home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / asmutl / hd64180a.lbr / RAMIO.AZM / RAMIO.ASM
Encoding:
Assembly Source File  |  1991-08-04  |  6.0 KB  |  247 lines

  1.     title    'IORAM Drivers'
  2. ;----------------------------------------------------------------
  3. ; This module reads and writes to the mass memory board connected
  4. ; to a General Purpose port on CORE BOARD as sectors of 128 bytes.
  5. ;
  6. ; On entry,
  7. ;
  8. ; CUR$DMA = address to transfer to or from
  9. ; CUR$SEC = sector number to do I/O upon
  10. ;
  11. ;    Written     by Richard Holmes    24-05-86
  12. ;       Last update by Richard Holmes    23-11-86
  13. ;----------------------------------------------------------------
  14. ;
  15.     maclib    z80
  16.     maclib    core            ; Load true/false equates
  17. ;
  18. ;
  19.     public    in$ioram,rd$ioram,wr$ioram    ; Entry points
  20.     extrn    cur$dma,cur$sec            ; External variables
  21.  
  22. ;
  23. ;
  24. me$msk    equ    1000$0000b        ; Master enable, 1 = board alive
  25. wr$msk    equ    0100$0000b        ;                           1 = read
  26. hadlch    equ    0010$0000b        ; High address latch bit
  27. cslch    equ    0001$0000b        ; Chip select latch bit
  28. bs3    equ    0000$1000b        ; Board select bit 3
  29. ;
  30. gp$base    equ    04ch            ; GP I/O port address base
  31. ;
  32. dat$prt    equ    gp$base            ; Data port address
  33. adr$prt    equ    gp$base + 1        ; Low and latched address port
  34. cnt$prt    equ    gp$base + 2        ; Control port for the I/O Ram card
  35. mod$prt    equ    gp$base + 3        ; Mode port for the 8255
  36. ;
  37. rd$mod    equ    090h            ; 8255 mode to read the i/o ram board
  38. wr$mod    equ    080h            ; 8255 mode to write to i/o ram board
  39. ;
  40. ;--------------------------------
  41. ;   Initialize the IORAM board
  42. ;--------------------------------
  43. ;
  44. in$ioram:
  45.     mvi    a,rd$mod
  46.     out    mod$prt            ; Select read mode
  47. ; Clear the control port
  48.     xra    a
  49.     out    cnt$prt            ; Send to the i/o ram control port
  50.     ret
  51. ;
  52. ;----------------------------------------------------------------
  53. ;             Read One Sector from the IO RAM board
  54. ;
  55. ; On entry,
  56. ;
  57. ; CUR$SEC = sector number to be read.
  58. ; CUR$DMA = system memory address to read into
  59. ;
  60. ; On exit
  61. ;   All registers except A preserved
  62. ;   Memory at DMA loaded from the IO memory board
  63. ;
  64. ;----------------------------------------------------------------
  65. ;
  66. rd$ioram:
  67.     push    h
  68.     push    b
  69.     push    d
  70. ; Select read mode.
  71.     mvi    a,rd$mod
  72.     out    mod$prt        ; Read mode. A=in, B=C=outs
  73. ;
  74. ; Calculate and latch the chip select bits.
  75. ; For RAMS: chip to use is sector / 64
  76. ;     ROMS: chip to use is sector / 256
  77. ;
  78.     lhld    cur$sec
  79.     mov    a,l
  80.     ral            ; gets top bit
  81.     mov    e,a        ; Save to a temp
  82.     mov    a,h
  83.     ral
  84.     mov    d,a        
  85. ;
  86.     mov    a,e
  87.     ral            ; gets top bit
  88.     mov    a,d
  89.     ral
  90.     ani    0001$1111b    ; Mask off control bits
  91.     out    adr$prt        ; Send to address port
  92. ; Now latch in by raising high address momentarily
  93.     mvi    a,me$msk or cslch or bs3    ; Select the board 
  94.     out    cnt$prt            ; Latches
  95.     mvi    a,me$msk or bs3        ; Low again to finish latching
  96.     out    cnt$prt            ; done
  97. ;
  98. ; Calculate the real address.
  99. ; Address = sector number * 128 = HL shl 7 bits
  100. ;
  101.     mov    a,h
  102.     rar
  103.     mov    a,l
  104.     rar
  105.     mov    d,a
  106.     mov    a,l
  107.     rar
  108.     mvi    a,0
  109.     rar            ; Loads carry/top bit
  110.     mov    e,a        ; DE = read address
  111. ; NOW, latch the high address
  112.     mov    a,d            ; High address
  113.     ani    0001$1111b        ; Allow only 0..1FFFh address space
  114. ;
  115.     out    adr$prt            ; Load the address onto the port
  116.     mvi    a,me$msk or hadlch or bs3    ; master enable and high addr
  117.     out    cnt$prt            ; Latches
  118.     mvi    a,me$msk or bs3        ; Low again to finish latching
  119.     out    cnt$prt            ; done
  120. ;
  121. ; OK, ready for data I/O
  122. ; Get ready for the data read.
  123. ;
  124.     lhld    cur$dma        ; Data transfer address
  125.     mvi    b,128        ; Bits to transfer
  126.     mvi    c,dat$prt    ; C = data port to read data from
  127. rd$loop:
  128.     mov    a,e        ; Get address
  129.     out    adr$prt        ; Send to low address port
  130.     inr    e        ; -> next address and allow to settle
  131.     ini            ; Read port(C) into m(HL)
  132.     jnz    rd$loop        ; Read next byte from port
  133. ; Disable board
  134.     xra    a
  135.     out    cnt$prt        ; Deselects all boards in the system
  136. ;
  137. ; Restore registers and exit
  138. ;
  139.     pop    d
  140.     pop    b
  141.     pop    h
  142.     ret
  143. ;
  144. ;
  145. ;----------------------------------------------------------------
  146. ;             Write One Sector to the IO RAM board
  147. ;
  148. ; On entry,
  149. ;
  150. ; CUR$SEC = sector number to be write.
  151. ; CUR$DMA = system memory address to write from
  152. ;
  153. ; On exit
  154. ;   All registers except A preserved
  155. ;   Memory at DMA sent to the IO memory board
  156. ;
  157. ;----------------------------------------------------------------
  158. ;
  159. wr$ioram:
  160.     push    h
  161.     push    b
  162.     push    d
  163. ; Select read mode.
  164.     mvi    a,wr$mod
  165.     out    mod$prt        ; Read mode. A=in, B=C=outs
  166. ;
  167. ; Calculate and latch the chip select bits.
  168. ; For RAMS: chip to use is sector / 64
  169. ;     ROMS: chip to use is sector / 256
  170. ;
  171.     lhld    cur$sec
  172.     mov    a,l
  173.     ral            ; gets top bit
  174.     mov    e,a        ; Save to a temp
  175.     mov    a,h
  176.     ral
  177.     mov    d,a        
  178. ;
  179.     mov    a,e
  180.     ral            ; gets top bit
  181.     mov    a,d
  182.     ral
  183.     ani    0001$1111b    ; Mask off control bits
  184.     out    adr$prt        ; Send to address port
  185. ; Now latch in by raising high address momentarily
  186.     mvi    a,me$msk or cslch or bs3    ; master enable and chip sel
  187.     out    cnt$prt            ; Latches
  188.     mvi    a,me$msk or bs3        ; Low again to finish latching
  189.     out    cnt$prt            ; done
  190. ;
  191. ; Calculate the real address.
  192. ; Address = sector number * 128 = HL shl 7 bits
  193. ;
  194.     mov    a,h
  195.     rar
  196.     mov    a,l
  197.     rar
  198.     mov    d,a
  199.     mov    a,l
  200.     rar
  201.     mvi    a,0
  202.     rar            ; Loads carry/top bit
  203.     mov    e,a        ; DE = read address
  204. ; NOW, latch the high address
  205.     mov    a,d
  206.     ani    0001$1111b        ; Allows only 0.1fffh address space
  207. ;
  208.     out    adr$prt            ; Load the address onto the port
  209.     mvi    a,me$msk or hadlch or bs3    ; master enable and high addr
  210.     out    cnt$prt            ; Latches
  211.     mvi    a,me$msk or bs3        ; Low again to finish latching. 
  212.     out    cnt$prt            ; done
  213. ;
  214. ; OK, ready for data I/O
  215. ; Get ready for the data read.
  216. ;
  217.     lhld    cur$dma        ; Data transfer address
  218.     mvi    b,128        ; Bits to transfer
  219.     mvi    c,dat$prt    ; C = data port to read data from
  220. ; Setup the low address then enable writes
  221.     mov    a,e
  222.     out    adr$prt
  223.     mvi    a,me$msk or wr$msk or bs3    ; Allow writing
  224.     out    cnt$prt            ; done
  225.  
  226. wr$loop:
  227.     mov    a,e        ; Get address
  228.     out    adr$prt        ; Send to low address port
  229.     inr    e        ; -> next address and allow to settle
  230. ;
  231.     outi            ; Read port(C) into m(HL)
  232.     jnz    wr$loop        ; Read next byte from port
  233. ; Disable board
  234.     xra    a
  235.     out    cnt$prt        ; Deselects all boards in the system
  236. ;
  237. ; Restore registers and exit
  238. ;
  239.     pop    d
  240.     pop    b
  241.     pop    h
  242.     ret
  243. ;
  244. ; ====++++====
  245. ;
  246.     end
  247. ;