C128 Archives

Everything about the Commodore 128, or the C128, or the CBM128. It featured BASIC 7.0. I never had one, but my friend Frank did – complete with Modem and 80 column monitor. Buy did we have fun dialling up those BBSes after school.

Working with Keyboard Input in Commodore BASIC

In this episode I’ll show you three ways to take user input from the keyboard in Commodore BASIC. The INPUT and GET commands work on all systems, while the GETKEY command only works on the Plus/4 and C128. I’ll demonstrate how to use all of them. This will come in handy for our little lottery … Read more

How to print numbers as columns in Commodore BASIC

In this episode I’m demonstrating how to print numbers in evenly spaced columns in Commodore BASIC.

On the C128 and the Plus/4 we can use a nifty little function called PRINT USING for this, with which we can format the output of any printed text or variable.

On the C64 and VIC-20 that function doesn’t exist, so we’ll have to convert a numeric value into a string (using the STR$ function), and then determine how long our string is. Following that we’ll have to manually pad our string value with as many spaces as are required.

Read more

Sorting an Array on the Commodore 64

In this episode I’ll demonstrate how to sort a numeric array on the Commodore 64. The same principle works for string arrays, and of course on all other Commodore BASIC computers. The technique I’m using here is called Bubble Sort: in effect we’re comparing the first two items in the array, and if the left … Read more

How to generate Lottery Numbers on the Commodore 64

In this episode I’ll demonstrate how to draw random lottery numbers on a Commodore 64. The secret sauce here is not only the RND function to generate random numbers, but also two loops inside each other that prevent the same number from coming up more than once. Here’s the lottery generator code: 10 x=rnd(-ti) 20 … Read more

String Operations on Commodore Computers

Commodore BASIC has some interesting and simple string functions built in. Three of them are self explanatory: LEN, LEFT$ and RIGHT$. But others, like the mysterious MID$ and INSTR functions, are a little tricker, and I can never remember how they works. So here’s a quick recap on how they all work. LEN (A$) Returns … Read more

How to use direct block access commands in Commodore DOS

Commodore-Logo-PaddedWe can access each sector’s raw data on Commodore disk drives with direct block access commands. Supported drives include the 1541, 1571, the VICE emulator as well as the SD2IEC card reader (for the most part).

Each single sided floppy contains 35 sectors, while a double sided 1571 formatted disk contains 70 sectors. Each track contains between 17 and 21 sectors depending on how far inside or outside they are. Each sector contains 255 bytes we can read or write.

Sectors are the same as blocks: only the directory refers to them as “blocks” and shows us how many we have available.

We’ll need to open two channels to our disk drives: a command channel and a data channel. Here’s how to do it:

Read more

How to create relative data files on your Commodore 128

The CBM DOS can write “relative data” onto disk, based on individual records. The advantage is that all space is allocated once and then randomly accessed if and when it’s needed – much like the tracks on a CD. This approach is different from sequential files, which have to read or write the whole file … Read more