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.

rs232trans 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. .PAGE 'RS-232 TRANSMITT'
  2. ; RSTRAB - ENTRY FOR NMI CONTINUE ROUTINE
  3. ; RSTBGN - ENTRY FOR START TRANSMITTER
  4. ;
  5. ; RSR - 8/18/80
  6. ;
  7. ; VARIABLES USED
  8. ; BITTS - # OF BITS TO BE SENT (<>0 NOT DONE)
  9. ; NXTBIT - BYTE CONTAINS NEXT BIT TO BE SENT
  10. ; ROPRTY - BYTE CONTAINS PARITY BIT CALCULATED
  11. ; RODATA - STORES DATA BYTE CURRENTLY BEING TRANSMITTED
  12. ; RODBS - OUTPUT BUFFER INDEX START
  13. ; RODBE - OUTPUT BUFFER INDEX END
  14. ; IF RODBS=RODBE THEN BUFFER EMPTY
  15. ; ROBUF - INDIRECT POINTER TO DATA BUFFER
  16. ; RSSTAT - RS-232 STATUS BYTE
  17. ;
  18. ; XXX US - NORMAL BIT PATH
  19. ; XXX US - WORST CASE PARITY BIT PATH
  20. ; XXX US - STOP BIT PATH
  21. ; XXX US - START BIT PATH
  22. ;
  23. RSTRAB LDA BITTS ;CHECK FOR PLACE IN BYTE...
  24. BEQ RSTBGN ;...DONE, =0 START NEXT
  25. ;
  26. BMI RST050 ;...DOING STOP BITS
  27. ;
  28. LSR RODATA ;SHIFT DATA INTO CARRY
  29. LDX #00 ;PREPARE FOR A ZERO
  30. BCC RST005 ;YES...A ZERO
  31. DEX ;NO...MAKE AN $FF
  32. RST005 TXA ;READY TO SEND
  33. ;
  34. EOR ROPRTY ;CALC INTO PARITY
  35. STA ROPRTY
  36. ;
  37. DEC BITTS ;BIT COUNT DOWN
  38. BEQ RST010 ;WANT A PARITY INSTEAD
  39. ;
  40. RSTEXT TXA ;CALC BIT WHOLE TO SEND
  41. AND #$04 ;GOES OUT D2PA2
  42. STA NXTBIT
  43. RTS
  44. .PAGE 'RS-232 TRANSMITT'
  45. ; CALCULATE PARITY
  46. ; NXTBIT =0 UPON ENTRY
  47. ;
  48. RST010 LDA #$20 ;CHECK 6551 REG BITS
  49. BIT M51CDR
  50. BEQ RSPNO ;...NO PARITY, SEND A STOP
  51. BMI RST040 ;...NOT REAL PARITY
  52. BVS RST030 ;...EVEN PARITY
  53. ;
  54. LDA ROPRTY ;CALC ODD PARITY
  55. BNE RSPEXT ;CORRECT GUESS
  56. ;
  57. RSWEXT DEX ;WRONG GUESS...ITS A ONE
  58. ;
  59. RSPEXT DEC BITTS ;ONE STOP BIT ALWAYS
  60. LDA M51CTR ;CHECK # OF STOP BITS
  61. BPL RSTEXT ;...ONE
  62. DEC BITTS ;...TWO
  63. BNE RSTEXT ;JUMP
  64. ;
  65. RSPNO ;LINE TO SEND CANNOT BE PB0
  66. INC BITTS ;COUNTS AS ONE STOP BIT
  67. BNE RSWEXT ;JUMP TO FLIP TO ONE
  68. ;
  69. RST030 LDA ROPRTY ;EVEN PARITY
  70. BEQ RSPEXT ;CORRECT GUESS...EXIT
  71. BNE RSWEXT ;WRONG...FLIP AND EXIT
  72. ;
  73. RST040 BVS RSPEXT ;WANTED SPACE
  74. BVC RSWEXT ; WANTED MARK
  75. .SKI 3
  76. ; STOP BITS
  77. ;
  78. RST050 INC BITTS ;STOP BIT COUNT TOWARDS ZERO
  79. LDX #$FF ;SEND STOP BIT
  80. BNE RSTEXT ;JUMP TO EXIT
  81. ;
  82. .PAG 'RS-232 TRANSMITT'
  83. ; RSTBGN - ENTRY TO START BYTE TRANS
  84. ;
  85. RSTBGN LDA M51CDR ;CHECK FOR 3/X LINE
  86. LSR A
  87. BCC RST060 ;3 LINE...NO CHECK
  88. BIT D2PRB ;CHECK FOR...
  89. BPL DSRERR ;...DSR ERROR
  90. BVC CTSERR ;...CTS ERROR
  91. ;
  92. ; SET UP TO SEND NEXT BYTE
  93. ;
  94. RST060 LDA #0
  95. STA ROPRTY ;ZERO PARITY
  96. STA NXTBIT ;SEND START BIT
  97. LDX BITNUM ;GET # OF BITS
  98. RST070 STX BITTS ;BITTS=#OF BITTS+1
  99. ;
  100. RST080 LDY RODBS ;CHECK BUFFER POINTERS
  101. CPY RODBE
  102. BEQ RSODNE ;ALL DONE...
  103. ;
  104. LDA (ROBUF)Y ;GET DATA...
  105. STA RODATA ;...INTO BYTE BUFFER
  106. INC RODBS ;MOVE POINTER TO NEXT
  107. RTS
  108. .SKI 3
  109. ; SET ERRORS
  110. ;
  111. DSRERR LDA #$40 ;DSR GONE ERROR
  112. .BYT $2C
  113. CTSERR LDA #$10 ;CTS GONE ERROR
  114. ORA RSSTAT
  115. STA RSSTAT
  116. ;
  117. ; ERRORS TURN OFF T1
  118. ;
  119. RSODNE LDA #$01 ;KILL T1 NMI
  120. ;ENTRY TO TURN OFF AN ENABLED NMI...
  121. OENABL STA D2ICR ;TOSS BAD/OLD NMI
  122. EOR ENABL ;FLIP ENABLE
  123. ORA #$80 ;ENABLE GOOD NMI'S
  124. STA ENABL
  125. STA D2ICR
  126. RTS
  127. .SKI 3
  128. ; BITCNT - CAL # OF BITS TO BE SENT
  129. ; RETURNS #OF BITS+1
  130. ;
  131. BITCNT LDX #9 ;CALC WORD LENGTH
  132. LDA #$20
  133. BIT M51CTR
  134. BEQ BIT010
  135. DEX ;BIT 5 HIGH IS A 7 OR 5
  136. BIT010 BVC BIT020
  137. DEX ;BIT 6 HIGH IS A 6 OR 5
  138. DEX
  139. BIT020 RTS
  140. .END
  141. ; RSR 8/24/80 CORRECT SOME MISTAKES
  142. ; RSR 8/27/80 CHANGE BITNUM BASE TO #BITS+1
  143. ; RSR 12/11/81 MODIFY FOR VIC-40
  144. ; RSR 3/11/82 FIX ENABLES FOR BAD/OLD NMI'S