refactor DrawUIOffscreen

This commit is contained in:
4am 2019-09-21 13:41:36 -04:00
parent c11468f877
commit 6f1895c1a7
5 changed files with 205 additions and 252 deletions

View File

@ -9,7 +9,7 @@
; D000..E5F4 - persistent data structures (per-game cheat categories,
; gGlobalPrefsStore, gGamesListStore)
; ...unused...
; EB9E..FFF9 - main program code
; EBCF..FFF9 - main program code
; FFFA..FFFF - NMI, reset, IRQ vectors
;
; LC RAM BANK 2

View File

@ -107,7 +107,7 @@ GameCount = *+1
+ !byte $FD ; SMC
clc
jsr DrawSearchBarOffscreen
jsr DrawUIOffscreen
jmp ShowOtherPage
;------------------------------------------------------------------------------

View File

@ -5,9 +5,6 @@
;
; Public functions:
; - ToggleCheat
; - BuildUILine1WithNoDots
; - BuildCheatLine1
; - BuildCheatLine2
;
ToggleCheat
@ -28,229 +25,3 @@ ToggleCheat
rts
@pref !byte 1
@val !byte $FD
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 +
ldy #.kCheatsEnabled
+
ldx #40
lda #$00 ; horizontal bar
- sta UILine1-1,x ; first, reset entire line to solid bar
dex
bne -
bit gCheatsEnabled
bpl @maybeDrawDots ; if no cheats, we don't need any curves on this line
lda .kCheatDescriptionLo,y
sta PTR
lda .kCheatDescriptionHi,y
sta PTR+1
; (PTR) -> length-prefixed cheat description
ldy #0
lda (PTR),y ; A = length of cheat description
clc
adc #4 ; extra padding (2 on each side)
sta @len
lda #40
sec
sbc @len
lsr
tax
lda #$09 ; rounded bottom-right character
sta UILine1,x
ldy #1 ; fill the proper width with spaces
lda #$20 ; space character
- inx
sta UILine1,x
iny
@len=*+1
cpy #$FD ; SMC
bne -
lda #$08 ; rounded bottom-left character
sta UILine1,x
@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: 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 +
ldy #.kCheatsEnabled
+
ldx #39 ; reset gPathname+2 to gPathname+41 to
lda #$00 ; horizontal bar character
- sta gPathname+1,x
dex
bne -
lda #$06 ; gPathname+1 = top-left rounded corner character
sta gPathname+1
lda .kCheatDescriptionLo,y
sta PTR
lda .kCheatDescriptionHi,y
sta PTR+1
; (PTR) -> length-prefixed cheat description
ldy #0
lda (PTR),y ; A = length of cheat description
clc
adc #4 ; extra padding (2 on each side)
sta gPathname ; gPathname = length
tax
lda #$07 ; gPathname+length = top-right rounded corner character
sta gPathname,x
rts
BuildCheatLine2
; 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 +
ldy #.kCheatsEnabled
+ lda .kCheatDescriptionLo,y
sta SAVE
lda .kCheatDescriptionHi,y
sta SAVE+1
; (SAVE) -> length-prefixed cheat description
+LDADDR .sCheatDescriptionPrefix
jsr SetPath
+LDAY SAVE
jsr AddToPath
+LDADDR .sCheatDescriptionSuffix
jmp AddToPath
.kCheatsEnabled = 3 ; index of 'cheats enabled' string in following table
.kCheatDescriptionLo
!byte <.sNoCheats
!byte <.sInfiniteLives
!byte <.sInfiniteLivesAndWeapons
!byte <.sCheatsEnabled
.kCheatDescriptionHi
!byte >.sNoCheats
!byte >.sInfiniteLives
!byte >.sInfiniteLivesAndWeapons
!byte >.sCheatsEnabled
.sNoCheats
!byte 8
!text "no cheat"
.sInfiniteLives
!byte 18
!byte $16 ; bolt
!text " "
!text "infinite lives"
!text " "
!byte $16 ; bolt
.sInfiniteLivesAndWeapons
!byte 28
!byte $16 ; bolt
!text " "
!text "infinite lives & weapons"
!text " "
!byte $16 ; bolt
.sCheatsEnabled
!byte 18
!byte $16 ; bolt
!text " "
!text "cheats enabled"
!text " "
!byte $16 ; bolt
.sCheatDescriptionPrefix
!byte 2
!byte $03 ; vertical line
!text " "
.sCheatDescriptionSuffix
!byte 2
!text " "
!byte $03 ; vertical line

View File

@ -8,7 +8,7 @@
; - GetOffscreenAddress
; - LoadTitleOffscreen
; - LoadCoverOffscreen
; - DrawSearchBarOffscreen
; - DrawUIOffscreen
; - ShowOtherPage
; - ToggleOffscreenPage
; - CoverFade
@ -43,6 +43,50 @@ ReturnToPlay
!byte $0D
!text " to play"
kCheatsEnabled = 3 ; index of 'cheats enabled' string in following table
kCheatDescriptionLo
!byte <sNoCheats
!byte <sInfiniteLives
!byte <sInfiniteLivesAndWeapons
!byte <sCheatsEnabled
kCheatDescriptionHi
!byte >sNoCheats
!byte >sInfiniteLives
!byte >sInfiniteLivesAndWeapons
!byte >sCheatsEnabled
sNoCheats
!byte 8
!text "no cheat"
sInfiniteLives
!byte 18
!byte $16 ; bolt
!text " "
!text "infinite lives"
!text " "
!byte $16 ; bolt
sInfiniteLivesAndWeapons
!byte 28
!byte $16 ; bolt
!text " "
!text "infinite lives & weapons"
!text " "
!byte $16 ; bolt
sCheatsEnabled
!byte 18
!byte $16 ; bolt
!text " "
!text "cheats enabled"
!text " "
!byte $16 ; bolt
sCheatDescriptionPrefix
!byte 2
!byte $03 ; vertical line
!text " "
sCheatDescriptionSuffix
!byte 2
!text " "
!byte $03 ; vertical line
;------------------------------------------------------------------------------
; GetOffscreenAddress
; get high byte of HGR page that is currently not showing
@ -124,7 +168,7 @@ CoverFade
!text "COVERFADE"
;------------------------------------------------------------------------------
; DrawSearchBarOffscreen
; DrawUIOffscreen
; draw 2- or 4-line search/browse UI on the HGR page that is not currently
; showing
;
@ -134,37 +178,175 @@ CoverFade
; C clear = don't print either of those things
; out: all flags and registers clobbered
;------------------------------------------------------------------------------
DrawSearchBarOffscreen
jsr BuildUILine1And2
DrawUIOffscreen
php
bcc + ; set up cursor printing if caller wanted that
lda #$7F
+HIDE_NEXT_2_BYTES
+
lda #" "
sta @printCursor+1
lda #22 ; draw visible search bar
ldy #39
- lda #$00 ; horizontal bar character
sta UILine1,y ; reset UI line 1 to solid bar
sta gPathname,y ; reset cheat UI line 1 to solid bar
lda Instructions,y
sta UILine2,y ; copy instructions to UI line 2
dey
bpl -
ldx gGameToLaunch
cpx #$FF ; if no game, nothing more to do on UI line 2
beq @doneWithLine2
+LDADDR gGamesListStore
jsr okvs_nth
+STAY + ; (A/Y) -> game filename
jsr okvs_get
!word gGamesListStore
+ !word $FDFD
+STAY SRC ; (SRC) -> game title
ldy #0 ; copy game title into UI line 2
lda (SRC),y
sta SAVE ; 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
sta UILine2,y
cpy #MaxInputLength+1
bcc -
ldx #8 ; replace games count with 'to play' label
- lda ReturnToPlay,x
sta UI_ToPlay,x
dex
bpl -
@doneWithLine2
bit gCheatsEnabled
bpl @maybeDrawDots ; if cheat mode is disabled, we don't need
; any curves or spaces on UI line 1
ldx gGameToLaunch
ldy gCheatsAvailable,x
cpx #$FF
bne +
ldy #kCheatsEnabled
+
lda kCheatDescriptionLo,y
sta SAVE
lda kCheatDescriptionHi,y
sta SAVE+1
; (SAVE) -> length-prefixed string
; (game-specific description or 'cheats enabled' message)
ldy #0
lda (SAVE),y ; A = string length
clc
adc #4 ; extra padding (2 on each side)
sta @len
lda #40
sec
sbc @len
lsr
tax
lda #$09 ; rounded bottom-right character
sta UILine1,x
ldy #1 ; fill the proper width with spaces
lda #$20 ; space character
- inx
sta UILine1,x
iny
@len=*+1
cpy #$FD ; SMC
bne -
lda #$08 ; rounded bottom-left character
sta UILine1,x
@maybeDrawDots
plp
bcc @doneHighlight ; if caller asked for no dots, then we're done building UI line 1
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 drawing dots
beq @doneHighlight
+ inc HTAB
cpy SAVE ; if game name is exhausted, we're done drawing dots
bne @dotloop
@doneHighlight
lda #22
sta VTAB
lda OffscreenPage
ror ; draw line 1 on offscreen page
ror
php
+LDADDR UILine1
jsr Draw40Chars
lda OffscreenPage
ror ; draw line 2 on offscreen page
jsr Draw40Chars ; draw UI line 1 on offscreen page
plp
+LDADDR UILine2
jsr Draw40Chars
bit gCheatsEnabled
bpl OffscreenDone ; if cheats are not enabled, we're done
jsr Draw40Chars ; draw UI line 2 on offscreen page
bit gCheatsEnabled ; if cheats are disabled, then we're done drawing UI
bpl OffscreenDone
; (SAVE) still points to length-prefixed cheat description
ldy #0
lda (SAVE),y ; A = length of cheat description
clc
adc #4 ; extra padding (2 on each side)
sta gPathname ; gPathname = length
tax
lda #$07 ; gPathname+length = top-right rounded corner character
sta gPathname,x
lda #$06 ; gPathname+1 = top-left rounded corner character
sta gPathname+1
lda #20
sta VTAB
jsr BuildCheatLine1
lda OffscreenPage
ror
php
+LDADDR gPathname
jsr DrawCenteredString
jsr DrawCenteredString ; draw cheat UI line 1
ldx gGameToLaunch
ldy gCheatsAvailable,x
cpx #$FF
bne +
ldy #kCheatsEnabled
+ lda kCheatDescriptionLo,y
sta SAVE
lda kCheatDescriptionHi,y
sta SAVE+1
; (SAVE) -> length-prefixed cheat description
+LDADDR sCheatDescriptionPrefix
jsr SetPath
+LDAY SAVE
jsr AddToPath
+LDADDR sCheatDescriptionSuffix
jsr AddToPath
inc VTAB
jsr BuildCheatLine2
lda OffscreenPage
ror
plp
+LDADDR gPathname
jmp DrawCenteredString
jmp DrawCenteredString ; draw cheat UI line 2
;------------------------------------------------------------------------------
; ClearOffscreen

View File

@ -127,7 +127,7 @@ SearchMode
stx gGameToLaunch ; no game selected
jsr LoadTitleOffscreen
clc
jsr DrawSearchBarOffscreen
jsr DrawUIOffscreen
jsr ShowOtherPage
clc
rts
@ -169,7 +169,7 @@ SearchMode
@skipload
sec
jsr DrawSearchBarOffscreen
jsr DrawUIOffscreen
jmp ShowOtherPage
;------------------------------------------------------------------------------