4 #include "../platforms.h"
5 #include "amiga-autoconf.h"
6 #include "amiga-registers.h"
7 #include "../shared/rtc.h"
9 int handle_register_read_amiga(unsigned int addr, unsigned char type, unsigned int *val);
10 int handle_register_write_amiga(unsigned int addr, unsigned int value, unsigned char type);
12 extern int ac_z2_done;
13 extern int ac_z2_pic_count;
14 extern int ac_z2_type[AC_PIC_LIMIT];
15 extern int ac_z2_index[AC_PIC_LIMIT];
17 extern int ac_z3_pic_count;
18 extern int ac_z3_done;
19 extern int ac_z3_type[AC_PIC_LIMIT];
20 extern int ac_z3_index[AC_PIC_LIMIT];
21 extern int gayle_emulation_enabled;
23 char *z2_autoconf_id = "z2_autoconf_fast";
24 char *z2_autoconf_zap_id = "^2_autoconf_fast";
25 char *z3_autoconf_id = "z3_autoconf_fast";
26 char *z3_autoconf_zap_id = "^3_autoconf_fast";
28 extern const char *op_type_names[OP_TYPE_NUM];
29 extern uint8_t cdtv_mode;
30 extern uint8_t rtc_type;
32 #define min(a, b) (a < b) ? a : b
33 #define max(a, b) (a > b) ? a : b
35 inline int custom_read_amiga(struct emulator_config *cfg, unsigned int addr, unsigned int *val, unsigned char type) {
36 if (!ac_z2_done && addr >= AC_Z2_BASE && addr < AC_Z2_BASE + AC_SIZE) {
37 if (ac_z2_pic_count == 0) {
42 if (type == OP_TYPE_BYTE) {
43 *val = autoconfig_read_memory_8(cfg, addr);
47 if (!ac_z3_done && addr >= AC_Z3_BASE && addr < AC_Z3_BASE + AC_SIZE) {
48 if (ac_z3_pic_count == 0) {
53 if (type == OP_TYPE_BYTE) {
54 *val = autoconfig_read_memory_z3_8(cfg, addr);
58 printf("Unexpected %s read from Z3 autoconf addr %.X\n", op_type_names[type], addr - AC_Z3_BASE);
66 inline int custom_write_amiga(struct emulator_config *cfg, unsigned int addr, unsigned int val, unsigned char type) {
67 if (!ac_z2_done && addr >= AC_Z2_BASE && addr < AC_Z2_BASE + AC_SIZE) {
68 if (type == OP_TYPE_BYTE) {
69 if (ac_z2_pic_count == 0) {
74 //printf("Write to Z2 autoconf area.\n");
75 autoconfig_write_memory_8(cfg, addr, val);
80 if (!ac_z3_done && addr >= AC_Z3_BASE && addr < AC_Z3_BASE + AC_SIZE) {
81 if (type == OP_TYPE_BYTE) {
82 if (ac_z3_pic_count == 0) {
87 //printf("Write to autoconf area.\n");
88 autoconfig_write_memory_z3_8(cfg, addr, val);
91 else if (type == OP_TYPE_WORD) {
92 autoconfig_write_memory_z3_16(cfg, addr, val);
96 printf("Unexpected %s write to Z3 autoconf addr %.X\n", op_type_names[type], addr - AC_Z3_BASE);
104 void adjust_ranges_amiga(struct emulator_config *cfg) {
105 cfg->mapped_high = 0;
107 cfg->custom_high = 0;
110 // Set up the min/max ranges for mapped reads/writes
111 if (gayle_emulation_enabled) {
112 cfg->mapped_low = GAYLEBASE;
113 cfg->mapped_high = GAYLEBASE + GAYLESIZE;
115 for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) {
116 if (cfg->map_type[i] != MAPTYPE_NONE) {
117 if ((cfg->map_offset[i] != 0 && cfg->map_offset[i] < cfg->mapped_low) || cfg->mapped_low == 0)
118 cfg->mapped_low = cfg->map_offset[i];
119 if (cfg->map_offset[i] + cfg->map_size[i] > cfg->mapped_high)
120 cfg->mapped_high = cfg->map_offset[i] + cfg->map_size[i];
124 if (ac_z2_pic_count && !ac_z2_done) {
125 if (cfg->custom_low == 0)
126 cfg->custom_low = AC_Z2_BASE;
128 cfg->custom_low = min(cfg->custom_low, AC_Z2_BASE);
129 cfg->custom_high = max(cfg->custom_high, AC_Z2_BASE + AC_SIZE);
131 if (ac_z3_pic_count && !ac_z3_done) {
132 if (cfg->custom_low == 0)
133 cfg->custom_low = AC_Z3_BASE;
135 cfg->custom_low = min(cfg->custom_low, AC_Z3_BASE);
136 cfg->custom_high = max(cfg->custom_high, AC_Z3_BASE + AC_SIZE);
139 printf("Platform custom range: %.8X-%.8X\n", cfg->custom_low, cfg->custom_high);
140 printf("Platform mapped range: %.8X-%.8X\n", cfg->mapped_low, cfg->mapped_high);
143 int setup_platform_amiga(struct emulator_config *cfg) {
144 printf("Performing setup for Amiga platform.\n");
145 // Look for Z2 autoconf Fast RAM by id
146 int index = get_named_mapped_item(cfg, z2_autoconf_id);
149 // "Zap" config items as they are processed.
150 cfg->map_id[index][0] = '^';
152 if (cfg->map_size[index] > 8 * SIZE_MEGA) {
153 printf("Attempted to configure more than 8MB of Z2 Fast RAM, downsizng to 8MB.\n");
154 resize_data = 8 * SIZE_MEGA;
156 else if(cfg->map_size[index] != 2 * SIZE_MEGA && cfg->map_size[index] != 4 * SIZE_MEGA && cfg->map_size[index] != 8 * SIZE_MEGA) {
157 printf("Z2 Fast RAM may only provision 2, 4 or 8MB of memory, resizing to ");
158 if (cfg->map_size[index] > 8 * SIZE_MEGA)
159 resize_data = 8 * SIZE_MEGA;
160 else if (cfg->map_size[index] > 4 * SIZE_MEGA)
161 resize_data = 4 * SIZE_MEGA;
163 resize_data = 2 * SIZE_MEGA;
164 printf("%dMB.\n", resize_data / SIZE_MEGA);
167 free(cfg->map_data[index]);
168 cfg->map_size[index] = resize_data;
169 cfg->map_data[index] = (unsigned char *)malloc(cfg->map_size[index]);
171 printf("%dMB of Z2 Fast RAM configured at $%lx\n", cfg->map_size[index] / SIZE_MEGA, cfg->map_offset[index]);
172 ac_z2_type[ac_z2_pic_count] = ACTYPE_MAPFAST_Z2;
173 ac_z2_index[ac_z2_pic_count] = index;
177 printf("No Z2 Fast RAM configured.\n");
179 index = get_named_mapped_item(cfg, z2_autoconf_id);
183 for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i ++) {
184 // Restore any "zapped" autoconf items so they can be reinitialized if needed.
185 if (cfg->map_id[i] && strcmp(cfg->map_id[i], z2_autoconf_zap_id) == 0) {
186 cfg->map_id[i][0] = z2_autoconf_id[0];
190 index = get_named_mapped_item(cfg, z3_autoconf_id);
193 cfg->map_id[index][0] = '^';
194 printf("%dMB of Z3 Fast RAM configured at $%lx\n", cfg->map_size[index] / SIZE_MEGA, cfg->map_offset[index]);
195 ac_z3_type[ac_z3_pic_count] = ACTYPE_MAPFAST_Z3;
196 ac_z3_index[ac_z3_pic_count] = index;
200 printf("No Z3 Fast RAM configured.\n");
201 index = get_named_mapped_item(cfg, z3_autoconf_id);
204 for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) {
205 if (cfg->map_id[i] && strcmp(cfg->map_id[i], z3_autoconf_zap_id) == 0) {
206 cfg->map_id[i][0] = z3_autoconf_id[0];
210 index = get_named_mapped_item(cfg, "cpu_slot_ram");
212 m68k_add_ram_range((uint32_t)cfg->map_offset[index], (uint32_t)cfg->map_high[index], cfg->map_data[index]);
215 adjust_ranges_amiga(cfg);
220 void setvar_amiga(char *var, char *val) {
224 if (strcmp(var, "enable_rtc_emulation") == 0) {
225 int8_t rtc_enabled = 0;
226 if (!val || strlen(val) == 0)
229 rtc_enabled = get_int(val);
231 if (rtc_enabled != -1) {
232 configure_rtc_emulation_amiga(rtc_enabled);
235 if (strcmp(var, "hdd0") == 0) {
236 if (val && strlen(val) != 0)
237 set_hard_drive_image_file_amiga(0, val);
239 if (strcmp(var, "cdtv") == 0) {
242 if (strcmp(var, "rtctype") == 0) {
243 if (val && strlen(val) != 0) {
244 if (strcmp(val, "msm") == 0) {
245 rtc_type = RTC_TYPE_MSM;
247 rtc_type = RTC_TYPE_RICOH;
252 void handle_reset_amiga(struct emulator_config *cfg) {
256 adjust_ranges_amiga(cfg);
259 void create_platform_amiga(struct platform_config *cfg, char *subsys) {
260 cfg->register_read = handle_register_read_amiga;
261 cfg->register_write = handle_register_write_amiga;
262 cfg->custom_read = custom_read_amiga;
263 cfg->custom_write = custom_write_amiga;
264 cfg->platform_initial_setup = setup_platform_amiga;
265 cfg->handle_reset = handle_reset_amiga;
267 cfg->setvar = setvar_amiga;
268 cfg->id = PLATFORM_AMIGA;
271 cfg->subsys = malloc(strlen(subsys) + 1);
272 strcpy(cfg->subsys, subsys);