Jo Engine  2020.06.22
Jo Sega Saturn Engine
time.h
Go to the documentation of this file.
1 /*
2 ** Jo Sega Saturn Engine
3 ** Copyright (c) 2012-2020, 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 */
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
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 
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 
69 {
70  return (*(volatile unsigned int *)(addr));
71 }
72 
75 {
77 }
78 
79 static __jo_force_inline void jo_time_set_frc(unsigned char reg)
80 {
83 }
84 
88 unsigned int jo_get_ticks(void);
89 
90 /*
91 ████████╗██╗███╗ ███╗███████╗ ████████╗██████╗ █████╗ ██████╗██╗ ██╗██╗███╗ ██╗ ██████╗
92 ╚══██╔══╝██║████╗ ████║██╔════╝ ╚══██╔══╝██╔══██╗██╔══██╗██╔════╝██║ ██╔╝██║████╗ ██║██╔════╝
93  ██║ ██║██╔████╔██║█████╗ ██║ ██████╔╝███████║██║ █████╔╝ ██║██╔██╗ ██║██║ ███╗
94  ██║ ██║██║╚██╔╝██║██╔══╝ ██║ ██╔══██╗██╔══██║██║ ██╔═██╗ ██║██║╚██╗██║██║ ██║
95  ██║ ██║██║ ╚═╝ ██║███████╗ ██║ ██║ ██║██║ ██║╚██████╗██║ ██╗██║██║ ╚████║╚██████╔╝
96  ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝ ╚═════╝
97 
98 ██╗███╗ ██╗ ███████╗██╗██╗ ██╗███████╗██████╗ ███████╗███████╗ ██████╗ ██████╗ ███╗ ██╗██████╗ ███████╗
99 ██║████╗ ██║ ██╔════╝██║╚██╗██╔╝██╔════╝██╔══██╗ ██╔════╝██╔════╝██╔════╝██╔═══██╗████╗ ██║██╔══██╗██╔════╝
100 ██║██╔██╗ ██║ █████╗ ██║ ╚███╔╝ █████╗ ██║ ██║ ███████╗█████╗ ██║ ██║ ██║██╔██╗ ██║██║ ██║███████╗
101 ██║██║╚██╗██║ ██╔══╝ ██║ ██╔██╗ ██╔══╝ ██║ ██║ ╚════██║██╔══╝ ██║ ██║ ██║██║╚██╗██║██║ ██║╚════██║
102 ██║██║ ╚████║ ██║ ██║██╔╝ ██╗███████╗██████╔╝ ███████║███████╗╚██████╗╚██████╔╝██║ ╚████║██████╔╝███████║
103 ╚═╝╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═════╝ ╚══════╝╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝╚═════╝ ╚══════╝
104 
105 Contributed by Ponut64: https://github.com/johannes-fetz/joengine/pull/21 & Emerald Nova
106 */
107 
110 
112 extern jo_fixed delta_time;
113 
118 
119 #endif /* !__JO_TIME_H__ */
120 
121 /*
122 ** END OF FILE
123 */
RegisterTCR
@ RegisterTCR
Time Control Register (TCR)
Definition: time.h:48
__jo_force_inline
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition: conf.h:154
RegisterHighFRC
@ RegisterHighFRC
High Free Running Counter Register (FCR), counts up to 255, then iterates FCR Low.
Definition: time.h:44
time_in_seconds
jo_fixed time_in_seconds
Will increment fixed-point 1 every second since starting jo_fixed_point_time()
jo_time_peek_int
static __jo_force_inline unsigned int jo_time_peek_int(jo_time_memory_address addr)
Definition: time.h:68
jo_time_peek_byte
static __jo_force_inline unsigned char jo_time_peek_byte(jo_time_memory_address addr)
Definition: time.h:58
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_fixed
int jo_fixed
Fixed point Q16.16 number.
Definition: types.h:46
jo_time_set_frc
static __jo_force_inline void jo_time_set_frc(unsigned char reg)
Definition: time.h:79
jo_time_memory_address
jo_time_memory_address
Definition: time.h:42
jo_fixed_point_time
void jo_fixed_point_time(void)
get ticks count
RegisterLowFRC
@ RegisterLowFRC
Low Free Running Counter Register (FCR), increases every time FCR high reaches 256.
Definition: time.h:46
RegisterSysClock
@ RegisterSysClock
System clock register.
Definition: time.h:50
delta_time
jo_fixed delta_time
Represent the delta time (in fixed-point seconds) between each frame.
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
jo_get_ticks
unsigned int jo_get_ticks(void)
get ticks count