home *** CD-ROM | disk | FTP | other *** search
/ PC Interdit / pc-interdit.iso / memory / flat / gifunit.pas < prev    next >
Pascal/Delphi Source File  |  1994-10-31  |  8KB  |  517 lines

  1. unit gifunit;
  2.  
  3. interface uses dos;
  4.  
  5. const clr=256;              {gif}
  6.             eof=257;
  7.       pakt : byte = 0;
  8. Const Maxsprites=14;
  9.             o_dtx=4; o_dty=6;
  10.       sampr : integer = 22;
  11.  
  12. var palette:Array[0..767] of Byte;
  13. Var Handle:Word;
  14.         Puf:Array[0..767] of Byte;
  15.     PufInd:Word;
  16.     Stack:Array[0..1280] of byte;
  17.     ab_prfx,ab_tail:Array[0..4096] of word;
  18.     Byt:Byte;
  19.     free,Largeur,max,
  20.         stackp,restbits,restbyte,sonderfall,
  21.     code,old_code,readbyt,bits,bits2get:Word;
  22.     lbyte:Word;
  23.     mask:Word;
  24.     zseg,zofs,
  25.     GifName:String[15];
  26.     VScreen:Pointer;
  27.  
  28. Procedure LoadGif(name:String;var Ciblevar:Pointer;startadr:word;seek:Longint);
  29. Procedure SetPal;
  30. procedure Blackpal;
  31. Procedure p13_2_modex(start,pic_size:word);
  32. Procedure Split(row:byte);
  33. Procedure Start(Ofst:Word);
  34. Procedure Init_ModeX;
  35. Procedure Init_Mode13;
  36. Procedure WaitRetrace;
  37.  
  38. implementation
  39.  
  40. Procedure SetPal;assembler;
  41. asm
  42.   mov si,offset palette
  43.   mov cx,256*3
  44.   xor al,al
  45.   mov dx,03c8h
  46.   out dx,al
  47.   inc dx
  48. @lp:
  49.   rep outsb
  50. End;
  51.  
  52. procedure Blackpal;
  53. begin;
  54.   fillchar(palette,768,0);
  55.   setpal;
  56. end;
  57.  
  58. Procedure GifOpen;assembler;
  59. asm
  60.     mov ax,03d00h
  61.   lea dx,gifname + 1
  62.   int 21h
  63.   mov handle,ax
  64. End;
  65. Procedure GifRead(n:Word);assembler;
  66. asm
  67.     mov ax,03f00h
  68.   mov bx,handle
  69.   mov cx,n
  70.   lea dx,puf
  71.     int 21h
  72. end;
  73. Procedure GifSeekdelta(delta:Longint);assembler;
  74. asm
  75.     mov ax,04200h
  76.   mov bx,handle
  77.   mov cx,word ptr delta + 2
  78.   mov dx,word ptr delta
  79.   int 21h
  80. End;
  81. Procedure GifClose;Assembler;
  82. asm
  83.     mov ax,03e00h
  84.   mov bx,handle
  85.   int 21h
  86. End;
  87. Procedure ShiftPal;assembler;
  88. asm
  89.     push ds
  90.   pop es
  91.   mov si,offset Puf
  92.   mov di,offset Palette
  93.   mov cx,768
  94. @l1:
  95.     lodsb
  96.   shr al,2
  97.   stosb
  98.   loop @l1
  99. End;
  100. Procedure FillPuf;
  101. Begin
  102.     GifRead(1);
  103.   restbyte:=puf[0];
  104.   GifRead(restbyte);
  105. End;
  106.  
  107. Function GetPhysByte:Byte;assembler;
  108. asm
  109.     push bx
  110.     cmp restbyte,0
  111.   ja @restda
  112.   pusha
  113.   call fillpuf
  114.   popa
  115.     mov pufind,0
  116. @restda:
  117.   mov bx,PufInd
  118.   mov al,byte ptr Puf[bx]
  119.   inc pufind
  120.   pop bx
  121. End;
  122.  
  123. Function GetLogByte:Word;assembler;
  124. asm
  125.   push si
  126.     mov ax,Largeur
  127.     mov si,ax
  128.   mov dx,restbits
  129.   mov cx,8
  130.   sub cx,dx
  131.   mov ax,lByte
  132.   shr ax,cl
  133.   mov code,ax
  134.   sub si,dx
  135. @nextbyte:
  136.   call getphysbyte
  137.   xor ah,ah
  138.   mov lByte,ax
  139.   dec restbyte
  140.  
  141.   mov bx,1
  142.   mov cx,si
  143.   shl bx,cl
  144.   dec bx
  145.   and ax,bx
  146.  
  147.   mov cx,dx
  148.   shl ax,cl
  149.   add code,ax
  150.  
  151.   sbb dx,Largeur
  152.   add dx,8
  153.   jns @Positif
  154.   add dx,8
  155. @Positif:
  156.   sub si,8
  157.   jle @Fini       { <= 0 }
  158.     add dx,Largeur
  159.   sub dx,8
  160.   jmp @nextbyte
  161. @Fini:
  162.     mov restbits,dx
  163.   mov ax,code
  164.     pop si
  165. End;
  166.  
  167. Procedure p13_2_modex(start,pic_size:word);assembler;
  168. Var   Plane_l:Byte;
  169.             Plane_Pos:Word;
  170. asm
  171.         mov plane_l,1
  172.     mov plane_pos,0
  173.     push ds
  174.     lds si,vscreen
  175.     mov plane_pos,si
  176.     mov ax,0a000h
  177.     mov es,ax
  178.     mov di,start
  179.     mov cx,pic_size
  180. @lpplane:
  181.     mov al,02h
  182.     mov ah,plane_l
  183.     mov dx,3c4h
  184.     out dx,ax
  185.  
  186.     @lp1:
  187.     movsb
  188.     add si,3
  189.     loop @lp1
  190. {        dec cx
  191.     jne @lp1}
  192.  
  193.  
  194.         mov di,start
  195.     inc plane_pos
  196.     mov si,plane_pos
  197.     mov cx,pic_size
  198.     shl plane_l,1
  199.     cmp plane_l,10h
  200.     jne @lpplane
  201.  
  202.     pop ds
  203. End;
  204.  
  205. Procedure LoadGif(name:String;var Ciblevar:Pointer;startadr:word;seek:Longint);
  206. Var Cible,
  207.     quelle,qseg:Word;
  208. {        pic_size,pic_height,pic_width:word;}
  209.          x_count:Word;
  210.     Ciblevarlok:Pointer;
  211. Begin
  212.   gifName:=Name+#0;
  213.      if Ciblevar = Nil Then
  214.         getMem(Ciblevar,64000);
  215.     GifOpen;
  216.     gifseekdelta(seek+13);
  217.     gifread(768);
  218.   Shiftpal;
  219.     gifread(1);
  220.   While Puf[0] = $21 do Begin
  221.     gifread(2);
  222.     gifread(puf[1]+1);
  223.   End;
  224.   GifRead(10);
  225. {  pic_width:=puf[4]+puf[5]*256;
  226.   pic_height:=puf[6]+puf[7]*256;
  227.   pic_size:=pic_width div 4 * pic_height;}
  228.   If Puf[8] and 128 = 128 Then Begin
  229.     gifread(768);
  230.       Shiftpal;
  231.   End;
  232.   lByte:=0;
  233.   Ciblevarlok:=Ciblevar;
  234.     asm
  235.     les di,Ciblevarlok
  236.  
  237.     mov free,258
  238.     mov Largeur,9
  239.     mov max,511
  240.     mov stackp,0
  241.     mov restbits,0
  242.     mov restbyte,0
  243.   @mainloop:
  244.     call getlogByte
  245.         cmp ax,eof
  246.     je @abbruch
  247.     cmp ax,clr
  248.     je @clear
  249.       mov readbyt,ax
  250.     cmp ax,free
  251.     jb @code_in_ab
  252.     mov ax,old_code
  253.     mov code,ax
  254.     mov bx,stackp
  255.     mov cx,sonderfall
  256.     mov word ptr stack[bx],cx
  257.     inc stackp
  258.   @code_in_ab:
  259.       cmp ax,clr
  260.       jb @konkret
  261.   @fillstack_loop:
  262.     mov bx,code
  263.     shl bx,1
  264.     push bx
  265.     mov ax,word ptr ab_tail[bx]
  266.     mov bx,stackp
  267.     shl bx,1
  268.     mov word ptr stack[bx],ax
  269.     inc stackp
  270.     pop bx
  271.     mov ax,word ptr ab_prfx[bx]
  272.     mov code,ax
  273.     cmp ax,clr
  274.     ja @fillstack_loop
  275.   @konkret:
  276.       mov bx,stackp
  277.     shl bx,1
  278.     mov word ptr stack[bx],ax
  279.     mov sonderfall,ax
  280.     inc stackp
  281.     mov bx,stackp
  282.     dec bx
  283.     shl bx,1
  284.   @readstack_loop:
  285.       mov ax,word ptr stack[bx]
  286.  
  287.         stosb
  288.       or di,di
  289.     jne @noovl1
  290.     push startadr
  291.     push 16384
  292.     add startadr,16384
  293.     call p13_2_modex
  294.     les di,Ciblevarlok
  295.  
  296. @noovl1:
  297. {    add si,4
  298.     and si,12
  299.     or di,di
  300.     jne @rsnc
  301.     mov ax,es
  302.     add ax,1000h
  303.     mov es,ax
  304.     @rsnc:}
  305.         dec bx
  306.     dec bx
  307.     jns @readstack_loop
  308.     mov stackp,0
  309.     mov bx,free
  310.     shl bx,1
  311.     mov ax,old_code
  312.     mov word ptr ab_prfx[bx],ax
  313.     mov ax,code
  314.     mov word ptr ab_tail[bx],ax
  315.     mov ax,readbyt
  316.     mov old_code,ax
  317.     inc free
  318.     mov ax,free
  319.     cmp ax,max
  320.     jbe @mainloop
  321.     cmp byte ptr Largeur,12
  322.     jae @mainloop
  323.     inc Largeur
  324.     mov cl,byte ptr Largeur
  325.     mov ax,1
  326.     shl ax,cl
  327.     dec ax
  328.     mov max,ax
  329.     jmp @mainloop
  330.   @clear:
  331.     mov Largeur,9
  332.     mov max,511
  333.     mov free,258
  334.     call getlogbyte
  335.     mov sonderfall,ax
  336.     mov old_code,ax
  337.  
  338.         stosb
  339.       or di,di
  340.     jne @noovl2
  341.     push startadr
  342.     push 16384
  343.     add startadr,16384
  344.     call p13_2_modex
  345.     les di,Ciblevarlok
  346.  
  347. @noovl2:
  348. {    add si,4
  349.     and si,12
  350.  
  351.     or di,di
  352.     jne @mainloop
  353.     mov ax,es
  354.     add ax,1000h
  355.     mov es,ax    }
  356.  
  357.     jmp @mainloop
  358.   @abbruch:
  359.   End;
  360.   gifclose;
  361. End;
  362.  
  363. procedure disable4; assembler;
  364. asm;
  365.     mov dx,3c4h
  366.   mov ax,0f02h
  367.   out dx,ax
  368.  
  369.   mov dx,3ceh
  370.   mov ax,4005h
  371.   out dx,ax
  372. end;
  373.  
  374. Procedure ShowPic;assembler;
  375. asm
  376.     push ds
  377.     mov di,0a000h
  378.   mov es,di
  379.   xor di,di
  380.   mov si,word ptr VScreen
  381.   mov ax,word ptr Vscreen + 2
  382.   mov ds,ax
  383.   mov cx,32000
  384.   rep movsw
  385.   pop ds
  386. End;
  387. Procedure ClearPic(Size:Word);assembler;
  388. asm
  389.     mov ax,word ptr vscreen + 2
  390.   mov es,ax
  391.   mov di,word ptr vscreen
  392.   mov cx,Size
  393.   xor ax,ax
  394.   rep stosw
  395. End;
  396.  
  397. Procedure WaitRetrace;assembler;
  398. asm
  399.     mov dx,3dah
  400. @wait1:
  401.     in al,dx
  402.   test al,8h
  403.     jz @wait1
  404. @wait2:
  405.     in al,dx
  406.   test al,8h
  407.   jnz @wait2
  408. End;
  409.  
  410. Procedure Init_Mode13;assembler;
  411.     asm
  412.       mov ax,13h
  413.     int 10h
  414.   End;
  415.  
  416. Procedure Init_ModeX;assembler;
  417. asm
  418.     mov ax,0013h
  419.   int 10h
  420.  
  421.   mov dx,3c4h
  422.   mov al,4
  423.   out dx,al
  424.   inc dx
  425.   in al,dx
  426.   and al,0f7h
  427.   or al,4h
  428.   out dx,al
  429.   dec dx
  430.   mov ax,0f02h
  431.   out dx,ax
  432.  
  433.     mov ax,0a000h
  434.   mov es,ax
  435.   xor di,di
  436.   xor ax,ax
  437.   mov cx,8000h
  438.   cld
  439.   rep stosw
  440.  
  441.   mov dx,3d4h
  442.   mov al,14h
  443.   out dx,al
  444.   inc dx
  445.   in al,dx
  446.   and al,0bfh
  447.   out dx,al
  448.   dec dx
  449.   mov al,17h
  450.   out dx,al
  451.   inc dx
  452.   in al,dx
  453.   or al,40h
  454.   out dx,al
  455. End;
  456.  
  457. Procedure Start(Ofst:Word);assembler;
  458. asm
  459.     mov dx,3d4h
  460.   mov al,0ch
  461.   mov ah,byte ptr ofst + 1
  462.   out dx,ax
  463.   inc al
  464.   mov ah,byte ptr ofst
  465.   out dx,ax
  466. End;
  467.  
  468. Procedure Split(row:byte);assembler;
  469. asm
  470.     mov bl,row
  471.   xor bh,bh
  472.     shl bx,1
  473.   mov cx,bx
  474.  
  475.     mov dx,3d4h
  476.   mov al,07h
  477.   out dx,al
  478.   inc dx
  479.   in al,dx
  480.     and al,11101111b
  481.   shr cx,4
  482.   and cl,16
  483.   or al,cl
  484.   out dx,al
  485.  
  486.   dec dx
  487.   mov al,09h
  488.   out dx,al
  489.   inc dx
  490.   in al,dx
  491.   and al,10111111b
  492.   shr bl,3
  493.   and bl,64
  494.   or al,bl
  495.   out dx,al
  496.  
  497.   dec dx
  498.   mov al,18h
  499.   mov ah,row
  500.   shl ah,1
  501.   out dx,ax
  502. End;
  503.  
  504. Procedure enable4;assembler;
  505. asm
  506.     mov dx,3c4h
  507.   mov ax,0f02h
  508.   out dx,ax
  509.  
  510.   mov dx,3ceh
  511.   mov ax,4105h
  512.   out dx,ax
  513. End;
  514.  
  515.  
  516. begin;
  517. end.