diff --git a/main.cpp b/main.cpp index d3dd88e..7071c90 100644 --- a/main.cpp +++ b/main.cpp @@ -84,7 +84,6 @@ void maple_test() uint32_t * command_buf = align_32byte(_command_buf); uint32_t * receive_address = align_32byte(_receive_address); - serial_int(mdstar::table_address(reinterpret_cast(command_buf))); maple_init_host_command(command_buf, receive_address); maple_dma_start(command_buf); diff --git a/maple/maple.cpp b/maple/maple.cpp index 77fb592..022d732 100644 --- a/maple/maple.cpp +++ b/maple/maple.cpp @@ -7,55 +7,37 @@ #include "../systembus_bits.h" #include "maple_bits.h" +#include "maple_host_bits.h" #include "maple_bus_commands.h" #include "maple.h" -#define AP__PO__A (0b00 << 6) -#define AP__PO__B (0b01 << 6) -#define AP__PO__C (0b10 << 6) -#define AP__PO__D (0b11 << 6) - -#define AP__DE__DEVICE (1 << 5) -#define AP__DE__EXPANSION_DEVICE (0 << 5) -#define AP__DE__PORT (0 << 5) - -#define AP__LM(reg) ((reg) & 0b11111) - -// 2.6.8 "Peripheral Data Transfers" -// 5 "User Interface"; page 269 - -#define HOST_INSTRUCTION__END_FLAG (1 << 31) -#define HOST_INSTRUCTION__PORT_SELECT__A (0b00 << 16) -#define HOST_INSTRUCTION__PORT_SELECT__B (0b01 << 16) -#define HOST_INSTRUCTION__PORT_SELECT__C (0b10 << 16) -#define HOST_INSTRUCTION__PORT_SELECT__D (0b11 << 16) -#define HOST_INSTRUCTION__TRANSFER_LENGTH(n) (((n) & 0xff) << 0) - template struct maple_host_command { uint32_t host_instruction; uint32_t receive_data_storage_address; - uint8_t command_code; - uint8_t destination_ap; - uint8_t source_ap; - uint8_t data_size; - T data_fields; + struct bus_data { + uint8_t command_code; + uint8_t destination_ap; + uint8_t source_ap; + uint8_t data_size; + T data_fields; + } bus_data; }; void maple_init_host_command(uint32_t * buf, uint32_t * receive_address) { auto host_command = reinterpret_cast *>(buf); - host_command->host_instruction = HOST_INSTRUCTION__END_FLAG - | HOST_INSTRUCTION__PORT_SELECT__A - | HOST_INSTRUCTION__TRANSFER_LENGTH(0); // 4 bytes + host_command->host_instruction = host_instruction::end_flag + | host_instruction::port_select::a + | host_instruction::transfer_length(0); // 4 bytes host_command->receive_data_storage_address = reinterpret_cast(receive_address); - host_command->command_code = device_request::command_code; - host_command->destination_ap = AP__DE__DEVICE | AP__PO__A; - host_command->source_ap = AP__PO__A; - host_command->data_size = 0; + host_command->bus_data.command_code = device_request::command_code; + host_command->bus_data.destination_ap = ap::de::device | ap::port_select::a; + host_command->bus_data.source_ap = ap::port_select::a; + host_command->bus_data.data_size = 0; } void maple_dma_start(uint32_t * command_buf) @@ -76,7 +58,7 @@ void maple_dma_start(uint32_t * command_buf) // 20nsec * 0xc350 = 1ms constexpr uint32_t one_msec = 0xc350; maple_if.MSYS = msys::time_out_counter(one_msec) - | msys::sending_rate::_2M; + | msys::sending_rate::_2M; maple_if.MDTSEL = mdtsel::trigger_select::software_initiation; diff --git a/maple/maple_host_bits.h b/maple/maple_host_bits.h new file mode 100644 index 0000000..1949632 --- /dev/null +++ b/maple/maple_host_bits.h @@ -0,0 +1,48 @@ +#include + +#include "../float_uint32.h" + +namespace host_instruction { + constexpr uint32_t end_flag = 1 << 31; + + namespace port_select { + constexpr uint32_t a = 0 << 16; + constexpr uint32_t b = 1 << 16; + constexpr uint32_t c = 2 << 16; + constexpr uint32_t d = 3 << 16; + } + + namespace pattern { + constexpr uint32_t normal = 0b000 << 8; + constexpr uint32_t light_gun_mode = 0b010 << 8; + constexpr uint32_t reset = 0b011 << 8; + constexpr uint32_t return_from_light_gun_mode = 0b100 << 8; + constexpr uint32_t nop = 0b111 << 8; + } + + constexpr uint32_t transfer_length(uint32_t num) { return (num & 0xff) << 0; } +} + +namespace ap { + namespace port_select { + constexpr uint32_t a = 0b00 << 6; + constexpr uint32_t b = 0b01 << 6; + constexpr uint32_t c = 0b10 << 6; + constexpr uint32_t d = 0b11 << 6; + } + + namespace de { + constexpr uint32_t device = 1 << 5; + constexpr uint32_t expansion_device = 0 << 5; + constexpr uint32_t port = 0 << 5; + } + + namespace lm_bus { + constexpr uint32_t _4 = 0b10000 << 0; + constexpr uint32_t _3 = 0b01000 << 0; + constexpr uint32_t _2 = 0b00100 << 0; + constexpr uint32_t _1 = 0b00010 << 0; + constexpr uint32_t _0 = 0b00001 << 0; + } +} + diff --git a/regs/maple.csv b/regs/maple_bits.csv similarity index 100% rename from regs/maple.csv rename to regs/maple_bits.csv diff --git a/regs/maple.ods b/regs/maple_bits.ods similarity index 100% rename from regs/maple.ods rename to regs/maple_bits.ods diff --git a/regs/maple_host_bits.csv b/regs/maple_host_bits.csv new file mode 100644 index 0000000..febbbe6 --- /dev/null +++ b/regs/maple_host_bits.csv @@ -0,0 +1,30 @@ +"register_name","enum_name","bits","bit_name","value","mask","description" +"host_instruction",,31,"end_flag",1,, +,,,,,, +"host_instruction","port_select","17-16","a",0,, +"host_instruction","port_select","17-16","b",1,, +"host_instruction","port_select","17-16","c",2,, +"host_instruction","port_select","17-16","d",3,, +,,,,,, +"host_instruction","pattern","10-8","normal","0b000",, +"host_instruction","pattern","10-8","light_gun_mode","0b010",, +"host_instruction","pattern","10-8","reset","0b011",, +"host_instruction","pattern","10-8","return_from_light_gun_mode","0b100",, +"host_instruction","pattern","10-8","nop","0b111",, +,,,,,, +"host_instruction",,"7-0","transfer_length",,"0xff", +,,,,,, +"ap","port_select","7-6","a","0b00",, +"ap","port_select","7-6","b","0b01",, +"ap","port_select","7-6","c","0b10",, +"ap","port_select","7-6","d","0b11",, +,,,,,, +"ap","de",5,"device",1,, +"ap","de",5,"expansion_device",0,, +"ap","de",5,"port",0,, +,,,,,, +"ap","lm_bus","4-0","_4","0b10000",, +"ap","lm_bus","4-0","_3","0b01000",, +"ap","lm_bus","4-0","_2","0b00100",, +"ap","lm_bus","4-0","_1","0b00010",, +"ap","lm_bus","4-0","_0","0b00001",, diff --git a/regs/maple_host_bits.ods b/regs/maple_host_bits.ods new file mode 100644 index 0000000..f06e279 Binary files /dev/null and b/regs/maple_host_bits.ods differ