diff --git a/core6502/execute.go b/core6502/execute.go index cef1c12..d55f7f7 100644 --- a/core6502/execute.go +++ b/core6502/execute.go @@ -17,12 +17,15 @@ const ( // State represents the state of the simulated device type State struct { - reg registers - mem Memory - cycles uint64 - opcodes *[256]opcode - trace bool - lineCache []uint8 + opcodes *[256]opcode + trace bool + + reg registers + mem Memory + cycles uint64 + + extraCycle bool + lineCache []uint8 // We cache the allocation of a line to avoid a malloc per instruction. To be used only // by ExecuteInstruction(). 2x speedup on the emulation!! } @@ -76,6 +79,10 @@ func (s *State) ExecuteInstruction() { } opcode.action(s, s.lineCache, opcode) s.cycles += uint64(opcode.cycles) + if s.extraCycle { + s.cycles++ + s.extraCycle = false + } if s.trace { fmt.Printf("%v, [%02x]\n", s.reg, s.lineCache[0:opcode.bytes]) } diff --git a/core6502/operations.go b/core6502/operations.go index 0c8f5d9..405de53 100644 --- a/core6502/operations.go +++ b/core6502/operations.go @@ -76,6 +76,7 @@ func buildOpUpdateFlag(flag uint8, value bool) opFunc { func buildOpBranch(flag uint8, test bool) opFunc { return func(s *State, line []uint8, opcode opcode) { if s.reg.getFlag(flag) == test { + s.extraCycle = true address := resolveAddress(s, line, opcode) s.reg.setPC(address) } diff --git a/storage/disketteWoz.go b/storage/disketteWoz.go index 51d8b29..fceb051 100644 --- a/storage/disketteWoz.go +++ b/storage/disketteWoz.go @@ -18,7 +18,7 @@ Emulation status for the disk used on the reference: - *** Commando: Not working - Planetfall: Working - Rescue Raiders: Working - - *** Sammy Lightfoot: Not working + - Sammy Lightfoot: Working (failed if no 6502 extra cycle is added on branches done) - Stargate: Working - Cross track sync - *** Blazing Paddles: Not working