]> git.sesse.net Git - pistorm/commitdiff
Add some more Mac68k handling stuff
authorbeeanyew <beeanyew@gmail.com>
Wed, 23 Jun 2021 02:42:58 +0000 (04:42 +0200)
committerbeeanyew <beeanyew@gmail.com>
Wed, 23 Jun 2021 02:42:58 +0000 (04:42 +0200)
Makefile
emulator.c
m68k.h
m68kcpu.c
m68kmmu.h
mac68k.cfg
platforms/mac68k/mac68k-platform.c [new file with mode: 0644]
platforms/platforms.c
platforms/platforms.h

index 942b4a901eb215fe7620ecd292b03fe63a3875ec..ed7fbf60074be6693e108203e864e62978707697 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,6 +10,7 @@ MAINFILES        = emulator.c \
        platforms/amiga/amiga-autoconf.c \
        platforms/amiga/amiga-platform.c \
        platforms/amiga/amiga-registers.c \
+       platforms/mac68k/mac68k-platform.c \
        platforms/dummy/dummy-platform.c \
        platforms/dummy/dummy-registers.c \
        platforms/amiga/Gayle.c \
index 4d2fc8a37c8036c5044da7bfa66ce8d520dfecc7..968f52e7bd430c988034566d401d08039c322d37 100644 (file)
@@ -629,13 +629,10 @@ switch_config:
 void cpu_pulse_reset(void) {
        m68ki_cpu_core *state = &m68ki_cpu;
   ps_pulse_reset();
-  if (cfg->platform->handle_reset)
-    cfg->platform->handle_reset(cfg);
 
-  //m68k_write_memory_16(INTENA, 0x7FFF);
   ovl = 1;
-  //m68k_write_memory_8(0xbfe201, 0x0001);  // AMIGA OVL
-  //m68k_write_memory_8(0xbfe001, 0x0001);  // AMIGA OVL high (ROM@0x0)
+  if (cfg->platform->handle_reset)
+    cfg->platform->handle_reset(cfg);
 
        m68k_pulse_reset(state);
 }
@@ -954,9 +951,11 @@ static inline int32_t platform_write_check(uint8_t type, uint32_t addr, uint32_t
           if (val & 0x10 && !ovl) {
               ovl = 1;
               printf("[MAC] OVL on.\n");
+              handle_ovl_mappings_mac68k(cfg);
           } else if (ovl) {
             ovl = 0;
             printf("[MAC] OVL off.\n");
+            handle_ovl_mappings_mac68k(cfg);
           }
           break;
       }
diff --git a/m68k.h b/m68k.h
index a838118ad3a9d9e2219d50125840b79ec12af4b8..ce9e648d7b4ec15c2a56cbc76dca2937fab9bad2 100644 (file)
--- a/m68k.h
+++ b/m68k.h
@@ -212,6 +212,7 @@ void m68k_write_memory_32(unsigned int address, unsigned int value);
 /* PiStorm speed hax */
 void m68k_add_ram_range(uint32_t addr, uint32_t upper, unsigned char *ptr);
 void m68k_add_rom_range(uint32_t addr, uint32_t upper, unsigned char *ptr);
