void wait() { short i=0,j=0; while( !i && !key_inkey() ) joy_get_btn_up_cnt(&i, &j); }
// If not installed, uses BIOS and returns getch(); // Else returns pending key (or waits for one if none waiting). int key_getch() { int dummy=0; if (!Installed) return getch(); while (!key_checkch()) dummy++; return key_inkey(); }
bool dc_pause_output(void) { dc_printf("More to follow. Press any key to continue. ESC halts output..."); int key; bool loop; do { loop = true; os_poll(); dc_draw(FALSE); key = key_inkey(); switch (key) { case KEY_ESC: return true; break; case KEY_PAGEUP: if (dc_scroll_y > 1) { dc_scroll_y--; } break; case KEY_PAGEDOWN: if (dc_scroll_y < DBROWS) { dc_scroll_y++; } else { dc_scroll_y = DBROWS; } break; case KEY_LEFT: // TODO: Scroll Left break; case KEY_RIGHT: // TODO: Scroll Right break; case 0: // No key pressed break; default: // Non-control key pressed, break. loop = false; } } while (loop); dc_printf("\n"); return false; };
int key_getch() { int dummy=0; if (!Installed) return 0; // return getch(); while (!key_checkch()){ dummy++; #ifdef SUPPORTS_NICEFPS d_delay(1); #endif } return key_inkey(); }
// If not installed, uses BIOS and returns getch(); // Else returns pending key (or waits for one if none waiting). int key_getch() { int dummy=0; int in; if ( !key_inited ) return 0; while (!key_checkch()){ os_poll(); dummy++; } in = key_inkey(); return in; }
int local_key_inkey(void) { int rval; rval = key_inkey(); if ( rval==KEY_ALTED+KEY_F2 ) { title_save_game(); return 0; } if (rval == KEY_PRINT_SCREEN) { save_screen_shot(0); return 0; //say no key pressed } return rval; }
int main() { fix fsecs; int oldmin=-1, oldsec=-1; error_init(NULL, NULL); dpmi_init(0); timer_init(); key_init(); RBAInit(); RBARegisterCD(); RBAPlayTrack(2); fsecs = timer_get_fixed_seconds(); do { int min, sec, frame; long headloc; if ((timer_get_fixed_seconds() - fsecs) >= F2_0) { headloc = RBAGetHeadLoc(&min, &sec, &frame); printf("Head loc: %d (%d:%d:%d)\n", headloc, min, sec, frame); if (min==oldmin && sec==oldsec) { printf("\nRepeating track..\n"); RBAPlayTrack(2); } oldmin = min; oldsec = sec; fsecs = timer_get_fixed_seconds(); } if (key_inkey()) { RBAStop(); printf("\nCD stopped.\n"); break; } } while (1); key_close(); timer_close(); return 0; }
void scores_view(int citem) { fix time_out_value; fix t1; int i,done,looper; int k; byte fades[64] = { 1,1,1,2,2,3,4,4,5,6,8,9,10,12,13,15,16,17,19,20,22,23,24,26,27,28,28,29,30,30,31,31,31,31,31,30,30,29,28,28,27,26,24,23,22,20,19,17,16,15,13,12,10,9,8,6,5,4,4,3,2,2,1,1 }; ReshowScores: scores_read(); set_screen_mode(SCREEN_MENU); gr_set_current_canvas(NULL); nm_draw_background(0,0,grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_h ); grd_curcanv->cv_font = Gamefonts[GFONT_MEDIUM_3]; gr_string( 0x8000, 15, TXT_HIGH_SCORES ); grd_curcanv->cv_font = Gamefonts[GFONT_SMALL]; gr_set_fontcolor( BM_XRGB(31,26,5), -1 ); gr_string( 31+33+XX, 46+7+YY, TXT_NAME ); gr_string( 82+33+XX, 46+7+YY, TXT_SCORE ); gr_string( 127+33+XX, 46+7+YY, TXT_SKILL ); gr_string( 170+33+XX, 46+7+YY, TXT_LEVELS ); // gr_string( 202, 46, "Kills" ); // gr_string( 234, 46, "Rescues" ); gr_string( 288-42+XX, 46+7+YY, TXT_TIME ); if ( citem < 0 ) gr_string( 0x8000, 175, TXT_PRESS_CTRL_R ); gr_set_fontcolor( BM_XRGB(28,28,28), -1 ); gr_printf( 0x8000, 31, "%c%s%c - %s", 34, Scores.cool_saying, 34, Scores.stats[0].name ); for (i=0; i<MAX_HIGH_SCORES; i++ ) { if (i==0) { gr_set_fontcolor( BM_XRGB(28,28,28), -1 ); } else { gr_set_fontcolor( gr_fade_table[BM_XRGB(28,28,28)+((28-i*2)*256)], -1 ); } scores_draw_item( i, &Scores.stats[i] ); } gr_palette_fade_in( gr_palette,32, 0); game_flush_inputs(); done = 0; looper = 0; time_out_value = timer_get_fixed_seconds()+i2f(60*5); while(!done) { if ( citem > -1 ) { t1 = timer_get_fixed_seconds(); if ( t1 > time_out_value ) done = 1; while ( timer_get_fixed_seconds() < t1+F1_0/128 ); gr_set_fontcolor( gr_fade_table[fades[looper]*256+BM_XRGB(28,28,28)], -1 ); looper++; if (looper>63) looper=0; if ( citem == MAX_HIGH_SCORES ) scores_draw_item( MAX_HIGH_SCORES, &Last_game ); else scores_draw_item( citem, &Scores.stats[citem] ); } for (i=0; i<4; i++ ) if (joy_get_button_down_cnt(i)>0) done=1; for (i=0; i<3; i++ ) if (mouse_button_down_count(i)>0) done=1; k = key_inkey(); switch( k ) { case KEY_CTRLED+KEY_R: if ( citem < 0 ) { // Reset scores... if ( nm_messagebox( NULL, 2, TXT_NO, TXT_YES, TXT_RESET_HIGH_SCORES )==1 ) { remove( get_scores_filename() ); gr_palette_fade_out( gr_palette, 32, 0 ); goto ReshowScores; } } break; case KEY_BACKSP: Int3(); k = 0; break; case KEY_PRINT_SCREEN: save_screen_shot(0); k = 0; break; case KEY_ENTER: case KEY_SPACEBAR: case KEY_ESC: done=1; break; } } // Restore background and exit gr_palette_fade_out( gr_palette, 32, 0 ); gr_set_current_canvas(NULL); game_flush_inputs(); }
void debug_console(void (*_func)(void)) { int done = 0; while( key_inkey() ) { os_poll(); } if ( !debug_inited ) { dc_init(); } dc_draw(TRUE); while (!done) { // poll the os os_poll(); int k = key_inkey(); switch( k ) { case KEY_SHIFTED+KEY_ENTER: case KEY_ESC: done = TRUE; break; case KEY_BACKSP: if (!dc_command_buf.empty()) { dc_command_buf.erase(dc_command_buf.size() - 1); } break; case KEY_F3: case KEY_UP: if (last_oldcommand < (dc_history.end() - 1)) { ++last_oldcommand; } dc_command_buf = *last_oldcommand; break; case KEY_DOWN: if (last_oldcommand > dc_history.begin()) { --last_oldcommand; } dc_command_buf = *last_oldcommand; break; case KEY_PAGEUP: if (dc_scroll_y > 1) { dc_scroll_y--; } break; case KEY_PAGEDOWN: if (dc_scroll_y < (DBROWS - DROWS)) { dc_scroll_y++; } else { dc_scroll_y = (DBROWS - DROWS); } break; case KEY_ENTER: dc_scroll_y = (DBROWS - DROWS); // Set the scroll to look at the bottom last_oldcommand = dc_history.begin(); // Reset the last oldcommand lastline = 0; // Reset the line counter // Clear the command line on the window, but don't print the prompt until the command has processed // Stuff a copy of the command line onto the history // Search for the command // If not found: // abort, // dc_printf("Error: Invalid or Missing command %s", cmd.c_str()), and // dc_printf(dc_prompt) when ready for input // Call the function for that command, and strip the cmd token from the command line string if (dc_command_buf.empty()) { dc_printf("No command given.\n"); break; } // Else, continue to process the cmd_line // z64: Thread Note: Maybe lock a mutex here to allow a previous DCF to finish/abort before starting a new one // z64: We'll just assume we won't be here unless a command has finished... dc_history.push_front(dc_command_buf); // Push the command onto the history queue last_oldcommand = dc_history.begin(); // Reset oldcommand while (dc_history.size() > DCMDS) { dc_history.pop_back(); // Keep the commands less than or equal to DCMDS } dc_command_str = dc_command_buf; // Xfer to the command string for processing dc_command_buf.resize(0); // Nullify the buffer dc_printf("%s%s\n", dc_prompt, dc_command_str.c_str()); // Print the command w/ prompt. dc_draw(FALSE); // Redraw the console without the command line. dc_do_command(&dc_command_str); // Try to do the command break; default: // Not any of the control key codes, so it's probably a letter or number. ubyte c = (ubyte)key_to_ascii(k); if ((c != 255) && (dc_command_buf.size() < MAX_CLI_LEN)) { dc_command_buf.push_back(c); } } // Do the passed function if ( _func ) { _func(); } // All done, and ready for new entry dc_draw(TRUE); } while( key_inkey() ) { os_poll(); } }
void modex_print_message(int x, int y, char *str) { #ifndef AUTOMAP_DIRECT_RENDER #ifndef AUTOMAP_NO_PAGING int i; for (i=0; i<2; i++ ) { gr_set_current_canvas(&Pages[i]); #else { gr_set_current_canvas(OffscreenPage); #endif #endif modex_printf(x, y, str, GFONT_MEDIUM_1); #ifndef AUTOMAP_DIRECT_RENDER } gr_set_current_canvas(&DrawingPages[current_page]); #endif } extern void GameLoop(int, int ); extern int set_segment_depths(int start_seg, ubyte *segbuf); u_int32_t automap_mode = SM(640,480); int automap_width = 640; int automap_height = 480; int automap_use_game_res=0; int nice_automap=0; void do_automap( int key_code ) { int done=0; vms_matrix tempm; vms_angvec tangles; int leave_mode=0; int first_time=1; // int pcx_error; int c; // char filename[] = "MAP.PCX"; fix entry_time; int pause_game=1; // Set to 1 if everything is paused during automap...No pause during net. fix t1, t2; control_info saved_control_info; grs_bitmap Automap_background; int Max_segments_away = 0; int SegmentLimit = 1; //added on 10/28/98 by adb to fix compile versions #if !defined (NDEBUG) || (!defined(AUTOMAP_NO_PAGING) && !defined(AUTOMAP_DIRECT_RENDER)) int i; #endif key_code = key_code; // disable warning... if ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) pause_game = 0; if (pause_game) stop_time(); create_name_canv(); Max_edges = min(MAX_EDGES_FROM_VERTS(Num_vertices),MAX_EDGES); //make maybe smaller than max //Edges = malloc( sizeof(Edge_info)*Max_edges); //if ( Edges == NULL ) { // mprintf((0, "Couldn't get %dK for automap!", sizeof(Edge_info)*Max_edges/1024)); // return; //} //DrawingListBright = malloc( sizeof(short)*Max_edges); //if ( DrawingListBright == NULL ) { // mprintf((0, "Couldn't get %dK for automap!", sizeof(short)*Max_edges/1024)); // return; //} mprintf( (0, "Num_vertices=%d, Max_edges=%d, (MAX:%d)\n", Num_vertices, Max_edges, MAX_EDGES )); mprintf( (0, "Allocated %d K for automap edge list\n", (sizeof(Edge_info)+sizeof(short))*Max_edges/1024 )); //edit 4/23/99 Matt Mueller - don't switch res unless we need to if (grd_curscreen->sc_mode != AUTOMAP_MODE) gr_set_mode( AUTOMAP_MODE ); else gr_set_current_canvas(NULL); //end edit -MM automap_width=grd_curscreen->sc_canvas.cv_bitmap.bm_w; automap_height=grd_curscreen->sc_canvas.cv_bitmap.bm_h; gr_palette_clear(); #ifndef AUTOMAP_DIRECT_RENDER gr_init_sub_canvas(&Pages[0],grd_curcanv,0,0,automap_width,automap_height); #ifndef AUTOMAP_NO_PAGING // NOTICE: should be 0,401! FIXME! gr_init_sub_canvas(&Pages[1],grd_curcanv,0,0,automap_width,automap_height); gr_init_sub_canvas(&DrawingPages[0],&Pages[0],0,0,automap_width,automap_height); gr_init_sub_canvas(&DrawingPages[1],&Pages[1],0,0,automap_width,automap_height); #else OffscreenPage = gr_create_canvas( automap_width,automap_height ); if (!OffscreenPage) { nm_messagebox("No memory for automap", 1, "Ok"); return; } gr_init_sub_canvas(&DrawingPages[0],OffscreenPage,0,0,automap_width,automap_height); #endif #endif gr_init_bitmap_data (&Automap_background); // pcx_error = pcx_read_bitmap(filename,&Automap_background,BM_LINEAR,NULL); // if ( pcx_error != PCX_ERROR_NONE ) { // printf("File %s - PCX error: %s",filename,pcx_errormsg(pcx_error)); // Error("File %s - PCX error: %s",filename,pcx_errormsg(pcx_error)); // return; // } #ifndef AUTOMAP_DIRECT_RENDER #ifndef AUTOMAP_NO_PAGING for (i=0; i<2; i++ ) { gr_set_current_canvas(&Pages[i]); #else { gr_set_current_canvas(OffscreenPage); #endif // gr_bitmap( 0, 0, &Automap_background ); // modex_printf( 40, 22,TXT_AUTOMAP,GFONT_BIG_1); // modex_printf( 70,353,TXT_TURN_SHIP,GFONT_SMALL); // modex_printf( 70,369,TXT_SLIDE_UPDOWN,GFONT_SMALL); // modex_printf( 70,385,TXT_VIEWING_DISTANCE,GFONT_SMALL); } #ifdef AUTOMAP_NO_PAGING //killed 05/17/99 Matt Mueller - this seems to merely copy undefined bytes around.. not needed //--killed-- gr_bm_ubitblt(automap_width,automap_height, 0, 0, 0, 0, &OffscreenPage->cv_bitmap,&Pages[0].cv_bitmap); //end kill -MM #endif gr_free_bitmap_data (&Automap_background); gr_set_current_canvas(&DrawingPages[current_page]); #endif automap_build_edge_list(); if ( ViewDist==0 ) ViewDist = ZOOM_DEFAULT; ViewMatrix = Objects[Players[Player_num].objnum].orient; tangles.p = PITCH_DEFAULT; tangles.h = 0; tangles.b = 0; done = 0; view_target = Objects[Players[Player_num].objnum].pos; t1 = entry_time = timer_get_fixed_seconds(); t2 = t1; //Fill in Automap_visited from Objects[Players[Player_num].objnum].segnum Max_segments_away = set_segment_depths(Objects[Players[Player_num].objnum].segnum, Automap_visited); SegmentLimit = Max_segments_away; adjust_segment_limit(SegmentLimit); while(!done) { if ( leave_mode==0 && Controls.automap_state && (timer_get_fixed_seconds()-entry_time)>LEAVE_TIME) leave_mode = 1; if ( !Controls.automap_state && (leave_mode==1) ) done=1; if (!pause_game) { ushort old_wiggle; saved_control_info = Controls; // Save controls so we can zero them memset(&Controls,0,sizeof(control_info)); // Clear everything... old_wiggle = ConsoleObject->mtype.phys_info.flags & PF_WIGGLE; // Save old wiggle ConsoleObject->mtype.phys_info.flags &= ~PF_WIGGLE; // Turn off wiggle #ifdef NETWORK if (multi_menu_poll()) done = 1; #endif // GameLoop( 0, 0 ); // Do game loop with no rendering and no reading controls. ConsoleObject->mtype.phys_info.flags |= old_wiggle; // Restore wiggle Controls = saved_control_info; } controls_read_all(); if ( Controls.automap_down_count ) { if (leave_mode==0) done = 1; c = 0; } while( (c=key_inkey()) ) { switch( c ) { #ifndef NDEBUG case KEY_BACKSP: Int3(); break; #endif case KEY_PRINT_SCREEN: save_screen_shot(1); break; case KEY_ESC: if (leave_mode==0) done = 1; break; case KEY_ALTED+KEY_F: // Alt+F shows full map, if cheats enabled if (Cheats_enabled) { uint t; t = Players[Player_num].flags; Players[Player_num].flags |= PLAYER_FLAGS_MAP_ALL_CHEAT; automap_build_edge_list(); Players[Player_num].flags=t; } break; #ifndef NDEBUG case KEY_DEBUGGED+KEY_F: { for (i=0; i<=Highest_segment_index; i++ ) Automap_visited[i] = 1; automap_build_edge_list(); Max_segments_away = set_segment_depths(Objects[Players[Player_num].objnum].segnum, Automap_visited); SegmentLimit = Max_segments_away; adjust_segment_limit(SegmentLimit); } break; #endif case KEY_MINUS: if (SegmentLimit > 1) { SegmentLimit--; adjust_segment_limit(SegmentLimit); } break; case KEY_EQUAL: if (SegmentLimit < Max_segments_away) { SegmentLimit++; adjust_segment_limit(SegmentLimit); } break; } } if ( Controls.fire_primary_down_count ) { // Reset orientation ViewDist = ZOOM_DEFAULT; tangles.p = PITCH_DEFAULT; tangles.h = 0; tangles.b = 0; view_target = Objects[Players[Player_num].objnum].pos; } ViewDist -= Controls.forward_thrust_time*ZOOM_SPEED_FACTOR; tangles.p += fixdiv( Controls.pitch_time, ROT_SPEED_DIVISOR ); tangles.h += fixdiv( Controls.heading_time, ROT_SPEED_DIVISOR ); tangles.b += fixdiv( Controls.bank_time, ROT_SPEED_DIVISOR*2 ); if ( Controls.vertical_thrust_time || Controls.sideways_thrust_time ) { vms_angvec tangles1; vms_vector old_vt; old_vt = view_target; tangles1 = tangles; vm_angles_2_matrix(&tempm,&tangles1); vm_matrix_x_matrix(&ViewMatrix,&Objects[Players[Player_num].objnum].orient,&tempm); vm_vec_scale_add2( &view_target, &ViewMatrix.uvec, Controls.vertical_thrust_time*SLIDE_SPEED ); vm_vec_scale_add2( &view_target, &ViewMatrix.rvec, Controls.sideways_thrust_time*SLIDE_SPEED ); if ( vm_vec_dist_quick( &view_target, &Objects[Players[Player_num].objnum].pos) > i2f(1000) ) { view_target = old_vt; } } vm_angles_2_matrix(&tempm,&tangles); vm_matrix_x_matrix(&ViewMatrix,&Objects[Players[Player_num].objnum].orient,&tempm); if ( ViewDist < ZOOM_MIN_VALUE ) ViewDist = ZOOM_MIN_VALUE; if ( ViewDist > ZOOM_MAX_VALUE ) ViewDist = ZOOM_MAX_VALUE; draw_automap(); if ( first_time ) { first_time = 0; gr_palette_load( gr_palette ); } t2 = timer_get_fixed_seconds(); while (t2-t1<F1_0/100){//ogl is fast enough that the automap can read the input too fast and you start to turn really slow. So delay a bit (and free up some cpu :) if (nice_automap) d_delay(1); t2 = timer_get_fixed_seconds(); } if (pause_game) FrameTime=t2-t1; t1 = t2; } //free(Edges); //free(DrawingListBright); gr_free_canvas(name_canv); name_canv=NULL; #ifdef AUTOMAP_NO_PAGING gr_free_canvas(OffscreenPage); OffscreenPage = NULL; #endif mprintf( (0, "Automap memory freed\n" )); game_flush_inputs(); if (pause_game) start_time(); } void adjust_segment_limit(int SegmentLimit) { int i,e1; Edge_info * e; mprintf(( 0, "Seglimit: %d\n", SegmentLimit )); for (i=0; i<=Highest_edge_index; i++ ) { e = &Edges[i]; e->flags |= EF_TOO_FAR; for (e1=0; e1<e->num_faces; e1++ ) { if ( Automap_visited[e->segnum[e1]] <= SegmentLimit ) { e->flags &= (~EF_TOO_FAR); break; } } } }
void iglasses_init_tracking(int serial_port) { fix t1,t2; int c; if (iglasses_headset_installed) return; if ( (serial_port < 1) || (serial_port > 4) ) { Error( TXT_IGLASSES_ERROR_1 ); } printf( "\n\n"); printf( TXT_IGLASSES_INIT, serial_port ); printf( "\n%s\n", TXT_IGLASSES_ON); printf( "Looking for glasses - %s", TXT_PRESS_ESC_TO_ABORT); Iport = PortOpenGreenleafFast(serial_port-1, 9600, 'N', 8, 1 ); if ( !Iport ) { printf( "%s\n", TXT_SERIAL_FAILURE, Iport->status ); return; } SetDtr( Iport, 1 ); SetRts( Iport, 1 ); UseRtsCts( Iport, 0 ); t2 = timer_get_fixed_seconds() + i2f(20); while(timer_get_fixed_seconds() < t2) { printf( "." ); t1 = timer_get_fixed_seconds() + F1_0; ClearRXBuffer(Iport); ClearTXBuffer(Iport); WriteBuffer( Iport, "!\r", 2 ); while ( timer_get_fixed_seconds() < t1 ) { if ( key_inkey() == KEY_ESC ) goto NotOK; c = ReadChar( Iport ); if ( c == 'O' ) { goto TrackerOK1; } } } NotOK:; printf( "\n\nWarning: Cannot find i-glasses! on port %d\n" " Press Esc to abort D2, any other key to continue without i-glasses support.\n" " Use SETUP to disable i-glasses support.\n",serial_port); if ( key_getch() == KEY_ESC ) exit(1); else return; TrackerOK1: while( 1 ) { printf( "." ); t1 = timer_get_fixed_seconds() + F1_0; ClearRXBuffer(Iport); ClearTXBuffer(Iport); // M2 = p,b,h // M1 = all data WriteBuffer( Iport, "!M1,P,B\r", 8 ); while ( timer_get_fixed_seconds() < t1 ) { if ( key_inkey() == KEY_ESC ) return; c = ReadChar( Iport ); if ( c == 'O' ) { goto TrackerOK2; } } } TrackerOK2: printf( ".\n" ); ClearRXBuffer(Iport); ClearTXBuffer(Iport); WriteChar( Iport, 'S' ); iglasses_headset_installed = 1; atexit( iglasses_close_tracking ); #ifdef USE_FILTERS initFIR( &X_filter ); initFIR( &Y_filter ); initFIR( &Z_filter ); #endif // { // fix y,p,r; // while( 1 ) { // iglasses_read_headset( &y, &p, &r); // //printf( "%d\t%d\t%d\n", y, p, r ); // printf( "%8.2f\n", f2fl(y) ); // if (key_inkey()==KEY_ESC) break; // } // } }
int game_poll() { return key_inkey(); }
int game_check_key() { return key_inkey(); }
void debug_console( void (*_func)() ) { int done = 0; scanner_init(); while( key_inkey() ) { os_poll(); } if ( !debug_inited ) { debug_init(); } debug_draw(); while (!done) { // poll the os os_poll(); int k = key_inkey(); switch( k ) { case KEY_SHIFTED+KEY_ENTER: case KEY_ESC: done=1; break; case KEY_BACKSP: if ( command_line_pos > 0 ) { command_line[--command_line_pos] = 0; } break; case KEY_F3: if ( last_oldcommand > -1 ) { strcpy_s( command_line, oldcommand_line[last_oldcommand] ); command_line_pos = strlen(command_line); command_line[command_line_pos] = 0; } break; case KEY_UP: command_scroll--; if (command_scroll<0) { command_scroll = last_oldcommand; } if ( command_scroll > -1 ) { strcpy_s( command_line, oldcommand_line[command_scroll] ); command_line_pos = strlen(command_line); command_line[command_line_pos] = 0; } break; case KEY_DOWN: command_scroll++; if (command_scroll>last_oldcommand) { command_scroll = 0; } if (command_scroll>last_oldcommand) { command_scroll = -1; } if ( command_scroll > -1 ) { strcpy_s( command_line, oldcommand_line[command_scroll] ); command_line_pos = strlen(command_line); command_line[command_line_pos] = 0; } break; case KEY_ENTER: { debug_output( '\n' ); debug_draw(); debug_do_command(command_line); int i, found = 0; for (i=0; i<=last_oldcommand; i++ ) { if (!stricmp( oldcommand_line[i], command_line )) { found = 1; } } if ( !found ) { if ( last_oldcommand < DEBUG_HISTORY-1 ) { last_oldcommand++; strcpy_s( oldcommand_line[last_oldcommand], command_line); } else { int iLoop; for (iLoop=0; iLoop<last_oldcommand; iLoop++ ) { strcpy_s( oldcommand_line[iLoop], oldcommand_line[iLoop+1] ); } strcpy_s( oldcommand_line[last_oldcommand], command_line); } } debug_output( '\n' ); command_line_pos = 0; command_line[command_line_pos] = 0; command_scroll = 0; } break; default: { ubyte c = (ubyte)key_to_ascii(k); if ( c != 255 ) { command_line[command_line_pos++] = c; command_line[command_line_pos] = 0; } } } strcpy_s( debug_text[debug_y], ">" ); strcat_s( debug_text[debug_y], command_line ); debug_draw(); if ( _func ) { _func(); } } while( key_inkey() ) { os_poll(); } }
void credits_show() { int i, j, l, done; CFILE * file; char buffer[NUM_LINES][80]; grs_bitmap backdrop; ubyte backdrop_palette[768]; int pcx_error; int buffer_line = 0; fix last_time; fix time_delay = 4180 / f2fl(Scale_y); // ~ F1_0 / 12.9 int first_line_offset,extra_inc=0; int have_bin_file = 0; char * tempp; grs_point scale_pts[] = FULLSCREEN_SCALE_PTS; ubyte *fade_values = malloc(grd_curscreen->sc_h); for (i = 0; i < grd_curscreen->sc_h; ++i) { fade_values[i] = fade_values_200[(int)(((float)i / (float)grd_curscreen->sc_h) * 200)]; } set_screen_mode(SCREEN_MENU); // Clear out all tex buffer lines. for (i=0; i<NUM_LINES; i++ ) buffer[i][0] = 0; have_bin_file = 0; file = cfopen( "credits.tex", "rb" ); if (file == NULL) { file = cfopen("credits.txb", "rb"); if (file == NULL) Error("Missing CREDITS.TEX and CREDITS.TXB file\n"); have_bin_file = 1; } gr_use_palette_table( "credits.256" ); header_font = gr_init_font( "font1-1.fnt" ); title_font = gr_init_font( "font2-3.fnt" ); names_font = gr_init_font( "font2-2.fnt" ); backdrop.bm_data=NULL; pcx_error = pcx_read_bitmap("stars.pcx",&backdrop,BM_LINEAR,backdrop_palette); if (pcx_error != PCX_ERROR_NONE) { cfclose(file); return; } songs_play_song( SONG_CREDITS, 0 ); gr_remap_bitmap_good( &backdrop,backdrop_palette, -1, -1 ); gr_set_current_canvas(NULL); scale_bitmap(&backdrop,scale_pts); gr_palette_fade_in( gr_palette, 32, 0 ); vfx_set_palette_sub( gr_palette ); //gr_clear_canvas(BM_XRGB(0,0,0)); key_flush(); last_time = timer_get_fixed_seconds(); done = 0; first_line_offset = 0; while( 1 ) { int k; do { buffer_line = (buffer_line+1) % NUM_LINES; if (cfgets( buffer[buffer_line], 80, file )) { char *p; if (have_bin_file) { // is this a binary tbl file for (i = 0; i < strlen(buffer[buffer_line]) - 1; i++) { encode_rotate_left(&(buffer[buffer_line][i])); buffer[buffer_line][i] ^= BITMAP_TBL_XOR; encode_rotate_left(&(buffer[buffer_line][i])); } } p = strchr(&buffer[buffer_line][0],'\n'); if (p) *p = '\0'; } else { //fseek( file, 0, SEEK_SET); buffer[buffer_line][0] = 0; done++; } } while (extra_inc--); extra_inc = 0; for (i=0; i<ROW_SPACING; i++ ) { int y; y = first_line_offset - i; #ifndef OGLES gr_set_current_canvas(VR_offscreen_buffer); #endif scale_bitmap(&backdrop, scale_pts); for (j=0; j<NUM_LINES; j++ ) { char *s; l = (buffer_line + j + 1 ) % NUM_LINES; s = buffer[l]; if ( s[0] == '!' ) { s++; } else if ( s[0] == '$' ) { grd_curcanv->cv_font = header_font; s++; } else if ( s[0] == '*' ) { grd_curcanv->cv_font = title_font; s++; } else grd_curcanv->cv_font = names_font; gr_bitblt_fade_table = fade_values; tempp = strchr( s, '\t' ); if ( tempp ) { int w, h, aw; *tempp = 0; gr_get_string_size( s, &w, &h, &aw ); w *= f2fl(Scale_x); h *= f2fl(Scale_y); gr_scale_printf( (160-w)/2, y, Scale_factor, Scale_factor, s ); gr_get_string_size( &tempp[1], &w, &h, &aw ); w *= f2fl(Scale_x); h *= f2fl(Scale_y); gr_scale_printf( 160+((160-w)/2), y, Scale_factor, Scale_factor, &tempp[1] ); *tempp = '\t'; } else { gr_scale_printf( 0x8000, y, Scale_factor, Scale_factor, s ); } gr_bitblt_fade_table = NULL; if (buffer[l][0] == '!') y += ROW_SPACING/2; else y += ROW_SPACING; } #ifdef OGLES showRenderBuffer(); #else gr_bm_ubitblt(grd_curscreen->sc_w, grd_curscreen->sc_h, 0, 0, 0, 0, &(VR_offscreen_buffer->cv_bitmap), &(grd_curscreen->sc_canvas.cv_bitmap) ); #endif while( timer_get_fixed_seconds() < last_time+time_delay ); last_time = timer_get_fixed_seconds(); k = key_inkey(); #ifndef NDEBUG if (k == KEY_BACKSP) { Int3(); k=0; } #endif // { // fix ot = time_delay; // time_delay += (keyd_pressed[KEY_X] - keyd_pressed[KEY_Z])*100; // if (ot!=time_delay) { // mprintf( (0, "[%x] ", time_delay )); // } // } if (k == KEY_PRINT_SCREEN) { save_screen_shot(0); k = 0; } if ((k>0)||(done>NUM_LINES)) { gr_close_font(header_font); gr_close_font(title_font); gr_close_font(names_font); gr_palette_fade_out( gr_palette, 32, 0 ); gr_use_palette_table( "palette.256" ); free(backdrop.bm_data); cfclose(file); songs_play_song( SONG_TITLE, 1 ); return; } } if (buffer[(buffer_line + 1 ) % NUM_LINES][0] == '!') { first_line_offset -= ROW_SPACING-ROW_SPACING/2; if (first_line_offset <= -ROW_SPACING) { first_line_offset += ROW_SPACING; extra_inc++; } } } free(fade_values); }
void main (void) { unsigned int t1, t2; int i, start, stop, frames; short bd1, bd2, bu1, bu2, b, x, y, bt1, bt2; key_init(); if (!joy_init()) { printf( "No joystick detected.\n" ); key_close(); exit(1); } timer_init( 0, NULL ); printf( "Displaying joystick button transitions and time...any key leaves.\n" ); i = 0; while( !key_inkey() ) { i++; if (i>500000) { i = 0; joy_get_btn_down_cnt( &bd1, &bd2 ); joy_get_btn_up_cnt( &bu1, &bu2 ); joy_get_btn_time( &bt1, &bt2 ); printf( "%d %d %d %d T1:%d T2:%d\n",bd1, bu1, bd2, bu2, bt1, bt2 ); } } printf( "\nPress c to do a deluxe-full-fledged calibration.\n" ); printf( "or any other key to just use the cheap method.\n" ); if (key_getch() == 'c') { printf( "Move stick to center and press any key.\n" ); wait(); joy_set_cen(); printf( "Move stick to Upper Left corner and press any key.\n" ); wait(); joy_set_ul(); printf( "Move stick to Lower Right corner and press any key.\n" ); wait(); joy_set_lr(); } while( !keyd_pressed[KEY_ESC]) { frames++; joy_get_pos( &x, &y ); b = joy_get_btns(); printf( "%d, %d (%d %d)\n", x, y, b & 1, b & 2); } printf( "Testing joystick reading speed...\n" ); t1 = timer_get_microseconds(); joy_get_pos( &x, &y ); t2 = timer_get_microseconds(); printf( "~ %u æsec per reading using Timer Timing\n", t2 - t1 ); joy_close(); key_close(); timer_close(); frames = 1000; start = TICKER; for (i=0; i<frames; i++ ) joy_get_pos( &x, &y ); stop = TICKER; printf( "~ %d æsec per reading using BIOS ticker as a stopwatch.\n", USECS_PER_READING( start, stop, frames ) ); }
void ui_mega_process() { int mx, my, mz; unsigned char k; event_process(); switch( Record ) { case 0: mouse_get_delta( &mx, &my, &mz ); Mouse.new_dx = mx; Mouse.new_dy = my; Mouse.new_buttons = mouse_get_btns(); last_keypress = key_inkey(); if ( Mouse.new_buttons || last_keypress || Mouse.new_dx || Mouse.new_dy ) { last_event = timer_query(); } break; case 1: if (ui_event_counter==0 ) { EventBuffer[ui_event_counter].frame = 0; EventBuffer[ui_event_counter].type = 7; EventBuffer[ui_event_counter].data = ui_number_of_events; ui_event_counter++; } if (ui_event_counter==1 && (RecordFlags & UI_RECORD_MOUSE) ) { Mouse.new_buttons = 0; EventBuffer[ui_event_counter].frame = FrameCount; EventBuffer[ui_event_counter].type = 6; EventBuffer[ui_event_counter].data = ((Mouse.y & 0xFFFF) << 16) | (Mouse.x & 0xFFFF); ui_event_counter++; } mouse_get_delta( &mx, &my, &mz ); MouseDX = mx; MouseDY = my; MouseButtons = mouse_get_btns(); Mouse.new_dx = MouseDX; Mouse.new_dy = MouseDY; if ((MouseDX != 0 || MouseDY != 0) && (RecordFlags & UI_RECORD_MOUSE) ) { if (ui_event_counter < ui_number_of_events-1 ) { EventBuffer[ui_event_counter].frame = FrameCount; EventBuffer[ui_event_counter].type = 1; EventBuffer[ui_event_counter].data = ((MouseDY & 0xFFFF) << 16) | (MouseDX & 0xFFFF); ui_event_counter++; } else { Record = 0; } } if ( (MouseButtons != Mouse.new_buttons) && (RecordFlags & UI_RECORD_MOUSE) ) { Mouse.new_buttons = MouseButtons; if (ui_event_counter < ui_number_of_events-1 ) { EventBuffer[ui_event_counter].frame = FrameCount; EventBuffer[ui_event_counter].type = 2; EventBuffer[ui_event_counter].data = MouseButtons; ui_event_counter++; } else { Record = 0; } } if ( keyd_last_pressed && (RecordFlags & UI_RECORD_KEYS) ) { _disable(); k = keyd_last_pressed; keyd_last_pressed= 0; _enable(); if (ui_event_counter < ui_number_of_events-1 ) { EventBuffer[ui_event_counter].frame = FrameCount; EventBuffer[ui_event_counter].type = 3; EventBuffer[ui_event_counter].data = k; ui_event_counter++; } else { Record = 0; } } if ( keyd_last_released && (RecordFlags & UI_RECORD_KEYS) ) { _disable(); k = keyd_last_released; keyd_last_released= 0; _enable(); if (ui_event_counter < ui_number_of_events-1 ) { EventBuffer[ui_event_counter].frame = FrameCount; EventBuffer[ui_event_counter].type = 4; EventBuffer[ui_event_counter].data = k; ui_event_counter++; } else { Record = 0; } } last_keypress = key_inkey(); if (last_keypress == KEY_F12 ) { ui_number_of_events = ui_event_counter; last_keypress = 0; Record = 0; break; } if ((last_keypress != 0) && (RecordFlags & UI_RECORD_KEYS) ) { if (ui_event_counter < ui_number_of_events-1 ) { EventBuffer[ui_event_counter].frame = FrameCount; EventBuffer[ui_event_counter].type = 5; EventBuffer[ui_event_counter].data = last_keypress; ui_event_counter++; } else { Record = 0; } } FrameCount++; break; case 2: case 3: Mouse.new_dx = 0; Mouse.new_dy = 0; Mouse.new_buttons = 0; last_keypress = 0; if ( keyd_last_pressed ) { _disable(); k = keyd_last_pressed; keyd_last_pressed = 0; _disable(); SavedState[k] = 1; } if ( keyd_last_released ) { _disable(); k = keyd_last_released; keyd_last_released = 0; _disable(); SavedState[k] = 0; } if (key_inkey() == KEY_F12 ) { restore_state(); Record = 0; break; } if (EventBuffer==NULL) { restore_state(); Record = 0; break; } while( (ui_event_counter < ui_number_of_events) && (EventBuffer[ui_event_counter].frame <= FrameCount) ) { switch ( EventBuffer[ui_event_counter].type ) { case 1: // Mouse moved Mouse.new_dx = EventBuffer[ui_event_counter].data & 0xFFFF; Mouse.new_dy = (EventBuffer[ui_event_counter].data >> 16) & 0xFFFF; break; case 2: // Mouse buttons changed Mouse.new_buttons = EventBuffer[ui_event_counter].data; break; case 3: // Key moved down keyd_pressed[ EventBuffer[ui_event_counter].data ] = 1; break; case 4: // Key moved up keyd_pressed[ EventBuffer[ui_event_counter].data ] = 0; break; case 5: // Key pressed last_keypress = EventBuffer[ui_event_counter].data; break; case 6: // Initial Mouse X position Mouse.x = EventBuffer[ui_event_counter].data & 0xFFFF; Mouse.y = (EventBuffer[ui_event_counter].data >> 16) & 0xFFFF; break; case 7: break; } ui_event_counter++; if (ui_event_counter >= ui_number_of_events ) { Record = 0; restore_state(); //( 0, "Done playing %d events.\n", ui_number_of_events ); } } switch (Record) { case 2: { int next_frame; if ( ui_event_counter < ui_number_of_events ) { next_frame = EventBuffer[ui_event_counter].frame; if ( (FrameCount+PlaybackSpeed) < next_frame ) FrameCount = next_frame - PlaybackSpeed; else FrameCount++; } else { FrameCount++; } } break; case 3: if ( ui_event_counter < ui_number_of_events ) FrameCount = EventBuffer[ui_event_counter].frame; else FrameCount++; break; default: FrameCount++; } } ui_mouse_process(); }
void do_automap( int key_code ) { int done=0; vms_matrix tempm; vms_angvec tangles; int leave_mode=0; int first_time=1; int pcx_error; int i; int c; char filename[] = "MAP.PCX"; fix entry_time; int pause_game=1; // Set to 1 if everything is paused during automap...No pause during net. fix t1, t2; control_info saved_control_info; int Max_segments_away = 0; int SegmentLimit = 1; key_code = key_code; // disable warning... if ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) pause_game = 0; if (pause_game) stop_time(); create_name_canv(); Max_edges = min(MAX_EDGES_FROM_VERTS(Num_vertices),MAX_EDGES); //make maybe smaller than max //Edges = malloc( sizeof(Edge_info)*Max_edges); //if ( Edges == NULL ) { // mprintf((0, "Couldn't get %dK for automap!", sizeof(Edge_info)*Max_edges/1024)); // return; //} //DrawingListBright = malloc( sizeof(short)*Max_edges); //if ( DrawingListBright == NULL ) { // mprintf((0, "Couldn't get %dK for automap!", sizeof(short)*Max_edges/1024)); // return; //} mprintf( (0, "Num_vertices=%d, Max_edges=%d, (MAX:%d)\n", Num_vertices, Max_edges, MAX_EDGES )); mprintf( (0, "Allocated %d K for automap edge list\n", (sizeof(Edge_info)+sizeof(short))*Max_edges/1024 )); gr_palette_clear(); gr_init_sub_canvas(&Page,&VR_render_buffer[0],0, 0, 640, 480); gr_init_sub_canvas(&DrawingPage,&Page,38,77,564,381); #if 0 gr_init_sub_canvas(&Pages[0],grd_curcanv,0,0,320,400); gr_init_sub_canvas(&Pages[1],grd_curcanv,0,401,320,400); gr_init_sub_canvas(&DrawingPages[0],&Pages[0],16,69,288,272); gr_init_sub_canvas(&DrawingPages[1],&Pages[1],16,69,288,272); #endif gr_set_current_canvas(&Page); pcx_error = pcx_read_bitmap(filename,&(grd_curcanv->cv_bitmap),BM_LINEAR,NULL); if ( pcx_error != PCX_ERROR_NONE ) { printf("File %s - PCX error: %s",filename,pcx_errormsg(pcx_error)); Error("File %s - PCX error: %s",filename,pcx_errormsg(pcx_error)); return; } gr_set_curfont(Gamefonts[GFONT_BIG_1]); gr_set_fontcolor(BM_XRGB(20, 20, 20), -1); gr_printf( 80, 36,TXT_AUTOMAP,GFONT_BIG_1); gr_set_curfont(Gamefonts[GFONT_SMALL]); gr_set_fontcolor(BM_XRGB(20, 20, 20), -1); gr_printf( 265, 27,TXT_TURN_SHIP); gr_printf( 265, 44,TXT_SLIDE_UPDOWN); gr_printf( 265, 61,TXT_VIEWING_DISTANCE); gr_set_current_canvas(&DrawingPage); automap_build_edge_list(); if ( ViewDist==0 ) ViewDist = ZOOM_DEFAULT; ViewMatrix = Objects[Players[Player_num].objnum].orient; tangles.p = PITCH_DEFAULT; tangles.h = 0; tangles.b = 0; done = 0; view_target = Objects[Players[Player_num].objnum].pos; t1 = entry_time = timer_get_fixed_seconds(); t2 = t1; //Fill in Automap_visited from Objects[Players[Player_num].objnum].segnum Max_segments_away = set_segment_depths(Objects[Players[Player_num].objnum].segnum, Automap_visited); SegmentLimit = Max_segments_away; adjust_segment_limit(SegmentLimit); while(!done) { #ifndef MAC_SHAREWARE redbook_restart_track(); #endif if ( leave_mode==0 && Controls.automap_state && (timer_get_fixed_seconds()-entry_time)>LEAVE_TIME) leave_mode = 1; if ( !Controls.automap_state && (leave_mode==1) ) done=1; if (!pause_game) { ushort old_wiggle; saved_control_info = Controls; // Save controls so we can zero them memset(&Controls,0,sizeof(control_info)); // Clear everything... old_wiggle = ConsoleObject->mtype.phys_info.flags & PF_WIGGLE; // Save old wiggle ConsoleObject->mtype.phys_info.flags &= ~PF_WIGGLE; // Turn off wiggle #ifdef NETWORK if (multi_menu_poll()) done = 1; #endif // GameLoop( 0, 0 ); // Do game loop with no rendering and no reading controls. ConsoleObject->mtype.phys_info.flags |= old_wiggle; // Restore wiggle Controls = saved_control_info; } controls_read_all(); if ( Controls.automap_down_count ) { if (leave_mode==0) done = 1; c = 0; } while( (c=key_inkey()) ) { switch( c ) { #ifndef NDEBUG case KEY_BACKSP: Int3(); break; #endif case KEY_PRINT_SCREEN: save_screen_shot(1); break; case KEY_ESC: if (leave_mode==0) done = 1; break; case KEY_ALTED+KEY_F: // Alt+F shows full map, if cheats enabled if (Cheats_enabled) { uint t; t = Players[Player_num].flags; Players[Player_num].flags |= PLAYER_FLAGS_MAP_ALL_CHEAT; automap_build_edge_list(); Players[Player_num].flags=t; } break; #ifndef NDEBUG case KEY_DEBUGGED+KEY_F: { for (i=0; i<=Highest_segment_index; i++ ) Automap_visited[i] = 1; automap_build_edge_list(); Max_segments_away = set_segment_depths(Objects[Players[Player_num].objnum].segnum, Automap_visited); SegmentLimit = Max_segments_away; adjust_segment_limit(SegmentLimit); } break; #endif case KEY_MINUS: if (SegmentLimit > 1) { SegmentLimit--; adjust_segment_limit(SegmentLimit); } break; case KEY_EQUAL: if (SegmentLimit < Max_segments_away) { SegmentLimit++; adjust_segment_limit(SegmentLimit); } break; } } if ( Controls.fire_primary_down_count ) { // Reset orientation ViewDist = ZOOM_DEFAULT; tangles.p = PITCH_DEFAULT; tangles.h = 0; tangles.b = 0; view_target = Objects[Players[Player_num].objnum].pos; } ViewDist -= Controls.forward_thrust_time*ZOOM_SPEED_FACTOR; tangles.p += fixdiv( Controls.pitch_time, ROT_SPEED_DIVISOR ); tangles.h += fixdiv( Controls.heading_time, ROT_SPEED_DIVISOR ); tangles.b += fixdiv( Controls.bank_time, ROT_SPEED_DIVISOR*2 ); if ( Controls.vertical_thrust_time || Controls.sideways_thrust_time ) { vms_angvec tangles1; vms_vector old_vt; old_vt = view_target; tangles1 = tangles; vm_angles_2_matrix(&tempm,&tangles1); vm_matrix_x_matrix(&ViewMatrix,&Objects[Players[Player_num].objnum].orient,&tempm); vm_vec_scale_add2( &view_target, &ViewMatrix.uvec, Controls.vertical_thrust_time*SLIDE_SPEED ); vm_vec_scale_add2( &view_target, &ViewMatrix.rvec, Controls.sideways_thrust_time*SLIDE_SPEED ); if ( vm_vec_dist_quick( &view_target, &Objects[Players[Player_num].objnum].pos) > i2f(1000) ) { view_target = old_vt; } } vm_angles_2_matrix(&tempm,&tangles); vm_matrix_x_matrix(&ViewMatrix,&Objects[Players[Player_num].objnum].orient,&tempm); if ( ViewDist < ZOOM_MIN_VALUE ) ViewDist = ZOOM_MIN_VALUE; if ( ViewDist > ZOOM_MAX_VALUE ) ViewDist = ZOOM_MAX_VALUE; draw_automap(); if ( first_time ) { first_time = 0; gr_palette_load( gr_palette ); } t2 = timer_get_fixed_seconds(); if (pause_game) FrameTime=t2-t1; t1 = t2; } //free(Edges); //free(DrawingListBright); gr_free_canvas(name_canv); name_canv=NULL; mprintf( (0, "Automap memory freed\n" )); game_flush_inputs(); if (pause_game) start_time(); }