4 #include "../platforms.h"
5 #include "amiga-autoconf.h"
6 #include "amiga-registers.h"
8 int handle_register_read_amiga(unsigned int addr, unsigned char type, unsigned int *val);
9 int handle_register_write_amiga(unsigned int addr, unsigned int value, unsigned char type);
11 extern int ac_z2_done;
12 extern int ac_z2_pic_count;
13 extern int ac_z2_type[AC_PIC_LIMIT];
14 extern int ac_z2_index[AC_PIC_LIMIT];
16 extern int ac_z3_pic_count;
17 extern int ac_z3_done;
18 extern int ac_z3_type[AC_PIC_LIMIT];
19 extern int ac_z3_index[AC_PIC_LIMIT];
20 extern int gayle_emulation_enabled;
22 char *z2_autoconf_id = "z2_autoconf_fast";
23 char *z2_autoconf_zap_id = "^2_autoconf_fast";
24 char *z3_autoconf_id = "z3_autoconf_fast";
25 char *z3_autoconf_zap_id = "^3_autoconf_fast";
27 extern const char *op_type_names[OP_TYPE_NUM];
29 #define min(a, b) (a < b) ? a : b
30 #define max(a, b) (a > b) ? a : b
32 inline int custom_read_amiga(struct emulator_config *cfg, unsigned int addr, unsigned int *val, unsigned char type) {
33 if (!ac_z2_done && addr >= AC_Z2_BASE && addr < AC_Z2_BASE + AC_SIZE) {
34 if (ac_z2_pic_count == 0) {
39 if (type == OP_TYPE_BYTE) {
40 *val = autoconfig_read_memory_8(cfg, addr);
44 if (!ac_z3_done && addr >= AC_Z3_BASE && addr < AC_Z3_BASE + AC_SIZE) {
45 if (ac_z3_pic_count == 0) {
50 if (type == OP_TYPE_BYTE) {
51 *val = autoconfig_read_memory_z3_8(cfg, addr);
55 printf("Unexpected %s read from Z3 autoconf addr %.X\n", op_type_names[type], addr - AC_Z3_BASE);
63 inline int custom_write_amiga(struct emulator_config *cfg, unsigned int addr, unsigned int val, unsigned char type) {
64 if (!ac_z2_done && addr >= AC_Z2_BASE && addr < AC_Z2_BASE + AC_SIZE) {
65 if (type == OP_TYPE_BYTE) {
66 if (ac_z2_pic_count == 0) {
71 //printf("Write to Z2 autoconf area.\n");
72 autoconfig_write_memory_8(cfg, addr, val);
77 if (!ac_z3_done && addr >= AC_Z3_BASE && addr < AC_Z3_BASE + AC_SIZE) {
78 if (type == OP_TYPE_BYTE) {
79 if (ac_z3_pic_count == 0) {
84 //printf("Write to autoconf area.\n");
85 autoconfig_write_memory_z3_8(cfg, addr, val);
88 else if (type == OP_TYPE_WORD) {
89 autoconfig_write_memory_z3_16(cfg, addr, val);
93 printf("Unexpected %s write to Z3 autoconf addr %.X\n", op_type_names[type], addr - AC_Z3_BASE);
101 void adjust_ranges_amiga(struct emulator_config *cfg) {
102 cfg->mapped_high = 0;
104 cfg->custom_high = 0;
107 // Set up the min/max ranges for mapped reads/writes
108 if (gayle_emulation_enabled) {
109 cfg->mapped_low = GAYLEBASE;
110 cfg->mapped_high = GAYLEBASE + GAYLESIZE;
112 for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) {
113 if (cfg->map_type[i] != MAPTYPE_NONE) {
114 if ((cfg->map_offset[i] != 0 && cfg->map_offset[i] < cfg->mapped_low) || cfg->mapped_low == 0)
115 cfg->mapped_low = cfg->map_offset[i];
116 if (cfg->map_offset[i] + cfg->map_size[i] > cfg->mapped_high)
117 cfg->mapped_high = cfg->map_offset[i] + cfg->map_size[i];
121 if (ac_z2_pic_count && !ac_z2_done) {
122 if (cfg->custom_low == 0)
123 cfg->custom_low = AC_Z2_BASE;
125 cfg->custom_low = min(cfg->custom_low, AC_Z2_BASE);
126 cfg->custom_high = max(cfg->custom_high, AC_Z2_BASE + AC_SIZE);
128 if (ac_z3_pic_count && !ac_z3_done) {
129 if (cfg->custom_low == 0)
130 cfg->custom_low = AC_Z3_BASE;
132 cfg->custom_low = min(cfg->custom_low, AC_Z3_BASE);
133 cfg->custom_high = max(cfg->custom_high, AC_Z3_BASE + AC_SIZE);
136 printf("Platform custom range: %.8X-%.8X\n", cfg->custom_low, cfg->custom_high);
137 printf("Platform mapped range: %.8X-%.8X\n", cfg->mapped_low, cfg->mapped_high);
140 int setup_platform_amiga(struct emulator_config *cfg) {
141 printf("Performing setup for Amiga platform.\n");
142 // Look for Z2 autoconf Fast RAM by id
143 int index = get_named_mapped_item(cfg, z2_autoconf_id);
146 // "Zap" config items as they are processed.
147 cfg->map_id[index][0] = '^';
149 if (cfg->map_size[index] > 8 * SIZE_MEGA) {
150 printf("Attempted to configure more than 8MB of Z2 Fast RAM, downsizng to 8MB.\n");
151 resize_data = 8 * SIZE_MEGA;
153 else if(cfg->map_size[index] != 2 * SIZE_MEGA && cfg->map_size[index] != 4 * SIZE_MEGA && cfg->map_size[index] != 8 * SIZE_MEGA) {
154 printf("Z2 Fast RAM may only provision 2, 4 or 8MB of memory, resizing to ");
155 if (cfg->map_size[index] > 8 * SIZE_MEGA)
156 resize_data = 8 * SIZE_MEGA;
157 else if (cfg->map_size[index] > 4 * SIZE_MEGA)
158 resize_data = 4 * SIZE_MEGA;
160 resize_data = 2 * SIZE_MEGA;
161 printf("%dMB.\n", resize_data / SIZE_MEGA);
164 free(cfg->map_data[index]);
165 cfg->map_size[index] = resize_data;
166 cfg->map_data[index] = (unsigned char *)malloc(cfg->map_size[index]);
168 printf("%dMB of Z2 Fast RAM configured at $%lx\n", cfg->map_size[index] / SIZE_MEGA, cfg->map_offset[index]);
169 ac_z2_type[ac_z2_pic_count] = ACTYPE_MAPFAST_Z2;
170 ac_z2_index[ac_z2_pic_count] = index;
174 printf("No Z2 Fast RAM configured.\n");
176 index = get_named_mapped_item(cfg, z2_autoconf_id);
180 for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i ++) {
181 // Restore any "zapped" autoconf items so they can be reinitialized if needed.
182 if (cfg->map_id[i] && strcmp(cfg->map_id[i], z2_autoconf_zap_id) == 0) {
183 cfg->map_id[i][0] = z2_autoconf_id[0];
187 index = get_named_mapped_item(cfg, z3_autoconf_id);
190 cfg->map_id[index][0] = '^';
191 printf("%dMB of Z3 Fast RAM configured at $%lx\n", cfg->map_size[index] / SIZE_MEGA, cfg->map_offset[index]);
192 ac_z3_type[ac_z3_pic_count] = ACTYPE_MAPFAST_Z3;
193 ac_z3_index[ac_z3_pic_count] = index;
197 printf("No Z3 Fast RAM configured.\n");
198 index = get_named_mapped_item(cfg, z3_autoconf_id);
201 for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) {
202 if (cfg->map_id[i] && strcmp(cfg->map_id[i], z3_autoconf_zap_id) == 0) {
203 cfg->map_id[i][0] = z3_autoconf_id[0];
207 index = get_named_mapped_item(cfg, "cpu_slot_ram");
209 m68k_add_ram_range((uint32_t)cfg->map_offset[index], (uint32_t)cfg->map_high[index], cfg->map_data[index]);
212 adjust_ranges_amiga(cfg);
217 void setvar_amiga(char *var, char *val) {
221 if (strcmp(var, "enable_rtc_emulation") == 0) {
222 int8_t rtc_enabled = 0;
223 if (!val || strlen(val) == 0)
226 rtc_enabled = get_int(val);
228 if (rtc_enabled != -1) {
229 configure_rtc_emulation_amiga(rtc_enabled);
232 if (strcmp(var, "hdd0") == 0) {
233 if (val && strlen(val) != 0)
234 set_hard_drive_image_file_amiga(0, val);
238 void handle_reset_amiga(struct emulator_config *cfg) {
242 adjust_ranges_amiga(cfg);
245 void create_platform_amiga(struct platform_config *cfg, char *subsys) {
246 cfg->register_read = handle_register_read_amiga;
247 cfg->register_write = handle_register_write_amiga;
248 cfg->custom_read = custom_read_amiga;
249 cfg->custom_write = custom_write_amiga;
250 cfg->platform_initial_setup = setup_platform_amiga;
251 cfg->handle_reset = handle_reset_amiga;
253 cfg->setvar = setvar_amiga;
254 cfg->id = PLATFORM_AMIGA;
257 cfg->subsys = malloc(strlen(subsys) + 1);
258 strcpy(cfg->subsys, subsys);