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.

413 lines
13KB

  1. .PAGE 'CASSETTE READ'
  2. ; VARIABLES USED IN CASSETTE READ ROUTINES
  3. ;
  4. ; REZ - COUNTS ZEROS (IF Z THEN CORRECT # OF DIPOLES)
  5. ; RER - FLAGS ERRORS (IF Z THEN NO ERROR)
  6. ; DIFF - USED TO PRESERVE SYNO (OUTSIDE OF BIT ROUTINES)
  7. ; SYNO - FLAGS IF WE HAVE BLOCK SYNC (16 ZERO DIPOLES)
  8. ; SNSW1 - FLAGS IF WE HAVE BYTE SYNC (A LONGLONG)
  9. ; DATA - HOLDS MOST RECENT DIPOLE BIT VALUE
  10. ; MYCH - HOLDS INPUT BYTE BEING BUILT
  11. ; FIRT - USED TO INDICATE WHICH HALF OF DIPOLE WE'RE IN
  12. ; SVXT - TEMP USED TO ADJUST SOFTWARE SERVO
  13. ; TEMP - USED TO HOLD DIPOLE TIME DURING TYPE CALCULATIONS
  14. ; PRTY - HOLDS CURRENT CALCULATED PARITY BIT
  15. ; PRP - HAS COMBINED ERROR VALUES FROM BIT ROUTINES
  16. ; FSBLK - INDICATE WHICH BLOCK WE'RE LOOKING AT (0 TO EXIT)
  17. ; SHCNL - HOLDS FSBLK, USED TO DIRECT ROUTINES, BECAUSE OF EXIT CASE
  18. ; RDFLG - HOLDS FUNCTION MODE
  19. ; MI - WAITING FOR BLOCK SYNC
  20. ; VS - IN DATA BLOCK READING DATA
  21. ; NE - WAITING FOR BYTE SYNC
  22. ; SAL - INDIRECT TO DATA STORAGE AREA
  23. ; SHCNH - LEFT OVER FROM DEBUGGING
  24. ; BAD - STORAGE SPACE FOR BAD READ LOCATIONS (BOTTOM OF STACK)
  25. ; PTR1 - COUNT OF READ LOCATIONS IN ERROR (POINTER INTO BAD, MAX 61)
  26. ; PTR2 - COUNT OF RE-READ LOCATIONS (POINTER INTO BAD, DURING RE-READ)
  27. ; VERCHK - VERIFY OR LOAD FLAG (Z - LOADING)
  28. ; CMP0 - SOFTWARE SERVO (+/- ADJUST TO TIME CALCS)
  29. ; DPSW - IF NZ THEN EXPECTING LL/L COMBINATION THAT ENDS A BYTE
  30. ; PCNTR - COUNTS DOWN FROM 8-0 FOR DATA THEN TO FF FOR PARITY
  31. ; STUPID - HOLD INDICATOR (NZ - NO T1IRQ YET) FOR T1IRQ
  32. ; KIKA26 - HOLDS OLD D1ICR AFTER CLEAR ON READ
  33. ;
  34. .PAG 'CASSETTE READ'
  35. READ LDX D1T2H ;GET TIME SINCE LAST INTERRUPT
  36. LDY #$FF ;COMPUTE COUNTER DIFFERENCE
  37. TYA
  38. SBC D1T2L
  39. CPX D1T2H ;CHECK FOR TIMER HIGH ROLLOVER...
  40. BNE READ ;...YES THEN RECOMPUTE
  41. STX TEMP
  42. TAX
  43. STY D1T2L ;RELOAD TIMER2 (COUNT DOWN FROM $FFFF)
  44. STY D1T2H
  45. LDA #$19 ;ENABLE TIMER
  46. STA D1CRB
  47. LDA D1ICR ;CLEAR READ INTERRUPT
  48. STA KIKA26 ;SAVE FOR LATTER
  49. TYA
  50. SBC TEMP ;CALCULATE HIGH
  51. STX TEMP
  52. LSR A ;MOVE TWO BITS FROM HIGH TO TEMP
  53. ROR TEMP
  54. LSR A
  55. ROR TEMP
  56. LDA CMP0 ;CALC MIN PULSE VALUE
  57. CLC
  58. ADC #60
  59. CMP TEMP ;IF PULSE LESS THAN MIN...
  60. BCS RDBK ;...THEN IGNORE AS NOISE
  61. LDX DPSW ;CHECK IF LAST BIT...
  62. BEQ RJDJ ;...NO THEN CONTINUE
  63. JMP RADJ ;...YES THEN GO FINISH BYTE
  64. .SKI 2
  65. RJDJ LDX PCNTR ;IF 9 BITS READ...
  66. BMI JRAD2 ;... THEN GOTO ENDING
  67. LDX #0 ;SET BIT VALUE TO ZERO
  68. ADC #48 ;ADD UP TO HALF WAY BETWEEN...
  69. ADC CMP0 ;...SHORT PULSE AND SYNC PULSE
  70. CMP TEMP ;CHECK FOR SHORT...
  71. BCS RADX2 ;...YES IT'S A SHORT
  72. INX ;SET BIT VALUE TO ONE
  73. ADC #38 ;MOVE TO MIDDLE OF HIGH
  74. ADC CMP0
  75. CMP TEMP ;CHECK FOR ONE...
  76. BCS RADL ;...YES IT'S A ONE
  77. ADC #44 ;MOVE TO LONGLONG
  78. ADC CMP0
  79. CMP TEMP ;CHECK FOR LONGLONG...
  80. BCC SRER ;...GREATER THAN IS ERROR
  81. JRAD2 JMP RAD2 ;...IT'S A LONGLONG
  82. .SKI 2
  83. SRER LDA SNSW1 ;IF NOT SYNCRONIZED...
  84. BEQ RDBK ;...THEN NO ERROR
  85. STA RER ;...ELSE FLAG RER
  86. BNE RDBK ;JMP
  87. .SKI 2
  88. RADX2 INC REZ ;COUNT REZ UP ON ZEROS
  89. BCS RAD5 ;JMP
  90. RADL DEC REZ ;COUNT REZ DOWN ON ONES
  91. RAD5 SEC ;CALC ACTUAL VALUE FOR COMPARE STORE
  92. SBC #19
  93. SBC TEMP ;SUBTRACT INPUT VALUE FROM CONSTANT...
  94. ADC SVXT ;...ADD DIFFERENCE TO TEMP STORAGE...
  95. STA SVXT ;...USED LATER TO ADJUST SOFT SERVO
  96. LDA FIRT ;FLIP DIPOLE FLAG
  97. EOR #1
  98. STA FIRT
  99. BEQ RAD3 ;SECOND HALF OF DIPOLE
  100. STX DATA ;FIRST HALF SO STORE ITS VALUE
  101. .SKI 3
  102. RDBK LDA SNSW1 ;IF NO BYTE START...
  103. BEQ RADBK ;...THEN RETURN
  104. LDA KIKA26 ;CHECK TO SEE IF TIMER1 IRQD US...
  105. AND #$01
  106. BNE RADKX ;...YES
  107. LDA STUPID ;CHECK FOR OLD T1IRQ
  108. BNE RADBK ;NO...SO EXIT
  109. ;
  110. RADKX LDA #0 ;...YES, SET DIPOLE FLAG FOR FIRST HALF
  111. STA FIRT
  112. STA STUPID ;SET T1IRQ FLAG
  113. LDA PCNTR ;CHECK WHERE WE ARE IN BYTE...
  114. BPL RAD4 ;...DOING DATA
  115. BMI JRAD2 ;...PROCESS PARITY
  116. .SKI 2
  117. RADP LDX #166 ;SET UP FOR LONGLONG TIMEOUT
  118. JSR STT1
  119. LDA PRTY ;IF PARITY NOT EVEN...
  120. BNE SRER ;...THEN GO SET ERROR
  121. RADBK JMP PREND ;GO RESTORE REGS AND RTI
  122. .SKI 3
  123. RAD3 LDA SVXT ;ADJUST THE SOFTWARE SERVO (CMP0)
  124. BEQ ROUT1 ;NO ADJUST
  125. BMI ROUT2 ;ADJUST FOR MORE BASE TIME
  126. DEC CMP0 ;ADJUST FOR LESS BASE TIME
  127. .BYT $2C ;SKIP TWO BYTES
  128. ROUT2 INC CMP0
  129. ROUT1 LDA #0 ;CLEAR DIFFERENCE VALUE
  130. STA SVXT
  131. ;CHECK FOR CONSECUTIVE LIKE VALUES IN DIPOLE...
  132. CPX DATA
  133. BNE RAD4 ;...NO, GO PROCESS INFO
  134. TXA ;...YES SO CHECK THE VALUES...
  135. BNE SRER ;IF THEY WERE ONES THEN ERROR
  136. ; CONSECUTIVE ZEROS
  137. LDA REZ ;...CHECK HOW MANY ZEROS HAVE HAPPENED
  138. BMI RDBK ;...IF MANY DON'T CHECK
  139. CMP #16 ;... DO WE HAVE 16 YET?...
  140. BCC RDBK ;....NO SO CONTINUE
  141. STA SYNO ;....YES SO FLAG SYNO (BETWEEN BLOCKS)
  142. BCS RDBK ;JMP
  143. .SKI 3
  144. RAD4 TXA ;MOVE READ DATA TO .A
  145. EOR PRTY ;CALCULATE PARITY
  146. STA PRTY
  147. LDA SNSW1 ;REAL DATA?...
  148. BEQ RADBK ;...NO SO FORGET BY EXITING
  149. DEC PCNTR ;DEC BIT COUNT
  150. BMI RADP ;IF MINUS THEN TIME FOR PARITY
  151. LSR DATA ;SHIFT BIT FROM DATA...
  152. ROR MYCH ;...INTO BYTE STORAGE (MYCH) BUFFER
  153. LDX #218 ;SET UP FOR NEXT DIPOLE
  154. JSR STT1
  155. JMP PREND ;RESTORE REGS AND RTI
  156. .SKI 3
  157. ; RAD2 - LONGLONG HANDLER (COULD BE A LONG ONE)
  158. RAD2 LDA SYNO ;HAVE WE GOTTEN BLOCK SYNC...
  159. BEQ RAD2Y ;...NO
  160. LDA SNSW1 ;CHECK IF WE'VE HAD A REAL BYTE START...
  161. BEQ RAD2X ;...NO
  162. RAD2Y LDA PCNTR ;ARE WE AT END OF BYTE...
  163. BMI RAD2X ;YES...GO ADJUST FOR LONGLONG
  164. JMP RADL ;...NO SO TREAT IT AS A LONG ONE READ
  165. .SKI 2
  166. RAD2X LSR TEMP ;ADJUST TIMEOUT FOR...
  167. LDA #147 ;...LONGLONG PULSE VALUE
  168. SEC
  169. SBC TEMP
  170. ADC CMP0
  171. ASL A
  172. TAX ;AND SET TIMEOUT FOR LAST BIT
  173. JSR STT1
  174. INC DPSW ;SET BIT THROW AWAY FLAG
  175. LDA SNSW1 ;IF BYTE SYNCRONIZED....
  176. BNE RADQ2 ;...THEN SKIP TO PASS CHAR
  177. LDA SYNO ;THROWS OUT DATA UNTILL BLOCK SYNC...
  178. BEQ RDBK2 ;...NO BLOCK SYNC
  179. STA RER ;FLAG DATA AS ERROR
  180. LDA #0 ;KILL 16 SYNC FLAG
  181. STA SYNO
  182. LDA #$81 ;SET UP FOR TIMER1 INTERRUPTS
  183. STA D1ICR
  184. STA SNSW1 ;FLAG THAT WE HAVE BYTE SYNCRONIZED
  185. ;
  186. RADQ2 LDA SYNO ;SAVE SYNO STATUS
  187. STA DIFF
  188. BEQ RADK ;NO BLOCK SYNC, NO BYTE LOOKING
  189. LDA #0 ;TURN OFF BYTE SYNC SWITCH
  190. STA SNSW1
  191. LDA #$01 ;DISABLE TIMER1 INTERRUPTS
  192. STA D1ICR
  193. RADK LDA MYCH ;PASS CHARACTER TO BYTE ROUTINE
  194. STA OCHAR
  195. LDA RER ;COMBINE ERROR VALUES WITH ZERO COUNT...
  196. ORA REZ
  197. STA PRP ;...AND SAVE IN PRP
  198. RDBK2 JMP PREND ;GO BACK AND GET LAST BYTE
  199. .SKI 2
  200. RADJ JSR NEWCH ;FINISH BYTE, CLR FLAGS
  201. STA DPSW ;CLEAR BIT THROW AWAY FLAG
  202. LDX #218 ;INITILIZE FOR NEXT DIPOLE
  203. JSR STT1
  204. LDA FSBLK ;CHECK FOR LAST VALUE
  205. BEQ RD15
  206. STA SHCNL
  207. .PAG 'BYTE HANDLER'
  208. ;*************************************************
  209. ;* BYTE HANDLER OF CASSETTE READ *
  210. ;* *
  211. ;* THIS PORTION OF IN LINE CODE IS PASSED THE *
  212. ;* BYTE ASSEMBLED FROM READING TAPE IN OCHAR. *
  213. ;* RER IS SET IF THE BYTE READ IS IN ERROR. *
  214. ;* REZ IS SET IF THE INTERRUPT PROGRAM IS READING*
  215. ;* ZEROS. RDFLG TELLS US WHAT WE ARE DOING. *
  216. ;* BIT 7 SAYS TO IGNORE BYTES UNTIL REZ IS SET *
  217. ;* BIT 6 SAYS TO LOAD THE BYTE. OTHERWISE RDFLG *
  218. ;* IS A COUNTDOWN AFTER SYNC. IF VERCK IS SET *
  219. ;* WE DO A COMPARE INSTEAD OF A STORE AND SET *
  220. ;* STATUS. FSBLK COUNTS THE TWO BLOCKS. PTR1 IS *
  221. ;* INDEX TO ERROR TABLE FOR PASS1. PTR2 IS INDEX*
  222. ;* TO CORRECTION TABLE FOR PASS2. *
  223. ;*************************************************
  224. ;
  225. SPERR=16
  226. CKERR=32
  227. SBERR=4
  228. LBERR=8
  229. ;
  230. RD15 LDA #$F
  231. ;
  232. BIT RDFLG ;TEST FUNCTION MODE
  233. BPL RD20 ;NOT WAITING FOR ZEROS
  234. ;
  235. LDA DIFF ;ZEROS YET?
  236. BNE RD12 ;YES...WAIT FOR SYNC
  237. LDX FSBLK ;IS PASS OVER?
  238. DEX ;...IF FSBLK ZERO THEN NO ERROR (FIRST GOOD)
  239. BNE RD10 ;NO...
  240. ;
  241. LDA #LBERR
  242. JSR UDST ;YES...LONG BLOCK ERROR
  243. BNE RD10 ;BRANCH ALWAYS
  244. ;
  245. RD12 LDA #0
  246. STA RDFLG ;NEW MODE IS WAIT FOR SYNC
  247. RD10 JMP PREND ;EXIT...DONE
  248. ;
  249. RD20 BVS RD60 ;WE ARE LOADING
  250. BNE RD200 ;WE ARE SYNCING
  251. ;
  252. LDA DIFF ;DO WE HAVE BLOCK SYNC...
  253. BNE RD10 ;...YES, EXIT
  254. LDA PRP ;IF FIRST BYTE HAS ERROR...
  255. BNE RD10 ;...THEN SKIP (EXIT)
  256. LDA SHCNL ;MOVE FSBLK TO CARRY...
  257. LSR A
  258. LDA OCHAR ; SHOULD BE A HEADER COUNT CHAR
  259. BMI RD22 ;IF NEG THEN FIRSTBLOCK DATA
  260. BCC RD40 ;...EXPECTING FIRSTBLOCK DATA...YES
  261. CLC
  262. RD22 BCS RD40 ;EXPECTING SECOND BLOCK?...YES
  263. AND #$F ;MASK OFF HIGH STORE HEADER COUNT...
  264. STA RDFLG ;...IN MODE FLAG (HAVE CORRECT BLOCK)
  265. RD200 DEC RDFLG ;WAIT UNTILL WE GET REAL DATA...
  266. BNE RD10 ;...9876543210 REAL
  267. LDA #$40 ;NEXT UP IS REAL DATA...
  268. STA RDFLG ;...SET DATA MODE
  269. JSR RD300 ;GO SETUP ADDRESS POINTERS
  270. LDA #0 ;DEBUG CODE##################################################
  271. STA SHCNH
  272. BEQ RD10 ;JMP TO CONTINUE
  273. .SKI 2
  274. RD40 LDA #$80 ;WE WANT TO...
  275. STA RDFLG ;IGNORE BYTES MODE
  276. BNE RD10 ;JMP
  277. .SKI 2
  278. RD60 LDA DIFF ;CHECK FOR END OF BLOCK...
  279. BEQ RD70 ;...OKAY
  280. ;
  281. LDA #SBERR ;SHORT BLOCK ERROR
  282. JSR UDST
  283. LDA #0 ;FORCE RDFLG FOR AN END
  284. JMP RD161
  285. .SKI 2
  286. RD70 JSR CMPSTE ;CHECK FOR END OF STORAGE AREA
  287. BCC *+5 ;NOT DONE YET
  288. JMP RD160
  289. LDX SHCNL ;CHECK WHICH PASS...
  290. DEX
  291. BEQ RD58 ;...SECOND PASS
  292. LDA VERCK ;CHECK IF LOAD OR VERIFY...
  293. BEQ RD80 ;...LOADING
  294. LDY #0 ;...JUST VERIFYING
  295. LDA OCHAR
  296. CMP (SAL)Y ;COMPARE WITH DATA IN PET
  297. BEQ RD80 ;...GOOD SO CONTINUE
  298. LDA #1 ;...BAD SO FLAG...
  299. STA PRP ;...AS AN ERROR
  300. .SKI 1
  301. ; STORE BAD LOCATIONS FOR SECOND PASS RE-TRY
  302. RD80 LDA PRP ;CHK FOR ERRORS...
  303. BEQ RD59 ;...NO ERRORS
  304. LDX #61 ;MAX ALLOWED IS 30
  305. CPX PTR1 ;ARE WE AT MAX?...
  306. BCC RD55 ;...YES, FLAG AS SECOND PASS ERROR
  307. LDX PTR1 ;GET INDEX INTO BAD...
  308. LDA SAH ;...AND STORE THE BAD LOCATION
  309. STA BAD+1,X ;...IN BAD TABLE
  310. LDA SAL
  311. STA BAD,X
  312. INX ;ADVANCE POINTER TO NEXT
  313. INX
  314. STX PTR1
  315. JMP RD59 ;GO STORE CHARACTER
  316. .SKI 2
  317. ; CHECK BAD TABLE FOR RE-TRY (SECOND PASS)
  318. RD58 LDX PTR2 ;HAVE WE DONE ALL IN THE TABLE?...
  319. CPX PTR1
  320. BEQ RD90 ;...YES
  321. LDA SAL ;SEE IF THIS IS NEXT IN THE TABLE...
  322. CMP BAD,X
  323. BNE RD90 ;...NO
  324. LDA SAH
  325. CMP BAD+1,X
  326. BNE RD90 ;...NO
  327. INC PTR2 ;WE FOUND NEXT ONE, SO ADVANCE POINTER
  328. INC PTR2
  329. LDA VERCK ;DOING A LOAD OR VERIFY?...
  330. BEQ RD52 ;...LOADING
  331. LDA OCHAR ;...VERIFYING, SO CHECK
  332. LDY #0
  333. CMP (SAL)Y
  334. BEQ RD90 ;...OKAY
  335. INY ;MAKE .Y= 1
  336. STY PRP ;FLAG IT AS AN ERROR
  337. .SKI 2
  338. RD52 LDA PRP ;A SECOND PASS ERROR?...
  339. BEQ RD59 ;...NO
  340. ;SECOND PASS ERR
  341. RD55 LDA #SPERR
  342. JSR UDST
  343. BNE RD90 ;JMP
  344. .SKI 2
  345. RD59 LDA VERCK ;LOAD OR VERIFY?...
  346. BNE RD90 ;...VERIFY, DON'T STORE
  347. TAY ;MAKE Y ZERO
  348. LDA OCHAR
  349. STA (SAL)Y ;STORE CHARACTER
  350. RD90 JSR INCSAL ;INCREMENT ADDR.
  351. BNE RD180 ;BRANCH ALWAYS
  352. .SKI 3
  353. RD160 LDA #$80 ;SET MODE SKIP NEXT DATA
  354. RD161 STA RDFLG
  355. ;
  356. ; MODIFY FOR C64 6526'S
  357. ;
  358. SEI ;PROTECT CLEARING OF T1 INFORMATION
  359. LDX #$01
  360. STX D1ICR ;CLEAR T1 ENABLE...
  361. LDX D1ICR ;CLEAR THE INTERRUPT
  362. LDX FSBLK ;DEC FSBLK FOR NEXT PASS...
  363. DEX
  364. BMI RD167 ;WE ARE DONE...FSBLK=0
  365. STX FSBLK ;...ELSE FSBLK=NEXT
  366. RD167 DEC SHCNL ;DEC PASS CALC...
  367. BEQ RD175 ;...ALL DONE
  368. LDA PTR1 ;CHECK FOR FIRST PASS ERRORS...
  369. BNE RD180 ;...YES SO CONTINUE
  370. STA FSBLK ;CLEAR FSBLK IF NO ERRORS...
  371. BEQ RD180 ;JMP TO EXIT
  372. .SKI 2
  373. RD175 JSR TNIF ;READ IT ALL...EXIT
  374. JSR RD300 ;RESTORE SAL & SAH
  375. LDY #0 ;SET SHCNH TO ZERO...
  376. STY SHCNH ;...USED TO CALC PARITY BYTE
  377. ;
  378. ;COMPUTE PARITY OVER LOAD
  379. ;
  380. VPRTY LDA (SAL)Y ;CALC BLOCK BCC
  381. EOR SHCNH
  382. STA SHCNH
  383. JSR INCSAL ;INCREMENT ADDRESS
  384. JSR CMPSTE ;TEST AGAINST END
  385. BCC VPRTY ;NOT DONE YET...
  386. LDA SHCNH ;CHECK FOR BCC CHAR MATCH...
  387. EOR OCHAR
  388. BEQ RD180 ;...YES, EXIT
  389. ;CHKSUM ERROR
  390. LDA #CKERR
  391. JSR UDST
  392. RD180 JMP PREND
  393. .SKI 4
  394. RD300 LDA STAH ; RESTORE STARTING ADDRESS...
  395. STA SAH ;...POINTERS (SAH & SAL)
  396. LDA STAL
  397. STA SAL
  398. RTS
  399. .SKI 4
  400. NEWCH LDA #8 ;SET UP FOR 8 BITS+PARITY
  401. STA PCNTR
  402. LDA #0 ;INITILIZE...
  403. STA FIRT ;..DIPOLE COUNTER
  404. STA RER ;..ERROR FLAG
  405. STA PRTY ;..PARITY BIT
  406. STA REZ ;..ZERO COUNT
  407. RTS ;.A=0 ON RETURN
  408. .END
  409. ; RSR 7/31/80 ADD COMMENTS
  410. ; RSR 3/28/82 MODIFY FOR C64 (ADD STUPID/COMMENTS)
  411. ; RSR 3/29/82 PUT BLOCK T1IRQ CONTROL
  412. ; RSR 5/11/82 MODIFY C64 STUPID CODE