pitch-dark/src/paint.a
2018-02-24 15:25:41 -05:00

389 lines
11 KiB
Plaintext

;license:MIT
;(c) 2018 by 4am
;
; User interface - views and paint routines
;
; Public functions
; - CreateViews
; - PaintAllViews
; - RepaintSomeViews
;
; ROM routines
INVERSE = $FE80
NORMAL = $FE84
MAGICRTS = $FF58 ; used to set overflow bit
; View IDs (application-specific, acceptable range 0..15, no duplicates)
ID_TITLE = 0
ID_PREVIOUS = 1
ID_OPTIONS = 2
ID_NEXT = 3
ID_HR = 4
ID_PLAY = 5
ID_VERSIONS = 6
ID_BOXART = 7
ID_CLUES = 8
ID_INFO = 9
ID_DESCRIPTION = 13
!zone {
;------------------------------------------------------------------------------
; CreateViews
; call WeeGUI to create all application views
;
; in: WeeGUI loaded and initialized
; out: all registers clobbered
; all flags clobbered
;------------------------------------------------------------------------------
CreateViews
ldx #WGCreateView ; create title bar on top line
lda #<.viewTitle
sta PARAM0
lda #>.viewTitle
sta PARAM1
jsr WeeGUI
ldx #WGViewSetAction
lda #<.paintTitleView
sta PARAM0
lda #>.paintTitleView
sta PARAM1
jsr WeeGUI
ldx #WGCreateView ; create horizontal rule
lda #<.viewHR
sta PARAM0
lda #>.viewHR
sta PARAM1
jsr WeeGUI
ldx #WGViewSetAction
lda #<.paintHRView
sta PARAM0
lda #>.paintHRView
sta PARAM1
jsr WeeGUI
jsr .createButton ; create various buttons
!word .viewPrevious
jsr .createButton
!word .viewNext
jsr .createButton
!word .viewPlay
jsr .createButton
!word .viewVersions
jsr .createButton
!word .viewBoxArt
jsr .createButton
!word .viewClues
jsr .createButton
!word .viewOptions
ldx #WGCreateView ; create borderless frame for game title and info
lda #<.viewInfo
sta PARAM0
lda #>.viewInfo
sta PARAM1
jsr WeeGUI
ldx #WGViewSetAction
lda #<.paintInfoView
sta PARAM0
lda #>.paintInfoView
sta PARAM1
jsr WeeGUI
ldx #WGCreateView ; create scrollable frame for game description text
lda #<.viewDescription
sta PARAM0
lda #>.viewDescription
sta PARAM1
jsr WeeGUI
ldx #WGViewSetAction
lda #<.paintDescriptionView
sta PARAM0
lda #>.paintDescriptionView
sta PARAM1
jmp WeeGUI
;------------------------------------------------------------------------------
; PaintAllViews
; call WeeGUI to paint all UI elements
;
; in: WeeGUI loaded and initialized
; CreateViews has been called
; out: all registers clobbered
; all flags clobbered
; $00/$01 clobbered
;------------------------------------------------------------------------------
PaintAllViews
ldx #WGViewPaintAll ; repaint all views that can be painted automatically
jsr WeeGUI
jsr .paintTitleView
jsr .paintHRView
jsr .paintInfoView
jmp .paintDescriptionView
;------------------------------------------------------------------------------
; RepaintSomeViews
; call WeeGUI to repaint UI elements after changing the current game
;
; in: WeeGUI loaded and initialized
; CreateViews has been called
; gCurrentGame has new game index
; LoadGameInfo has been called to load new game description text
; out: all registers clobbered
; all flags clobbered
;------------------------------------------------------------------------------
RepaintSomeViews
jsr .paintInfoView
jsr .resetDescriptionViewScrolling
jmp .paintDescriptionView
;------------------------------------------------------------------------------
.paintTitleView
ldx #WGSelectView
lda #ID_TITLE
jsr WeeGUI
jsr INVERSE
ldx #WGPrint
lda #<.stringTitle
sta PARAM0
lda #>.stringTitle
sta PARAM1
jsr WeeGUI
jmp NORMAL
.paintHRView
ldx #WGSelectView
lda #ID_HR
jsr WeeGUI
ldx #WGPrint
lda #<.stringHR
sta PARAM0
lda #>.stringHR
sta PARAM1
bit MAGICRTS ; set overflow bit
jmp WeeGUI
.paintDescriptionView
ldx #WGSelectView
lda #ID_DESCRIPTION
jsr WeeGUI
lda addrDescription
ldy addrDescription+1
ldx #78
jsr .multiPrint
lda .vtab+1
cmp #10
bcs +
lda #10
+ sta $59B6 ; HACKHACKHACK set view height inside WeeGUI internals (WG_VIEWRECORDS)
rts
.paintInfoView
ldx #WGSelectView
lda #ID_INFO
jsr WeeGUI
lda addrInfo
ldy addrInfo+1
ldx #65
; note: execution falls through here
.multiPrint
sta $00
sty $01
stx .printLineLength+1
stz .htab+1
stz .vtab+1
.printLoop
lda ($00)
beq .printDone
ldx #WGSetCursor
.htab lda #$FD ; set at runtime
sta PARAM0
.vtab lda #$FD ; set at runtime
sta PARAM1
jsr WeeGUI
ldx #WGPrint
lda $00
sta PARAM0
lda $01
sta PARAM1
bit MAGICRTS ; set overflow bit
jsr WeeGUI
lda $00
clc
.printLineLength
adc #$fd ; set at runtime
sta $00
bcc +
inc $01
+ inc .vtab+1
bne .printLoop
.printDone
rts
.createButton
pla
sta $00
pla
sta $01
tax
lda #$02
clc
adc $00
bcc +
inx
+ phx
pha
ldy #$01
lda ($00),y
sta PARAM0
iny
lda ($00),y
sta PARAM1
ldx #WGCreateButton
jsr WeeGUI
ldx #WGViewSetRawTitle
lda #1
sta PARAM0
jmp WeeGUI
.resetDescriptionViewScrolling
ldx #WGSelectView
lda #ID_DESCRIPTION
jsr WeeGUI
ldx #WGScrollX
lda #0
jsr WeeGUI
ldx #WGScrollY
lda #0
jmp WeeGUI
.viewTitle
!byte ID_TITLE ; view ID
!byte 0 ; style
!byte 0 ; left
!byte 0 ; top
!byte 80 ; visible width
!byte 1 ; visible height
!byte 80 ; width
!byte 1 ; height
.stringTitle
!raw " Pitch Dark ",0
.viewPrevious
!byte ID_PREVIOUS ; view ID
!byte 1 ; left
!byte 2 ; top
!byte 17 ; width
!word callback_previous ; callback
!word .stringPrevious ; caption
.stringPrevious
!text "< "
!byte $10 ; 'P' inverse
!text "revious game",0
.viewNext
!byte ID_NEXT ; view ID
!byte 66 ; left
!byte 2 ; top
!byte 13 ; width
!word callback_next ; callback
!word .stringNext ; caption
.stringNext
!byte $0E ; 'N' inverse
!text "ext game >",0
.viewOptions
!byte ID_OPTIONS ; view ID
!byte 34 ; left
!byte 2 ; top
!byte 12 ; width
!word callback_options ; callback
!word .stringOptions
.stringOptions
!byte $13 ; 'S' inverse
!text "ettings",0
.viewHR
!byte ID_HR ; view ID
!byte 0 ; style
!byte 1 ; left
!byte 4 ; top
!byte 78 ; visible width
!byte 1 ; visible height
!byte 78 ; width
!byte 1 ; height
.stringHR
!fill 78,83
!byte 0
.viewPlay
!byte ID_PLAY ; view ID
!byte 66 ; left
!byte 6 ; top
!byte 13 ; width
!word callback_play ; callback
!word .stringPlay ; caption
.stringPlay
!byte 144
!text "lay "
!byte $67 ; 'g' inverse
!text "ame",0
.viewBoxArt
!byte ID_BOXART ; view ID
!byte 66 ; left
!byte 8 ; top
!byte 13 ; width
!word callback_boxart ; callback
!word .stringBoxArt ; caption
.stringBoxArt
!byte $01 ; 'A' inverse
!text "rtwork",0
.viewClues
!byte ID_CLUES ; view ID
!byte 66 ; left
!byte 10 ; top
!byte 13 ; width
!word callback_clues ; callback
!word .stringClues ; caption
.stringClues
!byte $08 ; 'H' inverse
!text "ints",0
.viewVersions
!byte ID_VERSIONS ; view ID
!byte 66 ; left
!byte 12 ; top
!byte 13 ; width
!word callback_versions ; callback
!word .stringVersions ; caption
.stringVersions
!byte $12 ; 'R' inverse
!text "evisions",0
.viewInfo
!byte ID_INFO ; view ID
!byte 0 ; style
!byte 0 ; left
!byte 6 ; top
!byte 65 ; visible width
!byte 6 ; visible height
!byte 65 ; width
!byte 6 ; height
.viewDescription
!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
}