]> git.sesse.net Git - pistorm/blob - platforms/amiga/amiga-platform.c
def8f19a7945e0f586c37d8c70f10047c8519117
[pistorm] / platforms / amiga / amiga-platform.c
1 #include "../platforms.h"
2 #include "amiga-autoconf.h"
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6
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);
9
10 extern int ac_done;
11 extern int ac_pic_count;
12 extern int ac_type[AC_PIC_LIMIT];
13 extern int ac_index[AC_PIC_LIMIT];
14
15 const char *z2_autoconf_id = "z2_autoconf_fast";
16 const char *z2_autoconf_zap_id = "^2_autoconf_fast";
17
18 int custom_read_amiga(struct emulator_config *cfg, unsigned int addr, unsigned int *val, unsigned char type) {
19     if (!ac_done && addr >= AC_BASE && addr < AC_BASE + AC_SIZE) {
20         if (ac_pic_count == 0) {
21             ac_done = 1;
22             return -1;
23         }
24
25         if (type == OP_TYPE_BYTE) {
26             //printf("Read from autoconf area.\n");
27             *val = autoconfig_read_memory_8(cfg, addr);
28             return 1;
29         }
30     }
31
32     return -1;
33 }
34
35 int custom_write_amiga(struct emulator_config *cfg, unsigned int addr, unsigned int val, unsigned char type) {
36     if (cfg || addr || val || type) {}
37     if (!ac_done && addr >= AC_BASE && addr < AC_BASE + AC_SIZE) {
38         if (type == OP_TYPE_BYTE) {
39             if (ac_pic_count == 0) {
40                 ac_done = 1;
41                 return -1;
42             }
43
44             //printf("Write to autoconf area.\n");
45             autoconfig_write_memory_8(cfg, addr, val);
46             return 1;
47         }
48     }
49
50     return -1;
51 }
52
53 int setup_platform_amiga(struct emulator_config *cfg) {
54     if (cfg) {}
55     printf("Performing setup for Amiga platform.\n");
56     // Look for Z2 autoconf Fast RAM by id
57     int index = get_named_mapped_item(cfg, "z2_autoconf_fast");
58     more_z2_fast:;
59     if (index != -1) {
60         cfg->map_id[index][0] = '^';
61         int resize_data = 0;
62         if (cfg->map_size[index] > 8 * SIZE_MEGA) {
63             printf("Attempted to configure more than 8MB of Z2 Fast RAM, downsizng to 8MB.\n");
64             resize_data = 8 * SIZE_MEGA;
65         }
66         else if(cfg->map_size[index] != 2 * SIZE_MEGA && cfg->map_size[index] != 4 * SIZE_MEGA && cfg->map_size[index] != 8 * SIZE_MEGA) {
67             printf("Z2 Fast RAM may only provision 2, 4 or 8MB of memory, resizing to ");
68             if (cfg->map_size[index] > 8 * SIZE_MEGA)
69                 resize_data = 8 * SIZE_MEGA;
70             else if (cfg->map_size[index] > 4 * SIZE_MEGA)
71                 resize_data = 4 * SIZE_MEGA;
72             else
73                 resize_data = 2 * SIZE_MEGA;
74             printf("%dMB.\n", resize_data / SIZE_MEGA);
75         }
76         if (resize_data) {
77             free(cfg->map_data[index]);
78             cfg->map_size[index] = resize_data;
79             cfg->map_data[index] = (unsigned char *)malloc(cfg->map_size[index]);
80         }
81         printf("%dMB of Z2 Fast RAM configured at $%lx\n", cfg->map_size[index] / SIZE_MEGA, cfg->map_offset[index]);
82         ac_type[ac_pic_count] = ACTYPE_MAPFAST_Z2;
83         ac_index[ac_pic_count] = index;
84         ac_pic_count++;
85         printf("AAAAHH!\n");
86     }
87     else
88         printf("No Z2 Fast RAM configured.\n");
89     index = get_named_mapped_item(cfg, "z2_autoconf_fast");
90     if (index != -1)
91         goto more_z2_fast;
92     
93     for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i ++) {
94         if (cfg->map_id[i] && strcmp(cfg->map_id[i], z2_autoconf_zap_id) == 0) {
95             cfg->map_id[i][0] = 'z';
96         }
97     }
98     
99     return 0;
100 }
101
102 void setvar_amiga(char *var, char *val) {
103     if (var || val) {}
104 }
105
106 void create_platform_amiga(struct platform_config *cfg, char *subsys) {
107     cfg->register_read = handle_register_read_amiga;
108     cfg->register_write = handle_register_write_amiga;
109     cfg->custom_read = custom_read_amiga;
110     cfg->custom_write = custom_write_amiga;
111     cfg->platform_initial_setup = setup_platform_amiga;
112
113     cfg->setvar = setvar_amiga;
114
115     if (subsys) {
116         cfg->subsys = malloc(strlen(subsys) + 1);
117         strcpy(cfg->subsys, subsys);
118     }
119 }