home *** CD-ROM | disk | FTP | other *** search
/ PC Underground / UNDERGROUND.ISO / magn / magn.asm < prev    next >
Assembly Source File  |  1995-07-28  |  5KB  |  147 lines

  1. data segment public
  2.   extrn    buffer:dword        ;Pointer to image buffer
  3.   extrn backgnd:dword           ;Pointer to background
  4.   extrn Circle_Start:dataptr    ;Definition of circle
  5.   extrn Circle_End:dataptr
  6. data ends
  7.  
  8. code segment public
  9. assume cs:code,ds:data
  10. .386                            ;386 commands on (32 Bit)
  11. cur_ofs    dw 0                                    ;current offset in destination image
  12. Row_Ofs dw 0                    ;current offset at beginning of row
  13. Circle_Start_cs dw 49*2 dup (0) ;Definition of circle
  14. Circle_End_cs dw 49*2 dup (0)
  15. cur_End dw 0            ;current end of circle
  16.  
  17.  
  18. root proc pascal                ;extracts root of eax, result in ax
  19.   or eax,eax                                        ;is radicand 0 ?
  20.   je return                     ;then already finished, else:
  21.   push ecx                                            ;save register
  22.   push edx
  23.   xor esi,esi                   ;clear interim results (in esi)
  24.   mov ebx,eax
  25.   xor edx,edx                   ;clear edx
  26.   mov ecx,ebx                   ;store initial value in ecx
  27.  
  28. iterat:
  29.   cdq
  30.   idiv ebx                      ;divide by Xn
  31.   xor edx,edx                   ;remainder not important
  32.   add eax,ebx                   ;add Xn
  33.   shr eax,1                     ;divide by 2
  34.   sub esi,eax                   ;difference from previous results
  35.   cmp esi,1                     ;less than or equal to 1
  36.   jbe finished                  ;then finished
  37.   mov esi,eax                   ;store results as previous
  38.   mov ebx,eax                   ;record as Xn
  39.   mov eax,ecx                   ;reload initial value for division
  40.   jmp iterat                    ;and to beginning of loop
  41. finished:
  42.   pop edx                                                ;restore register
  43.   pop ecx
  44. return:
  45.   ret                           ;results now in eax
  46. root endp
  47.  
  48.  
  49. public magn_asm                                    ;shows magnifying glass effect at coordinates zx/zy
  50. magn_asm proc pascal zx,zy:word
  51. local y_count,x_count:word
  52. push ds                                                ;store ds
  53.  
  54.   mov bx,cs                                            ;es := cs
  55.   mov es,bx
  56.   lea si,Circle_Start            ;Circle_Start - values to code segment
  57.   lea di,Circle_Start_cs
  58.   mov cx,49                      ;copy 49 values
  59.   rep movsw
  60.   lea si,Circle_End              ;Circle_End - values to code segment
  61.   lea di,Circle_End_cs
  62.   mov cx,49
  63.   rep movsw
  64.  
  65.   les di,buffer                 ;load destination address: Buffer
  66.   mov ax,zy                     ;add destination coordinates to offset
  67.   imul ax,320
  68.   add ax,zx
  69.   mov cur_ofs,ax                ;destination offset finished
  70.   mov Row_Ofs,ax
  71.  
  72.   lds si,backgnd                ;source address: background
  73. assume ds:nothing
  74.  
  75.   xor eax,eax                                        ;clear 32bit register
  76.   xor ebx,ebx
  77.   xor ecx,ecx
  78.   xor edx,edx
  79.   mov y_count,0                 ;y-loop from 48 - 0
  80.  
  81. next_y:
  82.   mov bx,y_count
  83.   shl bx,1                      ;Array from words
  84.   mov ax,Circle_End_cs[bx]      ;Circle_Start - get value from array
  85.   mov cur_End,ax                ;note for later
  86.   mov bx,Circle_Start_cs[bx]    ;Circle_End - get value from array
  87.   mov x_count,bx                                ;load x counter
  88.   add cur_ofs,bx                ;in addition, add destination offset
  89.  
  90. next_x:
  91.   mov ecx,24d                                        ;24= half width of magnifying glass
  92.   movzx eax,y_count             ;load y counter
  93.   sub eax,ecx                                        ;shift center point to middle of magnifying glass
  94.   shl eax,8                     ;for calculating accuracy
  95.   cdq                           ;load edx
  96.   idiv ecx                      ;range of values to -1..1 (-256..256)
  97.   mov ebx,eax                   ;store temporarily in ebx
  98.   movzx eax,x_count             ;the same with the x-counter
  99.   sub eax,24d
  100.   shl eax,8
  101.   cdq
  102.   idiv ecx
  103.   mov ecx,eax                   ;store x in ecx
  104.   mov edx,ebx                   ;and y in edx
  105.   imul eax,eax                  ;square x
  106.   imul ebx,ebx                  ;square y
  107.   add eax,ebx                   ;obtain sum
  108.   call root                     ;and calculate root
  109.   imul eax,24d                  ;multiply roots times half width
  110.   mov edi,eax                                        ;save results for later
  111.  
  112.   imul eax,edx                                    ;multiply times y-coordinate
  113.   sar eax,16d                   ;offset squaring etc.
  114.   movzx ebx,zy                  ;add destination coordinate
  115.   add eax,ebx
  116.   add eax,24d                   ;shift center
  117.   imul eax,320                                    ;convert to offset
  118.   mov esi,eax                   ;and store in esi
  119.  
  120.   mov eax,ecx                   ;get x
  121.   imul eax,edi                  ;multiply times root
  122.   sar eax,16d                   ;offset squaring etc.
  123.   movzx ebx,zx                  ;add destination coordinate
  124.   add eax,ebx
  125.   add eax,24d                   ;shift center
  126.   add esi,eax                   ;add to previous offset
  127.  
  128.   mov di,cur_ofs                ;get current destination offset
  129.   inc cur_ofs                   ;and increment
  130.   movsb                         ;copy point
  131.  
  132.   inc x_count                   ;increment x counter
  133.   mov ax,cur_End                                ;already at end ?
  134.   cmp x_count,ax
  135.   jb next_x
  136.   add Row_Ofs,320        ;then to next row
  137.   mov ax,Row_Ofs
  138.   mov cur_ofs,ax
  139.   inc y_count                   ;increment y counter
  140.   cmp y_count,48
  141.   jb next_y                        ;if finished,
  142.   pop ds                        ;then finished drawing magnifying glass
  143.   ret
  144. magn_asm endp
  145. code ends
  146. end
  147.