diff --git a/src/memory.c b/src/memory.c index 5530b3f..a0a0c90 100644 --- a/src/memory.c +++ b/src/memory.c @@ -210,7 +210,7 @@ uint32_t load_rom(uint8_t* filename, uint32_t base_addr, uint8_t flags) { printf("reconfigure FPGA with %s...\n", romprops.fpga_conf); fpga_pgm((uint8_t*)romprops.fpga_conf); } - set_mcu_addr(base_addr); + set_mcu_addr(base_addr + romprops.load_address); file_open(filename, FA_READ); ff_sd_offload=1; sd_offload_tgt=0; diff --git a/src/smc.c b/src/smc.c index 7d3dee1..35e92b0 100644 --- a/src/smc.c +++ b/src/smc.c @@ -59,6 +59,7 @@ void smc_id(snes_romprops_t* props) { uint8_t score, maxscore=1, score_idx=2; /* assume LoROM */ snes_header_t* header = &(props->header); + props->load_address = 0; props->has_dspx = 0; props->has_st0010 = 0; props->has_cx4 = 0; @@ -95,6 +96,14 @@ void smc_id(snes_romprops_t* props) { props->expramsize_bytes = 0; props->mapper_id = 3; /* BS-X Memory Map */ props->region = 0; /* BS-X only existed in Japan */ + uint8_t alloc = header->name[0x10]; + if(alloc) { + while(!(alloc & 0x01)) { + props->load_address += 0x20000; + alloc >>= 1; + } + } + printf("load address: %lx\n", props->load_address); return; } } diff --git a/src/smc.h b/src/smc.h index a73843a..1276f47 100644 --- a/src/smc.h +++ b/src/smc.h @@ -84,6 +84,7 @@ typedef struct _snes_romprops { uint8_t has_cx4; /* CX4 presence flag */ uint8_t fpga_features; /* feature/peripheral enable bits*/ uint8_t region; /* game region (derived from destination code) */ + uint32_t load_address; /* where to load the ROM image */ snes_header_t header; /* original header from ROM image */ } snes_romprops_t;