ideal
model tiny
P386N

codeseg

startupcode
start:    mov  ah,02h
	  int  1Ah
	  mov  [offset random+1],dx

	  mov  di,offset OBRAZ
	  mov  ax,07DBh
	  mov  cx,77
	  rep  stosw
	  mov  al,'0'
	  stosw
	  inc  al
	  stosw
	  mov  dl,23
start1:   mov  ax,07DBh
	  stosw
	  stosw
	  mov  ax,0500h
	  mov  cx,78
	  rep  stosw
	  dec  dl
	  jnz  start1
	  mov  ax,07DBh          
	  mov  cx,81
	  rep  stosw

	  mov  [word offset OBRAZ+80*22*2+40*2],0001h

	  mov  cx,200
start2:   call nah_poz
	  stosw
	  loop start2

	  mov  ax,022Ah
	  mov  cx,150
start3:   call nah_poz
	  stosw
	  loop start3





cervoxo:  mov  ax,0B800h
	  mov  es,ax
	  xor  di,di
	  mov  si,offset OBRAZ
	  mov  cx,80*25

cervoxo1: lodsw
	  or   ah,ah
	  jnz  cervoxo2
	  mov  ax,0640h
cervoxo2: stosw
	  loop cervoxo1





cervoxp:  call pauzinit
cervoxp1: mov  ax,0001h
cervoxp2: mov  bx,100
	  sub  bl,[DLZ]
cervoxp3: mov  cx,0800h
cervoxp4: loop cervoxp4
          dec  bx
          jnz  cervoxp3
	  dec  ax
	  jnz  cervoxp2


cervoxk:  mov  ah,01h
	  int  16h
	  jz   cervoxd
	  xor  ah,ah
	  int  16h
	  cmp  al,27
	  jz   cervoxe1
	  or   al,al
	  jnz  cervoxd
	  mov  al,1
	  cmp  ah,72 
	  jz   cervoxk2
	  inc  al
	  cmp  ah,80
	  jz   cervoxk2
	  inc  al
	  cmp  ah,75
	  jz   cervoxk2
	  cmp  ah,77
	  jnz  cervoxd
	  inc  al
cervoxk2: mov  [SMER],al




cervoxd:  mov  si,offset OBRAZ
	  mov  cx,80*25+1
cervoxd1: dec  cx
	  jz   cervoxd3
	  lodsw
	  or   ah,ah
	  jnz  cervoxd1
	  inc  [byte si-2]
	  cmp  al,1
	  jnz  cervoxd2
	  mov  bx,si
cervoxd2: cmp  al,[DLZ]
	  jc   cervoxd1
	  mov  [word si-2],0500h
	  jmp  cervoxd1

cervoxd3: mov  si,bx
	  mov  al,[SMER]
	  sub  bx,160+2
	  dec  al
	  jz   cervoxd4
	  add  bx,160*2
	  dec  al
	  jz   cervoxd4
	  sub  bx,162
	  dec  al
	  jz   cervoxd4
	  add  bx,4
cervoxd4: mov  ax,[bx]
	  cmp  ah,07h
	  jz   cervoxdx
	  or   ah,ah
	  jz   cervoxdx
	  cmp  ah,02h
	  mov  [word bx],0001h
	  jnz  cervoxo

	  call nah_poz
	  stosw
	  inc  [DLZ]
	  mov  si,offset OBRAZ+78*2
          inc  [byte si]
	  cmp  [byte si],58
	  jnz  cervoxo
	  mov  [byte si],'0'
	  inc  [byte si-2]
	  jmp  cervoxo

cervoxdx: sub  si,offset OBRAZ
	  mov  [word es:si-2],0421h






cervoxex: xor  ah,ah
	  int  16h
cervoxe1: exitcode





pauzinit: mov  di,2*2
	  mov  si,offset TEXT
	  mov  cx,74
	  mov  ah,75h
pi1:      lodsb
	  add  al,64
	  stosw
	  loop pi1

	  mov  ah,02h
	  int  1Ah
	  mov  bx,dx
pi2:      mov  ah,02h
	  int  1Ah
	  cmp  dh,bh
	  jz   pi2
	  mov  bh,dh

pi3:      mov  bl,20
pi4:      mov  ah,02h
	  int  1Ah
          dec  bl
          jnz  pi4
	  add  [word offset cervoxp1+1],1
	  cmp  dh,bh
	  jz   pi3
	  mov  [byte offset cervoxp],90h
	  mov  [word offset cervoxp+1],9090h
	  ret



nah_poz:  push ax
nah_poz1: call random
	  cmp  dx,80*25
	  jnc  nah_poz1
	  rol  dx,1
	  mov  di,dx
	  add  di,offset OBRAZ
	  cmp  [byte di+1],05h
	  jnz  nah_poz1
	  pop  ax
	  ret

random:   mov  bx,0
	  mov  dh,bl
	  mov  dl,253
	  mov  al,bh
	  sub  dx,bx
	  sbb  al,0
	  sbb  dx,bx
	  sbb  al,0
	  mov  bl,al
	  mov  bh,0
	  sbb  dx,bx
	  jnc  random1
	  inc  dx
random1:  mov  [offset random+1],dx
	  ret






dataseg

DLZ       db 1 
SMER      db 1 
TEXT      db 'C'-64,'E'-64,'R'-64,'V'-64,'O'-64,'X'-64,'-'-64,'f'-64
	  db 'r'-64,'e'-64,'e'-64,'w'-64,'a'-64,'r'-64,'e'-64,' '-64,'b'-64,'y'-64,' '-64
	  db 'P'-64,'i'-64,'c'-64,'a'-64,'s'-64,'s'-64,'o'-64,' '-64,'P'-64,'a'-64
	  db 'b'-64,'l'-64,'o'-64,','-64,' '-64,'A'-64,'t'-64,'r'-64,'i'-64,'p'-64,' '-64
	  db 's'-64,'o'-64,'f'-64,'t'-64,'w'-64,'a'-64,'r'-64,'e'-64,' '-64,'S'-64
	  db 'l'-64,'o'-64,'v'-64,'a'-64,'k'-64,'i'-64,'a'-64,' '-64,' '-64,'p'-64,'i'-64
	  db 'c'-64,'a'-64,'s'-64,'s'-64,'o'-64,'@'-64,'p'-64,'o'-64,'s'-64,'t'-64
          db '.'-64,'s'-64,'k'-64
OBRAZ     db 80*25*2 dup(?)

	  
end
