Esempio n. 1
0
def main(argv):
    header, data = header_and_data(argv[1])
    dictionary = ZMachineDictionary(data, header)

    for i in range(1, dictionary.number_of_entries + 1):
        entry = dictionary.entry(i)
        print(f'{i} = {entry.text}')

    return 0
Esempio n. 2
0
def test_tokenize(zork_v3_dict: ZMachineDictionary):
    text_buffer_addr = 0
    parse_buffer_addr = 256

    memory = memoryview(bytearray(b' ' * 512))

    # The games will set the maximum text-buffer size in the first byte of the text buffer
    memory[0] = 77

    # Games will set the max number of token blocks that can be stored at the beginning of the parse buffer
    memory[parse_buffer_addr] = 10

    write_asciiz(memory, 1, 'get,   lamp poop')

    tokenize(memory, zork_v3_dict, text_buffer_addr, parse_buffer_addr)

    assert memory[
        parse_buffer_addr +
        1] == 4, 'The parse buffer should have marked that 4 tokens were parsed'

    token_block_0 = read_token_block(memory, parse_buffer_addr, 0)
    assert token_block_0.dict_addr == zork_v3_dict.entry_addr(
        252), 'correct address of the word `get` was found'
    assert token_block_0.text_pos == 1, 'correct position of the word `get` was found'
    assert token_block_0.word_len == 3, 'correct length of the word `get` was found'

    token_block_1 = read_token_block(memory, parse_buffer_addr, 1)
    assert token_block_1.dict_addr == zork_v3_dict.entry_addr(
        3), 'correct address of the comma was found'
    assert token_block_1.text_pos == 4, 'correct position of the comma was found'
    assert token_block_1.word_len == 1, 'correct length of the comma was found'

    token_block_2 = read_token_block(memory, parse_buffer_addr, 2)
    assert token_block_2.dict_addr == zork_v3_dict.entry_addr(
        336), 'correct address of the word `lamp` was found'
    assert token_block_2.text_pos == 8, 'correct position of the word `lamp` was found'
    assert token_block_2.word_len == 4, 'correct length of the word `lamp` was found'

    token_block_3 = read_token_block(memory, parse_buffer_addr, 3)
    assert token_block_3.dict_addr == 0, 'the word `poop` was correctly not found'
    assert token_block_3.text_pos == 13, 'correct position of the word `poop` was found'
    assert token_block_3.word_len == 4, 'correct length of the word `poop` was found'
Esempio n. 3
0
def test_word_lookup_not_found(zork_v3_dict: ZMachineDictionary,
                               zork_v5_dict: ZMachineDictionary):
    assert 0 == zork_v3_dict.lookup_word('poop')
    assert 0 == zork_v5_dict.lookup_word('pistolgrippump')
Esempio n. 4
0
def test_word_lookup_v5(word: str, expected_entry_num: int, desc: str,
                        zork_v5_dict: ZMachineDictionary):
    word_addr = zork_v5_dict.lookup_word(word)
    assert word_addr == zork_v5_dict.entry_addr(expected_entry_num), desc
Esempio n. 5
0
def test_word_lookup_v3_leaves_bug(zork_v3_dict: ZMachineDictionary):
    word_addr = zork_v3_dict.lookup_word('leave')
    assert word_addr == zork_v3_dict.entry_addr(347)

    word_addr = zork_v3_dict.lookup_word('leaves')
    assert word_addr == zork_v3_dict.entry_addr(348)
Esempio n. 6
0
def test_dictionary_entries(entry_num: int, expected_text: str,
                            zork_v3_dict: ZMachineDictionary):
    entry = zork_v3_dict.entry(entry_num)
    assert entry.text == expected_text
    assert len(entry.data) == 3
Esempio n. 7
0
def zork_v3_dict(zork1_v3_data: memoryview) -> ZMachineDictionary:
    header = get_header(zork1_v3_data)
    yield ZMachineDictionary(zork1_v3_data, header)