;---------------------------------------------------------------------------
; Diz is George Stark typing ....
;
; You see now another short but nice source code of me ...
; it is no new effect but I guess a really nice one and I have seen it
; the first time in an intro of a friend called Digisnap/FATAL! .. Now
; I had a lot of free time and I didn't know what I could do so I started
; coding this effect ..  and you see I managed it hehehe ..
;
; So ... I tried to comment the source and I did it really well but your
; problem could be the principle ... okay .. you have got a 3D plain
; ( I used a 40x40 field ) ... and now you take a sine function or something
; like this and change the y position (or Offset) of every point using the
; values ... and instead of a pixel you write a block .. and that's it !
; easy eh ? ... and don't blame me 'cause of using so many BIG tables
; ... everybody uses ASM for a great speed ... to use tables is more
; comfortable and faster than realtime calculating everything ... in an
; intro or demo for a competition it could be important but here it is
; not a problem .... for pre-calculating I have used TP .. slow but
; easy to program mathematical problems ... for questions ask me ...
; and if you got new ideas or use the source greet me and YAKUZA .. hehe
;
;                                              thx and bye .. cu l8er
;
;                                                George Stark/YAKUZA
;
;----------------------------------------------------------------------------

.model small                                             ; enough ...
.stack 100h                                              ; too much ?!!?
.386                                                     ; for greater
.data                                                    ; opcodes ...
                                  include kurve.tab
                                  include thewave.tab
                                  include abstand.tab
                                  adder    dw 0
                                  virtual  dw 0
                                  copyrights db 'Code by GEORGE STARK/YAKUZA DS+HS , 07.06.1995',10,13,'$'
                                  error    db 'Memory error ...',10,13,'$'
.code

                          retrace proc near
                                  push dx
                                  push ax
                                  mov dx,03DAh
                                  mov ah,8
active:                           in al,dx
	                          and al,ah
			          je active
test_again:                       in al,dx
	                          and al,ah
                 		  jne test_again
                                  pop ax
                                  pop dx
                                  retn
                          retrace endp

                            block proc near
                                  pusha
                                  mov di,ds:[si]         ; screen offset
                                  mov bx,ds:[si+2]       ; widht
                                  mov cx,ds:[si+4]       ; height
                                  inc cx
                                  add di,dx              ; new_height
                                  xor ax,ax
                                  mov ax,dx
                                  shr ax,7               ; div 128
                                  add al,120             ; new color
whole_block:                      push cx
                                  mov cx,bx
                                  push di
                                  rep stosb              ; one line
                                  pop di
                                  add di,320             ; next line offset
                                  pop cx
                                  loop whole_block       ; all lines
                                  popa
                                  retn
                            block endp

                    clear_virtual proc near
                                  pusha
                                  mov di,16000           ; di to offset 16000
                                  mov cx,8000            ; 8000x4 bytes
                                  xor eax,eax
                                  rep stosd              ; clear memory
                                  popa
                                  retn
                    clear_virtual endp

                     copy_virtual proc near
                                  pusha                  ; flicker free
                                  push es                ; deleting +
                                  push ds                ; painting ..
                                  mov ax,virtual
                                  mov ds,ax              ; set ds to virtual
                                  mov ax,0A000h
                                  mov es,ax              ; es to 0A000h
                                  mov di,16000
                                  mov si,di
                                  mov cx,8000
                                  rep movsd              ; copy 8000x4 bytes
                                  pop ds
                                  pop es
                                  popa
                                  retn
                     copy_virtual endp

                    change_colors proc near
                                  pusha
                                  mov dx,03c8h
                                  mov al,1
                                  out dx,al              ; color 1 first
                                  inc dx
                                  mov di,63              ; highest
                                  xor si,si
                                  mov cx,254             ; 254 colors
all_colors:                       add si,24              ; using
                                  cmp si,99              ; fix point
                                  jbe color_part         ; arithmetics
                                  dec di                 ; c=c+0.24
                                  sub si,99
color_part:                       mov ax,di
                                  out dx,al
                                  xor al,al
                                  out dx,al
                                  mov al,12
                                  out dx,al
                                  loop all_colors        ; I hope you
                                  popa                   ; understand
                                  retn
                    change_colors endp

memory_error:                     mov ah,09h
                                  mov dx,offset error
                                  int 21h                ; Error message
                                  mov ah,4Ch
                                  int 21h                ; bye bye

start:                            mov dx,@data
                                  mov ds,dx              ; init ds
                                  mov ah,4Ah
                                  mov bx,4000
                                  int 21h                ; change memory size
                                  jc memory_error        ; Error ..
                                  mov ah,48h             ; lame machine !
                                  mov bx,4000
                                  int 21h                ; get memory
                                  jc memory_error        ; „h .. lame !
                                  mov virtual,ax         ; save VIRTUAL Seg.
                                  mov es,ax              ; es to V-Seg
                                  cld                    ; clear direction
                                  mov al,2
                                  out 21h,al             ; bye int 09h
                                  mov ax,13h             ; flag ...
                                  int 10h                ; initialize mode
                                  call change_colors     ; ups ?!?!
                                  xor bp,bp              ; internal pointer
over_and_over:                    add bp,2               ; speed of moving
                                  cmp bp,360             ; ( 2 steps )
                                  jb it_is_okay
                                  sub bp,360             ; table size
it_is_okay:                       call clear_virtual     ; no idea ?!?!
                                  mov cx,1600            ; many bytes eh ?
for_cx_to_do:                     mov bx,cx
                                  shl bx,1               ; *2
                                  add bx,offset abstand  ; abstand + counter
                                  mov dx,[bx]            ; entry ?
                                  add dx,bp              ; entry + internal
                                  cmp dx,360             ; table size
                                  jb nothing_to_change
                                  sub dx,360
nothing_to_change:                mov di,offset kurve    ; wave itself
                                  shl dx,1               ; *2
                                  add di,dx
                                  mov dx,ds:[di]         ; new height
                                  imul si,cx,6           ; si=cx*6
                                  add si,offset wave     ; great 386's hehe
                                  call block             ; and show it ...
                                  dec cx                 ; table of 40x40
                                  cmp cx,0
                                  ja for_cx_to_do        ; do it ...
                                  call retrace           ; for same speed
                                  call copy_virtual      ; show the wave
                                  in al,60h
                                  cmp al,1               ; ask keyb. port
                                  jne over_and_over      ; ESC ?!?
                                  mov al,0               ; welcome back
                                  out 21h,al             ; int 09h
                                  mov ax,03h             ; textmode 80x25
                                  int 10h                ; color
                                  mov ah,49h
                                  int 21h                ; free memory
                                  jc memory_error
                                  mov ah,09h
                                  mov dx,offset copyrights
                                  int 21h
                                  mov ah,4Ch
                                  int 21h                ; and bye ...
end start

;                                                  bye GEORGE STARK/YAKUZA