Hidden Code
From Maze
(Difference between revisions)
(Initial entry) | (Fixing pre tags) | ||
| Line 9: | Line 9: | ||
'''Colors''' | '''Colors''' | ||
| − | <pre>''Set background color to dark blue | + | ''Set background color to dark blue |
Set text color to light blue'' | Set text color to light blue'' | ||
| − | 10 PRINT CHR$(205.5+RND(1)); : GOTO 10</pre> | + | 10 PRINT CHR$(205.5+RND(1)); : GOTO 10 |
The first environmental setting is apparent before the program is written; the default text and background colors of the Commodore 64. While these defaults can be overridden easily enough – text colors in BASIC on the Commodore 64 are printable characters so adding PRINT CHR$(30), for example, would make the text green; background colors are similarly changeable using POKE – the original 10-Print program outputs using the pre-existing conditions of the environment. | The first environmental setting is apparent before the program is written; the default text and background colors of the Commodore 64. While these defaults can be overridden easily enough – text colors in BASIC on the Commodore 64 are printable characters so adding PRINT CHR$(30), for example, would make the text green; background colors are similarly changeable using POKE – the original 10-Print program outputs using the pre-existing conditions of the environment. | ||
| Line 23: | Line 23: | ||
'''Screen grid''' | '''Screen grid''' | ||
| − | <pre>''Set background color to dark blue | + | ''Set background color to dark blue |
Set text color to light blue | Set text color to light blue | ||
'''Divide screen into a 40 column by 25 row grid''''' | '''Divide screen into a 40 column by 25 row grid''''' | ||
| − | 10 PRINT CHR$(205.5+RND(1)); : GOTO 10</pre> | + | 10 PRINT CHR$(205.5+RND(1)); : GOTO 10 |
While the code for 10-Print is devoted to choosing a character and printing it on the screen, it says nothing about where on the screen the chosen character should appear. Instead it depends on the Commodore 64's screen memory map, a system that divides the screen into a grid 40 characters wide and 25 characters tall while in text mode. Each memory location has an associated pixel position on the screen, and any character value that is stored in that memory slot will be displayed at the corresponding screen position. | While the code for 10-Print is devoted to choosing a character and printing it on the screen, it says nothing about where on the screen the chosen character should appear. Instead it depends on the Commodore 64's screen memory map, a system that divides the screen into a grid 40 characters wide and 25 characters tall while in text mode. Each memory location has an associated pixel position on the screen, and any character value that is stored in that memory slot will be displayed at the corresponding screen position. | ||
| Line 34: | Line 34: | ||
'''Truncation''' | '''Truncation''' | ||
| − | <pre>''Set background color to dark blue | + | ''Set background color to dark blue |
Set text color to light blue | Set text color to light blue | ||
Divide screen into a 40 column by 25 row grid'' | Divide screen into a 40 column by 25 row grid'' | ||
| − | 10 PRINT CHR$('''''round down'''''(205.5+RND(1))); : GOTO 10</pre> | + | 10 PRINT CHR$('''''round down'''''(205.5+RND(1))); : GOTO 10 |
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. | 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. | ||
| Line 45: | Line 45: | ||
'''Cursor''' | '''Cursor''' | ||
| − | <pre>''Set background color to dark blue | + | ''Set background color to dark blue |
Set text color to light blue | Set text color to light blue | ||
Divide screen into a 40 column by 25 row grid'' | Divide screen into a 40 column by 25 row grid'' | ||
| Line 54: | Line 54: | ||
Move cursor to column 0 | Move cursor to column 0 | ||
Move cursor down one row''''' | Move cursor down one row''''' | ||
| − | GOTO 10</pre> | + | GOTO 10 |
Once a grid has been established the software still needs to determine the grid position in which it should be drawing a character. Without this information the characters would be drawn either randomly across the screen or one on top of another instead of in the neatly linear pattern seen in 10-Print. The Commodore 64's text mode includes the concept of a cursor that begins on the left side of the screen, advances to the right by one column every time a character is printed to the screen, and drops to the next row while returning to the leftmost column after the final column is filled. The key command here is PRINT; if the characters were simply POKE'd to the screen, the cursor would not be moved and the environment would not automatically handle positioning. The semi-colon at the end of the PRINT statement ensures that a line break will not be inserted between each character, allowing the cursor to move horizontally despite only one character being printed in each iteration of the loop. | Once a grid has been established the software still needs to determine the grid position in which it should be drawing a character. Without this information the characters would be drawn either randomly across the screen or one on top of another instead of in the neatly linear pattern seen in 10-Print. The Commodore 64's text mode includes the concept of a cursor that begins on the left side of the screen, advances to the right by one column every time a character is printed to the screen, and drops to the next row while returning to the leftmost column after the final column is filled. The key command here is PRINT; if the characters were simply POKE'd to the screen, the cursor would not be moved and the environment would not automatically handle positioning. The semi-colon at the end of the PRINT statement ensures that a line break will not be inserted between each character, allowing the cursor to move horizontally despite only one character being printed in each iteration of the loop. | ||
| Line 63: | Line 63: | ||
'''Scrolling''' | '''Scrolling''' | ||
| − | <pre>''Set background color to dark blue | + | ''Set background color to dark blue |
Set text color to light blue | Set text color to light blue | ||
Divide screen into a 40 column by 25 row grid | Divide screen into a 40 column by 25 row grid | ||
| Line 78: | Line 78: | ||
Move cursor to row 24''''' | Move cursor to row 24''''' | ||
| − | GOTO 10</pre> | + | GOTO 10 |
10-Print is programmed to loop forever, so there must be a contingency available for when the cursor has filled the entire screen grid with characters and cannot move to the next row. In addition to automatically wrapping text, the Commodore 64's text mode also automatically scrolls the contents of the screen when the cursor is on the bottom row and attempts to move down. While it seems intuitive to do this, some programming environments would simply stop the program or return the cursor to the first column and row of the grid, overwriting the characters that had already been printed on the screen. | 10-Print is programmed to loop forever, so there must be a contingency available for when the cursor has filled the entire screen grid with characters and cannot move to the next row. In addition to automatically wrapping text, the Commodore 64's text mode also automatically scrolls the contents of the screen when the cursor is on the bottom row and attempts to move down. While it seems intuitive to do this, some programming environments would simply stop the program or return the cursor to the first column and row of the grid, overwriting the characters that had already been printed on the screen. | ||
