enhanced basic source code

Upload: namelessu

Post on 17-Feb-2018

227 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/23/2019 Enhanced Basic Source Code

    1/147

    ; Enhanced BASIC to assemble under 6502 simulator, $ver 2.22

    ; $E7E1 $E7CF $E7C6 $E7D3 $E7D1 $E7D5 $E7CF $E81E $E825

    ; 2.00 new revision numbers start here; 2.01 fixed LCASE$() and UCASE$(); 2.02 new get value routine done; 2.03 changed RND() to galoise method; 2.04 fixed SPC(); 2.05 new get value routine fixed; 2.06 changed USR() code; 2.07 fixed STR$(); 2.08 changed INPUT and READ to remove need for $00 start to input buff

    er; 2.09 fixed RND(); 2.10 integrated missed changes from an earlier version; 2.20 added ELSE to IF .. THEN and fixed IF .. GOTO to caus

    e error; 2.21 fixed IF .. THEN RETURN to not cause error; 2.22 fixed RND() breaking the get byte routine

    ; zero page use ..

    LAB_WARM = $00 ; BASIC warm start entry point

    Wrmjpl = LAB_WARM+1; BASIC warm start vector jump low byteWrmjph = LAB_WARM+2; BASIC warm start vector jump high byte

    Usrjmp = $0A ; USR function JMP addressUsrjpl = Usrjmp+1 ; USR function JMP vector low byteUsrjph = Usrjmp+2 ; USR function JMP vector high byteNullct = $0D ; nulls output after each lineTPos = $0E ; BASIC terminal position byteTWidth = $0F ; BASIC terminal width byteIclim = $10 ; input column limitItempl = $11 ; temporary integer low byteItemph = Itempl+1 ; temporary integer high byte

    nums_1 = Itempl ; number to bin/hex string convert MSBnums_2 = nums_1+1 ; number to bin/hex string convertnums_3 = nums_1+2 ; number to bin/hex string convert LSB

    Srchc = $5B ; search characterTemp3 = Srchc ; temp byte used in number routinesScnquo = $5C ; scan-between-quotes flagAsrch = Scnquo ; alt search character

    XOAw_l = Srchc ; eXclusive OR, OR and AND word low byteXOAw_h = Scnquo ; eXclusive OR, OR and AND word high byte

    Ibptr = $5D ; input buffer pointer

    Dimcnt = Ibptr ; # of dimensionsTindx = Ibptr ; token index

    Defdim = $5E ; default DIM flagDtypef = $5F ; data type flag, $FF=string, $00=numericOquote = $60 ; open quote flag (b7) (Flag: DATA scan; LIST quote; mem

    ory)Gclctd = $60 ; garbage collected flagSufnxf = $61 ; subscript/FNX flag, 1xxx xxx = FN(0xxx xxx)Imode = $62 ; input mode flag, $00=INPUT, $80=READ

  • 7/23/2019 Enhanced Basic Source Code

    2/147

    Cflag = $63 ; comparison evaluation flag

    TabSiz = $64 ; TAB step size (was input flag)

    next_s = $65 ; next descriptor stack address

    ; these two bytes form a word pointer to the item; currently on top of the descriptor stacklast_sl = $66 ; last descriptor stack address low bytelast_sh = $67 ; last descriptor stack address high byte (always $00)

    des_sk = $68 ; descriptor stack start address (temp strings)

    ; = $70 ; End of descriptor stack

    ut1_pl = $71 ; utility pointer 1 low byteut1_ph = ut1_pl+1 ; utility pointer 1 high byteut2_pl = $73 ; utility pointer 2 low byteut2_ph = ut2_pl+1 ; utility pointer 2 high byte

    Temp_2 = ut1_pl ; temp byte for block move

    FACt_1 = $75 ; FAC temp mantissa1

    FACt_2 = FACt_1+1 ; FAC temp mantissa2FACt_3 = FACt_2+1 ; FAC temp mantissa3

    dims_l = FACt_2 ; array dimension size low bytedims_h = FACt_3 ; array dimension size high byte

    TempB = $78 ; temp page 0 byte

    Smeml = $79 ; start of mem low byte (Start-of-Basic)Smemh = Smeml+1 ; start of mem high byte (Start-of-Basic)Svarl = $7B ; start of vars low byte (Start-of-Variables)Svarh = Svarl+1 ; start of vars high byte (Start-of-Variables)Sarryl = $7D ; var mem end low byte (Start-of-Arrays)

    Sarryh = Sarryl+1 ; var mem end high byte (Start-of-Arrays)Earryl = $7F ; array mem end low byte (End-of-Arrays)Earryh = Earryl+1 ; array mem end high byte (End-of-Arrays)Sstorl = $81 ; string storage low byte (String storage (moving down))Sstorh = Sstorl+1 ; string storage high byte (String storage (movi

    ng down))Sutill = $83 ; string utility ptr low byteSutilh = Sutill+1 ; string utility ptr high byteEmeml = $85 ; end of mem low byte (Limit-of-memory)Ememh = Ememl+1 ; end of mem high byte (Limit-of-memory)Clinel = $87 ; current line low byte (Basic line number)Clineh = Clinel+1 ; current line high byte (Basic line number)Blinel = $89 ; break line low byte (Previous Basic line number)

    Blineh = Blinel+1 ; break line high byte (Previous Basic line number)

    Cpntrl = $8B ; continue pointer low byteCpntrh = Cpntrl+1 ; continue pointer high byte

    Dlinel = $8D ; current DATA line low byteDlineh = Dlinel+1 ; current DATA line high byte

    Dptrl = $8F ; DATA pointer low byte

  • 7/23/2019 Enhanced Basic Source Code

    3/147

    Dptrh = Dptrl+1 ; DATA pointer high byte

    Rdptrl = $91 ; read pointer low byteRdptrh = Rdptrl+1 ; read pointer high byte

    Varnm1 = $93 ; current var name 1st byteVarnm2 = Varnm1+1 ; current var name 2nd byte

    Cvaral = $95 ; current var address low byteCvarah = Cvaral+1 ; current var address high byte

    Frnxtl = $97 ; var pointer for FOR/NEXT low byteFrnxth = Frnxtl+1 ; var pointer for FOR/NEXT high byte

    Tidx1 = Frnxtl ; temp line index

    Lvarpl = Frnxtl ; let var pointer low byteLvarph = Frnxth ; let var pointer high byte

    prstk = $99 ; precedence stacked flag

    comp_f = $9B ; compare function flag, bits 0,1 and 2 used; bit 2 set if >; bit 1 set if =

    ; bit 0 set if = do "Out of memory" error then warm start

    ; ok exit, carry clearLAB_124BRTS

    ; do "Out of memory" error then warm start

    LAB_OMERLDX #$0C ; error code $0C ("Out of memory" error)

    ; do error #X, then warm start

    LAB_XERRJSR LAB_CRLF ; print CR/LF

    LDA LAB_BAER,X ; get error message pointer low byteLDY LAB_BAER+1,X ; get error message pointer high byte

    JSR LAB_18C3 ; print null terminated string from memory

    JSR LAB_1491 ; flush stack and clear continue flagLDA #LAB_EMSG ; point to " Error" high addrLAB_1269JSR LAB_18C3 ; print null terminated string from memoryLDY Clineh ; get current line high byteINY ; increment itBEQ LAB_1274 ; go do warm start (was immediate mode)

  • 7/23/2019 Enhanced Basic Source Code

    14/147

    ; else print line numberJSR LAB_2953 ; print " in line [LINE #]"

    ; BASIC warm start entry point; wait for Basic command

    LAB_1274; clear ON IRQ/NMI bytesLDA #$00 ; clear ASTA IrqBase ; clear enabled byteSTA NmiBase ; clear enabled byteLDA #LAB_RMSG ; point to "Ready" message high byte

    JSR LAB_18C3 ; go do print string

    ; wait for Basic command (no "Ready")

    LAB_127DJSR LAB_1357 ; call for BASIC inputLAB_1280STX Bpntrl ; set BASIC execute pointer low byteSTY Bpntrh ; set BASIC execute pointer high byte

    JSR LAB_GBYT ; scan memoryBEQ LAB_127D ; loop while null

    ; got to interpret input line now ..

    LDX #$FF ; current line to null valueSTX Clineh ; set current line high byteBCC LAB_1295 ; branch if numeric character (handle new BASIC line)

    ; no line number .. immediate modeJSR LAB_13A6 ; crunch keywords into Basic tokensJMP LAB_15F6 ; go scan and interpret code

    ; handle new BASIC line

    LAB_1295JSR LAB_GFPN ; get fixed-point number into temp integerJSR LAB_13A6 ; crunch keywords into Basic tokensSTY Ibptr ; save index pointer to end of crunched lineJSR LAB_SSLN ; search BASIC for temp integer line numberBCC LAB_12E6 ; branch if not found

    ; aroooogah! line # already exists! delete itLDY #$01 ; set index to next line pointer high byteLDA (Baslnl),Y ; get next line pointer high byteSTA ut1_ph ; save it

    LDA Svarl ; get start of vars low byteSTA ut1_pl ; save itLDA Baslnh ; get found line pointer high byteSTA ut2_ph ; save itLDA Baslnl ; get found line pointer low byteDEY ; decrement indexSBC (Baslnl),Y ; subtract next line pointer low byteCLC ; clear carry for addADC Svarl ; add start of vars low byteSTA Svarl ; save new start of vars low byte

  • 7/23/2019 Enhanced Basic Source Code

    15/147

    STA ut2_pl ; save destination pointer low byteLDA Svarh ; get start of vars high byteADC #$FF ; -1 + carrySTA Svarh ; save start of vars high byteSBC Baslnh ; subtract found line pointer high byteTAX ; copy to block countSEC ; set carry for subtractLDA Baslnl ; get found line pointer low byteSBC Svarl ; subtract start of vars low byteTAY ; copy to bytes in first block countBCS LAB_12D0 ; branch if overflow

    INX ; increment block count (correct for =0 loop exit)DEC ut2_ph ; decrement destination high byteLAB_12D0CLC ; clear carry for addADC ut1_pl ; add source pointer low byteBCC LAB_12D8 ; branch if no overflow

    DEC ut1_ph ; else decrement source pointer high byteCLC ; clear carry

    ; close up memory to delete old lineLAB_12D8

    LDA (ut1_pl),Y ; get byte from sourceSTA (ut2_pl),Y ; copy to destinationINY ; increment indexBNE LAB_12D8 ; while 0 do this block

    INC ut1_ph ; increment source pointer high byteINC ut2_ph ; increment destination pointer high byteDEX ; decrement block countBNE LAB_12D8 ; loop until all done

    ; got new line in buffer and no existing same #LAB_12E6LDA Ibuffs ; get byte from start of input buffer

    BEQ LAB_1319 ; if null line just go flush stack/vars and exit

    ; got new line and it isn't empty lineLDA Ememl ; get end of mem low byteLDY Ememh ; get end of mem high byteSTA Sstorl ; set bottom of string space low byteSTY Sstorh ; set bottom of string space high byteLDA Svarl ; get start of vars low byte (end of BASIC)STA Obendl ; save old block end low byteLDY Svarh ; get start of vars high byte (end of BASIC)STY Obendh ; save old block end high byteADC Ibptr ; add input buffer pointer (also buffer length)BCC LAB_1301 ; branch if no overflow from add

    INY ; else increment high byteLAB_1301STA Nbendl ; save new block end low byte (move to, low byte)STY Nbendh ; save new block end high byteJSR LAB_11CF ; open up space in memory; old start pointer Ostrtl,Ostrth set by the find line callLDA Earryl ; get array mem end low byteLDY Earryh ; get array mem end high byteSTA Svarl ; save start of vars low byte

  • 7/23/2019 Enhanced Basic Source Code

    16/147

    STY Svarh ; save start of vars high byteLDY Ibptr ; get input buffer pointer (also buffer length)DEY ; adjust for loop typeLAB_1311LDA Ibuffs-4,Y ; get byte from crunched lineSTA (Baslnl),Y ; save it to program memoryDEY ; decrement countCPY #$03 ; compare with first byte-1BNE LAB_1311 ; continue while count 3

    LDA Itemph ; get line # high byteSTA (Baslnl),Y ; save it to program memoryDEY ; decrement countLDA Itempl ; get line # low byteSTA (Baslnl),Y ; save it to program memoryDEY ; decrement countLDA #$FF ; set byte to allow chain rebuild. if you didn't set this; byte then a zero already here would stop the chain rebuild; as it would think it was the [EOT] marker.STA (Baslnl),Y ; save it to program memory

    LAB_1319JSR LAB_1477 ; reset execution to start, clear vars and flush stackLDX Smeml ; get start of mem low byte

    LDA Smemh ; get start of mem high byteLDY #$01 ; index to high byte of next line pointerLAB_1325STX ut1_pl ; set line start pointer low byteSTA ut1_ph ; set line start pointer high byteLDA (ut1_pl),Y ; get itBEQ LAB_133E ; exit if end of program

    ; rebuild chaining of Basic lines

    LDY #$04 ; point to first code byte of line; there is always 1 byte + [EOL] as null entries are deletedLAB_1330

    INY ; next code byteLDA (ut1_pl),Y ; get byteBNE LAB_1330 ; loop if not [EOL]

    SEC ; set carry for add + 1TYA ; copy end indexADC ut1_pl ; add to line start pointer low byteTAX ; copy to XLDY #$00 ; clear index, point to this line's next line pointerSTA (ut1_pl),Y ; set next line pointer low byteTYA ; clear AADC ut1_ph ; add line start pointer high byte + carryINY ; increment index to high byte

    STA (ut1_pl),Y ; save next line pointer low byteBCC LAB_1325 ; go do next line, branch always, carry clear

    LAB_133EJMP LAB_127D ; else we just wait for Basic command, no "Ready"

    ; print "? " and get BASIC input

    LAB_INLN

  • 7/23/2019 Enhanced Basic Source Code

    17/147

    JSR LAB_18E3 ; print "?" characterJSR LAB_18E0 ; print " "BNE LAB_1357 ; call for BASIC input and return

    ; receive line from keyboard

    ; $08 as delete key (BACKSPACE on standard keyboard)LAB_134BJSR LAB_PRNA ; go print the characterDEX ; decrement the buffer counter (delete).byte $2C ; make LDX into BIT abs

    ; call for BASIC input (main entry point)

    LAB_1357LDX #$00 ; clear BASIC line buffer pointerLAB_1359JSR V_INPT ; call scan input deviceBCC LAB_1359 ; loop if no byte

    BEQ LAB_1359 ; loop until valid input (ignore NULLs)

    CMP #$07 ; compare with [BELL]BEQ LAB_1378 ; branch if [BELL]

    CMP #$0D ; compare with [CR]BEQ LAB_1384 ; do CR/LF exit if [CR]

    CPX #$00 ; compare pointer with $00BNE LAB_1374 ; branch if not empty

    ; next two lines ignore any non print character and [SPACE] if input buffer empty

    CMP #$21 ; compare with [SP]+1BCC LAB_1359 ; if < ignore character

    LAB_1374CMP #$08 ; compare with [BACKSPACE] (delete last character)BEQ LAB_134B ; go delete last character

    LAB_1378CPX #Ibuffe-Ibuffs ; compare character count with maxBCS LAB_138E ; skip store and do [BELL] if buffer full

    STA Ibuffs,X ; else store in bufferINX ; increment pointerLAB_137FJSR LAB_PRNA ; go print the characterBNE LAB_1359 ; always loop for next character

    LAB_1384JMP LAB_1866 ; do CR/LF exit to BASIC

    ; announce buffer full

    LAB_138ELDA #$07 ; [BELL] character into ABNE LAB_137F ; go print the [BELL] but ignore input character; branch always

  • 7/23/2019 Enhanced Basic Source Code

    18/147

    ; crunch keywords into Basic tokens; position independent buffer version ..; faster, dictionary search version ....

    LAB_13A6LDY #$FF ; set save index (makes for easy math later)

    SEC ; set carry for subtractLDA Bpntrl ; get basic execute pointer low byteSBC #= go save byte then continue crunching

    CMP #'

  • 7/23/2019 Enhanced Basic Source Code

    19/147

    LAB_13D1TYA ; copy matching indexASL ; *2 (bytes per pointer)TAX ; copy to new indexLDA TAB_CHRT,X ; get keyword table pointer low byteSTA ut2_pl ; save pointer low byteLDA TAB_CHRT+1,X ; get keyword table pointer high byteSTA ut2_ph ; save pointer high byte

    LDY #$FF ; clear table pointer (make -1 for start)

    LDX TempB ; restore buffer read index

    LAB_13D6INY ; next table byteLDA (ut2_pl),Y ; get byte from tableLAB_13D8BMI LAB_13EA ; all bytes matched so go save token

    INX ; next buffer byteCMP Ibuffs,X ; compare with byte from input bufferBEQ LAB_13D6 ; go compare next if match

    BNE LAB_1417 ; branch if >< (not found keyword)

    LAB_13EALDY csidx ; restore save index

    ; save crunched to outputLAB_13ECINX ; increment buffer index (to next input byte)INY ; increment save index (to next output byte)STA Ibuffs,Y ; save byte to outputCMP #$00 ; set the flags, set carryBEQ LAB_142A ; do exit if was null [EOL]

    ; A holds token or byte here

    SBC #':' ; subtract ":" (carry set by CMP #00)BEQ LAB_13FF ; branch if it was ":" (is now $00)

    ; A now holds token-$3ACMP #TK_DATA-$3A ; compare with DATA token - $3ABNE LAB_1401 ; branch if not DATA

    ; token was : or DATALAB_13FFSTA Oquote ; save token-$3A (clear for ":", TK_DATA-$3A for DATA)LAB_1401EOR #TK_REM-$3A ; effectively subtract REM token offsetBNE LAB_13AC ; If wasn't REM then go crunch rest of line

    STA Asrch ; else was REM so set search for [EOL]

    ; loop for REM, "..." etc.LAB_1408LDA Ibuffs,X ; get byte from input bufferBEQ LAB_13EC ; branch if null [EOL]

    CMP Asrch ; compare with stored characterBEQ LAB_13EC ; branch if match (end quote)

  • 7/23/2019 Enhanced Basic Source Code

    20/147

    ; entry for copy string in quotes, don't crunchLAB_1410INY ; increment buffer save indexSTA Ibuffs,Y ; save byte to outputINX ; increment buffer read indexBNE LAB_1408 ; loop while 0 (should never be 0!)

    ; not found keyword this goLAB_1417LDX TempB ; compare has failed, restore buffer index (start byte!)

    ; now find the end of this word in the tableLAB_141BLDA (ut2_pl),Y ; get table bytePHP ; save statusINY ; increment table indexPLP ; restore byte statusBPL LAB_141B ; if not end of keyword go do next

    LDA (ut2_pl),Y ; get byte from keyword tableBNE LAB_13D8 ; go test next word if not zero byte (end of table)

    ; reached end of table with no match

    LDA Ibuffs,X ; restore byte from input bufferBPL LAB_13EA ; branch always (all bytes in buffer are $00-$7F); go save byte in output and continue crunching

    ; reached [EOL]LAB_142AINY ; increment pointerINY ; increment pointer (makes it next line pointer high byte)STA Ibuffs,Y ; save [EOL] (marks [EOT] in immediate mode)INY ; adjust for line copyINY ; adjust for line copyINY ; adjust for line copyDEC Bpntrl ; allow for increment (change if buffer starts at $xxFF)

    RTS

    ; search Basic for temp integer line number from start of mem

    LAB_SSLNLDA Smeml ; get start of mem low byteLDX Smemh ; get start of mem high byte

    ; search Basic for temp integer line number from AX; returns carry set if found; returns Baslnl/Baslnh pointer to found or next higher (not found) line

    ; old 541 new 507

    LAB_SHLNLDY #$01 ; set indexSTA Baslnl ; save low byte as currentSTX Baslnh ; save high byte as currentLDA (Baslnl),Y ; get pointer high byte from addrBEQ LAB_145F ; pointer was zero so we're done, do 'not found' exit

    LDY #$03 ; set index to line # high byteLDA (Baslnl),Y ; get line # high byte

  • 7/23/2019 Enhanced Basic Source Code

    21/147

    DEY ; decrement index (point to low byte)CMP Itemph ; compare with temporary integer high byteBNE LAB_1455 ; if skip low byte check

    LDA (Baslnl),Y ; get line # low byteCMP Itempl ; compare with temporary integer low byteLAB_1455BCS LAB_145E ; else if temp < this line, exit (passed line#)

    LAB_1456DEY ; decrement index to next line ptr high byteLDA (Baslnl),Y ; get next line pointer high byteTAX ; copy to XDEY ; decrement index to next line ptr low byteLDA (Baslnl),Y ; get next line pointer low byteBCC LAB_SHLN ; go search for line # in temp (Itempl/Itemph) from AX; (carry always clear)

    LAB_145EBEQ LAB_1460 ; exit if temp = found line #, carry is set

    LAB_145FCLC ; clear found flagLAB_1460

    RTS

    ; perform NEW

    LAB_NEWBNE LAB_1460 ; exit if not end of statement (to do syntax error)

    LAB_1463LDA #$00 ; clear ATAY ; clear YSTA (Smeml),Y ; clear first line, next line pointer, low byteINY ; increment indexSTA (Smeml),Y ; clear first line, next line pointer, high byte

    CLC ; clear carryLDA Smeml ; get start of mem low byteADC #$02 ; calculate end of BASIC low byteSTA Svarl ; save start of vars low byteLDA Smemh ; get start of mem high byteADC #$00 ; add any carrySTA Svarh ; save start of vars high byte

    ; reset execution to start, clear vars and flush stack

    LAB_1477CLC ; clear carryLDA Smeml ; get start of mem low byte

    ADC #$FF ; -1STA Bpntrl ; save BASIC execute pointer low byteLDA Smemh ; get start of mem high byteADC #$FF ; -1+carrySTA Bpntrh ; save BASIC execute pointer high byte

    ; "CLEAR" command gets here

    LAB_147ALDA Ememl ; get end of mem low byte

  • 7/23/2019 Enhanced Basic Source Code

    22/147

    LDY Ememh ; get end of mem high byteSTA Sstorl ; set bottom of string space low byteSTY Sstorh ; set bottom of string space high byteLDA Svarl ; get start of vars low byteLDY Svarh ; get start of vars high byteSTA Sarryl ; save var mem end low byteSTY Sarryh ; save var mem end high byteSTA Earryl ; save array mem end low byteSTY Earryh ; save array mem end high byteJSR LAB_161A ; perform RESTORE command

    ; flush stack and clear continue flag

    LAB_1491LDX #des_sk ; set descriptor stack pointerSTX next_s ; save descriptor stack pointerPLA ; pull return address low byteTAX ; copy return address low bytePLA ; pull return address high byteSTX LAB_SKFE ; save to cleared stackSTA LAB_SKFF ; save to cleared stackLDX #$FD ; new stack pointerTXS ; reset stackLDA #$00 ; clear byte

    STA Cpntrh ; clear continue pointer high byteSTA Sufnxf ; clear subscript/FNX flagLAB_14A6RTS

    ; perform CLEAR

    LAB_CLEARBEQ LAB_147A ; if no following token go do "CLEAR"

    ; else there was a following token (go do syntax error)RTS

    ; perform LIST [n][-m]; bigger, faster version (a _lot_ faster)

    LAB_LISTBCC LAB_14BD ; branch if next character numeric (LIST n..)

    BEQ LAB_14BD ; branch if next character [NULL] (LIST)

    CMP #TK_MINUS ; compare with token for -BNE LAB_14A6 ; exit if not - (LIST -m)

    ; LIST [[n][-m]]; this bit sets the n , if present, as the start and end

    LAB_14BDJSR LAB_GFPN ; get fixed-point number into temp integerJSR LAB_SSLN ; search BASIC for temp integer line number; (pointer in Baslnl/Baslnh)JSR LAB_GBYT ; scan memoryBEQ LAB_14D4 ; branch if no more characters

    ; this bit checks the - is presentCMP #TK_MINUS ; compare with token for -BNE LAB_1460 ; return if not "-" (will be Syntax error)

  • 7/23/2019 Enhanced Basic Source Code

    23/147

    ; LIST [n]-m; the - was there so set m as the end valueJSR LAB_IGBY ; increment and scan memoryJSR LAB_GFPN ; get fixed-point number into temp integerBNE LAB_1460 ; exit if not ok

    LAB_14D4LDA Itempl ; get temporary integer low byteORA Itemph ; OR temporary integer high byteBNE LAB_14E2 ; branch if start set

    LDA #$FF ; set for -1STA Itempl ; set temporary integer low byteSTA Itemph ; set temporary integer high byteLAB_14E2LDY #$01 ; set index for lineSTY Oquote ; clear open quote flagJSR LAB_CRLF ; print CR/LFLDA (Baslnl),Y ; get next line pointer high byte; pointer initially set by search at LAB_14BDBEQ LAB_152B ; if null all done so exitJSR LAB_1629 ; do CRTL-C check vector

    INY ; increment index for lineLDA (Baslnl),Y ; get line # low byteTAX ; copy to XINY ; increment indexLDA (Baslnl),Y ; get line # high byteCMP Itemph ; compare with temporary integer high byteBNE LAB_14FF ; branch if no high byte match

    CPX Itempl ; compare with temporary integer low byteBEQ LAB_1501 ; branch if = last line to do (< will pass next branch)

    LAB_14FF ; else ..BCS LAB_152B ; if greater all done so exit

    LAB_1501STY Tidx1 ; save index for lineJSR LAB_295E ; print XA as unsigned integerLDA #$20 ; space is the next characterLAB_1508LDY Tidx1 ; get index for lineAND #$7F ; mask top out bit of characterLAB_150CJSR LAB_PRNA ; go print the characterCMP #$22 ; was it " characterBNE LAB_1519 ; branch if not

    ; we are either entering or leaving a pair of quotesLDA Oquote ; get open quote flagEOR #$FF ; toggle itSTA Oquote ; save it backLAB_1519INY ; increment indexLDA (Baslnl),Y ; get next byteBNE LAB_152E ; branch if not [EOL] (go print character)TAY ; else clear indexLDA (Baslnl),Y ; get next line pointer low byte

  • 7/23/2019 Enhanced Basic Source Code

    24/147

    TAX ; copy to XINY ; increment indexLDA (Baslnl),Y ; get next line pointer high byteSTX Baslnl ; set pointer to line low byteSTA Baslnh ; set pointer to line high byteBNE LAB_14E2 ; go do next line if not [EOT]; else ..LAB_152BRTS

    LAB_152EBPL LAB_150C ; just go print it if not token byte

    ; else was token byte so uncrunch it (maybe)BIT Oquote ; test the open quote flagBMI LAB_150C ; just go print character if open quote set

    LDX #>LAB_KEYT ; get table address high byteASL ; *2ASL ; *4BCC LAB_152F ; branch if no carry

    INX ; else increment high byteCLC ; clear carry for add

    LAB_152FADC #

  • 7/23/2019 Enhanced Basic Source Code

    25/147

    ; perform FOR

    LAB_FORLDA #$80 ; set FNXSTA Sufnxf ; set subscript/FNX flagJSR LAB_LET ; go do LETPLA ; pull return addressPLA ; pull return addressLDA #$10 ; we need 16d bytes !JSR LAB_1212 ; check room on stack for A bytesJSR LAB_SNBS ; scan for next BASIC statement ([:] or [EOL])CLC ; clear carry for addTYA ; copy index to AADC Bpntrl ; add BASIC execute pointer low bytePHA ; push onto stackLDA Bpntrh ; get BASIC execute pointer high byteADC #$00 ; add carryPHA ; push onto stackLDA Clineh ; get current line high bytePHA ; push onto stackLDA Clinel ; get current line low bytePHA ; push onto stackLDA #TK_TO ; get "TO" tokenJSR LAB_SCCA ; scan for CHR$(A) , else do syntax error then warm start

    JSR LAB_CTNM ; check if source is numeric, else do type mismatchJSR LAB_EVNM ; evaluate expression and check is numeric,; else do type mismatchLDA FAC1_s ; get FAC1 sign (b7)ORA #$7F ; set all non sign bitsAND FAC1_1 ; and FAC1 mantissa1STA FAC1_1 ; save FAC1 mantissa1LDA #LAB_159F ; set return address high byteSTA ut1_pl ; save return address low byteSTY ut1_ph ; save return address high byteJMP LAB_1B66 ; round FAC1 and put on stack (returns to next instruction)

    LAB_159FLDA #LAB_259C ; set 1 pointer high addrJSR LAB_UFAC ; unpack memory (AY) into FAC1JSR LAB_GBYT ; scan memoryCMP #TK_STEP ; compare with STEP tokenBNE LAB_15B3 ; jump if not "STEP"

    ;.was step so ..JSR LAB_IGBY ; increment and scan memoryJSR LAB_EVNM ; evaluate expression and check is numeric,; else do type mismatchLAB_15B3

    JSR LAB_27CA ; return A=FF,C=1/-ve A=01,C=0/+veSTA FAC1_s ; set FAC1 sign (b7); this is +1 for +ve step and -1 for -ve step, in NEXT we; compare the FOR value and the TO value and return +1 if; FOR > TO, 0 if FOR = TO and -1 if FOR < TO. the value; here (+/-1) is then compared to that result and if they; are the same (+ve and FOR > TO or -ve and FOR < TO) then; the loop is doneJSR LAB_1B5B ; push sign, round FAC1 and put on stackLDA Frnxth ; get var pointer for FOR/NEXT high byte

  • 7/23/2019 Enhanced Basic Source Code

    26/147

    PHA ; push on stackLDA Frnxtl ; get var pointer for FOR/NEXT low bytePHA ; push on stackLDA #TK_FOR ; get FOR tokenPHA ; push on stack

    ; interpreter inner loop

    LAB_15C2JSR LAB_1629 ; do CRTL-C check vectorLDA Bpntrl ; get BASIC execute pointer low byteLDY Bpntrh ; get BASIC execute pointer high byte

    LDX Clineh ; continue line is $FFxx for immediate mode; ($00xx for RUN from immediate mode)INX ; increment it (now $00 if immediate mode)BEQ LAB_15D1 ; branch if null (immediate mode)

    STA Cpntrl ; save continue pointer low byteSTY Cpntrh ; save continue pointer high byteLAB_15D1LDY #$00 ; clear indexLDA (Bpntrl),Y ; get next byteBEQ LAB_15DC ; branch if null [EOL]

    CMP #':' ; compare with ":"BEQ LAB_15F6 ; branch if = (statement separator)

    LAB_15D9JMP LAB_SNER ; else syntax error then warm start

    ; have reached [EOL]LAB_15DCLDY #$02 ; set indexLDA (Bpntrl),Y ; get next line pointer high byteCLC ; clear carry for no "BREAK" messageBEQ LAB_1651 ; if null go to immediate mode (was immediate or [EOT]

    ; marker)

    INY ; increment indexLDA (Bpntrl),Y ; get line # low byteSTA Clinel ; save current line low byteINY ; increment indexLDA (Bpntrl),Y ; get line # high byteSTA Clineh ; save current line high byteTYA ; A now = 4ADC Bpntrl ; add BASIC execute pointer low byteSTA Bpntrl ; save BASIC execute pointer low byteBCC LAB_15F6 ; branch if no overflow

    INC Bpntrh ; else increment BASIC execute pointer high byteLAB_15F6JSR LAB_IGBY ; increment and scan memory

    LAB_15F9JSR LAB_15FF ; go interpret BASIC code from (Bpntrl)

    LAB_15FCJMP LAB_15C2 ; loop

  • 7/23/2019 Enhanced Basic Source Code

    27/147

    ; interpret BASIC code from (Bpntrl)

    LAB_15FFBEQ LAB_1628 ; exit if zero [EOL]

    LAB_1602ASL ; *2 bytes per vector and normalise tokenBCS LAB_1609 ; branch if was token

    JMP LAB_LET ; else go do implied LET

    LAB_1609CMP #(TK_TAB-$80)*2 ; compare normalised token * 2 with TABBCS LAB_15D9 ; branch if A>=TAB (do syntax error then warm start); only tokens before TAB can start a lineTAY ; copy to indexLDA LAB_CTBL+1,Y ; get vector high bytePHA ; onto stackLDA LAB_CTBL,Y ; get vector low bytePHA ; onto stackJMP LAB_IGBY ; jump to increment and scan memory; then "return" to vector

    ; CTRL-C check jump. this is called as a subroutine but exits back via a

    jump if a; key press is detected.

    LAB_1629JMP (VEC_CC) ; ctrl c check vector

    ; if there was a key press it gets back here ..

    LAB_1636CMP #$03 ; compare with CTRL-C

    ; perform STOP

    LAB_STOPBCS LAB_163B ; branch if token follows STOP; else just END; END

    LAB_ENDCLC ; clear the carry, indicate a normal program endLAB_163BBNE LAB_167A ; if wasn't CTRL-C or there is a following byte return

    LDA Bpntrh ; get the BASIC execute pointer high byteEOR #>Ibuffs ; compare with buffer address high byte (Cb unchanged)BEQ LAB_164F ; branch if the BASIC pointer is in the input buffer

    ; (can't continue in immediate mode)

    ; else ..EOR #>Ibuffs ; correct the bitsLDY Bpntrl ; get BASIC execute pointer low byteSTY Cpntrl ; save continue pointer low byteSTA Cpntrh ; save continue pointer high byteLAB_1647LDA Clinel ; get current line low byteLDY Clineh ; get current line high byte

  • 7/23/2019 Enhanced Basic Source Code

    28/147

    STA Blinel ; save break line low byteSTY Blineh ; save break line high byteLAB_164FPLA ; pull return address lowPLA ; pull return address highLAB_1651BCC LAB_165E ; if was program end just do warm start

    ; else ..LDA #LAB_BMSG ; point to "Break" high byteJMP LAB_1269 ; print "Break" and do warm start

    LAB_165EJMP LAB_1274 ; go do warm start

    ; perform RESTORE

    LAB_RESTOREBNE LAB_RESTOREn ; branch if next character not null (RESTORE n)

    LAB_161ASEC ; set carry for subtractLDA Smeml ; get start of mem low byte

    SBC #$01 ; -1LDY Smemh ; get start of mem high byteBCS LAB_1624 ; branch if no underflow

    LAB_uflowDEY ; else decrement high byteLAB_1624STA Dptrl ; save DATA pointer low byteSTY Dptrh ; save DATA pointer high byteLAB_1628RTS

    ; is RESTORE n

    LAB_RESTOREnJSR LAB_GFPN ; get fixed-point number into temp integerJSR LAB_SNBL ; scan for next BASIC lineLDA Clineh ; get current line high byteCMP Itemph ; compare with temporary integer high byteBCS LAB_reset_search ; branch if >= (start search from beginning)

    TYA ; else copy line index to ASEC ; set carry (+1)ADC Bpntrl ; add BASIC execute pointer low byteLDX Bpntrh ; get BASIC execute pointer high byteBCC LAB_go_search ; branch if no overflow to high byte

    INX ; increment high byteBCS LAB_go_search ; branch always (can never be carry clear)

    ; search for line # in temp (Itempl/Itemph) from start of mem pointer (Smeml)

    LAB_reset_searchLDA Smeml ; get start of mem low byteLDX Smemh ; get start of mem high byte

  • 7/23/2019 Enhanced Basic Source Code

    29/147

    ; search for line # in temp (Itempl/Itemph) from (AX)

    LAB_go_search

    JSR LAB_SHLN ; search Basic for temp integer line number from AXBCS LAB_line_found ; if carry set go set pointer

    JMP LAB_16F7 ; else go do "Undefined statement" error

    LAB_line_found; carry already set for subtractLDA Baslnl ; get pointer low byteSBC #$01 ; -1LDY Baslnh ; get pointer high byteBCS LAB_1624 ; branch if no underflow (save DATA pointer and return)

    BCC LAB_uflow ; else decrement high byte then save DATA pointer and; return (branch always)

    ; perform NULL

    LAB_NULLJSR LAB_GTBY ; get byte parameterSTX Nullct ; save new NULL count

    LAB_167ARTS

    ; perform CONT

    LAB_CONTBNE LAB_167A ; if following byte exit to do syntax error

    LDY Cpntrh ; get continue pointer high byteBNE LAB_166C ; go do continue if we can

    LDX #$1E ; error code $1E ("Can't continue" error)JMP LAB_XERR ; do error #X, then warm start

    ; we can continue so ..LAB_166CLDA #TK_ON ; set token for ONJSR LAB_IRQ ; set IRQ flagsLDA #TK_ON ; set token for ONJSR LAB_NMI ; set NMI flags

    STY Bpntrh ; save BASIC execute pointer high byteLDA Cpntrl ; get continue pointer low byteSTA Bpntrl ; save BASIC execute pointer low byteLDA Blinel ; get break line low byteLDY Blineh ; get break line high byte

    STA Clinel ; set current line low byteSTY Clineh ; set current line high byteRTS

    ; perform RUN

    LAB_RUNBNE LAB_1696 ; branch if RUN nJMP LAB_1477 ; reset execution to start, clear variables, flush stack an

    d

  • 7/23/2019 Enhanced Basic Source Code

    30/147

    ; return

    ; does RUN n

    LAB_1696JSR LAB_147A ; go do "CLEAR"BEQ LAB_16B0 ; get n and do GOTO n (branch always as CLEAR sets Z=1)

    ; perform DO

    LAB_DOLDA #$05 ; need 5 bytes for DOJSR LAB_1212 ; check room on stack for A bytesLDA Bpntrh ; get BASIC execute pointer high bytePHA ; push on stackLDA Bpntrl ; get BASIC execute pointer low bytePHA ; push on stackLDA Clineh ; get current line high bytePHA ; push on stackLDA Clinel ; get current line low bytePHA ; push on stackLDA #TK_DO ; token for DOPHA ; push on stackJSR LAB_GBYT ; scan memory

    JMP LAB_15C2 ; go do interpreter inner loop

    ; perform GOSUB

    LAB_GOSUBLDA #$05 ; need 5 bytes for GOSUBJSR LAB_1212 ; check room on stack for A bytesLDA Bpntrh ; get BASIC execute pointer high bytePHA ; push on stackLDA Bpntrl ; get BASIC execute pointer low bytePHA ; push on stackLDA Clineh ; get current line high bytePHA ; push on stack

    LDA Clinel ; get current line low bytePHA ; push on stackLDA #TK_GOSUB ; token for GOSUBPHA ; push on stackLAB_16B0JSR LAB_GBYT ; scan memoryJSR LAB_GOTO ; perform GOTO nJMP LAB_15C2 ; go do interpreter inner loop; (can't RTS, we used the stack!)

    ; perform GOTO

    LAB_GOTO

    JSR LAB_GFPN ; get fixed-point number into temp integerJSR LAB_SNBL ; scan for next BASIC lineLDA Clineh ; get current line high byteCMP Itemph ; compare with temporary integer high byteBCS LAB_16D0 ; branch if >= (start search from beginning)

    TYA ; else copy line index to ASEC ; set carry (+1)ADC Bpntrl ; add BASIC execute pointer low byteLDX Bpntrh ; get BASIC execute pointer high byte

  • 7/23/2019 Enhanced Basic Source Code

    31/147

    BCC LAB_16D4 ; branch if no overflow to high byte

    INX ; increment high byteBCS LAB_16D4 ; branch always (can never be carry)

    ; search for line # in temp (Itempl/Itemph) from start of mem pointer (Smeml)

    LAB_16D0LDA Smeml ; get start of mem low byteLDX Smemh ; get start of mem high byte

    ; search for line # in temp (Itempl/Itemph) from (AX)

    LAB_16D4JSR LAB_SHLN ; search Basic for temp integer line number from AXBCC LAB_16F7 ; if carry clear go do "Undefined statement" error; (unspecified statement)

    ; carry already set for subtractLDA Baslnl ; get pointer low byteSBC #$01 ; -1STA Bpntrl ; save BASIC execute pointer low byteLDA Baslnh ; get pointer high byte

    SBC #$00 ; subtract carrySTA Bpntrh ; save BASIC execute pointer high byteLAB_16E5RTS

    LAB_DONOKLDX #$22 ; error code $22 ("LOOP without DO" error)JMP LAB_XERR ; do error #X, then warm start

    ; perform LOOP

    LAB_LOOPTAY ; save following token

    TSX ; copy stack pointerLDA LAB_STAK+3,X ; get token byte from stackCMP #TK_DO ; compare with DO tokenBNE LAB_DONOK ; branch if no matching DO

    INX ; dump calling routine return addressINX ; dump calling routine return addressTXS ; correct stackTYA ; get saved following token backBEQ LoopAlways ; if no following token loop forever; (stack pointer in X)

    CMP #':' ; could be ':'

    BEQ LoopAlways ; if :... loop forever

    SBC #TK_UNTIL ; subtract token for UNTIL, we know carry is set hereTAX ; copy to X (if it was UNTIL then Y will be correct)BEQ DoRest ; branch if was UNTIL

    DEX ; decrement resultBNE LAB_16FC ; if not WHILE go do syntax error and warm start; only if the token was WHILE will this fail

  • 7/23/2019 Enhanced Basic Source Code

    32/147

    DEX ; set invert result byteDoRestSTX Frnxth ; save invert result byteJSR LAB_IGBY ; increment and scan memoryJSR LAB_EVEX ; evaluate expressionLDA FAC1_e ; get FAC1 exponentBEQ DoCmp ; if =0 go do straight compare

    LDA #$FF ; else set all bitsDoCmpTSX ; copy stack pointerEOR Frnxth ; EOR with invert byteBNE LoopDone ; if 0 clear stack and back to interpreter loop

    ; loop condition wasn't met so do it againLoopAlwaysLDA LAB_STAK+2,X ; get current line low byteSTA Clinel ; save current line low byteLDA LAB_STAK+3,X ; get current line high byteSTA Clineh ; save current line high byteLDA LAB_STAK+4,X ; get BASIC execute pointer low byteSTA Bpntrl ; save BASIC execute pointer low byteLDA LAB_STAK+5,X ; get BASIC execute pointer high byteSTA Bpntrh ; save BASIC execute pointer high byte

    JSR LAB_GBYT ; scan memoryJMP LAB_15C2 ; go do interpreter inner loop

    ; clear stack and back to interpreter loopLoopDoneINX ; dump DO tokenINX ; dump current line low byteINX ; dump current line high byteINX ; dump BASIC execute pointer low byteINX ; dump BASIC execute pointer high byteTXS ; correct stackJMP LAB_DATA ; go perform DATA (find : or [EOL])

    ; do the return without gosub error

    LAB_16F4LDX #$04 ; error code $04 ("RETURN without GOSUB" error).byte $2C ; makes next line BIT LAB_0EA2

    LAB_16F7 ; do undefined statement errorLDX #$0E ; error code $0E ("Undefined statement" error)JMP LAB_XERR ; do error #X, then warm start

    ; perform RETURN

    LAB_RETURN

    BNE LAB_16E5 ; exit if following token (to allow syntax error)

    LAB_16E8PLA ; dump calling routine return addressPLA ; dump calling routine return addressPLA ; pull tokenCMP #TK_GOSUB ; compare with GOSUB tokenBNE LAB_16F4 ; branch if no matching GOSUB

    LAB_16FF

  • 7/23/2019 Enhanced Basic Source Code

    33/147

    PLA ; pull current line low byteSTA Clinel ; save current line low bytePLA ; pull current line high byteSTA Clineh ; save current line high bytePLA ; pull BASIC execute pointer low byteSTA Bpntrl ; save BASIC execute pointer low bytePLA ; pull BASIC execute pointer high byteSTA Bpntrh ; save BASIC execute pointer high byte

    ; now do the DATA statement as we could be returning into; the middle of an ON GOSUB n,m,p,q line; (the return address used by the DATA statement is the one; pushed before the GOSUB was executed!)

    ; perform DATA

    LAB_DATAJSR LAB_SNBS ; scan for next BASIC statement ([:] or [EOL])

    ; set BASIC execute pointerLAB_170FTYA ; copy index to ACLC ; clear carry for addADC Bpntrl ; add BASIC execute pointer low byte

    STA Bpntrl ; save BASIC execute pointer low byteBCC LAB_1719 ; skip next if no carry

    INC Bpntrh ; else increment BASIC execute pointer high byteLAB_1719RTS

    LAB_16FCJMP LAB_SNER ; do syntax error then warm start

    ; scan for next BASIC statement ([:] or [EOL]); returns Y as index to [:] or [EOL]

    LAB_SNBSLDX #':' ; set look for character = ":".byte $2C ; makes next line BIT $00A2

    ; scan for next BASIC line; returns Y as index to [EOL]

    LAB_SNBLLDX #$00 ; set alt search character = [EOL]LDY #$00 ; set search character = [EOL]STY Asrch ; store search characterLAB_1725TXA ; get alt search character

    EOR Asrch ; toggle search character, effectively swap with $00STA Asrch ; save swapped search characterLAB_172DLDA (Bpntrl),Y ; get next byteBEQ LAB_1719 ; exit if null [EOL]

    CMP Asrch ; compare with search characterBEQ LAB_1719 ; exit if found

    INY ; increment index

  • 7/23/2019 Enhanced Basic Source Code

    34/147

    CMP #$22 ; compare current character with open quoteBNE LAB_172D ; if not open quote go get next character

    BEQ LAB_1725 ; if found go swap search character for alt search character

    ; perform IF

    LAB_IFJSR LAB_EVEX ; evaluate the expressionJSR LAB_GBYT ; scan memoryCMP #TK_THEN ; compare with THEN tokenBEQ LAB_174B ; if it was THEN go do IF

    ; wasn't IF .. THEN so must be IF .. GOTOCMP #TK_GOTO ; compare with GOTO tokenBNE LAB_16FC ; if it wasn't GOTO go do syntax error

    LDX Bpntrl ; save the basic pointer low byteLDY Bpntrh ; save the basic pointer high byteJSR LAB_IGBY ; increment and scan memoryBCS LAB_16FC ; if not numeric go do syntax error

    STX Bpntrl ; restore the basic pointer low byte

    STY Bpntrh ; restore the basic pointer high byteLAB_174BLDA FAC1_e ; get FAC1 exponentBEQ LAB_174E ; if the result was zero go look for an ELSE

    JSR LAB_IGBY ; else increment and scan memoryBCS LAB_174D ; if not numeric go do var or keyword

    LAB_174CJMP LAB_GOTO ; else was numeric so do GOTO n

    ; is var or keywordLAB_174D

    CMP #TK_RETURN ; compare the byte with the token for RETURNBNE LAB_174G ; if it wasn't RETURN go interpret BASIC code from (Bpntrl); and return to this code to process any following code

    JMP LAB_1602 ; else it was RETURN so interpret BASIC code from (Bpntrl); but don't return here

    LAB_174GJSR LAB_15FF ; interpret BASIC code from (Bpntrl)

    ; the IF was executed and there may be a following ELSE so the code needs to return

    ; here to check and ignore the ELSE if present

    LDY #$00 ; clear the indexLDA (Bpntrl),Y ; get the next BASIC byteCMP #TK_ELSE ; compare it with the token for ELSEBEQ LAB_DATA ; if ELSE ignore the following statement

    ; there was no ELSE so continue execution of IF THEN [: ]. any

    ; following ELSE will, correctly, cause a syntax error

  • 7/23/2019 Enhanced Basic Source Code

    35/147

    RTS ; else return to the interpreter inner loop

    ; perform ELSE after IF

    LAB_174ELDY #$00 ; clear the BASIC byte indexLDX #$01 ; clear the nesting depthLAB_1750INY ; increment the BASIC byte indexLDA (Bpntrl),Y ; get the next BASIC byteBEQ LAB_1753 ; if EOL go add the pointer and return

    CMP #TK_IF ; compare the byte with the token for IFBNE LAB_1752 ; if not IF token skip the depth increment

    INX ; else increment the nesting depth ..BNE LAB_1750 ; .. and continue looking

    LAB_1752CMP #TK_ELSE ; compare the byte with the token for ELSEBNE LAB_1750 ; if not ELSE token continue looking

    DEX ; was ELSE so decrement the nesting depthBNE LAB_1750 ; loop if still nested

    INY ; increment the BASIC byte index past the ELSE

    ; found the matching ELSE, now do

    LAB_1753TYA ; else copy line index to ACLC ; clear carry for addADC Bpntrl ; add the BASIC execute pointer low byteSTA Bpntrl ; save the BASIC execute pointer low byteBCC LAB_1754 ; branch if no overflow to high byte

    INC Bpntrh ; else increment the BASIC execute pointer high byte

    LAB_1754JSR LAB_GBYT ; scan memoryBCC LAB_174C ; if numeric do GOTO n; the code will return to the interpreter loop at the; tail end of the GOTO

    JMP LAB_15FF ; interpret BASIC code from (Bpntrl); the code will return to the interpreter loop at the; tail end of the

    ; perform REM, skip (rest of) line

    LAB_REM

    JSR LAB_SNBL ; scan for next BASIC lineJMP LAB_170F ; go set BASIC execute pointer and return, branch always

    LAB_16FDJMP LAB_SNER ; do syntax error then warm start

    ; perform ON

    LAB_ONCMP #TK_IRQ ; was it IRQ token ?

  • 7/23/2019 Enhanced Basic Source Code

    36/147

    BNE LAB_NOIN ; if not go check NMI

    JMP LAB_SIRQ ; else go set-up IRQ

    LAB_NOINCMP #TK_NMI ; was it NMI token ?BNE LAB_NONM ; if not go do normal ON command

    JMP LAB_SNMI ; else go set-up NMI

    LAB_NONMJSR LAB_GTBY ; get byte parameterPHA ; push GOTO/GOSUB tokenCMP #TK_GOSUB ; compare with GOSUB tokenBEQ LAB_176B ; branch if GOSUB

    CMP #TK_GOTO ; compare with GOTO tokenLAB_1767BNE LAB_16FD ; if not GOTO do syntax error then warm start

    ; next character was GOTO or GOSUB

    LAB_176B

    DEC FAC1_3 ; decrement index (byte value)BNE LAB_1773 ; branch if not zero

    PLA ; pull GOTO/GOSUB tokenJMP LAB_1602 ; go execute it

    LAB_1773JSR LAB_IGBY ; increment and scan memoryJSR LAB_GFPN ; get fixed-point number into temp integer (skip this n); (we could LDX #',' and JSR LAB_SNBL+2, then we; just BNE LAB_176B for the loop. should be quicker ..; no we can't, what if we meet a colon or [EOL]?)CMP #$2C ; compare next character with ","

    BEQ LAB_176B ; loop if ","

    LAB_177EPLA ; else pull keyword token (run out of options); also dump +/-1 pointer low byte and exitLAB_177FRTS

    ; takes n * 106 + 11 cycles where n is the number of digits

    ; get fixed-point number into temp integer

    LAB_GFPN

    LDX #$00 ; clear regSTX Itempl ; clear temporary integer low byteLAB_1785STX Itemph ; save temporary integer high byteBCS LAB_177F ; return if carry set, end of scan, character was; not 0-9

    CPX #$19 ; compare high byte with $19TAY ; ensure Zb = 0 if the branch is takenBCS LAB_1767 ; branch if >=, makes max line # 63999 because next

  • 7/23/2019 Enhanced Basic Source Code

    37/147

    ; bit does *$0A, = 64000, compare at target will fail; and do syntax error

    SBC #'0'-1 ; subtract "0", $2F + carry, from byteTAY ; copy binary digitLDA Itempl ; get temporary integer low byteASL ; *2 low byteROL Itemph ; *2 high byteASL ; *2 low byteROL Itemph ; *2 high byte, *4ADC Itempl ; + low byte, *5STA Itempl ; save itTXA ; get high byte copy to AADC Itemph ; + high byte, *5ASL Itempl ; *2 low byte, *10dROL ; *2 high byte, *10dTAX ; copy high byte back to XTYA ; get binary digit backADC Itempl ; add number low byteSTA Itempl ; save number low byteBCC LAB_17B3 ; if no overflow to high byte get next character

    INX ; else increment high byteLAB_17B3

    JSR LAB_IGBY ; increment and scan memoryJMP LAB_1785 ; loop for next character

    ; perform DEC

    LAB_DECLDA #

  • 7/23/2019 Enhanced Basic Source Code

    38/147

    IncrErrJMP LAB_1ABC ; do "Type mismatch" error then warm start

    ; perform LET

    LAB_LETJSR LAB_GVAR ; get var addressSTA Lvarpl ; save var address low byteSTY Lvarph ; save var address high byteLDA #TK_EQUAL ; get = tokenJSR LAB_SCCA ; scan for CHR$(A), else do syntax error then warm startLDA Dtypef ; get data type flag, $FF=string, $00=numericPHA ; push data type flagJSR LAB_EVEX ; evaluate expressionPLA ; pop data type flagROL ; set carry if type = stringJSR LAB_CKTM ; type match check, set C for stringBNE LAB_17D5 ; branch if string

    JMP LAB_PFAC ; pack FAC1 into variable (Lvarpl) and return

    ; string LET

    LAB_17D5LDY #$02 ; set index to pointer high byteLDA (des_pl),Y ; get string pointer high byteCMP Sstorh ; compare bottom of string space high byteBCC LAB_17F4 ; if less assign value and exit (was in program memory)

    BNE LAB_17E6 ; branch if >; else was equal so compare low bytesDEY ; decrement indexLDA (des_pl),Y ; get pointer low byteCMP Sstorl ; compare bottom of string space low byteBCC LAB_17F4 ; if less assign value and exit (was in program memory)

    ; pointer was >= to bottom of string space pointerLAB_17E6LDY des_ph ; get descriptor pointer high byteCPY Svarh ; compare start of vars high byteBCC LAB_17F4 ; branch if less (descriptor is on stack)

    BNE LAB_17FB ; branch if greater (descriptor is not on stack)

    ; else high bytes were equal so ..LDA des_pl ; get descriptor pointer low byteCMP Svarl ; compare start of vars low byteBCS LAB_17FB ; branch if >= (descriptor is not on stack)

    LAB_17F4LDA des_pl ; get descriptor pointer low byteLDY des_ph ; get descriptor pointer high byteJMP LAB_1811 ; clean stack, copy descriptor to variable and return

    ; make space and copy stringLAB_17FBLDY #$00 ; index to lengthLDA (des_pl),Y ; get string lengthJSR LAB_209C ; copy string

  • 7/23/2019 Enhanced Basic Source Code

    39/147

    LDA des_2l ; get descriptor pointer low byteLDY des_2h ; get descriptor pointer high byteSTA ssptr_l ; save descriptor pointer low byteSTY ssptr_h ; save descriptor pointer high byteJSR LAB_228A ; copy string from descriptor (sdescr) to (Sutill)LDA #FAC1_e ; get descriptor pointer high byte

    ; clean stack and assign value to string variableLAB_1811STA des_2l ; save descriptor_2 pointer low byteSTY des_2h ; save descriptor_2 pointer high byteJSR LAB_22EB ; clean descriptor stack, YA = pointerLDY #$00 ; index to lengthLDA (des_2l),Y ; get string lengthSTA (Lvarpl),Y ; copy to let string variableINY ; index to string pointer low byteLDA (des_2l),Y ; get string pointer low byteSTA (Lvarpl),Y ; copy to let string variableINY ; index to string pointer high byteLDA (des_2l),Y ; get string pointer high byteSTA (Lvarpl),Y ; copy to let string variableRTS

    ; perform GET

    LAB_GETJSR LAB_GVAR ; get var addressSTA Lvarpl ; save var address low byteSTY Lvarph ; save var address high byteJSR INGET ; get input byteLDX Dtypef ; get data type flag, $FF=string, $00=numericBMI LAB_GETS ; go get string character

    ; was numeric getTAY ; copy character to YJSR LAB_1FD0 ; convert Y to byte in FAC1

    JMP LAB_PFAC ; pack FAC1 into variable (Lvarpl) and return

    LAB_GETSPHA ; save characterLDA #$01 ; string is single byteBCS LAB_IsByte ; branch if byte received

    PLA ; string is nullLAB_IsByteJSR LAB_MSSP ; make string space A bytes long A=$AC=length,; X=$AD=Sutill=ptr low byte, Y=$AE=Sutilh=ptr high byteBEQ LAB_NoSt ; skip store if null string

    PLA ; get character backLDY #$00 ; clear indexSTA (str_pl),Y ; save byte in string (byte IS string!)LAB_NoStJSR LAB_RTST ; check for space on descriptor stack then put address; and length on descriptor stack and update stack pointers

    JMP LAB_17D5 ; do string LET and return

    ; perform PRINT

  • 7/23/2019 Enhanced Basic Source Code

    40/147

    LAB_1829JSR LAB_18C6 ; print string from Sutill/SutilhLAB_182CJSR LAB_GBYT ; scan memory

    ; PRINT

    LAB_PRINTBEQ LAB_CRLF ; if nothing following just print CR/LF

    LAB_1831CMP #TK_TAB ; compare with TAB( tokenBEQ LAB_18A2 ; go do TAB/SPC

    CMP #TK_SPC ; compare with SPC( tokenBEQ LAB_18A2 ; go do TAB/SPC

    CMP #',' ; compare with ","BEQ LAB_188B ; go do move to next TAB mark

    CMP #';' ; compare with ";"BEQ LAB_18BD ; if ";" continue with PRINT processing

    JSR LAB_EVEX ; evaluate expressionBIT Dtypef ; test data type flag, $FF=string, $00=numericBMI LAB_1829 ; branch if string

    JSR LAB_296E ; convert FAC1 to stringJSR LAB_20AE ; print " terminated string to Sutill/SutilhLDY #$00 ; clear index

    ; don't check fit if terminal width byte is zero

    LDA TWidth ; get terminal width byteBEQ LAB_185E ; skip check if zero

    SEC ; set carry for subtractSBC TPos ; subtract terminal positionSBC (des_pl),Y ; subtract string lengthBCS LAB_185E ; branch if less than terminal width

    JSR LAB_CRLF ; else print CR/LFLAB_185EJSR LAB_18C6 ; print string from Sutill/SutilhBEQ LAB_182C ; always go continue processing line

    ; CR/LF return to BASIC from BASIC input handler

    LAB_1866

    LDA #$00 ; clear byteSTA Ibuffs,X ; null terminate inputLDX #Ibuffs ; set Y to buffer start-1 high byte

    ; print CR/LF

    LAB_CRLFLDA #$0D ; load [CR]JSR LAB_PRNA ; go print the character

  • 7/23/2019 Enhanced Basic Source Code

    41/147

    LDA #$0A ; load [LF]BNE LAB_PRNA ; go print the character and return, branch always

    LAB_188BLDA TPos ; get terminal positionCMP Iclim ; compare with input column limitBCC LAB_1897 ; branch if less

    JSR LAB_CRLF ; else print CR/LF (next line)BNE LAB_18BD ; continue with PRINT processing (branch always)

    LAB_1897SEC ; set carry for subtractLAB_1898SBC TabSiz ; subtract TAB sizeBCS LAB_1898 ; loop if result was +ve

    EOR #$FF ; complement itADC #$01 ; +1 (twos complement)BNE LAB_18B6 ; always print A spaces (result is never $00)

    ; do TAB/SPCLAB_18A2PHA ; save token

    JSR LAB_SGBY ; scan and get byte parameterCMP #$29 ; is next character )BNE LAB_1910 ; if not do syntax error then warm start

    PLA ; get token backCMP #TK_TAB ; was it TAB ?BNE LAB_18B7 ; if not go do SPC

    ; calculate TAB offsetTXA ; copy integer value to ASBC TPos ; subtract terminal positionBCC LAB_18BD ; branch if result was < 0 (can't TAB backwards)

    ; print A spacesLAB_18B6TAX ; copy result to XLAB_18B7TXA ; set flags on size for SPCBEQ LAB_18BD ; branch if result was = $0, already here

    ; print X spacesLAB_18BAJSR LAB_18E0 ; print " "DEX ; decrement countBNE LAB_18BA ; loop if not all done

    ; continue with PRINT processingLAB_18BDJSR LAB_IGBY ; increment and scan memoryBNE LAB_1831 ; if more to print go do it

    RTS

    ; print null terminated string from memory

    LAB_18C3

  • 7/23/2019 Enhanced Basic Source Code

    42/147

    JSR LAB_20AE ; print " terminated string to Sutill/Sutilh

    ; print string from Sutill/Sutilh

    LAB_18C6JSR LAB_22B6 ; pop string off descriptor stack, or from top of string; space returns with A = length, X=$71=pointer low byte,; Y=$72=pointer high byteLDY #$00 ; reset indexTAX ; copy length to XBEQ LAB_188C ; exit (RTS) if null string

    LAB_18CD

    LDA (ut1_pl),Y ; get next byteJSR LAB_PRNA ; go print the characterINY ; increment indexDEX ; decrement countBNE LAB_18CD ; loop if not done yet

    RTS

    ; Print single format character; print " "

    LAB_18E0LDA #$20 ; load " ".byte $2C ; change next line to BIT LAB_3FA9

    ; print "?" character

    LAB_18E3LDA #$3F ; load "?" character

    ; print character in A; now includes the null handler; also includes infinite line length code

    ; note! some routines expect this one to exit with Zb=0

    LAB_PRNACMP #' ' ; compare with " "BCC LAB_18F9 ; branch if less (non printing)

    ; else printable characterPHA ; save the character

    ; don't check fit if terminal width byte is zero

    LDA TWidth ; get terminal widthBNE LAB_18F0 ; branch if not zero (not infinite length)

    ; is "infinite line" so check TAB position

    LDA TPos ; get positionSBC TabSiz ; subtract TAB size, carry set by CMP #$20 aboveBNE LAB_18F7 ; skip reset if different

    STA TPos ; else reset positionBEQ LAB_18F7 ; go print character

  • 7/23/2019 Enhanced Basic Source Code

    43/147

    LAB_18F0CMP TPos ; compare with terminal character positionBNE LAB_18F7 ; branch if not at end of line

    JSR LAB_CRLF ; else print CR/LFLAB_18F7INC TPos ; increment terminal positionPLA ; get character backLAB_18F9JSR V_OUTP ; output byte via output vectorCMP #$0D ; compare with [CR]BNE LAB_188A ; branch if not [CR]

    ; else print nullct nulls after the [CR]STX TempB ; save buffer indexLDX Nullct ; get null countBEQ LAB_1886 ; branch if no nulls

    LDA #$00 ; load [NULL]LAB_1880JSR LAB_PRNA ; go print the characterDEX ; decrement countBNE LAB_1880 ; loop if not all done

    LDA #$0D ; restore the character (and set the flags)LAB_1886STX TPos ; clear terminal position (X always = zero when we get here)LDX TempB ; restore buffer indexLAB_188AAND #$FF ; set the flagsLAB_188CRTS

    ; handle bad input data

    LAB_1904LDA Imode ; get input mode flag, $00=INPUT, $00=READ

    BPL LAB_1913 ; branch if INPUT (go do redo)

    LDA Dlinel ; get current DATA line low byteLDY Dlineh ; get current DATA line high byteSTA Clinel ; save current line low byteSTY Clineh ; save current line high byteLAB_1910JMP LAB_SNER ; do syntax error then warm start

    ; mode was INPUTLAB_1913LDA #LAB_REDO ; point to redo message (high addr)

    JSR LAB_18C3 ; print null terminated string from memoryLDA Cpntrl ; get continue pointer low byteLDY Cpntrh ; get continue pointer high byteSTA Bpntrl ; save BASIC execute pointer low byteSTY Bpntrh ; save BASIC execute pointer high byteRTS

    ; perform INPUT

    LAB_INPUT

  • 7/23/2019 Enhanced Basic Source Code

    44/147

    CMP #$22 ; compare next byte with open quoteBNE LAB_1934 ; branch if no prompt string

    JSR LAB_1BC1 ; print "..." stringLDA #$3B ; load A with ";"JSR LAB_SCCA ; scan for CHR$(A), else do syntax error then warm startJSR LAB_18C6 ; print string from Sutill/Sutilh

    ; done with prompt, now get dataLAB_1934JSR LAB_CKRN ; check not Direct, back here if okJSR LAB_INLN ; print "? " and get BASIC inputLDA #$00 ; set mode = INPUTCMP Ibuffs ; test first byte in bufferBNE LAB_1953 ; branch if not null input

    CLC ; was null input so clear carry to exit programJMP LAB_1647 ; go do BREAK exit

    ; perform READ

    LAB_READLDX Dptrl ; get DATA pointer low byteLDY Dptrh ; get DATA pointer high byte

    LDA #$80 ; set mode = READ

    LAB_1953STA Imode ; set input mode flag, $00=INPUT, $80=READSTX Rdptrl ; save READ pointer low byteSTY Rdptrh ; save READ pointer high byte

    ; READ or INPUT next variable from listLAB_195BJSR LAB_GVAR ; get (var) addressSTA Lvarpl ; save address low byteSTY Lvarph ; save address high byteLDA Bpntrl ; get BASIC execute pointer low byte

    LDY Bpntrh ; get BASIC execute pointer high byteSTA Itempl ; save as temporary integer low byteSTY Itemph ; save as temporary integer high byteLDX Rdptrl ; get READ pointer low byteLDY Rdptrh ; get READ pointer high byteSTX Bpntrl ; set BASIC execute pointer low byteSTY Bpntrh ; set BASIC execute pointer high byteJSR LAB_GBYT ; scan memoryBNE LAB_1988 ; branch if not null

    ; pointer was to null entryBIT Imode ; test input mode flag, $00=INPUT, $80=READBMI LAB_19DD ; branch if READ

    ; mode was INPUTJSR LAB_18E3 ; print "?" character (double ? for extended input)JSR LAB_INLN ; print "? " and get BASIC inputSTX Bpntrl ; set BASIC execute pointer low byteSTY Bpntrh ; set BASIC execute pointer high byteLAB_1985JSR LAB_GBYT ; scan memoryLAB_1988BIT Dtypef ; test data type flag, $FF=string, $00=numeric

  • 7/23/2019 Enhanced Basic Source Code

    45/147

    BPL LAB_19B0 ; branch if numeric

    ; else get stringSTA Srchc ; save search characterCMP #$22 ; was it " ?BEQ LAB_1999 ; branch if so

    LDA #':' ; else search character is ":"STA Srchc ; set new search characterLDA #',' ; other search character is ","CLC ; clear carry for addLAB_1999STA Asrch ; set second search characterLDA Bpntrl ; get BASIC execute pointer low byteLDY Bpntrh ; get BASIC execute pointer high byte

    ADC #$00 ; c is =1 if we came via the BEQ LAB_1999, else =0BCC LAB_19A4 ; branch if no execute pointer low byte rollover

    INY ; else increment high byteLAB_19A4JSR LAB_20B4 ; print Srchc or Asrch terminated string to Sutill/SutilhJSR LAB_23F3 ; restore BASIC execute pointer from temp (Btmpl/Btmph)JSR LAB_17D5 ; go do string LET

    JMP LAB_19B6 ; go check string terminator

    ; get numeric INPUTLAB_19B0JSR LAB_2887 ; get FAC1 from stringJSR LAB_PFAC ; pack FAC1 into (Lvarpl)LAB_19B6JSR LAB_GBYT ; scan memoryBEQ LAB_19C5 ; branch if null (last entry)

    CMP #',' ; else compare with ","BEQ LAB_19C2 ; branch if ","

    JMP LAB_1904 ; else go handle bad input data

    ; got good input dataLAB_19C2JSR LAB_IGBY ; increment and scan memoryLAB_19C5LDA Bpntrl ; get BASIC execute pointer low byte (temp READ/INPUT ptr)LDY Bpntrh ; get BASIC execute pointer high byte (temp READ/INPUT ptr)STA Rdptrl ; save for nowSTY Rdptrh ; save for nowLDA Itempl ; get temporary integer low byte (temp BASIC execute ptr)LDY Itemph ; get temporary integer high byte (temp BASIC execute ptr)STA Bpntrl ; set BASIC execute pointer low byte

    STY Bpntrh ; set BASIC execute pointer high byteJSR LAB_GBYT ; scan memoryBEQ LAB_1A03 ; if null go do extra ignored message

    JSR LAB_1C01 ; else scan for "," , else do syntax error then warm startJMP LAB_195B ; go INPUT next variable from list

    ; find next DATA statement or do "Out of DATA" errorLAB_19DDJSR LAB_SNBS ; scan for next BASIC statement ([:] or [EOL])

  • 7/23/2019 Enhanced Basic Source Code

    46/147

    INY ; increment indexTAX ; copy character ([:] or [EOL])BNE LAB_19F6 ; branch if [:]

    LDX #$06 ; set for "Out of DATA" errorINY ; increment index, now points to next line pointer high byteLDA (Bpntrl),Y ; get next line pointer high byteBEQ LAB_1A54 ; branch if end (eventually does error X)

    INY ; increment indexLDA (Bpntrl),Y ; get next line # low byteSTA Dlinel ; save current DATA line low byteINY ; increment indexLDA (Bpntrl),Y ; get next line # high byteINY ; increment indexSTA Dlineh ; save current DATA line high byteLAB_19F6LDA (Bpntrl),Y ; get byteINY ; increment indexTAX ; copy to XJSR LAB_170F ; set BASIC execute pointerCPX #TK_DATA ; compare with "DATA" tokenBEQ LAB_1985 ; was "DATA" so go do next READ

    BNE LAB_19DD ; go find next statement if not "DATA"

    ; end of INPUT/READ routine

    LAB_1A03LDA Rdptrl ; get temp READ pointer low byteLDY Rdptrh ; get temp READ pointer high byteLDX Imode ; get input mode flag, $00=INPUT, $80=READBPL LAB_1A0E ; branch if INPUT

    JMP LAB_1624 ; save AY as DATA pointer and return

    ; we were getting INPUT

    LAB_1A0ELDY #$00 ; clear indexLDA (Rdptrl),Y ; get next byteBNE LAB_1A1B ; error if not end of INPUT

    RTS

    ; user typed too muchLAB_1A1BLDA #LAB_IMSG ; point to extra ignored message (high addr)JMP LAB_18C3 ; print null terminated string from memory and return

    ; search the stack for FOR activity; exit with z=1 if FOR else exit with z=0

    LAB_11A1TSX ; copy stack pointerINX ; +1 pass return addressINX ; +2 pass return addressINX ; +3 pass calling routine return addressINX ; +4 pass calling routine return addressLAB_11A6

  • 7/23/2019 Enhanced Basic Source Code

    47/147

    LDA LAB_STAK+1,X ; get token byte from stackCMP #TK_FOR ; is it FOR tokenBNE LAB_11CE ; exit if not FOR token

    ; was FOR tokenLDA Frnxth ; get var pointer for FOR/NEXT high byteBNE LAB_11BB ; branch if not null

    LDA LAB_STAK+2,X ; get FOR variable pointer low byteSTA Frnxtl ; save var pointer for FOR/NEXT low byteLDA LAB_STAK+3,X ; get FOR variable pointer high byteSTA Frnxth ; save var pointer for FOR/NEXT high byteLAB_11BBCMP LAB_STAK+3,X ; compare var pointer with stacked var pointer (high by

    te)BNE LAB_11C7 ; branch if no match

    LDA Frnxtl ; get var pointer for FOR/NEXT low byteCMP LAB_STAK+2,X ; compare var pointer with stacked var pointer (low byt

    e)BEQ LAB_11CE ; exit if match found

    LAB_11C7TXA ; copy index

    CLC ; clear carry for addADC #$10 ; add FOR stack use sizeTAX ; copy back to indexBNE LAB_11A6 ; loop if not at start of stack

    LAB_11CERTS

    ; perform NEXT

    LAB_NEXTBNE LAB_1A46 ; branch if NEXT var

    LDY #$00 ; else clear YBEQ LAB_1A49 ; branch always (no variable to search for)

    ; NEXT var

    LAB_1A46JSR LAB_GVAR ; get variable addressLAB_1A49STA Frnxtl ; store variable pointer low byteSTY Frnxth ; store variable pointer high byte; (both cleared if no variable defined)JSR LAB_11A1 ; search the stack for FOR activityBEQ LAB_1A56 ; branch if found

    LDX #$00 ; else set error $00 ("NEXT without FOR" error)LAB_1A54BEQ LAB_1ABE ; do error #X, then warm start

    LAB_1A56TXS ; set stack pointer, X set by search, dumps return addresses

    TXA ; copy stack pointerSEC ; set carry for subtract

  • 7/23/2019 Enhanced Basic Source Code

    48/147

    SBC #$F7 ; point to TO varSTA ut2_pl ; save pointer to TO var for compareADC #$FB ; point to STEP var

    LDY #>LAB_STAK ; point to stack page high byteJSR LAB_UFAC ; unpack memory (STEP value) into FAC1TSX ; get stack pointer backLDA LAB_STAK+8,X ; get step signSTA FAC1_s ; save FAC1 sign (b7)LDA Frnxtl ; get FOR variable pointer low byteLDY Frnxth ; get FOR variable pointer high byteJSR LAB_246C ; add (FOR variable) to FAC1JSR LAB_PFAC ; pack FAC1 into (FOR variable)LDY #>LAB_STAK ; point to stack page high byteJSR LAB_27FA ; compare FAC1 with (Y,ut2_pl) (TO value)TSX ; get stack pointer backCMP LAB_STAK+8,X ; compare step signBEQ LAB_1A9B ; branch if = (loop complete)

    ; loop back and do it all againLDA LAB_STAK+$0D,X ; get FOR line low byteSTA Clinel ; save current line low byteLDA LAB_STAK+$0E,X ; get FOR line high byteSTA Clineh ; save current line high byte

    LDA LAB_STAK+$10,X ; get BASIC execute pointer low byteSTA Bpntrl ; save BASIC execute pointer low byteLDA LAB_STAK+$0F,X ; get BASIC execute pointer high byteSTA Bpntrh ; save BASIC execute pointer high byteLAB_1A98JMP LAB_15C2 ; go do interpreter inner loop

    ; loop complete so carry onLAB_1A9BTXA ; stack copy to AADC #$0F ; add $10 ($0F+carry) to dump FOR structureTAX ; copy back to indexTXS ; copy to stack pointer

    JSR LAB_GBYT ; scan memoryCMP #',' ; compare with ","BNE LAB_1A98 ; branch if not "," (go do interpreter inner loop)

    ; was "," so another NEXT variable to doJSR LAB_IGBY ; else increment and scan memoryJSR LAB_1A46 ; do NEXT (var)

    ; evaluate expression and check is numeric, else do type mismatch

    LAB_EVNMJSR LAB_EVEX ; evaluate expression

    ; check if source is numeric, else do type mismatch

    LAB_CTNMCLC ; destination is numeric.byte $24 ; makes next line BIT $38

    ; check if source is string, else do type mismatch

    LAB_CTSTSEC ; required type is string

  • 7/23/2019 Enhanced Basic Source Code

    49/147

    ; type match check, set C for string, clear C for numeric

    LAB_CKTMBIT Dtypef ; test data type flag, $FF=string, $00=numericBMI LAB_1ABA ; branch if data type is string

    ; else data type was numericBCS LAB_1ABC ; if required type is string do type mismatch errorLAB_1AB9RTS

    ; data type was string, now check required typeLAB_1ABABCS LAB_1AB9 ; exit if required type is string

    ; else do type mismatch errorLAB_1ABCLDX #$18 ; error code $18 ("Type mismatch" error)LAB_1ABEJMP LAB_XERR ; do error #X, then warm start

    ; evaluate expression

    LAB_EVEXLDX Bpntrl ; get BASIC execute pointer low byteBNE LAB_1AC7 ; skip next if not zero

    DEC Bpntrh ; else decrement BASIC execute pointer high byteLAB_1AC7DEC Bpntrl ; decrement BASIC execute pointer low byte

    LAB_EVEZLDA #$00 ; set null precedence (flag done)LAB_1ACCPHA ; push precedence byteLDA #$02 ; 2 bytes

    JSR LAB_1212 ; check room on stack for A bytesJSR LAB_GVAL ; get value from lineLDA #$00 ; clear ASTA comp_f ; clear compare function flagLAB_1ADBJSR LAB_GBYT ; scan memoryLAB_1ADESEC ; set carry for subtractSBC #TK_GT ; subtract token for > (lowest comparison function)BCC LAB_1AFA ; branch if < TK_GT

    CMP #$03 ; compare with ">" to "

  • 7/23/2019 Enhanced Basic Source Code

    50/147

    ; was more than one )

    STA comp_f ; save new compare function flagJSR LAB_IGBY ; increment and scan memoryJMP LAB_1ADE ; go do next character

    ; token is < ">" or > "

  • 7/23/2019 Enhanced Basic Source Code

    51/147

    DEC Bpntrh ; else decrement BASIC execute pointer high byteLAB_1B34DEC Bpntrl ; decrement BASIC execute pointer low byteTK_LT_PLUS = TK_LT-TK_PLUSLDY #TK_LT_PLUS*3 ; set offset to last operator entrySTA comp_f ; save new compare function flagBNE LAB_1B13 ; branch always

    LAB_1B3CCMP LAB_OPPT,Y ;.compare with stacked function precedenceBCS LAB_1B86 ; branch if A >=, pop FAC2 and return

    BCC LAB_1B1C ; branch always

    ;.get vector, execute function then continue evaluation

    LAB_1B43LDA LAB_OPPT+2,Y ; get function vector high bytePHA ; onto stackLDA LAB_OPPT+1,Y ; get function vector low bytePHA ; onto stack; now push sign, round FAC1 and put on stackJSR LAB_1B5B ; function will return here, then the next RTS will call; the function

    LDA comp_f ; get compare function flagPHA ; push compare evaluation byteLDA LAB_OPPT,Y ; get precedence byteJMP LAB_1ACC ; continue evaluating expression

    LAB_1B53JMP LAB_SNER ; do syntax error then warm start

    ; push sign, round FAC1 and put on stack

    LAB_1B5BPLA ; get return addr low byteSTA ut1_pl ; save it

    INC ut1_pl ; increment it (was ret-1 pushed? yes!); note! no check is made on the high byte! if the calling; routine assembles to a page edge then this all goes; horribly wrong !!!PLA ; get return addr high byteSTA ut1_ph ; save itLDA FAC1_s ; get FAC1 sign (b7)PHA ; push sign

    ; round FAC1 and put on stack

    LAB_1B66JSR LAB_27BA ; round FAC1

    LDA FAC1_3 ; get FAC1 mantissa3PHA ; push on stackLDA FAC1_2 ; get FAC1 mantissa2PHA ; push on stackLDA FAC1_1 ; get FAC1 mantissa1PHA ; push on stackLDA FAC1_e ; get FAC1 exponentPHA ; push on stackJMP (ut1_pl) ; return, sort of

  • 7/23/2019 Enhanced Basic Source Code

    52/147

    ; do functions

    LAB_1B78LDY #$FF ; flag functionPLA ; pull precedence byteLAB_1B7BBEQ LAB_1B9D ; exit if done

    LAB_1B7DCMP #$64 ; compare previous precedence with $64BEQ LAB_1B84 ; branch if was $64 (< function)

    JSR LAB_CTNM ; check if source is numeric, else do type mismatchLAB_1B84STY prstk ; save precedence stacked flag

    ; pop FAC2 and returnLAB_1B86PLA ; pop byteLSR ; shift out comparison evaluation lowest bitSTA Cflag ; save comparison evaluation flagPLA ; pop exponentSTA FAC2_e ; save FAC2 exponentPLA ; pop mantissa1

    STA FAC2_1 ; save FAC2 mantissa1PLA ; pop mantissa2STA FAC2_2 ; save FAC2 mantissa2PLA ; pop mantissa3STA FAC2_3 ; save FAC2 mantissa3PLA ; pop signSTA FAC2_s ; save FAC2 sign (b7)EOR FAC1_s ; EOR FAC1 sign (b7)STA FAC_sc ; save sign compare (FAC1 EOR FAC2)LAB_1B9DLDA FAC1_e ; get FAC1 exponentRTS

    ; print "..." string to string util area

    LAB_1BC1LDA Bpntrl ; get BASIC execute pointer low byteLDY Bpntrh ; get BASIC execute pointer high byteADC #$00 ; add carry to low byteBCC LAB_1BCA ; branch if no overflow

    INY ; increment high byteLAB_1BCAJSR LAB_20AE ; print " terminated string to Sutill/SutilhJMP LAB_23F3 ; restore BASIC execute pointer from temp and return

    ; get value from line

    LAB_GVALJSR LAB_IGBY ; increment and scan memoryBCS LAB_1BAC ; branch if not numeric character

    ; else numeric string found (e.g. 123)LAB_1BA9JMP LAB_2887 ; get FAC1 from string and return

  • 7/23/2019 Enhanced Basic Source Code

    53/147

    ; get value from line .. continued

    ; wasn't a number so ..LAB_1BACTAX ; set the flagsBMI LAB_1BD0 ; if -ve go test token values

    ; else it is either a string, number, variable or ()CMP #'$' ; compare with "$"BEQ LAB_1BA9 ; branch if "$", hex number

    CMP #'%' ; else compare with "%"BEQ LAB_1BA9 ; branch if "%", binary number

    CMP #'.' ; compare with "."BEQ LAB_1BA9 ; if so get FAC1 from string and return (e.g. was .123)

    ; it wasn't any sort of number so ..CMP #$22 ; compare with "BEQ LAB_1BC1 ; branch if open quote

    ; wasn't any sort of number so ..

    ; evaluate expression within parentheses

    CMP #'(' ; compare with "("BNE LAB_1C18 ; if not "(" get (var), return value in FAC1 and $ flag

    LAB_1BF7JSR LAB_EVEZ ; evaluate expression, no decrement

    ; all the 'scan for' routines return the character after the sought character

    ; scan for ")" , else do syntax error then warm start

    LAB_1BFB

    LDA #$29 ; load A with ")"

    ; scan for CHR$(A) , else do syntax error then warm start

    LAB_SCCALDY #$00 ; clear indexCMP (Bpntrl),Y ; check next byte is = ABNE LAB_SNER ; if not do syntax error then warm start

    JMP LAB_IGBY ; increment and scan memory then return

    ; scan for "(" , else do syntax error then warm start

    LAB_1BFELDA #$28 ; load A with "("BNE LAB_SCCA ; scan for CHR$(A), else do syntax error then warm start; (branch always)

    ; scan for "," , else do syntax error then warm start

    LAB_1C01LDA #$2C ; load A with ","BNE LAB_SCCA ; scan for CHR$(A), else do syntax error then warm start

  • 7/23/2019 Enhanced Basic Source Code

    54/147

    ; (branch always)

    ; syntax error then warm start

    LAB_SNERLDX #$02 ; error code $02 ("Syntax" error)JMP LAB_XERR ; do error #X, then warm start

    ; get value from line .. continued; do tokens

    LAB_1BD0CMP #TK_MINUS ; compare with token for -BEQ LAB_1C11 ; branch if - token (do set-up for functions)

    ; wasn't -n so ..CMP #TK_PLUS ; compare with token for +BEQ LAB_GVAL ; branch if + token (+n = n so ignore leading +)

    CMP #TK_NOT ; compare with token for NOTBNE LAB_1BE7 ; branch if not token for NOT

    ; was NOT tokenTK_EQUAL_PLUS = TK_EQUAL-TK_PLUS

    LDY #TK_EQUAL_PLUS*3 ; offset to NOT functionBNE LAB_1C13 ; do set-up for function then execute (branch always)

    ; do = compare

    LAB_EQUALJSR LAB_EVIR ; evaluate integer expression (no sign check)LDA FAC1_3 ; get FAC1 mantissa3EOR #$FF ; invert itTAY ; copy itLDA FAC1_2 ; get FAC1 mantissa2EOR #$FF ; invert itJMP LAB_AYFC ; save and convert integer AY to FAC1 and return

    ; get value from line .. continued

    ; wasn't +, -, or NOT so ..LAB_1BE7CMP #TK_FN ; compare with token for FNBNE LAB_1BEE ; branch if not token for FN

    JMP LAB_201E ; go evaluate FNx

    ; get value from line .. continued

    ; wasn't +, -, NOT or FN so ..

    LAB_1BEESBC #TK_SGN ; subtract with token for SGNBCS LAB_1C27 ; if a function token go do it

    JMP LAB_SNER ; else do syntax error

    ; set-up for functions

    LAB_1C11TK_GT_PLUS = TK_GT-TK_PLUS

  • 7/23/2019 Enhanced Basic Source Code

    55/147

    LDY #TK_GT_PLUS*3 ; set offset from base to > operatorLAB_1C13PLA ; dump return address low bytePLA ; dump return address high byteJMP LAB_1B1D ; execute function then continue evaluation

    ; variable name set-up; get (var), return value in FAC_1 and $ flag

    LAB_1C18JSR LAB_GVAR ; get (var) addressSTA FAC1_2 ; save address low byte in FAC1 mantissa2STY FAC1_3 ; save address high byte in FAC1 mantissa3LDX Dtypef ; get data type flag, $FF=string, $00=numericBMI LAB_1C25 ; if string then return (does RTS)

    LAB_1C24JMP LAB_UFAC ; unpack memory (AY) into FAC1

    LAB_1C25RTS

    ; get value from line .. continued; only functions left so ..

    ; set up function references

    ; new for V2.0+ this replaces a lot of IF .. THEN .. ELSEIF .. THEN .. that was needed

    ; to process function calls. now the function vector is computed and pushed on the stack

    ; and the preprocess offset is read. if the preprocess offset is non zero then the vector

    ; is calculated and the routine called, if not this routine just does RTS. whichever

    ; happens the RTS at the end of this routine, or the end of the preprocess routine, calls

    ; the function code

    ; this also removes some less than elegant code that was used to bypasstype checking

    ; for functions that returned strings

    LAB_1C27ASL ; *2 (2 bytes per function address)TAY ; copy to index

    LDA LAB_FTBM,Y ; get function jump vector high bytePHA ; push functions jump vector high byteLDA LAB_FTBL,Y ; get function jump vector low byte

    PHA ; push functions jump vector low byte

    LDA LAB_FTPM,Y ; get function pre process vector high byteBEQ LAB_1C56 ; skip pre process if null vector

    PHA ; push functions pre process vector high byteLDA LAB_FTPL,Y ; get function pre process vector low bytePHA ; push functions pre process vector low byte

    LAB_1C56

  • 7/23/2019 Enhanced Basic Source Code

    56/147

    RTS ; do function, or pre process, call

    ; process string expression in parenthesis

    LAB_PPFSJSR LAB_1BF7 ; process expression in parenthesisJMP LAB_CTST ; check if source is string then do function,; else do type mismatch

    ; process numeric expression in parenthesis

    LAB_PPFNJSR LAB_1BF7 ; process expression in parenthesisJMP LAB_CTNM ; check if source is numeric then do function,; else do type mismatch

    ; set numeric data type and increment BASIC execute pointer

    LAB_PPBILSR Dtypef ; clear data type flag, $FF=string, $00=numericJMP LAB_IGBY ; increment and scan memory then do function

    ; process string for LEFT$, RIGHT$ or MID$

    LAB_LRMSJSR LAB_EVEZ ; evaluate (should be string) expressionJSR LAB_1C01 ; scan for ",", else do syntax error then warm startJSR LAB_CTST ; check if source is string, else do type mismatch

    PLA ; get function jump vector low byteTAX ; save functions jump vector low bytePLA ; get function jump vector high byteTAY ; save functions jump vector high byteLDA des_ph ; get descriptor pointer high bytePHA ; push string pointer high byteLDA des_pl ; get descriptor pointer low bytePHA ; push string pointer low byte

    TYA ; get function jump vector high byte backPHA ; save functions jump vector high byteTXA ; get function jump vector low byte backPHA ; save functions jump vector low byteJSR LAB_GTBY ; get byte parameterTXA ; copy byte parameter to ARTS ; go do function

    ; process numeric expression(s) for BIN$ or HEX$

    LAB_BHSSJSR LAB_EVEZ ; process expressionJSR LAB_CTNM ; check if source is numeric, else do type mismatch

    LDA FAC1_e ; get FAC1 exponentCMP #$98 ; compare with exponent = 2^24BCS LAB_BHER ; branch if n>=2^24 (is too big)

    JSR LAB_2831 ; convert FAC1 floating-to-fixedLDX #$02 ; 3 bytes to doLAB_CFACLDA FAC1_1,X ; get byte from FAC1STA nums_1,X ; save byte to tempDEX ; decrement index

  • 7/23/2019 Enhanced Basic Source Code

    57/147

    BPL LAB_CFAC ; copy FAC1 mantissa to temp

    JSR LAB_GBYT ; get next BASIC byteLDX #$00 ; set default to no leading "0"sCMP #')' ; compare with close bracketBEQ LAB_1C54 ; if ")" go do rest of function

    JSR LAB_SCGB ; scan for "," and get byteJSR LAB_GBYT ; get last byte backCMP #')' ; is next character )BNE LAB_BHER ; if not ")" go do error

    LAB_1C54RTS ; else do function

    LAB_BHERJMP LAB_FCER ; do function call error then warm start

    ; perform EOR

    ; added operator format is the same as AND or OR, precedence is the sameas OR

    ; this bit worked first time but it took a while to sort out the operato

    r table ; pointers and offsets afterwards!

    LAB_EORJSR GetFirst ; get first integer expression (no sign check)EOR XOAw_l ; EOR with expression 1 low byteTAY ; save in YLDA FAC1_2 ; get FAC1 mantissa2EOR XOAw_h ; EOR with expression 1 high byteJMP LAB_AYFC ; save and convert integer AY to FAC1 and return

    ; perform OR

    LAB_ORJSR GetFirst ; get first integer expression (no sign check)ORA XOAw_l ; OR with expression 1 low byteTAY ; save in YLDA FAC1_2 ; get FAC1 mantissa2ORA XOAw_h ; OR with expression 1 high byteJMP LAB_AYFC ; save and convert integer AY to FAC1 and return

    ; perform AND

    LAB_ANDJSR GetFirst ; get first integer expression (no sign check)AND XOAw_l ; AND with expression 1 low byte

    TAY ; save in YLDA FAC1_2 ; get FAC1 mantissa2AND XOAw_h ; AND with expression 1 high byteJMP LAB_AYFC ; save and convert integer AY to FAC1 and return

    ; get first value for OR, AND or EOR

    GetFirstJSR LAB_EVIR ; evaluate integer expression (no sign check)LDA FAC1_2 ; get FAC1 mantissa2

  • 7/23/2019 Enhanced Basic Source Code

    58/147

    STA XOAw_h ; save itLDA FAC1_3 ; get FAC1 mantissa3STA XOAw_l ; save itJSR LAB_279B ; copy FAC2 to FAC1 (get 2nd value in expression)JSR LAB_EVIR ; evaluate integer expression (no sign check)LDA FAC1_3 ; get FAC1 mantissa3LAB_1C95RTS

    ; perform comparisons

    ; do < compare

    LAB_LTHANJSR LAB_CKTM ; type match check, set C for stringBCS LAB_1CAE ; branch if string

    ; do numeric < compareLDA FAC2_s ; get FAC2 sign (b7)ORA #$7F ; set all non sign bitsAND FAC2_1 ; and FAC2 mantissa1 (AND in sign bit)STA FAC2_1 ; save FAC2 mantissa1LDA #FAC2_e ; set pointer high byte to FAC2

    JSR LAB_27F8 ; compare FAC1 with FAC2 (AY)TAX ; copy resultJMP LAB_1CE1 ; go evaluate result

    ; do string < compareLAB_1CAELSR Dtypef ; clear data type flag, $FF=string, $00=numericDEC comp_f ; clear < bit in compare function flagJSR LAB_22B6 ; pop string off descriptor stack, or from top of string; space returns with A = length, X=pointer low byte,; Y=pointer high byteSTA str_ln ; save lengthSTX str_pl ; save string pointer low byte

    STY str_ph ; save string pointer high byteLDA FAC2_2 ; get descriptor pointer low byteLDY FAC2_3 ; get descriptor pointer high byteJSR LAB_22BA ; pop (YA) descriptor off stack or from top of string space; returns with A = length, X=pointer low byte,; Y=pointer high byteSTX FAC2_2 ; save string pointer low byteSTY FAC2_3 ; save string pointer high byteTAX ; copy lengthSEC ; set carry for subtractSBC str_ln ; subtract string 1 lengthBEQ LAB_1CD6 ; branch if str 1 length = string 2 length

    LDA #$01 ; set str 1 length > string 2 lengthBCC LAB_1CD6 ; branch if so

    LDX str_ln ; get string 1 lengthLDA #$FF ; set str 1 length < string 2 lengthLAB_1CD6STA FAC1_s ; save length compareLDY #$FF ; set indexINX ; adjust for loopLAB_1CDB

  • 7/23/2019 Enhanced Basic Source Code

    59/147

    INY ; increment indexDEX ; decrement countBNE LAB_1CE6 ; branch if still bytes to do

    LDX FAC1_s ; get length compare backLAB_1CE1BMI LAB_1CF2 ; branch if str 1 < str 2

    CLC ; flag str 1 string 2LAB_1CF2INX ; x = 0, 1 or 2TXA ; copy to AROL ; *2 (1, 2 or 4)

    AND Cflag ; AND with comparison evaluation flagBEQ LAB_1CFB ; branch if 0 (compare is false)

    LDA #$FF ; else set result trueLAB_1CFBJMP LAB_27DB ; save A as integer byte and return

    LAB_1CFEJSR LAB_1C01 ; scan for ",", else do syntax error then warm start

    ; perform DIM

    LAB_DIM

    TAX ; copy "DIM" flag to XJSR LAB_1D10 ; search for variableJSR LAB_GBYT ; scan memoryBNE LAB_1CFE ; scan for "," and loop if not null

    RTS

    ; perform =

    Ls_loopASL FAC1_3 ; shift low byteROL ; shift high byteDEX ; decrement bit countBNE Ls_loop ; loop if shift not complete

  • 7/23/2019 Enhanced Basic Source Code

    60/147

    LDY FAC1_3 ; get expression low byteJMP LAB_AYFC ; save and convert integer AY to FAC1 and return

    ; perform >> (right shift)

    LAB_RSHIFTJSR GetPair ; get integer expression and byte (no sign check)LDA FAC1_2 ; get expression high byteLDX TempB ; get shift countBEQ NoShift ; branch if zero

    CPX #$10 ; compare bit count with 16dBCS TooBig ; branch if >=

    Rs_loopLSR ; shift high byteROR FAC1_3 ; shift low byteDEX ; decrement bit countBNE Rs_loop ; loop if shift not complete

    NoShiftLDY FAC1_3 ; get expression low byteJMP LAB_AYFC ; save and convert integer AY to FAC1 and return

    TooBigLDA #$00 ; clear high byteTAY ; copy to low byteJMP LAB_AYFC ; save and convert integer AY to FAC1 and return

    GetPairJSR LAB_EVBY ; evaluate byte expression, result in XSTX TempB ; save itJSR LAB_279B ; copy FAC2 to FAC1 (get 2nd value in expression)JMP LAB_EVIR ; evaluate integer expression (no sign check)

    ; search for variable

    ; return pointer to variable in Cvaral/Cvarah

    LAB_GVARLDX #$00 ; set DIM flag = $00JSR LAB_GBYT ; scan memory (1st character)LAB_1D10STX Defdim ; save DIM flagLAB_1D12STA Varnm1 ; save 1st characterAND #$7F ; clear FN flag bitJSR LAB_CASC ; check byte, return C=0 if"Z"BCS LAB_1D1F ; branch if ok

    JMP LAB_SNER ; else syntax error then warm start

    ; was variable name so ..LAB_1D1FLDX #$00 ; clear 2nd character tempSTX Dtypef ; clear data type flag, $FF=string, $00=numericJSR LAB_IGBY ; increment and scan memory (2nd character)BCC LAB_1D2D ; branch if character = "0"-"9" (ok)

  • 7/23/2019 Enhanced Basic Source Code

    61/147

    ; 2nd character wasn't "0" to "9" so ..JSR LAB_CASC ; check byte, return C=0 if"Z"BCC LAB_1D38 ; branch if "Z" (go check if string)

    LAB_1D2DTAX ; copy 2nd character

    ; ignore further (valid) characters in the variable nameLAB_1D2EJSR LAB_IGBY ; increment and scan memory (3rd character)BCC LAB_1D2E ; loop if character = "0"-"9" (ignore)

    JSR LAB_CASC ; check byte, return C=0 if"Z"BCS LAB_1D2E ; loop if character = "A"-"Z" (ignore)

    ; check if string variableLAB_1D38CMP #'$' ; compare with "$"BNE LAB_1D47 ; branch if not string

    ; to introduce a new variable type (% suffix for integers say) then thisbranch

    ; will need to go to that check and then that branch, if it fails, go toLAB_1D47

    ; type is stringLDA #$FF ; set data type = stringSTA Dtypef ; set data type flag, $FF=string, $00=numericTXA ; get 2nd character backORA #$80 ; set top bit (indicate string var)TAX ; copy back to 2nd character tempJSR LAB_IGBY ; increment and scan memory

    ; after we have determined the variable type we need to come back here to determine

    ; if it's an array of type. this would plug in a%(b[,c[,d]])) integer arrays nicely

    LAB_1D47 ; gets here with character after var name in ASTX Varnm2 ; save 2nd characterORA Sufnxf ; or with subscript/FNX flag (or FN name)CMP #'(' ; compare with "("BNE LAB_1D53 ; branch if not "("

    JMP LAB_1E17 ; go find, or make, array

    ; either find or create var; var name (1st two characters only!) is in Varnm1,Varnm2

    ; variable name wasn't var(... so look for plain varLAB_1D53LDA #$00 ; clear ASTA Sufnxf ; clear subscript/FNX flagLDA Svarl ; get start of vars low byteLDX Svarh ; get start of vars high byteLDY #$00 ; clear indexLAB_1D5DSTX Vrschh ; save search address high byteLAB_1D5F

  • 7/23/2019 Enhanced Basic Source Code

    62/147

    STA Vrschl ; save search address low byteCPX Sarryh ; compare high address with var space endBNE LAB_1D69 ; skip next compare if

    ; high addresses were = so compare low addressesCMP Sarryl ; compare low address with var space endBEQ LAB_1D8B ; if not found go make new var

    LAB_1D69LDA Varnm1 ; get 1st character of var to findCMP (Vrschl),Y ; compare with variable name 1st characterBNE LAB_1D77 ; branch if no match

    ; 1st characters match so compare 2nd charactersLDA Varnm2 ; get 2nd character of var to findINY ; index to point to variable name 2nd characterCMP (Vrschl),Y ; compare with variable name 2nd characterBEQ LAB_1DD7 ; branch if match (found var)

    DEY ; else decrement index (now = $00)LAB_1D77CLC ; clear carry for addLDA Vrschl ; get search address low byteADC #$06 ; +6 (offset to next var name)

    BCC LAB_1D5F ; loop if no overflow to high byte

    INX ; else increment high byteBNE LAB_1D5D ; loop always (RAM doesn't extend to $FFFF !)

    ; check byte, return C=0 if"Z" or "a" to "z"

    LAB_CASCCMP #'a' ; compare with "a"BCS LAB_1D83 ; go check $5ALAB_1D8ARTS

    LAB_1D83

    SBC #$7B ; subtract "z"+1SEC ; set carrySBC #$85 ; subtract $85 (restore byte); carry clear if byte>$7ARTS

    ; reached end of variable mem without match; .. so create new variableLAB_1D8BPLA ; pop return address low byte

  • 7/23/2019 Enhanced Basic Source Code

    63/147

    PHA ; push return address low byteLAB_1C18p2 = LAB_1C18+2CMP #

  • 7/23/2019 Enhanced Basic Source Code

    64/147

    LDA Varnm1 ; get var name 1st characterSTA (Vrschl),Y ; save var name 1st characterINY ; increment indexLDA Varnm2 ; get var name 2nd characterSTA (Vrschl),Y ; save var name 2nd characterLDA #$00 ; clear AINY ; increment indexSTA (Vrschl),Y ; initialise var byteINY ; increment indexSTA (Vrschl),Y ; initialise var byteINY ; increment indexSTA (Vrschl),Y ; initialise var byteINY ; increment indexSTA (Vrschl),Y ; initialise var byte

    ; found a match for var ((Vrschl) = ptr)LAB_1DD7LDA Vrschl ; get var address low byteCLC ; clear carry for addADC #$02 ; +2 (offset past var name bytes)LDY Vrschh ; get var address high byteBCC LAB_1DE1 ; branch if no overflow from add

    INY ; else increment high byte

    LAB_1DE1STA Cvaral ; save current var address low byteSTY Cvarah ; save current var address high byteRTS

    ; set-up array pointer (Adatal/h) to first element in array; set Adatal,Adatah to Astrtl,Astrth+2*Dimcnt+#$05

    LAB_1DE6LDA Dimcnt ; get # of dimensions (1, 2 or 3)ASL ; *2 (also clears the carry !)ADC #$05 ; +5 (result is 7, 9 or 11 here)ADC Astrtl ; add array start pointer low byte

    LDY Astrth ; get array pointer high byteBCC LAB_1DF2 ; branch if no overflow

    INY ; else increment high byteLAB_1DF2STA Adatal ; save array data pointer low byteSTY Adatah ; save array data pointer high byteRTS

    ; evaluate integer expression

    LAB_EVINJSR LAB_IGBY ; increment and scan memory

    JSR LAB_EVNM ; evaluate expression and check is numeric,; else do type mismatch

    ; evaluate integer expression (no check)

    LAB_EVPILDA FAC1_s ; get FAC1 sign (b7)BMI LAB_1E12 ; do function call error if -ve

    ; evaluate integer expression (no sign check)

  • 7/23/2019 Enhanced Basic Source Code

    65/147

    LAB_EVIRLDA FAC1_e ; get FAC1 exponentCMP #$90 ; compare with exponent = 2^16 (n>2^15)BCC LAB_1E14 ; branch if n

  • 7/23/2019 Enhanced Basic Source Code

    66/147

    STA Defdim ; restore DIM flagLDX Sarryl ; get array mem start low byteLDA Sarryh ; get array mem start high byte

    ; now check to see if we are at the end of array memory (we would be ifthere were

    ; no arrays).

    LAB_1E5CSTX Astrtl ; save as array start pointer low byteSTA Astrth ; save as array start pointer high byteCMP Earryh ; compare with array mem end high byteBNE LAB_1E68 ; branch if not reached array mem end

    CPX Earryl ; else compare with array mem end low byteBEQ LAB_1EA1 ; go build array if not found

    ; search for arrayLAB_1E68LDY #$00 ; clear indexLDA (Astrtl),Y ; get array name first byteINY ; increment index to second name byteCMP Varnm1 ; compare with this array name first byteBNE LAB_1E77 ; branch if no match

    LDA Varnm2 ; else get this array name second byteCMP (Astrtl),Y ; compare with array name second byteBEQ LAB_1E8D ; array found so branch

    ; no matchLAB_1E77INY ; increment indexLDA (Astrtl),Y ; get array size low byteCLC ; cl