;ħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħ
;
; Design-Effect Nr.6. - %100 Protected Mode Code by CyberDancer/Shock!/Mfc
;
; First shown: - Show by Majic 12
; Advancement: - Now with variable foreground anim / background anim!
;
;ħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħħ
                .386p
                .model flat, c
                locals
                .code

extrn           d61            :dword
extrn           d62            :dword
extrn           pic1           :dword
extrn           pic2           :dword

directions      db      160 dup (0)             ; it stores whether a box will
db_temp         dd      0                       ; increase or decrease
lofasz          dd      200

boxmatrix:      y = 20                          ; storing the boxmatrix
                rept 10                         ; try some more variations!
                x = y
                 rept 16
                 db x
                  if x
                  x = x - 1
                  endif
                 endm
                y = y - 1
                endm

public          designeffect6

designeffect6:  pushad
                mov     ecx,lofasz
                dec     lofasz
                call    clearbuffer
                call    displayboxes
                call    fuckthematrix
                call    rasterwait
                call    rasterwait
                popad
                ret

displayboxes:   pushad
                mov     db_temp,ecx             ; store the actual frame
                mov     ecx,0
db_mainloop:    mov     eax,ecx
                shr     eax,4
                mov     edx,6400
                mul     edx
                mov     edx,ecx
                and     edx,0fh
                lea     edi,[edx+edx*4]
                shl     edi,2
                add     edi,eax                 ; we calculated the box's
                mov     ebp,edi                 ; upper left corner
                add     ebp,d61
                add     edi,d62                 ; from where to copy pic/anim
                movzx   eax,byte ptr [boxmatrix+ecx]
                cmp     db_temp,160             ; until 160 we can't see the
                jb      db_noindul              ; whole other pic...
                push    ecx
                mov     ecx,db_temp             ; here we make the change
                sub     ecx,160                 ; smoother and therefore we
                shr     ecx,1                   ; use the actual phase to
                add     eax,ecx                 ; determine if we need
                pop     ecx                     ; corrections
                cmp     eax,20
                jna     db_noindul
                mov     eax,20                  ; we may get higher nrs than 20
db_noindul:     cmp     eax,0                   ; or 0 too... then we must esc.
                je      db_ureskocka
                mov     edx,eax
db_onebox:      mov     ebx,0
db_oneline:     mov     ah,byte ptr [ebp+ebx]   ; it's like a movsb but...
                mov     byte ptr [edi+ebx],ah   ; doesn't destroy edi & ebp
                inc     ebx
                movzx   eax,al
                cmp     ebx,eax                 ; are we done with 1 line?
                jne     db_oneline
                add     edi,320
                add     ebp,320
                dec     edx
                jnz     db_onebox               ; are we done with one box?
db_ureskocka:   inc     ecx
                cmp     ecx,160                 ; are we done with all the
                jne     db_mainloop             ; boxes?
                popad
                ret

fuckthematrix:  pushad                          ; this will determine whether
                mov     ebx,0                   ; to inc or dec the values of
fuckmainloop:   cmp     byte ptr [directions+ebx],0    ; boxmatrix
                je      fm_deccer
                cmp     byte ptr [boxmatrix+ebx],20
                je      fm_maxreached
                inc     byte ptr [boxmatrix+ebx]
                jmp     fuckmainend
fm_maxreached:  mov     byte ptr [directions+ebx],0
                jmp     fuckmainend
fm_deccer:      cmp     byte ptr [boxmatrix+ebx],0
                je      fm_minreached
                dec     byte ptr [boxmatrix+ebx]
                jmp     fuckmainend
fm_minreached:  cmp     ecx,40
                jbe     fuckmainend
                mov     byte ptr [directions+ebx],1
fuckmainend:    inc     ebx
                cmp     ebx,160
                jne     fuckmainloop
                popad
                ret

clearbuffer:    push    edi ecx eax             ; clears the screenbuf
                mov     edi,d62                 ; we may put a screen here
                mov     esi,pic1
                mov     ecx,16000               ; and then we get a very
                mov     eax,0                   ; cool efffect! we can mix
                rep     movsd                   ; two routines running
                pop     eax ecx edi             ; realtime!!
                ret

rasterwait:     push    eax edx
                mov     edx,3dah
rasterw1:       in      al,dx
                and     al,8
                je      rasterw1
rasterw2:       in      al,dx
                and     al,8
                jne     rasterw2
                pop     edx eax
                ret
                end
