home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / asmutl / hd64180a.lbr / CSIO.AZM / CSIO.ASM
Assembly Source File  |  1991-08-04  |  4KB  |  171 lines

  1.     title    'CSI/O Test program'
  2. ;
  3.     maclib    hdz80
  4.     maclib    exec
  5.     maclib    iomap
  6. ;
  7. true    equ    0ffffh
  8. false    equ    not true
  9. cr    equ    0dh
  10. lf    equ    0ah
  11. ;
  12. ;
  13. hd64180    equ    true
  14. ;
  15.     mvi    c,csio$vec    ; CSIO interrupt vector setup command
  16.     lxi    d,csio$hdlr    ; -> CSIO interrupt handler
  17.     rst    1        ; Install using the EXEC processor/handler
  18. ;
  19.     mvi    c,inln$chn
  20.     rst    1
  21.     db    cr,lf,'---- CSI/O Test Program ----'
  22.     db    cr,lf,0
  23. ;
  24.     xra    a
  25.     sta    disable        ; 00 = enabled.
  26. ;
  27. ;
  28.     mvi    a,055h
  29.     sta    data
  30. ;
  31.     in    ip$rd        ; Read links
  32.     cma            ; Convert to positive logic
  33.     ani    0000$0111b    ; Use bottom 3 bits for Csio Speed
  34.     sta    speed        ; Save in the CSI/O baud rate divisor
  35. ;
  36. ; Send first byte out, interrupt enabled
  37.     lda    data
  38.     out    trdr        ; Send data
  39.     lda    speed
  40.     ori    0101$0000b    ; Transmit + end interrupt enable + speed
  41.     outo    cntr,a        ; Should be sending NOW.
  42. ;
  43. ;       ---- Loop back here to wait for the exit command ----
  44. ;
  45. ; Each time the transmitter empties, the hlander will send another byte
  46. ; according to the enable byte and the speed selected. 
  47. ;
  48. loop:
  49.     out    085h        ; Clear watchdog
  50.     out    085h
  51.     in    ip$rd        ; Read switch
  52.     cma            ; Turn around
  53.     ani    0010$0000b    ; Look for a plugged bit 5 to exit job
  54.     jnz    exit        ; Terminate on top bit
  55. ;
  56. ; Read links for the speed to be used
  57.     in    ip$rd
  58.     cma    
  59.     ani    0000$0111b    ; Csio Speed now
  60.     sta    speed
  61. ;
  62.     jmp    loop
  63. ;
  64.     page
  65. ;----------------------------------------------------------------
  66. ;         Handle CSIO interrupts
  67. ;
  68. ; This quite simple. The routine will keep sending the data byte 
  69. ; at the selected speed till the disable flag is set. The it will
  70. ; just disable interrupts on the CSIO.
  71. ;
  72. ; NOTE that at the maximum speed, the watchdog must be cleared by 
  73. ; this routine since they happen so blindingly fast.
  74. ;----------------------------------------------------------------
  75. ;
  76. csio$hdlr:
  77.     push    h
  78.     push    b
  79.     push    d
  80.     push    psw
  81. ;
  82.     lda    disable        ; 00 = send more data
  83.     ora    a
  84.     jnz    csio$skip
  85. ;
  86. ; ---- Send the byte in the data area out ----
  87. ;
  88.     lda    data
  89.     outo    trdr,a        ; Load data
  90. ;
  91. ; ---- Generate the baud rate divisor and enable tx and interrupts etc ----
  92. ;
  93.     lda    speed        ; CSI/O Clock
  94.     ori    0101$0000b    ; Enable interrupts + transmitter
  95.     outo    cntr,a        ; Send command to transmit data
  96.     jmp    csio$end
  97. ;
  98. csio$skip:
  99.     lda    speed
  100.     outo    cntr,a        ; Send divisor ONLY, disables interrupts etc.
  101. ;
  102. csio$end:
  103.     out    085h        ; clear watchdog
  104.     out    085h
  105.     pop    psw
  106.     pop    d
  107.     pop    b
  108.     pop    h
  109.     ei
  110.     ret            ; Internal interrupts only require RET
  111. ;
  112. ;----------------------------------------------------------------
  113. ; To exit this program safely, disable the CSIO sending with the
  114. ; "disable" flag then wait for the CSIO to be not busy sending.
  115. ; ONLY THEN can we disable the interrupt vector.
  116. ;----------------------------------------------------------------
  117. ;
  118. exit:
  119.     mvi    a,1
  120.     sta    disable
  121. ;
  122.     mvi    c,inln$chn
  123.     rst    1
  124.     db    cr,lf,'Turning Off CSI/O',0
  125. ;
  126. exit$wait:
  127.     out    085h
  128.     ino    a,cntr        ; Get CSIO status
  129.     ani    0001$0000b    ; Transmitting still ?
  130.     jrnz    exit$wait    ; Wait to stop
  131. ;
  132.     mvi    c,inln$chn
  133.     rst    1
  134.     db    cr,lf,'Job Ended',0
  135. ;
  136. ;
  137.     mvi    c,clr$vec    ; Disable all interrupt vectors
  138.     rst    1
  139. ;
  140.     jmp    03
  141. ;
  142. ;----------------------------------------------------------------
  143. ; Get the CSIO end flag status
  144. ;    00 = NOT idle
  145. ;    01 = Last function ended
  146. ;----------------------------------------------------------------
  147. ;
  148. csio$est:
  149.     ino    a,cntr        ; Read Csio status
  150.     ani    1000$0000b    
  151.     ret
  152. ;
  153. ; Send data out the CSIO for others to use.
  154. ;
  155. send$csio:
  156.     lda    data
  157.     outo    trdr,a        ; Load data
  158.     lda    speed
  159.     ori    0101$0000b    ; Or in send and Interrupt enable
  160.     outo    cntr,a        ; Sending NOW
  161.     ret
  162. ;
  163. data    ds    1
  164. speed:    ds    1
  165. disable ds    1
  166. ;
  167.     end
  168. ;
  169. ;
  170. ;
  171. ;