begin implementing token search routine
This commit is contained in:
1 parent
fbad812b56
commit
3892503289
1 file changed
+48
-3
@@ -36,13 +36,58 @@ got_line_of_input:
|
|||||||
ldx #$00
|
ldx #$00
|
||||||
jsr pack_word
|
jsr pack_word
|
||||||
|
|
||||||
;; Print the packed word
|
;; Search for word in keyword list
|
||||||
lda #<$0100
|
;; The packed form is canonical, so we can search for the keyword while
|
||||||
|
;; it remains compressed. This also saves a little time.
|
||||||
|
;; Algorithm is simply to find matching first bytes, and then look for
|
||||||
|
;; the rest being a match.
|
||||||
|
|
||||||
|
token_search:
|
||||||
|
;; tokenise_work1 = offset in line of input
|
||||||
|
;; tokenise_work2 = length of token we are matching
|
||||||
|
;; tokenise_work3 = offset in token list
|
||||||
|
ldy #$00
|
||||||
|
sta tokenise_work1
|
||||||
|
sta tokenise_work3
|
||||||
|
next_kw_offset:
|
||||||
|
;; Advance offset in compressed keyword list, to see if a match
|
||||||
|
;; BEGINS here
|
||||||
|
|
||||||
|
;; Get count of bytes to compare
|
||||||
|
lda tokenise_work2
|
||||||
|
sta tokenise_work4
|
||||||
|
sta $0427
|
||||||
|
|
||||||
|
;; Load current position
|
||||||
|
ldx tokenise_work1
|
||||||
|
ldy tokenise_work3
|
||||||
|
|
||||||
|
;; Advance offset in compressed token list
|
||||||
|
inc tokenise_work3
|
||||||
|
lda tokenise_work3
|
||||||
|
cmp #$ff
|
||||||
|
bne next_in_match
|
||||||
|
jmp done_searching_for_token
|
||||||
|
next_in_match:
|
||||||
|
lda $0100,x
|
||||||
|
cmp packed_keywords,y
|
||||||
|
bne next_kw_offset
|
||||||
|
;; Advance to next chars in source and target
|
||||||
|
inx
|
||||||
|
iny
|
||||||
|
dec tokenise_work4 ; Have we compared all bytes yet?
|
||||||
|
bne next_in_match
|
||||||
|
;; Keyword matches!
|
||||||
|
inc $d020
|
||||||
|
tya
|
||||||
|
clc
|
||||||
|
adc #<packed_keywords
|
||||||
sta temp_string_ptr+0
|
sta temp_string_ptr+0
|
||||||
lda #>$0100
|
lda #>packed_keywords
|
||||||
sta temp_string_ptr+1
|
sta temp_string_ptr+1
|
||||||
jsr print_packed_string
|
jsr print_packed_string
|
||||||
|
|
||||||
|
done_searching_for_token:
|
||||||
jsr ready_message
|
jsr ready_message
|
||||||
|
|
||||||
jmp basic_main_loop
|
jmp basic_main_loop
|
||||||
Reference in new issue
Block a user