]> git.sesse.net Git - pistorm/blob - platforms/mac68k/mac68k-platform.c
e750321c89f172e546b4ede8822b3ebe8125389d
[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 void adjust_ranges_mac68k(struct emulator_config *cfg) {
30     cfg->mapped_high = 0;
31     cfg->mapped_low = 0;
32     cfg->custom_high = 0;
33     cfg->custom_low = 0;
34
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];
42         }
43     }
44
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);
47 }
48
49
50 int setup_platform_mac68k(struct emulator_config *cfg) {
51     printf("Performing setup for Mac68k platform.\n");
52
53     if (strlen(cfg->platform->subsys)) {
54         printf("Sub system %sd specified, but no handler is available for this.\n", cfg->platform->subsys);
55     }
56     else
57         printf("No sub system specified.\n");
58
59     handle_ovl_mappings_mac68k(cfg);
60
61     return 0;
62 }
63
64 #define CHKVAR(a) (strcmp(var, a) == 0)
65
66 void setvar_mac68k(struct emulator_config *cfg, char *var, char *val) {
67     if (!var)
68         return;
69
70     // FIXME: Silence unused variable warnings.
71     if (var || cfg || val) {}
72
73     if (CHKVAR("iscsi") && !iscsi_enabled) {
74         printf("[MAC68K] iSCSI Interface Enabled... well, not really.\n");
75         iscsi_enabled = 1;
76         //iscsi_init();
77         //adjust_ranges_mac68k(cfg);
78     }
79 }
80
81 void handle_ovl_mappings_mac68k(struct emulator_config *cfg) {
82     int32_t index = -1;
83
84     index = get_named_mapped_item(cfg, "sysrom");
85     if (index != -1) {
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");
91     } else {
92         printf ("[MAC68K] No sysrom mapping found. If you intended to memory map a system ROM, make sure it has the correct ID.\n");
93     }
94     index = get_named_mapped_item(cfg, "sysram");
95     if (index != -1) {
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");
101     } else {
102         printf ("[MAC68K] No sysram mapping found. If you intended to memory map a system RAM, make sure it has the correct ID.\n");
103     }
104
105     adjust_ranges_mac68k(cfg);
106 }
107
108 void handle_reset_mac68k(struct emulator_config *cfg) {
109     DEBUG("[MAC68K] Reset handler.\n");
110
111     if (iscsi_enabled) {
112         //iscsi_refresh_drives();
113     }
114
115     handle_ovl_mappings_mac68k(cfg);
116 }
117
118 void shutdown_platform_mac68k(struct emulator_config *cfg) {
119     printf("[MAC68K] Performing Mac68k platform shutdown.\n");
120     if (cfg) {}
121
122     if (cfg->platform->subsys) {
123         free(cfg->platform->subsys);
124         cfg->platform->subsys = NULL;
125     }
126     if (iscsi_enabled) {
127         //iscsi_shutdown();
128         iscsi_enabled = 0;
129     }
130
131     mouse_hook_enabled = 0;
132     kb_hook_enabled = 0;
133
134     printf("[MAC68K] Platform shutdown completed.\n");
135 }
136
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;
145
146     cfg->setvar = setvar_mac68k;
147     cfg->id = PLATFORM_MAC;
148
149     if (subsys) {
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]);
154         }
155     }
156 }