-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathndev.s
More file actions
1246 lines (1001 loc) · 29.8 KB
/
Copy pathndev.s
File metadata and controls
1246 lines (1001 loc) · 29.8 KB
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
;; N: Device Handler
;; Compile with MADS
;; Author: Thomas Cherryhomes
;; <thom.cherryhomes@gmail.com>
;; CURRENT IOCB IN ZERO PAGE
DEBUG = 0 ; displays debug messages
DONT_RELOCATE = 0 ; set to one if you don't want to relocate code.
ZIOCB = $20 ; ZP IOCB
ZICHID = ZIOCB ; ID
ZICDNO = ZIOCB+1 ; UNIT #
ZICCOM = ZIOCB+2 ; COMMAND
ZICSTA = ZIOCB+3 ; STATUS
ZICBAL = ZIOCB+4 ; BUF ADR LOW
ZICBAH = ZIOCB+5 ; BUF ADR HIGH
ZICPTL = ZIOCB+6 ; PUT ADDR L
ZICPTH = ZIOCB+7 ; PUT ADDR H
ZICBLL = ZIOCB+8 ; BUF LEN LOW
ZICBLH = ZIOCB+9 ; BUF LEN HIGH
ZICAX1 = ZIOCB+10 ; AUX 1
ZICAX2 = ZIOCB+11 ; AUX 2
ZICAX3 = ZIOCB+12 ; AUX 3
ZICAX4 = ZIOCB+13 ; AUX 4
ZICAX5 = ZIOCB+14 ; AUX 5
ZICAX6 = ZIOCB+15 ; AUX 6
;; CIO only copies the first 12 IOCB bytes to/from the ZP
;; IOCB; $2C-$2F are CIO work bytes, so AUX3-5 must be read
;; and written in the real IOCB, indexed by ICIDNO.
ICIDNO = $2E ; CIO: IOCB # * 16
DOSINI = $0C ; DOSINI
VPRCED = $0202 ; PROCEED VCTR
MEMLO = $02E7 ; MEM LO
DVSTAT = $02EA ; 4 BYTE STATS
; PAGE 3
; DEVICE CONTROL BLOCK (DCB)
DCB = $0300 ; BASE
DDEVIC = DCB ; DEVICE #
DUNIT = DCB+1 ; UNIT #
DCOMND = DCB+2 ; COMMAND
DSTATS = DCB+3 ; STATUS/DIR
DBUFL = DCB+4 ; BUF ADR L
DBUFH = DCB+5 ; BUF ADR H
DTIMLO = DCB+6 ; TIMEOUT (S)
DRSVD = DCB+7 ; NOT USED
DBYTL = DCB+8 ; BUF LEN L
DBYTH = DCB+9 ; BUF LEN H
DAUXL = DCB+10 ; AUX BYTE L
DAUXH = DCB+11 ; AUX BYTE H
HATABS = $031A ; HANDLER TBL
; IOCB'S * 8
IOCB = $0340 ; IOCB BASE
ICHID = IOCB ; ID
ICDNO = IOCB+1 ; UNIT #
ICCOM = IOCB+2 ; COMMAND
ICSTA = IOCB+3 ; STATUS
ICBAL = IOCB+4 ; BUF ADR LOW
ICBAH = IOCB+5 ; BUF ADR HIGH
ICPTL = IOCB+6 ; PUT ADDR L
ICPTH = IOCB+7 ; PUT ADDR H
ICBLL = IOCB+8 ; BUF LEN LOW
ICBLH = IOCB+9 ; BUF LEN HIGH
ICAX1 = IOCB+10 ; AUX 1
ICAX2 = IOCB+11 ; AUX 2
ICAX3 = IOCB+12 ; AUX 3
ICAX4 = IOCB+13 ; AUX 4
ICAX5 = IOCB+14 ; AUX 5
ICAX6 = IOCB+15 ; AUX 6
; HARDWARE REGISTERS
PACTL = $D302 ; PIA CTRL A
; OS ROM VECTORS
CIOV = $E456 ; CIO ENTRY
SIOV = $E459 ; SIO ENTRY
; CONSTANTS
DEVIDN = $71 ; SIO DEVID
DSREAD = $40 ; FUJI->ATARI
DSWRIT = $80 ; ATARI->FUJI
MAXDEV = 8 ; # OF N: DEVS
EOF = $88 ; ERROR 136
EOL = $9B ; EOL CHAR
;; BURST MODE PARAMETERS
MINBURST = $80 ; Min user buf len to burst (128)
MAXBURST = $2000 ; Max bytes per burst frame (8192).
; LO byte MUST be 0 (see CAPCHK).
;; ORG HERE
ORG $6000
RELOCATE_CODE_START:
;; This is for OS/A+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
RTS ; Immediately exit
;;; RESET HANDLER ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
RESET:
JSR $FFFF ; pointing to original DOSINI
LDA RELOC_HANDLEREND ; Driver end LO
STA MEMLO
LDA RELOC_HANDLEREND+1 ; Driver end HI
STA MEMLO+1
JSR IHTBS ; Insert into HATABS
JSR CLALL
RTS
;;; END RESET HANDLER ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; INTERRUPT HANDLER ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
INTR: LDA #$01 ; set trip to 1
STA TRIP
PLA
RTI
;;; END INTERRUPT HANDLER ;;;;;;;;;;;;;;;;;;;;;;;;
;;; SUBROUTINES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GET IOCB UNIT # INTO X
GDIDX: LDX ZICDNO ; CURRENT IOCB UNIT #
DEX ; -1
RTS
;; Poll for Status
POLL: LDA ZICDNO ; Get Unit #
STA POLDCB+1 ; Put into Table
LDA RELOC_POLDCB ; Set up STATUS POLL DCB table
LDY RELOC_POLDCB+1
JSR DOSIOV ; And do SIOV, fall thru to...
;; Update Bytes waiting
GETBW: JSR GDIDX ; Get Unit #
TXA ; move to A for ASL
ASL ; * 2
TAX ; X = unit*2
LDA DVSTAT ; Get Bytes Waiting (LO)
STA BW,X ; Store in BW,(unit)
LDA DVSTAT+1 ; Get Bytes Waiting (HI)
STA BW+1,X ; Store in BW,(unit)+1
RTS
;; Save DVSTAT values
SVSTAT: JSR GDIDX ; Get Unit into X
JSR CAPRX ; Cap RX values
LDA DVSTAT ; Get RX bytes waiting
STA RLEN,X ; Save RX bytes waiting
LDA DVSTAT+2 ; Get Server Client connected/disconnected?
STA DVS2,X ; Save
LDA DVSTAT+3 ; Get last error
STA DVS3,X ; Save
RTS
;; Enable PROCEED interrupt
ENPRCD: LDA PACTL ; Get PACTL register
ORA #$01 ; Enable PROCEED
STA PACTL ; Store it back
RTS
;; Disable PROCEED interrupt
DIPRCD: LDA PACTL ; Get PACTL register
AND #$FE ; Disable PROCEED
STA PACTL ; store it back.
RTS
;; Flush TX Buffer out
FLUSH: JSR GDIDX ; UNIT NUMBER into X
LDA ZICDNO ; IOCB UNIT #
STA FLUDCB+1 ; Put into table.
LDA TOFF,X ; get Transmit offset (# of bytes to send)
BEQ FLDONE ; Don't do anything if TX cursor is at 0.
STA FLUDCB+8 ; Put into Table (Len and Aux)
STA FLUDCB+10
LDA RELOC_FLUDCB ; Copy Table to DCB
LDY RELOC_FLUDCB+1
JSR DOSIOV ; And call SIOV
JSR GDIDX ; Get Unit into X
LDA #$00 ; Clear TOFF
STA TOFF,X
LDY DSTATS
FLDONE: RTS ; Done, LDY has DSTATS
;; Cap RX to 127 bytes (temporary routine)
CAPRX: LDA DVSTAT+1 ; Get hi-byte
BNE CAPADJ ; Adjust if > 256 bytes
LDA DVSTAT ; Get lo-byte
BPL CAPDON ; Exit if < 127 bytes
CAPADJ: LDA #$7F ; 127 bytes
STA DVSTAT ; into DVSTAT/DVSTAT+1
LDA #$00
STA DVSTAT+1
CAPDON: RTS ; Done
;; Close all IOCBs
CLALL: LDA #MAXDEV ; Close all 4 N: devices
STA TRIP ; Temporarily use trip
CLLP: LDA TRIP ; Get
STA ZICDNO ; Store into unit #
JSR CLOSE ; Close Nx:
DEC TRIP ; Decrement
LDA TRIP ; Get it
BNE CLLP ; Loop until done.
RTS
;; Do read from ZIOCB unit
READ: JSR GDIDX ; unit into X
LDA #$00 ; Set 0 into
STA ROFF,X ; RXD cursor.
LDA ZICDNO ; Get Unit #
STA READCB+1 ; Put into Read DCB table
LDA RLEN,X ; Get RLEN (from status)
BEQ RDONE ; If RLEN=0 then abort read.
STA READCB+8 ; Store in DBYTL
STA READCB+10 ; Store in DAUX1
LDA RELOC_READCB ; Set up Read DCB
LDY RELOC_READCB+1 ; ...
JSR DOSIOV ; Do SIO call
LDY DSTATS ; Get DSTATS for error
CPY #144 ; Is it 144?
BNE RDONE ; No, simply return DSTATS in Y
JSR POLL ; Otherwise, do a poll to get extended error
LDY DVSTAT+3 ; And return it in Y.
RDONE: RTS ; Done.
;;; HANDLER RUNAD HERE ;;;;;;;;;;;;;;;;;;;;;;;;;;;
START: LDA DOSINI ; store the old dosini in our routine
STA RESET+1
LDA DOSINI+1
STA RESET+2
LDA RELOC_RESET ; add our reset handler
STA DOSINI
LDA RELOC_RESET+1
STA DOSINI+1
LDA RELOC_HANDLEREND ; update memlo
STA MEMLO
LDA RELOC_HANDLEREND+1
STA MEMLO+1
JSR CLALL ; Close all
;;; Insert Handler entry into HATABS ;;;;;;;;;;;
IHTBS: LDY #$00 ; Start at beginning of HATABS
IH1: LDA HATABS,Y
BEQ HFND ; Did we find a blank ($00) entry?
CMP #'N' ; or did we find our existing 'N' entry?
BEQ HFND ; If so, insert our entry here.
INY ; Otherwise, scoot forward to next entry.
INY
INY
CPY #11*3 ; Are we at the end of the table?
BCC IH1 ; Check again.
;; We found a slot, insert it in.
HFND: LDA #'N' ; We are the N: device
STA HATABS,Y ; first byte in our entry
LDA RELOC_DEVHDL ; Get address of our handler table
STA HATABS+1,Y ; and put it in Hatabs
LDA RELOC_DEVHDL+1
STA HATABS+2,Y
;; And vector in PROCEED.
VPRCD: LDA RELOC_INTR ; Get Addr of interrupt handler
STA VPRCED ; Store it in PROCEED vector
LDA RELOC_INTR+1
STA VPRCED+1
;; We're done, back to DOS.
RTS
;;; INDICATE SUCCESS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SUCC: LDY #$01 ; Indicate success
RTS ; Back to caller.
;;; CLEAR BUFFERS FOR UNIT X ;;;;;;;;;;;;;;;;;;;;
CLRBUF: LDA #$00
STA RLEN,X
STA TOFF,X
STA ROFF,X
STA DVS2,X
STA DVS3,X
RTS
;;; COPY TABLE TO DCB AND DO SIO CALL ;;;;;;;;;;;
DOSIOV: STA DODCBL+1 ; Set source address
STY DODCBL+2
LDY #$0B ; 12 bytes
DODCBL LDA $FFFF,Y ; Changed above.
STA DCB,Y ; To DCB table
DEY ; Count down
BPL DODCBL ; Until done
SIOVDST:
JSR SIOV ; Call SIOV
LDY DSTATS ; Get STATUS in Y
TYA ; Copy it into A
RTS ; Done
;;; OPEN ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Fill in the OPEN table
OPEN: JSR GDIDX ; Set IOCB OFFSET TO UNIT #
JSR CLRBUF ; Clear Buffers
LDA ZICDNO ; GET Desired unit #
STA OPNDCB+1 ; Store in open table
LDA ZICBAL ; Get desired buffer LO
STA OPNDCB+4 ; Store in open table
LDA ZICBAH ; Get desired buffer HI
STA OPNDCB+5 ; Store in open table
LDA ZICAX1 ; Get requested Aux1
STA OPNDCB+10 ; Store in open table
LDA ZICAX2 ; Get requested Aux2
STA OPNDCB+11 ; Store in open table
;; Do the SIOV call
LDA RELOC_OPNDCB
LDY RELOC_OPNDCB+1
JSR DOSIOV
;; Return DSTATS in Y, unless 144, then get ext err.
CPY #144 ; Did we get an ERROR- 144?
BNE OPDONE ; Nope, keep DSTATS in Y
;; We got a 144, get error from STATUS call
JSR POLL ; Do Status poll
LDY DVSTAT+3 ; Get error code
OPDONE: RTS
;;; CLOSE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CLOSE: JSR DIPRCD ; Disable PROCEED
JSR FLUSH ; do PUT flush if needed.
JSR CLRBUF ; Clear buffer pointers
LDA ZICDNO ; Unit #
STA CLODCB+1 ; Put into table
LDA RELOC_CLODCB ; Close DCB table
LDY RELOC_CLODCB+1
JSR DOSIOV ; Do SIOV
CLV
BVC SUCC ; Always return success
;;; GET ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
GET: JSR GDIDX ; Unit into X
LDA RLEN,X ; Get current RX len from last STATUS
BNE GETDRN ; If RLEN > 0 then drain.
;; Otherwise, we wait for something to happen.
GETWAI: JSR ENPRCD ; Enable Proceed
LDA TRIP ; Did trip change?
BEQ GETWAI ; Nope, not yet...
;; Something happened, try to poll for data.
JSR POLL ; Do Status Poll
;; If a burst read is possible, do it directly into the
;; user's buffer instead of filling RBUF one byte at a time.
JSR BCHK ; Burst eligible? (C clear = yes)
BCS GETNRM ; No -> normal one-byte-at-a-time path
JMP BGET ; Yes -> burst (returns straight to CIO)
GETNRM: JSR SVSTAT ; Save Status
JSR READ ; Do read
;; If RLEN=0 then determine if error.
LDA DVSTAT ; Get RLEN Again
BNE GETDRN ; If RLEN > 1, then drain.
LDY DVSTAT+3 ; Get ext err
CPY #136 ; EOF?
BEQ GETDNE ; Yes, return it.
LDY DSTATS ; Else, get DSTATS from status/read.
CPY #144 ; is it 144?
BNE GETDNE ; Nope, simply return it in Y, done.
LDY DVSTAT+3 ; Get Extended error
BNE GETDNE ; Done.
;; Drain
GETDRN: JSR DIPRCD ; Disable PROCEED
JSR GDIDX ; Get Unit into X again
DEC RLEN,X ; Decrement length
LDY ROFF,X ; Get Current Offset into X
LDA RBUF,Y ; Get next character
INC ROFF,X ; Increment cursor
TAY ; Store in Y for a moment
;; If RX buffer empty, turn off trip.
LDA RLEN,X ; Get RLEN
BNE GETDN2 ; some left, just go done with success
STA TRIP ; Otherwise store 0 into trip
GETDN2: TYA ; Bring back char into A
LDY #$01 ;
GETDNE: RTS
;;; PUT ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PUT: PHA ; Save byte (needed for normal path)
JSR GDIDX ; Get Unit # into X
;; Try to burst the whole write directly from the user's
;; buffer. Only for binary PUT CHARACTERS with a large enough
;; length and nothing already buffered in TBUF (to keep order).
LDA TOFF,X ; Pending buffered bytes?
BNE PUTNRM ; Yes -> normal path
LDA ZICCOM ; CIO command
AND #$02 ; Binary PUT CHARACTERS?
BEQ PUTNRM ; No (text/record) -> normal path
LDA ZICBLH ; Buffer length hi
BNE PUTBST ; >= 256 -> burst
LDA ZICBLL ; Buffer length lo
CMP #MINBURST ; >= MINBURST?
BCC PUTNRM ; No -> normal path
PUTBST: PLA ; Discard byte (burst re-reads from buffer)
JMP BPUT ; Burst write (returns straight to CIO)
PUTNRM: PLA ; Restore byte
LDY TOFF,X ; Get TX cursor
STA TBUF,Y ; Put char into buffer ptd by cursor
INC TOFF,X ; Increment TX cursor
;; Do a FLUSH if EOL or buffer full
CMP #EOL ; EOL?
BEQ PFLUSH ; Do flush
CPY #$7F ; At end of buffer?
BNE PUTDON ; Nope, done.
PFLUSH: JSR FLUSH ; Do Flush.
PUTDON: RTS ; We're done.
;;; STATUS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
STATUS: JSR ENPRCD ; Enable PROCEED.
;; Return cached value if we still have data in RX
JSR GDIDX ; Unit into X
LDA RLEN,X ; Get RX len
BNE STRETC ; Return cached value if RLEN > 0
LDA TRIP ; Get TRIP?
BEQ STRETC ; No trip? Return cached.
JSR POLL ; RLEN = 0, do poll.
JSR SVSTAT ; Save DVSTAT values
JSR READ ; Do read.
STRETC: JSR GDIDX ; Unit into X
TXA
ASL ; A = unit*2
TAX ; X = unit*2 for BW
LDA BW,X ; Get Saved DVSTAT+0 val
STA DVSTAT ; Store into DVSTAT
LDA BW+1,X ; Get Saved DVSTAT+1 val
STA DVSTAT+1 ; Store into DVSTAT+1
JSR GDIDX ; X = unit for DVS2/DVS3
LDA DVS2,X ; Get Saved DVSTAT+2 val
STA DVSTAT+2 ; Store
LDA DVS3,X ; Get Saved DVSTAT+3 val
STA DVSTAT+3
TAY ; copy it into Y for error output.
RTS ; Done.
;;; SPECIAL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SPECIAL:
;; Clear Trip
LDA #$00
STA TRIP
;; Handle Local Commands
LDA ZICCOM
CMP #$0F ; 15 = FLUSH
BNE SPNOTP ; No. Check NOTE/POINT
JSR FLUSH ; Yes. Do flush.
LDY #$01 ; Flush always successful
JMP SPCDNE ; We're done.
;; NOTE/POINT are handled locally with a 3-byte position
;; payload; the generic path below can't carry ICAX3-5.
SPNOTP: CMP #$25 ; 37 = POINT
BNE SPNOTN ; No.
JMP PPOINT ; Do Point
SPNOTN: CMP #$26 ; 38 = NOTE
BNE SPQ ; No. Handle protocol commands
JMP PNOTE ; Do Note
;; Handle Protocol commands, do INQDS Query
SPQ: LDA ZICDNO ; Get Unit #
STA SPQDCB+1 ; Store in table
LDA ZICCOM ; Get Command
STA SPQDCB+10 ; Put in AUX1 for query
LDA RELOC_SPQDCB ; Set up SPECIAL QUERY DCB TABLE
LDY RELOC_SPQDCB+1 ;
JSR DOSIOV ; Do Query
LDY DSTATS ; Get DSTATS
BMI SPCDNE ; SIO error, return in Y. There is no ext err.
;; We got a query, if it's $FF, return unimplemented.
LDA INQDS ; Get the Returned DSTATS value from inquiry
CMP #$FF ; Is it $FF ?
BNE SPDO ; Nope, let's do it.
LDY #146 ; ERROR- 146 Unimplemented Command
JMP SPCDNE ; Done.
;; Do the Special, get all IOCB params, push onto stack
SPDO: STA SPEDCB+3 ; DSTATS value from inquiry
LDA ZICDNO ; Unit #
STA SPEDCB+1
LDA ZICCOM ; Command
STA SPEDCB+2
LDA ZICBAL ; Ptr to passed in devicespec
STA SPEDCB+4
LDA ZICBAH ;
STA SPEDCB+5
LDA ZICAX1 ; Aux1
STA SPEDCB+10
LDA ZICAX2 ; Aux2
STA SPEDCB+11
LDA RELOC_SPEDCB
LDY RELOC_SPEDCB+1
JSR DOSIOV
;; Get error and return extended if needed.
LDY DSTATS ; Get DSTATS
CPY #144 ; Is it 144?
BNE SPCDNE ; Nope, just return it.
JSR POLL ; Get status, for error
LDY DVSTAT+3 ; Get extended error.
SPCDNE: RTS
;;; NOTE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; NOTE ($26) returns the current 24-bit linear file
;; position in ICAX3 (lo), ICAX4 (mid), ICAX5 (hi).
PNOTE: JSR FLUSH ; Push pending PUT bytes first
LDA ZICDNO ; Unit #
STA NOTDCB+1
LDA RELOC_NOTDCB
LDY RELOC_NOTDCB+1
JSR DOSIOV ; 3-byte position into NPBUF
LDY DSTATS
CPY #$01 ; Success?
BEQ PNOK
CPY #144 ; Extended error?
BNE PNDONE ; No, return DSTATS in Y
JSR POLL
LDY DVSTAT+3 ; Return extended error
PNDONE: RTS
;; FujiNet's position is ahead of the user's by whatever is
;; still unread in RBUF; subtract it (24-bit minus 8-bit).
PNOK: JSR GDIDX ; Unit into X
SEC
LDA NPBUF
SBC RLEN,X
STA NPBUF
LDA NPBUF+1
SBC #$00
STA NPBUF+1
LDA NPBUF+2
SBC #$00
STA NPBUF+2
;; Store into the caller's IOCB (see ICIDNO note up top).
LDX ICIDNO ; IOCB # * 16
LDA NPBUF
STA ICAX3,X
LDA NPBUF+1
STA ICAX4,X
LDA NPBUF+2
STA ICAX5,X
LDY #$01
RTS
;;; POINT ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; POINT ($25) sets the 24-bit linear file position from
;; ICAX3 (lo), ICAX4 (mid), ICAX5 (hi).
PPOINT: JSR FLUSH ; Push pending PUT bytes first
LDX ICIDNO ; IOCB # * 16
LDA ICAX3,X ; Position (lo)
STA NPBUF
LDA ICAX4,X ; Position (mid)
STA NPBUF+1
LDA ICAX5,X ; Position (hi)
STA NPBUF+2
LDA ZICDNO ; Unit #
STA PNTDCB+1
LDA RELOC_PNTDCB
LDY RELOC_PNTDCB+1
JSR DOSIOV ; Send 3-byte position
LDY DSTATS
CPY #$01 ; Success?
BEQ PPOK
CPY #144 ; Extended error?
BNE PPDONE ; No, return DSTATS in Y
JSR POLL
LDY DVSTAT+3 ; Return extended error
PPDONE: RTS
;; Drop stale read-ahead and cached status, and trip so the
;; next GET/STATUS polls fresh data at the new position.
PPOK: JSR GDIDX ; Unit into X
LDA #$00
STA RLEN,X
STA ROFF,X
TXA
ASL ; unit*2
TAX
LDA #$00
STA BW,X
STA BW+1,X
LDA #$01
STA TRIP
LDY #$01
RTS
;;; BURST MODE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Burst mode short-circuits CIO's one-byte-at-a-time GET/PUT
;;; loop. The OS keeps its running buffer pointer in ZICBAL and
;;; its remaining byte count in ZICBLL while transferring. On a
;;; GET it stores the returned byte, then bumps ZICBAL and drops
;;; ZICBLL by one; on a PUT it reads the byte, then does the same.
;;;
;;; So a handler can move a whole block by transferring directly
;;; to/from (ZICBAL) and advancing ZICBAL / shrinking ZICBLL by
;;; (block-1); CIO's own final +1/-1 accounts for the last byte.
;;; This mirrors the burst I/O in the Atari DOS 2.0S FMS.
;;; BURST CHECK ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Decide whether a GET can burst. Call right after POLL,
;; while DVSTAT holds the (uncapped) bytes-waiting count.
;; Eligible = binary GET CHARACTERS, user buffer at least
;; MINBURST bytes, and something actually waiting.
;; Returns C clear if eligible, C set otherwise.
BCHK: LDA ZICCOM ; CIO command
AND #$02 ; Bit 1 set = CHARACTERS (binary)
BEQ BCHKNO ; Clear = RECORD (text) -> no burst
LDA ZICBLH ; Buffer length hi
BNE BCHKAV ; >= 256 -> big enough
LDA ZICBLL ; Buffer length lo
CMP #MINBURST ; >= MINBURST?
BCC BCHKNO ; No -> too small to bother
BCHKAV: LDA DVSTAT ; Bytes waiting lo
ORA DVSTAT+1 ; | hi
BEQ BCHKNO ; Nothing waiting -> let normal path run
CLC ; Eligible
RTS
BCHKNO: SEC ; Not eligible
RTS
;;; BURST GET ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Read min(bytes-waiting, buffer length, MAXBURST) bytes in
;; one SIO call, straight into the user's buffer. Advance
;; ZICBAL/ZICBLL past all but the last byte and hand that
;; last byte back to CIO (which stores it and does the final
;; +1/-1). Entry: DVSTAT = bytes waiting (from POLL).
BGET: ;; CHUNK = min(bytes-waiting, ZICBLL)
LDA DVSTAT+1 ; waiting hi
CMP ZICBLH
BCC BGBW ; waiting < len -> use waiting
BNE BGBL ; waiting > len -> use len
LDA DVSTAT ; hi equal, compare lo
CMP ZICBLL
BCC BGBW ; waiting < len -> use waiting
BGBL: LDA ZICBLL ; use length (length <= waiting)
STA CHUNK
LDA ZICBLH
STA CHUNK+1
JMP BGCAP
BGBW: LDA DVSTAT ; use bytes waiting
STA CHUNK
LDA DVSTAT+1
STA CHUNK+1
BGCAP: JSR CAPCHK ; Cap CHUNK to MAXBURST
;; Fill in the burst read DCB
LDA ZICDNO
STA BRDCB+1 ; DUNIT
LDA ZICBAL
STA BRDCB+4 ; DBUFL = user buffer
LDA ZICBAH
STA BRDCB+5 ; DBUFH
LDA CHUNK
STA BRDCB+8 ; DBYTL
STA BRDCB+10 ; DAUX1 (bytes to read)
LDA CHUNK+1
STA BRDCB+9 ; DBYTH
STA BRDCB+11 ; DAUX2
JSR BTIM ; DTIMLO scaled by size
STA BRDCB+6 ; DTIMLO
LDA RELOC_BRDCB ; Do the SIO read
LDY RELOC_BRDCB+1
JSR DOSIOV
LDY DSTATS ; Success?
CPY #$01
BNE BGERR ; No -> return error
JSR ADVBUF ; Advance past all but the last byte
;; Refresh the STATUS cache (we skipped SVSTAT). The 'R' read
;; went to the user buffer, so DVSTAT+2/+3 still hold the poll.
JSR GDIDX ; Unit into X
LDA DVSTAT+2 ; Connection state
STA DVS2,X
LDA DVSTAT+3 ; Last error
STA DVS3,X
;; If we drained everything that was waiting, zero the cached
;; bytes-waiting and clear TRIP so the next GET blocks for
;; fresh data (like the one-byte drain path does).
LDA CHUNK
CMP DVSTAT
BNE BGTRP
LDA CHUNK+1
CMP DVSTAT+1
BNE BGTRP
TXA
ASL ; unit*2
TAX
LDA #$00
STA BW,X ; BW[unit*2]
STA BW+1,X
STA TRIP
BGTRP: JSR DIPRCD ; Disable PROCEED
LDY #$00
LDA (ZICBAL),Y ; A = last byte, for CIO to store
LDY #$01 ; Success
RTS
;; SIO error during burst; return status (extended if 144)
BGERR: CPY #144
BNE BGERTS
JSR POLL
LDY DVSTAT+3
BGERTS: RTS
;;; BURST PUT ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Write the whole remaining buffer (up to MAXBURST) in one
;; SIO call, straight from the user's buffer. Advance
;; ZICBAL/ZICBLL past all but the last byte; CIO's final
;; +1/-1 accounts for it. The byte CIO handed us is the
;; first byte of the block, re-sent from memory.
BPUT: LDA ZICBLL ; CHUNK = remaining length
STA CHUNK
LDA ZICBLH
STA CHUNK+1
JSR CAPCHK ; Cap CHUNK to MAXBURST
LDA ZICDNO
STA BWRCB+1 ; DUNIT
LDA ZICBAL
STA BWRCB+4 ; DBUFL = user buffer
LDA ZICBAH
STA BWRCB+5 ; DBUFH
LDA CHUNK
STA BWRCB+8 ; DBYTL
STA BWRCB+10 ; DAUX1 (bytes to write)
LDA CHUNK+1
STA BWRCB+9 ; DBYTH
STA BWRCB+11 ; DAUX2
JSR BTIM ; DTIMLO scaled by size
STA BWRCB+6 ; DTIMLO
LDA RELOC_BWRCB ; Do the SIO write
LDY RELOC_BWRCB+1
JSR DOSIOV
LDY DSTATS
CPY #$01
BNE BPERR
JSR ADVBUF ; Advance past all but the last byte
LDY #$01 ; Success
RTS
BPERR: CPY #144
BNE BPERTS
JSR POLL
LDY DVSTAT+3
BPERTS: RTS
;;; ADVANCE CIO BUFFER BY (CHUNK-1) ;;;;;;;;;;;;;
;; ZICBAL += CHUNK-1 ; ZICBLL -= CHUNK-1
;; Leaves CIO pointing at the last transferred byte with one
;; count still to go, which its own +1/-1 then consumes.
ADVBUF: LDA CHUNK ; DECR = CHUNK - 1
SEC
SBC #$01
STA DECR
LDA CHUNK+1
SBC #$00
STA DECR+1
CLC ; ZICBAL += DECR
LDA ZICBAL
ADC DECR
STA ZICBAL
LDA ZICBAH
ADC DECR+1
STA ZICBAH
SEC ; ZICBLL -= DECR
LDA ZICBLL
SBC DECR
STA ZICBLL
LDA ZICBLH
SBC DECR+1
STA ZICBLH
RTS
;;; CAP CHUNK TO MAXBURST ;;;;;;;;;;;;;;;;;;;;;;;
;; Relies on MAXBURST's low byte being 0: if CHUNK's hi byte
;; reaches MAXBURST's hi byte the value is already >= MAXBURST.
CAPCHK: LDA CHUNK+1
CMP #>MAXBURST
BCC CAPRTS ; hi < MAXBURST hi -> under cap
LDA #<MAXBURST ; else clamp to MAXBURST
STA CHUNK
LDA #>MAXBURST
STA CHUNK+1
CAPRTS: RTS
;;; SCALE DTIMLO WITH TRANSFER SIZE ;;;;;;;;;;;;;
;; A big DBYT needs a proportionally longer SIO timeout or it
;; lapses mid-transfer. Base $1F plus CHUNK's hi byte, capped
;; at $FF -> ~one extra unit per 256 bytes. Returns DTIMLO in A.
BTIM: LDA CHUNK+1
CLC
ADC #$1F
BCC BTIMR
LDA #$FF
BTIMR: RTS
RELOCATE_CODE_END:
; ----------------------
; ---- DATA SECTION ----
; ----------------------
READCB .BYTE DEVIDN ; DDEVIC
.BYTE $FF ; DUNIT
.BYTE 'R' ; DCOMND
.BYTE DSREAD ; DSTATS
rel100 .WORD RBUF ; DBUF
.BYTE $1F ; DTIMLO
.BYTE $00 ; DRESVD
.BYTE $FF ; DBYTL
.BYTE $00 ; DBYTH
.BYTE $FF ; DAUX1
.BYTE $00 ; DAUX2
;;; END SUBROUTINES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
FLUDCB: .BYTE DEVIDN ; DDEVIC
.BYTE $FF ; DUNIT
.BYTE 'W' ; DCOMND
.BYTE DSWRIT ; DSTATS
rel101 .WORD TBUF ; DBUFL
.BYTE $1F ; DTIMLO
.BYTE $00 ; DRESVD
.BYTE $FF ; DBYTL
.BYTE $00 ; DBYTH
.BYTE $FF ; DAUX1
.BYTE $00 ; DAUX2
POLDCB: .BYTE DEVIDN ; DDEVIC
.BYTE $FF ; DUNIT
.BYTE 'S' ; DCOMND
.BYTE DSREAD ; DSTATS
.WORD DVSTAT ; DBUF
.BYTE $1F ; DTIMLO
.BYTE $00 ; DRESVD
.WORD 4 ; 4 bytes
.BYTE $00 ; DAUX1
.BYTE $00 ; DAUX2
;;; DEVICE HANDLER TABLE ;;;;;;;;;;;;;;;;;;;;;;;;;
DEVHDL:
rel110 .WORD OPEN-1
rel111 .WORD CLOSE-1
rel112 .WORD GET-1
rel113 .WORD PUT-1
rel114 .WORD STATUS-1
rel115 .WORD SPECIAL-1
;; OPEN DCB TABLE
OPNDCB:
.BYTE DEVIDN ; DDEVIC
.BYTE $FF ; DUNIT
.BYTE 'O' ; DCOMND
.BYTE DSWRIT ; DSTATS
.BYTE $FF ; DBUFL
.BYTE $FF ; DBUFH
.BYTE $1F ; DTIMLO
.BYTE $00 ; DRESVD
.BYTE $00 ; DBYTL
.BYTE $01 ; DBYTH
.BYTE $FF ; DAUX1
.BYTE $FF ; DAUX2
CLODCB .BYTE DEVIDN ; DDEVIC
.BYTE $FF ; DUNIT
.BYTE 'C' ; DCOMND
.BYTE $00 ; DSTATS
.BYTE $00 ; DBUFL
.BYTE $00 ; DBUFH
.BYTE $1F ; DTIMLO
.BYTE $00 ; DRESVD
.BYTE $00 ; DBYTL
.BYTE $00 ; DBYTH
.BYTE $00 ; DAUX1
.BYTE $00 ; DAUX2
SPQDCB .BYTE DEVIDN ; DDEVIC
.BYTE $FF ; DUNIT
.BYTE $FF ; DCOMND ; inq
.BYTE DSREAD ; DSTATS
rel120 .WORD INQDS ; DBUFL, DBUFH
.BYTE $1F ; DTIMLO