home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / pascal / rehack / demosrc / anim5.asm next >
Encoding:
Assembly Source File  |  1991-04-13  |  13.5 KB  |  386 lines

  1. ;****************************************************************************
  2. ;+    Mode 13h animation test program. Rotates a golden cross above a complex +    
  3. ;+    background using logical operations to manipulate the bitmaps           +
  4. ;+**************************************************************************+    
  5. ;+    developed on: 4-8-91                                                    +
  6. ;+  last update : 4-12-91                                                   +
  7. ;+  developed by: Chris Lampton                                                         +
  8. ;+                Mark Betz                                                           +
  9. ;+  caller: Turbo Pascal                                                    +
  10. ;+**************************************************************************+
  11. ;+  This source code is copyrighted 1991 by the Gamers Programming Workshop +
  12. ;+  which is a function of the GAMERS forum, Compuserve. Limited license    +
  13. ;+  is granted for distribution and copying provided that this notice is    +
  14. ;+  left intact on all versions. Use of these routines is permitted without +
  15. ;+    license or fee. No price may be charged beyond disk costs for this code +                                                        +
  16. ;+**************************************************************************+
  17.  
  18.     TITLE GPWAnim
  19.     
  20.     .MODEL    TPascal
  21.     .DATA    
  22.         ;    constants
  23.         ;    not all of these are being used
  24.  
  25.         V_Seg           equ 0A000H        ;     video segment
  26.          GC_Index_reg     equ 003CEH        ;     port address of GC index register
  27.         StatReg1        equ 003DAH      ;     port address of VGA status register
  28.         VSMask            equ    00008H        ;    mask for bit 4, vsynch signal
  29.         SeqIReg         equ 003C4H      ;    port address of Sequencer Index Reg
  30.         SeqDReg            equ 003C5H        ;    port address of Sequencer Data Reg
  31.         DEMask          equ 00020H      ;   mask for bit 5, Refresh enable    
  32.  
  33.         ;    variables
  34.         
  35.         x1                DW     ?            ;    current top left x display coord
  36.         y1                DW     ?            ;    current top left y display coord
  37.         ox1                DW     ?            ;    old top left x display coord
  38.         oy1                DW     ?            ;    old top left y display coord
  39.         DeltaX1            DW    ?            ;    x incremental change per iteration
  40.         DeltaY1            DW    ?            ;    y incremental change per iteration
  41.         FrameCnt        DB    ?            ;    number of current frame
  42.         SvFrm1        DB  2600 DUP (?)    ;    background save array
  43.         OldVofs            DW    ?            ;    hold precalculated offsets into
  44.         NewVofs            DW    ?            ;    the video buffer
  45.  
  46. ;    variables and structures declared in Turbo Pascal calling module
  47.  
  48. ;******************************************************************************
  49. ;    PROGRAMMER'S NOTE:
  50. ;    This module is written to accept Pascal calling conventions. This basically
  51. ;    means it expects parameters pushed on the stack in order of left-right
  52. ;   occurence in the function definition. Also, the called routine is expected
  53. ;    to clean up passed parameters and restore the stack before returning. I 
  54. ;    don't believe converting it to be called by C++ would be much of a chore.
  55. ;******************************************************************************
  56.  
  57. ;******************************************************************************
  58. ;    EXTERNAL VARIABLE DECLARATION NOTES
  59. ;
  60. ;    Calling programs must declare the following variables:
  61. ;
  62. ;    FRMBuff   : pointer to buffer containing the primary image frames
  63. ;    SvFrm1      : array containing saved background image data
  64. ;    FrameWid  : word containing frame width in bytes    
  65. ;    FrameDep  : word containing frame depth in lines
  66. ;   FrameSize : word containing frame size in bytes
  67. ;    TopFrame  : byte containing number of last frame in buffer
  68. ;******************************************************************************
  69.  
  70.         EXTRN FRMBuff:DWORD                ;    pointer to frame image buffer
  71.         EXTRN PcxBuff:DWORD                ;    pointer to background image
  72.         EXTRN FrameWid:WORD                ;    global frame width in pixels
  73.         EXTRN FrameDep:WORD                ;    global frame depth in lines
  74.         EXTRN FrameSize:WORD            ;    global frame size variable
  75.         EXTRN TopFrame:BYTE                ;    global top frame number
  76.  
  77.     DATA    ENDS
  78.     .CODE    
  79.         assume cs:CODE
  80.  
  81.     PUBLIC    _Animate
  82.                 
  83. ;******************************************************************************
  84. ;    Procedure _CalcVOffset. Calculate the offset for the new video frame based
  85. ;    on the current values of x1, and y1. Stores result in NewVofs. Swaps the
  86. ;    old value of NewVOfs into OldVofs
  87. ;
  88. ;
  89. ;    call: nothing
  90. ;    destroys: ax,bx,dx
  91. ;*****************************************************************************
  92.  
  93.     _CalcVOffset PROC NEAR
  94.          ;    calculate the offset into the video buffer by the formula
  95.         ;    ((y-1)*320)+x = offset
  96.  
  97.         mov        ax,NewVofs                ;    mov current frame ofs to OldVofs
  98.         mov        OldVofs,ax
  99.         mov        ax,y1
  100.         mov        bx,x1
  101.         sub        ax,1                    ;    subtract 1 from the y coord
  102.         push    bx                        ;    save the x coord
  103.         mov        bx,320                    ;    move the bytes per line value to bx
  104.         mul        bx                        ;    multiply ax by bx, result in ax
  105.         pop        bx                        ;    restore the x coordinate
  106.         add        ax,bx                    ;    add the x coordinate to mul result
  107.         mov        NewVofs,ax                ;    new offset value in ax
  108.         ret
  109.     _CalcVOffset ENDP    
  110.  
  111. ;*****************************************************************************
  112. ;    Procedure _GetBKGRND. Grabs a background frame at the current offset into
  113. ;    video ram. Works in mode 13h ONLY. 
  114. ;
  115. ;    call: with frame depth in lines in cx, frame width in bytes in dx, pointer
  116. ;    to frame buffer in es:di
  117. ;    
  118. ;    destroys: ax, cx, es, di, si
  119. ;***************************************************************************** 
  120.  
  121.     _GetBKGRND    PROC NEAR
  122.         push    ds
  123.         mov        si,NewVOfs                ;    put vram offset in si
  124.         mov        ax,WORD PTR PcxBuff+2    ;    get the image segment into
  125.         mov        ds,ax                    ;    the ds register
  126.         cld
  127.     gbgloop:
  128.         push    cx                        ;    save the line counter
  129.         mov        cx,dx                    ;    initialize byte counter
  130.         rep        movsb                    ;    move bytes from ds:si to es:di
  131.         pop        cx                        ;    restore line counter
  132.         add        si,320                    ;    move to next line
  133.         sub        si,dx                    ;    need to subtract frame width
  134.         loop    gbgloop                    ;    do the next line
  135.         pop        ds
  136.         ret
  137.     _GetBKGRND    ENDP
  138.  
  139. ;*****************************************************************************
  140. ;    Procedure _PutBKGRND. Displays a background frame at the passed x,y coord-
  141. ;    inate pair. Works in mode 13h ONLY. Only non-zero bytes are displayed.
  142. ;
  143. ;    call: with frame depth in lines in cx, frame width in bytes in dx, pointer
  144. ;    to frame buffer in ds:si
  145. ;    
  146. ;    destroys: ax, cx, es, di, si
  147. ;***************************************************************************** 
  148.  
  149.     _PutBKGRND    PROC NEAR
  150.         mov        di,OldVofs                ;    put vram offset in ax
  151.         mov        ax, WORD PTR PcxBuff+2    ;    get the video segment into
  152.         mov        es,ax                    ;    the es register
  153.         cld
  154.     pbgloop:
  155.         push    cx                        ;    save the line counter
  156.         mov        cx,dx                    ;    initialize byte counter
  157.         rep        movsb                    ;    move bytes from ds:si to es:di
  158.         pop        cx                        ;    restore line counter
  159.         add        di,320                    ;    move to next line
  160.         sub        di,dx                    ;    need to subtract frame width
  161.         loop    pbgloop                    ;    do the next line
  162.         ret
  163.     _PutBKGRND    ENDP
  164.  
  165. ;*****************************************************************************
  166. ;    Procedure _PutFrame. Displays a frame from the frame buffer. Works in mode
  167. ;    13h ONLY. Only non-zero bytes are displayed.
  168. ;
  169. ;    call: with frame depth in lines in cx, frame width in bytes in dx, pointer 
  170. ;    to frame buffer in ds:si
  171. ;    
  172. ;    destroys: ax, bx, cx, es, di, si
  173. ;***************************************************************************** 
  174.  
  175.     _PutFrame   PROC NEAR
  176.         mov        di,NewVofs                ;    put offset into vram in di
  177.         mov        ax, WORD PTR PcxBuff+2    ;    get the video segment into
  178.         mov        es,ax                    ;    the es register
  179.         xor        bx,bx                    ;    this is a counter
  180.  
  181.     PFrmLoop:        
  182.         cmp        BYTE PTR [si+bx],0        ;    is the next byte in the frame 0
  183.         je        nodisp2                    ;    if yes don't display
  184.         mov     al,[si+bx]                ;    display the image byte
  185.         mov        es:[di+bx],al
  186.     nodisp2:
  187.         inc        bx                        ;    increment the counter
  188.         cmp        bx,dx                   ;    at the end of the line?
  189.         jb        PFrmLoop
  190.         add        si,dx                   ;    point to next line in frame buff
  191.         add        di,320                    ;    point to next line in vram
  192.         xor     bx,bx                    ;    re-zero the byte counter
  193.         loop    PFrmLoop                ;    go process the next line
  194.         ret
  195.     _PutFrame   ENDP
  196.  
  197. ;*****************************************************************************
  198. ;    Procedure _CheckKey. Returns a 1 in ax if there was a key in the buffer
  199. ;    else it returns a 0 in ax. The key is removed from the buffer.
  200. ;
  201. ;    call: nothing
  202. ;    destroys: ax
  203. ;*****************************************************************************
  204.  
  205.     _CheckKey    PROC NEAR
  206.         mov        ah, 01h                    ;    function 01h: check for key
  207.         int        016h
  208.         jz        NoKey                    ;    if zf not set then no key ready
  209.         mov        ah,0h                    ;    function 0h, read key from buffer
  210.         int        016h
  211.         mov        ax,1                    ;    return a 1 in ax
  212.         jmp     kend                    
  213.     NoKey:
  214.         mov        ax,0                    ;    return a 0 in ax
  215.     kend:    
  216.         ret
  217.     _CheckKey    ENDP
  218.  
  219. ;*****************************************************************************
  220. ;    Procedure _Wait. Waits in a null loop.
  221. ;    call: nothing
  222. ;    destroys: nothing
  223. ;*****************************************************************************
  224.  
  225.     _Wait        PROC NEAR
  226.         push    cx
  227.         mov        cx,63000
  228.     waitloop:
  229.         loop    waitloop
  230.         pop        cx
  231.         ret                    
  232.     _Wait        ENDP
  233.  
  234. ;*****************************************************************************
  235. ;    Procedure _AdjCoords. Increments the x and y position, checks for coll-
  236. ;    ision with the edge of the screen, and flips the sign of DeltaX1 or 
  237. ;    DeltaY1 if a collisions is detected. It also saves the last x,y pair in
  238. ;    ox1, and oy1.
  239. ;
  240. ;    call: nothing
  241. ;    destroys: ax
  242. ;*****************************************************************************
  243.  
  244.     _AdjCoords    PROC NEAR
  245.         mov        ax, x1                    ;    move the current x value to ox1
  246.         mov        ox1,ax                
  247.         mov        ax,    y1                    ;    move the current y value to oy1
  248.         mov        oy1,ax
  249.  
  250.         mov        ax,x1
  251.         add        ax,DeltaX1                ;    increment x1
  252.         mov        x1,ax
  253.         cmp        x1,270                    ;    x1 greater than 265?
  254.         jb        testx1low                ;    if so then check low
  255.         neg        DeltaX1                    ;    else flip DeltaX1's sign
  256.         jmp        x1okay                    ;    and skip the low check
  257.     testx1low:
  258.         cmp        x1,2                    ;    is it greater than 10?
  259.         ja        x1okay                    ;    if so then no action
  260.         neg        DeltaX1                    ;    else flip DeltaX1's sign        
  261.     x1okay:
  262.         mov        ax,y1
  263.         add        ax,DeltaY1                ;    do the same for y1
  264.         mov        y1,ax
  265.         cmp        y1,146
  266.         jb        testy1low
  267.         neg        DeltaY1
  268.         jmp        y1okay
  269.     testy1low:
  270.         cmp        y1,2
  271.         ja        y1okay
  272.         neg        DeltaY1
  273.     y1okay:
  274.         ret
  275.     _AdjCoords     ENDP
  276.  
  277. ;*****************************************************************************
  278. ;    Procedure _Animate handles the animation of the rotating cross. It expects
  279. ;    the starting x,y coordinate pair to be on the stack when it is called.
  280. ;    The calling program must also have declared variables as described above,
  281. ;    and must have loaded the frame data into the buffers.
  282. ;
  283. ;    call: push x, then y
  284. ;
  285. ;    destroys: nothing
  286. ;*****************************************************************************
  287.  
  288.     _Animate     PROC NEAR
  289.         push     bp
  290.         mov        bp,    sp                    ;    set up stack frame
  291.         push     ds                        ;    save the registers
  292.         push     es
  293.         push    ss
  294.         push    di
  295.         push    si
  296.         push    ax
  297.         push    bx
  298.         push    cx
  299.         push    dx        
  300.  
  301.         mov        ax,    [bp+6]                ;    get the starting x,y coords
  302.         mov        x1,    ax                    
  303.         mov        ax,    [bp+4]
  304.         mov        y1,    ax    
  305.         mov        FrameCnt,0                ;    zero out the frame counter
  306.         mov        DeltaX1,1                ;    start with delta values of 1
  307.         mov        DeltaY1,1                            
  308.  
  309.  
  310.         CALL    _CalcVOffset            ;    sets up the offsets into vram
  311.         mov        ax,NewVofs                ;    first time through we want these
  312.         mov        OldVofs,ax                ;    pointing the same place
  313.         mov        ax,ds                    ;    set up for _GetBKGRND call
  314.         mov        es,ax
  315.         mov        di,OFFSET SvFrm1
  316.         mov        cx,FrameDep                ;    frame depth in cx
  317.         mov        dx,FrameWid                ;    frame width in dx
  318.         CALL    _GetBKGRND                ;    get the background at OldVofs
  319.  
  320.         mov        si,WORD PTR FRMBuff        ;    put offset to first frame in si
  321.         push     si                        ;    save it on the stack
  322.         mov        cx,FrameDep                ;    frame depth in cx
  323.         CALL    _PutFrame                ;    blit the first frame at NewVofs
  324.         pop        si
  325.         
  326.     MainAnimLoop:
  327.         CALL    _AdjCoords                ;    increment coordinates
  328.         CALL    _CalcVOffset            ;    get the video offset into ax
  329.         add        si,FrameSize            ;    increment pointer into frame buffer
  330.         push    si                        ;    save si (offset into frame buffer)
  331.  
  332.         mov        cx,FrameDep                ;    do part of set-up for _PutBKGRND
  333.         mov        si, OFFSET SvFrm1
  334.         mov        dx,FrameWid                ;    frame width in bytes in dx
  335.         CALL    _PutBKGRND                ;    restore the background
  336.  
  337.         mov        cx,FrameDep                ;    set up for call to _GetBKGRND
  338.         mov        ax,@DATA
  339.         mov        es,ax
  340.         mov        di,OFFSET SvFrm1
  341.         CALL    _GetBKGRND                ;    restore the background
  342.  
  343.         pop        si                        ;    restore frame buffer offset
  344.         push    si                        ;    and save it again
  345.         mov        cx,FrameDep                ;    see _PutFrame for details on call
  346.         CALL    _PutFrame        
  347.  
  348.         mov        cx,64000                ;    size of mode 13h screen
  349.         mov        ax,0A000h                ;    get video segment into es
  350.         mov        es,ax
  351.         xor        di,di                    ;    offset 0
  352.         push    ds                        ;    save data segment
  353.         mov        bx,WORD PTR PcxBuff+2    ;    get image buffer segment
  354.         mov        si,WORD PTR PcxBuff        ;    offset of image buffer
  355.         mov        ds,bx                    ;    set up ds to image segment
  356.         rep        movsw                    ;    move 64000 bytes
  357.         pop        ds                        ;    restore data segment
  358.         pop        si                        ;    restore frame buffer offset
  359.  
  360.         inc        FrameCnt                ;    increment FrameCnt and check it 
  361.         mov        al,FrameCnt
  362.         cmp        al,TopFrame                ;    against TopFrame
  363.         jb        MainAnimLoop
  364.         CALL    _CheckKey                ;    check for a key
  365.         cmp        ax,1                    ;    see if one was ready
  366.         je        alldone                    ;    if so all done
  367.         mov        FrameCnt,0                ;    reset to first frame
  368.         mov        si,WORD PTR FRMBuff        ;    set offset to first frame
  369.         jmp        MainAnimLoop            ;    start sequence again
  370.     alldone:
  371.         pop        dx                        ;    restore the registers
  372.         pop        cx
  373.         pop        bx
  374.         pop        ax
  375.         pop        si
  376.         pop        di
  377.         pop        ss
  378.         pop        es
  379.         pop        ds
  380.         mov        sp,bp                    ;    and the stack
  381.         pop        bp            
  382.         ret        4
  383.     _Animate    ENDP
  384.     CODE    ENDS
  385. END
  386.