From 7bd90170dc6db6703316056290d40a353df56c69 Mon Sep 17 00:00:00 2001 From: beeanyew Date: Fri, 4 Dec 2020 18:35:56 +0100 Subject: [PATCH] Add support for ROM mirroring Confirmed to be working this way on a real Amiga, removes the need for separate ROM image maps in the config file for 256/512KB ROM images. --- config_file/config_file.c | 3 ++- config_file/config_file.h | 1 + default.cfg | 6 ++---- memory_mapped.c | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/config_file/config_file.c b/config_file/config_file.c index b7eff98..31e06b4 100644 --- a/config_file/config_file.c +++ b/config_file/config_file.c @@ -212,12 +212,13 @@ void add_mapping(struct emulator_config *cfg, unsigned int type, unsigned int ad } fseek(in, 0, SEEK_SET); cfg->map_data[index] = (unsigned char *)calloc(1, cfg->map_size[index]); + cfg->rom_size[index] = (cfg->map_size[index] <= file_size) ? cfg->map_size[index] : file_size; if (!cfg->map_data[index]) { printf("ERROR: Unable to allocate memory for mapped ROM!\n"); goto mapping_failed; } memset(cfg->map_data[index], 0x00, cfg->map_size[index]); - fread(cfg->map_data[index], (cfg->map_size[index] <= file_size) ? cfg->map_size[index] : file_size, 1, in); + fread(cfg->map_data[index], cfg->rom_size[index], 1, in); fclose(in); break; case MAPTYPE_REGISTER: diff --git a/config_file/config_file.h b/config_file/config_file.h index 6c56a68..272e910 100644 --- a/config_file/config_file.h +++ b/config_file/config_file.h @@ -49,6 +49,7 @@ struct emulator_config { unsigned char map_type[MAX_NUM_MAPPED_ITEMS]; long map_offset[MAX_NUM_MAPPED_ITEMS]; unsigned int map_size[MAX_NUM_MAPPED_ITEMS]; + unsigned int rom_size[MAX_NUM_MAPPED_ITEMS]; unsigned char *map_data[MAX_NUM_MAPPED_ITEMS]; int map_mirror[MAX_NUM_MAPPED_ITEMS]; char *map_id[MAX_NUM_MAPPED_ITEMS]; diff --git a/default.cfg b/default.cfg index fd8a3fc..f92897b 100644 --- a/default.cfg +++ b/default.cfg @@ -1,11 +1,9 @@ # Sets CPU type. Valid types are (probably) 68000, 68010, 68020, 68EC020, 68030, 68EC030, 68040, 68EC040, 68LC040 and some STTTT thing. cpu 68020 # Map 512KB kickstart ROM to default offset. -map type=rom address=0xF80000 size=0x80000 file=kick512.rom ovl=0 -# This is for mapping a 256KB kickstart ROM. I can probably add some additional thing about kicking this file into low/high area. -#map type=rom address=0xFC0000 size=0x40000 file=kick256.rom ovl=0 +map type=rom address=0xF80000 size=0x80000 file=kick.rom ovl=0 # Want to map an extended ROM, such as CDTV or CD32? -#map type=rom address=0xF00000 size=0x90000 file=cdtv.rom +#map type=rom address=0xF00000 size=0x80000 file=cdtv.rom # Map 256MB of Fast RAM at 0x8000000. map type=ram address=0x08000000 size=128M # Map Gayle as a register range. diff --git a/memory_mapped.c b/memory_mapped.c index c5a99e7..b77a8d2 100644 --- a/memory_mapped.c +++ b/memory_mapped.c @@ -27,9 +27,9 @@ int handle_mapped_read(struct emulator_config *cfg, unsigned int addr, unsigned switch(cfg->map_type[i]) { case MAPTYPE_ROM: if (CHKRANGE(addr, cfg->map_offset[i], cfg->map_size[i])) - read_addr = cfg->map_data[i] + (addr - cfg->map_offset[i]); + read_addr = cfg->map_data[i] + ((addr - cfg->map_offset[i]) % cfg->rom_size[i]); else if (cfg->map_mirror[i] != -1 && mirror && CHKRANGE(addr, cfg->map_mirror[i], cfg->map_size[i])) - read_addr = cfg->map_data[i] + (addr - cfg->map_mirror[i]); + read_addr = cfg->map_data[i] + ((addr - cfg->map_mirror[i]) % cfg->rom_size[i]); break; case MAPTYPE_RAM: if (CHKRANGE(addr, cfg->map_offset[i], cfg->map_size[i])) -- 2.39.2