Skip to content

Commit

Permalink
use std::swap 🔃
Browse files Browse the repository at this point in the history
  • Loading branch information
RSDuck committed Aug 20, 2021
1 parent c23e158 commit 883fceb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 43 deletions.
64 changes: 31 additions & 33 deletions src/ARM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include <stdio.h>
#include <algorithm>
#include "NDS.h"
#include "DSi.h"
#include "ARM.h"
Expand Down Expand Up @@ -392,74 +393,71 @@ void ARM::RestoreCPSR()

void ARM::UpdateMode(u32 oldmode, u32 newmode)
{
u32 temp;
#define SWAP(a, b) temp = a; a = b; b = temp;

if ((oldmode & 0x1F) == (newmode & 0x1F)) return;

switch (oldmode & 0x1F)
{
case 0x11:
SWAP(R[8], R_FIQ[0]);
SWAP(R[9], R_FIQ[1]);
SWAP(R[10], R_FIQ[2]);
SWAP(R[11], R_FIQ[3]);
SWAP(R[12], R_FIQ[4]);
SWAP(R[13], R_FIQ[5]);
SWAP(R[14], R_FIQ[6]);
std::swap(R[8], R_FIQ[0]);
std::swap(R[9], R_FIQ[1]);
std::swap(R[10], R_FIQ[2]);
std::swap(R[11], R_FIQ[3]);
std::swap(R[12], R_FIQ[4]);
std::swap(R[13], R_FIQ[5]);
std::swap(R[14], R_FIQ[6]);
break;

case 0x12:
SWAP(R[13], R_IRQ[0]);
SWAP(R[14], R_IRQ[1]);
std::swap(R[13], R_IRQ[0]);
std::swap(R[14], R_IRQ[1]);
break;

case 0x13:
SWAP(R[13], R_SVC[0]);
SWAP(R[14], R_SVC[1]);
std::swap(R[13], R_SVC[0]);
std::swap(R[14], R_SVC[1]);
break;

case 0x17:
SWAP(R[13], R_ABT[0]);
SWAP(R[14], R_ABT[1]);
std::swap(R[13], R_ABT[0]);
std::swap(R[14], R_ABT[1]);
break;

case 0x1B:
SWAP(R[13], R_UND[0]);
SWAP(R[14], R_UND[1]);
std::swap(R[13], R_UND[0]);
std::swap(R[14], R_UND[1]);
break;
}

switch (newmode & 0x1F)
{
case 0x11:
SWAP(R[8], R_FIQ[0]);
SWAP(R[9], R_FIQ[1]);
SWAP(R[10], R_FIQ[2]);
SWAP(R[11], R_FIQ[3]);
SWAP(R[12], R_FIQ[4]);
SWAP(R[13], R_FIQ[5]);
SWAP(R[14], R_FIQ[6]);
std::swap(R[8], R_FIQ[0]);
std::swap(R[9], R_FIQ[1]);
std::swap(R[10], R_FIQ[2]);
std::swap(R[11], R_FIQ[3]);
std::swap(R[12], R_FIQ[4]);
std::swap(R[13], R_FIQ[5]);
std::swap(R[14], R_FIQ[6]);
break;

case 0x12:
SWAP(R[13], R_IRQ[0]);
SWAP(R[14], R_IRQ[1]);
std::swap(R[13], R_IRQ[0]);
std::swap(R[14], R_IRQ[1]);
break;

case 0x13:
SWAP(R[13], R_SVC[0]);
SWAP(R[14], R_SVC[1]);
std::swap(R[13], R_SVC[0]);
std::swap(R[14], R_SVC[1]);
break;

case 0x17:
SWAP(R[13], R_ABT[0]);
SWAP(R[14], R_ABT[1]);
std::swap(R[13], R_ABT[0]);
std::swap(R[14], R_ABT[1]);
break;

case 0x1B:
SWAP(R[13], R_UND[0]);
SWAP(R[14], R_UND[1]);
std::swap(R[13], R_UND[0]);
std::swap(R[14], R_UND[1]);
break;
}

Expand Down
19 changes: 9 additions & 10 deletions src/GPU3D_Soft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "GPU3D_Soft.h"

#include <algorithm>
#include <stdio.h>
#include <string.h>
#include "NDS.h"
Expand Down Expand Up @@ -756,11 +757,10 @@ void SoftRenderer::RenderShadowMaskScanline(RendererPolygon* rp, s32 y)
rp->SlopeR.EdgeParams_YMajor(&l_edgelen, &l_edgecov);
rp->SlopeL.EdgeParams_YMajor(&r_edgelen, &r_edgecov);

s32 tmp;
tmp = xstart; xstart = xend; xend = tmp;
tmp = wl; wl = wr; wr = tmp;
tmp = zl; zl = zr; zr = tmp;
tmp = (s32)l_filledge; l_filledge = r_filledge; r_filledge = (bool)tmp;
std::swap(xstart, xend);
std::swap(wl, wr);
std::swap(zl, zr);
std::swap(l_filledge, r_filledge);
}
else
{
Expand Down Expand Up @@ -977,11 +977,10 @@ void SoftRenderer::RenderPolygonScanline(RendererPolygon* rp, s32 y)
rp->SlopeR.EdgeParams_YMajor(&l_edgelen, &l_edgecov);
rp->SlopeL.EdgeParams_YMajor(&r_edgelen, &r_edgecov);

s32 tmp;
tmp = xstart; xstart = xend; xend = tmp;
tmp = wl; wl = wr; wr = tmp;
tmp = zl; zl = zr; zr = tmp;
tmp = (s32)l_filledge; l_filledge = r_filledge; r_filledge = (bool)tmp;
std::swap(xstart, xend);
std::swap(wl, wr);
std::swap(zl, zr);
std::swap(l_filledge, r_filledge);
}
else
{
Expand Down

0 comments on commit 883fceb

Please sign in to comment.