From 9bd79c6664505c23929211171056cb3fbcb3ec51 Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Fri, 15 Dec 2023 19:06:59 +0800 Subject: [PATCH] maple: remove cruft from maple_wink This also adds a new overload for align_32byte for integers. --- align.hpp | 7 ++++++- example/maple_controller.cpp | 4 ++-- example/maple_wink.cpp | 16 +++++++--------- maple/maple.cpp | 14 ++++++++------ maple/maple_bus_commands.hpp | 2 -- 5 files changed, 23 insertions(+), 20 deletions(-) diff --git a/align.hpp b/align.hpp index fae4dbe..6deb119 100644 --- a/align.hpp +++ b/align.hpp @@ -3,7 +3,12 @@ #include template -inline T * align_32byte(T * mem) +constexpr inline T * align_32byte(T * mem) { return reinterpret_cast((((reinterpret_cast(mem) + 31) & ~31))); } + +constexpr inline uint32_t align_32byte(uint32_t mem) +{ + return (mem + 31) & ~31; +} diff --git a/example/maple_controller.cpp b/example/maple_controller.cpp index 356f2f6..7af9004 100644 --- a/example/maple_controller.cpp +++ b/example/maple_controller.cpp @@ -7,8 +7,8 @@ constexpr uint32_t command_data_size = (sizeof (device_request::data_fields)); constexpr uint32_t response_data_size = (sizeof (device_status::data_fields)); -constexpr uint32_t host_command_size = ((sizeof (struct maple::host_command))); -constexpr uint32_t command_response_size = ((sizeof (struct maple::command_response)) + 31) & ~31; +constexpr uint32_t host_command_size = (sizeof (struct maple::host_command)); +constexpr uint32_t command_response_size = align_32byte((sizeof (struct maple::command_response))); uint32_t _command_buf[host_command_size * 4 + 32] = {0}; uint32_t _receive_buf[command_response_size * 4 + 32] = {0}; diff --git a/example/maple_wink.cpp b/example/maple_wink.cpp index 5d552d2..ee4f7d7 100644 --- a/example/maple_wink.cpp +++ b/example/maple_wink.cpp @@ -25,28 +25,26 @@ void make_wink(uint32_t * buf) } } +constexpr uint32_t width = 48; +constexpr uint32_t height = 32; +constexpr uint32_t pixels_per_byte = 8; +constexpr uint32_t wink_size = width * height / pixels_per_byte; + void main() { - constexpr int width = 48; - constexpr int height = 32; - constexpr int pixels_per_byte = 8; - - uint32_t __attribute__((aligned(4))) wink_buf[(width * height / pixels_per_byte + 32) / 4]; + uint32_t wink_buf[wink_size / 4]; make_wink(wink_buf); - if ((((uint32_t)wink_buf) & 3) != 0) serial::string("misaligned\n"); uint32_t _command_buf[(1024 + 32) / 4]; uint32_t _receive_buf[(1024 + 32) / 4]; uint32_t * command_buf = align_32byte(_command_buf); uint32_t * receive_buf = align_32byte(_receive_buf); - if ((((uint32_t)command_buf) & 31) != 0) serial::string("misaligned\n"); - if ((((uint32_t)receive_buf) & 31) != 0) serial::string("misaligned\n"); maple::init_block_write(command_buf, receive_buf, host_instruction::port_select::a, ap::de::expansion_device | ap::port_select::a | ap::lm_bus::_0, wink_buf, - 192); + wink_size); maple::dma_start(command_buf); for (int i = 0; i < 1; i++) { diff --git a/maple/maple.cpp b/maple/maple.cpp index 3ec466b..3e01ebd 100644 --- a/maple/maple.cpp +++ b/maple/maple.cpp @@ -1,10 +1,12 @@ #include #include -#include "../sh7091.hpp" -#include "../sh7091_bits.hpp" -#include "../systembus.hpp" -#include "../systembus_bits.hpp" +#include "align.hpp" + +#include "sh7091.hpp" +#include "sh7091_bits.hpp" +#include "systembus.hpp" +#include "systembus_bits.hpp" #include "maple_bits.hpp" #include "maple_bus_bits.hpp" @@ -38,8 +40,8 @@ void init_host_command(uint32_t * command_buf, uint32_t * receive_buf, void init_host_command_all_ports(uint32_t * buf, uint32_t * receive_buf, uint8_t command_code, uint32_t command_data_size, uint32_t response_data_size) { - const uint32_t command_size = (((sizeof (struct host_command)) + command_data_size)); - const uint32_t response_size = (((sizeof (struct command_response)) + response_data_size) + 31) & ~31; + const uint32_t command_size = ((sizeof (struct host_command)) + command_data_size); + const uint32_t response_size = align_32byte(((sizeof (struct command_response)) + response_data_size)); init_host_command(&buf[(command_size / 4) * 0], &receive_buf[(response_size / 4) * 0], host_instruction::port_select::a, // destination_port diff --git a/maple/maple_bus_commands.hpp b/maple/maple_bus_commands.hpp index 377646b..97a0977 100644 --- a/maple/maple_bus_commands.hpp +++ b/maple/maple_bus_commands.hpp @@ -128,8 +128,6 @@ namespace block_write { }; static_assert((sizeof (struct data_fields)) == 8); - static_assert((offsetof (struct data_fields, written_data)) == 8); - static_assert((offsetof (struct data_fields, written_data)) == 8); } namespace get_last_error {