LOOKUP HRFORTH  ( HGR page 1 reserved )
LOOKUP HR2FORTH ( HGR page 1 and 2 reserved )
OR NOT ?ABORT" Must run with HRFORTH."

SRC" PLASMA.4TH"
SRC" CONIO.4TH"
SRC" HGRLIB.4TH"

 5 VARIABLE BALLCLR
10 VARIABLE BALLX
20 VARIABLE BALLY
10 VARIABLE OLDX
20 VARIABLE OLDY
 1 VARIABLE INCX
 1 VARIABLE INCY

: BEEP 30 10 TONE ;

: BOOP 10 30 TONE ;

: MOVEBALL
  BALLX @ 0=    IF INCX @ NEGATE INCX ! BEEP THEN
  BALLX @ 279 = IF INCX @ NEGATE INCX ! BEEP THEN
  BALLY @ 0=    IF INCY @ NEGATE INCY ! BOOP THEN
  BALLY @ 191 = IF INCY @ NEGATE INCY ! BOOP THEN
  INCX @ BALLX +!
  INCY @ BALLY +!
  BALLX @ BALLY @ HGRXORPLOT
  OLDX @ OLDY @ HGRXORPLOT
  BALLX @ OLDX !
  BALLY @ OLDY !
;

0 VARIABLE TOP
0 VARIABLE BOTTOM
0 VARIABLE LEFT
0 VARIABLE RIGHT
: RECT ( left top right bottom -- )
  BOTTOM !
  RIGHT !
  TOP !
  LEFT !
  LEFT  @ TOP    @ RIGHT @ TOP    @ HGRLINE
  LEFT  @ BOTTOM @ RIGHT @ BOTTOM @ HGRLINE
  LEFT  @ TOP    @ LEFT  @ BOTTOM @ HGRLINE
  RIGHT @ TOP    @ RIGHT @ BOTTOM @ HGRLINE
;  

: BOUNCE
  0 HGRMODE    DROP
  0 HGRDRAWBUF DROP
  0 TILEDRAWBUF DROP
  0 HGRSHOW    DROP
  10 12 " Hello from PLFORTH!" HGRPUTSTR
  1 HGRCOLOR
  61 90 209 107 RECT
  BALLCLR @ HGRCOLOR
  BEGIN
    MOVEBALL
    KEY?
  UNTIL
  KEY DROP
  -1 HGRMODE DROP
;

BOUNCE
