The lost ways of programming: Commodore 64 BASIC (2020)
tomasp.net
tomasp.net
C64 BASIC has ingrained 1 evil in me. "goto" Atleast once a month I'll be working on some script and I'm stuck but a little voice in the back of my head will say: "a goto would fix this part you are stuck on!" And damn if that doesn't reverberate into the past.
I went the hardware route. I bought additional hardware for my C64. First the 1541 (5.25" floppy drive), then the 1581 (3.5" floppy drive), then a 300/1200 baud modem, then a 2400baud modem.
I've been hardware hooked ever since. I'm now a sysadmin working with *nix servers.
I tried programming. I really did. I meticulously copied one of the sample programs out of the back of the C64 manual. It never worked.
GOSUB would put the calling location on a stack so you could RETURN to it later but there was no stack for parameters, local variables or return values so you had to use global variables for all of those.
You could not write recursive functions in BASIC unless you implemented a stack yourself using arrays. It was easy to compute Fibonacci iteratively, but people had to sort in BASIC all the time and wrote bubble sort, shell sort and other algorithms that were slow but easy to code in BASIC as opposed to Quicksort.
If you have the kind of functions that exist in C, Pascal, LISP, ML, Python and many other languages then you can write a simple Quicksort in a few lines of clear code.
One of the things many people fail to understand when they criticize GOTO and GOSUB is that it is essentially an expression of what is happening at the hardware level. Modern languages didn't really do away with them. They simply added a layer of abstraction that made it easier to develop reliable software. Unfortunately that abstraction also has overhead, which as problematic when you had a few kilobytes of RAM to work on with early personal computers. I would imagine that it was also problematic on the early multi-user systems that BASIC originated on. It isn't that GOTO is evil. It simply became less necessary for developers to use it in high level languages as technology improved.
Of course, the other thing that made spaghetti code inevitable was the line number based syntax. Until development tools improved, people were basically plopping new statements in random locations because they needed more "space" between existing statements. Yet line numbers were used in early systems since the BASIC REPL also served as a line editor. (At least on personal computers. I'm not sure how it worked on mainframes.)
If you added a bit more RAM than that you had more of a choice, for instance a 16K Color Computer could run
https://www.cocopedia.com/wiki/index.php/EDTASM%2B
editing programs with a text editor, saving them on cassette tapes, assembling them, etc. In the same amount of RAM you could have fit a FORTH implementation and with a disk system you could have an experience similar to BASIC based around editing individual disk blocks. With 64k of RAM I would run a C compiler on that color computer and people did the same with CP/M.
So far as mainframes at first they didn't have text editors, instead you would put together a deck of punched cards and submit that to the FORTRAN compiler which would output the object code to another deck of punched cards.
It wasn't unusual for people in the 1980s to use BASIC preprocessors that would read a text file, append line numbers, and let you use structured loops, and GOTOs with named labels. I read about
https://www.pcjs.org/software/pcx86/lang/other/ratbas/1982/
and wrote one for my TRS-80 Coco. It was the sort of thing you could write in BASIC without a lot of understanding about how to write compilers.
The problem, which you even mention, is that it's impractical to work with larger programs because their control flow becomes too hard to understand. Now, if you have (as many of the earlier BASIC systems did) only 4096 bytes of RAM you can't write such complex programs anyway, you don't have enough RAM. But even by the time these 4K home computers start to appear on the market the price of a modest business computer is tumbling, and such a computer might have dozens of kilobytes of RAM.
Once a flow diagram you can draw on a whiteboard isn't a correct description of your whole program, but merely a high level summary, go-to is just a foot gun.
goto is perfectly fine if used right. Kernel C code tends to use a lot of goto, to consolidate return points and to clean up resources on the way. A long function with no goto to one common return point, or multiple staggered ones, is suspicious.
The problem that led to the famous paper was rather that goto was abused, used at places where "higher level" control construct like "for", "while" and so on would be better. Partly because the languages just didn't have any, like for example... C64 BASIC.
Often within the scope of a function we would need to allocate/create dictionaries, arrays, other objects requiring disposal. MacOS's CoreFoundation API often returned NULL when creation (or insertion, etc.) failed. The sane thing to do when you got an unexpected NULL was to "bail" from the function. But rather than return immediately, there was clean up code at the bottom of the function — code like "if stackDict != NULL {CFRelease(stackDict);}". So we often added a label (called typically "bail") just before the clean up code and would "goto bail".
These were the days before garbage collection....
There was also far fewer variations of things to confound that info sharing. You had a c64, or 128, or Atari 800? You had the same everything as everyone else - same manual, same BASIC, same registers, same books available. You didn't have to worry about what version of something you had, or whether something got upgraded, or what video card you had, etc.
When there was a disagreement about something, it generally wasn't hard to at least point to a common base to start from.
1: https://www.c64-wiki.com/wiki/Commodore_64_Programmer%27s_Re...
[1] https://archive.org/details/Assembly_Language_Programming_Wi...
Over the in the other significant English-speaking economy, we were a lot poorer in the early 1980s, and as such, anything priced in US$ was too expensive.
So things like Atari 8-bits didn't sell well here. In fact only the budget C64 did, and it was an expensive machine in early-1980s Britain.
Which was a good thing, because it encouraged a flourishing local market in locally-made computers.
Although the C64 sold in the millions, and so is familiar to many, Sinclair's ZX Spectrum was even more common over here. And although we didn't know it back then, it was huge behind the Iron Curtain too, in the form of dozens and dozens of unauthorized clones. Every Communist nation had its own ZX Spectrum clone, or maybe several. Some adapted to display Cyrillic, some built from imported bits and some from Soviet bits, some with discrete logic in place of Sinclair Research's ULA.
And all of the Euromicros had better BASICs than the C64.
Sinclair BASIC wasn't great but it did graphics and sound. The best was BBC BASIC on the BBC Micro from Acorn. Named procedures, with local variables and recursion. IF...THEN...ELSE, various loop constructs, and inline 6502 assembler.
I reckon it's partly the terrible BASIC of the C64 that turned everyone against the language:
I think you suffered from what I did in Canada at the time, pre-free trade duties. Trade is so duty unencumbered now, comparatively.
The c64 was 2x or even 3x the price in Canada, mostly due to duty, compared to US pricing.
I recall buying a unit in the US, after convincing my parents to smuggle it across in their car...
My first thought back then with my C64 and BASIC: "I'll make it so when someone types LIST they won't be able to see the code, by writing more BASIC code that prevents it".
I do miss the 64 (and the Amiga which followed). The variety of machines back then was really refreshing compared to now.
We had access to "Nibble" magazine which had a lot of printed code. I got my "sound" routines from that. Between that and "Beagle Bros." programs. It was fun. We never figured out machine code...We got the basics, but it was just too much.
Though we just had each other as our lab wasn't internet enabled (as was the style in the early 80s)
If someone says "What, you didn't know that?" about something they only learned yesterday, they're being a jerk. Because this was all new to all of you, it became harder to feel like saying that.
Something that the author of the article could also touch upon is that, lack of resources was also a boon. I recall reading interviews of great programmers of the yesteryear saying how they would "read the same book twice over to understand deeply" and "sometimes I'd read the same concept from another book to make it really click", one of them being John Carmack!
A naive assumption I made after reading statements like those was this: When performing, sometimes you go fast to pressure yourself but under that pressure the odds of delivering quality work is greatly reduced. However, when comprehending something new, you cannot romanticize speed. You almost have to value comprehension and depth. Speed comes as a byproduct of the hours spend understanding.
Instead of that we favor speed of questionable learning quality, we tag ourselves "jacks of all trades" because you know enough Next.js to ship the product but not enough to tell what you could have done better or even why we chose to do A over B outside of "the stackoverflow answer told me to". That is, until the client complains. We really misuse the whole "premature optimization is the root of all evil" to "premature readability", "premature anything". Gotta go fast!
tl;dr aside from the programming environment, not having access to "quick and dirty" answers to any problem affected everyone's expectations of delivery and performance, and that also played a role in how we learned.
“The best thing for being sad," replied Merlin, beginning to puff and blow, "is to learn something. That's the only thing that never fails. ... There is only one thing for it then — to learn. Learn why the world wags and what wags it. That is the only thing which the mind can never exhaust, never alienate, never be tortured by, never fear or distrust, and never dream of regretting. Learning is the only thing for you. Look what a lot of things there are to learn.”
― T.H. White, The Once and Future King
https://www.goodreads.com/quotes/21627-the-best-thing-for-be...
it broke when it was 14.
parents were happy that I do not waste so much time anymore on the computer. so no computers for me any more. I think they never understood what I was actually doing. Coded some nice games and also a "use your joystick as a music instrument".
also party and girls became much more interesting at that point in my life.
with 19 I needed a job - as I became a father myself.
Applied for a dot come job. Started coding again. Found out that not much has changed. Code was still code and with enough trial and error, lots of reading and thinking about a problem you could figure everything out.
So thx C64, you thought me a lot.
As a parent I now wonder about the ways that I might do something similar to my kid.
Or perhaps more importantly, what is the c64 of my kid's generation that I can buy for her?
Raspberry Pi. The Pi 400 is especially close, with the same keyboard form factor and all.
It’s not as immediately programmable as the 8-bit micros were (hard to beat booting up right into a BASIC prompt for that), but Linux is still more tinkerable than most other devices you’ll encounter and the default Pi distro has a bunch of educational stuff preinstalled.
Using an old desktop that my dad had installed Linux onto had a huge impact on me in my formative years. I credit that for at least part of my career success.
Yes, it's "retrocomputing on easy mode": an ARM Linux computer running VICE and preloaded with a carousel of C64 games. But it can be set to boot into BASIC just like a real C64, and it gets you about 80% of the way to the experience of the real thing without needing to recap mainboards or track down a missing pulled SID on eBay. And it hooks straight into modern TVs and uses modern peripherals (game pads, etc.). It can be programmed in BASIC or any other language/environment for the C64 that's sideloaded onto it.
If she wants to mess with more modern paradigms of computing, get her a Raspberry Pi 400 or something also. Old laptops with Linux are good for this use case also -- a used ThinkPad will work wonderfully. With modern tools, she can even more easily write 6502 programs to sideload onto her THEC64!
This may not be what you mean, but there are a couple of modern devices that function pretty much the same way, just with faster CPUs and better graphics:
https://geoffg.net/maximite.html
https://www.olimex.com/Products/Duino/Duinomite/DUINOMITE-MI... (a cheaper knock-off of the above)
Similar, but doesn't boot to basic, and requires more skill to deal with. Cheap though...
https://www.tindie.com/products/lilygo/lilygo-ttgo-vga-v14-c...
It's basically a ready-to-run platform for the awesome fabgl library: http://www.fabglib.org/
POKE X CHR$(209) is not valid syntax, POKE takes a memory address (in decimal) a COMMA and the value (0-FF) in decimal.
Also.. CHR$ converts an ascii value to a character.. you don't want that here..
Also.. the character color has not been set under the ball, so it won't show up on most of the screen-area..
Screen memory starts at 1024, color memory at 55296 so to show your ball, you'll do
POKE 1024,209 POKE 55296,1
Also, you should use 81 and not 209, since the machine is in uppercase mode, and 209 is the inverted circle in that mode.
Why spend the time to write an article with examples that do not actually work?
> The emulator implemented here only supports POKE for accessing screen memory. To keep things simpler, it starts at offset 0 rather than at offset 1024 as in the real Commodore 64. When you access an invalid address, e.g. by waiting until the ball runs off the screen, the operation fails and the program execution will stop.
He doesn't need a full emulator to show the principle.
I was using the page in C64 reader mode (due to the colors making it impossible for me to see anything) and so I never realized that the image to the right was actually an emulator, I thought it was just a screenshot.
My fault ^_^
Still though, in my opinion it'd then be better to skin the thing as something other than a C64 so as not to avoid the confuzion for no reason.
The virtual machine is not in uppercase mode, typing stuff into it goes in as lowercase and doesn't get properly parsed. (This might be a Safari bug).
As far as I recall there was no DELETE keyword, which this thing uses instead of NEW.
Different revisions of the C64 ROM did different things with regards to clearing the color memory when clearing the screen, my early c64 would set it all to white, while later revisions would (I think) set it to whatever the current character color was.
I guess this is trying to simplify things somewhat to make its points about the power of booting up straight to a BASIC prompt, but it sure does annoy anyone who spent time hacking on a real c64!
Apparently you haven't bothered to read the manual.
I agree with the author, one thing great about these systems was having BASIC as a kind of systems programming language, with high level niceties, and a REPL.
Something that younger generations taught in the ways of C have no idea how it went.
I think the loss of a simple, integrated and interactive programming environment like BASIC has been a tragedy. Is there anything like BASIC today that any child, secretary, or grandmother can pick up and learn with as little hassle as possible?
https://www.microsoft.com/en-us/makecode
https://smallbasic-publicwebsite.azurewebsites.net/ (partially dead)
I loved my C64 and BASIC was my first programming language... but boy was it limited. It wasn't a good BASIC for the standards of its time. It was hard to program games with it, and in order to do any graphics you had to PEEK and POKE, which can hardly be considered "programming in BASIC" or user-friendly...
I tried to develop something like that: https://easylang.online/ide
When he explains
PRINT "HELLO WORLD"
he says "To a modern programmer, it is amazing how little it takes to get from booting the machine to printing hello world. "When I wrote my first compiler in the 80s I made sure you could run a program that simple. I am somewhat surprised that only Python and arguably Javascript give you that kind of immediacy. With all the advances in languages it constantly surprises me that there's no universally available language that lets you start out so quickly.
https://beagle.applearchives.com/the_posters/
Its funny how you remember some things. like how to fill the screen a single color. 10 hgr 20 hcolor=2 30 hplot 0,0, 40 call 62454
Being relatively young (25) and not living through the times of these classic computers, I knew the basic (heh) ideas behind programming for them, where the whole thing is essentially a REPL and you write line numbers to add to the program. But I never saw demos farther than printing a line and then doing a goto to print it infinitely. I didn't understand the actual workflow/iteration process programming for these machines, writing something more advanced where you're figuring things out as you go.
I have to say my conclusion is I'm glad that in modern times we have the ability to go back and insert as many lines as we want in between any other lines :)
But here's how everyone understood a computer would work, before they saw anything else:
GREETINGS PROFESSOR FALKEN.
Hello.
HOW ARE YOU FEELING TODAY?
However, this gives a lot of credit to Commodore for something that was completely standard at the time on all 8-bit computers (and then some). The real credit belongs to Dartmouth BASIC [1].
Especially when considering the original context (very very limited machines), the genius of the BASIC model (not so much the language) is something to appreciate.
Interestingly, John G. Kemeny, one of the two behind it, used to work for Richard Feynman and is one of the "martians" [2]
It had Locomotive Basic which was quite a bit more advanced than C-64 BASIC.
It had instructions like AFTER delay, timer GOSUB line or EVERY time, timer, GOSUB line for example.
Giving you a sense of multi-threading all the way back in 1984!
I spent quite a bit of time translating C-64 BASIC code into Locomotive.
Learning on an 8-bit computer, diving into Z80 assembly and understanding how the thing works on a very low level is a useful skill to have.
Haha, that's a really low bar! Commodore really cheaped out with C64 BASIC.
I wonder if that also was ultimately advantageous for C64, forcing kids to learn 6502/6510 machine language early to get anything interesting done.
Thus a lot of kids could create their own games and whatnot in assembler, with way higher performance than what was possible with BASIC at the time.
There are educational coding environments, but you will never understand the underlying computer model, just by playing with them.
And no setup whatsoever. Python was supposed to be that simple, but we’re past that, obviously.
I'm thinking about buying one for my best friend's son and teach him PyGame programming.
For myself I prefer something more bare metal, such as asm or C game programming. I think there is probably a NON-CARTRIDGE handheld somewhere to quench my thirst but need to find it.
I can't wait to start playing around. Seems like a great sandbox to finally get comfortable with assembly. I think I'll try diagnosing the issue this weekend if I can muster up the energy.
Measure the voltages on the connector. There's a pinout diagram further down on this page:
https://retrogamestart.com/answers/replace-c64-power-supply-...
I've seen a bad power supply kill one of the two CIAs, the color ram & damage the SID on a C64C
So it’s not all old timers who love these old machines, the new generation can enjoy them, too. Given that it’s a mystery why some company just build and sell a C64 / Amiga/ Sinclair clone for a reasonable price. Next batch of YC anyone?
But I was young and didn't see how important that was for my development. So I never took care of archiving or even backups, ultimatily I just got rid of the discs while moving or cleaning up. I don't even remember. No this old "Brotkasten" is catching dust in the drawer.
Nowadays I really miss my early work and take a lot more care when it comes to backups and archiving my work.
//EDIT No wait, my first computer was some kind of weird robotron my father brought home some day. This thing really fascinated me, I wasn't able to do much on it, because there was no documentation and of course I had no internet. But I really loved the green letters on the black screen.
Wrote a D&D character generator. Worked pretty good.
Messed with sound a bunch. Apocalyptic chords.
Hacked up freeware games.
Made lots of generative art
Poked random stuff till the machine crashed prettily
[0]https://www.youtube.com/watch?v=h3bDa5z_B1M [1]https://www.youtube.com/watch?v=iJDYoVgrtOs
If it weren't for "War Games" and the vic-20 (and later the c64), I would've ended up on a very different path.
If you put out a new computer in the mid-70's, you had to include two things: an assembler, and BASIC.
Floppy disk? Optional. 16K of RAM? Optional. If you didn't have BASIC, your new machine was doomed.
Small, mid- and even some larger-sized businesses ran in BASIC. If you didn't need a mainframe, your business was running on assembler or BASIC.
I can understand why Microsoft made so much money back then, porting BASIC to every platform from calculators to minis.
I loved the Simons Basic cartridge, that gave me a lot of the PEEK/POKE power wrapped up in new Basic keywords. Sprites were so cool!
Thank god for our tools and abstractions today.
``` A$ = "Hello World ```
So you say this as "A-string equals Hello World"
I still pronounce "$" as string however many years later
LOAD “$”,8,1
list
run
Commondore was good old times :)
For some reason I still remember 646, 53280, 53281 (pokes), 30120, and yes 64738.