- Painting code for Checkboxes

- Painting code for Buttons
- Data structures for controls
- Support for single width and height rectangle stroking
- Abstraction of normal and inverse text printing
- Support for lowercase in hex scanning
- Creation of checkboxes and buttons
- Support for view titles
This commit is contained in:
Quinn Dunki 2014-09-05 16:31:33 -07:00
parent ef8035f244
commit f13f4b1ee2
7 changed files with 362 additions and 36 deletions

55
gui.s
View File

@ -20,21 +20,44 @@
main:
jsr begin80cols
jmp tortureTestPrint
;jmp tortureTestPrint
;jmp tortureTestRects
; jsr WGClearScreen
jsr WGClearScreen
jsr WGInverse
; lda #<testView
; sta PARAM0
; lda #>testView
; sta PARAM1
; jsr WGCreateView
lda #<testStr
sta PARAM0
lda #>testStr
sta PARAM1
jsr WGPrint
ldx #0
ldy #1
jsr WGSetCursor
lda #<testStr2
sta PARAM0
lda #>testStr2
sta PARAM1
jsr WGPrint
jmp loop
; lda #0
; jsr WGSelectView
; jsr WGPaintView
lda #<testView
sta PARAM0
lda #>testView
sta PARAM1
jsr WGCreateButton
lda #0
jsr WGSelectView
lda #<testTitle
sta PARAM0
lda #>testTitle
sta PARAM1
jsr WGViewSetTitle
jsr WGPaintView
; ldx #5
; ldy #0
@ -151,11 +174,17 @@ read80ColSwitch_40:
.include "memory.s"
;testView:
testView:
; .byte "0007033e13207e" ; 0, 7,3,62,19,126,126
; .byte "00230a"
.byte "00230a0f"
;testStr:
testStr:
; .byte "This is a test of the emergency broadcast system.",0; If this had been a real emergency, you would be dead now.",0 ; 107 chars
.byte "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_ !",34,"#$%&'()*+,-./0123456789:;<=>?`abcdefghijklmno",0
testStr2:
.byte "pqrstuvwxyz{|}~",$ff,0
testTitle:
.byte "Okay",0

Binary file not shown.

View File

@ -28,6 +28,11 @@ CHAR_NORMAL = $ff
CHAR_INVERSE = $3f
CHAR_FLASH = $7f
VIEW_STYLE_PLAIN = $00
VIEW_STYLE_FANCY = $01
VIEW_STYLE_CHECK = $02
VIEW_STYLE_BUTTON = $03
; ROM entry points
@ -57,7 +62,7 @@ WG_VIEWCLIP:
.byte 0,0,0,0,0
WG_VIEWRECORDS:
; X, Y, Screen Width, Screen Height, Style, X Offset, Y Offset, View Width, View Height
; X, Y, Screen Width, Screen Height, Style, X Offset, Y Offset, View Width, View Height, State, CallbackH, CallbackL, TitleH, TitleL
.byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

View File

