home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / MCGA.ZIP / RAINBOW.PAS
Encoding:
Pascal/Delphi Source File  |  1987-10-02  |  5.6 KB  |  178 lines

  1. procedure RainbowMode;
  2.   var
  3.     regs : record
  4.              AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags : Integer;
  5.            end;
  6.   begin
  7.     regs.ax := $0013;
  8.     intr($10,regs);
  9.   end {RainbowMode};
  10.  
  11. procedure NormalMode;
  12.   var
  13.     regs : record
  14.              AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags : Integer;
  15.            end;
  16.   begin
  17.     regs.ax := $0003;
  18.     intr($10,regs);
  19.   end {NormalMode};
  20.  
  21. function Color(hue,chroma, intensity : integer) : integer;
  22.   begin
  23.     Color := (intensity * 3 + chroma) * 24 + hue + 32;
  24.   end {Color};
  25.  
  26. procedure plot(x,y,color : integer);
  27.   begin
  28.     mem[$A000:y*320+x] := color;
  29.   end {plot};
  30.  
  31. procedure FillArea(x,y,w,h,c : integer);
  32.   var
  33.     a,r : integer;
  34.   begin
  35.     a := 320 * y + x;
  36.     for r := 1 to h do begin
  37.       FillChar(mem[$A000:a],w,lo(c));
  38.       a := a + 320;
  39.     end;
  40.   end {FillArea};
  41.  
  42. procedure FillTop(x,y,w,h,c : integer);
  43.   var
  44.     a,r : integer;
  45.   begin
  46.     a := 320 * y + x;
  47.     for r := 1 to h do begin
  48.       FillChar(mem[$A000:a],w,lo(c));
  49.       a := a + 319;
  50.     end;
  51.   end {FillArea};
  52.  
  53. procedure FillSide(x,y,w,h,c : integer);
  54.   var
  55.     a,r : integer;
  56.   begin
  57.     a := 320 * succ(y-h) + x;
  58.     for r := 1 to h div 2 do begin
  59.       FillChar(mem[$A000:a],r,lo(c));
  60.       a := a + 319;
  61.     end;
  62.     a := a - 319;
  63.     for r := w downto 1 do begin
  64.       FillChar(mem[$A000:a],w,lo(c));
  65.       a := a + 320;
  66.     end;
  67.     a := a - 320;
  68.     for r := h - h div 2 downto 1 do begin
  69.       FillChar(mem[$A000:a],r,lo(c));
  70.       a := a + 320;
  71.     end;
  72.   end {FillArea};
  73.  
  74. procedure DrawCube(x,y,h:integer);
  75.   begin
  76.     FillTop(x-16,y-16,32,16,Color(h,0,0));
  77.     FillArea(x-32,y,32,32,Color(h,0,1));
  78.     FillSide(x+15,y+16,16,32,Color(h,0,2));
  79.   end {DrawCube};
  80.  
  81. procedure Wait;
  82.   var
  83.     c : char;
  84.   begin
  85.     repeat
  86.     until KeyPressed;
  87.     read(kbd,c);
  88.     while KeyPressed do
  89.       read(kbd,c);
  90.   end {Wait};
  91.  
  92. var
  93.   h,c,i,x,y : integer;
  94.  
  95. const
  96.   Cube : array[1..6] of record x,y,color:integer end =
  97.      ((x:128;y:106;color:12), (x:180;y:106;color:20), (x:232;y:106;color: 8),
  98.       (x:154;y: 74;color: 4), (x:206;y: 74;color: 0), (x:180;y: 42;color:16));
  99.  
  100. begin
  101.   ClrScr;
  102.   GotoXY((80-51) div 2,1);
  103.   writeln('Welcome to the Wonderful World of Mode 19 Graphics!');
  104.   GotoXY(1,3);
  105.   writeln('    Mode 19 is the 320x200 pixel graphics mode availble on all of the new IBM ');
  106.   writeln('PS/2 computers, whether equiped with the MCGA (models 25 and 30) or the VGA   ');
  107.   writeln('(models 50, 60, and 80).  This program will show the default palette settings ');
  108.   writeln('for the new mode.                                                             ');
  109.   writeln('    The first screen will show all 256 values.  The values are displayed in   ');
  110.   writeln('order from left to right, moving down the screen.  They are grouped according ');
  111.   writeln('to how they would be used by a program.                                       ');
  112.   writeln('    Rows 1 and 2 show 16 values each.  The first are the old CGA colors, the  ');
  113.   writeln('second are shades of grey.  The next 9 rows show 24 values each.  Each row    ');
  114.   writeln('displays a full spectrum of hues, with each row differing in the chroma and   ');
  115.   writeln('the intensity of the color.  The last row contains the 12 "dead" colors.  They');
  116.   writeln('are all defined in the palette table as black.                                ');
  117.   writeln('    The second screen shows the center 144 values from the previous screen,   ');
  118.   writeln('arranged in a different format.  Each of the 24 large squares has a single hue');
  119.   writeln('displayed, sub-divided into 9 small squares showing variation of chroma and   ');
  120.   writeln('intensity values.                                                             ');
  121.   writeln('    The background color on both screens is a dim, pastel yellow, specifically');
  122.   writeln('the rightmost of the two colors at the center of the 24x9 array on the first  ');
  123.   writeln('screen.  The color may be found on the second screen at the center of the big ');
  124.   writeln('square in the first column, third row.                                        ');
  125.   writeln('    The third screen is just for fun.                                         ');
  126.   GotoXY(51,25);
  127.   Write('Press any key to continue...');
  128.   Wait;
  129.   RainbowMode;
  130.   FillArea(0,0,320,200,Color(12,1,1));
  131.   { 0 to 15 are "standard" colors }
  132.   { 16 to 31 are shades of grey }
  133.   for h := 0 to 31 do begin
  134.     x := (h mod 16 + 4) * 12 + 16;
  135.     y := (h div 16) * 24 + 12;
  136.     FillArea(x,y,12,12,h);
  137.   end;
  138.   { 32 to 247 is a spectrum }
  139.   { 24 hues x 3 chroma levels x 3 intensities }
  140.   for h := 0 to 215 do begin
  141.     x := (h mod 24) * 12 + 16;
  142.     y := (h div 24 + 4) * 12 + 12;
  143.     FillArea(x,y,12,12,h+32);
  144.   end;
  145.   { 248 to 255 are all black }
  146.   for h := 0 to 7 do begin
  147.     x := (h mod 16 + 4) * 12 + 64;
  148.     y := (h div 16 + 15) * 12;
  149.     FillArea(x,y,12,12,h+248);
  150.   end;
  151.   Wait;
  152.   FillArea(0,0,320,200,Color(12,1,1));
  153.   for h := 0 to 23 do begin
  154.     for c := 0 to 2 do
  155.       for i := 0 to 2 do
  156.         FillArea((h mod 6)*50+11 + c*16,(h div 6)*50+1 + i*16,
  157.                  16,16,Color(h,c,i));
  158.   end;
  159.   Wait;
  160.   { draw room }
  161.   FillArea(0,0,320,135,Color(2,1,1));
  162.   FillArea(0,135,320,65,Color(7,1,1));
  163.   delay(500);
  164.   { draw table }
  165.   FillArea(102,102,6,80,Color(11,1,2));
  166.   FillArea(293,102,6,80,Color(11,1,2));
  167.   FillArea(52,148,6,52,Color(11,1,2));
  168.   FillArea(243,148,6,52,Color(11,1,2));
  169.   FillTop(100,100,200,50,Color(11,1,1));
  170.   { draw boxes }
  171.   for i := 1 to 6 do begin
  172.     delay(500);
  173.     DrawCube(Cube[i].x,Cube[i].y,Cube[i].color);
  174.   end;
  175.   delay(500);
  176.   Wait;
  177.   NormalMode;
  178. end.