Skip to content

Commit

Permalink
Fixed lswi, mtocrf, stswi PPU instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAltea committed Oct 24, 2014
1 parent db57ec9 commit 05b2043
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
14 changes: 9 additions & 5 deletions nucleus/cpu/ppu/interpreter/ppu_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ void PPUInterpreter::lswi(PPUFields code, PPUThread& thread)
{
u64 ea = code.ra ? thread.gpr[code.ra] : 0;
u64 n = code.nb ? code.nb : 32;
u8 reg = thread.gpr[code.rd];
u8 reg = code.rd;
while (n > 0) {
if (n > 3) {
thread.gpr[reg] = nucleus.memory.read32(ea);
Expand All @@ -657,10 +657,12 @@ void PPUInterpreter::lswi(PPUFields code, PPUThread& thread)
}
else {
u32 buf = 0;
u32 i = 3;
while (n > 0) {
n--;
buf |= nucleus.memory.read8(ea) << (n*8);
buf |= nucleus.memory.read8(ea) << (i * 8);
ea++;
i--;
}
thread.gpr[reg] = buf;
}
Expand Down Expand Up @@ -786,11 +788,13 @@ void PPUInterpreter::mtocrf(PPUFields code, PPUThread& thread)
}
}
else {
for (u32 i=0; i<8; ++i) {
u32 mask = 0;
for (int i = 0; i < 8; i++) {
if (code.crm & (1 << i)) {
thread.cr.setField(7 - i, thread.gpr[code.rs] & (0xf << (i * 4)));
mask |= (0xF << (i * 4));
}
}
thread.cr.CR = bitReverse32(thread.gpr[code.rs] & mask) | (bitReverse32(thread.cr.CR) & ~mask);
}
}
void PPUInterpreter::mtspr(PPUFields code, PPUThread& thread)
Expand Down Expand Up @@ -1121,7 +1125,7 @@ void PPUInterpreter::stswi(PPUFields code, PPUThread& thread)
{
u64 ea = code.ra ? thread.gpr[code.ra] : 0;
u64 n = code.nb ? code.nb : 32;
u8 reg = thread.gpr[code.rd];
u8 reg = code.rd;

while (n > 0) {
if (n > 3) {
Expand Down
11 changes: 11 additions & 0 deletions nucleus/cpu/ppu/ppu_disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,17 @@ std::string dis_mftb(PPUFields code)
return dis_global("mftb", "r%d, %d", code.rd, tbr);
}

std::string dis_mtocrf(PPUFields code)
{
if (code.l11 == 0 && code.crm == 0xFF) {
return dis_global("mtcr", "r%d", code.rs);
} else if (code.l11 == 0) {
return dis_global("mtcrf", "0x%X, r%d", code.crm, code.rs);
} else {
return dis_global("mtocrf", "0x%X, r%d", code.crm, code.rs);
}
}

std::string dis_mtspr(PPUFields code)
{
switch ((code.spr >> 5) | ((code.spr & 0x1F) << 5)) {
Expand Down
1 change: 1 addition & 0 deletions nucleus/cpu/ppu/ppu_disasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ std::string dis_mfcr(PPUFields code);
std::string dis_mfocrf(PPUFields code);
std::string dis_mfspr(PPUFields code);
std::string dis_mftb(PPUFields code);
std::string dis_mtocrf(PPUFields code);
std::string dis_mtspr(PPUFields code);
std::string dis_mulhdx(PPUFields code);
std::string dis_mulhdux(PPUFields code);
Expand Down
4 changes: 2 additions & 2 deletions nucleus/cpu/ppu/ppu_tables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void initTables()
s_table31[0x087] = {"stvebx", PPUInterpreter::stvebx, dis_unknown};
s_table31[0x088] = {"subfe", PPUInterpreter::subfe, dis_subfex};
s_table31[0x08a] = {"adde", PPUInterpreter::adde, dis_addex};
s_table31[0x090] = {"mtocrf", PPUInterpreter::mtocrf, dis_unknown};
s_table31[0x090] = {"mtocrf", PPUInterpreter::mtocrf, dis_mtocrf};
s_table31[0x095] = {"stdx", PPUInterpreter::stdx, dis_stdx};
s_table31[0x096] = {"stwcx_", PPUInterpreter::stwcx_, dis_stwcx_};
s_table31[0x097] = {"stwx", PPUInterpreter::stwx, dis_stwx};
Expand All @@ -343,7 +343,7 @@ void initTables()
s_table31[0x11c] = {"eqv", PPUInterpreter::eqv, dis_eqvx};
s_table31[0x136] = {"eciwx", PPUInterpreter::eciwx, dis_eciwx};
s_table31[0x137] = {"lhzux", PPUInterpreter::lhzux, dis_lhzux};
s_table31[0x13c] = {"xor", PPUInterpreter::xorx, dis_unknown};
s_table31[0x13c] = {"xor", PPUInterpreter::xorx, dis_xorx};
s_table31[0x153] = {"mfspr", PPUInterpreter::mfspr, dis_mfspr};
s_table31[0x155] = {"lwax", PPUInterpreter::lwax, dis_lwax};
s_table31[0x156] = {"dst", PPUInterpreter::dst, dis_unknown};
Expand Down
1 change: 1 addition & 0 deletions nucleus/loader/loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Filetype detectFiletype(const std::string& filepath)
if (!fs->isOpen(file) || !fs->readFile(file, &magic, sizeof(magic))) {
return FILETYPE_ERROR;
}
fs->closeFile(file);

switch (magic.ToBE()) {
case 0x464c457f:
Expand Down
4 changes: 2 additions & 2 deletions nucleus/nucleus.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)\bin\</OutDir>
<OutDir>$(SolutionDir)bin\</OutDir>
<TargetName>$(ProjectName)-dbg</TargetName>
<LibraryPath>$(SolutionDir)\libs\$(Configuration)\;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)\bin\</OutDir>
<OutDir>$(SolutionDir)bin\</OutDir>
<LibraryPath>$(SolutionDir)\libs\$(Configuration)\;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand Down

0 comments on commit 05b2043

Please sign in to comment.