refactor UILine1 and UILine2

This commit is contained in:
4am 2019-09-21 12:59:56 -04:00
parent 00deb0f54b
commit ee045b8723
5 changed files with 112 additions and 123 deletions

View File

@ -79,7 +79,10 @@ zpCharMask = $F1 ; only uesd during init, then clobbered
gPathname = $1F00 ; used by SetPath/AddToPath
gKeyLen = $1F00 ; used by ParseGamesList
gKey = $1F01
UILine1 = $1F80
UILine1 = $1FB0
UILine2 = $1FD8
UI_ToPlay = $1FF7
gValLen = $1F80
gVal = $1F81

View File

@ -95,9 +95,9 @@ GameCount = *+1
; execution falls through here
.OnBrowseChanged
+LDADDR gGamesListStore
jsr okvs_nth ; get the name of the new game
jsr okvs_nth ; get the filename of the new game
+STAY @key
+STAY @key2
jsr GetOffscreenAddress ; load new title screenshot offscreen
sta + ; new title screenshot (offscreen)
jsr LoadFile
@ -106,34 +106,9 @@ GameCount = *+1
!byte $00
+ !byte $FD ; SMC
jsr okvs_get
!word gGamesListStore
@key2 !word $FDFD
+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 @printTitleChar
lda #" "
+HIDE_NEXT_2_BYTES
@printTitleChar
lda (SRC),y ; copy game title to UI line 2
sta UILine2,y
cpy #MaxInputLength+1
bcc -
ldx #8
- lda ReturnToPlay,x ; replace games count with 'to play' label
sta UI_ToPlay,x
dex
bpl -
ldx gGameToLaunch
jsr BuildUILine1WithNoDots; build UI line 1 with bars and other shapes
ldx gGameToLaunch
jsr DrawSearchBarOffscreen; actually draw the UI (offscreen)
jmp ShowOtherPage ; now show everything at once
clc
jsr DrawSearchBarOffscreen
jmp ShowOtherPage
;------------------------------------------------------------------------------

View File

@ -29,10 +29,65 @@ ToggleCheat
@pref !byte 1
@val !byte $FD
BuildUILine1WithNoDots
; in: X = game index, or #$FF if no game selected
; out: all registers clobbered
; UILine1 contains 40-character buffer (not length-prefixed) to print
BuildUILine1And2
; in: gGameToLaunch = game index, or #$FF if no game selected
; C set = print block cursor after game title and print dots to
; highlight matching characters
; C clear = don't print either of those things
; UILine1 and UILine2 each contain a 40-character buffer (not length-prefixed) to print
php
bcc + ; set up cursor printing if caller wanted that
lda #$7F
+HIDE_NEXT_2_BYTES
+
lda #" "
sta @printCursor+1
ldy #39 ; copy instructions to line 2
- lda Instructions,y
sta UILine2,y
dey
bpl -
ldx gGameToLaunch
cpx #$FF ; if no game, we're done with the bottom line
beq @doneWithLine2
+LDADDR gGamesListStore
jsr okvs_nth
+STAY +
jsr okvs_get
!word gGamesListStore
+ !word $FDFD
+STAY SRC ; (SRC) -> 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 @printTitleChar
beq @printCursor
lda #" "
+HIDE_NEXT_2_BYTES
@printCursor
lda #$FD ; SMC
+HIDE_NEXT_2_BYTES
@printTitleChar
lda (SRC),y ; copy game title to search UI
sta UILine2,y
cpy #MaxInputLength+1
bcc -
ldx #8
- lda ReturnToPlay,x ; replace games count with 'to play' label
sta UI_ToPlay,x
dex
bpl -
@doneWithLine2
ldx gGameToLaunch
ldy gCheatsAvailable,x
cpx #$FF
bne +
@ -45,7 +100,7 @@ BuildUILine1WithNoDots
bne -
bit gCheatsEnabled
bpl @done ; if cheats are not enabled, we're done
bpl @maybeDrawDots ; if no cheats, we don't need any curves on this line
lda .kCheatDescriptionLo,y
sta PTR
@ -75,13 +130,35 @@ BuildUILine1WithNoDots
lda #$08 ; rounded bottom-left character
sta UILine1,x
@done rts
@maybeDrawDots
plp
bcc @doneHighlight
ldx #0
ldy #0
@dotloop
iny
lda (SRC),y ; (SRC) still points to game title
+LOW_ASCII_TO_LOWER
cmp InputBuffer,x
bne +
lda #$11 ; dot character
sta UILine1,y
inx
cpx InputLength ; if input buffer is exhausted, we're done
beq @doneHighlight
+ inc HTAB
cpy SAVE ; if game name is exhausted, we're done
bne @dotloop
@doneHighlight
rts
BuildCheatLine1
; in: X = game index, or #$FF if no game is selected
; in: gGameToLaunch = game index, or #$FF if no game is selected
; out: gPathname contains length-prefixed string to print centered
; all registers clobbered
; PTR clobbered
ldx gGameToLaunch
ldy gCheatsAvailable,x
cpx #$FF
bne +
@ -112,11 +189,12 @@ BuildCheatLine1
rts
BuildCheatLine2
; in: X = game index, or #$FF if no game is selected
; in: gGameToLaunch = game index, or #$FF if no game is selected
; out: gPathname contains length-prefixed string to print centered
; all registers clobbered
; PTR clobbered
; SAVE clobbered
ldx gGameToLaunch
ldy gCheatsAvailable,x
cpx #$FF
bne +

