;BALL.ASM - Ball bounces round the screen.
; Jonathan Gilbert

.Model Tiny
.Code
.286
.Radix 16
Org 100h
Start:  Mov   Ax,0B800h
        Mov   Ds,Ax
        Mov   Cx,0
        Mov   Ax,200Fh
Lminus1:
        Mov   Di,Cx
        Shl   Di,1
        Mov   [DI],Ah
        Inc   Di
        Mov   [DI],Al
        Inc   Cx
        Cmp   Cx,7D1h
        Jl Lminus1
        Mov   Ax,280Ch
        Mov   Bx,0101h
L0:
        Cmp   Bh,01
        Jz    L1
        Sub   Ah,01
        Jmp   short L2
L1:
        Add   Ah,01
L2:
        Cmp   Bl,01
        Jz    L3
        Sub   Al,01
        Jmp   short L4
L3:
        Add   Al,01
L4:
        Xor   Cx,Cx     ;random number routine?
        Mov   Cl,Al
        Shl   Cx,6
        Mov   Di,Cx
        Shl   Cx,2
        Add   Di,Cx
        Shr   Di,1
        Xor   Cx,Cx
        Mov   Cl,Ah
        Shl   Cx,1
        Add   Di,Cx
        Mov   Dl,0FEh
        Mov   [DI],Dl
        Mov   Cx,07FFFh  ;sets delay "time"
L5:
        Sub   Cx,01     ;delay loop
        Cmp   Cx,00
        Jg    L5
        Mov   Cx,02FFFh  ;sets delay "time"
L5point1:
        Sub   Cx,01     ;delay loop
        Cmp   Cx,00
        Jg    L5point1
        Mov   Dl,20h  ;ball erase
        Mov   [DI],Dl
        Cmp   Ah,00
        Jg    L6
        Mov   Bh,01
L6:
        Cmp   Ah,50h    ;ok
        Jl    L7
        Mov   Bh,00
L7:
        Cmp   Al,00
        Jg    L8
        Mov   Bl,01
L8:
        Cmp   Al,18h    ;ok
        Jl    L9
        Mov   Bl,00
L9:
        Mov   Cl,Al
        In    Al,60h    ;keyboard AT & PS2
        Cmp   Al,01     ;program only exits when ESC is pressed
        Jz    Retx
        Mov   Al,Cl
        Jmp   L0
Retx:   Ret
End Start
