Skip to content

Commit 45501b5

Browse files
committed
example: add JavaCubeMemory
1 parent 99b7346 commit 45501b5

File tree

6 files changed

+258
-2
lines changed

6 files changed

+258
-2
lines changed

c/classpath.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "classes/filesystem/iso9660/PrimaryVolumeDescriptor.class.h"
77
#include "classes/filesystem/iso9660/VolumeParser.class.h"
88
#include "classes/java/io/PrintStream.class.h"
9+
#include "classes/java/lang/Character.class.h"
910
#include "classes/java/lang/DecimalDigits.class.h"
1011
#include "classes/java/lang/Integer.class.h"
1112
#include "classes/java/lang/Float.class.h"
@@ -79,3 +80,4 @@
7980
#include "classes/sega/dreamcast/holly/TAVertexParameter.class.h"
8081
#include "classes/sega/dreamcast/holly/TextureMemoryAllocation.class.h"
8182
#include "classes/sega/dreamcast/sh7091/StoreQueueBuffer.class.h"
83+
#include "classes/example/JavaCubeMemory.class.h"

c/classpath.inc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
(const uint8_t *)&_binary_classes_filesystem_iso9660_PrimaryVolumeDescriptor_class_start,
77
(const uint8_t *)&_binary_classes_filesystem_iso9660_VolumeParser_class_start,
88
(const uint8_t *)&_binary_classes_java_io_PrintStream_class_start,
9+
(const uint8_t *)&_binary_classes_java_lang_Character_class_start,
910
(const uint8_t *)&_binary_classes_java_lang_DecimalDigits_class_start,
1011
(const uint8_t *)&_binary_classes_java_lang_Integer_class_start,
1112
(const uint8_t *)&_binary_classes_java_lang_Float_class_start,
@@ -79,3 +80,4 @@
7980
(const uint8_t *)&_binary_classes_sega_dreamcast_holly_TAVertexParameter_class_start,
8081
(const uint8_t *)&_binary_classes_sega_dreamcast_holly_TextureMemoryAllocation_class_start,
8182
(const uint8_t *)&_binary_classes_sega_dreamcast_sh7091_StoreQueueBuffer_class_start,
83+
(const uint8_t *)&_binary_classes_example_JavaCubeMemory_class_start,

c/main_dreamcast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void main()
2020

2121
//const uint8_t * main_class = (const uint8_t *)"example/JavaCube";
2222
//const uint8_t * main_class = (const uint8_t *)"example/GdromClassLoader";
23-
const uint8_t * main_class = (const uint8_t *)"Main";
23+
const uint8_t * main_class = (const uint8_t *)"example/JavaCubeMemory";
2424
int main_class_length = string_length((const char *)main_class);
2525

2626
for (int i = 0; i < main_class_length; i++)

