home *** CD-ROM | disk | FTP | other *** search
/ The Party 1994: Try This At Home / disk_image.bin / source / fakesrc / worm.asm < prev    next >
Assembly Source File  |  1993-10-21  |  8KB  |  230 lines

  1. ;=============================================================================
  2. ; worm.asm - Worm Hole palette demostration.
  3. ;                                                    File created: 10/04/93
  4. ; Copyright (c) 1993, Carlos Hasan                  Last modified: 10/04/93
  5. ;
  6. ; Description:
  7. ;   This file demostrates a palette animation routine, the main piccy
  8. ; was created using the pascal source file. This one uses the VGA card
  9. ; in 320x200x256 graphics mode.
  10. ;
  11. ; Portability:
  12. ;  Requires Turbo Assembler 3.2 or better to be assembled.
  13. ;  Dependent on the IBM PC 286 and the VGA graphics card.
  14. ;
  15. ; Modifications:
  16. ;  10/22/93 - Startup Code and Picture on .OBJ file.
  17. ;=============================================================================
  18.  
  19.                 .model  small,pascal
  20.                 .286
  21.  
  22.                 dosseg                          ; used to link like
  23.                 .stack  1024                    ; and standalone program.
  24.  
  25.                 global  WormHole:proc
  26.                 global  WormPic:byte            ; in WORMRAW.OBJ file.
  27.  
  28. ;====================== Demo Equates and Data ================================
  29.  
  30. TIMEOUT         equ     70 * 8                  ; About 8 sec for timeout.
  31.  
  32.                 .data
  33.  
  34. Palette         db      768 dup (?)             ; hold the color palette
  35. FadePalette     db      768 dup (?)             ; and the faded palette.
  36. Timer           dw      ?                       ; timer counter.
  37.  
  38. ;========================== Demo routines ====================================
  39.  
  40.                 .code
  41.  
  42. ;-----------------------------------------------------------------------------
  43. ; SetPalette - set the 256 entries of the VGA color palette.
  44. ; In:
  45. ;   DS:SI - Palette structure address.
  46. ;-----------------------------------------------------------------------------
  47.  
  48. SetPalette      proc near
  49.  
  50.                 mov     cx,768
  51.                 mov     dx,3C8h
  52.                 xor     al,al
  53.                 out     dx,al
  54.                 mov     dx,3DAh
  55. WaitVRT1:       in      al,dx                   ; wait the start of
  56.                 test    al,8                    ; vertical retrace.
  57.                 jz      WaitVRT1
  58. WaitVRT2:       in      al,dx                   ; wait the end of
  59.                 test    al,8                    ; vertical retrace.
  60.                 jnz     WaitVRT2
  61.                 mov     dx,3C9h
  62.                 rep     outsb
  63.                 ret
  64.  
  65. SetPalette      endp
  66.  
  67. ;-----------------------------------------------------------------------------
  68. ; RotPalette - Rotates the palette and do fading.
  69. ; In:
  70. ;   Palette - Source palette.
  71. ;   Fade    - Fading level.
  72. ;-----------------------------------------------------------------------------
  73.  
  74. RotPalette      proc near Fade:word
  75.  
  76.                 mov     ax,ds
  77.                 mov     es,ax
  78.  
  79.                 lea     di,[FadePalette]
  80.                 mov     cx,16*3
  81.                 xor     ax,ax
  82.                 cld
  83.                 rep     stosb
  84.                 lea     si,[Palette+32*3]
  85.                 mov     cx,224*3
  86.                 cld
  87.                 rep     movsb
  88.                 lea     si,[Palette+16*3]
  89.                 mov     cx,16*3
  90.                 rep     movsb
  91.  
  92.                 lea     bx,[FadePalette]
  93.                 mov     cx,16
  94. RotLoop:        push    cx
  95.                 mov     si,bx
  96.                 mov     di,bx
  97.                 lodsb
  98.                 mov     ah,al
  99.                 lodsb
  100.                 mov     dl,al
  101.                 lodsb
  102.                 mov     dh,al
  103.                 mov     cx,15*3
  104.                 rep     movsb
  105.                 mov     al,ah
  106.                 stosb
  107.                 mov     al,dl
  108.                 stosb
  109.                 mov     al,dh
  110.                 stosb
  111.                 add     bx,16*3
  112.                 pop     cx
  113.                 loop    RotLoop
  114.  
  115.                 lea     si,[FadePalette]
  116.                 lea     di,[Palette]
  117.                 mov     cx,768
  118.                 rep     movsb
  119.  
  120.                 lea     si,[FadePalette]
  121.                 mov     cx,768
  122.                 mov     dx,[Fade]
  123. FadeLoop:       mov     al,[si]
  124.                 mul     dl
  125.                 shr     ax,7
  126.                 mov     [si],al
  127.                 inc     si
  128.                 loop    FadeLoop
  129.  
  130.                 lea     si,[FadePalette]
  131.                 call    SetPalette
  132.                 ret
  133.  
  134. RotPalette      endp
  135.  
  136. ;-----------------------------------------------------------------------------
  137. ; WormHole - Worm Hole demostration.
  138. ; In:
  139. ;   DS     - Data segment.
  140. ;   PicSeg - 320x200x256 picture segment address.
  141. ;-----------------------------------------------------------------------------
  142.  
  143. WormHole        proc    PicPtr:dword
  144.                 local   Fade:word
  145.  
  146.                 mov     ax,0013h                ; set 320x200x256 mode.
  147.                 int     10h
  148.  
  149.                 mov     ax,ds                   ; set black palette.
  150.                 mov     es,ax
  151.                 lea     di,[Palette]
  152.                 mov     cx,768
  153.                 xor     ax,ax
  154.                 cld
  155.                 rep     stosb
  156.                 lea     si,[Palette]
  157.                 call    SetPalette
  158.  
  159.                 lea     di,[Palette]            ; generate the palette.
  160.                 mov     cx,256
  161.                 xor     bx,bx
  162. GenPalette:     mov     ax,bx
  163.                 shr     ax,4
  164.                 and     ax,0Fh
  165.                 shl     ax,2
  166.                 mov     [di+0],al
  167.                 mov     ax,bx
  168.                 and     ax,0Fh
  169.                 shl     ax,1
  170.                 mov     [di+1],al
  171.                 mov     al,3Fh
  172.                 mov     [di+2],al
  173.                 add     di,3
  174.                 inc     bx
  175.                 loop    GenPalette
  176.  
  177.                 push    ds                      ; write the picture.
  178.                 mov     ax,0A000h
  179.                 mov     es,ax
  180.                 lds     si,[PicPtr]
  181.                 xor     di,di
  182.                 mov     cx,320*200
  183.                 cld
  184.                 rep     movsb
  185.                 pop     ds
  186.  
  187.                 mov     [Fade],0
  188.                 mov     [Timer],0
  189.  
  190. WormIn:         call    RotPalette,[Fade]       ; rotate palette.
  191.                 cmp     [Fade],128              ; adjust fade level.
  192.                 jae     WormTime
  193.                 inc     [Fade]
  194. WormTime:       inc     [Timer]                 ; check if timeout,
  195.                 cmp     [Timer],TIMEOUT
  196.                 jae     WormOut
  197. WormKey:        mov     ah,1                    ; or any key pressed.
  198.                 int     16h
  199.                 jz      WormIn
  200.  
  201. WormOut:        cmp     [Fade],128              ; start fading-out.
  202.                 ja      WormExit
  203.                 call    RotPalette,[Fade]
  204.                 dec     [Fade]
  205.                 jmp     WormOut
  206.  
  207. WormExit:       mov     ax,03h                  ; restore 80x25x16 textmode.
  208.                 int     10h
  209.                 ret
  210.  
  211. WormHole        endp
  212.  
  213. ;-----------------------------------------------------------------------------
  214. ; Start - Startup Code called from DOS.
  215. ; In:
  216. ;   ES - Program Segment Prefix.
  217. ;-----------------------------------------------------------------------------
  218.  
  219. Start           proc
  220.  
  221.                 mov     ax,@Data
  222.                 mov     ds,ax
  223.                 call    WormHole,SEG WormPic,OFFSET WormPic
  224.                 mov     ax,4C00h
  225.                 int     21h
  226.  
  227. Start           endp
  228.  
  229.                 end     Start
  230.