@ -225,6 +225,10 @@ WGStrokeRect_horzEdge:
and #$01
bne WGStrokeRect_horzLoopOdd
lda PARAM2
cmp #1 ; Width==1 is a special case
beq WGStrokeRect_horzLoopEvenAlignedOneWidth
; CASE 1: Left edge even-aligned, even width
SETSWITCH PAGE2OFF
lda PARAM2
@ -252,8 +256,8 @@ WGStrokeRect_horzLoopEvenAligned1: ; Draw odd columns
and #$01
beq WGStrokeRect_horzLoopEvenAlignedEvenWidth
WGStrokeRect_horzLoopEvenAlignedOddWidth:
; CASE 1a: Left edge even aligned, odd width
;SETSWITCH PAGE2OFF
lda PARAM2 ; Fill in extra last column
lsr
tay
@ -272,8 +276,17 @@ WGStrokeRect_horzLoopEvenAlignedEvenWidth:
sta SCRATCH0
jmp WGStrokeRect_horzEdge
WGStrokeRect_horzLoopEvenAlignedOneWidth:
SETSWITCH PAGE2ON
bra WGStrokeRect_horzLoopEvenAlignedOddWidth
WGStrokeRect_horzLoopOdd:
; CASE 2: Left edge odd-aligned, even width
lda PARAM2
cmp #1 ; Width==1 is a special case
beq WGStrokeRect_horzLoopOddAlignedOneWidth
SETSWITCH PAGE2ON
lda PARAM2
lsr
@ -300,6 +313,7 @@ WGStrokeRect_horzLoopOddAligned1: ; Draw even columns
and #$01
beq WGStrokeRect_horzLoopOddAlignedEvenWidth
WGStrokeRect_horzLoopOddAlignedOddWidth:
; CASE 2a: Left edge odd aligned, odd width
lda PARAM2 ; Fill in extra last column
dec
@ -320,6 +334,9 @@ WGStrokeRect_horzLoopOddAlignedEvenWidth:
sta SCRATCH0
jmp WGStrokeRect_horzEdge
WGStrokeRect_horzLoopOddAlignedOneWidth:
SETSWITCH PAGE2OFF
bra WGStrokeRect_horzLoopOddAlignedOddWidth
WGStrokeRect_vertEdge:
; Left and right edges
@ -449,7 +466,7 @@ WGStrokeRect_done:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGPlot
; Plots a character at current cursor position (assumes 80 cols)
; A: Character to plot
; A: Character to plot (Apple format)
; Side effects: Clobbers S0, BASL,BASH
;
WGPlot:
@ -494,7 +511,7 @@ WGPlot_done:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGPrint
; Prints a null-terminated Apple string at the current view's
; Prints a null-terminated ASCII string at the current view's
; cursor position. Clips to current view.
; PARAM0: String pointer, LSB
; PARAM1: String pointer, MSB
@ -580,10 +597,14 @@ WGPrint_lineLoop:
WGPrint_visibleChars:
jsr WGSyncGlobalCursor
WGPrint_charLoop:
lda INVERSE
cmp #CHAR_INVERSE
beq WGPrint_charLoopInverse
WGPrint_charLoopNormal:
lda (PARAM0),y ; Draw current character
beq WGPrint_done
ora #$80
ora #%10000000
jsr WGPlot
iny
@ -595,7 +616,12 @@ WGPrint_charLoop:
beq WGPrint_nextLine
cmp WG_VIEWCLIP+2 ; Check for right clip plane
beq WGPrint_endVisible
bra WGPrint_charLoop
bra WGPrint_charLoopNormal
WGPrint_done: ; This is up here to keep local branches in range
RESTORE_ZPS
RESTORE_AXY
rts
WGPrint_endVisible:
tya
@ -617,7 +643,54 @@ WGPrint_nextLine:
sta WG_LOCALCURSORX
jmp WGPrint_lineLoop
WGPrint_done:
RESTORE_ZPS
RESTORE_AXY
WGPrint_charLoopInverse:
lda (PARAM0),y ; Draw current character
beq WGPrint_done
cmp #$60
bcc WGPrint_charLoopInverseLow
and #%01111111 ; Inverse lowercase is in alternate character set
bra WGPrint_charLoopInversePlot
WGPrint_charLoopInverseLow:
and #%00111111 ; Normal inverse
WGPrint_charLoopInversePlot: ; This is down here to keep local branches in range
jsr WGPlot
iny
inc WG_CURSORX ; Advance cursors
inc WG_LOCALCURSORX
lda WG_LOCALCURSORX
cmp WG_SCRATCHA ; Check for wrap boundary
beq WGPrint_nextLine
cmp WG_VIEWCLIP+2 ; Check for right clip plane
beq WGPrint_endVisible
bra WGPrint_charLoopInverse
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGNormal
; Sets normal text rendering mode
;
WGNormal:
pha
lda #CHAR_NORMAL
sta INVERSE
pla
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGInverse
; Sets inverse text rendering mode
;
WGInverse:
pha
lda #CHAR_INVERSE
sta INVERSE
pla
rts

