ta_parameter: TA parameter initialization experiment
This also includes an example for generating a quad primitive. In flycast, this is very obviously rendered as two triangles. On real hardware, this appears to be a "native" quad.
This commit is contained in:
parent
9610c428bd
commit
6cebd0ce90
@ -23,6 +23,8 @@ LD = $(TARGET)ld
|
||||
OBJCOPY = $(TARGET)objcopy
|
||||
OBJDUMP = $(TARGET)objdump
|
||||
|
||||
LIBGCC = $(shell $(CC) -print-file-name=libgcc.a)
|
||||
|
||||
define BUILD_BINARY_O
|
||||
$(OBJCOPY) \
|
||||
-I binary -O elf32-shl -B sh4 \
|
||||
@ -54,11 +56,11 @@ MAIN_OBJ = \
|
||||
rgb.o \
|
||||
holly/background.o \
|
||||
holly/region_array.o \
|
||||
holly/ta_parameter.o \
|
||||
holly/ta_fifo_polygon_converter.o \
|
||||
holly/core.o \
|
||||
scene.o \
|
||||
macaw.data.o
|
||||
macaw.data.o \
|
||||
$(LIBGCC)
|
||||
|
||||
all: main.cdi
|
||||
|
||||
@ -144,7 +146,7 @@ audio.pcm:
|
||||
clean:
|
||||
find -P \
|
||||
-regextype posix-egrep \
|
||||
-regex '.*\.(iso|o|bin|elf|cue|gch)$$' \
|
||||
-regex '.*\.(iso|o|d|bin|elf|cue|gch)$$' \
|
||||
-exec rm {} \;
|
||||
|
||||
.SUFFIXES:
|
||||
|
@ -1,258 +0,0 @@
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
#include "float_uint32.h"
|
||||
#include "ta_parameter.h"
|
||||
#include "isp_tsp.h"
|
||||
|
||||
static_assert((sizeof (float)) == (sizeof (uint32_t)));
|
||||
|
||||
struct vertex_polygon_type_0 {
|
||||
uint32_t parameter_control_word;
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
uint32_t _res0;
|
||||
uint32_t _res1;
|
||||
uint32_t base_color;
|
||||
uint32_t _res2;
|
||||
};
|
||||
|
||||
struct vertex_polygon_type_3 {
|
||||
uint32_t parameter_control_word;
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float u;
|
||||
float v;
|
||||
uint32_t base_color;
|
||||
uint32_t offset_color;
|
||||
};
|
||||
|
||||
static_assert((sizeof (vertex_polygon_type_0)) == 32);
|
||||
static_assert((offsetof (struct vertex_polygon_type_0, parameter_control_word)) == 0x00);
|
||||
static_assert((offsetof (struct vertex_polygon_type_0, x)) == 0x04);
|
||||
static_assert((offsetof (struct vertex_polygon_type_0, y)) == 0x08);
|
||||
static_assert((offsetof (struct vertex_polygon_type_0, z)) == 0x0c);
|
||||
static_assert((offsetof (struct vertex_polygon_type_0, _res0)) == 0x10);
|
||||
static_assert((offsetof (struct vertex_polygon_type_0, _res1)) == 0x14);
|
||||
static_assert((offsetof (struct vertex_polygon_type_0, base_color)) == 0x18);
|
||||
static_assert((offsetof (struct vertex_polygon_type_0, _res2)) == 0x1c);
|
||||
|
||||
struct global_polygon_type_0 {
|
||||
uint32_t parameter_control_word;
|
||||
uint32_t isp_tsp_instruction_word;
|
||||
uint32_t tsp_instruction_word;
|
||||
uint32_t texture_control_word;
|
||||
uint32_t _res0;
|
||||
uint32_t _res1;
|
||||
uint32_t data_size_for_sort_dma;
|
||||
uint32_t next_address_for_sort_dma;
|
||||
};
|
||||
|
||||
static_assert((sizeof (global_polygon_type_0)) == 32);
|
||||
static_assert((offsetof (struct global_polygon_type_0, parameter_control_word)) == 0x00);
|
||||
static_assert((offsetof (struct global_polygon_type_0, isp_tsp_instruction_word)) == 0x04);
|
||||
static_assert((offsetof (struct global_polygon_type_0, tsp_instruction_word)) == 0x08);
|
||||
static_assert((offsetof (struct global_polygon_type_0, texture_control_word)) == 0x0c);
|
||||
static_assert((offsetof (struct global_polygon_type_0, _res0)) == 0x10);
|
||||
static_assert((offsetof (struct global_polygon_type_0, _res1)) == 0x14);
|
||||
static_assert((offsetof (struct global_polygon_type_0, data_size_for_sort_dma)) == 0x18);
|
||||
static_assert((offsetof (struct global_polygon_type_0, next_address_for_sort_dma)) == 0x1c);
|
||||
|
||||
struct global_end_of_list {
|
||||
uint32_t parameter_control_word;
|
||||
uint32_t _res0;
|
||||
uint32_t _res1;
|
||||
uint32_t _res2;
|
||||
uint32_t _res3;
|
||||
uint32_t _res4;
|
||||
uint32_t _res5;
|
||||
uint32_t _res6;
|
||||
};
|
||||
|
||||
static_assert((sizeof (global_end_of_list)) == 32);
|
||||
static_assert((offsetof (struct global_end_of_list, parameter_control_word)) == 0x00);
|
||||
static_assert((offsetof (struct global_end_of_list, _res0)) == 0x04);
|
||||
static_assert((offsetof (struct global_end_of_list, _res1)) == 0x08);
|
||||
static_assert((offsetof (struct global_end_of_list, _res2)) == 0x0c);
|
||||
static_assert((offsetof (struct global_end_of_list, _res3)) == 0x10);
|
||||
static_assert((offsetof (struct global_end_of_list, _res4)) == 0x14);
|
||||
static_assert((offsetof (struct global_end_of_list, _res5)) == 0x18);
|
||||
static_assert((offsetof (struct global_end_of_list, _res6)) == 0x1c);
|
||||
|
||||
namespace para_control {
|
||||
namespace para_type {
|
||||
constexpr uint32_t end_of_list = 0 << 29;
|
||||
constexpr uint32_t user_tile_clip = 1 << 29;
|
||||
constexpr uint32_t object_list_set = 2 << 29;
|
||||
constexpr uint32_t polygon_or_modifier_volume = 4 << 29;
|
||||
constexpr uint32_t sprite = 5 << 29;
|
||||
constexpr uint32_t vertex_parameter = 7 << 29;
|
||||
}
|
||||
|
||||
constexpr uint32_t end_of_strip = 1 << 28;
|
||||
|
||||
namespace list_type {
|
||||
constexpr uint32_t opaque = 0 << 24;
|
||||
constexpr uint32_t opaque_modifier_volume = 1 << 24;
|
||||
constexpr uint32_t translucent = 2 << 24;
|
||||
constexpr uint32_t translucent_modifier_volume = 3 << 24;
|
||||
constexpr uint32_t punch_through = 4 << 24;
|
||||
}
|
||||
}
|
||||
|
||||
namespace group_control {
|
||||
constexpr uint32_t group_en = 1 << 23;
|
||||
|
||||
namespace strip_len {
|
||||
constexpr uint32_t _1_strip = 0 << 18;
|
||||
constexpr uint32_t _2_strip = 1 << 18;
|
||||
constexpr uint32_t _4_strip = 2 << 18;
|
||||
constexpr uint32_t _6_strip = 3 << 18;
|
||||
}
|
||||
|
||||
namespace user_clip {
|
||||
constexpr uint32_t disabled = 0 << 16;
|
||||
constexpr uint32_t inside_enable = 2 << 16;
|
||||
constexpr uint32_t outside_enable = 3 << 16;
|
||||
}
|
||||
}
|
||||
|
||||
namespace obj_control {
|
||||
constexpr uint32_t shadow = 1 << 7;
|
||||
constexpr uint32_t volume = 1 << 6;
|
||||
|
||||
namespace col_type {
|
||||
constexpr uint32_t packed_color = 0 << 4;
|
||||
constexpr uint32_t floating_color = 1 << 4;
|
||||
constexpr uint32_t intensity_mode_1 = 2 << 4;
|
||||
constexpr uint32_t intensity_mode_2 = 3 << 4;
|
||||
}
|
||||
|
||||
constexpr uint32_t texture = 1 << 3;
|
||||
constexpr uint32_t offset = 1 << 2;
|
||||
constexpr uint32_t gouraud = 1 << 1;
|
||||
constexpr uint32_t _16bit_uv = 1 << 0;
|
||||
}
|
||||
|
||||
void vertex(volatile uint32_t * buf,
|
||||
const float x,
|
||||
const float y,
|
||||
const float z,
|
||||
const uint32_t base_color,
|
||||
bool end_of_strip
|
||||
)
|
||||
{
|
||||
volatile vertex_polygon_type_0 * parameter = reinterpret_cast<volatile vertex_polygon_type_0 *>(buf);
|
||||
|
||||
parameter->parameter_control_word = para_control::para_type::vertex_parameter;
|
||||
|
||||
if (end_of_strip)
|
||||
parameter->parameter_control_word |= para_control::end_of_strip;
|
||||
|
||||
parameter->x = x;
|
||||
parameter->y = y;
|
||||
parameter->z = z;
|
||||
parameter->_res0 = 0;
|
||||
parameter->_res1 = 0;
|
||||
parameter->base_color = base_color;
|
||||
parameter->_res2 = 0;
|
||||
}
|
||||
|
||||
void triangle(volatile uint32_t * buf)
|
||||
{
|
||||
volatile global_polygon_type_0 * parameter = reinterpret_cast<volatile global_polygon_type_0 *>(buf);
|
||||
|
||||
parameter->parameter_control_word = para_control::para_type::polygon_or_modifier_volume
|
||||
| para_control::list_type::opaque
|
||||
| obj_control::col_type::packed_color;
|
||||
|
||||
parameter->isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::always
|
||||
| isp_tsp_instruction_word::culling_mode::no_culling;
|
||||
|
||||
parameter->tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one
|
||||
| tsp_instruction_word::dst_alpha_instr::zero
|
||||
| tsp_instruction_word::fog_control::no_fog;
|
||||
parameter->texture_control_word = 0;
|
||||
parameter->_res0 = 0;
|
||||
parameter->_res1 = 0;
|
||||
parameter->data_size_for_sort_dma = 0;
|
||||
parameter->next_address_for_sort_dma = 0;
|
||||
}
|
||||
|
||||
void textured_vertex(volatile uint32_t * buf,
|
||||
const float x,
|
||||
const float y,
|
||||
const float z,
|
||||
const float u,
|
||||
const float v,
|
||||
const uint32_t base_color,
|
||||
const uint32_t offset_color,
|
||||
bool end_of_strip
|
||||
)
|
||||
{
|
||||
volatile vertex_polygon_type_3 * parameter = reinterpret_cast<volatile vertex_polygon_type_3 *>(buf);
|
||||
|
||||
parameter->parameter_control_word = para_control::para_type::vertex_parameter;
|
||||
|
||||
if (end_of_strip)
|
||||
parameter->parameter_control_word |= para_control::end_of_strip;
|
||||
|
||||
parameter->x = x;
|
||||
parameter->y = y;
|
||||
parameter->z = z;
|
||||
parameter->u = u;
|
||||
parameter->v = v;
|
||||
parameter->base_color = base_color;
|
||||
parameter->offset_color = offset_color;
|
||||
}
|
||||
|
||||
void textured_triangle(volatile uint32_t * buf,
|
||||
uint32_t texture_address)
|
||||
{
|
||||
volatile global_polygon_type_0 * parameter = reinterpret_cast<volatile global_polygon_type_0 *>(buf);
|
||||
|
||||
parameter->parameter_control_word = para_control::para_type::polygon_or_modifier_volume
|
||||
| para_control::list_type::opaque
|
||||
| obj_control::col_type::packed_color
|
||||
| obj_control::texture;
|
||||
|
||||
parameter->isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::always
|
||||
| isp_tsp_instruction_word::culling_mode::no_culling;
|
||||
|
||||
// <Note> Because a value of "0.0" is invalid for [MIP-Map] D [adjust], it must not be specified.
|
||||
parameter->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::mip_map_d_adjust(0b0100) // 1.0 (2.2 fixed-point)
|
||||
//| tsp_instruction_word::filter_mode::bilinear_filter
|
||||
//| tsp_instruction_word::clamp_uv::uv
|
||||
//| tsp_instruction_word::flip_uv::uv
|
||||
| tsp_instruction_word::texture_u_size::_128 // 128px
|
||||
| tsp_instruction_word::texture_v_size::_128; // 128px
|
||||
|
||||
if ((texture_address & 63) != 0) while (1);
|
||||
parameter->texture_control_word = texture_control_word::pixel_format::_565
|
||||
| texture_control_word::scan_order // non-twiddled
|
||||
| texture_control_word::texture_address(texture_address / 8);
|
||||
|
||||
parameter->_res0 = 0;
|
||||
parameter->_res1 = 0;
|
||||
parameter->data_size_for_sort_dma = 0;
|
||||
parameter->next_address_for_sort_dma = 0;
|
||||
}
|
||||
|
||||
void end_of_list(volatile uint32_t * buf)
|
||||
{
|
||||
volatile global_end_of_list * parameter = reinterpret_cast<volatile global_end_of_list *>(buf);
|
||||
|
||||
parameter->parameter_control_word = para_control::para_type::end_of_list;
|
||||
parameter->_res0 = 0;
|
||||
parameter->_res1 = 0;
|
||||
parameter->_res2 = 0;
|
||||
parameter->_res3 = 0;
|
||||
parameter->_res4 = 0;
|
||||
parameter->_res5 = 0;
|
||||
parameter->_res6 = 0;
|
||||
}
|
@ -1,30 +1,314 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
void vertex(volatile uint32_t * buf,
|
||||
const float x,
|
||||
const float y,
|
||||
const float z,
|
||||
const uint32_t base_color,
|
||||
bool end_of_strip
|
||||
);
|
||||
#include "float_uint32.h"
|
||||
#include "isp_tsp.h"
|
||||
|
||||
void triangle(volatile uint32_t * buf);
|
||||
namespace para_control {
|
||||
namespace para_type {
|
||||
constexpr uint32_t end_of_list = 0 << 29;
|
||||
constexpr uint32_t user_tile_clip = 1 << 29;
|
||||
constexpr uint32_t object_list_set = 2 << 29;
|
||||
constexpr uint32_t polygon_or_modifier_volume = 4 << 29;
|
||||
constexpr uint32_t sprite = 5 << 29;
|
||||
constexpr uint32_t vertex_parameter = 7 << 29;
|
||||
}
|
||||
|
||||
void textured_vertex(volatile uint32_t * buf,
|
||||
const float x,
|
||||
const float y,
|
||||
const float z,
|
||||
const float u,
|
||||
const float v,
|
||||
const uint32_t base_color,
|
||||
const uint32_t offset_color,
|
||||
bool end_of_strip
|
||||
);
|
||||
constexpr uint32_t end_of_strip = 1 << 28;
|
||||
|
||||
void textured_triangle(volatile uint32_t * buf,
|
||||
uint32_t texture_address
|
||||
);
|
||||
namespace list_type {
|
||||
constexpr uint32_t opaque = 0 << 24;
|
||||
constexpr uint32_t opaque_modifier_volume = 1 << 24;
|
||||
constexpr uint32_t translucent = 2 << 24;
|
||||
constexpr uint32_t translucent_modifier_volume = 3 << 24;
|
||||
constexpr uint32_t punch_through = 4 << 24;
|
||||
}
|
||||
}
|
||||
|
||||
void end_of_list(volatile uint32_t * buf);
|
||||
namespace group_control {
|
||||
constexpr uint32_t group_en = 1 << 23;
|
||||
|
||||
namespace strip_len {
|
||||
constexpr uint32_t _1_strip = 0 << 18;
|
||||
constexpr uint32_t _2_strip = 1 << 18;
|
||||
constexpr uint32_t _4_strip = 2 << 18;
|
||||
constexpr uint32_t _6_strip = 3 << 18;
|
||||
}
|
||||
|
||||
namespace user_clip {
|
||||
constexpr uint32_t disabled = 0 << 16;
|
||||
constexpr uint32_t inside_enable = 2 << 16;
|
||||
constexpr uint32_t outside_enable = 3 << 16;
|
||||
}
|
||||
}
|
||||
|
||||
namespace obj_control {
|
||||
constexpr uint32_t shadow = 1 << 7;
|
||||
constexpr uint32_t volume = 1 << 6;
|
||||
|
||||
namespace col_type {
|
||||
constexpr uint32_t packed_color = 0 << 4;
|
||||
constexpr uint32_t floating_color = 1 << 4;
|
||||
constexpr uint32_t intensity_mode_1 = 2 << 4;
|
||||
constexpr uint32_t intensity_mode_2 = 3 << 4;
|
||||
}
|
||||
|
||||
constexpr uint32_t texture = 1 << 3;
|
||||
constexpr uint32_t offset = 1 << 2;
|
||||
constexpr uint32_t gouraud = 1 << 1;
|
||||
constexpr uint32_t _16bit_uv = 1 << 0;
|
||||
}
|
||||
|
||||
static_assert((sizeof (float)) == (sizeof (uint32_t)));
|
||||
|
||||
struct vertex_polygon_type_0 {
|
||||
uint32_t parameter_control_word;
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
uint32_t _res0;
|
||||
uint32_t _res1;
|
||||
uint32_t base_color;
|
||||
uint32_t _res2;
|
||||
|
||||
vertex_polygon_type_0(const float x,
|
||||
const float y,
|
||||
const float z,
|
||||
const uint32_t base_color,
|
||||
const bool end_of_strip
|
||||
)
|
||||
: parameter_control_word( para_control::para_type::vertex_parameter
|
||||
| (end_of_strip ? para_control::end_of_strip : 0)
|
||||
)
|
||||
, x(x)
|
||||
, y(y)
|
||||
, z(z)
|
||||
, _res0(0)
|
||||
, _res1(0)
|
||||
, base_color(base_color)
|
||||
, _res2(0)
|
||||
{ }
|
||||
};
|
||||
|
||||
struct vertex_polygon_type_3 {
|
||||
uint32_t parameter_control_word;
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float u;
|
||||
float v;
|
||||
uint32_t base_color;
|
||||
uint32_t offset_color;
|
||||
|
||||
vertex_polygon_type_3(const float x,
|
||||
const float y,
|
||||
const float z,
|
||||
const float u,
|
||||
const float v,
|
||||
const uint32_t base_color,
|
||||
const bool end_of_strip
|
||||
)
|
||||
: parameter_control_word( para_control::para_type::vertex_parameter
|
||||
| (end_of_strip ? para_control::end_of_strip : 0)
|
||||
)
|
||||
, x(x)
|
||||
, y(y)
|
||||
, z(z)
|
||||
, u(u)
|
||||
, v(v)
|
||||
, base_color(base_color)
|
||||
, offset_color(0)
|
||||
{ }
|
||||
};
|
||||
|
||||
static_assert((sizeof (vertex_polygon_type_0)) == 32);
|
||||
static_assert((offsetof (struct vertex_polygon_type_0, parameter_control_word)) == 0x00);
|
||||
static_assert((offsetof (struct vertex_polygon_type_0, x)) == 0x04);
|
||||
static_assert((offsetof (struct vertex_polygon_type_0, y)) == 0x08);
|
||||
static_assert((offsetof (struct vertex_polygon_type_0, z)) == 0x0c);
|
||||
static_assert((offsetof (struct vertex_polygon_type_0, _res0)) == 0x10);
|
||||
static_assert((offsetof (struct vertex_polygon_type_0, _res1)) == 0x14);
|
||||
static_assert((offsetof (struct vertex_polygon_type_0, base_color)) == 0x18);
|
||||
static_assert((offsetof (struct vertex_polygon_type_0, _res2)) == 0x1c);
|
||||
|
||||
struct global_polygon_type_0 {
|
||||
uint32_t parameter_control_word;
|
||||
uint32_t isp_tsp_instruction_word;
|
||||
uint32_t tsp_instruction_word;
|
||||
uint32_t texture_control_word;
|
||||
uint32_t _res0;
|
||||
uint32_t _res1;
|
||||
uint32_t data_size_for_sort_dma;
|
||||
uint32_t next_address_for_sort_dma;
|
||||
|
||||
/*
|
||||
global_polygon_type_0()
|
||||
: parameter_control_word( para_control::para_type::polygon_or_modifier_volume
|
||||
| para_control::list_type::opaque
|
||||
| obj_control::col_type::packed_color )
|
||||
|
||||
, isp_tsp_instruction_word( isp_tsp_instruction_word::depth_compare_mode::always
|
||||
| isp_tsp_instruction_word::culling_mode::no_culling )
|
||||
|
||||
, tsp_instruction_word( tsp_instruction_word::src_alpha_instr::one
|
||||
| tsp_instruction_word::dst_alpha_instr::zero
|
||||
| tsp_instruction_word::fog_control::no_fog )
|
||||
|
||||
, texture_control_word(0)
|
||||
, _res0(0)
|
||||
, _res1(0)
|
||||
, data_size_for_sort_dma(0)
|
||||
, next_address_for_sort_dma(0)
|
||||
{ }
|
||||
*/
|
||||
|
||||
global_polygon_type_0(const uint32_t texture_address)
|
||||
: parameter_control_word( para_control::para_type::polygon_or_modifier_volume
|
||||
| para_control::list_type::opaque
|
||||
| obj_control::col_type::packed_color
|
||||
| obj_control::texture )
|
||||
|
||||
, isp_tsp_instruction_word( isp_tsp_instruction_word::depth_compare_mode::always
|
||||
| isp_tsp_instruction_word::culling_mode::no_culling )
|
||||
|
||||
// <Note> Because a value of "0.0" is invalid for [MIP-Map] D [adjust], it must not be specified.
|
||||
, 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::mip_map_d_adjust(0b0100) // 1.0 (2.2 fixed-point)
|
||||
//| tsp_instruction_word::filter_mode::bilinear_filter
|
||||
//| tsp_instruction_word::clamp_uv::uv
|
||||
//| tsp_instruction_word::flip_uv::uv
|
||||
| tsp_instruction_word::texture_u_size::_128 // 128px
|
||||
| tsp_instruction_word::texture_v_size::_128 ) // 128px
|
||||
|
||||
, texture_control_word( texture_control_word::pixel_format::_565
|
||||
| texture_control_word::scan_order // non-twiddled
|
||||
| texture_control_word::texture_address(texture_address / 8) )
|
||||
|
||||
, _res0(0)
|
||||
, _res1(0)
|
||||
, data_size_for_sort_dma(0)
|
||||
, next_address_for_sort_dma(0)
|
||||
{ if ((texture_address & 63) != 0) { while (1); } }
|
||||
};
|
||||
|
||||
static_assert((sizeof (global_polygon_type_0)) == 32);
|
||||
static_assert((offsetof (struct global_polygon_type_0, parameter_control_word)) == 0x00);
|
||||
static_assert((offsetof (struct global_polygon_type_0, isp_tsp_instruction_word)) == 0x04);
|
||||
static_assert((offsetof (struct global_polygon_type_0, tsp_instruction_word)) == 0x08);
|
||||
static_assert((offsetof (struct global_polygon_type_0, texture_control_word)) == 0x0c);
|
||||
static_assert((offsetof (struct global_polygon_type_0, _res0)) == 0x10);
|
||||
static_assert((offsetof (struct global_polygon_type_0, _res1)) == 0x14);
|
||||
static_assert((offsetof (struct global_polygon_type_0, data_size_for_sort_dma)) == 0x18);
|
||||
static_assert((offsetof (struct global_polygon_type_0, next_address_for_sort_dma)) == 0x1c);
|
||||
|
||||
struct global_sprite {
|
||||
uint32_t parameter_control_word;
|
||||
uint32_t isp_tsp_instruction_word;
|
||||
uint32_t tsp_instruction_word;
|
||||
uint32_t texture_control_word;
|
||||
uint32_t base_color;
|
||||
uint32_t offset_color;
|
||||
uint32_t data_size_for_sort_dma;
|
||||
uint32_t next_address_for_sort_dma;
|
||||
|
||||
global_sprite(const uint32_t base_color)
|
||||
: parameter_control_word( para_control::para_type::sprite
|
||||
| para_control::list_type::opaque )
|
||||
, isp_tsp_instruction_word( isp_tsp_instruction_word::depth_compare_mode::always
|
||||
| isp_tsp_instruction_word::culling_mode::no_culling )
|
||||
, tsp_instruction_word( tsp_instruction_word::src_alpha_instr::one
|
||||
| tsp_instruction_word::dst_alpha_instr::zero
|
||||
| tsp_instruction_word::fog_control::no_fog)
|
||||
, texture_control_word(0)
|
||||
, base_color(base_color)
|
||||
, offset_color(0)
|
||||
, data_size_for_sort_dma(0)
|
||||
, next_address_for_sort_dma(0)
|
||||
{ }
|
||||
};
|
||||
|
||||
static_assert((sizeof (global_sprite)) == 32);
|
||||
|
||||
struct vertex_sprite_type_0 {
|
||||
uint32_t parameter_control_word;
|
||||
float ax;
|
||||
float ay;
|
||||
float az;
|
||||
float bx;
|
||||
float by;
|
||||
float bz;
|
||||
float cx;
|
||||
|
||||
float cy;
|
||||
float cz;
|
||||
float dx;
|
||||
float dy;
|
||||
float _res0;
|
||||
float _res1;
|
||||
float _res2;
|
||||
float _res3;
|
||||
|
||||
vertex_sprite_type_0(const float ax,
|
||||
const float ay,
|
||||
const float az,
|
||||
const float bx,
|
||||
const float by,
|
||||
const float bz,
|
||||
const float cx,
|
||||
const float cy,
|
||||
const float cz,
|
||||
const float dx,
|
||||
const float dy)
|
||||
: parameter_control_word(para_control::para_type::vertex_parameter)
|
||||
, ax(ax)
|
||||
, ay(ay)
|
||||
, az(az)
|
||||
, bx(bx)
|
||||
, by(by)
|
||||
, bz(bz)
|
||||
, cx(cx)
|
||||
, cy(cy)
|
||||
, dx(dx)
|
||||
, dy(dy)
|
||||
, _res0(0)
|
||||
, _res1(0)
|
||||
, _res2(0)
|
||||
, _res3(0)
|
||||
{}
|
||||
};
|
||||
|
||||
static_assert((sizeof (vertex_sprite_type_0)) == 64);
|
||||
|
||||
struct global_end_of_list {
|
||||
uint32_t parameter_control_word;
|
||||
uint32_t _res0;
|
||||
uint32_t _res1;
|
||||
uint32_t _res2;
|
||||
uint32_t _res3;
|
||||
uint32_t _res4;
|
||||
uint32_t _res5;
|
||||
uint32_t _res6;
|
||||
|
||||
global_end_of_list()
|
||||
: parameter_control_word(para_control::para_type::end_of_list)
|
||||
, _res0(0)
|
||||
, _res1(0)
|
||||
, _res2(0)
|
||||
, _res3(0)
|
||||
, _res4(0)
|
||||
, _res5(0)
|
||||
, _res6(0)
|
||||
{ }
|
||||
};
|
||||
|
||||
static_assert((sizeof (global_end_of_list)) == 32);
|
||||
static_assert((offsetof (struct global_end_of_list, parameter_control_word)) == 0x00);
|
||||
static_assert((offsetof (struct global_end_of_list, _res0)) == 0x04);
|
||||
static_assert((offsetof (struct global_end_of_list, _res1)) == 0x08);
|
||||
static_assert((offsetof (struct global_end_of_list, _res2)) == 0x0c);
|
||||
static_assert((offsetof (struct global_end_of_list, _res3)) == 0x10);
|
||||
static_assert((offsetof (struct global_end_of_list, _res4)) == 0x14);
|
||||
static_assert((offsetof (struct global_end_of_list, _res5)) == 0x18);
|
||||
static_assert((offsetof (struct global_end_of_list, _res6)) == 0x1c);
|
||||
|
6
main.cpp
6
main.cpp
@ -126,16 +126,14 @@ void main()
|
||||
}
|
||||
|
||||
int frame = 0;
|
||||
int ix = 0;
|
||||
|
||||
while (true) {
|
||||
v_sync_out();
|
||||
v_sync_in();
|
||||
|
||||
ta_polygon_converter_init();
|
||||
uint32_t ta_parameter_count = scene_transform(&scene[0]);
|
||||
uint32_t ta_parameter_size = ta_parameter_count * 32; /* 32 bytes per parameter */
|
||||
ta_polygon_converter_transfer(&scene[0], ta_parameter_size);
|
||||
uint32_t ta_parameter_size = scene_transform(scene);
|
||||
ta_polygon_converter_transfer(scene, ta_parameter_size);
|
||||
ta_wait_opaque_list();
|
||||
core_start_render(frame);
|
||||
|
||||
|
95
scene.cpp
95
scene.cpp
@ -12,7 +12,7 @@
|
||||
-0.5,0.5 | 0.5,0.5
|
||||
*/
|
||||
|
||||
struct triangle {
|
||||
struct vertex0 {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
@ -21,26 +21,75 @@ struct triangle {
|
||||
uint32_t color;
|
||||
};
|
||||
|
||||
const struct triangle scene_triangle[4] = {
|
||||
const struct vertex0 scene_triangle[4] = {
|
||||
{ -0.5f, 0.5f, 0.f, 0.f , 128.f/128.f, 0x00000000}, // the first two base colors in a
|
||||
{ -0.5f, -0.5f, 0.f, 0.f , 0.f , 0x00000000}, // triangle strip are ignored
|
||||
{ 0.5f, 0.5f, 0.f, 128.f/128.f, 128.f/128.f, 0xffff00ff},
|
||||
{ 0.5f, -0.5f, 0.f, 128.f/128.f, 0.f , 0xffffff00},
|
||||
};
|
||||
|
||||
static float theta = 0;
|
||||
constexpr float one_degree = 0.01745329f / 2.f;
|
||||
struct vertex1 {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
};
|
||||
|
||||
uint32_t scene_transform(volatile uint32_t * scene)
|
||||
const struct vertex1 scene_quad[4] = {
|
||||
{ -0.5f, 0.5f, 0.f },
|
||||
{ -0.5f, -0.5f, 0.f },
|
||||
{ 0.5f, -0.5f, 0.f },
|
||||
{ 0.5f, 0.5f, 0.f },
|
||||
};
|
||||
|
||||
struct scene_quad_ta_parameters {
|
||||
global_sprite sprite;
|
||||
vertex_sprite_type_0 vertex;
|
||||
global_end_of_list end_of_list;
|
||||
};
|
||||
|
||||
static_assert((sizeof (scene_quad_ta_parameters)) == 32 * 4);
|
||||
|
||||
uint32_t scene_transform_quad(uint32_t * _scene)
|
||||
{
|
||||
uint32_t ix = 0;
|
||||
auto scene = reinterpret_cast<scene_quad_ta_parameters *>(&_scene[0]);
|
||||
|
||||
uint32_t address = (offsetof (struct texture_memory_alloc, texture));
|
||||
textured_triangle(&scene[(32 * ix) / 4],
|
||||
address);
|
||||
ix++;
|
||||
uint32_t base_color = 0xffffff00;
|
||||
scene->sprite = global_sprite(base_color);
|
||||
scene->vertex = vertex_sprite_type_0(scene_quad[0].x * 240 + 320,
|
||||
scene_quad[0].y * 240 + 240,
|
||||
1 / (scene_quad[0].z + 10),
|
||||
scene_quad[1].x * 240 + 320,
|
||||
scene_quad[1].y * 240 + 240,
|
||||
1 / (scene_quad[1].z + 10),
|
||||
scene_quad[2].x * 240 + 320,
|
||||
scene_quad[2].y * 240 + 240,
|
||||
1 / (scene_quad[2].z + 10),
|
||||
scene_quad[3].x * 240 + 320,
|
||||
scene_quad[3].y * 240 + 240);
|
||||
scene->end_of_list = global_end_of_list();
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
return (sizeof (scene_quad_ta_parameters));
|
||||
}
|
||||
|
||||
static float theta = 0;
|
||||
constexpr float half_degree = 0.01745329f / 2.f;
|
||||
|
||||
union ta_parameter {
|
||||
struct global_polygon_type_0 global_polygon_type_0;
|
||||
struct vertex_polygon_type_3 vertex_polygon_type_3;
|
||||
struct global_end_of_list global_end_of_list;
|
||||
};
|
||||
|
||||
extern void serial_string(const char * s);
|
||||
|
||||
uint32_t scene_transform(uint32_t * _scene)
|
||||
{
|
||||
ta_parameter * scene = reinterpret_cast<ta_parameter *>(&_scene[0]);
|
||||
int ix = 0;
|
||||
uint32_t texture_address = (offsetof (struct texture_memory_alloc, texture));
|
||||
scene[ix++].global_polygon_type_0 = global_polygon_type_0(texture_address);
|
||||
|
||||
for (uint32_t i = 0; i < 4; i++) {
|
||||
bool end_of_strip = i == 3;
|
||||
|
||||
float x = scene_triangle[i].x;
|
||||
@ -56,22 +105,18 @@ uint32_t scene_transform(volatile uint32_t * scene)
|
||||
x += 320.f;
|
||||
y += 240.f;
|
||||
|
||||
textured_vertex(&scene[(32 * ix) / 4],
|
||||
x, // x
|
||||
y, // y
|
||||
1.f / (z + 10.f), // z
|
||||
scene_triangle[i].u, // u
|
||||
scene_triangle[i].v, // v
|
||||
scene_triangle[i].color, // base_color
|
||||
0, // offset_color
|
||||
end_of_strip);
|
||||
ix++;
|
||||
scene[ix++].vertex_polygon_type_3 = vertex_polygon_type_3(x, // x
|
||||
y, // y
|
||||
1.f / (z + 10.f), // z
|
||||
scene_triangle[i].u, // u
|
||||
scene_triangle[i].v, // v
|
||||
scene_triangle[i].color, // base_color
|
||||
end_of_strip);
|
||||
}
|
||||
|
||||
end_of_list(&scene[(32 * ix) / 4]);
|
||||
ix++;
|
||||
scene[ix++].global_end_of_list = global_end_of_list();
|
||||
|
||||
theta += one_degree;
|
||||
theta += half_degree;
|
||||
|
||||
return ix;
|
||||
return ix * 32;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user