Check dictionary for word
This commit is contained in:
parent
788bd63b38
commit
0ac6546490
|
@ -33,4 +33,4 @@ with open(targetpath, 'w') as f:
|
||||||
|
|
||||||
f.write('dictionaries:\n')
|
f.write('dictionaries:\n')
|
||||||
for startletter in arrays:
|
for startletter in arrays:
|
||||||
f.write(f'\tdw dictionary_{startletter}\n')
|
f.write(f'\tdw dictionary_{startletter}, {len(arrays[startletter])}\n')
|
||||||
|
|
106
dosdl.asm
106
dosdl.asm
|
@ -113,8 +113,104 @@ read_guess:
|
||||||
|
|
||||||
.done:
|
.done:
|
||||||
|
|
||||||
check_guess:
|
check_dictionary:
|
||||||
; TODO: See whether guess is in the dictionary or targets
|
; 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:
|
find_exact_hits:
|
||||||
mov si, guess
|
mov si, guess
|
||||||
|
@ -292,12 +388,18 @@ newline:
|
||||||
section .data
|
section .data
|
||||||
target times 5 db 0
|
target times 5 db 0
|
||||||
guess times 5 db 0
|
guess times 5 db 0
|
||||||
|
|
||||||
exact_hits times 5 db 0
|
exact_hits times 5 db 0
|
||||||
wrong_places times 5 db 0
|
wrong_places times 5 db 0
|
||||||
|
|
||||||
guesses db 0
|
guesses db 0
|
||||||
|
|
||||||
|
dictionary_entry times 4 db 0
|
||||||
|
|
||||||
section .rodata
|
section .rodata
|
||||||
|
|
||||||
|
not_found_str db ' - word not found$'
|
||||||
|
erase_word_str db ' $'
|
||||||
word_was_str db 'The word was: $'
|
word_was_str db 'The word was: $'
|
||||||
correct_in_str db 'Correct in $'
|
correct_in_str db 'Correct in $'
|
||||||
guesses_str db ' guesses.$'
|
guesses_str db ' guesses.$'
|
||||||
|
|
Loading…
Reference in New Issue