-
Notifications
You must be signed in to change notification settings - Fork 0
/
lowlevrw.asm
executable file
·939 lines (936 loc) · 24.1 KB
/
lowlevrw.asm
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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
#INCLUDE "MOTO.H"
***************************
* DISC-II *
* 13-SECTOR FORMAT *
* READ AND WRITE *
* SUBROUTINES *
* *
***************************
* *
* *
* COPYRIGHT 1978 *
* APPLE COMPUTER INC. *
* *
* ALL RIGHTS RESERVED *
* *
***************************
* *
* MAY 25, 1978 *
* WOZ *
* R. WIGGINTON *
* *
***************************
EJECT
***************************
* *
* CRITICAL TIMING *
* REQUIRES PAGE BOUND *
* CONSIDERATIONS FOR *
* CODE AND DATA *
* *
* -----CODE----- *
* *
* VIRTUALLY THE ENTIRE *
* 'WRITE' ROUTINE *
* MUST NOT CROSS *
* PAGE BOUNDARIES. *
* *
* CRITICAL BRANCHES IN *
* THE 'WRITE', 'READ', *
* AND 'READ ADR' SUBRS *
* WHICH MUST NOT CROSS *
* PAGE BOUNDARIES ARE *
* NOTED IN COMMENTS. *
* *
* -----DATA----- *
* *
* NBUF1, NBUF2, NBUF3, *
* NBUF4, AND NBUF5 ARE *
* 51-BYTE RAM BUFFERS *
* WHICH SHOULD ALL BE *
* LOCATED ON A SINGLE *
* PAGE BEGINNING WITH *
* NBUF1. (NBUF5 IS 52). *
* *
* NBUF6, NBUF7, AND *
* NBUF8 MUST NOT CROSS *
* PAGE BOUNDARIES AND *
* SHOULD BE LOCATED *
* ON A PAGE BEGINNING *
* WITH NBUF6. NBUF6 *
* AND NBUF7 ARE 51 BYTES *
* WHILE NBUF8 IS 52. *
* *
* NIBLIZING TABLE 'NIBL' *
* (32 BYTES) MUST NOT *
* CROSS PAGE BOUNDARY. *
* CONVERTS 5-BIT NIBLS *
* TO 7-BIT NIBLS. *
* *
* DENIBLIZING TABLE *
* 'DNIBL' MUST BE ON A *
* PAGE BOUNDARY, BUT *
* ONLY DNIBL,$AB TO *
* DNIBL,$FF NEED BE *
* USED. CONVERTS 7-BIT *
* NIBLS TO 5-BIT NIBLS. *
* *
***************************
EJECT
***************************
* *
* EQUATES *
* *
***************************
* *
* -----PRENIBL---- *
* AND POSTNIBL *
* *
***************************
BUF EQU $3E ;TWO BYTE POINTER.
*
* POINTS TO 256-BYTE
* USER BUFFER ANYWHERE
* IN MEMORY. PRENIBL
* CONVERTS USER DATA
* (IN BUF) INTO 5-BIT
* NIBLS 000ABCDE IN
* NBUF1 THROUGH NBUF8
* PRIOR TO 'WRITE'.
* POSTNIBL CONVERTS
* 5-BIT NIBLS ABCDE000
* BACK TO USER DATA
* (IN BUF) AFTER 'READ'.
*
NBUF1 EQU $3B00
NBUF2 EQU $3B33 ;OBSERVE THESE
NBUF3 EQU $3B66 ;PLACEMENTS
NBUF4 EQU $3B99 ;RELATIVE TO
NBUF5 EQU $3BCC ;PAGE STARTS!
NBUF6 EQU $3C00
NBUF7 EQU $3C33
NBUF8 EQU $3C66 ;(TO $BC99)
*
T0 EQU $26 ;TEMPS USED BY PRENIBL
T1 EQU $27 ; AND POSTNIBL.
T2 EQU $2A ;TEMP USED BY PRENIBL.
*
************************
* *
* ----READADR---- *
* *
************************
COUNT EQU $26 ;'MUST FIND' COUNT.
LAST EQU $26 ;'ODD BIT' NIBLS.
CSUM EQU $27 ;CHECKSUM BYTE.
CSSTV EQU $2C ;FOUR BYTES,
* CHECKSUM, SECTOR, TRACK, AND VOLUME.
*
************************
* *
* ----WRITE---- *
* *
* USES ALL NBUFS *
* AND 32-BYTE *
* DATA TABLE 'NIBL' *
* *
************************
WTEMP EQU $26 ;TEMP FOR DATA AT NBUF6,0.
SLOTZ EQU $27 ;SLOTNUM IN Z-PAG LOC.
SLOTABS EQU $678 ;SLOTNUM IN NON-ZPAG LOC.
*
************************
* *
* -----READ---- *
* *
* USES ALL NBUFS *
* USES LAST 54 BYTES *
* OF A CODE PAGE FOR *
* USED BYTES OF DNIBL *
* TABLE. *
* *
************************
IDX EQU $26 ;INDEX INTO (BUF).
DNIBL EQU $3A00 ;7-BIT TO 5-BIT NIBLS.
*
************************
* *
* ---- SEEK ---- *
* *
************************
TRKCNT EQU $26 ;HALFTRKS MOVED COUNT.
PRIOR EQU $27 ;PRIOR HALFTRACK.
TRKN EQU $2A ;DESIRED TRACK.
SLOTTEMP EQU $2B ;SLOT NUM TIMES $10.
CURTRK EQU $478 ;CURRENT TRACK ON ENTYR.
*
************************
* *
* ---- MSWAIT ---- *
* *
************************
MONTIMEL EQU $46
MONTIMEH EQU $47
*
************************
* *
* DEVICE ADDRESS *
* ASSIGNMENTS *
* *
************************
PHASEOFF EQU $C080 ;STEPPER PHASE OFF.
PHASEON EQU $C081 ;STEPPER PHASE ON.
Q6L EQU $C08C ;Q7L,Q6L=READ
Q6H EQU $C08D ;Q7L,Q6H=SENSE WPROT
Q7L EQU $C08E ;Q7H,Q6L=WRITE
Q7H EQU $C08F ;Q7H,Q6H=WRITE STORE
EJECT
****************************
* *
* PRENIBLIZE SUBR *
* *
****************************
* *
* CONVERTS 256 BYTES OF *
* USER DATA IN (BUF),0 *
* TO (BUF),255 INTO 410 *
* 5-BIT NIBLS (000ABCDE) *
* IN NBUF1 THROUGH NBUF8. *
* *
* ---- ON ENTRY ---- *
* *
* BUF IS 2-BYTE POINTER *
* TO 256 BYTES OF USER *
* DATA. *
* *
* ---- ON EXIT ----- *
* *
* A-REG: UNCERTAIN. *
* X-REG: UNCERTAIN. *
* Y-REG: HOLDS $FF. *
* CARRY: UNCERTAIN. *
* *
* NBUF1 THROUGH NBUF8 *
* CONTAIN 5-BIT NIBLS *
* OF FORM 000ABCDE. *
* *
* TEMPS T0, T1, T2 USED. *
* *
****************************
ORG $3800
* OBJ $B800
PRENIBL LDX #$32 ;INDEX FOR (51) 5-BYTE PASSES.
LDY #$0 ;USER BUF INDEX.
PNIB1 LDA (BUF),Y ;FIRST OF 5 USER BYTES.
STA T0 ;(ONLY 3 LSB'S USED)
LSRA
LSRA ;5 MSB'S TO LOW BITS.
LSRA
STA NBUF1,X ;FIRST OF 8 5-BIT NIBLS.
INY
LDA (BUF),Y ;SECOND OF 5 USER BYTES.
STA T1 ;ONLY 3 LSB'S USED)
LSRA
LSRA ;5 MSB'S TO LOW BITS.
LSRA
STA NBUF2,X ;SECOND OF 8 5-BIT NIBLS.
INY
LDA (BUF),Y ;THIRD OF 5 USER BYTES.
STA T2 ;(ONLY 3 LSB'S USED)
LSRA
LSRA ;5 MSB'S TO LOW BITS.
LSRA
STA NBUF3,X ;THIRD OF 8 5-BIT NIBLS.
INY
LDA (BUF),Y ;FOURTH OF 5 USER BYTES.
LSRA
ROL T2 ;LSB INTO T2.
LSRA
ROL T1 ;NEXT LSB INTO T1.
LSRA
ROL T0 ;NEXT LSB INTO T0.
STA NBUF4,X ;FOURTH OF 8 5-BIT NIBLS.
INY
LDA (BUF),Y ;FIFTH OF 5 USER BYTES.
LSRA
ROL T2 ;LSB INTO T2.
LSRA
ROL T1 ;NEXT LSB INTO T1.
LSRA
STA NBUF5,X ;FIFTH OF 8 5-BIT NIBLS.
LDA T0
ROLA ;NEXT LSB.
AND #$1F ;TRUNCATE TO 5 BITS.
STA NBUF6,X ;SIXTH OF 8 5-BIT NIBLS.
LDA T1
AND #$1F ;TRUNCATE TO 5 BITS.
STA NBUF7,X ;SEVENTH OF 8 5-BIT NIBLS.
LDA T2
AND #$1F ;TRUNCATE TO 5 BITS.
STA NBUF8,X ;EIGHTH OF 8 5-BIT NIBLS.
INY
DEX ;NEXT OF (51) 5-BYTE PASSES.
BPL PNIB1
LDA (BUF),Y
TAX
AND #$7 ;3 LSB'S OF LAST
STA NBUF8+$33 ;USER BYTE.
TXA
LSRA
LSRA
LSRA ;5 MSB'S OF LAST
STA NBUF5+$33 ;USER BYTE.
RTS
EJECT
************************
* *
* WRITE SUBR *
* *
************************
* *
* WRITES DATA FROM *
* NBUF1 TO NBUF8 *
* CONVERTING 5-BIT *
* TO 7-BIT NIBLS *
* VIA 'NIBL' TABLE. :
* *
* FIRST, NBUF6 TO *
* NBUF8, HIGH TO LOW *
* THEN, NBUF1 TO *
* NBUF5, LOW TO HIGH *
* *
* ---- ON ENTRY ---- *
* *
* X-REG: SLOTNUM *
* TIMES $10. *
* *
* NBUF1 TO NBUF8 *
* HOLD NIBLS FROM *
* PRENIBL SUBR. *
* (000ABCDE) *
* *
* ---- ON EXIT ----- *
* *
* CARRY SET IF ERROR. *
* (W PROT VIOLATION) *
* *
* IF NO ERROR: *
* *
* A-REG: UNCERTAIN. *
* X-REG: UNCHANGED. *
* Y-REG: HOLDS $00. *
* CARRY CLEAR. *
* *
* SLOTABS, SLOTZ, *
* AND WTEMP USED. *
* *
* ---- ASSUMES ---- *
* *
* 1 USEC CYCLE TIME *
* *
************************
WRITE SEC ;ANTICIPATE WPROT ERR.
LDA Q6H,X
LDA Q7L,X ;SENSE WPROT FLAG.
BMI WEXIT ;IF HIGH, THEN ERR.
STX SLOTZ ;FOR ZERO PAGE ACCESS.
STX SLOTABS ;FOR NON-ZERO PAGE.
LDA NBUF6
STA WTEMP ;FOR ZERO-PAGE ACCESS.
LDA #$FF ;SYNC DATA.
STA Q7H,X ;(5) WRITE 1ST NIBL.
ORA Q6L,X ;(4)
PHA ;(3)
PLA ;(4) CRITICAL TIMING!
NOP ;(2)
LDY #$A ;(2) FOR 11 NIBLS.
WSYNC ORA WTEMP ;(3) FOR TIMING.
JSR WNIBL7 ;(13,9,6) WRITE SYNC.
DEY ;(2)
BNE WSYNC ;(2*) MUST NOT CROSS PAGE!
LDA #$D5 ;(2) 1ST DATA MARK.
JSR WNIBL9 ;(15,9,6)
LDA #$AA ;(2) 2ND DATA MARK.
JSR WNIBL9 ;(15,9,6)
LDA #$AD ;(2) 3RD DATA MARK.
JSR WNIBL9 ;(15,9,6)
TYA ;(2) CLEAR CHKSUM.
LDY #$9A ;(2) NBUF6-8 INDEX.
BNE WDATA1 ;(3) ALWAYS. NO PAGE CROSS!!
WDATA0 LDA NBUF6,Y ;(4) PRIOR 5-BIT NIBL.
WDATA1 EOR NBUF6-1,Y ;(5) XOR WITH CURRENT.
* (NBUF6 MUST BE ON PAGE BOUNDARY FOR TIMING!!)
TAX ;(2) INDEX TO 7-BIT NIBL.
LDA NIBL,X ;(4) MUST NOT CROSS PAGE!
LDX SLOTZ ;(3) CRITICAL TIMING!
STA Q6H,X ;(5) WRITE NIBL.
LDA Q6L,X ;(4)
DEY ;(2) NEXT NIBL.
BNE WDATA0 ;(2*) MUST NOT CROSS PAGE!
LDA WTEMP ;(3) PRIOR NIBL FROM BUF6.
NOP ;(2) CRITICAL TIMING.
WDATA2 EOR NBUF1,Y ;(4) XOR NBUF1 NIBL.
TAX ;(2) INDEX TO 7-BIT NIBL.
LDA NIBL,X ;(4)
LDX SLOTABS ;(4) TIMING CRITICAL.
STA Q6H,X ;(5) WRITE NIBL.
LDA Q6L,X ;(4)
LDA NBUF1,Y ;(4) PRIOR 5-BIT NIBL.
INY ;(2) NEXT NBUF1 NIBL.
BNE WDATA2 ;(2*) MUST NOT CROSS PAGE!
TAX ;(2) LAST NIBL AS CHKSUM.
LDA NIBL,X ;(4) INDEX TO 7-BIT NIBL.
LDX SLOTZ ;(3)
JSR WNIBL ;(6,9,6) WRITE CHKSUM.
LDA #$DE ;(2) DM4, BIT SLIP MARK.
JSR WNIBL9 ;(15,9,6) WRITE IT.
LDA #$AA ;(2) DM5, BIT SLIP MARK.
JSR WNIBL9 ;(15,9,6) WRITE IT.
LDA #$EB ;(2) DM6, BIT SLIP MARK.
JSR WNIBL9 ;(15,9,6) WRITE IT.
LDA Q7L,X ;OUT OF WRITE MODE.
WEXIT LDA Q6L,X ;TO READ MODE.
RTS ;RETURN FROM WRITE.
*****************************
* *
* 7-BIT NIBL WRITE SUBRS *
* *
* A-REG OR'D PRIOR EXIT *
* CARRY CLEARED *
* *
*****************************
WNIBL9 CLC ;(2) 9 CYCLES, THEN WRITE.
WNIBL7 PHA ;(3) 7 CYCLES, THEN WRITE.
PLA ;(4)
WNIBL STA Q6H,X ;(5) NIBL WRITE SUB.
ORA Q6L,X ;(4) CLOBBERS ACC, NOT CARRY.
RTS
EJECT
**************************
* *
* READ SUBROUTINE *
* *
**************************
* *
* READS 5-BIT NIBLS *
* (ABCDE000) INTO *
* NBUF1 THROUGH NBUF8 *
* CONVERTING 7-BIT *
* NIBLS TO 5-BIT *
* VIA 'DNIBL' TABLE *
* *
* FIRST READS NBUF6 TO *
* NBUF8 HIGH TO LOW, *
* THEN READS NBUF1 TO *
* NBUF5 LOW TO HIGH *
* *
* ---- ON ENTRY ---- *
* *
* X-REG: SLOTNUM *
* TIMES $10. *
* *
* READ MODE (Q6L, Q7L) *
* *
* ---- ON EXIT ----- *
* *
* CARRY SET IF ERROR. *
* *
* IF NO ERROR: *
* A-REG: HOLDS $AA *
* X-REG: UNCHANGED. *
* Y-REG: HOLDS $00 *
* CARRY CLEAR. *
* *
* NBUF1 TO NBUF8 *
* HOLD 5-BIT *
* NIBLS ABCDE000. *
* *
* USES TEMP 'IDX'. *
* *
* ---- CAUTION ----- *
* *
* OBSERVE *
* 'NO PAGE CROSS' *
* WARNINGS ON *
* SOME BRANCHES!! *
* *
* ---- ASSUMES ---- *
* *
* 1 USEC CYCLE TIME *
* *
**************************
READ LDY #$20 ;'MUST FIND' COUNT.
RSYNC DEY ;IF CAN'T FIND MARKS
BEQ RDERR ;THEN EXIT WITH CARRY SET.
RD1 LDA Q6L,X ;READ NIBL.
BPL RD1 ;*** NO PAGE CROSS! ***
RSYNC1 EOR #$D5 ;DATA MARK 1?
BNE RSYNC ;LOOP IF NOT.
NOP ;DELAY BETWEEN NIBLS.
RD2 LDA Q6L,X
BPL RD2 ;*** NO PAGE CROSS! ***
CMP #$AA ;DATA MARK 2?
BNE RSYNC1 ; (IF NOT, IS IT DM1?)
LDY #$9A ;INIT NBUF6 INDEX.
* (ADDED NIBL DELAY)
RD3 LDA Q6L,X
BPL RD3 ;*** NO PAGE CROSS! ***
CMP #$AD ;DATA MARK 3?
BNE RSYNC1 ; (IF NOT, IS IT DM1?)
* (CARRY SET IF DM3!)
LDA #$00 ;INIT CHECKSUM.
RDATA1 DEY
STY IDX
RD4 LDY Q6L,X
BPL RD4 ;*** NO PAGE CROSS! ***
EOR DNIBL,Y ;XOR 5-BIT NIBL.
LDY IDX
STA NBUF6,Y ;STORE IN NBUF6 PAGE.
BNE RDATA1 ;TAKEN IF Y-REG NONZERO.
RDATA2 STY IDX
RD5 LDY Q6L,X
BPL RD5 ;*** NO PAGE CROSS! ***
EOR DNIBL,Y ;XOR 5-BIT NIBL.
LDY IDX
STA NBUF1,Y ;STORE IN NBUF1 PAGE.
INY
BNE RDATA2
RD6 LDY Q6L,X ;READ 7-BIT CSUM NIBL.
BPL RD6 ;*** NO PAGE CROSS! ***
CMP DNIBL,Y ;IF LAST NBUF1 NIBL NOT
BNE RDERR ;EQUAL CHKSUM NIBL THEN ERR.
RD7 LDA Q6L,X
BPL RD7 ;*** NO PAGE CROSS! ***
CMP #$DE ;FIRST BIT SLIP MARK?
BNE RDERR ; (ERR IF NOT)
NOP ;DELAY BETWEEN NIBLS.
RD8 LDA Q6L,X
BPL RD8 ;*** NO PAGE CROSS! ***
CMP #$AA ;SECOND BIT SLIP MARK?
BEQ RDEXIT ; (DONE IF IT IS)
RDERR SEC ;INDICATE 'ERROR EXIT'.
RTS ;RETURN FROM READ OR READADR.
EJECT
****************************
* *
* READ ADDRESS FIELD *
* *
* SUBROUTINE *
* *
****************************
* *
* READS VOLUME, TRACK *
* AND SECTOR *
* *
* ---- ON ENTRY ---- *
* *
* XREG: SLOTNUM TIMES $10 *
* *
* READ MODE (Q6L, Q7L) *
* *
* ---- ON EXIT ----- *
* *
* CARRY SET IF ERROR. *
* *
* IF NO ERROR: *
* A-REG: HOLDS $AA. *
* Y-REG: HOLDS $00. *
* X-REG: UNCHANGED. *
* CARRY CLEAR. *
* *
* CSSTV HOLDS CHKSUM, *
* SECTOR, TRACK, AND *
* VOLUME READ. *
* *
* USES TEMPS COUNT, *
* LAST, CSUM, AND *
* 4 BYTES AT CSSTV. *
* *
* ---- EXPECTS ---- *
* *
* NORMAL DENSITY NIBLS *
* (4-BIT), ODD BITS, *
* THEN EVEN. *
* *
* ---- CAUTION ---- *
* *
* OBSERVE *
* 'NO PAGE CROSS' *
* WARNINGS ON *
* SOME BRANCHES!! *
* *
* ---- ASSUMES ---- *
* *
* 1 USEC CYCLE TIME *
* *
****************************
RDADR LDY #$F8
STY COUNT ;'MUST FIND' COUNT.
RDASYN INY
BNE RDA1 ;LOW ORDER OF COUNT.
INC COUNT ;(2K NIBLS TO FIND
BEQ RDERR ; ADR MARK, ELSE ERR)
RDA1 LDA Q6L,X ;READ NIBL.
BPL RDA1 ;*** NO PAGE CROSS! ***
RDASN1 CMP #$D5 ;ADR MARK 1?
BNE RDASYN ; (LOOP IF NOT)
NOP ;ADDED NIBL DELAY.
RDA2 LDA Q6L,X
BPL RDA2 ;*** NO PAGE CROSS! ***
CMP #$AA ;ADR MARK 2?
BNE RDASN1 ; (IF NOT, IS IT AM1?)
LDY #$3 ;INDEX FOR 4-BYTE READ.
* (ADDED NIBL DELAY)
RDA3 LDA Q6L,X
BPL RDA3 ;*** NO PAGE CROSS! ***
CMP #$B5 ;ADR MARK 3?
BNE RDASN1 ; (IF NOT, IS IT AM1?)
* (LEAVES CARRY SET!)
LDA #$0 ;INIT CHECKSUM.
RDAFLD STA CSUM
RDA4 LDA Q6L,X ;READ 'ODD BIT' NIBL.
BPL RDA4 ;*** NO PAGE CROSS! ***
ROLA ;ALIGN ODD BITS, '1' INTO LSB.
STA LAST ; (SAVE THEM)
RDA5 LDA Q6L,X ;READ 'EVEN BIT' NIBL.
BPL RDA5 ;*** NO PAGE CROSS! ***
AND LAST ;MERGE ODD AND EVEN BITS.
STA CSSTV,Y ;STORE DATA BYTE.
EOR CSUM ;XOR CHECKSUM.
DEY
BPL RDAFLD ;LOOP ON 4 DATA BYTES.
TAY ;IF FINAL CHECKSUM
BNE RDERR ; NONZERO, THEN ERROR.
RDA6 LDA Q6L,X ;FIRST BIT-SLIP NIBL.
BPL RDA6 ;*** NO PAGE CROSS! ***
CMP #$DE
BNE RDERR ;ERROR IF NONMATCH.
NOP ;DELAY BETWEEN NIBLS.
RDA7 LDA Q6L,X ;SECOND BIT-SLIP NIBL.
BPL RDA7 ;*** NO PAGE CROSS! ***
CMP #$AA
BNE RDERR ;ERROR IF NONMATCH.
RDEXIT CLC ;CLEAR CARRY ON
RTS ;NORMAL READ EXITS.
EJECT
***************************
* *
* POSTNIBLIZE SUBR *
* *
***************************
* *
* CONVERTS 5-BIT NIBLS *
* OF FORM ABCDE000 IN *
* NBUF1 THROUGH NBUF8 *
* INTO 256 BYTES OF *
* USER DATA IN BUF. *
* *
* ---- ON ENTRY ---- *
* *
* X-REG: HOLDS SLOTNUM *
* TIMES $10. *
* *
* BUF IS 2-BYTE POINTER *
* TO 256 BYTES OF USER *
* DATA TO BE CONVERTED *
* TO 5-BIT NIBLS IN *
* NBUF1 THROUGH NBUF8 *
* PRIOR TO WRITE. *
* *
* ---- ON EXIT ----- *
* *
* A-REG: UNCERTAIN. *
* Y-REG: HOLDS $FF. *
* X-REG: HOLDS $FF. *
* CARRY: UNCERTAIN. *
* *
* 5-BIT NIBLS OF FORM *
* 000ABCDE IN 410 *
* BYTES FROM NBUF1 *
* TO NBUF8. *
* *
***************************
POSTNIB LDX #$32 ;INDEX FOR 51 PASSES.
LDY #$0 ;INDEX TO USER BUF.
POSTNB1 LDA NBUF6,X
LSRA
LSRA
LSRA
STA T1
LSRA
STA T0
LSRA
ORA NBUF1,X
STA (BUF),Y ;FIRST OF 5 USER BYTES.
INY
LDA NBUF7,X
LSRA
LSRA
LSRA
LSRA
ROL T1
LSRA
ROL T0
ORA NBUF2,X
STA (BUF),Y ;SECOND OF 5 USER BYTES.
INY
LDA NBUF8,X
LSRA
LSRA
LSRA
LSRA
ROL T1
LSRA
ROL T0
ORA NBUF3,X
STA (BUF),Y ;THIRD OF 5 USER BYTES.
INY
LDA T0
AND #$7
ORA NBUF4,X
STA (BUF),Y ;FOURTH OF 5 USER BYTES.
INY
LDA T1
AND #$7
ORA NBUF5,X
STA (BUF),Y ;FIFTH OF 5 USER BYTES.
INY
DEX ;NEXT OF 51 PASSES.
BPL POSTNB1 ;HANDLE LAST USER
LDA NBUF8+$33 ; BYTE DIFFERENTLY.
LSRA
LSRA
LSRA
ORA NBUF5+$33
STA (BUF),Y
RTS
EJECT
**************************
* *
* FAST SEEK SUBROUTINE *
* *
**************************
* *
* ---- ON ENTRY ---- *
* *
* X-REG HOLDS SLOTNUM *
* TIMES $10. *
* *
* A-REG HOLDS DESIRED *
* HALFTRACK. *
* (SINGLE PHASE) *
* *
* CURTRK HOLDS CURRENT *
* HALFTRACK. *
* *
* ---- ON EXIT ----- *
* *
* A-REG UNCERTAIN. *
* Y-REG UNCERTAIN. *
* X-REG UNDISTURBED. *
* *
* CURTRK AND TRKN HOLD *
* FINAL HALFTRACK. *
* *
* PRIOR HOLDS PRIOR *
* HALFTRACK IF SEEK *
* WAS REQUIRED. *
* *
* MONTIMEL AND MONTIMEH *
* ARE INCREMENTED BY *
* THE NUMBER OF *
* 100 USEC QUANTUMS *
* REQUIRED BY SEEK *
* FOR MOTOR ON TIME *
* OVERLAP. *
* *
* --- VARIABLES USED --- *
* *
* CURTRK, TRKN, COUNT, *
* PRIOR, SLOTTEMP *
* MONTIMEL, MONTIMEH *
* *
**************************
SEEK STA TRKN ;TARGET TRACK.
CMP CURTRK ;ON DESIRED TRACK?
BEQ SEEKXIT ; YES, HIT IT AND RETURN.
STX SLOTTEMP ;SAVE X-REG.
LDA #$0
STA TRKCNT ;HALFTRACK COUNT.
SEEK2 LDA CURTRK ;SAVE CURTRK FOR
STA PRIOR ; DELAYED TURNOFF.
SEC
SBC TRKN ;DELTA-TRACKS.
BEQ SEEKEND ;DONE, FINISH SEEK.
BCS OUT ;(MOVE OUT, NOT IN)
EOR #$FF ;CALC TRKS TO GO.
INC CURTRK ;INCR CURRENT TRACK (IN).
BCC MINTST ;(ALWAYS TAKEN)
OUT ADC #$FE ;CALC TRKS TO GO.
DEC CURTRK ;DECR CURRENT TRACK (OUT).
MINTST CMP TRKCNT
BCC MAXTST ; AND 'TRKS MOVED'.
LDA TRKCNT
MAXTST CMP #$C
BCC STEP ;IF > $B, USE $B.
LDA #$B
STEP TAY ;ACCELLERATION INDEX.
LDA CURTRK
AND #$3 ;INDEX TO 'CURRENT
ASLA ; PHASE' OF 4-PHASE
ORA SLOTTEMP ; STEPPER.
TAX
LDA PHASEON,X ;HIT NEXT PHASE
LDA ONTABLE,Y ; FOR 'ONTIME'.
JSR MSWAIT ;(100 USEC INTERVALS)
LDA PRIOR
AND #$3 ;INDEX TO 'PRIOR PHASE'
ASLA ; OF 4-PHASE STEPPER.
ORA SLOTTEMP
TAX
LDA PHASEOFF,X ;PRIOR PHASE OFF,
LDA OFFTABLE,Y ; THEN WAIT 'OFFTIME'.
JSR MSWAIT ;(100 USEC INTERVALS)
INC TRKCNT ;'TRACKS MOVED' COUNT.
BNE SEEK2 ;(ALWAYS TAKEN)
SEEKEND LDA #$5F ;DELAY 9.5 MSEC FOR
JSR MSWAIT ; SETTLING TIME.
LDX SLOTTEMP ;RESTORE X-REG.
SEEKXIT RTS ;RETURN.
EJECT
**************************
* *
* MSWAIT SUBROUTINE *
* *
**************************
* *
* DELAYS A SPECIFIED *
* NUMBER OF 100 USEC *
* INTERVALS FOR MOTOR *
* ON TIMING. *
* *
* ---- ON ENTRY ---- *
* *
* A-REG: HOLDS NUMBER *
* OF 100 USEC *
* INTERVALS TO *
* DELAY. *
* *
* ---- ON EXIT ----- *
* *
* A-REG: HOLDS $00. *
* X-REG: HOLDS $00. *
* Y-REG: UNCHANGED. *
* CARRY: SET. *
* *
* MONTIMEL, MONTIMEH *
* ARE INCREMENTED ONCE *
* PER 100 USEC INTERVAL*
* FOR MOTON ON TIMING. *
* *
* ---- ASSUMES ---- *
* *
* 1 USEC CYCLE TIME *
* *
**************************
MSWAIT LDX #$11
MSW1 DEX ;DELAY 86 USEC.
BNE MSW1
INC MONTIMEL
BNE MSW2 ;DOUBLE-BYTE
INC MONTIMEH ; INCREMENT.
MSW2 SEC
SBC #$1 ;DONE 'N' INTERVALS?
BNE MSWAIT ;(A-REG COUNTS)
RTS
EJECT
**************************
* *
* PHASE ON-, OFF-TIME *
* TABLES IN 100-USEC *
* INTERVALS. (SEEK) *
* *
**************************
ONTABLE DB $01,$30,$28
DB $24,$20,$1E
DB $1D,$1C,$1C
DB $1C,$1C,$1C
OFFTABLE DB $70,$2C,$26
DB $22,$1F,$1E
DB $1D,$1C,$1C
DB $1C,$1C,$1C
EJECT
**************************
* *
* 7-BIT TO 5-BIT *
* 'DENIBLIZE' TABL *
* *
* VALID CODES *
* $AB TO $FF ONLY. *
* ($DA NOT VALID) *
* *
* ---- CAUTION ---- *
* *
* INSURE THAT FOLLOWING *
* 'RE-ORG' IS OK. *
* *
**************************
ORG $3AAB
* OBJ $BAAB
DB $00,$01,$08
DB $10,$18,$02
DB $03,$04,$05
DB $06,$20,$28
DB $30,$07,$09
DB $38,$40,$0A
DB $48,$50,$58
DB $0B,$0C,$0D
DB $0E,$0F,$11
DB $12,$13,$14
DB $15,$16,$17
DB $19,$1A,$1B
DB $1C,$1D,$1E
DB $21,$22,$23
DB $24,$60,$68
DB $25,$26,$70
DB $78,$27,$80
DB $88,$90,$29
DB $2A,$2B,$2C
DB $2D,$2E,$2F
DB $31,$32,$33
DB $98,$A0,$34
DB $A8,$B0,$B8
DB $35,$36,$37
DB $39,$3A,$C0
DB $C8,$D0,$3B
DB $3C,$D8,$E0
DB $3E,$E8,$F0
DB $F8
EJECT
**************************
* *
* 5-BIT TO 7-BIT *
* NIBL CONVERSION *
* TABLE *
* *
**************************
* *
* CODES $AA, $D5 *
* NOT USED *
* *
**************************
ORG $3C9A
* OBJ $BC9A
NIBL DB $AB,$AD,$AE
DB $AF,$B5,$B6
DB $B7,$BA,$BB
DB $BD,$BE,$BF
DB $D6,$D7,$DA
DB $0DB,$DD,$DE
DB $DF,$EA,$EB
DB $ED,$EE,$EF
DB $F5,$F6,$F7
DB $FA,$FB,$FD
DB $FE,$FF
DB $1C,$1C,$1C
END