home *** CD-ROM | disk | FTP | other *** search
/ The Party 1994: Try This At Home / disk_image.bin / source / fakesrc / total.txt < prev    next >
Text File  |  1995-04-18  |  153KB  |  5,626 lines

  1. /* NOTE: This is just a complition of all the source code files. This file
  2.    can not be compiled. Use the original files instead! */
  3.  
  4. ;=============================================================================
  5. ; flag.asm - Runtime Flag Demostration.
  6. ;                                                   File created: 10-22-93
  7. ; Copyright (C) 1993, Carlos Hasan                 Last modified: 10-22-93
  8. ;
  9. ; Description:
  10. ;   This file implements a runtime flag movement using plasma like
  11. ;   sinus overlapping waves in the VGA 320x200x256 graphics mode.
  12. ;
  13. ; Portability:
  14. ;  Requires Turbo Assembler 3.2 or better to be assembler.
  15. ;  Dependent on the IBM PC 286 and the VGA graphics card.
  16. ;=============================================================================
  17.  
  18.         .model  small,pascal
  19.         .286
  20.  
  21.         dosseg                          ; used to link like
  22.         .stack  1024                    ; an standalone program.
  23.  
  24.         global  FlagDemo:proc
  25.  
  26. ;======================= Demo equates and data ===============================
  27.  
  28. TIMEOUT         equ     70 * 8                  ; at least 8 secs.
  29. BMPWIDTH        equ     160                     ; bitmap dimens.
  30. BMPHEIGHT       equ     96
  31. MAXWIDTH        equ     320                     ; screen dimens.
  32. MAXHEIGHT       equ     200
  33. XOFS            equ     80                      ; flag upper left
  34. YOFS            equ     30                      ; corner coordinates.
  35.  
  36.         .data
  37.  
  38. ; flag bitmap, palette and sinus wave tables.
  39. ; The bitmap is about 15K, but because it's highly compressed using
  40. ; any exepacker, it was included in the data segment avoiding the
  41. ; extra segment needed in the demo algorithms.
  42.  
  43.         include flagbmp.inc 
  44.  
  45. HWavPos         db      ?                       ; wave horiz and vert
  46. VWavPos         db      ?                       ; positions.
  47.  
  48. FadePalette     db      768 dup (?)             ; faded palette.
  49. Fade            db      ?                       ; fade level.
  50. Esckey          db      ?                       ; true if key pressed.
  51. Timer           dw      ?                       ; timer counter.
  52.  
  53. ;======================= Demo routines =======================================
  54.  
  55.         .code
  56.  
  57. ;-----------------------------------------------------------------------------
  58. ; WaitVRT - Waits the Vertical Retrace.
  59. ;-----------------------------------------------------------------------------
  60.  
  61. WaitVRT         proc near
  62.  
  63.         mov     dx,3DAh
  64. WaitVR1:        in      al,dx
  65.         test    al,8
  66.         jne     WaitVR1
  67. WaitVR2:        in      al,dx
  68.         test    al,8
  69.         je      WaitVR2
  70.         ret
  71.  
  72. WaitVRT         endp
  73.  
  74. ;-----------------------------------------------------------------------------
  75. ; SetPalette - set the CX entries of the VGA color palette.
  76. ; In:
  77. ;   DS:SI - Palette structure address.
  78. ;   CX    - Number of colors components.
  79. ;-----------------------------------------------------------------------------
  80.  
  81. SetPalette      proc near
  82.  
  83.         call    WaitVRT
  84.         mov     dx,3C8h
  85.         xor     al,al
  86.         out     dx,al
  87.         inc     dx
  88.         rep     outsb
  89.         ret
  90.  
  91. SetPalette      endp
  92.  
  93. ;-----------------------------------------------------------------------------
  94. ; PutFlag - Writes the next Flag Frame to the Screen.
  95. ;-----------------------------------------------------------------------------
  96.  
  97. PutFlag         proc near
  98.  
  99.         mov     ax,0A000h
  100.         mov     es,ax
  101.         add     [HWavPos],4             ; Incr Wave Positions.
  102.         add     [VWavPos],7
  103.         mov     dh,[HWavPos]            ; k = hwavpos.
  104.         mov     di,MAXWIDTH*YOFS+XOFS   ; p = screen offset.
  105.         lea     si,[Piccy]              ; q = piccy offset.
  106.         mov     cx,BMPWIDTH-16          ; for col=0 to W-16 do
  107.         xor     bh,bh
  108. ColLoop:        push    cx
  109.         push    si
  110.         push    di
  111.         mov     bl,dh
  112.         mov     dl,[VWave+bx]           ; x = vwave[k]
  113.         mov     al,[HWave+bx]           ; h = (x+hwave[k])/2
  114.         add     al,dl
  115.         rcr     al,1
  116.         mov     ah,BMPWIDTH             ; q= col+160*h
  117.         mul     ah
  118.         add     si,ax
  119.         mov     ah,[VWavPos]            ; l = vwavpos
  120.         mov     cx,BMPHEIGHT-16         ; for row=0 to H-16 do
  121. RowLoop:        mov     bl,ah
  122.         mov     bl,[VWave+bx]           ; v = (x+vwave[l])/2
  123.         add     bl,dl
  124.         rcr     bl,1
  125.         mov     al,[si+bx]              ; al = pic[si+v]+vwave[k+v]
  126.         add     bl,dh
  127.         mov     bl,[VWave+bx]
  128.         xor     bl,0Fh
  129.         add     al,bl
  130.         mov     es:[di],al              ; put pixel.
  131.         add     di,MAXWIDTH             ; p= p+320
  132.         add     si,BMPWIDTH             ; q= q+160
  133.         inc     ah                      ; l= l+1
  134.         loop    RowLoop
  135.         pop     di
  136.         pop     si
  137.         pop     cx
  138.         inc     dh                      ; k=k+1
  139.         inc     si                      ; q=q+1
  140.         inc     di                      ; p=p+1
  141.         test    di,1                    ; if odd(p) p=p+320
  142.         jne     ColBrk
  143.         add     di,MAXWIDTH
  144. ColBrk:         loop    ColLoop                 ; next col.
  145.         ret
  146.  
  147. PutFlag         endp
  148.  
  149. ;-----------------------------------------------------------------------------
  150. ; FlagDemo - Performs the demonstration.
  151. ; In:
  152. ;   DS - Data segment.
  153. ;-----------------------------------------------------------------------------
  154.  
  155. FlagDemo        proc
  156.  
  157.         pusha
  158.         push    ds
  159.         push    es
  160.  
  161.         mov     ax,0013h                ; set 320x200x256 mode.
  162.         int     10h
  163.  
  164.         mov     [Fade],0                ; setup variables.
  165.         mov     [EscKey],0
  166.         mov     [Timer],0
  167.  
  168.         mov     [HWavPos],0
  169.         mov     [VWavPos],0
  170.  
  171. FlagLoop:       cmp     [EscKey],0              ; change fade level.
  172.         jne     FadeOut
  173. FadeIn:         mov     bl,[Fade]
  174.         cmp     bl,64
  175.         jae     SkipFade
  176.         inc     [Fade]
  177.         jmp     FadeInOut
  178. FadeOut:        mov     bl,[Fade]
  179.         cmp     bl,0
  180.         jbe     FadeInOut
  181.         dec     [Fade]
  182.  
  183. FadeInOut:      lea     si,[Palette]            ; set faded palette.
  184.         lea     di,[FadePalette]
  185.         mov     cx,3*16*4
  186.         mov     ax,ds
  187.         mov     es,ax
  188.         cld
  189. FadeLoop:       lodsb
  190.         mul     bl
  191.         shr     ax,6
  192.         stosb
  193.         loop    FadeLoop
  194.  
  195. DoFade:         lea     si,[FadePalette]        ; ensures thats always
  196.         mov     cx,3*16*4               ; waits the VR per frame.
  197.         call    SetPalette
  198.         jmp     DoFlag
  199.  
  200. SkipFade:       call    WaitVRT
  201.  
  202. DoFlag:         call    PutFlag                 ; put the flag.
  203.  
  204.         mov     ah,1                    ; if any key pressed,
  205.         int     16h
  206.         jz      CheckTimer
  207.         mov     ah,0
  208.         int     16h
  209.         jmp     BeginFadeOut
  210.  
  211. CheckTimer:     inc     [Timer]                 ; or timeout,
  212.         cmp     [Timer],TIMEOUT
  213.         jb      CheckExit
  214.  
  215. BeginFadeOut:   inc     [EscKey]                ; then fade-out and exit.
  216.  
  217. CheckExit:      cmp     [Fade],0
  218.         je      FlagExit
  219.         jmp     FlagLoop
  220.  
  221. FlagExit:       mov     ax,0003h
  222.         int     10h
  223.  
  224.         pop     es
  225.         pop     ds
  226.         popa
  227.         ret
  228.  
  229. FlagDemo        endp
  230.  
  231.  
  232. ;-----------------------------------------------------------------------------
  233. ; Start - Startup code called from DOS.
  234. ; In:
  235. ;   DS - Program Segment Prefix.
  236. ;-----------------------------------------------------------------------------
  237.  
  238. Start           proc
  239.  
  240.         mov     ax,@Data
  241.         mov     ds,ax
  242.         call    FlagDemo
  243.         mov     ax,4C00h
  244.         int     21h
  245.  
  246. Start           endp
  247.  
  248.         end     Start
  249. ;=============================================================================
  250. ; mandel.asm - Mandelbrot Set calculation Routines.
  251. ;                                                    File created:  9-22-93
  252. ; Copyright (C) 1993, Carlos Hasan                  Last modified: 10-11-93
  253. ;
  254. ; Description:
  255. ;  This file implements the Mandelbrot Set fractal using a fast algorithm
  256. ;  based on the Fracint's Boundary trace method. The drawing is optimized
  257. ;  for using with VGA 320x200x256 graphics mode.
  258. ;
  259. ; Portability:
  260. ;  Requires Turbo Assembler 3.2 or better to be assembler.
  261. ;  Dependent on the IBM PC 386 or later microprocessor.
  262. ;=============================================================================
  263.  
  264.         .model  small,pascal
  265.         .386
  266.  
  267.         global  DrawMandel:proc
  268.  
  269. ;======================= Mandelbrot Routine ==================================
  270.  
  271. ;-----------------------------------------------------------------------------
  272. ; Equates for Mandelbrot Set calculation.
  273. ;-----------------------------------------------------------------------------
  274.  
  275. MAXITER         equ     150                     ; max iterations
  276. FUDGE           equ     24                      ; fudge factor
  277. BAILOUT         equ     4 shl FUDGE             ; bait out
  278. PERIODMASK      equ     0FFFF0000h              ; periodicy mask
  279.  
  280. ;-----------------------------------------------------------------------------
  281. ; Miscellaneus Data used for calculation.
  282. ;-----------------------------------------------------------------------------
  283.  
  284.         .data
  285.  
  286. SavedAnd        dw      ?
  287. SavedIncr       dw      ?
  288. SavedMask       dd      ?
  289. OldIter         dw      ?
  290. LinX            dd      ?
  291. LinY            dd      ?
  292. SavedX          dd      ?
  293. SavedY          dd      ?
  294.  
  295. ;-----------------------------------------------------------------------------
  296. ; CalcMand - Main Mandelbrot Set calculation routine.
  297. ; In:
  298. ;   ESI  - real part of the initial complex value.
  299. ;   EDI  - imaginary part of the initial complex value.
  300. ; Out:
  301. ;   AL   - Mandelbrot level.
  302. ; Modified:
  303. ;   EAX, EBX, ECX, EDX, ESI, EDI, Flags.
  304. ;-----------------------------------------------------------------------------
  305.  
  306.         .code
  307.  
  308. CalcMand        proc near
  309.  
  310.         mov     [SavedAnd],1            ; init periodicy check.
  311.         mov     [SavedIncr],1
  312.         mov     [SavedMask],1
  313.         mov     [SavedX],0FFFFFFFFh     ; values impossibles
  314.         mov     [SavedY],0FFFFFFFFh     ; for x and y.
  315.  
  316.         mov     [LinX],esi              ; linx = real
  317.         mov     [LinY],edi              ; liny = imag
  318.  
  319.         xor     esi,esi                 ; x = 0
  320.         xor     edi,edi                 ; y = 0
  321.  
  322.         mov     cx,MAXITER              ; iter = maxiter
  323.  
  324. MandLoop:       mov     eax,esi                 ; ebx = x*x
  325.         imul    esi
  326.         shrd    eax,edx,FUDGE
  327.         mov     ebx,eax
  328.  
  329.         mov     eax,edi                 ; ebx = y*y
  330.         imul    edi
  331.         shrd    eax,edx,FUDGE
  332.  
  333.         mov     edx,ebx                 ; edx = x*x + y*y
  334.         add     edx,eax
  335.         sub     ebx,eax                 ; ebx = x*x - y*y
  336.  
  337.         cmp     edx,BAILOUT             ; x*x + y*y > bailout?
  338.         jge     MandBreak               ; break.
  339.  
  340.         mov     eax,edi                 ; y = 2*x*y + liny
  341.         imul    esi
  342.         shrd    eax,edx,FUDGE-1
  343.         add     eax,[LinY]
  344.         mov     edi,eax
  345.  
  346.         add     ebx,[LinX]              ; x = x*x - y*y + linx
  347.         mov     esi,ebx
  348.  
  349.         cmp     [OldIter],cx            ; check periodicity.
  350.         jle     MandContinue
  351.  
  352.         mov     eax,esi
  353.         xor     eax,[SavedX]
  354.         test    eax,PERIODMASK
  355.         jne     CheckSave
  356.         mov     eax,edi
  357.         xor     eax,[SavedY]
  358.         test    eax,PERIODMASK
  359.         jne     CheckSave
  360.         xor     cx,cx
  361.         jmp     MandBreak
  362.  
  363. CheckSave:      test    cx,[SavedAnd]
  364.         jne     MandContinue
  365.         mov     [SavedX],esi
  366.         mov     [SavedY],edi
  367.         dec     [SavedIncr]
  368.         jne     MandContinue
  369.         stc
  370.         rcl     [SavedAnd],1
  371.         mov     [SavedIncr],4
  372.  
  373. MandContinue:   dec     cx
  374.         jne     MandLoop
  375.  
  376. MandBreak:      mov     ax,cx
  377.         mov     bx,cx
  378.         sub     bx,10
  379.         test    cx,cx
  380.         je      SetOldIter
  381.         mov     bx,MAXITER
  382. SetOldIter:     mov     [OldIter],bx
  383.         ret
  384.  
  385. CalcMand        endp
  386.  
  387.  
  388. ;=================== Boundary Trace Method (BTM) =============================
  389.  
  390. ;-----------------------------------------------------------------------------
  391. ; Equates for BTM into a 320x200x256 virtual screen.
  392. ;-----------------------------------------------------------------------------
  393.  
  394. MAXWIDTH        equ     320                     ; Virtual screen dimensions.
  395. MAXHEIGHT       equ     200
  396. XSTART          equ     0                       ; Virtual screen drawing
  397. XSTOP           equ     319                     ; window coordinates.
  398. YSTART          equ     0
  399. YSTOP           equ     199
  400. NORTH           equ     0                       ; Used for BTM algorithm.
  401. EAST            equ     1
  402. SOUTH           equ     2
  403. WEST            equ     3
  404. MAXINT          equ     7FFFh
  405.  
  406. ;-----------------------------------------------------------------------------
  407. ; Data used for BTM during plotting.
  408. ;-----------------------------------------------------------------------------
  409.  
  410.         .data
  411.  
  412. LeftX           dw      MAXHEIGHT dup (?)       ; array of left and right
  413. RightX          dw      MAXHEIGHT dup (?)       ; limits for poly filling.
  414. ComplexX        dd      MAXWIDTH  dup (?)       ; translate screen coords
  415. ComplexY        dd      MAXHEIGHT dup (?)       ; to complex coords.
  416. FirstX          dw      ?                       ; temporary variables used
  417. FirstY          dw      ?                       ; for BTM algorithm.
  418. Iters           dw      ?
  419. Color           db      ?
  420. Dir             db      ?
  421.  
  422. ;-----------------------------------------------------------------------------
  423. ; GetPixel - get the pixel color at specified location.
  424. ; In:
  425. ;   ES      - Virtual screen segment.
  426. ;   (SI,DI) - Pixel position.
  427. ; Out:
  428. ;   AL      - Pixel color.
  429. ; Modified:
  430. ;   BX, Flags.
  431. ;-----------------------------------------------------------------------------
  432.  
  433.         .code
  434.  
  435. GetPixel        macro
  436.  
  437.         mov     bx,di
  438.         imul    bx,MAXWIDTH
  439.         add     bx,si
  440.         mov     al,es:[bx]
  441.  
  442.         endm
  443.  
  444. ;-----------------------------------------------------------------------------
  445. ; PutPixel - put the pixel color at specified location.
  446. ; In:
  447. ;   ES      - Virtual screen segment.
  448. ;   (SI,DI) - Pixel position.
  449. ;   AL      - Pixel color.
  450. ; Modified:
  451. ;   BX, Flags.
  452. ;-----------------------------------------------------------------------------
  453.  
  454. PutPixel        macro
  455.  
  456.         mov     bx,di
  457.         imul    bx,MAXWIDTH
  458.         add     bx,si
  459.         mov     es:[bx],al
  460.  
  461.         endm
  462.  
  463. ;-----------------------------------------------------------------------------
  464. ; GetColor - get the pixel color using the MandelBrot Set routine or
  465. ;   the virtual screen if already painted.
  466. ; In:
  467. ;   ES       - Virtual screen segment.
  468. ;   (SI,DI)  - Pixel position.
  469. ; Out:
  470. ;   AL       - Pixel color.
  471. ; Modified:
  472. ;   EAX, EBX, ECX, EDX, Flags.
  473. ;-----------------------------------------------------------------------------
  474.  
  475. GetColor        proc near
  476.  
  477.         GetPixel
  478.         test    al,al
  479.         jne     ColorNonZero
  480.         push    si
  481.         push    di
  482.         shl     si,2
  483.         shl     di,2
  484.         mov     esi,[ComplexX+si]
  485.         mov     edi,[ComplexY+di]
  486.         call    CalcMand
  487.         pop     di
  488.         pop     si
  489.         inc     al
  490.         PutPixel                ; don't destroy AL.
  491. ColorNonZero:   ret
  492.  
  493. GetColor        endp
  494.  
  495. ;-----------------------------------------------------------------------------
  496. ; BoundTrace - Trace a boundary and fill it.
  497. ; In:
  498. ;   ES      - Virtual screen segment.
  499. ;   (SI,DI) - starting point inside of the boundary.
  500. ; Modified:
  501. ;   EAX, EBX, ECX, EDX, Flags.
  502. ;-----------------------------------------------------------------------------
  503.  
  504. BoundTrace      proc near
  505.  
  506.         mov     [FirstX],si
  507.         mov     [FirstY],di
  508.         call    GetColor
  509.         mov     [Color],al
  510.         mov     [Dir],EAST
  511.         mov     [Iters],0
  512.  
  513. BoundLoop:      mov     bx,di
  514.         shl     bx,1
  515.         cmp     si,[LeftX+bx]
  516.         jge     NotLess
  517.         mov     [LeftX+bx],si
  518. NotLess:        cmp     si,[RightX+bx]
  519.         jle     NotGreat
  520.         mov     [RightX+bx],si
  521. NotGreat:       mov     al,[Dir]
  522.         cmp     al,NORTH
  523.         je      GoNorth
  524.         cmp     al,EAST
  525.         je      GoEast
  526.         cmp     al,SOUTH
  527.         je      GoSouth
  528.         cmp     al,WEST
  529.         je      GoWest
  530.  
  531. GoNorth:        cmp     di,[FirstY]
  532.         jle     SetEast
  533.         dec     di
  534.         call    GetColor
  535.         inc     di
  536.         cmp     al,[Color]
  537.         jne     SetEast
  538.         dec     di
  539.         cmp     si,XSTART
  540.         jle     BoundContinue
  541.         dec     si
  542.         call    GetColor
  543.         inc     si
  544.         cmp     al,[Color]
  545.         jne     BoundContinue
  546.         dec     si
  547.         jmp     SetWest
  548.  
  549. GoEast:         cmp     si,XSTOP
  550.         jge     SetSouth
  551.         inc     si
  552.         call    GetColor
  553.         dec     si
  554.         cmp     al,[Color]
  555.         jne     SetSouth
  556.         inc     si
  557.         cmp     di,[FirstY]
  558.         jle     BoundContinue
  559.         dec     di
  560.         call    GetColor
  561.         inc     di
  562.         cmp     al,[Color]
  563.         jne     BoundContinue
  564.         dec     di
  565.         jmp     SetNorth
  566.  
  567. GoSouth:        cmp     di,YSTOP
  568.         jge     SetWest
  569.         inc     di
  570.         call    GetColor
  571.         dec     di
  572.         cmp     al,[Color]
  573.         jne     SetWest
  574.         inc     di
  575.         cmp     si,XSTOP
  576.         jge     BoundContinue
  577.         inc     si
  578.         call    GetColor
  579.         dec     si
  580.         cmp     al,[Color]
  581.         jne     BoundContinue
  582.         inc     si
  583.         jmp     SetEast
  584.  
  585. GoWest:         cmp     si,XSTART
  586.         jle     SetNorth
  587.         dec     si
  588.         call    GetColor
  589.         inc     si
  590.         cmp     al,[Color]
  591.         jne     SetNorth
  592.         dec     si
  593.         cmp     di,YSTOP
  594.         jge     BoundContinue
  595.         inc     di
  596.         call    GetColor
  597.         dec     di
  598.         cmp     al,[Color]
  599.         jne     BoundContinue
  600.         inc     di
  601.         jmp     SetSouth
  602.  
  603. SetNorth:       mov     [Dir],NORTH
  604.         jmp     BoundContinue
  605.  
  606. SetEast:        mov     [Dir],EAST
  607.         jmp     BoundContinue
  608.  
  609. SetSouth:       mov     [Dir],SOUTH
  610.         jmp     BoundContinue
  611.  
  612. SetWest:        mov     [Dir],WEST
  613.  
  614. BoundContinue:  inc     [Iters]
  615.         cmp     si,[FirstX]
  616.         jne     BoundLoop
  617.         cmp     di,[FirstY]
  618.         jne     BoundLoop
  619.  
  620.         cmp     [Iters],4
  621.         jl      BoundExit
  622.  
  623.         mov     si,[FirstY]
  624.         cld
  625. BoundForY:      mov     bx,si
  626.         shl     bx,1
  627.         mov     ax,[LeftX+bx]
  628.         mov     dx,[RightX+bx]
  629.         mov     [LeftX+bx],+MAXINT
  630.         mov     [RightX+bx],-MAXINT
  631.         cmp     ax,dx
  632.         jg      BoundExit
  633.         mov     cx,dx
  634.         sub     cx,ax
  635.         inc     cx
  636.         mov     di,si
  637.         imul    di,MAXWIDTH
  638.         add     di,ax
  639.         mov     al,[Color]
  640. ScanColor:      repne   scasb
  641.         jne     BoundNextY
  642.         jcxz    BoundNextY
  643. FillBlank:      mov     ah,es:[di]
  644.         test    ah,ah
  645.         jne     ScanColor
  646.         mov     es:[di],al
  647.         inc     di
  648.         dec     cx
  649.         jne     FillBlank
  650. BoundNextY:     inc     si
  651.         cmp     si,YSTOP
  652.         jle     BoundForY
  653.  
  654. BoundExit:      mov     si,[FirstX]
  655.         mov     di,[FirstY]
  656.         ret
  657.  
  658. BoundTrace      endp
  659.  
  660. ;-----------------------------------------------------------------------------
  661. ; DrawMandel - Draw the Mandelbrot Set into a virtual 320x200x256 screen.
  662. ; In:
  663. ;   (PosX,PosX)      - top left corner complex number.
  664. ;   (DeltaX,DeltaY)  - complex windows extends.
  665. ;   ScreenSeg        - Virtual screen segment.
  666. ;-----------------------------------------------------------------------------
  667.  
  668. DrawMandel      proc    PosX:dword,PosY:dword, \
  669.             DeltaX:dword,DeltaY:dword, ScreenSeg:word
  670.  
  671.         mov     ax,ds
  672.         mov     es,ax
  673.         cld
  674.  
  675.         mov     cx,MAXHEIGHT
  676.         lea     di,[LeftX]
  677.         mov     ax,+MAXINT
  678.         rep     stosw
  679.  
  680.         mov     cx,MAXHEIGHT
  681.         lea     di,[RightX]
  682.         mov     ax,-MAXINT
  683.         rep     stosw
  684.  
  685.         mov     ecx,XSTOP-XSTART
  686.         mov     eax,[DeltaX]
  687.         cdq
  688.         div     ecx
  689.         inc     cx
  690.         mov     edx,eax
  691.         add     eax,[PosX]
  692.         add     eax,[PosX]
  693.         sar     eax,1
  694.         lea     di,[ComplexX]
  695. MakeX:          stosd
  696.         add     eax,edx
  697.         loop    MakeX
  698.  
  699.         mov     ecx,YSTOP-YSTART
  700.         mov     eax,[DeltaY]
  701.         cdq
  702.         div     ecx
  703.         inc     cx
  704.         mov     edx,eax
  705.         add     eax,[PosY]
  706.         add     eax,[PosY]
  707.         sar     eax,1
  708.         lea     di,[ComplexY]
  709. MakeY:          stosd
  710.         add     eax,edx
  711.         loop    MakeY
  712.  
  713.         mov     ax,[ScreenSeg]
  714.         mov     es,ax
  715.         mov     cx,MAXWIDTH * MAXHEIGHT
  716.         xor     di,di
  717.         xor     ax,ax
  718.         rep     stosb
  719.  
  720.         mov     di,YSTART
  721. ForY:           mov     si,XSTART
  722. ForX:           GetPixel
  723.         test    al,al
  724.         jne     NextX
  725.         call    BoundTrace
  726. NextX:          inc     si
  727.         cmp     si,XSTOP
  728.         jle     ForX
  729. NextY:          inc     di
  730.         cmp     di,YSTOP
  731.         jle     ForY
  732.         ret
  733.  
  734. DrawMandel      endp
  735.  
  736.         end
  737. ;=============================================================================
  738. ; zoom.asm - Mandelbrot Set Zoom Demostration.
  739. ;                                                    File created: 10-11-93
  740. ; Copyright (C) 1993, Carlos Hasan                  Last modified: 11-21-93
  741. ;
  742. ; Description:
  743. ;  This file implements the Runtime MandelZoom demostration. Needs the
  744. ;  Mandelbrot Set calculation routines and the zoom-in path include file.
  745. ;
  746. ; Portability:
  747. ;  Requires Turbo Assembler 3.2 or better to be assembler.
  748. ;  Dependent on the IBM PC 386 and the VGA graphics card.
  749. ;
  750. ; Modifications:
  751. ;  10/22/93 - Startup Code.
  752. ;  11/21/93 - Now this thing Shows the Frame Creation.
  753. ;=============================================================================
  754.  
  755.         .model  small,pascal
  756.         .386
  757.  
  758.         dosseg                          ; used to link like
  759.         .stack  1024                    ; an standalone program.
  760.  
  761.         global  MandelZoom:proc
  762.         global  DrawMandel:proc         ; in MANDEL.ASM
  763.  
  764. ;===================== Demo Equates ==========================================
  765.  
  766. MAXWIDTH        equ     320                     ; VGA Screen Dimensions.
  767. MAXHEIGHT       equ     200
  768.  
  769. ;===================== Demo Data =============================================
  770.  
  771.         .data
  772.  
  773.         include ZoomPath.Inc            ; Zoom-In Information.
  774.                         ; and Color Palette.
  775.  
  776. GridX           dw      WINSIZEX dup (?)        ; Used to compute the
  777. GridY           dw      WINSIZEY dup (?)        ; Zoom-In Window.
  778.  
  779. ;===================== Demo Routines =========================================
  780.  
  781.         .code
  782.  
  783. ;-----------------------------------------------------------------------------
  784. ; WaitVRT - Waits the next VGA Vertical Retrace Period.
  785. ;-----------------------------------------------------------------------------
  786.  
  787. WaitVRT         proc near
  788.  
  789.         mov     dx,3DAh
  790. WaitVRT1:       in      al,dx
  791.         test    al,8
  792.         jz      WaitVRT1
  793. WaitVRT2:       in      al,dx
  794.         test    al,8
  795.         jnz     WaitVRT2
  796.         ret
  797.  
  798. WaitVRT         endp
  799.  
  800. ;-----------------------------------------------------------------------------
  801. ; BlackPalette - Set a Black Palette.
  802. ;-----------------------------------------------------------------------------
  803.  
  804. BlackPalette    proc near
  805.  
  806.         call    WaitVRT
  807.         mov     dx,3C8h
  808.         xor     al,al
  809.         out     dx,al
  810.         inc     dx
  811.         mov     cx,768
  812. BlackLoop:      out     dx,al
  813.         loop    BlackLoop
  814.         ret
  815.  
  816. BlackPalette    endp
  817.  
  818.  
  819. ;-----------------------------------------------------------------------------
  820. ; SetPalette - Sets the Color Palette.
  821. ;-----------------------------------------------------------------------------
  822.  
  823. SetPalette      proc near
  824.  
  825.         call    WaitVRT
  826.         mov     dx,3C8h
  827.         xor     al,al
  828.         out     dx,al
  829.         inc     dx
  830.         lea     si,[Palette]
  831.         mov     cx,768
  832.         rep     outsb
  833.         ret
  834.  
  835. SetPalette      endp
  836.  
  837. ;-----------------------------------------------------------------------------
  838. ; FadeInPalette - Fade-In the palette.
  839. ;-----------------------------------------------------------------------------
  840.  
  841. FadeInPalette   proc near
  842.  
  843.         xor     bx,bx
  844. FadeInLoop:     lea     si,[Palette]
  845.         mov     dx,3C8h
  846.         xor     al,al
  847.         out     dx,al
  848.         mov     cx,768
  849.         call    WaitVRT
  850.         mov     dx,3C9h
  851. FadeIn:         lodsb
  852.         mul     bl
  853.         mov     al,ah
  854.         out     dx,al
  855.         loop    FadeIn
  856.         add     bl,4
  857.         jnc     FadeInLoop
  858.         ret
  859.  
  860. FadeInPalette   endp
  861.  
  862.  
  863. ;-----------------------------------------------------------------------------
  864. ; FadeOutPalette - Fade-Out the palette.
  865. ;-----------------------------------------------------------------------------
  866.  
  867. FadeOutPalette  proc near
  868.  
  869.         mov     bl,252
  870. FadeOutLoop:    call    WaitVRT
  871.         mov     dx,3C8h
  872.         xor     al,al
  873.         out     dx,al
  874.         inc     dx
  875.         lea     si,[Palette]
  876.         mov     cx,768
  877. FadeOut:        lodsb
  878.         mul     bl
  879.         mov     al,ah
  880.         out     dx,al
  881.         loop    FadeOut
  882.         sub     bl,4
  883.         jnc     FadeOutLoop
  884.         ret
  885.  
  886. FadeOutPalette  endp
  887.  
  888.  
  889. ;-----------------------------------------------------------------------------
  890. ; ClearScreen - Clears the Video Screen using a Spray-like effect.
  891. ;-----------------------------------------------------------------------------
  892.  
  893. ClearScreen     proc near
  894.  
  895.         push    ds
  896.         push    es
  897.  
  898.         mov     ax,0A000h
  899.         mov     es,ax
  900.  
  901.         xor     cx,cx
  902. SprayLoop:      push    cx
  903.         xor     bx,bx
  904. SprayLine:      push    bx
  905.         mov     ah,cs:[RandTable+bx]
  906.         mov     bx,cx
  907.         mov     al,cs:[RandTable+bx]
  908.         mov     bx,ax
  909.         mov     di,ax
  910.         xor     al,al
  911.         mov     es:[di],al
  912.         pop     bx
  913.         inc     cl
  914.         inc     bl
  915.         jne     SprayLine
  916.         pop     cx
  917.         inc     cl
  918.         jne     SprayLoop
  919.  
  920.         pop     es
  921.         pop     ds
  922.         ret
  923.  
  924. RandTable label byte
  925.       db   83,   8,  18, 177,  13, 241, 149, 157
  926.       db   75, 248, 254,  23,  16,  66, 207,  31
  927.       db  211, 183,  80, 242, 218,  27,  15, 128
  928.       db   94,  98,   4,  36, 139, 110,  85, 230
  929.       db  212,  26,  12, 249, 169, 233, 200, 150
  930.       db   95, 114, 130, 167, 202, 187,  76, 145
  931.       db   62, 117, 115, 190, 209,  42, 185, 224
  932.       db  129, 104, 108, 192, 174, 137,  44,  41
  933.       db  141,  53, 179,  81, 181,  57, 147, 210
  934.       db   50, 134, 156, 125, 133, 126, 106, 162
  935.       db   20,  59,  84,   0, 151, 143, 101, 215
  936.       db   68, 246, 189, 197,  99, 213, 112, 144
  937.       db   28, 235, 240,  90, 154,  56, 138, 165
  938.       db   19, 166, 159,  92, 127, 208, 105, 118
  939.       db  119, 153, 191, 184,  87,  70,   9, 164
  940.       db   60, 252,  96,   3, 171,  38, 136,  14
  941.       db    7, 160,  71, 146, 102, 229, 227,  43
  942.       db  221, 182, 217,  30, 131, 219,  61, 180
  943.       db  195, 245, 109, 203,  24,  49, 170, 247
  944.       db   46, 148, 122, 250, 173, 107, 255, 194
  945.       db    6,  37,  93,  22, 168,  97, 193,   5
  946.       db   51, 223, 116,  86,   1,  89, 121, 243
  947.       db  140, 220,  39, 222,  65,  55,  17,  54
  948.       db  175, 206, 214, 155, 142, 163,  25, 188
  949.       db  178,  11, 204, 135, 201, 238,  79, 132
  950.       db  198,  40,  21,  45, 237, 253, 152,  74
  951.       db   32, 111,  52,  47, 236,   2, 176, 239
  952.       db  234,  58, 100,  91, 172,  73,  82, 205
  953.       db   34,  88,  78, 231, 232, 225,  48, 251
  954.       db   67, 123, 244,  29, 216,  64, 196,  69
  955.       db  199,  33,  72,  35,  10,  63, 161, 228
  956.       db  113, 158, 120, 103, 124, 186, 226,  77
  957.  
  958. ClearScreen   endp
  959.  
  960.  
  961. ;-----------------------------------------------------------------------------
  962. ; ZoomBox - Draws the Zoom Window using the precalculated Mandelbrot
  963. ;  pictures and coordinates in the ZoomPath include file.
  964. ;-----------------------------------------------------------------------------
  965.  
  966. ZoomBox         proc near XStart:word,YStart:word,XStop:word,YStop:word, \
  967.              PicSeg:word
  968.  
  969.         mov     si,[XStart]             ; compute the GridX array.
  970.         mov     di,[XStop]
  971.         lea     bx,[GridX]
  972.         mov     cx,WINSIZEX
  973.         mov     ax,di
  974.         sub     ax,si
  975.         cwd
  976.         div     cx
  977.         xchg    si,ax
  978.         mov     di,dx
  979.         mov     dx,cx
  980.         shr     dx,1
  981.         neg     dx
  982. MakeGridX:      mov     [bx],ax
  983.         add     ax,si
  984.         add     dx,di
  985.         jl      SkipX
  986.         sub     dx,WINSIZEX
  987.         inc     ax
  988. SkipX:          add     bx,2
  989.         loop    MakeGridX
  990.  
  991.         mov     si,[YStart]             ; compute the GridY array.
  992.         mov     di,[YStop]
  993.         lea     bx,[GridY]
  994.         mov     cx,WINSIZEY
  995.         mov     ax,di
  996.         sub     ax,si
  997.         cwd
  998.         div     cx
  999.         xchg    si,ax
  1000.         mov     di,dx
  1001.         mov     dx,cx
  1002.         shr     dx,1
  1003.         neg     dx
  1004. MakeGridY:      mov     [bx],ax
  1005.         add     ax,si
  1006.         add     dx,di
  1007.         jl      SkipY
  1008.         sub     dx,WINSIZEY
  1009.         inc     ax
  1010. SkipY:          add     bx,2
  1011.         loop    MakeGridY
  1012.  
  1013.         mov     dx,[PicSeg]
  1014.         mov     cx,ds
  1015.         mov     ax,0A000h
  1016.         mov     es,ax
  1017.         mov     di,WINPOSX+320*WINPOSY
  1018.         cld
  1019.  
  1020.  
  1021.         xor     bx,bx
  1022. ZoomLoopY:      push    bx
  1023.         mov     ax,[GridY+bx]
  1024.         imul    ax,ax,MAXWIDTH
  1025.         xor     bx,bx
  1026. ZoomLoopX:      mov     si,ax
  1027.         add     si,[GridX+bx]
  1028.         mov     ds,dx
  1029.         movsb
  1030.         mov     ds,cx
  1031.         add     bx,2
  1032.         cmp     bx,2*WINSIZEX
  1033.         jb      ZoomLoopX
  1034.         pop     bx
  1035.         add     di,MAXWIDTH-WINSIZEX
  1036.         add     bx,2
  1037.         cmp     bx,2*WINSIZEY
  1038.         jb      ZoomLoopY
  1039.         ret
  1040.  
  1041. ZoomBox         endp
  1042.  
  1043.  
  1044. ;-----------------------------------------------------------------------------
  1045. ; MandelZoom - Performs the demonstration. Because this routine is called
  1046. ;   from a High-Level language the allocation and deallocation of memory
  1047. ;   is done by the caller.
  1048. ; In:
  1049. ;   MemSegs - Array of NUMPICS segments of 64K to store the pictures.
  1050. ;-----------------------------------------------------------------------------
  1051.  
  1052. MandelZoom      proc    MemSegs:dword
  1053.  
  1054.         mov     ax,13h                  ; set VGA 320x200x256 mode.
  1055.         int     10h
  1056.  
  1057.         call    SetPalette              ; Sets Color Palette
  1058.  
  1059.         les     si,[MemSegs]            ; Creates the Mandelbrot
  1060.         mov     cx,NUMPICS              ; piccys into the virtual
  1061.         xor     bx,bx                   ; screens.
  1062. MakePics:       pusha
  1063.         push    ds 
  1064.         push    es
  1065.         mov     eax,[bx+PicTable+0]     ; get fixedpoint X,Y,DX,DY.
  1066.         mov     edx,[bx+PicTable+4]
  1067.         mov     esi,[bx+PicTable+8]
  1068.         mov     edi,[bx+PicTable+12]    ; Draw Mandelbrot Set.
  1069.         call    DrawMandel,eax,edx,esi,edi,0A000h
  1070.         pop     es
  1071.         pop     ds
  1072.         popa
  1073.  
  1074.         pusha                           ; Copy Picture:
  1075.         push    ds
  1076.         push    es
  1077.         mov     ax,0A000h               ; get screen segment
  1078.         mov     ds,ax
  1079.         mov     es,es:[si]              ; get vscreen segment
  1080.         xor     di,di
  1081.         xor     si,si
  1082.         mov     cx,32000                ; copy screen
  1083.         cld
  1084.         rep     movsw
  1085.         call    ClearScreen             ; clears screen
  1086.         pop     es
  1087.         pop     ds
  1088.         popa
  1089.  
  1090.         add     si,2                    ; Next Picture Gap.
  1091.         add     bx,16
  1092.         loop    MakePics
  1093.  
  1094.         call    BlackPalette            ; set Black Palette.
  1095.  
  1096. DemoLoop:
  1097.         mov     cx,NUMFRAMES            ; Zoom-In.
  1098.         xor     bx,bx
  1099. ZoomIN:         call    WaitVRT
  1100.         push    bx
  1101.         push    cx
  1102.         les     si,[MemSegs]
  1103.         mov     ax,[bx+FrameTable+8]    ; PicNo.
  1104.         add     si,ax
  1105.         add     si,ax
  1106.         mov     cx,es:[si]              ; PicSeg.
  1107.         mov     ax,[bx+FrameTable+0]    ; XStart.
  1108.         mov     dx,[bx+FrameTable+2]    ; YStart.
  1109.         mov     si,[bx+FrameTable+4]    ; XStop.
  1110.         mov     di,[bx+FrameTable+6]    ; YStop.
  1111.         call    ZoomBox,ax,dx,si,di,cx
  1112.         pop     cx
  1113.         pop     bx
  1114.         test    bx,bx
  1115.         jne     DontFadeIn
  1116.         push    bx
  1117.         push    cx
  1118.         call    FadeInPalette
  1119.         pop     cx
  1120.         pop     bx
  1121. DontFadeIn:     add     bx,10
  1122.         loop    ZoomIN
  1123.  
  1124.         mov     cx,NUMFRAMES            ; Zoom-Out.
  1125.         mov     bx,10*NUMFRAMES-10
  1126. ZoomOUT:        call    WaitVRT
  1127.         push    bx
  1128.         push    cx
  1129.         les     si,[MemSegs]
  1130.         mov     ax,[bx+FrameTable+8]    ; PicNo.
  1131.         add     si,ax
  1132.         add     si,ax
  1133.         mov     cx,es:[si]              ; PicSeg.
  1134.         mov     ax,[bx+FrameTable+0]    ; XStart.
  1135.         mov     dx,[bx+FrameTable+2]    ; YStart.
  1136.         mov     si,[bx+FrameTable+4]    ; XStop.
  1137.         mov     di,[bx+FrameTable+6]    ; YStop.
  1138.         call    ZoomBox,ax,dx,si,di,cx
  1139.         pop     cx
  1140.         pop     bx
  1141.         test    bx,bx
  1142.         jne     DontFadeOut
  1143.         push    bx
  1144.         push    cx
  1145.         call    FadeOutPalette
  1146.         pop     cx
  1147.         pop     bx
  1148. DontFadeOut:    sub     bx,10
  1149.         loop    ZoomOUT
  1150.  
  1151.         mov     ax,03h                  ; set VGA 80x25x16 mode.
  1152.         int     10h
  1153.         ret
  1154.  
  1155. MandelZoom      endp
  1156.  
  1157. ;-----------------------------------------------------------------------------
  1158. ; Start - Startup Code called from DOS.
  1159. ; In:
  1160. ;   ES - Program Segment Prefix.
  1161. ;-----------------------------------------------------------------------------
  1162.  
  1163. Start           proc
  1164.         local   PicSegs:word:NUMPICS
  1165.  
  1166.         mov     ax,@Data
  1167.         mov     ds,ax
  1168.         mov     ax,ss                   ; shrink memory block.
  1169.         mov     bx,es
  1170.         sub     ax,bx
  1171.         mov     bx,sp
  1172.         shr     bx,4
  1173.         inc     bx
  1174.         add     bx,ax
  1175.         mov     ah,4Ah
  1176.         int     21h
  1177.  
  1178.         lea     bx,[PicSegs]
  1179.         mov     cx,NUMPICS
  1180. AllocLoop:      push    bx
  1181.         push    cx
  1182.         mov     ah,48h                  ; alloc 64000 bytes per
  1183.         mov     bx,4000                 ; picture.
  1184.         int     21h
  1185.         jc      Exit
  1186.         pop     cx
  1187.         pop     bx
  1188.         mov     ss:[bx],ax
  1189.         add     bx,2
  1190.         loop    AllocLoop
  1191.  
  1192.         lea     bx,[PicSegs]            ; do demostration.
  1193.         call    MandelZoom,ss,bx
  1194.  
  1195.         lea     bx,[PicSegs]
  1196.         mov     cx,NUMPICS              ; Free 64000 bytes
  1197. FreeLoop:       push    bx                      ; per picture.
  1198.         push    cx
  1199.         mov     ah,49h
  1200.         mov     es,ss:[bx]
  1201.         int     21h
  1202.         pop     cx
  1203.         pop     bx
  1204.         add     bx,2
  1205.         loop    FreeLoop
  1206.  
  1207. Exit:           mov     ax,4C00h
  1208.         int     21h
  1209.  
  1210. Start           endp
  1211.  
  1212.         end     Start
  1213. ;=============================================================================
  1214. ; flame.asm - Plasma-Like Flames Demo.
  1215. ;                                                    File created: 11/22/93
  1216. ; Copyright (c) 1993, Carlos Hasan                  Last modified: 11/22/93
  1217. ;
  1218. ; Description:
  1219. ;  Plasma Like Flames effect based on Vangelis Fire Code.
  1220. ;
  1221. ; Portability:
  1222. ;  Requires Turbo Assembler 3.2 or later to be assembled.
  1223. ;  Dependant on the IBM PC 286 or better processor.
  1224. ;=============================================================================
  1225.  
  1226.     ideal
  1227.     model   small
  1228.     jumps
  1229.     p286
  1230.  
  1231.     dosseg
  1232.     stack   1024
  1233.     ends
  1234.  
  1235.     global  FontFAR:byte            ; FLAMES.FNT linked file.
  1236.  
  1237. ;=========================== VLA Font Header =================================
  1238.  
  1239. struc   FontHeader
  1240.   Magic   db   "VGACH"                  ; Font Signature
  1241.   First   db   ?                        ; First Char
  1242.   Width   db   ?                        ; Font Width
  1243.   Height  db   ?                        ; Font Height
  1244.   Total   db   ?                        ; Number of Chars
  1245. ends    FontHeader
  1246.  
  1247. ;======================== Equates and Data Segment ===========================
  1248.  
  1249. TIMEOUT   equ  70*50                    ; At Least 50 secs
  1250. MESGSPEED equ  20                       ; Message Speed in VR Ticks
  1251. FLSEED    equ  4                        ; Initial Flames Seed
  1252. FLBLANK   equ  100                      ; Ending Flames Seed (Blank Screen)
  1253. XDOTS     equ  80                       ; VGA Screen Dimensions
  1254. YDOTS     equ  80
  1255. HIDDEN    equ  8                        ; Number of Hidden Working Lines
  1256.  
  1257.     dataseg
  1258.  
  1259. label   Palette byte                    ; Flames RGB Palette:
  1260.     I=0                             ; black to blue
  1261.     rept 8
  1262.     db   0,0,2*I
  1263.     I=I+1
  1264.     endm
  1265.     I=0                             ; blue to darkred
  1266.     rept 8
  1267.     db   2*I,0,16-2*I
  1268.     I=I+1
  1269.     endm
  1270.     I=0                             ; darkred to lightred
  1271.     rept 24
  1272.     db   16+47*I/24,0,0
  1273.     I=I+1
  1274.     endm
  1275.     I=0                             ; lighred to yellow
  1276.     rept 32
  1277.     db   63,31*I/16,0
  1278.     I=I+1
  1279.     endm
  1280.     I=0                             ; yellow to white
  1281.     rept 24
  1282.     db   63,63,21*I/8
  1283.     I=I+1
  1284.     endm
  1285.     rept 160                        ; white
  1286.     db   63,63,63
  1287.     endm
  1288.  
  1289. Frame        dw   XDOTS*(YDOTS+HIDDEN) dup(?)  ; Flames Frame Buffer
  1290. Seed         dw   1234h                 ; Random Seed
  1291. FontDataOfs  dw   ?                     ; Font Data Address
  1292. FontDataSeg  dw   ?
  1293. FontWidths   db   256 dup (?)           ; Font Char Widths
  1294. FontFirst    db   ?                     ; Font First Char
  1295. FontWidth    db   ?                     ; Font Max Width
  1296. FontHeight   db   ?                     ; Font Height
  1297. FontSize     dw   ?                     ; Font BitMap Size (=Width*Height)
  1298.  
  1299. MesgOff      dw   offset TheMessage     ; Message Offset
  1300. TheMessage   db   "     FAKE DEMO  CODED BY PELUSA  MUSIC BY NECROS"
  1301.          db   "     GREETS GO TO ALL THE PC DEMO PEOPLE..."
  1302.          db   "     THANKS FOR WATCHING THIS LAME THING..."
  1303.          db   "     SEEING YA........              "
  1304.          db   0
  1305.  
  1306.  
  1307. ;============================ Code Segment ===================================
  1308.  
  1309.     codeseg
  1310.  
  1311. ;-----------------------------------------------------------------------------
  1312. ; SetModeX - Sets VGA Tweaked Mode 80x80x256.
  1313. ;-----------------------------------------------------------------------------
  1314.  
  1315. proc    SetModeX
  1316.     mov     ax,0013h                ; Set VGA Linear 320x200x256
  1317.     int     10h
  1318.     mov     dx,3C4h                 ; Disable Chain-Four
  1319.     mov     ax,0604h
  1320.     out     dx,ax
  1321.     mov     dx,3C4h                 ; Enable Write to All Four Planes
  1322.     mov     ax,0F02h
  1323.     out     dx,ax
  1324.     mov     ax,0A000h               ; Clear Display Memory
  1325.     mov     es,ax
  1326.     xor     di,di
  1327.     xor     ax,ax
  1328.     mov     cx,8000h
  1329.     cld
  1330.     rep     stosw
  1331.     mov     dx,3D4h                 ; Reprogram CRT Controller:
  1332.     mov     ax,00014h               ; turn off dword mode
  1333.     out     dx,ax
  1334.     mov     ax,0e317h               ; turn on byte mode
  1335.     out     dx,ax
  1336.     mov     ax,00409h               ; cell height
  1337.     out     dx,ax
  1338.     ret
  1339. endp    SetModeX
  1340.  
  1341. ;-----------------------------------------------------------------------------
  1342. ; WaitVR - Waits Vertical Retrace.
  1343. ;-----------------------------------------------------------------------------
  1344.  
  1345. proc    WaitVR
  1346.     mov     dx,3DAh
  1347. WaitStartVR:
  1348.     in      al,dx
  1349.     test    al,8
  1350.     je      WaitStartVR
  1351. WaitEndVR:
  1352.     in      al,dx
  1353.     test    al,8
  1354.     jne     WaitEndVR
  1355.     ret
  1356. endp    WaitVR
  1357.  
  1358. ;-----------------------------------------------------------------------------
  1359. ; LoadFont - Loads the VLA font.
  1360. ;-----------------------------------------------------------------------------
  1361.  
  1362. proc    LoadFont
  1363.     mov     ax,SEG FontFAR          ; Load Font File Address
  1364.     mov     es,ax
  1365.     mov     [FontDataSeg],ax
  1366.     mov     [FontDataOfs],Size FontHeader
  1367.     mov     al,[es:FontHeader.First] ; Get Font First Char
  1368.     mov     [FontFirst],al
  1369.     mov     al,[es:FontHeader.Width] ; Get Font Data Size
  1370.     mov     ah,[es:FontHeader.Height]
  1371.     mov     [FontWidth],al
  1372.     mov     [FontHeight],ah
  1373.     mul     ah
  1374.     mov     [FontSize],ax
  1375.     mov     dl,[es:FontHeader.Total]
  1376.     xor     dh,dh
  1377.     mul     dx
  1378.     add     ax,Size FontHeader      ; Copy Font Widths.
  1379.     mov     si,ax
  1380.     xor     di,di
  1381.     mov     cl,[es:FontHeader.Total]
  1382.     xor     ch,ch
  1383. CopyWidths:
  1384.     mov     al,[es:si]
  1385.     mov     [FontWidths+di],al
  1386.     inc     si
  1387.     inc     di
  1388.     loop    CopyWidths
  1389.     ret
  1390. endp    LoadFont
  1391.  
  1392. ;-----------------------------------------------------------------------------
  1393. ; DrawChar - Draw a Font Char.
  1394. ; In:
  1395. ;  AL = Character Code.
  1396. ;  ES:DI = Frame Screen Address.
  1397. ;-----------------------------------------------------------------------------
  1398.  
  1399. proc    DrawChar
  1400.     sub     al,[FontFirst]          ; Get Char BitMap Offset
  1401.     xor     ah,ah
  1402.     mov     bx,ax
  1403.     mul     [FontSize]
  1404.     add     ax,[FontDataOfs]        ; si = char offset
  1405.     mov     si,ax
  1406.     mov     dl,[FontWidths+bx]      ; dx = char width
  1407.     xor     dh,dh
  1408.     mov     cl,[FontHeight]         ; cx = char height
  1409.     xor     ch,ch
  1410.     mov     al,[FontWidth]          ; bp = font max width
  1411.     xor     ah,ah
  1412.     mov     bp,ax
  1413.  
  1414.     mov     ax,XDOTS                ; Draw on Screen Center
  1415.     sub     ax,dx
  1416.     shr     ax,1
  1417.     shl     ax,1
  1418.     add     di,XDOTS*(16+YDOTS)
  1419.     add     di,ax
  1420.  
  1421.     push    ds                      ; ds = font data segment
  1422.     mov     ds,[FontDataSeg]
  1423. DrawCharLoop:
  1424.     push    cx
  1425.     push    si
  1426.     push    di
  1427.     xor     ah,ah
  1428. DrawPlane1:
  1429.     mov     al,[ds:si]
  1430.     test    al,al
  1431.     je      SkipColor
  1432.     mov     al,0FFh
  1433.     mov     [es:di],ax
  1434. SkipColor:
  1435.     add     si,bp
  1436.     add     di,XDOTS*2
  1437.     loop    DrawPlane1
  1438.     pop     di
  1439.     pop     si
  1440.     pop     cx
  1441.     inc     si
  1442.     add     di,2
  1443.     dec     dx
  1444.     jg      DrawCharLoop
  1445.     pop     ds
  1446.     ret
  1447. endp    DrawChar
  1448.  
  1449. ;-----------------------------------------------------------------------------
  1450. ; DrawMesg - Draws the Next Message on the Screen.
  1451. ;-----------------------------------------------------------------------------
  1452.  
  1453. proc    DrawMesg
  1454.     pusha
  1455.     push    es
  1456.     mov     ax,ds                   ; Loads Frame Area Address
  1457.     mov     es,ax
  1458.     lea     di,[Frame] 
  1459.     cld
  1460.     mov     si,[MesgOff]
  1461.     lodsb
  1462.     test    al,al
  1463.     stc
  1464.     je      DrawMesgExit
  1465.     mov     [MesgOff],si
  1466.     call    DrawChar
  1467.     clc
  1468. DrawMesgExit:
  1469.     pop     es
  1470.     popa
  1471.     ret
  1472. endp    DrawMesg
  1473.  
  1474. ;-----------------------------------------------------------------------------
  1475. ; Random - Returns a random number of 16 bits.
  1476. ;-----------------------------------------------------------------------------
  1477.  
  1478. proc    Random
  1479.     mov     ax,[Seed]
  1480.     imul    ax,8905h
  1481.     inc     ax
  1482.     mov     [Seed],ax
  1483.     ret
  1484. endp    Random
  1485.  
  1486. ;-----------------------------------------------------------------------------
  1487. ; Flames - Flames Like Screen Animation.
  1488. ;-----------------------------------------------------------------------------
  1489.  
  1490. proc    Flames
  1491.     pusha
  1492.     push    ds
  1493.     push    es
  1494.  
  1495.     call    SetModeX                ; Sets VGA 80x80x256 graphics mode
  1496.  
  1497.     call    LoadFont
  1498.     mov     [MesgOff],offset TheMessage
  1499.  
  1500.     call    WaitVR
  1501.     lea     si,[Palette]            ; Sets Color Palette
  1502.     mov     cx,768
  1503.     mov     dx,3C8h
  1504.     xor     al,al
  1505.     out     dx,al
  1506.     inc     dx
  1507.     cld
  1508.     rep     outsb
  1509.     mov     ax,ds                   ; Clears Frame Buffer
  1510.     mov     es,ax
  1511.     lea     di,[Frame]
  1512.     mov     cx,XDOTS*(YDOTS+HIDDEN)
  1513.     xor     ax,ax
  1514.     rep     stosw
  1515.     mov     ax,0A000h               ; Set Display Memory Segment
  1516.     mov     es,ax
  1517.     mov     bx,FLSEED               ; Loads Flames Seed Factor
  1518.     xor     bp,bp                   ; Start Timer Counter
  1519.      
  1520. FlamesLoop:
  1521.     inc     bp                      ; Increase Timer
  1522.     call    WaitVR                  ; Wait Vertical Retrace
  1523.     lea     si,[Frame]              ; Write Frame to the Screen
  1524.     xor     di,di
  1525.     mov     cx,XDOTS*YDOTS/2
  1526. WriteFrameLoop:
  1527.     lodsw
  1528.     mov     dl,al
  1529.     lodsw
  1530.     mov     dh,al
  1531.     mov     ax,dx
  1532.     stosw
  1533.     loop    WriteFrameLoop
  1534.  
  1535.     cmp     bp,TIMEOUT              ; Don't Draw Message while
  1536.     jae     DontDrawMesg            ; Fading out the Flames.
  1537.     mov     ax,bp
  1538.     xor     dx,dx
  1539.     mov     cx,MESGSPEED
  1540.     div     cx
  1541.     test    dx,dx                   ; Draws Messages...
  1542.     jne     DontDrawMesg
  1543.     call    DrawMesg
  1544.     jnc     DontDrawMesg            ; If no more message text,
  1545.     mov     bp,TIMEOUT              ; Start fading out...
  1546. DontDrawMesg:
  1547.  
  1548.     mov     cx,XDOTS*(YDOTS+HIDDEN-2) ; Transform Upper Frame Lines
  1549.     lea     si,[Frame+2*XDOTS]
  1550. FlamesTransform:
  1551.     mov     ax,[ds:si-2]            ; Sets Pixel at (X,Y) like
  1552.     add     ax,[ds:si+0]            ; the average of the near four
  1553.     add     ax,[ds:si+2]            ; pixels below it:
  1554.     add     ax,[ds:si+2*XDOTS]      ; P(X,Y) = (P(X-1,Y+1)+P(X,Y+1)+
  1555.     sub     ax,bx                   ;   P(X+1,Y+1)+P(X,Y+2)-Seed)/4
  1556.     sar     ax,2
  1557.     jge     FlameNotTooLow
  1558.     xor     ax,ax
  1559. FlameNotTooLow:
  1560.     mov     [ds:si-2*XDOTS],ax
  1561.     add     si,2
  1562.     loop    FlamesTransform
  1563.  
  1564.     ; Sets New Random Bottom Flames with Colors from 0 to 127.
  1565.     lea     si,[Frame+2*XDOTS*(YDOTS+HIDDEN-2)]
  1566.     mov     cx,XDOTS
  1567.     xor     dx,dx
  1568. RandomFlames:
  1569.     call    Random                  ; Use Random to Create a New
  1570.     test    ax,ax                   ; Flames Bottom Lines
  1571.     js      NotNewColor
  1572.     call    Random
  1573.     mov     dl,al
  1574.     and     dl,7Fh
  1575. NotNewColor:
  1576.     mov     [ds:si],dx
  1577.     mov     [ds:si+2*XDOTS],dx
  1578.     add     si,2
  1579.     loop    RandomFlames
  1580.     mov     ah,1                    ; or Any Key Pressed?
  1581.     int     16h                     
  1582.     je      CheckTimer
  1583.     mov     ah,0
  1584.     int     16h
  1585.     mov     bp,TIMEOUT
  1586. CheckTimer:
  1587.     cmp     bp,TIMEOUT              ; Timeout?
  1588.     jb      FlamesLoop
  1589. DecreaseFlames:
  1590.     inc     bx                      ; Increase Flames Seed
  1591.     cmp     bx,FLBLANK              ; (makes flames more low)
  1592.     jbe     FlamesLoop
  1593. FlamesExit:
  1594.     mov     ax,0003h                ; Set Text Mode 80x25x16
  1595.     int     10h
  1596.     pop     es
  1597.     pop     ds
  1598.     popa
  1599.     ret
  1600. endp    Flames
  1601.  
  1602. ;-----------------------------------------------------------------------------
  1603. ; Start - Startup code called from DOS.
  1604. ;-----------------------------------------------------------------------------
  1605.  
  1606. proc    Start
  1607.     mov     ax,@Data                ; Set DS Segment
  1608.     mov     ds,ax
  1609.     mov     bx,ss                   ; Shrink Program Segment
  1610.     mov     ax,es
  1611.     sub     bx,ax
  1612.     mov     ax,sp
  1613.     shr     ax,4
  1614.     inc     ax
  1615.     add     bx,ax
  1616.     mov     ah,4Ah
  1617.     call    Flames                  ; Do Flames Demo
  1618.     mov     ax,4C00h
  1619.     int     21h                     ; Exit to DOS.
  1620. endp    Start
  1621.  
  1622.     end     Start
  1623. ;=============================================================================
  1624. ; scrl.asm - Simple Horizontal Scroller.
  1625. ;                                                   File created: 11/21/93
  1626. ; Copyright (c) 1993, Carlos Hasan                 Last modified: 11/21/93
  1627. ;
  1628. ; Description:
  1629. ;  Just a simple scroller in VGA ModeX and an external proportional
  1630. ; font file in VLA chars format. Mainly based on VLA scrollers.
  1631. ;
  1632. ; Dependency:
  1633. ;  Requires Turbo Assembler 3.2 or later to be assembled.
  1634. ;  Dependant on the IBM PC 286 or better processor.
  1635. ;=============================================================================
  1636.  
  1637.     ideal
  1638.     model   small,pascal
  1639.     jumps
  1640.     p286
  1641.  
  1642.     dosseg
  1643.     stack   1024
  1644.     ends
  1645.  
  1646. IFDEF LinkFont
  1647.     global  FontFAR:byte            ; SCRL.FNT linked file.
  1648. ENDIF
  1649.  
  1650. ;=========================== VLA Font Header =================================
  1651.  
  1652. struc   FontHeader
  1653.   Magic   db   "VGACH"                  ; Font Signature
  1654.   First   db   ?                        ; First Char
  1655.   Width   db   ?                        ; Font Width
  1656.   Height  db   ?                        ; Font Height
  1657.   Total   db   ?                        ; Number of Chars
  1658. ends    FontHeader
  1659.  
  1660. ;=========================== Data Segment ====================================
  1661.  
  1662.     dataseg
  1663.  
  1664. SCREENWIDTH     equ  (2*320+8)          ; Logical Screen Width
  1665.                     ; Enough Space for Double-Window
  1666.                     ; and the working hidden area
  1667. SCROLLROW       equ  180                ; Scroller Window Start Row.
  1668.  
  1669. WinOffs         dw   ?                  ; Window Offset
  1670. CharOffs        dw   ?                  ; Char BitMap Offset
  1671. MesgOffs        dw   ?                  ; Ascii-Message Offset
  1672. FontHead        FontHeader ?            ; Font Header
  1673. CharColumn      db   ?                  ; Cur Char Column
  1674. FontFirst       db   ?                  ; Font First Char
  1675. FontWidth       db   ?                  ; Font Max Width
  1676. FontHeight      db   ?                  ; Font Height
  1677. FontDataOfs     dw   ?                  ; Font Data Offset
  1678. FontDataSeg     dw   ?                  ; Font Data Segment
  1679. FontWidths      db   256 dup(?)         ; Font Width Table
  1680. FontSize        dw   ?                  ; Font Char Size (Width*Height)
  1681.  
  1682. IFNDEF LinkFont
  1683. FontFileName    db   "SCRL.FNT",0       ; Font File Name
  1684. ENDIF
  1685.  
  1686. TheMessage      db   " ... Hello out there ... "
  1687.         db   "                        "
  1688.         db   " ... I am PELUSA from Chile ... "
  1689.         db   "                        "
  1690.         db   " ... Just a simple scroller... "
  1691.         db   "                        "
  1692.         db   " ... only useful to say that it's the FAKE demo ... "
  1693.         db   "                        "
  1694.         db   " ... you probably could have guessed that ... "
  1695.         db   "                        "
  1696.         db   " ... I hate scrollers because i have nothing to say..."
  1697.         db   "                        "
  1698.         db   " ... now enjoy the rest of this LAME thing ... "
  1699.         db   "                                    ",0
  1700.  
  1701.     codeseg
  1702.  
  1703. ;-----------------------------------------------------------------------------
  1704. ; SetModeX - Sets the VGA in Tweaked ModeX 320x400x256.
  1705. ;-----------------------------------------------------------------------------
  1706.  
  1707. proc    SetModeX
  1708.     mov     ax,0013h                ; Sets VGA linear 320x200x256
  1709.     int     10h
  1710.     mov     dx,3C4h                 ; Disable Chain-Four
  1711.     mov     ax,0604h
  1712.     out     dx,ax
  1713.     mov     dx,3C4h                 ; Enable Write to All Four Planes
  1714.     mov     ax,0F02h
  1715.     out     dx,ax
  1716.     mov     ax,0A000h               ; Clear Display Memory
  1717.     mov     es,ax
  1718.     xor     di,di
  1719.     xor     ax,ax
  1720.     mov     cx,8000h
  1721.     cld
  1722.     rep     stosw
  1723.     mov     dx,3D4h                 ; Reprogram CRT Controller:
  1724.     mov     ax,00014h               ; turn off dword mode
  1725.     out     dx,ax
  1726.     mov     ax,0e317h               ; turn on byte mode
  1727.     out     dx,ax
  1728.     mov     ax,00009h               ; cell height
  1729.     out     dx,ax
  1730.     mov     dx,3D4h                 ; Sets Logical Screen Width
  1731.     mov     al,13h
  1732.     mov     ah,SCREENWIDTH/8
  1733.     out     dx,ax
  1734.     ret
  1735. endp    SetModeX
  1736.  
  1737. ;-----------------------------------------------------------------------------
  1738. ; WaitVR - Waits the Next VGA Vertical Retrace Ending.
  1739. ;-----------------------------------------------------------------------------
  1740.  
  1741. proc    WaitVR
  1742.     mov     dx,3DAh
  1743. WaitStartVR:
  1744.     in      al,dx
  1745.     test    al,8
  1746.     je      WaitStartVR
  1747. WaitEndVR:
  1748.     in      al,dx
  1749.     test    al,8
  1750.     jne     WaitEndVR
  1751.     ret
  1752. endp    WaitVR
  1753.  
  1754. ;-----------------------------------------------------------------------------
  1755. ; InitScroll - Initializes the Scroller Variables.
  1756. ; Out:
  1757. ;  CF=1 if function was not successful.
  1758. ;  CF=0 if function was successful.
  1759. ;-----------------------------------------------------------------------------
  1760.  
  1761. proc    InitScroll
  1762.     mov     [WinOffs],0             ; Start Window Column
  1763.     mov     [CharColumn],0          ; Start with a ZeroWidth Char
  1764.     mov     [CharOffs],0            ; ZeroWidth Char BitMap Address
  1765.     lea     ax,[TheMessage]         ; Sets Message Address
  1766.     mov     [MesgOffs],ax
  1767.     call    LoadFont                ; Load Font Data
  1768.     ret
  1769. endp    InitScroll
  1770.  
  1771. ;-----------------------------------------------------------------------------
  1772. ; DoneScroll - Done Scroller Variables.
  1773. ;-----------------------------------------------------------------------------
  1774.  
  1775. proc    DoneScroll
  1776. IFNDEF LinkFont
  1777.     mov     es,[FontDataSeg]        ; Free Font Data Segment
  1778.     mov     ah,49h
  1779.     int     21h
  1780. ENDIF
  1781.     ret
  1782. endp    DoneScroll
  1783.  
  1784. ;-----------------------------------------------------------------------------
  1785. ; LoadFont - Loads a New VGA Font.
  1786. ; Out:
  1787. ;  CF=1 if function was not successful.
  1788. ;  CF=0 if function was successful.
  1789. ;-----------------------------------------------------------------------------
  1790.  
  1791. proc    LoadFont
  1792.  
  1793. IFDEF LinkFont
  1794.     mov     ax,SEG FontFAR          ; Load Font File Address
  1795.     mov     es,ax
  1796.     mov     [FontDataSeg],ax
  1797.     mov     [FontDataOfs],Size FontHeader
  1798.     mov     al,[es:FontHeader.First] ; Get Font First Char
  1799.     mov     [FontFirst],al
  1800.     mov     al,[es:FontHeader.Width] ; Get Font Data Size
  1801.     mov     ah,[es:FontHeader.Height]
  1802.     mov     [FontWidth],al
  1803.     mov     [FontHeight],ah
  1804.     mul     ah
  1805.     mov     [FontSize],ax
  1806.     mov     dl,[es:FontHeader.Total]
  1807.     xor     dh,dh
  1808.     mul     dx
  1809.     add     ax,Size FontHeader      ; Copy Font Widths.
  1810.     mov     si,ax
  1811.     xor     di,di
  1812.     mov     cl,[es:FontHeader.Total]
  1813.     xor     ch,ch
  1814. CopyWidths:
  1815.     mov     al,[es:si]
  1816.     mov     [FontWidths+di],al
  1817.     inc     si
  1818.     inc     di
  1819.     loop    CopyWidths
  1820. ELSE
  1821.     mov     [FontDataSeg],0
  1822.     mov     ax,3D00h                ; Open Font File
  1823.     lea     dx,[FontFileName]
  1824.     int     21h
  1825.     jc      LoadFontExit
  1826.     mov     bx,ax
  1827.     mov     ah,3Fh                  ; Read Font Header
  1828.     lea     dx,[FontHead]
  1829.     mov     cx,Size FontHeader
  1830.     int     21h
  1831.     jc      LoadFontExit
  1832.     mov     al,[FontHead.First]     ; Get Font First Char
  1833.     mov     [FontFirst],al
  1834.     mov     al,[FontHead.Width]     ; Get Font Data Size
  1835.     mov     ah,[FontHead.Height]
  1836.     mov     [FontWidth],al
  1837.     mov     [FontHeight],ah
  1838.     mul     ah
  1839.     mov     [FontSize],ax
  1840.     mov     dl,[FontHead.Total]
  1841.     xor     dh,dh
  1842.     mul     dx
  1843.     push    ax
  1844.     push    bx                      ; Alloc Space for Font Data
  1845.     mov     bx,ax
  1846.     shr     bx,4
  1847.     inc     bx
  1848.     mov     ah,48h
  1849.     int     21h
  1850.     pop     bx
  1851.     pop     cx
  1852.     jc      LoadFontExit
  1853.     push    ds                      ; Read Font Data
  1854.     mov     [FontDataSeg],ax
  1855.     mov     [FontDataOfs],0
  1856.     mov     ds,ax
  1857.     xor     dx,dx
  1858.     mov     ah,3Fh
  1859.     int     21h
  1860.     pop     ds
  1861.     jc      LoadFontExit
  1862.     lea     dx,[FontWidths]         ; Read Font Widths
  1863.     mov     cl,[FontHead.Total]
  1864.     xor     ch,ch
  1865.     mov     ah,3Fh
  1866.     int     21h
  1867.     jc      LoadFontExit
  1868.     mov     ah,3Eh                  ; Close Font File
  1869.     int     21h
  1870. ENDIF
  1871. LoadFontExit:
  1872.     ret
  1873. endp    LoadFont
  1874.  
  1875. ;-----------------------------------------------------------------------------
  1876. ; DrawScroll - Polls the Horizontal Scroller.
  1877. ; Out:
  1878. ;  CF=1 If no more scroll message.
  1879. ;  CF=0 If more scroll message.
  1880. ;-----------------------------------------------------------------------------
  1881.  
  1882. proc    DrawScroll
  1883.     mov     bx,[WinOffs]            ; Loads Window Offset
  1884.     add     bx,2
  1885.     mov     dx,3D4h                 ; Sets VGA Start Address
  1886.     mov     al,0Dh
  1887.     mov     ah,bl
  1888.     out     dx,ax
  1889.     dec     al
  1890.     mov     ah,bh
  1891.     out     dx,ax
  1892.     sub     [CharColumn],4          ; Advance 4 pixels
  1893.     jg      NoNewChar               ; Need a New Char?
  1894.     call    GetsNewChar             ; Yes, Draw a New Char
  1895.     jc      DrawScrollExit
  1896. NoNewChar:
  1897.     mov     ax,0A000h               ; Loads Display Memory Segment
  1898.     mov     es,ax
  1899.     mov     bl,[FontWidth]          ; Loads Font Width and Height
  1900.     mov     cl,[FontHeight]
  1901.     xor     bh,bh
  1902.     xor     ch,ch
  1903.     mov     bp,SCREENWIDTH/4        ; Loads Logical Screen Width
  1904.  
  1905.     mov     dx,3C4h                 ; Enable Write to Plane 1
  1906.     mov     ax,0102h
  1907.     out     dx,ax
  1908.     mov     si,[CharOffs]           ; Loads Char BitMap Address
  1909.     mov     di,[WinOffs]            ; Loads VGA Window Dest Address
  1910.     add     di,SCROLLROW*SCREENWIDTH/4
  1911.     push    cx
  1912.     push    ds
  1913.     mov     ds,[FontDataSeg]
  1914. DrawCharColumn1:
  1915.     mov     al,[ds:si]
  1916.     mov     [es:di],al
  1917.     mov     [es:di+SCREENWIDTH/8],al
  1918.     add     si,bx
  1919.     add     di,bp
  1920.     loop    DrawCharColumn1
  1921.     pop     ds
  1922.     pop     cx
  1923.  
  1924.     mov     dx,3C4h                 ; Enable Write to Plane 2
  1925.     mov     ax,0202h
  1926.     out     dx,ax
  1927.     mov     si,[CharOffs]           ; Loads Char BitMap Address
  1928.     mov     di,[WinOffs]            ; Loads VGA Window Dest Address
  1929.     inc     si
  1930.     add     di,SCROLLROW*SCREENWIDTH/4
  1931.     push    cx
  1932.     push    ds
  1933.     mov     ds,[FontDataSeg]
  1934. DrawCharColumn2:
  1935.     mov     al,[ds:si]
  1936.     mov     [es:di],al
  1937.     mov     [es:di+SCREENWIDTH/8],al
  1938.     add     si,bx
  1939.     add     di,bp
  1940.     loop    DrawCharColumn2
  1941.     pop     ds
  1942.     pop     cx
  1943.  
  1944.     mov     dx,3C4h                 ; Enable Write to Plane 3
  1945.     mov     ax,0402h
  1946.     out     dx,ax
  1947.     mov     si,[CharOffs]           ; Loads Char BitMap Address
  1948.     mov     di,[WinOffs]            ; Loads VGA Window Dest Address
  1949.     add     si,2
  1950.     add     di,SCROLLROW*SCREENWIDTH/4
  1951.     push    cx
  1952.     push    ds
  1953.     mov     ds,[FontDataSeg]
  1954. DrawCharColumn3:
  1955.     mov     al,[ds:si]
  1956.     mov     [es:di],al
  1957.     mov     [es:di+SCREENWIDTH/8],al
  1958.     add     si,bx
  1959.     add     di,bp
  1960.     loop    DrawCharColumn3
  1961.     pop     ds
  1962.     pop     cx
  1963.  
  1964.     mov     dx,3C4h                 ; Enable Write to Plane 4
  1965.     mov     ax,0802h
  1966.     out     dx,ax
  1967.     mov     si,[CharOffs]           ; Loads Char BitMap Address
  1968.     mov     di,[WinOffs]            ; Loads VGA Window Dest Address
  1969.     add     si,3
  1970.     add     di,SCROLLROW*SCREENWIDTH/4
  1971.     push    cx
  1972.     push    ds
  1973.     mov     ds,[FontDataSeg]
  1974. DrawCharColumn4:
  1975.     mov     al,[ds:si]
  1976.     mov     [es:di],al
  1977.     mov     [es:di+SCREENWIDTH/8],al
  1978.     add     si,bx
  1979.     add     di,bp
  1980.     loop    DrawCharColumn4
  1981.     pop     ds
  1982.     pop     cx
  1983.  
  1984.     inc     [WinOffs]               ; Advance Window by 4 pixels
  1985.     cmp     [WinOffs],SCREENWIDTH/8
  1986.     jb      DontWrapWindow
  1987.     mov     [WinOffs],0
  1988. DontWrapWindow:
  1989.     add     [CharOffs],4            ; Advance Char Column by 4
  1990.     clc
  1991. DrawScrollExit:
  1992.     ret
  1993. endp    DrawScroll
  1994.  
  1995. ;-----------------------------------------------------------------------------
  1996. ; GetsNewChar - Gets the next message Character.
  1997. ; Out:
  1998. ;  CF=1 If no more characters
  1999. ;  CF=0 If more characters
  2000. ;-----------------------------------------------------------------------------
  2001.  
  2002. proc    GetsNewChar
  2003.     mov     si,[MesgOffs]           ; Loads the Message Offset
  2004. GetCharLoop:
  2005.     lodsb                           ; Gets the Character
  2006.     test    al,al                   ; if End of Message ReStart
  2007.     jne     DrawCharNow
  2008.     stc
  2009.     jmp     GetsNewCharExit
  2010. DrawCharNow:
  2011.     mov     [MesgOffs],si           ; Save Message Offset
  2012.     sub     al,[FontFirst]          ; Compute the Char BitMap Address
  2013.     xor     ah,ah
  2014.     mov     bx,ax
  2015.     mov     dx,[FontSize]
  2016.     mul     dx
  2017.     add     ax,[FontDataOfs]
  2018.     mov     [CharOffs],ax
  2019.     mov     al,[FontWidths+bx]      ; Set the Char Width
  2020.     mov     [CharColumn],al
  2021.     clc
  2022. GetsNewCharExit:
  2023.     ret
  2024. endp    GetsNewChar
  2025.  
  2026.  
  2027. ;-----------------------------------------------------------------------------
  2028. ; Start - Start the Demostration. Called from DOS.
  2029. ;-----------------------------------------------------------------------------
  2030.  
  2031. proc    Start
  2032.     mov     ax,@Data                ; Sets Data Segment.
  2033.     mov     ds,ax
  2034.     mov     bx,sp                   ; Shrink Program Memory Block.
  2035.     shr     bx,4
  2036.     inc     bx
  2037.     mov     ax,ss
  2038.     mov     dx,es
  2039.     sub     ax,dx
  2040.     add     bx,ax
  2041.     mov     ah,4Ah
  2042.     int     21h
  2043.     call    SetModeX                ; Sets VGA ModeX.
  2044.     call    InitScroll              ; Init Scroller.
  2045.     jc      DemoExit
  2046.     cld
  2047. DemoLoop:
  2048.     call    WaitVR                  ; Waits Vertical Retrace.
  2049.     call    DrawScroll              ; Draw the Scroller.
  2050.     jc      DemoBreak
  2051.     mov     ah,1                    ; Any Key Pressed?
  2052.     int     16h                     ; No, Loop.
  2053.     je      DemoLoop
  2054. DemoBreak:
  2055.     call    DoneScroll              ; Done Scroller.
  2056. DemoExit:
  2057.     mov     ax,0003h                ; Set Text Mode.
  2058.     int     10h
  2059.     mov     ax,4C00h                ; Exit to DOS.
  2060.     int     21h
  2061. endp    Start
  2062.  
  2063.     end     Start
  2064. ;=============================================================================
  2065. ; cplasma - Real Color plasma clouds demo.
  2066. ;                                                     File created: 9-28-93
  2067. ;                                                    Last modified: 9-28-93
  2068. ; Description:
  2069. ;   This file implements the real color plasma demostration using the
  2070. ;   plasma routines and palette rotation using the VGA 320x200x256 mode.
  2071. ;
  2072. ; Portability:
  2073. ;  Requires Turbo Assembler 3.2 or better to be assembler.
  2074. ;  Dependent on the IBM PC 286 and the VGA graphics card.
  2075. ;=============================================================================
  2076.  
  2077.         .model  small,pascal
  2078.          jumps
  2079.         .286
  2080.  
  2081.         global  DrawPlasma:proc         ; in PLASMA.ASM file.
  2082.         global  ColorPlasma:proc
  2083.  
  2084. ;===================== Demo equates and data =================================
  2085.  
  2086. TIMEOUT         equ     70 * 6                  ; 6 seconds timeout.
  2087.  
  2088.         .data
  2089.  
  2090. Palette         db      768 dup (?)             ; hold the palette.
  2091. FadePalette     db      768 dup (?)             ; hold the faded palette.
  2092. Fade            db      ?                       ; fade level.
  2093. EscKey          db      ?                       ; true if ESC pressed.
  2094. Timer           dw      ?                       ; timer counter.
  2095.  
  2096. ;========================== Demo routines ====================================
  2097.  
  2098.         .code
  2099.  
  2100. ;-----------------------------------------------------------------------------
  2101. ; WaitVRT - Waits the Vertical Retrace Period.
  2102. ;-----------------------------------------------------------------------------
  2103.  
  2104. WaitVRT         proc near
  2105.  
  2106.         push    ax
  2107.         push    dx
  2108.         mov     dx,3DAh
  2109. WaitVRT1:       in      al,dx
  2110.         test    al,8
  2111.         jz      WaitVRT1
  2112. WaitVRT2:       in      al,dx
  2113.         test    al,8
  2114.         jnz     WaitVRT2
  2115.         pop     dx
  2116.         pop     ax
  2117.         ret
  2118.  
  2119. WaitVRT         endp
  2120.  
  2121. ;-----------------------------------------------------------------------------
  2122. ; SetPalette - set the 256 entries of the VGA color palette.
  2123. ; In:
  2124. ;   DS:SI - Palette structure address.
  2125. ;-----------------------------------------------------------------------------
  2126.  
  2127. SetPalette      proc near
  2128.  
  2129.         mov     cx,768
  2130.         mov     dx,3C8h
  2131.         xor     al,al
  2132.         out     dx,al
  2133.         mov     dx,3DAh
  2134. WaitVR1:        in      al,dx
  2135.         test    al,8
  2136.         jz      WaitVR1
  2137.         mov     dx,3C9h
  2138.         rep     outsb
  2139. WaitVR2:        in      al,dx
  2140.         test    al,8
  2141.         jnz     WaitVR2
  2142.         ret
  2143.  
  2144. SetPalette      endp
  2145.  
  2146. ;-----------------------------------------------------------------------------
  2147. ; ColorPlasma - Performs the demonstration.
  2148. ; In:
  2149. ;   DS - Data segment.
  2150. ;-----------------------------------------------------------------------------
  2151.  
  2152. ColorPlasma      proc
  2153.  
  2154.         mov     ax,0013h                ; set 320x200x256 mode.
  2155.         int     10h
  2156.  
  2157.         mov     [Fade],0                ; setup variables.
  2158.         mov     [EscKey],0
  2159.         mov     [Timer],0
  2160.  
  2161.         lea     di,[FadePalette]        ; clear fade palette.
  2162.         mov     ax,ds
  2163.         mov     es,ax
  2164.         mov     cx,768
  2165.         xor     ax,ax
  2166.         cld
  2167.         rep     stosb
  2168.         lea     si,[FadePalette]
  2169.         call    SetPalette              ; set black palette.
  2170.  
  2171. GenPalette:     lea     di,[Palette]            ; generation of the
  2172.         xor     cx,cx                   ; plasma palette.
  2173. GP0:            mov     al,63
  2174.         mov     ah,cl
  2175.         mov     bl,al
  2176.         sub     bl,cl
  2177.         mov     [di+0],al
  2178.         mov     [di+1],ah
  2179.         mov     [di+2],bl
  2180.         add     di,3
  2181.         inc     cx
  2182.         cmp     cx,64
  2183.         jb      Gp0
  2184.  
  2185.         xor     cx,cx
  2186. Gp1:            mov     al,63
  2187.         sub     al,cl
  2188.         mov     ah,63
  2189.         mov     bl,cl
  2190.         mov     [di+0],al
  2191.         mov     [di+1],ah
  2192.         mov     [di+2],bl
  2193.         add     di,3
  2194.         inc     cx
  2195.         cmp     cx,64
  2196.         jb      Gp1
  2197.  
  2198.         xor     cx,cx
  2199. Gp2:            mov     al,0
  2200.         mov     ah,63
  2201.         sub     ah,cl
  2202.         mov     bl,63
  2203.         mov     [di+0],al
  2204.         mov     [di+1],ah
  2205.         mov     [di+2],bl
  2206.         add     di,3
  2207.         inc     cx
  2208.         cmp     cx,64
  2209.         jb      Gp2
  2210.  
  2211.         xor     cx,cx
  2212. Gp3:            mov     al,cl
  2213.         mov     ah,0
  2214.         mov     bl,63
  2215.         mov     [di+0],al
  2216.         mov     [di+1],ah
  2217.         mov     [di+2],bl
  2218.         add     di,3
  2219.         inc     cx
  2220.         cmp     cx,64
  2221.         jb      Gp3
  2222.  
  2223.         ; draw plasma onto VGA screen.
  2224.  
  2225.         call    DrawPlasma,30,36,290,164,01234h,0A000h
  2226.  
  2227.         mov     ax,ds
  2228.         mov     es,ax
  2229.         cld
  2230.  
  2231. PlasmaLoop:     test    [Timer],1               ; decreases the rot speed.
  2232.         jne     DontRotate
  2233.         lea     bx,[Palette]            ; rotate the palette.
  2234.         mov     si,bx
  2235.         mov     di,bx
  2236.         add     si,9
  2237.         mov     cx,768-9
  2238.         rep     movsb
  2239.         mov     si,bx
  2240.         mov     cx,9
  2241.         rep     movsb
  2242.         mov     di,bx
  2243.         xor     al,al
  2244.         mov     cx,9
  2245.         rep     stosb
  2246. DontRotate:
  2247.  
  2248.         cmp     [EscKey],0              ; change the fade level.
  2249.         jne     FadeOut
  2250. FadeIn:         mov     bl,[Fade]
  2251.         cmp     bl,128
  2252.         jae     FadeInOut
  2253.         inc     [Fade]
  2254.         jmp     FadeInOut
  2255.  
  2256. FadeOut:        mov     bl,[Fade]
  2257.         cmp     bl,0
  2258.         jbe     FadeInOut
  2259.         dec     [Fade]
  2260.  
  2261. FadeInOut:      lea     si,[Palette]            ; set fade palette using
  2262.         lea     di,[FadePalette]        ; the current fade level
  2263.         mov     cx,768                  ; and plasma palette.
  2264. FadeLoop:       lodsb
  2265.         mul     bl
  2266.         shr     ax,7
  2267.         stosb
  2268.         loop    FadeLoop
  2269.  
  2270.         lea     si,[FadePalette]        ; set VGA fade-palette.
  2271.         call    SetPalette
  2272.  
  2273.         mov     ah,1                    ; if any key pressed,
  2274.         int     16h
  2275.         jz      CheckTimer
  2276.         mov     ah,0
  2277.         int     16h
  2278.         jmp     BeginFadeOut
  2279.  
  2280. CheckTimer:     inc     [Timer]                 ; or timeout...
  2281.         cmp     [Timer],TIMEOUT
  2282.         jb      CheckExit
  2283.  
  2284. BeginFadeOut:   inc     [EscKey]                ; start fade-out and exit.
  2285.  
  2286. CheckExit:      cmp     [Fade],0                ; if fade-out is done
  2287.         jne     PlasmaLoop              ; then quit.
  2288.  
  2289.         mov     ax,0003h                ; restore 80x25x16 text mode.
  2290.         int     10h
  2291.  
  2292.         ret
  2293.  
  2294. ColorPlasma      endp
  2295.  
  2296.  
  2297.         end
  2298. ;=============================================================================
  2299. ; plasma.asm - Plasma Clouds fractal calculation routine.
  2300. ;                                                     File created: 9-26-93
  2301. ; Copyright (c) 1993, Carlos Hasan                   Last modified: 9-26-93
  2302. ;
  2303. ; Description:
  2304. ;  This file implements the plasma clouds routine using a recursive algorithm
  2305. ;  optimized for use with VGA 320x200x256 graphics mode. There must be enough
  2306. ;  stack space for this routine.
  2307. ;
  2308. ; Portability:
  2309. ;  Requires Turbo Assembler 3.2 or better to be assembler.
  2310. ;  Dependent on the IBM PC 286 or later microprocessor.
  2311. ;=============================================================================
  2312.  
  2313.         .model  small,pascal
  2314.         .286
  2315.  
  2316.         global  DrawPlasma:proc
  2317.  
  2318. ;===================== Plasma equates ========================================
  2319.  
  2320. MAXWIDTH        equ     320                     ; virtual screen dimensions.
  2321. MAXHEIGHT       equ     200
  2322. MAXCOLOR        equ     255                     ; max colors for plasma.
  2323. SHIFTVALUE      equ     2                       ; granularity shift.
  2324.  
  2325. ;====================== Plasma data ==========================================
  2326.  
  2327.         .data
  2328.  
  2329. RandSeed        dw      ?                       ; random generator seed.
  2330.  
  2331. ;====================== Plasma routines ======================================
  2332.  
  2333.         .code
  2334.  
  2335. ;-----------------------------------------------------------------------------
  2336. ; Random - Returns a random number of 16 bits, modified version of the
  2337. ;  ripped System unit random routine of the Borland Pascal 7.0.
  2338. ; Out:
  2339. ;  AX - random value.
  2340. ; Modified:
  2341. ;  AX, DX, Flags.
  2342. ;-----------------------------------------------------------------------------
  2343.  
  2344. Random          proc near
  2345.  
  2346.         mov     ax,[RandSeed]
  2347.         mov     dx,8405h
  2348.         mul     dx
  2349.         inc     ax
  2350.         mov     [RandSeed],ax
  2351.         ret
  2352.  
  2353. Random          endp
  2354.  
  2355.  
  2356. ;-----------------------------------------------------------------------------
  2357. ; GetPixel - get the pixel color at specified location.
  2358. ; In:
  2359. ;   ES    - virtual screen segment.
  2360. ;   (X,Y) - pixel location.
  2361. ; Out:
  2362. ;   AL    - pixel color value.
  2363. ; Modified:
  2364. ;   BX, Flags.
  2365. ;-----------------------------------------------------------------------------
  2366.  
  2367. GetPixel        macro   X,Y
  2368.  
  2369.         mov     bx,Y
  2370.         imul    bx,MAXWIDTH
  2371.         add     bx,X
  2372.         mov     al,es:[bx]
  2373.  
  2374.         endm
  2375.  
  2376. ;-----------------------------------------------------------------------------
  2377. ; PutPixel - put the pixel color at specified location.
  2378. ; In:
  2379. ;   ES    - virtual screen segment.
  2380. ;   (X,Y) - pixel location.
  2381. ;   AL    - pixel value.
  2382. ; Modified:
  2383. ;   BX, Flags.
  2384. ;-----------------------------------------------------------------------------
  2385.  
  2386. PutPixel        macro   X,Y
  2387.  
  2388.         mov     bx,Y
  2389.         imul    bx,MAXWIDTH
  2390.         add     bx,X
  2391.         mov     es:[bx],al
  2392.  
  2393.         endm
  2394.  
  2395.  
  2396. ;----------------------------------------------------------------------------
  2397. ; Adjust - adjust a new pixel value using two neighboring pixels.
  2398. ; In:
  2399. ;  (XA,YA) - first near pixel.
  2400. ;  (XB,YB) - second near pixel.
  2401. ;  (X,Y)   - new pixel.
  2402. ; Out:
  2403. ;  AX      - new pixel color value.
  2404. ; Modified:
  2405. ;  AX, BX, DX, SI, DI, Flags.
  2406. ;----------------------------------------------------------------------------
  2407.  
  2408. Adjust          proc near XA:word,YA:word,X:word,Y:word,XB:word,YB:word
  2409.  
  2410.         mov     si,[X]                  ; if already painted
  2411.         mov     di,[Y]                  ; the pixel, use this
  2412.         xor     ax,ax                   ; one instead of new
  2413.         GetPixel si,di                  ; calculation.
  2414.         test    ax,ax
  2415.         jne     AdjExit
  2416.  
  2417.         call    Random                  ; get a random variation
  2418.         mov     bx,[XB]                 ; dependent of the pixels
  2419.         sub     bx,[XA]                 ; distance and granularity
  2420.         add     bx,[YB]                 ; shift factor.
  2421.         sub     bx,[YA]
  2422.         shl     bx,SHIFTVALUE
  2423.         imul    bx
  2424.         xor     ax,ax                   ; adds the average of the
  2425.         GetPixel [XA],[YA]              ; near pixels colors.
  2426.         add     dx,ax
  2427.         GetPixel [XB],[YB]
  2428.         add     ax,dx
  2429.         shr     ax,1
  2430.         cmp     ax,1                    ; check if new color is
  2431.         jge     ColorUp                 ; in the right range.
  2432.         mov     ax,1
  2433. ColorUp:        cmp     ax,MAXCOLOR
  2434.         jle     ColorDn
  2435.         mov     ax,MAXCOLOR
  2436. ColorDn:        PutPixel si,di                  ; paint pixel color.
  2437. AdjExit:        ret
  2438.  
  2439. Adjust          endp
  2440.  
  2441.  
  2442. ;-----------------------------------------------------------------------------
  2443. ; SubDivide - main plasma routine that divides a region recursively.
  2444. ; In:
  2445. ;   (X1,Y1,X2,Y2) - screen plasma region.
  2446. ; Modified:
  2447. ;   AX, BX, CX, DX, Flags.
  2448. ;-----------------------------------------------------------------------------
  2449.  
  2450. SubDivide       proc near X1:word,Y1:word,X2:word,Y2:word
  2451.         local   X:word,Y:word
  2452.  
  2453.         mov     ax,[X2]                 ; test if this region
  2454.         sub     ax,[X1]                 ; needs a sub-division.
  2455.         cmp     ax,2
  2456.         jge     SubDivCont
  2457.         mov     ax,[Y2]
  2458.         sub     ax,[Y1]
  2459.         cmp     ax,2
  2460.         jge     SubDivCont
  2461.         jmp     SubDivExit
  2462.  
  2463. SubDivCont:     mov     ax,[X1]                 ; get the center position
  2464.         add     ax,[X2]                 ; of the region.
  2465.         rcr     ax,1
  2466.         mov     [X],ax
  2467.         mov     ax,[Y1]
  2468.         add     ax,[Y2]
  2469.         rcr     ax,1
  2470.         mov     [Y],ax
  2471.  
  2472.         ; get the sum of the neighboring four pixel colors.
  2473.         xor     cx,cx
  2474.         call    Adjust, [X1],[Y1], [X],[Y1], [X2],[Y1]
  2475.         add     cx,ax
  2476.         call    Adjust, [X2],[Y1], [X2],[Y], [X2],[Y2]
  2477.         add     cx,ax
  2478.         call    Adjust, [X1],[Y2], [X],[Y2], [X2],[Y2]
  2479.         add     cx,ax
  2480.         call    Adjust, [X1],[Y1], [X1],[Y], [X1],[Y2]
  2481.         add     cx,ax
  2482.  
  2483.         mov     si,[X]                  ; test if the center pixel
  2484.         mov     di,[Y]                  ; need to be calculated.
  2485.         GetPixel si,di
  2486.         test    al,al
  2487.         jne     SubDivNow
  2488.         mov     ax,cx                   ; yes, use the average of
  2489.         add     ax,2                    ; the neighboring pixels.
  2490.         shr     ax,2                    ; (don't allow color 0)
  2491.         PutPixel si,di
  2492.  
  2493.         ; sub-divides the new four regions.
  2494. SubDivNow:      call    SubDivide, [X1],[Y1], [X],[Y]
  2495.         call    SubDivide, [X],[Y1], [X2],[Y]
  2496.         call    SubDivide, [X],[Y], [X2],[Y2]
  2497.         call    SubDivide, [X1],[Y], [X],[Y2]
  2498.  
  2499. SubDivExit:     ret
  2500.  
  2501. SubDivide       endp
  2502.  
  2503. ;-----------------------------------------------------------------------------
  2504. ; DrawPlasma - Main routine to draw plasma into a virtual screen.
  2505. ; In:
  2506. ;   (X1,Y1,X2,Y2) - Virtual screen Window location.
  2507. ;   Seed          - Initial random seed for the plasma generator.
  2508. ;   ScreenSeg     - Virtual screen segment.
  2509. ;-----------------------------------------------------------------------------
  2510.  
  2511. DrawPlasma      proc    XStart:word,YStart:word,XStop:word,YStop:word, \
  2512.           Seed:word,ScreenSeg:word
  2513.  
  2514.         mov     ax,[ScreenSeg]          ; setup virtual screen
  2515.         mov     es,ax                   ; segment,
  2516.  
  2517.         mov     ax,[Seed]               ; and random calculation
  2518.         mov     [RandSeed],ax           ; seed.
  2519.  
  2520.         call    Random                  ; set window corner pixels.
  2521.         or      al,1
  2522.         PutPixel [XStart],[YStart]
  2523.  
  2524.         call    Random
  2525.         or      al,1
  2526.         PutPixel [XStop],[YStart]
  2527.  
  2528.         call    Random
  2529.         or      al,1
  2530.         PutPixel [XStart],[YStop]
  2531.  
  2532.         call    Random
  2533.         or      al,1
  2534.         PutPixel [XStop],[YStop]
  2535.  
  2536.         call    SubDivide, [XStart],[YStart], [XStop],[YStop]
  2537.         ret
  2538.  
  2539. DrawPlasma      endp
  2540.  
  2541.         end;=============================================================================
  2542. ; rplasma - Runtime real plasma clouds demo.
  2543. ;                                                   File created: 9-28-93
  2544. ; Copyright (C) 1993, Carlos Hasan                 Last modified: 9-28-93
  2545. ;
  2546. ; Description:
  2547. ;   This file implements a runtime real plasma using sinus overlapping
  2548. ;   waves at random speeds using the VGA 320x400x256 mode. Based on the
  2549. ;   Vangelis Plasma demo code.
  2550. ;
  2551. ; Portability:
  2552. ;  Requires Turbo Assembler 3.2 or better to be assembler.
  2553. ;  Dependent on the IBM PC 286 and the VGA graphics card.
  2554. ;=============================================================================
  2555.  
  2556.         .model  small,pascal
  2557.         .286
  2558.  
  2559.         global  SinusPlasma:proc
  2560.  
  2561. ;======================= Demo equates and data ===============================
  2562.  
  2563. TIMEOUT         equ     70 * 6                  ; 6 secs for timeout.
  2564.  
  2565.         .data
  2566.  
  2567.         include sintable.inc            ; sinus table.
  2568.  
  2569. Palette         db      768 dup (?)             ; plasma palette.
  2570. FadePalette     db      768 dup (?)             ; faded palette.
  2571. WavHPos1        db      ?                       ; wave horizontal and
  2572. WavHPos2        db      ?                       ; vertical positions
  2573. WavVPos1        db      ?                       ; and increments.
  2574. WavVPos2        db      ?
  2575. WavHAdd1        db      ?                       ; WARNING: the four waves
  2576. WavHAdd2        db      ?                       ;  positions must be at
  2577. WavVAdd1        db      ?                       ;  consecutive addresses.
  2578. WavVAdd2        db      ?
  2579. Fade            db      ?                       ; fade level.
  2580. Esckey          db      ?                       ; true if key pressed.
  2581. Timer           dw      ?                       ; timer counter.
  2582.  
  2583. ;======================= Demo routines =======================================
  2584.  
  2585.         .code
  2586.  
  2587. ;-----------------------------------------------------------------------------
  2588. ; SetPalette - set the 256 entries of the VGA color palette.
  2589. ; In:
  2590. ;   DS:SI - Palette structure address.
  2591. ;-----------------------------------------------------------------------------
  2592.  
  2593. SetPalette      proc near
  2594.  
  2595.         mov     cx,768
  2596.         mov     dx,3C8h
  2597.         xor     al,al
  2598.         out     dx,al
  2599.         mov     dx,3DAh
  2600. WaitVRT:        in      al,dx
  2601.         test    al,8
  2602.         jz      WaitVRT
  2603.         mov     dx,3C9h
  2604.         rep     outsb
  2605. WaitVRTE:       in      al,dx
  2606.         test    al,8
  2607.         jnz     WaitVRTE
  2608.         ret
  2609.  
  2610. SetPalette      endp
  2611.  
  2612. ;-----------------------------------------------------------------------------
  2613. ; SinusPlasma - Performs the demonstration.
  2614. ; In:
  2615. ;   DS - Data segment.
  2616. ;-----------------------------------------------------------------------------
  2617.  
  2618. SinusPlasma     proc
  2619.  
  2620.         pusha
  2621.         push    ds
  2622.         push    es
  2623.  
  2624.         mov     ax,0013h                ; set 320x200x256 mode.
  2625.         int     10h
  2626.  
  2627.         mov     ax,ds                   ; set black palette.
  2628.         mov     es,ax
  2629.         lea     di,[FadePalette]
  2630.         mov     cx,768
  2631.         xor     ax,ax
  2632.         cld
  2633.         rep     stosb
  2634.         lea     si,[FadePalette]
  2635.         call    SetPalette
  2636.  
  2637.         mov     dx,3C4h                 ; setup VGA tricky
  2638.         mov     ax,0604h                ; 320x400x256 mode.
  2639.         out     dx,ax
  2640.         mov     ax,0F02h                ; enable 4-planes.
  2641.         out     dx,ax
  2642.         mov     dx,3D4h                 ; disable dword mode
  2643.         mov     ax,0014h
  2644.         out     dx,ax
  2645.         mov     ax,0E317h               ; enable byte mode
  2646.         out     dx,ax
  2647.         mov     ax,0009h                ; dup each scan 1 times
  2648.         out     dx,ax
  2649.  
  2650.         mov     ax,0A000h
  2651.         mov     es,ax
  2652.         xor     di,di
  2653.         mov     cx,8000h                ; clear video memory.
  2654.         xor     ax,ax
  2655.         cld
  2656.         rep     stosw
  2657.  
  2658.         mov     [Fade],0                ; setup variables.
  2659.         mov     [EscKey],0
  2660.         mov     [Timer],0
  2661.  
  2662.         mov     [WavHPos1],0            ; setup wave parameters.
  2663.         mov     [WavHPos2],0
  2664.         mov     [WavVPos1],0
  2665.         mov     [WavVPos2],0
  2666.         mov     [WavHAdd1],2
  2667.         mov     [WavHAdd2],1
  2668.         mov     [WavVAdd1],3
  2669.         mov     [WavVAdd2],4
  2670.  
  2671. GenPalette:     lea     di,[Palette]            ; generation of the
  2672.         xor     al,al                   ; plasma palette.
  2673.         mov     [di+0],al
  2674.         mov     [di+1],al
  2675.         mov     [di+2],al
  2676.         add     di,3
  2677.         mov     cx,1
  2678. GP0:            mov     al,63
  2679.         mov     ah,cl
  2680.         mov     bl,al
  2681.         sub     bl,cl
  2682.         mov     [di+0],al
  2683.         mov     [di+1],ah
  2684.         mov     [di+2],bl
  2685.         add     di,3
  2686.         inc     cx
  2687.         cmp     cx,64
  2688.         jb      Gp0
  2689.  
  2690.         xor     cx,cx
  2691. Gp1:            mov     al,63
  2692.         sub     al,cl
  2693.         mov     ah,63
  2694.         mov     bl,cl
  2695.         mov     [di+0],al
  2696.         mov     [di+1],ah
  2697.         mov     [di+2],bl
  2698.         add     di,3
  2699.         inc     cx
  2700.         cmp     cx,64
  2701.         jb      Gp1
  2702.  
  2703.         xor     cx,cx
  2704. Gp2:            mov     al,0
  2705.         mov     ah,63
  2706.         sub     ah,cl
  2707.         mov     bl,63
  2708.         mov     [di+0],al
  2709.         mov     [di+1],ah
  2710.         mov     [di+2],bl
  2711.         add     di,3
  2712.         inc     cx
  2713.         cmp     cx,64
  2714.         jb      Gp2
  2715.  
  2716.         xor     cx,cx
  2717. Gp3:            mov     al,cl
  2718.         mov     ah,0
  2719.         mov     bl,63
  2720.         mov     [di+0],al
  2721.         mov     [di+1],ah
  2722.         mov     [di+2],bl
  2723.         add     di,3
  2724.         inc     cx
  2725.         cmp     cx,64
  2726.         jb      Gp3
  2727.  
  2728. PlasmaLoop:     cmp     [EscKey],0              ; change fade level.
  2729.         jne     FadeOut
  2730. FadeIn:         mov     bl,[Fade]
  2731.         cmp     bl,64
  2732.         jae     SkipFade
  2733.         inc     [Fade]
  2734.         jmp     FadeInOut
  2735. FadeOut:        mov     bl,[Fade]
  2736.         cmp     bl,0
  2737.         jbe     FadeInOut
  2738.         dec     [Fade]
  2739.  
  2740. FadeInOut:      lea     si,[Palette]            ; set faded palette.
  2741.         lea     di,[FadePalette]
  2742.         mov     cx,768
  2743.         mov     ax,ds
  2744.         mov     es,ax
  2745.         cld
  2746. FadeLoop:       lodsb
  2747.         mul     bl
  2748.         shr     ax,6
  2749.         stosb
  2750.         loop    FadeLoop
  2751.  
  2752. SkipFade:       lea     si,[FadePalette]
  2753.         call    SetPalette
  2754.  
  2755.         mov     ax,0A000h
  2756.         mov     es,ax
  2757.  
  2758.         lea     si,[SinusTable]
  2759.  
  2760.         mov     di,80*100+10            ; top left corner.
  2761.  
  2762.         mov     ah,100                  ; 100 lines.
  2763.         mov     cl,[WavVPos1]
  2764.         mov     ch,[WavVPos2]
  2765. VertLoop:       push    ax
  2766.         mov     ah,60                   ; 60 columns.
  2767.         mov     dl,[WavHPos1]
  2768.         mov     dh,[WavHPos2]
  2769. HorizLoop:      mov     bx,bp                   ; get random value.
  2770.         mov     al,bl
  2771.         xor     bh,bh
  2772.         mov     bl,dl
  2773.         add     al,[bx+si]
  2774.         mov     bl,dh
  2775.         add     al,[bx+si]
  2776.         mov     bl,cl
  2777.         add     al,[bx+si]
  2778.         mov     bl,ch
  2779.         add     al,[bx+si]
  2780.         or      al,1
  2781.         stosb
  2782.         add     dl,1
  2783.         add     dh,3
  2784.         dec     ah
  2785.         jne     HorizLoop
  2786.         add     di,80+20                ; skip scan line.
  2787.         add     cl,7
  2788.         add     ch,3
  2789.         pop     ax
  2790.         dec     ah
  2791.         jne     VertLoop                ; next plasma line.
  2792.  
  2793.         inc     bp                      ; get random value.
  2794.         mov     bx,bp
  2795.         xor     bl,bh
  2796.         xor     bl,[di-1]
  2797.         xor     bl,cl
  2798.         xor     bl,dl
  2799.         add     bl,ch
  2800.         add     bl,dh
  2801.  
  2802.         test    bl,8                    ; change waves speed.
  2803.         jne     SpeedDown
  2804. SpeedUp:        and     bx,3
  2805.         cmp     [WavHAdd1+bx],+7
  2806.         jg      ChangePos
  2807.         inc     [WavHAdd1+bx]
  2808.         jmp     ChangePos
  2809. SpeedDown:      and     bx,3
  2810.         cmp     [WavHAdd1+bx],-7
  2811.         jl      ChangePos
  2812.         dec     [WavHAdd1+bx]
  2813.  
  2814. ChangePos:      mov     al,[WavHAdd1]           ; change waves positions.
  2815.         add     [WavHPos1],al
  2816.         mov     al,[WavHAdd2]
  2817.         add     [WavHPos2],al
  2818.         mov     al,[WavVAdd1]
  2819.         add     [WavVPos1],al
  2820.         mov     al,[WavVAdd2]
  2821.         add     [WavVPos2],al
  2822.  
  2823.         mov     ah,1                    ; if any key pressed,
  2824.         int     16h
  2825.         jz      CheckTimer
  2826.         mov     ah,0
  2827.         int     16h
  2828.         jmp     BeginFadeOut
  2829.  
  2830. CheckTimer:     inc     [Timer]                 ; or timeout,
  2831.         cmp     [Timer],TIMEOUT
  2832.         jb      CheckExit
  2833.  
  2834. BeginFadeOut:   inc     [EscKey]                ; then fade-out and exit.
  2835.  
  2836. CheckExit:      cmp     [Fade],0
  2837.         je      PlasmaExit
  2838.         jmp     PlasmaLoop
  2839.  
  2840. PlasmaExit:     mov     ax,0003h
  2841.         int     10h
  2842.  
  2843.         pop     es
  2844.         pop     ds
  2845.         popa
  2846.         ret
  2847.  
  2848. SinusPlasma     endp
  2849.  
  2850.         end
  2851. ;=============================================================================
  2852. ; wplasma - Runtime Sinus Wave Plasma Demostration.
  2853. ;                                                   File created: 10-21-93
  2854. ; Copyright (C) 1993, Carlos Hasan                 Last modified: 10-21-93
  2855. ;
  2856. ; Description:
  2857. ;   This file implements a runtime real plasma using sinus overlapping
  2858. ;   waves at random speeds using the VGA 320x80x256 mode.
  2859. ;
  2860. ; Portability:
  2861. ;  Requires Turbo Assembler 3.2 or better to be assembler.
  2862. ;  Dependent on the IBM PC 286 and the VGA graphics card.
  2863. ;=============================================================================
  2864.  
  2865.         jumps
  2866.         .model  small,pascal
  2867.         .286
  2868.  
  2869.         global  WavePlasma:proc
  2870.  
  2871. ;======================= Demo equates and data ===============================
  2872.  
  2873. TIMEOUT         equ     70 * 10                 ; at least 10 secs.
  2874. MAXHW           equ     32                      ; max horiz wave amount.
  2875. MAXVW           equ     64                      ; max vert wave amount.
  2876. MAXH            equ     60                      ; horiz wave length.
  2877. MAXV            equ     80+MAXHW                ; vert wave length.
  2878. SEED            equ     57FEh                   ; randomize.
  2879.  
  2880.         .data
  2881.  
  2882.         include sintab2.inc             ; sinus table.
  2883.  
  2884. HWave1          db      MAXH dup (?)            ; horiz waves.
  2885. HWave2          db      MAXH dup (?)
  2886. VWave1          db      MAXV dup (?)            ; vert waves.
  2887. VWave2          db      MAXV dup (?)
  2888. HWavPos1        dw      ?                       ; horiz waves pos.
  2889. HWavPos2        dw      ?
  2890. VWavPos1        dw      ?                       ; vert waves pos.
  2891. VWavPos2        dw      ?
  2892. HWavInc1        dw      ?                       ; horiz wave speed.
  2893. VWavInc1        dw      ?                       ; vert wave speed.
  2894. Bitmap          db      256*MAXH+MAXV dup (?)   ; aux plasma buffer.
  2895.  
  2896. Palette         db      768 dup (?)             ; plasma palette.
  2897. FadePalette     db      768 dup (?)             ; faded palette.
  2898. Fade            db      ?                       ; fade level.
  2899. Esckey          db      ?                       ; true if key pressed.
  2900. Timer           dw      ?                       ; timer counter.
  2901. RandSeed        dw      ?                       ; Random seed.
  2902.  
  2903. ;======================= Demo routines =======================================
  2904.  
  2905.         .code
  2906.  
  2907. ;-----------------------------------------------------------------------------
  2908. ; Random - Returns a 16-bit random number.
  2909. ; Out:
  2910. ;  AX - Random number.
  2911. ;-----------------------------------------------------------------------------
  2912.  
  2913. Random          proc near
  2914.  
  2915.         mov     ax,[RandSeed]
  2916.         imul    ax,13A7h
  2917.         inc     ax
  2918.         mov     [RandSeed],ax
  2919.         ret
  2920.  
  2921. Random          endp
  2922.  
  2923. ;-----------------------------------------------------------------------------
  2924. ; WaitVRT - Waits the Vertical Retrace.
  2925. ;-----------------------------------------------------------------------------
  2926.  
  2927. WaitVRT         proc near
  2928.  
  2929.         mov     dx,3DAh
  2930. WaitVR1:        in      al,dx
  2931.         test    al,8
  2932.         jne     WaitVR1
  2933. WaitVR2:        in      al,dx
  2934.         test    al,8
  2935.         je      WaitVR2
  2936.         ret
  2937.  
  2938. WaitVRT         endp
  2939.  
  2940. ;-----------------------------------------------------------------------------
  2941. ; SetPalette - set the CX entries of the VGA color palette.
  2942. ; In:
  2943. ;   DS:SI - Palette structure address.
  2944. ;   CX    - Number of colors components.
  2945. ;-----------------------------------------------------------------------------
  2946.  
  2947. SetPalette      proc near
  2948.  
  2949.         call    WaitVRT
  2950.         mov     dx,3C8h
  2951.         xor     al,al
  2952.         out     dx,al
  2953.         inc     dx
  2954.         rep     outsb
  2955.         ret
  2956.  
  2957. SetPalette      endp
  2958.  
  2959. ;-----------------------------------------------------------------------------
  2960. ; UpdHWaves - Updates the Horiz Waves.
  2961. ;-----------------------------------------------------------------------------
  2962.  
  2963. UpdHWaves       proc near
  2964.  
  2965.         mov     ax,ds
  2966.         mov     es,ax
  2967.         cld
  2968.         lea     si,[HWave1+1]
  2969.         lea     di,[HWave1]
  2970.         mov     cx,MAXH-1
  2971.         rep     movsb
  2972.         mov     si,[HWavPos1]
  2973.         mov     al,[SinusTable+si]
  2974.         sar     al,1
  2975.         stosb
  2976.         add     si,[HWavInc1]
  2977.         cmp     si,360
  2978.         jb      SetHInc
  2979.         sub     si,360
  2980. SetHInc:        mov     [HWavPos1],si
  2981.         lea     si,[SinusTable]
  2982.         add     si,[HWavPos2]
  2983.         lea     bx,[HWave1]
  2984.         lea     di,[HWave2]
  2985.         mov     cx,MAXH
  2986. UpdHLoop:       lodsb
  2987.         sar     al,1
  2988.         add     al,[bx]
  2989.         sar     al,3
  2990.         add     al,16
  2991.         stosb
  2992.         add     si,3
  2993.         inc     bx
  2994.         loop    UpdHLoop
  2995.         add     [HWavPos2],4
  2996.         cmp     [HWavPos2],360
  2997.         jb      UpdHExit
  2998.         sub     [HWavPos2],360
  2999. UpdHExit:       ret
  3000.  
  3001. UpdHWaves       endp
  3002.  
  3003. ;-----------------------------------------------------------------------------
  3004. ; UpdVWaves - Updates the Vert Waves.
  3005. ;-----------------------------------------------------------------------------
  3006.  
  3007. UpdVWaves       proc near
  3008.  
  3009.         mov     ax,ds
  3010.         mov     es,ax
  3011.         cld
  3012.         lea     si,[VWave1+1]
  3013.         lea     di,[VWave1]
  3014.         mov     cx,MAXV-1
  3015.         rep     movsb
  3016.         mov     si,[VWavPos1]
  3017.         mov     al,[SinusTable+si]
  3018.         sar     al,1
  3019.         stosb
  3020.         add     si,[VWavInc1]
  3021.         cmp     si,360
  3022.         jb      SetVInc
  3023.         sub     si,360
  3024. SetVInc:        mov     [VWavPos1],si
  3025.         lea     si,[SinusTable]
  3026.         add     si,[VWavPos2]
  3027.         lea     bx,[VWave1]
  3028.         lea     di,[VWave2]
  3029.         mov     cx,MAXV
  3030. UpdVLoop:       lodsb
  3031.         sar     al,1
  3032.         add     al,[bx]
  3033.         sar     al,2
  3034.         add     al,32
  3035.         stosb
  3036.         add     si,2
  3037.         inc     bx
  3038.         loop    UpdVLoop
  3039.         inc     [VWavPos2]
  3040.         cmp     [VWavPos2],360
  3041.         jb      UpdVExit
  3042.         sub     [VWavPos2],360
  3043. UpdVExit:       ret
  3044.  
  3045. UpdVWaves       endp
  3046.  
  3047. ;-----------------------------------------------------------------------------
  3048. ; UpdBmp - Updates the Plasma bitmap.
  3049. ;-----------------------------------------------------------------------------
  3050.  
  3051. UpdBmp          proc near
  3052.  
  3053.         cld
  3054.         mov     cx,MAXV
  3055.         lea     si,[VWave2]
  3056.         lea     di,[BitMap]
  3057. UpBmLoop:       lodsb
  3058.         i=0
  3059.         REPT MAXH
  3060.           inc   al
  3061.           mov   [di+i],al
  3062.           i=i+256
  3063.         ENDM
  3064.         inc     di
  3065.         loop    UpBmLoop
  3066.         ret
  3067.  
  3068. UpdBmp          endp
  3069.  
  3070. ;-----------------------------------------------------------------------------
  3071. ; PutBmp - Puts into the screen the Plasma bitmap.
  3072. ;-----------------------------------------------------------------------------
  3073.  
  3074. PutBmp          proc near
  3075.  
  3076.         cld
  3077.         mov     ax,0A000h
  3078.         mov     es,ax
  3079.         mov     di,80*10
  3080.         lea     dx,[BitMap]
  3081.         lea     si,[HWave2]
  3082.         mov     bl,MAXH
  3083.         xor     ah,ah
  3084. PutLoop:        lodsb
  3085.         push    si
  3086.         mov     si,ax
  3087.         add     si,dx
  3088.         mov     cx,40
  3089.         rep     movsw
  3090.         pop     si
  3091.         inc     dh
  3092.         dec     bl
  3093.         jne     PutLoop
  3094.         ret
  3095.  
  3096. PutBmp          endp
  3097.  
  3098. ;-----------------------------------------------------------------------------
  3099. ; WavePlasma - Performs the demonstration.
  3100. ; In:
  3101. ;   DS - Data segment.
  3102. ;-----------------------------------------------------------------------------
  3103.  
  3104. WavePlasma      proc
  3105.  
  3106.         pusha
  3107.         push    ds
  3108.         push    es
  3109.  
  3110.         mov     ax,0013h                ; set 320x200x256 mode.
  3111.         int     10h
  3112.  
  3113.         mov     dx,3C4h                 ; disable chain-four
  3114.         mov     al,04h
  3115.         out     dx,al
  3116.         inc     dx
  3117.         in      al,dx
  3118.         and     al,0F7h
  3119.         out     dx,al
  3120.         mov     dx,3C4h                 ; enable all planes
  3121.         mov     ax,0F02h
  3122.         out     dx,ax
  3123.         mov     ax,0A000h               ; clear video memory
  3124.         mov     es,ax
  3125.         xor     di,di
  3126.         xor     ax,ax
  3127.         mov     cx,8000h
  3128.         cld
  3129.         rep     stosw
  3130.         mov     dx,3D4h                 ; normal word addressing
  3131.         mov     al,14h
  3132.         out     dx,al
  3133.         inc     dx
  3134.         in      al,dx
  3135.         and     al,0BFh
  3136.         out     dx,al
  3137.         dec     dx                      ; address output byte mode
  3138.         mov     al,17h
  3139.         out     dx,al
  3140.         inc     dx
  3141.         in      al,dx
  3142.         or      al,40h
  3143.         out     dx,al
  3144.         mov     dx,3D4h                 ; set max scanline.
  3145.         mov     ax,0409h
  3146.         out     dx,ax
  3147.  
  3148. GenPalette:     lea     di,[Palette]            ; generation of the
  3149.         xor     al,al                   ; plasma palette.
  3150.         mov     [di+0],al
  3151.         mov     [di+1],al
  3152.         mov     [di+2],al
  3153.         add     di,3
  3154.         mov     cx,MAXH+MAXVW
  3155.         xor     ah,ah
  3156.         mov     bl,2
  3157. GPLoop:         mov     dl,32
  3158.         mov     al,ah
  3159.         shr     al,1
  3160.         sub     dl,al
  3161.         mov     [di+0],dl
  3162.         mov     dl,16
  3163.         mov     al,ah
  3164.         shr     al,2
  3165.         sub     dl,al
  3166.         mov     [di+1],dl
  3167.         mov     dl,63
  3168.         mov     al,ah
  3169.         shr     al,2
  3170.         sub     dl,al
  3171.         mov     [di+2],dl
  3172.         add     ah,bl
  3173.         cmp     ah,64
  3174.         jb      GPCont
  3175.         neg     bl
  3176.         add     ah,bl
  3177.         add     ah,bl
  3178. GPCont:         add     di,3
  3179.         loop    GPLoop
  3180.  
  3181.         mov     [Fade],0                ; setup variables.
  3182.         mov     [EscKey],0
  3183.         mov     [Timer],0
  3184.         mov     [RandSeed],SEED
  3185.  
  3186.         mov     [HWavPos1],0            ; setup wave parameters.
  3187.         mov     [HWavPos2],0
  3188.         mov     [VWavPos1],0
  3189.         mov     [VWavPos2],0
  3190.         mov     [HWavInc1],1
  3191.         mov     [VWavInc1],7
  3192.  
  3193.         mov     cx,MAXV                 ; use enough steps
  3194. SetupWaves:     push    cx                      ; to update all the
  3195.         call    UpdHWaves               ; waves entries.
  3196.         call    UpdVWaves
  3197.         pop     cx
  3198.         loop    SetupWaves
  3199.  
  3200.  
  3201. PlasmaLoop:     cmp     [EscKey],0              ; change fade level.
  3202.         jne     FadeOut
  3203. FadeIn:         mov     bl,[Fade]
  3204.         cmp     bl,64
  3205.         jae     SkipFade
  3206.         inc     [Fade]
  3207.         jmp     FadeInOut
  3208. FadeOut:        mov     bl,[Fade]
  3209.         cmp     bl,0
  3210.         jbe     FadeInOut
  3211.         dec     [Fade]
  3212.  
  3213. FadeInOut:      lea     si,[Palette]            ; set faded palette.
  3214.         lea     di,[FadePalette]
  3215.         mov     cx,768
  3216.         mov     ax,ds
  3217.         mov     es,ax
  3218.         cld
  3219. FadeLoop:       lodsb
  3220.         mul     bl
  3221.         shr     ax,6
  3222.         stosb
  3223.         loop    FadeLoop
  3224.  
  3225. DoFade:         lea     si,[FadePalette]        ; ensures thats always
  3226.         mov     cx,3*(MAXH+MAXVW+1)     ; waits the VR per frame.
  3227.         call    SetPalette
  3228.         jmp     DoPlasma
  3229.  
  3230. SkipFade:       call    WaitVRT
  3231.  
  3232. DoPlasma:       call    UpdHWaves               ; updates horiz waves.
  3233.         call    UpdVWaves               ; updates vert waves.
  3234.         call    UpdBmp                  ; updates bitmap.
  3235.         call    PutBmp                  ; draw plasma.
  3236.  
  3237.         call    Random                  ; change wave's speed.
  3238.         and     ax,7
  3239.         add     ax,3
  3240.         mov     [HWavInc1],ax
  3241.         call    Random
  3242.         and     ax,3
  3243.         add     ax,5
  3244.         mov     [VWavInc1],ax
  3245.  
  3246.         mov     ah,1                    ; if any key pressed,
  3247.         int     16h
  3248.         jz      CheckTimer
  3249.         mov     ah,0
  3250.         int     16h
  3251.         jmp     BeginFadeOut
  3252.  
  3253. CheckTimer:     inc     [Timer]                 ; or timeout,
  3254.         cmp     [Timer],TIMEOUT
  3255.         jb      CheckExit
  3256.  
  3257. BeginFadeOut:   inc     [EscKey]                ; then fade-out and exit.
  3258.  
  3259. CheckExit:      cmp     [Fade],0
  3260.         je      PlasmaExit
  3261.         jmp     PlasmaLoop
  3262.  
  3263. PlasmaExit:     mov     ax,0003h
  3264.         int     10h
  3265.  
  3266.         pop     es
  3267.         pop     ds
  3268.         popa
  3269.         ret
  3270.  
  3271. WavePlasma      endp
  3272.  
  3273.         end
  3274. ;=============================================================================
  3275. ; lenz.asm - Lenz or Crystal Ball Demostration.
  3276. ;                                                    File created: 10/18/93
  3277. ; Copyright (c) 1993, Carlos Hasan                  Last modified: 11/16/93
  3278. ;
  3279. ; Description:
  3280. ;   This file implements a Lenz-like Crystall Ball effect using the
  3281. ;   VGA 320x200x256 graphics mode and a 320x200x256 picture.
  3282. ;
  3283. ; Portability:
  3284. ;  Requires Turbo Assembler 3.2 or better to be assembled.
  3285. ;  Dependent on the IBM PC 286 and the VGA graphics card.
  3286. ;
  3287. ; Modifications:
  3288. ;  10/22/93 - Startup Code and Picture/Palette in .OBJ files.
  3289. ;  11/01/93 - Fixed Vertical Strengh Amplification.
  3290. ;  11/16/93 - Added EmBoss and Slide Effect.
  3291. ;=============================================================================
  3292.  
  3293.         jumps
  3294.         .model  small,pascal
  3295.         .286
  3296.  
  3297.         dosseg                          ; used to link like
  3298.         .stack  1024                    ; an standalone program.
  3299.  
  3300.         global  LenzDemo:proc
  3301.         global  LenzPal:byte            ; in LENZPAL.OBJ file.
  3302.         global  LenzPic:byte            ; in LENZRAW.OBJ file.
  3303.  
  3304. ;========================= Demo equates ======================================
  3305. ;
  3306. ; Note: 1. Lenz strengh is computed like:  Strengh = 256/Factor
  3307. ;          where Factor is the real amplification of the lenz.
  3308. ;
  3309. ;       2. I have used a picture with a gray scale palette at
  3310. ;          entries from 128 to 255. Emboss Bright, Depth, MinGray
  3311. ;          and MaxGray must be adjusted for others pictures.
  3312. ;
  3313.  
  3314. RADIUS          equ     52                      ; Lenz Radius in pixels.
  3315. RADIUSI         equ     (15*RADIUS)/20          ; Internal Lenz Radius.
  3316. STRENGH         equ     155                     ; Lenz Amplify (fixed 8.8).
  3317. MAXWIDTH        equ     320                     ; VGA 320x200x256 dimensions.
  3318. MAXHEIGHT       equ     200
  3319. SEED            equ     286Ah                   ; Random seed for movement.
  3320. BRIGHT          equ     150                     ; Emboss Bright Factor.
  3321. DEPTH           equ     12*256                  ; Emboss Depth Factor (8.8).
  3322. MINGRAY         equ     128                     ; Emboss Min/Max Gray
  3323. MAXGRAY         equ     255                     ; Scale Range Values.
  3324. TIMEOUT         equ     70 * 6                  ; at least 6 secs.
  3325.  
  3326. ;======================== Demo data ==========================================
  3327.  
  3328.         .data
  3329.  
  3330. LenzTable       dw      4*RADIUS*RADIUS dup(?)  ; Holds the transformation.
  3331. LenzWidth       dw      2*RADIUS dup(?)         ; Scanline widths.
  3332. RandSeed        dw      ?                       ; Random Seed.
  3333. Timer           dw      ?                       ; Timer counter.
  3334.  
  3335. ;======================== Demo Routines ======================================
  3336.  
  3337.         .code
  3338.  
  3339. ;-----------------------------------------------------------------------------
  3340. ; Random - Returns a random number of 16 bits, modified version of the
  3341. ;  ripped System unit random routine of the Borland Pascal 7.0.
  3342. ; Out:
  3343. ;  AX - random value.
  3344. ; Modified:
  3345. ;  AX, DX, Flags.
  3346. ;-----------------------------------------------------------------------------
  3347.  
  3348. Random          proc near
  3349.  
  3350.         mov     ax,[RandSeed]
  3351.         mov     dx,8405h
  3352.         mul     dx
  3353.         inc     ax
  3354.         mov     [RandSeed],ax
  3355.         ret
  3356.  
  3357. Random          endp
  3358.  
  3359. ;-----------------------------------------------------------------------------
  3360. ; WaitVRT - Waits the next VGA Vertical Retrace Period.
  3361. ;-----------------------------------------------------------------------------
  3362.  
  3363. WaitVRT         proc near
  3364.  
  3365.         mov     dx,3DAh
  3366. WaitVR1:        in      al,dx
  3367.         test    al,8
  3368.         jne     WaitVR1
  3369. WaitVR2:        in      al,dx
  3370.         test    al,8
  3371.         je      WaitVR2
  3372.         ret
  3373.  
  3374. WaitVRT         endp
  3375.  
  3376. ;-----------------------------------------------------------------------------
  3377. ; Delay - Sleeps during any amount of time. Uses the VGA Vertical retrace.
  3378. ; In:
  3379. ;   CX - Number of ticks to speed (ticks at 70Hz).
  3380. ;-----------------------------------------------------------------------------
  3381.  
  3382. Delay           proc near
  3383.  
  3384. DelayLoop:      call    WaitVRT
  3385.         loop    DelayLoop
  3386.         ret
  3387.  
  3388. Delay           endp
  3389.  
  3390. ;-----------------------------------------------------------------------------
  3391. ; SetPalette - Sets the VGA color palette.
  3392. ; In:
  3393. ;   ES:SI - Palette segment address.
  3394. ;-----------------------------------------------------------------------------
  3395.  
  3396. SetPalette      proc near
  3397.  
  3398.         push    ds
  3399.         mov     ax,es
  3400.         mov     ds,ax
  3401.         mov     dx,3C8h
  3402.         xor     al,al
  3403.         out     dx,al
  3404.         inc     dx
  3405.         mov     cx,768
  3406.         cld
  3407.         rep     outsb
  3408.         pop     ds
  3409.         ret
  3410.  
  3411. SetPalette      endp
  3412.  
  3413. ;-----------------------------------------------------------------------------
  3414. ; ShowSpray - Writes a picture on the scren using a Spray-like effect.
  3415. ; In:
  3416. ;   DX - Picture source segment.
  3417. ;-----------------------------------------------------------------------------
  3418.  
  3419. ShowSpray       proc near
  3420.  
  3421.         push    ds
  3422.         push    es
  3423.  
  3424.         mov     ds,dx
  3425.         xor     si,si
  3426.         mov     ax,0A000h
  3427.         mov     es,ax
  3428.  
  3429.         xor     cx,cx
  3430. SprayLoop:      push    cx
  3431.         xor     bx,bx
  3432. SprayLine:      push    bx
  3433.         mov     ah,cs:[RandTable+bx]
  3434.         mov     bx,cx
  3435.         mov     al,cs:[RandTable+bx]
  3436.         mov     bx,ax
  3437.         mov     di,ax
  3438.         mov     al,ds:[si+bx]
  3439.         mov     es:[di],al
  3440.         pop     bx
  3441.         inc     cl
  3442.         inc     bl
  3443.         jne     SprayLine
  3444.         pop     cx
  3445.         inc     cl
  3446.         jne     SprayLoop
  3447.  
  3448.         pop     es
  3449.         pop     ds
  3450.         ret
  3451.  
  3452. RandTable label byte
  3453.       db   83,   8,  18, 177,  13, 241, 149, 157
  3454.       db   75, 248, 254,  23,  16,  66, 207,  31
  3455.       db  211, 183,  80, 242, 218,  27,  15, 128
  3456.       db   94,  98,   4,  36, 139, 110,  85, 230
  3457.       db  212,  26,  12, 249, 169, 233, 200, 150
  3458.       db   95, 114, 130, 167, 202, 187,  76, 145
  3459.       db   62, 117, 115, 190, 209,  42, 185, 224
  3460.       db  129, 104, 108, 192, 174, 137,  44,  41
  3461.       db  141,  53, 179,  81, 181,  57, 147, 210
  3462.       db   50, 134, 156, 125, 133, 126, 106, 162
  3463.       db   20,  59,  84,   0, 151, 143, 101, 215
  3464.       db   68, 246, 189, 197,  99, 213, 112, 144
  3465.       db   28, 235, 240,  90, 154,  56, 138, 165
  3466.       db   19, 166, 159,  92, 127, 208, 105, 118
  3467.       db  119, 153, 191, 184,  87,  70,   9, 164
  3468.       db   60, 252,  96,   3, 171,  38, 136,  14
  3469.       db    7, 160,  71, 146, 102, 229, 227,  43
  3470.       db  221, 182, 217,  30, 131, 219,  61, 180
  3471.       db  195, 245, 109, 203,  24,  49, 170, 247
  3472.       db   46, 148, 122, 250, 173, 107, 255, 194
  3473.       db    6,  37,  93,  22, 168,  97, 193,   5
  3474.       db   51, 223, 116,  86,   1,  89, 121, 243
  3475.       db  140, 220,  39, 222,  65,  55,  17,  54
  3476.       db  175, 206, 214, 155, 142, 163,  25, 188
  3477.       db  178,  11, 204, 135, 201, 238,  79, 132
  3478.       db  198,  40,  21,  45, 237, 253, 152,  74
  3479.       db   32, 111,  52,  47, 236,   2, 176, 239
  3480.       db  234,  58, 100,  91, 172,  73,  82, 205
  3481.       db   34,  88,  78, 231, 232, 225,  48, 251
  3482.       db   67, 123, 244,  29, 216,  64, 196,  69
  3483.       db  199,  33,  72,  35,  10,  63, 161, 228
  3484.       db  113, 158, 120, 103, 124, 186, 226,  77
  3485.  
  3486. ShowSpray     endp
  3487.  
  3488. ;-----------------------------------------------------------------------------
  3489. ; DoEmBoss - Do the EmBoss effect into a 320x200x256 picture.
  3490. ; In:
  3491. ;  DX - Picture Source Segment.
  3492. ;-----------------------------------------------------------------------------
  3493.  
  3494. DoEmboss        proc
  3495.  
  3496.         pusha
  3497.         push    ds
  3498.  
  3499.         mov     ds,dx                   ; DS:SI = source image.
  3500.         xor     si,si
  3501.         xor     cx,cx
  3502. EmBossLine:     push    cx                      ; Y= 0..198
  3503.         xor     bx,bx
  3504. EmBossLoop:     push    bx                      ; X= 0..318
  3505.         add     bx,cx
  3506.         xor     dh,dh
  3507.         mov     dl,[si+bx]
  3508.         mov     ax,dx
  3509.         mov     dl,[si+bx+MAXWIDTH+1]
  3510.         sub     ax,dx
  3511.         mov     dx,DEPTH                ; EmBoss Depth Factor.
  3512.         imul    dx
  3513.         mov     al,ah
  3514.         mov     ah,dl
  3515.         add     ax,BRIGHT
  3516.         cmp     ax,MINGRAY              ; Check Color Range.
  3517.         jge     EmbossHigh
  3518.         mov     ax,MINGRAY
  3519. EmbossHigh:     cmp     ax,MAXGRAY
  3520.         jle     EmbossLow
  3521.         mov     ax,MAXGRAY
  3522. EmbossLow:      mov     [si+bx],al
  3523.         pop     bx
  3524.         inc     bx
  3525.         cmp     bx,MAXWIDTH-2
  3526.         jbe     EmbossLoop
  3527.         pop     cx
  3528.         add     cx,MAXWIDTH
  3529.         cmp     cx,MAXWIDTH*(MAXHEIGHT-2)
  3530.         jbe     EmbossLine
  3531.  
  3532.         pop     ds
  3533.         popa
  3534.         ret
  3535.  
  3536. DoEmboss        endp
  3537.  
  3538. ;-----------------------------------------------------------------------------
  3539. ; ShowSlide - Shows a 320x200x256 picture using a Slide Effect.
  3540. ; In:
  3541. ;  DX - Piccy Source Segment.
  3542. ;-----------------------------------------------------------------------------
  3543.  
  3544. ShowSlide       proc
  3545.         local    Level:word:MAXWIDTH,Weight:word:MAXWIDTH,\
  3546.            LevelPtr:word,WeightPtr:word
  3547.  
  3548.         pusha
  3549.         push    ds
  3550.         push    es
  3551.  
  3552.         mov     ds,dx           ; DS:SI = Source Picture.
  3553.         xor     si,si
  3554.  
  3555.         mov     ax,ss
  3556.         mov     es,ax
  3557.  
  3558.         lea     di,[Level]      ; Clear Slide Row Levels.
  3559.         mov     cx,MAXWIDTH
  3560.         cld
  3561.         xor     ax,ax
  3562.         rep     stosw
  3563.  
  3564.         lea     di,[Weight]     ; Clear Slide Row Weights.
  3565.         mov     cx,MAXWIDTH
  3566.         cld
  3567.         xor     ax,ax
  3568.         rep     stosw
  3569.  
  3570.         mov     ax,0A000h
  3571.         mov     es,ax
  3572.  
  3573. SlideLoop:      call    WaitVRT
  3574.         lea     bx,[Level]      ; Loads Level Pointer.
  3575.         mov     [LevelPtr],bx
  3576.  
  3577.         lea     bx,[Weight]     ; Loads Weight Pointer.
  3578.         mov     [WeightPtr],bx
  3579.  
  3580.         xor     cx,cx           ; For Each Column:
  3581.         xor     dx,dx
  3582.  
  3583. SlideInner:     mov     bx,[LevelPtr]   ; Level[Col] < 320*200? Skip.
  3584.         mov     ax,ss:[bx]
  3585.         cmp     ax,MAXWIDTH*MAXHEIGHT
  3586.         jae     SlideContinue
  3587.  
  3588.         inc     dx              ; Sets Flag.
  3589.  
  3590.         mov     bx,[WeightPtr]  ; Weight[Col] <> 0?
  3591.         mov     ax,ss:[bx]      ; Yes, Decrease.
  3592.         test    ax,ax           ; No, Slide Down Row.
  3593.         jz      SlideDown
  3594.         dec     ax
  3595.         mov     ss:[bx],ax
  3596.         jmp     SlideContinue
  3597.  
  3598. SlideDown:      mov     bx,[LevelPtr]   ; Level[Col] += 320
  3599.         mov     ax,ss:[bx]
  3600.         add     ax,MAXWIDTH
  3601.         mov     ss:[bx],ax
  3602.         add     ax,cx           ; DI = Col + Level[Col]
  3603.         mov     di,ax
  3604.         mov     bx,di           ; Sets New Row Weight:
  3605.         mov     al,es:[di+MAXWIDTH] ; W=ABS(VMEM[DI+320]-VMEM[DI])
  3606.         sub     al,es:[di]
  3607.         jge     SlidePos
  3608.         neg     al
  3609. SlidePos:       xor     ah,ah
  3610.         mov     bx,[WeightPtr]
  3611.         mov     ss:[bx],ax
  3612.  
  3613.         mov     bx,di           ; Put Pixel at (Col,Level[Col])
  3614.         mov     al,ds:[si+bx]
  3615.         mov     es:[di],al
  3616.  
  3617. SlideContinue:  add     [LevelPtr],2    ; Next Column.
  3618.         add     [WeightPtr],2
  3619.         inc     cx
  3620.         cmp     cx,MAXWIDTH
  3621.         jb      SlideInner
  3622.  
  3623.         test    dx,dx           ; Screen 100% filled?
  3624.         jnz     SlideLoop       ; No, Repeat.
  3625.  
  3626.         pop     es
  3627.         pop     ds
  3628.         popa
  3629.         ret
  3630.  
  3631. ShowSlide       endp
  3632.  
  3633.  
  3634. ;-----------------------------------------------------------------------------
  3635. ; GenLenz - Renders the Transformation matrix used during animation.
  3636. ;
  3637. ; Note: The square root is calculated using the Newton iteration
  3638. ;       aproximation algorithm:
  3639. ;                                        y² + (r² - x²)
  3640. ;               y² ≡ r² - x²  ══   y ≈ ────────────────
  3641. ;                                             2y
  3642. ;
  3643. ;       We performs only one iteration using a initial «y» value
  3644. ;       near to the real square root wanted.
  3645. ;-----------------------------------------------------------------------------
  3646.  
  3647. GenLenz         proc near
  3648.         local    X:word,Y:word,R:word,Dist:Word,AddX:word,AddY:word
  3649.  
  3650.         mov      ax,ds
  3651.         mov      es,ax
  3652.         cld
  3653.  
  3654.         xor      ax,ax                  ; Fills the whole rectangle
  3655.         lea      di,[LenzTable]         ; matrix with a linear
  3656.         mov      cx,2*RADIUS            ; transformation.
  3657. MakLinLoop:     push     ax
  3658.         push     cx
  3659.         mov      cx,2*RADIUS
  3660. MakLinRow:      stosw
  3661.         inc      ax
  3662.         loop     MakLinRow
  3663.         pop      cx
  3664.         pop      ax
  3665.         add      ax,MAXWIDTH
  3666.         loop     MakLinLoop
  3667.  
  3668.         mov      [X],RADIUS             ; makes the scanlines
  3669.         mov      [Y],0                  ; widths of the lenz
  3670. MakWidth:       cmp      [Y],RADIUS             ; with radius RADIUS.
  3671.         jge      MakXWidth
  3672.         mov      ax,[X]
  3673.         mov      bx,RADIUS              ; LenzWidth[Radius+Y] = X
  3674.         add      bx,[Y]
  3675.         shl      bx,1
  3676.         mov      [LenzWidth+bx],ax
  3677.         mov      bx,RADIUS              ; LenzWidth[Radius-Y-1] = X
  3678.         sub      bx,[Y]
  3679.         dec      bx
  3680.         shl      bx,1
  3681.         mov      [LenzWidth+bx],ax
  3682.         mov      ax,[Y]                 ; X² = Radius² - Y²
  3683.         imul     ax
  3684.         mov      bx,ax
  3685.         mov      ax,[X]
  3686.         imul     ax
  3687.         sub      ax,bx
  3688.         add      ax,RADIUS*RADIUS
  3689.         sar      ax,1
  3690.         cwd
  3691.         mov      bx,[X]
  3692.         idiv     bx
  3693.         mov      [X],ax
  3694.         inc      [Y]                    ; Y = Y+1
  3695.         jmp      MakWidth
  3696. MakXWidth:
  3697.  
  3698.  
  3699.         mov     [X],RADIUSI             ; Makes the transformation
  3700.         mov     [Y],0                   ; for the Lenz of radius
  3701. MakLoop:        cmp     [Y],RADIUSI             ; RADIUSY. Notice that
  3702.         jge     MakExit                 ; this lets a border
  3703.                         ; used for restoring the
  3704.                         ; background while moving
  3705.                         ; the lenz into the screen.
  3706.  
  3707.         mov     ax,[X]                  ; compute the scanline
  3708.         mov     dx,6                    ; width adjusting with
  3709.         imul    dx                      ; an aspect ratio of 6/5.
  3710.         mov     bx,5
  3711.         idiv    bx
  3712.         mov     [R],ax
  3713.  
  3714.         mov     [Dist],0
  3715.         mov     [AddX],0
  3716.         mov     [AddY],ax
  3717.  
  3718. MakLine:        mov     ax,[R]
  3719.         cmp     [AddX],ax
  3720.         jge     MakLineBreak
  3721.  
  3722.         ; si = @LenzTable[0,RADIUS-Y-1]
  3723.  
  3724.         lea     si,[LenzTable]
  3725.         mov     ax,RADIUS
  3726.         sub     ax,[Y]
  3727.         dec     ax
  3728.         imul    ax,2*RADIUS
  3729.         add     si,ax
  3730.         shl     si,1
  3731.  
  3732.         ; di = @LenzTable[0,RADIUS+Y]
  3733.  
  3734.         lea     di,[LenzTable]
  3735.         mov     ax,RADIUS
  3736.         add     ax,[Y]
  3737.         imul    ax,2*RADIUS
  3738.         add     di,ax
  3739.         shl     di,1
  3740.  
  3741.         ; Lenz[RADIUS+AddX,RADIUS-Y-1] = RADIUS+Hi(Dist) +
  3742.         ;     MAXWIDTH * (RADIUS-1-STRENGH*Y)
  3743.  
  3744.         mov     bx,RADIUS
  3745.         add     bx,[AddX]
  3746.         shl     bx,1
  3747.         mov     ax,[Y]
  3748.         imul    ax,STRENGH
  3749.         sar     ax,8
  3750.         imul    ax,MAXWIDTH
  3751.         neg     ax
  3752.         add     ax,RADIUS+MAXWIDTH*(RADIUS-1)
  3753.         mov     dx,[Dist]
  3754.         shr     dx,8
  3755.         add     ax,dx
  3756.         mov     [si+bx],ax
  3757.  
  3758.         ; Lenz[RADIUS-AddX-1,RADIUS-Y-1] = RADIUS-Hi(Dist)-1+
  3759.         ;     MAXWIDTH * (RADIUS-1-STRENGH*Y)
  3760.  
  3761.         mov     bx,RADIUS
  3762.         sub     bx,[AddX]
  3763.         dec     bx
  3764.         shl     bx,1
  3765.         mov     ax,[Y]
  3766.         imul    ax,STRENGH
  3767.         sar     ax,8
  3768.         imul    ax,MAXWIDTH
  3769.         neg     ax
  3770.         add     ax,RADIUS+MAXWIDTH*(RADIUS-1)
  3771.         mov     dx,[Dist]
  3772.         shr     dx,8
  3773.         sub     ax,dx
  3774.         dec     ax
  3775.         mov     [si+bx],ax
  3776.  
  3777.         ; LenzTable[RADIUS+AddX,RADIUS+Y] = RADIUS+Hi(Dist)+
  3778.         ;    MAXWIDTH * (RADIUS + STRENGH*Y)
  3779.  
  3780.         mov     bx,RADIUS
  3781.         add     bx,[AddX]
  3782.         shl     bx,1
  3783.         mov     ax,[Y]
  3784.         imul    ax,STRENGH
  3785.         sar     ax,8
  3786.         imul    ax,MAXWIDTH
  3787.         add     ax,RADIUS+MAXWIDTH*RADIUS
  3788.         mov     dx,[Dist]
  3789.         shr     dx,8
  3790.         add     ax,dx
  3791.         mov     [di+bx],ax
  3792.  
  3793.         ; LenzTable[RADIUS-AddX-1,RADIUS+Y] = RADIUS-Hi(Dist)-1+
  3794.         ;    MAXWIDTH * (RADIUS+STRENGH*Y)
  3795.  
  3796.         mov     bx,RADIUS
  3797.         sub     bx,[AddX]
  3798.         dec     bx
  3799.         shl     bx,1
  3800.         mov     ax,[Y]
  3801.         imul    ax,STRENGH
  3802.         sar     ax,8
  3803.         imul    ax,MAXWIDTH
  3804.         add     ax,RADIUS+MAXWIDTH*RADIUS
  3805.         mov     dx,[Dist]
  3806.         shr     dx,8
  3807.         sub     ax,dx
  3808.         dec     ax
  3809.         mov     [di+bx],ax
  3810.  
  3811.         ; Dist = Dist + (Strengh*Radius)/dY
  3812.  
  3813.         mov     ax,STRENGH*RADIUS
  3814.         cwd
  3815.         mov     bx,[AddY]
  3816.         idiv    bx
  3817.         add     [Dist],ax
  3818.  
  3819.         mov     ax,[AddY]               ; dY² = R² - dX²
  3820.         imul    ax
  3821.         mov     bx,ax
  3822.         mov     ax,[AddX]
  3823.         imul    ax
  3824.         sub     bx,ax
  3825.         mov     ax,[R]
  3826.         imul    ax
  3827.         add     ax,bx
  3828.         sar     ax,1
  3829.         cwd
  3830.         mov     bx,[AddY]
  3831.         idiv    bx
  3832.         mov     [AddY],ax
  3833.         inc     [AddX]                  ; dX = dX+1
  3834.         jmp     MakLine
  3835.  
  3836. MakLineBreak:   mov     ax,[X]                  ; X² = Radius'² - Y²
  3837.         imul    ax
  3838.         mov     bx,ax
  3839.         mov     ax,[Y]
  3840.         imul    ax
  3841.         sub     bx,ax
  3842.         mov     ax,RADIUSI*RADIUSI
  3843.         add     ax,bx
  3844.         sar     ax,1
  3845.         cwd
  3846.         mov     bx,[X]
  3847.         idiv    bx
  3848.         mov     [X],ax
  3849.         inc     [Y]                     ; Y = Y+1
  3850.         jmp     MakLoop
  3851. MakExit:        ret
  3852.  
  3853. GenLenz         endp
  3854.  
  3855. ;-----------------------------------------------------------------------------
  3856. ; WriteLenz - Writes the Lenz using the transformation matrix.
  3857. ; In:
  3858. ;  DI  - Starting offset location of the lenz.
  3859. ;  DX  - Virtual picture used like background.
  3860. ;-----------------------------------------------------------------------------
  3861.  
  3862. WriteLenz       proc near
  3863.  
  3864.         push    bp
  3865.         mov     ax,0A000h
  3866.         mov     es,ax
  3867.         lea     bx,[LenzTable]
  3868.         lea     si,[LenzWidth]
  3869.         mov     bp,di
  3870.         mov     cx,2*RADIUS
  3871.         cld
  3872. WriteLoop:      push    bx
  3873.         push    cx
  3874.         push    si
  3875.         push    di
  3876.         cmp     di,MAXWIDTH*MAXHEIGHT
  3877.         jae     WriteBreak
  3878.         mov     cx,[si]                 ; gets the scanline width.
  3879.         mov     ax,RADIUS
  3880.         sub     ax,cx
  3881.         add     di,ax
  3882.         add     bx,ax
  3883.         add     bx,ax
  3884. WriteLine:      push    es
  3885.         mov     es,dx
  3886.         mov     si,[bx]
  3887.         mov     al,es:[bp+si]
  3888.         mov     si,[bx+2]
  3889.         mov     ah,es:[bp+si]
  3890.         add     bx,4
  3891.         pop     es
  3892.         stosw
  3893.         loop    WriteLine
  3894. WriteBreak:     pop     di
  3895.         pop     si
  3896.         pop     cx
  3897.         pop     bx
  3898.         add     bx,4*RADIUS
  3899.         add     si,2
  3900.         add     di,MAXWIDTH
  3901.         loop    WriteLoop
  3902.         pop     bp
  3903.         ret
  3904.  
  3905. WriteLenz       endp
  3906.  
  3907.  
  3908. ;-----------------------------------------------------------------------------
  3909. ; LenzDemo - Performs the demostration.
  3910. ; In:
  3911. ;   DS      - Data Segment.
  3912. ;   PicSeg  - VGA 320x200x256 Picture used for Background.
  3913. ;   PalSeg  - Color Palette of the Picture.
  3914. ;-----------------------------------------------------------------------------
  3915.  
  3916. LenzDemo        proc  PicSeg:word,PalSeg:dword
  3917.         local   X:word,Y:word,AddX:word,AddY:word
  3918.  
  3919.         mov     ax,13h                  ; sets 320x200x256 mode.
  3920.         int     10h
  3921.  
  3922.         call    GenLenz                 ; creates the lenz matrix.
  3923.  
  3924.         mov     cx,35                   ; waits 0.5 seconds.
  3925.         call    Delay
  3926.  
  3927.         les     si,[PalSeg]             ; sets the palette.
  3928.         call    SetPalette
  3929.  
  3930.         mov     dx,[PicSeg]             ; writes the picture
  3931.         call    ShowSpray               ; to the screen.
  3932.  
  3933.         mov     [RandSeed],SEED         ; Randomize.
  3934.         mov     [Timer],0
  3935.  
  3936.         mov     [X],RADIUS
  3937.         mov     [Y],RADIUS
  3938.         mov     [AddX],3
  3939.         mov     [AddY],2
  3940.  
  3941. DemoLoop:       call    WaitVRT                 ; Waits VR period.
  3942.  
  3943.         mov     ax,[Y]                  ; outputs the lenz
  3944.         sub     ax,RADIUS               ; crystall ball at
  3945.         mov     dx,MAXWIDTH             ; center coordinates (X,Y).
  3946.         mul     dx
  3947.         add     ax,[X]
  3948.         sub     ax,RADIUS
  3949.         mov     di,ax
  3950.         mov     dx,[PicSeg]
  3951.         call    WriteLenz
  3952.  
  3953. AdjustX:        mov     ax,[X]                  ; adjust the X coord.
  3954.         add     ax,[AddX]
  3955.         cmp     ax,RADIUS
  3956.         jb      ChangeX
  3957.         cmp     ax,MAXWIDTH-RADIUS
  3958.         ja      ChangeX
  3959.         mov     [X],ax
  3960.         jmp     AdjustY
  3961. ChangeX:        call    Random
  3962.         shr     ax,15
  3963.         inc     ax
  3964.         cmp     [AddX],0
  3965.         jl      SetAddX
  3966.         neg     ax
  3967. SetAddX:        mov     [AddX],ax
  3968.  
  3969. AdjustY:        mov     ax,[Y]                  ; adjust the Y coord.
  3970.         add     ax,[AddY]
  3971.         cmp     ax,RADIUSI
  3972.         jb      ChangeY
  3973.         cmp     ax,MAXHEIGHT-RADIUSI
  3974.         ja      ChangeY
  3975.         mov     [Y],ax
  3976.         jmp     Continue
  3977. ChangeY:        call    Random
  3978.         and     ax,1
  3979.         inc     ax
  3980.         cmp     [AddY],0
  3981.         jl      SetAddY
  3982.         neg     ax
  3983. SetAddY:        mov     [AddY],ax
  3984.  
  3985. Continue:       inc     [Timer]                 ; timeout?
  3986.         cmp     [Timer],TIMEOUT
  3987.         jae     DemoExit
  3988.  
  3989.         mov     ah,1                    ; any key pressed?
  3990.         int     16h
  3991.         je      DemoLoop
  3992.         mov     ah,0                    ; flush keyboard.
  3993.         int     16h
  3994.         
  3995. DemoExit:       mov     dx,[PicSeg]             ; EmBoss the Piccy.
  3996.         call    DoEmboss
  3997.  
  3998.         mov     dx,[PicSeg]             ; SlideDown the Piccy.
  3999.         call    ShowSlide
  4000.  
  4001.         mov     cx,70                   ; Sleep a while..
  4002.         call    Delay
  4003.  
  4004.         mov     es,[PicSeg]             ; Blanks the picture.
  4005.         xor     di,di
  4006.         mov     cx,MAXWIDTH*MAXHEIGHT
  4007.         xor     ax,ax
  4008.         cld
  4009.         rep     stosb
  4010.  
  4011.         mov     dx,[PicSeg]             ; Clears the Screen.
  4012.         call    ShowSpray
  4013.  
  4014.         mov     cx,35                   ; waits 0.5 seconds.
  4015.         call    Delay
  4016.  
  4017.         mov     ax,03h                  ; restores 80x25x16 mode.
  4018.         int     10h
  4019.         ret
  4020.  
  4021. LenzDemo        endp
  4022.  
  4023.  
  4024. ;-----------------------------------------------------------------------------
  4025. ; Start - Startup Code called from DOS.
  4026. ; In:
  4027. ;   ES - Program Segment Prefix.
  4028. ;-----------------------------------------------------------------------------
  4029.  
  4030. Start           proc
  4031.  
  4032.         mov     ax,@Data
  4033.         mov     ds,ax
  4034.         call    LenzDemo,SEG LenzPic,SEG LenzPal,OFFSET LenzPal
  4035.         mov     ax,4C00h
  4036.         int     21h
  4037.  
  4038. Start           endp
  4039.  
  4040.         end     Start
  4041. ;=============================================================================
  4042. ; dblscrl.asm - Double Horizontal Scroller.
  4043. ;                                                   File created: 11/21/93
  4044. ; Copyright (c) 1993, Carlos Hasan                 Last modified: 11/21/93
  4045. ;
  4046. ; Description:
  4047. ;  Another Horizontal Scroller using a Logo Picture of 256x128x256.
  4048. ;
  4049. ; Dependency:
  4050. ;  Requires Turbo Assembler 3.2 or later to be assembled.
  4051. ;  Dependant on the IBM PC 286 or better processor.
  4052. ;=============================================================================
  4053.  
  4054.     ideal
  4055.     model   small,pascal
  4056.     jumps
  4057.     p286
  4058.  
  4059.     dosseg
  4060.     stack   1024
  4061.     ends
  4062.  
  4063.     global  LogoRAW:byte            ; LOGO.RAW linked file.
  4064.     global  LogoPAL:byte            ; LOGO.PAL linked file.
  4065.  
  4066. ;=========================== Data Segment ====================================
  4067.  
  4068.     dataseg
  4069.  
  4070. SCREENWIDTH     equ  (2*320)            ; Logical Screen Width
  4071.                     ; Enough Space for Double-Window
  4072. LOGOWIDTH       equ  256                ; Logo Piccy Dimensions.
  4073. LOGOHEIGHT      equ  128
  4074. SCROLLSPEED     equ  2                  ; Scrollers Speed.
  4075.  
  4076. ;=========================== Code Segment ====================================
  4077.  
  4078.     codeseg
  4079.  
  4080. ;-----------------------------------------------------------------------------
  4081. ; SetModeX - Sets the VGA in Tweaked ModeX 320x400x256.
  4082. ;-----------------------------------------------------------------------------
  4083.  
  4084. proc    SetModeX
  4085.     mov     ax,0013h                ; Sets VGA linear 320x200x256
  4086.     int     10h
  4087.     mov     dx,3C4h                 ; Disable Chain-Four
  4088.     mov     ax,0604h
  4089.     out     dx,ax
  4090.     mov     dx,3C4h                 ; Enable Write to All Four Planes
  4091.     mov     ax,0F02h
  4092.     out     dx,ax
  4093.     mov     ax,0A000h               ; Clear Display Memory
  4094.     mov     es,ax
  4095.     xor     di,di
  4096.     xor     ax,ax
  4097.     mov     cx,8000h
  4098.     cld
  4099.     rep     stosw
  4100.     mov     dx,3D4h                 ; Reprogram CRT Controller:
  4101.     mov     ax,00014h               ; turn off dword mode
  4102.     out     dx,ax
  4103.     mov     ax,0e317h               ; turn on byte mode
  4104.     out     dx,ax
  4105.     mov     ax,00009h               ; cell height
  4106.     out     dx,ax
  4107.     mov     dx,3D4h                 ; Sets Logical Screen Width
  4108.     mov     al,13h
  4109.     mov     ah,SCREENWIDTH/8
  4110.     out     dx,ax
  4111.     ret
  4112. endp    SetModeX
  4113.  
  4114. ;-----------------------------------------------------------------------------
  4115. ; SetStartAddr - Sets the VGA Start Address Register.
  4116. ; In:
  4117. ;  BX = Start Address.
  4118. ;-----------------------------------------------------------------------------
  4119.  
  4120. proc    SetStartAddr
  4121.     mov     dx,3D4h                 ; Sets VGA Start Address
  4122.     mov     al,0Dh
  4123.     mov     ah,bl
  4124.     out     dx,ax
  4125.     dec     al
  4126.     mov     ah,bh
  4127.     out     dx,ax
  4128.     ret
  4129. endp    SetStartAddr
  4130.  
  4131. ;-----------------------------------------------------------------------------
  4132. ; WaitVR - Waits the Next VGA Vertical Retrace Ending.
  4133. ;-----------------------------------------------------------------------------
  4134.  
  4135. proc    WaitVR
  4136.     mov     dx,3DAh
  4137. WaitStartVR:
  4138.     in      al,dx
  4139.     test    al,8
  4140.     je      WaitStartVR
  4141. WaitEndVR:
  4142.     in      al,dx
  4143.     test    al,8
  4144.     jne     WaitEndVR
  4145.     ret
  4146. endp    WaitVR
  4147.  
  4148. ;-----------------------------------------------------------------------------
  4149. ; DrawLogo - Writes on Screen the Logo Picture.
  4150. ;-----------------------------------------------------------------------------
  4151.  
  4152. proc    DrawLogo
  4153.     pusha
  4154.     push    ds
  4155.     push    es
  4156.     call    WaitVR
  4157.     mov     ax,SEG LogoPAL          ; Sets the Logo Palette
  4158.     mov     ds,ax
  4159.     mov     si,OFFSET LogoPAL
  4160.     mov     cx,768
  4161.     mov     dx,3C8h
  4162.     xor     al,al
  4163.     out     dx,al
  4164.     inc     dx
  4165.     rep     outsb
  4166.     mov     ax,SEG LogoRAW          ; Load LogoRAW Address
  4167.     mov     ds,ax
  4168.     mov     si,OFFSET LogoRAW
  4169.     mov     ax,0A000h               ; Load Display Memory Segment
  4170.     mov     es,ax
  4171.     mov     ax,1102h
  4172. DrawPlanes:
  4173.     push    ax
  4174.     push    si
  4175.     mov     dx,3C4h                 ; Select Write Plane
  4176.     out     dx,ax
  4177.     mov     di,(320+SCREENWIDTH*220)/4
  4178.     mov     bx,LOGOHEIGHT           ; Write Pixels
  4179. DrawLoop:
  4180.     mov     cx,LOGOWIDTH/4
  4181. DrawRow:
  4182.     mov     al,[ds:si]
  4183.     mov     [es:di],al
  4184.     add     si,4
  4185.     inc     di
  4186.     loop    DrawRow
  4187.     add     di,(SCREENWIDTH-LOGOWIDTH)/4
  4188.     dec     bx
  4189.     jne     DrawLoop
  4190.     pop     si
  4191.     pop     ax
  4192.     inc     si
  4193.     add     ah,ah                   ; Next Plane.
  4194.     jnc     DrawPlanes
  4195.     pop     es
  4196.     pop     ds
  4197.     popa
  4198.     ret
  4199. endp    DrawLogo
  4200.  
  4201. ;-----------------------------------------------------------------------------
  4202. ; Start - Start the Demostration. Called from DOS.
  4203. ;-----------------------------------------------------------------------------
  4204.  
  4205. proc    Start
  4206.     mov     ax,@Data                ; Sets Data Segment.
  4207.     mov     ds,ax
  4208.     mov     bx,sp                   ; Shrink Program Memory Block.
  4209.     shr     bx,4
  4210.     inc     bx
  4211.     mov     ax,ss
  4212.     mov     dx,es
  4213.     sub     ax,dx
  4214.     add     bx,ax
  4215.     mov     ah,4Ah
  4216.     int     21h
  4217.     call    SetModeX                ; Sets VGA ModeX.
  4218.     call    DrawLogo                ; Draw Logo.
  4219.     mov     cx,35                   ; Sleep about 0.5 sec
  4220. SleepEntry:
  4221.     call    WaitVR
  4222.     loop    SleepEntry
  4223.     mov     si,0                    ; Starting Scrollers
  4224.     mov     di,SCREENWIDTH*164/4    ; Address Offsets.
  4225. DemoLoop:
  4226.     call    WaitVR                  ; Waits Vertical Retrace.
  4227.     mov     bx,si                   ; Show Upper Scroller.
  4228.     call    SetStartAddr
  4229.     call    WaitVR                  ; Waits Vertical Retrace.
  4230.     mov     bx,di                   ; Show Bottom Scroller
  4231.     call    SetStartAddr
  4232.     add     si,SCROLLSPEED          ; Move Scrollers to the Left&Right.
  4233.     sub     di,SCROLLSPEED
  4234.     cmp     si,SCREENWIDTH/4        ; Enough Frames?
  4235.     jbe     DemoLoop
  4236. DemoExit:
  4237.     mov     cx,35                   ; Sleep about 0.5 sec
  4238. SleepExit:
  4239.     call    WaitVR
  4240.     loop    SleepExit
  4241.     mov     ax,0003h                ; Set Text Mode.
  4242.     int     10h
  4243.     mov     ax,4C00h                ; Exit to DOS.
  4244.     int     21h
  4245. endp    Start
  4246.  
  4247.     end     Start
  4248. ;=============================================================================
  4249. ; land.asm - Landscape fractal demostration.
  4250. ;                                                    File created:  9/30/93
  4251. ; Copyright (c) 1993, Carlos Hasan                  Last modified: 10/22/93
  4252. ;
  4253. ; Description:
  4254. ;   This file implements a fractal 3D landscape rotation using the basic
  4255. ;   plasma routines and 3D rotations. This uses the VGA 320x200x256 mode.
  4256. ;
  4257. ; Portability:
  4258. ;  Requires Turbo Assembler 3.2 or better to be assembled.
  4259. ;  Dependent on the IBM PC 286 and the VGA graphics card.
  4260. ;
  4261. ; Modifications:
  4262. ;  10/22/93  - Startup Code. Now is an Standalone Program.
  4263. ;=============================================================================
  4264.  
  4265.         .model  small,pascal
  4266.         .286
  4267.  
  4268.         dosseg                          ; used to link like
  4269.         .stack  1024                    ; an standalone program.
  4270.  
  4271.         global  DrawPlasma:proc         ; in PLASMA.ASM file.
  4272.         global  LandScape:proc
  4273.  
  4274. ;===================== Demo equates and data =================================
  4275.  
  4276. TIMEOUT         equ     70 * 10                 ; about 10 sec for timeout.
  4277. FADESPEED       equ     6                       ; fade speed.
  4278. SCREENWIDTH     equ     320                     ; screen dimensions.
  4279. SCREENHEIGHT    equ     200
  4280. TRIGSHIFT       equ     6                       ; sin/cos shift factor.
  4281. LANDSCAPEX      equ     320                     ; landscape grid dimensions.
  4282. LANDSCAPEY      equ     200
  4283. WATERLEVEL      equ     128                     ; plasma water level.
  4284. PLASMASEED      equ     8945h                   ; plasma random seed.
  4285. CENTERX         equ     160                     ; screen grid center
  4286. CENTERY         equ     140                     ; position.
  4287. GRIDX           equ     32                      ; screen grid dimensions
  4288. GRIDY           equ     32                      ; and gaps length.
  4289. GRIDDX          equ     6
  4290. GRIDDY          equ     6
  4291.  
  4292.         .data
  4293.  
  4294.         include sincos.inc              ; sinus/cosinus table.
  4295.  
  4296. LandSeg         dw      ?                       ; landscape levels.
  4297. Pixels          dw      GRIDX * GRIDY dup (?)   ; screen pixels locations.
  4298. Palette         db      768 dup (?)             ; hold the color palette.
  4299. FromPalette     db      768 dup (?)             ; fading-palettes.
  4300. ToPalette       db      768 dup (?)
  4301. Timer           dw      ?                       ; timer counter.
  4302.  
  4303. ;======================= Demo routines =======================================
  4304.  
  4305.         .code
  4306.  
  4307. ;-----------------------------------------------------------------------------
  4308. ; WaitVRT - Waits the VGA vertical retrace period.
  4309. ;-----------------------------------------------------------------------------
  4310.  
  4311. WaitVRT         proc near
  4312.  
  4313.         mov     dx,3DAh
  4314. WaitVRT1:       in      al,dx                   ; wait the start of
  4315.         test    al,8                    ; vertical retrace.
  4316.         jz      WaitVRT1
  4317. WaitVRT2:       in      al,dx                   ; wait the end of
  4318.         test    al,8                    ; vertical retrace.
  4319.         jnz     WaitVRT2
  4320.         ret
  4321.  
  4322. WaitVRT         endp
  4323.  
  4324. ;-----------------------------------------------------------------------------
  4325. ; SetPalette - set the 256 entries of the VGA color palette.
  4326. ; In:
  4327. ;   DS:SI - Palette structure address.
  4328. ;-----------------------------------------------------------------------------
  4329.  
  4330. SetPalette      proc near
  4331.  
  4332.         mov     cx,768
  4333.         mov     dx,3C8h
  4334.         xor     al,al
  4335.         out     dx,al
  4336.         call    WaitVRT
  4337.         mov     dx,3C9h
  4338.         rep     outsb
  4339.         ret
  4340.  
  4341. SetPalette      endp
  4342.  
  4343. ;-----------------------------------------------------------------------------
  4344. ; FadeTo - Fade palette effect.
  4345. ; In:
  4346. ;  FromPalette - Source palette.
  4347. ;  ToPalette   - Destination palette.
  4348. ;-----------------------------------------------------------------------------
  4349.  
  4350. FadeTo         proc near
  4351.  
  4352. FadeLoop:       lea     si,[FromPalette]
  4353.         call    SetPalette
  4354.         mov     cx,768
  4355.         xor     dx,dx
  4356.         xor     bx,bx
  4357. FadeColor:      mov     al,[FromPalette+bx]
  4358.         mov     ah,[ToPalette+bx]
  4359.         cmp     al,ah
  4360.         je      SkipFade
  4361.         ja      FadeOut
  4362. FadeIn:         add     al,FADESPEED
  4363.         cmp     al,ah
  4364.         jl      SetColor
  4365.         mov     al,ah
  4366.         jmp     SetColor
  4367. FadeOut:        sub     al,FADESPEED
  4368.         cmp     al,ah
  4369.         jg      SetColor
  4370.         mov     al,ah
  4371.         jmp     SetColor
  4372. SetColor:       mov     [FromPalette+bx],al
  4373.         inc     dx
  4374. SkipFade:       inc     bx
  4375.         loop    FadeColor
  4376.         test    dx,dx
  4377.         jne     FadeLoop
  4378.         ret
  4379.  
  4380. FadeTo          endp
  4381.  
  4382. ;-----------------------------------------------------------------------------
  4383. ; FlashIn - Flash fade-in effect.
  4384. ; In:
  4385. ;  Palette - Source palette.
  4386. ;-----------------------------------------------------------------------------
  4387.  
  4388. FlashIn         proc near
  4389.  
  4390.         mov     ax,ds
  4391.         mov     es,ax
  4392.         cld
  4393.         lea     di,[FromPalette]        ; fade from black to white.
  4394.         mov     cx,768
  4395.         mov     al,00h
  4396.         rep     stosb
  4397.         lea     di,[ToPalette]
  4398.         mov     cx,768
  4399.         mov     al,3Fh
  4400.         rep     stosb
  4401.         call    FadeTo
  4402.         lea     di,[FromPalette]        ; fade from white to
  4403.         mov     cx,768                  ; destination palette.
  4404.         mov     al,3Fh
  4405.         rep     stosb
  4406.         lea     si,[Palette]
  4407.         lea     di,[ToPalette]
  4408.         mov     cx,768
  4409.         rep     movsb
  4410.         call    FadeTo
  4411.         ret
  4412.  
  4413. FlashIn         endp
  4414.  
  4415. ;-----------------------------------------------------------------------------
  4416. ; FlashOut - Flash fade-out effect.
  4417. ; In:
  4418. ;  Palette - Source palette.
  4419. ;-----------------------------------------------------------------------------
  4420.  
  4421. FlashOut        proc near
  4422.  
  4423.         mov     ax,ds
  4424.         mov     es,ax
  4425.         cld
  4426.         lea     di,[ToPalette]          ; fade from source palette
  4427.         mov     cx,768                  ; to white palette.
  4428.         mov     al,3Fh
  4429.         rep     stosb
  4430.         lea     si,[Palette]
  4431.         lea     di,[FromPalette]
  4432.         mov     cx,768
  4433.         rep     movsb
  4434.         call    FadeTo
  4435.         lea     di,[FromPalette]        ; fade from white to black.
  4436.         mov     cx,768
  4437.         mov     al,3Fh
  4438.         rep     stosb
  4439.         lea     di,[ToPalette]
  4440.         mov     cx,768
  4441.         mov     al,00h
  4442.         rep     stosb
  4443.         call    FadeTo
  4444.         ret
  4445.  
  4446. FlashOut        endp
  4447.  
  4448. ;-----------------------------------------------------------------------------
  4449. ; GenLandscape - This routines generates the lanscape surface using the
  4450. ;   plasma routines basically and checks that all the mountain levels
  4451. ;   are in the right range.
  4452. ; In:
  4453. ;  LandSeg - Segment addressing for the landscape.
  4454. ;-----------------------------------------------------------------------------
  4455.  
  4456. GenLandscape    proc near
  4457.  
  4458.         mov     ax,[LandSeg]            ; clear landscape area.
  4459.         mov     es,ax
  4460.         xor     di,di
  4461.         xor     ax,ax
  4462.         mov     cx,LANDSCAPEX * LANDSCAPEY
  4463.         cld
  4464.         rep     stosb
  4465.  
  4466.         ; draw initial plasma landscape.
  4467.         call    DrawPlasma,0,0,LANDSCAPEX-1,LANDSCAPEY-1, \
  4468.                          PLASMASEED,[LandSeg]
  4469.  
  4470.         ; adjust levels for the real landscape.
  4471.  
  4472.         mov     ax,[LandSeg]
  4473.         mov     es,ax
  4474.         xor     di,di
  4475.         mov     cx,LANDSCAPEX * LANDSCAPEY
  4476.         cld
  4477. AdjLoop:        mov     al,es:[di]
  4478.         sub     al,WATERLEVEL
  4479.         test    al,al
  4480.         jge     AdjLevel
  4481.         xor     al,al
  4482. AdjLevel:       xor     ah,ah
  4483.         imul    ax,192
  4484.         inc     ah
  4485.         mov     es:[di],ah
  4486.         inc     di
  4487.         loop    AdjLoop
  4488.         ret
  4489.  
  4490. GenLandscape    endp
  4491.  
  4492.  
  4493. ;-----------------------------------------------------------------------------
  4494. ; DrawLandscape - Draws a region of the landscape on the screen starting
  4495. ;   at the specified position and rotation angles. The clipping support
  4496. ;   have been removed for speed.
  4497. ; In:
  4498. ;   (PosX,PosY) - Landscape starting position.
  4499. ;   AngleY      - Inclination angle.
  4500. ;   AngleZ      - Spin angle.
  4501. ;-----------------------------------------------------------------------------
  4502.  
  4503. DrawLandscape   proc near PosX:word,PosY:word, AngleY:word,AngleZ:word
  4504.         local SinY:word,SinZ:word,CosY:word,CosZ:word, \
  4505.               YIAdd:word,YJAdd:word,ZIAdd:word,ZJAdd:word, \
  4506.               Y0:word,Z0:word,Y:word,Z:word
  4507.  
  4508.         mov     bx,[AngleY]             ; compute rotation
  4509.         mov     al,[SinTable+bx]        ; parameters.
  4510.         cbw
  4511.         mov     [SinY],ax
  4512.         mov     al,[CosTable+bx]
  4513.         cbw
  4514.         mov     [CosY],ax
  4515.  
  4516.         mov     bx,[AngleZ]
  4517.         mov     al,[SinTable+bx]
  4518.         cbw
  4519.         mov     [SinZ],ax
  4520.         mov     al,[CosTable+bx]
  4521.         cbw
  4522.         mov     [CosZ],ax
  4523.  
  4524.         mov     ax,[SinZ]               ; yiadd = griddx * sinz
  4525.         imul    ax,GRIDDX
  4526.         mov     [YIAdd],ax
  4527.         mov     ax,[CosZ]               ; yjadd = griddy * cosz
  4528.         imul    ax,GRIDDY
  4529.         mov     [YJAdd],ax
  4530.         mov     ax,[CosZ]               ; ziadd = griddx * cosz * siny
  4531.         mov     dx,[SinY]
  4532.         imul    dx
  4533.         imul    ax,GRIDDX
  4534.         sar     ax,TRIGSHIFT
  4535.         mov     [ZIAdd],ax
  4536.         mov     ax,[SinZ]               ; zjadd = -griddy * sinz * siny
  4537.         mov     dx,[SinY]
  4538.         imul    dx
  4539.         imul    ax,-GRIDDY
  4540.         sar     ax,TRIGSHIFT
  4541.         mov     [ZJAdd],ax
  4542.  
  4543.         mov     ax,[YIAdd]              ; compute starting grid
  4544.         imul    ax,-GRIDX/2             ; corner position.
  4545.         mov     dx,[YJAdd]
  4546.         imul    dx,-GRIDY/2
  4547.         add     ax,dx
  4548.         mov     [Y0],ax
  4549.         mov     ax,[ZIAdd]
  4550.         imul    ax,-GRIDX/2
  4551.         mov     dx,[ZJAdd]
  4552.         imul    dx,-GRIDY/2
  4553.         add     ax,dx
  4554.         mov     [Z0],ax
  4555.  
  4556.         mov     ax,[LandSeg]            ; es = landscape segment.
  4557.         mov     es,ax
  4558.  
  4559.         lea     si,[Pixels]             ; ds:si = pixels offsets.
  4560.  
  4561.         mov     di,[PosY]               ; store offset
  4562.         imul    di,LANDSCAPEX           ; just for speed.
  4563.         add     di,[PosX]
  4564.  
  4565.         mov     cx,GRIDX
  4566. ForI:           push    cx
  4567.         mov     ax,[Y0]                 ; y = y0
  4568.         mov     [Y],ax
  4569.         mov     ax,[Z0]                 ; z = z0
  4570.         mov     [Z],ax
  4571.  
  4572.         mov     cx,GRIDY
  4573. ForJ:           push    es
  4574.         mov     ax,0A000h               ; clear old pixel.
  4575.         mov     es,ax
  4576.         mov     bx,[si]
  4577.         mov     byte ptr es:[bx],al
  4578.         pop     es
  4579.  
  4580. ; here the code must be hooked to support clipping, use an "illegal"
  4581. ; offset to store pixels that are not drawed, and then the routine above
  4582. ; must erase only "legal" pixels.
  4583.  
  4584.         mov     bl,es:[di]              ; bl = landscape(posx,posy)
  4585.         mov     al,bl                   ; ax = -centery + (z + bl*cosy)
  4586.         xor     ah,ah
  4587.         imul    [CosY]
  4588.         add     ax,[Z]
  4589.         sar     ax,TRIGSHIFT
  4590.         sub     ax,CENTERY
  4591.         imul    ax,SCREENWIDTH
  4592.         mov     dx,[Y]                  ; dx = centery + y
  4593.         sar     dx,TRIGSHIFT
  4594.         add     dx,CENTERX
  4595.         sub     dx,ax
  4596.         mov     [si],dx                 ; store pixel offset.
  4597.  
  4598.         push    es
  4599.         mov     ax,0A000h               ; paint new pixel.
  4600.         mov     es,ax
  4601.         xchg    dx,bx
  4602.         mov     es:[bx],dl
  4603.         pop     es
  4604.  
  4605.         mov     ax,[YJAdd]              ; y = y + yjadd
  4606.         add     [Y],ax
  4607.         mov     ax,[ZJAdd]              ; z = z + zjadd
  4608.         add     [Z],ax
  4609.         inc     di                      ; posy = posy + 1
  4610.         add     si,2
  4611.         loop    ForJ
  4612.  
  4613.         mov     ax,[YIAdd]              ; y0 = y0 + yiadd
  4614.         add     [Y0],ax
  4615.         mov     ax,[ZIAdd]              ; z0 = z0 + ziadd
  4616.         add     [Z0],ax
  4617.         add     di,LANDSCAPEX-GRIDY     ; posy = posy - gridy
  4618.         pop     cx                      ; posx = posx + 1
  4619.         loop    ForI
  4620.         ret
  4621.  
  4622. DrawLandscape   endp
  4623.  
  4624. ;-----------------------------------------------------------------------------
  4625. ; LandScape - Main landscape demo routine. Because this routine was tested
  4626. ;   using the Borland Pascal high-level interface, the allocation of the
  4627. ;   memory is done by the caller.
  4628. ; In:
  4629. ;  DS     - Data segment.
  4630. ;  MemSeg - Memory segment of 64K needed for storage.
  4631. ;-----------------------------------------------------------------------------
  4632.  
  4633. LandScape       proc    MemSeg:word
  4634.         local   PosX:word,PosY:word,AngleY:word,AngleZ:word
  4635.  
  4636.         mov     ax,0013h                ; set VGA 320x200x256 mode.
  4637.         int     10h
  4638.  
  4639.         mov     ax,[MemSeg]             ; setup landscape
  4640.         mov     [LandSeg],ax            ; memory segment.
  4641.  
  4642.         lea     di,[Palette]            ; set black palette.
  4643.         mov     ax,ds
  4644.         mov     es,ax
  4645.         mov     cx,768
  4646.         xor     ax,ax
  4647.         cld
  4648.         rep     stosb
  4649.         lea     si,[Palette]
  4650.         call    SetPalette
  4651.  
  4652. GenPalette:     lea     di,[Palette]            ; generate color palette.
  4653.         mov     ax,3F00h
  4654.         mov     [di+0],al               ; background.
  4655.         mov     [di+1],al
  4656.         mov     [di+2],al
  4657.         add     di,3
  4658.         mov     [di+0],al               ; blue. (water)
  4659.         mov     [di+1],al
  4660.         mov     [di+2],ah
  4661.         add     di,3
  4662.         mov     ax,0000h                ; green to brown.
  4663.         mov     bx,3F00h
  4664.         mov     dx,0000h
  4665.         mov     cx,61
  4666. GP0:            mov     [di+0],ah
  4667.         mov     [di+1],bh
  4668.         mov     [di+2],dh
  4669.         add     di,3
  4670.         add     ax,0108h
  4671.         sub     bx,0086h
  4672.         add     dx,0000h
  4673.         loop    GP0
  4674.         mov     ax,3F00h                ; brown to white.
  4675.         mov     bx,2000h                ; (mountain)
  4676.         mov     dx,0000h
  4677.         mov     cx,48
  4678. GP1:            mov     [di+0],ah
  4679.         mov     [di+1],bh
  4680.         mov     [di+2],dh
  4681.         add     di,3
  4682.         add     ax,0000h
  4683.         add     bx,00AAh
  4684.         add     dx,0150h
  4685.         loop    GP1
  4686.         mov     ax,3F00h                ; white. (snow)
  4687.         mov     bx,3F00h
  4688.         mov     dx,3F00h
  4689.         mov     cx,145
  4690. GP2:            mov     [di+0],ah
  4691.         mov     [di+1],bh
  4692.         mov     [di+2],dh
  4693.         add     di,3
  4694.         add     ax,0000h
  4695.         add     bx,0000h
  4696.         add     dx,0000h
  4697.         loop    GP2
  4698.  
  4699.         call    GenLandscape            ; creates the landscape.
  4700.  
  4701.         mov     [AngleY],240            ; inclination angle.
  4702.         mov     [AngleZ],0              ; initial spin angle.
  4703.         mov     [PosX],0                ; starting landscape
  4704.         mov     [PosY],0                ; position.
  4705.  
  4706.         ; pixels offset array could be cleaned but not necesary,
  4707.         ; because i am using the 64K of video memory ...
  4708.         ; i can't overwrite anything! :-)
  4709.  
  4710.         ; draw hidden landscape and do flash-in effect.
  4711.  
  4712.         call    DrawLandscape,[PosX],[PosY],[AngleY],[AngleZ]
  4713.         lea     si,[Palette]
  4714.         call    FlashIn
  4715.  
  4716.         mov     [Timer],0               ; set timer counter.
  4717.  
  4718.         mov     si,1                    ; starting landscape
  4719.         mov     di,1                    ; directions.
  4720.  
  4721. LandLoop:       call    WaitVRT                 ; wait vertical retrace.
  4722.  
  4723.         push    si                      ; draw landscape.
  4724.         push    di
  4725.         call    DrawLandscape,[PosX],[PosY],[AngleY],[AngleZ]
  4726.         pop     di
  4727.         pop     si
  4728.  
  4729.         inc     byte ptr [AngleZ]       ; increase spin angle.
  4730.         add     [PosX],si               ; advance landscape position.
  4731.         add     [PosY],di
  4732. TestX:          cmp     [PosX],0                ; check for boundaries.
  4733.         jl      NegIncX
  4734.         cmp     [PosX],LANDSCAPEX-GRIDX
  4735.         jl      TestY
  4736. NegIncX:        sub     [PosX],si
  4737.         neg     si
  4738. TestY:          cmp     [PosY],0
  4739.         jl      NegIncY
  4740.         cmp     [PosY],LANDSCAPEY-GRIDY
  4741.         jl      CheckExit
  4742. NegIncY:        sub     [PosY],di
  4743.         neg     di
  4744.  
  4745. CheckExit:      inc     [Timer]                 ; timeout?
  4746.         cmp     [Timer],TIMEOUT
  4747.         jae     ByeBye
  4748.  
  4749.         mov     ah,1                    ; any key pressed?
  4750.         int     16h
  4751.         jz      LandLoop
  4752.  
  4753. ByeBye:         call    FlashOut                ; flash-out!
  4754.  
  4755.         mov     ax,03h                  ; set 80x25x16 text mode.
  4756.         int     10h
  4757.         ret
  4758.  
  4759. LandScape       endp
  4760.  
  4761.  
  4762. ;-----------------------------------------------------------------------------
  4763. ; Start - Startup code called from DOS.
  4764. ; In:
  4765. ;   ES - Program Segment Prefix.
  4766. ;-----------------------------------------------------------------------------
  4767.  
  4768. Start           proc
  4769.  
  4770.         mov     ax,@Data
  4771.         mov     ds,ax
  4772.  
  4773.         mov     ax,ss                   ; shrink memory block.
  4774.         mov     bx,es
  4775.         sub     ax,bx
  4776.         mov     bx,sp
  4777.         shr     bx,4
  4778.         inc     bx
  4779.         add     bx,ax
  4780.         mov     ah,4Ah
  4781.         int     21h
  4782.  
  4783.         mov     ah,48h                  ; allocate 64000 bytes.
  4784.         mov     bx,4000
  4785.         int     21h
  4786.         jc      Exit
  4787.         push    ax
  4788.         call    LandScape,ax            ; do demostration.
  4789.         pop     es
  4790.         mov     ah,49h                  ; free 64000 bytes.
  4791.         int     21h
  4792.  
  4793. Exit:           mov     ax,4C00h                ; exit to DOS.
  4794.         int     21h
  4795.  
  4796. Start           endp
  4797.  
  4798.         end     Start
  4799. ;=============================================================================
  4800. ; shades.asm - Bop Shades Demostration.
  4801. ;                                                    File created: 10-21-93
  4802. ; Copyright (c) 1993, Carlos Hasan                  Last modified: 10-21-93
  4803. ;
  4804. ; Description:
  4805. ;   This code implements bop shades using a gray palette of 64 levels in
  4806. ;   the VGA 320x200x256 graphics mode.
  4807. ;
  4808. ; Portability:
  4809. ;  Requires Turbo Assembler 3.2 or better to be assembled.
  4810. ;  Dependent on the IBM PC 286 and the VGA graphics card.
  4811. ;=============================================================================
  4812.  
  4813.         jumps
  4814.         .model  small,pascal
  4815.         .286
  4816.  
  4817.         dosseg                          ; used for linking like 
  4818.         .stack 1024                     ; an Standalone program.
  4819.  
  4820.         global  BopShades:proc
  4821.  
  4822. ;======================== Demo Equates and Data ==============================
  4823.  
  4824. TIMEOUT         equ     4000                    ; Number of Frames Total.
  4825. MAXWIDTH        equ     320                     ; Screen Dimens.
  4826. MAXHEIGHT       equ     200
  4827. CENTERX         equ     160-25                  ; Screen Center Coord.
  4828. CENTERY         equ     100-25
  4829. MAXBOPS         equ     150                     ; Number of Bops.
  4830. RADIUSX         equ     120                     ; Bops Path Radius.
  4831. RADIUSY         equ     60
  4832.  
  4833.         .data
  4834.  
  4835.         include shades.inc              ; Bop Points Table.
  4836.         include sincos.inc              ; Sin/Cos Table.
  4837.  
  4838. BopQueue        dw      MAXBOPS dup(?)          ; Bops Positions Queue.
  4839. BopHead         dw      ?                       ; Current Queue Head.
  4840. Angle           dw      ?                       ; Bops Path Generation
  4841. Phase1          dw      ?                       ; Parameters.
  4842. Phase2          dw      ?                       ; Angle, Phase, Incs.
  4843. PhInc1          dw      ?
  4844. PhInc2          dw      ?
  4845. Frames          dw      ?                       ; Frame Counter.
  4846.  
  4847. ;======================== Demo Routines ======================================
  4848.  
  4849.         .code
  4850.  
  4851. ;-----------------------------------------------------------------------------
  4852. ; ShowBop - Shows a BopShade at specified position.
  4853. ; In:
  4854. ;   DI  - Position Offset.
  4855. ;-----------------------------------------------------------------------------
  4856.  
  4857. ShowBop         proc near
  4858.  
  4859.         mov     ax,0A000h
  4860.         mov     es,ax
  4861.         xor     si,si
  4862.         mov     cx,BOPPTS
  4863. ShowLoop:       mov     al,[BopAddTab+si]
  4864.         shl     si,1
  4865.         mov     bx,[BopTab+si]
  4866.         shr     si,1
  4867.         add     es:[bx+di],al
  4868.         inc     si
  4869.         loop    ShowLoop
  4870.         ret
  4871.  
  4872. ShowBop         endp
  4873.  
  4874. ;-----------------------------------------------------------------------------
  4875. ; HideBop - Hides a BopShade at specified position.
  4876. ; In:
  4877. ;   DI  - Position Offset.
  4878. ;-----------------------------------------------------------------------------
  4879.  
  4880. HideBop         proc near
  4881.  
  4882.         mov     ax,0A000h
  4883.         mov     es,ax
  4884.         xor     si,si
  4885.         mov     cx,BOPPTS
  4886. HideLoop:       mov     al,[BopAddTab+si]
  4887.         shl     si,1
  4888.         mov     bx,[BopTab+si]
  4889.         shr     si,1
  4890.         sub     es:[bx+di],al
  4891.         inc     si
  4892.         loop    HideLoop
  4893.         ret
  4894.  
  4895. HideBop         endp
  4896.  
  4897. ;-----------------------------------------------------------------------------
  4898. ; InitBops - Initializes the BopShade Queue.
  4899. ;-----------------------------------------------------------------------------
  4900.  
  4901. InitBops        proc near
  4902.  
  4903.         mov     ax,ds
  4904.         mov     es,ax
  4905.         lea     di,[BopQueue]
  4906.         mov     cx,MAXBOPS
  4907.         mov     ax,0FFFFh               ; illegel offset,
  4908.         cld                             ; because first bops
  4909.         rep     stosw                   ; are hidden.
  4910.         mov     [BopHead],0
  4911.         ret
  4912.  
  4913. InitBops        endp
  4914.  
  4915. ;-----------------------------------------------------------------------------
  4916. ; PutBop - Puts a new BopShade onto the Queue and updates the screen.
  4917. ; In:
  4918. ;   (CX,DX) - Screen coordinates.
  4919. ;-----------------------------------------------------------------------------
  4920.  
  4921. PutBop          proc near
  4922.  
  4923.         mov     di,dx
  4924.         imul    di,MAXWIDTH
  4925.         add     di,cx
  4926.         mov     bx,[BopHead]
  4927.         xchg    [BopQueue+bx],di
  4928.         cmp     di,MAXWIDTH*MAXHEIGHT
  4929.         jae     PutNewBop
  4930.         call    HideBop
  4931. PutNewBop:      mov     bx,[BopHead]
  4932.         mov     di,[BopQueue+bx]
  4933.         cmp     di,MAXWIDTH*MAXHEIGHT
  4934.         jae     SkipShow
  4935.         call    ShowBop
  4936. SkipShow:       add     [BopHead],2
  4937.         cmp     [BopHead],2*MAXBOPS
  4938.         jb      ByePutBop
  4939.         mov     [BopHead],0
  4940. ByePutBop:      ret
  4941.  
  4942. PutBop          endp
  4943.  
  4944.  
  4945. ;-----------------------------------------------------------------------------
  4946. ; BopShades - Performs the Demostration.
  4947. ; In:
  4948. ;   DS - Data Segment.
  4949. ;-----------------------------------------------------------------------------
  4950.  
  4951. BopShades       proc
  4952.  
  4953.         mov     ax,13h                  ; Sets 320x200x256 mode.
  4954.         int     10h
  4955.  
  4956.         mov     dx,3C8h                 ; Set the Shaded Palette.
  4957.         xor     al,al
  4958.         out     dx,al
  4959.         inc     dx
  4960.         mov     cx,256
  4961.         xor     ah,ah
  4962. SetPal:         xor     al,al
  4963.         out     dx,al
  4964.         out     dx,al
  4965.         mov     al,ah
  4966.         out     dx,al
  4967.         cmp     ah,63
  4968.         jae     SetBrk
  4969.         inc     ah
  4970. SetBrk:         loop    SetPal
  4971.  
  4972.         call    InitBops                ; Init BopsQueue.
  4973.  
  4974.         mov     [Angle],0               ; Init Variables.
  4975.         mov     [Phase1],2*1024
  4976.         mov     [Phase2],2*1024
  4977.         mov     [PhInc1],2
  4978.         mov     [PhInc2],3
  4979.         mov     [Frames],0
  4980.  
  4981. ShadesLoop:     mov     ax,[Angle]              ; Compute X Coord.
  4982.         imul    [Phase1]
  4983.         mov     bl,ah
  4984.         mov     bh,dl
  4985.         shr     bx,2
  4986.         xor     bh,bh
  4987.         mov     al,[CosTable+bx]
  4988.         mov     ah,RADIUSX
  4989.         imul    ah
  4990.         sar     ax,6
  4991.         add     ax,CENTERX
  4992.         mov     cx,ax
  4993.  
  4994.         mov     ax,[Angle]              ; Compute Y Coord.
  4995.         imul    [Phase2]
  4996.         mov     bl,ah
  4997.         mov     bh,dl
  4998.         shr     bx,2
  4999.         xor     bh,bh
  5000.         mov     al,[SinTable+bx]
  5001.         mov     ah,RADIUSY
  5002.         imul    ah
  5003.         sar     ax,6
  5004.         add     ax,CENTERY
  5005.         mov     dx,ax
  5006.  
  5007.         call    PutBop                  ; Puts BopShade at (CX,DX)
  5008.  
  5009.         mov     ax,[Angle]              ; Increment Angle.
  5010.         inc     ax
  5011.         and     ax,1023
  5012.         mov     [Angle],ax
  5013.  
  5014.         mov     ax,[Phase1]             ; Increment Phase1.
  5015.         add     ax,[PhInc1]
  5016.         cwd
  5017.         mov     bx,5*1024
  5018.         div     bx
  5019.         mov     [Phase1],dx
  5020.  
  5021.         mov     ax,[Phase2]             ; Increment Phase2.
  5022.         add     ax,[PhInc2]
  5023.         cwd
  5024.         mov     bx,5*1024
  5025.         div     bx
  5026.         mov     [Phase2],dx
  5027.  
  5028.         inc     [Frames]                ; enough frames showed?
  5029.         cmp     [Frames],TIMEOUT
  5030.         ja      ShadesBye
  5031.  
  5032.         mov     ah,1                    ; any key pressed?
  5033.         int     16h
  5034.         je      ShadesLoop
  5035.  
  5036. ShadesBye:      
  5037.         mov     cx,MAXBOPS              ; Hides all the Bops.
  5038. HidesLoop:      push    cx
  5039.         mov     cx,0FFFFh
  5040.         mov     dx,cx
  5041.         call    PutBop
  5042.         pop     cx
  5043.         loop    HidesLoop
  5044.  
  5045.         mov     ax,03h
  5046.         int     10h
  5047.         ret
  5048.  
  5049. BopShades       endp
  5050.  
  5051.  
  5052. ;-----------------------------------------------------------------------------
  5053. ; Start - Startup Code called from DOS.
  5054. ; In:
  5055. ;   DS - Program Segment Prefix.
  5056. ;-----------------------------------------------------------------------------
  5057.  
  5058. Start           proc
  5059.  
  5060.         mov     ax,@Data
  5061.         mov     ds,ax
  5062.         call    BopShades
  5063.         mov     ax,4C00h
  5064.         int     21h
  5065.  
  5066. Start           endp
  5067.  
  5068.         end     Start
  5069. ;=============================================================================
  5070. ; worm.asm - Worm Hole palette demostration.
  5071. ;                                                    File created: 10/04/93
  5072. ; Copyright (c) 1993, Carlos Hasan                  Last modified: 10/04/93
  5073. ;
  5074. ; Description:
  5075. ;   This file demostrates a palette animation routine, the main piccy
  5076. ; was created using the pascal source file. This one uses the VGA card
  5077. ; in 320x200x256 graphics mode.
  5078. ;
  5079. ; Portability:
  5080. ;  Requires Turbo Assembler 3.2 or better to be assembled.
  5081. ;  Dependent on the IBM PC 286 and the VGA graphics card.
  5082. ;
  5083. ; Modifications:
  5084. ;  10/22/93 - Startup Code and Picture on .OBJ file.
  5085. ;=============================================================================
  5086.  
  5087.         .model  small,pascal
  5088.         .286
  5089.  
  5090.         dosseg                          ; used to link like
  5091.         .stack  1024                    ; and standalone program.
  5092.  
  5093.         global  WormHole:proc
  5094.         global  WormPic:byte            ; in WORMRAW.OBJ file.
  5095.  
  5096. ;====================== Demo Equates and Data ================================
  5097.  
  5098. TIMEOUT         equ     70 * 8                  ; About 8 sec for timeout.
  5099.  
  5100.         .data
  5101.  
  5102. Palette         db      768 dup (?)             ; hold the color palette
  5103. FadePalette     db      768 dup (?)             ; and the faded palette.
  5104. Timer           dw      ?                       ; timer counter.
  5105.  
  5106. ;========================== Demo routines ====================================
  5107.  
  5108.         .code
  5109.  
  5110. ;-----------------------------------------------------------------------------
  5111. ; SetPalette - set the 256 entries of the VGA color palette.
  5112. ; In:
  5113. ;   DS:SI - Palette structure address.
  5114. ;-----------------------------------------------------------------------------
  5115.  
  5116. SetPalette      proc near
  5117.  
  5118.         mov     cx,768
  5119.         mov     dx,3C8h
  5120.         xor     al,al
  5121.         out     dx,al
  5122.         mov     dx,3DAh
  5123. WaitVRT1:       in      al,dx                   ; wait the start of
  5124.         test    al,8                    ; vertical retrace.
  5125.         jz      WaitVRT1
  5126. WaitVRT2:       in      al,dx                   ; wait the end of
  5127.         test    al,8                    ; vertical retrace.
  5128.         jnz     WaitVRT2
  5129.         mov     dx,3C9h
  5130.         rep     outsb
  5131.         ret
  5132.  
  5133. SetPalette      endp
  5134.  
  5135. ;-----------------------------------------------------------------------------
  5136. ; RotPalette - Rotates the palette and do fading.
  5137. ; In:
  5138. ;   Palette - Source palette.
  5139. ;   Fade    - Fading level.
  5140. ;-----------------------------------------------------------------------------
  5141.  
  5142. RotPalette      proc near Fade:word
  5143.  
  5144.         mov     ax,ds
  5145.         mov     es,ax
  5146.  
  5147.         lea     di,[FadePalette]
  5148.         mov     cx,16*3
  5149.         xor     ax,ax
  5150.         cld
  5151.         rep     stosb
  5152.         lea     si,[Palette+32*3]
  5153.         mov     cx,224*3
  5154.         cld
  5155.         rep     movsb
  5156.         lea     si,[Palette+16*3]
  5157.         mov     cx,16*3
  5158.         rep     movsb
  5159.  
  5160.         lea     bx,[FadePalette]
  5161.         mov     cx,16
  5162. RotLoop:        push    cx
  5163.         mov     si,bx
  5164.         mov     di,bx
  5165.         lodsb
  5166.         mov     ah,al
  5167.         lodsb
  5168.         mov     dl,al
  5169.         lodsb
  5170.         mov     dh,al
  5171.         mov     cx,15*3
  5172.         rep     movsb
  5173.         mov     al,ah
  5174.         stosb
  5175.         mov     al,dl
  5176.         stosb
  5177.         mov     al,dh
  5178.         stosb
  5179.         add     bx,16*3
  5180.         pop     cx
  5181.         loop    RotLoop
  5182.  
  5183.         lea     si,[FadePalette]
  5184.         lea     di,[Palette]
  5185.         mov     cx,768
  5186.         rep     movsb
  5187.  
  5188.         lea     si,[FadePalette]
  5189.         mov     cx,768
  5190.         mov     dx,[Fade]
  5191. FadeLoop:       mov     al,[si]
  5192.         mul     dl
  5193.         shr     ax,7
  5194.         mov     [si],al
  5195.         inc     si
  5196.         loop    FadeLoop
  5197.  
  5198.         lea     si,[FadePalette]
  5199.         call    SetPalette
  5200.         ret
  5201.  
  5202. RotPalette      endp
  5203.  
  5204. ;-----------------------------------------------------------------------------
  5205. ; WormHole - Worm Hole demostration.
  5206. ; In:
  5207. ;   DS     - Data segment.
  5208. ;   PicSeg - 320x200x256 picture segment address.
  5209. ;-----------------------------------------------------------------------------
  5210.  
  5211. WormHole        proc    PicPtr:dword
  5212.         local   Fade:word
  5213.  
  5214.         mov     ax,0013h                ; set 320x200x256 mode.
  5215.         int     10h
  5216.  
  5217.         mov     ax,ds                   ; set black palette.
  5218.         mov     es,ax
  5219.         lea     di,[Palette]
  5220.         mov     cx,768
  5221.         xor     ax,ax
  5222.         cld
  5223.         rep     stosb
  5224.         lea     si,[Palette]
  5225.         call    SetPalette
  5226.  
  5227.         lea     di,[Palette]            ; generate the palette.
  5228.         mov     cx,256
  5229.         xor     bx,bx
  5230. GenPalette:     mov     ax,bx
  5231.         shr     ax,4
  5232.         and     ax,0Fh
  5233.         shl     ax,2
  5234.         mov     [di+0],al
  5235.         mov     ax,bx
  5236.         and     ax,0Fh
  5237.         shl     ax,1
  5238.         mov     [di+1],al
  5239.         mov     al,3Fh
  5240.         mov     [di+2],al
  5241.         add     di,3
  5242.         inc     bx
  5243.         loop    GenPalette
  5244.  
  5245.         push    ds                      ; write the picture.
  5246.         mov     ax,0A000h
  5247.         mov     es,ax
  5248.         lds     si,[PicPtr]
  5249.         xor     di,di
  5250.         mov     cx,320*200
  5251.         cld
  5252.         rep     movsb
  5253.         pop     ds
  5254.  
  5255.         mov     [Fade],0
  5256.         mov     [Timer],0
  5257.  
  5258. WormIn:         call    RotPalette,[Fade]       ; rotate palette.
  5259.         cmp     [Fade],128              ; adjust fade level.
  5260.         jae     WormTime
  5261.         inc     [Fade]
  5262. WormTime:       inc     [Timer]                 ; check if timeout,
  5263.         cmp     [Timer],TIMEOUT
  5264.         jae     WormOut
  5265. WormKey:        mov     ah,1                    ; or any key pressed.
  5266.         int     16h
  5267.         jz      WormIn
  5268.  
  5269. WormOut:        cmp     [Fade],128              ; start fading-out.
  5270.         ja      WormExit
  5271.         call    RotPalette,[Fade]
  5272.         dec     [Fade]
  5273.         jmp     WormOut
  5274.  
  5275. WormExit:       mov     ax,03h                  ; restore 80x25x16 textmode.
  5276.         int     10h
  5277.         ret
  5278.  
  5279. WormHole        endp
  5280.  
  5281. ;-----------------------------------------------------------------------------
  5282. ; Start - Startup Code called from DOS.
  5283. ; In:
  5284. ;   ES - Program Segment Prefix.
  5285. ;-----------------------------------------------------------------------------
  5286.  
  5287. Start           proc
  5288.  
  5289.         mov     ax,@Data
  5290.         mov     ds,ax
  5291.         call    WormHole,SEG WormPic,OFFSET WormPic
  5292.         mov     ax,4C00h
  5293.         int     21h
  5294.  
  5295. Start           endp
  5296.  
  5297.         end     Start
  5298. ;=============================================================================
  5299. ; txtfx.asm - Texture Effect Demostration.
  5300. ;                                                    File created: 11/03/93
  5301. ; Copyright (c) 1993, Carlos Hasan                  Last modified: 11/04/93
  5302. ;
  5303. ; Description:
  5304. ;   This file implements a texture algorithm that maps repeteadly into
  5305. ; screen a picture of 128x128x256 using the tweaked 80x200x256 mode.
  5306. ;
  5307. ; Portability:
  5308. ;   Requires Turbo Assembler 3.2 or better to be assembled.
  5309. ;   Dependent on the IBM PC 286 and the VGA graphics card.
  5310. ;=============================================================================
  5311.  
  5312.     ideal
  5313.     model   small,pascal
  5314.     jumps
  5315.     p286
  5316.     
  5317.     dosseg                  ; Used for Standalone DOS programs.
  5318.     stack   1024            ; Sets the Stack with 1KB of space.
  5319.     ends                    ; Must close stack segment!
  5320.  
  5321. ;===================== External Data =========================================
  5322.  
  5323.     global  PicRaw:far      ; 128x128x256 Image.
  5324.     global  PicPal:far      ; RGB Image Palette.
  5325.     global  TextFx:proc
  5326.  
  5327. ;===================== Demo Equates ==========================================
  5328.  
  5329.     dataseg
  5330.  
  5331. MAXWIDTH        equ     80      ; Screen Dimensions.
  5332. MAXHEIGHT       equ     200
  5333. BMPHEIGHT       equ     128     ; Image Bitmap Dimensions.
  5334. BMPWIDTH        equ     128
  5335. BMPMASK         equ     3FFFh   ; Image Position Mask.
  5336. TIMEOUT         equ     1800    ; Max Number of Frames for TimeOut.
  5337. ROTSPEED        equ     2       ; Rotation Speed Factor.
  5338. AMPSPEED        equ     4       ; Amplify Speed Factor.
  5339. FADESPEED       equ     6       ; Fadeout Speed Factor.
  5340.  
  5341.     include "SinCos.Inc"    ; Sinus/Cosinus Table.
  5342.  
  5343. ;======================== Demo Routines ======================================
  5344.  
  5345.     codeseg
  5346.  
  5347. ;-----------------------------------------------------------------------------
  5348. ; SetGraphMode - Sets the tweaked 80x200x256 VGA mode.
  5349. ;-----------------------------------------------------------------------------
  5350.  
  5351. proc    SetGraphMode
  5352.     mov     ax,13h          ; Sets VGA 320x200x256 mode.
  5353.     int     10h
  5354.     mov     dx,3C4h         ; Disable Chain-Four.
  5355.     mov     al,04h
  5356.     out     dx,al
  5357.     inc     dx
  5358.     in      al,dx
  5359.     and     al,0F7h
  5360.     out     dx,al
  5361.     mov     dx,3C4h         ; Enable All Planes.
  5362.     mov     ax,0F02h
  5363.     out     dx,ax
  5364.     mov     ax,0A000h       ; Clear Video Memory
  5365.     mov     es,ax
  5366.     xor     di,di
  5367.     xor     ax,ax
  5368.     mov     cx,8000h
  5369.     cld
  5370.     rep     stosw
  5371.     mov     dx,3D4h         ; Normal Word Addressing.
  5372.     mov     al,14h
  5373.     out     dx,al
  5374.     inc     dx
  5375.     in      al,dx
  5376.     and     al,0BFh
  5377.     out     dx,al
  5378.     dec     dx              ; Address Output Byte Mode.
  5379.     mov     al,17h
  5380.     out     dx,al
  5381.     inc     dx
  5382.     in      al,dx
  5383.     or      al,40h
  5384.     out     dx,al
  5385.     ret
  5386. endp    SetGraphMode
  5387.  
  5388.  
  5389. ;-----------------------------------------------------------------------------
  5390. ; SetTextMode - Restores 80x25x16 text mode.
  5391. ;-----------------------------------------------------------------------------
  5392.  
  5393. proc    SetTextMode
  5394.     mov     ax,03h
  5395.     int     10h
  5396.     ret
  5397. endp    SetTextMode
  5398.  
  5399. ;-----------------------------------------------------------------------------
  5400. ; WaitVR - Waits the Next Vertical Retrace.
  5401. ;-----------------------------------------------------------------------------
  5402.  
  5403. proc    WaitVR
  5404.     mov     dx,3DAh
  5405. WaitNotVRT:
  5406.     in      al,dx
  5407.     test    al,8
  5408.     jne     WaitNotVRT
  5409. WaitEndVRT:
  5410.     in      al,dx
  5411.     test    al,8
  5412.     je      WaitEndVRT
  5413.     ret
  5414. endp    WaitVR
  5415.  
  5416. ;-----------------------------------------------------------------------------
  5417. ; SetPalette - Sets the current VGA color palette.
  5418. ; In:
  5419. ;  DS:SI - Palette Address.
  5420. ;-----------------------------------------------------------------------------
  5421.  
  5422. proc    SetPalette
  5423.     call    WaitVR
  5424.     mov     dx,3C8h
  5425.     xor     al,al
  5426.     out     dx,al
  5427.     inc     dx
  5428.     mov     cx,768
  5429.     cld
  5430.     rep     outsb
  5431.     ret
  5432. endp    SetPalette
  5433.  
  5434. ;-----------------------------------------------------------------------------
  5435. ; FadeOut - Fades out the RGB Palette.
  5436. ; In:
  5437. ;  DS:SI = Palette Address.
  5438. ;-----------------------------------------------------------------------------
  5439.  
  5440. proc    FadeOut
  5441.     push    si
  5442.     push    ds
  5443.     mov     cx,768
  5444.     xor     bx,bx
  5445.     mov     di,si
  5446. DecPal: sub     [byte ptr di],FADESPEED
  5447.     jnc     NotDec
  5448.     inc     bx
  5449.     mov     [byte ptr di],0
  5450. NotDec: inc     di
  5451.     loop    DecPal
  5452.     push    bx
  5453.     call    SetPalette
  5454.     pop     bx
  5455.     pop     ds
  5456.     pop     si
  5457.     cmp     bx,768
  5458.     jb      FadeOut
  5459.     ret
  5460. endp    FadeOut
  5461.  
  5462. ;-----------------------------------------------------------------------------
  5463. ; RotImage - Puts on the screen the rotated image.
  5464. ; In:
  5465. ;  DeltaX,DeltaY = Rotation Parameters.
  5466. ;  Image         = Source 128x128x256 Image Bitmap.
  5467. ;-----------------------------------------------------------------------------
  5468.  
  5469. proc    RotImage DeltaX:word,DeltaY:word,Image:word
  5470. local   AddX:word:MAXWIDTH,AddY:word:MAXHEIGHT
  5471.  
  5472.     push    ds
  5473.     push    es
  5474.  
  5475.     shl     [DeltaX],1      ; Makes the Horiz Array
  5476.     shl     [DeltaY],1      ; of increments for the
  5477.     mov     cx,MAXWIDTH     ; Rotation.
  5478.     xor     bl,bl
  5479.     xor     dl,dl
  5480.     lea     di,[AddX]
  5481. MakeAddX:
  5482.     xor     bh,bh
  5483.     xor     dh,dh
  5484.     add     bx,[DeltaX]
  5485.     add     dx,[DeltaY]
  5486.     mov     al,dh
  5487.     cbw
  5488.     imul    si,ax,BMPWIDTH
  5489.     mov     al,bh
  5490.     cbw
  5491.     add     ax,si
  5492.     mov     [ss:di],ax
  5493.     add     di,2
  5494.     loop    MakeAddX
  5495.  
  5496.     sar     [DeltaX],1      ; Makes the Vert Array
  5497.     sar     [DeltaY],1      ; of increments for the
  5498.     mov     cx,MAXHEIGHT    ; Rotation.
  5499.     xor     bl,bl
  5500.     xor     dl,dl
  5501.     lea     di,[AddY]
  5502. MakeAddY:
  5503.     xor     bh,bh
  5504.     xor     dh,dh
  5505.     sub     bx,[DeltaY]
  5506.     add     dx,[DeltaX]
  5507.     mov     al,dh
  5508.     cbw
  5509.     imul    si,ax,BMPWIDTH
  5510.     mov     al,bh
  5511.     cbw
  5512.     add     ax,si
  5513.     mov     [ss:di],ax
  5514.     add     di,2
  5515.     loop    MakeAddY
  5516.  
  5517.     mov     ax,0A000h       ; Start drawing at the top left
  5518.     mov     es,ax           ; screen corner.
  5519.     xor     di,di
  5520.     mov     ds,[Image]      ; Load Source Image Address.
  5521.     xor     si,si
  5522.     mov     dx,BMPMASK      ; Load Image Position Mask.
  5523.     lea     bx,[AddY]
  5524.     mov     cx,MAXHEIGHT
  5525.     cld
  5526. DrawScanLines:
  5527.     push    si
  5528.     OFF=0                    ; This Loop have been unrolled
  5529.     REPT MAXWIDTH/2          ; for fastest drawing.
  5530.     and      si,dx           ; Also, the drawwing is done 
  5531.     mov      al,[si]         ; putting two pixels at once.
  5532.     add      si,[ss:AddX+OFF]
  5533.     and      si,dx
  5534.     mov      ah,[si]
  5535.     add      si,[ss:AddX+OFF+2]
  5536.     stosw
  5537.     OFF=OFF+4
  5538.     ENDM
  5539.     pop     si
  5540.     add     si,[ss:bx]       ; Next Scan Line. 
  5541.     add     bx,2
  5542.     dec     cx
  5543.     jne     DrawScanLines
  5544.     pop     es
  5545.     pop     ds
  5546.     ret
  5547. endp    RotImage
  5548.  
  5549. ;-----------------------------------------------------------------------------
  5550. ; TextFx - Performs the Demostration.
  5551. ; In:
  5552. ;  DS      = Data Segment.
  5553. ;  Image   = Source Image Segment.
  5554. ;  Palette = Image RGB Palette.
  5555. ;-----------------------------------------------------------------------------
  5556.  
  5557. proc    TextFx Image:word,Palette:dword
  5558.     pusha
  5559.     push    ds
  5560.     push    es
  5561.     call    SetGraphMode    ; Init Graphics Mode.
  5562.     push    ds
  5563.     lds     si,[Palette]    ; Sets the RGB Palette.
  5564.     call    SetPalette
  5565.     pop     ds
  5566.  
  5567.     xor     bx,bx           ; Init Rotation Angle.
  5568.     mov     dx,32           ; Init Amplify Factor.
  5569. TextFxLoop:
  5570.     add     bl,ROTSPEED     ; Increase Rot Angle.
  5571.     add     dx,AMPSPEED     ; Increase Amplify Factor.
  5572.     mov     cl,[SinTable+bx]
  5573.     mov     ch,[CosTable+bx]
  5574.     push    bx
  5575.     push    dx
  5576.     mov     al,cl           ; Amplify Rotation Parameters
  5577.     cbw                     ; using the Amplify Factor.
  5578.     imul    dx
  5579.     mov     al,ah
  5580.     mov     ah,dl
  5581.     mov     bx,ax
  5582.     pop     dx
  5583.     push    dx
  5584.     mov     al,ch
  5585.     cbw
  5586.     imul    dx
  5587.     mov     al,ah
  5588.     mov     ah,dl
  5589.     call    RotImage,ax,bx,[Image]
  5590.     mov     ah,1            ; Any Key Pressed?
  5591.     int     16h
  5592.     pop     dx
  5593.     pop     bx
  5594.     jz      CheckTimeOut
  5595.     mov     ah,0
  5596.     int     16h
  5597.     jmp     TextExit
  5598. CheckTimeout:
  5599.     cmp     dx,TIMEOUT      ; Enough Frames Showed?
  5600.     jb      TextFxLoop
  5601. TextExit:
  5602.     lds     si,[Palette]    ; Fade out the Palette.
  5603.     call    FadeOut
  5604.     call    SetTextMode     ; Restores 80x25x16 Text Mode.
  5605.     pop     es
  5606.     pop     ds
  5607.     popa
  5608.     ret
  5609. endp    TextFx
  5610.  
  5611. ;-----------------------------------------------------------------------------
  5612. ; Start - Startup code called from DOS.
  5613. ; In:
  5614. ;  ES = Program Segment Prefix.
  5615. ;-----------------------------------------------------------------------------
  5616.  
  5617. proc    Start
  5618.     mov     ax,@Data        ; Setup Data Segment.
  5619.     mov     ds,ax           ; Do the Demostration.
  5620.     call    TextFx,SEG PicRaw,SEG PicPal,OFFSET PicPal
  5621.     mov     ax,4C00h
  5622.     int     21h             ; Exit to DOS.
  5623. endp    Start
  5624.  
  5625.     end     Start
  5626.