-
Notifications
You must be signed in to change notification settings - Fork 84
/
rs232rcvr.src
145 lines (107 loc) · 2.52 KB
/
rs232rcvr.src
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
137
138
139
140
141
142
143
144
145
.page
.subttl rs-232 receiver (09/17/84): c/128
; rsrcvr - nmi routine to collect data into bytes
;
; variables used:
; inbit - input bit value
; bitci - bit count in
; rinone - flag for start bit check <>0 start bit
; ridata - byte input buffer
; riprty - holds byte input parity
; ribuf - indirect pointer to data buffer
; ridbs - input buffer pointer to start
; ridbe - input buffer index to end (if ridbe=ridbs then input buffer empty)
rsrcvr
ldx rinone ;check for start bit
bne rsrtrt ;was start bit
dec bitci ;check where we are in input...
beq rsr030 ;have a full byte
bmi rsr020 ;getting stop bits
; calculate parity
lda inbit ;get data up
eor riprty ;calc new parity
sta riprty
; shift data bit in
lsr inbit ;in bit pos 0
ror ridata ;c into data
; exit
rsrext
rts
.page
; have stop bit, so store in buffer
rsr018
dec bitci ;no parity, dec so check works
rsr020
lda inbit ;get data...
beq rsr060 ;...zero, an error?
lda m51ctr ;check for correct # of stop bits
asl a ;carry tell how may stop bits
lda #1
adc bitci
bne rsrext ;no..exit
; enable to recieve a byte
rsrabl
lda #$90 ;enable flag for next byte
sta d2icr ;toss bad/old nmi
ora enabl ;mark in enable register
sta enabl ; (re-enabled by 'jmp oenabl')
sta rinone ;flag for start bit
lda #$02 ;disable t2
jmp oenabl ;flip-off enabl
; reciever start bit check
rsrtrt
lda inbit ;check if space
bne rsrabl ;bad...try again
sta rinone ;good...disable flag
lda #1 ;set parity to one always
sta riprty
rts ;and exit
; put data in buffer (at parity time)
rsr030
ldy ridbe ;get end
iny
cpy ridbs ;have we passed start?
beq recerr ;yes...error
sty ridbe ;move ridbe foward
dey
lda ridata ;get byte buffer up
ldx bitnum ;shift untill full byte
1$
cpx #9 ;always 8 bits
beq 2$
lsr a ;fill with zeros
inx
bne 1$
2$ sta (ribuf),y ;data to page buffer
; parity checking
lda #$20 ;check 6551 command register
bit m51cdr
beq rsr018 ;no parity bit so stop bit
bmi rsrext ;no parity check
; check calc parity
lda inbit
eor riprty ;put in with parity
beq 3$ ;even parity
bvs rsrext ;odd...okay so exit
.byte $2c ;skip two
3$ bvc rsrext ;even...okay so exit
; errors reported
lda #1 ;parity error
.byte $2c
recerr
lda #$4 ;reciever overrun
.byte $2c
breake
lda #$80 ;break detected
.byte $2c
framee
lda #$02 ;frame error
ora rsstat
sta rsstat
jmp rsrabl ;bad exit so hang (!?)
; check for errors
rsr060
lda ridata ;expecting stop...
bne framee ;frame error
beq breake ;could be a break
;.end