Page 1 of 2

Can you load a bitmap directly into VRAM?

Posted: Fri Feb 03, 2023 6:57 pm
by mwiedmann
I'm displaying a bitmap file on screen. I can load then bitmap from disk into RAM using cbm_k_load, but then I have to copy the bytes one-at-a-time into VRAM using the Address Lo/Hi/Mid and Data0 registers. Its pretty slow. Even a 320x200 image takes quite a few seconds to fully render on screen.

Is there a faster way?

Re: Can you load a bitmap directly into VRAM?

Posted: Fri Feb 03, 2023 7:29 pm
by mwiedmann
I think I figured it out. The kernal function "memory_copy" at FEE7 seems to do it.

So something like:
POKEW(0x2, BANK_RAM); // Read from the BANK_RAM location where I loaded the bitmap
POKEW(0x4, 0x9F23); // Point it to the Data0 register
POKEW(0x6, numBytesToCopy); // Size of my bitmap
__asm__("jsr $FEE7");

This seems to work. Are these kernal functions exposed through any C libs? I didn't see any of them in cx16.h or the other headers.

Re: Can you load a bitmap directly into VRAM?

Posted: Fri Feb 03, 2023 7:31 pm
by StephenHorn
This could stand to be documented clearly, but the X16 has extended the behavior of the LOAD kernal function.

Normally, if the A register is 0, the kernal loads the file into system memory. Non-zero means the kernal should perform a verify instead.

On the X16:
  • If the A register is zero, the kernal loads into system memory.
  • If the A register is 1, the kernal performs a verify.
  • If the A register is 2, the kernal loads into VRAM, starting from $00000 + the specified starting address.
  • If the A register is 3, the kernal loads into VRAM, starting from $10000 + the specified starting address.

Re: Can you load a bitmap directly into VRAM?

Posted: Fri Feb 03, 2023 7:41 pm
by TomXP411
From the manual:

VLOAD
TYPE: Command
FORMAT: VLOAD <filename>, <device>, <VERA_high_address>, <VERA_low_address>

Action: Loads a file directly into VERA RAM.

Re: Can you load a bitmap directly into VRAM?

Posted: Fri Feb 03, 2023 7:45 pm
by StephenHorn
Ah, yes, if you're attempting to use BASIC to load the bitmap into VRAM, just use the VLOAD command. :3

Re: Can you load a bitmap directly into VRAM?

Posted: Fri Feb 03, 2023 7:50 pm
by StephenHorn
mwiedmann wrote: Fri Feb 03, 2023 7:29 pm Are these kernal functions exposed through any C libs? I didn't see any of them in cx16.h or the other headers.
If you're working from the latest repository version of cc65 and it's not there, then it's not there. :(

cc65 does support the X16, but that support is a little dated these days because C development got stalled by some wonkiness on the X16 side of things, and the folks I recall being the main contributors to the C development support kind of wandered away since their pull requests to cc65 couldn't be honored in a timely fashion. (In fairness, it's hard to remain motivated with something when forces beyond your control are stymying your ability to contribute.)

Re: Can you load a bitmap directly into VRAM?

Posted: Fri Feb 03, 2023 8:27 pm
by mwiedmann
Thanks for all the info. I'm using C so the VLOAD function doesn't help. I'll try setting the A register to load directly into VRAM, but with the memory_copy kernal function, its so fast to copy from banked RAM now that my problem is essentially solved.

Thanks all!

Re: Can you load a bitmap directly into VRAM?

Posted: Sat Feb 04, 2023 1:14 pm
by desertfish
Prog8 has a vload() function in the disk io library. It is calling the regular kernal routines to load a file, but with the correct parameters set up to make it load directly into vram.

I'm sure you can do the same in cc65 by making your own vload routine. (it's too bad that everyone has to do this, but maybe someone could make an updated/extended x16 library that others can utilize / contribute to)

Re: Can you load a bitmap directly into VRAM?

Posted: Thu Feb 09, 2023 3:31 pm
by BruceRMcF
Ender, it's true that message is repeating the OP question that was just answered ... but sitting at the end of the message is a link to "how to unlock an iphone without itunes", so the message text is just spam.

Re: Can you load a bitmap directly into VRAM?

Posted: Thu Feb 09, 2023 4:05 pm
by Ender
BruceRMcF wrote: Thu Feb 09, 2023 3:31 pm Ender, it's true that message is repeating the OP question that was just answered ... but sitting at the end of the message is a link to "how to unlock an iphone without itunes", so the message text is just spam.
Oh haha, I didn't look back and notice that the message was literally the same as the OP, just with a few words changed/removed. I guess some more spam bot protections need to be added to the board.