mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-19 10:36:43 +00:00
Bug fixes related to floppy drive
This commit is contained in:
parent
cfb8050cee
commit
8701007ad9
@ -23,8 +23,6 @@ public class CubotFloppyDrive extends CpuHardware {
|
|||||||
|
|
||||||
public CubotFloppyDrive(Cubot cubot) {
|
public CubotFloppyDrive(Cubot cubot) {
|
||||||
this.cubot = cubot;
|
this.cubot = cubot;
|
||||||
|
|
||||||
this.floppyDisk = new FloppyDisk();//todo remove
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -44,6 +42,7 @@ public class CubotFloppyDrive extends CpuHardware {
|
|||||||
if (floppyDisk == null) {
|
if (floppyDisk == null) {
|
||||||
getCpu().getRegisterSet().getRegister("B").setValue(0);
|
getCpu().getRegisterSet().getRegister("B").setValue(0);
|
||||||
} else {
|
} else {
|
||||||
|
if (cubot.spendEnergy(1)) {
|
||||||
getCpu().getRegisterSet().getRegister("B").setValue(1);
|
getCpu().getRegisterSet().getRegister("B").setValue(1);
|
||||||
|
|
||||||
int x = getCpu().getRegisterSet().getRegister("X").getValue();
|
int x = getCpu().getRegisterSet().getRegister("X").getValue();
|
||||||
@ -51,12 +50,14 @@ public class CubotFloppyDrive extends CpuHardware {
|
|||||||
|
|
||||||
floppyDisk.readSector(x, cubot.getParent().getCpu().getMemory(), y);
|
floppyDisk.readSector(x, cubot.getParent().getCpu().getMemory(), y);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} else if (a == WRITE_SECTOR) {
|
} else if (a == WRITE_SECTOR) {
|
||||||
if (floppyDisk == null) {
|
if (floppyDisk == null) {
|
||||||
getCpu().getRegisterSet().getRegister("B").setValue(0);
|
getCpu().getRegisterSet().getRegister("B").setValue(0);
|
||||||
} else {
|
} else {
|
||||||
|
if (cubot.spendEnergy(1)) {
|
||||||
getCpu().getRegisterSet().getRegister("B").setValue(1);
|
getCpu().getRegisterSet().getRegister("B").setValue(1);
|
||||||
|
|
||||||
int x = getCpu().getRegisterSet().getRegister("X").getValue();
|
int x = getCpu().getRegisterSet().getRegister("X").getValue();
|
||||||
@ -65,6 +66,7 @@ public class CubotFloppyDrive extends CpuHardware {
|
|||||||
floppyDisk.writeSector(x, cubot.getParent().getCpu().getMemory(), y);
|
floppyDisk.writeSector(x, cubot.getParent().getCpu().getMemory(), y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ package net.simon987.cubotplugin;
|
|||||||
|
|
||||||
import net.simon987.server.assembly.Memory;
|
import net.simon987.server.assembly.Memory;
|
||||||
import net.simon987.server.io.JSONSerialisable;
|
import net.simon987.server.io.JSONSerialisable;
|
||||||
import net.simon987.server.logging.LogManager;
|
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,9 +38,8 @@ public class FloppyDisk implements JSONSerialisable {
|
|||||||
*/
|
*/
|
||||||
public boolean readSector(int sector, Memory cpuMemory, int ramAddress) {
|
public boolean readSector(int sector, Memory cpuMemory, int ramAddress) {
|
||||||
|
|
||||||
cpuMemory.write(ramAddress, memory.getBytes(), sector * 512, 1024);
|
if (sector <= 1440) {
|
||||||
|
cpuMemory.write(ramAddress, memory.getBytes(), sector * 1024, 1024);
|
||||||
LogManager.LOGGER.fine("Read 512 words from floppy sector:" + sector + " to memory addr:" + ramAddress);
|
|
||||||
|
|
||||||
//Calculate seek time
|
//Calculate seek time
|
||||||
int deltaTrack = (sector / 80) - rwHeadTrack;
|
int deltaTrack = (sector / 80) - rwHeadTrack;
|
||||||
@ -53,6 +51,9 @@ public class FloppyDisk implements JSONSerialisable {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write 512 words to the specified sector from cpu memory at the specified address
|
* Write 512 words to the specified sector from cpu memory at the specified address
|
||||||
@ -64,10 +65,9 @@ public class FloppyDisk implements JSONSerialisable {
|
|||||||
*/
|
*/
|
||||||
public boolean writeSector(int sector, Memory cpuMemory, int ramAddress) {
|
public boolean writeSector(int sector, Memory cpuMemory, int ramAddress) {
|
||||||
|
|
||||||
|
if (sector <= 1440) {
|
||||||
memory.write(sector * 512, cpuMemory.getBytes(), ramAddress * 2, 1024);
|
memory.write(sector * 512, cpuMemory.getBytes(), ramAddress * 2, 1024);
|
||||||
|
|
||||||
LogManager.LOGGER.fine("Wrote 512 words to floppy sector:" + sector + " from memory addr:" + ramAddress);
|
|
||||||
|
|
||||||
//Calculate seek time
|
//Calculate seek time
|
||||||
int deltaTrack = (sector / 80) - rwHeadTrack;
|
int deltaTrack = (sector / 80) - rwHeadTrack;
|
||||||
|
|
||||||
@ -77,6 +77,9 @@ public class FloppyDisk implements JSONSerialisable {
|
|||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,8 +108,14 @@ public class GameServer implements Runnable {
|
|||||||
for (User user : users_) {
|
for (User user : users_) {
|
||||||
|
|
||||||
if(user.getCpu() != null){
|
if(user.getCpu() != null){
|
||||||
|
try {
|
||||||
user.getCpu().reset();
|
user.getCpu().reset();
|
||||||
user.getCpu().execute();
|
user.getCpu().execute();
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogManager.LOGGER.severe("Error executing " + user.getUsername() + "'s code");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ public class Memory implements Target, JSONSerialisable {
|
|||||||
offset = (char)offset * 2;
|
offset = (char)offset * 2;
|
||||||
|
|
||||||
|
|
||||||
if (offset + count > this.bytes.length || count < 0 || offset < 0) {
|
if (offset + count > this.bytes.length || count < 0 || offset < 0 || srcOffset >= bytes.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user