Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self...

167
Written by Jon Silvera & Colin Bodley FUZE BASIC Programmer’s Reference Guide

Transcript of Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self...

Page 1: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

Written by Jon Silvera& Colin Bodley

FUZE BASICProgrammer’s

Reference Guide

Page 2: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

2

FUZE BASIC

Programmer’sReference Guide

Introduction ....................................................................... 3

Commands ....................................................................... 5 1

Procedures & Functions...................................................58

Built-in Variables and Constants ....................................154

Keycodes (scanKeyboard)…………....................................165

Notes & Octaves for Sound command.....................…....166

For new commands, features and projects visit;

fuze.co.uk & lair.fuze.co.uk

For example look up; FULLSCREEN, ROTATEIMAGE & SCALEIMAGE

Published in the United Kingdom ©2015 FUZE Technologies Ltd. FUZE, FUZE BASIC,logos, designs, documentation and associated materials are Copyright FUZE Technologies Ltd.No part of this document may be copied, reproduced and or distributed without written consent fromFUZE Technologies Ltd. All rights reserved.

With many thanks and a great deal of respect to Gordon Henderson for his work on RTB which is whereFUZE BASIC originated. Mike Green for his vision and commitment to FUZE BASIC development. Additionalthanks to Colin Bodley, the author of this reference guide and major contributor to the FUZE project.Further mentions go to Jon Clough - Finance Director, Shila Odedra-Silvera - Education Director, TraceyClough - Administration, Vicki Pickering - Account Manager & Tutor, Nic Baxter and project inspirersMolly Odedra-Silvera, Gracie Odedra-Silvera, David Ian Silvera and Charlie!

FUZE BASIC is developed by FUZE Technologies Ltd in the UK. The team consists of;

Mike Green - Lead programmer & head of FUZE BASIC developmentColin Bodley - Programmer & documentationLuke Mulcahy - ProgrammerJon Silvera - Project manager

Additional information – www.fuze.co.uk

Manual Version: 3.0 Date: 09/04/2015 FUZE BASIC Version: 3.0

Page 3: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

3

IntroductionFUZE Keyboard .............................................................. 4Computer Programs...................................................... 4Programming Languages............................................... 5BASIC ............................................................................. 5FUZE BASIC .................................................................... 5Immediate Mode .......................................................... 6Computer Memory/Storage.......................................... 7Stored Program Mode................................................... 7Run Mode...................................................................... 8Edit Mode...................................................................... 9Variables...................................................................... 11Booleans...................................................................... 13Conditionals ................................................................ 13Input/Output............................................................... 15Loops ........................................................................... 17Procedures and Functions........................................... 19Graphics ...................................................................... 20Comments ................................................................... 24ASCII ............................................................................ 24Text ............................................................................. 25Bits and Bytes.............................................................. 28Arrays .......................................................................... 29Data, Read and Restore............................................... 32

Files ............................................................................. 33Sprites ......................................................................... 36User Defined Procedures & Functions ........................ 39Numerical Functions ................................................... 42Turtle Graphics............................................................ 43GPIO ............................................................................ 44Robot Arm................................................................... 45Music........................................................................... 46Sound Effects .............................................................. 47Synthesized Music....................................................... 49Immediate Mode Commands ..................................... 50

Page 4: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

4

FUZE KeyboardMost keys on the keyboard are self explanatory. I havemarked a few of the special keys in case you are unsurewhat they are:

The following chapter is an introduction to programmingin FUZE BASIC on a FUZE Powered by Raspberry Pi®. I haveincluded background sections on how computers work tohelp with your understanding but if you want to just skipto the programming you can jump forward a few pages.

Computer ProgramsComputer programs are sets of instructions that tell acomputer to carry out a particular task.

The programs are executed (or run) by the computer’sCentral Processing Unit (CPU) .

Computers run programs in a language called machine code.

This consists of a series of numbers which representinstructions that the machine understands and can carry out.

Introduction

Page 5: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

5

In fact, even worse than that, the numbers are represented inthe machine as a series of 1s and 0s in something called binary.So to us a machine code program could look something likethis: 001010101010101111101010101010100101...

Programming LanguagesMachine-code is therefore, difficult for us humans to read andunderstand. This is why we use programming languages to tella computer what to do. Instructions in the programminglanguage are converted into the 1s and 0s that the computeractually understands.

There are many different programming languages in existence.Over the years I have written programs in several: FORTRAN,PASCAL, C, C#, PHP and SQL, but the first language I learned toprogram in was a language called BASIC.

BASICThe BASIC programming language has been around a couple ofyears longer than me (and I was born when England won theWorld Cup!). It stands for Beginner's All- purpose SymbolicInstruction Code. It was designed to be easy to use for peoplewho had not used computers before.

Here at FUZE Technologies Ltd. we believe it is still thebest introduction to computer programming.

BASIC is (usually) known as an interpreted language. Thismeans that each instruction is taken in turn and converted tothe binary code before being executed. Other languages suchas C are called compiled languages because the whole programis converted in one go before being run. Compiled languagesare generally faster than interpreted languages because theinstructions only have to be converted once. The advantage ofan interpreted language is that you can see results morequickly as you are writing the program.

FUZE BASICFUZE BASIC is a modern evolution of the many variations of theclassic BASIC programming language.

Follow the instructions in your Getting Started guide to set upand start yourFUZE computer.Once thecomputer hasfinished ‘booting’you should seethe FUZEdesktop:

Page 6: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

6

Use your mouse to point to the FUZE BASIC icon in the topleft of the screen which looks like this:

Using the left mouse buttonclick twice quickly (this is calleddouble clicking) on the FUZEBASIC icon in the top left tostart FUZE BASIC.

You should now see a FUZE BASIC window:

FUZE BASIC can be configured with a number of differentsettings so you may find the window looks different to theabove but the principle is always the same.

When you see the “Ready” prompt, you are ready to startprogramming!

Immediate ModeYou will notice underneath the banner on the left handside the following:

This is the input cursor and it is telling you that it is ready foryou to enter a command. The command will not be carried outuntil the Enter key is pressed. On the FUZE this key is towardsthe right hand side, to the left of the Page Down key and lookslike this:

This is called immediate or Direct Mode because the commandwill be carried out immediately. Try it now, type somethingand press the Enter key. Unless you were extremely lucky (oryou have done this before!) the chances are that you receivedan error message something like the on the next page:

Page 7: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

7

The syntax of the language describes the commands that canbe executed, so a syntax error is saying that it did not recognisewhat you typed as being a valid command. Try it again but thistime type the following and press the Enter key:

Strings of characters are marked using the speech markcharacter " which is on the same key as 2 on the keyboard andcan be typed by holding down the Shift key and pressing the 2key. There are two Shift keys on the keyboard, one on eitherside, that look like this:

This time you should see Hello World echoed back to you. Thisis because the PRINT command is part of FUZE BASIC and whatit does is to print the text between the speech marks to thescreen.

You have now executed your first FUZE BASIC command butyou are yet to write your first program.

Computer Memory/StorageLike a lot of other computers the FUZE has two different typesof storage for programs (instructions) and data (information).The first is called volatile storage and lasts only as long as thecomputer is switched on. The second is called non-volatileand “remembers” information even when the device isdisconnected from the power. Volatile storage tends to befaster but more expensive and lower capacity than non-volatilealthough the difference is reducing all the time.

In the case of the FUZE the volatile storage is on a microchip onthe circuit board of the Raspberry Pi inside the FUZE case. Thenon-volatile storage is on the SD card inserted in the back ofthe case. Programs are stored on the non-volatile memory andthen loaded into the volatile memory to be executed.

Stored Program ModeIn this mode a sequence of FUZE BASIC commands arestored in the computer’s memory which can then be executedagain and again.

The simplest (and rather old fashioned) way of doing this is toenter a line number before each command to be executed. Thenumber indicates where in the program the line will beinserted. Type the number 10 in front of the print commandthat you enteredearlier:

Page 8: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

8

You will notice that this time nothing is printed on the screen.That is because what you have actually done here is add linenumber 10 to the program currently loaded into thecomputer’s memory. This is initially empty when FUZE BASIC isstarted (or when you enter the NEW command).

Type the LIST command and press the Enter key. The programcurrently loaded into memory will be listed to the screen:

Run ModeYou can execute this program using the RUN command. Try itnow and you will get the following:

The first line of the program is executed and carries out thePRINT command. This prints Hello World to the screen. Theprogram runs until a STOP or END command is reached. Ifthere is no STOP or END command found you will receive anerror like the one above.

Now type the following and press Enter:

This adds another line to the program (line 20) with the ENDcommand. This tells FUZE BASIC that the end of the programhas been reached. Now when you LIST your program you getthis:

And when you RUN it you get this:

Congratulations! You have just written your first (working)FUZE BASIC program. Admittedly it doesn’t do very much butthis is traditionally the first program that everyone writes whenthey are learning a new programming language. Now type thefollowing and press Enter.

This replaces the existing line 20 with a new one that uses theGOTO command. LIST the program again to see the change:

The GOTO command tells the computer to jump to thespecified line of the program (in this case line 10). If you RUNthis program now it will first print Hello World to the screenand then jump back to line 10 which will print Hello World tothe screen again and so on. Try it now and see what happens.

Page 9: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

9

This program will never end as it is stuck in what is called aninfinite loop. Luckily you can stop it from running by pressingthe Esc (Escape) key which is at the top left of the keyboard. Infact you can use this key to stop any FUZE BASIC program fromrunning at any time.

This method of editing a program a line at a time is quite hardwork and difficult because you have to keep listing theprogram to see where to insert new lines. This is how I used tohave to program when I first started. Luckily you don’t have todo this as FUZE BASIC has its own built in full screen editor.

Edit ModeFirst clear the program currently in memory using the Newcommand and pressing Enter. To start the full screen editorand enter edit mode now type the EDIT command and pressEnter. I think that I will stop saying press Enter after everycommand. You should have got the idea by now!

You will now see the editor screen as shown across the page:

The green block in the top left shows the current position ofthe input cursor. The first time you enter the Editor it will nothave any code in there, this is just for example.

Now that we have a full screen editor we don’t need to worryabout line numbers any more. Let’s rewrite the Hello Worldprogram without using them. On the first line of the programtype the command:

You will notice that when you press Enter the command is notexecuted but that the cursor moves down to the line below.Now add the End command to the second line (without a linenumber). Your program should now look like this:

Page 10: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

10

You can run your program from within the editor by pressingthe function key F3. The Function keys are along the top of thekeyboard and numbered from F1 to F12.

These keys usually have different functions depending on theprogram running but normally F1 is used to bring up helpinformation for the current program. Try it now and you willget help pages for the editor:

For now press the Esc key to return to the editor.

Now press the F3 key to run your program. You will notice thatthe cursor has jumped to the bottom of the window and isprompting you to Save As:

Your program is currently only residing in the computer’smemory. If the power were to go off all of your hard workwould be lost forever. The editor is prompting you to save yourprogram to a file on the SD card where it will still be the nexttime you switch on your computer.

Enter a name for your program. You should choose one thatwill remind you what it does. In this case you could call itHelloWorld. When you press Enter the program is saved to afile on the card and the program is run, printing Hello World tothe screen again and then ending.

At this point you can press F2 to return to the editor of Esc toexit the editor and return to immediate mode. Press F2 toreturn to the editor. Now if you press F3 to run your programagain you will not be prompted to save the program as it hasalready been saved. Instead the program will be run again.

Previously we used GOTO 10 to send the program back to thestart. How are we going to do this when we no longer have linenumbers?

We need to create something called a loop. This is a section ofcode that is repeated over and over again, either a set numberof times or until some condition is met. In this case we aregoing to create another infinite loop (one that never finishes)

Page 11: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

11

We first need to add a CYCLE command to the beginning of thesection of code that we want to repeat. Use the cursor keys tomove around the program.

Each arrow key moves the cursorone character in the directionindicated by the arrow. So pressingthe up arrow will move the cursorup one line.

You now need to create a new line above the first line. To dothis you need to Press the Enter key. Edit your program so itlooks like;

The REPEAT command tells the program to jump back to theprevious CYCLE command. There will be much more aboutloops in a later section. Now when you press F3 you will getthe same result as previously using the GOTO command. Asbefore, you will need to press the Esc key to break out of theinfinite loop.

Save your changes by pressing F5. At this point you can justpress Enter to save over the previous version with the samename or you could give it a different name and keep bothversions of the program. Finally press F2 to exit from theeditor and return to immediate mode.

At this point your program is still in memory and can still berun using the RUN command or edited using EDIT. To erase theprogram from memory you can use the NEW command. Try itnow and then type LIST to see that it has gone. In immediatemode you can now load the program back into memory usingLOAD “Hello World” (assuming that is what you called it).

VariablesVariables are used in computer programs to store andretrieve pieces of information in the computer’s memory. Avariable is a friendly name given to a memory location. Youcould think of it like a box with a name on it. You can putsomething in the box and find it again later amongst lots ofother boxes because it is labelled. You can look at what is inthe box or change its contents. Variables are so called becausetheir values can vary as a program is run.

You assign a value to a variable using the LET command. Inimmediate mode, enter the following command to set thevalue of a variable called X to 10:

Now to see the value of the variable X you can use the PRINTcommand as follows:

Page 12: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

12

You can change the value in a variable by assigning it again to adifferent value. Try it now using the LET command again butsetting a different value and using the PRINT command to seethe value.

In fact you can get and set thevalue of a variable in the samecommand. Suppose you want toincrease the value in the variable Xby 1. You first need to get thecurrent value, then add 1 to it andthen set it again to the new value asshown in the example below. The plus operator (+) is typed byholding the shift key and pressing the = key at the same time.You may notice that I left out the LET command on the firstline. This is because the LET command is used so much that it isimplied when a variable starts a command and can be safelyleft out.

Variables should be named after the things that they containso that you can remember what they are for. The variablecalled X does not really tell you very much about what itcontains. For example if you have a variable that you want tostore the current temperature in you would probably call itTemperature or even CurrentTemperature.

Although this requires more typing you will be glad you did itwhen you come back to your program and try to rememberhow it works!

Note: Unlike some versions of BASIC, FUZE BASIC variablenames are case sensitive. This means that upper case (Capital)and lower case letters in the name are significant. This means,for example, that temperature, Temperature andTEMPERATURE are actually three different variables.

You can clear all of the variables currently in memory using theCLEAR command. Try it now and then use the PRINTcommand to show the current value of the variable X. You willget the following response:

This is because the variable no longer exists after the CLEARcommand and cannot be accessed any more.

Variables in FUZE BASIC can be used to store two differentsorts of values: numbers and strings of characters. Numberscan be whole such as 1, 72 and -5 (integers) or fractional suchas 3.1415926 (floating point).

Variable names that contain character strings (called stringvariables) are ended with the dollar sign $ so that they can betold apart from numeric ones. To type the $ character youhold down the Shift key and press the 4.

Page 13: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

13

