-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
79 lines (64 loc) · 1.6 KB
/
main.cpp
File metadata and controls
79 lines (64 loc) · 1.6 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
#include <iostream>
#include "Cartridge.h"
#include "Memory.h"
#include "Cpu.h"
#include "CpuTypes.h"
#include "Video.h"
#include "Debugger/Debugger.h"
#include <assert.h>
int main(int argc, char** argv)
{
if ( argc < 2 )
{
std::cout << "Please provide the rom path";
return -1;
}
Cartridge cartridge( argv[1] );
if ( !cartridge.IsLoaded() )
{
std::cout << "The cartridge couldn't be loaded";
return -1;
}
cartridge.PrintDetails();
Video video( &cartridge );
Memory memory( &cartridge, &video );
video.Init( &memory );
Cpu cpu( &memory );
Debugger debugger( &cpu, &memory, &video );
debugger.StartDebugger();
bool quit = false;
u32 currentCycles = 0;
while ( !quit )
{
currentCycles += cpu.Update();
video.Update( currentCycles );
const DebuggerUpdateResult result = debugger.Update( 0.f, currentCycles );
switch ( result )
{
case DebuggerUpdateResult::QUIT:
{
quit = true;
}
break;
case DebuggerUpdateResult::RESET:
{
debugger.ResetDebugger();
memory.Reset();
video.Reset();
cpu.Reset();
currentCycles = 0;
}
break;
case DebuggerUpdateResult::CONTINUE:
default:
{
// Nothing to do here
}
}
if ( currentCycles >= AVERAGE_CYCLES_PER_FRAME )
{
currentCycles = 0;
}
}
return 0;
}