-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread.aii
808 lines (613 loc) · 9.36 KB
/
read.aii
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
string asis
include 'gsos.equ'
include 'minix.equ'
include 'records.equ'
include 'fst.equ'
include 'fst.macros'
include 'M16.Debug'
include 'p.equ'
import do_ignore
import init_fcr
import init_vcr
import read_data_block
entry memcpy
entry do_transfer_count
entry do_data_buffer
entry do_request_count
entry init_block
entry next_block
entry slow_read
entry read_direct_block
entry read_partial_block
entry getchar
entry build_nl_table
import disk_inode:v1_inode
my_dp record dp.__end
dataBuffer ds.l 1
requestCount ds.l 1
transferCount ds.l 1
mark ds.l 1
mtc ds.l 1
count ds.w 1 ; count from partial block read
block ds.w 1 ; current block for reading.
zone ds.l 1
nl_mask ds.w 1
IF *>=$d4 THEN
AERROR 'dp -- too large.'
ENDIF
endr
data record
nl_table ds.b 256
endr
;
; read logic...
; if (mark & 1024-1) read partial block
; while (transferCount >= 1024) direct read into dataBuffer
; if (transferCount & 1024 - 1) read partial block
do_transfer_count procname
with fst_parms, my_dp
lda transferCount
sta [param_blk_ptr],y
iny
iny
lda transferCount+2
sta [param_blk_ptr],y
rts
endp
do_data_buffer procname
with fst_parms, my_dp
lda [param_blk_ptr],y
sta dataBuffer
iny
iny
lda [param_blk_ptr],y
sta dataBuffer+2
rts
endp
do_request_count procname
with fst_parms, my_dp
lda [param_blk_ptr],y
sta requestCount
iny
iny
lda [param_blk_ptr],y
sta requestCount+2
rts
endp
do_cache_priority procname
with fst_parms, my_dp, dp
lda [param_blk_ptr],y
; 0 or 1 only.
cmp #2
bcs pre
sta dev_parms.dev_cache_pr
rts
pre
lda #parm_range_err
sta tool_error
rts
endp
entry set_zone
init_block procname
with my_dp
lda mark+1
sta zone
lda mark+3
and #$00ff
sta zone+2
lsr zone+2
ror zone
lsr zone+2
ror zone
ldx zone
bra set_zone
endp
; updates block, zone, etc.
; find the block to read.
next_block procname
with my_dp, dp, v1
ldx zone
inx
inx
stx zone
entry set_zone
set_zone
cpx #NR_DZONES*2
bcc direct
indirect
double_indirect
; todo ...
lda #damaged_bitmap
sec
rts
direct
lda disk_inode.zone,x
sta block
clc
rts
endp
read procname export
with dp, my_dp, fst_parms
;
jsr init_vcr
jsr init_fcr
; zero-out transferCount, even if there's an error
; later
ldy call_class
lda tc_table,y
tay
lda #0
sta [param_blk_ptr],y
iny
iny
sta [param_blk_ptr],y
;brk $ea
;~DebugSetTrace #1
; can only read from regular files or links.
lda disk_inode.mode
and #S_IFMT
cmp #S_IFREG
beq @ok
cmp #S_IFLNK
beq @ok
lda #bad_store_type
sec
rtl
@ok
; offset is 2 for class 0, 4 for class 1!
; check for read-access
ldy #fcr.access
lda [<my_fcr],y
and #read_access
bne @access_ok
lda #invalid_access
sec
rtl
@access_ok
stz transferCount
stz transferCount+2
ldy #fcr.mark
lda [my_fcr],y
sta mark
iny
iny
lda [my_fcr],y
sta mark+2
lda call_class
beq class0
class1
lda [param_blk_ptr] ; pcount
dec a
asl a ; x 2
asl a ; x 4
tax
dispatch read_dcb_1
lda tool_error
beq class_over
sec
rtl
class0
ldx #read_dcb_0_size-4
dispatch read_dcb_0
bra class_over
read_dcb_1
with IORecGS
dc.w refNum, do_ignore
dc.w dataBuffer, do_data_buffer
dc.w requestCount, do_request_count
dc.w transferCount, do_ignore
dc.w cachePriority, do_cache_priority
endwith
read_dcb_0
with FileIORec
dc.w fileRefNum, do_ignore
dc.w dataBuffer, do_data_buffer
dc.w requestCount, do_request_count
dc.w transferCount, do_ignore
endwith
read_dcb_0_size equ *-read_dcb_0
class_over
; end of file?
lda mark+2
cmp disk_inode.size+2
bcc noteof
lda mark
cmp disk_inode.size
bne noteof
eof
lda #end_of_file
sec
rtl
noteof
; if requestCount is 0, just quit now!
lda requestCount
ora requestCount+2
bne @rc
lda #0
clc
rtl
@rc
; transferCount can't go past the eof mark...
tc
; mtc -- max transferCount
sec
lda disk_inode.size
sbc mark
sta mtc
lda disk_inode.size+2
sbc mark+2
sta mtc+2
; if negative, we have a problem...
bmi eof
; if 0, end of file...
ora mtc
beq eof
lda requestCount+2
cmp mtc+2
bcc @ok
beq @lw
bra @toobig
@lw ; low word
lda requestCount
cmp mtc
beq @ok
bcc @ok
@toobig
lda mtc
sta requestCount
lda mtc+2
sta requestCount+2
@ok
jsr init_block
bcs exit
; we are ok to read!
; check for new line mode...
jsr build_nl_table
bcs normal_read
jsr slow_read
bcc done
rtl
normal_read
; currently limited to 7 zones, anyhow!
; first block may have extra work since it may be offset into a block.
; (should store block in the fcr)
lda mark
and #1024-1
beq aligned
jsr read_partial_block
bcs exit
aligned
; while transferCount >= 1024 { read_direct_block }
lda requestCount+2
bne @read
lda requestCount
beq done
cmp #1024
bcc tail
@read
jsr read_direct_block
bcs exit
bra aligned
tail
; read a partial tail block.
; set up block...
jsr read_partial_block
bcs exit
done
; read complete!
; todo -- update fcr, transferCount
ldy #fcr.mark
lda mark
sta [my_fcr],y
iny
iny
lda mark+2
sta [my_fcr],y
; eventually, data_zone, data_block.
ldx call_class
lda tc_table,x
tay
lda transferCount
sta [param_blk_ptr],y
iny
iny
lda transferCount+2
sta [param_blk_ptr],y
;~DebugSetTrace #0
lda tool_error
cmp #1
rtl
exit
rtl
tc_table dc.w FileIORec.transferCount, IORecGS.transferCount
endp
update_counts procname
with my_dp
; mark += count
lda count
clc
adc mark
sta mark
lda #0
adc mark+2
sta mark+2
;dataBuffer += count
lda count
clc
adc dataBuffer
sta dataBuffer
lda #0
adc dataBuffer+2
sta dataBuffer+2
; transferCount += count
lda count
clc
adc transferCount
sta transferCount
lda #0
adc transferCount+2
sta transferCount+2
;
; requestCount -= count
lda requestCount
sec
sbc count
sta requestCount
lda requestCount+2
sbc #0
sta requestCount+2
; a = requestCount+2
ora requestCount
beq done
jmp next_block
done
clc
rts
endp
; todo -- should read block into fcr, update fcr.
read_partial_block procname
; read a block into io_buffer, then copy the parts we want into dataBuffer.
; a = block number.
with my_dp, dp
; count = 1024 - (mark & 0x1023)
lda mark
and #1024-1
rsb #1024
sta count
lda requestCount+2
bne @ok
lda requestCount
cmp count
bcs @ok
; requestCount is less than count...
sta count
@ok
; assume block, etc are set up.
lda io_buffer
sta dev_parms.dev_buff
lda io_buffer+2
sta dev_parms.dev_buff+2
lda block
jsr read_data_block
bcs exit
; set ptr to the offset...
lda mark
and #1024-1
clc
adc io_buffer
sta ptr
lda #0
adc io_buffer+2
sta ptr+2
lda count
jsr memcpy
jmp update_counts
exit
rts
endp
read_direct_block procname
with dp, my_dp
; set up for direct read!
lda dataBuffer
sta dev_parms.dev_buff
lda dataBuffer+2
sta dev_parms.dev_buff+2
lda block
jsr read_data_block
bcs exit
lda #1024
sta count
jmp update_counts
exit
rts
endp
memcpy procname
; copy from ptr to dataBuffer
; a = count
;pha ; save
; all registers are clobbered.
with dp, my_dp
lsr a ; / 2
beq last_byte
tax
ldy #0
loop
lda [ptr],y
sta [dataBuffer],y
iny
iny
dex
bne loop
last_byte
;pla
; carry still set...
bcc done
short m
lda [ptr],y
sta [dataBuffer],y
long m
done
rts
endp
macro
fix_count
lda requestCount+2
bne @fini
lda requestCount
cmp count
bcs @fini
sta count
@fini
endm
;
; builds a new-line table, if necessary.
; returns:
; c = 0 if new_line mode enabled.
; c = 1 if new_line mode disabled.
build_nl_table procname
with dp, my_dp
with data
ldy #fcr.mask
lda [my_fcr],y
sta nl_mask
bne @yes
sec
rts
@yes
lda #0
ldx #256-2
zloop
sta nl_table,x
dex
dex
bpl zloop
; newline list is a virtual pointer.
ldy #fcr.newline
lda [my_fcr],y
tax
iny
iny
lda [my_fcr],y
tay
jsl deref
stx ptr
sty ptr+2
ldy #fcr.newline_length
lda [my_fcr],y
tay
dey
ldx #0
short m
nloop
lda [ptr],y
;and nl_mask
tax
lda #$ff
sta nl_table,x
dey
bpl nloop
long m
clc
rts
endp
slow_read procname
with dp, my_dp
; new-line processing is in effect.
; read a block, then copy each character at a time.
; first block may not be aligned.
;jsr build_nl_table
lda mark
and #1024-1
beq aligned
lda block
jsr read_data_block
_rts.cs
; set up ptr.
lda mark
and #1024-1
clc
adc io_buffer
sta ptr
lda #0
adc io_buffer+2
sta ptr+2
; count = (1024 - mark) & 1023
lda #1024
sec
sbc mark
and #1024-1
sta count
; count = min(requestCount,count)
fix_count
jsr getchar
bcs exit
bvs done
lda requestCount
ora requestCount+2
beq done
aligned
lda io_buffer
sta ptr
lda io_buffer+2
sta ptr+2
@loop
; read aligned blocks.
lda block
jsr read_data_block
bcs exit
lda #1024
sta count
fix_count
jsr getchar
bcs exit
bvs done
lda requestCount
ora requestCount+2
bne @loop
done
lda #0
clc
exit
rts
endp
; copies up to count characters from ptr to dataBuffer
; returns v = 1 if eol found,
; returns v = 0 if eol not found.
; (c set from next_block)
; updates mark, transferCount, dataBuffer, requestCount, etc.
;
getchar procname
with dp, my_dp
with data
ldy #0
short m
bloop
lda [ptr],y
sta [dataBuffer],y
iny
and nl_mask
; bit nl_mask+1 ; high bit set if 1-char nl
; bpl @table
; cmp nl_char
; beq @eol
;@table
tax
lda nl_table,x
bne @eol
@next
cpy count
bcc bloop
long m
sty count
jsr update_counts
clv
rts
@eol
; end-of-line!
long m
sty count
jsr update_counts
sep #p.v
rts
endp
end