bradford-hamilton-apple-1/internal/vm/exec_funcs.go
Bradford Lamson-Scribner 8d6a0f8fd3 internal/vm: start playing with op executions
So far the pattern feels a tiny bit weird but also has been nice to work
with. As you can see, the op now contains it’s instruction execution func
which can be called directly from the op.
2020-05-30 17:06:36 -06:00

50 lines
961 B
Go

package vm
import "fmt"
func todo(a *Appleone, o op) error {
fmt.Println("implement me")
return nil
}
// interrupt, N Z C I D V
// push PC+2, push SR - - - 1 - -
func exec0x00(a *Appleone, o op) error {
// set processer status flag to BRK
a.cpu.ps = flagBreak
a.pushDWordToStack(a.cpu.pc + 1)
a.pushWordToStack(a.cpu.ps)
a.cpu.ps |= flagDisableInterrupts
a.cpu.pc = uint16(a.mem[0xFFFF])<<8 | uint16(a.mem[0xFFFE])
return nil
}
// pull SR, pull PC N Z C I D V
// from stack
func exec0x40(a *Appleone, o op) error {
a.cpu.ps = a.popStackWord()
a.cpu.pc = a.popStackDWord()
return nil
}
// M - 1 -> M N Z C I D V
// + + - - - -
func exec0xC6(a *Appleone, o op) error {
addr, err := o.getAddr(a)
if err != nil {
return err
}
b := a.mem[addr]
b--
a.mem[addr] = b
a.setZeroIfNeeded(b)
a.setNegativeIfOverflow(b)
return nil
}