removed some staticcheck errors (golangci-lint -E staticcheck)

supercharger tap window will now set tape counter (revealed by
staticcheck)
This commit is contained in:
JetSetIlly 2020-10-16 14:50:23 +01:00
parent 7c1409d474
commit 7b624b5506
22 changed files with 82 additions and 31 deletions

View file

@ -2,7 +2,6 @@ linters:
disable: disable:
- errcheck - errcheck
- ineffassign - ineffassign
- staticcheck
enable: enable:
- bodyclose - bodyclose
- unconvert - unconvert

View file

@ -20,7 +20,7 @@ generate:
lint: lint:
# uses .golangci.yml configuration file # uses .golangci.yml configuration file
golangci-lint run golangci-lint run --sort-results
test: test:
go test -tags=testing ./... go test -tags=testing ./...

View file

@ -1038,7 +1038,8 @@ func (dbg *Debugger) processTokens(tokens *commandline.Tokens) (bool, error) {
return false, curated.Errorf("value required for %s %s", cmdDisplay, action) return false, curated.Errorf("value required for %s %s", cmdDisplay, action)
} }
scale, err := strconv.ParseFloat(scl, 32) var scale float64
scale, err = strconv.ParseFloat(scl, 32)
if err != nil { if err != nil {
return false, curated.Errorf("%s %s value not valid (%s)", cmdDisplay, action, scl) return false, curated.Errorf("%s %s value not valid (%s)", cmdDisplay, action, scl)
} }
@ -1100,7 +1101,7 @@ func (dbg *Debugger) processTokens(tokens *commandline.Tokens) (bool, error) {
return false, nil return false, nil
} }
option, ok := tokens.Get() option, _ := tokens.Get()
switch option { switch option {
case "NICK": case "NICK":

View file

@ -317,6 +317,9 @@ func TestParser_optional(t *testing.T) {
} }
cmds, err = commandline.ParseCommandTemplate(template) cmds, err = commandline.ParseCommandTemplate(template)
if err != nil {
t.Errorf("does not parse: %s", err)
}
f, err := os.Create("memviz.dot") f, err := os.Create("memviz.dot")
if err != nil { if err != nil {

View file

@ -269,6 +269,10 @@ func TestTabCompletion_nestedGroups(t *testing.T) {
cmds, err = commandline.ParseCommandTemplate([]string{ cmds, err = commandline.ParseCommandTemplate([]string{
"PREF ([SET|NO|TOGGLE] [RANDSTART|RANDPINS])", "PREF ([SET|NO|TOGGLE] [RANDSTART|RANDPINS])",
}) })
if err != nil {
t.Errorf("does not parse: %s", err)
}
tc = commandline.NewTabCompletion(cmds) tc = commandline.NewTabCompletion(cmds)
completion = "P" completion = "P"
expected = "PREF " expected = "PREF "

View file

@ -261,6 +261,9 @@ func TestValidation_singluarOption(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("%s", err) t.Fatalf("%s", err)
} }
if err != nil {
t.Errorf("does not parse: %s", err)
}
err = cmds.Validate("SCRIPT foo") err = cmds.Validate("SCRIPT foo")
if err != nil { if err != nil {
@ -501,6 +504,9 @@ func TestValidation_optional_group(t *testing.T) {
cmds, err = commandline.ParseCommandTemplate([]string{ cmds, err = commandline.ParseCommandTemplate([]string{
"PREF ([SET|NO|TOGGLE] [RANDSTART|RANDPINS])", "PREF ([SET|NO|TOGGLE] [RANDSTART|RANDPINS])",
}) })
if err != nil {
t.Errorf("does not parse: %s", err)
}
err = cmds.Validate("pref") err = cmds.Validate("pref")
if err != nil { if err != nil {

View file

@ -54,6 +54,10 @@ func newPreferences(dsm *Disassembly) (*Preferences, error) {
} }
p.dsk, err = prefs.NewDisk(pth) p.dsk, err = prefs.NewDisk(pth)
if err != nil {
return nil, err
}
p.dsk.Add("disassembly.fxxxMirror", &p.FxxxMirror) p.dsk.Add("disassembly.fxxxMirror", &p.FxxxMirror)
p.dsk.Add("disassembly.symbols", &p.Symbols) p.dsk.Add("disassembly.symbols", &p.Symbols)
@ -68,7 +72,7 @@ func newPreferences(dsm *Disassembly) (*Preferences, error) {
err = p.dsk.Load(true) err = p.dsk.Load(true)
if err != nil { if err != nil {
return p, err return nil, err
} }
return p, nil return p, nil

View file

@ -38,6 +38,9 @@ func (img *SdlImgui) initPrefs(group prefGroup) error {
return err return err
} }
img.prefs, err = prefs.NewDisk(pth) img.prefs, err = prefs.NewDisk(pth)
if err != nil {
return err
}
err = img.prefs.Add(fmt.Sprintf("%s.windowsize", group), prefs.NewGeneric( err = img.prefs.Add(fmt.Sprintf("%s.windowsize", group), prefs.NewGeneric(
func(s string) error { func(s string) error {

View file

@ -17,6 +17,7 @@ package sdlimgui
import ( import (
"fmt" "fmt"
"strconv"
"github.com/inkyblackness/imgui-go/v2" "github.com/inkyblackness/imgui-go/v2"
) )
@ -63,6 +64,12 @@ func (win *winCartTape) draw() {
imguiText("Counter") imguiText("Counter")
counter := fmt.Sprintf("%8d", win.img.lz.Cart.TapeState.Counter) counter := fmt.Sprintf("%8d", win.img.lz.Cart.TapeState.Counter)
if imguiDecimalInput("##counter", !win.img.paused, 8, &counter) { if imguiDecimalInput("##counter", !win.img.paused, 8, &counter) {
win.img.lz.Dbg.PushRawEvent(func() {
c, err := strconv.ParseInt(counter, 10, 64)
if err == nil {
win.img.lz.Cart.TapeBus.SetTapeCounter(int(c))
}
})
} }
imgui.SameLine() imgui.SameLine()
imgui.Text("/") imgui.Text("/")

View file

@ -134,11 +134,9 @@ func (win *winControl) drawQuantumToggle() {
if toggle { if toggle {
stepLabel = videoCycleLabel stepLabel = videoCycleLabel
if videoStep != toggle { if videoStep != toggle {
videoStep = toggle
win.img.term.pushCommand("QUANTUM VIDEO") win.img.term.pushCommand("QUANTUM VIDEO")
} }
} else if videoStep != toggle { } else if videoStep != toggle {
videoStep = toggle
win.img.term.pushCommand("QUANTUM CPU") win.img.term.pushCommand("QUANTUM CPU")
} }

View file

@ -219,7 +219,6 @@ func (win *winTerm) saveOutput() {
n.Year(), n.Month(), n.Day(), n.Hour(), n.Minute(), n.Second())) n.Year(), n.Month(), n.Day(), n.Hour(), n.Minute(), n.Second()))
f, err := os.Create(fn) f, err := os.Create(fn)
defer f.Close()
if err != nil { if err != nil {
win.output = append(win.output, terminalOutput{ win.output = append(win.output, terminalOutput{
style: terminal.StyleError, style: terminal.StyleError,
@ -228,6 +227,7 @@ func (win *winTerm) saveOutput() {
}) })
return return
} }
defer f.Close()
for _, o := range win.output { for _, o := range win.output {
f.Write([]byte(o.text)) f.Write([]byte(o.text))

View file

@ -302,10 +302,8 @@ func (mc *CPU) read8BitPC(f func(val uint8) error) error {
mc.LastResult.Error = err.Error() mc.LastResult.Error = err.Error()
} }
carry, _ := mc.PC.Add(1) // ignoring if program counter cycling
if carry { mc.PC.Add(1)
// program counter cycled
}
// bump the number of bytes read during instruction decode // bump the number of bytes read during instruction decode
mc.LastResult.ByteCount++ mc.LastResult.ByteCount++
@ -345,10 +343,8 @@ func (mc *CPU) read16BitPC() error {
mc.LastResult.Error = err.Error() mc.LastResult.Error = err.Error()
} }
carry, _ := mc.PC.Add(1) // ignoring if program counter cycling
if carry { mc.PC.Add(1)
// program counter cycled
}
// bump the number of bytes read during instruction decode // bump the number of bytes read during instruction decode
mc.LastResult.ByteCount++ mc.LastResult.ByteCount++
@ -370,10 +366,8 @@ func (mc *CPU) read16BitPC() error {
mc.LastResult.Error = err.Error() mc.LastResult.Error = err.Error()
} }
carry, _ = mc.PC.Add(1) // ignoring if program counter cycling
if carry { mc.PC.Add(1)
// program counter cycled
}
// bump the number of bytes read during instruction decode // bump the number of bytes read during instruction decode
mc.LastResult.ByteCount++ mc.LastResult.ByteCount++

View file

@ -42,21 +42,21 @@ func TestDecimalModeCarry(t *testing.T) {
// subtraction with carry (subtract value) // subtraction with carry (subtract value)
r8.Load(9) r8.Load(9)
rtest.EquateRegisters(t, r8, 0x09) rtest.EquateRegisters(t, r8, 0x09)
rcarry, _, _, _ = r8.SubtractDecimal(1, true) r8.SubtractDecimal(1, true)
rtest.EquateRegisters(t, r8, 0x08) rtest.EquateRegisters(t, r8, 0x08)
// subtraction without carry (subtract value and another 1) // subtraction without carry (subtract value and another 1)
rcarry, _, _, _ = r8.SubtractDecimal(1, false) r8.SubtractDecimal(1, false)
rtest.EquateRegisters(t, r8, 0x06) rtest.EquateRegisters(t, r8, 0x06)
// addition on tens boundary // addition on tens boundary
r8.Load(9) r8.Load(9)
rtest.EquateRegisters(t, r8, 0x09) rtest.EquateRegisters(t, r8, 0x09)
rcarry, _, _, _ = r8.AddDecimal(1, false) r8.AddDecimal(1, false)
rtest.EquateRegisters(t, r8, 0x10) rtest.EquateRegisters(t, r8, 0x10)
// subtraction on tens boundary // subtraction on tens boundary
rcarry, _, _, _ = r8.SubtractDecimal(1, true) r8.SubtractDecimal(1, true)
rtest.EquateRegisters(t, r8, 0x09) rtest.EquateRegisters(t, r8, 0x09)
// addition on hundreds boundary // addition on hundreds boundary
@ -67,7 +67,7 @@ func TestDecimalModeCarry(t *testing.T) {
test.Equate(t, rcarry, true) test.Equate(t, rcarry, true)
// subtraction on hundreds boundary // subtraction on hundreds boundary
rcarry, _, _, _ = r8.SubtractDecimal(1, true) r8.SubtractDecimal(1, true)
rtest.EquateRegisters(t, r8, 0x99) rtest.EquateRegisters(t, r8, 0x99)
} }

View file

@ -173,6 +173,9 @@ type CartTapeBus interface {
// effective // effective
Rewind() bool Rewind() bool
// Set tape counter to specified value
SetTapeCounter(c int)
// GetTapeState retrieves a copy of the current state of the tape. returns // GetTapeState retrieves a copy of the current state of the tape. returns
// true is state is valid // true is state is valid
GetTapeState() (bool, CartTapeState) GetTapeState() (bool, CartTapeState)

View file

@ -51,6 +51,10 @@ func newPreferences() (*Preferences, error) {
} }
p.dsk, err = prefs.NewDisk(pth) p.dsk, err = prefs.NewDisk(pth)
if err != nil {
return nil, err
}
p.dsk.Add("plusrom.nick", &p.Nick) p.dsk.Add("plusrom.nick", &p.Nick)
p.dsk.Add("plusrom.id", &p.ID) p.dsk.Add("plusrom.id", &p.ID)

View file

@ -152,7 +152,7 @@ func (cart *Supercharger) PutRegister(register string, data string) {
case "delay": case "delay":
v, _ := strconv.ParseUint(data, 16, 8) v, _ := strconv.ParseUint(data, 16, 8)
if v < 0 || v > 6 { if v > 6 {
panic("delay value out of range") panic("delay value out of range")
} }
cart.registers.Delay = int(v) cart.registers.Delay = int(v)
@ -178,7 +178,7 @@ func (cart *Supercharger) PutRegister(register string, data string) {
case "bankingmode": case "bankingmode":
v, _ := strconv.ParseUint(data, 16, 8) v, _ := strconv.ParseUint(data, 16, 8)
if v < 0 || v > 7 { if v > 7 {
panic("bankingmode value out of range") panic("bankingmode value out of range")
} }
cart.registers.BankingMode = int(v) cart.registers.BankingMode = int(v)

View file

@ -149,6 +149,14 @@ func (tap *SoundLoad) Rewind() bool {
return true return true
} }
// SetTapeCounter implements the mapper.CartTapeBus interface
func (tap *SoundLoad) SetTapeCounter(c int) {
if c >= len(tap.samples) {
c = len(tap.samples)
}
tap.idx = c
}
// the number of samples to copy and return from GetTapeState() // the number of samples to copy and return from GetTapeState()
const numStateSamples = 100 const numStateSamples = 100

View file

@ -393,6 +393,16 @@ func (cart *Supercharger) Rewind() bool {
return false return false
} }
// SetTapeCounter implements the mapper.CartTapeBus interface
//
// Whether this does anything meaningful depends on the interal implementation
// of the 'tape' interface.
func (cart *Supercharger) SetTapeCounter(c int) {
if tape, ok := cart.tape.(mapper.CartTapeBus); ok {
tape.SetTapeCounter(c)
}
}
// GetTapeState implements the mapper.CartTapeBus interface // GetTapeState implements the mapper.CartTapeBus interface
// //
// Whether this does anything meaningful depends on the interal implementation // Whether this does anything meaningful depends on the interal implementation

View file

@ -481,7 +481,7 @@ func (tia *TIA) Step(readMemory bool) (bool, error) {
readMemory = tia.Video.UpdateSpritePixels(memoryData) readMemory = tia.Video.UpdateSpritePixels(memoryData)
} }
if readMemory { if readMemory {
readMemory = tia.Audio.UpdateRegisters(memoryData) _ = tia.Audio.UpdateRegisters(memoryData)
} }
// copy audio to television signal // copy audio to television signal

View file

@ -43,6 +43,10 @@ func newPreferences() (*Preferences, error) {
} }
p.dsk, err = prefs.NewDisk(pth) p.dsk, err = prefs.NewDisk(pth)
if err != nil {
return p, curated.Errorf("hiscore: %v", err)
}
p.dsk.Add("hiscore.server", &p.Server) p.dsk.Add("hiscore.server", &p.Server)
p.dsk.Add("hiscore.authtoken", &p.AuthToken) p.dsk.Add("hiscore.authtoken", &p.AuthToken)

View file

@ -57,10 +57,13 @@ func CartridgeMemory(mem *cartridge.Cartridge, patchFile string) (bool, error) {
// make sure we're at the beginning of the file // make sure we're at the beginning of the file
if _, err = f.Seek(0, io.SeekStart); err != nil { if _, err = f.Seek(0, io.SeekStart); err != nil {
return false, err return false, curated.Errorf("patch: %v", err)
} }
buffer, err := ioutil.ReadAll(f) buffer, err := ioutil.ReadAll(f)
if err != nil {
return false, curated.Errorf("patch: %v", err)
}
// once a patch has been made then we'll flip patched to true and return it // once a patch has been made then we'll flip patched to true and return it
// to the calling function // to the calling function

View file

@ -126,7 +126,7 @@ func (dsk *Disk) Save() error {
var n int var n int
// add warning label // add warning label
n, err = fmt.Fprintf(f, fmt.Sprintf("%s\n", WarningBoilerPlate)) n, err = fmt.Fprintf(f, "%s\n", WarningBoilerPlate)
if err != nil { if err != nil {
return curated.Errorf("prefs: %v", err) return curated.Errorf("prefs: %v", err)
} }
@ -135,7 +135,7 @@ func (dsk *Disk) Save() error {
} }
// write entries (combination of old and live entries) to disk // write entries (combination of old and live entries) to disk
n, err = fmt.Fprintf(f, entries.String()) n, err = fmt.Fprint(f, entries.String())
if err != nil { if err != nil {
return curated.Errorf("prefs: %v", err) return curated.Errorf("prefs: %v", err)
} }