home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / sysutl / ykey21.lbr / YK-EXAMP.LBR / Y21MBAS.ZZZ / Y21MBAS.AZM
Text File  |  1987-12-11  |  10KB  |  322 lines

  1.  
  2. ;   Overlay to MBASIC      R.Gaspari     12-04-87
  3. ;   Assemble with Z80MR.   Overlay onto MBASIC with DDT.
  4.                 
  5. PROGEND    EQU      6000h           ; original end of the program being modified
  6. KBA    EQU    0D700H        ; base addr below which code is loaded (ccp)
  7. KKS    EQU    200H        ; how far below kba code will go
  8. NO    EQU    0
  9. YES    EQU    .NOT.NO
  10.  
  11. NSADV    EQU    YES        ; using Northstar Advantage?      @N
  12.                 ;   (for on-screen BOLD and UNDERLINE)
  13. SMTCLK    EQU    YES        ; using SMT no-slot clock?        @S
  14.                 ;   (for pop-up clock display)
  15. Z80DOS    EQU    YES        ; using Z80DOS?                   @Z
  16.                 ;   (to trap make-file bdos calls)
  17.  
  18.     ORG     0100h           ; overlay the program being modified
  19.     JP    LOADCD        ;   (MBASIC had a JMP 5D8C here)
  20.                 
  21.     ORG    PROGEND        ; point to end of normal MBASIC
  22. LOADCD: 
  23.     LD    HL,0        ; * prevent soft return to CCP
  24.     EX      (SP),HL     ; * any soft retn becomes JP 0
  25.     CALL    SETUP        ; load CCP and BIOS overlays
  26.     JP    5D8CH        ; continue with original program
  27.     
  28.  
  29. ; ************************************
  30. ;    PART I  -  SETUP JUMP VECTORS
  31. ; ************************************
  32.  
  33. M6    EQU    -6        ; a constant
  34.                 
  35. SETUP:
  36.     if    nsadv.and.smtclk ; @N3 @S1
  37. USORG    EQU    0F400h        ; start of USER.ASM (F400 for floppy)
  38.     LD    DE,USORG         ; spot in BIOS to put clock code  
  39.     LD    HL,UCODE       ; point to data we'll put there
  40.     LD    BC,USIZE     ; size of code block to be moved
  41.     LDIR                  
  42.     endif            ; @N3 @S1
  43.                 
  44.  
  45.     LD    HL,(6)        ; get bdos vector DF06
  46.     LD    (KREM6),HL    ; store it for future use 
  47.     LD    DE,M6        ; get -6
  48.     ADD    HL,DE        ; HL now has DF00 (source)
  49.     LD    DE,KBA-KKS    ; DE now has D300 (destination)
  50.     LD    BC,9        ; move 9 bytes 
  51.     LDIR            
  52.                 
  53.     LD    HL,(1)        ; get warm boot vector ED03 (source)
  54.     LD    DE,KBA-KKS+9    ; DE now has D309 (destination)
  55.     LD    BC,12        ; move 12 bytes
  56.     LDIR            
  57.                 
  58.     LD    DE,KBA-KKS+21    ; DE has D315 (destination)
  59.     LD    HL,KKODE+21    ; HL points to code below
  60.     LD    BC,KSIZE    ; move bytes
  61.     LDIR            
  62.                 
  63.     LD    HL,KBDOS    ; get new bdos vector
  64.     LD    (6),HL        ; put it in place
  65.     LD    HL,(1)        ; point to actual table (dest)
  66.     LD    DE,KBOOT    ; point to replace table (source)
  67.     EX    DE,HL        ;
  68.     LD    BC,12        ; move 12 bytes 
  69.      LDIR            
  70.                 
  71.     if    z80dos      ; @Z1
  72.     LD    HL,(KBA-KKS+7)
  73.     LD    (Z8ENTRY+1),HL
  74.     LD    HL,Z8NEW
  75.     LD    (KBA-KKS+7),HL
  76.     endif            ; @Z1   
  77.  
  78.     RET            ; done with SETUP
  79.                 
  80.  
  81.          
  82. ; ********************************************************
  83. ;    PART II  -  NEW VECTOR CODE  (move to high memory)
  84. ; ********************************************************
  85.  
  86. KKODE:                
  87. OK    EQU    (KBA-KKS)-KKODE        ; offset 
  88.                 
  89. KSER    EQU    $+OK        
  90.     DS    6        ; space for serial number
  91. KBDOS    EQU    $+OK        
  92.     DS    3        ; space for bdos jump
  93. BBOOT    EQU    $+OK        
  94.     DS    3        ; orig warm boot jmp vector
  95. BSTAT    EQU    $+OK        
  96.     DS    3        ; orig console status
  97. BCONIN    EQU    $+OK        
  98.     DS    3        ; orig console input
  99. BCONOUT EQU    $+OK        
  100.     DS    3        ; orig console output
  101.                 
  102. KBOOT    EQU    $+OK        
  103.     JP    KBT        ; new warm boot vector
  104. KCSTAT    EQU    $+OK        
  105.     JP    KST        ; new console status
  106. KCONIN    EQU    $+OK        
  107.     JP    KIN        ; new console input
  108. KCONOUT    EQU    $+OK        
  109.     JP    BCONOUT        ; new console output
  110.                 
  111.  
  112. ; *****************************************
  113. ;    REPLACEMENT WARM BOOT ROUTINE
  114. KBT    EQU    $+OK        ; remove key code each wm boot
  115.     CALL    KREM        ; put the 4 bios vectors back
  116.     JP    0        ; exit to cpm
  117. KREM    EQU    $+OK
  118.     LD    HL,(KREM6)    ; get orig bdos jmp vector
  119.     LD    (6),HL        ; put it back
  120.     LD    DE,(1)        ; point to ED03
  121.     LD    HL,BBOOT    ; get orig actual data
  122.     LD    BC,12        ; move 12 bytes
  123.     LDIR
  124.     XOR    A
  125.     RET
  126.  
  127.  
  128. ; **************************************
  129. ;    REPLACEMENT CONSOLE STATUS
  130. KST    EQU    $+OK        
  131.     LD    A,(KEYINF)    
  132.     OR    A        
  133.     JP     Z,BSTAT        ; 
  134.     LD    A,0FFH        
  135.     RET            
  136.                 
  137.  
  138. ; ***************************************
  139. ;    REPLACEMENT CONSOLE INPUT
  140. KIN    EQU    $+OK        
  141.     LD    HL,KEYINF    ; get the counter of keys waiting
  142.     LD    A,(HL)        
  143.     OR    A        
  144.     JR    NZ,KEYWAT    ; go process the keys waiting
  145.     CALL    BCONIN         ; get the byte using actual bios
  146.     CP    7FH        ; see if it's a "delete"
  147.     RET    C        ; if less than 7F, return with it
  148.     JR    NZ,KEYFNI    ; if greater than 7F, prep for funct key
  149.     LD    A,(KEYDEL)    ; if equal to 7F, replace with a  ^H
  150.     RET            ; 
  151. KEYFNI: CP    9EH        ; see if it's CMND-F4
  152.     JR    NZ,KEYNR    ;    (2nd F4 removes fnct key code)
  153.     LD    HL,KREMC    ; look at the removal counter
  154.     INC    (HL)        
  155.     LD    A,(HL)        
  156.     AND    2        
  157.     JP      NZ,KREM      ; if Z, go remove key code
  158.  
  159. KEYNR:    LD    B,A        ; store the function key
  160.     LD    A,(KEYLEN)    ; get length of replacement byte string
  161.     OR    A        ; see if zero
  162.     LD    A,B        ; get the function key back
  163.     RET    Z        ; if len=0, don't process function keys
  164. KEYFN   EQU     $+OK
  165.     CP    0DBH        ; now see if its F1 - F15 or if a cursor
  166.     JR    NC,KEY2        ; if no carry, its greater (F1 - F15)
  167.     SBC    A,7FH        ; subtract to point to offset in table
  168.     LD    HL,(KEYNMP)     ; get address of the cursor replacements
  169.     JR    KEYX        ; go to the exchange routine
  170. KEY2:   SBC    A,0DBH        ; subtract to get the offset for our table
  171.     LD    HL,(KEYFNP)    ; get address of the fn key replacements
  172. KEYX:    LD    C,A        ; store offset temporarily in C
  173.     LD    A,(KEYLEN)    ; get the length of each replacement str
  174.     DEC    A        ; 
  175.     LD    (KEYINF),A    ; store the number of remaining bytes 
  176.     LD    D,A        ; the number of times to add A to itself 
  177.     LD    A,C        ; get the offset back from C
  178. KEYX2:    ADD    A,c        ; by adding N times, adjust offset for 
  179.     DEC    D        ;      the number of bytes in KEYLEN
  180.     JR    NZ,KEYX2    ; repeat till D=0
  181.     LD    E,A        ; put the offset in DE, prep for DAD D
  182.     LD    D,0        ; ditto
  183.     ADD    HL,DE        ; HL now points to the replacement bytes
  184.     LD    D,(HL)        ; get first replacement byte
  185.     INC    HL        ; point to next byte
  186.     LD    (KEYPTR),HL    ; store pointer to the next byte
  187.         LD      A,(HL)          ;  get next byte
  188.         OR      A                 
  189.         JR      NZ,KNXTZ        ; if next byte NZ skip, otherwise...
  190.         LD      (KEYINF),A      ;    notify keyinf that there's no more
  191. KNXTZ:    LD      A,D             ; get the replacement key back
  192.         OR      A               ; check that it's not a null
  193.         RET     NZ              ; if no null, return with it
  194.         LD      (KEYINF),A      ; otherwise notify keyinf that no more
  195.     RET            ; return with function key replacement
  196.  
  197. KEYWAT: DEC    A        ; decrement count of keys waiting
  198.     LD    (HL),A        ; store for future use
  199.     LD    HL,(KEYPTR)    ; get address of next byte waiting
  200.     LD    A,(HL)        ; get the byte there
  201.     INC    HL        ; update the pointer to the next byte
  202.     LD    (KEYPTR),HL    ; and store it
  203.     RET            ; return with the byte that was waiting
  204.  
  205. KREMC    EQU    $+OK
  206.     DW    0        ; temp storage for CMND-F4 counter
  207. KEYPTR  EQU     $+OK
  208.         DEFW    0        ; temp pointer to next replacement byte
  209. KEYINF  EQU     $+OK    
  210.         DEFB    0        ; temp storage for number of keys waiting
  211. KREM6    EQU    $+OK
  212.     DW    0        ; temp storage for orig bdos (DF06)
  213.  
  214.  
  215. KEYDEL   EQU    $+OK        ; permanent storage for delete key
  216.          DEFB   08H             ;    replacement (set delete = ^H)
  217. KEYLEN   EQU    $+OK        ; permanent storage for length of
  218.          DEFB    7        ;    each replacement string
  219. KEYFNP     EQU    $+OK
  220.      dw    KFNTBL           ; pointer to KFNTBL 
  221. KEYNMP   EQU    $+OK
  222.      dw    KNMTBL         ; pointer to KNMTBL
  223.  
  224.  
  225.  
  226. ; *****************************************************
  227. ;    PART IIb  -  FUNCTION KEY REPLACEMENT DATA
  228. ; *****************************************************
  229.  
  230. KNMTBL    EQU    $+OK
  231.     db        0,0,0,0,0,0,0       ; 80h cmnd -
  232.     db        0,0,0,0,0,0,0       ; 81h cmnd .
  233.     db        0,0,0,0,0,0,0       ; 82h up arrow
  234.     db        0,0,0,0,0,0,0       ; 83h  3 arrow
  235.     db        0,0,0,0,0,0,0       ; 84h  1 arrow
  236.     db        'EDIT ',0,0         ; 85h  5 arrow (center)
  237.     db        ' ',0,0,0,0,0,0     ; 86h rt arrow
  238.     db        0,0,0,0,0,0,0       ; 87h  7 arrow
  239.     db        8,0,0,0,0           ; 88h lf arrow
  240.  
  241.  
  242. KFNTBL    EQU    $+OK
  243.     db        'SAVE  "'            ; dbh  F1 key
  244.     db        0,0,0,0,0,0,0        ; dch  F2
  245.     db        'PRINT  '            ; ddh  F3
  246.     db        'LPRINT '            ; deh  F4
  247.     db        18H,0,0,0,0,0,0      ; dfh  F5
  248.     db        0,0,0,0,0,0,0        ; e0h  F6
  249.     db        0,0,0,0,0,0,0        ; e1h  F7
  250.     db        0,0,0,0,0,0,0        ; e2h  F8
  251.     db        'RUN ',0,0,0         ; e3h  F9
  252.     db        'SYSTEM',0DH         ; e4h  F10
  253.     db        0,0,0,0,0,0,0        ; e5h  F11
  254.     db        'LIST ',0,0          ; e6h  F12
  255.     db        'LLIST ',0           ; e7h  F13
  256.     db        'LOAD  "'            ; e8h  F14
  257.     db        08H,0,0,0,0,0,0      ; e9h  F15
  258.  
  259.  
  260. ; *********************************
  261. ;     PART IIc  -  Z80DOS TRAP
  262. ; *********************************
  263.  
  264.     if    z80dos      ; @Z2
  265. Z8NEW    EQU    $+OK
  266.     LD    A,C        ; move bdos funct number into A 
  267.     CP    0FH        ; see if it's the first open-file call
  268.     JR      Z,Z8GET        ; if yes, GET the time stamp
  269.     CP    16H        ; see if this is make-file call
  270.     JR      Z,Z8USE        ; if yes, USE the time stamp
  271.     JR    Z8ENTX        ; all else, go do real bdos jump
  272. Z8GET:
  273.     PUSH    DE        ; preserve the fcb for bdos 54
  274.     PUSH    DE
  275.     CALL    Z8ENTRY        ; go to bdos & return
  276.     POP    DE        ; get the fcb back again
  277.     PUSH    AF        ; preserve open-file bdos status
  278.     INC    A        ; see if it's 0ffh (no file found)
  279.     LD    (Z8NFF),A    ; store results for use later
  280.     JR    Z,Z8SKP        ; if no file found, skip get stamp
  281.     LD    C,54        ; 54 = get stamp
  282.     CALL    5        ; 
  283. Z8SKP:    POP    AF        ; get orig open-file status back
  284.     POP    DE        ; and orig fcb 
  285.     RET            
  286. Z8USE:
  287.     LD    A,(Z8NFF)    ; see if open-file was successful
  288.     OR    A        ; a=0 if unsuccessful
  289.     JR    Z,Z8ENTX    ; if zero, skip use-stamp
  290.     PUSH    BC        ; save bdos funct number (c=16h)
  291.     PUSH    DE        ; save fcb
  292.     LD    C,55        ; 55 = use stamp
  293.     CALL    5    
  294.     POP    DE
  295.     POP    BC    
  296. Z8ENTRY    EQU    $+OK
  297. Z8ENTX:    JP    0        ; do the JP into real bdos
  298. Z8NFF    EQU    $+OK        
  299.     DB    0        ; flag for no-file-found
  300.     endif            ; @Z2 
  301.  
  302.  
  303. KREF1    EQU    $          ; location of end of code
  304. KREF2    EQU    $+OK          ; location of end (after it's moved)
  305. KSIZE    EQU    $-KKODE           ; the size code to be moved
  306.  
  307.     IF    (KSIZE).GT.(KKS)
  308.     *  ERROR  -  allow more size for KKS
  309.     ENDIF
  310.  
  311. ; ***************************************************
  312. ;    PART III  -  BIOS CODE (moved to high memory)
  313. ; ***************************************************
  314.  
  315.     if    nsadv.and.smtclk    ; @N4 @S2
  316. *include    user201.azm        ; see NOSLTDOS.LBR for more info
  317.     endif                ; @N4 @S2
  318.  
  319.     end
  320.  
  321.  
  322.