Annotation of quake1/sys_wind.c, revision 1.1

1.1     ! root        1: // sys_null.h -- null system driver to aid porting efforts
        !             2: 
        !             3: #include "quakedef.h"
        !             4: #include "winquake.h"
        !             5: #include "errno.h"
        !             6: #include <sys\types.h>
        !             7: #include <sys\timeb.h>
        !             8: 
        !             9: 
        !            10: /*
        !            11: ===============================================================================
        !            12: 
        !            13: FILE IO
        !            14: 
        !            15: ===============================================================================
        !            16: */
        !            17: 
        !            18: #define        MAX_HANDLES             10
        !            19: FILE   *sys_handles[MAX_HANDLES];
        !            20: 
        !            21: int            findhandle (void)
        !            22: {
        !            23:        int             i;
        !            24:        
        !            25:        for (i=1 ; i<MAX_HANDLES ; i++)
        !            26:                if (!sys_handles[i])
        !            27:                        return i;
        !            28:        Sys_Error ("out of handles");
        !            29:        return -1;
        !            30: }
        !            31: 
        !            32: /*
        !            33: ================
        !            34: filelength
        !            35: ================
        !            36: */
        !            37: int filelength (FILE *f)
        !            38: {
        !            39:        int             pos;
        !            40:        int             end;
        !            41: 
        !            42:        pos = ftell (f);
        !            43:        fseek (f, 0, SEEK_END);
        !            44:        end = ftell (f);
        !            45:        fseek (f, pos, SEEK_SET);
        !            46: 
        !            47:        return end;
        !            48: }
        !            49: 
        !            50: int Sys_FileOpenRead (char *path, int *hndl)
        !            51: {
        !            52:        FILE    *f;
        !            53:        int             i;
        !            54:        
        !            55:        i = findhandle ();
        !            56: 
        !            57:        f = fopen(path, "rb");
        !            58:        if (!f)
        !            59:        {
        !            60:                *hndl = -1;
        !            61:                return -1;
        !            62:        }
        !            63:        sys_handles[i] = f;
        !            64:        *hndl = i;
        !            65:        
        !            66:        return filelength(f);
        !            67: }
        !            68: 
        !            69: int Sys_FileOpenWrite (char *path)
        !            70: {
        !            71:        FILE    *f;
        !            72:        int             i;
        !            73:        
        !            74:        i = findhandle ();
        !            75: 
        !            76:        f = fopen(path, "wb");
        !            77:        if (!f)
        !            78:                Sys_Error ("Error opening %s: %s", path,strerror(errno));
        !            79:        sys_handles[i] = f;
        !            80:        
        !            81:        return i;
        !            82: }
        !            83: 
        !            84: void Sys_FileClose (int handle)
        !            85: {
        !            86:        fclose (sys_handles[handle]);
        !            87:        sys_handles[handle] = NULL;
        !            88: }
        !            89: 
        !            90: void Sys_FileSeek (int handle, int position)
        !            91: {
        !            92:        fseek (sys_handles[handle], position, SEEK_SET);
        !            93: }
        !            94: 
        !            95: int Sys_FileRead (int handle, void *dest, int count)
        !            96: {
        !            97:        return fread (dest, 1, count, sys_handles[handle]);
        !            98: }
        !            99: 
        !           100: int Sys_FileWrite (int handle, void *data, int count)
        !           101: {
        !           102:        return fwrite (data, 1, count, sys_handles[handle]);
        !           103: }
        !           104: 
        !           105: int    Sys_FileTime (char *path)
        !           106: {
        !           107:        FILE    *f;
        !           108:        
        !           109:        f = fopen(path, "rb");
        !           110:        if (f)
        !           111:        {
        !           112:                fclose(f);
        !           113:                return 1;
        !           114:        }
        !           115:        
        !           116:        return -1;
        !           117: }
        !           118: 
        !           119: void Sys_mkdir (char *path)
        !           120: {
        !           121: }
        !           122: 
        !           123: 
        !           124: /*
        !           125: ===============================================================================
        !           126: 
        !           127: SYSTEM IO
        !           128: 
        !           129: ===============================================================================
        !           130: */
        !           131: 
        !           132: void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
        !           133: {
        !           134: }
        !           135: 
        !           136: 
        !           137: void Sys_DebugLog(char *file, char *fmt, ...)
        !           138: {
        !           139: }
        !           140: 
        !           141: void Sys_Error (char *error, ...)
        !           142: {
        !           143:        va_list         argptr;
        !           144:        char            text[1024];
        !           145: 
        !           146:        va_start (argptr,error);
        !           147:        vsprintf (text, error,argptr);
        !           148:        va_end (argptr);
        !           149: 
        !           150: //    MessageBox(NULL, text, "Error", 0 /* MB_OK */ );
        !           151:        printf ("ERROR: %s\n", text);
        !           152: 
        !           153:        exit (1);
        !           154: }
        !           155: 
        !           156: void Sys_Printf (char *fmt, ...)
        !           157: {
        !           158:        va_list         argptr;
        !           159:        
        !           160:        va_start (argptr,fmt);
        !           161:        vprintf (fmt,argptr);
        !           162:        va_end (argptr);
        !           163: }
        !           164: 
        !           165: void Sys_Quit (void)
        !           166: {
        !           167:        exit (0);
        !           168: }
        !           169: 
        !           170: double Sys_FloatTime (void)
        !           171: {
        !           172:        double t;
        !           173:     struct _timeb tstruct;
        !           174:        static int      starttime;
        !           175: 
        !           176:        _ftime( &tstruct );
        !           177:  
        !           178:        if (!starttime)
        !           179:                starttime = tstruct.time;
        !           180:        t = (tstruct.time-starttime) + tstruct.millitm*0.001;
        !           181:        
        !           182:        return t;
        !           183: }
        !           184: 
        !           185: void Sys_Sleep (void)
        !           186: {
        !           187: }
        !           188: 
        !           189: 
        !           190: void Sys_SendKeyEvents (void)
        !           191: {
        !           192: }
        !           193: 
        !           194: void Sys_HighFPPrecision (void)
        !           195: {
        !           196: }
        !           197: 
        !           198: void Sys_LowFPPrecision (void)
        !           199: {
        !           200: }
        !           201: 
        !           202: char *Sys_ConsoleInput (void)
        !           203: {
        !           204:        static char     text[256];
        !           205:        static int              len;
        !           206:        INPUT_RECORD    recs[1024];
        !           207:        int             count;
        !           208:        int             i;
        !           209:        int             c;
        !           210: 
        !           211:        // read a line out
        !           212:        while (_kbhit())
        !           213:        {
        !           214:                c = _getch();
        !           215:                putch (c);
        !           216:                if (c == '\r')
        !           217:                {
        !           218:                        text[len] = 0;
        !           219:                        putch ('\n');
        !           220:                        len = 0;
        !           221:                        return text;
        !           222:                }
        !           223:                if (c == 8)
        !           224:                {
        !           225:                        putch (' ');
        !           226:                        putch (c);
        !           227:                        len--;
        !           228:                        text[len] = 0;
        !           229:                        continue;
        !           230:                }
        !           231:                text[len] = c;
        !           232:                len++;
        !           233:                text[len] = 0;
        !           234:                if (len == sizeof(text))
        !           235:                        len = 0;
        !           236:        }
        !           237: 
        !           238:        return NULL;
        !           239: }
        !           240: 
        !           241: 
        !           242: 
        !           243: /*
        !           244: ==================
        !           245: main
        !           246: 
        !           247: ==================
        !           248: */
        !           249: char   *newargv[256];
        !           250: 
        !           251: int main (int argc, char **argv)
        !           252: {
        !           253:     MSG        msg;
        !           254:        quakeparms_t    parms;
        !           255:        double                  time, oldtime;
        !           256:        static  char    cwd[1024];
        !           257: 
        !           258:        memset (&parms, 0, sizeof(parms));
        !           259: 
        !           260:        parms.memsize = 16384*1024;
        !           261:        parms.membase = malloc (parms.memsize);
        !           262: 
        !           263:        _getcwd (cwd, sizeof(cwd));
        !           264:        if (cwd[Q_strlen(cwd)-1] == '\\')
        !           265:                cwd[Q_strlen(cwd)-1] = 0;
        !           266:        parms.basedir = cwd; //"f:/quake";
        !           267: //     parms.basedir = "f:\\quake";
        !           268: 
        !           269:        COM_InitArgv (argc, argv);
        !           270: 
        !           271:        // dedicated server ONLY!
        !           272:        if (!COM_CheckParm ("-dedicated"))
        !           273:        {
        !           274:                memcpy (newargv, argv, argc*4);
        !           275:                newargv[argc] = "-dedicated";
        !           276:                argc++;
        !           277:                argv = newargv;
        !           278:                COM_InitArgv (argc, argv);
        !           279:        }
        !           280: 
        !           281:        parms.argc = argc;
        !           282:        parms.argv = argv;
        !           283: 
        !           284:        printf ("Host_Init\n");
        !           285:        Host_Init (&parms);
        !           286: 
        !           287:        oldtime = Sys_FloatTime ();
        !           288: 
        !           289:     /* main window message loop */
        !           290:        while (1)
        !           291:        {
        !           292:                time = Sys_FloatTime();
        !           293:                if (time - oldtime < sys_ticrate.value )
        !           294:                {
        !           295:                        Sleep(1);
        !           296:                        continue;
        !           297:                }
        !           298: 
        !           299:                Host_Frame ( time - oldtime );
        !           300:                oldtime = time;
        !           301:        }
        !           302: 
        !           303:     /* return success of application */
        !           304:     return TRUE;
        !           305: }
        !           306: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.