The Commodore 64

From Maze

(Difference between revisions)
Jump to: navigation, search
(modified RUN to serve as an intro for the chapter)
(Added transition to hidden code)
Line 28:Line 28:
==Hidden Code==
==Hidden Code==
−
(Note: This section does not get into areas that I believe are going to be covered in greater depth elsewhere in the book. The biggest glaring omission is in character sets/graphics. It is intended as a high-level gloss of some of the features of the environment that impact 10-Print's output; depending on the trajectory of the book, it might serve as an introduction to other sections or be fleshed out more itself. I'd like to take it in the direction of how other environments would change the output/require different code, but I'll see how it fits with other sections.)
+
Computer languages are like any other written language in that a certain set of assumptions must be shared between those who are reading them before they can make any sense. Writers in French have agreed to read from the left side of a page to the right side, whereas Arabic writers go from right to left. An English apostrophe has been agreed to have a functional meaning that is determined by the reader seeing it in the context of its surrounding text. Similarly, BASIC also makes some assumptions about the meaning of the code a programmer writes, including the expectation that the function CHR$(x) will only have values of x that are whole numbers. The fact that BASIC is running on the Commodore 64 specifically introduces even more assumptions, like the idea that a screen will always be 40 characters wide. A few of the unspoken agreements between programmers, BASIC, and the Commodore 64 include:
−
<pre>10 PRINT CHR$(205.5+RND(1)); : GOTO 10</pre>
+
1. Truncation
 +
2. Colors
 +
3. Screen Grid
 +
4. Cursor
 +
5. Scrolling
−
One of the features that make one-line programs interesting is the amount of functionality that can be squeezed from a single line of code. In the case of 10-Print, the final appearance of the program's output has as much to do with the Commodore 64's BASIC environment as the code that is actually written in BASIC on the screen. The functionality specified in the code – printing, looping, and displaying characters – is explored elsewhere in the book. This section looks at the hidden code, the functionality that is implicitly inherited from the environment and has a big impact on the aesthetics of the 10-Print program.
+
Since these agreements are indeed unwritten they do not appear in the BASIC code that makes 10-Print work. However, they can be understood by adding pseudocode to the program. Pseudocode is a descriptive, informal kind of notation that programmers often use to sketch out the functionality of a program without writing the specific code that will implement that functionality. It cannot be interpreted by the computer, but it is very useful for programmers who want to try to understand how different parts of a program will work and fit together–or in this case, how different parts of the code/BASIC/Commodore 64 system influence the output of running 10-Print's code.
−
'''Colors'''
+
<blockquote>10 PRINT CHR$(205.5+RND(1));: GOTO 10</blockquote>
 +
 +
===Truncation===
 +
 +
<blockquote>10 PRINT CHR$('''''round down('''''205.5+RND(1)''''')'''''); : GOTO 10</blockquote>
 +
 +
The process of choosing a random number is described elsewhere in this book, but one key feature of 10-Print's environment that makes the random number useful is its ability to automatically truncate decimals. The equation used to determine which character code to display, 205.5+RND(1), results in values between 205.500000 and 206.500000 and includes 6 digits after the decimal. Character codes, however, are integer values. In many environments the programmer would need to include a separate function to round off the equation output and create an integer that would be recognized as a character code, potentially pushing the 10-Print program beyond a single line. The Commodore 64 BASIC environment simply truncates the decimal value, resulting in character codes of either 205 or 206.
 +
 +
Modified version: not possible
 +
 +
===Colors===
<blockquote>'''''Set background color to dark blue'''''<br />
<blockquote>'''''Set background color to dark blue'''''<br />
Line 48:Line 62:
20 GOTO 10</pre>
20 GOTO 10</pre>
−
'''Screen grid'''
+
===Screen grid===
<blockquote>''Set background color to dark blue''<br />
<blockquote>''Set background color to dark blue''<br />
Line 59:Line 73:
Modified version: Not possible in text mode
Modified version: Not possible in text mode
−
'''Truncation'''
 
−
<blockquote>''Set background color to dark blue''<br />
 
−
''Set text color to light blue''<br />
 
−
''Divide screen into a 40 column by 25 row grid''<br />
 
−
10 PRINT CHR$('''''round down('''''205.5+RND(1)''''')'''''); : GOTO 10</blockquote>
 
−
The process of choosing a random number is described elsewhere in this book, but one key feature of 10-Print's environment that makes the random number useful is its ability to automatically truncate decimals. The equation used to determine which character code to display, 205.5+RND(1), results in values between 205.500000 and 206.500000 and includes 6 digits after the decimal. Character codes, however, are integer values. In many environments the programmer would need to include a separate function to round off the equation output and create an integer that would be recognized as a character code, potentially pushing the 10-Print program beyond a single line. The Commodore 64 BASIC environment simply truncates the decimal value, resulting in character codes of either 205 or 206.
+
===Cursor===
−
 
−
Modified version: not possible
 
−
 
−
'''Cursor'''
 
<blockquote>''Set background color to dark blue''<br />
<blockquote>''Set background color to dark blue''<br />
Line 89:Line 94:
<pre>10 POKE 1024+RND(1)*1024,205.5+RND(1): GOTO 10</pre>
<pre>10 POKE 1024+RND(1)*1024,205.5+RND(1): GOTO 10</pre>
−
'''Scrolling'''
+
===Scrolling===
<blockquote>''Set background color to dark blue''<br />
<blockquote>''Set background color to dark blue''<br />
Line 113:Line 118:
Modified version:
Modified version:
<pre>10 FOR I=1024 TO 2043: POKE I,205.5+RND(1): NEXT I: GOTO 10</pre>
<pre>10 FOR I=1024 TO 2043: POKE I,205.5+RND(1): NEXT I: GOTO 10</pre>
 +
 +
==Layers of Code==
There are many ways to program a computer. This is true in the general sense--that is, when setting out to work creatively with computers, a wide range of options are available. But it is also true in a more specific way: given a particular computer and a particular idea, there are often many different ways to accomplish a goal computationally.
There are many ways to program a computer. This is true in the general sense--that is, when setting out to work creatively with computers, a wide range of options are available. But it is also true in a more specific way: given a particular computer and a particular idea, there are often many different ways to accomplish a goal computationally.

Revision as of 18:06, 26 March 2011

View this revision of The Commodore 64.

Personal tools