1 // SPDX-License-Identifier: MIT
7 #include "platforms/platforms.h"
8 #include "platforms/shared/rtc.h"
10 //#define DEBUG_MAC_PLATFORM
12 #ifdef DEBUG_MAC_PLATFORM
18 #define min(a, b) (a < b) ? a : b
19 #define max(a, b) (a > b) ? a : b
21 extern void stop_cpu_emulation(uint8_t disasm_cur);
23 uint8_t iscsi_enabled;
25 extern int kb_hook_enabled;
26 extern int mouse_hook_enabled;
27 extern unsigned int ovl;
29 void adjust_ranges_mac68k(struct emulator_config *cfg) {
35 // Set up the min/max ranges for mapped reads/writes
36 for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) {
37 if (cfg->map_type[i] != MAPTYPE_NONE) {
38 if ((cfg->map_offset[i] != 0 && cfg->map_offset[i] < cfg->mapped_low) || cfg->mapped_low == 0)
39 cfg->mapped_low = cfg->map_offset[i];
40 if (cfg->map_offset[i] + cfg->map_size[i] > cfg->mapped_high)
41 cfg->mapped_high = cfg->map_offset[i] + cfg->map_size[i];
45 printf("[MAC68K] Platform custom range: %.8X-%.8X\n", cfg->custom_low, cfg->custom_high);
46 printf("[MAC68K] Platform mapped range: %.8X-%.8X\n", cfg->mapped_low, cfg->mapped_high);
50 int setup_platform_mac68k(struct emulator_config *cfg) {
51 printf("Performing setup for Mac68k platform.\n");
53 if (strlen(cfg->platform->subsys)) {
54 printf("Sub system %sd specified, but no handler is available for this.\n", cfg->platform->subsys);
57 printf("No sub system specified.\n");
59 handle_ovl_mappings_mac68k(cfg);
64 #define CHKVAR(a) (strcmp(var, a) == 0)
66 void setvar_mac68k(struct emulator_config *cfg, char *var, char *val) {
70 // FIXME: Silence unused variable warnings.
71 if (var || cfg || val) {}
73 if (CHKVAR("iscsi") && !iscsi_enabled) {
74 printf("[MAC68K] iSCSI Interface Enabled... well, not really.\n");
77 //adjust_ranges_mac68k(cfg);
81 void handle_ovl_mappings_mac68k(struct emulator_config *cfg) {
84 index = get_named_mapped_item(cfg, "sysrom");
86 cfg->map_offset[index] = (ovl) ? 0x0 : 0x400000;
87 cfg->map_high[index] = cfg->map_size[index];
88 m68k_remove_range(cfg->map_data[index]);
89 m68k_add_rom_range((uint32_t)cfg->map_offset[index], (uint32_t)cfg->map_high[index], cfg->map_data[index]);
90 printf("[MAC68K] Added memory mapping for Mac68k System ROM.\n");
92 printf ("[MAC68K] No sysrom mapping found. If you intended to memory map a system ROM, make sure it has the correct ID.\n");
94 index = get_named_mapped_item(cfg, "sysram");
96 cfg->map_offset[index] = (ovl) ? 0x400000 : 0x0;
97 cfg->map_high[index] = cfg->map_size[index];
98 m68k_remove_range(cfg->map_data[index]);
99 m68k_add_ram_range((uint32_t)cfg->map_offset[index], (uint32_t)cfg->map_high[index], cfg->map_data[index]);
100 printf("[MAC68K] Added memory mapping for Mac68k System RAM.\n");
102 printf ("[MAC68K] No sysram mapping found. If you intended to memory map a system RAM, make sure it has the correct ID.\n");
105 adjust_ranges_mac68k(cfg);
108 void handle_reset_mac68k(struct emulator_config *cfg) {
109 DEBUG("[MAC68K] Reset handler.\n");
112 //iscsi_refresh_drives();
115 handle_ovl_mappings_mac68k(cfg);
118 void shutdown_platform_mac68k(struct emulator_config *cfg) {
119 printf("[MAC68K] Performing Mac68k platform shutdown.\n");
122 if (cfg->platform->subsys) {
123 free(cfg->platform->subsys);
124 cfg->platform->subsys = NULL;
131 mouse_hook_enabled = 0;
134 printf("[MAC68K] Platform shutdown completed.\n");
137 void create_platform_mac68k(struct platform_config *cfg, char *subsys) {
138 cfg->register_read = NULL;
139 cfg->register_write = NULL;
140 cfg->custom_read = NULL;
141 cfg->custom_write = NULL;
142 cfg->platform_initial_setup = setup_platform_mac68k;
143 cfg->handle_reset = handle_reset_mac68k;
144 cfg->shutdown = shutdown_platform_mac68k;
146 cfg->setvar = setvar_mac68k;
147 cfg->id = PLATFORM_MAC;
150 cfg->subsys = malloc(strlen(subsys) + 1);
151 strcpy(cfg->subsys, subsys);
152 for (unsigned int i = 0; i < strlen(cfg->subsys); i++) {
153 cfg->subsys[i] = tolower(cfg->subsys[i]);