Also disables keyboard input for now, until more investigating can be done.
cfg->map_type[index] = type;
cfg->map_offset[index] = addr;
cfg->map_size[index] = size;
+ cfg->map_high[index] = addr + size;
cfg->map_mirror[index] = mirr_addr;
if (strlen(map_id)) {
cfg->map_id[index] = (char *)malloc(strlen(map_id) + 1);
unsigned char map_type[MAX_NUM_MAPPED_ITEMS];
long map_offset[MAX_NUM_MAPPED_ITEMS];
+ long map_high[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];
unsigned char mouse_enabled, keyboard_enabled;
unsigned int loop_cycles;
- unsigned int map_low, map_high;
+ unsigned int mapped_low, mapped_high;
unsigned int custom_low, custom_high;
};
int (*register_write)(unsigned int addr, unsigned int value, unsigned char type);
int (*platform_initial_setup)(struct emulator_config *cfg);
+ void (*handle_reset)(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_mapped_read(struct emulator_config *cfg, unsigned int addr, unsigned int *val, unsigned char type);
+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);
unsigned int get_int(char *str);
//unsigned char g_kick[524288];
//unsigned char g_ram[FASTSIZE + 1]; /* RAM */
unsigned char toggle;
-static volatile unsigned char ovl;
+int ovl;
static volatile unsigned char maprom;
void sigint_handler(int sig_num) {
m68k_execute(loop_cycles);
// FIXME: Rework this to use keyboard events instead.
- while (get_key_char(&c)) {
+ /*while (get_key_char(&c)) {
if (c == cfg->keyboard_toggle_key && !kb_hook_enabled) {
kb_hook_enabled = 1;
printf("Keyboard hook enabled.\n");
goto stop_cpu_emulation;
}
}
- }
+ }*/
/*
if (toggle == 1){
srdata = read_reg();
break; \
} \
} \
- if (ovl || (address >= cfg->map_low && address < cfg->map_high)) { \
- if (handle_mapped_read(cfg, address, &target, a, ovl) != -1) \
+ if (ovl || (address >= cfg->mapped_low && address < cfg->mapped_high)) { \
+ if (handle_mapped_read(cfg, address, &target, a) != -1) \
return target; \
- } \
+ }
unsigned int m68k_read_memory_8(unsigned int address) {
PLATFORM_CHECK_READ(OP_TYPE_BYTE);
if (address >= cfg->custom_low && address < cfg->custom_high) { \
switch(cfg->platform->id) { \
case PLATFORM_AMIGA: { \
- if (custom_write_amiga(cfg, address, value, OP_TYPE_BYTE) != -1) { \
+ if (custom_write_amiga(cfg, address, value, a) != -1) { \
return; \
} \
break; \
break; \
} \
} \
- if (address >= cfg->map_low && address < cfg->map_high) { \
- if (handle_mapped_write(cfg, address, value, OP_TYPE_BYTE, ovl) != -1) \
+ if (address >= cfg->mapped_low && address < cfg->mapped_high) { \
+ if (handle_mapped_write(cfg, address, value, a) != -1) \
return; \
- } \
+ }
void m68k_write_memory_8(unsigned int address, unsigned int value) {
PLATFORM_CHECK_WRITE(OP_TYPE_BYTE);
#include <endian.h>
#define CHKRANGE(a, b, c) a >= (unsigned int)b && a < (unsigned int)(b + c)
+#define CHKRANGE_ABS(a, b, c) a >= (unsigned int)b && a < (unsigned int) c
static unsigned int target;
+extern int ovl;
extern const char *map_type_names[MAPTYPE_NUM];
const char *op_type_names[OP_TYPE_NUM] = {
"MEM",
};
-inline int handle_mapped_read(struct emulator_config *cfg, unsigned int addr, unsigned int *val, unsigned char type, unsigned char mirror) {
+inline int handle_mapped_read(struct emulator_config *cfg, unsigned int addr, unsigned int *val, unsigned char type) {
unsigned char *read_addr = NULL;
- char handle_regs = 0;
-
- //printf("Mapped read: %.8x\n", addr);
for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) {
if (cfg->map_type[i] == MAPTYPE_NONE)
continue;
- 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]) % 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]) % cfg->rom_size[i]);
- break;
- case MAPTYPE_RAM:
- if (CHKRANGE(addr, cfg->map_offset[i], cfg->map_size[i]))
- read_addr = cfg->map_data[i] + (addr - cfg->map_offset[i]);
- break;
- case MAPTYPE_REGISTER:
- if (CHKRANGE(addr, cfg->map_offset[i], cfg->map_size[i]))
- handle_regs = 1;
- break;
- }
-
- if (!read_addr && !handle_regs)
- continue;
-
- if (handle_regs) {
- if (cfg->platform && cfg->platform->register_read) {
- if (cfg->platform->register_read(addr, type, &target) != -1) {
- *val = target;
- return 1;
- }
+ else if (ovl && cfg->map_type[i] == MAPTYPE_ROM) {
+ if (cfg->map_mirror[i] != -1 && CHKRANGE_ABS(addr, cfg->map_mirror[i], cfg->map_high[i])) {
+ read_addr = cfg->map_data[i] + ((addr - cfg->map_mirror[i]) % cfg->rom_size[i]);
+ goto read_value;
}
- return -1;
}
- else if (read_addr) {
- //printf("[PC: %.8X] Read %s from %s (%.8X) (%d)\n", m68k_get_reg(NULL, M68K_REG_PC), op_type_names[type], map_type_names[cfg->map_type[i]], addr, mirror);
- //printf("Readaddr: %.8lX (Base %.8lX\n", (uint64_t)(read_addr), (uint64_t)cfg->map_data[i]);
- switch(type) {
- case OP_TYPE_BYTE:
- *val = read_addr[0];
- //printf("Read val: %.8lX (%d)\n", (uint64_t)val, *val);
- return 1;
- break;
- case OP_TYPE_WORD:
- *val = be16toh(((unsigned short *)read_addr)[0]);
- //printf("Read val: %.8lX (%d)\n", (uint64_t)val, *val);
- return 1;
+ else if (CHKRANGE_ABS(addr, cfg->map_offset[i], cfg->map_high[i])) {
+ switch(cfg->map_type[i]) {
+ case MAPTYPE_ROM:
+ read_addr = cfg->map_data[i] + ((addr - cfg->map_offset[i]) % cfg->rom_size[i]);
+ goto read_value;
break;
- case OP_TYPE_LONGWORD:
- *val = be32toh(((unsigned int *)read_addr)[0]);
- //printf("Read val: %.8lX (%d)\n", (uint64_t)val, *val);
- return 1;
+ case MAPTYPE_RAM:
+ read_addr = cfg->map_data[i] + (addr - cfg->map_offset[i]);
+ goto read_value;
break;
- case OP_TYPE_MEM:
+ case MAPTYPE_REGISTER:
+ if (cfg->platform && cfg->platform->register_read) {
+ if (cfg->platform->register_read(addr, type, &target) != -1) {
+ *val = target;
+ return 1;
+ }
+ }
return -1;
break;
}
}
return -1;
+
+read_value:;
+ //printf("Read value from %.8X\n", addr);
+ switch(type) {
+ case OP_TYPE_BYTE:
+ *val = read_addr[0];
+ return 1;
+ break;
+ case OP_TYPE_WORD:
+ *val = be16toh(((unsigned short *)read_addr)[0]);
+ return 1;
+ break;
+ case OP_TYPE_LONGWORD:
+ *val = be32toh(((unsigned int *)read_addr)[0]);
+ return 1;
+ break;
+ case OP_TYPE_MEM:
+ return -1;
+ break;
+ }
+
+ return 1;
}
-inline int handle_mapped_write(struct emulator_config *cfg, unsigned int addr, unsigned int value, unsigned char type, unsigned char mirror) {
+inline int handle_mapped_write(struct emulator_config *cfg, unsigned int addr, unsigned int value, unsigned char type) {
unsigned char *write_addr = NULL;
- char handle_regs = 0;
-
- //printf("Mapped write: %.8x\n", addr);
- if (mirror) { }
for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) {
if (cfg->map_type[i] == MAPTYPE_NONE)
continue;
- switch(cfg->map_type[i]) {
- case MAPTYPE_ROM:
- if (CHKRANGE(addr, cfg->map_offset[i], cfg->map_size[i]))
- return 1;
- break;
- case MAPTYPE_RAM:
- if (CHKRANGE(addr, cfg->map_offset[i], cfg->map_size[i]))
- write_addr = cfg->map_data[i] + (addr - cfg->map_offset[i]);
- break;
- case MAPTYPE_REGISTER:
- if (CHKRANGE(addr, cfg->map_offset[i], cfg->map_size[i]))
- handle_regs = 1;
- break;
- }
-
- if (!write_addr && !handle_regs)
- continue;
-
- if (handle_regs) {
- 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);
- //printf("Writeaddr: %.8lX (Base %.8lX\n", (uint64_t)(write_addr), (uint64_t)cfg->map_data[i]);
- switch(type) {
- case OP_TYPE_BYTE:
- write_addr[0] = (unsigned char)value;
- //printf("Write val: %.8X (%d)\n", (uint32_t)value, value);
+ else if (CHKRANGE_ABS(addr, cfg->map_offset[i], cfg->map_high[i])) {
+ switch(cfg->map_type[i]) {
+ case MAPTYPE_ROM:
return 1;
break;
- case OP_TYPE_WORD:
- ((short *)write_addr)[0] = htobe16(value);
- //printf("Write val: %.8X (%d)\n", (uint32_t)value, value);
- return 1;
- break;
- case OP_TYPE_LONGWORD:
- ((int *)write_addr)[0] = htobe32(value);
- //printf("Write val: %.8X (%d)\n", (uint32_t)value, value);
- return 1;
+ case MAPTYPE_RAM:
+ write_addr = cfg->map_data[i] + (addr - cfg->map_offset[i]);
+ goto write_value;
break;
- case OP_TYPE_MEM:
- return -1;
+ case MAPTYPE_REGISTER:
+ if (cfg->platform && cfg->platform->register_write) {
+ return cfg->platform->register_write(addr, value, type);
+ }
break;
}
}
}
return -1;
+
+write_value:;
+ //printf("Write value to %.8X\n", addr);
+ switch(type) {
+ case OP_TYPE_BYTE:
+ write_addr[0] = (unsigned char)value;
+ return 1;
+ break;
+ case OP_TYPE_WORD:
+ ((short *)write_addr)[0] = htobe16(value);
+ return 1;
+ break;
+ case OP_TYPE_LONGWORD:
+ ((int *)write_addr)[0] = htobe32(value);
+ return 1;
+ break;
+ case OP_TYPE_MEM:
+ return -1;
+ break;
+ }
+
+ return 1;
}
return AC_MEM_SIZE_EXT_64MB;
}
+extern void adjust_ranges_amiga(struct emulator_config *cfg);
+
unsigned int autoconfig_read_memory_z3_8(struct emulator_config *cfg, unsigned int address_) {
int address = address_ - AC_Z3_BASE;
int index = ac_z3_index[ac_z3_current_pic];
nib_latch = 0;
printf("Address of Z3 autoconf RAM assigned to $%.8x\n", ac_base[ac_z3_current_pic]);
cfg->map_offset[index] = ac_base[ac_z3_current_pic];
+ cfg->map_high[index] = cfg->map_offset[index] + cfg->map_size[index];
ac_z3_current_pic++;
- if (ac_z3_current_pic == ac_z3_pic_count)
+ if (ac_z3_current_pic == ac_z3_pic_count) {
ac_z3_done = 1;
+ adjust_ranges_amiga(cfg);
+ }
}
return;
void autoconfig_write_memory_8(struct emulator_config *cfg, unsigned int address_, unsigned int value) {
int address = address_ - AC_Z2_BASE;
int done = 0;
+ int index = ac_z2_index[ac_z2_current_pic];
unsigned int *base = NULL;
if (done) {
printf("Address of Z2 autoconf RAM assigned to $%.8x\n", ac_base[ac_z2_current_pic]);
- cfg->map_offset[ac_z2_index[ac_z2_current_pic]] = ac_base[ac_z2_current_pic];
+ cfg->map_offset[index] = ac_base[ac_z2_current_pic];
+ cfg->map_high[index] = cfg->map_offset[index] + cfg->map_size[index];
+ printf("Z2 PIC %d at $%.8lX-%.8lX, Size: %d MB\n", ac_z2_current_pic, cfg->map_offset[index], cfg->map_high[index], cfg->map_size[index] / SIZE_MEGA);
ac_z2_current_pic++;
- if (ac_z2_current_pic == ac_z2_pic_count)
+ if (ac_z2_current_pic == ac_z2_pic_count) {
ac_z2_done = 1;
+ adjust_ranges_amiga(cfg);
+ }
}
}
extern const char *op_type_names[OP_TYPE_NUM];
+#define min(a, b) (a < b) ? a : b
+#define max(a, b) (a > b) ? a : b
+
inline int custom_read_amiga(struct emulator_config *cfg, unsigned int addr, unsigned int *val, unsigned char type) {
if (!ac_z2_done && addr >= AC_Z2_BASE && addr < AC_Z2_BASE + AC_SIZE) {
if (ac_z2_pic_count == 0) {
return -1;
}
- printf("Write to Z2 autoconf area.\n");
+ //printf("Write to Z2 autoconf area.\n");
autoconfig_write_memory_8(cfg, addr, val);
return 1;
}
return -1;
}
+void adjust_ranges_amiga(struct emulator_config *cfg) {
+ cfg->mapped_high = 0;
+ cfg->mapped_low = 0;
+ cfg->custom_high = 0;
+ cfg->custom_low = 0;
+
+ // Set up the min/max ranges for mapped reads/writes
+ if (gayle_emulation_enabled) {
+ cfg->mapped_low = GAYLEBASE;
+ cfg->mapped_high = GAYLEBASE + GAYLESIZE;
+ }
+ for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) {
+ if (cfg->map_type[i] != MAPTYPE_NONE) {
+ if ((cfg->map_offset[i] != 0 && cfg->map_offset[i] < cfg->mapped_low) || cfg->mapped_low == 0)
+ cfg->mapped_low = cfg->map_offset[i];
+ if (cfg->map_offset[i] + cfg->map_size[i] > cfg->mapped_high)
+ cfg->mapped_high = cfg->map_offset[i] + cfg->map_size[i];
+ }
+ }
+
+ if (ac_z2_pic_count && !ac_z2_done) {
+ if (cfg->custom_low == 0)
+ cfg->custom_low = AC_Z2_BASE;
+ else
+ cfg->custom_low = min(cfg->custom_low, AC_Z2_BASE);
+ cfg->custom_high = max(cfg->custom_high, AC_Z2_BASE + AC_SIZE);
+ }
+ if (ac_z3_pic_count && !ac_z3_done) {
+ if (cfg->custom_low == 0)
+ cfg->custom_low = AC_Z3_BASE;
+ else
+ cfg->custom_low = min(cfg->custom_low, AC_Z3_BASE);
+ cfg->custom_high = max(cfg->custom_high, AC_Z3_BASE + AC_SIZE);
+ }
+
+ printf("Platform custom range: %.8X-%.8X\n", cfg->custom_low, cfg->custom_high);
+ printf("Platform mapped range: %.8X-%.8X\n", cfg->mapped_low, cfg->mapped_high);
+}
+
int setup_platform_amiga(struct emulator_config *cfg) {
if (cfg) {}
printf("Performing setup for Amiga platform.\n");
}
}
- // Set up the min/max ranges for mapped reads/writes
- for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) {
- if (cfg->map_type[i] != MAPTYPE_NONE) {
- if ((cfg->map_offset[i] != 0 && cfg->map_offset[i] < cfg->map_low) || cfg->map_low == 0)
- cfg->map_low = cfg->map_offset[i];
- if (cfg->map_offset[i] + cfg->map_size[i] > cfg->map_high)
- cfg->map_high = cfg->map_offset[i] + cfg->map_size[i];
- }
- }
-
- if (gayle_emulation_enabled) {
- cfg->custom_low = GAYLEBASE;
- cfg->custom_high = GAYLEBASE + GAYLESIZE;
- }
-
- printf("Platform custom range: %.8X-%.8X\n", cfg->custom_low, cfg->custom_high);
- printf("Platform mapped range: %.8X-%.8X\n", cfg->map_low, cfg->map_high);
+ adjust_ranges_amiga(cfg);
return 0;
}
}
}
+void handle_reset_amiga(struct emulator_config *cfg) {
+ ac_z3_done = 0;
+ ac_z2_done = 0;
+
+ adjust_ranges_amiga(cfg);
+}
+
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->handle_reset = handle_reset_amiga;
cfg->setvar = setvar_amiga;
cfg->id = PLATFORM_AMIGA;