Added support for variables in widget titles

Views, buttons, and checkboxes can now all use Applesoft string variables in their title parameters. Hardcoded literals still work as well.

Also generalized the string pool allocator and added support for allocating pascal strings.
This commit is contained in:
blondie7575 2017-12-20 12:41:34 -08:00
parent 971da7c4da
commit 5202ddbeb7
4 changed files with 100 additions and 21 deletions

Binary file not shown.

View File

@ -258,13 +258,13 @@ WGAmpersandStrArgument:
ldy #0
lda #'"' ; Expect opening quote
cmp (TXTPTRL),y ; Can't use SYNERR here because it skips whitespace
bne WGAmpersandStrArgument_error
bne WGAmpersandStr_NotLiteral
inc TXTPTRL ; Can't use CHRGET here, because it skips leading whitespace (among other issues)
bne WGAmpersandStrArgument_loop_inc0
inc TXTPTRH
WGAmpersandStrArgument_loop_inc0:
WGAmpersandStrArgument_loop_inc0:
lda TXTPTRL ; Allocate for, and copy the string at TXTPTR
sta PARAM0
lda TXTPTRH
@ -276,6 +276,7 @@ WGAmpersandStrArgument_loop:
inc TXTPTRL ; Can't use CHRGET here, because it skips leading whitespace (among other issues)
bne WGAmpersandStrArgument_loop_inc1
inc TXTPTRH
WGAmpersandStrArgument_loop_inc1:
lda (TXTPTRL),y
beq WGAmpersandStrArgument_done
@ -290,8 +291,8 @@ WGAmpersandStrArgument_done:
inc TXTPTRL ; Can't use CHRGET here, because it skips leading whitespace (among other issues)
bne WGAmpersandStrArgument_loop_inc2
inc TXTPTRH
WGAmpersandStrArgument_loop_inc2:
WGAmpersandStrArgument_loop_inc2:
ldx PARAM0
ldy PARAM1
rts
@ -299,6 +300,20 @@ WGAmpersandStrArgument_loop_inc2:
WGAmpersandStrArgument_error:
jmp SYNERR
WGAmpersandStr_NotLiteral:
jsr PTRGET ; Assume string variable
ldy #0
lda (VARPNT),y ; Grab length
tax
iny
lda (VARPNT),y ; Get string pointer out of Applesoft record
sta PARAM0 ; Allocate for, and copy the string
iny
lda (VARPNT),y
sta PARAM1
jsr WGStorePascalStr
bra WGAmpersandStrArgument_loop_inc2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersandTempStrArgument

100
utility.s
View File

@ -111,6 +111,37 @@ WGStrLen_done:
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAllocStr
; Finds room in our block string allocator
; Return: PARAM0: Stored string, LSB
; PARAM1: Stored string, MSB
; Null if pool is full
; X: Pool index of free space
; Side Effects: Clobbers AX
;
WGAllocStr:
ldx #0
WGAllocStr_findEmptyLoop:
lda WG_STRINGS,x
beq WGAllocStr_done
txa
clc
adc #16 ; String blocks are 16 bytes wide
bcs WGAllocStr_noRoom
tax
bra WGAllocStr_findEmptyLoop
WGAllocStr_noRoom:
lda #0
sta PARAM0
sta PARAM1
WGAllocStr_done:
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGStoreStr
; Finds room in our block allocator and copies the given string.
@ -125,26 +156,11 @@ WGStoreStr:
sta WG_SCRATCHA
SAVE_AXY
ldx #0
jsr WGAllocStr
lda PARAM1
beq WGStoreStr_done
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:
@ -172,3 +188,51 @@ WGStoreStr_terminate:
WGStoreStr_done:
RESTORE_AXY
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGStorePascalStr
; Finds room in our block allocator and copies the given string.
; X: Length
; PARAM0: String pointer, LSB
; PARAM1: String pointer, MSB
; Return: PARAM0: Stored string, LSB
; PARAM1: Stored string, MSB
; Side Effects: Clobbers SA
;
WGStorePascalStr:
stx WG_SCRATCHA
SAVE_AXY
jsr WGAllocStr
lda PARAM1
beq WGStorePascalStr_done
ldy #0
phx ; Remember the start of our string
WGStorePascalStr_copyLoop:
cpy WG_SCRATCHA
beq WGStorePascalStr_terminate
lda (PARAM0),y
sta WG_STRINGS,x
inx
iny
cpy #15 ; Clip string to maximum block size
bne WGStorePascalStr_copyLoop
WGStorePascalStr_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
WGStorePascalStr_done:
RESTORE_AXY
rts

Binary file not shown.