You can set a string variable in the same way that you do anumeric one using the LET command (or leaving it out!). Asbefore the character string is started and ended with thespeech mark character (") which is Shift and 2 at the sametime.The contents ofstring variables canbe changed in asimilar way tonumeric ones. Forinstance you can addthem together:

In this case the plusoperator (+) joins thetwo strings togetherto make a new longerstring. You will notice that there is no space between Helloand Colin. To do this you would need to add a space either onthe end of Hello or at the beginning of Colin.

A numeric value of 0 is considered to be false and any valueother than 0 is true, so for example 10 would be treated astrue. There are also two built-in variables called TRUE andFALSE which represent these values.

ConditionalsConditional statements allow the program to perform differentactions depending on the value of a particular variable.

BooleansSome programming languages have a special type of variablecalled a Boolean. This is a variable that can only have one oftwo possible values: true and false. These are used byprograms to make decisions about which pieces of code toexecute. Other languages like FUZE BASIC just use a numericvalue to do this job.

The simplest conditional statement is IF...THEN which executesa command only if a particular condition is met.

The command has the following syntax:

IF Condition THEN{ Commands }

ENDIF

A Condition is an expression that evaluates to either true orfalse, for instance the expression 1 + 1 = 2 evaluates totrue (check on the Internet if you don’t believe me).

On the other hand the expression 6 * 9 = 42 evaluates to falsebecause the value on the left of the equals sign (=) does notequate to the value on the right i.e. it is not the same.

Page 14: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

14

Note: Usually in programming languages the asterisk (*)symbol is used to denote multiplication. The more normal x(times) used in mathematics would cause confusion with avariable called x.

The ENDIF command marks the end of the set of commandsthat will be executed if the condition is true.

Enter Edit mode and type the following program:

X=10IF X=10 THEN

PRINT "X IS 10"ENDIFEND

If you then run this program (by pressing F3 – remember thatyou will have to give it a name first so it can be saved on to theSD card) you will get the following result:

However if you change the first line to X=11 say and run theprogram again then nothing will be printed.

Suppose that we want a different action to be carried out if thecondition is false. This is when you would use theIF...THEN...ELSE conditional construct which has the

following syntax:

IF Condition THEN{ Commands }

ELSE{ Commands }

ENDIF

In this case if the condition is true the first set of commands isexecuted and if it is false the second set. So we could changeour program to look like this:

X=11IF X=10 THEN

PRINT "X IS 10"ELSE

PRINT "X IS NOT 10"ENDIFEND

This time when you run theprogram you will get this result:

Page 15: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

15

What if you wanted to test a variable for a number of differentvalues and execute different code in each case? In someversions of BASIC you have to use something called an IF THENELSE ladder as shown in this example:

X=2IF X=1 THEN

PRINT "X IS 1"ELSE

IF X=2 THENPRINT "X IS 2"

ELSEIF X=3 THEN

PRINT "X IS 3"ELSE

PRINT "X IS Something Else"ENDIF

ENDIFENDIFEND

Each IF statement is nested within the ELSE part of the oneabove it. I think that you will agree that this is not easy tounderstand. Without the indentation it would be even worseand with it you can soon end up a long way over to the right ofthe screen as you add more tests. Anyway, luckily for you FUZEBASIC supports another conditional statement called a SWITCHstatement. Using a SWITCH statement the above code can berewritten as follows:

X=2SWITCH (X)

CASE 1PRINT "X IS 1"

ENDCASECASE 2

PRINT "X IS 2"ENDCASECASE 3

PRINT "X IS 3"ENDCASEDEFAULT

PRINT "X IS Something Else"ENDCASE

ENDSWITCHEND

I hope that you agree that this is easier to follow. If the value ofX matches the value following a CASE statement then the codewill be executed up to the next ENDCASE statement. If none ofthe values match and there is a DEFAULT statement then thiscode is executed instead.

Input/OutputInput /Output (or I/O) is the communication between theprogram and a human being or another device. You havealready used the simplest output command PRINT to outputtext to the screen (and therefore to the user).

Page 16: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

16

The simplest Input command is in fact INPUT which takes inputfrom the keyboard (and therefore from the user) and puts itinto a variable. Enter the following program using the editor(remember to type NEW to clear the current program frommemory):

When you run this program (F3) you will bepresented with an enigmatic questionmark (?). This is prompting you to entersomething using your keyboard. What you

type will then be put into the variable called A when the Enterkey is pressed. Because A is a numeric variable (it doesn’t endwith a $ sign) the value should be numeric otherwise a value of0 will be assigned.

Try it now; type a number and press the Enter key. The numberyou type will be echoed back to the screen by the followingPRINT command. If you enter something which is not anumber 0 will be printed.

The question mark doesn’t really tell us what the program isasking us to enter. We can add our own prompt by placing itbetween the INPUT command and the variable as in thisexample:

The text after the INPUT command is first printed to thescreen. In this case the program is asking you to enter yourname. Because the variable is a string one, this time when youpress the Enter key everything that you type will be put intothe string variable called Name$. Then whatever you type willbe printed back to the screen with the word Hello in front of ite.g.

Now we can use conditional statements and input to make ourprograms do different things depending on what the userenters on the keyboard. Consider the following example:

INPUT "Enter Your Name: ", Name$IF Name$ = "Dave" Then

PRINT "I am sorry " + Name$PRINT "I am afraid I can't do that"

ELSEPRINT "No problem " + Name$

ENDIFEND

If you run this and enter Dave you will get this:

Page 17: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

17

Anything else and you will get something like:

Note: Because the equals operator (=) is case sensitive if youwere to type dave without a Capital letter you would also getthe ELSE part of the conditional statement. Only typing Davewith a capital letter will produce the first result.

In this example the variable called Seconds will initially be setto 0. The CYCLE command indicates the start of a loop. Thenthe value of Seconds will be increased by 1. Next the value willbe printed to the screen with the word Seconds in front of it.On the next line WAIT(1) is calling a built in procedure whichtells the program to do nothing for the specified amount oftime (in this case 1 second). Finally the REPEAT command tellsthe program to jump back to the beginning of the loop (CYCLE).Note that no END command is needed as it will never bereached. This program when RUN will count the number ofseconds since the program was started and print it to thescreen. It will do this until the loop is interrupted by pressingthe Esc key.

In practice it is not a good idea to use infinite loops becausethe program will never finish unless the user interrupts it andthat is not very graceful. This brings us to the next type of loopwhich is conditional.

LoopsLoops enable sections of code to be executed more than once.This can be a specified number of times or until a condition ismet. In fact as shown earlier in the manual a loop can be madeto execute forever (or at least until the Esc key is pressed orthe power is switched off!).

There are a number of different ways of doing loops in FUZEBASIC. The best one to use will vary according to what you aretrying to do. The simplest loop you have already seen which isthe one that never ends (infinite):

Seconds=0CYCLE

Seconds = Seconds + 1PRINT Seconds; " Seconds"WAIT(1)

REPEAT

Suppose we want the program to do nothing until the userpresses the space bar, maybe to give them time to read what ison the screen (such as the program’s instructions). We can usea WHILE loop as shown below:

Page 18: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

18

This needs some explaining. In this case WHILE the condition istrue the loop will be executed. The condition is INKEY <> 32.INKEY is another built in variable like TRUE and FALSE.Whereas their values never change, INKEY will always containthe value of the last key pressed. I will cover this in more detaillater but for now take it that the value that the space barreturns is 32. The <> operator means not equal and is theopposite of the equals operator (=) i.e. it will be true if thevalues either side are not the same. So as long as the keypressed is not the space bar the loop will be repeated.

Note: Unlike the INPUT command INKEY does not stop theprogram from running until the Enter key is pressed butinstead carries on.

You will notice that there is no actual code inside of the loop(between the CYCLE and REPEAT) so this loop will execute veryquickly (it has nothing to do). The loop will actually executemany times every second. How can we find out how many? Wecan use a variable to count them. Enter the program below:

PRINT "Press the space bar to continue"Count=0WHILE INKEY <> 32 CYCLE

Count = Count + 1REPEATPRINT CountEND

Run this program and after a few seconds press the space bar.Yes the loop really has been round that number of times!Modern computers are very fast compared to the ones I firstused.

Suppose that we want to execute a loop a specific number oftimes. We could use a WHILE loop with a variable as shownbelow:

Count=0WHILE Count < 10 CYCLE

Count = Count + 1PRINT Count

REPEATEND

This time I have used the < operator to test whether the valueof the variable Count is less than 10. As long as it is, the loopwill execute and increase the value of Count by 1. So thisprogram will count from 1 to 10.

However in FUZE BASIC there is another way to do the samething called a FOR loop as shown below:

FOR Count = 1 TO 10 CYCLEPRINT Count

REPEATEND

Page 19: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

19

The FOR loop sets the value of the variable following it to theinitial value specified. It then executes the commands withinthe loop and repeats increasing the value by 1 each timearound until the value after the TO command is reached.

Both ways are equally valid but the second is easier tounderstand and uses two lines less code to do the same thing.In programming there are often many different ways toachieve the same outcome and there isn’t always a right wayand a wrong way to do something.

There is another part to the FOR loop that lets you change theamount that the variable is increased by each time the loop isrepeated. This is done using the STEP command as follows:

FOR Count = 1 TO 100 STEP 10 CYCLEPRINT Count;" ";

REPEATEND

This will produce the following result:

Note: The semi-colon (;) symbol on the end of the PRINT

command stops the printing of a new line. This means that

everything will be printed across on the same line and not

down the screen in a column.

You will notice that although the last value in the FOR loop was100 this was never printed. When the previous value wasincreased by 10 it went over this value and the loop ended.

The next loop we will look at is a different version of the WHILEloop that we saw earlier. Because the WHILE loop tests thecondition at the top of the loop it is possible that the loop willnever be executed. Suppose that we want to make sure thatthe loop will be executed at least once. To do this we can use aREPEAT UNTIL loop as shown below:

CYCLE{ Commands }

REPEAT UNTIL { Condition }

This will execute the Commands once before testing to seewhether the Condition is true. If it is then the loop will end andthe statement following will be executed. If it is false then theloop will start again from the CYCLE command.

Procedures and functions are built in pieces of code that arenot part of the syntax of the programming language but havebeen written to make your life easier. There is no point in youcontinually having to write your own code to draw a circle inevery program where you need to. Instead you can use thebuilt in procedure (but you don’t have to if you don’t want to!)

Procedures and Functions

Page 20: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

20

The only real difference between a procedure and a function isthat functions give you back a value and procedures don’t(they just carry out an action).

Procedures and functions may or may not have values passedto them (called arguments) which change the way theybehave. FUZE BASIC has a large number of built in proceduresand functions to carry out a number of different tasks such asgraphics and mathematics. It is even possible to write yourown which we will cover in a later section.

GraphicsGraphics are about drawing things on the computer’s screen.You can think of the screen as a grid, like a sheet of graphpaper, where each square is an individual picture elementcalled a pixel. Each pixel has a position on the screen and acolour. The position is given as two numbers which show howfar across thescreen andhow far up thescreen fromthe bottomleft handcorner it is asshown:

In the example shown the black pixel is at position 3 across and4 up or (3, 4) counting from zero.

The position across or horizontal position is usually called the xcoordinate and the position up or vertical position is called they coordinate. So any pixel’s position can be given as (x, y).

The bottom left corner or position (0,0) is also known as theORIGIN. The number of pixels across and down the screen willvary depending on the graphics mode and on how FUZE BASIChas been set up. You can find out how many pixels there areusing two built in variables called GWIDTH and GHEIGHT.GWIDTH gives the number of pixels across and GHEIGHT thenumber of pixels up so that the top right pixel on the screen isat position: (GWIDTH, GHEIGHT).

You can set the screen or window resolution to best suit yourapplication. However it is also sensible to adapt your programto run in the resolution the device is set to. To find out thenumber of pixels you have in the current FUZE BASIC setup youcould use the following program:

PRINT "GWIDTH=";GWIDTHPRINT "GHEIGHT=";GHEIGHTPRINT "PIXELS=";GWIDTH*GHEIGHTEND

Which when run will give you something like this:

Page 21: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

21

So in this case there are over ¾ of a million pixels! You can setthe colour of each individual pixel using the PLOT command.First you need to select a colour for your pixel using theCOLOUR command.

FUZE BASIC has 16 predefined colours as shown:

To set a colour you can either use the number or thepredefined constant so COLOUR=RED and COLOUR=12 are thesame thing. Once you have set the colour, all of the followinggraphic commands will use this colour until you change itagain. The syntax of the plot command is:

PLOT(x,y). So to set the pixel in the middle of the screen youwould use:

PLOT(GWIDTH/2,GHEIGHT/2)

Note: the / symbol is used to denote division, so / 2 meansdivide by 2. The more usual mathematical symbol is ÷ which isnot on your keyboard!

Now select the colour red using COLOUR=RED. Finally plot apixel using the command above. You should just about be ableto see a red pixel in the middle of the screen. You may have tolook hard to see it!

It will obviously take a long time to draw anything on thescreen one pixel at a time even in the low resolution graphicsmode. Luckily there are lots of built in graphics procedures fordrawing different shapes. The simplest of these, LINE draws aline in the current COLOUR between two points on the screen:

LINE(xpos1, ypos1, xpos2, ypos2)

Page 22: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

22

This will draw a straight line between point (xpos1, ypos1) andpoint (xpos2, ypos2). For example to draw a yellow line fromthe bottom left of the screen to the top right you would usethe following program:

CLSCOLOUR=YELLOWLINE(0,0,GWIDTH,GHEIGHT)END

The CLS command simply clears the screen display. Say wewant to draw a box on the screen. As usual there are severalways that we could do this. We could use the LINE procedurethat we have just met:

CLSCOLOUR=LIMELINE(100,100,200,100)LINE(200,100,200,200)LINE(200,200,100,200)LINE(100,200,100,100)END

You will notice that the endpoint of each line is the start pointof the next one. We can use the LINETO procedure to simplifythis as follows:

CLSCOLOUR=LIMELINE(100,100,200,100)LINETO(200,200)LINETO(100,200)LINETO(100,100)END

LINETO always uses the previous point plotted as the startpoint of the next line. In fact we don’t even need to do thisbecause there is built in procedure for drawing rectanglescalled RECT which has the following syntax:

RECT(xpos,ypos,width,height,fill)

In this case the point (xpos, ypos) is the bottom left handcorner of the box and the width and height are the number ofpixels to draw across and down from there. So our program isnow simplified again to:

CLSCOLOUR=LIMERECT(100,100,100,100,FALSE)END

This will draw exactly the same box as before. What do youthink will happen if you change the value of fill from FALSE toTRUE? Try it and see. Did you guess correctly?

Page 23: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

23

There are a couple of other shapes that you can draw easily.Firstly a circle using the CIRCLE procedure:

CIRCLE(centrex,centrey,radius,fill)

Here the point (centrex, centrey) is the middle of the circle andthe radius is the distance of each point in the circle from themiddle (in pixels). Again, if fill is TRUE then the shape will befilled in, otherwise it will just be an outline.

Finally TRIANGLE does exactly what you would expect:

TRIANGLE(x1, y1, x2, y2, x3, y3, fill)

In this case the 3 points (x1, y1), (x2, y2) and (x3, y3) are thepoints of a triangle and fill is whether to fill it or not.

At this point there is one other graphics command that youneed to know about. This is the UPDATE command and itcauses the screen to be refreshed (or redrawn). As we sawearlier there are a lot of pixels on the screen and if we updatedthem after every graphics command it would make theprogram very slow and flickery. So instead the graphicscommands are carried out behind the scenes in memory andthen drawn on the screen when an UPDATE command is used.

Up until this point all of the examples we have done have beenprograms that ended (with an END command) and this iscausing an automatic UPDATE. Consider a non-terminatingprogram like this one :

CLSCOLOUR=AQUACYCLE

CIRCLE(GWIDTH/2, GHEIGHT/2, 100, TRUE)REPEAT

When we RUN this the screen remains blank until we press theEsc key and the program is interrupted. If we now change theprogram to this:

CLSCOLOUR=AQUACYCLE

CIRCLE(GWIDTH/2, GHEIGHT/2, 100, TRUE)UPDATE

REPEAT

The circle appears immediately. In fact we can call as manygraphic procedures as we like and they will only appear whenan UPDATE command is called.

Note: In FUZE BASIC the PRINT command (which prints text tothe screen has been made by default to do an UPDATE as wellwhen a new line is printed).

Page 24: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

24

CommentsComments are bits of text that you add to your program tomake it easier for someone else to understand what it is doingand how it works. They are also for you when you come backto a program that you wrote earlier to remind you of the same!

In FUZE BASIC comments are added using the REM (remark)command at the beginning of a line. You can then typewhatever you like as it will be ignored by the interpreter.

REM This is a comment

You don’t need to comment on every line, but each routine orblock of code should have one. You can also use // to addcomments. This can be added at the end of a command:

PRINT "Hello Word" // This is a comment too

As mentioned before everything is stored in the computer asnumbers. How do we convert from these numbers to letters,numbers and punctuation characters on the output device?The most commonly used system is one called ASCII whichdefines how each number maps to a specific character. This is astandard and as long as you know that a system uses it you willbe able to understand something encoded in it. For example inASCII the number 65 is always treated as the capital letter A.The standard ASCII character set is shown opposite:

ASCII

Page 25: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

25

TextOK we have covered drawing stuff on the screen, now in thissection I will talk about processing text. Text is just the let-ters, numbers and punctuation symbols that you enter withyour keyboard and read off your screen. Computers are quitegood at manipulating it.

You have already seen the two simple commands INPUT toread from the keyboard and PRINT to output to the screen.FUZE BASIC has a number of built in functions for manipu-lating strings of characters (called string functions). The firstone we will look at is the LEN function. This tells you howmany characters (letters, numbers and punctuation – includ-ing spaces) there are in a particular string. So for instance:

PRINT LEN("Hello World!")

This will print 12 (10 letters, 1 punctuation and 1 space).You may ask why would we want to know that? We can obvi-ously count them ourselves easily enough. Suppose howeverthat the string was something that had been entered by theuser using the INPUT command and placed in a variable:

INPUT "What is your name? ",name$

We do not know how many characters the user will type andhow long the string in the variable name$ will be. Again youmay be asking why we would need to know. Suppose wewant to print the person’s name centred on the screen. To dothis we will first need to know how many characters will fitacross the screen. This will depend on how FUZE BASIC hasbeen set up but you can find it out using the TWIDTH built-invariable. So to centre the text you could subtract the lengthof the string from this number, divide it by 2 and then printthis number of spaces before it as follows:

INPUT "What is your name? ",name$PadLength=(TWIDTH – LEN(name$))/2FOR P=1 TO PadLength CYCLE

PRINT " ";REPEATPRINT name$END

As usual there is a simpler (and better) way of doing this

same thing:

INPUT "What is your name? ",name$PadLength=(TWIDTH – LEN(name$))/2PRINT SPACE$(PadLength) + name$

The SPACE$ function returns a string of the specified numberof space characters.

Page 26: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

26

There are 3 string functions provided that let you chop up astring into pieces. These are LEFT$, RIGHT$ and MID$. The firstof these LEFT$ returns the specified number of characters fromthe left hand side of the string. If the number is greater thanthe length of the string then it returns the whole string. Here isan example and the result of running it:

string$="0123456789"FOR C=1 TO LEN(string$) CYCLE

PRINT LEFT$(string$, C)REPEATEND

As you might expect RIGHT$ returns the specified number ofrightmost characters:

string$="0123456789"FOR C=1 TO LEN(string$) CYCLE

PRINT RIGHT$(string$, C)REPEATEND

The final one MID$ has an extra argument which specifies thestart position in the string (starting from zero):

result$ = MID$(string$, start, count)

So this can be used to extract a string from the middle of thestring as shown below:

string$="0123456789"FOR C=1 TO LEN(string$) CYCLE

PRINT MID$(string$, C-1, 1)REPEATEND

Note: We have subtracted one from C here to make sure that itstarts from position 0 which is the start of the string. If the startposition is past the end of the string then you will get an error.Now you may be wondering what the point of all this is soI will give you a ‘Real World’ example. Suppose you want to asksomeone their name and get them to type it into the computerbut that you want to make sure that it is formatted correctly.The user could type all in lower case letters or in CAPITALS.This does not look very good; you would normally print a namewith an initial Capital letter and then lower case. We couldwrite a program to make sure that the name was in thisformat. Here is an example of (one) way that you could do it:

Page 27: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

27

INPUT "What is your name? ",name$newname$=""FOR C=1 TO LEN(name$) CYCLE

char$=MID$(name$, C - 1, 1)IF C = 1 THEN

IF char$ >= "a" AND char$ <= "z" THENchar$ = CHR$(ASC(char$) - 32)

ENDIFELSE

IF char$ >= "A" AND char$ <= "Z" THENchar$ = CHR$(ASC(char$) + 32)

ENDIFENDIFnewname$=newname$+char$

REPEATPRINT "Hello " + newname$END

Now this looks complicated but it really isn’t, I will walk youthrough it. The first line prompts the user to enter their nameand puts it into the string variable name$. The next creates anew empty string variable in which to store our new formattedname.

We then start a loop from 1 to the length of the name that hasbeen entered. The first thing we do in the loop is use the MID$function to get the next character from the string and place itinto a variable called char$.

We then test to see if the loop variable C is 1, that is we havethe first character of the name. If it is then we want to makesure that it is a capital letter. Notice that you can compareletters as if they were numbers so for example the letter a isless than the letter z.

Note: The <= operator means less than or equal to and the >=means greater than or equal to.

If the first character is a lower case letter (between a and z)then we need to convert it to a capital one. As has beenmentioned before the letters are really stored as numbers, inthis case in ASCII format. Because of the way that thecharacters are laid out in ASCII you can easily convert fromlower case to upper case by subtracting 32 from the codes.

First you have to find the ASCII code for your character usingthe ASC function. Then you can subtract 32 from this to findthe code for the equivalent capital letter. Finally you need toconvert it back from a code to a character again using the CHR$function. You could do this on separate lines of code but it isalso possible to do it all in one go as shown:

char$ = CHR$(ASC(char$) - 32)

Page 28: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

28

The ELSE part of the IF statement will be executed when C isgreater than 1 which will be every other time around the loop.This time we test for the letters being capital ones and convertthem to lower case.

Finally we add our converted (or not) character onto our newstring variable. Once every character has been checked andconverted if necessary we can print out our new formattedname string.

As usual there are other ways this could be done and theprogram does not check that the user entered just letters.What if they had typed numbers or punctuation or even theirfull name with surname? It is difficult to allow for everypossible thing that a user could enter.

Bits and BytesAs I mentioned before information is stored in a computer as aseries of 1s and 0s. Each one of these 1s or 0s is known as a bitand is represented in the computer by something being eitheron (1) or off (0).

We count in a system called decimal which uses base 10. This ismostly because with have ten digits (fingers and thumbs) onour hands. Computers count in a system called binary whichuses base 2. We count from 1 to 9 and then start a 10s column.In binary you count from 0 to 1 and then start a 2s column.

Each column is then 2 times the one before (just as in decimalit is 10 times).

8 bits of computer storage are known as a byte. This can beused to store a decimal number in the range 0 to 255. Here isan example:

128 64 32 16 8 4 2 1

1 0 1 1 0 0 0 1

To convert 10110001 in binary to decimal you do (128 x 1) +(64 x 0) + (32 x 1) + (16 x 1) + (8 x 0) + (4 x 0) + (2 x 0) + (1 x 1).Anything times 0 is 0 and anything times 1 is itself so thissimplifies to 128 + 32 + 16 + 1 = 177.

My first computer had 32KB (Kilobytes) which is about 32,000Bytes of memory. Your FUZE has 1GB (Gigabyte) which is over1,000,000,000 bytes. The SD card sticking out of the back hasat least 8 GB (Gigabytes) of storage which is over 8,000,000,000bytes. You can now buy hard disk drives with a capacity of 4TB(Terabytes) which is an enormous 4,000,000,000,000 Bytes ofdata!

There’s an old computer programming joke: There are 10 sortsof people in the world; those who understand binaryand those who don’t!

Page 29: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

29

ArraysThe next key concept that I want to introduce is called an arrayor indexed variable. An array is really just a way of groupingtogether related variables in a convenient way for processing.

This is best illustrated by an example. Say that you wanted tostore a list of 5 numbers given by the user so that you can thenperform calculations on them such as adding them together.You could do something like this:

Input "Enter Number 1: ", Num1Input "Enter Number 2: ", Num2Input "Enter Number 3: ", Num3Input "Enter Number 4: ", Num4Input "Enter Number 5: ", Num5Sum = Num1 + Num2 + Num3 + Num4 + Num5PRINT "Sum = "; SumEND

This will work perfectly well but what if we want to add 20numbers? or 30? or indeed an unknown number. This is wherean array can come in useful. An array is a variable that canstore multiple values which can be accessed using a numbercalled an index. The indexed array variables are known as arrayelements.

To create an array we have to specify the maximum number ofelements that we want to store. This can be tricky because wewant to leave enough space for our use but have to bear inmind that computer memory (a finite resource) is beingallocated whether we use it or not, so try to make arrays assmall as possible. To create an array you use the Dim command(dimension) as follows:

DIM VariableName(Size)

Where VariableName is the name of the array and Size is themaximum size. To access the elements of the array you thenuse:

VariableName(Index)

where Index is a number from 0 to Size. If you try to access anarray element greater than Size you will get an Out of boundserror.

So we can now rewrite our summing program using an array asfollows:

Page 30: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

30

DIM Num(5)FOR Index= 1 to 5 CYCLE

INPUT "Enter Number: ", NumberNum(Index) = Number

REPEATSum=0FOR Index= 1 to 5 CYCLE

Sum = Sum + Num(Index)REPEATPRINT "Sum = "; SumEND

You will notice that this program is actually slightly longer thanthe original, but if we wanted to add 10 numbers rather than 5in the first case we would almost double the length of theprogram whereas in the second you would just change the 5sinto 10s.

As well as arrays of numbers you can also have arrays ofstrings. These work in a very similar way to number arrays butthe values stored are character strings. To dimension a stringarray you just add the $ sign to the end of the name, same aswith a string variable:

DIM DayOfWeek$(7)

You can then access the array elements in the same way as in anumeric array:

DayOfWeek$(1) = "Monday"DayOfWeek$(2) = "Tuesday"

PRINT "The first day of the week is ";PRINT DayOfWeek$(1)

Arrays can also have more than one dimension. Suppose thatwe wanted to write a program to play chess. We couldrepresent the board using a 2 dimensional array. A chess boardhas 8 rows and 8 columns as shown below:

1 2 3 4 5 6 7 8

1

2

3

4

5

6

7

8

To create an array to represent this we would use thefollowing:

Page 31: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

31

DIM ChessBoard(8,8)

We can then access individual board positions by crossreferencing the row number and the column number as shownbelow:

1 2 3 4 5 6 7 81 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8)

2 (2,1) (2,2) (2,3) (2,4) (2,5) (2,6) (2,7) (2,8)

3 (3,1) (3,2) (3,3) (3,4) (3,5) (3,6) (3,7) (3,8)

4 (4,1) (4,2) (4,3) (4,4) (4,5) (4,6) (4,7) (4,8)

5 (5,1) (5,2) (5,3) (5,4) (5,5) (5,6) (5,7) (5,8)

6 (6,1) (6,2) (6,3) (6,4) (6,5) (6,6) (6,7) (6,8)

7 (7,1) (7,2) (7,3) (7,4) (7,5) (7,6) (7,7) (7,8)

8 (8,1) (8,2) (8,3) (8,4) (8,5) (8,6) (8,7) (8,8)

For example the position highlighted would be accessed usingChessBoard(4,5)

Say that we wanted to store the colour of each position in thearray we could use the following:

DIM ChessBoard(8,8)Count = 0FOR Row= 1 TO 8 CYCLE

FOR Col = 1 To 8 CYCLECount = Count + 1IF Count MOD 2 = 1 THEN

ChessBoard(Row, Col) = 7ELSE

ChessBoard(Row, Col) = 0ENDIF

REPEATREPEATEND

The Row loop executes 8 times. Within it the Col loop executesfor each row. This means that the Count variable isincremented 64 times going from1 to 64. The MOD (modulus)operator gives the remainder when the first number is dividedby the second (if there is no remainder it returns 0). Soanything MOD 2 will return either 1, if it is an odd number or 0if it is even. The net result is that the value will toggle between1 and 0 (or True and False) as Count increases i.e.

For example the position highlighted would be accessed usingChessBoard(4,5)

Say that we wanted to store the colour of each position in thearray we could use the following:

Page 32: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

32

1 Mod 2 = 1 (True)2 Mod 2 = 0 (False)3 Mod 2 = 1 (True)4 Mod 2 = 0 (False)5 Mod 2 = 1 (True)And so on.

In fact arrays can have any number of dimensions limited onlyby the amount of available memory.

There is another type of array supported by FUZE BASIC whichis called an associative array. This allows you to associate a keywith an array index. So for example youcould create an array tohold information about a person and then use the key to storedifferent bits of information could create an array to holdinformation about a person and then use the key to storedifferent bits of information about them:

DIM Person$(10)Person$("firstname") = "Ford"Person$("surname") = "Prefect"PRINT "Full name: ";PRINT Person$("firstname");" ";PRINT Person$("surname");END

Data, Read and RestoreThese three commands provide an easy way to initialise (setinitial values) variables with a set of values. This is probablybest shown with an example. Suppose that you have an arrayto store the names of the days of the week. You could set it uplike this:

Dim DayOfWeek$(7)DayOfWeek$(1) = "Monday"DayOfWeek$(2) = "Tuesday"DayOfWeek$(3) = "Wednesday"DayOfWeek$(4) = "Thursday"DayOfWeek$(5) = "Friday"DayOfWeek$(6) = "Saturday"DayOfWeek$(7) = "Sunday"

This will work fine but as the list of values gets longer it willstart to make the program get very long. A neater way to dothis is to use the DATA command to store the values and thenREAD to set them as follows:

DIM DayOfWeek$(7)FOR DayNo = 1 TO 7 CYCLE

READ DayOfWeek$(DayNo)REPEATENDDATA "Monday", "Tuesday", "Wednesday"DATA "Thursday", "Friday", "Saturday"DATA "Sunday"

Page 33: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

33

The DATA statements can actually occur anywhere in theprogram but are usually placed at the end. The READcommand will start reading values from the first DATAstatement it finds in the program and continue from there.

The RESTORE command will set it back to the first one again ifyou needed to reread it. This could be useful if the values havebeen changed by the program but you want to reset them backto their initial values.

FilesAnother way to store data is as collections of bytes on astorage device (such as an SD card or hard drive) called files.Files fall broadly into two types: text, consisting of ASCIIcharacters and readable by a human and binary, consisting of1s and 0s and readable by machines only. Binary data is used tostore things like images, video or music.

FUZE BASIC has support for creating files. You have alreadybeen using text files as they are used to store the FUZE BASICprograms themselves. To demonstrate this let’s create aprogram to read itself!

In the editor enter the following program:

handle=OPEN("ReadSelf.fuze")UNTIL EOF(handle) CYCLE

INPUT# handle, record$PRINT record$

REPEATCLOSE (handle)END

When you run this (F3) and are prompted to enter a file name,enter ReadSelf (make sure that the case of the letters matchesexactly). You should see the program printed to the screen. Sohow does this work?

The first line opens a file in the current location calledReadSelf.fuze and returns a number into the variable calledhandle. This number, called a file handle, is linked to this fileand we can access the file by passing the number to filehandling routines. If the file does not exist then a new file willbe created.

Note: File names usually have two parts. The first part is itsname and the second part after the dot is called the fileextension. This is used to tell what type of file it is, for examplea music file might have the file extension .mp3 and a text file.txt. FUZE BASIC programs have the file extension .fuze

Page 34: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

34

The second line starts a loop which will loop as long asEOF(handle) is FALSE. The EOF function returns TRUE when theend of the file has been reached and FALSE otherwise soinitially this should be FALSE as we are at the start of the file.

The next line uses a special version of the INPUT commandINPUT# which instead of reading from the keyboard reads fromthe file linked to the file handle that follows it and puts theresult in the variable specified (in this case the string variablerecord$). The INPUT# command will read up until the end of aline is reached.

Finally the contents of the record$ variable is printed to thescreen and the program loops around. When the end of the fileis reached EOF(handle) returns FALSE and the loop terminates.Finally the CLOSE statement is used to close the file andrelease the file handle (which can then be used again for adifferent file if required).

So that is how you read a file, how do we go about writing toone? Just as you use INPUT# instead of INPUT you can usePRINT# instead of PRINT to print to a file.

handle=OPEN("TestFile.txt")FOR RecNo=1 to 10 CYCLE

PRINT# handle,"Record "; RecNoREPEATCLOSE(handle)handle=OPEN("TestFile.txt")UNTIL EOF(handle) CYCLE

INPUT# handle, record$PRINT record$

REPEATCLOSE (handle)END

Run this program and you will get the following:

This program first opens a file called TestFile.txt and creates itif it doesn’t exist.  It then loops with the variable RecNo goingfrom 1 to 10.

Page 35: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

35

The PRINT# command then prints Record and the value ofRecNo to the file linked to handle. The file is then closed andreopened again. This will position the file handle back to thestart again. The file is then read back and printed to the screenas before. On the left hand side of the FUZE Desktop you willsee an Icon that looks like this:

If you double click on this icon it will open theFile Manager window for the folder whereFUZE BASIC stores its files by default:

In this folder you should see the file you have just created. Ifyou double click on this file you will see its contents in theeditor:

There is another wayto position the fileback to the start andthat is using the SEEKfunction which hasthe following syntax:

SEEK(handle, offset)

The offset argument supplied is the position in the file to jumpto, 0 being the beginning of the file. So instead of closing andreopening the file we could have simply written:

SEEK(handle, 0)

We can use the SEEK function to access the file at any pointrather than having to read it sequentially from the start. This isknown as random file access. To do this successfully we needto know how long the records are and they need to be a fixedsize.

Page 36: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

36

handle=OPEN("TestFile.txt")recSize = 20FOR recNo=0 to 10 CYCLE

record$ = "Record " + STR$(recNo)pad = recSize - LEN(record$)PRINT# handle,record$;SPACE$(pad)

REPEATSEEK (handle,(recSize+1)*7)INPUT# handle,record$PRINT record$CLOSE(handle)END

In this example the maximum record size is set to be 20characters. Each record is then padded with spaces to beexactly this length using the SPACE$ function. Then you canseek to any record using:

SEEK(handle,(recSize+1)*recNo)

where recNo is the record number. Notice that you have to add1 to the record size. This is to skip over the new line character(ASCII character 10) at the end of each record.

There are a couple of other file handling functions that Ihaven’t covered yet. The REWIND(handle) function sets the fileback to the beginning. This is equivalent to SEEK(handle, 0).

The fast forward function FFWD(handle) sets the file pointer tothe end of the file. This allows you to append records to theend of the file.

SpritesNow for some fun! Sprites are small computer graphics thatcan be animated and moved around on the screen. They formthe basis of a lot of computer games. To create sprites youreally need to use a sprite editor or graphic editing program.However you can use FUZE BASIC’S ability to be able to savewhat’s on the screen to a file to create your own using thegraphic routines you saw earlier.

The SAVEREGION function takes a snapshot of the specifiedarea of the screen and saves it to a file:

SAVEREGION(file$,xpos,ypos,width,height)

The region is given by the rectangle with bottom left at point(xpos,ypos) with width and height pixels, and is saved to a filenamed file$ in a bitmap (.bmp) format.

Let’s try this now. We will draw a yellow circle on the screenand save it to a file:

Page 37: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

37

CLSCOLOUR=YELLOWCIRCLE(100,100,50,TRUE)SAVEREGION("pacman1.bmp",50,50,101,101)END

Now if you open the FUZE folder on the Desktop you will seethis:

