10REM Program to list all BASIC variables 20REM (C) John Robinson 1988 30REM Second processor compatible 40: 50DIM code &200 60origin=&500 70: 80num = &0070 90q = &0074 100temp = &0076 110den = &0077 120letter = &0079 130pointer = &007A 140dimens = &007C 150arrptr = &007D 160numofvars = &007E 170longest = &0080 180workspace = &0081 190basicrom = &0080 200: 210osbyte = &FFF4 220oswrch = &FFEE 230osnewl = &FFE7 240osasci = &FFE3 250: 260FOR pass=4 TO 7 STEP 3 270O%=code 280P%=origin 290[OPT pass 300 310.varlist 320LDA #&BB 330LDX #0 340LDY #&FF 350JSR osbyte 360STX basicrom 370LDA #&FC 380LDX #0 390LDY #&FF 400JSR osbyte 410CPX basicrom 420BEQ inBASIC 430BRK 440EQUB 254 450EQUS "Not in BASIC" 460EQUB 0 470.inBASIC 480LDA #0 490STA numofvars 500STA numofvars+1 510STA longest 520LDX #2 530.varloop1 540STX letter 550LDA &481,X 560BEQ next_letter 570STA pointer+1 580LDA &480,X 590STA pointer 600.print_variable_name 610LDY #2 620LDA letter 630LSR A 640ADC #&40 650JSR oswrch 660.pvnloop 670LDA (pointer),Y 680BEQ donevn 690JSR oswrch 700INY 710BNE pvnloop 720.donevn 730CPY longest 740BCC not_longer 750STY longest 760.not_longer 770DEY 780LDA (pointer),Y 790CMP #ASC "(" 800BNE not_an_array 810INY 820INY 830LDA (pointer),Y 840SBC #1 850STA dimens 860INY 870.dimensionsloop 880STY arrptr 890LDA (pointer),Y 900SEC 910SBC #1 920TAX 930INY 940LDA (pointer),Y 950SBC #0 960TAY 970JSR outputdec 980LDY arrptr 990INY 1000INY 1010DEC dimens 1020DEC dimens 1030BEQ finished_array 1040LDA #ASC "," 1050JSR oswrch 1060JMP dimensionsloop 1070.finished_array 1080LDA #ASC ")" 1090JSR oswrch 1100.not_an_array 1110INC numofvars 1120BNE noinchi 1130INC numofvars+1 1140.noinchi 1150JSR osnewl 1160LDY #1 1170LDA (pointer),Y 1180BEQ next_letter 1190PHA 1200DEY 1210LDA (pointer),Y 1220STA pointer 1230PLA 1240STA pointer+1 1250BNE print_variable_name 1260.next_letter 1270LDX letter 1280INX 1290INX 1300CPX #(ASC "z"+1-&40)*2 1310BCS finished 1320CPX #(92-&40)*2 1330BEQ nvarloop1 1340.gvarloop1 1350JMP varloop1 1360.nvarloop1 1370LDX #(95-&40)*2 1380BNE gvarloop1 1390.finished 1400LDX #mes1-messages 1410JSR pmessage 1420LDY numofvars+1 1430LDX numofvars 1440JSR outputdec 1450LDX #mes2-messages 1460JSR pmessage 1470LDY #0 1480LDX longest 1490DEX 1500JSR outputdec 1510LDX #mes3-messages 1520.pmessage 1530LDA messages,X 1540BEQ done_message 1550JSR osasci 1560INX 1570BNE pmessage 1580.done_message 1590RTS 1600 1610.messages 1620.mes1 1630EQUS "Total of " 1640EQUB 0 1650.mes2 1660EQUS " variables." 1670EQUB &D 1680EQUS "Longest variable " 1690EQUB 0 1700.mes3 1710EQUS " characters long." 1720EQUB &D 1730EQUB 0 1740 1750.outputdec 1760STY num+1 1770STX num 1780LDX #0 1790.decloop 1800LDA #0 1810STA num+2 1820STA num+3 1830STA den+1 1840LDA #10 1850STA den 1860JSR div10mod10 1870LDA num+2 1880STA workspace,X 1890LDA q 1900STA num 1910LDA q+1 1920STA num+1 1930BNE around_loop_again 1940LDA q 1950BEQ finished_going_round_loop 1960.around_loop_again 1970INX 1980BNE decloop 1990.finished_going_round_loop 2000LDA workspace,X 2010ORA #&30 2020JSR oswrch 2030DEX 2040BPL finished_going_round_loop 2050RTS 2060 2070.div10mod10 2080LDA #0 2090STA q 2100STA q+1 2110LDY #16 2120.loop 2130ASL num 2140ROL num+1 2150ROL num+2 2160ROL num+3 2170LDA num+2 2180BCC label 2190SBC den 2200STA num+2 2210LDA num+3 2220SEC 2230SBC den+1 2240SEC 2250BCS shift 2260.label 2270SEC 2280SBC den 2290STA temp 2300LDA num+3 2310SBC den+1 2320BCC shift 2330STA num+3 2340LDA temp 2350STA num+2 2360.shift 2370ROL q 2380ROL q+1 2390DEY 2400BNE loop 2410RTS 2420 2430] 2440NEXT pass 2450: 2460save$="*SAVE BasVarList "+STR$~code+" "+STR$~O%+" "+STR$~origin+" "+STR$~origin 2470PRINT save$;" ? (Y/N) "; 2480IF (GET OR &20)=ASC "y" THEN PRINT "Yes":OSCLI save$:PRINT "OK" ELSE PRINT "No" 2490: