📄 pm.c
字号:
/****************************************************************************** SciTech OS Portability Manager Library** ========================================================================** The contents of this file are subject to the SciTech MGL Public* License Version 1.0 (the "License"); you may not use this file* except in compliance with the License. You may obtain a copy of* the License at http://www.scitechsoft.com/mgl-license.txt** Software distributed under the License is distributed on an* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or* implied. See the License for the specific language governing* rights and limitations under the License.** The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.** The Initial Developer of the Original Code is SciTech Software, Inc.* All Rights Reserved.** ========================================================================** Language: ANSI C* Environment: *** TODO: ADD YOUR OS ENVIRONMENT NAME HERE ***** Description: Implementation for the OS Portability Manager Library, which* contains functions to implement OS specific services in a* generic, cross platform API. Porting the OS Portability* Manager library is the first step to porting any SciTech* products to a new platform.*****************************************************************************/#include "pmapi.h"#include "drvlib/os/os.h"#include <stdio.h>#include <stdlib.h>#include <string.h>/* TODO: Include any OS specific headers here! *//*--------------------------- Global variables ----------------------------*//* TODO: If you support access to the BIOS, the following VESABuf globals *//* keep track of a single VESA transfer buffer. If you don't support *//* access to the BIOS, remove these variables. */static uint VESABuf_len = 1024; /* Length of the VESABuf buffer */static void *VESABuf_ptr = NULL; /* Near pointer to VESABuf */static uint VESABuf_rseg; /* Real mode segment of VESABuf */static uint VESABuf_roff; /* Real mode offset of VESABuf */static void (PMAPIP fatalErrorCleanup)(void) = NULL;/*----------------------------- Implementation ----------------------------*//****************************************************************************REMARKS:Initialise the PM library.****************************************************************************/void PMAPI PM_init(void){ /* TODO: Do any initialisation in here. This includes getting IOPL */ /* access for the process calling PM_init. This will get called */ /* more than once. */ /* TODO: If you support the supplied MTRR register stuff (you need to */ /* be at ring 0 for this!), you should initialise it in here. *//* MTRR_init(); */}/****************************************************************************REMARKS:Return the operating system type identifier.****************************************************************************/long PMAPI PM_getOSType(void){ /* TODO: Change this to return the define for your OS from drvlib/os.h */ return _OS_MYOS;}/****************************************************************************REMARKS:Return the runtime type identifier (always PM_386 for protected mode)****************************************************************************/int PMAPI PM_getModeType(void){ return PM_386; }/****************************************************************************REMARKS:Add a file directory separator to the end of the filename.****************************************************************************/void PMAPI PM_backslash( char *s){ uint pos = strlen(s); if (s[pos-1] != '/') { s[pos] = '/'; s[pos+1] = '\0'; }}/****************************************************************************REMARKS:Add a user defined PM_fatalError cleanup function.****************************************************************************/void PMAPI PM_setFatalErrorCleanup( void (PMAPIP cleanup)(void)){ fatalErrorCleanup = cleanup;}/****************************************************************************REMARKS:Report a fatal error condition and halt the program.****************************************************************************/void PMAPI PM_fatalError( const char *msg){ /* TODO: If you are running in a GUI environment without a console, */ /* this needs to be changed to bring up a fatal error message */ /* box and terminate the program. */ if (fatalErrorCleanup) fatalErrorCleanup(); fprintf(stderr,"%s\n", msg); exit(1);}/****************************************************************************REMARKS:Exit handler to kill the VESA transfer buffer.****************************************************************************/static void ExitVBEBuf(void){ /* TODO: If you do not have BIOS access, remove this function. */ if (VESABuf_ptr) PM_freeRealSeg(VESABuf_ptr); VESABuf_ptr = 0;}/****************************************************************************REMARKS:Allocate the real mode VESA transfer buffer for communicating with the BIOS.****************************************************************************/void * PMAPI PM_getVESABuf( uint *len, uint *rseg, uint *roff){ /* TODO: If you do not have BIOS access, simply delete the guts of */ /* this function and return NULL. */ if (!VESABuf_ptr) { /* Allocate a global buffer for communicating with the VESA VBE */ if ((VESABuf_ptr = PM_allocRealSeg(VESABuf_len, &VESABuf_rseg, &VESABuf_roff)) == NULL) return NULL; atexit(ExitVBEBuf); } *len = VESABuf_len; *rseg = VESABuf_rseg; *roff = VESABuf_roff; return VESABuf_ptr;}/****************************************************************************REMARKS:Check if a key has been pressed.****************************************************************************/int PMAPI PM_kbhit(void){ /* TODO: This function checks if a key is available to be read. This */ /* should be implemented, but is mostly used by the test programs */ /* these days. */ return true;}/****************************************************************************REMARKS:Wait for and return the next keypress.****************************************************************************/int PMAPI PM_getch(void){ /* TODO: This returns the ASCII code of the key pressed. This */ /* should be implemented, but is mostly used by the test programs */ /* these days. */ return 0xD;}/****************************************************************************REMARKS:Open a fullscreen console mode for output.****************************************************************************/int PMAPI PM_openConsole(void){ /* TODO: Opens up a fullscreen console for graphics output. If your */ /* console does not have graphics/text modes, this can be left */ /* empty. The main purpose of this is to disable console switching */ /* when in graphics modes if you can switch away from fullscreen */ /* consoles (if you want to allow switching, this can be done */ /* elsewhere with a full save/restore state of the graphics mode). */ return 0;}/****************************************************************************REMARKS:Return the size of the state buffer used to save the console state.****************************************************************************/int PMAPI PM_getConsoleStateSize(void){ /* TODO: Returns the size of the console state buffer used to save the */ /* state of the console before going into graphics mode. This is */ /* used to restore the console back to normal when we are done. */ return 1;}/****************************************************************************REMARKS:Save the state of the console into the state buffer.****************************************************************************/void PMAPI PM_saveConsoleState( void *stateBuf, int console_id){ /* TODO: Saves the state of the console into the state buffer. This is */ /* used to restore the console back to normal when we are done. */ /* We will always restore 80x25 text mode after being in graphics */ /* mode, so if restoring text mode is all you need to do this can */ /* be left empty. */}/****************************************************************************REMARKS:Restore the state of the console from the state buffer.****************************************************************************/void PMAPI PM_restoreConsoleState( const void *stateBuf, int console_id){ /* TODO: Restore the state of the console from the state buffer. This is */ /* used to restore the console back to normal when we are done. */ /* We will always restore 80x25 text mode after being in graphics */ /* mode, so if restoring text mode is all you need to do this can */ /* be left empty. */}/****************************************************************************REMARKS:Close the console and return to non-fullscreen console mode.****************************************************************************/void PMAPI PM_closeConsole( int console_id){ /* TODO: Close the console when we are done, going back to text mode. */}/****************************************************************************REMARKS:Set the location of the OS console cursor.****************************************************************************/void PM_setOSCursorLocation( int x, int y){ /* TODO: Set the OS console cursor location to the new value. This is */ /* generally used for new OS ports (used mostly for DOS). */}/****************************************************************************REMARKS:Set the width of the OS console.****************************************************************************/void PM_setOSScreenWidth( int width, int height){ /* TODO: Set the OS console screen width. This is generally unused for */ /* new OS ports. */}/****************************************************************************REMARKS:Set the real time clock handler (used for software stereo modes).****************************************************************************/ibool PMAPI PM_setRealTimeClockHandler( PM_intHandler ih, int frequency){ /* TODO: Install a real time clock interrupt handler. Normally this */ /* will not be supported from most OS'es in user land, so an */ /* alternative mechanism is needed to enable software stereo. */ /* Hence leave this unimplemented unless you have a high priority */ /* mechanism to call the 32-bit callback when the real time clock */ /* interrupt fires. */ return false;}/****************************************************************************REMARKS:Set the real time clock frequency (for stereo modes).****************************************************************************/void PMAPI PM_setRealTimeClockFrequency( int frequency){ /* TODO: Set the real time clock interrupt frequency. Used for stereo */ /* LC shutter glasses when doing software stereo. Usually sets */ /* the frequency to around 2048 Hz. */}/****************************************************************************REMARKS:Restore the original real time clock handler.****************************************************************************/void PMAPI PM_restoreRealTimeClockHandler(void){ /* TODO: Restores the real time clock handler. */}/****************************************************************************REMARKS:Return the current operating system path or working directory.****************************************************************************/char * PMAPI PM_getCurrentPath( char *path, int maxLen){ return getcwd(path,maxLen);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -