Variables on a theme System variables are bytes in memory which help the Spectrum remember certain things it needs to know about itself- if you like, the housekeeping routines. Delve deeper into the Spectrum ROM with Dilwyn Jones in two articles which investigate the complete available set of system variables, giving comprehensive guidelines as to what you can and can't do with them. This article is extracted from Dilwyn Jones' book, Beyond Simple Basic - Delving Deeper Into Your ZX Spectrum. http://www.users.globalnet.co.uk/~jg27paw4/yr02/yr02_78.htm http://www.users.globalnet.co.uk/~jg27paw4/yr03/yr03_97.htm ==================== PART ONE The system variables are bytes in the Spectrum ROM which allow the computer to know all the things it should do to operate in the way you've come to expect. The information, such as how the Spectrum's memory is laid out, is held in the system variables in these addresses so that the computer can get hold of it and update it as and when required. We can make use of the information stored in these memory locations in our programs, either by reading information already there or changing it to make the computer do something it might not otherwise do, or sometimes do it more easily. Not all of them are that much use to us. And certainly not all of them ought to be changed. Some will cause the computer to crash, or the computer may simply ignore you. Some can be happily changed under certain circumstances only, and most within strict limitations. I hope to give you some guidelines as to what can and can't be done, but hopefully you will learn your own little PEEKs and POKEs in time as well. 23552 to 23559 KSTATE reading the keyboard -------------------------------------------- When the processor is interrupted (50 times every second in the UK normally) one of the things done is to read the keyboard and store the results here. The bytes have different uses. Not all can be practically used by the programmer. You can use this program to examine what's going on in the eight bytes of KSTATE. Run it and press various keys to see what effect individual keys have, such as the Shift keys, and what effect going from one key to another has. 10 FOR A=23552 TO 23559 20 POKE 23692,0: REM KEEP SCROLLING 30 LET B=PEEK A 40 PRINT A; TAB 10;B; TAB 20;CHR$ B AND B>31 50 NEXT A 60 GO TO 10 The first four bytes of KSTATE deal with something called 'two key rollover' which allows you to press a second key before you actually let go of the first. The descriptions given to the main four bytes, 23556 to 23559, will apply to the first four also as long as you bear in mind that these only come into operation for two key rollover. PEEK 23556 can return the code of the upper case version of the key pressed, so if you pressed Symbol Shift A you would get the code of 'A', not the code of 'a' nor the code of 'STOP'. This may be useful where it is essential that upper case be entered, etc. The effect of pressing a key is temporary and lasts only as long as the key is being pressed. The value in 23556 would be 255 if no key was being pressed at the time the interrupt had occurred. For the Enter key, a value of 13 is returned. For the Space key, a value of 32 is returned. Pressing both Shift keys simultaneously produces 14. This program will demonstrate this: 10 LET A=PEEK 23556 20 POKE 23692,0 30 PRINT A, CHR$ A AND A>31 40 GO TO 10 23557 ------------------------------------------ is used for timing to prevent intermittent key contact, etc, causing problems - known as keyboard de- bouncing. 23558 ------------------------------------------ is the auto repeat timer which times the pause before the keys start repeating, then the pause between repeats once the key has actually started repeating. The delays used are those in the system variables that hold these delays (23561/2). 23559 ------------------------------------------ contains the code of the last character pressed on the keyboard. This depends on whether the Shift keys were pressed or not. The numbers produced are those that would be returned by PRINT CODE INKEY$ except that these are the last key pressed and not necessarily the key currently being pressed. Try this program to display what can happen - RUN it and try pressing various keys making use of the Shift keys. 10 LET A=PEEK 23559 20 POKE 23692,0 30 PRINT A, CHR$ A AND A>31 40 GO TO 10 See also under 23611 FLAGS. 23560 LAST_K Newly pressed key ------------------------------------------ Every time the keyboard is scanned, a key is found to have been pressed and proved valid, the value of this system variable is updated. Its content is the code of the last key pressed. This system variable does not really do much you could not do with INKEY$, except that it could be used to type ahead one character. If you try this program, you will find that if you press a key when invited to do so, the key is indicated on the screen in a short while even though the program may not have got as far as line 50 when you pressed a key. The code of the last key pressed is stored here and stays here until another key is pressed. It is possible to test for a newly pressed key by examining bit 5 of the system variable FLAGS 23611. This would be '1' for a key just pressed. 10 PRINT "Press a key now" 20 FOR A=1 TO 900 30 NEXT A 40 CLS 50 LET A=PEEK 23560 60 PRINT A: IF A>31 THEN PRINT CHR$ A This could be used for testing for a y/n (yes or no) type situation - if you knew one was coming up, you could indicate your response before the program got there and the program would respond when it got round to it. Also, if two keys were pressed simultaneously, the program would respond if one were released without having to wait for the keyboard to be released completely. Control characters can be generated using Caps Shift in conjunction with the number keys. Enter returns 13. Pressing both Shift keys together returns 14. To see this, try this program: 10 LET A=PEEK 23560 20 PRINT A, CHR$ A AND A>31 30 GO TO 10 23561 REPDEL Repeat delay ------------------------------------------ This system variable contains the length of time that a key must be held down before it starts to auto-repeat. The time delay in the UK is one-fiftieth of a second and starts off at 35/50 of a second. You can happily POKE this if, for instance, you want the key to start repeating immediately. The cursors become rather difficult to control if you, say, POKE 23561,1. POKE 23561,0 effectively turns off the auto-repeat, actually giving a delay of about five seconds like POKE 23561,255. 23562 REPPER delay between repeats ------------------------------------------ This system variable controls the length of time between repeats once the auto- repeat has actually begun. The time is in fiftieths of a second in the UK. If you effectively want to turn off the auto- repeat for any reason, POKE 23562,0 or POKE 23562,255 gives about five seconds between repeats. If you wish to edit long program lines (eg. a long PRINT statement) then POKE 23562,1 will speed up moving the cursor to the right place. But beware of changing 23562 too much at the same time or you may speed up the cursor so much it becomes difficult to control. Its normal value is 5/50 to a second or one tenth of a second. 23563/4 DEFADD ------------------------------------------ The address of the argument of a user- defined function in a program; ie. if you had DEF FN A(B) in a program line, the value in 23563/4 would be the address of the letter B in the brackets in that line while only the function is being used. The best way to PEEK into 23563/4 to show this is to put the PEEK as a part of the FN to be evaluated as there is always a zero there unless the function is being evaluated. So the line: 10 PRINT PEEK 23563+256*PEEK 23564 would always return zero. On the other hand: 10 DEF FN A(B)=PEEK 23563 + 256*PEEK 23564 20 PRINT FN A(999) would return the address of the B in line 10. The 999 is not significant, just something to actually give a value to B to prevent an error. In the case of a function with no argument: 10 DEF FN A()=PEEK 23563 + 256*PEEK 23564 20 PRINT FN A() this would print the address of the closed bracket symbol. 23568 to 23605 STRMS ------------------------------------------ The first 14 bytes on a basic Spectrum contain addresses relating to channels and streams. Streams -3 to +3 are stored in two bytes each. 23606/7 CHARS ------------------------------------------ This system variable has as normal values: 23606 contains 0 ------------------------------------------ 23607 contains 60 ------------------------------------------ This system variable points to the start of the character set that the computer uses for printing on the screen and the printer. SCREEN$ also uses this system variable. The normal address pointed to is 15360 which is 256 less then the address of the start of the ROM character set. (256 less because the character generator is accessed by something similar to PEEK 23606 + 256 * PEEK 23607 + CODE "A" * 8 and since the first character is a space, and the code of a space is 32 you can see that 8 * 32 is 256). The character generator is 768 bytes long, so if you wish to set up a new character set you must set aside this number of bytes in case it is overwritten by Basic - you wouldn't get a crash, you'd just end up with gibberish. Mention was made of SCREEN$ using this system variable - in fact, you may be aware of the problem that SCREEN$ does not recognise user- defined graphics normally, unless they happen to be similar to an existing Spectrum character. In fact, SCREEN$ works by picking up the address of the start of the character generator and looking through the table until it finds a matching character. Now since the Spectrum screen is bit-mapped rather than memory-mapped like some computers, once anything is printed on the screen it stays the same even if you change the character in memory. So we could temporarily change the pointer to the character set to point to the user- defined graphics and look up there. One snag is that although there is a system variable that tells us where the user-defined graphics start, this address is 256 or more - so we must subtract 256. This conveniently means we subtract one from the high byte. This program should demonstrate: 10 FOR X=144 TO 164 20 PRINT AT 0,0; CHR$ X 30 POKE 23606, PEEK 23675 40 POKE 23607, PEEK 23676-1 50 PRINT AT 20,0; SCREEN$ (0,0) 60 PAUSE 40 70 POKE 23606,0 80 POKE 23607,60 90 NEXT X What we did was make the computer think the user-defined graphics are the normal character set. SCREEN$ will still produce characters with codes of 32-127, although this is easily overcome with a bit of fiddling. Since SCREEN$ starts off with CHR$ 32 and the UDGs start off at 144, we would need to add 112 to return characters in the range of the user-defined graphics. Here is one way to do this. X is the x co-ordinate across the screen and Y is the y co-ordinate down the screen of the location SCREEN$ is to examine. A check is first of all made that SCREEN$ does not find one of the normal characters there, then returns if one is found. The character at Y,X is returned in A$. Line 8025 is needed only if you are using a character set other than the ROM one. If you are using the ROM character set, then delete line 8025 and replace lines 8070 and 8080 with the alternative versions that follow. 8000 REM SCREEN$ FOR UDGs 8010 LET A$=SCREEN$ (Y,X) 8020 IF A$()="" THEN RETURN 8025 LET A=PEEK 23606: LET B=PEEK 23607 8030 POKE 23606, PEEK 23675 8040 POKE 23607, PEEK 23676-1 8050 LET A$=SCREEN$ (Y,X) 8060 IF A$()<>"" THEN LET A$=CHR$ (CODE A$+112) 8070 POKE 23606,A 8080 POKE 23607,B 8090 RETURN 8070 POKE 23606,0 8080 POKE 23607,60 The story does not finish there. There are only 21 user-defined graphics - if SCREEN$ does not find a match, it will continue looking up past the user-defined graphics until it has finished looking for the 32 to 127 range it thinks it's looking for. This could be embarrassing if there just happened to be some data stored above the UDGs for any reason which resembled any character. To help prevent this happening, although the UDGs are normally at the top of RAM anyway, this line could be added: 8065 IF A$>CHR$ 164 THEN LET A$="" Incidentally, you should ensure that 23606/7 always points to the right character set when PRINTing, LISTing, etc, is done. 23608 RASP ------------------------------------------ Controls the duration of the buzz that sounds to warn you that you are running out of memory. At switch-on, this has a value of 64. This can be altered, but there seems little point. POKE 23608,0 gives a very short click rather than a buzz - useful if you hate the buzz that satirically mocks you when you run out of memory. Alternatively, POKE 23608,255 gives a very long buzz which immobilises the keyboard, preventing you typing any further than when the buzz sounded. 23609 PIP ------------------------------------------ Controls the length of the click emanated when a key is pressed in command mode or during an INPUT. It starts off at zero but may be changed. Any value between 30 and about 130 gives a pleasant, more audible bleep rather than the quieter click normally given. Values high than 130 tend to noticeably slow down the keyboard response (since computing stops as the bleep is sounded). Usually, the one to use is POKE 23609,100. 23610 ERR_NR ------------------------------------------ Controls error report number and normally has a value of 255 unless an error arises, when it contains one less than the error report codes printed, eg. for error 4, out of memory, it would contain a three. The message printed out is contained in ROM starting at address 5010 decimal. The end of the message is signified by the last character in the message having bit 7 set to a one. After the error message comes the '© 1982 Sinclair Research Ltd.' message that you see after switch-on or NEW. You can POKE 23610 to generate an error to stop the program, but since the message printed is fixed and in ROM, you may end up with garbage. If you wanted to simulate an 'out of memory' error you would end a program with POKE 23610,3. This would not work as any program line; you'd have to ensure that it was the last line, as once a condition arises to end a program, only then is 23610 looked at to determine what is printed. 23611 FLAGS ------------------------------------------ This system variable contains various flags controlling the Basic system and generally should not be POKEd. However, some of the flags can be usefully PEEKed. Bit 0: Being a one indicates no space to be printed before the next keyword. Bit 1: This bit being set to a one indicates that the print output is to be send to the printer. A zero would mean it is to be sent to the TV screen. Bit 5: Any newly pressed key is indicated by its code being stored in 23560 (the LASTK system variable) and bit 5 of 23611 (FLAGS) is set to indicate that a new key has been pressed. Bit 7: Syntax flag. These will be of more use when using ROM routines in a machine code program. 23613/4 ERR_SP ------------------------------------------ Keeps track of the address on the machine stack where the appropriate return data lies. Try calling a few GOSUBs with no matching RETURNs and watch this point down the memory. Now you can see what happens and why this occurs when you run out of memory in a situation like this. Also, try PEEKing the contents of the three addresses (the base of which is pointed to by 23613/4) to see what return data actually consists of. 10 LET A=PEEK 23613 + 255*PEEK 23614 20 PRINT PEEK A; TAB 10; PEEK (A+1); TAB 20; PEEK (A+2) 23617 MODE ------------------------------------------ Specifies cursor. Values zero, one, two or four specify the L/C mode, E mode, G mode or K mode respectively. POKEing this system variable will affect the appearance of the cursor - it may appear as a flashing letter, number, symbol or even a keyword. This is most apparent during an INPUT statement. The value is reset when the need arises, eg. a mode change made normally from the keyboard. So if you get into difficulties, press both Shift keys for E mode and then the same again to get back to normal L/C mode. Try this program which POKEs all possible values into 23617. Most are variants on the four cursors, ie. you will find yourself in a particular mode after the POKE, such as everything coming as graphics as in G mode. 252 will give an L/C mode flashing '<' to point to where you're typing ... 10 FOR A=0 TO 255 20 PRINT A 30 POKE 23617,A 40 INPUT A$ 50 NEXT A 23618/9 NEWPPC and 23620 NSPPC ------------------------------------------ 23618/9 is a two-byte system variable containing the line number of the line to be jumped to. 23618 contains the lower byte of the line number and 23619 the higher, so the line number contained is read as PEEK 23618 + 256 * PEEK 23619. To POKE a line number in, say line X: POKE 23618, X-256*INT (X/256) POKE 23619, INT (X/256) We now come to system variable 23620. With 23618/9 and 23620, we could actually simulate a GO TO command to a statement within a program line, should that ever be necessary. GO TOs cannot access individual statements within long program lines. To jump to statement four in line X, first go through the motions described above then POKE 23620,4 and the jump is executed. 23624 BORDCR ------------------------------------------ By POKEing various values into this system variable you could achieve a flashing, bright, multicoloured lower screen, or make both PAPER and INK the same colour to prevent other people getting at your programs - however, any alteration would have to be made blind. You could also make INPUTs extra bright to stand out. Table 1.1. The bits of system variable 23624 control the attributes of the lower screen and the BORDER colour. BIT7 BIT6 BIT5 BIT4 BIT3 BIT2 BIT1 BIT0 FLASH lower BORDER colour lower screen and lower screen lower screen INK screen BRIGHT PAPER 23627/8 VARS ------------------------------------------ The pointer to the start of the variables store. Apart from finding your way into the variables area, you can find the length of the Basic program with this expression. This excludes screen, system variables, stacks and variables. LET bytes=PEEK 23567 + 256*PEEK 23628 - PEEK 23635 - 256*PEEK 23636 23629/30 DEST ------------------------------------------ The address of the variable when it is assigned to. If the variable had been set up before, it would point to the start of where it was stored in the variables area. If it was being defined for the first time, it would point to the address of the start of the name of the variable in the program, eg. in 10 LET A = 5, it would point to the address of the letter A. It can also be used to find the memory address of a numeric variable, if you use something like LET A=A as in the following program: 10 LET A=5 20 LET A=A 30 PRINT PEEK 23629 + 256*PEEK 23630 23631/2 CHANS ------------------------------------------ Stores the address of where the channel information area starts. 23633/4 CURCHL ------------------------------------------ The address of INPUT/OUTPUT information used at that moment. It normally points during an INPUT/ OUTPUT operation to a five byte block of data in the channel information area. Use this program to examine the contents. 1 FOR X=0 TO 3: PRINT #X; PEEK 23633 + 256*PEEK 23634: NEXT X: PAUSE 0: STOP ==================== PART TWO In the last issue of Your Spectrum, an investigation was made of the system variables, 23552 through to 23634. Here we continue with a study of the remaining system variables, 23635 to 23689. For the uninitiated, the system variables are bytes in the Spectrum ROM which tell the computer the things it needs to know to act in the way you've come to know and love. Information, such as how the memory map is laid out, is held in the system variables so that the computer can access it and update it as and when required. 23635/6 PROG ------------------------------------------ The address of the start of the area in memory where the Basic program is stored. This points to the first byte of the line number of the first program line. This may be useful if you're converting programs for other Sinclair Research computers with information held as a REM statement in the first line of a program. See also under VARS above. If you wish to 'security lock' a line into a program, then by means of this system variable you could POKE a zero into both bytes of a line number at the start of a program. Program lines start with a two-byte line number. 23637/8 NXTLIN ------------------------------------------ The address of the start of the next program line. You could use this to enable you to access machine code stored within REM statements anywhere in the program, eg. those loaded with MERGE from a tape library of subroutines. These would have their own local calls to machine code like this: 9000 LET A=USR (PEEK 23637 + 256*PEEK 23638+5) 9010 REM <> MACHINE CODE <> 9020 RETURN One constraint to this is that you should not include any colour, flash, brightness, etc, control characters into the REM statement or they may be interpreted as machine code, upsetting things somewhat. However, if used from a library of subroutines, these would not normally be used anyway. 23639/40 DATADD ------------------------------------------ This contains the address of the comma ending the last item of data. If nothing was read from the list (eg. after RUN or restored, etc) the address held in 23639/40 is the address of the byte before the program area, normally the CHR$ 128 at the end of the channel information area. To demonstrate try RUNing this program: 10 DATA "1","2","3","4","5" 20 LET A=PEEK 23639 + 256*PEEK 23640 30 PRINT A; TAB 9; PEEK A; TAB 18; CHR$ PEEK A AND PEEK A>31 40 READ B$ 50 GO TO 20 23754 128 23763 44 , 23767 44 , 23771 44 , 23775 44 , 23779 13 The address in this two-byte system variable can point to the Enter character or the colon signifying the end of the line or statement containing the data - the address of the terminator of the last item of data. 23641/2 E_LINE ------------------------------------------ This system variable points to the start of the area above the variables. From this we can gain an idea of how much memory is used in bytes by screen, system variables, program and variables, once the program has been RUN to set up the variables, etc. Type this in, as a direct command: PRINT PEEK 23641 + 256*PEEK 23642-16384 We can also tell how much room is used for variables once the program has been RUN to set up the variables. Use the command: PRINT PEEK 23641 + 256*PEEK 23642 - PEEK 23627 - 256*PEEK 23628 23653/4 STKEND ------------------------------------------ This system variable contains the address of where the spare part of memory starts. From reading this we can gain an idea of how much memory we have left by subtracting it from RAMtop. This will not include memory used for the machine GOSUB stacks but includes the length of the PEEK statement. So this is only a fairly accurate guide ... but one which is adequate from most circumstances. PRINT PEEK 23730 + 256*PEEK 23731 - PEEK 23653 - 256*PEEK 23654 23658 FLAGS2 ------------------------------------------ This system variable contains some flags used (normally) by the computer to indicate certain conditions. The best use we can make of this is to utilise the flag indicated by bit 3. This being a one indicates Caps Lock on or Caps Lock engaged. What use is that? Consider in a program using INKEY$; eg. in a menu of options in a filing program, we often need to know whether the operator is pressing a certain key. If the operator is invited to press 'Y' for Yes or 'N' for No, they may press 'y' for Yes or 'n' for No - mixing up lower case and upper case capitals. Most often this would depend on whether Caps Lock was engaged - people are not interested in upper or lower case and whether they press 'y' or 'Y' they expect the computer to understand as humans would. But the computer doesn't really appreciate that. So if we engage Caps Lock ,automatically, our worries are over and we have a simpler program which doesn't have to check (as far as it's concerned) two separate options for each choice. It is tempting to use the Basic statement POKE 23658,8 to engage Caps Lock and POKE 23658,0 to dis- engage it. But this will affect the other flags, so do check their state first unless you know they are not any particular value. Normally in L mode, 23658 has a value of zero so it is generally OK to use the POKEs above. You are not likely to cause crashes, but some funny effects may be caused in rare cases. When the printer buffer is empty, bit 1 will be zero. 23659 DF_SZ ------------------------------------------ This system variable contains the number of lines in the lower section of the screen, normally used for INPUTs, error reports and so on. Normally this would be a two, except for when a long INPUT prompt is displayed, etc. If a value of zero is POKEd in, normally to attempt to clear this unused part so that we can use the whole 24 lines of the screen, the computer crashes. However, this can be done within a few restrictions. These are that we must ensure the lower part of the screen is restored to normal before any use is made of this - so to break out of a program would be somewhat catastrophic! Also, errors generated within the course of a program will have the same effect since the error report would have to be printed out. Here is a short listing to demonstrate the use of line 22 and 23 on the screen. Unfortunately, it only works for PRINT or PRINT TAB as we cannot use PLOT down here and PRINT AT will only work down to line 22. The screen is restored to normal by POKE 23659,2 within the program. 10 POKE 23659,0 20 FOR A=0 TO 23 30 PRINT A 40 NEXT A 50 PAUSE 0 60 POKE 23659,2 To demonstrate what can go wrong, let us generate an error by adding this line to the program: 45 PRINT error Oops!!! If you just want to PRINT on the bottom two lines it is usually better to use PRINT #1; "text" which works just as well if not better, without such a risk of causing a system crash. If you POKE a value greater than two into DF_SZ the upper screen will become smaller than normal. So after POKE 23569,Y the upper screen would be 24-Y rows down and would scroll when the PRINT position got to or beyond 24-Y,0. This program shows how a part screen scroll can be maintained with DF_SZ and SCR_CT. Here, random numbers appear and scroll up the top 14 lines of the screen only. 10 POKE 23692,0: POKE 23659,10 20 PRINT RND 30 GO TO 10 23670/1 SEED ------------------------------------------ When RANDOMIZE (number) is used, the number (a constant or a variable) is stored in this system variable. This is the number that determines the next random number. It opens up the possibility of cheating, since you could work out the next (supposedly) random number generated and use the knowledge gained to 'swing' luck your way. For example, after RANDOMIZE 1, the next value of RND would be (0.0022735596, INT (RND *6) + 1) to simulate a die being thrown as a one. 23672/3/4 FRAMES ------------------------------------------ This is a frame counter which can be used as a timer. It counts frames of a TV picture and so is incremented fifty times a second in the UK, or every 0.02 seconds, although the time taken to actually read and evaluate these three bytes of the timer may not allow it to be used to this accuracy. It has a timing range of nearly four days (actually about three days 21¾ hours). The manual (chapter 18) points out that you need to read the value of these three bytes twice in succession and take the high value for full accuracy because of the possibility of the values of the three changing while being read in such a way as to cause large inaccuracies. It must be emphasised that the timer bytes are in the opposite order to what you might expect - the most significant byte is 23674, so the timer values are read by: 65636*PEEK 23674 + 256*PEEK 23673 + PEEK 23672 which returns time in units of fiftieths of a second. There are several things that affect the accuracy of this timer. Using BEEP stops the timer. Using the printer and loading/saving, etc, also affect its accuracy. However, the use of PAUSE is OK as this only waits a specified time without re-setting or stopping the timer. 23675/6 UDG ------------------------------------------ The address of the start of the dot patterns for the user-defined graphics is normally 32600 on a 16K Spectrum or 65368 on a 48K Spectrum. This number is the same as USR "a", so PRINT USR "a" corresponds to: PRINT PEEK 23675 + 256*PEEK 23676 Compulsive POKEers can have fun with this one. The manual suggests changing this to save space by having fewer user-defined graphics. However, it is also possible to do the reverse, and set up more than one user- defined graphics set if required; however, only one set of 21 can be in use at any one time. Remember that since there are 21 UDGs it is necessary to set aside 21*8 (168) bytes for each separate set of UDGs and POKE the start addresses, into 23675/6, of the character set in use. For fun, type in the following commands: POKE 23675,96: POKE 23676,127 (16K Spectrum) POKE 23675,96: POKE 23676,255 (48K Spectrum) Then, using the user-defined graphics (they normally appear as capital letters until re-defined) try to type out a message. I'll leave you to find out what happens. One useful tip: once you've set up a user-defined character set it may be SAVEd on tape. Most people would type something like: SAVE "chars" CODE 32600,168 Fine, but you have to specify the start addresses. You could use SAVE "chars" CODE(PEEK 23675 + 256 * PEEK 23676), 168, and then you could happily save the current set of UDGs on tape without knowing the address of where they start. This would, for example, allow you to LOAD a character set SAVEd from a 16K Spectrum back into a 48K Spectrum without having to know the addresses. To get a character set back into the right place on a machine with different amounts of memory, simply use LOAD "chars" CODE(PEEK 23675 + 256 * PEEK 23676),l68. This would automatically re-locate data to the right address for the machine in use at the time. This is the same as LOAD "chars" CODE USR "a", which saves a bit of typing although it may look a bit strange. 23679 P_POSN ------------------------------------------ Contains information about how far across the printer buffer the LPRINT position has got to. Contains (33- column number) for columns 0 to 31. You cannot change the LPRINT position by POKEing this alone. 23680 PR_CC ------------------------------------------ Contains the low byte of the address where the next character is to go into the printer buffer, ie. this will contain (23296 + LPRINT column numberer), being zero for the left column of the printer, 15 for the 15th column etc. Because this is the address of the top row of dots of each character, you can POKE this to change the LPRINT buffer position provided you change the value in P_POSN (23679) to match. It may appear to work if you don't do this, but problems will be encountered at the end of the line. 23681 Unused system variable ------------------------------------------ This system variable, although strictly speaking unused, usually contains 91. This is the high byte of the LPRINT buffer address (91*256 is 23296 where the buffer starts). This can be POKEd for your own use but using the printer will overwrite it back again to 91. 23680/1 together contain the address of the LPRINT position in the printer buffer. You will not affect the working of the printer if you POKE 23681, but anything stored here may be over- written by the printer routines. 23677/8 COORDS ------------------------------------------ 23677 is the system variable that contains the x co-ordinate of the last plotted point. After CLS it starts off at zero and 23678 is the system variable that contains the y co-ordinate of the last point plotted. It contains the actual value, so if the last point plotted was 3,3 both bytes would contain threes. These two can be POKEd with valid x and y co-ordinates respectively. Since POKEing these does not actually PLOT anything on the screen, this is a convenient way to move the PLOT cursor around. This could be done by PLOT OVER 1;X,Y: PLOT OVER 1;X,Y - but would be messy. Amongst other things this could simulate MOVE found in other BASICs - useful if you wanted to draw lines from around a particular point. 23684/5 DF_CC ------------------------------------------ The address in the display file of the PRINT position. It may be POKEd to send the PRINT output elsewhere although this requires an understanding of the way the display file is organised. 23688/9 SPOSN ------------------------------------------ 23688 contains information concerning how far across the screen the PRINT position has got. It starts off as 33 for the left-hand side of the screen and decreases by one every time the PRINT position moves one place to the right. After using PRINT AT Y,X; (if Y and X are valid PRINT AT co-ordinates) 23688 would contain 33-X. This can be useful when trying to prevent words being chopped in half when printed on the screen. If you imagine the number in 23688 as counting down towards zero as there is no more room on the current line, you can see that comparing this to the length of the word to be printed gives us an idea of whether it is necessary to move to a new line to prevent the word being chopped Suppose the word to be printed was W$: IF PEEK 23688