Our yellow circle has been saved to a file calledpacman1.bmp.  Now let’s create another image with atriangular piece missing. We can do this by drawing a blacktriangle on our circle and saving it again:

CLSCOLOUR=YELLOWCIRCLE(100,100,50,TRUE)COLOUR=BlackTRIANGLE(100,100,150,125,150,75,TRUE)SAVEREGION("pacman2.bmp",50,50,101,101)END

If you run this there should now be a new file in the folder thatlooks like this:

Finally we want to create anotherone with a bigger chunk missing, sowe just make the triangle bigger anddraw it again:

CLSCOLOUR=YELLOWCIRCLE(100,100,50,TRUE)COLOUR=BlackTRIANGLE(100,100,150,150,150,50,TRUE)SAVEREGION("pacman3.bmp",50,50,101,101)END

Now that we have created our bitmap images we can make asprite using the NEWSPRITE function. This takes an argumentto say how many images it will contain, in this case 3.

Page 38: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

38

We can then use LOADSPRITE to load the images from a file:

CLSpacman=NEWSPRITE(3)LOADSPRITE("pacman1.bmp",pacman,0)LOADSPRITE("pacman2.bmp",pacman,1)LOADSPRITE("pacman3.bmp",pacman,2)

LOADSPRITE has 3 arguments. The first is the name of the fileto load, the second is the handle of the sprite which wasreturned by NEWSPRITE and the last one is the image index(which goes from 0 to the number of images minus one).

To draw our sprite on the screen we use the PLOTSPRITEfunction which has the following syntax:

PLOTSPRITE(handle,xpos,ypos,index)

The handle argument is returned from the NEWSPRITEfunction and index is as above. The point (xpos, ypos) specifiesthe bottom left hand corner of the bounding rectangle of thesprite. When you call PLOTSPRITE the sprite at the currentposition is cleared and it is redrawn at the new one. So nowwe can make our sprite move across the screen using thefollowing program:

CLSpacman=NEWSPRITE(3)LOADSPRITE("pacman1.bmp",pacman,0)LOADSPRITE("pacman2.bmp",pacman,1)LOADSPRITE("pacman3.bmp",pacman,2)FOR X=1 TO GWIDTH STEP 25 CYCLE

FOR S=0 TO 2 CYCLEPLOTSPRITE(pacman,X,GHEIGHT/2,S)UPDATEWAIT(.05)

REPEATREPEATHIDESPRITE(pacman)END

You will notice that there are two loops, one inside the other.The first one moves the sprite across the screen. The secondcycles though the different versions of the sprite. Finally whenit has reached the other side of the screen the HIDESPRITEfunction removes it from the screen.

When writing games you quite often need to know when onesprite collides with another one on the screen. First let’s createanother sprite using the following program:

Page 39: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

39

CLSCOLOUR=REDCIRCLE(100,100,50,TRUE)RECT(50,50,101,50,TRUE)COLOUR=WHITEELLIPSE(72,120,13,17,TRUE)ELLIPSE(112,120,13,17,TRUE)COLOUR=BLUECIRCLE(68,115,7,TRUE)CIRCLE(108,115,7,TRUE)COLOUR=BLACKTRIANGLE(55,49,65,65,80,50,TRUE)TRIANGLE(85,49,95,65,110,50,TRUE)TRIANGLE(115,49,125,65,140,50,TRUE)SaveRegion("ghost1.bmp",50,50,101,101)END

Now we can use the SPRITECOLLIDE function to work outwhen our two sprites have hit each other as shown below andopposite:

CLSpacman=NEWSPRITE(3)LOADSPRITE("pacman1.bmp",pacman,0)LOADSPRITE("pacman2.bmp",pacman,1)LOADSPRITE("pacman3.bmp",pacman,2)ghost=NEWSPRITE(1)LOADSPRITE("ghost1.bmp",ghost,0)midY=GHEIGHT/2

(Continued)

FOR X=0 TO GWIDTH STEP 10 CYCLEPLOTSPRITE(pacman,X,midY,X MOD 3)PLOTSPRITE(ghost,GWIDTH-X-100,midY,0)IF SPRITECOLLIDE(pacman) <> -1 THEN

BREAKENDIFUPDATEWAIT(0.1)

REPEATEND

When you call SPRITECOLLIDE it will return -1 if the givensprite is not in contact with any other and the handle of thecolliding sprite if it is.

User Defined Procedures & FunctionsAs mentioned before it is possible for you to define your ownprocedures and functions. This allows you to reuse code andmakes your program much more readable. It will also makeyour program easier to maintain and modify.

As usual I will try to illustrate this using an example. Say youwant to print out some messages and you want them to becentred on the screen. I showed you how this could be donebefore:

Page 40: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

40

Message$="This text will be in"PadLength=(TWIDTH – LEN(message$))/2PRINT SPACE$(PadLength) + message$Message$="the centre of each"PadLength=(TWIDTH – LEN(message$))/2PRINT SPACE$(PadLength) + message$Message$="line on the"PadLength=(TWIDTH – LEN(message$))/2PRINT SPACE$(PadLength) + message$Message$="screen"PadLength=(TWIDTH – LEN(message$))/2PRINT SPACE$(PadLength) + message$END

You will notice that we have repeated some code here. Line 2is the same as line 5, 8 and 11. Line 3 is the same as line 6, 9and 12. This is a good sign that we should probably use aprocedure.

PROC CentreText("This text will be in")PROC CentreText("the centre of each")PROC CentreText("line on the")PROC CentreText("screen")ENDREM Centre text on the lineDEF PROC CentreText(message$)

PadLength=(TWIDTH – LEN(message$))/2PRINT SPACE$(PadLength) + message$

ENDPROC

I hope you will agree that this is much neater and easier toread and understand. The procedure is defined using the DEFPROC (define procedure) command and this is placed after theEND of the program as it will only be used when it is calledusing the PROC command.

In this example the procedure has one variable (called aparameter) which is the text string to be printed but it couldhave zero or many (in which case they would be separated bycommas). When the procedure is called the argument, in thiscase the text to be printed is passed into this parameter.

When the ENDPROC command is executed the programreturns to the point where it was called and resumes on thefollowing line.

What if you decide that you want the text to be in upper case(capital letters)? For this we could write a function to convertany string to upper case.

Note: The only difference between a procedure and a functionis that a function returns a value.

Page 41: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

41

DEF FN ToUpper(string$)result$=""FOR C=1 TO LEN(string$) CYCLE

char$=MID$( string$, C - 1, 1)IF char$ >= "a" AND char$ <= "z" THEN

char$ = CHR$(ASC(char$) - 32)ENDIFresult$= result$+char$

REPEAT=result$

This uses the code that we wrote earlier but puts it into a userdefined function using the DEF FN command. You would callthis function using the FN command:

message$=FN ToUpper("String to convert")

The last line =result$ returns the value in this variable andplaces it in the variable on the calling line.

You can think of writing procedures and functions as writingyour own extensions to the language. You could even writeyour own library of standard routines to be included into yourprograms.There is one other thing that I need to mention aboutprocedures. If you set the value of a variable in a procedureand you use the same variable name in the main body of theprogram then the value will be changed there as well.

This is because variables are global by default. However it ispossible to declare a variable as being local to a procedure toavoid any nasty side effects. Consider the following example:

X=10PRINT "1 Global X="; XPROC Test()PRINT "2 Global X="; XENDDEF PROC Test()

PRINT "3 Global X="; XX=15LOCAL XX=5PRINT "4 Local X="; X

ENDPROC

This will produce thefollowing result whenrun:

So let me just runthrough this. First you define a (global) variable X and give it avalue of 10. Then you call a procedure called Test. This firstprints out the value of the (global) variable X. The value is thenchanged to 15. It then declares a new local variable X and givesit the value 5. As long as you are in the procedure this is theone that will be used.

Page 42: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

42

When the procedure ends and the program goes back to thecalling line the local variable X is destroyed. However the globalvariable X still exists and has the last value that it was set to(15).

In general it is good practice to declare variables local to aprocedure or function and to pass any values required asparameters rather than using global variables. This preventsunforeseen consequences!

Numerical FunctionsComputers are good for doing mathematical calculations andcan perform many thousands per second. I have alreadycovered some arithmetic operators such as add (+), multiply(*), subtract (-) and divide(/) but there are also a number ofbuilt in functions in FUZE BASIC to do more complicatedmathematical calculations for things like trigonometry (themathematics of triangles).

I am not going to cover all of these in detail as you can findthem in the language reference section of this manual but I willjust go over an example.

Suppose we want to draw the second hand of a clock and makeit move round once per second. We can use the trigonometricfunctions SIN (sine) and COS (cosine) to do this. Without going

into a huge amount of detail, for a circle of radius r and centreat point (x1,y1) we can calculate any given point (x2,y2) using:

x2 = r * SIN(a) + x1 and

y2 = r * COS(a) + y1

where a is the angle going from 0 to 360 degrees

By default angles in FUZE BASIC are measured in degreeswhere there are 360 degrees in a circle. You can change theunits to Radians using the RAD command (there are 2 * PIRadians in a circle) or to minutes using the CLOCK command(there are 60 minutes in a circle). You can change back todegrees using the DEG command.

Page 43: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

43

So to draw our second hand we can set the units to CLOCK andthen loop from 0 to 60 minutes (this is the same as usingdegrees and looping from 0 to 360 with a STEP of 5). Ourprogram could then look like this:

CLSCLOCKFOR Angle=0 TO 60 CYCLE

PROC SecondHand(Angle-1, BLACK)REPEATFOR Angle=0 TO 60 CYCLE

PROC SecondHand(Angle, WHITE)PROC SecondHand(Angle-1, BLACK)UPDATEWAIT(1)

REPEATENDREM Draw second hand on the screenDEF PROC SecondHand(seconds, handColour)

COLOUR=handColourXpos=200*SIN(seconds)+GWIDTH/2Ypos=200*COS(seconds)+GHEIGHT/2LINE(GWIDTH/2,GHEIGHT/2,Xpos,Ypos)IF handColour = BLACK THEN

COLOUR=WHITECIRCLE(Xpos,Ypos,2,TRUE)

ENDIFENDPROC

The first loop draws a white circle at 1 minute intervals. Thesecond draws the second hand and erases the previous secondhand. It then waits for 1 second before looping around.

The output from our program is shown below:

Turtle GraphicsFUZE BASIC supports another type of computer graphics calledTurtle Graphics. They are called this because they wereoriginally used to control a small robot which had a domed topand looked a bit like a turtle. This was done using aprogramming language called LOGO which was designed toteach people (and especially children) about programming.

Page 44: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

44

The turtle had a pen and by moving the pen up and down andthe robot around on a piece of paper it could draw pictures.

In FUZE BASIC the turtle is ‘virtual’, that is it exists onlyinside the computer’s memory but it can be made to drawpictures on the screen. It should be possible for you to make areal turtle controlled by your FUZE!

There are two commands that control the virtual pen. ThePENUP command lifts the pen from the paper and stops theturtle from drawing. As you might expect the PENDOWNcommand does the opposite. When the pen is down everytime you move the turtle it will draw in the currently selectedCOLOUR. The pen is initially in the ‘up’ position.

To move the turtle you can either use an absolute position onthe screen using the MOVETO(xpos,ypos) command or you canmake it move relative to the current point using theMOVE(pixels) command. The turtle is initially placed in themiddle of the screen.

The turtle has a current direction that it is facing. You canrotate the turtle in either direction using the LEFT(angle) orRIGHT(angle) commands. The angle will be in the current angleunits (degrees is the default). You can also find or set thecurrent turtle angle using the TANGLE built- in variable.

The turtle is initially facing towards the top of the screen. Thisexample draws a spiral on the screen:

CLSPENDOWNFOR I=2 TO GWIDTH CYCLE

MOVE(I)RIGHT(30)

REPEATUPDATEEND

GPIOGPIO stands for General Purpose Input/Output and allows youto connect your FUZE to other electronic devices. These caneither send signals to the FUZE or be controlled by it. Thecircuit board at the top left of your FUZE is connected to theGPIO of the Raspberry PI inside it.

I won’t go into lots of detail here as it will be covered in theproject cards, but I will go over the main items you will use.

The PINMODE procedure is used to set a particular GPIO pin tobe either an output pin or an input pin. An output pin could beused to light up an LED and an input pin to read whether abutton has been pressed. The syntax of PINMODE is as follows:PINMODE(pinno,pinmode)

Page 45: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

45

Where pinno is the number of the pin (from 0 to 16) andpinmode is 0 for input and 1 for output. So to set pin 12 to bean output pin you would do:

PINMODE(12, 1)

Then to set the output to on or off you use the DIGITALWRITEprocedure which has the following syntax:

DIGITALWRITE(pinno,pinvalue)

Where pinno is the number of the pin and pinvalue is 0 for offand 1 for on. So to set pin 12 to be on you would use:

DIGITALWRITE(12,1)

So if there was an LED attached to pin 12 of the GPIO thiswould switch it on. The following program would cause an LEDto flash on and off if it were attached to pin 2:

PINMODE(2,1)CYCLE

DIGITALWRITE(2,1)WAIT(1)DIGITALWRITE(2,0)WAIT(1)

REPEATEND

If you set a pin to be input you use the DIGITALREAD functionto read whether it is set to on or off. The following programwould loop and do nothing until a button attached to pin 12 ispressed:

PINMODE(12,0)REM Wait for button to be pushedUNTIL DIGITALREAD(12) CYCLEREPEATPRINT "Button Pushed"END

Robot ArmFUZE BASIC has built in support for the popular OWI-535 robotarm kit.

The robot arm comes in two forms, one with just a manualremote control and the other with a PC USB interface as well.You will need to have the USB interface in order to be able tocontrol it from the FUZE. This is also available to be boughtseparately. You will also need a spare USB socket which mayrequire a separate powered USB hub.

Note: If you have an older version of the FUZE boot image youmay be missing some of the libraries required to connect tothe robot arm and you may get an error. You can download thelatest version of the image from the FUZE website.

Page 46: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

46

Connect the robot arm to a spare USB socket and make surethat it is switched on before booting up your FUZE. Then startFUZE BASIC and to test that the communication is working typeARMLIGHT(1) and press the Enter key. This should switch onthe LED in the middle of the arm’s grippers. TypingARMLIGHT(0) will switch it off again.

The arm has 5 motors and each of them can be controlledseparately to move in a clockwise direction, by passing 1 as theargument, or anti-clockwise by passing -1. The ARMRESETcommand is used to stop them again.

For Example to move the Elbow motor for 2 seconds in aclockwise direction you would do the following:

ARMELBOW(1)WAIT(2)ARMELBOW(0)

MusicFUZE BASIC can play various audio formats. You will need tohave some additional hardware in order to hear the sound.

If your FUZE is connected to an HDMI monitor then by defaultthe sound is played through the audio output of the monitor. Ifthe monitor does not have built-in speakers you will need toconnect some headphones or external powered speakers tothe audio output of the monitor.

If you are not using anHDMI monitor thesound will bedirected to the audiojack on the back of theFUZE unit.

Page 47: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

47

Even if you are using an HDMI monitor you can force it to usethis audio jack by starting a terminal session (click on the Iconin the bottom left of the desktop and select Accessories andthen LXTerminal) and typing the following command:

amixer cset numid=3 1

To switch back to automatic simply change the 1 to a 0 in theabove command. If your FUZE unit is connected to the internetyou can download a sample file by opening a terminal sessionand entering the following commands:

cd /home/pi/Desktop/FUZE

wget http://www.fuze.co.uk/FUZEBIN/media/takeoff.wav

Alternatively you can download the file on an internetconnected device and transfer it to your FUZE using a memorystick. Enter the address above into an internet browser, thenright-click and select Save as from the menu. Copy the file intothe folder;

/home/pi/Desktop/FUZE on the FUZE.

To load a music file you use the LOADMUSIC function:

handle=LOADMUSIC("takeoff.wav")

And to play the music file you use the PLAYMUSIC function asfollows:

PLAYMUSIC(handle,1)

This starts the music playing in the background which meansthat you can carry on issuing new commands while it plays. Forexample the PAUSEMUSIC function will pause the currentlyplaying music and RESUMEMUSIC will start it playing again. TheSTOPMUSIC function will stop the music playing completely.You can also set the playback volume usingSETMUSICVOL(level) where level is a number from 0 to 100%.

The second argument of the PLAYMUSIC functions tells it howmany times to repeat the track before stopping. You can have8 different music tracks loaded at the same time.

Sound EffectsSound samples are similar to music playback except that youcan play up to 4 tracks at the same time. This will let you addsound effects to your games. You can load up to 32 tracks andplay any 4 at the same time in a similar manner to the music:

handle=LOADSAMPLE("filename.wav")

Page 48: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

48

You can then playback a sample using;

PLAYSAMPLE(handle, channel, loops)

Here, the channel is 0, 1, 2 or 3. This lets you play up to 4concurrent samples. The loops parameter is different to therepeats one in the PLAYMUSIC function. Here it means thenumber of times to loop the sample - zero means no loopswhich means play it ONCE.

You then have similar functions to the music playback ones tostop, pause or resume the sample as shown below. You canalso control the volume of each individual channel usingSETCHANVOL.

STOPCHAN(handle)PAUSECHAN(handle)RESUMECHAN(handle)SETCHANVOL(channel, volume)

So now we can add some sound effects to the pacmananimation that we created earlier. You can download twosamples from our website by opening a terminal session andentering the following commands:

cd /home/pi/Desktop/FUZE

Wget http://www.fuze.co.uk/FUZEBIN/media/pacman_chomp.wavwget http://www.fuze.co.uk/FUZEBIN/media/pacman_death.wav

Now try the following:

CLSpacman=NEWSPRITE(3)LOADSPRITE("pacman1.bmp",pacman,0)LOADSPRITE("pacman2.bmp",pacman,1)LOADSPRITE("pacman3.bmp",pacman,2)ghost=NEWSPRITE(1)LOADSPRITE("ghost1.bmp",ghost,0)chomp=LOADSAMPLE("pacman_chomp.wav")death=LOADSAMPLE("pacman_death.wav")PLAYSAMPLE(chomp,0,10)midY=GHEIGHT/2FOR X=0 TO GWIDTH STEP 10 CYCLE

PLOTSPRITE(pacman,X,midY,X MOD 3)PLOTSPRITE(ghost,GWIDTH-X-100,midY,0)IF SPRITECOLLIDE(pacman) <> -1 THEN

HIDESPRITE(ghost)STOPCHAN(chomp)PLAYSAMPLE(death,1,0)BREAK

ENDIFUPDATEWAIT(0.1)

REPEATEND

Page 49: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

49

You will need the sprite files that you created earlier. I willleave it as an exercise for you to add the pacman deathanimation sequence.

Synthesized MusicThe simplest way to generate sound in FUZE BASIC is using thetone command which has the following syntax:

TONE(channel, volume, frequency, duration)

This plays a simple tone of the given frequency (1 to 5000Hz),volume (%) and duration (0.01 to 20 seconds) on the givenchannel (0 to 3).

You can play multiple tones by playing them one after theother and up to three tones can be played simultaneously ondifferent channels. Channel 0 is white noise and the frequencyhas no bearing on the sound produced.

The demonstration program below reads the notes anddurations using the DATA and READ commands to play asimple tune.

Channel=1Volume=70FOR Note=1 TO 5 CYCLE

READ Frequency,DurationTONE(Channel,Volume,Frequency,Duration)

REPEATENDDATA 440,1DATA 493,1DATA 392,1DATA 196,1DATA 294,2

Here are the notefrequencies for theBass and Treble clefs.

Note Bass Treble

C 131 262

C# 139 277

D 147 294

D# 156 311

E 165 330

F 175 349

F# 185 370

G 196 392

G# 208 415

A 220 440

A# 233 466

B 247 493

Page 50: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

50

Immediate Mode CommandsThere are a number of immediate modecommands that we haven’t covered yet.By default FUZE BASIC will store your programsin a folder on your Desktop called FUZE:

In Immediate mode type the command pwd (print workingdirectory) and you will be shown the path of the folder that willbe used by default to load and save files:

You can list the FUZE program files in this directory using theDIR command (you can also use the unix ls command to do thesame thing). Note that this will only show FUZE BASIC programfiles, not images or other text files that are in the folder.