classes/example/JavaCubeMemory.java

Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
package example;
2+
3+
import sega.dreamcast.holly.Background;
4+
import sega.dreamcast.holly.Core;
5+
import sega.dreamcast.holly.CoreBits;
6+
import sega.dreamcast.holly.Holly;
7+
import sega.dreamcast.holly.RegionArray;
8+
import sega.dreamcast.holly.TABits;
9+
import sega.dreamcast.holly.TAFIFOPolygonConverter;
10+
import sega.dreamcast.holly.TAParameter;
11+
import sega.dreamcast.holly.TextureMemoryAllocation;
12+
import sega.dreamcast.holly.ISPTSP;
13+
import sega.dreamcast.holly.TAVertexParameter;
14+
import sega.dreamcast.holly.TAGlobalParameter;
15+
import sega.dreamcast.holly.VideoOutput;
16+
import sega.dreamcast.holly.VideoOutputMode;
17+
import sega.dreamcast.MemoryMap;
18+
import model.CubeModel;
19+
import model.Vec3;
20+
import model.Vec2;
21+
import model.FacePTN;
22+
import model.ModelObject;
23+
import jvm.internal.Memory;
24+
25+
public class JavaCubeMemory {
26+
static final int framebuffer_width = 640;
27+
static final int framebuffer_height = 480;
28+
29+
static Vec2[] quad;
30+
static Vec2[] quad_uv;
31+
32+
static float theta;
33+
34+
public static int[] texture_extents;
35+
36+
static String[] texture_filenames = {
37+
"JAVA_CUP.DAT;1",
38+
"JAVA_TEX.DAT;1",
39+
};
40+
41+
static final int parameter_control_word = TAParameter.para_control__para_type__polygon_or_modifier_volume
42+
| TAParameter.para_control__list_type__translucent
43+
| TAParameter.obj_control__col_type__packed_color
44+
| TAParameter.obj_control__texture;
45+
46+
static final int isp_tsp_instruction_word = ISPTSP.isp_tsp_instruction_word__depth_compare_mode__greater
47+
| ISPTSP.isp_tsp_instruction_word__culling_mode__no_culling;
48+
49+
static final int tsp_instruction_word = ISPTSP.tsp_instruction_word__src_alpha_instr__src_alpha
50+
| ISPTSP.tsp_instruction_word__dst_alpha_instr__inverse_src_alpha
51+
| ISPTSP.tsp_instruction_word__fog_control__no_fog
52+
| ISPTSP.tsp_instruction_word__texture_u_size__512
53+
| ISPTSP.tsp_instruction_word__texture_v_size__1024
54+
| ISPTSP.tsp_instruction_word__use_alpha;
55+
56+
static final int texture_address = TextureMemoryAllocation.texture_regions[1][0] + 512;
57+
static final int texture_control_word = ISPTSP.texture_control_word__pixel_format__4444
58+
| ISPTSP.texture_control_word__scan_order__non_twiddled
59+
| ISPTSP.texture_control_word__texture_address(texture_address / 8);
60+
61+
static {
62+
texture_extents = new int[texture_filenames.length];
63+
for (int i = 0; i < texture_filenames.length; i++) {
64+
texture_extents[i] = -1;
65+
}
66+
}
67+
68+
public static void transform_vertex(int parameter_control_word,
69+
Vec3[] position,
70+
Vec2[] texture,
71+
FacePTN ptn) {
72+
73+
float px = position[ptn.position].x;
74+
float py = position[ptn.position].y;
75+
float pz = position[ptn.position].z;
76+
77+
float theta2 = theta * 2.0f;
78+
float scale = (Math.sin(theta2) + 3.0f) * 0.3f;
79+
80+
px *= scale;
81+
py *= scale;
82+
pz *= scale;
83+
84+
float x0 = px * Math.cos(theta) - py * Math.sin(theta);
85+
float y0 = px * Math.sin(theta) + py * Math.cos(theta);
86+
float z0 = pz;
87+
88+
float theta05 = theta * 0.5f;
89+
90+
float x1 = x0 * Math.cos(theta05) - z0 * Math.sin(theta05);
91+
float y1 = y0;
92+
float z1 = x0 * Math.sin(theta05) + z0 * Math.cos(theta05);
93+
94+
// camera transform
95+
float z2 = 3f + z1;
96+
97+
// perspective
98+
float x2 = x1 / z2;
99+
float y2 = y1 / z2;
100+
101+
// screen space
102+
float x = x2 * 240f + 320f;
103+
float y = -y2 * 240f + 240f;
104+
float z = 1.0f / z2;
105+
106+
TAVertexParameter.polygon_type_3(parameter_control_word,
107+
x,
108+
y,
109+
z,
110+
texture[ptn.texture].x, // u
111+
texture[ptn.texture].y, // v
112+
0xff000000, // base_color
113+
0); // offset_color
114+
}
115+
116+
public static void transform_triangle(int n, Vec3[] position, Vec2[] texture, FacePTN[] face) {
117+
for (int i = 0; i < 3; i++) {
118+
int parameter_control_word = TAParameter.para_control__para_type__vertex_parameter;
119+
if (i == 2)
120+
parameter_control_word |= TAParameter.para_control__end_of_strip;
121+
transform_vertex(parameter_control_word, position, texture, face[i]);
122+
}
123+
}
124+
125+
public static void transfer_cube_scene() {
126+
// global parameters
127+
TAGlobalParameter.polygon_type_0(parameter_control_word,
128+
isp_tsp_instruction_word,
129+
tsp_instruction_word,
130+
texture_control_word,
131+
0, // data_size_for_sort_dma
132+
0); // next_address_for_sort_dma
133+
134+
// triangle parameters
135+
ModelObject obj = CubeModel.objects[0];
136+
for (int i = 0; i < obj.faces.length; i ++) {
137+
transform_triangle(i, CubeModel.position, CubeModel.texture, obj.faces[i]);
138+
}
139+
140+
// end of list
141+
TAGlobalParameter.end_of_list(TAParameter.para_control__para_type__end_of_list);
142+
}
143+
144+
public static void transfer_textures() {
145+
int texture = MemoryMap.texture_memory64 + TextureMemoryAllocation.texture_regions[1][0] + 512;
146+
147+
int length = 512 * 512 * 2 * 2 / 4;
148+
int address = 0xac400000;
149+
for (int i = 0; i < length; i++) {
150+
int value = Memory.getU4(address);
151+
Memory.putU4(texture, value);
152+
if ((i & 2047) == 0) {
153+
System.out.print(i);
154+
System.out.print(' ');
155+
System.out.print(address);
156+
System.out.print(' ');
157+
System.out.print(texture);
158+
}
159+
address += 4;
160+
texture += 4;
161+
}
162+
}
163+
164+
public static void main() {
165+
System.out.println("main1");
166+
int ta_alloc =
167+
TABits.ta_alloc_ctrl__opb_mode__increasing_addresses
168+
| TABits.ta_alloc_ctrl__pt_opb__no_list
169+
| TABits.ta_alloc_ctrl__tm_opb__no_list
170+
| TABits.ta_alloc_ctrl__t_opb__8x4byte
171+
| TABits.ta_alloc_ctrl__om_opb__no_list
172+
| TABits.ta_alloc_ctrl__o_opb__no_list
173+
;
174+
175+
RegionArray.OPBSize[] opb_size = {
176+
new RegionArray.OPBSize(0, // opaque
177+
0, // opaque_modifier_volume
178+
8 * 4, // translucent
179+
0, // translucent_modifier_volume
180+
0) // punch_through
181+
};
182+
int opb_size_total = opb_size[0].total();
183+
184+
int background_color = 0xff100a00;
185+
Background.background(TextureMemoryAllocation.background_start[0],
186+
0x00c0c0c0); // sega white
187+
Background.background(TextureMemoryAllocation.background_start[1],
188+
0x00c0c0c0);//background_color); // dark black
189+
190+
Memory.putU4(Holly.VO_BORDER_COL, background_color);
191+
192+
int num_render_passes = opb_size.length;
193+
RegionArray.region_array(framebuffer_width / 32,
194+
framebuffer_height / 32,
195+
opb_size,
196+
num_render_passes,
197+
TextureMemoryAllocation.region_array_start[0],
198+
TextureMemoryAllocation.object_list_start[0]);
199+
RegionArray.region_array(framebuffer_width / 32,
200+
framebuffer_height / 32,
201+
opb_size,
202+
num_render_passes,
203+
TextureMemoryAllocation.region_array_start[1],
204+
TextureMemoryAllocation.object_list_start[1]);
205+
206+
Core.init();
207+
208+
System.out.println("transfer_textures");
209+
transfer_textures();
210+
System.out.println("transfer_textures2");
211+
212+
VideoOutput.set_framebuffer_resolution(640, 480);
213+
VideoOutput.set_mode(VideoOutputMode.vga);
214+
215+
int core = 0;
216+
int ta = 0;
217+
System.out.println("main");
218+
while (true) {
219+
// unpipelined render loop
220+
TAFIFOPolygonConverter.init(TextureMemoryAllocation.isp_tsp_parameters_start[ta],
221+
TextureMemoryAllocation.isp_tsp_parameters_end[ta],
222+
TextureMemoryAllocation.object_list_start[ta],
223+
TextureMemoryAllocation.object_list_end[ta],
224+
opb_size_total,
225+
ta_alloc,
226+
framebuffer_width / 32,
227+
framebuffer_height / 32);
228+
transfer_cube_scene();
229+
TAFIFOPolygonConverter.wait_translucent_list();
230+
231+
Core.start_render(TextureMemoryAllocation.region_array_start[ta],
232+
TextureMemoryAllocation.isp_tsp_parameters_start[ta],
233+
TextureMemoryAllocation.background_start[1],
234+
TextureMemoryAllocation.framebuffer_start[core],
235+
framebuffer_width);
236+
Core.wait_end_of_render_tsp();
237+
238+
while (!(CoreBits.spg_status__vsync(Memory.getU4(Holly.SPG_STATUS)) != 0));
239+
Memory.putU4(Holly.FB_R_SOF1, TextureMemoryAllocation.framebuffer_start[core]);
240+
while ((CoreBits.spg_status__vsync(Memory.getU4(Holly.SPG_STATUS)) != 0));
241+
242+
core = (core + 1) % 1;
243+
244+
theta += Math.DEGREES_TO_RADIANS;
245+
}
246+
}
247+
}

