/* mpu_init: * Initialises the MPU-401 midi interface. */ static int mpu_init(int input, int voices) { if (!mpu_output_mode) { /* only do the hardware initialisation once */ outportb(_mpu_port+1, 0x3F); mpu_input(); LOCK_VARIABLE(midi_mpu401); LOCK_VARIABLE(_mpu_port); LOCK_VARIABLE(_mpu_irq); LOCK_FUNCTION(_mpu_poll); LOCK_FUNCTION(mpu_output); LOCK_FUNCTION(mpu_interrupt); } if (input) { /* only hook the interrupt if we have direct access to it */ if (!mpu_piggyback) { _enable_irq(_mpu_irq); _install_irq(mpu_int, mpu_interrupt); } mpu_input_mode = TRUE; } else mpu_output_mode = TRUE; return 0; }
static int key_mac_init(void) { #if (TRACE_MAC_KBRD) fprintf(stdout, "key_mac_init()\n"); fflush(stdout); #endif GetKeys(KeyNow); _key_shifts=0; if(BitTst(KeyNow,k_apple_shift) || BitTst(KeyNow,k_apple_rshift))_key_shifts |= KB_SHIFT_FLAG; if(BitTst(KeyNow,k_apple_alt) || BitTst(KeyNow,k_apple_altgr))_key_shifts |= KB_ALT_FLAG; if(BitTst(KeyNow,k_apple_control) || BitTst(KeyNow,k_apple_rcontrol))_key_shifts |= KB_CTRL_FLAG; _mouse2nd=BitTst(KeyNow,k_2nd); LOCK_VARIABLE(KeyNow); LOCK_VARIABLE(KeyOld); LOCK_VARIABLE(key_apple_to_allegro); LOCK_VARIABLE(modifier_table); LOCK_VARIABLE(standard_key_ascii_table); LOCK_VARIABLE(standard_key_capslock_table); LOCK_VARIABLE(standard_key_shift_table); LOCK_VARIABLE(standard_key_control_table); LOCK_FUNCTION(_key_mac_interrupt); LOCK_FUNCTION(_handle_mac_key_press); LOCK_FUNCTION(_handle_mac_key_release); BlockMove(KeyNow, KeyOld, sizeof(KeyMap)); if (!tm_running) _tm_sys_init(); _mac_keyboard_installed=1; return 0; }
/* xtended_init: * Selects the unchained 640x400 mode. */ static BITMAP *xtended_init(int w, int h, int v_w, int v_h, int color_depth) { unsigned long addr; BITMAP *b; /* Do not continue if this version of Allegro was built in C-only mode. * The bank switchers assume asm-mode calling conventions, but the * library would try to call them with C calling conventions. */ #ifdef ALLEGRO_NO_ASM return NULL; #endif /* see modexsms.c */ _split_modex_screen_ptr = really_split_modex_screen; /* check it is a valid resolution */ if (color_depth != 8) { ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Xtended mode only supports 8 bit color")); return NULL; } if ((w != 640) || (h != 400) || (v_w > 640) || (v_h > 400)) { ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Xtended mode only supports 640x400")); return NULL; } /* lock everything that is used to draw mouse pointers */ LOCK_VARIABLE(__modex_vtable); LOCK_FUNCTION(_x_draw_sprite); LOCK_FUNCTION(_x_blit_from_memory); LOCK_FUNCTION(_x_blit_to_memory); /* set VESA mode 0x100 */ addr = _set_vga_mode(0x100); if (!addr) { ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("VESA mode 0x100 not available")); return NULL; } outportw(0x3C4, 0x0604); /* disable chain-4 */ /* we only use 1/4th of the width for the bitmap line pointers */ b = _make_bitmap(640/4, 400, addr, &gfx_xtended, 8, 640/4); if (!b) return NULL; b->w = b->cr = 640; b->vtable = &__modex_vtable; b->id |= BMP_ID_PLANAR; setup_x_magic(b); return b; }
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; }
void Frame_Skipper_Init (void) { // Auto Frame Skipper LOCK_VARIABLE (fskipper.Automatic_Frame_Elapsed); LOCK_FUNCTION (Frame_Skipper_Auto_Adjust_Handler); Frame_Skipper_Auto_Install_Handler (); // FPS Counter LOCK_VARIABLE (fskipper.New_Second); LOCK_FUNCTION (Frame_Skipper_New_Second_Handler); Frame_Skipper_New_Second_Handler (); install_int_ex (Frame_Skipper_New_Second_Handler, TIMERS_PER_SECOND); }
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); }
int alogg_play_ex_oggstream(ALOGG_OGGSTREAM *ogg, int buffer_len, int vol, int pan, int speed) { int samples; /* continue only if we are not already playing it */ if (alogg_is_playing_oggstream(ogg)) return ALOGG_OK; /* check the buffer is big enough*/ if (buffer_len < 4096) return ALOGG_PLAY_BUFFERTOOSMALL; /* create a new audiostream and play it */ samples = buffer_len / (ogg->stereo ? 2 : 1) / 2; /* / 2 = 16 bits samples */ ogg->audiostream = play_audio_stream(samples, 16, ogg->stereo, ogg->freq, vol, pan); ogg->audiostream_buffer_len = samples * (ogg->stereo ? 2 : 1) * 2; /* * 2 = 16 bits samples */ ogg->wait_for_audio_stop = 0; if (speed != 1000) adjust_sample(ogg->audiostream->samp, vol, pan, speed, TRUE); /* if the user asked for autopolling, install the interrupt now */ if (ogg->auto_polling) { LOCK_FUNCTION(alogg_autopoll_oggstream); install_param_int(&alogg_autopoll_oggstream, (void *)ogg, ogg->auto_poll_speed); } return ALOGG_OK; }
void Time::init() { install_timer(); LOCK_VARIABLE(myCurrentTick); LOCK_FUNCTION(callback); install_int_ex(callback, BPS_TO_TIMER(Time::TicksPerSecond)); }
void sleep_init(int mins) { char txt[256]; LOCK_FUNCTION(sleep_timeout); LOCK_FUNCTION(sleep_fadeout); /* See if fading is required */ sprintf(txt,get_config_string("[options]","sleep_fade","yes")); if(stricmp(txt,"YES") == 0) sleep_want_fade = TRUE; install_int_ex(sleep_timeout, SECS_TO_TIMER(mins*60)); }
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 void run_demo (void) { set_color_depth (16); if (set_gfx_mode(GFX_OPENGL, width, height, 0, 0) < 0) { allegro_message ("Error setting OpenGL graphics mode:\n%s\nAllegro GL error : %s\n", allegro_error, allegro_gl_error); return; } install_keyboard(); LOCK_FUNCTION(secs_timer); LOCK_VARIABLE(secs); glClearColor (0, 0, 0, 0); glShadeModel (GL_FLAT); glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); glPolygonMode (GL_BACK, GL_POINTS); glEnable (GL_DEPTH_TEST); glCullFace (GL_BACK); glEnable (GL_CULL_FACE); install_int (secs_timer, 1000); do { keyboard(); rest(2); } while (!key[KEY_ESC]); remove_int (secs_timer); remove_keyboard(); }
//Main function int main(){ //Allegro init allegro_init(); set_color_depth(32); set_gfx_mode(GFX_AUTODETECT_WINDOWED, 1280, 960, 0, 0); set_window_title("Chuckie Egg"); srand(time(NULL)); //Installations install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,0); install_timer(); install_keyboard(); install_mouse(); //Close button LOCK_FUNCTION(close_button_handler); set_close_button_callback(close_button_handler); //Show menu ce_menu *menu = new ce_menu(); menu->setupMenu(); menu->showMenu(); delete menu; allegro_exit(); return 1; }
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; }
/* setup_x_magic: * To make sure that things will go on working properly even if a few * bits of code don't know about mode-X screens, we do special magic * inside the bank switch functions to emulate a linear image surface. * Whenever someone tries to access the screen directly, these routines * copy the planar image into a temporary buffer, let the client write * there, and then automatically refresh the screen with the updated * graphics. Very slow, but it makes 100% sure that everything will work. */ static void setup_x_magic(BITMAP *b) { #ifdef ALLEGRO_DOS /* DOS buffer has to go in conventional memory */ int seg = __dpmi_allocate_dos_memory((b->w+15)/16, &magic_sel); if (seg > 0) _x_magic_buffer_addr = seg*16; else _x_magic_buffer_addr = 0; #else /* other platforms can put the buffer wherever they like */ _x_magic_buffer_addr = (unsigned long)_AL_MALLOC(b->w); #endif _x_magic_screen_addr = 0; _x_magic_screen_width = 0; LOCK_VARIABLE(_x_magic_buffer_addr); LOCK_VARIABLE(_x_magic_screen_addr); LOCK_VARIABLE(_x_magic_screen_width); LOCK_FUNCTION(_x_bank_switch); b->write_bank = b->read_bank = _x_bank_switch; }
/* fixed_timer_init: * Installs the fixed-rate timer driver. */ int dzdos_fixed_timer_init() { int i; detect_os(); LOCK_VARIABLE(dzdos_timedrv_fixed_rate); LOCK_VARIABLE(dzdos_bios_counter); LOCK_FUNCTION(dzdos_fixed_timer_handler); dzdos_bios_counter = 0x10000; if (_dzdos_install_irq(TIMER_INT, dzdos_fixed_timer_handler) != 0) return -1; DISABLE(); /* sometimes it doesn't seem to register if we only do this once... */ for (i=0; i<4; i++) dzdos_set_timer_rate(LOVEBILL_TIMER_SPEED); ENABLE(); return 0; }
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; }
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 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; }
/* int33_init: * Initialises the int 0x33 driver. */ static int int33_init(void) { if (os_type == OSTYPE_WINNT) return -1; LOCK_VARIABLE(mousedrv_int33); LOCK_FUNCTION(int33_handler); return init_mouse(int33_handler); }
/* polling_init: * Initialises the periodic timer driver. */ static int polling_init(void) { if (os_type == OSTYPE_WINNT) return -1; LOCK_VARIABLE(mousedrv_polling); LOCK_FUNCTION(polling_timer_poll); return init_mouse(NULL); }
//--------------------------------------------------- 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 serial_module_init() { #ifndef ALLEGRO_WINDOWS dzcomm_init(); #endif serial_timer_running = FALSE; /* all variables and code used inside interrupt handlers must be locked */ LOCK_VARIABLE(serial_time_out); LOCK_FUNCTION(serial_time_out_handler); _add_exit_func(serial_module_shutdown, "serial_module_shutdown"); }
/* winnt_init: * Initialises the WinNT driver. */ static int winnt_init(void) { /* only for use under WinNT */ if (os_type != OSTYPE_WINNT) return -1; LOCK_VARIABLE(mousedrv_polling); LOCK_FUNCTION(polling_timer_poll); return init_mouse(NULL); }
/* awe32_lockmem: * Locks required memory blocks */ static void awe32_lockmem() { /* Functions */ LOCK_FUNCTION(awe32_key_on); LOCK_FUNCTION(awe32_key_off); LOCK_FUNCTION(_awe32_do_note); LOCK_FUNCTION(awe32_set_volume); LOCK_FUNCTION(awe32_set_pitch); /* Data */ /* Most data is locked on allocation */ LOCK_VARIABLE(midi_preset); LOCK_VARIABLE(voice_envelope); LOCK_VARIABLE(exclusive_class_info); LOCK_VARIABLE(midi_awe32); /* Stuff in emu8k.c */ emu8k_lock(); }
// 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; }
// Gets called at the beginning of every "open" function, to ensure // things are initialized static void Initialize_Decoder(void) { static int inited = FALSE; if(!inited) { // Lock the timer function LOCK_FUNCTION(timer_proc); inited = TRUE; } memset(apeg_error, 0, sizeof(apeg_error)); }
/* 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; }
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; }
Alleg4Display(int width, int height, int scale) : m_surface(NULL) , m_scale(0) { unique_display = this; if (install_mouse() < 0) throw DisplayCreationException(allegro_error); if (install_keyboard() < 0) throw DisplayCreationException(allegro_error); #ifdef FULLSCREEN_PLATFORM set_color_depth(16); // TODO Try all color depths for fullscreen platforms #else set_color_depth(desktop_color_depth()); #endif if (set_gfx_mode( #ifdef FULLSCREEN_PLATFORM GFX_AUTODETECT_FULLSCREEN, #else GFX_AUTODETECT_WINDOWED, #endif width, height, 0, 0) < 0) throw DisplayCreationException(allegro_error); setScale(scale); m_queue = new Alleg4EventQueue(); // Copy the initial queue to the display queue { base::scoped_lock hold(unique_display_mutex); Event ev; while (initial_queue.try_pop(ev)) m_queue->queueEvent(ev); } // Add a hook to display-switch so when the user returns to the // screen it's completelly refreshed/redrawn. LOCK_VARIABLE(display_flags); LOCK_FUNCTION(display_switch_in_callback); set_display_switch_callback(SWITCH_IN, display_switch_in_callback); #ifdef ALLEGRO4_WITH_RESIZE_PATCH // Setup the handler for window-resize events set_resize_callback(resize_callback); #endif #if WIN32 subclass_hwnd((HWND)nativeHandle()); #endif }