BeyondHor {%;=9600%:9000(#:p(23681\)=01000 p(23681\)  992 &n(aK\)=a+256*(a+1) *:" BEYOND HORIZONS " #'''" LIST OF CHAPTERS" &''"1 Introduction and instructions" "2 CPU needs RAM" "3 How the computer counts" "4 ADDRESSING the memory" ""5 How the memory is organised" $"6 The Display File" ."7 The Attributes" 8$"8 System variables-Introduction" B"9 SVs for mapping memory." L"10 PEEKing & POKEing SVs" `"11 Looking at memory bytes" t/''1;" SPECTRUM MEMORY INTRODUCED " ~!"  East London Robotics 1983"  9700% ?"Enter Chapter you require ";a$:9300T$:(e)1200 +bord=a$:bord8bord=bord-8 a$=1a$=a$+" " bord>11 1200  9000(# bord j=160< p$(j)=a$23681\,j:p(j) j  1200 F.21,0;"f=forward b=back i=index" P7n(23653e\)-n(23627K\)<2009000(# U""1365U Z=""1370Z da$= n"a$"f"a$"b"a$"i"1365U x@a$="f"ƾ23681\<59;23681\,23681\+1 ?a$="b"ƾ23681\223681\,23681\-1 a$="i"1000  9400$ e=11350F p(23681\) .s=23:bin=a$:r2=0:h$="ABCDEF" 8,1;"HEX" i=012 4 i6s=21 /r1=((bin/16-(bin/16))*16) &r19 8,s-i;1;r1 -r19 bin=(bin/16):1495 r1>9 r2=r1-9  r2=0k$="0":1490 k$=h$(r2r2) 8,s-i;1;k$ bin=(bin/16) i  *:4;"HOW TO USE THIS PROGRAM" ]'"BEYOND HORIZONS has chapters andpages. You have already learned how to choose a chapter." "o'"At the end of each page you can go back to the previous page, onto the next one, or return to the index" 'H'"To turn ";1;"forward";0;" a page press ";1;"f" ,H'"To turn ";1;"back";0;" a page press ";1;"b" 1H'"To return to the ";1;"index";0;" press ";1;"i" 6d'"Try turning forward and back. You cannot change the chapter without returning to the index." ; 1350F r':4;"STOPPING THE PROGRAM" w['"Sometimes you are invited to enter your own programs or to try a few experiments." |T'"Whenever this occurs, the main program stops RUNning and a STOPreport appears." 7'"If you simply wish to carry on, enter CONTINUE" '"But if you have been RUNning your own program or messing around in some way and wish to return to where this program stopped, enter GOTO 999" '"Try them both now." !"THE PROGRAM HAS NOW STOPPED":  1350F  e=0 &:6;"EMERGENCY PROCEDURE" '''"On occasions you will be asked to interfere with the operating system. If you get lost and cantrestore normality, GOTO 999 willusually fix it. If not, you may have to reload." {'''"Use GOTO 999 even if you cant read what you are writing."''"Now press ENTER (or f & ENTER toescape this page.)" e $e=1:z$:z$="f"1350F 9236077\,61=:23693\,254:1701  1350F -:0,6;"PEEKING AND POKING" '"Some of the remaining 16 pins determine whether DATA is being READ or WRITTEN. Until you come to write machine code, however, it is necessary only to grasp that it does work, not yet HOW it works." Z'"In BASIC, PEEKing an address means looking at the number"'"stored in that address." @'"POKEing an address means puttinga number into that address." ='"PEEK and POKE give you enormous power over the computer." ) 1350F .!:" A NOTE ON PROCEDURE" 86,0;"Next time you press f, this program will stop running."::"You will be asked to enter your own programs. Your line numbers can be anything from 1 990." B|'"Before proceeding be sure you know the procedure for leaving and returning to the program as explained in Chapter 1." L 1350F `%:6;"PEEKING AND POKING" b23728\,0 dc'"At the moment this program is not using the byte whose addressis 23728. Enter the following:" h/"PRINT PEEK 23728 then ";1;"CONTINUE" jN::"The number 0 is stored there, so PEEK 23728=0":22720X,250 o=:"Now enter the following:"'" POKE 23728,110 then CONT": t4:"Now enter:"::" PRINT PEEK 23728 then CONT": yi=22624`X22626bX:i,250:i:'"As you can see, PEEK 23728 is now 110....Because 110 is what you POKEd into it." {E:"This technique is used a great deal in the following chapters." }p'"Note that the expression ""PEEK 23728"" is considered to be a"'"number. Try entering ""PRINT PEEK23728*2""" ~ 1350F :" PROGRAMS FOR PEEKING MEMORY"''"You should now enter your own program for PEEKing a series of addresses in number order."''"Use a FOR.....NEXT loop and makeit ask you for the first addressand the last address." Y'"Use the program to print out the first 20 addresses of ROM with their contents." /:"GOTO 999 to get back here"'"afterwards.": 1350F :5;"A VERY USEFUL PROGRAM"''"The PEEK program should look"'"something like this."''"10 INPUT ""1st address"";x"'"20 INPUT ""Last address"";y"'"30 FOR i=xy: PRINT i,i: NEXT i" f::"If you did not succeed, enter and RUN the program now. Don't forget ""GOTO 999"" to return." :"CONT to continue": 1350F !:9 ;"BITS AND BYTES" Τ:"The smallest element of memory is a BIT. A BIT is a point whichcan hold an electrical charge. The electrical charge held by a BIT can be either HIGH or LOW." L:"If a BIT is HIGH the CPU reads it as a 1. If LOW, it is read as 0."; P" BITS are organised into groups of eight. These groups are called BYTES." :"Text, numbers, instructions, variables, routines, graphics and anything else you might everwant to put into the computer must be converted to BYTE-sized groups of HIGH and LOW BITS." 1350F 5:0,4;"HOLDING NUMBERS IN BYTES" :"There is absolutely no way the memory can retain numbers exceptas combinations of HIGH and LOW BITS organised into BYTES." 0'"A BIT can only hold two numbers: - 0 and 1!" '"Because of this all numbers are converted to ""BINARY"" before being stored, and converted backinto DECIMAL before being displayed." e'"So if you want to intervene directly in the memory, you willhave to learn to count in BINARY" # 1350F (":8;"WHAT IS BINARY?" 2C:"There follows a practical demon-stration of BINARY in action." <^:"The next page shows the machine counting, starting from 0, in both decimal and binary." Fm:"When you have completed this chapter, have a look at AppendixE (page 219) of the Spectrum manual." P~:"You must remember the highest numbers which can be held by 1 BYTE and 2 BYTES. Write them down when you know them." U 1350F Zb(16): \^10 ,0;"MSB means MOST SIGNIFICANT BYTE LSB means LEAST SIGNIFICANT BYTE" ^T:"Notice that it is normal to number the BITS from 0 to 7 fromright to left." `9:"Compare the DECIMAL number with the BINARY pattern." b&:"Hold down f to continue program." dj=065535 hbin=j:9500% j="f"2970 :1350F nj p 1350F s:9500% uT12 ,0;"Can you find the highest number that can be held by TWO BYTES?" x2900T :a$=""2970 yQ16,12 ;" ":a$="65535"16,12 ;1;"CORRECT" { 2677u }{12 ,0;"Try entering your own numbers, starting with low ones."''"Can you predict what the BITS will show?" 2900T :a$=""2970 2685} t12 ,0;"Try entering 2^0, 2^1, 2^2.........2^15.(See your manual page 65if you don't understand ""^"")" E:"Can you see the reason for the BIT-numbering system of 0 to 7?" 2900T :a$=""2970 2750 T12 ,0;"Can you find the highest number which can be held in one BYTE?" *2900T :16,12 ;" " 1a$="255"16,12 ;1;"CORRECT" a$=""2970 2770 12 ,0;"The highest number which can be held by one BYTE is 255. But 0 is also a number, so there is a maximum of 256 numbers." /:"Try entering 1*256, then 2*256 and so on." 2900T :a$=""2970 2790 T="f"2900T ^3"Enter a number (or just ENTER to continue)";a$ e619,0;" " h a$="" |9300T$:(e)2910^ Wbin=a$:binɺbin19,0;1;"Whole numbers only please":2910^ Lbin6553619,0;1;bin;" is too high for 2 BYTES" 9500%  Si=10 21:i,0;" ":i:1350F ':5;"ROUTINES FOR THE CPU" &'"The CPU is a highly ingenious device but it does not think."''"""All"" it can do is carry out theinstructions it finds in memory." +;'"It can only carry out one tiny instruction at a time." 0'"When a computer appears to be intelligent, it is because the CPU is reading a clever program from memory."''"So the interaction between CPU and memory is the basis of"'"computing." I 1350F N:9 ;"RAM AND ROM" S:"When you switch on, the CPU starts to READ the memory from the beginning to the end and obeys EVERY INSTRUCTION IT FINDS" XS'"It starts with the Sinclair ROM which, step by step, sets up a usable system." b|:"The same circuitry is used for communicating with both ROM and RAM. It's just MEMORY as far as the CPU is concerned."; l"The ONLY differences are that ROM doesn'tget rubbed out when you switch off and if you WRITE TO ROM it will have no effect." v 1350F ):"KNOW THE COMPUTER BY ITS MEMORY" o''"So if you know what memory (ROM or RAM) contains, you are well on the way to understanding yourcomputer." '"Learning about your computer's memory is the first major step beyond BASIC."''"BEYOND HORIZONS will help you take that step." 1350F H!:10 ;"A NOTE ON HEX" R:"Machine code programmers have toenter their programs BYTE by BYTE. Any number above 255 has to be broken down into separate BYTES before it can be entered." \T:"It is also often necessary to know which BITS are HIGH and which are LOW." f:"It is extremely tedious to entereverything in BINARY (all those ones and noughts!) so a system called HEXADECIMAL is used." z 1350F :10 ;"HEXADECIMAL" z:"If Adam and Eve had had eight fingers on each hand, our basic counting unit would probably nowbe 16 instead of 10." #"16 would then be written ""10""" \:"When counting the fingers from 9upwards, they would have called them 9,?,?,?,?,?,?,10." Q"HEX people have 16 fingers. Theycall them"''"1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,10" &:"Compare decimal with HEXADECIMAL" *:"DECIMAL 8,9,10,11,12,13,14,15,16" (" HEX 8,9, A, B, C, D, E, F,10" 1350F :bin=0:a$="0"  9500% ! 1450 $12 ,0;"Computers can count up to 15 on four BITS. The contents of each eight-BIT BYTE can therefore be described by only 2 HEX symbols." .2900T :a$=""1350F 8 3617! (:5;"ADDRESSING THE MEMORY" t'"When you switch the Spectrum on,the CPU starts to read, BYTE by BYTE, from the beginning of memory onwards." '"It carries out every instructionit reads. Even ""0"" is read and loaded into one of the CPU's"'"registers. 0 is, in effect, an instruction to the CPU to read the next BYTE." W'"The CPU must have a system for locating each BYTE in memory, - all 65536 of them." D'"So each BYTE is given its own permanent number, - an ADDRESS."  1350F ':" ADDRESS LINES AND DATA LINES" 8'"You have seen that 16 BITS can hold 65536 numbers." r'"So you will now understand why 16 of the CPU's soldered"'"connections to the circuit boardare ADDRESS LINES!" '"When a number is put onto these lines, the BYTE whose address isheld by the ADDRESS LINES is called, either for READING FROM or WRITING TO." '"8 more of the CPU's soldered connections carry the DATA, theygo HIGH or LOW according to the BITS in the BYTES and REGISTERS."  1350F :9800H& 13,2;"ADD-";4,2;"RESS" "70,1;" ";1,1;" " 6u6,4;"0";9 ,3;"TO";12 ,2;"16383";15,3;"IS";17,3;"ROM" @!0,17;"THE ROM" Jo2,10 ;"The ROM occupies the";3,10 ;"first 16384 (16k)";4,10 ;"addresses." TU6,10 ;"The first 7k contains";7,10 ;"the OPERATING SYSTEM." ^Q9 ,10 ;"The BASIC INTERPRETER";10 ,10 ;"uses the next 8k" h)12 ,10 ;"The final 1k holds a";13 ,10 ;"CHARACTER GENERATOR.";14,10 ;"All the bit patterns";15,10 ;"for standard letters";16,10 ;"are held there and are";17,10 ;"called by ROM routines";18,10 ;"whenever required." r 1350F |:9800H& 15,1;"" *0,12 ;"THE DISPLAY FILE" )15,13 ;"THE ATTRIBUTES" J3,2;"16384";9 ,3;"TO";13 ,2;"22527" U16,2;1;"22528";17,3;"TO";18,2;"23296" ֠3,10 ;"This occupies the";4,10 ;"first 6k of RAM.The";5,10 ;"contents are always";6,10 ;"shown on the screen." ۣ8,10 ;"It is written to by";9 ,10 ;"the CPU, and READ by";10 ,10 ;"the ULA, which creates";11 ,10 ;"the TV picture." 16,10 ;"This file holds";17,10 ;"instructions about INK";18,10 ;"and PAPER colour,";19,10 ;"FLASH, BRIGHT etc."  1350F :9800H& 7,1;"" ,1,10 ;"THE PRINTER BUFFER" &2,10 ;"If the printer is";3,10 ;"being used, this holds";4,10 ;"the current line of";5,10 ;"text to be printed." (.7,10 ;"THE SYSTEM VARIABLES" *K8,2;"23552";12 ,3;"TO";17,2;"23733" 0I3,2;"23296";4,3;"TO";5,2;"23551" :9 ,10 ;"These are loaded with";10 ,10 ;"information by the";11 ,10 ;"Operating System when";12 ,10 ;"you switch on. They";13 ,10 ;"are in RAM (not ROM)";14,10 ;"because they change." D16,10 ;"If you change them,";17,10 ;"you can affect the";18,10 ;"way the computer";19,10 ;"operates." I 1350F b:9800H& l':" A QUICK TRIP THROUGH MEMORY" vs'"This chapter runs through the memory from Address 0 to Address65535 so that you know where everything is." {610 ,1;"FIXED AND VARIABLE ADDRESSES" 12 ,0;"The first section deals with those areas of memory with fixedaddresses. They are always in the same place. The second part deals with those areas of memorywhich vary in both size and location."  1350F 5:0,0;" FIXED ADDRESSES" 3,1;"MEMORY ";4,1;" AREAS ";5,1;" FROM ";6,1;"ADDRESS";7,1;" 0 ";8,1;" TO ";9 ,1;" 23733 ";10 ,1;" ARE ";11 ,1;" FIXED " .i=12 20:i,1;" ":i 2,10 ;"The addresses of the";3,10 ;"ROM, the DISPLAY";4,10 ;"FILE, the ATTRIBUTES,";5,10 ;"the PRINTER BUFFER and";6,10 ;"the SYSTEM VARIABLES";7,10 ;"are fixed." 9 ,10 ;"They are fixed by the";10 ,10 ;"design of the circuit";11 ,10 ;"board and ULA, and";12 ,10 ;"because the addresses";13 ,10 ;"are written into ROM" 15,10 ;"The size of these";16,10 ;"areas of memory does";17,10 ;"not change. The TV";18,10 ;"screen, for example,";19,10 ;"always needs the same";20,10 ;"number of bytes."  1350F .:i=07:i,1;" ":i ߁8,1;" AREAS ";9 ,1;" OF ";10 ,1;"MEMORY ";11 ,1;" FROM ";12 ,1;"ADDRESS";13 ,1;" 23734 ";14,1;" TO ";15,1;" 65535 ";16,1;"VARY IN";17,1;" SIZE ";18,1;" AND ";19,1;" PLACE " ,0,10 ;"VARIABLE ADDRESSES" 2,10 ;"The size of areas of";3,10 ;"memory in the rest of";4,10 ;"RAM depend on the size";5,10 ;"of the BASIC program,";6,10 ;"number of variables";7,10 ;"held, and so on." L9 ,10 ;"These keep changing";10 ,10 ;"as you go on." 12 ,10 ;"The Operating System";13 ,10 ;"must keep track of";14,10 ;"where one area ends";15,10 ;"and the next begins." 17,10 ;"It keeps a note of";18,10 ;"these locations (in";19,10 ;"constant change) among";20,10 ;"the System Variables."  1350F  /:i=020:i,1;" ":i 11 ,1;" CHANS ";12 ,1;" ";13 ,1;" ";14,1;" ";15,1;1;"" L12 ,2;"23734";13 ,3;"TO";14,2;"23754" m5,2;"SYST";6,2;"VARS";7,2;1;"END AT";8,2;"23733" 16,2;"BASIC";17,2;"PROG";18,2;1;"STARTS";19,3;"AT";20,2;"23755" )0,10 ;"MICRODRIVE MAPS"  2,10 ;"Unless you have a";3,10 ;"Microdrive fitted,";4,10 ;"this area will not be";5,10 ;"used, so forget about";6,10 ;"it. It uses no bytes";7,10 ;"at all." *-9 ,10 ;"CHANNEL INFORMATION" 4I11 ,10 ;"Unless you have a";12 ,10 ;"Microdrive fitted this";13 ,10 ;"area always occupies";14,10 ;"21 bytes. It is used";15,10 ;"to control input from";16,10 ;"the keyboard and out-";17,10 ;"put to the screen";18,10 ;"and printer." 9F18,23;"It is not";19,10 ;"dealt with here." > 1350F H:9800H& Rf0,14;"THE BASIC PROGRAM";14,1;" VARS ";2,1;" PROG " \f7,2;"BASIC";9 ,2;"PROG";15,2;"VARI-";17,2;"ABLES" f2,10 ;"When you switch on,";3,10 ;"this area uses no";4,10 ;"bytes. It expands as";5,10 ;"you enter your program";6,10 ;"and pushes other areas";7,10 ;"into higher addresses." pN9 ,10 ;"Its first address is";10 ,10 ;"usually 23755." z-13 ,13 ;"THE VARIABLES AREA" 15,10 ;"Both the first address";16,10 ;"and the size depend on";17,10 ;"the length and content";18,10 ;"of the BASIC Program."  1350F :9800H& M0,14;"EDITING AREA";1,13 ;"AND WORKSPACE" 2,10 ;"These areas form";3,10 ;"a sort of workshop for";4,10 ;"the Operating System.";6,10 ;"The EDIT area uses 3";7,10 ;"bytes and expands to";8,10 ;"hold any line being";9 ,10 ;"entered or edited." 11 ,10 ;"The WORKSPACE uses no";12 ,10 ;"bytes unless it is in";13 ,10 ;"use.(eg for an INPUT)" 15,10 ;"The CALCULATOR STACK";16,10 ;"is a notepad for";17,10 ;"temporarily holding";18,10 ;"numbers during calc-";19,10 ;"ulations." ʕ4,2;"EDIT";5,2;"AREA";8,2;"WORK";9 ,2;"SPACE";13 ,2;"CALC";14,2;"STACK" s2,1;" E LINE";7,1;" WORKSP";11 ,1;" STKBOT";16,1;" STKEND" .i=1720:i,1;" ":i  1350F :9800H& V0,1;"L ";1,1;"STACK";2,1;"STKEND " 6,2;"SPARE";9 ,3;"RAM";15,1;"";16,3;"M/C";17,2;"STACK" 77,1;" ";8,1;" " (0,15;"THE SPARE AREA" @2,10 ;"When you switch on,";3,10 ;"most of the RAM is";4,10 ;"spare. Each byte from";5,10 ;"the top of the calc-";6,10 ;"ulator stack to the";7,10 ;"bottom of the MACHINE";8,10 ;"STACK is loaded with 0";9 ,10 ;"by the CPU." 11 ,10 ;"As the BASIC and";12 ,10 ;"variables areas grow";13 ,10 ;"they push the calc";14,10 ;"stack towards the M/C";15,10 ;"stack." 17,10 ;"The machine stack";18,10 ;"also grows into the";19,10 ;"spare RAM. When RAM is";20,10 ;"full, the stacks meet."  1350F $.:i=05:i,1;" ":i .76,1;" ";7,1;"" 8i=813 :i,1;" ":i:11 ,1;"";14,1;" RAMTOP";14,1;1;"_______";15,1;" UDG ";18,1;" P RAMT" =K16,1;1;" ";17,1;1;" " B8,3;"M/C";9 ,2;"STACK";12 ,2;"GOSUB";13 ,2;"STACK";16,2;"U-DEF";17,2;"GRAPH" Lr1,3;"S A";2,3;"P R";3,3;"A E";4,3;"R A";5,3;"E" Q19,2;"65535" V+0,12 ;"THE MACHINE STACK" `2,10 ;"This is a notepad for";3,10 ;"the CPU. You need";4,10 ;"to know Machine Code";5,10 ;"to use it properly." j)7,13 ;"THE GOSUB STACK" oT9 ,10 ;"This holds return line";10 ,10 ;"numbers from GOSUB";11 ,10 ;"routines. The last one";12 ,10 ;"to go ON is always";13 ,10 ;"the first one to come";14,10 ;"OFF. That's why RETURN";15,10 ;"always goes back to";16,10 ;"the most recent GOSUB." t18,10 ;"USER DEFINED GRAPHICS";19,10 ;"168 bytes above RAMTOP";20,10 ;"so not affected by NEW" ~ 1350F :9800H& W0,10 ;"MEMORY LOCATIONS AND";1,10 ;" SYSTEM VARIABLES " W3,1;" CHANS ";7,1;" PROG ";15,1;" VARS " 3,10 ;"Some of the SYSTEM";4,10 ;"VARIABLES (SVs) are";5,10 ;"used to keep track of";6,10 ;"the addresses where";7,10 ;"memory areas start or";8,10 ;"end. Each SV has been";9 ,10 ;"given a name." 11 ,10 ;"In the following";12 ,10 ;"pages, SVs for memory";13 ,10 ;"mapping are shown as";14,10 ;"in the examples here." o16,10 ;"Look at your manual";17,10 ;"page 165 for a Memory";18,10 ;"Map."  1350F #:7;"THE DISPLAY FILE" '"Each one of the 6k Display File bytes corresponds to a position on the screen. Try POKEing a fewaddresses from 16384 to 22527 with different numbers."''"CONT to continue" ::'"Unfortunately the bytes are not laid out in numerical sequence from top to bottom."'"When you press ENTER, 255 will be POKEd into each byte in turn and you will see how they are arranged." 6:"This is the program:"''"i=1638422527:i,255:i"  4"f+ENTER to avoid RUNning";z$:z$="f"1350F #21,19;"Address=" Ji=16384@22527W:i,255:21,27;1;i:i (:5100 2):5;"USING THE DISPLAY FILE" <'"The BASIC commands ";216;252;246;169;"are excellent on the Spectrum. POKEing direct to thescreen is not often worthwhile." F'"If you want to it is not too difficult to write programs to get over the problem of the odd screen layout, but they need a lot of arithmetic."''"This one draws a line across thescreen:" P'"k=02:j=07:i=07" Z&"16384+j+k*2056+j*32+i*256,128/2^i" d "i:j:k" n%"ENTER to RUN.f+ENTER to CONT ";z$ xz$="f"1350F 9k=02:j=07:i=07 G16384@+j+k*2056+j*32 +i*256,128/2^i  i:j:k 16,0;"Notice that a complete byte mustbe written each time so anythingalready in that byte gets rubbedout. "  1350F !:7;"THE ATTRIBUTES" '''"Bytes 22528 to 23296 are scannedfor colour and other display information. Each byte controls a character-sized square on the screen. The layout is in addressorder." S'"This program will POKE the byteswith any number you choose. Try a few out now." %'"Remember that 255 is the maximum" &19,0;"Try ""(*255)""" E"Enter a number (or just ENTER to continue)";a$:a$=""1350F e=15335 ܖ:10 ,0;"Now POKEing ATTRIBUTES with ";a$:14,12 ;"Address=":i=22528X23295Z:n=a$:i,n:14,20;i:i  5300 %:7;"THE ATTRIBUTE BITS" fi=4182:i,2;"";i+1,2;" ":i:20,2;"" =i=07:i*2+5,1;1;i:i 5,7;"The 1st 3 bits specify";6,7;"the INK colour (numbered";7,7;"as on the keyboard.)" 11 ,7;"The next 3 specify the";13 ,7;"the paper colour.";16,7;"Bit 6 is set at 1 for";17,7;"BRIGHT and 0 for normal";18,7;"Bit 7 is 1 for FLASH and";19,7;"0 for normal" "D"Enter a number(or just ENTER to continue)";a$:a$=""1350F '#9300T$:e=15410" )bin=a$:c=bin ,Ji=031:2,i;"I":i:j=22592@X22623_X:j,c:j 6Ob(8):i=18:9100#:3+2*i,4;b(i):i @ 5410" J*:5;"THE PERMANENT COLOURS" T'"You will have noticed that afteryou POKEd the ATTRIBUTE bytes, the screen colours reverted to normal as soon as anything was overprinted." ^'"The ATTRIBUTE bytes get their orders from System Variables"'"(ATTRP at 23693, MASKP at 23694 ATTRT at 23695 & MASKT at 23696)" h-'"Try POKEing these with a few numbers." r'"Notice that the ATTRIBUTE bytes retain the same numbers on the screen until overprinted. ie thecontents of the SVs are not seen"'"until the system PRINTs" w:1350F |*:"INTRODUCTION TO SYSTEM VARIABLES" '"The SVs are an integral part of the OPERATING SYSTEM and the numbers they hold are referred to constantly by the CPU as it carries out its routines." t'"They occupy addresses 23552 to 23733. When the computer is"'"switched on they are all set to standard numbers." '"All the SVs are listed on pages 173 to 176 of your manual. Referto this list as you go along."''"These chapters demonstrate the most useful SVs and show you howto experiment with the rest."  1350F (:" SVs NEED TO BE ABLE TO CHANGE" '"Consider these two types of SVs:"'"LAST K (23560) holds character code of key last pressed."'"PIP (23609) specifies length of the keyboard blip." '"LAST K is held among SVs becauseit must change constantly."'"PIP is in SVs so that the user can change it if he wants to. It could have been put in ROM!" ¹'"POKEing SVs must be done with great care, particlularly the 1st type, as you can crash the system. You cannot damage the computer, and the system can be reset by unplugging."  1350F -:3;"SVs WHICH GIVE INFORMATION" '"You can PEEK a lot of SVs to find out what is going on. Some of the most useful are those"'"mentioned in chapter 5 giving the addresses of boundaries"'"between memory areas." '"You can find out how much memoryyou have used at any time, how much is program, how much is"'"variables, and how much is spare" k'"Remember that ""23627"" is treated as a number, so you can use it in Expressions and"'"Functions."  1350F ":8;"HOW TO PEEK SVs" '"Addresses are held in 2 bytes. The Least Significant Byte comesBEFORE the Most Significant Byte"''"So to find the value of,eg,VARS (at addresses 23627 & 23628, youmust calculate as follows:" '" 23627 + (256*23628)" '"Calculate the value of VARS now.The correct answer is around 64200 but it changes slightly asyou go through this program." :1350F ):4;"SVs FOR MEMORY MAPPING" &k'"Using the routine saves time (see manual page 60). The program should be:"''"10 n(a)=a+(a+1)*256" +P'"When you want the number from two bytes, eg VARS, type"''"PRINT n(23627)" 0g'"Write a program to print out allthe SVs mentioned in Chapter 5."''"How much spare memory is there?" ::1350F D :"MEMORY MAPPING PROGRAM" Nc'"Your mapping program should do something like this: If you wantto look at it, enter LIST 5720" Z'"CHANS = ";n(23631O\)'"PROG = ";n(23635S\)'"VARS = ";n(23627K\)'"ELINE = ";n(23641Y\)'"WORKSP= ";n(23649a\)'"STKBOT= ";n(23651c\)'"STKEND= ";n(23653e\)'"RAMTOP= ";n(23730\)'"UDG = ";n(23675{\)'"P-RAMT= ";n(23732\) \J'"Try CLEAR and CONT. Notice how bytes between VARS and ELINE arelost." bA"ENTER to STOP then CONT to rerun, or f+ Enter to proceed ";z$ gz$="f"1350F l z$="" v 5700D ,:3;"CHANGING MEMORY POSITIONS" '"By POKEing these SVs we can get the system to assume that the areas of memory start in odd places. This is a simple example" '"1 To put RAMTOP at P-RAMT(P-RAMTis ""Physical Ram Top"" the last byte in memory), enter either:"'"POKE 23730,255 or CLEAR 65535" '"2 Change UDG to point elsewhere-say the Printer Buffer(otherwisewe'll be poking UDGs into the machine stack, and probably crash!). Enter..." \'"POKE 23675,0:POKE 23676,91"'"(P Buffer address=23296=91*256) (23675-23676 are UDG SVs.)"   1350F #:8;"DON'T LOSE TRACK" Y'"If you followed the last page, you have moved the User Defined Graphics to the Printer Buffer and moved RAMTOP up to 65535, giving a little more room for variables and program. Turn backtwo pages to the Mapping programto check that UDG and RAMTOP addresses have changed, and try Chapter 5 to make sure the"'"Graphics still work OK." '"If you don't mind reloading, trymessing around with other memoryarea SVs. If you have already read Chapter 11, try changing PROG so that RUN starts at line 1000 instead of line 999 in thisprogram."  1350F &:6;"PIP,REPDEL & REPPER" a'"A number of SVs specify the way the system should behave. Enter:"''"POKE 23609,100 then CONT"  I'"You should now find a much more positive Beep when you touch a key." '"Try POKE 23562,1"'"This speeds up the repeat key speed."'"If you dare, first set PIP to 1,(ie. POKE 23609,1) then try..."'"POKE 23561,1"'"You will need a very delicate touch to set it to rights again!" :1350F  :9 ;"MODE & FLAGS2"  '"MODE, at address 23617, tells the system what mode the cursor should be in;(K,L,E,G or C)"'"If you POKE MODE, it will have no lasting effect.So how can youspecify upper or lower case for INPUT statements in the middle of a program?" '"If you set BIT 3 of FLAGS2"'"(at 23658) the system will stay in CAPS LOCK until you set BIT 3back to 0. POKE it with 8 now."  {'"THIS IS MOST USEFUL FOR PROGRAMSWITH LOTS OF INPUTS, WHERE YOU DONT NEED LOWER CASE."'"By the way, F,B & I f,b & i!" % 1350F >:13 ;"CHARS"''"CHARS at 23606-7 tells the"'"system where in ROM to find bit-patterns for the characters. Butyou can set up your own"'"characters in RAM (Cursive or Gothic?!) and set CHARS to pointto them." He'"As a demonstration, we will displace CHARS by 1 character (8bytes). Enter..."''"POKE 23606,8" R-''"GOTO 999 will get you back to normal." \:1350F p:13 ;"SCR CT" z'"SCR CT at 23692 controls the scrolling. In effect it counts down from 23 until it reaches 1,when it stops. To watch it in action, enter this program..." 0''"10 PRINT 23692;23692;"""""'"30 GOTO 10" n'"This will stop scrolling as soonas SCR CT reaches 1. But now enter...."'"20 IF 236921 POKE 23692,32" ?'"and RUN again. This non-stop scroll can be very useful." :1350F *:"EXPERIMENT WITH SYSTEM VARIABLES" }'"You should now be happy enough with the concept of system"'"variables and you should start exploring them on your own." '"Most of the explanations given in the manual for each system variable are enough to enable you to experiment with them."''"Familiarity with SVs is a major step beyond BASIC and towards a deeper understanding of your computer." c'"Do not, however, PEEK and POKE SVs in your programs when BASIC commands will do just as well"  1350F &:" LOOKING DIRECTLY AT MEMORY" r'"It is not too difficult to look at the numbers held in a series of bytes and understand their significance." '"Enter the following program, which prints out the first 40 bytes of the BASIC area. (Make sure there are no other program lines with numbers less than 10)" '"10j=02020:" !"20i=23755+j23775+j:i;6;i" "30i:6150+j" "40j" ='"(To return here after entering each line, use GOTO 999)" &"Enter to break.f+Enter to Cont";z$  z$="" z$""1350F  0,10 ;"1st 2 bytes hold";1,10 ;"line No,(MSB 1st!)";2,10 ;"2nd 2 bts=No of bytes";3,10 ;"in the line (LSB 1st)"  4,10 ;"FOR These are Chr";5,10 ;"j codes.(See";6,10 ;"= page 183 to 188)";7,10 ;"0"  8,10 ;"14 means";9 ,10 ;"a number follows.";10 ,10 ;"";11 ,10 ;"Then 5 bytes for";12 ,10 ;"the number(0)";13 ,10 ;"converted to binary" g14,10 ;"TO More";15,10 ;"2 Character";16,10 ;"0 Codes" y17,10 ;" Then Chr 14 plus";18,10 ;" 5 more bytes giving";19,10 ;" 20 in binary." 221,0;"CONT to continue"::40( h0,10 ;" These 3 are binary";1,10 ;" form of 20 (cont)";2,10 ;"" g3,10 ;"STEP More";4,10 ;"2 Character";5,10 ;"0 Codes"  ti=611 :i,10 ;"":i:8,14;"Chr 14 + 5 bytes";9 ,14;"for binary number" $112 ,10 ;": Chr";13 ,10 ;"CLS Codes";14,10 ;"ENTER Chr=end of line";15,10 ;" Next line";16,10 ;" number";17,10 ;" length of ln 20";18,10 ;"";19,10 ;"FOR";20,10 ;"i.....and so on...." ) 1350F 8):" LOOKING AT MEMORY BYTES (cont)" ='"You have seen that the first twobytes (23755-6) hold the first line number. Try POKE 23756,0 and LIST. Can you edit line 0?" >|'"Can you use the same method to create line numbers above 9999? What is the highest line number that will LIST and RUN?" B)'''"THIS IS THE END OF THE PROGRAM" L 1350F #' #(1499,"0",1550,"1",1650r,"1",1700,"1",3100 ,"2",3150N ,"2",3200 ,"2",2500 ,"3",2550 ,"3",2600( ,"3",2650Z ,"3",2685} ,"3",2750 ,"3",2770 ,"3",2790 ,"3",2675s ,"3",3400H ,"3",3500 ,"3",3570 ,"3" #*k 4000,"4",4050,"4",2300,"4",2350. ,"4",2400` ,"4",2435 ,"4",2450 ,"4" #,4460l,"5",4500,"5",4560,"5",5000,"5",4100,"5",4220|,"5",4340,"5",4620 ,"5",4680H,"5",4750,"5",4840,"5",4900$,"5" #.5100,"6",51702,"6",5300,"7",5360,"7",5450J,"7",5500|,"8",5530,"8",5600,"9",5620,"9",5660,"9",5700D,"9",5760,"9",5800,"9" #05840,"10",5890,"10",5950>,"10",6000p,"10",6050,"10",6100,"11",62008,"11",1000,"0" #2%p(60<):p$(60<,2): #7+19,10 ;1;"PLEASE WAIT" #<$i=159;:p(i):p$(i):i #A"19,10 ;" " #F #b(i)=0 #2(bin/2-(bin/2))=09140# #b(i)=1 #bin=(bin/2) # $T^e=0:i=1̱a$:(a$(ii)<40(ůa$(ii)>579)Ưa$(ii)94^e=1 $^i: $ke=0:23681\=120,0;1;"You're already on the first page":e=1 $+23681\=123681\,2 $̞a$="b"p$(23681\)p$(23681\+1)20,0;1;"You're already on the first page":23681\,23681\+1:e=1 $ևa$="f"p$(23681\)p$(23681\-1)20,8;"END OF CHAPTER":23681\,23681\-1:e=1 $ %B4,9 ;" MSB ";4,19;" LSB " %!02,9 ;"DECIMAL  = ";bin;" " %& x=27:i=116 %+i9 x=25 %0 9100# %X7,x-i;1;b(i) %b67,1;"Binary";6,1;"Bit No." %l*6,9 ;"76543210 76543210":i %v %{823681\,1:23729\,230:1000 %+236066\,0:236077\,60< %+23693\,568:23694\,0 % %pi=062:""+i,192:""+i+1,0:""+i,3:""+i+1,0:i %)23729\230(23729\) %8i=07:""+i,192:""+i,3:i %N"",255:""+1,255:i=27:""+i,0:i &P"",255:""+1,255:"",255:""+1,255 & 8i=27:""+i,192:""+i,3:i & &H[0,1;" ";1,1;" ";2,1;1;"" &R-i=318:i,1;" ":i &\`19,1;"":19,1;1;" ":20,1;" " &f & & 1000 '%23641Y\+23642Z\*256 <;<#eor/<r N ( Z } s H . ` l| H$2J|D>p8}<0 1 1 1 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 6 6 7 7 7 8 8 9 9 9 9 9 9 101010101011110 .<Af"