[Coco] Wierd bug---is it my code, or BASIC?
William Astle
lost at l-w.ca
Fri Nov 14 18:38:58 EST 2025
It's your code. You don't seem to be removing the parameter string from the string stack
The ST error means the string stack (which is used to keep track of anonymous strings for garbage collection) overflowed.
On November 14, 2025 4:14:18 p.m. MST, Sean Conner via Coco <coco at maltedmedia.com> wrote:
>
> I've been playing around with extending BASIC, this time by adding new
>commands and functions to the user command interpretation table at $013E. I
>was able to add several new commands and functions, but one of my functions
>isn't quite working as intended, and I don't know if it's my code, or BASIC.
>
> Here's the function in question:
>
>FP0 equ $0050
>CHKSTR equ $B146
>RSVPSTR equ $B50F
>GIVSTR equ $B54C
>
>id jsr CHKSTR ; check we have a string
> ldy FP0+2 ; get string descriptor
> ldb ,y ; get length
> jsr RSVPSTR ; reserve some new space
> ldy 2,y ; point to actual string
> tstb ; do we have any characters?
> beq iddone ; if not, skip
>idcopy lda ,y+ ; copy the string
> sta ,x+
> decb
> bne idcopy
>iddone jmp GIVSTR ; return new string to BASIC
>
> When the code is loaded, and I do:
>
> FOR I=1 TO 100:PRINT I,ID$("ID"):NEXT
>
>I get:
>
> 1 ID
> 2 ID
> 3 ID
> 4 ID
> 5 ID
> 6 ID
> 7 ID
> 8
> ?ST ERROR
>
>But yet, if I do:
>
> I$="ID":FOR I=1 TO 100:PRINT I,ID$(I$):NEXT
>
>it runs fine (I'll spare you the 100 lines of output). As far as I can
>tell, this should work for both cases, so I'm not sure if it's my code, or
>BASIC.
>
> Attached is the minimum version that exhibits the error (and the code
>should assemble fine using any assembler---I hope). Also is the BASIC
>program to poke it into memory. It assumes a 32K DECB system. When the
>BASIC code is loaded:
>
> RUN
> EXEC&H7000
>
> To test if the code is properly loaded, you can type:
>
> XYZZY
>
>which should print out "NOTHING HAPPENS". I hope someone can help.
>
> -spc
>
More information about the Coco
mailing list