Added framework to support per device help commands

This commit is contained in:
Mark Pizzolato 2012-12-30 13:12:15 -08:00
parent bdcfe994e0
commit ba0f331fa5
9 changed files with 161 additions and 20 deletions

View file

@ -175,6 +175,7 @@
#define CPUT(x) ((cpu_type & (x)) != 0)
#define CPUO(x) ((cpu_opt & (x)) != 0)
#define UNIBUS (cpu_opt & BUS_U)
extern uint32 cpu_model, cpu_type, cpu_opt;
/* Feature sets

126
scp.c
View file

@ -215,6 +215,8 @@
#include "sim_defs.h"
#include "sim_rev.h"
#include "sim_disk.h"
#include "sim_tape.h"
#include "sim_ether.h"
#include "sim_serial.h"
#include "sim_sock.h"
@ -746,12 +748,12 @@ static CTAB cmd_table[] = {
"echo <string> display <string>\n" },
{ "ASSERT", &assert_cmd, 0,
"assert {<dev>} <cond> test simulator state against condition\n" },
{ "HELP", &help_cmd, 0,
"h{elp} type this message\n"
"h{elp} <command> type help for command\n" },
{ "!", &spawn_cmd, 0,
"! execute local command interpreter\n"
"! <command> execute local host command\n" },
{ "HELP", &help_cmd, 0,
"h{elp} type this message\n"
"h{elp} <command> type help for command\n" },
{ NULL, NULL, 0 }
};
@ -980,6 +982,8 @@ return SCPE_EXIT;
void fprint_help (FILE *st)
{
CTAB *cmdp;
DEVICE *dptr;
int i;
for (cmdp = sim_vm_cmd; cmdp && (cmdp->name != NULL); cmdp++) {
if (cmdp->help)
@ -989,6 +993,21 @@ for (cmdp = cmd_table; cmdp && (cmdp->name != NULL); cmdp++) {
if (cmdp->help && (!sim_vm_cmd || !find_ctab (sim_vm_cmd, cmdp->name)))
fputs (cmdp->help, st);
}
for (i = 0; (dptr = sim_devices[i]) != NULL; i++) {
if (dptr->help)
fprintf (st, "h{elp} %-17s type help for device %s\n", dptr->name, dptr->name);
if (dptr->attach_help ||
(DEV_TYPE(dptr) == DEV_MUX) ||
(DEV_TYPE(dptr) == DEV_DISK) ||
(DEV_TYPE(dptr) == DEV_TAPE)) {
if (dptr->numunits == 1)
fprintf (st, "h{elp} %s ATTACH\t type help for device %s ATTACH command\n", dptr->name, dptr->name);
else {
fprintf (st, "h{elp} %s ATTACH\t type help for device %s ATTACH command\n", dptr->name, dptr->name);
fprintf (st, "h{elp} %sn ATTACH\t type help for unit %sn ATTACH command\n", dptr->name, dptr->name);
}
}
}
return;
}
@ -1000,13 +1019,33 @@ CTAB *cmdp;
GET_SWITCHES (cptr);
if (*cptr) {
cptr = get_glyph (cptr, gbuf, 0);
if (*cptr)
return SCPE_2MARG;
if ((cmdp = find_cmd (gbuf))) {
if (*cptr)
return SCPE_2MARG;
if (cmdp->help) {
fputs (cmdp->help, stdout);
if (sim_log)
fputs (cmdp->help, sim_log);
if (strcmp (cmdp->name, "HELP") == 0) {
DEVICE *dptr;
int i;
for (i = 0; (dptr = sim_devices[i]) != NULL; i++) {
if (dptr->help) {
fprintf (stdout, "h{elp} %-17s type help for device %s\n", dptr->name, dptr->name);
if (sim_log)
fprintf (sim_log, "h{elp} %-17s type help for device %s\n", dptr->name, dptr->name);
}
if (dptr->attach_help ||
(DEV_TYPE(dptr) == DEV_MUX) ||
(DEV_TYPE(dptr) == DEV_DISK) ||
(DEV_TYPE(dptr) == DEV_TAPE)) {
fprintf (stdout, "h{elp} %s ATTACH\t type help for device %s ATTACH command\n", dptr->name, dptr->name);
if (sim_log)
fprintf (sim_log, "h{elp} %s ATTACH\t type help for device %s ATTACH command\n", dptr->name, dptr->name);
}
}
}
}
else { /* no help so it is likely a command alias */
CTAB *cmdpa;
@ -1027,7 +1066,80 @@ if (*cptr) {
}
}
}
else return SCPE_ARG;
else {
DEVICE *dptr;
UNIT *uptr;
int i, dev_type;
static struct dev_help {
int type;
t_stat (*attach_help)(FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
} helps[] = {
{DEV_DISK, &sim_disk_attach_help},
{DEV_TAPE, &sim_tape_attach_help},
{DEV_MUX, &tmxr_attach_help},
{0, NULL}};
dptr = find_unit (gbuf, &uptr);
if (dptr == NULL)
return SCPE_ARG;
dev_type = DEV_TYPE (dptr);
for (i=0; helps[i].type; i++)
if (helps[i].type == dev_type)
break;
if (*cptr) {
cptr = get_glyph (cptr, gbuf, 0);
cmdp = find_cmd (gbuf);
}
else
cmdp = NULL;
if ((dptr->help == NULL) && (cmdp == NULL)) {
fprintf (stdout, "No help available for the %s device\n", dptr->name);
if (sim_log)
fprintf (sim_log, "No help available for the %s device\n", dptr->name);
if (dptr->attach_help ||
(DEV_TYPE(dptr) == DEV_MUX) ||
(DEV_TYPE(dptr) == DEV_DISK) ||
(DEV_TYPE(dptr) == DEV_TAPE)) {
fprintf (stdout, "Some help is available if you type HELP %s ATTACH\n", dptr->name);
if (sim_log)
fprintf (sim_log, "Some help is available if you type HELP %s ATTACH\n", dptr->name);
}
}
else {
if (cmdp != NULL) {
if (cmdp->action != &attach_cmd) {
fprintf (stdout, "No help available for the %s device %s command\n", dptr->name, cmdp->name);
if (sim_log)
fprintf (sim_log, "No help available for the %s device %s command\n", dptr->name, cmdp->name);
if (dptr->attach_help ||
(DEV_TYPE(dptr) == DEV_MUX) ||
(DEV_TYPE(dptr) == DEV_DISK) ||
(DEV_TYPE(dptr) == DEV_TAPE)) {
fprintf (stdout, "Some help is available if you type HELP %s ATTACH\n", dptr->name);
if (sim_log)
fprintf (sim_log, "Some help is available if you type HELP %s ATTACH\n", dptr->name);
}
}
else {
if (dptr->attach_help) {
dptr->attach_help (stdout, dptr, uptr, 0, cptr);
if (sim_log)
dptr->attach_help (sim_log, dptr, uptr, 0, cptr);
}
else {
helps[i].attach_help (stdout, dptr, uptr, 0, cptr);
if (sim_log)
helps[i].attach_help (sim_log, dptr, uptr, 0, cptr);
}
}
}
else {
dptr->help (stdout, dptr, uptr, 0, cptr);
if (sim_log)
dptr->help (sim_log, dptr, uptr, 0, cptr);
}
}
}
}
else {
fprint_help (stdout);
@ -2908,8 +3020,6 @@ if (!(uptr->flags & UNIT_ATTABLE)) /* not attachable? */
return SCPE_NOATT;
if ((dptr = find_dev_from_unit (uptr)) == NULL)
return SCPE_NOATT;
if (dptr->flags & DEV_RAWONLY) /* raw mode only? */
return SCPE_NOFNC;
uptr->filename = (char *) calloc (CBUFSIZE, sizeof (char)); /* alloc name buf */
if (uptr->filename == NULL)
return SCPE_MEM;

View file

@ -317,6 +317,10 @@ struct sim_device {
t_stat (*msize)(struct sim_unit *up, int32 v, char *cp, void *dp);
/* mem size routine */
char *lname; /* logical name */
t_stat (*help)(FILE *st, struct sim_device *dptr,
struct sim_unit *uptr, int32 flag, char *cptr); /* help */
t_stat (*attach_help)(FILE *st, struct sim_device *dptr,
struct sim_unit *uptr, int32 flag, char *cptr); /* help */
};
/* Device flags */
@ -324,10 +328,9 @@ struct sim_device {
#define DEV_V_DIS 0 /* dev disabled */
#define DEV_V_DISABLE 1 /* dev disable-able */
#define DEV_V_DYNM 2 /* mem size dynamic */
#define DEV_V_NET 3 /* network attach */
#define DEV_V_DEBUG 4 /* debug capability */
#define DEV_V_RAW 5 /* raw supported */
#define DEV_V_RAWONLY 6 /* only raw supported */
#define DEV_V_DEBUG 3 /* debug capability */
#define DEV_V_TYPE 4 /* Attach type */
#define DEV_S_TYPE 3 /* Width of Type Field */
#define DEV_V_UF_31 12 /* user flags, V3.1 */
#define DEV_V_UF 16 /* user flags */
#define DEV_V_RSV 31 /* reserved */
@ -335,10 +338,17 @@ struct sim_device {
#define DEV_DIS (1 << DEV_V_DIS)
#define DEV_DISABLE (1 << DEV_V_DISABLE)
#define DEV_DYNM (1 << DEV_V_DYNM)
#define DEV_NET (1 << DEV_V_NET)
#define DEV_DEBUG (1 << DEV_V_DEBUG)
#define DEV_RAW (1 << DEV_V_RAW)
#define DEV_RAWONLY (1 << DEV_V_RAWONLY)
#define DEV_NET 0 /* Deprecated - meaningless */
#define DEV_TYPEMASK (((1 << DEV_S_TYPE) - 1) << DEV_V_TYPE)
#define DEV_DISK (1 << DEV_S_TYPE) /* sim_disk Attach */
#define DEV_TAPE (2 << DEV_S_TYPE) /* sim_tape Attach */
#define DEV_MUX (3 << DEV_S_TYPE) /* sim_tmxr Attach */
#define DEV_ETHER (4 << DEV_S_TYPE) /* Ethernet Device */
#define DEV_DISPLAY (5 << DEV_S_TYPE) /* Display Device */
#define DEV_TYPE(dptr) ((dptr)->flags & DEV_TYPEMASK)
#define DEV_UFMASK_31 (((1u << DEV_V_RSV) - 1) & ~((1u << DEV_V_UF_31) - 1))
#define DEV_UFMASK (((1u << DEV_V_RSV) - 1) & ~((1u << DEV_V_UF) - 1))

View file

@ -34,6 +34,7 @@ Public routines:
sim_disk_attach attach disk unit
sim_disk_detach detach disk unit
sim_disk_attach_help help routine for attaching disks
sim_disk_rdsect read disk sectors
sim_disk_rdsect_a read disk sectors asynchronously
sim_disk_wrsect write disk sectors
@ -1131,6 +1132,12 @@ if (close_function (fileref) == EOF)
return SCPE_OK;
}
t_stat sim_disk_attach_help(FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr)
{
fprintf (st, "%s Disk Attach Help\n", dptr->name);
return SCPE_OK;
}
t_stat sim_disk_reset (UNIT *uptr)
{
if (!(uptr->flags & UNIT_ATT)) /* attached? */

View file

@ -67,6 +67,7 @@ typedef void (*DISK_PCALLBACK)(UNIT *unit, t_stat status);
t_stat sim_disk_attach (UNIT *uptr, char *cptr, size_t sector_size, size_t xfer_element_size, t_bool dontautosize,
uint32 debugbit, const char *drivetype, uint32 pdp11_tracksize, int completion_delay);
t_stat sim_disk_detach (UNIT *uptr);
t_stat sim_disk_attach_help(FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
t_stat sim_disk_rdsect (UNIT *uptr, t_lba lba, uint8 *buf, t_seccnt *sectsread, t_seccnt sects);
t_stat sim_disk_rdsect_a (UNIT *uptr, t_lba lba, uint8 *buf, t_seccnt *sectsread, t_seccnt sects, DISK_PCALLBACK callback);
t_stat sim_disk_wrsect (UNIT *uptr, t_lba lba, uint8 *buf, t_seccnt *sectswritten, t_seccnt sects);

View file

@ -58,6 +58,7 @@
sim_tape_attach attach tape unit
sim_tape_detach detach tape unit
sim_tape_attach_help help routine for attaching tapes
sim_tape_rdrecf read tape record forward
sim_tape_rdrecr read tape record reverse
sim_tape_wrrecf write tape record forward
@ -506,6 +507,12 @@ uptr->io_flush = NULL;
return SCPE_OK;
}
t_stat sim_tape_attach_help(FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr)
{
fprintf (st, "%s Tape Attach Help\n", dptr->name);
return SCPE_OK;
}
void sim_tape_data_trace(UNIT *uptr, const uint8 *data, size_t len, const char* txt, int detail, uint32 reason)
{
struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx;

View file

@ -124,6 +124,7 @@ typedef void (*TAPE_PCALLBACK)(UNIT *unit, t_stat status);
t_stat sim_tape_attach_ex (UNIT *uptr, char *cptr, uint32 dbit, int completion_delay);
t_stat sim_tape_attach (UNIT *uptr, char *cptr);
t_stat sim_tape_detach (UNIT *uptr);
t_stat sim_tape_attach_help(FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
t_stat sim_tape_rdrecf (UNIT *uptr, uint8 *buf, t_mtrlnt *bc, t_mtrlnt max);
t_stat sim_tape_rdrecf_a (UNIT *uptr, uint8 *buf, t_mtrlnt *bc, t_mtrlnt max, TAPE_PCALLBACK callback);
t_stat sim_tape_rdrecr (UNIT *uptr, uint8 *buf, t_mtrlnt *bc, t_mtrlnt max);

View file

@ -78,6 +78,7 @@
tmxr_close_master - close master connection
tmxr_attach - attach terminal multiplexor to listening port
tmxr_detach - detach terminal multiplexor to listening port
tmxr_attach_help - help routine for attaching multiplexer devices
tmxr_set_line_unit - set the unit which polls for input for a given line
tmxr_ex - (null) examine
tmxr_dep - (null) deposit
@ -2068,12 +2069,8 @@ for (i = 0; i < mp->lines; i++) { /* loop thru conn */
tmxr_reset_ln (lp);
}
if (lp->serport) {
tmxr_reset_ln (lp);
sim_control_serial (lp->serport, 0, TMXR_MDM_DTR|TMXR_MDM_RTS, NULL);/* drop DTR and RTS */
sim_close_serial (lp->serport);
lp->serport = 0;
free (lp->serconfig);
lp->serconfig = NULL;
tmxr_close_ln (lp);
}
free (lp->destination);
lp->destination = NULL;
@ -2109,6 +2106,12 @@ uptr->flags = uptr->flags & ~UNIT_ATT; /* not attached */
return SCPE_OK;
}
t_stat tmxr_attach_help(FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr)
{
fprintf (st, "%s Multiplexer Attach Help\n", dptr->name);
return SCPE_OK;
}
/* Stub examine and deposit */
t_stat tmxr_ex (t_value *vptr, t_addr addr, UNIT *uptr, int32 sw)

View file

@ -151,6 +151,7 @@ t_stat tmxr_open_master (TMXR *mp, char *cptr);
t_stat tmxr_close_master (TMXR *mp);
t_stat tmxr_attach (TMXR *mp, UNIT *uptr, char *cptr);
t_stat tmxr_detach (TMXR *mp, UNIT *uptr);
t_stat tmxr_attach_help(FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
t_stat tmxr_set_modem_control_passthru (TMXR *mp);
t_stat tmxr_clear_modem_control_passthru (TMXR *mp);
t_stat tmxr_set_get_modem_bits (TMLN *lp, int32 bits_to_set, int32 bits_to_clear, int32 *incoming_bits);