[Coco] A question about the BASIC statement CLEAR

Sean Conner sean at conman.org
Mon Nov 4 00:44:59 EST 2024


It was thus said that the Great Arthur Flexser via Coco once stated:
> Actually, Ciaran, your message caused me to think more about this, and now
> I'm not completely certain about the extra byte.  It's been almost 40
> years since I've done any CoCo programming.  Somebody should check the ROM
> code to find the definitive answer.

  I thought of that after posting.  So I did.  From _Color BASIC
Unravelled II_, the listing for CLEAR (any typos mine---cutting and pasting
from the PDF was problematic):

CLEAR   BEQ     LAE6F   BRANCH IF NO ARGUMENT
        JSR     LB4E6   EVALUATE ARGUMENT
        PSHS    A,B     SAVE AMOUNT OF STRING SPACE ON STAK
        LDX     MEMSIZ  GET CURRENT TOP OF CLEARED SPACE
        JSR     GETCCH  GET CURRENT INPUT CHARACTER
        BEQ     LAE5A   BRANCH IF NO NEW TOP OF CLEARED SPAC
        JSR     LB26D   SYNTAX CHECK FOR COMMA
        JSR     LB73D   EVALUATE EXPRESSION; RETURN VALUE IN X
        LEAX    -1,X    X = TOP OF CLEARED SPACE	*********
        CMPX    TOPRAM  COMPARE TO TOP OF RAM
        BHI     LAE72   OM ERROR IF > TOP OF RAM
LAE5A   TFR     X,D     ADDC = TOP OF CLEARED SPACE
        SUBD    ,S++    SUBTRACT OUT AMOUNT OF CLEARED SPACE
        BCS     LAE72   OM ERROR IF FREE MEM < 0
        TFR     D,U     U = BOTTOM OF CLEARED SPACE
        SUBD    #STKBUF SUBTRACT OUT STACK BUFFER
        BCS     LAE72   OM ERROR IF FREE MEM < 0
        SUBD    VARTAB  SUBTRACT OUT START OF VARIABLES
        BCS     LAE72   OM ERROR IF FREE MEM < 0
        STU     FRETOP  SAVE NEW BOTTOM OF CLEARED SPACE
        STX     MEMSIZ  SAVE NEW TOP OF CLEARED SPACE
LAE6F   JMP     LAD26   ERASE ALL VARIABLES, INITIALIZE POINTERS, ETC
LAE72   JMP     LAC44   OM ERROR

  The marked line with the "LEAX -1,X" tells me that the secondar parameter
is the FIRST address excluded from BASIC.  So I think that's a conclusive
answer.

  -spc


More information about the Coco mailing list