Files
itgmania212121/stepmania/src/arch/ArchHooks/ArchHooks_Xbox.cpp
T

160 lines
4.4 KiB
C++
Raw Normal View History

2004-06-20 01:35:25 +00:00
#include "global.h"
#include "ArchHooks_Xbox.h"
#include "dsound.h" // for timeGetTime
2004-08-31 08:19:49 +00:00
#include "archutils/Xbox/custom_launch_params.h" // for XGetCustomLaunchData
2004-12-01 02:48:50 +00:00
#include "archutils/Xbox/VirtualMemory.h"
2004-06-20 01:35:25 +00:00
2004-10-26 11:56:08 +00:00
#include <xtl.h> // for XNetStartup
2004-12-12 00:23:32 +00:00
#include <new.h> // for _set_new_handler and _set_new_mode
2004-10-26 11:56:08 +00:00
2004-10-21 05:43:00 +00:00
typedef struct _UNICODE_STRING {unsigned short Length; unsigned short MaximumLength; PSTR Buffer;} UNICODE_STRING,*PUNICODE_STRING;
extern "C" XBOXAPI DWORD WINAPI IoCreateSymbolicLink(IN PUNICODE_STRING SymbolicLinkName,IN PUNICODE_STRING DeviceName);
2004-06-20 01:35:25 +00:00
static bool g_bTimerInitialized;
static DWORD g_iStartTime;
static void InitTimer()
{
if( g_bTimerInitialized )
return;
g_bTimerInitialized = true;
g_iStartTime = timeGetTime();
}
int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate )
{
if( !g_bTimerInitialized )
InitTimer();
int64_t ret = (timeGetTime() - g_iStartTime) * int64_t(1000);
if( bAccurate )
{
ret = FixupTimeIfLooped( ret );
ret = FixupTimeIfBackwards( ret );
}
return ret;
2004-06-20 01:35:25 +00:00
}
2004-10-21 05:43:00 +00:00
void MountDriveLetter(char drive, char* szDevice, char* szDir)
{
char szSourceDevice[256];
char szDestinationDrive[16];
sprintf(szDestinationDrive, "\\??\\%c:", drive);
sprintf(szSourceDevice,"\\Device\\%s",szDevice);
if (*szDir != 0x00 && *szDir != '\\')
{
strcat(szSourceDevice, "\\");
strcat(szSourceDevice, szDir);
}
UNICODE_STRING LinkName =
{
strlen(szDestinationDrive),
strlen(szDestinationDrive) + 1,
szDestinationDrive
};
UNICODE_STRING DeviceName =
{
strlen(szSourceDevice),
strlen(szSourceDevice) + 1,
szSourceDevice
};
IoCreateSymbolicLink(&LinkName, &DeviceName);
}
void MountDrives()
{
MountDriveLetter('A', "Cdrom0", "\\");
MountDriveLetter('E', "Harddisk0\\Partition1", "\\");
MountDriveLetter('C', "Harddisk0\\Partition2", "\\");
MountDriveLetter('X', "Harddisk0\\Partition3", "\\");
MountDriveLetter('Y', "Harddisk0\\Partition4", "\\");
MountDriveLetter('F', "Harddisk0\\Partition6", "\\");
MountDriveLetter('G', "Harddisk0\\Partition7", "\\");
}
2004-10-26 11:56:08 +00:00
bool SetupNetwork()
{
#if !defined(WITHOUT_NETWORKING)
XNetStartupParams xnsp;
memset(&xnsp, 0, sizeof(xnsp));
xnsp.cfgSizeOfStruct = sizeof(XNetStartupParams);
xnsp.cfgFlags = XNET_STARTUP_BYPASS_SECURITY;
INT err = XNetStartup(&xnsp);
return err == 0;
#else
return true;
#endif
}
2004-10-28 07:58:13 +00:00
// if Xbox has 128 meg RAM make sure its used
void EnableExtraRAM()
{
LARGE_INTEGER regVal;
// Verify that we have 128 megs available
MEMORYSTATUS memStatus;
GlobalMemoryStatus( &memStatus );
if( memStatus.dwTotalPhys < (100 * 1024 * 1024) )
return;
// Grab the existing default type (0x02FF)
READMSRREG( 0x02FF, &regVal );
// Set the default to WriteBack (0x06)
regVal.LowPart = (regVal.LowPart & ~0xFF) | 0x06;
WRITEMSRREG( 0x02FF, regVal );
}
2004-07-21 23:08:04 +00:00
ArchHooks_Xbox::ArchHooks_Xbox()
{
2004-12-01 02:48:50 +00:00
_set_new_handler(NoMemory);
_set_new_mode(1);
SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER) CheckPageFault);
2004-07-21 23:08:04 +00:00
XGetCustomLaunchData();
2004-10-21 05:43:00 +00:00
// mount A to DVD, C, E, F, G, X, and Y to the harddisk
MountDrives();
2004-10-26 11:56:08 +00:00
SetupNetwork();
2004-10-28 07:58:13 +00:00
EnableExtraRAM();
2004-07-21 23:08:04 +00:00
}
ArchHooks_Xbox::~ArchHooks_Xbox()
{
// We only want to reboot the Xbox in a software manner.
XLaunchNewImage( NULL, NULL );
}
2004-06-20 01:35:25 +00:00
/*
* (c) 2003-2004 Glenn Maynard, Chris Danford
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/