diff --git a/dreamcast2/example/deferred_shading.cpp b/dreamcast2/example/deferred_shading.cpp new file mode 100644 index 0000000..7a47039 --- /dev/null +++ b/dreamcast2/example/deferred_shading.cpp @@ -0,0 +1,714 @@ +#include "memorymap.hpp" + +#include "holly/core/object_list_bits.hpp" +#include "holly/core/region_array.hpp" +#include "holly/core/region_array_bits.hpp" +#include "holly/core/parameter_bits.hpp" +#include "holly/core/parameter.hpp" +#include "holly/ta/global_parameter.hpp" +#include "holly/ta/vertex_parameter.hpp" +#include "holly/ta/parameter_bits.hpp" +#include "holly/holly.hpp" +#include "holly/holly_bits.hpp" + +#include "sh7091/sh7091.hpp" +#include "sh7091/sh7091_bits.hpp" +#include "sh7091/pref.hpp" +#include "sh7091/store_queue_transfer.hpp" + +#include "systembus/systembus.hpp" +#include "systembus/systembus_bits.hpp" + +static inline void character(const char c) +{ + using sh7091::sh7091; + using namespace sh7091; + + // set the transmit trigger to `1 byte`--this changes the behavior of TDFE + sh7091.SCIF.SCFCR2 = scif::scfcr2::ttrg::trigger_on_1_bytes; + + // wait for transmit fifo to become partially empty + while ((sh7091.SCIF.SCFSR2 & scif::scfsr2::tdfe::bit_mask) == 0); + + // unset tdfe bit + sh7091.SCIF.SCFSR2 = (uint16_t)(~scif::scfsr2::tdfe::bit_mask); + + sh7091.SCIF.SCFTDR2 = c; +} + +static void string(const char * s) +{ + while (*s != 0) { + character(*s++); + } +} + +static void print_base16(uint32_t n, int len) +{ + char buf[len]; + char * bufi = &buf[len - 1]; + + while (bufi >= buf) { + uint32_t nib = n & 0xf; + n = n >> 4; + if (nib > 9) { + nib += (97 - 10); + } else { + nib += (48 - 0); + } + + *bufi = nib; + bufi -= 1; + } + + for (int i = 0; i < len; i++) { + character(buf[i]); + } +} + +#include "../../math/float_types.hpp" +//#include "model/suzanne.h" +//#include "model/icosphere.h" +#include "model/cube.h" + +void transfer_background_polygon(uint32_t isp_tsp_parameter_start) +{ + using namespace holly::core::parameter; + + using parameter = isp_tsp_parameter<3>; + + volatile parameter * polygon = (volatile parameter *)&texture_memory32[isp_tsp_parameter_start]; + + polygon->isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::always + | isp_tsp_instruction_word::culling_mode::no_culling; + + polygon->tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one + | tsp_instruction_word::dst_alpha_instr::zero + | tsp_instruction_word::fog_control::no_fog; + + polygon->texture_control_word = 0; + + polygon->vertex[0].x = 0.0f; + polygon->vertex[0].y = 0.0f; + polygon->vertex[0].z = 0.00001f; + polygon->vertex[0].base_color = 0x000000; + + polygon->vertex[1].x = 32.0f; + polygon->vertex[1].y = 0.0f; + polygon->vertex[1].z = 0.00001f; + polygon->vertex[1].base_color = 0x000000; + + polygon->vertex[2].x = 32.0f; + polygon->vertex[2].y = 32.0f; + polygon->vertex[2].z = 0.00001f; + polygon->vertex[2].base_color = 0x000000; +} + +static inline uint32_t transfer_ta_global_end_of_list(uint32_t store_queue_ix) +{ + using namespace holly::ta; + using namespace holly::ta::parameter; + + // + // TA "end of list" global transfer + // + volatile global_parameter::end_of_list * end_of_list = (volatile global_parameter::end_of_list *)&store_queue[store_queue_ix]; + store_queue_ix += (sizeof (global_parameter::end_of_list)); + + end_of_list->parameter_control_word = parameter_control_word::para_type::end_of_list; + + // start store queue transfer of `end_of_list` to the TA + pref(end_of_list); + + return store_queue_ix; +} + +static inline uint32_t transfer_ta_global_polygon(uint32_t store_queue_ix) +{ + using namespace holly::core::parameter; + using namespace holly::ta; + using namespace holly::ta::parameter; + + // + // TA polygon global transfer + // + + volatile global_parameter::polygon_type_0 * polygon = (volatile global_parameter::polygon_type_0 *)&store_queue[store_queue_ix]; + store_queue_ix += (sizeof (global_parameter::polygon_type_0)); + + polygon->parameter_control_word = parameter_control_word::para_type::polygon_or_modifier_volume + | parameter_control_word::list_type::opaque + | parameter_control_word::col_type::floating_color + | parameter_control_word::gouraud; + + polygon->isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater + | isp_tsp_instruction_word::culling_mode::no_culling; + // Note that it is not possible to use + // ISP_TSP_INSTRUCTION_WORD::GOURAUD_SHADING in this isp_tsp_instruction_word, + // because `gouraud` is one of the bits overwritten by the value in + // parameter_control_word. See DCDBSysArc990907E.pdf page 200. + + polygon->tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one + | tsp_instruction_word::dst_alpha_instr::zero + | tsp_instruction_word::fog_control::no_fog; + + polygon->texture_control_word = 0; + + // start store queue transfer of `polygon` to the TA + pref(polygon); + + return store_queue_ix; +} + +#define abs(n) __builtin_abs(n) +#define cos(n) __builtin_cosf(n) +#define sin(n) __builtin_sinf(n) + +static float theta = 0; + +static inline vec3 vertex_rotate(vec3 v) +{ + // to make the models's appearance more interesting, rotate the vertex on two + // axes + + float x0 = v.x; + float y0 = v.y; + float z0 = v.z; + + float x1 = x0 * cos(theta) - z0 * sin(theta); + float y1 = y0; + float z1 = x0 * sin(theta) + z0 * cos(theta); + + float x2 = x1; + float y2 = y1 * cos(theta) - z1 * sin(theta); + float z2 = y1 * sin(theta) + z1 * cos(theta); + + return (vec3){x2, y2, z2}; +} + +static inline vec3 vertex_perspective_divide(vec3 v) +{ + float w = 1.0f / (v.z + 2.5f); + return (vec3){v.x * w, v.y * w, w}; +} + +static inline vec3 vertex_screen_space(vec3 v) +{ + return (vec3){ + v.x * 240.f + 320.f, + v.y * 240.f + 240.f, + v.z, + }; +} + +static inline uint32_t transfer_ta_vertex_triangle(uint32_t store_queue_ix, + float x, float y, float z, + float r, float g, float b, + bool end_of_strip) +{ + using namespace holly::ta; + using namespace holly::ta::parameter; + + // + // TA polygon vertex transfer + // + + volatile vertex_parameter::polygon_type_1 * vertex = (volatile vertex_parameter::polygon_type_1 *)&store_queue[store_queue_ix]; + store_queue_ix += (sizeof (vertex_parameter::polygon_type_1)) * 1; + + vertex[0].parameter_control_word = parameter_control_word::para_type::vertex_parameter + | (end_of_strip ? parameter_control_word::end_of_strip : 0); + vertex[0].x = x; + vertex[0].y = y; + vertex[0].z = z; + //vertex[0].base_color_alpha = a; + vertex[0].base_color_r = r; + vertex[0].base_color_g = g; + vertex[0].base_color_b = b; + + pref(vertex); + + return store_queue_ix; +} + +static inline float remap(float f) +{ + return (f + 1.0f) * 0.5f; +} + +static inline float unremap(int i) +{ + return -1.0f + (((float)i) * (1.0f / 255.0f)) * 2.0f; +} + +static inline vec3 remap_normal(vec3 n) +{ + return { + remap(n.x), + remap(n.y), + remap(n.z) + }; +} + +float pow(float f) +{ + return __builtin_powf(f, 32); +} + +vec3 lighting(vec3& FragPos, vec3& Normal) +{ + vec3 lightColor = {1, 1, 1}; + + vec3 lightPos = {0, 0, -2}; + + vec3 viewPos = {0, 0, -5}; + + // ambient + float ambientStrength = 0.1f; + vec3 ambient = ambientStrength * lightColor; + + // diffuse + vec3 norm = normalize(Normal); + vec3 lightDir = normalize(lightPos - FragPos); + //vec3 lightDir = normalize(vec3(0, 0, 1)); + float diff = max(dot(norm, lightDir), 0.0f); + vec3 diffuse = (diff * 0.8f) * lightColor; + + // specular + float specularStrength = 0.5f; + vec3 viewDir = normalize(viewPos - FragPos); + vec3 reflectDir = reflect(-lightDir, norm); + float spec = pow(max(dot(viewDir, reflectDir), 0.0f)); + vec3 specular = specularStrength * spec * lightColor; + + vec3 intensity = ambient + diffuse + specular; + + return intensity; +} + +static const int strips_length = (sizeof (strips)) / (sizeof (strips[0])); + +template +void transfer_ta_strips() +{ + { + using namespace sh7091; + using sh7091::sh7091; + + // set the store queue destination address to the TA Polygon Converter FIFO + sh7091.CCN.QACR0 = sh7091::ccn::qacr0::address(ta_fifo_polygon_converter); + sh7091.CCN.QACR1 = sh7091::ccn::qacr1::address(ta_fifo_polygon_converter); + } + + uint32_t store_queue_ix = 0; + + store_queue_ix = transfer_ta_global_polygon(store_queue_ix); + + int color_ix = 0; + + for (int strip_ix = 0; strip_ix < strips_length; strip_ix++) { + int vertex_ix = strips[strip_ix]; + + vec3 p = vertex_rotate(vertices[abs(vertex_ix)]); + + vec3 vp = vertex_screen_space( + vertex_perspective_divide(p)); + + vec3 n = vertex_rotate(normals[abs(vertex_ix)]); + + bool end_of_strip = vertex_ix < 0; + + vec3 c = lighting(p, n); + + if constexpr (render_mode == 0) { + store_queue_ix = transfer_ta_vertex_triangle(store_queue_ix, + vp.x, vp.y, vp.z, + remap(p.x), remap(p.y), remap(p.z), + //c.x, c.y, c.z, + //remap(n.x), remap(n.y), remap(n.z), + end_of_strip); + } + if constexpr (render_mode == 1) { + store_queue_ix = transfer_ta_vertex_triangle(store_queue_ix, + vp.x, vp.y, vp.z, + //remap(p.x), remap(p.y), remap(p.z), + //c.x, c.y, c.z, + remap(n.x), remap(n.y), remap(n.z), + end_of_strip); + } + if constexpr (render_mode == 2) { + store_queue_ix = transfer_ta_vertex_triangle(store_queue_ix, + vp.x, vp.y, vp.z, + //remap(p.x), remap(p.y), remap(p.z), + c.x, c.y, c.z, + //remap(n.x), remap(n.y), remap(n.z), + end_of_strip); + } + + if (end_of_strip) { + color_ix = (color_ix + 1) % 64; + } + } + + store_queue_ix = transfer_ta_global_end_of_list(store_queue_ix); +} + +static inline void assert(bool t) +{ + if (!t) { + string("assertion failed\n"); + } +} + +void ch1_dma_transfer(uint32_t source, uint32_t destination, uint32_t transfers) +{ + using namespace sh7091::dmac; + using sh7091::sh7091; + + volatile uint32_t _dummy = sh7091.DMAC.CHCR1; + (void)_dummy; + + sh7091.DMAC.CHCR1 = 0; + + assert((((uint32_t)source) & 0b11111) == 0); + assert((((uint32_t)destination) & 0b11111) == 0); + sh7091.DMAC.SAR1 = source; + sh7091.DMAC.DAR1 = destination; + sh7091.DMAC.DMATCR1 = dmatcr::transfer_count(transfers); + + sh7091.DMAC.CHCR1 = chcr::dm::destination_address_incremented + | chcr::sm::source_address_incremented + | chcr::rs::resource_select(0b0100) /* auto request; external address space → external address space */ + | chcr::tm::cycle_burst_mode /* transmit mode */ + //| chcr::tm::cycle_steal_mode /* transmit mode */ + | chcr::ts::_32_byte /* transfer size */ + //| chcr::ie::interrupt_request_generated + | chcr::de::channel_operation_enabled; +} + +void ch2_dma_transfer(uint32_t source, uint32_t destination, uint32_t transfers) +{ + using namespace sh7091::dmac; + using sh7091::sh7091; + using namespace systembus; + using systembus::systembus; + + for (uint32_t i = 0; i < transfers; i++) { + ocbp(source + (32 * i)); + } + + // this dummy read appears to be required on real hardware. + volatile uint32_t _dummy = sh7091.DMAC.CHCR2; + (void)_dummy; + + systembus.ISTNRM = istnrm::end_of_dma_ch2_dma; + + /* start a new CH2-DMA transfer from "system memory" to "TA FIFO polygon converter" */ + sh7091.DMAC.CHCR2 = 0; /* disable DMA channel */ + sh7091.DMAC.SAR2 = reinterpret_cast(source); /* start address, must be aligned to a CHCHR__TS-sized (32-byte) boundary */ + sh7091.DMAC.DMATCR2 = dmatcr::transfer_count(transfers); /* transfer count, in CHCHR__TS-sized (32-byte) units */ + sh7091.DMAC.CHCR2 = chcr::dm::destination_address_incremented + | chcr::sm::source_address_incremented + | chcr::rs::resource_select(0b0010) /* external request, single address mode; + external address space → external device */ + | chcr::tm::cycle_burst_mode /* transmit mode */ + | chcr::ts::_32_byte /* transfer size */ + | chcr::de::channel_operation_enabled; + + systembus.C2DSTAT = c2dstat::texture_memory_start_address(destination); /* CH2-DMA destination address */ + systembus.C2DLEN = c2dlen::transfer_length(transfers * 32); /* CH2-DMA length (must be a multiple of 32) */ + systembus.C2DST = 1; /* CH2-DMA start (an 'external' request from SH7091's perspective) */ +} + +static inline void wait_ta() +{ + using namespace systembus; + using systembus::systembus; + + while ((systembus.ISTNRM & istnrm::end_of_transferring_opaque_list) == 0); + systembus.ISTNRM = istnrm::end_of_transferring_opaque_list; +} + +static inline void wait_render() +{ + using namespace systembus; + using systembus::systembus; + + while ((systembus.ISTNRM & istnrm::end_of_render_tsp) == 0) { + if (systembus.ISTERR) { + string("ISTERR: "); + print_base16(systembus.ISTERR, 8); + string("\n "); + return; + } + for (int i = 0; i < 10000; i++) { + asm volatile ("nop" ::: "memory"); + } + } + systembus.ISTNRM = istnrm::end_of_render_tsp + | istnrm::end_of_render_isp + | istnrm::end_of_render_video; +} + +static uint8_t tmp_buf0[640 * 480 * 4] __attribute__((aligned(32))); +static uint8_t tmp_buf1[640 * 480 * 4] __attribute__((aligned(32))); + +void main() +{ + { + using namespace sh7091::dmac; + using sh7091::sh7091; + sh7091.DMAC.CHCR0 = 0; + sh7091.DMAC.CHCR1 = 0; + sh7091.DMAC.CHCR2 = 0; + sh7091.DMAC.CHCR3 = 0; + 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 */ + + } + + /* + a very simple memory map: + + the ordering within texture memory is not significant, and could be + anything + */ + + uint32_t framebuffer_start[3] = {0x000000, 0x12c000, 0x258000}; + uint32_t region_array_start = 0x384000; + uint32_t isp_tsp_parameter_start = 0x500000; + uint32_t object_list_start = 0x400000; + + const int tile_y_num = 480 / 32; + const int tile_x_num = 640 / 32; + + using namespace holly::core; + + region_array::list_block_size list_block_size = { + .opaque = 32 * 4, + }; + + region_array::transfer(tile_x_num, + tile_y_num, + list_block_size, + region_array_start, + object_list_start); + + transfer_background_polygon(isp_tsp_parameter_start); + + ////////////////////////////////////////////////////////////////////////////// + // configure the TA + ////////////////////////////////////////////////////////////////////////////// + + using namespace holly; + using holly::holly; + + // TA_GLOB_TILE_CLIP restricts which "object pointer blocks" are written + // to. + // + // This can also be used to implement "windowing", as long as the desired + // window size happens to be a multiple of 32 pixels. The "User Tile Clip" TA + // control parameter can also ~equivalently be used as many times as desired + // within a single TA initialization to produce an identical effect. + // + // See DCDBSysArc990907E.pdf page 183. + holly.TA_GLOB_TILE_CLIP = ta_glob_tile_clip::tile_y_num(tile_y_num - 1) + | ta_glob_tile_clip::tile_x_num(tile_x_num - 1); + + // While CORE supports arbitrary-length object lists, the TA uses "object + // pointer blocks" as a memory allocation strategy. These fixed-length blocks + // can still have infinite length via "object pointer block links". This + // mechanism is illustrated in DCDBSysArc990907E.pdf page 188. + holly.TA_ALLOC_CTRL = ta_alloc_ctrl::opb_mode::increasing_addresses + | ta_alloc_ctrl::o_opb::_32x4byte; + + // While building object lists, the TA contains an internal index (exposed as + // the read-only TA_ITP_CURRENT) for the next address that new ISP/TSP will be + // stored at. The initial value of this index is TA_ISP_BASE. + + // reserve space in ISP/TSP parameters for the background parameter + using polygon = holly::core::parameter::isp_tsp_parameter<3>; + uint32_t ta_isp_base_offset = (sizeof (polygon)) * 1; + + holly.TA_ISP_BASE = isp_tsp_parameter_start + ta_isp_base_offset; + holly.TA_ISP_LIMIT = isp_tsp_parameter_start + 0x100000; + + // Similarly, the TA also contains, for up to 600 tiles, an internal index for + // the next address that an object list entry will be stored for each + // tile. These internal indicies are partially exposed via the read-only + // TA_OL_POINTERS. + holly.TA_OL_BASE = object_list_start; + + // TA_OL_LIMIT, DCDBSysArc990907E.pdf page 385: + // + // > Because the TA may automatically store data in the address that is + // > specified by this register, it must not be used for other data. For + // > example, the address specified here must not be the same as the address + // > in the TA_ISP_BASE register. + holly.TA_OL_LIMIT = object_list_start + 0x100000 - 32; + + holly.TA_NEXT_OPB_INIT = (object_list_start + 32 * 4 * tile_y_num * tile_x_num); + + ////////////////////////////////////////////////////////////////////////////// + // configure CORE + ////////////////////////////////////////////////////////////////////////////// + + // REGION_BASE is the (texture memory-relative) address of the region array. + holly.REGION_BASE = region_array_start; + + // PARAM_BASE is the (texture memory-relative) address of ISP/TSP parameters. + // Anything that references an ISP/TSP parameter does so relative to this + // address (and not relative to the beginning of texture memory). + holly.PARAM_BASE = isp_tsp_parameter_start; + + // Set the offset of the background ISP/TSP parameter, relative to PARAM_BASE + // SKIP is related to the size of each vertex + uint32_t background_offset = 0; + + holly.ISP_BACKGND_T = isp_backgnd_t::tag_address(background_offset / 4) + | isp_backgnd_t::tag_offset(0) + | isp_backgnd_t::skip(1); + + // FB_W_SOF1 is the (texture memory-relative) address of the framebuffer that + // will be written to when a tile is rendered/flushed. + //holly.FB_W_SOF1 = framebuffer_start; + + // without waiting for rendering to actually complete, immediately display the + // framebuffer. + //holly.FB_R_SOF1 = framebuffer_start[0]; + + using systembus::systembus; + using namespace systembus; + systembus.ISTNRM = 0xffffffff; + + // draw 500 frames of cube rotation + for (int frame_ix = 0; frame_ix < 10000; frame_ix++) { + ////////////////////////////////////////////////////////////////////////////// + // transfer cube to texture memory via the TA polygon converter FIFO + ////////////////////////////////////////////////////////////////////////////// + + // TA_LIST_INIT needs to be written (every frame) prior to the first FIFO + // write. + holly.TA_LIST_INIT = ta_list_init::list_init; + + // dummy TA_LIST_INIT read; DCDBSysArc990907E.pdf in multiple places says this + // step is required. + (void)holly.TA_LIST_INIT; + + /* + asm volatile ("" ::: "memory"); + + { // position + transfer_ta_strips<0>(); + wait_ta(); + holly.FB_W_SOF1 = framebuffer_start[0]; + systembus.ISTERR = 0xffffffff; + holly.STARTRENDER = 1; + wait_render(); + } + + asm volatile ("" ::: "memory"); + + { + uint32_t source = (uint32_t)&texture_memory32[framebuffer_start[0]]; + ch1_dma_transfer(source, (uint32_t)tmp_buf0, (640 * 480 * 4) / 32); + for (int i = 0; i < 640 * 480 * 4 / 32; i++) { + ocbi(&tmp_buf0[i * 32]); + } + } + + asm volatile ("" ::: "memory"); + + { // normals + transfer_ta_strips<1>(); + wait_ta(); + holly.FB_W_SOF1 = framebuffer_start[1]; + systembus.ISTERR = 0xffffffff; + holly.STARTRENDER = 1; + wait_render(); + } + + asm volatile ("" ::: "memory"); + + while ((sh7091::sh7091.DMAC.CHCR1 & sh7091::dmac::chcr::te::transfers_completed) == 0) {} + + { + uint32_t source = (uint32_t)&texture_memory32[framebuffer_start[1]]; + ch1_dma_transfer(source, (uint32_t)tmp_buf1, (640 * 480 * 4) / 32); + for (int i = 0; i < 640 * 480 * 4 / 32; i++) { + ocbi(&tmp_buf1[i * 32]); + } + } + + while ((sh7091::sh7091.DMAC.CHCR1 & sh7091::dmac::chcr::te::transfers_completed) == 0) {} + + for (int i = 0; i < 640 * 480; i++) { + if (i % 8 == 0) { + pref(&tmp_buf0[(i + 1) * 4 / 32]); + pref(&tmp_buf1[(i + 1) * 4 / 32]); + } + + uint8_t p_b = tmp_buf0[i * 4 + 0]; + uint8_t p_g = tmp_buf0[i * 4 + 1]; + uint8_t p_r = tmp_buf0[i * 4 + 2]; + if (p_b == 0 && p_g == 0 && p_r == 0) + continue; + vec3 p = {unremap(p_r), unremap(p_g), unremap(p_b)}; + + uint8_t n_b = tmp_buf1[i * 4 + 0]; + uint8_t n_g = tmp_buf1[i * 4 + 1]; + uint8_t n_r = tmp_buf1[i * 4 + 2]; + if (n_b == 0 && n_g == 0 && n_r == 0) + continue; + vec3 n = {unremap(n_r), unremap(n_g), unremap(n_b)}; + + vec3 c = lighting(p, n); + int color = c.z * 255.0f; + if (color > 255) color = 255; + if (color < 0) color = 0; + + tmp_buf0[i * 4 + 0] = color; + tmp_buf0[i * 4 + 1] = color; + tmp_buf0[i * 4 + 2] = color; + + if (i % 8 == 7) { + ocbp(&tmp_buf0[(i & (~7)) * 4 / 32]); + } + } + + systembus.ISTNRM = istnrm::v_blank_in; + while ((systembus.ISTNRM & istnrm::v_blank_in) == 0); + + systembus.LMMODE0 = 1; + systembus.LMMODE1 = 1; + uint32_t destination = 0x11000000 + framebuffer_start[2]; + ch2_dma_transfer((uint32_t)tmp_buf0, destination, (640 * 480 * 4) / 32); + while ((systembus.ISTNRM & istnrm::end_of_dma_ch2_dma) == 0); + systembus.ISTNRM = istnrm::end_of_dma_ch2_dma; + + holly.FB_R_SOF1 = framebuffer_start[2]; + */ + + { // color + transfer_ta_strips<2>(); + wait_ta(); + holly.FB_W_SOF1 = framebuffer_start[frame_ix % 3]; + systembus.ISTERR = 0xffffffff; + holly.STARTRENDER = 1; + wait_render(); + } + + systembus.ISTNRM = istnrm::v_blank_in; + while ((systembus.ISTNRM & istnrm::v_blank_in) == 0); + + holly.FB_R_SOF1 = framebuffer_start[frame_ix % 3]; + + // increment theta for the cube rotation animation + // (used by the `vertex_rotate` function) + theta += 0.01f; + } + + string("return\n "); + // return from main; this will effectively jump back to the serial loader +} diff --git a/dreamcast2/example/example.mk b/dreamcast2/example/example.mk index a98bdce..359742b 100644 --- a/dreamcast2/example/example.mk +++ b/dreamcast2/example/example.mk @@ -59,6 +59,13 @@ SUZANNE_TRIANGLE_STRIPS_OBJ = \ example/suzanne_triangle_strips.elf: LDSCRIPT = $(LIB)/main.lds example/suzanne_triangle_strips.elf: $(START_OBJ) $(SUZANNE_TRIANGLE_STRIPS_OBJ) +DEFERRED_SHADING_OBJ = \ + holly/core/region_array.o \ + example/deferred_shading.o + +example/deferred_shading.elf: LDSCRIPT = $(LIB)/main.lds +example/deferred_shading.elf: $(START_OBJ) $(DEFERRED_SHADING_OBJ) + TETRAHEDRON_OBJ = \ holly/core/region_array.o \ example/tetrahedron.o diff --git a/dreamcast2/example/model/cube.h b/dreamcast2/example/model/cube.h new file mode 100644 index 0000000..31ee916 --- /dev/null +++ b/dreamcast2/example/model/cube.h @@ -0,0 +1,550 @@ +static const int strips[] = { + // strip_0 + 136, 1, 110, 127, 129, 130, 132, 133, 123, 126, 125, 118, 115, 117, 114, 116, 113, 4, 3, 6, 5, 8, 58, 70, 61, 71, 64, 72, 80, 79, 77, 76, 74, 73, 175, 163, 173, 191, 210, 208, 211, 209, 212, 197, 198, 195, 196, 193, 205, 143, 155, 158, 157, 160, 159, 150, 147, 149, 146, 148, 136, 30, 27, 32, 11, 12, 14, 15, 17, 18, 10, 26, 9, 23, 8, 20, 70, 67, 68, 65, 66, 102, 105, 103, 106, 104, 107, 90, 91, 88, 98, 97, 95, 94, 92, 82, 56, 163, -73, + // strip_1 + 136, 110, 146, 129, 147, 132, 159, 120, 156, 119, 137, 109, 190, 164, 200, 183, 201, 186, 213, 174, 210, -173, + // strip_2 + 136, 27, 1, 11, 13, 14, 16, 17, 7, 10, -9, + // strip_3 + 163, 82, 191, -208, + // strip_4 + 8, 6, 9, -7, + // strip_5 + 6, 4, 7, -16, + // strip_6 + 4, 116, 16, 128, 13, 127, -1, + // strip_7 + 70, 68, 71, 69, 72, -79, + // strip_8 + 68, 66, 69, 78, 79, -76, + // strip_9 + 66, 105, 78, 93, 75, 92, -56, + // strip_10 + 56, 73, 75, 76, -78, + // strip_11 + 82, 94, 208, -209, + // strip_12 + 92, 93, 95, 96, 98, 99, 91, -107, + // strip_13 + 93, 105, 96, 106, 99, -107, + // strip_14 + 94, 97, 209, -197, + // strip_15 + 132, 123, 120, 122, 119, 121, 109, 181, 164, -183, + // strip_16 + 123, 125, 122, 124, 121, 182, 181, 184, 183, -186, + // strip_17 + 125, 115, 124, 112, 170, 167, 168, 165, 166, 59, 62, 60, 63, 61, -64, + // strip_18 + 61, 60, 58, 57, 5, 0, 3, 108, 113, 111, 114, 112, -115, + // strip_19 + 60, 59, 57, 54, 0, 162, 108, -111, + // strip_20 + 59, 165, 54, -162, + // strip_21 + 64, 80, 63, 77, 62, 74, 178, 175, 176, 173, -174, + // strip_22 + 112, 111, 167, 162, -165, + // strip_23 + 127, 128, 130, 131, 133, 134, 126, -118, + // strip_24 + 128, 116, 131, 117, 134, -118, + // strip_25 + 159, 156, 157, 154, 155, 202, 205, 203, 206, 204, 207, 214, 215, 212, -198, + // strip_26 + 156, 137, 154, 190, 202, 200, 203, 201, 204, 213, 214, 211, -212, + // strip_27 + 211, 213, -210, + // strip_28 + 62, 178, 166, 169, 168, 171, 170, 185, 182, -184, + // strip_29 + 170, 182, -124, + // strip_30 + 205, 206, 196, 199, 198, -215, + // strip_31 + 206, 207, 199, -215, + // strip_32 + 26, 18, 25, 15, 24, 12, 35, 32, 33, 30, 31, 148, 151, 149, 152, 150, 153, 160, 161, 158, 144, 143, 141, 140, 138, 135, 28, 81, 38, 86, 39, 89, 51, 101, 48, 100, 29, 83, 55, 65, -67, + // strip_33 + 26, 25, 23, 22, 20, 19, 67, -55, + // strip_34 + 25, 24, 22, 21, 19, 2, 55, -29, + // strip_35 + 65, 83, 102, 100, 103, 101, 104, 89, 90, 87, 88, 85, 97, -197, + // strip_36 + 89, 86, 87, 84, 85, 194, 197, -195, + // strip_37 + 86, 81, 84, 189, 194, 192, 195, -193, + // strip_38 + 81, 135, 189, -192, + // strip_39 + 135, 140, 192, -193, + // strip_40 + 140, 143, -193, + // strip_41 + 29, 2, 46, 21, 47, 24, -35, + // strip_42 + 29, 46, 48, 49, 51, 52, 42, 45, 44, 37, 34, 36, 33, -35, + // strip_43 + 33, 31, 34, 43, 44, 41, 42, 39, -51, + // strip_44 + 31, 151, 43, 139, 40, 138, -28, + // strip_45 + 28, 38, 40, 41, -43, + // strip_46 + 39, 41, -38, + // strip_47 + 46, 47, 49, 50, 52, 53, 45, -37, + // strip_48 + 47, 35, 50, 36, 53, -37, + // strip_49 + 138, 139, 141, 142, 144, 145, 161, -153, + // strip_50 + 139, 151, 142, 152, 145, -153, + // strip_51 + 169, 178, 179, 176, 177, 174, -186, + // strip_52 + 186, 184, 187, 185, 188, 171, 172, 169, -179, + // strip_53 + 186, 187, 177, 180, 179, -172, + // strip_54 + 187, 188, 180, -172, +}; + +static const vec3 vertices[] = { + {-0.9000000, -0.9000000, -1.0000000}, + {-0.9000000, -1.0000000, -0.9000000}, + {-1.0000000, -0.9000000, -0.9000000}, + {-0.9000000, -0.9309075, -0.9951038}, + {-0.9000000, -0.9587687, -0.9809088}, + {-0.9309074, -0.9000000, -0.9951038}, + {-0.9317268, -0.9319055, -0.9893054}, + {-0.9306927, -0.9574144, -0.9759048}, + {-0.9587687, -0.9000000, -0.9809088}, + {-0.9574655, -0.9307720, -0.9758340}, + {-0.9529119, -0.9529119, -0.9663376}, + {-0.9309075, -0.9951038, -0.9000000}, + {-0.9587687, -0.9809088, -0.9000000}, + {-0.9000000, -0.9951038, -0.9309074}, + {-0.9319055, -0.9893054, -0.9317268}, + {-0.9574144, -0.9759048, -0.9306927}, + {-0.9000000, -0.9809088, -0.9587687}, + {-0.9307720, -0.9758340, -0.9574655}, + {-0.9529119, -0.9663376, -0.9529119}, + {-0.9951038, -0.9000000, -0.9309075}, + {-0.9809088, -0.9000000, -0.9587687}, + {-0.9951038, -0.9309074, -0.9000000}, + {-0.9893054, -0.9317268, -0.9319055}, + {-0.9759048, -0.9306927, -0.9574144}, + {-0.9809088, -0.9587687, -0.9000000}, + {-0.9758340, -0.9574655, -0.9307720}, + {-0.9663376, -0.9529119, -0.9529119}, + {-0.9000000, -1.0000000, 0.9000000}, + {-0.9000000, -0.9000000, 1.0000000}, + {-1.0000000, -0.9000000, 0.9000000}, + {-0.9000000, -0.9951038, 0.9309075}, + {-0.9000000, -0.9809088, 0.9587687}, + {-0.9309074, -0.9951038, 0.9000000}, + {-0.9317268, -0.9893054, 0.9319055}, + {-0.9306927, -0.9759048, 0.9574144}, + {-0.9587687, -0.9809088, 0.9000000}, + {-0.9574655, -0.9758340, 0.9307720}, + {-0.9529119, -0.9663376, 0.9529119}, + {-0.9309075, -0.9000000, 0.9951038}, + {-0.9587687, -0.9000000, 0.9809088}, + {-0.9000000, -0.9309074, 0.9951038}, + {-0.9319055, -0.9317268, 0.9893054}, + {-0.9574144, -0.9306927, 0.9759048}, + {-0.9000000, -0.9587687, 0.9809088}, + {-0.9307720, -0.9574655, 0.9758340}, + {-0.9529119, -0.9529119, 0.9663376}, + {-0.9951038, -0.9309075, 0.9000000}, + {-0.9809088, -0.9587687, 0.9000000}, + {-0.9951038, -0.9000000, 0.9309074}, + {-0.9893054, -0.9319055, 0.9317268}, + {-0.9759048, -0.9574144, 0.9306927}, + {-0.9809088, -0.9000000, 0.9587687}, + {-0.9758340, -0.9307720, 0.9574655}, + {-0.9663376, -0.9529119, 0.9529119}, + {-0.9000000, 0.9000000, -1.0000000}, + {-1.0000000, 0.9000000, -0.9000000}, + {-0.9000000, 1.0000000, -0.9000000}, + {-0.9309075, 0.9000000, -0.9951038}, + {-0.9587687, 0.9000000, -0.9809088}, + {-0.9000000, 0.9309074, -0.9951038}, + {-0.9319055, 0.9317268, -0.9893054}, + {-0.9574144, 0.9306927, -0.9759048}, + {-0.9000000, 0.9587687, -0.9809088}, + {-0.9307720, 0.9574655, -0.9758340}, + {-0.9529119, 0.9529119, -0.9663376}, + {-0.9951038, 0.9309075, -0.9000000}, + {-0.9809088, 0.9587687, -0.9000000}, + {-0.9951038, 0.9000000, -0.9309074}, + {-0.9893054, 0.9319055, -0.9317268}, + {-0.9759048, 0.9574144, -0.9306927}, + {-0.9809088, 0.9000000, -0.9587687}, + {-0.9758340, 0.9307720, -0.9574655}, + {-0.9663376, 0.9529119, -0.9529119}, + {-0.9000000, 0.9951038, -0.9309075}, + {-0.9000000, 0.9809088, -0.9587687}, + {-0.9309074, 0.9951038, -0.9000000}, + {-0.9317268, 0.9893054, -0.9319055}, + {-0.9306927, 0.9759048, -0.9574144}, + {-0.9587687, 0.9809088, -0.9000000}, + {-0.9574655, 0.9758340, -0.9307720}, + {-0.9529119, 0.9663376, -0.9529119}, + {-0.9000000, 0.9000000, 1.0000000}, + {-0.9000000, 1.0000000, 0.9000000}, + {-1.0000000, 0.9000000, 0.9000000}, + {-0.9000000, 0.9309075, 0.9951038}, + {-0.9000000, 0.9587687, 0.9809088}, + {-0.9309074, 0.9000000, 0.9951038}, + {-0.9317268, 0.9319055, 0.9893054}, + {-0.9306927, 0.9574144, 0.9759048}, + {-0.9587687, 0.9000000, 0.9809088}, + {-0.9574655, 0.9307720, 0.9758340}, + {-0.9529119, 0.9529119, 0.9663376}, + {-0.9309075, 0.9951038, 0.9000000}, + {-0.9587687, 0.9809088, 0.9000000}, + {-0.9000000, 0.9951038, 0.9309074}, + {-0.9319055, 0.9893054, 0.9317268}, + {-0.9574144, 0.9759048, 0.9306927}, + {-0.9000000, 0.9809088, 0.9587687}, + {-0.9307720, 0.9758340, 0.9574655}, + {-0.9529119, 0.9663376, 0.9529119}, + {-0.9951038, 0.9000000, 0.9309075}, + {-0.9809088, 0.9000000, 0.9587687}, + {-0.9951038, 0.9309074, 0.9000000}, + {-0.9893054, 0.9317268, 0.9319055}, + {-0.9759048, 0.9306927, 0.9574144}, + {-0.9809088, 0.9587687, 0.9000000}, + {-0.9758340, 0.9574655, 0.9307720}, + {-0.9663376, 0.9529119, 0.9529119}, + {0.9000000, -0.9000000, -1.0000000}, + {1.0000000, -0.9000000, -0.9000000}, + {0.9000000, -1.0000000, -0.9000000}, + {0.9309075, -0.9000000, -0.9951038}, + {0.9587687, -0.9000000, -0.9809088}, + {0.9000000, -0.9309074, -0.9951038}, + {0.9319055, -0.9317268, -0.9893054}, + {0.9574144, -0.9306927, -0.9759048}, + {0.9000000, -0.9587687, -0.9809088}, + {0.9307720, -0.9574655, -0.9758340}, + {0.9529119, -0.9529119, -0.9663376}, + {0.9951038, -0.9309075, -0.9000000}, + {0.9809088, -0.9587687, -0.9000000}, + {0.9951038, -0.9000000, -0.9309074}, + {0.9893054, -0.9319055, -0.9317268}, + {0.9759048, -0.9574144, -0.9306927}, + {0.9809088, -0.9000000, -0.9587687}, + {0.9758340, -0.9307720, -0.9574655}, + {0.9663376, -0.9529119, -0.9529119}, + {0.9000000, -0.9951038, -0.9309075}, + {0.9000000, -0.9809088, -0.9587687}, + {0.9309074, -0.9951038, -0.9000000}, + {0.9317268, -0.9893054, -0.9319055}, + {0.9306927, -0.9759048, -0.9574144}, + {0.9587687, -0.9809088, -0.9000000}, + {0.9574655, -0.9758340, -0.9307720}, + {0.9529119, -0.9663376, -0.9529119}, + {0.9000000, -0.9000000, 1.0000000}, + {0.9000000, -1.0000000, 0.9000000}, + {1.0000000, -0.9000000, 0.9000000}, + {0.9000000, -0.9309075, 0.9951038}, + {0.9000000, -0.9587687, 0.9809088}, + {0.9309074, -0.9000000, 0.9951038}, + {0.9317268, -0.9319055, 0.9893054}, + {0.9306927, -0.9574144, 0.9759048}, + {0.9587687, -0.9000000, 0.9809088}, + {0.9574655, -0.9307720, 0.9758340}, + {0.9529119, -0.9529119, 0.9663376}, + {0.9309075, -0.9951038, 0.9000000}, + {0.9587687, -0.9809088, 0.9000000}, + {0.9000000, -0.9951038, 0.9309074}, + {0.9319055, -0.9893054, 0.9317268}, + {0.9574144, -0.9759048, 0.9306927}, + {0.9000000, -0.9809088, 0.9587687}, + {0.9307720, -0.9758340, 0.9574655}, + {0.9529119, -0.9663376, 0.9529119}, + {0.9951038, -0.9000000, 0.9309075}, + {0.9809088, -0.9000000, 0.9587687}, + {0.9951038, -0.9309074, 0.9000000}, + {0.9893054, -0.9317268, 0.9319055}, + {0.9759048, -0.9306927, 0.9574144}, + {0.9809088, -0.9587687, 0.9000000}, + {0.9758340, -0.9574655, 0.9307720}, + {0.9663376, -0.9529119, 0.9529119}, + {0.9000000, 0.9000000, -1.0000000}, + {0.9000000, 1.0000000, -0.9000000}, + {1.0000000, 0.9000000, -0.9000000}, + {0.9000000, 0.9309075, -0.9951038}, + {0.9000000, 0.9587687, -0.9809088}, + {0.9309074, 0.9000000, -0.9951038}, + {0.9317268, 0.9319055, -0.9893054}, + {0.9306927, 0.9574144, -0.9759048}, + {0.9587687, 0.9000000, -0.9809088}, + {0.9574655, 0.9307720, -0.9758340}, + {0.9529119, 0.9529119, -0.9663376}, + {0.9309075, 0.9951038, -0.9000000}, + {0.9587687, 0.9809088, -0.9000000}, + {0.9000000, 0.9951038, -0.9309074}, + {0.9319055, 0.9893054, -0.9317268}, + {0.9574144, 0.9759048, -0.9306927}, + {0.9000000, 0.9809088, -0.9587687}, + {0.9307720, 0.9758340, -0.9574655}, + {0.9529119, 0.9663376, -0.9529119}, + {0.9951038, 0.9000000, -0.9309075}, + {0.9809088, 0.9000000, -0.9587687}, + {0.9951038, 0.9309074, -0.9000000}, + {0.9893054, 0.9317268, -0.9319055}, + {0.9759048, 0.9306927, -0.9574144}, + {0.9809088, 0.9587687, -0.9000000}, + {0.9758340, 0.9574655, -0.9307720}, + {0.9663376, 0.9529119, -0.9529119}, + {0.9000000, 0.9000000, 1.0000000}, + {1.0000000, 0.9000000, 0.9000000}, + {0.9000000, 1.0000000, 0.9000000}, + {0.9309075, 0.9000000, 0.9951038}, + {0.9587687, 0.9000000, 0.9809088}, + {0.9000000, 0.9309074, 0.9951038}, + {0.9319055, 0.9317268, 0.9893054}, + {0.9574144, 0.9306927, 0.9759048}, + {0.9000000, 0.9587687, 0.9809088}, + {0.9307720, 0.9574655, 0.9758340}, + {0.9529119, 0.9529119, 0.9663376}, + {0.9951038, 0.9309075, 0.9000000}, + {0.9809088, 0.9587687, 0.9000000}, + {0.9951038, 0.9000000, 0.9309074}, + {0.9893054, 0.9319055, 0.9317268}, + {0.9759048, 0.9574144, 0.9306927}, + {0.9809088, 0.9000000, 0.9587687}, + {0.9758340, 0.9307720, 0.9574655}, + {0.9663376, 0.9529119, 0.9529119}, + {0.9000000, 0.9951038, 0.9309075}, + {0.9000000, 0.9809088, 0.9587687}, + {0.9309074, 0.9951038, 0.9000000}, + {0.9317268, 0.9893054, 0.9319055}, + {0.9306927, 0.9759048, 0.9574144}, + {0.9587687, 0.9809088, 0.9000000}, + {0.9574655, 0.9758340, 0.9307720}, + {0.9529119, 0.9663376, 0.9529119}, +}; + +static const vec3 normals[] = { + {-0.0779369, -0.0779360, -0.9939074}, + {-0.0779360, -0.9939074, -0.0779369}, + {-0.9939072, -0.0779380, -0.0779372}, + {-0.0783546, -0.3064310, -0.9486625}, + {-0.0753902, -0.5855243, -0.8071417}, + {-0.3066674, -0.0787251, -0.9485555}, + {-0.3093096, -0.3102272, -0.8989365}, + {-0.2872533, -0.5712489, -0.7688694}, + {-0.5853158, -0.0757397, -0.8072601}, + {-0.5713511, -0.2876457, -0.7686467}, + {-0.5149081, -0.5150670, -0.6852559}, + {-0.3064311, -0.9486625, -0.0783546}, + {-0.5855243, -0.8071417, -0.0753902}, + {-0.0787251, -0.9485555, -0.3066674}, + {-0.3102272, -0.8989365, -0.3093096}, + {-0.5712489, -0.7688695, -0.2872533}, + {-0.0757397, -0.8072602, -0.5853158}, + {-0.2876457, -0.7686467, -0.5713511}, + {-0.5150670, -0.6852559, -0.5149082}, + {-0.9486625, -0.0783546, -0.3064310}, + {-0.8071417, -0.0753902, -0.5855243}, + {-0.9485555, -0.3066674, -0.0787251}, + {-0.8989365, -0.3093096, -0.3102272}, + {-0.7688694, -0.2872533, -0.5712489}, + {-0.8072601, -0.5853157, -0.0757397}, + {-0.7686467, -0.5713511, -0.2876457}, + {-0.6852559, -0.5149081, -0.5150669}, + {-0.0779375, -0.9939072, 0.0779376}, + {-0.0779376, -0.0779375, 0.9939072}, + {-0.9939074, -0.0779365, 0.0779364}, + {-0.0783542, -0.9486627, 0.3064306}, + {-0.0753906, -0.8071429, 0.5855225}, + {-0.3066655, -0.9485560, 0.0787252}, + {-0.3093096, -0.8989362, 0.3102278}, + {-0.2872531, -0.7688694, 0.5712491}, + {-0.5853159, -0.8072601, 0.0757390}, + {-0.5713505, -0.7686472, 0.2876458}, + {-0.5149055, -0.6852569, 0.5150683}, + {-0.3064306, -0.0783542, 0.9486628}, + {-0.5855225, -0.0753906, 0.8071429}, + {-0.0787252, -0.3066655, 0.9485560}, + {-0.3102278, -0.3093096, 0.8989362}, + {-0.5712491, -0.2872531, 0.7688694}, + {-0.0757390, -0.5853159, 0.8072601}, + {-0.2876458, -0.5713505, 0.7686472}, + {-0.5150683, -0.5149055, 0.6852570}, + {-0.9486626, -0.3064307, 0.0783543}, + {-0.8071429, -0.5855225, 0.0753906}, + {-0.9485561, -0.0787252, 0.3066655}, + {-0.8989362, -0.3102278, 0.3093096}, + {-0.7688693, -0.5712490, 0.2872531}, + {-0.8072600, -0.0757390, 0.5853159}, + {-0.7686472, -0.2876458, 0.5713505}, + {-0.6852570, -0.5150683, 0.5149055}, + {-0.0779376, 0.0779375, -0.9939072}, + {-0.9939074, 0.0779365, -0.0779364}, + {-0.0779375, 0.9939072, -0.0779376}, + {-0.3064306, 0.0783542, -0.9486628}, + {-0.5855225, 0.0753906, -0.8071429}, + {-0.0787252, 0.3066655, -0.9485560}, + {-0.3102278, 0.3093096, -0.8989362}, + {-0.5712491, 0.2872531, -0.7688694}, + {-0.0757390, 0.5853159, -0.8072600}, + {-0.2876458, 0.5713505, -0.7686472}, + {-0.5150683, 0.5149055, -0.6852570}, + {-0.9486626, 0.3064307, -0.0783543}, + {-0.8071429, 0.5855225, -0.0753906}, + {-0.9485561, 0.0787252, -0.3066655}, + {-0.8989362, 0.3102278, -0.3093096}, + {-0.7688693, 0.5712490, -0.2872531}, + {-0.8072600, 0.0757390, -0.5853159}, + {-0.7686472, 0.2876458, -0.5713505}, + {-0.6852570, 0.5150683, -0.5149055}, + {-0.0783542, 0.9486627, -0.3064306}, + {-0.0753906, 0.8071429, -0.5855225}, + {-0.3066655, 0.9485560, -0.0787252}, + {-0.3093096, 0.8989362, -0.3102278}, + {-0.2872531, 0.7688694, -0.5712491}, + {-0.5853159, 0.8072601, -0.0757390}, + {-0.5713505, 0.7686472, -0.2876457}, + {-0.5149055, 0.6852569, -0.5150683}, + {-0.0779369, 0.0779360, 0.9939074}, + {-0.0779360, 0.9939074, 0.0779369}, + {-0.9939072, 0.0779380, 0.0779371}, + {-0.0783546, 0.3064310, 0.9486625}, + {-0.0753902, 0.5855243, 0.8071417}, + {-0.3066674, 0.0787251, 0.9485555}, + {-0.3093096, 0.3102272, 0.8989365}, + {-0.2872533, 0.5712489, 0.7688694}, + {-0.5853158, 0.0757397, 0.8072601}, + {-0.5713511, 0.2876457, 0.7686467}, + {-0.5149081, 0.5150670, 0.6852559}, + {-0.3064311, 0.9486625, 0.0783546}, + {-0.5855243, 0.8071417, 0.0753902}, + {-0.0787251, 0.9485555, 0.3066674}, + {-0.3102272, 0.8989365, 0.3093096}, + {-0.5712489, 0.7688695, 0.2872533}, + {-0.0757397, 0.8072602, 0.5853158}, + {-0.2876457, 0.7686467, 0.5713511}, + {-0.5150670, 0.6852559, 0.5149082}, + {-0.9486625, 0.0783546, 0.3064310}, + {-0.8071417, 0.0753902, 0.5855243}, + {-0.9485555, 0.3066674, 0.0787251}, + {-0.8989365, 0.3093096, 0.3102272}, + {-0.7688694, 0.2872533, 0.5712489}, + {-0.8072601, 0.5853157, 0.0757397}, + {-0.7686467, 0.5713511, 0.2876457}, + {-0.6852559, 0.5149081, 0.5150669}, + {0.0779376, -0.0779375, -0.9939072}, + {0.9939074, -0.0779365, -0.0779364}, + {0.0779375, -0.9939072, -0.0779376}, + {0.3064306, -0.0783542, -0.9486628}, + {0.5855225, -0.0753906, -0.8071429}, + {0.0787252, -0.3066655, -0.9485560}, + {0.3102278, -0.3093096, -0.8989362}, + {0.5712491, -0.2872531, -0.7688694}, + {0.0757390, -0.5853159, -0.8072600}, + {0.2876458, -0.5713505, -0.7686472}, + {0.5150683, -0.5149055, -0.6852570}, + {0.9486626, -0.3064307, -0.0783543}, + {0.8071429, -0.5855225, -0.0753906}, + {0.9485561, -0.0787252, -0.3066655}, + {0.8989362, -0.3102278, -0.3093096}, + {0.7688693, -0.5712490, -0.2872531}, + {0.8072600, -0.0757390, -0.5853159}, + {0.7686472, -0.2876458, -0.5713505}, + {0.6852570, -0.5150683, -0.5149055}, + {0.0783542, -0.9486627, -0.3064306}, + {0.0753906, -0.8071429, -0.5855225}, + {0.3066655, -0.9485560, -0.0787252}, + {0.3093096, -0.8989362, -0.3102278}, + {0.2872531, -0.7688694, -0.5712491}, + {0.5853159, -0.8072601, -0.0757390}, + {0.5713505, -0.7686472, -0.2876457}, + {0.5149055, -0.6852569, -0.5150683}, + {0.0779369, -0.0779360, 0.9939074}, + {0.0779360, -0.9939074, 0.0779369}, + {0.9939072, -0.0779380, 0.0779371}, + {0.0783546, -0.3064310, 0.9486625}, + {0.0753902, -0.5855243, 0.8071417}, + {0.3066674, -0.0787251, 0.9485555}, + {0.3093096, -0.3102272, 0.8989365}, + {0.2872533, -0.5712489, 0.7688694}, + {0.5853158, -0.0757397, 0.8072601}, + {0.5713511, -0.2876457, 0.7686467}, + {0.5149081, -0.5150670, 0.6852559}, + {0.3064311, -0.9486625, 0.0783546}, + {0.5855243, -0.8071417, 0.0753902}, + {0.0787251, -0.9485555, 0.3066674}, + {0.3102272, -0.8989365, 0.3093096}, + {0.5712489, -0.7688695, 0.2872533}, + {0.0757397, -0.8072602, 0.5853158}, + {0.2876457, -0.7686467, 0.5713511}, + {0.5150670, -0.6852559, 0.5149082}, + {0.9486625, -0.0783546, 0.3064310}, + {0.8071417, -0.0753902, 0.5855243}, + {0.9485555, -0.3066674, 0.0787251}, + {0.8989365, -0.3093096, 0.3102272}, + {0.7688694, -0.2872533, 0.5712489}, + {0.8072601, -0.5853157, 0.0757397}, + {0.7686467, -0.5713511, 0.2876457}, + {0.6852559, -0.5149081, 0.5150669}, + {0.0779369, 0.0779360, -0.9939074}, + {0.0779360, 0.9939074, -0.0779369}, + {0.9939072, 0.0779380, -0.0779372}, + {0.0783546, 0.3064310, -0.9486625}, + {0.0753902, 0.5855243, -0.8071417}, + {0.3066674, 0.0787251, -0.9485555}, + {0.3093096, 0.3102272, -0.8989365}, + {0.2872533, 0.5712489, -0.7688694}, + {0.5853158, 0.0757397, -0.8072601}, + {0.5713511, 0.2876457, -0.7686467}, + {0.5149081, 0.5150670, -0.6852559}, + {0.3064311, 0.9486625, -0.0783547}, + {0.5855243, 0.8071417, -0.0753902}, + {0.0787251, 0.9485555, -0.3066674}, + {0.3102272, 0.8989365, -0.3093096}, + {0.5712489, 0.7688695, -0.2872533}, + {0.0757397, 0.8072602, -0.5853158}, + {0.2876457, 0.7686467, -0.5713511}, + {0.5150670, 0.6852559, -0.5149082}, + {0.9486625, 0.0783546, -0.3064310}, + {0.8071417, 0.0753902, -0.5855243}, + {0.9485555, 0.3066674, -0.0787251}, + {0.8989365, 0.3093096, -0.3102272}, + {0.7688694, 0.2872533, -0.5712489}, + {0.8072600, 0.5853158, -0.0757397}, + {0.7686467, 0.5713511, -0.2876457}, + {0.6852559, 0.5149081, -0.5150669}, + {0.0779376, 0.0779375, 0.9939072}, + {0.9939074, 0.0779365, 0.0779364}, + {0.0779375, 0.9939072, 0.0779376}, + {0.3064306, 0.0783542, 0.9486628}, + {0.5855225, 0.0753906, 0.8071429}, + {0.0787252, 0.3066655, 0.9485560}, + {0.3102278, 0.3093096, 0.8989362}, + {0.5712491, 0.2872531, 0.7688694}, + {0.0757390, 0.5853159, 0.8072600}, + {0.2876458, 0.5713505, 0.7686472}, + {0.5150683, 0.5149055, 0.6852570}, + {0.9486626, 0.3064306, 0.0783542}, + {0.8071429, 0.5855225, 0.0753906}, + {0.9485561, 0.0787252, 0.3066655}, + {0.8989362, 0.3102278, 0.3093096}, + {0.7688693, 0.5712490, 0.2872531}, + {0.8072600, 0.0757390, 0.5853159}, + {0.7686472, 0.2876458, 0.5713505}, + {0.6852570, 0.5150683, 0.5149055}, + {0.0783542, 0.9486627, 0.3064306}, + {0.0753906, 0.8071429, 0.5855225}, + {0.3066655, 0.9485561, 0.0787252}, + {0.3093096, 0.8989362, 0.3102278}, + {0.2872531, 0.7688694, 0.5712491}, + {0.5853160, 0.8072601, 0.0757390}, + {0.5713505, 0.7686472, 0.2876457}, + {0.5149055, 0.6852569, 0.5150683}, +}; diff --git a/dreamcast2/example/model/icosphere.h b/dreamcast2/example/model/icosphere.h new file mode 100644 index 0000000..49946f5 --- /dev/null +++ b/dreamcast2/example/model/icosphere.h @@ -0,0 +1,124 @@ +static const int strips[] = { + // strip_0 + 0, 13, 12, 14, 2, 24, 27, 33, 7, 39, 34, 40, 8, 35, 28, 31, 4, 21, 19, 16, 0, -13, + // strip_1 + 0, 12, 17, 18, 3, 26, 29, 34, -8, + // strip_2 + 0, 17, 19, 20, 4, -28, + // strip_3 + 34, 26, 7, -27, + // strip_4 + 26, 18, 27, -2, + // strip_5 + 12, 2, -18, + // strip_6 + 8, 28, 29, 20, 3, -17, + // strip_7 + 13, 16, 15, 5, 23, 30, 36, 9, 41, 35, -40, + // strip_8 + 16, 21, 5, -30, + // strip_9 + 21, 31, 30, -9, + // strip_10 + 31, 35, -9, + // strip_11 + 14, 13, 1, 15, 22, 23, 10, 36, 38, 41, 11, 40, -39, + // strip_12 + 14, 1, 25, 22, 32, 10, -38, + // strip_13 + 14, 25, 24, 6, 33, 37, 39, -11, + // strip_14 + 25, 32, 6, -37, + // strip_15 + 32, 38, 37, -11, +}; + +static const vec3 vertices[] = { + {0.0000000, 0.0000000, -1.0000000}, + {0.7236073, -0.5257253, -0.4472195}, + {-0.2763880, -0.8506492, -0.4472198}, + {-0.8944262, 0.0000000, -0.4472156}, + {-0.2763880, 0.8506492, -0.4472198}, + {0.7236073, 0.5257253, -0.4472195}, + {0.2763880, -0.8506492, 0.4472198}, + {-0.7236073, -0.5257253, 0.4472195}, + {-0.7236073, 0.5257253, 0.4472195}, + {0.2763880, 0.8506492, 0.4472198}, + {0.8944262, 0.0000000, 0.4472156}, + {0.0000000, 0.0000000, 1.0000000}, + {-0.1624556, -0.4999953, -0.8506544}, + {0.4253227, -0.3090114, -0.8506542}, + {0.2628688, -0.8090116, -0.5257376}, + {0.8506479, 0.0000000, -0.5257359}, + {0.4253227, 0.3090114, -0.8506542}, + {-0.5257298, 0.0000000, -0.8506517}, + {-0.6881894, -0.4999969, -0.5257362}, + {-0.1624556, 0.4999953, -0.8506544}, + {-0.6881894, 0.4999969, -0.5257362}, + {0.2628688, 0.8090116, -0.5257376}, + {0.9510579, -0.3090126, 0.0000000}, + {0.9510579, 0.3090126, 0.0000000}, + {0.0000000, -0.9999999, 0.0000000}, + {0.5877856, -0.8090167, 0.0000000}, + {-0.9510579, -0.3090126, 0.0000000}, + {-0.5877856, -0.8090167, 0.0000000}, + {-0.5877856, 0.8090167, 0.0000000}, + {-0.9510579, 0.3090126, 0.0000000}, + {0.5877856, 0.8090167, 0.0000000}, + {0.0000000, 0.9999999, 0.0000000}, + {0.6881894, -0.4999969, 0.5257362}, + {-0.2628688, -0.8090116, 0.5257376}, + {-0.8506479, 0.0000000, 0.5257359}, + {-0.2628688, 0.8090116, 0.5257376}, + {0.6881894, 0.4999969, 0.5257362}, + {0.1624556, -0.4999953, 0.8506544}, + {0.5257298, 0.0000000, 0.8506517}, + {-0.4253227, -0.3090114, 0.8506542}, + {-0.4253227, 0.3090114, 0.8506542}, + {0.1624556, 0.4999953, 0.8506544}, +}; + +static const vec3 normals[] = { + {-0.0000014, 0.0000000, -1.0000000}, + {0.7236077, -0.5257269, -0.4472172}, + {-0.2763892, -0.8506496, -0.4472183}, + {-0.8944264, 0.0000000, -0.4472152}, + {-0.2763892, 0.8506495, -0.4472184}, + {0.7236077, 0.5257269, -0.4472172}, + {0.2763892, -0.8506496, 0.4472184}, + {-0.7236077, -0.5257268, 0.4472171}, + {-0.7236077, 0.5257269, 0.4472172}, + {0.2763892, 0.8506496, 0.4472184}, + {0.8944264, 0.0000000, 0.4472152}, + {0.0000014, 0.0000000, 1.0000000}, + {-0.1624570, -0.4999964, -0.8506535}, + {0.4253235, -0.3090130, -0.8506532}, + {0.2628689, -0.8090131, -0.5257353}, + {0.8506489, 0.0000000, -0.5257344}, + {0.4253235, 0.3090130, -0.8506532}, + {-0.5257297, -0.0000000, -0.8506517}, + {-0.6881894, -0.4999988, -0.5257342}, + {-0.1624570, 0.4999964, -0.8506535}, + {-0.6881894, 0.4999988, -0.5257342}, + {0.2628689, 0.8090131, -0.5257353}, + {0.9510571, -0.3090152, -0.0000002}, + {0.9510571, 0.3090152, -0.0000002}, + {0.0000000, -1.0000000, -0.0000000}, + {0.5877860, -0.8090164, 0.0000002}, + {-0.9510571, -0.3090152, 0.0000002}, + {-0.5877860, -0.8090164, -0.0000002}, + {-0.5877860, 0.8090164, -0.0000002}, + {-0.9510571, 0.3090152, 0.0000002}, + {0.5877861, 0.8090164, 0.0000002}, + {0.0000000, 1.0000000, -0.0000000}, + {0.6881894, -0.4999988, 0.5257343}, + {-0.2628689, -0.8090131, 0.5257354}, + {-0.8506489, -0.0000000, 0.5257344}, + {-0.2628689, 0.8090131, 0.5257353}, + {0.6881894, 0.4999987, 0.5257342}, + {0.1624570, -0.4999964, 0.8506535}, + {0.5257297, 0.0000000, 0.8506517}, + {-0.4253235, -0.3090130, 0.8506532}, + {-0.4253234, 0.3090130, 0.8506532}, + {0.1624570, 0.4999964, 0.8506535}, +}; diff --git a/dreamcast2/example/model/suzanne.h b/dreamcast2/example/model/suzanne.h index bcc7f9e..55e22c7 100644 --- a/dreamcast2/example/model/suzanne.h +++ b/dreamcast2/example/model/suzanne.h @@ -818,3 +818,514 @@ static const vec3 vertices[] = { {0.8593750, 0.3828125, 0.3828125}, {-0.8593750, 0.3828125, 0.3828125}, }; + +static const vec3 normals[] = { + {0.7116418, -0.1793450, -0.6792653}, + {-0.7116418, -0.1793449, -0.6792653}, + {0.6053073, -0.6146231, -0.5058077}, + {-0.6053073, -0.6146231, -0.5058077}, + {0.6836696, -0.4827453, -0.5473143}, + {-0.6836695, -0.4827453, -0.5473143}, + {0.1094815, -0.4753184, -0.8729755}, + {-0.1094815, -0.4753184, -0.8729755}, + {0.0968995, -0.6531068, -0.7510406}, + {-0.0968995, -0.6531068, -0.7510406}, + {0.0487559, -0.2555731, -0.9655595}, + {-0.0487559, -0.2555730, -0.9655595}, + {-0.6411769, -0.3256359, -0.6948767}, + {0.6411769, -0.3256358, -0.6948767}, + {-0.4592703, -0.7059537, -0.5391661}, + {0.4592703, -0.7059537, -0.5391661}, + {-0.5482250, -0.5447102, -0.6346181}, + {0.5482250, -0.5447103, -0.6346181}, + {-0.8097197, -0.5867752, -0.0069870}, + {0.8097197, -0.5867752, -0.0069870}, + {-0.6909685, -0.7228582, -0.0062136}, + {0.6909685, -0.7228582, -0.0062136}, + {-0.9538676, -0.3001271, -0.0077690}, + {0.9538676, -0.3001270, -0.0077690}, + {-0.6575786, -0.3099492, 0.6866745}, + {0.6575787, -0.3099492, 0.6866745}, + {-0.4560633, -0.7187719, 0.5247602}, + {0.4560633, -0.7187719, 0.5247602}, + {-0.5305916, -0.5717299, 0.6257775}, + {0.5305916, -0.5717299, 0.6257775}, + {0.1257523, -0.5252544, 0.8416021}, + {-0.1257523, -0.5252544, 0.8416021}, + {0.1030727, -0.6644185, 0.7402189}, + {-0.1030727, -0.6644185, 0.7402189}, + {0.0257564, -0.2311724, 0.9725718}, + {-0.0257564, -0.2311724, 0.9725718}, + {0.7363888, -0.1803049, 0.6520903}, + {-0.7363887, -0.1803049, 0.6520903}, + {0.6102186, -0.6180766, 0.4955952}, + {-0.6102186, -0.6180766, 0.4955951}, + {0.6682232, -0.5147883, 0.5370947}, + {-0.6682232, -0.5147883, 0.5370947}, + {0.8691105, -0.4946063, -0.0033997}, + {-0.8691105, -0.4946064, -0.0033997}, + {0.7999730, -0.6000354, -0.0007937}, + {-0.7999730, -0.6000354, -0.0007938}, + {0.9705383, -0.2409454, -0.0008272}, + {-0.9705383, -0.2409454, -0.0008272}, + {0.9635527, -0.2675057, -0.0026134}, + {-0.9635527, -0.2675057, -0.0026134}, + {0.7216295, -0.2224212, 0.6555758}, + {-0.7216295, -0.2224212, 0.6555758}, + {0.0431597, -0.3414669, 0.9389023}, + {-0.0431597, -0.3414670, 0.9389023}, + {-0.6236874, -0.4647028, 0.6285424}, + {0.6236873, -0.4647028, 0.6285423}, + {-0.9255452, -0.3786369, 0.0004986}, + {0.9255451, -0.3786369, 0.0004986}, + {-0.5992141, -0.4639659, -0.6524401}, + {0.5992141, -0.4639659, -0.6524400}, + {0.1836297, -0.9829810, -0.0053294}, + {-0.1836297, -0.9829810, -0.0053294}, + {0.0303101, -0.3364834, -0.9412015}, + {-0.0303101, -0.3364835, -0.9412015}, + {0.7106176, -0.2273696, -0.6658270}, + {-0.7106177, -0.2273696, -0.6658270}, + {0.0000000, -0.3816463, 0.9243085}, + {0.0000000, -0.9991772, -0.0405553}, + {0.0000000, -0.9994190, -0.0340827}, + {0.0000000, -0.5010811, -0.8654003}, + {-0.2224921, -0.4986964, 0.8377346}, + {-0.0000000, -0.2732406, -0.9619457}, + {0.0000000, -0.4619505, 0.8869057}, + {0.0000000, -0.8383862, 0.5450766}, + {0.0000000, 0.5323898, 0.8464993}, + {-0.0000000, 0.9389296, 0.3441094}, + {0.0000000, 0.9523703, -0.3049438}, + {0.0000000, 0.3414160, -0.9399123}, + {0.9254966, -0.1944435, -0.3250348}, + {-0.9254966, -0.1944435, -0.3250348}, + {0.9541827, -0.1488797, 0.2595578}, + {-0.9541827, -0.1488797, 0.2595578}, + {0.9781803, -0.1916998, 0.0800901}, + {-0.9781803, -0.1916998, 0.0800901}, + {0.9384460, -0.0142561, -0.3451314}, + {-0.9384460, -0.0142561, -0.3451315}, + {0.6251408, -0.0803596, -0.7763641}, + {-0.6251408, -0.0803596, -0.7763641}, + {0.1454864, -0.1378255, -0.9797131}, + {-0.1454864, -0.1378255, -0.9797131}, + {-0.0000000, -0.2276704, -0.9737382}, + {0.3508350, 0.0179519, -0.9362652}, + {-0.3508350, 0.0179519, -0.9362652}, + {0.6060348, -0.1986769, -0.7702267}, + {-0.6060349, -0.1986769, -0.7702267}, + {0.8967634, 0.1397673, -0.4198577}, + {-0.8967634, 0.1397673, -0.4198577}, + {0.8457707, -0.2993234, 0.4416758}, + {-0.8457707, -0.2993234, 0.4416759}, + {0.5157970, -0.2141364, 0.8295174}, + {-0.5157970, -0.2141364, 0.8295174}, + {0.6022623, -0.1593803, 0.7822263}, + {-0.6022623, -0.1593803, 0.7822263}, + {0.2261501, -0.1716636, 0.9588471}, + {-0.2261501, -0.1716636, 0.9588471}, + {-0.6039217, -0.2107165, 0.7686853}, + {0.6039217, -0.2107165, 0.7686853}, + {-0.8001339, -0.1864205, 0.5701168}, + {0.8001339, -0.1864205, 0.5701168}, + {0.3582143, -0.8892356, -0.2845042}, + {-0.3582143, -0.8892356, -0.2845042}, + {0.1231472, -0.9826441, -0.1387272}, + {-0.1231471, -0.9826441, -0.1387272}, + {-0.0058607, -0.9705128, -0.2409782}, + {0.0058608, -0.9705128, -0.2409782}, + {0.3458365, -0.8612931, -0.3722514}, + {-0.3458366, -0.8612931, -0.3722515}, + {0.4165575, -0.8137501, -0.4053277}, + {-0.4165576, -0.8137501, -0.4053276}, + {0.4685396, -0.8698990, -0.1540984}, + {-0.4685396, -0.8698990, -0.1540984}, + {0.3553275, -0.9266044, -0.1230724}, + {-0.3553275, -0.9266044, -0.1230724}, + {0.2254187, -0.9049981, -0.3607837}, + {-0.2254187, -0.9049981, -0.3607838}, + {0.2810756, -0.9584455, 0.0487725}, + {-0.2810755, -0.9584455, 0.0487725}, + {0.2672625, -0.9564185, -0.1176200}, + {-0.2672625, -0.9564185, -0.1176200}, + {-0.0000000, -0.8095977, -0.5869851}, + {0.1571504, -0.9807653, -0.1157720}, + {-0.1571504, -0.9807653, -0.1157720}, + {0.1066501, -0.9441408, -0.3118075}, + {-0.1066501, -0.9441408, -0.3118075}, + {-0.0709030, -0.9193332, -0.3870393}, + {0.0709030, -0.9193332, -0.3870392}, + {-0.0000000, -0.9113576, -0.4116155}, + {-1.0000000, 0.0000000, 0.0000000}, + {-0.1464669, -0.7529550, 0.6415654}, + {-0.4409974, -0.6562516, 0.6122542}, + {0.4409974, -0.6562516, 0.6122541}, + {0.8248708, -0.4241618, -0.3737311}, + {-0.8248708, -0.4241617, -0.3737311}, + {0.4956971, -0.7463818, -0.4440703}, + {-0.4956971, -0.7463819, -0.4440704}, + {0.4232974, -0.7439231, -0.5171051}, + {-0.4232974, -0.7439231, -0.5171052}, + {0.4969694, -0.7820258, -0.3761078}, + {-0.4969693, -0.7820258, -0.3761078}, + {0.5666372, -0.7603879, -0.3173841}, + {-0.5666372, -0.7603879, -0.3173841}, + {0.4607019, -0.8756584, -0.1448316}, + {-0.4607019, -0.8756584, -0.1448316}, + {0.4801154, -0.8578390, -0.1833070}, + {-0.4801154, -0.8578390, -0.1833070}, + {0.3118622, -0.9500606, -0.0112639}, + {-0.3118623, -0.9500606, -0.0112639}, + {0.2538028, -0.9431913, 0.2144166}, + {-0.2538028, -0.9431913, 0.2144166}, + {-0.1577591, -0.9733830, 0.1662458}, + {0.1577591, -0.9733829, 0.1662458}, + {-0.0611148, -0.9978111, -0.0252573}, + {0.0611149, -0.9978111, -0.0252573}, + {-0.1206535, -0.9502252, -0.2872539}, + {0.1206535, -0.9502252, -0.2872538}, + {0.5838202, -0.8045327, 0.1090009}, + {-0.5838202, -0.8045327, 0.1090009}, + {0.5565921, -0.8295292, -0.0456796}, + {-0.5565921, -0.8295292, -0.0456796}, + {0.5686149, -0.7927816, -0.2194867}, + {-0.5686150, -0.7927817, -0.2194867}, + {0.3670904, -0.6788069, -0.6359764}, + {-0.3670904, -0.6788069, -0.6359763}, + {0.1460700, -0.6056224, -0.7822309}, + {-0.1460700, -0.6056223, -0.7822309}, + {0.0000000, -0.6502649, -0.7597076}, + {0.0000000, -0.9999322, 0.0116469}, + {-0.0000000, -0.9599553, -0.2801530}, + {0.1104339, -0.9861388, -0.1238330}, + {-0.1104339, -0.9861388, -0.1238330}, + {-0.2213638, -0.9608526, -0.1666140}, + {0.2213638, -0.9608526, -0.1666140}, + {-0.1369803, -0.9782942, -0.1554893}, + {0.1369803, -0.9782942, -0.1554893}, + {0.1927682, -0.9801576, -0.0461683}, + {-0.1927682, -0.9801576, -0.0461683}, + {0.1377873, -0.9904584, 0.0025991}, + {-0.1377873, -0.9904584, 0.0025991}, + {0.0000000, -1.0000000, 0.0000000}, + {0.0000000, -0.8794674, -0.4759592}, + {0.5188406, -0.4272424, -0.7404515}, + {-0.5188406, -0.4272424, -0.7404515}, + {0.9459205, -0.2673042, -0.1838013}, + {-0.9459205, -0.2673041, -0.1838013}, + {0.6227701, -0.1197165, 0.7731917}, + {-0.6227701, -0.1197165, 0.7731917}, + {-0.2379596, -0.1851094, 0.9534724}, + {0.2379596, -0.1851094, 0.9534724}, + {-0.0000000, -0.9842356, 0.1768621}, + {-0.1436999, -0.7960969, 0.5878607}, + {0.1436999, -0.7960967, 0.5878607}, + {0.3675970, -0.8083256, 0.4598719}, + {-0.3675970, -0.8083256, 0.4598719}, + {0.4687915, -0.8574325, -0.2122356}, + {-0.4687917, -0.8574325, -0.2122356}, + {0.2690249, -0.5760131, -0.7719032}, + {-0.2690249, -0.5760131, -0.7719032}, + {-0.0000000, -0.8528421, -0.5221688}, + {0.9277765, -0.1208982, 0.3530075}, + {-0.9277765, -0.1208982, 0.3530075}, + {0.7709850, -0.6340799, -0.0593699}, + {-0.7709851, -0.6340799, -0.0593700}, + {0.6506593, -0.7446542, 0.1487706}, + {-0.6506593, -0.7446542, 0.1487706}, + {0.9420161, -0.0994069, 0.3205059}, + {-0.9420161, -0.0994069, 0.3205059}, + {-0.0000000, -0.8056915, 0.5923353}, + {-0.3669317, -0.7077018, 0.6037543}, + {0.3669318, -0.7077019, 0.6037543}, + {-0.6331984, -0.7739895, -0.0001920}, + {0.6331984, -0.7739896, -0.0001920}, + {-0.1468504, -0.8393554, -0.5233712}, + {0.1468504, -0.8393555, -0.5233712}, + {0.0000000, -0.7201923, -0.6937745}, + {-0.5168294, -0.4875191, -0.7037133}, + {0.5168294, -0.4875191, -0.7037134}, + {-0.6714875, -0.7266991, 0.1449585}, + {0.6714875, -0.7266991, 0.1449585}, + {-0.3190205, -0.8234201, 0.4692604}, + {0.3190205, -0.8234201, 0.4692604}, + {-0.0000000, -0.8496167, 0.5274006}, + {0.1187257, -0.9913912, -0.0552067}, + {-0.1187257, -0.9913912, -0.0552067}, + {-0.0410928, -0.9978148, -0.0517399}, + {0.0410928, -0.9978148, -0.0517400}, + {0.0600079, -0.9978143, 0.0276703}, + {-0.0600079, -0.9978143, 0.0276703}, + {0.1746861, -0.9796566, 0.0987800}, + {-0.1746861, -0.9796566, 0.0987801}, + {0.1460786, -0.9719416, -0.1843651}, + {-0.1460786, -0.9719416, -0.1843651}, + {0.2934718, -0.9559668, -0.0013427}, + {-0.2934718, -0.9559668, -0.0013427}, + {0.1771432, -0.9820952, -0.0641034}, + {-0.1771432, -0.9820952, -0.0641034}, + {0.2866523, -0.9574176, -0.0343806}, + {-0.2866523, -0.9574176, -0.0343806}, + {0.2739663, -0.9612888, -0.0294319}, + {-0.2739663, -0.9612888, -0.0294319}, + {0.2374126, -0.9563221, -0.1705388}, + {-0.2374125, -0.9563221, -0.1705388}, + {-0.0618315, -0.9823949, -0.1762874}, + {0.0618315, -0.9823949, -0.1762875}, + {0.2478383, -0.9619574, -0.1149525}, + {-0.2478383, -0.9619574, -0.1149525}, + {0.1526227, -0.9831099, -0.1010013}, + {-0.1526227, -0.9831099, -0.1010013}, + {0.5008380, -0.7427813, -0.4443392}, + {-0.5008380, -0.7427813, -0.4443392}, + {0.7938546, -0.5363662, -0.2865418}, + {-0.7938545, -0.5363662, -0.2865418}, + {0.4322813, -0.6876498, 0.5833272}, + {-0.4322813, -0.6876498, 0.5833272}, + {0.1431002, -0.8169456, 0.5586791}, + {-0.1431002, -0.8169456, 0.5586791}, + {-0.1241960, -0.7775313, 0.6164581}, + {0.1241960, -0.7775313, 0.6164581}, + {-0.1911089, -0.9686066, 0.1589926}, + {0.1911089, -0.9686066, 0.1589926}, + {-0.4178195, -0.9035593, -0.0949079}, + {0.4178195, -0.9035593, -0.0949079}, + {-0.1286399, -0.7994074, -0.5868558}, + {0.1286399, -0.7994074, -0.5868558}, + {-0.2740568, -0.4390944, -0.8556221}, + {0.2740567, -0.4390944, -0.8556221}, + {0.3007137, -0.9164183, -0.2641001}, + {-0.3007137, -0.9164183, -0.2641001}, + {0.0995977, -0.9472572, -0.3046048}, + {-0.0995977, -0.9472572, -0.3046048}, + {0.6920184, -0.6585141, 0.2957528}, + {-0.6920183, -0.6585141, 0.2957528}, + {0.7986909, -0.6014290, 0.0193935}, + {-0.7986909, -0.6014290, 0.0193935}, + {-0.5624565, -0.3115283, 0.7658935}, + {0.5624565, -0.3115283, 0.7658935}, + {-0.4742855, 0.7173900, 0.5102988}, + {0.4742854, 0.7173901, 0.5102988}, + {0.1193071, 0.7538186, 0.6461605}, + {-0.1193071, 0.7538186, 0.6461605}, + {0.2928950, 0.3876316, 0.8740448}, + {-0.2928949, 0.3876317, 0.8740447}, + {0.3349467, 0.2018428, 0.9203641}, + {-0.3349467, 0.2018428, 0.9203641}, + {0.7117290, 0.4092475, 0.5709276}, + {-0.7117290, 0.4092475, 0.5709276}, + {0.8799298, 0.2749914, -0.3874314}, + {-0.8799298, 0.2749914, -0.3874314}, + {0.6260707, 0.0493463, -0.7782032}, + {-0.6260708, 0.0493463, -0.7782033}, + {0.3829610, 0.2053981, -0.9006401}, + {-0.3829610, 0.2053981, -0.9006401}, + {0.0000000, -0.5568164, 0.8306355}, + {0.0000000, -0.0256592, 0.9996708}, + {0.0000000, 0.7225899, -0.6912770}, + {0.0000000, 0.1914827, -0.9814959}, + {0.0000000, 0.4458487, -0.8951083}, + {0.0000000, 0.9547627, -0.2973689}, + {-0.0000000, 0.9769825, -0.2133195}, + {-0.0000000, 0.6260526, -0.7797809}, + {0.9844949, -0.0811448, -0.1555165}, + {-0.9844949, -0.0811448, -0.1555165}, + {0.9969392, 0.0674014, 0.0396120}, + {-0.9969393, 0.0674015, 0.0396120}, + {0.7796627, 0.6075606, -0.1516448}, + {-0.7796627, 0.6075606, -0.1516448}, + {0.5280487, 0.8270288, 0.1928420}, + {-0.5280486, 0.8270288, 0.1928420}, + {0.7504904, -0.1004417, -0.6532042}, + {-0.7504904, -0.1004417, -0.6532043}, + {0.3685123, 0.0395083, -0.9287829}, + {-0.3685124, 0.0395083, -0.9287829}, + {0.3664424, 0.7006975, -0.6121626}, + {-0.3664424, 0.7006974, -0.6121625}, + {0.4455009, 0.8204249, -0.3583742}, + {-0.4455008, 0.8204248, -0.3583741}, + {0.8954768, 0.3625970, 0.2581563}, + {-0.8954768, 0.3625970, 0.2581563}, + {0.7013794, 0.2623272, -0.6627604}, + {-0.7013794, 0.2623272, -0.6627604}, + {0.6280958, 0.7726209, 0.0924803}, + {-0.6280958, 0.7726209, 0.0924803}, + {0.7745567, 0.6318026, -0.0297903}, + {-0.7745567, 0.6318026, -0.0297903}, + {0.6665307, 0.6028829, -0.4384851}, + {-0.6665306, 0.6028828, -0.4384852}, + {0.1586957, 0.9774514, -0.1392995}, + {-0.1586957, 0.9774514, -0.1392995}, + {0.2958739, 0.8968768, -0.3287410}, + {-0.2958739, 0.8968768, -0.3287410}, + {0.0594842, 0.6037991, -0.7949139}, + {-0.0594842, 0.6037991, -0.7949139}, + {0.9988856, -0.0445113, -0.0156958}, + {-0.9988855, -0.0445113, -0.0156958}, + {0.9596947, -0.2265009, -0.1663833}, + {-0.9596947, -0.2265009, -0.1663834}, + {0.7857206, -0.2367489, -0.5714833}, + {-0.7857206, -0.2367489, -0.5714832}, + {0.5807636, -0.0148785, -0.8139363}, + {-0.5807636, -0.0148785, -0.8139364}, + {0.5099924, 0.2058772, -0.8351780}, + {-0.5099924, 0.2058772, -0.8351780}, + {0.5222794, 0.5477115, -0.6536332}, + {-0.5222794, 0.5477115, -0.6536332}, + {0.4265464, 0.4225228, 0.7997078}, + {-0.4265465, 0.4225228, 0.7997078}, + {0.4264883, -0.0425409, 0.9034920}, + {-0.4264883, -0.0425409, 0.9034922}, + {0.4597845, -0.5281099, 0.7139314}, + {-0.4597845, -0.5281099, 0.7139314}, + {0.4034796, -0.2413205, 0.8825920}, + {-0.4034797, -0.2413205, 0.8825920}, + {0.8342609, -0.0109273, 0.5512615}, + {-0.8342609, -0.0109273, 0.5512615}, + {0.3446603, -0.4650036, 0.8154637}, + {-0.3446603, -0.4650037, 0.8154637}, + {0.6550512, -0.3186295, 0.6851155}, + {-0.6550511, -0.3186295, 0.6851155}, + {0.7907880, -0.3725854, 0.4856278}, + {-0.7907880, -0.3725854, 0.4856278}, + {0.8624595, -0.0145038, 0.5059182}, + {-0.8624595, -0.0145038, 0.5059182}, + {0.6595556, 0.0732917, 0.7480740}, + {-0.6595556, 0.0732917, 0.7480741}, + {0.4915177, 0.6667503, 0.5602270}, + {-0.4915176, 0.6667504, 0.5602270}, + {0.8733491, 0.3769000, 0.3085575}, + {-0.8733491, 0.3769000, 0.3085575}, + {0.6094710, 0.7926867, -0.0138900}, + {-0.6094710, 0.7926867, -0.0138900}, + {0.5292385, 0.6817329, -0.5051207}, + {-0.5292385, 0.6817329, -0.5051207}, + {0.9146974, -0.3323509, 0.2299380}, + {-0.9146974, -0.3323509, 0.2299380}, + {0.5601247, -0.1449396, -0.8156303}, + {-0.5601246, -0.1449396, -0.8156304}, + {0.5633090, 0.1213324, -0.8172891}, + {-0.5633090, 0.1213324, -0.8172890}, + {-0.2928875, -0.6023554, 0.7425528}, + {0.2928875, -0.6023554, 0.7425528}, + {-0.0324385, -0.7376747, -0.6743765}, + {0.0324385, -0.7376747, -0.6743766}, + {0.4787385, -0.3898605, -0.7866501}, + {-0.4787385, -0.3898605, -0.7866501}, + {0.6719652, -0.6073738, -0.4237451}, + {-0.6719652, -0.6073738, -0.4237450}, + {0.7788039, -0.6044064, 0.1678021}, + {-0.7788039, -0.6044063, 0.1678021}, + {0.3888909, -0.3228621, 0.8628580}, + {-0.3888909, -0.3228621, 0.8628580}, + {-0.0068514, -0.4847742, 0.8746125}, + {0.0068514, -0.4847742, 0.8746125}, + {0.5408057, -0.8361706, -0.0913675}, + {-0.5408056, -0.8361706, -0.0913675}, + {0.3415477, -0.9320834, -0.1206885}, + {-0.3415478, -0.9320834, -0.1206885}, + {-0.1544787, -0.9801985, -0.1238844}, + {0.1544787, -0.9801984, -0.1238844}, + {-0.0406100, -0.9495651, 0.3109292}, + {0.0406100, -0.9495651, 0.3109293}, + {0.5001760, -0.8087698, 0.3093789}, + {-0.5001760, -0.8087698, 0.3093789}, + {0.3526420, -0.9073152, 0.2289604}, + {-0.3526420, -0.9073152, 0.2289604}, + {0.3981110, -0.9164683, -0.0399200}, + {-0.3981109, -0.9164683, -0.0399200}, + {0.6990247, -0.4910395, -0.5198507}, + {-0.6990247, -0.4910395, -0.5198507}, + {0.3313772, -0.4866598, 0.8083016}, + {-0.3313772, -0.4866598, 0.8083016}, + {-0.1909603, -0.2400758, 0.9517866}, + {0.1909603, -0.2400758, 0.9517866}, + {-0.7619943, 0.0196649, 0.6472851}, + {0.7619943, 0.0196649, 0.6472851}, + {-0.9900345, -0.1191951, -0.0749935}, + {0.9900345, -0.1191951, -0.0749935}, + {-0.1340385, -0.6476039, -0.7500952}, + {0.1340385, -0.6476039, -0.7500952}, + {0.5714957, -0.5112480, -0.6418864}, + {-0.5714957, -0.5112480, -0.6418865}, + {0.3850242, -0.9051121, -0.1803565}, + {-0.3850241, -0.9051121, -0.1803565}, + {0.6863607, -0.3745711, -0.6233823}, + {-0.6863607, -0.3745711, -0.6233822}, + {0.8436565, -0.4918015, 0.2153487}, + {-0.8436564, -0.4918015, 0.2153487}, + {0.5886132, -0.3829507, 0.7119574}, + {-0.5886132, -0.3829507, 0.7119573}, + {0.8537704, -0.4806302, -0.2001768}, + {-0.8537704, -0.4806302, -0.2001768}, + {0.6661735, -0.5221579, 0.5325072}, + {-0.6661736, -0.5221578, 0.5325072}, + {0.8602951, 0.1432356, -0.4892606}, + {-0.8602951, 0.1432356, -0.4892606}, + {0.7019203, -0.7014517, 0.1235859}, + {-0.7019203, -0.7014517, 0.1235859}, + {0.9520066, -0.2776189, -0.1288847}, + {-0.9520066, -0.2776189, -0.1288847}, + {0.8483779, -0.3011609, -0.4353815}, + {-0.8483779, -0.3011610, -0.4353815}, + {0.7105365, -0.4895708, -0.5054289}, + {-0.7105365, -0.4895708, -0.5054289}, + {0.6460170, -0.5762031, -0.5006516}, + {-0.6460170, -0.5762032, -0.5006517}, + {0.6512326, -0.7094201, 0.2694794}, + {-0.6512326, -0.7094201, 0.2694795}, + {0.3094249, -0.8701605, 0.3835062}, + {-0.3094250, -0.8701605, 0.3835062}, + {0.4326039, -0.7811609, 0.4501573}, + {-0.4326039, -0.7811609, 0.4501573}, + {0.7703243, -0.5790883, 0.2669404}, + {-0.7703243, -0.5790883, 0.2669404}, + {0.5677933, -0.7002168, -0.4327899}, + {-0.5677933, -0.7002168, -0.4327899}, + {0.5205066, -0.8164924, -0.2498262}, + {-0.5205066, -0.8164924, -0.2498262}, + {-0.2083806, -0.8156407, -0.5397295}, + {0.2083806, -0.8156406, -0.5397295}, + {-0.7491201, -0.6624171, -0.0047533}, + {0.7491202, -0.6624171, -0.0047533}, + {-0.5831412, -0.6403265, 0.4999283}, + {0.5831411, -0.6403266, 0.4999283}, + {0.0971928, -0.7020003, 0.7055134}, + {-0.0971928, -0.7020003, 0.7055134}, + {-0.0789488, -0.3485891, 0.9339446}, + {0.0789489, -0.3485891, 0.9339447}, + {0.6240093, -0.6499016, -0.4338666}, + {-0.6240094, -0.6499017, -0.4338666}, + {0.1796740, -0.9828697, 0.0410417}, + {-0.1796740, -0.9828697, 0.0410417}, + {-0.1907078, -0.8330870, 0.5192267}, + {0.1907078, -0.8330871, 0.5192268}, + {0.4614231, -0.8864308, -0.0364568}, + {-0.4614231, -0.8864308, -0.0364568}, + {0.3526459, -0.9357482, -0.0040121}, + {-0.3526459, -0.9357482, -0.0040121}, + {0.3140624, -0.9477456, -0.0560636}, + {-0.3140624, -0.9477456, -0.0560636}, + {0.2944475, -0.9499435, -0.1044410}, + {-0.2944475, -0.9499435, -0.1044409}, + {0.3746378, -0.9235396, -0.0819821}, + {-0.3746378, -0.9235396, -0.0819821}, + {0.3563313, -0.8849803, 0.2997298}, + {-0.3563313, -0.8849803, 0.2997298}, + {-0.4261702, 0.7100570, 0.5605338}, + {0.4261702, 0.7100570, 0.5605338}, + {0.2970959, 0.7341888, 0.6104923}, + {-0.2970959, 0.7341888, 0.6104923}, + {0.9252766, 0.3680059, 0.0918420}, + {-0.9252766, 0.3680059, 0.0918420}, + {0.6614180, 0.5729129, -0.4840423}, + {-0.6614179, 0.5729130, -0.4840423}, + {-0.0617431, 0.7270822, -0.6837685}, + {0.0617431, 0.7270822, -0.6837685}, + {-0.2319965, 0.4861563, -0.8425139}, + {0.2319965, 0.4861563, -0.8425139}, + {-0.6582950, 0.4886806, 0.5725722}, + {0.6582950, 0.4886806, 0.5725722}, +}; + diff --git a/dreamcast2/sh7091/pref.hpp b/dreamcast2/sh7091/pref.hpp index 843cdf6..0492193 100644 --- a/dreamcast2/sh7091/pref.hpp +++ b/dreamcast2/sh7091/pref.hpp @@ -6,6 +6,15 @@ #define pref2(address) \ { asm volatile ("pref @%0" : : "r" (((uint32_t)(address)) + 32) : "memory"); } +#define ocbi(address) \ + { asm volatile ("ocbi @%0" : : "r" ((uint32_t)(address)) : "memory"); } + +#define ocbwb(address) \ + { asm volatile ("ocbwb @%0" : : "r" ((uint32_t)(address)) : "memory"); } + +#define ocbp(address) \ + { asm volatile ("ocbp @%0" : : "r" ((uint32_t)(address)) : "memory"); } + namespace sh7091::ccn::qacr0 { template constexpr inline uint32_t address(T a) { return (((uint32_t)a) >> 24) & 0b11100; }