Commit 2572e073 authored by Nebuleon Fumika's avatar Nebuleon Fumika
Browse files

ppu.cpp: Store multiplicands and quotients using aligned 16-bit writes...

ppu.cpp: Store multiplicands and quotients using aligned 16-bit writes (little-endian). Fold more identical case statements in the huge switch.
parent 4846dfa8
...@@ -356,38 +356,14 @@ void S9xSetPPU (uint8 Byte, uint16 Address) ...@@ -356,38 +356,14 @@ void S9xSetPPU (uint8 Byte, uint16 Address)
} }
break; break;
case 0x2107: // [BG0SC] case 0x2107: // [BG0SC]
if (Byte != Memory.FillRAM [0x2107])
{
FLUSH_REDRAW ();
PPU.BG[0].SCSize = Byte & 3;
PPU.BG[0].SCBase = (Byte & 0x7c) << 8;
}
break;
case 0x2108: // [BG1SC] case 0x2108: // [BG1SC]
if (Byte != Memory.FillRAM [0x2108])
{
FLUSH_REDRAW ();
PPU.BG[1].SCSize = Byte & 3;
PPU.BG[1].SCBase = (Byte & 0x7c) << 8;
}
break;
case 0x2109: // [BG2SC] case 0x2109: // [BG2SC]
if (Byte != Memory.FillRAM [0x2109])
{
FLUSH_REDRAW ();
PPU.BG[2].SCSize = Byte & 3;
PPU.BG[2].SCBase = (Byte & 0x7c) << 8;
}
break;
case 0x210A: // [BG3SC] case 0x210A: // [BG3SC]
if (Byte != Memory.FillRAM [0x210a]) if (Byte != Memory.FillRAM [Address])
{ {
FLUSH_REDRAW (); FLUSH_REDRAW ();
PPU.BG[3].SCSize = Byte & 3; PPU.BG[Address - 0x2107].SCSize = Byte & 3;
PPU.BG[3].SCBase = (Byte & 0x7c) << 8; PPU.BG[Address - 0x2107].SCBase = (Byte & 0x7c) << 8;
} }
break; break;
...@@ -769,15 +745,9 @@ void S9xSetPPU (uint8 Byte, uint16 Address) ...@@ -769,15 +745,9 @@ void S9xSetPPU (uint8 Byte, uint16 Address)
break; break;
case 0x212e: case 0x212e:
// Window mask designation for main screen ? // Window mask designation for main screen ?
if (Byte != Memory.FillRAM [0x212e])
{
FLUSH_REDRAW ();
PPU.RecomputeClipWindows = TRUE;
}
break;
case 0x212f: case 0x212f:
// Window mask designation for sub-screen ? // Window mask designation for sub-screen ?
if (Byte != Memory.FillRAM [0x212f]) if (Byte != Memory.FillRAM [Address])
{ {
FLUSH_REDRAW (); FLUSH_REDRAW ();
PPU.RecomputeClipWindows = TRUE; PPU.RecomputeClipWindows = TRUE;
...@@ -970,7 +940,7 @@ void S9xSetPPU (uint8 Byte, uint16 Address) ...@@ -970,7 +940,7 @@ void S9xSetPPU (uint8 Byte, uint16 Address)
if (Address == 0x2801 && Settings.SRTC) if (Address == 0x2801 && Settings.SRTC)
S9xSetSRTC (Byte, Address); S9xSetSRTC (Byte, Address);
else else
if (Address < 0x3000 || Address >= 0x3000 + 768) if (Address < 0x3000 || Address >= 0x3300)
{ {
#ifdef DEBUGGER #ifdef DEBUGGER
missing.unknownppu_write = Address; missing.unknownppu_write = Address;
...@@ -1505,12 +1475,6 @@ uint8 S9xGetPPU (uint16 Address) ...@@ -1505,12 +1475,6 @@ uint8 S9xGetPPU (uint16 Address)
case 0x2181: case 0x2181:
case 0x2182: case 0x2182:
case 0x2183: case 0x2183:
#ifndef NO_OPEN_BUS
return OpenBus;
#else
return 0; // Arbitrarily chosen value [Neb]
#endif
default: default:
#ifndef NO_OPEN_BUS #ifndef NO_OPEN_BUS
return OpenBus; return OpenBus;
...@@ -1524,7 +1488,7 @@ uint8 S9xGetPPU (uint16 Address) ...@@ -1524,7 +1488,7 @@ uint8 S9xGetPPU (uint16 Address)
if (Settings.SA1) if (Settings.SA1)
return (S9xGetSA1 (Address)); return (S9xGetSA1 (Address));
if (Address <= 0x2fff || Address >= 0x3000 + 768) if (Address <= 0x2fff || Address >= 0x3300)
{ {
switch (Address) switch (Address)
{ {
...@@ -1730,8 +1694,13 @@ void S9xSetCPU (uint8 byte, uint16 Address) ...@@ -1730,8 +1694,13 @@ void S9xSetCPU (uint8 byte, uint16 Address)
// Multiplicand // Multiplicand
uint32 res = Memory.FillRAM[0x4202] * byte; uint32 res = Memory.FillRAM[0x4202] * byte;
#if defined FAST_LSB_WORD_ACCESS || defined FAST_ALIGNED_LSB_WORD_ACCESS
// assume malloc'd memory is 2-byte aligned
* ((uint16 *) &Memory.FillRAM[0x4216]) = res;
#else
Memory.FillRAM[0x4216] = (uint8) res; Memory.FillRAM[0x4216] = (uint8) res;
Memory.FillRAM[0x4217] = (uint8) (res >> 8); Memory.FillRAM[0x4217] = (uint8) (res >> 8);
#endif
break; break;
} }
case 0x4204: case 0x4204:
...@@ -1740,16 +1709,25 @@ void S9xSetCPU (uint8 byte, uint16 Address) ...@@ -1740,16 +1709,25 @@ void S9xSetCPU (uint8 byte, uint16 Address)
break; break;
case 0x4206: case 0x4206:
{ {
// TODO FAST_ALIGNED_LSB_WORD_ACCESS [Neb] #if defined FAST_LSB_WORD_ACCESS || defined FAST_ALIGNED_LSB_WORD_ACCESS
// Divisor // assume malloc'd memory is 2-byte aligned
uint16 a = *((uint16 *) &Memory.FillRAM[0x4204]);
#else
uint16 a = Memory.FillRAM[0x4204] + (Memory.FillRAM[0x4205] << 8); uint16 a = Memory.FillRAM[0x4204] + (Memory.FillRAM[0x4205] << 8);
#endif
uint16 div = byte ? a / byte : 0xffff; uint16 div = byte ? a / byte : 0xffff;
uint16 rem = byte ? a % byte : a; uint16 rem = byte ? a % byte : a;
#if defined FAST_LSB_WORD_ACCESS || defined FAST_ALIGNED_LSB_WORD_ACCESS
// assume malloc'd memory is 2-byte aligned
* ((uint16 *) &Memory.FillRAM[0x4214]) = div;
* ((uint16 *) &Memory.FillRAM[0x4216]) = rem;
#else
Memory.FillRAM[0x4214] = (uint8)div; Memory.FillRAM[0x4214] = (uint8)div;
Memory.FillRAM[0x4215] = div >> 8; Memory.FillRAM[0x4215] = div >> 8;
Memory.FillRAM[0x4216] = (uint8)rem; Memory.FillRAM[0x4216] = (uint8)rem;
Memory.FillRAM[0x4217] = rem >> 8; Memory.FillRAM[0x4217] = rem >> 8;
#endif
break; break;
} }
case 0x4207: case 0x4207:
...@@ -2317,8 +2295,7 @@ uint8 S9xGetCPU (uint16 Address) ...@@ -2317,8 +2295,7 @@ uint8 S9xGetCPU (uint16 Address)
case 0x4213: case 0x4213:
// I/O port input - returns 0 wherever $4201 is 0, and 1 elsewhere // I/O port input - returns 0 wherever $4201 is 0, and 1 elsewhere
// unless something else pulls it down (i.e. a gun) // unless something else pulls it down (i.e. a gun)
return Memory.FillRAM[0x4213]; /* fall through */
case 0x4214: case 0x4214:
case 0x4215: case 0x4215:
// Quotient of divide result // Quotient of divide result
...@@ -2400,18 +2377,7 @@ uint8 S9xGetCPU (uint16 Address) ...@@ -2400,18 +2377,7 @@ uint8 S9xGetCPU (uint16 Address)
case 0x4356: case 0x4356:
case 0x4366: case 0x4366:
case 0x4376: case 0x4376:
return (Memory.FillRAM[Address]); /* fall through */
case 0x4307:
case 0x4317:
case 0x4327:
case 0x4337:
case 0x4347:
case 0x4357:
case 0x4367:
case 0x4377:
return (DMA[(Address >> 4) & 7].IndirectBank);
case 0x4308: case 0x4308:
case 0x4318: case 0x4318:
case 0x4328: case 0x4328:
...@@ -2431,6 +2397,16 @@ uint8 S9xGetCPU (uint16 Address) ...@@ -2431,6 +2397,16 @@ uint8 S9xGetCPU (uint16 Address)
case 0x4379: case 0x4379:
return (Memory.FillRAM[Address]); return (Memory.FillRAM[Address]);
case 0x4307:
case 0x4317:
case 0x4327:
case 0x4337:
case 0x4347:
case 0x4357:
case 0x4367:
case 0x4377:
return (DMA[(Address >> 4) & 7].IndirectBank);
case 0x430A: case 0x430A:
case 0x431A: case 0x431A:
case 0x432A: case 0x432A:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment