summaryrefslogtreecommitdiff
path: root/mknes.c
diff options
context:
space:
mode:
authorPeter Fors <peter.fors@mindkiller.com>2025-04-04 01:03:19 +0200
committerPeter Fors <peter.fors@mindkiller.com>2025-04-04 01:03:19 +0200
commit8c82be43720d9e221a9e2541c9ff6151015838bb (patch)
tree6ed341720934bbf69a386e254c4e9449f9051616 /mknes.c
parent6274071e3857c1640cc5aef804cb86509ab312f9 (diff)
move read/write prg/chr/cirom data to mapper
Diffstat (limited to 'mknes.c')
-rw-r--r--mknes.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/mknes.c b/mknes.c
index 54da663..0ca6749 100644
--- a/mknes.c
+++ b/mknes.c
@@ -75,14 +75,16 @@ static GLFWwindow *window;
#define DEBUG_PRINT printf
#include "timer.c"
+#include "audio.c"
+
#include "opengl_loader.c"
#include "opengl.c"
#include "render.c"
-#include "audio.c"
+
#include "callbacks.c"
+// NES core
#include "mapper.h"
-
#include "mknes.h"
// #include "apu.c"
#include "ppu.c"
@@ -95,7 +97,6 @@ struct nes_state nstate;
static uint32_t frames;
-
int main(int argc, char **argv) {
#ifdef _WIN32
timeBeginPeriod(1);
@@ -108,11 +109,11 @@ int main(int argc, char **argv) {
// protect_opcode_lut();
ppu_reset(&nstate);
// ines2_load(&nstate, "data/nrom/10-Yard Fight (USA, Europe).nes");
- ines2_load(&nstate, "data/nrom/Balloon Fight (USA).nes");
+ // ines2_load(&nstate, "data/nrom/Balloon Fight (USA).nes");
// ines2_load(&nstate, "data/nrom/Excitebike (Japan, USA).nes");
// ines2_load(&nstate, "data/nrom/Ice Climber (USA, Europe, Korea).nes");
// ines2_load(&nstate, "data/nrom/Kung Fu (Japan, USA).nes");
- // ines2_load(&nstate, "data/nrom/Super Mario Bros. (World) (HVC-SM).nes");
+ ines2_load(&nstate, "data/nrom/Super Mario Bros. (World) (HVC-SM).nes");
// ines2_load(&nstate, "data/nrom/Urban Champion (World).nes");
// ines2_load(&nstate, "data/nrom/Wrecking Crew (World).nes");
// ines2_load(&nstate, "data/nrom/scanline.nes");
@@ -129,8 +130,8 @@ int main(int argc, char **argv) {
// ines2_load(&nstate, "data/nrom/NEStress.NES");
mapper_setup(&nstate);
- uint32_t lo = nstate.mapper.read(&nstate, 0xfffc);
- uint32_t hi = nstate.mapper.read(&nstate, 0xfffd);
+ uint32_t lo = nstate.mapper.prg_read(&nstate, 0xfffc);
+ uint32_t hi = nstate.mapper.prg_read(&nstate, 0xfffd);
nstate.cpu.pc = (hi << 8) | lo;
struct timer_handle *timer = timer_new(FRAME_INTERVAL_NS);
@@ -171,7 +172,7 @@ int main(int argc, char **argv) {
timer_start(timer);
while(!glfwWindowShouldClose(window)) {
- timer_wait(timer);
+ // timer_wait(timer);
glfwPollEvents();
// //
@@ -182,22 +183,21 @@ int main(int argc, char **argv) {
nstate.ppu.frame_ready = 0;
frames++;
- uint32_t *dst = buffer;
- uint8_t *src = nstate.ppu.pixels;
- for(uint32_t y = 0; y < 240; ++y) {
- for(uint32_t x = 0; x < 256; ++x) {
- uint8_t val = *src++;
- if(val >= 64) val = 0;
- dst[x] = nes_palette[val];
- }
- dst += BUFFER_WIDTH;
- }
-//
- apply_phosphor_decay();
- render_frame();
+ // uint32_t * restrict dst = buffer;
+ // uint8_t * restrict src = nstate.ppu.pixels;
+ // for(uint32_t y = 0; y < 240; ++y) {
+ // for(uint32_t x = 0; x < 256; ++x) {
+ // uint8_t val = *src++;
+ // if(val >= 64) val = 0;
+ // dst[x] = nes_palette[val];
+ // }
+ // dst += BUFFER_WIDTH;
+ // }
+ // apply_phosphor_decay();
+ // render_frame();
glfwSwapBuffers(window);
}
-
+printf("%d\n", frames);
glfwDestroyWindow(window);
} else {
fprintf(stderr, "Failed to create window\n");