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
|
2021-06-13 05:06:09 +00:00
|
|
|
; A = @gDisplayBytes = sector where string was found
|
2017-01-08 03:35:35 +00:00
|
|
|
; X = starting offset where string was found
|
|
|
|
; all other registers and flags clobbered
|
|
|
|
;-------------------------------
|
|
|
|
SearchTrack
|
2017-02-21 00:50:38 +00:00
|
|
|
;set end point for the search
|
|
|
|
|
|
|
|
lda #BASEPAGE+$10
|
|
|
|
sta .endvalue+1
|
|
|
|
lda #BASEPAGE
|
|
|
|
bne SearchSectors
|
|
|
|
|
|
|
|
;-------------------------------
|
|
|
|
; SearchSector subroutine
|
|
|
|
; written by qkumba
|
|
|
|
; same as SearchTrack, but for a single sector
|
2021-06-20 21:35:48 +00:00
|
|
|
; in: A = high byte of sector address in data buffer (e.g. $10 for sector 0)
|
2017-02-21 00:50:38 +00:00
|
|
|
; Y = string length
|
|
|
|
; stack = string to find
|
|
|
|
; out: C clear if string found
|
|
|
|
; or set if not found
|
|
|
|
; If C is clear, then
|
|
|
|
; X = starting offset where string was found
|
|
|
|
; all other registers and flags clobbered
|
|
|
|
;-------------------------------
|
|
|
|
|
|
|
|
SearchSector
|
|
|
|
;set end point for the search
|
|
|
|
|
|
|
|
tax
|
|
|
|
inx
|
|
|
|
stx .endvalue+1
|
|
|
|
|
|
|
|
; set high part of initial search position
|
|
|
|
|
|
|
|
SearchSectors
|
|
|
|
sta search+2
|
2017-01-08 03:35:35 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
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
|
2021-06-13 05:06:09 +00:00
|
|
|
sta gDisplayBytes
|
2021-06-13 05:43:46 +00:00
|
|
|
clc
|
2017-01-08 03:35:35 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
; cold path
|
|
|
|
|
|
|
|
check_end
|
|
|
|
inc search+2
|
|
|
|
ldx search+2
|
2017-02-21 00:50:38 +00:00
|
|
|
.endvalue
|
|
|
|
cpx #$D1
|
2017-01-08 03:35:35 +00:00
|
|
|
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
|
|
|
|
|
2021-06-21 15:24:21 +00:00
|
|
|
compare1
|
|
|
|
ldy #$01
|
|
|
|
; /!\ execution falls through here
|
|
|
|
|
2017-01-08 03:35:35 +00:00
|
|
|
;-------------------------------
|
|
|
|
; 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)
|
2021-06-13 05:43:46 +00:00
|
|
|
; out: C = 0 if string matches, and gDisplayBytes set to A
|
|
|
|
; C = 1 if not matched
|
2021-06-12 04:50:09 +00:00
|
|
|
; A,X,Y preserved
|
2017-01-08 03:35:35 +00:00
|
|
|
; $tmp zero page clobbered
|
|
|
|
; $cmp1 zero page clobbered
|
|
|
|
; $cmp2 zero page clobbered
|
|
|
|
; stack set to first instruction after string
|
|
|
|
;-------------------------------
|
|
|
|
compare
|
2021-06-19 17:07:09 +00:00
|
|
|
sta tmpa
|
2017-01-08 03:35:35 +00:00
|
|
|
clc
|
|
|
|
adc #BASEPAGE
|
2021-06-19 17:07:09 +00:00
|
|
|
!byte $2C
|
2017-01-08 03:35:35 +00:00
|
|
|
CompareMemory
|
2021-06-19 17:07:09 +00:00
|
|
|
sta tmpa
|
2017-01-08 03:35:35 +00:00
|
|
|
sta cmp1+1
|
|
|
|
stx cmp1
|
2021-06-19 17:07:09 +00:00
|
|
|
sty tmpy
|
2017-01-08 03:35:35 +00:00
|
|
|
pla
|
|
|
|
sta cmp2
|
|
|
|
pla
|
|
|
|
sta cmp2+1
|
|
|
|
tax
|
|
|
|
tya
|
|
|
|
clc
|
|
|
|
adc cmp2
|
|
|
|
bcc +
|
|
|
|
inx
|
2021-06-19 17:07:09 +00:00
|
|
|
+ sta modtmp
|
2017-01-08 03:35:35 +00:00
|
|
|
txa
|
|
|
|
pha
|
2021-06-19 17:07:09 +00:00
|
|
|
lda modtmp
|
2017-01-08 03:35:35 +00:00
|
|
|
pha
|
2021-04-20 04:27:11 +00:00
|
|
|
@cmp
|
2017-01-08 03:35:35 +00:00
|
|
|
lda (cmp2),y
|
|
|
|
dey
|
2021-04-20 04:27:11 +00:00
|
|
|
bmi @success
|
2017-01-08 03:35:35 +00:00
|
|
|
cmp (cmp1),y
|
2021-04-20 04:27:11 +00:00
|
|
|
beq @cmp
|
2017-01-08 03:35:35 +00:00
|
|
|
cmp #WILDCARD
|
2021-04-20 04:27:11 +00:00
|
|
|
beq @cmp
|
2017-01-08 03:35:35 +00:00
|
|
|
sec
|
|
|
|
!byte $24 ; hide CLC
|
2021-04-20 04:27:11 +00:00
|
|
|
@success clc
|
2021-06-19 17:07:09 +00:00
|
|
|
lda tmpa
|
2017-01-08 03:35:35 +00:00
|
|
|
ldx cmp1
|
2021-06-19 17:07:09 +00:00
|
|
|
ldy tmpy
|
2021-06-13 05:43:46 +00:00
|
|
|
bcs +
|
|
|
|
sta gDisplayBytes
|
|
|
|
+ rts
|