Example #1
0
int main(void)
{
    PM_HWND hwndConsole;
    ulong   stateSize;
    void    *stateBuf;
    FILE    *f;

    /* Allocate a buffer to save console state and save the state */
    hwndConsole = PM_openConsole(0,0,0,0,0,true);
    stateSize = PM_getConsoleStateSize();
    if ((stateBuf = PM_malloc(stateSize)) == NULL) {
        PM_closeConsole(hwndConsole);
        printf("Unable to allocate console state buffer!\n");
        return -1;
        }
    PM_saveConsoleState(stateBuf,0);

    /* Restore the console state on exit */
    PM_restoreConsoleState(stateBuf,0);
    PM_closeConsole(hwndConsole);

    /* Write the saved console state buffer to disk */
    if ((f = fopen("/etc/pmsave.dat","wb")) == NULL)
        printf("Unable to open /etc/pmsave.dat for writing!\n");
    else {
        fwrite(&stateSize,1,sizeof(stateSize),f);
        fwrite(stateBuf,1,stateSize,f);
        fclose(f);
        printf("Console state successfully saved to /etc/pmsave.dat\n");
        }
    PM_free(stateBuf);
    return 0;
}
Example #2
0
int main(void)
{
    int     i;
    ulong   allocs;
    char    *p,*pa[MAXALLOC];
    PM_HWND hwndConsole;

    hwndConsole = PM_openConsole(0,0,0,0,0,true);
    for (allocs = i = 0; i < MAXALLOC; i++) {
        if ((pa[i] = PM_malloc(10*1024)) != 0) {    /* in 10k blocks    */
            p = pa[allocs];
            memset(p, 0, 10*1024); /* touch every byte              */
            *p = 'x';           /* do something, anything with      */
            p[1023] = 'y';      /* the allocated memory             */
            allocs++;
            printf("Allocated %lu bytes\r", 10*(allocs << 10));
            }
        else break;
        if (PM_kbhit() && (PM_getch() == 0x1B))
            break;
        }
    PM_closeConsole(hwndConsole);

    printf("\n\nAllocated total of %lu bytes\n", 10 * (allocs << 10));

    for (i = allocs-1; i >= 0; i--)
        PM_free(pa[i]);

    return 0;
}
Example #3
0
void main(int argc,char *argv[])
{
    PM_HWND hwndConsole;
    int     stateSize;
    void    *stateBuf;

    /* Initialise the console output routines */
    hwndConsole = PM_openConsole(0,0,0,0,0,true);
    stateSize = PM_getConsoleStateSize();
    if ((stateBuf = malloc(stateSize)) == NULL)
        PM_fatalError("Out of memory!\n");
    PM_saveConsoleState(stateBuf,hwndConsole);
    PM_init();
    CON_init();
    if (argc > 1) {
        if (atoi(argv[1]) == 25)
            CON_set25LineMode();
        else if (atoi(argv[1]) == 43)
            CON_set43LineMode();
        else if (atoi(argv[1]) == 50)
            CON_set50LineMode();
        }
    do_tests();
    do_tests_in_window();
    CON_getch();
    CON_restoreMode();
    PM_restoreConsoleState(stateBuf,hwndConsole);
    PM_closeConsole(hwndConsole);
    free(stateBuf);
}
Example #4
0
/****************************************************************************
REMARKS:
Load the SNAP driver and intialise it.
****************************************************************************/
static GA_devCtx *LoadDriver(
    int deviceIndex)
{
    GA_devCtx *dc;

    /* Save the state of the console */
    hwndConsole = PM_openConsole(0,0,640,480,8,true);
    if ((stateBuf = malloc(PM_getConsoleStateSize())) == NULL)
        PM_fatalError("Out of memory!");
    PM_saveConsoleState(stateBuf,hwndConsole);

    /* Register our fatal error cleanup handler */
    PM_setFatalErrorCleanup(Cleanup);

    /* Load the driver */
    if ((dc = GA_loadDriver(deviceIndex,false)) == NULL)
        PM_fatalError(GA_errorMsg(GA_status()));
    init.dwSize = sizeof(init);
    if (!GA_queryFunctions(dc,GA_GET_INITFUNCS,&init))
        PM_fatalError("Unable to get device driver functions!");

    /* Cleanup. We do this here because we know that we will not
     * be setting any graphics modes after loading the driver,
     * so we can properly restore the console state and make calls
     * to non-destructive functions in the driver before we unload
     * it.
     */
    Cleanup();
    return dc;
}
Example #5
0
/****************************************************************************
REMARKS:
Main program entry point
****************************************************************************/
int main(void)
{
    event_t     evt;
    ibool       done = false;
    PM_HWND     hwndConsole;

    hwndConsole = PM_openConsole(0,0,0,0,0,true);
    EVT_init(&moveMouse);
    EVT_setMouseRange(1024,768);
    CalibrateJoy();
    do {
	EVT_pollJoystick();
	if (EVT_getNext(&evt,EVT_EVERYEVT)) {
	    switch (evt.what) {
		case EVT_KEYDOWN:
		    DisplayKey("EVT_KEYDOWN  ", &evt);
		    if (EVT_scanCode(evt.message) == KB_esc)
			done = true;
		    break;
		case EVT_KEYREPEAT:
		    DisplayKey("EVT_KEYREPEAT", &evt);
		    break;
		case EVT_KEYUP:
		    DisplayKey("EVT_KEYUP    ", &evt);
		    break;
		case EVT_MOUSEDOWN:
		    DisplayMouse("EVT_MOUSEDOWN", &evt);
		    break;
		case EVT_MOUSEAUTO:
		    DisplayMouse("EVT_MOUSEAUTO", &evt);
		    break;
		case EVT_MOUSEUP:
		    DisplayMouse("EVT_MOUSEUP  ", &evt);
		    break;
		case EVT_MOUSEMOVE:
		    DisplayMouse("EVT_MOUSEMOVE", &evt);
		    break;
		case EVT_JOYCLICK:
		    DisplayJoy("EVT_JOYCLICK ", &evt);
		    break;
		case EVT_JOYMOVE:
		    DisplayJoy("EVT_JOYMOVE  ", &evt);
		    break;
		}
	    }
	} while (!done);
    EVT_exit();
    PM_closeConsole(hwndConsole);
    return 0;
}
Example #6
0
/****************************************************************************
DESCRIPTION:
Create a new windowed device context.

HEADER:
mglwin.h

PARAMETERS:
hwnd    - Window handle with which to associate new device context

RETURNS:
Pointer to the allocated windowed device context, or NULL if not enough memory.

REMARKS:
Creates a new windowed device context for drawing information into a window
on the Windows desktop. When you create a Windowed device context, you
associate it with a standard Windows HWND for the window that you wish MGL
to display it's output on. Windowed device contexts are special device
contexts in that you cannot directly access the surface for the device, nor
can you actually use the MGL rasterizing functions to draw on the device
surface. The only rasterizing functions supported are the MGL_bitBlt and
MGL_stretchBlt for blt'ing data from memory device contexts to the window on
the desktop.

However in order to change the color palette values for the data copied to
the window, you must use the MGL palette functions on the windowed display
device context. Note that MGL automatically takes care of creating a proper
Windows identity palette for the windowed device context, so as long as you
program the same palette values for the windowed device and the memory
device you should get the maximum performance blt'ing speed.

SEE ALSO:
MGL_createMemoryDC, MGL_createDisplayDC, MGL_destroyDC, MGL_setWinDC,
MGL_activatePalette
****************************************************************************/
MGLDC * MGLAPI MGL_createWindowedDC(
    MGL_HWND hwnd)
{
    MGLDC       *dc;
    driverent   *driver;
    PM_HWND     hwndConsole = (PM_HWND)NULL;

    /* Allocate memory for the new DC */
    _MGL_destroyCurrentMode();
    if ((dc = _LST_newNode(sizeof(MGLDC))) == NULL) {
        FATALERROR(grNoMem);
        return NULL;
        }

    // TODO: Add code to handle multiple windowed DC's!!

    /* The display device list is currently empty, so create the new
     * list and start the specified graphics mode
     */
    if (_MGL_winDCList == NULL) {
        if ((_MGL_winDCList = _LST_create()) == NULL) {
            FATALERROR(grNoMem);
            goto Error;
            }
        }

    /* Find the device driver to use */
    if ((driver = _MGL_findStaticDriver(MGL_WINDOWEDNAME)) == NULL) {
        FATALERROR(grDriverNotFound);
        goto Error;
        }
    if (!driver) {
        FATALERROR(grDriverNotFound);
        goto Error;
        }

    /* Now initialise the driver */
    if (!driver->data) {
        if ((driver->data = driver->driver->createInstance()) == NULL) {
            FATALERROR(grLoadMem);
            return NULL;
            }
        }
    if (!_MGL_initDC(dc,driver,NULL,hwnd,-1,-1,1,false,MGL_DEFAULT_REFRESH))
        goto Error;

    /* Open a new windowed console for the mode */
    hwndConsole = PM_openConsole((PM_HWND)hwnd,0,dc->mi.xRes+1,dc->mi.xRes+2,dc->mi.bitsPerPixel,false);

    /* Set up the mouse cursor */
    // TODO: Tell the mouse system we are in a window so it will pass the
    //       mouse cursor images through to the window manager?
    if (_MGL_consoleSupport)
        MS_setCursor(MGL_DEF_CURSOR);

    /* Allow the OS specific code to hook the window procedure as necessary */
    _MGL_hookWindowProc(dc);

    /* Add the new DC to the start of the DC chain */
    RESET_DEFAULT_CW();
    _LST_addAfter(_MGL_winDCList,dc,LST_HEAD(_MGL_winDCList));
    return dc;

Error:
    if (hwndConsole)
        PM_closeConsole(hwndConsole);
    if (_MGL_winDCList && _MGL_winDCList->count == 0) {
        _LST_destroy(_MGL_winDCList,_LST_freeNode);
        _MGL_winDCList = NULL;
        }
    _LST_freeNode(dc);
    return NULL;
}
Example #7
0
/****************************************************************************
REMARKS:
Does the hard work to create the actual display device context.
****************************************************************************/
static MGLDC * _MGL_createDisplayDC(
    int mode,
    int virtualX,
    int virtualY,
    int numBuffers,
    ibool stereo,
    int refreshRate)
{
    MGLDC       *dc;
    driverent   *entry;
    modeent     *me = &DEV.availableModes[mode];
    PM_HWND     hwndConsole = (PM_HWND)NULL;

    /* Check if the mode is currently available */
    __MGL_result = grOK;
    if (mode >= DEV.numModes || DEV.availableModes[mode].driver == 0xFF) {
        SETERROR(grInvalidMode);
        return NULL;
        }
    _MGL_destroyCurrentMode();

    /* Allocate memory for the new DC */
    if ((dc = _LST_newNode(sizeof(MGLDC))) == NULL) {
        FATALERROR(grNoMem);
        return NULL;
        }

    /* The display device list is currently empty, so create the new
     * list and start the specified graphics mode
     */
    if ((DEV.dispDCList = _LST_create()) == NULL) {
        FATALERROR(grNoMem);
        goto Error;
        }

    /* Open a new fullscreen console for the mode, and save it's state */
    DEV.stateBuf = NULL;
    if (_MGL_consoleSupport && (GET_CURRENT_DEVICE() == 0)) {
        hwndConsole = PM_openConsole((PM_HWND)_MGL_hwndFullScreen,GET_CURRENT_DEVICE(),me->xRes,me->yRes,me->bits,true);
        if ((DEV.stateBuf = PM_malloc(PM_getConsoleStateSize())) == NULL) {
            FATALERROR(grNoMem);
            goto Error;
            }
        PM_saveConsoleState(DEV.stateBuf,hwndConsole);
        }

    /* Now intialise the driver */
    entry = &DEV.driverTable[me->driver];
    if (!_MGL_initDC(dc,entry,me,(MGL_HWND)hwndConsole,virtualX,virtualY,numBuffers,stereo,refreshRate))
        goto Error;

    /* Set the suspend application callback for the console */
    PM_setSuspendAppCallback(_MGL_suspendAppProc);

    /* Set up the mouse cursor */
    if (_MGL_consoleSupport) {
        _MS_setDisplayDC(dc);
        MS_setCursor(MGL_DEF_CURSOR);
        MS_moveTo(dc->mi.xRes/2,dc->mi.yRes/2);
        }

    /* Now clear the device page */
    MGL_makeCurrentDC(dc);
    MGL_clearDevice();

    /* And clear the event queue of any extraneous events */
    if (_MGL_consoleSupport) {
        EVT_flush(EVT_EVERYEVT);
    }

    /* Add the new DC to the start of the DC chain */
    RESET_DEFAULT_CW();
    _LST_addToHead(DEV.dispDCList,dc);
    return dc;

Error:
    if (hwndConsole) {
        if (DEV.stateBuf) {
            PM_restoreConsoleState(DEV.stateBuf,hwndConsole);
            PM_free(DEV.stateBuf);
            DEV.stateBuf = NULL;
            }
        PM_closeConsole(hwndConsole);
        }
    DEV.fullScreen = false;
    if (DEV.dispDCList && DEV.dispDCList->count == 0) {
        _LST_destroy(DEV.dispDCList,_LST_freeNode);
        DEV.dispDCList = NULL;
        }
    _LST_freeNode(dc);
    return NULL;
}
Example #8
0
/****************************************************************************
REMARKS:
Main routine. Expects the x & y resolution of the desired video mode
to be passed on the command line. Will print out a list of available
video modes if no command line is present.
****************************************************************************/
int main(
    int argc,
    char *argv[])
{
    /* Check to see if we are running in a window */
    if (PM_runningInAWindow()) {
        printf("This program cannot run in a window. Please switch to a fullscreen mode.\n");
        return -1;
        }

    /* Save the state of the console */
    hwndConsole = PM_openConsole(0,0,640,480,8,true);
    if ((stateBuf = malloc(PM_getConsoleStateSize())) == NULL)
        PM_fatalError("Out of memory!");
    PM_saveConsoleState(stateBuf,hwndConsole);

    /* Register our fatal error cleanup handler */
    PM_setFatalErrorCleanup(FatalErrorCleanup);

    /* Register the ISV license file if desired */
#ifdef  ISV_LICENSE
    GA_registerLicense(OemLicense,false);
#endif

    /* Load the device driver for this device */
    if ((dc = GA_loadDriver(0,false)) == NULL)
        PM_fatalError(GA_errorMsg(GA_status()));
    init.dwSize = sizeof(init);
    if (!GA_queryFunctions(dc,GA_GET_INITFUNCS,&init))
        PM_fatalError("Unable to get device driver functions!");
    driver.dwSize = sizeof(driver);
    if (!GA_queryFunctions(dc,GA_GET_DRIVERFUNCS,&driver))
        PM_fatalError("Unable to get device driver functions!");

    /* Display available modes for invalid command line */
    if (argc != 4) {
        /* Restore the console */
        PM_restoreConsoleState(stateBuf,hwndConsole);
        PM_closeConsole(hwndConsole);
        AvailableModes();
        GA_unloadDriver(dc);
        return 0;
        }

    /* Get requested resolution, start graphics and draw pattern */
    xRes = atoi(argv[1]);
    yRes = atoi(argv[2]);
    bpp = atoi(argv[3]);
    if ((oldMode = InitGraphics(xRes,yRes,bpp)) != -1) {
        DrawMoire();
        PM_getch();

        virtualX = virtualY = bytesPerLine = -1;
        init.SetVideoMode(oldMode,&virtualX,&virtualY,&bytesPerLine,&maxMem,0,NULL);
        }

    /* Restore the console */
    ExitSoftwareRasterizer();
    PM_restoreConsoleState(stateBuf,hwndConsole);
    PM_closeConsole(hwndConsole);

    /* Unload the device driver */
    GA_unloadDriver(dc);

    if (oldMode == -1)
        printf("Unable to find specified graphics mode, or error starting mode.\n");
    return 0;
}