mirror of
				https://github.com/libsdl-org/SDL.git
				synced 2025-11-04 01:34:38 +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:
		@@ -43,7 +43,6 @@ void lockDecr(volatile int *piVal);
 | 
			
		||||
  parm [eax];
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static ULONG _getEnvULong(PSZ pszName, ULONG ulMax, ULONG ulDefault)
 | 
			
		||||
{
 | 
			
		||||
    ULONG   ulValue;
 | 
			
		||||
@@ -60,36 +59,34 @@ static ULONG _getEnvULong(PSZ pszName, ULONG ulMax, ULONG ulDefault)
 | 
			
		||||
static int _MCIError(PSZ pszFunc, ULONG ulResult)
 | 
			
		||||
{
 | 
			
		||||
    CHAR    acBuf[128];
 | 
			
		||||
 | 
			
		||||
    mciGetErrorString(ulResult, acBuf, sizeof(acBuf));
 | 
			
		||||
    return SDL_SetError("[%s] %s", pszFunc, acBuf);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void _mixIOError(PSZ pszFunction, ULONG ulRC)
 | 
			
		||||
{
 | 
			
		||||
  debug( "%s() - failed, rc = 0x%X (%s)",
 | 
			
		||||
    debug_os2("%s() - failed, rc = 0x%X (%s)",
 | 
			
		||||
              pszFunction, ulRC,
 | 
			
		||||
         ulRC == MCIERR_INVALID_MODE ? "Mixer mode does not match request"
 | 
			
		||||
         : ulRC == MCIERR_INVALID_BUFFER ? "Caller sent an invalid buffer"
 | 
			
		||||
         : "unknown" );
 | 
			
		||||
              (ulRC == MCIERR_INVALID_MODE)   ? "Mixer mode does not match request" :
 | 
			
		||||
              (ulRC == MCIERR_INVALID_BUFFER) ? "Caller sent an invalid buffer"     : "unknown");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
LONG APIENTRY cbAudioWriteEvent(ULONG ulStatus, PMCI_MIX_BUFFER pBuffer,
 | 
			
		||||
                                ULONG ulFlags)
 | 
			
		||||
{
 | 
			
		||||
  PSDL_PrivateAudioData pAData = (PSDL_PrivateAudioData)pBuffer->ulUserParm;
 | 
			
		||||
    SDL_PrivateAudioData *pAData = (SDL_PrivateAudioData *)pBuffer->ulUserParm;
 | 
			
		||||
    ULONG   ulRC;
 | 
			
		||||
 | 
			
		||||
  if ( ulFlags != MIX_WRITE_COMPLETE )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "flags = 0x%X", ulFlags );
 | 
			
		||||
    if (ulFlags != MIX_WRITE_COMPLETE) {
 | 
			
		||||
        debug_os2("flags = 0x%X", ulFlags);
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
//  lockDecr( (int *)&pAData->ulQueuedBuf );
 | 
			
		||||
    /*lockDecr((int *)&pAData->ulQueuedBuf);*/
 | 
			
		||||
    ulRC = DosPostEventSem(pAData->hevBuf);
 | 
			
		||||
  if ( ( ulRC != NO_ERROR ) && ( ulRC != ERROR_ALREADY_POSTED ) )
 | 
			
		||||
    debug( "DosPostEventSem(), rc = %u", ulRC );
 | 
			
		||||
    if (ulRC != NO_ERROR && ulRC != ERROR_ALREADY_POSTED) {
 | 
			
		||||
        debug_os2("DosPostEventSem(), rc = %u", ulRC);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return 1; // It seems, return value is not matter.
 | 
			
		||||
}
 | 
			
		||||
@@ -97,21 +94,20 @@ LONG APIENTRY cbAudioWriteEvent(ULONG ulStatus, PMCI_MIX_BUFFER pBuffer,
 | 
			
		||||
LONG APIENTRY cbAudioReadEvent(ULONG ulStatus, PMCI_MIX_BUFFER pBuffer,
 | 
			
		||||
                               ULONG ulFlags)
 | 
			
		||||
{
 | 
			
		||||
  PSDL_PrivateAudioData pAData = (PSDL_PrivateAudioData)pBuffer->ulUserParm;
 | 
			
		||||
    SDL_PrivateAudioData *pAData = (SDL_PrivateAudioData *)pBuffer->ulUserParm;
 | 
			
		||||
    ULONG   ulRC;
 | 
			
		||||
 | 
			
		||||
  if ( ulFlags != MIX_READ_COMPLETE )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "flags = 0x%X", ulFlags );
 | 
			
		||||
    if (ulFlags != MIX_READ_COMPLETE) {
 | 
			
		||||
        debug_os2("flags = 0x%X", ulFlags);
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  pAData->stMCIMixSetup.pmixRead( pAData->stMCIMixSetup.ulMixHandle, pBuffer,
 | 
			
		||||
                                  1 );
 | 
			
		||||
    pAData->stMCIMixSetup.pmixRead(pAData->stMCIMixSetup.ulMixHandle, pBuffer, 1);
 | 
			
		||||
 | 
			
		||||
    ulRC = DosPostEventSem(pAData->hevBuf);
 | 
			
		||||
  if ( ( ulRC != NO_ERROR ) && ( ulRC != ERROR_ALREADY_POSTED ) )
 | 
			
		||||
    debug( "DosPostEventSem(), rc = %u", ulRC );
 | 
			
		||||
    if (ulRC != NO_ERROR && ulRC != ERROR_ALREADY_POSTED) {
 | 
			
		||||
        debug_os2("DosPostEventSem(), rc = %u", ulRC);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return 1;
 | 
			
		||||
}
 | 
			
		||||
@@ -133,38 +129,34 @@ static void OS2_DetectDevices(void)
 | 
			
		||||
    stMCISysInfo.usDeviceType = MCI_DEVTYPE_AUDIO_AMPMIX;
 | 
			
		||||
    ulRC = mciSendCommand(0, MCI_SYSINFO, MCI_WAIT | MCI_SYSINFO_QUANTITY,
 | 
			
		||||
                          &stMCISysInfo, 0);
 | 
			
		||||
  if ( ulRC != NO_ERROR )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "MCI_SYSINFO, MCI_SYSINFO_QUANTITY - failed, rc = 0x%X", ulRC );
 | 
			
		||||
    if (ulRC != NO_ERROR) {
 | 
			
		||||
        debug_os2("MCI_SYSINFO, MCI_SYSINFO_QUANTITY - failed, rc = 0x%X", ulRC);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ulDevicesNum = atol(stMCISysInfo.pszReturn);
 | 
			
		||||
 | 
			
		||||
    for (stSysInfoParams.ulNumber = 0; stSysInfoParams.ulNumber < ulDevicesNum;
 | 
			
		||||
       stSysInfoParams.ulNumber++ )
 | 
			
		||||
  {
 | 
			
		||||
    // Get device install name.
 | 
			
		||||
         stSysInfoParams.ulNumber++) {
 | 
			
		||||
        /* Get device install name. */
 | 
			
		||||
        stSysInfoParams.pszReturn    = acBuf;
 | 
			
		||||
        stSysInfoParams.ulRetSize    = sizeof(acBuf);
 | 
			
		||||
        stSysInfoParams.usDeviceType = MCI_DEVTYPE_AUDIO_AMPMIX;
 | 
			
		||||
        ulRC = mciSendCommand(0, MCI_SYSINFO, MCI_WAIT | MCI_SYSINFO_INSTALLNAME,
 | 
			
		||||
                              &stSysInfoParams, 0);
 | 
			
		||||
    if ( ulRC != NO_ERROR )
 | 
			
		||||
    {
 | 
			
		||||
      debug( "MCI_SYSINFO, MCI_SYSINFO_INSTALLNAME - failed, rc = 0x%X", ulRC );
 | 
			
		||||
        if (ulRC != NO_ERROR) {
 | 
			
		||||
            debug_os2("MCI_SYSINFO, MCI_SYSINFO_INSTALLNAME - failed, rc = 0x%X", ulRC);
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    // Get textual product description.
 | 
			
		||||
        /* Get textual product description. */
 | 
			
		||||
        stSysInfoParams.ulItem = MCI_SYSINFO_QUERY_DRIVER;
 | 
			
		||||
        stSysInfoParams.pSysInfoParm = &stLogDevice;
 | 
			
		||||
        strcpy(stLogDevice.szInstallName, stSysInfoParams.pszReturn);
 | 
			
		||||
        ulRC = mciSendCommand(0, MCI_SYSINFO, MCI_WAIT | MCI_SYSINFO_ITEM,
 | 
			
		||||
                              &stSysInfoParams, 0);
 | 
			
		||||
    if ( ulRC != NO_ERROR )
 | 
			
		||||
    {
 | 
			
		||||
      debug( "MCI_SYSINFO, MCI_SYSINFO_ITEM - failed, rc = 0x%X", ulRC );
 | 
			
		||||
        if (ulRC != NO_ERROR) {
 | 
			
		||||
            debug_os2("MCI_SYSINFO, MCI_SYSINFO_ITEM - failed, rc = 0x%X", ulRC);
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -177,41 +169,42 @@ static void OS2_DetectDevices(void)
 | 
			
		||||
 | 
			
		||||
static void OS2_WaitDevice(_THIS)
 | 
			
		||||
{
 | 
			
		||||
  PSDL_PrivateAudioData pAData = (PSDL_PrivateAudioData)this->hidden;
 | 
			
		||||
    SDL_PrivateAudioData *pAData = (SDL_PrivateAudioData *)this->hidden;
 | 
			
		||||
    ULONG   ulRC;
 | 
			
		||||
 | 
			
		||||
    /* Wait for an audio chunk to finish */
 | 
			
		||||
    ulRC = DosWaitEventSem(pAData->hevBuf, 5000);
 | 
			
		||||
  if ( ulRC != NO_ERROR )
 | 
			
		||||
    debug( "DosWaitEventSem(), rc = %u", ulRC );
 | 
			
		||||
    if (ulRC != NO_ERROR) {
 | 
			
		||||
        debug_os2("DosWaitEventSem(), rc = %u", ulRC);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static Uint8 *OS2_GetDeviceBuf(_THIS)
 | 
			
		||||
{
 | 
			
		||||
  PSDL_PrivateAudioData pAData = (PSDL_PrivateAudioData)this->hidden;
 | 
			
		||||
 | 
			
		||||
    SDL_PrivateAudioData *pAData = (SDL_PrivateAudioData *)this->hidden;
 | 
			
		||||
    return pAData->aMixBuffers[pAData->ulNextBuf].pBuffer;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void OS2_PlayDevice(_THIS)
 | 
			
		||||
{
 | 
			
		||||
  PSDL_PrivateAudioData pAData = (PSDL_PrivateAudioData)this->hidden;
 | 
			
		||||
    SDL_PrivateAudioData *pAData = (SDL_PrivateAudioData *)this->hidden;
 | 
			
		||||
    ULONG                 ulRC;
 | 
			
		||||
    PMCI_MIX_BUFFER       pMixBuffer = &pAData->aMixBuffers[pAData->ulNextBuf];
 | 
			
		||||
 | 
			
		||||
    /* Queue it up */
 | 
			
		||||
//  lockIncr( (int *)&pAData->ulQueuedBuf );
 | 
			
		||||
    /*lockIncr((int *)&pAData->ulQueuedBuf);*/
 | 
			
		||||
    ulRC = pAData->stMCIMixSetup.pmixWrite(pAData->stMCIMixSetup.ulMixHandle,
 | 
			
		||||
                                           pMixBuffer, 1);
 | 
			
		||||
  if ( ulRC != MCIERR_SUCCESS )
 | 
			
		||||
    if (ulRC != MCIERR_SUCCESS) {
 | 
			
		||||
        _mixIOError("pmixWrite", ulRC);
 | 
			
		||||
  else
 | 
			
		||||
    } else {
 | 
			
		||||
        pAData->ulNextBuf = (pAData->ulNextBuf + 1) % pAData->cMixBuffers;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void OS2_CloseDevice(_THIS)
 | 
			
		||||
{
 | 
			
		||||
  PSDL_PrivateAudioData pAData = (PSDL_PrivateAudioData)this->hidden;
 | 
			
		||||
    SDL_PrivateAudioData *pAData = (SDL_PrivateAudioData *)this->hidden;
 | 
			
		||||
    MCI_GENERIC_PARMS     sMCIGenericParms;
 | 
			
		||||
    ULONG                 ulRC;
 | 
			
		||||
 | 
			
		||||
@@ -219,22 +212,20 @@ static void OS2_CloseDevice(_THIS)
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
    /* Close up audio */
 | 
			
		||||
  if ( pAData->usDeviceId != (USHORT)~0 )
 | 
			
		||||
  {
 | 
			
		||||
    // Device is open.
 | 
			
		||||
    if ( pAData->stMCIMixSetup.ulBitsPerSample != 0 )
 | 
			
		||||
    {
 | 
			
		||||
      // Mixer was initialized.
 | 
			
		||||
    if (pAData->usDeviceId != (USHORT)~0) {
 | 
			
		||||
        /* Device is open. */
 | 
			
		||||
        if (pAData->stMCIMixSetup.ulBitsPerSample != 0) {
 | 
			
		||||
            /* Mixer was initialized. */
 | 
			
		||||
            ulRC = mciSendCommand(pAData->usDeviceId, MCI_MIXSETUP,
 | 
			
		||||
                                  MCI_WAIT | MCI_MIXSETUP_DEINIT,
 | 
			
		||||
                                  &pAData->stMCIMixSetup, 0);
 | 
			
		||||
      if ( ulRC != MCIERR_SUCCESS )
 | 
			
		||||
        debug( "MCI_MIXSETUP, MCI_MIXSETUP_DEINIT - failed" );
 | 
			
		||||
            if (ulRC != MCIERR_SUCCESS) {
 | 
			
		||||
                debug_os2("MCI_MIXSETUP, MCI_MIXSETUP_DEINIT - failed");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    if ( pAData->cMixBuffers != 0 )
 | 
			
		||||
    {
 | 
			
		||||
      // Buffers was allocated.
 | 
			
		||||
        if (pAData->cMixBuffers != 0) {
 | 
			
		||||
            /* Buffers was allocated. */
 | 
			
		||||
            MCI_BUFFER_PARMS    stMCIBuffer;
 | 
			
		||||
 | 
			
		||||
            stMCIBuffer.ulBufferSize = pAData->aMixBuffers[0].ulBufferLength;
 | 
			
		||||
@@ -243,14 +234,16 @@ static void OS2_CloseDevice(_THIS)
 | 
			
		||||
 | 
			
		||||
            ulRC = mciSendCommand(pAData->usDeviceId, MCI_BUFFER,
 | 
			
		||||
                                  MCI_WAIT | MCI_DEALLOCATE_MEMORY, &stMCIBuffer, 0);
 | 
			
		||||
      if ( ulRC != MCIERR_SUCCESS )
 | 
			
		||||
        debug( "MCI_BUFFER, MCI_DEALLOCATE_MEMORY - failed" );
 | 
			
		||||
            if (ulRC != MCIERR_SUCCESS) {
 | 
			
		||||
                debug_os2("MCI_BUFFER, MCI_DEALLOCATE_MEMORY - failed");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ulRC = mciSendCommand(pAData->usDeviceId, MCI_CLOSE, MCI_WAIT,
 | 
			
		||||
                              &sMCIGenericParms, 0);
 | 
			
		||||
    if ( ulRC != MCIERR_SUCCESS )
 | 
			
		||||
      debug( "MCI_CLOSE - failed" );
 | 
			
		||||
        if (ulRC != MCIERR_SUCCESS) {
 | 
			
		||||
            debug_os2("MCI_CLOSE - failed");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (pAData->hevBuf != NULLHANDLE)
 | 
			
		||||
@@ -262,7 +255,7 @@ static void OS2_CloseDevice(_THIS)
 | 
			
		||||
static int OS2_OpenDevice(_THIS, void *handle, const char *devname,
 | 
			
		||||
                          int iscapture)
 | 
			
		||||
{
 | 
			
		||||
  PSDL_PrivateAudioData pAData;
 | 
			
		||||
    SDL_PrivateAudioData *pAData;
 | 
			
		||||
    SDL_AudioFormat       SDLAudioFmt;
 | 
			
		||||
    MCI_AMP_OPEN_PARMS    stMCIAmpOpen;
 | 
			
		||||
    MCI_BUFFER_PARMS      stMCIBuffer;
 | 
			
		||||
@@ -275,15 +268,12 @@ static int OS2_OpenDevice(_THIS, void *handle, const char *devname,
 | 
			
		||||
    SDL_zero(stMCIBuffer);
 | 
			
		||||
 | 
			
		||||
    for (SDLAudioFmt = SDL_FirstAudioFormat(this->spec.format);
 | 
			
		||||
       SDLAudioFmt != 0; SDLAudioFmt = SDL_NextAudioFormat() )
 | 
			
		||||
  {
 | 
			
		||||
    if ( ( SDLAudioFmt == AUDIO_U8 ) || ( SDLAudioFmt == AUDIO_S16 ) )
 | 
			
		||||
         SDLAudioFmt != 0; SDLAudioFmt = SDL_NextAudioFormat()) {
 | 
			
		||||
        if (SDLAudioFmt == AUDIO_U8 || SDLAudioFmt == AUDIO_S16)
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  if ( SDLAudioFmt == 0 )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "Unsupported audio format, AUDIO_S16 used" );
 | 
			
		||||
    if (SDLAudioFmt == 0) {
 | 
			
		||||
        debug_os2("Unsupported audio format, AUDIO_S16 used");
 | 
			
		||||
        SDLAudioFmt = AUDIO_S16;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -293,54 +283,51 @@ static int OS2_OpenDevice(_THIS, void *handle, const char *devname,
 | 
			
		||||
    this->hidden = pAData;
 | 
			
		||||
 | 
			
		||||
    ulRC = DosCreateEventSem(NULL, &pAData->hevBuf, DCE_AUTORESET, TRUE);
 | 
			
		||||
  if ( ulRC != NO_ERROR )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "DosCreateEventSem() failed, rc = %u", ulRC );
 | 
			
		||||
    if (ulRC != NO_ERROR) {
 | 
			
		||||
        debug_os2("DosCreateEventSem() failed, rc = %u", ulRC);
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  // Open audio device
 | 
			
		||||
  stMCIAmpOpen.usDeviceID = handle != NULL ? ( ((ULONG)handle) - 1 ) : 0;
 | 
			
		||||
    /* Open audio device */
 | 
			
		||||
    stMCIAmpOpen.usDeviceID = (handle != NULL) ? ((ULONG)handle - 1) : 0;
 | 
			
		||||
    stMCIAmpOpen.pszDeviceType = (PSZ)MCI_DEVTYPE_AUDIO_AMPMIX;
 | 
			
		||||
    ulRC = mciSendCommand(0, MCI_OPEN,
 | 
			
		||||
           _getEnvULong( "SDL_AUDIO_SHARE", 1, 0 ) != 0
 | 
			
		||||
             ? MCI_WAIT | MCI_OPEN_TYPE_ID | MCI_OPEN_SHAREABLE
 | 
			
		||||
             : MCI_WAIT | MCI_OPEN_TYPE_ID,
 | 
			
		||||
                          (_getEnvULong("SDL_AUDIO_SHARE", 1, 0) != 0)?
 | 
			
		||||
                           MCI_WAIT | MCI_OPEN_TYPE_ID | MCI_OPEN_SHAREABLE :
 | 
			
		||||
                           MCI_WAIT | MCI_OPEN_TYPE_ID,
 | 
			
		||||
                          &stMCIAmpOpen,  0);
 | 
			
		||||
  if ( ulRC != MCIERR_SUCCESS )
 | 
			
		||||
  {
 | 
			
		||||
    if (ulRC != MCIERR_SUCCESS) {
 | 
			
		||||
        stMCIAmpOpen.usDeviceID = (USHORT)~0;
 | 
			
		||||
        return _MCIError("MCI_OPEN", ulRC);
 | 
			
		||||
    }
 | 
			
		||||
    pAData->usDeviceId = stMCIAmpOpen.usDeviceID;
 | 
			
		||||
 | 
			
		||||
  if ( iscapture != 0 )
 | 
			
		||||
  {
 | 
			
		||||
    if (iscapture != 0) {
 | 
			
		||||
        MCI_CONNECTOR_PARMS stMCIConnector;
 | 
			
		||||
        MCI_AMP_SET_PARMS   stMCIAmpSet;
 | 
			
		||||
        BOOL                fLineIn = _getEnvULong("SDL_AUDIO_LINEIN", 1, 0);
 | 
			
		||||
 | 
			
		||||
    // Set particular connector.
 | 
			
		||||
        /* Set particular connector. */
 | 
			
		||||
        SDL_zero(stMCIConnector);
 | 
			
		||||
    stMCIConnector.ulConnectorType = fLineIn ? MCI_LINE_IN_CONNECTOR
 | 
			
		||||
                                             : MCI_MICROPHONE_CONNECTOR;
 | 
			
		||||
        stMCIConnector.ulConnectorType = (fLineIn)? MCI_LINE_IN_CONNECTOR :
 | 
			
		||||
                                                    MCI_MICROPHONE_CONNECTOR;
 | 
			
		||||
        mciSendCommand(stMCIAmpOpen.usDeviceID, MCI_CONNECTOR,
 | 
			
		||||
                       MCI_WAIT | MCI_ENABLE_CONNECTOR |
 | 
			
		||||
                       MCI_CONNECTOR_TYPE, &stMCIConnector, 0);
 | 
			
		||||
 | 
			
		||||
    // Disable monitor.
 | 
			
		||||
        /* Disable monitor. */
 | 
			
		||||
        SDL_zero(stMCIAmpSet);
 | 
			
		||||
        stMCIAmpSet.ulItem = MCI_AMP_SET_MONITOR;
 | 
			
		||||
        mciSendCommand(stMCIAmpOpen.usDeviceID, MCI_SET,
 | 
			
		||||
                       MCI_WAIT | MCI_SET_OFF | MCI_SET_ITEM,
 | 
			
		||||
                       &stMCIAmpSet, 0);
 | 
			
		||||
 | 
			
		||||
    // Set record volume.
 | 
			
		||||
        /* Set record volume. */
 | 
			
		||||
        stMCIAmpSet.ulLevel = _getEnvULong("SDL_AUDIO_RECVOL", 100, 90);
 | 
			
		||||
        stMCIAmpSet.ulItem  = MCI_AMP_SET_AUDIO;
 | 
			
		||||
    stMCIAmpSet.ulAudio = MCI_SET_AUDIO_ALL; // Both cnannels.
 | 
			
		||||
    stMCIAmpSet.ulValue = fLineIn ? MCI_LINE_IN_CONNECTOR
 | 
			
		||||
                                  : MCI_MICROPHONE_CONNECTOR ;
 | 
			
		||||
        stMCIAmpSet.ulAudio = MCI_SET_AUDIO_ALL; /* Both cnannels. */
 | 
			
		||||
        stMCIAmpSet.ulValue = (fLineIn) ? MCI_LINE_IN_CONNECTOR :
 | 
			
		||||
                                          MCI_MICROPHONE_CONNECTOR ;
 | 
			
		||||
 | 
			
		||||
        mciSendCommand(stMCIAmpOpen.usDeviceID, MCI_SET,
 | 
			
		||||
                       MCI_WAIT | MCI_SET_AUDIO | MCI_AMP_SET_GAIN,
 | 
			
		||||
@@ -349,38 +336,31 @@ static int OS2_OpenDevice(_THIS, void *handle, const char *devname,
 | 
			
		||||
 | 
			
		||||
    this->spec.format = SDLAudioFmt;
 | 
			
		||||
    this->spec.channels = this->spec.channels > 1 ? 2 : 1;
 | 
			
		||||
  if ( this->spec.freq < 8000 )
 | 
			
		||||
  {
 | 
			
		||||
    if (this->spec.freq < 8000) {
 | 
			
		||||
        this->spec.freq = 8000;
 | 
			
		||||
        new_freq = TRUE;
 | 
			
		||||
  }
 | 
			
		||||
  else if ( this->spec.freq > 48000 )
 | 
			
		||||
  {
 | 
			
		||||
    } else if (this->spec.freq > 48000) {
 | 
			
		||||
        this->spec.freq = 48000;
 | 
			
		||||
        new_freq = TRUE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  // Setup mixer.
 | 
			
		||||
    /* Setup mixer. */
 | 
			
		||||
    pAData->stMCIMixSetup.ulFormatTag     = MCI_WAVE_FORMAT_PCM;
 | 
			
		||||
    pAData->stMCIMixSetup.ulBitsPerSample = SDL_AUDIO_BITSIZE(SDLAudioFmt);
 | 
			
		||||
    pAData->stMCIMixSetup.ulSamplesPerSec = this->spec.freq;
 | 
			
		||||
    pAData->stMCIMixSetup.ulChannels      = this->spec.channels;
 | 
			
		||||
    pAData->stMCIMixSetup.ulDeviceType    = MCI_DEVTYPE_WAVEFORM_AUDIO;
 | 
			
		||||
  if ( iscapture == 0 )
 | 
			
		||||
  {
 | 
			
		||||
    if (iscapture == 0) {
 | 
			
		||||
        pAData->stMCIMixSetup.ulFormatMode= MCI_PLAY;
 | 
			
		||||
        pAData->stMCIMixSetup.pmixEvent   = cbAudioWriteEvent;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    } else {
 | 
			
		||||
        pAData->stMCIMixSetup.ulFormatMode= MCI_RECORD;
 | 
			
		||||
        pAData->stMCIMixSetup.pmixEvent   = cbAudioReadEvent;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ulRC = mciSendCommand(pAData->usDeviceId, MCI_MIXSETUP,
 | 
			
		||||
                          MCI_WAIT | MCI_MIXSETUP_INIT, &pAData->stMCIMixSetup, 0);
 | 
			
		||||
  if ( ( ulRC != MCIERR_SUCCESS ) && ( this->spec.freq > 44100 ) )
 | 
			
		||||
  {
 | 
			
		||||
    if (ulRC != MCIERR_SUCCESS && this->spec.freq > 44100) {
 | 
			
		||||
        new_freq = TRUE;
 | 
			
		||||
        pAData->stMCIMixSetup.ulSamplesPerSec = 44100;
 | 
			
		||||
        this->spec.freq = 44100;
 | 
			
		||||
@@ -388,14 +368,13 @@ static int OS2_OpenDevice(_THIS, void *handle, const char *devname,
 | 
			
		||||
                              MCI_WAIT | MCI_MIXSETUP_INIT, &pAData->stMCIMixSetup, 0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  debug( "Setup mixer [BPS: %u, Freq.: %u, Channels: %u]: %s",
 | 
			
		||||
    debug_os2("Setup mixer [BPS: %u, Freq.: %u, Channels: %u]: %s",
 | 
			
		||||
              pAData->stMCIMixSetup.ulBitsPerSample,
 | 
			
		||||
              pAData->stMCIMixSetup.ulSamplesPerSec,
 | 
			
		||||
              pAData->stMCIMixSetup.ulChannels,
 | 
			
		||||
         ulRC == MCIERR_SUCCESS ? "SUCCESS" : "FAIL" );
 | 
			
		||||
              (ulRC == MCIERR_SUCCESS)? "SUCCESS" : "FAIL");
 | 
			
		||||
 | 
			
		||||
  if ( ulRC != MCIERR_SUCCESS )
 | 
			
		||||
  {
 | 
			
		||||
    if (ulRC != MCIERR_SUCCESS) {
 | 
			
		||||
        pAData->stMCIMixSetup.ulBitsPerSample = 0;
 | 
			
		||||
        return _MCIError("MCI_MIXSETUP", ulRC);
 | 
			
		||||
    }
 | 
			
		||||
@@ -413,25 +392,21 @@ static int OS2_OpenDevice(_THIS, void *handle, const char *devname,
 | 
			
		||||
    /* Update the fragment size as size in bytes */
 | 
			
		||||
    SDL_CalculateAudioSpec(&this->spec);
 | 
			
		||||
 | 
			
		||||
  // Allocate memory buffers
 | 
			
		||||
 | 
			
		||||
  stMCIBuffer.ulBufferSize = this->spec.size;// (this->spec.freq / 1000) * 100;
 | 
			
		||||
    /* Allocate memory buffers */
 | 
			
		||||
    stMCIBuffer.ulBufferSize = this->spec.size;/* (this->spec.freq / 1000) * 100 */
 | 
			
		||||
    stMCIBuffer.ulNumBuffers = NUM_BUFFERS;
 | 
			
		||||
    stMCIBuffer.pBufList     = &pAData->aMixBuffers;
 | 
			
		||||
 | 
			
		||||
    ulRC = mciSendCommand(pAData->usDeviceId, MCI_BUFFER,
 | 
			
		||||
                          MCI_WAIT | MCI_ALLOCATE_MEMORY, &stMCIBuffer, 0);
 | 
			
		||||
  if ( ulRC != MCIERR_SUCCESS )
 | 
			
		||||
  {
 | 
			
		||||
    if (ulRC != MCIERR_SUCCESS) {
 | 
			
		||||
        return _MCIError("MCI_BUFFER", ulRC);
 | 
			
		||||
    }
 | 
			
		||||
    pAData->cMixBuffers = stMCIBuffer.ulNumBuffers;
 | 
			
		||||
    this->spec.size = stMCIBuffer.ulBufferSize;
 | 
			
		||||
 | 
			
		||||
  // Fill all device buffers with data
 | 
			
		||||
 | 
			
		||||
  for( ulIdx = 0; ulIdx < stMCIBuffer.ulNumBuffers; ulIdx++ )
 | 
			
		||||
  {
 | 
			
		||||
    /* Fill all device buffers with data */
 | 
			
		||||
    for (ulIdx = 0; ulIdx < stMCIBuffer.ulNumBuffers; ulIdx++) {
 | 
			
		||||
        pAData->aMixBuffers[ulIdx].ulFlags        = 0;
 | 
			
		||||
        pAData->aMixBuffers[ulIdx].ulBufferLength = stMCIBuffer.ulBufferSize;
 | 
			
		||||
        pAData->aMixBuffers[ulIdx].ulUserParm     = (ULONG)pAData;
 | 
			
		||||
@@ -440,13 +415,12 @@ static int OS2_OpenDevice(_THIS, void *handle, const char *devname,
 | 
			
		||||
                this->spec.silence, stMCIBuffer.ulBufferSize);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  // Write buffers to kick off the amp mixer
 | 
			
		||||
//  pAData->ulQueuedBuf = 1;//stMCIBuffer.ulNumBuffers;
 | 
			
		||||
    /* Write buffers to kick off the amp mixer */
 | 
			
		||||
    /*pAData->ulQueuedBuf = 1;//stMCIBuffer.ulNumBuffers;*/
 | 
			
		||||
    ulRC = pAData->stMCIMixSetup.pmixWrite(pAData->stMCIMixSetup.ulMixHandle,
 | 
			
		||||
                                           &pAData->aMixBuffers,
 | 
			
		||||
                                          1 );//stMCIBuffer.ulNumBuffers );
 | 
			
		||||
  if ( ulRC != MCIERR_SUCCESS )
 | 
			
		||||
  {
 | 
			
		||||
                                           1 /*stMCIBuffer.ulNumBuffers*/);
 | 
			
		||||
    if (ulRC != MCIERR_SUCCESS) {
 | 
			
		||||
        _mixIOError("pmixWrite", ulRC);
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
@@ -465,11 +439,11 @@ static int OS2_Init(SDL_AudioDriverImpl * impl)
 | 
			
		||||
    impl->GetDeviceBuf  = OS2_GetDeviceBuf;
 | 
			
		||||
    impl->CloseDevice   = OS2_CloseDevice;
 | 
			
		||||
 | 
			
		||||
// TODO: IMPLEMENT CAPTURE SUPPORT:
 | 
			
		||||
//  impl->CaptureFromDevice = ;
 | 
			
		||||
//  impl->FlushCapture = ;
 | 
			
		||||
//  impl->HasCaptureSupport = SDL_TRUE;
 | 
			
		||||
 | 
			
		||||
    /* TODO: IMPLEMENT CAPTURE SUPPORT:
 | 
			
		||||
    impl->CaptureFromDevice = ;
 | 
			
		||||
    impl->FlushCapture = ;
 | 
			
		||||
    impl->HasCaptureSupport = SDL_TRUE;
 | 
			
		||||
    */
 | 
			
		||||
    return 1; /* this audio target is available. */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -46,8 +46,8 @@ typedef struct SDL_PrivateAudioData
 | 
			
		||||
    ULONG               ulNextBuf;
 | 
			
		||||
    ULONG               cMixBuffers;
 | 
			
		||||
    MCI_MIX_BUFFER      aMixBuffers[NUM_BUFFERS];
 | 
			
		||||
//  ULONG                ulQueuedBuf;
 | 
			
		||||
} SDL_PrivateAudioData, *PSDL_PrivateAudioData;
 | 
			
		||||
/*  ULONG               ulQueuedBuf;*/
 | 
			
		||||
} SDL_PrivateAudioData;
 | 
			
		||||
 | 
			
		||||
#endif /* SDL_os2mm_h_ */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -18,19 +18,21 @@
 | 
			
		||||
     misrepresented as being the original software.
 | 
			
		||||
  3. This notice may not be removed or altered from any source distribution.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
#include "../../SDL_internal.h"
 | 
			
		||||
 | 
			
		||||
#if defined(__OS2__)
 | 
			
		||||
 | 
			
		||||
#include "geniconv/geniconv.h"
 | 
			
		||||
 | 
			
		||||
// SDL_OS2Quit() will be called from SDL_QuitSubSystem().
 | 
			
		||||
 | 
			
		||||
void SDL_OS2Quit()
 | 
			
		||||
/* SDL_OS2Quit() will be called from SDL_QuitSubSystem() */
 | 
			
		||||
void SDL_OS2Quit(void)
 | 
			
		||||
{
 | 
			
		||||
  // Unload DLL used for iconv. We can do it at any time and use iconv again -
 | 
			
		||||
  // dynamic library will be loaded on first call iconv_open() (see geniconv).
 | 
			
		||||
    /* Unload DLL used for iconv. We can do it at any time and use iconv again -
 | 
			
		||||
     * dynamic library will be loaded on first call iconv_open() (see geniconv). */
 | 
			
		||||
    libiconv_clean();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/* vi: set ts=4 sw=4 expandtab: */
 | 
			
		||||
 
 | 
			
		||||
@@ -27,24 +27,26 @@
 | 
			
		||||
 | 
			
		||||
#ifdef OS2DEBUG
 | 
			
		||||
#if (OS2DEBUG-0 >= 2)
 | 
			
		||||
# define debug(s,...) SDL_LogDebug( SDL_LOG_CATEGORY_APPLICATION, \
 | 
			
		||||
# define debug_os2(s,...) SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,    \
 | 
			
		||||
                                 __func__ "(): " ##s,      ##__VA_ARGS__)
 | 
			
		||||
#else
 | 
			
		||||
# define debug(s,...) printf( __func__"(): "##s"\n", ##__VA_ARGS__ )
 | 
			
		||||
# define debug_os2(s,...) printf(__func__ "(): " ##s "\n", ##__VA_ARGS__)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#else
 | 
			
		||||
#else /* no debug */
 | 
			
		||||
 | 
			
		||||
# define debug(s,...)
 | 
			
		||||
# define debug_os2(s,...) do {} while (0)
 | 
			
		||||
 | 
			
		||||
#endif /* OS2DEBUG */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/* StrUTF8New() - geniconv/sys2utf8.c */
 | 
			
		||||
#define OS2_SysToUTF8(S) StrUTF8New( 1, S, SDL_strlen( S ) + 1 )
 | 
			
		||||
#define OS2_UTF8ToSys(S) StrUTF8New( 0, (char *)(S), SDL_strlen( S ) + 1 )
 | 
			
		||||
#define OS2_SysToUTF8(S) StrUTF8New(1,         (S), SDL_strlen((S)) + 1)
 | 
			
		||||
#define OS2_UTF8ToSys(S) StrUTF8New(0, (char *)(S), SDL_strlen((S)) + 1)
 | 
			
		||||
 | 
			
		||||
/* SDL_OS2Quit() will be called from SDL_QuitSubSystem() */
 | 
			
		||||
void SDL_OS2Quit();
 | 
			
		||||
void SDL_OS2Quit(void);
 | 
			
		||||
 | 
			
		||||
#endif /* SDL_os2_h_ */
 | 
			
		||||
 | 
			
		||||
/* vi: set ts=4 sw=4 expandtab: */
 | 
			
		||||
 
 | 
			
		||||
@@ -31,32 +31,32 @@
 | 
			
		||||
 | 
			
		||||
#include "geniconv.h"
 | 
			
		||||
 | 
			
		||||
//#define DEBUG
 | 
			
		||||
/*#define DEBUG*/
 | 
			
		||||
 | 
			
		||||
#ifdef DEBUG
 | 
			
		||||
# include <stdio.h>
 | 
			
		||||
# define debug(s,...) printf(__func__"(): "##s"\n" ,##__VA_ARGS__)
 | 
			
		||||
#else
 | 
			
		||||
# define debug(s,...)
 | 
			
		||||
# define debug(s,...) do {} while (0)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
// Exports from os2iconv.c.
 | 
			
		||||
/* Exports from os2iconv.c */
 | 
			
		||||
extern iconv_t _System os2_iconv_open(const char* tocode, const char* fromcode);
 | 
			
		||||
extern size_t _System os2_iconv(iconv_t cd, char* * inbuf,
 | 
			
		||||
                                size_t *inbytesleft, char* * outbuf,
 | 
			
		||||
                                size_t *outbytesleft);
 | 
			
		||||
extern int _System os2_iconv_close(iconv_t cd);
 | 
			
		||||
 | 
			
		||||
// Functions pointers types.
 | 
			
		||||
/* Functions pointers types */
 | 
			
		||||
typedef iconv_t _System (*FNICONV_OPEN)(const char* tocode, const char* fromcode);
 | 
			
		||||
typedef size_t _System (*FNICONV)(iconv_t cd, char* * inbuf,
 | 
			
		||||
                                  size_t *inbytesleft, char* * outbuf,
 | 
			
		||||
                                  size_t *outbytesleft);
 | 
			
		||||
typedef int _System (*FNICONV_CLOSE)(iconv_t cd);
 | 
			
		||||
 | 
			
		||||
// Used DLL module handle.
 | 
			
		||||
/* Used DLL module handle */
 | 
			
		||||
static HMODULE         hmIconv = NULLHANDLE;
 | 
			
		||||
// Functions pointers.
 | 
			
		||||
/* Functions pointers */
 | 
			
		||||
static FNICONV_OPEN    fn_iconv_open = NULL;
 | 
			
		||||
static FNICONV         fn_iconv = NULL;
 | 
			
		||||
static FNICONV_CLOSE   fn_iconv_close = NULL;
 | 
			
		||||
@@ -69,58 +69,49 @@ static BOOL _loadDLL(PSZ pszName, PSZ pszIconvOpen, PSZ pszIconv,
 | 
			
		||||
    CHAR  acError[256];
 | 
			
		||||
 | 
			
		||||
    ulRC = DosLoadModule(acError, sizeof(acError), pszName, &hmIconv);
 | 
			
		||||
  if ( ulRC != NO_ERROR )
 | 
			
		||||
  {
 | 
			
		||||
    if (ulRC != NO_ERROR) {
 | 
			
		||||
        debug("DLL not loaded: %s", &acError);
 | 
			
		||||
        return FALSE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  do
 | 
			
		||||
  {
 | 
			
		||||
    do {
 | 
			
		||||
        ulRC = DosQueryProcAddr(hmIconv, 0, pszIconvOpen, (PFN *)&fn_iconv_open);
 | 
			
		||||
    if ( ulRC != NO_ERROR )
 | 
			
		||||
    {
 | 
			
		||||
        if (ulRC != NO_ERROR) {
 | 
			
		||||
            debug("Error: cannot find entry %s in %s", pszIconvOpen, pszName);
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ulRC = DosQueryProcAddr(hmIconv, 0, pszIconv, (PFN *)&fn_iconv);
 | 
			
		||||
    if ( ulRC != NO_ERROR )
 | 
			
		||||
    {
 | 
			
		||||
        if (ulRC != NO_ERROR) {
 | 
			
		||||
            debug("Error: cannot find entry %s in %s", pszIconv, pszName);
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ulRC = DosQueryProcAddr(hmIconv, 0, pszIconvClose, (PFN *)&fn_iconv_close);
 | 
			
		||||
    if ( ulRC != NO_ERROR )
 | 
			
		||||
    {
 | 
			
		||||
        if (ulRC != NO_ERROR) {
 | 
			
		||||
            debug("Error: cannot find entry %s in %s", pszIconvClose, pszName);
 | 
			
		||||
          break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        debug("DLL %s used", pszName);
 | 
			
		||||
        return TRUE;
 | 
			
		||||
  }
 | 
			
		||||
  while( FALSE );
 | 
			
		||||
    } while (FALSE);
 | 
			
		||||
 | 
			
		||||
    DosFreeModule(hmIconv);
 | 
			
		||||
    hmIconv = NULLHANDLE;
 | 
			
		||||
    return FALSE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void _init()
 | 
			
		||||
static void _init(void)
 | 
			
		||||
{
 | 
			
		||||
  if ( fn_iconv_open != NULL )
 | 
			
		||||
    // Already was initialized.
 | 
			
		||||
    if (fn_iconv_open != NULL) /* Already was initialized */
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
  // Try to load kiconv.dll, iconv2.dll or iconv.dll.
 | 
			
		||||
  if ( !_loadDLL( "KICONV", "_libiconv_open", "_libiconv", "_libiconv_close" )
 | 
			
		||||
       && !_loadDLL( "ICONV2", "_libiconv_open", "_libiconv", "_libiconv_close" )
 | 
			
		||||
       && !_loadDLL( "ICONV", "_iconv_open", "_iconv", "_iconv_close" ) )
 | 
			
		||||
  {
 | 
			
		||||
    // No one DLL was loaded - use OS/2 conversion objects API.
 | 
			
		||||
 | 
			
		||||
    /* Try to load kiconv.dll, iconv2.dll or iconv.dll */
 | 
			
		||||
    if (!_loadDLL("KICONV", "_libiconv_open", "_libiconv", "_libiconv_close") &&
 | 
			
		||||
        !_loadDLL("ICONV2", "_libiconv_open", "_libiconv", "_libiconv_close") &&
 | 
			
		||||
        !_loadDLL("ICONV",  "_iconv_open",    "_iconv",    "_iconv_close") ) {
 | 
			
		||||
        /* No DLL was loaded - use OS/2 conversion objects API */
 | 
			
		||||
        debug("Uni*() API used");
 | 
			
		||||
        fn_iconv_open  = os2_iconv_open;
 | 
			
		||||
        fn_iconv       = os2_iconv;
 | 
			
		||||
@@ -129,14 +120,14 @@ static void _init()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//           Public routines.
 | 
			
		||||
//           ----------------
 | 
			
		||||
/* Public routines.
 | 
			
		||||
 * ----------------
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
// Non-standard function for iconv to unload the used dynamic library.
 | 
			
		||||
void libiconv_clean()
 | 
			
		||||
{
 | 
			
		||||
  if ( hmIconv != NULLHANDLE )
 | 
			
		||||
/* Non-standard function for iconv to unload the used dynamic library */
 | 
			
		||||
void libiconv_clean(void)
 | 
			
		||||
{
 | 
			
		||||
    if (hmIconv != NULLHANDLE) {
 | 
			
		||||
        DosFreeModule(hmIconv);
 | 
			
		||||
        hmIconv = NULLHANDLE;
 | 
			
		||||
 | 
			
		||||
@@ -162,3 +153,5 @@ int libiconv_close(iconv_t cd)
 | 
			
		||||
{
 | 
			
		||||
    return fn_iconv_close(cd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* vi: set ts=4 sw=4 expandtab: */
 | 
			
		||||
 
 | 
			
		||||
@@ -47,34 +47,39 @@
 | 
			
		||||
 | 
			
		||||
#define iconv_clean libiconv_clean
 | 
			
		||||
 | 
			
		||||
// Non-standard function for iconv to unload the used dynamic library.
 | 
			
		||||
void libiconv_clean();
 | 
			
		||||
/* Non-standard function for iconv to unload the used dynamic library */
 | 
			
		||||
void libiconv_clean(void);
 | 
			
		||||
 | 
			
		||||
iconv_t libiconv_open (const char *tocode, const char *fromcode);
 | 
			
		||||
int     libiconv_close(iconv_t cd);
 | 
			
		||||
size_t  libiconv      (iconv_t cd, char **inbuf, size_t *inbytesleft,
 | 
			
		||||
                       char **outbuf, size_t *outbytesleft);
 | 
			
		||||
int libiconv_close(iconv_t cd);
 | 
			
		||||
 | 
			
		||||
// System codepage <-> UTF-8.
 | 
			
		||||
 | 
			
		||||
// StrUTF8()
 | 
			
		||||
// Coverts string from system cp to UTF-8 (fToUTF8 is not 0) or from UTF-8 to
 | 
			
		||||
// the system cp (fToUTF8 is 0). Converted ASCIIZ string will be placed at the
 | 
			
		||||
// buffer pcDst, up to cbDst - 1 (for sys->utf8) or 2 (for utf8->sys) bytes.
 | 
			
		||||
// Returns the number of bytes written into pcDst, not counting the terminating
 | 
			
		||||
// 0 byte(s) or -1 on error.
 | 
			
		||||
/* System codepage <-> UTF-8
 | 
			
		||||
 *
 | 
			
		||||
 * StrUTF8()
 | 
			
		||||
 * Coverts string from system cp to UTF-8 (fToUTF8 is not 0) or from UTF-8 to
 | 
			
		||||
 * the system cp (fToUTF8 is 0). Converted ASCIIZ string will be placed at the
 | 
			
		||||
 * buffer pcDst, up to cbDst - 1 (for sys->utf8) or 2 (for utf8->sys) bytes.
 | 
			
		||||
 * Returns the number of bytes written into pcDst, not counting the terminating
 | 
			
		||||
 * 0 byte(s) or -1 on error.
 | 
			
		||||
 */
 | 
			
		||||
int StrUTF8(int fToUTF8, char *pcDst, int cbDst, char *pcSrc, int cbSrc);
 | 
			
		||||
 | 
			
		||||
// StrUTF8New()
 | 
			
		||||
// Coverts string from system cp to UTF-8 (fToUTF8 is not 0) or from UTF-8 to
 | 
			
		||||
// the system cp (fToUTF8 is 0). Memory for the new string is obtained by
 | 
			
		||||
// using libc malloc().
 | 
			
		||||
// Returns converted string, terminating two bytes 0 is appended to the result.
 | 
			
		||||
// Returns null on error.
 | 
			
		||||
/* StrUTF8New()
 | 
			
		||||
 * Coverts string from system cp to UTF-8 (fToUTF8 is not 0) or from UTF-8 to
 | 
			
		||||
 * the system cp (fToUTF8 is 0). Memory for the new string is obtained by
 | 
			
		||||
 * using libc malloc().
 | 
			
		||||
 * Returns converted string, terminating two bytes 0 is appended to the result.
 | 
			
		||||
 * Returns null on error.
 | 
			
		||||
 */
 | 
			
		||||
char *StrUTF8New(int fToUTF8, char *pcStr, int cbStr);
 | 
			
		||||
 | 
			
		||||
// StrUTF8Free()
 | 
			
		||||
// Deallocates the memory block located by StrUTF8New() (just libc free()).
 | 
			
		||||
/* StrUTF8Free()
 | 
			
		||||
 * Deallocates the memory block located by StrUTF8New() (just libc free()).
 | 
			
		||||
 */
 | 
			
		||||
void StrUTF8Free(char *pszStr);
 | 
			
		||||
 | 
			
		||||
#endif // GENICONV_H
 | 
			
		||||
#endif /* GENICONV_H */
 | 
			
		||||
 | 
			
		||||
/* vi: set ts=4 sw=4 expandtab: */
 | 
			
		||||
 
 | 
			
		||||
@@ -37,8 +37,7 @@ typedef struct _NAME2CP {
 | 
			
		||||
  ULONG ulCode;
 | 
			
		||||
} NAME2CP;
 | 
			
		||||
 | 
			
		||||
static CP2NAME		aCP2Name[] =
 | 
			
		||||
{
 | 
			
		||||
static CP2NAME aCP2Name[] = {
 | 
			
		||||
  {367, "ANSI_X3.4-1968"},
 | 
			
		||||
  {813, "ECMA-118"},
 | 
			
		||||
  {819, "CP819"},
 | 
			
		||||
@@ -85,8 +84,7 @@ static CP2NAME		aCP2Name[] =
 | 
			
		||||
  {62210, "HEBREW"}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static NAME2CP		aName2CP[] =
 | 
			
		||||
{
 | 
			
		||||
static NAME2CP aName2CP[] = {
 | 
			
		||||
  {"850", 850},
 | 
			
		||||
  {"862", 862},
 | 
			
		||||
  {"866", 866},
 | 
			
		||||
@@ -304,8 +302,7 @@ char * os2cpToName(unsigned long cp)
 | 
			
		||||
    ULONG ulNext;
 | 
			
		||||
    LONG  lFound = -1;
 | 
			
		||||
 | 
			
		||||
  if ( cp == SYSTEM_CP )
 | 
			
		||||
  {
 | 
			
		||||
    if (cp == SYSTEM_CP) {
 | 
			
		||||
        ULONG aulCP[3];
 | 
			
		||||
        ULONG cCP;
 | 
			
		||||
 | 
			
		||||
@@ -315,7 +312,7 @@ char * os2cpToName(unsigned long cp)
 | 
			
		||||
        cp = aulCP[0];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  if ( ( aCP2Name[0].ulCode > cp ) || ( aCP2Name[ulHi].ulCode < cp ) )
 | 
			
		||||
    if (aCP2Name[0].ulCode > cp || aCP2Name[ulHi].ulCode < cp)
 | 
			
		||||
        return NULL;
 | 
			
		||||
 | 
			
		||||
    if (aCP2Name[0].ulCode == cp)
 | 
			
		||||
@@ -324,22 +321,20 @@ char * os2cpToName(unsigned long cp)
 | 
			
		||||
    if (aCP2Name[ulHi].ulCode == cp)
 | 
			
		||||
        return aCP2Name[ulHi].pszName;
 | 
			
		||||
 | 
			
		||||
  while( ( ulHi - ulLo ) > 1 )
 | 
			
		||||
  {
 | 
			
		||||
    while ((ulHi - ulLo) > 1) {
 | 
			
		||||
        ulNext = (ulLo + ulHi) / 2;
 | 
			
		||||
 | 
			
		||||
        if (aCP2Name[ulNext].ulCode < cp)
 | 
			
		||||
            ulLo = ulNext;
 | 
			
		||||
        else if (aCP2Name[ulNext].ulCode > cp)
 | 
			
		||||
            ulHi = ulNext;
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        else {
 | 
			
		||||
            lFound = ulNext;
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  return lFound == -1 ? NULL : aCP2Name[lFound].pszName;
 | 
			
		||||
    return (lFound == -1)? NULL : aCP2Name[lFound].pszName;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
unsigned long os2cpFromName(char *cp)
 | 
			
		||||
@@ -352,15 +347,16 @@ unsigned long os2cpFromName(char *cp)
 | 
			
		||||
    PCHAR pcEnd;
 | 
			
		||||
    CHAR  acBuf[64];
 | 
			
		||||
 | 
			
		||||
  if ( cp == NULL )
 | 
			
		||||
  {
 | 
			
		||||
    if (cp == NULL) {
 | 
			
		||||
        ULONG aulCP[3];
 | 
			
		||||
        ULONG cCP;
 | 
			
		||||
 | 
			
		||||
    return DosQueryCp( sizeof(aulCP), aulCP, &cCP ) != NO_ERROR ? 0 : aulCP[0];
 | 
			
		||||
        return (DosQueryCp(sizeof(aulCP), aulCP, &cCP) != NO_ERROR)? 0 : aulCP[0];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  while( isspace( *cp ) ) cp++;
 | 
			
		||||
    while (isspace(*cp))
 | 
			
		||||
        cp++;
 | 
			
		||||
 | 
			
		||||
    pcEnd = strchr(cp, ' ');
 | 
			
		||||
    if (pcEnd == NULL)
 | 
			
		||||
        pcEnd = strchr(cp, '\0');
 | 
			
		||||
@@ -385,8 +381,7 @@ unsigned long os2cpFromName(char *cp)
 | 
			
		||||
    else if (lCmp == 0)
 | 
			
		||||
        return aName2CP[ulHi].ulCode;
 | 
			
		||||
 | 
			
		||||
  while( ( ulHi - ulLo ) > 1 )
 | 
			
		||||
  {
 | 
			
		||||
    while ((ulHi - ulLo) > 1) {
 | 
			
		||||
        ulNext = (ulLo + ulHi) / 2;
 | 
			
		||||
 | 
			
		||||
        lCmp = strcmp(aName2CP[ulNext].pszName, acBuf);
 | 
			
		||||
@@ -394,12 +389,13 @@ unsigned long os2cpFromName(char *cp)
 | 
			
		||||
            ulLo = ulNext;
 | 
			
		||||
        else if (lCmp > 0)
 | 
			
		||||
            ulHi = ulNext;
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        else {
 | 
			
		||||
            lFound = ulNext;
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  return lFound == -1 ? 0 : aName2CP[lFound].ulCode;
 | 
			
		||||
    return (lFound == -1)? 0 : aName2CP[lFound].ulCode;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* vi: set ts=4 sw=4 expandtab: */
 | 
			
		||||
 
 | 
			
		||||
@@ -27,4 +27,6 @@
 | 
			
		||||
char *os2cpToName(unsigned long cp);
 | 
			
		||||
unsigned long os2cpFromName(char *cp);
 | 
			
		||||
 | 
			
		||||
#endif // OS2CP_H
 | 
			
		||||
#endif /* OS2CP_H */
 | 
			
		||||
 | 
			
		||||
/* vi: set ts=4 sw=4 expandtab: */
 | 
			
		||||
 
 | 
			
		||||
@@ -60,12 +60,11 @@ static int _createUconvObj(const char *code, UconvObject *uobj)
 | 
			
		||||
 | 
			
		||||
    if (code == NULL)
 | 
			
		||||
        uc_code[0] = 0;
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    for( i = 0; i < MAX_CP_NAME_LEN; i++ )
 | 
			
		||||
    {
 | 
			
		||||
    else {
 | 
			
		||||
        for (i = 0; i < MAX_CP_NAME_LEN; i++) {
 | 
			
		||||
            uc_code[i] = (unsigned short)*ch;
 | 
			
		||||
      if ( !(*ch) ) break;
 | 
			
		||||
            if (! (*ch))
 | 
			
		||||
                break;
 | 
			
		||||
            ch++;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@@ -77,15 +76,13 @@ static int uconv_open(const char *code, UconvObject *uobj)
 | 
			
		||||
{
 | 
			
		||||
    int rc;
 | 
			
		||||
 | 
			
		||||
  if ( !stricmp( code, "UTF-16" ) )
 | 
			
		||||
  {
 | 
			
		||||
    if (!stricmp(code, "UTF-16")) {
 | 
			
		||||
        *uobj = NULL;
 | 
			
		||||
        return ULS_SUCCESS;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    rc = _createUconvObj(code, uobj);
 | 
			
		||||
  if ( rc != ULS_SUCCESS )
 | 
			
		||||
  {
 | 
			
		||||
    if (rc != ULS_SUCCESS) {
 | 
			
		||||
        unsigned long cp = os2cpFromName((char *)code);
 | 
			
		||||
        char cp_name[16];
 | 
			
		||||
 | 
			
		||||
@@ -110,24 +107,20 @@ extern iconv_t _System os2_iconv_open(const char* tocode, const char* fromcode)
 | 
			
		||||
    if (fromcode == NULL)
 | 
			
		||||
        fromcode = "";
 | 
			
		||||
 | 
			
		||||
  if ( stricmp(tocode, fromcode) != 0 )
 | 
			
		||||
  {
 | 
			
		||||
    if (stricmp(tocode, fromcode) != 0) {
 | 
			
		||||
        rc = uconv_open(fromcode, &uo_fromcode);
 | 
			
		||||
    if ( rc != ULS_SUCCESS )
 | 
			
		||||
    {
 | 
			
		||||
        if (rc != ULS_SUCCESS) {
 | 
			
		||||
            errno = EINVAL;
 | 
			
		||||
            return (iconv_t)(-1);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        rc = uconv_open(tocode, &uo_tocode);
 | 
			
		||||
    if ( rc != ULS_SUCCESS )
 | 
			
		||||
    {
 | 
			
		||||
        if (rc != ULS_SUCCESS) {
 | 
			
		||||
            UniFreeUconvObject(uo_fromcode);
 | 
			
		||||
            errno = EINVAL;
 | 
			
		||||
            return (iconv_t)(-1);
 | 
			
		||||
        }
 | 
			
		||||
  }
 | 
			
		||||
  else {
 | 
			
		||||
    } else {
 | 
			
		||||
        uo_tocode = NULL;
 | 
			
		||||
        uo_fromcode = NULL;
 | 
			
		||||
    }
 | 
			
		||||
@@ -158,8 +151,7 @@ extern size_t _System os2_iconv(iconv_t cd, char* * inbuf,
 | 
			
		||||
    int rc;
 | 
			
		||||
    size_t ret = (size_t)(-1);
 | 
			
		||||
 | 
			
		||||
  if ( uo_tocode == NULL && uo_fromcode == NULL )
 | 
			
		||||
  {
 | 
			
		||||
    if (uo_tocode == NULL && uo_fromcode == NULL) {
 | 
			
		||||
        uc_buf_len = min(*inbytesleft, *outbytesleft);
 | 
			
		||||
        memcpy(*outbuf, *inbuf, uc_buf_len);
 | 
			
		||||
        *inbytesleft -= uc_buf_len;
 | 
			
		||||
@@ -174,23 +166,19 @@ extern size_t _System os2_iconv(iconv_t cd, char* * inbuf,
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    if (uo_tocode && uo_fromcode &&
 | 
			
		||||
       (( ((iuconv_obj *)(cd))->buf_len >> 1 ) < (*inbytesleft)) )
 | 
			
		||||
  {
 | 
			
		||||
    if ( ( ((iuconv_obj *)(cd))->buf ) != NULL )
 | 
			
		||||
      free( ((iuconv_obj *)(cd))->buf );
 | 
			
		||||
    ((iuconv_obj *)(cd))->buf_len = *inbytesleft << 1;
 | 
			
		||||
    ((iuconv_obj *)(cd))->buf = (UniChar *)malloc( ((iuconv_obj *)(cd))->buf_len );
 | 
			
		||||
        (((iuconv_obj *)cd)->buf_len >> 1) < *inbytesleft) {
 | 
			
		||||
        if (((iuconv_obj *)cd)->buf != NULL)
 | 
			
		||||
            free(((iuconv_obj *)cd)->buf);
 | 
			
		||||
        ((iuconv_obj *)cd)->buf_len = *inbytesleft << 1;
 | 
			
		||||
        ((iuconv_obj *)cd)->buf = (UniChar *)malloc(((iuconv_obj *)cd)->buf_len);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  if ( uo_fromcode )
 | 
			
		||||
  {
 | 
			
		||||
    if ( uo_tocode )
 | 
			
		||||
    {
 | 
			
		||||
      uc_buf = ((iuconv_obj *)(cd))->buf;
 | 
			
		||||
      uc_buf_len = ((iuconv_obj *)(cd))->buf_len;
 | 
			
		||||
    if (uo_fromcode) {
 | 
			
		||||
        if (uo_tocode) {
 | 
			
		||||
            uc_buf = ((iuconv_obj *)cd)->buf;
 | 
			
		||||
            uc_buf_len = ((iuconv_obj *)cd)->buf_len;
 | 
			
		||||
            uc_str = &uc_buf;
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        } else {
 | 
			
		||||
            uc_str = (UniChar **)outbuf;
 | 
			
		||||
            uc_buf_len = *outbytesleft;
 | 
			
		||||
        }
 | 
			
		||||
@@ -202,14 +190,10 @@ extern size_t _System os2_iconv(iconv_t cd, char* * inbuf,
 | 
			
		||||
        if (!uo_tocode)
 | 
			
		||||
            *outbytesleft = uc_buf_len;
 | 
			
		||||
 | 
			
		||||
    if ( rc != ULS_SUCCESS )
 | 
			
		||||
    {
 | 
			
		||||
        if (rc != ULS_SUCCESS) {
 | 
			
		||||
            errno = EILSEQ;
 | 
			
		||||
            goto done;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
      if ( *inbytesleft && !*uc_str_len )
 | 
			
		||||
      {
 | 
			
		||||
        } else if (*inbytesleft && !*uc_str_len) {
 | 
			
		||||
            errno = E2BIG;
 | 
			
		||||
            goto done;
 | 
			
		||||
        }
 | 
			
		||||
@@ -217,12 +201,11 @@ extern size_t _System os2_iconv(iconv_t cd, char* * inbuf,
 | 
			
		||||
        if (!uo_tocode)
 | 
			
		||||
            return nonIdenticalConv;
 | 
			
		||||
 | 
			
		||||
    uc_buf = ((iuconv_obj *)(cd))->buf;
 | 
			
		||||
    uc_buf_len = ((iuconv_obj *)(cd))->buf_len - uc_buf_len;
 | 
			
		||||
        uc_buf = ((iuconv_obj *)cd)->buf;
 | 
			
		||||
        uc_buf_len = ((iuconv_obj *)cd)->buf_len - uc_buf_len;
 | 
			
		||||
        uc_str = &uc_buf;
 | 
			
		||||
        uc_str_len = &uc_buf_len;
 | 
			
		||||
  }
 | 
			
		||||
  else {
 | 
			
		||||
    } else {
 | 
			
		||||
        uc_str = (UniChar **)inbuf;
 | 
			
		||||
        uc_str_len = inbytesleft;
 | 
			
		||||
    }
 | 
			
		||||
@@ -230,10 +213,8 @@ extern size_t _System os2_iconv(iconv_t cd, char* * inbuf,
 | 
			
		||||
    *uc_str_len = *uc_str_len>>1;
 | 
			
		||||
    rc = UniUconvFromUcs(uo_tocode, uc_str, uc_str_len, (void **)outbuf,
 | 
			
		||||
                         outbytesleft, &nonIdenticalConv);
 | 
			
		||||
  if ( rc != ULS_SUCCESS )
 | 
			
		||||
  {
 | 
			
		||||
    switch ( rc )
 | 
			
		||||
    {
 | 
			
		||||
    if (rc != ULS_SUCCESS) {
 | 
			
		||||
        switch (rc) {
 | 
			
		||||
        case ULS_BUFFERFULL:
 | 
			
		||||
            errno = E2BIG;
 | 
			
		||||
            break;
 | 
			
		||||
@@ -245,10 +226,7 @@ extern size_t _System os2_iconv(iconv_t cd, char* * inbuf,
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
        goto done;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
    if ( *uc_str_len && !*outbytesleft )
 | 
			
		||||
    {
 | 
			
		||||
    } else if (*uc_str_len && !*outbytesleft) {
 | 
			
		||||
        errno = E2BIG;
 | 
			
		||||
        goto done;
 | 
			
		||||
    }
 | 
			
		||||
@@ -258,28 +236,29 @@ extern size_t _System os2_iconv(iconv_t cd, char* * inbuf,
 | 
			
		||||
done:
 | 
			
		||||
 | 
			
		||||
#ifdef ICONV_THREAD_SAFE
 | 
			
		||||
  DosReleaseMutexSem( ((iuconv_obj *)(cd))->hMtx );
 | 
			
		||||
    DosReleaseMutexSem(((iuconv_obj *)cd)->hMtx);
 | 
			
		||||
#endif
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern int _System os2_iconv_close(iconv_t cd)
 | 
			
		||||
int _System os2_iconv_close(iconv_t cd)
 | 
			
		||||
{
 | 
			
		||||
  if ( !cd )
 | 
			
		||||
    return 0;
 | 
			
		||||
    if (!cd) return 0;
 | 
			
		||||
 | 
			
		||||
#ifdef ICONV_THREAD_SAFE
 | 
			
		||||
  DosCloseMutexSem( ((iuconv_obj *)(cd))->hMtx );
 | 
			
		||||
    DosCloseMutexSem(((iuconv_obj *)cd)->hMtx);
 | 
			
		||||
#endif
 | 
			
		||||
  if ( ((iuconv_obj *)(cd))->uo_tocode != NULL )
 | 
			
		||||
    UniFreeUconvObject( ((iuconv_obj *)(cd))->uo_tocode );
 | 
			
		||||
  if ( ((iuconv_obj *)(cd))->uo_fromcode != NULL )
 | 
			
		||||
    UniFreeUconvObject( ((iuconv_obj *)(cd))->uo_fromcode );
 | 
			
		||||
    if (((iuconv_obj *)cd)->uo_tocode != NULL)
 | 
			
		||||
        UniFreeUconvObject(((iuconv_obj *)cd)->uo_tocode);
 | 
			
		||||
    if (((iuconv_obj *)cd)->uo_fromcode != NULL)
 | 
			
		||||
        UniFreeUconvObject(((iuconv_obj *)cd)->uo_fromcode);
 | 
			
		||||
 | 
			
		||||
  if ( ( ((iuconv_obj *)(cd))->buf ) != NULL )
 | 
			
		||||
    free( ((iuconv_obj *)(cd))->buf );
 | 
			
		||||
    if (((iuconv_obj *)cd)->buf != NULL)
 | 
			
		||||
        free(((iuconv_obj *)cd)->buf);
 | 
			
		||||
 | 
			
		||||
    free(cd);
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* vi: set ts=4 sw=4 expandtab: */
 | 
			
		||||
 
 | 
			
		||||
@@ -33,13 +33,10 @@ int StrUTF8(int fToUTF8, char *pcDst, int cbDst, char *pcSrc, int cbSrc)
 | 
			
		||||
    if (cbDst < 4)
 | 
			
		||||
        return -1;
 | 
			
		||||
 | 
			
		||||
  if ( fToUTF8 )
 | 
			
		||||
  {
 | 
			
		||||
    if (fToUTF8) {
 | 
			
		||||
        pszToCP   = "UTF-8";
 | 
			
		||||
        pszFromCP = "";
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    } else {
 | 
			
		||||
        pszToCP   = "";
 | 
			
		||||
        pszFromCP = "UTF-8";
 | 
			
		||||
    }
 | 
			
		||||
@@ -48,14 +45,11 @@ int StrUTF8(int fToUTF8, char *pcDst, int cbDst, char *pcSrc, int cbSrc)
 | 
			
		||||
    if (cd == (iconv_t)-1)
 | 
			
		||||
        return -1;
 | 
			
		||||
 | 
			
		||||
  while( cbSrc > 0 )
 | 
			
		||||
  {
 | 
			
		||||
    while (cbSrc > 0) {
 | 
			
		||||
        rc = iconv(cd, &pcSrc, (size_t *)&cbSrc, &pcDst, (size_t *)&cbDst);
 | 
			
		||||
    if ( rc == (size_t)-1 )
 | 
			
		||||
    {
 | 
			
		||||
      if ( errno == EILSEQ )
 | 
			
		||||
      {
 | 
			
		||||
        // Try to skip invalid character.
 | 
			
		||||
        if (rc == (size_t)-1) {
 | 
			
		||||
            if (errno == EILSEQ) {
 | 
			
		||||
                /* Try to skip invalid character */
 | 
			
		||||
                pcSrc++;
 | 
			
		||||
                cbSrc--;
 | 
			
		||||
                continue;
 | 
			
		||||
@@ -68,41 +62,35 @@ int StrUTF8(int fToUTF8, char *pcDst, int cbDst, char *pcSrc, int cbSrc)
 | 
			
		||||
 | 
			
		||||
    iconv_close(cd);
 | 
			
		||||
 | 
			
		||||
  // Write trailing ZERO (1 byte for UTF-8, 2 bytes for the system cp).
 | 
			
		||||
  if ( fToUTF8 )
 | 
			
		||||
  {
 | 
			
		||||
    if ( cbDst < 1 )
 | 
			
		||||
    {
 | 
			
		||||
    /* Write trailing ZERO (1 byte for UTF-8, 2 bytes for the system cp) */
 | 
			
		||||
    if (fToUTF8) {
 | 
			
		||||
        if (cbDst < 1) {
 | 
			
		||||
            pcDst--;
 | 
			
		||||
      fError = 1;      // The destination buffer overflow.
 | 
			
		||||
            fError = 1; /* The destination buffer overflow */
 | 
			
		||||
        }
 | 
			
		||||
        *pcDst = '\0';
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    if ( cbDst < 2 )
 | 
			
		||||
    {
 | 
			
		||||
    } else {
 | 
			
		||||
        if (cbDst < 2) {
 | 
			
		||||
            pcDst -= (cbDst == 0)? 2 : 1;
 | 
			
		||||
      fError = 1;      // The destination buffer overflow.
 | 
			
		||||
            fError = 1; /* The destination buffer overflow */
 | 
			
		||||
        }
 | 
			
		||||
        *((short *)pcDst) = '\0';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  return fError ? -1 : ( pcDst - pcDstStart );
 | 
			
		||||
    return (fError) ? -1 : (pcDst - pcDstStart);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
char *StrUTF8New(int fToUTF8, char *pcStr, int cbStr)
 | 
			
		||||
{
 | 
			
		||||
  int        cbNewStr = ( ( cbStr > 4 ? cbStr : 4 ) + 1 ) * 2;
 | 
			
		||||
    int   cbNewStr = (((cbStr > 4)? cbStr : 4) + 1) * 2;
 | 
			
		||||
    char *pszNewStr = malloc(cbNewStr);
 | 
			
		||||
 | 
			
		||||
    if (pszNewStr == NULL)
 | 
			
		||||
        return NULL;
 | 
			
		||||
 | 
			
		||||
    cbNewStr = StrUTF8(fToUTF8, pszNewStr, cbNewStr, pcStr, cbStr);
 | 
			
		||||
  if ( cbNewStr != -1 )
 | 
			
		||||
  {
 | 
			
		||||
    pcStr = realloc( pszNewStr, cbNewStr + ( fToUTF8 ? 1 : sizeof(short) ) );
 | 
			
		||||
    if (cbNewStr != -1) {
 | 
			
		||||
        pcStr = realloc(pszNewStr, cbNewStr + ((fToUTF8)? 1 : sizeof(short)));
 | 
			
		||||
        if (pcStr != NULL)
 | 
			
		||||
            return pcStr;
 | 
			
		||||
    }
 | 
			
		||||
@@ -115,3 +103,5 @@ void StrUTF8Free(char *pszStr)
 | 
			
		||||
{
 | 
			
		||||
    free(pszStr);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* vi: set ts=4 sw=4 expandtab: */
 | 
			
		||||
 
 | 
			
		||||
@@ -27,42 +27,43 @@
 | 
			
		||||
int main(void)
 | 
			
		||||
{
 | 
			
		||||
    char    acBuf[128];
 | 
			
		||||
  char       *inbuf = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"; // KOI8-R string.
 | 
			
		||||
    char   *inbuf = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"; /* KOI8-R string */
 | 
			
		||||
    size_t  inbytesleft = strlen(inbuf);
 | 
			
		||||
  char       *outbuf = &acBuf;
 | 
			
		||||
    char   *outbuf = acBuf;
 | 
			
		||||
    size_t  outbytesleft = sizeof(acBuf);
 | 
			
		||||
    iconv_t ic;
 | 
			
		||||
 | 
			
		||||
  // KOI8 -> system cp.
 | 
			
		||||
 | 
			
		||||
    /* KOI8 -> system cp */
 | 
			
		||||
    ic = iconv_open("", "KOI8-R");
 | 
			
		||||
  if ( ic == (iconv_t)(-1) )
 | 
			
		||||
  {
 | 
			
		||||
    if (ic == (iconv_t)(-1)) {
 | 
			
		||||
        puts("iconv_open() fail");
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    iconv(ic, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
 | 
			
		||||
  printf( "KOI8-R to system cp.: %s\n", &acBuf );
 | 
			
		||||
    printf("KOI8-R to system cp: %s\n", acBuf);
 | 
			
		||||
 | 
			
		||||
    iconv_close(ic);
 | 
			
		||||
 | 
			
		||||
  // System cp. -> UTF-8 -> system cp.
 | 
			
		||||
    /* System cp -> UTF-8 -> system cp: */
 | 
			
		||||
 | 
			
		||||
  // System cp. -> UTF-8 by StrUTF8New().
 | 
			
		||||
  inbuf = StrUTF8New( 1, &acBuf, strlen( &acBuf ) );
 | 
			
		||||
    /* System cp -> UTF-8 by StrUTF8New() */
 | 
			
		||||
    inbuf = StrUTF8New(1, acBuf, strlen(acBuf));
 | 
			
		||||
 | 
			
		||||
  // UTF-8 -> system cp. by StrUTF8().
 | 
			
		||||
  if ( StrUTF8( 0, &acBuf, sizeof(acBuf), inbuf, strlen( inbuf ) ) == -1 )
 | 
			
		||||
    /* UTF-8 -> system cp. by StrUTF8() */
 | 
			
		||||
    if (StrUTF8(0, &acBuf, sizeof(acBuf), inbuf, strlen(inbuf)) == -1) {
 | 
			
		||||
        puts("StrUTF8() failed");
 | 
			
		||||
  else
 | 
			
		||||
    } else {
 | 
			
		||||
        printf("system cp. -> UTF-8 -> system cp.: %s\n", &acBuf);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    free(inbuf);
 | 
			
		||||
 | 
			
		||||
  // Unload used DLL.
 | 
			
		||||
    /* Unload used DLL */
 | 
			
		||||
    iconv_clean();
 | 
			
		||||
 | 
			
		||||
    puts("Done.");
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* vi: set ts=4 sw=4 expandtab: */
 | 
			
		||||
 
 | 
			
		||||
@@ -46,7 +46,7 @@ SDL_GetBasePath(void)
 | 
			
		||||
    CHAR    acBuf[_MAX_PATH];
 | 
			
		||||
 | 
			
		||||
    if (ulRC != NO_ERROR) {
 | 
			
		||||
    debug("DosGetInfoBlocks() failed, rc = %u", ulRC);
 | 
			
		||||
        debug_os2("DosGetInfoBlocks() failed, rc = %u", ulRC);
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -68,9 +68,10 @@ SDL_LoadFunction(void *handle, const char *name)
 | 
			
		||||
void
 | 
			
		||||
SDL_UnloadObject(void *handle)
 | 
			
		||||
{
 | 
			
		||||
  if (handle != NULL)
 | 
			
		||||
    if (handle != NULL) {
 | 
			
		||||
        DosFreeModule((HMODULE)handle);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif /* SDL_LOADSO_OS2 */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -32,9 +32,8 @@
 | 
			
		||||
#define INCL_DOSERRORS
 | 
			
		||||
#include <os2.h>
 | 
			
		||||
 | 
			
		||||
struct SDL_mutex
 | 
			
		||||
{
 | 
			
		||||
  ULONG      ulHandle;
 | 
			
		||||
struct SDL_mutex {
 | 
			
		||||
    HMTX  _handle;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* Create a mutex */
 | 
			
		||||
@@ -45,9 +44,8 @@ SDL_CreateMutex(void)
 | 
			
		||||
    HMTX  hMtx;
 | 
			
		||||
 | 
			
		||||
    ulRC = DosCreateMutexSem(NULL, &hMtx, 0, FALSE);
 | 
			
		||||
  if ( ulRC != NO_ERROR )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "DosCreateMutexSem(), rc = %u", ulRC );
 | 
			
		||||
    if (ulRC != NO_ERROR) {
 | 
			
		||||
        debug_os2("DosCreateMutexSem(), rc = %u", ulRC);
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -62,8 +60,9 @@ SDL_DestroyMutex(SDL_mutex * mutex)
 | 
			
		||||
    HMTX  hMtx = (HMTX)mutex;
 | 
			
		||||
 | 
			
		||||
    ulRC = DosCloseMutexSem(hMtx);
 | 
			
		||||
  if ( ulRC != NO_ERROR )
 | 
			
		||||
    debug( "DosCloseMutexSem(), rc = %u", ulRC );
 | 
			
		||||
    if (ulRC != NO_ERROR) {
 | 
			
		||||
        debug_os2("DosCloseMutexSem(), rc = %u", ulRC);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Lock the mutex */
 | 
			
		||||
@@ -77,9 +76,8 @@ SDL_LockMutex(SDL_mutex * mutex)
 | 
			
		||||
        return SDL_SetError("Passed a NULL mutex");
 | 
			
		||||
 | 
			
		||||
    ulRC = DosRequestMutexSem(hMtx, SEM_INDEFINITE_WAIT);
 | 
			
		||||
  if ( ulRC != NO_ERROR )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "DosRequestMutexSem(), rc = %u", ulRC );
 | 
			
		||||
    if (ulRC != NO_ERROR) {
 | 
			
		||||
      debug_os2("DosRequestMutexSem(), rc = %u", ulRC);
 | 
			
		||||
      return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -101,9 +99,8 @@ SDL_TryLockMutex(SDL_mutex * mutex)
 | 
			
		||||
    if (ulRC == ERROR_TIMEOUT)
 | 
			
		||||
        return SDL_MUTEX_TIMEDOUT;
 | 
			
		||||
 | 
			
		||||
  if ( ulRC != NO_ERROR )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "DosRequestMutexSem(), rc = %u", ulRC );
 | 
			
		||||
    if (ulRC != NO_ERROR) {
 | 
			
		||||
        debug_os2("DosRequestMutexSem(), rc = %u", ulRC);
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -45,24 +45,21 @@ SDL_CreateSemaphore(Uint32 initial_value)
 | 
			
		||||
    ULONG ulRC;
 | 
			
		||||
    SDL_sem *pSDLSem = SDL_malloc(sizeof(SDL_sem));
 | 
			
		||||
 | 
			
		||||
  if ( pSDLSem == NULL )
 | 
			
		||||
  {
 | 
			
		||||
    if (pSDLSem == NULL) {
 | 
			
		||||
        SDL_OutOfMemory();
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ulRC = DosCreateEventSem(NULL, &pSDLSem->hEv, DCE_AUTORESET, FALSE);
 | 
			
		||||
  if ( ulRC != NO_ERROR )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "DosCreateEventSem(), rc = %u", ulRC );
 | 
			
		||||
    if (ulRC != NO_ERROR) {
 | 
			
		||||
        debug_os2("DosCreateEventSem(), rc = %u", ulRC);
 | 
			
		||||
        SDL_free(pSDLSem);
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ulRC = DosCreateMutexSem(NULL, &pSDLSem->hMtx, 0, FALSE);
 | 
			
		||||
  if ( ulRC != NO_ERROR )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "DosCreateMutexSem(), rc = %u", ulRC );
 | 
			
		||||
    if (ulRC != NO_ERROR) {
 | 
			
		||||
        debug_os2("DosCreateMutexSem(), rc = %u", ulRC);
 | 
			
		||||
        DosCloseEventSem(pSDLSem->hEv);
 | 
			
		||||
        SDL_free(pSDLSem);
 | 
			
		||||
        return NULL;
 | 
			
		||||
@@ -76,8 +73,7 @@ SDL_CreateSemaphore(Uint32 initial_value)
 | 
			
		||||
void
 | 
			
		||||
SDL_DestroySemaphore(SDL_sem * sem)
 | 
			
		||||
{
 | 
			
		||||
  if ( sem == NULL )
 | 
			
		||||
    return;
 | 
			
		||||
    if (!sem) return;
 | 
			
		||||
 | 
			
		||||
    DosCloseMutexSem(sem->hMtx);
 | 
			
		||||
    DosCloseEventSem(sem->hEv);
 | 
			
		||||
@@ -98,8 +94,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
 | 
			
		||||
    if (timeout != SEM_INDEFINITE_WAIT)
 | 
			
		||||
        DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &ulStartTime, sizeof(ULONG));
 | 
			
		||||
 | 
			
		||||
  while( TRUE )
 | 
			
		||||
  {
 | 
			
		||||
    while (TRUE) {
 | 
			
		||||
        ulRC = DosRequestMutexSem(sem->hMtx, SEM_INDEFINITE_WAIT);
 | 
			
		||||
        if (ulRC != NO_ERROR)
 | 
			
		||||
            return SDL_SetError("DosRequestMutexSem() failed, rc = %u", ulRC);
 | 
			
		||||
@@ -115,8 +110,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
 | 
			
		||||
 | 
			
		||||
        if (timeout == SEM_INDEFINITE_WAIT)
 | 
			
		||||
            ulTimeout = SEM_INDEFINITE_WAIT;
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        else {
 | 
			
		||||
            DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &ulCurTime, sizeof(ULONG));
 | 
			
		||||
            ulTimeout = ulCurTime - ulStartTime;
 | 
			
		||||
            if (timeout < ulTimeout)
 | 
			
		||||
@@ -152,8 +146,7 @@ SDL_SemValue(SDL_sem * sem)
 | 
			
		||||
{
 | 
			
		||||
    ULONG ulRC;
 | 
			
		||||
 | 
			
		||||
  if ( sem == NULL )
 | 
			
		||||
  {
 | 
			
		||||
    if (sem == NULL) {
 | 
			
		||||
        SDL_SetError("Passed a NULL sem");
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
@@ -183,8 +176,9 @@ SDL_SemPost(SDL_sem * sem)
 | 
			
		||||
    sem->cPost++;
 | 
			
		||||
 | 
			
		||||
    ulRC = DosPostEventSem(sem->hEv);
 | 
			
		||||
  if ( ( ulRC != NO_ERROR ) && ( ulRC != ERROR_ALREADY_POSTED ) )
 | 
			
		||||
    debug( "DosPostEventSem() failed, rc = %u", ulRC );
 | 
			
		||||
    if (ulRC != NO_ERROR && ulRC != ERROR_ALREADY_POSTED) {
 | 
			
		||||
        debug_os2("DosPostEventSem() failed, rc = %u", ulRC);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    DosReleaseMutexSem(sem->hMtx);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -63,13 +63,12 @@ SDL_SYS_CreateThread(SDL_Thread * thread,
 | 
			
		||||
        thread->stacksize = 65536;
 | 
			
		||||
 | 
			
		||||
    if (pfnBeginThread) {
 | 
			
		||||
    // Save the function which we will have to call to clear the RTL of calling app!
 | 
			
		||||
        /* Save the function which we will have to call to clear the RTL of calling app! */
 | 
			
		||||
        thread->endfunc = pfnEndThread;
 | 
			
		||||
    // Start the thread using the runtime library of calling app!
 | 
			
		||||
        /* Start the thread using the runtime library of calling app! */
 | 
			
		||||
        thread->handle = (SYS_ThreadHandle)
 | 
			
		||||
                            pfnBeginThread(RunThread, NULL, thread->stacksize, thread);
 | 
			
		||||
  }
 | 
			
		||||
  else {
 | 
			
		||||
    } else {
 | 
			
		||||
        thread->endfunc = _endthread;
 | 
			
		||||
        thread->handle = (SYS_ThreadHandle)
 | 
			
		||||
                            _beginthread(RunThread, NULL, thread->stacksize, thread);
 | 
			
		||||
@@ -84,7 +83,7 @@ SDL_SYS_CreateThread(SDL_Thread * thread,
 | 
			
		||||
void
 | 
			
		||||
SDL_SYS_SetupThread(const char *name)
 | 
			
		||||
{
 | 
			
		||||
    return;
 | 
			
		||||
    /* nothing. */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
SDL_threadID
 | 
			
		||||
@@ -118,8 +117,9 @@ SDL_SYS_WaitThread(SDL_Thread * thread)
 | 
			
		||||
{
 | 
			
		||||
    ULONG ulRC = DosWaitThread((PTID)&thread->handle, DCWW_WAIT);
 | 
			
		||||
 | 
			
		||||
  if ( ulRC != NO_ERROR )
 | 
			
		||||
    debug( "DosWaitThread() failed, rc = %u", ulRC );
 | 
			
		||||
    if (ulRC != NO_ERROR) {
 | 
			
		||||
        debug_os2("DosWaitThread() failed, rc = %u", ulRC);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
 
 | 
			
		||||
@@ -36,48 +36,48 @@ SDL_TLSData     **ppSDLTLSData = NULL;
 | 
			
		||||
 | 
			
		||||
static ULONG  cTLSAlloc = 0;
 | 
			
		||||
 | 
			
		||||
// SDL_OS2TLSAlloc() called from SDL_InitSubSystem()
 | 
			
		||||
void SDL_OS2TLSAlloc()
 | 
			
		||||
/* SDL_OS2TLSAlloc() called from SDL_InitSubSystem() */
 | 
			
		||||
void SDL_OS2TLSAlloc(void)
 | 
			
		||||
{
 | 
			
		||||
    ULONG ulRC;
 | 
			
		||||
 | 
			
		||||
  if ( ( cTLSAlloc == 0 ) || ( ppSDLTLSData == NULL ) )
 | 
			
		||||
  {
 | 
			
		||||
    // First call - allocate the thread local memory (1 DWORD).
 | 
			
		||||
    if (cTLSAlloc == 0 || ppSDLTLSData == NULL) {
 | 
			
		||||
        /* First call - allocate the thread local memory (1 DWORD) */
 | 
			
		||||
        ulRC = DosAllocThreadLocalMemory(1, (PULONG *)&ppSDLTLSData);
 | 
			
		||||
    if ( ulRC != NO_ERROR )
 | 
			
		||||
      debug( "DosAllocThreadLocalMemory() failed, rc = %u", ulRC );
 | 
			
		||||
        if (ulRC != NO_ERROR) {
 | 
			
		||||
            debug_os2("DosAllocThreadLocalMemory() failed, rc = %u", ulRC);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    cTLSAlloc++;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SDL_OS2TLSFree() called from SDL_QuitSubSystem()
 | 
			
		||||
void SDL_OS2TLSFree()
 | 
			
		||||
/* SDL_OS2TLSFree() called from SDL_QuitSubSystem() */
 | 
			
		||||
void SDL_OS2TLSFree(void)
 | 
			
		||||
{
 | 
			
		||||
    ULONG ulRC;
 | 
			
		||||
 | 
			
		||||
    if (cTLSAlloc != 0)
 | 
			
		||||
        cTLSAlloc--;
 | 
			
		||||
 | 
			
		||||
  if ( ( cTLSAlloc == 0 ) && ( ppSDLTLSData != NULL ) )
 | 
			
		||||
  {
 | 
			
		||||
    // Last call - free the thread local memory.
 | 
			
		||||
    if (cTLSAlloc == 0 && ppSDLTLSData != NULL) {
 | 
			
		||||
        /* Last call - free the thread local memory */
 | 
			
		||||
        ulRC = DosFreeThreadLocalMemory((PULONG)ppSDLTLSData);
 | 
			
		||||
    if ( ulRC != NO_ERROR )
 | 
			
		||||
      debug( "DosFreeThreadLocalMemory() failed, rc = %u", ulRC );
 | 
			
		||||
    else
 | 
			
		||||
        if (ulRC != NO_ERROR) {
 | 
			
		||||
            debug_os2("DosFreeThreadLocalMemory() failed, rc = %u", ulRC);
 | 
			
		||||
        } else {
 | 
			
		||||
            ppSDLTLSData = NULL;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
SDL_TLSData *SDL_SYS_GetTLSData()
 | 
			
		||||
SDL_TLSData *SDL_SYS_GetTLSData(void)
 | 
			
		||||
{
 | 
			
		||||
  return ppSDLTLSData == NULL ? NULL : *ppSDLTLSData;
 | 
			
		||||
    return (ppSDLTLSData == NULL)? NULL : *ppSDLTLSData;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int SDL_SYS_SetTLSData(SDL_TLSData *data)
 | 
			
		||||
{
 | 
			
		||||
  if ( ppSDLTLSData == NULL )
 | 
			
		||||
    if (!ppSDLTLSData)
 | 
			
		||||
        return -1;
 | 
			
		||||
 | 
			
		||||
    *ppSDLTLSData = data;
 | 
			
		||||
 
 | 
			
		||||
@@ -27,11 +27,11 @@
 | 
			
		||||
 | 
			
		||||
extern SDL_TLSData **ppSDLTLSData;
 | 
			
		||||
 | 
			
		||||
// SDL_OS2TLSAlloc() called from SDL_InitSubSystem()
 | 
			
		||||
void SDL_OS2TLSAlloc();
 | 
			
		||||
/* SDL_OS2TLSAlloc() called from SDL_InitSubSystem() */
 | 
			
		||||
void SDL_OS2TLSAlloc(void);
 | 
			
		||||
 | 
			
		||||
// SDL_OS2TLSFree() called from SDL_QuitSubSystem()
 | 
			
		||||
void SDL_OS2TLSFree();
 | 
			
		||||
/* SDL_OS2TLSFree() called from SDL_QuitSubSystem() */
 | 
			
		||||
void SDL_OS2TLSFree(void);
 | 
			
		||||
 | 
			
		||||
#endif /* SDL_THREAD_OS2 */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -34,8 +34,8 @@
 | 
			
		||||
#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;
 | 
			
		||||
 | 
			
		||||
@@ -48,23 +48,17 @@ SDL_TicksInit(void)
 | 
			
		||||
    ULONG   ulRC;
 | 
			
		||||
 | 
			
		||||
    ulRC = DosTmrQueryFreq(&ulTmrFreq);
 | 
			
		||||
  if ( ulRC != NO_ERROR )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "DosTmrQueryFreq() failed, rc = %u", ulRC );
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    if (ulRC != NO_ERROR) {
 | 
			
		||||
        debug_os2("DosTmrQueryFreq() failed, rc = %u", ulRC);
 | 
			
		||||
    } else {
 | 
			
		||||
        ulRC = DosTmrQueryTime((PQWORD)&ullTmrStart);
 | 
			
		||||
        if (ulRC == NO_ERROR)
 | 
			
		||||
            return;
 | 
			
		||||
 | 
			
		||||
    debug( "DosTmrQueryTime() failed, rc = %u", ulRC );
 | 
			
		||||
        debug_os2("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
 | 
			
		||||
@@ -78,19 +72,14 @@ SDL_GetTicks(void)
 | 
			
		||||
    ULONG   ulResult;
 | 
			
		||||
    ULLONG  ullTmrNow;
 | 
			
		||||
 | 
			
		||||
  if ( ulTmrFreq == 0 )
 | 
			
		||||
    // Was not initialized.
 | 
			
		||||
    if (ulTmrFreq == 0) /* Was not initialized. */
 | 
			
		||||
        SDL_TicksInit();
 | 
			
		||||
 | 
			
		||||
  if ( ulTmrFreq != 0 )
 | 
			
		||||
  {
 | 
			
		||||
    if (ulTmrFreq != 0) {
 | 
			
		||||
        DosTmrQueryTime((PQWORD)&ullTmrNow);
 | 
			
		||||
        ulResult = (ullTmrNow - ullTmrStart) * 1000 / ulTmrFreq;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    DosQuerySysInfo( QSV_MS_COUNT, QSV_MS_COUNT, (PULONG)&ullTmrNow,
 | 
			
		||||
                     sizeof(ULONG) );
 | 
			
		||||
    } else {
 | 
			
		||||
        DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, (PULONG)&ullTmrNow, sizeof(ULONG));
 | 
			
		||||
        ulResult = (ULONG)ullTmrNow - (ULONG)ullTmrStart;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -102,7 +91,7 @@ SDL_GetPerformanceCounter(void)
 | 
			
		||||
{
 | 
			
		||||
    QWORD   qwTmrNow;
 | 
			
		||||
 | 
			
		||||
  if ( ( ulTmrFreq == 0 ) || ( DosTmrQueryTime( &qwTmrNow ) != NO_ERROR ) )
 | 
			
		||||
    if (ulTmrFreq == 0 || (DosTmrQueryTime(&qwTmrNow) != NO_ERROR))
 | 
			
		||||
        return SDL_GetTicks();
 | 
			
		||||
 | 
			
		||||
    return *((Uint64 *)&qwTmrNow);
 | 
			
		||||
@@ -111,7 +100,7 @@ SDL_GetPerformanceCounter(void)
 | 
			
		||||
Uint64
 | 
			
		||||
SDL_GetPerformanceFrequency(void)
 | 
			
		||||
{
 | 
			
		||||
  return ulTmrFreq == 0 ? 1000 : (Uint64)ulTmrFreq;
 | 
			
		||||
    return (ulTmrFreq == 0)? 1000 : (Uint64)ulTmrFreq;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
@@ -128,55 +117,50 @@ SDL_Delay(Uint32 ms)
 | 
			
		||||
#endif
 | 
			
		||||
    HEV     hevTimer;
 | 
			
		||||
 | 
			
		||||
  if ( ms == 0 )
 | 
			
		||||
  {
 | 
			
		||||
    if (ms == 0) {
 | 
			
		||||
      DosSleep(0);
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ulRC = DosCreateEventSem(NULL, &hevTimer, DC_SEM_SHARED, FALSE);
 | 
			
		||||
  if ( ulRC != NO_ERROR )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "DosAsyncTimer() failed, rc = %u", ulRC );
 | 
			
		||||
    if (ulRC != NO_ERROR) {
 | 
			
		||||
        debug_os2("DosAsyncTimer() failed, rc = %u", ulRC);
 | 
			
		||||
        DosSleep(ms);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
#ifdef _SWITCH_PRIORITY
 | 
			
		||||
  if ( fSetPriority )
 | 
			
		||||
  {
 | 
			
		||||
    if (fSetPriority) {
 | 
			
		||||
        if (DosGetInfoBlocks(&tib, &pib) != NO_ERROR)
 | 
			
		||||
            fSetPriority = FALSE;
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        else {
 | 
			
		||||
            ulSavePriority = tib->tib_ptib2->tib2_ulpri;
 | 
			
		||||
      if ( ( (ulSavePriority & 0xFF00) == 0x0300 ) ||  // already have high pr.
 | 
			
		||||
            if (((ulSavePriority & 0xFF00) == 0x0300) || /* already have high pr. */
 | 
			
		||||
                  (DosEnterMustComplete( &ulNesting) != NO_ERROR))
 | 
			
		||||
                fSetPriority = FALSE;
 | 
			
		||||
      else
 | 
			
		||||
            else {
 | 
			
		||||
                DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    DosResetEventSem(hevTimer, &ulRC);
 | 
			
		||||
    ulRC = DosAsyncTimer(ms, (HSEM)hevTimer, &hTimer);
 | 
			
		||||
 | 
			
		||||
#ifdef _SWITCH_PRIORITY
 | 
			
		||||
  if ( fSetPriority )
 | 
			
		||||
  {
 | 
			
		||||
    if ( DosSetPriority( PRTYS_THREAD, (ulSavePriority >> 8) & 0xFF, 0, 0 ) ==
 | 
			
		||||
           NO_ERROR )
 | 
			
		||||
    if (fSetPriority) {
 | 
			
		||||
        if (DosSetPriority(PRTYS_THREAD, (ulSavePriority >> 8) & 0xFF, 0, 0) == NO_ERROR)
 | 
			
		||||
            DosSetPriority(PRTYS_THREAD, 0, ulSavePriority & 0xFF, 0);
 | 
			
		||||
 | 
			
		||||
        DosExitMustComplete(&ulNesting);
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
  if ( ulRC != NO_ERROR )
 | 
			
		||||
    debug( "DosAsyncTimer() failed, rc = %u", ulRC );
 | 
			
		||||
  else
 | 
			
		||||
    if (ulRC != NO_ERROR) {
 | 
			
		||||
        debug_os2("DosAsyncTimer() failed, rc = %u", ulRC);
 | 
			
		||||
    } else {
 | 
			
		||||
        DosWaitEventSem(hevTimer, SEM_INDEFINITE_WAIT);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (ulRC != NO_ERROR)
 | 
			
		||||
        DosSleep(ms);
 | 
			
		||||
 
 | 
			
		||||
@@ -41,8 +41,8 @@ typedef struct _VODATA {
 | 
			
		||||
  BOOL     fBlitterReady;
 | 
			
		||||
} VODATA;
 | 
			
		||||
 | 
			
		||||
static BOOL voQueryInfo(PVIDEOOUTPUTINFO pInfo);
 | 
			
		||||
static PVODATA voOpen();
 | 
			
		||||
static BOOL voQueryInfo(VIDEOOUTPUTINFO *pInfo);
 | 
			
		||||
static PVODATA voOpen(void);
 | 
			
		||||
static VOID voClose(PVODATA pVOData);
 | 
			
		||||
static BOOL voSetVisibleRegion(PVODATA pVOData, HWND hwnd,
 | 
			
		||||
                               SDL_DisplayMode *pSDLDisplayMode,
 | 
			
		||||
@@ -65,26 +65,23 @@ OS2VIDEOOUTPUT voDive = {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static BOOL voQueryInfo(PVIDEOOUTPUTINFO pInfo)
 | 
			
		||||
static BOOL voQueryInfo(VIDEOOUTPUTINFO *pInfo)
 | 
			
		||||
{
 | 
			
		||||
    DIVE_CAPS sDiveCaps = { 0 };
 | 
			
		||||
    FOURCC fccFormats[100] = { 0 };
 | 
			
		||||
 | 
			
		||||
  // Query information about display hardware from DIVE.
 | 
			
		||||
 | 
			
		||||
    /* Query information about display hardware from DIVE. */
 | 
			
		||||
    sDiveCaps.pFormatData    = fccFormats;
 | 
			
		||||
    sDiveCaps.ulFormatLength = 100;
 | 
			
		||||
    sDiveCaps.ulStructLen    = sizeof(DIVE_CAPS);
 | 
			
		||||
 | 
			
		||||
  if ( DiveQueryCaps( &sDiveCaps, DIVE_BUFFER_SCREEN ) )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "DiveQueryCaps() failed." );
 | 
			
		||||
    if (DiveQueryCaps(&sDiveCaps, DIVE_BUFFER_SCREEN)) {
 | 
			
		||||
        debug_os2("DiveQueryCaps() failed.");
 | 
			
		||||
        return FALSE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  if ( sDiveCaps.ulDepth < 8 )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "Not enough screen colors to run DIVE. "
 | 
			
		||||
    if (sDiveCaps.ulDepth < 8) {
 | 
			
		||||
        debug_os2("Not enough screen colors to run DIVE. "
 | 
			
		||||
                  "Must be at least 256 colors.");
 | 
			
		||||
        return FALSE;
 | 
			
		||||
    }
 | 
			
		||||
@@ -98,18 +95,16 @@ static BOOL voQueryInfo(PVIDEOOUTPUTINFO pInfo)
 | 
			
		||||
    return TRUE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
PVODATA voOpen()
 | 
			
		||||
PVODATA voOpen(void)
 | 
			
		||||
{
 | 
			
		||||
    PVODATA pVOData = SDL_calloc(1, sizeof(VODATA));
 | 
			
		||||
 | 
			
		||||
  if ( pVOData == NULL )
 | 
			
		||||
  {
 | 
			
		||||
    if (pVOData == NULL) {
 | 
			
		||||
        SDL_OutOfMemory();
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  if ( DiveOpen( &pVOData->hDive, FALSE, NULL ) != DIVE_SUCCESS )
 | 
			
		||||
  {
 | 
			
		||||
    if (DiveOpen(&pVOData->hDive, FALSE, NULL) != DIVE_SUCCESS) {
 | 
			
		||||
        SDL_free(pVOData);
 | 
			
		||||
        SDL_SetError("DIVE: A display engine instance open failed");
 | 
			
		||||
        return NULL;
 | 
			
		||||
@@ -135,28 +130,22 @@ static BOOL voSetVisibleRegion(PVODATA pVOData, HWND hwnd,
 | 
			
		||||
    PRECTL  prectl = NULL;
 | 
			
		||||
    ULONG   ulRC;
 | 
			
		||||
 | 
			
		||||
  if ( !fVisible )
 | 
			
		||||
  {
 | 
			
		||||
    if ( pVOData->fBlitterReady )
 | 
			
		||||
    {
 | 
			
		||||
    if (!fVisible) {
 | 
			
		||||
        if (pVOData->fBlitterReady) {
 | 
			
		||||
            pVOData->fBlitterReady = FALSE;
 | 
			
		||||
            DiveSetupBlitter(pVOData->hDive, 0);
 | 
			
		||||
      debug( "DIVE blitter is tuned off" );
 | 
			
		||||
            debug_os2("DIVE blitter is tuned off");
 | 
			
		||||
        }
 | 
			
		||||
        return TRUE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  // Query visible rectangles
 | 
			
		||||
 | 
			
		||||
    /* Query visible rectangles */
 | 
			
		||||
    hps = WinGetPS(hwnd);
 | 
			
		||||
    hrgn = GpiCreateRegion(hps, 0, NULL);
 | 
			
		||||
  if ( hrgn == NULLHANDLE )
 | 
			
		||||
  {
 | 
			
		||||
    if (hrgn == NULLHANDLE) {
 | 
			
		||||
        WinReleasePS(hps);
 | 
			
		||||
        SDL_SetError("GpiCreateRegion() failed");
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    } else {
 | 
			
		||||
        WinQueryVisibleRegion(hwnd, hrgn);
 | 
			
		||||
        if (hrgnShape != NULLHANDLE)
 | 
			
		||||
            GpiCombineRegion(hps, hrgn, hrgn, hrgnShape, CRGN_AND);
 | 
			
		||||
@@ -165,25 +154,22 @@ static BOOL voSetVisibleRegion(PVODATA pVOData, HWND hwnd,
 | 
			
		||||
        rgnCtl.crc          = 0;
 | 
			
		||||
        rgnCtl.ulDirection  = 1;
 | 
			
		||||
        GpiQueryRegionRects(hps, hrgn, NULL, &rgnCtl, NULL);
 | 
			
		||||
    if ( rgnCtl.crcReturned != 0 )
 | 
			
		||||
    {
 | 
			
		||||
        if (rgnCtl.crcReturned != 0) {
 | 
			
		||||
            prectl = SDL_malloc(rgnCtl.crcReturned * sizeof(RECTL));
 | 
			
		||||
      if ( prectl != NULL )
 | 
			
		||||
      {
 | 
			
		||||
            if (prectl != NULL) {
 | 
			
		||||
                rgnCtl.ircStart     = 1;
 | 
			
		||||
                rgnCtl.crc          = rgnCtl.crcReturned;
 | 
			
		||||
                rgnCtl.ulDirection  = 1;
 | 
			
		||||
                GpiQueryRegionRects(hps, hrgn, NULL, &rgnCtl, prectl);
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
            } else {
 | 
			
		||||
                SDL_OutOfMemory();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        GpiDestroyRegion(hps, hrgn);
 | 
			
		||||
        WinReleasePS(hps);
 | 
			
		||||
 | 
			
		||||
    if ( prectl != NULL )
 | 
			
		||||
    {
 | 
			
		||||
      // Setup DIVE blitter.
 | 
			
		||||
        if (prectl != NULL) {
 | 
			
		||||
            /* Setup DIVE blitter. */
 | 
			
		||||
            SETUP_BLITTER   sSetupBlitter;
 | 
			
		||||
            SWP             swp;
 | 
			
		||||
            POINTL          pointl = { 0 };
 | 
			
		||||
@@ -213,17 +199,16 @@ static BOOL voSetVisibleRegion(PVODATA pVOData, HWND hwnd,
 | 
			
		||||
            ulRC = DiveSetupBlitter(pVOData->hDive, &sSetupBlitter);
 | 
			
		||||
            SDL_free(prectl);
 | 
			
		||||
 | 
			
		||||
      if ( ulRC == DIVE_SUCCESS )
 | 
			
		||||
      {
 | 
			
		||||
            if (ulRC == DIVE_SUCCESS) {
 | 
			
		||||
                pVOData->fBlitterReady = TRUE;
 | 
			
		||||
                WinInvalidateRect(hwnd, NULL, TRUE);
 | 
			
		||||
        debug( "DIVE blitter is ready now." );
 | 
			
		||||
                debug_os2("DIVE blitter is ready now.");
 | 
			
		||||
                return TRUE;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            SDL_SetError("DiveSetupBlitter(), rc = 0x%X", ulRC);
 | 
			
		||||
    } // if ( prectl != NULL )
 | 
			
		||||
  } // if ( hrgn == NULLHANDLE ) else
 | 
			
		||||
        } /* if (prectl != NULL) */
 | 
			
		||||
    } /* if (hrgn == NULLHANDLE) else */
 | 
			
		||||
 | 
			
		||||
    pVOData->fBlitterReady = FALSE;
 | 
			
		||||
    DiveSetupBlitter(pVOData->hDive, 0);
 | 
			
		||||
@@ -237,31 +222,29 @@ static PVOID voVideoBufAlloc(PVODATA pVOData, ULONG ulWidth, ULONG ulHeight,
 | 
			
		||||
    ULONG   ulRC;
 | 
			
		||||
    ULONG   ulScanLineSize = ulWidth * (ulBPP >> 3);
 | 
			
		||||
 | 
			
		||||
  // Destroy previous buffer.
 | 
			
		||||
    /* Destroy previous buffer. */
 | 
			
		||||
    voVideoBufFree(pVOData);
 | 
			
		||||
 | 
			
		||||
  if ( ( ulWidth == 0 ) || ( ulHeight == 0 ) || ( ulBPP == 0 ) )
 | 
			
		||||
    if (ulWidth == 0 || ulHeight == 0 || ulBPP == 0)
 | 
			
		||||
        return NULL;
 | 
			
		||||
 | 
			
		||||
  // Bytes per line.
 | 
			
		||||
    /* Bytes per line. */
 | 
			
		||||
    ulScanLineSize  = (ulScanLineSize + 3) & ~3; /* 4-byte aligning */
 | 
			
		||||
    *pulScanLineSize = ulScanLineSize;
 | 
			
		||||
 | 
			
		||||
    ulRC = DosAllocMem(&pVOData->pBuffer,
 | 
			
		||||
                       (ulHeight * ulScanLineSize) + sizeof(ULONG),
 | 
			
		||||
                       PAG_COMMIT | PAG_EXECUTE | PAG_READ | PAG_WRITE);
 | 
			
		||||
  if ( ulRC != NO_ERROR )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "DosAllocMem(), rc = %u", ulRC );
 | 
			
		||||
    if (ulRC != NO_ERROR) {
 | 
			
		||||
        debug_os2("DosAllocMem(), rc = %u", ulRC);
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ulRC = DiveAllocImageBuffer(pVOData->hDive, &pVOData->ulDIVEBufNum,
 | 
			
		||||
                                fccColorEncoding, ulWidth, ulHeight,
 | 
			
		||||
                                ulScanLineSize, pVOData->pBuffer);
 | 
			
		||||
  if ( ulRC != DIVE_SUCCESS )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "DiveAllocImageBuffer(), rc = 0x%X", ulRC );
 | 
			
		||||
    if (ulRC != DIVE_SUCCESS) {
 | 
			
		||||
        debug_os2("DiveAllocImageBuffer(), rc = 0x%X", ulRC);
 | 
			
		||||
        DosFreeMem(pVOData->pBuffer);
 | 
			
		||||
        pVOData->pBuffer = NULL;
 | 
			
		||||
        pVOData->ulDIVEBufNum = 0;
 | 
			
		||||
@@ -272,7 +255,7 @@ static PVOID voVideoBufAlloc(PVODATA pVOData, ULONG ulWidth, ULONG ulHeight,
 | 
			
		||||
    pVOData->ulWidth = ulWidth;
 | 
			
		||||
    pVOData->ulHeight = ulHeight;
 | 
			
		||||
 | 
			
		||||
  debug( "buffer: 0x%P, DIVE buffer number: %u",
 | 
			
		||||
    debug_os2("buffer: 0x%P, DIVE buffer number: %u",
 | 
			
		||||
              pVOData->pBuffer, pVOData->ulDIVEBufNum);
 | 
			
		||||
 | 
			
		||||
    return pVOData->pBuffer;
 | 
			
		||||
@@ -282,23 +265,21 @@ static VOID voVideoBufFree(PVODATA pVOData)
 | 
			
		||||
{
 | 
			
		||||
    ULONG   ulRC;
 | 
			
		||||
 | 
			
		||||
  if ( pVOData->ulDIVEBufNum != 0 )
 | 
			
		||||
  {
 | 
			
		||||
    if (pVOData->ulDIVEBufNum != 0) {
 | 
			
		||||
        ulRC = DiveFreeImageBuffer(pVOData->hDive, pVOData->ulDIVEBufNum);
 | 
			
		||||
    if ( ulRC != DIVE_SUCCESS )
 | 
			
		||||
      debug( "DiveFreeImageBuffer(,%u), rc = %u", pVOData->ulDIVEBufNum, ulRC );
 | 
			
		||||
    else
 | 
			
		||||
      debug( "DIVE buffer %u destroyed", pVOData->ulDIVEBufNum );
 | 
			
		||||
 | 
			
		||||
        if (ulRC != DIVE_SUCCESS) {
 | 
			
		||||
            debug_os2("DiveFreeImageBuffer(,%u), rc = %u", pVOData->ulDIVEBufNum, ulRC);
 | 
			
		||||
        } else {
 | 
			
		||||
            debug_os2("DIVE buffer %u destroyed", pVOData->ulDIVEBufNum);
 | 
			
		||||
        }
 | 
			
		||||
        pVOData->ulDIVEBufNum = 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  if ( pVOData->pBuffer != NULL )
 | 
			
		||||
  {
 | 
			
		||||
    if (pVOData->pBuffer != NULL) {
 | 
			
		||||
        ulRC = DosFreeMem(pVOData->pBuffer);
 | 
			
		||||
    if ( ulRC != NO_ERROR )
 | 
			
		||||
      debug( "DosFreeMem(), rc = %u", ulRC );
 | 
			
		||||
 | 
			
		||||
        if (ulRC != NO_ERROR) {
 | 
			
		||||
            debug_os2("DosFreeMem(), rc = %u", ulRC);
 | 
			
		||||
        }
 | 
			
		||||
        pVOData->pBuffer = NULL;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -308,41 +289,41 @@ static BOOL voUpdate(PVODATA pVOData, HWND hwnd, SDL_Rect *pSDLRects,
 | 
			
		||||
{
 | 
			
		||||
    ULONG   ulRC;
 | 
			
		||||
 | 
			
		||||
  if ( !pVOData->fBlitterReady || ( pVOData->ulDIVEBufNum == 0 ) )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "DIVE blitter is not ready" );
 | 
			
		||||
    if (!pVOData->fBlitterReady || (pVOData->ulDIVEBufNum == 0)) {
 | 
			
		||||
        debug_os2("DIVE blitter is not ready");
 | 
			
		||||
        return FALSE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  if ( pSDLRects != 0 )
 | 
			
		||||
  {
 | 
			
		||||
    if (pSDLRects != 0) {
 | 
			
		||||
        PBYTE   pbLineMask;
 | 
			
		||||
 | 
			
		||||
        pbLineMask = SDL_stack_alloc(BYTE, pVOData->ulHeight);
 | 
			
		||||
    if ( pbLineMask == NULL )
 | 
			
		||||
    {
 | 
			
		||||
      debug( "Not enough stack size" );
 | 
			
		||||
        if (pbLineMask == NULL) {
 | 
			
		||||
            debug_os2("Not enough stack size");
 | 
			
		||||
            return FALSE;
 | 
			
		||||
        }
 | 
			
		||||
        memset(pbLineMask, 0, pVOData->ulHeight);
 | 
			
		||||
 | 
			
		||||
    for( ; ((LONG)cSDLRects) > 0; cSDLRects--, pSDLRects++ )
 | 
			
		||||
        for ( ; ((LONG)cSDLRects) > 0; cSDLRects--, pSDLRects++) {
 | 
			
		||||
            memset(&pbLineMask[pSDLRects->y], 1, pSDLRects->h);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ulRC = DiveBlitImageLines(pVOData->hDive, pVOData->ulDIVEBufNum,
 | 
			
		||||
                                  DIVE_BUFFER_SCREEN, pbLineMask);
 | 
			
		||||
        SDL_stack_free(pbLineMask);
 | 
			
		||||
 | 
			
		||||
    if ( ulRC != DIVE_SUCCESS )
 | 
			
		||||
      debug( "DiveBlitImageLines(), rc = 0x%X", ulRC );
 | 
			
		||||
        if (ulRC != DIVE_SUCCESS) {
 | 
			
		||||
            debug_os2("DiveBlitImageLines(), rc = 0x%X", ulRC);
 | 
			
		||||
        }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    } else {
 | 
			
		||||
        ulRC = DiveBlitImage(pVOData->hDive, pVOData->ulDIVEBufNum,
 | 
			
		||||
                             DIVE_BUFFER_SCREEN);
 | 
			
		||||
    if ( ulRC != DIVE_SUCCESS )
 | 
			
		||||
      debug( "DiveBlitImage(), rc = 0x%X", ulRC );
 | 
			
		||||
        if (ulRC != DIVE_SUCCESS) {
 | 
			
		||||
            debug_os2("DiveBlitImage(), rc = 0x%X", ulRC);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return ulRC == DIVE_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* vi: set ts=4 sw=4 expandtab: */
 | 
			
		||||
 
 | 
			
		||||
@@ -37,9 +37,9 @@
 | 
			
		||||
typedef struct _MSGBOXDLGDATA {
 | 
			
		||||
    USHORT       cb;
 | 
			
		||||
    HWND         hwndUnder;
 | 
			
		||||
} MSGBOXDLGDATA, *PMSGBOXDLGDATA;
 | 
			
		||||
} MSGBOXDLGDATA;
 | 
			
		||||
 | 
			
		||||
static VOID _wmInitDlg(HWND hwnd, PMSGBOXDLGDATA pDlgData)
 | 
			
		||||
static VOID _wmInitDlg(HWND hwnd, MSGBOXDLGDATA *pDlgData)
 | 
			
		||||
{
 | 
			
		||||
    HPS     hps = WinGetPS(hwnd);
 | 
			
		||||
    POINTL  aptText[TXTBOX_COUNT];
 | 
			
		||||
@@ -54,27 +54,23 @@ static VOID _wmInitDlg(HWND hwnd, PMSGBOXDLGDATA pDlgData)
 | 
			
		||||
    ULONG   ulX;
 | 
			
		||||
    ULONG   ulIdx;
 | 
			
		||||
    struct _BUTTON {
 | 
			
		||||
    HWND     hwnd;     // Button window handle.
 | 
			
		||||
    ULONG    ulCX;     // Button width in dialog coordinates.
 | 
			
		||||
      HWND  hwnd;   /* Button window handle. */
 | 
			
		||||
      ULONG ulCX;   /* Button width in dialog coordinates. */
 | 
			
		||||
    } aButtons[32];
 | 
			
		||||
    RECTL      rectlItem;
 | 
			
		||||
    HAB        hab = WinQueryAnchorBlock(hwnd);
 | 
			
		||||
 | 
			
		||||
    /* --- Align the buttons to the right/bottom. --- */
 | 
			
		||||
 | 
			
		||||
  // Collect window handles of all buttons in dialog.
 | 
			
		||||
 | 
			
		||||
    /* Collect window handles of all buttons in dialog. */
 | 
			
		||||
    hEnum = WinBeginEnumWindows(hwnd);
 | 
			
		||||
 | 
			
		||||
  while( ( hWndNext = WinGetNextWindow( hEnum ) ) != NULLHANDLE )
 | 
			
		||||
  {
 | 
			
		||||
    while ((hWndNext = WinGetNextWindow(hEnum)) != NULLHANDLE) {
 | 
			
		||||
        if (WinQueryClassName(hWndNext, sizeof(acBuf), acBuf) == 0)
 | 
			
		||||
            continue;
 | 
			
		||||
 | 
			
		||||
    if ( strcmp( acBuf, "#3" ) == 0 ) // Class name of button.
 | 
			
		||||
    {
 | 
			
		||||
      if ( cButtons < sizeof(aButtons) / sizeof(struct _BUTTON) )
 | 
			
		||||
      {
 | 
			
		||||
        if (strcmp(acBuf, "#3") == 0) { /* Class name of button. */
 | 
			
		||||
            if (cButtons < sizeof(aButtons) / sizeof(struct _BUTTON)) {
 | 
			
		||||
                aButtons[cButtons].hwnd = hWndNext;
 | 
			
		||||
                cButtons++;
 | 
			
		||||
            }
 | 
			
		||||
@@ -82,99 +78,97 @@ static VOID _wmInitDlg(HWND hwnd, PMSGBOXDLGDATA pDlgData)
 | 
			
		||||
    }
 | 
			
		||||
    WinEndEnumWindows(hEnum);
 | 
			
		||||
 | 
			
		||||
  // Query size of text for each button, get width of each button, total
 | 
			
		||||
  // buttons width (ulButtonsCX) and max. height (ulButtonsCX) in _dialog
 | 
			
		||||
  // coordinates_.
 | 
			
		||||
 | 
			
		||||
    /* Query size of text for each button, get width of each button, total
 | 
			
		||||
     * buttons width (ulButtonsCX) and max. height (ulButtonsCX) in _dialog
 | 
			
		||||
     * coordinates_. */
 | 
			
		||||
    hps = WinGetPS(hwnd);
 | 
			
		||||
 | 
			
		||||
  for( ulIdx = 0; ulIdx < cButtons; ulIdx++ )
 | 
			
		||||
  {
 | 
			
		||||
    // Query size of text in window coordinates.
 | 
			
		||||
    for(ulIdx = 0; ulIdx < cButtons; ulIdx++) {
 | 
			
		||||
        /* Query size of text in window coordinates. */
 | 
			
		||||
        cbBuf = WinQueryWindowText(aButtons[ulIdx].hwnd, sizeof(acBuf), acBuf);
 | 
			
		||||
        GpiQueryTextBox(hps, cbBuf, acBuf, TXTBOX_COUNT, aptText);
 | 
			
		||||
        aptText[TXTBOX_TOPRIGHT].x -= aptText[TXTBOX_BOTTOMLEFT].x;
 | 
			
		||||
        aptText[TXTBOX_TOPRIGHT].y -= aptText[TXTBOX_BOTTOMLEFT].y;
 | 
			
		||||
    // Convert text size to dialog coordinates.
 | 
			
		||||
        /* Convert text size to dialog coordinates. */
 | 
			
		||||
        WinMapDlgPoints(hwnd, &aptText[TXTBOX_TOPRIGHT], 1, FALSE);
 | 
			
		||||
    // Add vertical and horizontal space for button's frame (dialog coord.).
 | 
			
		||||
    if ( aptText[TXTBOX_TOPRIGHT].x < 30 ) // Minimal button width.
 | 
			
		||||
        /* Add vertical and horizontal space for button's frame (dialog coord.). */
 | 
			
		||||
        if (aptText[TXTBOX_TOPRIGHT].x < 30) {/* Minimal button width. */
 | 
			
		||||
            aptText[TXTBOX_TOPRIGHT].x = 30;
 | 
			
		||||
    else
 | 
			
		||||
        } else {
 | 
			
		||||
            aptText[TXTBOX_TOPRIGHT].x += 4;
 | 
			
		||||
        }
 | 
			
		||||
        aptText[TXTBOX_TOPRIGHT].y += 3;
 | 
			
		||||
 | 
			
		||||
    aButtons[ulIdx].ulCX = aptText[TXTBOX_TOPRIGHT].x; // Store button width.
 | 
			
		||||
    ulButtonsCX += aptText[TXTBOX_TOPRIGHT].x + 2;     // Add total btn. width.
 | 
			
		||||
    // Get max. height for buttons.
 | 
			
		||||
        aButtons[ulIdx].ulCX = aptText[TXTBOX_TOPRIGHT].x; /* Store button width   */
 | 
			
		||||
        ulButtonsCX += aptText[TXTBOX_TOPRIGHT].x + 2;     /* Add total btn. width */
 | 
			
		||||
        /* Get max. height for buttons. */
 | 
			
		||||
        if (ulButtonsCY < aptText[TXTBOX_TOPRIGHT].y)
 | 
			
		||||
            ulButtonsCY = aptText[TXTBOX_TOPRIGHT].y + 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WinReleasePS(hps);
 | 
			
		||||
 | 
			
		||||
  // Expand horizontal size of the window to fit all buttons and move window
 | 
			
		||||
  // to the center of parent window.
 | 
			
		||||
    /* Expand horizontal size of the window to fit all buttons and move window
 | 
			
		||||
     * to the center of parent window. */
 | 
			
		||||
 | 
			
		||||
  // Convert total width of buttons to window coordinates.
 | 
			
		||||
    /* Convert total width of buttons to window coordinates. */
 | 
			
		||||
    aptText[0].x = ulButtonsCX + 4;
 | 
			
		||||
    WinMapDlgPoints(hwnd, &aptText[0], 1, TRUE);
 | 
			
		||||
  // Check width of the window and expand as needed.
 | 
			
		||||
    /* Check width of the window and expand as needed. */
 | 
			
		||||
    WinQueryWindowRect(hwnd, &rectlItem);
 | 
			
		||||
    if (rectlItem.xRight <= aptText[0].x)
 | 
			
		||||
        rectlItem.xRight = aptText[0].x;
 | 
			
		||||
 | 
			
		||||
  // Move window rectangle to the center of owner window.
 | 
			
		||||
    /* Move window rectangle to the center of owner window. */
 | 
			
		||||
    WinQueryWindowRect(pDlgData->hwndUnder, &rectl);
 | 
			
		||||
    // Left-bottom point of centered dialog on owner window.
 | 
			
		||||
    /* Left-bottom point of centered dialog on owner window. */
 | 
			
		||||
    rectl.xLeft = (rectl.xRight - rectlItem.xRight) / 2;
 | 
			
		||||
    rectl.yBottom = (rectl.yTop - rectlItem.yTop) / 2;
 | 
			
		||||
    // Map left-bottom point to desktop.
 | 
			
		||||
    /* Map left-bottom point to desktop. */
 | 
			
		||||
    WinMapWindowPoints(pDlgData->hwndUnder, HWND_DESKTOP, (PPOINTL)&rectl, 1);
 | 
			
		||||
    WinOffsetRect(hab, &rectlItem, rectl.xLeft, rectl.yBottom);
 | 
			
		||||
 | 
			
		||||
  // Set new rectangle for the window.
 | 
			
		||||
    /* Set new rectangle for the window. */
 | 
			
		||||
    WinSetWindowPos(hwnd, HWND_TOP, rectlItem.xLeft, rectlItem.yBottom,
 | 
			
		||||
                    rectlItem.xRight - rectlItem.xLeft,
 | 
			
		||||
                    rectlItem.yTop - rectlItem.yBottom,
 | 
			
		||||
                    SWP_SIZE | SWP_MOVE);
 | 
			
		||||
 | 
			
		||||
  // Set buttons positions.
 | 
			
		||||
    /* Set buttons positions. */
 | 
			
		||||
 | 
			
		||||
  // Get horizontal position for the first button.
 | 
			
		||||
  WinMapDlgPoints( hwnd, (PPOINTL)&rectlItem, 2, FALSE ); // Win size to dlg coord.
 | 
			
		||||
  ulX = rectlItem.xRight - rectlItem.xLeft - ulButtonsCX - 2; // First button position.
 | 
			
		||||
    /* Get horizontal position for the first button. */
 | 
			
		||||
    WinMapDlgPoints(hwnd, (PPOINTL)&rectlItem, 2, FALSE);       /* Win size to dlg coord. */
 | 
			
		||||
    ulX = rectlItem.xRight - rectlItem.xLeft - ulButtonsCX - 2; /* First button position. */
 | 
			
		||||
 | 
			
		||||
  // Set positions and sizes for all buttons.
 | 
			
		||||
  for( ulIdx = 0; ulIdx < cButtons; ulIdx++ )
 | 
			
		||||
  {
 | 
			
		||||
    // Get poisition and size for the button in dialog coordinates.
 | 
			
		||||
    /* Set positions and sizes for all buttons. */
 | 
			
		||||
    for (ulIdx = 0; ulIdx < cButtons; ulIdx++) {
 | 
			
		||||
        /* Get poisition and size for the button in dialog coordinates. */
 | 
			
		||||
        aptText[0].x = ulX;
 | 
			
		||||
        aptText[0].y = 2;
 | 
			
		||||
        aptText[1].x = aButtons[ulIdx].ulCX;
 | 
			
		||||
        aptText[1].y = ulButtonsCY;
 | 
			
		||||
    // Convert to window coordinates.
 | 
			
		||||
        /* Convert to window coordinates. */
 | 
			
		||||
        WinMapDlgPoints(hwnd, aptText, 2, TRUE);
 | 
			
		||||
 | 
			
		||||
        WinSetWindowPos(aButtons[ulIdx].hwnd, HWND_TOP,
 | 
			
		||||
                        aptText[0].x, aptText[0].y, aptText[1].x, aptText[1].y,
 | 
			
		||||
                        SWP_MOVE | SWP_SIZE);
 | 
			
		||||
 | 
			
		||||
    // Offset horizontal position for the next button.
 | 
			
		||||
        /* Offset horizontal position for the next button. */
 | 
			
		||||
        ulX += aButtons[ulIdx].ulCX + 2;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  // Set right bound of the text to right bound of the last button and
 | 
			
		||||
  // bottom bound of the text just above the buttons.
 | 
			
		||||
    /* Set right bound of the text to right bound of the last button and
 | 
			
		||||
     * bottom bound of the text just above the buttons. */
 | 
			
		||||
 | 
			
		||||
  aptText[2].x = 25;              // Left bound of text in dlg coordinates.
 | 
			
		||||
  aptText[2].y = ulButtonsCY + 3; // Bottom bound of the text in dlg coords.
 | 
			
		||||
  WinMapDlgPoints( hwnd, &aptText[2], 1, TRUE ); // Convert ^^^ to win. coords.
 | 
			
		||||
    aptText[2].x = 25;              /* Left bound of text in dlg coordinates.  */
 | 
			
		||||
    aptText[2].y = ulButtonsCY + 3; /* Bottom bound of the text in dlg coords. */
 | 
			
		||||
    WinMapDlgPoints(hwnd, &aptText[2], 1, TRUE); /* Convert ^^^ to win. coords */
 | 
			
		||||
    hWndNext = WinWindowFromID(hwnd, IDD_TEXT_MESSAGE);
 | 
			
		||||
    WinQueryWindowRect(hWndNext, &rectlItem);
 | 
			
		||||
    rectlItem.xLeft = aptText[2].x;
 | 
			
		||||
    rectlItem.yBottom = aptText[2].y;
 | 
			
		||||
  // Right bound of the text equals right bound of the last button.
 | 
			
		||||
    /* Right bound of the text equals right bound of the last button. */
 | 
			
		||||
    rectlItem.xRight = aptText[0].x + aptText[1].x;
 | 
			
		||||
    WinSetWindowPos(hWndNext, HWND_TOP, rectlItem.xLeft, rectlItem.yBottom,
 | 
			
		||||
                    rectlItem.xRight - rectlItem.xLeft,
 | 
			
		||||
@@ -184,19 +178,16 @@ static VOID _wmInitDlg(HWND hwnd, PMSGBOXDLGDATA pDlgData)
 | 
			
		||||
 | 
			
		||||
MRESULT EXPENTRY DynDlgProc(HWND hwnd, USHORT message, MPARAM mp1, MPARAM mp2)
 | 
			
		||||
{
 | 
			
		||||
  switch( message )
 | 
			
		||||
  {
 | 
			
		||||
    switch (message) {
 | 
			
		||||
    case WM_INITDLG:
 | 
			
		||||
      _wmInitDlg( hwnd, (PMSGBOXDLGDATA)mp2 );
 | 
			
		||||
        _wmInitDlg(hwnd, (MSGBOXDLGDATA*)mp2);
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case WM_COMMAND:
 | 
			
		||||
      switch( SHORT1FROMMP(mp1) )
 | 
			
		||||
      {
 | 
			
		||||
        switch (SHORT1FROMMP(mp1)) {
 | 
			
		||||
        case DID_OK:
 | 
			
		||||
            WinDismissDlg(hwnd, FALSE);
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        default:
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
@@ -210,16 +201,14 @@ MRESULT EXPENTRY DynDlgProc(HWND hwnd, USHORT message, MPARAM mp1, MPARAM mp2)
 | 
			
		||||
 | 
			
		||||
static HWND _makeDlg(const SDL_MessageBoxData *messageboxdata)
 | 
			
		||||
{
 | 
			
		||||
  SDL_MessageBoxButtonData       *pSDLBtnData =
 | 
			
		||||
                           (SDL_MessageBoxButtonData *)messageboxdata->buttons;
 | 
			
		||||
    SDL_MessageBoxButtonData*
 | 
			
		||||
        pSDLBtnData =  (SDL_MessageBoxButtonData *)messageboxdata->buttons;
 | 
			
		||||
    ULONG               cSDLBtnData = messageboxdata->numbuttons;
 | 
			
		||||
 | 
			
		||||
    PSZ                 pszTitle = OS2_UTF8ToSys((PSZ) messageboxdata->title);
 | 
			
		||||
  ULONG                cbTitle = pszTitle == NULL ?
 | 
			
		||||
                                             0 : strlen( pszTitle );
 | 
			
		||||
    ULONG               cbTitle = (pszTitle == NULL)? 0 : strlen(pszTitle);
 | 
			
		||||
    PSZ                 pszText = OS2_UTF8ToSys((PSZ) messageboxdata->message);
 | 
			
		||||
  ULONG                cbText = pszText == NULL ?
 | 
			
		||||
                                             0 : strlen( pszText );
 | 
			
		||||
    ULONG               cbText = (pszText == NULL)? 0 : strlen(pszText);
 | 
			
		||||
 | 
			
		||||
    PDLGTEMPLATE        pTemplate;
 | 
			
		||||
    ULONG               cbTemplate;
 | 
			
		||||
@@ -229,38 +218,36 @@ static HWND _makeDlg(const SDL_MessageBoxData *messageboxdata)
 | 
			
		||||
    PSZ                 pszBtnText;
 | 
			
		||||
    ULONG               cbBtnText;
 | 
			
		||||
    HWND                hwnd;
 | 
			
		||||
  const SDL_MessageBoxColor  *pSDLColors = (messageboxdata->colorScheme == NULL)? NULL : messageboxdata->colorScheme->colors;
 | 
			
		||||
    const SDL_MessageBoxColor* pSDLColors = (messageboxdata->colorScheme == NULL)?
 | 
			
		||||
                                       NULL : messageboxdata->colorScheme->colors;
 | 
			
		||||
    const SDL_MessageBoxColor* pSDLColor;
 | 
			
		||||
    MSGBOXDLGDATA       stDlgData;
 | 
			
		||||
 | 
			
		||||
    /* Build a dialog tamplate in memory */
 | 
			
		||||
 | 
			
		||||
  // Size of template (cbTemplate).
 | 
			
		||||
 | 
			
		||||
    /* Size of template (cbTemplate). */
 | 
			
		||||
    cbTemplate = sizeof(DLGTEMPLATE) + ((2 + cSDLBtnData) * sizeof(DLGTITEM)) +
 | 
			
		||||
               sizeof(ULONG) +    // First item data - frame control data.
 | 
			
		||||
               cbTitle + 1 +      // First item data - frame title + ZERO.
 | 
			
		||||
               cbText + 1 +       // Second item data - ststic text + ZERO.
 | 
			
		||||
               3;                 // Third item data - system icon Id.
 | 
			
		||||
  // Button items datas - text for buttons.
 | 
			
		||||
  for( ulIdx = 0; ulIdx < cSDLBtnData; ulIdx++ )
 | 
			
		||||
  {
 | 
			
		||||
                 sizeof(ULONG) +  // First item data - frame control data. */
 | 
			
		||||
                 cbTitle + 1 +    // First item data - frame title + ZERO. */
 | 
			
		||||
                 cbText + 1 +     // Second item data - ststic text + ZERO.*/
 | 
			
		||||
                 3;               /* Third item data - system icon Id.     */
 | 
			
		||||
    /* Button items datas - text for buttons. */
 | 
			
		||||
    for (ulIdx = 0; ulIdx < cSDLBtnData; ulIdx++) {
 | 
			
		||||
        pszBtnText = (PSZ)pSDLBtnData[ulIdx].text;
 | 
			
		||||
    cbTemplate += pszBtnText == NULL ? 1 : ( strlen( pszBtnText ) + 1 );
 | 
			
		||||
        cbTemplate += (pszBtnText == NULL)? 1 : (strlen(pszBtnText) + 1);
 | 
			
		||||
    }
 | 
			
		||||
  // Presentation parameter space.
 | 
			
		||||
    /* Presentation parameter space. */
 | 
			
		||||
    if (pSDLColors != NULL)
 | 
			
		||||
        cbTemplate += 26 /* PP for frame. */ + 26 /* PP for static text. */ +
 | 
			
		||||
                     (48 * cSDLBtnData); /* PP for buttons. */
 | 
			
		||||
 | 
			
		||||
  // Allocate memory for the dialog template.
 | 
			
		||||
    /* Allocate memory for the dialog template. */
 | 
			
		||||
    pTemplate = (PDLGTEMPLATE) SDL_malloc(cbTemplate);
 | 
			
		||||
  // Pointer on data for dialog items in allocated memory.
 | 
			
		||||
    /* Pointer on data for dialog items in allocated memory. */
 | 
			
		||||
    pcDlgData = &((PCHAR)pTemplate)[sizeof(DLGTEMPLATE) +
 | 
			
		||||
                                    ((2 + cSDLBtnData) * sizeof(DLGTITEM))];
 | 
			
		||||
 | 
			
		||||
    /* Header info */
 | 
			
		||||
 | 
			
		||||
    pTemplate->cbTemplate = cbTemplate; /* size of dialog template to pass to WinCreateDlg() */
 | 
			
		||||
    pTemplate->type = 0;                /* Currently always 0. */
 | 
			
		||||
    pTemplate->codepage = 0;
 | 
			
		||||
@@ -273,7 +260,6 @@ static HWND _makeDlg(const SDL_MessageBoxData *messageboxdata)
 | 
			
		||||
    pTemplate->coffPresParams = 0;
 | 
			
		||||
 | 
			
		||||
    /* First item info - frame */
 | 
			
		||||
 | 
			
		||||
    pDlgItem = pTemplate->adlgti;
 | 
			
		||||
    pDlgItem->fsItemStatus = 0;  /* Reserved? */
 | 
			
		||||
    /* Number of dialog item child windows owned by this item. */
 | 
			
		||||
@@ -285,10 +271,11 @@ static HWND _makeDlg(const SDL_MessageBoxData *messageboxdata)
 | 
			
		||||
    pDlgItem->cchText = cbTitle + 1; /* +1 - trailing ZERO. */
 | 
			
		||||
    pDlgItem->offText = pcDlgData - (PCHAR)pTemplate; /* Offset to title text.  */
 | 
			
		||||
    /* Copy text for the title into the dialog template. */
 | 
			
		||||
  if ( pszTitle != NULL )
 | 
			
		||||
    if (pszTitle != NULL) {
 | 
			
		||||
        strcpy(pcDlgData, pszTitle);
 | 
			
		||||
  else
 | 
			
		||||
    } else {
 | 
			
		||||
        *pcDlgData = '\0';
 | 
			
		||||
    }
 | 
			
		||||
    pcDlgData += pDlgItem->cchText;
 | 
			
		||||
 | 
			
		||||
    pDlgItem->flStyle = WS_GROUP | WS_VISIBLE | WS_CLIPSIBLINGS | 
 | 
			
		||||
@@ -300,9 +287,8 @@ static HWND _makeDlg(const SDL_MessageBoxData *messageboxdata)
 | 
			
		||||
    pDlgItem->id = DID_OK;     /* An ID value? */
 | 
			
		||||
    if (pSDLColors == NULL)
 | 
			
		||||
        pDlgItem->offPresParams = 0;
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    // Presentation parameter for the frame - dialog colors.
 | 
			
		||||
    else {
 | 
			
		||||
        /* Presentation parameter for the frame - dialog colors. */
 | 
			
		||||
        pDlgItem->offPresParams = pcDlgData - (PCHAR)pTemplate;
 | 
			
		||||
        ((PPRESPARAMS)pcDlgData)->cb = 22;
 | 
			
		||||
        pcDlgData += 4;
 | 
			
		||||
@@ -327,7 +313,6 @@ static HWND _makeDlg(const SDL_MessageBoxData *messageboxdata)
 | 
			
		||||
    pcDlgData += sizeof(ULONG);
 | 
			
		||||
 | 
			
		||||
    /* Second item info - static text (message). */
 | 
			
		||||
 | 
			
		||||
    pDlgItem++;
 | 
			
		||||
    pDlgItem->fsItemStatus = 0;
 | 
			
		||||
    /* No children since its a control, it could have child control */
 | 
			
		||||
@@ -340,25 +325,25 @@ static HWND _makeDlg(const SDL_MessageBoxData *messageboxdata)
 | 
			
		||||
    pDlgItem->cchText = cbText + 1;
 | 
			
		||||
    pDlgItem->offText = pcDlgData - (PCHAR)pTemplate;   /* Offset to the text. */
 | 
			
		||||
    /* Copy message text into the dialog template. */
 | 
			
		||||
  if ( pszText != NULL )
 | 
			
		||||
    if (pszText != NULL) {
 | 
			
		||||
        strcpy(pcDlgData, pszText);
 | 
			
		||||
  else
 | 
			
		||||
    } else {
 | 
			
		||||
      *pcDlgData = '\0';
 | 
			
		||||
    }
 | 
			
		||||
    pcDlgData += pDlgItem->cchText;
 | 
			
		||||
 | 
			
		||||
    pDlgItem->flStyle = SS_TEXT | DT_TOP | DT_LEFT | DT_WORDBREAK | WS_VISIBLE;
 | 
			
		||||
  // It will be really set in _wmInitDlg().
 | 
			
		||||
    /* It will be really set in _wmInitDlg(). */
 | 
			
		||||
    pDlgItem->x = 25;
 | 
			
		||||
    pDlgItem->y = 13;
 | 
			
		||||
    pDlgItem->cx = 147;
 | 
			
		||||
  pDlgItem->cy = 62;  // It will be used.
 | 
			
		||||
    pDlgItem->cy = 62;  /* It will be used. */
 | 
			
		||||
 | 
			
		||||
    pDlgItem->id = IDD_TEXT_MESSAGE;	  /* an ID value */
 | 
			
		||||
    if (pSDLColors == NULL)
 | 
			
		||||
        pDlgItem->offPresParams = 0;
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    // Presentation parameter for the static text - dialog colors.
 | 
			
		||||
    else {
 | 
			
		||||
        /* Presentation parameter for the static text - dialog colors. */
 | 
			
		||||
        pDlgItem->offPresParams = pcDlgData - (PCHAR)pTemplate;
 | 
			
		||||
        ((PPRESPARAMS)pcDlgData)->cb = 22;
 | 
			
		||||
        pcDlgData += 4;
 | 
			
		||||
@@ -378,29 +363,27 @@ static HWND _makeDlg(const SDL_MessageBoxData *messageboxdata)
 | 
			
		||||
    pDlgItem->offCtlData = 0;
 | 
			
		||||
 | 
			
		||||
    /* Third item info - static bitmap. */
 | 
			
		||||
 | 
			
		||||
    pDlgItem++;
 | 
			
		||||
    pDlgItem->fsItemStatus = 0;
 | 
			
		||||
    pDlgItem->cChildren = 0;
 | 
			
		||||
    pDlgItem->cchClassName = 0;
 | 
			
		||||
    pDlgItem->offClassName = (USHORT)WC_STATIC;
 | 
			
		||||
 | 
			
		||||
  pDlgItem->cchText = 3; // 0xFF, low byte of the icon Id, high byte of icon Id.
 | 
			
		||||
    pDlgItem->cchText = 3; /* 0xFF, low byte of the icon Id, high byte of icon Id. */
 | 
			
		||||
    pDlgItem->offText = pcDlgData - (PCHAR)pTemplate;   /* Offset to the Id. */
 | 
			
		||||
    /* Write susyem icon ID into dialog template. */
 | 
			
		||||
  *pcDlgData = 0xFF; // First byte is 0xFF - next 2 bytes is system pointer Id.
 | 
			
		||||
    *pcDlgData = 0xFF; /* First byte is 0xFF - next 2 bytes is system pointer Id. */
 | 
			
		||||
    pcDlgData++;
 | 
			
		||||
  *((PUSHORT)pcDlgData) = 
 | 
			
		||||
    (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) != 0
 | 
			
		||||
      ? SPTR_ICONERROR
 | 
			
		||||
      : (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) != 0
 | 
			
		||||
          ? SPTR_ICONWARNING : SPTR_ICONINFORMATION;
 | 
			
		||||
    *((PUSHORT)pcDlgData) = ((messageboxdata->flags & SDL_MESSAGEBOX_ERROR) != 0)?
 | 
			
		||||
                              SPTR_ICONERROR :
 | 
			
		||||
                                ((messageboxdata->flags & SDL_MESSAGEBOX_WARNING) != 0)?
 | 
			
		||||
                                  SPTR_ICONWARNING : SPTR_ICONINFORMATION;
 | 
			
		||||
    pcDlgData += 2;
 | 
			
		||||
 | 
			
		||||
    pDlgItem->flStyle = SS_SYSICON | WS_VISIBLE;
 | 
			
		||||
 | 
			
		||||
    pDlgItem->x = 4;
 | 
			
		||||
  pDlgItem->y = 45; // It will be really set in _wmInitDlg().
 | 
			
		||||
    pDlgItem->y = 45; /* It will be really set in _wmInitDlg(). */
 | 
			
		||||
    pDlgItem->cx = 0;
 | 
			
		||||
    pDlgItem->cy = 0;
 | 
			
		||||
 | 
			
		||||
@@ -409,9 +392,7 @@ static HWND _makeDlg(const SDL_MessageBoxData *messageboxdata)
 | 
			
		||||
    pDlgItem->offCtlData = 0;
 | 
			
		||||
 | 
			
		||||
    /* Next items - buttons. */
 | 
			
		||||
 | 
			
		||||
  for( ulIdx = 0; ulIdx < cSDLBtnData; ulIdx++ )
 | 
			
		||||
  {
 | 
			
		||||
    for (ulIdx = 0; ulIdx < cSDLBtnData; ulIdx++) {
 | 
			
		||||
        pDlgItem++;
 | 
			
		||||
 | 
			
		||||
        pDlgItem->fsItemStatus = 0;
 | 
			
		||||
@@ -420,29 +401,28 @@ static HWND _makeDlg(const SDL_MessageBoxData *messageboxdata)
 | 
			
		||||
        pDlgItem->offClassName = (USHORT)WC_BUTTON;
 | 
			
		||||
 | 
			
		||||
        pszBtnText = OS2_UTF8ToSys((PSZ)pSDLBtnData[ulIdx].text);
 | 
			
		||||
    cbBtnText = ( pszBtnText == NULL ?
 | 
			
		||||
                            0 : strlen( pszBtnText ) );
 | 
			
		||||
        cbBtnText = (pszBtnText == NULL)? 0 : strlen(pszBtnText);
 | 
			
		||||
        pDlgItem->cchText = cbBtnText + 1;
 | 
			
		||||
        pDlgItem->offText = pcDlgData - (PCHAR)pTemplate; /* Offset to the text. */
 | 
			
		||||
        /* Copy text for the button into the dialog template. */
 | 
			
		||||
    if ( pszBtnText != NULL )
 | 
			
		||||
        if (pszBtnText != NULL) {
 | 
			
		||||
            strcpy(pcDlgData, pszBtnText);
 | 
			
		||||
    else
 | 
			
		||||
        } else {
 | 
			
		||||
            *pcDlgData = '\0';
 | 
			
		||||
        }
 | 
			
		||||
        pcDlgData += pDlgItem->cchText;
 | 
			
		||||
        SDL_free(pszBtnText);
 | 
			
		||||
 | 
			
		||||
        pDlgItem->flStyle = BS_PUSHBUTTON | WS_TABSTOP | WS_VISIBLE;
 | 
			
		||||
    if ( pSDLBtnData[ulIdx].flags == SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT )
 | 
			
		||||
    {
 | 
			
		||||
        if (pSDLBtnData[ulIdx].flags == SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
 | 
			
		||||
            pDlgItem->flStyle |= BS_DEFAULT;
 | 
			
		||||
      pTemplate->iItemFocus = ulIdx + 3; // +3 - frame, static text and icon.
 | 
			
		||||
            pTemplate->iItemFocus = ulIdx + 3; /* +3 - frame, static text and icon. */
 | 
			
		||||
            pSDLColor = &pSDLColors[SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED];
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
        } else {
 | 
			
		||||
            pSDLColor = &pSDLColors[SDL_MESSAGEBOX_COLOR_TEXT];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    // It will be really set in _wmInitDlg()
 | 
			
		||||
        /* It will be really set in _wmInitDlg() */
 | 
			
		||||
        pDlgItem->x = 10;
 | 
			
		||||
        pDlgItem->y = 10;
 | 
			
		||||
        pDlgItem->cx = 70;
 | 
			
		||||
@@ -451,9 +431,8 @@ static HWND _makeDlg(const SDL_MessageBoxData *messageboxdata)
 | 
			
		||||
        pDlgItem->id = IDD_PB_FIRST + ulIdx;	  /* an ID value */
 | 
			
		||||
        if (pSDLColors == NULL)
 | 
			
		||||
          pDlgItem->offPresParams = 0;
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      // Presentation parameter for the button - dialog colors.
 | 
			
		||||
        else {
 | 
			
		||||
            /* Presentation parameter for the button - dialog colors. */
 | 
			
		||||
            pDlgItem->offPresParams = pcDlgData - (PCHAR)pTemplate;
 | 
			
		||||
            ((PPRESPARAMS)pcDlgData)->cb = 44;
 | 
			
		||||
            pcDlgData += 4;
 | 
			
		||||
@@ -484,17 +463,14 @@ static HWND _makeDlg(const SDL_MessageBoxData *messageboxdata)
 | 
			
		||||
        }
 | 
			
		||||
        pDlgItem->offCtlData = 0;
 | 
			
		||||
    }
 | 
			
		||||
  // Check, end of templ. data: &((PCHAR)pTemplate)[cbTemplate] == pcDlgData
 | 
			
		||||
 | 
			
		||||
  // Create the dialog from template.
 | 
			
		||||
    /* Check, end of templ. data: &((PCHAR)pTemplate)[cbTemplate] == pcDlgData */
 | 
			
		||||
 | 
			
		||||
    /* Create the dialog from template. */
 | 
			
		||||
    stDlgData.cb = sizeof(MSGBOXDLGDATA);
 | 
			
		||||
  stDlgData.hwndUnder = ( messageboxdata->window != NULL ) &&
 | 
			
		||||
                        ( messageboxdata->window->driverdata != NULL )
 | 
			
		||||
                          ? ((PWINDATA)messageboxdata->window->driverdata)->hwnd
 | 
			
		||||
                          : HWND_DESKTOP;
 | 
			
		||||
    stDlgData.hwndUnder = (messageboxdata->window != NULL && messageboxdata->window->driverdata != NULL)?
 | 
			
		||||
                            ((WINDATA *)messageboxdata->window->driverdata)->hwnd : HWND_DESKTOP;
 | 
			
		||||
 | 
			
		||||
  hwnd = WinCreateDlg( HWND_DESKTOP, // Parent is desktop.
 | 
			
		||||
    hwnd = WinCreateDlg(HWND_DESKTOP, /* Parent is desktop. */
 | 
			
		||||
                        stDlgData.hwndUnder,
 | 
			
		||||
                        (PFNWP)DynDlgProc, pTemplate, &stDlgData);
 | 
			
		||||
    SDL_free(pTemplate);
 | 
			
		||||
@@ -510,80 +486,68 @@ int OS2_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
 | 
			
		||||
    HWND    hwnd;
 | 
			
		||||
    ULONG   ulRC;
 | 
			
		||||
    SDL_MessageBoxButtonData
 | 
			
		||||
                       *pSDLBtnData =
 | 
			
		||||
                           (SDL_MessageBoxButtonData *)messageboxdata->buttons;
 | 
			
		||||
            *pSDLBtnData = (SDL_MessageBoxButtonData *)messageboxdata->buttons;
 | 
			
		||||
    ULONG   cSDLBtnData = messageboxdata->numbuttons;
 | 
			
		||||
    BOOL    fVideoInitialized = SDL_WasInit(SDL_INIT_VIDEO);
 | 
			
		||||
    HAB     hab;
 | 
			
		||||
    HMQ     hmq;
 | 
			
		||||
    BOOL    fSuccess = FALSE;
 | 
			
		||||
 | 
			
		||||
  if ( !fVideoInitialized )
 | 
			
		||||
  {
 | 
			
		||||
    if (!fVideoInitialized) {
 | 
			
		||||
        PTIB    tib;
 | 
			
		||||
        PPIB    pib;
 | 
			
		||||
 | 
			
		||||
        DosGetInfoBlocks(&tib, &pib);
 | 
			
		||||
    if ( pib->pib_ultype == 2 || pib->pib_ultype == 0 )
 | 
			
		||||
    {
 | 
			
		||||
      // VIO windowable or fullscreen protect-mode session.
 | 
			
		||||
      pib->pib_ultype = 3; // Presentation Manager protect-mode session.
 | 
			
		||||
        if (pib->pib_ultype == 2 || pib->pib_ultype == 0) {
 | 
			
		||||
            /* VIO windowable or fullscreen protect-mode session */
 | 
			
		||||
            pib->pib_ultype = 3; /* Presentation Manager protect-mode session */
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        hab = WinInitialize(0);
 | 
			
		||||
    if ( hab == NULLHANDLE )
 | 
			
		||||
    {
 | 
			
		||||
      debug( "WinInitialize() failed" );
 | 
			
		||||
        if (hab == NULLHANDLE) {
 | 
			
		||||
            debug_os2("WinInitialize() failed");
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
        hmq = WinCreateMsgQueue(hab, 0);
 | 
			
		||||
    if ( hmq == NULLHANDLE )
 | 
			
		||||
    {
 | 
			
		||||
      debug( "WinCreateMsgQueue() failed" );
 | 
			
		||||
        if (hmq == NULLHANDLE) {
 | 
			
		||||
            debug_os2("WinCreateMsgQueue() failed");
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  // Create dynamic dialog.
 | 
			
		||||
    /* Create dynamic dialog. */
 | 
			
		||||
    hwnd = _makeDlg(messageboxdata);
 | 
			
		||||
  // Show dialog and obtain button Id.
 | 
			
		||||
    /* Show dialog and obtain button Id. */
 | 
			
		||||
    ulRC = WinProcessDlg(hwnd);
 | 
			
		||||
  // Destroy dialog,
 | 
			
		||||
    /* Destroy dialog, */
 | 
			
		||||
    WinDestroyWindow(hwnd);
 | 
			
		||||
 | 
			
		||||
  if ( ulRC == DID_CANCEL )
 | 
			
		||||
  {
 | 
			
		||||
    // Window closed by ESC, Alt+F4 or system menu.
 | 
			
		||||
    if (ulRC == DID_CANCEL) {
 | 
			
		||||
        /* Window closed by ESC, Alt+F4 or system menu. */
 | 
			
		||||
        ULONG   ulIdx;
 | 
			
		||||
 | 
			
		||||
    for( ulIdx = 0; ulIdx < cSDLBtnData; ulIdx++, pSDLBtnData++ )
 | 
			
		||||
    {
 | 
			
		||||
      if ( pSDLBtnData->flags == SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT )
 | 
			
		||||
      {
 | 
			
		||||
        for (ulIdx = 0; ulIdx < cSDLBtnData; ulIdx++, pSDLBtnData++) {
 | 
			
		||||
            if (pSDLBtnData->flags == SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
 | 
			
		||||
                *buttonid = pSDLBtnData->buttonid;
 | 
			
		||||
                fSuccess = TRUE;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    // Button pressed.
 | 
			
		||||
    } else {
 | 
			
		||||
        /* Button pressed. */
 | 
			
		||||
        ulRC -= IDD_PB_FIRST;
 | 
			
		||||
    if ( ulRC < cSDLBtnData )
 | 
			
		||||
    {
 | 
			
		||||
        if (ulRC < cSDLBtnData) {
 | 
			
		||||
            *buttonid = pSDLBtnData[ulRC].buttonid;
 | 
			
		||||
            fSuccess = TRUE;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  if ( !fVideoInitialized )
 | 
			
		||||
  {
 | 
			
		||||
    if (!fVideoInitialized) {
 | 
			
		||||
        WinDestroyMsgQueue(hmq);
 | 
			
		||||
        WinTerminate(hab);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  return fSuccess ? 0 : -1;
 | 
			
		||||
    return (fSuccess)? 0 : -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif /* SDL_VIDEO_DRIVER_OS2 */
 | 
			
		||||
 
 | 
			
		||||
@@ -35,9 +35,8 @@ static SDL_Cursor* OS2_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y)
 | 
			
		||||
    HPOINTER    hptr;
 | 
			
		||||
    SDL_Cursor* pSDLCursor;
 | 
			
		||||
 | 
			
		||||
  if ( ( surface->w > ulMaxW ) || ( surface->h > ulMaxH ) )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "Given image size is %u x %u, maximum allowed size is %u x %u",
 | 
			
		||||
    if (surface->w > ulMaxW || surface->h > ulMaxH) {
 | 
			
		||||
        debug_os2("Given image size is %u x %u, maximum allowed size is %u x %u",
 | 
			
		||||
                  surface->w, surface->h, ulMaxW, ulMaxH);
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
@@ -47,8 +46,7 @@ static SDL_Cursor* OS2_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y)
 | 
			
		||||
        return NULL;
 | 
			
		||||
 | 
			
		||||
    pSDLCursor = SDL_calloc(1, sizeof(SDL_Cursor));
 | 
			
		||||
  if ( pSDLCursor == NULL )
 | 
			
		||||
  {
 | 
			
		||||
    if (pSDLCursor == NULL) {
 | 
			
		||||
        WinDestroyPointer(hptr);
 | 
			
		||||
        SDL_OutOfMemory();
 | 
			
		||||
        return NULL;
 | 
			
		||||
@@ -64,8 +62,7 @@ static SDL_Cursor* OS2_CreateSystemCursor(SDL_SystemCursor id)
 | 
			
		||||
    LONG        lSysId;
 | 
			
		||||
    HPOINTER    hptr;
 | 
			
		||||
 | 
			
		||||
  switch( id )
 | 
			
		||||
  {
 | 
			
		||||
    switch (id) {
 | 
			
		||||
    case SDL_SYSTEM_CURSOR_ARROW:     lSysId = SPTR_ARROW;    break;
 | 
			
		||||
    case SDL_SYSTEM_CURSOR_IBEAM:     lSysId = SPTR_TEXT;     break;
 | 
			
		||||
    case SDL_SYSTEM_CURSOR_WAIT:      lSysId = SPTR_WAIT;     break;
 | 
			
		||||
@@ -79,24 +76,22 @@ static SDL_Cursor* OS2_CreateSystemCursor(SDL_SystemCursor id)
 | 
			
		||||
    case SDL_SYSTEM_CURSOR_NO:        lSysId = SPTR_ILLEGAL;  break;
 | 
			
		||||
    case SDL_SYSTEM_CURSOR_HAND:      lSysId = SPTR_ARROW;    break;
 | 
			
		||||
    default:
 | 
			
		||||
      debug( "Unknown cursor id: %u", id );
 | 
			
		||||
        debug_os2("Unknown cursor id: %u", id);
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  // On eCS SPTR_WAIT for last paramether fCopy=TRUE/FALSE gives different
 | 
			
		||||
  // "wait" icons. -=8( )
 | 
			
		||||
    /* On eCS SPTR_WAIT for last paramether fCopy=TRUE/FALSE gives different
 | 
			
		||||
     * "wait" icons. -=8( ) */
 | 
			
		||||
    hptr = WinQuerySysPointer(HWND_DESKTOP, lSysId,
 | 
			
		||||
                              id == SDL_SYSTEM_CURSOR_WAIT);
 | 
			
		||||
  if ( hptr == NULLHANDLE )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "Cannot load OS/2 system pointer %u for SDL cursor id %u",
 | 
			
		||||
    if (hptr == NULLHANDLE) {
 | 
			
		||||
        debug_os2("Cannot load OS/2 system pointer %u for SDL cursor id %u",
 | 
			
		||||
                  lSysId, id);
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pSDLCursor = SDL_calloc(1, sizeof(SDL_Cursor));
 | 
			
		||||
  if ( pSDLCursor == NULL )
 | 
			
		||||
  {
 | 
			
		||||
    if (pSDLCursor == NULL) {
 | 
			
		||||
        WinDestroyPointer(hptr);
 | 
			
		||||
        SDL_OutOfMemory();
 | 
			
		||||
        return NULL;
 | 
			
		||||
@@ -116,21 +111,20 @@ static void OS2_FreeCursor(SDL_Cursor *cursor)
 | 
			
		||||
 | 
			
		||||
static int OS2_ShowCursor(SDL_Cursor *cursor)
 | 
			
		||||
{
 | 
			
		||||
  hptrCursor = cursor != NULL ? (HPOINTER)cursor->driverdata : NULLHANDLE;
 | 
			
		||||
 | 
			
		||||
    hptrCursor = (cursor != NULL)? (HPOINTER)cursor->driverdata : NULLHANDLE;
 | 
			
		||||
    return ((SDL_GetMouseFocus() == NULL) ||
 | 
			
		||||
             WinSetPointer(HWND_DESKTOP, hptrCursor))? 0 : -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void OS2_WarpMouse(SDL_Window * window, int x, int y)
 | 
			
		||||
{
 | 
			
		||||
  PWINDATA             pWinData = (PWINDATA)window->driverdata;
 | 
			
		||||
    WINDATA    *pWinData = (WINDATA *)window->driverdata;
 | 
			
		||||
    POINTL      pointl;
 | 
			
		||||
 | 
			
		||||
    pointl.x = x;
 | 
			
		||||
    pointl.y = window->h - y;
 | 
			
		||||
    WinMapWindowPoints(pWinData->hwnd, HWND_DESKTOP, &pointl, 1);
 | 
			
		||||
//  pWinData->lSkipWMMouseMove++; ???
 | 
			
		||||
/*  pWinData->lSkipWMMouseMove++; ???*/
 | 
			
		||||
    WinSetPointerPos(HWND_DESKTOP, pointl.x, pointl.y);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -143,10 +137,8 @@ static int OS2_WarpMouseGlobal(int x, int y)
 | 
			
		||||
 | 
			
		||||
static int OS2_CaptureMouse(SDL_Window *window)
 | 
			
		||||
{
 | 
			
		||||
  return WinSetCapture( HWND_DESKTOP,
 | 
			
		||||
                    window == NULL ? NULLHANDLE
 | 
			
		||||
                                   : ((PWINDATA)window->driverdata)->hwnd )
 | 
			
		||||
           ? 0 : -1;
 | 
			
		||||
    return WinSetCapture(HWND_DESKTOP, (window == NULL)? NULLHANDLE :
 | 
			
		||||
                                         ((WINDATA *)window->driverdata)->hwnd)? 0 : -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static Uint32 OS2_GetGlobalMouseState(int *x, int *y)
 | 
			
		||||
@@ -158,8 +150,7 @@ static Uint32 OS2_GetGlobalMouseState(int *x, int *y)
 | 
			
		||||
    *x = pointl.x;
 | 
			
		||||
    *y = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN) - pointl.y - 1;
 | 
			
		||||
 | 
			
		||||
  ulRes = WinGetKeyState( HWND_DESKTOP, VK_BUTTON1 ) & 0x8000
 | 
			
		||||
            ? SDL_BUTTON_LMASK : 0;
 | 
			
		||||
    ulRes = (WinGetKeyState(HWND_DESKTOP, VK_BUTTON1) & 0x8000)? SDL_BUTTON_LMASK : 0;
 | 
			
		||||
    if (WinGetKeyState(HWND_DESKTOP, VK_BUTTON2) & 0x8000)
 | 
			
		||||
        ulRes |= SDL_BUTTON_RMASK;
 | 
			
		||||
    if (WinGetKeyState(HWND_DESKTOP, VK_BUTTON3) & 0x8000)
 | 
			
		||||
@@ -191,8 +182,7 @@ void OS2_QuitMouse(_THIS)
 | 
			
		||||
{
 | 
			
		||||
    SDL_Mouse   *pSDLMouse = SDL_GetMouse();
 | 
			
		||||
 | 
			
		||||
  if ( pSDLMouse->def_cursor != NULL )
 | 
			
		||||
  {
 | 
			
		||||
    if (pSDLMouse->def_cursor != NULL) {
 | 
			
		||||
        SDL_free(pSDLMouse->def_cursor);
 | 
			
		||||
        pSDLMouse->def_cursor = NULL;
 | 
			
		||||
        pSDLMouse->cur_cursor = NULL;
 | 
			
		||||
@@ -200,3 +190,5 @@ void OS2_QuitMouse(_THIS)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif /* SDL_VIDEO_DRIVER_OS2 */
 | 
			
		||||
 | 
			
		||||
/* vi: set ts=4 sw=4 expandtab: */
 | 
			
		||||
 
 | 
			
		||||
@@ -31,24 +31,29 @@ typedef struct _VIDEOOUTPUTINFO {
 | 
			
		||||
    ULONG     ulScanLineSize;
 | 
			
		||||
    ULONG     ulHorizResolution;
 | 
			
		||||
    ULONG     ulVertResolution;
 | 
			
		||||
} VIDEOOUTPUTINFO, *PVIDEOOUTPUTINFO;
 | 
			
		||||
} VIDEOOUTPUTINFO;
 | 
			
		||||
 | 
			
		||||
typedef struct _OS2VIDEOOUTPUT {
 | 
			
		||||
  BOOL (*QueryInfo)(PVIDEOOUTPUTINFO pInfo);
 | 
			
		||||
    BOOL (*QueryInfo)(VIDEOOUTPUTINFO *pInfo);
 | 
			
		||||
    PVODATA (*Open)();
 | 
			
		||||
    VOID (*Close)(PVODATA pVOData);
 | 
			
		||||
 | 
			
		||||
    BOOL (*SetVisibleRegion)(PVODATA pVOData, HWND hwnd,
 | 
			
		||||
                             SDL_DisplayMode *pSDLDisplayMode, HRGN hrgnShape,
 | 
			
		||||
                             BOOL fVisible);
 | 
			
		||||
 | 
			
		||||
    PVOID (*VideoBufAlloc)(PVODATA pVOData, ULONG ulWidth, ULONG ulHeight,
 | 
			
		||||
                           ULONG ulBPP, ULONG fccColorEncoding,
 | 
			
		||||
                           PULONG pulScanLineSize);
 | 
			
		||||
 | 
			
		||||
    VOID (*VideoBufFree)(PVODATA pVOData);
 | 
			
		||||
    BOOL (*Update)(PVODATA pVOData, HWND hwnd, SDL_Rect *pSDLRects,
 | 
			
		||||
                   ULONG cSDLRects);
 | 
			
		||||
} OS2VIDEOOUTPUT, *POS2VIDEOOUTPUT;
 | 
			
		||||
} OS2VIDEOOUTPUT;
 | 
			
		||||
 | 
			
		||||
extern OS2VIDEOOUTPUT voDive;
 | 
			
		||||
extern OS2VIDEOOUTPUT voVMan;
 | 
			
		||||
 | 
			
		||||
#endif /* SDL_os2output_ */
 | 
			
		||||
 | 
			
		||||
/* vi: set ts=4 sw=4 expandtab: */
 | 
			
		||||
 
 | 
			
		||||
@@ -24,7 +24,6 @@
 | 
			
		||||
 | 
			
		||||
#include "SDL_os2util.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
HPOINTER utilCreatePointer(SDL_Surface *surface, ULONG ulHotX, ULONG ulHotY)
 | 
			
		||||
{
 | 
			
		||||
    HBITMAP             hbm;
 | 
			
		||||
@@ -36,51 +35,43 @@ HPOINTER utilCreatePointer(SDL_Surface *surface, ULONG ulHotX, ULONG ulHotY)
 | 
			
		||||
    ULONG               ulY, ulX;
 | 
			
		||||
    HPOINTER            hptr = NULLHANDLE;
 | 
			
		||||
 | 
			
		||||
  if ( surface->format->format != SDL_PIXELFORMAT_ARGB8888 )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "Image format should be SDL_PIXELFORMAT_ARGB8888" );
 | 
			
		||||
    if (surface->format->format != SDL_PIXELFORMAT_ARGB8888) {
 | 
			
		||||
        debug_os2("Image format should be SDL_PIXELFORMAT_ARGB8888");
 | 
			
		||||
        return NULLHANDLE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pulBitmap = SDL_malloc(surface->h * surface->w * 4 * 2);
 | 
			
		||||
  if ( pulBitmap == NULL )
 | 
			
		||||
  {
 | 
			
		||||
    if (pulBitmap == NULL) {
 | 
			
		||||
        SDL_OutOfMemory();
 | 
			
		||||
        return NULLHANDLE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  // pulDst - last line of surface (image) part of the result bitmap
 | 
			
		||||
    /* pulDst - last line of surface (image) part of the result bitmap */
 | 
			
		||||
    pulDst = &pulBitmap[ (surface->h - 1) * surface->w ];
 | 
			
		||||
  // pulDstMask - last line of mask part of the result bitmap
 | 
			
		||||
    /* pulDstMask - last line of mask part of the result bitmap */
 | 
			
		||||
    pulDstMask = &pulBitmap[ (2 * surface->h - 1) * surface->w ];
 | 
			
		||||
  // pulSrc - first line of source image
 | 
			
		||||
    /* pulSrc - first line of source image */
 | 
			
		||||
    pulSrc = (PULONG)surface->pixels;
 | 
			
		||||
 | 
			
		||||
  for( ulY = 0; ulY < surface->h; ulY++ )
 | 
			
		||||
  {
 | 
			
		||||
    for( ulX = 0; ulX < surface->w; ulX++ )
 | 
			
		||||
    {
 | 
			
		||||
      if ( (pulSrc[ulX] & 0xFF000000) == 0 )
 | 
			
		||||
      {
 | 
			
		||||
    for (ulY = 0; ulY < surface->h; ulY++) {
 | 
			
		||||
        for (ulX = 0; ulX < surface->w; ulX++) {
 | 
			
		||||
            if ((pulSrc[ulX] & 0xFF000000) == 0) {
 | 
			
		||||
                pulDst[ulX] = 0;
 | 
			
		||||
                pulDstMask[ulX] = 0xFFFFFFFF;
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
            } else {
 | 
			
		||||
                pulDst[ulX] = pulSrc[ulX] & 0xFFFFFF;
 | 
			
		||||
                pulDstMask[ulX] = 0;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    // Set image and mask pointers on one line up
 | 
			
		||||
        /* Set image and mask pointers on one line up */
 | 
			
		||||
        pulDst -= surface->w;
 | 
			
		||||
        pulDstMask -= surface->w;
 | 
			
		||||
    // Set source image pointer to the next line
 | 
			
		||||
        /* Set source image pointer to the next line */
 | 
			
		||||
        pulSrc = (PULONG) (((PCHAR)pulSrc) + surface->pitch);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  // Create system bitmap object.
 | 
			
		||||
 | 
			
		||||
    /* Create system bitmap object. */
 | 
			
		||||
    bmih.cbFix          = sizeof(BITMAPINFOHEADER2);
 | 
			
		||||
    bmih.cx             = surface->w;
 | 
			
		||||
    bmih.cy             = 2 * surface->h;
 | 
			
		||||
@@ -98,14 +89,14 @@ HPOINTER utilCreatePointer(SDL_Surface *surface, ULONG ulHotX, ULONG ulHotY)
 | 
			
		||||
    hps = WinGetPS(HWND_DESKTOP);
 | 
			
		||||
    hbm = GpiCreateBitmap(hps, (PBITMAPINFOHEADER2)&bmih, CBM_INIT,
 | 
			
		||||
                          (PBYTE)pulBitmap, (PBITMAPINFO2)&bmi);
 | 
			
		||||
  if ( hbm == GPI_ERROR )
 | 
			
		||||
    debug( "GpiCreateBitmap() failed" );
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    // Create a system pointer object.
 | 
			
		||||
    if (hbm == GPI_ERROR) {
 | 
			
		||||
        debug_os2("GpiCreateBitmap() failed");
 | 
			
		||||
    } else {
 | 
			
		||||
        /* Create a system pointer object. */
 | 
			
		||||
        hptr = WinCreatePointer(HWND_DESKTOP, hbm, TRUE, ulHotX, ulHotY);
 | 
			
		||||
    if ( hptr == NULLHANDLE )
 | 
			
		||||
      debug( "WinCreatePointer() failed" );
 | 
			
		||||
        if (hptr == NULLHANDLE) {
 | 
			
		||||
            debug_os2("WinCreatePointer() failed");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    GpiDeleteBitmap(hbm);
 | 
			
		||||
 | 
			
		||||
@@ -116,3 +107,5 @@ HPOINTER utilCreatePointer(SDL_Surface *surface, ULONG ulHotX, ULONG ulHotY)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif /* SDL_VIDEO_DRIVER_OS2 */
 | 
			
		||||
 | 
			
		||||
/* vi: set ts=4 sw=4 expandtab: */
 | 
			
		||||
 
 | 
			
		||||
@@ -33,3 +33,6 @@
 | 
			
		||||
HPOINTER utilCreatePointer(SDL_Surface *surface, ULONG ulHotX, ULONG ulHotY);
 | 
			
		||||
 | 
			
		||||
#endif /* SDL_os2util_h_ */
 | 
			
		||||
 | 
			
		||||
/* vi: set ts=4 sw=4 expandtab: */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -41,18 +41,18 @@
 | 
			
		||||
typedef struct SDL_VideoData {
 | 
			
		||||
    HAB             hab;
 | 
			
		||||
    HMQ             hmq;
 | 
			
		||||
  POS2VIDEOOUTPUT      pOutput;            // Video output routines.
 | 
			
		||||
} SDL_VideoData, *PSDL_VideoData;
 | 
			
		||||
    OS2VIDEOOUTPUT *pOutput; /* Video output routines */
 | 
			
		||||
} SDL_VideoData;
 | 
			
		||||
 | 
			
		||||
typedef struct _WINDATA {
 | 
			
		||||
    SDL_Window     *window;
 | 
			
		||||
  POS2VIDEOOUTPUT      pOutput;            // Video output routines.
 | 
			
		||||
    OS2VIDEOOUTPUT *pOutput; /* Video output routines */
 | 
			
		||||
    HWND            hwndFrame;
 | 
			
		||||
    HWND            hwnd;
 | 
			
		||||
    PFNWP           fnUserWndProc;
 | 
			
		||||
    PFNWP           fnWndFrameProc;
 | 
			
		||||
 | 
			
		||||
  PVODATA              pVOData;            // Video output data.
 | 
			
		||||
    PVODATA         pVOData; /* Video output data */
 | 
			
		||||
 | 
			
		||||
    HRGN            hrgnShape;
 | 
			
		||||
    HPOINTER        hptrIcon;
 | 
			
		||||
@@ -63,19 +63,20 @@ typedef struct _WINDATA {
 | 
			
		||||
    LONG            lSkipWMMouseMove;
 | 
			
		||||
    LONG            lSkipWMVRNEnabled;
 | 
			
		||||
    LONG            lSkipWMAdjustFramePos;
 | 
			
		||||
} WINDATA, *PWINDATA;
 | 
			
		||||
} WINDATA;
 | 
			
		||||
 | 
			
		||||
typedef struct _DISPLAYDATA {
 | 
			
		||||
    ULONG           ulDPIHor;
 | 
			
		||||
    ULONG           ulDPIVer;
 | 
			
		||||
    ULONG           ulDPIDiag;
 | 
			
		||||
} DISPLAYDATA, *PDISPLAYDATA;
 | 
			
		||||
} DISPLAYDATA;
 | 
			
		||||
 | 
			
		||||
typedef struct _MODEDATA {
 | 
			
		||||
    ULONG           ulDepth;
 | 
			
		||||
    ULONG           fccColorEncoding;
 | 
			
		||||
    ULONG           ulScanLineBytes;
 | 
			
		||||
} MODEDATA, *PMODEDATA;
 | 
			
		||||
 | 
			
		||||
} MODEDATA;
 | 
			
		||||
 | 
			
		||||
#endif /* SDL_os2video_h_ */
 | 
			
		||||
 | 
			
		||||
/* vi: set ts=4 sw=4 expandtab: */
 | 
			
		||||
 
 | 
			
		||||
@@ -50,7 +50,7 @@ typedef struct _VODATA {
 | 
			
		||||
  ULONG    cBltRect;
 | 
			
		||||
} VODATA;
 | 
			
		||||
 | 
			
		||||
static BOOL voQueryInfo(PVIDEOOUTPUTINFO pInfo);
 | 
			
		||||
static BOOL voQueryInfo(VIDEOOUTPUTINFO *pInfo);
 | 
			
		||||
static PVODATA voOpen();
 | 
			
		||||
static VOID voClose(PVODATA pVOData);
 | 
			
		||||
static BOOL voSetVisibleRegion(PVODATA pVOData, HWND hwnd,
 | 
			
		||||
@@ -80,8 +80,7 @@ static ULONG           ulVRAMAddress = 0;
 | 
			
		||||
 | 
			
		||||
VOID APIENTRY ExitVMan(VOID)
 | 
			
		||||
{
 | 
			
		||||
  if ( ( ulVRAMAddress != 0 ) && ( hmodVMan != NULLHANDLE ) )
 | 
			
		||||
  {
 | 
			
		||||
    if (ulVRAMAddress != 0 && hmodVMan != NULLHANDLE) {
 | 
			
		||||
        pfnVMIEntry(0, VMI_CMD_TERMPROC, NULL, NULL);
 | 
			
		||||
        DosFreeModule(hmodVMan);
 | 
			
		||||
    }
 | 
			
		||||
@@ -89,54 +88,50 @@ VOID APIENTRY ExitVMan(VOID)
 | 
			
		||||
    DosExitList(EXLST_EXIT, (PFNEXITLIST)NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static BOOL _vmanInit()
 | 
			
		||||
static BOOL _vmanInit(void)
 | 
			
		||||
{
 | 
			
		||||
    ULONG       ulRC;
 | 
			
		||||
    CHAR        acBuf[255];
 | 
			
		||||
    INITPROCOUT stInitProcOut;
 | 
			
		||||
 | 
			
		||||
  if ( hmodVMan != NULLHANDLE )
 | 
			
		||||
    // Already was initialized.
 | 
			
		||||
    if (hmodVMan != NULLHANDLE) /* Already was initialized */
 | 
			
		||||
        return TRUE;
 | 
			
		||||
 | 
			
		||||
  // Load vman.dll
 | 
			
		||||
    /* Load vman.dll */
 | 
			
		||||
    ulRC = DosLoadModule(acBuf, sizeof(acBuf), "VMAN", &hmodVMan);
 | 
			
		||||
  if ( ulRC != NO_ERROR )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "Could not load VMAN.DLL, rc = %u : %s", ulRC, &acBuf );
 | 
			
		||||
    if (ulRC != NO_ERROR) {
 | 
			
		||||
        debug_os2("Could not load VMAN.DLL, rc = %u : %s", ulRC, acBuf);
 | 
			
		||||
        hmodVMan = NULLHANDLE;
 | 
			
		||||
        return FALSE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  // Get VMIEntry.
 | 
			
		||||
    /* Get VMIEntry */
 | 
			
		||||
    ulRC = DosQueryProcAddr(hmodVMan, 0L, "VMIEntry", (PFN *)&pfnVMIEntry);
 | 
			
		||||
  if ( ulRC != NO_ERROR )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "Could not query address of pfnVMIEntry func. of VMAN.DLL, "
 | 
			
		||||
    if (ulRC != NO_ERROR) {
 | 
			
		||||
        debug_os2("Could not query address of pfnVMIEntry func. of VMAN.DLL, "
 | 
			
		||||
                  "rc = %u", ulRC);
 | 
			
		||||
        DosFreeModule(hmodVMan);
 | 
			
		||||
        hmodVMan = NULLHANDLE;
 | 
			
		||||
        return FALSE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  // VMAN initialization.
 | 
			
		||||
    /* VMAN initialization */
 | 
			
		||||
    stInitProcOut.ulLength = sizeof(stInitProcOut);
 | 
			
		||||
    ulRC = pfnVMIEntry(0, VMI_CMD_INITPROC, NULL, &stInitProcOut);
 | 
			
		||||
  if ( ulRC != RC_SUCCESS )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "Could not initialize VMAN for this process" );
 | 
			
		||||
    if (ulRC != RC_SUCCESS) {
 | 
			
		||||
        debug_os2("Could not initialize VMAN for this process");
 | 
			
		||||
        pfnVMIEntry = NULL;
 | 
			
		||||
        DosFreeModule(hmodVMan);
 | 
			
		||||
        hmodVMan = NULLHANDLE;
 | 
			
		||||
        return FALSE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  // Store video memory virtual address.
 | 
			
		||||
    /* Store video memory virtual address */
 | 
			
		||||
    ulVRAMAddress = stInitProcOut.ulVRAMVirt;
 | 
			
		||||
  // We use exit list for VMI_CMD_TERMPROC.
 | 
			
		||||
  if ( DosExitList( EXLST_ADD | 0x00001000, (PFNEXITLIST)ExitVMan )
 | 
			
		||||
       != NO_ERROR )
 | 
			
		||||
    debug( "DosExitList() failed" );
 | 
			
		||||
    /* We use exit list for VMI_CMD_TERMPROC */
 | 
			
		||||
    if (DosExitList(EXLST_ADD | 0x00001000, (PFNEXITLIST)ExitVMan) != NO_ERROR) {
 | 
			
		||||
        debug_os2("DosExitList() failed");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return TRUE;
 | 
			
		||||
}
 | 
			
		||||
@@ -174,7 +169,7 @@ static PBLTRECT _getBltRectArray(PVODATA pVOData, ULONG cRects)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static BOOL voQueryInfo(PVIDEOOUTPUTINFO pInfo)
 | 
			
		||||
static BOOL voQueryInfo(VIDEOOUTPUTINFO *pInfo)
 | 
			
		||||
{
 | 
			
		||||
    ULONG       ulRC;
 | 
			
		||||
    GDDMODEINFO sCurModeInfo;
 | 
			
		||||
@@ -182,11 +177,10 @@ static BOOL voQueryInfo(PVIDEOOUTPUTINFO pInfo)
 | 
			
		||||
    if (!_vmanInit())
 | 
			
		||||
        return FALSE;
 | 
			
		||||
 | 
			
		||||
  // Query current (desktop) mode.
 | 
			
		||||
    /* Query current (desktop) mode */
 | 
			
		||||
    ulRC = pfnVMIEntry(0, VMI_CMD_QUERYCURRENTMODE, NULL, &sCurModeInfo);
 | 
			
		||||
  if ( ulRC != RC_SUCCESS )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "Could not query desktop video mode." );
 | 
			
		||||
    if (ulRC != RC_SUCCESS) {
 | 
			
		||||
        debug_os2("Could not query desktop video mode.");
 | 
			
		||||
        return FALSE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -199,7 +193,7 @@ static BOOL voQueryInfo(PVIDEOOUTPUTINFO pInfo)
 | 
			
		||||
    return TRUE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static PVODATA voOpen()
 | 
			
		||||
static PVODATA voOpen(void)
 | 
			
		||||
{
 | 
			
		||||
    PVODATA pVOData;
 | 
			
		||||
 | 
			
		||||
@@ -207,8 +201,7 @@ static PVODATA voOpen()
 | 
			
		||||
        return NULL;
 | 
			
		||||
 | 
			
		||||
    pVOData = SDL_calloc(1, sizeof(VODATA));
 | 
			
		||||
  if ( pVOData == NULL )
 | 
			
		||||
  {
 | 
			
		||||
    if (pVOData == NULL) {
 | 
			
		||||
        SDL_OutOfMemory();
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
@@ -236,30 +229,21 @@ static BOOL voSetVisibleRegion(PVODATA pVOData, HWND hwnd,
 | 
			
		||||
 | 
			
		||||
    hps = WinGetPS(hwnd);
 | 
			
		||||
 | 
			
		||||
  if ( pVOData->hrgnVisible != NULLHANDLE )
 | 
			
		||||
  {
 | 
			
		||||
    if (pVOData->hrgnVisible != NULLHANDLE) {
 | 
			
		||||
        GpiDestroyRegion(hps, pVOData->hrgnVisible);
 | 
			
		||||
        pVOData->hrgnVisible = NULLHANDLE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  if ( fVisible )
 | 
			
		||||
  {
 | 
			
		||||
    // Query visible rectangles
 | 
			
		||||
 | 
			
		||||
    if (fVisible) {
 | 
			
		||||
        /* Query visible rectangles */
 | 
			
		||||
        pVOData->hrgnVisible = GpiCreateRegion(hps, 0, NULL);
 | 
			
		||||
    if ( pVOData->hrgnVisible == NULLHANDLE )
 | 
			
		||||
    {
 | 
			
		||||
        if (pVOData->hrgnVisible == NULLHANDLE) {
 | 
			
		||||
            SDL_SetError("GpiCreateRegion() failed");
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      if ( WinQueryVisibleRegion( hwnd, pVOData->hrgnVisible ) == RGN_ERROR )
 | 
			
		||||
      {
 | 
			
		||||
        } else {
 | 
			
		||||
            if (WinQueryVisibleRegion(hwnd, pVOData->hrgnVisible) == RGN_ERROR) {
 | 
			
		||||
                GpiDestroyRegion(hps, pVOData->hrgnVisible);
 | 
			
		||||
                pVOData->hrgnVisible = NULLHANDLE;
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
            } else {
 | 
			
		||||
                if (hrgnShape != NULLHANDLE)
 | 
			
		||||
                    GpiCombineRegion(hps, pVOData->hrgnVisible, pVOData->hrgnVisible,
 | 
			
		||||
                                     hrgnShape, CRGN_AND);
 | 
			
		||||
@@ -270,11 +254,10 @@ static BOOL voSetVisibleRegion(PVODATA pVOData, HWND hwnd,
 | 
			
		||||
        WinQueryWindowRect(hwnd, &pVOData->rectlWin);
 | 
			
		||||
        WinMapWindowPoints(hwnd, HWND_DESKTOP, (PPOINTL)&pVOData->rectlWin, 2);
 | 
			
		||||
 | 
			
		||||
    if ( pSDLDisplayMode != NULL )
 | 
			
		||||
    {
 | 
			
		||||
        if (pSDLDisplayMode != NULL) {
 | 
			
		||||
            pVOData->ulScreenHeight = pSDLDisplayMode->h;
 | 
			
		||||
            pVOData->ulScreenBytesPerLine =
 | 
			
		||||
                     ((PMODEDATA)pSDLDisplayMode->driverdata)->ulScanLineBytes;
 | 
			
		||||
                     ((MODEDATA *)pSDLDisplayMode->driverdata)->ulScanLineBytes;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -290,22 +273,21 @@ static PVOID voVideoBufAlloc(PVODATA pVOData, ULONG ulWidth, ULONG ulHeight,
 | 
			
		||||
    ULONG ulRC;
 | 
			
		||||
    ULONG ulScanLineSize = ulWidth * (ulBPP >> 3);
 | 
			
		||||
 | 
			
		||||
  // Destroy previous buffer.
 | 
			
		||||
    /* Destroy previous buffer */
 | 
			
		||||
    voVideoBufFree(pVOData);
 | 
			
		||||
 | 
			
		||||
  if ( ( ulWidth == 0 ) || ( ulHeight == 0 ) || ( ulBPP == 0 ) )
 | 
			
		||||
    if (ulWidth == 0 || ulHeight == 0 || ulBPP == 0)
 | 
			
		||||
        return NULL;
 | 
			
		||||
 | 
			
		||||
  // Bytes per line.
 | 
			
		||||
    /* Bytes per line */
 | 
			
		||||
    ulScanLineSize  = (ulScanLineSize + 3) & ~3; /* 4-byte aligning */
 | 
			
		||||
    *pulScanLineSize = ulScanLineSize;
 | 
			
		||||
 | 
			
		||||
    ulRC = DosAllocMem(&pVOData->pBuffer,
 | 
			
		||||
                       (ulHeight * ulScanLineSize) + sizeof(ULONG),
 | 
			
		||||
                       PAG_COMMIT | PAG_EXECUTE | PAG_READ | PAG_WRITE);
 | 
			
		||||
  if ( ulRC != NO_ERROR )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "DosAllocMem(), rc = %u", ulRC );
 | 
			
		||||
    if (ulRC != NO_ERROR) {
 | 
			
		||||
        debug_os2("DosAllocMem(), rc = %u", ulRC);
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -325,11 +307,12 @@ static VOID voVideoBufFree(PVODATA pVOData)
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
    ulRC = DosFreeMem(pVOData->pBuffer);
 | 
			
		||||
  if ( ulRC != NO_ERROR )
 | 
			
		||||
    debug( "DosFreeMem(), rc = %u", ulRC );
 | 
			
		||||
  else
 | 
			
		||||
    if (ulRC != NO_ERROR) {
 | 
			
		||||
        debug_os2("DosFreeMem(), rc = %u", ulRC);
 | 
			
		||||
    } else {
 | 
			
		||||
        pVOData->pBuffer = NULL;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static BOOL voUpdate(PVODATA pVOData, HWND hwnd, SDL_Rect *pSDLRects,
 | 
			
		||||
                     ULONG cSDLRects)
 | 
			
		||||
@@ -346,7 +329,7 @@ static BOOL voUpdate(PVODATA pVOData, HWND hwnd, SDL_Rect *pSDLRects,
 | 
			
		||||
    HWREQIN     sHWReqIn;
 | 
			
		||||
    BITBLTINFO  sBitbltInfo = { 0 };
 | 
			
		||||
    ULONG       ulIdx;
 | 
			
		||||
//  RECTL                rectlScreenUpdate;
 | 
			
		||||
/*  RECTL       rectlScreenUpdate;*/
 | 
			
		||||
 | 
			
		||||
    if (pVOData->pBuffer == NULL)
 | 
			
		||||
        return FALSE;
 | 
			
		||||
@@ -370,12 +353,10 @@ static BOOL voUpdate(PVODATA pVOData, HWND hwnd, SDL_Rect *pSDLRects,
 | 
			
		||||
    bmiDst.ulBpp = bmiSrc.ulBpp;
 | 
			
		||||
    bmiDst.ulBytesPerLine = pVOData->ulScreenBytesPerLine;
 | 
			
		||||
 | 
			
		||||
  // List of update rectangles. This is the intersection of requested
 | 
			
		||||
  // rectangles and visible rectangles.
 | 
			
		||||
 | 
			
		||||
  if ( cSDLRects == 0 )
 | 
			
		||||
  {
 | 
			
		||||
    // Full update requested.
 | 
			
		||||
    /* List of update rectangles. This is the intersection of requested
 | 
			
		||||
     * rectangles and visible rectangles.  */
 | 
			
		||||
    if (cSDLRects == 0) {
 | 
			
		||||
        /* Full update requested */
 | 
			
		||||
        stSDLRectDef.x = 0;
 | 
			
		||||
        stSDLRectDef.y = 0;
 | 
			
		||||
        stSDLRectDef.w = bmiSrc.ulWidth;
 | 
			
		||||
@@ -384,17 +365,15 @@ static BOOL voUpdate(PVODATA pVOData, HWND hwnd, SDL_Rect *pSDLRects,
 | 
			
		||||
        cSDLRects = 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  // Make list of destionation rectangles (prectlDst) list from the source
 | 
			
		||||
  // list (prectl).
 | 
			
		||||
    /* Make list of destination rectangles (prectlDst) list from the source
 | 
			
		||||
     * list (prectl).  */
 | 
			
		||||
    prectlDst = _getRectlArray(pVOData, cSDLRects);
 | 
			
		||||
  if ( prectlDst == NULL )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "Not enough memory" );
 | 
			
		||||
    if (prectlDst == NULL) {
 | 
			
		||||
        debug_os2("Not enough memory");
 | 
			
		||||
        return FALSE;
 | 
			
		||||
    }
 | 
			
		||||
    prectlScan = prectlDst;
 | 
			
		||||
  for( ulIdx = 0; ulIdx < cSDLRects; ulIdx++, pSDLRects++, prectlScan++ )
 | 
			
		||||
  {
 | 
			
		||||
    for (ulIdx = 0; ulIdx < cSDLRects; ulIdx++, pSDLRects++, prectlScan++) {
 | 
			
		||||
        prectlScan->xLeft   = pSDLRects->x;
 | 
			
		||||
        prectlScan->yTop    = pVOData->ulHeight - pSDLRects->y;
 | 
			
		||||
        prectlScan->xRight  = prectlScan->xLeft + pSDLRects->w;
 | 
			
		||||
@@ -405,29 +384,26 @@ static BOOL voUpdate(PVODATA pVOData, HWND hwnd, SDL_Rect *pSDLRects,
 | 
			
		||||
    if (hps == NULLHANDLE)
 | 
			
		||||
        return FALSE;
 | 
			
		||||
 | 
			
		||||
  // Make destination region to update.
 | 
			
		||||
    /* Make destination region to update */
 | 
			
		||||
    hrgnUpdate = GpiCreateRegion(hps, cSDLRects, prectlDst);
 | 
			
		||||
  // "AND" on visible and destination regions, result is region to update.
 | 
			
		||||
  GpiCombineRegion( hps, hrgnUpdate, hrgnUpdate, pVOData->hrgnVisible,
 | 
			
		||||
                    CRGN_AND );
 | 
			
		||||
    /* "AND" on visible and destination regions, result is region to update */
 | 
			
		||||
    GpiCombineRegion(hps, hrgnUpdate, hrgnUpdate, pVOData->hrgnVisible, CRGN_AND);
 | 
			
		||||
 | 
			
		||||
  // Get rectangles of the region to update.
 | 
			
		||||
    /* Get rectangles of the region to update */
 | 
			
		||||
    rgnCtl.ircStart     = 1;
 | 
			
		||||
    rgnCtl.crc          = 0;
 | 
			
		||||
    rgnCtl.ulDirection  = 1;
 | 
			
		||||
    rgnCtl.crcReturned  = 0;
 | 
			
		||||
    GpiQueryRegionRects(hps, hrgnUpdate, NULL, &rgnCtl, NULL);
 | 
			
		||||
  if ( rgnCtl.crcReturned == 0 )
 | 
			
		||||
  {
 | 
			
		||||
    if (rgnCtl.crcReturned == 0) {
 | 
			
		||||
        GpiDestroyRegion(hps, hrgnUpdate);
 | 
			
		||||
        WinReleasePS(hps);
 | 
			
		||||
        return TRUE;
 | 
			
		||||
    }
 | 
			
		||||
  // We don't need prectlDst, use it again to store update regions.
 | 
			
		||||
    /* We don't need prectlDst, use it again to store update regions */
 | 
			
		||||
    prectlDst = _getRectlArray(pVOData, rgnCtl.crcReturned);
 | 
			
		||||
  if ( prectlDst == NULL )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "Not enough memory" );
 | 
			
		||||
    if (prectlDst == NULL) {
 | 
			
		||||
        debug_os2("Not enough memory");
 | 
			
		||||
        GpiDestroyRegion(hps, hrgnUpdate);
 | 
			
		||||
        WinReleasePS(hps);
 | 
			
		||||
        return FALSE;
 | 
			
		||||
@@ -439,21 +415,19 @@ static BOOL voUpdate(PVODATA pVOData, HWND hwnd, SDL_Rect *pSDLRects,
 | 
			
		||||
    GpiDestroyRegion(hps, hrgnUpdate);
 | 
			
		||||
    WinReleasePS(hps);
 | 
			
		||||
    cSDLRects = rgnCtl.crcReturned;
 | 
			
		||||
  // Now cRect/prectlDst is a list of regions in window (update && visible).
 | 
			
		||||
 | 
			
		||||
  // Make lists for blitting from update regions.
 | 
			
		||||
    /* Now cRect/prectlDst is a list of regions in window (update && visible) */
 | 
			
		||||
 | 
			
		||||
    /* Make lists for blitting from update regions */
 | 
			
		||||
    pbrDst = _getBltRectArray(pVOData, cSDLRects);
 | 
			
		||||
  if ( pbrDst == NULL )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "Not enough memory" );
 | 
			
		||||
    if (pbrDst == NULL) {
 | 
			
		||||
        debug_os2("Not enough memory");
 | 
			
		||||
        return FALSE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    prectlScan = prectlDst;
 | 
			
		||||
  pptlSrcOrg = (PPOINTL)prectlDst; // Yes, this memory block will be used again.
 | 
			
		||||
  for( ulIdx = 0; ulIdx < cSDLRects; ulIdx++, prectlScan++, pptlSrcOrg++ )
 | 
			
		||||
  {
 | 
			
		||||
    pptlSrcOrg = (PPOINTL)prectlDst; /* Yes, this memory block will be used again */
 | 
			
		||||
    for (ulIdx = 0; ulIdx < cSDLRects; ulIdx++, prectlScan++, pptlSrcOrg++) {
 | 
			
		||||
        pbrDst[ulIdx].ulXOrg = pVOData->rectlWin.xLeft + prectlScan->xLeft;
 | 
			
		||||
        pbrDst[ulIdx].ulYOrg = pVOData->ulScreenHeight -
 | 
			
		||||
                              (pVOData->rectlWin.yBottom + prectlScan->yTop);
 | 
			
		||||
@@ -464,18 +438,15 @@ static BOOL voUpdate(PVODATA pVOData, HWND hwnd, SDL_Rect *pSDLRects,
 | 
			
		||||
    }
 | 
			
		||||
    pptlSrcOrg = (PPOINTL)prectlDst;
 | 
			
		||||
 | 
			
		||||
  // Request HW
 | 
			
		||||
    /* Request HW */
 | 
			
		||||
    sHWReqIn.ulLength = sizeof(HWREQIN);
 | 
			
		||||
    sHWReqIn.ulFlags = REQUEST_HW;
 | 
			
		||||
    sHWReqIn.cScrChangeRects = 1;
 | 
			
		||||
    sHWReqIn.arectlScreen = &pVOData->rectlWin;
 | 
			
		||||
  if ( pfnVMIEntry( 0, VMI_CMD_REQUESTHW, &sHWReqIn, NULL ) != RC_SUCCESS )
 | 
			
		||||
  {
 | 
			
		||||
    debug( "pfnVMIEntry(,VMI_CMD_REQUESTHW,,) failed" );
 | 
			
		||||
    sHWReqIn.cScrChangeRects = 0; // for fail signal only.
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    if (pfnVMIEntry(0, VMI_CMD_REQUESTHW, &sHWReqIn, NULL) != RC_SUCCESS) {
 | 
			
		||||
        debug_os2("pfnVMIEntry(,VMI_CMD_REQUESTHW,,) failed");
 | 
			
		||||
        sHWReqIn.cScrChangeRects = 0; /* for fail signal only */
 | 
			
		||||
    } else {
 | 
			
		||||
        RECTL rclSrcBounds;
 | 
			
		||||
 | 
			
		||||
        rclSrcBounds.xLeft = 0;
 | 
			
		||||
@@ -494,18 +465,20 @@ static BOOL voUpdate(PVODATA pVOData, HWND hwnd, SDL_Rect *pSDLRects,
 | 
			
		||||
        sBitbltInfo.aptlSrcOrg = pptlSrcOrg;
 | 
			
		||||
        sBitbltInfo.abrDst = pbrDst;
 | 
			
		||||
 | 
			
		||||
    // Screen update.
 | 
			
		||||
    if ( pfnVMIEntry( 0, VMI_CMD_BITBLT, &sBitbltInfo, NULL ) != RC_SUCCESS )
 | 
			
		||||
    {
 | 
			
		||||
      debug( "pfnVMIEntry(,VMI_CMD_BITBLT,,) failed" );
 | 
			
		||||
      sHWReqIn.cScrChangeRects = 0; // for fail signal only.
 | 
			
		||||
        /* Screen update */
 | 
			
		||||
        if (pfnVMIEntry(0, VMI_CMD_BITBLT, &sBitbltInfo, NULL) != RC_SUCCESS) {
 | 
			
		||||
            debug_os2("pfnVMIEntry(,VMI_CMD_BITBLT,,) failed");
 | 
			
		||||
            sHWReqIn.cScrChangeRects = 0; /* for fail signal only */
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    // Release HW.
 | 
			
		||||
        /* Release HW */
 | 
			
		||||
        sHWReqIn.ulFlags = 0;
 | 
			
		||||
    if ( pfnVMIEntry( 0, VMI_CMD_REQUESTHW, &sHWReqIn, NULL ) != RC_SUCCESS )
 | 
			
		||||
      debug( "pfnVMIEntry(,VMI_CMD_REQUESTHW,,) failed" );
 | 
			
		||||
        if (pfnVMIEntry(0, VMI_CMD_REQUESTHW, &sHWReqIn, NULL) != RC_SUCCESS) {
 | 
			
		||||
          debug_os2("pfnVMIEntry(,VMI_CMD_REQUESTHW,,) failed");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return sHWReqIn.cScrChangeRects != 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* vi: set ts=4 sw=4 expandtab: */
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user