reworked palette and buffer handling due to some 32X bugs

This commit is contained in:
kub 2019-03-22 23:03:26 +01:00
parent 23eef37f25
commit b1a047c926
13 changed files with 236 additions and 130 deletions

View file

@ -70,7 +70,7 @@ SRCS_COMMON += $(R)pico/cd/memory_arm.S
endif
ifeq "$(asm_32xdraw)" "1"
DEFINES += _ASM_32X_DRAW
SRCS_COMMON += $(R)pico/32x/draw_arm.s
SRCS_COMMON += $(R)pico/32x/draw_arm.S
endif
ifeq "$(asm_mix)" "1"
SRCS_COMMON += $(R)pico/sound/mix_arm.S

View file

@ -1407,8 +1407,10 @@ void emu_loop(void)
{
notice_msg_time = 0;
plat_status_msg_clear();
#ifndef __GP2X__
plat_video_flip();
plat_status_msg_clear(); /* Do it again in case of double buffering */
#endif
notice_msg = NULL;
}
else {

View file

@ -155,7 +155,7 @@ static void blit(const char *fps, const char *notice)
}
// a hack for VR
if (PicoIn.AHW & PAHW_SVP)
memset32((int *)(Pico.est.Draw2FB+328*8+328*223), 0xe0e0e0e0, 328);
memset((int *)(Pico.est.Draw2FB+328*8+328*223), 0xe0e0e0e0, 328*4);
if (!(Pico.video.reg[12]&1)) lines_flags|=0x10000;
if (currentConfig.EmuOpt&0x4000)
lines_flags|=0x40000; // (Pico.m.frame_count&1)?0x20000:0x40000;
@ -166,22 +166,25 @@ static void blit(const char *fps, const char *notice)
int lines_flags;
// 8bit accurate renderer
if (Pico.m.dirtyPal) {
Pico.m.dirtyPal = 0;
vidConvCpyRGB565(localPal, Pico.cram, 0x40);
if (Pico.m.dirtyPal == 2)
Pico.m.dirtyPal = 0;
/* no support
switch (Pico.est.SonicPalCount) {
case 3: vidConvCpyRGB565(localPal+0xc0, Pico.est.SonicPal+0xc0, 0x40);
case 2: vidConvCpyRGB565(localPal+0x80, Pico.est.SonicPal+0x80, 0x40);
case 1: vidConvCpyRGB565(localPal+0x40, Pico.est.SonicPal+0x40, 0x40);
default://vidConvCpyRGB565(localPal, Pico.est.SonicPal, 0x40);
} */
vidConvCpyRGB565(localPal, Pico.est.SonicPal, 0x40);
if (Pico.video.reg[0xC]&8) { // shadow/hilight mode
//vidConvCpyRGB32sh(localPal+0x40, Pico.cram, 0x40);
//vidConvCpyRGB32hi(localPal+0x80, Pico.cram, 0x40); // TODO?
memcpy32((void *)(localPal+0xc0), (void *)(localPal+0x40), 0x40*2/4);
//vidConvCpyRGB32sh(localPal+0x40, Pico.est.SonicPal, 0x40);
//vidConvCpyRGB32hi(localPal+0x80, Pico.est.SonicPal, 0x40); // TODO?
memcpy((void *)(localPal+0xc0), (void *)(localPal+0x40), 0x40*2);
localPal[0xc0] = 0x0600;
localPal[0xd0] = 0xc000;
localPal[0xe0] = 0x0000; // reserved pixels for OSD
localPal[0xf0] = 0xffff;
}
/* no support
else if (rendstatus & 0x20) { // mid-frame palette changes
vidConvCpyRGB565(localPal+0x40, HighPal, 0x40);
vidConvCpyRGB565(localPal+0x80, HighPal+0x40, 0x40);
} */
}
lines_flags = (Pico.video.reg[1]&8) ? 240 : 224;
if (!(Pico.video.reg[12]&1)) lines_flags|=0x10000;

View file

@ -54,7 +54,7 @@ static unsigned int inp_prev = 0;
void menu_draw_begin(int use_bgbuff)
{
if (use_bgbuff)
memcpy32((int *)menu_screen, (int *)bg_buffer, 321*240*2/4);
memcpy((int *)menu_screen, (int *)bg_buffer, 321*240*2);
}
@ -66,7 +66,7 @@ void menu_draw_end(void)
lprintf("%s: Framework2D_LockBuffer() returned NULL\n", __FUNCTION__);
return;
}
memcpy32(giz_screen, (int *)menu_screen, 321*240*2/4);
memcpy(giz_screen, (int *)menu_screen, 321*240*2);
fb_unlock();
giz_screen = NULL;
fb_flip();

View file

