home *** CD-ROM | disk | FTP | other *** search
/ Sound, Music & MIDI Collection 2 / SMMVOL2.bin / PROG / BWSB120B.ZIP / TTP / MCGA.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-12-19  |  4.9 KB  |  245 lines

  1. Unit MCGA;
  2. {$G+,A+}
  3.  
  4. Interface
  5.  
  6. Var
  7.   Page0, Page1 : Word;
  8.   Frames : Longint;
  9.  
  10.  
  11. Procedure SetMode(Mode : Word);
  12. Function Alloc(Paras : Word) : Word;
  13. Procedure FreeAlloc(Address : Word);
  14. Procedure CopyPage(Source, Dest : Word);
  15. Procedure ClearPage(Dest : Word);
  16. Procedure SetPalette;
  17. Procedure PutScaledSprite(X, Y, Size : Integer; Var Image; Page : Word);
  18. Procedure DeCompPCX(Var PCX; Dest, BottomLine : Word);
  19. Function CheckHit : Boolean;
  20. Procedure ShowCross(P : Word);
  21.  
  22. Implementation
  23.  
  24. {$F+}
  25. {$L Pal.Obj}
  26. Procedure Palette; External;
  27. {$F-}
  28.  
  29. Function Alloc(Paras : Word) : Word; Assembler;
  30.  
  31. Asm
  32.   Mov ah,48h
  33.   Mov bx,Paras
  34.   Int 21h
  35.   Jnc @Exit
  36.   Mov ax,0ffffh
  37.  @Exit:
  38. End;
  39.  
  40. Procedure FreeAlloc(Address : Word); Assembler;
  41.  
  42. Asm
  43.   Mov  es,Address
  44.   Mov  ah,49h
  45.   Int  10h
  46. End;
  47.  
  48. Procedure SetMode(Mode : Word); Assembler;
  49.  
  50. Asm
  51.   Mov  ax,Mode
  52.   Int  10h
  53.   Mov  ax,64000/16
  54.   Push ax
  55.   Call Alloc
  56.   Mov  Page1,ax
  57.   Mov  ax,$A000
  58.   Mov  Page0,ax
  59.   Mov  ax,Page1
  60.   Push ax
  61.   Call ClearPage
  62. End;
  63.  
  64. Procedure CopyPage(Source, Dest : Word); Assembler;
  65.  
  66. Asm
  67.   db 66h; Inc Word Ptr [Frames]        { Inc DWord Ptr [Frames] }
  68.   Push  ds
  69.   Mov   es,Dest
  70.   Mov   ds,Source
  71.   Mov   di,0
  72.   Mov   si,di
  73.   db 66h; Mov  cx,16000; db 00h,00h    { Mov  ecx,16000 }
  74.   db 66h; Rep  Movsw;                  { Rep  Movsd     }
  75.   Pop   ds
  76. End;
  77.  
  78. Procedure ClearPage(Dest : Word); Assembler;
  79.  
  80. Asm
  81.   Mov  es,Dest
  82.   Mov  di,0
  83.   db 66h; Xor ax,ax                 { Xor eax,eax }
  84.   db 66h; Mov cx,16000; db 00h,00h  { Mov ecx,16000 }
  85.   db 66h; Rep Stosw                 { Rep Stosd }
  86. End;
  87.  
  88.  
  89. Procedure SetPalette;
  90.  
  91. Var
  92.   Count : Word;
  93.  
  94. Begin
  95.   Port[$3c8] := 0;
  96.   For Count := 0 to 767 do
  97.     Port[$3c9] := Mem[Seg(Palette):Ofs(Palette)+Count];
  98. End;
  99.  
  100. Procedure PutScaledSprite(X, Y, Size : Integer; Var Image; Page : Word);
  101. { in : X - X Location of Sprite           }
  102. {      Y - Y Location of Sprite           }
  103. {      Size - Size to make X and Y length }
  104. {      Image - Sprite data                }
  105. {      Page - Segment Pointer to gfx page }
  106. {* No Clipping is performed  *}
  107.  
  108.  
  109. Var
  110.   PicX, PicY : Integer;
  111.   Offset, Segment : Word;
  112.   XPos, YPos : Word;
  113.   XStart : Word;
  114.   XStep, YStep : Integer;
  115.   YCount, XCount : Integer;
  116.   O1, O2 : Integer;
  117.  
  118. Begin
  119.   Offset := Ofs(Image);
  120.   Segment := Seg(Image);
  121.   PicX := MemW[Segment:Offset];
  122.   PicY := MemW[Segment:Offset+2];
  123.   Offset := Offset + 4;
  124.   XStep := (PicX Shl 8) Div (Size);
  125.   YStep := (PicY Shl 8) Div (Size);
  126.   YPos := 0;
  127.   XPos := 0;
  128.   O1 := Y * 320 + x;
  129.   For YCount := Y to (Y + Size - 1) do
  130.     Begin
  131.       O2 := (YPos Shr 8) * PicX + Offset;
  132.       Asm
  133.         Push  ds
  134.         Mov   es,Page
  135.         Mov   di,O1
  136.         Mov   ds,Segment
  137.         Mov   si,O2
  138.         Mov   dx,XPos
  139.         Mov   bl,dh
  140.         Xor   bh,bh
  141.         Mov   cx,Size
  142.         Push  bp
  143.         Mov   bp,XStep
  144.  
  145.        @Looper:
  146.         Mov  al,ds:[si+bx]
  147.         Mov  es:[di],al
  148.         Add  dx,bp
  149.         Mov  bl,dh
  150.         Inc  di
  151.         Dec  cx
  152.         Jnz  @Looper
  153.  
  154.         Pop  bp
  155.         Mov  O1,di
  156.         Pop  ds
  157.       End;
  158.       O1 := O1 + (320 - Size);
  159.       YPos := YPos + YStep;
  160.       XPos := 0;
  161.     End;
  162. End;
  163.  
  164. Procedure DeCompPCX(Var PCX; Dest, BottomLine : Word); Assembler;
  165. { Decompresses a PCX picture _fast_                           }
  166. { Can keep the PCX picture compressed in memory.              }
  167. { treates color 0 as transparent.                             }
  168.  
  169. { in : PCX - Pointer to PCX file in memory                    }
  170. {      Dest - Segment pointer to memory location to put image }
  171. {      BottomLine - Offset to end decompression (YLine*320)   }
  172.  
  173. Asm
  174.   Push ds
  175.   Lds  si,PCX     { Make ds:si point to PCX picture }
  176.   Mov  es,Dest    { Make es:di point to screen }
  177.   Mov  di,0
  178.   Add  si,128
  179.   Xor  cx,cx
  180.   Xor  ah,ah
  181.  @OuterLoop:
  182.   Mov  al,ds:[si]
  183.   Mov  cl,al
  184.   Mov  bl,al
  185.   Inc  si
  186.   And  bl,11000000b
  187.   Cmp  bl,11000000b
  188.   Jnz @RunLen1
  189.   And  cl,00111111b   {  cl = Runlength }
  190.   Mov  al,ds:[si]     {  al = color     }
  191.   Inc  si
  192.   Jmp @DoitLoop
  193.  @RunLen1:
  194.   Mov  cl,1
  195.  @DoItLoop:
  196.   Cmp  al,0
  197.   Je  @Skip0Color
  198.  @InnerLoop:
  199.   Mov  es:[di],al
  200.   Inc  di
  201.   Dec  cl
  202.   Jz  @GotoNext
  203.   Cmp  di,BottomLine
  204.   Jnz  @InnerLoop
  205.   Jmp @AllDone
  206.  @Skip0Color:
  207.   Add  di,cx    { Increment screen offset by length of 0 color run }
  208.  @GotoNext:
  209.   Cmp  di,BottomLine
  210.   Jnz  @OuterLoop
  211.  @AllDone:
  212.   Pop  ds
  213. End;
  214.  
  215. Function CheckHit : Boolean;
  216.  
  217. Var
  218.   Temp : Byte;
  219.  
  220. Begin
  221.   Temp := Mem[Page0:32160];
  222.   CheckHit := ((Temp >= 65) and (Temp <= 77));
  223. End;
  224.  
  225. Procedure ShowCross(p : Word);
  226.  
  227. Var
  228.   X : Integer;
  229.  
  230. Begin
  231.   For x := -8 to -1 do
  232.     Begin
  233.       Mem[P:(100+x)*320+160] := 15;
  234.       Mem[P:32000+(160+x)] := 15;
  235.     End;
  236.   For x := 1 to 8 do
  237.     Begin
  238.       Mem[P:(100+x)*320+160] := 15;
  239.       Mem[P:32000+(160+x)] := 15;
  240.     End;
  241. End;
  242.  
  243. Begin
  244.   Frames := 0;
  245. End.