From a8e0c141b0184d629504b9f0ee8dbc4fefb90934 Mon Sep 17 00:00:00 2001 From: Peter Fors Date: Sat, 24 May 2025 15:45:54 +0200 Subject: 3011fps --- build.sh | 14 ++- callbacks.c | 24 ---- cpu.c | 15 +-- cpu_opcodes.c | 310 ++++++++++++++++++++++++------------------------- cpu_opcodes_ud.c | 132 ++++++++++----------- ines2.c | 1 + mappers/mapper.c | 2 +- mappers/mapper_000_0.c | 4 +- mappers/mapper_001_0.c | 12 +- mappers/mapper_002_2.c | 8 +- mappers/mapper_003_0.c | 6 +- mappers/mapper_003_1.c | 6 +- mappers/mapper_003_2.c | 6 +- mappers/mapper_007_2.c | 12 +- mappers/mapper_011_0.c | 6 +- mappers/mapper_066_0.c | 6 +- memory.c | 32 +---- mknes.c | 61 +++++++--- mknes.h | 15 +-- ppu.c | 12 +- ppu_registers.c | 6 +- render.c | 2 - shader.c | 2 +- 23 files changed, 328 insertions(+), 366 deletions(-) diff --git a/build.sh b/build.sh index cbe8e64..0660fbb 100755 --- a/build.sh +++ b/build.sh @@ -10,23 +10,26 @@ CFLAGS="-std=gnu11 -mtune=generic " CFLAGS+="-mbmi " CFLAGS+="-mfunction-return=keep -mindirect-branch=keep " CFLAGS+="-fwrapv -ffast-math -fno-trapping-math -fvisibility=hidden " -CFLAGS+="-fno-stack-protector -fno-PIE -no-pie -fno-strict-aliasing -fcf-protection=none -ffunction-sections -fdata-sections " +CFLAGS+="-fno-stack-protector -fno-PIE -no-pie -fcf-protection=none -ffunction-sections -fdata-sections " # CFLAGS+="-fno-exceptions -fno-rtti -fno-use-cxa-atexit " CFLAGS+="-fno-non-call-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables " -CFLAGS+="-Wall -Wextra " +CFLAGS+="-Wall -Wextra -Wstrict-aliasing=3 " CFLAGS+="-Wno-unused-parameter -Wno-sign-compare -Wno-trigraphs -Wno-maybe-uninitialized " CFLAGS+="-Wno-unused-variable -Wno-unused-const-variable -Wno-unused-function -Wno-write-strings -Wno-missing-field-initializers " CFLAGS+="-U_FORTIFY_SOURCE -fno-pic " +# Enable occationally to check for errors.. +# CFLAGS+="-fanalyzer " + LDFLAGS="-Wl,--gc-sections -Wl,--as-needed " -# LDFLAGS+="-Wl,--script=mknes.ld " # Base include paths (common for all platforms) INCLUDE_PATHS="-Ibase -I.." # Linux-specific includes and libraries LINUX_INCLUDE="-I/usr/include/pipewire-0.3 -I/usr/include/spa-0.2" -LINUX_LIBS="-lpipewire-0.3 -lXi -lX11 -lGL -lm -ldl -pthread -lglfw -larchive " +#LINUX_LIBS="-lpipewire-0.3 -lXi -lX11 -lGL -lm -ldl -pthread -lglfw -larchive " +LINUX_LIBS="-lXi -lX11 -lGL -lm -ldl -pthread -lglfw -larchive " # Windows-specific includes and libraries # WINDOWS_INCLUDE="" @@ -49,7 +52,7 @@ case "$BUILD_TYPE" in CFLAGS+=" -s -Wl,--strip-all -O2" ;; "profile") - CFLAGS+=" -g -O2 -fprofile-generate -ftest-coverage" + CFLAGS+=" -O2 -fprofile-generate -ftest-coverage" ;; "profile_release") CFLAGS+=" -s -Wl,--strip-all -O2 -fprofile-use" @@ -84,6 +87,7 @@ set -e ( # ../bin/ctime -begin .${PROJECT_NAME}_linux $CC $CFLAGS ${PROJECT_NAME}.c -o ${PROJECT_NAME} $INCLUDE_PATHS $LINUX_INCLUDE $LDFLAGS $LINUX_LIBS + objdump -d -Mintel mknes > mknes.s # ../bin/ctime -end .${PROJECT_NAME}_linux $? ) & diff --git a/callbacks.c b/callbacks.c index 6b62ea6..f32c59d 100644 --- a/callbacks.c +++ b/callbacks.c @@ -51,30 +51,6 @@ static void key_callback(GLFWwindow *window, int key, int scancode, int action, } } - if(action == GLFW_PRESS) { - switch(key) { - case GLFW_KEY_X: nes_state->ppu.input[0] |= (1 << 0); break; // A - case GLFW_KEY_Z: nes_state->ppu.input[0] |= (1 << 1); break; // B - case GLFW_KEY_SPACE: nes_state->ppu.input[0] |= (1 << 2); break; // Select - case GLFW_KEY_ENTER: nes_state->ppu.input[0] |= (1 << 3); break; // Start - case GLFW_KEY_UP: nes_state->ppu.input[0] |= (1 << 4); break; - case GLFW_KEY_DOWN: nes_state->ppu.input[0] |= (1 << 5); break; - case GLFW_KEY_LEFT: nes_state->ppu.input[0] |= (1 << 6); break; - case GLFW_KEY_RIGHT: nes_state->ppu.input[0] |= (1 << 7); break; - } - } else if(action == GLFW_RELEASE) { - switch(key) { - case GLFW_KEY_X: nes_state->ppu.input[0] &= ~(1 << 0); break; - case GLFW_KEY_Z: nes_state->ppu.input[0] &= ~(1 << 1); break; - case GLFW_KEY_SPACE: nes_state->ppu.input[0] &= ~(1 << 2); break; - case GLFW_KEY_ENTER: nes_state->ppu.input[0] &= ~(1 << 3); break; - case GLFW_KEY_UP: nes_state->ppu.input[0] &= ~(1 << 4); break; - case GLFW_KEY_DOWN: nes_state->ppu.input[0] &= ~(1 << 5); break; - case GLFW_KEY_LEFT: nes_state->ppu.input[0] &= ~(1 << 6); break; - case GLFW_KEY_RIGHT: nes_state->ppu.input[0] &= ~(1 << 7); break; - } - } - if(action == GLFW_RELEASE) { switch(key) { case GLFW_KEY_F12: { diff --git a/cpu.c b/cpu.c index 74d253d..23825aa 100644 --- a/cpu.c +++ b/cpu.c @@ -5,12 +5,10 @@ // DO NOT ENABLE FOR NES!!!!! // #define ENABLE_DECIMAL_MODE -__attribute__((hot)) static inline uint8_t pack_flags(struct cpu_state *cpu) { return (cpu->n << 7) | (cpu->v << 6) | (1 << 5) | (cpu->d << 3) | (cpu->i << 2) | (cpu->z << 1) | cpu->c; } -__attribute__((hot)) static inline void unpack_flags(struct cpu_state *cpu, uint8_t value) { cpu->n = (value >> 7) & 1; cpu->v = (value >> 6) & 1; @@ -20,7 +18,6 @@ static inline void unpack_flags(struct cpu_state *cpu, uint8_t value) { cpu->c = value & 1; } -__attribute__((hot)) static inline void update_zn(struct cpu_state *cpu, uint8_t result) { cpu->z = (result == 0); cpu->n = (result & 0x80) != 0; @@ -31,8 +28,7 @@ static void (*opcode_lut[256*2])(struct nes_state *) __attribute__((aligned(4096 #include "cpu_opcodes.c" #include "cpu_opcodes_ud.c" -__attribute__((hot)) -static inline void do_nmi(struct nes_state * restrict state) { +static inline void do_nmi(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); // T1: dummy read (fetch suppressed) @@ -51,8 +47,7 @@ static inline void do_nmi(struct nes_state * restrict state) { cpu->i = 1; } -__attribute__((hot)) -static inline void do_irq(struct nes_state * restrict state) { +static inline void do_irq(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); // T1: dummy read (fetch suppressed) @@ -71,8 +66,7 @@ static inline void do_irq(struct nes_state * restrict state) { cpu->i = 1; } -__attribute__((always_inline, hot)) -static inline void check_interrupts(struct nes_state * restrict state) { +static inline void check_interrupts(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; if(state->cpu.nmi_pending) { @@ -84,8 +78,7 @@ static inline void check_interrupts(struct nes_state * restrict state) { } } -__attribute__((hot)) -static void cpu_tick(struct nes_state *state) { +static inline void cpu_tick(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; check_interrupts(state); diff --git a/cpu_opcodes.c b/cpu_opcodes.c index 7e174be..b401910 100644 --- a/cpu_opcodes.c +++ b/cpu_opcodes.c @@ -1,8 +1,7 @@ // ADC -__attribute__((always_inline, hot)) -static inline void adc(struct cpu_state * restrict cpu, uint8_t value) { +static inline void adc(struct cpu_state *cpu, uint8_t value) { #ifdef ENABLE_DECIMAL_MODE if(cpu->d) { uint8_t al = (cpu->a & 0x0f) + (value & 0x0f) + cpu->c; @@ -32,7 +31,7 @@ static inline void adc(struct cpu_state * restrict cpu, uint8_t value) { // ADC ($nn,X) -static void opcode_adc_indx(struct nes_state * restrict state) { +static void opcode_adc_indx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); // T1 @@ -49,7 +48,7 @@ static void opcode_adc_indx(struct nes_state * restrict state) { } // ADC $nn -static void opcode_adc_zp(struct nes_state * restrict state) { +static void opcode_adc_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); // T1 @@ -59,7 +58,7 @@ static void opcode_adc_zp(struct nes_state * restrict state) { } // ADC #$nn -static void opcode_adc_imm(struct nes_state * restrict state) { +static void opcode_adc_imm(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t value = memory_read(state, cpu->pc++); // T1 @@ -67,7 +66,7 @@ static void opcode_adc_imm(struct nes_state * restrict state) { } // ADC $nnnn -static void opcode_adc_abs(struct nes_state * restrict state) { +static void opcode_adc_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -79,7 +78,7 @@ static void opcode_adc_abs(struct nes_state * restrict state) { } // ADC ($nn),Y -static void opcode_adc_indy(struct nes_state * restrict state) { +static void opcode_adc_indy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); // T1 @@ -98,7 +97,7 @@ static void opcode_adc_indy(struct nes_state * restrict state) { } // ADC $nn,X -static void opcode_adc_zpx(struct nes_state * restrict state) { +static void opcode_adc_zpx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); // T1 @@ -110,7 +109,7 @@ static void opcode_adc_zpx(struct nes_state * restrict state) { } // ADC $nnnn,Y -static void opcode_adc_absy(struct nes_state * restrict state) { +static void opcode_adc_absy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -127,7 +126,7 @@ static void opcode_adc_absy(struct nes_state * restrict state) { } // ADC $nnnn,X -static void opcode_adc_absx(struct nes_state * restrict state) { +static void opcode_adc_absx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -145,7 +144,7 @@ static void opcode_adc_absx(struct nes_state * restrict state) { // AND ($nn,X) -static void opcode_and_indx(struct nes_state * restrict state) { +static void opcode_and_indx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); // T1 @@ -163,7 +162,7 @@ static void opcode_and_indx(struct nes_state * restrict state) { } // AND $nn -static void opcode_and_zp(struct nes_state * restrict state) { +static void opcode_and_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); // T1 @@ -174,7 +173,7 @@ static void opcode_and_zp(struct nes_state * restrict state) { } // AND #$nn -static void opcode_and_imm(struct nes_state * restrict state) { +static void opcode_and_imm(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t value = memory_read(state, cpu->pc++); // T1 @@ -183,7 +182,7 @@ static void opcode_and_imm(struct nes_state * restrict state) { } // AND $nnnn -static void opcode_and_abs(struct nes_state * restrict state) { +static void opcode_and_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -196,7 +195,7 @@ static void opcode_and_abs(struct nes_state * restrict state) { } // AND ($nn),Y -static void opcode_and_indy(struct nes_state * restrict state) { +static void opcode_and_indy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); // T1 @@ -216,7 +215,7 @@ static void opcode_and_indy(struct nes_state * restrict state) { } // AND $nn,X -static void opcode_and_zpx(struct nes_state * restrict state) { +static void opcode_and_zpx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); // T1 @@ -229,7 +228,7 @@ static void opcode_and_zpx(struct nes_state * restrict state) { } // AND $nnnn,Y -static void opcode_and_absy(struct nes_state * restrict state) { +static void opcode_and_absy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -247,7 +246,7 @@ static void opcode_and_absy(struct nes_state * restrict state) { } // AND $nnnn,X -static void opcode_and_absx(struct nes_state * restrict state) { +static void opcode_and_absx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -268,7 +267,7 @@ static void opcode_and_absx(struct nes_state * restrict state) { // ASL // ASL $nn -static void opcode_asl_zp(struct nes_state * restrict state) { +static void opcode_asl_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); // T1 @@ -284,7 +283,7 @@ static void opcode_asl_zp(struct nes_state * restrict state) { } // ASL A -static void opcode_asl_acc(struct nes_state * restrict state) { +static void opcode_asl_acc(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); // T1 (dummy read at PC) @@ -296,7 +295,7 @@ static void opcode_asl_acc(struct nes_state * restrict state) { } // ASL $nnnn -static void opcode_asl_abs(struct nes_state * restrict state) { +static void opcode_asl_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -314,7 +313,7 @@ static void opcode_asl_abs(struct nes_state * restrict state) { } // ASL $nn,X -static void opcode_asl_zpx(struct nes_state * restrict state) { +static void opcode_asl_zpx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); // T1 @@ -332,7 +331,7 @@ static void opcode_asl_zpx(struct nes_state * restrict state) { } // ASL $nnnn,X -static void opcode_asl_absx(struct nes_state * restrict state) { +static void opcode_asl_absx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -356,7 +355,7 @@ static void opcode_asl_absx(struct nes_state * restrict state) { // BIT // BIT $nn -static void opcode_bit_zp(struct nes_state * restrict state) { +static void opcode_bit_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); // T1 @@ -368,7 +367,7 @@ static void opcode_bit_zp(struct nes_state * restrict state) { } // BIT $nnnn -static void opcode_bit_abs(struct nes_state * restrict state) { +static void opcode_bit_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -384,7 +383,7 @@ static void opcode_bit_abs(struct nes_state * restrict state) { // BRK -static void opcode_brk(struct nes_state * restrict state) { +static void opcode_brk(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; cpu->pc++; // BRK is 1 byte, skip padding byte @@ -407,12 +406,11 @@ static void opcode_brk(struct nes_state * restrict state) { // BRANCHES -__attribute__((always_inline, hot)) static inline int page_crossed(uint16_t a, uint16_t b) { return (a & 0xff00) != (b & 0xff00); } -static void opcode_bpl(struct nes_state * restrict state) { +static void opcode_bpl(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t offset = memory_read(state, cpu->pc++); // T1 @@ -427,7 +425,7 @@ static void opcode_bpl(struct nes_state * restrict state) { } } -static void opcode_bmi(struct nes_state * restrict state) { +static void opcode_bmi(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t offset = memory_read(state, cpu->pc++); @@ -442,7 +440,7 @@ static void opcode_bmi(struct nes_state * restrict state) { } } -static void opcode_bvc(struct nes_state * restrict state) { +static void opcode_bvc(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t offset = memory_read(state, cpu->pc++); @@ -457,7 +455,7 @@ static void opcode_bvc(struct nes_state * restrict state) { } } -static void opcode_bvs(struct nes_state * restrict state) { +static void opcode_bvs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t offset = memory_read(state, cpu->pc++); @@ -472,7 +470,7 @@ static void opcode_bvs(struct nes_state * restrict state) { } } -static void opcode_bcc(struct nes_state * restrict state) { +static void opcode_bcc(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t offset = memory_read(state, cpu->pc++); @@ -487,7 +485,7 @@ static void opcode_bcc(struct nes_state * restrict state) { } } -static void opcode_bcs(struct nes_state * restrict state) { +static void opcode_bcs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t offset = memory_read(state, cpu->pc++); @@ -502,7 +500,7 @@ static void opcode_bcs(struct nes_state * restrict state) { } } -static void opcode_bne(struct nes_state * restrict state) { +static void opcode_bne(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t offset = memory_read(state, cpu->pc++); @@ -517,7 +515,7 @@ static void opcode_bne(struct nes_state * restrict state) { } } -static void opcode_beq(struct nes_state * restrict state) { +static void opcode_beq(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t offset = memory_read(state, cpu->pc++); @@ -535,13 +533,13 @@ static void opcode_beq(struct nes_state * restrict state) { // SET/CLEAR flags -static void opcode_clc(struct nes_state * restrict state) { +static void opcode_clc(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); cpu->c = 0; } -static void opcode_cld(struct nes_state * restrict state) { +static void opcode_cld(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); #ifdef ENABLE_DECIMAL_MODE @@ -549,25 +547,25 @@ static void opcode_cld(struct nes_state * restrict state) { #endif } -static void opcode_cli(struct nes_state * restrict state) { +static void opcode_cli(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); cpu->i = 0; } -static void opcode_clv(struct nes_state * restrict state) { +static void opcode_clv(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); cpu->v = 0; } -static void opcode_sec(struct nes_state * restrict state) { +static void opcode_sec(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); cpu->c = 1; } -static void opcode_sed(struct nes_state * restrict state) { +static void opcode_sed(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); #ifdef ENABLE_DECIMAL_MODE @@ -575,7 +573,7 @@ static void opcode_sed(struct nes_state * restrict state) { #endif } -static void opcode_sei(struct nes_state * restrict state) { +static void opcode_sei(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); cpu->i = 1; @@ -583,14 +581,13 @@ static void opcode_sei(struct nes_state * restrict state) { // CMP -__attribute__((always_inline, hot)) static inline void cmp(struct cpu_state * restrict cpu, uint8_t value) { uint8_t result = cpu->a - value; cpu->c = (cpu->a >= value); update_zn(cpu, result); } -static void opcode_cmp_indx(struct nes_state * restrict state) { +static void opcode_cmp_indx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); // T1 @@ -606,7 +603,7 @@ static void opcode_cmp_indx(struct nes_state * restrict state) { cmp(cpu, value); // T6 } -static void opcode_cmp_zp(struct nes_state * restrict state) { +static void opcode_cmp_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); // T1 @@ -615,14 +612,14 @@ static void opcode_cmp_zp(struct nes_state * restrict state) { cmp(cpu, value); // T3 } -static void opcode_cmp_imm(struct nes_state * restrict state) { +static void opcode_cmp_imm(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t value = memory_read(state, cpu->pc++); // T1 cmp(cpu, value); // T2 } -static void opcode_cmp_abs(struct nes_state * restrict state) { +static void opcode_cmp_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -633,7 +630,7 @@ static void opcode_cmp_abs(struct nes_state * restrict state) { cmp(cpu, value); // T4 } -static void opcode_cmp_indy(struct nes_state * restrict state) { +static void opcode_cmp_indy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); // T1 @@ -651,7 +648,7 @@ static void opcode_cmp_indy(struct nes_state * restrict state) { cmp(cpu, value); // T5 or T6 } -static void opcode_cmp_zpx(struct nes_state * restrict state) { +static void opcode_cmp_zpx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); // T1 @@ -662,7 +659,7 @@ static void opcode_cmp_zpx(struct nes_state * restrict state) { cmp(cpu, value); // T4 } -static void opcode_cmp_absy(struct nes_state * restrict state) { +static void opcode_cmp_absy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -678,7 +675,7 @@ static void opcode_cmp_absy(struct nes_state * restrict state) { cmp(cpu, value); // T4 or T5 } -static void opcode_cmp_absx(struct nes_state * restrict state) { +static void opcode_cmp_absx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -696,21 +693,20 @@ static void opcode_cmp_absx(struct nes_state * restrict state) { // CPX -__attribute__((always_inline, hot)) static inline void cpx(struct cpu_state * restrict cpu, uint8_t value) { uint8_t result = cpu->x - value; cpu->c = (cpu->x >= value); update_zn(cpu, result); } -static void opcode_cpx_imm(struct nes_state * restrict state) { +static void opcode_cpx_imm(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t value = memory_read(state, cpu->pc++); // T1 cpx(cpu, value); // T2 } -static void opcode_cpx_zp(struct nes_state * restrict state) { +static void opcode_cpx_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); // T1 @@ -719,7 +715,7 @@ static void opcode_cpx_zp(struct nes_state * restrict state) { cpx(cpu, value); // T3 } -static void opcode_cpx_abs(struct nes_state * restrict state) { +static void opcode_cpx_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -732,21 +728,20 @@ static void opcode_cpx_abs(struct nes_state * restrict state) { // CPY -__attribute__((always_inline, hot)) static inline void cpy(struct cpu_state * restrict cpu, uint8_t value) { uint8_t result = cpu->y - value; cpu->c = (cpu->y >= value); update_zn(cpu, result); } -static void opcode_cpy_imm(struct nes_state * restrict state) { +static void opcode_cpy_imm(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t value = memory_read(state, cpu->pc++); // T1 cpy(cpu, value); // T2 } -static void opcode_cpy_zp(struct nes_state * restrict state) { +static void opcode_cpy_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); // T1 @@ -755,7 +750,7 @@ static void opcode_cpy_zp(struct nes_state * restrict state) { cpy(cpu, value); // T3 } -static void opcode_cpy_abs(struct nes_state * restrict state) { +static void opcode_cpy_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -769,7 +764,7 @@ static void opcode_cpy_abs(struct nes_state * restrict state) { // DEC -static void opcode_dec_zp(struct nes_state * restrict state) { +static void opcode_dec_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); // T1 @@ -782,7 +777,7 @@ static void opcode_dec_zp(struct nes_state * restrict state) { update_zn(cpu, value); // T5 } -static void opcode_dec_zpx(struct nes_state * restrict state) { +static void opcode_dec_zpx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); // T1 @@ -797,7 +792,7 @@ static void opcode_dec_zpx(struct nes_state * restrict state) { update_zn(cpu, value); // T6 } -static void opcode_dec_abs(struct nes_state * restrict state) { +static void opcode_dec_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -812,7 +807,7 @@ static void opcode_dec_abs(struct nes_state * restrict state) { update_zn(cpu, value); // T6 } -static void opcode_dec_absx(struct nes_state * restrict state) { +static void opcode_dec_absx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -833,7 +828,7 @@ static void opcode_dec_absx(struct nes_state * restrict state) { // EOR -static void opcode_eor_indx(struct nes_state * restrict state) { +static void opcode_eor_indx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); // T1 @@ -850,7 +845,7 @@ static void opcode_eor_indx(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_eor_zp(struct nes_state * restrict state) { +static void opcode_eor_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); // T1 @@ -860,7 +855,7 @@ static void opcode_eor_zp(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_eor_imm(struct nes_state * restrict state) { +static void opcode_eor_imm(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t value = memory_read(state, cpu->pc++); // T1 @@ -868,7 +863,7 @@ static void opcode_eor_imm(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_eor_abs(struct nes_state * restrict state) { +static void opcode_eor_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -880,7 +875,7 @@ static void opcode_eor_abs(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_eor_indy(struct nes_state * restrict state) { +static void opcode_eor_indy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); // T1 @@ -899,7 +894,7 @@ static void opcode_eor_indy(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_eor_zpx(struct nes_state * restrict state) { +static void opcode_eor_zpx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); // T1 @@ -911,7 +906,7 @@ static void opcode_eor_zpx(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_eor_absy(struct nes_state * restrict state) { +static void opcode_eor_absy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -928,7 +923,7 @@ static void opcode_eor_absy(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_eor_absx(struct nes_state * restrict state) { +static void opcode_eor_absx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -948,7 +943,7 @@ static void opcode_eor_absx(struct nes_state * restrict state) { // INC -static void opcode_inc_zp(struct nes_state * restrict state) { +static void opcode_inc_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); // T1 @@ -961,7 +956,7 @@ static void opcode_inc_zp(struct nes_state * restrict state) { update_zn(cpu, value); // T5 } -static void opcode_inc_zpx(struct nes_state * restrict state) { +static void opcode_inc_zpx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); // T1 @@ -976,7 +971,7 @@ static void opcode_inc_zpx(struct nes_state * restrict state) { update_zn(cpu, value); // T6 } -static void opcode_inc_abs(struct nes_state * restrict state) { +static void opcode_inc_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -991,7 +986,7 @@ static void opcode_inc_abs(struct nes_state * restrict state) { update_zn(cpu, value); // T6 } -static void opcode_inc_absx(struct nes_state * restrict state) { +static void opcode_inc_absx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -1012,7 +1007,7 @@ static void opcode_inc_absx(struct nes_state * restrict state) { // JMP/JSR -static void opcode_jmp_abs(struct nes_state * restrict state) { +static void opcode_jmp_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -1020,7 +1015,7 @@ static void opcode_jmp_abs(struct nes_state * restrict state) { cpu->pc = lo | (hi << 8); // T3 } -static void opcode_jmp_ind(struct nes_state * restrict state) { +static void opcode_jmp_ind(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t ptr_lo = memory_read(state, cpu->pc++); // T1 @@ -1038,7 +1033,7 @@ static void opcode_jmp_ind(struct nes_state * restrict state) { cpu->pc = lo | (hi << 8); // T5 } -static void opcode_jsr(struct nes_state * restrict state) { +static void opcode_jsr(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -1057,7 +1052,7 @@ static void opcode_jsr(struct nes_state * restrict state) { // LDA -static void opcode_lda_indx(struct nes_state * restrict state) { +static void opcode_lda_indx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); // T1 @@ -1073,7 +1068,7 @@ static void opcode_lda_indx(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_lda_zp(struct nes_state * restrict state) { +static void opcode_lda_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); // T1 @@ -1083,7 +1078,7 @@ static void opcode_lda_zp(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_lda_imm(struct nes_state * restrict state) { +static void opcode_lda_imm(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t value = memory_read(state, cpu->pc++); // T1 @@ -1091,7 +1086,7 @@ static void opcode_lda_imm(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_lda_abs(struct nes_state * restrict state) { +static void opcode_lda_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -1103,7 +1098,7 @@ static void opcode_lda_abs(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_lda_indy(struct nes_state * restrict state) { +static void opcode_lda_indy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); // T1 @@ -1122,7 +1117,7 @@ static void opcode_lda_indy(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_lda_zpx(struct nes_state * restrict state) { +static void opcode_lda_zpx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); // T1 @@ -1134,7 +1129,7 @@ static void opcode_lda_zpx(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_lda_absy(struct nes_state * restrict state) { +static void opcode_lda_absy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -1151,7 +1146,7 @@ static void opcode_lda_absy(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_lda_absx(struct nes_state * restrict state) { +static void opcode_lda_absx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -1171,7 +1166,7 @@ static void opcode_lda_absx(struct nes_state * restrict state) { // LDX -static void opcode_ldx_imm(struct nes_state * restrict state) { +static void opcode_ldx_imm(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t value = memory_read(state, cpu->pc++); @@ -1179,7 +1174,7 @@ static void opcode_ldx_imm(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_ldx_zp(struct nes_state * restrict state) { +static void opcode_ldx_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); @@ -1189,7 +1184,7 @@ static void opcode_ldx_zp(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_ldx_zpy(struct nes_state * restrict state) { +static void opcode_ldx_zpy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); @@ -1201,7 +1196,7 @@ static void opcode_ldx_zpy(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_ldx_abs(struct nes_state * restrict state) { +static void opcode_ldx_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -1213,7 +1208,7 @@ static void opcode_ldx_abs(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_ldx_absy(struct nes_state * restrict state) { +static void opcode_ldx_absy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -1233,7 +1228,7 @@ static void opcode_ldx_absy(struct nes_state * restrict state) { // LDY -static void opcode_ldy_imm(struct nes_state * restrict state) { +static void opcode_ldy_imm(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t value = memory_read(state, cpu->pc++); @@ -1241,7 +1236,7 @@ static void opcode_ldy_imm(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_ldy_zp(struct nes_state * restrict state) { +static void opcode_ldy_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); @@ -1251,7 +1246,7 @@ static void opcode_ldy_zp(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_ldy_zpx(struct nes_state * restrict state) { +static void opcode_ldy_zpx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); @@ -1263,7 +1258,7 @@ static void opcode_ldy_zpx(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_ldy_abs(struct nes_state * restrict state) { +static void opcode_ldy_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -1275,7 +1270,7 @@ static void opcode_ldy_abs(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_ldy_absx(struct nes_state * restrict state) { +static void opcode_ldy_absx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -1296,7 +1291,7 @@ static void opcode_ldy_absx(struct nes_state * restrict state) { // LSR -static void opcode_lsr_zp(struct nes_state * restrict state) { +static void opcode_lsr_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); // T1 @@ -1310,7 +1305,7 @@ static void opcode_lsr_zp(struct nes_state * restrict state) { update_zn(cpu, value); // T5 } -static void opcode_lsr_acc(struct nes_state * restrict state) { +static void opcode_lsr_acc(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); // T1 @@ -1319,7 +1314,7 @@ static void opcode_lsr_acc(struct nes_state * restrict state) { update_zn(cpu, cpu->a); // T2 } -static void opcode_lsr_abs(struct nes_state * restrict state) { +static void opcode_lsr_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -1336,7 +1331,7 @@ static void opcode_lsr_abs(struct nes_state * restrict state) { update_zn(cpu, value); // T6 } -static void opcode_lsr_zpx(struct nes_state * restrict state) { +static void opcode_lsr_zpx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); // T1 @@ -1353,7 +1348,7 @@ static void opcode_lsr_zpx(struct nes_state * restrict state) { update_zn(cpu, value); // T6 } -static void opcode_lsr_absx(struct nes_state * restrict state) { +static void opcode_lsr_absx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -1376,7 +1371,7 @@ static void opcode_lsr_absx(struct nes_state * restrict state) { // NOP -static void opcode_nop(struct nes_state * restrict state) { +static void opcode_nop(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); // T1: dummy read // T2: nothing changes @@ -1385,7 +1380,7 @@ static void opcode_nop(struct nes_state * restrict state) { // ORA -static void opcode_ora_indx(struct nes_state * restrict state) { +static void opcode_ora_indx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); // T1 @@ -1401,7 +1396,7 @@ static void opcode_ora_indx(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_ora_zp(struct nes_state * restrict state) { +static void opcode_ora_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); @@ -1411,7 +1406,7 @@ static void opcode_ora_zp(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_ora_imm(struct nes_state * restrict state) { +static void opcode_ora_imm(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t value = memory_read(state, cpu->pc++); @@ -1419,7 +1414,7 @@ static void opcode_ora_imm(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_ora_abs(struct nes_state * restrict state) { +static void opcode_ora_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -1431,7 +1426,7 @@ static void opcode_ora_abs(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_ora_indy(struct nes_state * restrict state) { +static void opcode_ora_indy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); @@ -1450,7 +1445,7 @@ static void opcode_ora_indy(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_ora_zpx(struct nes_state * restrict state) { +static void opcode_ora_zpx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); @@ -1462,7 +1457,7 @@ static void opcode_ora_zpx(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_ora_absy(struct nes_state * restrict state) { +static void opcode_ora_absy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -1479,7 +1474,7 @@ static void opcode_ora_absy(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_ora_absx(struct nes_state * restrict state) { +static void opcode_ora_absx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -1498,7 +1493,7 @@ static void opcode_ora_absx(struct nes_state * restrict state) { // PHA -static void opcode_pha(struct nes_state * restrict state) { +static void opcode_pha(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); // T1 memory_write(state, 0x0100 + cpu->sp--, cpu->a); // T2 @@ -1507,7 +1502,7 @@ static void opcode_pha(struct nes_state * restrict state) { // PHP -static void opcode_php(struct nes_state * restrict state) { +static void opcode_php(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); // T1 memory_write(state, 0x0100 + cpu->sp--, pack_flags(cpu) | 0x10); @@ -1516,7 +1511,7 @@ static void opcode_php(struct nes_state * restrict state) { // PLA -static void opcode_pla(struct nes_state * restrict state) { +static void opcode_pla(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); // T1 @@ -1530,7 +1525,7 @@ static void opcode_pla(struct nes_state * restrict state) { // PLP -static void opcode_plp(struct nes_state * restrict state) { +static void opcode_plp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); // T1 @@ -1543,7 +1538,7 @@ static void opcode_plp(struct nes_state * restrict state) { // RTI -static void opcode_rti(struct nes_state * restrict state) { +static void opcode_rti(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); // T1 @@ -1563,7 +1558,7 @@ static void opcode_rti(struct nes_state * restrict state) { // RTS -static void opcode_rts(struct nes_state * restrict state) { +static void opcode_rts(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); // T1 @@ -1578,7 +1573,7 @@ static void opcode_rts(struct nes_state * restrict state) { // ROL -static void opcode_rol_zp(struct nes_state * restrict state) { +static void opcode_rol_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); @@ -1594,7 +1589,7 @@ static void opcode_rol_zp(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_rol_acc(struct nes_state * restrict state) { +static void opcode_rol_acc(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); @@ -1606,7 +1601,7 @@ static void opcode_rol_acc(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_rol_abs(struct nes_state * restrict state) { +static void opcode_rol_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -1624,7 +1619,7 @@ static void opcode_rol_abs(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_rol_zpx(struct nes_state * restrict state) { +static void opcode_rol_zpx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); @@ -1642,7 +1637,7 @@ static void opcode_rol_zpx(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_rol_absx(struct nes_state * restrict state) { +static void opcode_rol_absx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -1666,7 +1661,7 @@ static void opcode_rol_absx(struct nes_state * restrict state) { // ROR -static void opcode_ror_zp(struct nes_state * restrict state) { +static void opcode_ror_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); @@ -1682,7 +1677,7 @@ static void opcode_ror_zp(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_ror_acc(struct nes_state * restrict state) { +static void opcode_ror_acc(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); @@ -1694,7 +1689,7 @@ static void opcode_ror_acc(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_ror_abs(struct nes_state * restrict state) { +static void opcode_ror_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -1712,7 +1707,7 @@ static void opcode_ror_abs(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_ror_zpx(struct nes_state * restrict state) { +static void opcode_ror_zpx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); @@ -1730,7 +1725,7 @@ static void opcode_ror_zpx(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_ror_absx(struct nes_state * restrict state) { +static void opcode_ror_absx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -1753,7 +1748,6 @@ static void opcode_ror_absx(struct nes_state * restrict state) { // SBC -__attribute__((always_inline, hot)) static inline void sbc(struct cpu_state * restrict cpu, uint8_t value) { #ifdef ENABLE_DECIMAL_MODE if(cpu->d) { @@ -1782,7 +1776,7 @@ static inline void sbc(struct cpu_state * restrict cpu, uint8_t value) { } -static void opcode_sbc_indx(struct nes_state * restrict state) { +static void opcode_sbc_indx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); @@ -1797,7 +1791,7 @@ static void opcode_sbc_indx(struct nes_state * restrict state) { sbc(cpu, value); } -static void opcode_sbc_zp(struct nes_state * restrict state) { +static void opcode_sbc_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); @@ -1806,14 +1800,14 @@ static void opcode_sbc_zp(struct nes_state * restrict state) { sbc(cpu, value); } -static void opcode_sbc_imm(struct nes_state * restrict state) { +static void opcode_sbc_imm(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t value = memory_read(state, cpu->pc++); sbc(cpu, value); } -static void opcode_sbc_abs(struct nes_state * restrict state) { +static void opcode_sbc_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -1824,7 +1818,7 @@ static void opcode_sbc_abs(struct nes_state * restrict state) { sbc(cpu, value); } -static void opcode_sbc_indy(struct nes_state * restrict state) { +static void opcode_sbc_indy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); @@ -1842,7 +1836,7 @@ static void opcode_sbc_indy(struct nes_state * restrict state) { sbc(cpu, value); } -static void opcode_sbc_zpx(struct nes_state * restrict state) { +static void opcode_sbc_zpx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); @@ -1853,7 +1847,7 @@ static void opcode_sbc_zpx(struct nes_state * restrict state) { sbc(cpu, value); } -static void opcode_sbc_absy(struct nes_state * restrict state) { +static void opcode_sbc_absy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -1869,7 +1863,7 @@ static void opcode_sbc_absy(struct nes_state * restrict state) { sbc(cpu, value); } -static void opcode_sbc_absx(struct nes_state * restrict state) { +static void opcode_sbc_absx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -1888,7 +1882,7 @@ static void opcode_sbc_absx(struct nes_state * restrict state) { // TAX -static void opcode_tax(struct nes_state * restrict state) { +static void opcode_tax(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); @@ -1896,7 +1890,7 @@ static void opcode_tax(struct nes_state * restrict state) { update_zn(cpu, cpu->x); } -static void opcode_tay(struct nes_state * restrict state) { +static void opcode_tay(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); @@ -1904,7 +1898,7 @@ static void opcode_tay(struct nes_state * restrict state) { update_zn(cpu, cpu->y); } -static void opcode_txa(struct nes_state * restrict state) { +static void opcode_txa(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); @@ -1912,7 +1906,7 @@ static void opcode_txa(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_tya(struct nes_state * restrict state) { +static void opcode_tya(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); @@ -1920,7 +1914,7 @@ static void opcode_tya(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_tsx(struct nes_state * restrict state) { +static void opcode_tsx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); @@ -1928,7 +1922,7 @@ static void opcode_tsx(struct nes_state * restrict state) { update_zn(cpu, cpu->x); } -static void opcode_txs(struct nes_state * restrict state) { +static void opcode_txs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); @@ -1938,7 +1932,7 @@ static void opcode_txs(struct nes_state * restrict state) { // INX -static void opcode_inx(struct nes_state * restrict state) { +static void opcode_inx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); @@ -1949,7 +1943,7 @@ static void opcode_inx(struct nes_state * restrict state) { // INY -static void opcode_iny(struct nes_state * restrict state) { +static void opcode_iny(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); @@ -1960,7 +1954,7 @@ static void opcode_iny(struct nes_state * restrict state) { // DEX -static void opcode_dex(struct nes_state * restrict state) { +static void opcode_dex(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); @@ -1971,7 +1965,7 @@ static void opcode_dex(struct nes_state * restrict state) { // DEY -static void opcode_dey(struct nes_state * restrict state) { +static void opcode_dey(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); @@ -1982,7 +1976,7 @@ static void opcode_dey(struct nes_state * restrict state) { // STA -static void opcode_sta_indx(struct nes_state * restrict state) { +static void opcode_sta_indx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); @@ -1996,14 +1990,14 @@ static void opcode_sta_indx(struct nes_state * restrict state) { memory_write(state, addr, cpu->a); } -static void opcode_sta_zp(struct nes_state * restrict state) { +static void opcode_sta_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); memory_write(state, addr, cpu->a); } -static void opcode_sta_abs(struct nes_state * restrict state) { +static void opcode_sta_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -2013,7 +2007,7 @@ static void opcode_sta_abs(struct nes_state * restrict state) { memory_write(state, addr, cpu->a); } -static void opcode_sta_indy(struct nes_state * restrict state) { +static void opcode_sta_indy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); // T1 @@ -2027,7 +2021,7 @@ static void opcode_sta_indy(struct nes_state * restrict state) { memory_write(state, addr, cpu->a); // T5 } -static void opcode_sta_zpx(struct nes_state * restrict state) { +static void opcode_sta_zpx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); @@ -2037,7 +2031,7 @@ static void opcode_sta_zpx(struct nes_state * restrict state) { memory_write(state, addr, cpu->a); } -static void opcode_sta_absy(struct nes_state * restrict state) { +static void opcode_sta_absy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -2049,7 +2043,7 @@ static void opcode_sta_absy(struct nes_state * restrict state) { memory_write(state, addr, cpu->a); } -static void opcode_sta_absx(struct nes_state * restrict state) { +static void opcode_sta_absx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -2064,14 +2058,14 @@ static void opcode_sta_absx(struct nes_state * restrict state) { // STX -static void opcode_stx_zp(struct nes_state * restrict state) { +static void opcode_stx_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); memory_write(state, addr, cpu->x); } -static void opcode_stx_abs(struct nes_state * restrict state) { +static void opcode_stx_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -2081,7 +2075,7 @@ static void opcode_stx_abs(struct nes_state * restrict state) { memory_write(state, addr, cpu->x); } -static void opcode_stx_zpy(struct nes_state * restrict state) { +static void opcode_stx_zpy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); @@ -2094,14 +2088,14 @@ static void opcode_stx_zpy(struct nes_state * restrict state) { // STY -static void opcode_sty_zp(struct nes_state * restrict state) { +static void opcode_sty_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); memory_write(state, addr, cpu->y); } -static void opcode_sty_abs(struct nes_state * restrict state) { +static void opcode_sty_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -2111,7 +2105,7 @@ static void opcode_sty_abs(struct nes_state * restrict state) { memory_write(state, addr, cpu->y); } -static void opcode_sty_zpx(struct nes_state * restrict state) { +static void opcode_sty_zpx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); diff --git a/cpu_opcodes_ud.c b/cpu_opcodes_ud.c index a679cae..44c1c8a 100644 --- a/cpu_opcodes_ud.c +++ b/cpu_opcodes_ud.c @@ -3,20 +3,20 @@ // NOP -static void opcode_nop_imm(struct nes_state * restrict state) { +static void opcode_nop_imm(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read(state, cpu->pc++); // T1: consume operand } -static void opcode_nop_zp(struct nes_state * restrict state) { +static void opcode_nop_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); // T1 memory_read_dummy(state, addr); // T2 } -static void opcode_nop_abs(struct nes_state * restrict state) { +static void opcode_nop_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -26,7 +26,7 @@ static void opcode_nop_abs(struct nes_state * restrict state) { memory_read_dummy(state, addr); // T3 } -static void opcode_nop_zpx(struct nes_state * restrict state) { +static void opcode_nop_zpx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); // T1: fetch operand @@ -35,7 +35,7 @@ static void opcode_nop_zpx(struct nes_state * restrict state) { memory_read_dummy(state, addr); // T3: final bus read to correct address } -static void opcode_nop_absx(struct nes_state * restrict state) { +static void opcode_nop_absx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); // T1 @@ -51,7 +51,7 @@ static void opcode_nop_absx(struct nes_state * restrict state) { } -static void opcode_nop_implied(struct nes_state * restrict state) { +static void opcode_nop_implied(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; memory_read_dummy(state, cpu->pc); // T1 @@ -60,7 +60,7 @@ static void opcode_nop_implied(struct nes_state * restrict state) { // LAX -static void opcode_lax_imm(struct nes_state * restrict state) { +static void opcode_lax_imm(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t value = memory_read(state, cpu->pc++); @@ -69,7 +69,7 @@ static void opcode_lax_imm(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_lax_indx(struct nes_state * restrict state) { +static void opcode_lax_indx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); @@ -86,7 +86,7 @@ static void opcode_lax_indx(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_lax_zp(struct nes_state * restrict state) { +static void opcode_lax_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); @@ -97,7 +97,7 @@ static void opcode_lax_zp(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_lax_zpy(struct nes_state * restrict state) { +static void opcode_lax_zpy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); @@ -110,7 +110,7 @@ static void opcode_lax_zpy(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_lax_abs(struct nes_state * restrict state) { +static void opcode_lax_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -123,7 +123,7 @@ static void opcode_lax_abs(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_lax_absy(struct nes_state * restrict state) { +static void opcode_lax_absy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -141,7 +141,7 @@ static void opcode_lax_absy(struct nes_state * restrict state) { update_zn(cpu, value); } -static void opcode_lax_indy(struct nes_state * restrict state) { +static void opcode_lax_indy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); @@ -163,7 +163,7 @@ static void opcode_lax_indy(struct nes_state * restrict state) { // SAX -static void opcode_sax_indx(struct nes_state * restrict state) { +static void opcode_sax_indx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); // T1 @@ -176,14 +176,14 @@ static void opcode_sax_indx(struct nes_state * restrict state) { } -static void opcode_sax_zp(struct nes_state * restrict state) { +static void opcode_sax_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); memory_write(state, addr, cpu->a & cpu->x); } -static void opcode_sax_abs(struct nes_state * restrict state) { +static void opcode_sax_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -193,7 +193,7 @@ static void opcode_sax_abs(struct nes_state * restrict state) { memory_write(state, addr, cpu->a & cpu->x); } -static void opcode_sax_zpy(struct nes_state * restrict state) { +static void opcode_sax_zpy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); @@ -203,7 +203,7 @@ static void opcode_sax_zpy(struct nes_state * restrict state) { memory_write(state, addr, cpu->a & cpu->x); } -static void opcode_sax_absy(struct nes_state * restrict state) { +static void opcode_sax_absy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -215,7 +215,7 @@ static void opcode_sax_absy(struct nes_state * restrict state) { memory_write(state, addr, cpu->a & cpu->x); } -static void opcode_sax_indy(struct nes_state * restrict state) { +static void opcode_sax_indy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); // T1 @@ -232,7 +232,7 @@ static void opcode_sax_indy(struct nes_state * restrict state) { // DCP -static void opcode_dcp_indx(struct nes_state * restrict state) { +static void opcode_dcp_indx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); @@ -253,7 +253,7 @@ static void opcode_dcp_indx(struct nes_state * restrict state) { update_zn(cpu, tmp & 0xff); } -static void opcode_dcp_zp(struct nes_state * restrict state) { +static void opcode_dcp_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); @@ -267,7 +267,7 @@ static void opcode_dcp_zp(struct nes_state * restrict state) { update_zn(cpu, tmp & 0xff); } -static void opcode_dcp_abs(struct nes_state * restrict state) { +static void opcode_dcp_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -284,7 +284,7 @@ static void opcode_dcp_abs(struct nes_state * restrict state) { update_zn(cpu, tmp & 0xff); } -static void opcode_dcp_indy(struct nes_state * restrict state) { +static void opcode_dcp_indy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); @@ -307,7 +307,7 @@ static void opcode_dcp_indy(struct nes_state * restrict state) { update_zn(cpu, tmp & 0xff); } -static void opcode_dcp_zpx(struct nes_state * restrict state) { +static void opcode_dcp_zpx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); @@ -324,7 +324,7 @@ static void opcode_dcp_zpx(struct nes_state * restrict state) { update_zn(cpu, tmp & 0xff); } -static void opcode_dcp_absy(struct nes_state * restrict state) { +static void opcode_dcp_absy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -344,7 +344,7 @@ static void opcode_dcp_absy(struct nes_state * restrict state) { update_zn(cpu, tmp & 0xff); } -static void opcode_dcp_absx(struct nes_state * restrict state) { +static void opcode_dcp_absx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -367,7 +367,7 @@ static void opcode_dcp_absx(struct nes_state * restrict state) { // ISC -static void opcode_isc_indx(struct nes_state * restrict state) { +static void opcode_isc_indx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); @@ -386,7 +386,7 @@ static void opcode_isc_indx(struct nes_state * restrict state) { sbc(cpu, value); } -static void opcode_isc_zp(struct nes_state * restrict state) { +static void opcode_isc_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); @@ -398,7 +398,7 @@ static void opcode_isc_zp(struct nes_state * restrict state) { sbc(cpu, value); } -static void opcode_isc_abs(struct nes_state * restrict state) { +static void opcode_isc_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -413,7 +413,7 @@ static void opcode_isc_abs(struct nes_state * restrict state) { sbc(cpu, value); } -static void opcode_isc_indy(struct nes_state * restrict state) { +static void opcode_isc_indy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); @@ -434,7 +434,7 @@ static void opcode_isc_indy(struct nes_state * restrict state) { sbc(cpu, value); } -static void opcode_isc_zpx(struct nes_state * restrict state) { +static void opcode_isc_zpx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); @@ -449,7 +449,7 @@ static void opcode_isc_zpx(struct nes_state * restrict state) { sbc(cpu, value); } -static void opcode_isc_absy(struct nes_state * restrict state) { +static void opcode_isc_absy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -467,7 +467,7 @@ static void opcode_isc_absy(struct nes_state * restrict state) { sbc(cpu, value); } -static void opcode_isc_absx(struct nes_state * restrict state) { +static void opcode_isc_absx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -488,7 +488,7 @@ static void opcode_isc_absx(struct nes_state * restrict state) { // SLO -static void opcode_slo_indx(struct nes_state * restrict state) { +static void opcode_slo_indx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); @@ -510,7 +510,7 @@ static void opcode_slo_indx(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_slo_zp(struct nes_state * restrict state) { +static void opcode_slo_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); @@ -525,7 +525,7 @@ static void opcode_slo_zp(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_slo_abs(struct nes_state * restrict state) { +static void opcode_slo_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -543,7 +543,7 @@ static void opcode_slo_abs(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_slo_indy(struct nes_state * restrict state) { +static void opcode_slo_indy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); @@ -567,7 +567,7 @@ static void opcode_slo_indy(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_slo_zpx(struct nes_state * restrict state) { +static void opcode_slo_zpx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); @@ -585,7 +585,7 @@ static void opcode_slo_zpx(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_slo_absy(struct nes_state * restrict state) { +static void opcode_slo_absy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -606,7 +606,7 @@ static void opcode_slo_absy(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_slo_absx(struct nes_state * restrict state) { +static void opcode_slo_absx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -630,7 +630,7 @@ static void opcode_slo_absx(struct nes_state * restrict state) { // RLA -static void opcode_rla_indx(struct nes_state * restrict state) { +static void opcode_rla_indx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); @@ -653,7 +653,7 @@ static void opcode_rla_indx(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_rla_zp(struct nes_state * restrict state) { +static void opcode_rla_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); @@ -669,7 +669,7 @@ static void opcode_rla_zp(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_rla_abs(struct nes_state * restrict state) { +static void opcode_rla_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -688,7 +688,7 @@ static void opcode_rla_abs(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_rla_indy(struct nes_state * restrict state) { +static void opcode_rla_indy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); @@ -713,7 +713,7 @@ static void opcode_rla_indy(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_rla_zpx(struct nes_state * restrict state) { +static void opcode_rla_zpx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); @@ -732,7 +732,7 @@ static void opcode_rla_zpx(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_rla_absy(struct nes_state * restrict state) { +static void opcode_rla_absy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -754,7 +754,7 @@ static void opcode_rla_absy(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_rla_absx(struct nes_state * restrict state) { +static void opcode_rla_absx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -779,7 +779,7 @@ static void opcode_rla_absx(struct nes_state * restrict state) { // SRE -static void opcode_sre_indx(struct nes_state * restrict state) { +static void opcode_sre_indx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); @@ -801,7 +801,7 @@ static void opcode_sre_indx(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_sre_zp(struct nes_state * restrict state) { +static void opcode_sre_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); @@ -816,7 +816,7 @@ static void opcode_sre_zp(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_sre_abs(struct nes_state * restrict state) { +static void opcode_sre_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -834,7 +834,7 @@ static void opcode_sre_abs(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_sre_indy(struct nes_state * restrict state) { +static void opcode_sre_indy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); @@ -858,7 +858,7 @@ static void opcode_sre_indy(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_sre_zpx(struct nes_state * restrict state) { +static void opcode_sre_zpx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); @@ -876,7 +876,7 @@ static void opcode_sre_zpx(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_sre_absy(struct nes_state * restrict state) { +static void opcode_sre_absy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -897,7 +897,7 @@ static void opcode_sre_absy(struct nes_state * restrict state) { update_zn(cpu, cpu->a); } -static void opcode_sre_absx(struct nes_state * restrict state) { +static void opcode_sre_absx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -921,7 +921,7 @@ static void opcode_sre_absx(struct nes_state * restrict state) { // opcode_rra -static void opcode_rra_indx(struct nes_state * restrict state) { +static void opcode_rra_indx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); @@ -943,7 +943,7 @@ static void opcode_rra_indx(struct nes_state * restrict state) { adc(cpu, value); } -static void opcode_rra_zp(struct nes_state * restrict state) { +static void opcode_rra_zp(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t addr = memory_read(state, cpu->pc++); @@ -958,7 +958,7 @@ static void opcode_rra_zp(struct nes_state * restrict state) { adc(cpu, value); } -static void opcode_rra_abs(struct nes_state * restrict state) { +static void opcode_rra_abs(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -976,7 +976,7 @@ static void opcode_rra_abs(struct nes_state * restrict state) { adc(cpu, value); } -static void opcode_rra_indy(struct nes_state * restrict state) { +static void opcode_rra_indy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t zp = memory_read(state, cpu->pc++); @@ -1000,7 +1000,7 @@ static void opcode_rra_indy(struct nes_state * restrict state) { adc(cpu, value); } -static void opcode_rra_zpx(struct nes_state * restrict state) { +static void opcode_rra_zpx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t base = memory_read(state, cpu->pc++); @@ -1018,7 +1018,7 @@ static void opcode_rra_zpx(struct nes_state * restrict state) { adc(cpu, value); } -static void opcode_rra_absy(struct nes_state * restrict state) { +static void opcode_rra_absy(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -1039,7 +1039,7 @@ static void opcode_rra_absy(struct nes_state * restrict state) { adc(cpu, value); } -static void opcode_rra_absx(struct nes_state * restrict state) { +static void opcode_rra_absx(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t lo = memory_read(state, cpu->pc++); @@ -1063,7 +1063,7 @@ static void opcode_rra_absx(struct nes_state * restrict state) { // ALR -static void opcode_alr_imm(struct nes_state * restrict state) { +static void opcode_alr_imm(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t value = memory_read(state, cpu->pc++); cpu->a &= value; @@ -1075,7 +1075,7 @@ static void opcode_alr_imm(struct nes_state * restrict state) { // ANC -static void opcode_anc_imm(struct nes_state * restrict state) { +static void opcode_anc_imm(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t value = memory_read(state, cpu->pc++); cpu->a &= value; @@ -1086,7 +1086,7 @@ static void opcode_anc_imm(struct nes_state * restrict state) { // ARR -static void opcode_arr_imm(struct nes_state * restrict state) { +static void opcode_arr_imm(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t value = memory_read(state, cpu->pc++); @@ -1103,7 +1103,7 @@ static void opcode_arr_imm(struct nes_state * restrict state) { // XAA -static void opcode_xaa_imm(struct nes_state * restrict state) { +static void opcode_xaa_imm(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t value = memory_read(state, cpu->pc++); @@ -1114,7 +1114,7 @@ static void opcode_xaa_imm(struct nes_state * restrict state) { // AXS -static void opcode_axs_imm(struct nes_state * restrict state) { +static void opcode_axs_imm(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; uint8_t value = memory_read(state, cpu->pc++); diff --git a/ines2.c b/ines2.c index dc0e57d..db28090 100644 --- a/ines2.c +++ b/ines2.c @@ -106,6 +106,7 @@ static int ines2_load(struct nes_state *state, const char *path) { } if(!data || size < INES_HEADER_SIZE) { + free(data); return -1; } diff --git a/mappers/mapper.c b/mappers/mapper.c index 71caff1..5636705 100644 --- a/mappers/mapper.c +++ b/mappers/mapper.c @@ -43,7 +43,7 @@ static void (*mapper_table[4096])(struct nes_state *state) = { [MAPPER_ID( 3, 2)] = mapper_003_2_init, [MAPPER_ID( 7, 2)] = mapper_007_2_init, [MAPPER_ID(11, 0)] = mapper_011_0_init, - [MAPPER_ID(66, 0)] = mapper_011_0_init, + [MAPPER_ID(66, 0)] = mapper_066_0_init, }; static void mapper_reset(struct nes_state *state) { diff --git a/mappers/mapper_000_0.c b/mappers/mapper_000_0.c index 8e46090..cc7baf8 100644 --- a/mappers/mapper_000_0.c +++ b/mappers/mapper_000_0.c @@ -1,13 +1,13 @@ -__attribute__((section(".mapper_000_0"), hot)) +__attribute__((section(".mapper_000_0"))) static uint8_t mapper_000_0_prg_read(struct nes_state *state, uint32_t addr) { struct mapper_000_0 *mapper = (struct mapper_000_0 *)&state->map; return state->prg_rom[addr & mapper->mask]; } -__attribute__((section(".mapper_000_0"), hot)) +__attribute__((section(".mapper_000_0"))) static uint8_t mapper_000_0_chr_read(struct nes_state *state, uint32_t addr) { return state->chr_rom[addr]; } diff --git a/mappers/mapper_001_0.c b/mappers/mapper_001_0.c index 519738e..0a03a27 100644 --- a/mappers/mapper_001_0.c +++ b/mappers/mapper_001_0.c @@ -1,5 +1,5 @@ -__attribute__((section(".mapper_001_0"), hot)) +__attribute__((section(".mapper_001_0"))) static uint8_t mapper_001_0_prg_read(struct nes_state *state, uint32_t addr) { struct mapper_001_0 *mapper = (struct mapper_001_0 *)&state->map; if(addr >= 0x8000) { @@ -12,7 +12,7 @@ static uint8_t mapper_001_0_prg_read(struct nes_state *state, uint32_t addr) { return 0; } -__attribute__((section(".mapper_001_0"), hot)) +__attribute__((section(".mapper_001_0"))) static void mapper_001_0_prg_write(struct nes_state *state, uint32_t addr, uint8_t value) { struct mapper_001_0 *mapper = (struct mapper_001_0 *)&state->map; if(addr < 0x8000) return; @@ -69,7 +69,7 @@ static void mapper_001_0_prg_write(struct nes_state *state, uint32_t addr, uint8 } } -__attribute__((section(".mapper_001_0"), hot)) +__attribute__((section(".mapper_001_0"))) static uint8_t mapper_001_0_chr_read(struct nes_state *state, uint32_t addr) { struct mapper_001_0 *mapper = (struct mapper_001_0 *)&state->map; if(mapper->control & 0x10) { @@ -85,18 +85,18 @@ static uint8_t mapper_001_0_chr_read(struct nes_state *state, uint32_t addr) { } } -__attribute__((section(".mapper_001_0"), hot)) +__attribute__((section(".mapper_001_0"))) static void mapper_001_0_chr_write(struct nes_state *state, uint32_t addr, uint8_t value) { // CHR RAM write (if present) state->chr_ram[addr] = value; } -__attribute__((section(".mapper_001_0"), hot)) +__attribute__((section(".mapper_001_0"))) static uint8_t mapper_001_0_ciram_read(struct nes_state *state, uint32_t addr) { return state->ciram[addr & 0x3ff]; } -__attribute__((section(".mapper_001_0"), hot)) +__attribute__((section(".mapper_001_0"))) static void mapper_001_0_ciram_write(struct nes_state *state, uint32_t addr, uint8_t value) { state->ciram[addr & 0x3ff] = value; } diff --git a/mappers/mapper_002_2.c b/mappers/mapper_002_2.c index b88c95b..4dbea85 100644 --- a/mappers/mapper_002_2.c +++ b/mappers/mapper_002_2.c @@ -1,6 +1,6 @@ -__attribute__((section(".mapper_002_2"), hot)) +__attribute__((section(".mapper_002_2"))) static uint8_t mapper_002_2_prg_read(struct nes_state *state, uint32_t addr) { struct mapper_002_2 *mapper = (struct mapper_002_2 *)&state->map; @@ -13,7 +13,7 @@ static uint8_t mapper_002_2_prg_read(struct nes_state *state, uint32_t addr) { return 0; } -__attribute__((section(".mapper_002_2"), hot)) +__attribute__((section(".mapper_002_2"))) static void mapper_002_2_prg_write(struct nes_state *state, uint32_t addr, uint8_t value) { struct mapper_002_2 *mapper = (struct mapper_002_2 *)&state->map; @@ -22,12 +22,12 @@ static void mapper_002_2_prg_write(struct nes_state *state, uint32_t addr, uint8 } } -__attribute__((section(".mapper_002_2"), hot)) +__attribute__((section(".mapper_002_2"))) static uint8_t mapper_002_2_chr_read(struct nes_state *state, uint32_t addr) { return state->chr_ram[addr]; } -__attribute__((section(".mapper_002_2"), hot)) +__attribute__((section(".mapper_002_2"))) static void mapper_002_2_chr_write(struct nes_state *state, uint32_t addr, uint8_t value) { state->chr_ram[addr] = value; } diff --git a/mappers/mapper_003_0.c b/mappers/mapper_003_0.c index e85d995..ec38f35 100644 --- a/mappers/mapper_003_0.c +++ b/mappers/mapper_003_0.c @@ -1,10 +1,10 @@ -__attribute__((section(".mapper_003_0"), hot)) +__attribute__((section(".mapper_003_0"))) static uint8_t mapper_003_0_prg_read(struct nes_state *state, uint32_t addr) { return state->prg_rom[addr & 0x7fff]; } -__attribute__((section(".mapper_003_0"), hot)) +__attribute__((section(".mapper_003_0"))) static void mapper_003_0_prg_write(struct nes_state *state, uint32_t addr, uint8_t value) { struct mapper_003_0 *mapper = (struct mapper_003_0 *)&state->map; @@ -13,7 +13,7 @@ static void mapper_003_0_prg_write(struct nes_state *state, uint32_t addr, uint8 } } -__attribute__((section(".mapper_003_0"), hot)) +__attribute__((section(".mapper_003_0"))) static uint8_t mapper_003_0_chr_read(struct nes_state *state, uint32_t addr) { struct mapper_003_0 *mapper = (struct mapper_003_0 *)&state->map; return mapper->chr_ptr[addr]; diff --git a/mappers/mapper_003_1.c b/mappers/mapper_003_1.c index fd7cd27..0032fbc 100644 --- a/mappers/mapper_003_1.c +++ b/mappers/mapper_003_1.c @@ -1,10 +1,10 @@ -__attribute__((section(".mapper_003_1"), hot)) +__attribute__((section(".mapper_003_1"))) static uint8_t mapper_003_1_prg_read(struct nes_state *state, uint32_t addr) { return state->prg_rom[addr & 0x7fff]; } -__attribute__((section(".mapper_003_1"), hot)) +__attribute__((section(".mapper_003_1"))) static void mapper_003_1_prg_write(struct nes_state *state, uint32_t addr, uint8_t value) { struct mapper_003_1 *mapper = (struct mapper_003_1 *)&state->map; @@ -13,7 +13,7 @@ static void mapper_003_1_prg_write(struct nes_state *state, uint32_t addr, uint8 } } -__attribute__((section(".mapper_003_1"), hot)) +__attribute__((section(".mapper_003_1"))) static uint8_t mapper_003_1_chr_read(struct nes_state *state, uint32_t addr) { struct mapper_003_1 *mapper = (struct mapper_003_1 *)&state->map; return mapper->chr_ptr[addr]; diff --git a/mappers/mapper_003_2.c b/mappers/mapper_003_2.c index b780a8f..73cfdc6 100644 --- a/mappers/mapper_003_2.c +++ b/mappers/mapper_003_2.c @@ -1,10 +1,10 @@ -__attribute__((section(".mapper_003_2"), hot)) +__attribute__((section(".mapper_003_2"))) static uint8_t mapper_003_2_prg_read(struct nes_state *state, uint32_t addr) { return state->prg_rom[addr & 0x7fff]; } -__attribute__((section(".mapper_003_2"), hot)) +__attribute__((section(".mapper_003_2"))) static void mapper_003_2_prg_write(struct nes_state *state, uint32_t addr, uint8_t value) { struct mapper_003_2 *mapper = (struct mapper_003_2 *)&state->map; @@ -14,7 +14,7 @@ static void mapper_003_2_prg_write(struct nes_state *state, uint32_t addr, uint8 } } -__attribute__((section(".mapper_003_2"), hot)) +__attribute__((section(".mapper_003_2"))) static uint8_t mapper_003_2_chr_read(struct nes_state *state, uint32_t addr) { struct mapper_003_2 *mapper = (struct mapper_003_2 *)&state->map; return mapper->chr_ptr[addr]; diff --git a/mappers/mapper_007_2.c b/mappers/mapper_007_2.c index 27125b9..c42bc62 100644 --- a/mappers/mapper_007_2.c +++ b/mappers/mapper_007_2.c @@ -1,5 +1,5 @@ -__attribute__((section(".mapper_007_2"), hot)) +__attribute__((section(".mapper_007_2"))) static uint8_t mapper_007_2_prg_read(struct nes_state *state, uint32_t addr) { struct mapper_007_2 *mapper = (struct mapper_007_2 *)&state->map; if(addr >= 0x8000) { @@ -8,7 +8,7 @@ static uint8_t mapper_007_2_prg_read(struct nes_state *state, uint32_t addr) { return 0; } -__attribute__((section(".mapper_007_2"), hot)) +__attribute__((section(".mapper_007_2"))) static void mapper_007_2_prg_write(struct nes_state *state, uint32_t addr, uint8_t value) { struct mapper_007_2 *mapper = (struct mapper_007_2 *)&state->map; if(addr >= 0x8000) { @@ -22,23 +22,23 @@ static void mapper_007_2_prg_write(struct nes_state *state, uint32_t addr, uint8 } } -__attribute__((section(".mapper_007_2"), hot)) +__attribute__((section(".mapper_007_2"))) static uint8_t mapper_007_2_chr_read(struct nes_state *state, uint32_t addr) { return state->chr_ram[addr]; } -__attribute__((section(".mapper_007_2"), hot)) +__attribute__((section(".mapper_007_2"))) static void mapper_007_2_chr_write(struct nes_state *state, uint32_t addr, uint8_t value) { state->chr_ram[addr] = value; } -__attribute__((section(".mapper_007_2"), hot)) +__attribute__((section(".mapper_007_2"))) static uint8_t mapper_007_2_ciram_read(struct nes_state *state, uint32_t addr) { struct mapper_007_2 *mapper = (struct mapper_007_2 *)&state->map; return mapper->ciram[addr & 0x3ff]; } -__attribute__((section(".mapper_007_2"), hot)) +__attribute__((section(".mapper_007_2"))) static void mapper_007_2_ciram_write(struct nes_state *state, uint32_t addr, uint8_t value) { struct mapper_007_2 *mapper = (struct mapper_007_2 *)&state->map; mapper->ciram[addr & 0x3ff] = value; diff --git a/mappers/mapper_011_0.c b/mappers/mapper_011_0.c index d6d518c..e5db02c 100644 --- a/mappers/mapper_011_0.c +++ b/mappers/mapper_011_0.c @@ -1,5 +1,5 @@ -__attribute__((section(".mapper_011_0"), hot)) +__attribute__((section(".mapper_011_0"))) static uint8_t mapper_011_0_prg_read(struct nes_state *state, uint32_t addr) { struct mapper_011_0 *mapper = (struct mapper_011_0 *)&state->map; @@ -9,7 +9,7 @@ static uint8_t mapper_011_0_prg_read(struct nes_state *state, uint32_t addr) { return 0; } -__attribute__((section(".mapper_011_0"), hot)) +__attribute__((section(".mapper_011_0"))) static void mapper_011_0_prg_write(struct nes_state *state, uint32_t addr, uint8_t value) { struct mapper_011_0 *mapper = (struct mapper_011_0 *)&state->map; @@ -19,7 +19,7 @@ static void mapper_011_0_prg_write(struct nes_state *state, uint32_t addr, uint8 } } -__attribute__((section(".mapper_011_0"), hot)) +__attribute__((section(".mapper_011_0"))) static uint8_t mapper_011_0_chr_read(struct nes_state *state, uint32_t addr) { struct mapper_011_0 *mapper = (struct mapper_011_0 *)&state->map; diff --git a/mappers/mapper_066_0.c b/mappers/mapper_066_0.c index 7a8f49c..9629fb2 100644 --- a/mappers/mapper_066_0.c +++ b/mappers/mapper_066_0.c @@ -1,5 +1,5 @@ -__attribute__((section(".mapper_066_0"), hot)) +__attribute__((section(".mapper_066_0"))) static uint8_t mapper_066_0_prg_read(struct nes_state *state, uint32_t addr) { struct mapper_066_0 *mapper = (struct mapper_066_0 *)&state->map; @@ -9,7 +9,7 @@ static uint8_t mapper_066_0_prg_read(struct nes_state *state, uint32_t addr) { return 0; } -__attribute__((section(".mapper_066_0"), hot)) +__attribute__((section(".mapper_066_0"))) static void mapper_066_0_prg_write(struct nes_state *state, uint32_t addr, uint8_t value) { struct mapper_066_0 *mapper = (struct mapper_066_0 *)&state->map; @@ -22,7 +22,7 @@ static void mapper_066_0_prg_write(struct nes_state *state, uint32_t addr, uint8 } } -__attribute__((section(".mapper_066_0"), hot)) +__attribute__((section(".mapper_066_0"))) static uint8_t mapper_066_0_chr_read(struct nes_state *state, uint32_t addr) { struct mapper_066_0 *mapper = (struct mapper_066_0 *)&state->map; return mapper->chr_offset[addr]; diff --git a/memory.c b/memory.c index 6e0c6df..90ae8b6 100644 --- a/memory.c +++ b/memory.c @@ -2,7 +2,7 @@ __attribute__((hot)) -static uint8_t memory_read(struct nes_state *restrict state, uint32_t offset) { +static inline uint8_t memory_read(struct nes_state *state, uint32_t offset) { state->cpu.cycles++; ppu_tick(state); // apu_tick(state); @@ -23,33 +23,11 @@ static uint8_t memory_read(struct nes_state *restrict state, uint32_t offset) { return value | 0x40; // Bit 6 open bus high, bit 7 low } -#if 0 - if(LIKELY(offset < 0x2000)) { // SECOND - return state->ram[offset & 0x07ff]; - - } else if(offset < 0x4000) { // THIRD - return ppu_read(state, offset); - - } else if(offset == 0x4016 || offset == 0x4017) { - uint32_t index = offset & 1; - uint8_t value = (state->ppu.input_latch[index] >> state->ppu.input_bit[index]) & 1; - state->ppu.input_bit[index]++; - return value | 0x40; // Bit 6 open bus high, bit 7 low - - // } else if(offset == 4015) { - // static uint32_t apuread = 0; - // // printf("%.5d apu\n", apuread++); - - } else if(LIKELY(offset >= 0x6000)) { // MOST - return state->mapper.prg_read(state, offset); - - } -#endif return 0; } __attribute__((hot)) -static void memory_write(struct nes_state *restrict state, uint32_t offset, uint8_t value) { +static inline void memory_write(struct nes_state *state, uint32_t offset, uint8_t value) { state->cpu.cycles++; ppu_tick(state); // apu_tick(state); @@ -93,8 +71,7 @@ static void memory_write(struct nes_state *restrict state, uint32_t offset, uint } } -__attribute__((hot)) -static uint8_t memory_read_dma(struct nes_state *restrict state, uint32_t offset) { +static inline uint8_t memory_read_dma(struct nes_state *state, uint32_t offset) { // Do not tick CPU/PPU/APU — caller handles timing if(LIKELY(offset < 0x2000)) { return state->ram[offset & 0x07ff]; @@ -106,8 +83,7 @@ static uint8_t memory_read_dma(struct nes_state *restrict state, uint32_t offset return 0; } -__attribute__((hot)) -static uint8_t memory_read_dummy(struct nes_state *restrict state, uint32_t offset) { +static inline uint8_t memory_read_dummy(struct nes_state *state, uint32_t offset) { state->cpu.cycles++; ppu_tick(state); // apu_tick(state); diff --git a/mknes.c b/mknes.c index 7220450..9e87a33 100644 --- a/mknes.c +++ b/mknes.c @@ -8,6 +8,8 @@ #include #include +#define printf(...) + #define BUFFER_WIDTH 256 #define BUFFER_HEIGHT 240 #define WINDOW_WIDTH 320 * 3 @@ -105,7 +107,7 @@ static uint32_t frames; // debug information #include "callbacks.c" -struct nes_state nstate; +// struct nes_state nstate; int main(int argc, char **argv) { #ifdef _WIN32 @@ -118,13 +120,17 @@ int main(int argc, char **argv) { init_opcode_lut(); init_opcode_ud_lut(); // protect_opcode_lut(); - ppu_reset(&nstate); + + struct nes_state *nstate = aligned_alloc(4096, (sizeof(struct nes_state) + 4095) & ~4096); + + + ppu_reset(nstate); // ines2_load(&nstate, "data/0000/10-Yard Fight (USA, Europe).nes"); // ines2_load(&nstate, "data/0000/Balloon Fight (USA).nes"); // ines2_load(&nstate, "data/0000/Excitebike (Japan, USA).nes"); // ines2_load(&nstate, "data/0000/Ice Climber (USA, Europe, Korea).nes"); // ines2_load(&nstate, "data/0000/Kung Fu (Japan, USA).nes"); - ines2_load(&nstate, "data/0000/Super Mario Bros. (World) (HVC-SM).nes"); + ines2_load(nstate, "data/0000/Super Mario Bros. (World) (HVC-SM).nes"); // ines2_load(&nstate, "data/Super Mario Bros. (W) (V1.0) [!].nes"); // ines2_load(&nstate, "data/Super Mario Bros. (JU) [!].nes"); // ines2_load(&nstate, "data/0000/Urban Champion (World).nes"); @@ -146,13 +152,13 @@ int main(int argc, char **argv) { // ines2_load(&nstate, "data/0000/Xevious - The Avenger (USA).zip"); // ines2_load(&nstate, "data/tv.nes"); - ines2_load(&nstate, "data/Life Force (USA).zip"); // 2002 + // ines2_load(&nstate, "data/Life Force (USA).zip"); // 2002 // ines2_load(&nstate, "data/0003/Flipull - An Exciting Cube Game (Japan) (En).zip"); // ines2_load(&nstate, "data/0003/Friday the 13th (USA).zip"); // ines2_load(&nstate, "data/0003/Ghostbusters (Japan).zip"); // ines2_load(&nstate, "data/0003/Gradius (USA).zip"); - // ines2_load(&nstate, "data/0007/Battletoads (USA).zip"); + // ines2_load(nstate, "data/0007/Battletoads (USA).zip"); // ines2_load(&nstate, "data/0007/Beetlejuice (USA).zip"); // ines2_load(&nstate, "data/0007/Cabal (USA).zip"); @@ -167,22 +173,22 @@ int main(int argc, char **argv) { // ines2_load(&nstate, "data/Blaster Master (USA).zip"); - mapper_setup(&nstate); - uint32_t lo = nstate.mapper.prg_read(&nstate, 0xfffc); - uint32_t hi = nstate.mapper.prg_read(&nstate, 0xfffd); - nstate.cpu.pc = (hi << 8) | lo; + mapper_setup(nstate); + uint32_t lo = nstate->mapper.prg_read(nstate, 0xfffc); + uint32_t hi = nstate->mapper.prg_read(nstate, 0xfffd); + nstate->cpu.pc = (hi << 8) | lo; #if 1 for(uint32_t i = 0; i < 0x5000; ++ i) { - while(!nstate.ppu.frame_ready) { + while(!nstate->ppu.frame_ready) { // PROFILE_NAMED("nes emulator"); - cpu_tick(&nstate); + cpu_tick(nstate); } - nstate.ppu.frame_ready = 0; + nstate->ppu.frame_ready = 0; frames++; } return 0; -#endif +#else struct timer_handle *timer = timer_new(FRAME_INTERVAL_NS); if(!timer) { @@ -198,10 +204,12 @@ int main(int argc, char **argv) { window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "NES Emulator", 0, 0); if(window) { - glfwSetWindowUserPointer(window, (void*)&nstate); + glfwSetWindowUserPointer(window, (void*)nstate); glfwSetWindowAspectRatio(window, 320, 240); // Need to set a 4:3 resolution for things to look correct! glfwSetWindowSizeLimits(window, WINDOW_WIDTH, WINDOW_HEIGHT, GLFW_DONT_CARE, GLFW_DONT_CARE); + glfwSetInputMode(window, GLFW_STICKY_KEYS, GLFW_TRUE); + glfwMakeContextCurrent(window); opengl_setup(); glfwSetKeyCallback(window, key_callback); @@ -226,15 +234,28 @@ int main(int argc, char **argv) { timer_wait(timer); glfwPollEvents(); - while(!nstate.ppu.frame_ready) { + uint8_t input = 0; + + if(glfwGetKey(window, GLFW_KEY_X) == GLFW_PRESS) { input |= (1 << 0); } + if(glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS) { input |= (1 << 1); } + if(glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) { input |= (1 << 2); } + if(glfwGetKey(window, GLFW_KEY_ENTER) == GLFW_PRESS) { input |= (1 << 3); } + if(glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS) { input |= (1 << 4); } + if(glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS) { input |= (1 << 5); } + if(glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS) { input |= (1 << 6); } + if(glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS) { input |= (1 << 7); } + + nstate->ppu.input[0] = input; + + while(!nstate->ppu.frame_ready) { // PROFILE_NAMED("nes emulator"); - cpu_tick(&nstate); + cpu_tick(nstate); } - nstate.ppu.frame_ready = 0; + nstate->ppu.frame_ready = 0; frames++; uint32_t * restrict dst = display_buffer; //buffer; - uint8_t * restrict src = nstate.pixels; + 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++; @@ -248,7 +269,7 @@ int main(int argc, char **argv) { glfwSwapBuffers(window); } - printf("total frames: %6.6d total cycles: %ld\n", frames, nstate.cpu.cycles); + printf("total frames: %6.6d total cycles: %ld\n", frames, nstate->cpu.cycles); glfwDestroyWindow(window); } else { @@ -261,6 +282,8 @@ int main(int argc, char **argv) { } timer_destroy(timer); // free_nes_state(&nstate); +#endif + #ifdef _WIN32 timeEndPeriod(1); #endif diff --git a/mknes.h b/mknes.h index fba1406..c169140 100644 --- a/mknes.h +++ b/mknes.h @@ -1,10 +1,8 @@ -#define PPU_CTRL_NMI 0x80 #define PPU_CTRL_BG_TILE_SELECT 0x10 #define PPU_CTRL_SPRITE_TILE_SELECT 0x08 -#define PPU_CTRL_VRAM_INCREMENT 0x04 // Define constants for PPU control and mask bits #define PPU_CTRL_NMI 0x80 @@ -44,12 +42,9 @@ struct ppu_state { uint8_t reg_status; uint8_t write_latch; - uint8_t vram_read_buffer; - uint8_t open_bus; - uint8_t sprite_zero_hit_possible; uint8_t sprite_count; uint8_t palette[32]; @@ -82,7 +77,7 @@ struct apu_state { struct cpu_state { size_t cycles; - uint32_t pc; // Program Counter + uint16_t pc; // Program Counter uint8_t sp; // Stack Pointer uint8_t a; // Accumulator uint8_t x; // X Register @@ -112,9 +107,10 @@ struct ines_state { struct nes_state { struct ppu_state ppu; struct mapper_functions mapper; - union mapper_data map; - struct ines_state ines; + // union mapper_data map; + char map[sizeof(union mapper_data)] __attribute__((aligned(64))); // NOTE(peter): Only way due to aliasing rules in the C standard. struct cpu_state cpu; + struct ines_state ines; // struct apu_state apu; uint8_t ram[RAM_SIZE] __attribute__((aligned(4096))); @@ -134,5 +130,6 @@ __attribute__((aligned(4096))) static uint32_t nes_palette[65] = { 0xffffffff, 0x51a5feff, 0x8084feff, 0xbc6afeff, 0xf15bfeff, 0xfe5ec4ff, 0xfe7269ff, 0xe19321ff, 0xadb600ff, 0x79d300ff, 0x51df21ff, 0x3ad974ff, 0x39c3dfff, 0x424242ff, 0x000000ff, 0x000000ff, 0xffffffff, 0xb5d9feff, 0xcacafeff, 0xe3befeff, 0xf9b8feff, 0xfebae7ff, 0xfec3bcff, 0xf4d199ff, - 0xdee086ff, 0xc6ec87ff, 0xb2f29dff, 0xa7f0c3ff, 0xa8e7f0ff, 0xacacacff, 0x000000ff, 0x000000ff, 0xffffffff + 0xdee086ff, 0xc6ec87ff, 0xb2f29dff, 0xa7f0c3ff, 0xa8e7f0ff, 0xacacacff, 0x000000ff, 0x000000ff, + 0xffffffff // one extra for debug-coloring... }; diff --git a/ppu.c b/ppu.c index 6f5a4eb..1cb29b8 100644 --- a/ppu.c +++ b/ppu.c @@ -26,8 +26,8 @@ static void ppu_reset(struct nes_state *state) { } -__attribute__((hot)) -static void ppu_evaluate_sprites(struct nes_state *state) { +// __attribute__((hot)) +static inline void ppu_evaluate_sprites(struct nes_state *state) { struct ppu_state *restrict ppu = &state->ppu; uint8_t sprite_height = (ppu->reg_ctrl & 0x20) ? 16 : 8; uint8_t n = 0; @@ -59,8 +59,8 @@ static void ppu_evaluate_sprites(struct nes_state *state) { ppu->sprite_count = n; } -__attribute__((hot)) -static void ppu_fetch_sprite_patterns(struct nes_state *state) { +// __attribute__((hot)) +static inline void ppu_fetch_sprite_patterns(struct nes_state *state) { struct ppu_state *restrict ppu = &state->ppu; uint32_t addr; uint32_t bank; @@ -105,7 +105,7 @@ static void ppu_fetch_sprite_patterns(struct nes_state *state) { } } -__attribute__((always_inline, hot)) +__attribute__((hot)) static inline void ppu_render_pixel(struct nes_state *state) { struct ppu_state *restrict ppu = &state->ppu; @@ -173,7 +173,7 @@ static inline void ppu_render_pixel(struct nes_state *state) { } __attribute__((hot, flatten)) -static void ppu_tick(struct nes_state *state) { +static inline void ppu_tick(struct nes_state *state) { struct ppu_state *restrict ppu = &state->ppu; uint32_t dot = ppu->dot; diff --git a/ppu_registers.c b/ppu_registers.c index f6bd515..98e2c7d 100644 --- a/ppu_registers.c +++ b/ppu_registers.c @@ -1,4 +1,4 @@ -__attribute__((always_inline, hot)) +__attribute__((hot)) static inline void ppu_write(struct nes_state *state, uint32_t offset, uint8_t value) { struct ppu_state *ppu = &state->ppu; @@ -70,7 +70,7 @@ static inline void ppu_write(struct nes_state *state, uint32_t offset, uint8_t v } } -__attribute__((always_inline, hot)) +__attribute__((hot)) static inline uint8_t ppu_read(struct nes_state *state, uint32_t offset) { struct ppu_state *ppu = &state->ppu; uint8_t result = ppu->open_bus; @@ -120,7 +120,7 @@ static inline uint8_t ppu_read(struct nes_state *state, uint32_t offset) { static uint8_t memory_read_dma(struct nes_state *state, uint32_t offset); __attribute__((hot)) -static void ppu_dma_4014(struct nes_state *state, uint8_t page) { +static inline void ppu_dma_4014(struct nes_state *state, uint8_t page) { uint32_t base = page << 8; // Add 1 or 2 idle cycles depending on current CPU cycle diff --git a/render.c b/render.c index 6e399ef..625753d 100644 --- a/render.c +++ b/render.c @@ -1,7 +1,6 @@ /* [=]===^=[ clear_buffer ]=================================================================^===[=] */ -__attribute__((always_inline, hot)) static inline void clear_buffer(void) { // PROFILE_FUNCTION(); memset(buffer, 0, sizeof(buffer)); @@ -16,7 +15,6 @@ static void set_decay(uint16_t old_weight) { } /* [=]===^=[ apply_phosphor_decay ]=================================================================^===[=] */ -// __attribute__((always_inline, hot)) // static inline void apply_phosphor_decay(void) { // // PROFILE_FUNCTION(); // __m256i old_weight = _mm256_set1_epi16(_old_weight); diff --git a/shader.c b/shader.c index a6e16f6..fab0f88 100644 --- a/shader.c +++ b/shader.c @@ -23,7 +23,7 @@ * thin, mask - Inputs shared between CrtsTone() and CrtsFilter() * */ -static void CrtsTone(float * restrict dst, float contrast, float saturation, float thin, float mask) { +static void CrtsTone(float *dst, float contrast, float saturation, float thin, float mask) { //-------------------------------------------------------------- #ifdef CRTS_MASK_NONE mask = 1.0f; -- cgit v1.2.3