core+gp2x+psp, fix handling mid-frame palette changes

This commit is contained in:
kub 2021-11-10 23:06:08 +01:00
parent d05e2eb3d6
commit ace184013b
8 changed files with 82 additions and 51 deletions

View file

@ -1894,10 +1894,10 @@ PICO_INTERNAL void PicoFrameStart(void)
if (FinalizeLine == FinalizeLine8bit) {
// make a backup of the current palette in case Sonic mode is detected later
Pico.est.SonicPalCount = 0;
Pico.m.dirtyPal = (Pico.m.dirtyPal ? 2 : 0); // mark as dirty but copied
Pico.m.dirtyPal = (Pico.m.dirtyPal || Pico.est.SonicPalCount ? 2 : 0);
blockcpy(Pico.est.SonicPal, PicoMem.cram, 0x40*2);
}
Pico.est.SonicPalCount = 0;
}
static void DrawBlankedLine(int line, int offs, int sh, int bgc)

View file

@ -656,10 +656,10 @@ void PicoFrameStartSMS(void)
Pico.est.DrawLineDest = (char *)DrawLineDestBase + screen_offset * DrawLineDestIncrement;
if (FinalizeLineSMS == FinalizeLine8bitSMS) {
Pico.est.SonicPalCount = 0;
Pico.m.dirtyPal = (Pico.m.dirtyPal ? 2 : 0);
memcpy(Pico.est.SonicPal, PicoMem.cram, 0x20*2);
Pico.m.dirtyPal = (Pico.m.dirtyPal || Pico.est.SonicPalCount ? 2 : 0);
memcpy(Pico.est.SonicPal, PicoMem.cram, 0x40*2);
}
Pico.est.SonicPalCount = 0;
}
void PicoParseSATSMS(int line)
@ -707,13 +707,12 @@ norender:
/* Fixed palette for TMS9918 modes */
static u16 tmspal[32] = {
#if 1 // SMS palette
// SMS palette
0x0000, 0x0000, 0x00a0, 0x00f0, 0x0500, 0x0f00, 0x0005, 0x0ff0,
0x000a, 0x000f, 0x0055, 0x00ff, 0x0050, 0x0f0f, 0x0555, 0x0fff,
#else // TMS palette
// TMS palette
0x0000, 0x0000, 0x04c2, 0x07d5, 0x0e55, 0x0f77, 0x045d, 0x0fe4,
0x055f, 0x077f, 0x05cd, 0x08ce, 0x03b2, 0x0b5c, 0x0ccc, 0x0fff,
#endif
};
void PicoDoHighPal555SMS(void)
@ -737,18 +736,18 @@ void PicoDoHighPal555SMS(void)
if (!(Pico.video.reg[0] & 0x4))
spal = (u32 *)tmspal; // fixed palette in TMS modes
for (i = 0x20/2; i > 0; i--, spal++, dpal++) {
t = *spal;
t = *spal;
#if defined(USE_BGR555)
t = ((t & 0x000f000f)<< 1) | ((t & 0x00f000f0)<<2) | ((t & 0x0f000f00)<<3);
t |= (t >> 4) & 0x04210421;
t = ((t & 0x000f000f)<<1) | ((t & 0x00f000f0)<<2) | ((t & 0x0f000f00)<<3);
t |= (t >> 4) & 0x04210421;
#elif defined(USE_BGR565)
t = ((t & 0x000f000f)<< 1) | ((t & 0x00f000f0)<<3) | ((t & 0x0f000f00)<<4);
t |= (t >> 4) & 0x08610861;
t = ((t & 0x000f000f)<<1) | ((t & 0x00f000f0)<<3) | ((t & 0x0f000f00)<<4);
t |= (t >> 4) & 0x08610861;
#else
t = ((t & 0x000f000f)<<12) | ((t & 0x00f000f0)<<3) | ((t & 0x0f000f00)>>7);
t |= (t >> 4) & 0x08610861;
t = ((t & 0x000f000f)<<12)| ((t & 0x00f000f0)<<3) | ((t & 0x0f000f00)>>7);
t |= (t >> 4) & 0x08610861;
#endif
*dpal = t;
*dpal = t;
}
memcpy(dpal, dpal-0x20/2, 0x20*2); // for prio bit
spal += 0x20/2, dpal += 0x20/2;

View file

@ -56,18 +56,19 @@ static void vdp_data_write(unsigned char d)
struct PicoVideo *pv = &Pico.video;
if (pv->type == 3) {
// cram. 32 on SMS, but 64 on MD. Fill 2nd half of cram for prio bit mirror
if (Pico.m.hardware & 0x1) { // GG, same layout as MD
unsigned a = pv->addr & 0x3f;
if (a & 0x1) { // write complete color on high byte write
u16 c = ((d&0x0f) << 8) | Pico.ms.vdp_buffer;
if (PicoMem.cram[a >> 1] != c) Pico.m.dirtyPal = 1;
PicoMem.cram[a >> 1] = c;
PicoMem.cram[a >> 1] = PicoMem.cram[(a >> 1)+0x20] = c;
}
} else { // SMS, convert to MD layout (00BbGgRr to 0000BbBbGgGgRrRr)
unsigned a = pv->addr & 0x1f;
u16 c = ((d&0x30)<<6) + ((d&0x0c)<<4) + ((d&0x03)<<2);
if (PicoMem.cram[a] != (c | (c>>2))) Pico.m.dirtyPal = 1;
PicoMem.cram[a] = c | (c>>2);
PicoMem.cram[a] = PicoMem.cram[a+0x20] = c | (c>>2);
}
} else {
PicoMem.vramb[MEM_LE2(pv->addr)] = d;