/* * VARCem Virtual Archaelogical Computer EMulator. * An emulator of (mostly) x86-based PC systems and devices, * using the ISA,EISA,VLB,MCA and PCI system buses, roughly * spanning the era between 1981 and 1995. * * This file is part of the VARCem Project. * * Implement the external ROM loader. * This loader defines a 'ROM set' to be one or more images * of ROM chip(s), where all properties of these defined in * a single 'ROM definition' (text) file. * * NOTE: This file uses a fairly generic script parser, which can * be re-used for others parts. This would mean passing the * 'parser' function a pointer to either a command handler, * or to use a generic handler, and then pass it a pointer * to a command table. For now, we don't. * * Version: @(#)rom_load.c 1.0.2 2018/03/01 * * Author: Fred N. van Kempen, * * Copyright 2018 Fred N. van Kempen. * * Redistribution and use in source and binary forms, with * or without modification, are permitted provided that the * following conditions are met: * * 1. Redistributions of source code must retain the entire * above notice, this list of conditions and the following * disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. Neither the name of the copyright holder nor the names * of its contributors may be used to endorse or promote * products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include #include #include "emu.h" #include "mem.h" #include "rom.h" #include "plat.h" #define PATH_BIOS "bios.txt" /* name of the script we run */ #define MAX_ARGS 16 /* max number of arguments */ /* Process a single (logical) command line. */ static int process(int ln, int argc, char **argv, romdef_t *r) { if (! strcmp(argv[0], "size")) { sscanf(argv[1], "%i", &r->total); } else if (! strcmp(argv[0], "offset")) { if (sscanf(argv[1], "0x%lx", (long unsigned int *)&r->offset) == 0) sscanf(argv[1], "%i", &r->offset); } else if (! strcmp(argv[0], "mode")) { if (! strcmp(argv[1], "linear")) r->mode = 0; else if (! strcmp(argv[1], "interleaved")) r->mode = 1; else { pclog("ROM: invalid mode '%s' on line %d.\n", argv[1], ln); return(0); } } else if (! strcmp(argv[0], "file")) { mbstowcs(r->files[r->nfiles].path, argv[1], sizeof_w(r->files[r->nfiles].path)); if (argc >= 3) sscanf(argv[2], "%i", &r->files[r->nfiles].skip); else r->files[r->nfiles].skip = 0; if (argc == 4) { if (sscanf(argv[3], "0x%lx", (long unsigned int *)&r->files[r->nfiles].offset) == 0) sscanf(argv[3], "%i", &r->files[r->nfiles].offset); } else r->files[r->nfiles].offset = r->offset; r->nfiles++; } else { pclog("ROM: invalid command '%s' on line %d.\n", argv[0], ln); return(0); } return(1); } /* Parse a script file, and call the command handler for each command. */ static int parser(FILE *fp, romdef_t *r) { char line[1024]; char *args[MAX_ARGS]; int doskip, doquot; int skipnl, dolit; int a, c, l; char *sp; /* Initialize the parser and run. */ l = 0; for (;;) { /* Clear the per-line stuff. */ skipnl = dolit = doquot = 0; doskip = 1; for (a=0; a= 0x010000) biosmask = (r.total - 1); break; case 1: /* interleaved file(s) */ /* We loop on all files. */ for (c=0; c= 0x010000) biosmask = (r.total - 1); break; } pclog("ROM: status %d, tot %u, mask 0x%06lx\n", i, r.total, biosmask); } return(i); }