Disable compact flash module if disk file is not available

master
Marco Maccaferri 2020-08-13 08:02:10 +02:00
rodzic 2b886ecb47
commit 66cafbaf1a
1 zmienionych plików z 91 dodań i 80 usunięć

Wyświetl plik

@ -120,7 +120,7 @@ public class Machine extends MemIoOps {
System.arraycopy(Utility.getSwappedBytes("1.00 "), 0, cfIdentifyBuffer, 46, 8); // Firmware version System.arraycopy(Utility.getSwappedBytes("1.00 "), 0, cfIdentifyBuffer, 46, 8); // Firmware version
System.arraycopy(Utility.getSwappedBytes("EMULATED CF CARD "), 0, cfIdentifyBuffer, 54, 40); // Card model System.arraycopy(Utility.getSwappedBytes("EMULATED CF CARD "), 0, cfIdentifyBuffer, 54, 40); // Card model
if (cfFile != null) { if (cfFile != null && cfFile.exists()) {
cf = new RandomAccessFile(cfFile, "rw"); cf = new RandomAccessFile(cfFile, "rw");
long size = cf.length() >> 9; long size = cf.length() >> 9;
@ -197,57 +197,61 @@ public class Machine extends MemIoOps {
tstates += 4; // 4 clocks for read byte from bus tstates += 4; // 4 clocks for read byte from bus
clockTimeNs += clockPeriodNs * 4; clockTimeNs += clockPeriodNs * 4;
if ((port & 0xFF) == tmsRam) { port &= 0xFF;
if (port == tmsRam) {
return tms9918.inRam(); return tms9918.inRam();
} }
if ((port & 0xFF) == tmsReg) { if (port == tmsReg) {
return tms9918.inReg(); return tms9918.inReg();
} }
switch (port & 0xFF) { if (cf != null) {
case CF_DATA: switch (port) {
if (cfCommand == CF_READ_SEC) { case CF_DATA:
if (cfDataCount < 512 * cfSecCount) { if (cfCommand == CF_READ_SEC) {
cfDataCount++; if (cfDataCount < 512 * cfSecCount) {
try { cfDataCount++;
if (cf != null) { try {
return (byte) cf.read(); if (cf != null) {
return (byte) cf.read();
}
} catch (IOException e) {
e.printStackTrace();
} }
} catch (IOException e) { return 0x00;
e.printStackTrace();
} }
return 0;
} }
} else if (cfCommand == CF_IDENTIFY) {
else if (cfCommand == CF_IDENTIFY) { if (cfDataCount < cfIdentifyBuffer.length) {
if (cfDataCount < cfIdentifyBuffer.length) { return cfIdentifyBuffer[cfDataCount++];
return cfIdentifyBuffer[cfDataCount++]; }
return 0x00;
} }
return 0; return 0x00;
} case CF_SECCOUNT:
return 0; return cfSecCount & 0xFF;
case CF_SECCOUNT: case CF_STATUS:
return cfSecCount & 0xFF; if (cfCommand == CF_WRITE_SEC || cfCommand == CF_READ_SEC) {
case CF_STATUS:
if (cfCommand == CF_WRITE_SEC || cfCommand == CF_READ_SEC) {
return 0x48; // CF Ready, DRQ
}
else if (cfCommand == CF_IDENTIFY) {
if (cfDataCount < cfIdentifyBuffer.length) {
return 0x48; // CF Ready, DRQ return 0x48; // CF Ready, DRQ
} }
} else if (cfCommand == CF_IDENTIFY) {
return 0x40; // CF Ready if (cfDataCount < cfIdentifyBuffer.length) {
case CF_ERROR: return 0x48; // CF Ready, DRQ
return 0x01; // No error }
case CF_SECTOR: }
case CF_CYL_LOW: return 0x40; // CF Ready
case CF_CYL_HI: case CF_ERROR:
case CF_HEAD: return 0x01; // No error
return 0; case CF_SECTOR:
case CF_CYL_LOW:
case CF_CYL_HI:
case CF_HEAD:
return 0x00;
}
} }
return port & 0xFF; return port;
} }
@Override @Override
@ -255,64 +259,71 @@ public class Machine extends MemIoOps {
tstates += 4; // 4 clocks for write byte to bus tstates += 4; // 4 clocks for write byte to bus
clockTimeNs += clockPeriodNs * 4; clockTimeNs += clockPeriodNs * 4;
if ((port & 0xFF) == tmsRam) { port &= 0xFF;
value &= 0xFF;
if (port == tmsRam) {
tms9918.outRam(value); tms9918.outRam(value);
} }
if ((port & 0xFF) == tmsReg) { if (port == tmsReg) {
tms9918.outReg(value); tms9918.outReg(value);
} }
switch (port & 0xFF) { if (cf != null) {
case CF_DATA: switch (port) {
if (cfCommand == CF_WRITE_SEC) { case CF_DATA:
if (cfDataCount < 512 * cfSecCount) { if (cfCommand == CF_WRITE_SEC) {
cfDataCount++; if (cfDataCount < 512 * cfSecCount) {
cfDataCount++;
try {
if (cf != null) {
cf.write(value & 0xFF);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
break;
case CF_COMMAND:
cfCommand = (byte) value;
if (cfCommand == CF_WRITE_SEC || cfCommand == CF_READ_SEC) {
try { try {
long addr = ((cfLBA[3] & 0x0F) << 24) | ((cfLBA[2] & 0xFF) << 16) | ((cfLBA[1] & 0xFF) << 8) | (cfLBA[0] & 0xFF);
if (cf != null) { if (cf != null) {
cf.write(value & 0xFF); cf.seek(addr << 9);
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
cfDataCount = 0;
} }
} else if (cfCommand == CF_IDENTIFY) {
break; cfDataCount = 0;
case CF_COMMAND:
cfCommand = (byte) value;
if (cfCommand == CF_WRITE_SEC || cfCommand == CF_READ_SEC) {
try {
long addr = ((cfLBA[3] & 0x0F) << 24) | ((cfLBA[2] & 0xFF) << 16) | ((cfLBA[1] & 0xFF) << 8) | (cfLBA[0] & 0xFF);
if (cf != null) {
cf.seek(addr << 9);
}
} catch (IOException e) {
e.printStackTrace();
} }
cfDataCount = 0; break;
case CF_LBA0:
cfLBA[0] = (byte) value;
break;
case CF_LBA1:
cfLBA[1] = (byte) value;
break;
case CF_LBA2:
cfLBA[2] = (byte) value;
break;
case CF_LBA3: {
cfLBA[3] = (byte) value;
break;
} }
else if (cfCommand == CF_IDENTIFY) { case CF_SECCOUNT:
cfDataCount = 0; cfSecCount = (byte) value;
} break;
break;
case CF_LBA0:
cfLBA[0] = (byte) value;
break;
case CF_LBA1:
cfLBA[1] = (byte) value;
break;
case CF_LBA2:
cfLBA[2] = (byte) value;
break;
case CF_LBA3: {
cfLBA[3] = (byte) value;
break;
} }
case CF_SECCOUNT: }
cfSecCount = (byte) value;
break;
switch (port) {
case 0x38: // ROM page case 0x38: // ROM page
rom_paged = (value & 0xFF) != 0x01; rom_paged = value != 0x01;
break; break;
} }
} }