From fcd25f63850fba8848301c03c149598fb8d75db3 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Sat, 20 Jan 2018 23:43:58 -0600 Subject: [PATCH] Use set16 to push items to the stack. The previous method was not incorrect, but set16 already handles the little-endian logic for us, and there's no need to do something bespoke here that we then need to test for separately. --- src/mos6502.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/mos6502.c b/src/mos6502.c index eab4620..acb6ec6 100644 --- a/src/mos6502.c +++ b/src/mos6502.c @@ -191,13 +191,7 @@ mos6502_free(mos6502 *cpu) void mos6502_push_stack(mos6502 *cpu, vm_16bit addr) { - // First we need to set the hi byte, by shifting the address right 8 - // positions and using the base offset of the S register. - mos6502_set(cpu, 0x0100 + cpu->S, addr & 0xff); - - // Next we must record the lo byte, this time by using a bitmask to - // capture just the low end of addr, but recording it in S + 1. - mos6502_set(cpu, 0x0100 + cpu->S + 1, addr >> 8); + mos6502_set16(cpu, 0x100 + cpu->S, addr); // And finally we need to increment S by 2 (since we've used two // bytes in the stack).