home *** CD-ROM | disk | FTP | other *** search
/ Groovy Bytes: Behind the Moon / groovybytes.iso / GROOVY / DISKMAGS / IMPHOB_8.ZIP / IMP8_EX!.ZIP / STONE4KB.ZIP / TAYLRSIN.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-08-26  |  3.9 KB  |  127 lines

  1. ;▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  2. ; Taylor Sinetable Generation (& Postprocessor Implementation Demo)
  3. ;
  4. ; To make 4KB Intros small. Published together with the Imphobia VIII issue.
  5. ;
  6. ; Written in 1994 by Markus Stein alias Stone/Dust
  7. ;▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  8.  
  9. code    segment
  10.         assume cs:code,ds:code
  11.         org 100h
  12.         locals
  13.         .386
  14.  
  15. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  16. ; MAIN
  17. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  18.  
  19. start:  cld                       ;clear direction flag
  20.         mov di,offset zeroed_data_start
  21.         mov cx,offset zeroed_data_end-zeroed_data_start
  22.         push ds
  23.         pop es
  24.         xor al,al
  25.         rep stosb                 ;init zeroed data (s. postprocessor)
  26.  
  27.         call generate_taylor_sinetab
  28.  
  29. EXIT:   mov ah,4ch                ;exit
  30.         int 21h
  31. ;----------------------------------
  32.  
  33. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  34. ; GENERATE SINE & COSINE LOOKUP-TABLE USING TAYLOR'S APPROXIMATION
  35. ; - fixed point integer math: 02b.30b
  36. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  37.  
  38. SINETAB_LENGTH  equ 4096          ;number of DWords sinetab will consist of
  39. ;----------------------------------
  40.  
  41. GENERATE_TAYLOR_SINETAB proc      ;GENERATE SINETABLE
  42.         mov ebp,40000000h          ;ebp = 1.0
  43.         xor esi,esi                ;variable x
  44.         xor cx,cx                  ;index for destination in table
  45.  
  46. @@01:   push cx                   ;calculate taylor's approximation for both
  47.         mov sinvalue,esi          ;sines and cosines
  48.         mov cosvalue,ebp
  49.         xor edi,edi
  50.         inc di
  51. @@02:   call @@sub
  52.         sub cosvalue,eax
  53.         call @@sub
  54.         sub sinvalue,eax
  55.         call @@sub
  56.         add cosvalue,eax
  57.         call @@sub
  58.         add sinvalue,eax
  59.         cmp di,13
  60.         jne @@02
  61.         pop cx
  62.  
  63.         mov eax,sinvalue          ;convert to 16b.16b
  64.         sar eax,14
  65.         mov ebx,cosvalue
  66.         sar ebx,14
  67.         mov di,offset sinetab     ;and store in table (sine and cosine values)
  68.         add di,cx
  69.         mov [di]+(sinetab_length/4*0)*4,eax
  70.         mov [di]+(sinetab_length/4*1)*4,ebx
  71.         mov [di]+(sinetab_length/4*4)*4,eax
  72.         sub di,cx
  73.         sub di,cx
  74.         mov [di]+(sinetab_length/4*2)*4,eax
  75.         mov [di]+(sinetab_length/4*1)*4,ebx
  76.         mov [di]+(sinetab_length/4*5)*4,ebx
  77.         neg eax
  78.         neg ebx
  79.         mov [di]+(sinetab_length/4*4)*4,eax
  80.         mov [di]+(sinetab_length/4*3)*4,ebx
  81.         add di,cx
  82.         add di,cx
  83.         mov [di]+(sinetab_length/4*2)*4,eax
  84.         mov [di]+(sinetab_length/4*3)*4,ebx
  85.  
  86.         add esi,1921f6h           ;next x value (pi/(sintab_length/8*4)*2^30)
  87.         add cx,4
  88.         cmp cx,(sinetab_length/8) * 4
  89.         jbe @@01
  90.         ret
  91.  
  92. @@sub:  inc di                    ;EAX <- x ^ (++count) / (count!)
  93.         mov eax,ebp
  94.         xor ebx,ebx
  95.         inc bx
  96.         mov ecx,edi
  97. @@sub@1:imul esi
  98.         shrd eax,edx,30
  99.         imul ebx,ecx
  100.         loop @@sub@1
  101.         cdq
  102.         idiv ebx
  103.         ret
  104. GENERATE_TAYLOR_SINETAB endp
  105. ;--------------------------------------------------
  106.  
  107. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  108. ; ZEROED DATA
  109. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  110.  
  111. ZEROED_DATA_START label
  112. ;---------------------------------- SINETABLE
  113.  
  114.         align 4
  115. SINVALUE     dd 0
  116. COSVALUE     dd 0
  117. SINETAB      dd sinetab_length/4 dup (0)
  118. COSINETAB    dd sinetab_length dup (0)
  119.              dd 0
  120. ;----------------------------------
  121.  
  122. ZEROED_DATA_END label
  123. ;----------------------------------
  124.  
  125. ;▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  126. code    ends
  127.         end start