/* Variadic functions guide found at http://www.unixpapa.com/incnote/variadic.html */ void gp2x_printf(char* fmt, ...) { int i,c; char strOut[4096]; char str[41]; va_list marker; va_start(marker, fmt); vsprintf(strOut, fmt, marker); va_end(marker); fprintf(stderr, "%s\n", strOut); c=0; for (i=0;i<strlen(strOut);i++) { str[c]=strOut[i]; if (str[c]=='\n') { str[c]=0; gp2x_text_log(str); c=0; } else if (c==39) { str[40]=0; gp2x_text_log(str); c=0; } else { c++; } } }
/* initialization was successful, nonzero otherwise. */ int osd_init(void) { #ifdef GP2X gp2x_text_log("GP2X Port Init..."); #endif if (msdos_init_sound()) return 1; msdos_init_input(); return 0; }
/* Variadic functions guide found at http://www.unixpapa.com/incnote/variadic.html */ void gp2x_printf(char* fmt, ...) { int i,c; char strOut[4096]; char str[41]; va_list marker; va_start(marker, fmt); vsprintf(strOut, fmt, marker); va_end(marker); gp2x_frontend_init(); c=0; for (i=0;i<strlen(strOut);i++) { str[c]=strOut[i]; if (str[c]=='\n') { str[c]=0; gp2x_text_log(str); c=0; } else if (c==39) { str[40]=0; gp2x_text_log(str); c=0; } else { c++; } } FE_DisplayScreen(); sleep(6); gp2x_frontend_deinit(); pflog=0; }
/* Variadic functions guide found at http://www.unixpapa.com/incnote/variadic.html */ void gp2x_text_log_fmt(char* fmt, ...) { char strOut[128]; va_list marker; va_start(marker, fmt); vsprintf(strOut, fmt, marker); va_end(marker); gp2x_text_log(strOut); }
/* routines don't clip at boundaries of the bitmap. */ struct osd_bitmap *osd_new_bitmap(int width,int height,int depth) /* ASG 980209 */ { struct osd_bitmap *bitmap; if (Machine->orientation & ORIENTATION_SWAP_XY) { int temp; temp = width; width = height; height = temp; } if ((bitmap = (struct osd_bitmap*)gp2x_malloc(sizeof(struct osd_bitmap))) != 0) { int i,rowlen,rdwidth; unsigned char *bm; int safety; if (width > 32) safety = 8; else safety = 0; /* don't create the safety area for GfxElement bitmaps */ if (depth != 8 && depth != 16) depth = 8; bitmap->depth = depth; bitmap->width = width; bitmap->height = height; rdwidth = (width + 7) & ~7; /* round width to a quadword */ if (depth == 16) rowlen = 2 * (rdwidth + 2 * safety) * sizeof(unsigned char); else rowlen = (rdwidth + 2 * safety) * sizeof(unsigned char); if (!(bitmap->_private = gp2x_malloc((height + 2 * safety) * rowlen))) { #ifndef DREAMCAST gp2x_text_log("osd_new_bitmap(): Out of Memory"); gp2x_free(bitmap); #endif return 0; } bm = (unsigned char*)bitmap->_private; fast_memset(bm,0,(height + 2 * safety) * rowlen); if (!(bitmap->line = (unsigned char**)gp2x_malloc(height * sizeof(unsigned char *)))) { #ifndef DREAMCAST gp2x_text_log("osd_new_bitmap(): Out of Memory"); gp2x_free(bm); gp2x_free(bitmap); #endif return 0; } for (i = 0;i < height;i++) bitmap->line[i] = &bm[(i + safety) * rowlen + safety]; } #ifndef DREAMCAST if(!bitmap) gp2x_text_log("osd_new_bitmap(): Out of Memory"); #endif return bitmap; }
int main(int argc,char **argv) { #ifdef PSP pspDebugScreenInit(); #ifdef PSP_USERMODE SetupCallbacks(); #endif #ifdef WIFI net_io_init(); #endif #endif char text[64]; int res, i, game_index; /* GP2X Video Init */ gp2x_video_init(); #ifdef GP2X { /* Border TV-Out */ #define BORDERTVOUTSTRUCTURE "--border_tvout %d --border_tvout_width %d --border_tvout_height %d" extern char gp2x_path_mame[24]; extern int gp2x_bordertvout; extern int gp2x_bordertvout_width; extern int gp2x_bordertvout_height; char name[256]; FILE *f; sprintf(name,"%scfg/mame_tvout.cfg",gp2x_path_mame); f=fopen(name,"rb"); if (f) { fscanf(f,BORDERTVOUTSTRUCTURE,&gp2x_bordertvout,&gp2x_bordertvout_width,&gp2x_bordertvout_height); fclose(f); if (gp2x_bordertvout) { printf("Border TV-Out Activated\r\n"); } else { printf("Border TV-Out Disabled\r\n"); } } } #endif /* Set Video Mode */ #ifdef PSP_RES SetVideoScaling(480,480,272); #else SetVideoScaling(320,320,240); #endif #ifdef GP2X /* Zaq121 07/05/2006 Alternative frontend support -> */ /* Check for command line arguments */ parse_cmdline (argc, argv, &options, game_index); if (no_selector==0) /* <- end mod */ #endif /* Intro screen */ gp2x_intro_screen(); /* Initialize Game Listings */ game_list_init(); while(1) { #ifdef GP2X /* Disable Scaling / Stretching */ { extern int gp2x_text_width; gp2x_text_width=320; } SetVideoScaling(320,320,240); gp2x_rotate=0; /* Mute Sound */ gp2x_sound_thread_mute(); #endif #ifdef GP2X /* Zaq121 07/05/2006 Alternative frontend support -> */ if (no_selector==0) /* <- end mod */ #endif /* Select Game */ select_game(playgame); #ifdef GP2X /* Zaq121 07/05/2006 Alternative frontend support -> */ else { extern int gp2x_freq; /* 9/5/06 Zaq, clock speed was never getting set */ int show_options(char *game); int set_last_game_selected(char *game); if(set_last_game_selected(playgame) == -1) break; /* game not available */ if(!show_options(playgame)) break; /* return back to external menu */ SetGP2XClock(gp2x_freq); /* 9/5/06 Zaq, clock speed was never getting set */ } /* <- end mod */ #endif /* Initialize the audio library */ msdos_init_seal(); /* Restore MAME Palette */ gp2x_mame_palette(); /* Set Log Messages start at row 0 */ gp2x_gamelist_zero(); /* Single Video Buffer for Log Messages */ gp2x_clear_screen(); game_index = -1; /* do we have a driver for this? */ for (i = 0; drivers[i] && (game_index == -1); i++) { if (strcasecmp(playgame,drivers[i]->name) == 0) { game_index = i; break; } } if (game_index == -1) { sprintf(text,"Game \"%s\" not supported\0",playgame); gp2x_text_log(text); while(1); /* MAME never ends xD */ } /* parse generic (os-independent) options */ parse_cmdline (argc, argv, &options, game_index); { /* Mish: I need sample rate initialised _before_ rom loading for optional rom regions */ extern int soundcard; if (soundcard == 0) { /* silence, this would be -1 if unknown in which case all roms are loaded */ Machine->sample_rate = 0; /* update the Machine structure to show that sound is disabled */ options.samplerate=0; } } sprintf(text,"Loading \"%s\"...",drivers[game_index]->description); gp2x_text_log(text); /* go for it */ filecache_init(); res = run_game (game_index , &options); #if !defined(GP2X) && defined(USE_FILECACHE) if ( res != 0) { gp2x_text_log("Retrying without filecache..."); filecache_disable(); res = run_game (game_index , &options); } #endif /* Error? */ if( res != 0 ) { #ifdef PSP gp2x_text_log("LOAD FAILED: Press [] button..."); #else gp2x_text_log("LOAD FAILED: Press A button..."); #endif while (!(gp2x_joystick_read()&GP2X_A)); while ((gp2x_joystick_read()&GP2X_A)); } #ifdef GP2X /* Zaq121 07/05/2006 Alternative frontend support -> */ if(no_selector) break; /* <- end mod */ #endif } /* MAME never ends xD */ }