]> git.sesse.net Git - pistorm/blob - platforms/mac68k/mac68k-platform.c
Add System ROM pos setvar to Mac platform
[pistorm] / platforms / mac68k / mac68k-platform.c
1 // SPDX-License-Identifier: MIT
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <ctype.h>
7 #include "platforms/platforms.h"
8 #include "platforms/shared/rtc.h"
9
10 //#define DEBUG_MAC_PLATFORM
11
12 #ifdef DEBUG_MAC_PLATFORM
13 #define DEBUG printf
14 #else
15 #define DEBUG(...)
16 #endif
17
18 #define min(a, b) (a < b) ? a : b
19 #define max(a, b) (a > b) ? a : b
20
21 extern void stop_cpu_emulation(uint8_t disasm_cur);
22
23 uint8_t iscsi_enabled;
24
25 extern int kb_hook_enabled;
26 extern int mouse_hook_enabled;
27 extern unsigned int ovl;
28
29 uint32_t ovl_sysrom_pos = 0x400000;
30
31 void adjust_ranges_mac68k(struct emulator_config *cfg) {
32     cfg->mapped_high = 0;
33     cfg->mapped_low = 0;
34     cfg->custom_high = 0;
35     cfg->custom_low = 0;
36
37     // Set up the min/max ranges for mapped reads/writes
38     for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) {
39         if (cfg->map_type[i] != MAPTYPE_NONE) {
40             if ((cfg->map_offset[i] != 0 && cfg->map_offset[i] < cfg->mapped_low) || cfg->mapped_low == 0)
41                 cfg->mapped_low = cfg->map_offset[i];
42             if (cfg->map_offset[i] + cfg->map_size[i] > cfg->mapped_high)
43                 cfg->mapped_high = cfg->map_offset[i] + cfg->map_size[i];
44         }
45     }
46
47     printf("[MAC68K] Platform custom range: %.8X-%.8X\n", cfg->custom_low, cfg->custom_high);
48     printf("[MAC68K] Platform mapped range: %.8X-%.8X\n", cfg->mapped_low, cfg->mapped_high);
49 }
50
51
52 int setup_platform_mac68k(struct emulator_config *cfg) {
53     printf("Performing setup for Mac68k platform.\n");
54
55     if (strlen(cfg->platform->subsys)) {
56         printf("Sub system %sd specified, but no handler is available for this.\n", cfg->platform->subsys);
57     }
58     else
59         printf("No sub system specified.\n");
60
61     handle_ovl_mappings_mac68k(cfg);
62
63     return 0;
64 }
65
66 #define CHKVAR(a) (strcmp(var, a) == 0)
67
68 void setvar_mac68k(struct emulator_config *cfg, char *var, char *val) {
69     if (!var)
70         return;
71
72     // FIXME: Silence unused variable warnings.
73     if (var || cfg || val) {}
74
75     if (CHKVAR("sysrom_pos") && val) {
76         ovl_sysrom_pos = get_int(val);
77         printf("[MAC68K] System ROM/RAM OVL position set to %.8X\n", ovl_sysrom_pos);
78     }
79
80     if (CHKVAR("iscsi") && !iscsi_enabled) {
81         printf("[MAC68K] iSCSI Interface Enabled... well, not really.\n");
82         iscsi_enabled = 1;
83         //iscsi_init();
84         //adjust_ranges_mac68k(cfg);
85     }
86 }
87
88 void handle_ovl_mappings_mac68k(struct emulator_config *cfg) {
89     int32_t index = -1;
90
91     index = get_named_mapped_item(cfg, "sysrom");
92     if (index != -1) {
93         cfg->map_offset[index] = (ovl) ? 0x0 : ovl_sysrom_pos;
94         cfg->map_high[index] = cfg->map_size[index];
95         m68k_remove_range(cfg->map_data[index]);
96         m68k_add_rom_range((uint32_t)cfg->map_offset[index], (uint32_t)cfg->map_high[index], cfg->map_data[index]);
97         printf("[MAC68K] Added memory mapping for Mac68k System ROM.\n");
98     } else {
99         printf ("[MAC68K] No sysrom mapping found. If you intended to memory map a system ROM, make sure it has the correct ID.\n");
100     }
101     index = get_named_mapped_item(cfg, "sysram");
102     if (index != -1) {
103         cfg->map_offset[index] = (ovl) ? ovl_sysrom_pos : 0x0;
104         cfg->map_high[index] = cfg->map_size[index];
105         m68k_remove_range(cfg->map_data[index]);
106         m68k_add_ram_range((uint32_t)cfg->map_offset[index], (uint32_t)cfg->map_high[index], cfg->map_data[index]);
107         printf("[MAC68K] Added memory mapping for Mac68k System RAM.\n");
108     } else {
109         printf ("[MAC68K] No sysram mapping found. If you intended to memory map a system RAM, make sure it has the correct ID.\n");
110     }
111
112     adjust_ranges_mac68k(cfg);
113 }
114
115 void handle_reset_mac68k(struct emulator_config *cfg) {
116     DEBUG("[MAC68K] Reset handler.\n");
117
118     if (iscsi_enabled) {
119         //iscsi_refresh_drives();
120     }
121
122     handle_ovl_mappings_mac68k(cfg);
123 }
124
125 void shutdown_platform_mac68k(struct emulator_config *cfg) {
126     printf("[MAC68K] Performing Mac68k platform shutdown.\n");
127     if (cfg) {}
128
129     if (cfg->platform->subsys) {
130         free(cfg->platform->subsys);
131         cfg->platform->subsys = NULL;
132     }
133     if (iscsi_enabled) {
134         //iscsi_shutdown();
135         iscsi_enabled = 0;
136     }
137
138     mouse_hook_enabled = 0;
139     kb_hook_enabled = 0;
140
141     printf("[MAC68K] Platform shutdown completed.\n");
142 }
143
144 void create_platform_mac68k(struct platform_config *cfg, char *subsys) {
145     cfg->register_read = NULL;
146     cfg->register_write = NULL;
147     cfg->custom_read = NULL;
148     cfg->custom_write = NULL;
149     cfg->platform_initial_setup = setup_platform_mac68k;
150     cfg->handle_reset = handle_reset_mac68k;
151     cfg->shutdown = shutdown_platform_mac68k;
152
153     cfg->setvar = setvar_mac68k;
154     cfg->id = PLATFORM_MAC;
155
156     if (subsys) {
157         cfg->subsys = malloc(strlen(subsys) + 1);
158         strcpy(cfg->subsys, subsys);
159         for (unsigned int i = 0; i < strlen(cfg->subsys); i++) {
160             cfg->subsys[i] = tolower(cfg->subsys[i]);
161         }
162     }
163 }