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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
|
page ,160
title bios system initialization
;
;----------------------------------------------------------------------------
;
; Modification history
;
; 26-Feb-1991 sudeepb Ported for NT DOSEm
;----------------------------------------------------------------------------
include version.inc ; set version build flags
include biosseg.inc ; establish bios segment structure
lf equ 10
cr equ 13
tab equ 9
; the following depends on the positions of the various letters in switchlist
switchnum equ 11111000b ; which switches require number
include syscall.inc
include doscntry.inc
include devsym.inc
include ioctl.inc
include devmark.inc ; needed
stacksw equ true ;include switchable hardware stacks
if ibmjapver
noexec equ true
else
noexec equ false
endif
sysinitseg segment public
assume cs:sysinitseg,ds:nothing,es:nothing,ss:nothing
extrn badopm:byte,crlfm:byte,badcom:byte,badmem:byte,badblock:byte
extrn badsiz_pre:byte,badld_pre:byte
extrn dosinfo:dword
extrn memory_size:word,fcbs:byte,keep:byte
extrn default_drive:byte,confbot:word,alloclim:word
extrn buffers:word,zero:byte,sepchr:byte
extrn files:byte
extrn count:word,chrptr:word
extrn bufptr:byte,memlo:word,prmblk:byte,memhi:word
extrn ldoff:word,area:word,packet:byte,unitcount:byte,
extrn break_addr:dword,bpb_addr:dword,drivenumber:byte
extrn com_level:byte, cmmt:byte, cmmt1:byte, cmmt2:byte
extrn cmd_indicator:byte
extrn donotshownum:byte
extrn multdeviceflag:byte
extrn devmark_addr:word
extrn setdevmarkflag:byte
extrn org_count:word
extrn pararound:near
extrn getchr:near
extrn stall:near
extrn error_line:near
extrn DevEntry:dword
insert_blank db 0 ; M051: indicates that blank has been
; M051: inserted
public int24,open_dev,organize,mem_err,newline,calldev,badload
public prndev,auxdev,config,commnd,condev,getnum,badfil,prnerr
public round,delim,print
public parseline,
public setdoscountryinfo,set_country_path,move_asciiz
public cntry_drv,cntry_root,cntry_path
public delim
public pathstring
public MseDev ; NTVDM internal mouse driver
;
;----------------------------------------------------------------------------
;
; procedure : parseline
;
; entry point is parseline. al contains the first character in command line.
;
;----------------------------------------------------------------------------
;
parseline proc near
; don't get character first time
push ds
push cs
pop ds
assume ds:sysinitseg
nextswtch:
cmp al,cr ; carriage return?
jz done_line
cmp al,lf ; linefeed?
jz put_back ; put it back and done
; anything less or equal to a space is ignored.
cmp al,' ' ; space?
jbe get_next ; skip over space
cmp al,'/'
jz getparm
stc ; mark error invalid-character-in-input
jmp short exitpl
getparm:
call check_switch
mov word ptr switches,bx ; save switches read so far
jc swterr
get_next:
call getchr
jc done_line
jmp nextswtch
swterr:
jmp short exitpl ; exit if error
done_line:
test word ptr switches,flagdrive ; see if drive specified
jnz okay
stc ; mark error no-drive-specified
jmp short exitpl
okay:
; mov ax,word ptr switches
; and ax,0003h ; get flag bits for changeline and non-rem
; mov word ptr deviceparameters.dp_deviceattributes,ax
; mov word ptr deviceparameters.dp_tracktableentries, 0
; clc ; everything is fine
; call setdeviceparameters
exitpl:
pop ds
ret
put_back:
inc count ; one more char to scan
dec chrptr ; back up over linefeed
jmp short done_line
parseline endp
;
;----------------------------------------------------------------------------
;
; procedure : check_switch
;
; processes a switch in the input. it ensures that the switch is valid, and
; gets the number, if any required, following the switch. the switch and the
; number *must* be separated by a colon. carry is set if there is any kind of
; error.
;
;----------------------------------------------------------------------------
;
check_switch proc near
call getchr
jc err_check
and al,0dfh ; convert it to upper case
cmp al,'A'
jb err_check
cmp al,'Z'
ja err_check
push es
push cs
pop es
mov cl,byte ptr switchlist ; get number of valid switches
mov ch,0
mov di,1+offset switchlist ; point to string of valid switches
repne scasb
pop es
jnz err_check
mov ax,1
shl ax,cl ; set bit to indicate switch
mov bx,word ptr switches ; get switches so far
or bx,ax ; save this with other switches
mov cx,ax
test ax, switchnum ; test against switches that require number to follow
jz done_swtch
call getchr
jc err_swtch
cmp al,':'
jnz err_swtch
call getchr
push bx ; preserve switches
mov byte ptr cs:sepchr,' ' ; allow space separators
call getnum
mov byte ptr cs:sepchr,0
pop bx ; restore switches
; because getnum does not consider carriage-return or line-feed as ok, we do
; not check for carry set here. if there is an error, it will be detected
; further on (hopefully).
call process_num
done_swtch:
clc
ret
err_swtch:
xor bx,cx ; remove this switch from the records
err_check:
stc
ret
check_switch endp
;
;----------------------------------------------------------------------------
;
; procedure : process_num
;
; this routine takes the switch just input, and the number following (if any),
; and sets the value in the appropriate variable. if the number input is zero
; then it does nothing - it assumes the default value that is present in the
; variable at the beginning. zero is ok for form factor and drive, however.
;
;----------------------------------------------------------------------------
;
process_num proc near
test word ptr switches,cx ; if this switch has been done before,
jnz done_ret ; ignore this one.
test cx,flagdrive
jz try_f
mov byte ptr drive,al
jmp short done_ret
try_f:
test cx,flagff
jz try_t
; ensure that we do not get bogus form factors that are not supported
; mov byte ptr deviceparameters.dp_devicetype,al
jmp short done_ret
try_t:
or ax,ax
jz done_ret ; if number entered was 0, assume default value
test cx,flagcyln
jz try_s
; mov word ptr deviceparameters.dp_cylinders,ax
jmp short done_ret
try_s:
test cx,flagseclim
jz try_h
mov word ptr slim,ax
jmp short done_ret
; must be for number of heads
try_h:
mov word ptr hlim,ax
done_ret:
clc
ret
process_num endp
;
;----------------------------------------------------------------------------
;
; procedure : organize
;
;----------------------------------------------------------------------------
;
assume ds:nothing, es:nothing
organize proc near
mov cx,[count]
jcxz nochar1
call mapcase
xor si,si
mov di,si
xor ax,ax
mov com_level, 0
;org1: call get ;skip leading control characters
; cmp al,' '
; jb org1
org1:
call skip_comment
jz end_commd_line ; found a comment string and skipped.
call get2 ; not a comment string. then get a char.
cmp al, lf
je end_commd_line ; starts with a blank line.
cmp al, ' '
jbe org1 ; skip leading control characters
jmp short findit
end_commd_line:
stosb ; store line feed char in buffer for the linecount.
mov com_level, 0 ; reset the command level.
jmp org1
nochar1:
stc
ret
findit:
push cx
push si
push di
mov bp,si
dec bp
mov si,offset comtab ;prepare to search command table
mov ch,0
findcom:
mov di,bp
mov cl,[si]
inc si
jcxz nocom
repe cmpsb
lahf
add si,cx ;bump to next position without affecting flags
sahf
lodsb ;get indicator letter
jnz findcom
cmp byte ptr es:[di], cr ;the next char might be cr,lf
je gotcom0 ; such as in "rem",cr,lf case.
cmp byte ptr es:[di], lf
je gotcom0
push ax
mov al, byte ptr es:[di] ;now the next char. should be a delim.
call delim
pop ax
jnz findcom
gotcom0:
pop di
pop si
pop cx
jmp short gotcom
nocom:
pop di
pop si
pop cx
mov al,'Z'
stosb ; save indicator char.
skip_line:
call get2
cmp al, lf ; skip this bad command line
jne skip_line
jmp end_commd_line ; handle next command line
gotcom: stosb ;save indicator char in buffer
mov cmd_indicator, al ; save it for the future use.
org2: call get2 ;skip the commad name until delimiter
cmp al, lf
je org21
cmp al, cr
je org21
call delim
jnz org2
jmp short org3
org21: ;if cr or lf then
dec si ; undo si, cx register
inc cx ; and continue
org3:
cmp cmd_indicator, 'Y' ; comment= command?
je get_cmt_token
cmp cmd_indicator, 'I' ; install= command?
je org_file
cmp cmd_indicator, 'D' ; device= command?
je org_file
cmp cmd_indicator, 'S' ; shell= is a special one!!!
je org_file
cmp cmd_indicator, '1' ; switches= command?
je org_switch
jmp org4
org_switch:
call skip_comment
jz end_commd_line_brdg
call get2
call org_delim
jz org_switch
stosb
jmp org5
org_file: ; get the filename and put 0 at end,
call skip_comment
jz org_put_zero
call get2 ; not a comment
call delim
jz org_file ; skip the possible delimeters
stosb ; copy the first non delim char found in buffer
org_copy_file:
call skip_comment ; comment char in the filename?
jz org_put_zero ; then stop copying filename at that point
call get2
cmp al, '/' ; a switch char? (device=filename/xxx)
je end_file_slash ; this will be the special case.
stosb ; save the char. in buffer
call delim
jz end_copy_file
cmp al, ' '
ja org_copy_file ; keep copying
jmp short end_copy_file ; otherwise, assume end of the filename.
get_cmt_token: ; get the token. just max. 2 char.
call get2
cmp al, ' ' ; skip white spaces or "=" char.
je get_cmt_token ; (we are allowing the other special
cmp al, tab ; charaters can used for comment id.
je get_cmt_token ; character.)
cmp al, '=' ; = is special in this case.
je get_cmt_token
cmp al, cr
je get_cmt_end ; cannot accept the carridge return
cmp al, lf
je get_cmt_end
mov cmmt1, al ; store it
mov cmmt, 1 ; 1 char. so far.
call get2
cmp al, ' '
je get_cmt_end
cmp al, tab
je get_cmt_end
cmp al, cr
je get_cmt_end
cmp al, lf
je end_commd_line_brdg
mov cmmt2, al
inc cmmt
get_cmt_end:
call get2
cmp al, lf
jne get_cmt_end ; skip it.
end_commd_line_brdg: jmp end_commd_line ; else jmp to end_commd_line
org_put_zero: ; make the filename in front of
mov byte ptr es:[di], 0 ; the comment string to be an asciiz.
inc di
jmp end_commd_line ; (maybe null if device=/*)
end_file_slash: ; al = "/" option char.
mov byte ptr es:[di],0 ; make a filename an asciiz
inc di ; and
stosb ; store "/" after that.
jmp short org5 ; continue with the rest of the line
end_copy_file:
mov byte ptr es:[di-1], 0 ; make it an asciiz and handle the next char.
cmp al, lf
je end_commd_line_brdg
jmp short org5
org4: ; org4 skips all delimiters after the command name except for '/'
call skip_comment
jz end_commd_line_brdg
call get2
call org_delim ; skip delimiters except '/' (mrw 4/88)
jz org4
jmp short org51
org5: ; rest of the line
call skip_comment ; comment?
jz end_commd_line_brdg
call get2 ; not a comment.
org51:
stosb ; copy the character
cmp al, '"' ; a quote ?
je at_quote
cmp al, ' '
ja org5
; M051 - Start
cmp cmd_indicator, 'U' ; Q: is this devicehigh
jne not_dh ; N:
cmp al, lf ; Q: is this line feed
je org_dhlf ; Y: stuff a blank before the lf
cmp al, cr ; Q: is this a cr
jne org5 ; N:
mov byte ptr es:[di-1], ' ' ; overwrite cr with blank
stosb ; put cr after blank
inc [insert_blank] ; indicate that blank has been
; inserted
jmp org5
not_dh: ; M051 - End
cmp al, lf ; line feed?
je org1_brdg ; handles the next command line.
jmp org5 ; handles next char in this line.
org_dhlf: ; M051 - Start
cmp [insert_blank], 1 ; Q:has a blank already been inserted
je org1_brdg ; Y:
mov byte ptr es:[di-1], ' ' ; overwrite lf with blank
stosb ; put lf after blank
; M051 - End
org1_brdg:
mov [insert_blank], 0 ; M051: clear blank indicator for
; M051: devicehigh
jmp org1
at_quote:
cmp com_level, 0
je up_level
mov com_level, 0 ; reset it.
jmp org5
up_level:
inc com_level ; set it.
jmp org5
organize endp
;
;----------------------------------------------------------------------------
;
; procedure : get2
;
;----------------------------------------------------------------------------
;
get2 proc near
jcxz noget
mov al,es:[si]
inc si
dec cx
od_ret:
ret
noget:
pop cx
mov count,di
mov org_count, di
xor si,si
mov chrptr,si
ng_ret:
ret
get2 endp
;
;----------------------------------------------------------------------------
;
; procedure : skip_comment
;
;skip the commented string until lf, if current es:si-> a comment string.
;in) es:si-> sting
; cx -> length.
;out) zero flag not set if not found a comment string.
; zero flag set if found a comment string and skipped it. al will contain
; the line feed charater at this moment when return.
; ax register destroyed.
; if found, si, cx register adjusted accordingly.
;
;----------------------------------------------------------------------------
;
skip_comment proc near
jcxz noget ; get out of the organize routine.
cmp com_level, 0 ; only check it if parameter level is 0.
jne no_commt ; (not inside quotations)
cmp cmmt, 1
jb no_commt
mov al, es:[si]
cmp cmmt1, al
jne no_commt
cmp cmmt, 2
jne skip_cmmt
mov al, es:[si+1]
cmp cmmt2, al
jne no_commt
skip_cmmt:
jcxz noget ; get out of organize routine.
mov al, es:[si]
inc si
dec cx
cmp al, lf ; line feed?
jne skip_cmmt
no_commt:
ret
skip_comment endp
;
;----------------------------------------------------------------------------
;
; procedure : delim
;
;----------------------------------------------------------------------------
;
delim proc near
cmp al,'/' ; ibm will assume "/" as an delimeter.
jz delim_ret
cmp al, 0 ; special case for sysinit!!!
jz delim_ret
org_delim: ; used by organize routine except for getting
cmp al,' ' ;the filename.
jz delim_ret
cmp al,9
jz delim_ret
cmp al,'='
jz delim_ret
cmp al,','
jz delim_ret
cmp al,';'
delim_ret:
ret
delim endp
;
;----------------------------------------------------------------------------
;
; procedure : newline
;
; newline returns with first character of next line
;
;----------------------------------------------------------------------------
;
newline proc near
call getchr ;skip non-control characters
jc nl_ret
cmp al,lf ;look for line feed
jnz newline
call getchr
nl_ret:
ret
newline endp
;
;----------------------------------------------------------------------------
;
; procedure : mapcase
;
;----------------------------------------------------------------------------
;
mapcase proc near
push cx
push si
push ds
push es
pop ds
xor si,si
convloop:
lodsb
ifdef DBCS
call testkanj
jz normconv ; if this is not lead byte
mov ah,al
lodsb ; get tail byte
cmp ax,DB_SPACE
jnz @f ; if this is not dbcs space
mov word ptr [si-2],' ' ; set 2 single space
@@:
dec cx
jcxz convdone ;just ignore 1/2 kanji error
jmp short noconv
;fall through, know al is not in 'a'-'z' range
normconv:
endif
cmp al,'a'
jb noconv
cmp al,'z'
ja noconv
sub al,20h
mov [si-1],al
noconv:
loop convloop
convdone:
pop ds
pop si
pop cx
ret
ifdef DBCS
public testkanj
testkanj:
push si
push ds
push ax
mov ax,6300h ; get dos dbcs vector
int 21h
pop ax
bdbcs_do:
cmp ds:word ptr [si],0 ; end of lead byte info?
jz bdbcs_notfound ; jump if so
cmp al,ds:[si] ; less than first byte character?
jb bdbcs_next ; jump if not
cmp al,ds:[si+1] ; grater than first byte character?
ja bdbcs_next
bdbcs_found:
push ax
xor ax,ax
inc ax ; reset zero flag
pop ax
bdbcs_exit:
pop ds
pop si
ret
bdbcs_notfound:
push ax
xor ax,ax ; set zero flag
pop ax
jmp short bdbcs_exit
bdbcs_next:
add si,2 ; points next lead byte table
jmp short bdbcs_do
endif ; DBCS
mapcase endp
;
;----------------------------------------------------------------------------
;
; procedure : round
;
; round the values in memlo and memhi to paragraph boundary.
; perform bounds check.
;
;----------------------------------------------------------------------------
;
round proc near
push ax
mov ax,[memlo]
call pararound ; para round up
add [memhi],ax
mov [memlo],0
mov ax,memhi ; ax = new memhi
cmp ax,[alloclim] ; if new memhi >= alloclim, error
jae mem_err
test cs:[setdevmarkflag], for_devmark
jz skip_set_devmarksize
push es
push si
mov si, cs:[devmark_addr]
mov es, si
sub ax, si
dec ax
mov es:[devmark_size], ax ; paragraph
and cs:[setdevmarkflag], not_for_devmark
pop si
pop es
skip_set_devmarksize:
pop ax
clc ;clear carry
ret
mem_err:
mov dx,offset badmem
push cs
pop ds
call print
jmp stall
round endp
;
;----------------------------------------------------------------------------
;
; procedure : calldev
;
;----------------------------------------------------------------------------
;
calldev proc near
mov ds,word ptr cs:[DevEntry+2]
add bx,word ptr cs:[DevEntry] ;do a little relocation
mov ax,ds:[bx]
push word ptr cs:[DevEntry]
mov word ptr cs:[DevEntry],ax
mov bx,offset packet
call [DevEntry]
pop word ptr cs:[DevEntry]
ret
calldev endp
;
;----------------------------------------------------------------------------
;
; procedure : todigit
;
;----------------------------------------------------------------------------
;
todigit proc near
sub al,'0'
jb notdig
cmp al,9
ja notdig
clc
ret
notdig:
stc
ret
todigit endp
;
;----------------------------------------------------------------------------
;
; procedure : getnum
;
; getnum parses a decimal number.
; returns it in ax, sets zero flag if ax = 0 (may be considered an
; error), if number is bad carry is set, zero is set, ax=0.
;
;----------------------------------------------------------------------------
;
getnum proc near
push bx
xor bx,bx ; running count is zero
b2:
call todigit ; do we have a digit
jc badnum ; no, bomb
xchg ax,bx ; put total in ax
push bx ; save digit
mov bx,10 ; base of arithmetic
mul bx ; shift by one decimal di...
pop bx ; get back digit
add al,bl ; get total
adc ah,0 ; make that 16 bits
jc badnum ; too big a number
xchg ax,bx ; stash total
call getchr ;get next digit
jc b1 ; no more characters
cmp al, ' ' ; space?
jz b15 ; then end of digits
cmp al, ',' ; ',' is a seperator!!!
jz b15 ; then end of digits.
cmp al, tab ; tab
jz b15
cmp al,sepchr ; allow 0 or special separators
jz b15
cmp al,'/' ; see if another switch follows
nop ; cas - remnant of old bad code
nop
jz b15
cmp al,lf ; line-feed?
jz b15
cmp al,cr ; carriage return?
jz b15
or al,al ; end of line separator?
jnz b2 ; no, try as a valid char...
b15:
inc count ; one more character to s...
dec chrptr ; back up over separator
b1:
mov ax,bx ; get proper count
or ax,ax ; clears carry, sets zero accordingly
pop bx
ret
badnum:
mov sepchr,0
xor ax,ax ; set zero flag, and ax = 0
pop bx
stc ; and carry set
ret
getnum endp
;*****************************************************************
setdoscountryinfo proc near
;input: es:di -> pointer to dos_country_cdpg_info
; ds:0 -> buffer.
; si = 0
; ax = country id
; dx = code page id. (if 0, then use ccsyscodepage as a default.)
; bx = file handle
; this routine can handle maxium 438 country_data entries.
;
;output: dos_country_cdpg_info set.
; carry set if any file read failure or wrong information in the file.
; carry set and cx = -1 if cannot find the matching country_id, codepage
; _id in the file.
push di
push ax
push dx
xor cx,cx
xor dx,dx
mov ax,512 ;read 512 bytes
call readincontrolbuffer ;read the file header
jc setdosdata_fail
push es
push si
push cs
pop es
mov di,offset country_file_signature
mov cx,8 ;length of the signature
repz cmpsb
pop si
pop es
jnz setdosdata_fail ;signature mismatch
add si,18 ;si -> county info type
cmp byte ptr ds:[si],1 ;only accept type 1 (currently only 1 header type)
jne setdosdata_fail ;cannot proceed. error return
inc si ;si -> file offset
mov dx,word ptr ds:[si] ;get the info file offset.
mov cx,word ptr ds:[si+2]
mov ax,6144 ;read 6144 bytes.
call readincontrolbuffer ;read info
jc setdosdata_fail
mov cx, word ptr ds:[si] ;get the # of country, codepage combination entries
cmp cx, 438 ;cannot handle more than 438 entries.
;
ja setdosdata_fail
inc si
inc si ;si -> entry information packet
pop dx ;restore code page id
pop ax ;restore country id
pop di
setdoscntry_find: ;search for desired country_id,codepage_id.
cmp ax, word ptr ds:[si+2] ;compare country_id
jne setdoscntry_next
cmp dx, 0 ;no user specified code page ?
je setdoscntry_any_codepage;then no need to match code page id.
cmp dx, word ptr ds:[si+4] ;compare code page id
je setdoscntry_got_it
setdoscntry_next:
add si, word ptr ds:[si] ;next entry
inc si
inc si ;take a word for size of entry itself
loop setdoscntry_find
mov cx, -1 ;signals that bad country id entered.
setdoscntry_fail:
stc
ret
setdosdata_fail:
pop si
pop cx
pop di
jmp short setdoscntry_fail
setdoscntry_any_codepage: ;use the code_page_id of the country_id found.
mov dx, word ptr ds:[si+4]
setdoscntry_got_it: ;found the matching entry
mov cs:cntrycodepage_id, dx ;save code page id for this country.
mov dx, word ptr ds:[si+10] ;get the file offset of country data
mov cx, word ptr ds:[si+12]
mov ax, 512 ;read 512 bytes
call readincontrolbuffer
jc setdoscntry_fail
mov cx, word ptr ds:[si] ;get the number of entries to handle.
inc si
inc si ;si -> first entry
setdoscntry_data:
push di ;es:di -> dos_country_cdpg_info
push cx ;save # of entry left
push si ;si -> current entry in control buffer
mov al, byte ptr ds:[si+2] ;get data entry id
call getcountrydestination ;get the address of destination in es:di
jc setdoscntry_data_next ;no matching data entry id in dos
mov dx, word ptr ds:[si+4] ;get offset of data
mov cx, word ptr ds:[si+6]
mov ax,4200h
stc
int 21h ;move pointer
jc setdosdata_fail
mov dx,512 ;start of data buffer
mov cx,20 ;read 20 bytes only. we only need to
mov ah,3fh ;look at the length of the data in the file.
stc
int 21h ;read the country.sys data
jc setdosdata_fail ;read failure
cmp ax,cx
jne setdosdata_fail
mov dx,word ptr ds:[si+4] ;get offset of data again.
mov cx,word ptr ds:[si+6]
mov ax,4200h
stc
int 21h ;move pointer back again
jc setdosdata_fail
push si
mov si,(512+8) ;get length of the data from the file
mov cx,word ptr ds:[si]
pop si
mov dx,512 ;start of data buffer
add cx,10 ;signature + a word for the length itself
mov ah,3fh ;read the data from the file.
stc
int 21h
jc setdosdata_fail
cmp ax, cx
jne setdosdata_fail
mov al,byte ptr ds:[si+2] ;save data id for future use.
mov si,(512+8) ;si-> data buffer + id tag field
mov cx,word ptr ds:[si] ;get the length of the file
inc cx ;take care of a word for lenght of tab
inc cx ;itself.
cmp cx,(2048 - 512 - 8) ;fit into the buffer?
ja setdosdata_fail
if bugfix
call setdbcs_before_copy
endif
cmp al, setcountryinfo ;is the data for setcountryinfo table?
jne setdoscntry_mov ;no, don't worry
push word ptr es:[di+ccmono_ptr-cccountryinfolen] ;cannot destroy ccmono_ptr address. save them.
push word ptr es:[di+ccmono_ptr-cccountryinfolen+2] ;at this time di -> cccountryinfolen
push di ;save di
push ax
mov ax,cs:cntrycodepage_id ;do not use the code page info in country_info
mov ds:[si+4], ax ;use the saved one for this !!!!
pop ax
setdoscntry_mov:
rep movsb ;copy the table into dos
cmp al, setcountryinfo ;was the ccmono_ptr saved?
jne setdoscntry_data_next
pop di ;restore di
pop word ptr es:[di+ccmono_ptr-cccountryinfolen+2] ;restore
pop word ptr es:[di+ccmono_ptr-cccountryinfolen]
setdoscntry_data_next:
pop si ;restore control buffer pointer
pop cx ;restore # of entries left
pop di ;restore pointer to dso_country_cdpg
add si, word ptr ds:[si] ;try to get the next entry
inc si
inc si ;take a word of entry length itself
dec cx
cmp cx,0
je setdoscntry_ok
jmp setdoscntry_data
setdoscntry_ok:
ret
setdoscountryinfo endp
if bugfix
setdbcs_before_copy proc near
cmp al,setdbcs ; dbcs vector set?
jnz @f ; jump if not
cmp word ptr es:[di], 0 ; zero byte data block?
jz @f ; jump if so
push di
push ax
push cx
mov cx,es:[di] ; load block length
add di,2 ; points actual data
xor al,al ; fill bytes
rep stosb ; clear data block
pop cx
pop ax
pop di
@@:
ret
setdbcs_before_copy endp
endif
getcountrydestination proc near
;get the destination address in the dos country info table.
;input: al - data id
; es:di -> dos_country_cdpg_info
;on return:
; es:di -> destination address of the matching data id
; carry set if no matching data id found in dos.
push cx
add di,ccnumber_of_entries ;skip the reserved area, syscodepage etc.
mov cx,word ptr es:[di] ;get the number of entries
inc di
inc di ;si -> the first start entry id
getcntrydest:
cmp byte ptr es:[di],al
je getcntrydest_ok
cmp byte ptr es:[di],setcountryinfo ;was it setcountryinfo entry?
je getcntrydest_1
add di,5 ;next data id
jmp short getcntrydest_loop
getcntrydest_1:
add di,new_country_size + 3 ;next data id
getcntrydest_loop:
loop getcntrydest
stc
jmp short getcntrydest_exit
getcntrydest_ok:
cmp al,setcountryinfo ;select country info?
jne getcntrydest_ok1
inc di ;now di -> cccountryinfolen
jmp short getcntrydest_exit
getcntrydest_ok1:
les di,dword ptr es:[di+1] ;get the destination in es:di
getcntrydest_exit:
pop cx
ret
getcountrydestination endp
readincontrolbuffer proc near
;move file pointer to cx:dx
;read ax bytes into the control buffer. (should be less than 2 kb)
;si will be set to 0 hence ds:si points to the control buffer.
;entry: cx,dx offset from the start of the file where the read/write pointer
; be moved.
; ax - # of bytes to read
; bx - file handle
; ds - buffer seg.
;return: the control data information is read into ds:0 - ds:0200.
; cx,dx value destroyed.
; carry set if error in reading file.
push ax ;# of bytes to read
mov ax, 4200h
stc
int 21h ;move pointer
pop cx ;# of bytes to read
jc ricb_exit
xor dx,dx ;ds:dx -> control buffer
xor si,si
mov ah,3fh ;read into the buffer
stc
int 21h ;should be less than 1024 bytes.
ricb_exit:
ret
readincontrolbuffer endp
set_country_path proc near
;in: ds - sysinitseg, es - confbot, si -> start of the asciiz path string
; dosinfo_ext, cntry_drv, cntry_root, cntry_path
; assumes current directory is the root directory.
;out: ds:di -> full path (cntry_drv).
; set the cntry_drv string from the country=,,path command.
; ds, es, si value saved.
push si
push ds ;switch ds, es
push es
pop ds
pop es ;now ds -> confbot, es -> sysinitseg
call chk_drive_letter ;current ds:[si] is a drive letter?
jc scp_default_drv ;no, use current default drive.
mov al, byte ptr ds:[si]
inc si
inc si ;si -> next char after ":"
jmp short scp_setdrv
scp_default_drv:
mov ah, 19h
int 21h
add al, "A" ;convert it to a character.
scp_setdrv:
mov cs:cntry_drv, al ;set the drive letter.
mov di, offset cntry_path
mov al, byte ptr ds:[si]
cmp al, "\"
je scp_root_dir
cmp al,"/" ;let's accept "/" as an directory delim
je scp_root_dir
jmp short scp_path
scp_root_dir:
dec di ;di -> cntry_root
scp_path:
call move_asciiz ;copy it
mov di, offset cntry_drv
scpath_exit:
push ds ;switch ds, es
push es
pop ds
pop es ;ds, es value restored
pop si
ret
set_country_path endp
chk_drive_letter proc near
;check if ds:[si] is a drive letter followed by ":".
;assume that every alpha charater is already converted to upper case.
;carry set if not.
push ax
cmp byte ptr ds:[si], "A"
jb cdletter_no
cmp byte ptr ds:[si], "Z"
ja cdletter_no
cmp byte ptr ds:[si+1], ":"
jne cdletter_no
jmp short cdletter_exit
cdletter_no:
stc
cdletter_exit:
pop ax
ret
chk_drive_letter endp
move_asciiz proc near
;in: ds:si -> source es:di -> target
;out: copy the string until 0.
;assumes there exists a 0.
masciiz_loop:
movsb
cmp byte ptr ds:[si-1],0 ;was it 0?
jne masciiz_loop
ret
move_asciiz endp
;
; ds:dx points to string to output (asciz)
;
; prints <badld_pre> <string> <badld_post>
badfil:
push cs
pop es
mov si,dx
badload:
mov dx,offset badld_pre ;want to print config error
mov bx, offset crlfm
prnerr:
push cs
pop ds
call print
prn1:
mov dl,es:[si]
or dl,dl
jz prn2
mov ah,std_con_output
int 21h
inc si
jmp prn1
prn2:
mov dx,bx
call print
cmp donotshownum,1 ; suppress line number when handling command.com
je prnexit
call error_line
prnexit:
ret
print:
cmp cs:bEchoConfig, 0 ; NTVDM skip print call, Jonle
je prnexit
mov ah,std_con_string_output
int 21h
ret
if noexec
; load non exe file called [ds:dx] at memory location es:bx
ldfil:
push ax
push bx
push cx
push dx
push si
push ds
push bx
xor ax,ax ;open the file
mov ah,open
stc ;in case of int 24
int 21h
pop dx ;clean stack in case jump
jc ldret
push dx
mov bx,ax ;handle in bx
xor cx,cx
xor dx,dx
mov ax,(lseek shl 8) or 2
stc ;in case of int 24
int 21h ; get file size in dx:ax
jc ldclsp
or dx,dx
jnz lderrp ; file >64k
pop dx
push dx
mov cx,es ; cx:dx is xaddr
add dx,ax ; add file size to xaddr
jnc dosize
add cx,1000h ; ripple carry
dosize:
mov ax,dx
call pararound
mov dx,ax
add cx,dx
cmp cx,[alloclim]
jb okld
jmp mem_err
okld:
xor cx,cx
xor dx,dx
mov ax,lseek shl 8 ;reset pointer to beginning of file
stc ;in case of int 24
int 21h
jc ldclsp
pop dx
push es ;read the file in
pop ds ;trans addr is ds:dx
mov cx,0ff00h ; .com files arn't any bigger than
; 64k-100h
mov ah,read
stc ;in case of int 24
int 21h
jc ldcls
mov si,dx ;check for exe file
cmp word ptr [si],"ZM"
clc ; assume ok
jnz ldcls ; only know how to do .com files
stc
jmp short ldcls
lderrp:
stc
ldclsp:
pop dx ;clean stack
ldcls:
pushf
mov ah,close ;close the file
stc
int 21h
popf
ldret: pop ds
pop si
pop dx
pop cx
pop bx
pop ax
ret
endif
;
; open device pointed to by dx, al has access code
; if unable to open do a device open null device instead
;
open_dev:
call open_file
jnc open_dev3
open_dev1:
mov dx,offset nuldev
call open_file
of_ret:
ret
open_dev3:
mov bx,ax ; handle from open to bx
xor ax,ax ; get device info
mov ah,ioctl
int 21h
test dl,10000000b
jnz of_ret
mov ah,close
int 21h
jmp open_dev1
open_file:
mov ah,open
stc
int 21h
ret
; test int24. return back to dos with the fake user response of "fail"
int24:
mov al, 3 ; fail the system call
iret ; return back to dos.
include copyrigh.inc ; copyright statement
nuldev db "NUL",0
condev db "CON",0
auxdev db "AUX",0
prndev db "PRN",0
MseDev db "MOUSE",0 ; NTVDM for internal spc mouse
; NTVDM we use a temp file for config.sys 23-Nov-1992 Jonle
; config db "C:\CONFIG.SYS",0
config db 64 dup (0)
cntry_drv db "A:"
cntry_root db "\"
cntry_path db "COUNTRY.SYS",0
db 52 dup (0)
country_file_signature db 0ffh,'COUNTRY'
cntrycodepage_id dw ?
commnd db "\COMMAND.COM",0
db 51 dup (0)
pathstring db 64 dup (0)
comtab label byte
; cmd len command cmd code
; ------- ------- --------
;
db 7, "BUFFERS", 'B'
db 5, "BREAK", 'C'
db 6, "DEVICE", 'D'
db 10, "DEVICEHIGH", 'U'
db 5, "FILES", 'F'
db 4, "FCBS", 'X'
db 9, "LASTDRIVE", 'L'
db 10, "MULTITRACK", 'M'
db 8, "DRIVPARM", 'P'
if stacksw
db 6, "STACKS", 'K'
endif
db 7, "COUNTRY", 'Q'
db 5, "SHELL", 'S'
db 7, "INSTALL", 'I'
db 7, "COMMENT", 'Y'
db 3, "REM", '0'
db 8, "SWITCHES", '1'
db 3, "DOS", 'H'
db 10, "ECHOCONFIG", 'E' ; NTVDM 14-Aug-1992 Jonle
db 11, "NTCMDPROMPT", 'T' ; NTVDM 06-May-1993 sudeepb
db 7, "DOSONLY", 'O' ; NTVDM 06-May-1993 sudeepb
db 0
hlim dw 2
slim dw 9
public bEchoConfig ; NTVDM - 14-Aug-1992 Jonle
bEchoConfig db 0
public drive
drive db ?
public switches
switches dw 0
switchlist db 8,"FHSTDICN" ; preserve the positions of n and c.
; the following depend on the positions of the various letters in switchlist
;switchnum equ 11111000b ; which switches require number
flagec35 equ 00000100b ; electrically compatible 3.5 inch disk drive
flagdrive equ 00001000b
flagcyln equ 00010000b
flagseclim equ 00100000b
flagheads equ 01000000b
flagff equ 10000000b
sysinitseg ends
end
|