From 2322f3aa527c9e0f81335790bd22354be7a21e8a Mon Sep 17 00:00:00 2001 From: Alessandro Abbruzzetti Date: Fri, 2 Feb 2018 23:42:16 +0100 Subject: [PATCH] Some refactoring Added drive type choice on 128 --- Kernal64/build/build.xml | 2 +- Kernal64/src/ucesoft/cbm/c128/C128.scala | 156 +++++++++++------- Kernal64/src/ucesoft/cbm/c64/C64.scala | 103 ++++++------ .../ucesoft/cbm/misc/FloppyComponent.scala | 34 ++-- .../ucesoft/cbm/peripheral/bus/IECBus.scala | 3 +- .../ucesoft/cbm/peripheral/drive/C1541.scala | 3 +- .../cbm/peripheral/drive/C1541Emu.scala | 1 + .../ucesoft/cbm/peripheral/drive/C1571.scala | 11 +- .../ucesoft/cbm/peripheral/drive/Drive.scala | 10 ++ .../ucesoft/cbm/peripheral/drive/Floppy.scala | 2 + .../cbm/peripheral/drive/FlyerIEC.scala | 1 + .../cbm/peripheral/drive/LocalDrive.scala | 1 + .../peripheral/drive/RWHeadController.scala | 2 +- .../cbm/peripheral/drive/VIADiskControl.scala | 2 +- .../src/ucesoft/cbm/trace/InspectPanel.scala | 36 ++-- .../src/ucesoft/cbm/trace/TraceDialog.scala | 2 +- 16 files changed, 204 insertions(+), 165 deletions(-) diff --git a/Kernal64/build/build.xml b/Kernal64/build/build.xml index 9b7712e7..86b96074 100644 --- a/Kernal64/build/build.xml +++ b/Kernal64/build/build.xml @@ -7,7 +7,7 @@ - + diff --git a/Kernal64/src/ucesoft/cbm/c128/C128.scala b/Kernal64/src/ucesoft/cbm/c128/C128.scala index 8e96c9eb..298e853e 100644 --- a/Kernal64/src/ucesoft/cbm/c128/C128.scala +++ b/Kernal64/src/ucesoft/cbm/c128/C128.scala @@ -119,20 +119,16 @@ class C128 extends CBMComponent with ActionListener with GamePlayer with MMUChan // -------------------- TRACE ---------------- private[this] var traceDialog : TraceDialog = _ private[this] var diskTraceDialog : TraceDialog = _ - private[this] var inspectDialog : JDialog = _ + private[this] var inspectDialog : InspectPanelDialog = _ private[this] var traceItem,traceDiskItem : JCheckBoxMenuItem = _ // -------------------- DISK ----------------- private[this] var isDiskActive = true private[this] var isDiskActive9 = false - private[this] var attachedDisks : Array[Option[Diskette]] = Array(None,None) private[this] val driveLeds = Array(new DriveLed,new DriveLed) private[this] val diskProgressPanels = Array(new DriveLoadProgressPanel,new DriveLoadProgressPanel) - private[this] val c1541 = new C1541Emu(bus,DriveLed8Listener) - private[this] val c1541_real : Drive with TraceListener = new C1571(0x00,bus,DriveLed8Listener,_1571mode _)//new C1541(0x00,bus,DriveLed8Listener) - private[this] val c1541_real9 : Drive with TraceListener = new C1571(0x01,bus,DriveLed9Listener, on => {}) private[this] val flyerIEC = new FlyerIEC(bus,file => attachDiskFile(0,file,false)) private[this] var isFlyerEnabled = false - private[this] var drives : Array[Drive] = Array(c1541_real,c1541_real9) + private[this] val drives : Array[Drive with TraceListener] = Array.ofDim(2) private[this] var device10Drive : Drive = _ private[this] var device10DriveEnabled = false private[this] var FSDIRasInput = true @@ -229,13 +225,49 @@ class C128 extends CBMComponent with ActionListener with GamePlayer with MMUChan maxSpeedItem.setSelected(false) } + private def initDrive(id:Int,driveType:DriveType.Value) { + val old = Option(drives(id)) + id match { + case 0 => + drives(0) = driveType match { + case DriveType._1571 => new C1571(0x00,bus,DriveLed8Listener,_1571mode _) + case DriveType._1541 => new C1541(0x00,bus,DriveLed8Listener) + } + drives(0).setIsRunningListener(diskRunning => isDiskActive = diskRunning) + isDiskActive = true + case 1 => + drives(1) = driveType match { + case DriveType._1571 => new C1571(0x01,bus,DriveLed9Listener,_ => {}) + case DriveType._1541 => new C1541(0x01,bus,DriveLed9Listener) + } + drives(1).setIsRunningListener(diskRunning => isDiskActive9 = diskRunning) + isDiskActive9 = true + } + + old match { + case None => + add(drives(id)) + case Some(c) => + c.disconnect + drives(id).initComponent + change(c,drives(id)) + drives(id).setDriveReader(c.getFloppy,false) + inspectDialog.updateRoot + diskTraceDialog.mem = drives(id).getMem + diskTraceDialog.traceListener = drives(id) + } + } + def init { val sw = new StringWriter Log.setOutput(new PrintWriter(sw)) Log.info("Building the system ...") - ExpansionPort.addConfigurationListener(mmu) - // ----------------------- + ExpansionPort.addConfigurationListener(mmu) + // drive + initDrive(0,DriveType._1571) + initDrive(1,DriveType._1571) + // ----------------------- clock.setClockHz(1000000) mmu.setKeyboard(keyb) add(clock) @@ -249,8 +281,8 @@ class C128 extends CBMComponent with ActionListener with GamePlayer with MMUChan add(expansionPort) add(rs232) rs232.setRS232Listener(rs232StatusPanel) - add(new FloppyComponent(8,attachedDisks,drives,driveLeds)) - add(new FloppyComponent(9,attachedDisks,drives,driveLeds)) + add(new FloppyComponent(8,drives(0),driveLeds(0))) + add(new FloppyComponent(9,drives(1),driveLeds(1))) // ----------------------- val vicMemory = mmu ExpansionPort.setMemoryForEmptyExpansionPort(mmu) @@ -357,7 +389,7 @@ class C128 extends CBMComponent with ActionListener with GamePlayer with MMUChan vicDisplay.addMouseListener(lightPen) // tracing traceDialog = TraceDialog.getTraceDialog(vicDisplayFrame,mmu,z80,vicDisplay,vicChip) - diskTraceDialog = TraceDialog.getTraceDialog(vicDisplayFrame,c1541_real.getMem,c1541_real) + diskTraceDialog = TraceDialog.getTraceDialog(vicDisplayFrame,drives(0).getMem,drives(0)) //diskTraceDialog.forceTracing(true) // drive leds add(driveLeds(0)) @@ -367,12 +399,6 @@ class C128 extends CBMComponent with ActionListener with GamePlayer with MMUChan vicDisplayFrame.setLocation(xy(0),xy(1)) } configureJoystick - // drive - c1541_real.setIsRunningListener(diskRunning => isDiskActive = diskRunning) - c1541_real9.setIsRunningListener(diskRunning => isDiskActive9 = diskRunning) - add(c1541) - add(c1541_real) - add(c1541_real9) Log.setOutput(traceDialog.logPanel.writer) // tape datassette = new c2n.Datassette(cia1.setFlagLow _) @@ -410,7 +436,8 @@ class C128 extends CBMComponent with ActionListener with GamePlayer with MMUChan override def afterInitHook { inspectDialog = InspectPanel.getInspectDialog(vicDisplayFrame,this) // deactivate drive 9 - c1541_real9.setActive(false) + drives(1).setActive(false) + driveLeds(1).setVisible(false) // set the correct CPU configuration cpuChanged(false) } @@ -575,16 +602,6 @@ class C128 extends CBMComponent with ActionListener with GamePlayer with MMUChan swapJoysticks case "DISK_RO" => drives foreach { _.setReadOnly(e.getSource.asInstanceOf[JCheckBoxMenuItem].isSelected) } - case "DISK_TRUE_EMU" => - val trueEmu = e.getSource.asInstanceOf[JCheckBoxMenuItem].isSelected - bus.reset - drives(0).setActive(false) - drives(0) = if (trueEmu) c1541_real - else { - isDiskActive = true - c1541 - } - drives(0).setActive(true) case "DISK_CAN_GO_SLEEP" => val canGoSleep = e.getSource.asInstanceOf[JCheckBoxMenuItem].isSelected drives foreach { _.setCanSleep(canGoSleep) } @@ -695,7 +712,7 @@ class C128 extends CBMComponent with ActionListener with GamePlayer with MMUChan changeLocalDriveDir case "DRIVE_9_ENABLED" => val enabled = e.getSource.asInstanceOf[JCheckBoxMenuItem].isSelected - c1541_real9.setActive(enabled) + drives(1).setActive(enabled) driveLeds(1).setVisible(enabled) adjustRatio case "SID_6581" => @@ -800,6 +817,16 @@ class C128 extends CBMComponent with ActionListener with GamePlayer with MMUChan kbef.setVisible(true) case "LOAD_KEYB" => loadKeyboard + case "DRIVE_1571" => + clock.pause + initDrive(0,DriveType._1571) + initDrive(1,DriveType._1571) + clock.play + case "DRIVE_1541" => + clock.pause + initDrive(0,DriveType._1541) + initDrive(1,DriveType._1541) + clock.play } } @@ -1114,16 +1141,12 @@ class C128 extends CBMComponent with ActionListener with GamePlayer with MMUChan private def attachDiskFile(driveID:Int,file:File,autorun:Boolean) { try { val isD64 = file.getName.toUpperCase.endsWith(".D64") || file.getName.toUpperCase.endsWith(".D71") - if (drives(driveID) == c1541 && !isD64) { + if (!isD64) { JOptionPane.showMessageDialog(vicDisplayFrame,"G64 format not allowed on a 1541 not in true emulation mode", "Disk attaching error",JOptionPane.ERROR_MESSAGE) return } val disk = Diskette(file.toString) - attachedDisks(driveID) match { - case Some(oldDisk) => oldDisk.close - case None => - } - attachedDisks(driveID) = Some(disk) + drives(driveID).getFloppy.close if (!traceDialog.isTracing) clock.pause drives(driveID).setDriveReader(disk,true) clock.play @@ -1329,21 +1352,20 @@ class C128 extends CBMComponent with ActionListener with GamePlayer with MMUChan } private def loadFileFromAttachedFile(driveID:Int,relocate:Boolean) { - attachedDisks(driveID) match { - case None => - JOptionPane.showMessageDialog(vicDisplayFrame,"No disk attached!", "Loading error",JOptionPane.ERROR_MESSAGE) - case Some(floppy) => - Option(JOptionPane.showInputDialog(vicDisplayFrame,"Load file","*")) match { - case None => - case Some(fileName) => - try { - floppy.asInstanceOf[Diskette].loadInMemory(mmu.getBank0RAM,fileName,relocate,c64Mode) - } - catch { - case t:Throwable => - JOptionPane.showMessageDialog(vicDisplayFrame, "Errore while loading from disk: " + t.getMessage,"Loading error",JOptionPane.ERROR_MESSAGE) - } - } + val floppy = drives(driveID).getFloppy + if (floppy.isEmpty) JOptionPane.showMessageDialog(vicDisplayFrame,"No disk attached!", "Loading error",JOptionPane.ERROR_MESSAGE) + else { + Option(JOptionPane.showInputDialog(vicDisplayFrame,"Load file","*")) match { + case None => + case Some(fileName) => + try { + floppy.asInstanceOf[Diskette].loadInMemory(mmu.getBank0RAM,fileName,relocate,c64Mode) + } + catch { + case t:Throwable => + JOptionPane.showMessageDialog(vicDisplayFrame, "Errore while loading from disk: " + t.getMessage,"Loading error",JOptionPane.ERROR_MESSAGE) + } + } } } @@ -1814,19 +1836,28 @@ class C128 extends CBMComponent with ActionListener with GamePlayer with MMUChan val diskItem = new JMenu("Drive") optionMenu.add(diskItem) + val driveTypeItem = new JMenu("Drive Type") + diskItem.add(driveTypeItem) + val group12 = new ButtonGroup + val _1571TypeItem = new JRadioButtonMenuItem("1571") + group12.add(_1571TypeItem) + _1571TypeItem.setSelected(true) + _1571TypeItem.setActionCommand("DRIVE_1571") + _1571TypeItem.addActionListener(this) + driveTypeItem.add(_1571TypeItem) + val _1541TypeItem = new JRadioButtonMenuItem("1541") + group12.add(_1541TypeItem) + _1541TypeItem.setActionCommand("DRIVE_1541") + _1541TypeItem.addActionListener(this) + driveTypeItem.add(_1541TypeItem) + val diskReadOnlyItem = new JCheckBoxMenuItem("Read only disk") diskReadOnlyItem.setSelected(false) diskReadOnlyItem.setActionCommand("DISK_RO") diskReadOnlyItem.addActionListener(this) diskItem.add(diskReadOnlyItem) - val diskTrueEmuItem = new JCheckBoxMenuItem("1541 True emulation") - diskTrueEmuItem.setSelected(true) - diskTrueEmuItem.setActionCommand("DISK_TRUE_EMU") - diskTrueEmuItem.addActionListener(this) - diskItem.add(diskTrueEmuItem) - - val diskCanSleepItem = new JCheckBoxMenuItem("1541 can go sleeping") + val diskCanSleepItem = new JCheckBoxMenuItem("Drive can go sleeping") diskCanSleepItem.setSelected(true) diskCanSleepItem.setActionCommand("DISK_CAN_GO_SLEEP") diskCanSleepItem.addActionListener(this) @@ -1838,7 +1869,7 @@ class C128 extends CBMComponent with ActionListener with GamePlayer with MMUChan parallelCableItem.addActionListener(this) diskItem.add(parallelCableItem) - val diskSpeedItem = new JMenu("1541 speed") + val diskSpeedItem = new JMenu("Drive speed") val group11 = new ButtonGroup val diskMinSpeedItem = new JRadioButtonMenuItem("Min speed") diskMinSpeedItem.setSelected(true) @@ -2082,13 +2113,10 @@ class C128 extends CBMComponent with ActionListener with GamePlayer with MMUChan try { val propsFile = new File(new File(scala.util.Properties.userHome),CONFIGURATION_FILENAME) val out = new FileWriter(propsFile) - configuration.store(out, "C64 configuration file") + configuration.store(out, "C128 configuration file") out.close - for(attachedDisk <- attachedDisks) - attachedDisk match { - case Some(d64) => d64.close - case None => - } + for(d <- drives) + d.getFloppy.close } catch { case io:IOException => diff --git a/Kernal64/src/ucesoft/cbm/c64/C64.scala b/Kernal64/src/ucesoft/cbm/c64/C64.scala index 5561a76e..7c32d589 100644 --- a/Kernal64/src/ucesoft/cbm/c64/C64.scala +++ b/Kernal64/src/ucesoft/cbm/c64/C64.scala @@ -140,15 +140,12 @@ class C64 extends CBMComponent with ActionListener with GamePlayer { // -------------------- DISK ----------------- private[this] var isDiskActive = true private[this] var isDiskActive9 = false - private[this] var attachedDisks : Array[Option[Diskette]] = Array(None,None) private[this] val driveLeds = Array(new DriveLed,new DriveLed) private[this] val diskProgressPanels = Array(new DriveLoadProgressPanel,new DriveLoadProgressPanel) private[this] val c1541 = new C1541Emu(bus,DriveLed8Listener) - private[this] val c1541_real = new C1541(0x00,bus,DriveLed8Listener) - private[this] val c1541_real9 = new C1541(0x01,bus,DriveLed9Listener) private[this] val flyerIEC = new FlyerIEC(bus,file => attachDiskFile(0,file,false)) private[this] var isFlyerEnabled = false - private[this] var drives : Array[Drive] = Array(c1541_real,c1541_real9) + private[this] val drives : Array[Drive with TraceListener] = Array.ofDim(2) private[this] var device10Drive : Drive = _ private[this] var device10DriveEnabled = false @@ -218,7 +215,6 @@ class C64 extends CBMComponent with ActionListener with GamePlayer { case _ => controlPortB.releaseEmulated } } - //override def mouseDragged(e:MouseEvent) = mouseClicked(e) def init {} def reset {} @@ -236,6 +232,24 @@ class C64 extends CBMComponent with ActionListener with GamePlayer { driveLeds(1).setVisible(false) } + private def initDrive(id:Int) { + val old = Option(drives(id)) + id match { + case 0 => + drives(0) = new C1541(0x00,bus,DriveLed8Listener) + drives(0).setIsRunningListener(diskRunning => isDiskActive = diskRunning) + case 1 => + drives(1) = new C1541(0x01,bus,DriveLed9Listener) + drives(1).setIsRunningListener(diskRunning => isDiskActive9 = diskRunning) + } + old match { + case None => + add(drives(id)) + case Some(c) => + change(c,drives(id)) + } + } + def reset { dma = false clock.maximumSpeed = false @@ -248,6 +262,9 @@ class C64 extends CBMComponent with ActionListener with GamePlayer { Log.info("Building the system ...") ExpansionPort.addConfigurationListener(mem) + // drive + initDrive(0) + initDrive(1) // ----------------------- add(clock) add(mem) @@ -259,8 +276,8 @@ class C64 extends CBMComponent with ActionListener with GamePlayer { add(expansionPort) add(rs232) rs232.setRS232Listener(rs232StatusPanel) - add(new FloppyComponent(8,attachedDisks,drives,driveLeds)) - add(new FloppyComponent(9,attachedDisks,drives,driveLeds)) + add(new FloppyComponent(8,drives(0),driveLeds(0))) + add(new FloppyComponent(9,drives(1),driveLeds(1))) // ----------------------- val vicMemory = new C64VICMemory(mem,mem.CHAR_ROM) add(vicMemory) @@ -313,7 +330,7 @@ class C64 extends CBMComponent with ActionListener with GamePlayer { add(lightPen) display.addMouseListener(lightPen) traceDialog = TraceDialog.getTraceDialog(displayFrame,mem,cpu,display,vicChip) - diskTraceDialog = TraceDialog.getTraceDialog(displayFrame,c1541_real.getMem,c1541_real) + diskTraceDialog = TraceDialog.getTraceDialog(displayFrame,drives(0).getMem,drives(0)) // drive leds add(driveLeds(0)) add(driveLeds(1)) @@ -322,12 +339,7 @@ class C64 extends CBMComponent with ActionListener with GamePlayer { displayFrame.setLocation(xy(0),xy(1)) } configureJoystick - // drive - c1541_real.setIsRunningListener(diskRunning => isDiskActive = diskRunning) - c1541_real9.setIsRunningListener(diskRunning => isDiskActive9 = diskRunning) add(c1541) - add(c1541_real) - add(c1541_real9) Log.setOutput(traceDialog.logPanel.writer) // tape datassette = new Datassette(cia1.setFlagLow _) @@ -363,7 +375,8 @@ class C64 extends CBMComponent with ActionListener with GamePlayer { override def afterInitHook { inspectDialog = InspectPanel.getInspectDialog(displayFrame,this) // deactivate drive 9 - c1541_real9.setActive(false) + drives(1).setActive(false) + driveLeds(1).setVisible(false) } private def errorHandler(t:Throwable) { @@ -477,16 +490,6 @@ class C64 extends CBMComponent with ActionListener with GamePlayer { swapJoysticks case "DISK_RO" => drives foreach { _.setReadOnly(e.getSource.asInstanceOf[JCheckBoxMenuItem].isSelected) } - case "DISK_TRUE_EMU" => - val trueEmu = e.getSource.asInstanceOf[JCheckBoxMenuItem].isSelected - bus.reset - drives(0).setActive(false) - drives(0) = if (trueEmu) c1541_real - else { - isDiskActive = true - c1541 - } - drives(0).setActive(true) case "DISK_CAN_GO_SLEEP" => val canGoSleep = e.getSource.asInstanceOf[JCheckBoxMenuItem].isSelected drives foreach { _.setCanSleep(canGoSleep) } @@ -599,7 +602,7 @@ class C64 extends CBMComponent with ActionListener with GamePlayer { changeLocalDriveDir case "DRIVE_9_ENABLED" => val enabled = e.getSource.asInstanceOf[JCheckBoxMenuItem].isSelected - c1541_real9.setActive(enabled) + drives(1).setActive(enabled) driveLeds(1).setVisible(enabled) adjustRatio case "SID_6581" => @@ -971,12 +974,8 @@ class C64 extends CBMComponent with ActionListener with GamePlayer { return } val disk = Diskette(file.toString) //if (isD64) new D64(file.toString) else new G64(file.toString) - attachedDisks(driveID) match { - case Some(oldDisk) => oldDisk.close - case None => - } - attachedDisks(driveID) = Some(disk) - clock.pause + drives(driveID).getFloppy.close + if (!traceDialog.isTracing) clock.pause drives(driveID).setDriveReader(disk,true) clock.play @@ -1170,21 +1169,20 @@ class C64 extends CBMComponent with ActionListener with GamePlayer { } private def loadFileFromAttachedFile(driveID:Int,relocate:Boolean) { - attachedDisks(driveID) match { - case None => - JOptionPane.showMessageDialog(displayFrame,"No disk attached!", "Loading error",JOptionPane.ERROR_MESSAGE) - case Some(floppy) => - Option(JOptionPane.showInputDialog(displayFrame,"Load file","*")) match { - case None => - case Some(fileName) => - try { - floppy.loadInMemory(mem,fileName,relocate) - } - catch { - case t:Throwable => - JOptionPane.showMessageDialog(displayFrame, "Errore while loading from disk: " + t.getMessage,"Loading error",JOptionPane.ERROR_MESSAGE) - } - } + val floppy = drives(driveID).getFloppy + if (floppy.isEmpty) JOptionPane.showMessageDialog(displayFrame,"No disk attached!", "Loading error",JOptionPane.ERROR_MESSAGE) + else { + Option(JOptionPane.showInputDialog(displayFrame,"Load file","*")) match { + case None => + case Some(fileName) => + try { + floppy.asInstanceOf[Diskette].loadInMemory(mem,fileName,relocate) + } + catch { + case t:Throwable => + JOptionPane.showMessageDialog(displayFrame, "Errore while loading from disk: " + t.getMessage,"Loading error",JOptionPane.ERROR_MESSAGE) + } + } } } @@ -1624,12 +1622,6 @@ class C64 extends CBMComponent with ActionListener with GamePlayer { diskReadOnlyItem.addActionListener(this) diskItem.add(diskReadOnlyItem) - val diskTrueEmuItem = new JCheckBoxMenuItem("1541 True emulation") - diskTrueEmuItem.setSelected(true) - diskTrueEmuItem.setActionCommand("DISK_TRUE_EMU") - diskTrueEmuItem.addActionListener(this) - diskItem.add(diskTrueEmuItem) - val diskCanSleepItem = new JCheckBoxMenuItem("1541 can go sleeping") diskCanSleepItem.setSelected(true) diskCanSleepItem.setActionCommand("DISK_CAN_GO_SLEEP") @@ -1863,11 +1855,8 @@ class C64 extends CBMComponent with ActionListener with GamePlayer { val out = new FileWriter(propsFile) configuration.store(out, "C64 configuration file") out.close - for(attachedDisk <- attachedDisks) - attachedDisk match { - case Some(d64) => d64.close - case None => - } + for(d <- drives) + d.getFloppy.close } catch { case io:IOException => diff --git a/Kernal64/src/ucesoft/cbm/misc/FloppyComponent.scala b/Kernal64/src/ucesoft/cbm/misc/FloppyComponent.scala index 9dee99bc..fdfee843 100644 --- a/Kernal64/src/ucesoft/cbm/misc/FloppyComponent.scala +++ b/Kernal64/src/ucesoft/cbm/misc/FloppyComponent.scala @@ -6,44 +6,36 @@ import ucesoft.cbm.CBMComponentType import java.io.ObjectOutputStream import java.io.ObjectInputStream import javax.swing.JFrame -import ucesoft.cbm.formats.Diskette import ucesoft.cbm.peripheral.drive.Floppy -class FloppyComponent(device:Int,attachedDisks : Array[Option[Diskette]],drives : Array[Drive],driveLeds:Array[DriveLed]) extends CBMComponent { +class FloppyComponent(device:Int,drive:Drive,driveLed:DriveLed) extends CBMComponent { val componentID = "Mounted floppy " + device val componentType = CBMComponentType.FLOPPY final private[this] val deviceID = device - 8 override def getProperties = { - val attachedDisk = attachedDisks(deviceID) - properties.setProperty("Floppy",if (attachedDisk.isDefined) attachedDisk.get.toString else "-") - properties.setProperty("Track",if (attachedDisk.isDefined) attachedDisk.get.currentTrack.toString else "-") - properties.setProperty("Sector",if (attachedDisk.isDefined && attachedDisk.get.currentSector.isDefined) attachedDisk.get.currentSector.get.toString else "N/A") - properties.setProperty("Total tracks",if (attachedDisk.isDefined) attachedDisk.get.totalTracks.toString else "-") - properties.setProperty("Side",if (attachedDisk.isDefined) attachedDisk.get.side.toString else "-") - properties.setProperty("Single side",if (attachedDisk.isDefined) attachedDisk.get.singleSide.toString else "-") + val attachedDisk = drive.getFloppy + properties.setProperty("Floppy",if (!attachedDisk.isEmpty) attachedDisk.toString else "-") + properties.setProperty("Track",if (!attachedDisk.isEmpty) attachedDisk.currentTrack.toString else "-") + properties.setProperty("Sector",if (!attachedDisk.isEmpty && attachedDisk.currentSector.isDefined) attachedDisk.currentSector.get.toString else "N/A") + properties.setProperty("Total tracks",if (!attachedDisk.isEmpty) attachedDisk.totalTracks.toString else "-") + properties.setProperty("Side",if (!attachedDisk.isEmpty) attachedDisk.side.toString else "-") + properties.setProperty("Single side",if (!attachedDisk.isEmpty) attachedDisk.singleSide.toString else "-") properties } def init {} - def reset = attachedDisks(deviceID) match { - case Some(d) => d.reset - case None => - } + def reset = drive.getFloppy.reset // state protected def saveState(out:ObjectOutputStream) { - Floppy.save(out,attachedDisks(deviceID)) + Floppy.save(out,if (drive.getFloppy.isEmpty) None else Some(drive.getFloppy)) } protected def loadState(in:ObjectInputStream) { Floppy.load(in) match { case Some(floppy) => - attachedDisks(deviceID) match { - case Some(oldDisk) => oldDisk.close - case None => - } - attachedDisks(deviceID) = Some(floppy.asInstanceOf[Diskette]) - drives(deviceID).setDriveReader(floppy,false) - driveLeds(deviceID).setToolTipText(floppy.file) + drive.getFloppy.close + drive.setDriveReader(floppy,false) + driveLed.setToolTipText(floppy.file) case None => } } diff --git a/Kernal64/src/ucesoft/cbm/peripheral/bus/IECBus.scala b/Kernal64/src/ucesoft/cbm/peripheral/bus/IECBus.scala index b4ece977..f5df020e 100644 --- a/Kernal64/src/ucesoft/cbm/peripheral/bus/IECBus.scala +++ b/Kernal64/src/ucesoft/cbm/peripheral/bus/IECBus.scala @@ -51,7 +51,8 @@ class IECBus extends CBMComponent { } final def unregisterListener(l:IECBusListener) { - lines = lines filterNot { s => s.listener == l } + lines = lines filterNot { _.listener.busid == l.busid } + updateLines } final def registerListener(l:IECBusListener) { diff --git a/Kernal64/src/ucesoft/cbm/peripheral/drive/C1541.scala b/Kernal64/src/ucesoft/cbm/peripheral/drive/C1541.scala index 88609885..34e684be 100644 --- a/Kernal64/src/ucesoft/cbm/peripheral/drive/C1541.scala +++ b/Kernal64/src/ucesoft/cbm/peripheral/drive/C1541.scala @@ -16,6 +16,7 @@ import javax.swing.JFrame import ucesoft.cbm.cpu.Memory class C1541(val jackID: Int, bus: IECBus, ledListener: DriveLedListener) extends TraceListener with Drive { + val driveType = DriveType._1541 val componentID = "C1541 Disk Drive " + jackID override val MIN_SPEED_HZ = 985248 override val MAX_SPEED_HZ = 1000000 @@ -66,7 +67,7 @@ class C1541(val jackID: Int, bus: IECBus, ledListener: DriveLedListener) extends viaDisk.awake } - def disconnect { + override def disconnect { bus.unregisterListener(viaBus) } diff --git a/Kernal64/src/ucesoft/cbm/peripheral/drive/C1541Emu.scala b/Kernal64/src/ucesoft/cbm/peripheral/drive/C1541Emu.scala index 6c69af17..6d52ad18 100644 --- a/Kernal64/src/ucesoft/cbm/peripheral/drive/C1541Emu.scala +++ b/Kernal64/src/ucesoft/cbm/peripheral/drive/C1541Emu.scala @@ -36,6 +36,7 @@ object C1541Emu { } class C1541Emu(bus: IECBus, ledListener: DriveLedListener, device: Int = 8) extends IECBusDevice(bus, device) with Drive { + val driveType = DriveType.OTHER val componentID = "C1541 Emu" override val busid = "C1541Emu_" + device diff --git a/Kernal64/src/ucesoft/cbm/peripheral/drive/C1571.scala b/Kernal64/src/ucesoft/cbm/peripheral/drive/C1571.scala index 7b81c3d3..dad36206 100644 --- a/Kernal64/src/ucesoft/cbm/peripheral/drive/C1571.scala +++ b/Kernal64/src/ucesoft/cbm/peripheral/drive/C1571.scala @@ -29,6 +29,7 @@ class C1571(val driveID: Int, RAMComponent with TraceListener with Drive { + val driveType = DriveType._1571 val componentID = "C1571 Disk Drive " + driveID override val MIN_SPEED_HZ = 985248 override val MAX_SPEED_HZ = 1000000 @@ -143,7 +144,7 @@ class C1571(val driveID: Int, * CIA for fast serial bus * ***********************************************************************************************************/ - private[this] val CIA = new CIA("CIA_FAST",0x4000,EmptyCIAConnector,EmptyCIAConnector,IRQSwitcher.ciaIRQ _,false) with IECBusListener { + private[this] val CIA = new CIA("CIA_FAST_" + driveID,0x4000,EmptyCIAConnector,EmptyCIAConnector,IRQSwitcher.ciaIRQ _,false) with IECBusListener { val busid = name override def srqTriggered = if (busDataDirection == 0) serialIN(bus.data == IECBus.GROUND) @@ -188,7 +189,7 @@ class C1571(val driveID: Int, override def read(address: Int, chipID: ChipID.ID) = (address & 0x0F) match { case ad@(PA|PA2) => super.read(address,chipID) - (if (floppy.currentTrack != 0) 1 else 0) | busDataDirection << 1 | activeHead << 2 | (if (_1541Mode) 0 else 1 << 5) | RW_HEAD.getByteReadySignal << 7 + (if (floppy.currentTrack != 1) 1 else 0) | busDataDirection << 1 | activeHead << 2 | (if (_1541Mode) 0 else 1 << 5) | RW_HEAD.getByteReadySignal << 7 case PB => (super.read(address,chipID) & 0x1A) | (bus.data|data_out) | (bus.clk|clock_out) << 2 | bus.atn << 7 | IDJACK << 5 @@ -237,7 +238,6 @@ class C1571(val driveID: Int, * ***********************************************************************************************************/ private[this] val VIA2 = new VIA("VIA1571_DiskControl", 0x1C00,IRQSwitcher.viaDiskIRQ _) { - val busid = "VIA1571_DiskControl" override lazy val componentID = "VIA1571_2 (DC)" private[this] val WRITE_PROTECT_SENSE = 0x10 private[this] val WRITE_PROTECT_SENSE_WAIT = 3 * 400000L @@ -425,6 +425,11 @@ class C1571(val driveID: Int, override def getMem = this // =============================================================== + override def disconnect { + bus.unregisterListener(VIA1) + bus.unregisterListener(CIA) + } + override def getProperties = { properties.setProperty("Speed Hz",currentSpeedHz.toString) properties.setProperty("Cycle adjustment",CYCLE_ADJ.toString) diff --git a/Kernal64/src/ucesoft/cbm/peripheral/drive/Drive.scala b/Kernal64/src/ucesoft/cbm/peripheral/drive/Drive.scala index b22c6e2c..5ee208d7 100644 --- a/Kernal64/src/ucesoft/cbm/peripheral/drive/Drive.scala +++ b/Kernal64/src/ucesoft/cbm/peripheral/drive/Drive.scala @@ -4,10 +4,20 @@ import ucesoft.cbm.CBMComponent import ucesoft.cbm.CBMComponentType import ucesoft.cbm.cpu.Memory +object DriveType extends Enumeration { + val _1541 = Value + val _1571 = Value + val _1581 = Value + val OTHER = Value + val LOCAL = Value +} + trait Drive extends CBMComponent { val componentType = CBMComponentType.DISK + val driveType : DriveType.Value protected var isRunningListener : (Boolean) => Unit = x => {} + def disconnect {} def setActive(active:Boolean) {} def setCanSleep(canSleep:Boolean) {} def setIsRunningListener(listener: (Boolean) => Unit) = isRunningListener = listener diff --git a/Kernal64/src/ucesoft/cbm/peripheral/drive/Floppy.scala b/Kernal64/src/ucesoft/cbm/peripheral/drive/Floppy.scala index caf6026a..a68295e5 100644 --- a/Kernal64/src/ucesoft/cbm/peripheral/drive/Floppy.scala +++ b/Kernal64/src/ucesoft/cbm/peripheral/drive/Floppy.scala @@ -50,6 +50,7 @@ trait Floppy { val totalTracks : Int val file : String lazy val singleSide = true + val isEmpty = false def minTrack = 1 def maxTrack = totalTracks @@ -101,6 +102,7 @@ object EmptyFloppy extends Floppy { val isFormattable = false val totalTracks = 35 val file = "" + override val isEmpty = true private[this] var track = 1 private[this] var listener : TrackListener = _ diff --git a/Kernal64/src/ucesoft/cbm/peripheral/drive/FlyerIEC.scala b/Kernal64/src/ucesoft/cbm/peripheral/drive/FlyerIEC.scala index 8a43de91..8d539e11 100644 --- a/Kernal64/src/ucesoft/cbm/peripheral/drive/FlyerIEC.scala +++ b/Kernal64/src/ucesoft/cbm/peripheral/drive/FlyerIEC.scala @@ -19,6 +19,7 @@ import java.net.URLEncoder import ucesoft.cbm.formats.Diskette class FlyerIEC(bus: IECBus,attachDrive: (File) => Unit) extends AbstractDrive(bus, 7) { + val driveType = DriveType.OTHER val componentID = "FlyerIEC" override val busid = "FlyerIEC" diff --git a/Kernal64/src/ucesoft/cbm/peripheral/drive/LocalDrive.scala b/Kernal64/src/ucesoft/cbm/peripheral/drive/LocalDrive.scala index 0695e27c..7e09e774 100644 --- a/Kernal64/src/ucesoft/cbm/peripheral/drive/LocalDrive.scala +++ b/Kernal64/src/ucesoft/cbm/peripheral/drive/LocalDrive.scala @@ -11,6 +11,7 @@ import language.postfixOps import ucesoft.cbm.formats.Diskette class LocalDrive(bus: IECBus, device: Int = 9) extends AbstractDrive(bus, device) { + val driveType = DriveType.LOCAL val componentID = "Local Drive" override val busid = "LocalDrive_" + device diff --git a/Kernal64/src/ucesoft/cbm/peripheral/drive/RWHeadController.scala b/Kernal64/src/ucesoft/cbm/peripheral/drive/RWHeadController.scala index 8db90d9e..a00144bd 100644 --- a/Kernal64/src/ucesoft/cbm/peripheral/drive/RWHeadController.scala +++ b/Kernal64/src/ucesoft/cbm/peripheral/drive/RWHeadController.scala @@ -114,7 +114,7 @@ class RWHeadController(val name:String, final def isMotorOn : Boolean = motorOn final def setMotor(on:Boolean) { motorOn = on - if (on && floppy == EmptyFloppy) floppy.setTrackChangeListener(updateTrackSectorLabelProgress _) + if (on && floppy.isEmpty) floppy.setTrackChangeListener(updateTrackSectorLabelProgress _) } final def isSync : Boolean = !isWriting && motorOn && last10Bits == 0x3FF final def moveHead(moveOut: Boolean) { diff --git a/Kernal64/src/ucesoft/cbm/peripheral/drive/VIADiskControl.scala b/Kernal64/src/ucesoft/cbm/peripheral/drive/VIADiskControl.scala index b998009b..65a843b0 100644 --- a/Kernal64/src/ucesoft/cbm/peripheral/drive/VIADiskControl.scala +++ b/Kernal64/src/ucesoft/cbm/peripheral/drive/VIADiskControl.scala @@ -178,7 +178,7 @@ class VIADiskControl(cpu: CPU6510, ledListener.endLoading if (lastMotorOn && !motorOn) currentFilename = "" } - else if (floppy == EmptyFloppy) floppy.setTrackChangeListener(updateTrackSectorLabelProgress _) + else if (floppy.isEmpty) floppy.setTrackChangeListener(updateTrackSectorLabelProgress _) } val newSpeedZone = (value & 0xFF) >> 5 & 0x3 if (newSpeedZone != speedZone) { diff --git a/Kernal64/src/ucesoft/cbm/trace/InspectPanel.scala b/Kernal64/src/ucesoft/cbm/trace/InspectPanel.scala index 2c992392..e6cb1244 100644 --- a/Kernal64/src/ucesoft/cbm/trace/InspectPanel.scala +++ b/Kernal64/src/ucesoft/cbm/trace/InspectPanel.scala @@ -17,22 +17,30 @@ import java.util.EventObject import java.awt.event.MouseEvent object InspectPanel { - def getInspectDialog(f: JFrame, root: CBMComponent) = { - val panel = new InspectPanel(root) - val dialog = new JDialog(f, "Inspect panel") { - override def setVisible(visible: Boolean) { - super.setVisible(visible) - panel.enableUpdating(visible) - } - } - dialog.getContentPane.add("Center", panel) - dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE) - dialog.pack - dialog + def getInspectDialog(f: JFrame, root: CBMComponent) = new InspectPanelDialog(f,root) +} + +class InspectPanelDialog(f: JFrame,root: CBMComponent) extends JDialog(f, "Inspect panel") { + private[this] var panel = new InspectPanel(root) + + override def setVisible(visible: Boolean) { + super.setVisible(visible) + panel.enableUpdating(visible) + } + + getContentPane.add("Center", panel) + setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE) + pack + + def updateRoot { + getContentPane.remove(panel) + panel = new InspectPanel(root) + getContentPane.add("Center", panel) + revalidate } } -class InspectPanel(root: CBMComponent) extends JPanel with Runnable with ChangeListener { +private[trace] class InspectPanel(root: CBMComponent) extends JPanel with Runnable with ChangeListener { private[this] val treeRoot = createTree(root) private[this] val lock = new Object private[this] val tree = new JTree(treeRoot) @@ -118,7 +126,7 @@ class InspectPanel(root: CBMComponent) extends JPanel with Runnable with ChangeL override def toString = "Insert an hex address [=]" } - private def enableUpdating(enabled: Boolean) { + def enableUpdating(enabled: Boolean) { visible = enabled if (enabled) lock.synchronized { lock.notify diff --git a/Kernal64/src/ucesoft/cbm/trace/TraceDialog.scala b/Kernal64/src/ucesoft/cbm/trace/TraceDialog.scala index 41ec0cd4..84d8c249 100644 --- a/Kernal64/src/ucesoft/cbm/trace/TraceDialog.scala +++ b/Kernal64/src/ucesoft/cbm/trace/TraceDialog.scala @@ -29,7 +29,7 @@ object TraceDialog { } class TraceDialog private (displayFrame: JFrame, - mem: Memory, + var mem: Memory, var traceListener: TraceListener, display: Option[Display], vic: Option[VIC]) extends JDialog(displayFrame, "Trace dialog") with ActionListener {