2016-01-27 09:11:59 +00:00
|
|
|
#include <stdio.h>
|
2016-02-13 20:01:41 +00:00
|
|
|
#include <string.h>
|
2021-04-12 06:34:26 +00:00
|
|
|
#include <stdint.h>
|
2016-02-13 19:33:16 +00:00
|
|
|
|
2016-02-11 08:04:45 +00:00
|
|
|
#include "Rsp.h"
|
2016-01-27 09:11:59 +00:00
|
|
|
#include "RSP Registers.h"
|
|
|
|
#include "memory.h"
|
|
|
|
|
2021-03-19 05:39:54 +00:00
|
|
|
// #define RSP_SAFE_DMA // Unoptimized DMA transfers
|
2016-01-27 09:11:59 +00:00
|
|
|
|
|
|
|
void SP_DMA_READ (void)
|
|
|
|
{
|
2016-02-13 19:33:16 +00:00
|
|
|
uint32_t i, j, Length, Skip, Count, End, addr;
|
|
|
|
uint8_t *Dest, *Source;
|
2016-01-27 09:11:59 +00:00
|
|
|
|
|
|
|
addr = (*RSPInfo.SP_DRAM_ADDR_REG) & 0x00FFFFFF;
|
|
|
|
|
|
|
|
if (addr > 0x7FFFFF)
|
|
|
|
{
|
2021-03-19 05:39:54 +00:00
|
|
|
DisplayError("SP DMA READ\nSP_DRAM_ADDR_REG not in RDRAM space");
|
2016-01-27 09:11:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*RSPInfo.SP_RD_LEN_REG & 0xFFF) + 1 + (*RSPInfo.SP_MEM_ADDR_REG & 0xFFF) > 0x1000)
|
|
|
|
{
|
2021-03-19 05:39:54 +00:00
|
|
|
DisplayError("SP DMA READ\nCould not fit copy in memory segment");
|
2016-01-27 09:11:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Length = ((*RSPInfo.SP_RD_LEN_REG & 0xFFF) | 7) + 1;
|
|
|
|
Skip = (*RSPInfo.SP_RD_LEN_REG >> 20) + Length;
|
|
|
|
Count = ((*RSPInfo.SP_RD_LEN_REG >> 12) & 0xFF) + 1;
|
|
|
|
End = ((*RSPInfo.SP_MEM_ADDR_REG & 0x0FFF) & ~7) + (((Count - 1) * Skip) + Length);
|
|
|
|
|
|
|
|
if ((*RSPInfo.SP_MEM_ADDR_REG & 0x1000) != 0)
|
|
|
|
{
|
|
|
|
Dest = RSPInfo.IMEM + ((*RSPInfo.SP_MEM_ADDR_REG & 0x0FFF) & ~7);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Dest = RSPInfo.DMEM + ((*RSPInfo.SP_MEM_ADDR_REG & 0x0FFF) & ~7);
|
|
|
|
}
|
|
|
|
Source = RSPInfo.RDRAM + (addr & ~7);
|
|
|
|
|
|
|
|
#if defined(RSP_SAFE_DMA)
|
|
|
|
for (j = 0 ; j < Count; j++)
|
|
|
|
{
|
|
|
|
for (i = 0 ; i < Length; i++)
|
|
|
|
{
|
|
|
|
*(uint8_t *)(((size_t)Dest + j * Length + i) ^ 3) = *(uint8_t *)(((size_t)Source + j * Skip + i) ^ 3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if ((Skip & 0x3) == 0)
|
|
|
|
{
|
|
|
|
for (j = 0; j < Count; j++)
|
|
|
|
{
|
|
|
|
memcpy(Dest, Source, Length);
|
|
|
|
Source += Skip;
|
|
|
|
Dest += Length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (j = 0 ; j < Count; j++)
|
|
|
|
{
|
|
|
|
for (i = 0 ; i < Length; i++)
|
|
|
|
{
|
|
|
|
*(uint8_t *)(((size_t)Dest + i) ^ 3) = *(uint8_t *)(((size_t)Source + i) ^ 3);
|
|
|
|
}
|
|
|
|
Source += Skip;
|
|
|
|
Dest += Length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-03-19 05:39:54 +00:00
|
|
|
// TODO: Could this be a problem DMEM to IMEM?
|
2016-01-27 09:11:59 +00:00
|
|
|
if (CPUCore == RecompilerCPU && (*RSPInfo.SP_MEM_ADDR_REG & 0x1000) != 0)
|
|
|
|
{
|
|
|
|
SetJumpTable(End);
|
|
|
|
}
|
|
|
|
|
|
|
|
*RSPInfo.SP_DMA_BUSY_REG = 0;
|
|
|
|
*RSPInfo.SP_STATUS_REG &= ~SP_STATUS_DMA_BUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SP_DMA_WRITE (void)
|
|
|
|
{
|
2016-02-13 19:33:16 +00:00
|
|
|
uint32_t i, j, Length, Skip, Count, addr;
|
|
|
|
uint8_t *Dest, *Source;
|
2016-01-27 09:11:59 +00:00
|
|
|
|
|
|
|
addr = (*RSPInfo.SP_DRAM_ADDR_REG) & 0x00FFFFFF;
|
|
|
|
|
|
|
|
if (addr > 0x7FFFFF)
|
|
|
|
{
|
2021-03-19 05:39:54 +00:00
|
|
|
DisplayError("SP DMA WRITE\nSP_DRAM_ADDR_REG not in RDRAM space");
|
2016-01-27 09:11:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*RSPInfo.SP_WR_LEN_REG & 0xFFF) + 1 + (*RSPInfo.SP_MEM_ADDR_REG & 0xFFF) > 0x1000)
|
|
|
|
{
|
2021-03-19 05:39:54 +00:00
|
|
|
DisplayError("SP DMA WRITE\nCould not fit copy in memory segment");
|
2016-01-27 09:11:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Length = ((*RSPInfo.SP_WR_LEN_REG & 0xFFF) | 7) + 1;
|
|
|
|
Skip = (*RSPInfo.SP_WR_LEN_REG >> 20) + Length;
|
|
|
|
Count = ((*RSPInfo.SP_WR_LEN_REG >> 12) & 0xFF) + 1;
|
|
|
|
Dest = RSPInfo.RDRAM + (addr & ~7);
|
|
|
|
Source = RSPInfo.DMEM + ((*RSPInfo.SP_MEM_ADDR_REG & 0x1FFF) & ~7);
|
|
|
|
|
|
|
|
#if defined(RSP_SAFE_DMA)
|
|
|
|
for (j = 0 ; j < Count; j++)
|
|
|
|
{
|
|
|
|
for (i = 0 ; i < Length; i++)
|
|
|
|
{
|
|
|
|
*(uint8_t *)(((size_t)Dest + j * Skip + i) ^ 3) = *(uint8_t *)(((size_t)Source + j * Length + i) ^ 3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if ((Skip & 0x3) == 0)
|
|
|
|
{
|
|
|
|
for (j = 0; j < Count; j++)
|
|
|
|
{
|
|
|
|
memcpy(Dest, Source, Length);
|
|
|
|
Source += Length;
|
|
|
|
Dest += Skip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (j = 0 ; j < Count; j++)
|
|
|
|
{
|
|
|
|
for (i = 0 ; i < Length; i++)
|
|
|
|
{
|
|
|
|
*(uint8_t *)(((size_t)Dest + i) ^ 3) = *(uint8_t *)(((size_t)Source + i) ^ 3);
|
|
|
|
}
|
|
|
|
Source += Length;
|
|
|
|
Dest += Skip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
*RSPInfo.SP_DMA_BUSY_REG = 0;
|
|
|
|
*RSPInfo.SP_STATUS_REG &= ~SP_STATUS_DMA_BUSY;
|
|
|
|
}
|