void retro_init() { int frames = 0; int c, d; install_timer(); install_int_ex(timer_rout, BPS_TO_TIMER(100)); install_int_ex(onesec, BPS_TO_TIMER(1)); midi_init(); initpc(); struct retro_log_callback log; unsigned colorMode = RETRO_PIXEL_FORMAT_XRGB8888; screen_pitch = 0; if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log)) log_cb = log.log; else log_cb = NULL; if (environ_cb(RETRO_ENVIRONMENT_GET_PERF_INTERFACE, &perf_cb)) perf_get_cpu_features_cb = perf_cb.get_cpu_features; else perf_get_cpu_features_cb = NULL; environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &colorMode); environ_cb(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &rumble); }
/* timer_calibrate_retrace: * Times several vertical retraces, and calibrates the retrace syncing * code accordingly. */ static void dzdos_timer_calibrate_retrace() { int ot = _dz_timer_use_retrace; int c; #define AVERAGE_COUNT 4 _dz_timer_use_retrace = FALSE; dzdos_vsync_speed = 0; /* time several retraces - taken out as irrelevant, see above.*/ for (c=0; c<AVERAGE_COUNT; c++) { /* _enter_critical(); */ /* _vga_vsync(); */ /* dzdos_set_timer(0); */ /* _vga_vsync(); */ /* dzdos_vsync_speed += dzdos_read_timer(); */ /* _exit_critical(); */ } dzdos_set_timer(dzdos_timer_delay); dzdos_vsync_speed /= AVERAGE_COUNT; /* sanity check to discard bogus values */ if ((dzdos_vsync_speed > BPS_TO_TIMER(40)) || (dzdos_vsync_speed < BPS_TO_TIMER(110))) dzdos_vsync_speed = BPS_TO_TIMER(70); dzdos_vsync_counter = dzdos_vsync_speed; _dz_timer_use_retrace = ot; }
/* allegInitializations() Initializes allegro and its associated packages (algif), as well as installing hardware settings for mouse, keyboard, sound, timers, and the screen. Autochecks for errors, and displays message and exits(1) on error. */ void allegInitializations() { int error = 0; srand(time(0)); error |= allegro_init (); algif_init (); set_color_depth (16); //set_gfx_mode(GFX_AUTODETECT_WINDOWED, 900,600,0,0); set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 1024,768,0,0); install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL); install_keyboard (); install_mouse(); error |= install_timer(); error |= install_int_ex(incrementTimer, BPS_TO_TIMER(60)); error |= install_int_ex(incrementUpdateCounter, BPS_TO_TIMER(4)); error |= install_int_ex(incrementAnimateCounter, BPS_TO_TIMER(8)); error |= install_int_ex(incrementEconomyCounter, BPM_TO_TIMER(60)); error |= install_int_ex(incrementFireCounter, BPS_TO_TIMER(12)); if (error) { set_gfx_mode(GFX_TEXT, 1024,768,0,0); allegro_message("Allegro Failed to Initialize!"); exit(1); } }
/* _set_current_refresh_rate: * Sets the current refresh rate. * (This function must be called by the gfx drivers) */ void _set_current_refresh_rate(int rate) { /* sanity check to discard bogus values */ if ((rate<40) || (rate>200)) rate = 0; current_refresh_rate = rate; /* adjust retrace speed */ _vsync_speed = rate ? BPS_TO_TIMER(rate) : BPS_TO_TIMER(70); }
/* do_open_fli: * Worker function used by open_fli() and open_memory_fli(). */ static int do_open_fli(void) { long speed; /* read the header */ if (_fli_read_header(&fli_header) != 0) { close_fli(); return FLI_ERROR; } /* check magic numbers */ if (((fli_header.bits_a_pixel != 8) && (fli_header.bits_a_pixel != 0)) || ((fli_header.type != FLI_MAGIC1) && (fli_header.type != FLI_MAGIC2))) { close_fli(); return FLI_ERROR; } if (fli_header.width == 0) fli_header.width = 320; if (fli_header.height == 0) fli_header.height = 200; /* create the frame bitmap */ fli_bitmap = create_bitmap_ex(8, fli_header.width, fli_header.height); if (!fli_bitmap) { close_fli(); return FLI_ERROR; } reset_fli_variables(); fli_frame = 0; fli_timer = 2; fli_status = FLI_OK; /* install the timer handler */ LOCK_VARIABLE(fli_timer); LOCK_FUNCTION(fli_timer_callback); if (fli_header.type == FLI_MAGIC1) speed = BPS_TO_TIMER(70) * (long)fli_header.speed; else speed = MSEC_TO_TIMER((long)fli_header.speed); if (speed == 0) speed = BPS_TO_TIMER(70); install_int_ex(fli_timer_callback, speed); return fli_status; }
void init_frame_speed() { LOCK_VARIABLE(frame_counter); LOCK_FUNCTION(increment_frame_counter); if(install_int_ex(increment_frame_counter, BPS_TO_TIMER(1000))<0)return; }
bool OSD::Init (bool fFirstInit_/*=false*/) { bool fRet = false; #ifndef _DEBUG // Ignore Ctrl-C and Ctrl-Break in release modes signal(SIGINT, SIG_IGN); #endif #ifdef ALLEGRO_WINDOWS // We'll do our own error handling, so suppress any windows error dialogs SetErrorMode(SEM_FAILCRITICALERRORS); #endif LOCK_VARIABLE(OSD::s_nTicks); LOCK_FUNCTION(TimerCallback); if (fFirstInit_ && !fAllegroInit) allegro_init(); install_int_ex(TimerCallback, BPS_TO_TIMER(EMULATED_FRAMES_PER_SECOND)); fRet = true; return fRet; }
static int init_vidmode () { int i; RGB p; install_keyboard(); install_timer(); /*install_mouse();*/ LOCK_VARIABLE (clock_ticks); LOCK_FUNCTION (tick_increment); install_int_ex (tick_increment, BPS_TO_TIMER (TICK_SECONDS)); screen_buffer = create_bitmap (GFX_WIDTH, GFX_HEIGHT); clear(screen_buffer); clock_count = 0; clock_ticks = 0; set_gfx_mode(GFX_VGA, GFX_WIDTH, GFX_HEIGHT, 0, 0); for(i = 0; i < 32; i++) { p.r = palette[(i*3)+0]; p.g = palette[(i*3)+1]; p.b = palette[(i*3)+2]; set_color(i, &p); } return err_OK; }
void Time::init() { install_timer(); LOCK_VARIABLE(myCurrentTick); LOCK_FUNCTION(callback); install_int_ex(callback, BPS_TO_TIMER(Time::TicksPerSecond)); }
void set_up_timer() { install_timer(); srand(time(NULL)); LOCK_VARIABLE(elapsed_time); LOCK_FUNCTION(__inc_elapsed_time); install_int_ex(__inc_elapsed_time, BPS_TO_TIMER(1000)); }
void sleep_timeout(void) { remove_int(sleep_timeout); if(sleep_want_fade) install_int_ex(sleep_fadeout, BPS_TO_TIMER(2)); else need_to_quit_program = TRUE; }
void clock_init() { // Install timer related stuff LOCK_VARIABLE(clock_var); LOCK_FUNCTION(clock_inc); install_int_ex(clock_inc, BPS_TO_TIMER(1000)); }
int main() { Game_sys game; LOCK_VARIABLE( counter ); // FPS control LOCK_FUNCTION( incrctrl ); install_int_ex( incrctrl, BPS_TO_TIMER( 30 ) ); game.LoadFiles(); game.ConfigureMusic(); while( !game.GetDone() && game.GetGameState() == 1 ) // splash screen and story { while( counter > 0 ) { game.UpdateSplashNStory(); counter -= 1; } game.DrawCrntScreen(); } game.ConfigureMusic(); while( !game.GetDone() && game.GetGameState() == 2 ) // gameplay { while( counter > 0 ) { game.Update(); counter -= 1; } game.Draw(); } game.ConfigureMusic(); while( !game.GetDone() && game.GetGameState() == 3 ) // story good end { while( counter > 0 ) { game.UpdateSplashNStory(); counter -= 1; } game.DrawCrntScreen(); } while( !game.GetDone() && game.GetGameState() == 4 ) // story bad end { while( counter > 0 ) { game.UpdateSplashNStory(); counter -= 1; } game.DrawCrntScreen(); } return 0; }
/** * Initialization routine. * * Sets all stars to the starting position. Their initial coordinates * are determined in the main loop. Also installs the algorithm timer. */ void initialize_starfield() { for (int a = 0; a < STAR_AMOUNT; ++a) { starfield[a].z = 0; } // Install algorithm selection timer. install_int_ex(update_starfield_counter, BPS_TO_TIMER(60)); // Set up the initial star positions. set_star_pos_algo(); initialize_star_positions(); }
int main() { std::srand(std::time(NULL)); allegro_init(); install_timer(); install_keyboard(); // install_mouse(); install_joystick(JOY_TYPE_AUTODETECT); override_config_file(redir("defnot.ini").c_str()); gfx_widescreen = get_config_int("Game", "Widescreen", gfx_widescreen); gfx_fullscreen = get_config_int("Game", "Fullscreen", gfx_fullscreen); if (!setup_gfx() != 0) { allegro_message("Unable to setup the graphics mode\n"); return 1; } // if (gfx_capabilities & GFX_HW_CURSOR) { // enable_hardware_cursor(); // select_mouse_cursor(MOUSE_CURSOR_ARROW); // show_mouse(screen); // } if (!load_media()) { allegro_message("Unable to load data files to play the game\n"); return 1; } // install the timer to control the game speed LOCK_VARIABLE(beats); LOCK_FUNCTION(timer_control); beats = 0; install_int_ex(timer_control, BPS_TO_TIMER(BPS)); // insert the callback routine for the close-button LOCK_VARIABLE(continuing); LOCK_FUNCTION(close_button); set_close_button_callback(close_button); // play the game game_loop(); set_config_int("Game", "Widescreen", gfx_widescreen); set_config_int("Game", "Fullscreen", gfx_fullscreen); remove_int(timer_control); allegro_exit(); return 0; }
/* var_timer_simulate_retrace: * Turns retrace syncing mode on or off. * However, we always fail, see above. */ void dzdos_var_timer_simulate_retrace(int enable) { if (enable) { /* dzdos_timer_calibrate_retrace(); */ /* _dz_timer_use_retrace = TRUE; */ _dz_timer_use_retrace = FALSE; } else { _dz_timer_use_retrace = FALSE; dzdos_vsync_counter = dzdos_vsync_speed = BPS_TO_TIMER(70); } }
// Setup game void setup(){ // Setup for FPS system LOCK_VARIABLE(ticks); LOCK_FUNCTION(ticker); install_int_ex(ticker, BPS_TO_TIMER(updates_per_second)); LOCK_VARIABLE(game_time); LOCK_FUNCTION(game_time_ticker); install_int_ex(game_time_ticker, BPS_TO_TIMER(10)); // Close button LOCK_FUNCTION(close_button_handler); set_close_button_callback(close_button_handler); // Game state int stateID = STATE_NULL; int nextState = STATE_NULL; // Variables closeGame = false; }
int main(int argc, char **argv) { allegro_init(); set_color_depth(32); set_gfx_mode(GFX_AUTODETECT_WINDOWED, SCRW, SCRH, 0, 0); install_keyboard(); install_mouse(); install_timer(); LOCK_VARIABLE(timer); LOCK_FUNCTION(timerupdate); install_int_ex(timerupdate, BPS_TO_TIMER(TIMER_BPS)); srand((unsigned)time(NULL)); set_window_title("Skat"); LOCK_FUNCTION(close_handler); set_close_button_callback(close_handler); cards = load_bitmap("images/cards.tga", NULL); game.p[0] = &human; game.p[1] = &cpu1; game.p[2] = &cpu2; human.choose_card = human_choose_card; cpu1.choose_card = cpu_choose_card; cpu2.choose_card = cpu_choose_card; human.choose_game = human_choose_game; cpu1.choose_game = cpu_choose_game; cpu2.choose_game = cpu_choose_game; human.reizen = human_reizen; cpu1.reizen = cpu_reizen; cpu2.reizen = cpu_reizen; human.schieben = human_schieben; cpu1.schieben = cpu_schieben; cpu2.schieben = cpu_schieben; human.kontra = human_kontra; cpu1.kontra = cpu_kontra; cpu2.kontra = cpu_kontra; human.name = "Stefan"; cpu1.name = "Robert"; cpu2.name = "Thomas"; human.rtext = cpu1.rtext = cpu2.rtext = NULL; human.total_points = 0; cpu1.total_points = 0; cpu2.total_points = 0; enable_hardware_cursor(); show_mouse(screen); buffered_do_dialog(main_dlg, -1); destroy_bitmap(cards); }
/* Reprogram the PIC timer to fire at a specified value */ void timer_adjust(int hertz) { int time; if (0 == hertz) time = 0; else time = BPS_TO_TIMER(hertz); outportb(0x43, 0x34); outportb(0x40, time & 0xFF); outportb(0x40, time >> 8); }
int main() { inicia_allegro(500,450); inicia_audio(70,70); BITMAP *nave = load_bitmap("nave.bmp",NULL); BITMAP *nube = load_tga("Galaxy2.tga",NULL); BITMAP *bala = load_bitmap("Bala2.bmp", NULL); // otra cosa BITMAP *buffer = create_bitmap(500,450); LOCK_VARIABLE(speed_counter); LOCK_FUNCTION(inc_speed_counter); install_int_ex(inc_speed_counter, BPS_TO_TIMER(30)); int i = 450 , dsw = 0 , cont = 0; while(!key[KEY_ESC]){ blit(nube,buffer,0,--i,0,0,500,450); if(i == 0) i=450; pintar_nave(nave,buffer,nav); if(key[KEY_UP]){ nav.dir = 1; nav.y -= 1; } else if(key[KEY_DOWN]) { nav.dir = 1; nav.y += 2; } if(key[KEY_RIGHT]){ nav.dir = 2; nav.x += 1; } else if(key[KEY_LEFT]){ nav.dir = 0; nav.x -= 1; } else nav.dir = 1; blit(buffer,screen,0,0,0,0,500,450); rest(5); } destroy_bitmap(buffer); destroy_bitmap(nave); destroy_bitmap(nube); return 0; }
void allegInitializations() { int error = 0; srand(time(0)); error |= allegro_init (); algif_init (); set_color_depth (32); set_gfx_mode(GFX_AUTODETECT_WINDOWED, 1024,768,0,0); //set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 1024,768,0,0); install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL); error |= install_keyboard (); install_mouse(); error |= install_timer(); error |= install_int_ex(incrementTimer, BPS_TO_TIMER(130)); error |= install_int_ex(incrementMoveTimer, BPS_TO_TIMER(30)); if (error) { set_gfx_mode(GFX_TEXT, 1024,768,0,0); allegro_message("Allegro Failed to Initialize!"); exit(1); } }
//Game Loop bool ce_game::start_game(){ //Create the tick timer functions LOCK_VARIABLE(ticks); LOCK_FUNCTION(ticker); install_int_ex(ticker, BPS_TO_TIMER(fps)); //----------GameLoop---------- while (isPlaying || end_timer > 0 || start_timer > 0){ //Wait until a tick has happened while(ticks == 0){ rest(1); } //If there is a tick pending update the logic and remve the tick while(ticks > 0){ //Do game logic or decriment end/start timers if (isPlaying){ checkEscape(); update(); checkState(); }else if (start_timer >= 0){ if (start_timer == 0){ isPlaying = true; start_timer = -1; }else{ start_timer--; } }else{ end_timer--; } ticks--; } //Draw game or start/end screens if (start_timer > 0){ drawStart(); }else if (isPlaying || end_timer > 150){ draw(); }else{ drawEnd(); } } return hasWon; }
//Allegro init fun! void techInit(){ allegro_init(); // all Allegro programs need this set_color_depth(32); set_gfx_mode(GFX_AUTODETECT_WINDOWED, WIDTH, HEIGHT, 0, 0); srand((unsigned)time(0)); screenBuffer = create_bitmap(WIDTH, HEIGHT); install_keyboard(); install_mouse(); LOCK_VARIABLE(speed_counter); LOCK_FUNCTION(increment_speed_counter); install_int_ex(increment_speed_counter,BPS_TO_TIMER(120)); /* add other initializations here*/ }
void Init_video(char* argv[]) { allegro_init(); install_timer(); install_keyboard(); install_joystick(JOY_TYPE_AUTODETECT); request_refresh_rate(FPS_VIDEO); set_color_depth(32); /*set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 320, 240, 0, 0);*/ set_gfx_mode(GFX_AUTODETECT_WINDOWED, 320, 240, 0, 0); set_window_title(game_name); clear_to_color(screen, makecol(0, 0, 0)); LOCK_VARIABLE(ticks); LOCK_FUNCTION(ticker); install_int_ex(ticker, BPS_TO_TIMER(FPS_VIDEO)); }
int main(int argc, char **argv) { srand((unsigned)time(NULL)); allegro_init(); install_keyboard(); install_timer(); set_color_depth(32); set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0); BITMAP *orig_screen = screen; screen = create_bitmap(SCREEN_W, SCREEN_H); LOCK_VARIABLE(timer); LOCK_FUNCTION(timer_increment); install_int_ex(timer_increment, BPS_TO_TIMER(60)); int need_redraw = 1; Game game; init_game(&game); while(!game.end) { for(; timer > 0; --timer) { need_redraw = 1; get_input(&game); update_game(&game); if(timer > 4) { timer = 0; break; } } if(need_redraw) { clear_to_color(screen, makecol(0,0,0)); draw_game(&game, screen); blit(screen, orig_screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); } else sched_yield(); } delete_list(game.asteroids); delete_list(game.shot); delete_list(game.particles); return 0; }
int _ji_system_init() { /* Install timer related stuff. */ LOCK_VARIABLE(ji_clock); LOCK_VARIABLE(m_b); LOCK_FUNCTION(clock_inc); if (install_int_ex(clock_inc, BPS_TO_TIMER(1000)) < 0) return -1; if (screen) jmouse_poll(); moved = true; mouse_cursor_type = kNoCursor; return 0; }
//--------------------------------------------------- void initAllegroTimer() { if(isInit) return; LOCK_VARIABLE(speed_counter); LOCK_VARIABLE(milliSec); LOCK_VARIABLE(fps); LOCK_VARIABLE(frame_counter); LOCK_FUNCTION(inc_milliSec); LOCK_FUNCTION(increment_speed_counter); LOCK_FUNCTION(fps_proc); install_int(inc_milliSec, 10);// every second //ever 10 of a sec install_int_ex(increment_speed_counter, BPS_TO_TIMER(60)); install_int(fps_proc, 1000); isInit = true; }
void lcd_init(void) { set_config_file(damp_ini_file); /* Load the driver */ lcd_load_driver(get_config_string("[lcd]","driver","NONE")); /* Call the driver's init function */ lcd_external_function("lcd_driver_init"); /* Read LCD variables from the ini file */ lcd_scroll_speed = get_config_int("[lcd]","scroll_speed",4); lcd_display_width = get_config_int("[lcd]","display_width",16); lcd_display_lines = get_config_int("[lcd]","display_lines",2); lcd_require_update = FALSE; /* Set up the scroller */ lcd_scroll_pos = 0; sprintf(lcd_scroll_text,"%*c\n",lcd_display_width,' '); LOCK_FUNCTION(lcd_scroll); LOCK_VARIABLE(lcd_scroll_pos); LOCK_VARIABLE(lcd_require_update); install_int_ex(lcd_scroll,BPS_TO_TIMER(lcd_scroll_speed)); /* Display driver details */ printf("======================================================================\n"); printf("DAMP LCD Driver\n"); printf("======================================================================\n"); printf("Driver name : %s\n",lcd_driver_name); printf("Driver version : %.2f\n",lcd_driver_version); printf("Author name : %s\n",lcd_driver_author); printf("Author email : %s\n",lcd_driver_author_email); printf("Driver description : %s\n",lcd_driver_description); printf("\n\n"); }
void allocate_credits(void) { unsigned int tlen = 0; int i; for (cc = credits; *cc; ++cc) { if (strlen(*cc) > tlen) { tlen = strlen(*cc); } } wk = create_bitmap(8 * tlen, 64); for (i = 0; i < 32; ++i) { etab[i] = i * i * (3 * 32 - 2 * i) / 32 / 32; } cc = credits; LOCK_FUNCTION(ticker); LOCK_VARIABLE(ticks); install_int_ex(ticker, BPS_TO_TIMER(60)); }
void InitTimer() { if (installed) return; Log("Initialize timer"); install_timer(); LOCK_VARIABLE(systemtime); LOCK_VARIABLE(timer_count); LOCK_VARIABLE(tick); LOCK_VARIABLE(pixel_scroll_timer); LOCK_VARIABLE(tile_scroll_timer); LOCK_VARIABLE(backupct); LOCK_VARIABLE(idlect); LOCK_VARIABLE(xz); LOCK_VARIABLE(yz); LOCK_VARIABLE(xzd); LOCK_VARIABLE(yzd); LOCK_VARIABLE(ssaver_enabled); LOCK_FUNCTION(_maped_timer_handler); install_int_ex(_maped_timer_handler, BPS_TO_TIMER(100)); installed=true; }