1
0
mirror of https://github.com/rcornwell/sims.git synced 2026-04-03 12:22:52 +00:00

SIM_CARD: Fixed auto detection to work correctly with mixed decks.

This commit is contained in:
Richard Cornwell
2023-02-11 14:50:37 -05:00
parent 96de4bf2bc
commit 4574ef89c9
2 changed files with 48 additions and 35 deletions

View File

@@ -53,11 +53,11 @@
of card.
ASCII mode recognizes some additional forms of input which allows the
intermixing of binary cards with text cards.
intermixing of binary cards with text cards.
Lines beginning with ~raw are taken as a number of 4 digit octal values
with represent each column of the card from 12 row down to 9 row. If there
is not enough octal numbers to span a full card the remainder of the
is not enough octal numbers to span a full card the remainder of the
card will not be punched.
Also ~eor, will generate a 7/8/9 punch card. An ~eof will gernerate a
@@ -66,7 +66,10 @@
A single line of ~ will set the EOF flag when that card is read.
For autodetection of card format, there can be no parity errors.
All undeterminate formats are treated as ASCII.
All undeterminate formats are treated as ASCII. CBN and BCD cards
must also contain short or full records, if the record is not terminate
early by a EOR flag, then only up to record size (80 for BCD and
160 for CBN will be read).
Auto output format is ASCII if card has only printable characters
or card format binary.
@@ -683,6 +686,7 @@ _sim_parse_card(UNIT *uptr, DEVICE *dptr, struct _card_buffer *buf, uint16 (*ima
int col;
sim_debug(DEBUG_CARD, dptr, "Read card ");
memset(image, 0, 160);
if ((uptr->flags & UNIT_CARD_MODE) == MODE_AUTO) {
mode = MODE_TEXT; /* Default is text */
@@ -697,27 +701,29 @@ _sim_parse_card(UNIT *uptr, DEVICE *dptr, struct _card_buffer *buf, uint16 (*ima
int odd = 0;
int even = 0;
/* Clear record mark */
buf->buffer[0] &= 0x7f;
/* Check all chars for correct parity */
for(i = 0, temp = 0; i < buf->len; i++) {
uint8 ch = buf->buffer[i];
/* Stop at EOR */
if (ch & 0x80)
break;
uint8 ch = buf->buffer[i] & 0177;
/* Try matching parity */
if (sim_parity_table[(ch & 077)] == (ch & 0100))
even++;
else
odd++;
/* Check if we hit end of record. */
if ((i == 79 && even == 80) || (i == 159 && odd == 160)) {
ch = buf->buffer[i+1];
/* If we have EOR then all ok */
if (ch & 0x80)
break;
if (ch == '\r' || ch == '\n' || ch >= ' ')
break;
}
}
/* Restore it */
buf->buffer[0] |= 0x80;
if (i == 160 && odd == i)
if (even == 0 && odd == 160)
mode = MODE_CBN;
else if (i < 80 && even == i)
else if (odd == 80 && even == 0)
mode = MODE_BCD;
}
}
/* Check if modes match */
if ((uptr->flags & UNIT_CARD_MODE) != MODE_AUTO &&
@@ -788,6 +794,10 @@ _sim_parse_card(UNIT *uptr, DEVICE *dptr, struct _card_buffer *buf, uint16 (*ima
sim_debug(DEBUG_CARD, dptr, "-eoi-");
(*image)[0] = 017; /* 6/7/8/9 punch */
i = 4;
} else if (_cmpcard(&buf->buffer[0], "78")) {
sim_debug(DEBUG_CARD, dptr, "-78-");
(*image)[0] = 06; /* 7/8 punch */
i = 3;
} else {
/* Convert text line into card image */
for (col = 0, i = 0; col < 80 && i < buf->len; i++) {
@@ -889,14 +899,16 @@ _sim_parse_card(UNIT *uptr, DEVICE *dptr, struct _card_buffer *buf, uint16 (*ima
(*image)[col++] |= c;
}
if (i < buf->len && col >= 80 && (buf->buffer[i] & 0x80) == 0) {
(*image)[0] |= CARD_ERR;
}
/* Record over length of card, skip until next */
while ((buf->buffer[i] & 0x80) == 0) {
if (i > buf->len)
break;
i++;
if ((uptr->flags & UNIT_CARD_MODE) != MODE_AUTO) {
if (i < buf->len && col >= 80 && (buf->buffer[i] & 0x80) == 0) {
(*image)[0] |= CARD_ERR;
while ((buf->buffer[i] & 0x80) == 0) {
if (i > buf->len)
break;
i++;
}
}
}
break;
@@ -909,9 +921,6 @@ _sim_parse_card(UNIT *uptr, DEVICE *dptr, struct _card_buffer *buf, uint16 (*ima
break;
}
/* Clear record mark */
buf->buffer[0] &= 0x7f;
/* Convert text line into card image */
for (col = 0, i = 0; col < 80 && i < buf->len; i++) {
if (buf->buffer[i] & 0x80)
@@ -924,17 +933,17 @@ _sim_parse_card(UNIT *uptr, DEVICE *dptr, struct _card_buffer *buf, uint16 (*ima
(*image)[col++] = sim_bcd_to_hol(c);
}
if (i < buf->len && col >= 80 && (buf->buffer[i] & 0x80) == 0) {
(*image)[0] |= CARD_ERR;
}
/* Record over length of card, skip until next */
while ((buf->buffer[i] & 0x80) == 0) {
if (i > buf->len)
break;
i++;
if ((uptr->flags & UNIT_CARD_MODE) != MODE_AUTO) {
if (i < buf->len && col >= 80 && (buf->buffer[i] & 0x80) == 0) {
(*image)[0] |= CARD_ERR;
while ((buf->buffer[i] & 0x80) == 0) {
if (i > buf->len)
break;
i++;
}
}
}
sim_debug(DEBUG_CARD, dptr, "]\n");
break;
@@ -1424,7 +1433,7 @@ t_stat sim_card_attach_help(FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, cons
}
if (uptr == NULL)
uptr = dptr->units;
fprintf (st, "%s Card %s%s%sAttach Help\n\n", dptr->name,
fprintf (st, "%s Card %s%s%sAttach Help\n\n", dptr->name,
readers ? "Reader " : "", readers & punches ? "& " : "", punches ? "Punch ": "");
if (0 == (uptr-dptr->units)) {
if (dptr->numunits > 1) {

View File

@@ -53,7 +53,11 @@
of card.
For autodetection of BCD card format, there can be no parity errors.
All undeterminate formats are treated as ASCII.
All undeterminate formats are treated as ASCII. CBN and BCD cards
must also contain short or full records, if the record is not terminate
early by a EOR flag, then only up to record size (80 for BCD and
160 for CBN will be read).
ASCII mode recognizes some additional forms of input which allows the
intermixing of binary cards with text cards.