internal/vm/{exec_funcs,opcodes}: add support for executing DEY, DEX, TAY, TAX opcodes

This commit is contained in:
Bradford Lamson-Scribner 2020-05-31 09:38:10 -06:00
parent 00cec5678e
commit 3743c0b0d8
2 changed files with 64 additions and 4 deletions

View File

@ -79,3 +79,52 @@ func execINY(a *Appleone, o op) error {
a.setNegativeIfOverflow(b)
return nil
}
// A -> X N Z C I D V
// + + - - - -
func execTAX(a *Appleone, o op) error {
a.cpu.x = a.cpu.a
a.setZeroIfNeeded(a.cpu.x)
a.setNegativeIfOverflow(a.cpu.x)
return nil
}
// A -> Y N Z C I D V
// + + - - - -
func execTAY(a *Appleone, o op) error {
a.cpu.y = a.cpu.a
a.setZeroIfNeeded(a.cpu.y)
a.setNegativeIfOverflow(a.cpu.y)
return nil
}
// X - 1 -> X N Z C I D V
// + + - - - -
func execDEX(a *Appleone, o op) error {
b := a.cpu.x - 1
a.cpu.x = b
a.setZeroIfNeeded(b)
a.setNegativeIfOverflow(b)
return nil
}
// Y - 1 -> Y N Z C I D V
// + + - - - -
func execDEY(a *Appleone, o op) error {
b := a.cpu.y - 1
a.cpu.y = b
a.setZeroIfNeeded(b)
a.setNegativeIfOverflow(b)
return nil
}
// M -> A N Z C I D V
// + + - - - -
func execLDA(a *Appleone, o op) error {
b, err := o.getData(a)
if err != nil {
return err
}
a.cpu.a = b
return nil
}

View File

@ -70,6 +70,17 @@ func (o op) getAddr(a *Appleone) (uint16, error) {
}
}
func (o op) getData(a *Appleone) (uint8, error) {
if o.addrMode == accumulator {
return a.cpu.a, nil
}
b, err := o.getAddr(a)
if err != nil {
return 0, err
}
return a.mem[b], nil
}
// opcodes represent all of the Apple 1 opcodes available. Each 8 bit opcode is mapped to a corresponding
// "op" which is just a struct holding metadata about the operation.
var opcodes = map[uint8]op{
@ -125,25 +136,25 @@ var opcodes = map[uint8]op{
// addressing assembler opc bytes cyles
// --------------------------------------------
// implied TAX AA 1 2
0xAA: newOp("TAX", 0xAA, 1, implied, todo),
0xAA: newOp("TAX", 0xAA, 1, implied, execTAX),
// TAY Transfer Accumulator to Index Y
// addressing assembler opc bytes cyles
// --------------------------------------------
// implied TAY A8 1 2
0xA8: newOp("TAY", 0xA8, 1, implied, todo),
0xA8: newOp("TAY", 0xA8, 1, implied, execTAY),
// DEX Decrement Index X by One
// addressing assembler opc bytes cyles
// --------------------------------------------
// implied DEC CA 1 2
0xCA: newOp("DEX", 0xCA, 1, implied, todo),
0xCA: newOp("DEX", 0xCA, 1, implied, execDEX),
// DEY Decrement Index Y by One
// addressing assembler opc bytes cyles
// --------------------------------------------
// implied DEC 88 1 2
0x88: newOp("DEY", 0x88, 1, implied, todo),
0x88: newOp("DEY", 0x88, 1, implied, execDEY),
// LDA Load Accumulator with Memory
// addressing assembler opc bytes cyles