Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
raydac committed Apr 4, 2022
1 parent c15d082 commit 830fa53
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 41 deletions.
6 changes: 6 additions & 0 deletions TestROM/build
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ echo it needs ZASM 4.0.11 from http://k1.spdns.de/Develop/Projects/zasm-4.0/Dist

JAVA_EXE=/home/igorm/SDK/jdk-11/bin/java

rm -f $PWD/images/*.ZX*
rm -f $PWD/images/*.c*

$JAVA_EXE -jar $PWD/bin/zxsc.jar sliceImage $PWD/images/256.png
$JAVA_EXE -jar $PWD/bin/zxsc.jar sliceImage $PWD/images/512.png

Expand All @@ -24,3 +27,6 @@ $PWD/bin/zx0 $PWD/images/512c3.c3 $PWD/images/512C3.ZX0
TARGETROM=$PWD/../zxpoly-emul/src/main/resources/com/igormaznitsa/zxpoly/rom/zxpolytest.prom

$PWD/bin/zasm --z80 -l0 $PWD/zxpolytest.asm -o $TARGETROM

rm -f $PWD/images/*.ZX*
rm -f $PWD/images/*.c*
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public final class Motherboard implements ZxPolyConstants {
private static final Logger LOGGER = Logger.getLogger("MB");

private static final int SPEC256_GFX_CORES = 8;

private static final int NUMBER_OF_MODULES = 4;
private final ZxPolyModule[] modules;
private final Z80[] spec256GfxCores;
private final IoDevice[] ioDevices;
Expand All @@ -60,6 +60,8 @@ public final class Motherboard implements ZxPolyConstants {
private final TimingProfile timingProfile;
private final VolumeProfile soundLevels;
private final int[] audioLevels;
private final TimingProfile.UlaTact[] memoryTimings;
private final boolean attributePortFf;
private volatile int port3D00 = (int) System.nanoTime() & 0xFF; // simulate noise after turning on
private volatile boolean totalReset;
private volatile int resetCounter;
Expand All @@ -75,14 +77,7 @@ public final class Motherboard implements ZxPolyConstants {
private volatile boolean gfxLeveledOr = false;
private volatile boolean gfxLeveledAnd = false;
private int frameTiStatesCounter = 0;

private static boolean isContended(final int address, final int port7FFD) {
final int pageStart = address & 0xC000;
return pageStart == 0x4000 || (pageStart == 0xC000 && (port7FFD & 1) != 0);
}

private final TimingProfile.UlaTact[] memoryTimings;
private final boolean attributePortFf;
private boolean frameIntTriggered;

public Motherboard(
final VolumeProfile soundLevels,
Expand All @@ -102,9 +97,9 @@ public Motherboard(
this.soundLevels = soundLevels;
this.audioLevels = this.soundLevels.getLevels();
this.timingProfile = timingProfile;
this.modules = new ZxPolyModule[4];
this.modules = new ZxPolyModule[NUMBER_OF_MODULES];
final List<IoDevice> ioDevices = new ArrayList<>();
for (int i = 0; i < this.modules.length; i++) {
for (int i = 0; i < NUMBER_OF_MODULES; i++) {
this.modules[i] = new ZxPolyModule(timingProfile, this, Objects.requireNonNull(rom, "ROM must not be null"), i);
ioDevices.add(this.modules[i]);
}
Expand Down Expand Up @@ -160,6 +155,11 @@ public Motherboard(
}
}

private static boolean isContended(final int address, final int port7FFD) {
final int pageStart = address & 0xC000;
return pageStart == 0x4000 || (pageStart == 0xC000 && (port7FFD & 1) != 0);
}

private static boolean isUlaPort(final int port) {
return (port & 1) == 0;
}
Expand Down Expand Up @@ -228,7 +228,7 @@ public void resetAndRestoreRom(final RomData rom) {
}

public void set3D00(final int value, final boolean force) {
if (is3D00NotLocked() || force) {
if (isNotLockedPort3D00() || force) {
this.port3D00 = value;
LOGGER.log(Level.INFO, "set #3D00 to " + Utils.toHex(value));

Expand Down Expand Up @@ -278,7 +278,7 @@ public int getMappedCpuIndex() {
return (this.port3D00 >>> 5) & 3;
}

public boolean is3D00NotLocked() {
public boolean isNotLockedPort3D00() {
return (this.port3D00 & PORTw_ZXPOLY_BLOCK) == 0;
}

Expand Down Expand Up @@ -337,8 +337,6 @@ public void syncGfxCpuState(final Z80 sourceCpu) {
}
}

private boolean frameIntTriggered;

public int step(final boolean tstatesIntReached,
final boolean wallclockInt,
final boolean commonNmi,
Expand Down Expand Up @@ -463,7 +461,7 @@ public int step(final boolean tstatesIntReached,
throw new Error("Unexpected value");
}

if (is3D00NotLocked() && (zx0halt || zx1halt || zx2halt || zx3halt)) {
if (isNotLockedPort3D00() && (zx0halt || zx1halt || zx2halt || zx3halt)) {
// a cpu has met halt and we need process notification
if (zx0halt) {
doModuleHaltNotification(0);
Expand Down Expand Up @@ -644,21 +642,20 @@ private boolean haveModulesSamePositionAndMode() {

public void writeBusIo(final ZxPolyModule module, final int port, final int value) {
final int mappedCpu = getMappedCpuIndex();
final int moduleIndex = module.getModuleIndex();

if (this.getBoardMode() == BoardMode.ZXPOLY) {
if (moduleIndex == 0) {
if (module.isMaster()) {
if (port == PORTrw_ZXPOLY) {
set3D00(value, false);
} else {
if (mappedCpu > 0) {
final ZxPolyModule destmodule = this.modules[mappedCpu];
this._writeRam(destmodule.ramOffset2HeapAddress(destmodule.read7FFD(), port), value);
destmodule.prepareLocalNmi();
} else {
if (mappedCpu == 0) {
for (final IoDevice d : this.ioDevices) {
d.writeIo(module, port, value);
}
} else {
final ZxPolyModule targetModule = this.modules[mappedCpu];
this._writeRam(targetModule.ramOffset2HeapAddress(targetModule.read7FFD(), port), value);
targetModule.prepareLocalNmi();
}
}
} else {
Expand Down Expand Up @@ -688,11 +685,10 @@ public int readBusIo(final ZxPolyModule module, final int port) {
final int mappedCPU = getMappedCpuIndex();
int result = -1;

if (this.getBoardMode() == BoardMode.ZXPOLY &&
(module.getModuleIndex() == 0 && mappedCPU > 0)) {
final ZxPolyModule destmodule = modules[mappedCPU];
result = this._readRam(destmodule.ramOffset2HeapAddress(destmodule.read7FFD(), port));
destmodule.prepareLocalInt();
if (this.getBoardMode() == BoardMode.ZXPOLY && module.isMaster() && mappedCPU != 0 ) {
final ZxPolyModule destinationModule = this.modules[mappedCPU];
result = this._readRam(destinationModule.ramOffset2HeapAddress(destinationModule.read7FFD(), port));
destinationModule.prepareLocalInt();
} else {
IoDevice firstDetectedActiveDevice = null;
for (final IoDevice device : this.ioDevices) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public void writeIo(final ZxPolyModule module, final int port, final int value)
this.cpu.addTstates(this.board.contendPort(this.port7FFD.get(), port));

if (this.board.getBoardMode() == BoardMode.ZXPOLY) {
if (this.board.is3D00NotLocked()
if (this.board.isNotLockedPort3D00()
&& module.moduleIndex <= this.moduleIndex
&& !module.isTrdosActive()
) {
Expand Down Expand Up @@ -290,14 +290,14 @@ public boolean step(

if (boardMode == BoardMode.ZXPOLY) {
if (this.moduleIndex == 0) {
if (this.board.is3D00NotLocked() && !is7FFDLocked()) {
if (this.board.isNotLockedPort3D00() && !is7FFDLocked()) {
doInt = (this.port7FFD.get() & PORTw_ZX128_INTCPU0) == 0 && (commonInt || this.localInt);
} else {
doInt = commonInt || this.localInt;
}
} else {
doInt = (!this.activeRegisterReading && this.registerReadingCounter <= 0) &&
((!this.board.is3D00NotLocked() && commonInt) || this.localInt);
((!this.board.isNotLockedPort3D00() && commonInt) || this.localInt);
}
this.localInt = false;

Expand Down Expand Up @@ -503,7 +503,7 @@ public byte readMemory(

switch (this.board.getBoardMode()) {
case ZXPOLY: {
if (m1 && this.board.is3D00NotLocked() && this.registerReadingCounter == 0) {
if (m1 && this.board.isNotLockedPort3D00() && this.registerReadingCounter == 0) {
final int moduleStopAddress =
this.zxPolyRegsWritten.get(2) | (this.zxPolyRegsWritten.get(3) << 8);
this.stopAddressWait = address != 0 && address == moduleStopAddress;
Expand Down Expand Up @@ -750,7 +750,7 @@ public void writeMemory(final Z80 cpu, final int ctx, final int address, final b
final int ramOffsetInHeap = ramOffset2HeapAddress(value7FFD, address);

if (address < 0x4000) {
if (this.board.is3D00NotLocked() && (this.port7FFD.get() & PORTw_ZX128_ROMRAM) != 0) {
if (this.board.isNotLockedPort3D00() && (this.port7FFD.get() & PORTw_ZX128_ROMRAM) != 0) {
//RAM0
this.board.writeRam(this, ramOffsetInHeap, val);
}
Expand Down Expand Up @@ -936,7 +936,7 @@ public void writePort(final Z80 cpu, final int ctx, final int port, final byte d
if ((reg0 & ZXPOLY_wREG0_OUT_DISABLED) == 0 || port == PORTw_ZX128) {
if (port == PORTw_ZX128) { // full port decode
if (this.moduleIndex == 0
&& this.board.getMappedCpuIndex() > 0
&& this.board.getMappedCpuIndex() != 0
&& (this.zxPolyRegsWritten.get(1) & ZXPOLY_wREG1_WRITE_MAPPED_IO_7FFD) != 0) {
this.board.writeBusIo(this, port, val);
} else {
Expand Down Expand Up @@ -976,7 +976,7 @@ public void onInterrupt(Z80 cpu, int ctx, boolean nmi) {

@Override
public void preStep(final int frameTiStates, final boolean signalReset, final boolean tstatesIntReached,
boolean wallclockInt) {
boolean wallClockInt) {
if (signalReset) {
setStateForSystemReset();
}
Expand All @@ -990,7 +990,7 @@ public void postStep(int spentTstates) {
private void prepareWaitSignal() {
if (this.board.getBoardMode() == BoardMode.ZXPOLY) {
this.waitSignal =
this.stopAddressWait || (this.moduleIndex > 0 && this.board.isSlaveModulesInWaitMode());
this.stopAddressWait || (this.moduleIndex != 0 && this.board.isSlaveModulesInWaitMode());
} else {
this.waitSignal = false;
}
Expand All @@ -1006,7 +1006,7 @@ public int getReg1WrittenData() {
}

private void setStateForSystemReset() {
logger.info("Reset");
logger.info("Reset state module: " + this.moduleIndex);
this.intTiStatesCounter = -1;
this.nmiTiStatesCounter = -1;
this.port7FFD.set(0);
Expand All @@ -1019,11 +1019,8 @@ private void setStateForSystemReset() {
this.localNmi = false;

for (int i = 0; i < this.zxPolyRegsWritten.length(); i++) {
this.zxPolyRegsWritten.set(i, 0);
this.zxPolyRegsWritten.set(i, i == 0 ? this.moduleIndex << 1 : 0);
}

// set the intitial module memory offset in the heap
this.zxPolyRegsWritten.set(0, this.moduleIndex << 1);
}

public int getLastM1Address() {
Expand Down

0 comments on commit 830fa53

Please sign in to comment.