/////////////////////////
// miscellaneous stuff //
/////////////////////////

#ifndef __PTC_MISC_H
#define __PTC_MISC_H

#include "lang.h"
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>






// nice types
typedef unsigned char  uchar;
typedef unsigned short ushort;
typedef unsigned int   uint;




// NULL if needed
#ifndef NULL                                       
#define NULL 0
#endif




#ifndef __BORLANDC__

// randomize
#ifndef randomize
#define randomize() srand((uint)time(NULL))
#endif

// randoms
#ifndef random
inline int random(int max)
{
    float n=(float)rand()/((float)(RAND_MAX));
    int val=(int)floor(n*max);
    if (val>=max) val=max-1;
    return val;
}
#endif

#endif




// inp | outp for VC++
#ifdef __VISUALC__
#define outp  _outp
#define outpw _outpw
#define outpd _outpd
#define inp  _inp
#define inpw _inpw
#define inpd _inpd
#endif

// inp | outp fo DJGPP
#if defined(__DJGPP__) 
#include <pc.h>
#endif




// console input
#if !defined(__LINUX__) && !defined(__CYGNUS__)
#include <conio.h>
#endif



// include memory routines
#if defined(__VISUALC__) || defined(__GNU__)
#include <memory.h>
#include <string.h>
#endif

#ifdef __WATCOMC__
#include <mem.h>
#include <string.h>
#endif



// include windows.h for windows platform
#ifdef __WIN32__
#include <windows.h>
#endif




// win32 delay
#ifdef __WIN32__
inline void delay(int time) { Sleep(time); }
#endif




// fixup icky kbhit #defines in DJGPP
#ifdef __DJGPP__
    #if kbhit == _conio_kbhit
    #undef kbhit
    inline int kbhit() { return _conio_kbhit(); }
    #endif
#endif


// no kbhit
#ifdef __CYGNUS__
    inline int kbhit() { return 0; }
#endif




// fallback getch to getchar (ansi)
#ifndef getch
    inline int getch() { return getchar(); }
#endif




// define "PACKED"
#ifndef PACKED
    #if defined (__DJGPP__)
        #define PACKED __attribute__ ((packed))        
    #else
        #define PACKED 
    #endif
#endif



// stricmp
#if defined(__LINUX__) || defined(__CYGNUS__)
    #define stricmp strcasecmp
#endif





// undefine
#undef ABSOLUTE
#undef HALFTONE





// HWINDOW
#ifdef __WIN32__

    // win32 HWND
    #define HWINDOW HWND

#elif __X11__

    // X11 Window
    #define HWINDOW (*Window)

#else
    
    // dummy window
    struct STUPIDWINDOW { int bah; };
    typedef STUPIDWINDOW* HWINDOW;

#endif









#endif
