C64 Users Guide
From Maze
Jump to:
navigation
,
search
This wiki is a read-only archive; the page source is shown below.
[[Category:Variorum]] __FORCETOC__ == C64 User's Guide == 10 PRINT "{CLR/HOME}" 20 PRINT CHR$(205.5 + RND(1)); 40 GOTO 20 [[Image:C64 Users Guide 53.png]] == Variant in later editions of the C64 User's Manual == There are versions of the program where the last line is numbered "30": - In [http://www.softwolves.pp.se/cbm/c64manual/4.html An etext of ''Commodore 64 användarmanual''], a Swedish translation of the ''User's Guide,'' (c) 1985. - In [http://www.unusedino.de/ec64/technical/project64/users_guide2.html The Project 64 etext of the ~Commodore 64 MicroComputer User Manual (2d ed)~] Copyright (C) 1984 by Commodore Business Machines, (UK) Ltd. Converted to etext by Frank Jeno Kontros <jeno@kontr.uzhgorod.ua> C64UG210.TXT, June 1997, etext #251# '''Note that the line number of the last line has changed from "40" to "20."''' Also, SHIFT-CLR/HOME is indicated to clear the screen. <pre> 5.8. RANDOM GRAPHICS As a final note on random numbers, and as an introduction to designing graphics, try entering and RUNning this program: 10 PRINT "(SHIFT-CLR/HOME)" 20 PRINT CHR$(205.5 + RND(1)); 30 GOTO 20 The function CHR$ (CHaracter String) gives you a character, based on a standard code number from 0 to 255. Every character the 64 can print is encoded this way. Appendix F lists the CHR$ codes for all keys. A quick way of finding out the code for any character is to use the function ASC (for the standard ASCII code). Type: PRINT ASC("X") X is the character you're checking. X can be any printable character, including graphics characters. You must enclose the character in quotation marks. Here's an example: PRINT ASC("G") 71 The CHR$ function is the opposite of ASC. PRINT CHR$(71) G If you type: PRINT CHR$(205);CHR$(206) the computer displays the two right side graphics on the M and N keys, which are the characters used in the little maze program you just tried. The formula 205.5 + RND(1) tells the computer to pick a random number between 205.5 and 206.5. There is fifty-fifty chance that the random number will be above or below 206. CHR$ ignores fractional values, so half the time the character with code 205 is printed, and the rest of the time code 206 is displayed. You can experiment with this program by adding or subtracting a couple of tenths from 205.5. This gives either character a greater chance of being displayed. </pre> == Variant discussed in "Commodore Computer Club UK," 2008 == From [http://commodorecomputerclub.co.uk/view.php?art=commodore_free_23&loc=magazine#In%20the%20beginning%20part%208 Commodore Computer Club UK] 23 September 2008: ---- New programme and type in 10 ?"<clear/home>"<br /> 20 ? chr$(205.5)+rnd(1))<br /> 40 goto20<br /> Run that and see what happens on the screen. If you have a mess of M and N show up, press shift and C= for upper case. Ah there is this weird maze looking thing that shows up, over and over and over again. The programme will run until you press that run/stop key. What is going on here? That was my question, all of that stuff on screen for just a few lines of programming. We have already understood the first line as the shifted clear home to clear the screen. The Last line is the goto statement that loops the programme back again. But all the action is created in line 20. But what is happening there? We can tell that there is a print command, we can see that this is going to print something to do with a sort of random number generator. A closer look at the screen shows that the things printed are the slash lines on the N and M keys. How doe two symbols appear with only one statement to print them? That is how it looks at first. Lets work things out a bit. CHR$ stands for "character string", remember I said that there are 256, that is from 0-255, characters for the C=. Well each one of them has a character string, or a number. Real simple now, what is happening is that the chr$(205) is a one symbol. There is no chr$(205.5) the random number generator is basically making a number that will be between 205.5 and 206.5. chr$ will only accept the whole number. So you have a 50/50 chance of each of the two chr$ characters showing up and being printed on the screen, Rather fast for a 1mcps speed machine. <VBG> Don't worry if my explanation of how that maze is being created doesn't make a lot of sense, I think that it is a bit too advanced for this level. It took me 7 times through the book working with others to even have a remote idea on how the process works. What the important point is that you can print the chr$ as well as the reverse. This is done as follows. ?asc("z") Press return<br /> 90 will appear on the screen .<br /> ?chr$(92)<br /> Press return<br /> \ will appear on the screen . Try a few of these on your own, there are books, reference cards and other places where the lists of the characters and codes are already listed. Still it is a way to have a little fun and get more of a feel for the system. A way to see the actual character from the keyboard as well as finding the ascii value. OK here we have a time problem, I quote from the book. "As you probably figured out, 'ASC' is another function, which returns the standard 'ASCII' code type for the character you typed." Early on in this collection of drivel I said something about the characters ascii and PETascii. Ascii and PETascii are different animals, lets not worry what the initials stand for in this case, only that there is a gigantic difference. Saying that we come to the point of what is really "Standard". Because, obviously there isn't a "real" standard, making a ruling now, PETascii is the Commodore standard and normal ascii is the standard used by the IBM pc! Clear for that, PETascii is what we are learning about, so it must be the only standard we need right? And yes I am biased towards the C=. Going by the book we just moved into Chapter 5 "Advanced Colour and Graphic Commands" Lets jump right in, even with the personal thought that we aren't really that advanced. I mean I have never thought that I was that "Advanced" any time I had reached this point in the manual. Here they start you off telling you the colours for the control and the C= key, we already covered this a bit earlier on in the series. You remember the bit about using the Control key and the number keys to make the first 8 colours, then the C= key and the numbers for the next 8 colours. In order to illustrate this in the book there is a little one line programme they want you to enter and run. 10 ?"RAINBOW" What they want you to do is change the colour for each letter by pressing the control and keys 1-7. Doing that in front of each letter and using the numbers in that order, yeah they want control and 1 before the R control and 7 before the W. Then run the programme and you will see the word printed in different coloured letters on screen. The rest of page 57 is taken up with a chart that shows you the character gfx symbol that appears in a print statements, all 16 of them. Sorry the writing tool I am using doesn't have all those gfx characters in the set, since I am using the upper and lower case letters. You can experiment on that at this point if you don't have a list, creating your own list; OK I don't bother with that myself. Only look at the word on the number key for the colour and press that key in the print statement, but I am a lamer programmer and lazy to boot. At this point in the book and therefore the series of articles we are going to run into this symbol problem in different ways, Seen by this short program they have you type in. new<br /> 10 ?chr$(147): rem clear home<br /> 20 ?chr$(30);"chr$ (30) changes me To ?"<br /> run Well you don't have a chart of the character strings, do you? I'm working on the assumption that you don't, at least at this moment. I believe that there is a place online that has the manual for Down Loading. This list of codes are in the appendix in he back of the manual and in the Programmers Reference Guide. As well as in some of the type in books I have seen. Those of you who do have these charts, they are the ones that are ladled "Screen Display Codes", and the other one is "Ascii and CHR$ codes. You are lucky and I'd like you to thumb to that section from time to time. Right now we are dealing with the "Ascii and CHR$ Codes" one. OK back to that little programme. Line 10<br /> This gives you the CHR$ for the shifted clear home, Note that the number is always in the () symbols. Well my level and understanding of programming has me looking at that and counting the spaces. Counting the print command as the ? symbol, that is 9 spaces taken up. Using the ? and the shifted clear home in the quotes takes up 4 spaces. Seems this last style is more effective in spaces. More experienced programmers can tell me if I am right or wrong on this thought. I have seen the chr$(147) in type in programmes and substituted the shifted clear home, didn't appear to me to do anything different in the prg. Line 20<br /> This will print that character string and then the words in the quotes notice that there is nothing for you to do for a real answer, which is green, before I go to a complicated programme for you to type in. I should tell you something, a short hand way to write CHR$, which is cH. Well that is how it looks in lower case. Upper case would have the capital C and a vertical bar. Still have to type in the () things with the number between them though. ----
Views
Page
Discussion
View source
History
Personal tools
Log in / create account
Navigation
Main page
Recent changes
Help
Search
Toolbox
What links here
Special pages
Permanent link