1
0
mirror of https://github.com/rcornwell/sims.git synced 2026-05-02 14:21:38 +00:00

SCP: Updated to current version

This commit is contained in:
Richard Cornwell
2017-03-12 11:02:04 -04:00
parent 719c19c660
commit 7b42641606
23 changed files with 6164 additions and 2149 deletions

View File

@@ -163,6 +163,8 @@ struct tape_context {
#define AIO_CALLSETUP \
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx; \
\
if (ctx == NULL) \
return sim_messagef (SCPE_IERR, "Bad Attach\n"); \
if ((!callback) || !ctx->asynch_io)
#define AIO_CALL(op, _buf, _bc, _fc, _max, _vbc, _gaplen, _bpi, _obj, _callback)\
@@ -216,16 +218,12 @@ static void *
_tape_io(void *arg)
{
UNIT* volatile uptr = (UNIT*)arg;
int sched_policy;
struct sched_param sched_priority;
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
/* Boost Priority for this I/O thread vs the CPU instruction execution
thread which in general won't be readily yielding the processor when
this thread needs to run */
pthread_getschedparam (pthread_self(), &sched_policy, &sched_priority);
++sched_priority.sched_priority;
pthread_setschedparam (pthread_self(), sched_policy, &sched_priority);
sim_os_set_thread_priority (PRIORITY_ABOVE_NORMAL);
sim_debug (ctx->dbit, ctx->dptr, "_tape_io(unit=%d) starting\n", (int)(uptr-ctx->dptr->units));
@@ -337,7 +335,7 @@ if (ctx) {
return FALSE;
}
static void _tape_cancel (UNIT *uptr)
static t_bool _tape_cancel (UNIT *uptr)
{
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
@@ -350,9 +348,12 @@ if (ctx) {
pthread_mutex_unlock (&ctx->io_lock);
}
}
return FALSE;
}
#else
#define AIO_CALLSETUP
#define AIO_CALLSETUP \
if (uptr->tape_ctx == NULL) \
return sim_messagef (SCPE_IERR, "Bad Attach\n");
#define AIO_CALL(op, _buf, _fc, _bc, _max, _vbc, _gaplen, _bpi, _obj, _callback) \
if (_callback) \
(_callback) (uptr, r);
@@ -364,8 +365,7 @@ if (ctx) {
t_stat sim_tape_set_async (UNIT *uptr, int latency)
{
#if !defined(SIM_ASYNCH_IO)
char *msg = "Tape: can't operate asynchronously\r\n";
sim_printf ("%s", msg);
sim_printf ("Tape: can't operate asynchronously\r\n");
return SCPE_NOFNC;
#else
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
@@ -389,7 +389,7 @@ if (ctx->asynch_io) {
}
uptr->a_check_completion = _tape_completion_dispatch;
uptr->a_is_active = _tape_is_active;
uptr->a_cancel = _tape_cancel;
uptr->cancel = _tape_cancel;
return SCPE_OK;
#endif
}
@@ -440,7 +440,11 @@ fflush (uptr->fileref);
t_stat sim_tape_attach (UNIT *uptr, CONST char *cptr)
{
return sim_tape_attach_ex (uptr, cptr, 0, 0);
DEVICE *dptr;
if ((dptr = find_dev_from_unit (uptr)) == NULL)
return SCPE_NOATT;
return sim_tape_attach_ex (uptr, cptr, (dptr->flags & DEV_DEBUG) ? 0xFFFFFFFF : 0, 0);
}
t_stat sim_tape_attach_ex (UNIT *uptr, const char *cptr, uint32 dbit, int completion_delay)
@@ -522,12 +526,15 @@ return SCPE_OK;
t_stat sim_tape_detach (UNIT *uptr)
{
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
struct tape_context *ctx;
uint32 f = MT_GET_FMT (uptr);
t_stat r;
t_bool auto_format = FALSE;
if ((uptr == NULL) || !(uptr->flags & UNIT_ATT))
if (uptr == NULL)
return SCPE_IERR;
ctx = (struct tape_context *)uptr->tape_ctx;
if ((ctx == NULL) || !(uptr->flags & UNIT_ATT))
return SCPE_IERR;
if (uptr->io_flush)
@@ -591,6 +598,8 @@ static void sim_tape_data_trace(UNIT *uptr, const uint8 *data, size_t len, const
{
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
if (ctx == NULL)
return;
if (sim_deb && (ctx->dptr->dctrl & reason))
sim_data_trace(ctx->dptr, uptr, (detail ? data : NULL), "", len, txt, reason);
}
@@ -697,6 +706,8 @@ MT_CLR_PNU (uptr); /* clear the position-no
if ((uptr->flags & UNIT_ATT) == 0) /* if the unit is not attached */
return MTSE_UNATT; /* then quit with an error */
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_fseek (uptr->fileref, uptr->pos, SEEK_SET); /* set the initial tape position */
@@ -907,6 +918,8 @@ MT_CLR_PNU (uptr); /* clear the position-no
if ((uptr->flags & UNIT_ATT) == 0) /* if the unit is not attached */
return MTSE_UNATT; /* then quit with an error */
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
if (sim_tape_bot (uptr)) /* if the unit is positioned at the BOT */
return MTSE_BOT; /* then reading backward is not possible */
@@ -1070,6 +1083,8 @@ t_mtrlnt i, tbc, rbc;
t_addr opos;
t_stat st;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_rdrecf(unit=%d, buf=%p, max=%d)\n", (int)(uptr-ctx->dptr->units), buf, max);
opos = uptr->pos; /* old position */
@@ -1134,6 +1149,8 @@ uint32 f = MT_GET_FMT (uptr);
t_mtrlnt i, rbc, tbc;
t_stat st;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_rdrecr(unit=%d, buf=%p, max=%d)\n", (int)(uptr-ctx->dptr->units), buf, max);
if (MTSE_OK != (st = sim_tape_rdlntr (uptr, &tbc))) /* read rec lnt */
@@ -1184,6 +1201,8 @@ struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
uint32 f = MT_GET_FMT (uptr);
t_mtrlnt sbc;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_wrrecf(unit=%d, buf=%p, bc=%d)\n", (int)(uptr-ctx->dptr->units), buf, bc);
sim_tape_data_trace(uptr, buf, bc, "Record Write", ctx->dptr->dctrl & MTSE_DBG_DAT, MTSE_DBG_STR);
@@ -1244,6 +1263,8 @@ struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
MT_CLR_PNU (uptr);
if ((uptr->flags & UNIT_ATT) == 0) /* not attached? */
return MTSE_UNATT;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
if (sim_tape_wrp (uptr)) /* write prot? */
return MTSE_WRP;
sim_fseek (uptr->fileref, uptr->pos, SEEK_SET); /* set pos */
@@ -1263,6 +1284,8 @@ t_stat sim_tape_wrtmk (UNIT *uptr)
{
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_wrtmk(unit=%d)\n", (int)(uptr-ctx->dptr->units));
if (MT_GET_FMT (uptr) == MTUF_F_P7B) { /* P7B? */
uint8 buf = P7B_EOF; /* eof mark */
@@ -1287,6 +1310,8 @@ t_stat sim_tape_wreom (UNIT *uptr)
t_stat result;
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_wreom(unit=%d)\n", (int)(uptr-ctx->dptr->units));
if (MT_GET_FMT (uptr) == MTUF_F_P7B) /* cant do P7B */
return MTSE_FMT;
@@ -1315,6 +1340,8 @@ t_stat sim_tape_wreomrw (UNIT *uptr)
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
t_stat r;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_wreomrw(unit=%d)\n", (int)(uptr-ctx->dptr->units));
if (MT_GET_FMT (uptr) == MTUF_F_P7B) /* cant do P7B */
return MTSE_FMT;
@@ -1447,6 +1474,8 @@ const uint32 format = MT_GET_FMT (uptr); /* tape format */
const uint32 meta_size = sizeof (t_mtrlnt); /* bytes per metadatum */
const uint32 min_rec_size = 2 + sizeof (t_mtrlnt) * 2; /* smallest data record size */
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_wrgap(unit=%d, gaplen=%u)\n", (int)(uptr-ctx->dptr->units), gaplen);
MT_CLR_PNU (uptr);
@@ -1614,6 +1643,8 @@ t_stat sim_tape_sprecf (UNIT *uptr, t_mtrlnt *bc)
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
t_stat st;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_sprecf(unit=%d)\n", (int)(uptr-ctx->dptr->units));
st = sim_tape_rdlntf (uptr, bc); /* get record length */
@@ -1655,6 +1686,8 @@ struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
t_stat st;
t_mtrlnt tbc;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_sprecsf(unit=%d, count=%d)\n", (int)(uptr-ctx->dptr->units), count);
*skipped = 0;
@@ -1700,6 +1733,8 @@ t_stat sim_tape_sprecr (UNIT *uptr, t_mtrlnt *bc)
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
t_stat st;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_sprecr(unit=%d)\n", (int)(uptr-ctx->dptr->units));
if (MT_TST_PNU (uptr)) {
@@ -1747,6 +1782,8 @@ struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
t_stat st;
t_mtrlnt tbc;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_sprecsr(unit=%d, count=%d)\n", (int)(uptr-ctx->dptr->units), count);
*skipped = 0;
@@ -1796,6 +1833,8 @@ t_stat st;
t_bool last_tapemark = FALSE;
uint32 filerecsskipped;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_spfilebyrecf(unit=%d, count=%d, check_leot=%d)\n", (int)(uptr-ctx->dptr->units), count, check_leot);
if (check_leot) {
@@ -1864,6 +1903,8 @@ t_stat sim_tape_spfilef (UNIT *uptr, uint32 count, uint32 *skipped)
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
uint32 totalrecsskipped;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_spfilef(unit=%d, count=%d)\n", (int)(uptr-ctx->dptr->units), count);
return sim_tape_spfilebyrecf (uptr, count, skipped, &totalrecsskipped, FALSE);
@@ -1905,6 +1946,8 @@ struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
t_stat st;
uint32 filerecsskipped;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_spfilebyrecr(unit=%d, count=%d)\n", (int)(uptr-ctx->dptr->units), count);
*skipped = 0;
@@ -1958,6 +2001,8 @@ t_stat sim_tape_spfiler (UNIT *uptr, uint32 count, uint32 *skipped)
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
uint32 totalrecsskipped;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_spfiler(unit=%d, count=%d)\n", (int)(uptr-ctx->dptr->units), count);
return sim_tape_spfilebyrecr (uptr, count, skipped, &totalrecsskipped);
@@ -1979,6 +2024,8 @@ t_stat sim_tape_rewind (UNIT *uptr)
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
if (uptr->flags & UNIT_ATT) {
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n");/* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_rewind(unit=%d)\n", (int)(uptr-ctx->dptr->units));
}
uptr->pos = 0;
@@ -2002,6 +2049,8 @@ t_stat sim_tape_position (UNIT *uptr, uint32 flags, uint32 recs, uint32 *recsski
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;
t_stat r = MTSE_OK;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_position(unit=%d, flags=0x%X, recs=%d, files=%d)\n", (int)(uptr-ctx->dptr->units), flags, recs, files);
*recsskipped = *filesskipped = *objectsskipped = 0;
@@ -2066,6 +2115,8 @@ MT_CLR_PNU (uptr);
if (!(uptr->flags & UNIT_ATT)) /* attached? */
return SCPE_OK;
if (ctx == NULL) /* if not properly attached? */
return sim_messagef (SCPE_IERR, "Bad Attach\n"); /* that's a problem */
sim_debug (ctx->dbit, ctx->dptr, "sim_tape_reset(unit=%d)\n", (int)(uptr-ctx->dptr->units));
_sim_tape_io_flush(uptr);
@@ -2112,10 +2163,10 @@ t_stat sim_tape_set_fmt (UNIT *uptr, int32 val, CONST char *cptr, void *desc)
{
uint32 f;
if (uptr->flags & UNIT_ATT)
return SCPE_ALATT;
if (uptr == NULL)
return SCPE_IERR;
if (uptr->flags & UNIT_ATT)
return SCPE_ALATT;
if (cptr == NULL)
return SCPE_ARG;
for (f = 0; f < MTUF_N_FMT; f++) {