Can you load a bitmap directly into VRAM?

All aspects of programming on the Commander X16.
mwiedmann
Posts: 70
Joined: Fri Jan 20, 2023 2:21 am
Location: New York City

Can you load a bitmap directly into VRAM?

Post 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?
mwiedmann
Posts: 70
Joined: Fri Jan 20, 2023 2:21 am
Location: New York City

Re: Can you load a bitmap directly into VRAM?

Post 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.
User avatar
StephenHorn
Posts: 565
Joined: Tue Apr 28, 2020 12:00 am
Contact:

Re: Can you load a bitmap directly into VRAM?

Post 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.
Developer for Box16, the other X16 emulator. (Box16 on GitHub)
I also accept pull requests for x16emu, the official X16 emulator. (x16-emulator on GitHub)
TomXP411
Posts: 1804
Joined: Tue May 19, 2020 8:49 pm

Re: Can you load a bitmap directly into VRAM?

Post 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.
User avatar
StephenHorn
Posts: 565
Joined: Tue Apr 28, 2020 12:00 am
Contact:

Re: Can you load a bitmap directly into VRAM?

Post by StephenHorn »

Ah, yes, if you're attempting to use BASIC to load the bitmap into VRAM, just use the VLOAD command. :3
Developer for Box16, the other X16 emulator. (Box16 on GitHub)
I also accept pull requests for x16emu, the official X16 emulator. (x16-emulator on GitHub)
User avatar
StephenHorn
Posts: 565
Joined: Tue Apr 28, 2020 12:00 am
Contact:

Re: Can you load a bitmap directly into VRAM?

Post 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.)
Developer for Box16, the other X16 emulator. (Box16 on GitHub)
I also accept pull requests for x16emu, the official X16 emulator. (x16-emulator on GitHub)
mwiedmann
Posts: 70
Joined: Fri Jan 20, 2023 2:21 am
Location: New York City

Re: Can you load a bitmap directly into VRAM?

Post 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!
User avatar
desertfish
Posts: 1123
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

Re: Can you load a bitmap directly into VRAM?

Post 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)
BruceRMcF
Posts: 224
Joined: Sat Jan 07, 2023 10:33 pm

Re: Can you load a bitmap directly into VRAM?

Post 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.
Ender
Posts: 220
Joined: Sat May 09, 2020 9:32 pm

Re: Can you load a bitmap directly into VRAM?

Post 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.
Post Reply