DEV Community

Alexey Medvecky
Alexey Medvecky

Posted on

Time-Travelling to Commodore 64: Hello World Program on C.


This time I will review the possibilities of programming on the Commodore 64 and try to understand how a modern programmer would feel in the realities of the mid-80s.

In those years, I did not have a Commodore 64 but had a ZX Spectrum clone.

There was no Internet, and there were few programming books.
So the maximum I then did on the Spectrum was writing simple scripts in BASIC to solve problems in mathematics and physics and games like Landing on the Moon.

Therefore, I have always been interested in the stories of my acquaintances who did more exciting things on 8-bit computers. I wanted to do it myself using the knowledge now available.

I'm starting an experiment. I'm in my mid-80s; I have a Commdore64 with a disk drive, some set of programs and books, there is no Internet, but the grass is greener, the sun is brighter, and the girls are more beautiful, and there is also a lot of time for experiments.

From the beginning, I needed to understand what the Commodore 64 offered for programming and try to write a "hello world" program.

The first thing that catches my eye is a different layout of special characters on the keyboard and a tiny resolution by modern standards.

If I get used to the layout, it's a matter of time, but how the developers in these conditions viewed and debugged extended programs; so far, the question is.

After turning on the C64, BASIC is launched. This is a programming environment and a shell with essential OS functions.
I can save and delete files to disk and make some adjustments by changing the values of variables in memory using the poke statement.

// There is a command examples
SAVE "MY_PRG",8
LOAD "MY_PRG",8,1
LIST
RUN
POKE 53280,1
Enter fullscreen mode Exit fullscreen mode

Since BASIC starts immediately, let's try to do something about it, for example, "Hello world".
In BASIC, everything is simple. Compared to Spectrum, the C64 has a more advanced ability to edit text within the screen.
The first program looks like this.

I can save a program to disk and then load it back.
I figured out the BASIC, but there are too few tools here.

What else can I try? Assembly is still tricky because I need to learn a set of commands.
The C should be better here because I know it.
I have a set of two floppy disks for C with the "power c" compiler.

After a short study of the manual, I started the shell.

Compared to BASIC, it's much more comfortable; at least there are several Unix-like commands like 'ls' and 'rm'.

I launch the editor and enter the program's text. The non-standard layout still interferes, but it's not so scary anymore. Curly braces are placed on the "+" and "-" keys. I know it from the manual.

// command to launch editor with spell checking

ced
Enter fullscreen mode Exit fullscreen mode

I have entered the program. The separate command performs a syntax check
Command mode is invoked by key (Hi VIM)

// to enter command mode press [run/stop] button
// command to start spelcheking 

check

//command to exit to shell

quit
Enter fullscreen mode Exit fullscreen mode

From the same mode, we save the program's text to disk just to the same disk where power c is located. It's worth saving to a separate floppy disk for more complex projects.

I exit the editor and start the compiler. Here is a suggestion to use separate source and object file disks.

I run the linker to create a simple shell executable.

Then I enter a special character — arrow to top. At this stage, I need to change the disk to the second one because that is where the necessary libraries are located. After the prompt, change the disk back. Save the executable file. Everything is ready. Now I can run my program as a shell script.

Yes, the programmer is almost a DJ here, but if the project is large and the source and object files are stored on separate disks…..

This most straightforward program's compilation, linking and loading time could be more encouraging. I had time to read the manual during the process, but what will happen on a more advanced project?

I add the key -s to the link command, repeat the linking process, and get an independent executable file.

This executable I can now load and run from BASIC.

The inscription became an upper case for some reason, but this looks like some feature. I will deal with this later.

The "Hello World" program is not just a string output. It means
the developer knows how to use the editor, compiler and linker. These days when it's all done automatically or in one command, it doesn't seem very relevant, but on C64, "hello world" is still an important step to start programming.

The first step is done, now I still need to make hello world in Assembly, and then it will be possible to say that I have all the tools in my hands.

I don't want to return from the 80s, so I'll rest here and take a walk.

Thank you for being a part of this journey.
I hope it was at least fun.
Warm regards.
Stay tuned for my next posts.

Top comments (0)