Compare commits

...

3 Commits

Author SHA1 Message Date
7e535e8038 common: quote the include path 2024-10-17 22:49:39 -05:00
e1e63795c9 example: unrot wiffle_attenuation 2024-10-17 22:46:11 -05:00
12bf231293 example/maple_*: update examples 2024-10-17 22:45:22 -05:00
9 changed files with 214 additions and 55 deletions

View File

@ -2,14 +2,14 @@ MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
DIR := $(dir $(MAKEFILE_PATH)) DIR := $(dir $(MAKEFILE_PATH))
LIB ?= . LIB ?= .
OPT ?= -O3 OPT ?= -O2
GENERATED ?= GENERATED ?=
AARCH = --isa=sh4 --little AARCH = --isa=sh4 --little
CARCH = -m4-single-only -ml CARCH = -m4-single-only -ml
CFLAGS += -mfsca -funsafe-math-optimizations -ffast-math CFLAGS += -mfsca -funsafe-math-optimizations -ffast-math
CFLAGS += -I$(dir $(MAKEFILE_PATH)) CFLAGS += -I"$(dir $(MAKEFILE_PATH))"
CXXFLAGS += -std=c++23 CXXFLAGS += -std=c++23

View File

@ -1,37 +1,49 @@
#include "align.hpp" #include <bit>
#include "maple/maple.hpp" #include "maple/maple.hpp"
#include "maple/maple_impl.hpp" #include "maple/maple_host_command_writer.hpp"
#include "maple/maple_bus_commands.hpp" #include "maple/maple_bus_commands.hpp"
#include "sh7091/serial.hpp" #include "sh7091/serial.hpp"
uint32_t _command_buf[(1024 + 32) / 4];
uint32_t _receive_buf[(1024 + 32) / 4];
void main() void main()
{ {
uint32_t * command_buf = align_32byte(_command_buf); serial::init(4);
uint32_t * receive_buf = align_32byte(_receive_buf);
using command_type = device_request; uint32_t send_buf[1024] __attribute__((aligned(32)));
using response_type = device_status; uint32_t recv_buf[1024] __attribute__((aligned(32)));
uint32_t command_size = maple::init_host_command_all_ports<command_type, response_type>(command_buf, receive_buf); using command_type = maple::device_request;
using response_type = maple::device_status;
constexpr uint32_t host_response_size = (sizeof (maple::host_response<response_type::data_fields>)); auto writer = maple::host_command_writer(send_buf, recv_buf);
maple::dma_start(command_buf, command_size, auto [host_command, host_response]
receive_buf, host_response_size); = writer.append_command_all_ports<command_type, response_type>();
maple::dma_start(send_buf, writer.send_offset,
recv_buf, writer.recv_offset);
uint8_t * buf = reinterpret_cast<uint8_t *>(receive_buf);
for (uint8_t port = 0; port < 4; port++) { for (uint8_t port = 0; port < 4; port++) {
serial::string("port "); auto& bus_data = host_response[port].bus_data;
serial::integer<uint8_t>(port); auto& data_fields = bus_data.data_fields;
if (bus_data.command_code != response_type::command_code) {
for (uint32_t i = 0; i < host_response_size; i++) { serial::string("port: ");
serial::integer<uint8_t>(buf[port * host_response_size + i]); serial::integer<uint8_t>(port);
serial::string(" disconnected\n");
} else {
serial::string("port: ");
serial::integer<uint8_t>(port);
serial::string(" ft: ");
serial::integer<uint32_t>(std::byteswap(data_fields.device_id.ft));
serial::string(" fd[0]: ");
serial::integer<uint32_t>(std::byteswap(data_fields.device_id.fd[0]));
serial::string(" fd[1]: ");
serial::integer<uint32_t>(std::byteswap(data_fields.device_id.fd[1]));
serial::string(" fd[2]: ");
serial::integer<uint32_t>(std::byteswap(data_fields.device_id.fd[2]));
serial::string(" source_ap.lm_bus: ");
serial::integer<uint8_t>(bus_data.source_ap & ap::lm_bus::bit_mask);
} }
serial::character('\n');
} }
while (1); while (1);

View File

@ -310,11 +310,16 @@ void do_lm_request(uint8_t port, uint8_t lm)
destination_ap, destination_ap,
true); // end_flag true); // end_flag
serial::string("lm command send_offset ");
serial::integer<uint32_t>(writer.send_offset);
serial::hexlify(send_buf, writer.send_offset);
maple::dma_start(send_buf, writer.send_offset, maple::dma_start(send_buf, writer.send_offset,
recv_buf, writer.recv_offset); recv_buf, writer.recv_offset);
auto& bus_data = host_response->bus_data; auto& bus_data = host_response->bus_data;
auto& data_fields = bus_data.data_fields; auto& data_fields = bus_data.data_fields;
serial::hexlify(recv_buf, writer.recv_offset);
if (bus_data.command_code != response_type::command_code) { if (bus_data.command_code != response_type::command_code) {
serial::string("lm did not reply: "); serial::string("lm did not reply: ");
serial::integer<uint8_t>(port, ' '); serial::integer<uint8_t>(port, ' ');
@ -581,9 +586,9 @@ void do_device_request()
void main() void main()
{ {
// flycast needs this in HLE mode, or else it won't start the vcount serial::init(4);
// counter.
video_output::set_mode_vga();
do_device_request(); do_device_request();
while (1);
} }

View File

@ -1,12 +1,23 @@
#include <cstdint> #include <cstdint>
#include <bit>
#include "maple/maple.hpp" #include "maple/maple.hpp"
#include "maple/maple_bus_commands.hpp" #include "maple/maple_bus_commands.hpp"
#include "maple/maple_bus_bits.hpp" #include "maple/maple_bus_bits.hpp"
#include "maple/maple_host_command_writer.hpp"
#include "maple/maple_port.hpp"
#include "align.hpp" #include "align.hpp"
#include "sh7091/serial.hpp" #include "sh7091/serial.hpp"
#include "holly/video_output.hpp"
extern uint32_t _binary_wink_data_start __asm("_binary_wink_data_start"); extern uint32_t _binary_wink_data_start __asm("_binary_wink_data_start");
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;
uint32_t wink_buf[wink_size / 4];
void make_wink(uint32_t * buf) void make_wink(uint32_t * buf)
{ {
@ -25,35 +36,165 @@ void make_wink(uint32_t * buf)
} }
} }
constexpr uint32_t width = 48; template <typename T>
constexpr uint32_t height = 32; inline void copy(T * dst, const T * src, const int32_t n) noexcept
constexpr uint32_t pixels_per_byte = 8;
constexpr uint32_t wink_size = width * height / pixels_per_byte;
uint32_t _command_buf[(1024 + 32) / 4];
uint32_t _receive_buf[(1024 + 32) / 4];
void main()
{ {
uint32_t wink_buf[wink_size / 4]; int32_t n_t = n / (sizeof (T));
make_wink(wink_buf); while (n_t > 0) {
*dst++ = *src++;
n_t--;
}
}
uint32_t * command_buf = align_32byte(_command_buf); void send_wink(uint8_t port, uint8_t lm)
uint32_t * receive_buf = align_32byte(_receive_buf); {
uint32_t send_buf[1024] __attribute__((aligned(32)));
uint32_t recv_buf[1024] __attribute__((aligned(32)));
const uint32_t command_size = maple::init_block_write(command_buf, receive_buf, using command_type = maple::block_write<uint8_t[0]>;
host_instruction::port_select::b, using response_type = maple::device_reply;
ap::de::expansion_device | ap::port_select::b | ap::lm_bus::_0,
wink_buf, auto writer = maple::host_command_writer(send_buf, recv_buf);
wink_size);
using response_type = device_reply; uint32_t host_port_select = host_instruction_port_select(port);
using host_response_type = struct maple::host_response<response_type::data_fields>; uint32_t destination_ap = ap_port_select(port) | ap::de::expansion_device | lm;
auto host_response = reinterpret_cast<host_response_type *>(receive_buf);
maple::dma_start(command_buf, command_size, auto [host_command, host_response]
receive_buf, maple::sizeof_command(host_response)); = writer.append_command<command_type, response_type>(host_port_select,
destination_ap,
true, // end_flag
wink_size, // send_trailing
0 // recv_trailing
);
auto& data_fields = host_command->bus_data.data_fields;
data_fields.function_type = std::byteswap(function_type::bw_lcd);
data_fields.pt = 0;
data_fields.phase = 0;
data_fields.block_number = std::byteswap<uint16_t>(0x0000);
copy<uint8_t>(data_fields.written_data, reinterpret_cast<uint8_t *>(wink_buf), wink_size);
maple::dma_start(send_buf, writer.send_offset,
recv_buf, writer.recv_offset);
serial::integer<uint8_t>(host_response->bus_data.command_code); serial::integer<uint8_t>(host_response->bus_data.command_code);
serial::integer<uint8_t>(host_response->bus_data.destination_ap); serial::integer<uint8_t>(host_response->bus_data.destination_ap);
serial::integer<uint8_t>(host_response->bus_data.source_ap); serial::integer<uint8_t>(host_response->bus_data.source_ap);
serial::integer<uint8_t>(host_response->bus_data.data_size); serial::integer<uint8_t>(host_response->bus_data.data_size);
} }
void do_lm_request(uint8_t port, uint8_t lm)
{
uint32_t send_buf[1024] __attribute__((aligned(32)));
uint32_t recv_buf[1024] __attribute__((aligned(32)));
auto writer = maple::host_command_writer(send_buf, recv_buf);
uint32_t host_port_select = host_instruction_port_select(port);
uint32_t destination_ap = ap_port_select(port) | ap::de::expansion_device | lm;
using command_type = maple::device_request;
using response_type = maple::device_status;
auto [host_command, host_response]
= writer.append_command<command_type, response_type>(host_port_select,
destination_ap,
true); // end_flag
maple::dma_start(send_buf, writer.send_offset,
recv_buf, writer.recv_offset);
auto& bus_data = host_response->bus_data;
auto& data_fields = bus_data.data_fields;
if (bus_data.command_code != maple::device_status::command_code) {
serial::string("lm did not reply: ");
serial::integer<uint8_t>(port, ' ');
serial::integer<uint8_t>(lm);
} else {
serial::string(" lm: ");
serial::integer<uint8_t>(lm);
serial::string(" ft: ");
serial::integer<uint32_t>(std::byteswap(data_fields.device_id.ft));
serial::string(" fd[0]: ");
serial::integer<uint32_t>(std::byteswap(data_fields.device_id.fd[0]));
serial::string(" fd[1]: ");
serial::integer<uint32_t>(std::byteswap(data_fields.device_id.fd[1]));
serial::string(" fd[2]: ");
serial::integer<uint32_t>(std::byteswap(data_fields.device_id.fd[2]));
serial::string(" source_ap.lm_bus: ");
serial::integer<uint8_t>(bus_data.source_ap & ap::lm_bus::bit_mask);
if (std::byteswap(data_fields.device_id.ft) & function_type::bw_lcd) {
serial::string("send wink\n");
send_wink(port, lm);
}
}
}
void do_lm_requests(uint8_t port, uint8_t lm)
{
if (lm & ap::lm_bus::_0)
do_lm_request(port, lm & ap::lm_bus::_0);
if (lm & ap::lm_bus::_1)
do_lm_request(port, lm & ap::lm_bus::_1);
if (lm & ap::lm_bus::_2)
do_lm_request(port, lm & ap::lm_bus::_2);
if (lm & ap::lm_bus::_3)
do_lm_request(port, lm & ap::lm_bus::_3);
if (lm & ap::lm_bus::_4)
do_lm_request(port, lm & ap::lm_bus::_4);
}
void do_device_request()
{
uint32_t send_buf[1024] __attribute__((aligned(32)));
uint32_t recv_buf[1024] __attribute__((aligned(32)));
auto writer = maple::host_command_writer(send_buf, recv_buf);
using command_type = maple::device_request;
using response_type = maple::device_status;
auto [host_command, host_response]
= writer.append_command_all_ports<command_type, response_type>();
maple::dma_start(send_buf, writer.send_offset,
recv_buf, writer.recv_offset);
for (uint8_t port = 0; port < 4; port++) {
auto& bus_data = host_response[port].bus_data;
auto& data_fields = bus_data.data_fields;
if (bus_data.command_code != response_type::command_code) {
serial::string("port: ");
serial::integer<uint8_t>(port);
serial::string(" disconnected\n");
} else {
serial::string("port: ");
serial::integer<uint8_t>(port);
serial::string(" ft: ");
serial::integer<uint32_t>(std::byteswap(data_fields.device_id.ft));
serial::string(" fd[0]: ");
serial::integer<uint32_t>(std::byteswap(data_fields.device_id.fd[0]));
serial::string(" fd[1]: ");
serial::integer<uint32_t>(std::byteswap(data_fields.device_id.fd[1]));
serial::string(" fd[2]: ");
serial::integer<uint32_t>(std::byteswap(data_fields.device_id.fd[2]));
serial::string(" source_ap.lm_bus: ");
serial::integer<uint8_t>(bus_data.source_ap & ap::lm_bus::bit_mask);
do_lm_requests(port,
bus_data.source_ap & ap::lm_bus::bit_mask);
}
}
}
void main()
{
serial::init(4);
make_wink(wink_buf);
do_device_request();
while (1);
}

View File

@ -70,7 +70,7 @@ uint32_t transform(uint32_t * ta_parameter_buf)
quad_vertices[2].z, quad_vertices[2].z,
quad_vertices[3].x, quad_vertices[3].x,
quad_vertices[3].y); quad_vertices[3].y);
// curiously, there is no quad_veritices[3].z in vertex_sprite_type_0 // curiously, there is no quad_vertices[3].z in vertex_sprite_type_0
parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list); parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);

