/* 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; }
/* 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; }
/* 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; }
/* emu8k_lock: * Locks all data and functions which might be called in an interrupt context. */ void emu8k_lock() { LOCK_VARIABLE(_emu8k_baseport); LOCK_VARIABLE(_emu8k_numchannels); LOCK_FUNCTION(emu8k_startsound); LOCK_FUNCTION(emu8k_releasesound); LOCK_FUNCTION(emu8k_modulate_atten); LOCK_FUNCTION(emu8k_modulate_ip); LOCK_FUNCTION(emu8k_modulate_pan); LOCK_FUNCTION(emu8k_terminatesound); }
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); }
static int key_adb_init(void) { OSErr e; short adb_command; short adb_devices; char adb_key_registers[8]; ADBAddress adb_address; ADBSetInfoBlock mySet; adb_key_cpt_upp = NewADBCompletionUPP(adb_command_callback); adb_key_upp = NewADBServiceRoutineUPP (key_adb_interrupt); adb_devices = CountADBs(); for(adb_keyboard_id = 1 ; adb_keyboard_id <= adb_devices ; adb_keyboard_id++){ adb_address = GetIndADB(&adb_key_save, adb_keyboard_id); e = GetADBInfo(&adb_key_save, adb_address); if(adb_key_save.origADBAddr == ADB_KEYBOARD){ switch (adb_key_save.devType){ case 2:case 3:case 5: LOCK_VARIABLE(KeyNow); LOCK_VARIABLE(KeyOld); LOCK_VARIABLE(_mouse2nd); LOCK_VARIABLE(adb_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_adb_interrupt);*/ /* LOCK_FUNCTION(adb_command_callback);*/ mySet.siService = adb_key_upp; mySet.siDataAreaAddr = NULL; SetADBInfo (&mySet,adb_address); adb_key_registers[0] = 2; adb_command = (adb_address * 16) + ADB_TALKMASK + ADB_TYPEREGISTER; if (send_adb_command_sync(adb_key_registers, adb_command) == noErr){ adb_key_registers[2] = 3; adb_command = (adb_address * 16) + ADB_LISTENMASK + ADB_TYPEREGISTER; send_adb_command_sync(adb_key_registers, adb_command); } 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); return 0; default: break; } } } adb_keyboard_id=0; return -1; }
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; }
int __libnet_internal__serial_init(void) { LOCK_FUNCTION(enable_thre_int); LOCK_FUNCTION(disable_thre_int); LOCK_FUNCTION(isr); LOCK_FUNCTION(isr_wrapper_0); LOCK_FUNCTION(isr_wrapper_1); LOCK_FUNCTION(isr_wrapper_2); LOCK_FUNCTION(isr_wrapper_3); LOCK_VARIABLE(port_0); LOCK_VARIABLE(port_1); LOCK_VARIABLE(port_2); LOCK_VARIABLE(port_3); return 0; }
void Time::init() { install_timer(); LOCK_VARIABLE(myCurrentTick); LOCK_FUNCTION(callback); install_int_ex(callback, BPS_TO_TIMER(Time::TicksPerSecond)); }
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(); }
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; }
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 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; }
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 init_at_startup(void) { allegro_init(); install_keyboard(); install_timer(); three_finger_flag = 0; key_led_flag = 0; // LOCK_FUNCTION (framecount); LOCK_FUNCTION (tickover); LOCK_VARIABLE (ticked); // LOCK_VARIABLE (tick_counter); // LOCK_VARIABLE (frames_per_second); // LOCK_VARIABLE (framecounter); LOCK_VARIABLE (turns_per_second); LOCK_VARIABLE (turncounter); // LOCK_VARIABLE (inputs_per_second); // LOCK_VARIABLE (inputcounter); // install_int (framecount, 1000); install_int (tickover, 30); set_color_depth(8); init_config(); if (set_gfx_mode((options.windowed == 1) ? GFX_AUTODETECT_WINDOWED : GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to set 640x480 mode\n%s\n", allegro_error); exit(1); } init_palette(); init_display(); init_menus_once_only(); init_sound(); // must come after init_menus_once_only, as that's where // options.sound_enabled is set. }
/* 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; }
//--------------------------------------------------- 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; }
/* 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 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 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"); }
/* 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(); }
/* 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); }
// 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; }
/* _dos_irq_init: * Initialises this module. */ void _dos_irq_init(void) { int c; LOCK_VARIABLE(_irq_handler); LOCK_VARIABLE(_irq_stack); LOCK_FUNCTION(_irq_wrapper_0); for (c=0; c<MAX_IRQS; c++) { _irq_handler[c].handler = NULL; _irq_handler[c].number = 0; } for (c=0; c<IRQ_STACKS; c++) { _irq_stack[c] = _AL_MALLOC(STACK_SIZE); if (_irq_stack[c]) { LOCK_DATA(_irq_stack[c], STACK_SIZE); _irq_stack[c] += STACK_SIZE - 32; /* stacks grow downwards */ } } }
int main() { int i, exit_flag = 0; int vnum, pnum; VEC3F *map_vertex; POLY3D *map_poly; BSP_NODE *root, *node; convert_map_to_3d("map.txt", &map_vertex, &map_poly, &vnum, &pnum); add_bsp_root(&root, &map_poly[0]); for(i = 1; i < pnum; i++) add_bsp_node(root, &map_poly[i], &map_vertex, &vnum); init(); LOCK_VARIABLE(fps); LOCK_VARIABLE(frame_count); LOCK_FUNCTION(update_fps); install_int(update_fps, 1000); while(!exit_flag) { if(key[KEY_ESC]) { exit_flag = 1; } clear_bitmap(buffer); blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); frame_count++; } free(map_vertex); for(i = 0; i < pnum; i++) free(map_poly[i].vind); free(map_poly); destroy_bsp_tree(root); destroy_bitmap(buffer); return 0; }