Tuesday, April 30, 2024
Raster Interrupts for C64
Monday, April 29, 2024
MLX II Listing for C64 Character Sets Editor
| Shown with 80s theme colors (key: 6) |
Back in the day we would enter program listings from magazines. That's how we got new utility and game software on a monthly basis. It was a fun activity in front of my Commodore Vic-20 on Saturdays.
For nostalgia, and retro vibes, you can repeat the process to get this character editor program. It's online elsewhere and pointed to in this blog, but if you have an air gapped C64, you can enter directly.
Note: Floppy drive 8 is required for loading/saving fonts and theme configuration. This program does not support tape drives or alternate floppy drives. So be prepared with a floppy drive 8 such as 1541, 1571, 1581.
Please enter the hex listing below using Compute's Gazette MLX II which includes a ninth checksum byte at the end of each line. MLX will stop you from continuing if the checksum doesn't match it's internal algorithm.
Friday, April 19, 2024
Edit Programmable Characters on Vic-20 and C64
The current release is considered fully functional and complete.
Links:
Vic-20 D64 (1541 image) and source
Commodore 64 D64 (1541 image) and source
The Commodore Vic-20 video chip added multiple features beyond what the original PET Model 2001 offered. Besides color support, it also includes the ability to change to user defined character sets. These can be used to customize the look and feel of a program, and also to provide bitmapped graphics.
Back in the 80s I was proud of my development of a character editor program that utilized a few machine language routines to perform quick operations via keyboard selections. Unfortunately I don't have direct access to that program today (haven't been able to read the tape back into the computer yet). So I decided to rewrite it again.
This time it is purely 6502 assembly code. I started using the VICE monitor to write the initial functionality, and soon afterwards transitioned to ACME source to ease edits and additions.
After mocking up the look of the screen, identifying operations that would be nice to have, and testing out memory layout and configuring the video chip to use character images from RAM, I got to work.
1. Initial screen layout including editor and commands.
2. Navigation of character selection, displaying bit patterns for editing to screen, and displaying hex character value and byte values.
3. Editing the pixels in a single character.
4. Saving font to floppy disk.
5. Continuing to iterate with new features and enhancements
Description of key operations
pressing a key on the keyboard as shown below will perform an operation:
@ - toggle between RAM/ROM character sets
SPACE - toggle pixel on/off
B - navigate back one character
C - copy
F - flip upside down
M - mirror the image left to right, right to left
N - navigate forward to next character
R - rotate 90 degress to the right
S - save to FONT.BIN (WARNING: overwrites any previous saves)
V - paste
X - cut
Y - redo
Z - undo
- minus - navigate 16 characters back
+ plus - navigate 16 characters forward
< > - shift pixels left/right
↑ - shift pixels up (^ carrat on PC)
Shift V - shift pixels down
CLR - erase all pixels
CURSOR keys - move cursor left/right/up/down
HOME - move cursor to upper left position
RVS - inverse the pixels
STOP - exit (usually mapped to ESC on PC)
There are up to 24 levels of undo [Z] (25 levels of redo [Y]) when editing a character. Navigating will clear the undos/redos. And there is a virtual clipboard which you can copy[C]/cut[X]/paste[V] a single character. Note in this program you do not use the Ctrl key for clipboard as you do on a PC.
Notes:
- When launching the program for the first time, the ROM font will be copied to RAM, including moving the start of programs up to $1800 past the RAM characters. Subsequent runs from that address will not recopy from ROM. If you want to restart fresh from ROM, either reset your computer and run again, or POKE 44,16:SYS 6157. You don't have to memorize the entry point, you can also LIST the line of BASIC that calls into the entry point.
- Saving overwrites FONT.BIN. So if you want to save your work permanently, it is recommended to rename your file to something else.
OPEN 15,8,15,"R0:COOL=FONT.BIN":CLOSE 15 - To LOAD your font for editing, be sure to run the program at least once, then load before running to enter back into edit mode. Be sure to include the ,1 otherwise you will wipe the font editor out of memory, then best to restart your Commodore and try again.
LOAD "COOL",8,1 - Pressing COMMODORE+SHIFT while in programmable characters will shift to a second set of characters which we don't have room for in RAM, so you will see bitmapped images of the program and video memory. Press the key combination again to return to the first set of characters. [Disabled in the C64 port]
Update 2024 April 26: more documentation
H - hide UI except pixels and character for a minimalist experience
/ - swap between two RAM character sets (C64 version edits total of 512 characters)
F1 - foreground color
F2 - cursor color
F3 - background color
F4 - character set 1 color
F5 - border color
F6 - character set 2 color
F7 - large pixel set color (editor)
F8 - large pixel cleared color (editor)
, - change titles color
. - change menus color
1,2,3,4,5,6,7,8,9,0 - select theme (colors and grid mode)
As the C64 has a different memory layout, video memory is at a lower address $0400 and more memory available, the memory map is a bit different. The start of the program is still at $1800, but the programmable characters are now from $0800 to $17FF, a full 4K (512 characters).
Note that only the first character set (256 characters) is visible at this address without moving the character set to another location (planned for future). But the editor can handle this by swapping the character sets in RAM for editing, swapping them back and forth, so one set is always edited from the lower $0800-$0FFF range that is visible. Just be sure to swap back to the first set before saving, otherwise the character sets will be out of order.
To use both character sets in your own programs, it is necessary to manually relocate them or load them at another address, unless you use the swapping technique used by the editor.
It is not presently possible to use raster interrupts to show both sets because the second set is at an address that is mapped to ROM characters instead. Another reason it is planned to move these in the future, for example to $3000-$3FFF but in the middle of BASIC RAM it may be too challenging to be useful to others.
Probably a better solution is to move both VIC-II memory to another bank of 16K, which also requires moving video memory. Say bank 4 with characters at $F000-$FFFF, and video ram at $CC00-$CFFF. Then move the start of BASIC to $0400, resulting in 39933 (39K) bytes available for BASIC, an increase of 1K the size of the video screen memory.
Leaving the editor, you have lost 4K of RAM from BASIC. To reclaim 2K for the not visible second character set, POKE 44, 20: POKE 20*256, 0: NEW but don't load any of your double character sets or you will wipe out the first 2K of your BASIC program. Best to leave 4K lost at start of BASIC in that case, or resize your character sets to a single set.
We're in the weeds here. Back to the fun -- please enjoy the programmable character sets and the graphical opportunities they provide!
Update 2024 April 27: raster interrupts implemented as described above, with two sets on screen, and working area using ROM font so doesn't change. Second set is copied to $3800-$3FFF for display purposes, while the two sets remain at $0800-$17FF.
Update 2024 April 28: themes implemented (10) and grid mode added, new C64 keys updated above. Themes allow quickly changing between color sets and grid options using the numeric keys.
Update 2024 May 1: wrote an article on moving video and programmable character memory.
Update 2024 May 4: have fixed many issues, and more enhancements, including moving programmable characters to $2000-$2FFF to make more usable, eliminate need to have separate edit/view copies. But loses more BASIC RAM ($0800-$1FFF 6K now available for other uses) while reserving memory for characters.
| Primary Color Theme |
Wednesday, February 7, 2024
Calculator for Commodore 64 and other CBM BASIC models
Introduction
Wow! A new desktop calculator for Commodore. Programmed all by myself in BASIC. Wow, so impressed! Or not. Doesn't even have decimals.
No, it's not the best thing since sliced bread, but it was fun. And it's just a start -- there's a bigger goal I'll get to in a while...
This was a puzzle programming exercise I challenged myself with. How to make the calculator, especially with the operator precedence feature.
Link: LOAD"CALC64",8
Implementation
Let's go through how it was implemented.
User Interface
First was the design of the user interface, by creating PRINT statements. Used reverse text to make a rectangular box with the keys displayed.
How to click on a key? I'm so used to a mouse or touch interface. Oops, Commodore doesn't have that usually, or not so easy. Ignoring the 1351 mouse for now. Most Commodore users are used to using the keyboard or joystick. Forget the joystick, this is not a game! Keyboard entry one key at a time will do just fine. Note that ENTER also acts as =, and DEL is equivalent to ←, and X is a synonym for *.
Entry of digits was the first processing, accepting up to the limit of the display. This stored as a string (V$) with keyed entries appended.
I started with 7 digits, but outgrew that in testing and increased to 9 digits.
At first, only positive numbers were supported, then fixed it to support negative numbers, with the negative sign taking up a position in the display. The N key toggles a number entry between positive and negative and back again.
Entries allowed by this calculator are interleaved numbers and binary (two argument) operators. Note that immediate operators like C and N usually take effect immediately, whereas binary operators require multiple arguments and a finalization (another binary operator or =).
There are exceptions allowed in entries to overwrite the prior value or the prior operator. Examples:
- 1+1=3 keyed entries will replace the 2 with a 3
- 2+x3 will replace the addition operator with multiplication operator
Precedence needs a Stack
One design requirement I set for myself was to include operator precedence. This means that multiplication and division have the same higher precedence over addition and subtraction at the same lower precedence. Usually math is evaluated left to right, but due to precedence issues, other operators may need to be done first. In other words the expression 1+2x3 is equivalent to 1 + (2x3) and then 1 + 6 and finally evaluates to 7. But 1 x 2 + 3 is equivalent to (1x2) + 3, then 2 + 3, and finally 5.
I simply put numbers and operators interchangeably on a stack in order of entry until enough information is present to start evaluating.
Rule 1 - if user presses =, then evaluate
Rule 2 - if first operator is multiplication or division, once the second number is finalized with a second operator, simply evaluate the first expressionRule 3 - if first operator is addition or subtraction, defer until the second operator and third number is finalized (third operator present!), then figure out what to do - either evaluate first or second expression, reducing the work
Subroutines
Error conditions
Limitations
Extras
Next
Saturday, December 30, 2023
Commodore 128 VDC Reference
Saturday, December 9, 2023
Commodore keyboards go wireless for my portable emulators
The c-simple-emu6502-cbm project supports a number of ESP32 platforms to provide a subset of Commodore C64 (and Vic-20, C128) emulation, and many currently include BLE keyboard support. Originally for CardKB only, now I have added BLE support for Commodore keyboards (20 to 25 pins) to the m5, T-Display-S3, and ESP32-8048S070-7inch ports/branches into the encapsulated BLE_commodore_keyboard_server Arduino sketch.
![]() |
| BLE options: (a) Commodore keyboard (b) CardKB |
No expense spared for these awesome graphics, seems retro eh?
![]() |
| M5Stick-C with CardKB BLE connected to T-Display-S3 |
Actually we already had BLE CardKB support, and the protocol for the hard wired keyboard is exactly the same as sent over BLE (string of active C64 and C128 scan codes), it was just a little bit of further coding to make the choice between CardKB and hardwired keyboard. In fact, that code was already present for CardKB or hardwired keyboard in the M5 branch itself. The tiny bit of extra work was to duplicate that in the BLE keyboard server project. And voila! More options all the way around.
![]() |
| Wired keyboards (a) Commodore (b) CardKB (c) Chrome Browser |
While wireless does have its convenience, it does require careful timing to pair correctly. Typically if both the BLE client and server are powered or reset at the same moment, they should pair. A few or more keystrokes may be necessary to confirm pairing is complete. If it doesn't work, just reset and try again.
Happy C64 computing over BLE!
Tuesday, December 5, 2023
7" LCD (ESP32) with C64 Text Emulator
![]() |
| 7" is giant compared to this much smaller screen |






