Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

word-wise dma copy #175

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/memory/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ extern void (*writememd[0x10000])(void);

#endif

#ifdef __arm__
void __aeabi_memcpy4(void*, void*, uint32_t); //this is present in libc6 on Raspberry PI
#define MEMCPY4(...) __aeabi_memcpy4(__VA_ARGS__)
#else
#define MEMCPY4(...) memcpy(__VA_ARGS__)
#endif


static void masked_write(uint32_t* dst, uint32_t value, uint32_t mask)
{
*dst = (*dst & ~mask) | (value & mask);
Expand Down
12 changes: 10 additions & 2 deletions src/pi/pi_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,17 @@ static void dma_pi_write(struct pi_controller* pi)
dram = (uint8_t*)pi->ri->rdram.dram;
rom = pi->cart_rom.rom;

for(i = 0; i < longueur; ++i)
// Check for 32-bit word alignment for faster copying
if (((dram_address | rom_address | longueur) & 3) != 0)
{
dram[(dram_address+i)^S8] = rom[(rom_address+i)^S8];
for(i = 0; i < longueur; ++i)
{
dram[(dram_address+i)^S8] = rom[(rom_address+i)^S8];
}
}
else
{
MEMCPY4(&dram[dram_address], &rom[rom_address], longueur);
}

invalidate_r4300_cached_code(0x80000000 + dram_address, longueur);
Expand Down
57 changes: 43 additions & 14 deletions src/rsp/rsp_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,35 @@ static void dma_sp_write(struct rsp_core* sp)
unsigned int length = ((l & 0xfff) | 7) + 1;
unsigned int count = ((l >> 12) & 0xff) + 1;
unsigned int skip = ((l >> 20) & 0xfff);

unsigned int memaddr = sp->regs[SP_MEM_ADDR_REG] & 0xfff;
unsigned int dramaddr = sp->regs[SP_DRAM_ADDR_REG] & 0xffffff;

unsigned char *spmem = (unsigned char*)sp->mem + (sp->regs[SP_MEM_ADDR_REG] & 0x1000);
unsigned char *dram = (unsigned char*)sp->ri->rdram.dram;

for(j=0; j<count; j++) {
for(i=0; i<length; i++) {
spmem[memaddr^S8] = dram[dramaddr^S8];
memaddr++;
dramaddr++;
// Check for 32-bit word alignment for faster copying
if (((memaddr | dramaddr | length | skip) & 3) != 0)
{
for(j=0; j<count; j++)
{
for(i=0; i<length; i++)
{
spmem[memaddr^S8] = dram[dramaddr^S8];
memaddr++;
dramaddr++;
}
dramaddr+=skip;
}
}
else
{
for(j=0; j<count; j++)
{
MEMCPY4(&spmem[memaddr], &dram[dramaddr], length);
memaddr += length;
dramaddr += skip + length;
}
dramaddr+=skip;
}
}

Expand All @@ -73,13 +88,28 @@ static void dma_sp_read(struct rsp_core* sp)
unsigned char *spmem = (unsigned char*)sp->mem + (sp->regs[SP_MEM_ADDR_REG] & 0x1000);
unsigned char *dram = (unsigned char*)sp->ri->rdram.dram;

for(j=0; j<count; j++) {
for(i=0; i<length; i++) {
dram[dramaddr^S8] = spmem[memaddr^S8];
memaddr++;
dramaddr++;
// Check for 32-bit word alignment for faster copying
if (((dramaddr | memaddr | skip | length) & 3) != 0)
{
for(j=0; j<count; j++)
{
for(i=0; i<length; i++)
{
dram[dramaddr^S8] = spmem[memaddr^S8];
memaddr++;
dramaddr++;
}
dramaddr+=skip;
}
}
else
{
for(j=0; j<count; j++)
{
MEMCPY4(&dram[dramaddr], &spmem[memaddr], length);
memaddr += length;
dramaddr += length + skip;
}
dramaddr+=skip;
}
}

Expand Down Expand Up @@ -307,7 +337,6 @@ void do_SP_Task(struct rsp_core* sp)
add_interupt_event(SP_INT, 4000/*500*/);
sp->r4300->mi.regs[MI_INTR_REG] &= ~MI_INTR_SP;
sp->regs[SP_STATUS_REG] &= ~0x300;

}
else
{
Expand Down