example: add sheik
This commit is contained in:
parent
8cead9614f
commit
03403c95aa
@ -581,3 +581,17 @@ CUBE_VQ_OBJ = \
|
||||
|
||||
example/cube_vq.elf: LDSCRIPT = $(LIB)/alt.lds
|
||||
example/cube_vq.elf: $(START_OBJ) $(CUBE_VQ_OBJ)
|
||||
|
||||
SHEIK_OBJ = \
|
||||
example/sheik.o \
|
||||
holly/core.o \
|
||||
holly/region_array.o \
|
||||
holly/background.o \
|
||||
holly/ta_fifo_polygon_converter.o \
|
||||
holly/video_output.o \
|
||||
sh7091/serial.o \
|
||||
model/sheik/sheik_00.data.o \
|
||||
model/sheik/xc_eye01.data.o
|
||||
|
||||
example/sheik.elf: LDSCRIPT = $(LIB)/alt.lds
|
||||
example/sheik.elf: $(START_OBJ) $(SHEIK_OBJ)
|
||||
|
271
example/sheik.cpp
Normal file
271
example/sheik.cpp
Normal file
@ -0,0 +1,271 @@
|
||||
#include <cstdint>
|
||||
|
||||
#include "holly/isp_tsp.hpp"
|
||||
#include "holly/ta_parameter.hpp"
|
||||
#include "holly/ta_global_parameter.hpp"
|
||||
#include "holly/ta_vertex_parameter.hpp"
|
||||
#include "holly/ta_bits.hpp"
|
||||
#include "holly/ta_fifo_polygon_converter.hpp"
|
||||
#include "holly/holly.hpp"
|
||||
#include "holly/core_bits.hpp"
|
||||
#include "holly/core.hpp"
|
||||
#include "holly/region_array.hpp"
|
||||
#include "holly/background.hpp"
|
||||
#include "holly/video_output.hpp"
|
||||
#include "holly/texture_memory_alloc2.hpp"
|
||||
#include "sh7091/store_queue.hpp"
|
||||
#include "sh7091/serial.hpp"
|
||||
|
||||
#include "systembus.hpp"
|
||||
#include "systembus_bits.hpp"
|
||||
|
||||
#include "twiddle.hpp"
|
||||
|
||||
#include "math/vec2.hpp"
|
||||
|
||||
#include "model/sheik/sheik_00.data.h"
|
||||
#include "model/sheik/xc_eye01.data.h"
|
||||
#include "model/sheik/material.h"
|
||||
#include "model/sheik/model.h"
|
||||
|
||||
void transfer_scene(float theta)
|
||||
{
|
||||
const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
|
||||
| para_control::list_type::opaque
|
||||
| obj_control::col_type::intensity_mode_1
|
||||
| obj_control::texture
|
||||
| obj_control::gouraud;
|
||||
|
||||
const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
|
||||
| isp_tsp_instruction_word::culling_mode::cull_if_negative;
|
||||
|
||||
|
||||
for (int j = 0; j < sheik_model.object_count; j++) {
|
||||
struct object * object = sheik_model.object[j];
|
||||
struct material_descriptor * mat = &material[object->material];
|
||||
|
||||
const uint32_t tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one
|
||||
| tsp_instruction_word::dst_alpha_instr::zero
|
||||
| tsp_instruction_word::fog_control::no_fog
|
||||
| tsp_instruction_word::texture_shading_instruction::modulate
|
||||
| tsp_instruction_word::texture_u_size::from_int(mat->pixel.width)
|
||||
| tsp_instruction_word::texture_v_size::from_int(mat->pixel.height);
|
||||
|
||||
const uint32_t texture_address = texture_memory_alloc::texture.start + mat->pixel.vram_offset;
|
||||
const uint32_t texture_control_word = texture_control_word::pixel_format::_1555
|
||||
| texture_control_word::scan_order::non_twiddled
|
||||
| texture_control_word::texture_address(texture_address / 8);
|
||||
|
||||
*reinterpret_cast<ta_global_parameter::polygon_type_1 *>(store_queue) =
|
||||
ta_global_parameter::polygon_type_1(parameter_control_word,
|
||||
isp_tsp_instruction_word,
|
||||
tsp_instruction_word,
|
||||
texture_control_word, // texture_control_word
|
||||
1.0, // face color alpha
|
||||
1.0, // face color r
|
||||
1.0, // face color g
|
||||
1.0 // face color b
|
||||
);
|
||||
sq_transfer_32byte(ta_fifo_polygon_converter);
|
||||
|
||||
for (int i = 0; i < object->triangle_count; i++) {
|
||||
for (int k = 0; k < 3; k++) {
|
||||
int position_ix = object->triangle[i].v[k].position;
|
||||
float x0 = sheik_model.position[position_ix].x;
|
||||
float y0 = sheik_model.position[position_ix].y;
|
||||
float z0 = sheik_model.position[position_ix].z;
|
||||
|
||||
float x1 = x0 * cos(theta) - z0 * sin(theta);
|
||||
float y1 = y0 - 3;
|
||||
float z1 = x0 * sin(theta) + z0 * cos(theta);
|
||||
|
||||
/*
|
||||
float x = x1;
|
||||
float y = y1 * cos(theta) - z1 * sin(theta);
|
||||
float z = y1 * sin(theta) + z1 * cos(theta);
|
||||
*/
|
||||
float x = x1;
|
||||
float y = -y1;
|
||||
float z = z1;
|
||||
|
||||
z += 3.5;
|
||||
|
||||
x /= z;
|
||||
y /= z;
|
||||
|
||||
// do rotation
|
||||
x = x * 240 + 320;
|
||||
y = y * 240 + 240;
|
||||
|
||||
z = 1/z;
|
||||
|
||||
bool end_of_strip = k == 2;
|
||||
|
||||
int texture_ix = object->triangle[i].v[k].texture;
|
||||
float u = sheik_model.texture[texture_ix].u;
|
||||
float v = 1.0 - sheik_model.texture[texture_ix].v;
|
||||
|
||||
*reinterpret_cast<ta_vertex_parameter::polygon_type_7 *>(store_queue) =
|
||||
ta_vertex_parameter::polygon_type_7(polygon_vertex_parameter_control_word(end_of_strip),
|
||||
x, y, z,
|
||||
u, v,
|
||||
1.0, // base intensity
|
||||
1.0 // offset intensity
|
||||
);
|
||||
sq_transfer_32byte(ta_fifo_polygon_converter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*reinterpret_cast<ta_global_parameter::end_of_list *>(store_queue) =
|
||||
ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
|
||||
sq_transfer_32byte(ta_fifo_polygon_converter);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void copy(T * dst, const T * src, const int32_t n) noexcept
|
||||
{
|
||||
int32_t n_t = n / (sizeof (T));
|
||||
while (n_t > 0) {
|
||||
*dst++ = *src++;
|
||||
n_t--;
|
||||
}
|
||||
}
|
||||
|
||||
void texture_init()
|
||||
{
|
||||
int length = (sizeof (material)) / (sizeof (material[0]));
|
||||
for (int i = 0; i < length; i++) {
|
||||
uint32_t offset = texture_memory_alloc::texture.start + material[i].pixel.vram_offset;
|
||||
|
||||
copy<volatile uint32_t>(&texture_memory64[offset / 4],
|
||||
reinterpret_cast<uint32_t *>(material[i].pixel.start),
|
||||
material[i].pixel.size);
|
||||
}
|
||||
}
|
||||
|
||||
void dump_ram(const volatile uint32_t * mem, const uint32_t len)
|
||||
{
|
||||
uint32_t sum = 0;
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
uint32_t m = mem[i];
|
||||
for (int j = 0; j < 4; j++) {
|
||||
uint8_t n = ((uint8_t*)&m)[j];
|
||||
sum += n;
|
||||
serial::hexlify(n);
|
||||
}
|
||||
if ((i & 0xf) == 0xf)
|
||||
serial::character('\n');
|
||||
}
|
||||
serial::character('\n');
|
||||
serial::integer<uint32_t>(sum);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
serial::init(4);
|
||||
constexpr uint32_t ta_alloc = ta_alloc_ctrl::pt_opb::no_list
|
||||
| ta_alloc_ctrl::tm_opb::no_list
|
||||
| ta_alloc_ctrl::t_opb::no_list
|
||||
| ta_alloc_ctrl::om_opb::no_list
|
||||
| ta_alloc_ctrl::o_opb::_32x4byte;
|
||||
|
||||
constexpr int render_passes = 1;
|
||||
constexpr struct opb_size opb_size[render_passes] = {
|
||||
{
|
||||
.opaque = 32 * 4,
|
||||
.opaque_modifier = 0,
|
||||
.translucent = 0,
|
||||
.translucent_modifier = 0,
|
||||
.punch_through = 0
|
||||
}
|
||||
};
|
||||
|
||||
holly.SOFTRESET = softreset::pipeline_soft_reset
|
||||
| softreset::ta_soft_reset;
|
||||
holly.SOFTRESET = 0;
|
||||
|
||||
core_init();
|
||||
|
||||
video_output::set_mode_vga();
|
||||
|
||||
constexpr int framebuffer_width = 640;
|
||||
constexpr int framebuffer_height = 480;
|
||||
constexpr int tile_width = framebuffer_width / 32;
|
||||
constexpr int tile_height = framebuffer_height / 32;
|
||||
|
||||
region_array_multipass(tile_width,
|
||||
tile_height,
|
||||
opb_size,
|
||||
render_passes,
|
||||
texture_memory_alloc::region_array[0].start,
|
||||
texture_memory_alloc::object_list[0].start);
|
||||
region_array_multipass(tile_width,
|
||||
tile_height,
|
||||
opb_size,
|
||||
render_passes,
|
||||
texture_memory_alloc::region_array[1].start,
|
||||
texture_memory_alloc::object_list[1].start);
|
||||
|
||||
background_parameter2(texture_memory_alloc::background[0].start,
|
||||
0xff220033);
|
||||
background_parameter2(texture_memory_alloc::background[1].start,
|
||||
0xff220033);
|
||||
|
||||
texture_init();
|
||||
|
||||
const float degree = 0.017453292519943295;
|
||||
float theta = 0;
|
||||
int ta = -1;
|
||||
int core = -2;
|
||||
while (1) {
|
||||
//serial::integer<uint8_t>(ta, ' ');
|
||||
//serial::integer<uint8_t>(core, '\n');
|
||||
if (core >= 0) {
|
||||
// core = 0 ; core = 1
|
||||
// ta = 1 ; ta = 0
|
||||
core_wait_end_of_render_video();
|
||||
while (!spg_status::vsync(holly.SPG_STATUS));
|
||||
holly.FB_R_SOF1 = texture_memory_alloc::framebuffer[core].start;
|
||||
while (spg_status::vsync(holly.SPG_STATUS));
|
||||
}
|
||||
|
||||
// core = -2 ; core = 1 ; core = 0
|
||||
// ta = -1 ; ta = 0 ; ta = 1
|
||||
core += 1;
|
||||
ta += 1;
|
||||
if (core > 1) core = 0;
|
||||
if (ta > 1) ta = 0;
|
||||
|
||||
if (core >= 0) {
|
||||
// core = 1 ; core = 0
|
||||
// ta = 0 ; ta = 1
|
||||
ta_wait_opaque_list();
|
||||
system.ISTNRM = istnrm::end_of_render_tsp
|
||||
| istnrm::end_of_render_isp
|
||||
| istnrm::end_of_render_video;
|
||||
|
||||
core_start_render2(texture_memory_alloc::region_array[core].start,
|
||||
texture_memory_alloc::isp_tsp_parameters[core].start,
|
||||
texture_memory_alloc::background[core].start,
|
||||
texture_memory_alloc::framebuffer[core].start,
|
||||
framebuffer_width);
|
||||
}
|
||||
|
||||
|
||||
// core = -1 ; core = 1 ; core = 0
|
||||
// ta = 0 ; ta = 0 ; ta = 1
|
||||
system.ISTNRM = istnrm::end_of_transferring_opaque_list;
|
||||
ta_polygon_converter_init2(texture_memory_alloc::isp_tsp_parameters[ta].start,
|
||||
texture_memory_alloc::isp_tsp_parameters[ta].end,
|
||||
texture_memory_alloc::object_list[ta].start,
|
||||
texture_memory_alloc::object_list[ta].end,
|
||||
opb_size[0].total(),
|
||||
ta_alloc,
|
||||
tile_width,
|
||||
tile_height);
|
||||
transfer_scene(theta);
|
||||
|
||||
theta += degree;
|
||||
}
|
||||
}
|
@ -49,11 +49,11 @@ constexpr start_end background[2] = {
|
||||
constexpr start_end object_list[2] = {
|
||||
{ // bus A
|
||||
.start = 0x10'0000,
|
||||
.end = 0x20'0000 - 0x10,
|
||||
.end = 0x20'0000 - 0x20,
|
||||
},
|
||||
{ // bus B
|
||||
.start = 0x50'0000,
|
||||
.end = 0x60'0000 - 0x10,
|
||||
.end = 0x60'0000 - 0x20,
|
||||
}
|
||||
};
|
||||
constexpr start_end framebuffer[2] = {
|
||||
|
32
model/sheik/material.h
Normal file
32
model/sheik/material.h
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "model/material.h"
|
||||
|
||||
enum material {
|
||||
body,
|
||||
eyes,
|
||||
};
|
||||
|
||||
struct material_descriptor material[] = {
|
||||
[body] = {
|
||||
.pixel = {
|
||||
.start = (uint8_t *)&_binary_model_sheik_sheik_00_data_start,
|
||||
.size = (int)&_binary_model_sheik_sheik_00_data_size,
|
||||
.vram_offset = 0,
|
||||
.width = 128,
|
||||
.height = 256,
|
||||
},
|
||||
},
|
||||
[eyes] = {
|
||||
.pixel = {
|
||||
.start = (uint8_t *)&_binary_model_sheik_xc_eye01_data_start,
|
||||
.size = (int)&_binary_model_sheik_xc_eye01_data_size,
|
||||
.vram_offset = 65536,
|
||||
.width = 32,
|
||||
.height = 32,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
7155
model/sheik/model.h
Normal file
7155
model/sheik/model.h
Normal file
File diff suppressed because it is too large
Load Diff
22
model/sheik/sheik.mtl
Normal file
22
model/sheik/sheik.mtl
Normal file
@ -0,0 +1,22 @@
|
||||
# Blender 4.1.1 MTL File: 'None'
|
||||
# www.blender.org
|
||||
|
||||
newmtl body
|
||||
Ns 1000.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.500000
|
||||
d 1.000000
|
||||
illum 1
|
||||
map_Kd /home/bilbo/dreamcast/model_gen/sheik/sheik_00.png
|
||||
|
||||
newmtl eyes
|
||||
Ns 250.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.500000
|
||||
d 1.000000
|
||||
illum 2
|
||||
map_Kd /home/bilbo/dreamcast/model_gen/sheik/xc_eye01.png
|
3120
model/sheik/sheik.obj
Normal file
3120
model/sheik/sheik.obj
Normal file
File diff suppressed because it is too large
Load Diff
BIN
model/sheik/sheik_00.data
Normal file
BIN
model/sheik/sheik_00.data
Normal file
Binary file not shown.
5
model/sheik/sheik_00.data.h
Normal file
5
model/sheik/sheik_00.data.h
Normal file
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
extern uint32_t _binary_model_sheik_sheik_00_data_start __asm("_binary_model_sheik_sheik_00_data_start");
|
||||
extern uint32_t _binary_model_sheik_sheik_00_data_end __asm("_binary_model_sheik_sheik_00_data_end");
|
||||
extern uint32_t _binary_model_sheik_sheik_00_data_size __asm("_binary_model_sheik_sheik_00_data_size");
|
BIN
model/sheik/sheik_00.png
Normal file
BIN
model/sheik/sheik_00.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
BIN
model/sheik/xc_eye01.data
Normal file
BIN
model/sheik/xc_eye01.data
Normal file
Binary file not shown.
5
model/sheik/xc_eye01.data.h
Normal file
5
model/sheik/xc_eye01.data.h
Normal file
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
extern uint32_t _binary_model_sheik_xc_eye01_data_start __asm("_binary_model_sheik_xc_eye01_data_start");
|
||||
extern uint32_t _binary_model_sheik_xc_eye01_data_end __asm("_binary_model_sheik_xc_eye01_data_end");
|
||||
extern uint32_t _binary_model_sheik_xc_eye01_data_size __asm("_binary_model_sheik_xc_eye01_data_size");
|
BIN
model/sheik/xc_eye01.png
Normal file
BIN
model/sheik/xc_eye01.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
Loading…
x
Reference in New Issue
Block a user