home *** CD-ROM | disk | FTP | other *** search
/ The Party 1994: Try This At Home / disk_image.bin / source / fakesrc / part10 / zoom.asm < prev   
Assembly Source File  |  1993-11-20  |  16KB  |  477 lines

  1. ;=============================================================================
  2. ; zoom.asm - Mandelbrot Set Zoom Demostration.
  3. ;                                                    File created: 10-11-93
  4. ; Copyright (C) 1993, Carlos Hasan                  Last modified: 11-21-93
  5. ;
  6. ; Description:
  7. ;  This file implements the Runtime MandelZoom demostration. Needs the
  8. ;  Mandelbrot Set calculation routines and the zoom-in path include file.
  9. ;
  10. ; Portability:
  11. ;  Requires Turbo Assembler 3.2 or better to be assembler.
  12. ;  Dependent on the IBM PC 386 and the VGA graphics card.
  13. ;
  14. ; Modifications:
  15. ;  10/22/93 - Startup Code.
  16. ;  11/21/93 - Now this thing Shows the Frame Creation.
  17. ;=============================================================================
  18.  
  19.                 .model  small,pascal
  20.                 .386
  21.  
  22.                 dosseg                          ; used to link like
  23.                 .stack  1024                    ; an standalone program.
  24.  
  25.                 global  MandelZoom:proc
  26.                 global  DrawMandel:proc         ; in MANDEL.ASM
  27.  
  28. ;===================== Demo Equates ==========================================
  29.  
  30. MAXWIDTH        equ     320                     ; VGA Screen Dimensions.
  31. MAXHEIGHT       equ     200
  32.  
  33. ;===================== Demo Data =============================================
  34.  
  35.                 .data
  36.  
  37.                 include ZoomPath.Inc            ; Zoom-In Information.
  38.                                                 ; and Color Palette.
  39.  
  40. GridX           dw      WINSIZEX dup (?)        ; Used to compute the
  41. GridY           dw      WINSIZEY dup (?)        ; Zoom-In Window.
  42.  
  43. ;===================== Demo Routines =========================================
  44.  
  45.                 .code
  46.  
  47. ;-----------------------------------------------------------------------------
  48. ; WaitVRT - Waits the next VGA Vertical Retrace Period.
  49. ;-----------------------------------------------------------------------------
  50.  
  51. WaitVRT         proc near
  52.  
  53.                 mov     dx,3DAh
  54. WaitVRT1:       in      al,dx
  55.                 test    al,8
  56.                 jz      WaitVRT1
  57. WaitVRT2:       in      al,dx
  58.                 test    al,8
  59.                 jnz     WaitVRT2
  60.                 ret
  61.  
  62. WaitVRT         endp
  63.  
  64. ;-----------------------------------------------------------------------------
  65. ; BlackPalette - Set a Black Palette.
  66. ;-----------------------------------------------------------------------------
  67.  
  68. BlackPalette    proc near
  69.  
  70.                 call    WaitVRT
  71.                 mov     dx,3C8h
  72.                 xor     al,al
  73.                 out     dx,al
  74.                 inc     dx
  75.                 mov     cx,768
  76. BlackLoop:      out     dx,al
  77.                 loop    BlackLoop
  78.                 ret
  79.  
  80. BlackPalette    endp
  81.  
  82.  
  83. ;-----------------------------------------------------------------------------
  84. ; SetPalette - Sets the Color Palette.
  85. ;-----------------------------------------------------------------------------
  86.  
  87. SetPalette      proc near
  88.  
  89.                 call    WaitVRT
  90.                 mov     dx,3C8h
  91.                 xor     al,al
  92.                 out     dx,al
  93.                 inc     dx
  94.                 lea     si,[Palette]
  95.                 mov     cx,768
  96.                 rep     outsb
  97.                 ret
  98.  
  99. SetPalette      endp
  100.  
  101. ;-----------------------------------------------------------------------------
  102. ; FadeInPalette - Fade-In the palette.
  103. ;-----------------------------------------------------------------------------
  104.  
  105. FadeInPalette   proc near
  106.  
  107.                 xor     bx,bx
  108. FadeInLoop:     lea     si,[Palette]
  109.                 mov     dx,3C8h
  110.                 xor     al,al
  111.                 out     dx,al
  112.                 mov     cx,768
  113.                 call    WaitVRT
  114.                 mov     dx,3C9h
  115. FadeIn:         lodsb
  116.                 mul     bl
  117.                 mov     al,ah
  118.                 out     dx,al
  119.                 loop    FadeIn
  120.                 add     bl,4
  121.                 jnc     FadeInLoop
  122.                 ret
  123.  
  124. FadeInPalette   endp
  125.  
  126.  
  127. ;-----------------------------------------------------------------------------
  128. ; FadeOutPalette - Fade-Out the palette.
  129. ;-----------------------------------------------------------------------------
  130.  
  131. FadeOutPalette  proc near
  132.  
  133.                 mov     bl,252
  134. FadeOutLoop:    call    WaitVRT
  135.                 mov     dx,3C8h
  136.                 xor     al,al
  137.                 out     dx,al
  138.                 inc     dx
  139.                 lea     si,[Palette]
  140.                 mov     cx,768
  141. FadeOut:        lodsb
  142.                 mul     bl
  143.                 mov     al,ah
  144.                 out     dx,al
  145.                 loop    FadeOut
  146.                 sub     bl,4
  147.                 jnc     FadeOutLoop
  148.                 ret
  149.  
  150. FadeOutPalette  endp
  151.  
  152.  
  153. ;-----------------------------------------------------------------------------
  154. ; ClearScreen - Clears the Video Screen using a Spray-like effect.
  155. ;-----------------------------------------------------------------------------
  156.  
  157. ClearScreen     proc near
  158.  
  159.                 push    ds
  160.                 push    es
  161.  
  162.                 mov     ax,0A000h
  163.                 mov     es,ax
  164.  
  165.                 xor     cx,cx
  166. SprayLoop:      push    cx
  167.                 xor     bx,bx
  168. SprayLine:      push    bx
  169.                 mov     ah,cs:[RandTable+bx]
  170.                 mov     bx,cx
  171.                 mov     al,cs:[RandTable+bx]
  172.                 mov     bx,ax
  173.                 mov     di,ax
  174.                 xor     al,al
  175.                 mov     es:[di],al
  176.                 pop     bx
  177.                 inc     cl
  178.                 inc     bl
  179.                 jne     SprayLine
  180.                 pop     cx
  181.                 inc     cl
  182.                 jne     SprayLoop
  183.  
  184.                 pop     es
  185.                 pop     ds
  186.                 ret
  187.  
  188. RandTable label byte
  189.       db   83,   8,  18, 177,  13, 241, 149, 157
  190.       db   75, 248, 254,  23,  16,  66, 207,  31
  191.       db  211, 183,  80, 242, 218,  27,  15, 128
  192.       db   94,  98,   4,  36, 139, 110,  85, 230
  193.       db  212,  26,  12, 249, 169, 233, 200, 150
  194.       db   95, 114, 130, 167, 202, 187,  76, 145
  195.       db   62, 117, 115, 190, 209,  42, 185, 224
  196.       db  129, 104, 108, 192, 174, 137,  44,  41
  197.       db  141,  53, 179,  81, 181,  57, 147, 210
  198.       db   50, 134, 156, 125, 133, 126, 106, 162
  199.       db   20,  59,  84,   0, 151, 143, 101, 215
  200.       db   68, 246, 189, 197,  99, 213, 112, 144
  201.       db   28, 235, 240,  90, 154,  56, 138, 165
  202.       db   19, 166, 159,  92, 127, 208, 105, 118
  203.       db  119, 153, 191, 184,  87,  70,   9, 164
  204.       db   60, 252,  96,   3, 171,  38, 136,  14
  205.       db    7, 160,  71, 146, 102, 229, 227,  43
  206.       db  221, 182, 217,  30, 131, 219,  61, 180
  207.       db  195, 245, 109, 203,  24,  49, 170, 247
  208.       db   46, 148, 122, 250, 173, 107, 255, 194
  209.       db    6,  37,  93,  22, 168,  97, 193,   5
  210.       db   51, 223, 116,  86,   1,  89, 121, 243
  211.       db  140, 220,  39, 222,  65,  55,  17,  54
  212.       db  175, 206, 214, 155, 142, 163,  25, 188
  213.       db  178,  11, 204, 135, 201, 238,  79, 132
  214.       db  198,  40,  21,  45, 237, 253, 152,  74
  215.       db   32, 111,  52,  47, 236,   2, 176, 239
  216.       db  234,  58, 100,  91, 172,  73,  82, 205
  217.       db   34,  88,  78, 231, 232, 225,  48, 251
  218.       db   67, 123, 244,  29, 216,  64, 196,  69
  219.       db  199,  33,  72,  35,  10,  63, 161, 228
  220.       db  113, 158, 120, 103, 124, 186, 226,  77
  221.  
  222. ClearScreen   endp
  223.  
  224.  
  225. ;-----------------------------------------------------------------------------
  226. ; ZoomBox - Draws the Zoom Window using the precalculated Mandelbrot
  227. ;  pictures and coordinates in the ZoomPath include file.
  228. ;-----------------------------------------------------------------------------
  229.  
  230. ZoomBox         proc near XStart:word,YStart:word,XStop:word,YStop:word, \
  231.                      PicSeg:word
  232.  
  233.                 mov     si,[XStart]             ; compute the GridX array.
  234.                 mov     di,[XStop]
  235.                 lea     bx,[GridX]
  236.                 mov     cx,WINSIZEX
  237.                 mov     ax,di
  238.                 sub     ax,si
  239.                 cwd
  240.                 div     cx
  241.                 xchg    si,ax
  242.                 mov     di,dx
  243.                 mov     dx,cx
  244.                 shr     dx,1
  245.                 neg     dx
  246. MakeGridX:      mov     [bx],ax
  247.                 add     ax,si
  248.                 add     dx,di
  249.                 jl      SkipX
  250.                 sub     dx,WINSIZEX
  251.                 inc     ax
  252. SkipX:          add     bx,2
  253.                 loop    MakeGridX
  254.  
  255.                 mov     si,[YStart]             ; compute the GridY array.
  256.                 mov     di,[YStop]
  257.                 lea     bx,[GridY]
  258.                 mov     cx,WINSIZEY
  259.                 mov     ax,di
  260.                 sub     ax,si
  261.                 cwd
  262.                 div     cx
  263.                 xchg    si,ax
  264.                 mov     di,dx
  265.                 mov     dx,cx
  266.                 shr     dx,1
  267.                 neg     dx
  268. MakeGridY:      mov     [bx],ax
  269.                 add     ax,si
  270.                 add     dx,di
  271.                 jl      SkipY
  272.                 sub     dx,WINSIZEY
  273.                 inc     ax
  274. SkipY:          add     bx,2
  275.                 loop    MakeGridY
  276.  
  277.                 mov     dx,[PicSeg]
  278.                 mov     cx,ds
  279.                 mov     ax,0A000h
  280.                 mov     es,ax
  281.                 mov     di,WINPOSX+320*WINPOSY
  282.                 cld
  283.  
  284.  
  285.                 xor     bx,bx
  286. ZoomLoopY:      push    bx
  287.                 mov     ax,[GridY+bx]
  288.                 imul    ax,ax,MAXWIDTH
  289.                 xor     bx,bx
  290. ZoomLoopX:      mov     si,ax
  291.                 add     si,[GridX+bx]
  292.                 mov     ds,dx
  293.                 movsb
  294.                 mov     ds,cx
  295.                 add     bx,2
  296.                 cmp     bx,2*WINSIZEX
  297.                 jb      ZoomLoopX
  298.                 pop     bx
  299.                 add     di,MAXWIDTH-WINSIZEX
  300.                 add     bx,2
  301.                 cmp     bx,2*WINSIZEY
  302.                 jb      ZoomLoopY
  303.                 ret
  304.  
  305. ZoomBox         endp
  306.  
  307.  
  308. ;-----------------------------------------------------------------------------
  309. ; MandelZoom - Performs the demonstration. Because this routine is called
  310. ;   from a High-Level language the allocation and deallocation of memory
  311. ;   is done by the caller.
  312. ; In:
  313. ;   MemSegs - Array of NUMPICS segments of 64K to store the pictures.
  314. ;-----------------------------------------------------------------------------
  315.  
  316. MandelZoom      proc    MemSegs:dword
  317.  
  318.                 mov     ax,13h                  ; set VGA 320x200x256 mode.
  319.                 int     10h
  320.  
  321.                 call    SetPalette              ; Sets Color Palette
  322.  
  323.                 les     si,[MemSegs]            ; Creates the Mandelbrot
  324.                 mov     cx,NUMPICS              ; piccys into the virtual
  325.                 xor     bx,bx                   ; screens.
  326. MakePics:       pusha
  327.                 push    ds 
  328.                 push    es
  329.                 mov     eax,[bx+PicTable+0]     ; get fixedpoint X,Y,DX,DY.
  330.                 mov     edx,[bx+PicTable+4]
  331.                 mov     esi,[bx+PicTable+8]
  332.                 mov     edi,[bx+PicTable+12]    ; Draw Mandelbrot Set.
  333.                 call    DrawMandel,eax,edx,esi,edi,0A000h
  334.                 pop     es
  335.                 pop     ds
  336.                 popa
  337.  
  338.                 pusha                           ; Copy Picture:
  339.                 push    ds
  340.                 push    es
  341.                 mov     ax,0A000h               ; get screen segment
  342.                 mov     ds,ax
  343.                 mov     es,es:[si]              ; get vscreen segment
  344.                 xor     di,di
  345.                 xor     si,si
  346.                 mov     cx,32000                ; copy screen
  347.                 cld
  348.                 rep     movsw
  349.                 call    ClearScreen             ; clears screen
  350.                 pop     es
  351.                 pop     ds
  352.                 popa
  353.  
  354.                 add     si,2                    ; Next Picture Gap.
  355.                 add     bx,16
  356.                 loop    MakePics
  357.  
  358.                 call    BlackPalette            ; set Black Palette.
  359.  
  360. DemoLoop:
  361.                 mov     cx,NUMFRAMES            ; Zoom-In.
  362.                 xor     bx,bx
  363. ZoomIN:         call    WaitVRT
  364.                 push    bx
  365.                 push    cx
  366.                 les     si,[MemSegs]
  367.                 mov     ax,[bx+FrameTable+8]    ; PicNo.
  368.                 add     si,ax
  369.                 add     si,ax
  370.                 mov     cx,es:[si]              ; PicSeg.
  371.                 mov     ax,[bx+FrameTable+0]    ; XStart.
  372.                 mov     dx,[bx+FrameTable+2]    ; YStart.
  373.                 mov     si,[bx+FrameTable+4]    ; XStop.
  374.                 mov     di,[bx+FrameTable+6]    ; YStop.
  375.                 call    ZoomBox,ax,dx,si,di,cx
  376.                 pop     cx
  377.                 pop     bx
  378.                 test    bx,bx
  379.                 jne     DontFadeIn
  380.                 push    bx
  381.                 push    cx
  382.                 call    FadeInPalette
  383.                 pop     cx
  384.                 pop     bx
  385. DontFadeIn:     add     bx,10
  386.                 loop    ZoomIN
  387.  
  388.                 mov     cx,NUMFRAMES            ; Zoom-Out.
  389.                 mov     bx,10*NUMFRAMES-10
  390. ZoomOUT:        call    WaitVRT
  391.                 push    bx
  392.                 push    cx
  393.                 les     si,[MemSegs]
  394.                 mov     ax,[bx+FrameTable+8]    ; PicNo.
  395.                 add     si,ax
  396.                 add     si,ax
  397.                 mov     cx,es:[si]              ; PicSeg.
  398.                 mov     ax,[bx+FrameTable+0]    ; XStart.
  399.                 mov     dx,[bx+FrameTable+2]    ; YStart.
  400.                 mov     si,[bx+FrameTable+4]    ; XStop.
  401.                 mov     di,[bx+FrameTable+6]    ; YStop.
  402.                 call    ZoomBox,ax,dx,si,di,cx
  403.                 pop     cx
  404.                 pop     bx
  405.                 test    bx,bx
  406.                 jne     DontFadeOut
  407.                 push    bx
  408.                 push    cx
  409.                 call    FadeOutPalette
  410.                 pop     cx
  411.                 pop     bx
  412. DontFadeOut:    sub     bx,10
  413.                 loop    ZoomOUT
  414.  
  415.                 mov     ax,03h                  ; set VGA 80x25x16 mode.
  416.                 int     10h
  417.                 ret
  418.  
  419. MandelZoom      endp
  420.  
  421. ;-----------------------------------------------------------------------------
  422. ; Start - Startup Code called from DOS.
  423. ; In:
  424. ;   ES - Program Segment Prefix.
  425. ;-----------------------------------------------------------------------------
  426.  
  427. Start           proc
  428.                 local   PicSegs:word:NUMPICS
  429.  
  430.                 mov     ax,@Data
  431.                 mov     ds,ax
  432.                 mov     ax,ss                   ; shrink memory block.
  433.                 mov     bx,es
  434.                 sub     ax,bx
  435.                 mov     bx,sp
  436.                 shr     bx,4
  437.                 inc     bx
  438.                 add     bx,ax
  439.                 mov     ah,4Ah
  440.                 int     21h
  441.  
  442.                 lea     bx,[PicSegs]
  443.                 mov     cx,NUMPICS
  444. AllocLoop:      push    bx
  445.                 push    cx
  446.                 mov     ah,48h                  ; alloc 64000 bytes per
  447.                 mov     bx,4000                 ; picture.
  448.                 int     21h
  449.                 jc      Exit
  450.                 pop     cx
  451.                 pop     bx
  452.                 mov     ss:[bx],ax
  453.                 add     bx,2
  454.                 loop    AllocLoop
  455.  
  456.                 lea     bx,[PicSegs]            ; do demostration.
  457.                 call    MandelZoom,ss,bx
  458.  
  459.                 lea     bx,[PicSegs]
  460.                 mov     cx,NUMPICS              ; Free 64000 bytes
  461. FreeLoop:       push    bx                      ; per picture.
  462.                 push    cx
  463.                 mov     ah,49h
  464.                 mov     es,ss:[bx]
  465.                 int     21h
  466.                 pop     cx
  467.                 pop     bx
  468.                 add     bx,2
  469.                 loop    FreeLoop
  470.  
  471. Exit:           mov     ax,4C00h
  472.                 int     21h
  473.  
  474. Start           endp
  475.  
  476.                 end     Start
  477.