-
Notifications
You must be signed in to change notification settings - Fork 84
/
rs232nmi
208 lines (208 loc) · 4.44 KB
/
rs232nmi
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
.PAGE 'NMI HANDLER'
NMI SEI ;NO IRQ'S ALLOWED...
JMP (NMINV) ;...COULD MESS UP CASSETTES
NNMI PHA
TXA
PHA
TYA
PHA
NNMI10 LDA #$7F ;DISABLE ALL NMI'S
STA D2ICR
LDY D2ICR ;CHECK IF REAL NMI...
BMI NNMI20 ;NO...RS232/OTHER
;
NNMI18 JSR A0INT ;CHECK IF $A0 IN...NO .Y
BNE NNMI19 ;...NO
JMP ($8002) ;...YES
;
; CHECK FOR STOP KEY DOWN
;
NNMI19
JSR UD60 ;NO .Y
JSR STOP ;NO .Y
BNE NNMI20 ;NO STOP KEY...TEST FOR RS232
;
; TIMB - WHERE SYSTEM GOES ON A BRK INSTRUCTION
;
TIMB JSR RESTOR ;RESTORE SYSTEM INDIRECTS
JSR IOINIT ;RESTORE I/O FOR BASIC
JSR CINT ;RESTORE SCREEN FOR BASIC
JMP ($A002) ;...NO, SO BASIC WARM START
.SKI 2
; DISABLE NMI'S UNTILL READY
; SAVE ON STACK
;
NNMI20 TYA ;.Y SAVED THROUGH RESTORE
AND ENABL ;SHOW ONLY ENABLES
TAX ;SAVE IN .X FOR LATTER
;
; T1 NMI CHECK - TRANSMITT A BIT
;
AND #$01 ;CHECK FOR T1
BEQ NNMI30 ;NO...
;
LDA D2PRA
AND #$FF-$04 ;FIX FOR CURRENT I/O
ORA NXTBIT ;LOAD DATA AND...
STA D2PRA ;...SEND IT
;
LDA ENABL ;RESTORE NMI'S
STA D2ICR ;READY FOR NEXT...
;
; BECAUSE OF 6526 ICR STRUCTURE...
; HANDLE ANOTHER NMI AS A SUBROUTINE
;
TXA ;TEST FOR ANOTHER NMI
AND #$12 ;TEST FOR T2 OR FLAG
BEQ NNMI25
AND #$02 ;CHECK FOR T2
BEQ NNMI22 ;MUST BE A FLAG
;
JSR T2NMI ;HANDLE A NORMAL BIT IN...
JMP NNMI25 ;...THEN CONTINUE OUTPUT
;
NNMI22 JSR FLNMI ;HANDLE A START BIT...
;
NNMI25 JSR RSTRAB ;GO CALC INFO (CODE COULD BE IN LINE)
JMP NMIRTI
;
.SKI 2
; T2 NMI CHECK - RECIEVE A BIT
;
NNMI30 TXA
AND #$02 ;MASK TO T2
BEQ NNMI40 ;NO...
;
JSR T2NMI ;HANDLE INTERRUPT
JMP NMIRTI
.SKI 2
; FLAG NMI HANDLER - RECIEVE A START BIT
;
NNMI40 TXA ;CHECK FOR EDGE
AND #$10 ;ON FLAG...
BEQ NMIRTI ;NO...
;
JSR FLNMI ;START BIT ROUTINE
.SKI 2
NMIRTI LDA ENABL ;RESTORE NMI'S
STA D2ICR
PREND PLA ;BECAUSE OF MISSING SCREEN EDITOR
TAY
PLA
TAX
PLA
RTI
.SKI 4
; BAUDO TABLE CONTAINS VALUES
; FOR 14.31818E6/14/BAUD RATE/2 (NTSC)
;
BAUDO .WOR 10277-CBIT ; 50 BAUD
.WOR 6818-CBIT ; 75 BAUD
.WOR 4649-CBIT ; 110 BAUD
.WOR 3800-CBIT ; 134.6 BAUD
.WOR 3409-CBIT ; 150 BAUD
.WOR 1705-CBIT ; 300 BAUD
.WOR 852-CBIT ; 600 BAUD
.WOR 426-CBIT ; 1200 BAUD
.WOR 284-CBIT ; 1800 BAUD
.WOR 213-CBIT ; 2400 BAUD
;
; CBIT - AN ADJUSTMENT TO MAKE NEXT T2 HIT NEAR CENTER
; OF THE NEXT BIT.
; APROX THE TIME TO SERVICE A CB1 NMI
CBIT =100 ;CYCLES
.PAG 'NMI - SUBROUTINES'
; T2NMI - SUBROUTINE TO HANDLE AN RS232
; BIT INPUT.
;
T2NMI LDA D2PRB ;GET DATA IN
AND #01 ;MASK OFF...
STA INBIT ;...SAVE FOR LATTER
;
; UPDATE T2 FOR MID BIT CHECK
; (WORST CASE <213 CYCLES TO HERE)
; (CALC 125 CYCLES+43-66 DEAD)
;
LDA D2T2L ;CALC NEW TIME & CLR NMI
SBC #22+6
ADC BAUDOF
STA D2T2L
LDA D2T2H
ADC BAUDOF+1
STA D2T2H
;
LDA #$11 ;ENABLE TIMER
STA D2CRB
;
LDA ENABL ;RESTORE NMI'S EARLY...
STA D2ICR
;
LDA #$FF ;ENABLE COUNT FROM $FFFF
STA D2T2L
STA D2T2H
;
JMP RSRCVR ;GO SHIFT IN...
.SKI 3
; FLNMI - SUBROUTINE TO HANDLE THE
; START BIT TIMING..
;
; CHECK FOR NOISE ?
;
FLNMI
;
; GET HALF BIT RATE VALUE
;
LDA M51AJB
STA D2T2L
LDA M51AJB+1
STA D2T2H
;
LDA #$11 ;ENABLE TIMER
STA D2CRB
;
LDA #$12 ;DISABLE FLAG, ENABLE T2
EOR ENABL
STA ENABL
;ORA #$82
;STA D2ICR
;
LDA #$FF ;PRESET FOR COUNT DOWN
STA D2T2L
STA D2T2H
;
LDX BITNUM ;GET #OF BITS IN
STX BITCI ;PUT IN RCVRCNT
RTS
;
; POPEN - PATCHES OPEN RS232 FOR UNIVERSAL KERNAL
;
POPEN TAX ;WE'RE CALCULATING BAUD RATE
LDA M51AJB+1 ; M51AJB=FREQ/BAUD/2-100
ROL A
TAY
TXA
ADC #CBIT+CBIT
STA BAUDOF
TYA
ADC #0
STA BAUDOF+1
RTS
NOP
NOP
.END
; RSR 8/02/80 - ROUTINE FOR PANIC
; RSR 8/08/80 - PANIC & STOP KEY
; RSR 8/12/80 - CHANGE FOR A0INT A SUBROUTINE
; RSR 8/19/80 - ADD RS-232 CHECKS
; RSR 8/21/80 - MODIFY RS-232
; RSR 8/29/80 - CHANGE PANIC ORDER FOR JACK
; RSR 8/30/80 - ADD T2
; RSR 9/22/80 - ADD 1800 BAUD OPPS!
; RSR 12/08/81 - MODIFY FOR VIC-40 SYSTEM
; RSR 12/11/81 - CONTINUE MODIFICATIONS (VIC-40)
; RSR 12/14/81 - MODIFY FOR 6526 TIMER ADJUST
; RSR 2/09/82 - FIX ENABLE FOR FLAG NMI
; RSR 2/16/82 - REWRITE FOR 6526 PROBLEMS
; RSR 3/11/82 - CHANGE NMI RENABLE, FIX RESTORE
; RSR 3/29/82 - ENABLES ARE ALWAYS OR'ED WITH $80
; RSR 6/21/82 - ADD OPEN PATCH