Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. lang equ ru
  2.  
  3. ;
  4. ;   Assembler
  5. ;     SMALL
  6. ;       CODE
  7. ;         Graphics
  8. ;           Libary
  9. ;
  10. ;   Ver 0.18 By Pavlushin Evgeni (RUSSIA)
  11. ;   www.waptap@mail.ru
  12.  
  13. ;InfoList
  14. ;0.01 LoadImage
  15. ;0.02 SetBmp
  16. ;0.03 Bmptoimg, Setimg ~01.03.2004
  17. ;0.04 Bug deleted, copyimg ~03.05.2004
  18. ;0.05 fullimg, collimg ~05.05.2004
  19. ;0.06 getimg ~09.05.2004
  20. ;0.07 convbmp ~13.05.2004
  21. ;0.08 fps ~14.05.2004
  22. ;0.09 drawfbox ~03.06.2004
  23. ;0.10 all macros optimized by halyavin, add at ~07.06.2004
  24. ;0.11 many macros optimized by halyavin, add at ~30.08.2004
  25. ;0.12 bmptoimg ~07.09.2004
  26. ;0.13 imgtoimg ~08.09.2004
  27. ;0.14 imgtoimg modify not brake bmp pict! ~09.09.2004
  28. ;0.15 giftoimg, giftoani ~10.09.2004
  29. ;0.16 setframe, rgbtobgr, setbmp deleted ~20.09.2004
  30. ;0.17 modification giftoimg, giftoani, getframeoff ~01.10.2004
  31. ;0.18 aframetoimg,aimgtoimg,frametoimg ~03.10.2004
  32.  
  33. aframetoimg_use_count=0
  34. macro aframetoimg img, x, y, canvas,acol
  35. {
  36. local loo,loo2,acolor
  37. aframetoimg_use_count=aframetoimg_use_count+1
  38. if aframetoimg_use_count = 1
  39.  
  40.      jmp end_aframetoimg_proc
  41.  
  42. acolor dd 0
  43. aframetoimg_proc:
  44. ;getout coord
  45.     mov [acolor],ebp
  46.  
  47.     mov edx,ebx ;img   ;xsize
  48.     movzx eax,word [edx]
  49.     add eax,esi ;y cor
  50.  
  51. ;    mov eax,esi ;y cor
  52.     mul dword [ecx] ;canvas xsize
  53.     add eax,edi ;x cor
  54.  
  55.     mov ebp,ebx ;img   ;xsize
  56.     movzx edx,word [ebp]
  57.     add eax,edx
  58.  
  59.     mov ebp,eax
  60.     shl eax,1
  61.     add ebp,eax
  62.     add ebp,ecx ;canvas+8;start
  63.     add ebp,8
  64. ;get img size
  65.     add ebx,4
  66.     mov eax,ebx ;img   ;xsize
  67.     movzx esi,word [eax]
  68.     movzx edi,word [eax+2]
  69.     add ebx,4
  70.     mov edx,ebx ;img+8
  71. loo2:
  72. push esi
  73. loo:
  74. ;test on alpha color
  75.     mov eax,[edx]
  76.     shl eax,8
  77.     shr eax,8
  78.     cmp eax,[acolor]
  79.     jne  yx
  80.     add edx,3
  81.     add ebp,3
  82.     jmp nx
  83. yx:
  84.  
  85.     mov al,byte [edx]
  86.     mov byte [ebp],al
  87.     inc ebp
  88.     inc edx
  89.     mov al,byte [edx]
  90.     mov byte [ebp],al
  91.     inc ebp
  92.     inc edx
  93.     mov al,byte [edx]
  94.     mov byte [ebp],al
  95.     inc ebp
  96.     inc edx
  97. nx:
  98.     dec esi
  99.     jnz loo
  100. pop esi
  101.     sub ebp,3
  102.     mov eax,[ecx]  ;offset = offset+((canxsize-imgxsize)*3)
  103.     sub eax,esi
  104.     add ebp,eax
  105.     shl eax,1
  106.     add ebp,eax
  107.  
  108.     add ebp,3
  109.  
  110.     dec edi
  111.     jnz loo2
  112.     ret
  113. end_aframetoimg_proc:
  114. end if
  115.     push img
  116.     push canvas
  117.     push x
  118.     push y
  119.     push acol
  120.     pop  ebp
  121.     pop  esi
  122.     pop  edi
  123.     pop ecx
  124.     pop ebx
  125.     call aframetoimg_proc
  126. }
  127.  
  128. frametoimg_use_count=0
  129. macro frametoimg img, x, y, canvas
  130. {
  131. local loo,loo2
  132. frametoimg_use_count=frametoimg_use_count+1
  133. if frametoimg_use_count = 1
  134.  
  135.     jmp end_frametoimg_proc
  136.  
  137. frametoimg_proc:
  138. ;getout coord
  139.     mov edx,ebx ;img   ;xsize
  140.     movzx eax,word [edx]
  141.     add eax,esi ;y cor
  142.  
  143. ;    mov eax,esi ;y cor
  144.     mul dword [ecx] ;canvas xsize
  145.     add eax,edi ;x cor
  146.  
  147.     mov ebp,ebx ;img   ;xsize
  148.     movzx edx,word [ebp]
  149.     add eax,edx
  150.  
  151.     mov ebp,eax
  152.     shl eax,1
  153.     add ebp,eax
  154.     add ebp,ecx ;canvas+8;start
  155.     add ebp,8
  156. ;get img size
  157.     add ebx,4
  158.     mov eax,ebx ;img   ;xsize
  159.     movzx esi,word [eax]
  160.     movzx edi,word [eax+2]
  161.     add ebx,4
  162.     mov edx,ebx ;img+8
  163. loo2:
  164. push esi
  165. loo:
  166.     mov al,byte [edx]
  167.     mov byte [ebp],al
  168.     inc ebp
  169.     inc edx
  170.     mov al,byte [edx]
  171.     mov byte [ebp],al
  172.     inc ebp
  173.     inc edx
  174.     mov al,byte [edx]
  175.     mov byte [ebp],al
  176.     inc ebp
  177.     inc edx
  178.  
  179.     dec esi
  180.     jnz loo
  181. pop esi
  182.     sub ebp,3
  183.     mov eax,[ecx]  ;offset = offset+((canxsize-imgxsize)*3)
  184.     sub eax,esi
  185.     add ebp,eax
  186.     shl eax,1
  187.     add ebp,eax
  188.  
  189.     add ebp,3
  190.  
  191.     dec edi
  192.     jnz loo2
  193.     ret
  194. end_frametoimg_proc:
  195. end if
  196.     push img
  197.     push canvas
  198.     push x
  199.     push y
  200.     pop  esi
  201.     pop  edi
  202.     pop ecx
  203.     pop ebx
  204.     call frametoimg_proc
  205. }
  206.  
  207.  
  208. aimgtoimg_use_count=0
  209. macro aimgtoimg img, x, y, canvas,acol
  210. {
  211. local loo,loo2,acolor
  212. aimgtoimg_use_count=aimgtoimg_use_count+1
  213. if aimgtoimg_use_count = 1
  214.  
  215.      jmp end_aimgtoimg_proc
  216.  
  217. acolor dd 0
  218. aimgtoimg_proc:
  219. ;getout coord
  220.     mov [acolor],ebp
  221.  
  222.     mov eax,esi ;y cor
  223.     mul dword [ecx] ;canvas xsize
  224.     add eax,edi ;x cor
  225.     mov ebp,eax
  226.     shl eax,1
  227.     add ebp,eax
  228.     add ebp,ecx ;canvas+8;start
  229.     add ebp,8
  230. ;get img size
  231.     mov eax,ebx ;img   ;xsize
  232.     mov esi,[eax]
  233.     add ebx,4
  234.     mov eax,ebx ; img+4 ;ysize
  235.     mov edi,[eax]
  236.     add ebx,4
  237.     mov edx,ebx ;img+8
  238. loo2:
  239. push esi
  240. loo:
  241.  
  242. ;test on alpha color
  243.     mov eax,[edx]
  244.     shl eax,8
  245.     shr eax,8
  246.     cmp eax,[acolor]
  247.     jne  yx
  248.     add edx,3
  249.     add ebp,3
  250.     jmp nx
  251. yx:
  252.  
  253.     mov al,byte [edx]
  254.     mov byte [ebp],al
  255.     inc ebp
  256.     inc edx
  257.     mov al,byte [edx]
  258.     mov byte [ebp],al
  259.     inc ebp
  260.     inc edx
  261.     mov al,byte [edx]
  262.     mov byte [ebp],al
  263.     inc ebp
  264.     inc edx
  265. nx:
  266.     dec esi
  267.     jnz loo
  268. pop esi
  269.     sub ebp,3
  270.     mov eax,[ecx]  ;offset = offset+((canxsize-imgxsize)*3)
  271.     sub eax,esi
  272.     add ebp,eax
  273.     shl eax,1
  274.     add ebp,eax
  275.  
  276.     add ebp,3
  277.  
  278.     dec edi
  279.     jnz loo2
  280.     ret
  281. end_aimgtoimg_proc:
  282. end if
  283.     push img
  284.     push canvas
  285.     push x
  286.     push y
  287.     push acol
  288.     pop  ebp
  289.     pop  esi
  290.     pop  edi
  291.     pop ecx
  292.     pop ebx
  293.     call aimgtoimg_proc
  294. }
  295.  
  296.  
  297.  
  298.  
  299. imgtoimg_use_count=0
  300. macro imgtoimg img, x, y, canvas
  301. {
  302. local loo,loo2
  303. imgtoimg_use_count=imgtoimg_use_count+1
  304. if imgtoimg_use_count = 1
  305.  
  306.      jmp end_imgtoimg_proc
  307. imgtoimg_proc:
  308. ;getout coord
  309.     mov eax,esi ;y cor
  310.     mul dword [ecx] ;canvas xsize
  311.     add eax,edi ;x cor
  312.     mov ebp,eax
  313.     shl eax,1
  314.     add ebp,eax
  315.     add ebp,ecx ;canvas+8;start
  316.     add ebp,8
  317. ;get img size
  318.     mov eax,ebx ;img   ;xsize
  319.     mov esi,[eax]
  320.     add ebx,4
  321.     mov eax,ebx ; img+4 ;ysize
  322.     mov edi,[eax]
  323.     add ebx,4
  324.     mov edx,ebx ;img+8
  325. loo2:
  326. push esi
  327. loo:
  328.     mov al,byte [edx]
  329.     mov byte [ebp],al
  330.     inc ebp
  331.     inc edx
  332.     mov al,byte [edx]
  333.     mov byte [ebp],al
  334.     inc ebp
  335.     inc edx
  336.     mov al,byte [edx]
  337.     mov byte [ebp],al
  338.     inc ebp
  339.     inc edx
  340.     dec esi
  341.     jnz loo
  342. pop esi
  343.     sub ebp,3
  344.     mov eax,[ecx]  ;offset = offset+((canxsize-imgxsize)*3)
  345.     sub eax,esi
  346.     add ebp,eax
  347.     shl eax,1
  348.     add ebp,eax
  349.  
  350.     add ebp,3
  351.  
  352.     dec edi
  353.     jnz loo2
  354.     ret
  355. end_imgtoimg_proc:
  356. end if
  357.     push img
  358.     push canvas
  359.     push x
  360.     push y
  361.     pop  esi
  362.     pop  edi
  363.     pop  ecx
  364.     pop  ebx
  365.     call imgtoimg_proc
  366. }
  367.  
  368.  
  369. ;DrawBox
  370. macro drawfbox x,y,xs,ys,color
  371. {
  372.     wordstoreg ebx,x,xs ;x*65536+xs
  373.     wordstoreg ecx,y,ys ;y*65536+ys
  374.     mov  edx,color
  375.     mov  eax,13
  376.     int  0x40
  377. }
  378.  
  379. ; FPS - Set Frame Per Second Display
  380. fps_show_frequency=40
  381. macro fps x,y,color,delcolor
  382. {
  383. local spdat,savetime,new_time,fps,fps_cntr,out_fps,new_time,ttt
  384. local no_out_fps
  385.     jmp spdat
  386. savetime dd 0
  387. fps_cntr dd 0
  388. fps      dd 0
  389. ttt      dd 0
  390. spdat:
  391. get_time:
  392.     mov eax,3
  393.     int 0x40
  394.     cmp eax,[savetime]
  395.     jne new_time
  396.     inc [fps_cntr]
  397.     cmp dword [ttt],0
  398.     je  out_fps
  399.     dec dword [ttt]
  400.     jmp no_out_fps
  401. new_time:
  402.     mov [savetime],eax
  403.     mov ebx,[fps_cntr]
  404.     mov [fps],ebx
  405.     mov [fps_cntr],0
  406. out_fps:
  407. if ~(delcolor eq )
  408.     mov ebx,x*65536+30
  409.     mov ecx,y*65536+7
  410.     mov edx,delcolor
  411.     mov eax,13
  412.     int 0x40
  413. end if
  414.     mov dword [ttt],fps_show_frequency
  415.     mov eax,47
  416.     mov ebx,5*65536
  417. ;   mov bl,0
  418.     mov edx,x*65536+y
  419.     mov esi,color
  420.     mov ecx,[fps]
  421.     int 0x40
  422. no_out_fps:
  423. }
  424.  
  425. ; COLLIMG - Collusion image's
  426. _1dbounce_count=0;
  427. macro collimg img1_off,x1,y1,img2_off,x2,y2,otv
  428. {
  429. local bounce,exit,anot,bc,nbc
  430.         mov esi,[img1_off] ;xs1
  431.         mov edi,[img2_off] ;ys2
  432.         mov eax,x1 ;
  433.         mov ebx,x2 ;
  434.         call _1dbounce
  435.         mov edx,ecx
  436.         mov esi,[img1_off+4] ;ys1
  437.         mov edi,[img2_off+4] ;ys2
  438.         mov eax,y1 ;
  439.         mov ebx,y2 ;
  440.         call _1dbounce
  441.         add edx,ecx
  442.         cmp edx,2
  443.         je bounce
  444.         mov otv,0
  445.         jmp exit
  446. _1dbounce_count=_1dbounce_count+1
  447. if _1dbounce_count = 1
  448. _1dbounce:
  449.         cmp ebx,eax
  450.         jb  anot
  451.         add eax,esi
  452.         cmp eax,ebx
  453.         jbe nbc
  454. bc:
  455.         mov ecx,1
  456.         ret
  457. anot:
  458.     add ebx,edi
  459.         cmp ebx,eax
  460.         ja  bc
  461. nbc:
  462.         xor ecx,ecx
  463.         ret
  464. end if
  465. bounce:
  466.         mov otv,1
  467. exit:  
  468. }
  469.  
  470. macro rgbtobgr image
  471. {
  472. local loo
  473.     mov eax,[image]
  474.     mul dword [image+4]
  475.     mov ecx,eax
  476.     mov esi,image+8
  477. ;   add esi,8
  478. loo:
  479.    mov al,[esi]
  480.    mov bl,[esi+2]
  481.    mov [esi],bl
  482.    mov [esi+2],al
  483.    add esi,3
  484.    dec ecx
  485.    jnz loo
  486. }
  487.  
  488.  
  489. macro setimg x , y ,arg3
  490. {
  491.     mov  eax,7
  492.     mov  ebx,arg3
  493.     add  ebx,8
  494.     mov  cx,[arg3]
  495.     shl  ecx,16
  496.     add  cx,[arg3+4]
  497. ;    wordstoreg ecx,[arg3],[arg3+4]
  498.     wordstoreg edx, x , y  ;arg1*65536+arg2
  499.     int  0x40
  500. }
  501.  
  502. macro setframe x , y ,arg3
  503. {
  504.     mov  eax,7
  505.     mov  ebx,arg3
  506.     add  ebx,8
  507.     wordstoreg edx, x , y  ;arg1*65536+arg2
  508.     add  edx,dword [arg3]
  509.     mov  ecx,dword [arg3+4]
  510.     int  0x40
  511. }
  512.  
  513.  
  514. macro getimg imgsrc,x,y,xs,ys,imgdest
  515. {
  516. local cyc
  517. if xs eqtype 0
  518.     mov dword [imgdest],xs
  519. else
  520.     mov eax,xs
  521.     mov dword [imgdest],eax
  522. end if
  523. if ys eqtype 0
  524.     mov dword [imgdest+4],ys
  525. else
  526.     mov eax,ys
  527.     mov dword [imgdest+4],eax
  528. end if
  529.  
  530.     mov eax,dword [imgsrc] ;getx size
  531. ;    lea ecx,[eax+2*eax]
  532.     mov ecx,eax
  533.     shl ecx,1
  534.     add ecx,eax
  535.  
  536.     mov ebx,y
  537.     mul ebx
  538.     add eax,x
  539.     mov edx,ecx
  540.     lea eax,[eax+2*eax]  ;eax=offset on imsrc
  541. ;    mov ebp,eax
  542. ;    shl eax,1
  543. ;    add eax,ebp
  544.  
  545.     mov ecx,xs
  546.     mov ebx,ys
  547.  
  548.     mov edi,8+imgdest
  549.     lea esi,[eax+8+imgsrc]
  550. ;    mov esi,eax
  551. ;    add esi,8
  552. ;    add esi,imgsrc
  553.  
  554.     cld
  555. cyc:
  556.     movsw
  557.     movsb
  558.     dec ecx
  559.     jne cyc
  560.     add esi,edx
  561.     mov ecx,xs
  562.     sub esi,ecx
  563.     sub esi,ecx
  564.     sub esi,ecx
  565.     dec ebx
  566.     jne cyc
  567. }
  568.  
  569. macro copyimg img2_off,img1_off
  570. {
  571.     mov  eax,dword [img1_off]
  572.     mov  ebx,dword [img1_off+4]
  573.     mul  ebx
  574.     lea  ecx,[eax+2*eax]
  575.     lea  esi,[img1_off+8]
  576.     lea  edi,[img2_off+8]
  577.     cld
  578.     rep  movsb
  579. }
  580.  
  581. macro fullimg img_off,xs,ys,color
  582. {
  583. local cop
  584.     mov eax,xs
  585.     mov ebx,ys
  586.     mov  dword [img_off],eax
  587.     mov  dword [img_off+4],ebx
  588.     mul  ebx
  589.     lea  ebp,[eax+2*eax]
  590.     mov  esi,color
  591. if color eqtype 0
  592.     mov  ecx,color/65536
  593. else
  594.     mov  ecx,esi
  595.     shr  ecx,16
  596. end if
  597.     xor  edi,edi
  598. cop:
  599.     mov  word [img_off+8+edi],si
  600.     add  edi,2
  601.     mov  byte [img_off+8+edi],cl
  602.     inc  edi
  603.     cmp  edi,ebp
  604.     jne  cop
  605. }
  606.  
  607.  
  608.  
  609.   ; number of frame in ecx
  610.   ; callculatin offset of raw data
  611.  
  612. macro getframeoff num_of_frame,offset_of_animation,offset_of_frame
  613. {
  614. local loo,setpic
  615.   mov ebp,num_of_frame ;ecx
  616.   mov esi,offset_of_animation;Image
  617. loo:
  618.   cmp ebp,0
  619.   je  setpic
  620.   movzx eax,word [esi+4]
  621.   movzx ebx,word [esi+6]
  622.   mul ebx ;dword [esi+4]
  623.   mov ebx,3
  624.   mul ebx
  625.   add eax,8
  626.   add esi,eax
  627.   dec ebp
  628.   jmp loo
  629. setpic:
  630.   mov dword offset_of_frame,esi
  631. }
  632.  
  633.  
  634. ; BMPTOIMG -Convert BMP format TO IMG format
  635. ; (SYNTAX)  BMPTOIMG BMP_source_offset,IMG_dest_ofset
  636. ; (SAMPLE)  View BMPLS.ASM sample.
  637. ; ( NOTE )  This is macros is not brake bmp structure! Tested in 32,8,4 bits
  638.  
  639.  
  640. bmptoimg_data_area_count=0
  641. macro bmptoimg bmp_load_area,img_dest_area
  642. {
  643. local fileinfo,string,end_bmp,nodix
  644. local converttable,noaddelem,nextbit,convert1bpp,convert4bpp,convert2
  645. local nextelem,convertno32,nomorestring,convert1,nextstring,yespicsize
  646. ;local qwe,bmpfn
  647.  
  648. ;  convert:
  649.     movzx eax,word [bmp_load_area+28]
  650.     mul  dword [bmp_load_area+18]
  651.     add  eax,31
  652.     shr  eax,5
  653.     mov  dword [bmptoimg_data_area_dwps],eax  ;dwps-doublewords per string
  654.     shl  eax,2
  655.     mov  dword [bmptoimg_data_area_bps],eax   ;bps-bytes per string
  656.  
  657.     cmp dword [bmp_load_area+34],0
  658.     jne  yespicsize  ;if picture size is defined
  659.     mul dword [bmp_load_area+22]
  660.     mov dword [bmp_load_area+34],eax
  661.  
  662.   yespicsize:
  663.     mov ebp,img_dest_area+8
  664.  
  665.     mov  eax,bmp_load_area
  666.     mov  ebx,eax
  667.     add  ebx, [bmp_load_area+2];file size
  668.     inc  ebx
  669.     mov  dword [bmptoimg_soi],ebx   ;soi-start of image area for drawing
  670.  
  671.     add  eax, [bmp_load_area+10]
  672.     mov  dword [bmptoimg_data_area_sop],eax   ;sop-start of picture in file
  673.     add  eax, [bmp_load_area+34]
  674.     mov  dword [bmptoimg_data_area_eop],eax   ;eop-end of picture in file
  675.     mov  eax, [bmp_load_area+18]
  676.     lea  eax,[eax+2*eax]   ;3x pixels in eax
  677.  
  678.     mov  edi,dword [bmptoimg_soi]   ;initializing
  679.     mov  esi,dword [bmptoimg_data_area_eop]
  680.     sub  esi,dword [bmptoimg_data_area_bps]
  681.  
  682.  
  683.   nextstring:
  684.     push edi
  685.     push ebp
  686.     cmp  word [bmp_load_area+28],24
  687.     jne  convertno32
  688.  
  689.     mov edi,ebp
  690.     mov  ecx,[bmptoimg_data_area_dwps]
  691.     cld
  692.     rep movsd
  693.  
  694.   convert1:
  695.     pop  ebp
  696.     pop  edi
  697.     sub  esi,dword [bmptoimg_data_area_bps]
  698.     sub  esi,dword [bmptoimg_data_area_bps]
  699.     cmp  esi,dword [bmptoimg_data_area_sop]
  700.     jb   end_bmp
  701.     add  edi,eax
  702.     add  ebp,eax
  703.     jmp  nextstring
  704.  
  705.   convertno32:
  706.     mov  ebx,bmp_load_area
  707.     add  ebx, [bmp_load_area+14]
  708.     add  ebx,14          ;start of color table
  709.     push esi
  710.     add  esi,dword [bmptoimg_data_area_bps]
  711.     mov  dword [bmptoimg_data_area_eos],esi
  712.     pop  esi
  713.   nextelem:
  714.     push eax
  715.     movzx eax,byte [esi]
  716.     cmp  word [bmp_load_area+28],4
  717.     je   convert4bpp
  718.     cmp  word [bmp_load_area+28],1
  719.     je   convert1bpp
  720.     call converttable
  721.  
  722.   convert2:
  723.     pop  eax
  724.     inc  esi
  725.     cmp  esi,dword [bmptoimg_data_area_eos]
  726.     jae  convert1
  727.     add  edi,3
  728.  
  729.     add  ebp,3
  730.  
  731.     jmp  nextelem
  732.  
  733.   convert4bpp:
  734.     shl  ax,4
  735.     shr  al,4
  736.     push ax
  737.     movzx eax,ah
  738.     call converttable
  739.     add  edi,3
  740.  
  741.     add ebp,3
  742.  
  743.     pop  ax
  744.     movzx eax,al
  745.     call converttable
  746.     jmp  convert2
  747.  
  748.   convert1bpp:
  749.     mov  ecx,eax
  750.     mov  edx,7
  751.   nextbit:
  752.     xor  eax,eax
  753.     bt   ecx,edx
  754.     jnc  noaddelem
  755.     inc  eax
  756.   noaddelem:
  757.     push edx
  758.     call converttable
  759.     pop  edx
  760.     dec  edx
  761.     js   convert2
  762.     add  edi,3
  763.  
  764.     add  ebp,3
  765.  
  766.     jmp  nextbit
  767.  
  768.   converttable:
  769.     shl  eax,2
  770.     add  eax,ebx
  771.     mov  edx, dword [eax]
  772. ;    mov  dword [edi],edx
  773.     mov [ebp],edx
  774.     ret
  775.  
  776. bmptoimg_data_area_count=bmptoimg_data_area_count+1
  777. if bmptoimg_data_area_count = 1
  778. ; DATA AREA
  779. bmptoimg_soi                dd 0
  780. bmptoimg_data_area_bps      dd 0
  781. bmptoimg_data_area_dwps     dd 0
  782. bmptoimg_data_area_sop      dd 0
  783. bmptoimg_data_area_eop      dd 0
  784. bmptoimg_data_area_eos      dd 0
  785. end if
  786.  
  787. end_bmp:
  788.     mov  eax,dword [bmp_load_area+18]
  789.     mov  ebx,dword [bmp_load_area+22]
  790.     mov  dword [img_dest_area],eax
  791.     mov  dword [img_dest_area+4],ebx
  792. }
  793.  
  794. ; For convert RGB to BGR
  795. COLOR_ORDER equ MENUETOS
  796.  
  797. macro giftoani gifsrc,imgsrc,num_of_frames
  798. {
  799. local hasharea, ReadGIF, nextblock,_null
  800. local globalColor, img_count, cur_info, img_start
  801. local codesize, compsize, bit_count, CC, EOI, Palette
  802. local block_ofs, table_ptr, gifmacend
  803. local no_gc, block_skip, no_comm, noextblock, uselocal
  804. local setPal, filltable, reinit, cycle, zadd, noinc
  805. local notintable, er, zend, nxt, continue, ex, Gif_skipmap
  806. local Gif_get_sym, shift, nextbl, noblock, loop1, exx
  807. local Gif_output, next, loop2
  808.  
  809. _null fix 0x1000 ; 0x1000
  810.  
  811. ;    jmp sss
  812. ;    if defined gif_hash_offset
  813. ;    else
  814. ;    hasharea:
  815. ;    times 4096 dd 0 ;4096
  816. ;    end if
  817. ;sss:
  818.  
  819.     mov  esi,gifsrc           ;“ª § â¥«ì ­  ƒˆ” ä ¨« ¢ ¯ ¬ïâ¨
  820.     mov  edi,imgsrc           ;“ª § â¥«ì ­  ᯨ᮪ ª à⨭®ª
  821.  
  822.     if defined gif_hash_offset
  823.     mov  eax,gif_hash_offset    ; ¡®ç ï ®¡« áâì ¬¨­¨¬ã¬ 4096*4 ¡ ©â
  824.     else
  825.     mov  eax,hasharea         ; ¡®ç ï ®¡« áâì ¬¨­¨¬ã¬ 4096*4 ¡ ©â
  826.     end if
  827.  
  828.     call ReadGIF
  829.     push ecx
  830.     pop  dword num_of_frames
  831.     jmp  gifmacend
  832.  
  833.     if defined gif_hash_offset
  834.     else
  835.     hasharea:
  836.     times 4096 dd 0 ;4096
  837.     end if
  838.  
  839. ReadGIF:
  840.     push esi edi
  841.     mov  [table_ptr],eax
  842.     mov  [cur_info],edi
  843.     xor  eax,eax
  844.     mov  [globalColor],eax
  845.     mov  [img_count],eax
  846.     inc  eax
  847.     cmp  dword[esi],'GIF8'
  848.     jne  er            ; signature
  849.     mov  ecx,[esi+0xa]
  850.     inc  eax
  851.     add  esi,0xd
  852.     mov  edi,esi
  853.     bt   ecx,7
  854.     jnc  nextblock
  855.     mov  [globalColor],esi
  856.     call Gif_skipmap
  857. nextblock:
  858.     cmp  byte[edi],0x21
  859.     jne  noextblock
  860.     inc  edi
  861.     cmp  byte[edi],0xf9 ; Graphic Control Ext
  862.     jne  no_gc
  863.     add  edi,7
  864.     jmp  nextblock
  865. no_gc:
  866.     cmp  byte[edi],0xfe ; Comment Ext
  867.     jne  no_comm
  868.     inc  edi
  869. block_skip:
  870.     movzx eax,byte[edi]
  871.     lea  edi,[edi+eax+1]
  872.     cmp  byte[edi],0
  873.     jnz  block_skip
  874.     inc  edi
  875.     jmp  nextblock
  876. no_comm:
  877.     cmp  byte[edi],0xff ; Application Ext
  878.     jne  nextblock
  879.     add  edi,13
  880.     jmp  block_skip
  881. noextblock:
  882.     cmp  byte[edi],0x2c    ; image beginning
  883.     jne  er
  884.     inc  [img_count]
  885.     inc  edi
  886.     mov  esi,[cur_info]
  887.     xchg esi,edi
  888.     movsd
  889.     movsd
  890.  
  891.     push edi
  892.     movzx ecx,word[esi]
  893.     inc  esi
  894.     bt   ecx,7
  895.     jc   uselocal
  896.     push [globalColor]
  897.     mov  edi,esi
  898.     jmp  setPal
  899. uselocal:
  900.     call Gif_skipmap
  901.     push esi
  902. setPal:
  903.     movzx ecx,byte[edi]
  904.     inc  ecx
  905.     mov  [codesize],ecx
  906.     dec  ecx
  907.     pop  [Palette]
  908.     lea  esi,[edi+1]
  909.     mov  edi,[table_ptr]
  910.     xor  eax,eax
  911.     cld
  912.     lodsb               ; eax - block_count
  913.     add  eax,esi
  914.     mov  [block_ofs],eax
  915.     mov  [bit_count],8
  916.     mov  eax,1
  917.     shl  eax,cl
  918.     mov  [CC],eax
  919.     inc  eax
  920.     mov  [EOI],eax
  921.     lea  ecx,[eax-1]
  922.     mov  eax, _null shl 16
  923. filltable:
  924.     stosd
  925.     inc  eax
  926.     loop filltable
  927.     pop  edi
  928.     mov  [img_start],edi
  929. reinit:
  930.     mov  edx,[EOI]
  931.     inc  edx
  932.     push [codesize]
  933.     pop  [compsize]
  934.     call Gif_get_sym
  935.     cmp  eax,[CC]
  936.     je   reinit
  937.     call Gif_output
  938. cycle:
  939.     movzx ebx,ax
  940.     call Gif_get_sym
  941.     cmp  eax,edx
  942.     jae  notintable
  943.     cmp  eax,[CC]
  944.     je   reinit
  945.     cmp  eax,[EOI]
  946.     je   zend
  947.     call Gif_output
  948. zadd:
  949.     push eax
  950.     mov  eax,[table_ptr]
  951.     mov  [eax+edx*4],ebx
  952.     pop  eax
  953.     cmp  edx,0xFFF
  954.     jae  cycle
  955.     inc  edx
  956.     bsr  ebx,edx
  957.     cmp  ebx,[compsize]
  958.     jne  noinc
  959.     inc  [compsize]
  960. noinc:
  961.     jmp  cycle
  962. notintable:
  963.     push eax
  964.     mov  eax,ebx
  965.     call Gif_output
  966.     push ebx
  967.     movzx eax,bx
  968.     call Gif_output
  969.     pop  ebx eax
  970.     jmp  zadd
  971. er:
  972.     pop  edi
  973.     jmp  ex
  974. zend:
  975. ;    mov  eax,[.cur_info]    ; skip offset to next frame
  976. ;    mov  [eax],edi
  977.     mov  [cur_info],edi
  978.     add  esi,2
  979.     xchg esi,edi
  980. nxt:
  981.     cmp  byte[edi],0
  982.     jnz  continue
  983.     inc  edi
  984.     jmp  nxt
  985. continue:
  986.     cmp  byte[edi],0x3b    ;read next frame
  987.     jne  nextblock
  988.     xor  eax,eax
  989.     stosd
  990.     mov  ecx,[img_count]
  991. ex:
  992.     pop  edi esi
  993.     ret
  994.  
  995. Gif_skipmap:
  996. ; in: ecx - image descriptor, esi - pointer to colormap
  997. ; out: edi - pointer to area after colormap
  998.  
  999.     and  ecx,111b
  1000.     inc  ecx            ; color map size
  1001.     mov  ebx,1
  1002.     shl  ebx,cl
  1003.     lea  ebx,[ebx*2+ebx]
  1004.     lea  edi,[esi+ebx]
  1005.     ret
  1006.  
  1007. Gif_get_sym:
  1008.     mov  ecx,[compsize]
  1009.     push ecx
  1010.     xor  eax,eax
  1011. shift:
  1012.     ror  byte[esi],1
  1013.     rcr  eax,1
  1014.     dec  [bit_count]
  1015.     jnz  loop1
  1016.     inc  esi
  1017.     cmp  esi,[block_ofs]
  1018.     jb   noblock
  1019.     push eax
  1020.     xor  eax,eax
  1021.     lodsb
  1022.     test eax,eax
  1023.     jnz  nextbl
  1024.     mov  eax,[EOI]
  1025.     sub  esi,2
  1026.     add  esp,8
  1027.     jmp  exx
  1028. nextbl:
  1029.     add  eax,esi
  1030.     mov  [block_ofs],eax
  1031.     pop  eax
  1032. noblock:
  1033.     mov  [bit_count],8
  1034. loop1:
  1035.     loop shift
  1036.     pop  ecx
  1037.     rol  eax,cl
  1038. exx:
  1039.     xor  ecx,ecx
  1040.     ret
  1041.  
  1042. Gif_output:
  1043.     push esi eax edx
  1044.     mov  edx,[table_ptr]
  1045. next:
  1046.     push word[edx+eax*4]
  1047.     mov  ax,word[edx+eax*4+2]
  1048.     inc  ecx
  1049.     cmp  ax,_null
  1050.     jnz  next
  1051.     shl  ebx,16
  1052.     mov  bx,[esp]
  1053. loop2:
  1054.     pop  ax
  1055.  
  1056.     lea  esi,[eax+eax*2]
  1057.     add  esi,[Palette]
  1058.  
  1059.     if COLOR_ORDER eq MENUETOS
  1060.         mov  esi,[esi]
  1061.         bswap esi
  1062.         shr  esi,8
  1063.         mov  [edi],esi
  1064.         add  edi,3
  1065.     else
  1066.         movsw
  1067.         movsb
  1068.     end if
  1069.  
  1070.     loop loop2
  1071.     pop  edx eax esi
  1072.     ret
  1073.  
  1074.     globalColor dd 1
  1075.     img_count dd 1
  1076.     cur_info dd 1        ; image table pointer
  1077.     img_start dd 1
  1078.     codesize dd 1
  1079.     compsize dd 1
  1080.     bit_count dd 1
  1081.     CC dd 1
  1082.     EOI dd 1
  1083.     Palette dd 1
  1084.     block_ofs dd 1
  1085.     table_ptr dd 1
  1086.  
  1087. gifmacend:
  1088. }
  1089.  
  1090.  
  1091.  
  1092. macro giftoimg gifsrc,imgsrc
  1093. {
  1094. local hasharea, ReadGIF, nextblock,_null
  1095. local globalColor, img_count, cur_info, img_start
  1096. local codesize, compsize, bit_count, CC, EOI, Palette
  1097. local block_ofs, table_ptr, gifmacend
  1098. local no_gc, block_skip, no_comm, noextblock, uselocal
  1099. local setPal, filltable, reinit, cycle, zadd, noinc
  1100. local notintable, er, zend, nxt, continue, ex, Gif_skipmap
  1101. local Gif_get_sym, shift, nextbl, noblock, loop1, exx
  1102. local Gif_output, next, loop2
  1103.  
  1104. _null fix 0x1000 ; 0x1000
  1105.  
  1106.     mov  esi,gifsrc           ;“ª § â¥«ì ­  ƒˆ” ä ¨« ¢ ¯ ¬ïâ¨
  1107.     mov  edi,imgsrc           ;“ª § â¥«ì ­  ᯨ᮪ ª à⨭®ª
  1108.  
  1109.     if defined gif_hash_offset
  1110.     mov  eax,gif_hash_offset    ; ¡®ç ï ®¡« áâì ¬¨­¨¬ã¬ 4096*4 ¡ ©â
  1111.     else
  1112.     mov  eax,hasharea         ; ¡®ç ï ®¡« áâì ¬¨­¨¬ã¬ 4096*4 ¡ ©â
  1113.     end if
  1114.  
  1115.     call ReadGIF
  1116.     jmp  gifmacend
  1117.  
  1118.     if defined gif_hash_offset
  1119.     else
  1120.     hasharea:
  1121.     times 4096 dd 0 ;4096
  1122.     end if
  1123.  
  1124. ReadGIF:
  1125.     push esi edi
  1126.     mov  [table_ptr],eax
  1127.     mov  [cur_info],edi
  1128.     xor  eax,eax
  1129.     mov  [globalColor],eax
  1130.     mov  [img_count],eax
  1131.     inc  eax
  1132.     cmp  dword[esi],'GIF8'
  1133.     jne  er            ; signature
  1134.     mov  ecx,[esi+0xa]
  1135.     inc  eax
  1136.     add  esi,0xd
  1137.     mov  edi,esi
  1138.     bt   ecx,7
  1139.     jnc  nextblock
  1140.     mov  [globalColor],esi
  1141.     call Gif_skipmap
  1142. nextblock:
  1143.     cmp  byte[edi],0x21
  1144.     jne  noextblock
  1145.     inc  edi
  1146.     cmp  byte[edi],0xf9 ; Graphic Control Ext
  1147.     jne  no_gc
  1148.     add  edi,7
  1149.     jmp  nextblock
  1150. no_gc:
  1151.     cmp  byte[edi],0xfe ; Comment Ext
  1152.     jne  no_comm
  1153.     inc  edi
  1154. block_skip:
  1155.     movzx eax,byte[edi]
  1156.     lea  edi,[edi+eax+1]
  1157.     cmp  byte[edi],0
  1158.     jnz  block_skip
  1159.     inc  edi
  1160.     jmp  nextblock
  1161. no_comm:
  1162.     cmp  byte[edi],0xff ; Application Ext
  1163.     jne  nextblock
  1164.     add  edi,13
  1165.     jmp  block_skip
  1166. noextblock:
  1167.     cmp  byte[edi],0x2c    ; image beginning
  1168.     jne  er
  1169.     inc  [img_count]
  1170.     inc  edi
  1171.     mov  esi,[cur_info]
  1172.     xchg esi,edi
  1173. ;    movsd
  1174. ;    movsd
  1175.  
  1176.     mov   bp,word[esi+4]
  1177.     movzx ebx,bp
  1178.     mov   [edi],ebx
  1179.  
  1180.     mov   bp,word[esi+6]
  1181.     movzx ebx,bp
  1182.     mov   [edi+4],ebx
  1183.  
  1184.     add edi,8
  1185.     add esi,8
  1186.  
  1187.     push edi
  1188.     movzx ecx,word[esi]
  1189.     inc  esi
  1190.     bt   ecx,7
  1191.     jc   uselocal
  1192.     push [globalColor]
  1193.     mov  edi,esi
  1194.     jmp  setPal
  1195. uselocal:
  1196.     call Gif_skipmap
  1197.     push esi
  1198. setPal:
  1199.     movzx ecx,byte[edi]
  1200.     inc  ecx
  1201.     mov  [codesize],ecx
  1202.     dec  ecx
  1203.     pop  [Palette]
  1204.     lea  esi,[edi+1]
  1205.     mov  edi,[table_ptr]
  1206.     xor  eax,eax
  1207.     cld
  1208.     lodsb               ; eax - block_count
  1209.     add  eax,esi
  1210.     mov  [block_ofs],eax
  1211.     mov  [bit_count],8
  1212.     mov  eax,1
  1213.     shl  eax,cl
  1214.     mov  [CC],eax
  1215.     inc  eax
  1216.     mov  [EOI],eax
  1217.     lea  ecx,[eax-1]
  1218.     mov  eax, _null shl 16
  1219. filltable:
  1220.     stosd
  1221.     inc  eax
  1222.     loop filltable
  1223.     pop  edi
  1224.     mov  [img_start],edi
  1225. reinit:
  1226.     mov  edx,[EOI]
  1227.     inc  edx
  1228.     push [codesize]
  1229.     pop  [compsize]
  1230.     call Gif_get_sym
  1231.     cmp  eax,[CC]
  1232.     je   reinit
  1233.     call Gif_output
  1234. cycle:
  1235.     movzx ebx,ax
  1236.     call Gif_get_sym
  1237.     cmp  eax,edx
  1238.     jae  notintable
  1239.     cmp  eax,[CC]
  1240.     je   reinit
  1241.     cmp  eax,[EOI]
  1242.     je   zend
  1243.     call Gif_output
  1244. zadd:
  1245.     push eax
  1246.     mov  eax,[table_ptr]
  1247.     mov  [eax+edx*4],ebx
  1248.     pop  eax
  1249.     cmp  edx,0xFFF
  1250.     jae  cycle
  1251.     inc  edx
  1252.     bsr  ebx,edx
  1253.     cmp  ebx,[compsize]
  1254.     jne  noinc
  1255.     inc  [compsize]
  1256. noinc:
  1257.     jmp  cycle
  1258. notintable:
  1259.     push eax
  1260.     mov  eax,ebx
  1261.     call Gif_output
  1262.     push ebx
  1263.     movzx eax,bx
  1264.     call Gif_output
  1265.     pop  ebx eax
  1266.     jmp  zadd
  1267. er:
  1268.     pop  edi
  1269.     jmp  ex
  1270. zend:
  1271. ;    mov  eax,[.cur_info]    ; skip offset to next frame
  1272. ;    mov  [eax],edi
  1273.     mov  [cur_info],edi
  1274.     add  esi,2
  1275.     xchg esi,edi
  1276. nxt:
  1277.     cmp  byte[edi],0
  1278.     jnz  continue
  1279.     inc  edi
  1280.     jmp  nxt
  1281. continue:
  1282. ;    cmp  byte[edi],0x3b    ;read next frame
  1283. ;    jne  nextblock
  1284.     xor  eax,eax
  1285.     stosd
  1286.     mov  ecx,[img_count]
  1287. ex:
  1288.     pop  edi esi
  1289.     ret
  1290.  
  1291. Gif_skipmap:
  1292. ; in: ecx - image descriptor, esi - pointer to colormap
  1293. ; out: edi - pointer to area after colormap
  1294.  
  1295.     and  ecx,111b
  1296.     inc  ecx            ; color map size
  1297.     mov  ebx,1
  1298.     shl  ebx,cl
  1299.     lea  ebx,[ebx*2+ebx]
  1300.     lea  edi,[esi+ebx]
  1301.     ret
  1302.  
  1303. Gif_get_sym:
  1304.     mov  ecx,[compsize]
  1305.     push ecx
  1306.     xor  eax,eax
  1307. shift:
  1308.     ror  byte[esi],1
  1309.     rcr  eax,1
  1310.     dec  [bit_count]
  1311.     jnz  loop1
  1312.     inc  esi
  1313.     cmp  esi,[block_ofs]
  1314.     jb   noblock
  1315.     push eax
  1316.     xor  eax,eax
  1317.     lodsb
  1318.     test eax,eax
  1319.     jnz  nextbl
  1320.     mov  eax,[EOI]
  1321.     sub  esi,2
  1322.     add  esp,8
  1323.     jmp  exx
  1324. nextbl:
  1325.     add  eax,esi
  1326.     mov  [block_ofs],eax
  1327.     pop  eax
  1328. noblock:
  1329.     mov  [bit_count],8
  1330. loop1:
  1331.     loop shift
  1332.     pop  ecx
  1333.     rol  eax,cl
  1334. exx:
  1335.     xor  ecx,ecx
  1336.     ret
  1337.  
  1338. Gif_output:
  1339.     push esi eax edx
  1340.     mov  edx,[table_ptr]
  1341. next:
  1342.     push word[edx+eax*4]
  1343.     mov  ax,word[edx+eax*4+2]
  1344.     inc  ecx
  1345.     cmp  ax,_null
  1346.     jnz  next
  1347.     shl  ebx,16
  1348.     mov  bx,[esp]
  1349. loop2:
  1350.     pop  ax
  1351.  
  1352.     lea  esi,[eax+eax*2]
  1353.     add  esi,[Palette]
  1354.  
  1355.     if COLOR_ORDER eq MENUETOS
  1356.         mov  esi,[esi]
  1357.         bswap esi
  1358.         shr  esi,8
  1359.         mov  [edi],esi
  1360.         add  edi,3
  1361.     else
  1362.         movsw
  1363.         movsb
  1364.     end if
  1365.  
  1366.     loop loop2
  1367.     pop  edx eax esi
  1368.     ret
  1369.  
  1370.     globalColor dd 1
  1371.     img_count dd 1
  1372.     cur_info dd 1        ; image table pointer
  1373.     img_start dd 1
  1374.     codesize dd 1
  1375.     compsize dd 1
  1376.     bit_count dd 1
  1377.     CC dd 1
  1378.     EOI dd 1
  1379.     Palette dd 1
  1380.     block_ofs dd 1
  1381.     table_ptr dd 1
  1382.  
  1383. gifmacend:
  1384. }
  1385.  
  1386.