rotating triangle
This commit is contained in:
parent
de56ce5ac4
commit
bb2e911546
@ -50,8 +50,5 @@ LIBGCC_OBJ = \
|
|||||||
|
|
||||||
include classpath.mk
|
include classpath.mk
|
||||||
|
|
||||||
CLASS_FILES = \
|
|
||||||
example/DreamcastVideo2.class.o
|
|
||||||
|
|
||||||
main.elf: LDSCRIPT = $(LIB)/main.lds
|
main.elf: LDSCRIPT = $(LIB)/main.lds
|
||||||
main.elf: $(START_OBJ) $(OBJ) $(MAIN_OBJ) $(MAIN_DREAMCAST_OBJ) $(LIBGCC_OBJ) $(CLASS_FILES) $(CLASS_PATH)
|
main.elf: $(START_OBJ) $(OBJ) $(MAIN_OBJ) $(MAIN_DREAMCAST_OBJ) $(LIBGCC_OBJ) $(CLASS_PATH)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "printf.h"
|
#include "printf.h"
|
||||||
|
#include "class_file.h"
|
||||||
|
|
||||||
#define assert(b) \
|
#define assert(b) \
|
||||||
do { \
|
do { \
|
||||||
@ -9,3 +10,32 @@
|
|||||||
while (1); \
|
while (1); \
|
||||||
} \
|
} \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
|
static inline void assert_print_string(struct constant * constant)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < constant->utf8.length; i++) {
|
||||||
|
printc(constant->utf8.bytes[i]);
|
||||||
|
}
|
||||||
|
printc('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
#define assertvm(vm, b) \
|
||||||
|
do { \
|
||||||
|
if (!(b)) { \
|
||||||
|
printf("%s:%d %s: vm assertion `%s` failed\n", __FILE__, __LINE__, __func__, #b); \
|
||||||
|
\
|
||||||
|
struct class_entry * class_entry = vm->current_frame->class_entry; \
|
||||||
|
struct constant * class_constant = &class_entry->class_file->constant_pool[class_entry->class_file->this_class - 1]; \
|
||||||
|
assert(class_constant->tag == CONSTANT_Class); \
|
||||||
|
struct constant * class_name_constant = &class_entry->class_file->constant_pool[class_constant->class.name_index - 1]; \
|
||||||
|
assert(class_name_constant->tag == CONSTANT_Utf8); \
|
||||||
|
assert_print_string(class_name_constant); \
|
||||||
|
\
|
||||||
|
struct method_info * method_info = vm->current_frame->method; \
|
||||||
|
struct constant * method_name_constant = &class_entry->class_file->constant_pool[method_info->name_index - 1]; \
|
||||||
|
assert(method_name_constant->tag == CONSTANT_Utf8); \
|
||||||
|
assert_print_string(method_name_constant); \
|
||||||
|
\
|
||||||
|
while (1); \
|
||||||
|
} \
|
||||||
|
} while (0);
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
#include "example/DreamcastVideo2.class.h"
|
||||||
|
#include "example/DreamcastVideo.class.h"
|
||||||
|
#include "example/Vec2.class.h"
|
||||||
#include "java/io/PrintStream.class.h"
|
#include "java/io/PrintStream.class.h"
|
||||||
#include "java/lang/Integer.class.h"
|
#include "java/lang/Integer.class.h"
|
||||||
#include "java/lang/Math.class.h"
|
#include "java/lang/Math.class.h"
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
(const uint8_t *)&_binary_example_DreamcastVideo2_class_start,
|
||||||
|
(const uint8_t *)&_binary_example_DreamcastVideo_class_start,
|
||||||
|
(const uint8_t *)&_binary_example_Vec2_class_start,
|
||||||
(const uint8_t *)&_binary_java_io_PrintStream_class_start,
|
(const uint8_t *)&_binary_java_io_PrintStream_class_start,
|
||||||
(const uint8_t *)&_binary_java_lang_Integer_class_start,
|
(const uint8_t *)&_binary_java_lang_Integer_class_start,
|
||||||
(const uint8_t *)&_binary_java_lang_Math_class_start,
|
(const uint8_t *)&_binary_java_lang_Math_class_start,
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
#include "sh7091_scif.h"
|
#include "sh7091_scif.h"
|
||||||
|
|
||||||
#include "classpath.h"
|
#include "classpath.h"
|
||||||
#include "example/DreamcastVideo2.class.h"
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
@ -16,7 +15,6 @@ void main()
|
|||||||
|
|
||||||
const uint8_t * class_file_buffers[] = {
|
const uint8_t * class_file_buffers[] = {
|
||||||
#include "classpath.inc.c"
|
#include "classpath.inc.c"
|
||||||
(const uint8_t *)&_binary_example_DreamcastVideo2_class_start,
|
|
||||||
};
|
};
|
||||||
int class_file_buffers_length = (sizeof (class_file_buffers)) / (sizeof (class_file_buffers[0]));
|
int class_file_buffers_length = (sizeof (class_file_buffers)) / (sizeof (class_file_buffers[0]));
|
||||||
|
|
||||||
|
@ -25,6 +25,8 @@ void print_cstring(const char * s);
|
|||||||
void _printf(const char * format, ...);
|
void _printf(const char * format, ...);
|
||||||
|
|
||||||
#define printf(...) _printf(__VA_ARGS__)
|
#define printf(...) _printf(__VA_ARGS__)
|
||||||
|
#define printc(c) print_char(c)
|
||||||
|
#define prints(s) print_cstring(s)
|
||||||
|
|
||||||
#if defined(DEBUG_PRINT)
|
#if defined(DEBUG_PRINT)
|
||||||
#define debugf(...) _printf(__VA_ARGS__)
|
#define debugf(...) _printf(__VA_ARGS__)
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
CLASS_PATH = \
|
CLASS_PATH = \
|
||||||
|
example/DreamcastVideo2.class.o \
|
||||||
|
example/DreamcastVideo.class.o \
|
||||||
|
example/Vec2.class.o \
|
||||||
java/io/PrintStream.class.o \
|
java/io/PrintStream.class.o \
|
||||||
java/lang/Integer.class.o \
|
java/lang/Integer.class.o \
|
||||||
java/lang/Math.class.o \
|
java/lang/Math.class.o \
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern C {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern uint32_t _binary_example_DreamcastVideo_class_start __asm("_binary_example_DreamcastVideo_class_start");
|
extern uint32_t _binary_example_DreamcastVideo_class_start __asm("_binary_example_DreamcastVideo_class_start");
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern C {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern uint32_t _binary_example_DreamcastVideo2_class_start __asm("_binary_example_DreamcastVideo2_class_start");
|
extern uint32_t _binary_example_DreamcastVideo2_class_start __asm("_binary_example_DreamcastVideo2_class_start");
|
||||||
|
@ -17,10 +17,22 @@ import sega.dreamcast.systembus.SystembusBits;
|
|||||||
import sega.dreamcast.MemoryMap;
|
import sega.dreamcast.MemoryMap;
|
||||||
import java.misc.Memory;
|
import java.misc.Memory;
|
||||||
|
|
||||||
|
class Vec2 {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
}
|
||||||
|
|
||||||
class DreamcastVideo2 {
|
class DreamcastVideo2 {
|
||||||
public static TAGlobalParameter.polygon_type_0 gt0;
|
static final int framebuffer_width = 640;
|
||||||
public static TAVertexParameter.polygon_type_0 vt0;
|
static final int framebuffer_height = 480;
|
||||||
public static TAGlobalParameter.end_of_list eol;
|
|
||||||
|
static TAGlobalParameter.polygon_type_0 gt0;
|
||||||
|
static TAVertexParameter.polygon_type_0 vt0;
|
||||||
|
static TAGlobalParameter.end_of_list eol;
|
||||||
|
|
||||||
|
static Vec2[] vtx;
|
||||||
|
|
||||||
|
static float theta;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
int parameter_control_word = TAParameter.para_control__para_type__polygon_or_modifier_volume
|
int parameter_control_word = TAParameter.para_control__para_type__polygon_or_modifier_volume
|
||||||
@ -52,6 +64,31 @@ class DreamcastVideo2 {
|
|||||||
0xff00ff00); // color (green)
|
0xff00ff00); // color (green)
|
||||||
|
|
||||||
eol = new TAGlobalParameter.end_of_list(TAParameter.para_control__para_type__end_of_list);
|
eol = new TAGlobalParameter.end_of_list(TAParameter.para_control__para_type__end_of_list);
|
||||||
|
|
||||||
|
vtx = new Vec2[3];
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
vtx[i] = new Vec2();
|
||||||
|
vtx[0].x = 0.0f;
|
||||||
|
vtx[0].y = 1.0f;
|
||||||
|
vtx[1].x = 0.866025f;
|
||||||
|
vtx[1].y = -0.5f;
|
||||||
|
vtx[2].x = -0.866025f;
|
||||||
|
vtx[2].y = -0.5f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void transform_vertex(Vec2 v, boolean end_of_strip) {
|
||||||
|
DreamcastVideo2.vt0.parameter_control_word = TAParameter.para_control__para_type__vertex_parameter;
|
||||||
|
if (end_of_strip)
|
||||||
|
DreamcastVideo2.vt0.parameter_control_word |= TAParameter.para_control__end_of_strip;
|
||||||
|
|
||||||
|
float x0 = v.x * Math.cos(theta) - v.y * Math.sin(theta);
|
||||||
|
float y0 = v.x * Math.sin(theta) + v.y * Math.cos(theta);
|
||||||
|
float x = x0 * 240 + 320;
|
||||||
|
float y = -y0 * 240 + 240;
|
||||||
|
|
||||||
|
DreamcastVideo2.vt0.x = x;
|
||||||
|
DreamcastVideo2.vt0.y = y;
|
||||||
|
Memory.putSQ1(DreamcastVideo2.vt0, MemoryMap.ta_fifo_polygon_converter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void transfer_scene() {
|
public static void transfer_scene() {
|
||||||
@ -59,21 +96,9 @@ class DreamcastVideo2 {
|
|||||||
Memory.putSQ1(DreamcastVideo2.gt0, MemoryMap.ta_fifo_polygon_converter);
|
Memory.putSQ1(DreamcastVideo2.gt0, MemoryMap.ta_fifo_polygon_converter);
|
||||||
|
|
||||||
// vertex parameters
|
// vertex parameters
|
||||||
DreamcastVideo2.vt0.parameter_control_word = TAParameter.para_control__para_type__vertex_parameter;
|
for (int i = 0; i < 3; i++) {
|
||||||
DreamcastVideo2.vt0.x = 10.0f;
|
transform_vertex(vtx[i], (i == 2));
|
||||||
DreamcastVideo2.vt0.y = 10.0f;
|
}
|
||||||
Memory.putSQ1(DreamcastVideo2.vt0, MemoryMap.ta_fifo_polygon_converter);
|
|
||||||
|
|
||||||
DreamcastVideo2.vt0.parameter_control_word = TAParameter.para_control__para_type__vertex_parameter;
|
|
||||||
DreamcastVideo2.vt0.x = 100.0f;
|
|
||||||
DreamcastVideo2.vt0.y = 10.0f;
|
|
||||||
Memory.putSQ1(DreamcastVideo2.vt0, MemoryMap.ta_fifo_polygon_converter);
|
|
||||||
|
|
||||||
DreamcastVideo2.vt0.parameter_control_word = TAParameter.para_control__para_type__vertex_parameter
|
|
||||||
| TAParameter.para_control__end_of_strip;
|
|
||||||
DreamcastVideo2.vt0.x = 100.0f;
|
|
||||||
DreamcastVideo2.vt0.y = 100.0f;
|
|
||||||
Memory.putSQ1(DreamcastVideo2.vt0, MemoryMap.ta_fifo_polygon_converter);
|
|
||||||
|
|
||||||
// end of list
|
// end of list
|
||||||
Memory.putSQ1(DreamcastVideo2.eol, MemoryMap.ta_fifo_polygon_converter);
|
Memory.putSQ1(DreamcastVideo2.eol, MemoryMap.ta_fifo_polygon_converter);
|
||||||
@ -100,9 +125,6 @@ class DreamcastVideo2 {
|
|||||||
};
|
};
|
||||||
|
|
||||||
int opb_size_total = opb_size[0].total();
|
int opb_size_total = opb_size[0].total();
|
||||||
|
|
||||||
int framebuffer_width = 640;
|
|
||||||
int framebuffer_height = 480;
|
|
||||||
int num_render_passes = opb_size.length;
|
int num_render_passes = opb_size.length;
|
||||||
|
|
||||||
Core.fb_init(framebuffer_width, framebuffer_height);
|
Core.fb_init(framebuffer_width, framebuffer_height);
|
||||||
@ -126,11 +148,10 @@ class DreamcastVideo2 {
|
|||||||
Background.background(TextureMemoryAllocation.background_start[1],
|
Background.background(TextureMemoryAllocation.background_start[1],
|
||||||
background_color);
|
background_color);
|
||||||
|
|
||||||
//int ta = -1;
|
|
||||||
//int core = -2;
|
|
||||||
int core = 0;
|
int core = 0;
|
||||||
int ta = 0;
|
int ta = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
|
// unpipelined render loop
|
||||||
TAFIFOPolygonConverter.init(TextureMemoryAllocation.isp_tsp_parameters_start[ta],
|
TAFIFOPolygonConverter.init(TextureMemoryAllocation.isp_tsp_parameters_start[ta],
|
||||||
TextureMemoryAllocation.isp_tsp_parameters_end[ta],
|
TextureMemoryAllocation.isp_tsp_parameters_end[ta],
|
||||||
TextureMemoryAllocation.object_list_start[ta],
|
TextureMemoryAllocation.object_list_start[ta],
|
||||||
@ -141,6 +162,7 @@ class DreamcastVideo2 {
|
|||||||
framebuffer_height / 32);
|
framebuffer_height / 32);
|
||||||
transfer_scene();
|
transfer_scene();
|
||||||
TAFIFOPolygonConverter.wait_opaque_list();
|
TAFIFOPolygonConverter.wait_opaque_list();
|
||||||
|
|
||||||
Core.start_render(TextureMemoryAllocation.region_array_start[ta],
|
Core.start_render(TextureMemoryAllocation.region_array_start[ta],
|
||||||
TextureMemoryAllocation.isp_tsp_parameters_start[ta],
|
TextureMemoryAllocation.isp_tsp_parameters_start[ta],
|
||||||
TextureMemoryAllocation.background_start[ta],
|
TextureMemoryAllocation.background_start[ta],
|
||||||
@ -149,6 +171,8 @@ class DreamcastVideo2 {
|
|||||||
Core.wait_end_of_render_tsp();
|
Core.wait_end_of_render_tsp();
|
||||||
Memory.putU4(Holly.FB_R_SOF1, TextureMemoryAllocation.framebuffer_start[core]);
|
Memory.putU4(Holly.FB_R_SOF1, TextureMemoryAllocation.framebuffer_start[core]);
|
||||||
core = (core + 1) % 1;
|
core = (core + 1) % 1;
|
||||||
|
|
||||||
|
theta += Math.DEGREES_TO_RADIANS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
example/Vec2.class.h
Normal file
15
example/Vec2.class.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern C {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern uint32_t _binary_example_Vec2_class_start __asm("_binary_example_Vec2_class_start");
|
||||||
|
extern uint32_t _binary_example_Vec2_class_end __asm("_binary_example_Vec2_class_end");
|
||||||
|
extern uint32_t _binary_example_Vec2_class_size __asm("_binary_example_Vec2_class_size");
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
@ -66,10 +66,12 @@ function classpath_h () {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
find sega/ java/ -name '*.class' -exec rm -f {} \;
|
find sega/ java/ -name '*.class' -exec rm -f {} \;
|
||||||
find example/ sega/ java/ -name '*.java' | sort | make_class
|
find example/ sega/ java/ -name '*.java' | sort | make_class
|
||||||
find sega/ java/ -name '*.class' | sort | rename_class_files
|
find example/ sega/ java/ -name '*.class' | sort | rename_class_files
|
||||||
find sega/ java/ -name '*.class' | sort | classpath_mk
|
find example/ sega/ java/ -name '*.class' | sort | classpath_mk
|
||||||
find sega/ java/ -name '*.class' | sort | classpath_inc_c
|
find example/ sega/ java/ -name '*.class' | sort | classpath_inc_c
|
||||||
find sega/ java/ -name '*.class' | sort | make_header
|
find example/ sega/ java/ -name '*.class' | sort | make_header
|
||||||
find sega/ java/ -name '*.class' | sort | classpath_h
|
find example/ sega/ java/ -name '*.class' | sort | classpath_h
|
||||||
|
30
p/VecTest.java
Normal file
30
p/VecTest.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package p;
|
||||||
|
|
||||||
|
class Vec2 {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
}
|
||||||
|
|
||||||
|
class VecTest {
|
||||||
|
static Vec2[] vtx;
|
||||||
|
|
||||||
|
static {
|
||||||
|
vtx = new Vec2[3];
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
vtx[i] = new Vec2();
|
||||||
|
vtx[0].x = 0.0f;
|
||||||
|
vtx[0].y = 1.0f;
|
||||||
|
vtx[1].x = 0.866025f;
|
||||||
|
vtx[1].y = -0.5f;
|
||||||
|
vtx[2].x = -0.866025f;
|
||||||
|
vtx[2].y = -0.5f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float test() {
|
||||||
|
return vtx[0].y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println(test());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user