-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bus.h
117 lines (96 loc) · 2.56 KB
/
Bus.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#ifndef BUS_H
#define BUS_H
#include <cstdint>
#include <string>
#include <iostream>
#include <sstream>
#include <SDL2/SDL.h>
//#include <SFML/Graphics.hpp>
#include "MBC.h"
class Z80_Gameboy;
class PPU_Gameboy;
class Timer_Gameboy;
class Bus
{
private:
Z80_Gameboy& cpu;
PPU_Gameboy& ppu;
Timer_Gameboy& tim;
uint8_t if_reg = 0;
uint8_t ie = 0;
uint8_t controller_reg = 0x83;
enum Controller_Key {Cont_RIGHT,Cont_LEFT,Cont_UP,Cont_DOWN, Cont_A,Cont_B,Cont_SELECT,Cont_START,Cont_KEYNB};
enum Controller_Signal {Sig_DOWN=0,Sig_UP=1};
Controller_Signal controller_keys_state[Cont_KEYNB];
uint8_t sb,sc;
std::string msg = "";
bool stopMode = false;
uint8_t ram[0x10000]; //TODO: allocate less memory as most of it isn't used
SDL_Renderer *ren;
SDL_Window *win;
bool blockMemoryWrite = false;
MBC * cartridge = nullptr;
std::string cartridgePath;
bool stepping = false;
bool debug = false;
public:
Bus(Z80_Gameboy& c,PPU_Gameboy& p,Timer_Gameboy& t);
~Bus();
void loadCartridge(std::string path);
void write(uint16_t adr,uint8_t data);
uint8_t read(uint16_t adr);
void triggerStopMode(bool stop);
void triggerDebugMode(bool debugMode);
void run();
std::string showMemory(uint16_t src,uint16_t dst)
{
std::stringstream ss;
ss << std::showbase << std::hex;
ss << "Memory Range from "<<src<<" to "<<dst<< "\nAdress: value\n";
for(uint16_t i = src; i <= dst; i++)
{
ss << i << ": " << (int)ram[i]<<"\n";
}
return ss.str();
}
void disassemble();
void testProgram()
{
uint8_t fibo[21] = {
0b00'100'001,0x00,0x03,
0b00'000'110,0x01,
0b00'001'110,0x01,
0b00'010'110,0x01,
0b01'111'000,
0b10'000'001,
0b00'100'010,
0b01'001'000,
0b01'000'111,
0b00'010'100,
0b01'111'010,
0b11'111'110,10,
0b11'000'010,0x09,0x01
};
uint8_t testDAA[] = {
0b00'010'001,0x00,0x9a,
0b11'010'101,
0b11'110'001,
0b00'100'111,
0b00'010'100,
0b11'000'010,0x03,0x01,
0b01'111'011,
0b11'000'110,0x10,
0b01'011'111,
0b11'000'010,0x03,0x01
};
for(uint16_t i = 0; i < 17; i++)
{
ram[i+0x100] = testDAA[i];
}
}
SDL_Renderer *getSDLRenderer()
{
return ren;
}
};
#endif // BUS_H