Updated ROM BIOS handling to use the external loader.

Several cleanups and fixes here and there.
Updated (Windows) UI to properly handle resets and changes in Settings.
Updated to no longer scan for roms at startup.
This commit is contained in:
waltje
2018-03-02 18:58:18 -05:00
parent 4c10496ae6
commit 227f0446ec
29 changed files with 1315 additions and 1387 deletions

611
src/rom.c
View File

@@ -13,7 +13,7 @@
* - c386sx16 BIOS fails checksum
* - the loadfont() calls should be done elsewhere
*
* Version: @(#)rom.c 1.0.3 2018/02/22
* Version: @(#)rom.c 1.0.4 2018/02/26
*
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
* Miran Grca, <mgrca8@gmail.com>
@@ -59,7 +59,7 @@ int romspresent[ROM_MAX];
FILE *
rom_fopen(wchar_t *fn, wchar_t *mode)
rom_fopen(wchar_t *fn)
{
wchar_t temp[1024];
@@ -67,7 +67,7 @@ rom_fopen(wchar_t *fn, wchar_t *mode)
plat_put_backslash(temp);
wcscat(temp, fn);
return(plat_fopen(temp, mode));
return(plat_fopen(temp, L"rb"));
}
@@ -95,7 +95,7 @@ rom_present(wchar_t *fn)
{
FILE *f;
f = rom_fopen(fn, L"rb");
f = rom_fopen(fn);
if (f != NULL) {
(void)fclose(f);
return(1);
@@ -105,6 +105,7 @@ rom_present(wchar_t *fn)
}
/* Read a byte from some area in ROM. */
uint8_t
rom_read(uint32_t addr, void *priv)
{
@@ -119,6 +120,7 @@ rom_read(uint32_t addr, void *priv)
}
/* Read a word from some area in ROM. */
uint16_t
rom_readw(uint32_t addr, void *priv)
{
@@ -133,6 +135,7 @@ rom_readw(uint32_t addr, void *priv)
}
/* Read a double-word from some area in ROM. */
uint32_t
rom_readl(uint32_t addr, void *priv)
{
@@ -151,7 +154,7 @@ rom_readl(uint32_t addr, void *priv)
int
rom_load_linear(wchar_t *fn, uint32_t addr, int sz, int off, uint8_t *ptr)
{
FILE *f = rom_fopen(fn, L"rb");
FILE *f = rom_fopen(fn);
if (f == NULL) {
pclog("ROM: image '%ls' not found\n", fn);
@@ -160,13 +163,9 @@ rom_load_linear(wchar_t *fn, uint32_t addr, int sz, int off, uint8_t *ptr)
/* Make sure we only look at the base-256K offset. */
if (addr >= 0x40000)
{
addr = 0;
}
else
{
else
addr &= 0x03ffff;
}
(void)fseek(f, off, SEEK_SET);
(void)fread(ptr+addr, sz, 1, f);
@@ -180,8 +179,8 @@ rom_load_linear(wchar_t *fn, uint32_t addr, int sz, int off, uint8_t *ptr)
int
rom_load_interleaved(wchar_t *fnl, wchar_t *fnh, uint32_t addr, int sz, int off, uint8_t *ptr)
{
FILE *fl = rom_fopen(fnl, L"rb");
FILE *fh = rom_fopen(fnh, L"rb");
FILE *fl = rom_fopen(fnl);
FILE *fh = rom_fopen(fnh);
int c;
if (fl == NULL || fh == NULL) {
@@ -212,6 +211,7 @@ rom_load_interleaved(wchar_t *fnl, wchar_t *fnh, uint32_t addr, int sz, int off,
}
/* Read and initialize an option ROM. */
int
rom_init(rom_t *rom, wchar_t *fn, uint32_t addr, int sz, int mask, int off, uint32_t flags)
{
@@ -264,590 +264,3 @@ rom_init_interleaved(rom_t *rom, wchar_t *fnl, wchar_t *fnh, uint32_t addr, int
return(0);
}
/* Load the ROM BIOS image(s) for the selected machine into memory. */
int
rom_load_bios(int rom_id)
{
FILE *f;
/* If not done yet, allocate a 128KB buffer for the BIOS ROM. */
if (rom == NULL)
rom = (uint8_t *)malloc(131072);
memset(rom, 0xff, 131072);
/* Default to a 64K ROM BIOS image. */
biosmask = 0xffff;
/* Zap the BIOS ROM EXTENSION area. */
memset(romext, 0xff, 0x8000);
mem_mapping_disable(&romext_mapping);
switch (rom_id) {
case ROM_IBMPC: /* IBM PC */
if (! rom_load_linear(
L"roms/machines/ibm/ibmpc/pc102782.bin",
0x00e000, 8192, 0, rom)) break;
/* Try to load the (full) BASIC ROM. */
if (rom_load_linear(
L"roms/machines/ibm/ibmpc/ibm-basic-1.10.rom",
0x006000, 32768, 0, rom)) return(1);
/* Nope. Try to load the first BASIC ROM image. */
if (! rom_load_linear(
L"roms/machines/ibm/ibmpc/basicc11.f6",
0x006000, 8192, 0, rom)) return(1); /* nope */
if (! rom_load_linear(
L"roms/machines/ibm/ibmpc/basicc11.f8",
0x008000, 8192, 0, rom)) break; /* nope */
if (! rom_load_linear(
L"roms/machines/ibm/ibmpc/basicc11.fa",
0x00a000, 8192, 0, rom)) break; /* nope */
if (! rom_load_linear(
L"roms/machines/ibm/ibmpc/basicc11.fc",
0x00c000, 8192, 0, rom)) break; /* nope */
return(1);
case ROM_IBMXT: /* IBM PX-XT */
if (rom_load_linear(
L"roms/machines/ibm/ibmxt/xt.rom",
0x000000, 65536, 0, rom)) return(1);
if (! rom_load_linear(
L"roms/machines/ibm/ibmxt/5000027.u19",
0x000000, 32768, 0, rom)) break;
if (rom_load_linear(
L"roms/machines/ibm/ibmxt/1501512.u18",
0x008000, 32768, 0, rom)) return(1);
break;
case ROM_IBMXT286: /* IBM PX-XT 286 */
if (rom_load_interleaved(
L"roms/machines/ibm/ibmxt286/bios_5162_21apr86_u34_78x7460_27256.bin",
L"roms/machines/ibm/ibmxt286/bios_5162_21apr86_u35_78x7461_27256.bin",
0x000000, 65536, 0, rom)) return(1);
break;
case ROM_IBMPCJR: /* IBM PCjr */
if (rom_load_linear(
L"roms/machines/ibm/ibmpcjr/bios.rom",
0x000000, 65536, 0, rom)) return(1);
break;
case ROM_IBMAT: /* IBM PC-AT */
if (rom_load_interleaved(
L"roms/machines/ibm/ibmat/62x0820.u27",
L"roms/machines/ibm/ibmat/62x0821.u47",
0x000000, 65536, 0, rom)) return(1);
break;
#ifdef WALTJE
case ROM_OPENAT: /* PC/AT clone with OpenBIOS */
if (rom_load_linear(
L"roms/machines/generic/open_at/bios.bin",
0x000000, 65536, 0, rom)) return(1);
break;
#endif
case ROM_GENXT: /* Generic PC-XT clone */
if (rom_load_linear(
L"roms/machines/generic/genxt/pcxt.rom",
0x00e000, 8192, 0, rom)) return(1);
break;
case ROM_PC1512: /* Amstrad PC-1512 */
if (! rom_load_interleaved(
L"roms/machines/amstrad/pc1512/40044v2.ic132",
L"roms/machines/amstrad/pc1512/40043v2.ic129",
0x00c000, 16384, 0, rom)) break;
f = rom_fopen(L"roms/machines/amstrad/pc1512/40078.ic127", L"rb");
if (f == NULL) break;
(void)fclose(f);
return(1);
case ROM_PC1640: /* Amstrad PC-1640 */
if (! rom_load_interleaved(
L"roms/machines/amstrad/pc1640/40044.v3",
L"roms/machines/amstrad/pc1640/40043.v3",
0x00c000, 16384, 0, rom)) break;
f = rom_fopen(L"roms/machines/amstrad/pc1640/40100", L"rb");
if (f == NULL) break;
(void)fclose(f);
return(1);
case ROM_PC200:
if (! rom_load_interleaved(
L"roms/machines/amstrad/pc200/pc20v2.1",
L"roms/machines/amstrad/pc200/pc20v2.0",
0x00c000, 16384, 0, rom)) break;
f = rom_fopen(L"roms/machines/amstrad/pc200/40109", L"rb");
if (f == NULL) break;
(void)fclose(f);
return(1);
case ROM_TANDY:
if (rom_load_linear(
L"roms/machines/tandy/tandy/tandy1t1.020",
0x000000, 65536, 0, rom)) return(1);
break;
case ROM_TANDY1000HX:
if (! rom_load_linear(
L"roms/machines/tandy/tandy1000hx/v020000.u12",
0x000000, 0x20000, 0, rom)) break;
biosmask = 0x1ffff;
return(1);
case ROM_TANDY1000SL2:
if (rom_load_interleaved(
L"roms/machines/tandy/tandy1000sl2/8079047.hu1",
L"roms/machines/tandy/tandy1000sl2/8079048.hu2",
0x000000, 65536, 0x30000/2, rom)) return(1);
break;
case ROM_PORTABLE:
if (rom_load_linear(
L"roms/machines/compaq/portable/compaq portable plus 100666-001 rev c u47.bin",
0x00e000, 8192, 0, rom)) return(1);
break;
case ROM_PORTABLEII:
if (! rom_load_interleaved(
L"roms/machines/compaq/portableii/109740-001.rom",
L"roms/machines/compaq/portableii/109739-001.rom",
0x008000, 32768, 0, rom)) break;
biosmask = 0x7fff;
return(1);
#if defined(DEV_BRANCH) && defined(USE_PORTABLE3)
case ROM_PORTABLEIII:
case ROM_PORTABLEIII386:
if (rom_load_interleaved(
L"roms/machines/compaq/portableiii/109738-002.bin",
L"roms/machines/compaq/portableiii/109737-002.bin",
0x000000, 65536, 0, rom)) return(1);
break;
#endif
case ROM_DTKXT:
if (rom_load_linear(
L"roms/machines/dtk/dtk/dtk_erso_2.42_2764.bin",
0x00e000, 8192, 0, rom)) return(1);
break;
case ROM_OLIM24:
if (rom_load_interleaved(
L"roms/machines/olivetti/olivetti_m24/olivetti_m24_version_1.43_low.bin",
L"roms/machines/olivetti/olivetti_m24/olivetti_m24_version_1.43_high.bin",
0x00c000, 16384, 0, rom)) return(1);
break;
case ROM_PC2086:
if (! rom_load_interleaved(
L"roms/machines/amstrad/pc2086/40179.ic129",
L"roms/machines/amstrad/pc2086/40180.ic132",
0x000000, 16384, 0, rom)) break;
f = rom_fopen(L"roms/machines/amstrad/pc2086/40186.ic171", L"rb");
if (f == NULL) break;
(void)fclose(f);
biosmask = 0x3fff;
return(1);
case ROM_PC3086:
if (! rom_load_linear(
L"roms/machines/amstrad/pc3086/fc00.bin",
0x000000, 16384, 0, rom)) break;
f = rom_fopen(L"roms/machines/amstrad/pc3086/c000.bin", L"rb");
if (f == NULL) break;
(void)fclose(f);
biosmask = 0x3fff;
return(1);
case ROM_CMDPC30:
if (! rom_load_interleaved(
L"roms/machines/commodore/cmdpc30/commodore pc 30 iii even.bin",
L"roms/machines/commodore/cmdpc30/commodore pc 30 iii odd.bin",
0x000000, 32768, 0, rom)) break;
biosmask = 0x7fff;
return(1);
case ROM_AMI386SX:
if (rom_load_linear(
L"roms/machines/generic/ami/ami386/ami386.bin",
0x000000, 65536, 0, rom)) return(1);
break;
case ROM_AMI386DX_OPTI495: /* uses the OPTi 82C495 chipset */
if (rom_load_linear(
L"roms/machines/generic/ami/ami386dx/opt495sx.ami",
0x000000, 65536, 0, rom)) return(1);
break;
case ROM_MR386DX_OPTI495: /* uses the OPTi 82C495 chipset */
if (rom_load_linear(
L"roms/machines/generic/microid/mr386dx/opt495sx.mr",
0x000000, 65536, 0, rom)) return(1);
break;
case ROM_AWARD386SX_OPTI495: /* uses the OPTi 82C495 chipset */
case ROM_AWARD386DX_OPTI495: /* uses the OPTi 82C495 chipset */
case ROM_AWARD486_OPTI495: /* uses the OPTi 82C495 chipset */
if (rom_load_linear(
L"roms/machines/generic/award/award495/opt495s.awa",
0x000000, 65536, 0, rom)) return(1);
break;
case ROM_AMI286:
if (rom_load_linear(
L"roms/machines/generic/ami/ami286/amic206.bin",
0x000000, 65536, 0, rom)) return(1);
break;
case ROM_AWARD286:
if (rom_load_linear(
L"roms/machines/generic/award/award286/award.bin",
0x000000, 65536, 0, rom)) return(1);
break;
case ROM_EUROPC:
if (rom_load_linear(
L"roms/machines/schneider/europc/50145",
0x008000, 32768, 0, rom)) return(1);
break;
case ROM_MEGAPC:
case ROM_MEGAPCDX:
if (rom_load_interleaved(
L"roms/machines/amstrad/megapc/41651-bios lo.u18",
L"roms/machines/amstrad/megapc/211253-bios hi.u19",
0x000000, 65536, 0x08000, rom)) return(1);
break;
case ROM_AMI486:
if (rom_load_linear(
L"roms/machines/generic/ami/ami486/ami486.bin",
0x000000, 65536, 0, rom)) return(1);
break;
case ROM_WIN486:
if (rom_load_linear(
L"roms/machines/generic/ami/win486/ali1429g.amw",
0x000000, 65536, 0, rom)) return(1);
break;
case ROM_430VX:
if (! rom_load_linear(
L"roms/machines/generic/award/430vx/55xwuq0e.bin",
0x000000, 131072, 0, rom)) break;
biosmask = 0x1ffff;
return(1);
case ROM_REVENGE:
if (! rom_load_linear(
L"roms/machines/intel/revenge/1009af2_.bio",
0x010000, 65536, 128, rom)) break;
if (! rom_load_linear(
L"roms/machines/intel/revenge/1009af2_.bi1",
0x000000, 0x00c000, 128, rom)) break;
biosmask = 0x1ffff;
return(1);
case ROM_ENDEAVOR:
if (! rom_load_linear(
L"roms/machines/intel/endeavor/1006cb0_.bio",
0x010000, 65536, 128, rom)) break;
if (! rom_load_linear(
L"roms/machines/intel/endeavor/1006cb0_.bi1",
0x000000, 0x00d000, 128, rom)) break;
biosmask = 0x1ffff;
return(1);
case ROM_IBMPS1_2011:
if (! rom_load_linear(
L"roms/machines/ibm/ibmps1es/f80000.bin",
0x000000, 131072, 0x60000, rom)) break;
biosmask = 0x1ffff;
return(1);
case ROM_IBMPS1_2121:
case ROM_IBMPS1_2121_ISA:
if (! rom_load_linear(
L"roms/machines/ibm/ibmps1_2121/fc0000.bin",
0x000000, 131072, 0x20000, rom)) break;
biosmask = 0x1ffff;
return(1);
case ROM_IBMPS1_2133:
if (! rom_load_linear(
L"roms/machines/ibm/ibmps1_2133/ps1_2133_52g2974_rom.bin",
0x000000, 131072, 0, rom)) break;
biosmask = 0x1ffff;
return(1);
#if defined(DEV_BRANCH) && defined(USE_PORTABLE3)
case ROM_DESKPRO_386:
if (! rom_load_interleaved(
L"roms/machines/compaq/deskpro386/109592-005.u11.bin",
L"roms/machines/compaq/deskpro386/109591-005.u13.bin",
0x000000, 32768, 0, rom)) break;
biosmask = 0x7fff;
return(1);
#endif
case ROM_AMIXT:
if (rom_load_linear(
L"roms/machines/generic/ami/amixt/ami_8088_bios_31jan89.bin",
0x00e000, 8192, 0, rom)) return(1);
break;
#if defined(DEV_BRANCH) && defined(USE_LASERXT)
case ROM_LTXT:
if (rom_load_linear(
L"roms/machines/vtech/ltxt/27c64.bin",
0x00e000, 8192, 0, rom)) return(1);
break;
case ROM_LXT3:
if (rom_load_linear(
L"roms/machines/vtech/lxt3/27c64d.bin",
0x00e000, 8192, 0, rom)) return(1);
break;
#endif
case ROM_SPC4200P: /* Samsung SPC-4200P */
if (rom_load_linear(
L"roms/machines/samsung/spc4200p/u8.01",
0x000000, 65536, 0, rom)) return(1);
break;
case ROM_SUPER286TR: /* Hyundai Super-286TR */
if (rom_load_linear(
L"roms/machines/hyundai/super286tr/hyundai_award286.bin",
0x000000, 65536, 0, rom)) return(1);
break;
case ROM_DTK386: /* uses NEAT chipset */
if (rom_load_linear(
L"roms/machines/dtk/dtk386/3cto001.bin",
0x000000, 65536, 0, rom)) return(1);
break;
case ROM_PXXT:
if (rom_load_linear(
L"roms/machines/generic/phoenix/pxxt/000p001.bin",
0x00e000, 8192, 0, rom)) return(1);
break;
case ROM_JUKOPC:
if (rom_load_linear(
L"roms/machines/juko/jukopc/000o001.bin",
0x00e000, 8192, 0, rom)) return(1);
break;
case ROM_IBMPS2_M30_286:
if (! rom_load_linear(
L"roms/machines/ibm/ibmps2_m30_286/33f5381a.bin",
0x000000, 131072, 0, rom)) break;
biosmask = 0x1ffff;
return(1);
case ROM_DTK486:
if (rom_load_linear(
L"roms/machines/dtk/dtk486/4siw005.bin",
0x000000, 65536, 0, rom)) return(1);
break;
case ROM_R418:
if (! rom_load_linear(
L"roms/machines/rise/r418/r418i.bin",
0x000000, 131072, 0, rom)) break;
biosmask = 0x1ffff;
return(1);
#if 0
case ROM_586MC1:
/* FIXME: no ROM? --FvK */
if (! rom_load_linear(
L"roms/machines/586mc1/is.34",
0x000000, 131072, 0, rom)) break;
biosmask = 0x1ffff;
return(1);
#endif
case ROM_PLATO:
if (! rom_load_linear(
L"roms/machines/intel/plato/1016ax1_.bio",
0x010000, 65536, 128, rom)) break;
if (! rom_load_linear(
L"roms/machines/intel/plato/1016ax1_.bi1",
0x000000, 0x00d000, 128, rom)) break;
biosmask = 0x1ffff;
return(1);
case ROM_MB500N:
if (! rom_load_linear(
L"roms/machines/pcpartner/mb500n/031396s.bin",
0x000000, 131072, 0, rom)) break;
biosmask = 0x1ffff;
return(1);
case ROM_AP53:
if (! rom_load_linear(
L"roms/machines/aopen/ap53/ap53r2c0.rom",
0x000000, 131072, 0, rom)) break;
biosmask = 0x1ffff;
return(1);
case ROM_P55T2S:
if (! rom_load_linear(
L"roms/machines/supermicro/p55t2s/s6y08t.rom",
0x000000, 131072, 0, rom)) break;
biosmask = 0x1ffff;
return(1);
case ROM_PRESIDENT:
if (! rom_load_linear(
L"roms/machines/president/president/bios.bin",
0x000000, 131072, 0, rom)) break;
biosmask = 0x1ffff;
return(1);
case ROM_P54TP4XE:
if (! rom_load_linear(
L"roms/machines/asus/p54tp4xe/t15i0302.awd",
0x000000, 131072, 0, rom)) break;
biosmask = 0x1ffff;
return(1);
case ROM_ACERM3A:
if (! rom_load_linear(
L"roms/machines/acer/acerm3a/r01-b3.bin",
0x000000, 131072, 0, rom)) break;
biosmask = 0x1ffff;
return(1);
case ROM_ACERV35N:
if (! rom_load_linear(
L"roms/machines/acer/acerv35n/v35nd1s1.bin",
0x000000, 131072, 0, rom)) break;
biosmask = 0x1ffff;
return(1);
case ROM_P55VA:
if (! rom_load_linear(
L"roms/machines/epox/p55va/va021297.bin",
0x000000, 131072, 0, rom)) break;
biosmask = 0x1ffff;
return(1);
case ROM_P55T2P4:
if (! rom_load_linear(
L"roms/machines/asus/p55t2p4/0207_j2.bin",
0x000000, 131072, 0, rom)) break;
biosmask = 0x1ffff;
return(1);
case ROM_P55TVP4:
if (! rom_load_linear(
L"roms/machines/asus/p55tvp4/tv5i0204.awd",
0x000000, 131072, 0, rom)) break;
biosmask = 0x1ffff;
return(1);
#if defined(DEV_BRANCH) && defined(USE_I686)
case ROM_440FX: /* working Tyan BIOS */
if (! rom_load_linear(
L"roms/machines/tyan/440fx/ntmaw501.bin",
0x000000, 131072, 0, rom)) break;
biosmask = 0x1ffff;
return(1);
case ROM_S1668: /* working Tyan BIOS */
if (! rom_load_linear(
L"roms/machines/tyan/tpatx/s1668p.rom",
0x000000, 131072, 0, rom)) break;
biosmask = 0x1ffff;
return(1);
#endif
case ROM_THOR:
if (! rom_load_linear(
L"roms/machines/intel/thor/1006cn0_.bio",
0x010000, 65536, 128, rom)) break;
if (! rom_load_linear(
L"roms/machines/intel/thor/1006cn0_.bi1",
0x000000, 65536, 128, rom)) break;
biosmask = 0x1ffff;
return(1);
case ROM_MRTHOR:
if (! rom_load_linear(
L"roms/machines/intel/mrthor/mr_atx.bio",
0x000000, 131072, 0, rom)) break;
biosmask = 0x1ffff;
return(1);
case ROM_ZAPPA:
if (! rom_load_linear(
L"roms/machines/intel/zappa/1006bs0_.bio",
0x010000, 65536, 128, rom)) break;
if (! rom_load_linear(
L"roms/machines/intel/zappa/1006bs0_.bi1",
0x000000, 65536, 128, rom)) break;
biosmask = 0x1ffff;
return(1);
case ROM_IBMPS2_M50:
if (! rom_load_interleaved(
L"roms/machines/ibm/ibmps2_m50/90x7423.zm14",
L"roms/machines/ibm/ibmps2_m50/90x7426.zm16",
0x000000, 65536, 0, rom)) break;
if (! rom_load_interleaved(
L"roms/machines/ibm/ibmps2_m50/90x7420.zm13",
L"roms/machines/ibm/ibmps2_m50/90x7429.zm18",
0x010000, 65536, 0, rom)) break;
biosmask = 0x1ffff;
return(1);
case ROM_IBMPS2_M55SX:
if (! rom_load_interleaved(
L"roms/machines/ibm/ibmps2_m55sx/33f8146.zm41",
L"roms/machines/ibm/ibmps2_m55sx/33f8145.zm40",
0x000000, 131072, 0, rom)) break;
biosmask = 0x1ffff;
return(1);
case ROM_IBMPS2_M80:
#ifdef WALTJE
case ROM_IBMPS2_M80_486:
#endif
if (! rom_load_interleaved(
L"roms/machines/ibm/ibmps2_m80/15f6637.bin",
L"roms/machines/ibm/ibmps2_m80/15f6639.bin",
0x000000, 131072, 0, rom)) break;
biosmask = 0x1ffff;
return(1);
#if defined(DEV_BRANCH) && defined(USE_GREENB)
case ROM_4GPV31:
if (! rom_load_linear(
L"roms/machines/addtech/green-b/4gpv31-ami-1993-8273517.bin",
0x000000, 65536, 0, rom)) break;
return(1);
#endif
case ROM_T3100E:
loadfont(L"roms/machines/toshiba/t3100e/t3100e_font.bin", 5);
if (rom_load_linear(
L"roms/machines/toshiba/t3100e/t3100e.rom",
0x000000, 65536, 0, rom)) return(1);
break;
default:
pclog("ROM: don't know how to handle ROM set %d !\n", rom_id);
}
return(0);
}