From 3e35137e077c7a98e38036cc9710c16ba82c94a1 Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Thu, 2 Jan 2025 18:10:24 -0600 Subject: [PATCH] load texture data from gdrom --- Main.java | 4 +- Makefile.dreamcast.mk | 7 +- c/execute.c | 17 ++- example/GdromTest.java | 2 - .../{DreamcastVideo2.java => JavaCube.java} | 126 ++++++++++++++---- images/color_convert.py | 2 +- images/java_cup.data | Bin 524292 -> 524288 bytes images/java_cup.data.h | 2 +- images/java_text.data | Bin 524292 -> 524288 bytes images/java_text.data.h | 2 +- sega/dreamcast/gdrom/GdromIF.java | 2 +- 11 files changed, 126 insertions(+), 38 deletions(-) rename example/{DreamcastVideo2.java => JavaCube.java} (81%) diff --git a/Main.java b/Main.java index 2527a6b..2b6ba1f 100644 --- a/Main.java +++ b/Main.java @@ -1,7 +1,7 @@ -import example.DreamcastVideo2; +import example.JavaCube; class Main { public static void main() { - DreamcastVideo2.main(); + JavaCube.main(); } } diff --git a/Makefile.dreamcast.mk b/Makefile.dreamcast.mk index 86957e0..a3b3de7 100644 --- a/Makefile.dreamcast.mk +++ b/Makefile.dreamcast.mk @@ -107,7 +107,8 @@ jvm.iso: boot.bin main.bin zero.bin sega/dreamcast/gdrom/GdromCommandPacketInterface.class \ sega/dreamcast/gdrom/GdromProtocol.class \ Main.class \ - example/DreamcastVideo2.class \ + example/JavaCube.class \ + example/JavaCubeDirectoryRecordHandler.class \ model/FacePTN.class \ model/ModelObject.class \ model/UntitledModel.class \ @@ -130,7 +131,9 @@ jvm.iso: boot.bin main.bin zero.bin sega/dreamcast/holly/TAVertexParameter_polygon_type_3.class \ sega/dreamcast/holly/TextureMemoryAllocation.class \ java/lang/Math.class \ - java/misc/Resource.class + java/misc/Resource.class \ + images/java_text.data \ + images/java_cup.data main.elf: LDSCRIPT = $(LIB)/main.lds main.elf: $(START_OBJ) $(OBJ) $(MAIN_OBJ) $(MAIN_DREAMCAST_OBJ) $(LIBGCC_OBJ) $(CLASS_PATH) diff --git a/c/execute.c b/c/execute.c index 0237dc0..7f9abff 100644 --- a/c/execute.c +++ b/c/execute.c @@ -1541,11 +1541,18 @@ void op_ldc2_w(struct vm * vm, uint32_t index) void op_ldc_w(struct vm * vm, uint32_t index) { struct constant * constant = &vm->current_frame->class_entry->class_file->constant_pool[index - 1]; - #ifdef DEBUG - assert(constant->tag == CONSTANT_Integer || constant->tag == CONSTANT_Float); - #endif - int32_t value = constant->integer.bytes; - operand_stack_push_u32(vm->current_frame, value); + if (constant->tag == CONSTANT_Integer || constant->tag == CONSTANT_Float) { + int32_t value = constant->integer.bytes; + operand_stack_push_u32(vm->current_frame, value); + } else if (constant->tag == CONSTANT_String) { + int32_t * objectref = class_resolver_lookup_string(vm->class_hash_table.length, + vm->class_hash_table.entry, + vm->current_frame->class_entry, + constant->string.string_index); + operand_stack_push_u32(vm->current_frame, (uint32_t)objectref); + } else { + assert(false); + } } void op_ldiv(struct vm * vm) diff --git a/example/GdromTest.java b/example/GdromTest.java index 7ca7f42..ab19d34 100644 --- a/example/GdromTest.java +++ b/example/GdromTest.java @@ -37,8 +37,6 @@ class GdromDirectoryRecordHandler implements DirectoryRecordHandler { int ix = 0; for (int i = length - 5; i < length; i++) { - System.out.print(ix); - System.out.print(" "); if (buf[offset + i] != class_ext[ix]) { return false; } diff --git a/example/DreamcastVideo2.java b/example/JavaCube.java similarity index 81% rename from example/DreamcastVideo2.java rename to example/JavaCube.java index ec9e906..77acd3d 100644 --- a/example/DreamcastVideo2.java +++ b/example/JavaCube.java @@ -22,8 +22,68 @@ import model.FacePTN; import model.ModelObject; import java.misc.Memory; import java.misc.Resource; +import filesystem.iso9660.VolumeParser; +import filesystem.iso9660.DirectoryRecordHandler; +import filesystem.iso9660.DirectoryRecord; +import sega.dreamcast.gdrom.GdromExtentReader; +import sega.dreamcast.gdrom.GdromProtocol; +import sega.dreamcast.gdrom.GdromIF; +import sega.dreamcast.gdrom.G1IF; +import sega.dreamcast.gdrom.Gdrom; +import java.misc.Memory; -public class DreamcastVideo2 { +class JavaCubeDirectoryRecordHandler implements DirectoryRecordHandler { + int[] texture_extents; + String[] texture_filenames; + + JavaCubeDirectoryRecordHandler(int[] texture_extents, String[] texture_filenames) { + this.texture_extents = texture_extents; + this.texture_filenames = texture_filenames; + } + + boolean bytesEqual(byte[] a, int a_offset, byte[] b, int length) { + for (int i = 0; i < length; i++) { + if (a[a_offset + i] != b[i]) + return false; + } + return true; + } + + public int isTexture(DirectoryRecord dr) { + int length = dr.lengthOfFileIdentifier(); + if (length != 14) + return -1; + + byte[] buf = dr.array; + int offset = dr.offset + DirectoryRecord.FILE_IDENTIFIER_START; + + if (buf[offset] != (byte)'J') + return -1; + + for (int i = 0; i < texture_filenames.length; i++) { + byte[] texture_filename = texture_filenames[i].getBytes(); + if (bytesEqual(buf, offset, texture_filename, length)) + return i; + } + return -1; + } + + public void handle(DirectoryRecord dr) { + int texture_index = isTexture(dr); + if (texture_index >= 0) { + int extent = dr.locationOfExtent(); // sector number + /* + System.out.print("texture extent: "); + System.out.print(texture_index); + System.out.print(": "); + System.out.println(extent); + */ + texture_extents[texture_index] = extent; + } + } +} + +public class JavaCube { static final int framebuffer_width = 640; static final int framebuffer_height = 480; @@ -43,7 +103,19 @@ public class DreamcastVideo2 { 11479204, 4042586, 16676239 }; + public static int[] texture_extents; + + static String[] texture_filenames = { + "JAVA_CUP.DAT;1", + "JAVA_TEX.DAT;1", + }; + static { + texture_extents = new int[texture_filenames.length]; + for (int i = 0; i < texture_filenames.length; i++) { + texture_extents[i] = -1; + } + int parameter_control_word = TAParameter.para_control__para_type__polygon_or_modifier_volume | TAParameter.para_control__list_type__translucent | TAParameter.obj_control__col_type__packed_color @@ -237,29 +309,33 @@ public class DreamcastVideo2 { public static void transfer_textures() { int texture = TextureMemoryAllocation.texture_regions[1][0] + 512; - /* - // java_cup - int[] java_cup = Resource.getResource("images/java_cup"); - int java_cup_length = (java_cup == null) ? 0 : java_cup.length; - //System.out.print("images/java_cup length: "); - //System.out.println(java_cup_length); + int data_track_fad = GdromProtocol.tocGetDataTrackFad(); - for (int i = 0; i < java_cup_length; i++) { - Memory.putU4(MemoryMap.texture_memory64 + texture, java_cup[i]); - texture += 4; + JavaCubeDirectoryRecordHandler handler + = new JavaCubeDirectoryRecordHandler(texture_extents, texture_filenames); + GdromExtentReader reader = new GdromExtentReader(); + VolumeParser parser = new VolumeParser(data_track_fad - 150, reader, handler); + parser.parse(); + + for (int i = 0; i < texture_extents.length; i++) { + int length = 512 * 512 * 2; + int sectors = length >> 11; // division by 2048 + + System.out.println(texture); + if (texture_extents[i] >= 0) { + int extent = texture_extents[i]; + Memory.putU4(G1IF.GDEN, 0); + GdromProtocol.cdReadDMA(extent + 150, sectors); + GdromIF.startG1DMA(MemoryMap.texture_memory64 + texture, length); + while ((Memory.getU4(G1IF.GDST) & 1) != 0); + System.out.println("transfer complete"); + int status = Memory.getU1(Gdrom.status); + System.out.print("status: "); + System.out.println(status); + } + + texture += length; } - - // java_text - int[] java_text = Resource.getResource("images/java_text"); - int java_text_length = (java_text == null) ? 0 : java_text.length; - //System.out.print("images/java_text length: "); - //System.out.println(java_text_length); - - for (int i = 0; i < java_text_length; i++) { - Memory.putU4(MemoryMap.texture_memory64 + texture, java_text[i]); - texture += 4; - } - */ } public static void transfer_java_powered() { @@ -340,7 +416,9 @@ public class DreamcastVideo2 { Core.init(); - boot_splash(ta_alloc, opb_size_total); + for (int i = 0; i < 2; i++) { + boot_splash(ta_alloc, opb_size_total); + } transfer_textures(); @@ -348,6 +426,8 @@ public class DreamcastVideo2 { Background.background(TextureMemoryAllocation.background_start[1], background_color); + Memory.putU4(Holly.VO_BORDER_COL, background_color); + RegionArray.region_array(framebuffer_width / 32, framebuffer_height / 32, opb_size, diff --git a/images/color_convert.py b/images/color_convert.py index c838853..1ba1466 100644 --- a/images/color_convert.py +++ b/images/color_convert.py @@ -46,7 +46,7 @@ class color_format: def convert_colors(f, convert, colors): assert len(colors) % 2 == 0, len(colors) - f.write(struct.pack("2#?+j})Skt}2*e?q diff --git a/images/java_cup.data.h b/images/java_cup.data.h index 36f1bad..ccbca4d 100644 --- a/images/java_cup.data.h +++ b/images/java_cup.data.h @@ -3,7 +3,7 @@ #include #ifdef __cplusplus -extern C { +extern "C" { #endif extern uint32_t _binary_images_java_cup_data_start __asm("_binary_images_java_cup_data_start"); diff --git a/images/java_text.data b/images/java_text.data index 333c94641e20aee0e57d955c8bed3c8378db1ea0..c026541e389ce746a33f05eaa7db6e64338f6023 100644 GIT binary patch delta 449 zcmZo^P-tjSXcTA_VB9Lelw~tffoFQbM3xyF6*8Dd8G|DbCMu}4TfAigVrC#_0b*7l MX4`J@mi>$n0C63w5&!@I delta 26 hcmZo@P-tmTU}0cjVrXb#Y+-6)ZeeL*ZDDI+2LM}i27>?q diff --git a/images/java_text.data.h b/images/java_text.data.h index cc93c73..ae7dc41 100644 --- a/images/java_text.data.h +++ b/images/java_text.data.h @@ -3,7 +3,7 @@ #include #ifdef __cplusplus -extern C { +extern "C" { #endif extern uint32_t _binary_images_java_text_data_start __asm("_binary_images_java_text_data_start"); diff --git a/sega/dreamcast/gdrom/GdromIF.java b/sega/dreamcast/gdrom/GdromIF.java index 34a39dd..05dbba5 100644 --- a/sega/dreamcast/gdrom/GdromIF.java +++ b/sega/dreamcast/gdrom/GdromIF.java @@ -8,7 +8,7 @@ public class GdromIF { public static void startG1DMA(int start_address, int transfer_length) { int gdstar = start_address & ~(0b111 << 29); - Memory.putU4(G1IF.GDAPRO, 0x8843407F); + Memory.putU4(G1IF.GDAPRO, 0x8843007F); Memory.putU4(G1IF.G1GDRC, 0x00001001); Memory.putU4(G1IF.GDSTAR, gdstar); Memory.putU4(G1IF.GDLEN, transfer_length);