Ir ao conteúdo
  • Cadastre-se

rogério dos santos araujo

Membro Júnior
  • Posts

    19
  • Cadastrado em

  • Última visita

Tudo que rogério dos santos araujo postou

  1. tenho um problema eu preciso que quando eu aumente o valor do multiplicador para 2 ou mais o contador só aumente o numero de acordo com o valor escolhido exemplo se eu mudar o multiplicador para 2 o contador só aumente 1 numero se eu colocar 2 creditos se mudar para 3 so aumente um numero do contador se colocar 3 creditos e assim sucessivamente int RetFichas=0,Fichas=0,Fichass=0, Contador2=0, Contador3=0; int Contador=0; int Multiplica=0; //BY GD int Multiplicador=0; //BY GD char bufferFicha[100]; char bufferpremio[100]; char bufferContador[100]; char bufferContador2[100]; char bufferContador3[100];// gero char PegaCreditoPF[100]; char PegaFicha[100]; char PegaBloqueado[100]; char buffermultiplica[100]; char sai_premio[100]; char valor_premio[100]; //PEGA O VALOR DA FICHA GetPrivateProfileStringA("configuração","valor_premio","0",valor_premio, 100, ini_cim.c_str()); GetPrivateProfileStringA("configuração","TEMPOPORFICHA","0",PegaFicha, 100, ini_cim.c_str()); ValorDaFicha=atoi(PegaFicha); //PEGA O CREDITO POR FICHA GetPrivateProfileStringA("configuração","CREDITOPF", "1", PegaCreditoPF, 100, ini_cim.c_str()); CreditoPorFicha=atoi(PegaCreditoPF); //PEGA CONTADOR GERAL GetPrivateProfileStringA("FICHEIRO","CONTADOR" ,"0", bufferContador, 100, ini_cim.c_str()); Contador = atoi(bufferContador); GetPrivateProfileStringA("FICHEIRO","CONTADOR_FIXO" ,"0", bufferContador2, 100, ini_cim.c_str()); Contador2 = atoi(bufferContador2); GetPrivateProfileStringA("FICHEIRO","comparador" ,"0", bufferContador3, 100, ini_cim.c_str());// gero Contador3 = atoi(bufferContador3); //quantidade de premio GetPrivateProfileStringA("configuração","fichas_premio", "0", sai_premio, 100, ini_cim.c_str()); //PEGA A QUANTIDADE DE FICHAS RetFichas = GetPrivateProfileStringA("FICHEIRO","FICHAS","0", bufferFicha, 100, ini_cim.c_str()); Fichas = atoi(bufferFicha); Multiplica = GetPrivateProfileStringA("FICHEIRO","MULTIPLICADOR","0", buffermultiplica, 100, ini_cim.c_str()); //BY GD Multiplicador = atoi(buffermultiplica); //BY GD cont=0; counter=0; Contador+=1;//PRECISO ALTERAR AQUI Contador2+=1; Contador3+=1;// gero Fichas+=(ValorDaFicha/Multiplicador)*CreditoPorFicha; //BY GD //Fichas+=ValorDaFicha*CreditoPorFicha; sprintf(bufferFicha,"%d",Fichas); if(Fichas !=0 ){ WritePrivateProfileStringA("FICHEIRO","FICHAS", bufferFicha,ini_cim.c_str()); }else{ WritePrivateProfileStringA("FICHEIRO","FICHAS", "0", ini_cim.c_str()); } sprintf(bufferContador, "%d", Contador); WritePrivateProfileStringA("FICHEIRO","CONTADOR", bufferContador, ini_cim.c_str()); sprintf(bufferContador2, "%d", Contador2); WritePrivateProfileStringA("FICHEIRO","CONTADOR_FIXO", bufferContador2, ini_cim.c_str());// andre ourives if(SOM_PERSONALIZADO == "ligado"){ sndPlaySoundA(SOM_COIN.c_str() , SND_ASYNC || SND_NODEFAULT ); }else{ sndPlaySoundA(".\\auxiliar\\som\\coin.wav" , SND_ASYNC || SND_NODEFAULT ); }
  2. tenho uma duvida uso esse relogio mas ele não atualiza os segundos alguém pode ajudar? if (tag_info == "relogio") { ostringstream os; int desliga=0; char buffer [80]; time_t rawtime; struct tm * timeinfo; time (&rawtime); timeinfo = localtime (&rawtime); strftime (buffer,80,"%H:%M:%S",timeinfo); puts (buffer); os <<buffer; info_tag = os.str(); }else{ info_tag = " "; }
  3. boa tarde estou com essa dificuldade preciso desse codigo em c++ para um peojeto mas meu conhecimento nessa linguagem é muito limitado mesmo preciso de ajuda Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\PsxPortEnumerator] "Type"=dword:00000001 "Start"=dword:00000003 "ErrorControl"=dword:00000000 "ImagePath"=hex(2):53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,44,00,\ 72,00,69,00,76,00,65,00,72,00,73,00,5c,00,70,00,73,00,78,00,65,00,6e,00,75,\ 00,6d,00,2e,00,73,00,79,00,73,00,00,00 "DisplayName"="Psx Port Enumerator" [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\PsxPortEnumerator\Enum] "0"="Root\\MEDIA\\0000" "Count"=dword:00000001 "NextInstance"=dword:00000001 [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\PsxPortEnumerator\Parameters] "PortType"=dword:00000020 "MaxPort"=dword:00000003 "ParallelIoAddress"=dword:00000378 "TimingCmdToCmd"=dword:00000000 "ClockTime"=dword:00000002 "TimingSelToClk"=dword:00000000 "TimingAckTimeOut"=dword:00000000 "TimingAckToClk"=dword:00000000 "PadEnumTimeOut"=dword:00000002 esse codigo acima é um registro do windows preciso transformar ele em codigo c++ quem puder ajudar eu agradeço
  4. boa tarde estou com essa dificuldade preciso desse codigo em c++ para um peojeto mas meu conhecimento nessa linguagem é muito limitado mesmo preciso de ajuda Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\PsxPortEnumerator] "Type"=dword:00000001 "Start"=dword:00000003 "ErrorControl"=dword:00000000 "ImagePath"=hex(2):53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,44,00,\ 72,00,69,00,76,00,65,00,72,00,73,00,5c,00,70,00,73,00,78,00,65,00,6e,00,75,\ 00,6d,00,2e,00,73,00,79,00,73,00,00,00 "DisplayName"="Psx Port Enumerator" [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\PsxPortEnumerator\Enum] "0"="Root\\MEDIA\\0000" "Count"=dword:00000001 "NextInstance"=dword:00000001 [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\PsxPortEnumerator\Parameters] "PortType"=dword:00000020 "MaxPort"=dword:00000003 "ParallelIoAddress"=dword:00000378 "TimingCmdToCmd"=dword:00000000 "ClockTime"=dword:00000002 "TimingSelToClk"=dword:00000000 "TimingAckTimeOut"=dword:00000000 "TimingAckToClk"=dword:00000000 "PadEnumTimeOut"=dword:00000002 esse codigo acima é um registro do windows preciso transformar ele em codigo c++ quem puder ajudar eu agradeço
  5. bom dia ten ho muito pouco conhecimento em c++ estou fazendo um registro para instalar um programa diretamente pelo registro em autoit ei fiz funcionar mas em c++ preciso de ajuda tentei fazer dessa forma mas da erro ao compilar #define JAMMA_CHOICE_DX 28*int_font_dx_get() int run_JAMMA(config_state& rs) { choice_bag ch; ch.insert(ch.end(), choice("MODO instala", 1)); ch.insert(ch.end(), choice("MODO desinstala", 2)); ch.insert(ch.end(), choice("SAIR", 3)); choice_bag::iterator i = ch.begin(); int key = ch.run(string(" ") + "SELECIONE O MODO", (int_dx_get() - JAMMA_CHOICE_DX) / 10, int_dy_get() /5 , JAMMA_CHOICE_DX, i); if (key == EVENT_ENTER) { int r; if (i->value_get()>=-1 && i->value_get()<=256) { switch (i->value_get()) { case 1 : HKEY hk; DWORD disp; RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SYSTEM\\ControlSet001\\Control\\Class\\{745A17A0-74D3-11D0-B6FE-00A0C90F57DA}\\0001", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,&hk, &disp ); RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SYSTEM\\ControlSet001\\Control\\Class\\{745A17A0-74D3-11D0-B6FE-00A0C90F57DA}\\0003", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,&hk, &disp ); RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SYSTEM\\ControlSet001\\Control\\Class\\{745A17A0-74D3-11D0-B6FE-00A0C90F57DA}\\0005", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,&hk, &disp ); RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SYSTEM\\ControlSet001\\Control\\Class\\{91AA9096-81E9-4366-9598-1BF416D0B342}\\InProcServer32", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,&hk, &disp ); RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SYSTEM\\ControlSet001\\Control\\Class\\{91AA9096-81E9-4366-9598-1BF416D0B342}", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,&hk, &disp ); RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SYSTEM\\ControlSet001\\Control\\Class\\{96B345D8-12F9-4a41-A4D3-CE45B551EA47}\\InProcServer32", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,&hk, &disp ); RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SYSTEM\\ControlSet001\\Control\\Class\\{96B345D8-12F9-4a41-A4D3-CE45B551EA47}\\0063", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,&hk, &disp ); RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SYSTEM\\ControlSet001\\Control\\Class\\{96B345D8-12F9-4a41-A4D3-CE45B551EA47}\\0064", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,&hk, &disp ); RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SYSTEM\\ControlSet001\\Control\\Class\\{96B345D8-12F9-4a41-A4D3-CE45B551EA47}\\0065", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,&hk, &disp ); RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SYSTEM\\ControlSet001\\Control\\Class\\{96B345D8-12F9-4a41-A4D3-CE45B551EA47}\\0069", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,&hk, &disp ); RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SYSTEM\\ControlSet001\\Control\\Class\\{96B345D8-12F9-4a41-A4D3-CE45B551EA47}\\0070", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,&hk, &disp ); RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SYSTEM\\ControlSet001\\Control\\Class\\{96B345D8-12F9-4a41-A4D3-CE45B551EA47}\\0071", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,&hk, &disp ); sndPlaySoundA( ".\\auxiliar\\som\\salvadados.wav", SND_ASYNC || SND_NODEFAULT ); system ("shutdown -r -t 0"); break; case 2 : // ainda falta comando sndPlaySoundA( ".\\auxiliar\\som\\salvadados.wav", SND_ASYNC || SND_NODEFAULT ); r = 0; system ("shutdown -r -t 0"); } } } return key; } primeiro estou testando a parte de adicionar o registro depois vou para a parte de remover ele por favor quem puder ajudar com a explicação fico grato
  6. bom dia o post foi meu mas ja foi resolvido ha tempos e como ninguém tinha respondido eu ja tinha até esquecido disso se o admin puder pode apagar esse post
  7. boa noite amigos eu praticamente não tenho conhecimento em c++ mas preciso fazer uma modificação para fazer o mame gravar videos.mng ja com audio dentro da pasta snap eu achei a parte do codigo responsável por isso mas não sei por onde começar /*************************************************************************** video.c Core MAME video routines. Copyright Nicola Salmoria and the MAME Team. Visit http://mamedev.org for licensing and usage restrictions. ***************************************************************************/ #include "driver.h" #include "profiler.h" #include "png.h" #include "debugger.h" #include "rendutil.h" #include "ui.h" #include "aviio.h" #include "deprecat.h" #include "snap.lh" /*************************************************************************** DEBUGGING ***************************************************************************/ #define LOG_THROTTLE (0) #define VERBOSE (0) #define LOG_PARTIAL_UPDATES(x) do { if (VERBOSE) logerror x; } while (0) /*************************************************************************** CONSTANTS ***************************************************************************/ #define SUBSECONDS_PER_SPEED_UPDATE (ATTOSECONDS_PER_SECOND / 4) #define PAUSED_REFRESH_RATE (30) #define MAX_VBLANK_CALLBACKS (10) #define DEFAULT_FRAME_RATE 60 #define DEFAULT_FRAME_PERIOD ATTOTIME_IN_HZ(DEFAULT_FRAME_RATE) /*************************************************************************** TYPE DEFINITIONS ***************************************************************************/ typedef struct _screen_state screen_state; struct _screen_state { /* dimensions */ int width; /* current width (HTOTAL) */ int height; /* current height (VTOTAL) */ rectangle visarea; /* current visible area (HBLANK end/start, VBLANK end/start) */ /* textures and bitmaps */ render_texture * texture[2]; /* 2x textures for the screen bitmap */ bitmap_t * bitmap[2]; /* 2x bitmaps for rendering */ UINT8 curbitmap; /* current bitmap index */ UINT8 curtexture; /* current texture index */ INT32 texture_format; /* texture format of bitmap for this screen */ UINT8 changed; /* has this bitmap changed? */ INT32 last_partial_scan; /* scanline of last partial update */ /* screen timing */ attoseconds_t frame_period; /* attoseconds per frame */ attoseconds_t scantime; /* attoseconds per scanline */ attoseconds_t pixeltime; /* attoseconds per pixel */ attoseconds_t vblank_period; /* attoseconds per VBLANK period */ attotime vblank_start_time; /* time of last VBLANK start */ attotime vblank_end_time; /* time of last VBLANK end */ emu_timer * vblank_begin_timer; /* timer to signal VBLANK start */ emu_timer * vblank_end_timer; /* timer to signal VBLANK end */ emu_timer * scanline0_timer; /* scanline 0 timer */ emu_timer * scanline_timer; /* scanline timer */ UINT64 frame_number; /* the current frame number */ /* screen specific VBLANK callbacks */ vblank_state_changed_func vblank_callback[MAX_VBLANK_CALLBACKS]; /* the array of callbacks */ void * vblank_callback_param[MAX_VBLANK_CALLBACKS]; /* array of parameters */ }; typedef struct _video_global video_global; struct _video_global { /* screenless systems */ emu_timer * screenless_frame_timer; /* timer to signal VBLANK start */ /* throttling calculations */ osd_ticks_t throttle_last_ticks; /* osd_ticks the last call to throttle */ attotime throttle_realtime; /* real time the last call to throttle */ attotime throttle_emutime; /* emulated time the last call to throttle */ UINT32 throttle_history; /* history of frames where we were fast enough */ /* dynamic speed computation */ osd_ticks_t speed_last_realtime; /* real time at the last speed calculation */ attotime speed_last_emutime; /* emulated time at the last speed calculation */ double speed_percent; /* most recent speed percentage */ UINT32 partial_updates_this_frame;/* partial update counter this frame */ /* overall speed computation */ UINT32 overall_real_seconds; /* accumulated real seconds at normal speed */ osd_ticks_t overall_real_ticks; /* accumulated real ticks at normal speed */ attotime overall_emutime; /* accumulated emulated time at normal speed */ UINT32 overall_valid_counter; /* number of consecutive valid time periods */ /* configuration */ UINT8 throttle; /* flag: TRUE if we're currently throttled */ UINT8 fastforward; /* flag: TRUE if we're currently fast-forwarding */ UINT32 seconds_to_run; /* number of seconds to run before quitting */ UINT8 auto_frameskip; /* flag: TRUE if we're automatically frameskipping */ UINT32 speed; /* overall speed (*100) */ /* frameskipping */ UINT8 empty_skip_count; /* number of empty frames we have skipped */ UINT8 frameskip_level; /* current frameskip level */ UINT8 frameskip_counter; /* counter that counts through the frameskip steps */ INT8 frameskip_adjust; UINT8 skipping_this_frame; /* flag: TRUE if we are skipping the current frame */ osd_ticks_t average_oversleep; /* average number of ticks the OSD oversleeps */ /* snapshot stuff */ render_target * snap_target; /* screen shapshot target */ bitmap_t * snap_bitmap; /* screen snapshot bitmap */ UINT8 snap_native; /* are we using native per-screen layouts? */ INT32 snap_width; /* width of snapshots (0 == auto) */ INT32 snap_height; /* height of snapshots (0 == auto) */ /* movie recording */ mame_file * mngfile; /* handle to the open movie file */ avi_file * avifile; /* handle to the open movie file */ attotime movie_frame_period; /* period of a single movie frame */ attotime movie_next_frame_time; /* time of next frame */ UINT32 movie_frame; /* current movie frame number */ }; /*************************************************************************** GLOBAL VARIABLES ***************************************************************************/ /* global state */ static video_global global; /* frameskipping tables */ static const UINT8 skiptable[FRAMESKIP_LEVELS][FRAMESKIP_LEVELS] = { { 0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,1 }, { 0,0,0,0,0,1,0,0,0,0,0,1 }, { 0,0,0,1,0,0,0,1,0,0,0,1 }, { 0,0,1,0,0,1,0,0,1,0,0,1 }, { 0,1,0,0,1,0,1,0,0,1,0,1 }, { 0,1,0,1,0,1,0,1,0,1,0,1 }, { 0,1,0,1,1,0,1,0,1,1,0,1 }, { 0,1,1,0,1,1,0,1,1,0,1,1 }, { 0,1,1,1,0,1,1,1,0,1,1,1 }, { 0,1,1,1,1,1,0,1,1,1,1,1 }, { 0,1,1,1,1,1,1,1,1,1,1,1 } }; /*************************************************************************** FUNCTION PROTOTYPES ***************************************************************************/ /* core implementation */ static void video_exit(running_machine *machine); static void init_buffered_spriteram(running_machine *machine); /* graphics decoding */ static void allocate_graphics(running_machine *machine, const gfx_decode_entry *gfxdecodeinfo); static void decode_graphics(running_machine *machine, const gfx_decode_entry *gfxdecodeinfo); static void realloc_screen_bitmaps(const device_config *screen); static STATE_POSTLOAD( video_screen_postload ); /* global rendering */ static TIMER_CALLBACK( vblank_begin_callback ); static TIMER_CALLBACK( vblank_end_callback ); static TIMER_CALLBACK( screenless_update_callback ); static TIMER_CALLBACK( scanline0_callback ); static TIMER_CALLBACK( scanline_update_callback ); static int finish_screen_updates(running_machine *machine); /* throttling/frameskipping/performance */ static void update_throttle(running_machine *machine, attotime emutime); static osd_ticks_t throttle_until_ticks(running_machine *machine, osd_ticks_t target_ticks); static void update_frameskip(running_machine *machine); static void recompute_speed(running_machine *machine, attotime emutime); static void update_refresh_speed(running_machine *machine); /* screen snapshots */ static void create_snapshot_bitmap(const device_config *screen); static file_error mame_fopen_next(running_machine *machine, const char *pathoption, const char *extension, mame_file **file); /* movie recording */ static void video_mng_record_frame(running_machine *machine); static void video_avi_record_frame(running_machine *machine); /* software rendering */ static void rgb888_draw_primitives(const render_primitive *primlist, void *dstdata, UINT32 width, UINT32 height, UINT32 pitch); /*************************************************************************** INLINE FUNCTIONS ***************************************************************************/ /*------------------------------------------------- get_safe_token - makes sure that the passed in device is, in fact, a screen -------------------------------------------------*/ INLINE screen_state *get_safe_token(const device_config *device) { assert(device != NULL); assert(device->token != NULL); assert(device->type == VIDEO_SCREEN); return (screen_state *)device->token; } /*------------------------------------------------- effective_autoframeskip - return the effective autoframeskip value, accounting for fast forward -------------------------------------------------*/ INLINE int effective_autoframeskip(running_machine *machine) { /* if we're fast forwarding or paused, autoframeskip is disabled */ if (global.fastforward || mame_is_paused(machine)) return FALSE; /* otherwise, it's up to the user */ return global.auto_frameskip; } /*------------------------------------------------- effective_frameskip - return the effective frameskip value, accounting for fast forward -------------------------------------------------*/ INLINE int effective_frameskip(void) { /* if we're fast forwarding, use the maximum frameskip */ if (global.fastforward) return FRAMESKIP_LEVELS - 1; /* otherwise, it's up to the user */ return global.frameskip_level; } /*------------------------------------------------- effective_throttle - return the effective throttle value, accounting for fast forward and user interface -------------------------------------------------*/ INLINE int effective_throttle(running_machine *machine) { /* if we're paused, or if the UI is active, we always throttle */ if (mame_is_paused(machine) || ui_is_menu_active()) return TRUE; /* if we're fast forwarding, we don't throttle */ if (global.fastforward) return FALSE; /* otherwise, it's up to the user */ return global.throttle; } /*------------------------------------------------- original_speed_setting - return the original speed setting -------------------------------------------------*/ INLINE int original_speed_setting(void) { return options_get_float(mame_options(), OPTION_SPEED) * 100.0 + 0.5; } /*************************************************************************** CORE IMPLEMENTATION ***************************************************************************/ /*------------------------------------------------- video_init - start up the video system -------------------------------------------------*/ void video_init(running_machine *machine) { const char *filename; const char *viewname; /* validate */ assert(machine != NULL); assert(machine->config != NULL); /* request a callback upon exiting */ add_exit_callback(machine, video_exit); /* reset our global state */ memset(&global, 0, sizeof(global)); global.speed_percent = 1.0; /* extract initial execution state from global configuration settings */ global.speed = original_speed_setting(); update_refresh_speed(machine); global.throttle = options_get_bool(mame_options(), OPTION_THROTTLE); global.auto_frameskip = options_get_bool(mame_options(), OPTION_AUTOFRAMESKIP); global.frameskip_level = options_get_int(mame_options(), OPTION_FRAMESKIP); global.seconds_to_run = options_get_int(mame_options(), OPTION_SECONDS_TO_RUN); /* create spriteram buffers if necessary */ if (machine->config->video_attributes & VIDEO_BUFFERS_SPRITERAM) init_buffered_spriteram(machine); /* convert the gfx ROMs into character sets. This is done BEFORE calling the driver's */ /* palette_init() routine because it might need to check the machine->gfx[] data */ if (machine->config->gfxdecodeinfo != NULL) allocate_graphics(machine, machine->config->gfxdecodeinfo); /* call the PALETTE_INIT function */ if (machine->config->init_palette != NULL) (*machine->config->init_palette)(machine, memory_region(machine, "proms")); /* actually decode the graphics */ if (PREDECODE_GFX && machine->config->gfxdecodeinfo != NULL) decode_graphics(machine, machine->config->gfxdecodeinfo); /* create a render target for snapshots */ viewname = options_get_string(mame_options(), OPTION_SNAPVIEW); global.snap_native = (machine->primary_screen != NULL && (viewname[0] == 0 || strcmp(viewname, "native") == 0)); /* the native target is hard-coded to our internal layout and has all options disabled */ if (global.snap_native) { global.snap_target = render_target_alloc(machine, layout_snap, RENDER_CREATE_SINGLE_FILE | RENDER_CREATE_HIDDEN); assert(global.snap_target != NULL); render_target_set_layer_config(global.snap_target, 0); } /* other targets select the specified view and turn off effects */ else { global.snap_target = render_target_alloc(machine, NULL, RENDER_CREATE_HIDDEN); assert(global.snap_target != NULL); render_target_set_view(global.snap_target, video_get_view_for_target(machine, global.snap_target, viewname, 0, 1)); render_target_set_layer_config(global.snap_target, render_target_get_layer_config(global.snap_target) & ~LAYER_CONFIG_ENABLE_SCREEN_OVERLAY); } /* extract snap resolution if present */ if (sscanf(options_get_string(mame_options(), OPTION_SNAPSIZE), "%dx%d", &global.snap_width, &global.snap_height) != 2) global.snap_width = global.snap_height = 0; /* start recording movie if specified */ filename = options_get_string(mame_options(), OPTION_MNGWRITE); if (filename[0] != 0) video_mng_begin_recording(machine, filename); filename = options_get_string(mame_options(), OPTION_AVIWRITE); if (filename[0] != 0) video_avi_begin_recording(machine, filename); /* if no screens, create a periodic timer to drive updates */ if (machine->primary_screen == NULL) { global.screenless_frame_timer = timer_alloc(machine, screenless_update_callback, NULL); timer_adjust_periodic(global.screenless_frame_timer, DEFAULT_FRAME_PERIOD, 0, DEFAULT_FRAME_PERIOD); } } /*------------------------------------------------- video_exit - close down the video system -------------------------------------------------*/ static void video_exit(running_machine *machine) { int i; /* validate */ assert(machine != NULL); assert(machine->config != NULL); /* stop recording any movie */ video_mng_end_recording(machine); video_avi_end_recording(machine); /* free all the graphics elements */ for (i = 0; i < MAX_GFX_ELEMENTS; i++) gfx_element_free(machine->gfx); /* free the snapshot target */ if (global.snap_target != NULL) render_target_free(global.snap_target); if (global.snap_bitmap != NULL) bitmap_free(global.snap_bitmap); /* print a final result if we have at least 5 seconds' worth of data */ if (global.overall_emutime.seconds >= 5) { osd_ticks_t tps = osd_ticks_per_second(); double final_real_time = (double)global.overall_real_seconds + (double)global.overall_real_ticks / (double)tps; double final_emu_time = attotime_to_double(global.overall_emutime); mame_printf_info("Average speed: %.2f%% (%d seconds)\n", 100 * final_emu_time / final_real_time, attotime_add_attoseconds(global.overall_emutime, ATTOSECONDS_PER_SECOND / 2).seconds); } } /*------------------------------------------------- init_buffered_spriteram - initialize the double-buffered spriteram -------------------------------------------------*/ static void init_buffered_spriteram(running_machine *machine) { assert_always(spriteram_size != 0, "Video buffers spriteram but spriteram_size is 0"); /* allocate memory for the back buffer */ buffered_spriteram = (UINT8 *)auto_malloc(spriteram_size); /* register for saving it */ state_save_register_global_pointer(machine, buffered_spriteram, spriteram_size); /* do the same for the secon back buffer, if present */ if (spriteram_2_size) { /* allocate memory */ buffered_spriteram_2 = (UINT8 *)auto_malloc(spriteram_2_size); /* register for saving it */ state_save_register_global_pointer(machine, buffered_spriteram_2, spriteram_2_size); } /* make 16-bit and 32-bit pointer variants */ buffered_spriteram16 = (UINT16 *)buffered_spriteram; buffered_spriteram32 = (UINT32 *)buffered_spriteram; buffered_spriteram16_2 = (UINT16 *)buffered_spriteram_2; buffered_spriteram32_2 = (UINT32 *)buffered_spriteram_2; } /*************************************************************************** GRAPHICS DECODING ***************************************************************************/ /*------------------------------------------------- allocate_graphics - allocate memory for the graphics -------------------------------------------------*/ static void allocate_graphics(running_machine *machine, const gfx_decode_entry *gfxdecodeinfo) { int curgfx; /* loop over all elements */ for (curgfx = 0; curgfx < MAX_GFX_ELEMENTS && gfxdecodeinfo[curgfx].gfxlayout != NULL; curgfx++) { const gfx_decode_entry *gfxdecode = &gfxdecodeinfo[curgfx]; UINT32 region_length = 8 * memory_region_length(machine, gfxdecode->memory_region); const UINT8 *region_base = memory_region(machine, gfxdecode->memory_region); UINT32 xscale = (gfxdecode->xscale == 0) ? 1 : gfxdecode->xscale; UINT32 yscale = (gfxdecode->yscale == 0) ? 1 : gfxdecode->yscale; UINT32 *extpoffs, extxoffs[MAX_ABS_GFX_SIZE], extyoffs[MAX_ABS_GFX_SIZE]; const gfx_layout *gl = gfxdecode->gfxlayout; int israw = (gl->planeoffset[0] == GFX_RAW); int planes = gl->planes; UINT32 width = gl->width; UINT32 height = gl->height; UINT32 total = gl->total; UINT32 charincrement = gl->charincrement; gfx_layout glcopy; int j; /* make a copy of the layout */ glcopy = *gfxdecode->gfxlayout; /* copy the X and Y offsets into temporary arrays */ memcpy(extxoffs, glcopy.xoffset, sizeof(glcopy.xoffset)); memcpy(extyoffs, glcopy.yoffset, sizeof(glcopy.yoffset)); /* if there are extended offsets, copy them over top */ if (glcopy.extxoffs != NULL) memcpy(extxoffs, glcopy.extxoffs, glcopy.width * sizeof(extxoffs[0])); if (glcopy.extyoffs != NULL) memcpy(extyoffs, glcopy.extyoffs, glcopy.height * sizeof(extyoffs[0])); /* always use the extended offsets here */ glcopy.extxoffs = extxoffs; glcopy.extyoffs = extyoffs; extpoffs = glcopy.planeoffset; /* expand X and Y by the scale factors */ if (xscale > 1) { width *= xscale; for (j = width - 1; j >= 0; j--) extxoffs[j] = extxoffs[j / xscale]; } if (yscale > 1) { height *= yscale; for (j = height - 1; j >= 0; j--) extyoffs[j] = extyoffs[j / yscale]; } /* if the character count is a region fraction, compute the effective total */ if (IS_FRAC(total)) { assert(region_length != 0); total = region_length / charincrement * FRAC_NUM(total) / FRAC_DEN(total); } /* for non-raw graphics, decode the X and Y offsets */ if (!israw) { /* loop over all the planes, converting fractions */ for (j = 0; j < planes; j++) { UINT32 value = extpoffs[j]; if (IS_FRAC(value)) { assert(region_length != 0); extpoffs[j] = FRAC_OFFSET(value) + region_length * FRAC_NUM(value) / FRAC_DEN(value); } } /* loop over all the X/Y offsets, converting fractions */ for (j = 0; j < width; j++) { UINT32 value = extxoffs[j]; if (IS_FRAC(value)) { assert(region_length != 0); extxoffs[j] = FRAC_OFFSET(value) + region_length * FRAC_NUM(value) / FRAC_DEN(value); } } for (j = 0; j < height; j++) { UINT32 value = extyoffs[j]; if (IS_FRAC(value)) { assert(region_length != 0); extyoffs[j] = FRAC_OFFSET(value) + region_length * FRAC_NUM(value) / FRAC_DEN(value); } } } /* otherwise, just use the line modulo */ else { int base = gfxdecode->start; int end = region_length/8; int linemod = gl->yoffset[0]; while (total > 0) { int elementbase = base + (total - 1) * charincrement / 8; int lastpixelbase = elementbase + height * linemod / 8 - 1; if (lastpixelbase < end) break; total--; } } /* update glcopy */ glcopy.width = width; glcopy.height = height; glcopy.total = total; /* allocate the graphics */ machine->gfx[curgfx] = gfx_element_alloc(machine, &glcopy, (region_base != NULL) ? region_base + gfxdecode->start : NULL, gfxdecode->total_color_codes, gfxdecode->color_codes_start); } } /*------------------------------------------------- decode_graphics - decode the graphics -------------------------------------------------*/ static void decode_graphics(running_machine *machine, const gfx_decode_entry *gfxdecodeinfo) { int totalgfx = 0, curgfx = 0; int i; /* count total graphics elements */ for (i = 0; i < MAX_GFX_ELEMENTS; i++) if (machine->gfx != NULL) totalgfx += machine->gfx->total_elements; /* loop over all elements */ for (i = 0; i < MAX_GFX_ELEMENTS; i++) if (machine->gfx != NULL) { /* if we have a valid region, decode it now */ if (gfxdecodeinfo.memory_region != NULL) { gfx_element *gfx = machine->gfx; int j; /* now decode the actual graphics */ for (j = 0; j < gfx->total_elements; j += 1024) { char buffer[200]; int num_to_decode = (j + 1024 < gfx->total_elements) ? 1024 : (gfx->total_elements - j); decodegfx(gfx, j, num_to_decode); curgfx += num_to_decode; /* display some startup text */ sprintf(buffer, "Decoding (%d%%)", curgfx * 100 / totalgfx); ui_set_startup_text(machine, buffer, FALSE); } } /* otherwise, clear the target region */ else memset(machine->gfx->gfxdata, 0, machine->gfx->char_modulo * machine->gfx->total_elements); } } /*************************************************************************** SCREEN MANAGEMENT ***************************************************************************/ /*------------------------------------------------- video_screen_configure - configure the parameters of a screen -------------------------------------------------*/ void video_screen_configure(const device_config *screen, int width, int height, const rectangle *visarea, attoseconds_t frame_period) { screen_state *state = get_safe_token(screen); screen_config *config = (screen_config *)screen->inline_config; /* validate arguments */ assert(width > 0); assert(height > 0); assert(visarea != NULL); assert(visarea->min_x >= 0); assert(visarea->min_y >= 0); assert(config->type == SCREEN_TYPE_VECTOR || visarea->min_x < width); assert(config->type == SCREEN_TYPE_VECTOR || visarea->min_y < height); assert(frame_period > 0); /* fill in the new parameters */ state->width = width; state->height = height; state->visarea = *visarea; /* reallocate bitmap if necessary */ realloc_screen_bitmaps(screen); /* compute timing parameters */ state->frame_period = frame_period; state->scantime = frame_period / height; state->pixeltime = frame_period / (height * width); /* if there has been no VBLANK time specified in the MACHINE_DRIVER, compute it now from the visible area, otherwise just used the supplied value */ if (config->vblank == 0 && !config->oldstyle_vblank_supplied) state->vblank_period = state->scantime * (height - (visarea->max_y + 1 - visarea->min_y)); else state->vblank_period = config->vblank; /* if we are on scanline 0 already, reset the update timer immediately */ /* otherwise, defer until the next scanline 0 */ if (video_screen_get_vpos(screen) == 0) timer_adjust_oneshot(state->scanline0_timer, attotime_zero, 0); else timer_adjust_oneshot(state->scanline0_timer, video_screen_get_time_until_pos(screen, 0, 0), 0); /* start the VBLANK timer */ timer_adjust_oneshot(state->vblank_begin_timer, video_screen_get_time_until_vblank_start(screen), 0); /* adjust speed if necessary */ update_refresh_speed(screen->machine); } /*------------------------------------------------- realloc_screen_bitmaps - reallocate screen bitmaps as necessary -------------------------------------------------*/ static void realloc_screen_bitmaps(const device_config *screen) { screen_state *state = get_safe_token(screen); screen_config *config = (screen_config *)screen->inline_config; if (config->type != SCREEN_TYPE_VECTOR) { int curwidth = 0, curheight = 0; /* extract the current width/height from the bitmap */ if (state->bitmap[0] != NULL) { curwidth = state->bitmap[0]->width; curheight = state->bitmap[0]->height; } /* if we're too small to contain this width/height, reallocate our bitmaps and textures */ if (state->width > curwidth || state->height > curheight) { bitmap_format screen_format = config->format; palette_t *palette; /* free what we have currently */ if (state->texture[0] != NULL) render_texture_free(state->texture[0]); if (state->texture[1] != NULL) render_texture_free(state->texture[1]); if (state->bitmap[0] != NULL) bitmap_free(state->bitmap[0]); if (state->bitmap[1] != NULL) bitmap_free(state->bitmap[1]); /* compute new width/height */ curwidth = MAX(state->width, curwidth); curheight = MAX(state->height, curheight); /* choose the texture format - convert the screen format to a texture format */ switch (screen_format) { case BITMAP_FORMAT_INDEXED16: state->texture_format = TEXFORMAT_PALETTE16; palette = screen->machine->palette; break; case BITMAP_FORMAT_RGB15: state->texture_format = TEXFORMAT_RGB15; palette = NULL; break; case BITMAP_FORMAT_RGB32: state->texture_format = TEXFORMAT_RGB32; palette = NULL; break; default: fatalerror("Invalid bitmap format!"); break; } /* allocate bitmaps */ state->bitmap[0] = bitmap_alloc(curwidth, curheight, screen_format); bitmap_set_palette(state->bitmap[0], screen->machine->palette); state->bitmap[1] = bitmap_alloc(curwidth, curheight, screen_format); bitmap_set_palette(state->bitmap[1], screen->machine->palette); /* allocate textures */ state->texture[0] = render_texture_alloc(NULL, NULL); render_texture_set_bitmap(state->texture[0], state->bitmap[0], &state->visarea, state->texture_format, palette); state->texture[1] = render_texture_alloc(NULL, NULL); render_texture_set_bitmap(state->texture[1], state->bitmap[1], &state->visarea, state->texture_format, palette); } } } /*------------------------------------------------- video_screen_set_visarea - just set the visible area of a screen -------------------------------------------------*/ void video_screen_set_visarea(const device_config *screen, int min_x, int max_x, int min_y, int max_y) { screen_state *state = get_safe_token(screen); rectangle visarea; /* validate arguments */ assert(min_x >= 0); assert(min_y >= 0); assert(min_x < max_x); assert(min_y < max_y); visarea.min_x = min_x; visarea.max_x = max_x; visarea.min_y = min_y; visarea.max_y = max_y; video_screen_configure(screen, state->width, state->height, &visarea, state->frame_period); } /*------------------------------------------------- video_screen_update_partial - perform a partial update from the last scanline up to and including the specified scanline -------------------------------------------------*/ int video_screen_update_partial(const device_config *screen, int scanline) { screen_state *state = get_safe_token(screen); rectangle clip = state->visarea; int result = FALSE; /* validate arguments */ assert(scanline >= 0); LOG_PARTIAL_UPDATES(("Partial: video_screen_update_partial(%s, %d): ", screen->tag, scanline)); /* these two checks only apply if we're allowed to skip frames */ if (!(screen->machine->config->video_attributes & VIDEO_ALWAYS_UPDATE)) { /* if skipping this frame, bail */ if (global.skipping_this_frame) { LOG_PARTIAL_UPDATES(("skipped due to frameskipping\n")); return FALSE; } /* skip if this screen is not visible anywhere */ if (!render_is_live_screen(screen)) { LOG_PARTIAL_UPDATES(("skipped because screen not live\n")); return FALSE; } } /* skip if less than the lowest so far */ if (scanline < state->last_partial_scan) { LOG_PARTIAL_UPDATES(("skipped because less than previous\n")); return FALSE; } /* set the start/end scanlines */ if (state->last_partial_scan > clip.min_y) clip.min_y = state->last_partial_scan; if (scanline < clip.max_y) clip.max_y = scanline; /* render if necessary */ if (clip.min_y <= clip.max_y) { UINT32 flags = UPDATE_HAS_NOT_CHANGED; profiler_mark(PROFILER_VIDEO); LOG_PARTIAL_UPDATES(("updating %d-%d\n", clip.min_y, clip.max_y)); if (screen->machine->config->video_update != NULL) flags = (*screen->machine->config->video_update)(screen, state->bitmap[state->curbitmap], &clip); global.partial_updates_this_frame++; profiler_mark(PROFILER_END); /* if we modified the bitmap, we have to commit */ state->changed |= ~flags & UPDATE_HAS_NOT_CHANGED; result = TRUE; } /* remember where we left off */ state->last_partial_scan = scanline + 1; return result; } /*------------------------------------------------- video_screen_update_now - perform an update from the last beam position up to the current beam position -------------------------------------------------*/ void video_screen_update_now(const device_config *screen) { screen_state *state = get_safe_token(screen); int current_vpos = video_screen_get_vpos(screen); int current_hpos = video_screen_get_hpos(screen); /* since we can currently update only at the scanline level, we are trying to do the right thing by updating including the current scanline, only if the beam is past the halfway point horizontally. If the beam is in the first half of the scanline, we only update up to the previous scanline. This minimizes the number of pixels that might be drawn incorrectly until we support a pixel level granularity */ if (current_hpos < (state->width / 2) && current_vpos > 0) current_vpos = current_vpos - 1; video_screen_update_partial(screen, current_vpos); } /*------------------------------------------------- video_screen_get_vpos - returns the current vertical position of the beam for a given screen -------------------------------------------------*/ int video_screen_get_vpos(const device_config *screen) { screen_state *state = get_safe_token(screen); attoseconds_t delta = attotime_to_attoseconds(attotime_sub(timer_get_time(screen->machine), state->vblank_start_time)); int vpos; /* round to the nearest pixel */ delta += state->pixeltime / 2; /* compute the v position relative to the start of VBLANK */ vpos = delta / state->scantime; /* adjust for the fact that VBLANK starts at the bottom of the visible area */ return (state->visarea.max_y + 1 + vpos) % state->height; } /*------------------------------------------------- video_screen_get_hpos - returns the current horizontal position of the beam for a given screen -------------------------------------------------*/ int video_screen_get_hpos(const device_config *screen) { screen_state *state = get_safe_token(screen); attoseconds_t delta = attotime_to_attoseconds(attotime_sub(timer_get_time(screen->machine), state->vblank_start_time)); int vpos; /* round to the nearest pixel */ delta += state->pixeltime / 2; /* compute the v position relative to the start of VBLANK */ vpos = delta / state->scantime; /* subtract that from the total time */ delta -= vpos * state->scantime; /* return the pixel offset from the start of this scanline */ return delta / state->pixeltime; } /*------------------------------------------------- video_screen_get_vblank - returns the VBLANK state of a given screen -------------------------------------------------*/ int video_screen_get_vblank(const device_config *screen) { screen_state *state = get_safe_token(screen); /* we should never be called with no VBLANK period - indication of a buggy driver */ assert(state->vblank_period != 0); return (attotime_compare(timer_get_time(screen->machine), state->vblank_end_time) < 0); } /*------------------------------------------------- video_screen_get_hblank - returns the HBLANK state of a given screen -------------------------------------------------*/ int video_screen_get_hblank(const device_config *screen) { screen_state *state = get_safe_token(screen); int hpos = video_screen_get_hpos(screen); return (hpos < state->visarea.min_x || hpos > state->visarea.max_x); } /*------------------------------------------------- video_screen_get_width - returns the width of a given screen -------------------------------------------------*/ int video_screen_get_width(const device_config *screen) { screen_state *state = get_safe_token(screen); return state->width; } /*------------------------------------------------- video_screen_get_height - returns the height of a given screen -------------------------------------------------*/ int video_screen_get_height(const device_config *screen) { screen_state *state = get_safe_token(screen); return state->height; } /*------------------------------------------------- video_screen_get_visible_area - returns the visible area of a given screen -------------------------------------------------*/ const rectangle *video_screen_get_visible_area(const device_config *screen) { screen_state *state = get_safe_token(screen); return &state->visarea; } /*------------------------------------------------- video_screen_get_time_until_pos - returns the amount of time remaining until the beam is at the given hpos,vpos -------------------------------------------------*/ attotime video_screen_get_time_until_pos(const device_config *screen, int vpos, int hpos) { screen_state *state = get_safe_token(screen); attoseconds_t curdelta = attotime_to_attoseconds(attotime_sub(timer_get_time(screen->machine), state->vblank_start_time)); attoseconds_t targetdelta; /* validate arguments */ assert(vpos >= 0); assert(hpos >= 0); /* since we measure time relative to VBLANK, compute the scanline offset from VBLANK */ vpos += state->height - (state->visarea.max_y + 1); vpos %= state->height; /* compute the delta for the given X,Y position */ targetdelta = (attoseconds_t)vpos * state->scantime + (attoseconds_t)hpos * state->pixeltime; /* if we're past that time (within 1/2 of a pixel), head to the next frame */ if (targetdelta <= curdelta + state->pixeltime / 2) targetdelta += state->frame_period; while (targetdelta <= curdelta) targetdelta += state->frame_period; /* return the difference */ return attotime_make(0, targetdelta - curdelta); } /*------------------------------------------------- video_screen_get_time_until_vblank_start - returns the amount of time remaining until the next VBLANK period start -------------------------------------------------*/ attotime video_screen_get_time_until_vblank_start(const device_config *screen) { return video_screen_get_time_until_pos(screen, video_screen_get_visible_area(screen)->max_y + 1, 0); } /*------------------------------------------------- video_screen_get_time_until_vblank_end - returns the amount of time remaining until the end of the current VBLANK (if in progress) or the end of the next VBLANK -------------------------------------------------*/ attotime video_screen_get_time_until_vblank_end(const device_config *screen) { attotime ret; screen_state *state = get_safe_token(screen); attotime current_time = timer_get_time(screen->machine); /* we are in the VBLANK region, compute the time until the end of the current VBLANK period */ if (video_screen_get_vblank(screen)) ret = attotime_sub(state->vblank_end_time, current_time); /* otherwise compute the time until the end of the next frame VBLANK period */ else ret = attotime_sub(attotime_add_attoseconds(state->vblank_end_time, state->frame_period), current_time); return ret; } /*------------------------------------------------- video_screen_get_time_until_update - returns the amount of time remaining until the next VBLANK period start -------------------------------------------------*/ attotime video_screen_get_time_until_update(const device_config *screen) { if (screen->machine->config->video_attributes & VIDEO_UPDATE_AFTER_VBLANK) return video_screen_get_time_until_vblank_end(screen); else return video_screen_get_time_until_vblank_start(screen); } /*------------------------------------------------- video_screen_get_scan_period - return the amount of time the beam takes to draw one scanline -------------------------------------------------*/ attotime video_screen_get_scan_period(const device_config *screen) { screen_state *state = get_safe_token(screen); return attotime_make(0, state->scantime); } /*------------------------------------------------- video_screen_get_frame_period - return the amount of time the beam takes to draw one complete frame -------------------------------------------------*/ attotime video_screen_get_frame_period(const device_config *screen) { attotime ret; /* a lot of modules want to the period of the primary screen, so if we are screenless, return something reasonable so that we don't fall over */ if (screen == NULL || !screen->started || video_screen_count(screen->machine->config) == 0) { ret = DEFAULT_FRAME_PERIOD; } else { screen_state *state = get_safe_token(screen); ret = attotime_make(0, state->frame_period); } return ret; } /*------------------------------------------------- video_screen_get_frame_number - return the current frame number since the start of the emulated machine -------------------------------------------------*/ UINT64 video_screen_get_frame_number(const device_config *screen) { screen_state *state = get_safe_token(screen); return state->frame_number; } /*------------------------------------------------- video_screen_register_vblank_callback - registers a VBLANK callback for a specific screen -------------------------------------------------*/ void video_screen_register_vblank_callback(const device_config *screen, vblank_state_changed_func vblank_callback, void *param) { screen_state *state = get_safe_token(screen); int i, found; /* validate arguments */ assert(vblank_callback != NULL); /* check if we already have this callback registered */ found = FALSE; for (i = 0; i < MAX_VBLANK_CALLBACKS; i++) { if (state->vblank_callback == NULL) break; if (state->vblank_callback == vblank_callback) found = TRUE; } /* check that there is room */ assert(i != MAX_VBLANK_CALLBACKS); /* if not found, register and increment count */ if (!found) { state->vblank_callback = vblank_callback; state->vblank_callback_param = param; } } /*************************************************************************** VIDEO SCREEN DEVICE INTERFACE ***************************************************************************/ /*------------------------------------------------- device_start_video_screen - device start callback for a video screen -------------------------------------------------*/ static DEVICE_START( video_screen ) { const device_config *screen = device; screen_state *state = get_safe_token(screen); render_container_user_settings settings; render_container *container; screen_config *config; /* validate some basic stuff */ assert(screen != NULL); assert(screen->static_config == NULL); assert(screen->inline_config != NULL); assert(screen->machine != NULL); assert(screen->machine->config != NULL); /* get and validate that the container for this screen exists */ container = render_container_get_screen(screen); assert(container != NULL); /* get and validate the configuration */ config = (screen_config *)screen->inline_config; assert(config->width > 0); assert(config->height > 0); assert(config->refresh > 0); assert(config->visarea.min_x >= 0); assert(config->visarea.max_x < config->width || config->type == SCREEN_TYPE_VECTOR); assert(config->visarea.max_x > config->visarea.min_x); assert(config->visarea.min_y >= 0); assert(config->visarea.max_y < config->height || config->type == SCREEN_TYPE_VECTOR); assert(config->visarea.max_y > config->visarea.min_y); /* allocate the VBLANK timers */ state->vblank_begin_timer = timer_alloc(screen->machine, vblank_begin_callback, (void *)screen); state->vblank_end_timer = timer_alloc(screen->machine, vblank_end_callback, (void *)screen); /* allocate a timer to reset partial updates */ state->scanline0_timer = timer_alloc(screen->machine, scanline0_callback, (void *)screen); /* configure the default cliparea */ render_container_get_user_settings(container, &settings); if (config->xoffset != 0) settings.xoffset = config->xoffset; if (config->yoffset != 0) settings.yoffset = config->yoffset; if (config->xscale != 0) settings.xscale = config->xscale; if (config->yscale != 0) settings.yscale = config->yscale; render_container_set_user_settings(container, &settings); /* allocate a timer to generate per-scanline updates */ if (screen->machine->config->video_attributes & VIDEO_UPDATE_SCANLINE) state->scanline_timer = timer_alloc(screen->machine, scanline_update_callback, (void *)screen); /* configure the screen with the default parameters */ video_screen_configure(screen, config->width, config->height, &config->visarea, config->refresh); /* reset VBLANK timing */ state->vblank_start_time = attotime_zero; state->vblank_end_time = attotime_make(0, state->vblank_period); /* start the timer to generate per-scanline updates */ if (screen->machine->config->video_attributes & VIDEO_UPDATE_SCANLINE) timer_adjust_oneshot(state->scanline_timer, video_screen_get_time_until_pos(screen, 0, 0), 0); state_save_register_device_item(screen, 0, state->width); state_save_register_device_item(screen, 0, state->height); state_save_register_device_item(screen, 0, state->visarea.min_x); state_save_register_device_item(screen, 0, state->visarea.min_y); state_save_register_device_item(screen, 0, state->visarea.max_x); state_save_register_device_item(screen, 0, state->visarea.max_y); state_save_register_device_item(screen, 0, state->last_partial_scan); state_save_register_device_item(screen, 0, state->frame_period); state_save_register_device_item(screen, 0, state->scantime); state_save_register_device_item(screen, 0, state->pixeltime); state_save_register_device_item(screen, 0, state->vblank_period); state_save_register_device_item(screen, 0, state->vblank_start_time.seconds); state_save_register_device_item(screen, 0, state->vblank_start_time.attoseconds); state_save_register_device_item(screen, 0, state->vblank_end_time.seconds); state_save_register_device_item(screen, 0, state->vblank_end_time.attoseconds); state_save_register_device_item(screen, 0, state->frame_number); state_save_register_postload(device->machine, video_screen_postload, (void *)device); } /*------------------------------------------------- video_screen_postload - after a state load, reconfigure each screen -------------------------------------------------*/ static STATE_POSTLOAD( video_screen_postload ) { const device_config *screen = (const device_config *)param; realloc_screen_bitmaps(screen); global.movie_next_frame_time = timer_get_time(machine); } /*------------------------------------------------- device_stop_video_screen - device stop callback for a video screen -------------------------------------------------*/ static DEVICE_STOP( video_screen ) { const device_config *screen = device; screen_state *state = get_safe_token(screen); if (state->texture[0] != NULL) render_texture_free(state->texture[0]); if (state->texture[1] != NULL) render_texture_free(state->texture[1]); if (state->bitmap[0] != NULL) bitmap_free(state->bitmap[0]); if (state->bitmap[1] != NULL) bitmap_free(state->bitmap[1]); } /*------------------------------------------------- video_screen_set_info - device set info callback -------------------------------------------------*/ static DEVICE_SET_INFO( video_screen ) { switch (state) { /* no parameters to set */ } } /*------------------------------------------------- video_screen_get_info - device get info callback -------------------------------------------------*/ DEVICE_GET_INFO( video_screen ) { switch (state) { /* --- the following bits of info are returned as 64-bit signed integers --- */ case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(screen_state); break; case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = sizeof(screen_config); break; case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_VIDEO; break; /* --- the following bits of info are returned as pointers to data or functions --- */ case DEVINFO_FCT_SET_INFO: info->set_info = DEVICE_SET_INFO_NAME(video_screen); break; case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(video_screen); break; case DEVINFO_FCT_STOP: info->stop = DEVICE_STOP_NAME(video_screen); break; case DEVINFO_FCT_RESET: /* Nothing */ break; /* --- the following bits of info are returned as NULL-terminated strings --- */ case DEVINFO_STR_NAME: strcpy(info->s, "Raster"); break; case DEVINFO_STR_FAMILY: strcpy(info->s, "Video Screen"); break; case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright Nicola Salmoria and the MAME Team"); break; } } /*************************************************************************** GLOBAL RENDERING ***************************************************************************/ /*------------------------------------------------- vblank_begin_callback - call any external callbacks to signal the VBLANK period has begun -------------------------------------------------*/ static TIMER_CALLBACK( vblank_begin_callback ) { int i; device_config *screen = (device_config *)ptr; screen_state *state = get_safe_token(screen); /* reset the starting VBLANK time */ state->vblank_start_time = timer_get_time(machine); state->vblank_end_time = attotime_add_attoseconds(state->vblank_start_time, state->vblank_period); /* call the screen specific callbacks */ for (i = 0; state->vblank_callback != NULL; i++) (*state->vblank_callback)(screen, state->vblank_callback_param, TRUE); /* if this is the primary screen and we need to update now */ if (screen == machine->primary_screen && !(machine->config->video_attributes & VIDEO_UPDATE_AFTER_VBLANK)) video_frame_update(machine, FALSE); /* reset the VBLANK start timer for the next frame */ timer_adjust_oneshot(state->vblank_begin_timer, video_screen_get_time_until_vblank_start(screen), 0); /* if no VBLANK period, call the VBLANK end callback immedietely, otherwise reset the timer */ if (state->vblank_period == 0) vblank_end_callback(machine, screen, 0); else timer_adjust_oneshot(state->vblank_end_timer, video_screen_get_time_until_vblank_end(screen), 0); } /*------------------------------------------------- vblank_end_callback - call any external callbacks to signal the VBLANK period has ended -------------------------------------------------*/ static TIMER_CALLBACK( vblank_end_callback ) { int i; const device_config *screen = (const device_config *)ptr; screen_state *state = get_safe_token(screen); /* call the screen specific callbacks */ for (i = 0; state->vblank_callback != NULL; i++) (*state->vblank_callback)(screen, state->vblank_callback_param, FALSE); /* if this is the primary screen and we need to update now */ if (screen == machine->primary_screen && (machine->config->video_attributes & VIDEO_UPDATE_AFTER_VBLANK)) video_frame_update(machine, FALSE); /* increment the frame number counter */ state->frame_number++; } /*------------------------------------------------- screenless_update_callback - update generator when there are no screens to drive it -------------------------------------------------*/ static TIMER_CALLBACK( screenless_update_callback ) { /* force an update */ video_frame_update(machine, FALSE); } /*------------------------------------------------- scanline0_callback - reset partial updates for a screen -------------------------------------------------*/ static TIMER_CALLBACK( scanline0_callback ) { const device_config *screen = (const device_config *)ptr; screen_state *state = get_safe_token(screen); /* reset partial updates */ state->last_partial_scan = 0; global.partial_updates_this_frame = 0; timer_adjust_oneshot(state->scanline0_timer, video_screen_get_time_until_pos(screen, 0, 0), 0); } /*------------------------------------------------- scanline_update_callback - perform partial updates on each scanline -------------------------------------------------*/ static TIMER_CALLBACK( scanline_update_callback ) { const device_config *screen = (const device_config *)ptr; screen_state *state = get_safe_token(screen); int scanline = param; /* force a partial update to the current scanline */ video_screen_update_partial(screen, scanline); /* compute the next visible scanline */ scanline++; if (scanline > state->visarea.max_y) scanline = state->visarea.min_y; timer_adjust_oneshot(state->scanline_timer, video_screen_get_time_until_pos(screen, scanline, 0), scanline); } /*------------------------------------------------- video_frame_update - handle frameskipping and UI, plus updating the screen during normal operations -------------------------------------------------*/ void video_frame_update(running_machine *machine, int debug) { attotime current_time = timer_get_time(machine); int skipped_it = global.skipping_this_frame; int phase = mame_get_phase(machine); /* validate */ assert(machine != NULL); assert(machine->config != NULL); /* only render sound and video if we're in the running phase */ if (phase == MAME_PHASE_RUNNING && (!mame_is_paused(machine) || options_get_bool(mame_options(), OPTION_UPDATEINPAUSE))) { int anything_changed = finish_screen_updates(machine); /* if none of the screens changed and we haven't skipped too many frames in a row, mark this frame as skipped to prevent throttling; this helps for games that don't update their screen at the monitor refresh rate */ if (!anything_changed && !global.auto_frameskip && global.frameskip_level == 0 && global.empty_skip_count++ < 3) skipped_it = TRUE; else global.empty_skip_count = 0; } /* draw the user interface */ ui_update_and_render(machine); /* if we're throttling, synchronize before rendering */ if (!debug && !skipped_it && effective_throttle(machine)) update_throttle(machine, current_time); /* ask the OSD to update */ profiler_mark(PROFILER_BLIT); osd_update(machine, !debug && skipped_it); profiler_mark(PROFILER_END); /* perform tasks for this frame */ if (!debug) mame_frame_update(machine); /* update frameskipping */ if (!debug) update_frameskip(machine); /* update speed computations */ if (!debug && !skipped_it) recompute_speed(machine, current_time); /* call the end-of-frame callback */ if (phase == MAME_PHASE_RUNNING) { /* reset partial updates if we're paused or if the debugger is active */ if (machine->primary_screen != NULL && (mame_is_paused(machine) || debug || debugger_within_instruction_hook(machine))) { void *param = (void *)machine->primary_screen; scanline0_callback(machine, param, 0); } /* otherwise, call the video EOF callback */ else if (machine->config->video_eof != NULL) { profiler_mark(PROFILER_VIDEO); (*machine->config->video_eof)(machine); profiler_mark(PROFILER_END); } } } /*------------------------------------------------- finish_screen_updates - finish updating all the screens -------------------------------------------------*/ static int finish_screen_updates(running_machine *machine) { const device_config *screen; int anything_changed = FALSE; /* finish updating the screens */ for (screen = video_screen_first(machine->config); screen != NULL; screen = video_screen_next(screen)) video_screen_update_partial(screen, video_screen_get_visible_area(screen)->max_y); /* now add the quads for all the screens */ for (screen = video_screen_first(machine->config); screen != NULL; screen = video_screen_next(screen)) { screen_state *state = get_safe_token(screen); /* only update if live */ if (render_is_live_screen(screen)) { const screen_config *config = (const screen_config *)screen->inline_config; /* only update if empty and not a vector game; otherwise assume the driver did it directly */ if (config->type != SCREEN_TYPE_VECTOR && (machine->config->video_attributes & VIDEO_SELF_RENDER) == 0) { /* if we're not skipping the frame and if the screen actually changed, then update the texture */ if (!global.skipping_this_frame && state->changed) { bitmap_t *bitmap = state->bitmap[state->curbitmap]; rectangle fixedvis = *video_screen_get_visible_area(screen); palette_t *palette = (state->texture_format == TEXFORMAT_PALETTE16) ? machine->palette : NULL; fixedvis.max_x++; fixedvis.max_y++; render_texture_set_bitmap(state->texture[state->curbitmap], bitmap, &fixedvis, state->texture_format, palette); state->curtexture = state->curbitmap; state->curbitmap = 1 - state->curbitmap; } /* create an empty container with a single quad */ render_container_empty(render_container_get_screen(screen)); render_screen_add_quad(screen, 0.0f, 0.0f, 1.0f, 1.0f, MAKE_ARGB(0xff,0xff,0xff,0xff), state->texture[state->curtexture], PRIMFLAG_BLENDMODE(BLENDMODE_NONE) | PRIMFLAG_SCREENTEX(1)); } } /* reset the screen changed flags */ if (state->changed) anything_changed = TRUE; state->changed = FALSE; } /* update our movie recording state */ if (!mame_is_paused(machine)) { video_mng_record_frame(machine); video_avi_record_frame(machine); } /* draw any crosshairs */ for (screen = video_screen_first(machine->config); screen != NULL; screen = video_screen_next(screen)) crosshair_render(screen); return anything_changed; } /*************************************************************************** THROTTLING/FRAMESKIPPING/PERFORMANCE ***************************************************************************/ /*------------------------------------------------- video_skip_this_frame - accessor to determine if this frame is being skipped -------------------------------------------------*/ int video_skip_this_frame(void) { return global.skipping_this_frame; } /*------------------------------------------------- video_get_speed_factor - return the speed factor as an integer * 100 -------------------------------------------------*/ int video_get_speed_factor(void) { return global.speed; } /*------------------------------------------------- video_set_speed_factor - sets the speed factor as an integer * 100 -------------------------------------------------*/ void video_set_speed_factor(int speed) { global.speed = speed; } /*------------------------------------------------- video_get_speed_text - print the text to be displayed in the upper-right corner -------------------------------------------------*/ const char *video_get_speed_text(running_machine *machine) { int paused = mame_is_paused(machine); static char buffer[1024]; char *dest = buffer; /* validate */ assert(machine != NULL); /* if we're paused, just display Paused */ if (paused) dest += sprintf(dest, "paused"); /* if we're fast forwarding, just display Fast-forward */ else if (global.fastforward) dest += sprintf(dest, "fast "); /* if we're auto frameskipping, display that plus the level */ else if (effective_autoframeskip(machine)) dest += sprintf(dest, "auto%2d/%d", effective_frameskip(), MAX_FRAMESKIP); /* otherwise, just display the frameskip plus the level */ else dest += sprintf(dest, "skip %d/%d", effective_frameskip(), MAX_FRAMESKIP); /* append the speed for all cases except paused */ if (!paused) dest += sprintf(dest, "%4d%%", (int)(100 * global.speed_percent + 0.5)); /* display the number of partial updates as well */ if (global.partial_updates_this_frame > 1) dest += sprintf(dest, "\n%d partial updates", global.partial_updates_this_frame); /* return a pointer to the static buffer */ return buffer; } /*------------------------------------------------- video_get_speed_percent - return the current effective speed percentage -------------------------------------------------*/ double video_get_speed_percent(running_machine *machine) { return global.speed_percent; } /*------------------------------------------------- video_get_frameskip - return the current actual frameskip (-1 means autoframeskip) -------------------------------------------------*/ int video_get_frameskip(void) { /* if autoframeskip is on, return -1 */ if (global.auto_frameskip) return -1; /* otherwise, return the direct level */ else return global.frameskip_level; } /*------------------------------------------------- video_set_frameskip - set the current actual frameskip (-1 means autoframeskip) -------------------------------------------------*/ void video_set_frameskip(int frameskip) { /* -1 means autoframeskip */ if (frameskip == -1) { global.auto_frameskip = TRUE; global.frameskip_level = 0; } /* any other level is a direct control */ else if (frameskip >= 0 && frameskip <= MAX_FRAMESKIP) { global.auto_frameskip = FALSE; global.frameskip_level = frameskip; } } /*------------------------------------------------- video_get_throttle - return the current actual throttle -------------------------------------------------*/ int video_get_throttle(void) { return global.throttle; } /*------------------------------------------------- video_set_throttle - set the current actual throttle -------------------------------------------------*/ void video_set_throttle(int throttle) { global.throttle = throttle; } /*------------------------------------------------- video_get_fastforward - return the current fastforward value -------------------------------------------------*/ int video_get_fastforward(void) { return global.fastforward; } /*------------------------------------------------- video_set_fastforward - set the current fastforward value -------------------------------------------------*/ void video_set_fastforward(int _fastforward) { global.fastforward = _fastforward; } /*------------------------------------------------- update_throttle - throttle to the game's natural speed -------------------------------------------------*/ static void update_throttle(running_machine *machine, attotime emutime) { /* Throttling theory: This routine is called periodically with an up-to-date emulated time. The idea is to synchronize real time with emulated time. We do this by "throttling", or waiting for real time to catch up with emulated time. In an ideal world, it will take less real time to emulate and render each frame than the emulated time, so we need to slow things down to get both times in sync. There are many complications to this model: * some games run too slow, so each frame we get further and further behind real time; our only choice here is to not throttle * some games have very uneven frame rates; one frame will take a long time to emulate, and the next frame may be very fast * we run on top of multitasking OSes; sometimes execution time is taken away from us, and this means we may not get enough time to emulate one frame * we may be paused, and emulated time may not be marching forward * emulated time could jump due to resetting the machine or restoring from a saved state */ static const UINT8 popcount[256] = { 0,1,1,2,1,2,2,3, 1,2,2,3,2,3,3,4, 1,2,2,3,2,3,3,4, 2,3,3,4,3,4,4,5, 1,2,2,3,2,3,3,4, 2,3,3,4,3,4,4,5, 2,3,3,4,3,4,4,5, 3,4,4,5,4,5,5,6, 1,2,2,3,2,3,3,4, 2,3,3,4,3,4,4,5, 2,3,3,4,3,4,4,5, 3,4,4,5,4,5,5,6, 2,3,3,4,3,4,4,5, 3,4,4,5,4,5,5,6, 3,4,4,5,4,5,5,6, 4,5,5,6,5,6,6,7, 1,2,2,3,2,3,3,4, 2,3,3,4,3,4,4,5, 2,3,3,4,3,4,4,5, 3,4,4,5,4,5,5,6, 2,3,3,4,3,4,4,5, 3,4,4,5,4,5,5,6, 3,4,4,5,4,5,5,6, 4,5,5,6,5,6,6,7, 2,3,3,4,3,4,4,5, 3,4,4,5,4,5,5,6, 3,4,4,5,4,5,5,6, 4,5,5,6,5,6,6,7, 3,4,4,5,4,5,5,6, 4,5,5,6,5,6,6,7, 4,5,5,6,5,6,6,7, 5,6,6,7,6,7,7,8 }; attoseconds_t real_delta_attoseconds; attoseconds_t emu_delta_attoseconds; attoseconds_t real_is_ahead_attoseconds; attoseconds_t attoseconds_per_tick; osd_ticks_t ticks_per_second; osd_ticks_t target_ticks; osd_ticks_t diff_ticks; /* apply speed factor to emu time */ if (global.speed != 0 && global.speed != 100) { /* multiply emutime by 100, then divide by the global speed factor */ emutime = attotime_div(attotime_mul(emutime, 100), global.speed); } /* compute conversion factors up front */ ticks_per_second = osd_ticks_per_second(); attoseconds_per_tick = ATTOSECONDS_PER_SECOND / ticks_per_second; /* if we're paused, emutime will not advance; instead, we subtract a fixed amount of time (1/60th of a second) from the emulated time that was passed in, and explicitly reset our tracked real and emulated timers to that value ... this means we pretend that the last update was exactly 1/60th of a second ago, and was in sync in both real and emulated time */ if (mame_is_paused(machine)) { global.throttle_emutime = attotime_sub_attoseconds(emutime, ATTOSECONDS_PER_SECOND / PAUSED_REFRESH_RATE); global.throttle_realtime = global.throttle_emutime; } /* attempt to detect anomalies in the emulated time by subtracting the previously reported value from our current value; this should be a small value somewhere between 0 and 1/10th of a second ... anything outside of this range is obviously wrong and requires a resync */ emu_delta_attoseconds = attotime_to_attoseconds(attotime_sub(emutime, global.throttle_emutime)); if (emu_delta_attoseconds < 0 || emu_delta_attoseconds > ATTOSECONDS_PER_SECOND / 10) { if (LOG_THROTTLE) logerror("Resync due to weird emutime delta: %s\n", attotime_string(attotime_make(0, emu_delta_attoseconds), 18)); goto resync; } /* now determine the current real time in OSD-specified ticks; we have to be careful here because counters can wrap, so we only use the difference between the last read value and the current value in our computations */ diff_ticks = osd_ticks() - global.throttle_last_ticks; global.throttle_last_ticks += diff_ticks; /* if it has been more than a full second of real time since the last call to this function, we just need to resynchronize */ if (diff_ticks >= ticks_per_second) { if (LOG_THROTTLE) logerror("Resync due to real time advancing by more than 1 second\n"); goto resync; } /* convert this value into attoseconds for easier comparison */ real_delta_attoseconds = diff_ticks * attoseconds_per_tick; /* now update our real and emulated timers with the current values */ global.throttle_emutime = emutime; global.throttle_realtime = attotime_add_attoseconds(global.throttle_realtime, real_delta_attoseconds); /* keep a history of whether or not emulated time beat real time over the last few updates; this can be used for future heuristics */ global.throttle_history = (global.throttle_history << 1) | (emu_delta_attoseconds > real_delta_attoseconds); /* determine how far ahead real time is versus emulated time; note that we use the accumulated times for this instead of the deltas for the current update because we want to track time over a longer duration than a single update */ real_is_ahead_attoseconds = attotime_to_attoseconds(attotime_sub(global.throttle_emutime, global.throttle_realtime)); /* if we're more than 1/10th of a second out, or if we are behind at all and emulation is taking longer than the real frame, we just need to resync */ if (real_is_ahead_attoseconds < -ATTOSECONDS_PER_SECOND / 10 || (real_is_ahead_attoseconds < 0 && popcount[global.throttle_history & 0xff] < 6)) { if (LOG_THROTTLE) logerror("Resync due to being behind: %s (history=%08X)\n", attotime_string(attotime_make(0, -real_is_ahead_attoseconds), 18), global.throttle_history); goto resync; } /* if we're behind, it's time to just get out */ if (real_is_ahead_attoseconds < 0) return; /* compute the target real time, in ticks, where we want to be */ target_ticks = global.throttle_last_ticks + real_is_ahead_attoseconds / attoseconds_per_tick; /* throttle until we read the target, and update real time to match the final time */ diff_ticks = throttle_until_ticks(machine, target_ticks) - global.throttle_last_ticks; global.throttle_last_ticks += diff_ticks; global.throttle_realtime = attotime_add_attoseconds(global.throttle_realtime, diff_ticks * attoseconds_per_tick); return; resync: /* reset realtime and emutime to the same value */ global.throttle_realtime = global.throttle_emutime = emutime; } /*------------------------------------------------- throttle_until_ticks - spin until the specified target time, calling the OSD code to sleep if possible -------------------------------------------------*/ static osd_ticks_t throttle_until_ticks(running_machine *machine, osd_ticks_t target_ticks) { osd_ticks_t minimum_sleep = osd_ticks_per_second() / 1000; osd_ticks_t current_ticks = osd_ticks(); osd_ticks_t new_ticks; int allowed_to_sleep = FALSE; /* we're allowed to sleep via the OSD code only if we're configured to do so and we're not frameskipping due to autoframeskip, or if we're paused */ if (options_get_bool(mame_options(), OPTION_SLEEP) && (!effective_autoframeskip(machine) || effective_frameskip() == 0)) allowed_to_sleep = TRUE; if (mame_is_paused(machine)) allowed_to_sleep = TRUE; /* loop until we reach our target */ profiler_mark(PROFILER_IDLE); while (current_ticks < target_ticks) { osd_ticks_t delta; int slept = FALSE; /* compute how much time to sleep for, taking into account the average oversleep */ delta = (target_ticks - current_ticks) * 1000 / (1000 + global.average_oversleep); /* see if we can sleep */ if (allowed_to_sleep && delta >= minimum_sleep) { osd_sleep(delta); slept = TRUE; } /* read the new value */ new_ticks = osd_ticks(); /* keep some metrics on the sleeping patterns of the OSD layer */ if (slept) { osd_ticks_t actual_ticks = new_ticks - current_ticks; /* if we overslept, keep an average of the amount */ if (actual_ticks > delta) { osd_ticks_t oversleep_milliticks = 1000 * (actual_ticks - delta) / delta; /* take 90% of the previous average plus 10% of the new value */ global.average_oversleep = (global.average_oversleep * 99 + oversleep_milliticks) / 100; if (LOG_THROTTLE) logerror("Slept for %d ticks, got %d ticks, avgover = %d\n", (int)delta, (int)actual_ticks, (int)global.average_oversleep); } } current_ticks = new_ticks; } profiler_mark(PROFILER_END); return current_ticks; } /*------------------------------------------------- update_frameskip - update frameskipping counters and periodically update autoframeskip -------------------------------------------------*/ static void update_frameskip(running_machine *machine) { /* if we're throttling and autoframeskip is on, adjust */ if (effective_throttle(machine) && effective_autoframeskip(machine) && global.frameskip_counter == 0) { double speed = global.speed * 0.01; /* if we're too fast, attempt to increase the frameskip */ if (global.speed_percent >= 0.995 * speed) { /* but only after 3 consecutive frames where we are too fast */ if (++global.frameskip_adjust >= 3) { global.frameskip_adjust = 0; if (global.frameskip_level > 0) global.frameskip_level--; } } /* if we're too slow, attempt to increase the frameskip */ else { /* if below 80% speed, be more aggressive */ if (global.speed_percent < 0.80 * speed) global.frameskip_adjust -= (0.90 * speed - global.speed_percent) / 0.05; /* if we're close, only force it up to frameskip 8 */ else if (global.frameskip_level < 8) global.frameskip_adjust--; /* perform the adjustment */ while (global.frameskip_adjust <= -2) { global.frameskip_adjust += 2; if (global.frameskip_level < MAX_FRAMESKIP) global.frameskip_level++; } } } /* increment the frameskip counter and determine if we will skip the next frame */ global.frameskip_counter = (global.frameskip_counter + 1) % FRAMESKIP_LEVELS; global.skipping_this_frame = skiptable[effective_frameskip()][global.frameskip_counter]; } /*------------------------------------------------- update_refresh_speed - update the global.speed based on the maximum refresh rate supported -------------------------------------------------*/ static void update_refresh_speed(running_machine *machine) { /* only do this if the refreshspeed option is used */ if (options_get_bool(mame_options(), OPTION_REFRESHSPEED)) { float minrefresh = render_get_max_update_rate(); if (minrefresh != 0) { attoseconds_t min_frame_period = ATTOSECONDS_PER_SECOND; UINT32 original_speed = original_speed_setting(); const device_config *screen; UINT32 target_speed; /* find the screen with the shortest frame period (max refresh rate) */ /* note that we first check the token since this can get called before all screens are created */ for (screen = video_screen_first(machine->config); screen != NULL; screen = video_screen_next(screen)) if (screen->token != NULL) { screen_state *state = get_safe_token(screen); if (state->frame_period != 0) min_frame_period = MIN(min_frame_period, state->frame_period); } /* compute a target speed as an integral percentage */ /* note that we lop 0.25Hz off of the minrefresh when doing the computation to allow for the fact that most refresh rates are not accurate to 10 digits... */ target_speed = floor((minrefresh - 0.25f) * 100.0 / ATTOSECONDS_TO_HZ(min_frame_period)); target_speed = MIN(target_speed, original_speed); /* if we changed, log that verbosely */ if (target_speed != global.speed) { mame_printf_verbose("Adjusting target speed to %d%% (hw=%.2fHz, game=%.2fHz, adjusted=%.2fHz)\n", target_speed, minrefresh, ATTOSECONDS_TO_HZ(min_frame_period), ATTOSECONDS_TO_HZ(min_frame_period * 100 / target_speed)); global.speed = target_speed; } } } } /*------------------------------------------------- recompute_speed - recompute the current overall speed; we assume this is called only if we did not skip a frame -------------------------------------------------*/ static void recompute_speed(running_machine *machine, attotime emutime) { attoseconds_t delta_emutime; /* if we don't have a starting time yet, or if we're paused, reset our starting point */ if (global.speed_last_realtime == 0 || mame_is_paused(machine)) { global.speed_last_realtime = osd_ticks(); global.speed_last_emutime = emutime; } /* if it has been more than the update interval, update the time */ delta_emutime = attotime_to_attoseconds(attotime_sub(emutime, global.speed_last_emutime)); if (delta_emutime > SUBSECONDS_PER_SPEED_UPDATE) { osd_ticks_t realtime = osd_ticks(); osd_ticks_t delta_realtime = realtime - global.speed_last_realtime; osd_ticks_t tps = osd_ticks_per_second(); /* convert from ticks to attoseconds */ global.speed_percent = (double)delta_emutime * (double)tps / ((double)delta_realtime * (double)ATTOSECONDS_PER_SECOND); #ifdef SOUND_RESYNC machine->speed_percent = global.speed_percent; #endif /* SOUND_RESYNC */ /* remember the last times */ global.speed_last_realtime = realtime; global.speed_last_emutime = emutime; /* if we're throttled, this time period counts for overall speed; otherwise, we reset the counter */ if (!global.fastforward) global.overall_valid_counter++; else global.overall_valid_counter = 0; /* if we've had at least 4 consecutive valid periods, accumulate stats */ if (global.overall_valid_counter >= 4) { global.overall_real_ticks += delta_realtime; while (global.overall_real_ticks >= tps) { global.overall_real_ticks -= tps; global.overall_real_seconds++; } global.overall_emutime = attotime_add_attoseconds(global.overall_emutime, delta_emutime); } } /* if we're past the "time-to-execute" requested, signal an exit */ if (global.seconds_to_run != 0 && emutime.seconds >= global.seconds_to_run) { if (machine->primary_screen != NULL) { astring *fname = astring_assemble_2(astring_alloc(), machine->basename, PATH_SEPARATOR "final.png"); file_error filerr; mame_file *file; /* create a final screenshot */ filerr = mame_fopen(SEARCHPATH_SCREENSHOT, astring_c(fname), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file); if (filerr == FILERR_NONE) { video_screen_save_snapshot(machine, machine->primary_screen, file); mame_fclose(file); } astring_free(fname); } /* schedule our demise */ mame_schedule_exit(machine); } } /*************************************************************************** SCREEN SNAPSHOTS ***************************************************************************/ /*------------------------------------------------- video_screen_save_snapshot - save a snapshot to the given file handle -------------------------------------------------*/ void video_screen_save_snapshot(running_machine *machine, const device_config *screen, mame_file *fp) { png_info pnginfo = { 0 }; const rgb_t *palette; png_error error; char text[256]; /* validate */ assert(!global.snap_native || screen != NULL); assert(fp != NULL); /* create the bitmap to pass in */ create_snapshot_bitmap(screen); /* add two text entries describing the image */ sprintf(text, APPNAME " %s", build_version); png_add_text(&pnginfo, "Software", text); sprintf(text, "%s %s", machine->gamedrv->manufacturer, machine->gamedrv->description); png_add_text(&pnginfo, "System", text); /* now do the actual work */ palette = (machine->palette != NULL) ? palette_entry_list_adjusted(machine->palette) : NULL; error = png_write_bitmap(mame_core_file(fp), &pnginfo, global.snap_bitmap, machine->config->total_colors, palette); /* free any data allocated */ png_free(&pnginfo); } /*------------------------------------------------- video_save_active_screen_snapshots - save a snapshot of all active screens -------------------------------------------------*/ void video_save_active_screen_snapshots(running_machine *machine) { mame_file *fp; const device_config *screen; /* validate */ assert(machine != NULL); assert(machine->config != NULL); /* if we're native, then write one snapshot per visible screen */ if (global.snap_native) { /* write one snapshot per visible screen */ for (screen = video_screen_first(machine->config); screen != NULL; screen = video_screen_next(screen)) if (render_is_live_screen(screen)) { file_error filerr = mame_fopen_next(machine, SEARCHPATH_SCREENSHOT, "png", &fp); if (filerr == FILERR_NONE) { video_screen_save_snapshot(machine, screen, fp); mame_fclose(fp); } } } /* otherwise, just write a single snapshot */ else { file_error filerr = mame_fopen_next(machine, SEARCHPATH_SCREENSHOT, "png", &fp); if (filerr == FILERR_NONE) { video_screen_save_snapshot(machine, NULL, fp); mame_fclose(fp); } } } /*------------------------------------------------- creare_snapshot_bitmap - creates a bitmap containing the screenshot for the given screen -------------------------------------------------*/ static void create_snapshot_bitmap(const device_config *screen) { const render_primitive_list *primlist; INT32 width, height; int view_index; /* select the appropriate view in our dummy target */ if (global.snap_native && screen != NULL) { view_index = device_list_index(screen->machine->config->devicelist, VIDEO_SCREEN, screen->tag); assert(view_index != -1); render_target_set_view(global.snap_target, view_index); } /* get the minimum width/height and set it on the target */ width = global.snap_width; height = global.snap_height; if (width == 0 || height == 0) render_target_get_minimum_size(global.snap_target, &width, &height); render_target_set_bounds(global.snap_target, width, height, 0); /* if we don't have a bitmap, or if it's not the right size, allocate a new one */ if (global.snap_bitmap == NULL || width != global.snap_bitmap->width || height != global.snap_bitmap->height) { if (global.snap_bitmap != NULL) bitmap_free(global.snap_bitmap); global.snap_bitmap = bitmap_alloc(width, height, BITMAP_FORMAT_RGB32); assert(global.snap_bitmap != NULL); } /* render the screen there */ primlist = render_target_get_primitives(global.snap_target); osd_lock_acquire(primlist->lock); rgb888_draw_primitives(primlist->head, global.snap_bitmap->base, width, height, global.snap_bitmap->rowpixels); osd_lock_release(primlist->lock); } /*------------------------------------------------- mame_fopen_next - open the next non-existing file of type filetype according to our numbering scheme -------------------------------------------------*/ static file_error mame_fopen_next(running_machine *machine, const char *pathoption, const char *extension, mame_file **file) { const char *snapname = options_get_string(mame_options(), OPTION_SNAPNAME); astring *snapstr = astring_alloc(); astring *fname = astring_alloc(); file_error filerr; int index; /* handle defaults */ if (snapname == NULL || snapname[0] == 0) snapname = "%g/%i"; astring_cpyc(snapstr, snapname); /* strip any extension in the provided name and add our own */ index = astring_rchr(snapstr, 0, '.'); if (index != -1) astring_substr(snapstr, 0, index); astring_catc(snapstr, "."); astring_catc(snapstr, extension); /* substitute path and gamename up front */ astring_replacec(snapstr, 0, "/", PATH_SEPARATOR); astring_replacec(snapstr, 0, "%g", machine->basename); /* determine if the template has an index; if not, we always use the same name */ if (astring_findc(snapstr, 0, "%i") == -1) astring_cpy(fname, snapstr); /* otherwise, we scan for the next available filename */ else { int seq; /* try until we succeed */ for (seq = 0; ; seq++) { char seqtext[10]; /* make text for the sequence number */ sprintf(seqtext, "%04d", seq); /* build up the filename */ astring_cpy(fname, snapstr); astring_replacec(fname, 0, "%i", seqtext); /* try to open the file; stop when we fail */ filerr = mame_fopen(pathoption, astring_c(fname), OPEN_FLAG_READ, file); if (filerr != FILERR_NONE) break; mame_fclose(*file); } } /* create the final file */ filerr = mame_fopen(pathoption, astring_c(fname), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, file); /* free the name and get out */ astring_free(fname); astring_free(snapstr); return filerr; } /*************************************************************************** MNG MOVIE RECORDING ***************************************************************************/ /*------------------------------------------------- video_mng_is_movie_active - return true if a MNG movie is currently being recorded -------------------------------------------------*/ int video_mng_is_movie_active(running_machine *machine) { return (global.mngfile != NULL); } /*------------------------------------------------- video_mng_begin_recording - begin recording of a MNG movie -------------------------------------------------*/ void video_mng_begin_recording(running_machine *machine, const char *name) { screen_state *state = NULL; file_error filerr; png_error pngerr; int rate; /* close any existing movie file */ if (global.mngfile != NULL) video_mng_end_recording(machine); /* look up the primary screen */ if (machine->primary_screen != NULL) state = get_safe_token(machine->primary_screen); /* create a snapshot bitmap so we know what the target size is */ create_snapshot_bitmap(NULL); /* create a new movie file and start recording */ if (name != NULL) filerr = mame_fopen(SEARCHPATH_MOVIE, name, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &global.mngfile); else filerr = mame_fopen_next(machine, SEARCHPATH_MOVIE, "mng", &global.mngfile); /* start the capture */ rate = (state != NULL) ? ATTOSECONDS_TO_HZ(state->frame_period) : DEFAULT_FRAME_RATE; pngerr = mng_capture_start(mame_core_file(global.mngfile), global.snap_bitmap, rate); if (pngerr != PNGERR_NONE) { video_mng_end_recording(machine); return; } /* compute the frame time */ global.movie_next_frame_time = timer_get_time(machine); global.movie_frame_period = ATTOTIME_IN_HZ(rate); global.movie_frame = 0; } /*------------------------------------------------- video_mng_end_recording - stop recording of a MNG movie -------------------------------------------------*/ void video_mng_end_recording(running_machine *machine) { /* close the file if it exists */ if (global.mngfile != NULL) { mng_capture_stop(mame_core_file(global.mngfile)); mame_fclose(global.mngfile); global.mngfile = NULL; global.movie_frame = 0; } } /*------------------------------------------------- video_mng_record_frame - record a frame of a movie -------------------------------------------------*/ static void video_mng_record_frame(running_machine *machine) { /* only record if we have a file */ if (global.mngfile != NULL) { attotime curtime = timer_get_time(machine); png_info pnginfo = { 0 }; png_error error; profiler_mark(PROFILER_MOVIE_REC); /* create the bitmap */ create_snapshot_bitmap(NULL); /* loop until we hit the right time */ while (attotime_compare(global.movie_next_frame_time, curtime) <= 0) { const rgb_t *palette; /* set up the text fields in the movie info */ if (global.movie_frame == 0) { char text[256]; sprintf(text, APPNAME " %s", build_version); png_add_text(&pnginfo, "Software", text); sprintf(text, "%s %s", machine->gamedrv->manufacturer, machine->gamedrv->description); png_add_text(&pnginfo, "System", text); } /* write the next frame */ palette = (machine->palette != NULL) ? palette_entry_list_adjusted(machine->palette) : NULL; error = mng_capture_frame(mame_core_file(global.mngfile), &pnginfo, global.snap_bitmap, machine->config->total_colors, palette); png_free(&pnginfo); if (error != PNGERR_NONE) { video_mng_end_recording(machine); break; } /* advance time */ global.movie_next_frame_time = attotime_add(global.movie_next_frame_time, global.movie_frame_period); global.movie_frame++; } profiler_mark(PROFILER_END); } } /*************************************************************************** AVI MOVIE RECORDING ***************************************************************************/ /*------------------------------------------------- video_avi_begin_recording - begin recording of an AVI movie -------------------------------------------------*/ void video_avi_begin_recording(running_machine *machine, const char *name) { screen_state *state = NULL; avi_movie_info info; mame_file *tempfile; file_error filerr; avi_error avierr; /* close any existing movie file */ if (global.avifile != NULL) video_avi_end_recording(machine); /* look up the primary screen */ if (machine->primary_screen != NULL) state = get_safe_token(machine->primary_screen); /* create a snapshot bitmap so we know what the target size is */ create_snapshot_bitmap(NULL); /* build up information about this new movie */ info.video_format = 0; info.video_timescale = 1000 * ((state != NULL) ? ATTOSECONDS_TO_HZ(state->frame_period) : DEFAULT_FRAME_RATE); info.video_sampletime = 1000; info.video_numsamples = 0; info.video_width = global.snap_bitmap->width; info.video_height = global.snap_bitmap->height; info.video_depth = 24; info.audio_format = 0; info.audio_timescale = machine->sample_rate; info.audio_sampletime = 1; info.audio_numsamples = 0; info.audio_channels = 2; info.audio_samplebits = 16; info.audio_samplerate = machine->sample_rate; /* create a new temporary movie file */ if (name != NULL) filerr = mame_fopen(SEARCHPATH_MOVIE, name, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &tempfile); else filerr = mame_fopen_next(machine, SEARCHPATH_MOVIE, "avi", &tempfile); /* reset our tracking */ global.movie_frame = 0; global.movie_next_frame_time = timer_get_time(machine); global.movie_frame_period = attotime_div(ATTOTIME_IN_SEC(1000), info.video_timescale); /* if we succeeded, make a copy of the name and create the real file over top */ if (filerr == FILERR_NONE) { astring *fullname = astring_dupc(mame_file_full_name(tempfile)); mame_fclose(tempfile); /* create the file and free the string */ avierr = avi_create(astring_c(fullname), &info, &global.avifile); astring_free(fullname); } } /*------------------------------------------------- video_avi_end_recording - stop recording of a avi movie -------------------------------------------------*/ void video_avi_end_recording(running_machine *machine) { /* close the file if it exists */ if (global.avifile != NULL) { avi_close(global.avifile); global.avifile = NULL; global.movie_frame = 0; } } /*------------------------------------------------- video_avi_record_frame - record a frame of a movie -------------------------------------------------*/ static void video_avi_record_frame(running_machine *machine) { /* only record if we have a file */ if (global.avifile != NULL) { attotime curtime = timer_get_time(machine); avi_error avierr; profiler_mark(PROFILER_MOVIE_REC); /* create the bitmap */ create_snapshot_bitmap(NULL); /* loop until we hit the right time */ while (attotime_compare(global.movie_next_frame_time, curtime) <= 0) { /* write the next frame */ avierr = avi_append_video_frame_rgb32(global.avifile, global.snap_bitmap); if (avierr != AVIERR_NONE) { video_avi_end_recording(machine); break; } /* advance time */ global.movie_next_frame_time = attotime_add(global.movie_next_frame_time, global.movie_frame_period); global.movie_frame++; } profiler_mark(PROFILER_END); } } /*------------------------------------------------- video_avi_add_sound - add sound to an AVI recording -------------------------------------------------*/ void video_avi_add_sound(running_machine *machine, const INT16 *sound, int numsamples) { /* only record if we have a file */ if (global.avifile != NULL) { avi_error avierr; profiler_mark(PROFILER_MOVIE_REC); /* write the next frame */ avierr = avi_append_sound_samples(global.avifile, 0, sound + 0, numsamples, 1); if (avierr == AVIERR_NONE) avierr = avi_append_sound_samples(global.avifile, 1, sound + 1, numsamples, 1); if (avierr != AVIERR_NONE) video_avi_end_recording(machine); profiler_mark(PROFILER_END); } } /*************************************************************************** CONFIGURATION HELPERS ***************************************************************************/ /*------------------------------------------------- video_get_view_for_target - select a view for a given target -------------------------------------------------*/ int video_get_view_for_target(running_machine *machine, render_target *target, const char *viewname, int targetindex, int numtargets) { int viewindex = -1; /* auto view just selects the nth view */ if (strcmp(viewname, "auto") != 0) { /* scan for a matching view name */ for (viewindex = 0; ; viewindex++) { const char *name = render_target_get_view_name(target, viewindex); /* stop scanning when we hit NULL */ if (name == NULL) { viewindex = -1; break; } if (mame_strnicmp(name, viewname, strlen(viewname)) == 0) break; } } /* if we don't have a match, default to the nth view */ if (viewindex == -1) { int scrcount = video_screen_count(machine->config); /* if we have enough targets to be one per screen, assign in order */ if (numtargets >= scrcount) { /* find the first view with this screen and this screen only */ for (viewindex = 0; ; viewindex++) { UINT32 viewscreens = render_target_get_view_screens(target, viewindex); if (viewscreens == (1 << targetindex)) break; if (viewscreens == 0) { viewindex = -1; break; } } } /* otherwise, find the first view that has all the screens */ if (viewindex == -1) { for (viewindex = 0; ; viewindex++) { UINT32 viewscreens = render_target_get_view_screens(target, viewindex); if (viewscreens == (1 << scrcount) - 1) break; if (viewscreens == 0) break; } } } /* make sure it's a valid view */ if (render_target_get_view_name(target, viewindex) == NULL) viewindex = 0; return viewindex; } /*************************************************************************** DEBUGGING HELPERS ***************************************************************************/ /*------------------------------------------------- video_assert_out_of_range_pixels - assert if any pixels in the given bitmap contain an invalid palette index -------------------------------------------------*/ void video_assert_out_of_range_pixels(running_machine *machine, bitmap_t *bitmap) { #ifdef MAME_DEBUG int maxindex = palette_get_max_index(machine->palette); int x, y; /* this only applies to indexed16 bitmaps */ if (bitmap->format != BITMAP_FORMAT_INDEXED16) return; /* iterate over rows */ for (y = 0; y < bitmap->height; y++) { UINT16 *rowbase = BITMAP_ADDR16(bitmap, y, 0); for (x = 0; x < bitmap->width; x++) assert(rowbase[x] < maxindex); } #endif } /*************************************************************************** SOFTWARE RENDERING ***************************************************************************/ #define FUNC_PREFIX(x) rgb888_##x #define PIXEL_TYPE UINT32 #define SRCSHIFT_R 0 #define SRCSHIFT_G 0 #define SRCSHIFT_B 0 #define DSTSHIFT_R 16 #define DSTSHIFT_G 8 #define DSTSHIFT_B 0 #define BILINEAR_FILTER 1 #include "rendersw.c"
  8. desse jeito da erro FILE *fp = fopen("C:\\arcade\\arcade1.exe", "rb"); if (fp == NULL){ MessageBox(NULL,"Este Sistema Operacional não contem informaçãos corretas para a execussão deste aplicativo.","Copia PIRATA",MB_OK ); exit(0) } assim funciona mas não executa,se o executavel arcade1.exe existir ele não executa mas não da erro.se o executavel não existir da a mensagem de erro postei o link do projeto inteiro para que possam analisar como devo colocar esse código o projeto é esse aqui https://mega.nz/#!ccZD0LYL!lDaBWPJ_DqWjNhP42UUuHxibwrbPHPhT5qQ1DFnutys esse é o source do frontend advmenu com algumas modificações e quero incluir mais esta int main(int argc,char *argv[]){ FILE *fp = fopen("C:\\arcade\\arcade1.exe", "rb"); if (fp == NULL) { MessageBox(NULL,"Este Sistema Operacional não contem informaçãos corretas para a execussão deste aplicativo.","Copia PIRATA",MB_OK ); exit(0); } } adicionado 59 minutos depois caramba assim funcionou mas o advmenu ficou acelerado #include <stdio.h> #include <stdlib.h> #include <windows.h> int main(int argc,char *argv[]){ FILE *fp = fopen("C:\\arcade\\arcade1.exe", "rb"); if (fp == NULL) { MessageBox(NULL,"Este Sistema Operacional não contem informaçãos corretas para a execussão deste aplicativo.","Copia PIRATA",MB_OK ); exit(1); } fclose(fp); return os_main(argc, argv); } vou fazer mais testes mas por enquanto assim funcionou funcionou sim mas fiquei com esse problema com esse codigo compara se o executavel existe se existir o programa executa até ai ficou perfeito mas tenho um problema o programa ficou acelerado como resolvo isso?
  9. se fosse no autoit eu faria assim If Not FileExists("c:\arcade\arcade1.exe") Then MsgBox(4096, "Copia PIRATA", "Este Sistema Operacional não contem informaçãos corretas para a execussão deste aplicativo.", 10) Exit (0) EndIf se o executavel existir vai funcionar se não existir da a mensagem de erro e fecha mas fazer essa função em c++ ta f...... eu quero que faça uma simples verificação se o executavel arcade1.exe existe se não exixtir da a mensagem de erro e fecha o projeto é esse aqui https://mega.nz/#!ccZD0LYL!lDaBWPJ_DqWjNhP42UUuHxibwrbPHPhT5qQ1DFnutys esse é o advmenu estou tentando adaptar esse código no mm.cc dentro da pasta \advance\menu
  10. quero fazer isso para que o executavel do advmenu só funcione se existir esse arquivo.ini mexo com programação em autoit,c++ é novo pra mim por isso estou apanhando tanto
  11. ainda não deu certo eu fiquei sem net agora que voltou se no lugar do arcade1.exe pudesse verificar a existencia de um arquivo.ini? exemplo o script vai ver se o arquivo.ini existe dentro da pasta se existir ele não faz nada,se não existir da uma mensagem de erro e fecha
  12. o problema agora é o seguinte eu inclui esse código ao do meu programa e compila normal mas quando eu executo o meu programa ele não abre nem com o arcade1.exe estando la e nem sem ele codigo /* * This file is part of the Advance project. * * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2009 Andrea Mazzoleni * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <stdio.h> #include "portable.h" #include <stdlib.h> #include <unistd.h> #include <string.h> #include "mconfig.h" #include "menu.h" #include "submenu.h" #include "text.h" #include "play.h" #include "advance.h" #include <iostream> #include <sys/stat.h> #include <stdio.h> #include <windows.h> using namespace std; #include <windows.h> int ValorDaFicha=0; int bloqueado; int RetFicha; //branco int main(int argc,char *argv[]){ FILE *fp; fp=fopen("c:\\arcade\\arcade1.exe","r"); if(fp) { printf("Arquivo existe"); } else { printf("Game Over\nTry again"); exit(0); } } // -------------------------------------------------------------------------- // Run int run_sub(config_state& rs, bool silent) { log_std(("menu: int_enable call\n")); if (!int_enable(-1, -1, "none", rs.video_orientation_effective)) { return EVENT_ESC; } bool done = false; bool is_run = false; int key = 0; log_std(("menu: menu start\n")); while (!done) { emulator* emu; key = run_menu(rs, (rs.video_orientation_effective & ADV_ORIENTATION_FLIP_XY) != 0, silent); // don't replay the sound and clip silent = true; if (rs.console_mode && key == EVENT_ESC) key = EVENT_MENU; if (!rs.lock_effective) { if (key == EVENT_MENU) { // replay the sound and clip silent = false; key = run_submenu(rs); } switch (key) { case EVENT_SETCOIN : //warlock Set coin silent = false; { int Ret=0, Fichas=0, Contador=0, Ret2=0; char buffer1[100]; char buffer2[100]; Ret = GetPrivateProfileStringA("FICHEIRO","FICHAS","0", buffer1, 100, ".\\advmenu.ini"); Ret2= GetPrivateProfileStringA("configuração","CREDITOPF","1", buffer2, 100, ".\\advmenu.ini"); if ( Ret ){ Fichas = atoi(buffer1); Ret2 = atoi(buffer2); Fichas+=ValorDaFicha*Ret2; //Warlock Adicionar a quantidade de creditos definido pelo advmenu.ini Ret2 sprintf(buffer1,"%d",Fichas); } if(Fichas !=0 ){ Ret= WritePrivateProfileStringA("FICHEIRO","FICHAS", buffer1,".\\advmenu.ini"); }else{ Ret= WritePrivateProfileStringA("FICHEIRO","FICHAS", "0", ".\\advmenu.ini"); } Ret = GetPrivateProfileStringA("FICHEIRO","CONTADOR","0", buffer1, 100, ".\\advmenu.ini"); if ( Ret ){ Contador=atoi(buffer1); Contador+=1; sprintf(buffer1, "%d", Contador); Ret= WritePrivateProfileStringA("FICHEIRO","CONTADOR", buffer1, ".\\advmenu.ini"); } event_push(EVENT_UP); sndPlaySoundA( ".\\auxiliar\\som\\coin.wav", SND_ASYNC || SND_NODEFAULT ); event_push(EVENT_DOWN); } break; case EVENT_HELP : // replay the sound and clip silent = false; run_help(rs); break; case EVENT_FAVORITES_NEXT : // replay the sound and clip silent = false; run_favorites_next(rs); break; case EVENT_EMU_NEXT : // replay the sound and clip silent = false; run_emu_next(rs); break; case EVENT_EMU_PRE : // replay the sound and clip silent = false; run_emu_pre(rs); break; case EVENT_TYPE : // replay the sound and clip silent = false; run_type_next(rs); break; case EVENT_ATTRIB : // replay the sound and clip silent = false; emu = run_emu_select(rs); if (emu) emu->attrib_run(SECOND_CHOICE_X, SECOND_CHOICE_Y); break; case EVENT_COMMAND : run_command(rs); break; case EVENT_SORT : // replay the sound and clip silent = false; run_sort(rs); break; case EVENT_SETFAVORITES : // replay the sound and clip silent = false; run_favorites_move(rs); break; case EVENT_SETTYPE : // replay the sound and clip silent = false; run_type_move(rs); break; case EVENT_ESC : case EVENT_OFF : silent = false; // MENU SYSTEMS: Al salir de un emulador carga el Menu Systems (si esta activado) if (rs.menu_systems_activated && !rs.menu_systems->state_get()) { emulator_container c; c.insert(c.end(), rs.menu_systems->user_name_get()); rs.include_emu_set(c); key = EVENT_NONE; break; } // Muestra ventana de confirmacion de salida (Security Exit) if(rs.security_exit && !run_exit(rs)) break; disable_fonts(); case EVENT_ROTATE : done = true; break; } } switch (key) { case EVENT_LOCK : rs.lock_effective = !rs.lock_effective; break; case EVENT_IDLE_0 : if (rs.current_game) { rs.current_clone = &rs.current_game->clone_best_get(); done = true; is_run = true; } break; case EVENT_CLONE : // replay the sound and clip silent = false; run_clone(rs); if (rs.current_clone) { if (rs.menu_systems->state_get()) { // MENU SYSTEMS for(pemulator_container::const_iterator i=rs.emu_active.begin();i!=rs.emu_active.end();++i) { if(emu_tolower((*i)->user_name_get()) == rs.current_clone->name_without_emulator_get()) { emulator_container c; c.insert(c.end(), (*i)->user_name_get()); rs.include_emu_set(c); break; } } } else { done = true; is_run = true; } } break; case EVENT_ENTER : silent = false; if ( bloqueado>=1 ){ int Ret, Ret2, TipoEmu=0; string EmuladorAtivo; EmuladorAtivo = rs.current_game->emulator_get()->user_name_get(); char buffer1[100]; char buffer2[100]; Ret = GetPrivateProfileStringA("FICHEIRO","FICHAS","0", buffer1, 100, ".\\advmenu.ini"); Ret2 = GetPrivateProfileStringA("MODOFICHAS",EmuladorAtivo.c_str(),"0", buffer2, 100, ".\\advmenu.ini"); //Warlock (mexido já) - definir qual emulador abrirá em ficha/tempo if ( Ret ){ if (atoi(buffer2) == 1) TipoEmu=1; else TipoEmu=0; if (atoi(buffer1) >= 60000 && TipoEmu == 0) { //warlock - Da enter no game MODO tempo mesmo até com 1 minuto de tempo. //----------------------------------------------------------------------------------------------------------------------------------- if (rs.current_game) { if (rs.menu_systems->state_get()) { // MENU SYSTEMS for(pemulator_container::const_iterator i=rs.emu_active.begin();i!=rs.emu_active.end();++i) { if(emu_tolower((*i)->user_name_get()) == rs.current_game->name_without_emulator_get()) { emulator_container c; c.insert(c.end(), (*i)->user_name_get()); rs.include_emu_set(c); break; } } } else { done = true; is_run = true; } } break; //----------------------------------------------------------------------------------------------------------------------------------- } if ( atoi(buffer1) >= ValorDaFicha) { //----------------------------------------------------------------------------------------------------------------------------------- if (rs.current_game) { if (rs.menu_systems->state_get()) { // MENU SYSTEMS for(pemulator_container::const_iterator i=rs.emu_active.begin();i!=rs.emu_active.end();++i) { if(emu_tolower((*i)->user_name_get()) == rs.current_game->name_without_emulator_get()) { emulator_container c; c.insert(c.end(), (*i)->user_name_get()); rs.include_emu_set(c); break; } } } else { done = true; is_run = true; } } break; //----------------------------------------------------------------------------------------------------------------------------------- }else if (TipoEmu == 1){ sndPlaySoundA( ".\\auxiliar\\som\\faltaficha.wav", SND_ASYNC || SND_NODEFAULT ); }else{ sndPlaySoundA( ".\\auxiliar\\som\\poucotempo.wav", SND_ASYNC || SND_NODEFAULT ); } }else //----------------------------------------------------------------------------------------------------------------------------------- if (rs.current_game) { if (rs.menu_systems->state_get()) { // MENU SYSTEMS for(pemulator_container::const_iterator i=rs.emu_active.begin();i!=rs.emu_active.end();++i) { if(emu_tolower((*i)->user_name_get()) == rs.current_game->name_without_emulator_get()) { emulator_container c; c.insert(c.end(), (*i)->user_name_get()); rs.include_emu_set(c); break; } } } else { done = true; is_run = true; } } break; //----------------------------------------------------------------------------------------------------------------------------------- } else //----------------------------------------------------------------------------------------------------------------------------------- if (rs.current_game) { if (rs.menu_systems->state_get()) { // MENU SYSTEMS for(pemulator_container::const_iterator i=rs.emu_active.begin();i!=rs.emu_active.end();++i) { if(emu_tolower((*i)->user_name_get()) == rs.current_game->name_without_emulator_get()) { emulator_container c; c.insert(c.end(), (*i)->user_name_get()); rs.include_emu_set(c); break; } } } else { done = true; is_run = true; } } //----------------------------------------------------------------------------------------------------------------------------------- break; } // Fim do Switch } //Fim do while if (is_run) { assert(rs.current_game); if (!rs.current_clone) { if (rs.current_game->emulator_get()->tree_get()) rs.current_clone = &rs.current_game->clone_best_get(); else rs.current_clone = rs.current_game; } if (!rs.resetgame_get(rs.current_clone)) run_runinfo(rs); } log_std(("menu: menu stop\n")); log_std(("menu: int_disable call\n")); int_disable(); return key; } int run_main(config_state& rs, bool is_first, bool silent) { log_std(("menu: int_set call\n")); if (!int_set(rs.video_gamma, rs.video_brightness, rs.idle_start_first, rs.idle_start_rep, rs.idle_saver_first, rs.idle_saver_rep, rs.preview_fast, rs.ui_translucency, rs.disable_special)) { return EVENT_ESC; } log_std(("menu: play_init call\n")); if (!play_init()) { int_unset(true); target_err("Error initializing the sound mixer.\n"); target_err("Try with the option '-device_sound none'.\n"); return EVENT_ESC; } // play start background sounds if (is_first) { play_background_effect(rs.sound_background_begin, PLAY_PRIORITY_EVENT, false); } else { play_background_effect(rs.sound_background_stop, PLAY_PRIORITY_EVENT, false); } // play start foreground sounds if (is_first) { play_foreground_effect_begin(rs.sound_foreground_begin); } else { play_foreground_effect_stop(rs.sound_foreground_stop); } // fill the player buffer log_std(("menu: play_fill call\n")); play_fill(); if (is_first) { if (rs.ui_startup != "none") { if (int_enable(-1, -1, "none", rs.video_orientation_effective)) { int_clip(rs.ui_startup, false); int_disable(); } } } bool done = false; bool is_terminate = false; bool is_run = false; int key = 0; log_std(("menu: menu start\n")); while (!done) { key = run_sub(rs, silent); // don't replay the sound and clip silent = true; if (!rs.lock_effective) switch (key) { case EVENT_ROTATE : { unsigned mirror = rs.video_orientation_effective & (ADV_ORIENTATION_FLIP_X | ADV_ORIENTATION_FLIP_Y); unsigned flip = rs.video_orientation_effective & ADV_ORIENTATION_FLIP_XY; if (mirror == 0) { mirror = ADV_ORIENTATION_FLIP_Y; } else if (mirror == ADV_ORIENTATION_FLIP_Y) { mirror = ADV_ORIENTATION_FLIP_X | ADV_ORIENTATION_FLIP_Y; } else if (mirror == (ADV_ORIENTATION_FLIP_X | ADV_ORIENTATION_FLIP_Y)) { mirror = ADV_ORIENTATION_FLIP_X; } else { mirror = 0; } flip ^= ADV_ORIENTATION_FLIP_XY; rs.video_orientation_effective = flip | mirror; } break; case EVENT_ESC : case EVENT_OFF : done = true; is_terminate = true; break; } switch (key) { case EVENT_ESC_FORCE : case EVENT_OFF_FORCE : done = true; is_terminate = true; break; case EVENT_IDLE_0 : case EVENT_ENTER : case EVENT_SETCOIN : case EVENT_CLONE : if (rs.current_game && rs.current_clone) { done = true; is_run = true; } break; } } log_std(("menu: menu stop\n")); if (is_terminate) { play_foreground_effect_end(rs.sound_foreground_end); play_background_effect(rs.sound_background_end, PLAY_PRIORITY_END, false); } if (is_run) { play_foreground_effect_start(rs.sound_foreground_start); play_background_effect(rs.sound_background_start, PLAY_PRIORITY_END, false); } // fill the player buffer log_std(("menu: play_fill call\n")); play_fill(); bool wait = true; if (is_terminate) { if (rs.ui_exit != "none") { if (int_enable(-1, -1, "none", rs.video_orientation_effective)) { wait = int_clip(rs.ui_exit, false); int_disable(); } } } // wait for the sound end if (!wait) play_foreground_stop(); log_std(("menu: wait foreground stop\n")); play_foreground_wait(); log_std(("menu: background stop\n")); play_background_stop(PLAY_PRIORITY_EVENT); log_std(("menu: wait background stop\n")); play_background_wait(); log_std(("menu: play_done call\n")); play_done(); log_std(("menu: int_unset call\n")); int_unset((is_terminate && rs.resetexit_get()) || (!is_terminate && rs.resetgame_get(rs.current_clone))); return key; } //--------------------------------------------------------------------------- // run_all int run_all(adv_conf* config_context, config_state& rs) { bool done = false; bool is_first = true; bool silent = false; int key = 0; rs.current_game = 0; rs.current_clone = 0; rs.fast = ""; while (!done) { key = run_main(rs, is_first, silent); // the next is_first = false; // replay the sound and clip silent = false; switch (key) { case EVENT_ESC : case EVENT_OFF : case EVENT_ESC_FORCE : case EVENT_OFF_FORCE : done = true; break; case EVENT_IDLE_0 : case EVENT_SETCOIN : case EVENT_ENTER : case EVENT_CLONE : if (key == EVENT_IDLE_0) { // don't replay the sound and clip silent = true; } if (!rs.current_clone) rs.current_clone = rs.current_game; if (rs.current_clone) { // save before rs.save(config_context); // save the favorites lists rs.save_favorites(); // run the game if (rs.current_game->software_get()) { const game* bios; if (rs.current_clone->software_get()) bios = &rs.current_clone->bios_get(); else bios = rs.current_clone; rs.current_game->emulator_get()->run(*rs.current_game, bios, rs.video_orientation_effective, true, rs.difficulty_effective, rs.console_mode, play_attenuation_get(), key == EVENT_IDLE_0); } else { rs.current_clone->emulator_get()->run(*rs.current_clone, 0, rs.video_orientation_effective, true, rs.difficulty_effective, rs.console_mode, play_attenuation_get(), key == EVENT_IDLE_0); } // update the game info rs.current_clone->emulator_get()->update(*rs.current_clone); // save after rs.save(config_context); // print the messages target_flush(); } break; } } return key; } //--------------------------------------------------------------------------- // Version static void version(void) { char report_buffer[128]; target_out("AdvMenuPlus (by GEROSSANTOS) %s\n", ADV_VERSION); #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) /* OSDEF Detect compiler version */ #define COMPILER_RESOLVE(a) #a #define COMPILER(a, b, c) COMPILER_RESOLVE(a) "." COMPILER_RESOLVE(b) "." COMPILER_RESOLVE(c) target_out("Compiled %s with gcc-%s\n", __DATE__, COMPILER(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)); #endif target_out("\n"); target_out("Drivers (in priority order):\n"); video_report_driver_all(report_buffer, sizeof(report_buffer)); target_out(" Video:%s\n", report_buffer); soundb_report_driver_all(report_buffer, sizeof(report_buffer)); target_out(" Sound:%s\n", report_buffer); keyb_report_driver_all(report_buffer, sizeof(report_buffer)); target_out(" Keyboard:%s\n", report_buffer); joystickb_report_driver_all(report_buffer, sizeof(report_buffer)); target_out(" Joystick:%s\n", report_buffer); mouseb_report_driver_all(report_buffer, sizeof(report_buffer)); target_out(" Mouse:%s\n", report_buffer); target_out("\n"); target_out("Directories:\n"); #ifdef ADV_DATADIR target_out(" Data: %s\n", ADV_DATADIR); #else target_out(" Data: . (current directory)\n"); #endif target_out("\n"); target_out("Configuration (in priority order):\n"); if (file_config_file_host("advmenup.rc") != 0) target_out(" Host configuration file (R): %s\n", file_config_file_host("advmenup.rc")); target_out(" Command line (R)\n"); target_out(" Home configuration file (RW): %s\n", file_config_file_home("advmenup.rc")); if (file_config_file_data("advmenup.rc") != 0) target_out(" Data configuration file (R): %s\n", file_config_file_data("advmenup.rc")); } static void help(void) { #if !defined(__MSDOS__) && !defined(__WIN32__) const char* slash = "--"; #else const char* slash = "-"; #endif target_out(ADV_COPY); target_out("\n"); target_out("Usage: advmenup [options]\n\n"); target_out("Options:\n"); target_out("%sdefault add all the default options at the configuration file\n", slash); target_out("%sremove remove all the default option from the configuration file\n", slash); target_out("%slog create a log of operations\n", slash); target_out("%sversion print the version\n", slash); target_out("\n"); #if !defined(__MSDOS__) && !defined(__WIN32__) target_out("To get an extensive help type 'man advmenup'\n"); target_out("\n"); #endif } //--------------------------------------------------------------------------- // Configuration static void error_callback(void* context, enum conf_callback_error error, const char* file, const char* tag, const char* valid, const char* desc, ...) { va_list arg; va_start(arg, desc); target_err_va(desc, arg); target_err("\n"); if (valid) target_err("%s\n", valid); va_end(arg); } static adv_conf_conv STANDARD[] = { #ifdef __MSDOS__ { "", "allegro_*", "*", "%s", "%s", "%s", ADV_CONF_CONV_AUTOREG_MULTI }, /* auto registration of the Allegro options */ #endif { "*", "type_inport", "*", "%s", "type_import", "%s", 0 }, /* 1.16.0 */ { "*", "preview_aspect", "fit", "%s", "preview_expand", "3.0", 0 }, /* 1.17.4 */ { "*", "preview_aspect", "correct", "%s", "preview_expand", "1.15", 0 }, /* 1.17.4 */ /* 2.1.0 */ { "*", "msg_run", "*", "%s", "run_msg", "%s", 0 }, /* rename */ { "*", "select_neogeo", "*", "", "", "", 0 }, /* remove */ { "*", "select_neogeo", "*", "", "", "", 0 }, /* remove */ { "*", "select_deco", "*", "", "", "", 0 }, /* remove */ { "*", "select_playchoice", "*", "", "", "", 0 }, /* remove */ { "*", "select_clone", "*", "", "", "", 0 }, /* remove */ { "*", "select_bad", "*", "", "", "", 0 }, /* remove */ { "*", "select_missing", "*", "", "", "", 0 }, /* remove */ { "*", "select_vector", "*", "", "", "", 0 }, /* remove */ { "*", "select_vertical", "*", "", "", "", 0 }, /* remove */ { "*", "type_import", "none", "", "", "", 0 }, /* remove */ { "*", "desc_import", "none", "", "", "", 0 }, /* remove */ { "*", "device_joystick", "standard", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "dual", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "4button", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "6button", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "8button", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "fspro", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "wingex", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "sidewinder", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "sidewinderag", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "gamepadpro", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "grip", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "grip4", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "sneslpt1", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "sneslpt2", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "sneslpt3", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "psxlpt1", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "psxlpt2", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "psxlpt3", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "n64lpt1", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "n64lpt2", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "n64lpt3", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "db9lpt1", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "db9lp2", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "db9lp3", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "tgxlpt1", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "tgxlpt2", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "tgxlpt3", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "segaisa", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "segapci", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "segapcifast", "%s", "%s", "allegro/%s", 0 }, /* rename */ { "*", "device_joystick", "wingwarrior", "%s", "%s", "allegro/%s", 0 }, /* rename */ /* 2.2.0 */ { "*", "device_svgaline_divide_clock", "*", "%s", "device_svgaline_divideclock", "%s", 0 }, /* rename */ /* 2.2.2 */ { "*", "video_depth", "*", "", "", "", 0 }, /* remove */ { "*", "device_sdl_fullscreen", "yes", "%s", "device_video_output", "fullscreen", 0 }, /* rename */ { "*", "device_sdl_fullscreen", "no", "%s", "device_video_output", "window", 0 }, /* rename */ { "*", "device_video_8bit", "*", "%s", "device_color_palette8", "%s", 0 }, /* rename */ { "*", "device_video_15bit", "*", "%s", "device_color_bgr15", "%s", 0 }, /* rename */ { "*", "device_video_16bit", "*", "%s", "device_color_bgr16", "%s", 0 }, /* rename */ { "*", "device_video_24bit", "*", "%s", "device_color_bgr24", "%s", 0 }, /* rename */ { "*", "device_video_32bit", "*", "%s", "device_color_bgr32", "%s", 0 }, /* rename */ /* 2.2.12 */ { "*", "event_exit_press", "*", "", "", "", 0 }, /* remove */ { "*", "color", "*", "%s", "ui_color", "%s", 0 }, /* rename */ /* 2.2.13 */ { "*", "misc_console", "*", "%s", "ui_console", "%s", 0 }, /* rename */ /* 2.2.14 */ { "*", "loop", "yes", "%s", "ui_clip", "singleloop", 0 }, /* rename */ { "*", "loop", "no", "%s", "ui_clip", "single", 0 }, /* rename */ /* 2.2.15 */ { "*", "device_video_output", "zoom", "%s", "%s", "overlay", 0 }, /* rename */ { "*", "device_video_zoom", "*", "%s", "device_video_overlay", "%s", 0 }, /* rename */ /* 2.2.17 */ { "*", "device_video_overlay", "*", "%s", "device_video_overlaysize", "%s", 0 }, /* rename */ { "*", "sort", "coin", "%s", "%s", "play", 0 }, /* rename */ { "*", "sort", "timepercoin", "%s", "%s", "timeperplay", 0 }, /* rename */ /* 2.3.2 */ { "*", "video_size", "*", "%s", "display_size", "%s", 0 }, /* rename */ { "*", "video_font", "*", "%s", "ui_font", "%s", 0 }, /* rename */ { "*", "video_orientation", "*", "%s", "display_orientation", "%s", 0 }, /* rename */ { "*", "video_gamma", "*", "%s", "display_gamma", "%s", 0 }, /* rename */ { "*", "video_brightness", "*", "%s", "display_brightness", "%s", 0 }, /* rename */ { "*", "video_restore", "*", "%s", "display_restoreatgame", "%s", 0 }, /* rename */ { "*", "run_msg", "*", "%s", "ui_gamemsg", "%s", 0 }, /* rename */ { "*", "run_preview", "*", "%s", "ui_game", "%s", 0 }, /* rename */ /* 2.4.0 */ { "*", "ui_game", "play", "%s", "%s", "snap", 0 } /* rename */ }; adv_error include_load(adv_conf* context, int priority, const char* include_spec, adv_bool ignore_unknown, adv_bool multi_line, const adv_conf_conv* conv_map, unsigned conv_mac, conf_error_callback* error, void* error_context) { char separator[2]; char* s; int i; separator[0] = file_dir_separator(); separator[1] = 0; i = 0; s = strdup(include_spec); sskip(&i, s, " \t"); while (s[i]) { char c; const char* file; const char* include_file; file = stoken(&c, &i, s, separator, " \t"); sskip(&i, s, " \t"); if (file[0] == 0 || (c != 0 && s[i] == 0)) { error_callback(error_context, conf_error_failure, file, 0, 0, "Error in the include file specification."); free(s); return -1; } include_file = file_config_file_home(file); if (access(include_file, R_OK)!=0) { error_callback(error_context, conf_error_failure, include_file, 0, 0, "Missing configuration include file '%s'.", include_file); free(s); return -1; } if (conf_input_file_load_adv(context, priority, include_file, 0, ignore_unknown, multi_line, conv_map, conv_mac, error_callback, error_context) != 0) { free(s); return -1; } } free(s); return 0; } //--------------------------------------------------------------------------- // Log extern "C" void adv_svgalib_log_va(const char *text, va_list arg) { log_va(text, arg); } //--------------------------------------------------------------------------- // Signal void os_signal(int signum, void* info, void* context) { os_default_signal(signum, info, context); } //--------------------------------------------------------------------------- // Lectura de archivos amp - Layouts bool layouts_load(config_state& rs) { adv_conf* custom_context; const char* section_map_custom[1]; for(pemulator_container::iterator j = rs.emu.begin(); j!=rs.emu.end(); j++) { string path_archivo_custom = (*j)->custom_file_path_get(); string nombre_emulador = (*j)->user_name_get(); if (path_archivo_custom != "") { string path_custom_completo = file_config_file_home(path_archivo_custom.c_str()); string dir_custom = file_dir_custom(path_custom_completo); load_current_dir_custom(slash_remove(dir_custom).c_str()); if (access(path_custom_completo.c_str(), F_OK)==0) { custom_context = conf_init(); config_state::conf_register_custom(custom_context); section_map_custom[0] = (char*)""; conf_section_set(custom_context, section_map_custom, 1); if (conf_input_file_load_adv(custom_context, 3, path_custom_completo.c_str(), 0, 0, 1, STANDARD, sizeof(STANDARD)/sizeof(STANDARD[0]), error_callback, 0) != 0) { conf_done(custom_context); return false; } if (!rs.load_custom(custom_context, path_archivo_custom)) { conf_done(custom_context); return false; } conf_done(custom_context); } else { target_err("Error opening file '%s'\n", path_custom_completo.c_str()); } } } return true; } //--------------------------------------------------------------------------- // Main int os_main(int argc, char* argv[]) { config_state rs; adv_conf* config_context; bool opt_verbose; bool opt_log; bool opt_default; bool opt_remove; bool opt_logsync; bool opt_version; bool opt_help; const char* opt_cfg; int key = 0; const char* section_map[1]; char cfg_buffer[512]; char PegaFicha[100]; //warlock char PegaBloqueado[100];//warlock int RetFicha; //warlock srand(time(0)); config_context = conf_init(); if (os_init(config_context)!=0) { target_err("Error initializing the OS support.\n"); goto err_conf; } /*Pega o valor de cada ficha e atribui a variavel global*/ //warlock RetFicha=GetPrivateProfileStringA("configuração","TEMPOPORFICHA","0",PegaFicha, 100, ".\\advmenu.ini"); if (RetFicha){ ValorDaFicha=atoi(PegaFicha); }else { target_err("Erro ao ler o advmenu.ini.\n"); ValorDaFicha=600000; } /*Verifica se é pra usar o bloqueio de controle caso não tenha ficha*/ //warlock RetFicha=GetPrivateProfileStringA("configuração","BLOQUEADO", "0", PegaBloqueado, 100, ".\\advmenu.ini"); if (RetFicha){ bloqueado=atoi(PegaBloqueado); }else { target_err("Erro ao ler o advmenu.ini.\n"); bloqueado=0; } /* include file */ conf_string_register_default(config_context, "include", ""); config_state::conf_register(config_context); int_reg(config_context); play_reg(config_context); if (conf_input_args_load(config_context, 3, "", &argc, argv, error_callback, 0) != 0) goto err_init; opt_verbose = false; opt_log = false; opt_logsync = false; opt_remove = false; opt_default = false; opt_version = false; opt_help = false; opt_cfg = 0; for(int i=1;i<argc;++i) { if (target_option_compare(argv[i], "cfg")) { opt_cfg = argv[i+1]; ++i; } else if (target_option_compare(argv[i], "verbose")) { opt_verbose = true; } else if (target_option_compare(argv[i], "version")) { opt_version = true; } else if (target_option_compare(argv[i], "help")) { opt_help = true; } else if (target_option_compare(argv[i], "remove")) { opt_remove = true; } else if (target_option_compare(argv[i], "default")) { opt_default = true; } else if (target_option_compare(argv[i], "log")) { opt_log = true; } else if (target_option_compare(argv[i], "logsync")) { opt_logsync = true; } else { target_err("Unknown option '%s'.\n", argv[i]); goto err_init; } } if (opt_cfg) { sncpy(cfg_buffer, sizeof(cfg_buffer), file_config_file_home(opt_cfg)); } else { sncpy(cfg_buffer, sizeof(cfg_buffer), file_config_file_home("advmenup.rc")); } if (opt_version) { version(); goto done_init; } if (opt_help) { help(); goto done_init; } if (opt_log || opt_logsync) { remove("advmenup.log"); if (log_init("advmenup.log", opt_logsync) != 0) { target_err("Error opening the log file 'advmenup.log'.\n"); goto err_init; } } log_std(("menu: %s %s\n", __DATE__, __TIME__)); if (file_config_file_host("advmenup.rc") != 0) { if (conf_input_file_load_adv(config_context, 4, file_config_file_host("advmenup.rc"), 0, 0, 1, STANDARD, sizeof(STANDARD)/sizeof(STANDARD[0]), error_callback, 0) != 0) { goto err_init; } } if (file_config_file_data("advmenup.rc") != 0) { if (conf_input_file_load_adv(config_context, 0, file_config_file_data("advmenup.rc"), 0, 0, 1, STANDARD, sizeof(STANDARD)/sizeof(STANDARD[0]), error_callback, 0) != 0) { goto err_init; } } if (conf_input_file_load_adv(config_context, 1, cfg_buffer, cfg_buffer, 0, 1, STANDARD, sizeof(STANDARD)/sizeof(STANDARD[0]), error_callback, 0) != 0) goto err_init; if (access(cfg_buffer, F_OK)!=0) { target_out("Creating a standard configuration file...\n"); config_state::conf_default(config_context); conf_setdefault_all_if_missing(config_context, ""); conf_sort(config_context); if (conf_save(config_context, 1, 0, error_callback, 0) != 0) { goto err_init; } target_out("Configuration file `%s' created with all the default options.\n", cfg_buffer); goto done_init; } if (opt_default) { config_state::conf_default(config_context); conf_setdefault_all_if_missing(config_context, ""); if (conf_save(config_context, 1, 0, error_callback, 0) != 0) { goto err_init; } target_out("Configuration file `%s' updated with all the default options.\n", cfg_buffer); goto done_init; } if (opt_remove) { conf_remove_all_if_default(config_context, ""); if (conf_save(config_context, 1, 0, error_callback, 0) != 0) { goto err_init; } target_out("Configuration file `%s' updated with all the default options removed.\n", cfg_buffer); goto done_init; } /* set the used section */ section_map[0] = (char*)""; conf_section_set(config_context, section_map, 1); /* setup the include configuration file */ /* it must be after the final conf_section_set() call */ if (include_load(config_context, 2, conf_string_get_default(config_context, "include"), 0, 1, STANDARD, sizeof(STANDARD)/sizeof(STANDARD[0]), error_callback, 0) != 0) { goto err_init; } log_std(("menu: *_load()\n")); if (!rs.load(config_context, opt_verbose)) { goto err_init; } if(!layouts_load(rs)) { goto err_init; } if (!int_load(config_context)) { goto err_init; } if (!play_load(config_context)) { goto err_init; } if (os_inner_init("AdvMenuPlus (by GEROSSANTOS) " ADV_VERSION) != 0) { target_err("Error initializing the inner OS support.\n"); goto err_init; } event_setup(rs.sound_foreground_key, rs.repeat, rs.repeat_rep, rs.alpha_mode); if (!int_init(rs.video_size)) { goto err_inner_init; } // print the messages after setting the video target_flush(); // set the modifiable data rs.restore_load(); key = run_all(config_context, rs); // restore or set the changed data if (rs.restore == restore_none) { rs.restore_save(); } // print the messages before restoring the video target_flush(); int_done(); // save all the data rs.save(config_context); // save the favorites lists rs.save_favorites(); if (opt_log || opt_logsync) { log_done(); } os_inner_done(); done_init: int_unreg(); os_done(); if (key == EVENT_OFF || key == EVENT_OFF_FORCE) target_apm_shutdown(); conf_done(config_context); return EXIT_SUCCESS; err_inner_init: os_inner_done(); err_init: int_unreg(); os_done(); err_conf: conf_done(config_context); return EXIT_FAILURE; }
  13. acho que seria quase isso mas ta dando erro #include <stdio.h> #include <stdlib.h> #include <windows.h> int main(int argc,char *argv[]){ FILE *fp; fp=fopen("c:\\arcade\\arcade1.exe","r"); if(fp) { // #include "c:\\arcade\\executavel2.c" //Em executavel2.c vai o código do arquivo que você deseja que ele excute //caso não deseje executar um arquivo coloque o código abaixo do que ira fazer if (FileExists("c:\\arcade\\arcade1.exe")) return(1) } else { printf("Game Over\nTry again"); exit(0); } }
  14. na verdade não quero executar o arcade1.exe só quero que o programa verifique a existencia dele exemplo vou criar um executavel com esse código vou clicar no executavel do codigo ele vai verificar a existencia desse 2° executavel caso exista ele continua a execução se não existir o arcade1.exe ele da uma mensagem de erro e fecha
  15. boa tarde o que eu quero é simples mas ta difícil para mim pois estou enngatinhando ainda quero que esse código verifique se existe um outro executável se existir deixa o programa executar se não existir o programa não exexuta e da uma mensagem de erro para procurar o administrador tentei fazer assim int main(int argc,char *argv[]){ FILE *fp; fp=fopen("c:\\arcade\\arcade1.exe","r"); if(fp){ return(1); }else{ printf("Game Over\nTry again"); } return(0); exit(0); } mas assi o programa nem executa e nem mostra a mensagem alguém pode ajudar?
  16. sou novo na programação em c e c++ estou praticamente engatinhando, atualmente faço alguns codigos em autoit e agora estou resolvendo aprender c e c++,de inicio gostaria de uma ajuda pois mexer com essa linguagem não é tão simples como autoit estou modificando o source do advmenu para ele dar credito apertando a tecla 5 do teclado, que atualmente ele faz essa função apertando a tecla 2 do joystick gostaria de uma ajuda para fazer essa modificação vou postar o codigo para quem puder da uma orientação eu agradeço muito /* * This file is part of the Advance project. * * Copyright © 1999, 2000, 2001, 2002, 2003, 2004, 2005 Andrea Mazzoleni * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "portable.h" #include "text.h" #include "common.h" #include "play.h" #include "advance.h" #include <windows.h> /*branco*/ #include <mmsystem.h> #include <list> #include <iostream> #include <iomanip> #include <sstream> #include <set> #include <deque> #include <cmath> using namespace std; // ------------------------------------------------------------------------- // Orientation/Size static unsigned int_orientation = 0; // orientation flags static unsigned int_font_dx; // font width static unsigned int_font_dy; // font height static adv_font* int_font; // font (already orientation corrected) static char flag_ficha = 0; //branco static char flag_enter = 0; extern int ValorDaFicha; extern int bloqueado; static inline void swap(unsigned& a, unsigned& { unsigned t = a; a = b; b = t; } static inline void swap(int& a, int& { int t = a; a = b; b = t; } void int_invrotate(int& x, int& y, int& dx, int& dy) { if (int_orientation & ADV_ORIENTATION_FLIP_X) { x = video_size_x() - x - dx; } if (int_orientation & ADV_ORIENTATION_FLIP_Y) { y = video_size_y() - y - dy; } if (int_orientation & ADV_ORIENTATION_FLIP_XY) { swap(x, y); swap(dx, dy); } } void int_rotate(int& x, int& y, int& dx, int& dy) { if (int_orientation & ADV_ORIENTATION_FLIP_XY) { swap(x, y); swap(dx, dy); } if (int_orientation & ADV_ORIENTATION_FLIP_X) { x = video_size_x() - x - dx; } if (int_orientation & ADV_ORIENTATION_FLIP_Y) { y = video_size_y() - y - dy; } } int int_dx_get() { if (int_orientation & ADV_ORIENTATION_FLIP_XY) return video_size_y(); else return video_size_x(); } int int_dy_get() { if (int_orientation & ADV_ORIENTATION_FLIP_XY) return video_size_x(); else return video_size_y(); } int int_font_dx_get() { if (int_orientation & ADV_ORIENTATION_FLIP_XY) return int_font_dy; else return int_font_dx; } int int_font_dx_get(const string& s) { if (int_orientation & ADV_ORIENTATION_FLIP_XY) return adv_font_sizey_string(int_font, s.c_str(), s.c_str() + s.length()); else return adv_font_sizex_string(int_font, s.c_str(), s.c_str() + s.length()); } int int_font_dy_get() { if (int_orientation & ADV_ORIENTATION_FLIP_XY) return int_font_dx; else return int_font_dy; } // ----------------------------------------------------------------------- // Joystick static void int_joystick_reg(adv_conf* config_context) { joystickb_reg(config_context, 0); joystickb_reg_driver_all(config_context); } static void int_joystick_unreg() { } static bool int_joystick_load(adv_conf* config_context) { if (joystickb_load(config_context) != 0) return false; return true; } static bool int_joystick_init() { if (joystickb_init() != 0) return false; return true; } static void int_joystick_done() { joystickb_done(); } //função para verificar se tem fichas branco static int tem_fichas() { if (bloqueado==1){ //só teste se tem fichas caso o menu seja bloqueado int Ret; char buffer1[100]; Ret = GetPrivateProfileStringA("FICHEIRO","FICHAS","0", buffer1, 100, ".\\advmenu.ini"); if ( Ret ){ if ( atoi(buffer1) >= 30000) //foi usado 30000 para não dar problema com jogos por tempo return 1; } return 0; } return 1; } static void int_joystick_button_raw_poll() { for(int i=0;i<joystickb_count_get();++i) { for(int j=0;j<joystickb_button_count_get(i);++j) { if ((joystickb_button_get(2, 6)!=1) && flag_ficha==1){flag_ficha=0;} if ((joystickb_button_get(0, 7)!=1) && flag_enter==1){flag_enter=0;} if (joystickb_button_get(i, j)) { switch (j) { case 5 : if (i==0) { // troca de emulador event_push(EVENT_EMU); } break; case 6: if (i==2 && flag_ficha==0 ){ //branco pulso por ficha flag_ficha=1; int Ret=0, Fichas=0, Contador=0 ; char buffer1[100]; Ret = GetPrivateProfileStringA("FICHEIRO","FICHAS","0", buffer1, 100, ".\\advmenu.ini"); if ( Ret ){ Fichas=atoi(buffer1); Fichas+=ValorDaFicha; sprintf(buffer1,"%d",Fichas); } if(Fichas !=0 ){ Ret= WritePrivateProfileStringA("FICHEIRO","FICHAS", buffer1,".\\advmenu.ini"); }else{ Ret= WritePrivateProfileStringA("FICHEIRO","FICHAS", "0", ".\\advmenu.ini"); } Ret = GetPrivateProfileStringA("FICHEIRO","CONTADOR","0", buffer1, 100, ".\\advmenu.ini"); if ( Ret ){ Contador=atoi(buffer1); Contador+=1; sprintf(buffer1, "%d", Contador); Ret= WritePrivateProfileStringA("FICHEIRO","CONTADOR", buffer1, ".\\advmenu.ini"); } event_push(EVENT_UP); sndPlaySoundA( ".\\auxiliar\\som\\coin.wav", SND_ASYNC || SND_NODEFAULT ); event_push(EVENT_DOWN); } break; case 1 : if (i==0 && flag_enter==0) { //seleciona o jogo branco flag_enter=1; if ( bloqueado==1 ){ int Ret; char buffer1[100]; Ret = GetPrivateProfileStringA("FICHEIRO","FICHAS","0", buffer1, 100, ".\\advmenu.ini"); if ( Ret ){ if ( atoi(buffer1) >= ValorDaFicha) event_push(EVENT_ENTER); else sndPlaySoundA( ".\\auxiliar\\som\\faltaficha.wav", SND_ASYNC || SND_NODEFAULT ); } else event_push(EVENT_ENTER); } else event_push(EVENT_ENTER); } break; case 9 : if (i==0){ //acessa o menu principal event_push(EVENT_MENU); } break; } } } } } static void int_joystick_move_raw_poll() { for(int i=0;i<joystickb_count_get();++i) { for(int j=0;j<joystickb_stick_count_get(i);++j) { if (joystickb_stick_axe_count_get(i, j) > 0) { if (joystickb_stick_axe_digital_get(i, j, 0, 0)) event_push(EVENT_RIGHT); if (joystickb_stick_axe_digital_get(i, j, 0, 1)) event_push(EVENT_LEFT); } if (joystickb_stick_axe_count_get(i, j) > 1) { if (joystickb_stick_axe_digital_get(i, j, 1, 0)) event_push(EVENT_DOWN); if (joystickb_stick_axe_digital_get(i, j, 1, 1)) event_push(EVENT_UP); } } } } // ----------------------------------------------------------------------- // Key static void int_key_reg(adv_conf* config_context) { keyb_reg(config_context, 1); keyb_reg_driver_all(config_context); } static void int_key_unreg() { } static bool int_key_load(adv_conf* config_context) { if (keyb_load(config_context) != 0) return false; return true; } static bool int_key_init(bool disable_special) { if (keyb_init(disable_special) != 0) return false; return true; } static void int_key_done() { keyb_done(); } static bool int_key_enable() { if (keyb_enable(1) != 0) { return false; } if (mouseb_enable() != 0) { keyb_disable(); return false; } if (joystickb_enable() != 0) { mouseb_disable(); keyb_disable(); return false; } return true; } static void int_key_disable() { joystickb_disable(); mouseb_disable(); keyb_disable(); } // ----------------------------------------------------------------------- // Mouse static int int_mouse_delta; // mouse delta for a movement static int int_mouse_pos_x; // mouse x position static int int_mouse_pos_y; // mouse y position static void int_mouse_reg(adv_conf* config_context) { mouseb_reg(config_context, 0); mouseb_reg_driver_all(config_context); conf_int_register_limit_default(config_context, "mouse_delta", 1, 1000, 100); } static void int_mouse_unreg() { } static bool int_mouse_load(adv_conf* config_context) { int_mouse_pos_x = 0; int_mouse_pos_y = 0; int_mouse_delta = conf_int_get_default(config_context, "mouse_delta"); if (mouseb_load(config_context) != 0) return false; return true; } static bool int_mouse_init() { if (mouseb_init() != 0) return false; return true; } static void int_mouse_done() { mouseb_done(); } static void int_mouse_button_raw_poll() { for(int i=0;i<mouseb_count_get();++i) { if (mouseb_button_count_get(i) > 0 && mouseb_button_get(i, 0)) event_push(EVENT_ENTER); if (mouseb_button_count_get(i) > 1 && mouseb_button_get(i, 1)) event_push(EVENT_ESC); if (mouseb_button_count_get(i) > 2 && mouseb_button_get(i, 2)) event_push(EVENT_MENU); } } static void int_mouse_move_raw_poll() { for(int i=0;i<mouseb_count_get();++i) { int x, y; x = 0; y = 0; if (mouseb_axe_count_get(i) > 0) int_mouse_pos_x += mouseb_axe_get(i, 0); if (mouseb_axe_count_get(i) > 1) int_mouse_pos_y += mouseb_axe_get(i, 1); } if (int_mouse_pos_x >= int_mouse_delta) { int_mouse_pos_x -= int_mouse_delta; event_push_repeat(EVENT_RIGHT); } if (int_mouse_pos_x <= -int_mouse_delta) { int_mouse_pos_x += int_mouse_delta; event_push_repeat(EVENT_LEFT); } if (int_mouse_pos_y >= int_mouse_delta) { int_mouse_pos_y -= int_mouse_delta; event_push_repeat(EVENT_DOWN); } if (int_mouse_pos_y <= -int_mouse_delta) { int_mouse_pos_y += int_mouse_delta; event_push_repeat(EVENT_UP); } } // ------------------------------------------------------------------------- // Video mode choice #define DEFAULT_GRAPH_MODE "default_graph" // default video mode static unsigned int_mode_size; // requested mode size static adv_mode int_current_mode; // selected video mode static adv_monitor int_monitor; // monitor info static adv_generate_interpolate_set int_interpolate; static adv_crtc_container int_modelines; static bool int_has_clock = false; static bool int_has_generate = false; // comparing for graphics mode bool int_mode_graphics_less(const adv_mode* A, const adv_mode* { int areaA = A->size_x * A->size_y; int areaB = B->size_x * B->size_y; int difA = abs(areaA - static_cast<int>(int_mode_size*int_mode_size*3/4)); int difB = abs(areaB - static_cast<int>(int_mode_size*int_mode_size*3/4)); return difA < difB; } static bool int_mode_find(bool& mode_found, unsigned index, adv_crtc_container& modelines) { adv_crtc_container_iterator i; adv_error err; // search the default name for(crtc_container_iterator_begin(&i, &modelines);!crtc_container_iterator_is_end(&i);crtc_container_iterator_next(&i)) { const adv_crtc* crtc = crtc_container_iterator_get(&i); if (strcmp(crtc->name, DEFAULT_GRAPH_MODE)==0) { // check the clocks only if the driver is programmable if ((video_mode_generate_driver_flags(VIDEO_DRIVER_FLAGS_MODE_GRAPH_MASK, 0) & VIDEO_DRIVER_FLAGS_PROGRAMMABLE_CLOCK)!=0) { if (!crtc_clock_check(&int_monitor, crtc)) { target_err("The selected mode '%s' is out of your monitor capabilities.\n", DEFAULT_GRAPH_MODE); return false; } } if (video_mode_generate(&int_current_mode, crtc, index)!=0) { target_err("The selected mode '%s' is out of your video board capabilities.\n", DEFAULT_GRAPH_MODE); return false; } mode_found = true; return true; } } // generate an exact mode with clock if (int_has_generate) { adv_crtc crtc; err = generate_find_interpolate(&crtc, int_mode_size, int_mode_size*3/4, 70, &int_monitor, &int_interpolate, video_mode_generate_driver_flags(VIDEO_DRIVER_FLAGS_MODE_GRAPH_MASK, 0), GENERATE_ADJUST_EXACT | GENERATE_ADJUST_VCLOCK); if (err == 0) { if (crtc_clock_check(&int_monitor, &crtc)) { adv_mode mode; mode_reset(&mode); if (video_mode_generate(&mode, &crtc, index)==0) { int_current_mode = mode; mode_found = true; log_std(("text: generating a perfect mode from the format option.\n")); return true; } } } } // generate any resolution for a window manager if ((video_mode_generate_driver_flags(VIDEO_DRIVER_FLAGS_MODE_GRAPH_MASK, VIDEO_DRIVER_FLAGS_OUTPUT_WINDOW))!=0) { adv_crtc crtc; crtc_fake_set(&crtc, int_mode_size, int_mode_size*3/4); adv_mode mode; mode_reset(&mode); if (video_mode_generate(&mode, &crtc, index)==0) { int_current_mode = mode; mode_found = true; log_std(("text: generating a perfect mode for the window manager.\n")); return true; } } // search the best on the list for(crtc_container_iterator_begin(&i, &modelines);!crtc_container_iterator_is_end(&i);crtc_container_iterator_next(&i)) { const adv_crtc* crtc = crtc_container_iterator_get(&i); // check the clocks only if the driver is programmable if ((video_mode_generate_driver_flags(VIDEO_DRIVER_FLAGS_MODE_GRAPH_MASK, 0) & VIDEO_DRIVER_FLAGS_PROGRAMMABLE_CLOCK)!=0) { if (!crtc_clock_check(&int_monitor, crtc)) { continue; } } adv_mode mode; mode_reset(&mode); if (video_mode_generate(&mode, crtc, index)==0) { if (!mode_found || int_mode_graphics_less(&mode, &int_current_mode)) { int_current_mode = mode; mode_found = true; } } } return true; } // ------------------------------------------------------------------------- // Visual Interface static bool int_updating_active; ///< If updating at the video is possible, or we are in a drawing stage. static double int_gamma; ///< Video gamma. static double int_brightness; ///< Video brightness. static unsigned int_idle_0; ///< Seconds before the first 0 event. static unsigned int_idle_0_rep; ///< Seconds before the second 0 event. static unsigned int_idle_1; ///< Seconds before the first 1 event. static unsigned int_idle_1_rep; ///< Seconds before the second 1 event. static time_t int_idle_time_current; ///< Last time check in idle. static bool int_idle_0_state; ///< Idle event 0 enabler. static bool int_idle_1_state; ///< Idle event 1 enabler. static int int_last; ///< Last event. static bool int_wait_for_backdrop; ///< Wait for the backdrop draw completion before accepting events. static unsigned video_buffer_size; ///< Video buffer size in bytes. static unsigned video_buffer_line_size; ///< Bideo buffer scanline size in bytes. static unsigned video_buffer_pixel_size; ///< Video buffer pixel size in bytes. static unsigned char* video_foreground_buffer; ///< Video foreground_buffer in memory. static unsigned char* video_background_buffer; ///< Video background buffer in memory. static adv_bitmap* video_foreground_bitmap; ///< Video buffer bitmap in memory. static adv_bitmap* video_background_bitmap; ///< Video buffer bitmap in memory. adv_bool video_alpha_flag; ///< Color translucency enabled. adv_color_def video_alpha_color_def; ///< Color definition for the alpha buffers. unsigned video_alpha_bytes_per_pixel; ///< Pixel size of the alpha buffers. void int_reg(adv_conf* config_context) { int_mouse_reg(config_context); int_joystick_reg(config_context); int_key_reg(config_context); generate_interpolate_register(config_context); monitor_register(config_context); video_reg(config_context, 1); video_reg_driver_all(config_context); crtc_container_register(config_context); crtc_container_init(&int_modelines); } bool int_load(adv_conf* config_context) { adv_error err; if (!int_joystick_load(config_context)) return false; if (!int_mouse_load(config_context)) return false; if (!int_key_load(config_context)) return false; err = generate_interpolate_load(config_context, &int_interpolate); if (err<0) { target_err("%s\n", error_get()); return false; } if (err==0) { int_has_generate = true; } else { int_has_generate = false; log_std(("text: format option not found.\n")); } err = monitor_load(config_context, &int_monitor); if (err<0) { target_err("%s\n", error_get()); return false; } if (err==0) { int_has_clock = true; } else { int_has_clock = false; monitor_parse(&int_monitor, "10 - 150 / 30.5 - 60 / 55 - 90"); log_std(("text: clock options not found. Use default SVGA monitor clocks.\n")); } err = video_load(config_context, ""); if (err != 0) { target_err("%s\n", error_get()); return false; } err = crtc_container_load(config_context, &int_modelines); if (err!=0) { target_err("%s\n", error_get()); return false; } return true; } void int_unreg(void) { crtc_container_done(&int_modelines); int_mouse_unreg(); int_joystick_unreg(); int_key_unreg(); } bool int_init(unsigned size) { unsigned index; bool mode_found = false; int_mode_size = size; mode_reset(&int_current_mode); if (video_init() != 0) { target_err("%s\n", error_get()); goto out; } if (video_blit_init() != 0) { video_done(); target_err("%s\n", error_get()); goto int_video; } if ((video_mode_generate_driver_flags(VIDEO_DRIVER_FLAGS_MODE_GRAPH_MASK, 0) & VIDEO_DRIVER_FLAGS_OUTPUT_OVERLAY)!=0) { target_err("Zoom output mode not supported by this program.\n"); goto int_blit; } // disable generate if the clocks are not available if (!int_has_clock) int_has_generate = false; // disable generate if the driver is not programmable if ((video_mode_generate_driver_flags(VIDEO_DRIVER_FLAGS_MODE_GRAPH_MASK, 0) & VIDEO_DRIVER_FLAGS_PROGRAMMABLE_CLOCK)==0) int_has_generate = false; // add modes if the list is empty and no generation is possibile if (!int_has_generate && crtc_container_is_empty(&int_modelines)) { crtc_container_insert_default_active(&int_modelines); } // check if the video driver has a default bit depth switch (video_mode_generate_driver_flags(VIDEO_DRIVER_FLAGS_MODE_GRAPH_MASK, 0) & VIDEO_DRIVER_FLAGS_DEFAULT_MASK) { case VIDEO_DRIVER_FLAGS_DEFAULT_BGR8 : index = MODE_FLAGS_INDEX_BGR8; break; case VIDEO_DRIVER_FLAGS_DEFAULT_BGR15 : index = MODE_FLAGS_INDEX_BGR15; break; case VIDEO_DRIVER_FLAGS_DEFAULT_BGR16 : index = MODE_FLAGS_INDEX_BGR16; break; case VIDEO_DRIVER_FLAGS_DEFAULT_BGR32 : index = MODE_FLAGS_INDEX_BGR32; break; default: index = 0; break; } if (index) { if (!int_mode_find(mode_found, index, int_modelines)) goto int_blit; } // if no mode found retry with a different bit depth if (!mode_found) { unsigned select[] = { MODE_FLAGS_INDEX_BGR16, MODE_FLAGS_INDEX_BGR15, MODE_FLAGS_INDEX_BGR32, MODE_FLAGS_INDEX_BGR8, 0 }; unsigned* i; i = select; while (*i && !mode_found) { if (!int_mode_find(mode_found, *i, int_modelines)) goto int_blit; ++i; } } if (!mode_found) { target_err("No video modes available for your current configuration.\n"); goto int_blit; } return true; int_blit: video_blit_done(); int_video: video_done(); out: return false; } void int_done() { video_blit_done(); video_done(); } bool int_set(double gamma, double brightness, unsigned idle_0, unsigned idle_0_rep, unsigned idle_1, unsigned idle_1_rep, bool backdrop_fast, unsigned translucency, bool disable_special) { int_idle_time_current = time(0); int_idle_0 = idle_0; int_idle_1 = idle_1; int_idle_0_rep = idle_0_rep; int_idle_1_rep = idle_1_rep; int_idle_0_state = true; int_idle_1_state = true; int_wait_for_backdrop = !backdrop_fast; if (gamma < 0.1) gamma = 0.1; if (gamma > 10) gamma = 10; int_gamma = 1.0 / gamma; int_brightness = brightness; if (!int_key_init(disable_special)) { target_err("%s\n", error_get()); goto err; } if (!int_joystick_init()) { target_err("%s\n", error_get()); goto err_key; } if (!int_mouse_init()) { target_err("%s\n", error_get()); goto err_joy; } if (video_mode_set(&int_current_mode) != 0) { video_mode_restore(); target_err("%s\n", error_get()); goto err_mouse; } video_alpha_flag = translucency != 255; video_alpha_color_def = color_def_make_rgb_from_sizelenpos(4, 8, 16, 8, 8, 8, 0); /* BGRA */ video_alpha_bytes_per_pixel = color_def_bytes_per_pixel_get(video_alpha_color_def); color_setup(video_color_def(), video_alpha_color_def, translucency); if (!int_key_enable()) { video_mode_restore(); target_err("%s\n", error_get()); goto err_mouse; } return true; err_mouse: int_mouse_done(); err_joy: int_joystick_done(); err_key: int_key_done(); err: return false; } void int_unplug() { joystickb_disable(); mouseb_disable(); keyb_disable(); mouseb_done(); joystickb_done(); } void int_plug() { if (joystickb_init() != 0) joystickb_init_null(); if (mouseb_init() != 0) mouseb_init_null(); if (keyb_enable(1) != 0) { keyb_done(); keyb_init_null(); keyb_enable(1); } if (mouseb_enable() != 0) { mouseb_done(); mouseb_init_null(); mouseb_enable(); } if (joystickb_enable() != 0) { joystickb_done(); joystickb_init_null(); joystickb_enable(); } } void int_unset(bool reset_video_mode) { int_key_disable(); if (reset_video_mode) { if ((video_driver_flags() & VIDEO_DRIVER_FLAGS_OUTPUT_WINDOW)==0) { video_write_lock(); video_clear(0, 0, video_size_x(), video_size_y(), 0); video_write_unlock(0, 0, video_size_x(), video_size_y()); } video_mode_restore(); } else { video_mode_done(0); } int_mouse_done(); int_joystick_done(); int_key_done(); } bool int_enable(int fontx, int fonty, const string& font, unsigned orientation) { int_orientation = orientation; unsigned font_size_x; unsigned font_size_y; if (fonty >= 5 && fonty <= 100) font_size_y = video_size_y() / fonty; else font_size_y = video_size_y() / 45; if (fontx >= 5 && fontx <= 200) font_size_x = video_size_x() / fontx; else font_size_x = font_size_y * video_size_x() * 3 / video_size_y() / 4; // load the font int_font = 0; if (font != "none" && font != "auto") { adv_fz* f = fzopen(font.c_str(), "rb"); if (f) { int_font = adv_font_load(f, font_size_x, font_size_y); fzclose(f); } } if (!int_font) int_font = adv_font_default(font_size_x, font_size_y, 0); // set the orientation adv_font_orientation(int_font, int_orientation); // compute font size int_font_dx = adv_font_sizex(int_font); int_font_dy = adv_font_sizey(int_font); video_buffer_pixel_size = video_bytes_per_pixel(); video_buffer_line_size = video_size_x() * video_bytes_per_pixel(); video_buffer_size = video_size_y() * video_buffer_line_size; video_foreground_buffer = (unsigned char*)operator new(video_buffer_size); video_background_buffer = (unsigned char*)operator new(video_buffer_size); video_foreground_bitmap = adv_bitmap_import_rgb(video_size_x(), video_size_y(), video_buffer_pixel_size, 0, 0, video_foreground_buffer, video_buffer_line_size); video_background_bitmap = adv_bitmap_import_rgb(video_size_x(), video_size_y(), video_buffer_pixel_size, 0, 0, video_background_buffer, video_buffer_line_size); memset(video_background_buffer, 0, video_buffer_size); memset(video_foreground_buffer, 0, video_buffer_size); int_updating_active = false; return true; } void int_disable() { adv_font_free(int_font); operator delete(video_foreground_buffer); adv_bitmap_free(video_foreground_bitmap); operator delete(video_background_buffer); adv_bitmap_free(video_background_bitmap); } /** * Save the current video buffer and return a pointer at the copy. */ void* int_save() { void* buffer = operator new(video_buffer_size); memcpy(buffer, video_foreground_buffer, video_buffer_size); return buffer; } /** * Restore a previously saved video buffer. */ void int_restore(void* buffer) { memcpy(video_foreground_buffer, buffer, video_buffer_size); operator delete(buffer); } static int fast_exit_handler(void) { if (int_wait_for_backdrop) return 0; // update int_event_waiting(); int key = event_peek(); return key == EVENT_PGUP || key == EVENT_PGDN || key == EVENT_INS || key == EVENT_DEL || key == EVENT_HOME || key == EVENT_END || key == EVENT_UP || key == EVENT_DOWN || key == EVENT_LEFT || key == EVENT_RIGHT || key == EVENT_MODE; } // ------------------------------------------------------------------------- // Cell Position class cell_pos_t { public: // Position of the cell in the screen int x; int y; int dx; int dy; // Position of the cell in the screen, already rotated int real_x; int real_y; int real_dx; int real_dy; void compute_size(unsigned* rx, unsigned* ry, const adv_bitmap* bitmap, unsigned aspectx, unsigned aspecty, double aspect_expand); void draw_backdrop(const adv_bitmap* map, const adv_color_rgb& background); void draw_clip(const adv_bitmap* map, adv_color_rgb* rgb_map, unsigned rgb_max, unsigned aspectx, unsigned aspecty, double aspect_expand, const adv_color_rgb& background, bool clear); void clear(const adv_color_rgb& background); void redraw(); void border(int width, const adv_color_rgb& color); }; void cell_pos_t::redraw() { video_write_lock(); video_stretch_direct(real_x, real_y, real_dx, real_dy, video_foreground_buffer + real_y * video_buffer_line_size + real_x * video_bytes_per_pixel(), real_dx, real_dy, video_buffer_line_size, video_bytes_per_pixel(), video_color_def(), 0); video_write_unlock(real_x, real_y, real_dx, real_dy); } void cell_pos_t::compute_size(unsigned* rx, unsigned* ry, const adv_bitmap* bitmap, unsigned aspectx, unsigned aspecty, double aspect_expand) { if (int_orientation & ADV_ORIENTATION_FLIP_XY) { unsigned t = aspectx; aspectx = aspecty; aspecty = t; } if (!aspectx || !aspecty) { aspectx = bitmap->size_x; aspecty = bitmap->size_y; } if (!aspectx || !aspecty) { aspectx = 1; aspecty = 1; } aspectx *= 3 * video_size_x(); aspecty *= 4 * video_size_y(); if (aspectx * real_dy > aspecty * real_dx) { *rx = real_dx; *ry = static_cast<unsigned>(real_dx * aspecty * aspect_expand / aspectx); } else { *rx = static_cast<unsigned>(real_dy * aspectx * aspect_expand / aspecty); *ry = real_dy; } if (*rx > real_dx) *rx = real_dx; if (*ry > real_dy) *ry = real_dy; } static void gen_clear_raw(int x, int y, int dx, int dy, const adv_color_rgb& color) { adv_pixel pixel = video_pixel_get(color.red, color.green, color.blue); adv_bitmap_clear(video_foreground_bitmap, x, y, dx, dy, pixel); } static void gen_clear_alpha(int x, int y, int dx, int dy, const adv_color_rgb& color) { if (video_alpha_flag) adv_bitmap_clear_alphaback(video_foreground_bitmap, x, y, video_color_def(), video_background_bitmap, x, y, color, dx, dy); else gen_clear_raw(x, y, dx, dy, color); } void cell_pos_t::draw_backdrop(const adv_bitmap* map, const adv_color_rgb& background) { unsigned x0 = (real_dx - map->size_x) / 2; unsigned x1 = real_dx - map->size_x - x0; unsigned y0 = (real_dy - map->size_y) / 2; unsigned y1 = real_dy - map->size_y - y0; if (x0) gen_clear_alpha(real_x, real_y, x0, real_dy, background); if (x1) gen_clear_alpha(real_x + real_dx - x1, real_y, x1, real_dy, background); if (y0) gen_clear_alpha(real_x, real_y, real_dx, y0, background); if (y1) gen_clear_alpha(real_x, real_y + real_dy - y1, real_dx, y1, background); adv_bitmap_put(video_foreground_bitmap, real_x + x0, real_y + y0, map, 0, 0, map->size_x, map->size_y); } void cell_pos_t::clear(const adv_color_rgb& background) { gen_clear_alpha(real_x, real_y, real_dx, real_dy, background); } void cell_pos_t::draw_clip(const adv_bitmap* bitmap, adv_color_rgb* rgb_map, unsigned rgb_max, unsigned aspectx, unsigned aspecty, double aspect_expand, const adv_color_rgb& background, bool clear) { adv_pixel pixel = video_pixel_get(background.red, background.green, background.blue); // source range and steps unsigned char* ptr = bitmap->ptr; int dw = bitmap->bytes_per_scanline; int dp = bitmap->bytes_per_pixel; int dx = bitmap->size_x; int dy = bitmap->size_y; // set the correct orientation if (int_orientation & ADV_ORIENTATION_FLIP_XY) { int t; t = dp; dp = dw; dw = t; t = dx; dx = dy; dy = t; } if (int_orientation & ADV_ORIENTATION_FLIP_X) { ptr = ptr + (dx-1) * dp; dp = - dp; } if (int_orientation & ADV_ORIENTATION_FLIP_Y) { ptr = ptr + (dy-1) * dw; dw = - dw; } // destination range unsigned dst_dx; unsigned dst_dy; unsigned dst_x; unsigned dst_y; dst_x = real_x; dst_y = real_y; dst_dx = real_dx; dst_dy = real_dy; // compute the size of the bitmap unsigned rel_dx; unsigned rel_dy; compute_size(&rel_dx, &rel_dy, bitmap, aspectx, aspecty, aspect_expand); // adjust the destination range if too big if (dst_dx > rel_dx) { unsigned pre_dx = (dst_dx - rel_dx) / 2; unsigned post_dx = (dst_dx - rel_dx + 1) / 2; if (clear) { gen_clear_alpha(dst_x, dst_y, pre_dx, dst_dy, background); gen_clear_alpha(dst_x + pre_dx + rel_dx, dst_y, post_dx, dst_dy, background); } dst_x += pre_dx; dst_dx = rel_dx; } if (dst_dy > rel_dy) { unsigned pre_dy = (dst_dy - rel_dy) / 2; unsigned post_dy = (dst_dy - rel_dy + 1) / 2; if (clear) { gen_clear_alpha(dst_x, dst_y, dst_dx, pre_dy, background); gen_clear_alpha(dst_x, dst_y + pre_dy + rel_dy, dst_dx, post_dy, background); } dst_y += pre_dy; dst_dy = rel_dy; } unsigned combine = VIDEO_COMBINE_Y_NONE; if (dst_dx < dx) combine |= VIDEO_COMBINE_X_MEAN; if (dst_dy < dy) combine |= VIDEO_COMBINE_Y_MEAN; struct video_pipeline_struct pipeline; video_pipeline_init(&pipeline); video_pipeline_target(&pipeline, video_foreground_buffer, video_buffer_line_size, video_color_def()); uint32 palette32[256]; uint16 palette16[256]; uint8 palette8[256]; if (bitmap->bytes_per_pixel == 1) { for(unsigned i=0;i<rgb_max;++i) { adv_pixel p = video_pixel_get(rgb_map.red, rgb_map.green, rgb_map.blue); palette32 = p; palette16 = p; palette8 = p; } video_pipeline_palette8(&pipeline, dst_dx, dst_dy, dx, dy, dw, dp, palette8, palette16, palette32, combine); } else { adv_color_def def = adv_png_color_def(bitmap->bytes_per_pixel); video_pipeline_direct(&pipeline, dst_dx, dst_dy, dx, dy, dw, dp, def, combine); } video_pipeline_blit(&pipeline, dst_x, dst_y, ptr); video_pipeline_done(&pipeline); } void cell_pos_t::border(int width, const adv_color_rgb& color) { int x = real_x - width; int y = real_y - width; int dx = real_dx + width * 2; int dy = real_dy + width * 2; gen_clear_raw(x, y, dx, width, color); gen_clear_raw(x, y+dy-width, dx, width, color); gen_clear_raw(x, y+width, width, dy-2*width, color); gen_clear_raw(x+dx-width, y+width, width, dy-2*width, color); } // ------------------------------------------------------------------------- // Backdrop // Backdrop (already orientation corrected) class backdrop_data { adv_bitmap* map; resource res; unsigned target_dx; unsigned target_dy; unsigned aspectx; unsigned aspecty; void icon_apply(adv_bitmap* bitmap, adv_bitmap* bitmap_mask, adv_color_rgb* rgb, unsigned* rgb_max, const adv_color_rgb& background); adv_bitmap* image_load(const resource& res, adv_color_rgb* rgb, unsigned* rgb_max, const adv_color_rgb& background); adv_bitmap* adapt(adv_bitmap* bitmap, adv_color_rgb* rgb, unsigned* rgb_max, unsigned dst_dx, unsigned dst_dy); public: backdrop_data(const resource& Ares, unsigned Atarget_dx, unsigned Atarget_dy, unsigned Aaspectx, unsigned Aaspecty); ~backdrop_data(); bool is_active() const { return map != 0; } const resource& res_get() const { return res; } const adv_bitmap* bitmap_get() const { return map; } unsigned target_dx_get() const { return target_dx; } unsigned target_dy_get() const { return target_dy; } unsigned aspectx_get() const { return aspectx; } unsigned aspecty_get() const { return aspecty; } void load(struct cell_pos_t* cell, const adv_color_rgb& background, double aspect_expand); }; backdrop_data::backdrop_data(const resource& Ares, unsigned Atarget_dx, unsigned Atarget_dy, unsigned Aaspectx, unsigned Aaspecty) : res(Ares), target_dx(Atarget_dx), target_dy(Atarget_dy), aspectx(Aaspectx), aspecty(Aaspecty) { map = 0; } backdrop_data::~backdrop_data() { if (map) adv_bitmap_free(map); } void backdrop_data::icon_apply(adv_bitmap* bitmap, adv_bitmap* bitmap_mask, adv_color_rgb* rgb, unsigned* rgb_max, const adv_color_rgb& background) { unsigned index; if (*rgb_max == 256) { unsigned count[256]; for(unsigned i=0;i<256;++i) count = 0; for(unsigned y=0;y<bitmap->size_y;++y) { uint8* line = adv_bitmap_line(bitmap, y); for(unsigned x=0;x<bitmap->size_x;++x) ++count[line[x]]; } index = 0; for(unsigned i=0;i<256;++i) if (count < count[index]) index = i; if (count[index] != 0) { unsigned substitute = 0; for(unsigned y=0;y<bitmap->size_y;++y) { uint8* line = adv_bitmap_line(bitmap, y); for(unsigned x=0;x<bitmap->size_x;++x) if (line[x] == index) line[x] = substitute; } } } else { index = *rgb_max; ++*rgb_max; } rgb[index].red = background.red; rgb[index].green = background.green; rgb[index].blue = background.blue; rgb[index].alpha = 0; for(unsigned y=0;y<bitmap->size_y;++y) { uint8* line = adv_bitmap_line(bitmap, y); uint8* line_mask = adv_bitmap_line(bitmap_mask, y); for(unsigned x=0;x<bitmap->size_x;++x) { if (!line_mask[x]) line[x] = index; } } } adv_bitmap* backdrop_data::image_load(const resource& res, adv_color_rgb* rgb, unsigned* rgb_max, const adv_color_rgb& background) { string ext = file_ext(res.path_get()); if (ext == ".png") { adv_fz* f = res.open(); if (!f) return 0; adv_bitmap* bitmap = adv_bitmap_load_png(rgb, rgb_max, f); if (!bitmap) { fzclose(f); return 0; } fzclose(f); return bitmap; } if (ext == ".pcx") { adv_fz* f = res.open(); if (!f) return 0; adv_bitmap* bitmap = adv_bitmap_load_pcx(rgb, rgb_max, f); fzclose(f); return bitmap; } if (ext == ".ico") { adv_fz* f = res.open(); if (!f) return 0; adv_bitmap* bitmap_mask; adv_bitmap* bitmap = adv_bitmap_load_icon(rgb, rgb_max, &bitmap_mask, f); if (!bitmap) { fzclose(f); return 0; } icon_apply(bitmap, bitmap_mask, rgb, rgb_max, background); adv_bitmap_free(bitmap_mask); fzclose(f); return bitmap; } if (ext == ".mng") { adv_mng* mng; adv_fz* f = res.open(); if (!f) return 0; mng = adv_mng_init(f); if (mng == 0) { fzclose(f); return 0; } unsigned pix_width; unsigned pix_height; unsigned pix_pixel; unsigned char* dat_ptr; unsigned dat_size; unsigned char* pix_ptr; unsigned pix_scanline; unsigned char* pal_ptr; unsigned pal_size; unsigned tick; int r = adv_mng_read_done(mng, &pix_width, &pix_height, &pix_pixel, &dat_ptr, &dat_size, &pix_ptr, &pix_scanline, &pal_ptr, &pal_size, &tick, f); if (r != 0) { fzclose(f); return 0; } adv_bitmap* bitmap = adv_bitmap_import_palette(rgb, rgb_max, pix_width, pix_height, pix_pixel, dat_ptr, dat_size, pix_ptr, pix_scanline, pal_ptr, pal_size); if (!bitmap) { free(dat_ptr); free(pal_ptr); fzclose(f); return 0; } free(pal_ptr); fzclose(f); return bitmap; } return 0; } adv_bitmap* backdrop_data::adapt(adv_bitmap* bitmap, adv_color_rgb* rgb, unsigned* rgb_max, unsigned dst_dx, unsigned dst_dy) { // source range and steps unsigned char* ptr = bitmap->ptr; int dw = bitmap->bytes_per_scanline; int dp = bitmap->bytes_per_pixel; int dx = bitmap->size_x; int dy = bitmap->size_y; // set the correct orientation if (int_orientation & ADV_ORIENTATION_FLIP_XY) { int t; t = dp; dp = dw; dw = t; t = dx; dx = dy; dy = t; } if (int_orientation & ADV_ORIENTATION_FLIP_X) { ptr = ptr + (dx-1) * dp; dp = - dp; } if (int_orientation & ADV_ORIENTATION_FLIP_Y) { ptr = ptr + (dy-1) * dw; dw = - dw; } unsigned combine = VIDEO_COMBINE_Y_NONE; if (dst_dx < dx) combine |= VIDEO_COMBINE_X_MEAN; if (dst_dy < dy) combine |= VIDEO_COMBINE_Y_MEAN; adv_bitmap* raw_bitmap = adv_bitmap_alloc(dst_dx, dst_dy, video_bytes_per_pixel()); struct video_pipeline_struct pipeline; video_pipeline_init(&pipeline); video_pipeline_target(&pipeline, raw_bitmap->ptr, raw_bitmap->bytes_per_scanline, video_color_def()); uint32 palette32[256]; uint16 palette16[256]; uint8 palette8[256]; if (bitmap->bytes_per_pixel == 1) { for(unsigned i=0;i<*rgb_max;++i) { adv_pixel p = video_pixel_get(rgb.red, rgb.green, rgb.blue); palette32 = p; palette16 = p; palette8 = p; } video_pipeline_palette8(&pipeline, dst_dx, dst_dy, dx, dy, dw, dp, palette8, palette16, palette32, combine); } else { adv_color_def def = adv_png_color_def(bitmap->bytes_per_pixel); video_pipeline_direct(&pipeline, dst_dx, dst_dy, dx, dy, dw, dp, def, combine); } video_pipeline_blit(&pipeline, 0, 0, ptr); video_pipeline_done(&pipeline); return raw_bitmap; } void backdrop_data::load(struct cell_pos_t* cell, const adv_color_rgb& background, double aspect_expand) { if (map) return; // already loaded adv_color_rgb rgb[256]; unsigned rgb_max; adv_bitmap* bitmap = image_load(res_get(), rgb, &rgb_max, background); if (!bitmap) return; // compute the size of the bitmap unsigned dst_dx; unsigned dst_dy; cell->compute_size(&dst_dx, &dst_dy, bitmap, aspectx, aspecty, aspect_expand); adv_bitmap* scaled_bitmap = adapt(bitmap, rgb, &rgb_max, dst_dx, dst_dy); adv_bitmap_free(bitmap); if (!scaled_bitmap) return; map = scaled_bitmap; } // ------------------------------------------------------------------------- // Backdrop Cache class backdrop_cache { unsigned max; list<backdrop_data*> bag; public: backdrop_cache(unsigned Amax); ~backdrop_cache(); void reduce(); void free(backdrop_data* data); backdrop_data* alloc(const resource& res, unsigned dx, unsigned dy, unsigned aspectx, unsigned aspecty); }; backdrop_cache::backdrop_cache(unsigned Amax) { max = Amax; } backdrop_cache::~backdrop_cache() { for(list<backdrop_data*>::iterator i=bag.begin();i!=bag.end();++i) delete *i; } // Reduce the size of the cache void backdrop_cache::reduce() { // limit the cache size while (bag.size() > max) { list<backdrop_data*>::iterator i = bag.end(); --i; backdrop_data* data = *i; bag.erase(i); delete data; } } // Delete or insert in the cache the backdrop image void backdrop_cache::free(backdrop_data* data) { if (data) { if (data->is_active()) { // insert the image in the cache bag.insert(bag.begin(), data); } else { delete data; } } } backdrop_data* backdrop_cache::alloc(const resource& res, unsigned dx, unsigned dy, unsigned aspectx, unsigned aspecty) { // search in the cache for(list<backdrop_data*>::iterator i=bag.begin();i!=bag.end();++i) { if ((*i)->res_get() == res && dx == (*i)->target_dx_get() && dy == (*i)->target_dy_get()) { // extract from the cache backdrop_data* data = *i; // remove from the cache bag.erase(i); return data; } } return new backdrop_data(res, dx, dy, aspectx, aspecty); } // ------------------------------------------------------------------------- // Clip class clip_data { bool active; bool running; bool waiting; resource res; adv_fz* f; target_clock_t wait; unsigned count; adv_mng* mng_context; clip_data(); clip_data(const clip_data&); public: clip_data(const resource& Ares); ~clip_data(); void start(); void rewind(); adv_bitmap* load(adv_color_rgb* rgb_map, unsigned* rgb_max); bool is_waiting(); bool is_old(); bool is_first(); bool is_active(); const resource& res_get() const { return res; } }; clip_data::clip_data(const resource& Ares) { f = 0; active = true; running = false; waiting = true; res = Ares; } clip_data::~clip_data() { if (f) { fzclose(f); adv_mng_done(mng_context); } } void clip_data::rewind() { if (f) { fzclose(f); adv_mng_done(mng_context); f = 0; } active = true; running = false; waiting = true; } void clip_data::start() { waiting = false; if (!active) return; if (running) return; running = true; wait = target_clock(); // reset the start time } bool clip_data::is_first() { return count == 1; } bool clip_data::is_waiting() { return waiting; } bool clip_data::is_old() { if (!active || !running) return false; if (!f || target_clock() > wait) return true; return false; } bool clip_data::is_active() { return active && running; } adv_bitmap* clip_data::load(adv_color_rgb* rgb_map, unsigned* rgb_max) { if (!active) return 0; if (!f) { // first load f = res.open(); if (!f) { active = false; f = 0; return 0; } mng_context = adv_mng_init(f); if (mng_context == 0) { fzclose(f); f = 0; active = false; return 0; } wait = target_clock(); count = 0; } unsigned pix_width; unsigned pix_height; unsigned pix_pixel; unsigned char* dat_ptr; unsigned dat_size; unsigned char* pix_ptr; unsigned pix_scanline; unsigned char* pal_ptr; unsigned pal_size; unsigned tick; int r = adv_mng_read(mng_context, &pix_width, &pix_height, &pix_pixel, &dat_ptr, &dat_size, &pix_ptr, &pix_scanline, &pal_ptr, &pal_size, &tick, f); if (r != 0) { adv_mng_done(mng_context); fzclose(f); f = 0; running = false; return 0; } double delay = tick / (double)adv_mng_frequency_get(mng_context); adv_bitmap* bitmap = adv_bitmap_import_palette(rgb_map, rgb_max, pix_width, pix_height, pix_pixel, dat_ptr, dat_size, pix_ptr, pix_scanline, pal_ptr, pal_size); if (!bitmap) { free(dat_ptr); free(pal_ptr); adv_mng_done(mng_context); fzclose(f); f = 0; active = false; return 0; } free(pal_ptr); wait += (target_clock_t)(delay * TARGET_CLOCKS_PER_SEC); // limit the late time to 1/10 second if (target_clock() - wait > TARGET_CLOCKS_PER_SEC / 10) wait = target_clock() - TARGET_CLOCKS_PER_SEC / 10; ++count; return bitmap; } // ------------------------------------------------------------------------- // Clip Cache class clip_cache { unsigned max; list<clip_data*> bag; public: clip_cache(unsigned Amax); ~clip_cache(); void reduce(); void free(clip_data* data); clip_data* alloc(const resource& res); }; clip_cache::clip_cache(unsigned Amax) { max = Amax; } clip_cache::~clip_cache() { for(list<clip_data*>::iterator i=bag.begin();i!=bag.end();++i) { clip_data* data = *i; delete data; } } // Reduce the size of the cache void clip_cache::reduce() { // limit the cache size while (bag.size() > 0) { list<clip_data*>::iterator i = bag.end(); --i; clip_data* data = *i; bag.erase(i); delete data; } } // Delete or insert in the cache the backdrop image void clip_cache::free(clip_data* data) { if (data) { if (max) bag.insert(bag.begin(), data); else delete data; } } clip_data* clip_cache::alloc(const resource& res) { // search in the cache for(list<clip_data*>::iterator i=bag.begin();i!=bag.end();++i) { if ((*i)->res_get() == res) { // extract from the cache clip_data* data = *i; // remove from the cache bag.erase(i); return data; } } return new clip_data(res); } //--------------------------------------------------------------------------- // Cell Manager struct cell_t { cell_pos_t pos; ///< Position on the screen. backdrop_data* data; ///< Backdrop (already orientation corrected and resized). clip_data* cdata; ///< Clip. unsigned caspectx; ///< Clip aspect. unsigned caspecty; resource last; ///< Previous backdrop resource. bool highlight; ///< The backdrop has the highlight. bool redraw; ///< The backdrop need to be redrawn. }; #define CELL_MAX 512 class cell_manager { class backdrop_cache* int_backdrop_cache; class clip_cache* int_clip_cache; unsigned backdrop_mac; struct cell_t backdrop_map[CELL_MAX]; // Color used for missing backdrop int_color backdrop_missing_color; // Color used for the lighting box backdrop int_color backdrop_box_color; unsigned backdrop_outline; // size of the backdrop outline unsigned backdrop_cursor; // size of the backdrop cursor double backdrop_expand_factor; // stretch factor bool multiclip; target_clock_t backdrop_box_last; bool idle_update(int index); unsigned idle_iterator; public: cell_manager(const int_color& Abackdrop_missing_color, const int_color& Abackdrop_box_color, unsigned Amac, unsigned Ainc, unsigned outline, unsigned cursor, double expand_factor, bool Amulticlip); ~cell_manager(); unsigned size() const { return backdrop_mac; } void pos_set(int index, int x, int y, int dx, int dy); void backdrop_set(int index, const resource& res, bool highlight, unsigned aspectx, unsigned aspecty); void backdrop_clear(int index, bool highlight); void backdrop_update(int index); unsigned backdrop_topline(int index); void backdrop_box(); void backdrop_redraw_all(); void clip_set(int index, const resource& res, unsigned aspectx, unsigned aspecty, bool restart); void clip_clear(int index); void clip_start(int index); bool clip_is_active(int index); void reduce(); bool idle(); }; unsigned cell_manager::backdrop_topline(int index) { return backdrop_map[index].pos.real_y - backdrop_outline; } cell_manager::cell_manager(const int_color& Abackdrop_missing_color, const int_color& Abackdrop_box_color, unsigned Amac, unsigned Ainc, unsigned outline, unsigned cursor, double expand_factor, bool Amulticlip) { backdrop_box_last = 0; backdrop_missing_color = Abackdrop_missing_color; backdrop_box_color = Abackdrop_box_color; backdrop_outline = outline; backdrop_cursor = cursor; backdrop_expand_factor = expand_factor; backdrop_mac = Amac; int_backdrop_cache = new backdrop_cache(backdrop_mac*2 + Ainc + 1); multiclip = Amulticlip; if (multiclip) int_clip_cache = new clip_cache(backdrop_mac); else int_clip_cache = new clip_cache(0); for(int i=0;i<backdrop_mac;++i) { backdrop_map.data = 0; backdrop_map.cdata = 0; backdrop_map.last = resource(); backdrop_map.highlight = false; backdrop_map.redraw = true; } idle_iterator = 0; } cell_manager::~cell_manager() { for(int i=0;i<backdrop_mac;++i) { if (backdrop_map.data) delete backdrop_map.data; backdrop_map.data = 0; if (backdrop_map.cdata) delete backdrop_map.cdata; backdrop_map.cdata = 0; } delete int_backdrop_cache; int_backdrop_cache = 0; delete int_clip_cache; int_clip_cache = 0; } void cell_manager::backdrop_redraw_all() { for(int i=0;i<backdrop_mac;++i) { backdrop_map.redraw = true; } } // Set the backdrop position and size void cell_manager::pos_set(int index, int x, int y, int dx, int dy) { assert(index >= 0 && index < backdrop_mac); int_backdrop_cache->free(backdrop_map[index].data); backdrop_map[index].data = 0; int_clip_cache->free(backdrop_map[index].cdata); backdrop_map[index].cdata = 0; backdrop_map[index].last = resource(); backdrop_map[index].highlight = false; backdrop_map[index].redraw = true; backdrop_map[index].pos.x = backdrop_map[index].pos.real_x = x + backdrop_outline; backdrop_map[index].pos.y = backdrop_map[index].pos.real_y = y + backdrop_outline; backdrop_map[index].pos.dx = backdrop_map[index].pos.real_dx = dx - 2*backdrop_outline; backdrop_map[index].pos.dy = backdrop_map[index].pos.real_dy = dy - 2*backdrop_outline; if (int_orientation & ADV_ORIENTATION_FLIP_XY) { swap(backdrop_map[index].pos.real_x, backdrop_map[index].pos.real_y); swap(backdrop_map[index].pos.real_dx, backdrop_map[index].pos.real_dy); } if (int_orientation & ADV_ORIENTATION_FLIP_X) { backdrop_map[index].pos.real_x = video_size_x() - backdrop_map[index].pos.real_x - backdrop_map[index].pos.real_dx; } if (int_orientation & ADV_ORIENTATION_FLIP_Y) { backdrop_map[index].pos.real_y = video_size_y() - backdrop_map[index].pos.real_y - backdrop_map[index].pos.real_dy; } } // Select the backdrop void cell_manager::backdrop_set(int index, const resource& res, bool highlight, unsigned aspectx, unsigned aspecty) { assert(index >= 0 && index < backdrop_mac); int_backdrop_cache->free(backdrop_map[index].data); backdrop_map[index].data = int_backdrop_cache->alloc(res, backdrop_map[index].pos.dx, backdrop_map[index].pos.dy, aspectx, aspecty); if (backdrop_map[index].last == res) { if (backdrop_map[index].highlight != highlight) { backdrop_map[index].highlight = highlight; backdrop_map[index].redraw = true; } } else { backdrop_map[index].last = res; backdrop_map[index].highlight = highlight; backdrop_map[index].redraw = true; } } // Clear the backdrop void cell_manager::backdrop_clear(int index, bool highlight) { assert(index >= 0 && index < backdrop_mac); int_backdrop_cache->free(backdrop_map[index].data); backdrop_map[index].data = 0; if (!backdrop_map[index].last.is_valid()) { if (backdrop_map[index].highlight != highlight) { backdrop_map[index].highlight = highlight; backdrop_map[index].redraw = true; } } else { backdrop_map[index].last = resource(); backdrop_map[index].highlight = highlight; backdrop_map[index].redraw = true; } } static void box(int x, int y, int dx, int dy, int width, const adv_color_rgb& color) { adv_pixel pixel = video_pixel_get(color.red, color.green, color.blue); video_clear(x, y, dx, width, pixel); video_clear(x, y+dy-width, dx, width, pixel); video_clear(x, y+width, width, dy-2*width, pixel); video_clear(x+dx-width, y+width, width, dy-2*width, pixel); } void cell_manager::backdrop_box() { if (!backdrop_cursor) return; for(int i=0;i<backdrop_mac;++i) { struct cell_t* back = backdrop_map + i; if (back->highlight) { unsigned x = back->pos.real_x - backdrop_outline; unsigned y = back->pos.real_y - backdrop_outline; unsigned dx = back->pos.real_dx + 2*backdrop_outline; unsigned dy = back->pos.real_dy + 2*backdrop_outline; video_write_lock(); box(x, y, dx, dy, backdrop_cursor, backdrop_box_color.foreground); video_write_unlock(x, y, dx, dy); adv_color_rgb c = backdrop_box_color.foreground; backdrop_box_color.foreground = backdrop_box_color.background; backdrop_box_color.background = c; } } } // Update the backdrop image void cell_manager::backdrop_update(int index) { struct cell_t* back = backdrop_map + index; assert(index >= 0 && index < backdrop_mac); if (back->data) { if (!fast_exit_handler()) back->data->load(&back->pos, backdrop_missing_color.background, backdrop_expand_factor); } if (back->redraw) { if (back->data) { if (back->data->bitmap_get()) { back->redraw = false; back->pos.draw_backdrop(back->data->bitmap_get(), backdrop_missing_color.background); } else { // the image need to be update when loaded back->pos.clear(backdrop_missing_color.background); } } else { back->redraw = false; back->pos.clear(backdrop_missing_color.background); } if (backdrop_outline) back->pos.border(backdrop_outline, backdrop_missing_color.foreground); } } void cell_manager::reduce() { if (int_backdrop_cache) int_backdrop_cache->reduce(); if (int_clip_cache) int_clip_cache->reduce(); } // Define to update the video in one whole time for multiclip // #define USE_MULTICLIP_WHOLE bool cell_manager::idle_update(int index) { adv_color_rgb rgb_map[256]; unsigned rgb_max; cell_t* cell = backdrop_map + index; clip_data* clip = cell->cdata; if (!clip) return false; if (!clip->is_old()) return false; adv_bitmap* bitmap = clip->load(rgb_map, &rgb_max); if (!bitmap) { cell->redraw = true; // force the redraw backdrop_update(index); #ifdef USE_MULTICLIP_WHOLE if (!multiclip) #endif cell->pos.redraw(); return false; } cell->pos.draw_clip(bitmap, rgb_map, rgb_max, cell->caspectx, cell->caspecty, backdrop_expand_factor, backdrop_missing_color.background, clip->is_first()); #ifdef USE_MULTICLIP_WHOLE if (!multiclip) #endif cell->pos.redraw(); adv_bitmap_free(bitmap); // ensure to fill the audio buffer play_poll(); return true; } bool cell_manager::idle() { if (multiclip) { int highlight_index = -1; target_clock_t start = target_clock(); target_clock_t stop = start + TARGET_CLOCKS_PER_SEC / 100; // limit update for 10 ms // search the highlight clip for(unsigned i=0;i<backdrop_mac;++i) { if (backdrop_map.highlight) { highlight_index = i; } } // always display the highlight clip if (highlight_index >= 0) { idle_update(highlight_index); } // update all the clip for(unsigned i=0;i<backdrop_mac;++i) { target_clock_t backdrop_box_new = target_clock(); if (backdrop_box_new >= backdrop_box_last + TARGET_CLOCKS_PER_SEC/20) { backdrop_box_last = backdrop_box_new; backdrop_box(); } // increment the iterator ++idle_iterator; if (idle_iterator >= backdrop_mac) idle_iterator = 0; if (idle_iterator != highlight_index) { idle_update(idle_iterator); // don't wait too much if (target_clock() > stop) break; } } #ifdef USE_MULTICLIP_WHOLE video_write_lock(); video_stretch(0, 0, video_size_x(), video_size_y(), video_foreground_buffer, video_size_x(), video_size_y(), video_buffer_line_size, video_bytes_per_pixel(), video_color_def(), 0); video_write_unlock(0, 0, video_size_x(), video_size_y()); #endif } else { for(unsigned i=0;i<backdrop_mac;++i) { idle_update(i); } target_clock_t backdrop_box_new = target_clock(); if (backdrop_box_new >= backdrop_box_last + TARGET_CLOCKS_PER_SEC/20) { backdrop_box_last = backdrop_box_new; backdrop_box(); } } // recheck if some clip is already old for(unsigned i=0;i<backdrop_mac;++i) { cell_t* cell = backdrop_map + i; clip_data* clip = cell->cdata; if (clip && clip->is_old()) return false; } return true; } void cell_manager::clip_set(int index, const resource& res, unsigned aspectx, unsigned aspecty, bool restart) { assert(index >= 0 && index < backdrop_mac); int_clip_cache->free(backdrop_map[index].cdata); backdrop_map[index].cdata = int_clip_cache->alloc(res); backdrop_map[index].caspectx = aspectx; backdrop_map[index].caspecty = aspecty; if (backdrop_map[index].cdata) { if (restart) backdrop_map[index].cdata->rewind(); } } void cell_manager::clip_clear(int index) { assert(index >= 0 && index < backdrop_mac); int_clip_cache->free(backdrop_map[index].cdata); backdrop_map[index].cdata = 0; } void cell_manager::clip_start(int index) { assert(index >= 0); for(unsigned i=0;i<backdrop_mac;++i) { if (backdrop_map.cdata && (i == index || backdrop_map.cdata->is_waiting())) { backdrop_map.cdata->start(); } } } bool cell_manager::clip_is_active(int index) { assert(index >= 0); if (index >= backdrop_mac) { return false; } if (backdrop_map[index].cdata) { return backdrop_map[index].cdata->is_active(); } else { return false; } } static class cell_manager* int_cell; // global cell manager //--------------------------------------------------------------------------- // Backgrop/Clip Interface void int_backdrop_init(const int_color& back_color, const int_color& back_box_color, unsigned Amac, unsigned Ainc, unsigned Aoutline, unsigned Acursor, double expand_factor, bool multiclip) { int_cell = new cell_manager(back_color, back_box_color, Amac, Ainc, Aoutline, Acursor, expand_factor, multiclip); } void int_backdrop_done() { delete int_cell; int_cell = 0; } void int_backdrop_pos(int index, int x, int y, int dx, int dy) { int_cell->pos_set(index, x, y, dx, dy); } void int_backdrop_set(int index, const resource& res, bool highlight, unsigned aspectx, unsigned aspecty) { int_cell->backdrop_set(index, res, highlight, aspectx, aspecty); } void int_backdrop_redraw_all() { if (int_cell) int_cell->backdrop_redraw_all(); } void int_backdrop_clear(int index, bool highlight) { int_cell->backdrop_clear(index, highlight); } void int_clip_set(int index, const resource& res, unsigned aspectx, unsigned aspecty, bool restart) { int_cell->clip_set(index, res, aspectx, aspecty, restart); } void int_clip_clear(int index) { int_cell->clip_clear(index); } void int_clip_start(int index) { if (int_cell) int_cell->clip_start(index); } bool int_clip_is_active(int index) { if (int_cell) return int_cell->clip_is_active(index); else return true; } //--------------------------------------------------------------------------- // Put Interface unsigned int_put_width(char c) { adv_bitmap* src = int_font->data[(unsigned char)c]; if (int_orientation & ADV_ORIENTATION_FLIP_XY) return src->size_y; else return src->size_x; } unsigned int_put_width(const string& s) { unsigned size = 0; for(unsigned i=0;i<s.length();++i) size += int_put_width(s); return size; } void int_put(int x, int y, char c, const int_color& color) { if (x>=0 && y>=0 && x+int_put_width©<=int_dx_get() && y+int_font_dy_get()<=int_dy_get()) { adv_bitmap* src = int_font->data[(unsigned char)c]; if (int_orientation & ADV_ORIENTATION_FLIP_XY) swap(x, y); if (int_orientation & ADV_ORIENTATION_FLIP_X) x = video_size_x() - src->size_x - x; if (int_orientation & ADV_ORIENTATION_FLIP_Y) y = video_size_y() - src->size_y - y; assert(x>=0 && y>=0 && x+src->size_x<=video_size_x() && y+src->size_y<=video_size_y()); adv_font_put_char_map(int_font, video_foreground_bitmap, x, y, c, color.opaque); } } void int_put_alpha(int x, int y, char c, const int_color& color) { if (x>=0 && y>=0 && x+int_put_width©<=int_dx_get() && y+int_font_dy_get()<=int_dy_get()) { adv_bitmap* src = int_font->data[(unsigned char)c]; if (int_orientation & ADV_ORIENTATION_FLIP_XY) swap(x, y); if (int_orientation & ADV_ORIENTATION_FLIP_X) x = video_size_x() - src->size_x - x; if (int_orientation & ADV_ORIENTATION_FLIP_Y) y = video_size_y() - src->size_y - y; assert(x>=0 && y>=0 && x+src->size_x<=video_size_x() && y+src->size_y<=video_size_y()); if (video_alpha_flag) { adv_bitmap* flat = adv_bitmap_alloc(src->size_x, src->size_y, video_alpha_bytes_per_pixel); adv_font_put_char_map(int_font, flat, 0, 0, c, color.alpha); adv_bitmap_put_alphaback(video_foreground_bitmap, x, y, video_color_def(), video_background_bitmap, x, y, flat, 0, 0, flat->size_x, flat->size_y, video_alpha_color_def); adv_bitmap_free(flat); } else { adv_font_put_char_map(int_font, video_foreground_bitmap, x, y, c, color.opaque); } } } void int_put_filled(int x, int y, int dx, const string& s, const int_color& color) { for(unsigned i=0;i<s.length();++i) { if (int_put_width(s) <= dx) { int_put(x, y, s, color); x += int_put_width(s); dx -= int_put_width(s); } else break; } if (dx) int_clear(x, y, dx, int_font_dy_get(), color.background); } void int_put_filled_alpha(int x, int y, int dx, const string& s, const int_color& color) { for(unsigned i=0;i<s.length();++i) { if (int_put_width(s) <= dx) { int_put_alpha(x, y, s, color); x += int_put_width(s); dx -= int_put_width(s); } else break; } if (dx) int_clear_alpha(x, y, dx, int_font_dy_get(), color.background); } void int_put_special(bool& in, int x, int y, int dx, const string& s, const int_color& c0, const int_color& c1, const int_color& c2) { for(unsigned i=0;i<s.length();++i) { if (int_put_width(s) <= dx) { if (s=='(' || s=='[') in = true; if (!in && isupper(s)) { int_put(x, y, s, c0); } else { int_put(x, y, s, in ? c1 : c2); } x += int_put_width(s); dx -= int_put_width(s); if (s==')' || s==']') in = false; } else break; } if (dx) int_clear(x, y, dx, int_font_dy_get(), c0.background); } void int_put_special_alpha(bool& in, int x, int y, int dx, const string& s, const int_color& c0, const int_color& c1, const int_color& c2) { for(unsigned i=0;i<s.length();++i) { if (int_put_width(s) <= dx) { if (s=='(' || s=='[') in = true; if (!in && isupper(s)) { int_put_alpha(x, y, s, c0); } else { int_put_alpha(x, y, s, in ? c1 : c2); } x += int_put_width(s); dx -= int_put_width(s); if (s==')' || s==']') in = false; } else break; } if (dx) int_clear_alpha(x, y, dx, int_font_dy_get(), c0.background); } void int_put(int x, int y, const string& s, const int_color& color) { for(unsigned i=0;i<s.length();++i) { int_put(x, y, s, color); x += int_put_width(s); } } void int_put_alpha(int x, int y, const string& s, const int_color& color) { for(unsigned i=0;i<s.length();++i) { int_put_alpha(x, y, s, color); x += int_put_width(s); } } unsigned int_put(int x, int y, int dx, const string& s, const int_color& color) { for(unsigned i=0;i<s.length();++i) { int width = int_put_width(s); if (width > dx) return i; int_put(x, y, s, color); x += width; dx -= width; } return s.length(); } unsigned int_put_alpha(int x, int y, int dx, const string& s, const int_color& color) { for(unsigned i=0;i<s.length();++i) { int width = int_put_width(s); if (width > dx) return i; int_put(x, y, s, color); x += width; dx -= width; } return s.length(); } unsigned int_put_right(int x, int y, int dx, const string& s, const int_color& color) { unsigned size = int_put_width(s); return int_put(x + dx - size, y, dx, s, color); } unsigned int_put_right_alpha(int x, int y, int dx, const string& s, const int_color& color) { unsigned size = int_put_width(s); return int_put_alpha(x + dx - size, y, dx, s, color); } void int_clear(const adv_color_rgb& color) { adv_pixel background = video_pixel_get(color.red, color.green, color.blue); adv_pixel overscan; // clear the whole bitmap using the overscan color if ((video_driver_flags() & VIDEO_DRIVER_FLAGS_OUTPUT_WINDOW)!=0 && video_buffer_pixel_size > 1) { // fill with white in a window manager environment overscan = video_pixel_get(0xff, 0xff, 0xff); } else { // fill with black in a full screen environment overscan = video_pixel_get(0, 0, 0); } adv_bitmap_clear(video_foreground_bitmap, 0, 0, video_size_x(), video_size_y(), overscan); adv_bitmap_clear(video_background_bitmap, 0, 0, video_size_x(), video_size_y(), background); } void int_box(int x, int y, int dx, int dy, int width, const adv_color_rgb& color) { int_clear(x, y, dx, width, color); int_clear(x, y+dy-width, dx, width, color); int_clear(x, y+width, width, dy-2*width, color); int_clear(x+dx-width, y+width, width, dy-2*width, color); } void int_clear(int x, int y, int dx, int dy, const adv_color_rgb& color) { // clip if (x < 0) { dx += x; x = 0; } if (y < 0) { dy += y; y = 0; } if (x + dx > int_dx_get()) { dx = int_dx_get() - x; } if (y + dy > int_dy_get()) { dy = int_dy_get() - y; } if (dx <= 0 || dy <= 0) return; // rotate if (int_orientation & ADV_ORIENTATION_FLIP_XY) { swap(x, y); swap(dx, dy); } if (int_orientation & ADV_ORIENTATION_FLIP_X) x = video_size_x() - dx - x; if (int_orientation & ADV_ORIENTATION_FLIP_Y) y = video_size_y() - dy - y; gen_clear_raw(x, y, dx, dy, color); } void int_clear_alpha(int x, int y, int dx, int dy, const adv_color_rgb& color) { // clip if (x < 0) { dx += x; x = 0; } if (y < 0) { dy += y; y = 0; } if (x + dx > int_dx_get()) { dx = int_dx_get() - x; } if (y + dy > int_dy_get()) { dy = int_dy_get() - y; } if (dx <= 0 || dy <= 0) return; // rotate if (int_orientation & ADV_ORIENTATION_FLIP_XY) { swap(x, y); swap(dx, dy); } if (int_orientation & ADV_ORIENTATION_FLIP_X) x = video_size_x() - dx - x; if (int_orientation & ADV_ORIENTATION_FLIP_Y) y = video_size_y() - dy - y; gen_clear_alpha(x, y, dx, dy, color); } bool int_clip(const string& file, bool loop) { unsigned aspectx = int_dx_get(); unsigned aspecty = int_dy_get(); resource res = path_import(file); bool wait = true; int_backdrop_init(COLOR_MENU_BACKDROP, COLOR_MENU_BACKDROP, 1, 0, 0, 0, 1.0, false); int_backdrop_pos(0, 0, 0, int_dx_get(), int_dy_get()); if (file.find(".mng") != string::npos) { int_clip_set(0, res, aspectx, aspecty, false); int_clip_start(0); int_update(); while (!int_event_waiting() && int_clip_is_active(0)) { } int_clip_clear(0); if (loop) wait = false; } else { int_backdrop_set(0, res, false, aspectx, aspecty); int_update(); } while (int_event_waiting()) { wait = false; int_event_get(false); } int_backdrop_done(); return wait; } bool int_image(const string& file, unsigned& scale_x, unsigned& scale_y) { adv_fz* f; f = fzopen(file.c_str(), "rb"); if (!f) { log_std(("ERROR:text: error opening file %s\n", file.c_str())); return false; } adv_color_rgb rgb_map[256]; unsigned rgb_max; adv_bitmap* bitmap; if (file.find(".mng") != string::npos) { adv_mng* mng; mng = adv_mng_init(f); if (mng == 0) { fzclose(f); return false; } unsigned pix_width; unsigned pix_height; unsigned pix_pixel; unsigned char* dat_ptr; unsigned dat_size; unsigned char* pix_ptr; unsigned pix_scanline; unsigned char* pal_ptr; unsigned pal_size; unsigned tick; int r = adv_mng_read_done(mng, &pix_width, &pix_height, &pix_pixel, &dat_ptr, &dat_size, &pix_ptr, &pix_scanline, &pal_ptr, &pal_size, &tick, f); if (r != 0) { fzclose(f); return false; } bitmap = adv_bitmap_import_palette(rgb_map, &rgb_max, pix_width, pix_height, pix_pixel, dat_ptr, dat_size, pix_ptr, pix_scanline, pal_ptr, pal_size); if (!bitmap) { free(dat_ptr); free(pal_ptr); fzclose(f); return false; } free(pal_ptr); } else { bitmap = adv_bitmap_load_png(rgb_map, &rgb_max, f); } if (!bitmap) { log_std(("ERROR:text: error reading file %s\n", file.c_str())); fzclose(f); return false; } fzclose(f); scale_x = bitmap->size_x; scale_y = bitmap->size_y; struct video_pipeline_struct pipeline; unsigned combine = VIDEO_COMBINE_X_MEAN | VIDEO_COMBINE_Y_MEAN; video_pipeline_init(&pipeline); video_pipeline_target(&pipeline, video_background_buffer, video_buffer_line_size, video_color_def()); uint32 palette32[256]; uint16 palette16[256]; uint8 palette8[256]; if (bitmap->bytes_per_pixel == 1) { for(unsigned i=0;i<rgb_max;++i) { adv_pixel p = video_pixel_get(rgb_map.red, rgb_map.green, rgb_map.blue); palette32 = p; palette16 = p; palette8 = p; } video_pipeline_palette8(&pipeline, video_size_x(), video_size_y(), bitmap->size_x, bitmap->size_y, bitmap->bytes_per_scanline, bitmap->bytes_per_pixel, palette8, palette16, palette32, combine); } else { adv_color_def def = adv_png_color_def(bitmap->bytes_per_pixel); video_pipeline_direct(&pipeline, video_size_x(), video_size_y(), bitmap->size_x, bitmap->size_y, bitmap->bytes_per_scanline, bitmap->bytes_per_pixel, def, combine); } video_pipeline_blit(&pipeline, 0, 0, bitmap->ptr); video_pipeline_done(&pipeline); adv_bitmap_free(bitmap); // copy also into the foreground memcpy(video_foreground_buffer, video_background_buffer, video_buffer_size); // invalidate all the backdrop if any int_backdrop_redraw_all(); return true; } //--------------------------------------------------------------------------- // Update Interface static void int_copy_partial(unsigned y0, unsigned y1) { video_write_lock(); unsigned char* buffer = video_foreground_buffer + y0 * video_buffer_line_size; for(unsigned y=y0;y<y1;++y) { memcpy(video_write_line(y), buffer, video_buffer_line_size); buffer += video_buffer_line_size; } video_write_unlock(0, y0, video_size_x(), y1 - y0); } unsigned int_update_pre(bool progressive) { int_updating_active = false; play_poll(); int y = 0; if (int_cell) { for(int i=0;i<int_cell->size();++i) { play_poll(); // this trick works only if the backdrops positioned are from top to down if (int_orientation == 0 && progressive) { // update progressively the screen int yl = int_cell->backdrop_topline(i); if (yl > y) { int_copy_partial(y, yl); y = yl; } } int_cell->backdrop_update(i); } int_cell->reduce(); } return y; } void int_update_post(unsigned y) { play_poll(); int_copy_partial(y, video_size_y()); if (int_cell) { int_cell->backdrop_box(); } play_poll(); int_updating_active = true; } void int_update(bool progressive) { int_update_post(int_update_pre(progressive)); } static void key_poll() { if (os_is_quit()) { event_push(EVENT_ESC); } int_joystick_button_raw_poll(); int_joystick_move_raw_poll(); int_mouse_button_raw_poll(); int_mouse_move_raw_poll(); event_poll(); } void int_idle_time_reset() { int_idle_time_current = time(0); int_last = EVENT_NONE; } void int_idle_0_enable(bool state) { int_idle_0_state = state; } void int_idle_1_enable(bool state) { int_idle_1_state = state; } static void int_idle() { time_t now = time(0); time_t elapsed = now - int_idle_time_current; if (int_idle_0_state) { if (int_idle_0_rep != 0 && int_last == EVENT_IDLE_0 && elapsed > int_idle_0_rep ) { log_std(("text: push IDLE_0 repeat\n")); event_push_repeat(EVENT_IDLE_0); } else if (int_idle_0 != 0 && elapsed > int_idle_0 ) { log_std(("text: push IDLE_0\n")); event_push_repeat(EVENT_IDLE_0); } } if (int_idle_1_state) { if (int_idle_1_rep != 0 && int_last == EVENT_IDLE_1 && elapsed > int_idle_1_rep ) { log_std(("text: push IDLE_1 repeat\n")); event_push_repeat(EVENT_IDLE_1); } else if (int_idle_1 != 0 && elapsed > int_idle_1 ) { log_std(("text: push IDLE_1\n")); event_push_repeat(EVENT_IDLE_1); } } if (event_peek() == EVENT_NONE) { if (int_updating_active) { if (int_cell) { // idle only if there is time if (int_cell->idle()) { target_idle(); } else { // we are late, allow to allocate 100% CPU target_yield(); } } else { target_idle(); } } } play_poll(); keyb_poll(); mouseb_poll(); joystickb_poll(); } bool int_event_waiting() { static target_clock_t key_pressed_last_time = 0; // low level mute/unmute management while (event_peek() == EVENT_MUTE) { event_pop(); play_mute_set(!play_mute_get()); } if (event_peek() != EVENT_NONE) return 1; target_clock_t now = target_clock(); // if you ask for keypress, assume a not CPU intensive state int_idle(); // don't check too frequently if (now - key_pressed_last_time >= TARGET_CLOCKS_PER_SEC / 25) { key_pressed_last_time = now; key_poll(); } // low level mute/unmute management while (event_peek() == EVENT_MUTE) { event_pop(); play_mute_set(!play_mute_get()); } if (event_peek() != EVENT_NONE) return 1; return 0; } unsigned int_event_get(bool update_background) { if (update_background) int_update(); // wait for a keypress, internally a idle call is already done while (!int_event_waiting()) { } int_idle_time_current = time(0); #if 0 /* OSDEF: Save interface image, only for debugging. */ if (event_peek() == EVENT_INS) { char name[256]; static int ssn = 0; ++ssn; snprintf(name, sizeof(name), "im%d.png", ssn); adv_fz* f = fzopen(name, "wb"); if (f) { adv_png_write_def(video_size_x(), video_size_y(), video_color_def(), video_foreground_buffer, video_buffer_pixel_size, video_buffer_line_size, 0, 0, 0, f, 0); fzclose(f); } } #endif return int_last = event_pop(); } void mostra_tooltip(const string& s) //branco { int x = int_dx_get() / 2; int y = 10; int dy = int_font_dy_get(); int border = int_font_dx_get()/4; unsigned w1; unsigned dx; //char b[100]; w1 = int_font_dx_get(s); dx = w1; int_box(x-2*border-dx/2, y-border, dx+4*border, dy+border+1, 1, COLOR_CHOICE_NORMAL.foreground); int_clear(x-2*border-dx/2+1, y-border+1, dx+4*border-2, dy+border-2, COLOR_CHOICE_NORMAL.background); int_put(x-w1/2, y, w1, s, COLOR_CHOICE_NORMAL); y += int_font_dy_get(); } um amigo meu me falou que tenho que criar um evento associando a tecla 5 a tecla 2 do joystick mas não tenho noção de como fazer,se alguem puder ajudar nessa questão agradeço muito

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

Ebook grátis: Aprenda a ler resistores e capacitores!

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!