home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / CONTRSRC.ZIP / SRC / TYPEONE / SNAKE.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-11-04  |  9.9 KB  |  389 lines

  1.  
  2. ;*************************************************
  3. ; SNAKE PIC (C) 1994 Type One / TFL-TDV Prod.
  4. ; GFX by Fred
  5. ;*************************************************
  6.  
  7. INCLUDE PDFIK.INC ; DataFile Manager
  8. INCLUDE VIDEO.INC ; Flamoot VGA SetUp
  9. INCLUDE PLAYINFO.INC ; Player structures
  10. INCLUDE KEYBOARD.INC ; Keyboard macros
  11.  
  12. ;-----------------------------------------
  13. ; Déclaration modèle mémoire
  14. .386
  15. DGROUP GROUP _DATA,_BSS
  16. SNAKE_TEXT  SEGMENT DWORD PUBLIC USE16 'CODE'
  17.             ASSUME CS:SNAKE_TEXT,DS:DGROUP
  18. SNAKE_TEXT  ENDS
  19. _DATA  SEGMENT DWORD PUBLIC USE16 'DATA'
  20. _DATA  ENDS
  21. _BSS   SEGMENT DWORD PUBLIC USE16 'BSS'
  22. _BSS   ENDS
  23. ;-----------------------------------------
  24.  
  25. _DATA SEGMENT
  26.  
  27.  
  28. ;-- donnees pattern --
  29. EXTRN _Datafile  : BYTE
  30. EXTRN _OfsinDta  : DWORD
  31. Picname   BYTE 'snake.raw',0
  32. Picparam  PARAM_STRUC<2,_DATA,OFFSET _Datafile,OFFSET Picname,0,0,0,,,0>
  33.  
  34.  
  35. EXTRN _BlackPal: BYTE
  36. EXTRN _WhitePal: BYTE
  37.  
  38. _DATA ENDS
  39.  
  40. ;données non initialisées
  41. _BSS SEGMENT
  42.  
  43. EXTRN _FrameCounter     : WORD
  44. EXTRN _StartAdr         : WORD
  45. EXTRN _WorkAdr          : WORD
  46. EXTRN _NextAdr          : WORD
  47. EXTRN _Triple           : WORD
  48. EXTRN _SyncFlag         : WORD
  49. EXTRN _TmpPal           : BYTE
  50. EXTRN _FadeON           : WORD
  51. ;!!!!!!!!!! synchro avec music !!!!!!!!!!!!
  52. EXTRN _MP               : DWORD ; extern ModulePlayer * MB
  53. EXTRN _ReplayInfo       : mpInformation
  54.  
  55. ;---- param pour synchro avec zizik ----
  56. EVEN
  57. DebSong  WORD ?
  58. FinSong  WORD ?
  59.  
  60.  
  61.  
  62. EVEN
  63. Picseg    WORD ?        ; seg for pattern
  64.  
  65. FadeFlag WORD ?        ; flag pour fading
  66. FadePtr1 WORD 2 DUP(?) ; ptr sur palette a fader
  67. FadePtr2 WORD 2 DUP(?)
  68. Delai    WORD ?
  69. Termine  WORD ?        ; flag pour terminer !!!
  70.  
  71.  
  72. _BSS ENDS
  73.  
  74. SNAKE_TEXT SEGMENT
  75.      PUBLIC _StartSnake
  76.      EXTRN _AveragePAL : FAR
  77.  
  78.  
  79. ; Point d'entrée de l'intro !!!!!
  80. ;---------------------------------
  81. ALIGN
  82. EVEN
  83. _StartSnake PROC FAR
  84.  
  85.          push    bp                  ; bâtit le cadre de pile
  86.          mov     bp,sp
  87.  
  88.          pushad
  89.          MPUSH ds,es,fs,gs
  90.  
  91.          STARTUP
  92. ;------- recuperer parametres sur le stack !!!! --------
  93.  
  94.          mov     ax,WORD PTR ss:[bp+6]  ; debut pos
  95.          shl     eax,14
  96.          or      ax,WORD PTR ss:[bp+8]  ; debut row
  97.          or      ah,al
  98.          shr     eax,8
  99.          mov     DebSong,ax
  100.          mov     ax,WORD PTR ss:[bp+10] ; fin pos
  101.          shl     eax,14
  102.          or      ax,WORD PTR ss:[bp+12] ; fin row
  103.          or      ah,al
  104.          shr     eax,8
  105.          mov     FinSong,ax
  106.          xor     eax,eax
  107. ;-------------------------------------------------------
  108.  
  109.          push    m320x200x256c   ; set 320x200x256 col/chained 60hz
  110.          call    _SetVGA
  111.          add     sp,2
  112.  
  113.          STARTUP
  114. ;--------------------------------------
  115.          call    DoSnake             ; !!!!! title part !!!!!
  116. ;--------------------------------------
  117.  
  118.          mov  ax,0a000h              ; clear screen
  119.          mov  es,ax
  120.          xor  eax,eax
  121.          xor  di,di
  122.          mov  cx,65536/4
  123.          rep  stosd
  124.  
  125.          MPOP ds,es,fs,gs
  126.          popad
  127.          nop
  128.  
  129.          leave                       ; restore stack
  130.                                      ; mov sp,bp + pop bp
  131.          retf
  132.  
  133. _StartSnake ENDP
  134.  
  135. ;==============================================================================
  136. ;============================ Snake part ======================================
  137. ;==============================================================================
  138.  
  139. ALIGN
  140. EVEN
  141. DoSnake PROC NEAR
  142.  
  143. ;------------------------------------------------------------------------------
  144.          pushad
  145.  
  146.          mov     eax,_OfsinDta         ; OFFSET in Datafile
  147.          mov     Picparam.OfsInPdf,eax
  148.          mov     ax,_DATA              ; prepare for PDFIK call
  149.          mov     es,ax
  150.          mov     bx,OFFSET Picparam
  151.          pusha
  152.          call    PDFIK_ASM             ; call function 2 (extract+alloc)
  153.          popa
  154.          mov     ax,Picparam.BufSeg ; where is the file in mem ?
  155.          mov     Picseg,ax
  156.  
  157.          push    ds
  158.          push    es
  159.          mov     ax,Picseg
  160.          mov     ds,ax                 ; 32 bytes for Alchemy Header
  161.          mov     si,32                 ; palette offset
  162.          mov     es,ax
  163.          mov     di,32
  164.  
  165.          mov     cx,768                ; 256*3 components
  166. @@:      lodsb
  167.          shr     al,2                  ; 8 to 6 bits conversion
  168.          stosb
  169.          dec     cx
  170.          jnz     @B
  171.  
  172.          pop     es
  173.          pop     ds
  174.  
  175. ;---------------
  176.  
  177.          STARTUP
  178.  
  179.  
  180.          call    PutSnake              ; transfert bitmap in vidmem and
  181.                                        ; set pal to black !!!!
  182.  
  183.  
  184. ;---- wait right position/row in tune ----
  185.  
  186. WaitPos:
  187.          mov     _ReplayInfo.numChannels,4 ; 4 voices
  188.  
  189.          les     bx,DWORD PTR[_MP]
  190.          push    ds
  191.          push    OFFSET _ReplayInfo
  192.  
  193.          ; _MP->GetInformation(&ReplayInfo)
  194.  
  195.          call    (ModulePlayer PTR es:[bx]).GetInformation
  196.          add     sp,4
  197.  
  198.          mov     ax,_ReplayInfo.pos
  199.          shl     eax,14
  200.          or      ax,_ReplayInfo.row
  201.          or      ah,al
  202.          shr     eax,8
  203.          cmp     ax,WORD PTR[DebSong]  ; is it time ????
  204.          jb      WaitPos
  205.  
  206.          xor     eax,eax
  207. ;------------------------------------------
  208.  
  209.          mov     Termine,0 ; pas encore terminer !!!
  210.  
  211.          mov     _FadeON,0
  212.          mov     FadeFlag,0
  213.          mov     FadePtr1,OFFSET _BlackPal  ; Black to pic for the beginning !!!
  214.          mov     ax,ds
  215.          mov     FadePtr1+2,ax
  216.          mov     FadePtr2,32
  217.          mov     ax,Picseg
  218.          mov     FadePtr2+2,ax
  219.          mov     ax,_FrameCounter
  220.          mov     Delai,ax
  221.  
  222.  
  223.          mov     bx,_StartAdr
  224.          mov     WORD PTR[bx],0         ; _StartAdr->base = 0
  225.          mov     WORD PTR[bx+2],0       ; _StartAdr->flag = false
  226.          mov     bx,_WorkAdr
  227.          mov     WORD PTR[bx],0         ; _WorkAdr->base
  228.          mov     WORD PTR[bx+2],0       ; _WorkAdr->flag = false
  229.          mov     _Triple,0              ; "faux" double buffering
  230.          mov     _SyncFlag,1
  231.          VSYNC
  232.  
  233.  
  234. EVEN
  235. Main: ; -= VSYNC =-
  236.  
  237. wait_for_VBL:                       ; wait for Sync Flag
  238.          cmp     _SyncFlag,1
  239.          jne      wait_for_VBL
  240.          mov     _SyncFlag,0
  241.  
  242.  
  243.          cmp     FadeFlag,255
  244.          jb      BNewFade2
  245.          cmp     Termine,1    ; Terminer si dernier fade fini
  246.          je      GoOut
  247.  
  248.          mov     _FadeON,0    ; don't set _TmpPal anymore ...
  249.          jmp     @F
  250. BNewFade2:mov     ax,FadeFlag  ; average Black-MyPal
  251.          push    ax
  252.          push    ds
  253.          push    OFFSET _TmpPal
  254.          mov     ax,FadePtr1+2
  255.          push    ax
  256.          mov     ax,FadePtr1
  257.          push    ax
  258.          mov     ax,FadePtr2+2
  259.          push    ax
  260.          mov     ax,FadePtr2
  261.          push    ax
  262.          call    _AveragePAL
  263.          add     sp,7*2
  264.          mov     _FadeON,1            ; set new PAL during next VR !!!
  265.          mov     cx,_FrameCounter
  266.          sub     cx,Delai             ; temps chargement
  267.          mov     Delai,0              ; plus delai ....
  268.          test    cx,cx
  269.          jnz     BFaddi
  270.          inc     cx
  271. BFaddi:  add     FadeFlag,4           ; inc fade ..
  272.          dec     cx
  273.          jnz     BFaddi
  274. @@:
  275.  
  276. ;----------- test if we must finish ... ----------
  277.          mov     ax,_FrameCounter
  278.          mov     _FrameCounter,0 ; set counter to NULL
  279.  
  280.          mov     _ReplayInfo.numChannels,4 ; 4 voices
  281.  
  282.          les     bx,DWORD PTR[_MP]
  283.          push    ds
  284.          push    OFFSET _ReplayInfo
  285.  
  286.          ; _MP->GetInformation(&ReplayInfo)
  287.  
  288.          call    (ModulePlayer PTR es:[bx]).GetInformation
  289.          add     sp,4
  290.  
  291.          mov     ax,_ReplayInfo.pos
  292.          shl     eax,14
  293.          or      ax,_ReplayInfo.row
  294.          or      ah,al
  295.          shr     eax,8
  296.  
  297.          cmp     ax,WORD PTR[FinSong]    ; is it time ????
  298.          jb      @F                      ; to fade off ???
  299.  
  300.          mov     Termine,1
  301.  
  302.          cmp     FadePtr2,OFFSET _BlackPal
  303.          je      @F
  304.          mov     FadeFlag,0
  305.          mov     eax,DWORD PTR[FadePtr2]
  306.          mov     DWORD PTR[FadePtr1],eax   ; fade to black !!!!
  307.          mov     ax,ds
  308.          mov     FadePtr2+2,ax
  309.          mov     FadePtr2,OFFSET _BlackPal
  310.  
  311. @@:      xor     eax,eax
  312. ;--------------------------------------------------------------------
  313.  
  314.          SHOWTIME 32
  315.  
  316.          SHOWTIME 0
  317.  
  318.          mov     bx,_WorkAdr
  319.          mov     WORD PTR[bx+2],1
  320.  
  321.  
  322.          LOOP_UNTIL_KEY Main
  323.  
  324. ;===============================================================
  325.  
  326. GoOut:
  327.  
  328.         FLUSH_KEYBUF                  ; Flush keyboard buffer !!! ;-)
  329.  
  330.         mov     _FadeON,0             ; to be sure ....
  331.  
  332. ;----- EXIT -----
  333.  
  334.         STARTUP
  335.         mov     ax,Picseg             ; segment to free
  336.         mov     es,ax
  337.         mov     ah,49h                ; MFREE
  338.         int     21h
  339.  
  340.         popad
  341.         nop
  342.         ret
  343.  
  344. DoSnake   ENDP
  345.  
  346.  
  347. PutSnake PROC NEAR                    ; put bitmap and set pal to black !!!
  348.  
  349.  
  350.         MPUSH ax,cx,dx,si,di,ds,es
  351.  
  352.         mov   dx,3c8h                 ; pal reg.
  353.         xor   al,al
  354.         out   dx,al
  355.         inc   dl
  356.         mov   cx,768
  357. @@:     out   dx,al                   ; black ....
  358.         dec   cx
  359.         jnz   @B
  360.  
  361.  
  362.         mov   ax,Picseg
  363.         add   ax,(768+32) SHR 4       ; segment of Snake pic "ConTrast"
  364.         mov   ds,ax
  365.         mov   ax,0a000h               ; video mem
  366.         mov   es,ax
  367.  
  368.         xor   si,si                  ; skip alchemy header ...
  369.         xor   di,di
  370.  
  371.         cld
  372.         mov   cx,320*200/4
  373.         rep   movsd                   ; copy to screen
  374.  
  375.  
  376.  
  377.         MPOP  ax,cx,dx,si,di,ds,es
  378.         ret
  379.  
  380. PutSnake ENDP
  381.  
  382.  
  383. ;==============================================================================
  384.  
  385. SNAKE_TEXT ENDS
  386.  
  387.      END
  388.  
  389.