-
Notifications
You must be signed in to change notification settings - Fork 0
/
nes.c
60 lines (51 loc) · 1.35 KB
/
nes.c
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
/*
* NES Emulator
*
* Author: Rahmet Ali Ölmez
* February 2020
*
* +------+----------------------------------------+
* | | Nintendo |||||||| |
* | | Entertainment System |||||||| |
* | +-----------------------------|||||||| |
* | |||||||| |
* | |||||||| |
* | +-----+ +-----+ |||||||| |
* | +-----+ +-----+ ||:||:|| |
* \ |||||||| /
* +-------------------------------------------+
*/
#include"nes.h"
#include"cpu.h"
#include"memory.h"
#include<stdlib.h>
#include<stdio.h>
nes_t* nes_create()
{
nes_t* nes = malloc(sizeof(nes_t));
nes->cpu = cpu_create();
nes->memory = memory_create();
nes_reset(nes);
return nes;
}
void nes_reset(nes_t* nes)
{
cpu_reset(nes->cpu);
memory_clear(nes->memory);
}
void nes_load_cartridge(nes_t* nes, const char* file_path)
{
}
void nes_run(nes_t* nes)
{
memory_write(nes->memory, nes->cpu->reg_pc, 0xaf);
printf("ram at pc: 0x%x\n", memory_read(nes->memory, nes->cpu->reg_pc));
printf("pc: 0x%x\n", nes->cpu->reg_pc);
cpu_execute(nes->cpu, nes->memory);
}
void nes_close(nes_t* nes)
{
cpu_close(nes->cpu);
memory_close(nes->memory);
free(nes);
}