-
Notifications
You must be signed in to change notification settings - Fork 1
/
mem.h
80 lines (60 loc) · 1.2 KB
/
mem.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
#ifndef __MEM_H__
#define __MEM_H__
#include "defs.h"
#include "sound.h"
#include "regs.h"
#include "hw.h"
#define MBC_NONE 0
#define MBC_MBC1 1
#define MBC_MBC2 2
#define MBC_MBC3 3
#define MBC_MBC5 5
#define MBC_RUMBLE 15
#define MBC_HUC1 0xC1
#define MBC_HUC3 0xC3
struct mbc
{
int type;
int model;
int rombank;
int rambank;
int romsize;
int ramsize;
int enableram;
int batt;
byte *rmap[0x10], *wmap[0x10];
};
struct rom
{
byte (*bank)[16384];
char name[20];
};
struct ram
{
byte hi[256];
byte ibank[8][4096];
byte (*sbank)[8192];
//byte **sbank;
int loaded;
};
extern struct mbc mbc;
extern struct rom rom;
extern struct ram ram;
//extern int david_block_end;
void mem_updatemap();
void ioreg_write(byte r, byte b);
byte ioreg_read(byte r);
void mbc_write(int a, byte b);
int mem_write(int a, byte b);
byte mem_read(int a);
void mbc_reset();
void mem_stop();
#define READB(a) ( mbc.rmap[(a)>>12] \
? mbc.rmap[(a)>>12][(a)] \
: mem_read((a)) )
#define READW(a) ( READB((a)) | ((word)READB((a)+1)<<8) )
#define WRITEB(a, b) ( mbc.wmap[(a)>>12] \
? ( mbc.wmap[(a)>>12][(a)] = (b) ) \
: ( mem_write((a), (b)), (b) ) )
#define WRITEW(a, w) ( WRITEB((a), (w)&0xFF), WRITEB((a)+1, (w)>>8) )
#endif