From cb355a17cd8f8a0e04dc7b5d9d5957587f158ba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Izaguirre?= Date: Sat, 9 Mar 2024 20:09:12 +0100 Subject: [PATCH] Improve the option to panic on undefined softswitches --- README.md | 2 +- cardBuilder.go | 8 ++++++-- doc/usage.txt | 2 +- ioC0Page.go | 49 +++++++++++++++++++++++++++++++------------------ traceBuilder.go | 4 ++-- 5 files changed, 41 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index eeffbb5..b606c84 100644 --- a/README.md +++ b/README.md @@ -257,7 +257,7 @@ The available tracers are: mli: Trace ProDOS MLI calls mos: Trace MOS calls with Applecorn skipping terminal IO mosfull: Trace MOS calls with Applecorn - panicSS: Panic on unimplemented softswitches + panicss: Panic on unimplemented softswitches ss: Trace sotfswiches calls ssreg: Trace sotfswiches registrations ucsd: Trace UCSD system calls diff --git a/cardBuilder.go b/cardBuilder.go index dc07c35..b50b000 100644 --- a/cardBuilder.go +++ b/cardBuilder.go @@ -28,6 +28,7 @@ const noCardName = "empty" var commonParams = []paramSpec{ {"trace", "Enable debug messages", "false"}, {"tracess", "Trace softswitches", "false"}, + {"panicss", "Panic on unimplemented softswitches", "false"}, } var cardFactory map[string]*cardBuilder @@ -118,11 +119,14 @@ func setupCard(a *Apple2, slot int, paramString string) (Card, error) { } // Common parameters - traceSS := paramsGetBool(finalParams, "tracess") - if traceSS { + if paramsGetBool(finalParams, "tracess") { a.io.traceSlot(slot) } + if paramsGetBool(finalParams, "panicss") { + a.io.panicNotImplementedSlot(slot) + } + debug := paramsGetBool(finalParams, "trace") card.setName(builder.name) diff --git a/doc/usage.txt b/doc/usage.txt index 8445192..da94663 100644 --- a/doc/usage.txt +++ b/doc/usage.txt @@ -82,7 +82,7 @@ The available tracers are: mli: Trace ProDOS MLI calls mos: Trace MOS calls with Applecorn skipping terminal IO mosfull: Trace MOS calls with Applecorn - panicSS: Panic on unimplemented softswitches + panicss: Panic on unimplemented softswitches ss: Trace sotfswiches calls ssreg: Trace sotfswiches registrations ucsd: Trace UCSD system calls diff --git a/ioC0Page.go b/ioC0Page.go index 0b56e31..839cb00 100644 --- a/ioC0Page.go +++ b/ioC0Page.go @@ -5,20 +5,20 @@ import ( ) type ioC0Page struct { - softSwitchesR [256]softSwitchR - softSwitchesW [256]softSwitchW - softSwitchesRName [256]string - softSwitchesWName [256]string - softSwitchesData [128]uint8 - keyboard KeyboardProvider - speaker SpeakerProvider - paddlesStrobeCycle uint64 - joysticks JoysticksProvider - mouse MouseProvider - apple2 *Apple2 - traceMask uint16 // A bit for each 16 softswitches - traceRegistrations bool - panicNotImplemented bool + softSwitchesR [256]softSwitchR + softSwitchesW [256]softSwitchW + softSwitchesRName [256]string + softSwitchesWName [256]string + softSwitchesData [128]uint8 + keyboard KeyboardProvider + speaker SpeakerProvider + paddlesStrobeCycle uint64 + joysticks JoysticksProvider + mouse MouseProvider + apple2 *Apple2 + traceMask uint16 // A bit for each 16 softswitches + panicMask uint16 // A bit for each 16 softswitches + traceRegistrations bool } type softSwitchR func() uint8 @@ -65,7 +65,10 @@ func (p *ioC0Page) setTrace(trace bool) { func (p *ioC0Page) traceSlot(slot int) { p.traceMask |= 1 << (8 + slot) - fmt.Printf("Slot %v traced %04x\n", slot, p.traceMask) +} + +func (p *ioC0Page) panicNotImplementedSlot(slot int) { + p.panicMask |= 1 << (8 + slot) } func (p *ioC0Page) setTraceRegistrations(traceRegistrations bool) { @@ -73,7 +76,11 @@ func (p *ioC0Page) setTraceRegistrations(traceRegistrations bool) { } func (p *ioC0Page) setPanicNotImplemented(value bool) { - p.panicNotImplemented = value + if value { + p.panicMask = 0xffff + } else { + p.panicMask = 0x0000 + } } func (p *ioC0Page) addSoftSwitchRW(address uint8, ss softSwitchR, name string) { @@ -125,6 +132,12 @@ func (p *ioC0Page) isTraced(address uint16) bool { (p.traceMask&(1<<(ss>>4))) != 0 } +func (p *ioC0Page) isPanicNotImplemented(address uint16) bool { + ss := address & 0xff + return ss != 0xc068 && // Ignore known IIGS softswitch + (p.panicMask&(1<<(ss>>4))) != 0 +} + func (p *ioC0Page) peek(address uint16) uint8 { pageAddress := uint8(address) ss := p.softSwitchesR[pageAddress] @@ -132,7 +145,7 @@ func (p *ioC0Page) peek(address uint16) uint8 { if p.isTraced(address) { fmt.Printf("Unknown softswitch on read to $%04x\n", address) } - if p.panicNotImplemented { + if p.isPanicNotImplemented(address) { panic(fmt.Sprintf("Unknown softswitch on read to $%04x", address)) } return 0 @@ -152,7 +165,7 @@ func (p *ioC0Page) poke(address uint16, value uint8) { if p.isTraced(address) { fmt.Printf("Unknown softswitch on write $%02x to $%04x\n", value, address) } - if p.panicNotImplemented { + if p.isPanicNotImplemented(address) { panic(fmt.Sprintf("Unknown softswitch on write to $%04x", address)) } return diff --git a/traceBuilder.go b/traceBuilder.go index 5286b97..e3934ff 100644 --- a/traceBuilder.go +++ b/traceBuilder.go @@ -64,8 +64,8 @@ func getTracerFactory() map[string]*traceBuilder { description: "Trace sotfswiches registrations", connectFunc: func(a *Apple2) { a.io.setTraceRegistrations(true) }, } - tracerFactory["panicSS"] = &traceBuilder{ - name: "panicSS", + tracerFactory["panicss"] = &traceBuilder{ + name: "panicss", description: "Panic on unimplemented softswitches", connectFunc: func(a *Apple2) { a.io.setPanicNotImplemented(true) }, }