From c7f643623d9f99436335e92733bd72db69b6494c Mon Sep 17 00:00:00 2001 From: Ivan Izaguirre Date: Sun, 6 Dec 2020 17:16:57 +0100 Subject: [PATCH] Extra cycle when brancing on conditional jumps. Fixes Sammy Lighfoot woz loadind. --- core6502/execute.go | 19 +++++++++++++------ core6502/operations.go | 1 + storage/disketteWoz.go | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) 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