mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-24 13:39:11 +00:00
os2: a _lot_ of coding style cleanup, sot that they match the SDL style.
also renamed the 'debug' macro to debug_os2: the former was dangerously a common name. the binary (dll) output is precisely the same as before.
This commit is contained in:
parent
bdc5129f13
commit
a90f0400a5
29 changed files with 3536 additions and 3806 deletions
|
@ -34,37 +34,31 @@
|
|||
#define INCL_DOSEXCEPTIONS
|
||||
#include <os2.h>
|
||||
|
||||
// No need to switch priorities in SDL_Delay() for OS/2 versions > Warp3 fp 42.
|
||||
//#define _SWITCH_PRIORITY
|
||||
/* No need to switch priorities in SDL_Delay() for OS/2 versions > Warp3 fp 42, */
|
||||
/*#define _SWITCH_PRIORITY*/
|
||||
|
||||
typedef unsigned long long ULLONG;
|
||||
typedef unsigned long long ULLONG;
|
||||
|
||||
static ULONG ulTmrFreq = 0;
|
||||
static ULLONG ullTmrStart;
|
||||
static ULONG ulTmrFreq = 0;
|
||||
static ULLONG ullTmrStart;
|
||||
|
||||
void
|
||||
SDL_TicksInit(void)
|
||||
{
|
||||
ULONG ulRC;
|
||||
ULONG ulRC;
|
||||
|
||||
ulRC = DosTmrQueryFreq( &ulTmrFreq );
|
||||
if ( ulRC != NO_ERROR )
|
||||
{
|
||||
debug( "DosTmrQueryFreq() failed, rc = %u", ulRC );
|
||||
}
|
||||
else
|
||||
{
|
||||
ulRC = DosTmrQueryTime( (PQWORD)&ullTmrStart );
|
||||
if ( ulRC == NO_ERROR )
|
||||
return;
|
||||
ulRC = DosTmrQueryFreq(&ulTmrFreq);
|
||||
if (ulRC != NO_ERROR) {
|
||||
debug_os2("DosTmrQueryFreq() failed, rc = %u", ulRC);
|
||||
} else {
|
||||
ulRC = DosTmrQueryTime((PQWORD)&ullTmrStart);
|
||||
if (ulRC == NO_ERROR)
|
||||
return;
|
||||
debug_os2("DosTmrQueryTime() failed, rc = %u", ulRC);
|
||||
}
|
||||
|
||||
debug( "DosTmrQueryTime() failed, rc = %u", ulRC );
|
||||
}
|
||||
|
||||
ulTmrFreq = 0; // Error - use DosQuerySysInfo() for timer.
|
||||
|
||||
DosQuerySysInfo( QSV_MS_COUNT, QSV_MS_COUNT, (PULONG)&ullTmrStart,
|
||||
sizeof(ULONG) );
|
||||
ulTmrFreq = 0; /* Error - use DosQuerySysInfo() for timer. */
|
||||
DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, (PULONG)&ullTmrStart, sizeof(ULONG));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -75,113 +69,103 @@ SDL_TicksQuit(void)
|
|||
Uint32
|
||||
SDL_GetTicks(void)
|
||||
{
|
||||
ULONG ulResult;
|
||||
ULLONG ullTmrNow;
|
||||
ULONG ulResult;
|
||||
ULLONG ullTmrNow;
|
||||
|
||||
if ( ulTmrFreq == 0 )
|
||||
// Was not initialized.
|
||||
SDL_TicksInit();
|
||||
if (ulTmrFreq == 0) /* Was not initialized. */
|
||||
SDL_TicksInit();
|
||||
|
||||
if ( ulTmrFreq != 0 )
|
||||
{
|
||||
DosTmrQueryTime( (PQWORD)&ullTmrNow );
|
||||
ulResult = ( ullTmrNow - ullTmrStart ) * 1000 / ulTmrFreq;
|
||||
}
|
||||
else
|
||||
{
|
||||
DosQuerySysInfo( QSV_MS_COUNT, QSV_MS_COUNT, (PULONG)&ullTmrNow,
|
||||
sizeof(ULONG) );
|
||||
ulResult = (ULONG)ullTmrNow - (ULONG)ullTmrStart;
|
||||
}
|
||||
if (ulTmrFreq != 0) {
|
||||
DosTmrQueryTime((PQWORD)&ullTmrNow);
|
||||
ulResult = (ullTmrNow - ullTmrStart) * 1000 / ulTmrFreq;
|
||||
} else {
|
||||
DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, (PULONG)&ullTmrNow, sizeof(ULONG));
|
||||
ulResult = (ULONG)ullTmrNow - (ULONG)ullTmrStart;
|
||||
}
|
||||
|
||||
return ulResult;
|
||||
return ulResult;
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_GetPerformanceCounter(void)
|
||||
{
|
||||
QWORD qwTmrNow;
|
||||
QWORD qwTmrNow;
|
||||
|
||||
if ( ( ulTmrFreq == 0 ) || ( DosTmrQueryTime( &qwTmrNow ) != NO_ERROR ) )
|
||||
return SDL_GetTicks();
|
||||
if (ulTmrFreq == 0 || (DosTmrQueryTime(&qwTmrNow) != NO_ERROR))
|
||||
return SDL_GetTicks();
|
||||
|
||||
return *((Uint64 *)&qwTmrNow);
|
||||
return *((Uint64 *)&qwTmrNow);
|
||||
}
|
||||
|
||||
Uint64
|
||||
SDL_GetPerformanceFrequency(void)
|
||||
{
|
||||
return ulTmrFreq == 0 ? 1000 : (Uint64)ulTmrFreq;
|
||||
return (ulTmrFreq == 0)? 1000 : (Uint64)ulTmrFreq;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_Delay(Uint32 ms)
|
||||
{
|
||||
HTIMER hTimer = NULLHANDLE;
|
||||
ULONG ulRC;
|
||||
HTIMER hTimer = NULLHANDLE;
|
||||
ULONG ulRC;
|
||||
#ifdef _SWITCH_PRIORITY
|
||||
PPIB pib;
|
||||
PTIB tib;
|
||||
BOOL fSetPriority = ms < 50;
|
||||
ULONG ulSavePriority;
|
||||
ULONG ulNesting;
|
||||
PPIB pib;
|
||||
PTIB tib;
|
||||
BOOL fSetPriority = ms < 50;
|
||||
ULONG ulSavePriority;
|
||||
ULONG ulNesting;
|
||||
#endif
|
||||
HEV hevTimer;
|
||||
HEV hevTimer;
|
||||
|
||||
if ( ms == 0 )
|
||||
{
|
||||
DosSleep( 0 );
|
||||
return;
|
||||
}
|
||||
|
||||
ulRC = DosCreateEventSem( NULL, &hevTimer, DC_SEM_SHARED, FALSE );
|
||||
if ( ulRC != NO_ERROR )
|
||||
{
|
||||
debug( "DosAsyncTimer() failed, rc = %u", ulRC );
|
||||
DosSleep( ms );
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef _SWITCH_PRIORITY
|
||||
if ( fSetPriority )
|
||||
{
|
||||
if ( DosGetInfoBlocks( &tib, &pib ) != NO_ERROR )
|
||||
fSetPriority = FALSE;
|
||||
else
|
||||
{
|
||||
ulSavePriority = tib->tib_ptib2->tib2_ulpri;
|
||||
if ( ( (ulSavePriority & 0xFF00) == 0x0300 ) || // already have high pr.
|
||||
( DosEnterMustComplete( &ulNesting ) != NO_ERROR ) )
|
||||
fSetPriority = FALSE;
|
||||
else
|
||||
DosSetPriority( PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0 );
|
||||
if (ms == 0) {
|
||||
DosSleep(0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
DosResetEventSem( hevTimer, &ulRC );
|
||||
ulRC = DosAsyncTimer( ms, (HSEM)hevTimer, &hTimer );
|
||||
ulRC = DosCreateEventSem(NULL, &hevTimer, DC_SEM_SHARED, FALSE);
|
||||
if (ulRC != NO_ERROR) {
|
||||
debug_os2("DosAsyncTimer() failed, rc = %u", ulRC);
|
||||
DosSleep(ms);
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef _SWITCH_PRIORITY
|
||||
if ( fSetPriority )
|
||||
{
|
||||
if ( DosSetPriority( PRTYS_THREAD, (ulSavePriority >> 8) & 0xFF, 0, 0 ) ==
|
||||
NO_ERROR )
|
||||
DosSetPriority( PRTYS_THREAD, 0, ulSavePriority & 0xFF, 0 );
|
||||
|
||||
DosExitMustComplete( &ulNesting );
|
||||
}
|
||||
if (fSetPriority) {
|
||||
if (DosGetInfoBlocks(&tib, &pib) != NO_ERROR)
|
||||
fSetPriority = FALSE;
|
||||
else {
|
||||
ulSavePriority = tib->tib_ptib2->tib2_ulpri;
|
||||
if (((ulSavePriority & 0xFF00) == 0x0300) || /* already have high pr. */
|
||||
(DosEnterMustComplete( &ulNesting) != NO_ERROR))
|
||||
fSetPriority = FALSE;
|
||||
else {
|
||||
DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( ulRC != NO_ERROR )
|
||||
debug( "DosAsyncTimer() failed, rc = %u", ulRC );
|
||||
else
|
||||
DosWaitEventSem( hevTimer, SEM_INDEFINITE_WAIT );
|
||||
DosResetEventSem(hevTimer, &ulRC);
|
||||
ulRC = DosAsyncTimer(ms, (HSEM)hevTimer, &hTimer);
|
||||
|
||||
if ( ulRC != NO_ERROR )
|
||||
DosSleep( ms );
|
||||
#ifdef _SWITCH_PRIORITY
|
||||
if (fSetPriority) {
|
||||
if (DosSetPriority(PRTYS_THREAD, (ulSavePriority >> 8) & 0xFF, 0, 0) == NO_ERROR)
|
||||
DosSetPriority(PRTYS_THREAD, 0, ulSavePriority & 0xFF, 0);
|
||||
DosExitMustComplete(&ulNesting);
|
||||
}
|
||||
#endif
|
||||
|
||||
DosCloseEventSem( hevTimer );
|
||||
if (ulRC != NO_ERROR) {
|
||||
debug_os2("DosAsyncTimer() failed, rc = %u", ulRC);
|
||||
} else {
|
||||
DosWaitEventSem(hevTimer, SEM_INDEFINITE_WAIT);
|
||||
}
|
||||
|
||||
if (ulRC != NO_ERROR)
|
||||
DosSleep(ms);
|
||||
|
||||
DosCloseEventSem(hevTimer);
|
||||
}
|
||||
|
||||
#endif /* SDL_TIMER_OS2 */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue