You are on page 1of 135
ATUING EINSTEIN, aan hpranprpan . Parr id ut Pfu. Introduction This book has been written as a guide ta understanding sone of the lesser knovn aspecte of prograsning the Tatung Finstein wicro computer. Grystal Research of Tarquay have written a worthy taaie dnterprater for the Einstein and it 1a the intention of thie book ta amplify sone basic instructions vhien one may feel require further explanation along with detailing srear of memory which can be altered for various effect It should ba made clear, however, that this is not & rewrite of the excellent manuals which are supplied vith tne micro. Ovner's manuals eannot supply every detail whieh may appeal to a wide range of owners, so this bank 1s for thesa who have put one toa inte the water and feel thot the tine de right to take the plunge and discover sage of the little extras vhich the Einstein and BAS contain. It Scombenc: with explanations af the graphic connanda whith, even if one haa progranted in basic before, are better explained by example programs. A11 the prograta vithin this book are direct printouts fron working prograaa and are believed to be correct, if you know otherwise the authore or publisher would be delighted to hear fram you. For those renders whe prefer nat to type in the listings @ diec of ell the prograns 12 available directly from G. M. Software, detaile will be found on the final page. 1 Ellipses and arcs Ellipse is probably the best addition to the group of graphic commands on the Einstein, Try drawing circles on soma other micro and see how long it takes, £llipse must always be followed by at least 3 parameters:- The X co-ordinate of the centro The ¥ co-ordinate of the centre and the radius. Enter this short pregram:- 1@ BCOL ¥:GCOL 15,0seLS40:ORIGIN 0,0 0 ELLIPSE 100,160, 50 and RUN cEHTERY Hotice the circle was drawn in an anti-clockwise direction starting fron the 3 o,clock position. This circle was absolutely round, it wasn't oval shaped. There are a further 4 optional parametera which can be used with the ELLIPSE command for different results. The fourth optional parameter defines the ratio between the Mand Y axes, The sereen is 256 pixels wide - X axis - againgt only 192 pixels high - ¥ axis - so if the fourth parameter ia omitted the Einstein adjusts the ¥ axis accordingly by multiplying the given radius by 4/3 to formulate the correct ¥ radius. In the above program the radius was entered as 50, but it is only the x axis which will have this value. The Y axis will be adjusted by S084 /9 which equals G6.6. The resulting shape if the fourth paraneter were omitted vould be the seme had it been entered as 1,333 - which is the sum of 4/3, Had a value of 1 been entered the circle would appear thus: 20 ELLIPSE 104,100,50,1 RUN Decreasing the value of the fourth parameter will tend to flatten the circle even nore, ae 20 ELLIPSE 100,100.0.5 However if the fourth parameter is larger than 1.33 the ellipse will grow in height. 20 ELLIPSE 100, 5051.75 Renember {it is only the Y radiua which 4a affected, the X redive remains at the given value. The firth, and also optional, parameter can have a valve between 0 and § to denote which type of line is to be used for the ellipse. These are shown on page 70 of the Reference manual. Entering these linea will cause the Program te erase the circle after s short delay:~ 20 ELLIPSE 100,100,590 30 FOR As1 TO 500:NEXT: BEEP 40 ELLIPSE 100,109,50,51 and BUM CENTER Hote the additional comma before the last figure in line 49, This signifies that we wish to add the fifth paraneter but omit the fourth. This last parameter -1- caused the circle to be unplotted - erased - rather than drawn, so much for complete ellipses of circles, but how would one go about drawing a semi-circle or arc? thie is where ons would use the sixth and seventh paraneters for ELLIPSE, Bot they must pe ontered as radians, so if you are acquainted with radians please skip over the next few paragraphs. A foll circle is made up of 360 degre so if one wanted to draw a semi-circle thie would equal 180 degrees (360/2). The function which converts degrens to radians RADIn where n represents the number of degrees. Delete Lines 30 and 40 by entering: - DEL 30,40 cENTER? And alter line 20 tor= 20 ELLIPSE 100,100, 50,,,0,RAD(10} RUN (ENTER? The top half of our original circle haa been @isplayed. The semi-circle was dravn in an anti- clockwise manner starting fron the 3 6,clock position round to the 9 0,cleck position. This means that 3 o,clock is equal te zero and 9 o,clock to RAD(180). Enter:— PRINT RAD(180) ¢BSTER> and 3.14153 has been displayed, oes this figure appear familiar? Enter:- PRINT PI ¢ENTERY and the sane value app 1.14159 is the radian value expressed by PI, which ts universally used to define circles. Line 20 could just as easily have been entered thuss- 20 ELLIPSE 109,100,50,,,0,PT ‘These diagrans show some equivalent positions of a circle uging the RAD or PE function, Note that the 3 o,clock position can be entered in 2 forns: RAD(O] or RAD{360) or simply 0. Or PE*2 or 0 mace rt reac ' nace om Paap ADczTa> ries Obviously the starting point of an arc does nat need to be zero, it could be any position on the circumference, To draw the lower half of a circle one could swap the start and end positions thus:~ 20 ELLIPSE 100,100,50, or 20 ELLIPSE 100,100,50,,,RADITBO1, 0 4 Ineither line the last parameter - zero - could have been entered as RADI360) or PI*2 which would still have drawn round to the 3 o,¢leck position. ‘to draw lines which connect the start and end positions to the centre - a fan shape - one only needs to enter either, er both, of the final parameters negative values = precanded with a - sign. Here are some exanpl 30 ELLIPSE 190,100, 50,,2AD(45},-RAD(90} [7 20 ELLIPSE 100,100, 50,» ,-RAD1001 -RADI1601 ea 20 ELLIPSE 100,109,580, ,,-RADI109),RAD( 90} Although the above examples have omitted the 4th and 5th parameters for simplicity, there is nothing to stop one displaying tha above shape as sn oval and in a dotted Line:- 20 ELLIPSE 100,100,50,0.5,2,-RADI 100), RAD(907 POLY This conmand mst be followed by at least 4 parameters: The number of sides the polygon is to contain The K co-ardinate of the centre The ¥ co-ordinate of the centre and the radius. Apart from the additional first parameter these are similar to those used with ELLIPSE. Enter this short programs~ 10 BOOL 1:GCOL 15,0:CLS40:ORIGIN 0,9 20 POLY §,100,100,50 and RUN ‘ENTER? In fact the POLY conmand uses the same internal 05 function to display the shape as the ELLIPSE command. If one altered line 20 so that « 30 sided polygon was displayed the Einstein would draw almost the same shapa as Af one were using the ELLIPSE cormand, try entering: 20 POLY 20,100,100,50 and RUN CENTER> Looks almost the same as a circle, doesn"t it? The Sth and $th parameters are equivalent to the 4th and Sth of ELLIPSE. If the Sth parameter is omitted the ratio betwean the % and ¥ radii ip adjusted to 4/3. And the 6th can he a value between @ and § denoting which type of line should be used. Tt will be assumed to be a continuous line if the 6th parameter is omitted, In the following diagrams the polygons have a dotted circle dravn vith the same radius around the shapes shoving how the points touch the radius, Each example only differs in the number of sides. 20 POLY 4,100,100, 50 20 POLY 5,100,100,50 20 POLY 8,109,109 ,50 Motice that each polygon started from the 3 o,clock position, One can add 2 final parameters which dencte the start and end angle, but as with ELLIPSE, these mist be shown in radians. In the last & sided example above one could speciry PI/B as both the start and end angles which would turn the polygon through 22,5 degrees. FI is equal to 180 degrees therefore 180/6=22.5 20 POLY 6,100,1090,50,,,PI/8,PI/8 The % sided polygon overleaf could be altered by changing the angles to PI/s 20 POLY 5,700,100,50,,,PI/5,PI/5 The angles can also be entered as degrees with Ehe RAD(nI function, where n equals the angle in degrees. The above line could be entered as: 20 POLY 5,100,100,50,,,RADI36),RAD(36) As the abore lines omitted the 5th and 6th pareneters - ratio and ling type - commas were entered in their place. So far the start and end angles have bean the same, But, as With the ELLIPSE conmand, they can be altered for incomplete polygons to be displayed. Enter: - 20 POLY #,100,100,50,,,0,RADI180) fe The top half of an 8 sided polygon has been displayed, This appears straight forward, the shape started at 9 and was drawn round to 190 degrees. © But had the munber of sides been § the resultant shape would be thus:- 20 POLY $,100,100,50,,,0,RAD(180) the polygon stopped drawing after it had reached 160 degrees, when the shape next touched the radius. So some thought must ba applied when drawing incomplete polysons as te the angles and amount of sides it contains. As with ELLIPSE prefixing ona of the angles with a mins eign will di 2 lines to the centre, but it will net be obvious whieh shape will be the result. flere are some examples: - 20 POLY 6,100, 100,50,,,RAD(45),-RADI90) i RAD (45) ,-RAD(90) 20 FOLY 4,100,100,50, 20 POLY 4,100,100,50,,,RADI45), 9RADI315) 20 POLY 6,100,100,50,,,AND(45),-RAD( 3151 (Ss Bbviowsly one can add the Sth and 6th parameters for even nore varieties of polygon. The last shape above could be displayed thust= 20 POLY 6,190, 100,50,0.5,2,RAD(45],-RADI 315) Pie chart program The Pie chart is one mathod of displaying small amounts af @ata, where the whole circle represents the totel and is broken up into sections which show the proportional size of each item in relation to that total, This program also prints the percentage of each item on the left of the screen with the segment oumbers colour matched to the numbers around the chart. The chart below contains 12 segments, but this can easily be altered, although if one increases tha number cf data items the chart could become overcrowded and lose legibility. wien - ee - oo i 2 3 4 S 6= ae & ? > 1 2 uinan =NVANGOM.UNS VN SUNG 2 SnT+ VON VOANAOH asm WRRNRNNN NNN eee res 0 The Pic Chart is conprised of the fan shapes explsined in the last chapter. Enter the lines in the order given, and once the progran is up and running further lines will be added, so make eure all Lines carry the correct Iine numbers « Rater NEW ‘ENTER? 30 TOM 4,01 TOM 5,0: ORTGIN O,D After NHAS has leaded or the RST command has bean used all TOH's are set to their initial state of 1. In the case of TOH 4 this signifies that any numeric output will be apffixed with a space and IOM 5 means that a nuneric output will be prefixed with a space, As we want to suppress these spaces both I0H 4 and 5 are set to rere which will print the numbers without leading or trailing spaces Rowever, it should be pointed out that in other prograns which deal with negative numbers, they will still print the minus sign before the number, so one may find that tabulated figures do not appear directly beneath cach other. 40 CLS32: BCOL 1; GCOL 15,0: TCOL 5,0 50 PRINT "PTE CHART 60 DRAW 0,183 TO 71,18) Line 40 sets up the display and line 50 prints the title message at the top left of the scracn, because line 49 cleared the screen and positioned the cursor at that position, Line 60 simply draws 4 line beneath the title essage. 70 DIM F(T?) 80 FOR Bel TO 12: READ PAB): TeT+F(B): NEXT 90 DATA 10,2,2,9,6,10 08, 12,4, 7412611 uw If your program is to uae 10 of less itena of data there ia no heed to DIM PI1Z], as in Line 70, for the Einstein allows up to 10 subscripts without the necessity to DiMension, However it is a good habit te dimension whenever eubscripted variables are te be used. The POR- NEXT loop reads the 12 items of data into variables Fil} to P(12}, Subseripted variables start at zero - one could us P(0) as the first subscript - but im this program it is simpler to use 1 to 12. As each item of data is read it is added to variable T which, after the loop has finished, will contain the total of all the values in line 90 - in the above case it will equal 74, It was not necessary to set T to cero before encountering these lines as whenever a Program is RUN all variables are set to zero. 100 Ket60: ¥=100 110 SePr*2,5 Line 100 sets up the centre x and ¥ co-ordinates for the centre point of the chart and line 110 sets the start angle to PI*2,5 We require the first segment of the chart to start from the 12 o,clock position and each further segment be added ino clockwise directicn. This is alien to how the Einstein wanta to draw them - remenber in the ELLIPSE section all drawing was anti-clockwise, 80 why have we entered PI*2.5 when the 12 o,clock position is PI/2? whan drawing fans - that's arcs with 2 lines drawn to the centre point - we prefix either the start or end position with 4 minus sign, Travelling anti-clockwise, as we are going to be, Af we deducted the start angle from PI/2 as soon as a segnent reached the 3 0,clock position our angle would be less than zero. So instead of small segments being drawn one would find that the remainder of the circle was displayed with our segment cut out of it, By adding a complete revolution - PI*2 - to the normal 12 o,clock position of PI/2 th: gives us PI*2.5 and the segments ard would require « complete circle plus a quarter before our angle reached zero. Once the program ia running try altering line 110 to PI/Z and see the result. Incidentally one could vee the RAD{n} function instead of PI in line 110 vhich should be entered a5 RAD(450) - a conplete circle plus a quarter 360+90=450. 120 FOR B=1 TO 12 130 Bes Line 120 starts the loop which will display the 12 segments, Line 130 loads variable & - the end angle - to variable § - the start angl As the Einstein draws the segments in an anti-clockwise manner the start point must be decreased for each new segment while the end point takes on the value of the previous start position. The first tine through the loop the first segment will end at the 12 o,cleck position - variable £ - while the variable 5 - the start point - is calculated in Lins 140. 140 SeS-( PIB) /T) RADE 360) Line 140 calculates the size of the segment in relation to the whole circle. Variable P(B}, which on the firet tine round the loop is actually Pdi}, will contain the value of the first iten of data - 10 in line 90. ‘This value io divided py the total of the data values held in variable T = F(B){T - which in thig instance is 10/94. This cum ia then multiplied by the runber of degrees in a complete circle, but as the angles must be in radians it is converted by RAD( 360). Ag we are @iaplaying the segments in a clockwise fashion this figure is deducted from variable & which now holds the radian value of the start of the segment. 150 ELLIPSE X,¥,50,,)-5,E Line 130 draws the segment, Hote that the atart angle is prefixed with the minus sign signifying that 2 lines to tha centre should be deaun, Although the program is not complete it should now be capable of displaying the first segment. So RUN the program and compared the results with the diagram, If it ds not the same check the entries so far, 210 ERT 2,0 220 PRINT @ 0,646; B; Line 210 altere the numeric output format command so thet Our segment numbers - 1 to 12 - will be aligned correctly when printed on consecutive lines beneath each other, Ag OOF fuhbers are all integers - whole numbers - we do not require any places after the decimal point, the second Paranater is set to 0, line 220 printe the value of our loop counter, which aleo represents the segment number, at column cero, the leftmost column, on lines B+6, This ensures that the first time through the Loop printing will begin on line 7, then 8 atc. The value of B is followed by the = sign. Do not forget to end line 220 with a semi-colon, 230 TOOL 15,0: FMT 2,3 240 PRINT FYB) /T*100;"0" 250 NEXT 14 Line 230 seta the text colour for printing out the percentages to white. FMT 2,3 alters the format command to print with 2 places before, and 3 places after, tha decimal point, Line 240 takes the value of PIB], which on the firet tine through the loop will equal 10 - the first item in data line 90 - and divides it by the totel - variable T - which we know equals 94, This gives a result of 0.106383. Multiplying this figure by 100 will return the percentage value of the data item - 10.6363 - and as the second parameter of PHT was 3 it will be displayed ag 10,638 with 7 figures after the decimal point. Line 240 then prints the & sign and line 250 loops back for the renainder of the itens. Before adding any further lines check on the results ao far, It should be aimilar to this disgram with the PLE CHART message and the number 1 below printed in light blue with the remainder of the display in white. wa now want to £111 alternative segnants with colour and Gisplay each segment number around the circumference of the chart. To use the FILL command we will need to find a point within @ segment which is surrounded by a boundary, or the colour W111 spill out and possibly flood the screen. There is a mathematical formula for determining any point on @ circle:- X co-ordinate » Radius*Cosine(Angle}) + centre % position ¥ co-ordinate = Redius*Sine(Angle) + centre ¥ position Now without delving too far into trigonometry, which this book really is not about, suffice to say that the formulas above can be sinply adapted to a basic program line without 4 vast mathematical knowledge, by using the 2 basic functions for cosine and sine - (0¢ and SIN. The Anglo shovld be entered in radians, but as our program already uses them for the ELLIPSE command, this is no problem. To assist in calculating the correct positions we will uso the DEF FX statement. Whenever several program lines contain the sane formula it ig more efficient, and faster on execution speed, to use the DEPine Pultction early in the listing but beginners tend to avoid it as it appears too complicated. Most owner's reference manuals briefly mention that it exists, but few show working examples. Add these lines:- 10 DEF FH (R)-R*COS( ANG) +x 20 DEF FNY(RI=R*4/3*5TH(ANGI4Y Whenever the program requires the * co-ordinate of a point around the circle all the function requires ia that variable ANG has been set to the correct angle, and that the radius is also known. The X latched onto the end cf the line is the centre xX co-ordinate, which already haa a value in line 100. Line 20 iz similar except that the radius ig multiplied by 4/4. Remembering that the ELLIPSE statement eutomatically adjuste the ¥ radius by this amount, we must adjust our radius of ¥ similarly, 16 160 AmG=S¢(P(BI/(T*2) }#RAD(360F Thie line divides the segment value - in P(B) - by twice the total — 2. In effect this results in a figure of half the seqnent's size, By adding this figure te the start position, not deducting as we did in Line 140, it will move the angle anti-clockwise by half the size of the Jast seqnent, Once again it is converted to radsans by RAD(360). And now ANG is set to a central point within the last segnent. 170 IF B MOO 280 THEN 180 180 PILL FNAC4S) -FNYCAS) 15 ‘As only alternate segments are to be filled in with colour lane 170 tests 1f our loop counter ts equal to a multiple cof 7, and if it is then the fill Line - 180 - is skipped. i.e, only segnenta with odd numbers are filled-in. Ling 180 uses the FELL command, and aa the angle is now Known all that ds required is to eet the radius to a smaller figure than wag used with ELLTFSE in line 150, I Line 10 we defined the functions as FNX(R}=R* etc., but we @o not need to use the function with a variable R. Simply set the radius when the function is used by - FNX(45). 190 TCOL B+1,02 FAT 0,0 2D0 PRINT @ PHX(62)/8,(192-FNY(621)/8; B Line 190 sets up the text colour to the value of the loop counter, B plua 1. 69 initially the text colour will be 7 - medium green - the next time through the leop variable & will equal 2, so the text colour will be 2+1*3 = light green and soon, -FNT is set to normal for displaying the seqnent numbers around the chart. Line 200 cunningly positions these numbers. Using FNX(62] will return the X co-ordinate of = pixel position outside the circle but lined-up with the centre af the last segment drawn as line 160 has already established the angle. As the ORIGIN was set to 0,0 in line 30 1f we now divide this figure by 6 it will return an actual column position for using PRINT &. ‘Think about it, print column 0 starts at pixel position 0, column 1 at 8, colunn 2 at 16 ete. Although the figure may run inte decimal places - t.e, if FNX{62}2210 and the this figure is then divided by #, the result would be 26.25 - this would not matter, as the PRINT f statement only looks at the integer part of a value and would print at colum 26. fo calewlate which line, from the top, to print at we must first deduct tne value in FNY(62) from 191, the top-nosr pixel position, For although line numbers are naarured from the top ef the screen the pixel © co-ordinates are measured fron the bottom. Tf PAY(G21=175 - which is near the top of the sereen - and we deduct this from 191 we are left with 16, Diwide this figure by @ and the result is line 2. After calculating the relevant position line 200 prints the segment fumber in variable B. The program showld now also display the seqment nunbers down the left of the screen in the same colours as vere used for around the chart. This program can easily be altered so that the data items can be input from the keyboard, but it should be remembered that all the data must be input before the program starts to draw the chart. To achieve this Lines 70 to 90 should be deleted by enteringt~ DEL 70,90 Now add these Line: 40 INPUT "Bnter no, of items "38 42 DIM PIM) 43 FOR Bel TON 44 PRINT "Enter data item "} AS TeT+P(BJ! NENT: CLS INPUT PIB) and alter line 120 to readt- 12D FOR B=1 TO 8 The progran will now prompt for the total amount of date itens and DiMension variable F accordingly, Line 43 starts the loop for the input of each item, When the correct number have been entered the variable T will hold the total valve of all the items and the program will then continue ‘ta slice up the chart. 13 Clock program Although there is an excellent alarm clock program on the demonstration disc, thie listing is designed to show how a simple working clock face could be designed. Firstly we will nove the ORIGIN fron the bottom left Position to the centre of the screen. This means that, unlike the previous example, there will be no need to add ‘the centre position to the end of cur formulae. ence any Point on the circumference of the clack face can he decided by:- X= Radius * Comine(Angle) Ys Radius * Sine(Angle) mn Program lines will be explained as they are entered. The functions for plotting the clock face require setting up. Enter NEW «ENTER? 10 ORIGIN 128,96 20 DEF FHx(#)=R*COS(P1/2-RAD(A}*S1 30 DEF FHY[R)=R¢4/3#51N(PI/2-RAD(A)*6} pefore using the functions variable A - angle - will need te he set up, but the angle locke different here than in cur previous example. Az one hour fs comprised of 60 mimites we will only require the minute hand to make 60 movanents in one complete circle. As one complete circle contains 360 degrees the minute will be multiplied by 6 to gecide on the correct angle (606-360). the other difference in the angle section of the arqument je FIv2. We wont all timings to be made from the 1? clack position, which if one refere to the chart in the previous section, ia equal to PI/Z. We also want the hands to be draun in # clockwise manner, so the angle - RADIA)*6 - is deducted fron this 12 o,clock position. If the sign was altered fron - to + the clock would go backwards, which is fine 1f you wish te view through a sirrorl 60 CLEI2: MAGI: BOOL 4: TOOL 15,01 GOOL 15,0 70 SHAPE 130,"80 00 09 99 G0 00 DO 00" 80 SPRITE 0,129,100,15,130 Line 60 sets up the screen display and colours, vhich have been left to shite on dark blue, but cen obviously be changed once the program has been entered and, dare I say it, debugged and working. Ling 70 defines the shape nunber 130 for the sprite which will rotete around the circunference of the clock face indicating the seconds. Line 60 gets sprite number @ a6 being white and allocates a it to shape 130, This line also positions the sprite off screen until the program ie ready to use it. 90 FOR Aet TO 60 100 TF A MOD S90 THEN DRAW FHX(65),FNY(G5) TO FNX(G2), PHYTe21: GOTO 120 110 PLOT NK (65) FIY6S | 120 NEXT A Line 90 sets op the loop te plot the 60 minute marks eround the foce, Line 190 checka that the minutes are equal to multiples of 5 with the A MOD S<0, in which case a line is @rawn fron radii 5 to 62, otherwise a single pixel is plotted in line 119 for the other minutes around the face, Notice that here we have not used a variable for the radive. As our DEFined FuNctions were entered as DEF FRA(BIsR* ete., this meane that the radius - to the right of the equals sign - will equal the value within the parentheses to the left of the equals sign - FNA(691 vould calculate the X co-ordinate to the radius of 60, Sa to draw a line from radius 65 to radius 62 we simply enter = DRAW FHX(6S),FNY(G5) TO FNA(E2), FY (62), At this stage the prearan can be KUN and checked that the display is similar to that on the right If it isn't then re-check the DEF FN lines 20-30 first before checking the remainder, It is essential that these lines are correct as the main part of the following progran relios on then whan the minute hand or sprite are moved, 2 the es-ordinates for the hour hand require defining. 4s 4n hour hand does not only point to the exact ‘hour, it gradually moves between cach hour mark depending on the number of minutes the time is past tho last hour, it 16 defined slightly differently to the minutes. 40 DEF PNXH(R)+R*COS( PI /2-RAD(HR1*20-{RAD(A)/Z1) 50 DEF FHYH(R) =Re4/3#519(PI/2-BADCHE)*30-(RADIA}/2}) Hare tha hour angle is defined as AAD(ARI*30 ag there are 4g hours in one revolution of the clock, the hour must be multiplied by 30 (360/12=30). therefore each hour mark is 30 degrees higher than the jest, As with the minutes in lines 20-20 this figure is deducted from PI/2 giving the correct angle past 1? o,cleck. Say the time is 4 o,clock the variable HR will . . contain 4) sa 4304120 and = + a5 can be seen from the diagram on the right 120 equals 4 0,clock. © But if y ¢ the time is 4.30 variable ¢ HE will still contain 4 but " Laiad we want the hour hand to be me: pointing to a point mid-way between the 4 and § as 8 normal clock would do. ara. a8 aze He are peeking en angle figure of 135 ~ halfway between 120 and 150, Therefore we divide the minutes - in variable © = by 2 which in the case af 4,30 wold (be 30/2615- Renenber thet wa are deducting this angle from Ff/2, 50 2120-15= -138 which is the correct angle for the hour hand past 12 o,clock. 130 HReVAL(LEFTS(TIS,2)) MOD 12 140 MNeVAL(MTDS (TTS, 3,2)) 150 SC=VAL(RIGHTS(TIS,2)1 These lines take sections of the system variable for tine -TI$- which always consists of 6 characters, and places them into the 3 variables. Hours are always held in the first 2 characters in TI#, minutes in the centre ? and seconds in the rightmost pair. 160 AsHH 170 DRAM 0,0 TO FRXH(46),FRYIN48)3 REN DRAW HOUR RAND THD DRAM 0,0 TO FMNx(G2),FNY(62): REM DRAW MTN HAND Ae explained earlier each time we use the DEFined Fulictions je muist give a value for the angle in variable A. As the nour hand is smaller than the minute hand the radius is subsequently smallec - line 170 - but to draw the minute hand the redius is increased to 62 in line 180, 190 S2sVAL(RIGHTS(TIS,2)) 200 IF 2=SC THEN 190: ELSE SCas? Ling 180 placed the seconds into variable 5C. tine 190 places the current seconds into variable S2, while line 290 checks if the seconds have changed, If they haven't the pregram jumps back to 190 and reads the seconds again, TAis peocess recurs until the seconds have changed and then the remainder of line 200 is encountered and S¢ now equals the new value of the seconds. 210 Aesc 220 SPRITE 0,FNR(661,FRY(6E) Once again we are going to use one of the functions, only thig time it ig to position the sprite for pointing to the seconds, The angle - variable A - i set to SC which holds Fry the current seconds value and cur DEFined FuNction will nove the sprite on the radius of 68. As we have already defined the shape snd colour of sprite 0 in line 80 all that is required to move the sprite is to enter the sprite number ahd K and ¥ co-ordinates - line 220. 230 PRINT 0,07 240 FOR Z=1 TO § STEP 2 250 PRINT MIDS(TIS,2,2)5 "| 2NEXT Line 730 positions the cursor at the top left corner of the screen. Lines 249-259 disact TI$ into J pairs of nunbere and prints each with « space following. This is updated each tine the seconds change. 260 IF §C<+0 THEN GOTO 190 Tf the seconds are not equal to sere - SC equals a value between 1 and 5% - there is no requirement to move the minute and hour hands, therefore the program jumps back to the seconds reading line at 190, If the seconds have reached zero then the following lines will be executed, for the hands need to be re-drawn at their new positions. But firet they met be erased from their old position by adding the qualifier - 1 - to the end of the DRAW statement. 270 haw 280 DRAW 0,0 TO FNXH(4E),FHYI(4E1,1: REM ERASE WOUR HAND 290 DRAW 0,0 TO FRX(62),FHY(62),1? REM ERASE MIN HAND 300 Goro 130 Before jumping back to line 130 the hands must be erased. Renember that although the seconds have reached zero, and the minute section of TIf must have changed alan, but the program has net read the minute section of TI$, only the rightmost 2 £igures fer the seconds, Therefore variable HN still contains tne previous value of minutes and 25 subsequently both hands can be erased using NN - Line 270. Once the program junps back to ling 130 variable MN is set to the new minute and the hands are drawn in Lines 170-180. And time continues... The program can have an input routine for the tine added quite easily. Here is a suggested method 61 PRINT “Enter time as HNMM i.e. 0430" 62 INPUT T$i IF LEN(T$}co4 TREN 61 63 TF VALILEFTS(T$,21)912 THEN 61 64 LF VALIRIGHTE(TS, 291959 THEN 61 65 TIS-T$s"90": CLS This input routine does not allow for the input of seconds, Line 65 simply adds "00" to the hours and minutes so TIS will contain 6 characters. The system variable TTf is peculiar as it does not internally check on a valid time, For instance one could input atime as 1175, adding 75 minutes to 11 o,clock results in a time of 12.15 which is what the hands on the tlock would point to, but when the Program prints out the value of TI$ it would be displayed as 117500, It will also accept hours qreater than 24, entering « time ag 2510 would cause the hands to point to 1.30 but TI$ would stil2 cet Printed as 253000. Therefore a chack on both hours and minutes is carried out in lines 63 and 64. Biorhythm program Tt is said that from the Gay we are born our physical, emotional and intellectual states conform to certain cycles, called Biorhythns. Bach cycle repeats at a rate of 23, 28 and 33 days respectively, meaning that occasionally one will find ail three will peak together, or the opposite pay happen. Whether you believe in them or not, this program shows off the chart plotting capabilities of the Einstein. A typical screen display:- / BORN: DEC S 1963 Name: JOHN Nl NT il. 3 22222 1.3.5.7,9.11.3 | | M. ENE ia1at LSE75913 57 ‘The program in listed first followed by explanatery notes. a 1D 20 ao ao So 60 70 ao 30 100 10 120 130 140 150 160 170 180 190 200 210 220 230 240 2480 260 270 2a0 730 300 no 2 coro, 320 a0 340 350 360 no RST: BCOL 1: GCOL 15,02 TCOL 15,0 CLS40: XO: TO: MAG 1 BATA B,1,0,F,H,¥,T,HyH FOR Ae 190 TO 20 STEP-20 READ CHS Rexat SPRITE K,X*22,4, Kel ASCICHS] SPRITE X+9,X922,220-A, K+) ,ASC(CHSE FOR tal TO 150: NEXT NEXT A FOR Ys1 To 8 SPRITE OFF Yt SPRITE OFF ¥+9 FOR A-1 TO 100; NEXT NENT ¥ Tete IF Ts4 THEN 160 ELSE RESTORE: X90: coTo 40 SPRITE OFE DEF ENY[T)-INT(72*5IN( [-24Ap*(PL*2}/CD}+.5 144 pigs" Aged 1-922: 8°2 B ae. D="1 3579735799957 9 1" DIM MaTHS(12},DAY(12) FOR Ae? TO 12: READ MNTHS(AD,DAY(A)# NEXT DATA JAN, 31,FEB,28,MAR,31,APR,30,HAY, 31 JUN, 30 DATA JUL, 31,AUG, 31 ,SEP,30,0CT,31 ,WOV,30,DEC,31 INPUT“Enter Mame..";NAMES INPUT"Yaar Born (1.0.19659). AP YBN¢1901 THEN PRIXT "Sorry cannot do“: GOTO 240 INPUT"Month (1 to 12)... "7B TP MBNe1 OR MBN?12 THEN 270 INPUT"Day (1 te 311...")D6N INPUT"Year to start... “yNBT IF YSTCYBN OR YSTC1901 THEN PRINT "Sorry cannot do! 200 INPUT™Honth. 2 eEMST IF MST¢1 OR MBT?12 THEN 320 YR=YEN: MH=MBH: DY-DAN: GOSUB 760 IF ER=1 THEN 250 GOSUB BDO: DEeF: T1eYHW: M1=MAN: D1=DeN YH+VST! MWeMST? DY*1 380 390 400 410 420 GOSUB #00: HeF IP HHe2 AND YR MOD 4-0 AND 1 MOD 4eo0 THEN DESDE+1 IF 4N?2 AKD YR MOD 4-0 AND Y1 MOD 4-0 THEN DE=DE-1 IF ¥R MOD 4450 AND ¥1 MOD 4-0 THEN DE=DE-1 GOOL 15,01 TCOL 15,0: N=DE~R: TF N90 THEN GOSUB 7907 GoTo 250 430 440 450 460 panes (M1 470 abo 490 500 510 520 530 540 550 560 570 580 590 00 610 620 430 PHe23¢(m/29-INT(N/23)}: BM=264(N/2B-TNTUN/2E)) wre33¢(H/33-INTCM/3I)) ‘Le32-LEN(MNTHS (M1) 4STR$(D1)+STRE (YTD) CLE: TOOL 1,15: PRINT “Name: ";NAME: vey ORIGIN 0,0: TCOL 13,0: PRINT TAB(16); "High" DRAW 3,32 TO 207,32 TO 207,176 TO 3,174 TO 3,32 FOR X=# TO 206 STEP 12 DRAW X,176 TO X,174: DRAM X,32 TO 4.34 DRAW X+6,176 TO Xe6 22 NEXT X DRAW 204,104 TO 3,104.2 TOOL 12,0: PRINT @ 0,20;MNTHS(MN)" “7STRS(YET WxoeteHtet : LF NXMH=13 THEN NXNN=1 PRINT ‘TAB( IZ) 7 MOTHS (HX) PRINT @ 0,21, LEPTS(D1S DAY (am) | PRINT LEFTS (026, DAY (HH) );LEFTS (02%, ¢35-DAY(MNI}) TeOL €,D2 PRINT @ 16,205 "Lew" EaPH: (0-29: COL=9: CYCLS="Phys": GOSUB 670 EsEW: CO=28: CObell: CYCL$<"Emot": GOSUE 679 EelT: C233: COb=13: CYCLS«"Intel"; GOBUB 670 TOOL 1,15: PRINT @ 5,23;"tero quits,.Any other for n ABUL); BORN: " ext";CARS(N1]: BEEP 640 450 60 70 BO 90 700 mo 120 AsINCHt IF A=44 THEN END Nerenxomt: IF Mat THEN ¥R=¥R«1 GOSUB #00: NaF: GoTo 420 ORIGIN 3,0: YelO4r Aw -D.5: BORE BFE96,0,PNY(¥) GCOL COL,o FOR Ae TO 33,5 STEP .5 DRAW TO A‘64],FNY(1) NEXT A TROL COLO: YYeINT(24-(DEER(RPB9S 1/80): Kxe35 70 IF PEERCPTR( 1S} 0(9Y¢404xK) 14932 THE YY=Y¥+1 26070730 740. PRINT @ XX, 4¥CYCLS 750 RETURN 76D EReG: IF B¢DAYIMN) THEN RETURN 770 IF Mice? THEN 790 780 IF YR NOD 4=0 AND D¥=29 THEN RETURN 790 BEEP: CLS: PRINT "INCORRECT DATE": ERe12 RETURN B00 FeO: IF me? THEN BAD BNQ FOR Axi TO mN-1 B20 F=F+DAYIA): NEXT ® B30 IF YR MOD $20 THEN FeFstz IF MN=2 THEN DAY(2)=29 B40 FaFeiGS#¥R+INT¢YR/ 4] +DY: RETURN Lines 10-160 set op the screen and display the word "BIORSYTHM' along the 2 diagonals of the sercen, The word 4g comprised of sprites for each letter. Line 170 geta up a function - FWYIY) = as the equation to find the ¥ co-ordinate to draw te for each cycle. The X co-ordinate does net require such a function as it increased by the sane nusber of positions equally fer each day of the month across the chart. Lines 180-190 set up string variables D1§ and D2$ with the days of each month for printing below the chart. Nake sure the correct spaces are entered inte the strings. Lines 200-230 load up the dimensioned variables MTHS anc DAY with the mamea of of the months of the year and number ‘ef days in each. Lines 240-330 check and accept the entry of details from the subject, and trap any subsequent errors of dates etc. Lines 340-440 calculate the munber of days that have elapsed, adding days for leap years. Lines &50-460 print the subject's details at top ef screen. 20 Line 480 draws the outside of the chart and lines 490-520 draw the vertical day lines across the width of the chart, Line 530 draws the dotted line across the centre, note that DRAM contains # third parameter = 2 - indicating a dotted line. If one runs the program before entering the renainder of the ligting it should present = display sinilar to the diagram right, although — the subject's mame and details should be shown as black on @ white background, Lines 540-580 display the current senth and daye of that month with Bf and D2& by using the LEFT$ function and BAY(NN} for the umber of days it contains. Depending on the length, the renainder of the line prints the dates of the follewing month, Lines 600-620 represent the start of each cycle and load variable CD with the cycle day length and the colour of the line into variable COL. CYCL$ 1p loaded with the name of each eyele for printing to the right of the chart, where the line ends, before calling the drawing subroutine at line 670, Tings 630-660 checks for input of zero for ending the pregran, for if it isn't the following menth's chart is isplayed. Lines 674-750 draw each eyele. The X origin is moved by 3 pixels in line 670 to enable the dates to be lined up centrally beneath. Each cycle will be drawn in 68 stages Hn acroas the chart. Each time a section is drawn we simply instruct it to ORAW TO Xx,¥ - bine 700 - from whatever position the graphics pointer happens to be at. ‘But firstly the graphics pointer pust be positioned on the leftmost line of the chart. As there ia no basic command for move - without drawing - we must resort to a double PORE to position the pointer. We cannot use the DRAW TO X-¥,1 command as this would unplot any pixe Addresses AFROG/7 (64406/7 decimal] contain the current ¥ co-ordinate of the pointer and AFBOB/9 (f4408/9) hold the ¥ co-ordinate, DOKE &F"96,0 would position the X pointer back to the X origin - in owr case pesitien 3 - and DOKE BFBSE,FNYCY) will position the ¥ co-ordinate pointer at the Porrect positien for the cycle scale tc begin from relative to the centre horizontal dotted line - although one must get ¥ to 104 iret. Although the program uses hexadecimal numbers, one could just as easily have used decimal and entered line 670 thus: 670 ORIGIN 3,0: YeIDd: Ae =0,5: DOKE 64406,0,FuY(Y) When ich cycle has been drawn we want to print the name of that cyele - CYCL$ - adjacent to where the Line finished, using the PRINT @ X,Y connand, The X co-ordinate = column - will always be the same - 35, but the ¥ co-ordinate will depend on the final position of the cycle drawn. Line 720 DEEKs the current graphics Y co-ordinate at address &FB95 and divides this figure by 8. It must also subtract this value from 24 to find the correct line number, why? Because lines are numbered from the top - 0 - ta the bottan - 24 = but the graphics pointer operates in reveree with the top pixel line being 191 and the bottom t. Hence if DEEK(4FR96) gave a value of 191 this would mean the graphics pointer was at the top of tne screen. Dividing this figure by @ would result in the answer m 23.875. Deduct this figure from 74 and the result is 0.125 and PRINT @ only takes the integer part of a value this would result in PRINT # 35,0. Wote ‘This only holds true if the origin for the ¥ co- ordinate ig zero = bottom of screen. We now have our co-ordinates for PRINT @ in variables Xx and YY. Before printing the string CYCLS we mist check that one of the previous cycles @id not finish in the same position - which ig common enough - as this would mean 4 would be printing over a previous cycle fame and erasing it. 60 a cheek must be made that no character is already printed at that position, PTR(19) holds the RAN address of the start of the screen. Fach character position on screen is mappod ta a block of consecutive mamory locations, so if one knows the position dt can be PEEKed to discover which ASCII character it containa. Line 730 calculates the screen position we intend to print te by multiplying the lina - in YY - by 40 and then adding the colusn number - in XX. This som is wedded to PTR(19) and then PEERed te check if it contains « space - ASCIT code 32 decimal - and if it doean"t the line - in Y¥ - 4s increased and a further check made until = apace is found. Line 740 prints the cycle name held in string variable CYCLg, The subroutine in lines 760-790 check on valid dates during the entry routine and lines B00-840 caleulate the elapsed days up €411 the current month. 2 Function keys After loading MBAS the function key buffer is enpty, so pressing any of the 8 qrey function keys will have no affect. ‘These keys can be very useful vhen writing or debugging programs. This section shows how to assign various commands to these function keys, and once the genetal concept has been shown one will obviously be able to use any commands with the keys. Load ABAS ap normal and enter this short pregram:— 10 FOR X81 TO 10 20 PRINT x 30 NEXT Running this progran will sinply print the numbers 1 ta 10 on consecutive lines. It will only be used to demonstrate the effects that the function kays can produce when assigned various commands. To assign the first grey function key to the command RUN one vould enter the followings - KEY 0,"RUN" CENTER? The keyword RUN was entered as a string, with quotes either pide, Pressing the function key marked FO will now cause the word RUN to be displayed on screen, as if the 3 letters R, Uand N had been entered singly from the keyboard, hut one will still need to press the red ENTER key for the command to be acted upon, We require to add the ASCII code for FNTER onto the end of the keyword RUN. There are 2 methods of achieving this. The Reference manual states that one may press both the GRAPH and ENTER keys after the last letter of RUN and before the closing quotation marks. This is fine providing one doesn't press the GRAPH and INS Keys by mistake vhich would send the Einstien into M05, An alternative, and safer, mathod vould be to add the ASCII code for ENTER to the end of RUM after the closing quotes:- REY 0, 4CHRS(13) CENTER? ASCII codes below 32 decimal are used as control codes, and when the Einstein encounters an ASCII character with a value below 32 it knows that it must perform an action other than simply printing = character to the screen. These contrel codes are listed on page 206/207 of the Introduction manual, Unfortunately they are only shown in hexadecimal but one will see that code 9¢ which is the hemedecimai equivalent of 13 ig stated as CR - carriage return, weiage return is an alternative way of stating Enter, so adding CHRS({13) to RUN will simply print RUN on screen and the Binstein looks to the next character (13) and acts upon it, just as if one had pressed the ERTER key. Other control codes cam be added to these commands for useful results. As an example assume a program vas listed on the screen, and one had just edited a line and the cursor was currently positioned to the left of the next progran line, Pressing the FO function key would display RUN, but an error would be caused due to there being other characters on that sereen line, Control code t5 hex (24 decinal} causes the remainder of text on the current screen line to be ignored, hence the keyword RUM would be acted upon without error, This could be entered asi~ KEY 0, "RUN" ecHRS( 21) eCHRE( 13} note that the code 13 - carriage return - is always entered last. Punction key 1 could be defined to list a program, and by adding CHRE(13) to the end will list a program fron the first line by only requiring key F1 to ba pressed. REY 1,"LIST"4CHRS(13} The third key could be defined to the LOAD" command. Here we wish the opening guotes to be produced on screen, 80 that after F2 has been pressed all that will be needed is for the program name to be entered, The only method of printing quotes on screen is by using the CHES function with the ASCIT code for the quote marks - 34 decimal. For instance one could not enter "LOAD"". This could be entered thus:- REY 2,"LOAD"+CHRS(34) Pressing key F2 will now di uoab" and the cursor will be flashing next to the quotes, on the same serean line, waiting for one te enter the program nane. Here though one will still neod to press the EWTER key after the program name, Although one can clear the screen by entering the CTRL and L keys simultaneously, it is also preferably to achieve 4 clear screen by one key pre Function key F3 could be used:- KEY 3,"CLE"+CHRS (21 }+CHRE (13) Ag with key PO we have added the 2 control characters - 21 delete to end of line - and - '3 carriage return. This means that key F3 can be used to perform s CLS even if there is other text on the sane screen line, 6 Function keys can contain more than one instruction provided they sre separated with a colon - + - as one would use in @ normal program line that contained more than one instruction, I£ one is using # normal television rather than the Einstein monitor you may have noticed that the 32 column screen mode tends te Jose the last character on each Line, making editing a big problom, Whereas 40 column @isplay appears correctly. ‘Therefore when editing it is nore convenient to list 8 program in 40 column mode regardless of which mode the program runs im, Rey 4 could be assigned Ehus:- KEY 4,"CLE40:b78T"#CHRS (21 P4CHRS (13) Which would clear the screen to 40 column mode before listing the current program. If one is vorking on & fprogram which experiments with colours one could find the progran requires debugging and cones to a halt printing text in the sama colour as the background - effectively displaying nothing. © Oefining a key to restore the colours to sanity vould be usoful as one could not see what was being entered fron the keyboard and peobably would not know the position of Ehe cursor, 80 CHRS(21} should be used too. KEY 5,"BCOL4: TOOLS ,D"+CHRS E21 )+CHRS( 13) One will soon discover which commands are mere frequently required when entering or debugging programs, one that is always being used ds the BiRectory conmand. The right hand function key could be used - F7 - for function keys do net need to be qued in order. KEY 7, "DIR" +CHRE(13) will list the directory of the current disc with only one key press. Entering KEY LIST «ENTER? FO: RUMAS showld now display the Fl: LIST contents of tha function F@: LOAD" : FS: CLO, keys. Fa: ee ust Remenber that each key can ne BCOL4: TCOLIS, Am be used in conjuction with po, pTRte the SHIFT key 60 producing srg, 16 functions, $Fi: sF2: Although EY LIST shows sF3: hese shifted keys numbered 5F4: from sF0 to sF7 they would 3FE+ be entered as from Foto SF6r FIs. sF7: Hokice that when CHR codes are added to the strings they become part of those strings, and are stored as single characters. When printing out the KEY LIST the Finstein alters the values of any characters below 32 by adding 128, for 1f it tried to print some of these control characters it could have adverse effects on the display, ‘The last character in each string, be it a printable or control code character, is altered sutomatically which will be shown overleaf, 60 in the case of FO above the last 2? characters are altered from 21 and 13 which are unprintable to 149 and 14. me "and "R characters are shown in the appendix of this book along with other control code symbols. Tt should be remembered that the ASCIT code area from 126 to 160 can pe used for storing sprite patterns, therefore one could find when entering REY List that the "e has changed to some other shape, but it will not affect the operation of the function keys. To clear the function keys simply load them with a space, ef even enter the following in direct made - without a line nonber - which will clear ali the function keys:- FOR Asef TO 15: KEY A," "z NEXT CENTER? 1£ memory space in the function key buffer is critical there are some abbreviations which can be made by using seme control codes. Ag an example we defined function hey 4 asz- “CLS 40 :LIST"+CHRS (21 )-+CHES 1131 which is 12 bytes in total. There are contrel codes - ingle bytes - which will clear the screen in the sane way that CLS does. There are cthers which will clear the screen and alter it te 32 or 40 column node. These are shown in the DOS/MOS Intreduction under the CTRL key section. Maybe you didn't realize that these codes are actual ASCIT control codes, well they are, and as such can he used within @ string of character: Pressing the (CTRL» + «N> keys will clear the screen to 40 column mode, So will entering:- PRINT CHRS(14) Another method of remembering the above is that Wis the 14th letter in the alphabet, Arnad with this knowledge function key 4 could be reduced by 5 bytes by entering it as r= REY 4,CHRS(14)+"LIST"+CHRS(21)+CHRS(13) which will only use 7 bytes of the function key buffer. Obviously using some control codes can have disastrous results! Tf one does not have a printer connected to the Einstein then donot use CHRS(1) or CHRS(18), which t= similar to presaing the ¢CTRL? + 4A) or keys, 40 as these codes relate to the printer and the Einstein will drop into a trance and the only way cut ds to press the Feset Dutton which could result in your program being «iped out. In this chapter we have referred to the function key entries as strings. Th strings are similar to the string variables which one uses in programs = conbinations of ASCII characters, One could append a control character toa string variable within « program for certain results, CHRS(7] ig the control code for 4 tone similar to that of ‘the BEEP command, Tf one required » message to sound an audible pronpt each time it was displayed one could use CURE(71. A Typical line could per- 100 AS="What ta your Mama! +CHRS(7} and whenever A$ wae printed on screen the tone would be heard too, One could even prefix the string with a clear screen code a that the screan was always cleared prior to the message being printed: - 100 AgeCHNS(12)e"What is your Nane"+CHRS (7h The answer is to experiment. ay 3 Character set On power up, ar after the basic command RST hae been used, the character set is loaded in from the ROM ares of memory into the Video RAM srea. Being in VRAM means the characters are soft - they can be altered. The complete ASCIT set - that's 256 characters - are nade up of 8 bytes each, therefore to store the complate set takes 2048 bytes of memory. They are stored fron addres 7800 to 1FFF hex (8144 to B19) decimal) in ¥RAM. Characters with a value of 32 of less are all blank as, besides character 32 (space), they are used as control characters and are not printable on serean. = The appendix shows how each character ie formed and where in VRAM it ie lecated, To create 4 new character, or sprite, one may either use the SHAPE command or, af Will be seen later, the VPORE funetion, The Introduction manual describes how each character ie formed by using an 6x8 pixel grid. Tt must be remembered that all characters will be reset to their original forms after the RST conmand has been used, this will wipe out any sprites that had been defined. Many commercial programs use RST to reset MBAS to its switch-on condition, snd a by product is that the characters are re- initialigation as well. It is recommended that sprites should be defined in characters 128 - 160 as these aro unused. Tf you read the chapter on Key defining one would have seen that some of the characters in this area are initially set to display the control codes when KEY LIST is entered, but they can still be overwritten, Defining a character is not that az easy, 48 one should possess sone knowledge of how a byte is composed, the Introduction manual should give one an ides on the format, However if the manual is used in conjunction with the next progran it should become even clearer, The program, although a bit lengthy, is designed to let you experiment with different shapes for use in one of your own programs, Once you have decided on a final shape you should copy down the shape values which will be @isplayed for use ag characters or sprites in your own program, It will allow ome to move the cursor around = displayed grid using the cursor key: The keys will auto repeat if held down but the cursor will not move out of the specified grid. Once running the program will ask you to enter ‘1' for a noreal size 8x8 character or ‘Z' for double size 16x16. Afterwhich you should then enter the ASCII number = in decimal - of the character you wish to alter. Tf you choose an ASCII number which already has a character assigned to it it will be displayed on the grid. — Henes entering 141 would display the "_ character as below, which can obviously be altered az it Le only used with REY LIST. To switch on a square, or pixel, within the grid simply press any key on the main keyboard except «SPACEY or key and the pixel will switch off. Once you are satisfied with the character preas the ¢ENTERy key and the shape will be displayed in the top right of the a screen with the correct line which should be entered in one of your own prograns shown at the botton of the acreen. When one has entered a 16x16 character or sprite, which defines 4 characters, the columns are divided on screen and the hex value for each row is shown, One may either use the SHAPE command followed by the 32 items in a string, or enter 4 separate SHAE connand followed by & items in the string, the program will prompt you to press any key to show the alternative, This is how the screen would look after entering this 16x16 shape, with the hex values for each row shown alongside the grid, and the recommended form of entering the shape shown under the grid. OF =FO =9o8 mic sie =i8 = = =1¢ =O8 =F2 43 #9 OF =56 =OA 31 =8c =1io 206 =F EF FE =14 26 =14 =2s =14 =26 mid 28 =14 =28 To enter the above qnaes use:- SHAPE 128, "GF OSO81810929056" SHAPE 129,"3110FF 1414141414" SHAPE Le ee eee haces SHAPE 131, "8COBFF2828262626" and enter each sinaly 10 SPRITE OFF: TOM 4,0 20 BOUL @: GOOL 15,01 TOO, 18,03 cLado 30 PRINT “Entor size of Sprite” 40 PRINT "Press 1 for BxB,..2 for 16x16" 50 SZeINCH 60 IF SE¢49 OR $0259 THEN PRINT: PRINT “ENTER 1 or 2": REEP?GOTO 40 70 CLS: Si-S8-481 IF S8=2 THEN MAG 34ELEE MAG 1 BO PRINT "Enter character number to modify” 80 PRINT “For sprites it is best to use numbers" 100 PRINT “between 126-160." 410 IF SZ =1 THEN 140 120 PRINT “16x16 eize MUST be entered” 130 PRINT “as multiples of 4: {.¢.128,132,136 atc” 140 THPUT CHAR 150 IF CHARCO OR CHAR 255 THEN PRINT "Between 0 and 25 ":BREP:GOTO 90 160 IF S242 AND CHAR NCD 4¢70 THEN BEEP:GOTO 120 170 x90 180 D=CHAR*646144 190 ens3z 200 FOR B+1 TO 6 210 FOR Asp TO De{a#sna1) 220 FRINT# X,POS(2) 210 Ag -BIN$ (VPEEK(A}),6) 240 TOR Bel TO B 250 IF MIDSLAS,By1 ha" CAREC 235); 260 NEAT 8 270 PRINT 280 NEAT A 290 XeOrbearPRINTE O, 300 GOSUR 80D 310 REM DRAW SINGLE CELL 320 DRAW XC*O,191-(4C°R) TO XC*846,191-(7C%H) TO ACMA 1B3-( 744) TO ACH, 18I-(YO*B) TO XC*S, 191-1 ¥C*B) 350 PRINT® XH, YH 340 XCePOS1 }:YC=POSI2Y THEN PRINT CHRS(32};:ELSE PRINT 350 360 370 ASTNCH IP A=13 THEN GoTo 440 IF Aed AND POS(1):8*S2-1 THEN Xv¥exXC+1:G0TO 31 LSE IF A=4 GOTO 310 300 IF As AND POS(1}>0 THEN XN=XC-1:G0TO 310rELSE IF A 268 GOT 31m 390 IF A=1D AND POS(2)¢B*52-1 THEM Ya¥Ce!:GOTO 110:ELS FTF AetO coro 310 san :G0TO J102ELSE IF IF Al? AND POS(2}>0 THEN YN=¥C- As11 GOTO 310 ap 420 aap 440 aso a60 a7 960 490 son IF As32 THEN PRINT " "sGoTO310 PRINT CHRS(2351:GOTO 310 REM DEFINE ENTERED SHAPE IF Sf=1 THEN 520 FoR ¥20 TO 15 LING=MID$ (SCRNS(Y), 3,151 LIN$ “4Lrns, PRINT# 8, }LINS FOR 4296 TO 152 STEP 8 DRAM X,191-(Y*B) TO X48,191-(¥*8) TO Xe, 163-(¥98) TO X,183-C¥*8) Ta x, 191-198) S10 520 san S40 550 560 Sto 58D 590 san 610 620 630 ean oso 66m NEXT X,¥ FOR B=0 TO 53-0.5 STEP 1.5 FOR Ye0 TO 8°S2-1 LIN$=MID$(SCRMS(¥),B*8+) ,B*B<8) c=0 FOR Xe1 TO 6 TF MIDS(LINS,%,1]=" “THEN 590 CsC+2"(8-%)sREM THE * KEY 15 3RD FROM RIGHT, TOP NENT X PRINTR (B+ }*a,¥3"="7HENSIC,2) SHS «SHS +HEXS1C,21 NEXT ¥,B PRINT® 0,16,"To enter the above shape use: - WIDTH 30 PRINT" SHAPE"; CHAR ;CHRS (44) ;CHRS( 34); SN8;CHRS(341 SHAPE CHAR, SHS 670 5B0 690 700 70 720 730 740 641,16 130 760 70 780 790 800 aio 20 830 8a SPRITE 1,200,160, 15,CHAR IP S%e1 THEN 770 PRINT"ALTERNATIVELY,.{prees any key)" a ENCH wIpTH 32 PRINTR 0,173 FOR ¥=0 TO 3 PRINT "SHAPE"; CHAR+Y;CHRS(441;CHRS (24) ;HIDS{SHS,1*1 CHAS( 34) ;CHRS (21) NEXT ¥ PRINT" wrDTH Oo xD REM DRAW FULL GRID FOR X=0 TO 64*S2 STEP 8 nd enter each singly" -DAAM K,191 TO K,191 64°52 DRAW O,194-x TO 6452 ,191-% NEXT RETURN a7 Alpha characters We have seen how one can alter each ASCIT character by the SHAPE command, but they can also be altered using the WPOKE function which will alter the contents of video RAM memory directly as the PORE function will on RAM, A diagran showing the VRAM map is shown on page 315 of the Reforence ramal. The table which holds each character commences at address 1800 hex (61dd dec) in WRAH. To calculate the address where a particular character is stored one would take the character number and multiply by B& ~ as each character Taquires 8 bytes to hold the 8 rows of pixels. This figure ie added to 6144 for the start address of the character. To find where the ‘A’ character is stered we first take the ASCIE code of A, which is 65, So 654Ba520, G144+520-6664, character 'a' is stored from 6664 decimal in VRAM. The following program alters the A - a - zand Oto 9 groups to slightly larger, and you may agree, clearer characters by increasing their height. A normal character is usually made up thon: ~ With an empty row of pixels top and bottom, Note that the 2 right hand columns are also bare due to the 40 cqlumn screen mode only displaying the first 6 columns. So unless one is using 32 column consistently it is unwise to extend the width, tut the height? = Possibly, One can alter the alpha characters to whatever but, if common sense is to prevail, they should pear some resemblance to their original characters. Hoenn QaavAWHS obs05000 10 20 a0 4a 50 60 70 cy a0 100 110 120 130 140 180 160 170 140 190 200 210 220 230 240 250 260 270 260 290 300 319 320 430 340 350 360 370 380 390 REM UPPER CASE FOR Xe6648 TO 6871 READ AS? VPOKE X,VAL("S"en$] > HEXT DATA 38, 44,94,08,10,0,10,02REM 7 DATA 36, 04,04,24,54,54,38,0:REH @ DATA 10,28,44,44,70,44,44,02REM A DATA 78,24,24, 38, 24,2 5 DATA 16,24,40,40,40,24,18,0:REM C DATA 76,24, 24,24,24,24,76,02REM D DATA 7C,40,40,78,40,40,7C,05REM DATA 7C,40,40,76,40,40,40,02REM F DATA 36,44,40,5C,44,44,28,0:REM G DATA 44,44,44,7C,04,44,44,03REM I DATA 38,10,10,10,10,10,38,0:REN £ DATA 1C,05,08,08,48,48,30,0 a DATA 44,48, 50,60,50,, 48, x DATA 40,40, 40, 40,40,09,7C,0:REM L DATA 44,60, 54, 54,44 ,44,44,0:REM DATA 44,64,64,54,4C,4C,44,0:REM a F Q ® 5 r u v " x ¥ z DATA 2, 44,44,44,44,44, 38 ,.03REH DATA 78,44,44, 78,4040, 40 ,0:RH DATA 38, 44,44, 44,54,48,34,0:7R2M DATA 74,44,44, 78,50, DATA 34, 44,40,38,04,44,38,05REM DATA 7C,1B,10,10,10,10,10,02RE00 DATA 44,44,44,44,449,44, 38,02 REM 44,28, 26,10,020EM 144,54, 54,6044, 03RBM 26,10, 28,44, 44,02REM 38,10, 10,19,02REM 10,20, 40,70, 44,0: REM BATA dd, DATA 44, DATA 44, DATA 7c,04,08 REM LOWER CASE FOR K=6920 TO 7127 READ AS: VPOKE X,VAL("6"SA$}: NEXT DATA 0,0,38,4,3C,44,3C,0:REM a DATA 40,40,56,64,44,64,58,0:REM b DATA 0,0, 38,44, 40,44,38,02REH DATA 4,4,34,4C,44,4C, 34,0 DATA 0,0,36,44,7C,40,38,0:REM © EM 400 410 420 430 440 450 460 470 480 490 S00 si0 520 530 S40 550 560 570 580 590 600 ao 620 630 640 650 66D ero 60 690 700 70 jae a0 700 750 76 174 Ten BATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA BATA BATA BATA DATA DATA BATA 9,14,10,7C,10,10,10,0:REM f 9,0,34,4C,4C,34,4,38¢REM 40,40,78,44,44,44, 44,0288 bh 14,0,30,10,10,10,38 ,0:REM 4 8,0,19,8.8,8,48,308REM 3 20, 20,24, 78,30, 28,24 ,0:REM k 30,10,10,19,10,10,38,02RER 1 0,0,68,54,54,54,54,0:REX m 0,0 ,58,64,44,44,49,08REM m 10,8844, 44,44,38,02REM o 0,0,58,64,64,58,40,402REM p 0,0,34,4C,4C,34,4 0,0,56,64,40,40,40,0:REM r 0,0,30,40,78.4,78,0:REM = 20,.20,76,20,20,24,18,0;REM t 0,0,48,48,48,08,34,0%REM uo 9,0,44,44,44,20,10,0:REM v 0,0,44,54,54,54, 28,0: REM w 9,0,44,28,10,28,44,0:REM x O,0,d4,44,40, 34 9,0,70,8,10,20,7C,02REM z REN TO 9 FOR X=6528 TO 6607 READ BATA BATA DATA DATA DATA DATA DATA DATA DATA DATA REM [ AS: VEORE X,VALA"R"4A$)2 NEXT 18, 44,4C,54,64,44,38,0:REM 0 10,.30,50,10, 10,10, 70,02REM 1 38,44, 4,8, 30,40, 7C,02REM 2 3604449016 .4 44498 ,03REM 3 6,18, 26,48,7C,B.4,02REM 4 ‘7,40 40,78 18,0+REM 5 18,20,90,78,44,40,38,0°REM 6 Fe,-44,68-10,10,10,10,02REM 7 38,44,94,38,44,44,28,07REM B 30 ,-44,44,30,4,8,30,02REM 9 r FOR X=6084 TO 6479 READ DATA, DATA A$: VEORE K,VAL("@"*AS): NEXT 4,10, 20,20,20,10,8,02REM 4 20,10,8,8,8,10,20,0:REm 1 SI Sprite management ‘The Video display processor is mapped out on page 315 pe the "Reference manwal' and it Will be seen that an area in the VDF is allocated to the ‘sprite attribute tabla", Although sprite movamant 18 adequately deacribed in the nenuals, the following could be of added interest to those whe like POKEing, but in the case of VRAM it would become VPOREing, ‘The table starts at 15904 (83800) in VRAM and is°128 bytes an tength, This table is divided into 32 blocks of 4 bytes each, one block fer each sprite. The first block (15104 to 15107) controls sprite 0, the second block (15108 ta 3111) eentrola sprite 1, and ao on. "Tf we tumber’ the bytes in each block from to 3, the first byte - hyte 0 ~ 4m each block contains the ¥ co-ordinate of tha top left Pixel of the sprite. One should net pay too much attention tothe contents of thia byte as it does not take into account any altered ORIGIN that may be in force, and also measures the position from the top of the sereen and not the bottom. Hence entering the following line:- SPRITE 0,0,8,15,65 will display the character 65 - A - in the lower corner of the screen in white, We know that the ¥ co-ordinate is at Position &, mut it is stored in the first byte in the block as 183 (191 Enter PRINT VPFEK(15104) will alter the character to 8, one will not need to know the current K of ¥ co-ordinates of the sprite. To eliminate excess code one could set up either of these ealeulations as Futictions by entering early in the program: 5 DEF FRM(S)=8"44+18194e2: REM Character nupber change G DEF FHC(S) 2344015104032 REM Colour change Where S-eprite number. go to alter the colour of sprite number 7 to black one could enter:- VPOKE FNC(7},1 «ENTER? to alter sprite number B to character 30 - 2 - enter:= VEOKE FNN(B),90 CENTERY The advantage of altering colours and characters in this way means that a sprite on the move can be changed without the need to know ite pregent position. One further point regarding the atteibute table, When the command SPRITE OFF is encountered all sprites are switched off and esch has the first byte in its attribute table - the ¥ co-ordinate - altered to tha value 192, Entering SPRITE OFF 1 would only alter the first byte of sprite 1's attribute block to 192. Nornally to turn off several sprites ona requires to enter a sucerssion of numbers following SPRITE OFT. However if one VPOKEs the value 208 into any ona of the block's first byte all higher numbered sprites will be also turned off. ‘The block for sprite 4 begins at YRAM addres T5120 (404+15108) and if we enter VPORE 15120-208 ¢ENTER? all the sprites fron the & character upwards have been cleared from the screen, There is no method in basic of detecting when 2 sprites have collided - when their pixels overlap. ‘The YOR, which is a customised chip, does record such collisions but it is not simple te arasp how this chip operates, in fart a book could be written on this subject alone. The following routine which is POKEd high up in RAM can be called whenever one wishes to detect a collision, It simply tests one bit of the atatus reqister of the VOF (there are 0 registers ip total) which is set if sprites overlap. It does not detect which sprites have overlapped, simply that a collision has occurred. ce Tt stores the result in address $7336 and when PEEKed the result muat be ANDed with 3? which will test the relevant bit, Here is a simple demonstration, the machina code routine, which is the part one would transpese into your own program, is in lines 20-49, 10 SPRITE OFF 20 CLEAR 57327 30 FOR K=97328 TO 57335: READ A: PORE X,At NEXT 40 DATA 6,136,219,9)50,248, 223,201 50 FOR X#100 TO 150 60 SPRITE 0,X,8,15,65 20 SPRETE 1,250-x,0,1.65. 80 CALL 57328:AePEBR(S7336) AND 32tIF Ar32 THEN GOSUB 110 30 NEXT X 100 END 110 PRINT "OVERLAPPING NOW’ RETURN ‘This purely sends 2 sprites towards each other, line 60 doce the testing and diverts to Line 110 and prints the mecsaqe only while the sprites are overlapping. 4 Peeks, pokes, do's and don'ts This chapter highlights some of the lesser known facts concerning the Einstein, and sone menory addresses which can be altered in XBAS 4,2 for various effects. CTR, key presged in conjunction with various keys will produce results as shown in the ‘Reference manual’, ther give the same results if ured with the CHRS function. Pressing keys produce a tone similar to the BEEP command as #111 PRINT CHRS(7), az G is the seventh letter in the alphabet. Tt must be stressed that if you do not have # printer connected, or it is not switched on, than pressing ) prompt when in MOS. $4321 (8F841) contains the value 32, vnich 1s. the blink Fate of the cursor, PORBing a Lover value will increase the rate while 4 higher value slowa it down. Try PORE S4321,10 to speed it up a little. $4322 [AFIM2) elds the value 160 which dm the initial delay before a key repeats. Lowering..the value will shorten the delay, increasing will lengthen. #4327 (SPE43) controls the repeat rate of a key held down, that is how quickly successive characters are displayed afler the initial delay above, It normally contains 16 but 4 lower value will increase the rate while increasing will slow it down, This could be apeeded up within a program before a rapid response from the INCH command was required as this delay aleo effects INCH - see next, 64326 [4FB46] contain the ASCII value of the last key Pressed or held down. This could be used as a faster method of testing for keys held down - for oxanple in ganas Programs. EB scans the keyboard once. and returns the ASCII code of a single key press, If tha key is continually held down it will return the value once and thereafter return 0 until another key iz pressed. This sbviously has advantages where one is asking the user for Anputs from the keyboard for if they were slow at releasing 62 a key it would have no effect. But for faster keyboard checks @ PEEK(61326} will return the ASCII value ono continucus basis, Try this: 10 ASKBD: PRINT A 20 coTo 10 and run the program pressing various keys, and held them down. Frege (SHIFT +cBREAKy to stop the program. A value other than zero is displayed only once when a key dn first pressed. Alter line 1f toz- 10 PRINT PEEK(G4326) and con the program with keys held - spot the difference? 84335 1APE4P) contains the current screen size - either 32 or 40. It Ss possible to alter the value of this byte without clearing the screen, hence 32 and 40 column display could be mixed and displayed on the same screen. Try the fol lowing:- 19 cLs40 20 PRINT "1234567890" 39 PORE 64335,32 40 PRINT "1234567850" There are certainly sone adverse side affects, especially when editing, but it could be used in moderation. 4406/7 {aFB96/7) store the current X co-ordinate of the graphics pointer in 2 bytes, POS 1 and 2 return the current text cursor position but it appears there is no system variable for discovering the graphics position. PRINT DEEKIG4406) will display the current x co-ordinate, but this met be added to the presant ORIGIN position, If ORIGIN is set to 0,0 as it is at switch-on then the ahove command will give 4 true position in relation to the viewed screen. One can move the current X co-ordinate to a new Position, without using DRAW by DOKE 64406, new x position. 4408/9 pointer eaatost 2 bytes however corrent result. eaanaya be used [aFB96/9) contain the ¥ co-ordinate of the graphics and can be weed with DREX and DORE am overleaf, {AEB9A/B) contain the K origin co-ordinate, These are up@ated when the basic ORIGIN command is used, there ig no command within basic to discover the ‘origin. Entering PRINT DEER( 64470) will supply the (ars8e/b) contain the ¥ origin co-ordinates and cat as above. 5 Additions to XBAS Thies chapter containg two utility routines which can be added to Tatung/Ktal Basic 4.2, the basic interpreter, Developed by Crystal Research the original versions for various machines allowed the weer to create extra commands and functions to be sdded to the interpreter and used as if they were already built into the TAL basic language. Adter further enhancenents a superb version specifically weitten for the Binstein was produced, but it didn't forget its origins, and despite being able to accomplish a host of tasks not thought possible in the early days, it ia still capable of being expanded and additional commands added. As the basic interpreter, XBAS, is stored in RAM it is simple to alter the valves contained in any memory location, some might comment too simple as indescriminate changing of values could, and probably would, result in a systen crash ~ programs will not function correctly, if at all, However if this condition does occur no lasting damage will be done it simply means that one will need to re-load XBAS of, at Worst, press the reset button on the rear of the machine and start all over. The methods of altering memory will be demonstrated in these sections. Fer those readers who have sone understanding of machine-code and assembly language mnemonics any alterations made to menory lecations will be described along with the respective instructions, Readers who have no knowledge, or aren't bothered with, machine- code need nave no worries as the longer additional routines wE1l algo be shown as direct basic programs which can be entered by anyone with normal keyboard experience, Before any alterations are made it is wise to fermat a new disc for the modified XBAS to be recorded on, The format facility is fully Geseribed on page 4D of the bos/mOs Intreduction manual. XBAS ready message To gain some practice, and to aee sone immediate reavlte, of altering memory contents we will alter the ‘Ready’ MBRBS ge, in, SEA, Ingert s copy of the master disc and load XBAS in the normal way. The screen will clear and the following should be displayed TATUNG/XTAL BASIC 4.2 (¢) 1983 1984 Size: 43324 Ready There are 2 methods of changing menory, the first is from NOS which is the machine code monitor ection of the Machina Operating System. Enter the comnand:- MOS ENTER? and the following will be sereened with the cursor flashing next to the chevren:- MOS 1,2 Ready > The Ready message ig stored in memory starting at location O73 hex (1955 decimal). Enterr- TOTA3 O7A7 «ENTER? and the screen will display:- O7AS 57 65 61 64 F9 Ready The hex mumbers to the right of O7A3 are the values contained in the 4 bytes O7A3 to D7AT hex. The values used when in the MOS, oF 00S, sections of the operating system are always displayed, or entered, using hexadecimal notation and not decimal. To the right of the line are the ASCII characters these ‘unbers represent. Check the values with the chart in the appondix of this book. | The only character which does not match up with the values is the final one, the letter "y'. ‘The ASCIT code for 'y' is 79 hex (121 decimal} but as the Hinstein must be able to separate the end of the mes: fron other inetructions within memory, the final character in a string + for that's what it 16, a string of characters - has 80 hex [128 dec) added to ita value. So adding 60 hex to 7% hex the resultant value becomes FF hex, in decimal this becomes 128 + 121 = 249, check with the hex/dec conversion table in the appendix. To make the Einstein even more ‘user friendly" ene ould alter "Ready" to your own initials, auch as ‘OK JR’ for instance, Tha 'Ready' meseage is 5 bytes long so our alteration must not exceed this number. You vill no doubt have your own ideas of alteration, but for an example let's try the above initials. Firstly one should look up the hex values of the ASCIT characters to be used in the message. Page 706 of the ‘Introduction to the Einstein’ shows the hex values, For the above nessage these are:- o kK sp oR the hex codes are 4F 48 20 4A 52+80-D2 Note that the code for space (sp) must be used and the final character's value hae &0 hex added. to alter memory contents when: an ROS: one anters the & connand rolloved by the etacting address. Tn Unie case one vould enter:~ MOTAI one should return to BAS by entering either the or ‘x! keys followed by the key. Characters shown under the DISPLAYED colunn are what you should see on the next screen line after Pressing ENTER, The COMMENTS colump contains a description of the entries for reference only and must not be entered. DISELAYED 10 ENTER COMMENTS Ready Hos Hove into MOS from basic Mos 1.2 Ready * NBR PTR 3 address of Aux word table mes cS) (O13E Alter PTR 3 te 3E01 2BBA 04. Full stop = quit Modify node > wapaz PTR 6 address of Aux addr table 289235 803 Alter PTR & to 3Fao zesece. Quit modify mode > C3BCS 3034 3601 Copy Aux word table to JB01 > C3CIS JC6G 2P80 Copy Aux addr table to IFa0 > FINCK 3Ce6 OO Fill old tables with 00 Wo have altered both the suxiliary reserved word and auxiliary addrese tables {PTR 3 and 6) to adresses higher in memory. Note that hex addresses are held in 2 bytes but they are ontered in roverse order, eo the bright sparks can relax they were not typing errors. We then move the conplete tables by using the MOS conmand C which copie whole sections of memory and places them elsewhora in memory. Hence the aueiliary reserved word table which resides between 3BC5 and 3034 hex (15301-15492 dec vag copied to start from address 3601 (19873), We aren‘t required to enter the finishing address of the new table position as the Einstein calculates this automatically, although for future additions to XBAS e should keep a note of this end location, it new finighes at address 3670 (15964), The auxiliary address table which started immediately after the word table at 3035 to 3066 hex (15413-15462 dec) wos copied to start fron address IF60 (16258) and this now ends at SPRY (16905). The F for Fill command simply loaded zeroes inte the original area taken up vith the tables, as unwanted code at these locations could cause confusion at @ later stage. At this point one could alter the initial sign-on message to show that one is using a modified copy of XBAS. The message ts held in memory Incations 3D9D to JDCS (15773 to VSBI3}, Entering:- TIN9D 30CS «ENTERY will display the contents of the initial message thust- 3080 54 41 84 55 de 7 OF 56 TATUNG/S 3DA5 74 61 6C 20 42 41 53 49 tal BAST JAD 43 20 14 2E 32 20 20 20 ¢ 4,2 3084 20 20 28 42:29 20 39 39 CT 30RD 38 33 20 37 29 4m 34 OD 83 1984, 30c5 an. Any byte can be altered within these memory Locations to another character by using the (Modify command in Mos, except the last 2 bytes, 0D and BA. The OD ia the code for carriage return, which moves the cursor back te the hoginning of the screan line, and the final chacacter BA is the code for line fead (0A) which moves the cursor down to the next screen line, with 80 hex added to its value. As with the 'Ready' message the final character in a printable string has 80 hex added te ite value signifying the end of message. One could change the message to include your own version number, as one may make other copies of XBAS with different conmands added, it would display the version number each time it loaded, Hore is one suggestion of how it cowld be changed. If one altera the bytes which display the "(C} 1983 1964" part of the megeage, that's the bytes between 3DB7 and 3DC3, making 43 bytes in total, As you will not be altering the last byte of the neesage there will be no need to add 80 hex to the last character, simply look up the hex values of the ASCII characters, Hence to alter the message to include ‘Version 1.0" the hex codes for which are:~ voe 4 s.d To cB dee? os hie 56 6S 72 73 69 GP GE 20 3 26 30 As there are only 11 characters in the above, the initial message will still print part of the line which contained the year numbers thust= TATUNG/tal BASIC 4.2 Version 1.084 So adding ? space characters (20) to the line will erase the extra characters. One should enter fram KOS MID? ana the display will show the cursor flashing over the 2 of % the value 24, Ac with ‘Ready’ singly type in the values without spaces and Einish off with the full stop before pressing the ENTER key:- 5665 727369606E2031 2E202020. «ENTER? Whether you have altered the seage or not ane should now return te basic by entering X CENTERS The screen will now clear and display the initial sign on message. To save the modified basic to disc we met enter pos by either entering DOS or by pressing the CCTRLY+¢BREABY keys. Saving files under DOS is different from saving basic rogram: in that the size of the file needs to be calculated first. ur version of MBAS Joads at 9100 up to 4200 hex, therefore the sire is 4100 hex 44700 - 4100). This figure should be converted to decimal and then divided by 256 to discover how many blocks it will occupy on the aise. 4100 hex equals 16540 decimal, therefore as 16640/256-65 the plock size will be 65, With a newly formatted disc in the drive enteri- SAVE 68 XBRS.COM cENTER? Ana after a few seconds the expanded version of XBAS will be saved toa now disc. One need not call it MBAS, it could be saved with just 1 character in the nama but one nust always add the ,COM to whatever it is called. Wow one has an expanded version a MBAS, capable of having additional commands added, there will probably be little need tc alter the addresses for the reserved word and address tables av was shown earlier, Simply make any additions and save under 095 az iz shown above. 7% Adding routines. It is difficult to write routines into the basic interpreter without » knowledge of machine code and the way the interpreter operates. These pages show the principles invelved and with care one should possess a copy of XBAS with sone useful utility aids to programming, There are 4 stagea to adding an extra conmand to XBAS. end al Enter the reserved word of the command to tI of the auxiliary reserved word table - PTR 3. bl Increase the value of the first byte in the table. This byte holds the total number of words in the table. c) Add the address of the new routine to the end of the auxiliary address table - PTR 8. 4] Enter tne machine code routine to start from the address entered above. There are 2 methods shown for adding the extra commande in this chapter, The first is by using the HOS command Modify. This first example should help clarify most points regarding how the tables are set up, especially for those readers considering writing their own routines. The embly language mnemonice for aach ingtrvetion are also shown under the COMMENTS column. The second is by a basic program in which the values are simply PORES dizectly into memory using READ and DATA stetenents, which some may find easier, n Trace function The trace function provides the facility of displaying the number ef the current line being executed in a basic program. In this routine it 16 displayed in the top left corner cf the screen, ‘This can be useful when trying to track down a bug in one of your own programs or perhaps searching for a line in some commercial software to find how a particular effect is programmed. Entering TRON before running a progran will turn on the trace command while TROFF will turn it off. Although XBAS ha: a SPEED command for slowing down the output it ids ther on or off. Tneluded in this routine is the option of pressing keye between 1 and 7, while the program is running, to slow at down when and where required. Fressing the "7" Key once - there is no need to keep it pressed - would be the slowest speed. Pressing any other keys of the main keyboard would return the speed to almost normal. Whilst the TRON command is switched on programs do run slightly slewer than normal, but as this command is only used while debugging a program this should not cause any inconvenience for when TROFF is entered the program runs at the normal speed. Adding words ‘The first task is to enter our new reserved words -TROW and TROFF = into the auxiliary reserved word table. To check on the correct Jocation to place then we will display that area of memory by using the MUS command Tabulate to see just where the auxiliary word table finishes, Tn tne Last action wo noved this table to start at address 3Ei1 7B (15873) and we calculated that it finished at 3E70 (15984). Load the modified copy of XBAS then enter:- MOS Kote The bytes above containing FF nay be displayed aa 00. Here we can see the last few reserved words: BINS( RST BEY ACC( BTN( and PSW. Note that the last byte in tne table ([JE70) is 60 hex. This signifies to the Einstein that it da the end of the table. So our new word, oF words in this case, must start from byte number S870, and overwrite the old table end value of 80 hex, amd we must remember to enter 80 hex after the last character of our new reserved words, Each word has the top bit of its first character set, slow down I hear from the back, Ina sindlar fashion to how screen messages have 4&0 hex added to their final character - as witn the ‘Ready’ message - reserved words have 80 hex added to their first character. No this ie net done to be arkward, the Einstein must be able to differentiate between words in the table, Take the eixth character in the ling commencing with JE66, it is the letter Poof the reserved word PSW. The ASCII code for P is 50 hex but as this is the first character of that word it has #0 hex added, so giving a valve of 00 mex, nm The codes fer the 2 new words are as followss- T = S4+80=D4 T + Sds8o-nd Ro 52 Re 52 oar oO. ar Now aE Pe 46 Fe 46 + end of table marker = BD Enter: W3E70 tENTER? and the display will show: ETO Bp with the cursor flashing aver the 8. &nter:- DAS2OP4TOAS 24FdGAGEO. ENTER? If you want to check that the 10 bytes have successfully been entered in the correct place in memory enter:~ TIESA JETE CENTER? and the display should showi— 3E68 28 C2 54 46 28 D0 5] 57 (BTM(PSW 270 D4 52 4F 4B D4 52 4F 46 TRONTROP 3E78 46 80 PF FF FF PF FF FF Fae , Note The bytes akeve containing FF may be displayed az 00. ‘The end of table marker (49 hex} is now at location 3E79. Auxiliary word count ‘The first byte cf the auxiliary reserved word table (PTR J} contains the total number of words in the table. Az ¥e have now added 2 more words this byte must have ats velue increased. There were 25 words originally in the table, ea renembering that it how starts at addregs 3E01 enter:- M3E0! «ENTER? and the display will show:- E01 19 19 being the hex equivalent of 28. So with the cursor flashing over the 1 of 19 ente: 1B, and the display will show the last few bytes of the address table (The 6 bytes with FF may be shown ag 00):~ SPAR PS 28 90 2F 34 2e 4c 2c x+./ FBO FA 35 FF PF FF FF FF FF t5.. » This time we are not looking at words but actual addresses in memory, therefore the ASCIT characters to the right of each line are insignificant. The addresses are in pairs, so taking the last 2 at 3FBO and 3FB1 we get PA and 35. Addresses stored in menory are always Ln reverse order, #0 this pair of bytes results in the address 35FA. As it is the last address in the table in can be quite rightly alate assumed that it is the address of the routine for the last word in the ayxiliary word table, which was the basic reserved word PSW. Working backwards on the line sbove one will see the pairs of bytes equal the following addresses: aed 24d FSC and 26FB. = These 4 addressee will be the locations of the other words which were displayed at the end of the auriliary word table: BTN( ADC KEY and RST. Our routines for TRON and TROFF are going to be placed in the now redundant area of memory where these tables used to sit, cenenber va filled it with zerces, The last byte in the address table is 3FRI (16305), so our 2 addresses must be placed at 3FB2/3 and 3FB4/5 (16306/7 and 16308f3). These are 38C5 for TRON and ABCC for TROFF, Enter:- M3PA2 CENTER? The cursor will be flashing over the first figure, and renenbering that each pair must be entered in reverse order, enteri~ CSIBCCIB. tENTER? Adding the routines Before we actually write the routines for TROW and TROPF it isa good idea to check that we have altered the tables correctly so far. Before we started altering the tables had we entered either TROM or THOFF, whilst in basic, the interpreter would have displayed the "Syntax Error’ messaqe as it would not have recognised either word ae 4 valid command. Before going any further wa should run a check to discover if these words are now accepted as valid. Tf we enter the het code (9, which fg a return instruction in assembly janquas te the starting addresses of both routines and subsequently enter either command, no error message should be displayed, just the "Ready' message, Go back into basic by entering: ~ 4 CENTER? Now enter:= POKE €3BC5,8C9: POKE &3BCC,4C# ‘ENTER? and then enter eith TRON «ENTER? or TROFF 8101 THEN PRINT"INCORRECT DATA": STOP 80 DATA 62,1,50,203,59, 20% ,0,175, 24,246 ,2537,03 ‘70 ONTR 81,1, 56,203,59,163,200,229,42,55, 1,229 80 DATA 17,0, 0,205,198, 34,205,184,2, 76,105,110 90 DATA 229,42,80,1,205,255,2/205-184,2432032 00 DATA 32,160,58,61,1,254,49,56,18, 254,56, 46 V10 DATA 14,294,480195-735,135,135.71,14,0,10,120 120 DATA 177,32, 251,209,205 ,198, 34,225,201 130 REM Add TRON & TROFP to Aux. word table 140 POKE 15994,212,62,79,76,212,02, 79,70, 70,128 180 POKE 15873, 27:REM Increase word count 160 PORE 16306,197,59,204,S59:REM Mad addresses to table 130 PORE 3562,205,207,59,0:REM Alter exec loop EDIT command Although XBAS contains 4 very versatile LIST command in which various parameters can be added for a host of listing variations not found on most computers, this second utility command will list one Line for editing purposes. when « program has come to an unscheduled halt due an error, and ve al] gat them, if one enters EDIT ‘ENTER? the erroneovs line will be listed on screen with the cursor flashing at the end of that line. There is no need to ‘enter the line number as XBAS keeps a record of faulty line numbers, This can only speed up that time conauming task of debuqging programs. To list any other line, whieh had not caused the program to stop, say line 100, one would enter EDIT 100 ‘ENTER? and line 190 would be displayed with the curgor at the end of the line. Once tha line has been corrected hitting the ENTER key will store it in memory in the normal way. Thia means one vill not need to keep entering LIST followed by various paraneters when just ona line is to be listed. If the program hag not stopped due to errors, or is stepped by the SHIFT+BREAK keys then entering EDIT on its own, without a line number, will simply do nothing and abort the edit routine, as there will not be a record of a faulty line, ‘This il] also be the case if the program stopped Que to a line which contained the STOP command, After one hag entered this routine a grey function key could be assigned with the command. KEY 6, “EDIT"+CHRSIN3) «ENTER? So that when a program encounters ar error one could pr just one key - FG - to List the faulty line. lon of It is assumed that one is using the expanded vei HBAS and that the previous TRON/THOPP commands have already been added. For those readers who prefer entering the additiens via a basic preqram the equivalent alterations under basic are shown in the alternate program fol lowing these MOS entries. After adding the 2 previous commands the end marker for the auxiliary word table is currently at 2879 (155931, so we must add our new reeerved word EDTT and remember that the first character has @0 hex added to its value. The ASCTT hex codes are thust- = 45e80605 46 249 34 send of table marker © 80 aeo0n If in basic enter:- MOS ‘DISPLAYED TO ENTER COMMENTS MOS 1.2 Ready e H3CIE ae16 co cDAAD CALL 0204 ;docs line nun follow? 3C19 OO 2605 oR £,3c20 mo just edit had Line 318 08 cp3a1k CALL 1633 get Line number in DE icte oo 160B on 328 igo find line in menory cs} BISPLAYED TO ENTER © COMMENTS 3e29 pO BAAI01 LD A,(0183) peheck error flag 3c23 00 FEDO ceo ;Deno error 3025 09 aan JR 2,339 if no error then exit 3027 00 © EDSBAMOT «LD DE, 4OVA4) error line num into BE 3c2p 0g COBEGa CALL 0338 find ling in memory Je2e 903009 OR WC,3C39 ;doesn't exist, exit sew ages PUSH BC iBCsline addr in man, jos. FOP HL jput addr into WL 3o32 00 INC HL tincrement HL 4 tines 3013 0023 IRC HL ito Jump over cua 0023 IWC HL joffset to next line 3035 0023 INC HL fand Line number. icié 00 © chaT0a CALE OAD = List. DEeno, Hteaddr. acug.ap ct vor BC plose return off stack jcta 00 © C3ABO7 JP 0708 jback to edit loop 3039 00S Fiull etopsquit modify There are no further memory alterations for the EDIT routine, unless one wishes to show a version number in the initial message, which has previously been described. 70 save a version of expanded XBAS including this routine enter DOS then enter SAVE 65 XBASMOD.COM «ENTER» Or use another file name, provided it ends with .COM am the file type. As we fave not increased the actual site of XBAS = it still Finishes at 4700 hex as our new routines have been placed within that area of memory - the block size, 65, renains the sa this means that any further alterations shown in this book can be saved into the modified XBAS by the same method. a Adding EDIT with Basic Lead in the expanded version of XBAS that already has the TRON and TROFF routines added, then enter this progran, un the proqrem which will make the alterations to menory and save the modified XBAS under DOS ss shown overleaf. 10 Too 20 REM EDIT Routine 30 FOR X=15382 TO 15420 40 READ A: POREN,Ar T=Tekr NEXT 50 IF T<> 3433 THEN PRINT“INCORRECT DATA": STOP 60 DATA 205,170,2,40,5,205,51,22,24,11¢56,163 70 DATA 1,254,9,40,18,2]7,91,164,1,205,62,3 BO DATA 46,9,97, 225,35 )3535,35,2055 110,193, 195,171 ,7 40 REM Add EDIT to aux, vord table 100 PORE 15993,197,6B,73,B4,120 110 POKE 15873,281 REM Inereage word count 120 POKE 16310,22,60: REM Add address to table It is hoped that further sdditional routines will be published in magazines for the Einstein, however, it must be stated that they could be written to the same areas of memory that have been used here which moans that if they are to be used with EDIT and TRON sone alterations will be required. Wherever they are placed in memory they will, no doubt, need to alter the tables that we have altered and save a modified basic back to disc. If this happens it is advisable to compare techniques, yeu now know how the kables are moved ond extended along with the auxiliary word count, so try adding the new routines to another section of the interpreter. EDIT is relocatable as all the jumps are relative, one would only need to alter the address table ta the new start address. ‘TRON is not 60 amonable in that the flag at 3RCH is referred to twice - at JBC? and apn3, Both ines would need to be altered so that they referred to tha seventh byte in the routine, and ODER would need altering so that it jumped to the 11th byte as it docs now. 6 Restoring erased programs Tf one has ever erased a progran from a diec and then regretted it this section could help, Bact @ise contains a track which holds a directory of the files, or programa, held on that disc. The directory for each file is 32 bytes long and contains the file nane and type (4. .BAS .COM ete.,) along with the number of blocks on the disc the file is recorded on, When one onters the ERAse command all that happens is the firat byte in the directory block for that particular file will be changed from 0 ta EB hex but the actual file, oF program, will not be erased from the disc until another file has heen saved to that disc. fence this restoring procedure will only be effective if one has not recorded another program since eraging the one we wish to bring back to life, Although altering sectors and tracks on a disc is usually beyond the sverage progranmers scope and for most users the need would not arise, except that restoring the directory track could save time, So that one will be acquainted with the principles of restoring a program file one should first experiment with the example shown here. We will use a copy of the master disc not the original Raster, so if you haven't done so already now is the time to make a back-up copy of the master disc, which is described on page @0 of the DOS/MOS Introduction manual. It should be remembered that one should always use the back-up master dise and keep the original in a eafe place away from magnetic fields which could damaged the recordings. Load XBAS from the back-up disc then enter:- DIR «ENTER? and the disc directory vill be listed. We will er: basic program called THTRO, but as Mill be seen from the asterisk alongside ite name on the directory it muat Tarat be UNLacKed, which if one had used the LOCK command in the fivet place there vould be no eequirenont for this section 2 the in the book! But, as most proqranpers are ina hurry, few make full use of the LOCK command. Enter:- UNLOCK “INTRO CENTER? followed by: «= ERA “INTRO” If one fow lists the directory again, the program INTRO will not be ligted as an existing file on the disc, enter:- CLR The DOS/MOS Introduction manual describes how disc tracks, and sectors within those tracks, can be read from the disc into menory on page 12. Tracks 0 and 1 contain the Disc Operating Systen (005). ‘Track 2 contains the directory for the disc and this is the track we are interested in, Fach track is divided inte 10 sectors and cach sector contains Blz bytes. The directory always starts at track 2 sector 0 and cal grow in size, depending on the amount of files on the disc, up te the end of sector 3 which is 4 sactors or 2048 bytes. ‘The dieplay should be showing the cursor flashing next ta the chevron shape as below: mos 1.2 Ready » Enter the following:~ R8O00 A7FF G0 02 cENTER> And the disc will be read and its contents stored in memory Locations 4000 to A7PF hex (32768 to 34815 dec). = This equals 2048 bytes which, as each sector containa 512 bytes, Will equal 4 sectors, In the line above the Oi signifies: the eector number to begin reading and the 02 ia the track number. Although spaces betwaen each parameter have been shown these are optional, one could have éntered the above aa RBQOOBTFFOOO2 «ENTER? bot the first example with spaces is clearer. Mow we inspect the memory contents which have been copied from the directory track by entering:- ‘Ta00 BOTF CENTER? and the first 128 bytes from BO000 to BO7F hex (32768 to 32895 dec] will be displayed in rows of B bytes each, on the right of cach line is displayed the ASCII characters for the values on the left. This [T)sbulation of memory contents is described on page 12 of the DOS/MOS manual. We could have enterod a third parameter signifying the anount ‘of bytes to be displayed on each line, but omitting thie figure will eimpty Iist out ® bytes for each. One will see the file names on the right of the display and a typical display of a master disc could appar Ehust- 8000 00 58 42 41 53 20 20 20 .4BAS 4008 20 C3 4P #00 G0 DO 7A COM...2 BO10 01 00 02 00 03 90 04 00 .......6 4018 05 00 06 00 07 00 OE 00 vereeere 8020 00 42 41 43 a8 55 50 20 .RACKUP 4028 20 C2 4F 40 00 00 00 0D COM... 8030 09 00 00 Bo am 60 O08 00 4038 00 09 00 BD OM DO Ob OO A040 00 43 4F 50 59 20 20 20 aoa 20 C2 4F 40 09 00 00 2a 8050 0A 00 08 BO Oc 90 00 00 a058 00 00 00 0D Of pO OP oO 4060 00 4c 4F 47 4F 20 20 20 8068 20 c aF db Of OO Ob BO 8070 00 0 OF OO OF oO 10 09 6078 11 00 12 40 13 OO 14 00.1.2... One can sce how cach file takes up 4 lines of the directory space (448= 32 bytes We are searching for the file name INTRO, but as it has not yet been found we continue the search by entering? - TROGO BOFF ¢ENTER> On the master dise copy used for this example the file INTRO was found st addrese 9070, but your version may differ, so to continue searching enter the parameters for the next 124 bytes - THO M1 7F And don't forget the full stop after the 00 which quite the modify node and returns to normal. To ensure that the byte has actually changed value fron ES to 00 enter the tabulate conmand againt— ‘TO080 BOFP or to reboot DOs presse the sCTRL®+=R THEN 510 SOD S=S+12 SL(5h=x; SR(S)-R Sia Rad 520 IF 1 0 THEN 410 540 GoTo 320 NOTE To alter the sort from low/high ta high/low alter the following lines:< 420 IF BOx)>Y THEN x=x+1; GoTO 430 440 IF ¥oB(J) THEN J20-1: GoTo 440 No, of items Bubble sort, Faster sort 20 1 sec. 1 aec, a0. 3 seca. 2 secs, 40 5 3 50 8 4 60 12 & a0 20 6 cont.. 102 7a Sh aa so ae inh hnh wm Ho. of items Bubble sort Faster sort 1a ” 200 2 nins 99 2a 100 a mins 26 Bt aoa 7 ming 51 50 soa 12 mina 12 1 min 08 When testing it ie quite possible to qet slightly differant timings as the order of the random numbers will differ, this example was an average for é tests for each amount of numbers. There are faster sort routites written in machine ood but these are unfortunately too complicated for inclusion in this beok, vo alter the faster sort routine te cater for strings we first need to change the program to generate letters at random. The resulting strings will not be recognisable words simply strings of random letters of varying Lengths. Alter or add these lines?~ 710 DIM BS(N) 125 FOR Axi TO RND(TI#10 130 BS(K) © ASCX)+CHRS(INT(RNDI1}*26]485)1 EXT A 440 PRINT BS(X);" "7 190 Goro 390 240 PRINT BS(XEE" "5 420 X=Lt JeR: ¥S=BSC INTE (TOR) /2)) 430 IF BS(X)CYS THEN X=x41s GOTO 430 440 TF YS¢RS(o) THEN deJ-1: GOTO 440 460 SWAP BSC) ,BS() 100 8 Database Te was suggested that a decent sized program should be included in this book, pt what type of program? Past action games are in plentiful supply and would not necessarily appeal to every reader, A business program might appeal to even less, particularly az ach business would need it to be tailor nade to be noch use, That leaves ue with a databage, and before soma letter writers begin putting pen to paper to complain that the manual contains such a program, L will point out some difference: The sinple mailing lists are purely that, simple, and have hoon included to show how one can vrite data to either sequential and random access files on the Einstein, and they dq tha job! This randon access database, however, iz novel in that a text window ig set up on the top right of the screen enabling one to enter details, not just nanes and addresses, a8 ona would expect to see then laid out on a record card. The window is 31 characters wide by 4 lines deep, totalling 248 characters per record, and one can enter characters and move the cursor around within this window, The ENTER key will move down a Line but will not move out of the window if on the bottom line, similarly one can"t enter text past the notton right hand corner. Once the record ts visually correct cae can exit the entry routine by pressing the «ESC» key. This differs from the usual data base type of programs which normally require input of; Tnput Mame, Teput Address ete, and you are stuck with the output format that was written inte the program. 104 Apart from the top line, which is used as a key for sorting and always starts at the leftmost position, the remaining ? lines can contain Eoenatted text which can begin fron any column. Once the text has been confirmed as O.K. any leading spaces on the top, key Line, will be deleted and one will see the text being shifted to the leftmost position. The other 7 lines will always be displayed as ‘what you gee is what you get’ which means if you entered ling 2 with 3 spaces before any text that is how it will always be displayed, unless you wish to alter it at a later stage. The program can be used for any type of records, apart from an addr book - auch as club subscriptions, timetables, forward calendar or even a Vet's record book. After entering and saving the following programs one must run the "SETUP" program which allows ons to enter a heading for each of the § lines which are displayed to the left of the window. ‘These could be - Name, Addrass!, Addrese2, Phone etc., or Mame, Suba due, Date due, Paid on, and so on. If you don't require line headings one can simply press the key when prompted. A typical display is then sereened with any line headings displayed. If one approves of the set up the program then asks for the entry of a file name which, and as one can have several files on dise, mupt not be the same as another date file. Here one should not enter the .DAT part of the file name os this will be added by the program, just enter aname op to @ characters, such as ADDRFILE or CALEHDAR. The set up program now creates the Gata file on disc, and records any headings one may have appointed to the & Lines ef the window, This program is only used when creating @ sew data file, wnich one could have several of. Once a new file has been created one will always use the second program vnicn is simply named ‘DB’ but can obviously be altered. Keeping the name te only 2 characters makes 16 entry simpler after booting up 00S, one could just enter 'XBAS DB' and the «ENTER? key for basic to load in and subsequently load and run the main program. This main program first asks for the name of the data file and, once again, one should just enter the name and not the .oaT Part. The data file is read to discover how many entries it containa and the top lines of cach entry are loaded inte menory and stored, mote that it does not read in the whole 248 characters of each record, just the 37° possible characters in the top line of each. ACterwhich the program drops into the menu which also displays the current data file name and total entries:- ‘TRE TOTAL ENTRIES ARE 200 ON FILE NAMED CALENDAR MAIN MENU KEY 1 = ADD A RECORD REY ALTER/CHECK RECORD REY DELETE A RECORD REY SORT RECORDS 2 t REY 4 = PRINTOUT RECORDS o REY RDS PROGRAM Enter 0 to & Thera are 3 further progran modules which are called up by the 'DB' program, these are ENTRY, PRINTOUT and SORTING, The ENTRY nodule is the longest, due to it requiring conpon routines for the 4 options - Add, Alter and telete a record. All 3 are numbered 400+ as they are CHATNed ta the "DR" program which uses HOLD 399, 108 ‘The variable CHY holds the value of the last option selected. Hence after using the ‘PRINTOUT’ option CHM would contain 4. If, after returning to the menu, one gelected option 4 again, the program would not CHAIN ‘PRINTOUT’, aa it would know by testing the value of CHN that it was already CHAINed, and would goto line 400, The menu options: 1 ADD A RECORD When the program is Eirst run one will require this option first, as thera will be no records on file. aftor pressing the '1" key the ENTER module will be CHATNed and contrel will pass to line 420 - the add s record routine. The screen will display the window and the cursor will be flashing within, Enter the required text and pross the ‘ESC? key when completed, In the disqran below one can also see the nanes attributed to the @ lines at the left of the screens TATUNG (UK) Addreaal/STAPFORD PARK 19 Address?) TELFORD Addcreas3)/SHROPSHIRE TF] 3AB Q952-613111 Purveyors of fine machines @™ (ESC) to finish NEW ENTRIES THIS WILL BE ENTRY MUMBER 101 107 Renepber that any eorting or checking of entries is nade with reference to the top line of the window. Therefore if using names it will assist sorting and checking if the surnames are entered first with any initials or firstnanes second, © Oncg kay, it checks if the entry has been altered, and if it hag it is recorded back to disc, as there ia no point in recording back an unaltered record. 3 DELETE A RECORD This section uses the same routines as above for entry of the name to find, Once the record is ected it is displayed snd one is prompted to confirm that dt ia the record for deletion. Tt 1s then deleted from the disc and all higher records are moved down one place in the file, and the total antry value is reduced. 40 PRINTOUT RECORDS Once this nodule has been CHAINed one is given the option to print the files to printer or screen, Afkerwhich one Iss the option of displaying the conplete files, by entering "A', or just the top Lines of each file, If the ‘top line only is required printing is carried out straight away as these are already in memory - in variable array EYS$ix) = and can be paused by pressing any key. One fan ‘then continue the printing or return to the menu by pressing the zero key. If one requires output of the 108 complete files then these are printed as they are loaded in from disc, but this option takes a little longer. Once again the printout can Be halted as akeve but here one also has the option of moving backwards through the file. 5 SORT RECORDS When Ehere are a number of records on file it will bes good idea to sort them into order, ‘The files are sorted by whatever is entered on the fop lines, Whether your records show names or numbers on the top line they will be sorted by their ASCII codes. lence B is larder than A but Ais larger than the number 2. Records which show lower case - small - letters will be listed as higher than those using upper case - capital - letters, Refer to the AScIE code chart if you aren't sure on this point. ‘The sorting routine is fairly quick, even sorting 200 names fen't too slow. ‘The routine ie similar to that shown an the last section except that the strings aren't SWAPped, only the subscripts. This cuts down the time taken due to the strings not being moved about in mamory. The slowest Part of the sort module is when each string is read from one file snd placed in the ordered position in a temporary Eile. 200 entries will take nearly 2 minutes, so don't use it too often. Once recording is completed one will have 2 data files en the sane disc so the routine erases the old file and renames the temporary file, hich mas been recorded in the sorted order, to that of the original before returning to the menu. In its present form the program will not accept conmas when inputting # record, but one can alter this by using the SEP ‘conmand. The progran has been tested with 200 records, but if one wishes to extend this number, without any quarantees, one should increase the DIM variables an line 40 of the program 'DB'. 9 Thawe are RYS(x1,Sb0x),5R00) and 110 TP(x). Variable TF iz dimensioned to 160 and ia only used when searching for entries. It may only need increasing if more than 100 entries are similar to each other, which ia doubtful. No error traps have been included for experience shows that ‘these can lead the unwary to confugion when they haven't designed the progran themselves, bot once the program is up and running correctly, add then by all means, If one finde the program doesn't behave and gives erroneous results than check each program vith the listings, T know it can be boring but one would be surprised of the number of times ene can look at a line and miss an error, so let soneone else read it too. Tf one has appended the TRON routine shown in the basic additions chapter this can be used, but should be avoided during record entries as the routine reads the contents of the top screen line which will corrupt the records. If TRON was not entered before the program started one can stop the program, by entering ‘SHIFT? + enter “TRON' CENTER? and continue the program fron where it stopped by entering 'OONT' CENTER». Another thought is te add lines with the STOP command so one can tell where a progran has reached. They can soon be deleted if the error hasn't cecurred before that line is encountered, or one can enter ‘CoNT' to continue providing lines have mot been altered while the program waz STOPped. Tf you find # bug in one of the module programs = a program other than 'DB" - and correct it, remember that ‘pe’ is still latched onto the front end - up to line 390 - so delete these lower lines before saving the module back te disc, and finally if one has added additional lines, for different colours ete., do not renumber the programs until they are working as this can make back tracking almost inpossible. Bawe a nice da..ta base, m1 on m2 5 REM 3: SETUP PROGRAM 10 ORTGIN G,0:TOOR 15,0 20 CLS4O:BCOL 8: cOOL 14,0 30 PRINT'SET UP PROGRAM" 40 PRINT: PRINT*THERE ARE 8 LINES TO EACH RECORD" 50 PRENTIPRINT"ANY OR ALL THE LINES Hay HAVE A NAME 60 PRINS"UP TO 8 CHARACTERS Lac To USE AS A” 70 PRINTREPERESCE WHICH WILL BE DISPLAYED EACH" 80 PRINT'TTHE THE FILE 15 USED" $0 PRINT: PRINT 100 PRINT“YOU WILL BE PROMPTED FOR THE 8 NAMES" 110 PRINT"TF NO NAME 15 TO USED" 120 PRINT"PRESS THE «ENTERS KEY" 130 PRINT 140 FoR Aso To? 150 PRINT"HAME POR LINE" pa¢1 F2 INPUT" "srgray 180 TF LEN(S$t4/)28 THEN PRINT "OnLy B CHARACTERS": AEFI coro 150 170 IP LEN CWS(A)1S3 THEY BEEPIGOTO 310 (CaC-48: IF CeO THEN END: ELSE IF CHN=0 THEN GoTo 350 IF CH¥<4 AND Ced OR Cii¥=C THEN GOTO 400 ccum=c: weno 490 ON C GOTO 170,370,370, 380,190 n3 ‘370 CHAIN "ENTRY": REM USED BY OPTION 1,2 AND 3 280 CHAIN “PRINTOUT 290 Chamn “soatinc" 400 STOP: REM IF IT GETS HERE WE ARE IM TROUBLE End of program named DE The following pregran mst be saved as “curry 400 OW C SOTD 420,510,640 410 REM *#4¢¢08480044 AND RECORD 420 BCOL 2: TOOL 15,0: GCOL 15,0 430 HEADS="NEW EWTRTES" 440 BRENT: XEN 450 CLS40: PRINTE 0,13; HEADS 460 PRINTS 0,15 ;"THIS WILL BE BNTRY NMBER 2% 470 cosua 1310 490 IF Qs! THEN EN=EN-1: GOTO 200:REM ENTRY ABORTED 420 GOSUB 1690: GUSUB 1760: GUO 200 S00 REM eae ALTER/CHECK RECORD 510 HEADS= "CHECK/ALTER SpcTaon’ 520 BCOL 8: GOSUB BBD $30 IF L$-"0" THEN 200 S40 IF X20 THEN 200 550 TAS-A$i TES-B$: REM CHECK IF ALTERED $60 GOSUB 1310; REM DISPLAY FILE S70 IF Q=1 THEN 520 5B0 Gosue 1690 590 IF AS@TAS AND BS=TBS THEN GOTO 520 G00 RYS1X)=DEPTSIAS, 31) 61D OPEN FILES ,FDS,127 n4 620 GOSUB 1800: GOTO $20 630 HEM Seasaeeees DELETE RECORD 640 HEAD$= "DELETIONS" 650 BCDL 3: TCOL 1,01 GosuB 840 860 IF Lg="0" THEN 200 670 TF Xa0 THEN 200 660 PRINT@ 6,9; "DELETE THIS ENTRY? (¥/N)" 690 ASEN THEN 810 760 FOR AeX TO EW F70 INPUTH FDS, A241 GAS BE 780 PRINTH FDS, R*2=1jA5,-BS 790 RES(A)=RYS(AS1) eo MEXT A 810 HAMES=RIGHTS (HANES ,LEN (NAMES }-3) 820 NAMES=RIGHTS("00"4S57RS(EN) ,31 +6ANES 830 PRINTO FDS ,ONAHES 840 CLOSE 850 coro 650 860 REM 870 BEM teeeeees 880 CLS 890 PRINT HEADS 900 GUSUB 1020! REN FIND IT 910 TF ASC(LS)<40 THEN RETURN 920 PRINT: PRINT “Enter record number and «ENTER? key" 920 PRINT " to finish *:T00L 1360 xPeOr Pe 1370 IF yPo 7TH YPsT 1380 IF ¥P¢O THEN ¥P=0 1990 IF XP>39THEN XP=9 :¥P a¥Ps1:GOTO 1370 1400 IF XP-39 AND YP=? THEN BEEP 1410 IF XP¢3 THEN XP 239: YP=¥P-1:G0TO 1379 1420 PRINTE XP, YP; 1430 AeINCH {440 IF As13 THEN YPe¥Ps1 XP=9r GOTO 1370 1450 IF As4 THEN XP-xPe12 GOTO 1376 1480 IF Asi THEN XP=4P-12 GOTO 1370 1470 TP Aeld THEN YP=¥P+12 GOTO 1370 0480 IF Axl THEM YeeYP-1; GOTOII7D 1490 TP As25 AND XP+9 THEN PRINT" ";CHRS(25)2*P=39;¥P<¥P— 1500 TP A+28 AND XP29 THEN PRINT CHRE(2$): ¥P=xP=11 GOTO 1370 1510 IP A=2? THEN 1570 1520 IP 4P239 AND YP=? THEN BEEP;PRINTCHRS (AJ; GOTO 1370 1530 IF a<>26 THEN 1560 1540 TP As26 AND ASC(MEDS(SCRNS(YP),39,1)0732 THEN BEEPC core 1370 1550 PRINT CHRS(Abs GOTD 1370 1560 PREWTCHAS(A)rxPeXP+1:GOTO 1370 1570 PRINTA B,9;"I5 THE ABOVE O.k. (3/N} ": BEE 1580 ASSINCHGIF Ag="T"OR AS="y"THEN 1610 1590 PRINT® B,9;"c¥> TO RE-ALTER....¢N> TO QUIT 1600 ASSINCHS:TF age"Y" OR AS="y" THEN 1340:ELSE elt RET URW 1610 L1S-MIDS(SCRNS(D) 419,30) 1620 FOR Bei TO 30 2630 TF LEPTS(L1S,1) ¢o" "THEN B=39% RETURN 1660 IF LEFTS(L1S,1)=" " THEN LtSeRIGHTS(LIS,31 b+" "i PRI mre $,0;115 nF 1650 1660 NEXT PRINTEO,22;"THERE MUST BE AN ENTRY O8 THE TOP Linz": BEEPZ0 1670 1680 1890 1700 ag 1720 17:30 140 1750 1760 1770 1780 1790 ve00 veto 1820 1aa0 1e40 1850 1860 1e70 1880 1490 1900 1910 1920 1930 PRINT#O, 22;MULS(" ",39):GoTO 1340 REM **9¢¢=84¢8% LOAD UP STRING Ags" 2B$5"" EKYS(XD=RICHTS(SCRNS(Q), 31) FOR AsO To 3 AS=AS+RIGHTS(GCRHS(AI, 31) BPABSsRTCHTE(SCRNE(ASd), 31) NENT RETURN REM ¢t9e94ee* SAVE RECORD X AND INCREASE COUNT OPEN FILES, FDS,127 NAMES “RIGHTS (NAMES , LEI HAMES) -3) NAMES «RIGHTS("00"+STRS (EN), 31 +HAMES PRINT H PDE, GiNAHES PRINTH FDS,2*2-1 345,55 Lose Age": age": RETURN REM END OF SAVER Ren * ** LOAD IN RECORD x FRINTE 9, OPEN PILES,PDS,127 INPUTS FDS, X*2-15A,,BS FOR Bef TO $4 STER 31 PRINT TAB(10) ;MIDS(AS ,B, 31); CHRS(71):NEXT B FOR B=? TO 94 STEP 31 PRINT TABINO);MEDSIBS,B,371;CHRS(11/:NEXT B CLOSE RETURN End of program named geertcbly: Ty The following program must be saved aa "PRINTOUT" 4D0 CLS: HEADS-"PRINTOUT" PRINT HEADS 410 PRINT: PRINT "FREES AT ANY TIME TO PAUSE" = 420 TOOL 4,15: PRINT:PRINT"PREGS ¢P> FOR OUTPUT TO PRINT aR” — 420 PRINTSPRINT"ANY OTHER FOR OUTPUT TO SCREEN" 440 TOOL 15,02 PaINCH: PRINT: PRINT -450 TF Pe@0 THEN PRINT HeADS;" TO PRINTER” 4160 PRINT"PRESS KEY =G0 BACK. .ANY OTHERS CONT "7: TOOL 15,0 620 BeINCHt PRINTCHRS( 11 ;mucg(" PRINT 00) ;CHREETT) ;CHMECT TD + = 640 TP F280 THEM PRINT! 650 LF B=48 THEM CLOSI 660 TF Berd9 THEN 690 670 AeA-2: TF AC) THEN Ast: GOTO 540 880 GOTO 540 690 NEXT Ar CLOSE 700 TCOL 4,1$2 PRINT#HO]"¢1>PRINT AGAIN. .ANY OTHER FOR ME 72 BEEP: TCOL 15,0 GoTo 860 Ty TAD BetNCH: TF Bed9 THEN 490 720 coro B60 730 CLS:PRINT: PRINT HEADS TAQ POKESO13D,0 750 IF P=80 THEN PRINTW 760 FOR A«1 TO BN 710 PRINT"REC."| Rp TAB 9) FEYE(A) TBO SS=PRINT AGAIN. .ANY OTHER FOR ME MU "pr 859 TCOL 18,0: BeINCH: IP B49 THEN 730 860 GoTo 700 End of program nemed PRINTOUT The following program must be saved ar “sorrine™ 400 WEAD$=-"SORTING™ 410 CLS:PRINT HEADS 420 FOR Ast TO EW: TRIA)©A: NEXT 430 Sclz SLIV)=1: SR(1)=EN 440 L=SL(S}: ReSR(S)1 Se5-1 450 KaLz deRe X$eRVS(TPCINTE (L4R 9/2109 M60 IF #YS(TP(X))°X$ THEN X=X%+1:GUTD 460 470 TF MSCRYS(TPID)) THEN JeJ-1:G0TD 470 480 TF X00 THEN 510 120 490 SWAP TP(J},TPIX) S00 Xexet Ieg-1 510 IF Xe=J THEN 460 520 IF %—R THEN 549 530 SeS4lr SL(S)+xXr SR(S)=R 540 Bad $50 1F L«R THEN 450 560 TF <> 0 THEN 440 570 BEEP: AeSIZE2 PRINT"ENTRIES ARE NOW SORTED" S80 PRINT: PRINT"WATTING UPDATED FILE TO BISC™ 590 TEMP$="TEMP,DAT™ 600 CREATE TEMPS ,TP$,127 610 PRINTE TPS,07NAMES: 620 OPEN FILES, FDS,127 640 FoR Aat TO EW 640 INPUT# FDS,TE(AP*2-17A5 BS 650 PRINTH TPS,A*2=1)A5,B3 660 KYS(AP=LEPTSIAS,31) 670 NEXT A §8D CLOSE 690 ERA TILES 700 REN TEMPS TO PILES 716 core 200 End of program named SORTING You should now have 5 programs saved SETUP nane can differ oR name can differ ERTRY nane cannot differ PRINTOUT name cannot differ SORTING name cannot differ 120 Appendix Basic tokens and addresses of XBAS 4-2 The following list is of all the reserved words and their respective token values along with the hex routine addresses in the interpreter. Some tokens do not show routine addresses as they are handled within a parent routine = such as SPC is handled through the PRIWT routine. The firat section is for words in the standard reserved word and address tables. The starting addresses for both are stored in PIR 2 and PIR 6. Bes. vord, Iosen Adar, Rem. word Token SPC oF = DATA a7 (Ogee STEP 70 -- Der 6B OCS TAR n -- DEL 69 (1098 1 nm -- DIK BR OLGA ‘THEN n - DORE 8B OMA + mM DRIVE ge 2A23 - 8 = ELSE ap ORae 76 ‘nD ae OAT2 . n FOR ar = OD76 i 76 GosUB 50) anaD HOD 79 -- Goro 91 GBF AnD TR HOLD 92 1002 oR 7B 1F 93 OEE xOR Te oo INPUT a4 ORg9 > 1 -- LET a5 oc32 . 1B = LIST 3 | O95? ‘ 7P cond ‘LOAD a7 BAG Avro ao 1028 ne 340 1DFA CHAIN a1 aADE HOS a3 EBD ‘CLEAR 82 OBI NEW an DASE ‘CLOSE 630 2a NEXT 92 ODOE chs. aa FeeT OFF oC. 065 ‘conr as OrKD on 5D OBES CREATE 86 2987 corey ce 2079 Ww Res. word, our PORE BOP PRINT HEAD RE RENUM URPLOT RESTORE RETURN RUN SAVE PLOT sTOF SWAP VERIFY WAIT ERT APPEND: DIA ERA LOCK REN UNLOCK MUSIC CALL 104 NULL SEP SPEED wioTa ZONE TIS ‘TEMPO ‘vOICe PSG BR2RRELREREELEareazeee ea SQ RSR ER SERRRE aa 0479 0438 onED FAG ORBE ona 170 acra oxs2 opp OAEC 297 2cFC OAGS 1A66 2anT oa7F o6en 3640 3678 374g 201F 3703 3638 3145, DASE 0627 paiD D558 osra azo o6oa 0611 20BE 205A joa 2089 curs ‘DEER EVAL ‘EXP HERS INP INT Lew PEEK POINT ND ScRHS sow SIN INCH MULS Pr SIZE i a4 ae BEESLSSGRERaSSassS SBEUSRSSSSSRRSRSSESIE adic. 1D66 V45E VEBA V4aA5 qVEC4 O4B4 1608 1Eda 1588 OsSP Voce a7 B93 1BBT oan 062D O4A2 a61F 156D 1o6C VEC toro W538 TERO 1523 1aBA sare 1455 OS76 gap? O6B9 OcAD O4Eo O52a 15D1 1820 ose8 o4e4 m3 The auxiliary word and address tables can be found by PTH and PIR 8, ‘These words are tokenised into 2 bytes, the first of which is always FF hex. Res. word. Token Addr. Rec. word Token Addr. DRAM FF BO 01a FILL PF aD PE2B ‘TCOL FF BY 2CAB VPOKE oF BE 3480 GcoL FF B2 2c VEER PF Cr J4BA BcoL FF BS 2c9¢ VDOKE FF 90 ‘4oF SPRITE FF 84 2EBB VOEEK Fr DI aac? HAG TY 65 2EAC BEEP FF 92 75 SHAPE FP BG 2568 BIN$ fF 93 ‘349P ORIGIN FF 87 2cEE RST FF 94 2Bre ELLIPSE FP BB 2po4 KEY FF 95 2Fsc bos FF ag ‘DFC apc FP 96 2cu4 RAD Fran 6 (34D8 BTN FF 9? 2eac DEG FP aR MBC raw PP 98 35PA POLY FR ac | 2pDIc Hex/Dec conversion table The Einstein will print the hex equivalent of a decimal number by entering 2EXS(nunber|, however this may not always be convenient so the follewing page shows a2 table for converting hexadecimal numbers to decimal. The first column is hex and the second and third decim For example take the value of PTR &, which is 3C67 hex, the start of the standard address table in XBAS 4.2. To calculate the decimal equivalent take the first pair of numbers - 30 - which is known ag the most significant byte (MSE), and look up its decinal value in one of the centre columns, 3¢ = 15360, Now look up the second pair of fumbers - 67 - known as the least significant byte (LSB), and the decimal equivalent will be found in one of the ighthand columns, §7 = 103 eo add the 7 results which is 18360 © 103 = 18463, 124 24576 95 G1 24832 97 62 25088 98 69 25348 99 64 75600 100 65 25856 101 fh Ber12 102 6 FB 103 Hex Dec Dec }iex Dee HSE LSB. 68 2624 104 69 2E4HD 105 6A H146 106 6B 27392 107 6c 27608 108 6b 27904 109 8E 25100 11D OF 2saté LL 70 28672 112 1 23928 113 72 29184 114 73 29400 115 74 10606 116 35 79992 117 7 moe 118 17 3064 119 34 30720 120 74° 30976 121 7A EH 122 78 3148 123 ae 17s 124 3p 32000 125 3B 32256 126 3F 32512 127 so 32768 Lat BL 3324 129 82 35280 130 8333536 131 Ba 33792 132 B5 34088 133 B6 34304 1394 BT 34560 135 BB 3uHl6 136 Bo 35072 1597 Ba 35928 138 BB 35580 139 Bo 35640 140 8D 36096 141 BE 36352 147 ar Shenk 143 0 jobns 144 1 37920 145 92 37376 146 9) 37632 147 94 37888 148 95 38148 149 96 3BM00 150, 97 38656 131 9B e912 152 90 39938 156 9p 40192 137 OG a0sas tha OF 40704 159 An an60 160 AL 41216 161 az wla72 162 Aa 41728 163 Ab A158 16S AS 42240 165 kb 2096 166 aP 42752 167 AB 43006 168 49 43H 169 ‘AA 43520 170) AB 43776 171 wc 40032 172 AD 48208 173 AE 8546 178 AP 48900 175 BO 45056 176 BE 43912 177 B2 45568 178 wd 43826 179 By 46060 18D BS 46335 181 Be wH592 1 B7 4aai 1S BS ATLO4 184 BY A736 185 WA 87615 185 BE STB72 187 BC SB128 188 BD 48386 189 BE ARG 190 ‘BF GREG 19) ep N15) 197 C1 49808 195 C2 966d. 194 ¢3 4920 195 CA 50176 196 5 Sok3z 197 Co SOE Ia C7 Sea 198 CB 51200 200 €9 51456 201 Ca 51712 202 €B 51968 203 CG 52724 204 99 39188 153] CO 5zs40 205 3A 39626 154 | Ce 52730 205 9p 39680 155 | CF 52992 21 Hex Dee Dec HSB LSB a s3248 208 Di 53504 209 ba 53760 210 D3 34016 211 Da S072 212 Ds se5z8 713 bo 5474 214) B? 55080 215 Da 55296 Z16 D9 59952 217 Dh 55806 718 BB 56064 719 1% 56320 220 ‘i 56576 223 DE 58832 222 ‘pe 57086 223 TO 57348 226 EL 57800 225 £2 S7as6 226 S Se112 227 Es 50368 270 ES 58674 279 B2AGS 244 FS 42720 244 Fb 297 246 FT 32m 2e7 Fe B1kH8 288 Pp ITA 269 Fa ga00d 250° FB 64236 25) FC A512 252 FD BATH 254 FE BS024 254 FE 63280 255 15 araec, einen. 178 ethes. ane, aches. Phen. 18Pdee inex thagec, Senex. titans. ernex aznex. Iaedec. m= m” iyOdec. Ozhex crnes. aytdec. i i im Preeeery Taaeeere x fakes eases fone. BePdee. BEades 135 Adding addresses Adding routines Adding words Additions to ABAS 4.2 Alpha characters ASCLI codes Auxiliary word count: Basic token addresses Biorhythm program Bubble sort CALL Character set CLEAR Clock program cTRE Copy NOS Database progran DEF FH bare DRAW EDIT ELLIPSE Expanding xBAs Fast sort Yall HOS PILL FHT Function keys Function key buffer econ Mex/dec conversion HOLD TOM XRD iy 17 78 48 126 a0 122 108 55 az 85 20 56 74 104 16 12 2a ay 70 192 74 7 a4 a9 56 12a 3a Index Locked files Ibs Modify Os ‘ORIGIN PL Phechart program PLOT RAD Roady message ENUM Rostoring erased proge ast Saving additions SCRNS SHAPE Sorting data Sprite attribute table System files Tabulate Mos TIS TRON TROPF VAL VEOKE WIDTH 137

You might also like