From 7980d47767fca1244743bd3a4c520c4dc406ef6b Mon Sep 17 00:00:00 2001 From: kub Date: Sat, 25 Jul 2020 23:58:57 +0200 Subject: [PATCH] sms mode 4, fix 8 bit renderer code --- pico/draw.c | 10 +++++++--- pico/mode4.c | 17 +++++++++++++---- pico/pico_int.h | 2 ++ platform/linux/emu.c | 20 +++++++++++++------- 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/pico/draw.c b/pico/draw.c index 668a1246..43bbea76 100644 --- a/pico/draw.c +++ b/pico/draw.c @@ -36,8 +36,8 @@ int (*PicoScanBegin)(unsigned int num) = NULL; int (*PicoScanEnd) (unsigned int num) = NULL; static unsigned char DefHighCol[8+320+8]; -static unsigned char *HighColBase = DefHighCol; -static int HighColIncrement; +unsigned char *HighColBase = DefHighCol; +int HighColIncrement; static unsigned int DefOutBuff[320*2/2]; void *DrawLineDestBase = DefOutBuff; @@ -1848,7 +1848,9 @@ void PicoDrawUpdateHighPal(void) if ((PicoIn.opt & POPT_ALT_RENDERER) | (est->rendstatus & PDRAW_SONIC_MODE)) sh = 0; // no s/h support - if (FinalizeLine == FinalizeLine8bit) + if (PicoIn.AHW & PAHW_SMS) + PicoDoHighPal555M4(); + else if (FinalizeLine == FinalizeLine8bit) PicoDoHighPal555_8bit(sh, 0, est); else PicoDoHighPal555(sh, 0, est); @@ -1863,6 +1865,7 @@ void PicoDrawUpdateHighPal(void) void PicoDrawSetOutFormat(pdso_t which, int use_32x_line_mode) { + PicoDrawSetInternalBuf(NULL, 0); switch (which) { case PDF_8BIT: @@ -1878,6 +1881,7 @@ void PicoDrawSetOutFormat(pdso_t which, int use_32x_line_mode) default: FinalizeLine = NULL; + PicoDrawSetOutBufMD(Pico.est.Draw2FB+8, 328); break; } if (PicoIn.AHW & PAHW_32X) diff --git a/pico/mode4.c b/pico/mode4.c index 8c063857..ca219a0a 100644 --- a/pico/mode4.c +++ b/pico/mode4.c @@ -69,6 +69,8 @@ static void draw_sprites(int scanline) if (pv->reg[0] & 8) xoff = 0; + if (!(PicoIn.opt & POPT_DIS_32C_BORDER)) + xoff += 32; sat = (unsigned char *)PicoMem.vram + ((pv->reg[5] & 0x7e) << 7); if (pv->reg[1] & 2) { @@ -177,6 +179,8 @@ static void DrawDisplayM4(int scanline) if (dx != 8) cells++; // have hscroll, need to draw 1 cell more dx += cellskip << 3; + if (!FinalizeLineM4 && !(PicoIn.opt & POPT_DIS_32C_BORDER)) + dx += 32; // low priority tiles if (!(pv->debug_p & PVD_KILL_B)) @@ -190,9 +194,11 @@ static void DrawDisplayM4(int scanline) if (!(pv->debug_p & PVD_KILL_A)) draw_strip(nametab, dx, cells, tilex | 0x1000 | (ty << 16)); - if (pv->reg[0] & 0x20) - // first column masked - ((int *)Pico.est.HighCol)[2] = ((int *)Pico.est.HighCol)[3] = 0xe0e0e0e0; + if (pv->reg[0] & 0x20) { + // first column masked, caculate offset to start of line + dx = (dx&~0x1f) / 4; + ((u32 *)Pico.est.HighCol)[dx+2] = ((u32 *)Pico.est.HighCol)[dx+3] = 0xe0e0e0e0; + } } void PicoFrameStartMode4(void) @@ -219,6 +225,7 @@ void PicoFrameStartMode4(void) rendlines = lines; } + Pico.est.HighCol = HighColBase + screen_offset * HighColIncrement; Pico.est.DrawLineDest = (char *)DrawLineDestBase + screen_offset * DrawLineDestIncrement; } @@ -243,6 +250,7 @@ void PicoLineMode4(int line) if (PicoScanEnd != NULL) skip_next_line = PicoScanEnd(line + screen_offset); + Pico.est.HighCol += HighColIncrement; Pico.est.DrawLineDest = (char *)Pico.est.DrawLineDest + DrawLineDestIncrement; } @@ -296,7 +304,8 @@ void PicoDrawSetOutputMode4(pdso_t which) { case PDF_8BIT: FinalizeLineM4 = FinalizeLine8bitM4; break; case PDF_RGB555: FinalizeLineM4 = FinalizeLineRGB555M4; break; - default: FinalizeLineM4 = NULL; break; + default: FinalizeLineM4 = NULL; + PicoDrawSetInternalBuf(Pico.est.Draw2FB, 328); break; } } diff --git a/pico/pico_int.h b/pico/pico_int.h index 7d69bcab..2d688a9f 100644 --- a/pico/pico_int.h +++ b/pico/pico_int.h @@ -666,6 +666,8 @@ extern int (*PicoScanBegin)(unsigned int num); extern int (*PicoScanEnd)(unsigned int num); #define MAX_LINE_SPRITES 27 // +1 last sprite width, +4 hdr; total 32 extern unsigned char HighLnSpr[240][4+MAX_LINE_SPRITES+1]; +extern unsigned char *HighColBase; +extern int HighColIncrement; extern void *DrawLineDestBase; extern int DrawLineDestIncrement; extern unsigned int VdpSATCache[128]; diff --git a/platform/linux/emu.c b/platform/linux/emu.c index 597c1308..4ef08a79 100644 --- a/platform/linux/emu.c +++ b/platform/linux/emu.c @@ -22,6 +22,8 @@ const char *renderer_names[] = { "16bit accurate", " 8bit accurate", " 8bit fast const char *renderer_names32x[] = { "accurate", "faster", "fastest", NULL }; enum renderer_types { RT_16BIT, RT_8BIT_ACC, RT_8BIT_FAST, RT_COUNT }; +static int out_x, out_y; +static int out_w, out_h; void pemu_prep_defconfig(void) { @@ -70,15 +72,18 @@ static void draw_cd_leds(void) void pemu_finalize_frame(const char *fps, const char *notice) { if (currentConfig.renderer != RT_16BIT && !(PicoIn.AHW & PAHW_32X)) { - unsigned short *pd = (unsigned short *)g_screen_ptr + 8 * g_screen_ppitch; - unsigned char *ps = Pico.est.Draw2FB + 328*8 + 8; + unsigned short *pd = (unsigned short *)g_screen_ptr + out_y * g_screen_ppitch + out_x; + unsigned char *ps = Pico.est.Draw2FB + 328*out_y + out_x + 8; unsigned short *pal = Pico.est.HighPal; int i, x; PicoDrawUpdateHighPal(); - for (i = 0; i < 224; i++, ps += 8) - for (x = 0; x < 320; x++) + for (i = 0; i < out_h; i++, ps += 8) { + for (x = 0; x < out_w; x++) *pd++ = pal[*ps++]; + pd += 320 - out_w; + ps += 320 - out_w; + } } if (notice || (currentConfig.EmuOpt & EOPT_SHOW_FPS)) { @@ -180,9 +185,10 @@ void emu_video_mode_change(int start_line, int line_count, int is_32cols) { // clear whole screen in all buffers if (currentConfig.renderer != RT_16BIT && !(PicoIn.AHW & PAHW_32X)) - memset32(Pico.est.Draw2FB, 0, (320+8) * (8+240+8) / 4); - else - memset32(g_screen_ptr, 0, g_screen_ppitch * g_screen_height * 2 / 4); + memset32(Pico.est.Draw2FB, 0xe0e0e0e0, (320+8) * (8+240+8) / 4); + memset32(g_screen_ptr, 0, g_screen_ppitch * g_screen_height * 2 / 4); + out_y = start_line; out_x = (is_32cols ? 32 : 0); + out_h = line_count; out_w = (is_32cols ? 256:320); } void pemu_loop_prep(void) -- 2.39.2