The PNG Pipeline
The first utility I wanted to build was a set of tools to convert any appropriately scaled-down PNG to be viewable directly in PC-60 BASIC.
I’ve used Python for the scripts that convert and generate the necessary data plus the 3rd party tool txt2bas.exe available online.
I was able to draw directly using the PC-60 palette using this palette profile I made for Paint.Net, then convert the PNG to a BASIC program for display.
I drew this small logo for PC-6002, here it’s getting unpacked in the emulator in Mode 5:
When I started experimenting on converting larger PNGs I immediately ran into RAM limits, back then this used to be a major bottleneck in my projects. The palette in PC-60 is tiny (16 colors) and as a result there are many repeated bytes in the pixel data, so I developed a simple RLE compression-decompression method in Python and ported it to BASIC. It was pretty effective I was able to load bigger more-detailed images.
The pipeline I went with to achieve all required features is pretty straightforward:
- PNG60.py: script to read a PNG, make sure it’s compatible, map all its colors to the closest colors in the PC-60 palette, then exports the resulting color data as a binary color list that matches PC-60’s video memory layout. It supports Mode 5 and 6. It outputs binary files using extension: “.p6bmp”
- p6bmp2bas.py: this is the workhorse in the system, it reads PNG60’s output binary files and pre-processes them first for PC-60 applying optional RLE compression. Then generate a BASIC program that includes all required code to display the bitmap as well as the bitmap data. It outputs the basic program as a “.bmp.bas” file.
- txt2bas: this is a tool developed by japanese PC-60 developers and is available online. It simply converts the BASIC program generated by p6bmp2bas script to a .p6 casette file that can be loaded directly in any PC-60 emulator using the “cload” command and then executed using the usual “run” command. The two supported modes are: Mode 5 Page 3, and Mode 6.
These tools are all grouped into a package usable via a few batch files I wrote to automate all the stages of the pipeline and directly output the .p6 file from a PNG file.
I setup this repository for the pipeline package (folder “PNG60”) and I will be constantly updating it with any new stuff I develop in the future.
I’ve pretty much implemented most of what I wanted to experiment with however the size/detail of PNGs I can convert over to PC-60 is still limited by memory even after RLE compression. I would like to reimplement the last stage of the pipeline to directly export to loadable binary data on a floppy disk (using BASIC’s BLOAD command) which is much faster and allows loading full-screen bitmaps directly.
Additionally, the current method to convert colors to PC-60 palette is just a simple RGB comparison to figure out which PC-60 color is the closest. As a result, many colors in exported bitmaps get approximated to gray which is right in the middle of the RGB range. I’d like to make sure to use the whole 16 colors palette and do some half-tone/dithering to fake more colors.
Next: I’ll be working on ditching BASIC for C/Assembly-programming and expand on this reference page I’m writing.
blog comments powered by Disqus