Jo Engine 2026.11.6
Jo Sega Saturn Engine
Loading...
Searching...
No Matches
smpc.h
Go to the documentation of this file.
1/*
2** Jo Sega Saturn Engine
3** Copyright (c) 2012-2026, Johannes Fetz (johannesfetz@gmail.com)
4** All rights reserved.
5**
6** Redistribution and use in source and binary forms, with or without
7** modification, are permitted provided that the following conditions are met:
8** * Redistributions of source code must retain the above copyright
9** notice, this list of conditions and the following disclaimer.
10** * Redistributions in binary form must reproduce the above copyright
11** notice, this list of conditions and the following disclaimer in the
12** documentation and/or other materials provided with the distribution.
13** * Neither the name of the Johannes Fetz nor the
14** names of its contributors may be used to endorse or promote products
15** derived from this software without specific prior written permission.
16**
17** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20** DISCLAIMED. IN NO EVENT SHALL Johannes Fetz BE LIABLE FOR ANY
21** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
36
37#ifndef __JO_SMPC_H__
38# define __JO_SMPC_H__
39
80
81typedef enum
82{
84 CommandRegister = 0x2010001f,
86 StatusRegister = 0x20100061,
88 StatusFlag = 0x20100063,
90 InputRegister0 = 0x20100001,
91 InputRegister1 = 0x20100003,
92 InputRegister2 = 0x20100005,
93 InputRegister3 = 0x20100007,
94 InputRegister4 = 0x20100009,
95 InputRegister5 = 0x2010000b,
96 InputRegister6 = 0x2010000d,
98 OutputRegister0 = 0x20100021,
99 OutputRegister1 = 0x20100023,
100 OutputRegister2 = 0x20100025,
101 OutputRegister3 = 0x20100027,
102 OutputRegister4 = 0x20100029,
103 OutputRegister5 = 0x2010002b,
104 OutputRegister6 = 0x2010002d,
105 OutputRegister7 = 0x2010002f,
106 OutputRegister8 = 0x20100031,
107 OutputRegister9 = 0x20100033,
108 OutputRegister10 = 0x20100035,
109 OutputRegister11 = 0x20100037,
110 OutputRegister12 = 0x20100039,
111 OutputRegister13 = 0x2010003b,
112 OutputRegister14 = 0x2010003d,
113 OutputRegister15 = 0x2010003f,
114 OutputRegister16 = 0x20100041,
115 OutputRegister17 = 0x20100043,
116 OutputRegister18 = 0x20100045,
117 OutputRegister19 = 0x20100047,
118 OutputRegister20 = 0x20100049,
119 OutputRegister21 = 0x2010004b,
120 OutputRegister22 = 0x2010004d,
121 OutputRegister23 = 0x2010004f,
122 OutputRegister24 = 0x20100051,
123 OutputRegister25 = 0x20100053,
124 OutputRegister26 = 0x20100055,
125 OutputRegister27 = 0x20100057,
126 OutputRegister28 = 0x20100059,
127 OutputRegister29 = 0x2010005b,
128 OutputRegister30 = 0x2010005d,
129 OutputRegister31 = 0x2010005f,
130 PortDataRegister1 = 0x20100075,
131 PortDataRegister2 = 0x20100077,
137
139{
140 (*(volatile unsigned char *)(addr)) = data;
141}
143{
144 return (*(volatile unsigned char *)(addr));
145}
147{
148 while ((jo_smpc_read_byte(StatusFlag) & 0x1) == 0x1);
149}
160
161/*
162** PERIPHERALS
163*/
164
166# define JO_PERIPHERAL_ID_NOT_CONNECTED (0xff)
168# define JO_PERIPHERAL_ID_STANDARD_PAD (0x02)
170# define JO_PERIPHERAL_ID_RACING_WHEEL (0x13)
172# define JO_PERIPHERAL_ID_MISSION_STICK (0x15)
174# define JO_PERIPHERAL_ID_NIGHTS_PAD (0x16)
176# define JO_PERIPHERAL_ID_MOUSE (0x23)
178# define JO_PERIPHERAL_ID_SHUTTLE_MOUSE (0xe3)
180# define JO_PERIPHERAL_ID_KEYBOARD (0x34)
185# define JO_PERIPHERAL_ID_GUN (0xa0)
186
188# define JO_PERIPHERAL_KEYBOARD_CAPS_LOCK (1 << 6)
190# define JO_PERIPHERAL_KEYBOARD_NUM_LOCK (1 << 5)
192# define JO_PERIPHERAL_KEYBOARD_SCROLL_LOCK (1 << 4)
194# define JO_PERIPHERAL_KEYBOARD_MAKE (1 << 3)
196# define JO_PERIPHERAL_KEYBOARD_BREAK (1 << 0)
198# define JO_PERIPHERAL_KEYBOARD_LEFT_SHIFT (1 << 0)
200# define JO_PERIPHERAL_KEYBOARD_RIGHT_SHIFT (1 << 1)
202# define JO_PERIPHERAL_KEYBOARD_SHIFT (JO_PERIPHERAL_KEYBOARD_LEFT_SHIFT | JO_PERIPHERAL_KEYBOARD_RIGHT_SHIFT)
204# define JO_PERIPHERAL_KEYBOARD_CODE_LEFT_SHIFT (0x12)
205# define JO_PERIPHERAL_KEYBOARD_CODE_RIGHT_SHIFT (0x59)
206
210typedef struct
211{
212 unsigned char id; // JO_PERIPHERAL_ID_xxx
213 unsigned char size; // Data size
214 unsigned short data; // Current state
215 unsigned short push; // Pressed this frame
216 unsigned short pull; // Released this frame
217 unsigned int reserved[4];
219
223typedef struct __jo_may_alias
224{
225 unsigned char id;
226 unsigned char size;
227 unsigned short data;
228 unsigned short push;
229 unsigned short pull;
230 unsigned char x;
231 unsigned char y;
232 unsigned char z;
233 unsigned char w;
234 unsigned int reserved[3];
236
240typedef struct __jo_may_alias
241{
242 unsigned char id;
243 unsigned char size;
244 unsigned short data;
245 unsigned short push;
246 unsigned short pull;
247 short x;
248 short y;
249 unsigned int reserved[3];
251
255typedef struct __jo_may_alias
256{
257 unsigned char id;
258 unsigned char size;
259 unsigned short data;
260 unsigned short push;
261 unsigned short pull;
262 short x; // Position of the last latch (pixels of the screen, without the calibration)
263 short y;
264 unsigned char light; // 1: the light sensor latched the position during the last field
265 unsigned char reserved1[3];
266 unsigned int reserved2[2];
268
272typedef struct __jo_may_alias
273{
274 unsigned char id;
275 unsigned char size;
276 unsigned short data;
277 unsigned short push;
278 unsigned short pull;
279 unsigned char condition; // JO_PERIPHERAL_KEYBOARD_xxx flags
280 unsigned char code; // Key code
281 unsigned char modifiers; // JO_PERIPHERAL_KEYBOARD_LEFT_SHIFT, JO_PERIPHERAL_KEYBOARD_RIGHT_SHIFT (held)
282 unsigned char reserved1;
283 unsigned int reserved2[3];
285
287# define JO_SMPC_PERIPHERAL_PER_PORT (15)
288
291
293typedef struct
294{
295 unsigned char cond;
296 unsigned short year; // BCD
297 unsigned char month; // week << 4 | month
298 unsigned char day; // BCD
299 unsigned char hour; // BCD
300 unsigned char minute; // BCD
301 unsigned char second; // BCD
302 unsigned char cartridge_code;
303 unsigned char area_code;
304 unsigned short system_status;
305 unsigned int smpc_memory;
307
312
316void __jo_smpc_set_reset_button(const bool enabled);
317
318#endif /* !__JO_SMPC_H__ */
319
320/*
321** END OF FILE
322*/
void * data
Definition entity.h:19
unsigned short year
Definition smpc.h:296
unsigned int reserved2[2]
Definition smpc.h:266
struct __jo_may_alias jo_peripheral_pointer
Pointing peripheral data (mouse).
unsigned char light
Definition smpc.h:264
unsigned char hour
Definition smpc.h:299
struct __jo_may_alias jo_peripheral_gun
Light gun data (Internal usage, see jo_get_input_gun_position()).
unsigned char code
Definition smpc.h:280
void __jo_smpc_set_reset_button(const bool enabled)
Enable or disable the reset button, nested calls (Internal usage, see jo_core_disable_reset()).
jo_3d_polygon_data data
Definition 3d.h:242
unsigned char condition
Definition smpc.h:279
unsigned char second
Definition smpc.h:301
unsigned char cond
Definition smpc.h:295
unsigned char x
Definition smpc.h:230
unsigned int reserved[3]
Definition smpc.h:234
static __jo_force_inline void jo_smpc_write_byte(jo_smpc_memory_address addr, unsigned char data)
Definition smpc.h:138
#define JO_SMPC_PERIPHERAL_PER_PORT
Number of peripherals per port (with a multitap).
Definition smpc.h:287
unsigned short push
Definition smpc.h:215
static __jo_force_inline void jo_smpc_end_command(jo_smpc_command command)
Definition smpc.h:155
jo_smpc_memory_address
Definition smpc.h:82
@ OutputRegister17
Definition smpc.h:115
@ OutputRegister7
Definition smpc.h:105
@ ExternalLatchEnableRegister
Definition smpc.h:135
@ OutputRegister22
Definition smpc.h:120
@ OutputRegister20
Definition smpc.h:118
@ OutputRegister8
Definition smpc.h:106
@ OutputRegister23
Definition smpc.h:121
@ OutputRegister16
Definition smpc.h:114
@ OutputRegister11
Definition smpc.h:109
@ DataDirectionRegister1
Definition smpc.h:132
@ InputRegister3
Definition smpc.h:93
@ InputRegister0
Input registers for command issuing. Whatever data the SMPC needs for processing command goes here.
Definition smpc.h:90
@ OutputRegister28
Definition smpc.h:126
@ OutputRegister13
Definition smpc.h:111
@ OutputRegister27
Definition smpc.h:125
@ OutputRegister19
Definition smpc.h:117
@ OutputRegister25
Definition smpc.h:123
@ InputRegister4
Definition smpc.h:94
@ OutputRegister0
Ouput Register for the command. If it supports it, it'll output any return data here.
Definition smpc.h:98
@ OutputRegister30
Definition smpc.h:128
@ DataDirectionRegister2
Definition smpc.h:133
@ OutputRegister24
Definition smpc.h:122
@ InputRegister2
Definition smpc.h:92
@ OutputRegister15
Definition smpc.h:113
@ InputRegister5
Definition smpc.h:95
@ OutputRegister9
Definition smpc.h:107
@ StatusRegister
Status Register.
Definition smpc.h:86
@ OutputRegister26
Definition smpc.h:124
@ InputRegister1
Definition smpc.h:91
@ OutputRegister1
Definition smpc.h:99
@ PortDataRegister1
Definition smpc.h:130
@ OutputRegister31
Definition smpc.h:129
@ OutputRegister12
Definition smpc.h:110
@ OutputRegister5
Definition smpc.h:103
@ OutputRegister4
Definition smpc.h:102
@ StatusFlag
Status Flag. Shows the status of the SMPC command. Normally you set this to 1 when issuing out a comm...
Definition smpc.h:88
@ InputOutputSelectRegister
Definition smpc.h:134
@ PortDataRegister2
Definition smpc.h:131
@ OutputRegister29
Definition smpc.h:127
@ OutputRegister14
Definition smpc.h:112
@ OutputRegister2
Definition smpc.h:100
@ OutputRegister21
Definition smpc.h:119
@ OutputRegister18
Definition smpc.h:116
@ OutputRegister3
Definition smpc.h:101
@ OutputRegister10
Definition smpc.h:108
@ CommandRegister
The command that's supposed to be issued by the SMPC.
Definition smpc.h:84
@ OutputRegister6
Definition smpc.h:104
@ InputRegister6
Definition smpc.h:96
jo_peripheral __jo_smpc_peripherals[(15) *2]
Peripherals (Internal usage): 15 entries for port 1 followed by 15 entries for port 2.
unsigned int reserved[4]
Definition smpc.h:217
unsigned char size
Definition smpc.h:213
static __jo_force_inline unsigned char jo_smpc_read_byte(jo_smpc_memory_address addr)
Definition smpc.h:142
unsigned char day
Definition smpc.h:298
unsigned char y
Definition smpc.h:231
unsigned char minute
Definition smpc.h:300
unsigned char reserved1[3]
Definition smpc.h:265
jo_smpc_command
SMPC Commands.
Definition smpc.h:42
@ EnableSoundCPU
Resets and enables the Motorola C68K (sound) CPU.
Definition smpc.h:50
@ EnableCD
Resets and enables the CD Block.
Definition smpc.h:54
@ ChangeSystemClockSpeed320
Changes the system clockspeed.
Definition smpc.h:66
@ SetSMPCMemory
Sets the 4-byte battery-backed memory contained on the SMPC(which is used by the bios for language se...
Definition smpc.h:72
@ DisableReset
Disables NMI requests to be sent when the Reset button is pressed.
Definition smpc.h:78
@ EnableNetlink
Resets and enables Netlink execution.
Definition smpc.h:58
@ DisableSlaveCPU
Disables the SH-2 Slave CPU.
Definition smpc.h:48
@ SystemReset
Resets the System.
Definition smpc.h:62
@ EnableReset
Enables NMI requests to be sent when the Reset button is pressed.
Definition smpc.h:76
@ ChangeSystemClockSpeed352
Changes the system clockspeed.
Definition smpc.h:64
@ DisableSoundCPU
Disables the Motorola C68K (sound) CPU.
Definition smpc.h:52
@ SetRTCDateAndTime
Sets the date and time for the RTC.
Definition smpc.h:70
@ EnableMasterCPU
Resets and enables the SH-2 Master CPU.
Definition smpc.h:44
@ DisableCD
Disables the CD Block.
Definition smpc.h:56
@ FetchStatusAndPeripheralData
Fetches the SMPC status and peripheral data.
Definition smpc.h:68
@ EnableSlaveCPU
Resets and enables the SH-2 Slave CPU.
Definition smpc.h:46
@ SendNMIRequestToMasterCPU
Sends an NMI request to the Master SH2.
Definition smpc.h:74
@ DisableNetlink
Disables Netlink execution.
Definition smpc.h:60
static __jo_force_inline void jo_smpc_wait(void)
Definition smpc.h:146
unsigned short data
Definition smpc.h:214
unsigned short system_status
Definition smpc.h:304
unsigned char id
Definition smpc.h:212
unsigned char id
Definition smpc.h:225
unsigned int smpc_memory
Definition smpc.h:305
unsigned short pull
Definition smpc.h:216
unsigned char month
Definition smpc.h:297
struct __jo_may_alias jo_peripheral_analog
Analog peripheral data (racing wheel, mission stick, 3D pad).
unsigned char cartridge_code
Definition smpc.h:302
unsigned short push
Definition smpc.h:228
unsigned char area_code
Definition smpc.h:303
void __jo_smpc_command(const jo_smpc_command command)
Send a command to the SMPC and wait for the end of the command (Internal usage).
unsigned char modifiers
Definition smpc.h:281
unsigned char size
Definition smpc.h:226
unsigned char w
Definition smpc.h:233
unsigned short pull
Definition smpc.h:229
unsigned char z
Definition smpc.h:232
static __jo_force_inline void jo_smpc_begin_command(void)
Definition smpc.h:150
struct __jo_may_alias jo_peripheral_keyboard
Keyboard data.
Digital peripheral data (gamepad).
Definition smpc.h:211
SMPC status (Internal usage).
Definition smpc.h:294
#define __jo_may_alias
The memory of an object of another type can be accessed through this type (the strict aliasing rule o...
Definition types.h:44
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition types.h:39