- Added support for string arguments within struct parameter lists

- Added string block allocator and copier
- Added AppleSoft API for creating checkboxes and buttons
- Fixed bug with view constructors not correctly selecting the view after creation
This commit is contained in:
Quinn Dunki 2014-09-16 18:01:08 -07:00
parent 7207675b35
commit 1c9d9a7bdd
6 changed files with 177 additions and 10 deletions

View File

@ -14,7 +14,8 @@ WG_AMPVECTOR = $03f5
CHRGET = $00b1 ; Advances text point and gets character in A
CHRGOT = $00b7 ; Returns character at text pointer in A
SYNCHR = $dec0 ; Validates current character is what's in A
TXTPTR = $00b8 ; (and $b9) ; Current location in BASIC listing
TXTPTRL = $00b8 ; Current location in BASIC listing (LSB)
TXTPTRH = $00b9 ; Current location in BASIC listing (MSB)
ERROR = $d412 ; Reports error in X
CHKCOM = $debe ; Validates current character is a ',', then gets it
GETBYT = $e6f8 ; Gets an integer at text pointer, stores in X
@ -206,12 +207,17 @@ WGAmpersandStructArgument:
jsr SYNCHR ; Expect opening parenthesis
WGAmpersandStructArguments_loop:
jsr CHRGOT
cmp #'"' ; Check for string pointer
beq WGAmpersandStructArguments_string
jsr GETBYT
txa
ply
sta WGAmpersandCommandBuffer,y
phy
WGAmpersandStructArguments_nextParam:
jsr CHRGOT
cmp #')' ; All done!
beq WGAmpersandStructArguments_cleanup
@ -228,8 +234,37 @@ WGAmpersandStructArguments_fail:
jsr ERROR
bra WGAmpersandStructArguments_done
WGAmpersandStructArguments_string:
jsr CHRGET ; Consume opening quote
lda TXTPTRL ; Allocate for, and copy the string at TXTPTR
sta PARAM0
lda TXTPTRH
sta PARAM1
lda #'"' ; Specify quote as our terminator
jsr WGStoreStr
ply ; Store returned string pointer in our struct
lda PARAM1
sta WGAmpersandCommandBuffer,y
iny
lda PARAM0
sta WGAmpersandCommandBuffer,y
iny
phy
WGAmpersandStructArguments_stringLoop:
jsr CHRGET ; Consume the rest of the string
beq WGAmpersandStructArguments_stringLoopDone
cmp #'"' ; Check for closing quote
beq WGAmpersandStructArguments_stringLoopDone
bra WGAmpersandStructArguments_stringLoop
WGAmpersandStructArguments_stringLoopDone:
jsr CHRGET ; Consume closing quote
bra WGAmpersandStructArguments_nextParam
WGAmpersandStructArguments_cleanup:
jsr CHRGET ; Consume closing parenthesis
jsr CHRGET ; Consume closing parenthesis
WGAmpersandStructArguments_done:
ply
@ -341,6 +376,39 @@ WGAmpersand_WINDOW:
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_CHECKBOX
; Create a checkbox
; &CHECKBOX(id,x,y)
WGAmpersand_CHECKBOX:
jsr WGAmpersandStructArgument
jsr WGCreateCheckbox
jsr WGPaintView
jsr WGBottomCursor
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_BUTTON
; Create a button
; &BUTTON(id,x,y,width,"title")
WGAmpersand_BUTTON:
jsr WGAmpersandStructArgument
jsr WGCreateButton
lda WGAmpersandCommandBuffer+4
sta PARAM0
lda WGAmpersandCommandBuffer+5
sta PARAM1
jsr WGViewSetTitle
jsr WGPaintView
jsr WGBottomCursor
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGBottomCursor
@ -379,6 +447,11 @@ WGAmpersandCommandBufferEnd:
; Jump table for ampersand commands.
; Each row is 16 bytes (14 for name, 2 for address)
;
; Note the strange byte values amidst some strings- this is because
; all text is tokenized before we receive it, so reserved words may
; be compressed
;
WGAmpersandCommandTable:
.byte $97,0,0,0,0,0,0,0,0,0,0,0,0,0 ; HOME
@ -390,6 +463,12 @@ WGAmpersandCommandTable:
.byte "WINDOW",0,0,0,0,0,0,0,0
.addr WGAmpersand_WINDOW
.byte "CHECKBOX",0,0,0,0,0,0
.addr WGAmpersand_CHECKBOX
.byte "BUT",$c1,"N",0,0,0,0,0,0,0,0,0 ; BUTTON
.addr WGAmpersand_BUTTON
WGAmpersandCommandTableEnd:

2
gui.s
View File

@ -21,7 +21,7 @@
main:
jsr WGInit
jsr WG80
;rts
rts
;jmp tortureTestPrint
;jmp tortureTestRects

Binary file not shown.

View File

@ -71,6 +71,24 @@ WG_VIEWRECORDS:
.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
WG_STRINGS: ; Fixed-size block allocator for strings (view titles, mainly)
.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
.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
.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
.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
.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
.byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
WG_SCRATCHA:
.byte 0

View File

@ -125,7 +125,7 @@ scanHex8:
WGStrLen:
phy
ldy #$0
ldy #0
WGStrLen_loop:
lda (PARAM0),y
beq WGStrLen_done
@ -138,3 +138,64 @@ WGStrLen_done:
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGStoreStr
; Finds room in our block allocator and copies the given string.
; A: Terminator character
; PARAM0: String pointer, LSB
; PARAM1: String pointer, MSB
; Return: PARAM0: Stored string, LSB
; PARAM1: Stored string, MSB
; Side Effects: Clobbers SA
;
WGStoreStr:
sta WG_SCRATCHA
SAVE_AXY
ldx #0
ldy #0
WGStoreStr_findEmptyLoop:
lda WG_STRINGS,x
beq WGStoreStr_copy
txa
clc
adc #16 ; String blocks are 16 bytes wide
bcs WGStoreStr_noRoom
tax
bra WGStoreStr_findEmptyLoop
WGStoreStr_noRoom:
lda #0
sta PARAM0
sta PARAM1
bra WGStoreStr_done
WGStoreStr_copy:
phx ; Remember the start of our string
WGStoreStr_copyLoop:
lda (PARAM0),y
cmp WG_SCRATCHA
beq WGStoreStr_terminate
sta WG_STRINGS,x
inx
iny
cpy #15 ; Clip string to maximum block size
bne WGStoreStr_copyLoop
WGStoreStr_terminate:
lda #0 ; Terminate the stored string
sta WG_STRINGS,x
pla ; Return pointer to the start of the block
clc
adc #>WG_STRINGS
sta PARAM0
lda #0
adc #<WG_STRINGS
sta PARAM1
WGStoreStr_done:
RESTORE_AXY
rts

21
views.s
View File

@ -29,9 +29,9 @@ WGCreateView:
SAVE_ZPS
ldy #0
lda (PARAM0),y
lda (PARAM0),y ; Find our new view record
pha ; Cache view ID so we can select when we're done
jsr WGSelectView ; Find our new view record
asl
asl
asl
@ -93,6 +93,9 @@ WGCreateView:
inx
sta WG_VIEWRECORDS,x
pla
jsr WGSelectView ; Leave this as the active view
WGCreateView_done:
RESTORE_ZPS
RESTORE_AXY
@ -116,9 +119,9 @@ WGCreateCheckbox:
SAVE_ZPS
ldy #0
lda (PARAM0),y
lda (PARAM0),y ; Find our new view record
pha ; Cache view ID so we can select when we're done
jsr WGSelectView ; Find our new view record
asl
asl
asl
@ -164,6 +167,9 @@ WGCreateCheckbox:
inx
sta WG_VIEWRECORDS,x
pla
jsr WGSelectView ; Leave this as the active view
WGCreateCheckbox_done:
RESTORE_ZPS
RESTORE_AXY
@ -187,9 +193,9 @@ WGCreateButton:
SAVE_ZPS
ldy #0
lda (PARAM0),y
lda (PARAM0),y ; Find our new view record
pha ; Cache view ID so we can select when we're done
jsr WGSelectView ; Find our new view record
asl
asl
asl
@ -244,6 +250,9 @@ WGCreateButton:
inx
sta WG_VIEWRECORDS,x ; Initialize title
pla
jsr WGSelectView ; Leave this as the active view
WGCreateButton_done:
RESTORE_ZPS
RESTORE_AXY