.model tiny
.code
.386
org 100h

start:  mov     ah,2
        xor     dx,dx
        xor     bx,bx
        int     10h                     ; Video display   ah=functn 02h
                                        ;  set cursor location in dx
        mov     ax,0A20h
        mov     cx,7D0h
        int     10h                     ; Video display   ah=functn 0Ah
                                        ;  set char al at present curs
                                        ;   cx=# of chars to replicate
loc_1:  mov     ax,701h
        mov     bh,22h                  ; '"'
        xor     cx,cx
        mov     dx,194Fh
        int     10h                     ; Video display   ah=functn 07h
                                        ;  scroll down, al=lines
                                        ;   bh=attrib, cx+dx=window size
        mov     ah,2
        mov     dx,data_1
        xor     bh,bh
        int     10h                     ; Video display   ah=functn 02h
                                        ;  set cursor location in dx
        mov     ah,8
        int     10h                     ; Video display   ah=functn 08h
                                        ;  get char al & attrib ah @curs
        cmp     al,20h                  ; ' '
        jne     loc_10
        mov     ax,901h
        mov     bl,31h                  ; '1'
        mov     cx,1
        int     10h                     ; Video display   ah=functn 09h
                                        ;  set char al & attrib bl @curs
                                        ;   cx=# of chars to replicate
        dec     data_3
        xor     ah,ah
        cmp     ah,data_3
        jne     loc_3

loc_2:  int     1Ah                     ; Real time clock   ah=func 00h
                                        ;  get system timer count cx,dx
        and     dl,0Fh
        jz      loc_2
        mov     data_3,dl
        and     dl,7
        mov     data_2,dl

loc_3:  mov     al,data_2
        mov     ah,data_4
        xor     dx,dx
        cmp     ah,5
        jg      loc_4
        and     al,3

loc_4:  cmp     ah,2Dh                  ; '-'
        jl      loc_5
        or      al,4

loc_5:  cmp     al,4
        jl      loc_6
        sub     al,4
        neg     al

loc_6:  add     ah,al
        mov     data_4,ah
        mov     data_2,al
        mov     ah,2
        add     dl,data_4
        mov     bx,71h
        int     10h                     ; Video display   ah=functn 02h
                                        ;  set cursor location in dx
        mov     ax,94Fh
        mov     cx,21h
        int     10h                     ; Video display   ah=functn 09h
                                        ;  set char al & attrib bl @curs
                                        ;   cx=# of chars to replicate
        mov     ah,2
        add     dl,4
        int     10h                     ; Video display   ah=functn 02h
                                        ;  set cursor location in dx
        mov     ax,920h
        mov     cx,19h
        int     10h                     ; Video display   ah=functn 09h
                                        ;  set char al & attrib bl @curs
                                        ;   cx=# of chars to replicate
        mov     ecx,data_5
        sub     ecx,100h
        mov     data_5,ecx
        mov     edx,ecx
        shr     ecx,10h
        mov     ah,86h
        int     15h                     ; General services, ah=func 86h
                                        ;  wait cx:dx microseconds
        mov     ah,1
        int     16h                     ; Keyboard i/o  ah=function 01h
                                        ;  get status, if zf=0  al=char
        mov     dx,data_1
        jnz     loc_7
        jmp     loc_1

loc_7:  mov     ah,0
        int     16h                     ; Keyboard i/o  ah=function 00h
                                        ;  get keybd char in al, ah=scan
        cmp     al,1Bh
        je      loc_11
        cmp     al,34h                  ; '4'
        je      loc_9
        cmp     al,36h                  ; '6'
        je      loc_8
        jmp     loc_1

loc_8:  add     dl,4

loc_9:  sub     dl,2
        mov     data_1,dx
        jmp     loc_1

loc_10: mov     ax,92Ah
        mov     bl,40h                  ; '@'
        mov     cx,1
        int     10h                     ; Video display   ah=functn 09h
                                        ;  set char al & attrib bl @curs
                                        ;   cx=# of chars to replicate
loc_11: ret

data_1  dw      1418h
data_2  db      0
data_3  db      10
data_4  db      20
data_5  dd      30000h

end     start
