diff options
| author | Peter Fors <peter.fors@mindkiller.com> | 2025-04-06 20:05:32 +0200 |
|---|---|---|
| committer | Peter Fors <peter.fors@mindkiller.com> | 2025-04-06 20:05:32 +0200 |
| commit | debadc464578ac2be6b75a95f6ea6f95bfecba79 (patch) | |
| tree | 0d27a48974ccb36f5fde9f945174880a37746da5 | |
| parent | 1372919415b23a9a596ca7211fd432328b2ac0cc (diff) | |
cleanup
| -rw-r--r-- | .gitignore | 5 | ||||
| -rwxr-xr-x | build.sh | 4 | ||||
| -rw-r--r-- | mapper.c | 2 | ||||
| -rw-r--r-- | mknes.c | 34 | ||||
| -rw-r--r-- | ppu.c | 27 |
5 files changed, 28 insertions, 44 deletions
@@ -1,4 +1,7 @@ - .vscode mknes data +TODO +dump_mappers +fragment_shader.h +vertex_shader.h @@ -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" @@ -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 }, @@ -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); @@ -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 { |
