#define SPRL_LO_ABOVE_HI 0x10 // low priority sprites may be on top of hi\r
unsigned char HighLnSpr[240][3 + MAX_LINE_SPRITES]; // sprite_count, ^flags, tile_count, [spritep]...\r
\r
-int rendstatus = 0;\r
-int DrawScanline = 0;\r
+int rendstatus, rendstatus_old;\r
+int DrawScanline;\r
int PicoDrawMask = -1;\r
\r
static int skip_next_line=0;\r
void DrawSpritesSHi(unsigned char *sprited);\r
void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells);\r
void FinalizeLineBGR444(int sh);\r
-void FinalizeLineRGB555(int sh);\r
void *blockcpy(void *dst, const void *src, size_t n);\r
void blockcpy_or(void *dst, void *src, size_t n, int pat);\r
#else\r
#ifndef _ASM_DRAW_C\r
void PicoDoHighPal555(int sh)\r
{\r
+ unsigned int *spal, *dpal;\r
unsigned short *pal=HighPal;\r
int i, t;\r
\r
Pico.m.dirtyPal = 0;\r
\r
- {\r
- unsigned int *spal=(void *)Pico.cram;\r
- unsigned int *dpal=(void *)HighPal;\r
- for (i = 0x3f/2; i >= 0; i--)\r
+ spal = (void *)Pico.cram;\r
+ dpal = (void *)HighPal;\r
+\r
+ for (i = 0; i < 0x40; i++) {\r
+ unsigned int t = spal[i];\r
#ifdef USE_BGR555\r
- dpal[i] = ((spal[i]&0x000f000f)<< 1)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)<<4);\r
+ t = ((t & 0x000e000e)<< 1) | ((t & 0x00e000e0)<<3) | ((t & 0x0e000e00)<<4);\r
#else\r
- dpal[i] = ((spal[i]&0x000f000f)<<12)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)>>7);\r
+ t = ((t & 0x000e000e)<<12) | ((t & 0x00e000e0)<<3) | ((t & 0x0e000e00)>>7);\r
#endif\r
+ t |= (t >> 3) & 0x18e318e3;\r
+ dpal[i] = t;\r
}\r
\r
if (sh)\r
}\r
\r
\r
-static void FinalizeLineRGB555(int sh)\r
+void FinalizeLineRGB555(int sh)\r
{\r
unsigned short *pd=DrawLineDest;\r
unsigned char *ps=HighCol+8;\r
\r
static void FinalizeLine8bit(int sh)\r
{\r
- unsigned char *pd=DrawLineDest;\r
+ unsigned char *pd = DrawLineDest;\r
int len, rs = rendstatus;\r
static int dirty_count;\r
\r
if (Pico.video.reg[12]&1) {\r
len = 320;\r
} else {\r
- if (!(PicoOpt&POPT_DIS_32C_BORDER)) pd+=32;\r
+ if (!(PicoOpt & POPT_DIS_32C_BORDER))\r
+ pd += 32;\r
len = 256;\r
}\r
\r
if (Pico.video.reg[1] & 8)\r
rendstatus |= PDRAW_240LINES;\r
\r
+ DrawScanline = 0;\r
+ skip_next_line = 0;\r
+\r
+ if (rendstatus != rendstatus_old) {\r
+ rendstatus_old = rendstatus;\r
+ emu_video_mode_change((rendstatus & PDRAW_240LINES) ? 0 : 8,\r
+ (rendstatus & PDRAW_240LINES) ? 240 : 224,\r
+ (Pico.video.reg[12] & 1) ? 0 : 1);\r
+ }\r
+\r
+ if (PicoOpt & POPT_ALT_RENDERER)\r
+ return;\r
+\r
if (Pico.m.dirtyPal)\r
Pico.m.dirtyPal = 2; // reset dirty if needed\r
-\r
- DrawScanline=0;\r
PrepareSprites(1);\r
- skip_next_line=0;\r
}\r
\r
static void DrawBlankedLine(int line, int offs)\r
void PicoFrameStartMode4(void)
{
+ int lines = 192;
skip_next_line = 0;
screen_offset = 24;
- rendstatus = PDRAW_192LINES;
+ rendstatus = 0;
+
if ((Pico.video.reg[0] & 6) == 6 && (Pico.video.reg[1] & 0x18)) {
- rendstatus &= ~PDRAW_192LINES;
if (Pico.video.reg[1] & 0x08) {
- screen_offset = 0;
rendstatus |= PDRAW_240LINES;
+ screen_offset = 0;
+ lines = 240;
}
- else // it's 224 lines
+ else {
screen_offset = 8;
+ lines = 224;
+ }
+ }
+
+ if (rendstatus != rendstatus_old) {
+ rendstatus_old = rendstatus;
+ emu_video_mode_change(screen_offset, lines, 1);
}
}
static void FinalizeLineRGB555M4(void)
{
- unsigned short *pd=DrawLineDest;
- unsigned char *ps=HighCol+8;
- unsigned short *pal=HighPal;
- int i;
-
if (Pico.m.dirtyPal)
PicoDoHighPal555M4();
- if (!(PicoOpt & POPT_DIS_32C_BORDER))
- pd += 32;
-
- for (i = 256/4; i > 0; i--) {
- *pd++ = pal[*ps++];
- *pd++ = pal[*ps++];
- *pd++ = pal[*ps++];
- *pd++ = pal[*ps++];
- }
+ // standard FinalizeLine can finish it for us,
+ // with features like scaling and such
+ FinalizeLineRGB555(0);
}
static void FinalizeLine8bitM4(void)
{
- memcpy32(DrawLineDest, (int *)(HighCol+8), 256/4);
+ unsigned char *pd = DrawLineDest;
+
+ if (!(PicoOpt & POPT_DIS_32C_BORDER))
+ pd += 32;
+
+ memcpy32((int *)pd, (int *)(HighCol+8), 256/4);
}
void PicoDrawSetColorFormatMode4(int which)
{\r
Pico.m.frame_count++;\r
\r
- if (PicoAHW & PAHW_MCD) {\r
- PicoFrameMCD();\r
+ if (PicoAHW & PAHW_SMS) {\r
+ PicoFrameMS();\r
return;\r
}\r
- else if (PicoAHW & PAHW_SMS) {\r
- PicoFrameMS();\r
+\r
+ if (PicoAHW & PAHW_MCD) {\r
+ PicoFrameMCD();\r
return;\r
}\r
\r
//if(Pico.video.reg[12]&0x2) Pico.video.status ^= 0x10; // change odd bit in interlace mode\r
\r
- if (!(PicoOpt&POPT_ALT_RENDERER))\r
- PicoFrameStart();\r
-\r
+ PicoFrameStart();\r
PicoFrameHints();\r
}\r
\r
// Pico Library - Header File\r
\r
// (c) Copyright 2004 Dave, All rights reserved.\r
-// (c) Copyright 2006-2008 notaz, All rights reserved.\r
+// (c) Copyright 2006-2009 notaz, All rights reserved.\r
// Free for non-commercial use.\r
\r
// For commercial use, separate licencing terms must be obtained.\r
// used by SVP dynarec\r
extern void cache_flush_d_inval_i(const void *start_addr, const void *end_addr);\r
\r
+// this one should handle display mode changes\r
+extern void emu_video_mode_change(int start_line, int line_count, int is_32cols);\r
+\r
// Pico.c\r
#define POPT_EN_FM (1<< 0) // 00 000x\r
#define POPT_EN_PSG (1<< 1)\r
#define PDRAW_PLANE_HI_PRIO (1<<6) // have layer with all hi prio tiles (mk3)\r
#define PDRAW_SHHI_DONE (1<<7) // layer sh/hi already processed\r
#define PDRAW_240LINES (1<<8) // 240 line display (224 if not set)\r
-#define PDRAW_192LINES (1<<9) // 192 line display (for SMS games)\r
-extern int rendstatus;\r
+extern int rendstatus, rendstatus_old;\r
extern unsigned short HighPal[0x100];\r
\r
// Draw2.c\r
#define z80_int() drZ80.Z80_IRQ = 1\r
\r
#define z80_cyclesLeft drZ80.cycles\r
+#define z80_pc() (drZ80.Z80PC - drZ80.Z80PC_BASE)\r
\r
#elif defined(_USE_CZ80)\r
#include "../cpu/cz80/cz80.h"\r
#define z80_int() Cz80_Set_IRQ(&CZ80, 0, HOLD_LINE)\r
\r
#define z80_cyclesLeft (CZ80.ICount - CZ80.ExtraCycles)\r
+#define z80_pc() Cz80_Get_Reg(&CZ80, CZ80_PC)\r
\r
#else\r
\r
PICO_INTERNAL void PicoFrameStart(void);\r
void PicoDrawSync(int to, int blank_last_line);\r
void BackFill(int reg7, int sh);\r
+void FinalizeLineRGB555(int sh);\r
extern int DrawScanline;\r
#define MAX_LINE_SPRITES 29\r
extern unsigned char HighLnSpr[240][3 + MAX_LINE_SPRITES];\r
int lines = is_pal ? 313 : 262;
int cycles_line = is_pal ? 58020 : 58293; /* (226.6 : 227.7) * 256 */
int cycles_done = 0, cycles_aim = 0;
+ int skip = PicoSkipFrame;
int lines_vis = 192;
int hint; // Hint counter
int y;
{
pv->v_counter = Pico.m.scanline = y;
- if (y < lines_vis)
+ if (y < lines_vis && !skip)
PicoLineMode4(y);
if (y <= lines_vis)
\r
PICO_INTERNAL void PsndGetSamplesMS(void)\r
{\r
- int *buf32 = PsndBuffer;\r
int stereo = (PicoOpt & 8) >> 3;\r
int length = PsndLen;\r
\r
if (PicoOpt & POPT_EN_PSG)\r
SN76496Update(PsndOut, length, stereo);\r
\r
- // convert + limit to normal 16bit output\r
- PsndMix_32_to_16l(PsndOut, buf32, length);\r
+ // upmix to "stereo" if needed\r
+ if (stereo) {\r
+ int i = length, *p = (void *)PsndOut;\r
+ while (i--)\r
+ *p |= *p << 16;\r
+ }\r
\r
if (PicoWriteSound != NULL)\r
PicoWriteSound(length);\r
\r
// For commercial use, separate licencing terms must be obtained.\r
\r
-void vidConvCpyRGB32 (void *to, void *from, int pixels);\r
-void vidConvCpyRGB32sh(void *to, void *from, int pixels);\r
-void vidConvCpyRGB32hi(void *to, void *from, int pixels);\r
+void bgr444_to_rgb32(void *to, void *from);\r
+void bgr444_to_rgb32_sh(void *to, void *from);\r
+\r
void vidcpy_m2(void *dest, void *src, int m32col, int with_32c_border);\r
void vidcpy_m2_rot(void *dest, void *src, int m32col, int with_32c_border);\r
void spend_cycles(int c); // utility\r
@ to 00000000 rrr00000 ggg00000 bbb00000 ...\r
\r
@ lr = 0x00e000e0, out: r3=lower_pix, r2=higher_pix; trashes rin\r
-@ if sh==2, r8=0x00404040 (sh!=0 destroys flags!)\r
.macro convRGB32_2 rin sh=0\r
and r2, lr, \rin, lsr #4 @ blue\r
and r3, \rin, lr\r
.endif\r
\r
orr r2, r2, r2, lsr #3\r
+.if \sh == 1\r
+ str r2, [r0, #0x40*2*4]\r
+.endif\r
str r2, [r0], #4\r
.endm\r
\r
\r
-.global vidConvCpyRGB32 @ void *to, void *from, int pixels\r
+.global bgr444_to_rgb32 @ void *to, void *from\r
\r
-vidConvCpyRGB32:\r
+bgr444_to_rgb32:\r
stmfd sp!, {r4-r7,lr}\r
\r
- mov r12, r2, lsr #3 @ repeats\r
+ mov r12, #0x40>>3 @ repeats\r
mov lr, #0x00e00000\r
orr lr, lr, #0x00e0\r
\r
convRGB32_2 r5\r
convRGB32_2 r6\r
convRGB32_2 r7\r
-\r
bgt .loopRGB32\r
\r
- ldmfd sp!, {r4-r7,lr}\r
- bx lr\r
+ ldmfd sp!, {r4-r7,pc}\r
\r
\r
-.global vidConvCpyRGB32sh @ void *to, void *from, int pixels\r
+.global bgr444_to_rgb32_sh @ void *to, void *from\r
\r
-vidConvCpyRGB32sh:\r
+bgr444_to_rgb32_sh:\r
stmfd sp!, {r4-r7,lr}\r
\r
- mov r12, r2, lsr #3 @ repeats\r
+ mov r12, #0x40>>3 @ repeats\r
+ add r0, r0, #0x40*4\r
mov lr, #0x00e00000\r
orr lr, lr, #0x00e0\r
\r
convRGB32_2 r5, 1\r
convRGB32_2 r6, 1\r
convRGB32_2 r7, 1\r
-\r
bgt .loopRGB32sh\r
\r
- ldmfd sp!, {r4-r7,lr}\r
- bx lr\r
-\r
-\r
-.global vidConvCpyRGB32hi @ void *to, void *from, int pixels\r
-\r
-vidConvCpyRGB32hi:\r
- stmfd sp!, {r4-r7,lr}\r
-\r
- mov r12, r2, lsr #3 @ repeats\r
- mov lr, #0x00e00000\r
- orr lr, lr, #0x00e0\r
+ mov r12, #0x40>>3 @ repeats\r
+ sub r1, r1, #0x40*2\r
\r
.loopRGB32hi:\r
ldmia r1!, {r4-r7}\r
{\r
int pframes_done; /* "period" frames, used for sync */\r
int frames_done, frames_shown; /* actual frames for fps counter */\r
- int oldmodes, target_fps, target_frametime;\r
+ int target_fps, target_frametime;\r
unsigned int timestamp_base = 0, timestamp_fps;\r
char *notice_msg = NULL;\r
char fpsbuff[24];\r
fpsbuff[0] = 0;\r
\r
/* make sure we are in correct mode */\r
- oldmodes = ((Pico.video.reg[12]&1)<<2) ^ 0xc;\r
Pico.m.dirtyPal = 1;\r
+ rendstatus_old = -1;\r
\r
/* number of ticks per frame */\r
if (Pico.m.pal) {\r
{\r
unsigned int timestamp;\r
int diff, diff_lim;\r
- int modes;\r
\r
timestamp = get_ticks();\r
if (reset_timing) {\r
}\r
}\r
\r
- // check for mode changes\r
- modes = ((Pico.video.reg[12]&1)<<2) | (Pico.video.reg[1]&8);\r
- if (modes != oldmodes) {\r
- oldmodes = modes;\r
- pemu_video_mode_change(!(modes & 4), (modes & 8));\r
- }\r
-\r
// second changed?\r
if (timestamp - timestamp_fps >= ms_to_ticks(1000))\r
{\r
void pemu_loop_prep(void);
void pemu_loop_end(void);
void pemu_forced_frame(int opts);
-void pemu_video_mode_change(int is_32col, int is_240_lines);
void pemu_update_display(const char *fps, const char *notice_msg);
void pemu_sound_start(void);
static short __attribute__((aligned(4))) sndBuffer[2*(44100+100)/50];\r
static unsigned char PicoDraw2FB_[(8+320) * (8+240+8)];\r
unsigned char *PicoDraw2FB = PicoDraw2FB_;\r
-static int osd_fps_x;\r
+static int osd_fps_x, osd_y;\r
\r
extern void *gp2x_screens[4];\r
\r
return 0;\r
}\r
\r
-int localPal[0x100];\r
-static void (*vidcpyM2)(void *dest, void *src, int m32col, int with_32c_border) = NULL;\r
+static int localPal[0x100];\r
+static void (*vidcpyM2)(void *dest, void *src, int m32col, int with_32c_border);\r
+static int (*make_local_pal)(int fast_mode);\r
+\r
+static int make_local_pal_md(int fast_mode)\r
+{\r
+ int pallen = 0xc0;\r
+\r
+ bgr444_to_rgb32(localPal, Pico.cram);\r
+ if (fast_mode)\r
+ return 0x40;\r
+\r
+ if (Pico.video.reg[0xC] & 8) { // shadow/hilight mode\r
+ bgr444_to_rgb32_sh(localPal, Pico.cram);\r
+ localPal[0xc0] = 0x0000c000;\r
+ localPal[0xd0] = 0x00c00000;\r
+ localPal[0xe0] = 0x00000000; // reserved pixels for OSD\r
+ localPal[0xf0] = 0x00ffffff;\r
+ pallen = 0x100;\r
+ }\r
+ else if (rendstatus & PDRAW_SONIC_MODE) { // mid-frame palette changes\r
+ bgr444_to_rgb32(localPal+0x40, HighPal);\r
+ bgr444_to_rgb32(localPal+0x80, HighPal+0x40);\r
+ }\r
+ else\r
+ memcpy32(localPal+0x80, localPal, 0x40); // for spr prio mess\r
+\r
+ return pallen;\r
+}\r
+\r
+static int make_local_pal_sms(int fast_mode)\r
+{\r
+ unsigned short *spal = Pico.cram;\r
+ unsigned int *dpal = (void *)localPal;\r
+ unsigned int i, t;\r
+\r
+ for (i = 0x40; i > 0; i--) {\r
+ t = *spal++;\r
+ t = ((t & 0x0003) << 22) | ((t & 0x000c) << 12) | ((t & 0x0030) << 2);\r
+ t |= t >> 2;\r
+ t |= t >> 4;\r
+ *dpal++ = t;\r
+ }\r
+\r
+ return 0x40;\r
+}\r
\r
void pemu_update_display(const char *fps, const char *notice)\r
{\r
int emu_opt = currentConfig.EmuOpt;\r
+ int ret;\r
\r
if (PicoOpt & POPT_ALT_RENDERER)\r
{\r
// 8bit fast renderer\r
if (Pico.m.dirtyPal) {\r
Pico.m.dirtyPal = 0;\r
- vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
+ ret = make_local_pal(1);\r
// feed new palette to our device\r
- gp2x_video_setpalette(localPal, 0x40);\r
+ gp2x_video_setpalette(localPal, ret);\r
}\r
// a hack for VR\r
if (PicoRead16Hook == PicoSVPRead16)\r
// 8bit accurate renderer\r
if (Pico.m.dirtyPal)\r
{\r
- int pallen = 0xc0;\r
Pico.m.dirtyPal = 0;\r
- if (Pico.video.reg[0xC]&8) // shadow/hilight mode\r
- {\r
- vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
- vidConvCpyRGB32sh(localPal+0x40, Pico.cram, 0x40);\r
- vidConvCpyRGB32hi(localPal+0x80, Pico.cram, 0x40);\r
- memcpy32(localPal+0xc0, localPal+0x40, 0x40);\r
- pallen = 0x100;\r
- }\r
- else if (rendstatus & PDRAW_SONIC_MODE) { // mid-frame palette changes\r
- vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
- vidConvCpyRGB32(localPal+0x40, HighPal, 0x40);\r
- vidConvCpyRGB32(localPal+0x80, HighPal+0x40, 0x40);\r
- }\r
- else {\r
- vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
- memcpy32(localPal+0x80, localPal, 0x40); // for spr prio mess\r
- }\r
- if (pallen > 0xc0) {\r
- localPal[0xc0] = 0x0000c000;\r
- localPal[0xd0] = 0x00c00000;\r
- localPal[0xe0] = 0x00000000; // reserved pixels for OSD\r
- localPal[0xf0] = 0x00ffffff;\r
- }\r
- gp2x_video_setpalette(localPal, pallen);\r
+ ret = make_local_pal(0);\r
+ gp2x_video_setpalette(localPal, ret);\r
}\r
}\r
\r
if (notice || (emu_opt & 2)) {\r
- int h = 232;\r
- if (currentConfig.scaling == EOPT_SCALE_HW_HV && !(Pico.video.reg[1]&8))\r
- h -= 8;\r
if (notice)\r
- osd_text(4, h, notice);\r
+ osd_text(4, osd_y, notice);\r
if (emu_opt & 2)\r
- osd_text(osd_fps_x, h, fps);\r
+ osd_text(osd_fps_x, osd_y, fps);\r
}\r
if ((emu_opt & 0x400) && (PicoAHW & PAHW_MCD))\r
draw_cd_leds();\r
if (currentConfig.scaling == EOPT_SCALE_HW_HV && !(Pico.video.reg[1]&8))\r
gp2x_video_RGB_setscaling(8, (PicoOpt&0x100)&&!(Pico.video.reg[12]&1) ? 256 : 320, 224);\r
else gp2x_video_RGB_setscaling(0, (PicoOpt&0x100)&&!(Pico.video.reg[12]&1) ? 256 : 320, 240);\r
+\r
+ // palette converters for 8bit modes\r
+ make_local_pal = (PicoAHW & PAHW_SMS) ? make_local_pal_sms : make_local_pal_md;\r
}\r
\r
void plat_video_toggle_renderer(int is_next, int is_menu)\r
return;\r
\r
vidResetMode();\r
+ rendstatus_old = -1;\r
\r
if (PicoOpt & POPT_ALT_RENDERER) {\r
emu_status_msg(" 8bit fast renderer");\r
{\r
}\r
\r
-void pemu_video_mode_change(int is_32col, int is_240_lines)\r
+void emu_video_mode_change(int start_line, int line_count, int is_32cols)\r
{\r
int scalex = 320;\r
osd_fps_x = OSD_FPS_X;\r
- if (is_32col && (PicoOpt & POPT_DIS_32C_BORDER)) {\r
+ osd_y = 232;\r
+ if (is_32cols && (PicoOpt & POPT_DIS_32C_BORDER)) {\r
scalex = 256;\r
osd_fps_x = OSD_FPS_X - 64;\r
}\r
+\r
/* want vertical scaling and game is not in 240 line mode */\r
- if (currentConfig.scaling == EOPT_SCALE_HW_HV && !is_240_lines)\r
- gp2x_video_RGB_setscaling(8, scalex, 224);\r
- else\r
+ if (currentConfig.scaling == EOPT_SCALE_HW_HV) {\r
+ gp2x_video_RGB_setscaling(start_line, scalex, line_count);\r
+ osd_y = start_line + line_count - 8;\r
+ } else\r
gp2x_video_RGB_setscaling(0, scalex, 240);\r
\r
// clear whole screen in all buffers\r
int eo_old = currentConfig.EmuOpt;\r
\r
pemu_sound_stop();\r
+ memset32(g_screen_ptr, 0, 320*240*2/4);\r
\r
/* do one more frame for menu bg */\r
PicoOpt &= ~POPT_ALT_RENDERER;\r
// to 00000000 rrr00000 ggg00000 bbb00000 ...
// TODO: rm when gp2x/emu.c is no longer used
-void vidConvCpyRGB32 (void *to, void *from, int pixels)
+void bgr444_to_rgb32(void *to, void *from)
{
unsigned short *ps = from;
unsigned int *pd = to;
+ int pixels;
- for (; pixels; pixels--, ps++, pd++)
+ for (pixels = 0x40; pixels; pixels--, ps++, pd++)
{
*pd = ((*ps<<20)&0xe00000) | ((*ps<<8)&0xe000) | ((*ps>>4)&0xe0);
*pd |= *pd >> 3;
}
}
-void vidConvCpyRGB32sh(void *to, void *from, int pixels)
+void bgr444_to_rgb32_sh(void *to, void *from)
{
unsigned short *ps = from;
unsigned int *pd = to;
+ int pixels;
- for (; pixels; pixels--, ps++, pd++)
+ pd += 0x40;
+ for (pixels = 0x40; pixels; pixels--, ps++, pd++)
{
*pd = ((*ps<<20)&0xe00000) | ((*ps<<8)&0xe000) | ((*ps>>4)&0xe0);
*pd >>= 1;
*pd |= *pd >> 3;
+ pd[0x40*2] = *pd;
}
-}
-
-void vidConvCpyRGB32hi(void *to, void *from, int pixels)
-{
- unsigned short *ps = from;
- unsigned int *pd = to;
- for (; pixels; pixels--, ps++, pd++)
+ ps -= 0x40;
+ for (pixels = 0x40; pixels; pixels--, ps++, pd++)
{
*pd = ((*ps<<20)&0xe00000) | ((*ps<<8)&0xe000) | ((*ps>>4)&0xe0);
continue;