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 uint32_t ovl_sysrom_pos = 0x400000;
31 void adjust_ranges_mac68k(struct emulator_config *cfg) {
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];
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);
52 int setup_platform_mac68k(struct emulator_config *cfg) {
53 printf("Performing setup for Mac68k platform.\n");
55 if (strlen(cfg->platform->subsys)) {
56 printf("Sub system %sd specified, but no handler is available for this.\n", cfg->platform->subsys);
59 printf("No sub system specified.\n");
61 handle_ovl_mappings_mac68k(cfg);
66 #define CHKVAR(a) (strcmp(var, a) == 0)
68 void setvar_mac68k(struct emulator_config *cfg, char *var, char *val) {
72 // FIXME: Silence unused variable warnings.
73 if (var || cfg || val) {}
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);
80 if (CHKVAR("iscsi") && !iscsi_enabled) {
81 printf("[MAC68K] iSCSI Interface Enabled... well, not really.\n");
84 //adjust_ranges_mac68k(cfg);
88 void handle_ovl_mappings_mac68k(struct emulator_config *cfg) {
91 index = get_named_mapped_item(cfg, "sysrom");
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");
99 printf ("[MAC68K] No sysrom mapping found. If you intended to memory map a system ROM, make sure it has the correct ID.\n");
101 index = get_named_mapped_item(cfg, "sysram");
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");
109 printf ("[MAC68K] No sysram mapping found. If you intended to memory map a system RAM, make sure it has the correct ID.\n");
112 adjust_ranges_mac68k(cfg);
115 void handle_reset_mac68k(struct emulator_config *cfg) {
116 DEBUG("[MAC68K] Reset handler.\n");
119 //iscsi_refresh_drives();
122 handle_ovl_mappings_mac68k(cfg);
125 void shutdown_platform_mac68k(struct emulator_config *cfg) {
126 printf("[MAC68K] Performing Mac68k platform shutdown.\n");
129 if (cfg->platform->subsys) {
130 free(cfg->platform->subsys);
131 cfg->platform->subsys = NULL;
138 mouse_hook_enabled = 0;
141 printf("[MAC68K] Platform shutdown completed.\n");
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;
153 cfg->setvar = setvar_mac68k;
154 cfg->id = PLATFORM_MAC;
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]);