home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / OPENDOOR / RA-CDK03.ZIP / RACDK.H < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-29  |  6.6 KB  |  149 lines

  1. /* File:    RACDK.H     'C' functions for RemoteAccess 2.50 Gamma
  2.     Version:        0.3    (22/04/96)
  3.     Author:        Damien Guard
  4.     Copyright:  Envy Technologies, 1996.
  5.     Notes:       CRC algorithm based on Ross Williams reflected form
  6.                     ftp://ftp.delaide.edu.au/pub/rocksoft/crc_v3.txt
  7.  
  8.     CRC32
  9.     =====
  10.     This routine uses a reflected 32-bit CRC with direct table lookup
  11.     for speed.  This routine should work with CRC'ing RemoteAccess
  12.     passwords & indexes, JAM message base checksums and Z-Modem blocks.
  13.  
  14.     Example:        myCRC=CRC32(mystring,strlen(mystring));
  15.     This would generate the CRC32 for the string 'mystring' and return this
  16.     strings CRC32 code as a long integer (32-bits hence the name).
  17.  
  18.  
  19.     TimeSlice
  20.     =========
  21.     This routine will release timeslices to DESQview, OS/2, Windows etc.
  22.     Please note that the there are several older multitasking systems
  23.     supported by RemoteAccess for which I can not find details on how to
  24.     detect & timeslice to so are not supported by this routine.  They are
  25.     DoubleDOS, TopView, MultiLink and PC-MOS/386.
  26.  
  27.     The first time you call this routine it will attempt to detect Windows,
  28.     OS/2 and DESQview then timeslice to the best detected OS.  (The order
  29.     is OS/2, Windows, DESQview then DOS generic).  Note: Windows NT does
  30.     not appear to allow DOS sessions to timeslice.
  31.  
  32. */
  33.  
  34. #include <dos.h>
  35.  
  36. /* Prototypes ───────────────────────────────────────────────────────────── */
  37. unsigned long CRC32(unsigned char *pBuffer, unsigned int iBufLen);
  38. void TimeSlice();
  39.  
  40. /* Poly lookup table ────────────────────────────────────────────────────── */
  41. static long crc32table[256]=
  42.     {            0L,  1996959894L,  -301047508L, -1727442502L,   124634137L,
  43.       1886057615L,  -379345611L, -1637575261L,   249268274L,  2044508324L,
  44.       -522852066L, -1747789432L,   162941995L,  2125561021L,  -407360249L,
  45.      -1866523247L,   498536548L,  1789927666L,  -205950648L, -2067906082L,
  46.         450548861L,  1843258603L,  -187386543L, -2083289657L,   325883990L,
  47.       1684777152L,   -43845254L, -1973040660L,   335633487L,  1661365465L,
  48.         -99664541L, -1928851979L,   997073096L,  1281953886L,  -715111964L,
  49.      -1570279054L,  1006888145L,  1258607687L,  -770865667L, -1526024853L,
  50.         901097722L,  1119000684L,  -608450090L, -1396901568L,   853044451L,
  51.       1172266101L,  -589951537L, -1412350631L,   651767980L,  1373503546L,
  52.       -925412992L, -1076862698L,   565507253L,  1454621731L,  -809855591L,
  53.      -1195530993L,   671266974L,  1594198024L,  -972236366L, -1324619484L,
  54.         795835527L,  1483230225L, -1050600021L, -1234817731L,  1994146192L,
  55.          31158534L, -1731059524L,  -271249366L,  1907459465L,   112637215L,
  56.      -1614814043L,  -390540237L,  2013776290L,   251722036L, -1777751922L,
  57.       -519137256L,  2137656763L,   141376813L, -1855689577L,  -429695999L,
  58.       1802195444L,   476864866L, -2056965928L,  -228458418L,  1812370925L,
  59.         453092731L, -2113342271L,  -183516073L,  1706088902L,   314042704L,
  60.      -1950435094L,   -54949764L,  1658658271L,   366619977L, -1932296973L,
  61.         -69972891L,  1303535960L,   984961486L, -1547960204L,  -725929758L,
  62.       1256170817L,  1037604311L, -1529756563L,  -740887301L,  1131014506L,
  63.         879679996L, -1385723834L,  -631195440L,  1141124467L,   855842277L,
  64.      -1442165665L,  -586318647L,  1342533948L,   654459306L, -1106571248L,
  65.       -921952122L,  1466479909L,   544179635L, -1184443383L,  -832445281L,
  66.       1591671054L,   702138776L, -1328506846L,  -942167884L,  1504918807L,
  67.         783551873L, -1212326853L, -1061524307L,  -306674912L, -1698712650L,
  68.          62317068L,  1957810842L,  -355121351L, -1647151185L,    81470997L,
  69.       1943803523L,  -480048366L, -1805370492L,   225274430L,  2053790376L,
  70.       -468791541L, -1828061283L,   167816743L,  2097651377L,  -267414716L,
  71.      -2029476910L,   503444072L,  1762050814L,  -144550051L, -2140837941L,
  72.         426522225L,  1852507879L,   -19653770L, -1982649376L,   282753626L,
  73.       1742555852L,  -105259153L, -1900089351L,   397917763L,  1622183637L,
  74.       -690576408L, -1580100738L,   953729732L,  1340076626L,  -776247311L,
  75.      -1497606297L,  1068828381L,  1219638859L,  -670225446L, -1358292148L,
  76.         906185462L,  1090812512L,  -547295293L, -1469587627L,   829329135L,
  77.       1181335161L,  -882789492L, -1134132454L,   628085408L,  1382605366L,
  78.       -871598187L, -1156888829L,   570562233L,  1426400815L,  -977650754L,
  79.      -1296233688L,   733239954L,  1555261956L, -1026031705L, -1244606671L,
  80.         752459403L,  1541320221L, -1687895376L,  -328994266L,  1969922972L,
  81.          40735498L, -1677130071L,  -351390145L,  1913087877L,    83908371L,
  82.      -1782625662L,  -491226604L,  2075208622L,   213261112L, -1831694693L,
  83.       -438977011L,  2094854071L,   198958881L, -2032938284L,  -237706686L,
  84.       1759359992L,   534414190L, -2118248755L,  -155638181L,  1873836001L,
  85.         414664567L, -2012718362L,   -15766928L,  1711684554L,   285281116L,
  86.      -1889165569L,  -127750551L,  1634467795L,   376229701L, -1609899400L,
  87.       -686959890L,  1308918612L,   956543938L, -1486412191L,  -799009033L,
  88.       1231636301L,  1047427035L, -1362007478L,  -640263460L,  1088359270L,
  89.         936918000L, -1447252397L,  -558129467L,  1202900863L,   817233897L,
  90.      -1111625188L,  -893730166L,  1404277552L,   615818150L, -1160759803L,
  91.       -841546093L,  1423857449L,   601450431L, -1285129682L, -1000256840L,
  92.       1567103746L,   711928724L, -1274298825L, -1022587231L,  1510334235L,
  93.         755167117L };
  94.  
  95. /* CRC-32 calculation routine ───────────────────────────────────────────── */
  96. unsigned long CRC32(unsigned char *pBuffer, unsigned int iBufLen)
  97. {
  98.      unsigned long crc = -1L;
  99.      while (iBufLen--)
  100.         crc = crc32table[(crc ^ *pBuffer++) & 0xFFL] ^ (crc >> 8);
  101.      return (crc);
  102. }
  103.  
  104. /* Timeslicing routines ─────────────────────────────────────────────────── */
  105. void TimeSlice()
  106. {
  107.         static int rk_OS;
  108.         static int rk_OSkey;
  109.         union REGS t_regs;
  110.  
  111.         if (rk_OSkey != 27140) { /* First call - autodetect operating system */
  112.             rk_OS = 0;
  113.             /* Detect DESQview */
  114.             t_regs.x.ax = 0x2B01;
  115.             t_regs.x.cx = 0x4445;
  116.             t_regs.x.dx = 0x5351;
  117.             intdos(&t_regs, &t_regs);
  118.             if (t_regs.h.al != 0xFF) rk_OS = 1;
  119.             /* Detect Windows */
  120.             t_regs.x.ax = 0x1600 ;
  121.             int86(0x2F, &t_regs, &t_regs);
  122.             switch (t_regs.h.al) {
  123.                 case 0x00 :
  124.                 case 0x01 :
  125.                 case 0x80 :
  126.                 case 0xFF : break;
  127.                 default   : rk_OS = 2;
  128.             }
  129.             /* Detect OS/2 */
  130.             if (_osmajor > 9) rk_OS = 2;
  131.             rk_OSkey = 27140;
  132.             printf("RACDK debug: Detected type %d\n",rk_OS);
  133.         };
  134.  
  135.         switch (rk_OS) {
  136.             case 0 : /* Generic timeslice for DOS */
  137.                     asm HLT;
  138.                     break;
  139.             case 1 : /* DESQview timeslice */
  140.                     t_regs.x.ax = 0x1000;
  141.                     int86(0x15,&t_regs,&t_regs);
  142.                     break;
  143.             case 2 : /* DPMI timeslice (Win,OS/2) */
  144.                     t_regs.x.ax = 0x1680;
  145.                     int86(0x2F,&t_regs,&t_regs);
  146.                     break;
  147.         };
  148. }
  149.