View File

@ -113,9 +113,9 @@ tortureTestPrint_print:
VBL_SYNC
jsr WGEraseViewContents
lda #<testStr
lda #<unitTestStr
sta PARAM0
lda #>testStr
lda #>unitTestStr
sta PARAM1
jsr WGPrint
@ -283,5 +283,5 @@ tortureTestRectsOddDone:
testPrintView:
.byte "000F061E0A287E" ; 0, 7,3,62,19,75,126
testStr:
unitTestStr:
.byte "This is a test of the emergency broadcast system. If this had been a real emergency, you would be dead now. Amusingly, it can be noted that if this had been a real emergency, and you were now a steaming pile of ash, there would of course be nobody.",0; to read this message. That begs any number",0; of extistential questions about this very text.",0

View File

@ -68,12 +68,18 @@ delayShortInner:
; Out A: Hex value
;
scanHexDigit:
cmp #'a'
bcs scanHexDigitLowCase
cmp #'A'
bcs scanHexDigitLetter
sec
sbc #'0'
jmp scanHexDigitDone
scanHexDigitLowCase:
sec
sbc #32
scanHexDigitLetter:
sec
sbc #55
@ -90,7 +96,7 @@ scanHexDigitDone:
; Y: Offset into string
; Out A: 8-bit hex value
; Y: One past what we scanned
; Side effects: Clobbers Y and S0
; Side effects: Clobbers S0
;
scanHex8:
lda (PARAM0),y

231
views.s
View File