View File

@ -22,7 +22,6 @@
; Public variables
; - OffscreenPage
; - UILine2
; - VisibleGameCount (set during init)
;
@ -34,14 +33,6 @@ OffscreenPage
; 1 = currently showing HGR page 1
; (so offscreen is page 2 @ $4000)
UILine2
!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
UI_ToPlay
!byte 0,0,0,0,0,0,0,0,0
Instructions
!text "[Type to search, "
!byte $0B
@ -134,14 +125,18 @@ CoverFade
;------------------------------------------------------------------------------
; DrawSearchBarOffscreen
; draw 2-line search UI on the HGR page that is not currently showing
; draw 2- or 4-line search/browse UI on the HGR page that is not currently
; showing
;
; in: X = game index, or #$FF if no game is selected
; in: gGameToLaunch = game index, or #$FF if no game is selected
; C set = print block cursor after game title and print dots to
; highlight matching characters
; C clear = don't print either of those things
; out: all flags and registers clobbered
;------------------------------------------------------------------------------
DrawSearchBarOffscreen
txa
pha
jsr BuildUILine1And2
lda #22 ; draw visible search bar
sta VTAB
lda OffscreenPage
@ -153,12 +148,9 @@ DrawSearchBarOffscreen
+LDADDR UILine2
jsr Draw40Chars
pla
bit gCheatsEnabled
bpl OffscreenDone ; if cheats are not enabled, we're done
pha
tax
lda #20
sta VTAB
jsr BuildCheatLine1
@ -168,8 +160,6 @@ DrawSearchBarOffscreen
jsr DrawCenteredString
inc VTAB
pla
tax
jsr BuildCheatLine2
lda OffscreenPage
ror

View File

@ -123,19 +123,12 @@ SearchMode
lda InputLength
bne @findMatchingTitle
; no input, reset params and UI
lda #$FF
sta gGameToLaunch ; no game selected
ldx #39 ; copy instructions to line 2
- lda Instructions,x
sta UILine2,x
dex
bpl -
ldx #$FF
stx gGameToLaunch ; no game selected
jsr LoadTitleOffscreen
ldx #$FF ; no game selected
jsr BuildUILine1WithNoDots; build UI line 1 with bars and other shapes
ldx #$FF ; no game selected
jsr DrawSearchBarOffscreen; draw everything at once (offscreen)
jsr ShowOtherPage ; show it all at once
clc
jsr DrawSearchBarOffscreen
jsr ShowOtherPage
clc
rts
@ -157,9 +150,8 @@ SearchMode
php ; (we'll use this later to skip reloading)
stx gGameToLaunch
+LDADDR gGamesListStore
jsr okvs_nth ; get the name of the new best match
jsr okvs_nth ; get the filename of the new best match
+STAY @key
+STAY @key2
plp
bne +
jsr ToggleOffscreenPage ; Since we're not loading a new screenshot
@ -176,58 +168,9 @@ SearchMode
+ !byte $FD ; SMC
@skipload
jsr okvs_get
!word gGamesListStore
@key2 !word $FDFD
+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 @printTitleChar
beq @printCursor
lda #" "
+HIDE_NEXT_2_BYTES
@printCursor
lda #$7F
+HIDE_NEXT_2_BYTES
@printTitleChar
lda (SRC),y ; copy game title to search UI
sta UILine2,y
cpy #MaxInputLength+1
bcc -
ldx #8
- lda ReturnToPlay,x ; replace games count with 'to play' label
sta UI_ToPlay,x
dex
bpl -
ldx gGameToLaunch
jsr BuildUILine1WithNoDots; build UI line 1 with bars and other shapes
; now add dots to UI line 1 to highlight matched characters
ldx #0
ldy #0
@dotloop
iny
lda (SRC),y
+LOW_ASCII_TO_LOWER
cmp InputBuffer,x
bne +
lda #$11 ; dot character
sta UILine1,y
inx
cpx InputLength ; if input buffer is exhausted, we're done
beq @doneHighlight
+ inc HTAB
cpy SAVE ; if game name is exhausted, we're done
bne @dotloop
@doneHighlight
ldx gGameToLaunch
jsr DrawSearchBarOffscreen; actually draw the search UI (offscreen)
jmp ShowOtherPage ; now show everything at once
sec
jsr DrawSearchBarOffscreen
jmp ShowOtherPage
;------------------------------------------------------------------------------