p** jAMAICAmon** oRIGINAL SUPERMON SOURCE CODE COURTESY jIM bUTTERFIELD** mERLINIZED AND ADAPTED FOR THE sUPERcpu BY* sTEPHEN l. jUDD* 12/7/97 (1/98)** V1.0 1/31/98* V2.0 10/28/98* V2.1 9/9/99* V3.0 12/14/99** tHIS PROGRAM IS PUBLIC DOMAIN.** dIRECT PAGE VARIABLESTMPC = $22NEMO = $23LENGTH = $24WRAP = $25ACMD = $26AFLG = $27 ;3 BYTESSATUS = $90LVFLAG = $93INDEV = $99OUTDEV = $9AEAL = $AEEAH = $AFFNLEN = $B7WTYPE = $B9FA = $BAFNADR = $BBPSAV = $57TMP2 = $5ATMP0 = $5DSAVX = $60INBUF = $0100SCPU = $0208 ;SCPU STUFFSTAGE = $0210REPTEMP = $022D ;rep/sep INSTRUCTIONREPVAL = $022E ;AND VALUEOHONE = $022FPBR = $0230PCL = $0231PCH = $0232ACC = $0233XR = $0235YR = $0237SP = $0239DP = $023BDBR = $023DFLGS = $023EEMUL = $023F ;HIGH BIT = EADDRS = $0240 ;LOAD/SAVE STRINGLASTMEM = $0257BKVEC = $0316LDVEC = $0330SVVEC = $0332READY = $A002SETMSG = $FF90RDT = $FFCFWRT = $FFD2STOP1 = $FFE1KLOAD = $FFD5KSAVE = $FFD8readst = $ffb7setlfs = $ffbasetnam = $ffbdopen = $ffc0close = $ffc3chkin = $ffc6chkout = $ffc9clrchn = $ffccchrin = $ffcfchrout = $ffd2stop = $ffe1clall = $ffe7acc = $5a ;TMP2aux = acc+2ext = aux+2 ;TMP0strbuf = ADDRS; ** INITIALIZATION **SUPER CLC >>> XCE ;NATIVE MODE >>> REP,$30 ;EVERYONE 16-BITS >>> PER,VBREAK SEI PLA STA BKVEC >>> PER,BREAK PLA >>> STA1,$FC9D ;nbrk >>> STA1,$7C9D LDA #00 DFB 00 DFB $5B ;dp -> ZERO-PAGE >>> SEP,$30 ;EVERYONE 8-BITS >>> STA1,$FC9F ;BANK 0 >>> STA1,$7C9F CLI LDA #$80 JSR SETMSG SEC >>> XCE JSR init ;INIT ppp BRK*-------------------------------* dEBUGGING ROUTINES DO 0DEBUG1 LDA #00 STA $D020 RTSDEBUG2 INC $D020:WAIT JSR $FFE4 BEQ :WAIT RTS FIN* TXT 'AH, MOON OF MY DELIGHT THAT KNOWS NO WANE'VBREAK ; ** VECTOR BREAK ENTRY ** >>> PLY >>> PLX PLA; ** BREAK ENTRY **BREAK CLI CLC >>> XCE >>> REP,$30 >>> PHD PHA LDA #00 DFB 00 >>> TCD ;DIRECT REG=$0000 STY YR STX XR PLA STA ACC PLA STA DP >>> SEP,$30 ;EVERYONE 8-BITS ROR EMUL ;HIGH BIT = E HEX AF010000 ;lda $000001 STA OHONE ORA #$02 HEX 8F010000 LDA $D0B2 ;sUPERcpu STATUS REG STA SCPU LDA $D0BC ;ramlINK STATUS STA $D073 ;SYS SPEED TO TURBO STA SCPU+1 AND #%01000000 BEQ :SKIP STA $DF20 ;RL WRT-PROT OFF STA $DF7F ;RL HW REG OUT:SKIP STA $D0BF ;DOS EXT ,PDE PFF STA $D07F ;SCPU HW OUT >>> PHB PLA STA DBR PLA STA FLGS >>> REP,$30 PLA SEC HEX E90200 ;sbc #0002 STA PCL >>> SEP,$30 LDA #00 LDX EMUL BMI :EMUL PLA:EMUL STA PBR >>> TSC STA SP >>> XBA STA SP+1 LDA PCL CMP BRKADDR BNE :NOTBRK LDA PCH SBC BRKADDR+1 BNE :NOTBRK LDA PBR SBC BRKADDR+2 BNE :NOTBRK JSR GETP2 LDA BRKINST DFB $87,TMP0 ;sta [tmp0] LDA #$FF STA BRKADDR STA BRKADDR+1 STA BRKADDR+2:NOTBRK JSR CRLF LDX #$42 LDA #$2A JSR WRTWO LDA #$52 BNE S0 ; ** PRINT ADDRESSES **WHEREAMI LDY #'N' JSR ALTRIT JSR SPACE >>> PER,SUPER >>> PLX PLA JSR WRAX >>> PER,ENDCODE >>> PLX PLA JSR WRAX >>> PER,ENDVARS >>> PLX PLA JSR WRAX JMP STRT ; ** WRITE 16-BITS IN x,a **WRAX STX TMPC JSR WROB LDA TMPC JSR WROB JMP SPACE; ** INCREMENT TEMP POINTER **INCTMP INC TMP0 BNE SETWR INC TMP0+1 BNE SETWR INC WRAPSETWR RTS; ** READ CHARACTER **RDOC JSR RDT CMP #$0D BNE SETWR PLA PLA; ** PROMPT FOR COMMAND  **STRT LDA #0 STA WRAP LDX #$0D LDA #$2E JSR WRTWO; ** CHECK INPUT COMMAND **ST1 JSR RDOC CMP #$2E BEQ ST1 CMP #$20 BEQ ST1S0 LDX #$1AS1 CMP KEYW,X BNE S2 TXA ASL TAX >>> PER,SUPER >>> REP,$20 PLA CLC ADC KADDR,X PHA >>> SEP,$30 RTSS2 DEX BPL S1 JMP ERROR ; ** HELP!  I NEED SOMEBODY **HELP JSR CRLF LDX #00:LOOP LDA KEYW,X BEQ STRT JSR WRT INX BNE :LOOP ; ** tOGGLE rep/sep FLAG **REPSEP LDA REPFLAG EOR #$FF STA REPFLAG TAX LDA #32 JSR WRT LDA #'O' JSR WRT LDA #'N' >>> TXY BPL :SKIP LDA #'F' JSR WRT:SKIP JSR WRT >>> BRA,STRT; ** SET PC ADDRRESS **PUTP2 LDA TMP0+2 STA PBRPUTP LDA TMP0 STA PCL LDA TMP0+1 STA PCH RTS; ** GET PC ADDRRESS **GETP2 LDA PBR STA TMP0+2GETP LDA PCL STA TMP0 LDA PCH STA TMP0+1 RTS; ** MEMORY DISPLAY **DM JSR OLDDM JSR MEMADJ JMP TMP2PSAVOLDDM LDA #$08 STA TMPC LDY #$FF:LOOP JSR SPACE INY JSR FETCHY JSR WROB DEC TMPC BNE :LOOP STY LENGTH RTS ; ** SCREEN CODE DISPLAY **DSCR LDA #32 STA TMPC LDY #$FF:LOOP INY JSR FETCHY JSR WRSCR DEC TMPC BNE :LOOP STY LENGTH JSR MEMADJ JMP TMP2PSAV ; ** TEXT DISPLAY **DT LDA #$08 STA TMPC LDY #$FF:LOOP INY JSR FETCHY JSR WRTEXT DEC TMPC BNE :LOOP STY LENGTHMEMADJ JSR PCADJ STA TMP0 STY TMP0+1 RTS; ** CHANGE MEMORY **BYTE JSR RDOB BCC BY3BYTEST DFB $87,TMP0 ;sta [tmp0] DFB $C7,TMP0 ;cmp [tmp0] BEQ BY3 JMP ERRORBY3 JSR INCTMP DEC TMPC RTS ; ** STORE ADDRESS **WORD JSR RDOB PHA JSR BYTE PLA JMP BYTEST; ** SET PC REG ADDRS **SETR LDA #<ACC STA TMP0 LDA #>ACC STA TMP0+1 LDA #00 STA TMP0+2 LDA #8 RTS; ** WRITE DISPLAY PROMPT **ALTRIT >>> PHY JSR CRLF PLA LDX #$2E JMP WRTWO ; ** PRINT TEXT **PRREG LDA REGK,X BEQ :DONE JSR WRT INX BNE PRREG:DONE JMP ALTRIT; **DISPLAY REGISTERS **DSPLYR JSR DISPLAYR JMP STRTDISPLAYR LDX #0 LDY #$3B JSR PRREG LDA #00 LDY EMUL BMI :SKIP LDA PBR:SKIP JSR WROB JSR SPACE LDY #00:LOOP LDA PCL+1,Y JSR WROB LDA PCL,Y JSR WROB JSR SPACE INY INY CPY #10 BCC :LOOP LDA FLGS JSR WRBIN LDA EMUL ASL JMP WRBIT ; ** DISPLAY EXTRA REGSDISPR2 LDX #REGK2-REGK LDY #'^' JSR PRREG LDA DBR JSR WROB JSR SPACE LDA DP+1 JSR WROB LDA DP JSR WROB JSR SPACE LDA OHONE JSR WROB >>> BRL,A9; ** DISPLAY MEMORY/MEM+TEXT **DSPLYT LDA #$FF DFB $2CDSPLYM LDA #$00 STA AFLG:RDT JSR RDT CMP #'*' ;I* BNE :CR ASL AFLG ;$00 OR $FE >>> BRA,:RDT:CR CMP #$0D BNE :C0 JSR PSAV2TMP LDA #$FF STA TMP2 STA TMP2+1 STA TMP2+2 BNE DSP1:C0 JSR READ24 BCS :C1 CMP #$0D BNE MERRS1:C1 LDX TMP0 STX TMP2 LDX TMP0+1 STX TMP2+1 LDX TMP0+2 STX TMP2+2 CMP #$0D BEQ DSP1 JSR READ24 BCC MERRS1 JSR T2T2DSP1 JSR STOP1 BEQ ALTJMP LDX WRAP BNE ALTJMP JSR DIFFP BCC ALTJMP LDX AFLG BMI :TEXT LDY #$3A JSR ALTRIT JSR WROA24 JSR DM >>> BRA,DSP1:TEXT INX BNE :TEXT2 ;I* JSR CRLF JSR WROA24 JSR OLDDM JSR SPACE JSR DT:BLAH JSR PCADJ JSR TMP2PSAV >>> BRA,DSP1:TEXT2 JSR CRLF JSR WROA24 JSR SPACE JSR DSCR BRA :BLAHMERRS1 JMP ERROR; ** ALTER MAIN REGS **ALTR JSR RDOB BCC :SKIP1 STA PBR:SKIP1 JSR RDOC JSR RDOA BCC :SKIP2 JSR PUTP:SKIP2 JSR SETR STA TMPC:LOOP JSR RDOC JSR WORD BNE :LOOP JSR RDOC JSR GETBITS STA FLGS JSR GETBIT ROR EMUL BPL ALTJMP LDA FLGS ORA #$30 STA FLGSALTJMP JMP STRT ; ** ALTERNATE REGS **ALTR2 JSR RDOB STA DBR JSR RDOC JSR RDOB STA DP+1 JSR RDOB STA DP JSR RDOC JSR RDOB BCC :EXIT STA OHONE ORA #$02 HEX 8F010000:EXIT JMP STRT ; ** ALTER MEMORY **ALTM JSR READ24 BCC ERRS2 LDA #$08 STA TMPC BNE :LOOP2 ;KLUDGE:LOOP JSR RDOC:LOOP2 JSR BYTE BNE :LOOPA9 JMP STRTERRS2 JMP ERROR ; ** nUMBER CONVERSION **CONVNUM JSR RDOC CMP #39 ;' BNE :NUM JSR RDOC STA acc LDA #00 STA acc+1 JSR RDT CMP #13 BNE ERRS2 BEQ :OUTPUT:NUM LDY #10 ;BASE CMP #'$' BNE :C1 LDY #16:C1 CMP #'%' BNE :C2 LDY #2:C2 >>> PHY LDX #00 STX SAVX CPY #10 BEQ :STA:READ JSR RDT LDX SAVX CMP #13 BNE :STA LDA #00:STA STA ADDRS,X INC SAVX TAX BNE :READ >>> PLY LDA #<ADDRS LDX #>ADDRS JSR asctonum BCS ERRS2:OUTPUT LDX #13 LDA #' ' JSR WRTWO LDA acc LDX acc+1 STA AFLG STX AFLG+1 LDY #10 JSR printnum LDX #' ' LDA #'$' JSR WRTWO LDA AFLG LDX AFLG+1 LDY #16 JSR printnum LDX #' ' LDA #'%' JSR WRTWO LDA AFLG LDX AFLG+1 LDY #2 JSR printnum LDX #' ' LDA #39 JSR WRTWO LDA AFLG+1 BNE :JMP LDA AFLG CMP #32 BCC :JMP CMP #128 BCC :WRT CMP #160 BCC :JMP:WRT JSR WRT:JMP JMP STRT ; ** sET BREAKPOINTSETBRK JSR RDT JSR READ24 JSR SETBRK2 JSR PRLINE JMP STRTSETBRK2 LDA TMP0 STA BRKADDR LDA TMP0+1 STA BRKADDR+1 LDA TMP0+2 STA BRKADDR+2 JSR FETCH ;LDA [TMP0] TAY LDA #00 DFB $87,TMP0 ;STA [TMP0] TYA STA BRKINST RTS ; ** sINGLE STEP **SINGSTEP LDA #00 DFB $2C; ** .GO **GO LDA #$FF PHA JSR RDT CMP #$0D BEQ :G1 CMP #$20 BNE ERRS3 JSR READ24 JSR PUTP2:G1 PLA BMI :NOBRK JSR GETP2 JSR FETCH JSR GETMIDX JSR MEMADJ JSR SETBRK2:NOBRK STA $D07E ;RESTORE scpu STUFF LDA SCPU+1 ;DOS EXT + RL STATUS STA $D0BC AND #$40 BEQ :SKIP STA $DF7E:SKIP LDA SCPU STA $D0B2 LDA DBR PHA >>> PLB JSR GETSP >>> TCS SEI LDA OHONE HEX 8F010000 ASL EMUL BCS :EMUL LDA PBR PHA:EMUL LDA PCH PHA LDA PCL PHA LDA FLGS PHA >>> REP,$30 LDA DP PHA LDA ACC LDX XR LDY YR >>> PLD >>> XCE RTIERRS3 JMP ERROR; ** BACK TO BASIC **EXIT JSR GETSP >>> TCS SEC >>> XCE JMP (READY) ; ** READ 1 OR 2 (DECIMAL) CHARS **READ12 JSR RDOC JSR DECIT STA ACMD JSR RDT CMP #$2C BEQ :SKIP CMP #$0D BEQ :SKIP JSR DECIT LDX ACMD BEQ :DONE CLC:L1 ADC #10 DEX BNE :L1:DONE STA ACMD JSR RDT:SKIP LDX ACMD RTS ; ** SEND DISK COMMAND **DISKCMD JSR RDT CMP #'$' BEQ :DIR CMP #13 BEQ :ERCHAN CMP #'#' BNE :SENDCMD JSR READ12 ;GET DEVICE NUMBER STX FA JMP STRT:DIR JSR RDT CMP #13 BNE :ERR JSR printdir JMP STRT:ERR JMP ERROR:ERCHAN JSR geterr JMP STRT:SENDCMD LDX #00 STX ACMD:LOOP LDX ACMD STA strbuf,X INC ACMD JSR RDT CMP #13 BNE :LOOP LDX ACMD LDA #00 STA strbuf,X JSR sendcmd JMP STRT** dISK ROUTINES** printdir READS THE DIRECTORY FROM THE CURRENT DEVICE* AND PRINTS IT TO THE SCREEN.*printdir lda #01 ;fILE NO. ldx $ba ;cURRENT DEVICE NUMBER ldy #00 ;sECONDARY ADDRESS jsr setlfs lda #'$' sta ADDRS lda #1 ldx #<ADDRS ldy #>ADDRS jsr setnam jsr open ldx #01 jsr chkin bcs :end ;eRROR IF CARRY SET jsr chrin ;gRAB LOAD ADDRESS jsr chrin:loop1 lda #13 jsr chrout jsr chrin ;lINE LINK jsr chrin jsr chrin ;lINE NUMBER (FILE SIZE) tay jsr chrin tax jsr readst bne :end tya ldy #10 ;bASE jsr printnum ;pRINT OUT THE NUMBER IN x,y lda #32 jsr chrout ;aDD A SPACE TO LOOK NICE:loop2 jsr chrin tax beq :stop jsr chrout bne :loop2:stop jsr stop bne :loop1:end lda #01 jsr close jsr clrchn lda #13 jmp chrout** sendcmd SENDS A COMMAND TO THE CURRENT DRIVE* cOMMAND CONTAINED IN strbuf*sendcmd lda #$0f ldx $ba ldy #$0f jsr setlfs lda #00 jsr setnam jsr open bcs :error ldx #$0f jsr chkout ldy #00:loop lda strbuf,y beq :error jsr chrout iny bne :loop:error jsr clrchn lda #$0f jsr close jmp clrchn** geterr PRINTS THE ERROR MESSAGE FROM THE CURRENT DISK DRIVE.*geterr lda #13 jsr chrout** tHIS METHOD IS A BIT FASTER ON OUTPUT TO SCREEN.* jsr openerr bcs getexitgeterr2:loop jsr chrin cmp #$0d beq getexit jsr chrout bne :loopgetexit jsr chrout jsr chrout ;oNE MORE TO LOOK NICE lda #15 jsr close jmp clrchnopenerr lda #$c0 ;kERNAL MSG ON sta $90 lda #$0f ldx $ba ldy #$0f jsr setlfs lda #00 jsr setnam jsr open lda #00 sta $90 bcs :error ldx #$0f jmp chkin ;cARRY CLEAR -> ok:error lda #13 sec rts*-------------------------------; ** LOAD/SAVE **LD LDY #1 STY FA STY WTYPE DEY STY FNLEN STY SATUS STY LVFLAG LDA #<ADDRS STA FNADR LDA #>ADDRS STA FNADR+1 JSR GETCHAR CMP #$0D BEQ L5 CMP #$22 BNE ERRLL3 JSR RDT CMP #$22 BEQ L8 CMP #$0D BEQ L5 STA (FNADR),Y INC FNLEN INY CPY #$10 BNE L3ERRL JMP ERRORL8 JSR RDT CMP #$0D BEQ L5 CMP #$2C BNE ERRL JSR READ12 PHA TXA AND #$0F BEQ ERRL CMP #$03 BEQ ERRL STA FA PLA CMP #$0D BEQ L5 CMP #$2C BNE ERRL JSR READ24 BCC ERRL DEC WTYPE LDX $F7E5 ;CHECK FOR 24-BIT LOAD/SAVE CPX #$91 BEQ :CONT DEC WTYPE ;$FF LDX TMP0+2 STX $B0 ;BANK:CONT CMP #$0DL5 RTSLOAD JSR LD BNE ERRL LDA WTYPE PHA LDX TMP0 LDY TMP0+1 LDA #00 JSR KLOAD BCS :BYE JSR SPACE LDA #'$' JSR WRT PLA BMI :C1 LDA $C3 STA TMP0 LDA $C4 STA TMP0+1 LDA #$00 STA TMP0+2:C1 JSR WROA24 LDA #'-' JSR WRT LDX $B0 LDA $AF JSR WRHEX LDA $AE JSR WROB:BYE JMP STRTSAVE JSR LD CMP #$2C BNE :ERRL JSR T2T2 JSR READ24 BCC :ERRL CMP #$0D BNE :ERRL LDA $F7E5 ;CHECK FOR 24-BIT LOAD/SAVE CMP #$91 BEQ :CONT LDA TMP0+2 STA $AB ;BANK:CONT LDX TMP0 LDY TMP0+1 LDA #TMP2 JSR KSAVE JMP STRT:ERRL JMP ERROR ; ** PRINT TEXT CHAR **WRTEXT CMP #32 BCC :ZAP CMP #128 BCC :OK CMP #160 BCS :OK:ZAP LDA #'.':OK JMP WRT ; ** PRINT AS SCREEN CODE **WRSCR TAX BPL :C1 INC $C7 ;RVS ON:C1 TXA AND #$7F EOR #32 ;cONVERT TO CHR$ CLC ADC #32 CMP #96 ;BLEAH BCC :WRT EOR #$E0 BPL :WRT EOR #32:WRT JSR WRT DFB $64,$C7 ;stz $C7 RTS; ** PRINT HEX BYTE **WROA24 LDA TMP0+2 JSR WROBWROA LDA TMP0+1 JSR WROB LDA TMP0WROB PHA LSR A LSR A LSR A LSR A JSR ASCII TAX PLA AND #$0F JSR ASCII; ** PRINT TWO CHARS **WRTWO PHA TXA JSR WRT PLA JMP WRT ; ** PRINT HEX ADDRESS **WRHEX PHA LDA #'$' JSR WRT TXA JSR WROB PLA JMP WROB; ** CONVERT TO ASCII **ASCII ORA #$30 CMP #$3A BCC ASC1 ADC #$06ASC1 RTS ; ** PRINT A BINARY BYTE **WRBIN STA TMPC LDY #08:LOOP ASL TMPC JSR WRBIT DEY BNE :LOOP RTS  ; ** PRINT BIT IN c **WRBIT LDA #'0' ADC #00 JMP WRT ; ** READ BINARY BYTE **GETBITS LDA #8 STA SAVX:LOOP JSR GETBIT ROL TMPC DEC SAVX BNE :LOOP LDA TMPC RTS ; ** READ A BIT **GETBIT JSR RDOC CMP #'1' RTS; ** SWAP TMP0, TMP2 **T2T2 LDX #$03T2T21 LDA TMP0-1,X PHA LDA TMP2-1,X STA TMP0-1,X PLA STA TMP2-1,X DEX BNE T2T21 RTS ; ** READ 16/24 BIT HEX ADDR **READ24 JSR RDOA BCC RDERRREAD24B LDX PBR STX TMP0+2 JSR RDT CMP #$0D BEQ RDEXIT CMP #$20 BEQ RDEXIT CMP #$2C BEQ RDEXITRDOA24 JSR RDOB2 BCC RDEXIT LDX TMP0+1 STX TMP0+2 LDX TMP0 STX TMP0+1 STA TMP0 JSR RDT ;.A = NEXT CHAR SEC RTSRDERR JMP ERROR; ** READ HEX ADDRESS **RDOA JSR RDOBRDOA1 BCC RDOA2 STA TMP0+1RDOA2 JSR RDOB BCC RDEXIT STA TMP0RDEXIT RTS; ** SCAN FOR HEX BYTE **RDOB LDA #0 STA ACMD JSR RDOCRDOB1 CMP #$20 BNE RDOB2 JSR RDOC CMP #$20 BNE RDOB3 CLC RTS; ** READ HEX BYTE **RDOB2 JSR HEXIT ASL A ASL A ASL A ASL A STA ACMD JSR RDOCRDOB3 JSR HEXIT ORA ACMD SEC RTSDECIT ; ** CONVERT FROM BASE 10 ** EOR #48 CMP #10 BCS :ERR RTS:ERR JMP ERROR; ** CONVERT FROM HEX **HEXIT CMP #$3A BCC HEX08 ADC #$08HEX08 AND #$0F RTS; ** DECREMENT T0,T2 **SPREAD = TMP2-TMP0DECT2 LDX #<SPREAD DFB $2CDECT0 LDX #0 LDY TMP0,X BNE DEC20 LDY TMP0+1,X BNE DEC10 INC WRAPDEC10 DEC TMP0+1,XDEC20 DEC TMP0,XRET1 RTS; ** GET A NON SPACE **GTCHR JSR RDOC CMP #$20 BEQ GTCHR RTS ; ** INCLUDING cr **GETCHAR JSR RDT CMP #$20 BEQ GETCHAR RTS; ** GET ADDRESS **INPUT LDA #00 STA INBUF STA ACMD JSR GTCHR JSR RDOB1 JSR RDOA1 BCC ERROR JMP READ24B; ** GET ADDRESS **GET2B CMP #$0D BEQ ERROR JSR READ24 BCS RET1; ** ERROR EXIT **ERROR JSR GETSP >>> TCS LDA #$3F JSR WRT JMP STRT ; ** GET STACK POINTER **GETSP >>> REP,$30 LDA SP >>> SEP,$30 RTS; ** PRINT SPACES **SPACD JSR SPACE DEX BNE SPACD RTS; ** INC TMP 2 **PTRINC INC TMP2 BNE P1OV INC TMP2+1P1OV RTS ; ** SWAP AFLG, TMP0 **SWAP LDX #$03SWP1 LDA TMP0-1,X PHA LDA AFLG-1,X STA TMP0-1,X PLA STA AFLG-1,X DEX BNE SWP1 RTS; ** CALC TMP2-TMP0-2 **DIFFB LDA TMP2 LDY TMP2+1 LDX TMP2+2 SEC SBC #2 BCS DECK DEY CPY #$FF BNE DECK DEX >>> BRA,DECK; ** CALC AFLG-TMP0 **DIFFA LDA AFLG LDY AFLG+1 LDX AFLG+2 >>> BRA,DECK; ** CALC TMP2-TMP0 **DIFFP LDA TMP2 LDY TMP2+1 LDX TMP2+2DECK SEC  SBC TMP0 STA NEMO >>> XBA TYA SBC TMP0+1 TAY ORA NEMO STA NEMO TXA SBC TMP0+2 TAX ORA NEMO RTS ; ** CHECK ADDRESS RANGE **CHKRANGE LDY #01 ;0 < ADDR-BEGIN < END-BEGIN LDX LENGTH SEC:LOOP JSR FETCHY SBC TMP2-1,Y STA STAGE+5,Y INY DEX BNE :LOOP BCC :RTS LDX LENGTH LDY #01 SEC:LOOP2 LDA AFLG-1,Y SBC STAGE+5,Y INY DEX BNE :LOOP2:RTS RTS ; ** RELOCATE **RELOCATE LDA #$FF DFB $2C; ** .TRANSFER **TRANS LDA #00 STA TMPC JSR INPUT PHA JSR T2T2 PLA JSR GET2B PHA LDA TMPC BEQ :SKIP JSR DIFFP ;START-END CODE = -# OF BYTES BCS :ERR >>> XBA STA STAGE STY STAGE+1 INX BNE :ERR PLA JSR GET2B ;END VARS PHA:SKIP JSR DIFFP BCC :OK BEQ :OK:ERR JMP ERROR:OK JSR SWAP PLA JSR GET2B ;DEST LDA TMP0+2 STA :MOV+1 LDA TMP2+2 STA :MOV+2 >>> PHB >>> REP,$30 LDX TMP2 LDY TMP0 LDA AFLG SEC SBC TMP2 STA AFLG ;END-BEGIN:MOV HEX 540000 ;mvn >>> SEP,$30 >>> PLB LDA TMPC BNE RELOC JMP STRT ;** RELOCATE CHUNK OF CODE **RELOC DFB $64,AFLG+2 ;STZ JSR DIFFP ;BEGIN-DEST >>> XBA STA STAGE+3 STY STAGE+4 STX STAGE+5:LOOP JSR FETCH JSR GETMIDX LDA ACMD ;MODES 9-E, 11 ARE ABSOLUTE CMP #9 BCC :NOPE CMP #$0F BCC :MAYBE CMP #$11 BNE :NOPE:MAYBE JSR CHKRANGE BCC :NOPE LDX LENGTH LDY #01 SEC:YEP JSR FETCHY SBC STAGE+2,Y DFB $97,TMP0 ;sta [tmp0],y INY DEX BNE :YEP:NOPE JSR MEMADJ LDA STAGE SEC ADC LENGTH STA STAGE BCC :LOOP INC STAGE+1 BNE :LOOP JMP STRT; ** .FILL **FILL JSR INPUT PHA JSR T2T2 PLA JSR GET2B CMP #$0D BEQ ERROR2 JSR T2T2 JSR RDOB BCC ERROR2 STA TMPCFLUP1 LDX WRAP BNE STRT1 JSR DIFFP BCC STRT1 LDA TMPC DFB $87,TMP0 ;STA [TMP0] JSR INCTMP BNE FLUP1ERROR2 JMP ERRORSTRT1 JMP STRT; ** .HUNT **HUNT JSR INPUT PHA JSR T2T2 PLA JSR GET2B CMP #$0D BEQ ERROR2 JSR T2T2 LDX #0 JSR RDOC CMP #$22 BNE NOSTRH JSR RDOCHPAR STA STAGE,X INX JSR RDT CMP #$0D BEQ HTGO CMP #$22 BEQ HTGO CPX #$1E BNE HPAR BEQ HTGONOSTRH STX INBUF JSR RDOB1 BCC ERROR2HLP STA STAGE,X INX JSR RDT CMP #$0D BEQ HTGO JSR RDOB BCC ERROR2 CPX #$1E BNE HLPHTGO STX SAVX JSR CRLFHSCAN JSR STOP1 BEQ HNJMP LDX #0 LDY #0HLP3 JSR FETCHY CMP STAGE,X BNE HNMTCH INY INX CPX SAVX BNE HLP3; ** MATCH FOUND ** JSR WROA24 JSR SPACEHNMTCH JSR INCTMP LDX WRAP BNE STRT1 JSR DIFFP BCS HSCANHNJMP JMP STRT ; ** fETCH A BYTE USING $01 **FETCHY PHP SEC DFB $2CFETCH PHP CLC >>> PHX LDX $01 LDA OHONE STA $01 BCS :FETCHY DFB $A7,TMP0 ;LDA [TMP0] DFB $2C:FETCHY DFB $B7,TMP0 ;LDA [TMP0],Y STX $01 >>> PLX PLP AND #$FF ;SET FLAGS RTS ; ** cOPY TMP0 TO PSAV **TMP2PSAV LDX #2:LOOP LDA TMP0,X STA PSAV,X DEX BPL :LOOP RTS ; ** cOPY PSAV TO TMP0 **PSAV2TMP LDX #2:LOOP LDA PSAV,X STA TMP0,X DEX BPL :LOOP RTS ; ** bACKWARDS DISASSEMBLE **BACKDIS LDA #21 STA SAVX ;DISTANCE:LOOP1 JSR PSAV2TMP INC SAVX JSR SUBSAVX LDA #$16 STA TMPC:LOOP2 JSR FETCH ;DISASSEMBLE 22 LINES JSR GETMIDX JSR MEMADJ:C2 DEC TMPC BNE :LOOP2 LDA PSAV CMP TMP0 LDA PSAV+1 SBC TMP0+1 LDA PSAV+2 SBC TMP0+2 BCC :LOOP1 ;uNTIL PSAV >= TMP0 JSR SUBSAVX JMP DISAS2 ;aND DISASSEMBLE!SUBSAVX LDA TMP0 SEC SBC SAVX STA TMP0 BCS :C1 DEC TMP0+1 ;nO 24-BIT WRAPPING:C1 RTS; ** .DISASSEMBLE **DISAS JSR RDOC JSR READ24DISAS2 JSR TMP2PSAV LDX #0 STX AFLGDPAG LDA #$93  ;CLR JSR WRT LDA #$16 STA TMPCDISLP JSR DISS1 JSR MEMADJ DEC TMPC BNE DISLP LDA #$91       ;UP JSR WRT JMP STRT; ** DISS 1 LINE **DISS1 LDY #',' JSR ALTRIT JSR SPACEDISS1A JSR WROA24 JSR SPACE JSR FETCH STA REPTEMP JSR GETMIDX ;MNEMONIC INDEX TXA PHA LDY #0 JSR DISVV PLA TAX JSR PROPXX JSR PRLCHAR ;LEADING CHARS JSR PRADDR ;ADDRESS LDA REPFLAG BMI :SKIP LDA REPVAL LDX REPTEMP ;cHECK FOR rep/sep AND ADJUST CPX #$C2 BNE :SEP ;STATUS REG ACCORDINGLY EOR #$FF AND FLGS >>> BRA,:STA:SEP CPX #$E2 BNE :SKIP ORA FLGS:STA LDX EMUL BPL :STA2 ORA #$30 ;x AND m ALWAYS SET:STA2 STA FLGS:SKIP JMP PRECHAR ;FINAL CHARS ;** cOMPUTE MNEMONIC INDEX,MODE **GETMIDX LSR TAY BCC :EVEN:ODD CMP #$44 ;bit # BNE :NOTBIT LDX #6 LDA #1 BNE :LEN:NOTBIT AND #$07 ;eXCEPTION IS $Xb CMP #%00000101 BEQ :EXCEPT TYA LSR LSR LSR LSR ;MSD/16/2 TAX LDA NEMTAB2,X TAX TYA AND #$0F TAY ;LOW 5 BITS/2 LDA MODETAB2,Y BPL :LEN ;.x .a = MNEMONIC, ADR MODE:EXCEPT TYA LSR LSR LSR TAY LDX NEMTAB+$80,Y LDA #00 ;aLL ARE MODE 0 BEQ :LEN:EVEN LDX NEMTAB,Y LDA MODETAB,Y:LEN STA ACMD ;MODE TAY LDA MODELEN,Y STA LENGTH DEY BNE CHKRTS ;** TEST FOR 16-BIT ** JSR FETCHCHECK16 CMP #$A2 ;ldx BEQ :XCHK AND #$0F ;cpx cpy ldy BEQ :XCHK CMP #9 ;sep rep BNE CHKRTS LDA #%00100000 DFB $2C:XCHK LDA #%00010000 AND FLGS BNE CHKRTS INC LENGTHCHKRTS RTS ;** PRINT LEADING CHARS **PRLCHAR LDA ACMD BEQ DONE CMP #1 BNE :C1 LDX #'#' BNE :TWO:C1 CMP #14 BCC :DOLLAR LDX #'(' CMP #20 BCC :TWO LDX #'[':TWO TXA JSR WRT:DOLLAR LDA #'$' JMP WRT ;** PRINT ADDRESS **PRADDR LDY LENGTH BEQ DONE LDA ACMD CMP #2 BEQ PRMOVE CMP #3 BEQ PREL CMP #4 BEQ PREL:LOOP JSR FETCHY STA REPVAL ;uSED WITH rep/sep STUFF JSR WROB DEY BNE :LOOPDONE RTS;** mvn/mvp ADDRESS **PRMOVE JSR :PRINT LDX #',' LDA #'$' JSR WRTWO DEY:PRINT JSR FETCHY JMP WROB; ** PRINT REL ADDRESS **PREL LDX #00 JSR FETCHY CLC BPL :TEST DEX:TEST DEY ;LENGTH BEQ :8BIT TAX JSR FETCHY SEC:8BIT ADC #2 ;BLEAH BCC :CALC INX CLC:CALC JSR PCADJ2 TAX TYA JSR PRBYTE TXAPRBYTE STX SAVX JSR WROB LDX SAVX RTS  ;** PRINT END CHARACTERS **PRECHAR LDY ACMD:SQUARE CPY #20 BCC :COMMAS LDA #']' JSR WRT:COMMAS LDX #',' CPY #19 BEQ :PRS CPY #5 BNE :COMMAX:PRS LDA #'S' JSR WRTWO:COMMAX JSR ISCOMX BNE :PAREN LDA #'X' JSR WRTWO:PAREN CPY #14 BCC :COMMAY CPY #20 BCS :COMMAY LDA #')' JSR WRT:COMMAY JSR ISCOMY BNE :BYE LDA #'Y' JSR WRTWO:BYE RTS ;** cHECK FOR ,X AND ,Y **ISCOMX CPY #7 BEQ :RTS CPY #10 BEQ :RTS CPY #13 BEQ :RTS CPY #17 BEQ :RTS CPY #18:RTS RTSISCOMY CPY #8 BEQ :RTS CPY #11 BEQ :RTS CPY #16 BEQ :RTS CPY #19 BEQ :RTS CPY #21:RTS RTS; ** ADD LENGTH+1 TO PC **PCADJ LDX #00 LDA LENGTH SECPCADJ2 ADC TMP0 ;RESULT-> .a .y = LO HI PHA TXA ADC TMP0+1 TAY PLA RTS; PRINT BYTESDISVV JSR FETCHY ;LDA [TMP0],Y JSR PRBYTE LDX #1DISVL JSR SPACD CPY LENGTH INY  BCC DISVV LDX #$03 CPY #4 BCC DISVL RTS; ** PRINT MNEMONIC IN .x **PROPXX LDA MNEML,X STA AFLG LDA MNEMR,X STA AFLG+1 LDX #3:LOOP1 LDA #0 LDY #$05:LOOP2 ASL AFLG+1 ROL AFLG ROL A DEY BNE :LOOP2 ADC #$40 JSR WRT DEX BNE :LOOP1; ** PRINT SPACE **SPACE LDA #$20 BNE FLIP; ** PRINT CR, MAYBE LF **CRLF LDA #$0D BIT $13 BPL FLIP JSR WRT LDA #$0AFLIP JMP WRT; **.P DISASSEMBLE **PRIN JSR INPUT PHA JSR T2T2 PLA JSR GET2B JSR T2T2 DFB $64,AFLG ;stzPLOOP JSR CRLF JSR DISS1A JSR MEMADJ JSR STOP1 BEQ STRTX JSR DIFFP BCS PLOOPSTRTX JMP STRT; ** RE-DISASSEMBLE **REDIS JSR INPUT LDA #$04 STA TMPC:LOOP JSR BYTE BEQ :DONE JSR RDOC CMP #$20 BEQ :LOOP:DONE JSR PSAV2TMP JMP DPAGFINDMNEM LDX #91 ;fIND MNEMONIC IN THE TABLE:LOOP LDA MNEML,X CMP STAGE BNE :NEXT LDA MNEMR,X CMP STAGE+1 BNE :NEXT STX STAGE ;mNEMONIC INDEX RTS:NEXT DEX BPL :LOOP JMP ERRORISLEAD ;** iS .a A LEADING CHAR?:LOOP CMP LEADCHAR,X BEQ :OUT DEX BPL :LOOP:OUT RTSISEND LDX #3 ;** iS .a AN ENDING CHAR?:LOOP CMP ENDCHAR,X BEQ :OUT DEX BPL :LOOP:OUT RTS ;** fLIP x AND m BITS **FLIPBIT JSR RDT LDX #$30 CMP #'M' BNE :C1 LDX #$20:C1 CMP #'X' BNE :C2 LDX #$10:C2 LDA EMUL BMI :SKIP TXA EOR FLGS STA FLGS:SKIP JSR DISPLAYR PLA PLA JMP ASMNEXT ;** rEAD IN AND PACK MNEMONICPACKM HEX 9C ;stz DA STAGE HEX 9C DA STAGE+1 JSR GTCHR CMP #'!' BEQ FLIPBIT PHA JSR RDOC PHA JSR RDOC PHA LDY #3:LOOP2 PLA LDX #5:LOOP LSR ROR STAGE ROR STAGE+1 DEX BNE :LOOP DEY BNE :LOOP2 JMP FINDMNEM ;...AND FIND IT IN THE TABLE ;** aSSEMBLE **ASSEMBLE JSR RDOC JSR READ24 ;ADDRESS BCC JERR1 CMP #$0D BNE ARDARG JMP STRTARDARG JSR PACKM ;MNEMONIC JSR GETCHAR ;ARGUMENT LDX #7 JSR ISLEAD BNE JERR1 DFB $64,AFLG ;stz aflg TXA ASL TAX >>> PER,SUPER >>> REP,$20 PLA CLC ADC LEADADR,X PHA >>> SEP,$30 RTS;** fORM NUMBER FROM STACKCPSTACK PLA STA TMP2 PLA STA TMP2+1 LDY #00:LOOP TXA ;.x CONTAINS # OF BYTES BEQ :SKIP DEX PLA:SKIP STA STAGE+4,Y INY CPY #3 ;ZERO OUT ANY EXTRA BNE :LOOP TXA BNE JERR1 ;nO MORE THAN 24 BITS BEQ RESTORE;** rEAD IN AN ADDRESSGETADDR JSR GETCHAR ;(OF ARBITRARY LENGTH)GETADDR3 CMP #'$' BNE JERR1GETADDR2 PLA STA TMP2 PLA STA TMP2+1 DFB $64,TMPC ;cOUNT # OF BYTES READ DFB $64,ACMD JSR RDT:LOOP JSR RDOB1 ;READ HEX BYTES BCC JERR1 PHA INC TMPC DFB $64,ACMD JSR RDT JSR ISEND BNE :LOOP LDX TMPCRESTORE TAY LDA TMP2+1 PHA LDA TMP2 PHA TYA RTSJERR1 JMP ERROR*** iNSTRUCTION MODES ;** aBSOLUTE MODE $ABS JSR GETADDR2 STX STAGE+2 LDY TIMES3P3,X STY STAGE+1 BNE ABSENDABS8 LDY #1 ;zERO PAGE ABSOLUTE < HEX 2C ;bitABS16 LDY #2 ;16-BIT ABSOLUTE ! HEX 2CABS24 LDY #3 ;24-BIT ABSOLUTE > STY STAGE+2 ;MAX # OF BYTES ALLOWED LDA TIMES3P3,Y STA STAGE+1 ;ADDRESSING MODE JSR GETADDR CPX STAGE+2 BCC ABSEND BNE JERR1ABSEND STX TMPC CMP #$0D ;LAST CHAR READ BEQ :DONE CMP #',' ;INDEX BNE JERR1 JSR RDT LDX TMPC CMP #'$' BEQ :MOVE CMP #'S' BEQ :STACK INC STAGE+1 CMP #'X' BEQ :DONE INC STAGE+1 CMP #'Y' BNE JERR1:DONE LDY STAGE+1 CPY #14 ;13 IS HIGHEST BCS JERR1 JMP INSTOUT:STACK CPX #1 ;D,S BNE JERR1 LDY #5 JMP INSTOUT:MOVE DEX ;** mvn/mvp D,D BNE JERR1 JSR GETADDR2 DEX ;1 BYTE ONLY BNE JERR1 LDX #2 LDY #2 JMP INSTOUTINDIR JSR GETADDR ;** iNDIRECT () STX STAGE+2 CMP #')' BNE :INDEX LDY #14 STY STAGE+1 DEX BNE :DONE INC STAGE+1 JSR RDT CMP #$0D BEQ :DONE INC STAGE+1 JSR RDOC CMP #'Y' BNE JERR2:DONE LDY STAGE+1 LDX STAGE+2 JMP INSTOUT:INDEX CMP #',' BNE JERR2 LDY #17 DEX BNE :ZP INY:ZP STY STAGE+1 JSR RDOC CMP #'X' BEQ :DONE CMP #'S' BNE JERR2 LDA #19 STA STAGE+1 JSR RDT JSR RDT JSR RDT CMP #'Y' BEQ :DONEJERR2 JMP ERRORLINDIR JSR GETADDR ;lONG INDIRECT [] STX STAGE+2 DEX BNE JERR2 CMP #']' BNE JERR2 LDY #20 STY STAGE+1 JSR RDT CMP #$0D BEQ :DONE INC STAGE+1 JSR RDT CMP #'Y' BNE JERR2:DONE LDX STAGE+2 LDY STAGE+1 >>> BRA,INSTOUTACCUM LDY #0 ;nO ARGUMENTS LDX #0 BEQ INSTOUT;** iMMEDIATE ADDRESSING #IMMED JSR GETADDR CMP #$0D ;eND WITH A cr! BNE JERR2 LDY #1 ;.y = ADDRESS MODE ;** cHECK AND OUTPUT INST BYTESINSTOUT STY STAGE+1 JSR CPSTACK JSR ISOP2 ;sEARCH THROUGH OPCODE TABLES BCC :GOTCHA JSR ISOP1 BCC :GOTCHA JMP ERROR:GOTCHA STA STAGE+3 ;OPCODE LDX STAGE+1 ;MODE LDY MODELEN,X ;NUMBER OF BYTES DEX BNE :LOOP STY LENGTH JSR CHECK16 LDY LENGTH:LOOP LDA STAGE+3,Y DFB $97,TMP0 ;STA [TMP0],Y DEY BPL :LOOP JSR PRLINE ;PRINT ASSEMBLED LINE JSR MEMADJ ;INC TMP0ASMNEXT LDY #'A' JSR ALTRIT JSR SPACE JSR WROA24 JSR SPACE JMP ARDARG ;** PRINT ASSEMBLED LINEPRLINE JSR CRLF LDA #145 ;UP JSR WRT JSR WRT JMP DISS1 ;** sEARCH THROUGH NEMTAB2ISOP2 LDY #$07 LDA STAGE:LOOP CMP NEMTAB2,Y BEQ :MODE DEY BPL :LOOP CMP #6 ;bit BNE :FAIL LDX STAGE+1 DEX BNE :FAIL LDY #8 LDA #$89 CLC RTS:MODE LDX #15 ;16 POSSIBLE MODES LDA STAGE+1:LOOP2 CMP MODETAB2,X BEQ :CRAZY DEX BPL :LOOP2:FAIL SEC RTS:CRAZY TXA ;fIGURE OUT THIS CRAZY THING SEC ROL ;LOW 5 BITS OF OPCODE STA TMPC TYA ASL ;MSB = MNEM*32 ASL ASL ASL ASL ORA TMPC ;ADD TO GET OPCODE CMP #$89 ;sta # BEQ :FAIL CLC RTS ;** sEARCH THROUGH TABLE 1 **ISOP1 LDY #$7F LDA STAGE:LOOP CMP NEMTAB,Y BNE :DEY LDX MODETAB,Y CPX STAGE+1 BEQ :GOTCHA CPX #3 ;cHECK FOR RELATIVE ADDRESSES BEQ :REL CPX #4 BEQ :REL:DEY DEY BPL :LOOP LDY #$8F ;SECOND PART OF TABLE LDX STAGE+1 ;$Xb IS ALL NO ARGS BNE :EXIT:LOOP2 CMP NEMTAB,Y BEQ :GOTCHA2:DEY2 DEY BMI :LOOP2:EXIT SEC RTS:REL LDA STAGE+1 CMP #9 ;A BNE :EXIT STX STAGE+1 LDA STAGE+2 CMP #2 BNE :EXIT JSR MAKEREL ;MAKE ADDRESS RELATIVE:GOTCHA TYA ASL RTS:GOTCHA2 TYA ASL ASL ASL ASL ORA #$0B RTS ;** cONVERT STAGE ADDRESS TO RELMAKEREL STX TMPC DEC TMPC LDA STAGE+4 SEC SBC TMPC ;2/3 FOR R/RLONG BCS :CONT DEC STAGE+5 SEC:CONT SBC TMP0 STA STAGE+4 LDA STAGE+5 SBC TMP0+1 STA STAGE+5 CPX #3 ;CHECK FOR OVERFLOW BNE :RTS LDA STAGE+4 CLC ADC #$80 LDA STAGE+5 ADC #00 BEQ :RTS JMP ERROR:RTS RTS* @@@@@*-------------------------------------* 16 BIT MULTIPLY AND DIVIDE ROUTINES.* tHREE 16 BIT (TWO-BYTE) LOCATIONS* acc, aux AND ext MUST BE SET UP,* PREFERABLY ON ZERO PAGE.*-------------------------------------* multiply routine* acc*aux -> [acc,ext] (LOW,HI) 32 BIT RESULTmult16 lda #0 sta ext+1 ldy #$11]loop lsr ext+1 ror ror acc+1 ror acc bcc mul2 clc adc aux pha lda aux+1 adc ext+1 sta ext+1 plamul2 dey bne ]loop sta ext rts* divide routine* acc/aux -> acc, REMAINDER IN extdiv16 lda #0 sta ext+1 ldy #$10]loop asl acc rol acc+1 rol rol ext+1 pha cmp aux lda ext+1 sbc aux+1 bcc div2 sta ext+1 pla sbc aux pha inc accdiv2 pla dey bne ]loop sta ext rts** asctonum*   cONVERTS A STRING TO A 16-BIT NUMBER.  tHE ADDRESS*   OF THE STRING IS PASSED IN IN (a,x) = (LO,HI), AND*   THE BASE OF THE NUMBER IS CONTAINED IN y.  vALID*   BASES ARE 0-16.  tHE STRING IS ASSUMED TO BE*   NULL-TERMINATED.**   oN EXIT, CARRY SET DENOTES AN ERROR, EITHER AN*   INVALID BASE, AN INVALID STRING, OR A NUMBER*   OVERFLOW.  tHE NUMBER IS CONTAINED IN acc, AS*   USED IN mult16.  tHE LAST CHAR READ IS CONTAINED*   IN (a,x)=(LO,HI).  y IS TOAST.*asctonum cpy #17 bcs :exit sty aux ;aux=NUMBER BASE ldy #00 sty aux+1 sty acc sty acc+1 stx :loop+2 tax ;x=LO BYTE STRING:loop lda $a000,x ;vALID CHARS ARE $30-$39, $41-$46 beq :exit eor #$30 cmp #10 bcc :cont eor #$70 ;sHOULD USE sbc #$70-9 adc #8 ;nOW a-f = 10-16:cont cmp aux ;cOMPARE WITH NUMBER BASE bcs :exit pha jsr mult16 ;mULTIPLY NUMBER TIMES BASE pla ldy ext ;dID MULTIPLICATION EXCEED 16 BITS? bne :error clc adc acc sta acc lda acc+1 adc #00 sta acc+1 inx bne :loop inc :loop+2 bne :loop:error sec:exit txa ldx :loop+2 rts** printnum*   pRINTS THE 16-BIT NUMBER IN (a,x) = (LO,HI)*   TO THE SCREEN, I.E. PRINTS USING chrout.*   tHE NUMBER BASE IS CONTAINED IN y.*printnum sta acc stx acc+1 sty aux ;bASE ldx #00 stx aux+1* acc/aux -> acc, REMAINDER IN ext:loop jsr div16 inx lda ext pha lda acc ora acc+1 bne :loop ;dIVIDE UNTIL RESULT=0:poop pla ora #$30 ;cONVERT TO CHR$ cmp #$3a bcc :plop adc #$06 ;$3a->a $3b->b ETC.:plop jsr chrout dex bne :poop rts