-
Notifications
You must be signed in to change notification settings - Fork 82
/
read
412 lines (412 loc) · 12.8 KB
/
read
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
.PAGE 'CASSETTE READ'
; VARIABLES USED IN CASSETTE READ ROUTINES
;
; REZ - COUNTS ZEROS (IF Z THEN CORRECT # OF DIPOLES)
; RER - FLAGS ERRORS (IF Z THEN NO ERROR)
; DIFF - USED TO PRESERVE SYNO (OUTSIDE OF BIT ROUTINES)
; SYNO - FLAGS IF WE HAVE BLOCK SYNC (16 ZERO DIPOLES)
; SNSW1 - FLAGS IF WE HAVE BYTE SYNC (A LONGLONG)
; DATA - HOLDS MOST RECENT DIPOLE BIT VALUE
; MYCH - HOLDS INPUT BYTE BEING BUILT
; FIRT - USED TO INDICATE WHICH HALF OF DIPOLE WE'RE IN
; SVXT - TEMP USED TO ADJUST SOFTWARE SERVO
; TEMP - USED TO HOLD DIPOLE TIME DURING TYPE CALCULATIONS
; PRTY - HOLDS CURRENT CALCULATED PARITY BIT
; PRP - HAS COMBINED ERROR VALUES FROM BIT ROUTINES
; FSBLK - INDICATE WHICH BLOCK WE'RE LOOKING AT (0 TO EXIT)
; SHCNL - HOLDS FSBLK, USED TO DIRECT ROUTINES, BECAUSE OF EXIT CASE
; RDFLG - HOLDS FUNCTION MODE
; MI - WAITING FOR BLOCK SYNC
; VS - IN DATA BLOCK READING DATA
; NE - WAITING FOR BYTE SYNC
; SAL - INDIRECT TO DATA STORAGE AREA
; SHCNH - LEFT OVER FROM DEBUGGING
; BAD - STORAGE SPACE FOR BAD READ LOCATIONS (BOTTOM OF STACK)
; PTR1 - COUNT OF READ LOCATIONS IN ERROR (POINTER INTO BAD, MAX 61)
; PTR2 - COUNT OF RE-READ LOCATIONS (POINTER INTO BAD, DURING RE-READ)
; VERCHK - VERIFY OR LOAD FLAG (Z - LOADING)
; CMP0 - SOFTWARE SERVO (+/- ADJUST TO TIME CALCS)
; DPSW - IF NZ THEN EXPECTING LL/L COMBINATION THAT ENDS A BYTE
; PCNTR - COUNTS DOWN FROM 8-0 FOR DATA THEN TO FF FOR PARITY
; STUPID - HOLD INDICATOR (NZ - NO T1IRQ YET) FOR T1IRQ
; KIKA26 - HOLDS OLD D1ICR AFTER CLEAR ON READ
;
.PAG 'CASSETTE READ'
READ LDX D1T2H ;GET TIME SINCE LAST INTERRUPT
LDY #$FF ;COMPUTE COUNTER DIFFERENCE
TYA
SBC D1T2L
CPX D1T2H ;CHECK FOR TIMER HIGH ROLLOVER...
BNE READ ;...YES THEN RECOMPUTE
STX TEMP
TAX
STY D1T2L ;RELOAD TIMER2 (COUNT DOWN FROM $FFFF)
STY D1T2H
LDA #$19 ;ENABLE TIMER
STA D1CRB
LDA D1ICR ;CLEAR READ INTERRUPT
STA KIKA26 ;SAVE FOR LATTER
TYA
SBC TEMP ;CALCULATE HIGH
STX TEMP
LSR A ;MOVE TWO BITS FROM HIGH TO TEMP
ROR TEMP
LSR A
ROR TEMP
LDA CMP0 ;CALC MIN PULSE VALUE
CLC
ADC #60
CMP TEMP ;IF PULSE LESS THAN MIN...
BCS RDBK ;...THEN IGNORE AS NOISE
LDX DPSW ;CHECK IF LAST BIT...
BEQ RJDJ ;...NO THEN CONTINUE
JMP RADJ ;...YES THEN GO FINISH BYTE
.SKI 2
RJDJ LDX PCNTR ;IF 9 BITS READ...
BMI JRAD2 ;... THEN GOTO ENDING
LDX #0 ;SET BIT VALUE TO ZERO
ADC #48 ;ADD UP TO HALF WAY BETWEEN...
ADC CMP0 ;...SHORT PULSE AND SYNC PULSE
CMP TEMP ;CHECK FOR SHORT...
BCS RADX2 ;...YES IT'S A SHORT
INX ;SET BIT VALUE TO ONE
ADC #38 ;MOVE TO MIDDLE OF HIGH
ADC CMP0
CMP TEMP ;CHECK FOR ONE...
BCS RADL ;...YES IT'S A ONE
ADC #44 ;MOVE TO LONGLONG
ADC CMP0
CMP TEMP ;CHECK FOR LONGLONG...
BCC SRER ;...GREATER THAN IS ERROR
JRAD2 JMP RAD2 ;...IT'S A LONGLONG
.SKI 2
SRER LDA SNSW1 ;IF NOT SYNCRONIZED...
BEQ RDBK ;...THEN NO ERROR
STA RER ;...ELSE FLAG RER
BNE RDBK ;JMP
.SKI 2
RADX2 INC REZ ;COUNT REZ UP ON ZEROS
BCS RAD5 ;JMP
RADL DEC REZ ;COUNT REZ DOWN ON ONES
RAD5 SEC ;CALC ACTUAL VALUE FOR COMPARE STORE
SBC #19
SBC TEMP ;SUBTRACT INPUT VALUE FROM CONSTANT...
ADC SVXT ;...ADD DIFFERENCE TO TEMP STORAGE...
STA SVXT ;...USED LATER TO ADJUST SOFT SERVO
LDA FIRT ;FLIP DIPOLE FLAG
EOR #1
STA FIRT
BEQ RAD3 ;SECOND HALF OF DIPOLE
STX DATA ;FIRST HALF SO STORE ITS VALUE
.SKI 3
RDBK LDA SNSW1 ;IF NO BYTE START...
BEQ RADBK ;...THEN RETURN
LDA KIKA26 ;CHECK TO SEE IF TIMER1 IRQD US...
AND #$01
BNE RADKX ;...YES
LDA STUPID ;CHECK FOR OLD T1IRQ
BNE RADBK ;NO...SO EXIT
;
RADKX LDA #0 ;...YES, SET DIPOLE FLAG FOR FIRST HALF
STA FIRT
STA STUPID ;SET T1IRQ FLAG
LDA PCNTR ;CHECK WHERE WE ARE IN BYTE...
BPL RAD4 ;...DOING DATA
BMI JRAD2 ;...PROCESS PARITY
.SKI 2
RADP LDX #166 ;SET UP FOR LONGLONG TIMEOUT
JSR STT1
LDA PRTY ;IF PARITY NOT EVEN...
BNE SRER ;...THEN GO SET ERROR
RADBK JMP PREND ;GO RESTORE REGS AND RTI
.SKI 3
RAD3 LDA SVXT ;ADJUST THE SOFTWARE SERVO (CMP0)
BEQ ROUT1 ;NO ADJUST
BMI ROUT2 ;ADJUST FOR MORE BASE TIME
DEC CMP0 ;ADJUST FOR LESS BASE TIME
.BYT $2C ;SKIP TWO BYTES
ROUT2 INC CMP0
ROUT1 LDA #0 ;CLEAR DIFFERENCE VALUE
STA SVXT
;CHECK FOR CONSECUTIVE LIKE VALUES IN DIPOLE...
CPX DATA
BNE RAD4 ;...NO, GO PROCESS INFO
TXA ;...YES SO CHECK THE VALUES...
BNE SRER ;IF THEY WERE ONES THEN ERROR
; CONSECUTIVE ZEROS
LDA REZ ;...CHECK HOW MANY ZEROS HAVE HAPPENED
BMI RDBK ;...IF MANY DON'T CHECK
CMP #16 ;... DO WE HAVE 16 YET?...
BCC RDBK ;....NO SO CONTINUE
STA SYNO ;....YES SO FLAG SYNO (BETWEEN BLOCKS)
BCS RDBK ;JMP
.SKI 3
RAD4 TXA ;MOVE READ DATA TO .A
EOR PRTY ;CALCULATE PARITY
STA PRTY
LDA SNSW1 ;REAL DATA?...
BEQ RADBK ;...NO SO FORGET BY EXITING
DEC PCNTR ;DEC BIT COUNT
BMI RADP ;IF MINUS THEN TIME FOR PARITY
LSR DATA ;SHIFT BIT FROM DATA...
ROR MYCH ;...INTO BYTE STORAGE (MYCH) BUFFER
LDX #218 ;SET UP FOR NEXT DIPOLE
JSR STT1
JMP PREND ;RESTORE REGS AND RTI
.SKI 3
; RAD2 - LONGLONG HANDLER (COULD BE A LONG ONE)
RAD2 LDA SYNO ;HAVE WE GOTTEN BLOCK SYNC...
BEQ RAD2Y ;...NO
LDA SNSW1 ;CHECK IF WE'VE HAD A REAL BYTE START...
BEQ RAD2X ;...NO
RAD2Y LDA PCNTR ;ARE WE AT END OF BYTE...
BMI RAD2X ;YES...GO ADJUST FOR LONGLONG
JMP RADL ;...NO SO TREAT IT AS A LONG ONE READ
.SKI 2
RAD2X LSR TEMP ;ADJUST TIMEOUT FOR...
LDA #147 ;...LONGLONG PULSE VALUE
SEC
SBC TEMP
ADC CMP0
ASL A
TAX ;AND SET TIMEOUT FOR LAST BIT
JSR STT1
INC DPSW ;SET BIT THROW AWAY FLAG
LDA SNSW1 ;IF BYTE SYNCRONIZED....
BNE RADQ2 ;...THEN SKIP TO PASS CHAR
LDA SYNO ;THROWS OUT DATA UNTILL BLOCK SYNC...
BEQ RDBK2 ;...NO BLOCK SYNC
STA RER ;FLAG DATA AS ERROR
LDA #0 ;KILL 16 SYNC FLAG
STA SYNO
LDA #$81 ;SET UP FOR TIMER1 INTERRUPTS
STA D1ICR
STA SNSW1 ;FLAG THAT WE HAVE BYTE SYNCRONIZED
;
RADQ2 LDA SYNO ;SAVE SYNO STATUS
STA DIFF
BEQ RADK ;NO BLOCK SYNC, NO BYTE LOOKING
LDA #0 ;TURN OFF BYTE SYNC SWITCH
STA SNSW1
LDA #$01 ;DISABLE TIMER1 INTERRUPTS
STA D1ICR
RADK LDA MYCH ;PASS CHARACTER TO BYTE ROUTINE
STA OCHAR
LDA RER ;COMBINE ERROR VALUES WITH ZERO COUNT...
ORA REZ
STA PRP ;...AND SAVE IN PRP
RDBK2 JMP PREND ;GO BACK AND GET LAST BYTE
.SKI 2
RADJ JSR NEWCH ;FINISH BYTE, CLR FLAGS
STA DPSW ;CLEAR BIT THROW AWAY FLAG
LDX #218 ;INITILIZE FOR NEXT DIPOLE
JSR STT1
LDA FSBLK ;CHECK FOR LAST VALUE
BEQ RD15
STA SHCNL
.PAG 'BYTE HANDLER'
;*************************************************
;* BYTE HANDLER OF CASSETTE READ *
;* *
;* THIS PORTION OF IN LINE CODE IS PASSED THE *
;* BYTE ASSEMBLED FROM READING TAPE IN OCHAR. *
;* RER IS SET IF THE BYTE READ IS IN ERROR. *
;* REZ IS SET IF THE INTERRUPT PROGRAM IS READING*
;* ZEROS. RDFLG TELLS US WHAT WE ARE DOING. *
;* BIT 7 SAYS TO IGNORE BYTES UNTIL REZ IS SET *
;* BIT 6 SAYS TO LOAD THE BYTE. OTHERWISE RDFLG *
;* IS A COUNTDOWN AFTER SYNC. IF VERCK IS SET *
;* WE DO A COMPARE INSTEAD OF A STORE AND SET *
;* STATUS. FSBLK COUNTS THE TWO BLOCKS. PTR1 IS *
;* INDEX TO ERROR TABLE FOR PASS1. PTR2 IS INDEX*
;* TO CORRECTION TABLE FOR PASS2. *
;*************************************************
;
SPERR=16
CKERR=32
SBERR=4
LBERR=8
;
RD15 LDA #$F
;
BIT RDFLG ;TEST FUNCTION MODE
BPL RD20 ;NOT WAITING FOR ZEROS
;
LDA DIFF ;ZEROS YET?
BNE RD12 ;YES...WAIT FOR SYNC
LDX FSBLK ;IS PASS OVER?
DEX ;...IF FSBLK ZERO THEN NO ERROR (FIRST GOOD)
BNE RD10 ;NO...
;
LDA #LBERR
JSR UDST ;YES...LONG BLOCK ERROR
BNE RD10 ;BRANCH ALWAYS
;
RD12 LDA #0
STA RDFLG ;NEW MODE IS WAIT FOR SYNC
RD10 JMP PREND ;EXIT...DONE
;
RD20 BVS RD60 ;WE ARE LOADING
BNE RD200 ;WE ARE SYNCING
;
LDA DIFF ;DO WE HAVE BLOCK SYNC...
BNE RD10 ;...YES, EXIT
LDA PRP ;IF FIRST BYTE HAS ERROR...
BNE RD10 ;...THEN SKIP (EXIT)
LDA SHCNL ;MOVE FSBLK TO CARRY...
LSR A
LDA OCHAR ; SHOULD BE A HEADER COUNT CHAR
BMI RD22 ;IF NEG THEN FIRSTBLOCK DATA
BCC RD40 ;...EXPECTING FIRSTBLOCK DATA...YES
CLC
RD22 BCS RD40 ;EXPECTING SECOND BLOCK?...YES
AND #$F ;MASK OFF HIGH STORE HEADER COUNT...
STA RDFLG ;...IN MODE FLAG (HAVE CORRECT BLOCK)
RD200 DEC RDFLG ;WAIT UNTILL WE GET REAL DATA...
BNE RD10 ;...9876543210 REAL
LDA #$40 ;NEXT UP IS REAL DATA...
STA RDFLG ;...SET DATA MODE
JSR RD300 ;GO SETUP ADDRESS POINTERS
LDA #0 ;DEBUG CODE##################################################
STA SHCNH
BEQ RD10 ;JMP TO CONTINUE
.SKI 2
RD40 LDA #$80 ;WE WANT TO...
STA RDFLG ;IGNORE BYTES MODE
BNE RD10 ;JMP
.SKI 2
RD60 LDA DIFF ;CHECK FOR END OF BLOCK...
BEQ RD70 ;...OKAY
;
LDA #SBERR ;SHORT BLOCK ERROR
JSR UDST
LDA #0 ;FORCE RDFLG FOR AN END
JMP RD161
.SKI 2
RD70 JSR CMPSTE ;CHECK FOR END OF STORAGE AREA
BCC *+5 ;NOT DONE YET
JMP RD160
LDX SHCNL ;CHECK WHICH PASS...
DEX
BEQ RD58 ;...SECOND PASS
LDA VERCK ;CHECK IF LOAD OR VERIFY...
BEQ RD80 ;...LOADING
LDY #0 ;...JUST VERIFYING
LDA OCHAR
CMP (SAL)Y ;COMPARE WITH DATA IN PET
BEQ RD80 ;...GOOD SO CONTINUE
LDA #1 ;...BAD SO FLAG...
STA PRP ;...AS AN ERROR
.SKI 1
; STORE BAD LOCATIONS FOR SECOND PASS RE-TRY
RD80 LDA PRP ;CHK FOR ERRORS...
BEQ RD59 ;...NO ERRORS
LDX #61 ;MAX ALLOWED IS 30
CPX PTR1 ;ARE WE AT MAX?...
BCC RD55 ;...YES, FLAG AS SECOND PASS ERROR
LDX PTR1 ;GET INDEX INTO BAD...
LDA SAH ;...AND STORE THE BAD LOCATION
STA BAD+1,X ;...IN BAD TABLE
LDA SAL
STA BAD,X
INX ;ADVANCE POINTER TO NEXT
INX
STX PTR1
JMP RD59 ;GO STORE CHARACTER
.SKI 2
; CHECK BAD TABLE FOR RE-TRY (SECOND PASS)
RD58 LDX PTR2 ;HAVE WE DONE ALL IN THE TABLE?...
CPX PTR1
BEQ RD90 ;...YES
LDA SAL ;SEE IF THIS IS NEXT IN THE TABLE...
CMP BAD,X
BNE RD90 ;...NO
LDA SAH
CMP BAD+1,X
BNE RD90 ;...NO
INC PTR2 ;WE FOUND NEXT ONE, SO ADVANCE POINTER
INC PTR2
LDA VERCK ;DOING A LOAD OR VERIFY?...
BEQ RD52 ;...LOADING
LDA OCHAR ;...VERIFYING, SO CHECK
LDY #0
CMP (SAL)Y
BEQ RD90 ;...OKAY
INY ;MAKE .Y= 1
STY PRP ;FLAG IT AS AN ERROR
.SKI 2
RD52 LDA PRP ;A SECOND PASS ERROR?...
BEQ RD59 ;...NO
;SECOND PASS ERR
RD55 LDA #SPERR
JSR UDST
BNE RD90 ;JMP
.SKI 2
RD59 LDA VERCK ;LOAD OR VERIFY?...
BNE RD90 ;...VERIFY, DON'T STORE
TAY ;MAKE Y ZERO
LDA OCHAR
STA (SAL)Y ;STORE CHARACTER
RD90 JSR INCSAL ;INCREMENT ADDR.
BNE RD180 ;BRANCH ALWAYS
.SKI 3
RD160 LDA #$80 ;SET MODE SKIP NEXT DATA
RD161 STA RDFLG
;
; MODIFY FOR C64 6526'S
;
SEI ;PROTECT CLEARING OF T1 INFORMATION
LDX #$01
STX D1ICR ;CLEAR T1 ENABLE...
LDX D1ICR ;CLEAR THE INTERRUPT
LDX FSBLK ;DEC FSBLK FOR NEXT PASS...
DEX
BMI RD167 ;WE ARE DONE...FSBLK=0
STX FSBLK ;...ELSE FSBLK=NEXT
RD167 DEC SHCNL ;DEC PASS CALC...
BEQ RD175 ;...ALL DONE
LDA PTR1 ;CHECK FOR FIRST PASS ERRORS...
BNE RD180 ;...YES SO CONTINUE
STA FSBLK ;CLEAR FSBLK IF NO ERRORS...
BEQ RD180 ;JMP TO EXIT
.SKI 2
RD175 JSR TNIF ;READ IT ALL...EXIT
JSR RD300 ;RESTORE SAL & SAH
LDY #0 ;SET SHCNH TO ZERO...
STY SHCNH ;...USED TO CALC PARITY BYTE
;
;COMPUTE PARITY OVER LOAD
;
VPRTY LDA (SAL)Y ;CALC BLOCK BCC
EOR SHCNH
STA SHCNH
JSR INCSAL ;INCREMENT ADDRESS
JSR CMPSTE ;TEST AGAINST END
BCC VPRTY ;NOT DONE YET...
LDA SHCNH ;CHECK FOR BCC CHAR MATCH...
EOR OCHAR
BEQ RD180 ;...YES, EXIT
;CHKSUM ERROR
LDA #CKERR
JSR UDST
RD180 JMP PREND
.SKI 4
RD300 LDA STAH ; RESTORE STARTING ADDRESS...
STA SAH ;...POINTERS (SAH & SAL)
LDA STAL
STA SAL
RTS
.SKI 4
NEWCH LDA #8 ;SET UP FOR 8 BITS+PARITY
STA PCNTR
LDA #0 ;INITILIZE...
STA FIRT ;..DIPOLE COUNTER
STA RER ;..ERROR FLAG
STA PRTY ;..PARITY BIT
STA REZ ;..ZERO COUNT
RTS ;.A=0 ON RETURN
.END
; RSR 7/31/80 ADD COMMENTS
; RSR 3/28/82 MODIFY FOR C64 (ADD STUPID/COMMENTS)
; RSR 3/29/82 PUT BLOCK T1IRQ CONTROL
; RSR 5/11/82 MODIFY C64 STUPID CODE