BitMagic
Posted: Sun Feb 13, 2022 6:40 pm
Introducing BitMagic!
BitMagic is -- currently -- a macro assembler and a compiler for the X16, that utilises C# and the dotnet build chain to provide us with the ability to write macros to a much greater degree of complexity than offered by traditional assemblers. The ideal being that there will no longer be a need to write external applications to construct what we're trying to do, especially with assets.
There are a few things to do, most importantly implement any missing 65c02 opcodes, but it is nearing a usable state so it felt like the right time to at least share.
Instead of cut/pasting the text on the GitHub repository, you can read all about it here.
However, an picture is worth a thousand words, so as an example here is the code for this downloadable demo. It is assembler -- honest!
assembly "..\..\Libraries\Compression\bin\Debug\net6.0\Compression.dll";
assembly "..\..\Libraries\ImageProcessor\bin\Debug\net6.0\ImageProcessor.dll";
assembly "..\..\Libraries\Vera\bin\Debug\net6.0\Vera.dll";
using Compression;
using ImageProcessor;
using Vera;
BM.X16Header(); // byte code to start execution.
VideoMemory.SetCopyZpWordAddress(0x00); // define where in ZP the copy can use.
Inflator.SetSourceZp(0x00); // define where in ZP we can use for inflating.
Video.Mode(Layers.None); // disable all layers and sprites while the image inflates.
Video.Scaling(Resolution.Half); // 320x240
Video.LayerBitmap(ConfigLayer.Layer0, Depth.Bpp_8, BitmapWidth.Half_320, 0x1000);
; in case colour 0 is not black!
lda #$11
sta ADDRx_H
lda #$fa
sta ADDRx_M
stz ADDRx_L
stz DATA0
stz DATA0
; call decompress
Inflator.InflateToVram("compressed_data", 0x1000);
var imageData = ImageAsset.LoadFullImage(@"Assets\bliss.bmp");
; copy palette to vera
VideoMemory.Copy("palette", 0x1fa00, imageData.X16Colours.Length);
Video.Mode(Layers.Layer0); // turn on layer 0 to show the image.
; infinite loop
.loop:
jmp loop
Inflator.InflateToVramCode(); // decompressor proc code.
VideoMemory.CopyProc(); // copy proc code.
.palette:
BM.Bytes(imageData.X16Colours);
var compressed = Deflator.Deflate(imageData.Pixels);
; Source data is @(imageData.Pixels.Length) bytes.
; Compressed data is $@(compressed.Length.ToString("X4")) bytes.
.compressed_data:
BM.Bytes(compressed);
; scratch space for decompression.
.segment Variables, $400
Inflator.DefineScratchArea();
.endsegment
Thanks for reading, and I hope you find it at least interesting!