Remarks: One-Liners

From Maze

Revision as of 21:22, 31 July 2011 by Nickm (Talk | contribs)
Jump to: navigation, search

In the early 1980s, magazines published one-line programs to fascinate and intrigue home computer users and to teach them how to write software. In the Commodore-specific magazine RUN, they appeared in a section near the front of the magazine entitled "Magic," which contained "Hints and tricks that will let you perform computing wizardy." Some of their one-liners and tips were clearly for amusement, having at best an educational purpose. Some were practical programming aids. Many were quite expressive and produced interesting visual effects.

Take for example, this one-liner from the April 1985 RUN (p. 8):

Sent in from a user named Larson E. Rapp: "When he's not looking, run this on a friend's VIC or C-64. Then get him to type a line or two, and watch the fun as he scrambles for his warranty." 10 poke207,0:poke204,0:wait198,1:geta$: print"{control rvs off}"chr$(asc(a$)+1.1*rnd(0));:goto10

This program is similar to 10 PRINT in a few ways. It runs in an infinite loop; it also makes use of the CHR$ and RND functions. Rapp's program, however, doesn't do anything obvious when run. After running it, the cursor sits blinking as if one were in the BASIC interpreter. Typing something will (often) cause the typed characters to appear on the screen as would usually be the case, but about one time in eleven, the next character in the PETSCII sequence will appear instead. Once run, this one-liner is actually in control of keyboard input and screen output and replaces BASIC and the KERNAL as the handler of input and output.

10 PRINT uses RND differently, to create an equal distribution of left- and right-slanted diagonal lines. As the Commodore 64 User's Manual was able to explain, this equal distribution can be skewed. Even with somewhat unequal distributions, i. e. changing the 205.5 to 205.3 or 205.7, the larger impression is still maze-like. The "essential frustration" of the maze is one that is evident and is due to its interlocking, larger structure to which the randomness contributes. Rapp's prank is tricky, on the other hand, because it is biased toward intermittent unpredictability that manifests itself infrequently.

Only the most utilitarian of one-liners were compatible across BASIC machines like the Commodore, Apple and Atari home computers and the original Dartmouth BASIC compiler. There were numerous of versions of BASIC, and some included commands such as PLOT and SOUND to facilitate making graphics and music. Of course, a one-liner using such a BASIC could take advantage of these special commands.

The Apple 2 with its BASIC commands for high- and low- resolution graphics enjoyed a rich culture of one-line programming as well as other variations in form such as "two-step" programs. "Two steps" were two lines long instead of one. That change in practice made them harder to memorize but more complex in their presentation. BASIC implementations with multimedia commands access their platform hardware often lead to more impressive one-liners which were not possible on the Commodore computers due to their relatively sparse operating system implementation, which may have been related to Commodore's earlier simple calculator products (Bagnall ??).

There is no space in a single line to include extensive data about specific movements, such as a 3-D animation. 10 PRINT relies on graphical images called PETSCII contained in the ROMs of the Commodore computers and simply refers to these using 205 and 206. Those two numbers are indexes into the "block graphics set" which 8-bit home computers used to draw simple graphics. The block graphics set uses more data to encode the image: 8 bytes for each graphic as opposed to the one byte used to point to it.

Block graphics have collectively allowed a non-alphabetic visual vocabulary to flourish. They have been used to represent emotions, stick-figures, space travel, balance sheets, and graphical window systems. In 10 PRINT, block graphics characters more firmly represent the notion of a maze than the typographic slash and backslash, which would not necessarily form complete diagonal lines.

This variation on 10 PRINT, called "Icicle Storm," uses one of its two diagonal graphics characters:

10 poke 1024+rnd(1)*1000,78: goto 10

This one-line simulation may represent the accumulating energy of a storm, but it will never, like a real storm, die out and warm up. After a while, the action will cease and diagonal lines, frozen, will fill the screen.

This illusion takes some imagination and relies on the default color scheme of the BASIC environment: light blue ice crystals against a dark, foreboding azure, sky at late dusk. Icicle Storm relies on the RND command as well as screen memory, the grid-shaped arrangement of memory locations which corresponds to the PETSCII graphics as they appear on a monitor.

In that program, part of the impression of movement and space-filling are features inherent to the medium of BASIC on the Commodore 64. Specifically, the slow, ruthless instantiation of icicles mimics the dynamics of a mounting storm because the computer can not draw them fast enough to fill the screen instantly. It would be possible to slow down the drawing, but not to speed it up (without resorting to something other than BASIC code, and without upgrading hardware or using a supercharged emulator). Icicle Storm shows a window gradually filling with frozen snow; 10 PRINT presents a somewhat cinematic representation of an experience as well. The pace of that experience is CPU-limited to the slow and steady rendering of their final output images.

In Icicle Storm, the unpredictable nature of the random number generator emulated the natural physical process of precipitation. This random nature can be combined with another hardware feature of the Commodore 64, the VIC-II chip. Together they create the following example which exploits the video chip inside the Commodore 64:

10 poke 53248+22,int(192+4+3*sin((time*3.456+rnd(1)*.5))): goto 10

The effect is to cause the main portion of the screen to slightly contract and the border to expand horizontally; everything that appears on the screen then shakes from left to right. This is a good example of one-liner program which exists not only to express a thought about weather, but also demonstrates the simplicity of working with the side-scrolling register in the video chip, an advanced topic which is never taught explicitly in the Commodore 64 manuals.

Commodore 64 BASIC has no specific commands such as PLOT and SOUND for controlling the video and sound hardware. As a result, simple sound programs are generally longer than one line. For example, the program below is an audio analogue of 10 PRINT. It plays a string of alternating tones balanced evenly between two opposing piano notes using the same pseudorandom pattern.

5 s=54272 10 poke s+24,15:poke s+5,190:poke s+6,248 20 a(0)=17:a(1)=37:a(2)=21:a(3)=76 30 q=int(.5+rnd(1)*1):poke s+1,a(q*2):pokes,a(q*2+1) 40 poke s+4,17:fort=1to75:next:poke s+4,16:fort=1to150:next 50 goto 30

This program can not be squished into one line for many reasons. As line 20 shows, the program must supply or perform its own calculations to create the descriptive data pertaining to the desired note. It is not possible, as it is in 10 PRINT and other one-liners like Icicle Storm, to supply an index into a reserve of information. That information does not exist to begin with in the Commodore 64. Commodore 64 BASIC does not have a command to produce a tone simply by specifying an index into a note table. These tables had to be included in programs. Furthermore, the sound chip requires two POKE commands to change the note frequency. Although this is because the chip is extremely accurate in this pitch control, it provides a hindrance to the development of one-liners that produce sounds.

Another way to go about probing the capabilities of complex chips like the Commodore 64's VIC-II and SID registers is to simply write random values to them. Here is such a program for the SID chip:

10 poke 54272 + (0*ti+(rnd(1)*25)),(rnd(1)*256)and255:goto 10

In the case of the video chip, writing random values may be unsafe. According to the Programmer's Reference Manual certain values must not be altered. You should try the following program only in an emulator:

10 poke 53248+rnd(0)*46,rnd(0)*256: goto 10

Personal tools