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];
21 char *z2_autoconf_id = "z2_autoconf_fast";
22 char *z2_autoconf_zap_id = "^2_autoconf_fast";
23 char *z3_autoconf_id = "z3_autoconf_fast";
24 char *z3_autoconf_zap_id = "^3_autoconf_fast";
26 extern const char *op_type_names[OP_TYPE_NUM];
28 int custom_read_amiga(struct emulator_config *cfg, unsigned int addr, unsigned int *val, unsigned char type) {
29 if (!ac_z2_done && addr >= AC_Z2_BASE && addr < AC_Z2_BASE + AC_SIZE) {
30 if (ac_z2_pic_count == 0) {
35 if (type == OP_TYPE_BYTE) {
36 *val = autoconfig_read_memory_8(cfg, addr);
40 if (!ac_z3_done && addr >= AC_Z3_BASE && addr < AC_Z3_BASE + AC_SIZE) {
41 if (ac_z3_pic_count == 0) {
46 if (type == OP_TYPE_BYTE) {
47 *val = autoconfig_read_memory_z3_8(cfg, addr);
51 printf("Unexpected %s read from Z3 autoconf addr %.X\n", op_type_names[type], addr - AC_Z3_BASE);
59 int custom_write_amiga(struct emulator_config *cfg, unsigned int addr, unsigned int val, unsigned char type) {
60 if (!ac_z2_done && addr >= AC_Z2_BASE && addr < AC_Z2_BASE + AC_SIZE) {
61 if (type == OP_TYPE_BYTE) {
62 if (ac_z2_pic_count == 0) {
67 printf("Write to Z2 autoconf area.\n");
68 autoconfig_write_memory_8(cfg, addr, val);
73 if (!ac_z3_done && addr >= AC_Z3_BASE && addr < AC_Z3_BASE + AC_SIZE) {
74 if (type == OP_TYPE_BYTE) {
75 if (ac_z3_pic_count == 0) {
80 //printf("Write to autoconf area.\n");
81 autoconfig_write_memory_z3_8(cfg, addr, val);
84 else if (type == OP_TYPE_WORD) {
85 autoconfig_write_memory_z3_16(cfg, addr, val);
89 printf("Unexpected %s write to Z3 autoconf addr %.X\n", op_type_names[type], addr - AC_Z3_BASE);
97 int setup_platform_amiga(struct emulator_config *cfg) {
99 printf("Performing setup for Amiga platform.\n");
100 // Look for Z2 autoconf Fast RAM by id
101 int index = get_named_mapped_item(cfg, z2_autoconf_id);
104 // "Zap" config items as they are processed.
105 cfg->map_id[index][0] = '^';
107 if (cfg->map_size[index] > 8 * SIZE_MEGA) {
108 printf("Attempted to configure more than 8MB of Z2 Fast RAM, downsizng to 8MB.\n");
109 resize_data = 8 * SIZE_MEGA;
111 else if(cfg->map_size[index] != 2 * SIZE_MEGA && cfg->map_size[index] != 4 * SIZE_MEGA && cfg->map_size[index] != 8 * SIZE_MEGA) {
112 printf("Z2 Fast RAM may only provision 2, 4 or 8MB of memory, resizing to ");
113 if (cfg->map_size[index] > 8 * SIZE_MEGA)
114 resize_data = 8 * SIZE_MEGA;
115 else if (cfg->map_size[index] > 4 * SIZE_MEGA)
116 resize_data = 4 * SIZE_MEGA;
118 resize_data = 2 * SIZE_MEGA;
119 printf("%dMB.\n", resize_data / SIZE_MEGA);
122 free(cfg->map_data[index]);
123 cfg->map_size[index] = resize_data;
124 cfg->map_data[index] = (unsigned char *)malloc(cfg->map_size[index]);
126 printf("%dMB of Z2 Fast RAM configured at $%lx\n", cfg->map_size[index] / SIZE_MEGA, cfg->map_offset[index]);
127 ac_z2_type[ac_z2_pic_count] = ACTYPE_MAPFAST_Z2;
128 ac_z2_index[ac_z2_pic_count] = index;
132 printf("No Z2 Fast RAM configured.\n");
134 index = get_named_mapped_item(cfg, z2_autoconf_id);
138 for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i ++) {
139 // Restore any "zapped" autoconf items so they can be reinitialized if needed.
140 if (cfg->map_id[i] && strcmp(cfg->map_id[i], z2_autoconf_zap_id) == 0) {
141 cfg->map_id[i][0] = z2_autoconf_id[0];
145 index = get_named_mapped_item(cfg, z3_autoconf_id);
148 cfg->map_id[index][0] = '^';
149 printf("%dMB of Z3 Fast RAM configured at $%lx\n", cfg->map_size[index] / SIZE_MEGA, cfg->map_offset[index]);
150 ac_z3_type[ac_z3_pic_count] = ACTYPE_MAPFAST_Z3;
151 ac_z3_index[ac_z3_pic_count] = index;
155 printf("No Z3 Fast RAM configured.\n");
156 index = get_named_mapped_item(cfg, z3_autoconf_id);
159 for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i ++) {
160 if (cfg->map_id[i] && strcmp(cfg->map_id[i], z3_autoconf_zap_id) == 0) {
161 cfg->map_id[i][0] = z3_autoconf_id[0];
168 void setvar_amiga(char *var, char *val) {
172 if (strcmp(var, "enable_rtc_emulation") == 0) {
173 int8_t rtc_enabled = 0;
174 if (!val || strlen(val) == 0)
177 rtc_enabled = get_int(val);
179 if (rtc_enabled != -1) {
180 configure_rtc_emulation_amiga(rtc_enabled);
183 if (strcmp(var, "hdd0") == 0) {
184 if (val && strlen(val) != 0)
185 set_hard_drive_image_file_amiga(0, val);
189 void create_platform_amiga(struct platform_config *cfg, char *subsys) {
190 cfg->register_read = handle_register_read_amiga;
191 cfg->register_write = handle_register_write_amiga;
192 cfg->custom_read = custom_read_amiga;
193 cfg->custom_write = custom_write_amiga;
194 cfg->platform_initial_setup = setup_platform_amiga;
196 cfg->setvar = setvar_amiga;
199 cfg->subsys = malloc(strlen(subsys) + 1);
200 strcpy(cfg->subsys, subsys);