Jay's Commodore Podcast

Jay Versluis
Jay's Commodore Podcast

Join Jay Versluis for tips and tricks on programming in BASIC and Assembly on vintage Commodore systems.

  1. 16/04/2018

    How to run Commodore BASIC as a Scripting Language on macOS

    Did you know you can run Commodore BASIC v2 on your Mac and Linux systems as a scripting language? It’s true – thanks to the marvellous efforts of Michael Steil and James Abbatiello. They’ve adapted the original BASIC v2 as featured on the VIC-20 and C64 with additional routines so that it works natively on modern machines. It’s ingenious! You can get the full source code on GitHub – it works a treat! For those who don’t quite know what to do with it, here are some instructions that’ll help you get CBM BASIC up and running on macOS. Download GitHub provides a convenient way to either clone a repository on your local machine if you have GitHub for Desktop installed, or you can download a ZIP file and unZIP it somewhere on your system. Once done, you should see a directory structure that looks exactly like the repo on GitHub. Compile You need a few utilities installed your your Mac to be able to compile files. Downloading Xcode will ptovide you with an excellent (and free) IDE as well as the command line tools needed to do that (gcc, make and several other goodies). You might be able to bring those components in using the Homebrew package manager. Using your Terminal app, navigate to your unZIPped folder. It includes a MAKEFILE so there’s no need to mess with any parameters. Enter “make” at the command prompt, and after a few moments you should have a file called “cbmbasic” without an extension in the same directory. That’s the binary for your Mac. To make it executable, we’ll have to tweak the file permissions – otherwise our operating system won’t be able to run it. We’ll do it using the chmod command: chmod +x ./cbmbasic You can test if it works by calling the binary without any parameters like this: ./cbmbasic If all goes well you should see something like this: For easy access, copy the binary over to your /usr/bin directory. That’s where common command line utilities are installed on Mac and Linux systems. The added benefit is that the path to that folder is already in your local $PATH variable, and as such you can simply type “cbmbasic” from any location when you’re on the command line. Here’s how to copy the binary over (this will ask for your administrator password): sudo cp ./cbmbasic /usr/bin Using Direct Mode When you run the binary it will bring up something like the standard BASIC command prompt we’re used to seeing on the Commodore 64. There are however a few important differences between a C64 emulator and this implementation: * this is NOT an emulator * cursor keys DO NOT work * all commands typed in must be CAPITALISED Other than that, you can start typing like on a real machine. Be careful with certain POKE commands though as those may call system routines that might not be implemented. LOAD and SAVE commands have been tweaked to reference the command line structure. They work just fine, but will load and save files in Commodore file format (which is not clear text ASCII – more on that later). For example: LOAD"$" LIST 0 "/Users/versluis/Desktop/cbmbasic" 00 2A 4    "."                PRG   2    ".."               PRG   2    ".git"             PRG   567  "cbmbasic"         PRG   7350 "cbmbasic.c"       PRG   593  "cbmbasic.o"       PRG   19   "cbmbasic.vcproj"  PRG   20   "console.c"        PRG   3    "console.h"        PRG   8    "console.o"        PRG   4    "glue.h"           PRG

    19 min
  2. 13/04/2018

    Writing HELLO WORLD in Machine Language on the Commodore 128

    The Commodore 128 has a built-in machine language monitor which makes it ideal for ML development. However, most (or pretty much all) documentation on this subject is geared towards the Commodore 64, making it slightly difficult to get a head start in writing ML code for the 128. Before I forget how to do it, here are a few pointers – courtesy of Jim Butterfield’s book “Machine Language – Expanded Edition”. Getting Started Let’s begin by typing MONITOR in C128 mode. It’ll take us to the machine language monitor. We’ll start our programme at $0B00. To begin assembling our code, we’ll type A 0B00 (A for Assemble), followed by these lines: LDX #$00 LDA $0C10,X JSR $FFD2 INX CPX #$2B BNE $0B02 RTS The MONITOR will turn this text into the output you’ll see in the screenshot above (the lines starting with a . dot). Here’s what this code will do when called: First we’ll load the X register with a value of zero. We’ll use this register as a counter. In the next line we’ll load the accumulator with whatever is stored in address $0C10 plus whatever is stored in the X register. So if X has a value of zero, then the contents of $0C10 will be loaded. If X was 1, then the value in $0C11 would be loaded, and so forth. We’re using this as ASCII representation of our text (Hello World in a box in this case). With JSR $FFD2 we’ll call a Kernal routine that prints a single character onto the screen. Now we’re incrementing X by one and ask if it’s 45 yet (CPX #$2D). This would indicate that we’ve printed all the characters we need. If that’s not the case, we’ll return to line 2 and keep printing. Otherwise, we’ll stop the programme. Storing ASCII characters You’d think it was possible to simply type in text in the MONITOR. But of course that would be too easy. Instead we need to grab one of those massive tables and hack in each character’s ASCII code in hex. How convenient! Type M 0C10 (or whichever location in memory you’d like to store your text string at) and overtype the numbers at the start of the line, each one representing a single byte of our ASCII text. At the end of each line you’ll see what those characters look like when converted. In my case it’s a total of 45 characters, beginning with a return, followed by the top of the box, HELLO WORLD, and the bottom of the box. Running from the MONITOR To start the programme from the monitor, we’ll type G F0B00. We’ll end up with a SYNTAX ERROR and back on the BASIC screen though due to the RTS command at the end of the listing. If we replace it with a BRK command instead, we’ll end up back in the MONITOR. The important thing to remember is the five digit addressing mode on the C128 (i.e. G for GO, followed by F0B00). Our programme starts at $0B00 in memory, but to make it run properly we’ll have to specify which BANK it should be called from. Anything other than BANK 0 or BANK 1 is fine, otherwise we won’t reach the print routine at $FFD2. In my example I’m choosing F, but E would work fine too (as we’ll see in a moment). Running from BASIC Type X to exit the monitor and go back into the land of BASIC. First we’ll need to choose a BANK. We’ll have 16 to choose from (0 to 15), so perhaps let’s try BANK 15. Now we’ll need to type the start of our programme in decimal: BANK 15 SYS 2816 or we can use the DEC command to convert hex to decimal on the fly: BANK 15 SYS DEC("0B00") Saving the programme From the MONITOR, we can save the programme using the S command. It needs to be followed by a name (in double quotes), followed by the drive number,

    22 min

Acerca de

Join Jay Versluis for tips and tricks on programming in BASIC and Assembly on vintage Commodore systems.

Para escuchar episodios explícitos, inicia sesión.

Mantente al día con este programa

Inicia sesión o regístrate para seguir programas, guardar episodios y enterarte de las últimas novedades.

Elige un país o región

Africa, Oriente Medio e India

Asia-Pacífico

Europa

Latinoamérica y el Caribe

Estados Unidos y Canadá