Mirror of CollapseOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 line
5.7KB

  1. ( ----- 600 )
  2. 601 ACIA 606 Zilog SIO driver
  3. 615 SPI relay 619 Xcomp unit
  4. ( ----- 601 )
  5. ACIA driver
  6. Manage I/O from an asynchronous communication interface adapter
  7. (ACIA). provides "(emit)" to put c char on the ACIA as well as
  8. an input buffer from which a provided "(key)" reads. This driver
  9. installs an interrupt handler at RST38 to handle RX.
  10. To use, begin by loading declarations (B582) before xcomp is
  11. loaded. These declarations provide default values for ports and
  12. memory offsets that you can override. See B582.
  13. Then, in the driver part, load range 583-588.
  14. ( ----- 602 )
  15. 0x80 CONSTANT ACIA_CTL ( IO port for ACIA's control register )
  16. 0x81 CONSTANT ACIA_IO ( IO port for ACIA's data registers )
  17. 0x20 CONSTANT ACIA_BUFSZ ( SZ-1 must be a mask )
  18. ( Address in memory that can be used variables shared
  19. with ACIA's native words. 4 bytes used. )
  20. CREATE ACIA_MEM SYSVARS 0x70 + ,
  21. ( Points to ACIA buf )
  22. : ACIA( ACIA_MEM @ 2+ ;
  23. ( Read buf idx Pre-inc )
  24. : ACIAR> ACIA_MEM @ ;
  25. ( Write buf idx Post-inc )
  26. : ACIAW> ACIA_MEM @ 1+ ;
  27. ( This means that if W> == R>, buffer is full.
  28. If R>+1 == W>, buffer is empty. )
  29. ( ----- 603 )
  30. ( ACIA INT handler, read into ACIAW> )
  31. ( Set RST 38 jump ) PC ORG @ 0x39 + !
  32. AF PUSH,
  33. ACIA_CTL INAi, 0x01 ANDi, ( is ACIA rcv buf full? )
  34. IFZ, ( no, abort ) AF POP, EI, RETI, THEN,
  35. HL PUSH,
  36. HL ACIAW> LDdi, A (HL) LDrr,
  37. HL DECd, (HL) CPr, ( W> == R> ? )
  38. IFNZ, ( buffer not full )
  39. ( get wr ptr ) HL ACIA( LDd(i),
  40. L ADDr, IFC, H INCr, THEN, L A LDrr,
  41. ( fetch/write ) ACIA_IO INAi, (HL) A LDrr,
  42. ( advance W> ) ACIAW> LDA(i), A INCr,
  43. ACIA_BUFSZ 1- ANDi, ACIAW> LD(i)A,
  44. THEN,
  45. HL POP, AF POP, EI, RETI,
  46. ( ----- 604 )
  47. : (key)
  48. ( inc then fetch )
  49. [ ACIAR> LITN ] C@ 1+ [ ACIA_BUFSZ 1- LITN ] AND
  50. ( As long as R> == W>-1, it means that buffer is empty )
  51. BEGIN DUP [ ACIAW> LITN ] C@ = NOT UNTIL
  52. DUP [ ACIA( LITN ] @ + C@ ( ridx c )
  53. SWAP [ ACIAR> LITN ] C! ( c )
  54. ;
  55. : (emit)
  56. ( As long at CTL bit 1 is low, we are transmitting. wait )
  57. BEGIN [ ACIA_CTL LITN ] PC@ 0x02 AND UNTIL
  58. ( The way is clear, go! )
  59. [ ACIA_IO LITN ] PC!
  60. ;
  61. ( ----- 605 )
  62. : ACIA$
  63. H@ [ ACIA( LITN ] ! 0 [ ACIAR> LITN ] C!
  64. 1 [ ACIAW> LITN ] C! ( write index starts one pos later )
  65. [ ACIA_BUFSZ LITN ] ALLOT
  66. ( setup ACIA
  67. CR7 (1) - Receive Interrupt enabled
  68. CR6:5 (00) - RTS low, transmit interrupt disabled.
  69. CR4:2 (101) - 8 bits + 1 stop bit
  70. CR1:0 (10) - Counter divide: 64 )
  71. 0b10010110 [ ACIA_CTL LITN ] PC!
  72. (im1) ;
  73. ( ----- 606 )
  74. Zilog SIO driver
  75. Declarations at B607
  76. Driver load range at B608-B610
  77. ( ----- 607 )
  78. 0x80 CONSTANT SIO_ACTL 0x81 CONSTANT SIO_ADATA
  79. 0x82 CONSTANT SIO_BCTL 0x83 CONSTANT SIO_BDATA
  80. 0x20 CONSTANT SIO_BUFSZ ( SZ-1 must be a mask )
  81. ( Address in memory that can be used variables shared
  82. with SIO native words. 4 bytes used. )
  83. CREATE SIO_MEM SYSVARS 0x70 + ,
  84. ( Points to SIO buf )
  85. : SIO( SIO_MEM @ 2+ ;
  86. ( Read buf idx Pre-inc )
  87. : SIOR> SIO_MEM @ ;
  88. ( Write buf idx Post-inc )
  89. : SIOW> SIO_MEM @ 1+ ;
  90. ( This means that if W> == R>, buffer is full.
  91. If R>+1 == W>, buffer is empty. )
  92. ( ----- 608 )
  93. ( INT handler. Set RST 38 jump ) PC ORG @ 0x39 + !
  94. AF PUSH, BEGIN,
  95. SIO_ACTL INAi, ( RR0 ) 0x01 ANDi, ( is recv buf full? )
  96. IFZ, ( nope, exit ) A 0x20 ( CMD 4 ) LDri, SIO_ACTL OUTiA,
  97. AF POP, EI, RETI, THEN,
  98. HL PUSH,
  99. HL SIOW> LDdi, A (HL) LDrr,
  100. HL DECd, (HL) CPr, ( W> == R> ? )
  101. IFNZ, ( buffer not full )
  102. ( get wr ptr ) HL SIO( LDd(i),
  103. L ADDr, IFC, H INCr, THEN, L A LDrr,
  104. ( fetch/write ) SIO_ADATA INAi, (HL) A LDrr,
  105. ( advance W> ) SIOW> LDA(i), A INCr,
  106. SIO_BUFSZ 1- ANDi, SIOW> LD(i)A,
  107. THEN, HL POP, JR, AGAIN,
  108. ( ----- 609 )
  109. : (key)
  110. ( inc then fetch )
  111. [ SIOR> LITN ] C@ 1+ [ SIO_BUFSZ 1- LITN ] AND
  112. ( As long as R> == W>-1, it means that buffer is empty )
  113. BEGIN DUP [ SIOW> LITN ] C@ = NOT UNTIL
  114. DUP [ SIO( LITN ] @ + C@ ( ridx c )
  115. SWAP [ SIOR> LITN ] C! ( c )
  116. ;
  117. : (emit)
  118. ( As long at CTL bit 2 is low, we are transmitting. wait )
  119. BEGIN [ SIO_ACTL LITN ] PC@ 0x04 AND UNTIL
  120. ( The way is clear, go! )
  121. [ SIO_ADATA LITN ] PC!
  122. ;
  123. ( ----- 610 )
  124. : _ [ SIO_ACTL LITN ] PC! ;
  125. : SIO$
  126. H@ [ SIO( LITN ] ! 0 [ SIOR> LITN ] C!
  127. 1 [ SIOW> LITN ] C! ( write index starts one pos later )
  128. [ SIO_BUFSZ LITN ] ALLOT
  129. 0x18 _ ( CMD3 )
  130. 0x24 _ ( CMD2/PTR4 ) 0b11000100 _ ( WR4/64x/1stop/nopar )
  131. 0x03 _ ( PTR3 ) 0b11000001 _ ( WR3/RXen/8char )
  132. 0x05 _ ( PTR5 ) 0b01101000 _ ( WR5/TXen/8char )
  133. 0x21 _ ( CMD2/PTR1 ) 0b00011000 _ ( WR1/Rx INT all chars )
  134. (im1)
  135. ;
  136. ( ----- 619 )
  137. ( RC2014 classic with ACIA )
  138. 0xff00 CONSTANT RS_ADDR 0xfffa CONSTANT PS_ADDR
  139. RS_ADDR 0x80 - CONSTANT SYSVARS
  140. 0x8000 CONSTANT HERESTART
  141. 4 CONSTANT SPI_DATA 5 CONSTANT SPI_CTL 1 CONSTANT SDC_DEVID
  142. 602 LOAD ( acia decl )
  143. 5 LOAD ( z80 assembler )
  144. 262 LOAD ( xcomp ) 282 LOAD ( boot.z80.decl )
  145. 270 LOAD ( xcomp overrides ) 283 335 LOADR ( boot.z80 )
  146. 353 LOAD ( xcomp core low ) 603 605 LOADR ( acia )
  147. 419 LOAD ( SPI relay ) 423 436 LOADR ( SD Card )
  148. 400 LOAD ( AT28 )
  149. 390 LOAD ( xcomp core high )
  150. (entry) _
  151. PC ORG @ 8 + ! ( Update LATEST )
  152. ," ACIA$ BLK$ " EOT,
  153. ( ----- 620 )
  154. ( RC2014 classic with SIO )
  155. 0xff00 CONSTANT RS_ADDR 0xfffa CONSTANT PS_ADDR
  156. RS_ADDR 0x80 - CONSTANT SYSVARS
  157. 0x8000 CONSTANT HERESTART
  158. 4 CONSTANT SPI_DATA 5 CONSTANT SPI_CTL 1 CONSTANT SDC_DEVID
  159. 607 LOAD ( SIO decl )
  160. 5 LOAD ( z80 assembler )
  161. 262 LOAD ( xcomp ) 282 LOAD ( boot.z80.decl )
  162. 270 LOAD ( xcomp overrides ) 283 335 LOADR ( boot.z80 )
  163. 353 LOAD ( xcomp core low ) 608 610 LOADR ( SIO )
  164. 419 LOAD ( SPI relay ) 423 436 LOADR ( SD Card )
  165. 400 LOAD ( AT28 )
  166. 390 LOAD ( xcomp core high )
  167. (entry) _
  168. PC ORG @ 8 + ! ( Update LATEST )
  169. ," SIO$ BLK$ " EOT,