Using bitmap mode from C

All aspects of programming on the Commander X16.
rorodev
Posts: 4
Joined: Wed Oct 25, 2023 5:22 pm

Re: Using bitmap mode from C

Post by rorodev »

rorodev wrote: Wed Oct 25, 2023 5:37 pm I am searching for an example to understand better how I use the bitmap mode in C (or maybe Assembler).
Ultimately, I'm wondering how to initialize this VERA mode and how I set after a pixel in a specific color.
It would be great if someone could give me a headstart. Thanks a lot.
,

Yes, thank you, that one I have found, and it was very useful too!
DragWx
Posts: 345
Joined: Tue Mar 07, 2023 9:07 pm

Re: Using bitmap mode from C

Post by DragWx »

Microdriver wrote: Thu Oct 26, 2023 8:40 am

Code: Select all

#include <cx16.h>
#include <peekpoke.h>
/* nope.c */
int main() {
    int i;
    POKE(0x9F25, 0);
    POKE(0x9F20, 0x34);
    POKE(0x9F21, 0x12);
    for (i = 0; i < 1000; i++) {
        POKE(0x9F22, i);
        POKE(0x9F23, i);
    }
    return 0;
}
Nope, doesn't do anything ...
Remember that the address is little-endian, so 0x9F20 contains bits 0..7, 0x9F21 contains bits 8..15, and 0x9F22 contains bit 16 of the VRAM address 0x9F23 will access. The for loop needs to poke 0x9F20 instead of 0x9F22, is all.

Second, while you might be writing values to VRAM, you need to make sure the VERA is configured to show that memory as pixel data.

With a layer in bitmap mode, you use 0x9F2F and 0x9F36 (for layer 0 and layer 1 respectively), bits 2..7 to specify the address of your pixel data in VRAM, in 0x800-byte increments (for example, POKE(0x9F2F, 0xC) = bitmap data at 0x01800 for layer 0).

The VERA Programmer's Reference contains a full reference of all the VERA's registers, if you want to verify.
Post Reply