Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libgambatte/include/gambatte.h
2 views
1
/***************************************************************************
2
* Copyright (C) 2007 by Sindre Aamås *
3
* [email protected] *
4
* *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License version 2 as *
7
* published by the Free Software Foundation. *
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 version 2 for more details. *
13
* *
14
* You should have received a copy of the GNU General Public License *
15
* version 2 along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18
***************************************************************************/
19
#ifndef GAMBATTE_H
20
#define GAMBATTE_H
21
22
#include "gbint.h"
23
#include <string>
24
#include <sstream>
25
#include <cstdint>
26
#include "newstate.h"
27
28
namespace gambatte {
29
enum { BG_PALETTE = 0, SP1_PALETTE = 1, SP2_PALETTE = 2 };
30
31
typedef void (*CDCallback)(int32_t addr, int32_t addrtype, int32_t flags);
32
33
enum eCDLog_AddrType
34
{
35
eCDLog_AddrType_ROM, eCDLog_AddrType_HRAM, eCDLog_AddrType_WRAM, eCDLog_AddrType_CartRAM,
36
eCDLog_AddrType_None
37
};
38
39
enum eCDLog_Flags
40
{
41
eCDLog_Flags_ExecFirst = 1,
42
eCDLog_Flags_ExecOperand = 2,
43
eCDLog_Flags_Data = 4,
44
};
45
46
class GB {
47
public:
48
GB();
49
~GB();
50
51
enum LoadFlag {
52
FORCE_DMG = 1, /**< Treat the ROM as not having CGB support regardless of what its header advertises. */
53
GBA_CGB = 2, /**< Use GBA intial CPU register values when in CGB mode. */
54
MULTICART_COMPAT = 4 /**< Use heuristics to detect and support some multicart MBCs disguised as MBC1. */
55
};
56
57
/** Load ROM image.
58
*
59
* @param romfile Path to rom image file. Typically a .gbc, .gb, or .zip-file (if zip-support is compiled in).
60
* @param flags ORed combination of LoadFlags.
61
* @return 0 on success, negative value on failure.
62
*/
63
int load(const char *romfiledata, unsigned romfilelength, std::uint32_t now, unsigned flags = 0);
64
65
/** Emulates until at least 'samples' stereo sound samples are produced in the supplied buffer,
66
* or until a video frame has been drawn.
67
*
68
* There are 35112 stereo sound samples in a video frame.
69
* May run for up to 2064 stereo samples too long.
70
* A stereo sample consists of two native endian 2s complement 16-bit PCM samples,
71
* with the left sample preceding the right one. Usually casting soundBuf to/from
72
* short* is OK and recommended. The reason for not using a short* in the interface
73
* is to avoid implementation-defined behaviour without compromising performance.
74
*
75
* Returns early when a new video frame has finished drawing in the video buffer,
76
* such that the caller may update the video output before the frame is overwritten.
77
* The return value indicates whether a new video frame has been drawn, and the
78
* exact time (in number of samples) at which it was drawn.
79
*
80
* @param soundBuf buffer with space >= samples + 2064
81
* @param samples in: number of stereo samples to produce, out: actual number of samples produced
82
* @return sample number at which the video frame was produced. -1 means no frame was produced.
83
*/
84
long runFor(gambatte::uint_least32_t *soundBuf, unsigned &samples);
85
86
void blitTo(gambatte::uint_least32_t *videoBuf, int pitch);
87
88
void setLayers(unsigned mask);
89
90
/** Reset to initial state.
91
* Equivalent to reloading a ROM image, or turning a Game Boy Color off and on again.
92
*/
93
void reset(std::uint32_t now);
94
95
/** @param palNum 0 <= palNum < 3. One of BG_PALETTE, SP1_PALETTE and SP2_PALETTE.
96
* @param colorNum 0 <= colorNum < 4
97
*/
98
void setDmgPaletteColor(unsigned palNum, unsigned colorNum, unsigned rgb32);
99
100
void setCgbPalette(unsigned *lut);
101
102
/** Sets the callback used for getting input state. */
103
void setInputGetter(unsigned (*getInput)());
104
105
void setReadCallback(void (*callback)(unsigned));
106
void setWriteCallback(void (*callback)(unsigned));
107
void setExecCallback(void (*callback)(unsigned));
108
void setCDCallback(CDCallback);
109
void setTraceCallback(void (*callback)(void *));
110
void setScanlineCallback(void (*callback)(), int sl);
111
void setRTCCallback(std::uint32_t (*callback)());
112
113
/** Returns true if the currently loaded ROM image is treated as having CGB support. */
114
bool isCgb() const;
115
116
/** Returns true if a ROM image is loaded. */
117
bool isLoaded() const;
118
119
/** Writes persistent cartridge data to disk. NOT Done implicitly on ROM close. */
120
void loadSavedata(const char *data);
121
int saveSavedataLength();
122
void saveSavedata(char *dest);
123
124
// 0 = vram, 1 = rom, 2 = wram, 3 = cartram, 4 = oam, 5 = hram
125
bool getMemoryArea(int which, unsigned char **data, int *length);
126
127
/** ROM header title of currently loaded ROM image. */
128
const std::string romTitle() const;
129
130
unsigned char ExternalRead(unsigned short addr);
131
void ExternalWrite(unsigned short addr, unsigned char val);
132
133
int LinkStatus(int which);
134
135
void GetRegs(int *dest);
136
137
template<bool isReader>void SyncState(NewState *ns);
138
139
private:
140
struct Priv;
141
Priv *const p_;
142
143
GB(const GB &);
144
GB & operator=(const GB &);
145
};
146
}
147
148
#endif
149
150