maple: add maple_host_bits

This commit is contained in:
Zack Buhman 2023-12-09 16:58:36 +08:00
parent 481a0cb0dc
commit ca77db1734
7 changed files with 94 additions and 35 deletions

View File

@ -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<uint32_t>(command_buf)));
maple_init_host_command(command_buf, receive_address);
maple_dma_start(command_buf);

View File

@ -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 <typename T>
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<maple_host_command<device_request::data_fields> *>(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<uint32_t>(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;

48
maple/maple_host_bits.h Normal file
View File

@ -0,0 +1,48 @@
#include <cstdint>
#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;
}
}

30
regs/maple_host_bits.csv Normal file
View File

@ -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",,
1 register_name enum_name bits bit_name value mask description
2 host_instruction 31 end_flag 1
3
4 host_instruction port_select 17-16 a 0
5 host_instruction port_select 17-16 b 1
6 host_instruction port_select 17-16 c 2
7 host_instruction port_select 17-16 d 3
8
9 host_instruction pattern 10-8 normal 0b000
10 host_instruction pattern 10-8 light_gun_mode 0b010
11 host_instruction pattern 10-8 reset 0b011
12 host_instruction pattern 10-8 return_from_light_gun_mode 0b100
13 host_instruction pattern 10-8 nop 0b111
14
15 host_instruction 7-0 transfer_length 0xff
16
17 ap port_select 7-6 a 0b00
18 ap port_select 7-6 b 0b01
19 ap port_select 7-6 c 0b10
20 ap port_select 7-6 d 0b11
21
22 ap de 5 device 1
23 ap de 5 expansion_device 0
24 ap de 5 port 0
25
26 ap lm_bus 4-0 _4 0b10000
27 ap lm_bus 4-0 _3 0b01000
28 ap lm_bus 4-0 _2 0b00100
29 ap lm_bus 4-0 _1 0b00010
30 ap lm_bus 4-0 _0 0b00001

BIN
regs/maple_host_bits.ods Normal file

Binary file not shown.