+void m68k_remove_range(unsigned char *ptr);
 void m68k_clear_ranges();
 
 /* Special call to simulate undocumented 68k behavior when move.l with a
index 1068f264440ef2ca82bdc6c2d8935cc7b5c05c3a..b384e2b0730d6ac4f6616994cd118cf1a3247651 100644 (file)
--- a/m68kcpu.c
+++ b/m68kcpu.c
@@ -1316,8 +1316,12 @@ void m68k_add_ram_range(uint32_t addr, uint32_t upper, unsigned char *ptr)
                return;
 
        for (int i = 0; i < m68ki_cpu.write_ranges; i++) {
-               if (m68ki_cpu.write_addr[i] == addr) {
+               if (m68ki_cpu.write_addr[i] == addr || m68ki_cpu.write_data[i] == ptr) {
                        uint8_t changed = 0;
+                       if (m68ki_cpu.write_addr[i] != addr) {
+                               m68ki_cpu.write_addr[i] = addr;
+                               changed = 1;
+                       }
                        if (m68ki_cpu.write_upper[i] != upper) {
                                m68ki_cpu.write_upper[i] = upper;
                                changed = 1;
@@ -1363,8 +1367,12 @@ void m68k_add_rom_range(uint32_t addr, uint32_t upper, unsigned char *ptr)
                return;
 
        for (int i = 0; i < m68ki_cpu.read_ranges; i++) {
-               if (m68ki_cpu.read_addr[i] == addr) {
+               if (m68ki_cpu.read_addr[i] == addr  || m68ki_cpu.read_data[i] == ptr) {
                        uint8_t changed = 0;
+                       if (m68ki_cpu.read_addr[i] != addr) {
+                               m68ki_cpu.read_addr[i] = addr;
+                               changed = 1;
+                       }
                        if (m68ki_cpu.read_upper[i] != upper) {
                                m68ki_cpu.read_upper[i] = upper;
                                changed = 1;
@@ -1392,6 +1400,28 @@ void m68k_add_rom_range(uint32_t addr, uint32_t upper, unsigned char *ptr)
        }
 }
 
+void m68k_remove_range(unsigned char *ptr) {
+       if (!ptr) {
+               return;
+       }
+
+       // FIXME: Replace the 8 with a #define, such as MAX_MUSASHI_RANGES
+       for (int i = 0; i < 8; i++) {
+               if (m68ki_cpu.read_data[i] == ptr) {
+                       m68ki_cpu.read_data[i] = NULL;
+                       m68ki_cpu.read_addr[i] = 0;
+                       m68ki_cpu.read_upper[i] = 0;
+                       printf("[MUSASHI] Unmapped read range %d.\n", i);
+               }
+               if (m68ki_cpu.write_data[i] == ptr) {
+                       m68ki_cpu.write_data[i] = NULL;
+                       m68ki_cpu.write_addr[i] = 0;
+                       m68ki_cpu.write_upper[i] = 0;
+                       printf("[MUSASHI] Unmapped write range %d.\n", i);
+               }
+       }
+}
+
 void m68k_clear_ranges()
 {
        printf("[MUSASHI] Clearing all reads/write memory ranges.\n");
index 364c183c09b7f7ebf8d245d4da0068fd21dfba0a..3a9c6e5e1ae7ab6859cf585f65b9e13cbd63e2ab 100644 (file)
--- a/m68kmmu.h
+++ b/m68kmmu.h
@@ -356,6 +356,9 @@ uint16 pmmu_match_tt(m68ki_cpu_core *state, uint32 addr_in, int fc, uint32 tt, u
 
 void update_descriptor(m68ki_cpu_core *state, uint32 tptr, int type, uint32 entry, int16 rw)
 {
+       // FIXME: Silence unused variable warning
+       if (state) {}
+
        if (type == M68K_MMU_DF_DT_PAGE && !rw &&
                        !(entry & M68K_MMU_DF_MODIFIED) &&
                        !(entry & M68K_MMU_DF_WP))
index 7ff1c7a49e4a1259467dc7b4e8f7b85de803915e..f1ea160e2975721ecf9135bf1812e61349b55fc9 100644 (file)
@@ -3,8 +3,9 @@
 cpu 68EC020
 
 # Map any size ROM to a the (max) 512KB KB system ROM default address with OVL enabled.
+# The id=sysrom and id=sysram for the ROM and WTC RAM are necessary in order for the 68k Mac's OVL to function properly.
 # (From what I could tell, the ROM was mirrored across this entire 512KB space regardless of physical capacity.)
-map type=rom address=0x400000 size=512K file=system.rom ovl=0 id=sysrom
+map type=rom address=0x400000 size=512K file=system.rom id=sysrom
 
 # Map X KB/MB of RAM starting at $0. The type of this RAM map is "wtcram", which is short for Write Through Cache RAM.
 # It appears that the Mac Classic sound/video chips can't write to RAM, only read from it, so this should be sufficient
diff --git a/platforms/mac68k/mac68k-platform.c b/platforms/mac68k/mac68k-platform.c
new file mode 100644 (file)
index 0000000..e750321
--- /dev/null
@@ -0,0 +1,156 @@
+// SPDX-License-Identifier: MIT
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include "platforms/platforms.h"
+#include "platforms/shared/rtc.h"
+
+//#define DEBUG_MAC_PLATFORM
+
+#ifdef DEBUG_MAC_PLATFORM
+#define DEBUG printf
+#else
+#define DEBUG(...)
+#endif
+
+#define min(a, b) (a < b) ? a : b
+#define max(a, b) (a > b) ? a : b
+
+extern void stop_cpu_emulation(uint8_t disasm_cur);
+
+uint8_t iscsi_enabled;
+
+extern int kb_hook_enabled;
+extern int mouse_hook_enabled;
+extern unsigned int ovl;
+
+void adjust_ranges_mac68k(struct emulator_config *cfg) {
+    cfg->mapped_high = 0;
+    cfg->mapped_low = 0;
+    cfg->custom_high = 0;
+    cfg->custom_low = 0;
+
+    // Set up the min/max ranges for mapped reads/writes
+    for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) {
+        if (cfg->map_type[i] != MAPTYPE_NONE) {
+            if ((cfg->map_offset[i] != 0 && cfg->map_offset[i] < cfg->mapped_low) || cfg->mapped_low == 0)
+                cfg->mapped_low = cfg->map_offset[i];
+            if (cfg->map_offset[i] + cfg->map_size[i] > cfg->mapped_high)
+                cfg->mapped_high = cfg->map_offset[i] + cfg->map_size[i];
+        }
+    }
+
+    printf("[MAC68K] Platform custom range: %.8X-%.8X\n", cfg->custom_low, cfg->custom_high);
+    printf("[MAC68K] Platform mapped range: %.8X-%.8X\n", cfg->mapped_low, cfg->mapped_high);
+}
+
+
+int setup_platform_mac68k(struct emulator_config *cfg) {
+    printf("Performing setup for Mac68k platform.\n");
+
+    if (strlen(cfg->platform->subsys)) {
+        printf("Sub system %sd specified, but no handler is available for this.\n", cfg->platform->subsys);
+    }
+    else
+        printf("No sub system specified.\n");
+
+    handle_ovl_mappings_mac68k(cfg);
+
+    return 0;
+}
+
+#define CHKVAR(a) (strcmp(var, a) == 0)
+
+void setvar_mac68k(struct emulator_config *cfg, char *var, char *val) {
+    if (!var)
+        return;
+
+    // FIXME: Silence unused variable warnings.
+    if (var || cfg || val) {}
+
+    if (CHKVAR("iscsi") && !iscsi_enabled) {
+        printf("[MAC68K] iSCSI Interface Enabled... well, not really.\n");
+        iscsi_enabled = 1;
+        //iscsi_init();
+        //adjust_ranges_mac68k(cfg);
+    }
+}
+
+void handle_ovl_mappings_mac68k(struct emulator_config *cfg) {
+    int32_t index = -1;
+
+    index = get_named_mapped_item(cfg, "sysrom");
+    if (index != -1) {
+        cfg->map_offset[index] = (ovl) ? 0x0 : 0x400000;
+        cfg->map_high[index] = cfg->map_size[index];
+        m68k_remove_range(cfg->map_data[index]);
+        m68k_add_rom_range((uint32_t)cfg->map_offset[index], (uint32_t)cfg->map_high[index], cfg->map_data[index]);
+        printf("[MAC68K] Added memory mapping for Mac68k System ROM.\n");
+    } else {
+        printf ("[MAC68K] No sysrom mapping found. If you intended to memory map a system ROM, make sure it has the correct ID.\n");
+    }
+    index = get_named_mapped_item(cfg, "sysram");
+    if (index != -1) {
+        cfg->map_offset[index] = (ovl) ? 0x400000 : 0x0;
+        cfg->map_high[index] = cfg->map_size[index];
+        m68k_remove_range(cfg->map_data[index]);
+        m68k_add_ram_range((uint32_t)cfg->map_offset[index], (uint32_t)cfg->map_high[index], cfg->map_data[index]);
+        printf("[MAC68K] Added memory mapping for Mac68k System RAM.\n");
+    } else {
+        printf ("[MAC68K] No sysram mapping found. If you intended to memory map a system RAM, make sure it has the correct ID.\n");
+    }
+
+    adjust_ranges_mac68k(cfg);
+}
+
+void handle_reset_mac68k(struct emulator_config *cfg) {
+    DEBUG("[MAC68K] Reset handler.\n");
+
+    if (iscsi_enabled) {
+        //iscsi_refresh_drives();
+    }
+
+    handle_ovl_mappings_mac68k(cfg);
+}
+
+void shutdown_platform_mac68k(struct emulator_config *cfg) {
+    printf("[MAC68K] Performing Mac68k platform shutdown.\n");
+    if (cfg) {}
+
+    if (cfg->platform->subsys) {
+        free(cfg->platform->subsys);
+        cfg->platform->subsys = NULL;
+    }
+    if (iscsi_enabled) {
+        //iscsi_shutdown();
+        iscsi_enabled = 0;
+    }
+
+    mouse_hook_enabled = 0;
+    kb_hook_enabled = 0;
+
+    printf("[MAC68K] Platform shutdown completed.\n");
+}
+
+void create_platform_mac68k(struct platform_config *cfg, char *subsys) {
+    cfg->register_read = NULL;
+    cfg->register_write = NULL;
+    cfg->custom_read = NULL;
+    cfg->custom_write = NULL;
+    cfg->platform_initial_setup = setup_platform_mac68k;
+    cfg->handle_reset = handle_reset_mac68k;
+    cfg->shutdown = shutdown_platform_mac68k;
+
+    cfg->setvar = setvar_mac68k;
+    cfg->id = PLATFORM_MAC;
+
+    if (subsys) {
+        cfg->subsys = malloc(strlen(subsys) + 1);
+        strcpy(cfg->subsys, subsys);
+        for (unsigned int i = 0; i < strlen(cfg->subsys); i++) {
+            cfg->subsys[i] = tolower(cfg->subsys[i]);
+        }
+    }
+}
index 4d301b4f085edefcc47a19f227624f49b1db2f04..a272de8948addf9543d8cfbee70337d002827960 100644 (file)
@@ -24,6 +24,7 @@ int get_platform_index(char *name) {
 }
 
 void create_platform_amiga(struct platform_config *cfg, char *subsys);
+void create_platform_mac68k(struct platform_config *cfg, char *subsys);
 void create_platform_dummy(struct platform_config *cfg, char *subsys);
 
 struct platform_config *make_platform_config(char *name, char *subsys) {
@@ -50,8 +51,10 @@ struct platform_config *make_platform_config(char *name, char *subsys) {
         case PLATFORM_AMIGA:
             create_platform_amiga(cfg, subsys);
             break;
-        case PLATFORM_NONE:
         case PLATFORM_MAC:
+            create_platform_mac68k(cfg, subsys);
+            break;
+        case PLATFORM_NONE:
         case PLATFORM_X68000:
         default:
             create_platform_dummy(cfg, subsys);
index a88bda81c0df169d5b6178917d067c0d2145b4bb..6cd93e27c004c99a93a117fa8f56a49353d5047f 100644 (file)
@@ -14,3 +14,5 @@ struct platform_config *make_platform_config(char *name, char *subsys);
 
 void dump_range_to_file(uint32_t addr, uint32_t size, char *filename);
 uint8_t *dump_range_to_memory(uint32_t addr, uint32_t size);
+
+void handle_ovl_mappings_mac68k(struct emulator_config *cfg);