example: add game_of_life
This commit is contained in:
parent
8bde5aaafa
commit
d09f032588
@ -1212,3 +1212,26 @@ STRIP_BUFFER_OBJ = \
|
||||
|
||||
example/strip_buffer.elf: LDSCRIPT = $(LIB)/main.lds
|
||||
example/strip_buffer.elf: $(START_OBJ) $(STRIP_BUFFER_OBJ)
|
||||
|
||||
GAME_OF_LIFE_OBJ = \
|
||||
example/game_of_life.o \
|
||||
holly/core.o \
|
||||
holly/region_array.o \
|
||||
holly/background.o \
|
||||
holly/ta_fifo_polygon_converter.o \
|
||||
holly/video_output.o \
|
||||
sh7091/serial.o \
|
||||
maple/maple.o \
|
||||
sh7091/c_serial.o \
|
||||
printf/printf.o \
|
||||
printf/unparse.o \
|
||||
printf/parse.o \
|
||||
texture/game_of_life/dead.data.o \
|
||||
texture/game_of_life/live1.data.o \
|
||||
texture/game_of_life/live2.data.o \
|
||||
texture/game_of_life/live3.data.o \
|
||||
texture/game_of_life/live4.data.o \
|
||||
$(LIBGCC)
|
||||
|
||||
example/game_of_life.elf: LDSCRIPT = $(LIB)/main.lds
|
||||
example/game_of_life.elf: $(START_OBJ) $(GAME_OF_LIFE_OBJ)
|
||||
|
809
example/game_of_life.cpp
Normal file
809
example/game_of_life.cpp
Normal file
@ -0,0 +1,809 @@
|
||||
#include <bit>
|
||||
|
||||
#include "holly/background.hpp"
|
||||
#include "holly/core.hpp"
|
||||
#include "holly/core_bits.hpp"
|
||||
#include "holly/holly.hpp"
|
||||
#include "holly/isp_tsp.hpp"
|
||||
#include "holly/region_array.hpp"
|
||||
#include "holly/ta_bits.hpp"
|
||||
#include "holly/ta_fifo_polygon_converter.hpp"
|
||||
#include "holly/ta_global_parameter.hpp"
|
||||
#include "holly/ta_parameter.hpp"
|
||||
#include "holly/ta_vertex_parameter.hpp"
|
||||
#include "holly/texture_memory_alloc7.hpp"
|
||||
#include "holly/video_output.hpp"
|
||||
|
||||
#include "systembus.hpp"
|
||||
#include "systembus_bits.hpp"
|
||||
|
||||
#include "maple/maple.hpp"
|
||||
#include "maple/maple_host_command_writer.hpp"
|
||||
#include "maple/maple_bus_bits.hpp"
|
||||
#include "maple/maple_bus_commands.hpp"
|
||||
#include "maple/maple_bus_ft0.hpp"
|
||||
|
||||
#include "memorymap.hpp"
|
||||
|
||||
#include "sh7091/sh7091.hpp"
|
||||
#include "sh7091/sh7091_bits.hpp"
|
||||
#include "sh7091/serial.hpp"
|
||||
#include "printf/printf.h"
|
||||
|
||||
#include "math/float_types.hpp"
|
||||
#include "math/transform.hpp"
|
||||
|
||||
#include "interrupt.hpp"
|
||||
#include "assert.h"
|
||||
|
||||
#include "texture/game_of_life/dead.data.h"
|
||||
#include "texture/game_of_life/live1.data.h"
|
||||
#include "texture/game_of_life/live2.data.h"
|
||||
#include "texture/game_of_life/live3.data.h"
|
||||
#include "texture/game_of_life/live4.data.h"
|
||||
|
||||
const int max_knot_segments = 32;
|
||||
const int max_knot_rings = 256;
|
||||
int knot_segments = 32;
|
||||
int knot_rings = 256;
|
||||
vec3 _knot_center[max_knot_rings];
|
||||
vec3 _knot_ring[max_knot_rings][max_knot_segments];
|
||||
//vec3 t_knot_center[max_knot_rings];
|
||||
vec3 t_knot_ring[max_knot_rings][max_knot_segments];
|
||||
|
||||
static inline vec3 knot(const float t)
|
||||
{
|
||||
float x = sin(t) + 2 * sin(2 * t);
|
||||
float y = cos(t) - 2 * cos(2 * t);
|
||||
float z = -sin(3 * t);
|
||||
return {x, y, z};
|
||||
}
|
||||
|
||||
static inline vec3 rodrigues_rotation(const vec3 v, const vec3 k, const float t)
|
||||
{
|
||||
return v * cos(t) + cross(k, v) * sin(t) + k * dot(k, v) * (1 - cos(t));
|
||||
}
|
||||
|
||||
static inline void radial_segments(const vec3 a,
|
||||
const vec3 n0,
|
||||
const vec3 n,
|
||||
const int segments,
|
||||
vec3 * radial_surface)
|
||||
{
|
||||
for (int i = 0; i < segments; i++) {
|
||||
float t = ((float)i / (float)segments) * 2.f * pi;
|
||||
vec3 rn = rodrigues_rotation(n, n0, t);
|
||||
rn = normalize(rn);
|
||||
radial_surface[i] = a + rn * 0.6f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static inline vec3 knot_center(const float i, const float rings)
|
||||
{
|
||||
float t = (i / rings) * 2.f * pi;
|
||||
vec3 center = knot(t);
|
||||
return center;
|
||||
}
|
||||
|
||||
void knot_edges(const int rings, const int segments)
|
||||
{
|
||||
for (int i = 0; i < rings; i++) {
|
||||
vec3 center = knot_center(i, rings);
|
||||
_knot_center[i] = center;
|
||||
}
|
||||
|
||||
for (int i = 0; i < rings; i++) {
|
||||
int ip = (i + 1) & (rings - 1);
|
||||
int im = (i - 1) & (rings - 1);
|
||||
|
||||
const vec3& a = _knot_center[i];
|
||||
const vec3& b = _knot_center[ip];
|
||||
const vec3& c = _knot_center[im];
|
||||
|
||||
vec3 n0 = ((b - a) + (a - c)) * 0.5f;
|
||||
n0 = normalize(n0);
|
||||
vec3 n = cross(n0, -a);
|
||||
n = normalize(n);
|
||||
|
||||
radial_segments(a, n0, n, segments, &_knot_ring[i][0]);
|
||||
}
|
||||
}
|
||||
|
||||
struct grid {
|
||||
int width;
|
||||
int height;
|
||||
int generation;
|
||||
uint8_t * data[2];
|
||||
};
|
||||
|
||||
static inline int grid_get(grid const * const grid, int x, int y)
|
||||
{
|
||||
x = x & (grid->width - 1);
|
||||
y = y & (grid->height - 1);
|
||||
int gen = grid->generation & 1;
|
||||
|
||||
return grid->data[gen][y * grid->width + x];
|
||||
}
|
||||
|
||||
static inline void grid_put(grid * const grid, int x, int y, int value)
|
||||
{
|
||||
x = x & (grid->width - 1);
|
||||
y = y & (grid->height - 1);
|
||||
int gen = !(grid->generation & 1);
|
||||
|
||||
grid->data[gen][y * grid->width + x] = value;
|
||||
}
|
||||
|
||||
static inline int count_neighbors(grid const * const grid, int x, int y)
|
||||
{
|
||||
int count = 0;
|
||||
count += grid_get(grid, x - 1, y - 1) != 0;
|
||||
count += grid_get(grid, x - 0, y - 1) != 0;
|
||||
count += grid_get(grid, x + 1, y - 1) != 0;
|
||||
count += grid_get(grid, x - 1, y - 0) != 0;
|
||||
//count += grid_get(grid, x - 0, y - 0) != 0;
|
||||
count += grid_get(grid, x + 1, y - 0) != 0;
|
||||
count += grid_get(grid, x - 1, y + 1) != 0;
|
||||
count += grid_get(grid, x - 0, y + 1) != 0;
|
||||
count += grid_get(grid, x + 1, y + 1) != 0;
|
||||
return count;
|
||||
}
|
||||
|
||||
static inline void apply_rule(grid * grid, int x, int y)
|
||||
{
|
||||
int live = grid_get(grid, x, y);
|
||||
int count = count_neighbors(grid, x, y);
|
||||
if (live > 0) {
|
||||
if (count < 2)
|
||||
live = 0;
|
||||
else if (count > 3)
|
||||
live = 0;
|
||||
else if (live < 4)
|
||||
live += 1;
|
||||
} else {
|
||||
if (count == 3)
|
||||
live = 1;
|
||||
}
|
||||
grid_put(grid, x, y, live);
|
||||
}
|
||||
|
||||
void grid_generation(grid * grid)
|
||||
{
|
||||
for (int y = 0; y < grid->height; y++) {
|
||||
for (int x = 0; x < grid->width; x++) {
|
||||
apply_rule(grid, x, y);
|
||||
}
|
||||
}
|
||||
grid->generation += 1;
|
||||
}
|
||||
|
||||
void seed_grid(grid * grid, int xo, int yo)
|
||||
{
|
||||
static const uint8_t seed[] = {
|
||||
0, 1, 0,
|
||||
1, 1, 0,
|
||||
0, 1, 1,
|
||||
};
|
||||
|
||||
const int seed_width = 3;
|
||||
const int seed_height = 3;
|
||||
|
||||
for (int y = 0; y < grid->height; y++) {
|
||||
for (int x = 0; x < grid->width; x++) {
|
||||
if (y < seed_height && x < seed_width) {
|
||||
grid_put(grid, xo + x, yo + y, seed[y * seed_width + x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static ft0::data_transfer::data_format data[4];
|
||||
|
||||
uint8_t send_buf[1024] __attribute__((aligned(32)));
|
||||
uint8_t recv_buf[1024] __attribute__((aligned(32)));
|
||||
|
||||
void do_get_condition()
|
||||
{
|
||||
auto writer = maple::host_command_writer(send_buf, recv_buf);
|
||||
|
||||
using command_type = maple::get_condition;
|
||||
using response_type = maple::data_transfer<ft0::data_transfer::data_format>;
|
||||
|
||||
auto [host_command, host_response]
|
||||
= writer.append_command_all_ports<command_type, response_type>();
|
||||
|
||||
for (int port = 0; port < 4; port++) {
|
||||
auto& data_fields = host_command[port].bus_data.data_fields;
|
||||
data_fields.function_type = std::byteswap(function_type::controller);
|
||||
}
|
||||
maple::dma_start(send_buf, writer.send_offset,
|
||||
recv_buf, writer.recv_offset);
|
||||
|
||||
for (uint8_t port = 0; port < 4; port++) {
|
||||
auto& bus_data = host_response[port].bus_data;
|
||||
if (bus_data.command_code != response_type::command_code) {
|
||||
return;
|
||||
}
|
||||
auto& data_fields = bus_data.data_fields;
|
||||
if ((std::byteswap(data_fields.function_type) & function_type::controller) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
data[port].digital_button = data_fields.data.digital_button;
|
||||
for (int i = 0; i < 6; i++) {
|
||||
data[port].analog_coordinate_axis[i]
|
||||
= data_fields.data.analog_coordinate_axis[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void vbr100()
|
||||
{
|
||||
serial::string("vbr100\n");
|
||||
interrupt_exception();
|
||||
}
|
||||
|
||||
void vbr400()
|
||||
{
|
||||
serial::string("vbr400\n");
|
||||
interrupt_exception();
|
||||
}
|
||||
|
||||
const int framebuffer_width = 640;
|
||||
const int framebuffer_height = 480;
|
||||
const int tile_width = framebuffer_width / 32;
|
||||
const int tile_height = framebuffer_height / 32;
|
||||
|
||||
constexpr uint32_t ta_alloc = 0
|
||||
| ta_alloc_ctrl::pt_opb::no_list
|
||||
| ta_alloc_ctrl::tm_opb::no_list
|
||||
| ta_alloc_ctrl::t_opb::_32x4byte
|
||||
| ta_alloc_ctrl::om_opb::no_list
|
||||
| ta_alloc_ctrl::o_opb::no_list
|
||||
;
|
||||
|
||||
constexpr int ta_cont_count = 1;
|
||||
constexpr struct opb_size opb_size[ta_cont_count] = {
|
||||
{
|
||||
.opaque = 0,
|
||||
.opaque_modifier = 0,
|
||||
.translucent = 32 * 4,
|
||||
.translucent_modifier = 0,
|
||||
.punch_through = 0
|
||||
}
|
||||
};
|
||||
|
||||
static volatile int ta_in_use = 0;
|
||||
static volatile int core_in_use = 0;
|
||||
static volatile int next_frame = 0;
|
||||
static volatile int framebuffer_ix = 0;
|
||||
static volatile int next_frame_ix = 0;
|
||||
|
||||
static inline void pump_events(uint32_t istnrm)
|
||||
{
|
||||
if (istnrm & istnrm::v_blank_in) {
|
||||
system.ISTNRM = istnrm::v_blank_in;
|
||||
|
||||
next_frame = 1;
|
||||
holly.FB_R_SOF1 = texture_memory_alloc.framebuffer[next_frame_ix].start;
|
||||
}
|
||||
|
||||
if (istnrm & istnrm::end_of_render_tsp) {
|
||||
system.ISTNRM = istnrm::end_of_render_tsp
|
||||
| istnrm::end_of_render_isp
|
||||
| istnrm::end_of_render_video;
|
||||
|
||||
next_frame_ix = framebuffer_ix;
|
||||
framebuffer_ix += 1;
|
||||
if (framebuffer_ix >= 3) framebuffer_ix = 0;
|
||||
|
||||
core_in_use = 0;
|
||||
}
|
||||
|
||||
if (istnrm & istnrm::end_of_transferring_translucent_list) {
|
||||
system.ISTNRM = istnrm::end_of_transferring_translucent_list;
|
||||
|
||||
core_in_use = 1;
|
||||
|
||||
holly.FB_W_SOF1 = texture_memory_alloc.framebuffer[framebuffer_ix].start;
|
||||
holly.STARTRENDER = 1;
|
||||
|
||||
ta_in_use = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void vbr600()
|
||||
{
|
||||
uint32_t sr;
|
||||
asm volatile ("stc sr,%0" : "=r" (sr));
|
||||
sr |= sh::sr::imask(15);
|
||||
asm volatile ("ldc %0,sr" : : "r" (sr));
|
||||
|
||||
if (sh7091.CCN.EXPEVT == 0 && sh7091.CCN.INTEVT == 0x320) {
|
||||
uint32_t istnrm = system.ISTNRM;
|
||||
uint32_t isterr = system.ISTERR;
|
||||
|
||||
if (isterr) {
|
||||
serial::string("isterr: ");
|
||||
serial::integer<uint32_t>(isterr);
|
||||
if (isterr & 1) {
|
||||
system.ISTERR = 1;
|
||||
}
|
||||
}
|
||||
|
||||
pump_events(istnrm);
|
||||
|
||||
sr &= ~sh::sr::imask(15);
|
||||
asm volatile ("ldc %0,sr" : : "r" (sr));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
serial::string("vbr600\n");
|
||||
interrupt_exception();
|
||||
}
|
||||
|
||||
void global_polygon_type_0(ta_parameter_writer& writer,
|
||||
uint32_t para_control_obj_control
|
||||
)
|
||||
{
|
||||
const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
|
||||
| obj_control::col_type::floating_color
|
||||
| obj_control::gouraud
|
||||
| para_control_obj_control
|
||||
;
|
||||
|
||||
const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater_or_equal
|
||||
| isp_tsp_instruction_word::culling_mode::no_culling
|
||||
;
|
||||
|
||||
uint32_t tsp_instruction_word = tsp_instruction_word::fog_control::no_fog
|
||||
| tsp_instruction_word::src_alpha_instr::one
|
||||
| tsp_instruction_word::dst_alpha_instr::zero
|
||||
| tsp_instruction_word::texture_shading_instruction::decal
|
||||
;
|
||||
|
||||
uint32_t texture_control_word = 0;
|
||||
|
||||
writer.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,
|
||||
0);
|
||||
}
|
||||
|
||||
void global_polygon_type_0_packed(ta_parameter_writer& writer,
|
||||
uint32_t para_control_obj_control,
|
||||
int ix
|
||||
)
|
||||
{
|
||||
const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
|
||||
| obj_control::col_type::packed_color
|
||||
| obj_control::texture
|
||||
| para_control_obj_control
|
||||
;
|
||||
|
||||
const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater_or_equal
|
||||
| isp_tsp_instruction_word::culling_mode::no_culling
|
||||
;
|
||||
|
||||
uint32_t tsp_instruction_word = tsp_instruction_word::fog_control::no_fog
|
||||
| tsp_instruction_word::src_alpha_instr::src_alpha
|
||||
| tsp_instruction_word::dst_alpha_instr::inverse_src_alpha
|
||||
| tsp_instruction_word::texture_shading_instruction::decal
|
||||
| tsp_instruction_word::texture_u_size::from_int(32)
|
||||
| tsp_instruction_word::texture_v_size::from_int(32)
|
||||
| tsp_instruction_word::filter_mode::bilinear_filter
|
||||
;
|
||||
|
||||
uint32_t texture_address = texture_memory_alloc.texture.start + (32 * 32 * 2) * ix;
|
||||
uint32_t texture_control_word = texture_control_word::pixel_format::_1555
|
||||
| texture_control_word::scan_order::twiddled
|
||||
| texture_control_word::texture_address(texture_address / 8)
|
||||
;
|
||||
|
||||
writer.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,
|
||||
0);
|
||||
}
|
||||
|
||||
static inline void render_quad(ta_parameter_writer& writer,
|
||||
vec3 ap,
|
||||
vec3 bp,
|
||||
vec3 cp,
|
||||
vec3 dp,
|
||||
vec3 ac,
|
||||
vec3 bc,
|
||||
vec3 cc,
|
||||
vec3 dc)
|
||||
{
|
||||
if (ap.z < 0 || bp.z < 0 || cp.z < 0 || dp.z < 0)
|
||||
return;
|
||||
|
||||
writer.append<ta_vertex_parameter::polygon_type_1>() =
|
||||
ta_vertex_parameter::polygon_type_1(polygon_vertex_parameter_control_word(false),
|
||||
ap.x, ap.y, ap.z,
|
||||
1, ac.r, ac.g, ac.b);
|
||||
|
||||
writer.append<ta_vertex_parameter::polygon_type_1>() =
|
||||
ta_vertex_parameter::polygon_type_1(polygon_vertex_parameter_control_word(false),
|
||||
bp.x, bp.y, bp.z,
|
||||
1, bc.r, bc.g, bc.b);
|
||||
|
||||
writer.append<ta_vertex_parameter::polygon_type_1>() =
|
||||
ta_vertex_parameter::polygon_type_1(polygon_vertex_parameter_control_word(false),
|
||||
dp.x, dp.y, dp.z,
|
||||
1, dc.r, dc.g, dc.b);
|
||||
|
||||
writer.append<ta_vertex_parameter::polygon_type_1>() =
|
||||
ta_vertex_parameter::polygon_type_1(polygon_vertex_parameter_control_word(true),
|
||||
cp.x, cp.y, cp.z,
|
||||
1, cc.r, cc.g, cc.b);
|
||||
}
|
||||
|
||||
static inline void render_quad2(ta_parameter_writer& writer,
|
||||
vec3 ap,
|
||||
vec3 bp,
|
||||
vec3 cp,
|
||||
vec3 dp)
|
||||
{
|
||||
if (ap.z < 0 || bp.z < 0 || cp.z < 0 || dp.z < 0)
|
||||
return;
|
||||
|
||||
writer.append<ta_vertex_parameter::polygon_type_3>() =
|
||||
ta_vertex_parameter::polygon_type_3(polygon_vertex_parameter_control_word(false),
|
||||
ap.x, ap.y, ap.z,
|
||||
0, 0,
|
||||
0, 0);
|
||||
|
||||
writer.append<ta_vertex_parameter::polygon_type_3>() =
|
||||
ta_vertex_parameter::polygon_type_3(polygon_vertex_parameter_control_word(false),
|
||||
bp.x, bp.y, bp.z,
|
||||
0, 1,
|
||||
0, 0);
|
||||
|
||||
writer.append<ta_vertex_parameter::polygon_type_3>() =
|
||||
ta_vertex_parameter::polygon_type_3(polygon_vertex_parameter_control_word(false),
|
||||
dp.x, dp.y, dp.z,
|
||||
1, 0,
|
||||
0, 0);
|
||||
|
||||
writer.append<ta_vertex_parameter::polygon_type_3>() =
|
||||
ta_vertex_parameter::polygon_type_3(polygon_vertex_parameter_control_word(true),
|
||||
cp.x, cp.y, cp.z,
|
||||
1, 1,
|
||||
0, 0);
|
||||
}
|
||||
|
||||
static inline vec3 screen_transform(vec3 v)
|
||||
{
|
||||
float dim = 480 / 2.0;
|
||||
|
||||
return {
|
||||
v.x / (1.f * v.z) * dim + 640 / 2.0f,
|
||||
v.y / (1.f * v.z) * dim + 480 / 2.0f,
|
||||
1 / v.z,
|
||||
};
|
||||
}
|
||||
|
||||
static int last_value = -1;
|
||||
|
||||
static inline void transfer_knot_face(ta_parameter_writer& writer, const grid * grid, int r0, int r1, int s0, int s1)
|
||||
{
|
||||
// x, y
|
||||
int value = grid_get(grid, r0, s0);
|
||||
|
||||
if (last_value != value) {
|
||||
global_polygon_type_0_packed(writer,
|
||||
para_control::list_type::translucent,
|
||||
value);
|
||||
last_value = value;
|
||||
}
|
||||
|
||||
render_quad2(writer,
|
||||
t_knot_ring[r0][s0],
|
||||
t_knot_ring[r0][s1],
|
||||
t_knot_ring[r1][s1],
|
||||
t_knot_ring[r1][s0]);
|
||||
}
|
||||
|
||||
static inline void transfer_knot_inner(ta_parameter_writer& writer, const grid * grid, int r0, int r1)
|
||||
{
|
||||
for (int s0 = 0; s0 < knot_segments - 1; s0++) {
|
||||
int s1 = s0 + 1;
|
||||
transfer_knot_face(writer, grid, r0, r1, s0, s1);
|
||||
}
|
||||
transfer_knot_face(writer, grid, r0, r1, knot_segments - 1, 0);
|
||||
}
|
||||
|
||||
void transfer_knot(ta_parameter_writer& writer, mat4x4& trans, const grid * grid)
|
||||
{
|
||||
for (int i = 0; i < knot_rings; i++) {
|
||||
//t_knot_center[i] = screen_transform(trans * _knot_center[i]);
|
||||
for (int j = 0; j < knot_segments; j++) {
|
||||
t_knot_ring[i][j] = screen_transform(trans * _knot_ring[i][j]);
|
||||
}
|
||||
}
|
||||
|
||||
for (int r0 = 0; r0 < knot_rings - 1; r0++) {
|
||||
int r1 = r0 + 1;
|
||||
transfer_knot_inner(writer, grid, r0, r1);
|
||||
}
|
||||
transfer_knot_inner(writer, grid, knot_rings - 1, 0);
|
||||
}
|
||||
|
||||
void transfer_grid(ta_parameter_writer& writer, const grid * grid)
|
||||
{
|
||||
float dim = 10;
|
||||
|
||||
for (int y = 0; y < grid->height; y++) {
|
||||
for (int x = 0; x < grid->width; x++) {
|
||||
int value = grid_get(grid, x, y);
|
||||
if (!value)
|
||||
continue;
|
||||
|
||||
float fx = x;
|
||||
float fx1 = x + 1;
|
||||
float fy = y;
|
||||
float fy1 = y + 1;
|
||||
|
||||
vec3 a = {dim * fx , dim * fy , 0.001f};
|
||||
vec3 b = {dim * fx1, dim * fy , 0.001f};
|
||||
vec3 c = {dim * fx1, dim * fy1, 0.001f};
|
||||
vec3 d = {dim * fx , dim * fy1, 0.001f};
|
||||
|
||||
mat4x4 r = translate((vec3){20, 20, 0});
|
||||
vec3 color = {1, 1, 1};
|
||||
render_quad(writer,
|
||||
r * a,
|
||||
r * b,
|
||||
r * c,
|
||||
r * d,
|
||||
color,
|
||||
color,
|
||||
color,
|
||||
color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void transfer_scene(ta_parameter_writer& writer, grid * grid, mat4x4& trans)
|
||||
{
|
||||
//global_polygon_type_0(writer,
|
||||
//para_control::list_type::translucent);
|
||||
//transfer_grid(writer, grid);
|
||||
|
||||
last_value = -1;
|
||||
transfer_knot(writer, trans, grid);
|
||||
|
||||
writer.append<ta_global_parameter::end_of_list>() =
|
||||
ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
|
||||
}
|
||||
|
||||
void transfer_ta_fifo_texture_memory_32byte(void * dst, const void * src, int length)
|
||||
{
|
||||
assert((((int)dst) & 31) == 0);
|
||||
assert((((int)length) & 31) == 0);
|
||||
|
||||
uint32_t out_addr = (uint32_t)dst;
|
||||
sh7091.CCN.QACR0 = ((reinterpret_cast<uint32_t>(out_addr) >> 24) & 0b11100);
|
||||
sh7091.CCN.QACR1 = ((reinterpret_cast<uint32_t>(out_addr) >> 24) & 0b11100);
|
||||
|
||||
volatile uint32_t * base = &store_queue[(out_addr & 0x03ffffe0) / 4];
|
||||
const uint32_t * src32 = reinterpret_cast<const uint32_t *>(src);
|
||||
|
||||
length = (length + 31) & ~31; // round up to nearest multiple of 32
|
||||
while (length > 0) {
|
||||
base[0] = src32[0];
|
||||
base[1] = src32[1];
|
||||
base[2] = src32[2];
|
||||
base[3] = src32[3];
|
||||
base[4] = src32[4];
|
||||
base[5] = src32[5];
|
||||
base[6] = src32[6];
|
||||
base[7] = src32[7];
|
||||
asm volatile ("pref @%0"
|
||||
: // output
|
||||
: "r" (&base[0]) // input
|
||||
: "memory");
|
||||
length -= 32;
|
||||
base += 8;
|
||||
src32 += 8;
|
||||
}
|
||||
}
|
||||
|
||||
void transfer_texture()
|
||||
{
|
||||
const void * start[5] = {
|
||||
(void *)&_binary_texture_game_of_life_dead_data_start,
|
||||
(void *)&_binary_texture_game_of_life_live1_data_start,
|
||||
(void *)&_binary_texture_game_of_life_live2_data_start,
|
||||
(void *)&_binary_texture_game_of_life_live3_data_start,
|
||||
(void *)&_binary_texture_game_of_life_live4_data_start,
|
||||
};
|
||||
|
||||
for (uint32_t i = 0; i < (sizeof (start)) / (sizeof (start[0])); i++) {
|
||||
uint32_t offset = texture_memory_alloc.texture.start + (32 * 32 * 2) * i;
|
||||
void * dst = reinterpret_cast<void *>(&ta_fifo_texture_memory[offset / 4]);
|
||||
const void * src = start[i];
|
||||
uint32_t size = 32 * 32 * 2;
|
||||
transfer_ta_fifo_texture_memory_32byte(dst, src, size);
|
||||
}
|
||||
}
|
||||
|
||||
void transfer_textures()
|
||||
{
|
||||
system.LMMODE0 = 0; // 64-bit address space
|
||||
system.LMMODE1 = 0; // 64-bit address space
|
||||
|
||||
transfer_texture();
|
||||
}
|
||||
|
||||
static inline mat4x4 update_analog(const mat4x4& screen_trans)
|
||||
{
|
||||
const float l_ = static_cast<float>(data[0].analog_coordinate_axis[0]) * (1.f / 255.f);
|
||||
const float r_ = static_cast<float>(data[0].analog_coordinate_axis[1]) * (1.f / 255.f);
|
||||
|
||||
const float x_ = static_cast<float>(data[0].analog_coordinate_axis[2] - 0x80) / 127.f;
|
||||
const float y_ = static_cast<float>(data[0].analog_coordinate_axis[3] - 0x80) / 127.f;
|
||||
float x = 0.05f * -x_;
|
||||
float y = 0.05f * y_;
|
||||
|
||||
float z = 1.0 + (-0.01f * r_ + 0.01f * l_);
|
||||
|
||||
mat4x4 s = scale((vec3){z, z, z});
|
||||
mat4x4 ry = rotate_x(x);
|
||||
mat4x4 rz = rotate_z(y);
|
||||
|
||||
return screen_trans * s * ry * rz;
|
||||
}
|
||||
|
||||
static inline vec3 lerp(vec3 a, vec3 b, float t)
|
||||
{
|
||||
return a + (b - a) * t;
|
||||
}
|
||||
|
||||
uint8_t __attribute__((aligned(32))) ta_parameter_buf[1024 * 1024 * 2];
|
||||
|
||||
int main()
|
||||
{
|
||||
sh7091.TMU.TSTR = 0; // stop all timers
|
||||
sh7091.TMU.TOCR = tmu::tocr::tcoe::tclk_is_external_clock_or_input_capture;
|
||||
sh7091.TMU.TCR0 = tmu::tcr0::tpsc::p_phi_256; // 256 / 50MHz = 5.12 μs ; underflows in ~1 hour
|
||||
sh7091.TMU.TCOR0 = 0xffff'ffff;
|
||||
sh7091.TMU.TCNT0 = 0xffff'ffff;
|
||||
sh7091.TMU.TSTR = tmu::tstr::str0::counter_start;
|
||||
|
||||
serial::init(0);
|
||||
|
||||
interrupt_init();
|
||||
|
||||
holly.SOFTRESET = softreset::pipeline_soft_reset
|
||||
| softreset::ta_soft_reset;
|
||||
holly.SOFTRESET = 0;
|
||||
|
||||
core_init();
|
||||
transfer_textures();
|
||||
|
||||
holly.FPU_SHAD_SCALE = fpu_shad_scale::simple_shadow_enable::parameter_selection_volume_mode;
|
||||
|
||||
system.IML6NRM = istnrm::end_of_render_tsp
|
||||
| istnrm::v_blank_in
|
||||
| istnrm::end_of_transferring_translucent_list;
|
||||
|
||||
region_array_multipass(tile_width,
|
||||
tile_height,
|
||||
opb_size,
|
||||
ta_cont_count,
|
||||
texture_memory_alloc.region_array.start,
|
||||
texture_memory_alloc.object_list.start);
|
||||
|
||||
background_parameter2(texture_memory_alloc.background[0].start,
|
||||
0xff000000);
|
||||
|
||||
video_output::set_mode_vga();
|
||||
|
||||
ta_parameter_writer writer = ta_parameter_writer(ta_parameter_buf, (sizeof (ta_parameter_buf)));
|
||||
|
||||
{
|
||||
uint32_t region_array_start = texture_memory_alloc.region_array.start;
|
||||
uint32_t isp_tsp_parameters_start = texture_memory_alloc.isp_tsp_parameters.start;
|
||||
uint32_t background_start = texture_memory_alloc.background[0].start;
|
||||
|
||||
holly.REGION_BASE = region_array_start;
|
||||
holly.PARAM_BASE = isp_tsp_parameters_start;
|
||||
|
||||
uint32_t background_offset = background_start - isp_tsp_parameters_start;
|
||||
holly.ISP_BACKGND_T = isp_backgnd_t::tag_address(background_offset / 4)
|
||||
| isp_backgnd_t::tag_offset(0)
|
||||
| isp_backgnd_t::skip(1);
|
||||
holly.ISP_BACKGND_D = _i(1.f/100000.f);
|
||||
|
||||
holly.FB_W_CTRL = fb_w_ctrl::fb_dither
|
||||
| fb_w_ctrl::fb_packmode::_565_rgb_16bit;
|
||||
uint32_t bytes_per_pixel = 2;
|
||||
holly.FB_W_LINESTRIDE = (framebuffer_width * bytes_per_pixel) / 8;
|
||||
}
|
||||
|
||||
const int width = max_knot_rings;
|
||||
const int height = max_knot_segments;
|
||||
static uint8_t grid_a[width * height] = {};
|
||||
static uint8_t grid_b[width * height] = {};
|
||||
grid grid = {
|
||||
.width = width,
|
||||
.height = height,
|
||||
.generation = 1,
|
||||
.data = {grid_a, grid_b},
|
||||
};
|
||||
for (int i = 0; i < 8; i++) {
|
||||
seed_grid(&grid, 32 * i, 0);
|
||||
}
|
||||
grid.generation = 0;
|
||||
|
||||
int tick = 0;
|
||||
|
||||
mat4x4 screen_trans = {
|
||||
1, 0, 0, 0,
|
||||
0, 0, -1, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 0, 1,
|
||||
};
|
||||
|
||||
knot_edges(knot_rings, knot_segments);
|
||||
|
||||
do_get_condition();
|
||||
while (1) {
|
||||
maple::dma_wait_complete();
|
||||
do_get_condition();
|
||||
//screen_trans = update_analog(screen_trans);
|
||||
|
||||
constexpr int ticks_per_animation_frame = 8;
|
||||
constexpr float tick_div = 1.0f / (float)ticks_per_animation_frame;
|
||||
int anim_tick = -tick;
|
||||
int anim_frame = anim_tick / ticks_per_animation_frame;
|
||||
float t = (anim_tick - (anim_frame * ticks_per_animation_frame)) * tick_div;
|
||||
int eye0 = (anim_frame + 0) & (knot_rings - 1);
|
||||
int eye1 = (anim_frame + 1) & (knot_rings - 1);
|
||||
int center0 = (anim_frame + 1) & (knot_rings - 1);
|
||||
int center1 = (anim_frame + 2) & (knot_rings - 1);
|
||||
|
||||
vec3 eye = lerp(_knot_center[eye0], _knot_center[eye1], t);
|
||||
vec3 center = lerp(_knot_center[center0], _knot_center[center1], t);
|
||||
vec3 up = lerp(_knot_ring[eye0][0], _knot_ring[eye1][0], t);
|
||||
screen_trans = look_at(eye, center, up);
|
||||
|
||||
writer.offset = 0;
|
||||
transfer_scene(writer, &grid, screen_trans);
|
||||
|
||||
tick += 1;
|
||||
if ((tick & 3) == 0) {
|
||||
grid_generation(&grid);
|
||||
}
|
||||
|
||||
while (ta_in_use);
|
||||
while (core_in_use);
|
||||
ta_in_use = 1;
|
||||
ta_polygon_converter_init2(texture_memory_alloc.isp_tsp_parameters.start,
|
||||
texture_memory_alloc.isp_tsp_parameters.end,
|
||||
texture_memory_alloc.object_list.start,
|
||||
texture_memory_alloc.object_list.end,
|
||||
opb_size[0].total(),
|
||||
ta_alloc,
|
||||
tile_width,
|
||||
tile_height);
|
||||
ta_polygon_converter_writeback(writer.buf, writer.offset);
|
||||
ta_polygon_converter_transfer(writer.buf, writer.offset);
|
||||
|
||||
|
||||
|
||||
while (next_frame == 0);
|
||||
next_frame = 0;
|
||||
}
|
||||
}
|
32
holly/texture_memory_alloc7.hpp
Normal file
32
holly/texture_memory_alloc7.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
struct texture_memory_alloc__start_end {
|
||||
uint32_t start;
|
||||
uint32_t end;
|
||||
};
|
||||
|
||||
struct texture_memory_alloc {
|
||||
struct texture_memory_alloc__start_end isp_tsp_parameters;
|
||||
struct texture_memory_alloc__start_end object_list;
|
||||
struct texture_memory_alloc__start_end region_array;
|
||||
struct texture_memory_alloc__start_end framebuffer[3];
|
||||
struct texture_memory_alloc__start_end background[2];
|
||||
struct texture_memory_alloc__start_end texture;
|
||||
};
|
||||
|
||||
constexpr texture_memory_alloc texture_memory_alloc = {
|
||||
// 32-bit addresses start end start end
|
||||
.isp_tsp_parameters = {0x000000, 0x21bfe0},
|
||||
.object_list = {0x400000, 0x495fe0},
|
||||
.region_array = {0x21c000, 0x22c000},
|
||||
.framebuffer = {{0x496000, 0x52c000},
|
||||
{0x22c000, 0x2c2000},
|
||||
{0x52c000, 0x5c2000}},
|
||||
.background = {{0x2c2000, 0x2c2020},
|
||||
{0x5c2000, 0x5c2020}},
|
||||
// 64-bit addresses
|
||||
.texture = {0x584100, 0x800000},
|
||||
};
|
@ -66,7 +66,7 @@ inline constexpr mat<4, 4, T> rotate_axis_angle(vec<3, T> u, T t)
|
||||
T xy = u.x * u.y;
|
||||
T xz = u.x * u.z;
|
||||
T yy = u.y * u.y;
|
||||
T yz = u.z * u.z;
|
||||
T yz = u.y * u.z;
|
||||
T zz = u.z * u.z;
|
||||
|
||||
return {
|
||||
@ -104,6 +104,26 @@ inline constexpr mat<4, 4, T> rotate_quaternion(vec<4, T> r)
|
||||
};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline constexpr mat<4, 4, T> look_at(vec<3, T> eye, vec<3, T> center, vec<3, T> up)
|
||||
{
|
||||
vec3 z = normalize(eye - center);
|
||||
vec3 y = up;
|
||||
vec3 x = cross(y, z);
|
||||
y = cross(z, x);
|
||||
x = normalize(x);
|
||||
y = normalize(y);
|
||||
|
||||
mat<4, 4, T> mat = {
|
||||
x.x, x.y, x.z, -dot(x, eye),
|
||||
y.x, y.y, y.z, -dot(y, eye),
|
||||
z.x, z.y, z.z, -dot(z, eye),
|
||||
0, 0, 0, 1,
|
||||
};
|
||||
|
||||
return mat;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline constexpr vec<3, T> normal_multiply(mat<4, 4, T> m, vec<3, T> n)
|
||||
{
|
||||
|
8704
model/knot.h
Normal file
8704
model/knot.h
Normal file
File diff suppressed because it is too large
Load Diff
BIN
texture/game_of_life/dead.data
Normal file
BIN
texture/game_of_life/dead.data
Normal file
Binary file not shown.
15
texture/game_of_life/dead.data.h
Normal file
15
texture/game_of_life/dead.data.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint32_t _binary_texture_game_of_life_dead_data_start __asm("_binary_texture_game_of_life_dead_data_start");
|
||||
extern uint32_t _binary_texture_game_of_life_dead_data_end __asm("_binary_texture_game_of_life_dead_data_end");
|
||||
extern uint32_t _binary_texture_game_of_life_dead_data_size __asm("_binary_texture_game_of_life_dead_data_size");
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
BIN
texture/game_of_life/dead.png
Normal file
BIN
texture/game_of_life/dead.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 589 B |
1
texture/game_of_life/live1.data
Normal file
1
texture/game_of_life/live1.data
Normal file
@ -0,0 +1 @@
|
||||
���ィ蒸�┴妾蒸┴蒸┴妾妾妾妾蒸�┴妾蒸�┴妾妾妾妾妾妾妾妾妾蒸┴蒸┴妾妾妾妾蒸┴蒸┴妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾蒸�┴妾蒸�┴妾妾妾妾妾妾妾妾妾蒸�┴妾蒸�┴妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾蒸┴蒸┴妾妾妾妾蒸┴蒸┴妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾蒸┴蒸┴妾妾妾妾蒸┴蒸┴妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾蒸�┴妾蒸�┴妾妾妾妾妾妾妾妾妾蒸�┴妾蒸�┴妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾蒸�┴妾蒸�┴妾妾妾妾妾妾妾妾妾蒸�┴妾蒸�┴蒸┴妾妾妾妾蒸┴蒸┴妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾蒸┴蒸┴妾妾妾妾蒸┴蒸┴妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾蒸┴蒸┴妾妾妾妾蒸┴蒸┴妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾蒸┴蒸┴妾妾妾妾蒸┴蒸�┴蒸┴妾妾妾妾蒸┴蒸┴妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾蒸┴蒸┴妾妾妾妾蒸┴蒸┴妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾蒸┴蒸┴妾妾妾妾蒸┴蒸┴妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾蒸┴蒸┴妾妾妾妾蒸┴蒸�┴妾蒸�┴妾妾妾妾妾妾妾妾妾蒸�┴妾蒸�┴妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾蒸�┴妾蒸�┴妾妾妾妾妾妾妾妾妾蒸�┴妾蒸�┴妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾蒸┴蒸┴妾妾妾妾蒸┴蒸┴妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾蒸┴蒸┴妾妾妾妾蒸┴蒸┴妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾蒸�┴妾蒸�┴妾妾妾妾妾妾妾妾妾蒸�┴妾蒸�┴妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾妾蒸┴蒸┴妾妾妾妾蒸┴蒸┴妾妾妾妾妾妾妾妾妾蒸�┴妾蒸�┴妾妾妾妾蒸┴蒸┴妾蒸�┴蒸���
|
15
texture/game_of_life/live1.data.h
Normal file
15
texture/game_of_life/live1.data.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint32_t _binary_texture_game_of_life_live1_data_start __asm("_binary_texture_game_of_life_live1_data_start");
|
||||
extern uint32_t _binary_texture_game_of_life_live1_data_end __asm("_binary_texture_game_of_life_live1_data_end");
|
||||
extern uint32_t _binary_texture_game_of_life_live1_data_size __asm("_binary_texture_game_of_life_live1_data_size");
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
BIN
texture/game_of_life/live1.png
Normal file
BIN
texture/game_of_life/live1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.3 KiB |
1
texture/game_of_life/live2.data
Normal file
1
texture/game_of_life/live2.data
Normal file
@ -0,0 +1 @@
|
||||
���」��┘��┘�┘������┘���┘����������┘�┘�����┘�┘����������������������┘���┘�����������┘���┘������������������������������������������┘�┘�����┘�┘���������������������┘�┘�����┘�┘��������������������������������������������������������������������������������������┘���┘�����������┘���┘�������������������������������������������┘���┘�����������┘���┘�┘�����┘�┘���������������������┘�┘�����┘�┘�������������������������������������������������������������������������������������┘�┘�����┘�┘���������������������┘�┘�����┘��┘�┘�����┘�┘���������������������┘�┘�����┘�┘�������������������������������������������������������������������������������������┘�┘�����┘�┘���������������������┘�┘�����┘��┘���┘�����������┘���┘�������������������������������������������┘���┘�����������┘���┘�������������������������������������������������������������������������������������┘�┘�����┘�┘���������������������┘�┘�����┘�┘�������������������������������������������┘���┘�����������┘���┘���������������������┘�┘�����┘�┘�����������┘���┘�����┘�┘���┘����
|
15
texture/game_of_life/live2.data.h
Normal file
15
texture/game_of_life/live2.data.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint32_t _binary_texture_game_of_life_live2_data_start __asm("_binary_texture_game_of_life_live2_data_start");
|
||||
extern uint32_t _binary_texture_game_of_life_live2_data_end __asm("_binary_texture_game_of_life_live2_data_end");
|
||||
extern uint32_t _binary_texture_game_of_life_live2_data_size __asm("_binary_texture_game_of_life_live2_data_size");
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
BIN
texture/game_of_life/live2.png
Normal file
BIN
texture/game_of_life/live2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.3 KiB |
1
texture/game_of_life/live3.data
Normal file
1
texture/game_of_life/live3.data
Normal file
@ -0,0 +1 @@
|
||||
������#�����#�#���#���#�#�#�#�#�����#�#�����#�#�#�#�#�#�#�#�#�#���#���#�#�#�#�#���#���#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�����#�#�����#�#�#�#�#�#�#�#�#�#�����#�#�����#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#���#���#�#�#�#�#���#���#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#���#���#�#�#�#�#���#���#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�����#�#�����#�#�#�#�#�#�#�#�#�#�����#�#�����#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�����#�#�����#�#�#�#�#�#�#�#�#�#�����#�#�����#���#�#�#�#�#���#���#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#���#���#�#�#�#�#���#���#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#���#���#�#�#�#�#���#���#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#���#���#�#�#�#�#���#�����#���#�#�#�#�#���#���#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#���#���#�#�#�#�#���#���#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#���#���#�#�#�#�#���#���#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#���#���#�#�#�#�#���#�����#�#�����#�#�#�#�#�#�#�#�#�#�����#�#�����#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�����#�#�����#�#�#�#�#�#�#�#�#�#�����#�#�����#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#���#���#�#�#�#�#���#���#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#���#���#�#�#�#�#���#���#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�����#�#�����#�#�#�#�#�#�#�#�#�#�����#�#�����#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#���#���#�#�#�#�#���#���#�#�#�#�#�#�#�#�#�#�����#�#�����#�#�#�#�#���#���#�#�����#�������
|
15
texture/game_of_life/live3.data.h
Normal file
15
texture/game_of_life/live3.data.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint32_t _binary_texture_game_of_life_live3_data_start __asm("_binary_texture_game_of_life_live3_data_start");
|
||||
extern uint32_t _binary_texture_game_of_life_live3_data_end __asm("_binary_texture_game_of_life_live3_data_end");
|
||||
extern uint32_t _binary_texture_game_of_life_live3_data_size __asm("_binary_texture_game_of_life_live3_data_size");
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
BIN
texture/game_of_life/live3.png
Normal file
BIN
texture/game_of_life/live3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.3 KiB |
1
texture/game_of_life/live4.data
Normal file
1
texture/game_of_life/live4.data
Normal file
@ -0,0 +1 @@
|
||||
���c�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
|
15
texture/game_of_life/live4.data.h
Normal file
15
texture/game_of_life/live4.data.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint32_t _binary_texture_game_of_life_live4_data_start __asm("_binary_texture_game_of_life_live4_data_start");
|
||||
extern uint32_t _binary_texture_game_of_life_live4_data_end __asm("_binary_texture_game_of_life_live4_data_end");
|
||||
extern uint32_t _binary_texture_game_of_life_live4_data_size __asm("_binary_texture_game_of_life_live4_data_size");
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
BIN
texture/game_of_life/live4.png
Normal file
BIN
texture/game_of_life/live4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.3 KiB |
@ -16,6 +16,7 @@ lookup = [
|
||||
#for n in lookup:
|
||||
# print(f"{n:08x}")
|
||||
|
||||
"""
|
||||
allocations = {
|
||||
"isp_tsp_parameters0" : (0x11_c000 , 32 ),
|
||||
"isp_tsp_parameters1" : (0x11_c000 , 32 ),
|
||||
@ -32,6 +33,21 @@ allocations = {
|
||||
"background0" : (0x00_0040 , 32 ),
|
||||
"background1" : (0x00_0040 , 32 ),
|
||||
}
|
||||
"""
|
||||
|
||||
allocations = {
|
||||
"isp_tsp_parameters" : (0x21_c000 , 32 ),
|
||||
"object_list" : (0x09_6000 , 32 ),
|
||||
|
||||
"region_array" : (0x01_0000 , 0 ),
|
||||
"framebuffer0" : (0x09_6000 , 0 ),
|
||||
|
||||
"framebuffer1" : (0x09_6000 , 0 ),
|
||||
"framebuffer2" : (0x09_6000 , 0 ),
|
||||
|
||||
"background0" : (0x00_0040 , 32 ),
|
||||
"background1" : (0x00_0040 , 32 ),
|
||||
}
|
||||
|
||||
def gen_allocations():
|
||||
acc = [0x00_0000, 0x40_0000]
|
||||
|
94
torus.py
Normal file
94
torus.py
Normal file
@ -0,0 +1,94 @@
|
||||
import bpy
|
||||
import bmesh
|
||||
from mathutils import Vector, Matrix
|
||||
import copy
|
||||
|
||||
from math import sin, cos, pi
|
||||
|
||||
def knot(t):
|
||||
x = sin(t) + 2 * sin(2 * t)
|
||||
y = cos(t) - 2 * cos(2 * t)
|
||||
z = -sin(3 * t)
|
||||
|
||||
return Vector((x, y, z))
|
||||
|
||||
def rr(v: Vector,
|
||||
k: Vector, # axis
|
||||
t: float):
|
||||
return v * cos(t) + k.cross(v) * sin(t) + k * (k.dot(v)) * (1 - cos(t))
|
||||
|
||||
def radial_segments(bm, a, n0, n, radial_surface_n, segments):
|
||||
for i in range(segments):
|
||||
t = (i / segments) * 2 * pi
|
||||
|
||||
rn = rr(n, n0, t)
|
||||
rn.normalize()
|
||||
surface = bm.verts.new(a.co + rn * 0.6)
|
||||
radial_surface_n[i] = surface
|
||||
|
||||
def radial_faces(bm, radial_surface_p, radial_surface_n, segments):
|
||||
for i in range(segments):
|
||||
j = (i + 1) % segments
|
||||
|
||||
bm.faces.new([
|
||||
radial_surface_n[i],
|
||||
radial_surface_n[j],
|
||||
radial_surface_p[j],
|
||||
radial_surface_p[i]
|
||||
])
|
||||
|
||||
def knot_edges(points, segments):
|
||||
bm = bmesh.new()
|
||||
|
||||
knot_centers = []
|
||||
|
||||
for i in range(points):
|
||||
t = (i / points) * 2 * pi
|
||||
center = bm.verts.new(knot(t))
|
||||
knot_centers.append(center)
|
||||
|
||||
radial_surface_p = [0] * segments
|
||||
radial_surface_n = [0] * segments
|
||||
radial_surface_f = None
|
||||
|
||||
for i in range(points):
|
||||
ip = (i + 1) % points
|
||||
im = (i - 1) % points
|
||||
a = knot_centers[i]
|
||||
b = knot_centers[ip]
|
||||
c = knot_centers[im]
|
||||
|
||||
n0 = ((b.co - a.co) + (a.co - c.co)) / 2
|
||||
n0.normalize()
|
||||
n1 = Vector(a.co)
|
||||
n = n0.cross(-n1)
|
||||
n.normalize()
|
||||
|
||||
radial_segments(bm, a, n0, n,
|
||||
radial_surface_n,
|
||||
segments)
|
||||
|
||||
if i == 0:
|
||||
radial_surface_f = copy.copy(radial_surface_n)
|
||||
else:
|
||||
radial_faces(bm, radial_surface_p, radial_surface_n, segments)
|
||||
|
||||
tmp = radial_surface_p
|
||||
radial_surface_p = radial_surface_n
|
||||
radial_surface_n = tmp
|
||||
|
||||
radial_faces(bm, radial_surface_f, radial_surface_p, segments)
|
||||
|
||||
mesh = bpy.data.meshes.new("test")
|
||||
bm.to_mesh(mesh)
|
||||
bm.free()
|
||||
object = bpy.data.objects.new("test", mesh)
|
||||
bpy.context.scene.collection.objects.link(object)
|
||||
|
||||
def delete_test_objects(collection):
|
||||
for o in collection.objects:
|
||||
if o.name.startswith("test"):
|
||||
collection.objects.unlink(o)
|
||||
|
||||
delete_test_objects(bpy.context.scene.collection)
|
||||
knot_edges(256, 32)
|
Loading…
x
Reference in New Issue
Block a user