Yearly Archives: 2015

How to create relative data files on your Commodore 128

Commodore-Logo-PaddedThe 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 in one go (Apple call this “reading and writing atomically”). So finding the 50th record in a sequential file can take some time, whereas retrieving record 50 from a relative file is just as fast as retrieving record 1 or record 157.

Let’s see how we can deal with such relative files in CBM BASIC 7.0. This works with all physical disk drives (1541, 1571, etc) as well as the SD2IEC card reader – but not with your trusty old Datasette (for obvious reasons).

This was revolutionary back in 1982!

Creating Relative Files

Here we create a new file with a REL extension using the DOPEN# keyword. When we do this for the first time, we need to tell the operating system how much data we’d like to allocate per record. Anything up to 255 bytes is fine. We’ll use 100 bytes in this example (the letter L followed by the length).

When we create a new file, CBM DOS doesn’t know how many records we’ll need, but it will create as many as necessary on the file. Here we create 100 entries using a for loop and write them to disk using the PRINT# statement.

Notice that before saving a record, we must position the record pointer using RECORD#. That’s how our data is written to the correct position on disk. The whole loop will take a while to complete, but all space will be allocated on the disk as soon as we CLOSE the file.

To add more records, we’ll simply position the record pointer to a later entry – even if one does not yet exist. CBM DOS will create the last record and all records leading up to it so they can be used later, up to a maximum of 65535 (space permitting obviously).

Reading data from Relative Files

Much like with sequential data, we can either use INPUT# or GET# to grab the data for an individual record. INPUT# reads everything until a CHR$(13) is found and works much faster, while GET# reads data one character at a time and is a lot slower.

Here we ask the user which record we want to retrieve. Next we open our relative file using DOPEN#, position to the desired RECORD# and then read in its value using INPUT#. When we’re done we close the file and ask if the user wants to retrieve another record.

While this type of data access is quick and convenient, it doesn’t help much unless you know which record is stored at which position. Think of an address book application: to find “Johnny Appleseed” can’t be done unless you sift through every single record until you find him.

Commodore therefore suggest to use sequential files alongside relative files, in which things like a last name could be saved together with the record number. Likewise, another sequential file could hold all records for the first names, and appended accordingly when a new record is created, or replaced when updated.

How to create sequential files on your Commodore C128

Commodore-Logo-PaddedSequential files are files to which we can write arbitrary data and read it back later. We can even append data to the file later without having to re-write the whole file.

This works with the Datasette (tape drive) as well as floppy drives. Here’s how to do it in CBM BASIC 7.0:

Creating Sequential Files

The C128 has a few special commands up its sleeve to aid us in this task. Here we create a new file using the DOPEN keyword and write 100 statements to it.

We’re creating a new sequential file (SEQ extension rather than the usual PRG), using the w after the filename so that BASIC knows to create the file. The @ sign in front of the file name makes sure this file is overwritten every time we run the programme – omit it if you don’t want that functionality.

Next we create a loop and generate a variable spelling RECORD 1, RECORD 2, etc. That’s your data. Each entry may be up to 127 characters in length (I believe) and is saved to the file by using the PRINT# keyword. Anything we could print to the screen, we can also print to a file.

With each new PRINT# command, a carriage return is saved to disk. This can come in handy when we’re reading the data back in. If you need special characters to separate your data, feel free to use them.

Appending data to Sequential Files

If we need to add anything to the file (much like Linux would add to the end of a text file using the “greater than” symbol), we can use the APPEND# keyword:

APPEND# opens the file for adding data and positions the pointer after the last entry in our file. We’ll do something very similar as above, creating records 101 to 150 and adding them to the file. Make sure to CLOSE the file so all data is saved to disk.

Reading Sequential Data

Much like PRINT# can be used to write data to disk, we can use INPUT# to read data back – almost equivalent to the INPUT keyword get get user input from a keyboard. The only difference is that out input comes from a different device:

Here we open our file with DOPEN# and grab each entry in the file using the INPUT# keyword. This will automatically position the next INPUT# when a carriage return is received (CHR$(13)).

