Compare commits

...

10 Commits

Author SHA1 Message Date
1cfbda2dcd example: add clipping2
Unlike the previous clipping example, this clipping example preserves
surface normals.
2024-01-27 10:03:01 +08:00
e54d762a20 example/viewing_system: add "viewer" concept 2024-01-11 15:34:55 +08:00
6836790205 add viewing_system
This is inspirted by the book "3D Computer Graphics" by Alan Watt.
2024-01-06 18:43:57 +08:00
c9b57abf81 example: add clipping 2024-01-06 11:32:41 +08:00
1f6a29f379 example: update several examples 2024-01-03 23:32:37 +08:00
dcb9f36120 sh7091_bits.ods: partial
Notably missing is:

- BSC (PDTRA / PCTRA)

This also updates a handful of files to use the new sh7091_bits.hpp.
2024-01-01 23:43:06 +08:00
0b6c650ebd common.mk: add headless csv build rule 2024-01-01 00:58:10 +08:00
e8aea009c6 example: add heart
I originally planned to make this a render-to-texture demo, but this
is fairly interesting by itself.
2023-12-31 20:19:41 +08:00
b6457bf687 modifier_volume_with_two_volumes: add simple controller input
The plane can be moved around with the analog stick and analog
triggers of the controller connected to port 1.
2023-12-30 23:08:13 +08:00
8e534e9e25 example: modifier_volume_with_two_volumes: textured 2023-12-30 22:22:50 +08:00
75 changed files with 11477 additions and 1627 deletions

1
.gitignore vendored
View File

@ -13,3 +13,4 @@ __pycache__
scramble scramble
cdi4dc cdi4dc
tools/ttf_outline tools/ttf_outline
*.blend1

View File

@ -1,34 +0,0 @@
#include "type.hpp"
#include "sh7091.hpp"
#include "sh7091_bits.hpp"
#include "cache.hpp"
extern volatile reg32 sh7091_ic_a[256][(1 << 5) / 4] __asm("sh7091_ic_a");
extern volatile reg32 sh7091_oc_a[512][(1 << 5) / 4] __asm("sh7091_oc_a");
namespace cache {
void init()
{
for (int i = 0; i < 256; i++) {
sh7091_ic_a[i][0] = 0;
}
for (int i = 0; i < 512; i++) {
sh7091_oc_a[i][0] = 0;
}
sh7091.CCN.CCR = CCR__ICI // instruction cache invalidate
| CCR__ICE // instruction cache enable
| CCR__OCI // operand cache invalidate
| CCR__OCE // operand cache enable
// | CCR__CB // enable copy-back mode for the P1 area
;
sh7091.CCN.MMUCR = 0;
asm volatile ("nop;nop;nop;nop;nop;nop;nop;nop;");
}
}

View File

@ -2,7 +2,7 @@ MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
DIR := $(dir $(MAKEFILE_PATH)) DIR := $(dir $(MAKEFILE_PATH))
LIB ?= . LIB ?= .
OPT ?= -O3 OPT ?= -O2
DEBUG ?= -g -gdwarf-4 DEBUG ?= -g -gdwarf-4
GENERATED ?= GENERATED ?=
@ -55,7 +55,7 @@ IP_OBJ = \
START_OBJ = \ START_OBJ = \
start.o \ start.o \
runtime.o \ runtime.o \
cache.o sh7091/cache.o
%.bin.o: %.bin %.bin.o: %.bin
$(BUILD_BINARY_O) $(BUILD_BINARY_O)
@ -130,18 +130,33 @@ audio.pcm:
%.data.o: %.data %.data.o: %.data
$(BUILD_BINARY_O) $(BUILD_BINARY_O)
regs/%.csv: regs/%.ods
libreoffice --headless -convert-to csv:"Text - txt - csv (StarCalc)":44,34,76,,,,true --outdir regs/ $<
maple/maple_bus_commands.hpp: regs/maple_bus_commands.csv regs/gen/maple_bus_commands.py maple/maple_bus_commands.hpp: regs/maple_bus_commands.csv regs/gen/maple_bus_commands.py
python regs/gen/maple_bus_commands.py $< > $@ python regs/gen/maple_bus_commands.py $< > $@
maple/maple_bus_bits.hpp: regs/maple_bus_bits.csv regs/gen/core_bits.py maple/maple_bus_bits.hpp: regs/maple_bus_bits.csv regs/gen/core_bits.py
python regs/gen/core_bits.py $< > $@ python regs/gen/core_bits.py $< > $@
holly/core_bits.hpp: regs/core_bits.csv regs/gen/core_bits.py
python regs/gen/core_bits.py $< > $@
holly/holly.hpp: regs/holly.csv regs/gen/holly.py
python regs/gen/holly.py $< > $@
holly/ta_global_parameter.hpp: regs/global_parameter_format.csv regs/gen/ta_parameter_format.py holly/ta_global_parameter.hpp: regs/global_parameter_format.csv regs/gen/ta_parameter_format.py
python regs/gen/ta_parameter_format.py $< ta_global_parameter > $@ python regs/gen/ta_parameter_format.py $< ta_global_parameter > $@
holly/ta_vertex_parameter.hpp: regs/vertex_parameter_format.csv regs/gen/ta_parameter_format.py holly/ta_vertex_parameter.hpp: regs/vertex_parameter_format.csv regs/gen/ta_parameter_format.py
python regs/gen/ta_parameter_format.py $< ta_vertex_parameter > $@ python regs/gen/ta_parameter_format.py $< ta_vertex_parameter > $@
sh7091/sh7091.hpp: regs/sh7091.csv regs/gen/sh7091.py
python regs/gen/sh7091.py $< > $@
sh7091/sh7091_bits.hpp: regs/sh7091_bits.csv regs/gen/core_bits.py
python regs/gen/core_bits.py $< > $@
clean: clean:
find -P \ find -P \
-regextype posix-egrep \ -regextype posix-egrep \

319
example/clipping.cpp Normal file
View File

