-
Notifications
You must be signed in to change notification settings - Fork 3
/
fabric.h
95 lines (75 loc) · 2.42 KB
/
fabric.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
#pragma once
#include "types.h"
#include "microcode.h"
#include "ppu.h"
#include "apu.h"
#define USE_UD struct pgf_userdata_t* __restrict ud = (struct pgf_userdata_t* __restrict)userdata;
struct pgf_userdata_t
{
struct mb_state* __restrict mb;
struct ppu_t* __restrict ppu;
struct apu_t* __restrict apu;
word _debug;
var JOYP_RAW; // A is $01, Right is $10
var JOYP;
var TIMER_SUB;
var TIMER_CNT;
var TIMER_ACCUM;
var TIMER_LOAD;
var SB;
var SC;
#if CONFIG_FORCE_ENABLE_CGB
var GDMA_SRC;
var GDMA_DST;
var GDMA_CNT;
var CGB_SPEED;
#endif
};
void pgf_timer_update_internal(struct pgf_userdata_t* __restrict ud, word ticks);
const r8* pgf_resolve_ROM(void* userdata, word addr, word bank);
word pgf_cb_ROM_(void* userdata, word addr, word data, word type);
word pgf_cb_IO_(void* userdata, word addr, word data, word type);
PGB_FUNC word pgf_cb_ROM_Dummy(void* userdata, word addr, word data, word type);
PGB_FUNC word pgf_cb_ROM_MBC1(void* userdata, word addr, word data, word type);
PGB_FUNC word pgf_cb_ROM_MBC2(void* userdata, word addr, word data, word type);
PGB_FUNC word pgf_cb_ROM_MBC3(void* userdata, word addr, word data, word type);
PGB_FUNC word pgf_cb_ROM_MBC5(void* userdata, word addr, word data, word type);
PGB_FUNC pmiDispatch pgf_get_mapper_callback(word mapper_id);
#if CONFIG_BOOTMEME
PGB_FUNC r32 pgf_cb_BOOTROM(void* userdata, r32 addr, r32 data, word type);
#endif
#if CONFIG_ENABLE_LRU
const r8* pgf_cb_ROM_LRU_(void* userdata, word addr, word bank);
#endif
static inline void pgf_timer_update(struct pgf_userdata_t* __restrict ud, word ticks)
{
if(!(ud->TIMER_CNT & 4))
return;
pgf_timer_update_internal(ud, ticks);
}
static inline const r8* pgf_resolve_ROM_internal(void* userdata, word addr, word bank)
{
const r8* res = NULL;
USE_UD;
if(addr < 0x4000)
bank = 0;
#if CONFIG_ENABLE_LRU
if(ud->mb->mi->ROM != NULL)
#endif
{
#if CONFIG_USE_FLAT_ROM
res = &ud->mb->mi->ROM[bank * 0x4000];
return &res[addr & 0x3FFF];
#else
res = ud->mb->mi->ROM[bank];
if(res != NULL)
return &res[addr & 0x3FFF];
#endif
}
#if CONFIG_ENABLE_LRU
res = ud->mb->mi->dispatch_ROM_Bank(userdata, addr & ~MICACHE_R_SEL, bank);
if(res != NULL)
return &res[((addr & 0x3FFF) & ~MICACHE_R_SEL) + (addr & MICACHE_R_SEL)];
#endif
return NULL;
}