passport/src/compare.a

205 lines
4.2 KiB
Plaintext
Raw Normal View History

2017-01-08 03:35:35 +00:00
WILDCARD = $97
;-------------------------------
; SearchTrack subroutine
; written by qkumba
; search for a string occurring anywhere
; in the data buffer for the current track
; #WILDCARD in search string matches any 1 byte
; (like "." character in regular expressions)
; in: Y = string length
; stack = string to find
; out: C clear if string found
; or set if not found
; If C is clear, then
; A = sector where string was found
; X = starting offset where string was found
; all other registers and flags clobbered
;-------------------------------
SearchTrack
pla
sta match_buffer1+1
sta match_all+1
pla
sta match_buffer1+2
sta match_all+2
tax
sty match_size1+1
sty match_size2+1
; fetch last byte to improve search speed
match_buffer1
lda $d1d1,y ; modified at runtime
sta check_byte1+1
sta check_byte2+1
; set low part of initial search position
tya
dey
sty cont_search+1
; set return address
clc
adc match_buffer1+1
tay
bcc plus01
inx
plus01
txa
pha
tya
pha
; set match position
inc match_all+1
bne plus02
inc match_all+2
plus02
; set high part of initial search position
lda #BASEPAGE
sta search+2
lda #<cont_search-branch_cont-2
sta branch_cont+1
; search...
cont_search
ldy #$d1 ; modified at runtime
search
lda $d100,y ; modified at runtime
iny
beq check_end
check_byte1
cmp #$d1 ; modified at runtime
bne search
; point to first byte
sty cont_search+1
check_match
tya
match_size1
sbc #$d1 ; modified at runtime
sta match_buffer2+1
ldx search+2
bcs plus03
dex
plus03
stx match_buffer2+2
ldy #$00
match_all
lda $d1d1,y ; modified at runtime
cmp #WILDCARD
beq found_wild
match_buffer2
cmp $d1d1,y ; modified at runtime
branch_cont
bne cont_search
found_wild
iny
match_size2
cpy #$d1 ; modified at runtime
bne match_all
; point to start of match
ldx match_buffer2+1
lda match_buffer2+2
sec
sbc #BASEPAGE
clc
rts
; cold path
check_end
inc search+2
ldx search+2
cpx #BASEPAGE+$10
bne check_byte1
ldx #<all_done_set-branch_cont-2
stx branch_cont+1
check_byte2
cmp #$d1 ; modified at runtime
beq check_match
all_done_set
sec
rts
;-------------------------------
; compare subroutine
; in: A = sector
; X = offset
; Y = string length
; stack = string to compare
; #WILDCARD in search string matches any 1 byte
; (like "." character in regular expressions)
; out: C clear if string matches
; or set if not matched
; A,X unchanged
; Y clobbered
; $tmp zero page clobbered
; $cmp1 zero page clobbered
; $cmp2 zero page clobbered
; stack set to first instruction after string
;-------------------------------
!zone {
2017-01-08 03:35:35 +00:00
compare
clc
adc #BASEPAGE
CompareMemory
sta cmp1+1
stx cmp1
pla
sta cmp2
pla
sta cmp2+1
tax
tya
clc
adc cmp2
bcc +
inx
+ sta tmp
txa
pha
lda tmp
pha
.cmp
2017-01-08 03:35:35 +00:00
lda (cmp2),y
dey
bmi .success
2017-01-08 03:35:35 +00:00
cmp (cmp1),y
beq .cmp
2017-01-08 03:35:35 +00:00
cmp #WILDCARD
beq .cmp
2017-01-08 03:35:35 +00:00
sec
!byte $24 ; hide CLC
.success clc
2017-01-08 03:35:35 +00:00
php
lda cmp1+1
sec
sbc #BASEPAGE
ldx cmp1
plp
rts
}