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
|
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
|
|
|
|
; - SelectedIndex ; [byte] index in gGamesListStore of currently selected game in search mode
|
|
|
|
; - MatchCount ; [byte] number of games that match InputBuffer
|
|
|
|
; - BestMatchScore ; [byte] raw ranking score (0-100) of current best match (updated during TextRankCallback)
|
|
|
|
; - BestMatchIndex ; [byte] index in gGamesListStore of current best match (updated during TextRankCallback)
|
2019-06-18 18:56:05 +00:00
|
|
|
|
|
|
|
zpword = $F0 ; word
|
|
|
|
zpstring = $F2 ; word
|
|
|
|
runningscore= $F4 ; word
|
|
|
|
startat = $F6 ; byte
|
|
|
|
i = $F7 ; byte
|
|
|
|
tmp = $F8 ; byte
|
|
|
|
gamelength= $F9 ; byte
|
|
|
|
firstletter= $FA ; byte
|
|
|
|
|
|
|
|
MaxInputLength = 24
|
|
|
|
InputLength
|
|
|
|
!byte 0
|
|
|
|
InputBuffer
|
|
|
|
!text " "
|
2019-06-27 02:51:34 +00:00
|
|
|
SelectedIndex
|
|
|
|
!byte $FF
|
2019-06-18 18:56:05 +00:00
|
|
|
MatchCount
|
|
|
|
!byte 0
|
|
|
|
BestMatchScore
|
|
|
|
!byte 0
|
|
|
|
BestMatchIndex
|
|
|
|
!byte 0
|
|
|
|
|
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
|
|
|
|
rts
|
|
|
|
|
2019-06-18 18:56:05 +00:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; TextRankCallback
|
|
|
|
; callback called by okvs_iter_values on gGamesListStore
|
|
|
|
; to calculate a ranking score for a single game title
|
|
|
|
; against the current InputBuffer
|
|
|
|
|
|
|
|
; in: A/Y contains address of game title
|
|
|
|
; X contains 0-based index of the current record in gGamesListStore
|
|
|
|
; out: all registers and flags clobbered
|
|
|
|
; MatchCount possibly incremented (if this title was a match at all)
|
|
|
|
; BestMatchScore and BestMatchIndex possibly updated (if this title
|
|
|
|
; was the best match so far)
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
TextRankCallback
|
|
|
|
stx @tmpx ; X = OKVS index of this title
|
|
|
|
+STAY zpstring ; A/Y = address of this title
|
|
|
|
+LDADDR InputLength
|
|
|
|
+STAY 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-06-18 18:56:05 +00:00
|
|
|
lda #0
|
|
|
|
sta runningscore
|
|
|
|
sta runningscore+1
|
|
|
|
ldy #1
|
|
|
|
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-06-18 18:56:05 +00:00
|
|
|
+
|
|
|
|
ldx #80
|
|
|
|
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-06-18 18:56:05 +00:00
|
|
|
|
2019-07-05 02:03:14 +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
|
|
|
|
+
|
|
|
|
cmp BestMatchScore
|
|
|
|
bcc +
|
2019-06-27 20:15:48 +00:00
|
|
|
beq +
|
2019-06-18 18:56:05 +00:00
|
|
|
sta BestMatchScore
|
|
|
|
ldx @tmpx
|
|
|
|
stx BestMatchIndex
|
|
|
|
inc MatchCount
|
|
|
|
+
|
|
|
|
rts
|
|
|
|
|
|
|
|
@div
|
|
|
|
sta @num1
|
|
|
|
stx @num1+1
|
|
|
|
sty @num2
|
|
|
|
|
|
|
|
lda #0
|
|
|
|
sta @rem
|
|
|
|
sta @rem+1
|
|
|
|
ldx #16
|
|
|
|
- asl @num1
|
|
|
|
rol @num1+1
|
|
|
|
rol @rem
|
|
|
|
rol @rem+1
|
|
|
|
lda @rem
|
|
|
|
sec
|
|
|
|
sbc @num2
|
|
|
|
bcc +
|
|
|
|
sta @rem
|
|
|
|
dec @rem+1
|
|
|
|
inc @num1
|
|
|
|
+ dex
|
|
|
|
bne -
|
|
|
|
lda @num1
|
|
|
|
rts
|
|
|
|
|
|
|
|
@rem !word 0
|
|
|
|
@num1 !word 0
|
|
|
|
@num2 !byte 0
|
|
|
|
@tmpx !byte $FD
|