1 #include "config_file/config_file.h"
6 #define CHKRANGE(a, b, c) a >= (unsigned int)b && a < (unsigned int)(b + c)
8 static unsigned int target;
10 extern const char *map_type_names[MAPTYPE_NUM];
11 const char *op_type_names[OP_TYPE_NUM] = {
18 int handle_mapped_read(struct emulator_config *cfg, unsigned int addr, unsigned int *val, unsigned char type, unsigned char mirror) {
19 unsigned char *read_addr = NULL;
22 //printf("Mapped read: %.8x\n", addr);
24 for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) {
25 if (cfg->map_type[i] == MAPTYPE_NONE)
27 switch(cfg->map_type[i]) {
29 if (CHKRANGE(addr, cfg->map_offset[i], cfg->map_size[i]))
30 read_addr = cfg->map_data[i] + (addr - cfg->map_offset[i]);
31 else if (cfg->map_mirror[i] != -1 && mirror && CHKRANGE(addr, cfg->map_mirror[i], cfg->map_size[i]))
32 read_addr = cfg->map_data[i] + (addr - cfg->map_mirror[i]);
35 if (CHKRANGE(addr, cfg->map_offset[i], cfg->map_size[i]))
36 read_addr = cfg->map_data[i] + (addr - cfg->map_offset[i]);
38 case MAPTYPE_REGISTER:
39 if (CHKRANGE(addr, cfg->map_offset[i], cfg->map_size[i]))
44 if (!read_addr && !handle_regs)
48 if (handle_register_read(addr, type, &target) != -1) {
55 //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);
56 //printf("Readaddr: %.8lX (Base %.8lX\n", (uint64_t)(read_addr), (uint64_t)cfg->map_data[i]);
60 //printf("Read val: %.8lX (%d)\n", (uint64_t)val, *val);
64 *val = be16toh(((unsigned short *)read_addr)[0]);
65 //printf("Read val: %.8lX (%d)\n", (uint64_t)val, *val);
68 case OP_TYPE_LONGWORD:
69 *val = be32toh(((unsigned int *)read_addr)[0]);
70 //printf("Read val: %.8lX (%d)\n", (uint64_t)val, *val);
83 int handle_mapped_write(struct emulator_config *cfg, unsigned int addr, unsigned int value, unsigned char type, unsigned char mirror) {
84 unsigned char *write_addr = NULL;
87 //printf("Mapped write: %.8x\n", addr);
90 for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) {
91 if (cfg->map_type[i] == MAPTYPE_NONE)
93 switch(cfg->map_type[i]) {
95 if (CHKRANGE(addr, cfg->map_offset[i], cfg->map_size[i]))
99 if (CHKRANGE(addr, cfg->map_offset[i], cfg->map_size[i]))
100 write_addr = cfg->map_data[i] + (addr - cfg->map_offset[i]);
102 case MAPTYPE_REGISTER:
103 if (CHKRANGE(addr, cfg->map_offset[i], cfg->map_size[i]))
108 if (!write_addr && !handle_regs)
112 return handle_register_write(addr, value, type);
114 else if (write_addr) {
115 //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);
116 //printf("Writeaddr: %.8lX (Base %.8lX\n", (uint64_t)(write_addr), (uint64_t)cfg->map_data[i]);
119 write_addr[0] = (unsigned char)value;
120 //printf("Write val: %.8X (%d)\n", (uint32_t)value, value);
124 ((short *)write_addr)[0] = htobe16(value);
125 //printf("Write val: %.8X (%d)\n", (uint32_t)value, value);
128 case OP_TYPE_LONGWORD:
129 ((int *)write_addr)[0] = htobe32(value);
130 //printf("Write val: %.8X (%d)\n", (uint32_t)value, value);