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

  1.     title    'I/O Drivers for Core Board'
  2. ;----------------------------------------------------------------
  3. ;            Core Board I/O Drivers 
  4. ;
  5. ;        Written     By Richard Holmes    12-05-86
  6. ;        Last Update By Richard Holmes    23-01-87
  7. ;
  8. ; Changed Dart setup for DTR set on                   08-06-86
  9. ; Modified clock routine to save year in 58167 ram    08-06-86
  10. ; Modified clock routine to use DE as buffer address  30-06-86
  11. ; Use WDT$FLG in the clrwdt routine                   23-11-86
  12. ; Added LED drivers                                   18-01-87
  13. ; Removed AUX drivers                                 19-01-87
  14. ;----------------------------------------------------------------
  15. ;
  16.     maclib    z80
  17.     maclib    core
  18. ;
  19.     public    cie,coe,cst
  20.     public    con$inp,con$out,con$ist
  21.     public    clkrd,clkwr,schrd
  22.     public    init,clrwdt
  23. ; Led Drivers
  24.     public    ini$led,tog$led        ; Initialize led drivers
  25.     public    clr$led,set$led        ; Led number on/off
  26.     public    ori$led,ani$led        ; OR and AND led bit mask
  27.     public    xri$led            ; XOR led image
  28. ; Bell driver
  29.     public    set$bel,clr$bel        ; Set/Clear bell
  30.     public    tog$bel            ; Toggle bell bit on/off
  31. ;
  32. ;================================================================
  33. ;        LED Drivers
  34. ;
  35. ;================================================================
  36. ; Initialize the LED drivers by clearing the data byte and hence 
  37. ; the led port
  38. ;----------------------------------------------------------------
  39. ;
  40. ini$led:
  41.     mvi    a,wr$en        ; Memory enable only
  42.     sta    led$byt        ; Save for masks later
  43.     out    @ledd        ; Send to driver
  44.     ret
  45. ;
  46. ;----------------------------------------------------------------
  47. ; Set the specified bit in A LED on. Leave others alone.
  48. ;
  49. ; On Entry
  50. ;    A = 1..6 for the led number
  51. ; On Exit
  52. ;     Led number turned on. Others preserved.
  53. ;----------------------------------------------------------------
  54. ;
  55. set$led:
  56.     ora    a
  57.     rz                ; Exit if = 0
  58.     cpi    7
  59.     rnc                ; NC and > 6 hence in error
  60.     push    b
  61.     call    led$msk
  62.     lda    led$byt            ; Load old data
  63.     ora    c            ; OR in the new bit mask
  64. led$com:
  65.     sta    led$byt
  66.     out    @ledd            ; Write out again
  67.     pop    b
  68.     ret
  69. ;
  70. ;----------------------------------------------------------------
  71. ; Clear the specified bit in A. Leave others alone.
  72. ;
  73. ; On Entry
  74. ;    A = 1..6 for the led number
  75. ; On Exit
  76. ;     Led number cleared. Others preserved.
  77. ;----------------------------------------------------------------
  78. ;
  79. clr$led:
  80.     ora    a
  81.     rz                ; Exit if = 0
  82.     cpi    7
  83.     rnc                ; NC and > 6 hence in error
  84.     push    b
  85.     call    led$msk
  86.     cma    
  87.     mov    c,a            ; Invert and save led mask
  88.     lda    led$byt            ; Load old data
  89.     ana    c            ; And OFF the selected bit
  90.     ori    wr$en            ; Mask in the memory enable bit
  91.     jr    led$com
  92. ;
  93. ;----------------------------------------------------------------
  94. ; Or the specified bit mask in A into the LED Outputs.
  95. ;
  96. ; On Entry
  97. ;    A = led mask
  98. ;
  99. ; On Exit
  100. ;     Set bit leds turned on. Others preserved.
  101. ;----------------------------------------------------------------
  102. ;
  103. ori$led:
  104.     push    b
  105.     ani    0011$1111b        ; Mask off any top bits
  106.     mov    c,a            ; Save
  107.     lda    led$byt            ; Load old data
  108.     ora    c            ; OR in the bit mask
  109. ; Maskin ram enable
  110.     ori    1100$0000b        ; Turns ram on.
  111.     jr    led$com
  112. ;
  113. ;----------------------------------------------------------------
  114. ; AND the specified bit mask in A into the LED Outputs.
  115. ;
  116. ; On Entry
  117. ;    A = led mask
  118. ;
  119. ; On Exit
  120. ;     Set bit leds turned on. Others turned off.
  121. ;----------------------------------------------------------------
  122. ;
  123. ani$led:
  124.     push    b
  125.     mov    c,a            ; Save
  126.     lda    led$byt            ; Load old data
  127.     ana    c            ; AND the bit image of previous leds
  128.     ori    wr$en            ; OR in memory enable
  129.     jr    led$com
  130. ;
  131. ;----------------------------------------------------------------
  132. ; Exclusive OR the bit in A with the current LED port mask.
  133. ;
  134. ; On Entry
  135. ;    A = bit mask to XOR into led image
  136. ;
  137. ; On Exit
  138. ;    LED image updated
  139. ;----------------------------------------------------------------
  140. ;
  141. xri$led:
  142.     push    b
  143.     mov    c,a
  144.     lda    led$byt
  145.     xra    c
  146.     jr    led$com
  147. ;
  148. ;----------------------------------------------------------------
  149. ; Toggle the passed in LED
  150. ;
  151. ;----------------------------------------------------------------
  152. ;
  153. tog$led:
  154.     ora    a
  155.     rz
  156.     cpi    8
  157.     rnc
  158. ;
  159.     push    b
  160.     call    led$msk
  161.     lda    led$byt
  162.     xra    c
  163.     ori    wr$en
  164.     jmp    led$com
  165. ;
  166. ; ---------------------------------------------
  167. ; -- Convert a bit number into an actual Bit --
  168. ; ---------------------------------------------
  169. ;
  170. led$msk:
  171.     mov    b,a            ; load counter
  172.     mvi    a,080h            ; Seed. Must rotate at least once.
  173. led$rot:
  174.     rlc                ; Shift left
  175.     djnz    led$rot
  176.     mov    c,a            ; Save data into C for later
  177.     ret
  178. ;
  179. ;----------------------------------------------------------------
  180. ;           Turn on the system bell
  181. ;----------------------------------------------------------------
  182. ;
  183. set$bel:
  184.     push    psw
  185.     mvi    a,1
  186.     sta    bel$byt
  187.     out    @buz            ; To bell / buzzer
  188.     pop    psw
  189.     ret
  190. ;
  191. ;----------------------------------------------------------------
  192. ;           Turn off the system bell
  193. ;----------------------------------------------------------------
  194. ;
  195. clr$bel:
  196.     push    psw
  197.     xra    a            ; Send a 0
  198.     sta    bel$byt
  199.     out    @buz            ; To bell / buzzer
  200.     pop    psw
  201.     ret
  202. ;
  203. ;----------------------------------------------------------------
  204. ;     Toggle the system bell bit ON/OFF
  205. ;----------------------------------------------------------------
  206. ;
  207. tog$bel:
  208.     push    psw
  209.     lda    bel$byt
  210.     xri    1
  211.     sta    bel$byt
  212.     out    @buz            ; To bell / buzzer
  213.     pop    psw
  214.     ret
  215. ;
  216. ;----------------------------------------------------------------
  217. ; Clear the watchdog timer by writing a 1 then 0 to toggle
  218. ; the port.
  219. ;----------------------------------------------------------------
  220. ;
  221. clrwdt:
  222.     push    psw
  223.     lda    wdt$flg
  224.     out    @wdt
  225.     xri    1            ; Toggle bit 1
  226.     sta    wdt$flg
  227.     pop    psw
  228.     ret
  229. ;
  230. ;----------------------------------------------------------------
  231. ; Read the dip switch into A for the user
  232. ;----------------------------------------------------------------
  233. ;
  234. schrd:
  235.     in    @sch
  236.     ret
  237. ;
  238. ;----------------------------------------------------------------
  239. ;    Read real time clock to ram at DE
  240. ;
  241. ; Memory is laid out in the following format:
  242. ; seconds
  243. ; minutes
  244. ; hours
  245. ; day of week
  246. ; day of month
  247. ; month
  248. ; Year. Saved in ram in the clock chip at port 01fh
  249. ;
  250. ; Note the bit of code that stops the clock from being read
  251. ; constantly if the chip is faulty. This is the count value
  252. ; in B.
  253. ;----------------------------------------------------------------
  254. ;
  255. clkrd:
  256.     push    h
  257.     push    b                ; Save
  258.     sded    ?time
  259.     mvi    b,5                ; 5 times maximum read count
  260. ;
  261. ;
  262. ;
  263. read$clock:                ; Repeat here if a rollover
  264.     lhld    ?time
  265.     in    @clk + 2            ; Seconds
  266.     mov    m,a
  267.     inx    h
  268. ;
  269.     in    @clk + 3            ; Minutes
  270.     mov    m,a
  271.     inx    h
  272. ;
  273.     in    @clk + 4            ; hours
  274.     mov    m,a
  275.     inx    h
  276. ;
  277.     in    @clk + 5            ; Day of week
  278.     mov    m,a
  279.     inx    h
  280. ;
  281.     in    @clk + 6            ; Day of month
  282.     mov    m,a
  283.     inx    h
  284. ;
  285.     in    @clk + 7            ; Month
  286.     mov    m,a
  287.     inx    h            ; -> year register in system ram
  288.     in    @clk + 0fh        ; Year ram in clock
  289.     mov    m,a
  290. ;
  291. ; Check rollover status port. Bitset = an internal ripple, re-read required.
  292. ;
  293.     in    @clk+20            ; Status port
  294.     ani    1            ; Status bit is in D0
  295.     jz    read$kend        ; if 00, a good read
  296.     djnz    read$clock        ; Read till a 0 bit.
  297. ;
  298. ; Else the time is valid
  299. ;
  300. read$kend:
  301.     pop    b            ; Restore all
  302.     pop    h
  303.     ret
  304. ;
  305. ;----------------------------------------------------------------
  306. ;
  307. ; Write the real time clock from a ram store. This is expected
  308. ; to be in the same format as that for clock read.
  309. ;
  310. ; On entry
  311. ;  DE -> time buffer
  312. ;----------------------------------------------------------------
  313. ;
  314. clkwr:
  315.     push    h
  316. ; Reset clock counters
  317.     mvi    a,0ffh            ; All 1's for a reset counter command
  318.     out    @clk + 18        ; Resets all the counters
  319. ;
  320.     ldax    d
  321.     mov    a,m
  322.     out    @clk + 2
  323.     inx    d
  324. ;
  325.     ldax    d
  326.     out    @clk + 3            ; Minutes
  327.     inx    d
  328. ;
  329.     ldax    d
  330.     out    @clk + 4            ; hours
  331.     inx    d
  332. ;
  333.     ldax    d
  334.     out    @clk + 5            ; Day of week
  335.     inx    d
  336. ;
  337.     ldax    d
  338.     out    @clk + 6            ; Day of month
  339.     inx    d
  340. ;
  341.     ldax    d
  342.     out    @clk + 7            ; Month
  343.     inx    d
  344. ;
  345.     ldax    d                ; Write year to clock ram
  346.     out    @clk + 0fh            ; Write to year register ram
  347. ;
  348.     pop    h
  349.     ret
  350. ;
  351. ;----------------------------------------------------------------
  352. ;     Initialize the hardware on the board
  353. ;
  354. ; Initialize the SIO for channel A and channel B 8 bit, 1 stop
  355. ; no parity and 9600 baud each.
  356. ; CTC channels 0 and 1 are for SIO baud rates
  357. ; CTC channel 2 for external interrupts......... (see monitor)
  358. ; CTC channel 3 for real time clock interrupts.. (see monitor)
  359. ;----------------------------------------------------------------
  360. ;
  361. init:
  362.     lxi    h,initbl
  363. initlp:    mov    b,m            ; get counter
  364.     inx    h
  365.     mov    c,m            ; get port    
  366.     mov    a,b
  367.     ora    a            ; check for zero
  368.     jz    inictc            ; exit if count=0
  369.     inx    h
  370.     outir                ; send all out
  371.     jr    initlp
  372. ;
  373. inictc:
  374.     mvi    a,02h            ; Reset channel
  375.     out    @ctc0
  376. ;
  377.     nop
  378.     nop
  379. ;
  380. ;
  381.     mvi    a,045h            ; Time constant follows
  382.     out    @ctc0
  383.     mvi    a,13
  384.     out    @ctc0
  385. ;
  386. ; Initialize the watchdog timer clear routine that toggles the
  387. ; low order bit each time called.
  388. ;
  389.     xra    a
  390.     sta    wdt$flg
  391.     sta    bel$byt
  392. ;
  393.     ret
  394. ;
  395. ;----------------------------------------------------------------
  396. ;         Console output
  397. ;----------------------------------------------------------------
  398. ;
  399. con$out:
  400. coe:
  401.     push    psw
  402. coe$wait:
  403.     in    @stat0
  404.     ani    txmsk            ; See if transmitter empty.
  405.     jrz    coe$wait
  406. ; Ok, send the data out.
  407.     pop    psw
  408.     out    @data0
  409.     ret
  410. ;
  411. ;----------------------------------------------------------------
  412. ;         Console input
  413. ;----------------------------------------------------------------
  414. ;
  415. con$inp:
  416. cie:
  417.     call    clrwdt
  418.     in    @stat0
  419.     ani    rxmsk
  420.     jz    cie
  421.     in    @data0
  422.     ret                ; Done
  423. ;
  424. ;----------------------------------------------------------------
  425. ;         Console status
  426. ;----------------------------------------------------------------
  427. ;
  428. con$ist:
  429. cst:
  430.     call    clrwdt            ; Clear the dog
  431.     in    @stat0
  432.     ani    rxmsk
  433.     rz
  434.     mvi    a,0ffh
  435.     ret
  436. ;
  437. ;----------------------------------------------------------------
  438. ;         Hardware setups for the system chips.
  439. ;----------------------------------------------------------------
  440. ;
  441. initbl:
  442. ; Setup the dart A channel
  443.     db    01,@stat0,018h        ; Channel reset
  444.     db    02,@stat0,04,044h    ; X1 clock, 1 stop bit, parity OFF
  445.     db    02,@stat0,01,000h    ; Clear internal status
  446.     db    02,@stat0,03,0c1h    ; Rx 8 bit. Rx enable, auto enables OFF
  447.     db    02,@stat0,05,0eah    ; DTR, Tx 8 bit, Tx enable, RTS, DTR of
  448.     db    00
  449. ; NOTE that the B channel is initialized in the AUX driver module used
  450. ; by the system. This makes sense as different system software may
  451. ; need different AUX drivers.
  452. ;
  453.     dseg
  454. ;
  455. bel$byt    db    00            ; Last bell port write
  456. led$byt    db    00            ; Last LED output byte
  457. wdt$flg    db    00            ; Dog flag bit 0
  458. ?time:    ds    8            ; Time buffer address
  459.     end
  460.  
  461.     
  462.  
  463. ;