Skip to content

Instantly share code, notes, and snippets.

@jacobmischka
Created January 31, 2015 23:04
Show Gist options
  • Save jacobmischka/8ec2d696265712e3aa22 to your computer and use it in GitHub Desktop.
Save jacobmischka/8ec2d696265712e3aa22 to your computer and use it in GitHub Desktop.
stack
/* --- Stack operations --- */
static void pushb(BYTE val) {
Memory_WriteByte((STACK_ADDR | cpu.SP--), val);
}
static void pushw(WORD val) {
BYTE tmp = (BYTE)(val & 0xFF);
Memory_WriteByte((STACK_ADDR | cpu.SP--), tmp);
tmp = (BYTE)((val & 0xFF00) >> 8);
Memory_WriteByte((STACK_ADDR | cpu.SP--), tmp);
}
static BYTE pullb() {
return Memory_ReadByte((STACK_ADDR | ++cpu.SP));
}
static WORD pullw() {
WORD tmp = (WORD)Memory_ReadByte((STACK_ADDR | ++cpu.SP));
return tmp & (WORD)(Memory_ReadByte((STACK_ADDR | ++cpu.SP)) << 8);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment