-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathppu.cpp
More file actions
201 lines (163 loc) · 4.01 KB
/
ppu.cpp
File metadata and controls
201 lines (163 loc) · 4.01 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// #include <sfc/sfc.hpp>
namespace SuperFamicom {
PPU ppu;
#include "main.cpp"
#include "io.cpp"
#include "mosaic.cpp"
#include "background.cpp"
#include "object.cpp"
#include "window.cpp"
#include "screen.cpp"
#include "serialization.cpp"
#include "counter/serialization.cpp"
PPU::PPU() :
bg1(Background::ID::BG1),
bg2(Background::ID::BG2),
bg3(Background::ID::BG3),
bg4(Background::ID::BG4) {
ppu1.version = 1; //allowed values: 1
ppu2.version = 3; //allowed values: 1, 2, 3
for(uint l = 0; l < 16; l++) {
for(uint r = 0; r < 32; r++) {
for(uint g = 0; g < 32; g++) {
for(uint b = 0; b < 32; b++) {
double luma = (double)l / 15.0;
uint ar = (luma * r + 0.5);
uint ag = (luma * g + 0.5);
uint ab = (luma * b + 0.5);
lightTable[l][(r << 10) + (g << 5) + b] = (ab << 10) + (ag << 5) + ar;
}
}
}
}
}
PPU::~PPU() {
}
auto PPU::synchronizeCPU() -> void {
if(clock >= 0) scheduler.resume(cpu.thread);
}
auto PPU::step() -> void {
tick(2);
clock += 2;
synchronizeCPU();
}
auto PPU::step(uint clocks) -> void {
clocks >>= 1;
while(clocks--) {
tick(2);
clock += 2;
synchronizeCPU();
}
}
auto PPU::Enter() -> void {
while(true) {
scheduler.synchronize();
ppu.main();
}
}
auto PPU::load() -> bool {
ppu1.version = 1;
ppu2.version = 3;
vram.mask = 0x7fff;
return true;
}
auto PPU::power(bool reset) -> void {
// create(Enter, system.cpuFrequency());
PPUcounter::reset();
memory::fill<uint16>(output, 512 * 480);
// function<uint8 (uint, uint8)> reader{&PPU::readIO, this};
// function<void (uint, uint8)> writer{&PPU::writeIO, this};
// bus.map(reader, writer, "00-3f,80-bf:2100-213f");
if(!reset) random.array((uint8*)vram.data, sizeof(vram.data));
ppu1.mdr = random.bias(0xff);
ppu2.mdr = random.bias(0xff);
latch.vram = random();
latch.oam = random();
latch.cgram = random();
latch.bgofsPPU1 = random();
latch.bgofsPPU2 = random();
latch.mode7 = random();
latch.counters = false;
latch.hcounter = 0;
latch.vcounter = 0;
latch.oamAddress = 0x0000;
latch.cgramAddress = 0x00;
//$2100 INIDISP
io.displayDisable = true;
io.displayBrightness = 0;
//$2102 OAMADDL
//$2103 OAMADDH
io.oamBaseAddress = random() & ~1;
io.oamAddress = random();
io.oamPriority = random();
//$2105 BGMODE
io.bgPriority = false;
io.bgMode = 0;
//$210d BG1HOFS
io.hoffsetMode7 = random();
//$210e BG1VOFS
io.voffsetMode7 = random();
//$2115 VMAIN
io.vramIncrementMode = random.bias(1);
io.vramMapping = random();
io.vramIncrementSize = 1;
//$2116 VMADDL
//$2117 VMADDH
io.vramAddress = random();
//$211a M7SEL
io.repeatMode7 = random();
io.vflipMode7 = random();
io.hflipMode7 = random();
//$211b M7A
io.m7a = random();
//$211c M7B
io.m7b = random();
//$211d M7C
io.m7c = random();
//$211e M7D
io.m7d = random();
//$211f M7X
io.m7x = random();
//$2120 M7Y
io.m7y = random();
//$2121 CGADD
io.cgramAddress = random();
io.cgramAddressLatch = random();
//$2133 SETINI
io.extbg = random();
io.pseudoHires = random();
io.overscan = false;
io.interlace = false;
//$213c OPHCT
io.hcounter = 0;
//$213d OPVCT
io.vcounter = 0;
mosaic.power();
bg1.power();
bg2.power();
bg3.power();
bg4.power();
obj.power();
window.power();
screen.power();
updateVideoMode();
}
auto PPU::refresh() -> void {
auto output = this->output;
auto pitch = 512;
auto width = 512;
auto height = 480;
// if(configuration.video.blurEmulation) {
// for(uint y : range(height)) {
// auto data = output + y * pitch;
// for(uint x : range(width - 1)) {
// auto a = data[x + 0];
// auto b = data[x + 1];
// data[x] = (a + b - ((a ^ b) & 0x0421)) >> 1;
// }
// }
// }
// if(auto device = controllerPort2.device) device->draw(output, pitch * sizeof(uint16), width, height);
platform->videoFrame(output, pitch * sizeof(uint16), width, height, /* scale = */ 1);
}
}