home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / BEEHIVE / UTILITYS / CORK10.ARC / CORK.Z80 < prev    next >
Text File  |  1991-08-11  |  10KB  |  342 lines

  1. ;************************************************************************
  2. ;*                                    *
  3. ;*                  CORK v1.0                 *
  4. ;*            Console Output Remapper Kernal            *
  5. ;*                                    *
  6. ;*                        S. Greenberg  12/12/88    *
  7. ;************************************************************************
  8.  
  9. ; v1.0 Placed in the public domain by Steven Greenberg, 12 December 1988
  10. ;      Responsible enhancements, corrections or offshoots encouraged.
  11.  
  12.  
  13.     .Z80
  14.     ASEG
  15.     ORG    100H
  16.  
  17. FALSE    EQU    0
  18. TRUE    EQU    NOT FALSE
  19. ;______________________________________________________________________________
  20. ;
  21. ; Note: The name of the target program may be changed - see "FCB:" below.
  22. ;    The character mapping table is at the end of the program.
  23. ;    Other configuration equates are here.
  24. ;
  25. RUBOUT    EQU    FALSE        ; TRUE if your terminal / monitor will display
  26. ;                ; - a 7FH character as a solid box. FALSE will
  27. ;                ; - cause a '#' character to be substituted.
  28. ALTDRV    EQU    'A'        ; Alternate drive to find target program*
  29. ALTUSR    EQU    0        ; Alternate user area to find target program*
  30. ;
  31. ; *Note: The current default DU is checked first, then the defined alternate.
  32. ;
  33. ; End of configuration.
  34. ;------------------------------------------------------------------------------
  35.  
  36. BDOS    EQU    0005H
  37.  
  38. CONO    EQU    02H        ; Console output
  39. DIRCON    EQU    06H        ; Direct console I/O
  40. OPEN    EQU    0FH        ; Open file
  41. CLOSE    EQU    10H        ; Close file
  42. READ    EQU    14H        ; Read sequential
  43. SETDMA    EQU    1AH        ; Set DMA address
  44. SGUSER    EQU    20H        ; Set / Get user
  45.  
  46. ;------------------------------------------------------------------------------
  47. ;
  48. START:    SUB    A        ; Don't even think of running this w/o a Z80
  49.     JP    PE,0000H    ; 8080's take a quick exit
  50.     LD    DE,(6)        ; Get BDOS vector
  51.     DEC    D        ; Subtract 1/2 k
  52.     DEC    D        ;
  53.     PUSH    DE        ; Where our code will go, 1/2k below BDOS
  54.     POP    IX        ; Leave IX ponting to that ("CODE+0")
  55.  
  56. ;................................
  57.                 ;
  58.     PUSH    DE        ; Save the command tail information
  59.     DEC    D        ; - temporarily,  using the page
  60.     LD    HL,5CH        ; - below where the code will go
  61.     LD    BC,100H-5CH    ;
  62.     LDIR            ;
  63.     POP    DE        ;
  64. ;...............................;
  65.  
  66.     LD    HL,CODE        ; Beg of code to be relocated
  67.     LD    BC,ENDCOD-CODE    ; Length of code to be relocated
  68.     LDIR            ; Do it; copy code to hi-memory
  69.  
  70.     LD    HL,(1)        ; Get pointer to BIOS table +3
  71.     PUSH    HL        ;
  72.     POP    IY        ; IY will remain pointing there
  73.  
  74.     LD    HL,(6)        ; Get system BDOS vector address
  75.     LD    (IX+7),L    ; Put that in the address field
  76.     LD    (IX+8),H    ; - of the jump instr (CODE+6,7,8)
  77.  
  78.     LD    L,(IY+1)    ; Get system warm boot vector address
  79.     LD    H,(IY+2)    ;
  80.     LD    (IX+10),L    ; Put that in the address field
  81.     LD    (IX+11),H    ; - of the jump instr (CODE+9,10,11)
  82.  
  83.     LD    L,(IY+10)    ; Get system BIOS console out addr
  84.     LD    H,(IY+11)    ;
  85.     LD    (IX+13),L    ; Put that in the address field
  86.     LD    (IX+14),H    ; - of the jump instr (CODE+12,13,14)
  87.  
  88.  
  89.     PUSH    IX        ;
  90.     POP    HL        ; (CODE+0)
  91.     LD    (6),HL        ; Install redirected BDOS vector.
  92.  
  93.     INC    HL        ;
  94.     INC    HL        ; (CODE+2)
  95.     LD    (IY+1),L    ; Install redirected warm boot vector
  96.     LD    (IY+2),H    ;
  97.  
  98.     INC    HL        ;
  99.     INC    HL        ; (CODE+4)
  100.     LD    (IY+10),L    ; Install redirected BIOS console out vector
  101.     LD    (IY+11),H    ;
  102.  
  103.     LD    DE,15-4        ; To get HL from CODE+4 to CODE+15
  104.     ADD    HL,DE        ; (CODE+15) 'pwr-up' entry
  105.     JP    (HL)        ; Go to it
  106.  
  107. ;..............................................................................
  108. ;
  109. ; This section gets relocated to 1/2 k below BDOS. The code uses only relative
  110. ; jumps, and is inherently relocatable. Note: The relative offsets of next
  111. ; eight structures are 'hard-wired' into code.    Do not change the positioning.
  112. ;
  113. CODE:    JR    BDOSPR        ; (CODE+0) process a BDOS call.
  114.     JR    JWBOOT        ; (CODE+2) process a warm boot
  115.     JR    CONOUT        ; (CODE+4) process a BIOS console output call
  116.  
  117. JPBDOS:    JP    $        ; (CODE+6) jp to sys BDOS ('$' gets filled in)
  118. JPWARM:    JP    $        ; (CODE+9) jump to system warm boot (likewise)
  119. JPBIOS:    JP    $        ; (CODE+12) jump to BIOS  console output
  120.  
  121. ENTRY:    JR    LOAD        ; (CODE+15) initial 'pwr-up' entrypoint
  122.  
  123. ;                ; (CODE+17) an FCB to load the target program
  124. ;           12345678ext    ; Filename may be changed. Must be 11 chars!
  125. ;           |||||||||||
  126. FCB:    DB    0,'ZMP     COM'    ; <== Target filename
  127.  
  128.     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
  129.  
  130. ;..............................................................................
  131. ;
  132. ; Code below this pont may be changed (no more critical offsets)
  133. ;
  134. BDOSPR:    PUSH    AF        ; <=== Intercept all BDOS calls here
  135.     LD    A,C        ; Leave all regs intact till call is identified
  136.     OR    A        ; BDOS function zero is a form of exit
  137.     JR    Z,JWBOOT    ; (does anyone really use this?)
  138.     CP    CONO        ; Is it console output?
  139.     JR    Z,YESCON    ; If so...
  140.     CP    DIRCON        ; Is it direct console output?
  141.     JR    Z,YESCON    ; If so...
  142.  
  143. NOTBL:    POP    AF        ; Else just let it pass thru
  144.     JR    JPBDOS        ; (jumps to system BDOS)
  145.  
  146. ;................................
  147.                 ; We have a console output call. No need to
  148. YESCON:    LD    A,E        ; - save regs except func (in C) and char (E)
  149.     CP    0FEH        ;
  150.     JR    NC,NOTBL    ; Let FE and FF thru. (Not chars under BDOS 6)
  151.                 ;
  152.     POP    AF        ; Get this pop out of the way
  153.     LD    A,E        ; Get the char in A
  154.     SUB    80H        ; Check hi bit / shift number down
  155.     JR    C,JPBDOS    ; If 0-7F, don't remap (char still ok in E)
  156.                 ;
  157.     LD    HL,(6)        ; Beg of this code
  158.     LD    DE,TABLE-CODE    ; Length of this code; table is at end
  159.     ADD    HL,DE        ; Offset to beg of conversion table
  160.     ADD    A,L        ; Add in character offset
  161.     LD    L,A        ;
  162.     JR    NC,NCRY        ;
  163.     INC    H        ; Possible carry
  164. NCRY:    LD    E,(HL)        ; Get converted character
  165.                 ;
  166.      IF    RUBOUT        ;
  167.     LD    A,E        ; (could eliminate doing this at run time)
  168.     CP    "#"        ; Convert '#''s in table to 7FH if indicated
  169.     JR    NZ,JPBDOS    ;
  170.     LD    E,7FH        ;
  171.      ENDIF            ;
  172.                 ;
  173.     JR    JPBDOS        ; Note C reg still contains appropriate BDOS #
  174.                 ; - end of console output redirection -
  175. ;...............................;
  176.  
  177. ;................................
  178.                 ;
  179. CONOUT:    LD    A,C        ; <== Intercept all BIOS console output here
  180.     SUB    80H        ; Check hi bit / shift number down
  181.     JR    C,JPBIOS    ; If 0-7F, don't remap (char still ok in E)
  182.                 ;
  183.     LD    HL,(6)        ; Beg of this code
  184.     LD    DE,TABLE-CODE    ; Length of this code; table is at end
  185.     ADD    HL,DE        ; Offset to beg of conversion table
  186.     ADD    A,L        ; Add in character offset
  187.     LD    L,A        ;
  188.     JR    NC,NCR2        ;
  189.     INC    H        ; Possible carry
  190. NCR2:    LD    C,(HL)        ; Get converted character
  191.                 ;
  192.      IF    RUBOUT        ;
  193.     LD    A,C        ; (could eliminate doing this at run time)
  194.     CP    "#"        ; Convert '#''s in table to 7FH if indicated
  195.     JR    NZ,JPBIOS    ;
  196.     LD    C,7FH        ;
  197.      ENDIF            ;
  198.                 ;
  199.     JR    JPBIOS        ;
  200. ;...............................;
  201.  
  202. JWBOOT:    JR    WBOOT        ; 'stepping stone'
  203.  
  204. ;................................
  205.                 ;
  206. LOAD:    INC    HL        ; 'Pwr-on' entry. Load the target program.
  207.     INC    HL        ; Tricky- we know HL (we got here via JP (HL)
  208.     EX    DE,HL        ; So now DE points to the FCB at CODE+17
  209.  
  210.     LD    C,SGUSER    ; Get current user, to restore with later
  211.     PUSH    DE        ;
  212.     LD    E,0FFH        ;
  213.     CALL    BDOS        ;
  214.     POP    DE        ;
  215.  
  216.     PUSH    AF        ; Will pop this back after loading program
  217.  
  218.     LD    C,OPEN        ; Attempt to open the file
  219.     PUSH    DE        ;
  220.     CALL    BDOS        ;
  221.     POP    DE        ;
  222.     OR    A        ;
  223.     JR    Z,OPOK        ; If file opened OK...
  224.  
  225.     LD    A,ALTDRV-'@'    ; Try alternate DU
  226.     LD    (DE),A        ;
  227.     LD    C,SGUSER    ;
  228.     PUSH    DE        ;
  229.     LD    E,ALTUSR    ;
  230.     CALL    BDOS        ;
  231.     POP    DE        ;
  232.  
  233.     LD    C,OPEN        ; Attempt to open the file
  234.     PUSH    DE        ;
  235.     CALL    BDOS        ;
  236.     POP    DE        ;
  237.     OR    A        ;
  238.     JR    NZ,FIXUSR    ; Graceful exit if fails (message here?)
  239.  
  240. OPOK:    LD    HL,100H        ; Else init DMA setting to load target program
  241.                 ;
  242. RDLP:    EX    DE,HL        ; Now DE is DMA, HL is FCB
  243.                 ;
  244.     LD    C,SETDMA    ; Set DMA
  245.     PUSH    HL        ;
  246.     PUSH    DE        ;
  247.     CALL    BDOS        ;
  248.     POP    DE        ;
  249.     POP    HL        ;
  250.                 ;
  251.     EX    DE,HL        ; Now HL is DMA, DE is FCB
  252.                 ;
  253.     LD    C,READ        ; Xfer a sector
  254.     PUSH    HL        ;
  255.     PUSH    DE        ;
  256.     CALL    BDOS        ;
  257.     POP    DE        ;
  258.     POP    HL        ;
  259.                 ;
  260.     CP    1        ;
  261.     JR    Z,EOFILE    ; If done..
  262.     JR    NC,FIXUSR    ; If random read failure
  263.     LD    BC,80H        ; Else incr dest addr and loop
  264.     ADD    HL,BC        ;
  265.     JR    RDLP        ;
  266. ;...............................;
  267.  
  268. FIXUSR:    POP    AF
  269.     LD    E,A
  270.     LD    C,SGUSER
  271.     CALL    BDOS
  272.     JR    WBOOT
  273. ;..............................................................................
  274. ;
  275. ;
  276. EOFILE:    POP    AF        ; User#, pushed a long time ago!
  277.     LD    E,A        ;
  278.     LD    C,SGUSER    ;
  279.     CALL    BDOS        ;
  280.  
  281.     LD    DE,0080H    ; Set the default DMA back to 80H
  282.     LD    C,SETDMA    ;
  283.     CALL    BDOS        ;
  284.  
  285. ;................................
  286.                 ;
  287.     LD    HL,(6)        ; Restore the command tail information
  288.     DEC    H        ; - as originally supplied to this program
  289.     LD    DE,5CH        ;
  290.     LD    BC,100H-5CH    ;
  291.     LDIR            ;
  292. ;...............................;
  293.  
  294.     CALL    100H        ; 'Fork a child process..' :-)
  295.                 ; It will either WBOOT or return to here
  296.                 ; - same difference. Fall thru to below..
  297.  
  298. ;................................
  299.                 ;
  300. WBOOT:    LD    IX,(6)        ; Code to restore all vectors on exit
  301.     LD    IY,(1)        ;
  302.  
  303.     LD    L,(IX+7)    ;
  304.     LD    H,(IX+8)    ;
  305.     LD    (6),HL        ; Restore BDOS vector from CODE+7,8
  306.  
  307.     LD    L,(IX+10)    ;
  308.     LD    H,(IX+11)    ;
  309.     LD    (IY+1),L    ; Restore BIOS warm boot addr
  310.     LD    (IY+2),H    ;
  311.  
  312.     LD    L,(IX+13)    ;
  313.     LD    H,(IX+14)    ;
  314.     LD    (IY+10),L    ; Restore BIOS console output vector
  315.     LD    (IY+11),H    ;
  316.     JP    0        ; And do a warm boot (the CCP is *not* there)
  317. ;...............................;
  318.  
  319. ;------------------------------------------------------------------------------
  320. ;
  321. ; Traslate table. Values to which we map bytes 80 - FF.
  322. TABLE:
  323. ;         8-------------->9-------------->    ;
  324. ;         0123456789ABCDEF0123456789ABCDEF    ; ==> Byte...
  325.     DB    '                                '     ; <== maps to
  326.  
  327. ;         A-------------->B-------------->    ;
  328. ;         0123456789ABCDEF0123456789ABCDEF    ; ==> Byte...
  329.     DB    '         ++  |<>###|++++++|+++++'     ; <== maps to
  330.  
  331. ;         C-------------->D-------------->    ;
  332. ;         0123456789ABCDEF0123456789ABCDEF    ; ==> Byte...
  333.     DB    '++++-++++++++-+++++++++++++#*||*'     ; <== maps to
  334.  
  335. ;         E-------------->F-------------->    ;
  336. ;         0123456789ABCDEF0123456789ABCDEF    ; ==> Byte...
  337.     DB    '                =               '     ; <== maps to
  338.  
  339. ENDCOD    EQU    $        ; That's it!
  340.  
  341.     END
  342.