diff --git a/common.mk b/common.mk index 1380afc..3145c60 100644 --- a/common.mk +++ b/common.mk @@ -2,7 +2,7 @@ MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) DIR := $(dir $(MAKEFILE_PATH)) LIB ?= . -OPT ?= -Os +OPT ?= -O3 DEBUG ?= -g -gdwarf-4 GENERATED ?= diff --git a/example/example.mk b/example/example.mk index 3c1655f..06a1b57 100644 --- a/example/example.mk +++ b/example/example.mk @@ -120,3 +120,10 @@ MAPLE_VIBRATOR_OBJ = \ example/maple_vibrator.elf: LDSCRIPT = $(LIB)/alt.lds example/maple_vibrator.elf: $(START_OBJ) $(MAPLE_VIBRATOR_OBJ) + +SERIAL_TRANSFER_OBJ = \ + example/serial_transfer.o \ + serial_load.o + +example/serial_transfer.elf: LDSCRIPT = $(LIB)/alt.lds +example/serial_transfer.elf: $(START_OBJ) $(SERIAL_TRANSFER_OBJ) diff --git a/example/macaw.cpp b/example/macaw.cpp index 3799fd4..95719a3 100644 --- a/example/macaw.cpp +++ b/example/macaw.cpp @@ -148,7 +148,6 @@ void main() core_start_render(frame_ix, num_frames); - v_sync_out(); v_sync_in(); core_wait_end_of_render_video(frame_ix, num_frames); diff --git a/example/macaw_cube.cpp b/example/macaw_cube.cpp index e67ddd0..c68f765 100644 --- a/example/macaw_cube.cpp +++ b/example/macaw_cube.cpp @@ -1,9 +1,8 @@ #include #include "align.hpp" -#include "vga.hpp" -#include "holly/texture_memory_alloc.hpp" +#include "vga.hpp" #include "holly.hpp" #include "holly/core.hpp" #include "holly/core_bits.hpp" @@ -12,6 +11,7 @@ #include "holly/ta_bits.hpp" #include "holly/region_array.hpp" #include "holly/background.hpp" +#include "holly/texture_memory_alloc.hpp" #include "memorymap.hpp" #include "serial.hpp" diff --git a/example/macaw_multipass.cpp b/example/macaw_multipass.cpp index 567cd82..2cb1c52 100644 --- a/example/macaw_multipass.cpp +++ b/example/macaw_multipass.cpp @@ -176,7 +176,6 @@ void main() core_start_render(frame_ix, num_frames); - v_sync_out(); v_sync_in(); core_wait_end_of_render_video(frame_ix, num_frames); diff --git a/example/maple_controller.cpp b/example/maple_controller.cpp index 33fe8bf..4688bfe 100644 --- a/example/maple_controller.cpp +++ b/example/maple_controller.cpp @@ -105,7 +105,6 @@ void main() vga(); while (1) { - v_sync_out(); v_sync_in(); do_device_request(); }; diff --git a/example/serial_transfer.cpp b/example/serial_transfer.cpp index f5e89f9..760d74d 100644 --- a/example/serial_transfer.cpp +++ b/example/serial_transfer.cpp @@ -4,14 +4,14 @@ #include "sh7091_bits.hpp" #include "cache.hpp" -#include "load.hpp" +#include "serial_load.hpp" extern uint32_t __bss_link_start __asm("__bss_link_start"); extern uint32_t __bss_link_end __asm("__bss_link_end"); void main() { - cache_init(); + cache::init(); uint32_t * start = &__bss_link_start; uint32_t * end = &__bss_link_end; diff --git a/example/sprite.cpp b/example/sprite.cpp index 0d92742..1f45781 100644 --- a/example/sprite.cpp +++ b/example/sprite.cpp @@ -6,8 +6,13 @@ #include "holly.hpp" #include "holly/core.hpp" #include "holly/core_bits.hpp" -#include "holly/ta_parameter.hpp" #include "holly/ta_fifo_polygon_converter.hpp" +#include "holly/ta_parameter.hpp" +#include "holly/ta_bits.hpp" +#include "holly/background.hpp" +#include "holly/region_array.hpp" +#include "holly/texture_memory_alloc.hpp" +#include "memorymap.hpp" struct vertex { float x; @@ -48,34 +53,65 @@ uint32_t transform(uint32_t * ta_parameter_buf) return parameter.offset; } +void init_texture_memory(const struct opb_size& opb_size) +{ + volatile texture_memory_alloc * mem = reinterpret_cast(texture_memory); + + background_parameter(mem->background); + + region_array2(mem->region_array, + (offsetof (struct texture_memory_alloc, object_list)), + 640 / 32, // width + 480 / 32, // height + opb_size + ); +} + uint32_t _ta_parameter_buf[((32 + 64 + 32) + 32) / 4]; void main() { vga(); + // The address of `ta_parameter_buf` must be a multiple of 32 bytes. + // This is mandatory for ch2-dma to the ta fifo polygon converter. + uint32_t * ta_parameter_buf = align_32byte(_ta_parameter_buf); + + constexpr uint32_t ta_alloc = ta_alloc_ctrl::pt_opb::no_list + | ta_alloc_ctrl::tm_opb::no_list + | ta_alloc_ctrl::t_opb::no_list + | ta_alloc_ctrl::om_opb::no_list + | ta_alloc_ctrl::o_opb::_16x4byte; + + constexpr struct opb_size opb_size = { .opaque = 16 * 4 + , .opaque_modifier = 0 + , .translucent = 0 + , .translucent_modifier = 0 + , .punch_through = 0 + }; + + constexpr uint32_t tiles = (640 / 32) * (320 / 32); + holly.SOFTRESET = softreset::pipeline_soft_reset | softreset::ta_soft_reset; holly.SOFTRESET = 0; core_init(); - core_init_texture_memory(); + init_texture_memory(opb_size); - // The address of `ta_parameter_buf` must be a multiple of 32 bytes. - // This is mandatory for ch2-dma to the ta fifo polygon converter. - uint32_t * ta_parameter_buf = align_32byte(_ta_parameter_buf); + uint32_t frame_ix = 0; + constexpr uint32_t num_frames = 1; while (true) { - v_sync_out(); - v_sync_in(); - - ta_polygon_converter_init(); + ta_polygon_converter_init(opb_size.total() * tiles, ta_alloc); uint32_t ta_parameter_size = transform(ta_parameter_buf); ta_polygon_converter_transfer(ta_parameter_buf, ta_parameter_size); ta_wait_opaque_list(); - constexpr int frame_ix = 0; - constexpr int num_frames = 0; core_start_render(frame_ix, num_frames); + + v_sync_in(); + core_wait_end_of_render_video(frame_ix, num_frames); + frame_ix += 1; } } diff --git a/example/translucency.cpp b/example/translucency.cpp index c543bea..2c67004 100644 --- a/example/translucency.cpp +++ b/example/translucency.cpp @@ -46,7 +46,18 @@ uint32_t transform(uint32_t * ta_parameter_buf, uint32_t texture_address = (offsetof (struct texture_memory_alloc, texture)); if (translucent) { // translucent untextured - parameter.append() = global_polygon_type_0(); + auto polygon = global_polygon_type_0(); + polygon.parameter_control_word = para_control::para_type::polygon_or_modifier_volume + | para_control::list_type::translucent + | obj_control::col_type::packed_color + | obj_control::gouraud; + + polygon.tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one + | tsp_instruction_word::dst_alpha_instr::src_alpha + | tsp_instruction_word::fog_control::no_fog + | tsp_instruction_word::use_alpha; + + parameter.append() = polygon; } else { // opaque textured parameter.append() = global_polygon_type_0(texture_address); @@ -100,7 +111,6 @@ uint32_t _ta_parameter_buf[((32 * (strip_length + 2)) * 2 + 32) / 4]; void main() { - vga(); auto src = reinterpret_cast(&_binary_macaw_data_start); @@ -154,7 +164,6 @@ void main() core_start_render(frame_ix, num_frames); - v_sync_out(); v_sync_in(); core_wait_end_of_render_video(frame_ix, num_frames); diff --git a/holly/ta_parameter.hpp b/holly/ta_parameter.hpp index beb33d9..be739ca 100644 --- a/holly/ta_parameter.hpp +++ b/holly/ta_parameter.hpp @@ -174,6 +174,7 @@ struct global_polygon_type_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::always diff --git a/load.cpp b/serial_load.cpp similarity index 100% rename from load.cpp rename to serial_load.cpp diff --git a/load.hpp b/serial_load.hpp similarity index 100% rename from load.hpp rename to serial_load.hpp