DOREDRAW()
LABEL L100
EV=WAITEVENT()
IF EV EQ 1 THEN
 DOREDRAW()
ELSE
 IF EV EQ 2 THEN
  GETKEY()
 ELSE
  IF EV EQ 3 THEN
   IF GETBUTT() EQ 1 THEN
    HALT
   ENDIF
  ENDIF
 ENDIF
ENDIF    
GOTO L100
END

FUNCTION WINDOWREDRAW(1)
ASMBEGIN
 mov eax,12
 mov ebx,[ebp+4]
 int 0x40
ASMEND
END

FUNCTION MAKEWINDOW(5)
ASMBEGIN
 mov eax,0
 mov ebx,[ebp+20]
 mov ecx,[ebp+16]
 mov edx,[ebp+12]
 mov esi,[ebp+8]
 mov edi,[ebp+4]
 int 0x40
ASMEND
END

FUNCTION DOREDRAW(0)
 WINDOWREDRAW(1)
 MAKEWINDOW(MKDWORD(100,150),MKDWORD(100,100),BODYCOLOR(RGB(128,128,128)),GRABCOLOR(RGB(64,64,46)),RGB(128,0,0))
 PUTSTR(4,4,0x800000,"MBASIC TEST")
 WINDOWREDRAW(2)
END

FUNCTION MKDWORD(2)
ASMBEGIN
 mov eax,dword [ebp+4]
 shl eax,16
 or ax,word [ebp+8]
ASMEND
END

FUNCTION RGB(3)
ASMBEGIN
 xor eax,eax
 mov al,byte [ebp+12]
 shl eax,8
 or al,byte [ebp+8]
 shl eax,8
 or al,byte [ebp+4]
ASMEND
END

FUNCTION BODYCOLOR(1)
ASMBEGIN
 mov eax,dword [ebp+4]
 or eax,0x03000000
ASMEND
END

FUNCTION GRABCOLOR(1)
ASMBEGIN
 mov eax,dword [ebp+4]
 or eax,0x80000000
ASMEND
END

FUNCTION WAITEVENT(0)
ASMBEGIN
 mov eax,10
 int 0x40
ASMEND
END

FUNCTION GETKEY(0)
ASMBEGIN
 mov eax,2
 int 0x40
ASMEND
END

FUNCTION GETBUTT(0)
ASMBEGIN
 mov eax,17
 int 0x40
 and eax,0x0000FF00
 shr eax,8 
ASMEND
END

FUNCTION PTRVALUE(1)
ASMBEGIN
 mov eax,dword [ebp+4]
 mov al,byte [eax]
 and eax,0x000000FF
ASMEND
END

FUNCTION STRLEN(1)
 SLEN=0
LABEL LSTR1
 RR=PTRVALUE($1)
 IF RR NE 0 THEN
  SLEN=SLEN+1
  $1=$1+1
  GOTO LSTR1
 ENDIF
 $0=SLEN
END

FUNCTION PUTSTR(4)
 XY=($1*65536)+$2
 SL=STRLEN($4)
 ASMBEGIN
  mov eax,4
  mov ebx,dword [XY]
  mov ecx,dword [ebp+8]
  mov edx,dword [ebp+12]
  mov esi,dword [SL]
  int 0x40
 ASMEND
END

ENDS
