4cade/src/ui.overlay.a

287 lines
9.1 KiB
Plaintext
Raw Normal View History

2019-09-24 19:50:40 +00:00
;License:MIT
2020-03-17 01:58:05 +00:00
;(c) 2018-2020 by 4am
2019-09-24 19:50:40 +00:00
;
; routines for drawing the UI overlay (search bar, browse bar, instructions, cheat mode)
; on top of whatever else is on the screen
;
; Public functions
; - DrawUIWithoutDots
; - DrawUI
;
; Public variables
; - VisibleGameCount (set during init)
;
Instructions
!text "[Type to search, ? for help ] "
2019-09-24 19:50:40 +00:00
VisibleGameCount
!text "000 games"
ReturnToPlay
!byte $0D
!text " to play"
kCheatsEnabled = 6 ; index of 'cheats enabled' string in following table
2019-09-24 19:50:40 +00:00
kCheatDescriptionLo
!byte <sNoCheats
!byte <sInfiniteLives
!byte <sInfiniteWeapons
2019-09-24 19:50:40 +00:00
!byte <sInfiniteLivesAndWeapons
2020-03-17 03:16:46 +00:00
!byte <sInvincibility
2020-04-06 20:26:28 +00:00
!byte <sInGame
2019-09-24 19:50:40 +00:00
!byte <sCheatsEnabled
kCheatDescriptionHi
!byte >sNoCheats
!byte >sInfiniteLives
!byte >sInfiniteWeapons
2019-09-24 19:50:40 +00:00
!byte >sInfiniteLivesAndWeapons
2020-03-17 03:16:46 +00:00
!byte >sInvincibility
2020-04-06 20:26:28 +00:00
!byte >sInGame
2019-09-24 19:50:40 +00:00
!byte >sCheatsEnabled
sNoCheats
2019-10-08 18:10:35 +00:00
!byte 8 ; length
2019-09-24 19:50:40 +00:00
!text "no cheat"
sInfiniteLives
2019-10-08 18:10:35 +00:00
!byte 18 ; length
2019-10-08 03:58:20 +00:00
!byte $16 ; bolt character
2019-09-24 19:50:40 +00:00
!text " "
!text "infinite lives"
!text " "
2019-10-08 03:58:20 +00:00
!byte $16 ; bolt character
sInfiniteWeapons
!byte 20 ; length
!byte $16 ; bolt character
!text " "
!text "infinite weapons"
!text " "
!byte $16 ; bolt character
2019-09-24 19:50:40 +00:00
sInfiniteLivesAndWeapons
2019-10-08 18:10:35 +00:00
!byte 28 ; length
2019-10-08 03:58:20 +00:00
!byte $16 ; bolt character
2019-09-24 19:50:40 +00:00
!text " "
!text "infinite lives & weapons"
!text " "
2019-10-08 03:58:20 +00:00
!byte $16 ; bolt character
2020-03-17 03:16:46 +00:00
sInvincibility
!byte 14 ; length
!byte $16 ; bolt character
!text " "
!text "invincible"
!text " "
!byte $16 ; bolt character
2020-04-06 20:26:28 +00:00
sInGame
!byte 18 ; length
!byte $16 ; bolt character
!text " "
!text "in-game cheats"
!text " "
!byte $16 ; bolt character
2019-09-24 19:50:40 +00:00
sCheatsEnabled
2019-10-08 18:10:35 +00:00
!byte 18 ; length
2019-10-08 03:58:20 +00:00
!byte $16 ; bolt character
2019-09-24 19:50:40 +00:00
!text " "
!text "cheats enabled"
!text " "
2019-10-08 03:58:20 +00:00
!byte $16 ; bolt character
2019-09-24 19:50:40 +00:00
sCheatDescriptionPrefix
2019-10-08 18:10:35 +00:00
!byte 2 ; length
2019-10-08 03:58:20 +00:00
!byte $03 ; vertical line character
2019-09-24 19:50:40 +00:00
!text " "
sCheatDescriptionSuffix
2019-10-08 18:10:35 +00:00
!byte 2 ; length
2019-09-24 19:50:40 +00:00
!text " "
2019-10-08 03:58:20 +00:00
!byte $03 ; vertical line character
2019-09-24 19:50:40 +00:00
;------------------------------------------------------------------------------
; DrawUIWithoutDots/DrawUI
; draw 2- or 4-line UI on the HGR page that is not currently showing, then
; show that HGR page
;
2020-03-24 20:30:14 +00:00
; in: gGameToLaunch = game index (word), or #$FFFF if no game is selected
2019-09-24 19:50:40 +00:00
; out: all flags and registers clobbered
;------------------------------------------------------------------------------
DrawUIWithoutDots
2019-10-09 02:25:22 +00:00
lda #" " * 2
+HIDE_NEXT_2_BYTES
2019-09-24 19:50:40 +00:00
DrawUI
2019-10-09 02:25:22 +00:00
lda #$FF ; #$7F * 2
lsr
sta @printCursor+1 ; set up cursor printing based on entry point
2019-09-24 19:50:40 +00:00
php
ldy #39
2020-03-09 21:24:30 +00:00
-
2019-09-24 19:50:40 +00:00
lda Instructions,y
sta UILine2,y ; copy instructions to UI line 2
2020-03-09 21:24:30 +00:00
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
2019-09-24 19:50:40 +00:00
dey
bpl -
2020-03-09 21:24:30 +00:00
sta gGameToLaunchInfo ; reset gGameToLaunchInfo
lda #40
sta gPathname ; hack, used by first RedrawForDHGR which follows
; Draw40Chars which doesn't set gPathname
2019-09-24 19:50:40 +00:00
2020-03-24 20:30:14 +00:00
jsr GetGameToLaunch ; get current game, if any
bcs @doneWithLine2 ; if no game, nothing more to do on UI line 2
jsr GetGameDisplayName
; A/Y -> game display name + bitfield of game info
2020-03-24 20:30:14 +00:00
+ST16 PTR
ldy #0
lda (PTR),y ; A = game display name length + 1
sta SAVE
tay
lda (PTR),y ; A = game info bitfield
sta gGameToLaunchInfo
ldy #0
2019-09-24 19:50:40 +00:00
- iny
2019-10-10 01:02:46 +00:00
@printCursor
lda #$FD ; SMC
2019-09-24 19:50:40 +00:00
cpy SAVE
bcc @printTitleChar
2019-10-10 01:02:46 +00:00
beq @printChar
2019-09-24 19:50:40 +00:00
lda #" "
+HIDE_NEXT_2_BYTES
@printTitleChar
lda (PTR),y
2019-10-10 01:02:46 +00:00
@printChar
2019-09-24 19:50:40 +00:00
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
lda MachineStatus
and #CHEATS_ENABLED
beq @maybeDrawDots ; if cheat mode is disabled, we don't need
2019-09-24 19:50:40 +00:00
; any curves or spaces on UI line 1
2019-10-10 01:02:46 +00:00
jsr CheckCheats
2019-09-24 19:50:40 +00:00
; (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
2019-11-27 21:51:43 +00:00
iny ; fill the proper width with spaces
2019-09-24 19:50:40 +00:00
lda #$20 ; space character
- inx
sta UILine1,x
iny
@len=*+1
cpy #$FD ; SMC
bne -
lda #$0C ; 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 (PTR),y ; (PTR) still points to game display name + game info bitfield
2019-10-10 01:02:46 +00:00
ora #$20 ; force lower-case always
2019-09-24 19:50:40 +00:00
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
php
+LDADDR UILine1
jsr Draw40Chars ; draw UI line 1 on offscreen page
2020-03-09 21:24:30 +00:00
jsr MaybeRedrawUIForDHGR ; transform for DHGR if this is a DHGR title screen
2019-09-24 19:50:40 +00:00
plp
gDrawingOnscreen=*+1
lda #$00 ; SMC, might be 1
bne @uidone
2019-09-24 19:50:40 +00:00
+LDADDR UILine2
jsr Draw40Chars ; draw UI line 2 on offscreen page
2020-03-09 21:24:30 +00:00
jsr MaybeRedrawUIForDHGR ; transform for DHGR if this is a DHGR title screen
lda MachineStatus
and #CHEATS_ENABLED
beq @uidone ; if cheats are disabled, then we're done drawing UI
2019-09-24 19:50:40 +00:00
; (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
lda OffscreenPage
ror
php
+LDADDR gPathname
jsr DrawCenteredString ; draw cheat UI line 1
2020-03-09 21:24:30 +00:00
jsr MaybeRedrawUIForDHGR ; transform for DHGR if this is a DHGR title screen
2019-10-10 01:02:46 +00:00
jsr CheckCheats
2019-09-24 19:50:40 +00:00
; (SAVE) -> length-prefixed cheat description
+LDADDR sCheatDescriptionPrefix
jsr SetPath
2020-03-24 20:30:14 +00:00
+LD16 SAVE
2019-09-24 19:50:40 +00:00
jsr AddToPath
+LDADDR sCheatDescriptionSuffix
jsr AddToPath
inc VTAB
plp
+LDADDR gPathname
jsr DrawCenteredString ; draw cheat UI line 2
2020-03-09 21:24:30 +00:00
jsr MaybeRedrawUIForDHGR ; transform for DHGR if this is a DHGR title screen
@uidone lda #0
sta gDrawingOnscreen
clc
2019-11-27 21:51:43 +00:00
jmp ShowOtherPage
2019-10-10 01:02:46 +00:00
CheckCheats
2020-03-24 20:30:14 +00:00
ldx #kCheatsEnabled
jsr AnyGameSelected
bcs +
gGameToLaunchInfo=*+1
lda #$FD ; SMC
2020-03-09 21:24:30 +00:00
and #CHEAT_CATEGORY
2020-03-24 20:30:14 +00:00
tax
2019-10-10 01:02:46 +00:00
+
2020-03-24 20:30:14 +00:00
lda kCheatDescriptionLo,x
2019-10-10 01:02:46 +00:00
sta SAVE
2020-03-24 20:30:14 +00:00
lda kCheatDescriptionHi,x
2019-10-10 01:02:46 +00:00
sta SAVE+1
2020-03-09 21:24:30 +00:00
- rts
MaybeRedrawUIForDHGR
2020-03-15 03:54:06 +00:00
bit MachineStatus
bvc -
2020-03-09 21:24:30 +00:00
bit gGameToLaunchInfo
bpl -
jmp RedrawForDHGR