You can then load a program into memory using the LOADcommand. To do this type LOAD followed by the programname but without the file extension (.fuze). Don’tput quotation marks (") around the filename and it is casesensitive so the upper and lower case letters must match,otherwise you will get an error.

You can save changes to your program using the SAVEcommand on its own or indeed save it to a different filenameby using SAVE filename where filename is the new name.

If you want to change the default folder where files are loadedand saved you can use the CD (change directory) commandfollowed by the path of the folder.

You can list the program currently loaded using the LISTcommand or edit it using the EDIT command. If you want tostart a new program you use the NEW command but as thisdeletes the program that is currently loaded make sure thatyou have saved any changes first!

To run the currently loaded program outside of the editor youcan use the RUN command and finally to exit FUZE BASIC andreturn to the desktop you use the EXIT command.

Page 51: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

51

CommandsCLEAR........................................................................... 51CLS ...............................................................................52CONT............................................................................ 52CONTINUE.................................................................... 53DIR ...............................................................................53EDIT..............................................................................54EXIT ..............................................................................54LIST ..............................................................................55LOAD............................................................................ 55NEW............................................................................. 56RUN..............................................................................56SAVE............................................................................. 57VERSION.......................................................................57

CLEARPurposeClear variable memory.

SyntaxCLEAR

DescriptionClears all variables and deletes all arrays. It also removesany active sprites from the screen. Stopped programs maynot be continued after a CLEAR command.

ExampleREM Immediate ModeVARIABLE=10PRINT VARIABLECLEARREM Unassigned variable error!PRINT VARIABLE

AssociatedNEW

Page 52: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

52

CLSPurposeClear the video display screen.

SyntaxCLS

DescriptionClears the video display screen and places the cursor inthe top left corner. The background is set to the currentbackground (PAPER) colour.

ExamplePAPER=WHITEINK=BLACKCLSPRINT "Hello World"END

AssociatedCLS2, INK, PAPER, UPDATE

CONTPurposeContinue running a program that has been stopped.

SyntaxCONT

DescriptionContinues program execution after a STOP instruction.Variables are not cleared.

ExampleREM Immediate modeCONT

AssociatedSTOP

Page 53: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

53

CONTINUEPurposeContinue a loop.

SyntaxCONTINUE

DescriptionWill cause the loop to re-start at the line containing theCYCLE instruction, continuing a FOR instruction and re-evaluating any WHILE or UNTIL instructions.

ExampleREM Prints 1 to 10 but skips over 5FOR I=1 to 10 CYCLE

IF (I=5) THEN CONTINUEPRINT I

REPEATEND

AssociatedBREAK, CYCLE, CYCLE REPEAT, FOR REPEAT, REPEATUNTIL, UNTIL REPEAT, WHILE REPEAT

DIRPurposeList FUZE BASIC program files in the current or specifieddirectory.

SyntaxDIR [directory]

DescriptionLists the program files in your current working directory orthe optional specified directory. These will have the .fuzefile extension.

ExampleREM Immediate ModeDIR

AssociatedLOAD, SAVE

Page 54: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

54

EDITPurposeEdit the program in memory.

SyntaxEDIT

DescriptionEdits the program in memory using a full screen editor.

ExampleREM Immediate modeEDIT

EXITPurposeExit FUZE BASIC and return to the environment.

SyntaxEXIT

DescriptionExit FUZE BASIC and return to the environment you started itin.

ExampleREM Immediate modeEXIT

Page 55: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

55

LISTPurposeList the program stored in memory to the screen.

SyntaxLIST

DescriptionThis lists the program stored in memory to the screen.You can pause the listing with the space-bar andterminate it with the escape key.

ExampleREM Immediate ModeLIST

LOADPurposeLoad a program into memory.

SyntaxLOAD filename$

DescriptionLoads in a program from the local non-volatile storage. Aswith SAVE, you need to supply the filename without anyquotes. Do not include the .fuze file extension. Note, ifyour filename has spaces then you must enter it withinquoatation marks. LOAD "my game" for example.

ExampleREM Immediate ModeLOAD demos/ballRUN

AssociatedSAVE

Page 56: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

56

NEWPurposeStart a new program

SyntaxNEW

DescriptionDeletes the program in memory. There is no verificationand once it’s gone, it’s gone. Remember to save first!

ExampleREM Immediate ModeNEWREM List will now be emptyLIST

AssociatedCLEAR

RUNPurposeRuns the program in memory.

SyntaxRUN

DescriptionRuns the program in memory. Note that using RUN willclear all variables.

ExampleREM Immediate ModeRUN

Page 57: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

57

SAVEPurposeSaves your program to the local non-volatile storage.

SyntaxSAVE filename$

DescriptionSaves your program to the local non-volatile storage. Thefilename$ is the name of the file you wish to save andmay not contain spaces. If you have already saved a file,then you can subsequently execute SAVE without thefilename and it will overwrite the last file saved. (This isreset when you load a new program or use the NEWcommand)

ExampleREM Immediate ModeSAVE testprog

AssociatedLOAD

VERSIONPurposePrint the current version of FUZE BASIC.

SyntaxVERSION

DescriptionPrint the current version of FUZE BASIC.

ExampleREM Immediate ModeVERSION

Page 58: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

58

Procedures & FunctionsABS............................................................................... 61ACOS ............................................................................ 62ADVANCESPRITE .......................................................... 62ARMBODY.................................................................... 63ARMELBOW ................................................................. 63ARMGRIPPER ............................................................... 64ARMLIGHT ................................................................... 64ARMRESET ................................................................... 65ARMSHOULDER ........................................................... 65ARMWRIST................................................................... 66ASC............................................................................... 66ASIN ............................................................................. 67ATAN............................................................................67BREAK .......................................................................... 68CHR$ ............................................................................68CIRCLE..........................................................................69CLEARKEYBOARD .........................................................69CLOCK .......................................................................... 70CLOSE...........................................................................70CLS2 ............................................................................. 71COLOUR ....................................................................... 72COPYREGION ............................................................... 73COS ..............................................................................74

CYCLE ........................................................................... 74CYCLE REPEAT.............................................................. 75DATA............................................................................ 75DATE$ ..........................................................................76DEF FN ......................................................................... 77DEF PROC..................................................................... 7 7DEFCHAR...................................................................... 7 8DEG .............................................................................. 78DIGITALREAD ............................................................... 79DIGITALWRITE ............................................................. 79DIM ..............................................................................80DRCANALOGREAD ....................................................... 81DRCCLOSE.................................................................... 81DRCDIGITALREAD ........................................................ 82DRCDIGITALWRITE ...................................................... 82DRCOPEN..................................................................... 83DRCPINMODE.............................................................. 83DRCPWMWRITE .......................................................... 84ELLIPSE ........................................................................ 84ELSE ............................................................................. 85END ............................................................................. 85ENDIF........................................................................... 86ENDPROC..................................................................... 86ENVELOPE ................................................................... 87EOF .............................................................................. 88

Page 59: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

59

EXP .............................................................................. 88FADEOFF...................................................................... 89FADEON....................................................................... 89FFWD........................................................................... 90FN ................................................................................ 90FONTSCALE.................................................................. 91FOR REPEAT................................................................. 91FREEIMAGE ..............................................…................ 92GETIMAGEH ................................................................ 92GETIMAGEW ............................................................... 93GETMOUSE.................................................................. 93GETPIXEL ..................................................................... 94GETPIXELRGB............................................................... 94GETSPRITEH................................................................. 95GETSPRITEW................................................................ 95GRABREGION............................................................... 96HIDESPRITE.................................................................. 96HLINE........................................................................... 97HTAB............................................................................ 97HVTAB ......................................................................... 98IF THEN........................................................................ 98INKEY........................................................................... 99INPUT .......................................................................... 99INPUT# .......................................................................100INT..............................................................................100

LEFT ............................................................................101LEFT$ ......................................................................….101LEN..........................................................................….102LINE.............................................................................102LINETO ........................................................................103LOADIMAGE................................................................103LOADMUSIC ................................................................104LOADSAMPLE..............................................................104LOADSPRITE ................................................................105LOCAL .........................................................................105LOG .............................................................................106MAX ............................................................................106MID$ ...........................................................................107MIN.............................................................................107MOUSEOFF .................................................................108MOUSEON ..................................................................108MOVE..........................................................................109MOVETO .....................................................................109NEWSPRITE .................................................................110NUMFORMAT .............................................................111OPEN...........................................................................111ORIGIN ........................................................................112PAUSECHAN................................................................112PAUSEMUSIC ........................................................…….113PENDOWN ..................................................................113

Page 60: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

60

PENUP.....................................................................… 114PINMODE................................................................… 114PLAYMUSIC .................................................................115PLAYSAMPLE...............................................................115PLOT............................................................................116PLOTIMAGE ................................................................116PLOTSPRITE.................................................................117POLYEND.....................................................................117POLYPLOT ...................................................................118POLYSTART .................................................................118PRINT ..........................................................................119PRINT# ........................................................................119

RIGHT$ ...................................................................... 126RND ........................................................................... 127SAVEREGION ............................................................. 127SAVESCREEN.............................................................. 128SCANKEYBOARD ........................................................ 129SCLOSE ...................................................................... 129SCROLLDOWN ........................................................... 130SCROLLLEFT ............................................................... 130SCROLLRIGHT ............................................................ 130SCROLLUP.................................................................. 130SEEK........................................................................... 131SETCHANVOL............................................................. 131SETMODE .................................................................. 132SETMOUSE ................................................................ 132SETMUSICVOL ........................................................... 133SETSPRITEALPHA ....................................................... 133SETSPRITEANGLE....................................................... 134SETSPRITEFLIP ........................................................... 134SETSPRITESIZE ........................................................... 135SETSPRITETRANS ....................................................... 135SGET .......................................................................... 136SGET$ ........................................................................ 137SGN............................................................................ 137SHOWKEYS ................................................................ 138SIN ............................................................................. 138

PRINTAT......................................................................120PROC ...........................................................................120PWMWRITE .................................................................121RAD..............................................................................121READ............................................................................122RECT ............................................................................122REPEAT UNTIL..............................................................123RESTORE.................................................................…..123RESUMECHAN .....................................................….….124RESUMEMUSIC.......................................................... 124REWIND..................................................................... 125RGBCOLOUR.............................................................. 125RIGHT ........................................................................ 126

Page 61: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

61

SOFTPWMWRITE....................................................... 139SOPEN........................................................................139SOUND.......................................................................140SPACE$.......................................................................140SPRITECOLLIDE ..........................................................141SPRITECOLLIDEPP ......................................................142SPRITEOUT.................................................................143SPUT...........................................................................143SPUT$ ........................................................................144SQRT ..........................................................................144SREADY ......................................................................145STOP ..........................................................................145STOPCHAN .................................................................146STOPMUSIC................................................................146STR$ ...........................................................................147SWAP .........................................................................147SWITCH ......................................................................148TAN ............................................................................149TONE..........................................................................149TRIANGLE...................................................................150UNTIL REPEAT ............................................................150UPDATE......................................................................151VAL.............................................................................152VLINE .........................................................................152VTAB ..........................................................................153WAIT ..........................................................................153WHILE REPEAT ...........................................................154

ABSPurposeReturn the absolute value of the argument.

Syntaxpositivenumber=ABS(number)

DescriptionReturns the absolute value of the supplied argumentnumber i.e. If the argument is negative, make it positive.

ExamplePRINT FN ElapsedYears(1966,2013)PRINT FN ElapsedYears(2013,1966)ENDREM Return Number of years elapsedREM Between two datesDEF FN ElapsedYears(Year1, Year2)=ABS(Year1-Year2)

AssociatedSGN

Page 62: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

62

ACOSPurposeReturns the arc cosine of the supplied argument.

Syntaxangle=ACOS(cosine)

DescriptionThis is the inverse of the COS function returning the anglefor a given cosine.

ExamplePRINT "Angle with cosine = 0.5: "DEGREM 60 DegreesPRINT "In Degrees: ";ACOS(0.5)RADREM PI/3 RadiansPRINT "In Radians: "; ACOS(0.5)CLOCKPRINT "In Minutes: "; ACOS(0.5)END

AssociatedATAN, COS, SIN, TAN

ADVANCESPRITEPurposeAdvances a sprite a specified amount

SyntaxADVANCESPRITE( sprite, distance )

DescriptionMoves a sprite forward by the specified distance. Thedirection is set by the SETSPRITEANGLE function. This isvery useful when used with rotating sprites.

Examplepic = NEWSPRITE( 1 )LOADSPRITE("/usr/share/fuze/logo.bmp", pic,0)PLOTSPRITE( pic, gWidth / 2, gHeight / 2, 0 )FOR angle = 0 TO 360 CYCLESETSPRITEANGLE( pic, angle )ADVANCESPRITE( pic, 5 )UPDATEREPEATEND

AssociatedPLOTSPRITE, SETSPRITEANGLE

Page 63: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

63

ARMBODYPurposeMove the robot arm body.

SyntaxARMBODY(direction)

DescriptionActivates the motor in the base of the robot armaccording to the direction argument as follows:1 Move clockwise0 Stop-1 Move anti-clockwise.

ExampleREM Move the body for 2 seconds clockwiseARMBODY(1)WAIT(2)ARMBODY(0)END

AssociatedARMELBOW, ARMGRIPPER, ARMLIGHT, ARMRESET,ARMSHOULDER, ARMWRIST

ARMELBOWPurposeMove the robot arm elbow.

SyntaxARMELBOW(direction)

DescriptionActivates the motor in the elbow of the robot armaccording to the direction argument as follows:1 Move clockwise0 Stop-1 Move anti-clockwise.

ExampleREM Move the elbow for 1s anti-clockwiseARMELBOW(-1)WAIT(1)ARMELBOW(0)END

AssociatedARMBODY, ARMGRIPPER, ARMLIGHT, ARMRESET,ARMSHOULDER, ARMWRIST

Page 64: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

64

ARMGRIPPERPurposeOpen or close the robot arm gripper.

SyntaxARMGRIPPER(direction)

DescriptionActivates the motor in the gripper of the robot armaccording to the direction argument as follows:1 Open gripper0 Stop-1 Close gripper

ExampleREM Open the gripper for 1 secondsARMGRIPPER(1)WAIT(1)ARMGRIPPER(0)END

AssociatedARMBODY, ARMELBOW, ARMLIGHT, ARMRESET,ARMSHOULDER, ARMWRIST

ARMLIGHTPurposeSwitch the robot's LED on or off.

SyntaxARMLIGHT(switch)

DescriptionIf the switch argument is 1 then the LED is illuminated andif it is 0 it is switched off.

ExampleREM Flash the LED with 1 second intervalCYCLE

ARMLIGHT(1)WAIT(1)ARMLIGHT(0)WAIT(1)

REPEAT

AssociatedARMBODY, ARMELBOW, ARMGRIPPER, ARMRESET,ARMSHOULDER, ARMWRIST

Page 65: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

65

ARMRESETPurposeReset the robot arm.

SyntaxARMRESET

DescriptionStops any moving motors on the robot arm and switchesoff the LED.

ExampleARMLIGHT(1)ARMELBOW(1)WAIT(2)ARMRESETEND

AssociatedARMBODY, ARMELBOW, ARMGRIPPER, ARMLIGHT,ARMSHOULDER, ARMWRIST

ARMSHOULDERPurposeMove the robot arm shoulder.

SyntaxARMSHOULDER(direction)

DescriptionActivates the motor in the shoulder of the robot armaccording to the direction argument as follows:1 Move clockwise0 Stop-1 Move anti-clockwise.

ExampleREM Move shoulder for 1s clockwise & backARMSHOULDER(1)WAIT(1)ARMSHOULDER(-1)WAIT(1)ARMSHOULDER(0)END

AssociatedARMBODY, ARMELBOW, ARMGRIPPER, ARMLIGHT,ARMRESET, ARMWRIST

Page 66: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

66

ARMWRISTPurposeMove the robot arm wrist.

SyntaxARMWRIST(direction)

DescriptionActivates the motor in the wrist of the robot armaccording to the direction argument as follows:1 Move clockwise0 Stop-1 Move anti-clockwise.

ExampleREM Move wrist for 1s clockwise & backARMWRIST(1)WAIT(1)ARMWRIST(-1)WAIT(1)ARMWRIST(0)END

AssociatedARMBODY, ARMELBOW, ARMGRIPPER, ARMLIGHT,ARMRESET, ARMSHOULDER

ASCPurposeReturn the ASCII code for a string character.

Syntaxasciicode=ASC(string$)

DescriptionReturns the ASCII value represented by the first characterof string$ e.g. "A" would return 65. It is the opposite ofthe CHR$ function.

Examplecode=ASC("A")PRINT "ASCII value of letter A is: "; codePRINT "ASCII char of code 65: "; CHR$(code)END

AssociatedCHR$

Page 67: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

67

ASINPurposeReturns the arc sine of the supplied argument.

Syntaxangle = ASIN(sine)

DescriptionThis is the inverse of the SIN function returning the anglefor a given sine.

ExamplePRINT "Angle with sine = 0.5: "DEGREM 30 DegreesPRINT "In Degrees: ";ASIN(0.5)RADREM PI/6 RadiansPRINT "In Radians: ";ASIN(0.5)CLOCKPRINT "In Minutes: ";ASIN(0.5)END

AssociatedACOS, ATAN, COS, SIN, TAN

ATANPurposeReturns the arc tangent of the supplied argument.

Syntaxangle=ATN(tangent)

DescriptionThis is the inverse of the TAN function returning the anglefor a given tangent.

ExamplePRINT "Angle with tangent equal to 1: "DEGREM 45 DegreesPRINT "In Degrees: ";ATAN(1)RADREM PI/4 RadiansPRINT "In Radians: ";ATAN(1)CLOCKPRINT "In Minutes: ";ATAN(1)END

AssociatedACOS, ASIN, COS, SIN, TAN

Page 68: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

68

BREAKPurposeProvide an early exit from a loop.

SyntaxBREAK

DescriptionTerminates a loop before the terminating condition ismet.

ExampleREM Loop until the space bar is pressedPRINT "Press the space bar to continue"CYCLE

IF INKEY=32 THEN BREAKREPEATEND

AssociatedCONTINUE, CYCLE, CYCLE REPEAT, FOR REPEAT, REPEATUNTIL, UNTIL REPEAT, WHILE REPEAT

CHR$PurposeReturns the string character for the specified ASCII code.

Syntaxcharacter$=CHR$(asciicode)

DescriptionReturns a one-character string consisting of the charactercorresponding to the ASCII code indicated by the asciicodeargument. This is the opposite of the ASC function.

ExamplePRINT "The following print the letter A"PRINT CHR$(65)PRINT CHR$(ASC("A"))PRINT "The following print the number 3"PRINT CHR$(51)PRINT CHR$(ASC("0") + 3)END

AssociatedASC

Page 69: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

69

CIRCLEPurposeDraw a circle on the screen.

SyntaxCIRCLE(centrex,centrey,radius,fill)

DescriptionDraws a circle at position (centrex,centrey) with thespecified radius in the current foreground COLOUR. Thefinal parameter fill is either TRUE or FALSE, and specifiesfilled (TRUE) or outline (FALSE).

ExampleCLSPRINT "Draw a filled yellow circle ";PRINT "In the centre of the screen"COLOUR=yellowCIRCLE(GWIDTH/2,GHEIGHT/2,100,TRUE)UPDATEEND

AssociatedELLIPSE, RECT, TRIANGLE

CLEARKEYBOARDPurposeClear all pending keyboard input.

SyntaxCLEARKEYBOARD

DescriptionClears the keyboard input buffer.

ExamplePRINT "Press space to continue"WHILE NOT SCANKEYBOARD(scanSpace) CYCLEREPEATCLEARKEYBOARDEND

AssociatedSCANKEYBOARD

Page 70: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

70

CLOCKPurposeSet angle units to minutes.

SyntaxCLOCK

DescriptionSwitches the internal angle system to clock mode. Thereare 60 minutes in a full circle.

ExamplePRINT "ATAN(1) = "DEGPRINT ATAN(1); " Degrees"CLOCKPRINT ATAN(1); " Minutes"RADPRINT ATAN(1); " Radians"END

AssociatedDEG, RAD

CLOSEPurposeClose a file after use.

SyntaxCLOSE(handle)

DescriptionThe CLOSE instruction closes the file specified by handleafter use and makes sure all data is securely written to thestorage medium.

Examplehandle = OPEN("testfile.txt")PRINT# handle, "Colin"CLOSE(handle)handle = OPEN("testfile.txt")INPUT# handle, Name$CLOSE(handle)PRINT "Name: " + Name$END

AssociatedEOF, FFWD, INPUT#, OPEN, PRINT#, REWIND, SEEK

Page 71: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

71

CLS2PurposeClear screen without an update.

SyntaxCLS2

DescriptionIdeally suited to games and graphical programming. CLS2clears the background or buffer screen and does not issue anupdate command. This means you can wipe the screen buffer,redraw on it and then issue an update. This ensures flicker freeupdates. It is also much faster than CLS.

Examplew = GWIDTHy = GHEIGHT / 2radius = w / 10FOR x = 0 TO w STEP radius CYCLECLS

COLOUR = PINKCIRCLE (x, y, radius, 1)UPDATE

REPEATFOR x = w TO 0 STEP -10 CYCLE

CLS2COLOUR = YELLOWCIRCLE (x, y, radius, 1)UPDATE

REPEATEND

AssociatedCLS, UPDATE

Page 72: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

72

COLOURPurposeSet/Read the current graphics plot colour.

SyntaxCOLOUR=setcolourgetcolour=COLOUR

DescriptionSet/Read the current graphics plot colour as follows:Black = 0, Navy = 1, Green = 2, Teal = 3, Maroon = 4,Purple = 5, Olive = 6, Silver = 7, Grey = 8, Blue = 9, Lime =10, Aqua = 11, Red = 12, Pink = 13, Yellow = 14, White = 15.

ExampleCLSFOR c=0 TO 15 CYCLE

COLOUR=cCIRCLE(50,GHEIGHT-c*40-50,20,TRUE)COLOUR=WHITECIRCLE(50,GHEIGHT-c*40-50,20,FALSE)READ NameOfColour$HVTAB(5,c*2+2)PRINT NameOfColour$;" ";c

REPEATUPDATEDATA "Black","Navy","Green","Teal"DATA "Maroon","Purple","Olive","Silver"DATA "Grey","Blue","Lime","Aqua","Red"DATA "Pink","Yellow","White"END

AssociatedINK, PAPER, RGBCOLOUR

Page 73: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

73

COPYREGIONPurposeCopy a region of the screen from one location to another.

SyntaxCOPYREGION(oldx,oldy,width,height,newX,newY)

DescriptionThis enables you to duplicate the contents of a section ofthe screen from one place to another. This could be usedfor example to create a background for a game bydrawing an image and then duplicating it. The region to becopied is specified by the rectangle at coordinates(oldx,oldy) width pixels wide and height pixelshigh. The region is copied to coordinates (newx,newy)

ExampleREM Draws a Brick WallCOLOUR=REDRECT(0,0,50,50,TRUE)COLOUR=WHITELINE(0,50,50,50)LINE(0,25,50,25)LINE(0,25,0,50)LINE(50,25,50,50)LINE(25,0,25,25)LINE(0,0,50,0)FOR X=0 TO GWIDTH STEP 50 CYCLE

FOR Y=0 TO GHEIGHT STEP 50 CYCLECOPYREGION(0,0,50,50,X,Y)

REPEATREPEATUPDATEEND

AssociatedGRABREGION

Page 74: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

74

COSPurposeReturns the cosine of the given angle.

Syntaxcosine=COS(angle)

DescriptionReturns the cosine of the argument angle. This is the ratioof the side of a right angled triangle, that is adjacent tothe angle, to the hypotenuse (the longest side).

ExampleCLSPRINT "Draw ellipse in screen centre"DEGFOR Angle=0 TO 360 CYCLE

Xpos=100*COS(Angle)+GWIDTH / 2Ypos=50*SIN(Angle)+GHEIGHT / 2PLOT(Xpos, Ypos)

REPEATEND

AssociatedACOS, ASIN, ATAN, SIN, TAN

CYCLEPurposeDefines the start of a block of code to be repeated.

SyntaxCYCLE

DescriptionMarks the start of a block of repeating code (called aloop). The number of times that the loop is executeddepends on the command used before CYCLE or at theend of the loop.

ExampleREM See Associated commands below.

AssociatedBREAK, CONTINUE, CYCLE REPEAT, FOR REPEAT, REPEATUNTIL, UNTIL REPEAT, WHILE REPEAT

Page 75: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

75

CYCLE REPEATPurposeCreate an infinite loop.

SyntaxCYCLE

{statements}REPEAT

DescriptionExecute the statements again and again forever.The BREAK command can be used to terminate the loopor control can be explicitly transferred to somewhereoutside of the loop by commands like GOTO (notrecommended).Pressing the Esc key will also interrupt the loop (andprogram).

ExampleREM Loop until the space bar is pressedPRINT "Press the space bar to continue"CYCLE

IF INKEY = 32 THEN BREAKREPEATEND

AssociatedBREAK, CONTINUE, CYCLE, FOR REPEAT, REPEAT UNTIL,UNTIL REPEAT, WHILE REPEAT

DATAPurposeStore constant data.

SyntaxDATA constant{,constant}

DescriptionStores numerical and string constants for later retrievalusing the READ command.

ExampleREM Load the name of the days of theREM week into a string arrayDATA "Monday", "Tuesday", "Wednesday"DATA "Thursday", "Friday", "Saturday"DATA "Sunday"DIM DaysOfWeek$(7)FOR DayNo=1 TO 7 CYCLE

READ DaysOfWeek$(DayNo)REPEATFOR DayNo=1 TO 7 CYCLE

PRINT "Day of the week number ";DayNo;PRINT " is ";DaysOfWeek$(DayNo)

REPEATEND

AssociatedREAD, RESTORE

Page 76: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

76

DATE$PurposeReturn the current date.

Syntaxtodaysdate$ = DATE$

DescriptionThis returns a string with the current date in the format:YYYY-MM-DD. For example: 2015-03-24.

ExamplePRINT "Today is ";FN FormatDate(DATE$)END

DEF FN FormatDate()DayNo=VAL(RIGHT$(DATE$, 2))MonthNo=VAL(MID$(DATE$, 5, 2))Year$=LEFT$(DATE$,4)SWITCH (DayNo MOD 10)

CASE 1DaySuffix$ = "st"

ENDCASECASE 2DaySuffix$ = "nd"

ENDCASECASE 3DaySuffix$ = "rd"

ENDCASEDEFAULTDaySuffix$ = "th"

ENDCASEENDSWITCHFOR I=1 TO MonthNo CYCLE

READ MonthName$REPEATResult$=STR$(DayNo)+DaySuffix$+" "

=Result$+MonthName$+" "+Year$DATA "January","February","March","April"DATA "May","June","July","August"DATA "September","October","November"DATA "December"

AssociatedTIME$

Page 77: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

77

DEF FNPurposeCreate a user defined function.

SyntaxDEF FN name({parameter}{,parameter})

{commands}=value

DescriptionUser defined functions are similar to user definedprocedures except that they can return a value. This canbe either a number or a character string.

ExampleREM Function test - print squaresFOR I=1 TO 10 CYCLE

x=FN square(I)PRINT I; " squared is "; xREPEATENDDEF FN square(num)

LOCAL resultresult=num*num

=result

AssociatedFN, LOCAL

DEF PROCPurposeCreate a user defined procedure.

SyntaxDEF PROC name({parameter}{,parameter})

{commands}ENDPROC

DescriptionAllows you to create your own routines that can be called bytheir label. Once you have written a procedure to do aparticular task you can copy it into other programs that requireit. Procedures are usually defined after the END of theprogram.

ExampleCLSPROC Hexagon(200,200,100,Red)UPDATEENDDEF PROC Hexagon(x,y,l,c)

PENUPMOVETO(x-l*COS(30),y+l/2)COLOUR = cPENDOWNFOR I=1 to 6 CYCLERIGHT(60)MOVE(l)

REPEATENDPROC

AssociatedLOCAL, PROC

Page 78: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

78

DEFCHARPurposeDefine a new font character.

SyntaxDEFCHAR(char,line1 … line10)

DescriptionCreate a user defined font character. The char parameteris the position of the character within the font (0-255) e.g.65 is the capital letter A in ASCII. The character consists of10 lines with 8 pixels in each line. These are set by thecorresponding bits in each of the line parameters. So forexample decimal 170 (binary 10101010) would setalternate pixels on the corresponding line of the character.

ExampleREM Define Chessboard CharacterFONTSCALE(10,10)DEFCHAR(2,0,85,170,85,170,85,170,85,170,0)PRINT CHR$(2)END

AssociatedCHR$

DEGPurposeSet angle units to degrees.

SyntaxDEG

DescriptionSwitches the internal angle system to degree mode. Thereare 360 degrees in a full circle.

ExampleREM Draw an ellipse in the screen centreCLSDEGFOR Angle = 0 TO 360 CYCLE

Xpos=100*COS(Angle)+GWIDTH / 2Ypos=50*SIN(Angle)+GHEIGHT / 2PLOT(Xpos, Ypos)

REPEATEND

AssociatedCLOCK, RAD

Page 79: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

79

DIGITALREADPurposeRead the state of a digital pin on the Raspberry Pi.

Syntaxpinvalue=DIGITALREAD(pinno)

DescriptionReads the state of a digital pin on the Raspberry Pi. Youmay need to set the pin mode beforehand to make sureit’s configured as an input device. It will return TRUE orFALSE to indicate an input being high or low respectively.

ExampleREM Set pin 12 to inputPINMODE(12,0)REM Wait for button to be pushedUNTIL DIGITALREAD(12) CYCLEREPEATPRINT "Button Pushed"END

AssociatedDIGITALWRITE, PINMODE, PWMWRITE

DIGITALWRITEPurposeSet the state of a digital pin on the Raspberry Pi.

SyntaxDIGITALWRITE(pinno,pinvalue)

DescriptionThis procedure sets a digital pin to the supplied value - 0for off or 1 for on. As with DigitalRead, you may need toset the pin mode (to output) beforehand.

ExampleREM Flash LED attached to pin2 of GPIOREM Set pin 2 to output modePINMODE(2,1)CYCLE

REM Set output High (on)DIGITALWRITE(2,1)WAIT(1)REM Set output Low (off)DIGITALWRITE(2,0)WAIT(1)

REPEATEND

AssociatedDIGITALREAD, PINMODE, PWMWRITE

Page 80: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

80

DIMPurposeDimension an array of variables.

SyntaxDIM variable(dimension{,dimension})

DescriptionCreates an indexed variable with one or more dimensions.The variable can be either a numeric or character stringtype (they cannot hold mixed values). The index is anumber from 0 to the size of the dimension.Associative arrays (sometimes called maps) are anotherway to refer to the individual elements of an array. In theexample below we use a number, however strings arealso allowed. They can be multi-dimensional and you canfreely mix numbers and strings for the array indices.

ExampleREM Initialise the squares of a chessREM board to black or whiteDIM ChessBoard(8,8)Count=0FOR Row=1 TO 8 CYCLE

FOR Col=1 TO 8 CYCLECount=Count+1IF Count MOD 2=1 THEN

ChessBoard(Row,Col) = BlackELSE

ChessBoard(Row,Col) = WhiteENDIF

REPEATREPEATPRINT ChessBoard(1,4)END

Page 81: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

81

DRCANALOGREADPurposeRead an analog channel on a DRC device.

Syntaxvoltage=DRCANALOGREAD(handle,pin)

DescriptionThis function reads an analog channel on a DRCcompatible device specified by handle and returns theresult. The value returned will depend on the hardwareyou’re connected to - for example the Arduino will returna number from 0 to 1023 representing an input voltagebetween 0 and 5 volts. Other devices may have differentranges.

Examplearduino=DRCOPEN("/dev/ttyUSB0")REM Get voltage on pin 4voltage=DRCANALOGREAD(arduino, 4)/1023*5PRINT "Voltage= "; voltageDRCCLOSE(arduino)END

AssociatedDRCCLOSE, DRCDIGITALREAD, DRCDIGITALWRITE,DRCOPEN, DRCPINMODE, DRCPWMWRITE

DRCCLOSEPurposeClose a connection to a DRC compatible device.

SyntaxDRCCLOSE(handle)

DescriptionThis closes a connection to a DRC device and frees up anyresources used by it. It’s not strictly necessary to do thiswhen you end your program, but it is considered goodpractice.

Examplearduino = DRCOPEN("/dev/ttyUSB0")REM Set pin 12 to inputDRCPINMODE(arduino, 12, 0)CYCLEREPEAT UNTIL DRCDIGITALREAD(arduino, 12)PRINT "Button Pushed"DRCCLOSE(arduino)END

AssociatedDRCANALOGREAD, DRCDIGITALREAD, DRCDIGITALWRITE,DRCOPEN, DRCPINMODE, DRCPWMWRITE

Page 82: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

82

DRCDIGITALREADPurposeRead the state of a digital pin on a remote DRC device.

Syntaxstate=DRCDIGITALREAD(handle,pin)

DescriptionThis function allows you to read the state of a digital pinon a DRC device specified by handle. You may need to setthe pin mode beforehand to make sure it’s configured asan input device. It will return TRUE or FALSE to indicate aninput being high or low respectively.

Examplearduino = DRCOPEN("/dev/ttyUSB0")REM Set pin 12 to inputDRCPINMODE(arduino, 12, 0)CYCLEREPEAT UNTIL DRCDIGITALREAD(arduino, 12)PRINT "Button Pushed"DRCCLOSE(arduino)END

AssociatedDRCANALOGREAD, DRCCLOSE, DRCDIGITALWRITE,DRCOPEN, DRCPINMODE, DRCPWMWRITE

DRCDIGITALWRITEPurposeSet a digital pin on a remote DRC device to the suppliedvalue.

SyntaxDRCDIGITALWRITE(handle,pin,value)

DescriptionThis procedure sets a digital pin on a DRC device specifiedby handle to the supplied value - 0 for off or 1 for on. Aswith DrcDigitalRead, you may need to set the pin modebeforehand.

Examplearduino=DRCOPEN("/dev/ttyUSB0")REM Set pin 2 to output modeDRCPINMODE(arduino, 2, 1)REM Set Output High (on)DRCDIGITALWRITE(arduino, 2, 1)REM Pause for 1 secondWAIT(1)REM Set output Low (off)DRCDIGITALWRITE(arduino, 2, 0)DRCCLOSE(arduino)END

AssociatedDRCANALOGREAD, DRCCLOSE, DRCDIGITALREAD,DRCOPEN, DRCPINMODE, DRCPWMWRITE

Page 83: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

83

DRCOPENPurposeOpen a connection to a DRC compatible device.

Syntaxhandle=DRCOPEN(drcdevice)

DescriptionThis opens a connection to a DRC compatible device andmakes it available for our use. It takes the name of thedevice as an argument and returns a number (the handle)of the device. We can use this handle to reference thedevice and allow us to open several devices at once. Someimplementations may have IO devices with fixed names.

Examplearduino = DRCOPEN("/dev/ttyUSB0")REM Set pin 12 to inputDRCPINMODE(arduino, 12, 0)CYCLEREPEAT UNTIL DRCDIGITALREAD(arduino, 12)PRINT "Button Pushed"DRCCLOSE(arduino)END

AssociatedDRCANALOGREAD, DRCCLOSE, DRCDIGITALREAD,DRCDIGITALWRITE, DRCPINMODE, DRCPWMWRITE

DRCPINMODEPurposeConfigure the mode of a pin on a remote DRC device.

SyntaxDRCPINMODE(handle,pin,mode)

DescriptionThis configures the mode of a pin on the DRC device specifiedby handle. It takes an argument which specifies the mode ofthe specified pin - input, output or PWM output. Other modesmay be available, depending on the device and its capabilities.Note that not all devices support all functions. The modes are:0 pinINPUT1 pinOUTPUT2 pinPWM

Examplearduino = DRCOPEN("/dev/ttyUSB0")REM Set pin 12 to inputDRCPINMODE(arduino, 12, 0)CYCLEREPEAT UNTIL DRCDIGITALREAD(arduino, 12)PRINT "Button Pushed"DRCCLOSE(arduino)END

AssociatedDRCANALOGREAD, DRCCLOSE, DRCDIGITALREAD,DRCDIGITALWRITE, DRCOPEN, DRCPWMWRITE

Page 84: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

84

DRCPWMWRITEPurposeOutput a PWM waveform on the selected pin of a DRCdevice.

SyntaxDRCPWMWRITE(handle,pin,value)

DescriptionThis procedure outputs a PWM waveform on the specifiedpin of a DRC compatible device specified by handle. Thepin must be configured for PWM mode beforehand, anddepending on the device you are using, then not all pinson a device may support PWM mode. The value setshould be between 0 and 255.

Examplearduino=DRCOPEN("/dev/ttyUSB0")REM Set pin 11 to PWM output modeDRCPINMODE(arduino, 11, 2)DRCPWMWRITE(arduino, 11, 200)DRCCLOSE(arduino)END

AssociatedDRCANALOGREAD, DRCCLOSE, DRCDIGITALREAD,DRCDIGITALWRITE, DRCOPEN, DRCPINMODE

ELLIPSEPurposeDraw an ellipse on the screen.

SyntaxELLIPSE(xpos,ypos,xradius,yradius,fill)

DescriptionDraws an ellipse centred at position (xpos,ypos) with thespecified xradius and yradius in the current foregroundCOLOUR. The final parameter fill is either TRUE or FALSE,and specifies filled (TRUE) or outline (FALSE).

ExampleCLSREM Draw a filled red ellipse atREM location 200,200COLOUR=redELLIPSE(200,200,100,50,TRUE)UPDATEEND

AssociatedCIRCLE, RECT, TRIANGLE

Page 85: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

85

ELSEPurposeExecute statement(s) when a tested condition is False.

SyntaxIF condition THEN{statements}ELSE{statements}ENDIF

ExampleNumber = 13IF Number MOD 2 = 0 THEN

PRINT "Number is Even"ELSE

PRINT "Number is Odd"ENDIFEND

AssociatedENDIF, IF THEN

ENDPurposeEnd program execution.

SyntaxEND

DescriptionProgram execution is ended. Programs must terminatewith the END or STOP commands or an error will occur.

ExamplePRINT "Hello World"END

Page 86: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

86

ENDIFPurposeTerminate a multiline conditional statement.

SyntaxIF condition THEN{statements}ENDIF

DescriptionWe can extend the IF statement over multiple lines, ifrequired. The way you do this is by making sure there isnothing after the THEN statement and ending it all withthe ENDIF statement.

ExampleDayOfWeek = 5IF DayOfWeek < 6 THEN

PRINT "It is a Weekday"PRINT "Go to Work!"

ENDIFEND

AssociatedELSE, IF THEN

ENDPROCPurposeDefines the end of a PROCedure

SyntaxENDPROC

DescriptionEnd a PROCedure and return to the next command afterthe procedure was called.

ExampleCLSPROC helloENDDEF PROC helloPRINTAT (10,10); "Hello"ENDPROC

AssociatedPROC

Page 87: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

87

ENVELOPEPurposeEmulate the BBC BASIC sound envelope command.

SyntaxENVELOPE(N,T,PI1,P12,PI3,PN1,PN2,PN3,AA,AD,AS,AR,ALA,ALD)

DescriptionNOTE: This is an experimental function. It might notperform entirely as expected. It is also prone to crashingif incorrect values are used. Use with caution!

N 1 to 8 Envelope number.

T 0 to 127 Length of each step in hundredths of a second.Add 128 to cancel auto repeat of the pitch envelope.

PI1 −128 to 127 Pitch change per step in section 3PI2 −128 to 127 Change of pitch per step in section 2PI3 −128 to 127 Change of pitch per step in section 1PN1 0 to 255 Number of steps in section 1PN2 0 to 255 Number of steps in section 2PN3 0 to 255 Number of steps in section 3AA −127 to 127 Change of attack amplitude per stepAD −127 to 127 Change of decay amplitude per stepAS −127 to 0 Change of sustain amplitude per stepAR −127 to 0 Change of release amplitude per stepALA 0 to 126 Level at end of the attack phaseALD 0 to 126 Level at end of the decay phase

ExampleENVELOPE(1,2,-2,10,1,80,40,40,127,0,0,0,126,126)SOUND(1, 1, 53, 64)END

AssociatedSOUND

Page 88: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

88

EOFPurposeReturn true if the end of an input file has been reached.

Syntaxendoffile=EOF(handle)

DescriptionThe EOF function returns a TRUE or FALSE indication ofthe state of the file pointer when reading the file. It is anerror to try to read past the end of the file, so if you arereading a file with unknown data in it, then you mustcheck at well defined intervals (e.g. Before each INPUT#).

Examplehandle=OPEN("eoftest.txt")FOR r = 0 TO 10 CYCLE

PRINT# handle, "Record "; rREPEATCLOSE (handle)handle = OPEN("eoftest.txt")WHILE NOT EOF (handle) CYCLE

INPUT# handle, record$PRINT record$

REPEATCLOSE (handle)END

AssociatedCLOSE, FFWD, INPUT#, OPEN, PRINT#, REWIND, SEEK

EXPPurposeReturn the exponential value of the specified number.

Syntaxexponential=EXP(number)

DescriptionReturns the exponential value of the specified number.This is e to the power of number where e is theexponential constant (approximately 2.718281828). Theexponential function arises whenever a quantity grows ordecays at a rate proportional to its current value. This isthe opposite of the LOG function i.e. EXP(LOG(X)) = X

ExampleREM prints 2.718281828PRINT EXP(1)REM prints 22026.46579PRINT EXP(10)REM prints 10PRINT LOG(EXP(10))END

AssociatedLOG

Page 89: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

89

FADEOFFPurposeFade the display from light to dark

SyntaxFADEOFF

DescriptionFADEOFF initiates a fade from light to dark. The entirescreen display is affected.

ExamplePAPER=0INK=1CLSPRINT "LOADING..."FADEOFFWHILE FADING = true CYCLE

UPDATEREPEATFADEONWHILE FADING = true CYCLE

UPDATEREPEATEND

AssociatedFADEON, FADING

FADEONPurposeFade the display from dark to light

SyntaxFADEON

DescriptionFADEON initiates a fade from dark to light. The entirescreen display is affected.

ExamplePAPER=0INK=1CLSPRINT "LOADING..."FADEOFFWHILE FADING = true CYCLE

UPDATEREPEATFADEONWHILE FADING = true CYCLE

UPDATEREPEATEND

AssociatedFADEOFF, FADING

Page 90: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

90

FFWDPurposeMove the file pointer to the end of a file.

SyntaxFFWD(handle)

DescriptionMove the file pointer back to the end of the file specifiedby handle. If you want to append data to the end of anexisting file, then you need to call FFWD before writingthe data.

Examplehandle=OPEN("ffwdtest.txt")PRINT# handle, "First Line"CLOSE (handle)handle = OPEN ("ffwdtest.txt")FFWD (handle)PRINT# handle, "Appended line"CLOSE (handle)handle = OPEN("ffwdtest.txt")WHILE NOT EOF (handle) CYCLE

INPUT# handle, record$PRINT record$

REPEATCLOSE (handle)END

AssociatedCLOSE, EOF, INPUT#, OPEN, PRINT#, REWIND, SEEK

FNPurposeCall a user defined function.

Syntaxresult=FN name({argument}{,argument})

DescriptionCalls the specified user defined function called name withthe specfied arguments. The returned result can then beused by the program. Once the function has beenexecuted control returns to the command following.

ExamplePRINT FN SphereVolume(10)ENDREM Function calculate volume of a sphereREM with radius rDEF FN SphereVolume(r)= (4/3)*PI*r*r*r

AssociatedDEF FN

Page 91: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

91

FONTSCALEPurposeScale the text font.

SyntaxFONTSCALE(xscale,yscale)

DescriptionChange the size of the text font. The font is scaled byxscale horizontally and yscale vertically. If the numbersare different it will appear stretched.

ExampleFOR S=1 TO 10 CYCLE

FONTSCALE(S,S)PRINT "Hello World"

REPEATEND

AssociatedPRINTAT

FOR REPEATPurposeLoop a specified number of times using a counter.

SyntaxFOR count=start TO end [STEP step] CYCLE

statementsREPEAT

DescriptionThe count variable is initially set to start and changes by stepeach time around the loop until count is greater than or equalto end. The optional step, which defaults to 1 may be lessthan zero to count backwards. The end of the loop is indicatedusing the REPEAT.

ExampleREM year into a string arrayDATA "January", "February", "March"DATA "April", "May", "June"DATA "July", "August", "September"DATA "October", "November", "December"DIM Months$(12)FOR Month = 1 TO 12 CYCLE

READ Months$(Month)REPEATPRINT "The seventh month is ";Months$(7)END

AssociatedBREAK, CONTINUE, CYCLE, CYCLE REPEAT, REPEAT UNTIL,UNTIL REPEAT, WHILE REPEAT

Page 92: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

92

FREEIMAGEPurposeRelease an image from memory

SyntaxFREEIMAGE(handle)

DescriptionFrees up the memory space taken up by a stored image

Examplehandle = LOADIMAGE( "sprite1.bmp" )PLOTIMAGE( handle, 0, 0 )UPDATEFREEIMAGE( handle )handle = LOADIMAGE( "sprite2.bmp" )PLOTIMAGE( handle, 100, 100 )UPDATEEND

AssociatedLOADIMAGE, PLOTIMAGE

GETIMAGEHPurposeGet the pixel height of a loaded image.

SyntaxGETIMAGEH(handle)

DescriptionGets the height in pixels of a loaded image

ExampleREM Centre image on screenlogo=LOADIMAGE("/usr/share/fuze/logo.bmp")imageW=GETIMAGEW(logo)imageH=GETIMAGEH(logo)X=(GWIDTH-imageW)/2Y=(GHEIGHT-imageH)/2PLOTIMAGE(logo,X,Y)UPDATEEND

AssociatedGETIMAGEW, LOADIMAGE, PLOTIMAGE

Page 93: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

93

GETIMAGEWPurposeGet the pixel width of a loaded image.

SyntaxGETIMAGEW(handle)

DescriptionGets the width in pixels of an image previously loadedusing LOADIMAGE (using the handle returned byLOADIMAGE).

ExampleREM Centre image on screenlogo=LOADIMAGE("/usr/share/fuze/logo.bmp")imageW=GETIMAGEW(logo)imageH=GETIMAGEH(logo)X=(GWIDTH-imageW)/2Y=(GHEIGHT-imageH)/2PLOTIMAGE(logo,X,Y)UPDATEEND

AssociatedGETIMAGEH, LOADIMAGE, PLOTIMAGE

GETMOUSEPurposeRead values from an attached mouse

SyntaxGETMOUSE(xpos,ypos,buttons)

DescriptionThis reads values for the current state of the mouse. xpos is thehorizontal mouse position, ypos is the vertical position andbuttons is the state of the mouse buttons. You can testwhether the left button has been pressed by using the logical &operator to see if bit 0 of the buttons value is set: buttons & 1will be TRUE. Likewise if the right button is pressed then bit 3will be set and buttons & 4 will be TRUE.

ExampleCLSMOUSEONCYCLE

GETMOUSE(x,y,b)LINETO(x,y)UPDATEREM Cycle colour if left button pressedIF b & 1 THEN

COLOUR = COLOUR MOD 16 + 1ENDIFREM Exit if right button pressed

REPEAT UNTIL b & 4MOUSEOFFENDAssociatedMOUSEOFF, MOUSEON, MOUSEX, MOUSEY, SETMOUSE

Page 94: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

94

GETPIXELPurposeReturn the colour of the specified pixel.

Syntaxcolour = GETPIXEL(xpos, ypos)

DescriptionThis returns the internal colour code (0-15) of the pixel atthe specified point (xpos,ypos). This is for the "named"colours - e.g. Red, Green etc. It returns -1 if the pixelcolour is not a standard colour - in which case, you needto use GETPIXELRGB.

ExampleCLSCOLOUR = REDXpos = GWIDTH / 2Ypos = GHEIGHT / 2PLOT(Xpos, Ypos)PRINT GETPIXEL(Xpos, Ypos)END

AssociatedGETPIXELRGB

GETPIXELRGBPurposeReturn the RGB colour of the specified pixel.

SyntaxRGBcolour = GETPIXELRGB(xpos, ypos)

DescriptionThis returns the RGB colour of the pixel at the specified point(xpos,ypos). This will return a 24-bit value.

ExampleCLSRGBCOLOUR(49, 101, 206)Xpos = GWIDTH / 2Ypos = GHEIGHT / 2CIRCLE(Xpos, Ypos, 50, TRUE)pixel = GETPIXELRGB(Xpos, Ypos)PRINT "RGB = "; pixelPRINT "Red = "; (pixel >> 16) & 0xFFPRINT "Green = "; (pixel >> 8) & 0xFFPRINT "Blue = "; (pixel >> 0) & 0xFFEND

AssociatedGETPIXEL

Page 95: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

95

GETSPRITEHPurposeGet the pixel height of a sprite.

SyntaxGETSPRITEH(spriteIndex)

DescriptionReturns the height in pixels of the sprite with the specifiedspriteIndex.

ExampleREM Centre sprite on the screenindex=NEWSPRITE(1)fuzelogo$="/usr/share/fuze/logo.bmp"LOADSPRITE(fuzelogo$,index,0)spriteW=GETSPRITEW(index)spriteH=GETSPRITEH(index)X=(GWIDTH-spriteW)/2Y=(GHEIGHT-spriteH)/2PLOTSPRITE(index,X,Y,0)UPDATEEND

AssociatedGETSPRITEW, HIDESPRITE, LOADSPRITE, NEWSPRITE,PLOTSPRITE, SETSPRITETRANS, SPRITECOLLIDE,SPRITECOLLIDEPP

GETSPRITEWPurposeGet the pixel width of a sprite.

SyntaxGETSPRITEW(spriteIndex)

DescriptionReturns the width in pixels of the sprite with the specifiedspriteIndex.

ExampleREM Centre sprite on the screenindex=NEWSPRITE(1)fuzelogo$="/usr/share/fuze/logo.bmp"LOADSPRITE(fuzelogo$,index,0)spriteW=GETSPRITEW(index)spriteH=GETSPRITEH(index)X=(GWIDTH-spriteW)/2Y=(GHEIGHT-spriteH)/2PLOTSPRITE(index,X,Y,0)UPDATEEND

AssociatedGETSPRITEH, HIDESPRITE, LOADSPRITE, NEWSPRITE,PLOTSPRITE, SETSPRITETRANS, SPRITECOLLIDE,SPRITECOLLIDEPP

Page 96: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

96

GRABREGIONPurposeGrab a region of the screen to a temporary buffer

Syntaxhandle = GRABREGION(x, y, width, height)

DescriptionGrab a region of the screen with x and y as the locationand with width and height in pixels. The region can berecalled by its handle and pasted using PLOTIMAGE.

ExampleFOR n = 0 TO 15 CYCLERECT(0,n*GHEIGHT/16, GWIDTH, GHEIGHT/16,1)REPEAThandle=GRABREGION(0,0,200,200)CLSPLOTIMAGE(handle, GWIDTH/2, GHEIGHT/2)UPDATEEND

AssociatedCOPYREGION, FREEIMAGE, LOADIMAGE, PLOTIMAGE,SAVEREGION, SAVESCREEN, SCROLLDOWN, SCROLLLEFT,SCROLLRIGHT, SCROLLUP

HIDESPRITEPurposeRemove a sprite from the screen.

SyntaxHIDESPRITE(spriteindex)

DescriptionThis removes the sprite at the specified spriteindex from thescreen. You do not have to erase a sprite from the screen whenyou move it, just call PLOTSPRITE with the new coordinates.

ExampleCLSfuzelogo$="/usr/share/fuze/logo.bmp"s1=NEWSPRITE(1)s2=NEWSPRITE(1)LOADSPRITE(fuzelogo$,s1,0)LOADSPRITEfuzelogo$,s2,0)PLOTSPRITE(s1,100,100,0)PLOTSPRITE(s2,200,200,0)UPDATEWAIT(2)REM Remove a sprite from the screenHIDESPRITE(s2)UPDATEEND

AssociatedGETSPRITEH, GETSPRITEW, LOADSPRITE, NEWSPRITE,PLOTSPRITE, SPRITECOLLIDE, SPRITECOLLIDEPP, SPRITEOUT

Page 97: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

97

HLINEPurposeDraw a horizontal line.

SyntaxHLINE(xpos1, xpos2, ypos)

DescriptionDraws a horizontal line on row y, from column xpos1to column xpos2.

ExampleCLSCOLOUR=redFOR ypos=0 TO GHEIGHT STEP 100 CYCLE

HLINE(0,GWIDTH,ypos)REPEATUPDATEEND

AssociatedLINE, LINETO, VLINE

HTABPurposeSet/Read the current text cursor horizontal position.

SyntaxHTAB=valuevalue=HTAB

DescriptionSet/Read the current text cursor horizontal position.

ExampleCLSFOR xpos = 0 TO TWIDTH STEP 2 CYCLE

HTAB=xposPRINT HTAB

REPEATEND

AssociatedHVTAB, VTAB

Page 98: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

98

HVTABPurposeMove the current text cursor to the specified position.

SyntaxHVTAB(xpos,ypos)

DescriptionThe cursor is moved to the supplied column xpos and lineypos. Note that (0,0) is top-left of the text screen.

ExampleCLSHVTAB(TWIDTH/2-3,THEIGHT/2)PRINT "CENTRE"HVTAB(0,0)END

AssociatedHTAB, VTAB

IF THENPurposeExecute a statement conditionally.

SyntaxIF condition THEN {statement}

DescriptionThe statement is executed when the condition evaluatesto TRUE (not 0). Unlike some implementations of BASICthe THEN is required.

ExamplePRINT "Press Space Bar to Continue"CYCLE

IF INKEY = 32 THEN BREAKREPEATPRINT "Space Bar Pressed"END

AssociatedELSE, ENDIF, SWITCH

Page 99: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

99

INKEYPurposeGet a single character code from the keyboard withoutpausing.

Syntaxasciicode=INKEY

DescriptionThis is similar to GET except that program execution is notpaused; If no key is pressed, then -1 is returned. The followingconstants are predefined to test for special keys: KeyUp,KeyDown, KeyLeft, KeyRight, KeyIns, KeyHome, KeyDel,KeyEnd, KeyPgUp, KeyPgDn, KeyF1, KeyF2, KeyF3, KeyF4,KeyF5, KeyF6, KeyF7, KeyF8, KeyF9, KeyF10, KeyF11, KeyF12.

ExampleREM Show the ASCII code for the last keypressedLastKey = -1REM Press Esc to QuitCYCLE

Key=INKEYIF Key<>-1 AND Key<>LastKey THEN

PRINT "Key Pressed: "; KeyLastKey = Key

ENDIFREPEAT

AssociatedGET, INPUT, SCANKEYBOARD

INPUTPurposeRead data from the keyboard into a variable.

SyntaxINPUT [prompt$,] variable

DescriptionWhen FUZE BASIC encounters the INPUT statement,program execution stops, a question mark(?) is printedand it waits for you to type something. It then assignswhat you typed to the variable. If you typed in a stringwhen it was expecting a number, then it will assign zero tothe number. To stop it printing the question mark, youcan optionally give it a string to print.

ExampleINPUT "What is your Name? ", Name$PRINT "Hello " + Name$END

AssociatedINKEY

Page 100: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

100

INPUT#PurposeRead data from a file.

SyntaxINPUT# handle,variable

DescriptionThis works similarly to the regular INPUT instruction, butreads from the file identified by the supplied handlerather than from the keyboard. Note that unlike theregular keyboard INPUT instruction, INPUT# can only readone variable at a time.

Examplehandle=OPEN("testfile.txt")PRINT# handle,"Hello World"REWIND(handle)INPUT# handle,record$PRINT record$CLOSE (handle)END

AssociatedCLOSE, EOF, FFWD, OPEN, PRINT#, REWIND, SEEK

INTPurposeReturn the integer part of a number.

Syntaxintegerpart=INT(number)

DescriptionReturns the integer part of the specified number.

ExamplePRINT "The integer part of PI is ";PRINT INT(PI)END

Page 101: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

101

LEFTPurposeTurns the turtle to the left (counter clockwise) by thegiven angle.

SyntaxLEFT(angle)

DescriptionTurns the virtual graphics turtle to the left (counterclockwise) by the given angle in the current angle units.

ExampleREM Draw a box using turtle graphicsCLSCOLOUR=REDMOVE(50)DEGLEFT(90)MOVE(50)PENDOWNFOR I = 1 TO 4 CYCLE

LEFT(90)MOVE(100)

REPEATUPDATEEND

AssociatedMOVE, MOVETO, PENDOWN, PENUP, RIGHT, TANGLE

LEFT$PurposeReturn the specified leftmost number of a characters froma string.

Syntaxsubstring$=LEFT$(string$,number)

DescriptionReturns a substring of string$ with number charactersfrom the left (start) of the string. If number is greater thanor equal to the length of string$ then the whole string isreturned.

Examplestring$="The quick brown fox"FOR I=1 TO 20 CYCLE

PRINT LEFT$(string$, I)REPEATEND

AssociatedMID$, RIGHT$

Page 102: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

102

LENPurposeReturn the length of the specified character string.

Syntaxlength=LEN(string$)

DescriptionReturns the number of characters in the specified string$.

ExampleString$="The Quick Brown Fox"Chars=LEN(String$)PRINT "String Length is: ";CharsFOR I=0 TO Chars - 1 CYCLE

Char$=MID$(String$,I,1)PRINT "Character No. ";I;" is "+Char$

REPEATEND

LINEPurposeDraw a line between two points

SyntaxLINE(xpos1,ypos1,xpos2,ypos2)

DescriptionDraw a line between point (xpos1,ypos1) and point(xpos2,ypos2) in the current COLOUR.

ExampleCLSCOLOUR = limeGH=GHEIGHTGW=GWIDTHLINE(10,10,10,GH-10)LINE(10,GH-10,GW-10,GH-10)LINE(GW-10,GH-10,GW-10,10)LINE(GW-10,10,10,10)UPDATEEND

AssociatedHLINE, LINETO, VLINE

Page 103: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

103

LINETOPurposeDraw a line from the last point plotted.

SyntaxLINETO(xpos1,ypos1)

DescriptionDraws a line from the last point plotted (by the PLOT orLINE procedures) to point (xpos1,ypos1).

ExampleCLSCOLOUR = yellowORIGIN(10,10)GH=GHEIGHTGW=GWIDTHLINETO(0,GH-20)LINETO(GW-20,GH-20)LINETO(GW-20, 0)LINETO(0,0)UPDATEEND

AssociatedHLINE, LINE, VLINE

LOADIMAGEPurposeLoad an image file into memory.

Syntaxhandle=LOADIMAGE(filename)

DescriptionLoad an image from a file with the specified filename. Thereturned handle can then be used to plot it on the screen withPLOTIMAGE.

ExampleCOLOUR=REDRECT(0,0,50,50,TRUE)COLOUR=WHITELINE(0,50,50,50)LINE(0,25,50,25)LINE(0,25,0,50)LINE(50,25,50,50)LINE(25,0,25,25)LINE(0,0,50,0)SAVEREGION("bricks.bmp",0,0,50,50)handle=LOADIMAGE("bricks.bmp")FOR X=0 TO GWIDTH STEP 50 CYCLE

FOR Y=0 TO GHEIGHT STEP 50 CYCLEPLOTIMAGE(handle,X,Y)

REPEATREPEATUPDATEEND

AssociatedGETIMAGEH, GETIMAGEW, PLOTIMAGE, FREEIMAGE

Page 104: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

104

LOADMUSICPurposeLoad a music file into memory ready to be played.

Syntaxhandle=LOADMUSIC(filename)

DescriptionLoads an uncompressed music file in wav format (fileextension .wav) from the file filename into memory andreturns a handle which can then be used to play the musicusing the PLAYMUSIC function.

Examplehandle=LOADMUSIC("takeoff.wav")SETMUSICVOL(70)PLAYMUSIC(handle,1)END

AssociatedPAUSEMUSIC, RESUMEMUSIC, SETMUSICVOL, STOPMUSIC

LOADSAMPLEPurposeLoad a sound sample into memory ready to be played.

Syntaxhandle=LOADSAMPLE(filename)

DescriptionThe LOADSAMPLE function loads a sound sample from theuncompressed WAV format file called filename andreturns a handle to it so that it can be played using thePLAYSAMPLE function. You can load up to 32 soundsamples into memory at the same time.

Examplechannel=0volume=70SETCHANVOL(channel,volume)intro=LOADSAMPLE("pacman_intro.wav")PLAYSAMPLE(intro,channel,0)WAIT(4.5)END

AssociatedPAUSECHAN, PLAYSAMPLE, RESUMECHAN, SETCHANVOL,STOPCHAN

Page 105: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

105

LOADSPRITEPurposeLoad a sprite from a file into memory.

SyntaxLOADSPRITE(filename$,index,subindex)

DescriptionThis loads a sprite from the supplied filename$ into memoryand associates it with the given sprite index and subindex. Theindex is the handle returned by a call to NewSprite and thesubindex is the version of the sprite to allow for animation. Thefirst subindex is 0.

ExampleCLSREM Create a new sprite with 1 versionSpriteIndex=NEWSPRITE(1)REM Load a sprite from a filefuzelogo$="/usr/share/fuze/logo.bmp"LOADSPRITE(fuzelogo$,SpriteIndex,0)REM Draw the sprite on the screenPLOTSPRITE(SpriteIndex,200,200,0)UPDATEEND

AssociatedGETSPRITEH, GETSPRITEW, HIDESPRITE, NEWSPRITE,PLOTSPRITE, SETSPRITETRANS, SPRITECOLLIDE,SPRITECOLLIDEPP

LOCALPurposeDefine variables to be local to a user defined procedure orfunction.

SyntaxLOCAL variable

DescriptionAllows a variable name to be reused in a procedure orfunction without affecting its value in the calling program.

ExampleX=10PRINT "Global X="+STR$(X)Proc Test()PRINT "Global X="+STR$(X)ENDDEF PROC Test()

PRINT "Global X="+STR$(X)LOCAL XX=5PRINT "Local X="+STR$(X)

ENDPROC

AssociatedDEF FN, DEF PROC

Page 106: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

106

LOGPurposeReturn the natural logarithm of the specified number.

Syntaxnaturallogarithm = LOG(number)

DescriptionReturns the natural logarithm of the specified number.This is the opposite of the EXP function i.e. LOG(EXP(X)) =X. Logarithms are used in science to solve exponentialradioactive decay problems and in finance to solveproblems involving compound interest.

ExampleX = EXP(10)PRINT X // Will print 22026.46579PRINT LOG(X) // Will print 10END

AssociatedEXP

MAXPurposeReturns the larger of two numbers.

Syntaxmaxvalue=MAX(number1,number2)

DescriptionReturns the larger (highest value) of number1 or number2.

ExampleREM Prints the value of number2number1=12.26number2=27.45PRINT MAX(number1, number2)END

AssociatedMIN

Page 107: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

107

MID$PurposeReturn characters from the middle of a string.

SyntaxMID$(string$, start, length)

DescriptionReturns the middle length characters of string$ startingfrom position start. The first character of the string isposition number 0.

ExampleREM Prints Quickstring$="The Quick Brown Fox"PRINT MID$(string$,4,5)END

AssociatedLEFT$, RIGHT$

MINPurposeReturns the smaller of two numbers.

Syntaxminvalue=MIN(number1,number2)

DescriptionReturns the smaller (lowest value) of number1 ornumber2.

ExampleREM Prints the value of number1number1=12.26number2=27.45PRINT MIN(number1, number2)END

AssociatedMAX

Page 108: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

108

MOUSEOFFPurposeMake the mouse cursor invisible.

SyntaxMOUSEOFF

DescriptionMake the mouse cursor invisible within the FUZE BASICwindow. This is the default value.

ExampleCLSMOUSEONCYCLE

GETMOUSE(x,y,b)LINETO(x,y)UPDATEREM Cycle colour if left button pressedIF b & 1 THEN

COLOUR = COLOUR MOD 16 + 1ENDIFREM Exit if right button pressed

REPEAT UNTIL b & 4MOUSEOFFEND

AssociatedGETMOUSE, MOUSEON, MOUSEX, MOUSEY, SETMOUSE

MOUSEONPurposeMake the mouse cursor visible.

SyntaxMOUSEON

DescriptionMake the mouse cursor visible within the FUZE BASICwindow. It is invisible by default.

ExampleCLSMOUSEONCYCLE

GETMOUSE(x,y,b)LINETO(x,y)UPDATEREM Cycle colour if left button pressedIF b & 1 THEN

COLOUR = COLOUR MOD 16 + 1ENDIFREM Exit if right button pressed

REPEAT UNTIL b & 4MOUSEOFFEND

AssociatedGETMOUSE, MOUSEOFF, MOUSEX, MOUSEY, SETMOUSE

Page 109: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

109

MOVEPurposeMove the graphics turtle forward

SyntaxMOVE(distance)

DescriptionThis causes the virtual graphics turtle to move forwardsdistance in screen pixels. A line will be drawn if the penisdown.

ExampleCLSCOLOUR=REDMOVE(50)DEGLEFT(90)MOVE(50)PENDOWNFOR I = 1 TO 4 CYCLE

LEFT(90)MOVE(100)

REPEATUPDATEEND

AssociatedLEFT, MOVETO, PENDOWN, PENUP, RIGHT, TANGLE

MOVETOPurposeMove the graphics turtle to a point on the screen.

SyntaxMOVETO(xpos,ypos)

DescriptionThis moves the virtual graphics turtle to the absolutelocation (xpos,ypos). A line will be drawn if the pen isdown.

ExampleREM Draw a spiral in the centre of thescreenCLSCOLOUR=REDPENUPMOVETO(GWIDTH/2,GHEIGHT/2)PENDOWNFOR I=2 TO GWIDTH CYCLE

MOVE(I)RIGHT(30)

REPEATUPDATEEND

AssociatedLEFT, MOVE, PENDOWN, PENUP, RIGHT, TANGLE

Page 110: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

110

NEWSPRITEPurposeCreate a new sprite.

Syntaxindex=NEWSPRITE(count)

DescriptionThis returns an index (or handle) to the internal spritedata. You need to use the index returned in all futuresprite handling functions/procedures. The countargument specifies the number of different versions ofthe sprite.

ExampleCLSCOLOUR=YELLOWCIRCLE(100,100,50,TRUE)SAVEREGION("pac1.bmp",50,50,101,101)COLOUR=BLACKTRIANGLE(100,100,150,125,150,75,TRUE)SAVEREGION("pac2.bmp",50,50,101,101)TRIANGLE(100,100,150,150,150,50,TRUE)SAVEREGION("pac3.bmp",50,50,101,101)CLSpacman=NEWSPRITE(3)LOADSPRITE("pac1.bmp",pacman,0)LOADSPRITE("pac2.bmp",pacman,1)LOADSPRITE("pac3.bmp",pacman,2)FOR X=1 TO GWIDTH STEP 25 CYCLE

FOR S=0 TO 2 CYCLEPLOTSPRITE(pacman,X,GHEIGHT/2,S)UPDATEWAIT(.1)

REPEATREPEATHIDESPRITE(pacman)END

AssociatedGETSPRITEH, GETSPRITEW, HIDESPRITE, LOADSPRITE,PLOTSPRITE, SETSPRITETRANS, SPRITECOLLIDE,SPRITECOLLIDEPP

Page 111: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

111

NUMFORMATPurposeControl how numbers are formatted.

SyntaxNUMFORMAT(width,decimals)

DescriptionYou can affect the way numbers are printed using theNUMFORMAT procedure. This takes 2 arguments, thewidth specifying the total number of characters to printand the decimals the number of characters after thedecimal point. Numbers printed this way are right-justified with leading spaces inserted if required.NUMFORMAT (0,0) restores the output to the generalpurpose format used by default.

ExampleNUMFORMAT(6,4)REM Prints 3.1416PRINT PINUMFORMAT(0,0)REM Prints 3.141592654PRINT PIEND

AssociatedPRINT, PRINTAT

OPENPurposeOpen a file for read or write.

Syntaxhandle=OPEN(filename$)

DescriptionThe OPEN function opens a file and makes it available forreading or writing and returns the numeric handleassociated with the file. The file is created if it doesn’texist, or if it does exist the file pointer is positioned at thestart of the file.

Examplehandle = OPEN("testfile.txt")PRINT# handle, "Colin"PRINT# handle, 47CLOSE(handle)handle = OPEN("testfile.txt")INPUT# handle, Name$INPUT# handle, AgeCLOSE(handle)PRINT "Name: " + Name$PRINT "Age: "; AgeEND

AssociatedCLOSE, EOF, FFWD, INPUT#, PRINT#, REWIND, SEEK

Page 112: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

112

ORIGINPurposeMove the graphics origin.

SyntaxORIGIN(xpos,ypos)

DescriptionThis changes the graphics origin for the Cartesian plottingprocedures. The xpos, ypos coordinates are alwaysabsolute coordinates with (0,0) being bottom left (thedefault).

ExampleCLSCOLOUR=yellowREM Move the origin to the screen centreORIGIN(GWIDTH/2, GHEIGHT/2)PLOT(-100,-100)LINETO(-100,100)LINETO(100,100)LINETO(100,-100)LINETO(-100,-100)UPDATEORIGIN(0,0)END

AssociatedGHEIGHT, GWIDTH

PAUSECHANPurposePause the playing of a sound sample.

SyntaxPAUSECHAN(handle)

DescriptionThis function pauses the playing of the sound sampleassociated with the handle returned by LOADSAMPLEthat has been started using PLAYSAMPLE. The samplecan be resumed where it left off using RESUMECHAN

Examplechannel=0volume=70SETCHANVOL(channel,volume)intro=LOADSAMPLE("pacman_intro.wav")PLAYSAMPLE(intro,channel,0)WAIT(3)PAUSECHAN(intro)Wait(2)RESUMECHAN(intro)END

AssociatedLOADSAMPLE, PLAYSAMPLE, RESUMECHAN,SETCHANVOL, STOPCHAN

Page 113: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

113

PAUSEMUSICPurposePause a playing music file

SyntaxPAUSEMUSIC

DescriptionPauses a playing music track which can them be restartedusing RESUMEMUSIC.

Examplehandle=LOADMUSIC("takeoff.wav")SETMUSICVOL(70)PLAYMUSIC(handle,1)PAUSEMUSIC

AssociatedLOADMUSIC, RESUMEMUSIC, SETMUSICVOL, STOPMUSIC

PENDOWNPurposeStart drawing using the graphics turtle.

SyntaxPENDOWN

DescriptionThis lowers the “pen” that the virtual graphics turtle isusing to draw with. Nothing will be drawn until youexecute this procedure.

ExampleREM Draw a spiral in the centre of thescreenCLSCOLOUR=REDPENUPMOVETO(GWIDTH/2,GHEIGHT/2)PENDOWNFOR I=2 TO GWIDTH CYCLE

MOVE(I)RIGHT(30)

REPEATUPDATEEND

AssociatedLEFT, MOVE, MOVETO, PENUP, RIGHT, TANGLE

Page 114: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

114

PENUPPurposeStop drawing using the graphics turtle.

SyntaxPENUP

DescriptionThis lifts the “pen” that the virtual graphics turtle uses todraw. You can move the turtle without drawing while thepen is up.

ExampleREM Draw a spiral in the centre of thescreenCLSCOLOUR=REDPENUPMOVETO(GWIDTH/2,GHEIGHT/2)PENDOWNFOR I=2 TO GWIDTH CYCLE

MOVE(I)RIGHT(30)

REPEATUPDATEEND

AssociatedLEFT, MOVE, MOVETO, PENDOWN, RIGHT, TANGLE

PINMODEPurposeConfigure the mode of a pin on the Pi’s GPIO.

SyntaxPINMODE(pinno,pinmode)

DescriptionConfigures the mode of a pin on the Pi’s GPIO. It takes anargument which specifies the mode of the pin - input,output or PWM output. The modes are:0 pinINPUT1 pinOUTPUT2 pinPWM

ExampleREM Set pin 12 to inputPINMODE(12,1)REM Wait for button to be pushedUNTIL DIGITALREAD(12) CYCLEREPEATPRINT "Button Pushed"END

AssociatedDIGITALREAD, DIGITALWRITE, PWMWRITE,SOFTPWMWRITE

Page 115: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

115

PLAYMUSICPurposeStart playing a music track.

SyntaxPLAYMUSIC(handle,repeats)

DescriptionThis function plays a music track previously loaded usingthe LOADMUSIC function which returns the handle. Therepeats are the number of times to play the track.

Examplehandle=LOADMUSIC("takeoff.wav")SETMUSICVOL(70)PLAYMUSIC(handle,1)END

AssociatedLOADMUSIC, PAUSEMUSIC, RESUMEMUSIC,SETMUSICVOL, STOPMUSIC

PLAYSAMPLEPurposeStart playing a sound sample.

SyntaxPLAYSAMPLE(handle,channel,loops)

DescriptionThis function plays a sound previously loaded using theLOADSAMPLE function which returns the handle. Thechannel is 0, 1, 2 or 3 which lets you play up to 4concurrent samples. The loops parameter is different tothe repeats one in the PLAYMUSIC function. Here it meansthe number of times to loop the sample – zero means noloops which means play it ONCE.

Examplechannel=0volume=70SETCHANVOL(channel,volume)intro=LOADSAMPLE("pacman_intro.wav")PLAYSAMPLE(intro,channel,0)WAIT(4.5)END

AssociatedLOADSAMPLE, PAUSECHAN, RESUMECHAN, SETCHANVOL,STOPCHAN

Page 116: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

116

PLOTPurposeDraw a single point on the screen.

SyntaxPLOT(xpos,ypos)

DescriptionThis plots a single pixel at screen location (xpos,ypos) inthe selected graphics mode in the selected colour. Notethat (0,0) is bottom left by default.

ExampleCLSCYCLE

IF INKEY<>-1 THEN BREAKxpos=RND(GWIDTH)ypos=RND(GHEIGHT)COLOUR=RND(16)PLOT(xpos, ypos)UPDATE

REPEATEND

PLOTIMAGEPurposeDisplay a loaded image on the screen.

SyntaxPLOTIMAGE(handle,xpos,ypos)

DescriptionPlot an image previously loaded using LOADIMAGE(using the handle returned by LOADIMAGE) on thescreen at coordinates (xpos,ypos).

ExampleCOLOUR=REDRECT(0,0,50,50,TRUE)COLOUR=WHITELINE(0,50,50,50)LINE(0,25,50,25)LINE(0,25,0,50)LINE(50,25,50,50)LINE(25,0,25,25)LINE(0,0,50,0)SAVEREGION("bricks.bmp",0,0,50,50)handle=LOADIMAGE("bricks.bmp")FOR X=0 TO GWIDTH STEP 50 CYCLE

FOR Y=0 TO GHEIGHT STEP 50 CYCLEPLOTIMAGE(handle,X,Y)

REPEATREPEATUPDATEEND

AssociatedGETIMAGEH, GETIMAGEW, LOADIMAGE, FREEIMAGE

Page 117: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

117

PLOTSPRITEPurposeDraw a sprite on the screen.

SyntaxPLOTSPRITE(index,xpos,ypos,subindex)

DescriptionThis plots the sprite index and version subindex at thecoordinates (xpos, ypos). The coordinates specify the bottom-left corner of the bounding rectangle of the sprite.

ExampleCLSREM Create a new sprite with 1 versionSpriteIndex=NEWSPRITE(1)REM Load a sprite from a filefuzelogo$="/usr/share/fuze/logo.bmp"LOADSPRITE(fuzelogo$,SpriteIndex,0)REM Draw the sprite on the screenPLOTSPRITE(SpriteIndex,200,200,0)UPDATEEND

AssociatedGETSPRITEH, GETSPRITEW, HIDESPRITE, LOADSPRITE,NEWSPRITE, SETSPRITEALPHA, SETSPRITEANGLE,SETSPRITEFLIP, SETSPRITESIZE, SETSPRITETRANS,SPRITECOLLIDE, SPRITECOLLIDEPP, SPRITEOUT

POLYENDPurposeDraw the filled polygon started by PolyStart.

SyntaxPOLYEND

DescriptionThis marks the end of drawing a polygon. When this iscalled, the stored points will be plotted on the screen andthe polygon will be filled.

ExampleCLSPROC Hexagon(200,200,50,Red)UPDATEENDDEF Proc Hexagon(x,y,l,c)

COLOUR=cPOLYSTARTPOLYPLOT(x+l,y)POLYPLOT(x+l/2,y-l*SQRT(3/2))POLYPLOT(x-l/2,y-l*SQRT(3/2))POLYPLOT(x-l,y)POLYPLOT(x-l/2,y+l*SQRT(3/2))POLYPLOT(x+l/2,y+l*SQRT(3/2))POLYEND

ENDPROC

AssociatedPOLYPLOT, POLYSTART

Page 118: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

118

POLYPLOTPurposeAdd a point to a filled polygon.

SyntaxPOLYPLOT(xpos,ypos)

DescriptionThis remembers the given xpos,ypos coordinates as part of afilled polygon. Nothing is actually drawn on the screen until thePolyEnd instruction is executed. Polygons can have a maximumof 64 points.

ExampleCLSPROC Hexagon(200,200,50,Red)UPDATEENDDEF Proc Hexagon(x,y,l,c)

COLOUR=cPOLYSTARTPOLYPLOT(x+l,y)POLYPLOT(x+l/2,y-l*SQRT(3/2))POLYPLOT(x-l/2,y-l*SQRT(3/2))POLYPLOT(x-l,y)POLYPLOT(x-l/2,y+l*SQRT(3/2))POLYPLOT(x+l/2,y+l*SQRT(3/2))POLYEND

ENDPROC

AssociatedPOLYEND, POLYSTART

POLYSTARTPurposeStart drawing a filled polygon.

SyntaxPOLYSTART

DescriptionThis marks the start of drawing a filled polygon.

ExampleCLSPROC Hexagon(200,200,50,Red)UPDATEENDDEF Proc Hexagon(x,y,l,c)

COLOUR=cPOLYSTARTPOLYPLOT(x+l,y)POLYPLOT(x+l/2,y-l*SQRT(3/2))POLYPLOT(x-l/2,y-l*SQRT(3/2))POLYPLOT(x-l,y)POLYPLOT(x-l/2,y+l*SQRT(3/2))POLYPLOT(x+l/2,y+l*SQRT(3/2))POLYEND

ENDPROC

AssociatedPOLYEND, POLYPLOT

Page 119: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

119

PRINTPurposeOutput text to the screen

SyntaxPRINT {text}{;text}

DescriptionOutputting text to the screen is done via the PRINTcommand. The PRINT command is quite versatile and willprint any combination of numbers and strings separatedby the semi-colon (;). A trailing semi-colon will suppressthe printing of a new line.

ExamplePRINT "Hello Colin"PRINT "Hello ";name$="Colin"PRINT name$PRINT "Hello "; name$END

AssociatedNUMFORMAT, PRINTAT

PRINT#PurposePrint data to a file.

SyntaxPRINT# handle,data

DescriptionThe PRINT# instruction acts just like the regular PRINTinstruction except that it sends data to the file identifiedby the supplied file-handle rather than to the screen.Numbers are formatted according to the settings ofNUMFORMAT. It is strongly recommended to only printone item per line if you are going to read those items backinto a FUZE BASIC program again.

Examplehandle = OPEN("testfile.txt")PRINT# handle, "Hello World"CLOSE (handle)END

AssociatedCLOSE, EOF, FFWD, INPUT#, OPEN, REWIND, SEEK

Page 120: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

120

PRINTATPurposeSet the text cursor position and print

SyntaxPRINTAT( x, y ); "text"

DescriptionUse to position the text cursor at the specified locationand print. Useful for laying out text and or variables atany preferred screen location.

Examplename$ = "Sam"age = 10PRINTAT( 0, 5 ); "My name is "; name$PRINTAT( 5, 10 ); "I am "; age ; " yearsold"END

AssociatedCHR$, FONTSCALE, FONTSCALE, HTAB, HVTAB, INK,PAPER, PRINT, PRINT, THEIGHT, TWIDTH, VTAB

PROCPurposeCall a user defined procedure.

SyntaxPROC name({argument}{,argument})

DescriptionCalls the specified user defined procedure called namewith the specified arguments. Once the procedure hasbeen executed control returns to the command following.

ExampleCLSCYCLE

x=RND(TWIDTH)y=RND(THEIGHT)c=RND(15)Text$=”Blossom”PROC text(text$, x, y, c)

REPEATENDDEF PROC text(text$, x, y, c) INK=c PRINTAT(x,y); text$ENDPROC

AssociatedDEF PROC, ENDPROC

Page 121: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

121

PWMWRITEPurposeOutput a PWM waveform on the selected pin.

SyntaxPWMWRITE(pinno,pinvalue)

DescriptionThis procedure outputs a PWM waveform on the selectedpin. The pin must be configured for PWM modebeforehand. The value set should be between 0 and 100.

ExampleREM Set pin 1 to PWM output modePINMODE(1,2)PWMWRITE (1,50)END

AssociatedDIGITALREAD, DIGITALWRITE, PINMODE

RADPurposeSet angle units to radians.

SyntaxRAD

DescriptionSwitches the internal angle system to radians. There are 2* PI radians in a full circle.

ExampleREM Draw an ellipse in the screen centreCLSRADFOR Angle=0 TO 2 * PI STEP 0.01 CYCLE

Xpos=100*COS(Angle)+GWIDTH / 2Ypos=50*SIN(Angle)+GHEIGHT / 2PLOT(Xpos,Ypos)

REPEATEND

AssociatedCLOCK, DEG

Page 122: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

122

READPurposeRead data into program variables.

SyntaxREAD variable {,variable}

DescriptionTo get data into your program variables, we use the READinstruction. We can read one, or many items of data at atime.

ExampleREM Load the name of the days of theREM week into a string arrayDATA "Monday", "Tuesday", "Wednesday"DATA "Thursday", "Friday", "Saturday"DATA "Sunday"DIM DaysOfWeek$(7)FOR Day = 1 TO 7 CYCLE

READ DaysOfWeek$(Day)REPEATPRINT "The third day of the week is ";PRINT DaysOfWeek$(3)END

AssociatedDATA, RESTORE

RECTPurposeDraw a rectangle on the screen.

SyntaxRECT(xpos,ypos,width,height,fill)

DescriptionDraws a rectangle at position (xpos,ypos) with width andheight. The final parameter, fill is either TRUE or FALSE,and specifies filled (TRUE) or outline (FALSE).

ExampleCLSCYCLE

COLOUR=RND(16)x=RND(GWIDTH)y=RND(GHEIGHT)w=RND(GWIDTH / 4)h=RND(GHEIGHT / 4)f=RND(2)RECT(x,y,w,h,f)UPDATEIF INKEY<>-1 THEN BREAK

REPEATEND

AssociatedCIRCLE, ELLIPSE, TRIANGLE

Page 123: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

123

REPEAT UNTILPurposeLoop until the specified condition is met.

SyntaxCYCLE

{statements}REPEAT UNTIL condition

DescriptionExecute the statements one or more times until thecondition is TRUE (not 0).

ExampleNumber=INT(RND(10)) + 1Guess=0REM Guessing GamePRINT "Guess a Number Between 1 and 10"CYCLE

INPUT "Enter Your Guess: ", GuessIF (Number<>Guess) THEN

PRINT "Incorrect Guess Again"ENDIF

REPEAT UNTIL Number = GuessPRINT "You are Correct!"END

AssociatedBREAK, CONTINUE, CYCLE, CYCLE REPEAT, FOR REPEAT,UNTIL REPEAT, WHILE REPEAT

RESTOREPurposeReset the DATA pointer.

SyntaxRESTORE

DescriptionWith no lineno specified resets the READ command to thevery first DATA statement in the program.

ExampleDATA "Monday", "Tuesday", "Wednesday"DATA "Thursday", "Friday", "Saturday","Sunday"FOR Day = 1 TO 3 CYCLE

READ DayOfWeek$REPEATPRINT DayOfWeek$RESTOREFOR Day = 1 TO 4 CYCLE

READ DayOfWeek$REPEATPRINT DayOfWeek$END

AssociatedDATA, READ

Page 124: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

124

RESUMECHANPurposeResume the playing of a sound sample.

SyntaxRESUMECHAN(handle)

DescriptionThis function resumes the playing of the sound sampleassociated with the handle returned by LOADSAMPLEthat has been started using PLAYSAMPLE and pausedusing PAUSECHAN.

Examplechannel=0volume=70SETCHANVOL(channel,volume)intro=LOADSAMPLE("pacman_intro.wav")PLAYSAMPLE(intro,channel,0)WAIT(3)PAUSECHAN(intro)WAIT(2)RESUMECHAN(intro)END

AssociatedLOADSAMPLE, PAUSECHAN, PLAYSAMPLE, SETCHANVOL,STOPCHAN

RESUMEMUSICPurposeResumes music playing after it has been paused.

SyntaxRESUMEMUSIC

DescriptionResumes the playing of a music track previously pausedusing PAUSEMUSIC.

Examplehandle=LOADMUSIC("takeoff.wav")SETMUSICVOL(70)PLAYMUSIC(handle,1)PAUSEMUSICWAIT(1)RESUMEMUSIC

AssociatedLOADMUSIC, PAUSEMUSIC, SETMUSICVOL, STOPMUSIC

Page 125: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

125

REWINDPurposeMove the file pointer to the start of a file.

SyntaxREWIND(handle)

DescriptionMove the file pointer to the start of the file specified byhandle.

Examplehandle=OPEN ("rewindtest.txt")PRINT# handle,"First Record"PRINT# handle,"Second Record"CLOSE(handle)handle=OPEN("rewindtest.txt")INPUT# handle, record$PRINT record$REWIND(handle)REM reads the first record againINPUT# handle, record$PRINT record$CLOSE (handle)END

AssociatedCLOSE, EOF, FFWD, INPUT#, OPEN, PRINT#, SEEK

RGBCOLOURPurposeSet the current graphical plot colour to an RGB(Red,Green, Blue) value.

SyntaxRGBCOLOUR(red,green,blue)

DescriptionThis sets the current graphical plot colour to an RGB(Red,Green, Blue) value. The values should be from 0 to 255.

ExampleCLSPRINT "Draw Spectrum"FOR v = 0 TO 255 CYCLE

RGBCOLOUR(255,v,0)LINE(v,300,v,400)RGBCOLOUR(v,255,0)LINE(511-v,300,511-v,400)RGBCOLOUR(0,255-v,v)LINE(512+v,300,512+v,400)RGBCOLOUR(0,v,255)LINE(768+v,300,768+v,400)

REPEATUPDATEEND

AssociatedCOLOUR, INK, PAPER

Page 126: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

126

RIGHTPurposeTurns the turtle to the right (clockwise) by the given angle.

SyntaxRIGHT(angle)

DescriptionTurns the virtual graphics turtle to the right (clockwise) bythe given angle in the current angle units.

ExampleCLSPRINT "Draw Pink Hexagon"PENUPCOLOUR = PINKPENDOWNFOR I = 1 TO 6 CYCLE

RIGHT(60)MOVE(100)

REPEATEND

AssociatedLEFT, MOVE, MOVETO, PENDOWN, PENUP, TANGLE

RIGHT$PurposeReturn the specified rightmost number of a charactersfrom a string.

Syntaxsubstring$=RIGHT$(string$,number)

DescriptionReturns a substring of string$ with number charactersfrom the right (end) of the string. If number is greaterthan or equal to the length of string$ then the wholestring is returned.

ExampleString$="The quick brown fox"FOR I=1 TO 20 CYCLE

PRINT RIGHT$(String$, I)REPEATEND

AssociatedLEFT$, MID$

Page 127: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

127

RNDPurposeGenerate a random number in a given range.

Syntaxrandom=RND(range)

DescriptionThis function returns a random number based on thevalue of range. If range is zero, then the last randomnumber generated is returned, if range is 1, then arandom number from 0 to 1 is returned, otherwise arandom number from 0 up to, but not including range isreturned.

ExampleDiceRoll=RND(6)+1PRINT "Dice Roll: "; DiceRollCoinToss=RND(2)IF CoinToss=0 THEN

PRINT "Heads"ELSE

PRINT "Tails"ENDIFEND

AssociatedSEED

SAVEREGIONPurposeSave a snapshot of an area of the screen to an image file.

SyntaxSAVEREGION(file$,xpos,ypos,width,height)

DescriptionThis takes a snapshot of an area of the current screen,specified by the rectangle with bottom left at coordinates(xpos,ypos) of specified width and height, and saves it tothe file named file$ in a bitmap (.bmp) format.

Example (overleaf)

Page 128: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

128

SAVEREGION Example

CLSCOLOUR=YELLOWCIRCLE(100,100,50,TRUE)SAVEREGION("pac1.bmp",50,50,101,101)COLOUR=BLACKTRIANGLE(100,100,150,125,150,75,TRUE)SAVEREGION("pac2.bmp",50,50,101,101)TRIANGLE(100,100,150,150,150,50,TRUE)SAVEREGION("pac3.bmp",50,50,101,101)CLSpacman=NEWSPRITE(3)LOADSPRITE("pac1.bmp",pacman,0)LOADSPRITE("pac2.bmp",pacman,1)LOADSPRITE("pac3.bmp",pacman,2)FOR X=1 TO GWIDTH STEP 25 CYCLE

FOR S=0 TO 2 CYCLEPLOTSPRITE(pacman,X,GHEIGHT/2,S)UPDATEWAIT(.1)

REPEATREPEATHideSprite(pacman)END

AssociatedSAVESCREEN

SAVESCREENPurposeSave a snapshot of the screen to an image file.

SyntaxSAVESCREEN(filename$)

DescriptionThis takes a snapshot of the current screen and saves it tothe filename given in a bitmap (.bmp) format file.

ExampleCLSPRINT "Draw Spectrum"FOR v = 0 TO 255 CYCLE

RGBCOLOUR(255,v,0)LINE(v,300,v,400)RGBCOLOUR(v,255,0)LINE(511-v,300,511-v,400)RGBCOLOUR(0,255-v,v)LINE(512+v,300,512+v,400)RGBCOLOUR(0,v,255)LINE(768+v,300,768+v,400)

REPEATUPDATESAVESCREEN("screenshot.bmp")END

AssociatedSAVEREGION

Page 129: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

129

SCANKEYBOARDPurposeScan for a key pressed down.

SyntaxSCANKEYBOARD(keycode)

DescriptionAllows you to detect that any of the keys have beenpressed (including special keys) and also to detect mutiplekeys pressed at the same time. The keycode parameterindicates the key press to be scanned for e.g scanSpace isthe space bar. See the end of this guide for a full list ofSCANKEYBOARD keycodes.

ExamplePRINT "Press Ctrl-Alt-Delete"CYCLE

LCtrl = SCANKEYBOARD(scanLCtrl)LAlt = SCANKEYBOARD(scanLAlt)Delete = SCANKEYBOARD(scanDelete)Reboot = LCtrl AND LAlt AND Delete

REPEAT UNTIL RebootPRINT "Rebooting…"CLEARKEYBOARDEND

AssociatedCLEARKEYBOARD, GET, INKEY, INPUT

SCLOSEPurposeClose an open serial port.

SyntaxSCLOSE(handle)

DescriptionThis closes a serial port and frees up any resources usedby it. It’s not strictly necessary to do this when you endyour program, but it is considered good practice.

ExampleREM Read a character from a serial portarduino=SOPEN("/dev/ttyUSB0", 115200)char$=SGET$(arduino)PRINT char$SCLOSE(arduino)END

AssociatedSGET, SGET$, SOPEN, SPUT, SPUT$, SREADY

Page 130: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

130

Procedures & Functions

SCROLLDOWNSCROLLLEFTSCROLLRIGHTSCROLLUPPurposeScroll a region of the screen down.

SyntaxSCROLLDOWN(xpos,ypos,width,height,pixels)

DescriptionScroll the region of the screen specified by the rectangleat position (xpos,ypos) with dimensions width X heightdown by the specified number of pixels.

ExampleCLSW=100 // WidthS=2 // Step SizeX=(GWIDTH-W)/2Y=(GHEIGHT-W)/2COLOUR=WHITERECT(X,Y,W,W,TRUE)RECT(X+W,Y+W,W,W,TRUE)RECT(X-2,Y-2,W*2+4,W*2+4,FALSE)UPDATECOLOUR=BLACKFOR I=1 TO W STEP S CYCLE

SCROLLUP(X,Y,W,W*2,S)SCROLLDOWN(X+W,Y,W,W*2,S)UPDATEWAIT(0.01)

REPEATFOR I = 1 TO W STEP S CYCLE

SCROLLRIGHT(X,Y+W,W*2,W,S)SCROLLLEFT(X,Y,W*2,W,S)WAIT(0.01)

UPDATEREPEATEND

AssociatedSCROLLLEFT, SCROLLRIGHT, SCROLLUP

Page 131: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

131

SEEKPurposeMove the file pointer to any place in the file.

SyntaxSEEK(handle,offset)

DescriptionThe SEEK instruction moves the file pointer to any place in thefile. It can even move the file pointer beyond the end of the filein which case the file is extended. The argument supplied toSEEK is an absolute number of bytes from the start of the file. Ifyou are using random access files and want to access the 7threcord in the file, then you need to multiply your record size by7 to get the final location to seek to.

Examplehandle=OPEN("TestFile.txt")recSize = 20FOR recNo=0 TO 10 CYCLE

record$ = "Record " + STR$(recNo)pad = recSize - LEN(record$)PRINT# handle,record$;SPACE$(pad)

REPEATREM read the 7th recordSEEK (handle,(recSize+1)*7)INPUT# handle,record$PRINT record$CLOSE(handle)END

AssociatedCLOSE, EOF, FFWD, INPUT#, OPEN, PRINT#, REWIND

SETCHANVOLPurposeSet the volume of a sound sample.

SyntaxSETCHANVOL(channel,volume)

DescriptionSets the sound sample playback volume on the specifiedchannel where volume is a percentage of the maximum(0-100)

Examplechannel=0chomp=LOADSAMPLE("pacman_chomp.wav")FOR volume=10 TO 100 STEP 10 CYCLE

SETCHANVOL(channel,volume)PLAYSAMPLE(chomp,0,0)WAIT(1)

REPEATEND

AssociatedLOADSAMPLE, PAUSECHAN, PLAYSAMPLE, RESUMECHAN,STOPCHAN

Page 132: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

132

SETMODEPurposeSet display width and height

SyntaxSETMODE( width, height )

DescriptionSets the display width and height to the specified. It isgenerally sensible to use standard screen display sizes

ExampleSETMODE( 1280, 720 )PRINT "Hello World"WAIT( 2 )SETMODE( 640, 480 )PRINT "Hello Another World"END

AssociatedGHEIGHT, GWIDTH

SETMOUSEPurposeMove the mouse pointer to the specified point.

SyntaxSETMOUSE(xpos,ypos)

DescriptionMoves the mouse pointer to the screen coordinate (xpos,ypos)

ExampleCLSMOUSEONCOLOUR=WHITERECT(100,100,150,50,TRUE)INK=BLACKPAPER=WHITEPRINTAT(7,38); PRINT "Click Me"UPDATEClicked=FALSECYCLEGETMOUSE(X,Y,Z)IF Z <> 0 THENIF (X > 100 AND X < 250) THEN

IF (Y > 100 AND Y < 150) THENClicked=TRUE

ENDIFENDIF

ENDIFREPEAT UNTIL ClickedSETMOUSE(GWIDTH/2,GHEIGHT/2)END

AssociatedGETMOUSE, MOUSEOFF, MOUSEON, MOUSEX, MOUSEY

Page 133: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

133

SETMUSICVOLPurposeSets the music playback volume.

SyntaxSETMUSICVOL(level)

DescriptionSets the music playback volume where level is apercentage of the maximum (0-100)

Examplehandle=LOADMUSIC("takeoff.wav")SETMUSICVOL(70)PLAYMUSIC(handle,1)

AssociatedLOADMUSIC, PAUSEMUSIC, RESUMEMUSIC, STOPMUSIC

SETSPRITEALPHAPurposeSets the transparency of a sprite

SyntaxSETSPRITEALPHA( sprite, alpha )

DescriptionSets how transparent a sprite is. An alpha of 0 means it'sinvisible and 255 means it's completely opaque, or solid.

Examplepic = NEWSPRITE( 1 )LOADSPRITE( "/usr/share/fuze/logo.bmp",pic, 0 )FOR alpha = 0 TO 255 CYCLESETSPRITEALPHA( pic, alpha )PLOTSPRITE( pic, GWIDTH / 2, GHEIGHT / 2, 0)UPDATEREPEATEND

AssociatedPLOTSPRITE

Page 134: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

134

SETSPRITEANGLEPurposeRotate a sprite to the given angle

SyntaxSETSPRITEANGLE( sprite, angle )

DescriptionUse to rotate the specified sprite to the given angle indegrees. 0 is default.

Examplepic = NEWSPRITE( 1 )LOADSPRITE( "/usr/share/fuze/logo.bmp",pic, 0 )FOR angle = 0 TO 360 CYCLESETSPRITEANGLE( pic, angle )PLOTSPRITE( pic, GWIDTH / 2, GHEIGHT / 2, 0)UPDATEREPEATEND

AssociatedPLOTSPRITE

SETSPRITEFLIPPurposeMirror a sprite in the specified direction

SyntaxSETSPRITEFLIP( sprite, flip )

DescriptionGraphically mirrors (flips) the specified sprite.

0 Reset to default1 mirrored vertically2 mirrored horizontally3 mirrored vertically & horizontally

Examplepic = NEWSPRITE( 1 )LOADSPRITE("/usr/share/fuze/logo.bmp",pic, 0)PLOTSPRITE(pic, gWidth / 2, gHeight / 2, 0)FOR a=3 TO 0 step -1 cycleSETSPRITEFLIP( pic, a )UPDATEWAIT( 1 )REPEAT

AssociatedPLOTSPRITE

Page 135: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

135

SETSPRITESIZEPurposeChange the size of a sprite

SyntaxSETSPRITESIZE( sprite, size )

DescriptionSets the sprite to the specified size in percent. 100 is thedefault, therefore 50 is half the size and 300 is three timesas big as the original.

Examplepic = NEWSPRITE( 1 )LOADSPRITE("/usr/share/fuze/logo.bmp",pic, 0)FOR angle = 50 TO 200 CYCLESETSPRITESIZE( pic, size )PLOTSPRITE( pic, GWIDTH / 2, GHEIGHT / 2, 0)UPDATEREPEATEND

AssociatedPLOTSPRITE

SETSPRITETRANSPurposeSet a transparency colour for a given sprite and its sub-sprites.

SyntaxSETSPRITETRANS(spriteId, Red, Green, Blue)

DescriptionIf you specify a transparency colour for a sprite then anypixels in the sprite that are this colour will be transparenti.e. They will show as the background colour. This allows asprite to pass over a background image without blocking itout. You need to load the sprite files first before settingthe transparency colour.

Example (overleaf)

Page 136: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

136

SETSPRITETRANS ExampleCLSRGBCOLOUR(247, 247, 247)RECT(50, 50, 101, 101, TRUE)COLOUR = YELLOWCIRCLE(100, 100, 50, TRUE)SAVEREGION("s3.bmp", 50, 50, 101, 101)CLS2COLOUR = REDMidY = GHEIGHT / 2FOR X = 0 TO GWIDTH STEP 100 CYCLE

RECT(X, MidY - 50, 50, 200, TRUE)REPEATCOLOUR = Blacks1 = NEWSPRITE(1)LOADSPRITE("s3.bmp", s1, 0)SETSPRITETRANS(s1, 247, 247, 247)FOR X = 0 TO gWidth STEP 10 CYCLE

PLOTSPRITE(s1, X, GHEIGHT / 2, 0)UPDATEWAIT (0.0005)

REPEATEND

AssociatedGETSPRITEH, GETSPRITEW, LOADSPRITE, NEWSPRITE,PLOTSPRITE, RGBCOLOUR

SGETPurposeRead a byte from a serial port.

Syntaxbyte=SGET(handle)

DescriptionFetch a single byte of data from an open serial port andreturn the data as a number. This function will pauseprogram execution for up to 5 seconds if no data isavailable. If there is still not data after 5 seconds, thefunction will return -1.

ExampleREM Read a byte from a serial portarduino=SOPEN("/dev/ttyUSB0", 115200)byte=SGET(arduino)PRINT byteSCLOSE(arduino)END

AssociatedSCLOSE, SGET$, SOPEN, SPUT, SPUT$, SREADY

Page 137: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

137

SGET$PurposeRead a character from a serial port.

Syntaxcharacter=SGET$(handle)

DescriptionFetch a single byte of data from an open serial port andreturn the data as a single character string. This functionwill pause program execution for up to 5 seconds if nodata is available. If there is still not data after 5 seconds,the function will return an empty string.

ExampleREM Read a character from a serial portarduino=SOPEN("/dev/ttyUSB0", 115200)char$=SGET$(arduino)PRINT char$SCLOSE(arduino)END

AssociatedSCLOSE, SGET, SOPEN, SPUT, SPUT$, SREADY

SGNPurposeReturns the sign of the specified number.

Syntaxsign=SGN(number)

DescriptionReturns -1 if the number is negative, 1 otherwise. (Zero isconsidered positive)

ExampleREM Prints 1PRINT SGN(100)PRINT SGN(0)REM Print -1PRINT SGN(-5)END

AssociatedABS

Page 138: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

138

SHOWKEYSPurposeList the function key definitions

SyntaxSHOWKEYS

DescriptionIt is possible to set the 12 function keys at the top of thekeyboard to user defined values. This command will showwhat the current definitions are. By default function keyF2 is defined to enter the EDIT command and F3 the RUNcommand but it is possible to overwrite these.

ExampleREM Set key F5 to clear screenkeyF5$ = "CLS\n"SHOWKEYS

SINPurposeReturns the sine of the given angle.

Syntaxsine=SIN(angle)

DescriptionReturns the sine of the argument angle in radians. This isthe ratio of the side of a right angled triangle, that isopposite to the angle, to the hypotenuse (the longestside).

ExampleREM Draw an ellipse in the screen centreCLSDEGFOR Angle=0 TO 360 CYCLE

Xpos=100*COS(Angle)+GWIDTH/2Ypos=50*SIN(Angle)+GHEIGHT/2PLOT(Xpos,Ypos)

REPEATEND

AssociatedASIN, ATAN, COS

Page 139: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

139

SOFTPWMWRITEPurposeSynthesize Pulse Wave Modulation to the specified GPIOpin.

SyntaxSOFTPWMWRITE(pinNo,value)

DescriptionThis enables you to simulate an analog output. For exampleinstead of an LED being just on or off you can make it appearbrighter or dimmer. The pinNo parameter is the number of theGPIO output pin. This must first be set to pinSoftPwm. Thevalue parameter is a percentage (0-100).

ExampleREM Connect an LED to GPIO pin 0PINMODE (0, PINSOFTPWM)FOR I=0 TO 100 CYCLE

SOFTPWMWRITE (0,I)WAIT(0.1)

REPEATFOR I=100 to 0 STEP -1 CYCLE

SOFTPWMWRITE (0,I)WAIT(0.1)

REPEATEND

AssociatedPINMODE

SOPENPurposeOpens a serial device and makes it available for use.

Syntaxhandle=SOPEN($device,speed)

DescriptionThis opens a serial device and makes it available for ouruse. It takes the name of the serial port and the speed asan argument and returns a number (the handle) of thedevice. We can use this handle to reference the deviceand allow us to open several devices at once.The following baud rates are recognised: 50, 75, 110, 134,150,200, 300, 600, 1200, 1800, 2400, 19200, 3840057600, 115200 and 230400, but do check your local PCand devices capabilities. The device is always opened withthe data format set to 8 data bits, 1 stop bit and no parity.All handshaking is turned off.

ExampleREM Read a byte from a serial portarduino=SOPEN("/dev/ttyUSB0", 115200)byte=SGET(arduino)SCLOSE(arduino)END

AssociatedSCLOSE, SGET, SGET$, SPUT, SPUT$, SREADY

Page 140: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

140

SOUNDPurposePlay a synthesised sound with the specified parameters(emulates BBC BASIC SOUND command).

Syntaxsound(channel,amplitude,pitch,duration)

DescriptionThe channel is 0 to 3 with 0 being for white noise (static). Theamplitude goes from 0 to -15 where 0 is silent and -15 is fullvolume (-7 being half volume and so on). The duration is in20ths of a second, so 20 represents one second, 10 half asecond and so on. The pitch values are taken from a tablewhich can be found at the end of the manual but, middle C hasa value of 53 and each note is 4 away from the next. Note thatwhen used with a sound envelope amplitude is replaced bythe envelope number.

ExampleChannel=1Volume=-10FOR Note=1 TO 5 CYCLE

READ Frequency,DurationSOUND(Channel,Volume,Frequency,Duration)

REPEATENDDATA 89, 20, 97, 20, 81, 20, 33, 20, 61, 40

AssociatedENVELOPE, TONE

SPACE$PurposeReturns a blank string of the specified length.

Syntaxblankstring=SPACE$(number)

DescriptionReturns a string of blank spaces number characters long.

ExampleBlank$ = SPACE$(100)FOR I=1 TO 20 CYCLE

PRINT Blank$REPEATEND

Page 141: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

141

SPRITECOLLIDEPurposeDetect a sprite collision (fast bounding box)

Syntaxcollision=SPRITECOLLIDE(target)

DescriptionReturns the sprite index of the first sprite that the spriteindex target has collided with, or -1 if there is no collision.It only checks the current sprite location and this is onlyupdated after a screen update cycle so it is possible to callPLOTSPRITE() and have a sprite overlap but it not bedetected until after the update has happened on screen.

ExampleCLSRGBCOLOUR(254,254,254)RECT(50,50,101,101,TRUE)COLOUR=YELLOWCIRCLE(100,100,50,TRUE)SAVEREGION("s1.bmp",50,50,101,101)COLOUR=REDCIRCLE(100,100,50,TRUE)SAVEREGION("s2.bmp",50,50,101,101)CLS2s1=NEWSPRITE(1)s2=NEWSPRITE(1)LOADSPRITE("s1.bmp",s1,0)LOADSPRITE("s2.bmp",s2,0)FOR X=0 TO GWIDTH STEP 1 CYCLE

PLOTSPRITE(s1,X,200,0)PLOTSPRITE(s2,GWIDTH-X-100,200,0)IF SPRITECOLLIDE (s2) <> -1 THEN BREAKUPDATEWAIT(0.0005)

REPEATEND

AssociatedGETSPRITEH, GETSPRITEW, HIDESPRITE, LOADSPRITE,NEWSPRITE, PLOTSPRITE, SPRITECOLLIDEPP

Page 142: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

142

SPRITECOLLIDEPPPurposeDetect a sprite collision (pixel perfect)

Syntaxcollision=SPRITECOLLIDEPP(target,accuracy)

DescriptionThis is a slower but more accurate version of SpriteCollide.It first does do a simple bounding box test then checksrow at a time. The accuracy parameter is how many pixelsto skip both horizontally and vertically. This is from 1 to16, where 1 is "perfect" and greater than 1 is lessaccurate, but faster. This will affect the amount of visibleoverlap you get before a collision is detected.

ExampleCLSRECT(50,50,101,101,TRUE)COLOUR=YELLOWCIRCLE(100,100,50,TRUE)SAVEREGION("s1.bmp",50,50,101,101)COLOUR=REDCIRCLE(100,100,50,TRUE)SAVEREGION("s2.bmp",50,50,101,101)CLS2s1=NEWSPRITE(1)s2=NEWSPRITE(1)LOADSPRITE("s1.bmp",s1,0)LOADSPRITE("s2.bmp",s2,0)FOR X=0 TO GWIDTH STEP 1 CYCLE

PLOTSPRITE(s1,X,200,0)PLOTSPRITE(s2,GWIDTH-X-100,200,0)IF SPRITECOLLIDEPP(s2,1) <> -1 THEN BREAKUPDATE

REPEATEND

AssociatedGETSPRITEH, GETSPRITEW, HIDESPRITE, LOADSPRITE,NEWSPRITE, PLOTSPRITE, SPRITECOLLIDE

Page 143: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

143

SPRITEOUTPurposeFind out if a sprite is off screen

Syntaxresult = SPRITEOUT( sprite )

DescriptionIf the sprite is off screen then result is true otherwise it isfalse.

Examplepic = NEWSPRITE( 1 )LOADSPRITE("/usr/share/fuze/logo.bmp",pic, 0)PLOTSPRITE( pic, GWIDTH / 2, GHEIGHT / 2, 0)WHILE NOT SPRITEOUT( pic ) CYCLEADVANCESPRITE( pic, 2 )UPDATEREPEATPRINT "GONE!"END

AssociatedHIDESPRITE, PLOTSPRITE

SPUTPurposeSend a byte to an open serial port.

SyntaxSPUT(arduino,byte)

DescriptionSend a single byte of data to an open serial port.

ExampleREM Write a byte to a serial portarduino=SOPEN("/dev/ttyUSB0", 115200)SPUT(arduino,52)SPUT(arduino,50)SCLOSE(arduino)END

AssociatedSCLOSE, SGET, SGET$, SOPEN, SPUT$, SREADY

Page 144: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

144

SPUT$PurposeSend a character string to an open serial port.

SyntaxSPUT$(arduino,string)

DescriptionSend a string of characters of data to an open serial port.

ExampleREM Write a byte to a serial portarduino=SOPEN("/dev/ttyUSB0", 115200)SPUT$(arduino,"Hello")SCLOSE(arduino)END

AssociatedSCLOSE, SGET, SGET$, SOPEN, SPUT, SREADY

SQRTPurposeReturn the square root of the specified number.

Syntaxsquareroot=SQRT(number)

DescriptionReturns the square root of the argument number. This isthe opposite of multiplying a number by itself i.e. X =SQRT(X * X)

Examplefoursquared=4*4PRINT SQRT(foursquared)END

Page 145: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

145

SREADYPurposeGet the number of characters available to be read on anopen serial port.

Syntaxcount=SREADY(handle)

DescriptionReturns the number of characters available to be readfrom an open serial port. This can be used to poll thedevice to avoid stalling your program when there is nodata available to be read.

ExampleREM Read a character from a serial portarduino=SOPEN("/dev/ttyUSB0", 115200)IF SREADY(arduino) THEN

char$=SGET$(arduino)PRINT char$

ENDIFSCLOSE(arduino)END

AssociatedSCLOSE, SGET, SGET$, SOPEN, SPUT, SPUT$

STOPPurposeStop a running program.

SyntaxSTOP

DescriptionProgram execution is stopped with a message indicatingthe current line number.

ExampleINPUT "Enter the Password: ", pass$IF pass$<>"wibble" THEN

PRINT "Password Incorrect"STOP

ENDIFPRINT "Password Correct"END

AssociatedCONT

Page 146: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

146

STOPCHANPurposeStop the playing of a sound sample.

SyntaxSTOPCHAN(handle)

DescriptionThis function stops the playing of the sound sampleassociated with the handle returned by LOADSAMPLE thathas been started using PLAYSAMPLE. It cannot be resumedonce stopped.

Examplechannel=0volume=70SETCHANVOL(channel,volume)intro=LOADSAMPLE("pacman_intro.wav")PLAYSAMPLE(intro,channel,0)WAIT(3)STOPCHAN(intro)END

AssociatedLOADSAMPLE, PAUSECHAN, PLAYSAMPLE, RESUMECHAN,SETCHANVOL

STOPMUSICPurposeStop music playing completely.

SyntaxSTOPMUSIC

DescriptionStops a playing music track which cannot then beresumed.

Examplehandle=LOADMUSIC("takeoff.wav")SETMUSICVOL(70)PLAYMUSIC(handle,1)STOPMUSIC

AssociatedLOADMUSIC, PAUSEMUSIC, RESUMEMUSIC,SETMUSICVOL

Page 147: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

147

STR$PurposeReturns a string version of the supplied number.

Syntaxstring$=STR$(number)

DescriptionReturns a string in the decimal (base 10) representation ofnumber. This is useful if you want to append a number toa string. This is the opposite of the VAL function.

ExamplePRINT "The Answer is "+STR$(42)END

AssociatedVAL

SWAPPurposeSwap the value of two variables.

SyntaxSWAP(value1,value2)

DescriptionThis swaps the value of the 2 variables round. Botharguments must be the same type - i.e. Both numeric orboth string.

Examplelowest=99highest=0IF lowest>highest THEN

SWAP(highest,lowest)ENDIFPRINT "Lowest "; lowestPRINT "Highest ";highestEND

Page 148: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

148

SWITCHPurposeTest a value against many different values and executedifferent code.

SyntaxSWITCH (variable)

{ CASE value {, value }commands

ENDCASE }[ DEFAULT

commandsENDCASE ]

ENDSWITCH

DescriptionSimplify the writing of multiple IF. . . THEN. . . ELSEstatements. Rules• Every SWITCH must have a matching ENDSWITCH.• Every CASE or DEFAULT statement must have amatching ENDCASE.• Statements after a CASE statement must not run-intoanother CASE.• The constants after the CASE statement (and theexpression in the SWITCH statement) can be eithernumbers or strings, but you can’t mix both.

ExampleINPUT aSWITCH(a)

CASE 1,2PRINT "You entered 1 or 2"

ENDCASECASE 7

PRINT "You entered 7"ENDCASEDEFAULT

PRINT "You entered something else"ENDCASE

ENDSWITCHEND

AssociatedELSE, IF THEN

Page 149: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

149

TANPurposeReturn the tangent of the given angle.

Syntaxtangent=TAN(angle)

DescriptionReturns the tangent of the angle in the current angleunits. In a right-angled triangle the tangent of an angle isthe ratio of the length of the opposite side to the lengthof the adjacent side. This is a measure of the steepness ofan angle.

ExampleDEGPRINT "Tangent of 45 degrees: "; TAN(45)PRINT "ArcTangent of 1: "; ATAN(1)END

AssociatedACOS, ASIN, ATAN, COS

TONEPurposePlay a tone with the specified parameters.

SyntaxTONE(channel,volume,frequency,duration)

DescriptionThis plays a simple tone of the given frequency (1 to5000Hz), volume (%) and duration (0.01 to 20 seconds) onthe given channel.You can play multiple tones by playing them one after theother and up to three tones can be played simultaneouslyon different channels.Channel 0 is white noise and the frequency has no bearingon the sound produced.

ExampleChannel=1Volume=70FOR Note=1 TO 5 CYCLE

READ Frequency,DurationTONE(Channel,Volume,Frequency,Duration)

REPEATENDDATA 440, 1, 493, 1, 392, 1, 196, 1, 294 ,2

AssociatedSOUND

Page 150: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

150

TRIANGLEPurposeDraw a triangle on the screen.

SyntaxTRIANGLE (xpos1, ypos1, xpos2, ypos2,xpos3, ypos3, fill)

DescriptionDraws a triangle with its corners at the three given points.The final parameter, fill is either TRUE or FALSE, andspecifies filled (TRUE) or outline (FALSE).

ExampleCYCLE

COLOUR=RND(16)x1=RND(GWIDTH)x2=RND(GWIDTH)x3=RND(GWIDTH)y1=RND(GHEIGHT)y2=RND(GHEIGHT)y3=RND(GHEIGHT)f=RND(2)TRIANGLE (x1,y1,x2,y2,x3,y3,f)UPDATEIF INKEY<>-1 THEN BREAK

REPEATEND

AssociatedCIRCLE, ELLIPSE, RECT

UNTIL REPEATPurposeLoop until the specified condition is met.

SyntaxUNTIL condition CYCLE

{statements}REPEAT

DescriptionExecute the statements zero or more times until thecondition is TRUE (Not 0).Because the test is done at the start of the loop thestatements may not be executed at all

ExampleREM Print 1 to 10count=1UNTIL count>10 CYCLE

PRINT countcount=count + 1

REPEATEND

AssociatedBREAK, CONTINUE, CYCLE, CYCLE REPEAT, FOR REPEAT,REPEAT UNTIL, WHILE REPEAT

Page 151: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

151

UPDATEPurposeUpdate screen graphics.

SyntaxUPDATE

DescriptionWhen plotting graphics, they are actually plotted to aseparate off-screen working area, so if you write aprogram that does lots and lots of graphical actions, thenyou may not see the display being updated. The UPDATEprocedure forces the working area to be copied to thedisplay. An update is also performed automatically if yourprogram stops for input, or when you PRINT a new line.

ExampleREM Moire patternsCLSGH=GHEIGHTGW=GWIDTHCYCLE

CLSCOLOUR=RND(15)+1x=RND(GW)y=RND(GH)FOR w=0 TO GW-1 STEP 3 CYCLE

LINE(x,y,w,0)LINE(x,y,w,GH-1)

REPEATFOR h=0 TO GH-1 STEP 3 CYCLE

LINE(x,y,0,h)LINE(x,y,GW-1,h)

REPEATUPDATEWAIT(3)

REPEATEND

AssociatedUPDATEMODE

Page 152: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

152

VALPurposeReturns the number represented by a character string.

Syntaxnumber=VAL(string$)

DescriptionReturns the number represented by string$. This is theopposite of the STR$ function.

Examplenow$ =TIME$hh=VAL(LEFT$(now$, 2))mm=VAL(MID$(now$, 3, 2))ss=VAL(RIGHT$(now$, 2))elapsed=hh*3600+mm*60+ssPRINT "Seconds since midnight: "; elapsedEND

AssociatedSTR$

VLINEPurposeDraws a vertical line.

SyntaxVLINE (ypos1,ypos2,xpos)

DescriptionDraws a vertical line on column xpos, from row ypos1 torow ypos2.

ExampleCLSCOLOUR=redFOR xpos=0 TO GWIDTH STEP 100 CYCLE

VLINE(0, GHEIGHT, xpos)REPEATUPDATEEND

AssociatedHLINE, LINE, LINETO

Page 153: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

153

VTABPurposeSet/Read the current text cursor vertical position.

SyntaxVTAB=valuevalue=VTAB

DescriptionSet/Read the current text cursor vertical position.

ExampleCLSFOR ypos = 0 TO THEIGHT CYCLE

VTAB=yposPRINT VTAB

REPEATVTAB=0END

AssociatedHTAB, HVTAB

WAITPurposeWaits for the specified time to elapse.

SyntaxWAIT(time)

DescriptionThis waits (does nothing) for time seconds. This may be afractional number, but the accuracy will depend on thecomputer you are running it on, however delays down to1/100th of a second should be achievable.

ExampleREM COUNT 10 SecondsCLSSeconds = 0FOR I=1 TO 10 CYCLE

WAIT(1)Seconds=Seconds + 1HVTAB(10,10)PRINT Seconds

REPEATPRINT "Elapsed "; TIME/1000END

Page 154: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

154

WHILE REPEATPurposeLoop while the specified condition is met.

SyntaxWHILE condition CYCLE

{statements}REPEAT

DescriptionExecute the statements zero or more times while the conditionis TRUE (Not 0). Because the test is done at the start of the loopthe statements may not be executed at all.

Examplehandle=OPEN("whiletest.txt")FOR r=0 TO 10 CYCLE

PRINT# handle,"Record ";rREPEATCLOSE(handle)handle = OPEN("whiletest.txt")WHILE NOT EOF(handle) CYCLE

INPUT# handle, record$PRINT record$

REPEATCLOSE (handle)END

AssociatedBREAK, CONTINUE, CYCLE, CYCLE REPEAT, FOR REPEAT,REPEAT UNTIL, UNTIL REPEAT

Built-in Variables andConstants

EDITCOLS ...................................................................155FADING ......................................................................155FALSE .........................................................................156GET ............................................................................156GET$ ..........................................................................157GHEIGHT ....................................................................157GWIDTH .....................................................................158INK .............................................................................158MOUSEX ....................................................................159MOUSEY.....................................................................159PAPER ........................................................................160PI................................................................................160SEED...........................................................................161TANGLE ......................................................................161THEIGHT.....................................................................162TIME...........................................................................162TIME$.........................................................................163TRUE ..........................................................................163TWIDTH......................................................................164UPDATEMODE ...........................................................164

Page 155: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

155

EDITCOLSPurposeTurn edit colouring on/off.

SyntaxEDITCOLS=TRUE | FALSE

DescriptionSwitches the highlighting of syntax in the editor on or off.If it is set to TRUE then the following colours can be set:editColNum - Colour for numberseditColStr - Colour for stringseditColKeyw - Colour for keywordseditColVar - Colour for variables/functionseditColRem - Colour for commentseditColArith - Colour for Arithmetic operatorseditColRel - Colour for relational operators

ExampleEDITCOLNum = PinkEDITCOLStr = OliveEDITCOLKeyw = AquaEDITCOLVar = GreyEDITCOLRem = YellowEDITCOLArith = SilverEDITCOLRel = RedEDITCOLS = TRUE

FADINGPurposeReports TRUE while fading is active

SyntaxFADING

DescriptionDuring the fadeOn or fadeOff functions the fadingvariable returns TRUE. Once a fade has completed thevalue is FALSE

ExamplePAPER=0INK=1CLSPRINT "LOADING..."FADEOFFWHILE FADING = true CYCLE

UPDATEREPEATFADEONWHILE FADING = true CYCLE

UPDATEREPEATEND

AssociatedFADEOFF, FADEON

Page 156: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

156

FALSEPurposeRepresent the logical "false" value.

SyntaxFALSE

DescriptionRepresents a Boolean value that fails a conditional test. Itis equivalent to a numeric value of 0.

Examplecondition = FALSEIF condition = FALSE THEN

PRINT "Condition is FALSE"ENDIFIF NOT condition THEN

PRINT "Condition is FALSE"ENDIFPRINT "Condition= ";conditionEND

AssociatedTRUE

GETPurposeGet a single character code from the keyboard.

Syntaxasciicode=GET

DescriptionThis pauses program execution and waits for you to type asingle character on the keyboard, then returns the valueof the key pressed as a numeric variable (ASCII).

ExamplePRINT "Press a key"key = GETPRINT "ASCII Value of key = "; keyEND

AssociatedGET$, INKEY

Page 157: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

157

GET$PurposeGet a single character from the keyboard.

Syntaxkey$ = GET$

DescriptionThis pauses program execution and waits for you to type asingle character on the keyboard, then returns the key asa string variable.

ExamplePRINT "Press a key"key$ = GET$PRINT "You Pressed Key: "; key$END

AssociatedGET, INKEY

GHEIGHTPurposeFind the current height of the display.

Syntaxheight=GHEIGHT

DescriptionThis can be read to find the current height of the displayin either high resolution or low resolution pixels.

ExampleREM Draw a circle in the centre of thescreenCLSCOLOUR = blueCIRCLE(GWIDTH/2,GHEIGHT/2,50,TRUE)UPDATEEND

AssociatedGWIDTH, ORIGIN, SETMODE

Page 158: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

158

GWIDTHPurposeFind the current width of the display.

Syntaxwidth=GWIDTH

DescriptionThis can be read to find current width of the display ineither high resolution or low resolution pixels.

ExampleREM Draw a circle in the centre of thescreenCLSCOLOUR = blueCIRCLE(GWIDTH/2,GHEIGHT/2,50,TRUE)UPDATEEND

AssociatedGHEIGHT, ORIGIN, SETMODE

INKPurposeSet/Read the current text foreground colour.

Syntaxforegroundcolour=INKINK=foregroundcolour

DescriptionSet/Read the current text foreground (ink) colour.

ExamplePAPER=blackCLSstring$="This is multicoloured text"FOR I=1 TO LEN(string$) CYCLE

INK=I MOD 15 + 1PRINT MID$(string$,I-1,1);

REPEATINK=whitePRINTEND

AssociatedPAPER

Page 159: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

159

MOUSEXPurposeTo find the mouse X position

Syntaxvalue = MOUSEX

DescriptionReturns the X position of the current mouse location

ExampleCYCLEPRINTAT(0,0); "Mouse X Position="; MOUSEX;" "REPEAT

AssociatedGETMOUSE, MOUSEOFF, MOUSEON, MOUSEY,SETMOUSE

MOUSEYPurposeTo find the mouse Y position

Syntaxvalue = MOUSEY

DescriptionReturns the Y position of the current mouse location

ExampleCYCLEPRINTAT(0,0); "Mouse Y Position="; MOUSEY;" "REPEAT

AssociatedGETMOUSE, MOUSEOFF, MOUSEON, MOUSEX,SETMOUSE

Page 160: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

160

PAPERPurposeSet/Read the current text background colour.

Syntaxbackgroundcolour=PAPERPAPER=backgroundcolour

DescriptionSet/Read the current text background (paper) colour.Clear screen (CLS) will set the entire background to thiscolour.

ExamplePRINT "Text background colour "; PAPERPAPER=REDPRINT "Text background colour "; PAPERPAPER=7PRINT "Text background colour "; PAPEREND

AssociatedINK

PIPurposeReturns the value of the constant pi.

Syntaxvalueofpi=PI

DescriptionReturns an approximation of the value of the constant piwhich is the ratio of a circle’s circumference to itsdiameter (approximately 3.141592654) which is widelyused in mathematics, specifically trigonometry andgeometry.

ExamplePRINT FN AreaOfCircle(12)ENDDEF FN AreaOfCircle(withRadius)

LOCAL resultresult=PI*withRadius*withRadius

= result

Page 161: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

161

SEEDPurposeSeed the random number generator.

SyntaxSEED=value

DescriptionThis can be assigned to initialise the random numbergenerator, or you can read it to find the current seed.

ExampleSEED=10PRINT RND(100)SEED=10REM Will print the same numberPRINT RND(100)REM Will print a different numberPRINT RND(100)END

AssociatedRND

TANGLEPurposeRead or set the current angle of the turtle.

Syntaxangle=TANGLETANGLE=angle

DescriptionThis can be read or assigned to and represents the currentangle of the turtle when using turtle graphics mode (in thecurrent angle units)

ExampleCLSORIGIN(GWIDTH/2,GHEIGHT/2)CLOCKFOR I = 1 TO 60 CYCLE

TANGLE = IMOVETO(0,0)PENDOWNMOVE(100)

REPEATEND

AssociatedLEFT, MOVE, MOVETO, PENDOWN, PENUP, RIGHT

Page 162: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

162

THEIGHTPurposeThe height in characters of the display.

Syntaxheight=THEIGHT

DescriptionThe height in characters of the display.

ExampleCLStext$="This text is centred in the screen"HVTAB((TWIDTH-LEN(text$))/2,THEIGHT/2)PRINT text$END

AssociatedTWIDTH

TIMEPurposeFind out how long the program has been running.

Syntaxtime=TIME

DescriptionThis returns a number which represents the time thatyour program has been running in milliseconds.

ExampleREM Simple reaction timerWAIT(2)REM Make sure no key pressedWHILE INKEY<>-1 CYCLEREPEATstime=TIMEPRINT "Go!"WHILE INKEY=-1 CYCLEREPEATetime = TIMEPRINT "Your reaction time is ";PRINT etime-stime; " milliseconds"END

Page 163: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

163

TIME$PurposeReturns a string with the current time.

Syntaxnow$=TIME$

DescriptionThis returns a string with the current time in the followingformat: HH:MM:SS. For example: 18:05:45.

ExamplePRINT "The time now is ";PRINT TIME$END

AssociatedDATE$

TRUEPurposeRepresents the logical "true" value.

SyntaxTRUE

DescriptionRepresents a Boolean value that succeeds a conditionaltest. It is equivalent to a numeric value of 1 (in factanything other than 0 evaluates to TRUE)

Examplecondition=TRUEIF condition=TRUE THEN

PRINT "Condition is TRUE"ENDIFPRINT conditionEND

AssociatedFALSE

Page 164: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

164

TWIDTHPurposeThe width in characters of the display.

Syntaxwidth=TWIDTH

DescriptionThe width in characters of the display.

Exampletext$="This text is centred horizontally"HTAB=(TWIDTH-LEN(text$))/2PRINT text$END

AssociatedTHEIGHT

DescriptionThe updateMode determines when the screen is redrawn.Redrawing the screen takes a little time and will slowdown a program if you do it too often. The value of themode parameter can be 0, 1, or 2 as follows:0- automatic updates do not happen. Nothing will bedrawn on the screen until the UPDATE command is issued.1-This is the default mode whereby an UPDATE happensautomatically when you output a new line, or the screenscrolls.2-The screen is updated after every PRINT instructionwhether it takes a new line or not.

ExampleCLSINPUT "Update Mode? ",modeIF mode>=0 AND mode<=2 THEN

PRINT "Press space to exit"WAIT(1)UPDATEMODE=modeCYCLE

PRINT "Hello World ";REPEAT UNTIL INKEY=32UPDATE

ELSEPRINT "Invalid Update Mode"

ENDIFWAIT(1)END

AssociatedUPDATE

UPDATEMODEPurposeSet the video update mode.

SyntaxUPDATEMODE=mode

Description (overleaf)

Page 165: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

165

scanBackspacescanTabscanClearscanReturnscanPausescanEscapescanSpacescanExclaimscanQuoteDblscanHashscanDollarscanAmpersandscanQuotescanLeftParenscanRightParenscanAsteriskscanPlusscanCommascanMinusscanPeriodscanSlashscan0

scanAscanBscanCscanDscanEscanFscanGscanHscanIscanJscanKscanLscanMscanNscanOscanPscanQscanRscanSscanTscanUscanV

scanDownscanRightscanLeftscanInsertscanHomescanEndscanPageupscanPagedownscanF1scanF2scanF3scanF4scanF5scanF6scanF7ScanF8scanF9scanF10scanF11scanF12scanF13scanF14ScanF15scanNumLock

scanCapsLockscanScrolLockscanRShiftscanLShiftscanRCtrlscanLCtrlscanRAltscanLAltscanRMetascanLMetascanLSuperscanRSuperscanModescanComposescanHelpscanPrintscanSysReqscanBreakscanMenuscanPowerscanEuroscanUndo

ScanKeyboard values

scan1scan2scan3scan4scan5scan6scan7scan8scan9scanColonscanSemiColonScanLessScanEqualsscanGreaterscanQuestionscanAtscanLeftBracketscanBackSlashscanRightBracketscanCaretScanUnderscorescanBackQuote

scanVscanWscanXscanYScanZscanDeletescanKP0scanKP1scanKP2scanKP3scanKP4scanKP5scanKP6scanKP7scanKP8scanKP9scanKpPeriodscanKpDividescanKpMultiplyscanKpMinusscanKpPlusScanKpEnterScanKpEqualsscanUp

Page 166: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

166

Notes & Octaves for Sound function

Octave NumberNote 1 2 3 4 5 6 7

B 0 49 97 145 193 241A# 0 45 93 141 189 237

A 41 89 137 185 233G# 37 85 133 181 229

G 33 81 129 177 225F# 29 77 125 173 221

F 25 73 121 169 217E 21 69 117 165 213

D# 17 65 113 161 209D 13 61 109 157 205 253

C# 9 57 105 153 201 249C 5 53 101 149 197 245

Page 167: Programmer’s Reference Guide - FUZE · FUZE Keyboard Most keys on the keyboard are self explanatory. I have marked a few of the special keys in case you are unsure what they are:

fuze.co.uk

FUZE BASICProgrammer’s reference guide£14.99 / $24.99 / €21.99

FUZE BASICProgrammer’s Reference Guide