izapple2/core6502/registers_test.go

70 lines
1.2 KiB
Go
Raw Normal View History

package core6502
2019-01-26 15:59:36 +00:00
import "testing"
2019-01-26 17:57:03 +00:00
func TestRegA(t *testing.T) {
var r registers
2019-01-26 15:59:36 +00:00
var data uint8
data = 200
2019-01-26 17:57:03 +00:00
r.setA(data)
if r.getA() != data {
2019-01-26 15:59:36 +00:00
t.Error("Error storing and loading A")
}
}
2019-01-26 17:57:03 +00:00
func TestRegPC(t *testing.T) {
var r registers
2019-01-26 15:59:36 +00:00
var data uint16
data = 0xc600
2019-01-26 17:57:03 +00:00
r.setPC(data)
if r.getPC() != data {
2019-01-26 15:59:36 +00:00
t.Error("Error storing and loading PC")
}
2019-01-26 17:57:03 +00:00
}
2019-01-27 22:03:08 +00:00
func TestFlags(t *testing.T) {
var r registers
2019-01-27 22:03:08 +00:00
r.setP(0x23)
if r.getP() != 0x23 {
t.Error("Error storing and loading P")
}
r.setP(0)
r.setFlag(flagD)
if !r.getFlag(flagD) {
t.Error("Error setting and getting flag")
}
r.clearFlag(flagD)
if r.getFlag(flagD) {
t.Error("Error clearing flag")
}
r.updateFlag(flagD, true)
if !r.getFlag(flagD) {
t.Error("Error update flag to true")
}
r.updateFlag(flagD, false)
if r.getFlag(flagD) {
t.Error("Error updating flag to false")
}
}
func TestUpdateFlagZN(t *testing.T) {
var r registers
2019-01-27 22:03:08 +00:00
r.updateFlagZN(0)
if r.getP() != flagZ {
t.Error("Error update flags ZN with 0")
}
r.updateFlagZN(0x10)
if r.getP() != 0 {
t.Error("Error update flags ZN with 0x10")
}
r.updateFlagZN(0xF2)
if r.getP() != flagN {
t.Error("Error update flags ZN with 0xF2")
}
}