mirror of
https://github.com/irmen/ksim65.git
synced 2025-01-19 17:29:54 +00:00
corrected BRK flag incompatibility + unit tests
This commit is contained in:
parent
5667c00d85
commit
1e27e5bae4
@ -1252,8 +1252,9 @@ open class Cpu6502 : BusComponent() {
|
||||
}
|
||||
|
||||
protected fun iPlp(): Boolean {
|
||||
val previousB = regP.B
|
||||
regP.fromInt(popStack())
|
||||
regP.B = false
|
||||
regP.B = previousB
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -226,9 +226,9 @@ class Test6502CpuBasics {
|
||||
// http://www.qmtpro.com/~nes/misc/nestest.txt
|
||||
|
||||
class NesCpu: Cpu6502() {
|
||||
fun resetTotalCycles(cycles: Long) {
|
||||
totalCycles = cycles
|
||||
instrCycles = 0
|
||||
override fun reset() {
|
||||
super.reset()
|
||||
instrCycles = 7 // the nintdulator cpu emu starts with this number of cycles
|
||||
}
|
||||
|
||||
override fun iAdc(): Boolean {
|
||||
@ -252,7 +252,6 @@ class Test6502CpuBasics {
|
||||
|
||||
val cpu = NesCpu()
|
||||
val ram = Ram(0, 0xffff)
|
||||
val disassembler = Disassembler(cpu)
|
||||
|
||||
val bytes = javaClass.getResource("nestest.nes").readBytes().drop(0x10).take(0x4000).toByteArray()
|
||||
ram.load(bytes, 0x8000)
|
||||
@ -261,10 +260,10 @@ class Test6502CpuBasics {
|
||||
bus.add(cpu)
|
||||
bus.add(ram)
|
||||
bus.reset()
|
||||
cpu.resetTotalCycles(7) // that is what the nes rom starts with
|
||||
cpu.regPC = 0xc000
|
||||
var tracingSnapshot = cpu.snapshot()
|
||||
cpu.tracing = { tracingSnapshot=it }
|
||||
// val disassembler = Disassembler(cpu)
|
||||
|
||||
val neslog = javaClass.getResource("nestest.log").readText().lineSequence()
|
||||
for(logline in neslog) {
|
||||
|
@ -1,3 +1,4 @@
|
||||
import org.junit.jupiter.api.Disabled
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import razorvine.ksim65.*
|
||||
import razorvine.ksim65.components.*
|
||||
@ -4150,13 +4151,13 @@ abstract class TestCommon6502 {
|
||||
|
||||
@Test
|
||||
fun test_plp_pulls_top_byte_from_stack_into_flags_and_updates_sp() {
|
||||
// $0000 PLP
|
||||
memory[0x0000] = 0x28
|
||||
memory[0x01FF] = 0xBA // must have BREAK and UNUSED set
|
||||
mpu.regP.fromInt(0)
|
||||
memory[0x01FF] = 0xBA // must have BREAK and UNUSED set
|
||||
memory[0x0000] = 0x28 // PLP
|
||||
mpu.regSP = 0xFE
|
||||
mpu.step()
|
||||
assertEquals(0x0001, mpu.regPC)
|
||||
assertEquals(0xBA, mpu.regP.asInt())
|
||||
assertEquals(0xAA, mpu.regP.asInt()) // BREAK cleared
|
||||
assertEquals(0xFF, mpu.regSP)
|
||||
}
|
||||
|
||||
@ -4166,8 +4167,7 @@ abstract class TestCommon6502 {
|
||||
fun test_rol_accumulator_zero_and_carry_zero_sets_z_flag() {
|
||||
mpu.regA = 0x00
|
||||
mpu.regP.C = false
|
||||
// $0000 ROL A
|
||||
memory[0x0000] = 0x2A
|
||||
memory[0x0000] = 0x2A // ROL A
|
||||
mpu.step()
|
||||
assertEquals(0x0001, mpu.regPC)
|
||||
assertEquals(0x00, mpu.regA)
|
||||
@ -4847,19 +4847,19 @@ abstract class TestCommon6502 {
|
||||
mpu.regSP = 0xFC
|
||||
mpu.step()
|
||||
assertEquals(0xFF, mpu.regSP)
|
||||
assertEquals(0xFC, mpu.regP.asInt())
|
||||
assertEquals(0xEC, mpu.regP.asInt()) // BREAK flag cleared
|
||||
assertEquals(0xC003, mpu.regPC)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled("this test is invalid")
|
||||
fun test_rti_forces_break_and_unused_flags_high() {
|
||||
// $0000 RTI
|
||||
memory[0x0000] = 0x40
|
||||
assertEquals(0b00100000, mpu.regP.asInt())
|
||||
memory[0x0000] = 0x40 // RTI
|
||||
writeMem(memory, 0x01FD, listOf(0x00, 0x03, 0xC0)) // Status, PCL, PCH
|
||||
mpu.regSP = 0xFC
|
||||
mpu.step()
|
||||
assertTrue(mpu.regP.B)
|
||||
// assertEquals(fUNUSED, mpu.Status.asByte().toInt() and fUNUSED)
|
||||
assertEquals(0b00110000, mpu.regP.asInt())
|
||||
}
|
||||
|
||||
// RTS
|
||||
|
Loading…
x
Reference in New Issue
Block a user