CLEAR ALL
BACKGROUND RGB(32,32,32)
TILEMAP 1 NEW 80,50
SPRITE 1 BIND TILEMAP 1 SHOW FIT
TARGET TILEMAP 1
w=TILEMAP.COLUMNS(1):h=TILEMAP.ROWS(1)
r=0
DO
    DO
        x1=RANGE(0,w-1)
        x2=RANGE(0,w-1)
    LOOP WHILE ABS(x2-x1)<5
    DO
        y1=RANGE(0,h-1)
        y2=RANGE(0,h-1)
    LOOP WHILE ABS(y2-y1)<5
    HIGHLIGHT RND.COLOR
    DrawBox(x1,y1,x2,y2,r)
    PAUSE
    a$=INKEY$
    IF a$=" " THEN r=1-r:a$=""
LOOP WHILE a$=""
END
FUNCTION DrawBox(x1,y1,x2,y2,r)
    SORT x1,x2
    SORT y1,y2
    IF r=0 THEN
        PUT TILE x1,y1,112
        PUT TILE x2,y1,110
        PUT TILE x1,y2,109
        PUT TILE x2,y2,125
    ELSE
        PUT TILE x1,y1,85
        PUT TILE x2,y1,73
        PUT TILE x1,y2,74
        PUT TILE x2,y2,75
    END IF
    PUT HLINE x1+1,x2-1,y1,64
    PUT HLINE x1+1,x2-1,y2,64
    PUT VLINE x1,y1+1,y2-1,93
    PUT VLINE x2,y1+1,y2-1,93
    PUT RECT FILL x1+1,y1+1,x2-1,y2-1,32
END FUNCTION
