mirror of
https://github.com/badvision/jace.git
synced 2025-01-17 21:33:55 +00:00
Replaced card array with Optional<Card> array
This commit is contained in:
parent
f3245a4245
commit
776dbafbdc
@ -40,6 +40,7 @@ import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@ -133,10 +134,8 @@ public class Apple2e extends Computer {
|
||||
getMemory().configureActiveMemory();
|
||||
getVideo().configureVideoMode();
|
||||
getCpu().reset();
|
||||
for (Card c : getMemory().getAllCards()) {
|
||||
if (c != null) {
|
||||
c.reset();
|
||||
}
|
||||
for (Optional<Card> c : getMemory().getAllCards()) {
|
||||
c.ifPresent(Card::reset);
|
||||
}
|
||||
|
||||
resume();
|
||||
@ -163,10 +162,8 @@ public class Apple2e extends Computer {
|
||||
getMemory().configureActiveMemory();
|
||||
getVideo().configureVideoMode();
|
||||
getCpu().reset();
|
||||
for (Card c : getMemory().getAllCards()) {
|
||||
if (c != null) {
|
||||
c.reset();
|
||||
}
|
||||
for (Optional<Card> c : getMemory().getAllCards()) {
|
||||
c.ifPresent(Card::reset);
|
||||
}
|
||||
getCpu().resume();
|
||||
resume();
|
||||
|
@ -160,22 +160,15 @@ abstract public class RAM128k extends RAM {
|
||||
} else {
|
||||
// Enable C1-CF to point to slots
|
||||
for (int slot = 1; slot <= 7; slot++) {
|
||||
Card c = getCard(slot);
|
||||
if (c != null) {
|
||||
// Enable card slot ROM
|
||||
activeRead.setBanks(0, 1, 0x0C0 + slot, c.getCxRom());
|
||||
if (getActiveSlot() == slot) {
|
||||
activeRead.setBanks(0, 8, 0x0C8, c.getC8Rom());
|
||||
}
|
||||
} else {
|
||||
// Disable card slot ROM (TODO: floating bus)
|
||||
activeRead.set(0x0C0 + slot, blank.get(0));
|
||||
}
|
||||
PagedMemory page = getCard(slot).map(Card::getCxRom).orElse(blank);
|
||||
activeRead.setBanks(0, 1, 0x0c0 + slot, page);
|
||||
}
|
||||
if (getActiveSlot() == 0) {
|
||||
for (int i = 0x0C8; i < 0x0D0; i++) {
|
||||
activeRead.set(i, blank.get(0));
|
||||
}
|
||||
} else {
|
||||
getCard(getActiveSlot()).ifPresent(c -> activeRead.setBanks(0,8,0x0c8, c.getC8Rom()));
|
||||
}
|
||||
if (SoftSwitches.SLOTC3ROM.isOff()) {
|
||||
// Enable C3 to point to internal ROM
|
||||
|
@ -24,6 +24,7 @@ import jace.config.Reconfigurable;
|
||||
import jace.library.MediaLibrary;
|
||||
import jace.state.StateManager;
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* This is a very generic stub of a Computer and provides a generic set of
|
||||
@ -61,11 +62,8 @@ public abstract class Computer implements Reconfigurable {
|
||||
}
|
||||
|
||||
public void notifyVBLStateChanged(boolean state) {
|
||||
for (Card c : getMemory().cards) {
|
||||
if (c == null) {
|
||||
continue;
|
||||
}
|
||||
c.notifyVBLStateChanged(state);
|
||||
for (Optional<Card> c : getMemory().cards) {
|
||||
c.ifPresent(card -> card.notifyVBLStateChanged(state));
|
||||
}
|
||||
if (state && stateManager != null) {
|
||||
stateManager.notifyVBLActive();
|
||||
|
@ -21,10 +21,9 @@ package jace.core;
|
||||
import jace.apple2e.SoftSwitches;
|
||||
import jace.apple2e.Speaker;
|
||||
import jace.config.ConfigurableField;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@ -78,7 +77,7 @@ public class Motherboard extends TimedDevice {
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
Card[] cards = computer.getMemory().getAllCards();
|
||||
Optional<Card>[] cards = computer.getMemory().getAllCards();
|
||||
try {
|
||||
clockCounter--;
|
||||
computer.getCpu().doTick();
|
||||
@ -88,26 +87,8 @@ public class Motherboard extends TimedDevice {
|
||||
clockCounter = cpuPerClock;
|
||||
computer.getVideo().doTick();
|
||||
// Unrolled loop since this happens so often
|
||||
if (cards[0] != null) {
|
||||
cards[0].doTick();
|
||||
}
|
||||
if (cards[1] != null) {
|
||||
cards[1].doTick();
|
||||
}
|
||||
if (cards[2] != null) {
|
||||
cards[2].doTick();
|
||||
}
|
||||
if (cards[3] != null) {
|
||||
cards[3].doTick();
|
||||
}
|
||||
if (cards[4] != null) {
|
||||
cards[4].doTick();
|
||||
}
|
||||
if (cards[5] != null) {
|
||||
cards[5].doTick();
|
||||
}
|
||||
if (cards[6] != null) {
|
||||
cards[6].doTick();
|
||||
for (Optional<Card> card : cards) {
|
||||
card.ifPresent(Card::doTick);
|
||||
}
|
||||
miscDevices.stream().forEach((m) -> {
|
||||
m.doTick();
|
||||
@ -186,12 +167,13 @@ public class Motherboard extends TimedDevice {
|
||||
public boolean suspend() {
|
||||
synchronized (resume) {
|
||||
resume.clear();
|
||||
for (Card c : computer.getMemory().getAllCards()) {
|
||||
if (c == null || !c.suspendWithCPU() || !c.isRunning()) {
|
||||
for (Optional<Card> c : computer.getMemory().getAllCards()) {
|
||||
if (!c.isPresent()) continue;
|
||||
if (!c.get().suspendWithCPU() || !c.get().isRunning()) {
|
||||
continue;
|
||||
}
|
||||
if (c.suspend()) {
|
||||
resume.add(c);
|
||||
if (c.get().suspend()) {
|
||||
resume.add(c.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import jace.config.Reconfigurable;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* RAM is a 64K address space of paged memory. It also manages sets of memory
|
||||
@ -38,7 +39,7 @@ public abstract class RAM implements Reconfigurable {
|
||||
public List<RAMListener> listeners;
|
||||
public List<RAMListener>[] listenerMap;
|
||||
public List<RAMListener>[] ioListenerMap;
|
||||
protected Card[] cards;
|
||||
protected Optional<Card>[] cards;
|
||||
// card 0 = 80 column card firmware / system rom
|
||||
public int activeSlot = 0;
|
||||
protected final Computer computer;
|
||||
@ -49,7 +50,10 @@ public abstract class RAM implements Reconfigurable {
|
||||
public RAM(Computer computer) {
|
||||
this.computer = computer;
|
||||
listeners = new ArrayList<>();
|
||||
cards = new Card[8];
|
||||
cards = new Optional[8];
|
||||
for (int i=0; i < 8; i ++) {
|
||||
cards[i] = Optional.empty();
|
||||
}
|
||||
refreshListenerMap();
|
||||
}
|
||||
|
||||
@ -66,19 +70,19 @@ public abstract class RAM implements Reconfigurable {
|
||||
return activeSlot;
|
||||
}
|
||||
|
||||
public Card[] getAllCards() {
|
||||
public Optional<Card>[] getAllCards() {
|
||||
return cards;
|
||||
}
|
||||
|
||||
public Card getCard(int slot) {
|
||||
public Optional<Card> getCard(int slot) {
|
||||
if (slot >= 1 && slot <= 7) {
|
||||
return cards[slot];
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public void addCard(Card c, int slot) {
|
||||
cards[slot] = c;
|
||||
cards[slot] = Optional.of(c);
|
||||
c.setSlot(slot);
|
||||
c.attach();
|
||||
}
|
||||
@ -90,11 +94,9 @@ public abstract class RAM implements Reconfigurable {
|
||||
}
|
||||
|
||||
public void removeCard(int slot) {
|
||||
if (cards[slot] != null) {
|
||||
cards[slot].suspend();
|
||||
cards[slot].detach();
|
||||
}
|
||||
cards[slot] = null;
|
||||
cards[slot].ifPresent(Card::suspend);
|
||||
cards[slot].ifPresent(Card::detach);
|
||||
cards[slot] = Optional.empty();
|
||||
}
|
||||
|
||||
abstract public void configureActiveMemory();
|
||||
|
@ -31,6 +31,7 @@ import jace.hardware.SmartportDriver;
|
||||
import jace.library.MediaConsumer;
|
||||
import jace.library.MediaConsumerParent;
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@ -135,8 +136,8 @@ public class CardMassStorage extends Card implements MediaConsumerParent {
|
||||
// This is a convenience to boot a hard-drive if the emulator has started waiting for a currentDisk
|
||||
currentDrive = drive1;
|
||||
getCurrentDisk().boot0(getSlot(), computer);
|
||||
Card[] cards = computer.getMemory().getAllCards();
|
||||
computer.getMotherboard().cancelSpeedRequest(cards[6]);
|
||||
Optional<Card>[] cards = computer.getMemory().getAllCards();
|
||||
cards[6].ifPresent(card->computer.getMotherboard().cancelSpeedRequest(card));
|
||||
}
|
||||
attach();
|
||||
} catch (IOException ex) {
|
||||
|
@ -25,6 +25,7 @@ import jace.core.Card;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.util.Optional;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
/**
|
||||
@ -79,21 +80,19 @@ public class MediaLibrary implements Reconfigurable {
|
||||
return;
|
||||
}
|
||||
userInterface.Drives.removeAll();
|
||||
for (Card card : Emulator.computer.memory.getAllCards()) {
|
||||
if (card == null || !(card instanceof MediaConsumerParent)) {
|
||||
continue;
|
||||
}
|
||||
MediaConsumerParent parent = (MediaConsumerParent) card;
|
||||
GridBagLayout layout = (GridBagLayout) userInterface.Drives.getLayout();
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
for (MediaConsumer consumer : parent.getConsumers()) {
|
||||
DriveIcon drive = new DriveIcon(consumer);
|
||||
drive.setSize(100, 70);
|
||||
drive.setPreferredSize(new Dimension(100, 70));
|
||||
c.gridwidth = GridBagConstraints.REMAINDER;
|
||||
layout.setConstraints(drive, c);
|
||||
userInterface.Drives.add(drive);
|
||||
}
|
||||
for (Optional<Card> card : Emulator.computer.memory.getAllCards()) {
|
||||
card.filter(c -> c instanceof MediaConsumerParent).ifPresent(parent -> {
|
||||
GridBagLayout layout = (GridBagLayout) userInterface.Drives.getLayout();
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
for (MediaConsumer consumer : ((MediaConsumerParent) parent).getConsumers()) {
|
||||
DriveIcon drive = new DriveIcon(consumer);
|
||||
drive.setSize(100, 70);
|
||||
drive.setPreferredSize(new Dimension(100, 70));
|
||||
c.gridwidth = GridBagConstraints.REMAINDER;
|
||||
layout.setConstraints(drive, c);
|
||||
userInterface.Drives.add(drive);
|
||||
}
|
||||
});
|
||||
}
|
||||
userInterface.Drives.revalidate();
|
||||
}
|
||||
@ -119,7 +118,7 @@ public class MediaLibrary implements Reconfigurable {
|
||||
form.setCreate(false);
|
||||
form.populate(entry);
|
||||
}
|
||||
form.setParentLibary(library);
|
||||
form.setParentLibary(library);
|
||||
return form;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import jace.core.Computer;
|
||||
import jace.core.Motherboard;
|
||||
import jace.hardware.CardExt80Col;
|
||||
import jace.hardware.CardMockingboard;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -79,19 +80,15 @@ public class PlaybackEngine extends Computer {
|
||||
|
||||
@Override
|
||||
public void coldStart() {
|
||||
for (Card c : getMemory().getAllCards()) {
|
||||
if (c != null) {
|
||||
c.reset();
|
||||
}
|
||||
for (Optional<Card> c : getMemory().getAllCards()) {
|
||||
c.ifPresent(Card::reset);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warmStart() {
|
||||
for (Card c : getMemory().getAllCards()) {
|
||||
if (c != null) {
|
||||
c.reset();
|
||||
}
|
||||
for (Optional<Card> c : getMemory().getAllCards()) {
|
||||
c.ifPresent(Card::reset);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#Generated by Maven
|
||||
#Wed Sep 17 00:59:53 CDT 2014
|
||||
#Sat Sep 20 01:41:50 CDT 2014
|
||||
version=2.0-SNAPSHOT
|
||||
groupId=org.badvision
|
||||
artifactId=jace
|
||||
|
@ -114,6 +114,7 @@ jace/hardware/massStorage/DirectoryNode.class
|
||||
jace/cheat/MetaCheatForm$2.class
|
||||
jace/hardware/ConsoleProbe$KeyReader.class
|
||||
jace/hardware/massStorage/FreespaceBitmap.class
|
||||
jace/tracker/PlaybackEngine$1.class
|
||||
jace/apple2e/MOS65C02$SMBCommand.class
|
||||
jace/hardware/massStorage/DiskNode.class
|
||||
jace/hardware/mockingboard/TimedGenerator.class
|
||||
@ -145,7 +146,6 @@ jace/library/MediaLibraryUI$tocOptions$3.class
|
||||
jace/apple2e/Apple2e.class
|
||||
jace/cheat/MemorySpy$6.class
|
||||
jace/hardware/PassportMidiInterface$PTMTimer.class
|
||||
jace/hardware/DiskIIDrive$1.class
|
||||
jace/library/DriveIcon.class
|
||||
jace/EmulatorUILogic$2.class
|
||||
jace/cheat/MetaCheatForm$11.class
|
||||
@ -157,7 +157,6 @@ jace/cheat/MetaCheatForm$4.class
|
||||
jace/apple2e/SoftSwitches$1.class
|
||||
jace/config/ClassSelection$1.class
|
||||
jace/hardware/CardExt80Col.class
|
||||
jace/ui/EmulatorFrame$2.class
|
||||
jace/library/MediaLibraryUI$tocOptions$4.class
|
||||
jace/hardware/ConsoleProbe$ScreenReader.class
|
||||
jace/config/FileComponent$2.class
|
||||
@ -167,8 +166,6 @@ jace/hardware/Joystick$1.class
|
||||
jace/library/MediaEditUI$5.class
|
||||
jace/tracker/EditableLabel.class
|
||||
jace/apple2e/VideoDHGR.class
|
||||
jace/ui/MainFrame$1.class
|
||||
jace/ui/AbstractEmulatorFrame$4.class
|
||||
jace/hardware/CardRamworks$1.class
|
||||
jace/apple2e/VideoDHGR$1.class
|
||||
jace/cheat/MetaCheatForm$10.class
|
||||
@ -178,7 +175,6 @@ jace/core/SoundMixer$1.class
|
||||
jace/JaceApplication.class
|
||||
jace/tracker/EditableLabel$2$1.class
|
||||
jace/applesoft/Command$ByteOrToken.class
|
||||
jace/cheat/MemorySpyGrid$7.class
|
||||
jace/config/Configuration$ConfigNode.class
|
||||
jace/state/Stateful.class
|
||||
jace/cheat/MetaCheatForm$6.class
|
||||
@ -196,7 +192,6 @@ jace/apple2e/MOS65C02$BBRCommand.class
|
||||
jace/apple2e/VideoDHGR$7.class
|
||||
jace/library/TocTreeModel$1.class
|
||||
jace/ui/DebuggerPanel$11.class
|
||||
jace/cheat/MetaCheats$2$1.class
|
||||
jace/state/ObjectGraphNode.class
|
||||
jace/hardware/massStorage/DirectoryNode$1.class
|
||||
jace/JaceUIController.class
|
||||
@ -219,7 +214,6 @@ jace/hardware/Joystick$3.class
|
||||
jace/cheat/MemorySpy$2.class
|
||||
jace/cheat/MemorySpy$9.class
|
||||
jace/hardware/CardSSC$2.class
|
||||
jace/cheat/MemorySpyGrid$8.class
|
||||
jace/core/Computer.class
|
||||
jace/hardware/massStorage/FileNode$1.class
|
||||
jace/apple2e/softswitch/IntC8SoftSwitch$1.class
|
||||
@ -292,7 +286,6 @@ jace/hardware/mockingboard/PSG$1.class
|
||||
jace/hardware/CardRamworks$BankType.class
|
||||
jace/tracker/PlaybackEngine.class
|
||||
jace/apple2e/VideoNTSC$2.class
|
||||
jace/cheat/MemorySpyGrid$6.class
|
||||
jace/apple2e/Speaker.class
|
||||
jace/ui/ScreenCanvas.class
|
||||
jace/config/IntegerComponent.class
|
||||
@ -323,7 +316,6 @@ jace/apple2e/VideoNTSC$3.class
|
||||
jace/library/MediaLibraryUI$tocOptions.class
|
||||
jace/hardware/ConsoleProbe$1.class
|
||||
jace/hardware/ProdosDriver$MLI_RETURN.class
|
||||
jace/cheat/MemorySpyGrid$5.class
|
||||
jace/cheat/MetaCheats.class
|
||||
jace/hardware/massStorage/FileNode$FileType.class
|
||||
jace/config/DynamicSelectComponent.class
|
||||
@ -331,7 +323,6 @@ jace/core/SoftSwitch$1.class
|
||||
jace/hardware/CardRamworks.class
|
||||
jace/library/MediaLibraryUI$8.class
|
||||
jace/ui/DebuggerPanel$7.class
|
||||
jace/cheat/MemorySpyGrid$4.class
|
||||
jace/config/ISelection.class
|
||||
jace/apple2e/MOS65C02$AddressCalculator.class
|
||||
jace/library/MediaLibraryUI$9.class
|
||||
|
Loading…
x
Reference in New Issue
Block a user