This will work just fine as long as the original data does not contain any special characters, like a scary comma. If you need such characters, or if you want to ignore the carriage return, you can also use the GET# command to read one character at a time from disk. This is dramatically slower though.

Notice that there’s no “end of file” marker as such: right now we need to know how many entries there are and read them accordingly. Reading beyond the data in our file will simply repeat the last record (on real devices) or crash your system (on VICE).

How to switch the Commodore 1571 into 1541 mode and back

Commodore-Logo-PaddedThe Commodore 1571 floppy drive powers up in compatibility mode and behaves just like a 1541 drive – unless a C128 is connected and sends it a fast serial transfer.

They did this because otherwise the drive wouldn’t be compatible with the C64 and Plus/4.

The C128 speaks to its attached disk drive when we power it on, and that’s how a 1571 turns on its super fast magical properties. Holding down the Commodore key will boot into C64 mode, and the 1571 will in turn reset itself to 1541 emulation mode.

Lucky for us, we can change this with a simple command, no matter what computer we’re using or which mode we’re currently in. This is done by first opening a command channel and then sending the 1571 the following switch command:

This will let the 1571 behave like a 1571 even when attached to a C64 or Plus/4: format floppies on both sides and enjoy 1328 blocks without flipping disks. Sadly it won’t transfer data any faster because the attached computers just can’t handle it.

Conversely, if we want to use a C128 and have our drive remain in 1541 mode for testing or compatibility, it works equally well.

Rebooting your computer will reset this value. As far as I know, there is no way to test which mode the drive is in before issuing either of the above commands.

How to check the Fan Speed on your Mac

Sometimes you may want to know how fast your fans are spinning, more as a “number value” rather than a “noise value”. While you can hear when your Mac in front of you is working hard, it’s impossible to tell how fast those fans are spinning when you’re miles away from your Mac in a data centre.

Thankfully there is an easy way to read out the fan speed with a small built-in utility we can access from the command line. Launch a terminal session and issue spindump as admin user:

It’ll take a few seconds, at the end of which a file is produced that tells you a lot more than just the fan speed. To filter this info out, issue the following:

And there you have it! Execute this command under low load, then try again under heavy load to see your low and high spin numbers to get an impression how how busy your Mac’s fans are.

To remove that temporary file and avoid your hard disk from being clogged up, issue this when you’re done:

This may not be the most elegant way to read out your fan speeds, but it works without installing additional utilities. The spindump command is computationally expensive, so don’t do it continuously – there are better tools for that (such as smcFanControl, or others – see the link below).


How to disable System Integrity Protection on OS X El Capitan

System Integrity Protection was introduced in El Capitan to add another layer of security to OS X. The system prevents the root user from doing things that are potentially harmful. Apple did this because any app at any time may ask for the administrator password and execute commands with elevated permissions, which is a big security risk on single user systems.

There are downsides to yet another layer of security, and much like Gate Keeper, System Integrity Protection brings us one step closer to a completely locked off system like iOS. I guess that’s the long term plan.

Until then, and if you need it, you can disable System Integrity Protection. Here’s how to do it:

  • boot into the Recovery Partition (hold down CMD + R during boot)
  • this takes a little longer than usual
  • when the system is back, select Utilities – Terminal
  • now type “csrutil disable”
  • close Terminal and restart the system

You can check at any time if this feature is on or off by typing

Enable it again during a Recovery session by typing “csrutil enable” and El Capitan is secured again.

To see what else this command has to offer, type csrutil without parameters:


How to turn plain URLs into clickable links in WordPress

The marvellous P2 Theme has an interesting feature: write out a plain link, and it magically becomes clickable without explicitly adding the a href tag.

This may not be a big deal if you’re writing posts in the visual WordPress editor rather than HTML, but for those of us who like to write in HTML, it’s just one less thing to worry about.

I was investigating this feature recently, and it turns out WordPress has a built-in function that can do this: they call it make_clickable(), and it works with URIs, FTP, Email addresses and anything starting with www. The function is really easy to use too: it only takes one parameter (a string), and returns the clickable HTML code.

Let’s see how to use it in context, using the TwentyThirteen theme.

Continue reading How to turn plain URLs into clickable links in WordPress

How to display Jetpack stats per post in WordPress

