Skip to content

Commit

Permalink
RSP: Better handling on unaligned SH and SW
Browse files Browse the repository at this point in the history
  • Loading branch information
project64 committed Jul 6, 2023
1 parent fbb388f commit 1158815
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions Source/Project64-rsp/memory.cpp
Expand Up @@ -444,10 +444,13 @@ void RSP_SH_DMEM(uint32_t Addr, uint16_t Value)
{
if ((Addr & 0x1) != 0)
{
DisplayError("Unaligned RSP_SH_DMEM");
return;
*(uint8_t *)(RSPInfo.DMEM + ((Addr ^ 3) & 0xFFF)) = (Value >> 8);
*(uint8_t *)(RSPInfo.DMEM + (((Addr + 1) ^ 3) & 0xFFF)) = (Value & 0xFF);
}
else
{
*(uint16_t *)(RSPInfo.DMEM + ((Addr ^ 2) & 0xFFF)) = Value;
}
*(uint16_t *)(RSPInfo.DMEM + ((Addr ^ 2) & 0xFFF)) = Value;
}

void RSP_SHV_DMEM(uint32_t Addr, int vect, int element)
Expand Down Expand Up @@ -579,21 +582,17 @@ void RSP_SUV_DMEM(uint32_t Addr, int vect, int element)

void RSP_SW_DMEM(uint32_t Addr, uint32_t Value)
{
Addr &= 0xFFF;
if ((Addr & 0x3) != 0)
{
if (Addr > 0xFFC)
{
DisplayError("There is a problem with:\nRSP_SW_DMEM");
return;
}
*(uint8_t *)(RSPInfo.DMEM + ((Addr + 0) ^ 3)) = (Value >> 24) & 0xFF;
*(uint8_t *)(RSPInfo.DMEM + ((Addr + 1) ^ 3)) = (Value >> 16) & 0xFF;
*(uint8_t *)(RSPInfo.DMEM + ((Addr + 2) ^ 3)) = (Value >> 8) & 0xFF;
*(uint8_t *)(RSPInfo.DMEM + ((Addr + 3) ^ 3)) = (Value >> 0) & 0xFF;
return;
*(uint8_t *)(RSPInfo.DMEM + (((Addr + 0) ^ 3) & 0xFFF)) = (Value >> 24) & 0xFF;
*(uint8_t *)(RSPInfo.DMEM + (((Addr + 1) ^ 3) & 0xFFF)) = (Value >> 16) & 0xFF;
*(uint8_t *)(RSPInfo.DMEM + (((Addr + 2) ^ 3) & 0xFFF)) = (Value >> 8) & 0xFF;
*(uint8_t *)(RSPInfo.DMEM + (((Addr + 3) ^ 3) & 0xFFF)) = (Value >> 0) & 0xFF;
}
else
{
*(uint32_t *)(RSPInfo.DMEM + (Addr & 0xFFF)) = Value;
}
*(uint32_t *)(RSPInfo.DMEM + Addr) = Value;
}

void RSP_SWV_DMEM(uint32_t Addr, int vect, int element)
Expand Down

0 comments on commit 1158815

Please sign in to comment.