View File

@ -101,7 +101,7 @@ uint32_t transform(uint32_t * ta_parameter_buf,
b.x, b.y, b.z, b.x, b.y, b.z,
c.x, c.y, c.z, c.x, c.y, c.z,
d.x, d.y); d.x, d.y);
// curiously, there is no quad_veritices[3].z in vertex_sprite_type_0 // curiously, there is no quad_vertices[3].z in vertex_sprite_type_0
parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list); parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);

View File

@ -91,7 +91,7 @@ void transform(ta_parameter_writer& parameter,
auto l = lights[0] - point; auto l = lights[0] - point;
auto n_dot_l = dot(n, l); auto n_dot_l = dot(n, l);
if (n_dot_l > 0) { if (n_dot_l > 0) {
float distance = length(lights[0] - point); float distance = magnitude(lights[0] - point);
float attenuation = 1.0 / (1.0f float attenuation = 1.0 / (1.0f
+ 0.07f * distance + 0.07f * distance
+ 0.007f * (distance * distance)); + 0.007f * (distance * distance));
@ -103,7 +103,7 @@ void transform(ta_parameter_writer& parameter,
auto l = lights[1] - point; auto l = lights[1] - point;
auto n_dot_l = dot(n, l); auto n_dot_l = dot(n, l);
if (n_dot_l > 0) { if (n_dot_l > 0) {
float distance = length(lights[1] - point); float distance = magnitude(lights[1] - point);
float attenuation = 1.0 / (1.0f float attenuation = 1.0 / (1.0f
+ 0.07f * distance + 0.07f * distance
+ 0.007f * (distance * distance)); + 0.007f * (distance * distance));
@ -115,7 +115,7 @@ void transform(ta_parameter_writer& parameter,
auto l = lights[2] - point; auto l = lights[2] - point;
auto n_dot_l = dot(n, l); auto n_dot_l = dot(n, l);
if (n_dot_l > 0) { if (n_dot_l > 0) {
float distance = length(lights[2] - point); float distance = magnitude(lights[2] - point);
float attenuation = 1.0 / (1.0f float attenuation = 1.0 / (1.0f
+ 0.07f * distance + 0.07f * distance
+ 0.007f * (distance * distance)); + 0.007f * (distance * distance));

View File

@ -14,7 +14,8 @@
void core_init() void core_init()
{ {
holly.ISP_FEED_CFG = isp_feed_cfg::cache_size_for_translucency(0x200) holly.ISP_FEED_CFG = isp_feed_cfg::cache_size_for_translucency(0x200)
| isp_feed_cfg::punch_through_chunk_size(0x040); | isp_feed_cfg::punch_through_chunk_size(0x040)
;
holly.FPU_SHAD_SCALE = fpu_shad_scale::simple_shadow_enable::intensity_volume_mode holly.FPU_SHAD_SCALE = fpu_shad_scale::simple_shadow_enable::intensity_volume_mode
| fpu_shad_scale::scale_factor_for_shadows(127); | fpu_shad_scale::scale_factor_for_shadows(127);

View File

@ -142,7 +142,7 @@ void ta_wait_opaque_list()
{ {
while ((system.ISTNRM & istnrm::end_of_transferring_opaque_list) == 0) { while ((system.ISTNRM & istnrm::end_of_transferring_opaque_list) == 0) {
if (system.ISTERR) { if (system.ISTERR) {
serial::string("ta "); serial::string("ta ISTERR: ");
serial::integer<uint32_t>(system.ISTERR); serial::integer<uint32_t>(system.ISTERR);
} }
}; };