diff --git a/internal/vm/disp.go b/internal/vm/disp.go index b62b361..1c6d0c9 100644 --- a/internal/vm/disp.go +++ b/internal/vm/disp.go @@ -161,12 +161,11 @@ func (driver *DisplayDriver) Init(vm *LC3, addrs []Word) { // Read gets the status of the display device. Reading any other address returns an error. func (driver *DisplayDriver) Read(addr Word) (Word, error) { - switch addr { //golint:exhaustive - case driver.statusAddr: + if addr == driver.statusAddr { return Word(driver.handle.device.DSR()), nil - case driver.dataAddr: + } else if addr == driver.dataAddr { return Word(driver.handle.device.Read()), nil - default: + } else { return Word(0xdea1), fmt.Errorf("read: %w: %s:%s", ErrNoDevice, addr, driver) } } @@ -180,14 +179,13 @@ func (driver *DisplayDriver) InterruptRequested() bool { // Write sets the data register of the display device. Writing any other address returns an error. func (driver *DisplayDriver) Write(addr Word, value Register) error { - switch addr { - case driver.dataAddr: + if addr == driver.dataAddr { driver.handle.device.Write(value) return nil - case driver.statusAddr: + } else if addr == driver.statusAddr { driver.handle.device.SetDSR(value) return nil - default: + } else { return fmt.Errorf("write: %w: %s:%s", ErrNoDevice, addr, driver) } } diff --git a/internal/vm/io.go b/internal/vm/io.go index 58ceaeb..3fe901a 100644 --- a/internal/vm/io.go +++ b/internal/vm/io.go @@ -141,6 +141,7 @@ func (mmio MMIO) PSR() ProcessorStatus { // DDR returns the value of the display data register, if it has been mapped. func (mmio MMIO) DDR() rune { ddr := rune('⍝') + if dev := mmio.devs[DDRAddr]; dev != nil { val := dev.(*DisplayDriver) ddr = rune(val.handle.device.ddr) @@ -152,6 +153,7 @@ func (mmio MMIO) DDR() rune { // DDR returns the value of the display status register, if it has been mapped. func (mmio MMIO) DSR() Word { dsr := Word('⍝') + if dev := mmio.devs[DSRAddr]; dev != nil { val := dev.(*DisplayDriver) dsr = Word(val.handle.device.dsr) @@ -163,6 +165,7 @@ func (mmio MMIO) DSR() Word { // KBDR returns the value of the keyboard data register, if it has been mapped. func (mmio MMIO) KBDR() Word { kbdr := Word('⍝') + if dev := mmio.devs[KBDRAddr]; dev != nil { val := dev.(*Keyboard) kbdr = Word(val.KBDR) @@ -174,6 +177,7 @@ func (mmio MMIO) KBDR() Word { // KBSR returns the value of the keyboard status register, if it has been mapped. func (mmio MMIO) KBSR() Word { kbsr := Word('⍝') + if dev := mmio.devs[KBSRAddr]; dev != nil { val := dev.(*Keyboard) kbsr = Word(val.KBSR)