Jo Engine 2026.11.1
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)
181
183# define JO_PERIPHERAL_KEYBOARD_CAPS_LOCK (1 << 6)
185# define JO_PERIPHERAL_KEYBOARD_NUM_LOCK (1 << 5)
187# define JO_PERIPHERAL_KEYBOARD_SCROLL_LOCK (1 << 4)
189# define JO_PERIPHERAL_KEYBOARD_MAKE (1 << 3)
191# define JO_PERIPHERAL_KEYBOARD_BREAK (1 << 0)
192
196typedef struct
197{
198 unsigned char id; // JO_PERIPHERAL_ID_xxx
199 unsigned char size; // Data size
200 unsigned short data; // Current state
201 unsigned short push; // Pressed this frame
202 unsigned short pull; // Released this frame
203 unsigned int reserved[4];
205
209typedef struct
210{
211 unsigned char id;
212 unsigned char size;
213 unsigned short data;
214 unsigned short push;
215 unsigned short pull;
216 unsigned char x;
217 unsigned char y;
218 unsigned char z;
219 unsigned char w;
220 unsigned int reserved[3];
222
226typedef struct
227{
228 unsigned char id;
229 unsigned char size;
230 unsigned short data;
231 unsigned short push;
232 unsigned short pull;
233 short x;
234 short y;
235 unsigned int reserved[3];
237
241typedef struct
242{
243 unsigned char id;
244 unsigned char size;
245 unsigned short data;
246 unsigned short push;
247 unsigned short pull;
248 unsigned char condition; // JO_PERIPHERAL_KEYBOARD_xxx flags
249 unsigned char code; // Key code
250 unsigned short reserved1;
251 unsigned int reserved2[3];
253
255# define JO_SMPC_PERIPHERAL_PER_PORT (15)
256
259
261typedef struct
262{
263 unsigned char cond;
264 unsigned short year; // BCD
265 unsigned char month; // week << 4 | month
266 unsigned char day; // BCD
267 unsigned char hour; // BCD
268 unsigned char minute; // BCD
269 unsigned char second; // BCD
270 unsigned char cartridge_code;
271 unsigned char area_code;
272 unsigned short system_status;
273 unsigned int smpc_memory;
275
278
283
284#endif /* !__JO_SMPC_H__ */
285
286/*
287** END OF FILE
288*/
unsigned short year
Definition smpc.h:264
unsigned char id
Definition smpc.h:211
unsigned short data
Definition smpc.h:230
unsigned short pull
Definition smpc.h:247
short y
Definition smpc.h:234
unsigned char hour
Definition smpc.h:267
unsigned char y
Definition smpc.h:217
unsigned char size
Definition smpc.h:212
jo_smpc_status __jo_smpc_status
SMPC status, refreshed every frame (Internal usage).
unsigned char size
Definition smpc.h:244
unsigned short push
Definition smpc.h:246
unsigned char code
Definition smpc.h:249
unsigned int reserved[3]
Definition smpc.h:220
unsigned char z
Definition smpc.h:218
unsigned char second
Definition smpc.h:269
unsigned char cond
Definition smpc.h:263
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:255
unsigned short pull
Definition smpc.h:232
unsigned short push
Definition smpc.h:201
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
short x
Definition smpc.h:233
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:203
unsigned char condition
Definition smpc.h:248
unsigned char size
Definition smpc.h:199
static __jo_force_inline unsigned char jo_smpc_read_byte(jo_smpc_memory_address addr)
Definition smpc.h:142
unsigned int reserved2[3]
Definition smpc.h:251
unsigned char day
Definition smpc.h:266
unsigned char id
Definition smpc.h:243
unsigned short pull
Definition smpc.h:215
unsigned char minute
Definition smpc.h:268
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 char id
Definition smpc.h:228
unsigned short data
Definition smpc.h:245
unsigned short data
Definition smpc.h:200
unsigned short system_status
Definition smpc.h:272
unsigned char id
Definition smpc.h:198
unsigned int smpc_memory
Definition smpc.h:273
unsigned short pull
Definition smpc.h:202
unsigned short data
Definition smpc.h:213
unsigned short push
Definition smpc.h:231
unsigned char w
Definition smpc.h:219
unsigned char month
Definition smpc.h:265
unsigned char size
Definition smpc.h:229
unsigned char cartridge_code
Definition smpc.h:270
unsigned int reserved[3]
Definition smpc.h:235
unsigned char area_code
Definition smpc.h:271
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 x
Definition smpc.h:216
unsigned short push
Definition smpc.h:214
unsigned short reserved1
Definition smpc.h:250
static __jo_force_inline void jo_smpc_begin_command(void)
Definition smpc.h:150
Digital peripheral data (gamepad).
Definition smpc.h:197
Analog peripheral data (racing wheel, mission stick, 3D pad).
Definition smpc.h:210
Keyboard data.
Definition smpc.h:242
Pointing peripheral data (mouse).
Definition smpc.h:227
SMPC status (Internal usage).
Definition smpc.h:262
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition types.h:39