home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug120.arc / MTEK.LBR / MTKSYM.Z80 < prev    next >
Text File  |  1979-12-31  |  3KB  |  93 lines

  1. ;                            MITEKSYM
  2. ;                        By Ian Johnstone
  3. ;                         5th July, 1988
  4. ;        Loads ZBUG and reads in A.SYM, A.COM AND ControlR
  5.  
  6. BDOS    EQU 5
  7. BDVEC    EQU 0D906H    ;Target for BDOS jump, which
  8. BDJMP    EQU 0D911H    ;then jumps to here
  9. CR    EQU 0DH
  10. CTRLR    EQU 12H        ;^R re-draws the ZBUG screen
  11. DEBUF    EQU 7FFCH    ;Temporary buffer for DE
  12. PTR    EQU 7FFEH    ;Pointer to next char in text buffer
  13. READV    EQU 8100H    ;relocated location of READ routine
  14. TFCB    EQU 5CH
  15. TRAPV    EQU 8000H    ;Relocated location of TRAP routine
  16. ZBCALL    EQU 0C945H    ;BDOS jump vector of ZBUG calling subroutine
  17. ;
  18.     LD HL,TRAP    ;Relocate the subroutine TRAP.
  19.     LD DE,TRAPV
  20.     LD BC,100H
  21.     LDIR
  22.     LD HL,READ    ;Relocate the subroutine READ
  23.     LD DE,READV
  24.     LD BC,100H
  25.     LDIR
  26.     JP READV    ;Execute the program
  27. ;
  28. TRAP:    ;Is the target of the redirected ZBUG call for keyboard
  29.     ;input. Returns a char from the text buffer in A
  30.     LD A,C        ;Get the BDOS service number
  31.     CP 6        ;Is if for direct keyboard access?
  32.     JP NZ,BDVEC
  33.     LD A,E
  34.     CP 0FFH        ;from the keyboard?
  35.     JP NZ,BDVEC    ;exit if not
  36.     LD HL,(PTR)
  37.     LD A,(HL)    ;Else get a char from buffer
  38.     INC HL        ;Advance pointer
  39.     LD (PTR),HL    ;And save it
  40.     OR A        ;Z means end of text
  41.     RET NZ
  42.     LD A,CR        ;If so return CR in A
  43.     LD HL,5
  44.     LD (ZBCALL),HL    ;and restore BDOS call vector in ZBUG
  45.             ;subroutine
  46.     RET
  47. TEXT:    DB  'RA.SYM',CR,CR,CTRLR,'RA.COM',CR,CTRLR,0
  48.        ;I don't know why but the `CR,CTRLR' are necessary
  49.        ;in both places
  50. ;
  51. TEMP:    ;Receives the early calls redirected from the BDOS entry
  52.     ;point until a call is received from the ZBUG calling
  53.     ;subroutine, when it switches the redirection point and
  54.     ;passes control to TRAP
  55.     LD (DEBUF),DE    ;Save it
  56.     POP DE        ;Get return address
  57.     PUSH DE
  58.     LD HL,ZBCALL+2    ;And ZBUG subroutine return addr
  59.     OR A
  60.     SBC HL,DE    ;Compare them
  61.     LD DE,(DEBUF)    ;restore DE
  62.     JP NZ,BDJMP    ;Exit if not equal
  63.     LD HL,TRAPV    ;Else point ZBUG subroutine jump vector
  64.     LD (ZBCALL),HL    ;at TRAP
  65.     LD HL,BDJMP    ;and restore old one
  66.     LD (BDVEC+1),HL
  67.     JP TRAPV    ;and pass control to TRAP
  68. ;
  69. READ:    ;Opens and reads ZBUG.COM. Redirects all BDOS calls from
  70.     ;BDOS entry point to TEMP. Passes control to ZBUG
  71.     LD HL,7F00H-TRAP+TEXT ;Calculate pointer to text
  72.     LD (PTR),HL    ;Save it
  73.     LD DE,TFCB    ;ZBUG.COM is in TFCB
  74.     LD C,15
  75.     CALL BDOS    ;Open it
  76.     LD DE,100H
  77.     PUSH DE
  78. LOOP:    POP DE        ;Pointer to next Input buffer
  79.     LD HL,80H
  80.     ADD HL,DE    ;Advance it by one record
  81.     PUSH HL        ;Store it (DE still holds old pointer)
  82.     LD C,26
  83.     CALL BDOS    ;So set it as the current buffer
  84.     LD DE,5CH
  85.     LD C,20
  86.     CALL BDOS    ;Read one record into buffer
  87.     OR A        ;NZ means EOF
  88.     JR Z,LOOP    ;Loop for another record
  89.     POP HL        ;Else clear stack
  90.     LD HL,7F00H-TRAP+TEMP
  91.     LD (BDVEC+1),HL    ;Redirect BDOS calls to TEMP
  92.     JP 100        ;Execute ZBUG
  93.