home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / KAYPRO / KPNUROM.LBR / KPORTS.ZQ0 / KPORTS.Z80
Text File  |  2000-06-30  |  12KB  |  424 lines

  1. title KAYPRO 4-83 RESIDENT SOFTWARE PACKAGE
  2. subttl SIO, PIO, and CTC equates
  3.     cseg
  4. ;
  5. ; ################################################################
  6. ; ##                                ##
  7. ; ##    System device I/O routines for KBD, TTY and LST        ##
  8. ; ##                                ##
  9. ; ################################################################
  10. ; ##    LAST UPDATE: JULY 7,1982    [001]            ##
  11. ; ##        BY JIM NICKERSON                ##
  12. ; ##        CHANGED SIOA REGISTER 3 INIT TO AUTO ENABLE    ##
  13. ; ##        ADDED LIST STATUS FOR THE SERIAL PORT        ##
  14. ; ##        TTYOUT NOW THE SAME AS OUT WITH STATUS CHK    ##
  15. ; ##        CHANGE VECTOR PAD MAPPING            ##
  16. ; ################################################################
  17. ; ## Fixed list status foulup.  Moved thnsd here. 85/6/15 cbf   ##
  18. ; ## Made bitport and bankbit available to external modules.    ##
  19. ; ################################################################
  20. ;
  21.     entry    kbdstat, kbdin, kbdout
  22.     entry    ttystat, ttyin, ttyout, ttyostat
  23.     entry    liststat, list, devinit
  24.     entry    thnsd
  25.     entry    bitport, bankbit
  26. ;
  27. ; ***************
  28. ; * sio equates *
  29. ; ***************
  30. ;
  31. sio    equ    04H;        base address of sio
  32. sioa0    equ    sio+2;        channel a command/status
  33. sioa1    equ    sio+0;        channel a data
  34. siob0    equ    sio+3;        channel b command/status
  35. siob1    equ    sio+1;        channel b data
  36. ;
  37. ; write registers 0-7 and control bits
  38. ; init registers in the following order 0,2,4,3,5,1
  39. ;
  40. wr0    equ    0;    command register, crc reset, reg ptr
  41. ; bits 0-2 are register pointers to WRx and RRx
  42. ; bits 3-5 and commands as given bellow
  43. null    equ    0;    null command
  44. extrset    equ    10H;    reset ext/status interrupts
  45. reset    equ    18H;    channel reset
  46. ienrc    equ    20H;    Enable Int on Next Rx Character
  47. rtip    equ    21H;    reset transmitter interrupt pending
  48. errset    equ    30H;    error reset
  49. retint    equ    31H;    return from interrupt
  50. ;
  51. wr1    equ    1H;    interrupt enable, Wait/Ready modes
  52. esie    equ    1H;    external/status interrupt enable
  53. tie    equ    2H;    transmitter interrupt enable
  54. tid    equ    0;    transmitter interrupt disable
  55. statav    equ    4H;    Status affects vector (z80 mode 2) (see WR2)
  56. ; bits 3-4 affect receive interrupt mode
  57. rid    equ    0;    receive interrupts disabled
  58. rifc    equ    8H;    receive interrupt on first char only
  59. riep    equ    10H;    recv interrupts enabled, parity err,
  60. ;                Special Recv Cond
  61. rie    equ    18H;    same as riep but parity error
  62. ;                not Special Recv Cond
  63. ;
  64. wr2    equ    2;    interrupt vect address/ptr (chan b only)
  65. ; interrupt address (z80 reg I+WR2=interrupt address)
  66. ; returned as is if not statav above in wr1
  67. ; if statav then bits 1-3 are modified as bellow:
  68. ;    000    ch b transmit buffer empty
  69. ;    001    ch b external/status change
  70. ;    010    ch b receive char available
  71. ;    011    ch b special receive condition
  72. ;            (parity error, Rx overrun,
  73. ;             framing error, end of frame(sdlc) )
  74. ;    1xx    ch a (* same vectors as for channel b above *)
  75. ;
  76. wr3    equ    3;    receiver logic control and parameters
  77. re    equ    1;    receiver enable
  78. autoe    equ    20H;    auto enable
  79. ;             (use dcd and cts to enable recv and xmt)
  80. ; bits 6-7 are receiver bits/character
  81. rbits5    equ    0;    5 bits/character
  82. rbits7    equ    40H;    7 bits/character
  83. rbits6    equ    80H;    6 bits/character
  84. rbits8    equ    0C0H;    8 bits/character
  85. ;
  86. wr4    equ    4;    control bits that affect both xmt and recv
  87. pon    equ    1;    enable parity (parity on)
  88. pstate    equ    2;    parity even   not pstate = parity odd
  89. ; bits 2-3 are number of stop bits
  90. syncmd    equ    0;    sync mode is to be selected
  91. sbits1    equ    4;    1 stop bit
  92. sbits5    equ    8H;    1.5 stop bits
  93. sbits2    equ    0CH;    2 stop bits
  94. ; bits 6-7 control clock rate
  95. cr1    equ    0;    data rate x1=clock rate
  96. cr16    equ    40H;              x16
  97. cr32    equ    80H;              x32
  98. cr64    equ    0CH;              x64
  99. ;
  100. wr5    equ    5;    control bits that affect xmt
  101. te    equ    8H;    transmit enable
  102. break    equ    10H;    send break
  103. ; bits 5-6 are number of bits/character to transmit
  104. tbits5    equ    0;    5 or less bits/character
  105. tbits7    equ    20H;    7 bits/character
  106. tbits6    equ    40H;    6 bits/character
  107. tbits8    equ    60H;    8 bits/character
  108. rts    equ    2;    RTS output
  109. dtr    equ    80H;    DTR output
  110. ;
  111. wr6    equ    6;    sdlc transmit sync character
  112. wr7    equ    7;    sdlc receive sync character
  113. ;
  114. ; read registers 0-2 and status bits
  115. rr0    equ    0;    general recv and xmt status
  116. rca    equ    1;    receive character available
  117. intped    equ    2;    interrupt pending (ch a only)
  118. tbe    equ    4;    transmit buffer empty
  119. synhnt    equ    10H;    sync/hunt
  120. dcd    equ    8H;    DCD input
  121. cts    equ    20H;    CTS input
  122. xmtundr    equ    40H;    transmit underrun/ EOM
  123. brk    equ    80H;    break/abort status
  124. ;
  125. rr1    equ    1;    Special Rcv conditions and Residue codes
  126. ; bits 4-7 are special receive conditions
  127. rpe    equ    10H;    parity error
  128. rovr    equ    20H;    Rx overrun error
  129. framerr    equ    40H;    framing error
  130. ;
  131. rr2    equ    2;    interrupt vector address/pointer
  132. ;
  133. ; ***************
  134. ; * pio equates *
  135. ; ***************
  136. ;
  137. pio    equ    08H;    base address of pio
  138. pioac    equ    pio+1;    pio a control
  139. pioad    equ    pio+0;    pio a data
  140. piobc    equ    pio+3;    pio b control
  141. piobd    equ    pio+2;    pio b data
  142. ;
  143. spio    equ    01CH;    base addr. of pio (system status bits port)
  144. spioac    equ    spio+1;    pio a control
  145. spioad    equ    spio+0;    pio a data
  146. spiobc    equ    spio+3;    pio b control
  147. spiobd    equ    spio+2;    pio b data
  148. ;
  149. bitport    equ    spioad;    system bit port for status and control
  150. bankbit    equ    080h;    switch to ROM bank
  151. ; 0 drive sel A:
  152. ; 1 drive sel B:
  153. ; 2 n/c
  154. ; 3 centronics i/o ready line
  155. ; 4 centronics i/o data strobe
  156. ; 5 single density  (not 5 is double density)
  157. ; 6 drive motor off (not 6 is motor on)
  158. ; 7 rom enable (not 7 is rom off)
  159. ;
  160. ; control register
  161. setiv    equ    0;    set interrupt vector, bits 1-7 are vect addr
  162. ;
  163. som    equ    0FH;    set operating mode. bits 6-7 specify mode
  164. mode0    equ    0;    output
  165. mode1    equ    40H;    input
  166. mode2    equ    80H;    bidirectional
  167. mode3    equ    0C0H;    control (bit by bit i/o,
  168. ;            mode3 command is followed by
  169. ;            byte where bit pattern specifies i/o bits
  170. ;                1=input, 0=output
  171. ;
  172. sicw    equ    7H;    set int control wd, bits 4-7 are params
  173. imask    equ    10H;    bit mask follows      )
  174. hghlow    equ    20H;    high/low          ) mode 3 only
  175. andor    equ    40H;    and/or of bits to gen interrupt )
  176. intena    equ    80H;    enable interrupt (bit low disable ints)
  177. ;
  178. intcmd    equ    03H;    set interrupt enable/disable
  179. ;            without changing status as sicw
  180. ;
  181. ; ***************
  182. ; * ctc equates *
  183. ; ***************
  184. ;
  185. ctc    equ    18H;    ctc base address
  186. ctc0    equ    ctc+0;    ctc channel 0
  187. ctc1    equ    ctc+1;    ctc channel 1
  188. ctc2    equ    ctc+2;    ctc channel 2
  189. ctc3    equ    ctc+3;    ctc channel 3
  190. ;
  191. ; channel control register bits
  192. ctccmd    equ    01H;    ctc command byte
  193. ctcint    equ    80H;    interrupt enable
  194. ctcm1    equ    40H;    set ctc mode is counter
  195. ctcm0    equ    00H;    set ctc mode is timer
  196. range    equ    20H;    timer prescaler factor is 256
  197. ;                (not range is 16)
  198. slope    equ    10H;    edge triger positive
  199. ;                (not slope is negative edge)
  200. trigger    equ    8H;    ext trigger
  201. ltc    equ    4H;    load time constant
  202. ;                (followed by time constant)
  203. rsetctc    equ    2H;    reset channel
  204. ;
  205. ctcivec    equ    0;    set ctc interrupt vector,
  206. ;                bits 3-7 are vector addr
  207. ctcvmsk    equ    0F8H;    interrupt vector mask to strip bits 0-2
  208. ;
  209. ; ***************
  210. ; * baud rate   *
  211. ; ***************
  212. ;
  213. bauda    equ    00H;    baud rate generator for serial chan a
  214. baudb    equ    0CH;    baud rate generator for serial chan b
  215. ;
  216. ; baud rate factors, output to baudx to select baud rate
  217. baud10    equ    02H;    110 baud rate
  218. baud30    equ    05H;    300 baud rate
  219. baud12    equ    07H;    1200 baud rate
  220. baud24    equ    0AH;    2400 baud rate
  221. baud48    equ    0CH;    4800 baud rate
  222. baud96    equ    0EH;    9600 baud rate
  223. baud19k    equ    0FH;    19.2k baud rate
  224. ;
  225. subttl I/O configuration tables
  226. ;
  227. iotabint:    ;        i/o device initialization table
  228.         ;        first byte is port #
  229.         ;        second byte is byte to send to port
  230.     db    (iotblend-iotabint)/2    ; table length in arguments
  231. ;
  232. ; init sio channel b
  233.  db    siob0, reset;        reset sio channel
  234.  db    baudb, baud30;        300 baud
  235.  db    siob0, wr4
  236.  db    siob0, sbits1 or cr16;    one stop bit, 16x clock
  237.  db    siob0, wr3
  238.  db    siob0, re or rbits8;    recv enable, 8 bits/char
  239.  db    siob0, wr5
  240.  db    siob0, te or tbits8 or dtr;    xmt enbl, 8 bits, dtr on
  241.  db    siob0, wr1
  242.  db    siob0, tid or rid;    xmt & recv interrupts disabled
  243. ;
  244. ; init sio channel a
  245.  db    sioa0, reset;        reset sio channel
  246.  db    bauda, baud30;        300 baud
  247.  db    sioa0, wr4
  248.  db    sioa0, sbits1 or cr16;    one stop bit, 16x clock
  249.  db    sioa0, wr3
  250.  db    sioa0, re or rbits8 or autoe;    rcv enbl, 8 bits, auto enbl
  251.  db    sioa0, wr5
  252.  db    sioa0, te or tbits8 or dtr;    xmt enbl, 8 bits, dtr on
  253.  db    sioa0, wr1
  254.  db    sioa0, tid or rid;    xmt & recv interrupts disabled
  255. ;
  256. ; init pio used form system control bits
  257.  db    spioac, intcmd;        disable interrupts
  258.  db    spioad, 10000001B;    set system status bits
  259. ;                    (before setting mode!)
  260.  db    spioac, som or mode3;    set mode to #3
  261.  db    spioac, 00001000B;    bit pattern for mode 3
  262. ;
  263. ; init pio used to drive printer
  264.  db    pioac, intcmd;        disable interrupts
  265.  db    pioac, som or mode0;    set mode to #0  (output)
  266.  db    piobc, intcmd;        disable interrupts
  267.  db    piobc, som or mode1;    set mode to #1 (input)
  268. iotblend:        ;    end of table
  269. ;
  270. ; Initialize i/o devices
  271. devinit:
  272.     ld    hl,iotabint
  273.     ld    b,(hl);        number of bytes to send to i/o devs
  274. iolp:    inc    hl
  275.     ld    c,(hl);        port to send
  276.     inc    hl
  277.     ld    a,(hl);        byte to send
  278.     out    (c),a
  279.     djnz    iolp
  280. ;    "    "
  281. ; Check the CPU clock speed against a 300 baud SIO port.
  282. ; Depends on the ZILOG SIO characteristics.
  283. ; a,f,b,c,h,l
  284. chkspd:    ld    hl,0
  285.     ld    b,10
  286. chks1:    xor    a
  287.     out    (siob1),a;    jam the output buffer
  288.     out    (siob1),a;    with nulls
  289.     out    (siob1),a
  290.     out    (siob1),a
  291. chks2:    inc    hl
  292.     in    a,(siob0);    and see how long till free
  293.     and    tbe
  294.     jp    z,chks2;    not free yet
  295.     djnz    chks1;        do again, summing to average.
  296.     ld    c,h;        hl = 5f00 approx at 2.5 mhz
  297.     xor    a
  298.     ld    b,a
  299.     add    hl,hl;        Scale to get count
  300.     adc    a,a;         for a 10 millisec pause.
  301.     add    hl,hl
  302.     adc    a,a
  303.     add    hl,hl
  304.     adc    a,a
  305.     ld    l,h
  306.     ld    h,a
  307.     add    hl,bc
  308.     ld    (clkspd),hl
  309.     ret
  310. ;
  311. subttl Device I/O handlers
  312. ;
  313. kbdstat:
  314.     in    a,(siob0);    kbd char avail?
  315.     and    rca
  316.     ret    z;        0=no char
  317.     ld    a,0FFH;        FF=char avail
  318.     ret
  319. ;
  320. kbdin:    call    kbdstat;    loop till char avail
  321.     jr    z,kbdin
  322.     in    a,(siob1);    get char
  323.     call    kbdmap;        map out funny vector pad chars/nums
  324.     ret
  325. ;
  326. kbdout:    in    a,(siob0);    xmit buffer empty?
  327.     and    tbe
  328.     jr    z,kbdout
  329.     ld    a,c;        out character
  330.     out    (siob1),a
  331.     ret
  332. ;
  333. kbdmap:    ld    hl,mapin;    input map table
  334.     ld    bc,mapout-mapin; table length
  335.     cpir;            search table
  336.     ret    nz;        not found
  337.     ld    de,mapin;    make hl=table index
  338.     or    a;        hl-mapin=index
  339.     sbc    hl,de
  340.     ld    de,mapout-1;    index
  341.     add    hl,de
  342.     ld    a,(hl);        get char from mapout
  343.     ret
  344. ;
  345. mapin:    db    0F1H, 0F2H, 0F3H, 0F4H;    up, down, left, right arrows
  346.     db    0B1H, 0C0H, 0C1H, 0C2H;    0,1,2,3
  347.     db    0D0H, 0D1H, 0D2H, 0E1H;    4,5,6,7
  348.     db    0E2H, 0E3H, 0E4H, 0D3H;    8,9, '-', ','
  349.     db    0C3H, 0B2H;        return, '.'
  350.     db    0FFH;            end of mapin table
  351. mapout:    db    80H, 81H, 82H, 83H;    vector pad, xlate in bios
  352.     db    84H, 85H, 86H, 87H
  353.     db    88H, 89H, 8AH, 8BH
  354.     db    8CH, 8DH, 8EH, 8FH
  355.     db    90H, 91H
  356. ;
  357. ttystat:
  358.     in    a,(sioa0);        serial port status input
  359.     and    rca
  360.     jr    comout
  361. ;
  362. ttyin:    call    ttystat;        is a char ready?
  363.     jr    z,ttyin
  364.     in    a,(sioa1)
  365.     ret
  366. ;
  367. ttyout:    in    a,(sioa0);        output a char to serial port
  368.     and    tbe
  369.     jr    z,ttyout;        xmit buffer full?
  370.     ld    a,c
  371.     out    (sioa1),a;        xmit character
  372.     ret
  373. ;
  374. ; test status of serial output
  375. ttyostat:
  376.     in    a,(sioa0)
  377.     and    tbe;            TX BUF FULL ?
  378.     jr    comout
  379. ;
  380. ; list port centronics equates
  381. pready    equ    08h;            bit in bit port
  382. pstrob    equ    10h;            bit in bit port
  383. ;
  384. ; Centronicts printer port status
  385. liststat:
  386.     in    a,(bitport)
  387.     and    pready
  388. ;    "    "
  389. ; common status output
  390. comout:    ret    z;            0=busy
  391.     ld    a,0FFH;            FF=ready
  392.     ret
  393. ;
  394. list:    call    liststat;        is printer busy?
  395.     jr    z,list
  396.     ld    a,c
  397.     out    (pioad),a;        output char to printer
  398.     in    a,(bitport);        strb. printer
  399.     or    pstrob
  400.     out    (bitport),a
  401.     and    not pstrob
  402.     out    (bitport),a
  403.     ret
  404. ;
  405. ; Delay for (b) units of 10 millisec.
  406. ; a,f,b
  407. thnsd:    push    hl
  408. td1:    ld    hl,(clkspd);    approx 1670 at 5 mhz
  409. td2:    dec    hl
  410.     ld    a,h
  411.     or    l
  412.     jp    nz,td2
  413.     djnz    td1
  414.     pop    hl
  415.     ret
  416. ;
  417. ;
  418.     dseg
  419.     entry    clkspd;    for boot pre-initialization
  420. ;
  421. clkspd:    ds    2;    holds the CPU clock rate for timer
  422. ;
  423.     end
  424.