void dc_init(void) { if (debug_inited) { return; } debug_inited = TRUE; // Init window settings dc_font = FONT1; row_height = ((Current_font->h) * 3) / 2; // Row/Line height, in pixels col_width = Current_font->w; // Col/Character width, in pixels dc_scroll_x = 0; dc_scroll_y = 0; DCOLS = (gr_screen.max_w / col_width) - 1; // Subtract as needed. Windowed mode has some quirks with the resolution DROWS = (gr_screen.max_h / row_height) - 2; DBCOLS = DCOLS; DBROWS = 2 * DROWS; // Init History dc_history.clear(); dc_history.push_back(""); last_oldcommand = dc_history.begin(); // Init buffers dc_buffer.clear(); dc_buffer.push_back(""); dc_command_buf.reserve(MAX_CLI_LEN); dc_command_buf.clear(); sprintf(dc_title, "FreeSpace Open v%i.%i.%i", FS_VERSION_MAJOR, FS_VERSION_MINOR, FS_VERSION_BUILD); dc_printf("Debug console started.\n" ); }
void dc_init(void) { if (debug_inited) { return; } debug_inited = TRUE; // Init window settings dc_font = font::FONT1; row_height = ((fl2i(font::get_current_font()->getHeight())) * 3) / 2; // Row/Line height, in pixels // This assumes that FONT1 is monospaced! gr_get_string_size(&col_width, nullptr, " "); // Col/Character width, in pixels dc_scroll_x = 0; dc_scroll_y = 0; DCOLS = (gr_screen.center_w / col_width) - 1; // Subtract as needed. Windowed mode has some quirks with the resolution DROWS = (gr_screen.center_h / row_height) - 2; DBCOLS = DCOLS; DBROWS = 2 * DROWS; // Init History dc_history.clear(); dc_history.push_back(""); last_oldcommand = dc_history.begin(); // Init buffers dc_buffer.clear(); dc_buffer.push_back(""); dc_command_buf.reserve(MAX_CLI_LEN); dc_command_buf.clear(); sprintf(dc_title, "FreeSpace Open v%i.%i.%i", FS_VERSION_MAJOR, FS_VERSION_MINOR, FS_VERSION_BUILD); dc_printf("Debug console started.\n" ); }
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(); } }