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