42fa37d27bb52e58e1900b08a6cd0a14853ffc67
2 * (C) Copyright 2002, Brian Knittel.
3 * You may freely use this program, but: it offered strictly on an AS-IS, AT YOUR OWN
4 * RISK basis, there is no warranty of fitness for any purpose, and the rest of the
5 * usual yada-yada. Please keep this notice and the copyright in any distributions
8 * This is not a supported product, but I welcome bug reports and fixes.
9 * Mail to sim@ibm1130.org
12 // DISKVIEW - lists contents of an 1130 system disk image file. Not finished yet.
13 // needs LET/SLET listing routine.
16 // diskview -v diskfile
24 #define BETWEEN(v,a,b) (((v) >= (a)) && ((v) <= (b)))
25 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
26 #define MAX(a,b) (((a) >= (b)) ? (a) : (b))
34 #define NOT_DEF 0x0658 // defective cylinder table entry means no defect
36 #define DSK_NUMWD 321 /* words/sector */
37 #define DSK_NUMCY 203 /* cylinders/drive */
38 #define DSK_SECCYL 8 /* sectors per cylinder */
39 #define SECLEN 320 /* data words per sector */
40 #define SLETLEN ((3*SECLEN)/4) /* length of slet in records */
42 typedef unsigned short WORD
;
61 void checksectors (void);
63 void dump_dcom (void);
64 void dump_resmon (void);
65 void dump_slet (void);
66 void dump_hdng (void);
67 void dump_scra (void);
69 void dump_flet (void);
71 void getsector (int sec
, WORD
*sbuf
);
73 char *lowcase (char *str
);
75 void bail(char *fmt
, ...);
78 int main (int argc
, char **argv
)
80 char *fname
= NULL
, *arg
;
81 static char usestr
[] = "Usage: diskview [-v] filename";
84 for (i
= 1; i
< argc
;) {
100 else if (fname
== NULL
)
109 if ((fp
= fopen(fname
, "rb")) == NULL
) {
114 printf("%s:\n", fname
);
119 dump_id(); // ID & coldstart
121 dump_resmon(); // resident image
123 dump_hdng(); // heading sector
133 // checksectors - verify that all sectors are properly numbered
139 fseek(fp
, 0, SEEK_SET
);
141 for (sec
= 0; sec
< DSK_NUMCY
*DSK_SECCYL
; sec
++) {
142 if (fxread(buf
, sizeof(WORD
), DSK_NUMWD
, fp
) != DSK_NUMWD
)
143 bail("File read error or not a disk image file");
146 bail("Sector /%x is misnumbered, run checkdisk [-f]", sec
);
150 // get defective cylinder list
154 fseek(fp
, sizeof(WORD
), SEEK_SET
); // skip sector count
155 if (fxread(dcyl
, sizeof(WORD
), 3, fp
) != 3)
156 bail("Unable to read defective cylinder table");
159 // getsector - read specified absolute sector
161 void getsector (int sec
, WORD
*sbuf
)
165 sec
&= 0x7FF; // mask of drive bits, if any
167 cyl
= sec
/ DSK_SECCYL
; // get cylinder
168 ssec
= sec
& ~(DSK_SECCYL
-1); // mask to get starting sector of cylinder
169 for (i
= 0; i
< 3; i
++) { // map through defective cylinder table
170 if (dcyl
[i
] == ssec
) {
171 sec
&= (DSK_SECCYL
-1); // mask to get base sector
172 cyl
= DSK_NUMCY
-3+i
; // replacements are last three on disk
173 sec
+= cyl
*DSK_SECCYL
; // add new cylinder offset
178 if (fseek(fp
, (sec
*DSK_NUMWD
+1)*sizeof(WORD
), SEEK_SET
) != 0)
179 bail("File seek failed");
181 if (fxread(sbuf
, sizeof(WORD
), DSK_NUMWD
, fp
) != DSK_NUMWD
)
182 bail("File read error or not a disk image file");
185 void dump (int nwords
)
189 for (i
= 0; i
< nwords
; i
++) {
195 printf("%04x", buf
[i
]);
201 void showmajor (char *label
)
205 printf("\n--- %s ", label
);
207 for (i
= strlen(label
); i
< 40; i
++)
214 void name (char *label
)
216 printf("%-32.32s ", label
);
219 void pbf (char *label
, WORD
*buf
, int nwords
)
225 for (i
= nout
= 0; i
< nwords
; i
++, nout
++) {
231 printf(" %04x", buf
[i
]);
237 void prt (char *label
, char *fmt
, ...)
253 showmajor("Sector 0 - ID & coldstart");
256 pbf("DCYL def cyl table", buf
+ 0, 3);
257 pbf("CIDN cart id", buf
+ 3, 1);
258 pbf(" copy code", buf
+ 4, 1);
259 pbf("DTYP disk type", buf
+ 7, 1);
260 pbf(" diskz copy", buf
+ 30, 8);
261 pbf(" cold start pgm",buf
+270, 8);
264 // EQUIVALENCES FOR DCOM PARAMETERS
265 #define NAME 4 // NAME OF PROGRAM/CORE LOAD
266 #define DBCT 6 // BLOCK CT OF PROGRAM/CORE LOAD
267 #define FCNT 7 // FILES SWITCH
268 #define SYSC 8 // SYSTEM/NON-SYSTEM CARTRIDGE INDR
269 #define JBSW 9 // JOBT SWITCH
270 #define CBSW 10 // CLB-RETURN SWITCH
271 #define LCNT 11 // NO. OF LOCALS
272 #define MPSW 12 // CORE MAP SWITCH
273 #define MDF1 13 // NO. DUP CTRL RECORDS (MODIF)
274 #define MDF2 14 // ADDR OF MODIF BUFFER
275 #define NCNT 15 // NO. OF NOCALS
276 #define ENTY 16 // RLTV ENTRY ADDR OF PROGRAM
277 #define RP67 17 // 1442-5 SWITCH
278 #define TODR 18 // OBJECT WORK STORAGE DRIVE CODE
279 #define FHOL 20 // ADDR LARGEST HOLE IN FIXED AREA
280 #define FSZE 21 // BLK CNT LARGEST HOLE IN FXA
281 #define UHOL 22 // ADDR LAST HOLE IN USER AREA 2-10
282 #define USZE 23 // BLK CNT LAST HOLE IN UA 2-10
283 #define DCSW 24 // DUP CALL SWITCH
284 #define PIOD 25 // PRINCIPAL I/O DEVICE INDICATOR
285 #define PPTR 26 // PRINCIPAL PRINT DEVICE INDICATOR
286 #define CIAD 27 // RLTV ADDR IN @STRT OF CIL ADDR
287 #define ACIN 28 // AVAILABLE CARTRIDGE INDICATOR
288 #define GRPH 29 // 2250 INDICATOR 2G2
289 #define GCNT 30 // NO. G2250 RECORDS 2G2
290 #define LOSW 31 // LOCAL-CALLS-LOCAL SWITCH 2-2
291 #define X3SW 32 // SPECIAL ILS SWITCH 2-2
292 #define ECNT 33 // NO. OF *EQUAT RCDS 2-4
293 #define ANDU 35 // 1+BLK ADDR END OF UA (ADJUSTED)
294 #define BNDU 40 // 1+BLK ADDR END OF UA (BASE)
295 #define FPAD 45 // FILE PROTECT ADDR
296 #define PCID 50 // CARTRIDGE ID, PHYSICAL DRIVE
297 #define CIDN 55 // CARTRIDGE ID, LOGICAL DRIVE
298 #define CIBA 60 // SCTR ADDR OF CIB
299 #define SCRA 65 // SCTR ADDR OF SCRA
300 #define FMAT 70 // FORMAT OF PROG IN WORKING STG
301 #define FLET 75 // SCTR ADDR 1ST SCTR OF FLET
302 #define ULET 80 // SCTR ADDR 1ST SCTR OF LET
303 #define WSCT 85 // BLK CNT OF PROG IN WORKING STG
304 #define CSHN 90 // NO. SCTRS IN CUSHION AREA
306 struct tag_dcominfo
{
311 "NAME", 4, "NAME OF PROGRAM/CORE LOAD",
312 "DBCT", 6, "BLOCK CT OF PROGRAM/CORE LOAD",
313 "FCNT", 7, "FILES SWITCH",
314 "SYSC", 8, "SYSTEM/NON-SYSTEM CARTRIDGE INDR",
315 "JBSW", 9, "JOBT SWITCH",
316 "CBSW", 10, "CLB-RETURN SWITCH",
317 "LCNT", 11, "NO. OF LOCALS",
318 "MPSW", 12, "CORE MAP SWITCH",
319 "MDF1", 13, "NO. DUP CTRL RECORDS (MODIF)",
320 "MDF2", 14, "ADDR OF MODIF BUFFER",
321 "NCNT", 15, "NO. OF NOCALS",
322 "ENTY", 16, "RLTV ENTRY ADDR OF PROGRAM",
323 "RP67", 17, "1442-5 SWITCH",
324 "TODR", 18, "OBJECT WORK STORAGE DRIVE CODE",
325 "FHOL", 20, "ADDR LARGEST HOLE IN FIXED AREA",
326 "FSZE", 21, "BLK CNT LARGEST HOLE IN FXA",
327 "UHOL", 22, "ADDR LAST HOLE IN USER AREA",
328 "USZE", 23, "BLK CNT LAST HOLE IN UA",
329 "DCSW", 24, "DUP CALL SWITCH",
330 "PIOD", 25, "PRINCIPAL I/O DEVICE INDICATOR",
331 "PPTR", 26, "PRINCIPAL PRINT DEVICE INDICATOR",
332 "CIAD", 27, "RLTV ADDR IN @STRT OF CIL ADDR",
333 "ACIN", 28, "AVAILABLE CARTRIDGE INDICATOR",
334 "GRPH", 29, "2250 INDICATOR",
335 "GCNT", 30, "NO. G2250 RECORDS",
336 "LOSW", 31, "LOCAL-CALLS-LOCAL SWITCH",
337 "X3SW", 32, "SPECIAL ILS SWITCH",
338 "ECNT", 33, "NO. OF *EQUAT RCDS",
339 "ANDU", 35, "1+BLK ADDR END OF UA (ADJUSTED)",
340 "BNDU", 40, "1+BLK ADDR END OF UA (BASE)",
341 "FPAD", 45, "FILE PROTECT ADDR",
342 "PCID", 50, "CARTRIDGE ID, PHYSICAL DRIVE",
343 "CIDN", 55, "CARTRIDGE ID, LOGICAL DRIVE",
344 "CIBA", 60, "SCTR ADDR OF CIB",
345 "SCRA", 65, "SCTR ADDR OF SCRA",
346 "FMAT", 70, "FORMAT OF PROG IN WORKING STG",
347 "FLET", 75, "SCTR ADDR 1ST SCTR OF FLET",
348 "ULET", 80, "SCTR ADDR 1ST SCTR OF LET",
349 "WSCT", 85, "BLK CNT OF PROG IN WORKING STG",
350 "CSHN", 90, "NO. SCTRS IN CUSHION AREA",
354 void dump_dcom (void)
356 struct tag_dcominfo
*d
;
359 showmajor("Sector 1 - DCOM");
362 for (d
= dcominfo
; d
->nm
!= NULL
; d
++) {
363 sprintf(txt
, "%-4.4s %s", d
->nm
, d
->descr
);
364 pbf(txt
, dcom
+d
->offset
, 1);
368 void dump_resmon (void)
370 showmajor("Sector 2 - Resident Image");
372 dump(verbose
? SECLEN
: 32);
380 0x01, 0x12, FALSE
, "DUP",
381 0x1F, 0x39, FALSE
, "Fortran",
382 0x51, 0x5C, FALSE
, "Cobol",
383 0x6E, 0x74, FALSE
, "Supervisor",
384 0x78, 0x84, FALSE
, "Core Load Builder",
385 0x8C, 0x8C, FALSE
, "Sys 1403 prt",
386 0x8D, 0x8D, FALSE
, "Sys 1132 prt",
387 0x8E, 0x8E, FALSE
, "Sys console prt",
388 0x8F, 0x8F, FALSE
, "Sys 2501 rdr",
389 0x90, 0x90, FALSE
, "Sys 1442 rdr/pun",
390 0x91, 0x91, FALSE
, "Sys 1134 paper tape",
391 0x92, 0x92, FALSE
, "Sys kbd",
392 0x93, 0x93, FALSE
, "Sys 2501/1442 conv",
393 0x94, 0x94, FALSE
, "Sys 1134 conv",
394 0x95, 0x95, FALSE
, "Sys kbd conv",
395 0x96, 0x96, FALSE
, "Sys diskz",
396 0x97, 0x97, FALSE
, "Sys disk1",
397 0x98, 0x98, FALSE
, "Sys diskn",
398 0x99, 0x99, FALSE
, "(primary print)",
399 0x9A, 0x9A, FALSE
, "(primary input)",
400 0x9B, 0x9B, FALSE
, "(primary input excl kbd)",
401 0x9C, 0x9C, FALSE
, "(primary sys conv)",
402 0x9D, 0x9D, FALSE
, "(primary conv excl kbd)",
403 0xA0, 0xA1, FALSE
, "Core Image Loader",
404 0xB0, 0xCC, FALSE
, "RPG",
405 0xCD, 0xCE, FALSE
, "Dup Part 2",
406 0xCF, 0xF6, FALSE
, "Macro Assembler",
410 void dump_slet (void)
412 int i
, j
, iphase
, nsecs
, sec
, max_sec
= 0;
413 char sstr
[16], *smark
;
415 showmajor("Sectors 3-5 - SLET");
416 for (i
= 0; i
< 3; i
++) {
418 memmove(((WORD
*) slet
)+SECLEN
*i
, buf
, SECLEN
*sizeof(WORD
));
421 printf("# PHID Addr Len Sector Secs\n");
422 printf("------------------------------------------\n");
423 for (i
= 0; i
< SLETLEN
; i
++) {
424 if (slet
[i
].phid
== 0)
427 sec
= slet
[i
].sector
;
428 iphase
= (int) (signed short) slet
[i
].phid
;
429 nsecs
= (slet
[i
].nwords
+ SECLEN
-1)/SECLEN
;
438 for (j
= 0; sletinfo
[j
].pfrom
!= 0; j
++)
439 if (sletinfo
[j
].pfrom
<= iphase
&& sletinfo
[j
].pto
>= iphase
)
442 sprintf(sstr
, "(%d.%d)", sec
/ DSK_SECCYL
, slet
[i
].sector
% DSK_SECCYL
);
444 printf("%3d %04x %4d %04x %04x %04x %s %-7s %3x",
445 i
, slet
[i
].phid
, iphase
, slet
[i
].addr
, slet
[i
].nwords
, slet
[i
].sector
, smark
, sstr
, nsecs
);
450 if (sletinfo
[j
].pfrom
== 0)
452 else if (! sletinfo
[j
].printed
) {
453 printf(" %s", sletinfo
[j
].name
);
454 sletinfo
[j
].printed
= TRUE
;
457 for (j
= 0; j
< i
; j
++) {
458 if (sec
== (slet
[j
].sector
& 0x7FF)) {
459 printf(" (same as %04x)", slet
[j
].phid
);
464 max_sec
= MAX(max_sec
, sec
+nsecs
-1); // find last sector used
468 if (i
>= 15 && ! verbose
) {
475 int ascii_to_ebcdic_table
[128] =
477 0x00,0x01,0x02,0x03,0x37,0x2d,0x2e,0x2f, 0x16,0x05,0x25,0x0b,0x0c,0x0d,0x0e,0x0f,
478 0x10,0x11,0x12,0x13,0x3c,0x3d,0x32,0x26, 0x18,0x19,0x3f,0x27,0x1c,0x1d,0x1e,0x1f,
479 0x40,0x5a,0x7f,0x7b,0x5b,0x6c,0x50,0x7d, 0x4d,0x5d,0x5c,0x4e,0x6b,0x60,0x4b,0x61,
480 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7, 0xf8,0xf9,0x7a,0x5e,0x4c,0x7e,0x6e,0x6f,
482 0x7c,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7, 0xc8,0xc9,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,
483 0xd7,0xd8,0xd9,0xe2,0xe3,0xe4,0xe5,0xe6, 0xe7,0xe8,0xe9,0xba,0xe0,0xbb,0xb0,0x6d,
484 0x79,0x81,0x82,0x83,0x84,0x85,0x86,0x87, 0x88,0x89,0x91,0x92,0x93,0x94,0x95,0x96,
485 0x97,0x98,0x99,0xa2,0xa3,0xa4,0xa5,0xa6, 0xa7,0xa8,0xa9,0xc0,0x4f,0xd0,0xa1,0x07,
488 int ebcdic_to_ascii (int ch
)
492 for (j
= 32; j
< 128; j
++)
493 if (ascii_to_ebcdic_table
[j
] == ch
)
504 char str
[HDR_LEN
+1], *p
= str
;
506 showmajor("Sector 7 - Heading");
509 for (i
= 0; i
< (HDR_LEN
/2); i
++) {
510 *p
++ = ebcdic_to_ascii((buf
[i
] >> 8) & 0xFF);
511 *p
++ = ebcdic_to_ascii( buf
[i
] & 0xFF);
519 BOOL
mget (int offset
, char *name
)
523 if (dcom
[offset
] == 0)
526 getsector(dcom
[offset
], buf
);
527 sprintf(title
, "Sector %x - %s", dcom
[offset
], name
);
532 void dump_scra (void)
534 if (! mget(SCRA
, "SCRA"))
537 dump(verbose
? SECLEN
: 32);
542 if (! mget(ULET
, "LET"))
546 void dump_flet (void)
548 if (! mget(FLET
, "FLET"))
554 if (! mget(CIBA
, "CIB"))
557 dump(verbose
? SECLEN
: 32);
560 #define LFHD 5 // WORD COUNT OF LET/FLET HEADER PMN09970
561 #define LFEN 3 // NO OF WDS PER LET/FLET ENTRY PMN09980
562 #define SCTN 0 // RLTY ADDR OF LET/FLET SCTR NO. PMN09990
563 #define UAFX 1 // RLTV ADDR OF SCTR ADDR OF UA/FXA PMN10000
564 #define WDSA 3 // RLTV ADDR OF WDS AVAIL IN SCTR PMN10010
565 #define NEXT 4 // RLTV ADDR OF ADDR NEXT SCTR PMN10020
566 #define LFNM 0 // RLTV ADDR OF LET/FLET ENTRY NAME PMN10030
567 #define BLCT 2 // RLTV ADDR OF LET/FLET ENTRY DBCT PMN10040
569 void bail (char *fmt
, ...)
574 fprintf(stderr
, fmt
, args
);
581 // ---------------------------------------------------------------------------------
582 // trim - remove trailing whitespace from string s
583 // ---------------------------------------------------------------------------------
589 for (nb
= s
-1; *s
; s
++)
597 /* ------------------------------------------------------------------------
598 * lowcase - force a string to lowercase (ASCII)
599 * ------------------------------------------------------------------------ */
601 char *lowcase (char *str
)
605 for (s
= str
; *s
; s
++) {
606 if (*s
>= 'A' && *s
<= 'Z')