Developing for Commander X16 in Prog8 – Part 1

Prog8 is a compiled programming language targeting the 8-bit 6502 CPU family. The language looks like a mix of Python and C.

I have been looking for a new platform to develop games for and Old Skool Coder has begun developing games for the Commander X16 (CX16) retro-style modern computer. It’s kind of a souped-up Commodore 64. In fact, it contains the C=64 KERNAL which you can use, but you will need to recode things as you cannot just load in C=64 games and expect them to work.

The specifications are:

8-bit 65C02S CPU at 8 MHz (*)
512 KB banked RAM (upgradeable to 2 MB on the X16 Developer Edition)
512 KB ROM
Expansion Cards (Gen 1) & Cartridges (Gen 1 and Gen 2)
Up to 3.5MB of RAM/ROM
5 32-byte Memory-Mapped IO slots
VERA video controller
Up to 640×480 resolution
256 colors from a palette of 4096
128 sprites
VGA, NTSC and RGB output
Powered by a Lattice ICE40UP5K FPGA
Three sound sources
Yamaha YM2151: 8 channels, 4-operator FM synthesis
VERA PSG: 16 channels, 4 waveforms
VERA PCM: Up to 48 kHz, 16 bit, stereo
Connectivity:
PS/2 keyboard and mouse
4 NES/SNES controllers
SD card
Commodore Serial Bus (“IEC”)
Many Free GPIOs (“user port”)

I have already developed games in C and Assembly (among a long line of other languages) and figured it’s time to try something new. Prog8 looks simple enough but creates tight, fast Assembly code when compiled and it’s like a breath of fresh air to learn something new like this — which is just what I need at this time.

I want to create a sort of Tutorial for programming the Commander X16 using Prog8. There’s lots of info around and some source code, but nothing seems to be available for newbies at this time. So, if you like, you can learn along with me. I hope to update this as time goes on and I learn new things. Programming the CX16 is something entirely different to any other platform I’ve seen.

To whit: Let’s start with some simple stuff. I wanted a fast-to-launch and easy-to-use way of coding. I had set up VSCode with the plan of coding in Assembly but now I that want something simpler and easier I decided to go with the Sublime Text editor, which I’ve already purchased and used in the past.

I added Syntax Highlighting from akubiczek’s Github. Now I can see when I’m (probably) doing the right thing 😀 I also set up Sublime Text so I can Build and Launch the CX16 Emulator using SHIFT-CTRL-B. I won’t go into setting these up as there’s info online for this.

Note that the compiler for Prog8 is written in Java. This is so it can be used cross-platform on Windows, Mac OSX and Linux without issues. You will need to install Java which you can get from Adoptium. I’m using the v11 JRE. You will also need the 64tass assembler installed. Extract 64tass somewhere on your hard drive. (OSX instructions: https://ports.macports.org/port/64tass/). If you have any issues compiling, please make sure you add the 64tass and Java bin folders to the PATH System Environment variable for your OS platform.

Download and extract the Prog8 compiler on your computer.

The Sublime Text build file I use contains the following code. You will need to change paths to suit your install locations:

{
	"shell_cmd": "java -jar D:\\X16\\Prog8\\prog8c.jar -target cx16 $file",
	"working_dir": "${project_path}",
	"variants": [
        {   
            "cmd": ["start", "cmd", "/k", "D:\\X16\\x16emu\\x16emu.exe -prg $file_base_name.prg -run -scale 2 -debug"],
            "working_dir": "${project_path}",
            "shell": true,
            "shell_cmd": null,
            "name": "Run"
        }
    ]
}

Please use double slashes in Windows. I have mine saved as prog8-sublime.build and stored in %AppData%\Roaming\Sublime Text 3\Packages\

You can easily find your packages folder by clicking on Preferences > Browse Packages. (Settings… -> Browse Packages in OSX).

For OSX and Linux, change the ‘cmd’ line to something similar to this:

    "cmd": ["~/Dev/x16emu/x16emu -prg $file_base_name.prg -run -scale 2 -debug && exit"],

-prg sets the name of the file to launch. -run executes it. -scale 2 makes the emulator bigger. -debug enables you to use debugging MONitor tools built into the emulator. You can also add -wuninit to the emulator to output errors to the console and -asmlist to the prog8 command-line above to get an Assembly .list file.  -zeroram for the emulator will set all memory to a 00 value.

You may wish to develop a game using VSCode. I’ve since pivoted to using this as I also have added my Github configuration which makes it simpler to sync my code. I also added in the CodeMap VSCode extension. This allows you to configure a tree-view showing your subroutines:

You can use this to quickly click on a subroutine and jump there instead of scrolling up and down your code. The configuration for CodeMap goes into your settings.json file. I won’t get into it here setting up Github for VSCode or installing extensions, but I will paste below my configuration for CodeMap so you can use it:

    "codemap.p8": [

        {
            "pattern": "sub (.*?)\\)(.*?){",
            "icon": "function"
        },
        {
            "pattern": "^(?!sub)(\\w*?)\\s+{",
            "icon": "class"
        }
    ],
    "codemap.ini": [
        {
            "pattern": "\\[.*\\]",
            "clear": "\\[|\\]",
            "prefix": "",
            "role": "class",
            "icon": "class"
        }
    ]

I’ll also add below my Build and Run tasks for compiling your Prog8 code and auto-launching the Commander X16 emulator which runs your code:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "CX16 Prog8 Build",
            "type": "shell",
            "command": "java -jar D:\\X16\\Prog8\\prog8c.jar -target cx16 ${file}",
            "problemMatcher": [],
        },
        {
            "label": "CX16 Prog8 Run",
            "type": "shell",
            "command": "D:\\X16\\x16emu\\x16emu.exe -prg ${fileBasenameNoExtension}.prg -run -joy1 -scale 3 -debug",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "dependsOrder": "sequence",
            "dependsOn": ["CX16 Prog8 Build"]
            "problemMatcher": []
        }
    ]
}

Of course, you will need to change paths to your specific setup. The ‘dependsOrder’ and ‘dependsOn’ settings are so it will first execute the ‘Build’ task and then auto-execute the ‘Run’ task.

In the next post we will look at some simple code to get you started.

Comments

Leave a Reply