TAPE: Minor cleanup and comments here and there.

This commit is contained in:
Larry Baker 2020-08-24 18:45:08 -07:00 committed by Mark Pizzolato
parent 60e5484541
commit 6f207b22a5

View file

@ -421,12 +421,8 @@ typedef struct HDR2 { /* Also EOF2, EOV2 */
typedef struct HDR3 { /* Also EOF3, EOV3 */ typedef struct HDR3 { /* Also EOF3, EOV3 */
char type[3]; /* HDR */ char type[3]; /* HDR */
char num; /* 3 */ char num; /* 3 */
char record_format; /* F(fixed)|D(variable)|S(spanned) */ char rms_attributes[64]; /* 32 bytes of RMS attributes, converted to hex */
char block_length[5]; /* label ident */ char reserved[12]; /* */
char record_length[5]; /* */
char reserved_os[35]; /* */
char buffer_offset[2]; /* */
char reserved_std[28]; /* */
} HDR3; } HDR3;
typedef struct HDR4 { /* Also EOF4, EOV4 */ typedef struct HDR4 { /* Also EOF4, EOV4 */
@ -463,11 +459,6 @@ const char HDR3_RMS_STMLF[] = "HDR3020002050000"
"0000000002000000" "0000000002000000"
"0000000000000000" "0000000000000000"
"0000 "; "0000 ";
const char HDR3_RMS_VAR[] = "HDR3005C02020000"
"0000000100000000"
"0000000000000000"
"0000000000000000"
"0000 ";
const char HDR3_RMS_FIXED[] = "HDR3020000010000" const char HDR3_RMS_FIXED[] = "HDR3020000010000"
"0000000100000000" "0000000100000000"
"0000000002000000" "0000000002000000"
@ -668,7 +659,7 @@ if (sim_switches & SWMASK ('F')) { /* format spec? */
if (sim_switches & SWMASK ('B')) { /* Record Size (blocking factor)? */ if (sim_switches & SWMASK ('B')) { /* Record Size (blocking factor)? */
cptr = get_glyph (cptr, gbuf, 0); /* get spec */ cptr = get_glyph (cptr, gbuf, 0); /* get spec */
if (*cptr == 0) /* must be more */ if (*cptr == 0) /* must be more */
return sim_messagef (SCPE_2FARG, "Missing Record Size and filename to attach\n"); return sim_messagef (SCPE_2FARG, "Missing Record Size and/or filename to attach\n");
recsize = (uint32) get_uint (gbuf, 10, 65536, &r); recsize = (uint32) get_uint (gbuf, 10, 65536, &r);
if ((r != SCPE_OK) || (recsize == 0)) if ((r != SCPE_OK) || (recsize == 0))
return sim_messagef (SCPE_ARG, "Invalid Tape Record Size: %s\n", gbuf); return sim_messagef (SCPE_ARG, "Invalid Tape Record Size: %s\n", gbuf);
@ -685,9 +676,10 @@ if ((MT_GET_FMT (uptr) == MTUF_F_TPC) ||
sim_switches |= SWMASK ('R'); /* Force ReadOnly attach for TPC, TAR and ANSI tapes */ sim_switches |= SWMASK ('R'); /* Force ReadOnly attach for TPC, TAR and ANSI tapes */
if (sim_switches & SWMASK ('X')) if (sim_switches & SWMASK ('X'))
cptr = get_glyph_nc (cptr, export_file, 0); /* get export file spec */ cptr = get_glyph_nc (cptr, export_file, 0); /* get export file spec */
switch (MT_GET_FMT (uptr)) { switch (MT_GET_FMT (uptr)) {
case MTUF_F_ANSI: case MTUF_F_ANSI:
if (1) { {
const char *ocptr = cptr; const char *ocptr = cptr;
char label[CBUFSIZE] = "simh"; char label[CBUFSIZE] = "simh";
int file_errors = 0; int file_errors = 0;
@ -734,7 +726,7 @@ switch (MT_GET_FMT (uptr)) {
break; break;
case MTUF_F_FIXED: case MTUF_F_FIXED:
if (1) { {
FILE *f; FILE *f;
size_t max_record_size; size_t max_record_size;
t_bool lf_line_endings; t_bool lf_line_endings;
@ -826,7 +818,7 @@ switch (MT_GET_FMT (uptr)) {
break; break;
case MTUF_F_DOS11: case MTUF_F_DOS11:
if (1) { {
const char *ocptr = cptr; const char *ocptr = cptr;
int file_errors = 0; int file_errors = 0;
@ -1102,8 +1094,8 @@ return 0;
static t_offset sim_tape_size (UNIT *uptr) static t_offset sim_tape_size (UNIT *uptr)
{ {
if (MT_GET_FMT (uptr) < MTUF_F_ANSI) if (MT_GET_FMT (uptr) < MTUF_F_ANSI)
return sim_fsize_ex (uptr->fileref); return sim_fsize_ex (uptr->fileref); /* True on-disk tape images: file size */
return uptr->tape_eom; return uptr->tape_eom; /* Virtual tape images: record/TM count */
} }
/* Read record length forward (internal routine). /* Read record length forward (internal routine).
@ -1218,7 +1210,7 @@ MT_CLR_PNU (uptr); /* clear the position-no
if ((uptr->flags & UNIT_ATT) == 0) /* if the unit is not attached */ if ((uptr->flags & UNIT_ATT) == 0) /* if the unit is not attached */
return MTSE_UNATT; /* then quit with an error */ return MTSE_UNATT; /* then quit with an error */
if ((uptr->tape_eom) && if ((uptr->tape_eom > 0) &&
(uptr->pos >= uptr->tape_eom)) { (uptr->pos >= uptr->tape_eom)) {
MT_SET_PNU (uptr); /* then set position not updated */ MT_SET_PNU (uptr); /* then set position not updated */
return MTSE_EOM; /* and quit with I/O error status */ return MTSE_EOM; /* and quit with I/O error status */
@ -1318,7 +1310,7 @@ switch (f) { /* otherwise the read method
runaway_counter -= sizeof_gap; /* then decrement the gap counter */ runaway_counter -= sizeof_gap; /* then decrement the gap counter */
else if (*bc == MTR_FHGAP) { /* otherwise if the value if a half gap */ else if (*bc == MTR_FHGAP) { /* otherwise if the value if a half gap */
uptr->pos = uptr->pos - sizeof (t_mtrlnt) / 2; /* then back up and resync */ uptr->pos -= sizeof (t_mtrlnt) / 2; /* then back up and resync */
if (sim_tape_seek (uptr, uptr->pos)) { /* set the tape position; if it fails */ if (sim_tape_seek (uptr, uptr->pos)) { /* set the tape position; if it fails */
status = sim_tape_ioerr (uptr); /* then quit with I/O error status */ status = sim_tape_ioerr (uptr); /* then quit with I/O error status */
@ -1391,7 +1383,7 @@ switch (f) { /* otherwise the read method
if (tpcbc == TPC_TMK) /* tape mark? */ if (tpcbc == TPC_TMK) /* tape mark? */
status = MTSE_TMK; status = MTSE_TMK;
else else
uptr->pos = uptr->pos + ((tpcbc + 1) & ~1); /* spc over record */ uptr->pos += (tpcbc + 1) & ~1; /* spc over record */
} }
} }
break; break;
@ -4200,6 +4192,8 @@ SIM_TEST(sim_tape_test_process_tape_file (dptr->units, "TapeTestFile1", "e11", 0
sim_switches = saved_switches; sim_switches = saved_switches;
SIM_TEST(sim_tape_test_process_tape_file (dptr->units, "TapeTestFile1", "simh", 0)); SIM_TEST(sim_tape_test_process_tape_file (dptr->units, "TapeTestFile1", "simh", 0));
sim_switches = saved_switches;
if ((sim_switches & SWMASK ('D')) == 0)
SIM_TEST(sim_tape_test_remove_tape_files (dptr->units, "TapeTestFile1")); SIM_TEST(sim_tape_test_remove_tape_files (dptr->units, "TapeTestFile1"));
return SCPE_OK; return SCPE_OK;
@ -4594,7 +4588,7 @@ else {
fclose (f); fclose (f);
free (block); free (block);
memory_tape_add_block (tape, NULL, 0); memory_tape_add_block (tape, NULL, 0); /* Tape Mark */
++tape->file_count; ++tape->file_count;
} }
@ -4665,8 +4659,14 @@ while (EOF != (chr = fgetc (f))) {
} }
} }
rewind (f); rewind (f);
/* Binary file */
if (non_print_chars) if (non_print_chars)
*max_record_size = 512; *max_record_size = 512;
/* Text file */
else { else {
if ((crlf_lines > 0) && (lf_lines == 0)) { if ((crlf_lines > 0) && (lf_lines == 0)) {
*lf_line_endings = FALSE; *lf_line_endings = FALSE;
@ -4747,11 +4747,12 @@ block = (uint8 *)calloc (tape->block_size, 1);
while (!feof (f) && !error) { while (!feof (f) && !error) {
size_t data_read = tape->block_size; size_t data_read = tape->block_size;
if (lf_line_endings || crlf_line_endings) /* text file? */ if (lf_line_endings || crlf_line_endings) /* Text file? */
ansi_fill_text_buffer (f, (char *)block, tape->block_size, ansi_fill_text_buffer (f, (char *)block, tape->block_size,
crlf_line_endings ? ansi->skip_crlf_line_endings : ansi->skip_lf_line_endings, crlf_line_endings ? ansi->skip_crlf_line_endings : ansi->skip_lf_line_endings,
ansi->fixed_text); ansi->fixed_text);
else
else /* Binary file */
data_read = fread (block, 1, tape->block_size, f); data_read = fread (block, 1, tape->block_size, f);
if (data_read > 0) { if (data_read > 0) {
error = memory_tape_add_block (tape, block, data_read); error = memory_tape_add_block (tape, block, data_read);