1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-06-25 19:29:49 +00:00

Detect stack overflow during Z80 tests

This commit is contained in:
Karol Stasiak 2019-07-31 22:29:50 +02:00
parent 96b020ce62
commit 0f9bb4fb56

View File

@ -162,14 +162,18 @@ class EmuZ80Run(cpu: millfork.Cpu.Value, nodeOptimizations: List[NodeOptimizatio
}
val memoryBank = assembler.mem.banks("default")
(0x1f0 until 0x200).foreach(i => memoryBank.readable(i) = true)
(0x1ed until 0x200).foreach(i => memoryBank.readable(i) = true)
(0xff00 to 0xffff).foreach{i =>
memoryBank.readable(i) = true
memoryBank.writeable(i) = true
}
// LD SP,$fffe
// CALL $0200
// HALT
memoryBank.output(0x1ed) = 0x31.toByte
memoryBank.output(0x1ee) = 0xFE.toByte
memoryBank.output(0x1ef) = 0xFF.toByte
memoryBank.output(0x1f0) = 0xCD.toByte
memoryBank.output(0x1f1) = 0
memoryBank.output(0x1f2) = 2
@ -187,13 +191,16 @@ class EmuZ80Run(cpu: millfork.Cpu.Value, nodeOptimizations: List[NodeOptimizatio
case millfork.Cpu.Z80 | millfork.Cpu.Intel8080 =>
val cpu = new Z80Core(Z80Memory(memoryBank), DummyIO)
cpu.reset()
cpu.setProgramCounter(0x1f0)
cpu.setProgramCounter(0x1ed)
cpu.resetTStates()
while (!cpu.getHalt) {
cpu.executeOneInstruction()
if (resetN) {
resetNMethod.invoke(cpu)
}
if (cpu.getSP.&(0xffff) < 0xd002) {
throw new IllegalStateException("stack overflow")
}
// dump(cpu)
cpu.getTStates should be < TooManyCycles
}
@ -202,7 +209,7 @@ class EmuZ80Run(cpu: millfork.Cpu.Value, nodeOptimizations: List[NodeOptimizatio
case millfork.Cpu.Sharp =>
var ticks = 0L
val cpu = GameboyStubs(memoryBank).cpu
cpu.getRegisters.setPC(0x1f0)
cpu.getRegisters.setPC(0x1ed)
while (cpu.getState != Cpu.State.HALTED) {
cpu.tick()
// dump(cpu)