platforms/amiga/piscsi/piscsi.c \
platforms/amiga/pistorm-dev/pistorm-dev.c \
platforms/amiga/net/pi-net.c \
- platforms/shared/rtc.c
+ platforms/shared/rtc.c \
+ platforms/shared/common.c
MUSASHIFILES = m68kcpu.c m68kdasm.c softfloat/softfloat.c softfloat/softfloat_fpsp.c
MUSASHIGENCFILES = m68kops.c
"file",
"ovl",
"id",
+ "autodump_file",
+ "autodump_mem",
};
int get_config_item_type(char *cmd) {
}
}
-void add_mapping(struct emulator_config *cfg, unsigned int type, unsigned int addr, unsigned int size, int mirr_addr, char *filename, char *map_id) {
+void add_mapping(struct emulator_config *cfg, unsigned int type, unsigned int addr, unsigned int size, int mirr_addr, char *filename, char *map_id, unsigned int autodump) {
unsigned int index = 0, file_size = 0;
FILE *in = NULL;
case MAPTYPE_ROM:
in = fopen(filename, "rb");
if (!in) {
- printf("[CFG] Failed to open file %s for ROM mapping. Using onboard ROM instead, if available.\n", filename);
- goto mapping_failed;
+ if (!autodump) {
+ printf("[CFG] Failed to open file %s for ROM mapping. Using onboard ROM instead, if available.\n", filename);
+ goto mapping_failed;
+ } else if (autodump == MAPCMD_AUTODUMP_FILE) {
+ printf("[CFG] Could not open file %s for ROM mapping. Autodump flag is set, dumping to file.\n", filename);
+ dump_range_to_file(cfg->map_offset[index], cfg->map_size[index], filename);
+ in = fopen(filename, "rb");
+ if (in == NULL) {
+ printf("[CFG] Could not open dumped file for reading. Using onboard ROM instead, if available.\n");
+ goto mapping_failed;
+ }
+ } else if (autodump == MAPCMD_AUTODUMP_MEM) {
+ printf("[CFG] Could not open file %s for ROM mapping. Autodump flag is set, dumping to memory.\n", filename);
+ cfg->map_data[index] = dump_range_to_memory(cfg->map_offset[index], cfg->map_size[index]);
+ cfg->rom_size[index] = cfg->map_size[index];
+ if (cfg->map_data[index] == NULL) {
+ printf("[CFG] Could not dump range to memory. Using onboard ROM instead, if available.\n");
+ goto mapping_failed;
+ }
+ goto skip_file_ops;
+ }
}
fseek(in, 0, SEEK_END);
file_size = (int)ftell(in);
}
memset(cfg->map_data[index], 0x00, cfg->map_size[index]);
fread(cfg->map_data[index], cfg->rom_size[index], 1, in);
- fclose(in);
+ if (in)
+ fclose(in);
+skip_file_ops:
displayRomInfo(cfg->map_data[index], cfg->rom_size[index]);
if (cfg->map_size[index] == cfg->rom_size[index])
m68k_add_rom_range(cfg->map_offset[index], cfg->map_high[index], cfg->map_data[index]);
cfg->cpu_type = get_m68k_cpu_type(parse_line + str_pos);
break;
case CONFITEM_MAP: {
- unsigned int maptype = 0, mapsize = 0, mapaddr = 0;
+ unsigned int maptype = 0, mapsize = 0, mapaddr = 0, autodump = 0;
unsigned int mirraddr = ((unsigned int)-1);
char mapfile[128], mapid[128];
memset(mapfile, 0x00, 128);
get_next_string(parse_line, cur_cmd, &str_pos, ' ');
mirraddr = get_int(cur_cmd);
break;
+ case MAPCMD_AUTODUMP_FILE:
+ case MAPCMD_AUTODUMP_MEM:
+ autodump = get_map_cmd(cur_cmd);
+ break;
default:
printf("[CFG] Unknown/unhandled map argument %s on line %d.\n", cur_cmd, cur_line);
break;
}
}
- add_mapping(cfg, maptype, mapaddr, mapsize, mirraddr, mapfile, mapid);
+ add_mapping(cfg, maptype, mapaddr, mapsize, mirraddr, mapfile, mapid, autodump);
break;
}
MAPCMD_FILENAME,
MAPCMD_OVL_REMAP,
MAPCMD_MAP_ID,
+ MAPCMD_AUTODUMP_FILE,
+ MAPCMD_AUTODUMP_MEM,
MAPCMD_NUM,
} map_cmds;
int handle_mapped_write(struct emulator_config *cfg, unsigned int addr, unsigned int value, unsigned char type);
int get_named_mapped_item(struct emulator_config *cfg, char *name);
int get_mapped_item_by_address(struct emulator_config *cfg, uint32_t address);
-void add_mapping(struct emulator_config *cfg, unsigned int type, unsigned int addr, unsigned int size, int mirr_addr, char *filename, char *map_id);
+void add_mapping(struct emulator_config *cfg, unsigned int type, unsigned int addr, unsigned int size, int mirr_addr, char *filename, char *map_id, unsigned int autodump);
unsigned int get_int(char *str);
#endif
cpu 68020
# Map 512KB kickstart ROM to default offset.
map type=rom address=0xF80000 size=0x80000 file=kick.rom ovl=0 id=kickstart
+# Comment out the line above and uncomment the line below to automatically copy the ROM contents to Pi RAM if the file isn't found
+#map type=rom address=0xF80000 size=0x80000 file=kick.rom ovl=0 id=kickstart autodump_mem
+
# Want to map an extended ROM, such as CDTV or CD32?
#map type=rom address=0xF00000 size=0x80000 file=cdtv.rom id=extended
switch_config:
srand(clock());
+ ps_setup_protocol();
+ ps_reset_state_machine();
+ ps_pulse_reset();
+ usleep(1500);
+
if (load_new_config != 0) {
uint8_t config_action = load_new_config - 1;
load_new_config = 0;
InitGayle();
signal(SIGINT, sigint_handler);
- /*setup_io();
-
- //goto skip_everything;
-
- // Enable 200MHz CLK output on GPIO4, adjust divider and pll source depending
- // on pi model
- printf("Enable 200MHz GPCLK0 on GPIO4\n");
- gpio_enable_200mhz();
-
- // reset cpld statemachine first
-
- write_reg(0x01);
- usleep(100);
- usleep(1500);
- write_reg(0x00);
- usleep(100);
-
- // reset amiga and statemachine
- skip_everything:;
- usleep(1500);
-
- m68k_init();
- printf("Setting CPU type to %d.\n", cpu_type);
- m68k_set_cpu_type(cpu_type);
- cpu_pulse_reset();
-
- if (maprom == 1) {
- m68k_set_reg(M68K_REG_PC, 0xF80002);
- } else {
- m68k_set_reg(M68K_REG_PC, 0x0);
- }*/
- ps_setup_protocol();
ps_reset_state_machine();
ps_pulse_reset();
-
usleep(1500);
+
m68k_init();
printf("Setting CPU type to %d.\n", cpu_type);
m68k_set_cpu_type(cpu_type);
free(cfg->map_id[index]);
cfg->map_type[index] = MAPTYPE_NONE;
// Dirty hack, I am sleepy and lazy.
- add_mapping(cfg, MAPTYPE_ROM, cfg->map_offset[index], cfg->map_size[index], 0, tmp_string, "kickstart");
+ add_mapping(cfg, MAPTYPE_ROM, cfg->map_offset[index], cfg->map_size[index], 0, tmp_string, "kickstart", 0);
pi_cmd_result = PI_RES_OK;
do_reset = 1;
} else {
free(cfg->map_id[index]);
cfg->map_type[index] = MAPTYPE_NONE;
// Dirty hack, I am tired and lazy.
- add_mapping(cfg, MAPTYPE_ROM, cfg->map_offset[index], cfg->map_size[index], 0, tmp_string, "extended");
+ add_mapping(cfg, MAPTYPE_ROM, cfg->map_offset[index], cfg->map_size[index], 0, tmp_string, "extended", 0);
pi_cmd_result = PI_RES_OK;
do_reset = 1;
} else {
}
m68k_add_ram_range(PIGFX_RTG_BASE + PIGFX_REG_SIZE, 32 * SIZE_MEGA - PIGFX_REG_SIZE, rtg_mem);
- add_mapping(cfg_, MAPTYPE_RAM_NOALLOC, PIGFX_RTG_BASE + PIGFX_REG_SIZE, 40 * SIZE_MEGA - PIGFX_REG_SIZE, -1, (char *)rtg_mem, "rtg_mem");
+ add_mapping(cfg_, MAPTYPE_RAM_NOALLOC, PIGFX_RTG_BASE + PIGFX_REG_SIZE, 40 * SIZE_MEGA - PIGFX_REG_SIZE, -1, (char *)rtg_mem, "rtg_mem", 0);
return 1;
}
};
struct platform_config *make_platform_config(char *name, char *subsys);
+
+void dump_range_to_file(uint32_t addr, uint32_t size, char *filename);
+uint8_t *dump_range_to_memory(uint32_t addr, uint32_t size);
--- /dev/null
+// SPDX-License-Identifier: MIT
+
+#include <time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <endian.h>
+#include "platforms/platforms.h"
+#include "gpio/ps_protocol.h"
+
+void dump_range_to_file(uint32_t addr, uint32_t size, char *filename) {
+ FILE *out = fopen(filename, "wb+");
+ if (out == NULL) {
+ printf ("[SHARED-DUMP_RANGE_TO_FILE] Failed to open %s for writing.\n", filename);
+ printf ("[SHARED-DUMP_RANGE_TO_FILE] Memory range has not been dumped to file.\n");
+ return;
+ }
+
+ for (uint32_t i = 0; i < size; i += 2) {
+ uint16_t in = be16toh(read16(addr + i));
+ fwrite(&in, 2, 1, out);
+ }
+
+ fclose(out);
+ printf ("[SHARED-DUMP_RANGE_TO_FILE] Memory range dumped to file %s.\n", filename);
+}
+
+uint8_t *dump_range_to_memory(uint32_t addr, uint32_t size) {
+ uint8_t *mem = calloc(size, 1);
+
+ if (mem == NULL) {
+ printf ("[SHARED-DUMP_RANGE_TO_MEMORY] Failed to allocate memory for dumped range.\n");
+ return NULL;
+ }
+
+ for (uint32_t i = 0; i < size; i += 2) {
+ *(uint16_t *)&mem[i] = (uint16_t)be16toh(read16(addr + i));
+ }
+
+ printf ("[SHARED-DUMP_RANGE_TO_FILE] Memory range copied to RAM.\n");
+ return mem;
+}