add cdReadPIO

This commit is contained in:
Zack Buhman 2025-01-01 17:10:24 -06:00
parent 61cd2de8fa
commit 13c11391e0
4 changed files with 85 additions and 16 deletions

View File

@ -1,9 +1,43 @@
package example; package example;
import sega.dreamcast.gdrom.GdromProtocol; import sega.dreamcast.gdrom.GdromProtocol;
import sega.dreamcast.gdrom.G1IF;
import java.misc.Memory;
class GdromTest { class GdromTest {
static byte[] buf;
static {
buf = new byte[2048];
}
public static void g1_dma_start(int start_address, int transfer_length) {
int gdstar = start_address & ~(0b111 << 29);
int gdlen = (transfer_length + 31) & ~(31);
Memory.putU4(G1IF.GDAPRO, 0x8843407F);
Memory.putU4(G1IF.G1GDRC, 0x00001001);
Memory.putU4(G1IF.GDSTAR, gdstar);
Memory.putU4(G1IF.GDLEN, gdlen);
Memory.putU4(G1IF.GDDIR, 1);
Memory.putU4(G1IF.GDEN, 1);
Memory.putU4(G1IF.GDST, 1);
}
public static void main() { public static void main() {
GdromProtocol.tocGetDataTrackFad(); // assume gdrom is already unlocked
int data_track_fad = GdromProtocol.tocGetDataTrackFad();
int primary_volume_descriptor = data_track_fad + 16;
GdromProtocol.cdReadPIO(buf, primary_volume_descriptor, 1);
System.out.println("data:");
for (int i = 0; i < 16; i++) {
System.out.print(buf[i]);
System.out.print(' ');
}
System.out.println();
} }
} }

View File

@ -4,11 +4,10 @@ python gen_decoder.py > c/decode.inc.c
python regs/register_gen.py ../dreamcast/regs/holly.csv holly holly Holly 0xa05f8000 > sega/dreamcast/holly/Holly.java python regs/register_gen.py ../dreamcast/regs/holly.csv holly holly Holly 0xa05f8000 > sega/dreamcast/holly/Holly.java
python regs/register_gen.py ../dreamcast/regs/systembus.csv systembus systembus Systembus 0xa05f6800 > sega/dreamcast/systembus/Systembus.java python regs/register_gen.py ../dreamcast/regs/systembus.csv systembus systembus Systembus 0xa05f6800 > sega/dreamcast/systembus/Systembus.java
python regs/register_gen.py ../dreamcast/regs/systembus.csv maple_if maple MapleIF 0xa05f6c00 > sega/dreamcast/maple/MapleIF.java python regs/register_gen.py ../dreamcast/regs/systembus.csv maple_if maple MapleIF 0xa05f6c00 > sega/dreamcast/maple/MapleIF.java
python regs/register_gen.py ../dreamcast/regs/systembus.csv gdrom_if gdrom GdromIF 0xa05f7000 > sega/dreamcast/gdrom/GdromIF.java python regs/register_gen.py ../dreamcast/regs/gdrom.csv gdrom gdrom Gdrom 0xa05f7000 > sega/dreamcast/gdrom/Gdrom.java
python regs/register_gen.py ../dreamcast/regs/systembus.csv g1_if gdrom G1IF 0xa05f7400 > sega/dreamcast/gdrom/G1IF.java python regs/register_gen.py ../dreamcast/regs/systembus.csv g1_if gdrom G1IF 0xa05f7400 > sega/dreamcast/gdrom/G1IF.java
python regs/register_gen.py ../dreamcast/regs/systembus.csv g2_if g2_if G2IF 0xa05f7800 > sega/dreamcast/g2_if/G2IF.java python regs/register_gen.py ../dreamcast/regs/systembus.csv g2_if g2_if G2IF 0xa05f7800 > sega/dreamcast/g2_if/G2IF.java
python regs/register_gen.py ../dreamcast/regs/systembus.csv pvr_if pvr_if PVRIF 0xa05f7c00 > sega/dreamcast/pvr_if/PVRIF.java python regs/register_gen.py ../dreamcast/regs/systembus.csv pvr_if pvr_if PVRIF 0xa05f7c00 > sega/dreamcast/pvr_if/PVRIF.java
python regs/register_gen.py ../dreamcast/regs/gdrom.csv gdrom gdrom Gdrom 0xa05f7000 > sega/dreamcast/gdrom/Gdrom.java
python regs/bits_gen.py ../dreamcast/regs/core_bits.csv holly CoreBits > sega/dreamcast/holly/CoreBits.java python regs/bits_gen.py ../dreamcast/regs/core_bits.csv holly CoreBits > sega/dreamcast/holly/CoreBits.java
python regs/bits_gen.py ../dreamcast/regs/ta_bits.csv holly TABits > sega/dreamcast/holly/TABits.java python regs/bits_gen.py ../dreamcast/regs/ta_bits.csv holly TABits > sega/dreamcast/holly/TABits.java