@ -0,0 +1,319 @@
#include <cstdint>
#include <bit>
#include "align.hpp"
#include "vga.hpp"
#include "holly/holly.hpp"
#include "holly/core.hpp"
#include "holly/core_bits.hpp"
#include "holly/ta_fifo_polygon_converter.hpp"
#include "holly/ta_parameter.hpp"
#include "holly/ta_vertex_parameter.hpp"
#include "holly/ta_global_parameter.hpp"
#include "holly/ta_bits.hpp"
#include "holly/isp_tsp.hpp"
#include "holly/region_array.hpp"
#include "holly/background.hpp"
#include "holly/texture_memory_alloc.hpp"
#include "memorymap.hpp"
#include "sh7091/serial.hpp"
#include "geometry/circle.hpp"
#include "math/vec4.hpp"
#include "math/math.hpp"
#include "maple/maple.hpp"
#include "maple/maple_impl.hpp"
#include "maple/maple_bus_bits.hpp"
#include "maple/maple_bus_commands.hpp"
#include "maple/maple_bus_ft0.hpp"
uint32_t _command_buf[1024 / 4 + 32];
uint32_t _receive_buf[1024 / 4 + 32];
static ft0::data_transfer::data_format data[4];
void do_get_condition(uint32_t * command_buf,
uint32_t * receive_buf)
{
using command_type = get_condition;
using response_type = data_transfer<ft0::data_transfer::data_format>;
get_condition::data_fields data_fields = {
.function_type = std::byteswap(function_type::controller)
};
maple::init_host_command_all_ports<command_type, response_type>(command_buf, receive_buf,
data_fields);
maple::dma_start(command_buf);
using command_response_type = struct maple::command_response<response_type::data_fields>;
for (uint8_t port = 0; port < 4; port++) {
auto response = reinterpret_cast<command_response_type *>(receive_buf);
auto& bus_data = response[port].bus_data;
if (bus_data.command_code != response_type::command_code) {
return;
}
auto& data_fields = bus_data.data_fields;
if ((data_fields.function_type & std::byteswap(function_type::controller)) == 0) {
return;
}
data[port].analog_axis_3 = data_fields.data.analog_axis_3;
data[port].analog_axis_4 = data_fields.data.analog_axis_4;
}
}
vec3 intersection(vec3& a, vec3& b, vec3& n)
{
const float t = (-dot(n, a)) / dot(n, b - a);
return a + t * (b - a);
}
void transform(ta_parameter_writer& parameter,
const vec3 * vertices,
const face_vn& face,
const vec4& color,
const vec3& position,
const bool enable_clipping
)
{
const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
| para_control::list_type::opaque
| obj_control::col_type::floating_color
| obj_control::gouraud;
const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
| isp_tsp_instruction_word::culling_mode::no_culling;
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;
constexpr uint32_t strip_length = 3;
vec3 points[strip_length * 2];
uint32_t positive = 0;
uint32_t negative = 0;
vec3 plane_normal = {-1.f, 0.f, 0.f};
// object transform and clip
for (uint32_t i = 0; i < strip_length; i++) {
uint32_t vertex_ix = face[i].vertex;
auto vertex = vertices[vertex_ix];
vertex = (vertex * 0.5f);
// rotate 90° around the X axis
float x = vertex.x;
float y = vertex.z;
float z = vertex.y;
// object transform
x += position.x; // object space
y += position.y; // object space
z += position.z; // object space
// clip
auto point = vec3(x, y, z);
float distance = dot(plane_normal, point);
if ((!enable_clipping) || distance > 0.0f) {
points[0 + positive] = point;
positive += 1;
} else { // is negative (or intersects)
points[(strip_length - 1) - negative] = point;
negative += 1;
}
}
uint32_t num_tris = 0;
if ((!enable_clipping) || positive == 3) {
num_tris = 1;
// nothing to clip
} else if (positive == 0) {
num_tris = 0;
// clip everything
} else if (positive == 1) {
num_tris = 1;
auto& A = points[0]; // positive
auto& B = points[1]; // negative
auto& C = points[2]; // negative
/*
// A
// /\
// / \
// -AB----AC--
// / \
// B________C
*/
auto AB_ = intersection(A, B, plane_normal);
auto AC_ = intersection(A, C, plane_normal);
points[0] = A;
points[1] = AC_;
points[2] = AB_;
} else if (positive == 2) {
num_tris = 2;
auto& A = points[0]; // positive
auto& B = points[1]; // positive
auto& C = points[2]; // negative
// A _____ B
// \ /
//--AC---BC--
// \ /
// \/
// C
auto AC_ = intersection(A, C, plane_normal);
auto BC_ = intersection(B, C, plane_normal);
points[0] = A;
points[1] = B;
points[2] = AC_;
points[3] = B;
points[4] = BC_;
points[5] = AC_;
}
for (uint32_t j = 0; j < num_tris; j++) {
parameter.append<ta_global_parameter::polygon_type_0>() =
ta_global_parameter::polygon_type_0(parameter_control_word,
isp_tsp_instruction_word,
tsp_instruction_word,
0, // texture_control_word
0, // data_size_for_sort_dma
0 // next_address_for_sort_dma
);
for (uint32_t i = 0; i < strip_length; i++) {
float x = points[3 * j + i].x;
float y = points[3 * j + i].y;
float z = points[3 * j + i].z;
// camera transform
z += 1;
// screen space transform
x *= 240.f;
y *= 240.f;
x += 320.f;
y += 240.f;
z = 1 / z;
bool end_of_strip = i == strip_length - 1;
parameter.append<ta_vertex_parameter::polygon_type_1>() =
ta_vertex_parameter::polygon_type_1(polygon_vertex_parameter_control_word(end_of_strip),
x, y, z,
1.0f, // alpha
(i == 0) ? 1.0f : 0.0f, // r
(i == 1) ? 1.0f : 0.0f, // g
(i == 2) ? 1.0f : 0.0f // b
);
}
}
}
void init_texture_memory(const struct opb_size& opb_size)
{
auto mem = reinterpret_cast<volatile texture_memory_alloc *>(texture_memory32);
background_parameter(mem->background, 0xff220000);
region_array2(mem->region_array,
(offsetof (struct texture_memory_alloc, object_list)),
640 / 32, // width
480 / 32, // height
opb_size
);
}
uint32_t _ta_parameter_buf[((32 * 8192) + 32) / 4];
void main()
{
uint32_t * command_buf = align_32byte(_command_buf);
uint32_t * receive_buf = align_32byte(_receive_buf);
vga();
// The address of `ta_parameter_buf` must be a multiple of 32 bytes.
// This is mandatory for ch2-dma to the ta fifo polygon converter.
uint32_t * ta_parameter_buf = align_32byte(_ta_parameter_buf);
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::_16x4byte;
constexpr struct opb_size opb_size = { .opaque = 16 * 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();
init_texture_memory(opb_size);
uint32_t frame_ix = 0;
constexpr uint32_t num_frames = 1;
float theta = 0;
float x_pos = 0;
float y_pos = 0;
while (1) {
do_get_condition(command_buf, receive_buf);
ta_polygon_converter_init(opb_size.total(),
ta_alloc,
640 / 32,
480 / 32);
float x_ = static_cast<float>(data[0].analog_axis_3 - 0x80) / 127.f;
float y_ = static_cast<float>(data[0].analog_axis_4 - 0x80) / 127.f;
if (x_ > x_pos) x_pos += (0.09f * ((x_ - x_pos) * (x_ - x_pos)));
if (x_ < x_pos) x_pos -= (0.09f * ((x_ - x_pos) * (x_ - x_pos)));
if (y_ > y_pos) y_pos += (0.09f * ((y_ - y_pos) * (y_ - y_pos)));
if (y_ < y_pos) y_pos -= (0.09f * ((y_ - y_pos) * (y_ - y_pos)));
auto parameter = ta_parameter_writer(ta_parameter_buf);
for (uint32_t i = 0; i < circle::num_faces; i++) {
/*
transform(parameter,
circle::vertices,
circle::faces[i],
vec4{1.0f, 0.5f, 0.5f, 0.0f} * (((i/1.2f) * (1.f / circle::num_faces)) + (1.f/1.2f)), // color
{x_pos * 2, y_pos * 2, 1.0f}, // position
false // clipping
);
*/
transform(parameter,
circle::vertices,
circle::faces[i],
{1.0f, 1.0f, 0.0f, 0.0f}, // color
{x_pos * 2, y_pos * 2, 0.0f}, // position
true // clipping
);
}
parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
ta_polygon_converter_transfer(ta_parameter_buf, parameter.offset);
ta_wait_opaque_list();
core_start_render(frame_ix, num_frames);
v_sync_in();
core_wait_end_of_render_video(frame_ix, num_frames);
frame_ix += 1;
theta += (2.f * pi) / 720.f;
}
}

294
example/clipping2.cpp Normal file
View File

@ -0,0 +1,294 @@
#include <cstdint>
#include <bit>
#include "align.hpp"
#include "vga.hpp"
#include "holly/holly.hpp"
#include "holly/core.hpp"
#include "holly/core_bits.hpp"
#include "holly/ta_fifo_polygon_converter.hpp"
#include "holly/ta_parameter.hpp"
#include "holly/ta_vertex_parameter.hpp"
#include "holly/ta_global_parameter.hpp"
#include "holly/ta_bits.hpp"
#include "holly/isp_tsp.hpp"
#include "holly/region_array.hpp"
#include "holly/background.hpp"
#include "holly/texture_memory_alloc.hpp"
#include "memorymap.hpp"
#include "sh7091/serial.hpp"
#include "geometry/triangle.hpp"
#include "geometry/circle.hpp"
#include "math/vec4.hpp"
#include "math/math.hpp"
#include "math/geometry.hpp"
#include "maple/maple.hpp"
#include "maple/maple_impl.hpp"
#include "maple/maple_bus_bits.hpp"
#include "maple/maple_bus_commands.hpp"
#include "maple/maple_bus_ft0.hpp"
uint32_t _command_buf[1024 / 4 + 32];
uint32_t _receive_buf[1024 / 4 + 32];
static ft0::data_transfer::data_format data[4];
void do_get_condition(uint32_t * command_buf,
uint32_t * receive_buf)
{
using command_type = get_condition;
using response_type = data_transfer<ft0::data_transfer::data_format>;
get_condition::data_fields data_fields = {
.function_type = std::byteswap(function_type::controller)
};
maple::init_host_command_all_ports<command_type, response_type>(command_buf, receive_buf,
data_fields);
maple::dma_start(command_buf);
using command_response_type = struct maple::command_response<response_type::data_fields>;
for (uint8_t port = 0; port < 4; port++) {
auto response = reinterpret_cast<command_response_type *>(receive_buf);
auto& bus_data = response[port].bus_data;
if (bus_data.command_code != response_type::command_code) {
return;
}
auto& data_fields = bus_data.data_fields;
if ((data_fields.function_type & std::byteswap(function_type::controller)) == 0) {
return;
}
data[port].analog_axis_1 = data_fields.data.analog_axis_1;
data[port].analog_axis_2 = data_fields.data.analog_axis_2;
data[port].analog_axis_3 = data_fields.data.analog_axis_3;
data[port].analog_axis_4 = data_fields.data.analog_axis_4;
}
}
constexpr vec3 colors[] = {
{1.f, 0.5f, 0.f},
{0.f, 1.0f, 0.f},
{0.f, 0.5f, 1.f},
{1.f, 0.0f, 1.f},
};
void transform1(ta_parameter_writer& parameter,
const vec3& v,
const vec3& c,
bool end_of_strip)
{
float x = v.x;
float y = v.y;
float z = v.z;
// camera transform
z += 1;
// screen space transform
x *= 240.f;
y *= 240.f;
x += 320.f;
y += 240.f;
z = 1 / z;
parameter.append<ta_vertex_parameter::polygon_type_1>() =
ta_vertex_parameter::polygon_type_1(polygon_vertex_parameter_control_word(end_of_strip),
x, y, z,
1.0f, // alpha
c.r,
c.g,
c.b
);
}
void transform(ta_parameter_writer& parameter,
const vec3 * vertices,
const face_vn& face,
const vec4& color,
const vec3& position,
const float theta,
const bool enable_clipping
)
{
const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
| para_control::list_type::opaque
| obj_control::col_type::floating_color
| obj_control::gouraud;
const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
| isp_tsp_instruction_word::culling_mode::no_culling;
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;
constexpr uint32_t strip_length = 3;
vec3 points[strip_length];
// object transform and clip
for (uint32_t i = 0; i < strip_length; i++) {
uint32_t vertex_ix = face[i].vertex;
auto vertex = vertices[vertex_ix];
vertex = (vertex * 0.5f);
// rotate 90° around the X axis
//float x = vertex.x;
//float y = vertex.z;
//float z = vertex.y;
float x = vertex.x * cos(theta) - vertex.z * sin(theta);
float y = vertex.x * sin(theta) + vertex.z * cos(theta);
float z = vertex.y;
// object transform
x += position.x; // object space
y += position.y; // object space
z += position.z; // object space
// clip
points[i] = vec3(x, y, z);
}
const vec3 plane_point = {0.f, 0.f, 0.f};
const vec3 plane_normal = {-1.f, 0.f, 0.f};
vec3 output[4];
int output_length = geometry::clip_polygon<3>(output, plane_point, plane_normal, &points[0]);
if (output_length >= 3) {
parameter.append<ta_global_parameter::polygon_type_0>() =
ta_global_parameter::polygon_type_0(parameter_control_word,
isp_tsp_instruction_word,
tsp_instruction_word,
0, // texture_control_word
0, // data_size_for_sort_dma
0 // next_address_for_sort_dma
);
transform1(parameter, output[0], colors[0], false);
transform1(parameter, output[1], colors[1], false);
transform1(parameter, output[2], colors[2], true);
}
if (output_length >= 4) {
parameter.append<ta_global_parameter::polygon_type_0>() =
ta_global_parameter::polygon_type_0(parameter_control_word,
isp_tsp_instruction_word,
tsp_instruction_word,
0, // texture_control_word
0, // data_size_for_sort_dma
0 // next_address_for_sort_dma
);
transform1(parameter, output[0], colors[0], false);
transform1(parameter, output[2], colors[2], false);
transform1(parameter, output[3], colors[3], true);
}
/*
A B
D C
*/
}
void init_texture_memory(const struct opb_size& opb_size)
{
auto mem = reinterpret_cast<volatile texture_memory_alloc *>(texture_memory32);
background_parameter(mem->background, 0xff220000);
region_array2(mem->region_array,
(offsetof (struct texture_memory_alloc, object_list)),
640 / 32, // width
480 / 32, // height
opb_size
);
}
uint32_t _ta_parameter_buf[((32 * 8192) + 32) / 4];
void main()
{
uint32_t * command_buf = align_32byte(_command_buf);
uint32_t * receive_buf = align_32byte(_receive_buf);
vga();
// The address of `ta_parameter_buf` must be a multiple of 32 bytes.
// This is mandatory for ch2-dma to the ta fifo polygon converter.
uint32_t * ta_parameter_buf = align_32byte(_ta_parameter_buf);
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::_16x4byte;
constexpr struct opb_size opb_size = { .opaque = 16 * 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();
init_texture_memory(opb_size);
uint32_t frame_ix = 0;
constexpr uint32_t num_frames = 1;
float theta = 0;
float x_pos = 0;
float y_pos = 0;
while (1) {
do_get_condition(command_buf, receive_buf);
ta_polygon_converter_init(opb_size.total(),
ta_alloc,
640 / 32,
480 / 32);
const float l_ = static_cast<float>(data[0].analog_axis_1) * (1.f / 255.f);
const float r_ = static_cast<float>(data[0].analog_axis_2) * (1.f / 255.f);
const float t_ = ((l_ > r_) ? l_ : -r_) * 3.14f / 2.f;
if (t_ > theta) theta += (0.04f * ((t_ - theta) * (t_ - theta)));
else theta -= (0.04f * ((t_ - theta) * (t_ - theta)));
const float x_ = static_cast<float>(data[0].analog_axis_3 - 0x80) / 127.f;
const float y_ = static_cast<float>(data[0].analog_axis_4 - 0x80) / 127.f;
if (x_ > x_pos) x_pos += (0.02f * ((x_ - x_pos) * (x_ - x_pos)));
else x_pos -= (0.02f * ((x_ - x_pos) * (x_ - x_pos)));
if (y_ > y_pos) y_pos += (0.02f * ((y_ - y_pos) * (y_ - y_pos)));
else y_pos -= (0.02f * ((y_ - y_pos) * (y_ - y_pos)));
auto parameter = ta_parameter_writer(ta_parameter_buf);
for (uint32_t i = 0; i < circle::num_faces; i++) {
transform(parameter,
circle::vertices,
circle::faces[i],
{1.0f, 1.0f, 0.0f, 0.0f}, // color
{x_pos * 2, y_pos * 2, 0.0f}, // position
theta,
true // clipping
);
}
parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
ta_polygon_converter_transfer(ta_parameter_buf, parameter.offset);
ta_wait_opaque_list();
core_start_render(frame_ix, num_frames);
v_sync_in();
core_wait_end_of_render_video(frame_ix, num_frames);
frame_ix += 1;
}
}

View File

@ -3,23 +3,24 @@
#include "align.hpp" #include "align.hpp"
#include "vga.hpp" #include "vga.hpp"
#include "holly.hpp" #include "holly/holly.hpp"
#include "holly/core.hpp" #include "holly/core.hpp"
#include "holly/core_bits.hpp" #include "holly/core_bits.hpp"
#include "holly/ta_fifo_polygon_converter.hpp" #include "holly/ta_fifo_polygon_converter.hpp"
#include "holly/ta_parameter.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_bits.hpp"
#include "holly/isp_tsp.hpp"
#include "holly/region_array.hpp" #include "holly/region_array.hpp"
#include "holly/background.hpp" #include "holly/background.hpp"
#include "holly/texture_memory_alloc.hpp" #include "holly/texture_memory_alloc.hpp"
#include "memorymap.hpp" #include "memorymap.hpp"
#include "serial.hpp"
#include "geometry/geometry.hpp"
#include "geometry/cube.hpp" #include "geometry/cube.hpp"
#include "math/vec4.hpp" #include "math/vec4.hpp"
using vec4 = vec<4, float>;
constexpr float half_degree = 0.01745329f / 2; constexpr float half_degree = 0.01745329f / 2;
vec3 rotate(const vec3& vertex, float theta) vec3 rotate(const vec3& vertex, float theta)
@ -59,10 +60,14 @@ void transform(ta_parameter_writer& parameter,
| tsp_instruction_word::dst_alpha_instr::zero | tsp_instruction_word::dst_alpha_instr::zero
| tsp_instruction_word::fog_control::no_fog; | tsp_instruction_word::fog_control::no_fog;
parameter.append<global_polygon_type_0>() = global_polygon_type_0(parameter_control_word, parameter.append<ta_global_parameter::polygon_type_0>() =
ta_global_parameter::polygon_type_0(parameter_control_word,
isp_tsp_instruction_word, isp_tsp_instruction_word,
tsp_instruction_word, tsp_instruction_word,
0); 0, // texture_control_word
0, // data_size_for_sort_dma
0 // next_address_for_sort_dma
);
auto& face = cube::faces[face_ix]; auto& face = cube::faces[face_ix];
constexpr uint32_t strip_length = 3; constexpr uint32_t strip_length = 3;
@ -116,13 +121,14 @@ void transform(ta_parameter_writer& parameter,
y += 240.f; y += 240.f;
z = 1 / z; z = 1 / z;
parameter.append<vertex_polygon_type_1>() = parameter.append<ta_vertex_parameter::polygon_type_1>() =
vertex_polygon_type_1(x, y, z, ta_vertex_parameter::polygon_type_1(polygon_vertex_parameter_control_word(end_of_strip),
x, y, z,
color.w, // alpha color.w, // alpha
color.x, // r color.x, // r
color.y, // g color.y, // g
color.z, // b color.z // b
end_of_strip); );
} }
} }
@ -163,8 +169,6 @@ void main()
, .punch_through = 0 , .punch_through = 0
}; };
constexpr uint32_t tiles = (640 / 32) * (320 / 32);
holly.SOFTRESET = softreset::pipeline_soft_reset holly.SOFTRESET = softreset::pipeline_soft_reset
| softreset::ta_soft_reset; | softreset::ta_soft_reset;
holly.SOFTRESET = 0; holly.SOFTRESET = 0;
@ -182,8 +186,10 @@ void main()
}; };
while (1) { while (1) {
ta_polygon_converter_init(opb_size.total() * tiles, ta_alloc, ta_polygon_converter_init(opb_size.total(),
640, 480); ta_alloc,
640 / 32,
480 / 32);
//lights[0].x = cos(theta) * 10; //lights[0].x = cos(theta) * 10;
//lights[0].z = sin(theta) * 10; //lights[0].z = sin(theta) * 10;
@ -195,7 +201,7 @@ void main()
for (uint32_t i = 0; i < cube::num_faces; i++) { for (uint32_t i = 0; i < cube::num_faces; i++) {
transform(parameter, i, theta, lights); transform(parameter, i, theta, lights);
} }
parameter.append<global_end_of_list>() = global_end_of_list(); parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
ta_polygon_converter_transfer(ta_parameter_buf, parameter.offset); ta_polygon_converter_transfer(ta_parameter_buf, parameter.offset);
ta_wait_opaque_list(); ta_wait_opaque_list();
core_start_render(frame_ix, num_frames); core_start_render(frame_ix, num_frames);

View File

@ -40,7 +40,6 @@ FONT_BITMAP_OBJ = \
holly/region_array.o \ holly/region_array.o \
holly/background.o \ holly/background.o \
holly/ta_fifo_polygon_converter.o \ holly/ta_fifo_polygon_converter.o \
serial.o \
sperrypc.data.o sperrypc.data.o
example/font_bitmap.elf: LDSCRIPT = $(LIB)/alt.lds example/font_bitmap.elf: LDSCRIPT = $(LIB)/alt.lds
@ -53,7 +52,6 @@ FONT_OUTLINE_OBJ = \
holly/region_array.o \ holly/region_array.o \
holly/background.o \ holly/background.o \
holly/ta_fifo_polygon_converter.o \ holly/ta_fifo_polygon_converter.o \
serial.o \
dejavusansmono.data.o dejavusansmono.data.o
example/font_outline.elf: LDSCRIPT = $(LIB)/alt.lds example/font_outline.elf: LDSCRIPT = $(LIB)/alt.lds
@ -66,7 +64,6 @@ FONT_OUTLINE_PUNCH_THROUGH_OBJ = \
holly/region_array.o \ holly/region_array.o \
holly/background.o \ holly/background.o \
holly/ta_fifo_polygon_converter.o \ holly/ta_fifo_polygon_converter.o \
serial.o \
dejavusansmono_mono.data.o dejavusansmono_mono.data.o
example/font_outline_punch_through.elf: LDSCRIPT = $(LIB)/alt.lds example/font_outline_punch_through.elf: LDSCRIPT = $(LIB)/alt.lds
@ -146,11 +143,38 @@ MODIFIER_VOLUME_WITH_TWO_VOLUMES_OBJ = \
holly/core.o \ holly/core.o \
holly/region_array.o \ holly/region_array.o \
holly/background.o \ holly/background.o \
holly/ta_fifo_polygon_converter.o holly/ta_fifo_polygon_converter.o \
wolf.data.o \
macaw.data.o \
maple/maple.o \
$(LIBGCC)
example/modifier_volume_with_two_volumes.elf: LDSCRIPT = $(LIB)/alt.lds example/modifier_volume_with_two_volumes.elf: LDSCRIPT = $(LIB)/alt.lds
example/modifier_volume_with_two_volumes.elf: $(START_OBJ) $(MODIFIER_VOLUME_WITH_TWO_VOLUMES_OBJ) example/modifier_volume_with_two_volumes.elf: $(START_OBJ) $(MODIFIER_VOLUME_WITH_TWO_VOLUMES_OBJ)
HEART_OBJ = \
example/heart.o \
vga.o \
holly/core.o \
holly/region_array.o \
holly/background.o \
holly/ta_fifo_polygon_converter.o
example/heart.elf: LDSCRIPT = $(LIB)/alt.lds
example/heart.elf: $(START_OBJ) $(HEART_OBJ)
VIEWING_SYSTEM_OBJ = \
example/viewing_system.o \
vga.o \
holly/core.o \
holly/region_array.o \
holly/background.o \
holly/ta_fifo_polygon_converter.o \
$(LIBGCC)
example/viewing_system.elf: LDSCRIPT = $(LIB)/alt.lds
example/viewing_system.elf: $(START_OBJ) $(VIEWING_SYSTEM_OBJ)
MACAW_CUBE_OBJ = \ MACAW_CUBE_OBJ = \
example/macaw_cube.o \ example/macaw_cube.o \
vga.o \ vga.o \
@ -170,12 +194,37 @@ MACAW_CUBE_RENDER_TO_TEXTURE_OBJ = \
holly/region_array.o \ holly/region_array.o \
holly/background.o \ holly/background.o \
holly/ta_fifo_polygon_converter.o \ holly/ta_fifo_polygon_converter.o \
serial.o \
macaw.data.o macaw.data.o
example/macaw_cube_render_to_texture.elf: LDSCRIPT = $(LIB)/alt.lds example/macaw_cube_render_to_texture.elf: LDSCRIPT = $(LIB)/alt.lds
example/macaw_cube_render_to_texture.elf: $(START_OBJ) $(MACAW_CUBE_RENDER_TO_TEXTURE_OBJ) example/macaw_cube_render_to_texture.elf: $(START_OBJ) $(MACAW_CUBE_RENDER_TO_TEXTURE_OBJ)
CLIPPING_OBJ = \
example/clipping.o \
vga.o \
holly/core.o \
holly/region_array.o \
holly/background.o \
holly/ta_fifo_polygon_converter.o \
maple/maple.o
example/clipping.elf: LDSCRIPT = $(LIB)/alt.lds
example/clipping.elf: $(START_OBJ) $(CLIPPING_OBJ)
CLIPPING2_OBJ = \
example/clipping2.o \
vga.o \
holly/core.o \
holly/region_array.o \
holly/background.o \
holly/ta_fifo_polygon_converter.o \
maple/maple.o \
sh7091/serial.o \
$(LIBGCC)
example/clipping2.elf: LDSCRIPT = $(LIB)/alt.lds
example/clipping2.elf: $(START_OBJ) $(CLIPPING2_OBJ)
MAPLE_DEVICE_REQUEST_OBJ = \ MAPLE_DEVICE_REQUEST_OBJ = \
example/maple_device_request.o \ example/maple_device_request.o \
vga.o \ vga.o \
@ -188,7 +237,7 @@ example/maple_device_request.elf: $(START_OBJ) $(MAPLE_DEVICE_REQUEST_OBJ)
MAPLE_CONTROLLER_OBJ = \ MAPLE_CONTROLLER_OBJ = \
example/maple_controller.o \ example/maple_controller.o \
vga.o \ vga.o \
serial.o \ sh7091/serial.o \
maple/maple.o maple/maple.o
example/maple_controller.elf: LDSCRIPT = $(LIB)/alt.lds example/maple_controller.elf: LDSCRIPT = $(LIB)/alt.lds
@ -222,7 +271,6 @@ MAPLE_ANALOG_OBJ = \
holly/region_array.o \ holly/region_array.o \
holly/background.o \ holly/background.o \
holly/ta_fifo_polygon_converter.o \ holly/ta_fifo_polygon_converter.o \
serial.o \
maple/maple.o maple/maple.o
example/maple_analog.elf: LDSCRIPT = $(LIB)/alt.lds example/maple_analog.elf: LDSCRIPT = $(LIB)/alt.lds
@ -234,3 +282,10 @@ SERIAL_TRANSFER_OBJ = \
example/serial_transfer.elf: LDSCRIPT = $(LIB)/alt.lds example/serial_transfer.elf: LDSCRIPT = $(LIB)/alt.lds
example/serial_transfer.elf: $(START_OBJ) $(SERIAL_TRANSFER_OBJ) example/serial_transfer.elf: $(START_OBJ) $(SERIAL_TRANSFER_OBJ)
INTERRUPT_OBJ = \
example/interrupt.o \
serial.o
example/interrupt.elf: LDSCRIPT = $(LIB)/alt.lds
example/interrupt.elf: $(START_OBJ) $(INTERRUPT_OBJ)

View File

@ -1,20 +1,22 @@
#include <cstdint> #include <cstdint>
#include "align.hpp" #include "align.hpp"
#include "vga.hpp" #include "vga.hpp"
#include "holly.hpp"
#include "holly/texture_memory_alloc.hpp"
#include "holly/holly.hpp"
#include "holly/core.hpp" #include "holly/core.hpp"
#include "holly/core_bits.hpp" #include "holly/core_bits.hpp"
#include "holly/ta_parameter.hpp"
#include "holly/ta_fifo_polygon_converter.hpp" #include "holly/ta_fifo_polygon_converter.hpp"
#include "holly/texture_memory_alloc.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/isp_tsp.hpp"
#include "memorymap.hpp" #include "memorymap.hpp"
#include "holly/background.hpp" #include "holly/background.hpp"
#include "holly/region_array.hpp" #include "holly/region_array.hpp"
#include "holly/ta_bits.hpp"
#include "twiddle.hpp" #include "twiddle.hpp"
#include "serial.hpp"
#include "sperrypc.hpp" #include "sperrypc.hpp"
@ -92,25 +94,35 @@ constexpr uint32_t strip_length = (sizeof (strip_vertices)) / (sizeof (struct ve
uint32_t transform(uint32_t * ta_parameter_buf, const char * s, const uint32_t len) uint32_t transform(uint32_t * ta_parameter_buf, const char * s, const uint32_t len)
{ {
auto parameter = ta_parameter_writer(ta_parameter_buf); auto parameter = ta_parameter_writer(ta_parameter_buf);
uint32_t texture_address = (offsetof (struct texture_memory_alloc, texture));
for (uint32_t string_ix = 0; string_ix < len; string_ix++) { for (uint32_t string_ix = 0; string_ix < len; string_ix++) {
auto polygon = global_polygon_type_0(texture_address); const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
polygon.parameter_control_word = para_control::para_type::polygon_or_modifier_volume
| para_control::list_type::opaque | para_control::list_type::opaque
| obj_control::col_type::packed_color | obj_control::col_type::packed_color
| obj_control::texture; | obj_control::texture;
polygon.tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
| isp_tsp_instruction_word::culling_mode::no_culling;
const uint32_t tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one
| tsp_instruction_word::dst_alpha_instr::zero | tsp_instruction_word::dst_alpha_instr::zero
| tsp_instruction_word::fog_control::no_fog | tsp_instruction_word::fog_control::no_fog
| tsp_instruction_word::texture_u_size::_8 // 8px | tsp_instruction_word::texture_u_size::from_int(8)
| tsp_instruction_word::texture_v_size::_8; // 8px | tsp_instruction_word::texture_v_size::from_int(8);
polygon.texture_control_word = texture_control_word::pixel_format::_4bpp_palette const uint32_t texture_address = (offsetof (struct texture_memory_alloc, texture));
const uint32_t texture_control_word = texture_control_word::pixel_format::_4bpp_palette
| texture_control_word::scan_order::twiddled | texture_control_word::scan_order::twiddled
| texture_control_word::texture_address((texture_address + 8 * 8 * (s[string_ix] - ' ')) / 8); | texture_control_word::texture_address((texture_address + 8 * 8 * (s[string_ix] - ' ')) / 8);
parameter.append<global_polygon_type_0>() = polygon;
parameter.append<ta_global_parameter::polygon_type_0>() =
ta_global_parameter::polygon_type_0(parameter_control_word,
isp_tsp_instruction_word,
tsp_instruction_word,
texture_control_word,
0, // data_size_for_sort_dma
0 // next_address_for_sort_dma
);
for (uint32_t i = 0; i < strip_length; i++) { for (uint32_t i = 0; i < strip_length; i++) {
bool end_of_strip = i == strip_length - 1; bool end_of_strip = i == strip_length - 1;
@ -125,16 +137,18 @@ uint32_t transform(uint32_t * ta_parameter_buf, const char * s, const uint32_t l
y += 240.f; y += 240.f;
z = 1.f / (z + 10.f); z = 1.f / (z + 10.f);
parameter.append<vertex_polygon_type_3>() = parameter.append<ta_vertex_parameter::polygon_type_3>() =
vertex_polygon_type_3(x, y, z, ta_vertex_parameter::polygon_type_3(polygon_vertex_parameter_control_word(end_of_strip),
x, y, z,
strip_vertices[i].u, strip_vertices[i].u,
strip_vertices[i].v, strip_vertices[i].v,
0x00000000, // base_color 0, // base_color
end_of_strip); 0 // offset_color
);
} }
} }
parameter.append<global_end_of_list>() = global_end_of_list(); parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
return parameter.offset; return parameter.offset;
} }
@ -236,8 +250,6 @@ void main()
, .punch_through = 0 , .punch_through = 0
}; };
constexpr uint32_t tiles = (640 / 32) * (320 / 32);
holly.SOFTRESET = softreset::pipeline_soft_reset holly.SOFTRESET = softreset::pipeline_soft_reset
| softreset::ta_soft_reset; | softreset::ta_soft_reset;
holly.SOFTRESET = 0; holly.SOFTRESET = 0;
@ -251,8 +263,10 @@ void main()
const char ana[18] = "A from ana i know"; const char ana[18] = "A from ana i know";
while (true) { while (true) {
ta_polygon_converter_init(opb_size.total() * tiles, ta_alloc, ta_polygon_converter_init(opb_size.total(),
640, 480); ta_alloc,
640 / 32,
480 / 32);
uint32_t ta_parameter_size = transform(ta_parameter_buf, ana, 17); uint32_t ta_parameter_size = transform(ta_parameter_buf, ana, 17);
ta_polygon_converter_transfer(ta_parameter_buf, ta_parameter_size); ta_polygon_converter_transfer(ta_parameter_buf, ta_parameter_size);
ta_wait_opaque_list(); ta_wait_opaque_list();

View File

@ -1,27 +1,27 @@
#include <cstdint> #include <cstdint>
#include "align.hpp" #include "align.hpp"
#include "vga.hpp" #include "vga.hpp"
#include "holly.hpp"
#include "holly/texture_memory_alloc.hpp"
#include "holly/holly.hpp"
#include "holly/core.hpp" #include "holly/core.hpp"
#include "holly/core_bits.hpp" #include "holly/core_bits.hpp"
#include "holly/ta_parameter.hpp"
#include "holly/ta_fifo_polygon_converter.hpp" #include "holly/ta_fifo_polygon_converter.hpp"
#include "holly/texture_memory_alloc.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/isp_tsp.hpp"
#include "memorymap.hpp" #include "memorymap.hpp"
#include "holly/background.hpp" #include "holly/background.hpp"
#include "holly/region_array.hpp" #include "holly/region_array.hpp"
#include "holly/ta_bits.hpp"
#include "twiddle.hpp" #include "twiddle.hpp"
#include "serial.hpp"
#include "palette.hpp" #include "palette.hpp"
#include "font/font.hpp" #include "font/font.hpp"
#include "dejavusansmono.hpp" #include "dejavusansmono.hpp"
#include "sperrypc.hpp"
struct vertex { struct vertex {
float x; float x;
float y; float y;
@ -58,27 +58,35 @@ uint32_t transform(ta_parameter_writer& parameter,
continue; continue;
} }
auto polygon = global_polygon_type_0(texture_address); const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
polygon.parameter_control_word = para_control::para_type::polygon_or_modifier_volume
| para_control::list_type::translucent | para_control::list_type::translucent
| obj_control::col_type::packed_color | obj_control::col_type::packed_color
| obj_control::texture; | obj_control::texture;
polygon.tsp_instruction_word = tsp_instruction_word::src_alpha_instr::src_alpha const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
| isp_tsp_instruction_word::culling_mode::no_culling;
const uint32_t tsp_instruction_word = tsp_instruction_word::src_alpha_instr::src_alpha
| tsp_instruction_word::dst_alpha_instr::one | tsp_instruction_word::dst_alpha_instr::one
| tsp_instruction_word::fog_control::no_fog | tsp_instruction_word::fog_control::no_fog
| tsp_instruction_word::use_alpha | tsp_instruction_word::use_alpha
| tsp_instruction_word::texture_u_size::from_int(texture_width) | tsp_instruction_word::texture_u_size::from_int(texture_width)
| tsp_instruction_word::texture_v_size::from_int(texture_height); | tsp_instruction_word::texture_v_size::from_int(texture_height);
polygon.texture_control_word = texture_control_word::pixel_format::_4bpp_palette const uint32_t texture_control_word = texture_control_word::pixel_format::_4bpp_palette
| texture_control_word::scan_order::twiddled | texture_control_word::scan_order::twiddled
| texture_control_word::texture_address(texture_address / 8); | texture_control_word::texture_address(texture_address / 8);
parameter.append<global_polygon_type_0>() = polygon;
parameter.append<ta_global_parameter::polygon_type_0>() =
ta_global_parameter::polygon_type_0(parameter_control_word,
isp_tsp_instruction_word,
tsp_instruction_word,
texture_control_word,
0, // data_size_for_sort_dma
0 // next_address_for_sort_dma
);
for (uint32_t i = 0; i < strip_length; i++) { for (uint32_t i = 0; i < strip_length; i++) {
bool end_of_strip = i == strip_length - 1;
float x = strip_vertices[i].x; float x = strip_vertices[i].x;
float y = strip_vertices[i].y; float y = strip_vertices[i].y;
float z = strip_vertices[i].z; float z = strip_vertices[i].z;
@ -99,11 +107,14 @@ uint32_t transform(ta_parameter_writer& parameter,
u = u / static_cast<float>(texture_width); u = u / static_cast<float>(texture_width);
v = v / static_cast<float>(texture_height); v = v / static_cast<float>(texture_height);
parameter.append<vertex_polygon_type_3>() = bool end_of_strip = i == strip_length - 1;
vertex_polygon_type_3(x, y, z, parameter.append<ta_vertex_parameter::polygon_type_3>() =
ta_vertex_parameter::polygon_type_3(polygon_vertex_parameter_control_word(end_of_strip),
x, y, z,
u, v, u, v,
0x00000000, // base_color 0, // base_color
end_of_strip); 0 // offset_color
);
} }
advance += glyph.metrics.horiAdvance; advance += glyph.metrics.horiAdvance;
@ -117,26 +128,34 @@ uint32_t transform2(ta_parameter_writer& parameter,
{ {
uint32_t texture_address = (offsetof (struct texture_memory_alloc, texture)); uint32_t texture_address = (offsetof (struct texture_memory_alloc, texture));
auto polygon = global_polygon_type_0(texture_address); const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
polygon.parameter_control_word = para_control::para_type::polygon_or_modifier_volume
| para_control::list_type::translucent | para_control::list_type::translucent
| obj_control::col_type::packed_color | obj_control::col_type::packed_color
| obj_control::texture; | obj_control::texture;
polygon.tsp_instruction_word = tsp_instruction_word::src_alpha_instr::src_alpha const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
| isp_tsp_instruction_word::culling_mode::no_culling;
const uint32_t tsp_instruction_word = tsp_instruction_word::src_alpha_instr::src_alpha
| tsp_instruction_word::dst_alpha_instr::zero | tsp_instruction_word::dst_alpha_instr::zero
| tsp_instruction_word::fog_control::no_fog | tsp_instruction_word::fog_control::no_fog
| tsp_instruction_word::texture_u_size::from_int(texture_width) | tsp_instruction_word::texture_u_size::from_int(texture_width)
| tsp_instruction_word::texture_v_size::from_int(texture_height); | tsp_instruction_word::texture_v_size::from_int(texture_height);
polygon.texture_control_word = texture_control_word::pixel_format::_4bpp_palette const uint32_t texture_control_word = texture_control_word::pixel_format::_4bpp_palette
| texture_control_word::scan_order::twiddled | texture_control_word::scan_order::twiddled
| texture_control_word::texture_address(texture_address / 8); | texture_control_word::texture_address(texture_address / 8);
parameter.append<global_polygon_type_0>() = polygon;
parameter.append<ta_global_parameter::polygon_type_0>() =
ta_global_parameter::polygon_type_0(parameter_control_word,
isp_tsp_instruction_word,
tsp_instruction_word,
texture_control_word,
0, // data_size_for_sort_dma
0 // next_address_for_sort_dma
);
for (uint32_t i = 0; i < strip_length; i++) { for (uint32_t i = 0; i < strip_length; i++) {
bool end_of_strip = i == strip_length - 1;
float x = strip_vertices[i].x; float x = strip_vertices[i].x;
float y = strip_vertices[i].y; float y = strip_vertices[i].y;
float z = strip_vertices[i].z; float z = strip_vertices[i].z;
@ -150,11 +169,14 @@ uint32_t transform2(ta_parameter_writer& parameter,
float u = strip_vertices[i].u; float u = strip_vertices[i].u;
float v = strip_vertices[i].v; float v = strip_vertices[i].v;
parameter.append<vertex_polygon_type_3>() = bool end_of_strip = i == strip_length - 1;
vertex_polygon_type_3(x, y, z, parameter.append<ta_vertex_parameter::polygon_type_3>() =
ta_vertex_parameter::polygon_type_3(polygon_vertex_parameter_control_word(end_of_strip),
x, y, z,
u, v, u, v,
0x00000000, // base_color 0, // base_color
end_of_strip); 0 // offset_color
);
} }
return parameter.offset; return parameter.offset;
@ -230,8 +252,6 @@ void main()
, .punch_through = 0 , .punch_through = 0
}; };
constexpr uint32_t tiles = (640 / 32) * (320 / 32);
holly.SOFTRESET = softreset::pipeline_soft_reset holly.SOFTRESET = softreset::pipeline_soft_reset
| softreset::ta_soft_reset; | softreset::ta_soft_reset;
holly.SOFTRESET = 0; holly.SOFTRESET = 0;
@ -246,8 +266,10 @@ void main()
const char cabal[27] = "where is this secret cabal"; const char cabal[27] = "where is this secret cabal";
while (true) { while (true) {
ta_polygon_converter_init(opb_size.total() * tiles, ta_alloc, ta_polygon_converter_init(opb_size.total(),
640, 480); ta_alloc,
640 / 32,
480 / 32);
auto parameter = ta_parameter_writer(ta_parameter_buf); auto parameter = ta_parameter_writer(ta_parameter_buf);
@ -268,7 +290,7 @@ void main()
cabal, 26, cabal, 26,
font->glyph_height * 1); font->glyph_height * 1);
parameter.append<global_end_of_list>() = global_end_of_list(); parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
ta_polygon_converter_transfer(ta_parameter_buf, parameter.offset); ta_polygon_converter_transfer(ta_parameter_buf, parameter.offset);
ta_wait_translucent_list(); ta_wait_translucent_list();

View File

@ -1,27 +1,27 @@
#include <cstdint> #include <cstdint>
#include "align.hpp" #include "align.hpp"
#include "vga.hpp" #include "vga.hpp"
#include "holly.hpp"
#include "holly/texture_memory_alloc.hpp"
#include "holly/holly.hpp"
#include "holly/core.hpp" #include "holly/core.hpp"
#include "holly/core_bits.hpp" #include "holly/core_bits.hpp"
#include "holly/ta_parameter.hpp"
#include "holly/ta_fifo_polygon_converter.hpp" #include "holly/ta_fifo_polygon_converter.hpp"
#include "holly/texture_memory_alloc.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/isp_tsp.hpp"
#include "memorymap.hpp" #include "memorymap.hpp"
#include "holly/background.hpp" #include "holly/background.hpp"
#include "holly/region_array.hpp" #include "holly/region_array.hpp"
#include "holly/ta_bits.hpp"
#include "twiddle.hpp" #include "twiddle.hpp"
#include "serial.hpp"
#include "palette.hpp" #include "palette.hpp"
#include "font/font.hpp" #include "font/font.hpp"
#include "dejavusansmono_mono.hpp" #include "dejavusansmono_mono.hpp"
#include "sperrypc.hpp"
struct vertex { struct vertex {
float x; float x;
float y; float y;
@ -58,27 +58,34 @@ uint32_t transform(ta_parameter_writer& parameter,
continue; continue;
} }
auto polygon = global_polygon_type_0(texture_address); const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
polygon.parameter_control_word = para_control::para_type::polygon_or_modifier_volume
| para_control::list_type::punch_through | para_control::list_type::punch_through
| obj_control::col_type::packed_color | obj_control::col_type::packed_color
| obj_control::texture; | obj_control::texture;
polygon.tsp_instruction_word = tsp_instruction_word::src_alpha_instr::src_alpha const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
| tsp_instruction_word::dst_alpha_instr::one | isp_tsp_instruction_word::culling_mode::no_culling;
const uint32_t tsp_instruction_word = tsp_instruction_word::src_alpha_instr::src_alpha
| tsp_instruction_word::dst_alpha_instr::zero
| tsp_instruction_word::fog_control::no_fog | tsp_instruction_word::fog_control::no_fog
//| tsp_instruction_word::use_alpha
| tsp_instruction_word::texture_u_size::from_int(texture_width) | tsp_instruction_word::texture_u_size::from_int(texture_width)
| tsp_instruction_word::texture_v_size::from_int(texture_height); | tsp_instruction_word::texture_v_size::from_int(texture_height);
polygon.texture_control_word = texture_control_word::pixel_format::_4bpp_palette const uint32_t texture_control_word = texture_control_word::pixel_format::_4bpp_palette
| texture_control_word::scan_order::twiddled | texture_control_word::scan_order::twiddled
| texture_control_word::texture_address(texture_address / 8); | texture_control_word::texture_address(texture_address / 8);
parameter.append<global_polygon_type_0>() = polygon;
parameter.append<ta_global_parameter::polygon_type_0>() =
ta_global_parameter::polygon_type_0(parameter_control_word,
isp_tsp_instruction_word,
tsp_instruction_word,
texture_control_word,
0, // data_size_for_sort_dma
0 // next_address_for_sort_dma
);
for (uint32_t i = 0; i < strip_length; i++) { for (uint32_t i = 0; i < strip_length; i++) {
bool end_of_strip = i == strip_length - 1;
float x = strip_vertices[i].x; float x = strip_vertices[i].x;
float y = strip_vertices[i].y; float y = strip_vertices[i].y;
float z = strip_vertices[i].z; float z = strip_vertices[i].z;
@ -99,11 +106,14 @@ uint32_t transform(ta_parameter_writer& parameter,
u = u / static_cast<float>(texture_width); u = u / static_cast<float>(texture_width);
v = v / static_cast<float>(texture_height); v = v / static_cast<float>(texture_height);
parameter.append<vertex_polygon_type_3>() = bool end_of_strip = i == strip_length - 1;
vertex_polygon_type_3(x, y, z, parameter.append<ta_vertex_parameter::polygon_type_3>() =
ta_vertex_parameter::polygon_type_3(polygon_vertex_parameter_control_word(end_of_strip),
x, y, z,
u, v, u, v,
0x00000000, // base_color 0, // base_color
end_of_strip); 0 // offset_color
);
} }
advance += glyph.metrics.horiAdvance; advance += glyph.metrics.horiAdvance;
@ -117,26 +127,34 @@ uint32_t transform2(ta_parameter_writer& parameter,
{ {
uint32_t texture_address = (offsetof (struct texture_memory_alloc, texture)); uint32_t texture_address = (offsetof (struct texture_memory_alloc, texture));
auto polygon = global_polygon_type_0(texture_address); const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
polygon.parameter_control_word = para_control::para_type::polygon_or_modifier_volume
| para_control::list_type::opaque | para_control::list_type::opaque
| obj_control::col_type::packed_color | obj_control::col_type::packed_color
| obj_control::texture; | obj_control::texture;
polygon.tsp_instruction_word = tsp_instruction_word::src_alpha_instr::src_alpha const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
| isp_tsp_instruction_word::culling_mode::no_culling;
const uint32_t tsp_instruction_word = tsp_instruction_word::src_alpha_instr::src_alpha
| tsp_instruction_word::dst_alpha_instr::zero | tsp_instruction_word::dst_alpha_instr::zero
| tsp_instruction_word::fog_control::no_fog | tsp_instruction_word::fog_control::no_fog
| tsp_instruction_word::texture_u_size::from_int(texture_width) | tsp_instruction_word::texture_u_size::from_int(texture_width)
| tsp_instruction_word::texture_v_size::from_int(texture_height); | tsp_instruction_word::texture_v_size::from_int(texture_height);
polygon.texture_control_word = texture_control_word::pixel_format::_4bpp_palette const uint32_t texture_control_word = texture_control_word::pixel_format::_4bpp_palette
| texture_control_word::scan_order::twiddled | texture_control_word::scan_order::twiddled
| texture_control_word::texture_address(texture_address / 8); | texture_control_word::texture_address(texture_address / 8);
parameter.append<global_polygon_type_0>() = polygon;
parameter.append<ta_global_parameter::polygon_type_0>() =
ta_global_parameter::polygon_type_0(parameter_control_word,
isp_tsp_instruction_word,
tsp_instruction_word,
texture_control_word,
0, // data_size_for_sort_dma
0 // next_address_for_sort_dma
);
for (uint32_t i = 0; i < strip_length; i++) { for (uint32_t i = 0; i < strip_length; i++) {
bool end_of_strip = i == strip_length - 1;
float x = strip_vertices[i].x; float x = strip_vertices[i].x;
float y = strip_vertices[i].y; float y = strip_vertices[i].y;
float z = strip_vertices[i].z; float z = strip_vertices[i].z;
@ -150,11 +168,14 @@ uint32_t transform2(ta_parameter_writer& parameter,
float u = strip_vertices[i].u; float u = strip_vertices[i].u;
float v = strip_vertices[i].v; float v = strip_vertices[i].v;
parameter.append<vertex_polygon_type_3>() = bool end_of_strip = i == strip_length - 1;
vertex_polygon_type_3(x, y, z, parameter.append<ta_vertex_parameter::polygon_type_3>() =
ta_vertex_parameter::polygon_type_3(polygon_vertex_parameter_control_word(end_of_strip),
x, y, z,
u, v, u, v,
0x00000000, // base_color 0, // base_color
end_of_strip); 0 // offset_color
);
} }
return parameter.offset; return parameter.offset;
@ -234,8 +255,6 @@ void main()
, .punch_through = 16 * 4 , .punch_through = 16 * 4
}; };
constexpr uint32_t tiles = (640 / 32) * (320 / 32);
holly.SOFTRESET = softreset::pipeline_soft_reset holly.SOFTRESET = softreset::pipeline_soft_reset
| softreset::ta_soft_reset; | softreset::ta_soft_reset;
holly.SOFTRESET = 0; holly.SOFTRESET = 0;
@ -251,15 +270,17 @@ void main()
const char cabal[27] = "where is this secret cabal"; const char cabal[27] = "where is this secret cabal";
while (true) { while (true) {
ta_polygon_converter_init(opb_size.total() * tiles, ta_alloc, ta_polygon_converter_init(opb_size.total(),
640, 480); ta_alloc,
640 / 32,
480 / 32);
auto parameter = ta_parameter_writer(ta_parameter_buf); auto parameter = ta_parameter_writer(ta_parameter_buf);
transform2(parameter, transform2(parameter,
font->texture_width, font->texture_height); font->texture_width, font->texture_height);
parameter.append<global_end_of_list>() = global_end_of_list(); parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
transform(parameter, transform(parameter,
font->texture_width, font->texture_height, font->texture_width, font->texture_height,
@ -275,7 +296,7 @@ void main()
cabal, 26, cabal, 26,
font->glyph_height * 1); font->glyph_height * 1);
parameter.append<global_end_of_list>() = global_end_of_list(); parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
ta_polygon_converter_transfer(ta_parameter_buf, parameter.offset); ta_polygon_converter_transfer(ta_parameter_buf, parameter.offset);
ta_wait_punch_through_list(); ta_wait_punch_through_list();

333
example/heart.cpp Normal file
View File

@ -0,0 +1,333 @@
#include <cstdint>
#include "align.hpp"
#include "vga.hpp"
#include "holly/texture_memory_alloc.hpp"
#include "holly/holly.hpp"
#include "holly/core.hpp"
#include "holly/core_bits.hpp"
#include "holly/ta_fifo_polygon_converter.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/region_array.hpp"
#include "holly/background.hpp"
#include "holly/isp_tsp.hpp"
#include "memorymap.hpp"
#include "geometry/heart.hpp"
#include "math/vec3.hpp"
#include "math/vec4.hpp"
#include "math/mat4x4.hpp"
using mat4x4 = mat<4, 4, float>;
constexpr float pi = 3.141592653589793;
struct rotation_weights {
float drx;
float dry;
float drz;
};
// randomly generated numbers
constexpr rotation_weights weights[16] = {
{-0.8154296875, 0.8583984375, -0.498046875},
{0.322265625, 0.6796875, 0.3251953125},
{-0.2626953125, -0.7744140625, 0.37109375},
{0.5830078125, 0.42578125, 0.5546875},
{0.9140625, 0.7568359375, -0.037109375},
{0.8974609375, 0.103515625, -0.2666015625},
{0.8427734375, -0.4091796875, -0.365234375},
{0.162109375, -0.603515625, 0.4248046875},
{-0.47265625, -0.73828125, -0.4912109375},
{-0.921875, 0.4609375, 0.2216796875},
{0.400390625, -0.5634765625, -0.3232421875},
{0.896484375, 0.26953125, -0.951171875},
{0.541015625, 0.90625, 0.640625},
{0.5927734375, -0.361328125, 0.21875},
{-0.9267578125, -0.9423828125, 0.4580078125},
{0.16796875, 0.3662109375, 0.603515625},
};
// randomly generated numbers
float lighting_weights[16] = {
0.7314453125,
0.44921875,
0.259765625,
0.3232421875,
0.1015625,
0.2529296875,
0.8662109375,
0.5439453125,
0.1337890625,
0.041015625,
0.6298828125,
0.30859375,
0.517578125,
0.6259765625,
0.283203125,
0.982421875,
};
struct model_transform {
float x;
float y;
float z;
float rx;
float ry;
float rz;
model_transform()
: x(0.f)
, y(0.f)
, z(0.f)
, rx(0.f)
, ry(0.f)
, rz(0.f)
{ }
};
struct model_transform models[] = {
};
inline mat4x4 rotate_x(float t)
{
return mat4x4(1.f, 0.f, 0.f, 0.f,
0.f, cos(t), -sin(t), 0.f,
0.f, sin(t), cos(t), 0.f,
0.f, 0.f, 0.f, 1.f
);
}
inline mat4x4 rotate_y(float t)
{
return mat4x4( cos(t), 0.f, sin(t), 0.f,
0.f, 1.f, 0.f, 0.f,
-sin(t), 0.f, cos(t), 0.f,
0.f, 0.f, 0.f, 1.f
);
}
inline mat4x4 rotate_z(float t)
{
return mat4x4(cos(t), -sin(t), 0.f, 0.f,
sin(t), cos(t), 0.f, 0.f,
0.f, 0.f, 1.f, 0.f,
0.f, 0.f, 0.f, 1.f
);
}
inline mat4x4 translate(float x, float y, float z)
{
return mat4x4(1.f, 0.f, 0.f, x,
0.f, 1.f, 0.f, y,
0.f, 0.f, 1.f, z,
0.f, 0.f, 0.f, 1.f
);
}
vec3 _transform(const vec4& point)
{
float x = point.x;
float y = point.y;
float z = point.z;
// camera transform
z += 4;
// perspective
x = x / z;
y = y / z;
// screen space transform
x *= 240.f;
y *= 240.f;
x += 320.f;
y += 240.f;
z = 1 / z;
return {x, y, z};
}
void transform_model(ta_parameter_writer& parameter,
const position__color * vertices,
const vec3 * normals,
const face_vn * faces,
const uint32_t num_faces,
const model_transform& mt,
const float lighting_weight)
{
const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
| para_control::list_type::opaque
| obj_control::col_type::floating_color
| obj_control::gouraud;
const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
| isp_tsp_instruction_word::culling_mode::no_culling;
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;
const mat4x4 mat = translate(mt.x, mt.y, mt.z) * rotate_z(mt.rz) * rotate_y(mt.ry) * rotate_x(mt.rx);
constexpr uint32_t strip_length = 3;
for (uint32_t face_ix = 0; face_ix < num_faces; face_ix++) {
parameter.append<ta_global_parameter::polygon_type_0>() =
ta_global_parameter::polygon_type_0(parameter_control_word,
isp_tsp_instruction_word,
tsp_instruction_word,
0, // texture_control_word
0, // data_size_for_sort_dma
0 // next_address_for_sort_dma
);
auto& face = faces[face_ix];
for (uint32_t i = 0; i < strip_length; i++) {
// world transform
uint32_t vertex_ix = face[i].vertex;
auto& vertex = vertices[vertex_ix].position;
auto& color = vertices[vertex_ix].color;
auto point = mat * vec4(vertex);
uint32_t normal_ix = face[i].normal;
auto& normal = normals[normal_ix];
auto n = mat * vec4(normal);
vec4 light = {0.f, 0.f, 40.f, 1.f};
auto l = light - point;
auto n_dot_l = dot(n, l);
vec3 c(0.f, 0.f, 0.f);
c.r += color.r * 0.1;
c.g += color.g * 0.1;
c.b += color.b * 0.1;
if (n_dot_l > 0) {
float intensity = n_dot_l / (length(n) * length(l));
c.r += color.r * intensity * lighting_weight;
c.g += color.g * intensity * lighting_weight;
c.b += color.b * intensity * lighting_weight;
}
auto screen = _transform(point);
bool end_of_strip = i == strip_length - 1;
parameter.append<ta_vertex_parameter::polygon_type_1>() =
ta_vertex_parameter::polygon_type_1(polygon_vertex_parameter_control_word(end_of_strip),
screen.x,
screen.y,
screen.z,
1.0f, // alpha
c.r, // red
c.g, // green
c.b // blue
);
}
}
}
void init_texture_memory(const struct opb_size& opb_size)
{
auto mem = reinterpret_cast<volatile texture_memory_alloc *>(texture_memory32);
background_parameter(mem->background, 0xff220000);
holly.VO_BORDER_COL = 0x00220000;
region_array2(mem->region_array,
(offsetof (struct texture_memory_alloc, object_list)),
640 / 32, // width
480 / 32, // height
opb_size
);
}
uint32_t _ta_parameter_buf[((32 * 8192) + 32) / 4];
void main()
{
vga();
// The address of `ta_parameter_buf` must be a multiple of 32 bytes.
// This is mandatory for ch2-dma to the ta fifo polygon converter.
uint32_t * ta_parameter_buf = align_32byte(_ta_parameter_buf);
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::_16x4byte;
constexpr struct opb_size opb_size = { .opaque = 16 * 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();
init_texture_memory(opb_size);
uint32_t frame_ix = 0;
constexpr uint32_t num_frames = 1;
float theta = 0;
model_transform mt[16] = {};
for (int x = 0; x < 4; x++) {
for (int y = 0; y < 4; y++) {
int ix = y * 4 + x;
mt[ix].x = -8.f + 5.f * static_cast<float>(x);
mt[ix].y = -7.5f + 5.f * static_cast<float>(y);
mt[ix].z = 6.f;
mt[ix].rx = (-8.f + static_cast<float>(ix)) * -pi / 16;
mt[ix].ry = (-8.f + static_cast<float>(ix)) * ix * -pi / 16;
mt[ix].rz = (-8.f + static_cast<float>(ix)) * ix * -pi / 16;
}
}
while (true) {
ta_polygon_converter_init(opb_size.total(),
ta_alloc,
640 / 32,
480 / 32);
auto parameter = ta_parameter_writer(ta_parameter_buf);
{ // plane
for (uint32_t i = 0; i < 16; i++) {
transform_model(parameter,
heart::vertices,
heart::normals,
heart::faces,
heart::num_faces,
mt[i],
(1.f + sin(theta * 2 * lighting_weights[i])) * 0.5f);
// update model
auto& weight = weights[i];
mt[i].rx += weight.drx / 50.f;
mt[i].ry += weight.dry / 50.f;
mt[i].rz += weight.drz / 50.f;
}
}
// end of opaque list
parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
ta_polygon_converter_transfer(ta_parameter_buf, parameter.offset);
ta_wait_opaque_list();
core_start_render(frame_ix, num_frames);
v_sync_in();
core_wait_end_of_render_video(frame_ix, num_frames);
constexpr float half_degree = 0.01745329f / 2;
theta += half_degree;
frame_ix += 1;
}
}

View File

@ -1,19 +1,21 @@
#include <cstdint> #include <cstdint>
#include "align.hpp" #include "align.hpp"
#include "vga.hpp" #include "vga.hpp"
#include "holly.hpp"
#include "holly/holly.hpp"
#include "holly/core.hpp" #include "holly/core.hpp"
#include "holly/core_bits.hpp" #include "holly/core_bits.hpp"
#include "holly/ta_fifo_polygon_converter.hpp" #include "holly/ta_fifo_polygon_converter.hpp"
#include "holly/ta_parameter.hpp" #include "holly/ta_parameter.hpp"
#include "holly/ta_global_parameter.hpp"
#include "holly/ta_vertex_parameter.hpp"
#include "holly/isp_tsp.hpp"
#include "holly/ta_bits.hpp" #include "holly/ta_bits.hpp"
#include "holly/region_array.hpp" #include "holly/region_array.hpp"
#include "holly/background.hpp" #include "holly/background.hpp"
#include "holly/texture_memory_alloc.hpp" #include "holly/texture_memory_alloc.hpp"
#include "memorymap.hpp" #include "memorymap.hpp"
#include "serial.hpp"
#include "geometry/icosphere.hpp" #include "geometry/icosphere.hpp"
#include "geometry/suzanne.hpp" #include "geometry/suzanne.hpp"
@ -21,7 +23,7 @@
constexpr float half_degree = 0.01745329f / 2; constexpr float half_degree = 0.01745329f / 2;
#define MODEL suzanne #define MODEL icosphere
vec3 rotate(const vec3& vertex, vec3 rotate(const vec3& vertex,
const float theta) const float theta)
@ -61,16 +63,18 @@ void transform(ta_parameter_writer& parameter,
| tsp_instruction_word::dst_alpha_instr::zero | tsp_instruction_word::dst_alpha_instr::zero
| tsp_instruction_word::fog_control::no_fog; | tsp_instruction_word::fog_control::no_fog;
parameter.append<global_polygon_type_0>() = global_polygon_type_0(parameter_control_word, parameter.append<ta_global_parameter::polygon_type_0>() =
ta_global_parameter::polygon_type_0(parameter_control_word,
isp_tsp_instruction_word, isp_tsp_instruction_word,
tsp_instruction_word, tsp_instruction_word,
0); 0, // texture_control_word
0, // data_size_for_sort_dma
0 // next_address_for_sort_dma
);
auto& face = MODEL::faces[face_ix]; auto& face = MODEL::faces[face_ix];
constexpr uint32_t strip_length = 3; constexpr uint32_t strip_length = 3;
for (uint32_t i = 0; i < strip_length; i++) { for (uint32_t i = 0; i < strip_length; i++) {
bool end_of_strip = i == strip_length - 1;
// world transform // world transform
uint32_t vertex_ix = face[i].vertex; uint32_t vertex_ix = face[i].vertex;
auto& vertex = MODEL::vertices[vertex_ix]; auto& vertex = MODEL::vertices[vertex_ix];
@ -130,13 +134,15 @@ void transform(ta_parameter_writer& parameter,
y += 240.f; y += 240.f;
z = 1 / z; z = 1 / z;
parameter.append<vertex_polygon_type_1>() = bool end_of_strip = i == strip_length - 1;
vertex_polygon_type_1(x, y, z, parameter.append<ta_vertex_parameter::polygon_type_1>() =
ta_vertex_parameter::polygon_type_1(polygon_vertex_parameter_control_word(end_of_strip),
x, y, z,
color.w, // alpha color.w, // alpha
color.x, // r color.x, // r
color.y, // g color.y, // g
color.z, // b color.z // b
end_of_strip); );
} }
} }
@ -156,10 +162,14 @@ void transform2(ta_parameter_writer& parameter,
| tsp_instruction_word::dst_alpha_instr::zero | tsp_instruction_word::dst_alpha_instr::zero
| tsp_instruction_word::fog_control::no_fog; | tsp_instruction_word::fog_control::no_fog;
parameter.append<global_polygon_type_0>() = global_polygon_type_0(parameter_control_word, parameter.append<ta_global_parameter::polygon_type_0>() =
ta_global_parameter::polygon_type_0(parameter_control_word,
isp_tsp_instruction_word, isp_tsp_instruction_word,
tsp_instruction_word, tsp_instruction_word,
0); 0, // texture_control_word
0, // data_size_for_sort_dma
0 // next_address_for_sort_dma
);
constexpr vec3 triangle[] = { constexpr vec3 triangle[] = {
{ 0.f, -1.f, 0.f}, { 0.f, -1.f, 0.f},
@ -169,7 +179,6 @@ void transform2(ta_parameter_writer& parameter,
constexpr uint32_t strip_length = 3; constexpr uint32_t strip_length = 3;
for (uint32_t i = 0; i < strip_length; i++) { for (uint32_t i = 0; i < strip_length; i++) {
bool end_of_strip = i == strip_length - 1;
float x = triangle[i].x; float x = triangle[i].x;
float y = triangle[i].y; float y = triangle[i].y;
float z = triangle[i].z; float z = triangle[i].z;
@ -196,13 +205,15 @@ void transform2(ta_parameter_writer& parameter,
y += 240.f; y += 240.f;
z = 1 / z; z = 1 / z;
parameter.append<vertex_polygon_type_1>() = bool end_of_strip = i == strip_length - 1;
vertex_polygon_type_1(x, y, z, parameter.append<ta_vertex_parameter::polygon_type_1>() =
ta_vertex_parameter::polygon_type_1(polygon_vertex_parameter_control_word(end_of_strip),
x, y, z,
color.w, // alpha color.w, // alpha
color.x, // r color.x, // r
color.y, // g color.y, // g
color.z, // b color.z // b
end_of_strip); );
} }
} }
@ -285,7 +296,7 @@ void main()
transform2(parameter, lights[1], {0.f, 1.f, 0.f, 1.f}); transform2(parameter, lights[1], {0.f, 1.f, 0.f, 1.f});
transform2(parameter, lights[2], {0.f, 0.f, 1.f, 1.f}); transform2(parameter, lights[2], {0.f, 0.f, 1.f, 1.f});
parameter.append<global_end_of_list>() = global_end_of_list(); parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
ta_polygon_converter_transfer(ta_parameter_buf, parameter.offset); ta_polygon_converter_transfer(ta_parameter_buf, parameter.offset);
ta_wait_opaque_list(); ta_wait_opaque_list();
core_start_render(frame_ix, num_frames); core_start_render(frame_ix, num_frames);

View File

@ -4,12 +4,15 @@
#include "vga.hpp" #include "vga.hpp"
#include "holly/texture_memory_alloc.hpp" #include "holly/texture_memory_alloc.hpp"
#include "holly.hpp" #include "holly/holly.hpp"
#include "holly/core.hpp" #include "holly/core.hpp"
#include "holly/core_bits.hpp" #include "holly/core_bits.hpp"
#include "holly/ta_fifo_polygon_converter.hpp" #include "holly/ta_fifo_polygon_converter.hpp"
#include "holly/ta_parameter.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_bits.hpp"
#include "holly/isp_tsp.hpp"
#include "holly/region_array.hpp" #include "holly/region_array.hpp"
#include "holly/background.hpp" #include "holly/background.hpp"
#include "memorymap.hpp" #include "memorymap.hpp"
@ -42,12 +45,35 @@ uint32_t transform(uint32_t * ta_parameter_buf,
const uint32_t strip_length) const uint32_t strip_length)
{ {
auto parameter = ta_parameter_writer(ta_parameter_buf); auto parameter = ta_parameter_writer(ta_parameter_buf);
uint32_t texture_address = (offsetof (struct texture_memory_alloc, texture)); const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
parameter.append<global_polygon_type_0>() = global_polygon_type_0(texture_address); | para_control::list_type::opaque
| obj_control::col_type::packed_color
| obj_control::texture;
const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
| isp_tsp_instruction_word::culling_mode::no_culling;
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_u_size::from_int(128)
| tsp_instruction_word::texture_v_size::from_int(128);
const uint32_t texture_address = (offsetof (struct texture_memory_alloc, texture));
const uint32_t 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.append<ta_global_parameter::polygon_type_0>() =
ta_global_parameter::polygon_type_0(parameter_control_word,
isp_tsp_instruction_word,
tsp_instruction_word,
texture_control_word,
0, // data_size_for_sort_dma
0 // next_address_for_sort_dma
);
for (uint32_t i = 0; i < strip_length; i++) { for (uint32_t i = 0; i < strip_length; i++) {
bool end_of_strip = i == strip_length - 1;
float x = strip_vertices[i].x; float x = strip_vertices[i].x;
float y = strip_vertices[i].y; float y = strip_vertices[i].y;
float z = strip_vertices[i].z; float z = strip_vertices[i].z;
@ -62,15 +88,18 @@ uint32_t transform(uint32_t * ta_parameter_buf,
y += 240.f; y += 240.f;
z = 1.f / (z + 10.f); z = 1.f / (z + 10.f);
parameter.append<vertex_polygon_type_3>() = bool end_of_strip = i == strip_length - 1;
vertex_polygon_type_3(x, y, z, parameter.append<ta_vertex_parameter::polygon_type_3>() =
ta_vertex_parameter::polygon_type_3(polygon_vertex_parameter_control_word(end_of_strip),
x, y, z,
strip_vertices[i].u, strip_vertices[i].u,
strip_vertices[i].v, strip_vertices[i].v,
strip_vertices[i].color, strip_vertices[i].color,
end_of_strip); 0 // offset_color
);
} }
parameter.append<global_end_of_list>() = global_end_of_list(); parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
return parameter.offset; return parameter.offset;
} }
@ -79,7 +108,7 @@ void init_texture_memory(const struct opb_size& opb_size)
{ {
auto mem = reinterpret_cast<volatile texture_memory_alloc *>(texture_memory32); auto mem = reinterpret_cast<volatile texture_memory_alloc *>(texture_memory32);
background_parameter(mem->background); background_parameter(mem->background, 0xff00ff00);
region_array2(mem->region_array, region_array2(mem->region_array,
(offsetof (struct texture_memory_alloc, object_list)), (offsetof (struct texture_memory_alloc, object_list)),
@ -128,8 +157,6 @@ void main()
, .punch_through = 0 , .punch_through = 0
}; };
constexpr uint32_t tiles = (640 / 32) * (320 / 32);
holly.SOFTRESET = softreset::pipeline_soft_reset holly.SOFTRESET = softreset::pipeline_soft_reset
| softreset::ta_soft_reset; | softreset::ta_soft_reset;
holly.SOFTRESET = 0; holly.SOFTRESET = 0;
@ -141,7 +168,10 @@ void main()
constexpr uint32_t num_frames = 1; constexpr uint32_t num_frames = 1;
while (true) { while (true) {
ta_polygon_converter_init(opb_size.total() * tiles, ta_alloc); ta_polygon_converter_init(opb_size.total(),
ta_alloc,
640 / 32,
480 / 32);
uint32_t ta_parameter_size = transform(ta_parameter_buf, strip_vertices, strip_length); uint32_t ta_parameter_size = transform(ta_parameter_buf, strip_vertices, strip_length);
ta_polygon_converter_transfer(ta_parameter_buf, ta_parameter_size); ta_polygon_converter_transfer(ta_parameter_buf, ta_parameter_size);
ta_wait_opaque_list(); ta_wait_opaque_list();

View File

@ -1,21 +1,22 @@
#include <cstdint> #include <cstdint>
#include "align.hpp" #include "align.hpp"
#include "vga.hpp" #include "vga.hpp"
#include "holly.hpp"
#include "holly/texture_memory_alloc.hpp"
#include "holly/holly.hpp"
#include "holly/core.hpp" #include "holly/core.hpp"
#include "holly/core_bits.hpp" #include "holly/core_bits.hpp"
#include "holly/ta_fifo_polygon_converter.hpp" #include "holly/ta_fifo_polygon_converter.hpp"
#include "holly/ta_parameter.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_bits.hpp"
#include "holly/isp_tsp.hpp"
#include "holly/region_array.hpp" #include "holly/region_array.hpp"
#include "holly/background.hpp" #include "holly/background.hpp"
#include "holly/texture_memory_alloc.hpp"
#include "memorymap.hpp" #include "memorymap.hpp"
#include "serial.hpp"
#include "macaw.hpp" #include "macaw.hpp"
struct vertex { struct vertex {
@ -63,12 +64,35 @@ void transform(ta_parameter_writer& parameter,
const vertex * strip_vertices, const vertex * strip_vertices,
const uint32_t strip_length) const uint32_t strip_length)
{ {
uint32_t texture_address = (offsetof (struct texture_memory_alloc, texture)); const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
parameter.append<global_polygon_type_0>() = global_polygon_type_0(); | para_control::list_type::opaque
| obj_control::col_type::packed_color
| obj_control::texture;
const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
| isp_tsp_instruction_word::culling_mode::no_culling;
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_u_size::from_int(128)
| tsp_instruction_word::texture_v_size::from_int(128);
const uint32_t texture_address = (offsetof (struct texture_memory_alloc, texture));
const uint32_t 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.append<ta_global_parameter::polygon_type_0>() =
ta_global_parameter::polygon_type_0(parameter_control_word,
isp_tsp_instruction_word,
tsp_instruction_word,
texture_control_word,
0, // data_size_for_sort_dma
0 // next_address_for_sort_dma
);
for (uint32_t i = 0; i < strip_length; i++) { for (uint32_t i = 0; i < strip_length; i++) {
bool end_of_strip = i == strip_length - 1;
float x = strip_vertices[i].x; float x = strip_vertices[i].x;
float y = strip_vertices[i].y; float y = strip_vertices[i].y;
float z = strip_vertices[i].z; float z = strip_vertices[i].z;
@ -98,12 +122,15 @@ void transform(ta_parameter_writer& parameter,
z = 1 / z; z = 1 / z;
parameter.append<vertex_polygon_type_0>() = bool end_of_strip = i == strip_length - 1;
vertex_polygon_type_0(x, y, z, parameter.append<ta_vertex_parameter::polygon_type_3>() =
//strip_vertices[i].u, ta_vertex_parameter::polygon_type_3(polygon_vertex_parameter_control_word(end_of_strip),
//strip_vertices[i].v, x, y, z,
color, strip_vertices[i].u,
end_of_strip); strip_vertices[i].v,
0, // base_color
0 // offset_color
);
} }
} }
@ -160,8 +187,6 @@ void main()
, .punch_through = 0 , .punch_through = 0
}; };
constexpr uint32_t tiles = (640 / 32) * (320 / 32);
holly.SOFTRESET = softreset::pipeline_soft_reset holly.SOFTRESET = softreset::pipeline_soft_reset
| softreset::ta_soft_reset; | softreset::ta_soft_reset;
holly.SOFTRESET = 0; holly.SOFTRESET = 0;
@ -173,12 +198,16 @@ void main()
constexpr uint32_t num_frames = 1; constexpr uint32_t num_frames = 1;
while (1) { while (1) {
ta_polygon_converter_init(opb_size.total() * tiles, ta_alloc, 640, 480); ta_polygon_converter_init(opb_size.total(),
ta_alloc,
640 / 32,
480 / 32);
auto parameter = ta_parameter_writer(ta_parameter_buf); auto parameter = ta_parameter_writer(ta_parameter_buf);
for (uint32_t i = 0; i < num_faces; i++) { for (uint32_t i = 0; i < num_faces; i++) {
transform(parameter, cube_faces[i], 4); transform(parameter, cube_faces[i], 4);
} }
parameter.append<global_end_of_list>() = global_end_of_list(); parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
ta_polygon_converter_transfer(ta_parameter_buf, parameter.offset); ta_polygon_converter_transfer(ta_parameter_buf, parameter.offset);
ta_wait_opaque_list(); ta_wait_opaque_list();
core_start_render(frame_ix, num_frames); core_start_render(frame_ix, num_frames);

View File

@ -1,21 +1,22 @@
#include <cstdint> #include <cstdint>
#include "align.hpp" #include "align.hpp"
#include "vga.hpp" #include "vga.hpp"
#include "holly.hpp"
#include "holly/texture_memory_alloc.hpp"
#include "holly/holly.hpp"
#include "holly/core.hpp" #include "holly/core.hpp"
#include "holly/core_bits.hpp" #include "holly/core_bits.hpp"
#include "holly/ta_fifo_polygon_converter.hpp" #include "holly/ta_fifo_polygon_converter.hpp"
#include "holly/ta_parameter.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_bits.hpp"
#include "holly/isp_tsp.hpp"
#include "holly/region_array.hpp" #include "holly/region_array.hpp"
#include "holly/background.hpp" #include "holly/background.hpp"
#include "holly/texture_memory_alloc.hpp"
#include "memorymap.hpp" #include "memorymap.hpp"
#include "serial.hpp"
#include "macaw.hpp" #include "macaw.hpp"
struct vertex { struct vertex {
@ -67,51 +68,71 @@ void transform(ta_parameter_writer& parameter,
const uint32_t texture_address, const uint32_t texture_address,
const uint32_t texture_width) const uint32_t texture_width)
{ {
auto polygon = global_polygon_type_0(texture_address); const uint32_t 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;
const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
| isp_tsp_instruction_word::culling_mode::no_culling;
const uint32_t texture_control_word = texture_control_word::pixel_format::_565
| texture_control_word::scan_order::non_twiddled
| texture_control_word::texture_address(texture_address / 8);
uint32_t tsp_instruction_word = 0;
switch (texture_width) { switch (texture_width) {
case 32: case 32:
polygon.tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one
| tsp_instruction_word::dst_alpha_instr::zero | tsp_instruction_word::dst_alpha_instr::zero
| tsp_instruction_word::fog_control::no_fog | tsp_instruction_word::fog_control::no_fog
| tsp_instruction_word::texture_u_size::_32 | tsp_instruction_word::texture_u_size::from_int(32)
| tsp_instruction_word::texture_v_size::_32 | tsp_instruction_word::texture_v_size::from_int(32)
| tsp_instruction_word::use_alpha; | tsp_instruction_word::use_alpha;
break; break;
case 64: case 64:
polygon.tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one
| tsp_instruction_word::dst_alpha_instr::zero | tsp_instruction_word::dst_alpha_instr::zero
| tsp_instruction_word::fog_control::no_fog | tsp_instruction_word::fog_control::no_fog
| tsp_instruction_word::texture_u_size::_64 | tsp_instruction_word::texture_u_size::from_int(64)
| tsp_instruction_word::texture_v_size::_64 | tsp_instruction_word::texture_v_size::from_int(64)
| tsp_instruction_word::use_alpha; | tsp_instruction_word::use_alpha;
break; break;
case 128: case 128:
polygon.tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one
| tsp_instruction_word::dst_alpha_instr::zero | tsp_instruction_word::dst_alpha_instr::zero
| tsp_instruction_word::fog_control::no_fog | tsp_instruction_word::fog_control::no_fog
| tsp_instruction_word::texture_u_size::_128 | tsp_instruction_word::texture_u_size::from_int(128)
| tsp_instruction_word::texture_v_size::_128 | tsp_instruction_word::texture_v_size::from_int(128)
| tsp_instruction_word::use_alpha; | tsp_instruction_word::use_alpha;
break; break;
case 256: case 256:
polygon.tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one
| tsp_instruction_word::dst_alpha_instr::zero | tsp_instruction_word::dst_alpha_instr::zero
| tsp_instruction_word::fog_control::no_fog | tsp_instruction_word::fog_control::no_fog
| tsp_instruction_word::texture_u_size::_256 | tsp_instruction_word::texture_u_size::from_int(256)
| tsp_instruction_word::texture_v_size::_256 | tsp_instruction_word::texture_v_size::from_int(256)
| tsp_instruction_word::use_alpha; | tsp_instruction_word::use_alpha;
break; break;
case 512: case 512:
polygon.tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one
| tsp_instruction_word::dst_alpha_instr::zero | tsp_instruction_word::dst_alpha_instr::zero
| tsp_instruction_word::fog_control::no_fog | tsp_instruction_word::fog_control::no_fog
| tsp_instruction_word::texture_u_size::_512 | tsp_instruction_word::texture_u_size::from_int(512)
| tsp_instruction_word::texture_v_size::_512 | tsp_instruction_word::texture_v_size::from_int(512)
| tsp_instruction_word::use_alpha; | tsp_instruction_word::use_alpha;
break; break;
default: break; default: break;
} }
parameter.append<global_polygon_type_0>() = polygon;
parameter.append<ta_global_parameter::polygon_type_0>() =
ta_global_parameter::polygon_type_0(parameter_control_word,
isp_tsp_instruction_word,
tsp_instruction_word,
texture_control_word,
0, // data_size_for_sort_dma
0 // next_address_for_sort_dma
);
for (uint32_t i = 0; i < strip_length; i++) { for (uint32_t i = 0; i < strip_length; i++) {
bool end_of_strip = i == strip_length - 1; bool end_of_strip = i == strip_length - 1;
@ -144,12 +165,14 @@ void transform(ta_parameter_writer& parameter,
z = 1 / z; z = 1 / z;
parameter.append<vertex_polygon_type_3>() = parameter.append<ta_vertex_parameter::polygon_type_3>() =
vertex_polygon_type_3(x, y, z, ta_vertex_parameter::polygon_type_3(polygon_vertex_parameter_control_word(end_of_strip),
x, y, z,
strip_vertices[i].u, strip_vertices[i].u,
strip_vertices[i].v, strip_vertices[i].v,
color, 0, // base_color
end_of_strip); 0 // offset_color
);
} }
} }
@ -186,9 +209,10 @@ void render(const uint32_t width, const uint32_t height,
const uint32_t texture_width, const uint32_t texture_width,
uint32_t * ta_parameter_buf) uint32_t * ta_parameter_buf)
{ {
const uint32_t tiles = (width / 32) * (height / 32); ta_polygon_converter_init(opb_size.total(),
ta_polygon_converter_init(opb_size.total() * tiles, ta_alloc, ta_alloc,
width, height); width / 32,
height / 32);
auto parameter = ta_parameter_writer(ta_parameter_buf); auto parameter = ta_parameter_writer(ta_parameter_buf);
for (uint32_t i = 0; i < num_faces; i++) { for (uint32_t i = 0; i < num_faces; i++) {
@ -197,7 +221,7 @@ void render(const uint32_t width, const uint32_t height,
texture_address, texture_address,
texture_width); texture_width);
} }
parameter.append<global_end_of_list>() = global_end_of_list(); parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
ta_polygon_converter_transfer(ta_parameter_buf, parameter.offset); ta_polygon_converter_transfer(ta_parameter_buf, parameter.offset);
ta_wait_opaque_list(); ta_wait_opaque_list();
} }

View File

@ -4,12 +4,15 @@
#include "vga.hpp" #include "vga.hpp"
#include "holly/texture_memory_alloc.hpp" #include "holly/texture_memory_alloc.hpp"
#include "holly.hpp" #include "holly/holly.hpp"
#include "holly/core.hpp" #include "holly/core.hpp"
#include "holly/core_bits.hpp" #include "holly/core_bits.hpp"
#include "holly/ta_fifo_polygon_converter.hpp" #include "holly/ta_fifo_polygon_converter.hpp"
#include "holly/ta_parameter.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_bits.hpp"
#include "holly/isp_tsp.hpp"
#include "holly/region_array.hpp" #include "holly/region_array.hpp"
#include "holly/background.hpp" #include "holly/background.hpp"
#include "memorymap.hpp" #include "memorymap.hpp"
@ -43,16 +46,35 @@ uint32_t transform(uint32_t * ta_parameter_buf,
const uint32_t strip_length) const uint32_t strip_length)
{ {
auto parameter = ta_parameter_writer(ta_parameter_buf); auto parameter = ta_parameter_writer(ta_parameter_buf);
uint32_t texture_address = (offsetof (struct texture_memory_alloc, texture)); const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
auto polygon = global_polygon_type_0(texture_address); | para_control::list_type::opaque
polygon.texture_control_word = texture_control_word::pixel_format::_565 | obj_control::col_type::packed_color
| obj_control::texture;
const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
| isp_tsp_instruction_word::culling_mode::no_culling;
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_u_size::from_int(128)
| tsp_instruction_word::texture_v_size::from_int(128);
const uint32_t texture_address = (offsetof (struct texture_memory_alloc, texture));
const uint32_t texture_control_word = texture_control_word::pixel_format::_565
| texture_control_word::scan_order::twiddled | texture_control_word::scan_order::twiddled
| texture_control_word::texture_address(texture_address / 8); | texture_control_word::texture_address(texture_address / 8);
parameter.append<global_polygon_type_0>() = polygon;
parameter.append<ta_global_parameter::polygon_type_0>() =
ta_global_parameter::polygon_type_0(parameter_control_word,
isp_tsp_instruction_word,
tsp_instruction_word,
texture_control_word,
0, // data_size_for_sort_dma
0 // next_address_for_sort_dma
);
for (uint32_t i = 0; i < strip_length; i++) { for (uint32_t i = 0; i < strip_length; i++) {
bool end_of_strip = i == strip_length - 1;
float x = strip_vertices[i].x; float x = strip_vertices[i].x;
float y = strip_vertices[i].y; float y = strip_vertices[i].y;
float z = strip_vertices[i].z; float z = strip_vertices[i].z;
@ -67,15 +89,18 @@ uint32_t transform(uint32_t * ta_parameter_buf,
y += 240.f; y += 240.f;
z = 1.f / (z + 10.f); z = 1.f / (z + 10.f);
parameter.append<vertex_polygon_type_3>() = bool end_of_strip = i == strip_length - 1;
vertex_polygon_type_3(x, y, z, parameter.append<ta_vertex_parameter::polygon_type_3>() =
ta_vertex_parameter::polygon_type_3(polygon_vertex_parameter_control_word(end_of_strip),
x, y, z,
strip_vertices[i].u, strip_vertices[i].u,
strip_vertices[i].v, strip_vertices[i].v,
strip_vertices[i].color, strip_vertices[i].color,
end_of_strip); 0 // offset_color
);
} }
parameter.append<global_end_of_list>() = global_end_of_list(); parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
return parameter.offset; return parameter.offset;
} }
@ -84,7 +109,7 @@ void init_texture_memory(const struct opb_size& opb_size)
{ {
auto mem = reinterpret_cast<volatile texture_memory_alloc *>(texture_memory32); auto mem = reinterpret_cast<volatile texture_memory_alloc *>(texture_memory32);
background_parameter(mem->background); background_parameter(mem->background, 0xff00ff00);
region_array2(mem->region_array, region_array2(mem->region_array,
(offsetof (struct texture_memory_alloc, object_list)), (offsetof (struct texture_memory_alloc, object_list)),
@ -132,8 +157,6 @@ void main()
, .punch_through = 0 , .punch_through = 0
}; };
constexpr uint32_t tiles = (640 / 32) * (320 / 32);
holly.SOFTRESET = softreset::pipeline_soft_reset holly.SOFTRESET = softreset::pipeline_soft_reset
| softreset::ta_soft_reset; | softreset::ta_soft_reset;
holly.SOFTRESET = 0; holly.SOFTRESET = 0;
@ -145,7 +168,10 @@ void main()
constexpr uint32_t num_frames = 1; constexpr uint32_t num_frames = 1;
while (true) { while (true) {
ta_polygon_converter_init(opb_size.total() * tiles, ta_alloc); ta_polygon_converter_init(opb_size.total(),
ta_alloc,
640 / 32,
480 / 32);
uint32_t ta_parameter_size = transform(ta_parameter_buf, strip_vertices, strip_length); uint32_t ta_parameter_size = transform(ta_parameter_buf, strip_vertices, strip_length);
ta_polygon_converter_transfer(ta_parameter_buf, ta_parameter_size); ta_polygon_converter_transfer(ta_parameter_buf, ta_parameter_size);
ta_wait_opaque_list(); ta_wait_opaque_list();

View File

@ -4,17 +4,20 @@
#include "align.hpp" #include "align.hpp"
#include "vga.hpp" #include "vga.hpp"
#include "holly.hpp" #include "holly/holly.hpp"
#include "holly/core.hpp" #include "holly/core.hpp"
#include "holly/core_bits.hpp" #include "holly/core_bits.hpp"
#include "holly/ta_fifo_polygon_converter.hpp" #include "holly/ta_fifo_polygon_converter.hpp"
#include "holly/ta_parameter.hpp" #include "holly/ta_parameter.hpp"
#include "holly/ta_vertex_parameter.hpp"
#include "holly/ta_global_parameter.hpp"
#include "holly/ta_bits.hpp" #include "holly/ta_bits.hpp"
#include "holly/isp_tsp.hpp"
#include "holly/region_array.hpp" #include "holly/region_array.hpp"
#include "holly/background.hpp" #include "holly/background.hpp"
#include "holly/texture_memory_alloc.hpp" #include "holly/texture_memory_alloc.hpp"
#include "memorymap.hpp" #include "memorymap.hpp"
#include "serial.hpp" #include "sh7091/serial.hpp"
#include "geometry/border.hpp" #include "geometry/border.hpp"
#include "geometry/circle.hpp" #include "geometry/circle.hpp"
@ -57,15 +60,6 @@ void do_get_condition(uint32_t * command_buf,
return; return;
} }
/*
bool a = ft0::data_transfer::digital_button::a(data_fields.data.digital_button);
if (a == 0) {
serial::string("port ");
serial::integer<uint8_t>(port);
serial::string(" `a` press ");
serial::integer<uint8_t>(a);
}
*/
data[port].analog_axis_3 = data_fields.data.analog_axis_3; data[port].analog_axis_3 = data_fields.data.analog_axis_3;
data[port].analog_axis_4 = data_fields.data.analog_axis_4; data[port].analog_axis_4 = data_fields.data.analog_axis_4;
} }
@ -73,7 +67,7 @@ void do_get_condition(uint32_t * command_buf,
void transform(ta_parameter_writer& parameter, void transform(ta_parameter_writer& parameter,
const vec3 * vertices, const vec3 * vertices,
const face& face, const face_vn& face,
const vec4& color, const vec4& color,
const vec3& position, const vec3& position,
const float scale const float scale
@ -91,14 +85,17 @@ void transform(ta_parameter_writer& parameter,
| tsp_instruction_word::dst_alpha_instr::zero | tsp_instruction_word::dst_alpha_instr::zero
| tsp_instruction_word::fog_control::no_fog; | tsp_instruction_word::fog_control::no_fog;
parameter.append<global_polygon_type_0>() = global_polygon_type_0(parameter_control_word, parameter.append<ta_global_parameter::polygon_type_0>() =
ta_global_parameter::polygon_type_0(parameter_control_word,
isp_tsp_instruction_word, isp_tsp_instruction_word,
tsp_instruction_word, tsp_instruction_word,
0); 0, // texture_control_word
0, // data_size_for_sort_dma
0 // next_address_for_sort_dma
);
constexpr uint32_t strip_length = 3; constexpr uint32_t strip_length = 3;
for (uint32_t i = 0; i < strip_length; i++) { for (uint32_t i = 0; i < strip_length; i++) {
bool end_of_strip = i == strip_length - 1;
// world transform // world transform
uint32_t vertex_ix = face[i].vertex; uint32_t vertex_ix = face[i].vertex;
@ -131,13 +128,16 @@ void transform(ta_parameter_writer& parameter,
y += 240.f; y += 240.f;
z = 1 / z; z = 1 / z;
parameter.append<vertex_polygon_type_1>() = bool end_of_strip = i == strip_length - 1;
vertex_polygon_type_1(x, y, z,
parameter.append<ta_vertex_parameter::polygon_type_1>() =
ta_vertex_parameter::polygon_type_1(polygon_vertex_parameter_control_word(end_of_strip),
x, y, z,
color.w, // alpha color.w, // alpha
color.x, // r color.x, // r
color.y, // g color.y, // g
color.z, // b color.z // b
end_of_strip); );
} }
} }
@ -223,7 +223,7 @@ void main()
); );
} }
parameter.append<global_end_of_list>() = global_end_of_list(); parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
ta_polygon_converter_transfer(ta_parameter_buf, parameter.offset); ta_polygon_converter_transfer(ta_parameter_buf, parameter.offset);
ta_wait_opaque_list(); ta_wait_opaque_list();
core_start_render(frame_ix, num_frames); core_start_render(frame_ix, num_frames);

View File

@ -4,10 +4,11 @@
#include "align.hpp" #include "align.hpp"
#include "maple/maple.hpp" #include "maple/maple.hpp"
#include "maple/maple_impl.hpp"
#include "maple/maple_bus_bits.hpp" #include "maple/maple_bus_bits.hpp"
#include "maple/maple_bus_commands.hpp" #include "maple/maple_bus_commands.hpp"
#include "maple/maple_bus_ft0.hpp" #include "maple/maple_bus_ft0.hpp"
#include "serial.hpp" #include "sh7091/serial.hpp"
uint32_t _command_buf[1024 / 4 + 32] = {0}; uint32_t _command_buf[1024 / 4 + 32] = {0};
uint32_t _receive_buf[1024 / 4 + 32] = {0}; uint32_t _receive_buf[1024 / 4 + 32] = {0};
@ -47,10 +48,11 @@ void do_get_condition(uint32_t port)
std::byteswap(function_type::controller)); std::byteswap(function_type::controller));
maple::dma_start(command_buf); maple::dma_start(command_buf);
using response_type = struct maple::command_response<data_transfer::data_fields<struct ft0::data_transfer::data_format>>; using response_type = data_transfer<ft0::data_transfer::data_format>;
auto response = reinterpret_cast<response_type *>(receive_buf); using command_response_type = struct maple::command_response<response_type::data_fields>;
auto response = reinterpret_cast<command_response_type *>(receive_buf);
auto& bus_data = response->bus_data; auto& bus_data = response->bus_data;
if (bus_data.command_code != data_transfer::command_code) { if (bus_data.command_code != response_type::command_code) {
return; return;
} }
auto& data_fields = bus_data.data_fields; auto& data_fields = bus_data.data_fields;
@ -69,20 +71,17 @@ void do_get_condition(uint32_t port)
void do_device_request() void do_device_request()
{ {
using response_type = struct maple::command_response<device_status::data_fields>; using command_type = device_request;
constexpr uint32_t response_size = align_32byte(sizeof (response_type)); using response_type = device_status;
maple::init_host_command_all_ports(command_buf, receive_buf, maple::init_host_command_all_ports<command_type, response_type>(command_buf, receive_buf);
device_request::command_code,
(sizeof (device_request::data_fields)), // command_data_size
(sizeof (device_status::data_fields))); // response_data_size
maple::dma_start(command_buf); maple::dma_start(command_buf);
using command_response_type = struct maple::command_response<response_type::data_fields>;
auto response = reinterpret_cast<command_response_type *>(receive_buf);
for (uint8_t port = 0; port < 4; port++) { for (uint8_t port = 0; port < 4; port++) {
auto response = reinterpret_cast<response_type *>(&receive_buf[response_size * port / 4]); auto& bus_data = response[port].bus_data;
auto& data_fields = response[port].bus_data.data_fields;
auto& bus_data = response->bus_data;
auto& data_fields = response->bus_data.data_fields;
if (bus_data.command_code != device_status::command_code) { if (bus_data.command_code != device_status::command_code) {
// the controller is disconnected // the controller is disconnected
} else { } else {

View File

@ -1,4 +1,5 @@
#include <cstdint> #include <cstdint>
#include <bit>
#include "align.hpp" #include "align.hpp"
#include "vga.hpp" #include "vga.hpp"
@ -22,9 +23,94 @@
#include "math/vec3.hpp" #include "math/vec3.hpp"
#include "math/vec4.hpp" #include "math/vec4.hpp"
#include "maple/maple.hpp"
#include "maple/maple_impl.hpp"
#include "maple/maple_bus_bits.hpp"
#include "maple/maple_bus_commands.hpp"
#include "maple/maple_bus_ft0.hpp"
#include "macaw.hpp"
#include "wolf.hpp"
#include "twiddle.hpp"
static ft0::data_transfer::data_format data[4];
void do_get_condition(uint32_t * command_buf,
uint32_t * receive_buf)
{
using command_type = get_condition;
using response_type = data_transfer<ft0::data_transfer::data_format>;
get_condition::data_fields data_fields = {
.function_type = std::byteswap(function_type::controller)
};
maple::init_host_command_all_ports<command_type, response_type>(command_buf, receive_buf,
data_fields);
maple::dma_start(command_buf);
using command_response_type = struct maple::command_response<response_type::data_fields>;
for (uint8_t port = 0; port < 4; port++) {
auto response = reinterpret_cast<command_response_type *>(receive_buf);
auto& bus_data = response[port].bus_data;
if (bus_data.command_code != response_type::command_code) {
return;
}
auto& data_fields = bus_data.data_fields;
if ((data_fields.function_type & std::byteswap(function_type::controller)) == 0) {
return;
}
data[port].analog_axis_1 = data_fields.data.analog_axis_1;
data[port].analog_axis_2 = data_fields.data.analog_axis_2;
data[port].analog_axis_3 = data_fields.data.analog_axis_3;
data[port].analog_axis_4 = data_fields.data.analog_axis_4;
}
}
struct rot_pos {
float theta;
float x;
float y;
};
vec3 _transform(const vec3& point,
const uint32_t scale)
{
float x = point.x;
float y = point.y;
float z = point.z;
x *= scale;
y *= scale;
z *= scale;
// world transform
y += 2.0f;
x *= 0.8;
y *= 0.8;
z *= 0.8;
// camera transform
z += 4;
// perspective
x = x / z;
y = y / z;
// screen space transform
x *= 240.f;
y *= 240.f;
x += 320.f;
y += 240.f;
z = 1 / z;
return {x, y, z};
}
vec3 _transform(const vec3& point, vec3 _transform(const vec3& point,
const uint32_t scale, const uint32_t scale,
const float theta) const struct rot_pos& rot_pos)
{ {
float x = point.x; float x = point.x;
float y = point.y; float y = point.y;
@ -32,10 +118,13 @@ vec3 _transform(const vec3& point,
float t; float t;
// object transform // object transform
t = z * cos(theta) - x * sin(theta); t = z * cos(rot_pos.theta) - x * sin(rot_pos.theta);
x = z * sin(theta) + x * cos(theta); x = z * sin(rot_pos.theta) + x * cos(rot_pos.theta);
z = t; z = t;
x += rot_pos.x;
z += rot_pos.y;
x *= scale; x *= scale;
y *= scale; y *= scale;
z *= scale; z *= scale;
@ -74,31 +163,47 @@ uint32_t argb8888(const vec4& color)
void transform_polygon(ta_parameter_writer& parameter, void transform_polygon(ta_parameter_writer& parameter,
const vec3 * vertices, const vec3 * vertices,
const vec2 * texture,
const face& face, const face& face,
const float scale, const float scale,
const vec4& color0, const vec4& color0,
const vec4& color1, const vec4& color1,
const float theta) const struct rot_pos& rot_pos)
{ {
const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
| para_control::list_type::opaque | para_control::list_type::opaque
| obj_control::col_type::packed_color
| obj_control::shadow | obj_control::shadow
| obj_control::volume::polygon::with_two_volumes; | obj_control::volume::polygon::with_two_volumes
| obj_control::texture;
const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
| isp_tsp_instruction_word::culling_mode::no_culling; | isp_tsp_instruction_word::culling_mode::no_culling;
const uint32_t tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one const uint32_t tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one
| tsp_instruction_word::dst_alpha_instr::zero | tsp_instruction_word::dst_alpha_instr::zero
| tsp_instruction_word::fog_control::no_fog; | tsp_instruction_word::fog_control::no_fog
| tsp_instruction_word::texture_u_size::from_int(128)
| tsp_instruction_word::texture_v_size::from_int(128);
uint32_t texture_address0 = (offsetof (struct texture_memory_alloc, texture)) + 128 * 128 * 2 * 0;
uint32_t texture_address1 = (offsetof (struct texture_memory_alloc, texture)) + 128 * 128 * 2 * 1;
const uint32_t texture_control_word_0 = texture_control_word::pixel_format::_565
| texture_control_word::scan_order::twiddled
| texture_control_word::texture_address(texture_address0 / 8);
const uint32_t texture_control_word_1 = texture_control_word::pixel_format::_565
| texture_control_word::scan_order::twiddled
| texture_control_word::texture_address(texture_address1 / 8);
parameter.append<ta_global_parameter::polygon_type_3>() = parameter.append<ta_global_parameter::polygon_type_3>() =
ta_global_parameter::polygon_type_3(parameter_control_word, ta_global_parameter::polygon_type_3(parameter_control_word,
isp_tsp_instruction_word, isp_tsp_instruction_word,
tsp_instruction_word, // tsp_instruction_word_0 tsp_instruction_word, // tsp_instruction_word_0
0, // texture_control_word_0 texture_control_word_0, // texture_control_word_0
tsp_instruction_word, // tsp_instruction_word_1 tsp_instruction_word, // tsp_instruction_word_1
0, // texture_control_word_1 texture_control_word_1, // texture_control_word_1
0, // data_size_for_sort_dma 0, // data_size_for_sort_dma
0 // next_address_for_sort_dma 0 // next_address_for_sort_dma
); );
@ -108,16 +213,25 @@ void transform_polygon(ta_parameter_writer& parameter,
// world transform // world transform
uint32_t vertex_ix = face[i].vertex; uint32_t vertex_ix = face[i].vertex;
auto& vertex = vertices[vertex_ix]; auto& vertex = vertices[vertex_ix];
auto point = _transform(vertex, scale, theta); auto point = _transform(vertex, scale, rot_pos);
uint32_t texture_ix = face[i].texture;
auto& uv = texture[texture_ix];
bool end_of_strip = i == strip_length - 1; bool end_of_strip = i == strip_length - 1;
parameter.append<ta_vertex_parameter::polygon_type_9>() = parameter.append<ta_vertex_parameter::polygon_type_11>() =
ta_vertex_parameter::polygon_type_9(polygon_vertex_parameter_control_word(end_of_strip), ta_vertex_parameter::polygon_type_11(polygon_vertex_parameter_control_word(end_of_strip),
point.x, point.x,
point.y, point.y,
point.z, point.z,
argb8888(color0), uv.u,
argb8888(color1) uv.v,
argb8888(color0), // base_color_0
0, // offset_color_0
uv.u,
uv.v,
argb8888(color1), // base_color_1
0 // offset_color_1
); );
} }
} }
@ -150,9 +264,9 @@ void transform_modifier_volume(ta_parameter_writer& parameter,
auto& _a = vertices[ix_a]; auto& _a = vertices[ix_a];
auto& _b = vertices[ix_b]; auto& _b = vertices[ix_b];
auto& _c = vertices[ix_c]; auto& _c = vertices[ix_c];
auto a = _transform(_a, scale, 0.f); auto a = _transform(_a, scale);
auto b = _transform(_b, scale, 0.f); auto b = _transform(_b, scale);
auto c = _transform(_c, scale, 0.f); auto c = _transform(_c, scale);
if (i == (num_faces - 1)) { if (i == (num_faces - 1)) {
const uint32_t last_parameter_control_word = para_control::para_type::polygon_or_modifier_volume const uint32_t last_parameter_control_word = para_control::para_type::polygon_or_modifier_volume
@ -190,15 +304,64 @@ void init_texture_memory(const struct opb_size& opb_size)
); );
} }
void
load_texture(const uint8_t * src,
const uint32_t size,
const uint32_t ix)
{
auto mem = reinterpret_cast<volatile texture_memory_alloc *>(texture_memory64);
uint16_t temp[size / 3];
for (uint32_t px = 0; px < size / 3; px++) {
uint8_t r = src[px * 3 + 0];
uint8_t g = src[px * 3 + 1];
uint8_t b = src[px * 3 + 2];
uint16_t rgb565 = ((r / 8) << 11) | ((g / 4) << 5) | ((b / 8) << 0);
temp[px] = rgb565;
}
twiddle::texture(&mem->texture[(128 * 128 * 2 * ix) / 2], temp, 128, 128);
}
void update_rot_pos(struct rot_pos& rot_pos)
{
const float l_pos = static_cast<float>(data[0].analog_axis_1) * (1.f / 255.f);
const float r_pos = static_cast<float>(data[0].analog_axis_2) * (1.f / 255.f);
const float x_pos = static_cast<float>(data[0].analog_axis_3 - 0x80) * (0.5f / 127.f);
const float y_pos = static_cast<float>(data[0].analog_axis_4 - 0x80) * (0.5f / 127.f);
const float rotation = (l_pos > r_pos) ? (l_pos) : (-r_pos);
constexpr float half_degree = 0.01745329f / 2;
rot_pos.x += x_pos / 10.f;
rot_pos.y += y_pos / 10.f;
rot_pos.theta += rotation * half_degree * 10.f;
}
uint32_t _ta_parameter_buf[((32 * 8192) + 32) / 4]; uint32_t _ta_parameter_buf[((32 * 8192) + 32) / 4];
uint32_t _command_buf[1024 / 4 + 32];
uint32_t _receive_buf[1024 / 4 + 32];
void main() void main()
{ {
vga(); vga();
auto src0 = reinterpret_cast<const uint8_t *>(&_binary_macaw_data_start);
auto size0 = reinterpret_cast<const uint32_t>(&_binary_macaw_data_size);
auto src1 = reinterpret_cast<const uint8_t *>(&_binary_wolf_data_start);
auto size1 = reinterpret_cast<const uint32_t>(&_binary_wolf_data_size);
load_texture(src0, size0, 0);
load_texture(src1, size1, 1);
// The address of `ta_parameter_buf` must be a multiple of 32 bytes. // The address of `ta_parameter_buf` must be a multiple of 32 bytes.
// This is mandatory for ch2-dma to the ta fifo polygon converter. // This is mandatory for ch2-dma to the ta fifo polygon converter.
uint32_t * ta_parameter_buf = align_32byte(_ta_parameter_buf); uint32_t * ta_parameter_buf = align_32byte(_ta_parameter_buf);
uint32_t * command_buf = align_32byte(_command_buf);
uint32_t * receive_buf = align_32byte(_receive_buf);
constexpr uint32_t ta_alloc = ta_alloc_ctrl::pt_opb::no_list constexpr uint32_t ta_alloc = ta_alloc_ctrl::pt_opb::no_list
| ta_alloc_ctrl::tm_opb::no_list | ta_alloc_ctrl::tm_opb::no_list
@ -224,26 +387,31 @@ void main()
uint32_t frame_ix = 0; uint32_t frame_ix = 0;
constexpr uint32_t num_frames = 1; constexpr uint32_t num_frames = 1;
float theta = 0; struct rot_pos rot_pos = { 0.f, 0.f, 0.f };
while (true) { while (true) {
do_get_condition(command_buf, receive_buf);
update_rot_pos(rot_pos);
ta_polygon_converter_init(opb_size.total(), ta_polygon_converter_init(opb_size.total(),
ta_alloc, ta_alloc,
640 / 32, 640 / 32,
480 / 32); 480 / 32);
auto parameter = ta_parameter_writer(ta_parameter_buf); auto parameter = ta_parameter_writer(ta_parameter_buf);
{ // plane { // plane
vec4 color0 = {1.0, 0.9, 0.4, 0.2}; vec4 color0 = {1.0, 0.9, 0.9, 0.9};
vec4 color1 = {1.0, 0.2, 0.9, 0.9}; vec4 color1 = {1.0, 0.9, 0.9, 0.9};
float scale = 2.f; float scale = 2.f;
for (uint32_t i = 0; i < plane::num_faces; i++) { for (uint32_t i = 0; i < plane::num_faces; i++) {
transform_polygon(parameter, transform_polygon(parameter,
plane::vertices, plane::vertices,
plane::texture,
plane::faces[i], plane::faces[i],
scale, scale,
color0, color0,
color1, color1,
theta); rot_pos);
} }
/* /*
@ -278,8 +446,6 @@ void main()
v_sync_in(); v_sync_in();
core_wait_end_of_render_video(frame_ix, num_frames); core_wait_end_of_render_video(frame_ix, num_frames);
constexpr float half_degree = 0.01745329f / 2;
theta += half_degree;
frame_ix += 1; frame_ix += 1;
} }
} }

View File

@ -1,9 +1,9 @@
#include <cstdint> #include <cstdint>
#include "sh7091.hpp" #include "sh7091/sh7091.hpp"
#include "sh7091_bits.hpp" #include "sh7091/sh7091_bits.hpp"
#include "sh7091/cache.hpp"
#include "cache.hpp"
#include "serial_load.hpp" #include "serial_load.hpp"
extern uint32_t __bss_link_start __asm("__bss_link_start"); extern uint32_t __bss_link_start __asm("__bss_link_start");
@ -22,13 +22,15 @@ void main()
load_init(); load_init();
while (1) { while (1) {
while ((sh7091.SCIF.SCFSR2 & SCFSR2__TDFE) == 0) { using namespace scif;
while ((sh7091.SCIF.SCFSR2 & scfsr2::tdfe::bit_mask) == 0) {
// wait // wait
} }
while ((sh7091.SCIF.SCFDR2 & 0b11111) > 0) { while ((scfdr2::receive_data_bytes(sh7091.SCIF.SCFDR2)) > 0) {
uint8_t c = sh7091.SCIF.SCFRDR2; uint8_t c = sh7091.SCIF.SCFRDR2;
load_recv(c); load_recv(c);
} }
sh7091.SCIF.SCFSR2 = sh7091.SCIF.SCFSR2 & (~SCFSR2__RDF); sh7091.SCIF.SCFSR2 = sh7091.SCIF.SCFSR2 & (~scfsr2::rdf::bit_mask);
} }
} }

View File

@ -3,15 +3,18 @@
#include "align.hpp" #include "align.hpp"
#include "vga.hpp" #include "vga.hpp"
#include "holly/texture_memory_alloc.hpp" #include "holly/holly.hpp"
#include "holly.hpp"
#include "holly/core.hpp" #include "holly/core.hpp"
#include "holly/core_bits.hpp" #include "holly/core_bits.hpp"
#include "holly/ta_fifo_polygon_converter.hpp" #include "holly/ta_fifo_polygon_converter.hpp"
#include "holly/ta_parameter.hpp" #include "holly/ta_parameter.hpp"
#include "holly/ta_global_parameter.hpp"
#include "holly/ta_vertex_parameter.hpp"
#include "holly/isp_tsp.hpp"
#include "holly/ta_bits.hpp" #include "holly/ta_bits.hpp"
#include "holly/region_array.hpp" #include "holly/region_array.hpp"
#include "holly/background.hpp" #include "holly/background.hpp"
#include "holly/texture_memory_alloc.hpp"
#include "memorymap.hpp" #include "memorymap.hpp"
#include "macaw.hpp" #include "macaw.hpp"
@ -43,29 +46,60 @@ uint32_t transform(uint32_t * ta_parameter_buf,
bool translucent) bool translucent)
{ {
auto parameter = ta_parameter_writer(ta_parameter_buf); auto parameter = ta_parameter_writer(ta_parameter_buf);
uint32_t texture_address = (offsetof (struct texture_memory_alloc, texture));
if (translucent) { if (translucent) {
// translucent untextured // translucent untextured
auto polygon = global_polygon_type_0(); const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
polygon.parameter_control_word = para_control::para_type::polygon_or_modifier_volume
| para_control::list_type::translucent | para_control::list_type::translucent
| obj_control::col_type::packed_color | obj_control::col_type::packed_color
| obj_control::gouraud; | obj_control::gouraud;
polygon.tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
| isp_tsp_instruction_word::culling_mode::no_culling;
const uint32_t tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one
| tsp_instruction_word::dst_alpha_instr::src_alpha | tsp_instruction_word::dst_alpha_instr::src_alpha
| tsp_instruction_word::fog_control::no_fog | tsp_instruction_word::fog_control::no_fog
| tsp_instruction_word::use_alpha; | tsp_instruction_word::use_alpha;
parameter.append<global_polygon_type_0>() = polygon; parameter.append<ta_global_parameter::polygon_type_0>() =
ta_global_parameter::polygon_type_0(parameter_control_word,
isp_tsp_instruction_word,
tsp_instruction_word,
0, // texture_control_word
0, // data_size_for_sort_dma
0 // next_address_for_sort_dma
);
} else { } else {
// opaque textured const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
parameter.append<global_polygon_type_0>() = global_polygon_type_0(texture_address); | para_control::list_type::opaque
| obj_control::col_type::packed_color
| obj_control::texture;
const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
| isp_tsp_instruction_word::culling_mode::no_culling;
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_u_size::from_int(128)
| tsp_instruction_word::texture_v_size::from_int(128);
const uint32_t texture_address = (offsetof (struct texture_memory_alloc, texture));
const uint32_t 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.append<ta_global_parameter::polygon_type_0>() =
ta_global_parameter::polygon_type_0(parameter_control_word,
isp_tsp_instruction_word,
tsp_instruction_word,
texture_control_word,
0, // data_size_for_sort_dma
0 // next_address_for_sort_dma
);
} }
for (uint32_t i = 0; i < strip_length; i++) { for (uint32_t i = 0; i < strip_length; i++) {
bool end_of_strip = i == strip_length - 1;
float x = strip_vertices[i].x; float x = strip_vertices[i].x;
float y = strip_vertices[i].y; float y = strip_vertices[i].y;
float z = strip_vertices[i].z; float z = strip_vertices[i].z;
@ -80,15 +114,18 @@ uint32_t transform(uint32_t * ta_parameter_buf,
y += 240.f; y += 240.f;
z = 1.f / (z + 10.f); z = 1.f / (z + 10.f);
parameter.append<vertex_polygon_type_3>() = bool end_of_strip = i == strip_length - 1;
vertex_polygon_type_3(x, y, z, parameter.append<ta_vertex_parameter::polygon_type_3>() =
ta_vertex_parameter::polygon_type_3(polygon_vertex_parameter_control_word(end_of_strip),
x, y, z,
strip_vertices[i].u, strip_vertices[i].u,
strip_vertices[i].v, strip_vertices[i].v,
strip_vertices[i].color, strip_vertices[i].color,
end_of_strip); 0 // offset_color
);
} }
parameter.append<global_end_of_list>() = global_end_of_list(); parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
return parameter.offset; return parameter.offset;
} }
@ -97,7 +134,7 @@ void init_texture_memory(const struct opb_size& opb_size)
{ {
auto mem = reinterpret_cast<volatile texture_memory_alloc *>(texture_memory32); auto mem = reinterpret_cast<volatile texture_memory_alloc *>(texture_memory32);
background_parameter(mem->background); background_parameter(mem->background, 0xffffff00);
region_array2(mem->region_array, region_array2(mem->region_array,
(offsetof (struct texture_memory_alloc, object_list)), (offsetof (struct texture_memory_alloc, object_list)),
@ -142,8 +179,6 @@ void main()
, .punch_through = 0 , .punch_through = 0
}; };
constexpr uint32_t tiles = (640 / 32) * (320 / 32);
holly.SOFTRESET = softreset::pipeline_soft_reset holly.SOFTRESET = softreset::pipeline_soft_reset
| softreset::ta_soft_reset; | softreset::ta_soft_reset;
holly.SOFTRESET = 0; holly.SOFTRESET = 0;
@ -155,7 +190,10 @@ void main()
constexpr uint32_t num_frames = 1; constexpr uint32_t num_frames = 1;
while (true) { while (true) {
ta_polygon_converter_init(opb_size.total() * tiles, ta_alloc); ta_polygon_converter_init(opb_size.total(),
ta_alloc,
640 / 32,
480 / 32);
uint32_t ta_parameter_size = 0; uint32_t ta_parameter_size = 0;
ta_parameter_size += transform(&ta_parameter_buf[ta_parameter_size / 4], strip_vertices, strip_length, 0); ta_parameter_size += transform(&ta_parameter_buf[ta_parameter_size / 4], strip_vertices, strip_length, 0);
ta_parameter_size += transform(&ta_parameter_buf[ta_parameter_size / 4], strip_vertices, strip_length, 1); ta_parameter_size += transform(&ta_parameter_buf[ta_parameter_size / 4], strip_vertices, strip_length, 1);

223
example/viewing_system.cpp Normal file
View File

@ -0,0 +1,223 @@
#include <cstdint>
#include "align.hpp"
#include "vga.hpp"
#include "holly/texture_memory_alloc.hpp"
#include "holly/holly.hpp"
#include "holly/core.hpp"
#include "holly/core_bits.hpp"
#include "holly/ta_fifo_polygon_converter.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/region_array.hpp"
#include "holly/background.hpp"
#include "holly/isp_tsp.hpp"
#include "memorymap.hpp"
#include "geometry/geometry.hpp"
#include "geometry/suzanne2.hpp"
#include "geometry/plane2.hpp"
#include "viewing_system/view_space.hpp"
#include "viewing_system/screen_space.hpp"
uint32_t _ta_parameter_buf[((32 * 8192) + 32) / 4];
struct viewer {
vec3 position;
vec3 orientation;
float azimuth;
float colatitude;
};
void ta_upload(ta_parameter_writer& parameter,
const position__color * vertices,
const face_vtn * faces,
const uint32_t num_faces,
const mat4x4 world_transform,
const mat4x4 screen_transform
)
{
const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
| para_control::list_type::opaque
| obj_control::col_type::floating_color
| obj_control::gouraud;
const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
| isp_tsp_instruction_word::culling_mode::no_culling;
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;
for (uint32_t face_ix = 0; face_ix < num_faces; face_ix++) {
parameter.append<ta_global_parameter::polygon_type_0>() =
ta_global_parameter::polygon_type_0(parameter_control_word,
isp_tsp_instruction_word,
tsp_instruction_word,
0, // texture_control_word
0, // data_size_for_sort_dma
0 // next_address_for_sort_dma
);
auto& face = faces[face_ix];
constexpr uint32_t strip_length = 3;
mat4x4 transform = screen_transform * world_transform;
for (uint32_t i = 0; i < strip_length; i++) {
const uint32_t vertex_ix = face[i].vertex;
auto& position = vertices[vertex_ix].position;
auto& color = vertices[vertex_ix].color;
vec4 vertex = { position.x,
position.y,
position.z,
1.0f };
// in three-dimensional screen space
vec4 v = transform * vertex;
float x = v.x / v.w;
float y = -v.y / v.w;
float z = v.w / v.z;
x = x * 240.f + 320.f;
y = y * 240.f + 240.f;
// perspective divide
bool end_of_strip = i == strip_length - 1;
parameter.append<ta_vertex_parameter::polygon_type_1>() =
ta_vertex_parameter::polygon_type_1(polygon_vertex_parameter_control_word(end_of_strip),
x,
y,
z,
1.0f, // alpha
color.r, // red
color.g, // green
color.b // blue
);
}
}
}
void init_texture_memory(const struct opb_size& opb_size)
{
auto mem = reinterpret_cast<volatile texture_memory_alloc *>(texture_memory32);
background_parameter(mem->background, 0xff220000);
holly.VO_BORDER_COL = 0x00220000;
region_array2(mem->region_array,
(offsetof (struct texture_memory_alloc, object_list)),
640 / 32, // width
480 / 32, // height
opb_size
);
}
void main()
{
vga();
// The address of `ta_parameter_buf` must be a multiple of 32 bytes.
// This is mandatory for ch2-dma to the ta fifo polygon converter.
uint32_t * ta_parameter_buf = align_32byte(_ta_parameter_buf);
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::_16x4byte;
constexpr struct opb_size opb_size = { .opaque = 16 * 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();
init_texture_memory(opb_size);
float delta = 0;
uint32_t frame_ix = 0;
constexpr uint32_t num_frames = 1;
while (true) {
viewer viewer {
.position = {0.f, -1.f, -2.f},
.orientation = {0.f, -1.f, 0.f}, // approximate "up" orientation
.azimuth = 0,
.colatitude = pi / 4.f * sin(delta) * 0.9f,
};
const vec3 plane_normal = view_space::viewing_direction(viewer.azimuth, viewer.colatitude);
const vec3 up_vector = view_space::project_vector_to_plane(plane_normal, viewer.orientation);
const mat4x4 view_space_transform = view_space::transformation_matrix(viewer.position, plane_normal, up_vector);
const mat4x4 perspective_transform = screen_space::transformation_matrix(1.f, // the z-coordinate of the view window
100.f, // the z-coordinate of the far clip plane
1.f // the dimension of the square view window
);
const mat4x4 screen_transform = perspective_transform * view_space_transform;
ta_polygon_converter_init(opb_size.total(),
ta_alloc,
640 / 32,
480 / 32);
auto parameter = ta_parameter_writer(ta_parameter_buf);
{
constexpr mat4x4 world_transform = { 1.f, 0.f, 0.f, 0.f,
0.f, 1.f, 0.f, 0.f,
0.f, 0.f, 1.f, 3.f,
0.f, 0.f, 0.f, 1.f };
ta_upload(parameter,
suzanne::vertices,
suzanne::faces,
suzanne::num_faces,
world_transform,
screen_transform
);
}
{
constexpr mat4x4 world_transform = { 0.1f, 0.f, 0.f, 0.f,
0.f, 0.1f, 0.f, 1.2f,
0.f, 0.f, 0.1f, 3.f,
0.f, 0.f, 0.f, 1.f };
ta_upload(parameter,
plane::vertices,
plane::faces,
plane::num_faces,
world_transform,
screen_transform
);
}
// end of opaque list
parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
ta_polygon_converter_transfer(ta_parameter_buf, parameter.offset);
ta_wait_opaque_list();
core_start_render(frame_ix, num_frames);
v_sync_out();
core_wait_end_of_render_video(frame_ix, num_frames);
frame_ix += 1;
delta += pi * 2 / 360;
}
}

View File

@ -1,19 +1,21 @@
#include <cstdint> #include <cstdint>
#include "align.hpp" #include "align.hpp"
#include "vga.hpp" #include "vga.hpp"
#include "holly.hpp"
#include "holly/holly.hpp"
#include "holly/core.hpp" #include "holly/core.hpp"
#include "holly/core_bits.hpp" #include "holly/core_bits.hpp"
#include "holly/ta_fifo_polygon_converter.hpp" #include "holly/ta_fifo_polygon_converter.hpp"
#include "holly/ta_parameter.hpp" #include "holly/ta_parameter.hpp"
#include "holly/ta_global_parameter.hpp"
#include "holly/ta_vertex_parameter.hpp"
#include "holly/isp_tsp.hpp"
#include "holly/ta_bits.hpp" #include "holly/ta_bits.hpp"
#include "holly/region_array.hpp" #include "holly/region_array.hpp"
#include "holly/background.hpp" #include "holly/background.hpp"
#include "holly/texture_memory_alloc.hpp" #include "holly/texture_memory_alloc.hpp"
#include "memorymap.hpp" #include "memorymap.hpp"
#include "serial.hpp"
#include "geometry/wiffle.hpp" #include "geometry/wiffle.hpp"
#include "math/vec4.hpp" #include "math/vec4.hpp"
@ -59,16 +61,19 @@ void transform(ta_parameter_writer& parameter,
| tsp_instruction_word::dst_alpha_instr::zero | tsp_instruction_word::dst_alpha_instr::zero
| tsp_instruction_word::fog_control::no_fog; | tsp_instruction_word::fog_control::no_fog;
parameter.append<global_polygon_type_0>() = global_polygon_type_0(parameter_control_word, parameter.append<ta_global_parameter::polygon_type_0>() =
ta_global_parameter::polygon_type_0(parameter_control_word,
isp_tsp_instruction_word, isp_tsp_instruction_word,
tsp_instruction_word, tsp_instruction_word,
0); 0, // texture_control_word
0, // data_size_for_sort_dma
0 // next_address_for_sort_dma
);
auto& face = MODEL::faces[face_ix]; auto& face = MODEL::faces[face_ix];
constexpr uint32_t strip_length = 3; constexpr uint32_t strip_length = 3;
for (uint32_t i = 0; i < strip_length; i++) { for (uint32_t i = 0; i < strip_length; i++) {
bool end_of_strip = i == strip_length - 1;
// world transform // world transform
uint32_t vertex_ix = face[i].vertex; uint32_t vertex_ix = face[i].vertex;
auto& vertex = MODEL::vertices[vertex_ix]; auto& vertex = MODEL::vertices[vertex_ix];
@ -140,13 +145,15 @@ void transform(ta_parameter_writer& parameter,
y += 240.f; y += 240.f;
z = 1 / z; z = 1 / z;
parameter.append<vertex_polygon_type_1>() = bool end_of_strip = i == strip_length - 1;
vertex_polygon_type_1(x, y, z, parameter.append<ta_vertex_parameter::polygon_type_1>() =
ta_vertex_parameter::polygon_type_1(polygon_vertex_parameter_control_word(end_of_strip),
x, y, z,
color.w, // alpha color.w, // alpha
color.x, // r color.x, // r
color.y, // g color.y, // g
color.z, // b color.z // b
end_of_strip); );
} }
} }
@ -166,10 +173,14 @@ void transform2(ta_parameter_writer& parameter,
| tsp_instruction_word::dst_alpha_instr::zero | tsp_instruction_word::dst_alpha_instr::zero
| tsp_instruction_word::fog_control::no_fog; | tsp_instruction_word::fog_control::no_fog;
parameter.append<global_polygon_type_0>() = global_polygon_type_0(parameter_control_word, parameter.append<ta_global_parameter::polygon_type_0>() =
ta_global_parameter::polygon_type_0(parameter_control_word,
isp_tsp_instruction_word, isp_tsp_instruction_word,
tsp_instruction_word, tsp_instruction_word,
0); 0, // texture_control_word
0, // data_size_for_sort_dma
0 // next_address_for_sort_dma
);
constexpr vec3 triangle[] = { constexpr vec3 triangle[] = {
{ 0.f, -1.f, 0.f}, { 0.f, -1.f, 0.f},
@ -179,7 +190,6 @@ void transform2(ta_parameter_writer& parameter,
constexpr uint32_t strip_length = 3; constexpr uint32_t strip_length = 3;
for (uint32_t i = 0; i < strip_length; i++) { for (uint32_t i = 0; i < strip_length; i++) {
bool end_of_strip = i == strip_length - 1;
float x = triangle[i].x; float x = triangle[i].x;
float y = triangle[i].y; float y = triangle[i].y;
float z = triangle[i].z; float z = triangle[i].z;
@ -206,13 +216,15 @@ void transform2(ta_parameter_writer& parameter,
y += 240.f; y += 240.f;
z = 1 / z; z = 1 / z;
parameter.append<vertex_polygon_type_1>() = bool end_of_strip = i == strip_length - 1;
vertex_polygon_type_1(x, y, z, parameter.append<ta_vertex_parameter::polygon_type_1>() =
ta_vertex_parameter::polygon_type_1(polygon_vertex_parameter_control_word(end_of_strip),
x, y, z,
color.w, // alpha color.w, // alpha
color.x, // r color.x, // r
color.y, // g color.y, // g
color.z, // b color.z // b
end_of_strip); );
} }
} }
@ -295,7 +307,7 @@ void main()
transform2(parameter, lights[1], {0.f, 1.f, 0.f, 1.f}); transform2(parameter, lights[1], {0.f, 1.f, 0.f, 1.f});
transform2(parameter, lights[2], {0.f, 0.f, 1.f, 1.f}); transform2(parameter, lights[2], {0.f, 0.f, 1.f, 1.f});
parameter.append<global_end_of_list>() = global_end_of_list(); parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
ta_polygon_converter_transfer(ta_parameter_buf, parameter.offset); ta_polygon_converter_transfer(ta_parameter_buf, parameter.offset);
ta_wait_opaque_list(); ta_wait_opaque_list();
core_start_render(frame_ix, num_frames); core_start_render(frame_ix, num_frames);

View File

@ -22,7 +22,7 @@ namespace border {
{ -0.000000f, 1.000000f, -0.000000f }, { -0.000000f, 1.000000f, -0.000000f },
}; };
constexpr face faces[] = { constexpr face_vn faces[] = {
{{ 5, 0}, {11, 0}, { 7, 0}}, {{ 5, 0}, {11, 0}, { 7, 0}},
{{ 4, 0}, {10, 0}, { 9, 0}}, {{ 4, 0}, {10, 0}, { 9, 0}},
{{ 5, 0}, { 8, 0}, {11, 0}}, {{ 5, 0}, { 8, 0}, {11, 0}},
@ -37,6 +37,6 @@ namespace border {
{{ 1, 0}, { 3, 0}, { 6, 0}}, {{ 1, 0}, { 3, 0}, { 6, 0}},
}; };
constexpr uint32_t num_faces = (sizeof (faces)) / (sizeof (face)); constexpr uint32_t num_faces = (sizeof (faces)) / (sizeof (face_vn));
} }

View File

@ -42,7 +42,7 @@ namespace circle {
{ -0.000000f, 1.000000f, -0.000000f }, { -0.000000f, 1.000000f, -0.000000f },
}; };
constexpr face faces[] = { constexpr face_vn faces[] = {
{{31, 0}, { 0, 0}, { 1, 0}}, {{31, 0}, { 0, 0}, { 1, 0}},
{{30, 0}, {31, 0}, { 1, 0}}, {{30, 0}, {31, 0}, { 1, 0}},
{{20, 0}, {13, 0}, {18, 0}}, {{20, 0}, {13, 0}, {18, 0}},
@ -75,6 +75,6 @@ namespace circle {
{{16, 0}, {17, 0}, {15, 0}}, {{16, 0}, {17, 0}, {15, 0}},
}; };
constexpr uint32_t num_faces = (sizeof (faces)) / (sizeof (face)); constexpr uint32_t num_faces = (sizeof (faces)) / (sizeof (face_vn));
} }

View File

@ -30,7 +30,7 @@ namespace cube {
{ -0.000000f, 1.000000f, -0.000000f }, { -0.000000f, 1.000000f, -0.000000f },
}; };
constexpr face faces[] = { constexpr face_vtn faces[] = {
{{1, 0, 0}, {2, 0, 0}, {0, 1, 0}}, {{1, 0, 0}, {2, 0, 0}, {0, 1, 0}},
{{3, 1, 1}, {6, 2, 1}, {2, 3, 1}}, {{3, 1, 1}, {6, 2, 1}, {2, 3, 1}},
{{7, 0, 2}, {4, 3, 2}, {6, 1, 2}}, {{7, 0, 2}, {4, 3, 2}, {6, 1, 2}},
@ -45,6 +45,6 @@ namespace cube {
{{3, 1, 5}, {1, 0, 5}, {5, 2, 5}}, {{3, 1, 5}, {1, 0, 5}, {5, 2, 5}},
}; };
constexpr uint32_t num_faces = (sizeof (faces)) / (sizeof (face)); constexpr uint32_t num_faces = (sizeof (faces)) / (sizeof (face_vtn));
} }

View File

@ -5,15 +5,30 @@
#include "math/vec2.hpp" #include "math/vec2.hpp"
#include "math/vec3.hpp" #include "math/vec3.hpp"
#include "math/vec4.hpp" #include "math/vec4.hpp"
#include "math/mat4x4.hpp"
using vec2 = vec<2, float>; using vec2 = vec<2, float>;
using vec3 = vec<3, float>; using vec3 = vec<3, float>;
using vec4 = vec<4, float>; using vec4 = vec<4, float>;
using mat4x4 = mat<4, 4, float>;
struct vertex__texture__normal { struct vertex__texture__normal {
uint16_t vertex; uint16_t vertex;
uint16_t texture; uint16_t texture;
uint16_t normal; uint16_t normal;
}; };
using face = vertex__texture__normal[3]; struct vertex__normal {
uint16_t vertex;
uint16_t normal;
};
struct position__color {
vec3 position;
vec3 color;
};
using face_vtn = vertex__texture__normal[3];
using face_vn = vertex__normal[3];

BIN
geometry/heart.blend Normal file

Binary file not shown.

247
geometry/heart.hpp Normal file
View File

@ -0,0 +1,247 @@
#pragma once
#include "geometry.hpp"
namespace heart {
constexpr position__color vertices[] = {
{ { 0.000000f, 0.400000f, -0.707107f}, { 1.000000f, 0.611800f, 0.211800f} },
{ { 0.144430f, -0.400000f, -0.831470f}, { 1.000000f, 0.000000f, 0.674500f} },
{ { 0.144430f, 0.400000f, -0.831470f}, { 1.000000f, 0.611800f, 0.215700f} },
{ { 0.317317f, -0.400000f, -0.923880f}, { 1.000000f, 0.000000f, 0.670600f} },
{ { 0.317317f, 0.400000f, -0.923880f}, { 1.000000f, 0.611800f, 0.211800f} },
{ { 0.504910f, -0.400000f, -0.980785f}, { 1.000000f, 0.011800f, 0.670600f} },
{ { 0.504910f, 0.400000f, -0.980785f}, { 1.000000f, 0.611800f, 0.211800f} },
{ { 0.700000f, -0.400000f, -1.000000f}, { 1.000000f, 0.000000f, 0.670600f} },
{ { 0.700000f, 0.400000f, -1.000000f}, { 1.000000f, 0.611800f, 0.211800f} },
{ { 0.895090f, -0.400000f, -0.980785f}, { 1.000000f, 0.000000f, 0.898000f} },
{ { 0.895090f, 0.400000f, -0.980785f}, { 1.000000f, 0.235300f, 0.843100f} },
{ { 1.082684f, -0.400000f, -0.923879f}, { 1.000000f, 0.023500f, 0.909800f} },
{ { 1.082684f, 0.400000f, -0.923879f}, { 1.000000f, 0.611800f, 0.211800f} },
{ { 1.255570f, -0.400000f, -0.831469f}, { 1.000000f, 0.329400f, 0.866600f} },
{ { 1.255570f, 0.400000f, -0.831469f}, { 1.000000f, 0.615700f, 0.219600f} },
{ { 1.407107f, -0.400000f, -0.707107f}, { 1.000000f, 0.282300f, 0.886200f} },
{ { 1.407107f, 0.400000f, -0.707107f}, { 1.000000f, 0.580400f, 0.384300f} },
{ { 1.531470f, -0.400000f, -0.555570f}, { 1.000000f, 0.282300f, 0.886200f} },
{ { 1.531470f, 0.400000f, -0.555570f}, { 1.000000f, 0.051000f, 0.600000f} },
{ { 1.623880f, -0.400000f, -0.382683f}, { 1.000000f, 0.282300f, 0.886200f} },
{ { 1.623880f, 0.400000f, -0.382683f}, { 1.000000f, 0.051000f, 0.603900f} },
{ { 1.680785f, -0.400000f, -0.195090f}, { 1.000000f, 0.615700f, 0.674500f} },
{ { 1.680785f, 0.400000f, -0.195090f}, { 1.000000f, 0.035300f, 0.776400f} },
{ { 1.700000f, -0.400000f, 0.000000f}, { 1.000000f, 0.623600f, 0.666700f} },
{ { 1.700000f, 0.400000f, 0.000000f}, { 0.988200f, 0.003900f, 0.996000f} },
{ { 1.680785f, -0.400000f, 0.195090f}, { 1.000000f, 0.000000f, 0.909800f} },
{ { 1.680785f, 0.400000f, 0.195090f}, { 0.843100f, 0.011800f, 0.956800f} },
{ { 1.623879f, -0.400000f, 0.382684f}, { 1.000000f, 0.011800f, 0.909800f} },
{ { 1.623879f, 0.400000f, 0.382684f}, { 0.611800f, 0.239200f, 0.976400f} },
{ { 1.531470f, -0.400000f, 0.555570f}, { 1.000000f, 0.643200f, 0.619700f} },
{ { 1.531470f, 0.400000f, 0.555570f}, { 0.611800f, 0.231400f, 0.976400f} },
{ { 1.407107f, 0.400000f, 0.707107f}, { 0.572500f, 0.235300f, 0.976400f} },
{ { 0.000000f, -0.400000f, -0.707107f}, { 1.000000f, 0.000000f, 0.670600f} },
{ {-0.000000f, 0.400000f, 2.121320f}, { 0.000000f, 0.807800f, 1.000000f} },
{ {-0.000000f, -0.400000f, 2.121320f}, { 1.000000f, 0.921500f, 0.000000f} },
{ { 1.407107f, -0.400000f, 0.707107f}, { 1.000000f, 0.780400f, 0.415700f} },
{ {-0.144430f, -0.400000f, -0.831470f}, { 0.901900f, 0.439200f, 0.603900f} },
{ {-0.144430f, 0.400000f, -0.831470f}, { 1.000000f, 0.611800f, 0.211800f} },
{ {-0.317317f, -0.400000f, -0.923880f}, { 0.670600f, 0.745100f, 0.603900f} },
{ {-0.317317f, 0.400000f, -0.923880f}, { 1.000000f, 0.607900f, 0.235300f} },
{ {-0.504910f, -0.400000f, -0.980785f}, { 0.235300f, 0.976400f, 0.196100f} },
{ {-0.504910f, 0.400000f, -0.980785f}, { 1.000000f, 0.047100f, 0.913700f} },
{ {-0.700000f, -0.400000f, -1.000000f}, { 0.403900f, 0.917600f, 0.360800f} },
{ {-0.700000f, 0.400000f, -1.000000f}, { 1.000000f, 0.000000f, 0.909800f} },
{ {-0.895090f, -0.400000f, -0.980785f}, { 0.403900f, 0.917600f, 0.360800f} },
{ {-0.895090f, 0.400000f, -0.980785f}, { 1.000000f, 0.000000f, 0.909800f} },
{ {-1.082683f, -0.400000f, -0.923880f}, { 0.262700f, 0.968600f, 0.223500f} },
{ {-1.082683f, 0.400000f, -0.923880f}, { 1.000000f, 0.117600f, 0.956800f} },
{ {-1.255570f, -0.400000f, -0.831470f}, { 0.560800f, 0.831300f, 0.505900f} },
{ {-1.255570f, 0.400000f, -0.831470f}, { 1.000000f, 0.000000f, 0.956800f} },
{ {-1.407107f, -0.400000f, -0.707107f}, { 0.776400f, 0.996000f, 0.090200f} },
{ {-1.407107f, 0.400000f, -0.707107f}, { 1.000000f, 0.117600f, 0.956800f} },
{ {-1.531470f, -0.400000f, -0.555570f}, { 0.878400f, 0.941100f, 0.305900f} },
{ {-1.531470f, 0.400000f, -0.555570f}, { 1.000000f, 0.000000f, 0.956800f} },
{ {-1.623880f, -0.400000f, -0.382683f}, { 0.882300f, 0.933300f, 0.325500f} },
{ {-1.623880f, 0.400000f, -0.382683f}, { 0.984300f, 1.000000f, 0.019600f} },
{ {-1.680785f, -0.400000f, -0.195090f}, { 0.745100f, 0.878400f, 0.458900f} },
{ {-1.680785f, 0.400000f, -0.195090f}, { 0.698000f, 0.741200f, 0.639300f} },
{ {-1.700000f, -0.400000f, -0.000000f}, { 0.219600f, 0.768600f, 0.639300f} },
{ {-1.700000f, 0.400000f, -0.000000f}, { 0.254900f, 1.000000f, 0.003900f} },
{ {-1.680785f, -0.400000f, 0.195090f}, { 0.051000f, 0.203900f, 0.980400f} },
{ {-1.680785f, 0.400000f, 0.195090f}, { 0.251000f, 1.000000f, 0.003900f} },
{ {-1.623879f, -0.400000f, 0.382683f}, { 0.054900f, 0.223500f, 0.976400f} },
{ {-1.623879f, 0.400000f, 0.382683f}, { 0.251000f, 1.000000f, 0.003900f} },
{ {-1.531470f, -0.400000f, 0.555570f}, { 0.098000f, 0.423500f, 0.901900f} },
{ {-1.531470f, 0.400000f, 0.555570f}, { 0.251000f, 1.000000f, 0.003900f} },
{ {-1.407107f, 0.400000f, 0.707107f}, { 0.254900f, 1.000000f, 0.007800f} },
{ {-1.407107f, -0.400000f, 0.707107f}, { 0.105900f, 0.203900f, 0.980400f} },
};
constexpr vec3 normals[] = {
{ -0.652500f, -0.000000f, -0.757800f },
{ -0.471400f, -0.000000f, -0.881900f },
{ -0.290300f, -0.000000f, -0.956900f },
{ -0.098000f, -0.000000f, -0.995200f },
{ 0.098000f, -0.000000f, -0.995200f },
{ 0.290300f, -0.000000f, -0.956900f },
{ 0.471400f, -0.000000f, -0.881900f },
{ 0.634400f, -0.000000f, -0.773000f },
{ 0.773000f, -0.000000f, -0.634400f },
{ 0.881900f, -0.000000f, -0.471400f },
{ 0.956900f, -0.000000f, -0.290300f },
{ 0.995200f, -0.000000f, -0.098000f },
{ 0.995200f, -0.000000f, 0.098000f },
{ 0.956900f, -0.000000f, 0.290300f },
{ 0.881900f, -0.000000f, 0.471400f },
{ 0.773000f, -0.000000f, 0.634400f },
{ -0.000000f, 1.000000f, -0.000000f },
{ -0.000000f, -1.000000f, -0.000000f },
{ 0.708900f, -0.000000f, 0.705300f },
{ 0.652500f, -0.000000f, -0.757800f },
{ -0.634400f, -0.000000f, -0.773000f },
{ -0.773000f, -0.000000f, -0.634400f },
{ -0.881900f, -0.000000f, -0.471400f },
{ -0.956900f, -0.000000f, -0.290300f },
{ -0.995200f, -0.000000f, -0.098000f },
{ -0.995200f, -0.000000f, 0.098000f },
{ -0.956900f, -0.000000f, 0.290300f },
{ -0.881900f, -0.000000f, 0.471400f },
{ -0.773000f, -0.000000f, 0.634400f },
{ -0.708900f, -0.000000f, 0.705300f },
};
constexpr face_vn faces[] = {
{{ 0, 0}, { 1, 0}, {32, 0}},
{{ 2, 1}, { 3, 1}, { 1, 1}},
{{ 4, 2}, { 5, 2}, { 3, 2}},
{{ 6, 3}, { 7, 3}, { 5, 3}},
{{ 8, 4}, { 9, 4}, { 7, 4}},
{{10, 5}, {11, 5}, { 9, 5}},
{{12, 6}, {13, 6}, {11, 6}},
{{14, 7}, {15, 7}, {13, 7}},
{{16, 8}, {17, 8}, {15, 8}},
{{18, 9}, {19, 9}, {17, 9}},
{{20, 10}, {21, 10}, {19, 10}},
{{22, 11}, {23, 11}, {21, 11}},
{{24, 12}, {25, 12}, {23, 12}},
{{26, 13}, {27, 13}, {25, 13}},
{{28, 14}, {29, 14}, {27, 14}},
{{30, 15}, {35, 15}, {29, 15}},
{{ 0, 16}, {18, 16}, {10, 16}},
{{ 1, 17}, {17, 17}, {25, 17}},
{{31, 18}, {34, 18}, {35, 18}},
{{35, 17}, {34, 17}, {32, 17}},
{{33, 16}, {31, 16}, { 0, 16}},
{{36, 19}, { 0, 19}, {32, 19}},
{{38, 6}, {37, 6}, {36, 6}},
{{40, 5}, {39, 5}, {38, 5}},
{{42, 4}, {41, 4}, {40, 4}},
{{44, 3}, {43, 3}, {42, 3}},
{{46, 2}, {45, 2}, {44, 2}},
{{48, 1}, {47, 1}, {46, 1}},
{{50, 20}, {49, 20}, {48, 20}},
{{52, 21}, {51, 21}, {50, 21}},
{{54, 22}, {53, 22}, {52, 22}},
{{56, 23}, {55, 23}, {54, 23}},
{{58, 24}, {57, 24}, {56, 24}},
{{60, 25}, {59, 25}, {58, 25}},
{{62, 26}, {61, 26}, {60, 26}},
{{64, 27}, {63, 27}, {62, 27}},
{{67, 28}, {65, 28}, {64, 28}},
{{39, 16}, {55, 16}, {63, 16}},
{{67, 17}, {50, 17}, {42, 17}},
{{34, 29}, {66, 29}, {67, 29}},
{{67, 17}, {32, 17}, {34, 17}},
{{33, 16}, { 0, 16}, {66, 16}},
{{ 0, 0}, { 2, 0}, { 1, 0}},
{{ 2, 1}, { 4, 1}, { 3, 1}},
{{ 4, 2}, { 6, 2}, { 5, 2}},
{{ 6, 3}, { 8, 3}, { 7, 3}},
{{ 8, 4}, {10, 4}, { 9, 4}},
{{10, 5}, {12, 5}, {11, 5}},
{{12, 6}, {14, 6}, {13, 6}},
{{14, 7}, {16, 7}, {15, 7}},
{{16, 8}, {18, 8}, {17, 8}},
{{18, 9}, {20, 9}, {19, 9}},
{{20, 10}, {22, 10}, {21, 10}},
{{22, 11}, {24, 11}, {23, 11}},
{{24, 12}, {26, 12}, {25, 12}},
{{26, 13}, {28, 13}, {27, 13}},
{{28, 14}, {30, 14}, {29, 14}},
{{30, 15}, {31, 15}, {35, 15}},
{{ 4, 16}, { 2, 16}, { 0, 16}},
{{ 0, 16}, {31, 16}, {30, 16}},
{{30, 16}, {28, 16}, {26, 16}},
{{26, 16}, {24, 16}, {22, 16}},
{{22, 16}, {20, 16}, {18, 16}},
{{18, 16}, {16, 16}, {14, 16}},
{{14, 16}, {12, 16}, {10, 16}},
{{10, 16}, { 8, 16}, { 6, 16}},
{{ 6, 16}, { 4, 16}, { 0, 16}},
{{ 0, 16}, {30, 16}, {26, 16}},
{{26, 16}, {22, 16}, {18, 16}},
{{18, 16}, {14, 16}, {10, 16}},
{{10, 16}, { 6, 16}, { 0, 16}},
{{ 0, 16}, {26, 16}, {18, 16}},
{{35, 17}, {32, 17}, { 1, 17}},
{{ 1, 17}, { 3, 17}, { 5, 17}},
{{ 5, 17}, { 7, 17}, { 9, 17}},
{{ 9, 17}, {11, 17}, {13, 17}},
{{13, 17}, {15, 17}, {17, 17}},
{{17, 17}, {19, 17}, {21, 17}},
{{21, 17}, {23, 17}, {25, 17}},
{{25, 17}, {27, 17}, {29, 17}},
{{29, 17}, {35, 17}, { 1, 17}},
{{ 1, 17}, { 5, 17}, { 9, 17}},
{{ 9, 17}, {13, 17}, {17, 17}},
{{17, 17}, {21, 17}, {25, 17}},
{{25, 17}, {29, 17}, { 1, 17}},
{{ 1, 17}, { 9, 17}, {17, 17}},
{{31, 18}, {33, 18}, {34, 18}},
{{36, 19}, {37, 19}, { 0, 19}},
{{38, 6}, {39, 6}, {37, 6}},
{{40, 5}, {41, 5}, {39, 5}},
{{42, 4}, {43, 4}, {41, 4}},
{{44, 3}, {45, 3}, {43, 3}},
{{46, 2}, {47, 2}, {45, 2}},
{{48, 1}, {49, 1}, {47, 1}},
{{50, 20}, {51, 20}, {49, 20}},
{{52, 21}, {53, 21}, {51, 21}},
{{54, 22}, {55, 22}, {53, 22}},
{{56, 23}, {57, 23}, {55, 23}},
{{58, 24}, {59, 24}, {57, 24}},
{{60, 25}, {61, 25}, {59, 25}},
{{62, 26}, {63, 26}, {61, 26}},
{{64, 27}, {65, 27}, {63, 27}},
{{67, 28}, {66, 28}, {65, 28}},
{{ 0, 16}, {37, 16}, {39, 16}},
{{39, 16}, {41, 16}, {43, 16}},
{{43, 16}, {45, 16}, {47, 16}},
{{47, 16}, {49, 16}, {51, 16}},
{{51, 16}, {53, 16}, {55, 16}},
{{55, 16}, {57, 16}, {59, 16}},
{{59, 16}, {61, 16}, {63, 16}},
{{63, 16}, {65, 16}, {66, 16}},
{{66, 16}, { 0, 16}, {39, 16}},
{{39, 16}, {43, 16}, {47, 16}},
{{47, 16}, {51, 16}, {55, 16}},
{{55, 16}, {59, 16}, {63, 16}},
{{63, 16}, {66, 16}, {39, 16}},
{{39, 16}, {47, 16}, {55, 16}},
{{36, 17}, {32, 17}, {67, 17}},
{{67, 17}, {64, 17}, {62, 17}},
{{62, 17}, {60, 17}, {58, 17}},
{{58, 17}, {56, 17}, {54, 17}},
{{54, 17}, {52, 17}, {50, 17}},
{{50, 17}, {48, 17}, {46, 17}},
{{46, 17}, {44, 17}, {42, 17}},
{{42, 17}, {40, 17}, {38, 17}},
{{38, 17}, {36, 17}, {67, 17}},
{{67, 17}, {62, 17}, {58, 17}},
{{58, 17}, {54, 17}, {50, 17}},
{{50, 17}, {46, 17}, {42, 17}},
{{42, 17}, {38, 17}, {67, 17}},
{{67, 17}, {58, 17}, {50, 17}},
{{34, 29}, {33, 29}, {66, 29}},
};
constexpr uint32_t num_faces = (sizeof (faces)) / (sizeof (face_vn));
}

234
geometry/heart.obj Normal file
View File

@ -0,0 +1,234 @@
# Blender 3.3.6
# www.blender.org
o Heart
v 0.000000 0.400000 -0.707107 1.0000 0.6118 0.2118
v 0.144430 -0.400000 -0.831470 1.0000 0.0000 0.6745
v 0.144430 0.400000 -0.831470 1.0000 0.6118 0.2157
v 0.317317 -0.400000 -0.923880 1.0000 0.0000 0.6706
v 0.317317 0.400000 -0.923880 1.0000 0.6118 0.2118
v 0.504910 -0.400000 -0.980785 1.0000 0.0118 0.6706
v 0.504910 0.400000 -0.980785 1.0000 0.6118 0.2118
v 0.700000 -0.400000 -1.000000 1.0000 0.0000 0.6706
v 0.700000 0.400000 -1.000000 1.0000 0.6118 0.2118
v 0.895090 -0.400000 -0.980785 1.0000 0.0000 0.8980
v 0.895090 0.400000 -0.980785 1.0000 0.2353 0.8431
v 1.082684 -0.400000 -0.923879 1.0000 0.0235 0.9098
v 1.082684 0.400000 -0.923879 1.0000 0.6118 0.2118
v 1.255570 -0.400000 -0.831469 1.0000 0.3294 0.8666
v 1.255570 0.400000 -0.831469 1.0000 0.6157 0.2196
v 1.407107 -0.400000 -0.707107 1.0000 0.2823 0.8862
v 1.407107 0.400000 -0.707107 1.0000 0.5804 0.3843
v 1.531470 -0.400000 -0.555570 1.0000 0.2823 0.8862
v 1.531470 0.400000 -0.555570 1.0000 0.0510 0.6000
v 1.623880 -0.400000 -0.382683 1.0000 0.2823 0.8862
v 1.623880 0.400000 -0.382683 1.0000 0.0510 0.6039
v 1.680785 -0.400000 -0.195090 1.0000 0.6157 0.6745
v 1.680785 0.400000 -0.195090 1.0000 0.0353 0.7764
v 1.700000 -0.400000 0.000000 1.0000 0.6236 0.6667
v 1.700000 0.400000 0.000000 0.9882 0.0039 0.9960
v 1.680785 -0.400000 0.195090 1.0000 0.0000 0.9098
v 1.680785 0.400000 0.195090 0.8431 0.0118 0.9568
v 1.623879 -0.400000 0.382684 1.0000 0.0118 0.9098
v 1.623879 0.400000 0.382684 0.6118 0.2392 0.9764
v 1.531470 -0.400000 0.555570 1.0000 0.6432 0.6197
v 1.531470 0.400000 0.555570 0.6118 0.2314 0.9764
v 1.407107 0.400000 0.707107 0.5725 0.2353 0.9764
v 0.000000 -0.400000 -0.707107 1.0000 0.0000 0.6706
v -0.000000 0.400000 2.121320 0.0000 0.8078 1.0000
v -0.000000 -0.400000 2.121320 1.0000 0.9215 0.0000
v 1.407107 -0.400000 0.707107 1.0000 0.7804 0.4157
v -0.144430 -0.400000 -0.831470 0.9019 0.4392 0.6039
v -0.144430 0.400000 -0.831470 1.0000 0.6118 0.2118
v -0.317317 -0.400000 -0.923880 0.6706 0.7451 0.6039
v -0.317317 0.400000 -0.923880 1.0000 0.6079 0.2353
v -0.504910 -0.400000 -0.980785 0.2353 0.9764 0.1961
v -0.504910 0.400000 -0.980785 1.0000 0.0471 0.9137
v -0.700000 -0.400000 -1.000000 0.4039 0.9176 0.3608
v -0.700000 0.400000 -1.000000 1.0000 0.0000 0.9098
v -0.895090 -0.400000 -0.980785 0.4039 0.9176 0.3608
v -0.895090 0.400000 -0.980785 1.0000 0.0000 0.9098
v -1.082683 -0.400000 -0.923880 0.2627 0.9686 0.2235
v -1.082683 0.400000 -0.923880 1.0000 0.1176 0.9568
v -1.255570 -0.400000 -0.831470 0.5608 0.8313 0.5059
v -1.255570 0.400000 -0.831470 1.0000 0.0000 0.9568
v -1.407107 -0.400000 -0.707107 0.7764 0.9960 0.0902
v -1.407107 0.400000 -0.707107 1.0000 0.1176 0.9568
v -1.531470 -0.400000 -0.555570 0.8784 0.9411 0.3059
v -1.531470 0.400000 -0.555570 1.0000 0.0000 0.9568
v -1.623880 -0.400000 -0.382683 0.8823 0.9333 0.3255
v -1.623880 0.400000 -0.382683 0.9843 1.0000 0.0196
v -1.680785 -0.400000 -0.195090 0.7451 0.8784 0.4589
v -1.680785 0.400000 -0.195090 0.6980 0.7412 0.6393
v -1.700000 -0.400000 -0.000000 0.2196 0.7686 0.6393
v -1.700000 0.400000 -0.000000 0.2549 1.0000 0.0039
v -1.680785 -0.400000 0.195090 0.0510 0.2039 0.9804
v -1.680785 0.400000 0.195090 0.2510 1.0000 0.0039
v -1.623879 -0.400000 0.382683 0.0549 0.2235 0.9764
v -1.623879 0.400000 0.382683 0.2510 1.0000 0.0039
v -1.531470 -0.400000 0.555570 0.0980 0.4235 0.9019
v -1.531470 0.400000 0.555570 0.2510 1.0000 0.0039
v -1.407107 0.400000 0.707107 0.2549 1.0000 0.0078
v -1.407107 -0.400000 0.707107 0.1059 0.2039 0.9804
vn -0.6525 -0.0000 -0.7578
vn -0.4714 -0.0000 -0.8819
vn -0.2903 -0.0000 -0.9569
vn -0.0980 -0.0000 -0.9952
vn 0.0980 -0.0000 -0.9952
vn 0.2903 -0.0000 -0.9569
vn 0.4714 -0.0000 -0.8819
vn 0.6344 -0.0000 -0.7730
vn 0.7730 -0.0000 -0.6344
vn 0.8819 -0.0000 -0.4714
vn 0.9569 -0.0000 -0.2903
vn 0.9952 -0.0000 -0.0980
vn 0.9952 -0.0000 0.0980
vn 0.9569 -0.0000 0.2903
vn 0.8819 -0.0000 0.4714
vn 0.7730 -0.0000 0.6344
vn -0.0000 1.0000 -0.0000
vn -0.0000 -1.0000 -0.0000
vn 0.7089 -0.0000 0.7053
vn 0.6525 -0.0000 -0.7578
vn -0.6344 -0.0000 -0.7730
vn -0.7730 -0.0000 -0.6344
vn -0.8819 -0.0000 -0.4714
vn -0.9569 -0.0000 -0.2903
vn -0.9952 -0.0000 -0.0980
vn -0.9952 -0.0000 0.0980
vn -0.9569 -0.0000 0.2903
vn -0.8819 -0.0000 0.4714
vn -0.7730 -0.0000 0.6344
vn -0.7089 -0.0000 0.7053
s 0
f 1//1 2//1 33//1
f 3//2 4//2 2//2
f 5//3 6//3 4//3
f 7//4 8//4 6//4
f 9//5 10//5 8//5
f 11//6 12//6 10//6
f 13//7 14//7 12//7
f 15//8 16//8 14//8
f 17//9 18//9 16//9
f 19//10 20//10 18//10
f 21//11 22//11 20//11
f 23//12 24//12 22//12
f 25//13 26//13 24//13
f 27//14 28//14 26//14
f 29//15 30//15 28//15
f 31//16 36//16 30//16
f 1//17 19//17 11//17
f 2//18 18//18 26//18
f 32//19 35//19 36//19
f 36//18 35//18 33//18
f 34//17 32//17 1//17
f 37//20 1//20 33//20
f 39//7 38//7 37//7
f 41//6 40//6 39//6
f 43//5 42//5 41//5
f 45//4 44//4 43//4
f 47//3 46//3 45//3
f 49//2 48//2 47//2
f 51//21 50//21 49//21
f 53//22 52//22 51//22
f 55//23 54//23 53//23
f 57//24 56//24 55//24
f 59//25 58//25 57//25
f 61//26 60//26 59//26
f 63//27 62//27 61//27
f 65//28 64//28 63//28
f 68//29 66//29 65//29
f 40//17 56//17 64//17
f 68//18 51//18 43//18
f 35//30 67//30 68//30
f 68//18 33//18 35//18
f 34//17 1//17 67//17
f 1//1 3//1 2//1
f 3//2 5//2 4//2
f 5//3 7//3 6//3
f 7//4 9//4 8//4
f 9//5 11//5 10//5
f 11//6 13//6 12//6
f 13//7 15//7 14//7
f 15//8 17//8 16//8
f 17//9 19//9 18//9
f 19//10 21//10 20//10
f 21//11 23//11 22//11
f 23//12 25//12 24//12
f 25//13 27//13 26//13
f 27//14 29//14 28//14
f 29//15 31//15 30//15
f 31//16 32//16 36//16
f 5//17 3//17 1//17
f 1//17 32//17 31//17
f 31//17 29//17 27//17
f 27//17 25//17 23//17
f 23//17 21//17 19//17
f 19//17 17//17 15//17
f 15//17 13//17 11//17
f 11//17 9//17 7//17
f 7//17 5//17 1//17
f 1//17 31//17 27//17
f 27//17 23//17 19//17
f 19//17 15//17 11//17
f 11//17 7//17 1//17
f 1//17 27//17 19//17
f 36//18 33//18 2//18
f 2//18 4//18 6//18
f 6//18 8//18 10//18
f 10//18 12//18 14//18
f 14//18 16//18 18//18
f 18//18 20//18 22//18
f 22//18 24//18 26//18
f 26//18 28//18 30//18
f 30//18 36//18 2//18
f 2//18 6//18 10//18
f 10//18 14//18 18//18
f 18//18 22//18 26//18
f 26//18 30//18 2//18
f 2//18 10//18 18//18
f 32//19 34//19 35//19
f 37//20 38//20 1//20
f 39//7 40//7 38//7
f 41//6 42//6 40//6
f 43//5 44//5 42//5
f 45//4 46//4 44//4
f 47//3 48//3 46//3
f 49//2 50//2 48//2
f 51//21 52//21 50//21
f 53//22 54//22 52//22
f 55//23 56//23 54//23
f 57//24 58//24 56//24
f 59//25 60//25 58//25
f 61//26 62//26 60//26
f 63//27 64//27 62//27
f 65//28 66//28 64//28
f 68//29 67//29 66//29
f 1//17 38//17 40//17
f 40//17 42//17 44//17
f 44//17 46//17 48//17
f 48//17 50//17 52//17
f 52//17 54//17 56//17
f 56//17 58//17 60//17
f 60//17 62//17 64//17
f 64//17 66//17 67//17
f 67//17 1//17 40//17
f 40//17 44//17 48//17
f 48//17 52//17 56//17
f 56//17 60//17 64//17
f 64//17 67//17 40//17
f 40//17 48//17 56//17
f 37//18 33//18 68//18
f 68//18 65//18 63//18
f 63//18 61//18 59//18
f 59//18 57//18 55//18
f 55//18 53//18 51//18
f 51//18 49//18 47//18
f 47//18 45//18 43//18
f 43//18 41//18 39//18
f 39//18 37//18 68//18
f 68//18 63//18 59//18
f 59//18 55//18 51//18
f 51//18 47//18 43//18
f 43//18 39//18 68//18
f 68//18 59//18 51//18
f 35//30 34//30 67//30

View File

@ -131,7 +131,7 @@ namespace icosphere {
{ 0.471300f, -0.661700f, 0.583100f }, { 0.471300f, -0.661700f, 0.583100f },
}; };
constexpr face faces[] = { constexpr face_vn faces[] = {
{{ 0, 0}, {13, 0}, {12, 0}}, {{ 0, 0}, {13, 0}, {12, 0}},
{{ 1, 1}, {13, 1}, {15, 1}}, {{ 1, 1}, {13, 1}, {15, 1}},
{{ 0, 2}, {12, 2}, {17, 2}}, {{ 0, 2}, {12, 2}, {17, 2}},
@ -214,6 +214,6 @@ namespace icosphere {
{{13, 79}, { 1, 79}, {14, 79}}, {{13, 79}, { 1, 79}, {14, 79}},
}; };
constexpr uint32_t num_faces = (sizeof (faces)) / (sizeof (face)); constexpr uint32_t num_faces = (sizeof (faces)) / (sizeof (face_vn));
} }

31
geometry/plane2.hpp Normal file
View File

@ -0,0 +1,31 @@
#pragma once
#include "geometry.hpp"
namespace plane {
constexpr position__color vertices[] = {
{ {-10.000000f, 0.000000f, -10.000000f}, { 0.011800f, 1.000000f, 1.000000f} },
{ {10.000000f, 0.000000f, -10.000000f}, { 1.000000f, 0.003900f, 0.066700f} },
{ {-10.000000f, 0.000000f, 10.000000f}, { 0.019600f, 1.000000f, 0.019600f} },
{ {10.000000f, 0.000000f, 10.000000f}, { 1.000000f, 0.952900f, 0.011800f} },
};
constexpr vec2 texture[] = {
{ 1.000000f, 0.000000f },
{ 0.000000f, 1.000000f },
{ 0.000000f, 0.000000f },
{ 1.000000f, 1.000000f },
};
constexpr vec3 normals[] = {
{ -0.000000f, -1.000000f, -0.000000f },
};
constexpr face_vtn faces[] = {
{{1, 0, 0}, {2, 1, 0}, {0, 2, 0}},
{{1, 0, 0}, {3, 3, 0}, {2, 1, 0}},
};
constexpr uint32_t num_faces = (sizeof (faces)) / (sizeof (face_vtn));
}

15
geometry/plane2.obj Normal file
View File

@ -0,0 +1,15 @@
# Blender 3.3.6
# www.blender.org
o Plane
v -10.000000 0.000000 -10.000000 0.0118 1.0000 1.0000
v 10.000000 0.000000 -10.000000 1.0000 0.0039 0.0667
v -10.000000 0.000000 10.000000 0.0196 1.0000 0.0196
v 10.000000 0.000000 10.000000 1.0000 0.9529 0.0118
vn -0.0000 -1.0000 -0.0000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 0.000000 1.000000
vt 1.000000 1.000000
s 0
f 2/2/1 3/3/1 1/1/1
f 2/2/1 4/4/1 3/3/1

View File

@ -1457,7 +1457,7 @@ namespace suzanne {
{ 0.360400f, 0.828300f, 0.429000f }, { 0.360400f, 0.828300f, 0.429000f },
}; };
constexpr face faces[] = { constexpr face_vn faces[] = {
{{ 46, 0}, { 2, 0}, { 44, 0}}, {{ 46, 0}, { 2, 0}, { 44, 0}},
{{ 3, 1}, { 47, 1}, { 45, 1}}, {{ 3, 1}, { 47, 1}, { 45, 1}},
{{ 44, 2}, { 4, 2}, { 42, 2}}, {{ 44, 2}, { 4, 2}, { 42, 2}},
@ -2427,6 +2427,6 @@ namespace suzanne {
{{504, 940}, {322, 940}, {320, 940}}, {{504, 940}, {322, 940}, {320, 940}},
}; };
constexpr uint32_t num_faces = (sizeof (faces)) / (sizeof (face)); constexpr uint32_t num_faces = (sizeof (faces)) / (sizeof (face_vn));
} }

2992
geometry/suzanne2.hpp Normal file

File diff suppressed because it is too large Load Diff

2976
geometry/suzanne2.obj Normal file

File diff suppressed because it is too large Load Diff

28
geometry/triangle.hpp Normal file
View File

@ -0,0 +1,28 @@
#pragma once
#include "geometry.hpp"
namespace triangle {
constexpr vec3 vertices[] = {
{ -1.000000f, 0.000000f, 0.000000f },
{ 1.000000f, 0.000000f, 1.000000f },
{ 1.000000f, 0.000000f, -1.000000f },
};
constexpr vec2 texture[] = {
{ 0.000000f, 0.000000f },
{ 1.000000f, 0.000000f },
{ 1.000000f, 1.000000f },
};
constexpr vec3 normals[] = {
{ -0.000000f, 1.000000f, -0.000000f },
};
constexpr face_vtn faces[] = {
{{0, 0, 0}, {1, 1, 0}, {2, 2, 0}},
};
constexpr uint32_t num_faces = (sizeof (faces)) / (sizeof (face_vtn));
}

12
geometry/triangle.obj Normal file
View File

@ -0,0 +1,12 @@
# Blender 3.3.6
# www.blender.org
o Triangle
v -1.000000 0.000000 0.000000
v 1.000000 0.000000 1.000000
v 1.000000 0.000000 -1.000000
vn -0.0000 1.0000 -0.0000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
s 0
f 1/1/1 2/2/1 3/3/1

View File

@ -335,7 +335,7 @@ namespace wiffle {
{ 0.500000f, -0.500000f, -0.707100f }, { 0.500000f, -0.500000f, -0.707100f },
}; };
constexpr face faces[] = { constexpr face_vn faces[] = {
{{ 0, 0}, { 1, 0}, { 2, 0}}, {{ 0, 0}, { 1, 0}, { 2, 0}},
{{ 1, 0}, { 3, 0}, { 2, 0}}, {{ 1, 0}, { 3, 0}, { 2, 0}},
{{ 0, 0}, { 4, 0}, { 1, 0}}, {{ 0, 0}, { 4, 0}, { 1, 0}},
@ -914,6 +914,6 @@ namespace wiffle {
{{250, 24}, {153, 24}, {151, 24}}, {{250, 24}, {153, 24}, {151, 24}},
}; };
constexpr uint32_t num_faces = (sizeof (faces)) / (sizeof (face)); constexpr uint32_t num_faces = (sizeof (faces)) / (sizeof (face_vn));
} }

View File

@ -1,13 +1,12 @@
#include "../float_uint32.hpp" #include "float_uint32.hpp"
#include "core_bits.hpp" #include "memorymap.hpp"
#include "../holly.hpp" #include "systembus.hpp"
#include "../memorymap.hpp" #include "systembus_bits.hpp"
#include "../systembus.hpp"
#include "../systembus_bits.hpp"
#include "texture_memory_alloc.hpp" #include "texture_memory_alloc.hpp"
#include "holly.hpp"
#include "core.hpp" #include "core.hpp"
#include "core_bits.hpp"
#include "background.hpp" #include "background.hpp"
#include "region_array.hpp" #include "region_array.hpp"

View File

@ -1,3 +1,5 @@
#pragma once
#include <cstdint> #include <cstdint>
#include "../float_uint32.hpp" #include "../float_uint32.hpp"
@ -139,7 +141,7 @@ namespace fpu_shad_scale {
} }
namespace fpu_cull_val { namespace fpu_cull_val {
constexpr uint32_t culling_comparison_value(float num) { return _i(__builtin_fabsf(num));; } inline uint32_t culling_comparison_value(float num) { return _i(__builtin_fabsf(num));; }
} }
namespace fpu_param_cfg { namespace fpu_param_cfg {
@ -180,11 +182,11 @@ namespace half_offset {
} }
namespace fpu_perp_val { namespace fpu_perp_val {
constexpr uint32_t perpendicular_triangle_compare(float num) { return _i(__builtin_fabsf(num));; } inline uint32_t perpendicular_triangle_compare(float num) { return _i(__builtin_fabsf(num));; }
} }
namespace isp_backgnd_d { namespace isp_backgnd_d {
constexpr uint32_t background_plane_depth(float num) { return _i(num) & 0xfffffff0; } inline uint32_t background_plane_depth(float num) { return _i(num) & 0xfffffff0; }
} }
namespace isp_backgnd_t { namespace isp_backgnd_t {

View File

@ -1,3 +1,5 @@
#pragma once
#include <cstdint> #include <cstdint>
#include "../float_uint32.hpp" #include "../float_uint32.hpp"
@ -35,6 +37,8 @@ namespace ta_alloc_ctrl {
namespace opb_mode { namespace opb_mode {
constexpr uint32_t increasing_addresses = 0 << 20; constexpr uint32_t increasing_addresses = 0 << 20;
constexpr uint32_t decreasing_addresses = 1 << 20; constexpr uint32_t decreasing_addresses = 1 << 20;
constexpr uint32_t bit_mask = 0x1 << 20;
} }
namespace pt_opb { namespace pt_opb {
@ -42,6 +46,8 @@ namespace ta_alloc_ctrl {
constexpr uint32_t _8x4byte = 1 << 16; constexpr uint32_t _8x4byte = 1 << 16;
constexpr uint32_t _16x4byte = 2 << 16; constexpr uint32_t _16x4byte = 2 << 16;
constexpr uint32_t _32x4byte = 3 << 16; constexpr uint32_t _32x4byte = 3 << 16;
constexpr uint32_t bit_mask = 0x3 << 16;
} }
namespace tm_opb { namespace tm_opb {
@ -49,6 +55,8 @@ namespace ta_alloc_ctrl {
constexpr uint32_t _8x4byte = 1 << 12; constexpr uint32_t _8x4byte = 1 << 12;
constexpr uint32_t _16x4byte = 2 << 12; constexpr uint32_t _16x4byte = 2 << 12;
constexpr uint32_t _32x4byte = 3 << 12; constexpr uint32_t _32x4byte = 3 << 12;
constexpr uint32_t bit_mask = 0x3 << 12;
} }
namespace t_opb { namespace t_opb {
@ -56,6 +64,8 @@ namespace ta_alloc_ctrl {
constexpr uint32_t _8x4byte = 1 << 8; constexpr uint32_t _8x4byte = 1 << 8;
constexpr uint32_t _16x4byte = 2 << 8; constexpr uint32_t _16x4byte = 2 << 8;
constexpr uint32_t _32x4byte = 3 << 8; constexpr uint32_t _32x4byte = 3 << 8;
constexpr uint32_t bit_mask = 0x3 << 8;
} }
namespace om_opb { namespace om_opb {
@ -63,6 +73,8 @@ namespace ta_alloc_ctrl {
constexpr uint32_t _8x4byte = 1 << 4; constexpr uint32_t _8x4byte = 1 << 4;
constexpr uint32_t _16x4byte = 2 << 4; constexpr uint32_t _16x4byte = 2 << 4;
constexpr uint32_t _32x4byte = 3 << 4; constexpr uint32_t _32x4byte = 3 << 4;
constexpr uint32_t bit_mask = 0x3 << 4;
} }
namespace o_opb { namespace o_opb {
@ -70,6 +82,8 @@ namespace ta_alloc_ctrl {
constexpr uint32_t _8x4byte = 1 << 0; constexpr uint32_t _8x4byte = 1 << 0;
constexpr uint32_t _16x4byte = 2 << 0; constexpr uint32_t _16x4byte = 2 << 0;
constexpr uint32_t _32x4byte = 3 << 0; constexpr uint32_t _32x4byte = 3 << 0;
constexpr uint32_t bit_mask = 0x3 << 0;
} }
} }
@ -85,11 +99,15 @@ namespace ta_yuv_tex_ctrl {
namespace yuv_form { namespace yuv_form {
constexpr uint32_t yuv420 = 0 << 24; constexpr uint32_t yuv420 = 0 << 24;
constexpr uint32_t yuv422 = 1 << 24; constexpr uint32_t yuv422 = 1 << 24;
constexpr uint32_t bit_mask = 0x1 << 24;
} }
namespace yuv_tex { namespace yuv_tex {
constexpr uint32_t one_texture = 0 << 16; constexpr uint32_t one_texture = 0 << 16;
constexpr uint32_t multiple_textures = 1 << 16; constexpr uint32_t multiple_textures = 1 << 16;
constexpr uint32_t bit_mask = 0x1 << 16;
} }
constexpr uint32_t yuv_v_size(uint32_t num) { return (num & 0x3f) << 8; } constexpr uint32_t yuv_v_size(uint32_t num) { return (num & 0x3f) << 8; }

View File

@ -1,13 +1,13 @@
#include <cstdint> #include <cstdint>
#include "systembus.hpp"
#include "systembus_bits.hpp"
#include "sh7091/sh7091.hpp"
#include "sh7091/sh7091_bits.hpp"
#include "core_bits.hpp" #include "core_bits.hpp"
#include "ta_bits.hpp" #include "ta_bits.hpp"
#include "../holly.hpp" #include "holly.hpp"
#include "../systembus.hpp"
#include "../systembus_bits.hpp"
#include "../sh7091.hpp"
#include "../sh7091_bits.hpp"
#include "texture_memory_alloc.hpp" #include "texture_memory_alloc.hpp"
#include "ta_fifo_polygon_converter.hpp" #include "ta_fifo_polygon_converter.hpp"
@ -79,21 +79,23 @@ void ta_polygon_converter_transfer(volatile uint32_t * buf, uint32_t size)
volatile uint32_t _dummy = sh7091.DMAC.CHCR2; volatile uint32_t _dummy = sh7091.DMAC.CHCR2;
(void)_dummy; (void)_dummy;
using namespace dmac;
/* start a new CH2-DMA transfer from "system memory" to "TA FIFO polygon converter" */ /* start a new CH2-DMA transfer from "system memory" to "TA FIFO polygon converter" */
sh7091.DMAC.CHCR2 = 0; /* disable DMA channel */ sh7091.DMAC.CHCR2 = 0; /* disable DMA channel */
sh7091.DMAC.SAR2 = reinterpret_cast<uint32_t>(&buf[0]); /* start address, must be aligned to a CHCHR__TS-sized (32-byte) boundary */ sh7091.DMAC.SAR2 = reinterpret_cast<uint32_t>(&buf[0]); /* start address, must be aligned to a CHCHR__TS-sized (32-byte) boundary */
sh7091.DMAC.DMATCR2 = DMATCR2__TRANSFER_COUNT(size / 32); /* transfer count, in CHCHR__TS-sized (32-byte) units */ sh7091.DMAC.DMATCR2 = dmatcr::transfer_count(size / 32); /* transfer count, in CHCHR__TS-sized (32-byte) units */
sh7091.DMAC.CHCR2 = CHCR2__DM__DESTINATION_ADDRESS_FIXED sh7091.DMAC.CHCR2 = chcr::dm::destination_address_fixed
| CHCR2__SM__SOURCE_ADDRESS_INCREMENTED | chcr::sm::source_address_incremented
| CHCR2__RS(0b0010) /* external request, single address mode; | chcr::rs::resource_select(0b0010) /* external request, single address mode;
external address space external device */ external address space external device */
| CHCR2__TM__BURST_MODE /* transmit mode */ | chcr::tm::cycle_burst_mode /* transmit mode */
| CHCR2__TS__32_BYTE /* transfer size */ | chcr::ts::_32_byte /* transfer size */
| CHCR2__DE; /* DMAC (channel) enable */ | chcr::de::channel_operation_enabled;
sh7091.DMAC.DMAOR = DMAOR__DDT /* on-demand data transfer mode */ sh7091.DMAC.DMAOR = dmaor::ddt::on_demand_data_transfer_mode /* on-demand data transfer mode */
| DMAOR__PR__CH2_CH0_CH1_CH3 /* priority mode; CH2 > CH0 > CH1 > CH3 */ | dmaor::pr::ch2_ch0_ch1_ch3 /* priority mode; CH2 > CH0 > CH1 > CH3 */
| DMAOR__DME; /* DMAC master enable */ | dmaor::dme::operation_enabled_on_all_channels; /* DMAC master enable */
system.C2DSTAT = C2DSTAT__ADDRESS(0x10000000); /* CH2-DMA destination address */ system.C2DSTAT = C2DSTAT__ADDRESS(0x10000000); /* CH2-DMA destination address */
system.C2DLEN = CD2LEN__LENGTH(size); /* CH2-DMA length (must be a multiple of 32) */ system.C2DLEN = CD2LEN__LENGTH(size); /* CH2-DMA length (must be a multiple of 32) */
system.C2DST = 1; /* CH2-DMA start (an 'external' request from SH7091's perspective) */ system.C2DST = 1; /* CH2-DMA start (an 'external' request from SH7091's perspective) */

View File

@ -3,8 +3,8 @@
#include "align.hpp" #include "align.hpp"
#include "sh7091.hpp" #include "sh7091/sh7091.hpp"
#include "sh7091_bits.hpp" #include "sh7091/sh7091_bits.hpp"
#include "systembus.hpp" #include "systembus.hpp"
#include "systembus_bits.hpp" #include "systembus_bits.hpp"
@ -97,9 +97,11 @@ void init_block_write(uint32_t * command_buf, uint32_t * receive_buf,
void dma_start(uint32_t * command_buf) void dma_start(uint32_t * command_buf)
{ {
sh7091.DMAC.DMAOR = DMAOR__DDT // on-demand data transfer mode using namespace dmac;
| DMAOR__PR__CH2_CH0_CH1_CH3 // priority mode; CH2 > CH0 > CH1 > CH3
| DMAOR__DME; // DMAC master enable sh7091.DMAC.DMAOR = dmaor::ddt::on_demand_data_transfer_mode /* on-demand data transfer mode */
| dmaor::pr::ch2_ch0_ch1_ch3 /* priority mode; CH2 > CH0 > CH1 > CH3 */
| dmaor::dme::operation_enabled_on_all_channels; /* DMAC master enable */
// clear maple-DMA end status // clear maple-DMA end status
system.ISTNRM = ISTNRM__END_OF_DMA_MAPLE_DMA; system.ISTNRM = ISTNRM__END_OF_DMA_MAPLE_DMA;

View File

@ -43,4 +43,34 @@ void init_host_command_all_ports(uint32_t * command_buf, uint32_t * receive_buf,
host_command[3].bus_data.data_fields = data_fields; host_command[3].bus_data.data_fields = data_fields;
} }
template <typename C, typename R>
void init_host_command_all_ports(uint32_t * command_buf, uint32_t * receive_buf)
{
using command_type = maple::host_command<typename C::data_fields>;
using response_type = maple::command_response<typename R::data_fields>;
auto host_command = reinterpret_cast<command_type *>(command_buf);
auto response_command = reinterpret_cast<response_type *>(receive_buf);
init_host_command((uint32_t*)&host_command[0], (uint32_t*)&response_command[0],
host_instruction::port_select::a, // destination_port
ap::de::device | ap::port_select::a, C::command_code, (sizeof (typename C::data_fields)),
false); // end_flag
init_host_command((uint32_t*)&host_command[1], (uint32_t*)&response_command[1],
host_instruction::port_select::b, // destination_port
ap::de::device | ap::port_select::b, C::command_code, (sizeof (typename C::data_fields)),
false); // end_flag
init_host_command((uint32_t*)&host_command[2], (uint32_t*)&response_command[2],
host_instruction::port_select::c, // destination_port
ap::de::device | ap::port_select::c, C::command_code, (sizeof (typename C::data_fields)),
false); // end_flag
init_host_command((uint32_t*)&host_command[3], (uint32_t*)&response_command[3],
host_instruction::port_select::d, // destination_port
ap::de::device | ap::port_select::d, C::command_code, (sizeof (typename C::data_fields)),
true); // end_flag
}
} }

119
math/geometry.hpp Normal file
View File

@ -0,0 +1,119 @@
#include <functional>
#include "vec.hpp"
namespace geometry {
template <int L, typename T>
vec<L, T> line_plane_intersection(const vec<L, T>& plane_point, // p0
const vec<L, T>& plane_normal, // n
const vec<L, T>& line_start, // l0
const vec<L, T>& line_end
)
{
const auto line_vector = line_end - line_start; // l
const T intersection = // d
dot(plane_point - line_start, plane_normal)
/ dot(line_vector, plane_normal);
return line_start + line_vector * intersection;
}
template <int L, typename T>
T clip_boundary(const vec<L, T>& plane_point, // X
const vec<L, T>& plane_normal, // Nc
const vec<L, T>& line_point
)
{
return dot(plane_normal, line_point - plane_point);
}
template <typename T>
inline T positive_modulo(T a, T b)
{
return (a % b + b) % b;
}
template <int polygon_len, int L, typename T>
inline int clip_polygon1(vec<L, T> * output,
const vec<L, T> plane_point,
const vec<L, T> plane_normal,
const vec<L, T> * polygon,
const int ix_s,
const int ix_f,
const bool last_inside)
{
const vec<L, T>& s = polygon[ix_s];
const vec<L, T>& f = polygon[ix_f];
bool this_inside = 0.f < clip_boundary<L, T>(plane_point,
plane_normal,
f);
int length = 0;
switch ((last_inside << 1) | (this_inside << 0)) {
case 0b00: // no output
length = 0;
break;
case 0b01: // I, F
length = 2;
{
auto i = line_plane_intersection<L, T>(plane_point, plane_normal, s, f);
*output++ = i;
*output++ = f;
}
break;
case 0b10: // I
length = 1;
{
auto i = line_plane_intersection<L, T>(plane_point, plane_normal, s, f);
*output++ = i;
}
break;
case 0b11: // F
length = 1;
*output++ = f;
break;
}
bool end_of_polygon = ix_f == (polygon_len - 1);
if (!end_of_polygon) {
return length +
clip_polygon1<polygon_len, L, T>(output,
plane_point,
plane_normal,
polygon,
ix_f,
ix_f + 1,
this_inside);
} else {
return length;
}
}
template <int polygon_len, int L, typename T>
int clip_polygon(vec<L, T> * output,
const vec<L, T>& plane_point,
const vec<L, T>& plane_normal,
const vec<L, T> * polygon
)
{
const vec<L, T> f = polygon[polygon_len - 1];
// It would be nice to remove the extra dot product, but the
// alternative seems likely uglier.
bool this_inside = 0.f < clip_boundary<L, T>(plane_point,
plane_normal,
f);
return clip_polygon1<polygon_len, L, T>(output,
plane_point,
plane_normal,
polygon,
polygon_len - 1, // ix_s
0, // ix_f
this_inside);
}
}

View File

@ -26,3 +26,5 @@ constexpr float sin(const float n) noexcept
{ {
return __builtin_sinf(n); return __builtin_sinf(n);
} }
constexpr float pi = 3.141592653589793;

View File

@ -107,6 +107,12 @@ inline constexpr vec<2, T> operator*(vec<2, T> const& v1, T const& scalar)
return v1 * vec<2, T>(scalar); return v1 * vec<2, T>(scalar);
} }
template <typename T>
inline constexpr vec<2, T> operator*(T const& scalar, vec<2, T> const& v1)
{
return vec<2, T>(scalar) * v1;
}
template <typename T> template <typename T>
inline constexpr vec<2, T> operator/(vec<2, T> const& v1, vec<2, T> const& v2) inline constexpr vec<2, T> operator/(vec<2, T> const& v1, vec<2, T> const& v2)
{ {

View File

@ -112,6 +112,12 @@ inline constexpr vec<3, T> operator*(vec<3, T> const& v1, T const& scalar)
return v1 * vec<3, T>(scalar); return v1 * vec<3, T>(scalar);
} }
template <typename T>
inline constexpr vec<3, T> operator*(T const& scalar, vec<3, T> const& v1)
{
return vec<3, T>(scalar) * v1;
}
template <typename T> template <typename T>
inline constexpr vec<3, T> operator/(vec<3, T> const& v1, vec<3, T> const& v2) inline constexpr vec<3, T> operator/(vec<3, T> const& v1, vec<3, T> const& v2)
{ {
@ -133,6 +139,14 @@ inline constexpr T dot(vec<3, T> const& v1, vec<3, T> const& v2)
return tmp.x + tmp.y + tmp.z; return tmp.x + tmp.y + tmp.z;
} }
template <typename T>
inline constexpr vec<3, T> cross(vec<3, T> const& v1, vec<3, T> const& v2)
{
return vec<3, T>(v1.y * v2.z - v2.y * v1.z,
v1.z * v2.x - v2.z * v1.x,
v1.x * v2.y - v2.x * v1.y);
}
template <typename T> template <typename T>
inline constexpr vec<3, T> functor1(T (&func) (T const& x), vec<3, T> const& v) inline constexpr vec<3, T> functor1(T (&func) (T const& x), vec<3, T> const& v)
{ {

View File

@ -18,6 +18,7 @@ struct vec<4, T>
inline constexpr vec(); inline constexpr vec();
inline constexpr vec(T scalar); inline constexpr vec(T scalar);
inline constexpr vec(T _x, T _y, T _z, T _w); inline constexpr vec(T _x, T _y, T _z, T _w);
inline constexpr vec(const vec<3, T>& v);
constexpr inline vec<4, T> operator-() const; constexpr inline vec<4, T> operator-() const;
inline constexpr T const& operator[](int i) const; inline constexpr T const& operator[](int i) const;
@ -41,6 +42,11 @@ inline constexpr vec<4, T>::vec(T _x, T _y, T _z, T _w)
: x(_x), y(_y), z(_z), w(_w) : x(_x), y(_y), z(_z), w(_w)
{} {}
template <typename T>
inline constexpr vec<4, T>::vec(const vec<3, T>& v)
: x(v.x), y(v.y), z(v.z), w(1.f)
{}
template <typename T> template <typename T>
constexpr inline vec<4, T> vec<4, T>::operator-() const constexpr inline vec<4, T> vec<4, T>::operator-() const
{ {
@ -117,6 +123,12 @@ inline constexpr vec<4, T> operator*(vec<4, T> const& v1, T const& scalar)
return v1 * vec<4, T>(scalar); return v1 * vec<4, T>(scalar);
} }
template <typename T>
inline constexpr vec<4, T> operator*(T const& scalar, vec<4, T> const& v1)
{
return vec<4, T>(scalar) * v1;
}
template <typename T> template <typename T>
inline constexpr vec<4, T> operator/(vec<4, T> const& v1, vec<4, T> const& v2) inline constexpr vec<4, T> operator/(vec<4, T> const& v1, vec<4, T> const& v2)
{ {

View File

@ -18,11 +18,19 @@ def parse_bit_number(s):
assert '-' not in s assert '-' not in s
return int(s, 10) return int(s, 10)
def parse_bit_set(s, split_char):
assert len(list(c for c in s if c == split_char)) == 1
left, right = map(parse_bit_number, s.split(split_char, maxsplit=1))
assert left > right, (left, right)
return left, right
def parse_bit_range(s): def parse_bit_range(s):
if '-' in s: if '-' in s:
left, right = map(parse_bit_number, s.split('-', maxsplit=1)) left, right = parse_bit_set(s, '-')
assert left > right, (left, right)
return set(range(right, left+1)) return set(range(right, left+1))
elif ',' in s:
left, right = parse_bit_set(s, ',')
return set([right, left])
else: else:
num = parse_bit_number(s) num = parse_bit_number(s)
return set([num]) return set([num])
@ -41,7 +49,7 @@ def aggregate_enums(aggregated_rows):
for row in aggregated_rows: for row in aggregated_rows:
bits = parse_bit_range(row["bits"]) bits = parse_bit_range(row["bits"])
assert row["bit_name"] != "" assert row["bit_name"] != "", row
if row["enum_name"] == "": if row["enum_name"] == "":
assert_unique_ordered(bits) assert_unique_ordered(bits)
non_enum.append(row) non_enum.append(row)
@ -50,7 +58,7 @@ def aggregate_enums(aggregated_rows):
assert_unique_ordered(bits) assert_unique_ordered(bits)
non_enum.append(row["enum_name"]) non_enum.append(row["enum_name"])
else: else:
assert enum_bits[row["enum_name"]] == bits assert enum_bits[row["enum_name"]] == bits, row
enum_bits[row["enum_name"]] = bits enum_bits[row["enum_name"]] = bits
enum_aggregated[row["enum_name"]].append(row) enum_aggregated[row["enum_name"]].append(row)
@ -64,6 +72,7 @@ class enum:
@dataclass @dataclass
class register: class register:
block: Union[None, str]
name: str name: str
defs: list[Union[dict, enum]] defs: list[Union[dict, enum]]
@ -79,9 +88,17 @@ def aggregate_all_enums(aggregated):
return row_or_string return row_or_string
else: else:
assert False, (row_or_string, type(row_or_string)) assert False, (row_or_string, type(row_or_string))
defs = [resolve(aggregate) for aggregate in non_enum]
if 'block' in rows[0]:
blocks = set(row['block'] for row in rows)
assert len(blocks) == 1, blocks
block_name = next(iter(blocks))
out.append( out.append(
register(register_name, register(block_name, register_name, defs))
[resolve(aggregate) for aggregate in non_enum])) else:
out.append(
register(None, register_name, defs))
return out return out
''' '''
@ -107,19 +124,26 @@ def aggregate_all_enums(aggregated):
''' '''
def mask_from_bits(bits): def mask_from_bits(bits):
mask = 2 ** len(bits) - 1 h, l = max(bits), min(bits)
mask = 2 ** ((h - l) + 1) - 1
return mask return mask
def parse_value(value): def parse_value(value):
return eval(value) return eval(value)
def escape(bit_name):
if bit_name[0] in {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}:
return '_' + bit_name
else:
return bit_name
def render_read_only(bit_def): def render_read_only(bit_def):
assert bit_def["value"] == "" assert bit_def["value"] == ""
assert bit_def["mask"] == "" assert bit_def["mask"] == ""
bits = parse_bit_range(bit_def["bits"]) bits = parse_bit_range(bit_def["bits"])
mask_value = mask_from_bits(bits) mask_value = mask_from_bits(bits)
yield ( yield (
f"constexpr uint32_t {bit_def['bit_name']}(uint32_t reg) {{ " f"constexpr uint32_t {escape(bit_def['bit_name'])}(uint32_t reg) {{ "
f"return (reg >> {min(bits)}) & {hex(mask_value)};" f"return (reg >> {min(bits)}) & {hex(mask_value)};"
" }" " }"
) )
@ -145,7 +169,7 @@ def render_mask(bit_def):
bits = parse_bit_range(bit_def["bits"]) bits = parse_bit_range(bit_def["bits"])
if mask.startswith("float_"): if mask.startswith("float_"):
yield ( yield (
f"constexpr uint32_t {bit_def['bit_name']}(float num) {{ " f"inline uint32_t {escape(bit_def['bit_name'])}(float num) {{ "
f"return {render_float_mask(mask)};" f"return {render_float_mask(mask)};"
" }" " }"
) )
@ -155,7 +179,7 @@ def render_mask(bit_def):
assert mask_value & mask_from_bits(bits) == mask_value, (mask_value, mask_from_bits(bits)) assert mask_value & mask_from_bits(bits) == mask_value, (mask_value, mask_from_bits(bits))
yield ( yield (
f"constexpr uint32_t {bit_def['bit_name']}(uint32_t num) {{ " f"constexpr uint32_t {escape(bit_def['bit_name'])}(uint32_t num) {{ "
f"return (num & {hex(mask_value)}) << {min(bits)};" f"return (num & {hex(mask_value)}) << {min(bits)};"
" }" " }"
) )
@ -163,9 +187,9 @@ def render_mask(bit_def):
def render_value(bit_def): def render_value(bit_def):
assert bit_def["mask"] == "" assert bit_def["mask"] == ""
bits = parse_bit_range(bit_def["bits"]) bits = parse_bit_range(bit_def["bits"])
assert parse_value(bit_def["value"]) <= mask_from_bits(bits), bit_def["value"] assert parse_value(bit_def["value"]) <= mask_from_bits(bits), (bit_def["value"], mask_from_bits(bits), bits)
bit_ix = min(bits) bit_ix = min(bits)
yield f"constexpr uint32_t {bit_def['bit_name']} = {bit_def['value']} << {bit_ix};" yield f"constexpr uint32_t {escape(bit_def['bit_name'])} = {bit_def['value']} << {bit_ix};"
def render_defs(bit_def): def render_defs(bit_def):
if bit_def["value"] != "": if bit_def["value"] != "":
@ -212,9 +236,23 @@ def render_register(register):
yield "" yield ""
def render_registers(registers): def render_registers(registers):
last_block = None
for register in registers: for register in registers:
if register.block != last_block:
assert register.block is not None
if last_block is not None:
yield '}' # end of previous namespace
yield ""
yield f'namespace {register.block.lower()} {{'
if register.block is None:
assert last_block is None
last_block = register.block
yield from render_register(register) yield from render_register(register)
if last_block is not None:
yield '}' # end of block namespace
def header(): def header():
yield "#pragma once" yield "#pragma once"
yield "" yield ""

View File

@ -45,13 +45,12 @@ def new_writer():
def terminate(): def terminate():
nonlocal last_block nonlocal last_block
nonlocal first_address
nonlocal stack nonlocal stack
if last_block is not None: if last_block is not None:
yield "};" yield "};"
for address, name in stack: for address, name in stack:
yield f"static_assert((offsetof (struct {last_block.lower()}_reg, {name})) == {hex(address)});" yield f"static_assert((offsetof (struct {last_block.lower()}_reg, {name})) == {hex(address - first_address)});"
yield "" yield ""
stack = [] stack = []
@ -68,15 +67,16 @@ def new_writer():
_address = int(row["address"], 16) _address = int(row["address"], 16)
assert _offset <= 0xff assert _offset <= 0xff
assert _address <= 0xffff assert _address <= 0xffff
address = (_offset << 16) | (_address << 0) offset_address = (_offset << 16)
address = offset_address | (_address << 0)
size = int(row["size"], 10) size = int(row["size"], 10)
name = row["name"] name = row["name"]
description = row["description"] description = row["description"]
if block != last_block: if block != last_block:
yield from terminate() yield from terminate()
first_address = 0 # hmm... first_address = offset_address
last_address = 0 last_address = offset_address
size_total = 0 size_total = 0
reserved_num = 0 reserved_num = 0
yield f"struct {block.lower()}_reg {{" yield f"struct {block.lower()}_reg {{"

Binary file not shown.

293
regs/sh7091_bits.csv Normal file
View File

@ -0,0 +1,293 @@
"block","register_name","enum_name","bits","bit_name","value","mask","description"
"CCN","PTEH",,"31-10","VPN",,,"Virtual Page Number"
"CCN","PTEH",,"7-0","ASID",,,"Address space identifier"
,,,,,,,
"CCN","PTEL",,"28-10","PPN",,,"Physical page number"
"CCN","PTEL","V","8","invalid","0",,"Validity"
"CCN","PTEL","V","8","valid","1",,"Validity"
"CCN","PTEL","SZ","7,4","1_kbyte_page","0b0000",,"Page size"
"CCN","PTEL","SZ","7,4","4_kbyte_page","0b0001",,"Page size"
"CCN","PTEL","SZ","7,4","64_kbyte_page","0b1000",,"Page size"
"CCN","PTEL","SZ","7,4","1_mbyte_page","0b1001",,"Page size"
"CCN","PTEL","PR","6-5","read_only_in_privileged_mode","0b00",,"Protection key data"
"CCN","PTEL","PR","6-5","read_write_in_privileged_mode","0b01",,"Protection key data"
"CCN","PTEL","PR","6-5","read_only_in_privileged_and_user_mode","0b10",,"Protection key data"
"CCN","PTEL","PR","6-5","read_write_in_privileged_and_user_mode","0b11",,"Protection key data"
"CCN","PTEL","C","3","not_cacheable","0",,"Cacheability bit"
"CCN","PTEL","C","3","cacheable","1",,"Cacheability bit"
"CCN","PTEL","D","2","write_has_not_been_performed","0",,"Dirty bit"
"CCN","PTEL","D","2","write_has_been_performed","1",,"Dirty bit"
"CCN","PTEL","SH","1","pages_are_shared_by_processes","0",,"Share status bit"
"CCN","PTEL","SH","1","pages_are_not_shared_by_processes","1",,"Share status bit"
"CCN","PTEL","WT","0","copy_back_mode","0",,"Write-through bit"
"CCN","PTEL","WT","0","write_through_mode","1",,"Write-through bit"
,,,,,,,
"CCN","MMUCR",,"31-26","LRUI",,,"Least recently used ITLB"
"CCN","MMUCR",,"23-18","URB",,,"UTLB replace boundary"
"CCN","MMUCR",,"15-10","URC",,,"UTLB replace counter"
"CCN","MMUCR","SQMD","9","user_privileged_access_possible","0",,"Store queue mode bit"
"CCN","MMUCR","SQMD","9","privileged_access_possible","1",,"Store queue mode bit"
"CCN","MMUCR","SV","8","multiple_virtual_memory_mode","0",,"Single virtual mode bit"
"CCN","MMUCR","SV","8","single_virtual_memory_mode","1",,"Single virtual mode bit"
"CCN","MMUCR","TI","2","invalidate_all_utlb_itlb_bits","1",,"TLB invalidate"
"CCN","MMUCR","AT","0","mmu_disabled","0",,"Address translation bit"
"CCN","MMUCR","AT","0","mmu_enabled","1",,"Address translation bit"
,,,,,,,
"CCN","BASRA",,"7-0","basa",,"0xff",
,,,,,,,
"CCN","BASRB",,"7-0","basa",,"0xff",
,,,,,,,
"CCN","CCR","IIX","15","address_bits_12_5_used_for_ic_entry_selection","0",,"IC index enable"
"CCN","CCR","IIX","15","address_bits_25_and_11_5_used_for_ic_entry_selection","1",,"IC index enable"
"CCN","CCR","ICI","11","clear_v_bits_of_all_ic_entries","1",,"IC invalidation"
"CCN","CCR","ICE","8","ic_not_used","0",,"IC enable"
"CCN","CCR","ICE","8","ic_used","1",,"IC enable"
"CCN","CCR","OIX","7","address_bits_13_5_used_for_oc_entry_selection","0",,"OC index enable"
"CCN","CCR","OIX","7","address_bits_25_and_12_5_used_for_oc_entry_selection","1",,"OC index enable"
"CCN","CCR","ORA","5","16_kbytes_used_as_cache","0",,"OC RAM enable"
"CCN","CCR","ORA","5","8_kbytes_used_as_cache_8_kbytes_used_as_ram","1",,"OC RAM enable"
"CCN","CCR","OCI","3","clear_v_and_u_bits_of_all_oc_entries","1",,"OC invalidation"
"CCN","CCR","CB","2","write_through_mode","0",,"Copy-back enable"
"CCN","CCR","CB","2","copy_back_mode","1",,"Copy-back enable"
"CCN","CCR","WT","1","copy_back_mode","0",,"Write-through enable"
"CCN","CCR","WT","1","write_through_mode","1",,"Write-through enable"
"CCN","CCR","OCE","0","oc_not_used","0",,"OC enable"
"CCN","CCR","OCE","0","oc_used","1",,"OC enable"
,,,,,,,
"CCN","TRA",,"9-2","imm",,,
,,,,,,,
"CCN","EXPEVT",,"11-0","exception_code",,,
,,,,,,,
"CCN","INTEVT",,"11-0","exception_code",,,
,,,,,,,
"CCN","PTEA","TC","3","area_5_is_used","0",,"Timing control bit"
"CCN","PTEA","TC","3","area_6_is_used","1",,"Timing control bit"
"CCN","PTEA","SA","2-0","undefined","0b000",,"Space attribute bits"
"CCN","PTEA","SA","2-0","variable_size_io_space","0b001",,"Space attribute bits"
"CCN","PTEA","SA","2-0","8_bit_io_space","0b010",,"Space attribute bits"
"CCN","PTEA","SA","2-0","16_bit_io_space","0b011",,"Space attribute bits"
"CCN","PTEA","SA","2-0","8_bit_common_memory_space","0b100",,"Space attribute bits"
"CCN","PTEA","SA","2-0","16_bit_common_memory_space","0b101",,"Space attribute bits"
"CCN","PTEA","SA","2-0","8_bit_attribute_memory_space","0b110",,"Space attribute bits"
"CCN","PTEA","SA","2-0","16_bit_attribute_memory_space","0b111",,"Space attribute bits"
,,,,,,,
"CCN","QACR0",,"4-2","area",,"0b111",
,,,,,,,
"CCN","QACR1",,"4-2","area",,"0b111",
,,,,,,,
"DMAC","DMATCR",,"23-0","transfer_count",,"0xffffff",
,,,,,,,
"DMAC","CHCR","SSA","31-29","reserved_in_pcmcia_access","0b000",,
"DMAC","CHCR","SSA","31-29","dynamic_bus_sizing_io_space","0b001",,
"DMAC","CHCR","SSA","31-29","8_bit_io_space","0b010",,
"DMAC","CHCR","SSA","31-29","16_bit_io_space","0b011",,
"DMAC","CHCR","SSA","31-29","8_bit_common_memory_space","0b100",,
"DMAC","CHCR","SSA","31-29","16_bit_common_memory_space","0b101",,
"DMAC","CHCR","SSA","31-29","8_bit_attribute_memory_space","0b110",,
"DMAC","CHCR","SSA","31-29","16_bit_attribute_memory_space","0b111",,
"DMAC","CHCR","STC","28","c5_space_wait_cycle_selection","0",,
"DMAC","CHCR","STC","28","c6_space_wait_cycle_selection","1",,
"DMAC","CHCR","DSA","27-25","reserved_in_pcmcia_access","0b000",,
"DMAC","CHCR","DSA","27-25","dynamic_bus_sizing_io_space","0b001",,
"DMAC","CHCR","DSA","27-25","8_bit_io_space","0b010",,
"DMAC","CHCR","DSA","27-25","16_bit_io_space","0b011",,
"DMAC","CHCR","DSA","27-25","8_bit_common_memory_space","0b100",,
"DMAC","CHCR","DSA","27-25","16_bit_common_memory_space","0b101",,
"DMAC","CHCR","DSA","27-25","8_bit_attribute_memory_space","0b110",,
"DMAC","CHCR","DSA","27-25","16_bit_attribute_memory_space","0b111",,
"DMAC","CHCR","DTC","24","c5_space_wait_cycle_selection","0",,
"DMAC","CHCR","DTC","24","c6_space_wait_cycle_selection","1",,
"DMAC","CHCR","DS","19","low_level_detection","0",,
"DMAC","CHCR","DS","19","falling_edge_detection","1",,
"DMAC","CHCR","RL","18","drak_is_an_active_high","0",,
"DMAC","CHCR","RL","18","drak_is_an_active_low","1",,
"DMAC","CHCR","AM","17","dack_is_output_in_read_cycle","0",,
"DMAC","CHCR","AM","17","dack_is_output_in_write_cycle","1",,
"DMAC","CHCR","AL","16","active_high_output","0",,
"DMAC","CHCR","AL","16","active_low_output","1",,
"DMAC","CHCR","DM","15-14","destination_address_fixed","0b00",,
"DMAC","CHCR","DM","15-14","destination_address_incremented","0b01",,
"DMAC","CHCR","DM","15-14","destination_address_decremented","0b10",,
"DMAC","CHCR","SM","13-12","source_address_fixed","0b00",,
"DMAC","CHCR","SM","13-12","source_address_incremented","0b01",,
"DMAC","CHCR","SM","13-12","source_address_decremented","0b10",,
"DMAC","CHCR","RS","11-8","resource_select",,"0b1111",
"DMAC","CHCR","TM","7","cycle_steal_mode","0",,
"DMAC","CHCR","TM","7","cycle_burst_mode","1",,
"DMAC","CHCR","TS","6-4","64_bit","0b000",,
"DMAC","CHCR","TS","6-4","8_bit","0b001",,
"DMAC","CHCR","TS","6-4","16_bit","0b010",,
"DMAC","CHCR","TS","6-4","32_bit","0b011",,
"DMAC","CHCR","TS","6-4","32_byte","0b100",,
"DMAC","CHCR","IE","2","interrupt_request_not_generated","0",,
"DMAC","CHCR","IE","2","interrupt_request_generated","1",,
"DMAC","CHCR","TE","1","transfers_not_completed","0",,
"DMAC","CHCR","TE","1","transfers_completed","1",,
"DMAC","CHCR","DE","0","channel_operation_disabled","0",,
"DMAC","CHCR","DE","0","channel_operation_enabled","1",,
,,,,,,,
"DMAC","DMAOR","DDT","15","normal_dma_mode","0",,
"DMAC","DMAOR","DDT","15","on_demand_data_transfer_mode","1",,
"DMAC","DMAOR","PR","9-8","ch0_ch1_ch2_ch3","0b00",,
"DMAC","DMAOR","PR","9-8","ch0_ch2_ch3_ch1","0b01",,
"DMAC","DMAOR","PR","9-8","ch2_ch0_ch1_ch3","0b10",,
"DMAC","DMAOR","PR","9-8","round_robin","0b11",,
"DMAC","DMAOR","AE","2","no_address_error__dma_transfer_enabled","0",,
"DMAC","DMAOR","AE","2","address_error__dma_transfer_disabled","1",,
"DMAC","DMAOR","NMIF","1","no_nmi__dma_transfer_enabled","0",,
"DMAC","DMAOR","NMIF","1","nmi__dma_transfer_disabled","1",,
"DMAC","DMAOR","DME","0","operation_disabled_on_all_channels","0",,
"DMAC","DMAOR","DME","0","operation_enabled_on_all_channels","1",,
,,,,,,,
"INTC","ICR","NMIL","15","pin_input_level_is_low","0",,
"INTC","ICR","NMIL","15","pin_input_level_is_high","1",,
"INTC","ICR","MAI","14","interrupts_enabled_while_nmi_pin_is_low","0",,
"INTC","ICR","MAI","14","interrupts_disabled_while_nmi_pin_is_low","1",,
"INTC","ICR","NMIB","9","interrupt_requests_witheld","0",,
"INTC","ICR","NMIB","9","interrupt_requests_detected","1",,
"INTC","ICR","NMIE","8","interrupt_on_falling_edge_of_nmi","0",,
"INTC","ICR","NMIE","8","interrupt_on_rising_edge_of_nmi","1",,
"INTC","ICR","IRLM","7","level_encoded_interrupt_requests","0",,
"INTC","ICR","IRLM","7","independent_interrupt_request","1",,
,,,,,,,
"INTC","IPRA",,"15-12","TMU0",,"0b1111",
"INTC","IPRA",,"11-8","TMU1",,"0b1111",
"INTC","IPRA",,"7-4","TMU2",,"0b1111",
"INTC","IPRA",,"3-0","RTC",,"0b1111",
,,,,,,,
"INTC","IPRB",,"15-12","WDT",,"0b1111",
"INTC","IPRB",,"11-8","REF",,"0b1111",
"INTC","IPRB",,"7-4","SCI1",,"0b1111",
,,,,,,,
"INTC","IPRC",,"15-12","GPIO",,"0b1111",
"INTC","IPRC",,"11-8","DMAC",,"0b1111",
"INTC","IPRC",,"7-4","SCIF",,"0b1111",
"INTC","IPRC",,"3-0","UDI",,"0b1111",
,,,,,,,
"TMU","TOCR","TCOE","0","tclk_is_external_clock_or_input_capture","0",,"Timer Clock Pin Control"
"TMU","TOCR","TCOE","0","tclk_is_on_chip_rtc","1",,"Timer Clock Pin Control"
,,,,,,,
"TMU","TSTR","STR2","2","counter_start","1",,"Counter Start 2"
"TMU","TSTR","STR1","1","counter_start","1",,"Counter Start 1"
"TMU","TSTR","STR0","0","counter_start","1",,"Counter Start 0"
,,,,,,,
"TMU","TCR0",,"8","UNF","1",,"Underflow Flag"
"TMU","TCR0",,"5","UNIE","1",,"Underflow Interrupt Control"
"TMU","TCR0","CKEG","4-3","rising","0b00",,"Clock Edge"
"TMU","TCR0","CKEG","4-3","falling","0b01",,"Clock Edge"
"TMU","TCR0","CKEG","4-3","rising_falling","0b10",,"Clock Edge"
"TMU","TCR0","TPSC","2-0","p_phi_4","0b000",,"Timer Prescaler"
"TMU","TCR0","TPSC","2-0","p_phi_16","0b001",,"Timer Prescaler"
"TMU","TCR0","TPSC","2-0","p_phi_64","0b010",,"Timer Prescaler"
"TMU","TCR0","TPSC","2-0","p_phi_256","0b011",,"Timer Prescaler"
"TMU","TCR0","TPSC","2-0","p_phi_1024","0b100",,"Timer Prescaler"
"TMU","TCR0","TPSC","2-0","rtc_output","0b110",,"Timer Prescaler"
"TMU","TCR0","TPSC","2-0","external","0b111",,"Timer Prescaler"
,,,,,,,
"TMU","TCR1",,"8","UNF","1",,"Underflow Flag"
"TMU","TCR1",,"5","UNIE","1",,"Underflow Interrupt Control"
"TMU","TCR1","CKEG","4-3","rising","0b00",,"Clock Edge"
"TMU","TCR1","CKEG","4-3","falling","0b01",,"Clock Edge"
"TMU","TCR1","CKEG","4-3","rising_falling","0b10",,"Clock Edge"
"TMU","TCR1","TPSC","2-0","p_phi_4","0b000",,"Timer Prescaler"
"TMU","TCR1","TPSC","2-0","p_phi_16","0b001",,"Timer Prescaler"
"TMU","TCR1","TPSC","2-0","p_phi_64","0b010",,"Timer Prescaler"
"TMU","TCR1","TPSC","2-0","p_phi_256","0b011",,"Timer Prescaler"
"TMU","TCR1","TPSC","2-0","p_phi_1024","0b100",,"Timer Prescaler"
"TMU","TCR1","TPSC","2-0","rtc_output","0b110",,"Timer Prescaler"
"TMU","TCR1","TPSC","2-0","external","0b111",,"Timer Prescaler"
,,,,,,,
"TMU","TCR2",,"9","ICPF","1",,"Input Capture Interrupt Flag"
"TMU","TCR2",,"8","UNF","1",,"Underflow Flag"
"TMU","TCR2","ICPE","7-6","disabled","0b00",,"Input Capture Control"
"TMU","TCR2","ICPE","7-6","enabled","0b10",,"Input Capture Control"
"TMU","TCR2","ICPE","7-6","enabled_with_interrupts","0b11",,"Input Capture Control"
"TMU","TCR2",,"5","UNIE","1",,"Underflow Interrupt Control"
"TMU","TCR2","CKEG","4-3","rising","0b00",,"Clock Edge"
"TMU","TCR2","CKEG","4-3","falling","0b01",,"Clock Edge"
"TMU","TCR2","CKEG","4-3","rising_falling","0b10",,"Clock Edge"
"TMU","TCR2","TPSC","2-0","p_phi_4","0b000",,"Timer Prescaler"
"TMU","TCR2","TPSC","2-0","p_phi_16","0b001",,"Timer Prescaler"
"TMU","TCR2","TPSC","2-0","p_phi_64","0b010",,"Timer Prescaler"
"TMU","TCR2","TPSC","2-0","p_phi_256","0b011",,"Timer Prescaler"
"TMU","TCR2","TPSC","2-0","p_phi_1024","0b100",,"Timer Prescaler"
"TMU","TCR2","TPSC","2-0","rtc_output","0b110",,"Timer Prescaler"
"TMU","TCR2","TPSC","2-0","external","0b111",,"Timer Prescaler"
,,,,,,,
"SCIF","SCSMR2","CHR","6","8_bit_data","0",,
"SCIF","SCSMR2","CHR","6","7_bit_data","1",,
"SCIF","SCSMR2","PE","5","parity_disabled","0",,
"SCIF","SCSMR2","PE","5","parity_enabled","1",,
"SCIF","SCSMR2","OE","4","even_parity","0",,
"SCIF","SCSMR2","OE","4","odd_parity","1",,
"SCIF","SCSMR2","STOP","3","1_stop_bit","0",,
"SCIF","SCSMR2","STOP","3","2_stop_bits","1",,
"SCIF","SCSMR2","CKS","1-0","p_phi_clock","0b00",,
"SCIF","SCSMR2","CKS","1-0","p_phi_4_clock","0b01",,
"SCIF","SCSMR2","CKS","1-0","p_phi_16_clock","0b10",,
"SCIF","SCSMR2","CKS","1-0","p_phi_64_clock","0b11",,
,,,,,,,
"SCIF","SCSCR2","TIE","7","transmit_fifo_data_empty_interrupt_disabled","0",,
"SCIF","SCSCR2","TIE","7","transmit_fifo_data_empty_interrupt_enabled","1",,
"SCIF","SCSCR2","RIE","6","request_disabled","0",,
"SCIF","SCSCR2","RIE","6","request_enabled","1",,
"SCIF","SCSCR2","TE","5","transmission_disabled","0",,
"SCIF","SCSCR2","TE","5","transmission_enabled","1",,
"SCIF","SCSCR2","RE","4","reception_disabled","0",,
"SCIF","SCSCR2","RE","4","reception_enabled","1",,
"SCIF","SCSCR2","REIE","3","requests_disabled","0",,
"SCIF","SCSCR2","REIE","3","requests_enabled","1",,
"SCIF","SCSCR2","CKE1","1","sck2_pin_functions_as_input_pin","0",,
"SCIF","SCSCR2","CKE1","1","sck2_pin_functions_as_clock_input","1",,
,,,,,,,
"SCIF","SCFSR2","PER3_0","15-12","number_of_parity_errors",,,
"SCIF","SCFSR2","FER3_0","11-8","number_of_framing_errors",,,
"SCIF","SCFSR2","ER","7","no_framing_error_or_parity_error","0",,
"SCIF","SCFSR2","ER","7","framing_error_or_parity_error","1",,
"SCIF","SCFSR2","TEND","6","transmission_in_progress","0",,
"SCIF","SCFSR2","TEND","6","transmission_has_ended","1",,
"SCIF","SCFSR2","TDFE","5","transmit_data_bytes_does_exceed_trigger","0",,
"SCIF","SCFSR2","TDFE","5","transmit_data_bytes_does_not_exceed_trigger","1",,
"SCIF","SCFSR2","BRK","4","break_not_received","0",,
"SCIF","SCFSR2","BRK","4","break_received","1",,
"SCIF","SCFSR2","FER","3","no_framing_error","0",,
"SCIF","SCFSR2","FER","3","framing_error","1",,
"SCIF","SCFSR2","PER","2","parity_error","0",,
"SCIF","SCFSR2","PER","2","no_parity_error","1",,
"SCIF","SCFSR2","RDF","1","receive_data_bytes_less_than_receive_trigger","0",,
"SCIF","SCFSR2","RDF","1","receive_data_bytes_greater_than_or_equal_receive_trigger","1",,
"SCIF","SCFSR2","DR","0","reception_is_in_progress","0",,
"SCIF","SCFSR2","DR","0","no_further_data_has_arrived","1",,
,,,,,,,
"SCIF","SCFCR2","RTRG","7-6","trigger_on_1_byte","0b00",,
"SCIF","SCFCR2","RTRG","7-6","trigger_on_4_bytes","0b01",,
"SCIF","SCFCR2","RTRG","7-6","trigger_on_8_bytes","0b10",,
"SCIF","SCFCR2","RTRG","7-6","trigger_on_14_byte","0b11",,
"SCIF","SCFCR2","TTRG","5-4","trigger_on_8_bytes","0b00",,
"SCIF","SCFCR2","TTRG","5-4","trigger_on_4_bytes","0b01",,
"SCIF","SCFCR2","TTRG","5-4","trigger_on_2_bytes","0b10",,
"SCIF","SCFCR2","TTRG","5-4","trigger_on_1_bytes","0b11",,
"SCIF","SCFCR2","MCE","3","modem_signals_disabled","0",,
"SCIF","SCFCR2","MCE","3","modem_signals_enabled","1",,
"SCIF","SCFCR2","TFRST","2","reset_operation_disabled","0",,
"SCIF","SCFCR2","TFRST","2","reset_operation_enabled","1",,
"SCIF","SCFCR2","RFRST","1","reset_operation_disabled","0",,
"SCIF","SCFCR2","RFRST","1","reset_operation_enabled","1",,
"SCIF","SCFCR2","LOOP","0","loopback_test_disabled","0",,
"SCIF","SCFCR2","LOOP","0","loopback_test_enabled","1",,
,,,,,,,
"SCIF","SCFDR2",,"12-8","transmit_data_bytes",,,
"SCIF","SCFDR2",,"4-0","receive_data_bytes",,,
,,,,,,,
"SCIF","SCSPTR2","RTSIO","7","rtsdt_not_output_to_rts2","0",,
"SCIF","SCSPTR2","RTSIO","7","rtsdt_output_to_rts2","1",,
"SCIF","SCSPTR2","RTSDT","6","input_output_data_is_low_level","0",,
"SCIF","SCSPTR2","RTSDT","6","input_output_data_is_high_level","1",,
"SCIF","SCSPTR2","CTSIO","5","ctsdt_is_not_output_to_cts2","0",,
"SCIF","SCSPTR2","CTSIO","5","ctsdt_is_output_to_cts2","1",,
"SCIF","SCSPTR2","CTSDT","4","input_output_data_is_low_level","0",,
"SCIF","SCSPTR2","CTSDT","4","input_output_data_is_high_level","1",,
"SCIF","SCSPTR2","SPB2IO","1","spb2dt_is_not_output_to_txd2","0",,
"SCIF","SCSPTR2","SPB2IO","1","spb2dt_is_output_to_txd2","1",,
"SCIF","SCSPTR2","SPB2DT","0","input_output_data_is_low_level","0",,
"SCIF","SCSPTR2","SPB2DT","0","input_output_data_is_high_level","1",,
1 block register_name enum_name bits bit_name value mask description
2 CCN PTEH 31-10 VPN Virtual Page Number
3 CCN PTEH 7-0 ASID Address space identifier
4
5 CCN PTEL 28-10 PPN Physical page number
6 CCN PTEL V 8 invalid 0 Validity
7 CCN PTEL V 8 valid 1 Validity
8 CCN PTEL SZ 7,4 1_kbyte_page 0b0000 Page size
9 CCN PTEL SZ 7,4 4_kbyte_page 0b0001 Page size
10 CCN PTEL SZ 7,4 64_kbyte_page 0b1000 Page size
11 CCN PTEL SZ 7,4 1_mbyte_page 0b1001 Page size
12 CCN PTEL PR 6-5 read_only_in_privileged_mode 0b00 Protection key data
13 CCN PTEL PR 6-5 read_write_in_privileged_mode 0b01 Protection key data
14 CCN PTEL PR 6-5 read_only_in_privileged_and_user_mode 0b10 Protection key data
15 CCN PTEL PR 6-5 read_write_in_privileged_and_user_mode 0b11 Protection key data
16 CCN PTEL C 3 not_cacheable 0 Cacheability bit
17 CCN PTEL C 3 cacheable 1 Cacheability bit
18 CCN PTEL D 2 write_has_not_been_performed 0 Dirty bit
19 CCN PTEL D 2 write_has_been_performed 1 Dirty bit
20 CCN PTEL SH 1 pages_are_shared_by_processes 0 Share status bit
21 CCN PTEL SH 1 pages_are_not_shared_by_processes 1 Share status bit
22 CCN PTEL WT 0 copy_back_mode 0 Write-through bit
23 CCN PTEL WT 0 write_through_mode 1 Write-through bit
24
25 CCN MMUCR 31-26 LRUI Least recently used ITLB
26 CCN MMUCR 23-18 URB UTLB replace boundary
27 CCN MMUCR 15-10 URC UTLB replace counter
28 CCN MMUCR SQMD 9 user_privileged_access_possible 0 Store queue mode bit
29 CCN MMUCR SQMD 9 privileged_access_possible 1 Store queue mode bit
30 CCN MMUCR SV 8 multiple_virtual_memory_mode 0 Single virtual mode bit
31 CCN MMUCR SV 8 single_virtual_memory_mode 1 Single virtual mode bit
32 CCN MMUCR TI 2 invalidate_all_utlb_itlb_bits 1 TLB invalidate
33 CCN MMUCR AT 0 mmu_disabled 0 Address translation bit
34 CCN MMUCR AT 0 mmu_enabled 1 Address translation bit
35
36 CCN BASRA 7-0 basa 0xff
37
38 CCN BASRB 7-0 basa 0xff
39
40 CCN CCR IIX 15 address_bits_12_5_used_for_ic_entry_selection 0 IC index enable
41 CCN CCR IIX 15 address_bits_25_and_11_5_used_for_ic_entry_selection 1 IC index enable
42 CCN CCR ICI 11 clear_v_bits_of_all_ic_entries 1 IC invalidation
43 CCN CCR ICE 8 ic_not_used 0 IC enable
44 CCN CCR ICE 8 ic_used 1 IC enable
45 CCN CCR OIX 7 address_bits_13_5_used_for_oc_entry_selection 0 OC index enable
46 CCN CCR OIX 7 address_bits_25_and_12_5_used_for_oc_entry_selection 1 OC index enable
47 CCN CCR ORA 5 16_kbytes_used_as_cache 0 OC RAM enable
48 CCN CCR ORA 5 8_kbytes_used_as_cache_8_kbytes_used_as_ram 1 OC RAM enable
49 CCN CCR OCI 3 clear_v_and_u_bits_of_all_oc_entries 1 OC invalidation
50 CCN CCR CB 2 write_through_mode 0 Copy-back enable
51 CCN CCR CB 2 copy_back_mode 1 Copy-back enable
52 CCN CCR WT 1 copy_back_mode 0 Write-through enable
53 CCN CCR WT 1 write_through_mode 1 Write-through enable
54 CCN CCR OCE 0 oc_not_used 0 OC enable
55 CCN CCR OCE 0 oc_used 1 OC enable
56
57 CCN TRA 9-2 imm
58
59 CCN EXPEVT 11-0 exception_code
60
61 CCN INTEVT 11-0 exception_code
62
63 CCN PTEA TC 3 area_5_is_used 0 Timing control bit
64 CCN PTEA TC 3 area_6_is_used 1 Timing control bit
65 CCN PTEA SA 2-0 undefined 0b000 Space attribute bits
66 CCN PTEA SA 2-0 variable_size_io_space 0b001 Space attribute bits
67 CCN PTEA SA 2-0 8_bit_io_space 0b010 Space attribute bits
68 CCN PTEA SA 2-0 16_bit_io_space 0b011 Space attribute bits
69 CCN PTEA SA 2-0 8_bit_common_memory_space 0b100 Space attribute bits
70 CCN PTEA SA 2-0 16_bit_common_memory_space 0b101 Space attribute bits
71 CCN PTEA SA 2-0 8_bit_attribute_memory_space 0b110 Space attribute bits
72 CCN PTEA SA 2-0 16_bit_attribute_memory_space 0b111 Space attribute bits
73
74 CCN QACR0 4-2 area 0b111
75
76 CCN QACR1 4-2 area 0b111
77
78 DMAC DMATCR 23-0 transfer_count 0xffffff
79
80 DMAC CHCR SSA 31-29 reserved_in_pcmcia_access 0b000
81 DMAC CHCR SSA 31-29 dynamic_bus_sizing_io_space 0b001
82 DMAC CHCR SSA 31-29 8_bit_io_space 0b010
83 DMAC CHCR SSA 31-29 16_bit_io_space 0b011
84 DMAC CHCR SSA 31-29 8_bit_common_memory_space 0b100
85 DMAC CHCR SSA 31-29 16_bit_common_memory_space 0b101
86 DMAC CHCR SSA 31-29 8_bit_attribute_memory_space 0b110
87 DMAC CHCR SSA 31-29 16_bit_attribute_memory_space 0b111
88 DMAC CHCR STC 28 c5_space_wait_cycle_selection 0
89 DMAC CHCR STC 28 c6_space_wait_cycle_selection 1
90 DMAC CHCR DSA 27-25 reserved_in_pcmcia_access 0b000
91 DMAC CHCR DSA 27-25 dynamic_bus_sizing_io_space 0b001
92 DMAC CHCR DSA 27-25 8_bit_io_space 0b010
93 DMAC CHCR DSA 27-25 16_bit_io_space 0b011
94 DMAC CHCR DSA 27-25 8_bit_common_memory_space 0b100
95 DMAC CHCR DSA 27-25 16_bit_common_memory_space 0b101
96 DMAC CHCR DSA 27-25 8_bit_attribute_memory_space 0b110
97 DMAC CHCR DSA 27-25 16_bit_attribute_memory_space 0b111
98 DMAC CHCR DTC 24 c5_space_wait_cycle_selection 0
99 DMAC CHCR DTC 24 c6_space_wait_cycle_selection 1
100 DMAC CHCR DS 19 low_level_detection 0
101 DMAC CHCR DS 19 falling_edge_detection 1
102 DMAC CHCR RL 18 drak_is_an_active_high 0
103 DMAC CHCR RL 18 drak_is_an_active_low 1
104 DMAC CHCR AM 17 dack_is_output_in_read_cycle 0
105 DMAC CHCR AM 17 dack_is_output_in_write_cycle 1
106 DMAC CHCR AL 16 active_high_output 0
107 DMAC CHCR AL 16 active_low_output 1
108 DMAC CHCR DM 15-14 destination_address_fixed 0b00
109 DMAC CHCR DM 15-14 destination_address_incremented 0b01
110 DMAC CHCR DM 15-14 destination_address_decremented 0b10
111 DMAC CHCR SM 13-12 source_address_fixed 0b00
112 DMAC CHCR SM 13-12 source_address_incremented 0b01
113 DMAC CHCR SM 13-12 source_address_decremented 0b10
114 DMAC CHCR RS 11-8 resource_select 0b1111
115 DMAC CHCR TM 7 cycle_steal_mode 0
116 DMAC CHCR TM 7 cycle_burst_mode 1
117 DMAC CHCR TS 6-4 64_bit 0b000
118 DMAC CHCR TS 6-4 8_bit 0b001
119 DMAC CHCR TS 6-4 16_bit 0b010
120 DMAC CHCR TS 6-4 32_bit 0b011
121 DMAC CHCR TS 6-4 32_byte 0b100
122 DMAC CHCR IE 2 interrupt_request_not_generated 0
123 DMAC CHCR IE 2 interrupt_request_generated 1
124 DMAC CHCR TE 1 transfers_not_completed 0
125 DMAC CHCR TE 1 transfers_completed 1
126 DMAC CHCR DE 0 channel_operation_disabled 0
127 DMAC CHCR DE 0 channel_operation_enabled 1
128
129 DMAC DMAOR DDT 15 normal_dma_mode 0
130 DMAC DMAOR DDT 15 on_demand_data_transfer_mode 1
131 DMAC DMAOR PR 9-8 ch0_ch1_ch2_ch3 0b00
132 DMAC DMAOR PR 9-8 ch0_ch2_ch3_ch1 0b01
133 DMAC DMAOR PR 9-8 ch2_ch0_ch1_ch3 0b10
134 DMAC DMAOR PR 9-8 round_robin 0b11
135 DMAC DMAOR AE 2 no_address_error__dma_transfer_enabled 0
136 DMAC DMAOR AE 2 address_error__dma_transfer_disabled 1
137 DMAC DMAOR NMIF 1 no_nmi__dma_transfer_enabled 0
138 DMAC DMAOR NMIF 1 nmi__dma_transfer_disabled 1
139 DMAC DMAOR DME 0 operation_disabled_on_all_channels 0
140 DMAC DMAOR DME 0 operation_enabled_on_all_channels 1
141
142 INTC ICR NMIL 15 pin_input_level_is_low 0
143 INTC ICR NMIL 15 pin_input_level_is_high 1
144 INTC ICR MAI 14 interrupts_enabled_while_nmi_pin_is_low 0
145 INTC ICR MAI 14 interrupts_disabled_while_nmi_pin_is_low 1
146 INTC ICR NMIB 9 interrupt_requests_witheld 0
147 INTC ICR NMIB 9 interrupt_requests_detected 1
148 INTC ICR NMIE 8 interrupt_on_falling_edge_of_nmi 0
149 INTC ICR NMIE 8 interrupt_on_rising_edge_of_nmi 1
150 INTC ICR IRLM 7 level_encoded_interrupt_requests 0
151 INTC ICR IRLM 7 independent_interrupt_request 1
152
153 INTC IPRA 15-12 TMU0 0b1111
154 INTC IPRA 11-8 TMU1 0b1111
155 INTC IPRA 7-4 TMU2 0b1111
156 INTC IPRA 3-0 RTC 0b1111
157
158 INTC IPRB 15-12 WDT 0b1111
159 INTC IPRB 11-8 REF 0b1111
160 INTC IPRB 7-4 SCI1 0b1111
161
162 INTC IPRC 15-12 GPIO 0b1111
163 INTC IPRC 11-8 DMAC 0b1111
164 INTC IPRC 7-4 SCIF 0b1111
165 INTC IPRC 3-0 UDI 0b1111
166
167 TMU TOCR TCOE 0 tclk_is_external_clock_or_input_capture 0 Timer Clock Pin Control
168 TMU TOCR TCOE 0 tclk_is_on_chip_rtc 1 Timer Clock Pin Control
169
170 TMU TSTR STR2 2 counter_start 1 Counter Start 2
171 TMU TSTR STR1 1 counter_start 1 Counter Start 1
172 TMU TSTR STR0 0 counter_start 1 Counter Start 0
173
174 TMU TCR0 8 UNF 1 Underflow Flag
175 TMU TCR0 5 UNIE 1 Underflow Interrupt Control
176 TMU TCR0 CKEG 4-3 rising 0b00 Clock Edge
177 TMU TCR0 CKEG 4-3 falling 0b01 Clock Edge
178 TMU TCR0 CKEG 4-3 rising_falling 0b10 Clock Edge
179 TMU TCR0 TPSC 2-0 p_phi_4 0b000 Timer Prescaler
180 TMU TCR0 TPSC 2-0 p_phi_16 0b001 Timer Prescaler
181 TMU TCR0 TPSC 2-0 p_phi_64 0b010 Timer Prescaler
182 TMU TCR0 TPSC 2-0 p_phi_256 0b011 Timer Prescaler
183 TMU TCR0 TPSC 2-0 p_phi_1024 0b100 Timer Prescaler
184 TMU TCR0 TPSC 2-0 rtc_output 0b110 Timer Prescaler
185 TMU TCR0 TPSC 2-0 external 0b111 Timer Prescaler
186
187 TMU TCR1 8 UNF 1 Underflow Flag
188 TMU TCR1 5 UNIE 1 Underflow Interrupt Control
189 TMU TCR1 CKEG 4-3 rising 0b00 Clock Edge
190 TMU TCR1 CKEG 4-3 falling 0b01 Clock Edge
191 TMU TCR1 CKEG 4-3 rising_falling 0b10 Clock Edge
192 TMU TCR1 TPSC 2-0 p_phi_4 0b000 Timer Prescaler
193 TMU TCR1 TPSC 2-0 p_phi_16 0b001 Timer Prescaler
194 TMU TCR1 TPSC 2-0 p_phi_64 0b010 Timer Prescaler
195 TMU TCR1 TPSC 2-0 p_phi_256 0b011 Timer Prescaler
196 TMU TCR1 TPSC 2-0 p_phi_1024 0b100 Timer Prescaler
197 TMU TCR1 TPSC 2-0 rtc_output 0b110 Timer Prescaler
198 TMU TCR1 TPSC 2-0 external 0b111 Timer Prescaler
199
200 TMU TCR2 9 ICPF 1 Input Capture Interrupt Flag
201 TMU TCR2 8 UNF 1 Underflow Flag
202 TMU TCR2 ICPE 7-6 disabled 0b00 Input Capture Control
203 TMU TCR2 ICPE 7-6 enabled 0b10 Input Capture Control
204 TMU TCR2 ICPE 7-6 enabled_with_interrupts 0b11 Input Capture Control
205 TMU TCR2 5 UNIE 1 Underflow Interrupt Control
206 TMU TCR2 CKEG 4-3 rising 0b00 Clock Edge
207 TMU TCR2 CKEG 4-3 falling 0b01 Clock Edge
208 TMU TCR2 CKEG 4-3 rising_falling 0b10 Clock Edge
209 TMU TCR2 TPSC 2-0 p_phi_4 0b000 Timer Prescaler
210 TMU TCR2 TPSC 2-0 p_phi_16 0b001 Timer Prescaler
211 TMU TCR2 TPSC 2-0 p_phi_64 0b010 Timer Prescaler
212 TMU TCR2 TPSC 2-0 p_phi_256 0b011 Timer Prescaler
213 TMU TCR2 TPSC 2-0 p_phi_1024 0b100 Timer Prescaler
214 TMU TCR2 TPSC 2-0 rtc_output 0b110 Timer Prescaler
215 TMU TCR2 TPSC 2-0 external 0b111 Timer Prescaler
216
217 SCIF SCSMR2 CHR 6 8_bit_data 0
218 SCIF SCSMR2 CHR 6 7_bit_data 1
219 SCIF SCSMR2 PE 5 parity_disabled 0
220 SCIF SCSMR2 PE 5 parity_enabled 1
221 SCIF SCSMR2 OE 4 even_parity 0
222 SCIF SCSMR2 OE 4 odd_parity 1
223 SCIF SCSMR2 STOP 3 1_stop_bit 0
224 SCIF SCSMR2 STOP 3 2_stop_bits 1
225 SCIF SCSMR2 CKS 1-0 p_phi_clock 0b00
226 SCIF SCSMR2 CKS 1-0 p_phi_4_clock 0b01
227 SCIF SCSMR2 CKS 1-0 p_phi_16_clock 0b10
228 SCIF SCSMR2 CKS 1-0 p_phi_64_clock 0b11
229
230 SCIF SCSCR2 TIE 7 transmit_fifo_data_empty_interrupt_disabled 0
231 SCIF SCSCR2 TIE 7 transmit_fifo_data_empty_interrupt_enabled 1
232 SCIF SCSCR2 RIE 6 request_disabled 0
233 SCIF SCSCR2 RIE 6 request_enabled 1
234 SCIF SCSCR2 TE 5 transmission_disabled 0
235 SCIF SCSCR2 TE 5 transmission_enabled 1
236 SCIF SCSCR2 RE 4 reception_disabled 0
237 SCIF SCSCR2 RE 4 reception_enabled 1
238 SCIF SCSCR2 REIE 3 requests_disabled 0
239 SCIF SCSCR2 REIE 3 requests_enabled 1
240 SCIF SCSCR2 CKE1 1 sck2_pin_functions_as_input_pin 0
241 SCIF SCSCR2 CKE1 1 sck2_pin_functions_as_clock_input 1
242
243 SCIF SCFSR2 PER3_0 15-12 number_of_parity_errors
244 SCIF SCFSR2 FER3_0 11-8 number_of_framing_errors
245 SCIF SCFSR2 ER 7 no_framing_error_or_parity_error 0
246 SCIF SCFSR2 ER 7 framing_error_or_parity_error 1
247 SCIF SCFSR2 TEND 6 transmission_in_progress 0
248 SCIF SCFSR2 TEND 6 transmission_has_ended 1
249 SCIF SCFSR2 TDFE 5 transmit_data_bytes_does_exceed_trigger 0
250 SCIF SCFSR2 TDFE 5 transmit_data_bytes_does_not_exceed_trigger 1
251 SCIF SCFSR2 BRK 4 break_not_received 0
252 SCIF SCFSR2 BRK 4 break_received 1
253 SCIF SCFSR2 FER 3 no_framing_error 0
254 SCIF SCFSR2 FER 3 framing_error 1
255 SCIF SCFSR2 PER 2 parity_error 0
256 SCIF SCFSR2 PER 2 no_parity_error 1
257 SCIF SCFSR2 RDF 1 receive_data_bytes_less_than_receive_trigger 0
258 SCIF SCFSR2 RDF 1 receive_data_bytes_greater_than_or_equal_receive_trigger 1
259 SCIF SCFSR2 DR 0 reception_is_in_progress 0
260 SCIF SCFSR2 DR 0 no_further_data_has_arrived 1
261
262 SCIF SCFCR2 RTRG 7-6 trigger_on_1_byte 0b00
263 SCIF SCFCR2 RTRG 7-6 trigger_on_4_bytes 0b01
264 SCIF SCFCR2 RTRG 7-6 trigger_on_8_bytes 0b10
265 SCIF SCFCR2 RTRG 7-6 trigger_on_14_byte 0b11
266 SCIF SCFCR2 TTRG 5-4 trigger_on_8_bytes 0b00
267 SCIF SCFCR2 TTRG 5-4 trigger_on_4_bytes 0b01
268 SCIF SCFCR2 TTRG 5-4 trigger_on_2_bytes 0b10
269 SCIF SCFCR2 TTRG 5-4 trigger_on_1_bytes 0b11
270 SCIF SCFCR2 MCE 3 modem_signals_disabled 0
271 SCIF SCFCR2 MCE 3 modem_signals_enabled 1
272 SCIF SCFCR2 TFRST 2 reset_operation_disabled 0
273 SCIF SCFCR2 TFRST 2 reset_operation_enabled 1
274 SCIF SCFCR2 RFRST 1 reset_operation_disabled 0
275 SCIF SCFCR2 RFRST 1 reset_operation_enabled 1
276 SCIF SCFCR2 LOOP 0 loopback_test_disabled 0
277 SCIF SCFCR2 LOOP 0 loopback_test_enabled 1
278
279 SCIF SCFDR2 12-8 transmit_data_bytes
280 SCIF SCFDR2 4-0 receive_data_bytes
281
282 SCIF SCSPTR2 RTSIO 7 rtsdt_not_output_to_rts2 0
283 SCIF SCSPTR2 RTSIO 7 rtsdt_output_to_rts2 1
284 SCIF SCSPTR2 RTSDT 6 input_output_data_is_low_level 0
285 SCIF SCSPTR2 RTSDT 6 input_output_data_is_high_level 1
286 SCIF SCSPTR2 CTSIO 5 ctsdt_is_not_output_to_cts2 0
287 SCIF SCSPTR2 CTSIO 5 ctsdt_is_output_to_cts2 1
288 SCIF SCSPTR2 CTSDT 4 input_output_data_is_low_level 0
289 SCIF SCSPTR2 CTSDT 4 input_output_data_is_high_level 1
290 SCIF SCSPTR2 SPB2IO 1 spb2dt_is_not_output_to_txd2 0
291 SCIF SCSPTR2 SPB2IO 1 spb2dt_is_output_to_txd2 1
292 SCIF SCSPTR2 SPB2DT 0 input_output_data_is_low_level 0
293 SCIF SCSPTR2 SPB2DT 0 input_output_data_is_high_level 1

BIN
regs/sh7091_bits.ods Normal file

Binary file not shown.

View File

@ -1,6 +1,6 @@
#include <cstdint> #include <cstdint>
#include "cache.hpp" #include "sh7091/cache.hpp"
extern uint32_t __bss_link_start __asm("__bss_link_start"); extern uint32_t __bss_link_start __asm("__bss_link_start");
extern uint32_t __bss_link_end __asm("__bss_link_end"); extern uint32_t __bss_link_end __asm("__bss_link_end");

View File

@ -1,8 +1,8 @@
#include <cstdint> #include <cstdint>
#include "sh7091.hpp" #include "sh7091/sh7091.hpp"
#include "sh7091_bits.hpp" #include "sh7091/sh7091_bits.hpp"
#include "holly.hpp" #include "holly/holly.hpp"
enum load_command { enum load_command {
CMD_NONE, CMD_NONE,
@ -48,7 +48,8 @@ void debug(const char * s)
{ {
char c; char c;
while ((c = *s++)) { while ((c = *s++)) {
while ((sh7091.SCIF.SCFSR2 & SCFSR2__TDFE) == 0); using namespace scif;
while ((sh7091.SCIF.SCFSR2 & scfsr2::tdfe::bit_mask) == 0);
sh7091.SCIF.SCFTDR2 = (uint8_t)c; sh7091.SCIF.SCFTDR2 = (uint8_t)c;
} }
} }

36
sh7091/cache.cpp Normal file
View File

@ -0,0 +1,36 @@
#include "type.hpp"
#include "sh7091.hpp"
#include "sh7091_bits.hpp"
#include "cache.hpp"
extern volatile reg32 sh7091_ic_a[256][(1 << 5) / 4] __asm("sh7091_ic_a");
extern volatile reg32 sh7091_oc_a[512][(1 << 5) / 4] __asm("sh7091_oc_a");
namespace cache {
void init()
{
for (int i = 0; i < 256; i++) {
sh7091_ic_a[i][0] = 0;
}
for (int i = 0; i < 512; i++) {
sh7091_oc_a[i][0] = 0;
}
using namespace ccn::ccr;
sh7091.CCN.CCR = ici::clear_v_bits_of_all_ic_entries // instruction cache invalidate
| ice::ic_used // instruction cache enable
| oci::clear_v_and_u_bits_of_all_oc_entries // operand cache invalidate
| oce::oc_used // operand cache enable
// | cb::copy_back_mode // enable copy-back mode for the P1 area
;
sh7091.CCN.MMUCR = ccn::mmucr::at::mmu_disabled;
asm volatile ("nop;nop;nop;nop;nop;nop;nop;nop;");
}
}

View File

@ -9,24 +9,29 @@ namespace serial {
void init() void init()
{ {
using namespace scif;
sh7091.SCIF.SCSCR2 = 0; sh7091.SCIF.SCSCR2 = 0;
sh7091.SCIF.SCSMR2 = 0; sh7091.SCIF.SCSMR2 = 0;
sh7091.SCIF.SCBRR2 = 1; // 520833.3 sh7091.SCIF.SCBRR2 = 1; // 520833.3
sh7091.SCIF.SCFCR2 = SCFCR2__TFRST | SCFCR2__RFRST; sh7091.SCIF.SCFCR2 = scfcr2::tfrst::reset_operation_enabled
| scfcr2::rfrst::reset_operation_enabled;
// tx/rx trigger on 1 byte // tx/rx trigger on 1 byte
sh7091.SCIF.SCFCR2 = 0; sh7091.SCIF.SCFCR2 = 0;
sh7091.SCIF.SCSPTR2 = 0; sh7091.SCIF.SCSPTR2 = 0;
sh7091.SCIF.SCLSR2 = 0; sh7091.SCIF.SCLSR2 = 0;
sh7091.SCIF.SCSCR2 = SCSCR2__TE | SCSCR2__RE; sh7091.SCIF.SCSCR2 = scscr2::te::transmission_enabled
| scscr2::re::reception_enabled;
} }
void character(const char c) void character(const char c)
{ {
using namespace scif;
// wait for transmit fifo to become empty // wait for transmit fifo to become empty
while ((sh7091.SCIF.SCFSR2 & SCFSR2__TDFE) == 0); while ((sh7091.SCIF.SCFSR2 & scfsr2::tdfe::bit_mask) == 0);
for (int i = 0; i < 100000; i++) { for (int i = 0; i < 100000; i++) {
asm volatile ("nop;"); asm volatile ("nop;");
@ -43,7 +48,7 @@ void string(const char * s)
} }
template <typename T> template <typename T>
void integer(const T n) void integer(const T n, const char end)
{ {
constexpr uint32_t length = (sizeof (T)) * 2; constexpr uint32_t length = (sizeof (T)) * 2;
char num_buf[length + 1]; char num_buf[length + 1];
@ -51,11 +56,21 @@ void integer(const T n)
num_buf[length] = 0; num_buf[length] = 0;
string("0x"); string("0x");
string(num_buf); string(num_buf);
string("\n"); character(end);
}
template <typename T>
void integer(const T n)
{
return integer(n, '\n');
} }
template void integer<uint32_t>(uint32_t param); template void integer<uint32_t>(uint32_t param);
template void integer<uint16_t>(uint16_t param); template void integer<uint16_t>(uint16_t param);
template void integer<uint8_t>(uint8_t param); template void integer<uint8_t>(uint8_t param);
template void integer<uint32_t>(uint32_t param, char end);
template void integer<uint16_t>(uint16_t param, char end);
template void integer<uint8_t>(uint8_t param, char end);
} }

View File

@ -6,6 +6,9 @@ void character(const char c);
void string(const char * s); void string(const char * s);
template <typename T>
void integer(const T n, const char end);
template <typename T> template <typename T>
void integer(const T n); void integer(const T n);

View File

@ -90,9 +90,9 @@ struct bsc_reg {
reg8 _pad7[2]; reg8 _pad7[2];
reg16 GPIOIC; /* GPIO interrupt control register */ reg16 GPIOIC; /* GPIO interrupt control register */
reg8 _pad8[1048502]; reg8 _pad8[1048502];
reg8 SDMR2[65536]; /* Synchronous DRAM mode registers */ reg32 SDMR2[16384]; /* Synchronous DRAM mode registers */
reg8 _pad9[196608]; reg8 _pad9[196608];
reg8 SDMR3[65536]; /* Synchronous DRAM mode registers */ reg32 SDMR3[16384]; /* Synchronous DRAM mode registers */
}; };
static_assert((offsetof (struct bsc_reg, BCR1)) == 0x0); static_assert((offsetof (struct bsc_reg, BCR1)) == 0x0);

822
sh7091/sh7091_bits.hpp Normal file
View File

@ -0,0 +1,822 @@
#pragma once
#include <cstdint>
#include "../float_uint32.hpp"
namespace ccn {
namespace pteh {
constexpr uint32_t VPN(uint32_t reg) { return (reg >> 10) & 0x3fffff; }
constexpr uint32_t ASID(uint32_t reg) { return (reg >> 0) & 0xff; }
}
namespace ptel {
constexpr uint32_t PPN(uint32_t reg) { return (reg >> 10) & 0x7ffff; }
namespace v {
constexpr uint32_t invalid = 0 << 8;
constexpr uint32_t valid = 1 << 8;
constexpr uint32_t bit_mask = 0x1 << 8;
}
namespace sz {
constexpr uint32_t _1_kbyte_page = 0b0000 << 4;
constexpr uint32_t _4_kbyte_page = 0b0001 << 4;
constexpr uint32_t _64_kbyte_page = 0b1000 << 4;
constexpr uint32_t _1_mbyte_page = 0b1001 << 4;
constexpr uint32_t bit_mask = 0xf << 4;
}
namespace pr {
constexpr uint32_t read_only_in_privileged_mode = 0b00 << 5;
constexpr uint32_t read_write_in_privileged_mode = 0b01 << 5;
constexpr uint32_t read_only_in_privileged_and_user_mode = 0b10 << 5;
constexpr uint32_t read_write_in_privileged_and_user_mode = 0b11 << 5;
constexpr uint32_t bit_mask = 0x3 << 5;
}
namespace c {
constexpr uint32_t not_cacheable = 0 << 3;
constexpr uint32_t cacheable = 1 << 3;
constexpr uint32_t bit_mask = 0x1 << 3;
}
namespace d {
constexpr uint32_t write_has_not_been_performed = 0 << 2;
constexpr uint32_t write_has_been_performed = 1 << 2;
constexpr uint32_t bit_mask = 0x1 << 2;
}
namespace sh {
constexpr uint32_t pages_are_shared_by_processes = 0 << 1;
constexpr uint32_t pages_are_not_shared_by_processes = 1 << 1;
constexpr uint32_t bit_mask = 0x1 << 1;
}
namespace wt {
constexpr uint32_t copy_back_mode = 0 << 0;
constexpr uint32_t write_through_mode = 1 << 0;
constexpr uint32_t bit_mask = 0x1 << 0;
}
}
namespace mmucr {
constexpr uint32_t LRUI(uint32_t reg) { return (reg >> 26) & 0x3f; }
constexpr uint32_t URB(uint32_t reg) { return (reg >> 18) & 0x3f; }
constexpr uint32_t URC(uint32_t reg) { return (reg >> 10) & 0x3f; }
namespace sqmd {
constexpr uint32_t user_privileged_access_possible = 0 << 9;
constexpr uint32_t privileged_access_possible = 1 << 9;
constexpr uint32_t bit_mask = 0x1 << 9;
}
namespace sv {
constexpr uint32_t multiple_virtual_memory_mode = 0 << 8;
constexpr uint32_t single_virtual_memory_mode = 1 << 8;
constexpr uint32_t bit_mask = 0x1 << 8;
}
namespace ti {
constexpr uint32_t invalidate_all_utlb_itlb_bits = 1 << 2;
constexpr uint32_t bit_mask = 0x1 << 2;
}
namespace at {
constexpr uint32_t mmu_disabled = 0 << 0;
constexpr uint32_t mmu_enabled = 1 << 0;
constexpr uint32_t bit_mask = 0x1 << 0;
}
}
namespace basra {
constexpr uint32_t basa(uint32_t num) { return (num & 0xff) << 0; }
}
namespace basrb {
constexpr uint32_t basa(uint32_t num) { return (num & 0xff) << 0; }
}
namespace ccr {
namespace iix {
constexpr uint32_t address_bits_12_5_used_for_ic_entry_selection = 0 << 15;
constexpr uint32_t address_bits_25_and_11_5_used_for_ic_entry_selection = 1 << 15;
constexpr uint32_t bit_mask = 0x1 << 15;
}
namespace ici {
constexpr uint32_t clear_v_bits_of_all_ic_entries = 1 << 11;
constexpr uint32_t bit_mask = 0x1 << 11;
}
namespace ice {
constexpr uint32_t ic_not_used = 0 << 8;
constexpr uint32_t ic_used = 1 << 8;
constexpr uint32_t bit_mask = 0x1 << 8;
}
namespace oix {
constexpr uint32_t address_bits_13_5_used_for_oc_entry_selection = 0 << 7;
constexpr uint32_t address_bits_25_and_12_5_used_for_oc_entry_selection = 1 << 7;
constexpr uint32_t bit_mask = 0x1 << 7;
}
namespace ora {
constexpr uint32_t _16_kbytes_used_as_cache = 0 << 5;
constexpr uint32_t _8_kbytes_used_as_cache_8_kbytes_used_as_ram = 1 << 5;
constexpr uint32_t bit_mask = 0x1 << 5;
}
namespace oci {
constexpr uint32_t clear_v_and_u_bits_of_all_oc_entries = 1 << 3;
constexpr uint32_t bit_mask = 0x1 << 3;
}
namespace cb {
constexpr uint32_t write_through_mode = 0 << 2;
constexpr uint32_t copy_back_mode = 1 << 2;
constexpr uint32_t bit_mask = 0x1 << 2;
}
namespace wt {
constexpr uint32_t copy_back_mode = 0 << 1;
constexpr uint32_t write_through_mode = 1 << 1;
constexpr uint32_t bit_mask = 0x1 << 1;
}
namespace oce {
constexpr uint32_t oc_not_used = 0 << 0;
constexpr uint32_t oc_used = 1 << 0;
constexpr uint32_t bit_mask = 0x1 << 0;
}
}
namespace tra {
constexpr uint32_t imm(uint32_t reg) { return (reg >> 2) & 0xff; }
}
namespace expevt {
constexpr uint32_t exception_code(uint32_t reg) { return (reg >> 0) & 0xfff; }
}
namespace intevt {
constexpr uint32_t exception_code(uint32_t reg) { return (reg >> 0) & 0xfff; }
}
namespace ptea {
namespace tc {
constexpr uint32_t area_5_is_used = 0 << 3;
constexpr uint32_t area_6_is_used = 1 << 3;
constexpr uint32_t bit_mask = 0x1 << 3;
}
namespace sa {
constexpr uint32_t undefined = 0b000 << 0;
constexpr uint32_t variable_size_io_space = 0b001 << 0;
constexpr uint32_t _8_bit_io_space = 0b010 << 0;
constexpr uint32_t _16_bit_io_space = 0b011 << 0;
constexpr uint32_t _8_bit_common_memory_space = 0b100 << 0;
constexpr uint32_t _16_bit_common_memory_space = 0b101 << 0;
constexpr uint32_t _8_bit_attribute_memory_space = 0b110 << 0;
constexpr uint32_t _16_bit_attribute_memory_space = 0b111 << 0;
constexpr uint32_t bit_mask = 0x7 << 0;
}
}
namespace qacr0 {
constexpr uint32_t area(uint32_t num) { return (num & 0x7) << 2; }
}
namespace qacr1 {
constexpr uint32_t area(uint32_t num) { return (num & 0x7) << 2; }
}
}
namespace dmac {
namespace dmatcr {
constexpr uint32_t transfer_count(uint32_t num) { return (num & 0xffffff) << 0; }
}
namespace chcr {
namespace ssa {
constexpr uint32_t reserved_in_pcmcia_access = 0b000 << 29;
constexpr uint32_t dynamic_bus_sizing_io_space = 0b001 << 29;
constexpr uint32_t _8_bit_io_space = 0b010 << 29;
constexpr uint32_t _16_bit_io_space = 0b011 << 29;
constexpr uint32_t _8_bit_common_memory_space = 0b100 << 29;
constexpr uint32_t _16_bit_common_memory_space = 0b101 << 29;
constexpr uint32_t _8_bit_attribute_memory_space = 0b110 << 29;
constexpr uint32_t _16_bit_attribute_memory_space = 0b111 << 29;
constexpr uint32_t bit_mask = 0x7 << 29;
}
namespace stc {
constexpr uint32_t c5_space_wait_cycle_selection = 0 << 28;
constexpr uint32_t c6_space_wait_cycle_selection = 1 << 28;
constexpr uint32_t bit_mask = 0x1 << 28;
}
namespace dsa {
constexpr uint32_t reserved_in_pcmcia_access = 0b000 << 25;
constexpr uint32_t dynamic_bus_sizing_io_space = 0b001 << 25;
constexpr uint32_t _8_bit_io_space = 0b010 << 25;
constexpr uint32_t _16_bit_io_space = 0b011 << 25;
constexpr uint32_t _8_bit_common_memory_space = 0b100 << 25;
constexpr uint32_t _16_bit_common_memory_space = 0b101 << 25;
constexpr uint32_t _8_bit_attribute_memory_space = 0b110 << 25;
constexpr uint32_t _16_bit_attribute_memory_space = 0b111 << 25;
constexpr uint32_t bit_mask = 0x7 << 25;
}
namespace dtc {
constexpr uint32_t c5_space_wait_cycle_selection = 0 << 24;
constexpr uint32_t c6_space_wait_cycle_selection = 1 << 24;
constexpr uint32_t bit_mask = 0x1 << 24;
}
namespace ds {
constexpr uint32_t low_level_detection = 0 << 19;
constexpr uint32_t falling_edge_detection = 1 << 19;
constexpr uint32_t bit_mask = 0x1 << 19;
}
namespace rl {
constexpr uint32_t drak_is_an_active_high = 0 << 18;
constexpr uint32_t drak_is_an_active_low = 1 << 18;
constexpr uint32_t bit_mask = 0x1 << 18;
}
namespace am {
constexpr uint32_t dack_is_output_in_read_cycle = 0 << 17;
constexpr uint32_t dack_is_output_in_write_cycle = 1 << 17;
constexpr uint32_t bit_mask = 0x1 << 17;
}
namespace al {
constexpr uint32_t active_high_output = 0 << 16;
constexpr uint32_t active_low_output = 1 << 16;
constexpr uint32_t bit_mask = 0x1 << 16;
}
namespace dm {
constexpr uint32_t destination_address_fixed = 0b00 << 14;
constexpr uint32_t destination_address_incremented = 0b01 << 14;
constexpr uint32_t destination_address_decremented = 0b10 << 14;
constexpr uint32_t bit_mask = 0x3 << 14;
}
namespace sm {
constexpr uint32_t source_address_fixed = 0b00 << 12;
constexpr uint32_t source_address_incremented = 0b01 << 12;
constexpr uint32_t source_address_decremented = 0b10 << 12;
constexpr uint32_t bit_mask = 0x3 << 12;
}
namespace rs {
constexpr uint32_t resource_select(uint32_t num) { return (num & 0xf) << 8; }
constexpr uint32_t bit_mask = 0xf << 8;
}
namespace tm {
constexpr uint32_t cycle_steal_mode = 0 << 7;
constexpr uint32_t cycle_burst_mode = 1 << 7;
constexpr uint32_t bit_mask = 0x1 << 7;
}
namespace ts {
constexpr uint32_t _64_bit = 0b000 << 4;
constexpr uint32_t _8_bit = 0b001 << 4;
constexpr uint32_t _16_bit = 0b010 << 4;
constexpr uint32_t _32_bit = 0b011 << 4;
constexpr uint32_t _32_byte = 0b100 << 4;
constexpr uint32_t bit_mask = 0x7 << 4;
}
namespace ie {
constexpr uint32_t interrupt_request_not_generated = 0 << 2;
constexpr uint32_t interrupt_request_generated = 1 << 2;
constexpr uint32_t bit_mask = 0x1 << 2;
}
namespace te {
constexpr uint32_t transfers_not_completed = 0 << 1;
constexpr uint32_t transfers_completed = 1 << 1;
constexpr uint32_t bit_mask = 0x1 << 1;
}
namespace de {
constexpr uint32_t channel_operation_disabled = 0 << 0;
constexpr uint32_t channel_operation_enabled = 1 << 0;
constexpr uint32_t bit_mask = 0x1 << 0;
}
}
namespace dmaor {
namespace ddt {
constexpr uint32_t normal_dma_mode = 0 << 15;
constexpr uint32_t on_demand_data_transfer_mode = 1 << 15;
constexpr uint32_t bit_mask = 0x1 << 15;
}
namespace pr {
constexpr uint32_t ch0_ch1_ch2_ch3 = 0b00 << 8;
constexpr uint32_t ch0_ch2_ch3_ch1 = 0b01 << 8;
constexpr uint32_t ch2_ch0_ch1_ch3 = 0b10 << 8;
constexpr uint32_t round_robin = 0b11 << 8;
constexpr uint32_t bit_mask = 0x3 << 8;
}
namespace ae {
constexpr uint32_t no_address_error__dma_transfer_enabled = 0 << 2;
constexpr uint32_t address_error__dma_transfer_disabled = 1 << 2;
constexpr uint32_t bit_mask = 0x1 << 2;
}
namespace nmif {
constexpr uint32_t no_nmi__dma_transfer_enabled = 0 << 1;
constexpr uint32_t nmi__dma_transfer_disabled = 1 << 1;
constexpr uint32_t bit_mask = 0x1 << 1;
}
namespace dme {
constexpr uint32_t operation_disabled_on_all_channels = 0 << 0;
constexpr uint32_t operation_enabled_on_all_channels = 1 << 0;
constexpr uint32_t bit_mask = 0x1 << 0;
}
}
}
namespace intc {
namespace icr {
namespace nmil {
constexpr uint32_t pin_input_level_is_low = 0 << 15;
constexpr uint32_t pin_input_level_is_high = 1 << 15;
constexpr uint32_t bit_mask = 0x1 << 15;
}
namespace mai {
constexpr uint32_t interrupts_enabled_while_nmi_pin_is_low = 0 << 14;
constexpr uint32_t interrupts_disabled_while_nmi_pin_is_low = 1 << 14;
constexpr uint32_t bit_mask = 0x1 << 14;
}
namespace nmib {
constexpr uint32_t interrupt_requests_witheld = 0 << 9;
constexpr uint32_t interrupt_requests_detected = 1 << 9;
constexpr uint32_t bit_mask = 0x1 << 9;
}
namespace nmie {
constexpr uint32_t interrupt_on_falling_edge_of_nmi = 0 << 8;
constexpr uint32_t interrupt_on_rising_edge_of_nmi = 1 << 8;
constexpr uint32_t bit_mask = 0x1 << 8;
}
namespace irlm {
constexpr uint32_t level_encoded_interrupt_requests = 0 << 7;
constexpr uint32_t independent_interrupt_request = 1 << 7;
constexpr uint32_t bit_mask = 0x1 << 7;
}
}
namespace ipra {
constexpr uint32_t TMU0(uint32_t num) { return (num & 0xf) << 12; }
constexpr uint32_t TMU1(uint32_t num) { return (num & 0xf) << 8; }
constexpr uint32_t TMU2(uint32_t num) { return (num & 0xf) << 4; }
constexpr uint32_t RTC(uint32_t num) { return (num & 0xf) << 0; }
}
namespace iprb {
constexpr uint32_t WDT(uint32_t num) { return (num & 0xf) << 12; }
constexpr uint32_t REF(uint32_t num) { return (num & 0xf) << 8; }
constexpr uint32_t SCI1(uint32_t num) { return (num & 0xf) << 4; }
}
namespace iprc {
constexpr uint32_t GPIO(uint32_t num) { return (num & 0xf) << 12; }
constexpr uint32_t DMAC(uint32_t num) { return (num & 0xf) << 8; }
constexpr uint32_t SCIF(uint32_t num) { return (num & 0xf) << 4; }
constexpr uint32_t UDI(uint32_t num) { return (num & 0xf) << 0; }
}
}
namespace tmu {
namespace tocr {
namespace tcoe {
constexpr uint32_t tclk_is_external_clock_or_input_capture = 0 << 0;
constexpr uint32_t tclk_is_on_chip_rtc = 1 << 0;
constexpr uint32_t bit_mask = 0x1 << 0;
}
}
namespace tstr {
namespace str2 {
constexpr uint32_t counter_start = 1 << 2;
constexpr uint32_t bit_mask = 0x1 << 2;
}
namespace str1 {
constexpr uint32_t counter_start = 1 << 1;
constexpr uint32_t bit_mask = 0x1 << 1;
}
namespace str0 {
constexpr uint32_t counter_start = 1 << 0;
constexpr uint32_t bit_mask = 0x1 << 0;
}
}
namespace tcr0 {
constexpr uint32_t UNF = 1 << 8;
constexpr uint32_t UNIE = 1 << 5;
namespace ckeg {
constexpr uint32_t rising = 0b00 << 3;
constexpr uint32_t falling = 0b01 << 3;
constexpr uint32_t rising_falling = 0b10 << 3;
constexpr uint32_t bit_mask = 0x3 << 3;
}
namespace tpsc {
constexpr uint32_t p_phi_4 = 0b000 << 0;
constexpr uint32_t p_phi_16 = 0b001 << 0;
constexpr uint32_t p_phi_64 = 0b010 << 0;
constexpr uint32_t p_phi_256 = 0b011 << 0;
constexpr uint32_t p_phi_1024 = 0b100 << 0;
constexpr uint32_t rtc_output = 0b110 << 0;
constexpr uint32_t external = 0b111 << 0;
constexpr uint32_t bit_mask = 0x7 << 0;
}
}
namespace tcr1 {
constexpr uint32_t UNF = 1 << 8;
constexpr uint32_t UNIE = 1 << 5;
namespace ckeg {
constexpr uint32_t rising = 0b00 << 3;
constexpr uint32_t falling = 0b01 << 3;
constexpr uint32_t rising_falling = 0b10 << 3;
constexpr uint32_t bit_mask = 0x3 << 3;
}
namespace tpsc {
constexpr uint32_t p_phi_4 = 0b000 << 0;
constexpr uint32_t p_phi_16 = 0b001 << 0;
constexpr uint32_t p_phi_64 = 0b010 << 0;
constexpr uint32_t p_phi_256 = 0b011 << 0;
constexpr uint32_t p_phi_1024 = 0b100 << 0;
constexpr uint32_t rtc_output = 0b110 << 0;
constexpr uint32_t external = 0b111 << 0;
constexpr uint32_t bit_mask = 0x7 << 0;
}
}
namespace tcr2 {
constexpr uint32_t ICPF = 1 << 9;
constexpr uint32_t UNF = 1 << 8;
namespace icpe {
constexpr uint32_t disabled = 0b00 << 6;
constexpr uint32_t enabled = 0b10 << 6;
constexpr uint32_t enabled_with_interrupts = 0b11 << 6;
constexpr uint32_t bit_mask = 0x3 << 6;
}
constexpr uint32_t UNIE = 1 << 5;
namespace ckeg {
constexpr uint32_t rising = 0b00 << 3;
constexpr uint32_t falling = 0b01 << 3;
constexpr uint32_t rising_falling = 0b10 << 3;
constexpr uint32_t bit_mask = 0x3 << 3;
}
namespace tpsc {
constexpr uint32_t p_phi_4 = 0b000 << 0;
constexpr uint32_t p_phi_16 = 0b001 << 0;
constexpr uint32_t p_phi_64 = 0b010 << 0;
constexpr uint32_t p_phi_256 = 0b011 << 0;
constexpr uint32_t p_phi_1024 = 0b100 << 0;
constexpr uint32_t rtc_output = 0b110 << 0;
constexpr uint32_t external = 0b111 << 0;
constexpr uint32_t bit_mask = 0x7 << 0;
}
}
}
namespace scif {
namespace scsmr2 {
namespace chr {
constexpr uint32_t _8_bit_data = 0 << 6;
constexpr uint32_t _7_bit_data = 1 << 6;
constexpr uint32_t bit_mask = 0x1 << 6;
}
namespace pe {
constexpr uint32_t parity_disabled = 0 << 5;
constexpr uint32_t parity_enabled = 1 << 5;
constexpr uint32_t bit_mask = 0x1 << 5;
}
namespace oe {
constexpr uint32_t even_parity = 0 << 4;
constexpr uint32_t odd_parity = 1 << 4;
constexpr uint32_t bit_mask = 0x1 << 4;
}
namespace stop {
constexpr uint32_t _1_stop_bit = 0 << 3;
constexpr uint32_t _2_stop_bits = 1 << 3;
constexpr uint32_t bit_mask = 0x1 << 3;
}
namespace cks {
constexpr uint32_t p_phi_clock = 0b00 << 0;
constexpr uint32_t p_phi_4_clock = 0b01 << 0;
constexpr uint32_t p_phi_16_clock = 0b10 << 0;
constexpr uint32_t p_phi_64_clock = 0b11 << 0;
constexpr uint32_t bit_mask = 0x3 << 0;
}
}
namespace scscr2 {
namespace tie {
constexpr uint32_t transmit_fifo_data_empty_interrupt_disabled = 0 << 7;
constexpr uint32_t transmit_fifo_data_empty_interrupt_enabled = 1 << 7;
constexpr uint32_t bit_mask = 0x1 << 7;
}
namespace rie {
constexpr uint32_t request_disabled = 0 << 6;
constexpr uint32_t request_enabled = 1 << 6;
constexpr uint32_t bit_mask = 0x1 << 6;
}
namespace te {
constexpr uint32_t transmission_disabled = 0 << 5;
constexpr uint32_t transmission_enabled = 1 << 5;
constexpr uint32_t bit_mask = 0x1 << 5;
}
namespace re {
constexpr uint32_t reception_disabled = 0 << 4;
constexpr uint32_t reception_enabled = 1 << 4;
constexpr uint32_t bit_mask = 0x1 << 4;
}
namespace reie {
constexpr uint32_t requests_disabled = 0 << 3;
constexpr uint32_t requests_enabled = 1 << 3;
constexpr uint32_t bit_mask = 0x1 << 3;
}
namespace cke1 {
constexpr uint32_t sck2_pin_functions_as_input_pin = 0 << 1;
constexpr uint32_t sck2_pin_functions_as_clock_input = 1 << 1;
constexpr uint32_t bit_mask = 0x1 << 1;
}
}
namespace scfsr2 {
namespace per3_0 {
constexpr uint32_t number_of_parity_errors(uint32_t reg) { return (reg >> 12) & 0xf; }
constexpr uint32_t bit_mask = 0xf << 12;
}
namespace fer3_0 {
constexpr uint32_t number_of_framing_errors(uint32_t reg) { return (reg >> 8) & 0xf; }
constexpr uint32_t bit_mask = 0xf << 8;
}
namespace er {
constexpr uint32_t no_framing_error_or_parity_error = 0 << 7;
constexpr uint32_t framing_error_or_parity_error = 1 << 7;
constexpr uint32_t bit_mask = 0x1 << 7;
}
namespace tend {
constexpr uint32_t transmission_in_progress = 0 << 6;
constexpr uint32_t transmission_has_ended = 1 << 6;
constexpr uint32_t bit_mask = 0x1 << 6;
}
namespace tdfe {
constexpr uint32_t transmit_data_bytes_does_exceed_trigger = 0 << 5;
constexpr uint32_t transmit_data_bytes_does_not_exceed_trigger = 1 << 5;
constexpr uint32_t bit_mask = 0x1 << 5;
}
namespace brk {
constexpr uint32_t break_not_received = 0 << 4;
constexpr uint32_t break_received = 1 << 4;
constexpr uint32_t bit_mask = 0x1 << 4;
}
namespace fer {
constexpr uint32_t no_framing_error = 0 << 3;
constexpr uint32_t framing_error = 1 << 3;
constexpr uint32_t bit_mask = 0x1 << 3;
}
namespace per {
constexpr uint32_t parity_error = 0 << 2;
constexpr uint32_t no_parity_error = 1 << 2;
constexpr uint32_t bit_mask = 0x1 << 2;
}
namespace rdf {
constexpr uint32_t receive_data_bytes_less_than_receive_trigger = 0 << 1;
constexpr uint32_t receive_data_bytes_greater_than_or_equal_receive_trigger = 1 << 1;
constexpr uint32_t bit_mask = 0x1 << 1;
}
namespace dr {
constexpr uint32_t reception_is_in_progress = 0 << 0;
constexpr uint32_t no_further_data_has_arrived = 1 << 0;
constexpr uint32_t bit_mask = 0x1 << 0;
}
}
namespace scfcr2 {
namespace rtrg {
constexpr uint32_t trigger_on_1_byte = 0b00 << 6;
constexpr uint32_t trigger_on_4_bytes = 0b01 << 6;
constexpr uint32_t trigger_on_8_bytes = 0b10 << 6;
constexpr uint32_t trigger_on_14_byte = 0b11 << 6;
constexpr uint32_t bit_mask = 0x3 << 6;
}
namespace ttrg {
constexpr uint32_t trigger_on_8_bytes = 0b00 << 4;
constexpr uint32_t trigger_on_4_bytes = 0b01 << 4;
constexpr uint32_t trigger_on_2_bytes = 0b10 << 4;
constexpr uint32_t trigger_on_1_bytes = 0b11 << 4;
constexpr uint32_t bit_mask = 0x3 << 4;
}
namespace mce {
constexpr uint32_t modem_signals_disabled = 0 << 3;
constexpr uint32_t modem_signals_enabled = 1 << 3;
constexpr uint32_t bit_mask = 0x1 << 3;
}
namespace tfrst {
constexpr uint32_t reset_operation_disabled = 0 << 2;
constexpr uint32_t reset_operation_enabled = 1 << 2;
constexpr uint32_t bit_mask = 0x1 << 2;
}
namespace rfrst {
constexpr uint32_t reset_operation_disabled = 0 << 1;
constexpr uint32_t reset_operation_enabled = 1 << 1;
constexpr uint32_t bit_mask = 0x1 << 1;
}
namespace loop {
constexpr uint32_t loopback_test_disabled = 0 << 0;
constexpr uint32_t loopback_test_enabled = 1 << 0;
constexpr uint32_t bit_mask = 0x1 << 0;
}
}
namespace scfdr2 {
constexpr uint32_t transmit_data_bytes(uint32_t reg) { return (reg >> 8) & 0x1f; }
constexpr uint32_t receive_data_bytes(uint32_t reg) { return (reg >> 0) & 0x1f; }
}
namespace scsptr2 {
namespace rtsio {
constexpr uint32_t rtsdt_not_output_to_rts2 = 0 << 7;
constexpr uint32_t rtsdt_output_to_rts2 = 1 << 7;
constexpr uint32_t bit_mask = 0x1 << 7;
}
namespace rtsdt {
constexpr uint32_t input_output_data_is_low_level = 0 << 6;
constexpr uint32_t input_output_data_is_high_level = 1 << 6;
constexpr uint32_t bit_mask = 0x1 << 6;
}
namespace ctsio {
constexpr uint32_t ctsdt_is_not_output_to_cts2 = 0 << 5;
constexpr uint32_t ctsdt_is_output_to_cts2 = 1 << 5;
constexpr uint32_t bit_mask = 0x1 << 5;
}
namespace ctsdt {
constexpr uint32_t input_output_data_is_low_level = 0 << 4;
constexpr uint32_t input_output_data_is_high_level = 1 << 4;
constexpr uint32_t bit_mask = 0x1 << 4;
}
namespace spb2io {
constexpr uint32_t spb2dt_is_not_output_to_txd2 = 0 << 1;
constexpr uint32_t spb2dt_is_output_to_txd2 = 1 << 1;
constexpr uint32_t bit_mask = 0x1 << 1;
}
namespace spb2dt {
constexpr uint32_t input_output_data_is_low_level = 0 << 0;
constexpr uint32_t input_output_data_is_high_level = 1 << 0;
constexpr uint32_t bit_mask = 0x1 << 0;
}
}
}

View File

@ -1,101 +0,0 @@
#define CCR__IIX (1 << 15)
#define CCR__ICI (1 << 11)
#define CCR__ICE (1 << 8)
#define CCR__OIX (1 << 7)
#define CCR__ORA (1 << 5)
#define CCR__OCI (1 << 4)
#define CCR__CB (1 << 2)
#define CCR__WT (1 << 1)
#define CCR__OCE (1 << 0)
#define PDTRA__MASK (0b11 << 8)
#define PDTRA__VGA (0b00 << 8)
#define PDTRA__RESERVED (0b01 << 8)
#define PDTRA__RGB (0b10 << 8)
#define PDTRA__AV (0b11 << 8)
#define SCFCR2__TFRST (1 << 2)
#define SCFCR2__RFRST (1 << 1)
#define SCSCR2__TE (1 << 5)
#define SCSCR2__RE (1 << 4)
#define SCFSR2__ER (1 << 7) /* read error */
#define SCFSR2__TEND (1 << 6) /* transmit end */
#define SCFSR2__TDFE (1 << 5) /* transmit fifo data empty */
#define SCFSR2__BRK (1 << 4) /* break detect */
#define SCFSR2__FER (1 << 3) /* framing error */
#define SCFSR2__PER (1 << 2) /* parity error */
#define SCFSR2__RDF (1 << 1) /* receive FIFO data full */
#define SCFSR2__DR (1 << 0) /* receive data ready */
#define DMAOR__DDT (1 << 15) /* on-demand data transfer mode */
/* priority mode */
#define DMAOR__PR__CH0_CH1_CH2_CH3 (0b11 << 8)
#define DMAOR__PR__CH0_CH2_CH3_CH1 (0b01 << 8)
#define DMAOR__PR__CH2_CH0_CH1_CH3 (0b10 << 8)
#define DMAOR__PR__ROUND_ROBIN (0b11 << 8)
#define DMAOR__AE (1 << 2) /* address error flag; clear-only */
#define DMAOR__NMIF (1 << 1) /* non-maskable interrupt flag; clear-only */
#define DMAOR__DME (1 << 0) /* DMAC master enable */
/* source address space attribute specification */
#define CHCR2__SSA__RESERVED_IN_PCMCIA_ACCESS (0b000 << 29)
#define CHCR2__SSA__DYNAMIC_BUS_SIZING_IO_SPACE (0b001 << 29)
#define CHCR2__SSA__8BIT_IO_SPACE (0b010 << 29)
#define CHCR2__SSA__16BIT_IO_SPACE (0b011 << 29)
#define CHCR2__SSA__8BIT_COMMON_MEMORY_SPACE (0b100 << 29)
#define CHCR2__SSA__16BIT_COMMON_MEMORY_SPACE (0b101 << 29)
#define CHCR2__SSA__8BIT_ATTRIBUTE_MEMORY_SPACE (0b110 << 29)
#define CHCR2__SSA__16BIT_ATTRIBUTE_MEMORY_SPACE (0b111 << 29)
/* source address wait control select */
#define CHCR2__STC__C5_SPACE_WAIT_CYCLE_SELECTION (0 << 28)
#define CHCR2__STC__C6_SPACE_WAIT_CYCLE_SELECTION (1 << 28)
/* destination address space attribute specification */
#define CHCR2__DSA__RESERVED_IN_PCMCIA_ACCESS (0b000 << 25)
#define CHCR2__DSA__DYNAMIC_BUS_SIZING_IO_SPACE (0b001 << 25)
#define CHCR2__DSA__8BIT_IO_SPACE (0b010 << 25)
#define CHCR2__DSA__16BIT_IO_SPACE (0b011 << 25)
#define CHCR2__DSA__8BIT_COMMON_MEMORY_SPACE (0b100 << 25)
#define CHCR2__DSA__16BIT_COMMON_MEMORY_SPACE (0b101 << 25)
#define CHCR2__DSA__8BIT_ATTRIBUTE_MEMORY_SPACE (0b110 << 25)
#define CHCR2__DSA__16BIT_ATTRIBUTE_MEMORY_SPACE (0b111 << 25)
/* destination address wait control select */
#define CHCR2__DTC__C5_SPACE_WAIT_CYCLE_SELECTION (0 << 24)
#define CHCR2__DTC__C6_SPACE_WAIT_CYCLE_SELECTION (1 << 24)
/* DREQ select */
#define CHCR2__DS__LOW_LEVEL_DETECTION (0 << 19)
#define CHCR2__DS__FALLING_EDGE_DETECTION (1 << 19)
/* request check level */
#define CHCR2__RL__DRAK_IS_AN_ACTIVE_HIGH_OUTPUT (0 << 18)
#define CHCR2__RL__DRAK_IS_AN_ACTIVE_LOW_OUTPUT (1 << 18)
/* acknowledge mode */
#define CHCR2__AM__DACK_IS_OUTPUT_IN_READ_CYCLE (0 << 17)
#define CHCR2__AM__DACK_IS_OUTPUT_IN_WRITE_CYCLE (1 << 17)
/* acknowledge level */
#define CHCR2__AL__ACTIVE_HIGH_OUTPUT (0 << 16)
#define CHCR2__AL__ACTIVE_LOW_OUTPUT (1 << 16)
/* destination address mode */
#define CHCR2__DM__DESTINATION_ADDRESS_FIXED (0b00 << 14)
#define CHCR2__DM__DESTINATION_ADDRESS_INCREMENTED (0b01 << 14)
#define CHCR2__DM__DESTINATION_ADDRESS_DECREMENTED (0b10 << 14)
/* source address mode */
#define CHCR2__SM__SOURCE_ADDRESS_FIXED (0b00 << 12)
#define CHCR2__SM__SOURCE_ADDRESS_INCREMENTED (0b01 << 12)
#define CHCR2__SM__SOURCE_ADDRESS_DECREMENTED (0b10 << 12)
/* resource select */
#define CHCR2__RS(n) (((n) & 0b1111) << 8)
/* transmit mode */
#define CHCR2__TM__CYCLE_STEAL_MODE (0 << 7)
#define CHCR2__TM__BURST_MODE (1 << 7)
/* transmit size */
#define CHCR2__TS__64_BIT (0b000 << 4)
#define CHCR2__TS__8_BIT (0b001 << 4)
#define CHCR2__TS__16_BIT (0b010 << 4)
#define CHCR2__TS__32_BIT (0b011 << 4)
#define CHCR2__TS__32_BYTE (0b100 << 4)
#define CHCR2__IE (1 << 2) /* interrupt enable */
#define CHCR2__TE (1 << 1) /* transfer end; clear only */
#define CHCR2__DE (1 << 0) /* DMAC (channel) enable */
#define DMATCR2__TRANSFER_COUNT(n) (((n) & 0xffffff) << 0)

View File

@ -1,6 +1,7 @@
import math import math
from dataclasses import dataclass from dataclasses import dataclass
import sys import sys
from typing import Union
from generate import renderer from generate import renderer
@ -13,18 +14,30 @@ class Vertex:
y: float y: float
z: float z: float
@dataclass(frozen=True)
class Color:
r: float
g: float
b: float
@dataclass(frozen=True) @dataclass(frozen=True)
class TextureCoordinate: class TextureCoordinate:
u: float u: float
v: float v: float
@dataclass
class VertexNormal:
vertex: int
normal: int
@dataclass @dataclass
class VertexTextureNormal: class VertexTextureNormal:
vertex: int vertex: int
texture: int texture: int
normal: int normal: int
Face = tuple[VertexTextureNormal, VertexTextureNormal, VertexTextureNormal] Face = Union[tuple[VertexTextureNormal, VertexTextureNormal, VertexTextureNormal],
tuple[VertexNormal, VertexNormal, VertexNormal]]
name = None name = None
@ -34,10 +47,17 @@ def parse_object(line):
return name.lower() return name.lower()
def parse_vertex(line): def parse_vertex(line):
h, *xyz = line.split() h, *xyz_rgb = line.split()
assert h == 'v' or h == 'vn' assert h == 'v' or h == 'vn'
assert len(xyz) == 3 if h == 'vn':
return Vertex(*map(float, xyz)) assert len(xyz_rgb) == 3
if h == 'v':
assert len(xyz_rgb) == 6 or len(xyz_rgb) == 3
coords = list(map(float, xyz_rgb))
if len(xyz_rgb) == 6:
return Vertex(*coords[0:3]), Color(*coords[3:6])
else:
return Vertex(*coords[0:3])
def parse_texture_coordinate(line): def parse_texture_coordinate(line):
h, *uv = line.split() h, *uv = line.split()
@ -47,7 +67,7 @@ def parse_texture_coordinate(line):
def maybe_int(i, offset): def maybe_int(i, offset):
if i.strip() == "": if i.strip() == "":
assert False return None
else: else:
return int(i) + offset return int(i) + offset
@ -62,14 +82,36 @@ def parse_face(line):
maybe_int(iix, offset=-1) maybe_int(iix, offset=-1)
for iix in ix for iix in ix
] ]
assert vertex_ix is not None
assert normal_ix is not None
if uv_ix is None:
return VertexNormal(vertex_ix, normal_ix)
else:
return VertexTextureNormal(vertex_ix, uv_ix, normal_ix) return VertexTextureNormal(vertex_ix, uv_ix, normal_ix)
return tuple(map(parse_ixs, tri)) return tuple(map(parse_ixs, tri))
def vertex_type(vertices):
types = set(type(v) for v in vertices)
assert len(types) == 1, types
if type(vertices[0]) is tuple:
return "position__color"
elif type(vertices[0]) is Vertex:
return "vec3"
else:
assert False, type(verticies[0])
def generate_vertices(vertices): def generate_vertices(vertices):
yield "constexpr vec3 vertices[] = {" type_str = vertex_type(vertices)
for v in vertices: yield f"constexpr {type_str} vertices[] = {{"
yield f"{{ {v.x:9f}f, {v.y:9f}f, {v.z:9f}f }}," for p_c in vertices:
if type(p_c) is tuple:
p, c = p_c
yield f"{{ {{{p.x:9f}f, {p.y:9f}f, {p.z:9f}f}}, {{{c.r:9f}f, {c.g:9f}f, {c.b:9f}f}} }},"
else:
assert type(p_c) is Vertex
p = p_c
yield f"{{ {p.x:9f}f, {p.y:9f}f, {p.z:9f}f }},"
yield "};" yield "};"
yield "" yield ""
@ -87,26 +129,42 @@ def generate_texture_coordinates(texture_coordinates):
yield "};" yield "};"
yield "" yield ""
def generate_faces(faces): def face_type_str(face_type):
if face_type is VertexNormal:
return "face_vn"
elif face_type is VertexTextureNormal:
return "face_vtn"
else:
assert False, face_type
def generate_faces(faces, face_type):
def face_coords(vtn):
if face_type is VertexNormal:
return [vtn.vertex, vtn.normal]
elif face_type is VertexTextureNormal:
return [vtn.vertex, vtn.texture, vtn.normal]
else:
assert False, face_type
max_ix = max( max_ix = max(
i i
for f in faces for f in faces
for vtn in f for vtn in f
for i in [vtn.vertex, vtn.texture, vtn.normal] for i in face_coords(vtn)
) )
align = 1 + math.floor(math.log(max_ix) / math.log(10)) align = 1 + math.floor(math.log(max_ix) / math.log(10))
yield "constexpr face faces[] = {" type_str = face_type_str(face_type)
yield f"constexpr {type_str} faces[] = {{"
def align_vtn(vtn): def align_vtn(vtn):
return ", ".join(str(ix).rjust(align) for ix in [vtn.vertex, vtn.texture, vtn.normal]) return ", ".join(str(ix).rjust(align) for ix in face_coords(vtn))
for f in faces: for f in faces:
inner = ", ".join(f"{{{align_vtn(vtn)}}}" for vtn in f) inner = ", ".join(f"{{{align_vtn(vtn)}}}" for vtn in f)
yield f"{{{inner}}}," yield f"{{{inner}}},"
yield "};" yield "};"
yield "" yield ""
yield "constexpr uint32_t num_faces = (sizeof (faces)) / (sizeof (face));" yield f"constexpr uint32_t num_faces = (sizeof (faces)) / (sizeof ({type_str}));"
yield "" yield ""
def generate_namespace(vertices, texture_coordinates, normals, faces): def generate_namespace(vertices, texture_coordinates, normals, faces, face_type):
global name global name
assert name is not None assert name is not None
yield "#pragma once" yield "#pragma once"
@ -116,9 +174,10 @@ def generate_namespace(vertices, texture_coordinates, normals, faces):
yield f"namespace {name} {{" yield f"namespace {name} {{"
yield from generate_vertices(vertices) yield from generate_vertices(vertices)
if texture_coordinates != []:
yield from generate_texture_coordinates(texture_coordinates) yield from generate_texture_coordinates(texture_coordinates)
yield from generate_normals(normals) yield from generate_normals(normals)
yield from generate_faces(faces) yield from generate_faces(faces, face_type)
yield "}" yield "}"
@ -163,10 +222,14 @@ def main():
else: else:
pass pass
face_types = set(type(vtn) for f in faces for vtn in f)
assert len(face_types) == 1, face_types
face_type = next(iter(face_types))
if face_type is VertexTextureNormal:
texture_coordinates, faces = merge_texture_coordinates(texture_coordinates, faces) texture_coordinates, faces = merge_texture_coordinates(texture_coordinates, faces)
render, out = renderer() render, out = renderer()
render(generate_namespace(vertices, texture_coordinates, normals, faces)) render(generate_namespace(vertices, texture_coordinates, normals, faces, face_type))
sys.stdout.write(out.getvalue()) sys.stdout.write(out.getvalue())
if __name__ == '__main__': if __name__ == '__main__':

14
vga.cpp
View File

@ -1,8 +1,8 @@
#include <cstdint> #include <cstdint>
#include "sh7091.hpp" #include "sh7091/sh7091.hpp"
#include "sh7091_bits.hpp" #include "sh7091/sh7091_bits.hpp"
#include "holly.hpp" #include "holly/holly.hpp"
#include "holly/core_bits.hpp" #include "holly/core_bits.hpp"
#include "aica.hpp" #include "aica.hpp"
#include "memorymap.hpp" #include "memorymap.hpp"
@ -10,14 +10,16 @@
#include "vga.hpp" #include "vga.hpp"
#include "rgb.hpp" #include "rgb.hpp"
/*
uint32_t get_cable_type() uint32_t get_cable_type()
{ {
/* set all pins to input */ // set all pins to input
sh7091.BSC.PCTRA = 0; sh7091.BSC.PCTRA = 0;
/* get cable type from pins 9 + 8 */ // get cable type from pins 9 + 8
return sh7091.BSC.PDTRA & PDTRA__MASK; return sh7091.BSC.PDTRA & PDTRA__MASK;
} }
*/
void vga1() void vga1()
{ {
@ -117,8 +119,6 @@ void v_sync_out()
void vga() void vga()
{ {
get_cable_type();
holly.SOFTRESET = softreset::sdram_if_soft_reset holly.SOFTRESET = softreset::sdram_if_soft_reset
| softreset::pipeline_soft_reset | softreset::pipeline_soft_reset
| softreset::ta_soft_reset; | softreset::ta_soft_reset;

View File

@ -0,0 +1,15 @@
#include "geometry/geometry.hpp"
namespace screen_space {
constexpr mat4x4 transformation_matrix(const float d, // the z-coordinate of the view window and the near clip plane
const float f, // the z-coordnate of the far clip plane
const float h // the dimension of the square view window
)
{
return { d/h, 0.f, 0.f , 0.f ,
0.f, d/h, 0.f , 0.f ,
0.f, 0.f, f/(f-d), -d*f/(f-d),
0.f, 0.f, 1.f , 0.f };
}
}

View File

@ -0,0 +1,44 @@
#include "geometry/geometry.hpp"
namespace view_space {
constexpr vec3 viewing_direction(const float azimuth,
const float colatitude
)
{
const float x = sin(colatitude) * cos(azimuth);
const float y = sin(colatitude) * sin(azimuth);
const float z = cos(colatitude);
return {x, y, z};
}
constexpr vec3 project_vector_to_plane(const vec3& n, // N: plane normal
const vec3& v_ // V': approximate "up" orientation
)
{
return v_ - dot(v_, n) * n;
}
constexpr mat4x4 transformation_matrix(const vec3& c, // C: in world space, the position of the viewer
const vec3& n, // N: in world space, the viewing direction
const vec3& v_ // V': approximate "up" orientation
)
{
const vec3 v = project_vector_to_plane(n, v_);
const vec3 u = cross(n, v);
const mat4x4 t = { 1.f, 0.f, 0.f, -c.x,
0.f, 1.f, 0.f, -c.y,
0.f, 0.f, 1.f, -c.z,
0.f, 0.f, 0.f, 1.f };
const mat4x4 r = { u.x, u.y, u.z, 0.f,
v.x, v.y, v.z, 0.f,
n.x, n.y, n.z, 0.f,
0.f, 0.f, 0.f, 1.f };
return r * t;
}
}

254
wolf.data Normal file

File diff suppressed because one or more lines are too long

5
wolf.hpp Normal file
View File

@ -0,0 +1,5 @@
#include <cstdint>
extern uint32_t _binary_wolf_data_start __asm("_binary_wolf_data_start");
extern uint32_t _binary_wolf_data_end __asm("_binary_wolf_data_end");
extern uint32_t _binary_wolf_data_size __asm("_binary_wolf_data_size");

BIN
wolf.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 575 KiB