-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenesis-plus-gx.patch
195 lines (186 loc) · 6.47 KB
/
genesis-plus-gx.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
commit bc4f11c187d3281c19310034b9ddc7578740f3d9
Author: Joey Parrish <[email protected]>
Date: Sun Oct 13 19:42:58 2024 -0700
Emulate Kinetoscope hardware in Genesis-Plus-GX
Patch based on https://github.com/libretro/Genesis-Plus-GX revision 7de0f0b6
diff --git a/LICENSE.txt b/LICENSE.txt
index eba63d1..3d1fd37 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -879,3 +879,30 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+
+
+----------------------------------------------------------------------------------------
+
+Kinetoscope emulation adapter is distributed under the following license:
+
+MIT License
+
+Copyright (c) 2024 Joey Parrish
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/Makefile.libretro b/Makefile.libretro
index 0d870ef..d6bd5a0 100644
--- a/Makefile.libretro
+++ b/Makefile.libretro
@@ -425,6 +425,7 @@ else ifeq ($(platform), libnx)
else ifeq ($(platform), emscripten)
TARGET := $(TARGET_NAME)_libretro_$(platform).bc
ENDIANNESS_DEFINES := -DLSB_FIRST -DALIGN_LONG -DBYTE_ORDER=LITTLE_ENDIAN -DHAVE_ZLIB
+ LDFLAGS += -s FETCH=1
STATIC_LINKING = 1
# RS90
@@ -881,6 +882,9 @@ all: $(TARGET)
%.o: %.c
$(CC) $(OBJOUT)$@ -c $< $(CFLAGS) $(LIBRETRO_CFLAGS)
+core/cart_hw/kinetoscope_adapter.o: core/cart_hw/kinetoscope_adapter.c core/kinetoscope/emulator-patches/kinetoscope.c core/kinetoscope/emulator-patches/fetch.c
+ $(CC) $(OBJOUT)$@ -c $< $(CFLAGS) $(LIBRETRO_CFLAGS)
+
$(TARGET): $(OBJECTS)
ifeq ($(STATIC_LINKING), 1)
$(AR) rcs $@ $(OBJECTS)
diff --git a/core/cart_hw/kinetoscope_adapter.c b/core/cart_hw/kinetoscope_adapter.c
new file mode 100644
index 0000000..e94a1b4
--- /dev/null
+++ b/core/cart_hw/kinetoscope_adapter.c
@@ -0,0 +1,45 @@
+// Kinetoscope: A Sega Genesis Video Player
+//
+// Copyright (c) 2024 Joey Parrish
+//
+// See MIT License in LICENSE.txt
+
+// Adapter between Kinetoscope emulation and Genesis Plus GX.
+
+#include "kinetoscope/emulator-patches/kinetoscope.c"
+
+#include "kinetoscope_adapter.h"
+#include "shared.h"
+
+void kinetoscope_adapter_reset() {
+ uint8_t* sram_buffer = (uint8_t*)kinetoscope_init();
+
+ // 0x20 here represents 2MB in the map. Each "unit" of the memory map is
+ // 64kB. We map each of these units to the corresponding offset in
+ // sram_buffer.
+ for (int i = 0x20; i < 0x40; ++i) {
+ m68k.memory_map[i].base = sram_buffer;
+
+ m68k.memory_map[i].read8 = NULL;
+ m68k.memory_map[i].read16 = NULL;
+ m68k.memory_map[i].write8 = m68k_unused_8_w;
+ m68k.memory_map[i].write16 = m68k_unused_16_w;
+
+ zbank_memory_map[i].read = NULL;
+ zbank_memory_map[i].write = zbank_unused_w;
+
+ sram_buffer += (64 << 10); // 64kB
+ }
+}
+
+void kinetoscope_adapter_write(unsigned int address, unsigned int data) {
+ // The Kinetoscope emulator expects only the low 8 bits of this address.
+ address &= 0xff;
+ kinetoscope_write_16((uint32_t)address, NULL, (uint16_t)data);
+}
+
+unsigned int kinetoscope_adapter_read(unsigned int address) {
+ // The Kinetoscope emulator expects only the low 8 bits of this address.
+ address &= 0xff;
+ return (unsigned int)kinetoscope_read_16((uint32_t)address, NULL);
+}
diff --git a/core/cart_hw/kinetoscope_adapter.h b/core/cart_hw/kinetoscope_adapter.h
new file mode 100644
index 0000000..654f816
--- /dev/null
+++ b/core/cart_hw/kinetoscope_adapter.h
@@ -0,0 +1,16 @@
+// Kinetoscope: A Sega Genesis Video Player
+//
+// Copyright (c) 2024 Joey Parrish
+//
+// See MIT License in LICENSE.txt
+
+// Adapter between Kinetoscope emulation and Genesis Plus GX.
+
+#ifndef _KINETOSCOPE_ADAPTER_H_
+#define _KINETOSCOPE_ADAPTER_H_
+
+extern void kinetoscope_adapter_reset(void);
+extern void kinetoscope_adapter_write(unsigned int address, unsigned int data);
+extern unsigned int kinetoscope_adapter_read(unsigned int address);
+
+#endif
diff --git a/core/cart_hw/md_cart.c b/core/cart_hw/md_cart.c
index 766289d..07d75e1 100644
--- a/core/cart_hw/md_cart.c
+++ b/core/cart_hw/md_cart.c
@@ -45,6 +45,7 @@
#include "eeprom_i2c.h"
#include "eeprom_spi.h"
#include "megasd.h"
+#include "kinetoscope_adapter.h"
/* Cart database entry */
typedef struct
@@ -549,6 +550,13 @@ void md_cart_init(void)
cart.special |= HW_MEGASD;
cart.hw.time_w = megasd_rom_mapper_w;
}
+ else if (strstr(rominfo.consoletype,"SEGA KINETOSCOPE"))
+ {
+ /* Kinetoscope cartridge hardware */
+ cart.special |= HW_KINETOSCOPE;
+ cart.hw.time_w = kinetoscope_adapter_write;
+ cart.hw.time_r = kinetoscope_adapter_read;
+ }
else if (strstr(rominfo.domestic,"SUPER STREET FIGHTER2"))
{
/* SSF2 mapper */
@@ -848,6 +856,12 @@ void md_cart_reset(int hard_reset)
megasd_reset();
}
+ /* MegaSD hardware */
+ if (cart.special & HW_KINETOSCOPE)
+ {
+ kinetoscope_adapter_reset();
+ }
+
/* SVP chip */
if (svp)
{
diff --git a/core/cart_hw/md_cart.h b/core/cart_hw/md_cart.h
index 58687b9..f142356 100644
--- a/core/cart_hw/md_cart.h
+++ b/core/cart_hw/md_cart.h
@@ -62,9 +62,10 @@
#define HW_ADDON_NONE 0x03
/* Special hardware (0x01 & 0x02 reserved for Master System 3-D glasses & Terebi Oekaki) */
-#define HW_J_CART 0x04
-#define HW_LOCK_ON 0x08
-#define HW_MEGASD 0x10
+#define HW_J_CART 0x04
+#define HW_LOCK_ON 0x08
+#define HW_MEGASD 0x10
+#define HW_KINETOSCOPE 0x20
/* Cartridge extra hardware */
typedef struct