From 0ac65464902ff2e2076a19b1ef879fef8f5ac961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Wed, 23 Feb 2022 03:00:03 +0200 Subject: [PATCH] Check dictionary for word --- compress-dict.py | 2 +- dosdl.asm | 106 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 105 insertions(+), 3 deletions(-) diff --git a/compress-dict.py b/compress-dict.py index d54a741..1ff9a68 100644 --- a/compress-dict.py +++ b/compress-dict.py @@ -33,4 +33,4 @@ with open(targetpath, 'w') as f: f.write('dictionaries:\n') for startletter in arrays: - f.write(f'\tdw dictionary_{startletter}\n') + f.write(f'\tdw dictionary_{startletter}, {len(arrays[startletter])}\n') diff --git a/dosdl.asm b/dosdl.asm index e433f12..b197e40 100644 --- a/dosdl.asm +++ b/dosdl.asm @@ -113,8 +113,104 @@ read_guess: .done: -check_guess: - ; TODO: See whether guess is in the dictionary or targets +check_dictionary: + ; Dictionary is split by initial letter + xor bx, bx + mov bl, [guess] + sub bl, 'a' + + ; Entry in the table is 4 bytes + shl bx, 1 + shl bx, 1 + mov si, [dictionaries + bx] ; Start address + mov cx, [dictionaries + bx + 2] ; Number of letters + + .dictionary_loop: + push cx + + mov di, dictionary_entry + ; Entry is stored 5 bits per letter (first letter is implicit) + ; 3332_2222 5444_4433 0000_5555 + ; Load 5444_4433_3332_2222 into dx and extract 3 first letters + mov dx, [si] + add si, 2 + mov cl, 5 +%rep 3 + mov al, dl + and al, 0x1f + add al, 'a' + stosb + shr dx, cl +%endrep + ; Load 0000_5555 into al, shift one over, or with dl which has + ; 0000_0005 + mov al, [si] + inc si + shl al, 1 + or al, dl + add al, 'a' + stosb + + sub di, 4 + mov bp, 1 + mov cx, 4 + .compare_loop: + mov al, [di] + inc di + cmp al, [guess + bp] + jne .not_match + inc bp + loop .compare_loop + + pop cx + jmp word_found + + .not_match: + pop cx + loop .dictionary_loop + +check_targets: + ; TODO: Check whether word is in the list of target words + +word_not_found: + mov ah, 9 + mov dx, not_found_str + int 0x21 + + ; Wait for a keypress + mov ah, 8 + int 0x21 + + ; Clear line + mov ah, 2 + mov dl, 13 + int 0x21 + + mov ah, 9 + mov dx, erase_word_str + int 0x21 + + mov si, not_found_str + .clear_loop: + lodsb + cmp al, '$' + je .done + + mov ah, 2 + mov dl, ' ' + int 0x21 + + jmp .clear_loop + + .done: + + mov ah, 2 + mov dl, 13 + int 0x21 + + jmp read_guess + +word_found: find_exact_hits: mov si, guess @@ -292,12 +388,18 @@ newline: section .data target times 5 db 0 guess times 5 db 0 + exact_hits times 5 db 0 wrong_places times 5 db 0 + guesses db 0 +dictionary_entry times 4 db 0 + section .rodata +not_found_str db ' - word not found$' +erase_word_str db ' $' word_was_str db 'The word was: $' correct_in_str db 'Correct in $' guesses_str db ' guesses.$'