PETdisk – Technical

Update: 5/10/2015
Version 3.0 beta firmware is now available. This allows for reading and writing to SEQ files located on the SD card.

As of 10/3/2011, I have updated the firmware in the PETdisk to version 1.1, and the microcontroller in the PETdisk has been switched to an ATMega168. Now using a bootloader, you can update the firmware on the chip directly from the SD card.
Here’s how to do it:

- Format your microSD card with the FAT32 filesystem.
- Copy a firmware file onto the SD card. This must be the first file copied onto the card after formatting in order for the bootloader to find it.
- With the PETdisk disconnected from power, insert the microSD card with the firmware into the PETdisk’s microSD slot.
- Power up the PETdisk. Within about 5 seconds of powering up, the bootloader will locate the firmware file and reprogram the memory of the ATMega168 chip.
- When the application is loaded onto the card, the bootloader jumps to the application and runs it. Upon launching, the application code will check for the existence of a firmware file and delete it if it exists. This is to prevent the program memory from being rewritten repeatedly upon powerup, which would shorten the life of the microcontroller chip.

That’s it! You can also create custom firmware builds and flash them onto the chip using this same procedure. Here are the specifications of the firmware file:
- The firmware file is a raw binary file with the exact contents of the program memory for the ATMega168. It is not an intel hex file (which AVR studio generates), but can be converted from one.
- The file must be exactly 14336 bytes in length. This is the exact size of the remaining memory remaining in the chip after the bootloader is programmed. (2048 bytes).
- The card containing the file must be formatted with FAT32 and the firmware file must be the first file copied onto the card.
- The name of the firmware file must be of the form:
FIRM****.BIN
where the * can be any character. FIRMWARE.BIN and FIRM011A.BIN are both valid.

Source code for the bootloader and for the v1.1 PETdisk application will be posted here soon.

For those enterprising souls who want to build their own version of the PETdisk from scratch, or who want to examine/modify the PETdisk firmware, I’m providing the full schematics of the board and the source code for the firmware.

Source code is licensed under the GNU GPL license.

Schematic:

Firmware:
Version 1.0 (pre-bootloader, needs AVR programmer)

Version 1.1 (wildcard support, DLOAD)

Version 1.21 (save long filenames) 1.21 Source

Firmware Version 2.0, with support for subdirectories:

Version 2.00 (subdirectory support)

The 2.0 firmware supports subdirectories on the SD card. To support this, I’ve added a few new Commodore DOS-ish commands:
Change directory:
LOAD”$:directoryname”,<devicenumber>

Change to parent directory:
LOAD:”$:..”,<devicenumber>

Change to root directory:
LOAD:”$:/”,<devicenumber> or LOAD”$:\”,<devicenumber>

Firmware Version 3.0 beta – supports reading and writing to SEQ files:
Version 3.0 beta (SEQ file support)

Bug Reports:
- When loading programs with long filenames (greater than 8 characters), the load will fail if the extension is not .prg on the SD card. This is case sensitive, so only .prg (lowercase) will work, .PRG will fail. This is not intended behavior, and will be fixed in the next firmware revision. For now the workaround is to rename long filenames to have a lowercase prg extension. (This is fixed in the v1.1 firmware)

7 Responses to PETdisk – Technical

  1. Sir Morris says:

    Great stuff – I had the pleasure of driving the Retro Computer Museum’s PETDisk this weekend – it went down a storm.

    I’ve just finished soldering up the single-sided version tonight – I’m going to get out the AVR programmer right now and tomorrow night the PET comes out :D

    Charlie

  2. Jac Goudsmit says:

    Are there any plans to support Basic 4.0?

    My 4032 works great with the PETdisk but only if I use commands like SAVE”NAME”,8 and LOAD”$”,8.

    I would like to use DLOAD/DSAVE and DIRECTORY so I can check whether a file is available without wiping the program memory with LOAD”$”,8.

    Thanks!

    ===Jac

    • Paul Krzyz says:

      Jac:

      Is your 4032 is running Basic 4.0? (I’m assuming so because you tried to use the 4.0 commands)
      What drive are you runninig?

      I thought that the Commodore 4.0 ROMs did the translation for the
      4.0 DISK comands. My understanding is that the ROMs essentially
      translate the DOS 4.0 disk commands into the older DOS 2.0 (SAVE”name”,8 and Load”name”,8 and Load”$”,8) commands before the PET sends the commands out to the drive.

      I just had a quick peek at the Commodore’s 4.0 ROMs (dissambly) and sure enough, the DLOAD gets converted to a standard LOAD command before it sends the request off to the drive. This should suggest that the DLOAD & DSAVE should work on the PETDisk.

      With the 4.0 Directory command, it of course does not overwrite the Basic memory space. It performs a standard (LOAD”$0″,8 or LOAD”$1″,8 ) but sends the output directly to the screen rather than saving it in RAM. It massages the output before printing it, (it removes the BASIC line links) before printing it.

      I don’t own a PetDisk yet, but have finally ordered one, and am waiting for it to arrive where I can play with it.

      Has anyone tried the DOS wedge (for those pre 4.0 users) to see if it works with the PetDisk.

      • Jac Goudsmit says:

        I updated the firmware to 1.21 (I wasn’t aware that my kit didn’t have the latest version pre-installed).

        With this firmware, it looks like the problem of not overwriting existing programs has been solved. But the directory or catalog commands don’t work: I get “?device not present error”.

        My machine has a 4016-N label on the back but I’m pretty sure someone did a motherboard swap before I got it: it has 32K factory-installed. This is a motherboard that doesn’t have a CRTC. I also tried it with the PETvet (configured for basic 4.0, no CRTC) and the result is the same: DLOAD and DSAVE work (as well as other commands such as scratch and header) but directory and catalog give device not present error.

        ===Jac

  3. Philip says:

    Hi,
    I have tried to update my PetDisk firmware, but how do I know it it successful? How can I check the firmware version number? I did all the things listed in your writeup, but the .bin file was not automatically deleted. Thanks. Philip

  4. Philip says:

    Replying to myself here. The answer to the problem was, don’t use a Mac to do this.

    • bitfixer says:

      Hi Philip, yes I have had issues trying to format an sd card with FAT32 on a mac. There is a terminal command on mac which does create what seems to be a working FAT32 partition, but the PETdisk doesn’t like it. I haven’t dug into exactly what’s wrong with it. I’m pretty sure there is a way to write a clone of a working FAT32 partition with dd or a similar command, when I get a chance I’ll try this on mac and let you know. But so far, I’ve used an old XP box to format all my SD cards to FAT32.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>