EXENAME = emulator
-MAINFILES = emulator.c Gayle.c ide.c memory_mapped.c config_file/config_file.c registers/registers_amiga.c input/input.c
+MAINFILES = emulator.c \
+ Gayle.c \
+ ide.c \
+ memory_mapped.c \
+ config_file/config_file.c \
+ platforms/platforms.c \
+ platforms/amiga/amiga-autoconf.c \
+ platforms/amiga/amiga-platform.c \
+ platforms/amiga/amiga-registers.c \
+ platforms/dummy/dummy-platform.c \
+ platforms/dummy/dummy-registers.c
+
MUSASHIFILES = m68kcpu.c softfloat/softfloat.c
MUSASHIGENCFILES = m68kops.c
MUSASHIGENHFILES = m68kops.h
-#include "config_file.h"
+#include "../platforms/platforms.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
"loopcycles",
"mouse",
"keyboard",
+ "platform",
};
const char *mapcmd_names[MAPCMD_NUM] = {
break;
}
- printf("[MAP %d] Added %s mapping for range %.8lX-%.8lX (%lX)\n", index, map_type_names[type], cfg->map_offset[index], cfg->map_offset[index] + cfg->map_size[index] - 1, (uint64_t)cfg->map_data[index]);
+ printf("[MAP %d] Added %s mapping for range %.8lX-%.8lX ID: %s\n", index, map_type_names[type], cfg->map_offset[index], cfg->map_offset[index] + cfg->map_size[index] - 1, cfg->map_id[index] ? cfg->map_id[index] : "None");
return;
cfg->keyboard_toggle_key = cur_cmd[0];
printf("Enabled keyboard event forwarding, toggle key %c.\n", cfg->keyboard_toggle_key);
break;
+ case CONFITEM_PLATFORM: {
+ char platform_name[128], platform_sub[128];
+ memset(platform_name, 0x00, 128);
+ memset(platform_sub, 0x00, 128);
+ get_next_string(parse_line, platform_name, &str_pos, ' ');
+ printf("Setting platform to %s", platform_name);
+ get_next_string(parse_line, platform_sub, &str_pos, ' ');
+ if (strlen(platform_sub))
+ printf(" (sub: %s)", platform_sub);
+ printf("\n");
+ cfg->platform = make_platform_config(platform_name, platform_sub);
+ break;
+ }
case CONFITEM_NONE:
default:
printf("Unknown config item %s on line %d.\n", cur_cmd, cur_line);
return cfg;
}
+
+int get_named_mapped_item(struct emulator_config *cfg, char *name) {
+ if (strlen(name) == 0)
+ return -1;
+
+ for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) {
+ if (cfg->map_type[i] == MAPTYPE_NONE || !cfg->map_id[i])
+ continue;
+ if (strcmp(name, cfg->map_id[i]) == 0)
+ return i;
+ }
+
+ return -1;
+}
CONFITEM_LOOPCYCLES,
CONFITEM_MOUSE,
CONFITEM_KEYBOARD,
+ CONFITEM_PLATFORM,
CONFITEM_NUM,
} config_items;
int map_mirror[MAX_NUM_MAPPED_ITEMS];
char *map_id[MAX_NUM_MAPPED_ITEMS];
+ struct platform_config *platform;
+
char *mouse_file;
char mouse_toggle_key, keyboard_toggle_key;
unsigned int loop_cycles;
};
+struct platform_config {
+ char *subsys;
+
+ int (*custom_read)(struct emulator_config *cfg, unsigned int addr, unsigned int *val, unsigned char type);
+ int (*custom_write)(struct emulator_config *cfg, unsigned int addr, unsigned int val, unsigned char type);
+
+ int (*register_read)(unsigned int addr, unsigned char type, unsigned int *val);
+ int (*register_write)(unsigned int addr, unsigned int value, unsigned char type);
+
+ int (*platform_initial_setup)(struct emulator_config *cfg);
+ void (*setvar)(char *var, char *val);
+};
+
unsigned int get_m68k_cpu_type(char *name);
struct emulator_config *load_config_file(char *filename);
int handle_mapped_read(struct emulator_config *cfg, unsigned int addr, unsigned int *val, unsigned char type, unsigned char mirror);
int handle_mapped_write(struct emulator_config *cfg, unsigned int addr, unsigned int value, unsigned char type, unsigned char mirror);
-int handle_register_read(unsigned int addr, unsigned char type, unsigned int *val);
-int handle_register_write(unsigned int addr, unsigned int value, unsigned char type);
+int get_named_mapped_item(struct emulator_config *cfg, char *name);
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=0x80000 file=cdtv.rom
-# Map 256MB of Fast RAM at 0x8000000.
-map type=ram address=0x08000000 size=128M
+
+# Map 128MB of Fast RAM at 0x8000000.
+map type=ram address=0x08000000 size=128M id=cpu_slot_ram
+# 128MB of Z3 Fast at the first proper address
+#map type=ram address=0x10000000 size=128M id=z3_autoconf_fast
+# Max 8MB of Z2 Fast can be mapped due to addressing space limitations, but for instance 2+4MB can be chained to leave 2MB for something else.
+map type=ram address=0x200000 size=8M id=z2_autoconf_fast
+#map type=ram address=0x200000 size=2M id=z2_autoconf_fast
+#map type=ram address=0x400000 size=4M id=z2_autoconf_fast
+
+# This is fake Chip RAM, do not use on a real Amiga.
+#map type=ram address=0x0 size=2M
+
# Map Gayle as a register range.
map type=register address=0xD80000 size=0x70000
# Number of instructions to run every main loop.
loopcycles 300
+# Set the platform to Amiga to enable all the registers and stuff.
+platform amiga
+
# Forward mouse events to host system, defaults to off unless toggle key is pressed on the Pi.
# Syntax is mouse [device] [toggle key]
#mouse /dev/input/mouse0 m
#include "ide.h"
#include "m68k.h"
#include "main.h"
-#include "config_file/config_file.h"
+#include "platforms/platforms.h"
#include "input/input.h"
//#define BCM2708_PERI_BASE 0x20000000 //pi0-1
if (cfg) {
if (cfg->cpu_type) cpu_type = cfg->cpu_type;
if (cfg->loop_cycles) loop_cycles = cfg->loop_cycles;
+
+ if (!cfg->platform)
+ cfg->platform = make_platform_config("none", "generic");
+ cfg->platform->platform_initial_setup(cfg);
}
if (cfg->mouse_enabled) {
static unsigned int target = 0;
unsigned int m68k_read_memory_8(unsigned int address) {
+ if (cfg->platform->custom_read && cfg->platform->custom_read(cfg, address, &target, OP_TYPE_BYTE) != -1) {
+ return target;
+ }
+
if (cfg) {
int ret = handle_mapped_read(cfg, address, &target, OP_TYPE_BYTE, ovl);
if (ret != -1)
}
unsigned int m68k_read_memory_16(unsigned int address) {
+ if (cfg->platform->custom_read && cfg->platform->custom_read(cfg, address, &target, OP_TYPE_WORD) != -1) {
+ return target;
+ }
+
if (cfg) {
int ret = handle_mapped_read(cfg, address, &target, OP_TYPE_WORD, ovl);
if (ret != -1)
}
unsigned int m68k_read_memory_32(unsigned int address) {
+ if (cfg->platform->custom_read && cfg->platform->custom_read(cfg, address, &target, OP_TYPE_LONGWORD) != -1) {
+ return target;
+ }
+
if (cfg) {
int ret = handle_mapped_read(cfg, address, &target, OP_TYPE_LONGWORD, ovl);
if (ret != -1)
}
void m68k_write_memory_8(unsigned int address, unsigned int value) {
+ if (cfg->platform->custom_write && cfg->platform->custom_write(cfg, address, value, OP_TYPE_BYTE) != -1) {
+ return;
+ }
+
if (cfg) {
int ret = handle_mapped_write(cfg, address, value, OP_TYPE_BYTE, ovl);
if (ret != -1)
}
void m68k_write_memory_16(unsigned int address, unsigned int value) {
+ if (cfg->platform->custom_write && cfg->platform->custom_write(cfg, address, value, OP_TYPE_WORD) != -1) {
+ return;
+ }
+
if (cfg) {
int ret = handle_mapped_write(cfg, address, value, OP_TYPE_WORD, ovl);
if (ret != -1)
}
void m68k_write_memory_32(unsigned int address, unsigned int value) {
+ if (cfg->platform->custom_write && cfg->platform->custom_write(cfg, address, value, OP_TYPE_LONGWORD) != -1) {
+ return;
+ }
+
if (cfg) {
int ret = handle_mapped_write(cfg, address, value, OP_TYPE_LONGWORD, ovl);
if (ret != -1)
continue;
if (handle_regs) {
- if (handle_register_read(addr, type, &target) != -1) {
- *val = target;
- return 1;
+ if (cfg->platform && cfg->platform->register_read) {
+ if (cfg->platform->register_read(addr, type, &target) != -1) {
+ *val = target;
+ return 1;
+ }
}
return -1;
}
continue;
if (handle_regs) {
- return handle_register_write(addr, value, type);
+ if (cfg->platform && cfg->platform->register_write) {
+ return cfg->platform->register_write(addr, value, type);
+ }
}
else if (write_addr) {
//printf("[PC: %.8X] Write %s to %s (%.8X) (%d)\n", m68k_get_reg(NULL, M68K_REG_PC), op_type_names[type], map_type_names[cfg->map_type[i]], addr, mirror);
--- /dev/null
+#include "../platforms.h"
+#include "amiga-autoconf.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static unsigned char ac_fast_ram_rom[] = {
+ 0xe, AC_MEM_SIZE_8MB, // 00/02, link into memory free list, 8 MB
+ 0x6, 0x9, // 04/06, product id
+ 0x8, 0x0, // 08/0a, preference to 8 MB space
+ 0x0, 0x0, // 0c/0e, reserved
+ 0x0, 0x7, 0xd, 0xb, // 10/12/14/16, mfg id
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x4, 0x2, 0x0 // 18/.../26, serial
+};
+
+static unsigned char ac_a314_rom[] = {
+ 0xc, AC_MEM_SIZE_64KB, // 00/02, 64 kB
+ 0xa, 0x3, // 04/06, product id
+ 0x0, 0x0, // 08/0a, any space okay
+ 0x0, 0x0, // 0c/0e, reserved
+ 0x0, 0x7, 0xd, 0xb, // 10/12/14/16, mfg id
+ 0xa, 0x3, 0x1, 0x4, 0x0, 0x0, 0x0, 0x0 // 18/.../26, serial
+};
+
+int ac_current_pic = 0;
+int ac_pic_count = 0;
+int ac_done = 0;
+int ac_type[AC_PIC_LIMIT];
+int ac_index[AC_PIC_LIMIT];
+unsigned int ac_base[AC_PIC_LIMIT];
+
+unsigned char get_autoconf_size(int size) {
+ if (size == 8 * SIZE_MEGA)
+ return AC_MEM_SIZE_8MB;
+ if (size == 4 * SIZE_MEGA)
+ return AC_MEM_SIZE_4MB;
+ if (size == 2 * SIZE_MEGA)
+ return AC_MEM_SIZE_2MB;
+ else
+ return AC_MEM_SIZE_64KB;
+}
+
+unsigned int autoconfig_read_memory_8(struct emulator_config *cfg, unsigned int address_) {
+ unsigned char *rom = NULL;
+ int address = address_ - AC_BASE;
+ unsigned char val = 0;
+
+ switch(ac_type[ac_current_pic]) {
+ case ACTYPE_MAPFAST_Z2:
+ rom = ac_fast_ram_rom;
+ break;
+ case ACTYPE_A314:
+ rom = ac_a314_rom;
+ break;
+ default:
+ return 0;
+ break;
+ }
+
+
+ if ((address & 1) == 0 && (address / 2) < (int)sizeof(ac_fast_ram_rom)) {
+ if (ac_type[ac_current_pic] == ACTYPE_MAPFAST_Z2 && address / 2 == 1)
+ val = get_autoconf_size(cfg->map_size[ac_index[ac_current_pic]]);
+ else
+ val = rom[address / 2];
+ //printf("Read byte %d from autoconf for PIC %d (%.2X).\n", address/2, ac_current_pic, val);
+ }
+ val <<= 4;
+ if (address != 0 && address != 2 && address != 40 && address != 42)
+ val ^= 0xf0;
+
+ return (unsigned int)val;
+}
+
+void autoconfig_write_memory_8(struct emulator_config *cfg, unsigned int address_, unsigned int value) {
+ int address = address_ - AC_BASE;
+ int done = 0;
+
+ unsigned int *base = NULL;
+
+ switch(ac_type[ac_current_pic]) {
+ case ACTYPE_MAPFAST_Z2:
+ base = &ac_base[ac_current_pic];
+ break;
+ case ACTYPE_A314:
+ //base = &a314_base;
+ break;
+ default:
+ break;
+ }
+
+ if (!base) {
+ printf("Failed to set up the base for autoconfig PIC %d.\n", ac_current_pic);
+ done = 1;
+ }
+ else {
+ if (address == 0x4a) { // base[19:16]
+ *base = (value & 0xf0) << (16 - 4);
+ } else if (address == 0x48) { // base[23:20]
+ *base &= 0xff0fffff;
+ *base |= (value & 0xf0) << (20 - 4);
+
+ if (ac_type[ac_current_pic] == ACTYPE_MAPFAST_Z2) { // fast ram
+ //a314_set_mem_base_size(*base, cfg->map_size[ac_index[ac_current_pic]]);
+ }
+ done = 1;
+ } else if (address == 0x4c) { // shut up
+ done = 1;
+ }
+ }
+
+ if (done) {
+ //printf("Address of Z2 autoconf RAM changed to %.8x\n", ac_base[ac_current_pic]);
+ cfg->map_offset[ac_index[ac_current_pic]] = ac_base[ac_current_pic];
+ ac_current_pic++;
+ if (ac_current_pic == ac_pic_count)
+ ac_done = 1;
+ }
+}
--- /dev/null
+#define AC_BASE 0xE80000
+#define AC_SIZE (64 * 1024)
+#define AC_PIC_LIMIT 8
+
+#define AC_MEM_SIZE_8MB 0
+#define AC_MEM_SIZE_64KB 1
+#define AC_MEM_SIZE_128KB 2
+#define AC_MEM_SIZE_256KB 3
+#define AC_MEM_SIZE_512KB 4
+#define AC_MEM_SIZE_1MB 5
+#define AC_MEM_SIZE_2MB 6
+#define AC_MEM_SIZE_4MB 7
+
+enum autoconf_types {
+ ACTYPE_MAPFAST_Z2,
+ ACTYPE_MAPFAST_Z3,
+ ACTYPE_A314,
+ ACTYPE_NUM,
+};
+
+unsigned int autoconfig_read_memory_8(struct emulator_config *cfg, unsigned int address);
+void autoconfig_write_memory_8(struct emulator_config *cfg, unsigned int address, unsigned int value);
--- /dev/null
+#include "../platforms.h"
+#include "amiga-autoconf.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int handle_register_read_amiga(unsigned int addr, unsigned char type, unsigned int *val);
+int handle_register_write_amiga(unsigned int addr, unsigned int value, unsigned char type);
+
+extern int ac_done;
+extern int ac_pic_count;
+extern int ac_type[AC_PIC_LIMIT];
+extern int ac_index[AC_PIC_LIMIT];
+
+const char *z2_autoconf_id = "z2_autoconf_fast";
+const char *z2_autoconf_zap_id = "^2_autoconf_fast";
+
+int custom_read_amiga(struct emulator_config *cfg, unsigned int addr, unsigned int *val, unsigned char type) {
+ if (!ac_done && addr >= AC_BASE && addr < AC_BASE + AC_SIZE) {
+ if (ac_pic_count == 0) {
+ ac_done = 1;
+ return -1;
+ }
+
+ if (type == OP_TYPE_BYTE) {
+ //printf("Read from autoconf area.\n");
+ *val = autoconfig_read_memory_8(cfg, addr);
+ return 1;
+ }
+ }
+
+ return -1;
+}
+
+int custom_write_amiga(struct emulator_config *cfg, unsigned int addr, unsigned int val, unsigned char type) {
+ if (cfg || addr || val || type) {}
+ if (!ac_done && addr >= AC_BASE && addr < AC_BASE + AC_SIZE) {
+ if (type == OP_TYPE_BYTE) {
+ if (ac_pic_count == 0) {
+ ac_done = 1;
+ return -1;
+ }
+
+ //printf("Write to autoconf area.\n");
+ autoconfig_write_memory_8(cfg, addr, val);
+ return 1;
+ }
+ }
+
+ return -1;
+}
+
+int setup_platform_amiga(struct emulator_config *cfg) {
+ if (cfg) {}
+ printf("Performing setup for Amiga platform.\n");
+ // Look for Z2 autoconf Fast RAM by id
+ int index = get_named_mapped_item(cfg, "z2_autoconf_fast");
+ more_z2_fast:;
+ if (index != -1) {
+ cfg->map_id[index][0] = '^';
+ int resize_data = 0;
+ if (cfg->map_size[index] > 8 * SIZE_MEGA) {
+ printf("Attempted to configure more than 8MB of Z2 Fast RAM, downsizng to 8MB.\n");
+ resize_data = 8 * SIZE_MEGA;
+ }
+ else if(cfg->map_size[index] != 2 * SIZE_MEGA && cfg->map_size[index] != 4 * SIZE_MEGA && cfg->map_size[index] != 8 * SIZE_MEGA) {
+ printf("Z2 Fast RAM may only provision 2, 4 or 8MB of memory, resizing to ");
+ if (cfg->map_size[index] > 8 * SIZE_MEGA)
+ resize_data = 8 * SIZE_MEGA;
+ else if (cfg->map_size[index] > 4 * SIZE_MEGA)
+ resize_data = 4 * SIZE_MEGA;
+ else
+ resize_data = 2 * SIZE_MEGA;
+ printf("%dMB.\n", resize_data / SIZE_MEGA);
+ }
+ if (resize_data) {
+ free(cfg->map_data[index]);
+ cfg->map_size[index] = resize_data;
+ cfg->map_data[index] = (unsigned char *)malloc(cfg->map_size[index]);
+ }
+ printf("%dMB of Z2 Fast RAM configured at $%lx\n", cfg->map_size[index] / SIZE_MEGA, cfg->map_offset[index]);
+ ac_type[ac_pic_count] = ACTYPE_MAPFAST_Z2;
+ ac_index[ac_pic_count] = index;
+ ac_pic_count++;
+ printf("AAAAHH!\n");
+ }
+ else
+ printf("No Z2 Fast RAM configured.\n");
+ index = get_named_mapped_item(cfg, "z2_autoconf_fast");
+ if (index != -1)
+ goto more_z2_fast;
+
+ for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i ++) {
+ if (cfg->map_id[i] && strcmp(cfg->map_id[i], z2_autoconf_zap_id) == 0) {
+ cfg->map_id[i][0] = 'z';
+ }
+ }
+
+ return 0;
+}
+
+void setvar_amiga(char *var, char *val) {
+ if (var || val) {}
+}
+
+void create_platform_amiga(struct platform_config *cfg, char *subsys) {
+ cfg->register_read = handle_register_read_amiga;
+ cfg->register_write = handle_register_write_amiga;
+ cfg->custom_read = custom_read_amiga;
+ cfg->custom_write = custom_write_amiga;
+ cfg->platform_initial_setup = setup_platform_amiga;
+
+ cfg->setvar = setvar_amiga;
+
+ if (subsys) {
+ cfg->subsys = malloc(strlen(subsys) + 1);
+ strcpy(cfg->subsys, subsys);
+ }
+}
-#include "../Gayle.h"
-#include "../config_file/config_file.h"
+#include "../../Gayle.h"
+#include "../../config_file/config_file.h"
#define GAYLEBASE 0xD80000 // D7FFFF
#define GAYLESIZE 0x6FFFF
-int handle_register_read(unsigned int addr, unsigned char type, unsigned int *val) {
+int handle_register_read_amiga(unsigned int addr, unsigned char type, unsigned int *val) {
if (addr > GAYLEBASE && addr < GAYLEBASE + GAYLESIZE) {
switch(type) {
case OP_TYPE_BYTE:
return -1;
}
-int handle_register_write(unsigned int addr, unsigned int value, unsigned char type) {
+int handle_register_write_amiga(unsigned int addr, unsigned int value, unsigned char type) {
if (addr > GAYLEBASE && addr < GAYLEBASE + GAYLESIZE) {
switch(type) {
case OP_TYPE_BYTE:
--- /dev/null
+#include "../platforms.h"
+#include <stdlib.h>
+#include <string.h>
+
+int handle_register_read_dummy(unsigned int addr, unsigned char type, unsigned int *val);
+int handle_register_write_dummy(unsigned int addr, unsigned int value, unsigned char type);
+
+int setup_platform_dummy(struct emulator_config *cfg) {
+ if (cfg) {}
+ return 0;
+}
+
+void create_platform_dummy(struct platform_config *cfg, char *subsys) {
+ cfg->custom_read = NULL;
+ cfg->custom_write = NULL;
+ cfg->register_read = handle_register_read_dummy;
+ cfg->register_write = handle_register_write_dummy;
+ cfg->platform_initial_setup = setup_platform_dummy;
+
+ if (subsys) {
+ cfg->subsys = malloc(strlen(subsys) + 1);
+ strcpy(cfg->subsys, subsys);
+ }
+}
--- /dev/null
+int handle_register_read_dummy(unsigned int addr, unsigned char type, unsigned int *val) {
+ if (addr) {}
+ if (type) {}
+ if (val) {}
+ return -1;
+}
+
+int handle_register_write_dummy(unsigned int addr, unsigned int value, unsigned char type) {
+ if (addr) {}
+ if (type) {}
+ if (value) {}
+ return -1;
+}
--- /dev/null
+#include "platforms.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static char*platform_names[PLATFORM_NUM] = {
+ "none",
+ "amiga",
+ "mac68k",
+ "x68000",
+};
+
+int get_platform_index(char *name) {
+ if (!name || strlen(name) == 0)
+ return -1;
+
+ for (int i = 0; i < PLATFORM_NUM; i++) {
+ if (strcmp(name, platform_names[i]) == 0)
+ return i;
+ }
+ return -1;
+}
+
+void create_platform_amiga(struct platform_config *cfg, char *subsys);
+void create_platform_dummy(struct platform_config *cfg, char *subsys);
+
+struct platform_config *make_platform_config(char *name, char *subsys) {
+ struct platform_config *cfg = NULL;
+ int platform_id = get_platform_index(name);
+
+ if (platform_id == -1) {
+ // Display a warning if no match is found for the config name, in case it was mistyped.
+ printf("No match found for platform name \'%s\', defaulting to none/generic.\n", name);
+ platform_id = PLATFORM_NONE;
+ }
+ else {
+ printf("Creating platform config for %s...\n", name);
+ }
+
+ cfg = (struct platform_config *)malloc(sizeof(struct platform_config));
+ if (!cfg) {
+ printf("Failed to allocate memory for new platform config!.\n");
+ return NULL;
+ }
+ memset(cfg, 0x00, sizeof(struct platform_config));
+
+ switch(platform_id) {
+ case PLATFORM_AMIGA:
+ create_platform_amiga(cfg, subsys);
+ break;
+ case PLATFORM_NONE:
+ case PLATFORM_MAC:
+ case PLATFORM_X68000:
+ default:
+ create_platform_dummy(cfg, subsys);
+ break;
+ }
+
+ return cfg;
+}
\ No newline at end of file
--- /dev/null
+#include "../config_file/config_file.h"
+
+enum base_platforms {
+ PLATFORM_NONE,
+ PLATFORM_AMIGA,
+ PLATFORM_MAC,
+ PLATFORM_X68000,
+ PLATFORM_NUM,
+};
+
+struct platform_config *make_platform_config(char *name, char *subsys);
+++ /dev/null
-int handle_register_read(unsigned int addr, unsigned char type) {
- return -1;
-}
-
-int handle_register_write(unsigned int addr, unsigned char type) {
- return -1;
-}