home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1995 November / PCWK1195.iso / inne / dos / programo / pmw120.exe / EXAMPLES.ZIP / EXAMPLE1.C next >
Encoding:
C/C++ Source or Header  |  1995-07-28  |  2.7 KB  |  136 lines

  1. /*****************************************************************************
  2.  
  3.   This is a simple example of some graphics functions in C. I got a bit bored
  4. one day so I decided to make this little plasma. The original idea came from
  5. Jare/VangeliSTeam's VTIRIS and was converted to C just for fun. This program
  6. also makes use of floating point and inline ASM just to show that they do
  7. indeed work under PMODE/W.
  8.  
  9. *****************************************************************************/
  10.  
  11. #include <stdio.h>
  12. #include <math.h>
  13.  
  14. #define M_PI 3.141592654
  15.  
  16. void vmode (unsigned short);
  17. void waitvr (void);
  18. void tweakvga (void);
  19.  
  20. #pragma aux tweakvga =\
  21.         "mov dx,3c4h",\
  22.         "mov ax,604h",\
  23.         "out dx,ax",\
  24.         "mov ax,0f02h",\
  25.         "out dx,ax",\
  26.         "mov dx,3d4h",\
  27.         "mov ax,14h",\
  28.         "out dx,ax",\
  29.         "mov ax,0e317h",\
  30.         "out dx,ax",\
  31.         "mov al,9",\
  32.         "out dx,al",\
  33.         "inc dx",\
  34.         "in al,dx",\
  35.         "and al,0e0h",\
  36.         "add al,7",\
  37.         "out dx,al",\
  38.         modify [ax dx];
  39.  
  40. #pragma aux vmode =\
  41.         "int 10h",\
  42.         parm [ax] modify [ax];
  43.  
  44. #pragma aux waitvr =\
  45.         "mov dx,3dah",\
  46.         "wait1:",\
  47.         "in al,dx",\
  48.         "test al,8",\
  49.         "jz wait1",\
  50.         modify [al dx];
  51.  
  52. void main ()
  53. {
  54.   static char wavetable[256], pal[768];
  55.  
  56.   int  v, x, y;
  57.  
  58.   char z;
  59.   char *vidmem = (char *)0xA0000;
  60.  
  61.   char spd1 = 1, spd2 = 2, spd3 = 3, spd4 = 4;
  62.   char pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
  63.   char tpos1, tpos2, tpos3, tpos4;
  64.  
  65.   for (x=0, y=0; x<64*3; x+=3, y++)
  66.     pal[x] = y;
  67.  
  68.   for (x=64*3, y=63; x<128*3; x+=3, y--)
  69.     pal[x] = y;
  70.  
  71.   for (x=128*3, y=0; x<192*3; x+=3, y++)
  72.     pal[x+2] = y;
  73.  
  74.   for (x=192*3, y=63; x<256*3; x+=3, y--)
  75.     pal[x+2] = y;
  76.  
  77.   for (x=0; x<256; x++)
  78.     wavetable[x] = 30 * (1 + sin(x*2 * M_PI / 256));
  79.  
  80.   vmode (0x13);
  81.   tweakvga ();
  82.   setpal (pal);
  83.  
  84.   while (!kbhit ())
  85.   {
  86.     waitvr ();
  87.  
  88.     v = 0;
  89.     tpos1 = pos1;
  90.     tpos2 = pos2;
  91.  
  92.     for (x=0; x<50; x++)
  93.     {
  94.       tpos3 = pos3;
  95.       tpos4 = pos4;
  96.  
  97.       for(y=0; y<80; y++)
  98.       {
  99.         z = wavetable[tpos1] + wavetable[tpos2] +
  100.             wavetable[tpos3] + wavetable[tpos4];
  101.  
  102.         vidmem[v ++] = z;
  103.  
  104.         tpos3 += 1;
  105.         tpos4 += 3;
  106.       }
  107.  
  108.       tpos1 += 2;
  109.       tpos2 += 1;
  110.     }
  111.  
  112.     pos1 += spd1;
  113.     pos2 -= spd2;
  114.     pos3 += spd3;
  115.     pos4 -= spd4;
  116.   }
  117.  
  118.   getch ();
  119.   vmode (3);
  120. }
  121.  
  122. void setpal (unsigned char palp[])
  123. {
  124.   int pcount;
  125.  
  126.   outp (0x3c8, 0);
  127.  
  128.   for (pcount=0; pcount<768; pcount+=3)
  129.   {
  130.     outp (0x3c9, palp[pcount]);
  131.     outp (0x3c9, palp[pcount+1]);
  132.     outp (0x3c9, palp[pcount+2]);
  133.   }
  134. }
  135.  
  136.