classpath.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CLASS_PATH = \
77
classes/filesystem/iso9660/PrimaryVolumeDescriptor.class.o \
88
classes/filesystem/iso9660/VolumeParser.class.o \
99
classes/java/io/PrintStream.class.o \
10+
classes/java/lang/Character.class.o \
1011
classes/java/lang/DecimalDigits.class.o \
1112
classes/java/lang/Integer.class.o \
1213
classes/java/lang/Float.class.o \
@@ -79,4 +80,5 @@ CLASS_PATH = \
7980
classes/sega/dreamcast/holly/TAGlobalParameter.class.o \
8081
classes/sega/dreamcast/holly/TAVertexParameter.class.o \
8182
classes/sega/dreamcast/holly/TextureMemoryAllocation.class.o \
82-
classes/sega/dreamcast/sh7091/StoreQueueBuffer.class.o
83+
classes/sega/dreamcast/sh7091/StoreQueueBuffer.class.o \
84+
classes/example/JavaCubeMemory.class.o

generate_classpath.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ declare -a boot_classes=(
8181
filesystem/iso9660/PrimaryVolumeDescriptor.class
8282
filesystem/iso9660/VolumeParser.class
8383
java/io/PrintStream.class
84+
java/lang/Character.class
8485
java/lang/DecimalDigits.class
8586
java/lang/Integer.class
8687
java/lang/Float.class
@@ -158,6 +159,8 @@ declare -a boot_classes=(
158159
sega/dreamcast/holly/TAVertexParameter.class
159160
sega/dreamcast/holly/TextureMemoryAllocation.class
160161
sega/dreamcast/sh7091/StoreQueueBuffer.class
162+
163+
example/JavaCubeMemory.class
161164
)
162165

163166
function boot_classes () {

0 commit comments

Comments
 (0)