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

  1. ;=============================================================================
  2. ; shades.asm - Bop Shades Demostration.
  3. ;                                                    File created: 10-21-93
  4. ; Copyright (c) 1993, Carlos Hasan                  Last modified: 10-21-93
  5. ;
  6. ; Description:
  7. ;   This code implements bop shades using a gray palette of 64 levels in
  8. ;   the VGA 320x200x256 graphics mode.
  9. ;
  10. ; Portability:
  11. ;  Requires Turbo Assembler 3.2 or better to be assembled.
  12. ;  Dependent on the IBM PC 286 and the VGA graphics card.
  13. ;=============================================================================
  14.  
  15.                 jumps
  16.                 .model  small,pascal
  17.                 .286
  18.  
  19.                 dosseg                          ; used for linking like 
  20.                 .stack 1024                     ; an Standalone program.
  21.  
  22.                 global  BopShades:proc
  23.  
  24. ;======================== Demo Equates and Data ==============================
  25.  
  26. TIMEOUT         equ     4000                    ; Number of Frames Total.
  27. MAXWIDTH        equ     320                     ; Screen Dimens.
  28. MAXHEIGHT       equ     200
  29. CENTERX         equ     160-25                  ; Screen Center Coord.
  30. CENTERY         equ     100-25
  31. MAXBOPS         equ     150                     ; Number of Bops.
  32. RADIUSX         equ     120                     ; Bops Path Radius.
  33. RADIUSY         equ     60
  34.  
  35.                 .data
  36.  
  37.                 include shades.inc              ; Bop Points Table.
  38.                 include sincos.inc              ; Sin/Cos Table.
  39.  
  40. BopQueue        dw      MAXBOPS dup(?)          ; Bops Positions Queue.
  41. BopHead         dw      ?                       ; Current Queue Head.
  42. Angle           dw      ?                       ; Bops Path Generation
  43. Phase1          dw      ?                       ; Parameters.
  44. Phase2          dw      ?                       ; Angle, Phase, Incs.
  45. PhInc1          dw      ?
  46. PhInc2          dw      ?
  47. Frames          dw      ?                       ; Frame Counter.
  48.  
  49. ;======================== Demo Routines ======================================
  50.  
  51.                 .code
  52.  
  53. ;-----------------------------------------------------------------------------
  54. ; ShowBop - Shows a BopShade at specified position.
  55. ; In:
  56. ;   DI  - Position Offset.
  57. ;-----------------------------------------------------------------------------
  58.  
  59. ShowBop         proc near
  60.  
  61.                 mov     ax,0A000h
  62.                 mov     es,ax
  63.                 xor     si,si
  64.                 mov     cx,BOPPTS
  65. ShowLoop:       mov     al,[BopAddTab+si]
  66.                 shl     si,1
  67.                 mov     bx,[BopTab+si]
  68.                 shr     si,1
  69.                 add     es:[bx+di],al
  70.                 inc     si
  71.                 loop    ShowLoop
  72.                 ret
  73.  
  74. ShowBop         endp
  75.  
  76. ;-----------------------------------------------------------------------------
  77. ; HideBop - Hides a BopShade at specified position.
  78. ; In:
  79. ;   DI  - Position Offset.
  80. ;-----------------------------------------------------------------------------
  81.  
  82. HideBop         proc near
  83.  
  84.                 mov     ax,0A000h
  85.                 mov     es,ax
  86.                 xor     si,si
  87.                 mov     cx,BOPPTS
  88. HideLoop:       mov     al,[BopAddTab+si]
  89.                 shl     si,1
  90.                 mov     bx,[BopTab+si]
  91.                 shr     si,1
  92.                 sub     es:[bx+di],al
  93.                 inc     si
  94.                 loop    HideLoop
  95.                 ret
  96.  
  97. HideBop         endp
  98.  
  99. ;-----------------------------------------------------------------------------
  100. ; InitBops - Initializes the BopShade Queue.
  101. ;-----------------------------------------------------------------------------
  102.  
  103. InitBops        proc near
  104.  
  105.                 mov     ax,ds
  106.                 mov     es,ax
  107.                 lea     di,[BopQueue]
  108.                 mov     cx,MAXBOPS
  109.                 mov     ax,0FFFFh               ; illegel offset,
  110.                 cld                             ; because first bops
  111.                 rep     stosw                   ; are hidden.
  112.                 mov     [BopHead],0
  113.                 ret
  114.  
  115. InitBops        endp
  116.  
  117. ;-----------------------------------------------------------------------------
  118. ; PutBop - Puts a new BopShade onto the Queue and updates the screen.
  119. ; In:
  120. ;   (CX,DX) - Screen coordinates.
  121. ;-----------------------------------------------------------------------------
  122.  
  123. PutBop          proc near
  124.  
  125.                 mov     di,dx
  126.                 imul    di,MAXWIDTH
  127.                 add     di,cx
  128.                 mov     bx,[BopHead]
  129.                 xchg    [BopQueue+bx],di
  130.                 cmp     di,MAXWIDTH*MAXHEIGHT
  131.                 jae     PutNewBop
  132.                 call    HideBop
  133. PutNewBop:      mov     bx,[BopHead]
  134.                 mov     di,[BopQueue+bx]
  135.                 cmp     di,MAXWIDTH*MAXHEIGHT
  136.                 jae     SkipShow
  137.                 call    ShowBop
  138. SkipShow:       add     [BopHead],2
  139.                 cmp     [BopHead],2*MAXBOPS
  140.                 jb      ByePutBop
  141.                 mov     [BopHead],0
  142. ByePutBop:      ret
  143.  
  144. PutBop          endp
  145.  
  146.  
  147. ;-----------------------------------------------------------------------------
  148. ; BopShades - Performs the Demostration.
  149. ; In:
  150. ;   DS - Data Segment.
  151. ;-----------------------------------------------------------------------------
  152.  
  153. BopShades       proc
  154.  
  155.                 mov     ax,13h                  ; Sets 320x200x256 mode.
  156.                 int     10h
  157.  
  158.                 mov     dx,3C8h                 ; Set the Shaded Palette.
  159.                 xor     al,al
  160.                 out     dx,al
  161.                 inc     dx
  162.                 mov     cx,256
  163.                 xor     ah,ah
  164. SetPal:         xor     al,al
  165.                 out     dx,al
  166.                 out     dx,al
  167.                 mov     al,ah
  168.                 out     dx,al
  169.                 cmp     ah,63
  170.                 jae     SetBrk
  171.                 inc     ah
  172. SetBrk:         loop    SetPal
  173.  
  174.                 call    InitBops                ; Init BopsQueue.
  175.  
  176.                 mov     [Angle],0               ; Init Variables.
  177.                 mov     [Phase1],2*1024
  178.                 mov     [Phase2],2*1024
  179.                 mov     [PhInc1],2
  180.                 mov     [PhInc2],3
  181.                 mov     [Frames],0
  182.  
  183. ShadesLoop:     mov     ax,[Angle]              ; Compute X Coord.
  184.                 imul    [Phase1]
  185.                 mov     bl,ah
  186.                 mov     bh,dl
  187.                 shr     bx,2
  188.                 xor     bh,bh
  189.                 mov     al,[CosTable+bx]
  190.                 mov     ah,RADIUSX
  191.                 imul    ah
  192.                 sar     ax,6
  193.                 add     ax,CENTERX
  194.                 mov     cx,ax
  195.  
  196.                 mov     ax,[Angle]              ; Compute Y Coord.
  197.                 imul    [Phase2]
  198.                 mov     bl,ah
  199.                 mov     bh,dl
  200.                 shr     bx,2
  201.                 xor     bh,bh
  202.                 mov     al,[SinTable+bx]
  203.                 mov     ah,RADIUSY
  204.                 imul    ah
  205.                 sar     ax,6
  206.                 add     ax,CENTERY
  207.                 mov     dx,ax
  208.  
  209.                 call    PutBop                  ; Puts BopShade at (CX,DX)
  210.  
  211.                 mov     ax,[Angle]              ; Increment Angle.
  212.                 inc     ax
  213.                 and     ax,1023
  214.                 mov     [Angle],ax
  215.  
  216.                 mov     ax,[Phase1]             ; Increment Phase1.
  217.                 add     ax,[PhInc1]
  218.                 cwd
  219.                 mov     bx,5*1024
  220.                 div     bx
  221.                 mov     [Phase1],dx
  222.  
  223.                 mov     ax,[Phase2]             ; Increment Phase2.
  224.                 add     ax,[PhInc2]
  225.                 cwd
  226.                 mov     bx,5*1024
  227.                 div     bx
  228.                 mov     [Phase2],dx
  229.  
  230.                 inc     [Frames]                ; enough frames showed?
  231.                 cmp     [Frames],TIMEOUT
  232.                 ja      ShadesBye
  233.  
  234.                 mov     ah,1                    ; any key pressed?
  235.                 int     16h
  236.                 je      ShadesLoop
  237.  
  238. ShadesBye:      
  239.                 mov     cx,MAXBOPS              ; Hides all the Bops.
  240. HidesLoop:      push    cx
  241.                 mov     cx,0FFFFh
  242.                 mov     dx,cx
  243.                 call    PutBop
  244.                 pop     cx
  245.                 loop    HidesLoop
  246.  
  247.                 mov     ax,03h
  248.                 int     10h
  249.                 ret
  250.  
  251. BopShades       endp
  252.  
  253.  
  254. ;-----------------------------------------------------------------------------
  255. ; Start - Startup Code called from DOS.
  256. ; In:
  257. ;   DS - Program Segment Prefix.
  258. ;-----------------------------------------------------------------------------
  259.  
  260. Start           proc
  261.  
  262.                 mov     ax,@Data
  263.                 mov     ds,ax
  264.                 call    BopShades
  265.                 mov     ax,4C00h
  266.                 int     21h
  267.  
  268. Start           endp
  269.  
  270.                 end     Start
  271.