home *** CD-ROM | disk | FTP | other *** search
/ PC Underground / UNDERGROUND.ISO / graphic / scal_tst.pas < prev    next >
Pascal/Delphi Source File  |  1995-08-02  |  6KB  |  140 lines

  1. {$G+}
  2. Uses Crt,Sprites,ModeXLib,Gif,Tools;
  3.  
  4.  
  5. Procedure PutScalSprt(pg_ofs,x,y,scale_y:Integer;qsprite:spritetyp);
  6. var planecount,                 {counter of copied planes}
  7.     planemask:Byte;             {masks Write-Plane in TS-Register 2}
  8.     Skip,                       {number of bytes to skip}
  9.     ofs,                        {current offset in video RAM}
  10.     plane,                      {Number of current plane}
  11.     Width,                      {width of bytes to be copied in a line,}
  12.     dty:Word;                   {height}
  13.     source:Pointer;             {pointer to graphic data, if ds modified}
  14.  
  15.     ppp:Array[0..3] of Byte;    {number of pixels per plane}
  16.     rel_y,                      {fractional portion of rel. y-position}
  17.     add_y:Word;                 {fractional value of the addend}
  18.     direction:Integer;          {direction of movement (+/- 80)}
  19.     i:Word;                     {local loop counter}
  20. Begin
  21.   if (x + qsprite.dtx > 319)    {Clipping ? then cancel}
  22.   or (x < 0)
  23.   or (y + qsprite.dty*scale_y div 100 > 199) or (y < 0) then exit;
  24.   add_y:=100-abs(scale_y);      {calculate addend}
  25.   if scale_y < 0 then direction:=-80 else direction:=80;
  26.                                 {define direction}
  27.   Source:=qsprite.addr;         {Pointer graphic data}
  28.   dty:=qsprite.dty;             {load local Height variable}
  29.   plane:=x mod 4;               {calculate start plane}
  30.   ofs:=pg_ofs+80*y+(x div 4);   {and offset}
  31.   Width:=0;                     {preinitialize Width and Skip}
  32.   Skip:=0;
  33.  
  34.   i:=qsprite.dtx shr 2;         {number of even blocks of 4}
  35.   ppp[0]:=i;ppp[1]:=i;          {equals the minimum number of bytes to be copied}
  36.   ppp[2]:=i;ppp[3]:=i;
  37.   For i:=1 to qsprite.dtx and 3 do{note "excess" pixels in ppp}
  38.     Inc(ppp[(plane+i - 1) and 3]);{add pixels beginning with Startplane}
  39. asm
  40.   push ds                       {save ds}
  41.   mov ax,0a000h                 {load destination segment (VGA)}
  42.   mov es,ax
  43.  
  44.   lds si,source                 {source (pointer to graphic data) to ds:si}
  45.   mov cx,plane                  {Create start plane mask}
  46.   mov ax,1                      {move Bit 0 left by plane}
  47.   shl ax,cl
  48.   mov planemask,al              {save mask}
  49.   shl al,4                      {enter in upper nibble also}
  50.   or planemask,al
  51.   mov planecount,4              {4 planes to copy}
  52. @lplane:                        {will run once per plane}
  53.   mov cl,byte ptr plane         {load current plane}
  54.   mov di,cx                     {in di}
  55.   mov cl,byte ptr ppp[di]       {load cx with matching ppp number }
  56.   mov byte ptr Width,cl         {recalculate skip each time}
  57.   mov ax,direction              {obtain difference direction width}
  58.   sub ax,cx
  59.   mov skip,ax                   {and write in skip}
  60.  
  61.   mov rel_y,0                   {start again with y=0,0}
  62.  
  63.   mov cx,Width                  {load cx with Width}
  64.   or cl,cl                      {Width 0, then Plane finished}
  65.   je @plane_finished
  66.  
  67.   mov di,ofs                    {destination offset in video RAM to di}
  68.   mov ah,planemask              {reduce plane mask to bit [0..3]}
  69.   and ah,0fh
  70.   mov al,02h                    {and through TS - Register 2 (Write Plane Mask)}
  71.   mov dx,3c4h                   {set}
  72.   out dx,ax
  73.   mov bx,dty                    {initialize y-counter}
  74. @lcopy_y:                       {y-loop, run once per row}
  75. @lcopy_x:                       {x-loop, run once per pixel}
  76.   lodsb                         {get byte}
  77.   or al,al                      {if 0, then skip}
  78.   je @Value0
  79.   stosb                         {else set}
  80. @entry:
  81.   loop @lcopy_x                 {and loop continues}
  82.  
  83.   mov ax,rel_y                  {addend to fractional portion}
  84.   add ax,add_y
  85.   cmp ax,100                    {integer place incremented ?}
  86.   jb @noaddovfl                 {no, then continue}
  87.   sub ax,100                    {else reset decimal place}
  88.   sub di,direction              {and in next/previous line}
  89. @noaddovfl:
  90.   mov rel_y,ax                  {and rewrite in fractional portion}
  91.  
  92.   dec bx                        {continue y-counter}
  93.   je @plane_finished            {y-counter = 0, then next plane}
  94.   add di,skip                   {else skip to next line beginning}
  95.   mov cx,Width                  {reinitialize x-counter,}
  96.   jmp @lcopy_y                  {jump back to y-loop}
  97. @value0:                        {sprite color 0:}
  98.   inc di                        {skip destination byte}
  99.   jmp @entry                    {and back to loop}
  100. @plane_finished:                {y-loop ends here}
  101.  
  102.   rol planemask,1               {mask next plane}
  103.   mov cl,planemask              {plane 0 selected ?}
  104.   and cx,1                      {(Bit 1 set), then}
  105.   add ofs,cx                    {increase destination offset by 1 (Bit 1 !)}
  106.   inc plane                     {increment plane number (Index in ppp)}
  107.   and plane,3                   {reduce to 0 to 3}
  108.   dec planecount                {4 planes copied already ?, then end}
  109.   jne @lplane
  110.   pop ds                        {restore ds, and see you later}
  111. End;{asm}
  112. End;
  113.  
  114. Var Logo:SpriteTyp;
  115.     Sine:Array[0..99] of Word;
  116.     Height:Integer;
  117.     i:Word;
  118.  
  119.  
  120. Begin
  121.   Init_ModeX;                   {enable Mode X}
  122.   LoadGif('sprites');           {load image with logo}
  123.   GetSprite(88+ 6*320,150,82,Logo);    {initialize logo}
  124.   LoadGif('wallpape');          {load wallpaper}
  125.   p13_2_ModeX(48000,16000);     {and copy to background page}
  126.   Sin_Gen(Sine,100,100,0);      {precalculate sine}
  127.   I:=0;                         {index in sine to 0}
  128.   repeat
  129.     Inc(i);                     {increment index}
  130.     Height:=Integer(Sine[i mod 100]); {get height from sine}
  131.     CopyScreen(vpage,48000);    {clear background}
  132.     PutScalSprt(vpage,85,100-Height *84 div 200,Height,Logo);
  133.                                 {copy scaled sprite to current page}
  134.     Switch;                     {switch to this page}
  135.     WaitRetrace;                {and wait for retrace}
  136.   Until KeyPressed;
  137.   ReadLn;
  138.   TextMode(3);                  {normal text mode on}
  139. End.
  140.