mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
Common: Moved Windows console functions to common
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1887 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@ -1,197 +0,0 @@
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// This program 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, version 2.0.
|
||||
|
||||
// This program 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
|
||||
|
||||
// =======================================================================================
|
||||
// Includes
|
||||
// --------------
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------------------
|
||||
// Defines and settings
|
||||
// --------------
|
||||
bool g_consoleEnable = true;
|
||||
#define DEBUGG
|
||||
//#define DEBUGG_FILEONLY
|
||||
//#define DEBUGG_NOFILE
|
||||
// ---------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------------------
|
||||
// Handles
|
||||
// --------------
|
||||
#ifdef DEBUGG
|
||||
FILE* __fStdOut = NULL;
|
||||
#endif
|
||||
#ifndef DEBUGG_FILEONLY
|
||||
HANDLE __hStdOut = NULL;
|
||||
#endif
|
||||
// ==============
|
||||
|
||||
|
||||
// =======================================================================================
|
||||
// Width and height is the size of console window, if you specify fname,
|
||||
// the output will also be writton to this file. The file pointer is automatically closed
|
||||
// when you close the app
|
||||
// --------------
|
||||
void startConsoleWin(int width, int height, char* fname)
|
||||
{
|
||||
#ifdef DEBUGG
|
||||
|
||||
#ifndef DEBUGG_FILEONLY
|
||||
AllocConsole();
|
||||
|
||||
SetConsoleTitle(fname);
|
||||
__hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
COORD co = {width,height};
|
||||
SetConsoleScreenBufferSize(__hStdOut, co);
|
||||
|
||||
SMALL_RECT coo = {0,0,(width - 1),70}; // top, left, right, bottom
|
||||
SetConsoleWindowInfo(__hStdOut, TRUE, &coo);
|
||||
|
||||
#endif
|
||||
#ifndef DEBUGG_NOFILE
|
||||
// ---------------------------------------------------------------------------------------
|
||||
// Write to a file
|
||||
if(fname)
|
||||
{
|
||||
// Edit the log file name
|
||||
std::string FileEnding = ".log";
|
||||
std::string FileName = fname;
|
||||
std::string FullFilename = (FileName + FileEnding);
|
||||
__fStdOut = fopen(FullFilename.c_str(), "w");
|
||||
}
|
||||
// -----------------
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void ClearScreen();
|
||||
int wprintf(char *fmt, ...)
|
||||
{
|
||||
#ifdef DEBUGG
|
||||
char s[6000]; // WARNING: mind this value
|
||||
va_list argptr;
|
||||
int cnt;
|
||||
|
||||
va_start(argptr, fmt);
|
||||
cnt = vsnprintf(s, 3000, fmt, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
DWORD cCharsWritten;
|
||||
|
||||
// ---------------------------------------------------------------------------------------
|
||||
#ifndef DEBUGG_FILEONLY
|
||||
if(__hStdOut)
|
||||
{
|
||||
WriteConsole(__hStdOut, s, strlen(s), &cCharsWritten, NULL);
|
||||
}
|
||||
#endif
|
||||
#ifndef DEBUGG_NOFILE
|
||||
// ---------------------------------------------------------------------------------------
|
||||
|
||||
if(__fStdOut)
|
||||
fprintf(__fStdOut, s);
|
||||
// ---------------------------------------------------------------------------------------
|
||||
#endif
|
||||
|
||||
return(cnt);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// =======================================================================================
|
||||
// Clear screen
|
||||
// --------------
|
||||
void ClearScreen()
|
||||
{
|
||||
if(g_consoleEnable)
|
||||
{
|
||||
COORD coordScreen = { 0, 0 };
|
||||
DWORD cCharsWritten;
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
DWORD dwConSize;
|
||||
|
||||
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
//HANDLE hConsole = __hStdOut;
|
||||
|
||||
GetConsoleScreenBufferInfo(hConsole, &csbi);
|
||||
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
|
||||
FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize,
|
||||
coordScreen, &cCharsWritten);
|
||||
GetConsoleScreenBufferInfo(hConsole, &csbi);
|
||||
FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize,
|
||||
coordScreen, &cCharsWritten);
|
||||
SetConsoleCursorPosition(hConsole, coordScreen);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// =======================================================================================
|
||||
// Get console HWND to be able to use MoveWindow()
|
||||
// --------------
|
||||
HWND GetConsoleHwnd(void)
|
||||
{
|
||||
#define MY_BUFSIZE 1024 // Buffer size for console window titles.
|
||||
HWND hwndFound; // This is what is returned to the caller.
|
||||
char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated
|
||||
// WindowTitle.
|
||||
char pszOldWindowTitle[MY_BUFSIZE]; // Contains original
|
||||
// WindowTitle.
|
||||
|
||||
// Fetch current window title.
|
||||
|
||||
GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
|
||||
|
||||
// Format a "unique" NewWindowTitle.
|
||||
|
||||
wsprintf(pszNewWindowTitle,"%d/%d",
|
||||
GetTickCount(),
|
||||
GetCurrentProcessId());
|
||||
|
||||
// Change current window title.
|
||||
|
||||
SetConsoleTitle(pszNewWindowTitle);
|
||||
|
||||
// Ensure window title has been updated.
|
||||
|
||||
Sleep(40);
|
||||
|
||||
// Look for NewWindowTitle.
|
||||
|
||||
hwndFound = FindWindow(NULL, pszNewWindowTitle);
|
||||
|
||||
// Restore original window title.
|
||||
|
||||
SetConsoleTitle(pszOldWindowTitle);
|
||||
|
||||
return(hwndFound);
|
||||
}
|
||||
|
||||
#endif
|
@ -1,26 +0,0 @@
|
||||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// This program 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, version 2.0.
|
||||
|
||||
// This program 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
void startConsoleWin(int width, int height, char* fname);
|
||||
int wprintf(char *fmt, ...);
|
||||
void ClearScreen();
|
||||
HWND GetConsoleHwnd(void);
|
||||
|
||||
#endif
|
@ -30,16 +30,20 @@
|
||||
#include "Common.h"
|
||||
|
||||
#include "UCode_AXStructs.h" // they are only in a virtual dir called UCodes AX
|
||||
#include "Console.h" // For wprintf, ClearScreen
|
||||
#include "ConsoleWindow.h" // For Console::Print, Console::ClearScreen
|
||||
// =====================
|
||||
|
||||
// ---------------------------------------------------------------------------------------
|
||||
// Declarations
|
||||
|
||||
// =======================================================================================
|
||||
// Declarations and definitions
|
||||
// --------------
|
||||
|
||||
// ----------------------------------
|
||||
// Settings
|
||||
// --------------
|
||||
#define NUMBER_OF_PBS 64 // Todo: move this to a logging class
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------------------
|
||||
// -----------------------------------
|
||||
// Externals
|
||||
// --------------
|
||||
extern u32 m_addressPBs;
|
||||
@ -49,9 +53,8 @@ short globalpBuffer;
|
||||
u32 gLastBlock;
|
||||
// --------------
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------------------
|
||||
// Vectors and other stuff
|
||||
// -----------------------------------
|
||||
// Vectors and other things
|
||||
// --------------
|
||||
std::vector<u32> gloopPos(64);
|
||||
std::vector<u32> gsampleEnd(64);
|
||||
@ -91,7 +94,7 @@ std::vector<u32> gsamplePos(64);
|
||||
std::vector<u16> gupdates5(64);
|
||||
std::vector<u32> gupdates_addr(64);
|
||||
|
||||
// other stuff
|
||||
// Other things
|
||||
std::vector<u16> Jump(64); // this is 1 or 0
|
||||
std::vector<int> musicLength(64);
|
||||
std::vector< std::vector<int> > vector1(64, std::vector<int>(100,0));
|
||||
@ -110,7 +113,7 @@ std::vector<u16> vector62(vectorLength);
|
||||
std::vector<u16> vector63(vectorLength);
|
||||
|
||||
int ReadOutPBs(AXParamBlock * _pPBs, int _num);
|
||||
// ===========
|
||||
// =====================
|
||||
|
||||
|
||||
// =======================================================================================
|
||||
@ -359,8 +362,8 @@ void Logging()
|
||||
// =======================================================================================
|
||||
// Print
|
||||
// ---------------
|
||||
ClearScreen();
|
||||
wprintf("%s", sbuff.c_str());
|
||||
Console::ClearScreen();
|
||||
Console::Print("%s", sbuff.c_str());
|
||||
sbuff.clear(); strcpy(buffer, "");
|
||||
// ---------------
|
||||
k=0;
|
||||
@ -377,4 +380,4 @@ void Logging()
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "CommonTypes.h" // Pluginspecs
|
||||
|
||||
#include "UCode_AXStructs.h" // For the AXParamBlock structure
|
||||
#include "Console.h" // For wprintf, ClearScreen
|
||||
#include "ConsoleWindow.h" // For Console::Print, Console::ClearScreen
|
||||
|
||||
|
||||
u32 m_addressPBs = 0;
|
||||
@ -54,7 +54,7 @@ int ReadOutPBs(AXParamBlock * _pPBs, int _num)
|
||||
|
||||
// reading and 'halfword' swap
|
||||
n++;
|
||||
if (n > 20 && logall) {ClearScreen();}
|
||||
if (n > 20 && logall) {Console::ClearScreen();}
|
||||
for (int i = 0; i < _num; i++)
|
||||
{
|
||||
// ---------------------------------------------------------------------------------------
|
||||
@ -68,7 +68,7 @@ int ReadOutPBs(AXParamBlock * _pPBs, int _num)
|
||||
// Create a shortcut that let us update struct members
|
||||
short * pDest = (short *) & _pPBs[i];
|
||||
|
||||
if (n > 20 && logall) {wprintf("%c%i:", 223, i);} // logging
|
||||
if (n > 20 && logall) {Console::Print("%c%i:", 223, i);} // logging
|
||||
|
||||
// --------------
|
||||
// Here we update the PB. We do it by going through all 192 / 2 = 96 u16 values
|
||||
@ -80,7 +80,7 @@ int ReadOutPBs(AXParamBlock * _pPBs, int _num)
|
||||
{
|
||||
if (pSrc[p] != 0 && n > 20 && logall)
|
||||
{
|
||||
wprintf("%i %04x | ", p, Common::swap16(pSrc[p]));
|
||||
Console::Print("%i %04x | ", p, Common::swap16(pSrc[p]));
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ int ReadOutPBs(AXParamBlock * _pPBs, int _num)
|
||||
|
||||
}
|
||||
|
||||
if(n > 20 && logall) {wprintf("\n");} // logging
|
||||
if(n > 20 && logall) {Console::Print("\n");} // logging
|
||||
// --------------
|
||||
// Here we update the block address to the starting point of the next PB
|
||||
blockAddr = (_pPBs[i].next_pb_hi << 16) | _pPBs[i].next_pb_lo;
|
||||
|
Reference in New Issue
Block a user