Control Statements, Loops, and SubroutinesIn the previous lesson we mentioned that the NO$ZX81 emulator’s default setup lets you enter a number of special characters from their regular position on a standard PC keyboard (rather than having to remember where they are found on an actual ZX81 keyboard). But sometimes we might want, or need, to resort to the standard ZX81 keyboard layout, so how do we change the keyboard type? On starting up NO$ZX81 click on the Options menu, then Emulation Setup and you’ll probably see that Key Translation is set to Automatic. From the drop list you’ll see that Original ZX Keyboard is an option. For now we can leave it at Automatic, but we’ll switch keyboard options when needed from this window, which can be accessed by using the F11 key. First we need
to go to the Run menu and select Run, then load the program that we created during
the last lesson by entering the command Then add the following
lines, which use some new commands, as follows: 20
REM “THIS PROGRAM CALCULATES AREAS” REM, used in lines 20 & 2000, is used to let the computer know that the text that follows is a comment or REMark GOSUB/RETURN is used in lines 105-115, 205-215, 2000-2120, and sets up a subroutine that can be called from various places in the program (so you can easily reuse the code) IF, used in lines 2010, 2080, 2100, and 2110, lets you execute particular code based on whether a specific function evaluates as true or not FOR/NEXT, as used in lines 2060 – 2090, lets you loop a number of times through the same section of code RAND is used with the function RND; RND uses a fixed sequence of 65536 numbers, and RAND can be used to set where RND will use a start point in the sequence by assigning a number between 1 and 65535, or by using RAND 0 (or just RAND) it will use the time the system has been on, and therefore should be really random (although the way we use it, it gets called just before RND each time, so the random sequence never really gets used). The full program now
looks like: The upgrade kit (new keyboard and chip) to bring a ZX80 up to near ZX81 standard Copyright www.LaraAcademy.com
|
|