-
Notifications
You must be signed in to change notification settings - Fork 9
/
shsucdx.nsm
4159 lines (3778 loc) · 77.8 KB
/
shsucdx.nsm
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
;
;****************************************************************************
; SHSUCDX Version 3.00
; Jason Hood, September to November, 2004.
; jadoxa@yahoo.com.au
; http://shsucdx.adoxa.vze.com/
;
; v3.01, March, 2005.
; v3.02, April/May, 2005.
; v3.03, December, 2005.
; v3.04, October, 2006.
; v3.05, February, 2011.
; v3.06, September, 2019.
; v3.07, April, 2020.
; v3.08, February, 2021.
; v3.09, September, 2022.
;
;*** Begin original comments (abridged):
;***************************************************************************
;
; SHSUCDX Version 1.4b
; (c) John H. McCoy, October 2000
; csc_jhm@shsu.edu
;
; SHSUCDX is an un-loadable CD-ROM redirector substitute for MSCDEX.
; Version 1.1a supports up to 10 CD drives. Each drive is single
; sector buffered and the last 10 directory entries are cached.
; This version finally fixes (I hope) a problem with handling some
; directory entries. It has also been changes to handle lower case
; characters in directory and file names. LC characters are not
; valid, but some NT/Win95 mastering programs put them in.
;
; Approx 17K of RAM is needed to install SHSUCDX. The resident size
; for a single drive is less than 11K. Each additional drive increases
; the resident size by 2500 bytes. Multiple drivers are supported.
; The driver name, drive letter, drive unit and number of drives from
; each driver can be specified on the command line.
;
; SHSUCDX does not attempt to read the CD ROM until an access request
; is made. Thus, the CD drive does not have to be ready when the
; redirector is loaded. If more than 7 seconds elapse between access
; requests a media check is made. The buffers and cache are flushed
; and the CD is re-read only if the driver reports a media change.
; This reduces network traffic but can result in missing a "fast"
; media change on a local drive.
;
; When SHSUCDX unloads it marks the drives it used as invalid.
;
; SHSUCDX has been run with MS-DOS 4, 5, 6 and 7 stand-alone, under
; Windows 3.1, and in a specific DOS window under OS2.
;
; A CD-ROM driver which supports the CD-ROM extensions must be loaded
; before loading SHSUCDX. By default, SHSUCDX looks for a driver
; named SHSU-CDN.
;
; SHSUCDX is a copyright reserved, free use program.
;
; (c)John H. McCoy, 1994 - 2000 Sam Houston St. Univ., TX 77341-2206
;
; ***************************************************************************
;
; Microsoft has not documented the redirector functions. I have borrowed
; from and am particularly indebted to the authors of:
;
; A CD-ROM redirector for HighSierra and ISO 9660 disks.
; Jim Harper, DDJ, March 1993
; Inside the ISO-9660 Filesystem Format
; William and Lynne Jolitz, DDJ, December 1992
; Undocumented DOS, Chapter 4.
; Andrew Schulman, et. al, Addison Wesley, 1990
;
; Written for MASM 6.0b. C functions compiled with MSC 5.1
;****************************************************************************
;*** End original comments.
;
; This version is a rewrite of the above version and my version 2 into NASM.
; The resident size is now less than 6K for one drive.
; Acknowledgement to Ralf Brown's Interrupt List.
;
;****************************************************************************
;
;%define i8086 ; If defined no 386 instructions will be used.
;%define CDROOT ; If defined use the CD root form of "\\D.\A.\".
%define HS ; If defined include High Sierra support.
%define JOLIET ; If defined use Joliet (required by DOSLFN 0.40a).
%define CDIMAGE ; If defined enables using an image on a CD.
%include "nasm.mac"
%include "undoc.mac"
%include "cdrom.mac"
%ifdef i8086
cpu 8086
%else
cpu 386
%endif
%define A_SUBDIR 10h
; Redirector equates
%define REDIR 11h ; make these defines so mpx can
%define InstallChk 00h ; combine into one word
ChDir equ 05h ; these must be EQU for creating
Close equ 06h ; the table
Read equ 08h
GetSpace equ 0ch
GetAttr equ 0fh
Open equ 16h
FindFirst equ 1Bh
FindNext equ 1Ch
Seek equ 21h
PathName equ 23h
EOpen equ 2eh
NoRedir equ 0ffh ; equate required for table terminator
; MSCDEX equates
%define MSCDEX 15h
%define MSCDEX_Q 0DADAh ; Query
%define MSCDEX_R 0ADADh ; Return
; SMARTDrive equate
%define SMARTDRV_Q 0BABEh
; DOSLFN equates
%define DOSLFN_Q 9877h
%define DOSLFN_R 8766h
; Return codes
%define RC_CPU 255 ; 386 required
%define RC_DOS 254 ; unsupported version of DOS
%define RC_INSTALLED 253 ; already installed
%define RC_CD 252 ; can't find CD driver
%define RC_UNIT 251 ; unit doesn't exist
%define RC_LETTER 250 ; no available drive letter
%define RC_DRIVE 249 ; no drives assigned
%define RC_MEM 248 ; not enough memory
%define RC_UNINST 247 ; can't uninstall
%define RC_OPT 246 ; problem with option
%define RC_OK 0 ; help, tilde/ro, successful uninstall
; 1..32 first drive number (A=1)
%assign COMPILE_FLAG hl(7,0)
%ifdef i8086
%assign COMPILE_FLAG COMPILE_FLAG | bit(0)
%endif
%ifdef CDROOT
%assign COMPILE_FLAG COMPILE_FLAG | bit(1)
%endif
%ifdef HS
%assign COMPILE_FLAG COMPILE_FLAG | bit(2)
%endif
%ifdef JOLIET
%assign COMPILE_FLAG COMPILE_FLAG | bit(3)
%endif
%ifdef CDIMAGE
%assign COMPILE_FLAG COMPILE_FLAG | bit(4)
%endif
%define MAXDRIVES 10
%define CACHEENTRIES 10
%define CACHESIZE CACHEENTRIES * DirEnt_size
%define SECTORSIZE 2048
%define SECTORSHIFT 11
org 100h
jmp Begin
; Credits
db 13 ; overwrite JMP if TYPEd
CopyrightMsg
dln "SHSUCDX by Jason Hood <jadoxa@yahoo.com.au>. | Derived from v1.4b by"
dln "Version 3.09 (2 September, 2022). Freeware. | John H. McCoy, October 2000,"
dlz "http://shsucdx.adoxa.vze.com/ | Sam Houston State University."
db 26
; Put the options here, to make room for the stack.
%macro dopt 2.nolist
dw %2
db %1
%endmacro
Options dopt '?', Opt?
dopt 'C', OptC
dopt 'D', DoDriver
dopt 'E', OptIgn ; MSCDEX: expanded memory
dopt 'I', OptI
dopt 'K', OptIgn ; MSCDEX: Kanji
dopt 'L', DoLetter
dopt 'M', OptIgn ; MSCDEX: buffers
dopt 'Q', OptQ
dopt 'R', OptR
dopt 'S', OptIgn ; MSCDEX: sharing
dopt 'U', OptU
dopt 'V', OptV
dopt '~', Opt~
dopt 255, OptUnk
UnknownOpt db "Unknown option: '"
OptChar dlz "?'."
DInvalid dlz "/D: invalid drive letter."
DUnitNumber dlz "/D: expecting unit number (0-99)."
DMaxNumber dlz "/D: expecting maximum units (1-9)."
LMissingValue dlz "/L: expecting value."
LInvalid dlz "/L: invalid drive letter."
LBadNumber dlz "/L: only two digits allowed."
CritInit:
; zero out the sector buffers (security and directory scan sentinel)
mov di, [Drive+DrvEnt.Bufp]
mov al, 0
mov cx, i(IODatap)
IODatap iw
sub cx, di
rep stosb
; initialise the bottom of the stack (to see how much is actually used)
mov di, local_stack
%ifdef i8086
mov cx, ($-local_stack + 1) / 2
mov ax, 'St'
rep stosw
%else
mov cx, ($-local_stack + 3) / 4
mov eax, 'Stak'
rep stosd
%endif
mov dx, i(KeepSize)
KeepSize iw
mov ax, 4cffh ; exit or go TSR
RC iw
dos
DriverIndex dw Drivers ; initialise here to help the below alignment
SilentFlag dflg off
align 16
Res_Begin equ $-$$+100h - 280*2
local_stack equ $ - 280*2 ; stack goes back into the PSP
throw_sp equ $-2
DriveOfs dw 0 ; EAX, but low word is not needed
scratch dw 0 ; used by 8086 code
_ES dw 0
_DI dw 0
_SI dw 0
DriveNo db 0 ; BP, preserved separately
%ifndef CDIMAGE
ChainFlag
%endif
db 0
CEH_SP dw 0 ; SP, ignored
_BX dw 0
_DX dw 0
_CX dw 0
_AX dw 0
top_stack equ $
_FLAGS dw 0
_SP dw 0
_SS dw 0
%ifdef CDIMAGE
cdxsda_len equ ($-local_stack) / 2
%else
cdxsda_len equ 0
%endif
;Old2F dd 0 ; (inlined)
FN1p dd 0
SDBp dd 0
DTApp dd 0
SAttrp dw 0
;Tildes dw 0 ; 0 truncate names, -1 append tilde (inlined)
%ifdef i8086
setax dw SetAX ; offset for PUSH
%endif
%ifdef CDIMAGE
Active db 1 ; 1 not active, 0 active, -1 swapped, -2 nested
ChainFlag db 0
%else
Active db 0 ; 0 not active, -1 active, -2 nested
%endif
;FirstDriveNo db 0 ; (inlined)
;NoDrives dw MAXDRIVES ; (inlined)
ResDrives db 0 ; number of drives available for use
file_name times 11 db 0 ; FCB name from PathLookup \ expected
dir_name times 11 db 0 ; FCB name from directory / consecutively
%ifdef JOLIET
Joliet dflg off
%endif
; Use BP to access variables, since it's shorter than direct memory access
; (one byte for displacement, instead of two bytes for address).
%define BP_(var) bp+var-top_stack
; Use a MOV instruction to jump one or two bytes.
%define jmp1 db 0b1h ; B1 nn = MOV CL, nn
%define jmp2 db 0b9h ; B9 nn nn = MOV CX, nnnn
rh_io
istruc rhIOCTL
at rhIOCTL.Header
istruc rh
at rh.Length, db rhIOCTL_size
at rh.Command, db rhcmdIOCTL_In
iend
at rhIOCTL.CBPtr, dw IoCB_MediaChange
at rhIOCTL.Bytes, dw 2
iend
rh_rl
istruc rhReadLong
at rhReadLong.Header
istruc rh
at rh.Length, db rhReadLong_size
at rh.Command, db rhcmdReadLong
iend
iend
; IOCTL-in control blocks
IoCB_MediaChange db 9
MediaChange db 0 ; 0 don't know
; 1 not changed
; 0FFh media changed
CD_Table dw CD_Number ; 00 Get number of CD-ROM drives
dw CD_Device ; 01 Get CD-ROM drive device list
dw CD_CAB ; 02 Get copyright file ID
dw CD_CAB ; 03 Get abstract file ID
dw CD_CAB ; 04 Get bibliographic file ID
dw CD_VTOC ; 05 Read VTOC
dw CD_unsupported ; 06 Turn debugging on
dw CD_unsupported ; 07 Turn debugging off
dw CD_Read ; 08 Absolute disk read
dw CD_unsupported ; 09 Absolute disk write
dw CD_unsupported ; 0A Reserved
dw CD_Check ; 0B CDROM drive check
dw CD_Version ; 0C MSCDEX version
dw CD_Letters ; 0D Get CD-ROM drive letters
%ifdef JOLIET
dw CD_VolDesc ; 0E Get/Set vol. descriptor preference
%else
dw CD_unsupported ; 0E Get/Set vol. descriptor preference
%endif
dw CD_DirEntry ; 0F Get directory entry
dw CD_Request ; 10 Send device request
; Redirector table (needs to be ordered by number).
%macro dr 1.nolist
db %1
dw RD_%1
%endmacro
RD_Table dr ChDir
dr Close
dr Read
dr GetSpace
dr GetAttr
dr Open
dr FindFirst
dr FindNext
dr Seek
dr EOpen
dr NoRedir
Installed:
push bp
mov bp, sp
ifw [bp+fr_Parm1] ,e, MSCDEX_Q
%ifdef i8086
movw [bp+fr_Parm1], MSCDEX_R
%else
rolw [bp+fr_Parm1], 4
%endif
fi
if bx ,e, SMARTDRV_Q
mov bx, COMPILE_FLAG
ld es, cs
mov di, Drive
mov cx, [cs:NoDrives]
mov dx, DrvEnt_size
fi
mov al, 0ffh
pop bp
iret
New2F
; is this call for us?
jif ah ,e, REDIR, TestInstall
jif ah ,e, MSCDEX, Main
Chain:
ijmpf Old2F ; chain out
TestInstall:
jif al ,e, PathName, Chain ; called a lot, so handle it directly
jif al ,e, InstallChk, Installed
Main:
; save registers and switch to local stack
push ds
ld ds, cs
cld
decb [Active] ; 1 --> 0 == PE, PL
jpo nested ; 0 --> -1 == PE, NG
%ifdef CDIMAGE ; -1 --> -2 == PO
if. s, call Swapcdx
%endif
push bp
mov bp, sp
mov bp, [bp+2+fr_Flags]
mov [_FLAGS], bp
sss sp, _SP
cli
ld ss, cs
mov sp, top_stack
;sti
mov bp, sp
pusha.
%ifdef i8086
save es,ax,ax
%else
save es,eax
%endif
call Main2F
cli
incb [BP_(Active)] ; none of the below affects the flags
; restore registers and switch back to caller's stack
restore
popa.
mov sp, [_FLAGS]
lss. bp, _SP
mov [bp+2+fr_Flags], sp
%ifdef i8086
mov sp, bp
pop bp
%else
leave
%endif
%ifdef CDIMAGE
if. z, call Swapcdx ; -1 --> 0 == ZR
%endif ; 0 --> 1 == NZ
decb [ChainFlag]
cexit:
pop ds
;sti
js Chain
iret
nested:
incb [Active]
jmp cexit
%ifdef CDIMAGE
Swapcdx uses es,si,di,cx
mov si, cdxsda
mov di, local_stack
if. s, xchg si, di
ld es, cs
mov cx, cdxsda_len
rep movsw
return
%endif
Main2F
movb [BP_(ChainFlag)], 1
drdos: cmp ah, MSCDEX ; (replaced with CALL if using DR-DOS)
if e
; Handle the MSCDEX calls
jif al ,a, 10h, CD_unsupported
cbw
add al, al ; clears carry
xchg bx, ax
%ifdef i8086
pushw [BP_(setax)]
%else
push SetAX ; alternate return address
%endif
call [CD_Table+bx]
pop ax
else
; Handle redirector calls
for bx, RD_Table, ne
cmp [bx], al
lea bx, [bx+3]
ja ChainExit
next
call [bx-2]
SetAX:
mov [_AX], ax
fi
cfbit [BP_(_FLAGS)]
ret
RD_NoRedir:
pop ax ; discard redirector return address
ChainExit:
decb [BP_(ChainFlag)] ; just chain out. Novell doesn't
MExit: ; like it if you call it an error
ret
Err0F: mov al, INVALIDDRIVE
jmp2
CD_unsupported
Err01: mov al, INVALIDFUNC
jmp2
Err03: mov al, PATHNOTFOUND
jmp2
Err02: mov al, FILENOTFOUND
jmp2
Err15: mov al, DRIVENOTREADY
ErrAL: cbw
mov sp, throw_sp
stc
jmp SetAX
; Determine if the various redirector functions are meant for us.
; In: Nothing
; Out: ES:BX -> filename
RedirForUsFN1:
les bx, [BP_(FN1p)]
; In: ES:BX -> filename
; Out: Nothing
RedirForUsDrive:
mov al, [es:bx+DriveOff]
sub al, 'A'
jmp RedirForUs
; In: ES:DI -> SFT
; Out: Nothing
RedirForUsSFT:
mov al, [es:di+SFT.Flags]
; In: AL := drive letter with flags
; Out: Nothing
RedirForUsFlag:
and al, 3fh ; just want drive number
RedirForUs:
call ForUs
cmp al, 0fh
jb MExit ; AL = 0, so for us, return
NotForUs:
pop ax ; Discard return address
je RD_NoRedir ; Invalid drive, not for us
push ax ; Put return address back
; Drive not ready - invoke critical error handler
incb [BP_(Active)] ; If aborted it won't be reset
save es,bp,si,di ; NB: does not reset swap data,
mov [BP_(CEH_SP)], sp ; abort will *really* abort
%ifdef i8086
mov ss, [BP_(_SP)+2] ; Need to use the DOS stack
mov sp, [_SP]
%else
lss sp, [BP_(_SP)]
%endif
mov ah, 00011110b ; Disk data error, allow retry & fail
mov al, [DriveNo]
push ax ; Int 24 error code on stack
mov di, 2 ; Drive not ready
zero bp ; BP:SI driver header (not needed)
zero si
mpx 1206h ; Invoke Critical Error
ld ss, cs
mov sp, [CEH_SP]
restore
decb [BP_(Active)]
jif al ,ne, 1, Err15 ; Didn't retry, drive not ready
mov al, [DriveNo]
jmp RedirForUs
;+
; FUNCTION : SetForUs
;
; Determine if the drive is one of ours.
;
; Parameters:
; CL := drive number (0=A)
;
; Returns:
; If for us:
; DriveNo and DriveOfs set appropriately
; BX restored to client's value
; Does not return if not for us
;
; Destroys:
; AX,CX
;-
SetForUs
xchg ax, cx
call ForUs
jnz ErrAL
mov bx, [BP_(_BX)]
ret
;+
; FUNCTION : SetDDD
;
; Search for matching drive and set DriveOfs and DriveNo.
;
; Parameters:
; CL := drive number (0=A)
;
; Returns:
; ZR if drive is one of ours
; DriveOfs and DriveNo set
; BX := DriveOfs
; CX != 0
; NZ if not our drive
; CX = 0
; BX destroyed
;
; Destroys:
; AX
;-
SetDDD
mov ax, [NoDrives]
mov bx, Drive
xchg cx, ax
inc cx ; clear zero if no drives
jmp .begin
repeat
break [bx+DrvEnt.No] ,e, al
add bx, DrvEnt_size
.begin: next
mov [BP_(DriveOfs)], bx
mov [DriveNo], al
ret
;+
; FUNCTION : ForUs
;
; Determine if the drive is one of ours and initialise it if so.
;
; Parameters:
; AL := drive number (0=A)
;
; Returns:
; ZR if successful
; AL := 00h
; NZ if failed
; AL := 0fh if invalid drive (not for us)
; 15h if drive not ready
;
; Destroys:
; CX
;-
ForUs uses bx,si,di
xchg cx, ax
call SetDDD
mov al, INVALIDDRIVE
retif nz
; Force re-init if it's been a while and the media has changed.
call GetTicks
sub ax, [bx+DrvEnt.LastAccess]
if ax ,ae, 128 ; approx. 7 seconds
save es,bx
ld es, ds
mov bx, rh_io
call DDCall
restore
decb [BP_(MediaChange)] ; cmp MediaChange, not changed
cmovby ne, [bx+DrvEnt.Type], UNKNOWN
fi
; May need to initialize this drive
ifb [bx+DrvEnt.Type] ,e, UNKNOWN
orw [bx+DrvEnt.BufBlkNo+2], -1
call CdReadPVD
mov al, DRIVENOTREADY
retif nz
call InitCD
fi
call GetTicks
mov [bx+DrvEnt.LastAccess], ax
zero al
return
;+
; FUNCTION : GetTicks
;
; Return the clock ticks (low word).
;
; Parameters:
; None.
;
; Returns:
; AX := clock ticks
;
; Destroys:
; None.
;-
GetTicks
uses ds
%ifdef i8086
zero ax
mov ds, ax
%else
ld ds, 0
%endif
mov ax, [46ch]
return
;+
; FUNCTION : InitCD
;
; Initialise the CD structures.
;
; Parameters:
; BX -> drive structure
;
; Returns:
; Nothing.
;
; Destroys:
; EAX,CX,SI,DI
;-
InitCD
; Flush the directory cache
lea si, [bx+DrvEnt.RootEnt]
mov cl, ISO9660 ; CH zero from CdReadPVD in ForUs
for di, [si+DirEnt.Forw], {,ne, si}
mov [di+DirEnt.FName], ch
mov di, [di+DirEnt.Forw]
next
mov di, [bx+DrvEnt.Bufp]
%ifdef i8086
ifw. {[di+isoVol.ID] ,e, 'CD'},\
cmpw [di+isoVol.ID+2], '00'
%else
cmpd [di+isoVol.ID], 'CD00' ; '1' is assumed to follow
%endif
%ifndef HS
retif ne
%else
je .iso
%ifdef i8086
retifw [di+hsVol.ID] ,ne, 'CD'
retifw [di+hsVol.ID+2] ,ne, 'RO'
%else
retifd [di+hsVol.ID] ,ne, 'CDRO' ; 'M' is assumed to follow
%endif
; High Sierra
dec cx ; HIGHSIERRA = ISO9660 - 1
lea si, [di+hsVol.DirRec]
lea di, [di+hsVol.VolID]
jmp .copy
%endif
.iso: ; ISO 9660 (ECMA-119)
lea si, [di+isoVol.DirRec]
lea di, [di+isoVol.VolID]
.copy:
mov [bx+DrvEnt.Type], cl
decw [di+28h+2] ; VolSizeLSB (relative to VolID)
cmov ax, ns, -1, [di+28h]
mov [bx+DrvEnt.VolSize], ax
save es,si
ld es, ds
push di
lea di, [bx+DrvEnt.RootEnt] ; also VLabel
mov al, A_SUBDIR
call DirFieldCopy
pop si
save di
call mov11b
restore
restore
%ifdef JOLIET
jnflg [BP_(Joliet)], .root
%ifdef HS
jifb [bx+DrvEnt.Type] ,e, HIGHSIERRA, .root
%endif
call .root
; Check for Joliet
%ifdef i8086
mov ax, 11h
cwd
%else
zero eax
mov al, 11h
%endif
forb [si-isoVol.DirRec],,nz,+ ; -1 is terminator ID
call CdReadBlk
break nz
ifb [si-isoVol.DirRec] ,e, 2 ; SVD
andifw [si+isoVol.Unused3-isoVol.DirRec] ,e, '%/' ; escape sequence
xchg ax, cx
mov al, [si+isoVol.Unused3+2-isoVol.DirRec]
jif al ,e, {'@','C','E'}, .jol
xchg ax, cx
fi
inc ax
next
return
.jol: mmovd di+DirEnt.FSize, si+Sizeoff
%endif
.root: mmovd di+DirEnt.ParentBlk, si+Blkoff
setblk
mmovd di+DirEnt.BlkNo
%ifndef JOLIET
InitCD.ret:
%endif
ret
;+
; FUNCTION : Redirector functions
;
; Entry points to the various redirector functions.
;
; Parameters:
; BX destroyed (but restored by the RedirForUs... fns)
; All others as per the function
;
; Returns:
; AX & CF according to function.
;-
; 05h: Change directory
; In: SS = DOS DS
; SDA first filename pointer -> fully-qualified directory name
; SDA CDS pointer -> current directory structure for drive with dir
; Out: CF set on error
; AX = DOS error code
; CF clear if successful
; CDS updated with new path
RD_ChDir
call RedirForUsFN1
call LookupDir
jnz RD_exit
jmp Err03
; 06h: Close file
; In: ES:DI -> filled-in SFT (assumed to point at SDA's current SFT field)
; Out: CF set on error
; AX = DOS error code
; CF clear if successful
; SFT updated (redirector must decrement open count, which may be
; done with INT 2F/AX=1208h)
; ES:DI must be preserved
RD_Close
call RedirForUsSFT
decw [es:di+SFT.RefCnt]
if. s, incw [es:di+SFT.RefCnt] ; assume count < 32768
RD_exit:
zero ax ; clears carry
ret
%ifdef i8086
; Shift DX:AX SECTORSHIFT bits to the right.
rshift
repeat SECTORSHIFT
shr dx, 1
rcr ax, 1
next
ret
%endif
; 08h: Read from file
; In: ES:DI -> SFT
; SFT DPB field -> DPB of drive containing file
; CX = number of bytes
; SS = DOS DS
; SDA DTA field -> user buffer
; Out: CF set on error
; AX = DOS error code
; CF clear if successful
; CX = number of bytes read (0000h = end of file)
; SFT updated
RD_Read
call RedirForUsSFT
zero cx
xchg [BP_(_CX)], cx
jcxz RD_exit
%ifdef i8086
%define LEN [BP_(scratch)]
%macro NEXT_SEC 0
add ax, 1
adc dx, si
%endmacro
ldhl si,bx, es:di+SFT.FilSiz
ldd es:di+SFT.FilPos
sub bx, ax
sbb si, dx
jb RD_exit ; Can't read past EOF
; Chop read back if too long
if z AND {cx ,a, bx}
mov cx, bx
jcxz RD_exit
fi
mov [BP_(scratch)], cx
; Calculate block with start of data
mov si, ax
and si, SECTORSIZE-1
call rshift
add ax, [es:di+SFT.FBN]
adc dx, [es:di+SFT.FBN+2]
save es
les bx, [BP_(DTApp)]
les bx, [es:bx]
forw LEN,,nz, -,cx
save di
; [scratch] < SECTORSIZE
jifb {[BP_(scratch)+1] ,b, 8} OR {si nzr}, .part
; Read complete blocks
mov di, [BP_(scratch)]
mov cl, SECTORSHIFT
shr di, cl
xchg cx, di
call CdReadLong
xchg cx, di
jnz .Err15 ; assume drive not ready
add ax, di ; but could use general failure
adc dx, si ; SI = 0
shl di, cl
mov cx, di
jmp .upd
.Err15: jmp Err15
%else ;386
%define LEN dx
%define NEXT_SEC inc eax
ldd es:di+SFT.FilSiz
sub eax, [es:di+SFT.FilPos]
jbe RD_exit ; Can't read past EOF
; Chop read back if too long
if {eax ,&!, 0ffff0000h} AND {cx ,a, ax}
xchg cx, ax
fi
mov dx, cx
; Calculate block with start of data
mov eax, [es:di+SFT.FilPos]
mov si, ax
shr eax, SECTORSHIFT
and si, SECTORSIZE-1
add eax, [es:di+SFT.FBN]
save es
les bx, [BP_(DTApp)]
les bx, [es:bx]