Wiki

Clone wiki

Super-Mon / SuperMon_internals

Super-Mon Internals

Miscellaneous notes on how Super-Mon works internally, and how to make changes to it.

Relocation script

Below is a script used to relocate Super-mon from upper mem ($E000.FFFF) to low mem ($6000.7FFF), so that one can use Super-mon to work on itself. This depends on a file (FRELOC) present only on Super-Mon-dev.dsk, not on the main distribution disk.

2000<FRELOCR
2000G

Zero-page

LocationUse
50PTMP
52QTMP
54PSYM
56BITCOUNT
57YSAVE
58PROGBEG
5APROGEND
5CMOVELEN
5ETARGET
60DSTEND

Internal routines

SymbolDescription
COLDSTCold start
WARMSTWarm start
MONLUPMon main loop patch
MONSPCMon space patch ($FF >= #81)
XBRFIX'X' forward branch fixer
PRERRXPrint ERR, jump to mon
XMONReset stack, jump to mon
GETNUM0Normal getnum without patches, using $34 for Y
GETNUMRResume getnum having put num in $3E/3F and advanced $34
GNUMPCGetnum patch "*" ($FF >= #82)
SHFTBITSShift Y bits from A into SYMBUF; (low bit first); decrement BITCOUNT and go to err if no more
ENCHAREncode char in A if sym char; sec if so else clc.
ENSYMEncode symbol $200,Y to SYMBUF. Y adv to next after sym. Sec if at least 3 chars, else clc.
SHFTBITSShift down SYMBUF by X bits
CHDECODDecode 1 char from SYMBUF
SYMDECODDecode and print symbol (PSYM)
AXDECdecrement A/X
AXINCincrement A/X
BUMPSYMBump PSYM, sec if ok, clc if at end.
FSYMSLOTLook for open slot and add sym name SYMBUF. Jump to err if full.
GLBSETGetnum patch: label set/get
SYMSCANSymbol scan (optimized): SYMBUF against sym tbl. PSYM set and sec if found. If sym value is zero, no match.
GPLUSResume getnum after checking for "+"
BLDHASHRebuild hash table, set hash marker
PRSYMTBL"T" handler: Print symbols in address range A1..A2
CHKSYMCheck if A1 ($3C/3D) is symbol; if so sec and set PSYM
CHKSYM2Check linked sym hash entry against A1 as in CHKSYM
PGPATCHPaging patch: expects count on stack; destroys A and X
BLDHASHZRebuild hash table only if necessary.
LSADRPatch: address printing in disassembly (FF:>=84 to enable)
LSLABPatch: label header in disassembly (FF>=85 to enable)
RWSYMRead/write symbol tbl
MONZAP"Z" zap handler
LSLUPPatch: replacement List loop (counter in BITCOUNT)
MKINSRe-create instruction length table
SUBDSubtract: (0,X) - (0,Y) -> (0,A) (preserves all regs)
READROMRead ROM
WRITEROMWrite ROM
CMPDSet carry if (0,X) >= (0,Y) (preserves all regs)
ADDDAdd: (0,X) + (0,Y) -> (0,A) (preserves all regs)
OVLMOVEMon overlapping move handler (FF>=86 to enable)
INCDIncrement (0,X) (preserves all regs)
DECDDecrement (0,X) (preserves all regs)
COLDSTPPatch: cold start - read sym tbl, clear PROGBEG and PROGEND
SETPROG"P" prog range handler
MKPGTB2sub: for page tbl building
MKPGTBLBuild table of pages that need rel checking ($80) and pages that are in SRCBEG.SRCEND ($01 or $81) at $200.2FF
FIXINBUFsub: fill $200.2FF with 8D
RELSCANRelocation scanning loop
SMRTMVBSmart move with relocate (FF>=87 to enable)
CALCQTsub: calc PTMP,Y -> QTMP, save Y in YSAVE
DISQTMPsub: CR, then disassemble QTMP (no CR after)
INCINSFXsub: increment INSFIXCT
BETWEENDsec if (0,X) <= (0,A) <= (0,Y) (preserves all regs)
DSQTMP2sub: calc PTMP,Y, save Y, sec if QTMP between PROGBEG..END
ABSRELOCAbsolute instruction relocate
FIXBRNCHFix rel branch at (QTMP) to TARGET and print it. ERR and clc if far.
CALCBRCompute target of branch at (QTMP) -> TARGET.
RELRELOCRelative instruction relocate
AXMAXSelect max(A/X vs. 0,Y) -> A/X
AXMINSelect min(A/X vs 0,Y) -> A/X
AXPCLMPsub: Clamp A/X between PROGBEG..PROGEND+1
NONOVLsub: calc non-overlapping part of smart move to clear
SMRTMVCRelocate with remainder range clear (FF>=88 to enable)
RELSYMsub: relocate symbols in SRCBEG.SRCEND (limited by PROGB.E)
SMRTMVDRelocate with symbols (FF>=89 to enable)
PCSRCsub: if SRCBEG specified, move to PCL; else move PCL to SRCBEG and SRCEND. Either way, sec if SRCBEG <> SRCEND
FZEROSsub: move SRCEND forward until it points to BITCOUNT zeros
MONINSInsert operator
MONKLSKlose operator
PHRNGsub: save move range to stack
PLRNGsub: restore move range from stack
PRNGsub: print DSTBEG<SRCBEG.SRCEND
CALCLENsub: calc MOVELEN and DSTEND
SAVEPCLsub: save PCL on stack
ADRPTCHpatch: don't print label if immediate fmt
FMTPTCHpatch: save format in PSYM
FILTLABLpatch: check for shorter label not separated by space; if not, check for probable label, ERR if so.
MONQUOTEProcess quote command
MONSRCHProcess search command
DATPTCH1ASCII dump patch
DATPTCH2"
DATPTCH3"
DATFLUSH"
PRLBORNUMPrint num in SRCBEG ($3C/3D), with PTMP bytes (1 or 2). If label+-0/1/2 or PC+-0/1/2, print that instead.
NODOLLARSPatch: don't print $ in normal disassembly (we only want one if not a label)
CKSYMORPCCheck SRCBEG if label or PCL. If so print and SEC; else clc.
......a bunch of routines that need documenting.
IDSHORT2Check if (QTMP) is a Short routine, SEC if so and put # args in X.
SHDISARGDisassemble one Short argument at (PCL).
SHPRADDRPrint address of short var or call in A(lo) / X(hi).
SHPRDECPrint PTMP as a 16-bit decimal number 0..65535. Uses QTMP, BITCOUNT, and SRCBEG.
CALCDIGITSubroutine used by SHPRDEC.

Helpful info for move/relocation routines:

LocationSymbol
3CSRCBEG
3ESRCEND
42DSTBEG
50PTMP
52QTMP
58PROGBEG
5APROGEND
5CMOVELEN
5ETARGET
60DSTEND

String table

LocationPurpose
F400Print string,X
--0C"FULL "
--12"[cr]SMARTMV "
--1C" SYMS, "
--24" INSTRS"
--2C"P-RANGE "
--36"TIGHT: INS MORE"
--46"[cr] FREE SECS: "
--53"(RD SYM)[cr]"
--5D"(WR SYM)[cr]"

Files

NakedOS File #SymbolAddress rangePurpose
DF01FHELLO1800.19FF$1800 loads Super-mon and sym tbl; $1940 regenerates the patch and saves everything.
DF02FSUPERMONE000.F7FFSuper-mon routines
DF03FSYMTBL1D000.DFFF (bank 2)Sym tbl 1 - addresses and hash links
DF04FSYMTBL2D000.DFFF (bank 1)Sym tbl 2 - packed names

Updated