git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

Core/timing.h

      1 #pragma once
      2 
      3 #include "defs.h"
      4 
      5 typedef enum {
      6     GB_RTC_MODE_SYNC_TO_HOST,
      7     GB_RTC_MODE_ACCURATE,
      8 } GB_rtc_mode_t;
      9 
     10 /* RTC emulation mode */
     11 void GB_set_rtc_mode(GB_gameboy_t *gb, GB_rtc_mode_t mode);
     12 
     13 /* Speed multiplier for the RTC, mostly for TAS syncing */
     14 void GB_set_rtc_multiplier(GB_gameboy_t *gb, double multiplier);
     15 
     16 #ifdef GB_INTERNAL
     17 internal void GB_advance_cycles(GB_gameboy_t *gb, uint8_t cycles);
     18 internal void GB_emulate_timer_glitch(GB_gameboy_t *gb, uint8_t old_tac, uint8_t new_tac);
     19 internal bool GB_timing_sync_turbo(GB_gameboy_t *gb); /* Returns true if should skip frame */
     20 internal void GB_timing_sync(GB_gameboy_t *gb);
     21 internal void GB_set_internal_div_counter(GB_gameboy_t *gb, uint16_t value);
     22 internal void GB_serial_master_edge(GB_gameboy_t *gb);
     23 internal void GB_rtc_set_time(GB_gameboy_t *gb, uint64_t time);
     24 
     25 #define GB_SLEEP(gb, unit, state, cycles) do {\
     26     (gb)->unit##_cycles -= (cycles) * __state_machine_divisor; \
     27     if (unlikely((gb)->unit##_cycles <= 0)) {\
     28         (gb)->unit##_state = state;\
     29         return;\
     30         unit##state:; \
     31     }\
     32 } while (0)
     33 
     34 #define GB_BATCHPOINT(gb, unit, state, cycles) do {\
     35 unit##state:; \
     36 if (likely(__state_machine_allow_batching && (gb)->unit##_cycles < (cycles * 2))) {\
     37     (gb)->unit##_state = state;\
     38     return;\
     39 }\
     40 } while (0)
     41 
     42 #define GB_BATCHED_CYCLES(gb, unit) ((gb)->unit##_cycles / __state_machine_divisor)
     43 
     44 #define GB_STATE_MACHINE(gb, unit, cycles, divisor) \
     45 static const int __state_machine_divisor = divisor;\
     46 (gb)->unit##_cycles += cycles; \
     47 if ((gb)->unit##_cycles <= 0) {\
     48     return;\
     49 }\
     50 switch ((gb)->unit##_state)
     51 
     52 #define GB_BATCHABLE_STATE_MACHINE(gb, unit, cycles, divisor, allow_batching) \
     53 const bool __state_machine_allow_batching = (allow_batching); \
     54 GB_STATE_MACHINE(gb, unit, cycles, divisor)
     55 
     56 #define GB_STATE(gb, unit, state) case state: goto unit##state
     57 #endif
     58 
     59 #define GB_UNIT(unit) int32_t unit##_cycles, unit##_state

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.