mirror of
https://github.com/bradford-hamilton/apple-1.git
synced 2024-05-31 14:41:29 +00:00
8d6a0f8fd3
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.
50 lines
961 B
Go
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
|
|
}
|