Example #1
0
void gp2x_init(int ticks_per_second, int bpp, int rate, int bits, int stereo, int Hz)
{
	static pthread_t main_tid;

    if (!lib_inited )
    {

       gp2x_ticks_per_second=1000;

	   //gp2x_screen15=screenbuffer;
	   //gp2x_screen8=(unsigned char *)screenbuffer;

	   gp2x_screen15=screenbuffer;
	   gp2x_screen8=(unsigned char *)screenbuffer;
       initVideo_callback((void *)&screenbuffer);

	   gp2x_nflip=0;

	   gp2x_set_video_mode(bpp,320,240);

	   gp2x_video_color8(0,0,0,0);
	   gp2x_video_color8(255,255,255,255);
	   gp2x_video_setpalette();

	   /* atexit(gp2x_deinit); */
	   //app_DemuteSound();

	   //int i = pthread_create(&main_tid, NULL, threaded_sound_play, NULL);
	   //if(i!=0)__android_log_print(ANDROID_LOG_ERROR, "mame4all-jni", "Error setting creating pthread %d",i);

	   pthread_mutex_init (&mut,NULL);
   	   lib_inited = 1;
    }
}
Example #2
0
void gp2x_init(int ticks_per_second, int bpp, int rate, int bits, int stereo, int Hz)
{

    if (!lib_inited )
    {

       gp2x_ticks_per_second=1000;

	   //gp2x_screen15=screenbuffer;
	   //gp2x_screen8=(unsigned char *)screenbuffer;
	   gp2x_nflip=0;

	   gp2x_set_video_mode(bpp,320,240);

	   gp2x_video_color8(0,0,0,0);
	   gp2x_video_color8(255,255,255,255);
	   gp2x_video_setpalette();

	   /* atexit(gp2x_deinit); */
	   //app_DemuteSound();

	   pthread_mutex_init (&mut,NULL);
   	   lib_inited = 1;
    }
}
Example #3
0
void pemu_finalize_frame(const char *fps, const char *notice)
{
	int emu_opt = currentConfig.EmuOpt;
	int ret;

	if (PicoAHW & PAHW_32X)
		; // 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);
		}
		// a hack for VR
		if (PicoAHW & PAHW_SVP)
			memset32((int *)(PicoDraw2FB+328*8+328*223), 0xe0e0e0e0, 328);
		// do actual copy
		vidcpyM2(g_screen_ptr, PicoDraw2FB+328*8,
			!(Pico.video.reg[12] & 1), !(PicoOpt & POPT_DIS_32C_BORDER));
	}
	else if (get_renderer() == RT_8BIT_ACC)
	{
		// 8bit accurate renderer
		if (Pico.m.dirtyPal)
		{
			Pico.m.dirtyPal = 0;
			ret = make_local_pal(0);
			gp2x_video_setpalette(localPal, ret);
		}
	}

	if (notice)
		osd_text(4, osd_y, notice);
	if (emu_opt & EOPT_SHOW_FPS)
		osd_text(osd_fps_x, osd_y, fps);
	if ((PicoAHW & PAHW_MCD) && (emu_opt & EOPT_EN_CD_LEDS))
		draw_cd_leds();
	if (PicoAHW & PAHW_PICO)
		draw_pico_ptr();
}
Example #4
0
void gp2x_mame_palette(void) {
	int i;

	/* Color #0 is black */
	for (i=0;i<256;i++)
		gp2x_video_color8(i,0,0,0);
	
	/* Color #1 is white */
	gp2x_video_color8(1,255,255,255);
	
	/* Update Palette */
	gp2x_video_setpalette();
}
Example #5
0
int video_canvas_set_palette(struct video_canvas_s *canvas,
                                    struct palette_s *palette)
{
	fprintf(stderr, "calling %s\n", __func__);
	int i;
	for(i=0; i<palette->num_entries; i++) {
		gp2x_palette[i*2]=
			((palette->entries[i].green)<<8)
			| (palette->entries[i].blue);
		gp2x_palette[i*2+1]=palette->entries[i].red;
	}
	gp2x_video_setpalette();
	return 0;
}
Example #6
0
/* Update GP2X Palette */
static void update_palette (void)
{
	int i;
	unsigned char *dirty=dirtycolor;

	for (i = 0;i < 256;i++)
	{
		if (dirty[i])
		{
			dirty[i] = 0;
			gp2x_video_color8(i,(current_palette[i][0]),(current_palette[i][1]),(current_palette[i][2]));
		}
	}
	dirtypalette = 0;

	/* Update Palette */
	gp2x_video_setpalette();
}	
Example #7
0
static void load_bmp_8bpp(unsigned char *out, unsigned char *in) 
{
	int i,x,y;
	unsigned char r,g,b,c;
	in+=14; /* Skip HEADER */
	in+=40; /* Skip INFOHD */
	/* Set Palette */
	for (i=0;i<256;i++) {
		b=*in++;
		g=*in++;
		r=*in++;
		c=*in++;
		gp2x_video_color8(i,r,g,b);
	}
	gp2x_video_setpalette();
	/* Set Bitmap */	
	for (y=239;y!=-1;y--) {
		for (x=0;x<320;x++) {
			*out++=in[x+y*320];
		}
	}
}
Example #8
0
void load_bmp_8bpp(unsigned char *out, unsigned char *in) 
{
#ifndef PSP
	int i,x,y;
	unsigned char r,g,b,c;

	in+=14; /* Skip HEADER */
	in+=40; /* Skip INFOHD */
	
	/* Set Palette */
	for (i=0;i<256;i++) {
		b=*in++;
		g=*in++;
		r=*in++;
		c=*in++;
		gp2x_video_color8(i,r,g,b);
	}
	gp2x_video_setpalette();
#ifdef GP2X
	if (gp2x_bordertvout) {
		out+=((((gp2x_bordertvout_width*320)/100)+7)&~7)/2;
		out+=(320+((((gp2x_bordertvout_width*320)/100))+7)&~7)*(((((gp2x_bordertvout_height*240)/100)+7)&~7)/2);
		/* Set Bitmap */	
		for (y=239;y!=-1;y--) {
			for (x=0;x<320;x++) {
				*out++=in[x+y*320];
			}
			out+=((((gp2x_bordertvout_width*320)/100)+7)&~7);
		}
	} else {
		/* Set Bitmap */	
		for (y=239;y!=-1;y--) {
			for (x=0;x<320;x++) {
				*out++=in[x+y*320];
			}
		}
	}
#else
	/* Set Bitmap */	
	for (y=239;y!=-1;y--) {
		for (x=0;x<320;x++) {
			*out++=in[x+y*320];
		}
	}
#endif
#else
#ifndef NO_IMAGES
	int i,x,y;
	unsigned char r,g,b,c;

	in+=14; /* Skip HEADER */
	in+=40; /* Skip INFOHD */
	
	/* Set Palette */
	for (i=0;i<256;i++) {
		b=*in++;
		g=*in++;
		r=*in++;
		c=*in++;
		gp2x_video_color8(i,r,g,b);
	}
	gp2x_video_setpalette();
	/* Set Bitmap */	
 #ifdef PSP_RES
	for (y=271;y!=-1;y--) {
		for (x=0;x<480;x++) {
			*out++=in[x+y*480];
		}
	}
 #else
	for (y=239;y!=-1;y--) {
		for (x=0;x<320;x++) {
			*out++=in[x+y*320];
		}
	}
 #endif
#else
	int i,x,y;
	unsigned char r,g,b,c;
	/* font face color */
	gp2x_video_color8(255,255,255,255);
	/* font shadow color */
	gp2x_video_color8(0,0,0,0);
	gp2x_video_color8(1,0,0,0);

	/* remaining palette */
	for (i=2;i<255;i++) {
		b=255-i;
		g=0;
		r=0;
		c=0;
		gp2x_video_color8(i,r,g,b);
	}
	gp2x_video_setpalette();
	/* Set Bitmap */	
 #ifdef PSP_RES
	for (y=271;y!=-1;y--) {
		for (x=0;x<480;x++) {
			*out++=(unsigned char)(x/2+3)&254;
		}
	}	
	gp2x_gamelist_text_out_fmt(150,10,"-= Mame4All " VERSION " =-");
	gp2x_gamelist_text_out_fmt(118,20,"Largest memory chunk: %u",check_free_memory());
 #else
	for (y=239;y!=-1;y--) {
		for (x=0;x<320;x++) {
			*out++=(unsigned char)(x/1.25+1)&254;
		}
	}
	gp2x_gamelist_text_out_fmt(66,10,"-= Mame4All " VERSION " =-");
	gp2x_gamelist_text_out_fmt(46,20,"Largest memory chunk: %u",check_free_memory());
 #endif
#endif
#endif
}
Example #9
0
/* Update the display. */
void osd_update_video_and_audio(struct osd_bitmap *bitmap)
{
	static const int waittable[FRAMESKIP_LEVELS][FRAMESKIP_LEVELS] =
	{
		{ 1,1,1,1,1,1,1,1,1,1,1,1 },
		{ 2,1,1,1,1,1,1,1,1,1,1,0 },
		{ 2,1,1,1,1,0,2,1,1,1,1,0 },
		{ 2,1,1,0,2,1,1,0,2,1,1,0 },
		{ 2,1,0,2,1,0,2,1,0,2,1,0 },
		{ 2,0,2,1,0,2,0,2,1,0,2,0 },
		{ 2,0,2,0,2,0,2,0,2,0,2,0 },
		{ 2,0,2,0,0,3,0,2,0,0,3,0 },
		{ 3,0,0,3,0,0,3,0,0,3,0,0 },
		{ 4,0,0,0,4,0,0,0,4,0,0,0 },
		{ 6,0,0,0,0,0,6,0,0,0,0,0 },
		{12,0,0,0,0,0,0,0,0,0,0,0 }
	};
	int i;
	static int showfps,showfpstemp;
	TICKER curr;
	static TICKER prev_measure=0,this_frame_base,prev;
	static int speed = 100;
	static int vups,vfcount;
	int have_to_clear_bitmap = 0;



	if (prev_measure==0 || iOS_exitPause)
	{
		iOS_exitPause = 0;
		/* first time through, initialize timer */
		prev_measure = ticker() - FRAMESKIP_LEVELS * TICKS_PER_SEC/video_fps;
	}

	if (frameskip_counter == 0)
		this_frame_base = prev_measure + FRAMESKIP_LEVELS * TICKS_PER_SEC/video_fps;

	/* update audio */
	msdos_update_audio();

	if (osd_skip_this_frame() == 0)
	{
		if (showfpstemp)
		{
			showfpstemp--;
			if (showfps == 0 && showfpstemp == 0)
			{
				have_to_clear_bitmap = 1;
			}
		}

		if (input_ui_pressed(IPT_UI_SHOW_FPS))
		{
			if (showfpstemp)
			{
				showfpstemp = 0;
				have_to_clear_bitmap = 1;
			}
			else
			{
				showfps ^= 1;
				if (showfps == 0)
				{
					have_to_clear_bitmap = 1;
				}
			}
		}

		/* now wait until it's time to update the screen */
		if (throttle)
		{
			profiler_mark(PROFILER_IDLE);
			if (video_sync)
			{
				static TICKER last;
				do
				{
					vsync();
					curr = ticker();
				} while (TICKS_PER_SEC / (curr - last) > video_fps * 11 /10);
				last = curr;
			}
			else
			{
				TICKER target;
				/* wait for video sync but use normal throttling */
				if (wait_vsync)
					vsync();
				curr = ticker();
				target = this_frame_base + frameskip_counter * TICKS_PER_SEC/video_fps;
				if ((curr < target) && (target-curr<TICKS_PER_SEC))
				{
					do
					{
                        //sched_yield();
						curr = ticker();
					} while ((curr < target) && (target-curr<TICKS_PER_SEC));
				}
			}
			profiler_mark(PROFILER_END);
		}
		else curr = ticker();

		if (frameskip_counter == 0)
		{

			float divdr;
			divdr = (float)((float)((float)(TICKS_PER_SEC) / video_fps) * (float)(FRAMESKIP_LEVELS)) / (float)(curr - prev_measure);
			speed = (int)(divdr * 100.0);
			prev_measure = curr;

			/*
			int divdr;
			divdr = video_fps * (curr - prev_measure) / (100 * FRAMESKIP_LEVELS);
			if (divdr==0)
			    divdr=1;
			speed = (TICKS_PER_SEC + divdr/2) / divdr;
			prev_measure = curr;
			*/
		}

		prev = curr;

		vfcount += waittable[frameskip][frameskip_counter];
		if (vfcount >= video_fps)
		{
			extern int vector_updates; /* avgdvg_go_w()'s per Mame frame, should be 1 */
			vfcount = 0;
			vups = vector_updates;
			vector_updates = 0;
		}

		if (global_fps || showfps || showfpstemp)
		{
			int fps;
			char buf[30];
			int divdr;
			divdr = 100 * FRAMESKIP_LEVELS;
			fps = (video_fps * (FRAMESKIP_LEVELS - frameskip) * speed + (divdr / 2)) / divdr;
			sprintf(buf,"%s%2d%4d%%%4d/%d fps",autoframeskip?"auto":"fskp",frameskip,speed,fps,(int)(video_fps+0.5));
			ui_text(bitmap,buf,Machine->uiwidth-strlen(buf)*Machine->uifontwidth,0);
			if (vector_game)
			{
				sprintf(buf," %d vector updates",vups);
				ui_text(bitmap,buf,Machine->uiwidth-strlen(buf)*Machine->uifontwidth,Machine->uifontheight);
			}
		}

		if (bitmap->depth == 8)
		{
			if (dirty_bright)
			{
				dirty_bright = 0;
				for (i = 0;i < 256;i++)
				{
					float rate = brightness * brightness_paused_adjust * pow(i / 255.0, 1 / osd_gamma_correction) / 100;
					bright_lookup[i] = 255 * rate + 0.5;
				}
			}
			if (dirtypalette)
			{
				dirtypalette = 0;
				for (i = 0;i < screen_colors;i++)
				{
					if (dirtycolor[i])
					{
						unsigned char r,g,b;
						
						dirtycolor[i] = 0;

						r = current_palette[3*i+0];
						g = current_palette[3*i+1];
						b = current_palette[3*i+2];
						if (i != Machine->uifont->colortable[1])	/* don't adjust the user interface text */
						{
							r = bright_lookup[r];
							g = bright_lookup[g];
							b = bright_lookup[b];
						}
						gp2x_video_color8(i,r,g,b);
					}
				}
				gp2x_video_setpalette();
			}
		}
		else
		{
			if (dirty_bright)
			{
				dirty_bright = 0;
				for (i = 0;i < 256;i++)
				{
					float rate = brightness * brightness_paused_adjust * pow(i / 255.0, 1 / osd_gamma_correction) / 100;
					bright_lookup[i] = 255 * rate + 0.5;
				}
			}
			if (dirtypalette)
			{
				if (use_dirty) init_dirty(1);	/* have to redraw the whole screen */

				dirtypalette = 0;
				for (i = 0;i < screen_colors;i++)
				{
					if (dirtycolor[i])
					{
						int r,g,b;

						dirtycolor[i] = 0;

						r = current_palette[3*i+0];
						g = current_palette[3*i+1];
						b = current_palette[3*i+2];
						if (i != Machine->uifont->colortable[1])	/* don't adjust the user interface text */
						{
							r = bright_lookup[r];
							g = bright_lookup[g];
							b = bright_lookup[b];
						}
						palette_16bit_lookup[i] = makecol(r,g,b);
					}
				}
			}
		}

		/* copy the bitmap to screen memory */
		profiler_mark(PROFILER_BLIT);
		update_screen(bitmap);
		profiler_mark(PROFILER_END);

		if (have_to_clear_bitmap)
			osd_clearbitmap(bitmap);

		if (use_dirty)
		{
			if (!vector_game)
				swap_dirty();
			init_dirty(0);
		}

		if (have_to_clear_bitmap)
			osd_clearbitmap(bitmap);

		if (throttle && autoframeskip && frameskip_counter == 0)
		{
			static int frameskipadjust/* = 0*/;
			int adjspeed;

			/* adjust speed to video refresh rate if vsync is on */
			adjspeed = speed * video_fps / vsync_frame_rate;

			if (adjspeed >= 100 /*92*/)
			{
				frameskipadjust++;
				if (frameskipadjust >= 3)
				{
					frameskipadjust = 0;
#ifdef GP2X
					{	
						extern int gp2x_pal_50hz;
						if ((gp2x_pal_50hz) && (video_fps>50))
						{ 
							if (frameskip>2)
								frameskip--;
						}
						else if (frameskip > 0)
							frameskip--;
					}
#else
					if (frameskip > 0) frameskip--;
#endif
				}
			}
			else
			{
				if (adjspeed < 80)
				{
					frameskipadjust -= (90 - adjspeed) / 5;
				}
				else
				{
					/* don't push frameskip too far if we are close to 100% speed */
					if (frameskip < 8)
						frameskipadjust--;
				}
				
				while (frameskipadjust <= -2)
				{
					frameskipadjust += 2;
//#ifdef GP2X
//					if (frameskip < 7) frameskip++;
//#else
					if (frameskip < FRAMESKIP_LEVELS-1) frameskip++;
//#endif
				}
			}
		}
	}

	/* Check for PGUP, PGDN and pan screen */
	pan_display();

	if (input_ui_pressed(IPT_UI_FRAMESKIP_INC))
	{
		if (autoframeskip)
		{
			autoframeskip = 0;
			frameskip = 0;
		}
		else
		{
			if (frameskip == FRAMESKIP_LEVELS-1)
			{
				frameskip = 0;
				autoframeskip = 1;
			}
			else
				frameskip++;
		}

		if (showfps == 0)
			showfpstemp = 2*video_fps;
	}

	if (input_ui_pressed(IPT_UI_FRAMESKIP_DEC))
	{
		if (autoframeskip)
		{
			autoframeskip = 0;
			frameskip = FRAMESKIP_LEVELS-1;
		}
		else
		{
			if (frameskip == 0)
				autoframeskip = 1;
			else
				frameskip--;
		}

		if (showfps == 0)
			showfpstemp = 2*video_fps;
	}

	if (input_ui_pressed(IPT_UI_THROTTLE))
	{
		throttle ^= 1;
	}

	frameskip_counter = (frameskip_counter + 1) % FRAMESKIP_LEVELS;
}
Example #10
0
static void vid_reset_mode(void)
{
	int gp2x_mode = 16;
	int renderer = get_renderer();

	PicoOpt &= ~POPT_ALT_RENDERER;
	emu_scan_begin = NULL;
	emu_scan_end = NULL;

	switch (renderer) {
	case RT_16BIT:
		PicoDrawSetOutFormat(PDF_RGB555, 0);
		PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);
		break;
	case RT_8BIT_ACC:
		PicoDrawSetOutFormat(PDF_8BIT, 0);
		PicoDrawSetOutBuf(g_screen_ptr, g_screen_width);
		gp2x_mode = 8;
		break;
	case RT_8BIT_FAST:
		PicoOpt |= POPT_ALT_RENDERER;
		PicoDrawSetOutFormat(PDF_NONE, 0);
		vidcpyM2 = vidcpy_m2;
		gp2x_mode = 8;
		break;
	default:
		printf("bad renderer\n");
		break;
	}

	if (PicoAHW & PAHW_32X) {
		// Wiz 16bit is an exception, uses line rendering due to rotation mess
		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;
	}

	if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) {
		if ((PicoAHW & PAHW_32X) || renderer == RT_16BIT) {
			emu_scan_begin = EmuScanBegin16_rot;
			emu_scan_end = EmuScanEnd16_rot;
		}
		else if (renderer == RT_8BIT_ACC) {
			emu_scan_begin = EmuScanBegin8_rot;
			emu_scan_end = EmuScanEnd8_rot;
		}
		else if (renderer == RT_8BIT_FAST)
			vidcpyM2 = vidcpy_m2_rot;
	}

	PicoDrawSetCallbacks(emu_scan_begin, emu_scan_end);

	if (is_16bit_mode())
		osd_text = (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) ? osd_text16_rot : emu_osd_text16;
	else
		osd_text = (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) ? osd_text8_rot : osd_text8;

	gp2x_video_wait_vsync();
	if (!is_16bit_mode()) {
		// setup pal for 8-bit modes
		localPal[0xc0] = 0x0000c000; // MCD LEDs
		localPal[0xd0] = 0x00c00000;
		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;

	gp2x_video_changemode(gp2x_mode, Pico.m.pal);

	Pico.m.dirtyPal = 1;

	PicoOpt &= ~POPT_EN_SOFTSCALE;
	if (currentConfig.scaling == EOPT_SCALE_SW)
		PicoOpt |= POPT_EN_SOFTSCALE;

	// palette converters for 8bit modes
	make_local_pal = (PicoAHW & PAHW_SMS) ? make_local_pal_sms : make_local_pal_md;
}