@ -291,32 +291,45 @@ static int EmuScanEnd16_ld(unsigned int num)
}
static int localPal[0x100];
static int localPalSize;
static void (*vidcpyM2)(void *dest, void *src, int m32col, int with_32c_border);
static int (*make_local_pal)(int fast_mode);
static int make_local_pal_md(int fast_mode)
{
int pallen = 0xc0;
int pallen = 0x100;
bgr444_to_rgb32(localPal, PicoMem.cram);
if (fast_mode)
return 0x40;
if (Pico.video.reg[0xC] & 8) { // shadow/hilight mode
bgr444_to_rgb32_sh(localPal, PicoMem.cram);
localPal[0xc0] = 0x0000c000;
localPal[0xd0] = 0x00c00000;
localPal[0xe0] = 0x00000000; // reserved pixels for OSD
localPal[0xf0] = 0x00ffffff;
pallen = 0x100;
if (fast_mode) {
bgr444_to_rgb32(localPal, PicoMem.cram);
pallen = 0x40;
Pico.m.dirtyPal = 0;
}
else if (Pico.est.rendstatus & PDRAW_SONIC_MODE) { // mid-frame palette changes
bgr444_to_rgb32(localPal+0x40, Pico.est.HighPal);
bgr444_to_rgb32(localPal+0x80, Pico.est.HighPal+0x40);
switch (Pico.est.SonicPalCount) {
case 3: bgr444_to_rgb32(localPal+0xc0, Pico.est.SonicPal+0xc0);
case 2: bgr444_to_rgb32(localPal+0x80, Pico.est.SonicPal+0x80);
case 1: bgr444_to_rgb32(localPal+0x40, Pico.est.SonicPal+0x40);
default:bgr444_to_rgb32(localPal, Pico.est.SonicPal);
}
pallen = (Pico.est.SonicPalCount+1)*0x40;
}
else
memcpy(localPal + 0x80, localPal, 0x40 * 4); // for spr prio mess
else if (Pico.video.reg[0xC] & 8) { // shadow/hilight mode
bgr444_to_rgb32(localPal, Pico.est.SonicPal);
bgr444_to_rgb32_sh(localPal, Pico.est.SonicPal);
}
else {
bgr444_to_rgb32(localPal, Pico.est.SonicPal);
memcpy(localPal+0x40, localPal, 0x40*4); // for spr prio mess
memcpy(localPal+0x80, localPal, 0x80*4); // for spr prio mess
}
localPal[0xc0] = 0x0000c000;
localPal[0xd0] = 0x00c00000;
localPal[0xe0] = 0x00000000; // reserved pixels for OSD
localPal[0xf0] = 0x00ffffff;
if (Pico.m.dirtyPal == 2)
Pico.m.dirtyPal = 0;
return pallen;
}
@ -334,25 +347,21 @@ static int make_local_pal_sms(int fast_mode)
*dpal++ = t;
}
Pico.m.dirtyPal = 0;
return 0x40;
}
void pemu_finalize_frame(const char *fps, const char *notice)
{
int emu_opt = currentConfig.EmuOpt;
int ret;
if (PicoIn.AHW & PAHW_32X)
; // nothing to do
localPalSize = 0; // nothing to do
else if (get_renderer() == RT_8BIT_FAST)
{
// 8bit fast renderer
if (Pico.m.dirtyPal) {
Pico.m.dirtyPal = 0;
ret = make_local_pal(1);
// feed new palette to our device
gp2x_video_setpalette(localPal, ret);
}
if (Pico.m.dirtyPal)
localPalSize = make_local_pal(1);
// a hack for VR
if (PicoIn.AHW & PAHW_SVP)
memset32((int *)(Pico.est.Draw2FB+328*8+328*223), 0xe0e0e0e0, 328);
@ -364,12 +373,9 @@ void pemu_finalize_frame(const char *fps, const char *notice)
{
// 8bit accurate renderer
if (Pico.m.dirtyPal)
{
Pico.m.dirtyPal = 0;
ret = make_local_pal(0);
gp2x_video_setpalette(localPal, ret);
}
localPalSize = make_local_pal(0);
}
else localPalSize = 0; // no palette in 16bit mode
if (notice)
osd_text(4, osd_y, notice);
@ -385,6 +391,10 @@ void plat_video_flip(void)
{
int stride = g_screen_width;
gp2x_video_flip();
// switching the palette takes immediate effect, whilst flipping only
// takes effect with the next vsync; unavoidable flicker may occur!
if (localPalSize)
gp2x_video_setpalette(localPal, localPalSize);
if (is_16bit_mode())
stride *= 2;
@ -502,9 +512,6 @@ static void vid_reset_mode(void)
if (renderer == RT_16BIT && (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX)) {
PicoDrawSetOutFormat(PDF_RGB555, 1);
}
else {
PicoDrawSetOutFormat(PDF_NONE, 0);
}
PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);
gp2x_mode = 16;
}
@ -537,10 +544,7 @@ static void vid_reset_mode(void)
localPal[0xe0] = 0x00000000; // reserved pixels for OSD
localPal[0xf0] = 0x00ffffff;
gp2x_video_setpalette(localPal, 0x100);
gp2x_memset_all_buffers(0, 0xe0, 320*240);
}
else
gp2x_memset_all_buffers(0, 0, 320*240*2);
if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX)
gp2x_mode = -gp2x_mode;
@ -723,6 +727,8 @@ void pemu_forced_frame(int no_scale, int do_emu)
PicoDrawSetCallbacks(NULL, NULL);
Pico.m.dirtyPal = 1;
if (!no_scale)
no_scale = currentConfig.scaling == EOPT_SCALE_NONE;
emu_cmn_forced_frame(no_scale, do_emu);
g_menubg_src_ptr = g_screen_ptr;

View file

@ -71,8 +71,8 @@ void pemu_finalize_frame(const char *fps, const char *notice)
unsigned char *ps = Pico.est.Draw2FB + 328*8 + 8;
unsigned short *pal = Pico.est.HighPal;
int i, x;
if (Pico.m.dirtyPal)
PicoDrawUpdateHighPal();
PicoDrawUpdateHighPal();
for (i = 0; i < 224; i++, ps += 8)
for (x = 0; x < 320; x++)
*pd++ = pal[*ps++];
@ -109,6 +109,8 @@ static void apply_renderer(void)
if (PicoIn.AHW & PAHW_32X)
PicoDrawSetOutBuf(g_screen_ptr, g_screen_ppitch * 2);
Pico.m.dirtyPal = 1;
}
void plat_video_toggle_renderer(int change, int is_menu)

View file

@ -201,13 +201,22 @@ static void do_pal_update(int allow_sh, int allow_as)
//for (i = 0x3f/2; i >= 0; i--)
// dpal[i] = ((spal[i]&0x000f000f)<< 1)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)<<4);
do_pal_convert(localPal, Pico.cram, currentConfig.gamma, currentConfig.gamma2);
Pico.m.dirtyPal = 0;
need_pal_upload = 1;
if (allow_sh && (Pico.video.reg[0xC]&8)) // shadow/hilight?
if ((currentConfig.EmuOpt&0x80) || (PicoOpt&0x10)) {
do_pal_convert(localPal, Pico.cram, currentConfig.gamma, currentConfig.gamma2);
Pico.m.dirtyPal = 0;
}
else if (Pico.est.rendstatus&0x20)
{
switch (Pico.est.SonicPalCount) {
case 3: do_pal_convert(localPal+0xc0, Pico.est.SonicPal+0xc0, currentConfig.gamma, currentConfig.gamma2);
case 2: do_pal_convert(localPal+0x80, Pico.est.SonicPal+0x80, currentConfig.gamma, currentConfig.gamma2);
case 1: do_pal_convert(localPal+0x40, Pico.est.SonicPal+0x40, currentConfig.gamma, currentConfig.gamma2);
default:do_pal_convert(localPal, Pico.est.SonicPal, currentConfig.gamma, currentConfig.gamma2);
}
}
else if (allow_sh && (Pico.video.reg[0xC]&8)) // shadow/hilight?
{
do_pal_convert(localPal, Pico.est.SonicPal, currentConfig.gamma, currentConfig.gamma2);
// shadowed pixels
for (i = 0x3f/2; i >= 0; i--)
dpal[0x20|i] = dpal[0x60|i] = (dpal[i]>>1)&0x7bcf7bcf;
@ -223,6 +232,16 @@ static void do_pal_update(int allow_sh, int allow_as)
localPal[0xe0] = 0;
localPal[0xf0] = 0x001f;
}
else if (allow_as && (Pico.est.rendstatus & PDRAW_SPR_LO_ON_HI))
{
do_pal_convert(localPal, Pico.est.SonicPal, currentConfig.gamma, currentConfig.gamma2);
memcpy((int *)dpal+0x40/2, (void *)localPal, 0x40*2);
memcpy((int *)dpal+0x80/2, (void *)localPal, 0x80*2);
}
if (Pico.m.dirtyPal == 2)
Pico.m.dirtyPal = 0;
need_pal_upload = 1;
}
static void do_slowmode_lines(int line_to)
@ -639,7 +658,7 @@ static void writeSound(int len)
PicoIn.sndOut += len / 2;
/*if (PicoIn.sndOut > sndBuffer_endptr) {
memcpy32((int *)(void *)sndBuffer, (int *)endptr, (PicoIn.sndOut - endptr + 1) / 2);
memcpy((int *)(void *)sndBuffer, (int *)endptr, (PicoIn.sndOut - endptr + 1) * 2);
PicoIn.sndOut = &sndBuffer[PicoIn.sndOut - endptr];
lprintf("mov\n");
}

View file

@ -59,7 +59,7 @@ void menu_draw_begin(void)
// int i;
// for (i = 272; i >= 0; i--, dst += 512, src += 480)
// memcpy32((int *)dst, (int *)src, 480*2/4);
// memcpy((int *)dst, (int *)src, 480*2);
sceGuSync(0,0); // sync with prev
sceGuStart(GU_DIRECT, guCmdList);