pitch-dark/src/ui.main.a

437 lines
14 KiB
Plaintext
Raw Normal View History

2018-02-07 14:05:24 +00:00
;license:MIT
;(c) 2018 by 4am
;
2018-03-27 20:55:31 +00:00
; User interface - views and paint routines for main screen
2018-02-07 14:05:24 +00:00
;
; Public functions
2018-04-18 20:44:52 +00:00
; - MainScreen
2018-02-07 14:05:24 +00:00
;
2018-04-01 22:44:00 +00:00
; Public variables
2018-04-18 19:28:55 +00:00
; - gMainScreenPaintDirty byte 0=false, nonzero=true
2018-04-01 22:44:00 +00:00
;
2018-02-07 14:05:24 +00:00
; View IDs (application-specific, acceptable range 0..15, no duplicates)
2018-02-24 20:25:41 +00:00
ID_PREVIOUS = 1
ID_OPTIONS = 2
ID_NEXT = 3
ID_PLAY = 4
ID_BOXART = 5
ID_HINTS = 6
ID_VERSIONS = 7
ID_INFO = 8
ID_DESCRIPTION = 9
2018-06-20 22:58:05 +00:00
ID_ABOUT = 10
ID_CATALOG = 11
2018-04-01 22:26:54 +00:00
gMainScreenPaintDirty
2018-04-18 19:28:55 +00:00
!byte 0
2018-02-07 14:05:24 +00:00
2018-04-18 19:28:55 +00:00
kInfoPaintWidth = 65
kDescriptionPaintWidth = 78
2018-04-18 20:44:52 +00:00
;------------------------------------------------------------------------------
; MainScreen
; display main screen and run to completion
;------------------------------------------------------------------------------
MainScreen
ldx #$FF
txs
jsr PaintMain ; create all WeeGUI views (UI elements) and paint them
jsr ClearPendingInput
2018-04-19 02:01:24 +00:00
- jsr RepaintMainIfDirty
2018-04-18 20:44:52 +00:00
ldx #WGPendingViewAction
jsr WeeGUI ; handle mouse movement and clicks
lda $C000
2018-04-19 02:01:24 +00:00
bpl -
2018-04-18 20:44:52 +00:00
jsr ClearPendingInput
jsr HandleKey ; handle keypresses
2018-04-19 02:01:24 +00:00
bra -
2018-04-18 20:44:52 +00:00
;------------------------------------------------------------------------------
; internal functions
2018-02-07 14:05:24 +00:00
;------------------------------------------------------------------------------
2018-04-01 22:26:54 +00:00
; PaintMain/RepaintMainIfDirty
; call WeeGUI to create all application views and paint them
; PaintMain entry point will clear the screen and unconditionally paint everything
; RepaintMainIfDirty will only repaint certain views that vary between games,
; and only if gMainScreenPaintDirty=1
2018-02-07 14:05:24 +00:00
;
2018-04-02 19:43:11 +00:00
; in: WeeGUI initialized
2018-03-27 21:17:47 +00:00
; out: all registers and flags clobbered
2018-02-07 14:05:24 +00:00
;------------------------------------------------------------------------------
2018-04-01 22:26:54 +00:00
PaintMain
jsr HardResetWeeGUI
2018-04-01 22:26:54 +00:00
ldx #1 ; flag - clear screen before painting
stx gMainScreenPaintDirty
2018-04-18 02:28:22 +00:00
+HIDE_NEXT_2_BYTES
2018-04-01 22:26:54 +00:00
RepaintMainIfDirty
ldx #0 ; flag - do not clear screen before painting
lda gMainScreenPaintDirty
bne +
rts
+ stz gMainScreenPaintDirty ; clear dirty flag
phx ; push 'clear screen' flag (will pop at end of procedure)
jsr CreateButton ; create 'previous' button
!word kViewPrevious
2018-04-01 22:26:54 +00:00
jsr CreateButton ; create 'catalog' button
!word kViewCatalog
2018-04-01 22:26:54 +00:00
jsr CreateButton ; create 'settings' button
!word kViewOptions
2018-04-01 22:26:54 +00:00
jsr CreateButton ; create 'next game' button
!word kViewNext
2018-04-01 22:26:54 +00:00
lda gHasSavedGames ; create 'play game' or 'resume game' button
beq @wantPlayButton
2018-03-01 16:06:00 +00:00
jsr CreateButton
!word kViewResume
bra @donePlayOrResume
@wantPlayButton
2018-03-01 16:06:00 +00:00
jsr CreateButton
!word kViewPlay
@donePlayOrResume
2018-04-01 22:44:00 +00:00
jsr CreateOrDestroyButton ; create or destroy 'artwork' button
!byte ID_BOXART
!word kViewBoxArt
!word kHasArtwork
2018-04-01 22:44:00 +00:00
jsr CreateOrDestroyButton ; create or destroy 'hints' button
!byte ID_HINTS
!word kViewHints
!word kHasHints
2018-04-01 22:44:00 +00:00
jsr CreateOrDestroyButton ; create or destroy 'revisions' button
!byte ID_VERSIONS
!word kViewVersions
!word kHasVersions
2018-02-07 14:05:24 +00:00
2018-06-20 22:58:05 +00:00
jsr CreateButton ; create '?' button
!word kViewAbout
2018-04-01 22:26:54 +00:00
pla ; clear screen before repainting?
beq @nohome ; no -> repaint over existing screen, YOLO
2018-04-01 22:26:54 +00:00
ldx #WGClearScreen ; clear screen
jsr WeeGUI
2018-04-01 22:26:54 +00:00
jsr PaintTitleBar ; paint top bar
2018-02-07 14:05:24 +00:00
2018-04-01 22:26:54 +00:00
lda #4 ; paint horizontal separator bar
2018-02-24 20:25:41 +00:00
sta PARAM1
ldy #78
lda #83
- sty PARAM0
ldx #WGSetGlobalCursor
jsr WeeGUI
ldx #WGPlot
jsr WeeGUI
dey
bne -
ldx #WGSyncGlobalCursor
2018-04-01 22:26:54 +00:00
jsr WeeGUI
@nohome
ldx #WGSelectView ; delete info box but leave its contents on screen
lda #ID_INFO ; (harmless if it doesn't exist yet)
jsr WeeGUI
ldx #WGResetView
jsr WeeGUI
ldx #WGSelectView ; delete description box but leave its contents on screen
lda #ID_DESCRIPTION ; (harmless if it doesn't exist yet)
jsr WeeGUI
ldx #WGResetView
jsr WeeGUI
ldx #WGSelectView ; WeeGUI does NOT like repainting if the selected view does not exist
lda #ID_PREVIOUS
jsr WeeGUI
ldx #WGViewPaintAll ; repaint all WeeGUI-controlled UI elements
jsr WeeGUI
ldx #WGCreateView ; (re)create borderless frame for game title and info
+LDADDR kViewInfo ; (has the nice side effect of resetting the scroll)
+STAY PARAM0
jsr WeeGUI
jsr PaintInfoView ; paint contents of info box
ldx #WGCreateView ; (re)create scrollable frame for game description text
+LDADDR kViewDescription
+STAY PARAM0
jsr WeeGUI
ldx #WGViewSetAction ; set view action (called automatically after scrolling)
+LDADDR PaintDescriptionView
+STAY PARAM0
jsr WeeGUI
ldx #WGPaintView ; paint frame of description box
2018-04-01 22:26:54 +00:00
jsr WeeGUI
jmp PaintDescriptionView ; paint contents of description box
2018-04-01 22:26:54 +00:00
;------------------------------------------------------------------------------
2018-04-01 22:44:00 +00:00
; CreateOrDestroyButton
; create or destroy a WeeGUI Button view, based on per-game options
; and whether the button already exists
2018-04-01 22:26:54 +00:00
;
2018-04-02 19:43:11 +00:00
; in: WeeGUI initialized
2018-04-01 22:26:54 +00:00
; gOptionsStore populated
; stack contains 5 bytes of parameters:
; +1 [byte] WeeGUI view ID
; +2 [word] address of WeeGUI view configuration record
; +4 [word] address of length-prefixed key into gOptionsStore
; out: all registers and flags clobbered
;------------------------------------------------------------------------------
2018-04-01 22:44:00 +00:00
CreateOrDestroyButton
2018-04-01 22:26:54 +00:00
+PARAMS_ON_STACK 5
ldy #1
lda (PARAM),y
2018-04-19 02:01:24 +00:00
pha ; A = WeeGUI view ID
+LDPARAM 2
+STAY @vcr
+LDPARAM 4
+STAY @key
2018-04-01 22:26:54 +00:00
jsr okvs_get
!word gOptionsStore
@key !word $FDFD ; SMC
2018-04-19 02:01:24 +00:00
plx ; X = WeeGUI view ID
2018-04-01 22:26:54 +00:00
jsr okvs_as_boolean
beq @destroy
2018-04-01 22:44:00 +00:00
lda gViewInUse,x ; create button if it doesn't exist
bne @exit ; oh it does exist, so we're done
2018-04-01 22:26:54 +00:00
lda #1
2018-04-01 22:44:00 +00:00
sta gViewInUse,x
2018-04-01 22:26:54 +00:00
jsr CreateButton
@vcr !word $FDFD ; SMC
@exit rts
2018-04-01 22:26:54 +00:00
@destroy
lda gViewInUse,x ; destroy button if it exists
beq @exit ; oh it doesn't exist, so we're done
2018-04-01 22:26:54 +00:00
lda #0
2018-04-01 22:44:00 +00:00
sta gViewInUse,x
2018-04-01 22:26:54 +00:00
txa ; A = WeeGUI view ID
ldx #WGSelectView
jsr WeeGUI
ldx #WGEraseView
2018-04-01 22:26:54 +00:00
jsr WeeGUI
ldx #WGResetView
2018-04-19 02:01:24 +00:00
jmp WeeGUI
2018-04-01 22:26:54 +00:00
PaintDescriptionView
2018-02-07 14:05:24 +00:00
ldx #WGSelectView
2018-02-08 02:41:07 +00:00
lda #ID_DESCRIPTION
2018-02-07 14:05:24 +00:00
jsr WeeGUI
2018-04-01 23:12:39 +00:00
2018-03-29 02:49:51 +00:00
+LDAY addrDescription
ldx #kDescriptionPaintWidth
2018-04-01 22:26:54 +00:00
jsr MultiPrint
2018-04-01 23:12:39 +00:00
lda SAVE
cmp #10
bcs +
lda #10 ; minimum content height
2018-04-01 23:12:39 +00:00
+ ldx #WGSetContentHeight ; set content height so we stop scrolling on the last line of text
2018-03-01 16:06:00 +00:00
jmp WeeGUI
2018-04-01 22:26:54 +00:00
PaintInfoView
ldx #WGSelectView
2018-02-08 21:28:49 +00:00
lda #ID_INFO
jsr WeeGUI
2018-04-01 23:12:39 +00:00
2018-03-29 02:49:51 +00:00
+LDAY addrInfo
ldx #kInfoPaintWidth
2018-04-01 23:16:36 +00:00
phx
2018-04-01 22:26:54 +00:00
jsr MultiPrint
2018-03-28 15:48:47 +00:00
jsr okvs_get ; get shortname of current game
!word gGlobalPrefsStore
!word kLastPlayed
2018-03-31 14:22:09 +00:00
+STAY + ; A/Y contains address
2018-03-28 15:48:47 +00:00
jsr okvs_get ; get selected version of this game
!word gGlobalPrefsStore
2018-03-29 02:49:51 +00:00
+ !word $FDFD ; SMC
2018-03-31 14:22:09 +00:00
+STAY + ; A/Y contains address
2018-03-28 15:48:47 +00:00
jsr okvs_get ; get long description of this version
!word gVersionsStore
2018-03-29 02:49:51 +00:00
+ !word $FDFD ; SMC
2018-03-31 14:22:09 +00:00
; A/Y contains address
2018-04-01 23:16:36 +00:00
plx ; X = width a.k.a. where to put the null (rest is padded with spaces)
2018-04-01 23:12:39 +00:00
jsr CreateNullTerminatedString ; copies string to kNullTerminatedBuffer
2018-04-01 23:12:39 +00:00
+LDADDR kNullTerminatedBuffer ; now use that as the buffer to print the last line
2018-04-18 02:28:22 +00:00
+HIDE_NEXT_2_BYTES
2018-04-01 22:26:54 +00:00
MultiPrint
2018-04-01 23:16:36 +00:00
stz SAVE ; VTAB, but 0-indexed
stx @linelen
2018-04-01 23:12:39 +00:00
+STAY SRC
@loop stz PARAM0
2018-04-01 23:12:39 +00:00
lda SAVE
2018-02-07 14:05:24 +00:00
sta PARAM1
2018-04-01 23:12:39 +00:00
ldx #WGSetCursor
2018-02-07 14:05:24 +00:00
jsr WeeGUI
2018-04-01 23:12:39 +00:00
+LDAY SRC
+STAY PARAM0
bit MAGICRTS ; set overflow bit to trigger raw printing (with mousetext)
2018-02-07 14:05:24 +00:00
ldx #WGPrint
jsr WeeGUI
2018-04-01 23:12:39 +00:00
lda SRC
2018-02-08 21:28:49 +00:00
clc
@linelen=*+1
2018-04-01 23:12:39 +00:00
adc #$FD ; SMC
sta SRC
2018-02-08 21:28:49 +00:00
bcc +
2018-04-01 23:12:39 +00:00
inc SRC+1
+ inc SAVE
lda (SRC)
bne @loop
2018-02-07 14:05:24 +00:00
rts
2018-04-01 23:16:36 +00:00
;------------------------------------------------------------------------------
2018-04-18 19:28:55 +00:00
; WeeGUI view configuration records
2018-02-07 14:05:24 +00:00
kViewPrevious
2018-02-07 14:05:24 +00:00
!byte ID_PREVIOUS ; view ID
!byte 1 ; left
!byte 2 ; top
!byte 13 ; width
2018-02-07 14:05:24 +00:00
!word callback_previous ; callback
!word kStringPrevious ; caption
2018-02-07 14:05:24 +00:00
kViewNext
2018-02-07 14:05:24 +00:00
!byte ID_NEXT ; view ID
2018-02-24 20:25:41 +00:00
!byte 66 ; left
2018-02-07 14:05:24 +00:00
!byte 2 ; top
!byte 13 ; width
!word callback_next ; callback
!word kStringNext ; caption
2018-02-07 14:05:24 +00:00
kViewCatalog
!byte ID_CATALOG ; view ID
!byte 27 ; left
!byte 2 ; top
!byte 11 ; width
!word CatalogDialog ; callback
!word kStringCatalog
kViewOptions
2018-02-24 20:25:41 +00:00
!byte ID_OPTIONS ; view ID
!byte 41 ; left
2018-02-24 20:25:41 +00:00
!byte 2 ; top
!byte 12 ; width
2018-04-18 19:28:55 +00:00
!word OptionsDialog ; callback
!word kStringOptions
2018-02-24 20:25:41 +00:00
kViewPlay
2018-02-07 14:05:24 +00:00
!byte ID_PLAY ; view ID
2018-02-24 20:25:41 +00:00
!byte 66 ; left
!byte 6 ; top
2018-02-07 14:05:24 +00:00
!byte 13 ; width
2018-04-18 19:28:55 +00:00
!word LaunchInterpreterWithNewGame ; callback
!word kStringPlay ; caption
2018-02-07 14:05:24 +00:00
kViewResume
!byte ID_PLAY ; view ID
!byte 66 ; left
!byte 6 ; top
!byte 13 ; width
2018-04-18 19:28:55 +00:00
!word ResumeDialog ; callback
!word kStringResume ; caption
kViewBoxArt
2018-02-07 14:05:24 +00:00
!byte ID_BOXART ; view ID
!byte 66 ; left
2018-02-24 20:25:41 +00:00
!byte 8 ; top
!byte 13 ; width
2018-04-18 19:28:55 +00:00
!word DisplayArtwork ; callback
!word kStringBoxArt ; caption
2018-02-07 14:05:24 +00:00
kViewHints
!byte ID_HINTS ; view ID
2018-02-07 14:05:24 +00:00
!byte 66 ; left
2018-02-24 20:25:41 +00:00
!byte 10 ; top
!byte 13 ; width
2018-04-18 19:28:55 +00:00
!word LaunchInterpreterWithHints ; callback
!word kStringHints ; caption
2018-02-24 20:25:41 +00:00
kViewVersions
2018-02-24 20:25:41 +00:00
!byte ID_VERSIONS ; view ID
!byte 66 ; left
!byte 12 ; top
!byte 13 ; width
2018-04-18 19:28:55 +00:00
!word VersionsDialog ; callback
!word kStringVersions ; caption
2018-02-07 14:05:24 +00:00
kViewInfo
2018-02-07 14:05:24 +00:00
!byte ID_INFO ; view ID
!byte 0 ; style
2018-02-24 20:25:41 +00:00
!byte 0 ; left
!byte 6 ; top
!byte 65 ; visible width
!byte 6 ; visible height
!byte 65 ; width
!byte 6 ; height
2018-02-07 14:05:24 +00:00
kViewDescription
2018-02-07 14:05:24 +00:00
!byte ID_DESCRIPTION ; view ID
!byte 2 ; style
!byte 1 ; left
!byte 15 ; top
!byte 77 ; visible width
!byte 8 ; visible height
!byte 77 ; width
!byte 39 ; height
2018-04-18 19:28:55 +00:00
2018-06-20 22:58:05 +00:00
kViewAbout
!byte ID_ABOUT ; view ID
!byte 79 ; left
!byte 0 ; top
!byte 1 ; width
!word CreditsDialog ; callback
!word kStringAbout
2018-04-18 19:28:55 +00:00
kStringPrevious
!text "< "
!byte $10 ; 'P' inverse
!text "revious",0
kStringNext
!byte $0E ; 'N' inverse
!text "ext game >",0
kStringCatalog
2020-04-27 15:28:15 +00:00
!byte $0A ; 'J' inverse
!text "ump to",0
2018-04-18 19:28:55 +00:00
kStringOptions
!byte $13 ; 'S' inverse
!text "ettings",0
kStringPlay
!byte 144
!text "lay "
!byte $67 ; 'g' inverse
!text "ame",0
kStringResume
!byte 146
!text "esume "
!byte $67 ; 'g' inverse
!text "ame",0
kStringBoxArt
!byte $01 ; 'A' inverse
!text "rtwork",0
kStringHints
!byte $08 ; 'H' inverse
!text "ints",0
kStringVersions
!byte $16 ; 'V' inverse
!text "ersion",0
2018-06-20 22:58:05 +00:00
kStringAbout
!byte $3F, 0 ; '?' inverse