diff --git a/tridoraemu/cpu.go b/tridoraemu/cpu.go index c0c7739..9d6b08d 100644 --- a/tridoraemu/cpu.go +++ b/tridoraemu/cpu.go @@ -125,7 +125,7 @@ func (c *CPU) step() error { Y := c.estack[c.ESP] - insWord, err := c.mem.read(c.PC) + insWord, err := c.mem.readIns(c.PC) if err != nil { return err } if c.PC % 4 == 0 { insWord = insWord >> 16 diff --git a/tridoraemu/mem.go b/tridoraemu/mem.go index 4765c8b..624c7bd 100644 --- a/tridoraemu/mem.go +++ b/tridoraemu/mem.go @@ -17,6 +17,12 @@ const IOSlotSize = 128 const IOSlotCount = 16 +const DRAMStart = 65536 + +const CacheAddrShift = 8 + +const CacheWriteThrough = true + type Mem struct { ram [] word iohandler [IOSlotCount] IOHandler @@ -79,7 +85,7 @@ func (m *Mem) attachIO(h IOHandler, slot int) { m.iohandler[slot] = h } -func (m *Mem) read(byteaddr word) (word, error) { +func (m *Mem) readRaw(byteaddr word) (word, error) { if byteaddr >= IOStartAddr && byteaddr < RAMStartAddr { ioslot := (byteaddr - IOStartAddr) / IOSlotSize if m.iohandler[ioslot] != nil { @@ -96,6 +102,14 @@ func (m *Mem) read(byteaddr word) (word, error) { } } +func (m *Mem) read(byteaddr word) (word, error) { + return m.readRaw(byteaddr); +} + +func (m *Mem) readIns(byteaddr word) (word, error) { + return m.readRaw(byteaddr); +} + func (m *Mem) write(value word, byteaddr word) error { if byteaddr < IOStartAddr { return fmt.Errorf("Write to ROM area at %08X value %08X", byteaddr, value) diff --git a/tridoraemu/tridoraemu.go b/tridoraemu/tridoraemu.go index 88804b4..c148515 100644 --- a/tridoraemu/tridoraemu.go +++ b/tridoraemu/tridoraemu.go @@ -8,7 +8,8 @@ import ( "flag" "time" "github.com/hajimehoshi/ebiten/v2" - // "github.com/hajimehoshi/ebiten/v2/ebitenutil" + "github.com/hajimehoshi/ebiten/v2/ebitenutil" + "github.com/hajimehoshi/ebiten/v2/inpututil" // "image/color" ) @@ -35,6 +36,7 @@ func idle(canGoIdle bool) { } type Game struct{ + debug bool x,y int stepsPerFrame int lastFrameDuration time.Duration @@ -58,16 +60,23 @@ func (g *Game) Update() error { } g.lastFrameDuration = time.Since(startTime) + if inpututil.IsKeyJustReleased(ebiten.KeyF12) { + g.debug = !g.debug + } + return nil } func (g *Game) Draw(screen *ebiten.Image) { screen.DrawImage(framebuffer.framebuffer, nil) - /* - buf := fmt.Sprintf("PC: %08X FP: %08X RP: %08X ESP: %2X\n%v", cpu.PC, cpu.FP, cpu.RP, cpu.ESP, g.lastFrameDuration) - ebitenutil.DebugPrint(screen, buf) + if g.debug { + buf := fmt.Sprintf("PC: %08X FP: %08X RP: %08X ESP: %2X %v", + cpu.PC, cpu.FP, cpu.RP, cpu.ESP, g.lastFrameDuration) + ebitenutil.DebugPrint(screen, buf) + } + /* screen.Set(g.x, g.y, color.RGBA{255,0,0,0}) screen.Set(g.x, g.y+1, color.RGBA{0,255,0,0}) screen.Set(g.x, g.y+2, color.RGBA{0,255,255,0})