-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimer.h
101 lines (81 loc) · 3.44 KB
/
Timer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* C64 NonSense, the C64 Game Engine.
* Copyright (C) 2020-2022 Dirk "YouDirk" Lehmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef TIMER_H__
#define TIMER_H__
#include "common.h"
/* *******************************************************************
*
* Logical timers (1, 2, ...) are controlled by physical timers (CIA1
* A B, CIA2 A B).
*/
#define TIMER_1_FREQUENCY_HZ 50 /* 50 Hz */
#define TIMER_1_TICKRATE_MS (1000/TIMER_1_FREQUENCY_HZ)
/* 20 ms */
/* These calibration values are just useful if the Timer 1 frequency
* is a multiple of the PAL/NTSC frequency. If you prefer accurate
* timer ticks then set these values to 0.
*
* Triple Buffering: Make sure that there is a small difference
* between Timer- and PAL/NTSC frequency (DEBUG_RENDERTIME_IRQ).
* Otherwise the shared/back buffer swap maybe called in worst case
* timing for a very long time.
*
* Double Buffering: Make sure that there is a large difference
* between Timer- and PAL/NTSC frequency (DEBUG_RENDERTIME_IRQ).
* Otherwise the Graphix_buffer_swap() maybe called in worst case
* timing for a very long time with a very huge stuttering.
*/
#ifndef CONF_DOUBLE_BUFFERING
# define TIMER_1_CALIBR_PAL_CLKS -36 /* reduce buckings/sec (PAL) */
# define TIMER_1_CALIBR_NTSC_CLKS TIMER_1_CALIBR_PAL_CLKS /* (NTSC) */
#else /* CONF_DOUBLE_BUFFERING */
# define TIMER_1_CALIBR_PAL_CLKS 0 /* triple buffering disabled */
# define TIMER_1_CALIBR_NTSC_CLKS TIMER_1_CALIBR_PAL_CLKS /* (NTSC) */
#endif /* CONF_DOUBLE_BUFFERING */
/* *************************************************************** */
/* Structure of static members for module. */
typedef struct Timer_t {
/* System clock of the MOS 6510 CPU. Depending if we are on a PAL
* or NTSC system.
*
* 16 bit is not wide enough to store 1 Mhz
*/
uint32_t system_clk;
} Timer_t;
/* *************************************************************** */
/* Static members of this module. */
extern Timer_t Timer;
/* Initialize the timers on CIA1 and CIA2 which we are using.
*/
extern void __fastcall__ Timer_init(void);
/* Restore timer configuration on CIA1 and CIA2 which we had used.
*/
extern void __fastcall__ Timer_release(void);
/* *******************************************************************
*
* Access to logical timers (1, 2, ...), controlled by physical timers
* (CIA1 A B, CIA2 A B).
*/
/* Reset the logical timer 1 to t=0. */
extern void __fastcall__ Timer_1_reset(void);
/* Return just the lowest byte of logical timer 1. */
extern uint8_t __fastcall__ Timer_1_get8(void);
/* Return the lower 16 bit of logical timer 1. */
extern uint16_t __fastcall__ Timer_1_get16(void);
/* Return the whole 32 bit of logical timer 1. */
extern uint32_t __fastcall__ Timer_1_get32(void);
#endif /* TIMER_H__ */