1 #include "../platforms.h"
2 #include "amiga-autoconf.h"
7 int handle_register_read_amiga(unsigned int addr, unsigned char type, unsigned int *val);
8 int handle_register_write_amiga(unsigned int addr, unsigned int value, unsigned char type);
10 extern int ac_z2_done;
11 extern int ac_z2_pic_count;
12 extern int ac_z2_type[AC_PIC_LIMIT];
13 extern int ac_z2_index[AC_PIC_LIMIT];
15 extern int ac_z3_pic_count;
16 extern int ac_z3_done;
17 extern int ac_z3_type[AC_PIC_LIMIT];
18 extern int ac_z3_index[AC_PIC_LIMIT];
20 char *z2_autoconf_id = "z2_autoconf_fast";
21 char *z2_autoconf_zap_id = "^2_autoconf_fast";
22 char *z3_autoconf_id = "z3_autoconf_fast";
23 char *z3_autoconf_zap_id = "^3_autoconf_fast";
25 extern const char *op_type_names[OP_TYPE_NUM];
27 int custom_read_amiga(struct emulator_config *cfg, unsigned int addr, unsigned int *val, unsigned char type) {
28 if (!ac_z2_done && addr >= AC_Z2_BASE && addr < AC_Z2_BASE + AC_SIZE) {
29 if (ac_z2_pic_count == 0) {
34 if (type == OP_TYPE_BYTE) {
35 *val = autoconfig_read_memory_8(cfg, addr);
39 if (!ac_z3_done && addr >= AC_Z3_BASE && addr < AC_Z3_BASE + AC_SIZE) {
40 if (ac_z3_pic_count == 0) {
45 if (type == OP_TYPE_BYTE) {
46 *val = autoconfig_read_memory_z3_8(cfg, addr);
50 printf("Unexpected %s read from Z3 autoconf addr %.X\n", op_type_names[type], addr - AC_Z3_BASE);
58 int custom_write_amiga(struct emulator_config *cfg, unsigned int addr, unsigned int val, unsigned char type) {
59 if (!ac_z2_done && addr >= AC_Z2_BASE && addr < AC_Z2_BASE + AC_SIZE) {
60 if (type == OP_TYPE_BYTE) {
61 if (ac_z2_pic_count == 0) {
66 printf("Write to Z2 autoconf area.\n");
67 autoconfig_write_memory_8(cfg, addr, val);
72 if (!ac_z3_done && addr >= AC_Z3_BASE && addr < AC_Z3_BASE + AC_SIZE) {
73 if (type == OP_TYPE_BYTE) {
74 if (ac_z3_pic_count == 0) {
79 //printf("Write to autoconf area.\n");
80 autoconfig_write_memory_z3_8(cfg, addr, val);
83 else if (type == OP_TYPE_WORD) {
84 autoconfig_write_memory_z3_16(cfg, addr, val);
88 printf("Unexpected %s write to Z3 autoconf addr %.X\n", op_type_names[type], addr - AC_Z3_BASE);
96 int setup_platform_amiga(struct emulator_config *cfg) {
98 printf("Performing setup for Amiga platform.\n");
99 // Look for Z2 autoconf Fast RAM by id
100 int index = get_named_mapped_item(cfg, z2_autoconf_id);
103 // "Zap" config items as they are processed.
104 cfg->map_id[index][0] = '^';
106 if (cfg->map_size[index] > 8 * SIZE_MEGA) {
107 printf("Attempted to configure more than 8MB of Z2 Fast RAM, downsizng to 8MB.\n");
108 resize_data = 8 * SIZE_MEGA;
110 else if(cfg->map_size[index] != 2 * SIZE_MEGA && cfg->map_size[index] != 4 * SIZE_MEGA && cfg->map_size[index] != 8 * SIZE_MEGA) {
111 printf("Z2 Fast RAM may only provision 2, 4 or 8MB of memory, resizing to ");
112 if (cfg->map_size[index] > 8 * SIZE_MEGA)
113 resize_data = 8 * SIZE_MEGA;
114 else if (cfg->map_size[index] > 4 * SIZE_MEGA)
115 resize_data = 4 * SIZE_MEGA;
117 resize_data = 2 * SIZE_MEGA;
118 printf("%dMB.\n", resize_data / SIZE_MEGA);
121 free(cfg->map_data[index]);
122 cfg->map_size[index] = resize_data;
123 cfg->map_data[index] = (unsigned char *)malloc(cfg->map_size[index]);
125 printf("%dMB of Z2 Fast RAM configured at $%lx\n", cfg->map_size[index] / SIZE_MEGA, cfg->map_offset[index]);
126 ac_z2_type[ac_z2_pic_count] = ACTYPE_MAPFAST_Z2;
127 ac_z2_index[ac_z2_pic_count] = index;
131 printf("No Z2 Fast RAM configured.\n");
133 index = get_named_mapped_item(cfg, z2_autoconf_id);
137 for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i ++) {
138 // Restore any "zapped" autoconf items so they can be reinitialized if needed.
139 if (cfg->map_id[i] && strcmp(cfg->map_id[i], z2_autoconf_zap_id) == 0) {
140 cfg->map_id[i][0] = z2_autoconf_id[0];
144 index = get_named_mapped_item(cfg, z3_autoconf_id);
147 cfg->map_id[index][0] = '^';
148 printf("%dMB of Z3 Fast RAM configured at $%lx\n", cfg->map_size[index] / SIZE_MEGA, cfg->map_offset[index]);
149 ac_z3_type[ac_z3_pic_count] = ACTYPE_MAPFAST_Z3;
150 ac_z3_index[ac_z3_pic_count] = index;
154 printf("No Z3 Fast RAM configured.\n");
155 index = get_named_mapped_item(cfg, z3_autoconf_id);
158 for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i ++) {
159 if (cfg->map_id[i] && strcmp(cfg->map_id[i], z3_autoconf_zap_id) == 0) {
160 cfg->map_id[i][0] = z3_autoconf_id[0];
167 void setvar_amiga(char *var, char *val) {
171 void create_platform_amiga(struct platform_config *cfg, char *subsys) {
172 cfg->register_read = handle_register_read_amiga;
173 cfg->register_write = handle_register_write_amiga;
174 cfg->custom_read = custom_read_amiga;
175 cfg->custom_write = custom_write_amiga;
176 cfg->platform_initial_setup = setup_platform_amiga;
178 cfg->setvar = setvar_amiga;
181 cfg->subsys = malloc(strlen(subsys) + 1);
182 strcpy(cfg->subsys, subsys);