Wednesday, January 06, 2016

Tiny BASIC part 3 - Adding GRAPHICWIN statement


We are going to add GRAPHICWIN and PSET statements to Tiny BASIC.

Let's start with the really easy one.  We will add a  case "graphicwin"  block to the end of the select case blocks that we examined in the last post.  Here is what it looks like.  The new code is in bold red.
 CASE "let"
  GOSUB [GetLabel]
  IF E$<>"" THEN [Ready]
 CASE "graphicwin"
  IF GWINOPEN = 1 THEN
    PRINT "Graphics window is already open."
  ELSE
    GWINOPEN = 1
    OPEN "Graphics" FOR graphics AS #GWIN
  END IF
  GOTO [FinishStatement]

 END SELECT
So when you run Tiny BASIC and type the command graphicwin and press Enter it will open a small graphics window.  When it does this it also sets the GWINOPEN flag to 1 to that we can check it if the program tries to open another graphics window.  Only one graphics window will be allowed at a time.

The other thing that we want to do it close the graphics window and reset GWINOPEN to 0 if the program is started using the RUN statement.

So, we need to add the following code into the  case "run"  block.  Here is how that code should look.  The new code is in bold red.

 CASE "run"
  IF GWINOPEN = 1 THEN
    CLOSE #GWIN
    GWINOPEN = 0
  END IF

  FOR I=27 TO 52 : A(I)=0 : NEXT I
  L=27 : C=1
  GOTO [FinishStatement2]
So now the program will always start off in a clean state each time it is run!

In our next post we will figure out how to add a PSET statement so we can draw some graphics!


No comments: