From 3887f52119a3dfbd47551d41ffcc7f72890623ba Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Fri, 13 Apr 2018 16:22:58 -0500 Subject: [PATCH] Clarify behavior of pop_stack --- src/mos6502/mos6502.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/mos6502/mos6502.c b/src/mos6502/mos6502.c index 637d891..98cfa9a 100644 --- a/src/mos6502/mos6502.c +++ b/src/mos6502/mos6502.c @@ -211,18 +211,15 @@ mos6502_push_stack(mos6502 *cpu, vm_8bit addr) } /* - * Pop an address from the stack and return that. + * Increment the stack register and return the value that is pointed at + * by the new offset. Because the S register is 8-bit, the following + * (correct) behavior is exhibited: when S overflows beyond 0xFF, it + * rolls over to 0x00. */ vm_8bit mos6502_pop_stack(mos6502 *cpu) { - // The first thing we want to do here is to decrement S by 2, since - // the value we want to return is two positions back. cpu->S++; - - // We need to use a bitwise-or operation to combine the hi and lo - // bytes we retrieve from the stack into the actual position we - // would use for the PC register. return mos6502_get(cpu, 0x0100 + cpu->S); }