endianness fix + joybus stop bit

This commit is contained in:
Polprzewodnikowy 2021-09-18 15:58:16 +02:00
parent ea42b286af
commit 281137f9f1
5 changed files with 37 additions and 37 deletions

View File

@ -57,7 +57,7 @@ module cpu_flashram (
flashram.operation_pending
};
if (bus.address[7]) begin
bus.rdata = flashram.rdata;
bus.rdata = {flashram.rdata[7:0], flashram.rdata[15:8], flashram.rdata[23:16], flashram.rdata[31:24]};
end
end

View File

@ -41,12 +41,12 @@ module cpu_sdram (
always_comb begin
bus.rdata = 32'd0;
if (bus.ack) begin
bus.rdata = rdata;
bus.rdata = {rdata[7:0], rdata[15:8], rdata[23:16], rdata[31:24]};
end
sdram.write = current_word ? &bus.wmask[1:0] : &bus.wmask[3:2];
sdram.address = {1'b0, bus.address[30:2], current_word, 1'b0};
sdram.wdata = current_word ? bus.wdata[15:0] : bus.wdata[31:16];
sdram.wdata = current_word ? {bus.wdata[23:16], bus.wdata[31:24]} : {bus.wdata[7:0], bus.wdata[15:8]};
end
always_ff @(posedge sys.clk) begin

View File

@ -201,14 +201,16 @@ module n64_si (
tx_sub_bit_counter <= tx_sub_bit_counter + 1'd1;
if (tx_sub_bit_counter == 3'd7) begin
tx_shift <= 1'b1;
if (tx_bit_counter > 7'd1) begin
if (tx_bit_counter >= 7'd1) begin
tx_bit_counter <= tx_bit_counter - 1'd1;
end else begin
tx_state <= S_TX_IDLE;
si.tx_busy <= 1'b0;
end
end
if (trx_data[80]) begin
if (tx_bit_counter == 7'd0) begin
si_dq_output_enable_data <= tx_sub_bit_counter < 3'd4;
end else if (trx_data[80]) begin
si_dq_output_enable_data <= tx_sub_bit_counter < 3'd2;
end else begin
si_dq_output_enable_data <= tx_sub_bit_counter < 3'd6;

2
sw/pc/.gitignore vendored
View File

@ -5,3 +5,5 @@
*.n64
*.z64
*.v64
*.data
*.bak

View File

@ -19,33 +19,29 @@
#define RTC_STATUS_RUNNING (0x00)
#define RTC_STATUS(running) (running ? RTC_STATUS_RUNNING : RTC_STATUS_STOPPED)
#define RTC_WP_MASK (0x03)
#define RTC_ST_MASK (0x04)
#define RTC_BLOCK_CFG (0)
#define RTC_BLOCK_BACKUP (1)
#define RTC_BLOCK_TIME (2)
#define RTC_WP_BACKUP (1 << 0)
#define RTC_WP_TIME (1 << 1)
#define RTC_WP_MASK (RTC_WP_TIME | RTC_WP_BACKUP)
#define RTC_ST (1 << 2)
#define RTC_CENTURY_20XX (0x01)
static void rx (uint8_t *data) {
static void joybus_rx (uint8_t *data) {
uint32_t rx_length = (JOYBUS->SCR & JOYBUS_SCR_RX_LENGTH_MASK) >> JOYBUS_SCR_RX_LENGTH_BIT;
for (size_t i = 0; i < rx_length; i++) {
data[i] = ((uint8_t *) JOYBUS->DATA)[(10 - rx_length) + i];
}
}
static void tx (uint8_t *data, size_t length) {
static void joybus_tx (uint8_t *data, size_t length) {
for (size_t i = 0; i < ((length + 3) / 4); i++) {
JOYBUS->DATA[i] = ((uint32_t *) data)[i];
}
JOYBUS->DATA[length / 4] |= (0x80 << ((length % 4) * 8));
JOYBUS->SCR = (((length * 8) + 1) << JOYBUS_SCR_TX_LENGTH_BIT) | JOYBUS_SCR_TX_START;
}
static uint32_t swapb (uint32_t data) {
return (
(data << 24) |
((data << 8) & 0x00FF0000) |
((data >> 8) & 0x0000FF00) |
(data >> 24)
);
JOYBUS->SCR = ((length * 8) << JOYBUS_SCR_TX_LENGTH_BIT) | JOYBUS_SCR_TX_START;
}
@ -79,7 +75,7 @@ void process_joybus (void) {
if (JOYBUS->SCR & JOYBUS_SCR_RX_READY) {
if (JOYBUS->SCR & JOYBUS_SCR_RX_STOP_BIT) {
rx(rx_data);
joybus_rx(rx_data);
for (size_t i = 0; i < sizeof(tx_data); i++) {
tx_data[i] = 0x00;
@ -90,21 +86,21 @@ void process_joybus (void) {
switch (rx_data[0]) {
case CMD_EEPROM_STATUS:
tx_data[1] = p.eeprom_type == EEPROM_16K ? EEPROM_ID_16K : EEPROM_ID_4K;
tx(tx_data, 3);
joybus_tx(tx_data, 3);
break;
case CMD_EEPROM_READ:
data_offset = (uint32_t *) (&tx_data[0]);
data_offset[0] = swapb(save_data[0]);
data_offset[1] = swapb(save_data[1]);
tx(tx_data, 8);
data_offset[0] = save_data[0];
data_offset[1] = save_data[1];
joybus_tx(tx_data, 8);
break;
case CMD_EEPROM_WRITE:
data_offset = (uint32_t *) (&rx_data[2]);
save_data[0] = swapb(data_offset[0]);
save_data[1] = swapb(data_offset[1]);
tx(tx_data, 1);
save_data[0] = data_offset[0];
save_data[1] = data_offset[1];
joybus_tx(tx_data, 1);
break;
}
}
@ -113,16 +109,16 @@ void process_joybus (void) {
case CMD_RTC_STATUS:
tx_data[1] = RTC_ID;
tx_data[2] = RTC_STATUS(p.rtc_running);
tx(tx_data, 3);
joybus_tx(tx_data, 3);
break;
case CMD_RTC_READ:
if (rx_data[1] == 0) {
if (rx_data[1] == RTC_BLOCK_CFG) {
tx_data[0] = p.rtc_write_protect;
if (!p.rtc_running) {
tx_data[1] = RTC_ST_MASK;
tx_data[1] = RTC_ST;
}
} else if (rx_data[1] == 2) {
} else if (rx_data[1] == RTC_BLOCK_TIME) {
rtc_time_t *rtc_time = rtc_get_time();
tx_data[0] = rtc_time->seconds;
tx_data[1] = rtc_time->minutes;
@ -134,14 +130,14 @@ void process_joybus (void) {
tx_data[7] = RTC_CENTURY_20XX;
}
tx_data[8] = RTC_STATUS(p.rtc_running);
tx(tx_data, 9);
joybus_tx(tx_data, 9);
break;
case CMD_RTC_WRITE:
if (rx_data[1] == 0) {
if (rx_data[1] == RTC_BLOCK_CFG) {
p.rtc_write_protect = rx_data[2] & RTC_WP_MASK;
p.rtc_running = (!(rx_data[3] & RTC_ST_MASK));
} else if (rx_data[1] == 2) {
p.rtc_running = (!(rx_data[3] & RTC_ST));
} else if (rx_data[1] == RTC_BLOCK_TIME && (!(p.rtc_write_protect & RTC_WP_TIME))) {
rtc_time_t rtc_time;
rtc_time.seconds = rx_data[2];
rtc_time.minutes = rx_data[3];
@ -153,7 +149,7 @@ void process_joybus (void) {
rtc_set_time(&rtc_time);
}
tx_data[0] = RTC_STATUS(p.rtc_running);
tx(tx_data, 1);
joybus_tx(tx_data, 1);
break;
}
}