20 #pragma warning(disable: 4201) // nameless struct/union
39 #define SCROLL_BUFFER_SIZE 512
40 #define MAX_LINE_WIDTH 128
41 #define TASKBAR_HEIGHT 30
45 #define ID_FILTER 32100
48 #define DOWN_FAST 65538
73 static int marked = 0;
112 : :
"g" (
value),
"g" (port) :
"al",
"dx");
115 inline unsigned char _inp(
unsigned short port)
122 :
"=g"(
value) :
"g" (port) :
"al",
"dx");
130 SetBkColor(hdc, RGB(0, 0, 0));
131 SetTextColor(hdc, RGB(255, 255, 255));
136 SetBkColor(hdc, RGB(255, 255, 255));
137 SetTextColor(hdc, RGB(0, 0, 0));
142 x = (
signed short) LOWORD(l_parm) /
nTextWidth;
177 memset( pathname, 0,
sizeof(pathname) );
180 fp = fopen(pathname,
"rt");
187 OutwndFilter.push_back( new_filter );
191 OutwndFilter.push_back( new_filter );
195 OutwndFilter.push_back( new_filter );
206 else if (*inbuf ==
'-')
211 z = strlen(inbuf) - 1;
212 if (inbuf[z] ==
'\n')
220 }
else if ( !
stricmp(new_filter.
name,
"general") ) {
222 }
else if ( !
stricmp(new_filter.
name,
"warning") ) {
226 OutwndFilter.push_back( new_filter );
229 if ( ferror(fp) && !feof(fp) )
230 nprintf((
"Error",
"Error reading \"%s\"\n", pathname));
247 memset( pathname, 0,
sizeof(pathname) );
250 fp = fopen(pathname,
"wt");
253 for (
uint i = 0;
i < OutwndFilter.size();
i++)
254 fprintf(fp,
"%c%s\n", OutwndFilter[
i].
enabled ?
'+' :
'-', OutwndFilter[
i].
name);
268 va_start(args, format);
276 char mono_ram[80*25*2];
282 if ( !mono_found )
return;
283 memcpy( (
void *)0xb0000, mono_ram, 80*25*2 );
292 ver.dwOSVersionInfoSize =
sizeof(OSVERSIONINFO);
294 if ( ver.dwPlatformId == VER_PLATFORM_WIN32_NT ) {
299 _outp( 0x3b4, 0x0f );
300 _outp( 0x3b4+1, 0x55 );
302 if (
_inp( 0x3b4+1 ) == 0x55 ) {
311 for (i=0; i<80*25; i++ ) {
312 mono_ram[i*2+0] =
' ';
313 mono_ram[i*2+1] = 0x07;
320 void mono_print(
char * text,
int len )
328 for (i=0; i<
len; i++ ) {
336 mono_ram[mono_y*160+mono_x*2] = text[
i];
350 memmove( mono_ram, mono_ram+160, 80*24*2 );
351 for (j=0; j<80; j++ ) {
352 mono_ram[24*160+j*2] =
' ';
369 if ( (
id == NULL) || (format == NULL) )
372 va_start(args, format);
386 if ( (
id == NULL) || (tmp == NULL) )
395 outwnd_print(
"general",
"==========================================================================\n" );
396 outwnd_print(
"general",
"DEBUG SPEW: No debug_filter.cfg found, so only general, error, and warning\n" );
397 outwnd_print(
"general",
"categories can be shown and no debug_filter.cfg info will be saved.\n" );
398 outwnd_print(
"general",
"==========================================================================\n" );
401 uint outwnd_size = OutwndFilter.size();
403 for (i = 0; i < OutwndFilter.size(); i++) {
409 if ( i == outwnd_size ) {
420 OutwndFilter.push_back( new_filter );
424 if ( !OutwndFilter[i].
enabled )
454 mono_print(tmp, strlen(tmp) );
468 mprintf_last_line = 0;
470 if ( *sptr !=
'\n' ) {
488 int oldpos = GetScrollPos(
hOutputWnd, SB_VERT );
491 si.cbSize =
sizeof(SCROLLINFO);
502 client.top = client.bottom -
nTextHeight*(nrows+1);
524 si.cbSize =
sizeof(SCROLLINFO);
525 si.fMask = SIF_RANGE | SIF_POS;
529 SetScrollInfo(hwnd, SB_VERT, &si, 1 );
554 OutwndFilter[
z].enabled = !OutwndFilter[
z].enabled;
557 OutwndFilter[
z].enabled = 1;
558 }
else if ( !
stricmp( OutwndFilter[z].name,
"general" ) ) {
559 OutwndFilter[
z].enabled = 1;
560 }
else if ( !
stricmp( OutwndFilter[z].name,
"warning" ) ) {
561 OutwndFilter[
z].enabled = 1;
587 case WM_RBUTTONDOWN: {
588 HMENU h_menu = CreatePopupMenu();
589 HMENU h_sub_menu = CreatePopupMenu();
592 for (
uint i = 0; i < OutwndFilter.size(); i++) {
597 }
else if ( !
stricmp( OutwndFilter[i].name,
"general" ) ) {
599 }
else if ( !
stricmp( OutwndFilter[i].name,
"warning" ) ) {
604 AppendMenu(h_sub_menu, flags | MF_CHECKED,
ID_FILTER + i, OutwndFilter[i].name);
606 AppendMenu(h_sub_menu, flags,
ID_FILTER + i, OutwndFilter[i].name);
609 AppendMenu(h_menu, MFT_STRING,
ID_COPY,
"&Copy\tEnter");
610 AppendMenu(h_menu, MFT_STRING,
ID_FIND,
"&Find Text");
611 AppendMenu(h_menu, MF_POPUP, (
unsigned int) h_sub_menu,
"Filter &Messages");
612 pt.
x = LOWORD(lParam);
613 pt.
y = HIWORD(lParam);
614 ClientToScreen(hwnd, &pt);
616 TrackPopupMenu(h_menu, 0, pt.
x, pt.
y, 0, hwnd, NULL);
646 int vpos = GetScrollPos( hwnd, SB_VERT );
648 switch (LOWORD(wParam)) {
655 case SB_THUMBPOSITION:
656 vpos = HIWORD(wParam);
659 vpos = HIWORD(wParam);
668 if ( vpos < 0 ) vpos = 0;
670 si.cbSize =
sizeof(SCROLLINFO);
673 SetScrollInfo(hwnd, SB_VERT, &si, 1 );
674 ScrollWindow(hwnd,0,(old_vpos-vpos)*
nTextHeight,NULL,NULL);
682 int vpos = GetScrollPos( hwnd, SB_VERT );
684 int nVirtKey = (
int) wParam;
717 if ( vpos < 0 ) vpos = 0;
719 si.cbSize =
sizeof(SCROLLINFO);
722 SetScrollInfo(hwnd, SB_VERT, &si, 1 );
723 ScrollWindow(hwnd, 0, (old_vpos-vpos)*
nTextHeight, NULL, NULL);
743 return DefWindowProc(hwnd, msg, wParam, lParam);
765 size += strlen(
outtext[i++]) + 2;
770 h_text = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, size);
771 ptr = (
char *) GlobalLock(h_text);
795 GlobalUnlock(h_text);
798 SetClipboardData(CF_TEXT, h_text);
802 InvalidateRect(hwnd, NULL, 0);
808 int old_nrows, scroll_pos;
813 HFONT newfont, oldfont;
814 HBRUSH newbrush, oldbrush;
818 hdc = BeginPaint(hwnd, &ps);
820 newfont = (HFONT)GetStockObject(ANSI_FIXED_FONT);
821 oldfont = (HFONT)SelectObject(hdc,newfont);
823 GetTextMetrics(hdc, &tm);
829 newbrush = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
830 oldbrush = (HBRUSH)SelectObject(hdc,newbrush);
848 sprintf( tmp,
"Debug Spew [Scrolled back %d lines]", scroll_pos );
911 TextOut(hdc, 0, y,
outtext[n], len);
917 TextOut(hdc, 0, y,
outtext[n], len);
928 SelectObject(hdc, oldfont);
929 SelectObject(hdc, oldbrush);
930 DeleteObject(newbrush);
932 if ( old_nrows != nCharRows ) {
935 si.cbSize =
sizeof(SCROLLINFO);
936 si.fMask = SIF_RANGE;
939 SetScrollInfo(hwnd, SB_VERT, &si, 1 );
952 y = (
signed short) HIWORD(l_parm);
953 GetClientRect(hwnd, &rect);
956 SendMessage(hwnd, WM_KEYDOWN,
UP_FAST, 0);
960 SendMessage(hwnd, WM_KEYDOWN, VK_UP, 0);
964 if (y >= rect.bottom + 150) {
965 SendMessage(hwnd, WM_KEYDOWN,
DOWN_FAST, 0);
968 }
else if (y >= rect.bottom) {
969 SendMessage(hwnd, WM_KEYDOWN, VK_DOWN, 0);
1011 if (marked && (marked_top > marked_bottom || (marked_top == marked_bottom &&
1016 sprintf(msg,
"Marking limits invalid!\n"
1032 InvalidateRect(hwnd, NULL, 0);
1039 HINSTANCE hInst = GetModuleHandle(NULL);
1043 wclass.hInstance = hInst;
1046 wclass.style = CS_BYTEALIGNCLIENT | CS_OWNDC;
1047 wclass.cbSize =
sizeof(WNDCLASSEX);
1048 wclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
1049 wclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
1050 wclass.hCursor = LoadCursor(NULL, IDC_ARROW);
1051 wclass.lpszMenuName = NULL;
1052 wclass.cbClsExtra = 0;
1053 wclass.cbWndExtra = 0;
1054 wclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
1056 if (!RegisterClassEx(&wclass))
1059 if (display_under_freespace_window) {
1060 style = WS_OVERLAPPEDWINDOW;
1063 client_rect.left = client_rect.top = 0;
1064 client_rect.right = 640;
1065 client_rect.bottom = 480;
1066 AdjustWindowRect(&client_rect,WS_CAPTION | WS_SYSMENU,
FALSE);
1068 int _x = (GetSystemMetrics( SM_CXSCREEN )-(client_rect.right - client_rect.left))/2;
1070 if ( _x < 0 ) _x = 0;
1074 rect.right = _x + client_rect.right - client_rect.left - 1;
1075 rect.bottom = _y + client_rect.bottom - client_rect.top - 1;
1078 rect.top = rect.bottom;
1079 rect.bottom = GetSystemMetrics(SM_CYSCREEN) -
TASKBAR_HEIGHT - rect.top;
1080 rect.right -= rect.left;
1087 style = WS_OVERLAPPEDWINDOW | WS_MINIMIZE;
1088 rect.top = rect.bottom = rect.left = rect.right = CW_USEDEFAULT;
1093 rect.top, rect.right, rect.bottom, NULL, NULL, hInst, NULL);
1097 SetWindowPos(
hOutputWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW );
1116 if (WaitMessage()) {
1117 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
1118 TranslateMessage(&msg);
1119 DispatchMessage(&msg);
1144 static bool debug_window_inited =
false;
1154 if ( (
mono_driver = CreateFile(
"\\\\.\\MONO", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == ((
HANDLE)-1)) {
1162 debug_window_inited =
true;
1197 memset( pathname, 0,
sizeof(pathname) );
1200 Log_fp = fopen(pathname,
"wb");
1205 time_t timedate = time(NULL);
1208 memset( datestr, 0,
sizeof(datestr) );
1209 strftime( datestr,
sizeof(datestr)-1,
"%a %b %d %H:%M:%S %Y", localtime(&timedate) );
1211 outwnd_printf(
"General",
"Opened log '%s', %s ...\n", pathname, datestr);
1223 switch (LOWORD(wParam)) {
1226 EndDialog(hwnd, IDOK);
1236 SendDlgItemMessage(hwnd,
IDC_TEXT, EM_LIMITTEXT, 80, 0);
1238 SetFocus(GetDlgItem(hwnd,
IDC_TEXT));
1258 int scroll_pos,
pos;
1289 si.cbSize =
sizeof(SCROLLINFO);
1319 time_t timedate = time(NULL);
1322 memset( datestr, 0,
sizeof(datestr) );
1323 strftime( datestr,
sizeof(datestr)-1,
"%a %b %d %H:%M:%S %Y", localtime(&timedate) );
1339 va_start(args, format);
GLenum GLsizei GLenum format
char * FreeSpace_logfilename
void outwnd_copy_marked_selection(HWND hwnd)
ubyte outwnd_filter_loaded
int Log_debug_output_to_file
void outwnd_init(int display_under_freespace_window)
GLsizei const GLfloat * value
void find_text_in_outwindow(int n, int p)
void safe_point(const char *file, int line, const char *format,...)
DWORD outwnd_thread(int display_under_freespace_window)
void outwnd_printf2(const char *format,...)
UINT WPARAM LPARAM lParam
std::basic_string< char, std::char_traits< char >, std::allocator< char > > SCP_string
const char * detect_home(void)
BOOL CALLBACK find_dlg_handler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
void text_hilight(HDC &hdc)
void _outp(unsigned short port, unsigned char value)
#define SCROLL_BUFFER_SIZE
void save_filter_info(void)
typedef int(SCP_EXT_CALLCONV *SCPDLL_PFVERSION)(SCPDLL_Version *)
void outwnd_update_marking(LPARAM l_parm, HWND hwnd)
void outwnd_print(const char *id=NULL, const char *temp=NULL)
void vsprintf(SCP_string &dest, const char *format, va_list ap)
GLenum GLenum GLsizei const GLuint GLboolean enabled
cf_pathtype Pathtypes[CF_MAX_PATH_TYPES]
sprintf(buf,"(%f,%f,%f)", v3->xyz.x, v3->xyz.y, v3->xyz.z)
void outwnd_paint(HWND hwnd)
unsigned char _inp(unsigned short port)
SCP_vector< outwnd_filter_struct > OutwndFilter
GLint GLint GLint GLint GLint x
typedef HDC(WINAPI *PFNWGLGETCURRENTREADDCARBPROC)(void)
void fix_marking_coords(int &x, int &y, LPARAM l_parm)
GLuint const GLchar * name
char outtext[SCROLL_BUFFER_SIZE][MAX_LINE_WIDTH]
ubyte Outwnd_no_filter_file
void outwnd_init_debug_window(int display_under_freespace_window)
GLsizei const GLchar ** path
void text_normal(HDC &hdc)
int MessageBox(HWND h, const char *s1, const char *s2, int i)
void outwnd_printf(const char *id, const char *format,...)
LRESULT CALLBACK outwnd_handler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
void safe_point_print(const char *format,...)
char spaces[MAX_LINE_WIDTH+1]
void load_filter_info(void)
BOOL outwnd_create(int display_under_freespace_window)