Tag

HEX

Browsing

The Apple II’s ROM has the 8th bit set for all of its ASCII strings. This convention makes it difficult to search the ROM for hex strings quickly. This Python script takes an ASCII string and returns the HEX string with (and without) the 8th bit set.

Python Code

input_string = "Mega IIe"

def string_to_hex_ascii(input_string, set_bit_8=False):
    hex_values = []
    for char in input_string:
        # Get the ASCII value of the character ord() and convert it string
        # representing the hex() value
        #
        # [2:] strips the '0x'

        if (set_bit_8):
            hex_value = (hex(ord(char) | 0x80)).upper() # for Apple II, awww
        else:
            hex_value = (hex(ord(char))).upper()
        
        hex_values.append(hex_value[2:])

    return hex_values

def print_list_with_spaces(input_list):
    # Join the list elements into a single string with spaces in between
    result = ' '.join(map(str, input_list))
    print(result)

def print_og_string_formatted(input_string):
    result = '  '.join(input_string)
    print(result)

# Remind user of string
print("Og  : ", end='')
print_og_string_formatted(input_string)

# As-is ASCII in Hex
hex_values_raw = string_to_hex_ascii(input_string)
print("Raw : ", end='')
print_list_with_spaces(hex_values_raw)

# Hex with 8th bit set
hex_values_8bit = string_to_hex_ascii(input_string, True)
print("8bit: ", end='')
print_list_with_spaces(hex_values_8bit)

Disclaimer: I used ChatGPT to generate an initial script for converting an ASCII string to a list of hex values. Then, I wrote the rest.

Example

The Apple IIe Enhanced ROM has the string Apple //e. It is displayed at the top of the screen during boot. Here is the 7-bit ASCII version and the 8-bit version found in the ROM file at address:

Og  : A  p  p  l  e     /  /  e
Raw : 41 70 70 6C 65 20 2F 2F 65
8bit: C1 F0 F0 EC E5 A0 AF AF E5