4cade/src/ui.search.mode.a

264 lines
7.1 KiB
Plaintext
Raw Normal View History

2018-12-23 16:13:47 +00:00
;license:MIT
;(c) 2018 by 4am
;
; Search Mode - incrementally search game catalog
;
; Public functions
; - SearchMode
;
2019-06-18 18:56:05 +00:00
; indices into InputDispatchTable
kInputBackspace= 1
kInputEnter = 2
kInputSearchKey= 3
InputDispatchTable
!word 0
!word OnBackspace
!word OnEnter
!word OnKey
2018-12-23 16:13:47 +00:00
SearchMode
jsr Home ; switches to text mode
2019-06-18 18:56:05 +00:00
lda #0
sta InputLength
2018-12-23 16:13:47 +00:00
2019-06-18 18:56:05 +00:00
jsr OnInputChanged
2018-12-23 16:13:47 +00:00
2019-06-18 18:56:05 +00:00
bit $C054 ; show it
bit $C052
bit $C057
bit $C050
2018-12-23 16:13:47 +00:00
2019-06-18 18:56:05 +00:00
bit $C010
InputLoop
- lda $C000
2018-12-23 16:13:47 +00:00
bpl -
2019-06-18 18:56:05 +00:00
bit $C010
and #$7F
cmp #$7F ; delete key
bne +
- ldx #kInputBackspace
bne InputDispatch ; always branches
+ cmp #$08 ; left arrow = delete
beq -
cmp #$0D ; ENTER launches the current game (if any)
bne +
ldx #kInputEnter
bne InputDispatch ; always branches
+
cmp #$30 ; control keys and punctuation ignored
bcc @badkey
cmp #$3A ; numbers are good input
bcc @goodkey
cmp #$41 ; more punctuation (also ignored)
bcc @badkey
cmp #$5B ; uppercase letters are good input
bcs +
ora #$20 ; convert uppercase letters to lowercase
bne @goodkey ; always branches
+ cmp #$61 ; more punctuation (also ignored)
bcc @badkey
cmp #$7B ; lowercase letters are good input
bcc @goodkey
; execution falls through here
@badkey
jsr SoftBell ; beep on invalid input
jmp InputLoop ; and start over
@goodkey
ldx #kInputSearchKey
; execution falls through here
InputDispatch
pha ; save key pressed
txa
asl
tax
lda InputDispatchTable,x
sta @j+1
lda InputDispatchTable+1,x
sta @j+2
pla ; restore key pressed
@j jsr $FDFD ; SMC
jmp InputLoop
2018-12-23 16:13:47 +00:00
2019-06-18 18:56:05 +00:00
OnBackspace
2018-12-23 16:13:47 +00:00
ldx InputLength
2019-06-18 18:56:05 +00:00
bne +
jsr SoftBell
rts
+ dec InputLength
jmp OnInputChanged
2018-12-23 16:13:47 +00:00
2019-06-18 18:56:05 +00:00
OnEnter
; TODO
jmp $ff59
2018-12-23 16:13:47 +00:00
2019-06-18 18:56:05 +00:00
OnKey
ldx InputLength
cpx #MaxInputLength
bne +
jsr SoftBell
rts
+ sta InputBuffer,x
inc InputLength
; execution falls through here
2018-12-23 16:13:47 +00:00
OnInputChanged
2019-06-18 18:56:05 +00:00
lda InputLength
bne @findMatchingTitle
; no input, reset params and UI
lda #$FF
sta SelectedIndex ; reset selected index
ldy #MaxInputLength ; clear visible search bar
lda #" "
- sta UILine2+1,y
dey
bne -
lda #$7F
sta UILine2+1
jsr LoadFile ; load default background at $2000
!word Cover
lda #22 ; draw visible search bar
sta VTAB
clc ; on page 1
+LDADDR UILine1
jsr Draw40Chars
clc
+LDADDR UILine2
jmp Draw40Chars
@findMatchingTitle
lda #0 ; reset match count
sta MatchCount ; TextRankCallback will increment this if
; there are any matches
2018-12-23 16:13:47 +00:00
jsr okvs_iter_values
!word gGamesListStore
2019-06-18 18:56:05 +00:00
!word TextRankCallback
2018-12-23 16:13:47 +00:00
2019-06-18 18:56:05 +00:00
lda MatchCount ; check match count
bne @yeschange
jsr SoftBell ; no matches for this input buffer, beep
dec InputLength ; and ignore the last key typed
@nochange
rts
@yeschange
2018-12-23 16:13:47 +00:00
lda BestMatchIndex
2019-06-18 18:56:05 +00:00
cmp SelectedIndex ; we found a 'new' best match but it's the
beq @nochange ; same as the current match, so we're done
; TODO re-highlight here
2018-12-23 16:13:47 +00:00
2019-06-18 18:56:05 +00:00
sta SelectedIndex ; we have a new best match, so load the
sta @index ; new title screenshot and display the
jsr okvs_nth ; new game title in the search bar
2018-12-23 16:13:47 +00:00
!word gGamesListStore
@index !byte $FD
+STAY @key
; load game title page at $4000 (page 2, not currently visible)
2018-12-29 18:29:17 +00:00
+LOAD_FILE kHGRTitleDirectory, @key
2018-12-23 16:13:47 +00:00
jsr okvs_get
!word gGamesListStore
@key !word $FDFD
2019-06-18 18:56:05 +00:00
+STAY SRC ; A/Y points to game title (in OKVS)
ldy #0 ; copy game title into search bar buffer
lda (SRC),y
sta SAVE ; game title length
inc SAVE
- iny
cpy SAVE
bcc +
lda #" "
+HIDE_NEXT_2_BYTES
+ lda (SRC),y
sta UILine2,y
cpy #MaxInputLength+1
bcc -
2018-12-23 16:13:47 +00:00
2019-06-18 18:56:05 +00:00
lda #22 ; draw search bar
sta VTAB
sec ; on page 2, not currently visible
+LDADDR UILine1
jsr Draw40Chars
2018-12-23 16:13:47 +00:00
sec
2019-06-18 18:56:05 +00:00
+LDADDR UILine2
jsr Draw40Chars
2018-12-23 16:13:47 +00:00
2019-06-18 18:56:05 +00:00
bit $C055 ; show page 2
ldx #$20 ; copy back to page 1
stx @b+2 ; TODO delete this and use LoadFileAt
lda #$40 ; to load title screenshots on different
sta @a+2 ; pages
2018-12-23 16:13:47 +00:00
ldy #0
2019-06-18 18:56:05 +00:00
@a lda $4000,y
@b sta $2000,y
iny
bne @a
inc @a+2
inc @b+2
dex
bne @a
bit $C054 ; show page 1
rts
;------------------------------------------------------------------------------
; SoftBell
;
; in: none
; out: all registers and flags preserved
;------------------------------------------------------------------------------
SoftBell
php
pha
txa
pha
ldx #32
- lda #2
jsr Wait
bit $C030
lda #33
jsr Wait
bit $C030
dex
2018-12-23 16:13:47 +00:00
bne -
2019-06-18 18:56:05 +00:00
pla
tax
pla
plp
2018-12-23 16:13:47 +00:00
rts
2019-06-18 18:56:05 +00:00
Wait ; identical to $FCA8 ROM routine, but ROM is switched out when we need it
sec
-- pha
- sbc #1
bne -
pla
sbc #1
bne --
rts
;------------------------------------------------------------------------------
2018-12-23 16:13:47 +00:00
Cover !byte 5
!text "COVER"
UILine1
!byte 0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0
!byte 0,0,0,0,0,0,0,0,0,0
UILine2
!text "["
!byte $7F
!text " "
!text "] 000 games"