-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
54 lines (42 loc) · 1.33 KB
/
main.cpp
File metadata and controls
54 lines (42 loc) · 1.33 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
#include <iostream>
#include <array>
#include <cstdint>
#include <string>
#include "ram.hpp"
#include "display.hpp"
#include "cpu.hpp"
#include "log.hpp"
int main(int argc, const char** argv)
{
if(argc != 2) {
LOG(ERROR) << "Incorrect arguments given. Usage " << argv[0]
<< " [ROM]";
exit(1);
}
Chip8Ram ram;
ram.load_ram(std::string(argv[1]));
Chip8Display display(ram, 800, 600);
Chip8CPU cpu(ram, display);
/* Write a (very simple!) program into ram */
// ram.write_instruction(0x200, 0xF00A); /* Ld char into V0 */
// ram.write_instruction(0x202, 0xF029); /* Find sprite for char in V0 */
// ram.write_instruction(0x204, 0x00E0); /* Clear screen */
// ram.write_instruction(0x206, 0xD005); /* Draw said sprite */
// ram.write_instruction(0x208, 0x1200); /* Jump to 0x200 */
sf::RenderWindow window(sf::VideoMode(800, 600), "Chip8");
while(window.isOpen()) {
sf::Event event;
while(window.pollEvent(event)) {
if(event.type == sf::Event::Closed)
window.close();
}
cpu.update_timers();
if(cpu.is_blocked()) {
continue;
}
cpu.execute(cpu.get_next_instruction());
if(display.needs_update())
display.draw(window);
}
return 0;
}