;************************************************************************ ;* * ;* CORK v1.0 * ;* Console Output Remapper Kernal * ;* * ;* S. Greenberg 12/12/88 * ;************************************************************************ ; v1.0 Placed in the public domain by Steven Greenberg, 12 December 1988 ; Responsible enhancements, corrections or offshoots encouraged. .Z80 ASEG ORG 100H FALSE EQU 0 TRUE EQU NOT FALSE ;______________________________________________________________________________ ; ; Note: The name of the target program may be changed - see "FCB:" below. ; The character mapping table is at the end of the program. ; Other configuration equates are here. ; RUBOUT EQU FALSE ; TRUE if your terminal / monitor will display ; ; - a 7FH character as a solid box. FALSE will ; ; - cause a '#' character to be substituted. ALTDRV EQU 'A' ; Alternate drive to find target program* ALTUSR EQU 0 ; Alternate user area to find target program* ; ; *Note: The current default DU is checked first, then the defined alternate. ; ; End of configuration. ;------------------------------------------------------------------------------ BDOS EQU 0005H CONO EQU 02H ; Console output DIRCON EQU 06H ; Direct console I/O OPEN EQU 0FH ; Open file CLOSE EQU 10H ; Close file READ EQU 14H ; Read sequential SETDMA EQU 1AH ; Set DMA address SGUSER EQU 20H ; Set / Get user ;------------------------------------------------------------------------------ ; START: SUB A ; Don't even think of running this w/o a Z80 JP PE,0000H ; 8080's take a quick exit LD DE,(6) ; Get BDOS vector DEC D ; Subtract 1/2 k DEC D ; PUSH DE ; Where our code will go, 1/2k below BDOS POP IX ; Leave IX ponting to that ("CODE+0") ;................................ ; PUSH DE ; Save the command tail information DEC D ; - temporarily, using the page LD HL,5CH ; - below where the code will go LD BC,100H-5CH ; LDIR ; POP DE ; ;...............................; LD HL,CODE ; Beg of code to be relocated LD BC,ENDCOD-CODE ; Length of code to be relocated LDIR ; Do it; copy code to hi-memory LD HL,(1) ; Get pointer to BIOS table +3 PUSH HL ; POP IY ; IY will remain pointing there LD HL,(6) ; Get system BDOS vector address LD (IX+7),L ; Put that in the address field LD (IX+8),H ; - of the jump instr (CODE+6,7,8) LD L,(IY+1) ; Get system warm boot vector address LD H,(IY+2) ; LD (IX+10),L ; Put that in the address field LD (IX+11),H ; - of the jump instr (CODE+9,10,11) LD L,(IY+10) ; Get system BIOS console out addr LD H,(IY+11) ; LD (IX+13),L ; Put that in the address field LD (IX+14),H ; - of the jump instr (CODE+12,13,14) PUSH IX ; POP HL ; (CODE+0) LD (6),HL ; Install redirected BDOS vector. INC HL ; INC HL ; (CODE+2) LD (IY+1),L ; Install redirected warm boot vector LD (IY+2),H ; INC HL ; INC HL ; (CODE+4) LD (IY+10),L ; Install redirected BIOS console out vector LD (IY+11),H ; LD DE,15-4 ; To get HL from CODE+4 to CODE+15 ADD HL,DE ; (CODE+15) 'pwr-up' entry JP (HL) ; Go to it ;.............................................................................. ; ; This section gets relocated to 1/2 k below BDOS. The code uses only relative ; jumps, and is inherently relocatable. Note: The relative offsets of next ; eight structures are 'hard-wired' into code. Do not change the positioning. ; CODE: JR BDOSPR ; (CODE+0) process a BDOS call. JR JWBOOT ; (CODE+2) process a warm boot JR CONOUT ; (CODE+4) process a BIOS console output call JPBDOS: JP $ ; (CODE+6) jp to sys BDOS ('$' gets filled in) JPWARM: JP $ ; (CODE+9) jump to system warm boot (likewise) JPBIOS: JP $ ; (CODE+12) jump to BIOS console output ENTRY: JR LOAD ; (CODE+15) initial 'pwr-up' entrypoint ; ; (CODE+17) an FCB to load the target program ; 12345678ext ; Filename may be changed. Must be 11 chars! ; ||||||||||| FCB: DB 0,'ZMP COM' ; <== Target filename DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;.............................................................................. ; ; Code below this pont may be changed (no more critical offsets) ; BDOSPR: PUSH AF ; <=== Intercept all BDOS calls here LD A,C ; Leave all regs intact till call is identified OR A ; BDOS function zero is a form of exit JR Z,JWBOOT ; (does anyone really use this?) CP CONO ; Is it console output? JR Z,YESCON ; If so... CP DIRCON ; Is it direct console output? JR Z,YESCON ; If so... NOTBL: POP AF ; Else just let it pass thru JR JPBDOS ; (jumps to system BDOS) ;................................ ; We have a console output call. No need to YESCON: LD A,E ; - save regs except func (in C) and char (E) CP 0FEH ; JR NC,NOTBL ; Let FE and FF thru. (Not chars under BDOS 6) ; POP AF ; Get this pop out of the way LD A,E ; Get the char in A SUB 80H ; Check hi bit / shift number down JR C,JPBDOS ; If 0-7F, don't remap (char still ok in E) ; LD HL,(6) ; Beg of this code LD DE,TABLE-CODE ; Length of this code; table is at end ADD HL,DE ; Offset to beg of conversion table ADD A,L ; Add in character offset LD L,A ; JR NC,NCRY ; INC H ; Possible carry NCRY: LD E,(HL) ; Get converted character ; IF RUBOUT ; LD A,E ; (could eliminate doing this at run time) CP "#" ; Convert '#''s in table to 7FH if indicated JR NZ,JPBDOS ; LD E,7FH ; ENDIF ; ; JR JPBDOS ; Note C reg still contains appropriate BDOS # ; - end of console output redirection - ;...............................; ;................................ ; CONOUT: LD A,C ; <== Intercept all BIOS console output here SUB 80H ; Check hi bit / shift number down JR C,JPBIOS ; If 0-7F, don't remap (char still ok in E) ; LD HL,(6) ; Beg of this code LD DE,TABLE-CODE ; Length of this code; table is at end ADD HL,DE ; Offset to beg of conversion table ADD A,L ; Add in character offset LD L,A ; JR NC,NCR2 ; INC H ; Possible carry NCR2: LD C,(HL) ; Get converted character ; IF RUBOUT ; LD A,C ; (could eliminate doing this at run time) CP "#" ; Convert '#''s in table to 7FH if indicated JR NZ,JPBIOS ; LD C,7FH ; ENDIF ; ; JR JPBIOS ; ;...............................; JWBOOT: JR WBOOT ; 'stepping stone' ;................................ ; LOAD: INC HL ; 'Pwr-on' entry. Load the target program. INC HL ; Tricky- we know HL (we got here via JP (HL) EX DE,HL ; So now DE points to the FCB at CODE+17 LD C,SGUSER ; Get current user, to restore with later PUSH DE ; LD E,0FFH ; CALL BDOS ; POP DE ; PUSH AF ; Will pop this back after loading program LD C,OPEN ; Attempt to open the file PUSH DE ; CALL BDOS ; POP DE ; OR A ; JR Z,OPOK ; If file opened OK... LD A,ALTDRV-'@' ; Try alternate DU LD (DE),A ; LD C,SGUSER ; PUSH DE ; LD E,ALTUSR ; CALL BDOS ; POP DE ; LD C,OPEN ; Attempt to open the file PUSH DE ; CALL BDOS ; POP DE ; OR A ; JR NZ,FIXUSR ; Graceful exit if fails (message here?) OPOK: LD HL,100H ; Else init DMA setting to load target program ; RDLP: EX DE,HL ; Now DE is DMA, HL is FCB ; LD C,SETDMA ; Set DMA PUSH HL ; PUSH DE ; CALL BDOS ; POP DE ; POP HL ; ; EX DE,HL ; Now HL is DMA, DE is FCB ; LD C,READ ; Xfer a sector PUSH HL ; PUSH DE ; CALL BDOS ; POP DE ; POP HL ; ; CP 1 ; JR Z,EOFILE ; If done.. JR NC,FIXUSR ; If random read failure LD BC,80H ; Else incr dest addr and loop ADD HL,BC ; JR RDLP ; ;...............................; FIXUSR: POP AF LD E,A LD C,SGUSER CALL BDOS JR WBOOT ;.............................................................................. ; ; EOFILE: POP AF ; User#, pushed a long time ago! LD E,A ; LD C,SGUSER ; CALL BDOS ; LD DE,0080H ; Set the default DMA back to 80H LD C,SETDMA ; CALL BDOS ; ;................................ ; LD HL,(6) ; Restore the command tail information DEC H ; - as originally supplied to this program LD DE,5CH ; LD BC,100H-5CH ; LDIR ; ;...............................; CALL 100H ; 'Fork a child process..' :-) ; It will either WBOOT or return to here ; - same difference. Fall thru to below.. ;................................ ; WBOOT: LD IX,(6) ; Code to restore all vectors on exit LD IY,(1) ; LD L,(IX+7) ; LD H,(IX+8) ; LD (6),HL ; Restore BDOS vector from CODE+7,8 LD L,(IX+10) ; LD H,(IX+11) ; LD (IY+1),L ; Restore BIOS warm boot addr LD (IY+2),H ; LD L,(IX+13) ; LD H,(IX+14) ; LD (IY+10),L ; Restore BIOS console output vector LD (IY+11),H ; JP 0 ; And do a warm boot (the CCP is *not* there) ;...............................; ;------------------------------------------------------------------------------ ; ; Traslate table. Values to which we map bytes 80 - FF. TABLE: ; 8-------------->9--------------> ; ; 0123456789ABCDEF0123456789ABCDEF ; ==> Byte... DB ' ' ; <== maps to ; A-------------->B--------------> ; ; 0123456789ABCDEF0123456789ABCDEF ; ==> Byte... DB ' ++ |<>###|++++++|+++++' ; <== maps to ; C-------------->D--------------> ; ; 0123456789ABCDEF0123456789ABCDEF ; ==> Byte... DB '++++-++++++++-+++++++++++++#*||*' ; <== maps to ; E-------------->F--------------> ; ; 0123456789ABCDEF0123456789ABCDEF ; ==> Byte... DB ' = ' ; <== maps to ENDCOD EQU $ ; That's it! END