2016-03-30 20:07:55 +00:00
|
|
|
#ifndef timing_h
|
|
|
|
#define timing_h
|
2018-05-27 16:30:23 +00:00
|
|
|
#include "gb_struct_def.h"
|
2016-03-30 20:07:55 +00:00
|
|
|
|
2017-04-17 17:16:17 +00:00
|
|
|
#ifdef GB_INTERNAL
|
2016-06-18 17:29:11 +00:00
|
|
|
void GB_advance_cycles(GB_gameboy_t *gb, uint8_t cycles);
|
2016-07-17 21:39:43 +00:00
|
|
|
void GB_rtc_run(GB_gameboy_t *gb);
|
2016-08-05 14:22:12 +00:00
|
|
|
void GB_emulate_timer_glitch(GB_gameboy_t *gb, uint8_t old_tac, uint8_t new_tac);
|
2017-04-21 13:00:53 +00:00
|
|
|
bool GB_timing_sync_turbo(GB_gameboy_t *gb); /* Returns true if should skip frame */
|
|
|
|
void GB_timing_sync(GB_gameboy_t *gb);
|
|
|
|
|
2017-04-17 17:16:17 +00:00
|
|
|
enum {
|
|
|
|
GB_TIMA_RUNNING = 0,
|
|
|
|
GB_TIMA_RELOADING = 1,
|
|
|
|
GB_TIMA_RELOADED = 2
|
|
|
|
};
|
2018-02-23 11:16:05 +00:00
|
|
|
|
|
|
|
#define GB_HALT_VALUE (0xFFFF)
|
|
|
|
|
|
|
|
#define GB_SLEEP(gb, unit, state, cycles) do {\
|
2018-02-24 22:48:45 +00:00
|
|
|
(gb)->unit##_cycles -= (cycles) * __state_machine_divisor; \
|
2018-02-23 11:16:05 +00:00
|
|
|
if ((gb)->unit##_cycles <= 0) {\
|
|
|
|
(gb)->unit##_state = state;\
|
|
|
|
return;\
|
|
|
|
unit##state:; \
|
|
|
|
}\
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define GB_HALT(gb, unit) (gb)->unit##_cycles = GB_HALT_VALUE
|
|
|
|
|
2018-02-24 22:48:45 +00:00
|
|
|
#define GB_STATE_MACHINE(gb, unit, cycles, divisor) \
|
|
|
|
static const int __state_machine_divisor = divisor;\
|
2018-02-23 11:16:05 +00:00
|
|
|
(gb)->unit##_cycles += cycles; \
|
|
|
|
if ((gb)->unit##_cycles <= 0 || (gb)->unit##_cycles == GB_HALT_VALUE) {\
|
|
|
|
return;\
|
|
|
|
}\
|
|
|
|
switch ((gb)->unit##_state)
|
2017-04-17 17:16:17 +00:00
|
|
|
#endif
|
|
|
|
|
2018-02-23 11:16:05 +00:00
|
|
|
#define GB_STATE(gb, unit, state) case state: goto unit##state
|
|
|
|
|
2018-02-23 13:33:44 +00:00
|
|
|
#define GB_UNIT(unit) int32_t unit##_cycles, unit##_state
|
2018-02-23 11:16:05 +00:00
|
|
|
|
2016-03-30 20:07:55 +00:00
|
|
|
#endif /* timing_h */
|