-
Notifications
You must be signed in to change notification settings - Fork 85
/
patchcr.src
1458 lines (1263 loc) · 22.7 KB
/
patchcr.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
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
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.page
.subttl 'patchCR.src'
;*****************************************************
jslower txa
ldx #5
bne jslowd+3 ; bra
jslowd txa
ldx #$0d ; insert 40 us. delay at 2 Mhz
1$ dex
bne 1$
tax
rts
;*****************************************************
sav_pnt lda bmpnt ; save pointers
sta savbm
lda bmpnt+1
sta savbm+1
rts
;*****************************************************
res_pnt lda savbm
sta bmpnt ; save pointers
lda savbm+1
sta bmpnt+1
rts
;*****************************************************
set_bm ldx drvnum
NODRRD ; read nodrv,x absolute
; lda nodrv,x ; drive active
beq 1$
lda #nodriv
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
; jsr cmder3
jsr cmder2 ; *** rom ds 11/07/85 beta9 ***, set error
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
1$ jsr bam2x ; get index into bufx
jsr redbam ; read BAM if neccessary
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
jmp 2$ ; *** rom ds 09/12/85 ***, always in memory!
; lda wbam ; write pending ?
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
beq 3$
ora #$80
sta wbam ; set write pending flag
bne 2$ ; bra
3$ jsr wrt_bam ; write out BAM, *** rom ds 9/12/85 ***, never get here
2$ jsr sav_pnt ; save current BAM pointers
jsr where ; find BAM
lda track ; get offset
sec
sbc #36
tay
lda (bmpnt),y ; get count
pha
jsr res_pnt ; restore BAM pointers
pla ; count in .a
rts
sono
.byte $44,$41,$56,$49,$44,$20,$47,$2e,$20,$53,$49,$52,$41,$43,$55,$53,$41
bam_pt lda track
sec
sbc #36 ; offset
tay
lda sector ; sector/8
lsr a
lsr a
lsr a
clc
adc bmindx,y ; get location
tay
lda sector
and #7
tax ; which sector
lda ovrbuf+$46,y
and bmask,x
php ; save status
lda ovrbuf+$46,y
plp ; retrieve status set/clr (z)
rts
;*****************************************************
deall_b jsr sav_pnt ; save pointers
jsr where ; where is the BAM
lda track
sec
sbc #36 ; offset
tay ; index into table
clc
lda (bmpnt),y ; goto location and add 1
adc #1
sta (bmpnt),y
jmp res_pnt ; restore BAM pointers
;*****************************************************
alloc_b jsr sav_pnt ; save pointers
jsr where ; find location of the BAM
lda track
sec
sbc #36 ; offset
tay ; index into table
sec
lda (bmpnt),y ; goto location and sub 1
sbc #1
sta (bmpnt),y
jmp res_pnt ; restore pointers
;*****************************************************
where ldx #blindx+7
lda buf0,x
and #$0f
tax
lda bufind,x ; which buffer is the BAM in
sta bmpnt+1
lda #$dd
sta bmpnt
rts
;*****************************************************
chk_blk lda temp
pha ; save temp
lda track
sec
sbc #36 ; get offset
tay
pha ; save
jsr sav_pnt
jsr where ; where is the BAM
lda (bmpnt),y
pha
lda #0
sta temp ; start at zero
lda #>bam_one
sta bmpnt+1 ; msb
lda bmindx,y ; starts here
clc
adc #<bam_one ; add offset
sta bmpnt
ldy #2
1$ ldx #7 ; verify bit map to count value
2$ lda (bmpnt),y
and bmask,x
beq 3$
inc temp ; on free increment
3$ dex
bpl 2$
dey
bpl 1$
pla
cmp temp
beq 4$
lda #direrr
jsr cmder2
4$ pla
tay ; restore track offset
pla
sta temp ; restore temp
jmp res_pnt
;*****************************************************
wrt_bam lda pota1 ; 1/2 Mhz ?
and #$20
bne 1$
2$ jmp dowrit
1$ lda maxtrk
cmp #37
bcc 2$
ldx jobnum
lda lstjob,x ; save last job
pha
jsr dowrit ; write out side zero
jsr sav_pnt ; save bmpnt
jsr setbpt
jsr clrbam+3 ; clear buffer
lda jobnum
asl a
tax
lda #53
sta hdrs,x ; put track in job queue, same sector
ldy #104
3$ lda ovrbuf+$46,y
sta (bmpnt),y
dey
bpl 3$ ; transfer to buffer
jsr res_pnt ; restore pointers
jsr dowrit ; write this track out
lda jobnum
asl a
tax
lda dirtrk ; *2
sta hdrs,x ; read back BAM side zero
jsr doread ; done
pla
ldx jobnum
sta lstjob,x ; restore last job
rts
;*****************************************************
bmindx .byte 0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54
.byte 57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,102
.page
;----------------------------------------------------
;
; PATCHES David G Siracusa - Commodore (c) 1985
;
; Compatibility is fun...
; I know you can say fun... I know you can...
;
;----------------------------------------------------
;
; patch 18 *rom ds 01/21/85*
;
ptch18 lda pota1 ; 1/2 Mhz ?
and #$20
beq 1$
ldy #0 ; clr regs
ldx #0
lda #1 ; place filename
sta filtbl
jsr onedrv ; setup drv
jmp rtch18 ; ret
1$ lda #$8d ; 1541 mode
jsr parse
jmp rtch18 ; ret
;
;
;----------------------------------------------------
;
; patch 19 *rom ds 01/21/85*
;
ptch19 jsr parsxq ; parse & xeq cmd
jsr spinp ; input
lda fastsr ; clr error
and #$7f
sta fastsr
jmp rtch19
;
;
;----------------------------------------------------
;
; patch 20 *rom ds 01/21/85*
;
ptch20 lda #255
sta acltim
lda #6 ; setup timer2
sta acltim2
rts
;
;
;----------------------------------------------------
;
; patch 21 *rom ds 01/21/85*
;
ptch21 bne 1$
lda mtrcnt ; anything to do ?
bne 2$
beq 3$
1$ lda #255
sta mtrcnt ; irq * 255
jsr moton ; turn on the motor
lda #1
sta wpsw
bne 3$ ; bra
2$ dec mtrcnt
bne 3$
lda drvst
bne 3$
jsr motoff ; turn off the motor
3$ jmp rtch21 ; return
;
;
;----------------------------------------------------
;
; patch 22
;
ptch22 lda #2
sta pb
lda #$20 ; *,_atn,2 mhz,*,*,side 0,sr-in,*
sta pa1
jmp ptch60 ; * rom ds 01/09/86 *, 1571CR
; jmp ptch22r ; ret
;
;
;----------------------------------------------------
;
; patch 23
;
ptch23 lda pota1 ; 1/2 Mhz ?
and #$20
bne 1$
2$ jmp doread ; 1541 mode read BAM side 1
1$ lda maxtrk ; seek ok, on other side ?
cmp #37
bcc 2$ ; seek regular method
jsr sav_pnt ; save pointers
lda #0
sta bmpnt ; even page
ldx jobnum
lda bufind,x ; which buffer is it in
sta bmpnt+1
lda #$ff
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
jmp ptch70 ; *** rom ds 05/21/86 ***
; sta jobrtn ; error recovery on
rtch70
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
lda jobnum
asl a
tax
lda #53 ; read BAM side one
sta hdrs,x ; put track in job queue, same sector
jsr doread ; read it
cmp #2 ; ok ?
ror a ; carry set bad return
and #$80 ; isolate sign bit
eor #$80
sta dside
bpl 3$ ; br, error
ldy #104
4$ lda (bmpnt),y ; get BAM 1 and put somewhere in God's country
sta ovrbuf+$46,y
dey
bpl 4$
3$
lda #$ff
sta jobrtn ; set error recovery on
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
rtch70a
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
lda jobnum
asl a
tax
lda dirtrk ; read BAM side zero
sta hdrs,x ; put track in job queue, same sector
jsr doread ; read it
cmp #2
bcc 5$
tax ; save error
lda #36
sta maxtrk ; def single sided
jsr res_pnt ; save BAM pointers
txa
jsr error ; let the error handler do the rest
jmp rec7 ; consist
5$ ldy #3
lda (bmpnt),y ; check double sided flag
and dside ; both must be ok....
bmi 6$
lda #36
.byte skip2
6$ lda #71
sta maxtrk ; double sided
jmp res_pnt ; restore BAM pointers
;
;
;----------------------------------------------------
;
; patch 24
;
ptch24 jsr dojob ; seek side zero
pha ; save status
cmp #2 ; error ?
bcs 1$ ; br, error...
lda pota1
and #$20
beq 1$ ; 1/2 Mhz ?
lda #71
sta maxtrk ; let DOS think he has double sided capability
lda #$ff
sta jobrtn ; return from error
lda header ; get id's
pha
lda header+1
pha ; save them
lda jobnum
asl a
tax
lda #53 ; seek side one BAM track
sta hdrs,x ; put track in job queue, same sector
lda #seek
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
; jsr dojob ; try it...
jsr ptch64 ; make it faster...
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
cmp #2 ; error ?
pla
tay ; header+1
pla
tax ; header
bcs 2$ ; error on last job ?
cpx header ; same id's ?
bne 2$
cpy header+1 ; same id's ?
bne 2$
lda #71 ; probably double sided
.byte skip2
2$ lda #36
sta maxtrk
sty header+1 ; restore original id's from side zero
stx header
lda jobnum
asl a
tax
lda dirtrk
sta hdrs,x ; put track in job queue, same sector
1$ pla ; get status
rts
;
;
;----------------------------------------------------
;
; patch 25
;
ptch25 jsr setbpt ; setup bit map pointer
lda pota1
and #%00100000 ; 1/2 Mhz ?
beq 1$
lda #0
ldy #104 ; clr BAM side one
2$ sta ovrbuf+$46,y
dey
bpl 2$
1$ jmp rtch25 ; return
;
;
;----------------------------------------------------
;
; patch 26
;
ptch26 pha ; save .a
lda pota1
and #%00100000 ; 1/2 Mhz ?
beq 1$
pla
cmp #36 ; > trk 35 ?
bcc 2$
sbc #35
.byte skip1
1$ pla ; restore .a
2$ ldx nzones ; cont
rts
;
;
;----------------------------------------------------
;
; patch 27
;
ptch27 jsr clrbam ; clear BAM area
lda pota1
and #%00100000
bne 1$ ; 1/2 Mhz ?
lda #36
.byte skip2
1$ lda #71
sta maxtrk ; set maximum track full format
jmp rtch27 ; return
;
;
;----------------------------------------------------
;
; patch 28
;
ptch28 lda pota1
and #%00100000
bne 1$ ; 1/2 Mhz ?
jmp format ; 1541 mode
1$ jmp jformat ; 1571 mode
;
;
;----------------------------------------------------
;
; patch 29
;
ptch29 lda pa1 ; change to 1 mhz
and #%11011111
sta pa1
jsr jslowd ; wait for ...
lda #$7f
sta icr ; clear all sources of irq's
jsr spinp ; finish up and enable irq's from '26
jmp tstatn ; chk for atn & goto xidle
*=$A7B3
;
;
;----------------------------------------------------
;
; patch 30
;
ptch30
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
; lda pota1
jsr ptch57 ; *** rom ds 08/05/85 ***, serial bus fix for a
; very old bug.
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
and #%00100000
beq 1$ ; 1/2 Mhz ?
jmp jatnsrv ; 2 Mhz
1$ jmp atnsrv ; 1 Mhz
;
;
;----------------------------------------------------
;
; patch 31
;
ptch31 sei
ldx #topwrt ; set stack pointer
txs
jmp rtch31
;
;
;----------------------------------------------------
;
; patch 32
;
ptch32 lda pota1 ; 1/2 Mhz ?
and #$20
ptch32a bne 1$
6$ ldy #3
lda #0
sta (bmpnt),y ; set single sided bit in BAM side 0
jmp newmap ; finish up 1541 mode
1$ lda maxtrk ; single/double sided?
cmp #37
bcc 6$
ldy #1
ldx #0
2$ cpy #18
beq 4$
txa
pha ; save .x
lda #0 ; start temps at zero
sta t0
sta t1
sta t2
lda num_sec-1,y
tax ; number of sectors per track
3$ sec
rol t0
rol t1
rol t2
dex
bne 3$
pla
tax ; restore .x
lda t0 ; write BAM side one
sta ovrbuf+$46,x
lda t1
sta ovrbuf+$46+1,x
lda t2
sta ovrbuf+$46+2,x
inx
inx
inx
cpx #$33 ; skip track 53
bne 4$
inx
inx
inx
iny ; bypass and leave allocated
4$ iny
cpy #36
bcc 2$
jsr newmap ; generate new BAM for side zero
ldy #3
lda #$80
sta (bmpnt),y ; set double sided bit in BAM side 0
ldy #$ff
ldx #34
5$ lda num_sec,x ; get # of free sectors
sta (bmpnt),y ; save in top end of BAM zero
dey ; => $dd-$ff
dex
bpl 5$
ldy #$ee ; offset for track 53
lda #0
sta (bmpnt),y ; allocate track 53
jmp nfcalc ; calculate BAM side 0/1
;
;
;----------------------------------------------------
;
; patch 33
;
ptch33 lda pota1 ; 1/2 Mhz ?
and #$20
bne 1$
2$ jsr freuse ; track < 36 or 1541 mode
jmp frets2 ; ret
1$ lda track ; is track greater than 35
cmp #36
bcc 2$
jsr set_bm ; setup & update parms
jsr bam_pt ; find position within table
bne 3$
ora bmask,x ; set it free
sta ovrbuf+$46,y
jsr dtybam ; set dirty flag
jsr deall_b ; deallocate BAM
lda track
cmp #53 ; skip BAM track side one
beq 4$
lda drvnum ; get drv #
asl a
tax ; *2
jmp fre20 ; ret
3$ sec
4$ rts
;
;
;----------------------------------------------------
;
; patch 34
;
ptch34 lda pota1 ; 1/2 Mhz ?
and #$20
bne 1$
2$ jsr freuse ; track < 36 or 1541 mode
jmp rtch34
1$ lda track ; check track
cmp #36
bcc 2$
jsr set_bm ; setup & update parms
jsr bam_pt ; find position within the BAM
beq 3$
eor bmask,x ; set it used
sta ovrbuf+$46,y
jsr dtybam ; set dirty flag
jsr alloc_b ; allocate BAM
lda track
cmp #53 ; skip BAM track side one
beq 3$
lda drvnum ; get drv #
asl a
tax
jmp use30
3$ rts
;
;
;----------------------------------------------------
;
; patch 35
;
ptch35 lda pota1 ; 1/2 Mhz ?
and #$20
bne 1$
2$ jsr setbam ; track < 36 or 1541 mode
jmp rtch35
1$ lda track ; check track
cmp #36
bcc 2$
jsr set_bm ; setup & update parms
jsr chk_blk ; chk alloc w/ bits
lda num_sec,y ; get number of sectors on this track
sta lstsec ; & save it
4$ lda sector ; what sector are we looking at ?
cmp lstsec
bcs 5$
jsr bam_pt ; check availability
bne 6$
inc sector ; we will find something I hope...
bne 4$
5$ lda #0
6$ rts ; (z=1) used
;
;
;----------------------------------------------------
;
; patch 36
;
ptch36 lda pota1 ; 1/2 Mhz ?
and #$20
bne 1$
2$ lda temp
pha
jmp rtch36
1$ lda track ; check track
cmp #36
bcc 2$
cmp #53
beq 3$
lda temp
pha ; save temp var
jsr set_bm ; setup & update parms
tay ; save .a
pla
sta temp ; restore temp
tya ; return allocation status in .a
jmp rtch36a
3$ lda #0 ; z=1
jmp rtch36a ; track 53 allocated
;
;
;----------------------------------------------------
;
; patch 37
;
ptch37 lda pota1 ; 1/2 Mhz ?
and #$20
bne 1$
2$ jsr setbam ; setup the BAM pointer
jmp rtch37 ; ret
1$ lda track ; check track
cmp #36
bcc 2$
jsr set_bm ; setup & update parms
jmp rtch37a
;
;
;----------------------------------------------------
;
; patch 38
;
ptch38 lda pota1 ; 1/2 Mhz ?
and #$20
bne 1$
2$ jsr setbam ; setup the BAM pointer
jmp rtch38 ; ret
1$ lda track ; check track
cmp #36
bcc 2$
jsr set_bm ; setup & update parms
jmp rtch38a
;
;
;----------------------------------------------------
;
; patch 39
;
ptch39 lda pota1 ; 1/2 Mhz ?
and #$20
bne 1$
2$ jmp avck ; check block availability
1$ lda maxtrk ; check maximum track
cmp #37
bcc 2$
lda track ; check track do regular check
cmp #36
bcc 2$
jmp chk_blk ; finish up
;
;
;----------------------------------------------------
;
; patch 40
;
ptch40 sta ndbl,x ; save low order
lda pota1 ; 1/2 Mhz ?
and #$20
beq 1$
lda maxtrk ; check maximum track
cmp #37
bcc 1$
jsr sav_pnt ; save pointers
jsr where ; locate BAM
ldy #34 ; count backwards and sleep........zzzzZZZZZZZZ
lda ndbl
2$ clc
adc (bmpnt),y ; count it up
sta ndbl ; keep track HAHA !!!
bcc 3$
inc ndbh ; increment msb
3$ dey
bpl 2$
jmp res_pnt ; restore pointers
1$ rts ; done
;
;
;----------------------------------------------------
;
; patch 41
;
ptch41 sta nbkl,x
sta nbkh,x
lda #0
sta lstchr,x
rts
;
;
;----------------------------------------------------
;
; patch 42
;
ptch42 jsr jformat ; format disk in GCR
ldy #0
sty jobrtn
rts
;
*=*+11 ; address adjust
;
;
;----------------------------------------------------
;
; patch 43
;
;
ptch43 lda #0 ; clr nodrv
NODRWR ; write nodrv,x absolute
jmp rtch43
;
;
;----------------------------------------------------
;
; patch 44
;
;
ptch44 tya ; set/clr nodrv
NODRWR ; write nodrv,x absolute
jmp rtch44
;
;
;----------------------------------------------------
;
; patch 45
;
ptch45 lda pota1 ; 1/2 Mhz ?
and #$20
beq 1$
jmp a2 ; 1571 mode
1$ jmp atns20 ; 1541 mode
;
;
;----------------------------------------------------
;
; patch 46
;
ptch46 pha ; save error
stx jobnum ; save job #
lda pota1 ; 1/2 Mhz ?
and #$20
beq 1$
bit fastsr ; error recovery on ?
bpl 1$
lda fastsr
and #$7f ; clr error recovery
sta fastsr
pla ; get error
tax
jmp ctr_err ; let it error out
1$ jmp rtch46 ; return
;
;
;----------------------------------------------------
;
; patch 47
;
ptch47 pha ; save error
lda pota1 ; 1/2 Mhz ?
and #$20
beq 1$