diff --git a/dreamcast2/example/example.mk b/dreamcast2/example/example.mk index 0934c88..fa6234d 100644 --- a/dreamcast2/example/example.mk +++ b/dreamcast2/example/example.mk @@ -9,8 +9,14 @@ example/framebuffer_shaded.elf: LDSCRIPT = $(LIB)/main.lds example/framebuffer_shaded.elf: $(START_OBJ) $(FRAMEBUFFER_SHADED_OBJ) TRIANGLE_CORE_OBJ = \ - holly/core/region_array.o \ example/triangle_core.o example/triangle_core.elf: LDSCRIPT = $(LIB)/main.lds example/triangle_core.elf: $(START_OBJ) $(TRIANGLE_CORE_OBJ) + + +TRIANGLE_TA_OBJ = \ + example/triangle_ta.o + +example/triangle_ta.elf: LDSCRIPT = $(LIB)/main.lds +example/triangle_ta.elf: $(START_OBJ) $(TRIANGLE_TA_OBJ) diff --git a/dreamcast2/example/triangle_core.cpp b/dreamcast2/example/triangle_core.cpp index b9cc291..daaddb2 100644 --- a/dreamcast2/example/triangle_core.cpp +++ b/dreamcast2/example/triangle_core.cpp @@ -135,8 +135,8 @@ void main() using polygon = holly::core::parameter::isp_tsp_parameter<3>; - uint32_t triangle_offset = (sizeof (polygon)) * 0; - uint32_t background_offset = (sizeof (polygon)) * 1; + uint32_t background_offset = (sizeof (polygon)) * 0; + uint32_t triangle_offset = (sizeof (polygon)) * 1; transfer_object_list(object_list_start, triangle_offset); diff --git a/dreamcast2/example/triangle_ta.cpp b/dreamcast2/example/triangle_ta.cpp new file mode 100644 index 0000000..4e1f227 --- /dev/null +++ b/dreamcast2/example/triangle_ta.cpp @@ -0,0 +1,287 @@ +#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/pref.hpp" + +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 = 0xff00ff; + + polygon->vertex[1].x = 32.0f; + polygon->vertex[1].y = 0.0f; + polygon->vertex[1].z = 0.00001f; + polygon->vertex[1].base_color = 0xff00ff; + + polygon->vertex[2].x = 32.0f; + polygon->vertex[2].y = 32.0f; + polygon->vertex[2].z = 0.00001f; + polygon->vertex[2].base_color = 0xff00ff; +} + +void transfer_ta_triangle() +{ + using namespace sh7091; + using sh7091::sh7091; + + 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; + + 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::packed_color + | parameter_control_word::gouraud; + + 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; + + pref(polygon); + + // + // TA polygon vertex transfer + // + + volatile vertex_parameter::polygon_type_0 * vertex = (volatile vertex_parameter::polygon_type_0 *)&store_queue[store_queue_ix]; + store_queue_ix += (sizeof (vertex_parameter::polygon_type_0)) * 3; + + // bottom left + vertex[0].parameter_control_word = parameter_control_word::para_type::vertex_parameter; + vertex[0].x = 1.0f; + vertex[0].y = 29.0f; + vertex[0].z = 0.1f; + vertex[0].base_color = 0xff0000; // red + + // start store queue transfer of `vertex[0]` to the TA + pref(&vertex[0]); + + // top center + vertex[1].parameter_control_word = parameter_control_word::para_type::vertex_parameter; + vertex[1].x = 16.0f; + vertex[1].y = 3.0f; + vertex[1].z = 0.1f; + vertex[1].base_color = 0x00ff00; // green + + // start store queue transfer of `vertex[1]` to the TA + pref(&vertex[1]); + + // bottom right + vertex[2].parameter_control_word = parameter_control_word::para_type::vertex_parameter + | parameter_control_word::end_of_strip; + vertex[2].x = 31.0f; + vertex[2].y = 29.0f; + vertex[2].z = 0.1f; + vertex[2].base_color = 0x0000ff; // blue + + // start store queue transfer of `params[2]` to the TA + pref(&vertex[2]); + + // + // 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); +} + +void transfer_region_array(uint32_t region_array_start, + uint32_t opaque_list_pointer) +{ + using namespace holly::core::region_array; + /* + Create a minimal region array with a single entry: + - one tile at tile coordinate (0, 0) with one opaque list pointer + */ + + /* + Holly reads the region array from "32-bit" texture memory address space, + so the region array is correspondingly written from "32-bit" address space. + */ + volatile region_array_entry * region_array = (volatile region_array_entry *)&texture_memory32[region_array_start]; + + region_array[0].tile + = tile::last_region + | tile::y_position(0) + | tile::x_position(0); + + /* + list pointers are offsets relative to the beginning of "32-bit" texture memory. + + each list type uses different rasterization steps, "opaque" being the fastest and most efficient. + */ + region_array[0].list_pointer.opaque = list_pointer::object_list(opaque_list_pointer); + region_array[0].list_pointer.opaque_modifier_volume = list_pointer::empty; + region_array[0].list_pointer.translucent = list_pointer::empty; + region_array[0].list_pointer.translucent_modifier_volume = list_pointer::empty; + region_array[0].list_pointer.punch_through = list_pointer::empty; +} + +void main() +{ + /* + a very simple memory map: + + the ordering within texture memory is not significant, and could be + anything + */ + uint32_t framebuffer_start = 0x200000; // intentionally the same address that the boot rom used to draw the SEGA logo + uint32_t isp_tsp_parameter_start = 0x400000; + uint32_t region_array_start = 0x500000; + uint32_t object_list_start = 0x100000; + + transfer_region_array(region_array_start, + object_list_start); + + transfer_background_polygon(isp_tsp_parameter_start); + + ////////////////////////////////////////////////////////////////////////////// + // configure the TA + ////////////////////////////////////////////////////////////////////////////// + + const int tile_y_num = 1; + const int tile_x_num = 1; + + 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::_8x4byte; + + // 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_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; + + ////////////////////////////////////////////////////////////////////////////// + // transfer triangles to texture memory via the TA polygon converter FIFO + ////////////////////////////////////////////////////////////////////////////// + + transfer_ta_triangle(); + + ////////////////////////////////////////////////////////////////////////////// + // 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; + + // start the actual render--the rendering process begins by interpreting the + // region array + holly.STARTRENDER = 1; + + // without waiting for rendering to actually complete, immediately display the + // framebuffer. + holly.FB_R_SOF1 = framebuffer_start; + + // return from main; this will effectively jump back to the serial loader + + while (1); +} diff --git a/dreamcast2/holly/core/object_list_bits.hpp b/dreamcast2/holly/core/object_list_bits.hpp index 78256a5..8e9b23d 100644 --- a/dreamcast2/holly/core/object_list_bits.hpp +++ b/dreamcast2/holly/core/object_list_bits.hpp @@ -25,27 +25,27 @@ namespace holly::core::object_list { } constexpr uint32_t shadow = 1 << 24; - constexpr uint32_t skip(uint32_t num) { return (num & 0x7) << 21; } - constexpr uint32_t start(uint32_t num) { return (num & 0x1fffff) << 0; } + constexpr inline uint32_t skip(uint32_t num) { return (num & 0x7) << 21; } + constexpr inline uint32_t start(uint32_t num) { return (num & 0x1fffff) << 0; } } namespace triangle_array { - constexpr uint32_t number_of_triangles(uint32_t num) { return (num & 0xf) << 25; } + constexpr inline uint32_t number_of_triangles(uint32_t num) { return (num & 0xf) << 25; } constexpr uint32_t shadow = 1 << 24; - constexpr uint32_t skip(uint32_t num) { return (num & 0x7) << 21; } - constexpr uint32_t start(uint32_t num) { return (num & 0x1fffff) << 0; } + constexpr inline uint32_t skip(uint32_t num) { return (num & 0x7) << 21; } + constexpr inline uint32_t start(uint32_t num) { return (num & 0x1fffff) << 0; } } namespace quad_array { - constexpr uint32_t number_of_quads(uint32_t num) { return (num & 0xf) << 25; } + constexpr inline uint32_t number_of_quads(uint32_t num) { return (num & 0xf) << 25; } constexpr uint32_t shadow = 1 << 24; - constexpr uint32_t skip(uint32_t num) { return (num & 0x7) << 21; } - constexpr uint32_t start(uint32_t num) { return (num & 0x1fffff) << 0; } + constexpr inline uint32_t skip(uint32_t num) { return (num & 0x7) << 21; } + constexpr inline uint32_t start(uint32_t num) { return (num & 0x1fffff) << 0; } } namespace object_pointer_block_link { constexpr uint32_t end_of_list = 1 << 28; - constexpr uint32_t next_pointer_block(uint32_t num) { return (num & 0xfffffc) << 0; } + constexpr inline uint32_t next_pointer_block(uint32_t num) { return (num & 0xfffffc) << 0; } } } diff --git a/dreamcast2/holly/core/parameter.hpp b/dreamcast2/holly/core/parameter.hpp index 0601125..2b7cf0a 100644 --- a/dreamcast2/holly/core/parameter.hpp +++ b/dreamcast2/holly/core/parameter.hpp @@ -1,3 +1,5 @@ +#pragma once + #include namespace holly::core::parameter { diff --git a/dreamcast2/holly/core/parameter_bits.hpp b/dreamcast2/holly/core/parameter_bits.hpp index aa10f08..f788ec5 100644 --- a/dreamcast2/holly/core/parameter_bits.hpp +++ b/dreamcast2/holly/core/parameter_bits.hpp @@ -125,7 +125,7 @@ namespace holly::core::parameter { } constexpr uint32_t super_sample_texture = 1 << 12; - constexpr uint32_t mip_map_d_adjust(uint32_t num) { return (num & 0xf) << 8; } + constexpr inline uint32_t mip_map_d_adjust(uint32_t num) { return (num & 0xf) << 8; } namespace texture_shading_instruction { constexpr uint32_t decal = 0 << 6; @@ -186,10 +186,10 @@ namespace holly::core::parameter { constexpr uint32_t bit_mask = 0x1 << 26; } - constexpr uint32_t palette_selector4(uint32_t num) { return (num & 0x3f) << 21; } - constexpr uint32_t palette_selector8(uint32_t num) { return (num & 0x3) << 25; } - constexpr uint32_t stride_select(uint32_t reg) { return (reg >> 25) & 0x1; } - constexpr uint32_t texture_address(uint32_t num) { return (num & 0x1fffff) << 0; } + constexpr inline uint32_t palette_selector4(uint32_t num) { return (num & 0x3f) << 21; } + constexpr inline uint32_t palette_selector8(uint32_t num) { return (num & 0x3) << 25; } + constexpr inline uint32_t stride_select(uint32_t reg) { return (reg >> 25) & 0x1; } + constexpr inline uint32_t texture_address(uint32_t num) { return (num & 0x1fffff) << 0; } } } diff --git a/dreamcast2/holly/core/region_array_bits.hpp b/dreamcast2/holly/core/region_array_bits.hpp index 0082289..4d83a77 100644 --- a/dreamcast2/holly/core/region_array_bits.hpp +++ b/dreamcast2/holly/core/region_array_bits.hpp @@ -8,13 +8,13 @@ namespace holly::core::region_array { constexpr uint32_t z_clear = 1 << 30; constexpr uint32_t pre_sort = 1 << 29; constexpr uint32_t flush_accumulate = 1 << 28; - constexpr uint32_t y_position(uint32_t num) { return (num & 0x3f) << 8; } - constexpr uint32_t x_position(uint32_t num) { return (num & 0x3f) << 2; } + constexpr inline uint32_t y_position(uint32_t num) { return (num & 0x3f) << 8; } + constexpr inline uint32_t x_position(uint32_t num) { return (num & 0x3f) << 2; } } namespace list_pointer { constexpr uint32_t empty = 1 << 31; - constexpr uint32_t object_list(uint32_t num) { return (num & 0xfffffc) << 0; } + constexpr inline uint32_t object_list(uint32_t num) { return (num & 0xfffffc) << 0; } } } diff --git a/dreamcast2/holly/holly_bits.hpp b/dreamcast2/holly/holly_bits.hpp index 7fb9a5f..b4b674b 100644 --- a/dreamcast2/holly/holly_bits.hpp +++ b/dreamcast2/holly/holly_bits.hpp @@ -4,12 +4,12 @@ namespace holly { namespace id { - constexpr uint32_t device_id(uint32_t reg) { return (reg >> 16) & 0xffff; } - constexpr uint32_t vendor_id(uint32_t reg) { return (reg >> 0) & 0xffff; } + constexpr inline uint32_t device_id(uint32_t reg) { return (reg >> 16) & 0xffff; } + constexpr inline uint32_t vendor_id(uint32_t reg) { return (reg >> 0) & 0xffff; } } namespace revision { - constexpr uint32_t chip_revision(uint32_t reg) { return (reg >> 0) & 0xffff; } + constexpr inline uint32_t chip_revision(uint32_t reg) { return (reg >> 0) & 0xffff; } } namespace softreset { @@ -23,16 +23,16 @@ namespace holly { } namespace test_select { - constexpr uint32_t diagdb_data(uint32_t reg) { return (reg >> 5) & 0x1f; } - constexpr uint32_t diagda_data(uint32_t reg) { return (reg >> 0) & 0x1f; } + constexpr inline uint32_t diagdb_data(uint32_t reg) { return (reg >> 5) & 0x1f; } + constexpr inline uint32_t diagda_data(uint32_t reg) { return (reg >> 0) & 0x1f; } } namespace param_base { - constexpr uint32_t base_address(uint32_t num) { return (num & 0xf00000) << 0; } + constexpr inline uint32_t base_address(uint32_t num) { return (num & 0xf00000) << 0; } } namespace region_base { - constexpr uint32_t base_address(uint32_t num) { return (num & 0xfffffc) << 0; } + constexpr inline uint32_t base_address(uint32_t num) { return (num & 0xfffffc) << 0; } } namespace span_sort_cfg { @@ -42,10 +42,10 @@ namespace holly { } namespace vo_border_col { - constexpr uint32_t chroma(uint32_t num) { return (num & 0x1) << 24; } - constexpr uint32_t red(uint32_t num) { return (num & 0xff) << 16; } - constexpr uint32_t green(uint32_t num) { return (num & 0xff) << 8; } - constexpr uint32_t blue(uint32_t num) { return (num & 0xff) << 0; } + constexpr inline uint32_t chroma(uint32_t num) { return (num & 0x1) << 24; } + constexpr inline uint32_t red(uint32_t num) { return (num & 0xff) << 16; } + constexpr inline uint32_t green(uint32_t num) { return (num & 0xff) << 8; } + constexpr inline uint32_t blue(uint32_t num) { return (num & 0xff) << 0; } } namespace fb_r_ctrl { @@ -57,9 +57,9 @@ namespace holly { } constexpr uint32_t fb_strip_buf_en = 1 << 22; - constexpr uint32_t fb_stripsize(uint32_t num) { return (num & 0x3e) << 16; } - constexpr uint32_t fb_chroma_threshold(uint32_t num) { return (num & 0xff) << 8; } - constexpr uint32_t fb_concat(uint32_t num) { return (num & 0x3) << 4; } + constexpr inline uint32_t fb_stripsize(uint32_t num) { return (num & 0x3e) << 16; } + constexpr inline uint32_t fb_chroma_threshold(uint32_t num) { return (num & 0xff) << 8; } + constexpr inline uint32_t fb_concat(uint32_t num) { return (num & 0x3) << 4; } namespace fb_depth { constexpr uint32_t xrgb0555 = 0 << 2; @@ -75,8 +75,8 @@ namespace holly { } namespace fb_w_ctrl { - constexpr uint32_t fb_alpha_threshold(uint32_t num) { return (num & 0xff) << 16; } - constexpr uint32_t fb_kval(uint32_t num) { return (num & 0xff) << 8; } + constexpr inline uint32_t fb_alpha_threshold(uint32_t num) { return (num & 0xff) << 16; } + constexpr inline uint32_t fb_kval(uint32_t num) { return (num & 0xff) << 8; } constexpr uint32_t fb_dither = 1 << 3; namespace fb_packmode { @@ -93,39 +93,39 @@ namespace holly { } namespace fb_w_linestride { - constexpr uint32_t fb_line_stride(uint32_t num) { return (num & 0xff) << 0; } + constexpr inline uint32_t fb_line_stride(uint32_t num) { return (num & 0xff) << 0; } } namespace fb_r_sof1 { - constexpr uint32_t frame_buffer_read_address_frame_1(uint32_t num) { return (num & 0xfffffc) << 0; } + constexpr inline uint32_t frame_buffer_read_address_frame_1(uint32_t num) { return (num & 0xfffffc) << 0; } } namespace fb_r_sof2 { - constexpr uint32_t frame_buffer_read_address_frame_2(uint32_t num) { return (num & 0xfffffc) << 0; } + constexpr inline uint32_t frame_buffer_read_address_frame_2(uint32_t num) { return (num & 0xfffffc) << 0; } } namespace fb_r_size { - constexpr uint32_t fb_modulus(uint32_t num) { return (num & 0x3ff) << 20; } - constexpr uint32_t fb_y_size(uint32_t num) { return (num & 0x3ff) << 10; } - constexpr uint32_t fb_x_size(uint32_t num) { return (num & 0x3ff) << 0; } + constexpr inline uint32_t fb_modulus(uint32_t num) { return (num & 0x3ff) << 20; } + constexpr inline uint32_t fb_y_size(uint32_t num) { return (num & 0x3ff) << 10; } + constexpr inline uint32_t fb_x_size(uint32_t num) { return (num & 0x3ff) << 0; } } namespace fb_w_sof1 { - constexpr uint32_t frame_buffer_write_address_frame_1(uint32_t num) { return (num & 0x1fffffc) << 0; } + constexpr inline uint32_t frame_buffer_write_address_frame_1(uint32_t num) { return (num & 0x1fffffc) << 0; } } namespace fb_w_sof2 { - constexpr uint32_t frame_buffer_write_address_frame_2(uint32_t num) { return (num & 0x1fffffc) << 0; } + constexpr inline uint32_t frame_buffer_write_address_frame_2(uint32_t num) { return (num & 0x1fffffc) << 0; } } namespace fb_x_clip { - constexpr uint32_t fb_x_clip_max(uint32_t num) { return (num & 0x7ff) << 16; } - constexpr uint32_t fb_x_clip_min(uint32_t num) { return (num & 0x7ff) << 0; } + constexpr inline uint32_t fb_x_clip_max(uint32_t num) { return (num & 0x7ff) << 16; } + constexpr inline uint32_t fb_x_clip_min(uint32_t num) { return (num & 0x7ff) << 0; } } namespace fb_y_clip { - constexpr uint32_t fb_y_clip_max(uint32_t num) { return (num & 0x3ff) << 16; } - constexpr uint32_t fb_y_clip_min(uint32_t num) { return (num & 0x3ff) << 0; } + constexpr inline uint32_t fb_y_clip_max(uint32_t num) { return (num & 0x3ff) << 16; } + constexpr inline uint32_t fb_y_clip_min(uint32_t num) { return (num & 0x3ff) << 0; } } namespace fpu_shad_scale { @@ -136,7 +136,7 @@ namespace holly { constexpr uint32_t bit_mask = 0x1 << 8; } - constexpr uint32_t scale_factor_for_shadows(uint32_t num) { return (num & 0xff) << 0; } + constexpr inline uint32_t scale_factor_for_shadows(uint32_t num) { return (num & 0xff) << 0; } } namespace fpu_cull_val { @@ -151,10 +151,10 @@ namespace holly { constexpr uint32_t bit_mask = 0x1 << 21; } - constexpr uint32_t tsp_parameter_burst_threshold(uint32_t num) { return (num & 0x3f) << 14; } - constexpr uint32_t isp_parameter_burst_threshold(uint32_t num) { return (num & 0x3f) << 8; } - constexpr uint32_t pointer_burst_size(uint32_t num) { return (num & 0xf) << 4; } - constexpr uint32_t pointer_first_burst_size(uint32_t num) { return (num & 0xf) << 0; } + constexpr inline uint32_t tsp_parameter_burst_threshold(uint32_t num) { return (num & 0x3f) << 14; } + constexpr inline uint32_t isp_parameter_burst_threshold(uint32_t num) { return (num & 0x3f) << 8; } + constexpr inline uint32_t pointer_burst_size(uint32_t num) { return (num & 0xf) << 4; } + constexpr inline uint32_t pointer_first_burst_size(uint32_t num) { return (num & 0xf) << 0; } } namespace half_offset { @@ -191,20 +191,20 @@ namespace holly { namespace isp_backgnd_t { constexpr uint32_t cache_bypass = 1 << 28; constexpr uint32_t shadow = 1 << 27; - constexpr uint32_t skip(uint32_t num) { return (num & 0x7) << 24; } - constexpr uint32_t tag_address(uint32_t num) { return (num & 0x1fffff) << 3; } - constexpr uint32_t tag_offset(uint32_t num) { return (num & 0x7) << 0; } + constexpr inline uint32_t skip(uint32_t num) { return (num & 0x7) << 24; } + constexpr inline uint32_t tag_address(uint32_t num) { return (num & 0x1fffff) << 3; } + constexpr inline uint32_t tag_offset(uint32_t num) { return (num & 0x7) << 0; } } namespace isp_feed_cfg { - constexpr uint32_t cache_size_for_translucency(uint32_t num) { return (num & 0x3ff) << 14; } - constexpr uint32_t punch_through_chunk_size(uint32_t num) { return (num & 0x3ff) << 4; } + constexpr inline uint32_t cache_size_for_translucency(uint32_t num) { return (num & 0x3ff) << 14; } + constexpr inline uint32_t punch_through_chunk_size(uint32_t num) { return (num & 0x3ff) << 4; } constexpr uint32_t discard_mode = 1 << 3; constexpr uint32_t pre_sort_mode = 1 << 0; } namespace sdram_refresh { - constexpr uint32_t refresh_counter_value(uint32_t num) { return (num & 0xff) << 0; } + constexpr inline uint32_t refresh_counter_value(uint32_t num) { return (num & 0xff) << 0; } } namespace sdram_arb_cfg { @@ -233,61 +233,61 @@ namespace holly { constexpr uint32_t bit_mask = 0x3 << 16; } - constexpr uint32_t arbiter_crt_page_break_latency_count_value(uint32_t num) { return (num & 0xff) << 8; } - constexpr uint32_t arbiter_page_break_latency_count_value(uint32_t num) { return (num & 0xff) << 0; } + constexpr inline uint32_t arbiter_crt_page_break_latency_count_value(uint32_t num) { return (num & 0xff) << 8; } + constexpr inline uint32_t arbiter_page_break_latency_count_value(uint32_t num) { return (num & 0xff) << 0; } } namespace sdram_cfg { - constexpr uint32_t read_command_to_returned_data_delay(uint32_t num) { return (num & 0x7) << 26; } - constexpr uint32_t cas_latency_value(uint32_t num) { return (num & 0x7) << 23; } - constexpr uint32_t activate_to_activate_period(uint32_t num) { return (num & 0x3) << 21; } - constexpr uint32_t read_to_write_period(uint32_t num) { return (num & 0x7) << 18; } - constexpr uint32_t refresh_to_activate_period(uint32_t num) { return (num & 0xf) << 14; } - constexpr uint32_t pre_charge_to_activate_period(uint32_t num) { return (num & 0x3) << 10; } - constexpr uint32_t activate_to_pre_charge_period(uint32_t num) { return (num & 0xf) << 6; } - constexpr uint32_t activate_to_read_write_command_period(uint32_t num) { return (num & 0x3) << 4; } - constexpr uint32_t write_to_pre_charge_period(uint32_t num) { return (num & 0x3) << 2; } - constexpr uint32_t read_to_pre_charge_period(uint32_t num) { return (num & 0x3) << 0; } + constexpr inline uint32_t read_command_to_returned_data_delay(uint32_t num) { return (num & 0x7) << 26; } + constexpr inline uint32_t cas_latency_value(uint32_t num) { return (num & 0x7) << 23; } + constexpr inline uint32_t activate_to_activate_period(uint32_t num) { return (num & 0x3) << 21; } + constexpr inline uint32_t read_to_write_period(uint32_t num) { return (num & 0x7) << 18; } + constexpr inline uint32_t refresh_to_activate_period(uint32_t num) { return (num & 0xf) << 14; } + constexpr inline uint32_t pre_charge_to_activate_period(uint32_t num) { return (num & 0x3) << 10; } + constexpr inline uint32_t activate_to_pre_charge_period(uint32_t num) { return (num & 0xf) << 6; } + constexpr inline uint32_t activate_to_read_write_command_period(uint32_t num) { return (num & 0x3) << 4; } + constexpr inline uint32_t write_to_pre_charge_period(uint32_t num) { return (num & 0x3) << 2; } + constexpr inline uint32_t read_to_pre_charge_period(uint32_t num) { return (num & 0x3) << 0; } } namespace fog_col_ram { - constexpr uint32_t red(uint32_t num) { return (num & 0xff) << 16; } - constexpr uint32_t green(uint32_t num) { return (num & 0xff) << 8; } - constexpr uint32_t blue(uint32_t num) { return (num & 0xff) << 0; } + constexpr inline uint32_t red(uint32_t num) { return (num & 0xff) << 16; } + constexpr inline uint32_t green(uint32_t num) { return (num & 0xff) << 8; } + constexpr inline uint32_t blue(uint32_t num) { return (num & 0xff) << 0; } } namespace fog_col_vert { - constexpr uint32_t red(uint32_t num) { return (num & 0xff) << 16; } - constexpr uint32_t green(uint32_t num) { return (num & 0xff) << 8; } - constexpr uint32_t blue(uint32_t num) { return (num & 0xff) << 0; } + constexpr inline uint32_t red(uint32_t num) { return (num & 0xff) << 16; } + constexpr inline uint32_t green(uint32_t num) { return (num & 0xff) << 8; } + constexpr inline uint32_t blue(uint32_t num) { return (num & 0xff) << 0; } } namespace fog_density { - constexpr uint32_t fog_scale_mantissa(uint32_t num) { return (num & 0xff) << 8; } - constexpr uint32_t fog_scale_exponent(uint32_t num) { return (num & 0xff) << 0; } + constexpr inline uint32_t fog_scale_mantissa(uint32_t num) { return (num & 0xff) << 8; } + constexpr inline uint32_t fog_scale_exponent(uint32_t num) { return (num & 0xff) << 0; } } namespace fog_clamp_max { - constexpr uint32_t alpha(uint32_t num) { return (num & 0xff) << 24; } - constexpr uint32_t red(uint32_t num) { return (num & 0xff) << 16; } - constexpr uint32_t green(uint32_t num) { return (num & 0xff) << 8; } - constexpr uint32_t blue(uint32_t num) { return (num & 0xff) << 0; } + constexpr inline uint32_t alpha(uint32_t num) { return (num & 0xff) << 24; } + constexpr inline uint32_t red(uint32_t num) { return (num & 0xff) << 16; } + constexpr inline uint32_t green(uint32_t num) { return (num & 0xff) << 8; } + constexpr inline uint32_t blue(uint32_t num) { return (num & 0xff) << 0; } } namespace fog_clamp_min { - constexpr uint32_t alpha(uint32_t num) { return (num & 0xff) << 24; } - constexpr uint32_t red(uint32_t num) { return (num & 0xff) << 16; } - constexpr uint32_t green(uint32_t num) { return (num & 0xff) << 8; } - constexpr uint32_t blue(uint32_t num) { return (num & 0xff) << 0; } + constexpr inline uint32_t alpha(uint32_t num) { return (num & 0xff) << 24; } + constexpr inline uint32_t red(uint32_t num) { return (num & 0xff) << 16; } + constexpr inline uint32_t green(uint32_t num) { return (num & 0xff) << 8; } + constexpr inline uint32_t blue(uint32_t num) { return (num & 0xff) << 0; } } namespace spg_trigger_pos { - constexpr uint32_t trigger_v_count(uint32_t reg) { return (reg >> 16) & 0x3ff; } - constexpr uint32_t trigger_h_count(uint32_t reg) { return (reg >> 0) & 0x3ff; } + constexpr inline uint32_t trigger_v_count(uint32_t reg) { return (reg >> 16) & 0x3ff; } + constexpr inline uint32_t trigger_h_count(uint32_t reg) { return (reg >> 0) & 0x3ff; } } namespace spg_hblank_int { - constexpr uint32_t hblank_in_interrupt(uint32_t reg) { return (reg >> 16) & 0x3ff; } + constexpr inline uint32_t hblank_in_interrupt(uint32_t reg) { return (reg >> 16) & 0x3ff; } namespace hblank_int_mode { constexpr uint32_t output_equal_line_comp_val = 0x0 << 12; @@ -297,12 +297,12 @@ namespace holly { constexpr uint32_t bit_mask = 0x3 << 12; } - constexpr uint32_t line_comp_val(uint32_t num) { return (num & 0x3ff) << 0; } + constexpr inline uint32_t line_comp_val(uint32_t num) { return (num & 0x3ff) << 0; } } namespace spg_vblank_int { - constexpr uint32_t vblank_out_interrupt_line_number(uint32_t num) { return (num & 0x3ff) << 16; } - constexpr uint32_t vblank_in_interrupt_line_number(uint32_t num) { return (num & 0x3ff) << 0; } + constexpr inline uint32_t vblank_out_interrupt_line_number(uint32_t num) { return (num & 0x3ff) << 16; } + constexpr inline uint32_t vblank_in_interrupt_line_number(uint32_t num) { return (num & 0x3ff) << 0; } } namespace spg_control { @@ -349,25 +349,25 @@ namespace holly { } namespace spg_hblank { - constexpr uint32_t hbend(uint32_t num) { return (num & 0x3ff) << 16; } - constexpr uint32_t hbstart(uint32_t num) { return (num & 0x3ff) << 0; } + constexpr inline uint32_t hbend(uint32_t num) { return (num & 0x3ff) << 16; } + constexpr inline uint32_t hbstart(uint32_t num) { return (num & 0x3ff) << 0; } } namespace spg_load { - constexpr uint32_t vcount(uint32_t num) { return (num & 0x3ff) << 16; } - constexpr uint32_t hcount(uint32_t num) { return (num & 0x3ff) << 0; } + constexpr inline uint32_t vcount(uint32_t num) { return (num & 0x3ff) << 16; } + constexpr inline uint32_t hcount(uint32_t num) { return (num & 0x3ff) << 0; } } namespace spg_vblank { - constexpr uint32_t vbend(uint32_t num) { return (num & 0x3ff) << 16; } - constexpr uint32_t vbstart(uint32_t num) { return (num & 0x3ff) << 0; } + constexpr inline uint32_t vbend(uint32_t num) { return (num & 0x3ff) << 16; } + constexpr inline uint32_t vbstart(uint32_t num) { return (num & 0x3ff) << 0; } } namespace spg_width { - constexpr uint32_t eqwidth(uint32_t num) { return (num & 0x3ff) << 22; } - constexpr uint32_t bpwidth(uint32_t num) { return (num & 0x3ff) << 12; } - constexpr uint32_t vswidth(uint32_t num) { return (num & 0xf) << 8; } - constexpr uint32_t hswidth(uint32_t num) { return (num & 0x7f) << 0; } + constexpr inline uint32_t eqwidth(uint32_t num) { return (num & 0x3ff) << 22; } + constexpr inline uint32_t bpwidth(uint32_t num) { return (num & 0x3ff) << 12; } + constexpr inline uint32_t vswidth(uint32_t num) { return (num & 0xf) << 8; } + constexpr inline uint32_t hswidth(uint32_t num) { return (num & 0x7f) << 0; } } namespace text_control { @@ -385,13 +385,13 @@ namespace holly { constexpr uint32_t bit_mask = 0x1 << 16; } - constexpr uint32_t bank_bit(uint32_t num) { return (num & 0x1f) << 8; } - constexpr uint32_t stride(uint32_t num) { return (num & 0x1f) << 0; } + constexpr inline uint32_t bank_bit(uint32_t num) { return (num & 0x1f) << 8; } + constexpr inline uint32_t stride(uint32_t num) { return (num & 0x1f) << 0; } } namespace vo_control { constexpr uint32_t pclk_delay_reset = 1 << 21; - constexpr uint32_t pclk_delay(uint32_t num) { return (num & 0x1f) << 16; } + constexpr inline uint32_t pclk_delay(uint32_t num) { return (num & 0x1f) << 16; } constexpr uint32_t pixel_double = 1 << 8; namespace field_mode { @@ -433,12 +433,12 @@ namespace holly { } namespace vo_startx { - constexpr uint32_t horizontal_start_position(uint32_t num) { return (num & 0x3ff) << 0; } + constexpr inline uint32_t horizontal_start_position(uint32_t num) { return (num & 0x3ff) << 0; } } namespace vo_starty { - constexpr uint32_t vertical_start_position_on_field_2(uint32_t num) { return (num & 0x3ff) << 16; } - constexpr uint32_t vertical_start_position_on_field_1(uint32_t num) { return (num & 0x3ff) << 0; } + constexpr inline uint32_t vertical_start_position_on_field_2(uint32_t num) { return (num & 0x3ff) << 16; } + constexpr inline uint32_t vertical_start_position_on_field_1(uint32_t num) { return (num & 0x3ff) << 0; } } namespace scaler_ctl { @@ -451,7 +451,7 @@ namespace holly { constexpr uint32_t interlace = 1 << 17; constexpr uint32_t horizontal_scaling_enable = 1 << 16; - constexpr uint32_t vertical_scale_factor(uint32_t num) { return (num & 0xffff) << 0; } + constexpr inline uint32_t vertical_scale_factor(uint32_t num) { return (num & 0xffff) << 0; } } namespace pal_ram_ctrl { @@ -466,67 +466,67 @@ namespace holly { } namespace spg_status { - constexpr uint32_t vsync(uint32_t reg) { return (reg >> 13) & 0x1; } - constexpr uint32_t hsync(uint32_t reg) { return (reg >> 12) & 0x1; } - constexpr uint32_t blank(uint32_t reg) { return (reg >> 11) & 0x1; } - constexpr uint32_t fieldnum(uint32_t reg) { return (reg >> 10) & 0x1; } - constexpr uint32_t scanline(uint32_t reg) { return (reg >> 0) & 0x3ff; } + constexpr inline uint32_t vsync(uint32_t reg) { return (reg >> 13) & 0x1; } + constexpr inline uint32_t hsync(uint32_t reg) { return (reg >> 12) & 0x1; } + constexpr inline uint32_t blank(uint32_t reg) { return (reg >> 11) & 0x1; } + constexpr inline uint32_t fieldnum(uint32_t reg) { return (reg >> 10) & 0x1; } + constexpr inline uint32_t scanline(uint32_t reg) { return (reg >> 0) & 0x3ff; } } namespace fb_burstctrl { - constexpr uint32_t wr_burst(uint32_t num) { return (num & 0xf) << 16; } - constexpr uint32_t vid_lat(uint32_t num) { return (num & 0x7f) << 8; } - constexpr uint32_t vid_burst(uint32_t num) { return (num & 0x3f) << 0; } + constexpr inline uint32_t wr_burst(uint32_t num) { return (num & 0xf) << 16; } + constexpr inline uint32_t vid_lat(uint32_t num) { return (num & 0x7f) << 8; } + constexpr inline uint32_t vid_burst(uint32_t num) { return (num & 0x3f) << 0; } } namespace fb_c_sof { - constexpr uint32_t frame_buffer_current_read_address(uint32_t reg) { return (reg >> 0) & 0xffffff; } + constexpr inline uint32_t frame_buffer_current_read_address(uint32_t reg) { return (reg >> 0) & 0xffffff; } } namespace y_coeff { - constexpr uint32_t coefficient_1(uint32_t num) { return (num & 0xff) << 8; } - constexpr uint32_t coefficient_0_2(uint32_t num) { return (num & 0xff) << 0; } + constexpr inline uint32_t coefficient_1(uint32_t num) { return (num & 0xff) << 8; } + constexpr inline uint32_t coefficient_0_2(uint32_t num) { return (num & 0xff) << 0; } } namespace pt_alpha_ref { - constexpr uint32_t alpha_reference_for_punch_through(uint32_t num) { return (num & 0xff) << 0; } + constexpr inline uint32_t alpha_reference_for_punch_through(uint32_t num) { return (num & 0xff) << 0; } } namespace fog_table { - constexpr uint32_t fog_table_data(uint32_t num) { return (num & 0xffff) << 0; } + constexpr inline uint32_t fog_table_data(uint32_t num) { return (num & 0xffff) << 0; } } namespace palette_ram { - constexpr uint32_t palette_data(uint32_t num) { return (num & 0xffffffff) << 0; } + constexpr inline uint32_t palette_data(uint32_t num) { return (num & 0xffffffff) << 0; } } namespace ta_ol_base { - constexpr uint32_t base_address(uint32_t num) { return (num & 0xffffe0) << 0; } + constexpr inline uint32_t base_address(uint32_t num) { return (num & 0xffffe0) << 0; } } namespace ta_isp_base { - constexpr uint32_t base_address(uint32_t num) { return (num & 0xfffffc) << 0; } + constexpr inline uint32_t base_address(uint32_t num) { return (num & 0xfffffc) << 0; } } namespace ta_ol_limit { - constexpr uint32_t limit_address(uint32_t num) { return (num & 0xffffe0) << 0; } + constexpr inline uint32_t limit_address(uint32_t num) { return (num & 0xffffe0) << 0; } } namespace ta_isp_limit { - constexpr uint32_t limit_address(uint32_t num) { return (num & 0xfffffc) << 0; } + constexpr inline uint32_t limit_address(uint32_t num) { return (num & 0xfffffc) << 0; } } namespace ta_next_opb { - constexpr uint32_t address(uint32_t num) { return (num & 0xffffe0) << 0; } + constexpr inline uint32_t address(uint32_t num) { return (num & 0xffffe0) << 0; } } namespace ta_itp_current { - constexpr uint32_t address(uint32_t reg) { return (reg >> 0) & 0xffffff; } + constexpr inline uint32_t address(uint32_t reg) { return (reg >> 0) & 0xffffff; } } namespace ta_glob_tile_clip { - constexpr uint32_t tile_y_num(uint32_t num) { return (num & 0xf) << 16; } - constexpr uint32_t tile_x_num(uint32_t num) { return (num & 0x1f) << 0; } + constexpr inline uint32_t tile_y_num(uint32_t num) { return (num & 0xf) << 16; } + constexpr inline uint32_t tile_x_num(uint32_t num) { return (num & 0x1f) << 0; } } namespace ta_alloc_ctrl { @@ -588,7 +588,7 @@ namespace holly { } namespace ta_yuv_tex_base { - constexpr uint32_t base_address(uint32_t num) { return (num & 0xfffff8) << 0; } + constexpr inline uint32_t base_address(uint32_t num) { return (num & 0xfffff8) << 0; } } namespace ta_yuv_tex_ctrl { @@ -606,12 +606,12 @@ namespace holly { constexpr uint32_t bit_mask = 0x1 << 16; } - constexpr uint32_t yuv_v_size(uint32_t num) { return (num & 0x3f) << 8; } - constexpr uint32_t yuv_u_size(uint32_t num) { return (num & 0x3f) << 0; } + constexpr inline uint32_t yuv_v_size(uint32_t num) { return (num & 0x3f) << 8; } + constexpr inline uint32_t yuv_u_size(uint32_t num) { return (num & 0x3f) << 0; } } namespace ta_yuv_tex_cnt { - constexpr uint32_t yuv_num(uint32_t reg) { return (reg >> 0) & 0x1fff; } + constexpr inline uint32_t yuv_num(uint32_t reg) { return (reg >> 0) & 0x1fff; } } namespace ta_list_cont { @@ -619,17 +619,17 @@ namespace holly { } namespace ta_next_opb_init { - constexpr uint32_t address(uint32_t num) { return (num & 0xffffe0) << 0; } + constexpr inline uint32_t address(uint32_t num) { return (num & 0xffffe0) << 0; } } namespace ta_ol_pointers { - constexpr uint32_t entry(uint32_t reg) { return (reg >> 31) & 0x1; } - constexpr uint32_t sprite(uint32_t reg) { return (reg >> 30) & 0x1; } - constexpr uint32_t triangle(uint32_t reg) { return (reg >> 29) & 0x1; } - constexpr uint32_t number_of_triangles_quads(uint32_t reg) { return (reg >> 25) & 0xf; } - constexpr uint32_t shadow(uint32_t reg) { return (reg >> 24) & 0x1; } - constexpr uint32_t pointer_address(uint32_t reg) { return (reg >> 2) & 0x3fffff; } - constexpr uint32_t skip(uint32_t reg) { return (reg >> 0) & 0x3; } + constexpr inline uint32_t entry(uint32_t reg) { return (reg >> 31) & 0x1; } + constexpr inline uint32_t sprite(uint32_t reg) { return (reg >> 30) & 0x1; } + constexpr inline uint32_t triangle(uint32_t reg) { return (reg >> 29) & 0x1; } + constexpr inline uint32_t number_of_triangles_quads(uint32_t reg) { return (reg >> 25) & 0xf; } + constexpr inline uint32_t shadow(uint32_t reg) { return (reg >> 24) & 0x1; } + constexpr inline uint32_t pointer_address(uint32_t reg) { return (reg >> 2) & 0x3fffff; } + constexpr inline uint32_t skip(uint32_t reg) { return (reg >> 0) & 0x3; } } } diff --git a/dreamcast2/holly/ta/global_parameter.hpp b/dreamcast2/holly/ta/global_parameter.hpp new file mode 100644 index 0000000..0cfe0cb --- /dev/null +++ b/dreamcast2/holly/ta/global_parameter.hpp @@ -0,0 +1,240 @@ +#pragma once + +#include +#include + +namespace holly::ta::global_parameter { + struct end_of_list { + uint32_t parameter_control_word; + uint32_t _res0; + uint32_t _res1; + uint32_t _res2; + uint32_t _res3; + uint32_t _res4; + uint32_t _res5; + uint32_t _res6; + }; + static_assert((sizeof (end_of_list)) == 32); + static_assert((offsetof (struct end_of_list, parameter_control_word)) == 0x00); + static_assert((offsetof (struct end_of_list, _res0)) == 0x04); + static_assert((offsetof (struct end_of_list, _res1)) == 0x08); + static_assert((offsetof (struct end_of_list, _res2)) == 0x0c); + static_assert((offsetof (struct end_of_list, _res3)) == 0x10); + static_assert((offsetof (struct end_of_list, _res4)) == 0x14); + static_assert((offsetof (struct end_of_list, _res5)) == 0x18); + static_assert((offsetof (struct end_of_list, _res6)) == 0x1c); + + struct user_tile_clip { + uint32_t parameter_control_word; + uint32_t _res0; + uint32_t _res1; + uint32_t _res2; + uint32_t user_clip_x_min; + uint32_t user_clip_y_min; + uint32_t user_clip_x_max; + uint32_t user_clip_y_max; + }; + static_assert((sizeof (user_tile_clip)) == 32); + static_assert((offsetof (struct user_tile_clip, parameter_control_word)) == 0x00); + static_assert((offsetof (struct user_tile_clip, _res0)) == 0x04); + static_assert((offsetof (struct user_tile_clip, _res1)) == 0x08); + static_assert((offsetof (struct user_tile_clip, _res2)) == 0x0c); + static_assert((offsetof (struct user_tile_clip, user_clip_x_min)) == 0x10); + static_assert((offsetof (struct user_tile_clip, user_clip_y_min)) == 0x14); + static_assert((offsetof (struct user_tile_clip, user_clip_x_max)) == 0x18); + static_assert((offsetof (struct user_tile_clip, user_clip_y_max)) == 0x1c); + + struct object_list_set { + uint32_t parameter_control_word; + uint32_t object_pointer; + uint32_t _res0; + uint32_t _res1; + uint32_t bounding_box_x_min; + uint32_t bounding_box_y_min; + uint32_t bounding_box_x_max; + uint32_t bounding_box_y_max; + }; + static_assert((sizeof (object_list_set)) == 32); + static_assert((offsetof (struct object_list_set, parameter_control_word)) == 0x00); + static_assert((offsetof (struct object_list_set, object_pointer)) == 0x04); + static_assert((offsetof (struct object_list_set, _res0)) == 0x08); + static_assert((offsetof (struct object_list_set, _res1)) == 0x0c); + static_assert((offsetof (struct object_list_set, bounding_box_x_min)) == 0x10); + static_assert((offsetof (struct object_list_set, bounding_box_y_min)) == 0x14); + static_assert((offsetof (struct object_list_set, bounding_box_x_max)) == 0x18); + static_assert((offsetof (struct object_list_set, bounding_box_y_max)) == 0x1c); + + struct polygon_type_0 { + uint32_t parameter_control_word; + uint32_t isp_tsp_instruction_word; + uint32_t tsp_instruction_word; + uint32_t texture_control_word; + uint32_t _res0; + uint32_t _res1; + uint32_t data_size_for_sort_dma; + uint32_t next_address_for_sort_dma; + }; + static_assert((sizeof (polygon_type_0)) == 32); + static_assert((offsetof (struct polygon_type_0, parameter_control_word)) == 0x00); + static_assert((offsetof (struct polygon_type_0, isp_tsp_instruction_word)) == 0x04); + static_assert((offsetof (struct polygon_type_0, tsp_instruction_word)) == 0x08); + static_assert((offsetof (struct polygon_type_0, texture_control_word)) == 0x0c); + static_assert((offsetof (struct polygon_type_0, _res0)) == 0x10); + static_assert((offsetof (struct polygon_type_0, _res1)) == 0x14); + static_assert((offsetof (struct polygon_type_0, data_size_for_sort_dma)) == 0x18); + static_assert((offsetof (struct polygon_type_0, next_address_for_sort_dma)) == 0x1c); + + struct polygon_type_1 { + uint32_t parameter_control_word; + uint32_t isp_tsp_instruction_word; + uint32_t tsp_instruction_word; + uint32_t texture_control_word; + float face_color_alpha; + float face_color_r; + float face_color_g; + float face_color_b; + }; + static_assert((sizeof (polygon_type_1)) == 32); + static_assert((offsetof (struct polygon_type_1, parameter_control_word)) == 0x00); + static_assert((offsetof (struct polygon_type_1, isp_tsp_instruction_word)) == 0x04); + static_assert((offsetof (struct polygon_type_1, tsp_instruction_word)) == 0x08); + static_assert((offsetof (struct polygon_type_1, texture_control_word)) == 0x0c); + static_assert((offsetof (struct polygon_type_1, face_color_alpha)) == 0x10); + static_assert((offsetof (struct polygon_type_1, face_color_r)) == 0x14); + static_assert((offsetof (struct polygon_type_1, face_color_g)) == 0x18); + static_assert((offsetof (struct polygon_type_1, face_color_b)) == 0x1c); + + struct polygon_type_2 { + uint32_t parameter_control_word; + uint32_t isp_tsp_instruction_word; + uint32_t tsp_instruction_word; + uint32_t texture_control_word; + uint32_t _res0; + uint32_t _res1; + uint32_t data_size_for_sort_dma; + uint32_t next_address_for_sort_dma; + float face_color_alpha; + float face_color_r; + float face_color_g; + float face_color_b; + float face_offset_color_alpha; + float face_offset_color_r; + float face_offset_color_g; + float face_offset_color_b; + }; + static_assert((sizeof (polygon_type_2)) == 64); + static_assert((offsetof (struct polygon_type_2, parameter_control_word)) == 0x00); + static_assert((offsetof (struct polygon_type_2, isp_tsp_instruction_word)) == 0x04); + static_assert((offsetof (struct polygon_type_2, tsp_instruction_word)) == 0x08); + static_assert((offsetof (struct polygon_type_2, texture_control_word)) == 0x0c); + static_assert((offsetof (struct polygon_type_2, _res0)) == 0x10); + static_assert((offsetof (struct polygon_type_2, _res1)) == 0x14); + static_assert((offsetof (struct polygon_type_2, data_size_for_sort_dma)) == 0x18); + static_assert((offsetof (struct polygon_type_2, next_address_for_sort_dma)) == 0x1c); + static_assert((offsetof (struct polygon_type_2, face_color_alpha)) == 0x20); + static_assert((offsetof (struct polygon_type_2, face_color_r)) == 0x24); + static_assert((offsetof (struct polygon_type_2, face_color_g)) == 0x28); + static_assert((offsetof (struct polygon_type_2, face_color_b)) == 0x2c); + static_assert((offsetof (struct polygon_type_2, face_offset_color_alpha)) == 0x30); + static_assert((offsetof (struct polygon_type_2, face_offset_color_r)) == 0x34); + static_assert((offsetof (struct polygon_type_2, face_offset_color_g)) == 0x38); + static_assert((offsetof (struct polygon_type_2, face_offset_color_b)) == 0x3c); + + struct polygon_type_3 { + uint32_t parameter_control_word; + uint32_t isp_tsp_instruction_word; + uint32_t tsp_instruction_word_0; + uint32_t texture_control_word_0; + uint32_t tsp_instruction_word_1; + uint32_t texture_control_word_1; + uint32_t data_size_for_sort_dma; + uint32_t next_address_for_sort_dma; + }; + static_assert((sizeof (polygon_type_3)) == 32); + static_assert((offsetof (struct polygon_type_3, parameter_control_word)) == 0x00); + static_assert((offsetof (struct polygon_type_3, isp_tsp_instruction_word)) == 0x04); + static_assert((offsetof (struct polygon_type_3, tsp_instruction_word_0)) == 0x08); + static_assert((offsetof (struct polygon_type_3, texture_control_word_0)) == 0x0c); + static_assert((offsetof (struct polygon_type_3, tsp_instruction_word_1)) == 0x10); + static_assert((offsetof (struct polygon_type_3, texture_control_word_1)) == 0x14); + static_assert((offsetof (struct polygon_type_3, data_size_for_sort_dma)) == 0x18); + static_assert((offsetof (struct polygon_type_3, next_address_for_sort_dma)) == 0x1c); + + struct polygon_type_4 { + uint32_t parameter_control_word; + uint32_t isp_tsp_instruction_word; + uint32_t tsp_instruction_word_0; + uint32_t texture_control_word_0; + uint32_t tsp_instruction_word_1; + uint32_t texture_control_word_1; + uint32_t data_size_for_sort_dma; + uint32_t next_address_for_sort_dma; + float face_color_alpha_0; + float face_color_r_0; + float face_color_g_0; + float face_color_b_0; + float face_color_alpha_1; + float face_color_r_1; + float face_color_g_1; + float face_color_b_1; + }; + static_assert((sizeof (polygon_type_4)) == 64); + static_assert((offsetof (struct polygon_type_4, parameter_control_word)) == 0x00); + static_assert((offsetof (struct polygon_type_4, isp_tsp_instruction_word)) == 0x04); + static_assert((offsetof (struct polygon_type_4, tsp_instruction_word_0)) == 0x08); + static_assert((offsetof (struct polygon_type_4, texture_control_word_0)) == 0x0c); + static_assert((offsetof (struct polygon_type_4, tsp_instruction_word_1)) == 0x10); + static_assert((offsetof (struct polygon_type_4, texture_control_word_1)) == 0x14); + static_assert((offsetof (struct polygon_type_4, data_size_for_sort_dma)) == 0x18); + static_assert((offsetof (struct polygon_type_4, next_address_for_sort_dma)) == 0x1c); + static_assert((offsetof (struct polygon_type_4, face_color_alpha_0)) == 0x20); + static_assert((offsetof (struct polygon_type_4, face_color_r_0)) == 0x24); + static_assert((offsetof (struct polygon_type_4, face_color_g_0)) == 0x28); + static_assert((offsetof (struct polygon_type_4, face_color_b_0)) == 0x2c); + static_assert((offsetof (struct polygon_type_4, face_color_alpha_1)) == 0x30); + static_assert((offsetof (struct polygon_type_4, face_color_r_1)) == 0x34); + static_assert((offsetof (struct polygon_type_4, face_color_g_1)) == 0x38); + static_assert((offsetof (struct polygon_type_4, face_color_b_1)) == 0x3c); + + struct sprite { + uint32_t parameter_control_word; + uint32_t isp_tsp_instruction_word; + uint32_t tsp_instruction_word; + uint32_t texture_control_word; + uint32_t base_color; + uint32_t offset_color; + uint32_t data_size_for_sort_dma; + uint32_t next_address_for_sort_dma; + }; + static_assert((sizeof (sprite)) == 32); + static_assert((offsetof (struct sprite, parameter_control_word)) == 0x00); + static_assert((offsetof (struct sprite, isp_tsp_instruction_word)) == 0x04); + static_assert((offsetof (struct sprite, tsp_instruction_word)) == 0x08); + static_assert((offsetof (struct sprite, texture_control_word)) == 0x0c); + static_assert((offsetof (struct sprite, base_color)) == 0x10); + static_assert((offsetof (struct sprite, offset_color)) == 0x14); + static_assert((offsetof (struct sprite, data_size_for_sort_dma)) == 0x18); + static_assert((offsetof (struct sprite, next_address_for_sort_dma)) == 0x1c); + + struct modifier_volume { + uint32_t parameter_control_word; + uint32_t isp_tsp_instruction_word; + uint32_t _res0; + uint32_t _res1; + uint32_t _res2; + uint32_t _res3; + uint32_t _res4; + uint32_t _res5; + }; + static_assert((sizeof (modifier_volume)) == 32); + static_assert((offsetof (struct modifier_volume, parameter_control_word)) == 0x00); + static_assert((offsetof (struct modifier_volume, isp_tsp_instruction_word)) == 0x04); + static_assert((offsetof (struct modifier_volume, _res0)) == 0x08); + static_assert((offsetof (struct modifier_volume, _res1)) == 0x0c); + static_assert((offsetof (struct modifier_volume, _res2)) == 0x10); + static_assert((offsetof (struct modifier_volume, _res3)) == 0x14); + static_assert((offsetof (struct modifier_volume, _res4)) == 0x18); + static_assert((offsetof (struct modifier_volume, _res5)) == 0x1c); + +} + diff --git a/dreamcast2/holly/ta/parameter_bits.hpp b/dreamcast2/holly/ta/parameter_bits.hpp new file mode 100644 index 0000000..7449806 --- /dev/null +++ b/dreamcast2/holly/ta/parameter_bits.hpp @@ -0,0 +1,78 @@ +#pragma once + +#include + +namespace holly::ta::parameter { + namespace parameter_control_word { + namespace para_type { + constexpr uint32_t end_of_list = 0 << 29; + constexpr uint32_t user_tile_clip = 1 << 29; + constexpr uint32_t object_list_set = 2 << 29; + constexpr uint32_t polygon_or_modifier_volume = 4 << 29; + constexpr uint32_t sprite = 5 << 29; + constexpr uint32_t vertex_parameter = 7 << 29; + + constexpr uint32_t bit_mask = 0x7 << 29; + } + + constexpr uint32_t end_of_strip = 1 << 28; + + namespace list_type { + constexpr uint32_t opaque = 0 << 24; + constexpr uint32_t opaque_modifier_volume = 1 << 24; + constexpr uint32_t translucent = 2 << 24; + constexpr uint32_t translucent_modifier_volume = 3 << 24; + constexpr uint32_t punch_through = 4 << 24; + + constexpr uint32_t bit_mask = 0x7 << 24; + } + + constexpr uint32_t group_en = 1 << 23; + + namespace strip_len { + constexpr uint32_t _1_strip = 0 << 18; + constexpr uint32_t _2_strip = 1 << 18; + constexpr uint32_t _4_strip = 2 << 18; + constexpr uint32_t _6_strip = 3 << 18; + + constexpr uint32_t bit_mask = 0x3 << 18; + } + + namespace user_clip { + constexpr uint32_t disabled = 0 << 16; + constexpr uint32_t inside_enable = 2 << 16; + constexpr uint32_t outside_enable = 3 << 16; + + constexpr uint32_t bit_mask = 0x3 << 16; + } + + namespace polygon_volume { + constexpr uint32_t no_volume = 0b00 << 6; + constexpr uint32_t intensity_volume = 0b10 << 6; + constexpr uint32_t two_volumes = 0b11 << 6; + + constexpr uint32_t bit_mask = 0x3 << 6; + } + + namespace modifier_volume { + constexpr uint32_t last_in_volume = 0b01 << 6; + + constexpr uint32_t bit_mask = 0x3 << 6; + } + + namespace col_type { + constexpr uint32_t packed_color = 0 << 4; + constexpr uint32_t floating_color = 1 << 4; + constexpr uint32_t intensity_mode_1 = 2 << 4; + constexpr uint32_t intensity_mode_2 = 3 << 4; + + constexpr uint32_t bit_mask = 0x3 << 4; + } + + constexpr uint32_t texture = 1 << 3; + constexpr uint32_t offset = 1 << 2; + constexpr uint32_t gouraud = 1 << 1; + constexpr uint32_t _16bit_uv = 1 << 0; + } + +} diff --git a/dreamcast2/holly/ta/vertex_parameter.hpp b/dreamcast2/holly/ta/vertex_parameter.hpp new file mode 100644 index 0000000..a86dc47 --- /dev/null +++ b/dreamcast2/holly/ta/vertex_parameter.hpp @@ -0,0 +1,512 @@ +#pragma once + +#include +#include + +namespace holly::ta::vertex_parameter { + struct polygon_type_0 { + uint32_t parameter_control_word; + float x; + float y; + float z; + uint32_t _res0; + uint32_t _res1; + uint32_t base_color; + uint32_t _res2; + }; + static_assert((sizeof (polygon_type_0)) == 32); + static_assert((offsetof (struct polygon_type_0, parameter_control_word)) == 0x00); + static_assert((offsetof (struct polygon_type_0, x)) == 0x04); + static_assert((offsetof (struct polygon_type_0, y)) == 0x08); + static_assert((offsetof (struct polygon_type_0, z)) == 0x0c); + static_assert((offsetof (struct polygon_type_0, _res0)) == 0x10); + static_assert((offsetof (struct polygon_type_0, _res1)) == 0x14); + static_assert((offsetof (struct polygon_type_0, base_color)) == 0x18); + static_assert((offsetof (struct polygon_type_0, _res2)) == 0x1c); + + struct polygon_type_1 { + uint32_t parameter_control_word; + float x; + float y; + float z; + float base_color_alpha; + float base_color_r; + float base_color_g; + float base_color_b; + }; + static_assert((sizeof (polygon_type_1)) == 32); + static_assert((offsetof (struct polygon_type_1, parameter_control_word)) == 0x00); + static_assert((offsetof (struct polygon_type_1, x)) == 0x04); + static_assert((offsetof (struct polygon_type_1, y)) == 0x08); + static_assert((offsetof (struct polygon_type_1, z)) == 0x0c); + static_assert((offsetof (struct polygon_type_1, base_color_alpha)) == 0x10); + static_assert((offsetof (struct polygon_type_1, base_color_r)) == 0x14); + static_assert((offsetof (struct polygon_type_1, base_color_g)) == 0x18); + static_assert((offsetof (struct polygon_type_1, base_color_b)) == 0x1c); + + struct polygon_type_2 { + uint32_t parameter_control_word; + float x; + float y; + float z; + uint32_t _res0; + uint32_t _res1; + float base_intensity; + uint32_t _res2; + }; + static_assert((sizeof (polygon_type_2)) == 32); + static_assert((offsetof (struct polygon_type_2, parameter_control_word)) == 0x00); + static_assert((offsetof (struct polygon_type_2, x)) == 0x04); + static_assert((offsetof (struct polygon_type_2, y)) == 0x08); + static_assert((offsetof (struct polygon_type_2, z)) == 0x0c); + static_assert((offsetof (struct polygon_type_2, _res0)) == 0x10); + static_assert((offsetof (struct polygon_type_2, _res1)) == 0x14); + static_assert((offsetof (struct polygon_type_2, base_intensity)) == 0x18); + static_assert((offsetof (struct polygon_type_2, _res2)) == 0x1c); + + struct polygon_type_3 { + uint32_t parameter_control_word; + float x; + float y; + float z; + float u; + float v; + uint32_t base_color; + uint32_t offset_color; + }; + static_assert((sizeof (polygon_type_3)) == 32); + static_assert((offsetof (struct polygon_type_3, parameter_control_word)) == 0x00); + static_assert((offsetof (struct polygon_type_3, x)) == 0x04); + static_assert((offsetof (struct polygon_type_3, y)) == 0x08); + static_assert((offsetof (struct polygon_type_3, z)) == 0x0c); + static_assert((offsetof (struct polygon_type_3, u)) == 0x10); + static_assert((offsetof (struct polygon_type_3, v)) == 0x14); + static_assert((offsetof (struct polygon_type_3, base_color)) == 0x18); + static_assert((offsetof (struct polygon_type_3, offset_color)) == 0x1c); + + struct polygon_type_4 { + uint32_t parameter_control_word; + float x; + float y; + float z; + uint32_t u_v; + uint32_t _res0; + uint32_t base_color; + uint32_t offset_color; + }; + static_assert((sizeof (polygon_type_4)) == 32); + static_assert((offsetof (struct polygon_type_4, parameter_control_word)) == 0x00); + static_assert((offsetof (struct polygon_type_4, x)) == 0x04); + static_assert((offsetof (struct polygon_type_4, y)) == 0x08); + static_assert((offsetof (struct polygon_type_4, z)) == 0x0c); + static_assert((offsetof (struct polygon_type_4, u_v)) == 0x10); + static_assert((offsetof (struct polygon_type_4, _res0)) == 0x14); + static_assert((offsetof (struct polygon_type_4, base_color)) == 0x18); + static_assert((offsetof (struct polygon_type_4, offset_color)) == 0x1c); + + struct polygon_type_5 { + uint32_t parameter_control_word; + float x; + float y; + float z; + float u; + float v; + uint32_t _res0; + uint32_t _res1; + float base_color_alpha; + float base_color_r; + float base_color_g; + float base_color_b; + float offset_color_alpha; + float offset_color_r; + float offset_color_g; + float offset_color_b; + }; + static_assert((sizeof (polygon_type_5)) == 64); + static_assert((offsetof (struct polygon_type_5, parameter_control_word)) == 0x00); + static_assert((offsetof (struct polygon_type_5, x)) == 0x04); + static_assert((offsetof (struct polygon_type_5, y)) == 0x08); + static_assert((offsetof (struct polygon_type_5, z)) == 0x0c); + static_assert((offsetof (struct polygon_type_5, u)) == 0x10); + static_assert((offsetof (struct polygon_type_5, v)) == 0x14); + static_assert((offsetof (struct polygon_type_5, _res0)) == 0x18); + static_assert((offsetof (struct polygon_type_5, _res1)) == 0x1c); + static_assert((offsetof (struct polygon_type_5, base_color_alpha)) == 0x20); + static_assert((offsetof (struct polygon_type_5, base_color_r)) == 0x24); + static_assert((offsetof (struct polygon_type_5, base_color_g)) == 0x28); + static_assert((offsetof (struct polygon_type_5, base_color_b)) == 0x2c); + static_assert((offsetof (struct polygon_type_5, offset_color_alpha)) == 0x30); + static_assert((offsetof (struct polygon_type_5, offset_color_r)) == 0x34); + static_assert((offsetof (struct polygon_type_5, offset_color_g)) == 0x38); + static_assert((offsetof (struct polygon_type_5, offset_color_b)) == 0x3c); + + struct polygon_type_6 { + uint32_t parameter_control_word; + float x; + float y; + float z; + uint32_t u_v; + uint32_t _res0; + uint32_t _res1; + uint32_t _res2; + float base_color_alpha; + float base_color_r; + float base_color_g; + float base_color_b; + float offset_color_alpha; + float offset_color_r; + float offset_color_g; + float offset_color_b; + }; + static_assert((sizeof (polygon_type_6)) == 64); + static_assert((offsetof (struct polygon_type_6, parameter_control_word)) == 0x00); + static_assert((offsetof (struct polygon_type_6, x)) == 0x04); + static_assert((offsetof (struct polygon_type_6, y)) == 0x08); + static_assert((offsetof (struct polygon_type_6, z)) == 0x0c); + static_assert((offsetof (struct polygon_type_6, u_v)) == 0x10); + static_assert((offsetof (struct polygon_type_6, _res0)) == 0x14); + static_assert((offsetof (struct polygon_type_6, _res1)) == 0x18); + static_assert((offsetof (struct polygon_type_6, _res2)) == 0x1c); + static_assert((offsetof (struct polygon_type_6, base_color_alpha)) == 0x20); + static_assert((offsetof (struct polygon_type_6, base_color_r)) == 0x24); + static_assert((offsetof (struct polygon_type_6, base_color_g)) == 0x28); + static_assert((offsetof (struct polygon_type_6, base_color_b)) == 0x2c); + static_assert((offsetof (struct polygon_type_6, offset_color_alpha)) == 0x30); + static_assert((offsetof (struct polygon_type_6, offset_color_r)) == 0x34); + static_assert((offsetof (struct polygon_type_6, offset_color_g)) == 0x38); + static_assert((offsetof (struct polygon_type_6, offset_color_b)) == 0x3c); + + struct polygon_type_7 { + uint32_t parameter_control_word; + float x; + float y; + float z; + float u; + float v; + float base_intensity; + float offset_intensity; + }; + static_assert((sizeof (polygon_type_7)) == 32); + static_assert((offsetof (struct polygon_type_7, parameter_control_word)) == 0x00); + static_assert((offsetof (struct polygon_type_7, x)) == 0x04); + static_assert((offsetof (struct polygon_type_7, y)) == 0x08); + static_assert((offsetof (struct polygon_type_7, z)) == 0x0c); + static_assert((offsetof (struct polygon_type_7, u)) == 0x10); + static_assert((offsetof (struct polygon_type_7, v)) == 0x14); + static_assert((offsetof (struct polygon_type_7, base_intensity)) == 0x18); + static_assert((offsetof (struct polygon_type_7, offset_intensity)) == 0x1c); + + struct polygon_type_8 { + uint32_t parameter_control_word; + float x; + float y; + float z; + uint32_t u_v; + uint32_t _res0; + float base_intensity; + float offset_intensity; + }; + static_assert((sizeof (polygon_type_8)) == 32); + static_assert((offsetof (struct polygon_type_8, parameter_control_word)) == 0x00); + static_assert((offsetof (struct polygon_type_8, x)) == 0x04); + static_assert((offsetof (struct polygon_type_8, y)) == 0x08); + static_assert((offsetof (struct polygon_type_8, z)) == 0x0c); + static_assert((offsetof (struct polygon_type_8, u_v)) == 0x10); + static_assert((offsetof (struct polygon_type_8, _res0)) == 0x14); + static_assert((offsetof (struct polygon_type_8, base_intensity)) == 0x18); + static_assert((offsetof (struct polygon_type_8, offset_intensity)) == 0x1c); + + struct polygon_type_9 { + uint32_t parameter_control_word; + float x; + float y; + float z; + uint32_t base_color_0; + uint32_t base_color_1; + uint32_t _res0; + uint32_t _res1; + }; + static_assert((sizeof (polygon_type_9)) == 32); + static_assert((offsetof (struct polygon_type_9, parameter_control_word)) == 0x00); + static_assert((offsetof (struct polygon_type_9, x)) == 0x04); + static_assert((offsetof (struct polygon_type_9, y)) == 0x08); + static_assert((offsetof (struct polygon_type_9, z)) == 0x0c); + static_assert((offsetof (struct polygon_type_9, base_color_0)) == 0x10); + static_assert((offsetof (struct polygon_type_9, base_color_1)) == 0x14); + static_assert((offsetof (struct polygon_type_9, _res0)) == 0x18); + static_assert((offsetof (struct polygon_type_9, _res1)) == 0x1c); + + struct polygon_type_10 { + uint32_t parameter_control_word; + float x; + float y; + float z; + uint32_t base_intensity_0; + uint32_t base_intensity_1; + uint32_t _res0; + uint32_t _res1; + }; + static_assert((sizeof (polygon_type_10)) == 32); + static_assert((offsetof (struct polygon_type_10, parameter_control_word)) == 0x00); + static_assert((offsetof (struct polygon_type_10, x)) == 0x04); + static_assert((offsetof (struct polygon_type_10, y)) == 0x08); + static_assert((offsetof (struct polygon_type_10, z)) == 0x0c); + static_assert((offsetof (struct polygon_type_10, base_intensity_0)) == 0x10); + static_assert((offsetof (struct polygon_type_10, base_intensity_1)) == 0x14); + static_assert((offsetof (struct polygon_type_10, _res0)) == 0x18); + static_assert((offsetof (struct polygon_type_10, _res1)) == 0x1c); + + struct polygon_type_11 { + uint32_t parameter_control_word; + float x; + float y; + float z; + float u_0; + float v_0; + uint32_t base_color_0; + uint32_t offset_color_0; + float u_1; + float v_1; + uint32_t base_color_1; + uint32_t offset_color_1; + uint32_t _res0; + uint32_t _res1; + uint32_t _res2; + uint32_t _res3; + }; + static_assert((sizeof (polygon_type_11)) == 64); + static_assert((offsetof (struct polygon_type_11, parameter_control_word)) == 0x00); + static_assert((offsetof (struct polygon_type_11, x)) == 0x04); + static_assert((offsetof (struct polygon_type_11, y)) == 0x08); + static_assert((offsetof (struct polygon_type_11, z)) == 0x0c); + static_assert((offsetof (struct polygon_type_11, u_0)) == 0x10); + static_assert((offsetof (struct polygon_type_11, v_0)) == 0x14); + static_assert((offsetof (struct polygon_type_11, base_color_0)) == 0x18); + static_assert((offsetof (struct polygon_type_11, offset_color_0)) == 0x1c); + static_assert((offsetof (struct polygon_type_11, u_1)) == 0x20); + static_assert((offsetof (struct polygon_type_11, v_1)) == 0x24); + static_assert((offsetof (struct polygon_type_11, base_color_1)) == 0x28); + static_assert((offsetof (struct polygon_type_11, offset_color_1)) == 0x2c); + static_assert((offsetof (struct polygon_type_11, _res0)) == 0x30); + static_assert((offsetof (struct polygon_type_11, _res1)) == 0x34); + static_assert((offsetof (struct polygon_type_11, _res2)) == 0x38); + static_assert((offsetof (struct polygon_type_11, _res3)) == 0x3c); + + struct polygon_type_12 { + uint32_t parameter_control_word; + float x; + float y; + float z; + uint32_t u_v_0; + uint32_t _res0; + uint32_t base_color_0; + uint32_t offset_color_0; + uint32_t u_v_1; + uint32_t _res1; + uint32_t base_color_1; + uint32_t offset_color_1; + uint32_t _res2; + uint32_t _res3; + uint32_t _res4; + uint32_t _res5; + }; + static_assert((sizeof (polygon_type_12)) == 64); + static_assert((offsetof (struct polygon_type_12, parameter_control_word)) == 0x00); + static_assert((offsetof (struct polygon_type_12, x)) == 0x04); + static_assert((offsetof (struct polygon_type_12, y)) == 0x08); + static_assert((offsetof (struct polygon_type_12, z)) == 0x0c); + static_assert((offsetof (struct polygon_type_12, u_v_0)) == 0x10); + static_assert((offsetof (struct polygon_type_12, _res0)) == 0x14); + static_assert((offsetof (struct polygon_type_12, base_color_0)) == 0x18); + static_assert((offsetof (struct polygon_type_12, offset_color_0)) == 0x1c); + static_assert((offsetof (struct polygon_type_12, u_v_1)) == 0x20); + static_assert((offsetof (struct polygon_type_12, _res1)) == 0x24); + static_assert((offsetof (struct polygon_type_12, base_color_1)) == 0x28); + static_assert((offsetof (struct polygon_type_12, offset_color_1)) == 0x2c); + static_assert((offsetof (struct polygon_type_12, _res2)) == 0x30); + static_assert((offsetof (struct polygon_type_12, _res3)) == 0x34); + static_assert((offsetof (struct polygon_type_12, _res4)) == 0x38); + static_assert((offsetof (struct polygon_type_12, _res5)) == 0x3c); + + struct polygon_type_13 { + uint32_t parameter_control_word; + float x; + float y; + float z; + float u_0; + float v_0; + uint32_t base_intensity_0; + float offset_intensity_0; + float u_1; + float v_1; + uint32_t base_intensity_1; + float offset_intensity_1; + uint32_t _res0; + uint32_t _res1; + uint32_t _res2; + uint32_t _res3; + }; + static_assert((sizeof (polygon_type_13)) == 64); + static_assert((offsetof (struct polygon_type_13, parameter_control_word)) == 0x00); + static_assert((offsetof (struct polygon_type_13, x)) == 0x04); + static_assert((offsetof (struct polygon_type_13, y)) == 0x08); + static_assert((offsetof (struct polygon_type_13, z)) == 0x0c); + static_assert((offsetof (struct polygon_type_13, u_0)) == 0x10); + static_assert((offsetof (struct polygon_type_13, v_0)) == 0x14); + static_assert((offsetof (struct polygon_type_13, base_intensity_0)) == 0x18); + static_assert((offsetof (struct polygon_type_13, offset_intensity_0)) == 0x1c); + static_assert((offsetof (struct polygon_type_13, u_1)) == 0x20); + static_assert((offsetof (struct polygon_type_13, v_1)) == 0x24); + static_assert((offsetof (struct polygon_type_13, base_intensity_1)) == 0x28); + static_assert((offsetof (struct polygon_type_13, offset_intensity_1)) == 0x2c); + static_assert((offsetof (struct polygon_type_13, _res0)) == 0x30); + static_assert((offsetof (struct polygon_type_13, _res1)) == 0x34); + static_assert((offsetof (struct polygon_type_13, _res2)) == 0x38); + static_assert((offsetof (struct polygon_type_13, _res3)) == 0x3c); + + struct polygon_type_14 { + uint32_t parameter_control_word; + float x; + float y; + float z; + uint32_t u_v_0; + uint32_t _res0; + uint32_t base_intensity_0; + float offset_intensity_0; + uint32_t u_v_1; + uint32_t _res1; + uint32_t base_intensity_1; + float offset_intensity_1; + uint32_t _res2; + uint32_t _res3; + uint32_t _res4; + uint32_t _res5; + }; + static_assert((sizeof (polygon_type_14)) == 64); + static_assert((offsetof (struct polygon_type_14, parameter_control_word)) == 0x00); + static_assert((offsetof (struct polygon_type_14, x)) == 0x04); + static_assert((offsetof (struct polygon_type_14, y)) == 0x08); + static_assert((offsetof (struct polygon_type_14, z)) == 0x0c); + static_assert((offsetof (struct polygon_type_14, u_v_0)) == 0x10); + static_assert((offsetof (struct polygon_type_14, _res0)) == 0x14); + static_assert((offsetof (struct polygon_type_14, base_intensity_0)) == 0x18); + static_assert((offsetof (struct polygon_type_14, offset_intensity_0)) == 0x1c); + static_assert((offsetof (struct polygon_type_14, u_v_1)) == 0x20); + static_assert((offsetof (struct polygon_type_14, _res1)) == 0x24); + static_assert((offsetof (struct polygon_type_14, base_intensity_1)) == 0x28); + static_assert((offsetof (struct polygon_type_14, offset_intensity_1)) == 0x2c); + static_assert((offsetof (struct polygon_type_14, _res2)) == 0x30); + static_assert((offsetof (struct polygon_type_14, _res3)) == 0x34); + static_assert((offsetof (struct polygon_type_14, _res4)) == 0x38); + static_assert((offsetof (struct polygon_type_14, _res5)) == 0x3c); + + struct sprite_type_0 { + uint32_t parameter_control_word; + float a_x; + float a_y; + float a_z; + float b_x; + float b_y; + float b_z; + float c_x; + float c_y; + float c_z; + float d_x; + float d_y; + uint32_t _res0; + uint32_t _res1; + uint32_t _res2; + uint32_t _res3; + }; + static_assert((sizeof (sprite_type_0)) == 64); + static_assert((offsetof (struct sprite_type_0, parameter_control_word)) == 0x00); + static_assert((offsetof (struct sprite_type_0, a_x)) == 0x04); + static_assert((offsetof (struct sprite_type_0, a_y)) == 0x08); + static_assert((offsetof (struct sprite_type_0, a_z)) == 0x0c); + static_assert((offsetof (struct sprite_type_0, b_x)) == 0x10); + static_assert((offsetof (struct sprite_type_0, b_y)) == 0x14); + static_assert((offsetof (struct sprite_type_0, b_z)) == 0x18); + static_assert((offsetof (struct sprite_type_0, c_x)) == 0x1c); + static_assert((offsetof (struct sprite_type_0, c_y)) == 0x20); + static_assert((offsetof (struct sprite_type_0, c_z)) == 0x24); + static_assert((offsetof (struct sprite_type_0, d_x)) == 0x28); + static_assert((offsetof (struct sprite_type_0, d_y)) == 0x2c); + static_assert((offsetof (struct sprite_type_0, _res0)) == 0x30); + static_assert((offsetof (struct sprite_type_0, _res1)) == 0x34); + static_assert((offsetof (struct sprite_type_0, _res2)) == 0x38); + static_assert((offsetof (struct sprite_type_0, _res3)) == 0x3c); + + struct sprite_type_1 { + uint32_t parameter_control_word; + float a_x; + float a_y; + float a_z; + float b_x; + float b_y; + float b_z; + float c_x; + float c_y; + float c_z; + float d_x; + float d_y; + uint32_t _res0; + uint32_t a_u_a_v; + uint32_t b_u_b_v; + uint32_t c_u_c_v; + }; + static_assert((sizeof (sprite_type_1)) == 64); + static_assert((offsetof (struct sprite_type_1, parameter_control_word)) == 0x00); + static_assert((offsetof (struct sprite_type_1, a_x)) == 0x04); + static_assert((offsetof (struct sprite_type_1, a_y)) == 0x08); + static_assert((offsetof (struct sprite_type_1, a_z)) == 0x0c); + static_assert((offsetof (struct sprite_type_1, b_x)) == 0x10); + static_assert((offsetof (struct sprite_type_1, b_y)) == 0x14); + static_assert((offsetof (struct sprite_type_1, b_z)) == 0x18); + static_assert((offsetof (struct sprite_type_1, c_x)) == 0x1c); + static_assert((offsetof (struct sprite_type_1, c_y)) == 0x20); + static_assert((offsetof (struct sprite_type_1, c_z)) == 0x24); + static_assert((offsetof (struct sprite_type_1, d_x)) == 0x28); + static_assert((offsetof (struct sprite_type_1, d_y)) == 0x2c); + static_assert((offsetof (struct sprite_type_1, _res0)) == 0x30); + static_assert((offsetof (struct sprite_type_1, a_u_a_v)) == 0x34); + static_assert((offsetof (struct sprite_type_1, b_u_b_v)) == 0x38); + static_assert((offsetof (struct sprite_type_1, c_u_c_v)) == 0x3c); + + struct modifier_volume { + uint32_t parameter_control_word; + float a_x; + float a_y; + float a_z; + float b_x; + float b_y; + float b_z; + float c_x; + float c_y; + float c_z; + uint32_t _res0; + uint32_t _res1; + uint32_t _res2; + uint32_t _res3; + uint32_t _res4; + uint32_t _res5; + }; + static_assert((sizeof (modifier_volume)) == 64); + static_assert((offsetof (struct modifier_volume, parameter_control_word)) == 0x00); + static_assert((offsetof (struct modifier_volume, a_x)) == 0x04); + static_assert((offsetof (struct modifier_volume, a_y)) == 0x08); + static_assert((offsetof (struct modifier_volume, a_z)) == 0x0c); + static_assert((offsetof (struct modifier_volume, b_x)) == 0x10); + static_assert((offsetof (struct modifier_volume, b_y)) == 0x14); + static_assert((offsetof (struct modifier_volume, b_z)) == 0x18); + static_assert((offsetof (struct modifier_volume, c_x)) == 0x1c); + static_assert((offsetof (struct modifier_volume, c_y)) == 0x20); + static_assert((offsetof (struct modifier_volume, c_z)) == 0x24); + static_assert((offsetof (struct modifier_volume, _res0)) == 0x28); + static_assert((offsetof (struct modifier_volume, _res1)) == 0x2c); + static_assert((offsetof (struct modifier_volume, _res2)) == 0x30); + static_assert((offsetof (struct modifier_volume, _res3)) == 0x34); + static_assert((offsetof (struct modifier_volume, _res4)) == 0x38); + static_assert((offsetof (struct modifier_volume, _res5)) == 0x3c); + +} + diff --git a/dreamcast2/memorymap.hpp b/dreamcast2/memorymap.hpp index a9d5f90..06cb6b4 100644 --- a/dreamcast2/memorymap.hpp +++ b/dreamcast2/memorymap.hpp @@ -1,3 +1,5 @@ +#pragma once + #include extern volatile uint8_t system_boot_rom[0x200000] __asm("system_boot_rom") __attribute__((aligned(32))); diff --git a/dreamcast2/regs.mk b/dreamcast2/regs.mk index 395539c..ac70528 100644 --- a/dreamcast2/regs.mk +++ b/dreamcast2/regs.mk @@ -13,16 +13,25 @@ holly/holly_bits.hpp: regs/holly/holly_bits.csv regs/render_bits.py holly/core/region_array_bits.hpp: regs/holly/core/region_array_bits.csv regs/render_bits.py python regs/render_bits.py $< holly::core::region_array > $@ -holly/core/object_list_bits.hpp:regs/holly/core/object_list_bits.csv regs/render_bits.py +holly/core/object_list_bits.hpp: regs/holly/core/object_list_bits.csv regs/render_bits.py python regs/render_bits.py $< holly::core::object_list > $@ -holly/core/parameter_bits.hpp:regs/holly/core/parameter_bits.csv regs/render_bits.py +holly/core/parameter_bits.hpp: regs/holly/core/parameter_bits.csv regs/render_bits.py python regs/render_bits.py $< holly::core::parameter > $@ +holly/ta/parameter_bits.hpp: regs/holly/ta/parameter_bits.csv regs/render_bits.py + python regs/render_bits.py $< holly::ta::parameter > $@ + +holly/ta/global_parameter.hpp: regs/holly/ta/global_parameter.csv regs/render_ta_parameter_struct.py + python regs/render_ta_parameter_struct.py $< holly::ta::global_parameter > $@ + +holly/ta/vertex_parameter.hpp: regs/holly/ta/vertex_parameter.csv regs/render_ta_parameter_struct.py + python regs/render_ta_parameter_struct.py $< holly::ta::vertex_parameter > $@ + # SH7091 -sh7091/sh7091.hpp: regs/sh7091/sh7091.csv regs/sh7091.py - python regs/sh7091.py $< sh7091 > $@ +sh7091/sh7091.hpp: regs/sh7091/sh7091.csv regs/render_sh7091.py + python regs/render_sh7091.py $< sh7091 > $@ sh7091/sh7091_bits.hpp: regs/sh7091/sh7091_bits.csv regs/render_bits.py python regs/render_bits.py $< sh7091 > $@ diff --git a/dreamcast2/regs/generic_sparse_struct.py b/dreamcast2/regs/generic_sparse_struct.py new file mode 100644 index 0000000..4f34bed --- /dev/null +++ b/dreamcast2/regs/generic_sparse_struct.py @@ -0,0 +1,126 @@ +from dataclasses import dataclass + +class EndOfInput(Exception): + pass + +def next_row(ix, rows, advance): + if ix >= len(rows): + raise EndOfInput + + if advance: + while rows[ix][0] == "": + ix += 1 + if ix >= len(rows): + raise EndOfInput + row = rows[ix] + ix += 1 + return ix, row + +@dataclass +class FieldDeclaration: + offset: int + name: str + default: int + array_length: str + +@dataclass +class StructDeclaration: + name: str + fields: list[FieldDeclaration] + size: int + +def parse_type_declaration(ix, rows, expected_offset, expected_sizes): + ix, row = next_row(ix, rows, advance=True) + assert len(row) in {2, 3}, row + struct_name, *empty = row + assert all(e == "" for e in empty) + fields = [] + last_offset = 0 - expected_offset + res_ix = 0 + + def terminate(): + size = last_offset + expected_offset + assert size in expected_sizes, size + return ix, StructDeclaration( + struct_name, + fields, + size + ) + + seen_names = set() + + while True: + try: + ix, row = next_row(ix, rows, advance=False) + except EndOfInput: + return terminate() + if row[0] == "": + return terminate() + else: + default = None + if len(row) == 2: + _offset, name = row + elif len(row) == 3: + _offset, name, _default = row + if _default.strip() != "": + default = int(_default, 16) + else: + assert False, row + offset = int(_offset, 16) + assert offset == last_offset + expected_offset, (hex(offset), hex(last_offset)) + last_offset = offset + if name == "": + name = f"_res{res_ix}" + res_ix += 1 + + if fields and fields[-1].name == name: + assert offset == fields[-1].offset + (fields[-1].array_length * expected_offset) + fields[-1].array_length += 1 + else: + assert name not in seen_names, row + seen_names.add(name) + fields.append(FieldDeclaration(offset, name, default, 1)) + +def parse(rows, expected_offset, expected_sizes): + ix = 0 + declarations = [] + while True: + try: + ix, declaration = parse_type_declaration(ix, rows, expected_offset, expected_sizes) + except EndOfInput: + break + declarations.append(declaration) + + return declarations + +def render_static_assertions(declaration): + yield f"static_assert((sizeof ({declaration.name})) == {declaration.size});" + for field in declaration.fields: + yield f"static_assert((offsetof (struct {declaration.name}, {field.name})) == 0x{field.offset:02x});" + +def render_declaration(declaration, get_type): + yield f"struct {declaration.name} {{" + + for field in declaration.fields: + type = get_type(field.name) + if field.array_length == 1: + yield f"{type} {field.name};" + else: + yield f"{type} {field.name}[{field.array_length}];" + + yield "};" # struct {declaration.name} + yield from render_static_assertions(declaration) + +def render_declarations(namespace, declarations, get_type): + yield f"namespace {namespace} {{" + for declaration in declarations: + yield from render_declaration(declaration, get_type) + yield "" + yield "}" + +def headers(): + yield "#pragma once" + yield "" + yield "#include " + yield "#include " + yield "" diff --git a/dreamcast2/regs/holly/ta/global_parameter.ods b/dreamcast2/regs/holly/ta/global_parameter.ods new file mode 100644 index 0000000..5de3990 Binary files /dev/null and b/dreamcast2/regs/holly/ta/global_parameter.ods differ diff --git a/dreamcast2/regs/holly/ta/parameter_bits.ods b/dreamcast2/regs/holly/ta/parameter_bits.ods new file mode 100644 index 0000000..7327929 Binary files /dev/null and b/dreamcast2/regs/holly/ta/parameter_bits.ods differ diff --git a/dreamcast2/regs/holly/ta/vertex_parameter.ods b/dreamcast2/regs/holly/ta/vertex_parameter.ods new file mode 100644 index 0000000..d766222 Binary files /dev/null and b/dreamcast2/regs/holly/ta/vertex_parameter.ods differ diff --git a/dreamcast2/regs/render_bits.py b/dreamcast2/regs/render_bits.py index 1fe60c8..f8c23fe 100644 --- a/dreamcast2/regs/render_bits.py +++ b/dreamcast2/regs/render_bits.py @@ -152,7 +152,7 @@ def render_read_only(bit_def): bits = parse_bit_range(bit_def["bits"]) mask_value = mask_from_bits(bits) yield ( - f"constexpr uint32_t {escape(bit_def['bit_name'])}(uint32_t reg) {{ " + f"constexpr inline uint32_t {escape(bit_def['bit_name'])}(uint32_t reg) {{ " f"return (reg >> {min(bits)}) & {hex(mask_value)};" " }" ) @@ -173,7 +173,7 @@ def render_mask(bit_def): assert mask_value & mask_from_bits(bits) == mask_value, (mask_value, mask_from_bits(bits)) yield ( - f"constexpr uint32_t {escape(bit_def['bit_name'])}(uint32_t num) {{ " + f"constexpr inline uint32_t {escape(bit_def['bit_name'])}(uint32_t num) {{ " f"return (num & {hex(mask_value)}) << {min(bits)};" " }" ) diff --git a/dreamcast2/regs/render_ta_parameter_struct.py b/dreamcast2/regs/render_ta_parameter_struct.py new file mode 100644 index 0000000..134ffc6 --- /dev/null +++ b/dreamcast2/regs/render_ta_parameter_struct.py @@ -0,0 +1,68 @@ +import sys + +from generate import renderer +from csv_input import read_input_headerless +from generic_sparse_struct import parse +from generic_sparse_struct import headers +from generic_sparse_struct import render_declarations + +_field_types = { + "parameter_control_word": "uint32_t", + "user_clip_": "uint32_t", + "object_pointer": "uint32_t", + "bounding_box_": "uint32_t", + "isp_tsp_instruction_word": "uint32_t", + "tsp_instruction_word": "uint32_t", + "texture_control_word": "uint32_t", + "data_size_for_sort_dma": "uint32_t", + "next_address_for_sort_dma": "uint32_t", + "face_color_": "float", + "face_offset_color_": "float", + "x": "float", + "y": "float", + "z": "float", + "base_color_": "float", + "base_color_0": "uint32_t", + "base_color_1": "uint32_t", + "offset_color_0": "uint32_t", + "offset_color_1": "uint32_t", + "base_intensity_": "uint32_t", + "u": "float", + "v": "float", + "u_v": "uint32_t", + "base_color": "uint32_t", + "offset_color": "uint32_t", + "offset_color_": "float", + "base_intensity": "float", + "offset_intensity": "float", + "a_": "float", + "b_": "float", + "c_": "float", + "d_": "float", + "a_u_a_v": "uint32_t", + "b_u_b_v": "uint32_t", + "c_u_c_v": "uint32_t", + "_res": "uint32_t" +} + +def get_type(field_name: str): + match = None + match_len = 0 + for name, type in _field_types.items(): + if field_name.startswith(name) and len(name) >= match_len: + match = type + assert match_len != len(name), (name, match) + match_len = len(name) + assert match != None, field_name + return match + +if __name__ == "__main__": + rows = read_input_headerless(sys.argv[1]) + namespace = sys.argv[2] + declarations = parse(rows, + expected_offset=4, + expected_sizes={32, 64}) + render, out = renderer() + render(headers()) + render(render_declarations(namespace, declarations, get_type)) + print(out.getvalue()) diff --git a/dreamcast2/regs/sh7091/sh7091_bits.ods b/dreamcast2/regs/sh7091/sh7091_bits.ods index 5956d1e..77472eb 100644 Binary files a/dreamcast2/regs/sh7091/sh7091_bits.ods and b/dreamcast2/regs/sh7091/sh7091_bits.ods differ diff --git a/dreamcast2/sh7091/pref.hpp b/dreamcast2/sh7091/pref.hpp new file mode 100644 index 0000000..5ef1bfd --- /dev/null +++ b/dreamcast2/sh7091/pref.hpp @@ -0,0 +1,14 @@ +#pragma once + +#define pref(address) \ + { asm volatile ("pref @%0" : : "r" ((uint32_t)(address)) : "memory"); } + +namespace sh7091::ccn::qacr0 { + template + constexpr inline uint32_t address(T a) { return (((uint32_t)a) >> 24) & 0b11100; } +} + +namespace sh7091::ccn::qacr1 { + template + constexpr inline uint32_t address(T a) { return (((uint32_t)a) >> 24) & 0b11100; } +} diff --git a/dreamcast2/sh7091/sh7091_bits.hpp b/dreamcast2/sh7091/sh7091_bits.hpp index f6ac2c4..6ad2844 100644 --- a/dreamcast2/sh7091/sh7091_bits.hpp +++ b/dreamcast2/sh7091/sh7091_bits.hpp @@ -5,12 +5,12 @@ namespace sh7091 { namespace ccn { namespace pteh { - constexpr uint32_t VPN(uint32_t reg) { return (reg >> 10) & 0x3fffff; } - constexpr uint32_t ASID(uint32_t reg) { return (reg >> 0) & 0xff; } + constexpr inline uint32_t VPN(uint32_t reg) { return (reg >> 10) & 0x3fffff; } + constexpr inline uint32_t ASID(uint32_t reg) { return (reg >> 0) & 0xff; } } namespace ptel { - constexpr uint32_t PPN(uint32_t reg) { return (reg >> 10) & 0x7ffff; } + constexpr inline uint32_t PPN(uint32_t reg) { return (reg >> 10) & 0x7ffff; } namespace v { constexpr uint32_t invalid = 0 << 8; @@ -67,9 +67,9 @@ namespace sh7091 { } namespace mmucr { - constexpr uint32_t LRUI(uint32_t reg) { return (reg >> 26) & 0x3f; } - constexpr uint32_t URB(uint32_t reg) { return (reg >> 18) & 0x3f; } - constexpr uint32_t URC(uint32_t reg) { return (reg >> 10) & 0x3f; } + constexpr inline uint32_t LRUI(uint32_t reg) { return (reg >> 26) & 0x3f; } + constexpr inline uint32_t URB(uint32_t reg) { return (reg >> 18) & 0x3f; } + constexpr inline uint32_t URC(uint32_t reg) { return (reg >> 10) & 0x3f; } namespace sqmd { constexpr uint32_t user_privileged_access_possible = 0 << 9; @@ -100,11 +100,11 @@ namespace sh7091 { } namespace basra { - constexpr uint32_t basa(uint32_t num) { return (num & 0xff) << 0; } + constexpr inline uint32_t basa(uint32_t num) { return (num & 0xff) << 0; } } namespace basrb { - constexpr uint32_t basa(uint32_t num) { return (num & 0xff) << 0; } + constexpr inline uint32_t basa(uint32_t num) { return (num & 0xff) << 0; } } namespace ccr { @@ -171,15 +171,15 @@ namespace sh7091 { } namespace tra { - constexpr uint32_t imm(uint32_t reg) { return (reg >> 2) & 0xff; } + constexpr inline uint32_t imm(uint32_t reg) { return (reg >> 2) & 0xff; } } namespace expevt { - constexpr uint32_t exception_code(uint32_t reg) { return (reg >> 0) & 0xfff; } + constexpr inline uint32_t exception_code(uint32_t reg) { return (reg >> 0) & 0xfff; } } namespace intevt { - constexpr uint32_t exception_code(uint32_t reg) { return (reg >> 0) & 0xfff; } + constexpr inline uint32_t exception_code(uint32_t reg) { return (reg >> 0) & 0xfff; } } namespace ptea { @@ -205,18 +205,18 @@ namespace sh7091 { } namespace qacr0 { - constexpr uint32_t area(uint32_t num) { return (num & 0x7) << 2; } + constexpr inline uint32_t area(uint32_t num) { return (num & 0x7) << 2; } } namespace qacr1 { - constexpr uint32_t area(uint32_t num) { return (num & 0x7) << 2; } + constexpr inline uint32_t area(uint32_t num) { return (num & 0x7) << 2; } } } namespace dmac { namespace dmatcr { - constexpr uint32_t transfer_count(uint32_t num) { return (num & 0xffffff) << 0; } + constexpr inline uint32_t transfer_count(uint32_t num) { return (num & 0xffffff) << 0; } } namespace chcr { @@ -305,7 +305,7 @@ namespace sh7091 { } namespace rs { - constexpr uint32_t resource_select(uint32_t num) { return (num & 0xf) << 8; } + constexpr inline uint32_t resource_select(uint32_t num) { return (num & 0xf) << 8; } constexpr uint32_t bit_mask = 0xf << 8; } @@ -429,23 +429,23 @@ namespace sh7091 { } namespace ipra { - constexpr uint32_t TMU0(uint32_t num) { return (num & 0xf) << 12; } - constexpr uint32_t TMU1(uint32_t num) { return (num & 0xf) << 8; } - constexpr uint32_t TMU2(uint32_t num) { return (num & 0xf) << 4; } - constexpr uint32_t RTC(uint32_t num) { return (num & 0xf) << 0; } + constexpr inline uint32_t TMU0(uint32_t num) { return (num & 0xf) << 12; } + constexpr inline uint32_t TMU1(uint32_t num) { return (num & 0xf) << 8; } + constexpr inline uint32_t TMU2(uint32_t num) { return (num & 0xf) << 4; } + constexpr inline uint32_t RTC(uint32_t num) { return (num & 0xf) << 0; } } namespace iprb { - constexpr uint32_t WDT(uint32_t num) { return (num & 0xf) << 12; } - constexpr uint32_t REF(uint32_t num) { return (num & 0xf) << 8; } - constexpr uint32_t SCI1(uint32_t num) { return (num & 0xf) << 4; } + constexpr inline uint32_t WDT(uint32_t num) { return (num & 0xf) << 12; } + constexpr inline uint32_t REF(uint32_t num) { return (num & 0xf) << 8; } + constexpr inline uint32_t SCI1(uint32_t num) { return (num & 0xf) << 4; } } namespace iprc { - constexpr uint32_t GPIO(uint32_t num) { return (num & 0xf) << 12; } - constexpr uint32_t DMAC(uint32_t num) { return (num & 0xf) << 8; } - constexpr uint32_t SCIF(uint32_t num) { return (num & 0xf) << 4; } - constexpr uint32_t UDI(uint32_t num) { return (num & 0xf) << 0; } + constexpr inline uint32_t GPIO(uint32_t num) { return (num & 0xf) << 12; } + constexpr inline uint32_t DMAC(uint32_t num) { return (num & 0xf) << 8; } + constexpr inline uint32_t SCIF(uint32_t num) { return (num & 0xf) << 4; } + constexpr inline uint32_t UDI(uint32_t num) { return (num & 0xf) << 0; } } } @@ -653,13 +653,13 @@ namespace sh7091 { namespace scfsr2 { namespace per3_0 { - constexpr uint32_t number_of_parity_errors(uint32_t reg) { return (reg >> 12) & 0xf; } + constexpr inline uint32_t number_of_parity_errors(uint32_t reg) { return (reg >> 12) & 0xf; } constexpr uint32_t bit_mask = 0xf << 12; } namespace fer3_0 { - constexpr uint32_t number_of_framing_errors(uint32_t reg) { return (reg >> 8) & 0xf; } + constexpr inline uint32_t number_of_framing_errors(uint32_t reg) { return (reg >> 8) & 0xf; } constexpr uint32_t bit_mask = 0xf << 8; } @@ -770,8 +770,8 @@ namespace sh7091 { } namespace scfdr2 { - constexpr uint32_t transmit_data_bytes(uint32_t reg) { return (reg >> 8) & 0x1f; } - constexpr uint32_t receive_data_bytes(uint32_t reg) { return (reg >> 0) & 0x1f; } + constexpr inline uint32_t transmit_data_bytes(uint32_t reg) { return (reg >> 8) & 0x1f; } + constexpr inline uint32_t receive_data_bytes(uint32_t reg) { return (reg >> 0) & 0x1f; } } namespace scsptr2 { @@ -836,7 +836,7 @@ namespace sh7091 { constexpr uint32_t fd = 1 << 15; constexpr uint32_t m = 1 << 9; constexpr uint32_t q = 1 << 8; - constexpr uint32_t imask(uint32_t num) { return (num & 0xf) << 4; } + constexpr inline uint32_t imask(uint32_t num) { return (num & 0xf) << 4; } constexpr uint32_t s = 1 << 1; constexpr uint32_t t = 1 << 0; } diff --git a/dreamcast2/sh7091/store_queue_transfer.hpp b/dreamcast2/sh7091/store_queue_transfer.hpp index 6f8e205..bbc8bd3 100644 --- a/dreamcast2/sh7091/store_queue_transfer.hpp +++ b/dreamcast2/sh7091/store_queue_transfer.hpp @@ -1,6 +1,7 @@ #pragma once #include "sh7091/sh7091.hpp" +#include "sh7091/pref.hpp" #include "memorymap.hpp" namespace sh7091 { @@ -31,10 +32,7 @@ namespace sh7091 { base[5] = src32[5]; base[6] = src32[6]; base[7] = src32[7]; - asm volatile ("pref @%0" - : // output - : "r" (&base[0]) // input - : "memory"); + pref(&base[0]) length -= 32; base += 8; src32 += 8; @@ -66,10 +64,7 @@ namespace sh7091 { base[5] = value; base[6] = value; base[7] = value; - asm volatile ("pref @%0" - : // output - : "r" (&base[0]) // input - : "memory"); + pref(&base[0]); length -= 32; base += 8; } diff --git a/dreamcast2/systembus/systembus_bits.hpp b/dreamcast2/systembus/systembus_bits.hpp index 95ace0c..fc944c6 100644 --- a/dreamcast2/systembus/systembus_bits.hpp +++ b/dreamcast2/systembus/systembus_bits.hpp @@ -4,11 +4,11 @@ namespace systembus { namespace c2dstat { - constexpr uint32_t texture_memory_start_address(uint32_t num) { return (num & 0x13ffffe0) << 0; } + constexpr inline uint32_t texture_memory_start_address(uint32_t num) { return (num & 0x13ffffe0) << 0; } } namespace c2dlen { - constexpr uint32_t transfer_length(uint32_t num) { return (num & 0xffffe0) << 0; } + constexpr inline uint32_t transfer_length(uint32_t num) { return (num & 0xffffe0) << 0; } } namespace c2dst { @@ -74,9 +74,9 @@ namespace systembus { } namespace ffst { - constexpr uint32_t holly_cpu_if_block_internal_write_buffer(uint32_t reg) { return (reg >> 5) & 0x1; } - constexpr uint32_t holly_g2_if_block_internal_write_buffer(uint32_t reg) { return (reg >> 4) & 0x1; } - constexpr uint32_t aica_internal_write_buffer(uint32_t reg) { return (reg >> 0) & 0x1; } + constexpr inline uint32_t holly_cpu_if_block_internal_write_buffer(uint32_t reg) { return (reg >> 5) & 0x1; } + constexpr inline uint32_t holly_g2_if_block_internal_write_buffer(uint32_t reg) { return (reg >> 4) & 0x1; } + constexpr inline uint32_t aica_internal_write_buffer(uint32_t reg) { return (reg >> 0) & 0x1; } } namespace istext { diff --git a/tools/ftdi_transfer.cpp b/tools/ftdi_transfer.cpp index 98c4bb6..50da748 100644 --- a/tools/ftdi_transfer.cpp +++ b/tools/ftdi_transfer.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -87,6 +88,48 @@ int init_ftdi_context(struct ftdi_context * ftdi, uint32_t scbrr) } ftdi_list_free(&devlist); + + if (0) { + for (int i = 0; i < 2; i++) { + timespec t = {.tv_sec = 0, .tv_nsec = 33000 * 2 }; + + // toggle ACBUS5 low (g reset asserted) + uint8_t bitmask1 = (0b0001 << 4) | (0b0001 << 0); + res = ftdi_set_bitmode(ftdi, bitmask1, BITMODE_CBUS); + if (res < 0) { + fprintf(stderr, "ftdi_set_bitmode: %s\n", ftdi_get_error_string(ftdi)); + return -1; + } + printf("cbus1\n"); + + nanosleep(&t, NULL); + + // toggle ACBUS5 low (g reset deasserted) + uint8_t bitmask2 = (0b0000 << 4) | (0b0001 << 0); + res = ftdi_set_bitmode(ftdi, bitmask2, BITMODE_CBUS); + if (res < 0) { + fprintf(stderr, "ftdi_set_bitmode: %s\n", ftdi_get_error_string(ftdi)); + return -1; + } + printf("cbus2\n"); + + nanosleep(&t, NULL); + } + + uint8_t bitmask2 = (0b0000 << 4) | (0b0000 << 0); + res = ftdi_set_bitmode(ftdi, bitmask2, BITMODE_CBUS); + if (res < 0) { + fprintf(stderr, "ftdi_set_bitmode: %s\n", ftdi_get_error_string(ftdi)); + return -1; + } + + sleep(2); + printf("cbus3\n"); + ftdi_disable_bitbang(ftdi); + //while (1); + //return 0; + } + res = ftdi_set_baudrate(ftdi, round(dreamcast_rate(current_cks, scbrr))); if (res < 0) { fprintf(stderr, "ftdi_set_baudrate: %s\n", ftdi_get_error_string(ftdi));