Debian Codegraph @

src/engine/platform/sound/gb/timing.h

raw
1 #ifndef timing_h
2 #define timing_h
3 #include "gb_struct_def.h"
4
5 void GB_advance_cycles(GB_gameboy_t *gb, uint8_t cycles);
6 void GB_emulate_timer_glitch(GB_gameboy_t *gb, uint8_t old_tac, uint8_t new_tac);
7 bool GB_timing_sync_turbo(GB_gameboy_t *gb); /* Returns true if should skip frame */
8 void GB_timing_sync(GB_gameboy_t *gb);
9
10 enum {
11 GB_TIMA_RUNNING = 0,
12 GB_TIMA_RELOADING = 1,
13 GB_TIMA_RELOADED = 2
14 };
15
16
17 #define GB_SLEEP(gb, unit, state, cycles) do {\
18 (gb)->unit##_cycles -= (cycles) * __state_machine_divisor; \
19 if ((gb)->unit##_cycles <= 0) {\
20 (gb)->unit##_state = state;\
21 return;\
22 unit##state:; \
23 }\
24 } while (0)
25
26 #define GB_STATE_MACHINE(gb, unit, cycles, divisor) \
27 static const int __state_machine_divisor = divisor;\
28 (gb)->unit##_cycles += cycles; \
29 if ((gb)->unit##_cycles <= 0) {\
30 return;\
31 }\
32 switch ((gb)->unit##_state)
33
34 #define GB_STATE(gb, unit, state) case state: goto unit##state
35
36 #define GB_UNIT(unit) int32_t unit##_cycles, unit##_state
37
38 #endif /* timing_h */