mirror of
https://github.com/simh/simh.git
synced 2026-01-11 23:52:58 +00:00
SIM_CARD: Fixed to better detect mixed binary and ascii decks.
This commit is contained in:
parent
d7560cf3e4
commit
a56316389d
79
sim_card.c
79
sim_card.c
@ -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.
|
||||
@ -152,7 +155,7 @@ static const uint16 ascii_to_hol_026[128] = {
|
||||
/* p q r s t u v w */
|
||||
0xC04, 0xC02, 0xC01, 0x680, 0x640, 0x620, 0x610, 0x608,
|
||||
/* x y z { | } ~ del */
|
||||
/* T79 X78 Y79 79 */
|
||||
/* T79 X78 X79 79 */
|
||||
0x604, 0x602, 0x601, 0x406, 0x806, 0x805, 0x005, 0xf000
|
||||
};
|
||||
|
||||
@ -682,6 +685,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 */
|
||||
|
||||
@ -696,27 +700,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 &&
|
||||
@ -787,6 +793,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++) {
|
||||
@ -888,14 +898,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;
|
||||
|
||||
@ -908,9 +920,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)
|
||||
@ -923,17 +932,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;
|
||||
|
||||
@ -1423,7 +1432,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) {
|
||||
|
||||
@ -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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user