static void draw_text_error(void) { int x = 0; int y = 0; int dx = text_size_x(); int dy = text_size_y(); text_clear(); draw_text_center(x, y, dx, "ERROR! An error occurred in your last action!" , COLOR_REVERSE); ++y; ++y; y = draw_text_para(x, y, dx, dy, "Your action has generated an error. Probably you have requested an " "unsupported feature by your hardware or software." , COLOR_NORMAL); if (*error_get()) { y = draw_text_para(x, y, dx, dy-y, "\nThe video software reports this error:", COLOR_NORMAL); log_std(("v: error \"%s\"\n", error_get())); y = draw_text_para(x, y, dx, dy-y, error_get(), COLOR_ERROR); } y = draw_text_para(x, y, dx, dy-y, "\nPress ESC", COLOR_NORMAL); video_wait_vsync(); do { target_idle(); os_poll(); } while (inputb_get()==INPUTB_NONE); }
void run(void) { target_clock_t last; printf("Press ESC or Break to exit\n\r"); signal(SIGINT, sigint); last = target_clock(); while (!done) { if (inputb_hit()) { unsigned k; target_clock_t current = target_clock(); double period = (current - last) * 1000.0 / TARGET_CLOCKS_PER_SEC; k = inputb_get(); last = current; if (k > 32 && k < 256) printf("(%6.1f ms) %d '%c'\n\r", period, k, (char)k); else printf("(%6.1f ms) %d\n\r", period, k); if (k == 27) done = 1; } os_poll(); target_yield(); } }
// key_in: If not -1, this means to use this key as input, and not call game_poll() int UI_WINDOW::process(int key_in,int process_mouse) { UI_GADGET *tmp; // only does stuff in non THREADED mode os_poll(); if (process_mouse){ ui_mouse_process(); } if (key_in == -1){ keypress = game_check_key(); } else { keypress = key_in; } last_keypress = keypress; do_dump_check(); if (mouse_captured_gadget && B1_RELEASED){ mouse_captured_gadget = NULL; } // The following code was commented out by NeilK on 4/15/99 to fix a problem we were having with // the UI_SLIDER2 class not receiving the process event when the mouse was dragging the scroller // but outside the mask region. I checked a handful of other screens and so no adverse affects // of this change at the time. /* if (mouse_captured_gadget) { mouse_captured_gadget->process(); // if a control has captured the mouse, only it gets processed use_hack_to_get_around_stupid_problem_flag = 0; return last_keypress; } */ if (!first_gadget) { use_hack_to_get_around_stupid_problem_flag = 0; return last_keypress; } check_focus_switch_keys(); // run through all top level gadgets and process them (they are responsible for processing // their children, which UI_GADGET will handle if you don't override process() or if you // do, you call UI_GADGET::process()). if ( !ignore_gadgets ) { tmp = first_gadget; do { if ( !tmp->check_move() ) tmp->process(); tmp = tmp->next; } while (tmp != first_gadget); } use_hack_to_get_around_stupid_problem_flag = 0; return last_keypress; }
int popup_do_with_condition(popup_info *pi, int flags, int(*condition)()) { int screen_id, choice = -1, done = 0; int test; screen_id = gr_save_screen(); if ( popup_init(pi, flags) == -1 ) return -1; int old_max_w_unscaled = gr_screen.max_w_unscaled; int old_max_h_unscaled = gr_screen.max_h_unscaled; int old_max_w_unscaled_zoomed = gr_screen.max_w_unscaled_zoomed; int old_max_h_unscaled_zoomed = gr_screen.max_h_unscaled_zoomed; gr_reset_screen_scale(); while(!done) { int k; os_poll(); game_set_frametime(-1); game_do_state_common(gameseq_get_state()); // do stuff common to all states gr_restore_screen(screen_id); // draw one frame first Popup_window.draw(); popup_force_draw_buttons(pi); popup_draw_msg_text(pi, flags); popup_draw_button_text(pi, flags); gr_flip(); // test the condition function or process for the window if ((test = condition()) > 0) { done = 1; choice = test; } else { k = Popup_window.process(); // poll for input, handle mouse choice = popup_process_keys(pi, k, flags); if ( choice != POPUP_NOCHANGE ) { done=1; } if ( !done ) { choice = popup_check_buttons(pi); if ( choice != POPUP_NOCHANGE ) { done=1; } } } } gr_set_screen_scale(old_max_w_unscaled, old_max_h_unscaled, old_max_w_unscaled_zoomed, old_max_h_unscaled_zoomed); popup_close(pi,screen_id); return choice; }
static adv_error cmd_onvideo_calib(void) { adv_mode mode; adv_crtc* crtc; unsigned speed; char buffer[128]; mode_reset(&mode); if (the_mode_index == MODE_FLAGS_INDEX_TEXT) { error_set("Command supported only in graphics mode"); return -1; } crtc = menu_current(); if (!crtc) return -1; if (!crtc_is_fake(crtc) && !crtc_clock_check(&the_monitor, crtc)) return -1; if (video_mode_generate(&mode, crtc, the_mode_index)!=0) { return -1; } if (text_mode_set(&mode) != 0) { text_reset(); return -1; } video_write_lock(); draw_graphics_palette(); /* draw_graphics_out_of_screen(0); */ draw_graphics_clear(); speed = draw_graphics_speed(0, 0, video_size_x(), video_size_y()); draw_graphics_calib(0, 0, video_size_x(), video_size_y()); snprintf(buffer, sizeof(buffer), " %.2f MB/s", speed / (double)(1024*1024)); draw_string(0, 0, buffer, DRAW_COLOR_WHITE); video_write_unlock(0, 0, 0, 0, 0); video_wait_vsync(); do { target_idle(); os_poll(); } while (inputb_get()==INPUTB_NONE); return 0; }
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; };
static void draw_text_help(void) { int x = 0; int y = 0; int dx = text_size_x(); int dy = text_size_y(); text_clear(); y = draw_text_para(x, y, dx, dy, " HELP" , COLOR_REVERSE); y = draw_text_para(x, y, dx, dy-y, "F2 Save the selected modes\n" "F5 Create a new modeline (favourite modes with the specified size)\n" "F6 Create a new modeline (favourite modes with the specified clock)\n" "F7 Duplicate the current mode\n" "F8 Set an arbitrary clock value\n" "F9 Show a static test screen for the current video mode\n" "F10 Show a dynamic test screen for the current video mode\n" "SPACE Select/Unselect the current video mode\n" "ENTER Test the current video mode\n" "TAB Rename the current video mode\n" "ESC Exit\n" "\n" "q/a Increase the x/y Display End register (SHIFT to decrease)\n" "w/s Increase the x/y Blank Start register (SHIFT to decrease)\n" "e/d Increase the x/y Retrace Start register (SHIFT to decrease)\n" "r/f Increase the x/y Retrace End register (SHIFT to decrease)\n" "t/g Increase the x/y Blank End register (SHIFT to decrease)\n" "y/h Increase the x/y Total End register (SHIFT to decrease)\n" "u/j Change the polarization\n" "i/k Expand the x/y size (SHIFT to shrink)\n" "v Increase the pixel clock (SHIFT to decrease)\n" "x/c Change the scan line mode\n" "n/m Change the tv mode\n" "\n" "Press ESC" , COLOR_NORMAL); video_wait_vsync(); do { target_idle(); os_poll(); } while (inputb_get()==INPUTB_NONE); }
// 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 button_pressed(void) { int i, j; os_poll(); joystickb_poll(); target_idle(); for (i = 0; i < joystickb_count_get(); ++i) { for (j = 0; j < joystickb_button_count_get(i); ++j) { if (joystickb_button_get(i, j)) return 1; } } return 0; }
static adv_error cmd_input_key(const char* tag, const char* keys) { draw_text_fill(0, text_size_y()-1, ' ', text_size_x(), COLOR_REVERSE); draw_text_string(2, text_size_y()-1, tag, COLOR_REVERSE); draw_text_string(2+strlen(tag), text_size_y()-1, keys, COLOR_INPUT); while (1) { int i; unsigned k; video_wait_vsync(); target_idle(); os_poll(); k = inputb_get(); if (k == INPUTB_ESC) return -1; for(i=0;keys[i];++i) if (toupper(k)==toupper(keys[i])) return i; } }
void run(void) { char msg[1024]; char new_msg[1024]; int i, j, k; target_clock_t last; printf("Press Break to exit\n"); signal(SIGINT, sigint); last = target_clock(); msg[0] = 0; while (!done) { new_msg[0] = 0; for (i = 0; i < joystickb_count_get(); ++i) { if (i != 0) sncat(new_msg, sizeof(new_msg), "\n"); snprintf(new_msg + strlen(new_msg), sizeof(new_msg) - strlen(new_msg), "joy %d, [", i); for (j = 0; j < joystickb_button_count_get(i); ++j) { if (joystickb_button_get(i, j)) sncat(new_msg, sizeof(new_msg), "_"); else sncat(new_msg, sizeof(new_msg), "-"); } sncat(new_msg, sizeof(new_msg), "], "); for (j = 0; j < joystickb_stick_count_get(i); ++j) { for (k = 0; k < joystickb_stick_axe_count_get(i, j); ++k) { char digital; if (joystickb_stick_axe_digital_get(i, j, k, 0)) digital = '\\'; else if (joystickb_stick_axe_digital_get(i, j, k, 1)) digital = '/'; else digital = '-'; sncatf(new_msg, sizeof(new_msg), " %d/%d [%6d %c]", j, k, joystickb_stick_axe_analog_get(i, j, k), digital); } } sncat(new_msg, sizeof(new_msg), " ["); for (j = 0; j < joystickb_rel_count_get(i); ++j) { if (j != 0) sncat(new_msg, sizeof(new_msg), "/"); sncatf(new_msg, sizeof(new_msg), "%d", joystickb_rel_get(i, j)); } sncat(new_msg, sizeof(new_msg), "]"); } if (strcmp(msg, new_msg) != 0) { target_clock_t current = target_clock(); double period = (current - last) * 1000.0 / TARGET_CLOCKS_PER_SEC; last = current; sncpy(msg, sizeof(msg), new_msg); printf("%s (%4.0f ms)\n", msg, period); } os_poll(); joystickb_poll(); target_yield(); } }
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(); } }
static adv_error cmd_onvideo_test(void) { adv_crtc* crtc; adv_mode mode; adv_bool done; adv_crtc crtc_save; adv_bool dirty = 1; adv_bool crtc_save_modified; mode_reset(&mode); crtc = menu_current(); if (!crtc) return -1; if (!crtc_is_fake(crtc) && !crtc_clock_check(&the_monitor, crtc)) return -1; if (video_mode_generate(&mode, crtc, the_mode_index)!=0) { return -1; } if (text_mode_set(&mode) != 0) { text_reset(); return -1; } crtc_save = *crtc; crtc_save_modified = the_modes_modified; done = 0; while (!done) { int userkey; adv_bool modify = 0; adv_crtc last_crtc = *crtc; adv_mode last_mode = mode; adv_bool vm_last_modified = the_modes_modified; if (dirty) { video_write_lock(); test_draw(1, 1, &mode); video_write_unlock(0, 0, 0, 0, 0); dirty = 0; } video_wait_vsync(); target_idle(); os_poll(); userkey = inputb_get(); switch (userkey) { case INPUTB_ESC : done = 1; /* restore */ *crtc = crtc_save; the_modes_modified = crtc_save_modified; break; case INPUTB_ENTER : done = 1; break; } if (!done) { modify = test_exe_crtc(userkey, crtc); if (modify) { the_modes_modified = 1; dirty = 1; if ((crtc_is_fake(crtc) || crtc_clock_check(&the_monitor, crtc)) && video_mode_generate(&mode, crtc, the_mode_index)==0) { if (text_mode_set(&mode) != 0) { text_reset(); /* abort */ *crtc = crtc_save; the_modes_modified = crtc_save_modified; return -1; } } else { /* restore */ mode = last_mode; *crtc = last_crtc; the_modes_modified = vm_last_modified; dirty = 1; sound_error(); } } else { sound_warn(); } } } return 0; }
static adv_error cmd_onvideo_animate(void) { adv_mode mode; adv_crtc* crtc; unsigned i; int counter; mode_reset(&mode); if (the_mode_index == MODE_FLAGS_INDEX_TEXT) { error_set("Command supported only in graphics mode"); return -1; } crtc = menu_current(); if (!crtc) return -1; if (!crtc_is_fake(crtc) && !crtc_clock_check(&the_monitor, crtc)) return -1; if (video_mode_generate(&mode, crtc, the_mode_index)!=0) { return -1; } if (text_mode_set(&mode) != 0) { text_reset(); return -1; } update_init(2); draw_graphics_palette(); for(i=0;i<3;++i) { update_start(); video_clear(update_x_get(), update_y_get(), video_size_x(), video_size_y(), 0); update_stop(update_x_get(), update_y_get(), video_size_x(), video_size_y(), 1); } counter = update_page_max_get(); while (!inputb_hit()) { os_poll(); update_start(); draw_graphics_animate(update_x_get(), update_y_get(), video_size_x(), video_size_y(), counter - update_page_max_get() + 1, 1); ++counter; draw_graphics_animate(update_x_get(), update_y_get(), video_size_x(), video_size_y(), counter, 0); update_stop(update_x_get(), update_y_get(), video_size_x(), video_size_y(), 1); } update_done(); do { target_idle(); os_poll(); } while (inputb_get()==INPUTB_NONE); return 0; }
// exit: -1 => error // 0..nchoices-1 => choice int popup_do(popup_info *pi, int flags) { int screen_id, choice = -1, done = 0; if ( popup_init(pi, flags) == -1 ){ return -1; } screen_id = gr_save_screen(); int old_max_w_unscaled = gr_screen.max_w_unscaled; int old_max_h_unscaled = gr_screen.max_h_unscaled; int old_max_w_unscaled_zoomed = gr_screen.max_w_unscaled_zoomed; int old_max_h_unscaled_zoomed = gr_screen.max_h_unscaled_zoomed; gr_reset_screen_scale(); while(!done) { int k; os_poll(); // if we were killed by a call to popup_kill_any_active(), kill the popup if(Popup_should_die){ choice = -1; break; } // if we're flagged as should be running the state underneath, then do so if(flags & PF_RUN_STATE){ game_do_state(gameseq_get_state()); } // otherwise just run the common functions (for networking,etc) else { game_set_frametime(-1); game_do_state_common(gameseq_get_state(),flags & PF_NO_NETWORKING); // do stuff common to all states } k = Popup_window.process(); // poll for input, handle mouse choice = popup_process_keys(pi, k, flags); if ( choice != POPUP_NOCHANGE ) { done=1; } if ( !done ) { choice = popup_check_buttons(pi); if ( choice != POPUP_NOCHANGE ) { done=1; } } // don't draw anything if(!(flags & PF_RUN_STATE)){ gr_restore_screen(screen_id); } // if this is an input popup, store the input text if(flags & PF_INPUT){ Popup_input.get_text(pi->input_text); } Popup_window.draw(); popup_force_draw_buttons(pi); popup_draw_msg_text(pi, flags); popup_draw_button_text(pi, flags); gr_flip(); } gr_set_screen_scale(old_max_w_unscaled, old_max_h_unscaled, old_max_w_unscaled_zoomed, old_max_h_unscaled_zoomed); popup_close(pi,screen_id); return choice; }
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(); } }
/* Menu */ static int menu_run(void) { adv_bool done; int userkey; menu_base = 0; menu_rel = 0; menu_rel_max = MENU_DY; menu_max = crtc_container_max(&the_modes); menu_base_max = menu_max - menu_rel_max; if (menu_base_max < 0) menu_base_max = 0; done = 0; while (!done) { draw_text_index(BAR_X, BAR_Y1+1, BAR_DX); draw_text_bar(BAR_X, BAR_Y1, BAR_Y2, BAR_DX); draw_text_info(INFO_X, INFO_Y, INFO_DX, INFO_DY, menu_base + menu_rel); menu_draw(MENU_X, MENU_Y, MENU_DX, MENU_DY); video_wait_vsync(); target_idle(); os_poll(); userkey = inputb_get(); switch (userkey) { case INPUTB_UP: cmd_gotopos(menu_base + menu_rel - 1); break; case INPUTB_DOWN: cmd_gotopos(menu_base + menu_rel + 1); break; case INPUTB_HOME: { int i = menu_base + menu_rel - 1; if (i<0) i = 0; while (i>0 && !(crtc_container_pos(&the_modes, i)->user_flags & MODE_FLAGS_USER_BIT0)) --i; cmd_gotopos(i); break; } case INPUTB_END: { int i = menu_base + menu_rel + 1; if (i >= menu_max) i = menu_max - 1; while (i < menu_max - 1 && !(crtc_container_pos(&the_modes, i)->user_flags & MODE_FLAGS_USER_BIT0)) ++i; cmd_gotopos(i); break; } case INPUTB_PGDN: cmd_gotopos(menu_base + menu_rel + menu_rel_max); break; case INPUTB_PGUP: cmd_gotopos(menu_base + menu_rel - menu_rel_max); break; case INPUTB_F2: cmd_save(); break; case INPUTB_LEFT : case INPUTB_RIGHT : cmd_type(userkey); break; case INPUTB_ESC: done = cmd_exit(); break; case INPUTB_SPACE: cmd_select(); cmd_gotopos(menu_base + menu_rel + 1); break; case INPUTB_ENTER: if (cmd_onvideo_test() != 0) { text_reset(); draw_text_error(); } else { text_reset(); } break; case INPUTB_F9: if (cmd_onvideo_calib() != 0) { text_reset(); draw_text_error(); } else { text_reset(); } break; case INPUTB_F10: if (cmd_onvideo_animate() != 0) { text_reset(); draw_text_error(); } else { text_reset(); } break; case INPUTB_TAB : cmd_rename(); break; case INPUTB_F5 : if (cmd_modeline_create(1) !=0) { text_reset(); draw_text_error(); } else { text_reset(); } break; case INPUTB_F6 : if (cmd_modeline_create(0) !=0) { text_reset(); draw_text_error(); } else { text_reset(); } break; case INPUTB_F7 : cmd_copy(); break; case INPUTB_F8 : if (cmd_mode_clock() !=0) { text_reset(); draw_text_error(); } else { text_reset(); } break; case INPUTB_DEL : cmd_del(); cmd_gotopos(menu_base + menu_rel); break; case INPUTB_F1: draw_text_help(); break; default: if (cmd_offvideo_test(userkey) != 0) { draw_text_error(); } break; } } return userkey; }