Skip to content

Commit 05b9028

Browse files
committed
Fix some CPU sign extension bugs
1 parent 5986b3b commit 05b9028

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

src/cpu.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ void CPU::mult(uint32_t opcode)
757757
int64_t value = (int64_t)(int32_t)registersR[(opcode >> 16) & 0x1F] *
758758
(int32_t)registersR[(opcode >> 21) & 0x1F];
759759
hi = value >> 32;
760-
lo = (uint32_t)value;
760+
lo = (int32_t)value;
761761
}
762762

763763
void CPU::multu(uint32_t opcode)
@@ -766,7 +766,7 @@ void CPU::multu(uint32_t opcode)
766766
uint64_t value = (uint64_t)(uint32_t)registersR[(opcode >> 16) & 0x1F] *
767767
(uint32_t)registersR[(opcode >> 21) & 0x1F];
768768
hi = value >> 32;
769-
lo = (uint32_t)value;
769+
lo = (int32_t)value;
770770
}
771771

772772
void CPU::div(uint32_t opcode)

src/cpu_cp0.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void CPU_CP0::reset()
9090
scheduleCount();
9191
}
9292

93-
uint32_t CPU_CP0::read(int index)
93+
int32_t CPU_CP0::read(int index)
9494
{
9595
// Read from a CPU CP0 register if one exists at the given index
9696
switch (index)
@@ -153,7 +153,7 @@ uint32_t CPU_CP0::read(int index)
153153
}
154154
}
155155

156-
void CPU_CP0::write(int index, uint32_t value)
156+
void CPU_CP0::write(int index, int32_t value)
157157
{
158158
// Write to a CPU CP0 register if one exists at the given index
159159
switch (index)

src/cpu_cp0.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ namespace CPU_CP0
2727
extern void (*cp0Instrs[])(uint32_t);
2828

2929
void reset();
30-
uint32_t read(int index);
31-
void write(int index, uint32_t value);
30+
int32_t read(int index);
31+
void write(int index, int32_t value);
3232

3333
void resetCycles();
3434
void checkInterrupts();

src/cpu_cp1.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ uint64_t CPU_CP1::read(CP1Type type, int index)
179179
case CP1_32BIT:
180180
// Read a 32-bit register value, mapped based on the current mode
181181
// TODO: make this endian-safe
182-
return fullMode ? *(uint32_t*)&registers[index] :
183-
*((uint32_t*)&registers[index & ~1] + (index & 1));
182+
return fullMode ? *(int32_t*)&registers[index] : *((int32_t*)&registers[index & ~1] + (index & 1));
184183

185184
case CP1_64BIT:
186185
// Read a 64-bit register value
@@ -208,8 +207,7 @@ void CPU_CP1::write(CP1Type type, int index, uint64_t value)
208207
case CP1_32BIT:
209208
// Write a 32-bit value to a register, mapped based on the current mode
210209
// TODO: make this endian-safe
211-
(fullMode ? *(uint32_t*)&registers[index] :
212-
*((uint32_t*)&registers[index & ~1] + (index & 1))) = value;
210+
(fullMode ? *(int32_t*)&registers[index] : *((int32_t*)&registers[index & ~1] + (index & 1))) = value;
213211
return;
214212

215213
case CP1_64BIT:

0 commit comments

Comments
 (0)