| 1 | /* $Id: OS2UTIL.CPP,v 1.13 2002-03-22 15:55:00 sandervl Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * OS/2 Utility functions | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl) | 
|---|
| 7 | * | 
|---|
| 8 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 9 | * | 
|---|
| 10 | */ | 
|---|
| 11 | #define INCL_DOS | 
|---|
| 12 | #define INCL_DOSMEMMGR | 
|---|
| 13 | #define INCL_DOSDEVICES | 
|---|
| 14 | #include <os2wrap.h> | 
|---|
| 15 | #include <misc.h> | 
|---|
| 16 | #include "os2util.h" | 
|---|
| 17 | #include "cio2.h" | 
|---|
| 18 |  | 
|---|
| 19 | //****************************************************************************** | 
|---|
| 20 | //****************************************************************************** | 
|---|
| 21 | char *OS2AllocMem(ULONG size) | 
|---|
| 22 | { | 
|---|
| 23 | PVOID  lpMem; | 
|---|
| 24 | APIRET rc; | 
|---|
| 25 |  | 
|---|
| 26 | rc = DosAllocMem(&lpMem, size, PAG_READ|PAG_WRITE|PAG_COMMIT); | 
|---|
| 27 | if(rc) { | 
|---|
| 28 | dprintf(("DDRAW: DosAllocMem returned %d", rc)); | 
|---|
| 29 | return(NULL); | 
|---|
| 30 | } | 
|---|
| 31 | return((char *)lpMem); | 
|---|
| 32 | } | 
|---|
| 33 | //****************************************************************************** | 
|---|
| 34 | //****************************************************************************** | 
|---|
| 35 | void OS2FreeMem(char *lpMem) | 
|---|
| 36 | { | 
|---|
| 37 | APIRET rc; | 
|---|
| 38 |  | 
|---|
| 39 | rc = DosFreeMem(lpMem); | 
|---|
| 40 | if(rc) { | 
|---|
| 41 | dprintf(("DDRAW: DosFreeMem returned %d", rc)); | 
|---|
| 42 | } | 
|---|
| 43 | }//****************************************************************************** | 
|---|
| 44 | //****************************************************************************** | 
|---|
| 45 | void OS2MaximizeWindow(HWND hwndClient) | 
|---|
| 46 | { | 
|---|
| 47 | WinSetWindowPos(hwndClient, HWND_TOP, 0, 0, 0, 0, SWP_MAXIMIZE); | 
|---|
| 48 | } | 
|---|
| 49 | //****************************************************************************** | 
|---|
| 50 | //****************************************************************************** | 
|---|
| 51 |  | 
|---|
| 52 | extern "C" { | 
|---|
| 53 | BOOL    APIENTRY _GpiEnableYInversion (HPS hps, LONG lHeight); | 
|---|
| 54 | } | 
|---|
| 55 |  | 
|---|
| 56 | void InverseDC(HDC hdc, LONG lHeight) | 
|---|
| 57 | { | 
|---|
| 58 | USHORT sel = RestoreOS2FS(); | 
|---|
| 59 |  | 
|---|
| 60 | // _GpiEnableYInversion( WinGetPS( Win32ToOS2Handle( WindowFromDC(hdc) ) ), lHeight); | 
|---|
| 61 | _GpiEnableYInversion( hdc, lHeight); | 
|---|
| 62 | SetFS(sel); | 
|---|
| 63 |  | 
|---|
| 64 | } | 
|---|
| 65 |  | 
|---|
| 66 | int InitIO() | 
|---|
| 67 | { | 
|---|
| 68 | WORD  gdt; | 
|---|
| 69 | HRESULT rc; | 
|---|
| 70 | HFILE  device; | 
|---|
| 71 | ULONG  ulAction; | 
|---|
| 72 |  | 
|---|
| 73 | rc = DosOpen( "\\dev\\fastio$", | 
|---|
| 74 | &device, | 
|---|
| 75 | &ulAction, | 
|---|
| 76 | 0,0,1, | 
|---|
| 77 | OPEN_ACCESS_READWRITE|OPEN_SHARE_DENYNONE, | 
|---|
| 78 | 0); | 
|---|
| 79 | if(rc) | 
|---|
| 80 | return rc; | 
|---|
| 81 |  | 
|---|
| 82 | rc = DosDevIOCtl( device, 118, 100, 0,0,0,&gdt,2,&ulAction); | 
|---|
| 83 |  | 
|---|
| 84 | DosClose(device); | 
|---|
| 85 |  | 
|---|
| 86 | if(rc) | 
|---|
| 87 | { | 
|---|
| 88 | return rc; | 
|---|
| 89 | } | 
|---|
| 90 |  | 
|---|
| 91 | USHORT sel = RestoreOS2FS(); | 
|---|
| 92 |  | 
|---|
| 93 | io_init2(gdt); | 
|---|
| 94 |  | 
|---|
| 95 | SetFS(sel); | 
|---|
| 96 | return 0; | 
|---|
| 97 | } | 
|---|
| 98 |  | 
|---|