; stereo.asm by Michael Kohn
; Started: April 27, 1995

.model small

.data
sdepth db 16 
LocX dw 0
LocY dw 0
color db 6,4,1,3,4,5,13,1,50 dup(0) 
depth db 0
DEnd dw 0

CTable db 0,4,43,12,61,21,11,1,3,2,16,60,56,44,9,2,0

.stack 256

.code

cut proc
  push di
again2:
  mov al, [di]+1
  mov [di], al 
  inc di
  cmp di, DEnd
  jc again2
  pop di
  dec DEnd
  ret
cut endp

inert proc
  inc DEnd
  mov si, DEnd 
ForA:
  mov al, [si]-1
  mov [si], al
  dec si
  cmp si, di
  jnz ForA
  mov al, 0
  out 43h, al
  in al, 40h
  and al, 15
  mov [di], al
  in al, 40h 
  ret
inert endp

random proc
  mov al, 0 
  out 43h, al
  in al, 40h      ; picks a 1 byte number out of the system timer
  lea si, start
  mov ah, 0
  add si, ax      ; si = start + Timer 0 LSB = random numbers :)
  in al, 40h
  ret
random endp

start:
  mov ax, @data 
  mov ds, ax

  mov ah, 0
  mov al, 10h
  int 10h

  push ds
  pop es

  mov ah, 10h
  mov al, 2
  lea dx, CTable
  int 10h

  mov LocY, 0             ;  For Y = 0 to 349 
ForY:
  mov cl, sdepth           ;  For Z = depth+1 to 1 step -1
  mov depth, cl 
  inc cl
  lea di, color 
  call random
  mov ax, 0
  mov es, ax 
ForZ:
  mov al, es:[si] ; make a pattern and put in color array
  mov [di], al
  inc di
  inc si
  dec cl
  jnz ForZ                ; next Z
  mov LocX, 0             ; For X = 0 to 639 
  lea di, color 
  mov DEnd, di
  mov cl, sdepth
  mov ch, 0
  inc cl
  add DEnd, cx 
ForX:
  mov bh, 0
  mov cx, LocX
  mov dx, LocY
  mov al, [di]
  mov ah, 0ch
  int 10h
  inc di                  ; next color
  cmp di, DEnd            ; if di <> depth+1 then goto skip1
  jc skip1
  lea di, color           ; di = 0
skip1:
  cmp LocY, 125
  jc skip3
  cmp LocY, 225
  jnc skip3
  cmp LocX, 280
  jnz skip5
  call cut
skip5:
  cmp LocX, 400
  jnz skip6
  call inert
skip6:
  cmp LocX, 310
  jne skip7
  call cut
skip7:
  cmp LocX, 370
  jne skip8
  call inert
skip8:
  cmp LocX, 250 
  jne skip9
  call cut 
  call cut
skip9:
  cmp LocX, 430
  jne skip3
  call inert
  call inert
skip3: 
  inc word ptr LocX       ; next X
  cmp word ptr LocX, 640
  jnz ForX
  inc word ptr LocY       ; next Y
  cmp word ptr LocY, 350
  jz skip4
  jmp ForY

skip4:
  mov ah, 8
  int 21h

  mov ah, 0
  mov al, 3
  int 10h

  mov ax, 4c00h
  int 21h
end start