Some websites employ this or similar technologies to show how many views a single post has had. I was wondering how they did that without starting to count stats that have already been counted for several years, either by Google or by Jetpack.

Yesterday I came across this post by a WordPress dev named Topher about how to render Jetpack Stats:

I decided to test this in TwentyThirteen, and it works a treat – here’s how to do it. The principle will of course work with any theme.

Continue reading How to display Jetpack stats per post in WordPress

Zen Dash – Version 1.5 released


I’ve just released an update to my Zen Dash plugin. Besides adding funky zen-bamboo artwork to the page, I’ve made the following minor amendments:

  • the option to hide the Jetpack menu now only shows up when Jetpack is activated, otherwise it’s hidden
  • I’ve verified compatibility with the immanent release of WordPress 4.4
  • added funky zen-artwork (see above, courtesy of GraphicStock)

I’ve you’re one of the 70+ active lucky users, you can upgrade the plugin from within WordPress as usual, or you can download a copy from GitHub or the plugin repository:


Questions, suggestions, translations and pull requests are always welcome!

What is Zen Dash again?

Zen Dash is a magical plugin that lets you get rid of the myriad of options in the WordPress admin area. I’ve created it because sometimes less is indeed more, and new users can get overwhelmed by the sheer volume of menu items, dashboard widgets and upgrade notifications.

While it is possible to let casual users have privileges less than administrators (and therefore see less items), I found this ineffective. With Zen Dash you simply flick a switch and make things disappear that you don’t want to see everyday. You can just as easily bring them back if you need them.

You can read more about Zen Dash in my release post, which even includes a video on how to use the plugin.

How to see which users are logged in on OS X and Linux

There are two funky commands that can help us see who’s currently logged in, and what operations were performed last. Those two commands are who and last.

Let me show you how to use them.

The who command

Type who at the command prompt and you’ll see a list of currently logged-in users:

This system has two users logged in: versluis, via TTY, and root via PTS. We also get to see which IP addresses these users are logged in from (:0 is localhost).

On this note, TTY is the local text based terminal at the machine, while PTS is a pseudo-terminal. This is most likely an SSH session or similar, anything that’s happening remotely.

who can also show us who we are, in case you’re ever logged in on a system and don’t know which user you are:

You can also concatenate who am i into whoami.

The last command

The last command can take a moment to execute and will show a list similar to this:

You can see who has logged in to the system recently, from which IP address, and when each session started and finished. You can also see when the system was last restarted (and in Linux, which Kernel was used to do so).

The last line (on Linux, beginning with wtmp) shows since when the command was able to display results. last and who both read a file called wtmp (in /var/log/wtmp), which logs all login attempts over time.

last accepts several filtering options too. For example, to query when a particular user has logged on and off, type last followed by the username:

Or if you’re only interested in restarts:

On OS X the output is somewhat more limited due to the absence of kernels, but it works just the same. For more information on each command, checkout the man pages with man last and man who.


How to burn an ISO image with OS X El Capitan


Sometimes it’s important that things change for no apparent reason. You know, the way they move things around in supermarkets just to drive you crazy.

If you’ve tried burning an ISO image to disk in El Capitan recently, you know what I’m talking about:

because the option to burn an ISO has been removed from Disk Utility.

Yeah, I get it: plastic disks are out, no one should be using them anymore, there are no more Macs with SuperDrives in production as of 2016, so it’s time to remove this option from the built-in utility that had it for the last ten years. Think different. It keeps you sharp.

Lucky for us plastic spinners, there are two (not so obvious) solutions: the command line and the good old Finder that can still burn disks for us. Here’s how to do it.

Using Finder

Apparently Finder always had the option to burn a disk image. I never knew that! All we have to do is:

  • insert a new blank disk
  • navigate to our ISO image
  • select it (single-click)
  • head over to File – Burn Disk Image “xxx” to Disk

Screen Shot 2015-11-16 at 18.00.40

Using the Command Line

It’s for hackers really, but it’s very simple:

  • insert a blank disk
  • open Utilities – Terminal
  • navigate to the folder that holds your ISO image
  • issue the following command:

El Capitan. There’s just more to love with every click.