From c3a879da2d24b81e54dcb5950956376a0ff33b83 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Mon, 28 Sep 2015 09:19:38 -0700 Subject: [PATCH] VAX: Change to load ROMs or other boot code directly from built in memory arrays. Prior logic attempted to load the desired file from the current default directory and if that failed wrote the in memory boot code image to the desired file and then retried the desired load.. A user can still explicitly load a ROM image with a "LOAD -R romfile.bin" command prior to a BOOT attempt if they want to test or otherwise run with a different ROM. --- VAX/vax610_syslist.c | 2 +- VAX/vax630_syslist.c | 2 +- VAX/vax730_syslist.c | 2 +- VAX/vax750_syslist.c | 2 +- VAX/vax780_syslist.c | 2 +- VAX/vax860_syslist.c | 2 +- VAX/vax_cpu.c | 21 +++++---------------- VAX/vax_syslist.c | 2 +- scp.c | 44 ++++++++++++++++++++++++++++++++++++++------ scp.h | 2 ++ 10 files changed, 52 insertions(+), 29 deletions(-) diff --git a/VAX/vax610_syslist.c b/VAX/vax610_syslist.c index 5a2c966c..2d5a2f86 100644 --- a/VAX/vax610_syslist.c +++ b/VAX/vax610_syslist.c @@ -117,7 +117,7 @@ if (sim_switches & SWMASK ('O')) { /* origin? */ if (r != SCPE_OK) return SCPE_ARG; } -while ((i = getc (fileref)) != EOF) { /* read byte stream */ +while ((i = Fgetc (fileref)) != EOF) { /* read byte stream */ if (origin >= limit) /* NXM? */ return SCPE_NXM; else WriteB (origin, i); /* store byte */ diff --git a/VAX/vax630_syslist.c b/VAX/vax630_syslist.c index 497a0fe4..258c249f 100644 --- a/VAX/vax630_syslist.c +++ b/VAX/vax630_syslist.c @@ -144,7 +144,7 @@ else { return SCPE_ARG; } } -while ((i = getc (fileref)) != EOF) { /* read byte stream */ +while ((i = Fgetc (fileref)) != EOF) { /* read byte stream */ if (origin >= limit) /* NXM? */ return SCPE_NXM; if (sim_switches & SWMASK ('R')) /* ROM? */ diff --git a/VAX/vax730_syslist.c b/VAX/vax730_syslist.c index 3f1d2085..30184665 100644 --- a/VAX/vax730_syslist.c +++ b/VAX/vax730_syslist.c @@ -117,7 +117,7 @@ if (sim_switches & SWMASK ('O')) { /* origin? */ return SCPE_ARG; } -while ((val = getc (fileref)) != EOF) { /* read byte stream */ +while ((val = Fgetc (fileref)) != EOF) { /* read byte stream */ if (sim_switches & SWMASK ('R')) { /* ROM0? */ return SCPE_NXM; } diff --git a/VAX/vax750_syslist.c b/VAX/vax750_syslist.c index e4c600fa..b3abd741 100644 --- a/VAX/vax750_syslist.c +++ b/VAX/vax750_syslist.c @@ -126,7 +126,7 @@ else return SCPE_ARG; } -while ((val = getc (fileref)) != EOF) { /* read byte stream */ +while ((val = Fgetc (fileref)) != EOF) { /* read byte stream */ if (origin >= limit) /* NXM? */ return SCPE_NXM; if (sim_switches & SWMASK ('R')) /* ROM? */ diff --git a/VAX/vax780_syslist.c b/VAX/vax780_syslist.c index 52e124f7..511008ac 100644 --- a/VAX/vax780_syslist.c +++ b/VAX/vax780_syslist.c @@ -131,7 +131,7 @@ if (sim_switches & SWMASK ('O')) { /* origin? */ return SCPE_ARG; } -while ((val = getc (fileref)) != EOF) { /* read byte stream */ +while ((val = Fgetc (fileref)) != EOF) { /* read byte stream */ if (sim_switches & SWMASK ('R')) { /* ROM0? */ if (origin >= ROMSIZE) return SCPE_NXM; diff --git a/VAX/vax860_syslist.c b/VAX/vax860_syslist.c index ab2f8069..659a71ad 100644 --- a/VAX/vax860_syslist.c +++ b/VAX/vax860_syslist.c @@ -127,7 +127,7 @@ if (sim_switches & SWMASK ('O')) { /* origin? */ return SCPE_ARG; } -while ((val = getc (fileref)) != EOF) { /* read byte stream */ +while ((val = Fgetc (fileref)) != EOF) { /* read byte stream */ if (origin >= limit) /* NXM? */ return SCPE_NXM; WriteB (origin, val); /* memory */ diff --git a/VAX/vax_cpu.c b/VAX/vax_cpu.c index e8cda95c..36a1e3ad 100644 --- a/VAX/vax_cpu.c +++ b/VAX/vax_cpu.c @@ -3570,27 +3570,16 @@ t_stat cpu_load_bootcode (const char *filename, const unsigned char *builtin_cod char args[CBUFSIZE]; t_stat r; -sim_printf ("Loading boot code from %s\n", filename); +sim_printf ("Loading boot code from %s%s\n", builtin_code ? "internal " : "", filename); +if (builtin_code) + sim_set_memory_load_file (builtin_code, size); if (rom) sprintf (args, "-R %s", filename); else sprintf (args, "-O %s %X", filename, (int)offset); r = load_cmd (0, args); -if (r != SCPE_OK) { - if (builtin_code) { - FILE *f; - - if ((f = sim_fopen (filename, "wb"))) { - sim_printf ("Saving boot code to %s\n", filename); - sim_fwrite ((void *)builtin_code, 1, size, f); - fclose (f); - sim_printf ("Loading boot code from %s\n", filename); - r = load_cmd (0, args); - } - } - return r; - } -return SCPE_OK; +sim_set_memory_load_file (NULL, 0); +return r; } t_stat cpu_help (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, const char *cptr) diff --git a/VAX/vax_syslist.c b/VAX/vax_syslist.c index 3d5f158f..787f64db 100644 --- a/VAX/vax_syslist.c +++ b/VAX/vax_syslist.c @@ -139,7 +139,7 @@ else { return SCPE_ARG; } } -while ((i = getc (fileref)) != EOF) { /* read byte stream */ +while ((i = Fgetc (fileref)) != EOF) { /* read byte stream */ if (origin >= limit) /* NXM? */ return SCPE_NXM; if (sim_switches & SWMASK ('R')) /* ROM? */ diff --git a/scp.c b/scp.c index 7c90b729..259b9585 100644 --- a/scp.c +++ b/scp.c @@ -5048,22 +5048,55 @@ return r; du[mp] filename {arg} dump to specified file */ +/* Memory File use (for internal memory static ROM images) + + when used to read ROM image with internally generated + load commands, calling code setups with sim_set_memory_file() + sim_load uses Fgetc() instead of fgetc() or getc() +*/ + +static const unsigned char *mem_data = NULL; +static size_t mem_data_size = 0; + +t_stat sim_set_memory_load_file (const unsigned char *data, size_t size) +{ +mem_data = data; +mem_data_size = size; +return SCPE_OK; +} + +int Fgetc (FILE *f) +{ +if (mem_data) { + if (mem_data_size == 0) + return EOF; + --mem_data_size; + return (int)(*mem_data++); + } +else + return fgetc (f); +} + + t_stat load_cmd (int32 flag, char *cptr) { char gbuf[CBUFSIZE]; -FILE *loadfile; +FILE *loadfile = NULL; t_stat reason; GET_SWITCHES (cptr); /* get switches */ if (*cptr == 0) /* must be more */ return SCPE_2FARG; cptr = get_glyph_nc (cptr, gbuf, 0); /* get file name */ -loadfile = sim_fopen (gbuf, flag? "wb": "rb"); /* open for wr/rd */ -if (loadfile == NULL) - return SCPE_OPENERR; +if (!mem_data) { + loadfile = sim_fopen (gbuf, flag? "wb": "rb"); /* open for wr/rd */ + if (loadfile == NULL) + return SCPE_OPENERR; + } GET_SWITCHES (cptr); /* get switches */ reason = sim_load (loadfile, cptr, gbuf, flag); /* load or dump */ -fclose (loadfile); +if (loadfile) + fclose (loadfile); return reason; } @@ -9933,7 +9966,6 @@ va_end (args); return ret; } - /* Hierarchical help presentation * * Device help can be presented hierarchically by calling diff --git a/scp.h b/scp.h index e936569e..367d75fb 100644 --- a/scp.h +++ b/scp.h @@ -145,6 +145,8 @@ char *sim_encode_quoted_string (const uint8 *iptr, uint32 size); void fprint_buffer_string (FILE *st, const uint8 *buf, uint32 size); t_value strtotv (const char *cptr, const char **endptr, uint32 radix); int Fprintf (FILE *f, const char* fmt, ...); +t_stat sim_set_memory_load_file (const unsigned char *data, size_t size); +int Fgetc (FILE *f); t_stat fprint_val (FILE *stream, t_value val, uint32 rdx, uint32 wid, uint32 fmt); t_stat sim_print_val (t_value val, uint32 radix, uint32 width, uint32 format); char *read_line (char *cptr, int32 size, FILE *stream);