home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / ML_BME1.ZIP / ROTATE / V3 / ROTASM2.ASM < prev    next >
Encoding:
Assembly Source File  |  1996-10-25  |  6.5 KB  |  244 lines

  1. ; Bitmap rotation engine, v2.0
  2. ; by Maple Leaf, 22 Oct 96
  3. ;
  4. ; Version works for 320x200 bitmaps
  5. ; --------------------------------------------------------------------------
  6. ; This is far from being a masterpiece of optimized code; only the jumps and
  7. ; memory-ADD were optimized a little bit, but anyway, enjoy it.
  8. ; Note: The bitmap is supposed to be at 320x200, otherwise, the result will
  9. ;        be at least messy...
  10. ;       Some VERY important speed optimizations can be performed if the
  11. ;        bitmap is 256x256... The inner loop would be in this case VERY MUCH
  12. ;        simpler and much faster!
  13. ; --------------------------------------------------------------------------
  14. ; asm rules, yup yup! the others suck!
  15.  
  16. .model TPascal
  17. .386
  18. .DATA
  19.  
  20.         extrn    _Ax_ : DWORD
  21.         extrn    _Ay_ : DWORD
  22.         extrn    _Bx_ : DWORD
  23.         extrn    _By_ : DWORD
  24.         extrn    _Cx_ : DWORD
  25.         extrn    _Cy_ : DWORD
  26.         extrn    vScr:WORD
  27.         extrn    Img:DWORD
  28.         extrn    Angle:BYTE
  29.         extrn    WW:DWORD
  30.         extrn    WH:DWORD
  31.         extrn    CosTab:DWORD
  32.         extrn    SinTab:DWORD
  33.  
  34. .CODE
  35.  
  36.         public   GenFrame
  37.  
  38. include jumps.inc
  39.  
  40. ;****************************************************************************
  41.  
  42. proc    ComputeFramePara near
  43.  
  44.         mov      al,Angle
  45.         movzx    si,al
  46.         add      al,64     ; Angle+90 in a 360-deg system
  47.         movzx    di,al
  48.  
  49.         shl      si,2
  50.         shl      di,2      ; indexes in SinTab/CosTab
  51.  
  52.         mov      eax,WH
  53.         xor      edx,edx
  54.         mov      ecx,dword ptr CosTab[si]
  55.         imul     ecx
  56.         shrd     eax,edx,8
  57.         add      eax,_Ax_  ; eax = _ax_ + WH * cos (angle)
  58.         mov      _Bx_,eax  ; store result
  59.  
  60.         mov      eax,WH
  61.         xor      edx,edx
  62.         mov      ecx,dword ptr SinTab[si]
  63.         imul     ecx
  64.         shrd     eax,edx,8
  65.         sub      eax,_Ay_  
  66.         neg      eax       ; eax = _ay_ - WH * sin (angle)
  67.         mov      _By_,eax  ; store result
  68.  
  69.         mov      eax,WW
  70.         xor      edx,edx
  71.         mov      ecx,dword ptr CosTab[di]
  72.         imul     ecx
  73.         shrd     eax,edx,8
  74.         add      eax,_Ax_  ; eax = _ax_ + WW * cos (angle+90)
  75.         mov      _Cx_,eax  ; store result
  76.  
  77.         mov      eax,WW
  78.         xor      edx,edx
  79.         mov      ecx,dword ptr SinTab[di]
  80.         imul     ecx
  81.         shrd     eax,edx,8
  82.         sub      eax,_Ay_  
  83.         neg      eax       ; eax = _ay_ - WW * sin (angle+90)
  84.         mov      _Cy_,eax  ; store result
  85.  
  86.         mov      eax,_Cx_
  87.         sub      eax,_Ax_
  88.         shl      eax,16
  89.         cdq
  90.         mov      ecx,320
  91.         idiv     ecx        ; hAdvX = ((_cx_-_ax_) shl 16) div 320
  92.         mov      dword ptr cs:smc1+2,eax  ; SMCODE INIT
  93.  
  94.         mov      eax,_Cy_
  95.         sub      eax,_Ay_
  96.         shl      eax,16
  97.         cdq
  98.         mov      ecx,320
  99.         idiv     ecx        ; hAdvY = ((_cy_-_ay_) shl 16) div 320
  100.         mov      dword ptr cs:smc2+3,eax  ; SMCODE INIT
  101.  
  102.         mov      eax,_Bx_
  103.         sub      eax,_Ax_
  104.         shl      eax,16
  105.         cdq
  106.         mov      ecx,200
  107.         idiv     ecx        ; vAdvX = ((_bx_-_ax_) shl 16) div 200
  108.         mov      dword ptr cs:smc3+2,eax  ; SMCODE INIT
  109.  
  110.         mov      eax,_By_
  111.         sub      eax,_Ay_
  112.         shl      eax,16
  113.         cdq
  114.         mov      ecx,200
  115.         idiv     ecx        ; vAdvY = ((_by_-_ay_) shl 16) div 200
  116.         mov      dword ptr cs:smc4+3,eax  ; SMCODE INIT
  117.  
  118.         retn
  119.         endp
  120.  
  121. ;****************************************************************************
  122.  
  123. e5:     add      eax,1400000h
  124.         jmp      short ce5
  125.  
  126. e6:     add      ebx,0C80000h
  127.         jmp      short ce6
  128.  
  129. e7:     sub      eax,1400000h
  130.         jmp      short ce7
  131.  
  132. e8:     sub      ebx,0C80000h
  133.         jmp      short ce8
  134.  
  135. GenFrame PROC    NEAR  ;-----------------------------------------------------
  136.  
  137.         push     ds es
  138.  
  139. ;       pushad   ; in my example I don't need such sober instructions... :)
  140.                  ; but if the registers are vital to your application, feel
  141.                  ; free to erase the comment (see POPAD, too!)
  142.  
  143.         call     ComputeFramePara
  144.  
  145.         mov      es,vScr
  146.         xor      di,di
  147.  
  148.         mov      eax,_Ax_   ;  starting coordinates
  149.         mov      ebx,_Ay_   ;
  150.  
  151.         shl      eax,16     ;  float emulation ...
  152.         shl      ebx,16     ;
  153.  
  154.         mov      ds,Img[2]  ; bitmap seg (from this point on)
  155.  
  156. ;-- Loop 1 (200 times) ------------------------------------------------------
  157.         mov      cx,200
  158.  
  159. Loop1:  push     cx eax ebx
  160.  
  161. ;-- Loop 2 (320 times) ------------------------------------------------------
  162.         mov      cx,320
  163. Loop2:  mov      esi,ebx
  164.         shr      esi,16
  165.  
  166.     ;   add      si,si
  167.     ;   mov      si,word ptr RowOffs[si]  ; require DS=DATA !!!
  168.  
  169.         mov      dx,si       ; it seems quite unlikely, but these instructions
  170.         shl      si,6        ; are faster than the two instructions above
  171.         shl      dx,8        ; (which were replaced)
  172.         add      si,dx       ;
  173.  
  174.         mov      edx,eax
  175.         shr      edx,16
  176.         add      si,dx
  177.  
  178.     ;   mov      dl,[si]
  179.     ;   mov      es:[di],dl
  180.     ;   inc      di
  181.  
  182.         mov      al,[si]     ; this combination seems to be faster than two
  183.         stosb                ; MOVs and one INC, although it fucks up AL reg.
  184.  
  185. smc1:   add      eax,12345678h ;hAdvX  ; AL is fucked up, but what the heck...
  186.         sjl      e5
  187. ce5:
  188. smc2:   add      ebx,12345678h ;hAdvY
  189.         sjl      e6
  190.  
  191. ce6:    cmp      eax,1400000h
  192.         sjge     e7
  193.  
  194. ce7:    cmp      ebx,0C80000h
  195.         sjge     e8
  196.  
  197. ce8:    dec      cx
  198.         sjg      Loop2
  199.  
  200. ;-- End loop 2 --------------------------------------------------------------
  201.  
  202.         pop      ebx eax cx
  203.  
  204. smc3:   add      eax,12345678h ;vAdvX
  205.         sjl      e1
  206. ce1:
  207. smc4:   add      ebx,12345678h ;vAdvY
  208.         sjl      e2
  209.  
  210. ce2:    cmp      eax,1400000h
  211.         sjge     e3
  212.  
  213. ce3:    cmp      ebx,0C80000h
  214.         sjge     e4
  215.  
  216. ce4:    dec      cx
  217.         sjg      Loop1
  218.  
  219. ;-- End loop 1---------------------------------------------------------------
  220.  
  221. ;       popad
  222.  
  223.         pop      es ds
  224.  
  225.         retn
  226.  
  227. e1:     add      eax,1400000h
  228.         jmp      short ce1
  229.  
  230. e2:     add      ebx,0C80000h
  231.         jmp      short ce2
  232.  
  233. e3:     sub      eax,1400000h
  234.         jmp      short ce3
  235.  
  236. e4:     sub      ebx,0C80000h
  237.         jmp      short ce4
  238.  
  239.         endp
  240.  
  241.  
  242.  
  243.         END
  244.