Expanded Basic Nine new commands for Spectrum Basic, courtesy of Robert Newman I have written a machine-code routine which adds nine new commands to Spectrum Basic which will run with or without Interface 1. The machine-code routine must be loaded and initialised before either writing a program, or loading a program which uses the new commands. If you do this it is not necessary to save the machine code again when you save your program. A short Basic program, listing 1 (16K) or listing 2 (48K), is used to load the machine code above RAMtop, and perform the initialisation. This program should be typed in, and then saved on a cassette or Microdrive cartridge to auto-run from Line 3. If you use a Microdrive, the program can be given the filename "run", ie: SAVE *"m";1;"run" LINE 3 or SAVE "BASIC+" LINE 3 New the computer, then type in and Run Listing 3, the machine code loader program. Copy the machine code bytes from either listing 4 or 5 depending upon memory size. Great care must be taken while copying from the machine code dump, since a single mistake could cause the computer to crash. You should now have a working copy of the Basic+ inter- preter. To test it, rewind the take and clear the computer by typing Randomise USR 0. Then load the initialisation program and machine code, and type *ZAP which should pro- duce a laser type sound effect. Graphic characters *USE (Nchars), (Memory): (Nchars) is the number of diffe- rent graphic characters that you want to use, and can take values from 1 to 255. (Memory) is the memory size in bytes needed for storing those characters. To calculate the number of bytes required to store each character, divide its width by 8, and add 1 for any remainder, then multiply by its height. This command causes part of the memory to be reserved for the storage of your graphics characters. The total number of bytes required is (Memory) + (Nchars)*4 bytes. For example, the command *USE 8,256 reserves 288 bytes. If you try to reserve more memory for your graphics than the spare memory available, this will halt your program with a run- time error. The graphics memory area is situated just before the start of the machine code. If necessary, RAMtop will be lowered - and the machine stack and Gosub stack moved - to make room for the graphics memory. The routine will only lower RAMtop, and never moves it to a higher address. This is to allow your own machine-code routines to be used with extended Basic provided that they are located between the graphics memory and RAMtop. The *Use command clears the graphics memory and character size definitions - see *Def - and can be used more than once in a program for this purpose. If there is no *Use command in a program, the command *USE 8,256 is assumed by the routine. *DEF (Char), (Width), (Ht): After *Use, the *Def command is used to set the size of a graphics character. (Char) is the character number, which can take values from 1 to (Nchars). (Width) and (Ht) are the sizes of this character in pixels - from 1 to 256 pixels wide, and from 1 to 176 pixels high. You mist set the size of a character before using it in one of the remaining commands, which are:- *GET (char), (xpos), (ypos) *PUT (char), (xpos), (ypos) *CLR (char), (xpos), (ypos) Lines 2,3 and 4 of the initialisation program can be deleted once the machine code has loaded, but you must not delete line 1, otherwise none of the new commands will be recognised when you Run your program. During runtime, if the command cannot be executed, the error message produced is code Q - "Parameter error". *BRK 0 and *BRK 1: These commands allow the break key to be disabled (*BRK 0), or re-enabled (*BRK 1). [Note that the parameter has to be a literal 1 or 0. An expression with the value 1 or 0 won't be accepted.] *ZAP: This command gives a laser-type zap sound. *NSE (Length): This command gives white noise for a time depending upon (Length) which can take values from 1 to 255. Depending upon the length, this can sound like an explosion, gunshot etc. A machine-gun type sound can be made using a loop - eg., FOR j=1 TO 10: *NSE 50: PAUSE 10: NEXT j *SCR (Paper), (Ink): This command changes the Paper and Ink colours of the screen without erasing its contents. Paper and Ink can take values from 0 to 9 as with the normal colour commands. The remaining commands are concerned with printing of user-defined graphics. These can be copied from the screen into graphics memory with *Get and then printed anywhere on the screen with *Put. The routine can handle graphics of any size from 1 by 1 pixels to 256 by 176 pixels, and caters for up to 255 different graphics characters. First, you need to decide how much memory you want to set aside for the storage of graphics characters. This is done with the *Use command. In all three commands, (Char) is the character number - the size of which must have previously been defined with *Def. (Xpos) and (Ypos) are the pixel co-ordinates of a point on the screen at the top left hand corner of the area from where the graphic character information is to be copied from, printed to, or erased. The *Get command will copy a character from the speci- fied position on the screen, and store it in the graphics memory. It can then be printed anywhere on the screen using *Put. If the values of (Xpos) and (Ypos) cause part of the character to go over the edge, then it will wrap-around to the opposite side of the screen. The *Clr command can be used to erase a character, or alternatively it can be used to clear a window on the screen. For example, the instructions *DEF 1,16,16: *GET 1,0,175: *PUT 1,240,15 would copy an area of the screen 16 by 16 pixels in size from the top left of the screen to the bottom right. [ And finally something about the TZX. This starts with the extended Basic itself, in both 48k and 16k versions. The 16k version will not work on a 48k machine. Mr. Newman also provided two demonstration programs, and these follow on the TZX. They assume that the BASIC+ machine code has been loaded, but work with either size memory. The first, "Demo", is a demonstration of all of the new commands. The second I have called "Game"; it is a 15-tiles puzzle. To run either demo program, load the desired version of BASIC+, then simply load the demo over the top. There is no need to retain line 1 in this case, since both demos have it included, so they will simply auto-run. By the way, you may have noted that the demo programs use the commands in lower case, while the article gives them in capitals or mixed case. In fact, the system will accept any case combination. Richard Bos, May 2012. ]