blob: 3ed7a22915e4079932a2da56f22c0664ee1b28a8 (
plain)
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
|
#include "nes/nes.hh"
#include "nes/mapper.hh"
#include "nes/display.hh"
#include "nes/util/rgb.hh"
#include <iostream>
namespace nes
{
nes::nes(cartridge cartridge, display& display)
: cartridge_{ std::move(cartridge) }
, display_{ display }
, mapper_{ mapper::select(cartridge_) }
, ppu_{ cpu_, mapper_, display_ }
, cpu_{ ppu_, mapper_, controller_1_, controller_2_ }
{
if (!cartridge_.is_valid())
{
std::cerr << "Cartridge not valid!" << std::endl;
std::abort();
}
display_.clear(rgb{});
display_.switch_buffers();
display_.clear(rgb{});
}
auto nes::step(std::chrono::microseconds const delta) -> void
{
step(cycle_count::from_duration(delta));
}
auto nes::step(cycle_count const delta) -> void
{
current_cycles_ += delta;
cpu_.step_to(current_cycles_);
ppu_.step_to(current_cycles_);
}
auto nes::snapshot() -> test::status
{
auto res = test::status{};
res.sram = std::vector(cartridge_.get_ram(), cartridge_.get_ram() + cartridge_.get_ram_length());
cpu_.snapshot(res);
return res;
}
} // namespace nes
|