Jo Engine 2026.11.1
Jo Sega Saturn Engine
Loading...
Searching...
No Matches
core.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*/
34
35#ifndef __JO_CORE_H__
36# define __JO_CORE_H__
37
38#ifdef JO_DEBUG
39
44void __jo_core_error(char *message, const char *function);
47void __jo_core_errorf(const char *function, const char *format, ...) __attribute__((cold, noinline));
48# define jo_core_error(...) __jo_core_errorf(__FUNCTION__, __VA_ARGS__)
49
50#endif
51
53# define JO_ENGINE_VERSION (2025.1)
54
55/*
56** TYPEDEFS
57*/
59typedef void (*jo_event_callback)(void);
60
62typedef void (*jo_interrupt_handler)(void);
63
64#ifdef JO_COMPILE_WITH_DUAL_CPU_SUPPORT
65
67typedef void (*jo_slave_callback)(void);
68
69#endif
70
75void jo_core_init(const jo_color back_color);
76
80void jo_core_run(void);
81
87
91void jo_core_remove_vblank_callback(const int vblank_event_id);
92
99
103void jo_core_remove_callback(const int event_id);
104
105#ifdef JO_COMPILE_WITH_DUAL_CPU_SUPPORT
106
113
117void jo_core_remove_slave_callback(const int event_id);
118
119#endif
120
125
129
130#ifdef JO_COMPILE_WITH_DUAL_CPU_SUPPORT
131
140
145
152
154typedef void (*jo_slave_job_function)(void *argument);
155
160
168void __jo_core_add_slave_job(const jo_slave_job_function function, void *argument);
169
170#endif
171
175{
176 jo_smpc_begin_command();
177 jo_smpc_end_command(DisableReset);
178}
179
183{
184 jo_smpc_begin_command();
185 jo_smpc_end_command(EnableReset);
186}
187
190void jo_core_tv_off(void);
191
194void jo_core_tv_on(void);
195
201{
202 return ((JO_VDP2_TVSTAT & JO_VDP2_TVSTAT_PAL) ? 50 : 60);
203}
204
210{
211
212 (**(void(**)(void))0x600026C)();
213}
214
219{
220 jo_smpc_begin_command();
221 jo_smpc_end_command(SystemReset);
222}
223
229#define jo_core_set_screens_order(screen1, args...) __jo_core_set_screens_order(screen1, ## args, ~0);
230
231#ifdef JO_DEBUG
232
236
241{
242 return (__jo_last_error);
243}
244
248
252
253#endif
254
259
260/*
261** Internal usage
262*/
263
265extern volatile unsigned int __jo_core_vblank_count;
266
272{
273 return (__jo_core_vblank_count);
274}
275
280
285void __jo_core_set_interrupt_handler(const unsigned int vector, jo_interrupt_handler handler);
286
290void __jo_core_enable_scu_interrupts(const unsigned int mask);
291
297
301static __jo_force_inline unsigned int __jo_core_get_sr(void)
302{
303 unsigned int sr;
304
305 __asm__ volatile ("stc sr, %0" : "=r" (sr));
306 return (sr);
307}
308
312static __jo_force_inline void __jo_core_set_sr(const unsigned int sr)
313{
314 __asm__ volatile ("ldc %0, sr" : : "r" (sr) : "memory");
315}
316
321{
322 unsigned int sr;
323
324 sr = __jo_core_get_sr();
326 return (sr);
327}
328
332static __jo_force_inline void __jo_core_restore_interrupts(const unsigned int sr)
333{
335}
336
337#endif /* !__JO_CORE_H__ */
338
339/*
340** END OF FILE
341*/
#define JO_PRINTF_BUF_SIZE
Max character in available in jo_printf().
Definition conf.h:157
void jo_core_suspend(void)
Stop the execution until someone press Start.
static __jo_force_inline void __jo_core_restore_interrupts(const unsigned int sr)
Restore interrupts masked by __jo_core_disable_interrupts() (Internal usage).
Definition core.h:332
void __jo_core_add_slave_job(const jo_slave_job_function function, void *argument)
Add a job to the queue of the slave CPU (Internal usage).
void(*) jo_interrupt_handler(void)
Function prototype for interrupt handlers (Internal usage).
Definition core.h:62
void jo_core_remove_callback(const int event_id)
Remove a callback in the game loop from on main CPU.
void jo_core_init(const jo_color back_color)
Init the engine.
void jo_core_remove_vblank_callback(const int vblank_event_id)
Remove a callback during VBLANK interruption.
void jo_core_set_restart_game_callback(const jo_event_callback callback)
Add a callback when A+B+C+Start is pressed on the first control pad.
void __jo_core_set_interrupt_handler(const unsigned int vector, jo_interrupt_handler handler)
Set an interrupt handler in the vector table (Internal usage).
void(*) jo_event_callback(void)
Function prototype for jo_core_add_callback().
Definition core.h:59
void(*) jo_slave_job_function(void *argument)
Function of a job of the slave CPU (Internal usage).
Definition core.h:154
void __jo_core_synch(void)
Wait for the end of the current frame (Internal usage).
int jo_core_slave_idle_time(void)
Balance of the CPUs in the last frame (between the 2 last calls of jo_core_wait_for_slave()).
int jo_core_add_vblank_callback(const jo_event_callback callback)
Add a callback during VBLANK interruption.
void jo_core_remove_slave_callback(const int event_id)
Remove a callback in the game loop from on slave CPU.
void jo_goto_boot_menu(void)
Return to the boot menu.
static __jo_force_inline void __jo_core_set_sr(const unsigned int sr)
Set CPU status register (Internal usage).
Definition core.h:312
static __jo_force_inline int jo_core_get_refresh_rate(void)
Get the refresh rate of the console.
Definition core.h:200
void noinline
Definition core.h:47
void jo_core_exec_on_slave(jo_slave_callback callback)
Execute a callback on the slave CPU.
static __jo_force_inline void jo_core_exit_to_multiplayer(void)
Exit program and return to the Saturn multiplayer (CD player) screen.
Definition core.h:209
bool __jo_core_is_slave_running(void)
Check if the slave CPU started (Internal usage).
void jo_core_tv_off(void)
Turn OFF scroll drawing processing in the monitor.
static __jo_force_inline void jo_core_disable_reset(void)
Disable reset button.
Definition core.h:174
void jo_core_run(void)
Run the game.
char __jo_last_error[JO_PRINTF_BUF_SIZE]
Error handling (Internal usage).
static __jo_force_inline void jo_core_enable_reset(void)
Enable reset button.
Definition core.h:182
volatile unsigned int __jo_core_vblank_count
Number of VBLANK since startup (Internal usage).
void(*) jo_slave_callback(void)
Function prototype for jo_core_exec_on_slave().
Definition core.h:67
static __jo_force_inline unsigned int __jo_core_get_sr(void)
Get CPU status register (Internal usage).
Definition core.h:301
static __jo_force_inline void jo_core_restart_saturn(void)
Restart the Saturn.
Definition core.h:218
void jo_dump_vdp2_registers(void)
Dump VDP2 registers.
void __jo_core_restore_scu_mask(void)
Write the SCU interrupt mask again at the end of a SCU interrupt handler (Internal usage).
int jo_core_add_callback(const jo_event_callback callback)
Add a callback in the game loop on main CPU.
void jo_core_wait_for_slave(void)
Wait until all the callbacks given to jo_core_exec_on_slave() are completed.
void __jo_core_enable_scu_interrupts(const unsigned int mask)
Unmask SCU interrupts (Internal usage).
void jo_core_tv_on(void)
Turn ON scroll drawing processing in the monitor.
static __jo_force_inline unsigned int __jo_core_disable_interrupts(void)
Mask all interrupts (Internal usage).
Definition core.h:320
void __jo_core_set_screens_order(jo_scroll_screen screen1,...)
Screen order (Internal usage).
void jo_dump_vdp1_registers(void)
Dump VDP1 registers.
void __jo_core_error(char *message, const char *function)
int jo_core_add_slave_callback(const jo_event_callback callback)
Add a callback in the game loop on slave CPU.
void __jo_core_errorf(const char *function, const char *format,...) __attribute__((cold
The message formatted, then __jo_core_error() (Internal usage): one call at each of the hundreds of j...
static __jo_force_inline unsigned int jo_core_get_vblank_count(void)
Get the number of VBLANK since startup (60 per second in NTSC, 50 in PAL).
Definition core.h:271
static __jo_force_inline char * jo_get_last_error(void)
Get last error.
Definition core.h:240
#define JO_VDP2_TVSTAT
Definition sega_saturn.h:169
#define JO_SH2_SR_INTERRUPT_MASK
Status register: interrupt mask bits (level 15 = all interrupts masked).
Definition sega_saturn.h:551
#define JO_VDP2_TVSTAT_PAL
TVSTAT: PAL console (50 Hz).
Definition sega_saturn.h:171
@ DisableReset
Disables NMI requests to be sent when the Reset button is pressed.
Definition smpc.h:78
@ 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
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition types.h:39
unsigned short jo_color
15 bits color type
Definition types.h:42
jo_scroll_screen
Sega Saturn Scroll Screen Ids.
Definition types.h:322