Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libgambatte/src/cpu.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 CPU_H
20
#define CPU_H
21
22
#include "memory.h"
23
#include "newstate.h"
24
25
namespace gambatte {
26
27
class CPU {
28
Memory memory;
29
30
unsigned long cycleCounter_;
31
32
unsigned short PC;
33
unsigned short SP;
34
35
unsigned HF1, HF2, ZF, CF;
36
37
unsigned char A, B, C, D, E, /*F,*/ H, L;
38
39
bool skip;
40
41
void process(unsigned long cycles);
42
43
void (*tracecallback)(void *);
44
45
public:
46
47
CPU();
48
// void halt();
49
50
// unsigned interrupt(unsigned address, unsigned cycleCounter);
51
52
long runFor(unsigned long cycles);
53
void setStatePtrs(SaveState &state);
54
void loadState(const SaveState &state);
55
void setLayers(unsigned mask) { memory.setLayers(mask); }
56
57
void loadSavedata(const char *data) { memory.loadSavedata(data); }
58
int saveSavedataLength() {return memory.saveSavedataLength(); }
59
void saveSavedata(char *dest) { memory.saveSavedata(dest); }
60
61
bool getMemoryArea(int which, unsigned char **data, int *length) { return memory.getMemoryArea(which, data, length); }
62
63
void setVideoBuffer(uint_least32_t *const videoBuf, const int pitch) {
64
memory.setVideoBuffer(videoBuf, pitch);
65
}
66
67
void setInputGetter(unsigned (*getInput)()) {
68
memory.setInputGetter(getInput);
69
}
70
71
void setReadCallback(void (*callback)(unsigned)) {
72
memory.setReadCallback(callback);
73
}
74
75
void setWriteCallback(void (*callback)(unsigned)) {
76
memory.setWriteCallback(callback);
77
}
78
79
void setExecCallback(void (*callback)(unsigned)) {
80
memory.setExecCallback(callback);
81
}
82
83
void setCDCallback(CDCallback cdc) {
84
memory.setCDCallback(cdc);
85
}
86
87
void setTraceCallback(void (*callback)(void *)) {
88
tracecallback = callback;
89
}
90
91
void setScanlineCallback(void (*callback)(), int sl) {
92
memory.setScanlineCallback(callback, sl);
93
}
94
95
void setRTCCallback(std::uint32_t (*callback)()) {
96
memory.setRTCCallback(callback);
97
}
98
99
int load(const char *romfiledata, unsigned romfilelength, bool forceDmg, bool multicartCompat) {
100
return memory.loadROM(romfiledata, romfilelength, forceDmg, multicartCompat);
101
}
102
103
bool loaded() const { return memory.loaded(); }
104
const char * romTitle() const { return memory.romTitle(); }
105
106
void setSoundBuffer(uint_least32_t *const buf) { memory.setSoundBuffer(buf); }
107
unsigned fillSoundBuffer() { return memory.fillSoundBuffer(cycleCounter_); }
108
109
bool isCgb() const { return memory.isCgb(); }
110
111
void setDmgPaletteColor(unsigned palNum, unsigned colorNum, unsigned rgb32) {
112
memory.setDmgPaletteColor(palNum, colorNum, rgb32);
113
}
114
115
void setCgbPalette(unsigned *lut) {
116
memory.setCgbPalette(lut);
117
}
118
119
//unsigned char ExternalRead(unsigned short addr) { return memory.read(addr, cycleCounter_); }
120
unsigned char ExternalRead(unsigned short addr) { return memory.peek(addr); }
121
void ExternalWrite(unsigned short addr, unsigned char val) { memory.write_nocb(addr, val, cycleCounter_); }
122
123
int LinkStatus(int which) { return memory.LinkStatus(which); }
124
125
void GetRegs(int *dest);
126
127
template<bool isReader>void SyncState(NewState *ns);
128
};
129
130
}
131
132
#endif
133
134