Implemented CF identification block

master
Marco Maccaferri 2020-08-08 12:14:43 +02:00
rodzic ebdad84204
commit af731530de
3 zmienionych plików z 86 dodań i 16 usunięć

Wyświetl plik

@ -10,5 +10,6 @@
<mapEntry key="UBUNTU_MENUPROXY" value="0"/> <mapEntry key="UBUNTU_MENUPROXY" value="0"/>
</mapAttribute> </mapAttribute>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.maccasoft.tools.Application"/> <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.maccasoft.tools.Application"/>
<stringAttribute key="org.eclipse.jdt.launching.MODULE_NAME" value="z80-tools"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="z80-tools"/> <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="z80-tools"/>
</launchConfiguration> </launchConfiguration>

Wyświetl plik

@ -15,6 +15,8 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import com.maccasoft.tools.internal.Utility;
import z80core.MemIoOps; import z80core.MemIoOps;
import z80core.Z80; import z80core.Z80;
@ -40,8 +42,9 @@ public class Machine extends MemIoOps {
public final static int CF_LBA2 = 0x15; public final static int CF_LBA2 = 0x15;
public final static int CF_LBA3 = 0x16; public final static int CF_LBA3 = 0x16;
public final static int CF_READ_SEC = 0x20; public final static byte CF_READ_SEC = 0x20;
public final static int CF_WRITE_SEC = 0x30; public final static byte CF_WRITE_SEC = 0x30;
public final static byte CF_IDENTIFY = (byte) 0xEC;
boolean page; boolean page;
byte[] rom; byte[] rom;
@ -52,6 +55,8 @@ public class Machine extends MemIoOps {
byte cfSecCount; byte cfSecCount;
File cfFile; File cfFile;
RandomAccessFile cf; RandomAccessFile cf;
byte[] cfIdentifyBuffer = new byte[512];
int cfDataCount;
Z80 proc; Z80 proc;
Thread thread; Thread thread;
@ -111,8 +116,19 @@ public class Machine extends MemIoOps {
public void start() { public void start() {
try { try {
System.arraycopy("EM-CF-00000001 ".getBytes(), 0, cfIdentifyBuffer, 20, 20); // Serial number
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
if (cfFile != null) { if (cfFile != null) {
cf = new RandomAccessFile(cfFile, "rw"); cf = new RandomAccessFile(cfFile, "rw");
long size = cf.length() / 512;
cfIdentifyBuffer[14] = (byte) (size >> 16);
cfIdentifyBuffer[15] = (byte) (size >> 24);
cfIdentifyBuffer[16] = (byte) (size);
cfIdentifyBuffer[17] = (byte) (size >> 8);
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -190,27 +206,47 @@ public class Machine extends MemIoOps {
switch (port & 0xFF) { switch (port & 0xFF) {
case CF_DATA: case CF_DATA:
if (cfCommand == CF_READ_SEC) { if (cfCommand == CF_READ_SEC) {
try { if (cfDataCount < 512 * cfSecCount) {
if (cf != null) { cfDataCount++;
return (byte) cf.read(); try {
if (cf != null) {
return (byte) cf.read();
}
} catch (IOException e) {
e.printStackTrace();
} }
} catch (IOException e) { return 0;
e.printStackTrace();
} }
} }
break; else if (cfCommand == CF_IDENTIFY) {
if (cfDataCount < cfIdentifyBuffer.length) {
return cfIdentifyBuffer[cfDataCount++];
}
return 0;
}
return 0;
case CF_SECCOUNT: case CF_SECCOUNT:
return cfSecCount & 0xFF; return cfSecCount & 0xFF;
case CF_STATUS: case CF_STATUS:
if (cfCommand == CF_WRITE_SEC || cfCommand == CF_READ_SEC) { if (cfCommand == CF_WRITE_SEC || cfCommand == CF_READ_SEC) {
return 0x48; // CF Ready, DRQ return 0x48; // CF Ready, DRQ
} }
else { else if (cfCommand == CF_IDENTIFY) {
return 0x40; // CF Ready if (cfDataCount < cfIdentifyBuffer.length) {
return 0x48; // CF Ready, DRQ
}
} }
return 0x40; // CF Ready
case CF_ERROR:
return 0x01; // No error
case CF_SECTOR:
case CF_CYL_LOW:
case CF_CYL_HI:
case CF_HEAD:
return 0;
} }
return port; return 0xFF;
} }
@Override @Override
@ -228,12 +264,15 @@ public class Machine extends MemIoOps {
switch (port & 0xFF) { switch (port & 0xFF) {
case CF_DATA: case CF_DATA:
if (cfCommand == CF_WRITE_SEC) { if (cfCommand == CF_WRITE_SEC) {
try { if (cfDataCount < 512 * cfSecCount) {
if (cf != null) { cfDataCount++;
cf.write(value & 0xFF); try {
if (cf != null) {
cf.write(value & 0xFF);
}
} catch (IOException e) {
e.printStackTrace();
} }
} catch (IOException e) {
e.printStackTrace();
} }
} }
break; break;
@ -248,6 +287,10 @@ public class Machine extends MemIoOps {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
cfDataCount = 0;
}
else if (cfCommand == CF_IDENTIFY) {
cfDataCount = 0;
} }
break; break;
case CF_LBA0: case CF_LBA0:

Wyświetl plik

@ -0,0 +1,26 @@
/*
* Copyright (c) 2020 Marco Maccaferri and others.
* All rights reserved.
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License v1.0 which accompanies this
* distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.maccasoft.tools.internal;
public class Utility {
public static byte[] getSwappedBytes(String s) {
byte[] result = s.getBytes();
for (int i = 0; i < result.length; i += 2) {
byte a = result[i];
result[i] = result[i + 1];
result[i + 1] = a;
}
return result;
}
}