diff --git a/common.mk b/common.mk index afa9463..d2b1975 100644 --- a/common.mk +++ b/common.mk @@ -136,6 +136,12 @@ maple/maple_bus_commands.hpp: regs/maple_bus_commands.csv regs/gen/maple_bus_com maple/maple_bus_bits.hpp: regs/maple_bus_bits.csv regs/gen/core_bits.py python regs/gen/core_bits.py $< > $@ +holly/ta_global_parameter.hpp: regs/global_parameter_format.csv regs/gen/ta_parameter_format.py + python regs/gen/ta_parameter_format.py $< ta_global_parameter > $@ + +holly/ta_vertex_parameter.hpp: regs/vertex_parameter_format.csv regs/gen/ta_parameter_format.py + python regs/gen/ta_parameter_format.py $< ta_vertex_parameter > $@ + clean: find -P \ -regextype posix-egrep \ diff --git a/example/modifier_volume.cpp b/example/modifier_volume.cpp index 3ed4db4..43ddf97 100644 --- a/example/modifier_volume.cpp +++ b/example/modifier_volume.cpp @@ -9,9 +9,12 @@ #include "holly/core_bits.hpp" #include "holly/ta_fifo_polygon_converter.hpp" #include "holly/ta_parameter.hpp" +#include "holly/ta_global_parameter.hpp" +#include "holly/ta_vertex_parameter.hpp" #include "holly/ta_bits.hpp" #include "holly/region_array.hpp" #include "holly/background.hpp" +#include "holly/isp_tsp.hpp" #include "memorymap.hpp" #include "geometry/plane.hpp" @@ -79,10 +82,14 @@ void transform_polygon(ta_parameter_writer& parameter, | tsp_instruction_word::dst_alpha_instr::zero | tsp_instruction_word::fog_control::no_fog; - parameter.append() = global_polygon_type_0(parameter_control_word, - isp_tsp_instruction_word, - tsp_instruction_word, - 0); + parameter.append() = + ta_global_parameter::polygon_type_0(parameter_control_word, + isp_tsp_instruction_word, + tsp_instruction_word, + 0, // texture_control_word + 0, // data_size_for_sort_dma + 0 // next_address_for_sort_dma + ); constexpr uint32_t strip_length = 3; for (uint32_t i = 0; i < strip_length; i++) { @@ -92,16 +99,16 @@ void transform_polygon(ta_parameter_writer& parameter, auto point = _transform(vertex, scale, theta); bool end_of_strip = i == strip_length - 1; - parameter.append() = - vertex_polygon_type_1(polygon_vertex_parameter_control_word(end_of_strip), - point.x, - point.y, - point.z, - color.a, // alpha - color.r, // red - color.g, // green - color.b // blue - ); + parameter.append() = + ta_vertex_parameter::polygon_type_1(polygon_vertex_parameter_control_word(end_of_strip), + point.x, + point.y, + point.z, + color.a, // alpha + color.r, // red + color.g, // green + color.b // blue + ); } } @@ -120,9 +127,10 @@ void transform_modifier_volume(ta_parameter_writer& parameter, const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::volume_instruction::normal_polygon | isp_tsp_instruction_word::culling_mode::no_culling; - parameter.append() = - global_modifier_volume(parameter_control_word, - isp_tsp_instruction_word); + parameter.append() = + ta_global_parameter::modifier_volume(parameter_control_word, + isp_tsp_instruction_word + ); for (uint32_t i = 0; i < num_faces; i++) { // world transform @@ -144,17 +152,17 @@ void transform_modifier_volume(ta_parameter_writer& parameter, const uint32_t last_isp_tsp_instruction_word = isp_tsp_instruction_word::volume_instruction::inside_last_polygon | isp_tsp_instruction_word::culling_mode::no_culling; - parameter.append() = - global_modifier_volume(last_parameter_control_word, - last_isp_tsp_instruction_word); + parameter.append() = + ta_global_parameter::modifier_volume(last_parameter_control_word, + last_isp_tsp_instruction_word); } - parameter.append() = - vertex_modifier_volume(modifier_volume_vertex_parameter_control_word(), - a.x, a.y, a.z, - b.x, b.y, b.z, - c.x, c.y, c.z); + parameter.append() = + ta_vertex_parameter::modifier_volume(modifier_volume_vertex_parameter_control_word(), + a.x, a.y, a.z, + b.x, b.y, b.z, + c.x, c.y, c.z); } } @@ -236,7 +244,7 @@ void main() */ } // end of opaque list - parameter.append() = global_end_of_list(); + parameter.append() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list); { // cube float scale = 1.f; @@ -247,7 +255,7 @@ void main() scale); } // end of opaque modifier list - parameter.append() = global_end_of_list(); + parameter.append() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list); ta_polygon_converter_transfer(ta_parameter_buf, parameter.offset); ta_wait_opaque_modifier_volume_list(); diff --git a/holly/ta_global_parameter.hpp b/holly/ta_global_parameter.hpp new file mode 100644 index 0000000..a1149e3 --- /dev/null +++ b/holly/ta_global_parameter.hpp @@ -0,0 +1,439 @@ +#pragma once + +#include + +namespace 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; + + end_of_list(const uint32_t parameter_control_word + ) + : parameter_control_word(parameter_control_word) + , _res0(0) + , _res1(0) + , _res2(0) + , _res3(0) + , _res4(0) + , _res5(0) + , _res6(0) + { } + }; + 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; + + user_tile_clip(const uint32_t parameter_control_word, + const uint32_t user_clip_x_min, + const uint32_t user_clip_y_min, + const uint32_t user_clip_x_max, + const uint32_t user_clip_y_max + ) + : parameter_control_word(parameter_control_word) + , _res0(0) + , _res1(0) + , _res2(0) + , user_clip_x_min(user_clip_x_min) + , user_clip_y_min(user_clip_y_min) + , user_clip_x_max(user_clip_x_max) + , user_clip_y_max(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; + + object_list_set(const uint32_t parameter_control_word, + const uint32_t object_pointer, + const uint32_t bounding_box_x_min, + const uint32_t bounding_box_y_min, + const uint32_t bounding_box_x_max, + const uint32_t bounding_box_y_max + ) + : parameter_control_word(parameter_control_word) + , object_pointer(object_pointer) + , _res0(0) + , _res1(0) + , bounding_box_x_min(bounding_box_x_min) + , bounding_box_y_min(bounding_box_y_min) + , bounding_box_x_max(bounding_box_x_max) + , bounding_box_y_max(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; + + polygon_type_0(const uint32_t parameter_control_word, + const uint32_t isp_tsp_instruction_word, + const uint32_t tsp_instruction_word, + const uint32_t texture_control_word, + const uint32_t data_size_for_sort_dma, + const uint32_t next_address_for_sort_dma + ) + : parameter_control_word(parameter_control_word) + , isp_tsp_instruction_word(isp_tsp_instruction_word) + , tsp_instruction_word(tsp_instruction_word) + , texture_control_word(texture_control_word) + , _res0(0) + , _res1(0) + , data_size_for_sort_dma(data_size_for_sort_dma) + , next_address_for_sort_dma(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; + + polygon_type_1(const uint32_t parameter_control_word, + const uint32_t isp_tsp_instruction_word, + const uint32_t tsp_instruction_word, + const uint32_t texture_control_word, + const float face_color_alpha, + const float face_color_r, + const float face_color_g, + const float face_color_b + ) + : parameter_control_word(parameter_control_word) + , isp_tsp_instruction_word(isp_tsp_instruction_word) + , tsp_instruction_word(tsp_instruction_word) + , texture_control_word(texture_control_word) + , face_color_alpha(face_color_alpha) + , face_color_r(face_color_r) + , face_color_g(face_color_g) + , face_color_b(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; + + polygon_type_2(const uint32_t parameter_control_word, + const uint32_t isp_tsp_instruction_word, + const uint32_t tsp_instruction_word, + const uint32_t texture_control_word, + const uint32_t data_size_for_sort_dma, + const uint32_t next_address_for_sort_dma, + const float face_color_alpha, + const float face_color_r, + const float face_color_g, + const float face_color_b, + const float face_offset_color_alpha, + const float face_offset_color_r, + const float face_offset_color_g, + const float face_offset_color_b + ) + : parameter_control_word(parameter_control_word) + , isp_tsp_instruction_word(isp_tsp_instruction_word) + , tsp_instruction_word(tsp_instruction_word) + , texture_control_word(texture_control_word) + , _res0(0) + , _res1(0) + , data_size_for_sort_dma(data_size_for_sort_dma) + , next_address_for_sort_dma(next_address_for_sort_dma) + , face_color_alpha(face_color_alpha) + , face_color_r(face_color_r) + , face_color_g(face_color_g) + , face_color_b(face_color_b) + , face_offset_color_alpha(face_offset_color_alpha) + , face_offset_color_r(face_offset_color_r) + , face_offset_color_g(face_offset_color_g) + , face_offset_color_b(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; + + polygon_type_3(const uint32_t parameter_control_word, + const uint32_t isp_tsp_instruction_word, + const uint32_t tsp_instruction_word_0, + const uint32_t texture_control_word_0, + const uint32_t tsp_instruction_word_1, + const uint32_t texture_control_word_1, + const uint32_t data_size_for_sort_dma, + const uint32_t next_address_for_sort_dma + ) + : parameter_control_word(parameter_control_word) + , isp_tsp_instruction_word(isp_tsp_instruction_word) + , tsp_instruction_word_0(tsp_instruction_word_0) + , texture_control_word_0(texture_control_word_0) + , tsp_instruction_word_1(tsp_instruction_word_1) + , texture_control_word_1(texture_control_word_1) + , data_size_for_sort_dma(data_size_for_sort_dma) + , next_address_for_sort_dma(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; + + polygon_type_4(const uint32_t parameter_control_word, + const uint32_t isp_tsp_instruction_word, + const uint32_t tsp_instruction_word_0, + const uint32_t texture_control_word_0, + const uint32_t tsp_instruction_word_1, + const uint32_t texture_control_word_1, + const uint32_t data_size_for_sort_dma, + const uint32_t next_address_for_sort_dma, + const float face_color_alpha_0, + const float face_color_r_0, + const float face_color_g_0, + const float face_color_b_0, + const float face_color_alpha_1, + const float face_color_r_1, + const float face_color_g_1, + const float face_color_b_1 + ) + : parameter_control_word(parameter_control_word) + , isp_tsp_instruction_word(isp_tsp_instruction_word) + , tsp_instruction_word_0(tsp_instruction_word_0) + , texture_control_word_0(texture_control_word_0) + , tsp_instruction_word_1(tsp_instruction_word_1) + , texture_control_word_1(texture_control_word_1) + , data_size_for_sort_dma(data_size_for_sort_dma) + , next_address_for_sort_dma(next_address_for_sort_dma) + , face_color_alpha_0(face_color_alpha_0) + , face_color_r_0(face_color_r_0) + , face_color_g_0(face_color_g_0) + , face_color_b_0(face_color_b_0) + , face_color_alpha_1(face_color_alpha_1) + , face_color_r_1(face_color_r_1) + , face_color_g_1(face_color_g_1) + , face_color_b_1(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; + + sprite(const uint32_t parameter_control_word, + const uint32_t isp_tsp_instruction_word, + const uint32_t tsp_instruction_word, + const uint32_t texture_control_word, + const uint32_t base_color, + const uint32_t offset_color, + const uint32_t data_size_for_sort_dma, + const uint32_t next_address_for_sort_dma + ) + : parameter_control_word(parameter_control_word) + , isp_tsp_instruction_word(isp_tsp_instruction_word) + , tsp_instruction_word(tsp_instruction_word) + , texture_control_word(texture_control_word) + , base_color(base_color) + , offset_color(offset_color) + , data_size_for_sort_dma(data_size_for_sort_dma) + , next_address_for_sort_dma(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; + + modifier_volume(const uint32_t parameter_control_word, + const uint32_t isp_tsp_instruction_word + ) + : parameter_control_word(parameter_control_word) + , isp_tsp_instruction_word(isp_tsp_instruction_word) + , _res0(0) + , _res1(0) + , _res2(0) + , _res3(0) + , _res4(0) + , _res5(0) + { } + }; + 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/holly/ta_parameter.hpp b/holly/ta_parameter.hpp index dff45e8..a155a2b 100644 --- a/holly/ta_parameter.hpp +++ b/holly/ta_parameter.hpp @@ -2,7 +2,6 @@ #include #include "../float_uint32.hpp" -#include "isp_tsp.hpp" namespace para_control { namespace para_type { @@ -66,8 +65,6 @@ namespace obj_control { constexpr uint32_t _16bit_uv = 1 << 0; } -static_assert((sizeof (float)) == (sizeof (uint32_t))); - constexpr uint32_t polygon_vertex_parameter_control_word(const bool end_of_strip) { return para_control::para_type::vertex_parameter @@ -82,513 +79,6 @@ constexpr uint32_t modifier_volume_vertex_parameter_control_word() | para_control::end_of_strip; } -struct vertex_polygon_type_0 { - uint32_t parameter_control_word; - float x; - float y; - float z; - uint32_t _res0; - uint32_t _res1; - uint32_t base_color; - uint32_t _res2; - - vertex_polygon_type_0(const uint32_t parameter_control_word, - const float x, - const float y, - const float z, - const uint32_t base_color - ) - : parameter_control_word(parameter_control_word) - , x(x) - , y(y) - , z(z) - , _res0(0) - , _res1(0) - , base_color(base_color) - , _res2(0) - { } -}; - -struct vertex_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; - - vertex_polygon_type_1(const uint32_t parameter_control_word, - const float x, - const float y, - const float z, - const float base_color_alpha, - const float base_color_r, - const float base_color_g, - const float base_color_b - ) - : parameter_control_word(parameter_control_word) - , x(x) - , y(y) - , z(z) - , base_color_alpha(base_color_alpha) - , base_color_r(base_color_r) - , base_color_g(base_color_g) - , base_color_b(base_color_b) - { } -}; - -struct vertex_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; - - vertex_polygon_type_2(const uint32_t parameter_control_word, - const float x, - const float y, - const float z, - const float base_intensity - ) - : parameter_control_word(parameter_control_word) - , x(x) - , y(y) - , z(z) - , _res0(0) - , _res1(0) - , base_intensity(base_intensity) - , _res2(0) - { } -}; - -struct vertex_polygon_type_3 { - uint32_t parameter_control_word; - float x; - float y; - float z; - float u; - float v; - uint32_t base_color; - uint32_t offset_color; - - vertex_polygon_type_3(const uint32_t parameter_control_word, - const float x, - const float y, - const float z, - const float u, - const float v, - const uint32_t base_color - ) - : parameter_control_word(parameter_control_word) - , x(x) - , y(y) - , z(z) - , u(u) - , v(v) - , base_color(base_color) - , offset_color(0) - { } -}; - -static_assert((sizeof (vertex_polygon_type_0)) == 32); -static_assert((offsetof (struct vertex_polygon_type_0, parameter_control_word)) == 0x00); -static_assert((offsetof (struct vertex_polygon_type_0, x)) == 0x04); -static_assert((offsetof (struct vertex_polygon_type_0, y)) == 0x08); -static_assert((offsetof (struct vertex_polygon_type_0, z)) == 0x0c); -static_assert((offsetof (struct vertex_polygon_type_0, _res0)) == 0x10); -static_assert((offsetof (struct vertex_polygon_type_0, _res1)) == 0x14); -static_assert((offsetof (struct vertex_polygon_type_0, base_color)) == 0x18); -static_assert((offsetof (struct vertex_polygon_type_0, _res2)) == 0x1c); - -struct vertex_polygon_type_4 { - uint32_t parameter_control_word; - float x; - float y; - float z; - uint32_t uv; - uint32_t _res0; - uint32_t base_color; - uint32_t offset_color; - - vertex_polygon_type_4(const uint32_t parameter_control_word, - const float x, - const float y, - const float z, - const uint32_t uv, - const uint32_t base_color - ) - : parameter_control_word(parameter_control_word) - , x(x) - , y(y) - , z(z) - , uv(uv) - , _res0(0) - , base_color(base_color) - , offset_color(0) - { } -}; - -struct global_polygon_type_0 { - uint32_t parameter_control_word; - uint32_t isp_tsp_instruction_word; - uint32_t tsp_instruction_word; - uint32_t texture_control_word; - uint32_t _res0; - uint32_t _res1; - uint32_t data_size_for_sort_dma; - uint32_t next_address_for_sort_dma; - - global_polygon_type_0(const uint32_t parameter_control_word, - const uint32_t isp_tsp_instruction_word, - const uint32_t tsp_instruction_word, - const uint32_t texture_control_word) - : parameter_control_word(parameter_control_word) - , isp_tsp_instruction_word(isp_tsp_instruction_word) - , tsp_instruction_word(tsp_instruction_word) - , texture_control_word(texture_control_word) - , _res0(0) - , _res1(0) - , data_size_for_sort_dma(0) - , next_address_for_sort_dma(0) - { } - - // untextured - global_polygon_type_0() - : parameter_control_word( para_control::para_type::polygon_or_modifier_volume - | para_control::list_type::opaque - | obj_control::col_type::packed_color ) - - , isp_tsp_instruction_word( isp_tsp_instruction_word::depth_compare_mode::greater - | isp_tsp_instruction_word::culling_mode::no_culling ) - - , tsp_instruction_word( tsp_instruction_word::src_alpha_instr::one - | tsp_instruction_word::dst_alpha_instr::zero - | tsp_instruction_word::fog_control::no_fog ) - - , texture_control_word( 0 ) - - , _res0(0) - , _res1(0) - , data_size_for_sort_dma(0) - , next_address_for_sort_dma(0) - { } - - // textured - global_polygon_type_0(const uint32_t texture_address) - : parameter_control_word( para_control::para_type::polygon_or_modifier_volume - | para_control::list_type::opaque - | obj_control::col_type::packed_color - | obj_control::texture ) - - , isp_tsp_instruction_word( isp_tsp_instruction_word::depth_compare_mode::greater - | isp_tsp_instruction_word::culling_mode::no_culling ) - - // Because a value of "0.0" is invalid for [MIP-Map] D [adjust], it must not be specified. - , tsp_instruction_word( tsp_instruction_word::src_alpha_instr::one - | tsp_instruction_word::dst_alpha_instr::zero - | tsp_instruction_word::fog_control::no_fog - //| tsp_instruction_word::mip_map_d_adjust(0b0100) // 1.0 (2.2 fixed-point) - //| tsp_instruction_word::filter_mode::bilinear_filter - //| tsp_instruction_word::clamp_uv::uv - //| tsp_instruction_word::flip_uv::uv - | tsp_instruction_word::texture_u_size::_128 // 128px - | tsp_instruction_word::texture_v_size::_128 ) // 128px - - , texture_control_word( texture_control_word::pixel_format::_565 - | texture_control_word::scan_order::non_twiddled - | texture_control_word::texture_address(texture_address / 8) ) - - , _res0(0) - , _res1(0) - , data_size_for_sort_dma(0) - , next_address_for_sort_dma(0) - { if ((texture_address & 63) != 0) { while (1); } } -}; - -static_assert((sizeof (global_polygon_type_0)) == 32); -static_assert((offsetof (struct global_polygon_type_0, parameter_control_word)) == 0x00); -static_assert((offsetof (struct global_polygon_type_0, isp_tsp_instruction_word)) == 0x04); -static_assert((offsetof (struct global_polygon_type_0, tsp_instruction_word)) == 0x08); -static_assert((offsetof (struct global_polygon_type_0, texture_control_word)) == 0x0c); -static_assert((offsetof (struct global_polygon_type_0, _res0)) == 0x10); -static_assert((offsetof (struct global_polygon_type_0, _res1)) == 0x14); -static_assert((offsetof (struct global_polygon_type_0, data_size_for_sort_dma)) == 0x18); -static_assert((offsetof (struct global_polygon_type_0, next_address_for_sort_dma)) == 0x1c); - -struct global_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; - - global_polygon_type_1(const uint32_t parameter_control_word, - const uint32_t isp_tsp_instruction_word, - const uint32_t tsp_instruction_word, - const uint32_t texture_control_word, - const float face_color_alpha, - const float face_color_r, - const float face_color_g, - const float face_color_b) - : parameter_control_word(parameter_control_word) - , isp_tsp_instruction_word(isp_tsp_instruction_word) - , tsp_instruction_word(tsp_instruction_word) - , texture_control_word(texture_control_word) - , face_color_alpha(face_color_alpha) - , face_color_r(face_color_r) - , face_color_g(face_color_g) - , face_color_b(face_color_b) - { } -}; - -struct global_sprite { - uint32_t parameter_control_word; - uint32_t isp_tsp_instruction_word; - uint32_t tsp_instruction_word; - uint32_t texture_control_word; - uint32_t base_color; - uint32_t offset_color; - uint32_t data_size_for_sort_dma; - uint32_t next_address_for_sort_dma; - - global_sprite(const uint32_t base_color) - : parameter_control_word( para_control::para_type::sprite - | para_control::list_type::opaque - | obj_control::col_type::packed_color ) - , isp_tsp_instruction_word( isp_tsp_instruction_word::depth_compare_mode::always - | isp_tsp_instruction_word::culling_mode::no_culling ) - , tsp_instruction_word( tsp_instruction_word::src_alpha_instr::one - | tsp_instruction_word::dst_alpha_instr::zero - | tsp_instruction_word::fog_control::no_fog) - , texture_control_word(0) - , base_color(base_color) - , offset_color(0) - , data_size_for_sort_dma(0) - , next_address_for_sort_dma(0) - { } -}; - -static_assert((sizeof (global_sprite)) == 32); - -struct global_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; - - global_modifier_volume(const uint32_t parameter_control_word, - const uint32_t isp_tsp_instruction_word) - : parameter_control_word(parameter_control_word) - , isp_tsp_instruction_word(isp_tsp_instruction_word) - , _res0(0) - , _res1(0) - , _res2(0) - , _res3(0) - , _res4(0) - , _res5(0) - { } -}; - -static_assert((sizeof (global_modifier_volume)) == 32); - -struct vertex_sprite_type_0 { - uint32_t parameter_control_word; - float ax; - float ay; - float az; - float bx; - float by; - float bz; - float cx; - - float cy; - float cz; - float dx; - float dy; - float _res0; - float _res1; - float _res2; - float _res3; - - vertex_sprite_type_0(const float ax, - const float ay, - const float az, - const float bx, - const float by, - const float bz, - const float cx, - const float cy, - const float cz, - const float dx, - const float dy) - : parameter_control_word(para_control::para_type::vertex_parameter) - , ax(ax) - , ay(ay) - , az(az) - , bx(bx) - , by(by) - , bz(bz) - , cx(cx) - , cy(cy) - , dx(dx) - , dy(dy) - , _res0(0) - , _res1(0) - , _res2(0) - , _res3(0) - {} -}; - -static_assert((sizeof (vertex_sprite_type_0)) == 64); - -struct vertex_sprite_type_1 { - uint32_t parameter_control_word; - float ax; - float ay; - float az; - float bx; - float by; - float bz; - float cx; - - float cy; - float cz; - float dx; - float dy; - float _res0; - uint32_t au_av; - uint32_t bu_bv; - uint32_t cu_cv; - - vertex_sprite_type_1(const float ax, - const float ay, - const float az, - const float bx, - const float by, - const float bz, - const float cx, - const float cy, - const float cz, - const float dx, - const float dy, - const uint32_t au_av, - const uint32_t bu_bv, - const uint32_t cu_cv) - : parameter_control_word(para_control::para_type::vertex_parameter) - , ax(ax) - , ay(ay) - , az(az) - , bx(bx) - , by(by) - , bz(bz) - , cx(cx) - , cy(cy) - , dx(dx) - , dy(dy) - , _res0(0) - , au_av(au_av) - , bu_bv(bu_bv) - , cu_cv(cu_cv) - {} -}; - -static_assert((sizeof (vertex_sprite_type_1)) == 64); - -struct vertex_modifier_volume { - uint32_t parameter_control_word; - float ax; - float ay; - float az; - float bx; - float by; - float bz; - float cx; - float cy; - float cz; - float _res0; - float _res1; - float _res2; - float _res3; - float _res4; - float _res5; - - vertex_modifier_volume(const uint32_t parameter_control_word, - const float ax, - const float ay, - const float az, - const float bx, - const float by, - const float bz, - const float cx, - const float cy, - const float cz - ) - : parameter_control_word(parameter_control_word) - , ax(ax) - , ay(ay) - , az(az) - , bx(bx) - , by(by) - , bz(bz) - , cx(cx) - , cy(cy) - , cz(cz) - , _res0(0) - , _res1(0) - , _res2(0) - , _res3(0) - , _res4(0) - , _res5(0) - { } -}; - -static_assert((sizeof (vertex_modifier_volume)) == 64); - -struct global_end_of_list { - uint32_t parameter_control_word; - uint32_t _res0; - uint32_t _res1; - uint32_t _res2; - uint32_t _res3; - uint32_t _res4; - uint32_t _res5; - uint32_t _res6; - - global_end_of_list() - : parameter_control_word(para_control::para_type::end_of_list) - , _res0(0) - , _res1(0) - , _res2(0) - , _res3(0) - , _res4(0) - , _res5(0) - , _res6(0) - { } -}; - -static_assert((sizeof (global_end_of_list)) == 32); -static_assert((offsetof (struct global_end_of_list, parameter_control_word)) == 0x00); -static_assert((offsetof (struct global_end_of_list, _res0)) == 0x04); -static_assert((offsetof (struct global_end_of_list, _res1)) == 0x08); -static_assert((offsetof (struct global_end_of_list, _res2)) == 0x0c); -static_assert((offsetof (struct global_end_of_list, _res3)) == 0x10); -static_assert((offsetof (struct global_end_of_list, _res4)) == 0x14); -static_assert((offsetof (struct global_end_of_list, _res5)) == 0x18); -static_assert((offsetof (struct global_end_of_list, _res6)) == 0x1c); - - struct ta_parameter_writer { uint32_t * buf; uint32_t offset; // in bytes @@ -605,20 +95,6 @@ struct ta_parameter_writer { return t; } }; -/* -union ta_parameter { - struct global_polygon_type_0 global_polygon_type_0; - struct global_sprite global_sprite; - - struct vertex_polygon_type_0 vertex_polygon_type_0; - struct vertex_polygon_type_3 vertex_polygon_type_3; - - struct vertex_sprite_type_0 vertex_sprite_type_0; - - struct global_end_of_list global_end_of_list; -}; -static_assert((sizeof (ta_parameter)) == 32); -*/ uint32_t uv_16bit(float u, float v) { diff --git a/holly/ta_vertex_parameter.hpp b/holly/ta_vertex_parameter.hpp new file mode 100644 index 0000000..f858f99 --- /dev/null +++ b/holly/ta_vertex_parameter.hpp @@ -0,0 +1,949 @@ +#pragma once + +#include + +namespace 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; + + polygon_type_0(const uint32_t parameter_control_word, + const float x, + const float y, + const float z, + const uint32_t base_color + ) + : parameter_control_word(parameter_control_word) + , x(x) + , y(y) + , z(z) + , _res0(0) + , _res1(0) + , base_color(base_color) + , _res2(0) + { } + }; + 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; + + polygon_type_1(const uint32_t parameter_control_word, + const float x, + const float y, + const float z, + const float base_color_alpha, + const float base_color_r, + const float base_color_g, + const float base_color_b + ) + : parameter_control_word(parameter_control_word) + , x(x) + , y(y) + , z(z) + , base_color_alpha(base_color_alpha) + , base_color_r(base_color_r) + , base_color_g(base_color_g) + , base_color_b(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; + + polygon_type_2(const uint32_t parameter_control_word, + const float x, + const float y, + const float z, + const float base_intensity + ) + : parameter_control_word(parameter_control_word) + , x(x) + , y(y) + , z(z) + , _res0(0) + , _res1(0) + , base_intensity(base_intensity) + , _res2(0) + { } + }; + 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; + + polygon_type_3(const uint32_t parameter_control_word, + const float x, + const float y, + const float z, + const float u, + const float v, + const uint32_t base_color, + const uint32_t offset_color + ) + : parameter_control_word(parameter_control_word) + , x(x) + , y(y) + , z(z) + , u(u) + , v(v) + , base_color(base_color) + , offset_color(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; + + polygon_type_4(const uint32_t parameter_control_word, + const float x, + const float y, + const float z, + const uint32_t u_v, + const uint32_t base_color, + const uint32_t offset_color + ) + : parameter_control_word(parameter_control_word) + , x(x) + , y(y) + , z(z) + , u_v(u_v) + , _res0(0) + , base_color(base_color) + , offset_color(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; + + polygon_type_5(const uint32_t parameter_control_word, + const float x, + const float y, + const float z, + const float u, + const float v, + const float base_color_alpha, + const float base_color_r, + const float base_color_g, + const float base_color_b, + const float offset_color_alpha, + const float offset_color_r, + const float offset_color_g, + const float offset_color_b + ) + : parameter_control_word(parameter_control_word) + , x(x) + , y(y) + , z(z) + , u(u) + , v(v) + , _res0(0) + , _res1(0) + , base_color_alpha(base_color_alpha) + , base_color_r(base_color_r) + , base_color_g(base_color_g) + , base_color_b(base_color_b) + , offset_color_alpha(offset_color_alpha) + , offset_color_r(offset_color_r) + , offset_color_g(offset_color_g) + , offset_color_b(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; + + polygon_type_6(const uint32_t parameter_control_word, + const float x, + const float y, + const float z, + const uint32_t u_v, + const float base_color_alpha, + const float base_color_r, + const float base_color_g, + const float base_color_b, + const float offset_color_alpha, + const float offset_color_r, + const float offset_color_g, + const float offset_color_b + ) + : parameter_control_word(parameter_control_word) + , x(x) + , y(y) + , z(z) + , u_v(u_v) + , _res0(0) + , _res1(0) + , _res2(0) + , base_color_alpha(base_color_alpha) + , base_color_r(base_color_r) + , base_color_g(base_color_g) + , base_color_b(base_color_b) + , offset_color_alpha(offset_color_alpha) + , offset_color_r(offset_color_r) + , offset_color_g(offset_color_g) + , offset_color_b(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; + + polygon_type_7(const uint32_t parameter_control_word, + const float x, + const float y, + const float z, + const float u, + const float v, + const float base_intensity, + const float offset_intensity + ) + : parameter_control_word(parameter_control_word) + , x(x) + , y(y) + , z(z) + , u(u) + , v(v) + , base_intensity(base_intensity) + , offset_intensity(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; + + polygon_type_8(const uint32_t parameter_control_word, + const float x, + const float y, + const float z, + const uint32_t u_v, + const float base_intensity, + const float offset_intensity + ) + : parameter_control_word(parameter_control_word) + , x(x) + , y(y) + , z(z) + , u_v(u_v) + , _res0(0) + , base_intensity(base_intensity) + , offset_intensity(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; + float base_color_0; + float base_color_1; + uint32_t _res0; + uint32_t _res1; + + polygon_type_9(const uint32_t parameter_control_word, + const float x, + const float y, + const float z, + const float base_color_0, + const float base_color_1 + ) + : parameter_control_word(parameter_control_word) + , x(x) + , y(y) + , z(z) + , base_color_0(base_color_0) + , base_color_1(base_color_1) + , _res0(0) + , _res1(0) + { } + }; + 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; + float base_intensity_0; + float base_intensity_1; + uint32_t _res0; + uint32_t _res1; + + polygon_type_10(const uint32_t parameter_control_word, + const float x, + const float y, + const float z, + const float base_intensity_0, + const float base_intensity_1 + ) + : parameter_control_word(parameter_control_word) + , x(x) + , y(y) + , z(z) + , base_intensity_0(base_intensity_0) + , base_intensity_1(base_intensity_1) + , _res0(0) + , _res1(0) + { } + }; + 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; + float base_color_0; + float offset_color_0; + float u_1; + float v_1; + float base_color_1; + float offset_color_1; + uint32_t _res0; + uint32_t _res1; + uint32_t _res2; + uint32_t _res3; + + polygon_type_11(const uint32_t parameter_control_word, + const float x, + const float y, + const float z, + const float u_0, + const float v_0, + const float base_color_0, + const float offset_color_0, + const float u_1, + const float v_1, + const float base_color_1, + const float offset_color_1 + ) + : parameter_control_word(parameter_control_word) + , x(x) + , y(y) + , z(z) + , u_0(u_0) + , v_0(v_0) + , base_color_0(base_color_0) + , offset_color_0(offset_color_0) + , u_1(u_1) + , v_1(v_1) + , base_color_1(base_color_1) + , offset_color_1(offset_color_1) + , _res0(0) + , _res1(0) + , _res2(0) + , _res3(0) + { } + }; + 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; + float base_color_0; + float offset_color_0; + uint32_t u_v_1; + uint32_t _res1; + float base_color_1; + float offset_color_1; + uint32_t _res2; + uint32_t _res3; + uint32_t _res4; + uint32_t _res5; + + polygon_type_12(const uint32_t parameter_control_word, + const float x, + const float y, + const float z, + const uint32_t u_v_0, + const float base_color_0, + const float offset_color_0, + const uint32_t u_v_1, + const float base_color_1, + const float offset_color_1 + ) + : parameter_control_word(parameter_control_word) + , x(x) + , y(y) + , z(z) + , u_v_0(u_v_0) + , _res0(0) + , base_color_0(base_color_0) + , offset_color_0(offset_color_0) + , u_v_1(u_v_1) + , _res1(0) + , base_color_1(base_color_1) + , offset_color_1(offset_color_1) + , _res2(0) + , _res3(0) + , _res4(0) + , _res5(0) + { } + }; + 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; + float base_intensity_0; + float offset_intensity_0; + float u_1; + float v_1; + float base_intensity_1; + float offset_intensity_1; + uint32_t _res0; + uint32_t _res1; + uint32_t _res2; + uint32_t _res3; + + polygon_type_13(const uint32_t parameter_control_word, + const float x, + const float y, + const float z, + const float u_0, + const float v_0, + const float base_intensity_0, + const float offset_intensity_0, + const float u_1, + const float v_1, + const float base_intensity_1, + const float offset_intensity_1 + ) + : parameter_control_word(parameter_control_word) + , x(x) + , y(y) + , z(z) + , u_0(u_0) + , v_0(v_0) + , base_intensity_0(base_intensity_0) + , offset_intensity_0(offset_intensity_0) + , u_1(u_1) + , v_1(v_1) + , base_intensity_1(base_intensity_1) + , offset_intensity_1(offset_intensity_1) + , _res0(0) + , _res1(0) + , _res2(0) + , _res3(0) + { } + }; + 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; + float base_intensity_0; + float offset_intensity_0; + uint32_t u_v_1; + uint32_t _res1; + float base_intensity_1; + float offset_intensity_1; + uint32_t _res2; + uint32_t _res3; + uint32_t _res4; + uint32_t _res5; + + polygon_type_14(const uint32_t parameter_control_word, + const float x, + const float y, + const float z, + const uint32_t u_v_0, + const float base_intensity_0, + const float offset_intensity_0, + const uint32_t u_v_1, + const float base_intensity_1, + const float offset_intensity_1 + ) + : parameter_control_word(parameter_control_word) + , x(x) + , y(y) + , z(z) + , u_v_0(u_v_0) + , _res0(0) + , base_intensity_0(base_intensity_0) + , offset_intensity_0(offset_intensity_0) + , u_v_1(u_v_1) + , _res1(0) + , base_intensity_1(base_intensity_1) + , offset_intensity_1(offset_intensity_1) + , _res2(0) + , _res3(0) + , _res4(0) + , _res5(0) + { } + }; + 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; + + sprite_type_0(const uint32_t parameter_control_word, + const float a_x, + const float a_y, + const float a_z, + const float b_x, + const float b_y, + const float b_z, + const float c_x, + const float c_y, + const float c_z, + const float d_x, + const float d_y + ) + : parameter_control_word(parameter_control_word) + , a_x(a_x) + , a_y(a_y) + , a_z(a_z) + , b_x(b_x) + , b_y(b_y) + , b_z(b_z) + , c_x(c_x) + , c_y(c_y) + , c_z(c_z) + , d_x(d_x) + , d_y(d_y) + , _res0(0) + , _res1(0) + , _res2(0) + , _res3(0) + { } + }; + 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; + + sprite_type_1(const uint32_t parameter_control_word, + const float a_x, + const float a_y, + const float a_z, + const float b_x, + const float b_y, + const float b_z, + const float c_x, + const float c_y, + const float c_z, + const float d_x, + const float d_y, + const uint32_t a_u_a_v, + const uint32_t b_u_b_v, + const uint32_t c_u_c_v + ) + : parameter_control_word(parameter_control_word) + , a_x(a_x) + , a_y(a_y) + , a_z(a_z) + , b_x(b_x) + , b_y(b_y) + , b_z(b_z) + , c_x(c_x) + , c_y(c_y) + , c_z(c_z) + , d_x(d_x) + , d_y(d_y) + , _res0(0) + , a_u_a_v(a_u_a_v) + , b_u_b_v(b_u_b_v) + , c_u_c_v(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; + + modifier_volume(const uint32_t parameter_control_word, + const float a_x, + const float a_y, + const float a_z, + const float b_x, + const float b_y, + const float b_z, + const float c_x, + const float c_y, + const float c_z + ) + : parameter_control_word(parameter_control_word) + , a_x(a_x) + , a_y(a_y) + , a_z(a_z) + , b_x(b_x) + , b_y(b_y) + , b_z(b_z) + , c_x(c_x) + , c_y(c_y) + , c_z(c_z) + , _res0(0) + , _res1(0) + , _res2(0) + , _res3(0) + , _res4(0) + , _res5(0) + { } + }; + 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/regs/gen/generate.py b/regs/gen/generate.py index 5686039..2871189 100644 --- a/regs/gen/generate.py +++ b/regs/gen/generate.py @@ -15,7 +15,10 @@ def _render(out, lines): level -= 2 assert level >= 0, out.getvalue() - out.write(indent * level + l + "\n") + if len(l) == 0: + out.write("\n") + else: + out.write(indent * level + l + "\n") if l and (l[-1] == "{" or l[-1] == "("): level += 2 diff --git a/regs/gen/ta_parameter_format.py b/regs/gen/ta_parameter_format.py index 3da07dd..5ab8272 100644 --- a/regs/gen/ta_parameter_format.py +++ b/regs/gen/ta_parameter_format.py @@ -37,13 +37,14 @@ _field_types = { "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(type) and len(name) >= match_len: + if field_name.startswith(name) and len(name) >= match_len: match = type assert match_len != len(name), (name, match) match_len = len(name) @@ -75,6 +76,7 @@ class FieldDeclaration: class StructDeclaration: name: str fields: list[FieldDeclaration] + size: int def parse_type_declaration(ix, rows): ix, row = next_row(ix, rows, advance=True) @@ -83,20 +85,33 @@ def parse_type_declaration(ix, rows): assert empty == "", row fields = [] last_offset = -4 + res_ix = 0 + + def terminate(): + size = last_offset + 4 + assert size == 32 or size == 64, size + return ix, StructDeclaration( + struct_name, + fields, + size + ) + while True: - ix, row = next_row(ix, rows, advance=False) + try: + ix, row = next_row(ix, rows, advance=False) + except EndOfInput: + return terminate() if row[0] == "": - assert last_offset + 4 == 32 or last_offset + 4 == 64, last_offset + 4 - return ix, StructDeclaration( - struct_name, - fields - ) + return terminate() else: assert len(row) == 2, row _offset, name = row offset = int(_offset, 16) assert offset == last_offset + 4, (hex(offset), hex(last_offset)) last_offset = offset + if name == "": + name = f"_res{res_ix}" + res_ix += 1 fields.append(FieldDeclaration(offset, name)) def parse(rows): @@ -111,12 +126,44 @@ def parse(rows): return declarations +def render_initializer(declaration): + initializer = f"{declaration.name}(" + padding = " " * len(initializer) + def start(i): + if i == 0: + return initializer + else: + return padding + + nonres_fields = [f for f in declaration.fields if not f.name.startswith('_res')] + for i, field in enumerate(nonres_fields): + s = start(i) + type = get_type(field.name) + comma = ',' if i + 1 < len(nonres_fields) else '' + yield s + f"const {type} {field.name}" + comma + yield padding + ')' + + for i, field in enumerate(declaration.fields): + value = field.name if not field.name.startswith('_res') else '0' + s = ':' if i == 0 else ',' + yield " " + s + f" {field.name}({value})" + yield "{ }" + + +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): yield f"struct {declaration.name} {{" for field in declaration.fields: - yield f"" + type = get_type(field.name) + yield f"{type} {field.name};" + yield "" + yield from render_initializer(declaration) yield "};" - + yield from render_static_assertions(declaration) def render_declarations(namespace, declarations): yield f"namespace {namespace} {{" @@ -125,10 +172,16 @@ def render_declarations(namespace, declarations): yield "" yield "}" +def headers(): + yield "#pragma once" + yield "" + yield "#include " + yield "" + def read_input(filename): with open(filename) as f: reader = csv.reader(f, delimiter=",", quotechar='"') - rows = [ + rows = [ [s.strip() for s in row] for row in reader ] @@ -139,5 +192,6 @@ if __name__ == "__main__": namespace = sys.argv[2] declarations = parse(rows) render, out = renderer() + render(headers()) render(render_declarations(namespace, declarations)) print(out.getvalue())