home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / apple / pcpibdos.mzc / PCPIBDOS.MAC
Encoding:
Text File  |  1987-02-07  |  3.5 KB  |  157 lines

  1. ;BDOSPAT.MAC
  2. ;
  3. ;    by Steven Hirsch  9/85
  4. ;
  5. ;    From an idea by Al Hawley, modified for the Appli-Card
  6. ;
  7. ;
  8.     .Z80
  9.     ASEG
  10.  
  11. false    equ    0
  12. true     equ    not false
  13.  
  14. bdosmod    equ    true        ;Set false for std. CP/M BDOS
  15.  
  16.     if    bdosmod
  17. func13    equ    0C13h        ;If you are running a non-standard bdos
  18. drec    equ    0D73h        ;fill in these equates.
  19.  
  20.     else
  21. func13    equ    0C83h        ;For Vanilla BDOS
  22. drec    equ    0DECh
  23.     endif
  24.  
  25. Offset1    equ    func13 + 6    ;Offset to third instruction of func13
  26.                 ;which normally zeroes the dlog vector:
  27.                 ;          ld     (dlog),hl
  28. Offset2    equ    drec + 2    ;Offset to patch space at BDOS end
  29.  
  30. ;The 'lowmsk' byte should have a bit set for any drive using non-removable
  31. ;media, ie. :
  32. ;
  33. ;    bit 0 - Drive A
  34. ;    bit 1 - Drive B
  35. ;      ..........
  36. ;    bit 7 - Drive H
  37. ;
  38. ;Likewise for the 'himsk' byte, starting with drive "I" and ending with "P"
  39. ;
  40. Lowmsk    equ    10001111b    ;Don't re-log a,b,c,d, or h
  41. Himsk    equ    00000000b
  42.  
  43. wboot    equ    1        ;warm-boot vector
  44. bdos    equ    5        ;bdos call vector
  45. bdoslen    equ    0E00h        ;length of bdos
  46. pstring    equ    9        ;bdos print-string code
  47. dummy    equ    0
  48.  
  49. ;This is all Applicard stuff!
  50. wr65byt    equ    0FFE3h        ;write byte to 6502
  51. wr65wrd    equ    0FFE9h        ;write word to 6502
  52. wr65buf    equ    0FFEFh        ;write 'hl' for length 'de' to 6502
  53. wrdat    equ    2        ;code for 6502 receive data function
  54.  
  55. bdos65    equ    9900h        ;address of bdos in 6502 mem
  56. pat65    equ    bdos65+offset1    ;patch location in 6502
  57. bios65    equ    bdos65 + bdoslen    ;bios in 6502
  58.  
  59.     org    100h
  60.  
  61. ;Start of program
  62.     ld    hl,0        ;zero pointer
  63.     ld    a,(wboot+1)    ;get page address of BIOS in A
  64.     sub    0Eh        ;subtract BDOS len in pages 
  65.     ld    h,a        ;hl has BDOS base address
  66.     ld    (bdbase),hl    ;store this for later
  67.     ld    de,offset1    ;add offset into bdos
  68.     add    hl,de
  69.     push    hl        ;save address for later...
  70.  
  71.     inc    hl        ;this will be the address of 'dlog'
  72.     ld    de,code+1    ;Set pointer to patch point in our code
  73.     ld    a,(hl)        ;and patch in the address.
  74.     ld    (de),a
  75.     inc    hl        ;now the hi-order byte:
  76.     inc    de
  77.     ld    a,(hl)
  78.     ld    (de),a
  79.  
  80. ;Insert a call to the patch at func13+6
  81.     pop    hl        ;retrieve the address
  82.     ld    a,(hl)        ;Test instruction code 
  83.     cp    0CDh        ;is it a CALL already?
  84.     jr    z,error        ;bail out
  85.  
  86.     ld    (hl),0CDh    ;we're ok, patch in a "call" instruction
  87.     push    hl
  88.     ld    hl,(bdbase)    ;recover bdos base address
  89.     ld    de,offset2    ;and add offset to patch area
  90.     add    hl,de
  91.     ex    de,hl        ;put the patch area address in de
  92.  
  93.     pop    hl        ;And write it in after the CALL
  94.     inc    hl        
  95.     ld    (hl),e
  96.     inc    hl
  97.     ld    (hl),d
  98.  
  99. ;Now that we have the address in 'de', move our routine there
  100.     ld    hl,code
  101.     ld    bc,codlen
  102.     ldir
  103.  
  104. ;Patch bdos image in 6502 memory also, so a warm-boot won't over-write us.
  105.     ld    c,wrdat
  106.     call    wr65byt        ;send function code
  107.  
  108.     ld    de,pat65
  109.     call    wr65wrd        ;send target address
  110.  
  111.     ld    de,bios65-pat65    
  112.     call    wr65wrd        ;send length of transfer data
  113.  
  114.     ld    hl,(bdbase)    ;get bdos start address
  115.     ld    bc,offset1    
  116.     add    hl,bc        ;add offset to patch
  117.     call    wr65buf        ;transfer end of bdos
  118.  
  119.     ret            ;back to CP/M
  120.  
  121. ;We are already patched, notify the operator
  122. error:    ld    de,message    ;print message and exit
  123.     ld    c,pstring
  124.     call    bdos
  125.     ret
  126.  
  127. bdbase:    defw    0        ;temp storage for bdos base address
  128.  
  129. message:
  130.     db    0Dh,0Ah,'BDOS is already patched....',0Dh,0Ah,'$'
  131.  
  132. ;This routine will leave any previously logged drives alone
  133. code:    ld    hl,dummy    ;patched by program
  134.     ld    a,(hl)        ;get lo-byte of dlog
  135.     and    lowmsk        ;mask protected drives
  136.     ld    (hl),a
  137.     inc    hl
  138.     ld    a,(hl)        ;hi-byte
  139.     and    himsk
  140.     ld    (hl),a
  141.     ret
  142.  
  143. codlen    equ    $ - code
  144.  
  145.     end
  146.     
  147.     
  148.     
  149.     cted drives
  150.     ld    (hl),a
  151.     inc    hl
  152.     ld    a,(hl)        ;hi-byte
  153.     and    himsk
  154.     ld    (hl),a
  155.     ret
  156.  
  157. codlen    equ