-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcdtest.c
491 lines (444 loc) · 11.5 KB
/
cdtest.c
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
/*
cdtest.c - Test harness for the SHSUCDX Int2F/15 functions.
Jason Hood, 22 September, 2004.
Outputs the results of calling Int2F/AH=15,AL=00-0F (ie. including
unsupported functions, but excluding 10 [device request]). It also
calls the two redirector installation functions (Int2F/AX=1100:
stack=DADA for MSCDEX; BX=BABE for SMARTDrive). Since the results
will vary depending upon the CD present, manual verification is
necessary. To test 0F (directory entry), pass a filename (complete
path, including drive letter).
11 October, 2004:
added test for read-only function;
restore state of tilde/read-only.
17 & 19 November, 2004:
added test of FCB name function (when filename given);
include drive entry size.
26 November, 2004:
"invalidate" all buffers;
directory entry filename is now a complete path, with drive.
28 November, 2004:
recognise new version of SHSUCDX' SMARTDrive check (changed SMARTDRV_Q,
display compile-time options).
5 May, 2005:
use four characters for the options flag;
initialise buffers "manually" to make binary smaller;
added dump function.
*/
#include <stdio.h>
#include <string.h>
#include <dos.h>
struct REGPACK regs;
int num_drives;
int first_drive;
// Test the SHSUCDX installation check.
int install_check( void )
{
// First, test the standard redirector installation check.
asm {
mov ax, 0xDADA
push ax
mov ax, 0x1100
int 0x2f
pop ax
}
if (_AX == 0xADAD)
{
// Now test SHSUCDX SMARTDrive installation check.
regs.r_ax = 0x1100;
regs.r_bx = 0xBABE;
intr( 0x2f, ®s );
if (regs.r_bx != 0xBABE)
{
printf( "SHSUCDX v3 installed: %d drive(s) located at %04X:%04X,"
" %d bytes each entry.\n",
regs.r_cx, regs.r_es, regs.r_di, regs.r_dx );
printf( "Compiled with: %s, CD root form%s, High Sierra %ssupported,\n"
"(%04X) Joliet %ssupported, image on CD %ssupported.\n\n",
(regs.r_bx & 1) ? "8086" : "386",
(regs.r_bx & 2) ? "" : " not used",
(regs.r_bx & 4) ? "" : "not ", regs.r_bx,
(regs.r_bx & 8) ? "" : "not ",
(regs.r_bx & 16) ? "" : "not " );
return 1;
}
}
puts( "SHSUCDX v3 is not installed." );
return 0;
}
// Display a hex and character dump.
void dump( char* buf, int len )
{
int k, n;
unsigned char* p = (unsigned char*)buf;
unsigned char* e = p + len;
while (p < e)
{
fputs( " ", stdout );
n = (p + 16 <= e) ? 16 : e - p;
for (k = 0; k < n; ++k)
{
printf( " %02x", p[k] );
}
for (; k < 17; ++k)
fputs( " ", stdout );
do
{
printf( "%c", (*p >= 32) ? *p : '.' );
++p;
} while (--n);
putchar( '\n' );
}
}
char* fail_msg = NULL;
int mpx( int func )
{
regs.r_ax = 0x1500 + func;
intr( 0x2f, ®s );
printf( "%02x: ", func );
if (regs.r_flags & 1)
{
if (fail_msg && regs.r_ax == 1)
printf( "%s not supported.\n", fail_msg );
else
printf( "failed, error %d (%02xh).\n", regs.r_ax, regs.r_ax );
}
return !(regs.r_flags & 1);
}
// 00h: Get number of drive letters (installation check)
// In: BX = 0
// Out: BX = number of CD-ROM drive letters used
// CX = starting drive letter (0=A:)
void test00( void )
{
regs.r_bx = 0;
if (mpx( 0x00 ))
{
printf( "%d drive(s), first drive is %c:.\n",
regs.r_bx, regs.r_cx + 'A' );
num_drives = regs.r_bx;
first_drive = regs.r_cx;
}
}
// 01h: Get drive device list
// In: ES:BX -> buffer to hold drive letter list (5 bytes per drive)
// Out: buffer filled:
// BYTE subunit number in driver
// DWORD address of device driver header
void test01( void )
{
struct
{
char subunit;
void far* header;
}
buf[32];
buf[0].subunit = 0;
buf[0].header = MK_FP( 0xdead, 0xbeef );
regs.r_es = FP_SEG( buf );
regs.r_bx = FP_OFF( buf );
if (mpx( 0x01 ))
{
int j;
puts( "subunit header" );
for (j = 0; j < num_drives; ++j)
printf( " %d %Fp\n", buf[j].subunit, buf[j].header );
}
}
// 02h: Get copyright file name
// 03h: Get abstract file name
// 04h: Get biblio file name
// In: ES:BX -> 38-byte buffer for name of respective file
// CX = drive number (0=A:)
// Out: CF set if drive is not a CD-ROM drive
// AX = 000Fh (invalid drive)
// CF clear if successful
void test02( void )
{
char buf[38];
strcpy( buf, "failed" );
regs.r_es = FP_SEG( buf );
regs.r_bx = FP_OFF( buf );
regs.r_cx = first_drive;
if (mpx( 0x02 ))
printf( "Copyright file name: \"%s\"\n", buf );
}
void test03( void )
{
char buf[38];
strcpy( buf, "failed" );
regs.r_es = FP_SEG( buf );
regs.r_bx = FP_OFF( buf );
regs.r_cx = first_drive;
if (mpx( 0x03 ))
printf( "Abstract file name: \"%s\"\n", buf );
}
void test04( void )
{
char buf[38];
strcpy( buf, "failed" );
regs.r_es = FP_SEG( buf );
regs.r_bx = FP_OFF( buf );
regs.r_cx = first_drive;
if (mpx( 0x04 ))
printf( "Bibliographic file name: \"%s\"\n", buf );
}
// 05h: Read VTOC
// In: ES:BX -> 2048-byte buffer
// CX = drive number (0=A:)
// DX = sector index (0=first volume descriptor,1=second,...)
// Out: CF set on error
// AX = error code (15=invalid drive,21=not ready)
// CF clear if successful
// AX = volume descriptor type (1=standard,FFh=terminator,0=other)
void test05( void )
{
char buf[2048];
strcpy( buf, "failed" );
regs.r_es = FP_SEG( buf );
regs.r_bx = FP_OFF( buf );
regs.r_cx = first_drive;
regs.r_dx = 0;
if (mpx( 0x05 ))
{
printf( "volume descriptor type: %s\n",
(regs.r_ax == 1) ? "standard" :
(regs.r_ax == 0xff) ? "terminator" : "other" );
dump( buf, 16 );
}
}
// 08h: Absolute disk read
// In: ES:BX -> buffer
// CX = drive number (0=A:)
// SI:DI = starting sector number
// DX = number of sectors to read
// Out: CF set on error
// AL = error code (0Fh invalid drive,15h not ready)
// CF clear if successful
void test08( void )
{
char buf[2048];
strcpy( buf, "failed" );
regs.r_es = FP_SEG( buf );
regs.r_bx = FP_OFF( buf );
regs.r_cx = first_drive;
regs.r_si = 0x0000;
regs.r_di = 0x0010;
regs.r_dx = 1;
if (mpx( 0x08 ))
{
fputs( "sector 16:\n", stdout );
dump( buf, 16 );
}
}
// 0Bh: CDROM check
// In: CX = drive number (0=A:)
// Out: BX = ADADh if MSCDEX.EXE installed
// AX = support status
// 0000h if drive not supported
// nonzero if supported
void test0b( void )
{
regs.r_cx = 0;
if (mpx( 0x0b ))
{
if (regs.r_bx != 0xADAD)
{
printf( "wrong BX value: %04x\n", regs.r_bx );
return;
}
printf( "A: is %ssupported.\n", (regs.r_ax) ? "" : "not " );
}
regs.r_cx = first_drive;
if (mpx( 0x0b ))
printf( "%c: is %ssupported.\n",
first_drive + 'A', (regs.r_ax) ? "" : "not " );
}
// 0Ch: MSCDEX version
// In: BX = 0000h
// Out: BH = major version
// BL = minor version
void test0c( void )
{
regs.r_bx = 0;
if (mpx( 0x0c ))
printf( "version %d.%02d\n", regs.r_bx >> 8, regs.r_bx & 255 );
}
// 0Dh: Drive letters
// In: ES:BX -> buffer for drive letter list (1 byte per drive)
// Out: buffer filled with drive numbers (0=A:). Each byte corresponds
// to the drive in the same position for function 1501h
void test0d( void )
{
char buf[32];
buf[0] = '?' - 'A';
regs.r_es = FP_SEG( buf );
regs.r_bx = FP_OFF( buf );
if (mpx( 0x0d ))
{
int j;
fputs( "drive letters: ", stdout );
for (j = 0; j < num_drives; ++j)
putchar( buf[j] + 'A' );
putchar( '\n' );
}
}
// 0Fh: Get Directory Entry
// In: CL = drive number (0=A:)
// CH bit 0 = copy flag
// clear if direct copy
// set if copy removes ISO/High Sierra diffs
// ES:BX -> ASCIZ path name
// SI:DI -> buffer for directory entry
// must be 255 bytes for direct copy, 285 bytes for canonical
// Out: CF set on error
// AX = error code
// CF clear if successful
// AX = disk format (0=High Sierra,1=ISO 9660)
//
// In: CL = 0ffh
// CH = function
// 0 get tilde usage in AX
// 1 set tilde usage: BX = 0 no tildes, anything else to use tildes
// 2 get read-only attribute in AX
// 3 set read-only attribute: BX = 0 not ro, anything else ro
// CL = 0feh
// ES:SI -> pointer to directory entry
// ES:DI -> 11-byte buffer for FCB name
// DX = alias number (0 for none)
void test0f( void )
{
int tildes, ro;
regs.r_cx = 0x0100 + first_drive;
fail_msg = "canonical entry";
mpx( 0x0f );
fail_msg = NULL;
regs.r_cx = 0x00ff;
regs.r_ax = 0x150f;
intr( 0x2f, ®s );
tildes = regs.r_ax;
regs.r_cx = 0x02ff;
regs.r_ax = 0x150f;
intr( 0x2f, ®s );
ro = regs.r_ax;
regs.r_cx = 0x01ff;
regs.r_bx = 1;
if (mpx( 0x0f ))
{
puts( "tildes should have been turned on." );
regs.r_cx = 0x00ff;
if (mpx( 0x0f ))
printf( "tildes are %s.\n", (regs.r_ax) ? "on" : "off" );
}
regs.r_cx = 0x01ff;
regs.r_bx = 0;
if (mpx( 0x0f ))
{
puts( "tildes should have been turned off." );
regs.r_cx = 0x00ff;
if (mpx( 0x0f ))
printf( "tildes are %s.\n", (regs.r_ax) ? "on" : "off" );
}
regs.r_cx = 0x03ff;
regs.r_bx = 1;
if (mpx( 0x0f ))
{
puts( "read-only attribute should have been turned on." );
regs.r_cx = 0x02ff;
if (mpx( 0x0f ))
printf( "read-only attribute is %s.\n", (regs.r_ax) ? "on" : "off" );
}
regs.r_cx = 0x03ff;
regs.r_bx = 0;
if (mpx( 0x0f ))
{
puts( "read-only attribute should have been turned off." );
regs.r_cx = 0x02ff;
if (mpx( 0x0f ))
printf( "read-only attribute is %s.\n", (regs.r_ax) ? "on" : "off" );
}
regs.r_cx = 0x01ff;
regs.r_bx = tildes;
regs.r_ax = 0x150f;
intr( 0x2f, ®s );
regs.r_cx = 0x03ff;
regs.r_bx = ro;
regs.r_ax = 0x150f;
intr( 0x2f, ®s );
}
void dir_ent( char* name )
{
char buf[255];
char fcb[11];
strcpy( buf, "failed" );
strcpy( fcb, "failed" );
regs.r_ax = 0x1500;
intr( 0x2f, ®s );
regs.r_cx = (*name | 0x20) - 'a';
regs.r_es = FP_SEG( name );
regs.r_bx = FP_OFF( name ) + 2;
regs.r_si = FP_SEG( buf );
regs.r_di = FP_OFF( buf );
if (mpx( 0x0f ))
{
printf( "%s directory entry for \"%s\":\n", (regs.r_ax)?"ISO":"HS", name );
dump( buf, buf[0] );
regs.r_es = FP_SEG( buf );
regs.r_si = FP_OFF( buf );
regs.r_di = FP_OFF( fcb );
regs.r_dx = 2;
regs.r_cx = 0xfe;
if (mpx( 0x0f ))
printf( "FCB name: \"%.11s\"\n", fcb );
}
}
int main( int argc, char* argv[] )
{
if (argc > 1)
{
if (argv[1][0] == '/' && argv[1][1] == '?')
{
puts(
"Simple test harness for SHSUCDX CD-ROM functions (Int2F/AH=15).\n"
"Also tests installation checks (Int2F/AX=1100, stack=DADA and BX=BABE).\n"
"Tests all Int2F/AH=15 functions 00 to 0F (ie. it includes unsupported\n"
"functions, but excludes 10 device request). To test 0F directory entry\n"
"and FCB name generation (assuming entry number 2 if tildes are on)\n"
"specify a filename (complete path, including drive).\n"
"Since results differ according to CD, manual verification is necessary.\n"
"\n"
"Jason Hood <[email protected]>, 5 May, 2005."
);
return 0;
}
dir_ent( argv[1] );
}
else if (install_check())
{
test00();
test01();
test02();
test03();
test04();
test05();
fail_msg = "debug on";
mpx( 0x06 );
fail_msg = "debug off";
mpx( 0x07 );
fail_msg = NULL;
test08();
fail_msg = "absolute write";
mpx( 0x09 );
fail_msg = "reserved";
mpx( 0x0a );
fail_msg = NULL;
test0b();
test0c();
test0d();
fail_msg = "volume descriptor preference";
mpx( 0x0e );
fail_msg = NULL;
test0f();
}
return 0;
}