home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / fonts / cw_src / install / protect.c < prev   
Encoding:
C/C++ Source or Header  |  1995-05-19  |  2.7 KB  |  145 lines

  1. #include "c:\windev\include\dos.h"
  2. #include "c:\windev\include\bios.h"
  3. #include "c:\windev\include\memory.h"
  4.  
  5. //#define _TRACE_
  6.  
  7. #define    SecSize 512
  8. #define    SectorId 0x55
  9.  
  10. #pragma    check_stack (off)
  11.  
  12. static    unsigned char SecTable []= {
  13.     79, 1,  1, 2,
  14.     79, 1,  2, 2,
  15.     79, 1,  3, 2,
  16.     79, 1,  4, 2,
  17.     79, 1,  SectorId, 2,
  18.     79, 1,  6, 2,
  19.     79, 1,  7, 2,
  20.     79, 1,  8, 2,
  21.     79, 1,  9, 2,
  22.     79, 1, 10, 2,
  23.     79, 1, 11, 2,
  24.     79, 1, 12, 2,
  25.     79, 1, 13, 2,
  26.     79, 1, 14, 2,
  27.     79, 1, 15, 2
  28.     };
  29.  
  30. int    makedisk (int serialno, short drive, int ninsts);
  31. int    checkdsk (short drive);
  32. extern    unsigned BiosSum (void);
  33.  
  34. static    struct
  35.     {
  36.     int    serialId;
  37.     int    installed;
  38.     unsigned bioschk;
  39.     char    reserved [SecSize-6];
  40.     } Sector;
  41.  
  42. //
  43. //    write copyright information to disk (serial number);
  44. //
  45. int    makedisk (int serialno, short drive, int ninsts)
  46.     {
  47.     short retval;
  48.     char *iobuf= (char*) &Sector;
  49.  
  50.     memset ((char*) &Sector, 0, SecSize);
  51.     Sector.serialId= serialno;
  52.     Sector.installed= ninsts;
  53.     Sector.bioschk= 0x1234;
  54.     _asm
  55.         {
  56.         push    es
  57.         mov    ax, ds
  58.         mov    es, ax
  59.         }
  60.     _asm
  61.         {
  62.         xor    ah, ah
  63.         int    13h
  64.         mov    ax, 1703h
  65.         mov    dl, byte ptr drive
  66.         int    13h
  67.         jc    wfail
  68.         mov    dl, byte ptr drive    // drive number
  69.         mov    dh, 1            // head number
  70.         mov    ch, 79            // track number
  71.         mov    al, 15            // number of sectors
  72.         mov    ah, 5            // format track
  73.         mov    bx, offset SecTable    // addr. fields for track
  74.         int    13h
  75.         jc    wfail
  76.         mov    dl, byte ptr drive    // drive number
  77.         mov    dh, 1            // head number
  78.         mov    ch, 79            // track number
  79.         mov    cl, SectorId        // sector number
  80.         mov    al, 1            // number of sectors
  81.         mov    bx, iobuf        // io buffer address
  82.         mov    ah, 3            // write sector
  83.         int    13h
  84.         jc    wfail
  85.         xor    ax, ax
  86.         jmp    short wdone
  87.     wfail:    mov    ax, -1
  88.     wdone:    mov    retval, ax
  89.         }
  90.     return retval;
  91.     }
  92.  
  93. //
  94. //    check copyright information, decrement installation counter
  95. //    if first installlation, write BIOS checksumm value
  96. //
  97. int    checkdsk (short drive)
  98.     {
  99.     short retval;
  100.     char *iobuf= (char*) &Sector;
  101.  
  102.     _asm
  103.         {
  104.         mov    dl, byte ptr drive    // drive number
  105.         mov    dh, 1            // head number
  106.         mov    ch, 79            // track number
  107.         mov    cl, SectorId        // sector number
  108.         mov    al, 1            // number of sectors
  109.         mov    bx, iobuf        // io buffer address
  110.         mov    ah, 2            // write sector
  111.         int    13h
  112.         jc    rfail
  113.         xor    ax, ax
  114.         jmp    short rdone
  115.     rfail:    mov    ax, -2
  116.     rdone:    mov    retval, ax
  117.         }
  118.     if (!retval)
  119.         {
  120.         if (Sector.installed)
  121.             {
  122.             Sector.installed--;
  123.             _asm
  124.                 {
  125.                 mov    dl, byte ptr drive
  126.                 mov    dh, 1
  127.                 mov    ch, 79
  128.                 mov    cl, SectorId
  129.                 mov    al, 1
  130.                 mov    bx, iobuf
  131.                 mov    ah, 3
  132.                 int    13h
  133.                 jc    wfail
  134.                 xor    ax, ax
  135.                 jmp    short wdone
  136.             wfail:    mov    ax, -3
  137.             wdone:    mov    retval, ax
  138.                 }
  139.             return retval;
  140.             }
  141.         else
  142.             return 1;
  143.         }
  144.     }
  145.