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 inline int custom_read_amiga(struct emulator_config *cfg, unsigned int addr, unsigned int *val, unsigned char type) {
30 if (!ac_z2_done && addr >= AC_Z2_BASE && addr < AC_Z2_BASE + AC_SIZE) {
31 if (ac_z2_pic_count == 0) {
36 if (type == OP_TYPE_BYTE) {
37 *val = autoconfig_read_memory_8(cfg, addr);
41 if (!ac_z3_done && addr >= AC_Z3_BASE && addr < AC_Z3_BASE + AC_SIZE) {
42 if (ac_z3_pic_count == 0) {
47 if (type == OP_TYPE_BYTE) {
48 *val = autoconfig_read_memory_z3_8(cfg, addr);
52 printf("Unexpected %s read from Z3 autoconf addr %.X\n", op_type_names[type], addr - AC_Z3_BASE);
60 inline int custom_write_amiga(struct emulator_config *cfg, unsigned int addr, unsigned int val, unsigned char type) {
61 if (!ac_z2_done && addr >= AC_Z2_BASE && addr < AC_Z2_BASE + AC_SIZE) {
62 if (type == OP_TYPE_BYTE) {
63 if (ac_z2_pic_count == 0) {
68 printf("Write to Z2 autoconf area.\n");
69 autoconfig_write_memory_8(cfg, addr, val);
74 if (!ac_z3_done && addr >= AC_Z3_BASE && addr < AC_Z3_BASE + AC_SIZE) {
75 if (type == OP_TYPE_BYTE) {
76 if (ac_z3_pic_count == 0) {
81 //printf("Write to autoconf area.\n");
82 autoconfig_write_memory_z3_8(cfg, addr, val);
85 else if (type == OP_TYPE_WORD) {
86 autoconfig_write_memory_z3_16(cfg, addr, val);
90 printf("Unexpected %s write to Z3 autoconf addr %.X\n", op_type_names[type], addr - AC_Z3_BASE);
98 int setup_platform_amiga(struct emulator_config *cfg) {
100 printf("Performing setup for Amiga platform.\n");
101 // Look for Z2 autoconf Fast RAM by id
102 int index = get_named_mapped_item(cfg, z2_autoconf_id);
105 // "Zap" config items as they are processed.
106 cfg->map_id[index][0] = '^';
108 if (cfg->map_size[index] > 8 * SIZE_MEGA) {
109 printf("Attempted to configure more than 8MB of Z2 Fast RAM, downsizng to 8MB.\n");
110 resize_data = 8 * SIZE_MEGA;
112 else if(cfg->map_size[index] != 2 * SIZE_MEGA && cfg->map_size[index] != 4 * SIZE_MEGA && cfg->map_size[index] != 8 * SIZE_MEGA) {
113 printf("Z2 Fast RAM may only provision 2, 4 or 8MB of memory, resizing to ");
114 if (cfg->map_size[index] > 8 * SIZE_MEGA)
115 resize_data = 8 * SIZE_MEGA;
116 else if (cfg->map_size[index] > 4 * SIZE_MEGA)
117 resize_data = 4 * SIZE_MEGA;
119 resize_data = 2 * SIZE_MEGA;
120 printf("%dMB.\n", resize_data / SIZE_MEGA);
123 free(cfg->map_data[index]);
124 cfg->map_size[index] = resize_data;
125 cfg->map_data[index] = (unsigned char *)malloc(cfg->map_size[index]);
127 printf("%dMB of Z2 Fast RAM configured at $%lx\n", cfg->map_size[index] / SIZE_MEGA, cfg->map_offset[index]);
128 ac_z2_type[ac_z2_pic_count] = ACTYPE_MAPFAST_Z2;
129 ac_z2_index[ac_z2_pic_count] = index;
133 printf("No Z2 Fast RAM configured.\n");
135 index = get_named_mapped_item(cfg, z2_autoconf_id);
139 for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i ++) {
140 // Restore any "zapped" autoconf items so they can be reinitialized if needed.
141 if (cfg->map_id[i] && strcmp(cfg->map_id[i], z2_autoconf_zap_id) == 0) {
142 cfg->map_id[i][0] = z2_autoconf_id[0];
146 index = get_named_mapped_item(cfg, z3_autoconf_id);
149 cfg->map_id[index][0] = '^';
150 printf("%dMB of Z3 Fast RAM configured at $%lx\n", cfg->map_size[index] / SIZE_MEGA, cfg->map_offset[index]);
151 ac_z3_type[ac_z3_pic_count] = ACTYPE_MAPFAST_Z3;
152 ac_z3_index[ac_z3_pic_count] = index;
156 printf("No Z3 Fast RAM configured.\n");
157 index = get_named_mapped_item(cfg, z3_autoconf_id);
160 for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) {
161 if (cfg->map_id[i] && strcmp(cfg->map_id[i], z3_autoconf_zap_id) == 0) {
162 cfg->map_id[i][0] = z3_autoconf_id[0];
166 // Set up the min/max ranges for mapped reads/writes
167 for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) {
168 if (cfg->map_type[i] != MAPTYPE_NONE) {
169 if ((cfg->map_offset[i] != 0 && cfg->map_offset[i] < cfg->map_low) || cfg->map_low == 0)
170 cfg->map_low = cfg->map_offset[i];
171 if (cfg->map_offset[i] + cfg->map_size[i] > cfg->map_high)
172 cfg->map_high = cfg->map_offset[i] + cfg->map_size[i];
176 if (gayle_emulation_enabled) {
177 cfg->custom_low = GAYLEBASE;
178 cfg->custom_high = GAYLEBASE + GAYLESIZE;
181 printf("Platform custom range: %.8X-%.8X\n", cfg->custom_low, cfg->custom_high);
182 printf("Platform mapped range: %.8X-%.8X\n", cfg->map_low, cfg->map_high);
187 void setvar_amiga(char *var, char *val) {
191 if (strcmp(var, "enable_rtc_emulation") == 0) {
192 int8_t rtc_enabled = 0;
193 if (!val || strlen(val) == 0)
196 rtc_enabled = get_int(val);
198 if (rtc_enabled != -1) {
199 configure_rtc_emulation_amiga(rtc_enabled);
202 if (strcmp(var, "hdd0") == 0) {
203 if (val && strlen(val) != 0)
204 set_hard_drive_image_file_amiga(0, val);
208 void create_platform_amiga(struct platform_config *cfg, char *subsys) {
209 cfg->register_read = handle_register_read_amiga;
210 cfg->register_write = handle_register_write_amiga;
211 cfg->custom_read = custom_read_amiga;
212 cfg->custom_write = custom_write_amiga;
213 cfg->platform_initial_setup = setup_platform_amiga;
215 cfg->setvar = setvar_amiga;
216 cfg->id = PLATFORM_AMIGA;
219 cfg->subsys = malloc(strlen(subsys) + 1);
220 strcpy(cfg->subsys, subsys);