2019-06-18 18:56:05 +00:00
|
|
|
;license:MIT
|
2019-06-24 02:32:18 +00:00
|
|
|
;(c) 2018-9 by 4am & qkumba
|
2019-06-18 18:56:05 +00:00
|
|
|
;
|
|
|
|
; text rank - an implementation of the Quicksilver search rank algorithm
|
|
|
|
;
|
|
|
|
; Public functions
|
2020-03-18 16:08:39 +00:00
|
|
|
; - BuildSearchStore
|
2019-06-27 02:51:34 +00:00
|
|
|
; - ResetTextRank
|
2019-06-18 18:56:05 +00:00
|
|
|
; - TextRankCallback (as okvs_iter_values callback)
|
|
|
|
;
|
|
|
|
; Public variables
|
2019-06-27 02:51:34 +00:00
|
|
|
; - InputLength ; [byte] number of characters typed in search mode
|
|
|
|
; - InputBuffer ; [25 bytes] characters typed in search mode
|
2020-03-18 16:08:39 +00:00
|
|
|
; - SelectedIndex ; [byte] index in gSearchStore of currently selected game in search mode
|
2019-06-27 02:51:34 +00:00
|
|
|
; - MatchCount ; [byte] number of games that match InputBuffer
|
|
|
|
; - BestMatchScore ; [byte] raw ranking score (0-100) of current best match (updated during TextRankCallback)
|
2020-03-18 16:08:39 +00:00
|
|
|
; - BestMatchIndex ; [byte] index in gSearchStore of current best match (updated during TextRankCallback)
|
2019-06-18 18:56:05 +00:00
|
|
|
|
2019-07-08 18:10:11 +00:00
|
|
|
MaxInputLength = 26
|
2019-06-18 18:56:05 +00:00
|
|
|
InputLength
|
|
|
|
!byte 0
|
|
|
|
InputBuffer
|
|
|
|
!text " "
|
|
|
|
|
2020-03-18 16:08:39 +00:00
|
|
|
BuildSearchStore
|
|
|
|
jsr SwitchToBank2
|
|
|
|
jsr EnableAcceleratorAndSwitchToBank1
|
|
|
|
+LDADDR gSearchStore
|
|
|
|
jsr okvs_init
|
|
|
|
|
|
|
|
jsr okvs_iter
|
|
|
|
!word gGamesListStore
|
|
|
|
!word @callback
|
2020-03-19 02:11:28 +00:00
|
|
|
|
|
|
|
jsr SwitchToBank2
|
|
|
|
jmp DisableAcceleratorAndSwitchToBank1
|
2020-03-18 16:08:39 +00:00
|
|
|
@callback
|
|
|
|
; callback called by okvs_iter on gGamesListStore
|
|
|
|
|
|
|
|
; in: A/Y contains address of filename
|
2020-03-24 20:30:14 +00:00
|
|
|
; $WINDEX contains 0-based index of the current record in gGamesListStore (word)
|
2020-03-18 16:08:39 +00:00
|
|
|
; out: all registers and flags clobbered
|
2020-03-24 20:30:14 +00:00
|
|
|
+ST16 @key
|
2020-03-18 16:08:39 +00:00
|
|
|
jsr GetGameDisplayName
|
2020-03-24 20:30:14 +00:00
|
|
|
+ST16 @value
|
2020-03-18 16:08:39 +00:00
|
|
|
@append
|
|
|
|
jsr okvs_append
|
|
|
|
!word gSearchStore
|
|
|
|
@key !word $FDFD ; SMC
|
|
|
|
@value !word $FDFD ; SMC
|
|
|
|
!byte 0
|
|
|
|
rts
|
|
|
|
|
2019-06-18 20:52:35 +00:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; ResetTextRank
|
|
|
|
; reset the Match variables to allow re-scanning (e.g. because of backspace)
|
|
|
|
|
|
|
|
; in: nothing
|
|
|
|
; out: X, MatchCount, BestMatchScore, BestMatchIndex zeroed
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
ResetTextRank
|
|
|
|
ldx #0
|
|
|
|
stx MatchCount
|
|
|
|
stx BestMatchScore
|
2019-06-18 21:07:14 +00:00
|
|
|
dex
|
2019-06-18 20:52:35 +00:00
|
|
|
stx BestMatchIndex
|
2020-03-24 20:30:14 +00:00
|
|
|
stx BestMatchIndex+1
|
2019-06-18 20:52:35 +00:00
|
|
|
rts
|
|
|
|
|
2019-06-18 18:56:05 +00:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; TextRankCallback
|
2020-03-18 16:08:39 +00:00
|
|
|
; callback called by okvs_iter_values on gSearchStore
|
|
|
|
; to calculate a ranking score for a single game display name
|
2019-06-18 18:56:05 +00:00
|
|
|
; against the current InputBuffer
|
|
|
|
|
2020-03-18 16:08:39 +00:00
|
|
|
; in: A/Y contains address of game display name
|
2020-03-24 20:30:14 +00:00
|
|
|
; $WINDEX contains 0-based index of the current record in gSearchStore (word)
|
2019-06-18 18:56:05 +00:00
|
|
|
; out: all registers and flags clobbered
|
2020-03-18 16:08:39 +00:00
|
|
|
; MatchCount possibly incremented (if this game was a match at all)
|
|
|
|
; BestMatchScore and BestMatchIndex possibly updated (if this game
|
2019-06-18 18:56:05 +00:00
|
|
|
; was the best match so far)
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
TextRankCallback
|
2020-03-24 20:30:14 +00:00
|
|
|
+ST16 zpstring ; A/Y = address of this game display name
|
2019-06-18 18:56:05 +00:00
|
|
|
+LDADDR InputLength
|
2020-03-24 20:30:14 +00:00
|
|
|
+ST16 zpword
|
2019-06-30 19:10:09 +00:00
|
|
|
ldy #0
|
|
|
|
lda (zpstring),y
|
2019-07-04 20:31:28 +00:00
|
|
|
cmp InputLength
|
2019-07-05 02:03:14 +00:00
|
|
|
bcc ++
|
|
|
|
sta gamelength
|
2019-09-24 00:01:42 +00:00
|
|
|
sty runningscore
|
|
|
|
sty runningscore+1
|
|
|
|
iny
|
2019-06-18 18:56:05 +00:00
|
|
|
sty startat
|
|
|
|
- sty i
|
|
|
|
lda (zpword),y
|
|
|
|
+LOW_ASCII_TO_LOWER
|
|
|
|
sta tmp
|
|
|
|
ldy startat
|
|
|
|
-- lda (zpstring),y
|
|
|
|
+LOW_ASCII_TO_LOWER
|
|
|
|
cmp tmp
|
|
|
|
beq +
|
|
|
|
cpy gamelength
|
|
|
|
iny
|
|
|
|
bcc --
|
2019-07-05 02:03:14 +00:00
|
|
|
++ rts ; no match :(
|
2019-09-22 02:46:08 +00:00
|
|
|
+ ldx #80
|
2019-06-18 18:56:05 +00:00
|
|
|
cpy startat
|
|
|
|
beq +
|
|
|
|
ldx #10
|
|
|
|
cpy #1
|
|
|
|
beq +
|
|
|
|
dey
|
|
|
|
lda (zpstring),y
|
|
|
|
iny
|
|
|
|
cmp #' '
|
|
|
|
bne +
|
|
|
|
ldx #90
|
|
|
|
+ txa
|
|
|
|
clc
|
|
|
|
adc runningscore
|
|
|
|
sta runningscore
|
|
|
|
bcc +
|
|
|
|
inc runningscore+1
|
2019-07-05 02:03:14 +00:00
|
|
|
+ tya
|
2019-06-18 18:56:05 +00:00
|
|
|
ldy i
|
|
|
|
cpy InputLength
|
2019-07-05 02:03:14 +00:00
|
|
|
bcs +
|
2019-06-18 18:56:05 +00:00
|
|
|
iny
|
2019-07-05 02:03:14 +00:00
|
|
|
sta startat
|
|
|
|
inc startat
|
|
|
|
cmp gamelength
|
2019-06-18 18:56:05 +00:00
|
|
|
bcc -
|
2019-07-05 02:03:14 +00:00
|
|
|
rts ; no match :(
|
2019-09-22 02:46:08 +00:00
|
|
|
+ lda runningscore
|
2019-06-18 18:56:05 +00:00
|
|
|
ldx runningscore+1
|
|
|
|
ldy gamelength
|
|
|
|
jsr @div
|
|
|
|
sta tmp
|
|
|
|
lda runningscore
|
|
|
|
ldx runningscore+1
|
|
|
|
ldy InputLength
|
|
|
|
jsr @div
|
|
|
|
clc
|
|
|
|
adc tmp
|
|
|
|
lsr
|
|
|
|
pha
|
|
|
|
ldy #1
|
|
|
|
lda (zpstring),y
|
2019-06-18 20:52:35 +00:00
|
|
|
+LOW_ASCII_TO_LOWER
|
2019-06-18 18:56:05 +00:00
|
|
|
sta firstletter
|
|
|
|
pla
|
|
|
|
ldx InputBuffer
|
|
|
|
cpx firstletter
|
|
|
|
bne +
|
|
|
|
cmp #85
|
|
|
|
bcs +
|
|
|
|
adc #15
|
2019-09-22 02:46:08 +00:00
|
|
|
+ cmp BestMatchScore
|
2019-06-18 18:56:05 +00:00
|
|
|
bcc +
|
2019-06-27 20:15:48 +00:00
|
|
|
beq +
|
2019-06-18 18:56:05 +00:00
|
|
|
sta BestMatchScore
|
2020-03-24 20:30:14 +00:00
|
|
|
lda WINDEX
|
|
|
|
sta BestMatchIndex
|
|
|
|
lda WINDEX+1
|
|
|
|
sta BestMatchIndex+1
|
2019-06-18 18:56:05 +00:00
|
|
|
inc MatchCount
|
2019-09-22 02:46:08 +00:00
|
|
|
+ rts
|
2019-06-18 18:56:05 +00:00
|
|
|
|
|
|
|
@div
|
2019-09-22 02:46:08 +00:00
|
|
|
sta num1
|
|
|
|
stx num1+1
|
|
|
|
sty num2
|
2019-06-18 18:56:05 +00:00
|
|
|
lda #0
|
2019-09-22 02:46:08 +00:00
|
|
|
sta remainder
|
|
|
|
sta remainder+1
|
2019-06-18 18:56:05 +00:00
|
|
|
ldx #16
|
2019-09-22 02:46:08 +00:00
|
|
|
- asl num1
|
|
|
|
rol num1+1
|
|
|
|
rol remainder
|
|
|
|
rol remainder+1
|
|
|
|
lda remainder
|
2019-06-18 18:56:05 +00:00
|
|
|
sec
|
2019-09-22 02:46:08 +00:00
|
|
|
sbc num2
|
2019-06-18 18:56:05 +00:00
|
|
|
bcc +
|
2019-09-22 02:46:08 +00:00
|
|
|
sta remainder
|
|
|
|
dec remainder+1
|
|
|
|
inc num1
|
2019-06-18 18:56:05 +00:00
|
|
|
+ dex
|
|
|
|
bne -
|
2019-09-22 02:46:08 +00:00
|
|
|
lda num1
|
2019-06-18 18:56:05 +00:00
|
|
|
rts
|