home *** CD-ROM | disk | FTP | other *** search
/ The Party 1994: Try This At Home / disk_image.bin / source / fakesrc / part1 / flag.asm next >
Assembly Source File  |  1993-10-21  |  9KB  |  246 lines

  1. ;=============================================================================
  2. ; flag.asm - Runtime Flag Demostration.
  3. ;                                                   File created: 10-22-93
  4. ; Copyright (C) 1993, Carlos Hasan                 Last modified: 10-22-93
  5. ;
  6. ; Description:
  7. ;   This file implements a runtime flag movement using plasma like
  8. ;   sinus overlapping waves in the VGA 320x200x256 graphics mode.
  9. ;
  10. ; Portability:
  11. ;  Requires Turbo Assembler 3.2 or better to be assembler.
  12. ;  Dependent on the IBM PC 286 and the VGA graphics card.
  13. ;=============================================================================
  14.  
  15.                 .model  small,pascal
  16.                 .286
  17.  
  18.                 dosseg                          ; used to link like
  19.                 .stack  1024                    ; an standalone program.
  20.  
  21.                 global  FlagDemo:proc
  22.  
  23. ;======================= Demo equates and data ===============================
  24.  
  25. TIMEOUT         equ     70 * 8                  ; at least 8 secs.
  26. BMPWIDTH        equ     160                     ; bitmap dimens.
  27. BMPHEIGHT       equ     96
  28. MAXWIDTH        equ     320                     ; screen dimens.
  29. MAXHEIGHT       equ     200
  30. XOFS            equ     80                      ; flag upper left
  31. YOFS            equ     30                      ; corner coordinates.
  32.  
  33.                 .data
  34.  
  35. ; flag bitmap, palette and sinus wave tables.
  36. ; The bitmap is about 15K, but because it's highly compressed using
  37. ; any exepacker, it was included in the data segment avoiding the
  38. ; extra segment needed in the demo algorithms.
  39.  
  40.                 include flagbmp.inc 
  41.  
  42. HWavPos         db      ?                       ; wave horiz and vert
  43. VWavPos         db      ?                       ; positions.
  44.  
  45. FadePalette     db      768 dup (?)             ; faded palette.
  46. Fade            db      ?                       ; fade level.
  47. Esckey          db      ?                       ; true if key pressed.
  48. Timer           dw      ?                       ; timer counter.
  49.  
  50. ;======================= Demo routines =======================================
  51.  
  52.                 .code
  53.  
  54. ;-----------------------------------------------------------------------------
  55. ; WaitVRT - Waits the Vertical Retrace.
  56. ;-----------------------------------------------------------------------------
  57.  
  58. WaitVRT         proc near
  59.  
  60.                 mov     dx,3DAh
  61. WaitVR1:        in      al,dx
  62.                 test    al,8
  63.                 jne     WaitVR1
  64. WaitVR2:        in      al,dx
  65.                 test    al,8
  66.                 je      WaitVR2
  67.                 ret
  68.  
  69. WaitVRT         endp
  70.  
  71. ;-----------------------------------------------------------------------------
  72. ; SetPalette - set the CX entries of the VGA color palette.
  73. ; In:
  74. ;   DS:SI - Palette structure address.
  75. ;   CX    - Number of colors components.
  76. ;-----------------------------------------------------------------------------
  77.  
  78. SetPalette      proc near
  79.  
  80.                 call    WaitVRT
  81.                 mov     dx,3C8h
  82.                 xor     al,al
  83.                 out     dx,al
  84.                 inc     dx
  85.                 rep     outsb
  86.                 ret
  87.  
  88. SetPalette      endp
  89.  
  90. ;-----------------------------------------------------------------------------
  91. ; PutFlag - Writes the next Flag Frame to the Screen.
  92. ;-----------------------------------------------------------------------------
  93.  
  94. PutFlag         proc near
  95.  
  96.                 mov     ax,0A000h
  97.                 mov     es,ax
  98.                 add     [HWavPos],4             ; Incr Wave Positions.
  99.                 add     [VWavPos],7
  100.                 mov     dh,[HWavPos]            ; k = hwavpos.
  101.                 mov     di,MAXWIDTH*YOFS+XOFS   ; p = screen offset.
  102.                 lea     si,[Piccy]              ; q = piccy offset.
  103.                 mov     cx,BMPWIDTH-16          ; for col=0 to W-16 do
  104.                 xor     bh,bh
  105. ColLoop:        push    cx
  106.                 push    si
  107.                 push    di
  108.                 mov     bl,dh
  109.                 mov     dl,[VWave+bx]           ; x = vwave[k]
  110.                 mov     al,[HWave+bx]           ; h = (x+hwave[k])/2
  111.                 add     al,dl
  112.                 rcr     al,1
  113.                 mov     ah,BMPWIDTH             ; q= col+160*h
  114.                 mul     ah
  115.                 add     si,ax
  116.                 mov     ah,[VWavPos]            ; l = vwavpos
  117.                 mov     cx,BMPHEIGHT-16         ; for row=0 to H-16 do
  118. RowLoop:        mov     bl,ah
  119.                 mov     bl,[VWave+bx]           ; v = (x+vwave[l])/2
  120.                 add     bl,dl
  121.                 rcr     bl,1
  122.                 mov     al,[si+bx]              ; al = pic[si+v]+vwave[k+v]
  123.                 add     bl,dh
  124.                 mov     bl,[VWave+bx]
  125.                 xor     bl,0Fh
  126.                 add     al,bl
  127.                 mov     es:[di],al              ; put pixel.
  128.                 add     di,MAXWIDTH             ; p= p+320
  129.                 add     si,BMPWIDTH             ; q= q+160
  130.                 inc     ah                      ; l= l+1
  131.                 loop    RowLoop
  132.                 pop     di
  133.                 pop     si
  134.                 pop     cx
  135.                 inc     dh                      ; k=k+1
  136.                 inc     si                      ; q=q+1
  137.                 inc     di                      ; p=p+1
  138.                 test    di,1                    ; if odd(p) p=p+320
  139.                 jne     ColBrk
  140.                 add     di,MAXWIDTH
  141. ColBrk:         loop    ColLoop                 ; next col.
  142.                 ret
  143.  
  144. PutFlag         endp
  145.  
  146. ;-----------------------------------------------------------------------------
  147. ; FlagDemo - Performs the demonstration.
  148. ; In:
  149. ;   DS - Data segment.
  150. ;-----------------------------------------------------------------------------
  151.  
  152. FlagDemo        proc
  153.  
  154.                 pusha
  155.                 push    ds
  156.                 push    es
  157.  
  158.                 mov     ax,0013h                ; set 320x200x256 mode.
  159.                 int     10h
  160.  
  161.                 mov     [Fade],0                ; setup variables.
  162.                 mov     [EscKey],0
  163.                 mov     [Timer],0
  164.  
  165.                 mov     [HWavPos],0
  166.                 mov     [VWavPos],0
  167.  
  168. FlagLoop:       cmp     [EscKey],0              ; change fade level.
  169.                 jne     FadeOut
  170. FadeIn:         mov     bl,[Fade]
  171.                 cmp     bl,64
  172.                 jae     SkipFade
  173.                 inc     [Fade]
  174.                 jmp     FadeInOut
  175. FadeOut:        mov     bl,[Fade]
  176.                 cmp     bl,0
  177.                 jbe     FadeInOut
  178.                 dec     [Fade]
  179.  
  180. FadeInOut:      lea     si,[Palette]            ; set faded palette.
  181.                 lea     di,[FadePalette]
  182.                 mov     cx,3*16*4
  183.                 mov     ax,ds
  184.                 mov     es,ax
  185.                 cld
  186. FadeLoop:       lodsb
  187.                 mul     bl
  188.                 shr     ax,6
  189.                 stosb
  190.                 loop    FadeLoop
  191.  
  192. DoFade:         lea     si,[FadePalette]        ; ensures thats always
  193.                 mov     cx,3*16*4               ; waits the VR per frame.
  194.                 call    SetPalette
  195.                 jmp     DoFlag
  196.  
  197. SkipFade:       call    WaitVRT
  198.  
  199. DoFlag:         call    PutFlag                 ; put the flag.
  200.  
  201.                 mov     ah,1                    ; if any key pressed,
  202.                 int     16h
  203.                 jz      CheckTimer
  204.                 mov     ah,0
  205.                 int     16h
  206.                 jmp     BeginFadeOut
  207.  
  208. CheckTimer:     inc     [Timer]                 ; or timeout,
  209.                 cmp     [Timer],TIMEOUT
  210.                 jb      CheckExit
  211.  
  212. BeginFadeOut:   inc     [EscKey]                ; then fade-out and exit.
  213.  
  214. CheckExit:      cmp     [Fade],0
  215.                 je      FlagExit
  216.                 jmp     FlagLoop
  217.  
  218. FlagExit:       mov     ax,0003h
  219.                 int     10h
  220.  
  221.                 pop     es
  222.                 pop     ds
  223.                 popa
  224.                 ret
  225.  
  226. FlagDemo        endp
  227.  
  228.  
  229. ;-----------------------------------------------------------------------------
  230. ; Start - Startup code called from DOS.
  231. ; In:
  232. ;   DS - Program Segment Prefix.
  233. ;-----------------------------------------------------------------------------
  234.  
  235. Start           proc
  236.  
  237.                 mov     ax,@Data
  238.                 mov     ds,ax
  239.                 call    FlagDemo
  240.                 mov     ax,4C00h
  241.                 int     21h
  242.  
  243. Start           endp
  244.  
  245.                 end     Start
  246.