8-Bit Software Online Conversion

Detokenise BBC BASIC Program - Listing

10REM > Detoken 20: 30OSWRCH=&FFEE 40: 50tbase=&A8:tptr=&AA:REM workspace if running as a *command 60tbase=&70:tptr=&72:REM workspace if calling from BASIC 70: 80DIM mcode% &100 90FOR P=0 TO 1 100P%=mcode% 110[OPT P*3 120½ ================================= = 130½ TokenInit - Find BASIC token tabl e 140½ ================================= = 150½ On entry, BASIC ROM must be paged in 160½ On exit, tbase=>Start of token t able 170½ A,Y,tptr corrupted, X p reserved 180½ In RAM-based code this can be ove rwritten after being called 190½ 200.TokenInit 210LDY #0:STY tptr:LDA #&80:STA tptr+1 :½ tptr=>ROM start 220.TokInitLp 230LDA #1:CLC:ADC tptr:STA tptr :½ Inc. tptr 240LDA #0:TAY:ADC tptr+1:STA tptr+1 250LDA (tptr),Y:CMP #&80:BEQ TokInit2: DEY :½ Found &80 260.TokInit2 270INY:LDA (tptr),Y:CMP #ASC"A":BNE To kInitLp :½ Not "A" 280INY:LDA (tptr),Y:CMP #ASC"N":BNE To kInitLp :½ Not "AN" 290INY:LDA (tptr),Y:CMP #ASC"D":BNE To kInitLp :½ Not "AND" 300.TokInitOk 310LDA tptr:STA tbase:LDA tptr+1:STA t base+1 320RTS 330: 340: 350½ ============================= 360½ PrToken - Print a BASIC token 370½ ============================= 380½ On entry, A=token byte 390½ BASIC ROM must be paged in 400½ tbase=>Start of token t able, set by TokenInit 410½ On exit, A,Y,tptr corrupted, X p reserved 420½ 430.TokenPrint 440PHA:LDA tbase:STA tptr :½ Point to start token table 450LDA tbase+1:STA tptr+1 460.TokPrLp1 470LDY #&FF 480.TokPrLp2 490INY:LDA (tptr),Y:BPL TokPrLp2 :½ Loop until token byte found 500PLA:CMP (tptr),Y:BEQ TokPrFound :½ Found matching token 510PHA:TYA:BNE TokPrStep :½ Step to next token 520.TokPrLp3 530INY:LDA (tptr),Y:BPL TokPrLp3 :½ Find next token byte 540DEY:DEY 550.TokPrStep 560INY:TYA:SEC:ADC tptr:STA tptr :½ Step past this token string 570LDA #0:ADC tptr+1:STA tptr+1 580BNE TokPrLp1 :½ Loop to keep searching 590.TokPrFound 600TYA:BEQ TokPrNxt:LDY #0 :½ Skip past leading token 610.TokPrLp3 620LDA (tptr),Y:BMI TokPrEnd :½ Token byte, end 630CMP #32:BCC TokPrEnd:JSR OSWRCH :½ Flag byte, end 640.TokPrNxt 650INY:BNE TokPrLp3 :½ Loop back for next character 660.TokPrEnd 670RTS 680: 690]NEXT 700: 710REM Test code 720CALL TokenInit 730FOR A%=128 TO 255:PRINT;÷A%;": ";:C ALL TokenPrint:PRINT:NEXT