-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNESEmulator.cpp
More file actions
84 lines (67 loc) · 1.66 KB
/
NESEmulator.cpp
File metadata and controls
84 lines (67 loc) · 1.66 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
#include "SDL.h"
#include <stdio.h>
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <iomanip>
#include "APU.h"
#include "PPU.h"
#include "CPU.h"
#include "Cartridge.h"
#define WIDTH 256
#define HEIGHT 240
int main(int argc, char* argv[])
{
SDL_Event evt;
bool running = true;
int* pixels = new int[WIDTH * HEIGHT];
int pitch = WIDTH * 4;
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* window = SDL_CreateWindow
("NES Emulator", // window's title
100, 100, // coordinates on the screen, in pixels, of the window's upper left corner
WIDTH * 2, HEIGHT * 2, // window's length and height in pixels
SDL_WINDOW_OPENGL);
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
// Pixel manipulation through texture of the surface.
SDL_Texture* buffer = SDL_CreateTexture(renderer,
SDL_PIXELFORMAT_RGBA8888,
SDL_TEXTUREACCESS_STREAMING,
WIDTH,
HEIGHT);
SDL_LockTexture(buffer,
NULL, // NULL means the *whole texture* here.
(void**)(&pixels),
&pitch);
// Manipulate pixels here.
SDL_UnlockTexture(buffer);
//std::string filename("C:\\MyWork\\Super_mario_brothers.nes");
std::string filename("C:\\MyWork\\ex1.dasm.rom");
Cartridge::load(filename.c_str());
APU::initialize();
PPU::initialize();
CPU::power();
while(running)
{
SDL_PollEvent(&evt);
switch(evt.type)
{
case SDL_QUIT:
running = false;
break;
}
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, buffer, NULL, NULL);
SDL_RenderPresent(renderer);
if (Cartridge::loaded())
{
for (int i = 0; i < 3; ++i)
PPU::execute();
CPU::execute();
}
}
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}