42 Astoundingly Useful Scripts and Automations for the Macintosh

8 (bit) Days of Christmas: Day 11 (O Christmas Tree)

Day 11 of the 8 (bit) days of Christmas is the graphic accompaniment to “O Tannenbaum” from Robert T. Rogers “Holly Jolly Holidays”, from December 1984.

Jerry Stratton, December 21, 2020

Robert T. Rogers’s article, “Holly Jolly Holidays”, from the December 1984 Rainbow presented seven images and melodies:

  1. A snowman to the tune of Frosty the Snowman;
  2. A Christmas tree to Oh Christmas Tree;
  3. A star to Silent Night;
  4. A computer to Holly Jolly Christmas;
  5. A house in winter, to White Christmas;
  6. A sing-along with lyrics, for Jingle Bells;
  7. Flags of various countries to Joy to the World.

Item four is a bit self-referential.

If you want more songs,

Anyone can add or change the scenes and add new songs easily; just tack them at the end and change the line with RUN in it.

This is a lot of stuff for a single program. “It should fit in 16K, even though it was written on a 32K machine. If necessary, remove one picture and its music.”

Rogers also includes some tips to save memory:

When typing the listing you can omit the semicolons in the PLAY statements… Also, many of the LINE and CIRCLE statements are on separate lines for clarity; however, they can be put together on the same lines to save memory/time, just watch out for a few GOSUBs. The different segments of the programs most usually end with PLAY statements and begin with PMODEs, so if you need to eliminate routines to conserve memory, look at these areas for hacking.

I am always amused by BASIC how-to books from the era that extolled the necessity of commenting your code. As I wrote in my review of John M. Nevison’s Little Book of BASIC Style,

By the time the book came out, the audience was mostly people to whom that advice made little sense. In the penultimate chapter, he writes that “bad reasons” for code brevity “includes every argument about machine storage… Machine storage is cheap.” For him it was cheap, because someone else was paying for it. For someone with a Timex Sinclair and 2 kilobytes of RAM, space for program code was very dear. Some of his very, very short programs include more comments than code, easily using a quarter to half or more of the memory available on personal computers.

Comments were used sparingly for a reason: they took precious space away from making the computer do something useful. Rogers, in this program, uses one of the very useful tricks of the era: rather than waste a lot of space on comments, waste a little space on making the code itself more readable, and then let the reader know what to do to save memory. Tim Hartnell often had similar advice in his books.

I do think Rogers went a little too far in not even commenting the start of each item in his musical slideshow. To be sure of where the Christmas tree started, to show sample code for this post, I had to run the program and then hit break as the program started displaying the stars around the tree. If you’re following along, the Christmas tree starts on line 28 with PMODE3,1.

One reason you want to reduce the memory usage of someone else’s program is because you’ll want to add to their code. Rogers’s advice on adding new songs is a shorter version of Hartnell’s at the start of his Giant Book of Computer Games:

I deliberately wrote the programs in this book in the most general version of BASIC I could. Therefore, you’ll find no PEEKs and POKEs, no use of graphic character sets, and no use of such commands as SOUND or PLAY. I’ve assumed you have access to READ and DATA, and that your screen is around 32 to 40 characters wide… Of course, you’ll probably have to play with the display little, in order to make it as effective as possible. I expect, by the way, that you’ll modify and adapt the programs to make the most of your system, adding sound and color, plus your own system’s graphics, whenever you can.

I chose the Christmas tree image because it is especially beautiful. I chose all of these images first, and then found something interesting (I hope) to say about them. The code where Rogers draws stars in the sky says a lot about the style of coding of the day.

  • 37 FORE=1TO500:X=RND(255):Y=RND(192)
  • 41 PSET(X,Y,RND(8))
  • 42 NEXTE:GOTO61

The code FOR E=1 TO 500…NEXT E repeats this section of code. The FOR loop is the only multiline repeating block in these old BASICs. At each iteration through the loop, he’s setting X and Y to some value across the width (X) and height (Y) of the screen.

The PPOINT function looks at the value of the color at the specified (X,Y) location. The PSET statement sets the point at the specified (X,Y) location to the third value which is the color.

He’s randomly choosing where to draw stars, choosing from the entire screen. Both the X and Y are randomly chosen. If the color at (X,Y) is 3 at that point, which is to say, blue, then he replaces the blue pixel with a yellow pixel—he makes a star in the sky.

If the color is not 1, which is green, he skips to the next random point.

And then if the color was one, which means the random point is inside the tree, it sets the pixel to a random color—there are 8 colors, discounting black. Black is 0, RND(8) produces a number from 1 to 8.

So these random dots ignore the big shining star in the upper left; they ignore the red and yellow trees. But both the large and small green tree are decorated for Christmas.

Incidentally, that GOTO 61 that appears twice in this section of code is to skip over a subroutine. Lines 43 through 58 are a subroutine used on line 36.1 I always found it more normal to put all of the subroutines at the end of the code, often starting on hundred-based lines. My own “SuperBASIC” outputs code in this style, with subroutines and data at the end of the program. But that wasn’t the only style, and it was just as correct to intersperse subroutines (and DATA statements) inside the program, near to where it was used.

Despite my calling the FOR loop a multiline block, there really aren’t any blocks in this style of BASIC. The lines are interpreted in order, without any preprocessing. If the interpreter hits a RETURN, there had better be a GOSUB on the stack to return to; if the interpreter hits a NEXT E there had better have been a FOR E on the stack to return to. Other than that the interpreter doesn’t care, as evidenced by the presence of two NEXT E ends to the FOR E loop. This style of code was very common; the technically correct solution would have been for line 40 to end with GOTO 42 instead of NEXT E:GOTO 61.

Here’s a tip: make that change and you’ve got three extra bytes to play with. On my computer, free memory increases from 15,673 to 15,676.

A few bytes here, a few bytes there, pretty soon you’re talking an entire new image and song!

Rogers’s Christmas Tree

It is images like this that make the 8-bit style last.

In response to 8 (bit) Days of Christmas: Eight holiday images created on the TRS-80 Color Computer, from the early to mid eighties.

  1. I don’t understand why they’re separated into a subroutine; the subroutine is only called once, and so could just as well have gone at line 36 and pushed lines 37 through 42 up. The Color Computer had a RENUM statement, so this was not normally a problem.

  1. <- Day 100 Hearth
  2. Day 10 Help Santa ->