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.
This commit is contained in:
Mark Pizzolato 2015-09-28 09:19:38 -07:00
parent 4921d92650
commit c3a879da2d
10 changed files with 52 additions and 29 deletions

View file

@ -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 */

View file

@ -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? */

View file

@ -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;
}

View file

@ -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? */

View file

@ -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;

View file

@ -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 */

View file

@ -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)

View file

@ -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? */

44
scp.c
View file

@ -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

2
scp.h
View file

@ -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);