@ -29,7 +29,6 @@ WGCreateView:
ldy #0
jsr scanHex8
lda #0
pha
and #%00001111 ; Find our new view record
@ -86,6 +85,152 @@ WGCreateView_done:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGCreateCheckbox
; Creates a new checkbox
; PARAM0: Pointer to ASCII configuration string (LSB)
; PARAM1: Pointer to ASCII configuration string (MSB)
;
; Configuration string: "STXXYY"
; ST: (4:4) Reserved:ID
; XX: Screen X origin
; YY: Screen Y origin
;
WGCreateCheckbox:
SAVE_AXY
SAVE_ZPS
ldy #0
jsr scanHex8
and #%00001111 ; Find our new view record
asl
asl
asl
asl ; Records are 8 bytes wide
tax
jsr scanHex8
sta WG_VIEWRECORDS,x ; Screen X
inx
jsr scanHex8
sta WG_VIEWRECORDS,x ; Screen Y
inx
lda #1
sta WG_VIEWRECORDS,x ; Initialize screen width
inx
sta WG_VIEWRECORDS,x ; Initialize screen height
inx
lda #VIEW_STYLE_CHECK
sta WG_VIEWRECORDS,x ; Style
inx
lda #0 ; Initialize scrolling
sta WG_VIEWRECORDS,x
inx
sta WG_VIEWRECORDS,x
inx
lda #0
sta WG_VIEWRECORDS,x ; Initialize view width
inx
sta WG_VIEWRECORDS,x ; Initialize view height
inx
lda #%00000000 ; Initialize state
sta WG_VIEWRECORDS,x
inx
sta WG_VIEWRECORDS,x ; Initialize callback
inx
sta WG_VIEWRECORDS,x
WGCreateCheckbox_done:
RESTORE_ZPS
RESTORE_AXY
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGCreateButton
; Creates a new button
; PARAM0: Pointer to ASCII configuration string (LSB)
; PARAM1: Pointer to ASCII configuration string (MSB)
;
; Configuration string: "STXXYYBW"
; ST: (4:4) Reserved:ID
; XX: Screen X origin
; YY: Screen Y origin
; BW: Button width
WGCreateButton:
SAVE_AXY
SAVE_ZPS
ldy #0
jsr scanHex8
and #%00001111 ; Find our new view record
asl
asl
asl
asl ; Records are 8 bytes wide
tax
jsr scanHex8
sta WG_VIEWRECORDS,x ; Screen X
inx
jsr scanHex8
sta WG_VIEWRECORDS,x ; Screen Y
inx
jsr scanHex8
sta WG_VIEWRECORDS,x ; Screen width
inx
lda #1
sta WG_VIEWRECORDS,x ; Initialize screen height
inx
lda #VIEW_STYLE_BUTTON
sta WG_VIEWRECORDS,x ; Style
inx
lda #0 ; Initialize scrolling
sta WG_VIEWRECORDS,x
inx
sta WG_VIEWRECORDS,x
inx
lda #0
sta WG_VIEWRECORDS,x ; Initialize view width
inx
sta WG_VIEWRECORDS,x ; Initialize view height
inx
lda #%00000000 ; Initialize state
sta WG_VIEWRECORDS,x
inx
sta WG_VIEWRECORDS,x ; Initialize callback
inx
sta WG_VIEWRECORDS,x
inx
lda #0
sta WG_VIEWRECORDS,x ; Initialize title
inx
sta WG_VIEWRECORDS,x ; Initialize title
WGCreateButton_done:
RESTORE_ZPS
RESTORE_AXY
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGPaintView
; Paints the current view
@ -93,24 +238,72 @@ WGCreateView_done:
WGPaintView:
SAVE_AY
SAVE_ZPP
SAVE_ZPS
LDY_ACTIVEVIEW
lda WG_VIEWRECORDS+4,y ; Cache style information
sta SCRATCH0
lda WG_VIEWRECORDS,y ; Fetch the record
lda WG_VIEWRECORDS+0,y ; Fetch the geometry
sta PARAM0
iny
lda WG_VIEWRECORDS,y
lda WG_VIEWRECORDS+1,y
sta PARAM1
iny
lda WG_VIEWRECORDS,y
lda WG_VIEWRECORDS+2,y
sta PARAM2
iny
lda WG_VIEWRECORDS,y
lda WG_VIEWRECORDS+3,y
sta PARAM3
jsr WGStrokeRect
jsr WGStrokeRect ; Draw outline
lda SCRATCH0
cmp #VIEW_STYLE_CHECK
beq WGPaintView_check
cmp #VIEW_STYLE_BUTTON
beq WGPaintView_button
bra WGPaintView_done
WGPaintView_check:
lda WG_VIEWRECORDS+9,y ; Render checkbox state
beq WGPaintView_done
lda WG_VIEWRECORDS+0,y
sta WG_CURSORX
lda WG_VIEWRECORDS+1,y
sta WG_CURSORY
lda WG_VIEWRECORDS+9,y
and #$80
bne WGPaintView_checkSelected
lda #'D'
bra WGPaintView_checkPlot
WGPaintView_checkSelected:
lda #'E'
WGPaintView_checkPlot:
jsr WGPlot
bra WGPaintView_done
WGPaintView_button:
lda WG_VIEWRECORDS+13,y ; Prep the title string
sta PARAM0
lda WG_VIEWRECORDS+12,y
sta PARAM1
jsr WGStrLen ; Compute centering offset for title
lsr
sta SCRATCH1
lda WG_VIEWRECORDS+2,y
lsr
sec
sbc SCRATCH1
sta WG_LOCALCURSORX
lda #0 ; Position and print title
sta WG_LOCALCURSORY
jsr WGPrint
WGPaintView_done:
RESTORE_ZPS
RESTORE_ZPP
RESTORE_AY
rts
@ -208,6 +401,26 @@ WGSelectView_done:
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGViewSetTitle
; Sets the title of the active view
; PARAM0: Null-terminated string pointer (LSB)
; PARAM1: Null-terminated string pointer (MSB)
WGViewSetTitle:
SAVE_AXY
LDY_ACTIVEVIEW
lda PARAM0
sta WG_VIEWRECORDS+13,y
lda PARAM1
sta WG_VIEWRECORDS+12,y
WGViewSetTitle_done:
RESTORE_AXY
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGSetCursor
; Sets the current local view cursor