From: Toni Wilen Date: Sun, 5 Apr 2015 13:12:24 +0000 (+0300) Subject: ROM loader cleanup. X-Git-Tag: 3100~54 X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=b9172220e31244aab72f394799d6cfb3aba228e3;p=francis%2Fwinuae.git ROM loader cleanup. --- diff --git a/idecontrollers.cpp b/idecontrollers.cpp index 7d991e57..cc6db4df 100644 --- a/idecontrollers.cpp +++ b/idecontrollers.cpp @@ -1002,14 +1002,11 @@ addrbank *gvp_ide_rom_autoconfig_init(struct romconfig *rc) ide->rom = xcalloc(uae_u8, ide->rom_size); memset(ide->rom, 0xff, ide->rom_size); ide->rom_mask = ide->rom_size - 1; - struct zfile *z = read_device_from_romconfig(rc, roms); - if (z) { - for (int i = 0; i < 16; i++) { - uae_u8 b = autoconfig[i]; - ew(ide, i * 4, b); - } - int size = zfile_fread(ide->rom, 1, ide->rom_size, z); - zfile_fclose(z); + + load_rom_rc(rc, roms, ide->rom_size, 0, ide->rom, ide->rom_size, LOADROM_FILL); + for (int i = 0; i < 16; i++) { + uae_u8 b = autoconfig[i]; + ew(ide, i * 4, b); } return ide->bank; } @@ -1197,22 +1194,14 @@ addrbank *masoboshi_init(struct romconfig *rc) memset(ide->rom, 0xff, ide->rom_size); memset(ide->acmemory, 0xff, sizeof ide->acmemory); ide->rom_mask = ide->rom_size - 1; - struct zfile *z = read_device_from_romconfig(rc, roms); - if (z) { - int len = zfile_size(z); - for (int i = 0; i < 32768; i++) { - uae_u8 b; - zfile_fread(&b, 1, 1, z); - ide->rom[i * 2 + 0] = b; - ide->rom[i * 2 + 1] = 0xff; - } - zfile_fclose(z); - ide->subtype = rc->subtype; - if (rc && rc->autoboot_disabled) - memcpy(ide->acmemory, ide->rom + 0x100, sizeof ide->acmemory); - else - memcpy(ide->acmemory, ide->rom + 0x000, sizeof ide->acmemory); - } + + load_rom_rc(rc, roms, 32768, 0, ide->rom, 65536, LOADROM_EVENONLY_ODDONE | LOADROM_FILL); + ide->subtype = rc->subtype; + if (rc && rc->autoboot_disabled) + memcpy(ide->acmemory, ide->rom + 0x100, sizeof ide->acmemory); + else + memcpy(ide->acmemory, ide->rom + 0x000, sizeof ide->acmemory); + // init SCSI part ncr_masoboshi_autoconfig_init(rc); return ide->bank; @@ -1257,16 +1246,7 @@ addrbank *adide_init(struct romconfig *rc) memset(ide->rom, 0xff, ide->rom_size); ide->rom_mask = ide->rom_size - 1; if (!rc->autoboot_disabled) { - struct zfile *z = read_device_from_romconfig(rc, roms); - if (z) { - for (int i = 0; i < 16384; i++) { - uae_u8 b; - zfile_fread(&b, 1, 1, z); - ide->rom[i * 2 + 0] = b; - ide->rom[i * 2 + 1] = 0xff; - } - zfile_fclose(z); - } + load_rom_rc(rc, roms, 16384, 0, ide->rom, 32768, LOADROM_EVENONLY_ODDONE | LOADROM_FILL); } for (int i = 0; i < 16; i++) { uae_u8 b = adide_autoconfig[i]; @@ -1297,19 +1277,8 @@ addrbank *mtec_init(struct romconfig *rc) ide->rom = xcalloc(uae_u8, ide->rom_size); memset(ide->rom, 0xff, ide->rom_size); ide->rom_mask = ide->rom_size - 1; - struct zfile *z = read_device_from_romconfig(rc, roms); - if (z) { - if (!rc->autoboot_disabled) - zfile_fseek(z, 16384, SEEK_SET); - for (int i = 0; i < 16384; i++) { - uae_u8 b; - zfile_fread(&b, 1, 1, z); - ide->rom[i * 2 + 0] = b; - ide->rom[i * 2 + 1] = 0xff; - } - zfile_fclose(z); - memcpy(ide->acmemory, ide->rom, sizeof ide->acmemory); - } + load_rom_rc(rc, roms, 16384, !rc->autoboot_disabled ? 16384 : 0, ide->rom, 32768, LOADROM_EVENONLY_ODDONE | LOADROM_FILL); + memcpy(ide->acmemory, ide->rom, sizeof ide->acmemory); return ide->bank; } diff --git a/include/rommgr.h b/include/rommgr.h index 8ec7909d..68871a48 100644 --- a/include/rommgr.h +++ b/include/rommgr.h @@ -32,6 +32,7 @@ extern int decode_cloanto_rom_do (uae_u8 *mem, int size, int real_size); #define ROMTYPE_CB_CSPPC 0x0004000e #define ROMTYPE_CB_BLIZPPC 0x0004000f #define ROMTYPE_CB_GOLEM030 0x00040010 +#define ROMTYPE_CB_ACA500 0x00040011 #define ROMTYPE_FREEZER 0x00080000 #define ROMTYPE_AR 0x00080001 @@ -132,7 +133,7 @@ extern TCHAR *romlist_get (const struct romdata *rd); extern void romlist_clear (void); extern struct zfile *read_rom (struct romdata *rd); extern struct zfile *read_rom_name (const TCHAR *filename); -extern struct zfile *read_device_from_romconfig(struct romconfig *rc, int *roms); +extern struct zfile *read_device_from_romconfig(struct romconfig *rc, const int *roms); extern int load_keyring (struct uae_prefs *p, const TCHAR *path); extern uae_u8 *target_load_keyfile (struct uae_prefs *p, const TCHAR *path, int *size, TCHAR *name); @@ -159,3 +160,11 @@ const struct expansionromtype *get_unit_expansion_rom(int hdunit); struct boardromconfig *get_device_rom_new(struct uae_prefs *p, int romtype, int devnum, int *index); void clear_device_rom(struct uae_prefs *p, int romtype, int devnum); struct boardromconfig *get_boardromconfig(struct uae_prefs *p, int romtype, int *index); + +#define LOADROM_FILL 1 +#define LOADROM_EVENONLY 2 +#define LOADROM_EVENONLY_ODDONE ((255 << 16) | LOADROM_EVENONLY) +#define LOADROM_ONEFILL 4 +#define LOADROM_ZEROFILL 8 +#define LOADROM_ODDFILL(x) ((x << 16) | LOADROM_EVENONLY) +bool load_rom_rc(struct romconfig *rc, const int *roms, int maxfilesize, int fileoffset, uae_u8 *rom, int maxromsize, int flags); \ No newline at end of file diff --git a/rommgr.cpp b/rommgr.cpp index 1664ab13..79971966 100644 --- a/rommgr.cpp +++ b/rommgr.cpp @@ -95,7 +95,7 @@ struct romdata *getromdatabypath (const TCHAR *path) return NULL; } -#define NEXT_ROM_ID 137 +#define NEXT_ROM_ID 138 static struct romheader romheaders[] = { { _T("Freezer Cartridges"), 1 }, @@ -420,6 +420,8 @@ static struct romdata roms[] = { 0, 0, 0, 0, 0, 0, NULL, _T("blizzardppc_040.rom") }, { _T("Blizzard PPC 68060"), 0, 0, 0, 0, _T("BPPC\0"), 524288, 100, 0, 0, ROMTYPE_CB_BLIZPPC, 0, 0, NULL, 0, 0, 0, 0, 0, 0, NULL, _T("blizzardppc_060.rom") }, + { _T("ACA 500"), 0, 0, 0, 0, _T("ACA500\0"), 524288, 137, 0, 0, ROMTYPE_CB_ACA500, 0, 0, NULL, + 0, 0, 0, 0, 0, 0, NULL, _T("menu500.aca") }, { _T("Picasso IV"), 7, 4, 7, 4, _T("PIV\0"), 131072, 91, 0, 0, ROMTYPE_PIV, 0, 0, NULL, 0xa8133e7e, 0xcafafb91,0x6f16b9f3,0xec9b49aa,0x4b40eb4e,0xeceb5b5b }, @@ -1714,7 +1716,7 @@ struct romconfig *get_device_romconfig(struct uae_prefs *p, int romtype, int dev return NULL; } -struct zfile *read_device_from_romconfig(struct romconfig *rc, int *roms) +struct zfile *read_device_from_romconfig(struct romconfig *rc, const int *roms) { if (!_tcsicmp(rc->romfile, _T(":NOROM"))) return NULL; @@ -1783,4 +1785,57 @@ struct boardromconfig *get_boardromconfig(struct uae_prefs *p, int romtype, int } } return NULL; +} + +bool load_rom_rc(struct romconfig *rc, const int *roms, int maxfilesize, int fileoffset, uae_u8 *rom, int maxromsize, int flags) +{ + if (flags & LOADROM_ONEFILL) + memset(rom, 0xff, maxromsize); + if (flags & LOADROM_ZEROFILL) + memset(rom, 0x00, maxromsize); + struct zfile *f = read_device_from_romconfig(rc, roms); + if (!f) + return false; + zfile_fseek(f, fileoffset, SEEK_SET); + int cnt = 0; + int pos = 0; + bool eof = false; + while (cnt < maxromsize && cnt < maxfilesize && pos < maxromsize) { + uae_u8 b = 0xff; + if (!eof) { + if (!zfile_fread(&b, 1, 1, f)) + eof = true; + } + if (eof) { + int bitcnt = 0; + for (int i = 1; i < maxromsize; i <<= 1) { + if (cnt & i) + bitcnt++; + } + if (bitcnt == 1) + break; + } + + rom[pos] = b; + if (flags & LOADROM_EVENONLY) { + rom[pos + 1] = (flags >> 16) & 0xff; + pos += 2; + } else { + pos += 1; + } + cnt++; + } + zfile_fclose(f); + int posend = pos; + if (!(flags & LOADROM_FILL)) + return true; + int oldpos = 0; + while (pos < maxromsize) { + rom[pos] = rom[oldpos]; + oldpos++; + pos++; + if (oldpos >= posend) + oldpos = 0; + } + return true; } \ No newline at end of file diff --git a/scsi.cpp b/scsi.cpp index 38fb5327..326adaea 100644 --- a/scsi.cpp +++ b/scsi.cpp @@ -1999,29 +1999,11 @@ addrbank *supra_init(struct romconfig *rc) struct zfile *z = NULL; scsi->subtype = rc->subtype; if (!rc->autoboot_disabled && scsi->subtype != 3) { - struct zfile *z = read_device_from_romconfig(rc, roms); for (int i = 0; i < 16; i++) { uae_u8 b = ert->subtypes[rc->subtype].autoconfig[i]; ew(scsi, i * 4, b); } - if (z) { - int i; - for (i = 0; i < 16384; i++) { - uae_u8 b; - if (!zfile_fread(&b, 1, 1, z)) - break; - scsi->rom[i * 2 + 0] = b; - } - if (i < 16384) { - int ii = 0; - while (i < 16384) { - scsi->rom[i * 2 + 0] = scsi->rom[ii * 2 + 0]; - i++; - ii++; - } - } - zfile_fclose(z); - } + load_rom_rc(rc, roms, 16384, 0, scsi->rom, 32768, LOADROM_EVENONLY_ODDONE | LOADROM_FILL); } return scsi->bank; } @@ -2044,22 +2026,9 @@ addrbank *golem_init(struct romconfig *rc) scsi->intena = true; - struct zfile *z = NULL; - if (!rc->autoboot_disabled) { - struct zfile *z = read_device_from_romconfig(rc, roms); - if (z) { - if (rc->autoboot_disabled) - zfile_fseek(z, 8192, SEEK_SET); - for (int i = 0; i < 8192; i++) { - uae_u8 b; - zfile_fread(&b, 1, 1, z); - if (i < sizeof scsi->acmemory) - scsi->acmemory[i] = b; - scsi->rom[i] = b; - } - zfile_fclose(z); - } - } + load_rom_rc(rc, roms, 8192, rc->autoboot_disabled ? 8192 : 0, scsi->rom, 8192, 0); + memcpy(scsi->acmemory, scsi->rom, sizeof scsi->acmemory); + return scsi->bank; } @@ -2102,11 +2071,8 @@ addrbank *kommos_init(struct romconfig *rc) roms[0] = 127; roms[1] = -1; - struct zfile *z = read_device_from_romconfig(rc, roms); - if (z) { - zfile_fread(scsi->rom, 1, 32768, z); - zfile_fclose(z); - } + + load_rom_rc(rc, roms, 32768, 0, scsi->rom, 32768, 0); map_banks(scsi->bank, 0xf10000 >> 16, 1, 0); map_banks(scsi->bank, 0xeb0000 >> 16, 1, 0); @@ -2136,17 +2102,8 @@ addrbank *vector_init(struct romconfig *rc) struct zfile *z = NULL; if (!rc->autoboot_disabled) { - struct zfile *z = read_device_from_romconfig(rc, roms); - if (z) { - for (int i = 0; i < 32768; i++) { - uae_u8 b; - zfile_fread(&b, 1, 1, z); - if (i < sizeof scsi->acmemory) - scsi->acmemory[i] = b; - scsi->rom[i] = b; - } - zfile_fclose(z); - } + load_rom_rc(rc, roms, 32768, 0, scsi->rom, 32768, 0); + memcpy(scsi->acmemory, scsi->rom, sizeof scsi->acmemory); } return scsi->bank; } @@ -2168,16 +2125,8 @@ addrbank *protar_init(struct romconfig *rc) roms[0] = 131; roms[1] = -1; - struct zfile *z = read_device_from_romconfig(rc, roms); - if (z) { - for (int i = 0; i < 32768; i++) { - uae_u8 b; - zfile_fread(&b, 1, 1, z); - scsi->rom[i * 2] = b; - } - zfile_fclose(z); - memcpy(scsi->acmemory, scsi->rom + 0x200 * 2, sizeof scsi->acmemory); - } + load_rom_rc(rc, roms, 32768, 0, scsi->rom, 32768, LOADROM_EVENONLY_ODDONE); + memcpy(scsi->acmemory, scsi->rom + 0x200 * 2, sizeof scsi->acmemory); return scsi->bank; } @@ -2199,16 +2148,8 @@ addrbank *add500_init(struct romconfig *rc) scsi->rscsi.use_ack = true; - struct zfile *z = read_device_from_romconfig(rc, roms); - if (z) { - for (int i = 0; i < 16384; i++) { - uae_u8 b; - zfile_fread(&b, 1, 1, z); - scsi->rom[i * 2] = b; - } - zfile_fclose(z); - memcpy(scsi->acmemory, scsi->rom, sizeof scsi->acmemory); - } + load_rom_rc(rc, roms, 16384, 0, scsi->rom, 32768, LOADROM_EVENONLY_ODDONE | LOADROM_FILL); + memcpy(scsi->acmemory, scsi->rom, sizeof scsi->acmemory); return scsi->bank; } @@ -2230,15 +2171,7 @@ addrbank *kronos_init(struct romconfig *rc) scsi->databuffer_size = 1024; scsi->databufferptr = xcalloc(uae_u8, scsi->databuffer_size); - struct zfile *z = read_device_from_romconfig(rc, roms); - if (z) { - for (int i = 0; i < 4096; i++) { - uae_u8 b; - zfile_fread(&b, 1, 1, z); - scsi->rom[i * 2] = b; - } - zfile_fclose(z); - } + load_rom_rc(rc, roms, 4096, 0, scsi->rom, 32768, LOADROM_EVENONLY_ODDONE | LOADROM_FILL); return scsi->bank; } @@ -2258,16 +2191,8 @@ addrbank *adscsi_init(struct romconfig *rc) roms[0] = 132; roms[1] = -1; - struct zfile *z = read_device_from_romconfig(rc, roms); - if (z) { - for (int i = 0; i < 32768; i++) { - uae_u8 b; - zfile_fread(&b, 1, 1, z); - scsi->rom[i * 2] = b; - } - zfile_fclose(z); - memcpy(scsi->acmemory, scsi->rom, sizeof scsi->acmemory); - } + load_rom_rc(rc, roms, 32768, 0, scsi->rom, 65536, LOADROM_EVENONLY_ODDONE | LOADROM_FILL); + memcpy(scsi->acmemory, scsi->rom, sizeof scsi->acmemory); return scsi->bank; }