diff --git a/src/instruction.c b/src/instruction.c index 40b4824..7654e1e 100644 --- a/src/instruction.c +++ b/src/instruction.c @@ -220,3 +220,23 @@ instruction_data_read_1(rk65c02emu_t *e, instrdef_t *id, instruction_t *i) return rv; } +/* put value onto the stack */ +void +stack_push(rk65c02emu_t *e, uint8_t val) +{ + bus_write_1(e->bus, STACK_START+e->regs.SP, val); + e->regs.SP--; +} + +/* pull/pop value from the stack */ +uint8_t +stack_pop(rk65c02emu_t *e) +{ + uint8_t val; + + val = bus_read_1(e->bus, STACK_START+e->regs.SP); + e->regs.SP++; + + return val; +} + diff --git a/src/rk65c02.h b/src/rk65c02.h index 6b0e698..8c748f8 100644 --- a/src/rk65c02.h +++ b/src/rk65c02.h @@ -28,7 +28,10 @@ struct reg_state { #define P_SIGN_OVERFLOW 0x40 #define P_NEGATIVE 0x80 -#define NEGATIVE P_NEGATIVE +#define NEGATIVE P_NEGATIVE /* sign bit */ + +#define STACK_START 0x0100 +#define STACK_END 0x01FF typedef struct reg_state reg_state_t;