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