mirror of
https://github.com/romychs/Ocean-240.2-Emulator.git
synced 2026-04-21 11:03:21 +03:00
Fix reset and hard reset
This commit is contained in:
parent
16dcc40401
commit
0d3b26e116
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,5 +2,6 @@
|
||||
*.lst
|
||||
*.tmp
|
||||
*.sh
|
||||
*.log
|
||||
.idea/
|
||||
src/.idea/
|
||||
Binary file not shown.
@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"maps"
|
||||
"net"
|
||||
"okemu/config"
|
||||
"okemu/debug"
|
||||
@ -12,6 +13,7 @@ import (
|
||||
"okemu/okean240"
|
||||
"os"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -74,6 +76,7 @@ var commandHandlers = map[string]CommandHandler{
|
||||
"hexdump": {(*ZRCP).handleHexDump, "Dumps memory at address, showing hex and ascii"},
|
||||
"load-binary": {(*ZRCP).handleLoadBinary, "Load binary file \"file\" at address \"addr\" with length \"len\", on the current memory zone"},
|
||||
"quit": {(*ZRCP).handleEmptyHandler, "Closes connection"},
|
||||
"reset-cpu": {(*ZRCP).handleResetCPU, "Resets CPU"},
|
||||
"read-memory": {(*ZRCP).handleReadMemory, "Dumps memory at address"},
|
||||
"reset-tstates-partial": {(*ZRCP).handleResetTStatesPartial, "Resets the t-states partial counter"},
|
||||
"run": {(*ZRCP).handleRun, "Run cpu when on cpu step mode"},
|
||||
@ -336,6 +339,8 @@ func (p *ZRCP) handleCPUHistory() (string, error) {
|
||||
return p.stateResponse(history), nil
|
||||
}
|
||||
return "", errors.New("ERROR: index out of range")
|
||||
case "get-size":
|
||||
return strconv.Itoa(p.debugger.CpuHistorySize()), nil
|
||||
case "ignrephalt", "ignrepldxr":
|
||||
// ignore
|
||||
default:
|
||||
@ -637,6 +642,7 @@ func (p *ZRCP) handleSetBreakpointPassCount() (string, error) {
|
||||
|
||||
func (p *ZRCP) handleDisassemble() (string, error) {
|
||||
var addr uint16
|
||||
var size uint64
|
||||
if len(p.params) == 0 {
|
||||
addr = p.computer.CPUState().PC
|
||||
} else {
|
||||
@ -645,9 +651,17 @@ func (p *ZRCP) handleDisassemble() (string, error) {
|
||||
if e != nil {
|
||||
return "", fmt.Errorf("error, illegal address: %s", p.params[0])
|
||||
}
|
||||
if len(p.params) == 2 {
|
||||
size, e = parseUint64(p.params[1])
|
||||
if e != nil {
|
||||
return "", fmt.Errorf("error, illegal size: %s", p.params[1])
|
||||
}
|
||||
} else {
|
||||
size = 1
|
||||
}
|
||||
}
|
||||
res := p.disassembler.Disassm(addr)
|
||||
log.Trace(res)
|
||||
log.Tracef("DISASSM[0x%04X, %d]: %s", addr, size, res)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
@ -699,6 +713,11 @@ func (p *ZRCP) handleGetRegisters() (string, error) {
|
||||
}
|
||||
|
||||
func (p *ZRCP) handleHardResetCPU() (string, error) {
|
||||
p.computer.HardReset()
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (p *ZRCP) handleResetCPU() (string, error) {
|
||||
p.computer.Reset()
|
||||
return "", nil
|
||||
}
|
||||
@ -936,8 +955,10 @@ func (p *ZRCP) handleGetMemBreakpoints() (string, error) {
|
||||
func (p *ZRCP) handleHelp() (string, error) {
|
||||
var res strings.Builder
|
||||
res.WriteString("Available commands:\n")
|
||||
for k, v := range commandHandlers {
|
||||
res.WriteString(fmt.Sprintf("%-*s%s\n", 24, k, v.desc))
|
||||
commands := slices.Collect(maps.Keys(commandHandlers))
|
||||
slices.Sort(commands)
|
||||
for _, cmd := range commands {
|
||||
res.WriteString(fmt.Sprintf("%-*s%s\n", 24, cmd, commandHandlers[cmd].desc))
|
||||
}
|
||||
res.WriteString("\nTotal commands: " + strconv.Itoa(len(commandHandlers)) + "\n")
|
||||
return res.String(), nil
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
"okemu/config"
|
||||
"okemu/okean240"
|
||||
"okemu/okean240/fdc"
|
||||
"os"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/app"
|
||||
@ -93,7 +94,16 @@ func newOkdOpenDialog(drive byte, c *okean240.ComputerType, w fyne.Window, confi
|
||||
_ = reader.Close()
|
||||
}, w)
|
||||
fod.SetFileName(config.FDC[drive].FloppyFile)
|
||||
cwd, e := os.Getwd()
|
||||
if e == nil {
|
||||
uri, e := storage.ListerForURI(storage.NewFileURI(cwd))
|
||||
if e == nil {
|
||||
fod.SetLocation(uri)
|
||||
}
|
||||
}
|
||||
fod.SetTitleText(fmt.Sprintf("Load floppy %s: image", string(rune(int(drive+66)))))
|
||||
fod.SetFilter(storage.NewExtensionFileFilter(floppyDriveExt))
|
||||
fod.Resize(fyne.NewSize(580, 500))
|
||||
return fod
|
||||
}
|
||||
|
||||
|
||||
10
src/main.go
10
src/main.go
@ -40,8 +40,6 @@ const diffScale = 15.0
|
||||
////go:embed bin/jack.com
|
||||
//var ramBytes []byte
|
||||
|
||||
var needReset = false
|
||||
|
||||
func main() {
|
||||
fmt.Printf("Starting Ocean-240.2 emulator %s build at %s\n", Version, BuildTime)
|
||||
|
||||
@ -205,7 +203,7 @@ func cpuClock(computer *okean240.ComputerType, dezog debug.DEZOG) {
|
||||
|
||||
for {
|
||||
elapsed := hrtime.Since(timeStart)
|
||||
if int64(elapsed) >= cpuClkPeriod.Load() {
|
||||
if computer.FullSpeed() || int64(elapsed) >= cpuClkPeriod.Load() {
|
||||
timeStart = hrtime.Now()
|
||||
bp = 0
|
||||
bpType = 0
|
||||
@ -215,6 +213,7 @@ func cpuClock(computer *okean240.ComputerType, dezog debug.DEZOG) {
|
||||
if computer.FullSpeed() {
|
||||
// Max frequency
|
||||
_, bp, bpType = computer.Do()
|
||||
nextTick = cpuTicks.Load()
|
||||
} else if cpuTicks.Load() >= nextTick {
|
||||
var t uint32
|
||||
t, bp, bpType = computer.Do()
|
||||
@ -226,9 +225,8 @@ func cpuClock(computer *okean240.ComputerType, dezog debug.DEZOG) {
|
||||
if bp > 0 || bpType != 0 {
|
||||
dezog.BreakpointHit(bp, bpType)
|
||||
}
|
||||
if needReset {
|
||||
computer.Reset()
|
||||
needReset = false
|
||||
if computer.PendingReset() {
|
||||
computer.HardReset()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ type ComputerType struct {
|
||||
config *config.OkEmuConfig
|
||||
kbAck atomic.Bool
|
||||
fullSpeed atomic.Bool
|
||||
pendingReset atomic.Bool
|
||||
pendingHardReset atomic.Bool
|
||||
}
|
||||
|
||||
type Snapshot struct {
|
||||
@ -110,10 +110,28 @@ func (c *ComputerType) MemWrite(addr uint16, val byte) {
|
||||
func NewComputer(cfg *config.OkEmuConfig, deb *debug.Debugger) *ComputerType {
|
||||
c := ComputerType{}
|
||||
c.config = cfg
|
||||
c.memory = Memory{}
|
||||
c.memory.Init(cfg.MonitorFile, cfg.CPMFile)
|
||||
|
||||
c.cpu = z80go.NewCPU(&c)
|
||||
c.debugger = deb
|
||||
|
||||
c.HardReset()
|
||||
|
||||
return &c
|
||||
}
|
||||
|
||||
// Reset Only CPU reset
|
||||
func (c *ComputerType) Reset() {
|
||||
// CPU
|
||||
c.cpu.Reset()
|
||||
c.cycles = 0
|
||||
c.tstatesPartial = 0
|
||||
}
|
||||
|
||||
// HardReset full computer reset
|
||||
func (c *ComputerType) HardReset() {
|
||||
c.cpu.Reset()
|
||||
|
||||
c.memory = Memory{}
|
||||
c.memory.Init(c.config.MonitorFile, c.config.CPMFile)
|
||||
|
||||
c.cycles = 0
|
||||
c.tstatesPartial = 0
|
||||
@ -126,24 +144,17 @@ func NewComputer(cfg *config.OkEmuConfig, deb *debug.Debugger) *ComputerType {
|
||||
|
||||
c.vShift = 0
|
||||
c.hShift = 0
|
||||
//c.aOffset = 0x100
|
||||
|
||||
c.pit = pit.New()
|
||||
c.kbAck.Store(false)
|
||||
c.usart = usart.New()
|
||||
c.pic = pic.NewI8259()
|
||||
c.fdc = fdc.NewFDC(cfg)
|
||||
c.cpuFrequency = DefaultCPUFrequency
|
||||
c.debugger = deb
|
||||
c.fullSpeed.Store(false)
|
||||
c.pendingReset.Store(false)
|
||||
return &c
|
||||
}
|
||||
c.fdc = fdc.NewFDC(c.config)
|
||||
|
||||
c.cpuFrequency = DefaultCPUFrequency
|
||||
c.fullSpeed.Store(false)
|
||||
c.pendingHardReset.Store(false)
|
||||
|
||||
func (c *ComputerType) Reset() {
|
||||
c.cpu.Reset()
|
||||
c.cycles = 0
|
||||
c.tstatesPartial = 0
|
||||
}
|
||||
|
||||
func (c *ComputerType) getContext() map[string]interface{} {
|
||||
@ -524,11 +535,11 @@ func (c *ComputerType) FullSpeed() bool {
|
||||
}
|
||||
|
||||
func (c *ComputerType) SetPendingReset(pending bool) {
|
||||
c.pendingReset.Store(pending)
|
||||
c.pendingHardReset.Store(pending)
|
||||
}
|
||||
|
||||
func (c *ComputerType) PendingReset() bool {
|
||||
return c.pendingReset.Load()
|
||||
return c.pendingHardReset.Load()
|
||||
}
|
||||
|
||||
func (c *ComputerType) LoadFloppyData(drive byte, reader fyne.URIReadCloser) error {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user