mirror of
https://github.com/zellyn/go6502.git
synced 2024-06-28 15:29:51 +00:00
Add Print(boo) to Cpu type to turn on tracing.
This commit is contained in:
parent
986acf6917
commit
d9fa2336d3
20
cpu/cpu.go
20
cpu/cpu.go
|
@ -8,6 +8,8 @@ package cpu
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/zellyn/go6502/asm"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Chip versions.
|
// Chip versions.
|
||||||
|
@ -30,6 +32,7 @@ type Cpu interface {
|
||||||
P() byte // [NV-BDIZC]
|
P() byte // [NV-BDIZC]
|
||||||
SP() byte
|
SP() byte
|
||||||
// BUG(zellyn): Add signaling of interrupts.
|
// BUG(zellyn): Add signaling of interrupts.
|
||||||
|
Print(bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Memory interface, for all memory access.
|
// Memory interface, for all memory access.
|
||||||
|
@ -79,12 +82,13 @@ type cpu struct {
|
||||||
r registers
|
r registers
|
||||||
oldPC uint16
|
oldPC uint16
|
||||||
version CpuVersion
|
version CpuVersion
|
||||||
|
print bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create and return a new Cpu object with the given memory, ticker, and of the given version.
|
// Create and return a new Cpu object with the given memory, ticker, and of the given version.
|
||||||
func NewCPU(memory Memory, ticker Ticker, version CpuVersion) Cpu {
|
func NewCPU(memory Memory, ticker Ticker, version CpuVersion) Cpu {
|
||||||
c := cpu{m: memory, t: ticker, version: version}
|
c := cpu{m: memory, t: ticker, version: version}
|
||||||
c.r.P |= FLAG_UNUSED // Set unused flag to 1
|
c.r.P |= FLAG_UNUSED | FLAG_B // Set unused flag to 1
|
||||||
return &c
|
return &c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,8 +131,18 @@ func (c *cpu) Reset() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// status prints out the current CPU instruction and register status.
|
||||||
|
func status(c *cpu, m Memory) string {
|
||||||
|
bytes, text, _ := asm.Disasm(c.PC(), m.Read(c.PC()), m.Read(c.PC()+1), m.Read(c.PC()+2))
|
||||||
|
return fmt.Sprintf("$%04X: %s %s A=$%02X X=$%02X Y=$%02X SP=$%02X P=$%08b",
|
||||||
|
c.PC(), bytes, text, c.A(), c.X(), c.Y(), c.SP(), c.P())
|
||||||
|
}
|
||||||
|
|
||||||
// Step takes a single step (which will last several cycles, calling Tick() on the Ticker for each).
|
// Step takes a single step (which will last several cycles, calling Tick() on the Ticker for each).
|
||||||
func (c *cpu) Step() error {
|
func (c *cpu) Step() error {
|
||||||
|
if c.print {
|
||||||
|
fmt.Println(status(c, c.m))
|
||||||
|
}
|
||||||
c.oldPC = c.r.PC
|
c.oldPC = c.r.PC
|
||||||
i := c.m.Read(c.r.PC)
|
i := c.m.Read(c.r.PC)
|
||||||
c.r.PC++
|
c.r.PC++
|
||||||
|
@ -146,3 +160,7 @@ func (c *cpu) Step() error {
|
||||||
func (c *cpu) SetPC(address uint16) {
|
func (c *cpu) SetPC(address uint16) {
|
||||||
c.r.PC = address
|
c.r.PC = address
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *cpu) Print(print bool) {
|
||||||
|
c.print = print
|
||||||
|
}
|
||||||
|
|
|
@ -394,3 +394,7 @@ func (c *cpu) setupNodesAndTransistors() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *cpu) Print(bool) {
|
||||||
|
panic("not implemented")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user