-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathshsucdri.nsm
1016 lines (899 loc) · 18.7 KB
/
shsucdri.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
;
;****************************************************************************
;
; SHSUCDRI Version 1.00
; Jason Hood, March/May 2005.
; http://shsucdx.adoxa.vze.com/
;
; v1.01, January, 2012.
;
; Create an image of a CD in memory.
;
;****************************************************************************
;
;%define i8086 ; If defined no 386 instructions will be used.
%include "nasm.mac"
%ifdef i8086
cpu 286 ; Minimum 286 required for XMS
%else
cpu 386
%endif
struc rh
.Length resb 1 ; header size in bytes
.Unit resb 1 ; CD drive unit
.Command resb 1 ; device command code
.Status resw 1 ; device command status
.Reserved resb 8
endstruc
struc rhIOCTL
resb rh_size ; RH common
.MediaDesc resb 1
.CBPtr resd 1
.BytesToTransfer resw 1
.StartSector resw 1
.VolIdPtr resd 1
endstruc
struc rhTransfer
resb rh_size ; RH common
resb 1
.DtaPtr resd 1
.SectorCount resw 1
.StartSector resd 1
.ReadMode resb 1 ; we support cooked mode only
resb 1
resb 1
endstruc
rhcmdIOCTL_In equ 03h
rhcmdOpen equ 0Dh
rhcmdClose equ 0Eh
rhcmdReadLong equ 80h
IOCtl_In_RDHACmd equ 0
IOCtl_ReadDriveBytes equ 5
IOCtl_DevStatCmd equ 6
IOCtl_ReturnSectorSize equ 7
IOCtl_ReturnVolumeSize equ 8 ; total sectors on disk
IOCtl_MediaChangedCmd equ 9
IOCtl_AudioDiskInfo equ 10
IOCtl_AudioTrackInfo equ 11
IOCtl_AudioStatusInfo equ 15
MediaChanged_No equ 1
MediaChanged_Yes equ -1
MediaChanged_DontKnow equ 0
DeviceError equ 8000h
DeviceDone equ 0100h
DE_UnknownUnit equ 01h ; OR these with DeviceError
DE_DeviceNotReady equ 02h
DE_UnknownCommand equ 03h
DE_SectorNotFound equ 08h
DE_ReadError equ 0Bh
DriveNormalReady equ 0
; Door closed, door locked, supports only cooked reading, read only,
; data read only, no interleaving, (reserved), no prefetching,
; no audio channel manipulation, supports HSG addressing mode (not Red Book).
SectorSize equ 2048 ; make it an EQU so we don't change it
SectorShift equ 11
; DOS device header with CDROM extension fields
; DO NOT MAKE THE DEVICE DRIVER NAME THE SAME AS THE FILE NAME
CDRIHdr
NextDriver dd -1
dw 0C800h ; attributes for a CDROM
dw Strategy
dw Interrupt
DeviceName db 'SHSU-CDR'
dw 0 ; CDROM reserved
db 0 ; CDROM drive letter
Units db 1 ; number of CD drives on this device
rhAddr dd 0
EMM
bytes dd 0
srch dw 0
srco dd 0
dsth dw 0
dsto dd 0
; 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-CDRIHdr
; Make the IOCtl cases a little easier to read (NOT a general purpose case).
%macro Case 1.nolist
%ifctx case
%$not:
%pop
%endif
%push case
loop %$not
%endmacro
%macro ECase 1.nolist
%$not:
%pop
sub cl, %1 - IOCtl_AudioTrackInfo
jne .err
%endmacro
;************************************************************************
;* Driver Strategy routine
;************************************************************************
Strategy
; ES:BX contains request header pointer, save it.
ses bx, cs:rhAddr
retf
;************************************************************************
;* Driver Interrupt routine
;************************************************************************
Interrupt
pushf
savea ds,es
%ifdef i8086
save bp
%else
save eax
%endif
cld
zero bp ; = CDRIHdr
; process command
lds bx, [cs:BP_(rhAddr)] ; make sure we have RH addr
movzx. ax, [bx+rh.Command]
jif [bx+rh.Unit] ,ne, ah, .unk
sub al, rhcmdIOCTL_In
if e
les di, [bx+rhIOCTL.CBPtr]
movzx. cx, [es:di] ; 1st byte of DTA is subcommand
inc di ; address of buffer
jcxz .RDHACmd
sub cl, IOCtl_ReadDriveBytes
je .stb ; no bytes read
Case IOCtl_DevStatCmd
.stw2: stosw ; status is 0
.stw: stosw
jmp .done
Case IOCtl_ReturnSectorSize
stosb ; force cooked mode
mov ah, SectorSize >> 8 ; low byte is 0
jmp .stw
.RDHACmd:
stosw ; CDRIHdr = 0
mov ax, cs
jmp .stw
Case IOCtl_ReturnVolumeSize
%ifdef i8086
movw [es:di], i(VolSize)
VolSize iw
scasw
jmp .stw
%else
movl [es:di], i(VolSize)
VolSize id
jmp .done
%endif
Case IOCtl_MediaChangedCmd
inc ax ;MediaChanged_No
.stb: stosb
.done: zero ax
jmp .ddone
Case IOCtl_AudioDiskInfo
stosw ; first and last track numbers
mov ah, 2 ; lead-out track at 00:02:00
jmp .stw2
Case IOCtl_AudioTrackInfo
stosb ; force track 0
mov ah, 2
stosw ; track starts at 00:02:00
stosw
mov al, 01100000b ; data track, digital copy permitted
jmp .stb
ECase IOCtl_AudioStatusInfo
stosw ; not paused
stosw ; starting location
stosw
jmp .stw2 ; ending location
.unk: mov al, DE_UnknownUnit
db 0b9h ; MOV CX, nnnn
.err: mov al, DE_UnknownCommand
jmp .erxit
fi
sub al, rhcmdOpen - rhcmdIOCTL_In
je .ddone
dec ax ;rhcmdClose
je .ddone
cmp al, rhcmdReadLong - rhcmdClose
jne .err
; Limit read to 62Ki.
mov ax, [bx+rhTransfer.SectorCount]
if ax ,a, 31
mov ax, 31
mov [bx+rhTransfer.SectorCount], ax
fi
shl ax, SectorShift
jz .ddone
mov [cs:bytes], ax
mmovd cs:BP_(dsto), bx+rhTransfer.DtaPtr
save ds
call ReadImage
restore
if nz
zerow [bx+rhTransfer.SectorCount]
.erxit: mov ah, DeviceError >> 8
fi
.ddone: or ax, DeviceDone
mov [bx+rh.Status], ax
restore
restore
popf
retf
;+
; FUNCTION : ReadImage
;
; Read the sectors from XMS.
;
; Parameters:
; BX -> request header
;
; Returns:
; AL := 0 for all bytes read (and ZR)
; device error code otherwise (and NZ)
;
; Destroys:
;
;-
ReadImage
ldd bx+rhTransfer.StartSector
ld ds, cs
mov si, EMM
%ifdef i8086
repeat 3
shl ax, 1
rcl dx, 1
next
mov [si+6+1], ax ; srco
mov [si+6+3], dl
%else
shl eax, SectorShift
mov [si+6], eax
%endif
mov ah, 0bh
icallf xms
ibit al, 0 ; 0 -> 1 failed, 1 -> 0 succeeded
shl al, 3 ; DE_SectorNotFound
ret
EndOfRes
;============================================================================
; everything below this line is discarded after installing the driver
CopyrightMsg
dln "SHSUCDRI by Jason Hood <[email protected]>."
dln "Version 1.01 (24 January, 2012). Freeware."
dln "http://shsucdx.adoxa.vze.com/"
CRLF dlz
HelpMsg
dln "Simulate a CD-ROM using an image created in memory."
dln
dln "SHSUCDRI [/D:drive] [/L:mem] [/C] [/V] [/U] [/Q[Q]]"
dln
dln " /D:drive Drive letter of CD (default is first)."
dln " /L:mem Leave this many mebibytes of XMS free or don't load."
dln " /C Use conventional memory instead of loading high."
dln " /V Display memory usage (only at install)."
dln " /U Unload."
dln " /Q Quiet - don't display sign-on banner."
dln " /QQ Really quiet - don't display anything."
dln
dlz "The name of the device driver is SHSU-CDR."
%define ln 13,10
%define ht 9
%ifdef i8086
WrongCPUMsg dlz "Must have at least a 286."
%else
WrongCPUMsg dlz "Must have at least a 386."
WrongXMSMsg dlz "Must have XMS v3."
%endif
WrongDOSMsg dlz "Must be DOS 3.3 or later."
NoXMSMsg dlz "XMS driver not found."
InstallMsg dlz ln,"SHSU-CDR CD image driver installed."
UnInstallMsg dlz ln,"SHSUCDRI uninstalled and memory freed."
CouldNotRemoveMsg dlz ln,"SHSUCDRI can't uninstall."
NotInstalledMsg dlz ln,"SHSUCDRI not installed."
LeaveMsg dlz "/L: one or two digits expected (maximum 63)."
DriveMsg dz "D: "
InvalidDriveMsg dlz "invalid drive"
ReadErrorMsg dlz "read error"
ImageTooBigMsg dlz "too big for memory"
UnitMsg dlz "Unit 0"
MemoryUsage dln
dz "Memory Usage"
MemoryHigh dlz " (loaded high)"
MemoryBytes db " Static: "
MemoryStatic dln "00000 bytes"
db " Dynamic: "
MemoryDynamic dln "00000 bytes"
db " Total: "
MemoryTotal dln "00000 bytes"
db " XMS: "
MemoryXMS dlz "00000 kibibytes"
ArgumentNotFound EQU 2 ; Unrecognized argument
NoArgumentsFound EQU 1 ; No argument in command line
ArgumentFound EQU 0 ; Ok argument in command line
segment bss align=2
buf resb 32768
DriveNum resw 1
PSP resw 1
ResSeg resw 1
segment text
DOffset dw EndOfRes
XMSsize dd 0
XMSleave dd 0
Quiet dflg off
Silent dflg off
Verbose dflg off
Ignore dflg off
Reloc dflg on
Progress dz 8,8,8, "000" ; let's assume < 1000MiB
procount db 32
prosize dd 0
;+
; FUNCTION : MsgOut
;
; Output a NUL-terminated string.
;
; Parameters:
; SI -> message
;
; Returns:
; Nothing.
;
; Destroys:
; AX,DL,SI
;-
MsgOut
retif [Silent]
mov ah, 02h ; display ch function
when
prch. al
while
lodsb
is al nzr
return
%macro Output 0-1.nolist
%if %0 == 1
mov si, %1
%endif
call MsgOut
%endmacro
Wrong: Output
mov si, NotInstalledMsg
Xit: Output
exit 1
RC equ $-4
;+
; FUNCTION : Entry point
;-
..start
ld ds, cs
mov [PSP], es
cld
; check processor. Based on code by Henrik Haftmann.
cpu 8086
mov si, WrongCPUMsg
push sp ; Check for 80286
pop ax
jif ax ,ne, sp, Xit
%ifdef i8086
cpu 286
%else
pushf ; Now check for 386
pop ax
or ax, 7000h
push ax
popf
pushf
pop ax
jif ax ,&!, 7000h, Xit
cpu 386
%endif
; get DOS version
mov si, WrongDOSMsg
dos 30h
jif {al ,b, 3} OR e AND {ah ,b, 10}, Xit
; get the XMS driver address
mov si, NoXMSMsg
mov bx, -1
mpx 4310h
inc bx
jz Xit
dec bx
sthl es,bx, xms
%ifndef i8086
; check for v3
mov ah, 0
call far [xms]
mov si, WrongXMSMsg
jif ah ,b, 3, Wrong
%endif
mov es, [PSP]
mov al, 'Q' ; /Q quiet
call GetParm
if al ,e, ArgumentFound
sflg. [Quiet]
mov al, [es:di+1]
cbit al, 5
if. {al ,e, 'Q'}, sflg. [Silent]
fi
mov al, 'U' ; /U uninstall driver
call GetParm
jif al ,e, ArgumentFound, UnInstallCDRI
ifnflg [Quiet], \
Output CopyrightMsg
mov al, '?' ; /? help
call GetParm
if al ,e, ArgumentFound
mov si, HelpMsg
mov [RC], ch ; CH zero from command line length
jmp Xit
fi
mov al, 'C' ; /C "conventional" memory
call GetParm
if. {al ,e, ArgumentFound}, \
cflg. [Reloc]
mov al, 'V' ; /V display memory usage
call GetParm
if. {al ,e, ArgumentFound}, \
sflg. [Verbose]
mov al, 'L' ; /L:mem mebibytes free
call GetParm
if al ,e, ArgumentFound
mov ah, [es:di+1]
if ah ,e, ':'
inc di
mov ah, [es:di+1]
fi
mov si, LeaveMsg
sub ah, '0'
jif ah ,a, '9', Wrong
mov al, [es:di+2]
sub al, '0'
if al ,be, '9'
aad
jif al ,ae, 64, Wrong
else
movzx. ax, ah
fi
shl ax, 10
%ifdef i8086
push ax
mov ah, 8 ; query free XM
call far [xms]
pop bx
sub ax, bx
mov [XMSleave], ax
%else
push 0
push ax
mov ah, 88h
call far [xms]
pop ebx
sub eax, ebx
mov [XMSleave], eax
%endif
mov si, ImageTooBigMsg
jc Wrong
fi
mov al, 'D' ; /D:drive
call GetParm
mov si, InvalidDriveMsg
if al ,e, ArgumentFound
mov cl, [es:di+1]
cmov {cl ,e, ':'}, cl, [es:di+2]
cbit cl, 5
mov [DriveMsg], cl
sub cl, 'A'
mov [DriveNum], cx ; CH zero from command line length
mpx 150bh
jzr ax, Wrong
else
zero cx
mpx 1500h
jzr cx, Wrong
mov [DriveNum], cx
add cl, 'A'
mov [DriveMsg], cl
fi
Output DriveMsg
; Read the PVD, get the volume size
mov cx, [DriveNum]
zero si
mov di, 16
mov dx, 1
ld es, cs
mov bx, buf
mpx 1508h
mov si, ReadErrorMsg
jc Wrong
; see if we have the ISO or HS signatures
ifw {[buf+1] ,e, 'CD'} AND {word [buf+3] ,e, '00'} ; '1'
; found ISO, position the volume offset
mov di, buf+80
elifw {[buf+9] ,e, 'CD'} AND {word [buf+11] ,e, 'RO'} ; 'M'
; found HS, position the volume offset
mov di, buf+88
fi
mov si, InvalidDriveMsg
jne Wrong
ifnflg [Quiet]
lea si, [di-40] ; volume label
zerob [si+11]
Output
prch. ' '
fi
mov si, ImageTooBigMsg
%ifdef i8086
mov dx, [di]
jif {[di+2] nzw} OR {dx ,ae, 8000h}, Wrong ; only 64Mi allowed
mov [VolSize], dx
shl dx, 1
jif {[XMSleave] nzw} AND {[XMSleave] ,b, dx}, Wrong
mov ah, 9 ; allocate XM
pushb 0
push dx
%else
mov edx, [di]
mov [VolSize], edx
shl edx, 1
jif {[XMSleave] nzd} AND {[XMSleave] ,b, edx}, Wrong
mov ah, 89h
push edx
%endif
call far [xms]
dec ax
pop cx
pop ax
jnz Wrong
add [XMSsize], cx
adc [XMSsize+2], ax
mov [dsth], dx
call CopyImage
Output UnitMsg
mmovw [srch], [dsth]
zerow [dsth] ; reset destination back to normal memory
%ifdef i8086
zerob [srco] ; not set by ReadImage
%endif
mov cx, [DOffset]
call Link
ifflg [Verbose], call DisplayMemory
Output InstallMsg
ifflg [Reloc], exit 0
mov ds, [PSP]
zero ax
xchg ax, [2Ch] ; find environment and release it
mov es, ax
dos 49h
mov dx, [cs:DOffset]
add dx, 4fh ; first 40h bytes of PSP and rounding
shr dx, 4 ; para to keep
dos 3100h ; stay resident and exit
;+
; FUNCTION : Link
;
; Link the driver into the device chain and relocate.
;
; Parameters:
; CX := number of bytes to relocate
;
; Returns:
;
; Destroys:
;
;-
Link
dos 5200h ; get list of list
add bx, 22h ; ES:BX[22] is NUL device header
mmovd NextDriver, es:bx ; put NUL.next in our header
ifflg [Reloc]
save es,bx
dos 5802h ; get current UMB state
push ax ; save it
dos 5800h ; get current allocation strategy
push ax ; save it
mov bx, 1 ; link in UMB
dos 5803h
cmpw [PSP], 0A000h ; already high?
cmov bl, b, 80h, 0 ; high or low memory, first fit
dos 5801h
mov bx, [DOffset]
add bx, 15 ; paragraph rounding
shr bx, 4 ; bytes to paras
dos 48h
pushf
if nc
mov [ResSeg], ax
dec ax ; MCB of TSR
mov es, ax
inc ax
mov [es:1], ax ; make it own itself
save ds
mov ax, [PSP]
dec ax ; MCB of installer
mov ds, ax
mov si, 8 ; copy the MCB name
mov di, si
times 4 movsw
restore
fi
pop dx
pop bx ; restore allocation strategy
dos 5801h
pop bx ; restore UMB state
dos 5803h
restore
mov ax, [ResSeg]
shr dl, 1
jnc .ok
fi
cflg. [Reloc]
mov ax, [PSP]
add ax, 4
mov [ResSeg], ax
.ok: zero si ; = DVHDHdr
sthl ax,si, es:bx ; point NUL header at us
; relocate into the PSP/allocated memory
mov es, ax
zero di
rep movsb
ret
;+
; FUNCTION : UnInstallCDRI
;
; Remove the driver from the device chain and free the memory.
;
; Parameters:
;
; Returns:
;
; Destroys:
;
;-
UnInstallCDRI
dos 5200h ; get list of list
add bx, 22h ; ES:BX[22] is NUL (1st) device header
repeat
ses bx, buf ; save current header addr
les bx, [es:bx] ; load next header addr into ES:BX
inc bx ; end of drivers?
jz .DriverNotFound
dec bx
mov cx, 8
mov si, DeviceName ; DS:SI is our device name
lea di, [bx+si] ; ES:DI is chained device name
repe cmpsb ; if eq it's the one we are looking for
until e
push es
save ds
ld ds, es ; ES:BX is addr of driver being removed
mov si, bx ; put it into DS:SI
les di, [cs:buf] ; previous header now in ES:DI
times 2 movsw ; move address DS:SI -> ES:DI
mov dx, [srch] ; free the XMS handle
mov ah, 10
call far [xms]
restore
pop ax
sub ax, 4 ; locate the PSP of installed driver
mov es, ax ;
ifw [es:0] ,ne, 20cdh ; PSP signature?
add ax, 4 ; no, point back to driver
mov es, ax ;
fi ;
dos 49h ; free memory
mov si, UnInstallMsg
zerob [RC]
jmp Xit
.DriverNotFound:
mov si, CouldNotRemoveMsg
jmp Xit
;+
; FUNCTION : CopyImage
;
; Copy the image from CD to memory.
;
; Parameters:
; [dsth] := XMS handle
; AX:CX := size of image in KiB
;
; Returns:
;
; Destroys:
;
;-
CopyImage
shr ax, 1 ; convert Ki to Mi
rcr cx, 1
shr ax, 1
rcr cx, 1
mov ah, al
mov al, ch
mov si, Progress+3
mov cx, 3
call itoan
prch ' '
Output Progress+3 ; display mebibytes countdown
mov bx, buf
mov cx, [DriveNum]
zero si
zero di
%ifdef i8086
mmovw [prosize], [VolSize]
%define CNT dx
%define FIN zw
%else
mmovl [prosize], [VolSize]
zero edx
%define CNT edx
%define FIN zd
%endif
sthl cs,buf, srco
mov dx, 16
movw [bytes], 32768
repeat
sub [prosize], CNT
if c
add [prosize], CNT
mov dx, [prosize]
zerow [prosize]
mov ax, dx
shl ax, 11
mov [bytes], ax
fi
mpx 1508h
save si
decb [procount]
if z
mov si, Progress
decb [si+5]
ifb [si+5] ,b, '0'
movb [si+5], '9'
decb [si+4]
ifb [si+4] ,e, '0'
ifb. {[si+3] ,e, ' '}, movb [si+4], ' '
elif b
movb [si+4], '9'
decb [si+3]
ifb. {[si+3] ,e, '0'}, movb [si+3], ' '
fi
fi
Output
mov dx, 16
movb [procount], 32
fi
mov ah, 0bh
mov si, EMM
call far [xms]
restore
add di, 16
adc si, 0
addw [dsto], 32768
adcw [dsto+2], 0
until [prosize] FIN
prch 8
prch.
prch.
prch.
ret
;+
; FUNCTION : DisplayMemory
;
; Display the memory usage.
;
; Parameters:
; [DOffset] := last byte
; [XMSsize] := size of allocated XMS (in KiB)
;
; Returns:
;
; Destroys:
;
;-
DisplayMemory
Output MemoryUsage
cmov si, {word [ResSeg], ae, 0A000h}, MemoryHigh, CRLF
Output
mov ax, [DOffset]
ifnflg [Reloc], \
add ax, 40h ; PSP
dec ax ; round
or al, 15 ; to
inc ax ; paragraph
mov si, MemoryTotal
mov bx, ax
call itoa
cmov ax, [Reloc], EndOfRes, 40h + EndOfRes
mov si, MemoryStatic
sub bx, ax
call itoa
xchg ax, bx
mov si, MemoryDynamic
call itoa
mov si, MemoryXMS
mov ax, [XMSsize]
ifnzw [XMSsize+2] ; if smaller than 64MiB display as KiB
repeat 10 ; otherwise as MiB
shrw [XMSsize+2], 1
rcr ax, 1
next
movw [si+6], 'me'
fi
call itoa
Output MemoryBytes
ret
;+
; FUNCTION : itoa
;
; Convert a binary number to a space-padded string.
;
; Parameters:
; AX := number
; SI -> buffer
;
; Returns:
;
; Destroys:
;
;-
itoa
mov cx, 5
itoan
for si,,*,,+ ; fill with spaces
movb [si], ' '
next
mov cl, 10 ; base
do
zero dx
div cx
dec si
add dl, '0'
mov [si], dl
while ax nzr
ret
;+
; FUNCTION : GetParm
;
; Scans command line for argument of form /X or -X where
; X = specified ASCII character. Presumes that argument is preceded
; by a '/' or a '-'. Comparisons are case insensitive.
;
; Parameters:
; AL := parameter character to scan for
;
; Returns:
; AL := one of the following codes:
; NoArgumentsFound if empty command line
; ArgumentFound if argument found
; ArgumentNotFound if argument not as specified
; ES:DI -> pointer to found argument
; CX := chars left on command line including arg
;
; Destroys:
;
;-
GetParm
mov di, 80h ; command line length PSP +80h
movzx. cx, [es:di]
mov ah, NoArgumentsFound ; assume no /X style arguments
retif cxz
;if. {al ,[], 'a','z'}, cbit al, 5 ; Make character upper case
; Find start of argument
repeat
inc di
mov dl, [es:di] ; Get character from argument list
if dl ,e, {'/','-'} ; Found option prefix
inc di
dec cx