Compare commits

..

No commits in common. "31eb0df5085c63a9aadeaf6840137aa83ed83e50" and "511d99563d26ada77f38e55d552308d71986cd4b" have entirely different histories.

11 changed files with 118 additions and 160 deletions

View File

@ -29,8 +29,8 @@
#include "maple/maple_bus_commands.hpp"
#include "maple/maple_bus_ft0.hpp"
uint32_t _command_buf[(1024 + 32) / 4];
uint32_t _receive_buf[(1024 + 32) / 4];
uint32_t _command_buf[1024 / 4 + 32];
uint32_t _receive_buf[1024 / 4 + 32];
static ft0::data_transfer::data_format data[4];
@ -44,16 +44,14 @@ void do_get_condition(uint32_t * command_buf,
.function_type = std::byteswap(function_type::controller)
};
const uint32_t command_size = maple::init_host_command_all_ports<command_type, response_type>(command_buf, receive_buf,
const uint32_t size = maple::init_host_command_all_ports<command_type, response_type>(command_buf, receive_buf,
data_fields);
using host_response_type = struct maple::command_response<response_type::data_fields>;
auto host_response = reinterpret_cast<host_response_type *>(receive_buf);
maple::dma_start(command_buf, command_size,
receive_buf, maple::sizeof_command(host_response));
maple::dma_start(command_buf, size);
using command_response_type = struct maple::command_response<response_type::data_fields>;
for (uint8_t port = 0; port < 4; port++) {
auto& bus_data = host_response[port].bus_data;
auto response = reinterpret_cast<command_response_type *>(receive_buf);
auto& bus_data = response[port].bus_data;
if (bus_data.command_code != response_type::command_code) {
return;
}

View File

@ -30,10 +30,8 @@
#include "maple/maple_bus_commands.hpp"
#include "maple/maple_bus_ft0.hpp"
#include "sh7091/serial.hpp"
uint32_t _command_buf[(1024 + 32) / 4];
uint32_t _receive_buf[(1024 + 32) / 4];
uint32_t _command_buf[1024 / 4 + 32];
uint32_t _receive_buf[1024 / 4 + 32];
static ft0::data_transfer::data_format data[4];
@ -47,15 +45,14 @@ void do_get_condition(uint32_t * command_buf,
.function_type = std::byteswap(function_type::controller)
};
const uint32_t command_size = maple::init_host_command_all_ports<command_type, response_type>(command_buf, receive_buf,
const uint32_t size = maple::init_host_command_all_ports<command_type, response_type>(command_buf, receive_buf,
data_fields);
using host_response_type = struct maple::command_response<response_type::data_fields>;
auto host_response = reinterpret_cast<host_response_type *>(receive_buf);
maple::dma_start(command_buf, command_size,
receive_buf, maple::sizeof_command(host_response));
maple::dma_start(command_buf, size);
using command_response_type = struct maple::command_response<response_type::data_fields>;
for (uint8_t port = 0; port < 4; port++) {
auto& bus_data = host_response[port].bus_data;
auto response = reinterpret_cast<command_response_type *>(receive_buf);
auto& bus_data = response[port].bus_data;
if (bus_data.command_code != response_type::command_code) {
return;
}
@ -252,9 +249,6 @@ void main()
while (1) {
do_get_condition(command_buf, receive_buf);
if (frame_ix % 120 == 0) {
serial::integer(data[0].analog_axis_3);
}
ta_polygon_converter_init(opb_size.total(),
ta_alloc,

View File

@ -34,8 +34,8 @@
#include "twiddle.hpp"
#include "macaw.hpp"
uint32_t _command_buf[(1024 + 32) / 4];
uint32_t _receive_buf[(1024 + 32) / 4];
uint32_t _command_buf[1024 / 4 + 32];
uint32_t _receive_buf[1024 / 4 + 32];
static ft0::data_transfer::data_format data[4];
@ -49,12 +49,9 @@ void do_get_condition(uint32_t * command_buf,
.function_type = std::byteswap(function_type::controller)
};
const uint32_t command_size = maple::init_host_command_all_ports<command_type, response_type>(command_buf, receive_buf,
const uint32_t size = maple::init_host_command_all_ports<command_type, response_type>(command_buf, receive_buf,
data_fields);
using host_response_type = struct maple::command_response<response_type::data_fields>;
auto host_response = reinterpret_cast<host_response_type *>(receive_buf);
maple::dma_start(command_buf, command_size,
receive_buf, maple::sizeof_command(host_response));
maple::dma_start(command_buf, size);
using command_response_type = struct maple::command_response<response_type::data_fields>;
for (uint8_t port = 0; port < 4; port++) {

View File

@ -29,8 +29,8 @@
#include "maple/maple_bus_commands.hpp"
#include "maple/maple_bus_ft0.hpp"
uint32_t _command_buf[(1024 + 32) / 4];
uint32_t _receive_buf[(1024 + 32) / 4];
uint32_t _command_buf[1024 / 4 + 32];
uint32_t _receive_buf[1024 / 4 + 32];
static ft0::data_transfer::data_format data[4];
@ -44,16 +44,14 @@ void do_get_condition(uint32_t * command_buf,
.function_type = std::byteswap(function_type::controller)
};
const uint32_t command_size = maple::init_host_command_all_ports<command_type, response_type>(command_buf, receive_buf,
const uint32_t size = maple::init_host_command_all_ports<command_type, response_type>(command_buf, receive_buf,
data_fields);
using host_response_type = struct maple::command_response<response_type::data_fields>;
auto host_response = reinterpret_cast<host_response_type *>(receive_buf);
maple::dma_start(command_buf, command_size,
receive_buf, maple::sizeof_command(host_response));
maple::dma_start(command_buf, size);
using command_response_type = struct maple::command_response<response_type::data_fields>;
for (uint8_t port = 0; port < 4; port++) {
auto& bus_data = host_response[port].bus_data;
auto response = reinterpret_cast<command_response_type *>(receive_buf);
auto& bus_data = response[port].bus_data;
if (bus_data.command_code != response_type::command_code) {
return;
}

View File

@ -10,8 +10,8 @@
#include "maple/maple_bus_ft0.hpp"
#include "sh7091/serial.hpp"
uint32_t _command_buf[(1024 + 32) / 4];
uint32_t _receive_buf[(1024 + 32) / 4];
uint32_t _command_buf[1024 / 4 + 32] = {0};
uint32_t _receive_buf[1024 / 4 + 32] = {0};
static uint32_t * command_buf;
static uint32_t * receive_buf;
@ -42,19 +42,16 @@ void do_get_condition(uint32_t port)
return;
}
const uint32_t command_size = maple::init_get_condition(command_buf, receive_buf,
destination_port,
destination_ap,
std::byteswap(function_type::controller));
const uint32_t size = maple::init_get_condition(command_buf, receive_buf,
destination_port,
destination_ap,
std::byteswap(function_type::controller));
maple::dma_start(command_buf, size);
using response_type = data_transfer<ft0::data_transfer::data_format>;
using command_response_type = struct maple::command_response<response_type::data_fields>;
auto host_response = reinterpret_cast<command_response_type *>(receive_buf);
maple::dma_start(command_buf, command_size,
receive_buf, maple::sizeof_command(host_response));
auto& bus_data = host_response->bus_data;
auto response = reinterpret_cast<command_response_type *>(receive_buf);
auto& bus_data = response->bus_data;
if (bus_data.command_code != response_type::command_code) {
return;
}
@ -77,13 +74,11 @@ void do_device_request()
using command_type = device_request;
using response_type = device_status;
const uint32_t command_size = maple::init_host_command_all_ports<command_type, response_type>(command_buf, receive_buf);
using host_response_type = struct maple::command_response<response_type::data_fields>;
auto host_response = reinterpret_cast<host_response_type *>(receive_buf);
maple::dma_start(command_buf, command_size,
receive_buf, maple::sizeof_command(host_response));
const uint32_t size = maple::init_host_command_all_ports<command_type, response_type>(command_buf, receive_buf);
maple::dma_start(command_buf, size * 10);
using command_response_type = struct maple::command_response<response_type::data_fields>;
auto response = reinterpret_cast<command_response_type *>(receive_buf);
for (uint8_t port = 0; port < 4; port++) {
auto& bus_data = response[port].bus_data;
auto& data_fields = response[port].bus_data.data_fields;

View File

@ -5,8 +5,8 @@
#include "maple/maple_bus_commands.hpp"
#include "sh7091/serial.hpp"
uint32_t _command_buf[(1024 + 32) / 4];
uint32_t _receive_buf[(1024 + 32) / 4];
uint32_t _command_buf[1024 / 4 + 32] = {0};
uint32_t _receive_buf[1024 / 4 + 32] = {0};
void main()
{
@ -16,19 +16,16 @@ void main()
using command_type = device_request;
using response_type = device_status;
uint32_t command_size = maple::init_host_command_all_ports<command_type, response_type>(command_buf, receive_buf);
constexpr uint32_t host_response_size = (sizeof (maple::command_response<response_type::data_fields>));
maple::dma_start(command_buf, command_size,
receive_buf, host_response_size);
uint32_t size = maple::init_host_command_all_ports<command_type, response_type>(command_buf, receive_buf);
maple::dma_start(command_buf, size);
uint8_t * buf = reinterpret_cast<uint8_t *>(receive_buf);
for (uint8_t port = 0; port < 4; port++) {
serial::string("port ");
serial::integer<uint8_t>(port);
for (uint32_t i = 0; i < host_response_size; i++) {
constexpr uint32_t command_response_size = (sizeof (maple::command_response<response_type::data_fields>));
for (uint32_t i = 0; i < command_response_size; i++) {
serial::integer<uint8_t>(buf[port * command_response_size + i]);
}
serial::character('\n');

View File

@ -48,21 +48,28 @@ void do_lm_request(uint8_t port, uint8_t lm)
destination_ap, get_media_info::command_code, (sizeof (struct get_media_info::data_fields)),
true);
using host_command_type = struct maple::host_command<get_media_info::data_fields>;
auto host_command = reinterpret_cast<host_command_type *>(command_buf);
using command_type = struct maple::host_command<get_media_info::data_fields>;
auto host_command = reinterpret_cast<command_type *>(command_buf);
auto& fields = host_command->bus_data.data_fields;
fields.function_type = std::byteswap(function_type::vibration);
fields.pt = std::byteswap(1 << 24);
using response_type = data_transfer<ft8::data_transfer::data_format>;
using host_response_type = struct maple::command_response<response_type::data_fields>;
auto host_response = reinterpret_cast<host_response_type *>(receive_buf);
serial::string("dma start\n");
maple::dma_start(command_buf, maple::sizeof_command(host_command),
receive_buf, maple::sizeof_command(host_response));
const uint32_t size = (reinterpret_cast<uint32_t>(&host_command[1]) - reinterpret_cast<uint32_t>(&host_command[0]));
maple::dma_start(command_buf, size * 2);
auto& bus_data = host_response->bus_data;
using response_type = data_transfer<ft8::data_transfer::data_format>;
using command_response_type = struct maple::command_response<response_type::data_fields>;
for (uint32_t i = 0; i < (sizeof (command_response_type)) / 32; i++) {
asm volatile ("ocbp @%0"
: // output
: "r" (reinterpret_cast<uint32_t>(&receive_buf[(32 * i) / 4])) // input
);
}
auto response = reinterpret_cast<command_response_type *>(receive_buf);
auto& bus_data = response->bus_data;
if (bus_data.command_code != response_type::command_code) {
serial::string("lm did not reply to vibration get_media_info: ");
serial::integer<uint8_t>(lm);
@ -117,12 +124,18 @@ void do_lm_request(uint8_t port, uint8_t lm)
fields.write_in_data.freq = 0x27;
fields.write_in_data.inc = 0x00;
using host_response_type = struct maple::command_response<device_reply::data_fields>;
auto host_response = reinterpret_cast<host_response_type *>(receive_buf);
maple::dma_start(command_buf, maple::sizeof_command(host_command),
receive_buf, maple::sizeof_command(host_response));
const uint32_t size = (reinterpret_cast<uint32_t>(&host_command[1]) - reinterpret_cast<uint32_t>(&host_command[0]));
maple::dma_start(command_buf, size);
auto& bus_data = host_response->bus_data;
using command_response_type = struct maple::command_response<device_reply::data_fields>;
for (uint32_t i = 0; i < (sizeof (command_response_type)) / 32; i++) {
asm volatile ("ocbp @%0"
: // output
: "r" (reinterpret_cast<uint32_t>(&receive_buf[(32 * i) / 4])) // input
);
}
auto command_response = reinterpret_cast<command_response_type *>(receive_buf);
auto& bus_data = command_response->bus_data;
if (bus_data.command_code != device_reply::command_code) {
serial::string("lm did not reply to vibration set_condition: ");
@ -153,15 +166,21 @@ void do_device_request()
{
using command_type = device_request;
using response_type = device_status;
using host_response_type = struct maple::command_response<response_type::data_fields>;
auto host_response = reinterpret_cast<host_response_type *>(receive_buf);
const uint32_t command_size = maple::init_host_command_all_ports<command_type, response_type>(command_buf, receive_buf);
maple::dma_start(command_buf, command_size,
receive_buf, maple::sizeof_command(host_response));
const uint32_t size = maple::init_host_command_all_ports<command_type, response_type>(command_buf, receive_buf);
maple::dma_start(command_buf, size);
using command_response_type = struct maple::command_response<response_type::data_fields>;
for (uint32_t i = 0; i < ((sizeof (command_response_type)) * 4) / 32; i++) {
asm volatile ("ocbp @%0"
: // output
: "r" (reinterpret_cast<uint32_t>(&receive_buf[(32 * i) / 4])) // input
);
}
auto response = reinterpret_cast<command_response_type *>(receive_buf);
for (uint8_t port = 0; port < 4; port++) {
auto& bus_data = host_response[port].bus_data;
auto& data_fields = bus_data.data_fields;
auto& bus_data = response[port].bus_data;
auto& data_fields = response[port].bus_data.data_fields;
if (bus_data.command_code != device_status::command_code) {
// the controller is disconnected
} else {
@ -175,11 +194,11 @@ void do_device_request()
}
}
uint32_t _command_buf[(1024 + 32) / 4];
uint32_t _receive_buf[(1024 + 32) / 4];
void main()
{
uint32_t _command_buf[1024 / 4 + 32];
uint32_t _receive_buf[1024 / 4 + 32];
command_buf = align_32byte(_command_buf);
command_buf = reinterpret_cast<uint32_t *>(reinterpret_cast<uint32_t>(command_buf) | 0xa000'0000);
receive_buf = align_32byte(_receive_buf);

View File

@ -1,7 +1,6 @@
#include <cstdint>
#include "maple/maple.hpp"
#include "maple/maple_bus_commands.hpp"
#include "maple/maple_bus_bits.hpp"
#include "vga.hpp"
#include "align.hpp"
@ -31,32 +30,26 @@ constexpr uint32_t height = 32;
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];
make_wink(wink_buf);
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);
const uint32_t command_size = 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,
wink_size);
using response_type = device_reply;
using host_response_type = struct maple::command_response<response_type::data_fields>;
auto host_response = reinterpret_cast<host_response_type *>(receive_buf);
maple::dma_start(command_buf, command_size,
receive_buf, maple::sizeof_command(host_response));
const uint32_t size = 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,
wink_size);
maple::dma_start(command_buf, size);
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.source_ap);
serial::integer<uint8_t>(host_response->bus_data.data_size);
for (int i = 0; i < 1; i++) {
serial::integer<uint32_t>(receive_buf[i]);
}
vga();
v_sync_in();

View File

@ -45,16 +45,14 @@ void do_get_condition(uint32_t * command_buf,
.function_type = std::byteswap(function_type::controller)
};
const uint32_t command_size = maple::init_host_command_all_ports<command_type, response_type>(command_buf, receive_buf,
data_fields);
using host_response_type = struct maple::command_response<response_type::data_fields>;
auto host_response = reinterpret_cast<host_response_type *>(receive_buf);
maple::dma_start(command_buf, command_size,
receive_buf, maple::sizeof_command(host_response));
const uint32_t size = maple::init_host_command_all_ports<command_type, response_type>(command_buf, receive_buf,
data_fields);
maple::dma_start(command_buf, size);
using command_response_type = struct maple::command_response<response_type::data_fields>;
for (uint8_t port = 0; port < 4; port++) {
auto& bus_data = host_response[port].bus_data;
auto response = reinterpret_cast<command_response_type *>(receive_buf);
auto& bus_data = response[port].bus_data;
if (bus_data.command_code != response_type::command_code) {
return;
}
@ -343,8 +341,8 @@ void update_rot_pos(struct rot_pos& rot_pos)
}
uint32_t _ta_parameter_buf[((32 * 8192) + 32) / 4];
uint32_t _command_buf[(1024 + 32) / 4];
uint32_t _receive_buf[(1024 + 32) / 4];
uint32_t _command_buf[1024 / 4 + 32];
uint32_t _receive_buf[1024 / 4 + 32];
void main()
{

View File

@ -105,10 +105,17 @@ uint32_t init_block_write(uint32_t * command_buf, uint32_t * receive_buf,
+ data_size;
}
static inline void _dma_start(const uint32_t * command_buf)
void dma_start(const uint32_t * command_buf, const uint32_t size)
{
using namespace dmac;
for (uint32_t i = 0; i < align_32byte(size) / 32; i++) {
asm volatile ("ocbwb @%0"
: // output
: "r" (reinterpret_cast<uint32_t>(&command_buf[(32 * i) / 4])) // input
);
}
//command_buf = reinterpret_cast<uint32_t *>(reinterpret_cast<uint32_t>(command_buf) | 0xa000'0000);
sh7091.DMAC.DMAOR = dmaor::ddt::on_demand_data_transfer_mode /* on-demand data transfer mode */
@ -141,37 +148,6 @@ static inline void _dma_start(const uint32_t * command_buf)
maple_if.MDEN = mden::dma_enable::enable;
maple_if.MDST = mdst::start_status::start;
}
void dma_start(const uint32_t * command_buf,
const uint32_t command_size,
const uint32_t * receive_buf,
const uint32_t receive_size
)
{
// write back operand cache blocks for command buffer prior to starting DMA
for (uint32_t i = 0; i < align_32byte(command_size) / 32; i++) {
asm volatile ("ocbwb @%0"
: // output
: "r" (reinterpret_cast<uint32_t>(&command_buf[(32 * i) / 4])) // input
);
}
// start maple DMA
_dma_start(command_buf);
// purge operand cache block for receive buffer, prior to returning to the caller
for (uint32_t i = 0; i < align_32byte(receive_size) / 32; i++) {
asm volatile ("ocbp @%0"
: // output
: "r" (reinterpret_cast<uint32_t>(&receive_buf[(32 * i) / 4])) // input
);
}
// wait for maple DMA completion
while ((system.ISTNRM & ISTNRM__END_OF_DMA_MAPLE_DMA) == 0);
system.ISTNRM = ISTNRM__END_OF_DMA_MAPLE_DMA;
}
// wait for completion
//while (mdst::start_status::status(maple_if.MDST) != 0);
@ -187,5 +163,8 @@ void dma_start(const uint32_t * command_buf,
}
}
*/
while ((system.ISTNRM & ISTNRM__END_OF_DMA_MAPLE_DMA) == 0);
system.ISTNRM = ISTNRM__END_OF_DMA_MAPLE_DMA;
}
}

View File

@ -54,16 +54,6 @@ uint32_t init_block_write(uint32_t * buf, uint32_t * receive_buf,
uint32_t * data,
uint32_t data_size);
void dma_start(const uint32_t * command_buf,
const uint32_t command_size,
const uint32_t * receive_buf,
const uint32_t receive_size
);
template <typename T>
constexpr uint32_t sizeof_command(T * c)
{
return reinterpret_cast<uint32_t>(&c[1]) - reinterpret_cast<uint32_t>(&c[0]);
}
void dma_start(const uint32_t * command_buf, const uint32_t size);
}