2018-03-01 16:06:00 +00:00
|
|
|
;license:MIT
|
|
|
|
;(c) 2018 by 4am
|
|
|
|
;
|
|
|
|
; User interface - common views and paint routines across screens
|
|
|
|
;
|
|
|
|
; Public functions
|
2018-04-17 19:43:00 +00:00
|
|
|
; - HardResetWeeGUI
|
2018-04-17 20:08:32 +00:00
|
|
|
; - ExitWeeGUI
|
2018-04-17 20:16:45 +00:00
|
|
|
; - ClearPendingInput
|
2018-03-01 16:06:00 +00:00
|
|
|
; - CreateRadio
|
|
|
|
; - CreateCheckbox
|
|
|
|
; - CreateButton
|
2018-04-01 16:21:48 +00:00
|
|
|
; - PaintTitleBar
|
2018-04-02 18:38:05 +00:00
|
|
|
; - PrintAt
|
2018-04-02 19:26:05 +00:00
|
|
|
; - SimulateClick
|
2018-04-11 19:12:36 +00:00
|
|
|
; - GetCheckedRadioButton
|
2018-04-19 18:44:25 +00:00
|
|
|
; - HandleUpDownRadio
|
2018-04-15 16:29:24 +00:00
|
|
|
; - CreateNullTerminatedString
|
2018-03-01 16:06:00 +00:00
|
|
|
;
|
2018-04-19 18:44:25 +00:00
|
|
|
; Public variables
|
|
|
|
; - gViewInUse array of byte (each 0=false, nonzero=true)
|
|
|
|
|
2018-04-02 18:38:05 +00:00
|
|
|
; Public constants
|
|
|
|
; - kStringOK
|
|
|
|
; - kStringCancel
|
|
|
|
;
|
|
|
|
|
2018-04-19 18:41:39 +00:00
|
|
|
gViewInUse
|
|
|
|
!byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
|
|
|
|
2018-04-02 18:38:05 +00:00
|
|
|
kStringOK
|
|
|
|
!byte $0F ; 'O' inverse
|
|
|
|
!byte 139,0
|
|
|
|
kStringCancel
|
|
|
|
!byte $03 ; 'C' inverse
|
|
|
|
!text "ancel",0
|
2018-03-01 16:06:00 +00:00
|
|
|
|
2018-04-19 18:41:39 +00:00
|
|
|
; IDs of actions that do not correspond to WeeGUI view IDs have high bit set
|
|
|
|
ID_RADIO_PREVIOUS = $81
|
|
|
|
ID_RADIO_NEXT = $82
|
|
|
|
|
2018-04-17 19:43:00 +00:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; HardResetWeeGUI
|
|
|
|
; super-resets all WeeGUI views by creating 16 dummy views (which clears their
|
|
|
|
; internal state and callbacks and so on) then calling WeeGUI WGResetAll method
|
|
|
|
;
|
|
|
|
; in: WeeGUI initialized
|
2018-04-17 19:53:09 +00:00
|
|
|
; out: PARAM0/PARAM1 clobbered
|
2018-04-17 19:43:00 +00:00
|
|
|
; all registers clobbered
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
HardResetWeeGUI
|
|
|
|
lda #15 ; highest possible WeeGUI view ID
|
2018-04-19 14:05:48 +00:00
|
|
|
sta @kHardResetDummyView
|
|
|
|
+LDAY @kHardResetDummyView
|
2018-04-17 19:43:00 +00:00
|
|
|
+STAY PARAM0
|
2018-04-19 14:05:48 +00:00
|
|
|
- ldx #WGCreateView
|
2018-04-17 19:43:00 +00:00
|
|
|
jsr WeeGUI ; create dummy views to reset state on all views
|
2018-04-19 18:41:39 +00:00
|
|
|
ldx @kHardResetDummyView
|
|
|
|
lda #0
|
|
|
|
sta gViewInUse,x
|
2018-04-19 14:05:48 +00:00
|
|
|
dec @kHardResetDummyView
|
|
|
|
bpl -
|
2018-04-17 19:43:00 +00:00
|
|
|
ldx #WGResetAll ; reset WeeGUI (destroys everything we just created)
|
|
|
|
jmp WeeGUI
|
2018-04-19 14:05:48 +00:00
|
|
|
@kHardResetDummyView
|
2018-04-17 19:43:00 +00:00
|
|
|
!byte 0,0,0,0,0,0,0,0
|
2018-04-17 20:08:32 +00:00
|
|
|
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; ExitWeeGUI
|
|
|
|
; clears the screen and safely shuts down WeeGUI
|
|
|
|
;
|
|
|
|
; in: WeeGUI initialized
|
|
|
|
; out: A,Y preserved
|
|
|
|
; X clobbered
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
ExitWeeGUI
|
|
|
|
ldx #WGDisableMouse ; disable mouse support before quitting
|
|
|
|
jsr WeeGUI
|
|
|
|
ldx #WGClearScreen ; clear screen (HOME)
|
|
|
|
jsr WeeGUI
|
|
|
|
ldx #WGExit ; clean up WeeGUI
|
|
|
|
jmp WeeGUI
|
2018-04-17 19:43:00 +00:00
|
|
|
|
2018-04-17 20:16:45 +00:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; ClearPendingInput
|
|
|
|
; clears keyboard strobe and WeeGUI mouse click queue
|
|
|
|
;
|
|
|
|
; in: WeeGUI initialized
|
|
|
|
; out: A,Y preserved
|
|
|
|
; X clobbered
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
ClearPendingInput
|
|
|
|
bit $C010 ; clear keyboard strobe
|
|
|
|
ldx #WGClearPendingClick ; clear WeeGUI mouse strobe
|
|
|
|
jmp WeeGUI
|
|
|
|
|
2018-03-27 21:17:47 +00:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; CreateRadio/CreateCheckbox/CreateButton
|
|
|
|
; creates a WeeGUI UI control with the 'raw title' option set
|
|
|
|
;
|
2018-04-02 19:43:11 +00:00
|
|
|
; in: WeeGUI initialized
|
2018-04-02 18:38:05 +00:00
|
|
|
; stack contains 2 bytes of parameters:
|
2018-03-27 21:17:47 +00:00
|
|
|
; +1 [word] pointer to WeeGUI view configuration block
|
|
|
|
; out: $00/$01 clobbered
|
|
|
|
; all registers clobbered
|
|
|
|
;------------------------------------------------------------------------------
|
2018-03-01 16:06:00 +00:00
|
|
|
CreateRadio
|
|
|
|
ldx #WGCreateRadio
|
2018-04-18 02:28:22 +00:00
|
|
|
+HIDE_NEXT_2_BYTES
|
2018-03-01 16:06:00 +00:00
|
|
|
CreateCheckbox
|
|
|
|
ldx #WGCreateCheckbox
|
2018-04-18 02:28:22 +00:00
|
|
|
+HIDE_NEXT_2_BYTES
|
2018-03-01 16:06:00 +00:00
|
|
|
CreateButton
|
|
|
|
ldx #WGCreateButton
|
2018-04-19 14:05:48 +00:00
|
|
|
stx @type
|
2018-03-26 18:57:06 +00:00
|
|
|
|
|
|
|
+PARAMS_ON_STACK 2
|
2018-04-02 18:38:05 +00:00
|
|
|
+LDPARAM 1
|
|
|
|
+STAY PARAM0
|
2018-04-19 14:05:48 +00:00
|
|
|
@type=*+1
|
2018-03-28 15:48:47 +00:00
|
|
|
ldx #$FD ; SMC
|
2018-03-01 16:06:00 +00:00
|
|
|
jsr WeeGUI
|
2018-04-19 18:41:39 +00:00
|
|
|
lda (PARAM0)
|
|
|
|
tax
|
2018-03-01 16:06:00 +00:00
|
|
|
lda #1
|
2018-04-19 18:41:39 +00:00
|
|
|
sta gViewInUse,x
|
|
|
|
ldx #WGViewSetRawTitle
|
2018-03-01 16:06:00 +00:00
|
|
|
sta PARAM0
|
|
|
|
jmp WeeGUI
|
2018-04-01 16:21:48 +00:00
|
|
|
|
2018-04-02 18:38:05 +00:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; CreateDialog
|
|
|
|
; creates a WeeGUI decorated frame view
|
|
|
|
;
|
2018-04-02 19:43:11 +00:00
|
|
|
; in: WeeGUI initialized
|
2018-04-11 22:55:28 +00:00
|
|
|
; stack contains 4 bytes of parameters:
|
2018-04-02 18:38:05 +00:00
|
|
|
; +1 [word] address of WeeGUI view configuration block for frame
|
|
|
|
; +3 [word] address of null-terminated string for frame title
|
|
|
|
; out: $00/$01 clobbered
|
|
|
|
; all registers clobbered
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
CreateDialog
|
|
|
|
+PARAMS_ON_STACK 4
|
|
|
|
+LDPARAM 1
|
|
|
|
+STAY PARAM0
|
|
|
|
ldx #WGCreateView ; create frame
|
|
|
|
jsr WeeGUI
|
2018-04-19 18:41:39 +00:00
|
|
|
lda (PARAM0)
|
|
|
|
tax
|
|
|
|
lda #1
|
|
|
|
sta gViewInUse,x
|
2018-04-02 18:38:05 +00:00
|
|
|
|
|
|
|
+LDPARAM 3
|
|
|
|
+STAY PARAM0
|
|
|
|
ldx #WGViewSetTitle ; set frame title
|
|
|
|
jmp WeeGUI
|
|
|
|
|
2018-03-27 21:17:47 +00:00
|
|
|
;------------------------------------------------------------------------------
|
2018-04-01 16:21:48 +00:00
|
|
|
; PaintTitleBar
|
2018-04-02 18:38:05 +00:00
|
|
|
; paints the title bar on the top line
|
2018-03-27 21:17:47 +00:00
|
|
|
;
|
2018-04-02 19:43:11 +00:00
|
|
|
; in: WeeGUI initialized
|
2018-04-01 16:21:48 +00:00
|
|
|
; out: all registers and flags clobbered
|
2018-03-27 21:17:47 +00:00
|
|
|
;------------------------------------------------------------------------------
|
2018-04-01 16:21:48 +00:00
|
|
|
PaintTitleBar
|
|
|
|
ldy #79
|
|
|
|
- sty PARAM0
|
|
|
|
stz PARAM1
|
|
|
|
ldx #WGSetGlobalCursor
|
2018-03-01 16:06:00 +00:00
|
|
|
jsr WeeGUI
|
2018-04-01 16:21:48 +00:00
|
|
|
ldx #WGPlot
|
2018-04-02 19:26:05 +00:00
|
|
|
lda kStringGlobalTitle,y
|
2018-03-01 16:06:00 +00:00
|
|
|
jsr WeeGUI
|
2018-04-01 16:21:48 +00:00
|
|
|
dey
|
|
|
|
bpl -
|
|
|
|
ldx #WGSyncGlobalCursor
|
|
|
|
jmp WeeGUI
|
2018-03-01 16:06:00 +00:00
|
|
|
|
2018-04-02 19:26:05 +00:00
|
|
|
kStringGlobalTitle
|
2018-04-01 16:21:48 +00:00
|
|
|
!raw " "
|
2018-04-02 19:26:05 +00:00
|
|
|
!byte 16 ; inverse P
|
2018-04-01 16:21:48 +00:00
|
|
|
!raw "itch "
|
2018-04-02 19:26:05 +00:00
|
|
|
!byte 4 ; inverse D
|
2018-04-01 16:21:48 +00:00
|
|
|
!raw "ark ",0
|
2018-04-02 18:38:05 +00:00
|
|
|
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; PrintAt
|
|
|
|
; print a null-terminated string at a specified position
|
|
|
|
;
|
2018-04-02 19:43:11 +00:00
|
|
|
; in: WeeGUI initialized
|
2018-04-02 18:38:05 +00:00
|
|
|
; stack contains 4 bytes of parameters:
|
|
|
|
; +1 [byte] X coordinate (relative to selected view)
|
|
|
|
; +2 [byte] Y coordinate (relative to selected view)
|
|
|
|
; +3 [word] address of null-terminated string
|
|
|
|
; out: WeeGUI local cursor positioned after string
|
|
|
|
; $00/$01 clobbered
|
|
|
|
; all registers and flags clobbered
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
PrintAt
|
|
|
|
+PARAMS_ON_STACK 4
|
|
|
|
+LDPARAM 1
|
|
|
|
+STAY PARAM0
|
|
|
|
ldx #WGSetCursor
|
|
|
|
jsr WeeGUI
|
|
|
|
+LDPARAM 3
|
|
|
|
+STAY PARAM0
|
|
|
|
ldx #WGPrint
|
|
|
|
jmp WeeGUI
|
2018-04-02 19:26:05 +00:00
|
|
|
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; SimulateClick
|
2018-04-10 17:32:49 +00:00
|
|
|
; focus, activate, and unfocus a WeeGUI view
|
2018-04-11 19:12:36 +00:00
|
|
|
; note: does *not* select the view first, which you may or may not wish to do
|
|
|
|
; before calling
|
2018-04-02 19:26:05 +00:00
|
|
|
;
|
2018-04-02 19:43:11 +00:00
|
|
|
; in: WeeGUI initialized
|
2018-04-02 19:26:05 +00:00
|
|
|
; A contains WeeGUI view ID
|
|
|
|
; out: X clobbered
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
SimulateClick
|
|
|
|
ldx #WGViewFocus
|
|
|
|
jsr WeeGUI
|
|
|
|
ldx #WGViewFocusAction
|
|
|
|
jsr WeeGUI
|
|
|
|
ldx #WGViewUnfocus
|
|
|
|
jmp WeeGUI
|
2018-04-11 19:12:36 +00:00
|
|
|
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; GetCheckedRadioButton
|
|
|
|
; determine which radio button on screen is visually checked
|
|
|
|
; WeeGUI only supports a single radio group, so there is only ever one
|
|
|
|
; selected radio button.
|
|
|
|
; WeeGUI has no way to query the type of a view, so this function takes the
|
|
|
|
; lower and upper IDs and all views within that range are presumed to be
|
|
|
|
; radio buttons.
|
2018-04-19 18:41:39 +00:00
|
|
|
; WeeGUI has no way to query if a view is in use, so each view within the
|
|
|
|
; given range must either (a) be in use, or (b) have had its state set to 0
|
|
|
|
; (perhaps by calling HardResetWeeGUI earlier).
|
2018-04-11 19:12:36 +00:00
|
|
|
;
|
|
|
|
; in: WeeGUI initialized
|
2018-04-19 18:41:39 +00:00
|
|
|
; X = WeeGUI view ID of first radio button
|
|
|
|
; Y = WeeGUI view ID of last radio button
|
2018-04-11 19:12:36 +00:00
|
|
|
; out: C clear -> A contains WeeGUI view ID of selected radio button
|
|
|
|
; C set -> error, there is no selected radio button
|
2018-04-19 18:41:39 +00:00
|
|
|
; Y preserved
|
|
|
|
; X clobbered
|
|
|
|
; other flags clobbered
|
2018-04-11 19:12:36 +00:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
GetCheckedRadioButton
|
2018-04-19 18:41:39 +00:00
|
|
|
iny
|
2018-04-19 14:05:48 +00:00
|
|
|
sty @max
|
2018-04-19 18:41:39 +00:00
|
|
|
dey
|
|
|
|
txa
|
2018-04-11 19:12:36 +00:00
|
|
|
- pha
|
|
|
|
ldx #WGSelectView
|
|
|
|
jsr WeeGUI
|
|
|
|
ldx #WGGetState
|
|
|
|
jsr WeeGUI
|
|
|
|
lda PARAM0
|
|
|
|
and #1
|
2018-04-19 14:05:48 +00:00
|
|
|
bne @found
|
2018-04-11 19:12:36 +00:00
|
|
|
pla
|
|
|
|
inc
|
2018-04-19 14:05:48 +00:00
|
|
|
@max=*+1
|
2018-04-11 19:12:36 +00:00
|
|
|
cmp #$FD ; SMC
|
|
|
|
bcc -
|
2018-04-18 02:28:22 +00:00
|
|
|
+HIDE_NEXT_2_BYTES
|
2018-04-19 14:05:48 +00:00
|
|
|
@found pla
|
2018-04-11 19:12:36 +00:00
|
|
|
clc
|
|
|
|
rts
|
2018-04-15 16:29:24 +00:00
|
|
|
|
|
|
|
;------------------------------------------------------------------------------
|
2018-04-19 18:41:39 +00:00
|
|
|
; HandleUpDownRadio
|
|
|
|
;
|
|
|
|
; in: WeeGUI initialized
|
|
|
|
; A = action ID (#ID_RADIO_PREVIOUS or #ID_RADIO_NEXT)
|
|
|
|
; X = WeeGUI view ID of first radio button
|
|
|
|
; Y = WeeGUI view ID of last radio button
|
|
|
|
; out: all registers and flags clobbered
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
HandleUpDownRadio
|
|
|
|
sta @action ; action ID >= #$80 is a screen-specific action, so stash it for now
|
|
|
|
stx @first
|
|
|
|
sty @last
|
|
|
|
jsr GetCheckedRadioButton ; A = WeeGUI view ID of currently checked radio button
|
|
|
|
ldx #WGSelectView ; uncheck it and repaint it
|
|
|
|
jsr WeeGUI
|
|
|
|
stz PARAM0
|
|
|
|
ldx #WGSetState
|
|
|
|
jsr WeeGUI
|
|
|
|
ldx #WGPaintView
|
|
|
|
jsr WeeGUI
|
|
|
|
@findNewLoop
|
|
|
|
@action=*+1
|
|
|
|
ldx #$FD
|
|
|
|
cpx #ID_RADIO_PREVIOUS
|
|
|
|
beq @up
|
|
|
|
@last=*+1
|
|
|
|
cmp #$FD
|
|
|
|
bcs +
|
|
|
|
inc ; move to next
|
|
|
|
+HIDE_NEXT_2_BYTES
|
|
|
|
@first=*+1
|
|
|
|
+ lda #$FD ; move to first
|
|
|
|
bra @checkNew
|
|
|
|
@up dec ; tentatively move to previous
|
|
|
|
cmp @first
|
|
|
|
bcs @checkNew
|
|
|
|
lda @last ; nope, we were already on the first, so move to last
|
|
|
|
@checkNew
|
|
|
|
tax
|
|
|
|
ldy gViewInUse,x ; if new radio is unused, move again
|
|
|
|
beq @findNewLoop
|
|
|
|
ldx #WGSelectView ; check new radio button and repaint it
|
|
|
|
jsr WeeGUI
|
|
|
|
ldx #WGViewFocus
|
|
|
|
jsr WeeGUI
|
|
|
|
ldx #WGSetState
|
|
|
|
lda #1
|
|
|
|
sta PARAM0
|
|
|
|
jsr WeeGUI
|
|
|
|
ldx #WGPaintView
|
|
|
|
jmp WeeGUI
|
|
|
|
|
|
|
|
;------------------------------------------------------------------------------
|
2018-04-15 16:29:24 +00:00
|
|
|
; CreateNullTerminatedString
|
|
|
|
; Copy a length-prefixed string to kNullTerminatedBuffer and null-terminate it.
|
|
|
|
; Destination string is left-padded with a single space because reasons.
|
|
|
|
; Maximum length is 127 bytes.
|
|
|
|
;
|
|
|
|
; in: A/Y contains address of length-prefixed string to copy
|
|
|
|
; X contains length of null-terminated string -- if > length of source,
|
|
|
|
; remaining buffer will be padded with spaces (#$A0)
|
|
|
|
; out: X preserved
|
|
|
|
; all other registers and flags clobbered
|
|
|
|
; $00/$01 clobbered
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
CreateNullTerminatedString
|
|
|
|
+STAY $00
|
|
|
|
|
|
|
|
phx
|
|
|
|
lda #$A0
|
|
|
|
- dex
|
|
|
|
sta kNullTerminatedBuffer,x
|
|
|
|
bpl -
|
|
|
|
plx
|
|
|
|
lda #$00
|
|
|
|
sta kNullTerminatedBuffer,x
|
|
|
|
|
|
|
|
lda ($00)
|
|
|
|
tay
|
|
|
|
- lda ($00),y
|
|
|
|
sta kNullTerminatedBuffer,y
|
|
|
|
dey
|
|
|
|
bne -
|
|
|
|
rts
|