Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitmap data storage layout for VERA #36

Open
paradoxnj opened this issue Jan 7, 2020 · 8 comments
Open

Bitmap data storage layout for VERA #36

paradoxnj opened this issue Jan 7, 2020 · 8 comments

Comments

@paradoxnj
Copy link

Documentation is lacking for the bitmap storage on VERA.

@JimmyDansbo
Copy link
Contributor

What exactly is it you are missing? Bitmaps are documented here: https://github.com/commanderx16/x16-docs/blob/master/VERA%20Programmer's%20Reference.md#bitmap-mode-1248-bpp
1bpp = 1 bit per pixel = 8 pixel per byte
2bpp = 2 bit per pixel = 4 pixel per byte
4bpp = 4 bit per pixel = 2 pixel per byte
8bpp = 8 bit per pixel = 1 pixel per byte.

@paradoxnj
Copy link
Author

I got the bitmap data layout finally as that was recently added to the docs. Now the palette is giving me issues. There is hardly any documentation on converting an 8 bit palette to 12 bit. I thought it may be me so I tried a DOS program in x86 assembler. Took me 30 mins to write a bitmap viewer. I said DOS is easy, let me try Amiga...this time about an hour in 68K ASM to write a bitmap viewer and that uses bitplanes. I said...ok let me try C64. 45 mins and I rendered a full screen bitmap. For me on the x16, it has been 3+ months and I can't get a fullscreen bitmap rendered correctly. I get the outline of a photo, but all the colors are messed up.

@indigodarkwolf
Copy link
Collaborator

indigodarkwolf commented Apr 1, 2020

Colors in the palette are 16-bit values in little-endian order, but only use the 12 least-significant bits.

In other words, for each color in the palette, starting at $1FA00
Byte 0: #ggggbbbb
Byte 1: #0000rrrr

For instance, try this in BASIC: VPOKE1,$FA02,$00

Notice that all the white became red. That's because color index 1 starts as $FFF (white), but we've clobbered the green and blue components to 0. We can change it to lime with by restoring the green component and clobbering the red component: VPOKE1,$FA02,$F0:VPOKE1,$FA03,$00

@paradoxnj
Copy link
Author

OK...that part I get...my conversion code is as follows. Is this correct?

gb = (g & 0xF0) | ((b & 0xF0) >> 4);
r = (r & 0xF0) >> 4;

fwrite(&gb, sizeof(uint8_t), 1, outfile);
fwrite(&r, sizeof(uint8_t), 1, outfile);

@indigodarkwolf
Copy link
Collaborator

As long as r, g, and b are each 8-bit color components, then that looks correct to me. gb and r would need to be uint8_t as well, which I'm assuming is the case.

@paradoxnj
Copy link
Author

Yep. They are all uint8_t. It has to be my asm routine to copy the palette into VERA. When you embed a file into code via "!bin "filename", does the file need to have the load address at the beginning?

@JimmyDansbo
Copy link
Contributor

Yep. They are all uint8_t. It has to be my asm routine to copy the palette into VERA. When you embed a file into code via "!bin "filename", does the file need to have the load address at the beginning?

No, but you need to manually copy it to VRAM. When you include it with !bin, it is loaded into system RAM just like the rest of your program.

@paradoxnj
Copy link
Author

OK. My palette file has the load address in it. I have a routine that copies it into VRAM. If removing the load address does not work, then it has to be the ASM routine to copy to VRAM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants