Jo Engine
2026.11.6
Jo Sega Saturn Engine
Toggle main menu visibility
Loading...
Searching...
No Matches
jo_engine
jo
time.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_TIME_H__
36
# define __JO_TIME_H__
37
38
# define JO_TIME_CKS_32_MODE (1)
39
# define JO_TIME_M_CKS (3)
40
41
typedef
enum
42
{
44
RegisterHighFRC
= 0xfffffe12,
46
RegisterLowFRC
= 0xfffffe13,
48
RegisterTCR
= 0xfffffe16,
50
RegisterSysClock
= 0x6000324
51
}
jo_time_memory_address
;
52
53
static
__jo_force_inline
void
jo_time_poke_byte
(
jo_time_memory_address
addr,
unsigned
char
data
)
54
{
55
(*(
volatile
unsigned
char
*)(addr)) =
data
;
56
}
57
58
static
__jo_force_inline
unsigned
char
jo_time_peek_byte
(
jo_time_memory_address
addr)
59
{
60
return
(*(
volatile
unsigned
char
*)(addr));
61
}
62
63
static
__jo_force_inline
void
jo_time_poke_int
(
jo_time_memory_address
addr,
unsigned
int
data
)
64
{
65
(*(
volatile
unsigned
int
*)(addr)) =
data
;
66
}
67
68
static
__jo_force_inline
unsigned
int
jo_time_peek_int
(
jo_time_memory_address
addr)
69
{
70
return
(*(
volatile
unsigned
int
*)(addr));
71
}
72
74
static
__jo_force_inline
int
jo_time_get_frc
(
void
)
75
{
76
unsigned
int
sr;
77
unsigned
int
high;
78
unsigned
int
low;
79
80
// (the high byte first: its read latches the low byte in the only temporary register of the timer, an interrupt that
81
// reads the timer between the 2 reads changed it: masked. The order of the 2 operands of | is not fixed by C)
82
__asm__
volatile
(
"stc sr, %0"
:
"=r"
(sr) : :
"memory"
);
83
__asm__
volatile
(
"ldc %0, sr"
: :
"r"
(sr | 0xF0) :
"memory"
);
84
high =
jo_time_peek_byte
(
RegisterHighFRC
);
85
low =
jo_time_peek_byte
(
RegisterLowFRC
);
86
__asm__
volatile
(
"ldc %0, sr"
: :
"r"
(sr) :
"memory"
);
87
return
((
int
)(high << 8 | low));
88
}
89
90
static
__jo_force_inline
void
jo_time_set_frc
(
unsigned
short
reg)
91
{
92
jo_time_poke_byte
(
RegisterHighFRC
, reg >> 8);
93
jo_time_poke_byte
(
RegisterLowFRC
, reg);
94
}
95
99
unsigned
int
jo_get_ticks
(
void
);
100
101
/*
102
████████╗██╗███╗ ███╗███████╗ ████████╗██████╗ █████╗ ██████╗██╗ ██╗██╗███╗ ██╗ ██████╗
103
╚══██╔══╝██║████╗ ████║██╔════╝ ╚══██╔══╝██╔══██╗██╔══██╗██╔════╝██║ ██╔╝██║████╗ ██║██╔════╝
104
██║ ██║██╔████╔██║█████╗ ██║ ██████╔╝███████║██║ █████╔╝ ██║██╔██╗ ██║██║ ███╗
105
██║ ██║██║╚██╔╝██║██╔══╝ ██║ ██╔══██╗██╔══██║██║ ██╔═██╗ ██║██║╚██╗██║██║ ██║
106
██║ ██║██║ ╚═╝ ██║███████╗ ██║ ██║ ██║██║ ██║╚██████╗██║ ██╗██║██║ ╚████║╚██████╔╝
107
╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝ ╚═════╝
108
109
██╗███╗ ██╗ ███████╗██╗██╗ ██╗███████╗██████╗ ███████╗███████╗ ██████╗ ██████╗ ███╗ ██╗██████╗ ███████╗
110
██║████╗ ██║ ██╔════╝██║╚██╗██╔╝██╔════╝██╔══██╗ ██╔════╝██╔════╝██╔════╝██╔═══██╗████╗ ██║██╔══██╗██╔════╝
111
██║██╔██╗ ██║ █████╗ ██║ ╚███╔╝ █████╗ ██║ ██║ ███████╗█████╗ ██║ ██║ ██║██╔██╗ ██║██║ ██║███████╗
112
██║██║╚██╗██║ ██╔══╝ ██║ ██╔██╗ ██╔══╝ ██║ ██║ ╚════██║██╔══╝ ██║ ██║ ██║██║╚██╗██║██║ ██║╚════██║
113
██║██║ ╚████║ ██║ ██║██╔╝ ██╗███████╗██████╔╝ ███████║███████╗╚██████╗╚██████╔╝██║ ╚████║██████╔╝███████║
114
╚═╝╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═════╝ ╚══════╝╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝╚═════╝ ╚══════╝
115
116
Contributed by Ponut64: https://github.com/johannes-fetz/joengine/pull/21 & Emerald Nova
117
*/
118
120
extern
jo_fixed
time_in_seconds
;
121
123
extern
jo_fixed
delta_time
;
124
128
void
jo_fixed_point_time
(
void
);
129
130
#endif
/* !__JO_TIME_H__ */
131
132
/*
133
** END OF FILE
134
*/
data
void * data
Definition
entity.h:19
jo_time_get_frc
static __jo_force_inline int jo_time_get_frc(void)
Get Free Running Counter value.
Definition
time.h:74
jo_time_poke_int
static __jo_force_inline void jo_time_poke_int(jo_time_memory_address addr, unsigned int data)
Definition
time.h:63
time_in_seconds
jo_fixed time_in_seconds
Will increment fixed-point 1 every second since starting jo_fixed_point_time().
jo_time_peek_byte
static __jo_force_inline unsigned char jo_time_peek_byte(jo_time_memory_address addr)
Definition
time.h:58
delta_time
jo_fixed delta_time
Represent the delta time (in fixed-point seconds) between each frame.
jo_time_memory_address
jo_time_memory_address
Definition
time.h:42
RegisterSysClock
@ RegisterSysClock
System clock register.
Definition
time.h:50
RegisterLowFRC
@ RegisterLowFRC
Low Free Running Counter Register (FCR), increases every time FCR high reaches 256.
Definition
time.h:46
RegisterTCR
@ RegisterTCR
Time Control Register (TCR).
Definition
time.h:48
RegisterHighFRC
@ RegisterHighFRC
High Free Running Counter Register (FCR), counts up to 255, then iterates FCR Low.
Definition
time.h:44
jo_time_poke_byte
static __jo_force_inline void jo_time_poke_byte(jo_time_memory_address addr, unsigned char data)
Definition
time.h:53
jo_time_set_frc
static __jo_force_inline void jo_time_set_frc(unsigned short reg)
Definition
time.h:90
jo_time_peek_int
static __jo_force_inline unsigned int jo_time_peek_int(jo_time_memory_address addr)
Definition
time.h:68
jo_fixed_point_time
void jo_fixed_point_time(void)
get ticks count
jo_get_ticks
unsigned int jo_get_ticks(void)
get ticks count
__jo_force_inline
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition
types.h:39
jo_fixed
int jo_fixed
Fixed point Q16.16 number.
Definition
types.h:59
Generated by
1.18.0