diff --git a/c/classpath.h b/c/classpath.h index 53009a4..25b8f66 100644 --- a/c/classpath.h +++ b/c/classpath.h @@ -1,6 +1,12 @@ #include "example/DreamcastVideo2.class.h" #include "example/DreamcastVideo.class.h" +#include "example/GdromExtentReader.class.h" #include "example/GdromTest.class.h" +#include "filesystem/iso9660/ByteParser.class.h" +#include "filesystem/iso9660/DirectoryRecord.class.h" +#include "filesystem/iso9660/ExtentReader.class.h" +#include "filesystem/iso9660/PrimaryVolumeDescriptor.class.h" +#include "filesystem/iso9660/VolumeParser.class.h" #include "java/io/PrintStream.class.h" #include "java/lang/Boolean.class.h" #include "java/lang/Byte.class.h" diff --git a/c/classpath.inc.c b/c/classpath.inc.c index 900e62d..4a4a92f 100644 --- a/c/classpath.inc.c +++ b/c/classpath.inc.c @@ -1,6 +1,12 @@ (const uint8_t *)&_binary_example_DreamcastVideo2_class_start, (const uint8_t *)&_binary_example_DreamcastVideo_class_start, +(const uint8_t *)&_binary_example_GdromExtentReader_class_start, (const uint8_t *)&_binary_example_GdromTest_class_start, +(const uint8_t *)&_binary_filesystem_iso9660_ByteParser_class_start, +(const uint8_t *)&_binary_filesystem_iso9660_DirectoryRecord_class_start, +(const uint8_t *)&_binary_filesystem_iso9660_ExtentReader_class_start, +(const uint8_t *)&_binary_filesystem_iso9660_PrimaryVolumeDescriptor_class_start, +(const uint8_t *)&_binary_filesystem_iso9660_VolumeParser_class_start, (const uint8_t *)&_binary_java_io_PrintStream_class_start, (const uint8_t *)&_binary_java_lang_Boolean_class_start, (const uint8_t *)&_binary_java_lang_Byte_class_start, diff --git a/classpath.mk b/classpath.mk index 8a148a4..cccec1f 100644 --- a/classpath.mk +++ b/classpath.mk @@ -1,7 +1,13 @@ CLASS_PATH = \ example/DreamcastVideo2.class.o \ example/DreamcastVideo.class.o \ + example/GdromExtentReader.class.o \ example/GdromTest.class.o \ + filesystem/iso9660/ByteParser.class.o \ + filesystem/iso9660/DirectoryRecord.class.o \ + filesystem/iso9660/ExtentReader.class.o \ + filesystem/iso9660/PrimaryVolumeDescriptor.class.o \ + filesystem/iso9660/VolumeParser.class.o \ java/io/PrintStream.class.o \ java/lang/Boolean.class.o \ java/lang/Byte.class.o \ diff --git a/example/GdromExtentReader.class.h b/example/GdromExtentReader.class.h new file mode 100644 index 0000000..4eb6791 --- /dev/null +++ b/example/GdromExtentReader.class.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern C { +#endif + +extern uint32_t _binary_example_GdromExtentReader_class_start __asm("_binary_example_GdromExtentReader_class_start"); +extern uint32_t _binary_example_GdromExtentReader_class_end __asm("_binary_example_GdromExtentReader_class_end"); +extern uint32_t _binary_example_GdromExtentReader_class_size __asm("_binary_example_GdromExtentReader_class_size"); + +#ifdef __cplusplus +} +#endif diff --git a/example/GdromTest.java b/example/GdromTest.java index 44a72c1..ca909af 100644 --- a/example/GdromTest.java +++ b/example/GdromTest.java @@ -3,6 +3,17 @@ package example; import sega.dreamcast.gdrom.GdromProtocol; import sega.dreamcast.gdrom.G1IF; import java.misc.Memory; +import filesystem.iso9660.VolumeParser; +import filesystem.iso9660.ExtentReader; + +class GdromExtentReader implements ExtentReader { + public void readInto(byte[] buf, int extent) { + int starting_address = extent + 150; + System.out.print("starting_address: "); + System.out.println(starting_address); + GdromProtocol.cdReadPIO(buf, starting_address, 1); + } +} class GdromTest { static byte[] buf; @@ -29,15 +40,20 @@ class GdromTest { int data_track_fad = GdromProtocol.tocGetDataTrackFad(); - int primary_volume_descriptor = data_track_fad + 16; - - GdromProtocol.cdReadPIO(buf, primary_volume_descriptor, 1); + //GdromProtocol.cdReadPIO(buf, primary_volume_descriptor, 1); + GdromExtentReader reader = new GdromExtentReader(); + VolumeParser parser = new VolumeParser(data_track_fad - 150, reader); + System.out.println("::parser parse::"); + parser.parse(); + /* System.out.println("data:"); for (int i = 0; i < 16; i++) { - System.out.print(buf[i]); - System.out.print(' '); + System.out.print(((int)buf[i]) & 0xff); + System.out.print(" "); } System.out.println(); + */ + } } diff --git a/filesystem/iso9660/ByteParser.class.h b/filesystem/iso9660/ByteParser.class.h new file mode 100644 index 0000000..f4a7acf --- /dev/null +++ b/filesystem/iso9660/ByteParser.class.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern C { +#endif + +extern uint32_t _binary_filesystem_iso9660_ByteParser_class_start __asm("_binary_filesystem_iso9660_ByteParser_class_start"); +extern uint32_t _binary_filesystem_iso9660_ByteParser_class_end __asm("_binary_filesystem_iso9660_ByteParser_class_end"); +extern uint32_t _binary_filesystem_iso9660_ByteParser_class_size __asm("_binary_filesystem_iso9660_ByteParser_class_size"); + +#ifdef __cplusplus +} +#endif diff --git a/filesystem/iso9660/DirectoryRecord.class.h b/filesystem/iso9660/DirectoryRecord.class.h new file mode 100644 index 0000000..48c637a --- /dev/null +++ b/filesystem/iso9660/DirectoryRecord.class.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern C { +#endif + +extern uint32_t _binary_filesystem_iso9660_DirectoryRecord_class_start __asm("_binary_filesystem_iso9660_DirectoryRecord_class_start"); +extern uint32_t _binary_filesystem_iso9660_DirectoryRecord_class_end __asm("_binary_filesystem_iso9660_DirectoryRecord_class_end"); +extern uint32_t _binary_filesystem_iso9660_DirectoryRecord_class_size __asm("_binary_filesystem_iso9660_DirectoryRecord_class_size"); + +#ifdef __cplusplus +} +#endif diff --git a/filesystem/iso9660/ExtentReader.class.h b/filesystem/iso9660/ExtentReader.class.h new file mode 100644 index 0000000..b2d6ffc --- /dev/null +++ b/filesystem/iso9660/ExtentReader.class.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern C { +#endif + +extern uint32_t _binary_filesystem_iso9660_ExtentReader_class_start __asm("_binary_filesystem_iso9660_ExtentReader_class_start"); +extern uint32_t _binary_filesystem_iso9660_ExtentReader_class_end __asm("_binary_filesystem_iso9660_ExtentReader_class_end"); +extern uint32_t _binary_filesystem_iso9660_ExtentReader_class_size __asm("_binary_filesystem_iso9660_ExtentReader_class_size"); + +#ifdef __cplusplus +} +#endif diff --git a/filesystem/iso9660/ExtentReader.java b/filesystem/iso9660/ExtentReader.java index e20190b..63bfdf9 100644 --- a/filesystem/iso9660/ExtentReader.java +++ b/filesystem/iso9660/ExtentReader.java @@ -1,5 +1,5 @@ package filesystem.iso9660; -interface ExtentReader { +public interface ExtentReader { public abstract void readInto(byte[] buf, int extent); } diff --git a/filesystem/iso9660/PrimaryVolumeDescriptor.class.h b/filesystem/iso9660/PrimaryVolumeDescriptor.class.h new file mode 100644 index 0000000..e9d9e55 --- /dev/null +++ b/filesystem/iso9660/PrimaryVolumeDescriptor.class.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern C { +#endif + +extern uint32_t _binary_filesystem_iso9660_PrimaryVolumeDescriptor_class_start __asm("_binary_filesystem_iso9660_PrimaryVolumeDescriptor_class_start"); +extern uint32_t _binary_filesystem_iso9660_PrimaryVolumeDescriptor_class_end __asm("_binary_filesystem_iso9660_PrimaryVolumeDescriptor_class_end"); +extern uint32_t _binary_filesystem_iso9660_PrimaryVolumeDescriptor_class_size __asm("_binary_filesystem_iso9660_PrimaryVolumeDescriptor_class_size"); + +#ifdef __cplusplus +} +#endif diff --git a/filesystem/iso9660/TestExtentReader.java b/filesystem/iso9660/TestExtentReader.java index 0850e1c..b9a83b6 100644 --- a/filesystem/iso9660/TestExtentReader.java +++ b/filesystem/iso9660/TestExtentReader.java @@ -6,7 +6,6 @@ import java.io.IOException; class TestExtentReader implements ExtentReader { byte[] all_bytes; - public TestExtentReader() { try { all_bytes = Files.readAllBytes(Paths.get("classes/classes.iso")); diff --git a/filesystem/iso9660/VolumeParser.class.h b/filesystem/iso9660/VolumeParser.class.h new file mode 100644 index 0000000..f0e1358 --- /dev/null +++ b/filesystem/iso9660/VolumeParser.class.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern C { +#endif + +extern uint32_t _binary_filesystem_iso9660_VolumeParser_class_start __asm("_binary_filesystem_iso9660_VolumeParser_class_start"); +extern uint32_t _binary_filesystem_iso9660_VolumeParser_class_end __asm("_binary_filesystem_iso9660_VolumeParser_class_end"); +extern uint32_t _binary_filesystem_iso9660_VolumeParser_class_size __asm("_binary_filesystem_iso9660_VolumeParser_class_size"); + +#ifdef __cplusplus +} +#endif diff --git a/filesystem/iso9660/VolumeParser.java b/filesystem/iso9660/VolumeParser.java index 33356d2..4aea3ea 100644 --- a/filesystem/iso9660/VolumeParser.java +++ b/filesystem/iso9660/VolumeParser.java @@ -2,9 +2,9 @@ package filesystem.iso9660; import filesystem.iso9660.PrimaryVolumeDescriptor; import filesystem.iso9660.DirectoryRecord; -import filesystem.iso9660.TestExtentReader; public class VolumeParser { + int fad; byte[] buf; DirectoryRecord dr; ExtentReader reader; @@ -102,8 +102,10 @@ public class VolumeParser { } public void parse() { - int pvd_extent = 16; + int pvd_extent = this.fad + 16; + System.out.print("pvd_extent: "); + System.out.println(pvd_extent); reader.readInto(buf, pvd_extent); printStandardIdentifier(); @@ -119,15 +121,20 @@ public class VolumeParser { walkDirectory(extent, num_extents, 0); } - public VolumeParser(ExtentReader reader) { + public VolumeParser(int fad, ExtentReader reader) { + this.fad = fad; this.reader = reader; this.buf = new byte[2048]; this.dr = new DirectoryRecord(this.buf, 0); } + /* + import filesystem.iso9660.TestExtentReader; + public static void main(String[] args) { TestExtentReader reader = new TestExtentReader(); VolumeParser parser = new VolumeParser(reader); parser.parse(); } + */ } diff --git a/generate_classpath.sh b/generate_classpath.sh index 7e531a4..6972818 100644 --- a/generate_classpath.sh +++ b/generate_classpath.sh @@ -1,4 +1,4 @@ -function make_class () { +function java_to_class () { while read line; do echo "${line%.java}.class" done @@ -68,10 +68,20 @@ function classpath_h () { set -e -find sega/ java/ -name '*.class' -exec rm -f {} \; -make -j$(nproc) -f Makefile.dreamcast.mk $(find model/ example/ sega/ java/ -name '*.java' | make_class) -find model/ example/ sega/ java/ -name '*.class' | sort | rename_class_files -find model/ example/ sega/ java/ -name '*.class' | sort | classpath_mk -find model/ example/ sega/ java/ -name '*.class' | sort | classpath_inc_c -find model/ example/ sega/ java/ -name '*.class' | sort | make_header -find model/ example/ sega/ java/ -name '*.class' | sort | classpath_h +function find_classes () { + find model/ example/ sega/ java/ filesystem/ -name '*.class' -not -name 'Test*' | sort +} + +function find_sources () { + find model/ example/ sega/ java/ filesystem/ -name '*.java' -not -name 'Test*' | sort +} + +find sega/ java/ filesystem/ -name '*.class' -exec rm -f {} \; + +make -j$(nproc) -f Makefile.dreamcast.mk $(find_sources | java_to_class) + +find_classes | rename_class_files +find_classes | classpath_mk +find_classes | classpath_inc_c +find_classes | make_header +find_classes | classpath_h diff --git a/java/io/PrintStream.java b/java/io/PrintStream.java index ad867cb..4af2b96 100644 --- a/java/io/PrintStream.java +++ b/java/io/PrintStream.java @@ -24,6 +24,10 @@ public class PrintStream write(String.valueOf(b)); } + public void print(char c) { + write(String.valueOf(c)); + } + public void print(int i) { write(String.valueOf(i)); } @@ -58,6 +62,11 @@ public class PrintStream write(newline); } + public void println(char c) { + write(String.valueOf(c)); + write(newline); + } + public void println(int i) { write(String.valueOf(i)); write(newline); diff --git a/java/lang/String.java b/java/lang/String.java index 3bdcd2f..78f77f0 100644 --- a/java/lang/String.java +++ b/java/lang/String.java @@ -31,6 +31,10 @@ public class String { return b ? "true" : "false"; } + public static String valueOf(char c) { + return new String(new byte[] { (byte)c }); + } + public static String valueOf(int i) { return Integer.toString(i); } diff --git a/sega/dreamcast/gdrom/GdromProtocol.java b/sega/dreamcast/gdrom/GdromProtocol.java index 80bdddb..176d39a 100644 --- a/sega/dreamcast/gdrom/GdromProtocol.java +++ b/sega/dreamcast/gdrom/GdromProtocol.java @@ -36,13 +36,13 @@ public class GdromProtocol { Memory.putU1(Gdrom.command, GdromBits.command__code__packet_command); - System.out.println("words:"); + //System.out.println("words:"); for (int i = 0; i < 6; i++) { int i0 = command.getByte(i * 2); int i1 = command.getByte(i * 2 + 1); // little endian int word = ((i1 & 0xff) << 8) | (i0 & 0xff); - System.out.println(word); + //System.out.println(word); Memory.putU2(Gdrom.data, word); } @@ -56,18 +56,18 @@ public class GdromProtocol { public static void readData(byte[] buf, int length) { for (int i = 0; i < (length >> 1); i++) { int data = Memory.getU2(Gdrom.data); - buf[i * 2] = (byte)((data >> 8) & 0xff); - buf[i * 2 + 1] = (byte)(data & 0xff); + buf[i * 2] = (byte)(data); + buf[i * 2 + 1] = (byte)(data >> 8); } } public static int getFad(byte[] buf, int i) { - int i0 = buf[0]; - int i1 = buf[1]; - int i2 = buf[2]; - //int i3 = low & 0xff; + //int i0 = ((int)buf[i * 4 + 0]) & 0xff; + int i1 = ((int)buf[i * 4 + 1]) & 0xff; + int i2 = ((int)buf[i * 4 + 2]) & 0xff; + int i3 = ((int)buf[i * 4 + 3]) & 0xff; - return (i2 << 16) | (i1 << 8) | i0; + return (i1 << 16) | (i2 << 8) | (i3 << 0); } public static int tocGetDataTrackFad() {