summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Fors <peter.fors@mindkiller.com>2025-04-06 20:05:32 +0200
committerPeter Fors <peter.fors@mindkiller.com>2025-04-06 20:05:32 +0200
commitdebadc464578ac2be6b75a95f6ea6f95bfecba79 (patch)
tree0d27a48974ccb36f5fde9f945174880a37746da5
parent1372919415b23a9a596ca7211fd432328b2ac0cc (diff)
cleanup
-rw-r--r--.gitignore5
-rwxr-xr-xbuild.sh4
-rw-r--r--mapper.c2
-rw-r--r--mknes.c34
-rw-r--r--ppu.c27
5 files changed, 28 insertions, 44 deletions
diff --git a/.gitignore b/.gitignore
index a5fb90f..f9779a8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,7 @@
-
.vscode
mknes
data
+TODO
+dump_mappers
+fragment_shader.h
+vertex_shader.h
diff --git a/build.sh b/build.sh
index b548675..aed20c0 100755
--- a/build.sh
+++ b/build.sh
@@ -5,7 +5,7 @@ PROJECT_NAME="mknes" # Change this for each new project
# Base configuration common to all builds
CFLAGS="-std=gnu11 "
-CFLAGS+="-mavx2 -mbmi2 -mtune=native -mfunction-return=keep -mindirect-branch=keep "
+CFLAGS+="-mavx2 -mbmi2 -march=native -mfunction-return=keep -mindirect-branch=keep "
CFLAGS+="-fwrapv -ffast-math -fno-trapping-math -fwhole-program "
CFLAGS+="-fno-stack-protector -fno-PIE -no-pie -fno-strict-aliasing -ffunction-sections -fdata-sections "
# CFLAGS+="-fno-exceptions -fno-rtti -fno-use-cxa-atexit "
@@ -40,7 +40,7 @@ case "$BUILD_TYPE" in
# -fsanitize=address,undefined -fno-omit-frame-pointer"
;;
"release")
- CFLAGS+=" -s -O2"
+ CFLAGS+=" -s -Wl,--strip-all -O2"
;;
"debug")
CFLAGS+=" -g -O0"
diff --git a/mapper.c b/mapper.c
index 821224d..188d88b 100644
--- a/mapper.c
+++ b/mapper.c
@@ -38,7 +38,7 @@ static void mapper_default_tick(struct nes_state *state) { // No IRQ or timing l
static struct mapper_entry mapper_table[] = {
/* Mapper: 0 */ { 0x00, mapper_0000_prg_read, mapper_0000_prg_write, mapper_0000_chr_read, mapper_0000_chr_write, mapper_default_ciram_read, mapper_default_ciram_write, mapper_default_tick, mapper_0000_init },
/* Mapper: 3 */ { 0x03, mapper_0003_prg_read, mapper_0003_prg_write, mapper_0003_chr_read, mapper_0003_chr_write, mapper_default_ciram_read, mapper_default_ciram_write, mapper_default_tick, mapper_0003_init },
-/* Mapper: 7 */ { 0x07, mapper_0007_prg_read, mapper_0007_prg_write, mapper_0007_chr_read, mapper_0007_chr_write, mapper_0007_ciram_read, mapper_0007_ciram_write, mapper_default_tick, mapper_0007_init },
+/* Mapper: 7 */ { 0x2007, mapper_0007_prg_read, mapper_0007_prg_write, mapper_0007_chr_read, mapper_0007_chr_write, mapper_0007_ciram_read, mapper_0007_ciram_write, mapper_default_tick, mapper_0007_init },
/* Mapper: b */ { 0x0b, mapper_000b_prg_read, mapper_000b_prg_write, mapper_000b_chr_read, mapper_000b_chr_write, mapper_default_ciram_read, mapper_default_ciram_write, mapper_default_tick, mapper_000b_init },
/* Mapper: 66 */ { 0x42, mapper_0042_prg_read, mapper_0042_prg_write, mapper_0042_chr_read, mapper_0042_chr_write, mapper_default_ciram_read, mapper_default_ciram_write, mapper_default_tick, mapper_0042_init },
/* Mapper: 2002 */ { 0x2002, mapper_2002_prg_read, mapper_2002_prg_write, mapper_2002_chr_read, mapper_2002_chr_write, mapper_default_ciram_read, mapper_default_ciram_write, mapper_default_tick, mapper_2002_init },
diff --git a/mknes.c b/mknes.c
index 51e737e..977a3be 100644
--- a/mknes.c
+++ b/mknes.c
@@ -225,10 +225,10 @@ int main(int argc, char **argv) {
timer_start(timer);
- // while(!glfwWindowShouldClose(window)) {
- for(uint32_t i = 0; i < 0x5000; ++ i) {
- // timer_wait(timer);
- // glfwPollEvents();
+ while(!glfwWindowShouldClose(window)) {
+ // for(uint32_t i = 0; i < 0x5000; ++ i) {
+ timer_wait(timer);
+ glfwPollEvents();
// //
while(!nstate->ppu.frame_ready) {
@@ -238,19 +238,19 @@ int main(int argc, char **argv) {
nstate->ppu.frame_ready = 0;
frames++;
- // uint32_t * restrict dst = buffer;
- // uint8_t * restrict src = nstate->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);
+ uint32_t * restrict dst = buffer;
+ uint8_t * restrict src = nstate->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("total frames: %6.6d total cycles: %ld\n", frames, nstate->cycles);
glfwDestroyWindow(window);
diff --git a/ppu.c b/ppu.c
index e9a6894..d2772d8 100644
--- a/ppu.c
+++ b/ppu.c
@@ -69,7 +69,7 @@ static inline void ppu_write(struct nes_state *state, uint32_t offset, uint8_t v
case 7: { // 2007
uint32_t addr = ppu->vram_addr & 0x3fff;
if(addr < 0x2000) {
- // CHR-RAM, skip
+ state->mapper.chr_write(state, addr, value);
} else if(addr < 0x3f00) {
state->mapper.ciram_write(state, addr, value);
} else if(addr < 0x4000) {
@@ -297,29 +297,11 @@ static void ppu_tick(struct nes_state *state) {
}
ppu->vram_addr = (ppu->vram_addr & ~0x03e0) | (y << 5);
}
- goto render_and_shift;
- } break;
+ }
+ __attribute__((fallthrough));
case 1 ... 255: // fallthrough: this is 1->256
-render_and_shift: ppu_render_pixel(state);
-
- // if(UNLIKELY(dot == 256)) {
- // if((ppu->vram_addr & 0x7000) != 0x7000) {
- // ppu->vram_addr += 0x1000;
- // } else {
- // ppu->vram_addr &= ~0x7000;
- // uint32_t y = (ppu->vram_addr & 0x03e0) >> 5;
- // if(y == 29) {
- // y = 0;
- // ppu->vram_addr ^= 0x0800;
- // } else if(y == 31) {
- // y = 0;
- // } else {
- // y++;
- // }
- // ppu->vram_addr = (ppu->vram_addr & ~0x03e0) | (y << 5);
- // }
- // }
+ ppu_render_pixel(state);
__attribute__((fallthrough));
case 321 ... 336: { // fallthrough: the code below has to run 1->256 + 321->336
@@ -404,7 +386,6 @@ render_and_shift: ppu_render_pixel(state);
case 261: {
switch(dot) {
case 256: {
-
if((ppu->vram_addr & 0x7000) != 0x7000) {
ppu->vram_addr += 0x1000;
} else {