-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
128 lines (88 loc) · 1.92 KB
/
main.cpp
File metadata and controls
128 lines (88 loc) · 1.92 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
#include "modules/library.h"
#include "modules/memory.h"
#include "modules/cpu.h"
#include "modules/SDLManager.h"
#include "modules/cia1.h"
#include "modules/cia2.h"
#include "modules/loader.h"
void test_cpu(CPU*);
Memory *mem;
CPU *cpu;
SDLManager *sdl;
bool iterate = true;
void dump_mem_handler(int s){
cout<<endl<<"Dump Video Mem.."<<endl;
//mem->dump_memory(0x400,1000); //1000 byte not 1024!
mem->dump_color_memory(); //1000 byte not 1024!
}
void dump_cpu_handler(int s){
cout<<endl<<"Dump CPU"<<endl;
cout<<hex<<"PC: "<<unsigned(cpu->PC)<<endl;
//sdl->checkFPS();
}
void chiudi(int s){
iterate = false;
//SDL_Quit();
//exit(s);
}
int main(int argc, const char **argv){
//CTRL-Z
//signal(SIGTSTP,dump_mem_handler);
signal(SIGTSTP,dump_cpu_handler);
signal(SIGINT,chiudi);
VIC *vic = new VIC();
CIA1 *cia1 = new CIA1();
CIA2 *cia2 = new CIA2();
mem = new Memory();
mem->load_kernal_and_basic(KERNAL_BASIC_ROM);
mem->load_charset(CHARSET_ROM);
cpu = new CPU(mem);
sdl = new SDLManager();
cia1->setCPU(cpu);
cia1->setSDL(sdl);
cia2->setCPU(cpu);
cia2->setSDL(sdl);
mem->setVIC(vic);
mem->setCIA1(cia1);
mem->setCIA2(cia2);
vic->setMemory(mem);
vic->setSDL(sdl);
vic->setCPU(cpu);
vic->setCIA1(cia1);
vic->setCIA2(cia2);
Loader *loader = nullptr;
if(argc > 1){
const string s = argv[1];
loader = new Loader(cpu,mem,s);
}
while(iterate){
cpu->clock();
cia1->clock();
vic->clock();
if(loader)
loader->clock();
}
}
void test_cpu(CPU *cpu)
{
uint16_t pc=0;
uint8_t opcode;
bool loop = true;
while(loop){
if(pc == cpu->PC){
cout<<"infinite loop at "<<hex<<unsigned(pc)<<endl;
break;
} else if(cpu->PC == 0x3463){
cout<<"test passed!"<<endl;
break;
}
pc = cpu->PC;
opcode = cpu->fetch();
cout<<"OPCODE: "<<hex<<unsigned(opcode)<<endl;
loop = cpu->decode(opcode);
if(loop == false){
cout<<"Bloccato "<<endl;
}
cpu->dump_reg();
}
}