Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libmeteor/include/ameteor/memory.hpp
2 views
1
// Meteor - A Nintendo Gameboy Advance emulator
2
// Copyright (C) 2009-2011 Philippe Daouadi
3
//
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17
#ifndef __MEMORY_H__
18
#define __MEMORY_H__
19
20
#include "cartmem.hpp"
21
//XXX
22
#include "eeprom.hpp"
23
24
#include <stdint.h>
25
#include <string>
26
#include <istream>
27
#include <ostream>
28
29
namespace AMeteor
30
{
31
class Memory
32
{
33
public :
34
// in cycles
35
static const uint32_t CART_SAVE_TIME = 16*1024*1024; // 1 second
36
37
enum CartType
38
{
39
CTYPE_UNKNOWN,
40
CTYPE_EEPROM512,
41
CTYPE_EEPROM8192,
42
CTYPE_FLASH64,
43
CTYPE_FLASH128,
44
CTYPE_SRAM
45
};
46
enum CartError
47
{
48
CERR_NO_ERROR,
49
CERR_NOT_FOUND,
50
CERR_FAIL
51
};
52
53
Memory ();
54
~Memory ();
55
56
uint8_t GetCartType () const
57
{
58
return m_carttype;
59
}
60
// erases cartridge memory
61
void SetCartTypeFromSize (uint32_t size);
62
void SetCartType (uint8_t type);
63
//void SetCartFile (const char* filename)
64
//{
65
// m_cartfile = filename;
66
//}
67
68
void Reset (uint32_t params = ~0);
69
void ClearWbram ();
70
void ClearWcram ();
71
void ClearPalette ();
72
void ClearVram ();
73
void ClearOam ();
74
void SoftReset ();
75
76
bool LoadBios (const char* filename);
77
void LoadBios (const uint8_t* data, uint32_t size);
78
void UnloadBios ()
79
{
80
if (m_brom)
81
{
82
delete [] m_brom;
83
m_brom = NULL;
84
}
85
}
86
bool LoadRom (const char* filename);
87
void LoadRom (const uint8_t* data, uint32_t size);
88
//CartError LoadCart ();
89
bool LoadCart (const uint8_t* data, uint32_t size);
90
bool SaveCart (uint8_t** data, uint32_t* size);
91
void SaveCartDestroy(uint8_t* data);
92
#ifdef __LIBRETRO__
93
bool LoadCartInferred ();
94
#endif
95
bool HasCart () const
96
{
97
return m_cart;
98
}
99
100
void DeleteCart();
101
102
bool HasBios () const
103
{
104
return m_brom;
105
}
106
107
uint8_t GetCycles16NoSeq (uint32_t add, uint32_t count);
108
uint8_t GetCycles16Seq (uint32_t add, uint32_t count);
109
uint8_t GetCycles32NoSeq (uint32_t add, uint32_t count);
110
uint8_t GetCycles32Seq (uint32_t add, uint32_t count);
111
void UpdateWaitStates (uint16_t waitcnt);
112
113
uint8_t* GetRealAddress(uint32_t add, uint8_t size = 0);
114
115
bool SaveState (std::ostream& stream);
116
bool LoadState (std::istream& stream);
117
118
uint8_t Peek8 (uint32_t add);
119
120
// TODO make const members
121
uint8_t Read8 (uint32_t add);
122
uint16_t Read16 (uint32_t add);
123
uint32_t Read32 (uint32_t add);
124
125
void Write8 (uint32_t add, uint8_t val);
126
void Write16 (uint32_t add, uint16_t val);
127
void Write32 (uint32_t add, uint32_t val);
128
129
void WriteEepromDma (uint32_t src, uint16_t size);
130
//void ReadEepromDma (uint32_t dest, uint16_t size);
131
132
void TimeEvent ();
133
134
uint8_t* GetMemoryArea(int which);
135
136
private :
137
// times for a 8 or 16 bits access
138
uint8_t m_memtime[0xF];
139
// times for a sequential 8 or 16 bits access in GamePak ROM
140
uint8_t m_memtimeseq[0x3];
141
142
// General Internal Memory
143
uint8_t* m_brom; // BIOS - System ROM
144
uint8_t* m_wbram; // WRAM - On-board Work RAM
145
uint8_t* m_wcram; // WRAM - In-chip Work RAM
146
// Internal Display Memory
147
uint8_t* m_pram; // BG/OBJ Palette RAM
148
uint8_t* m_vram; // VRAM - Video RAM
149
uint8_t* m_oram; // OAM - OBJ Attributes
150
// External Memory (Game Pak)
151
uint8_t* m_rom; // Game Pake ROM/FlashROM (max 32MB)
152
153
uint8_t m_carttype;
154
CartMem* m_cart;
155
//std::string m_cartfile;
156
157
uint8_t ReadCart (uint16_t add);
158
void WriteCart (uint16_t add, uint8_t val);
159
};
160
}
161
162
#endif
163
164