From e42186683d75a1a204dcd56ab8771198ea4e8f4a Mon Sep 17 00:00:00 2001 From: mtabachenko Date: Sat, 3 May 2008 05:32:52 +0000 Subject: [PATCH] - moved console source code to new files for only windows port; --- desmume/src/debug.c | 60 ------------------------- desmume/src/debug.h | 15 ------- desmume/src/windows/console.c | 83 +++++++++++++++++++++++++++++++++++ desmume/src/windows/console.h | 37 ++++++++++++++++ desmume/src/windows/main.c | 10 ++--- 5 files changed, 124 insertions(+), 81 deletions(-) create mode 100644 desmume/src/windows/console.c create mode 100644 desmume/src/windows/console.h diff --git a/desmume/src/debug.c b/desmume/src/debug.c index 0501f16bc..cecd0b4c5 100644 --- a/desmume/src/debug.c +++ b/desmume/src/debug.c @@ -23,13 +23,6 @@ #include #include -/////// Console vars -#define BUFFER_SIZE 100 -#ifdef WIN32 -HANDLE hConsole; -#endif -/////// - ////////////////////////////////////////////////////////////////////////////// Debug * DebugInit(const char * n, DebugOutType t, char * s) { @@ -164,56 +157,3 @@ void LogStop(void) { } ////////////////////////////////////////////////////////////////////////////// - -///////////////////////////////////////////////////////////////// Console -#ifdef WIN32 -#ifdef BETA_VERSION -void OpenConsole() -{ - COORD csize; - CONSOLE_SCREEN_BUFFER_INFO csbiInfo; - SMALL_RECT srect; - char buf[256]; - - if (hConsole) return; - AllocConsole(); - memset(buf,0,256); - sprintf(buf,"DeSmuME v%s OUTPUT", VERSION); - SetConsoleTitle(TEXT(buf)); - csize.X = 60; - csize.Y = 800; - SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), csize); - GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbiInfo); - srect = csbiInfo.srWindow; - srect.Right = srect.Left + 99; - srect.Bottom = srect.Top + 64; - SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), TRUE, &srect); - hConsole = GetStdHandle(STD_OUTPUT_HANDLE); -} - -void CloseConsole() { - if (hConsole == NULL) return; - FreeConsole(); - hConsole = NULL; -} - -void printlog(char *fmt, ...) { - va_list list; - char msg[512],msg2[522]; - wchar_t msg3[522]; - char *ptr; - DWORD tmp; - int len, s; - int i, j; - - LPWSTR ret; - - va_start(list,fmt); - _vsnprintf(msg,511,fmt,list); - msg[511] = '\0'; - va_end(list); - ptr=msg; len=strlen(msg); - WriteConsole(hConsole,ptr, (DWORD)len, &tmp, 0); -} -#endif -#endif diff --git a/desmume/src/debug.h b/desmume/src/debug.h index 70eb58c64..2508f0f0a 100644 --- a/desmume/src/debug.h +++ b/desmume/src/debug.h @@ -20,9 +20,6 @@ #ifndef DEBUG_H #define DEBUG_H -#ifdef WIN32 -#include -#endif #include "types.h" #include @@ -53,18 +50,6 @@ extern Debug * MainLog; void LogStart(void); void LogStop(void); -#ifdef WIN32 -#ifdef BETA_VERSION -void OpenConsole(); -void CloseConsole(); -void printlog(LPCTSTR *fmt, ...); -#else -#define OpenConsole() -#define CloseConsole() -#define printlog(...) -#endif -#endif - #ifdef DEBUG #define LOG(...) DebugPrintf(MainLog, __FILE__, __LINE__, __VA_ARGS__) #else diff --git a/desmume/src/windows/console.c b/desmume/src/windows/console.c new file mode 100644 index 000000000..6663b1744 --- /dev/null +++ b/desmume/src/windows/console.c @@ -0,0 +1,83 @@ +/* Copyright (C) 2006 yopyop + yopyop156@ifrance.com + yopyop156.ifrance.com + + Copyright 2008 CrazyMax (mtabachenko) + + This file is part of DeSmuME + + DeSmuME is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DeSmuME is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DeSmuME; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include +#include + +///////////////////////////////////////////////////////////////// Console +#ifdef BETA_VERSION +#define BUFFER_SIZE 100 +HANDLE hConsole; +void printlog(char *fmt, ...); + +void OpenConsole() +{ + COORD csize; + CONSOLE_SCREEN_BUFFER_INFO csbiInfo; + SMALL_RECT srect; + char buf[256]; + + if (hConsole) return; + AllocConsole(); + memset(buf,0,256); + sprintf(buf,"DeSmuME v%s OUTPUT", VERSION); + SetConsoleTitle(TEXT(buf)); + csize.X = 60; + csize.Y = 800; + SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), csize); + GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbiInfo); + srect = csbiInfo.srWindow; + srect.Right = srect.Left + 99; + srect.Bottom = srect.Top + 64; + SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), TRUE, &srect); + hConsole = GetStdHandle(STD_OUTPUT_HANDLE); + printlog("DeSmuME v%s BETA\n",VERSION); + printlog("- compiled: %s %s\n\n",__DATE__,__TIME__); +} + +void CloseConsole() { + if (hConsole == NULL) return; + printlog("Closing..."); + FreeConsole(); + hConsole = NULL; +} + +void printlog(char *fmt, ...) { + va_list list; + char msg[512],msg2[522]; + wchar_t msg3[522]; + char *ptr; + DWORD tmp; + int len, s; + int i, j; + + LPWSTR ret; + + va_start(list,fmt); + _vsnprintf(msg,511,fmt,list); + msg[511] = '\0'; + va_end(list); + ptr=msg; len=strlen(msg); + WriteConsole(hConsole,ptr, (DWORD)len, &tmp, 0); +} +#endif diff --git a/desmume/src/windows/console.h b/desmume/src/windows/console.h new file mode 100644 index 000000000..c69da720b --- /dev/null +++ b/desmume/src/windows/console.h @@ -0,0 +1,37 @@ +/* Copyright (C) 2006 yopyop + yopyop156@ifrance.com + yopyop156.ifrance.com + + Copyright 2008 CrazyMax (mtabachenko) + + This file is part of DeSmuME + + DeSmuME is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DeSmuME is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DeSmuME; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +#ifndef _CONSOLE_H_ +#define _CONSOLE_H_ +#include +#include + +#ifdef BETA_VERSION +void OpenConsole(); +void CloseConsole(); +void printlog(LPCTSTR *fmt, ...); +#else +#define OpenConsole() +#define CloseConsole() +#define printlog(...) +#endif +#endif \ No newline at end of file diff --git a/desmume/src/windows/main.c b/desmume/src/windows/main.c index 45c8a34ad..80bfa7cb0 100644 --- a/desmume/src/windows/main.c +++ b/desmume/src/windows/main.c @@ -53,6 +53,7 @@ #include "../render3D.h" #include "../gdbstub.h" #include "colorctrl.h" +#include "console.h" #include "snddx.h" @@ -671,7 +672,6 @@ int WINAPI WinMain (HINSTANCE hThisInstance, InitCustomControls(); OpenConsole(); // Init debug console - printlog("DeSmuME v%s starting...\n\n",VERSION); /* default the firmware settings, they may get changed later */ NDS_FillDefaultFirmwareConfigData( &win_fw_config); @@ -1693,20 +1693,18 @@ LRESULT CALLBACK SoundSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { static timerid=0; - switch (uMsg) { case WM_INITDIALOG: { int i; char tempstr[MAX_PATH]; - // Setup Sound Core Combo box SendDlgItemMessage(hDlg, IDC_SOUNDCORECB, CB_RESETCONTENT, 0, 0); - SendDlgItemMessage(hDlg, IDC_SOUNDCORECB, CB_ADDSTRING, 0, (long)"None"); + SendDlgItemMessage(hDlg, IDC_SOUNDCORECB, CB_ADDSTRING, 0, (LPARAM)"None"); - for (i = 1; SNDCoreList[i] != NULL; i++) - SendDlgItemMessage(hDlg, IDC_SOUNDCORECB, CB_ADDSTRING, 0, (long)SNDCoreList[i]->Name); + for (i = 1; SNDCoreList[i] != NULL; i++) + SendDlgItemMessage(hDlg, IDC_SOUNDCORECB, CB_ADDSTRING, 0, (LPARAM)SNDCoreList[i]->Name); // Set Selected Sound Core for (i = 0; SNDCoreList[i] != NULL; i++)