Add some RAM and a stack

This commit is contained in:
Michael Smith
2025-08-29 17:04:30 +02:00
parent 1bae615b39
commit 82d3898216
4 changed files with 179 additions and 1 deletions

View File

@@ -110,3 +110,27 @@ func (cpu *CPU) ToggleFlag(flag CPUFlags) {
func (cpu *CPU) IsFlagSet(flag CPUFlags) bool {
return cpu.Regs.F&flag != 0
}
func (cpu *CPU) StackPush(data byte) {
cpu.Regs.SP--
cpu.Bus.Write(cpu.Regs.SP, data)
}
func (cpu *CPU) StackPush16(data uint16) {
cpu.StackPush(byte((data >> 8) & 0xFF))
cpu.StackPush(byte(data & 0xFF))
}
func (cpu *CPU) StackPop() byte {
val := cpu.Bus.Read(cpu.Regs.SP)
cpu.Regs.SP++
return val
}
func (cpu *CPU) StackPop16() uint16 {
lo := cpu.StackPop()
hi := cpu.StackPop()
return uint16(hi)<<8 | uint16(lo)
}