home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / TICTAC.ZIP / TICLIB.C < prev    next >
C/C++ Source or Header  |  1995-12-19  |  6KB  |  238 lines

  1. #include <conio.h>
  2. #include <stdio.h>
  3. #include <dos.h>
  4. #include <alloc.h>
  5. #include <mem.h>
  6. #include "ticlib.inc"
  7.  
  8. #define INTROSCREEN "TICSCRN.DTA"
  9. #define I asm
  10. void fadein(char far *);
  11. void fadeout(char far * palptr);
  12. void CycleColors(char far *PalPtr,int start, int stop);
  13.  
  14. void wait_vbi(void)
  15. {
  16. I    mov        dx,3DAh
  17. vent1:
  18. I    in         al,dx
  19. I    test       al,8
  20. I    jz         vent1
  21. I    cli
  22. vent2:
  23. I    in         al,dx
  24. I    test       al,8
  25. I    jnz        vent2
  26. I    sti
  27. }
  28.  
  29.  
  30. void GetColor (unsigned char Color,
  31.                     unsigned char *Red,
  32.                     unsigned char *Green,
  33.                     unsigned char *Blue)
  34. {       /* GetColor */
  35.   outp(967,Color);
  36.   *Red=inp(969);
  37.   *Green=inp(969);
  38.   *Blue=inp(969);
  39. }       /* GetColor */
  40.  
  41. void SetColor (unsigned char Color,
  42.                     unsigned char Red,
  43.                     unsigned char Green,
  44.                     unsigned char Blue)
  45. {       /* SetColor */
  46.   outp(968,Color);
  47.   outp(969,Red);
  48.   outp(969,Green);
  49.   outp(969,Blue);
  50. }       /* SetColor */
  51.  
  52. size_t freadfar(unsigned Segm, unsigned Offs, size_t start, size_t size, char FName[80])
  53. {
  54. size_t WasRead;
  55. unsigned fhandle;
  56.     unsigned int Segment;
  57.     unsigned int Offsett;
  58.  
  59.     Segment = FP_SEG(FName);
  60.     Offsett = FP_OFF(FName);
  61.  
  62. asm {
  63.     PUSH DS
  64.  
  65.     mov ax, Segment
  66.     mov ds, ax
  67.     mov DX, Offsett
  68.     MOV AX, 3D00h
  69.     INT 21h                            //open file
  70.     JC  EXIT
  71.  
  72.     MOV fhandle, AX                    // save filehandle
  73.  
  74.     MOV BX, AX                         // BX Has to hold File Handle
  75.     MOV CX,size                        // DX holds the size
  76.     MOV DX, Segm                       // DS:DX points to the read buffer
  77.     MOV DS, DX
  78.     MOV DX, Offs
  79.     MOV AH,3Fh                         // function to read data
  80.     INT 21h                            // read file
  81.     MOV WasRead, AX
  82.  
  83.     mov bx, fhandle
  84.     MOV AH, 3Eh
  85.     INT 21h                            //close file
  86. }
  87. EXIT: asm POP DS
  88.     if(start);                                  // sorry this is not yet implemented
  89.     return(WasRead);
  90. }
  91.  
  92.  
  93. void intro(void)                              // game intro!!! C00L!!!!
  94. {void far *Scrn;
  95.  char far *pallete;
  96.  char tmppal[768];
  97.  int count;
  98.  
  99.  Scrn = farcalloc(64000,1);               // allocate memory for the buffer
  100.                                           // get memory for the image screen &\& pallete
  101.  if(!Scrn)
  102.  {  printf("error allocating 64000 bytes for Screen Buffer");
  103.      return;
  104.  }
  105.  freadfar(FP_SEG(Scrn),FP_OFF(Scrn),0 , 64000, INTROSCREEN);
  106.  
  107.  asm {                               // set up VGA 320*200*256
  108.     mov ax, 13h
  109.     int 10h
  110.     }
  111.  pallete=Plt;
  112.  for(count=0;count<256;count++)     // clear the pallete
  113.      SetColor(count,0,0,0);
  114.  wait_vbi();
  115.  
  116.  for(count=0;count<768;count++)
  117.     tmppal[count]=pallete[count];
  118.  
  119.  pallete[223*3]=pallete[57*3];      // clear the colors of the pink words in the middle
  120.  pallete[223*3+1]=pallete[57*3+1];      // clear the colors of the pink words in the middle
  121.  pallete[223*3+2]=pallete[57*3+2];      // clear the colors of the pink words in the middle
  122.  pallete[224*3]=pallete[57*3];      // clear the colors of the pink words in the middle
  123.  pallete[224*3+1]=pallete[57*3+1];      // clear the colors of the pink words in the middle
  124.  pallete[224*3+2]=pallete[57*3+2];      // clear the colors of the pink words in the middle
  125.  pallete[225*3]=pallete[57*3];      // clear the colors of the pink words in the middle
  126.  pallete[225*3+1]=pallete[57*3+1];      // clear the colors of the pink words in the middle
  127.  pallete[225*3+2]=pallete[57*3+2];      // clear the colors of the pink words in the middle
  128.  
  129.  movedata(FP_SEG(Scrn),FP_OFF(Scrn),0xA000,0,64000);
  130.  fadein(pallete);
  131.  delay(1000);
  132.  pallete[225*3]=tmppal[225*3];
  133.  pallete[225*3+1]=tmppal[225*3+1];
  134.  pallete[225*3+2]=tmppal[225*3+2];
  135.  SetColor(225,pallete[225*3],pallete[225*3+1],pallete[225*3+2]);
  136.  wait_vbi();
  137.  delay(1000);
  138.  pallete[224*3]=tmppal[224*3];
  139.  pallete[224*3+1]=tmppal[224*3+1];
  140.  pallete[224*3+2]=tmppal[224*3+2];
  141.  SetColor(224,pallete[224*3],pallete[224*3+1],pallete[224*3+2]);
  142.  wait_vbi();
  143.  delay(1000);
  144.  pallete[223*3]=tmppal[223*3];
  145.  pallete[223*3+1]=tmppal[223*3+1];
  146.  pallete[223*3+2]=tmppal[223*3+2];
  147.  SetColor(223,pallete[223*3],pallete[223*3+1],pallete[223*3+2]);
  148.  wait_vbi();
  149.  
  150.  for(count=0;count<768;count++)             // save pallete for cycling;
  151.     tmppal[count]=pallete[count];
  152.  
  153.  delay(1000);
  154.  while(!kbhit())
  155.  /*   CycleColors(tmppal,226,254)*/;         // have to fix the cycling. Ohh well
  156.  while(kbhit())
  157.     getch();
  158.  fadeout(tmppal);
  159.  farfree(Scrn);
  160.  delay(2000);
  161. }
  162.  
  163. void fadein(char far * palptr)
  164. {char far *Pallete;
  165.  char Current[256][3];
  166.  int i;
  167.  int cycle;
  168.  
  169.  Pallete = palptr;
  170.  
  171.  for(i=0;i<256;i++)
  172.  {    Current[i][0]=0;    Current[i][1]=0;    Current[i][2]=0; }
  173.  
  174.  for(cycle=0;cycle<64;cycle++)
  175.  {
  176.  for(i=0;i<256;i++)
  177.  {
  178.     if(Current[i][0]<Pallete[i*3]) Current[i][0]++;
  179.     if(Current[i][1]<Pallete[i*3+1]) Current[i][1]++;
  180.     if(Current[i][2]<Pallete[i*3+2]) Current[i][2]++;
  181.  }
  182.  delay(10);
  183.  wait_vbi();
  184.  for(i=0;i<256;i++)
  185.     SetColor(i,Current[i][0],Current[i][1],Current[i][2]);
  186.  }
  187. }
  188.  
  189. void fadeout(char far * palptr)
  190. {char far *Pallete;
  191.  char Current[256][3];
  192.  int i;
  193.  int cycle;
  194.  
  195.  Pallete = palptr;
  196.  
  197.  for(i=0;i<256;i++)
  198.  {  Current[i][0]=Pallete[i*3];
  199.     Current[i][1]=Pallete[i*3+1];
  200.     Current[i][2]=Pallete[i*3+2]; }
  201.  
  202.  for(cycle=0;cycle<64;cycle++)
  203.  {
  204.  for(i=0;i<256;i++)
  205.  {
  206.     if(Current[i][0]>0) Current[i][0]--;
  207.     if(Current[i][1]>0) Current[i][1]--;
  208.     if(Current[i][2]>0) Current[i][2]--;
  209.  }
  210.  delay(10);
  211.  wait_vbi();
  212.  for(i=0;i<256;i++)
  213.     SetColor(i,Current[i][0],Current[i][1],Current[i][2]);
  214.  }
  215. }
  216.  
  217. void CycleColors(char far *PalPtr,int start, int stop)
  218. {  unsigned char r,g,b;
  219.    unsigned char R,G,B;
  220.    unsigned char count;
  221.  
  222.   if (stop > start)
  223.   {                // Main Cycle
  224.      wait_vbi();
  225.      GetColor(stop,&r,&g,&b);
  226.  
  227.      for(count=stop;count>start;count--)
  228.      {   GetColor(count-1,&R,&G,&B);
  229.          SetColor(count,R,G,B);
  230.          PalPtr[count*3]=R;
  231.          PalPtr[count*3+1]=G;
  232.          PalPtr[count*3+2]=B;
  233.      }
  234.      SetColor(start,r,g,b);
  235.   }
  236. }
  237.  
  238.