ideal
model tiny
JUMPS
P386N

QWERTY1 equ 15;15
QWERTY2 equ 127;127
QWERTY3 equ 53;53
QWERTY4 equ 13;13
QWERTY5 equ 10;10



codeseg
startupcode

          mov  ax,0013h
          int  10h

          mov  cx,000FFh
tpaleta:  mov  dx,003C8h
          mov  al,cl
          out  dx,al
          inc  dx
          mov  al,ch
          out  dx,al
          mov  al,cl
          shr  al,2
          out  dx,al
          mov  al,ch
          out  dx,al
          loop tpaleta

          mov  di,offset TSINT
          mov  cx,QWERTY3+QWERTY4
          mov  bx,07E00h
          mov  ax,QWERTY2*256+QWERTY1
tvekt:    push cx
          push ax
          mov  dx,ax
          imul bh
          mov  bp,ax
          mov  al,dh
          imul bl
          add  ax,bp
          mov  cl,ah
          mov  al,dl
          imul bl
          mov  bp,ax
          mov  al,dh
          imul bh
          sub  ax,bp
          mov  bh,ah
          mov  bl,cl
          shl  bl,1
          shl  bh,1
          mov  ax,bx
          stosb
          pop  ax
          pop  cx
          loop tvekt

tznaky:   mov  ax,01130h
          mov  bh,2
          int  10h
          mov  ax,es
          push ax
          mov  es,ax
          mov  si,bp
          add  si,('!'+1)*14
          xor  bx,bx



typex:

          mov  di,320*200
typexcls: mov  [byte di+offset TOBR],0
          dec  di
          jnz  typexcls

          mov  cx,14
          sub  si,cx
          mov  ah,01h
          int  16h
          jz   typexdal

          xor  ah,ah
	  int  16h
	  cmp  al,27
	  jnz  typexklv

          mov  ax,0003h
          int  10h

          exitcode

typexklv: mul  cl
          add  ax,bp
          mov  si,ax

typexdal: mov  al,[es:si]
          inc  si
          mov  [TZNAK],al
          mov  dx,14
          sub  dx,cx
          mov  ax,QWERTY5*320
          mul  dx
          mov  di,ax
          mov  al,080h
          add  di,160+40*320+offset TOBR
          and  [byte offset typexrot+1],11110111b
          test [byte bx+offset TSINT+QWERTY4],80h
          jnz  typexq23
          sub  al,[bx+offset TSINT+QWERTY4]
          inc  ch
         movsx dx,[byte bx+offset TSINT]
          add  di,dx
          or   [byte offset typexrot+1],00001000b

typexq23:movsx dx,[byte bx+offset TSINT-QWERTY4]
          test [byte bx+offset TSINT],80h
          jnz  typexq34
          xor  ch,01h
         movsx dx,[byte bx+offset TSINT+QWERTY4]
typexq34: sar  dx,4
          add  di,dx
          mov  [byte offset typexk3],47h
          ror  ch,1
          jc   typex1
          mov  [byte offset typexk3],4Fh

typex1:   mov  ch,8

typex2:   mov  ah,32
typexrot: rol  [TZNAK],1
          rcl  [TBOD],1

typex3:   add  dh,[bx+offset TSINT+QWERTY4]
          jno  typex4
          inc  al

typex4:   add  dl,[bx+offset TSINT]
          jno  typex5
          call typexkrs
typex5:   dec  ah
          jnz  typex3

          push di
          push dx

          push ax
          sub  al,20
          call typexkrs
          pop  ax

          push ax
          mov  ah,32

typex6:   add  dh,[bx+offset TSINT]
          jno  typex7
          dec  al
typex7:   add  dl,[bx+offset TSINT+QWERTY4]
          jno  typex8
          call typexkrs
typex8:   dec  ah
          jnz  typex6

          pop  ax
          pop  dx
          pop  di

          dec  ch
          jnz  typex2
          loop typexdal

          inc  bx
          cmp  bl,QWERTY3
          jnz  typex9
          xor  bl,bl

typex9:   mov  dx,003DAh
tretrace: in   al,dx
          and  al,08h
          jz   tretrace
          mov  ax,0A000h
          mov  es,ax
          push si
          mov  cx,320*200
          mov  si,offset TOBR
          xor  di,di
          rep  movsb
          pop  si
tretrac2: in   al,dx
          and  al,08h
          jz   tretrac2
          pop  ax
          push ax
          mov  es,ax

          jmp  typex


typexkrs: push cx
          push di
          mov  cx,QWERTY5
typexk1:  test [cs:TBOD],01h
          jz   typexk2
          mov  [di],al
typexk2:  add  di,320
          loop typexk1
          pop  di
          pop  cx
typexk3:  inc  di
typexkk:  ret

TOBR      db   320*200 dup (?)
TZNAK     db   ?
TBOD      db   ?
TSINT     db   QWERTY3+QWERTY4 dup (?)
end