p** sUPERmon 64** oRIGINAL SOURCE CODE COURTESY jIM bUTTERFIELD** mERLINIZED AND ADAPTED FOR THE sUPERcpu BY* sTEPHEN l. jUDD* 3/14/97**REM"S= DSAVE"@SUPER64.SRC2"*REM;OPEN 8,8,8,"1:LISTING,S,W"*SYS7*4096;.OPT P8; SUPERMON 64 SEPT 9/83;*=  $9824 org $9824SAVX = $1CTMPC = $1DNEMO = $1ELENGTH = $1FPSAV = $20WRAP = $26AFLG = $28ACMD = $2ASATUS = $90LVFLAG = $93INDEV = $99OUTDEV = $9AEAL = $AEEAH = $AFFNLEN = $B7WTYPE = $B9FA = $BAFNADR = $BBTMP0 = $C1TMP2 = $C3INBUF = $0100STAGE = $0210ADDRS = $0240PCH = $0239PCL = $023AFLGS = $023BACC = $023CXR = $023DYR = $023ESP = $023FBKVEC = $0316READY = $A002LDVEC = $0330SVVEC = $0332SETMSG = $FF90RDT = $FFCFWRT = $FFD2STOP1 = $FFE1; ** INITIALIZATION **SUPER LDA LINKAD STA BKVEC LDA LINKAD+1 STA BKVEC+1 LDA #$80 JSR SETMSG BRK; ** BREAK ENTRY **BREAK CLD CLI PLA STA YR PLA STA XR PLA STA ACC PLA STA FLGS PLA TAX PLA TAY SEC TXA SBC #$02 STA PCL TYA SBC #0 STA PCH TSX STX SP JSR CRLF LDX #$42 LDA #$2A JSR WRTWO LDA #$52 BNE S0; ** 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 #$0ES1 CMP KEYW,X BNE S2 TXA ASL A TAX LDA KADDR+1,X PHA LDA KADDR,X PHA RTSS2 DEX BPL S1 JMP ERROR; ** SET PC ADDRRESS **PUTP LDA TMP0 STA PCL LDA TMP0+1 STA PCH RTS; ** MEMORY DISPLAY **DM LDA #$08DM0 STA TMPC LDY #0DM1 JSR SPACE LDA (TMP0),Y JSR WROB JSR INCTMP DEC TMPC BNE DM1 RTS; ** CHANGE MEMORY **BYTE JSR RDOB BCC BY3 LDX #0 STA (TMP0,X) CMP (TMP0,X) BEQ BY3 JMP ERRORBY3 JSR INCTMP DEC TMPC RTS; ** SET PC REG ADDRS **SETR LDA #<PCH+2 STA TMP0 LDA #>PCH+2 STA TMP0+1 LDA #5 RTS; ** WRITE DISPLAY PROMPT **ALTRIT TYA  PHA JSR CRLF PLA LDX #$2E JMP WRTWO; **DISPLAY REGISTERS **DSPLYR LDX #0D2 LDA REGK,X JSR WRT INX CPX #$16 BNE D2 LDY #$3B JSR ALTRIT LDA PCH JSR WROB LDA PCL JSR WROB JSR SETR JSR DM0 BEQ A9; ** DISPLAY MEMORY **DSPLYM JSR RDOC JSR RDOA BCC ERRS1 LDA TMP0 STA TMP2 LDA TMP0+1 STA TMP2+1 JSR RDT CMP #$0D BEQ DSP1 JSR RDOA BCC ERRS1 JSR T2T2DSP1 JSR STOP1 BEQ A9 LDX WRAP BNE A9 JSR DIFFP BCC A9 LDY #$3A JSR ALTRIT JSR WROA JSR DM BEQ DSP1ERRS1 JMP ERROR; ** ALTER MEMORY **ALTR JSR RDOA BCC AL2 JSR PUTPAL2 JSR SETR BNE A0ALTM JSR RDOA BCC ERRS1A4 LDA #$08A0 STA TMPCA5 JSR RDOC JSR BYTE BNE A5A9 JMP STRT; ** .GO **GO JSR RDT CMP #$0D BEQ G1 CMP #$20 BNE ERRS1 JSR RDOA BCC G1 JSR PUTPG1 LDX SP TXS SEI LDA PCH PHA LDA PCL PHA LDA FLGS PHA LDA ACC LDX XR LDY YR RTI; ** BACK TO BASIC **EXIT LDX SP TXS JMP (READY); ** 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L1 JSR RDT CMP #$20 BEQ L1 CMP #$0D BEQ L5 CMP #$22L2 BNE ERRLL3 JSR RDT CMP #$22 BEQ L8 CMP #$0D BEQ L5 STA (FNADR),Y INC FNLEN INY CPY #$10L4 BNE L3ERRL JMP ERRORL8 JSR RDT CMP #$0D BEQ L5 CMP #$2C BNE L2 JSR RDOB AND #$0F BEQ L4 CMP #$03 BEQ L4 STA FA JSR RDT CMP #$0DL5 RTSLD15 JMP (LDVEC)SV15 JMP (SVVEC)LOAD JSR LD BNE ERRL LDA #$00 JSR LD15 LDA SATUS AND #$10 BNE ERRL JMP STRTSAVE JSR LD CMP #$2C BNE ERRL JSR RDOA JSR T2T2 JSR RDT CMP #$2C BNE ERRL JSR RDOA LDA TMP0 STA EAL LDA TMP0+1 STA EAH JSR T2T2 JSR RDT CMP #$0D BNE ERRL JSR SV15 JMP STRT; ** PRINT HEX BYTE **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; ** CONVERT TO ASCII **ASCII ORA #$30 CMP #$3A BCC ASC1 ADC #$06ASC1 RTS ; ** SWAP TMP0, TMP2 **T2T2 LDX #$02T2T21 LDA TMP0-1,X PHA LDA TMP2-1,X STA TMP0-1,X PLA STA TMP2-1,X DEX BNE T2T21 RTS; ** READ HEX ADDRESS **RDOA JSR RDOBRDOA1 BCC RDOA2 STA TMP0+1RDOA2 JSR RDOB BCC RDEXIT STA TMP0RDEXIT RTSRDOB LDA #0; ** SCAN FOR HEX BYTE ** 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; ** 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; ** GET ADDRESS **INPUT LDA #0 STA INBUF JSR GTCHR JSR RDOB1 JSR RDOA1 BCC ERROR RTS; ** GET ADDRESS **GET2B JSR RDOC JSR RDOA BCS RET1; ** ERROR EXIT **ERROR LDX SP TXS LDA #$3F JSR WRT JMP STRT; ** 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 #$02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 SEC SBC #2 BCS DECK DEY BCC DECK; ** CALC AFLG-TMP0 **DIFFA LDA AFLG LDY AFLG+1 JMP DECK; ** CALC TMP2-TMP0 **DIFFP LDA TMP2 LDY TMP2+1DECK SEC  SBC TMP0 STA NEMO TYA SBC TMP0+1 TAY ORA NEMO RTS; ** .TRANSFER **TRANS JSR INPUT JSR T2T2 JSR GET2B JSR SWAP JSR GET2B JSR DIFFP JSR T2T2 BCC MOV2; ** MOVE DOWN **MLLP1 LDX WRAP BNE STRT1 JSR DIFFA BCC STRT1 LDA (TMP0,X) STA (TMP2,X) JSR PTRINC JSR INCTMP BNE MLLP1; ** MOVE UP **MOV2 JSR DIFFA CLC LDA NEMO ADC TMP2 STA TMP2 TYA ADC TMP2+1 STA TMP2+1 JSR SWAPMLLP2 LDX WRAP BNE STRT1 LDA (TMP0,X) STA (TMP2,X) JSR DIFFA BCS STRT1 JSR DECT2 JSR DECT0 JMP MLLP2; ** .FILL **FILL JSR INPUT JSR T2T2 JSR GET2B JSR T2T2 JSR RDOC JSR RDOB BCC ERROR2 STA TMPCFLUP1 LDX WRAP BNE STRT1 JSR DIFFP BCC STRT1 LDA TMPC STA (TMP0,X) JSR INCTMP BNE FLUP1ERROR2 JMP ERRORSTRT1 JMP STRT; ** .HUNT **HUNT JSR INPUT JSR T2T2 JSR GET2B JSR T2T2 JSR RDOC LDX #0 JSR RDOC CMP #$27 BNE NOSTRH JSR RDOCHPAR STA STAGE,X INX JSR RDT CMP #$0D BEQ HTGO CPX #$20 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 #$20 BNE HLPHTGO STX SAVX JSR CRLFHSCAN LDX #0 LDY #0HLP3 LDA (TMP0),Y CMP STAGE,X BNE HNMTCH INY INX CPX SAVX BNE HLP3; ** MATCH FOUND ** JSR WROA JSR SPACEHNMTCH JSR INCTMP LDX WRAP BNE STRT1 JSR DIFFP BCS HSCAN JMP STRT; ** .DISASSEMBLE **DISAS JSR INPUT STA PSAV LDA TMP0+1 STA PSAV+1 LDX #0 STX AFLGDPAG LDA #$93  ;CLR JSR WRT LDA #$16 STA TMPCDISLP JSR DISS1 JSR PCADJ STA TMP0 STY TMP0+1 DEC TMPC BNE DISLP LDA #$91       ;UP JSR WRT JMP STRT; ** DISS 1 LINE **DISS1 LDY #"," JSR ALTRIT JSR SPACEDISS1A JSR WROA JSR SPACE LDX #0 LDA (TMP0,X) JSR INSTXX PHA  JSR DISVV PLA  JSR PROPXX LDX #$06PRADR1 CPX #$03 BNE PRADR3 LDY LENGTH BEQ PRADR3PRADR2 LDA ACMD CMP #$E8 LDA (TMP0),Y BCS RELADR JSR PRBYTE DEY  BNE PRADR2PRADR3 ASL ACMD BCC PRADR4 LDA CHAR1-1,X JSR CHROUT LDA CHAR2-1,X BEQ PRADR4 JSR CHROUTPRADR4 DEX  BNE PRADR1 RTS ; ** PRINT REL ADDRESS **RELADR JSR PCADJ3 TAX  INX  BNE PRNTYX INY PRNTYX TYA  JSR PRBYTE TXA PRBYTE STX SAVX JSR WROB LDX SAVX RTS ; ** ADD LENGTH+1 TO PC **PCADJ LDA LENGTH SEC PCADJ3 LDY TMP0+1 TAX  BPL PCADJ4 DEY PCADJ4 ADC TMP0 BCC RTS1 INY RTS1 RTS ; ** CHECK INST VALID, LEN **INSTXX TAY  LSR A BCC IEVEN LSR A BCS ERR CMP #$22 BEQ ERR AND #$07 ORA #$80IEVEN LSR A TAX  LDA MODE,X BCS RTMODE LSR A LSR A LSR A LSR ARTMODE AND #$0F BNE GETFMTERR LDY #$80 LDA #0; ** GET ADDR MODE, LENGTH **GETFMT TAX  LDA MODE2,X STA ACMD AND #$03 STA LENGTH; ** EXTRACT INTRUCTN ** TYA  AND #$8F TAX  TYA  LDY #$03 CPX #$8A BEQ MNNDX3MNNDX1 LSR A BCC MNNDX3 LSR AMNNDX2 LSR A ORA #$20 DEY  BNE MNNDX2 INY MNNDX3 DEY  BNE MNNDX1 RTS ; PRINT BYTESDISVV LDA (TMP0),Y JSR PRBYTE LDX #1DISVL JSR SPACD CPY LENGTH INY  BCC DISVV LDX #$03 CPY #4 BCC DISVL RTS ; ** PRINT MNEMONIC **PROPXX TAY  LDA MNEML,Y STA AFLG LDA MNEMR,Y STA AFLG+1PRMN1 LDA #0 LDY #$05PRMN2 ASL AFLG+1 ROL AFLG ROL A DEY  BNE PRMN2 ADC #$3F JSR WRT DEX  BNE PRMN1; ** 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 JSR T2T2 JSR GET2B JSR T2T2 LDX #0 STX AFLGPLOOP JSR CRLF JSR DISS1A JSR PCADJ STA TMP0 STY TMP0+1 JSR STOP1 BEQ STRTX JSR DIFFP BCS PLOOPSTRTX JMP STRT; ** RE-DISASSEMBLE **REDIS JSR INPUT LDA #$03 STA TMPCRLP JSR RDOC JSR BYTE BNE RLP LDA PSAV STA TMP0 LDA PSAV+1 STA TMP0+1 JMP DPAGCHROUT CMP AFLG BEQ CALTRIT JSR WRTCALTRIT RTS ; ** ASSEMBLE **ASSEM JSR INPUTASSRP JSR T2T2 STX STAGE+1 LDX #$03APUSH JSR GTCHR PHA  DEX  BNE APUSH LDX #$03APULL PLA  SEC  SBC #$3F LDY #$05ACRUN LSR A ROR STAGE+1 ROR STAGE DEY  BNE ACRUN DEX  BNE APULL LDX #$02AINP JSR RDT CMP #$0D BEQ ARET CMP #$20 BEQ AINP JSR AHEX BCS STONE JSR RDOB2 LDY TMP0 STY TMP0+1 STA TMP0 LDA #$30 STA STAGE,X INX STONE STA STAGE,X INX  BNE AINPARET STX AFLG LDX #0 STX WRAP BEQ ATRYABUMP INC WRAP BEQ AERRATRY LDX #0 STX TMPC LDA WRAP JSR INSTXX LDX ACMD STX AFLG+1 TAX  LDY MNEML,X LDA MNEMR,X JSR ACHEK2 BNE ABUMP LDX #$06AOPRND CPX #$03 BNE ASHF LDY LENGTH BEQ ASHFARSC LDA ACMD CMP #$E8 LDA #$30 BCS AREL1 JSR ACHECK BNE ABUMP JSR ACHICK BNE ABUMP DEY  BNE ARSCASHF ASL ACMD BCC ADEX LDY CHAR2-1,X LDA CHAR1-1,X JSR ACHEK2 BNE ABUMPADEX DEX  BNE AOPRND BEQ ALDAREL1 JSR ACDB1 BNE ABUMP JSR ACDB1 BNE ABUMPALD LDA AFLG CMP TMPC BNE ABUMP JSR T2T2 LDY LENGTH BEQ AOPSET LDA AFLG+1 CMP #$9D BNE AOPND JSR DIFFB BCC ABDOWN TYA  BNE AERR LDA NEMO BPL ABRANAERR JMP ERRORABDOWN INY  BNE AERR LDA NEMO BPL AERRABRAN LDY LENGTH BNE ABRELAOPND LDA TMP2-1,YABREL STA (TMP0),Y DEY  BNE AOPNDAOPSET LDA WRAP STA (TMP0),Y JSR PCADJ STA TMP0 STY TMP0+1 LDY #$41 JSR ALTRIT JSR SPACE JSR WROA JSR SPACE JMP ASSRPACDB1 TAY ACHEK2 JSR ACHECK BNE ACEX TYA ACHECK BEQ ACEXACHICK STX SAVX LDX TMPC CMP STAGE,X PHP  INX STX TMPC LDX SAVX PLP ACEX RTS AHEX CMP #$30 BCC ASX CMP #$47 RTS ASX SEC  RTS ; MODE TABLE... NYBBLE ORGANIZED; 0= ERR  4= IMPLIED  8= ZER,X   C= ZER,Y; 1= IMM  5= ACC      9= ABS,X   D= REL; 2= ZER  6= (IND,X)  A= ABS,Y; 3= ABS  7= (IND),Y  B= (IND)MODE DFB $40,$02,$45,$03 DFB $D0,$08,$40,$09 DFB $30,$22,$45,$33 DFB $D0,$08,$40,$09 DFB $40,$02,$45,$33 DFB $D0,$08,$40,$09 DFB $40,$02,$45,$B3 DFB $D0,$08,$40,$09 DFB $00,$22,$44,$33 DFB $D0,$8C,$44,$00 DFB $11,$22,$44,$33 DFB $D0,$8C,$44,$9A DFB $10,$22,$44,$33 DFB $D0,$08,$40,$09 DFB $10,$22,$44,$33 DFB $D0,$08,$40,$09 DFB $62,$13,$78,$A9;MASTER MODES;SIX HI-ORDER BITS  MODE OPTIONS;TWO LO-ORDER BITS  OPERAND LENGTHREADY.MODE2 DFB $00,$21,$81,$82 DFB $00,$00,$59,$4D DFB $91,$92,$86,$4A,$85,$9DCHAR1 DFB $2C,$29,$2C,$23,$28,$24CHAR2 DFB $59,$00,$58,$24,$24,$00; PACKED MNEMONICSMNEML DFB $1C,$8A,$1C,$23 DFB $5D,$8B,$1B,$A1 DFB $9D,$8A,$1D,$23 DFB $9D,$8B,$1D,$A1 DFB $00,$29,$19,$AE DFB $69,$A8,$19,$23 DFB $24,$53,$1B,$23 DFB $24,$53,$19,$A1 DFB $00,$1A,$5B,$5B DFB $A5,$69,$24,$24 DFB $AE,$AE,$A8,$AD DFB $29,$00,$7C,$00 DFB $15,$9C,$6D,$9C DFB $A5,$69,$29,$53 DFB $84,$13,$34,$11 DFB $A5,$69,$23,$A0MNEMR DFB $D8,$62,$5A,$48 DFB $26,$62,$94,$88 DFB $54,$44,$C8,$54 DFB $68,$44,$E8,$94 DFB $00,$B4,$08,$84 DFB $74,$B4,$28,$6E DFB $74,$F4,$CC,$4A DFB $72,$F2,$A4,$8A DFB $00,$AA,$A2,$A2 DFB $74,$74,$74,$72 DFB $44,$68,$B2,$32 DFB $B2,$00,$22,$00 DFB $1A,$1A,$26,$26 DFB $72,$72,$88,$C8 DFB $C4,$CA,$26,$48 DFB $44,$44,$A2,$C8KEYW TXT ':;RMGXLS' TXT 'TFHDP,A'KADDR DW ALTM-1 DW ALTR-1 DW DSPLYR-1 DW DSPLYM-1 DW GO-1 DW EXIT-1 DW LOAD-1 DW SAVE-1 DW TRANS-1 DW FILL-1 DW HUNT-1 DW DISAS-1 DW PRIN-1 DW REDIS-1 DW ASSEM-1 DW STRT-1 ;NLINKAD DW BREAKSADR DW SUPERREGK DFB $0D TXT '   PC  SR' TXT ' AC XR YR SP'