Yazwh0_BitMagic_Legacy/Examples/DisplayImage/DisplayImageX16/src/main.csasm
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;
machine CommanderX16R40;

    BM.X16Header(); // byte code to start execution.

    VideoMemory.SetCopyZpWordAddress(0x02); // define where in ZP the copy can use.
    Inflator.SetSourceZp(0x02); // 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

       lda #180
       sta DC_HSCALE
       sta DC_VSCALE

    Video.LayerBitmap(ConfigLayer.Layer0, Vera.Depth.Bpp_8, Vera.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 = Processor.LoadFullImage(@"Assets\bliss.bmp");

    ; copy palette to vera
    VideoMemory.Copy("palette", 0x1fa00, imageData.Colours.Length * 2);

    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.Colours.SelectMany(c => c.VeraColour));
    
    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