View File

@ -1,2 +0,0 @@
package sega.dreamcast.gdrom;

View File

@ -5,7 +5,7 @@ import sega.dreamcast.gdrom.GdromCommandPacketFormat;
public class GdromProtocol { public class GdromProtocol {
static GdromCommandPacketFormat.get_toc get_toc_command; static GdromCommandPacketFormat.get_toc get_toc_command;
static short[] toc_buf; static byte[] toc_buf;
static GdromCommandPacketFormat.cd_read cd_read_command; static GdromCommandPacketFormat.cd_read cd_read_command;
@ -15,7 +15,7 @@ public class GdromProtocol {
get_toc_command = new GdromCommandPacketFormat.get_toc(single_density_area, get_toc_command = new GdromCommandPacketFormat.get_toc(single_density_area,
maximum_toc_length); maximum_toc_length);
toc_buf = new short[maximum_toc_length >> 1]; toc_buf = new byte[maximum_toc_length];
cd_read_command = new GdromCommandPacketFormat.cd_read(0, 0, 0); cd_read_command = new GdromCommandPacketFormat.cd_read(0, 0, 0);
} }
@ -53,18 +53,18 @@ public class GdromProtocol {
} }
} }
public static void readData(short[] buf, int length) { public static void readData(byte[] buf, int length) {
for (int i = 0; i < (length >> 1); i++) { for (int i = 0; i < (length >> 1); i++) {
buf[i] = (short)Memory.getU2(Gdrom.data); int data = Memory.getU2(Gdrom.data);
buf[i * 2] = (byte)((data >> 8) & 0xff);
buf[i * 2 + 1] = (byte)(data & 0xff);
} }
} }
public static int getFad(short[] buf, int i) { public static int getFad(byte[] buf, int i) {
int low = toc_buf[i * 2] & 0xffff; int i0 = buf[0];
int high = toc_buf[i * 2 + 1] & 0xffff; int i1 = buf[1];
int i0 = (high >> 8) & 0xff; int i2 = buf[2];
int i1 = high & 0xff;
int i2 = (low >> 8) & 0xff;
//int i3 = low & 0xff; //int i3 = low & 0xff;
return (i2 << 16) | (i1 << 8) | i0; return (i2 << 16) | (i1 << 8) | i0;
@ -110,12 +110,50 @@ public class GdromProtocol {
cd_read_command.transfer_length2 = (transfer_length >> 0) & 0xff; cd_read_command.transfer_length2 = (transfer_length >> 0) & 0xff;
} }
public static void cdReadDMA(int starting_address, int transfer_length) { // transfer_length is in sectors
public static void cdReadPIO(byte[] buf, int starting_address, int transfer_length) {
int data_select = 0b0010; // data int data_select = 0b0010; // data
int expected_data_type = 0b100; // XA mode 2 form 1 int expected_data_type = 0b100; // XA mode 2 form 1
int parameter_type = 0b0; // FAD specified int parameter_type = 0b0; // FAD specified
int data = (data_select << 4) | (expected_data_type << 1) | (parameter_type); int data = (data_select << 4) | (expected_data_type << 1) | (parameter_type);
cdReadSet(data, starting_address, transfer_length);
packetCommand(cd_read_command, false); // PIO mode
int length = 0;
System.out.println("cdReadPIO");
while (true) {
int status = Memory.getU1(Gdrom.status);
if (GdromBits.status__drq(status) == 0)
break;
int low = Memory.getU1(Gdrom.byte_count_low);
int high = Memory.getU1(Gdrom.byte_count_high);
int byte_count = ((high & 0xff) << 8) | (low & 0xff);
readData(buf, byte_count);
length += byte_count;
}
int status = Memory.getU1(Gdrom.status);
System.out.print("status: ");
System.out.println(status);
System.out.print("read length: ");
System.out.println(length);
}
// transfer_length is in sectors
public static void cdReadDMA(int starting_address, int transfer_length) {
int data_select = 0b0010; // data
int expected_data_type = 0b100; // XA mode 2 form 1
int parameter_type = 0b0; // FAD specified
int data = (data_select << 4) | (expected_data_type << 1) | (parameter_type);
System.out.println("cdReadDMA");
cdReadSet(data, starting_address, transfer_length); cdReadSet(data, starting_address, transfer_length);
packetCommand(cd_read_command, true); // DMA mode packetCommand(cd_read_command, true); // DMA mode
} }