Jump to content
  • 0

Accessing VLOAD from cc65


ZeroByte
 Share

Question

I'm trying to get cc65 to do a vload() - I have some old code that worked back several revs ago, but now I can't figure out the way to get it to happen.

If I know cc65, there's already a function to do it, but I'm just having trouble figuring it out. Gonna keep working on my own but thought I'd see if anyone has the answer while I'm poking around....

in BASIC, it works easily by this command:

VLOAD "INTRO.BIN",8,1,$4000 (loads to bank 1, adress 0x4000)

What would the C equivalent be?

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

Looking around the cc65 source, it doesn't seem like there is a vload to me.  So you would have to do something like (note I didn't test this and I haven't really done any C with the X16 so something might be wrong):

Quote

cbm_k_setlfs(0, 8, 0);

cbm_k_setnam("intro.bin");

cbm_k_load(3, 0x4000);

The first argument to cbm_k_load() would be 2 for bank 0 and 3 for bank 1.

Edited by Ender
Link to comment
Share on other sites

  • 0
8 hours ago, ZeroByte said:

I'm trying to get cc65 to do a vload() - I have some old code that worked back several revs ago, but now I can't figure out the way to get it to happen.

If I know cc65, there's already a function to do it, but I'm just having trouble figuring it out. Gonna keep working on my own but thought I'd see if anyone has the answer while I'm poking around....

in BASIC, it works easily by this command:

VLOAD "INTRO.BIN",8,1,$4000 (loads to bank 1, adress 0x4000)

What would the C equivalent be?

At the risk of derailing your actual question, where is VLOAD documented?  In the manual it just says "TODO", but there is this section soon after that: https://github.com/commanderx16/x16-docs/blob/master/Commander X16 Programmer's Reference Guide.md#load-into-vram
Which uses the regular LOAD command and it supposedly uses the first two bytes to determine where to put it, don't know if it works.
But VLOAD as you describe is much more useful.  And thank you for showing the syntax, just wondering if it's documented anywhere.

Link to comment
Share on other sites

  • 0
10 minutes ago, x16tial said:

At the risk of derailing your actual question, where is VLOAD documented?  In the manual it just says "TODO", but there is this section soon after that: https://github.com/commanderx16/x16-docs/blob/master/Commander X16 Programmer's Reference Guide.md#load-into-vram
Which uses the regular LOAD command and it supposedly uses the first two bytes to determine where to put it, don't know if it works.
But VLOAD as you describe is much more useful.  And thank you for showing the syntax, just wondering if it's documented anywhere.

I believe that section of the documentation is out of date, and there's no official documentation, unfortunately.  However, it's pretty straightforward, as ZeroByte's example shows:

Quote

VLOAD "NAME",bank,address

The "bank" argument actually gets loaded into the ADDRx_H register of the VERA, so you could give a value for the increment there as well.

Link to comment
Share on other sites

  • 0
53 minutes ago, Ender said:

The first argument to cbm_k_load() would be 3 for bank 0 and 4 for bank 1.

THANKS!!!

One small thing wrong with your solution, the first argument is 2 for bank 0, and 3 for bank 1.

My previous code used bank+2 in that spot. The thing that was broken about my previous code was my values for SETLFS, which I had previously used 2,1,0 - not sure where the heck I came up with those numbers. The code I lifted that from was last built/used in 2019 (in my X16 port of Flappy Bird, which I'm about to dust off and complete now that this AdLib driver proof-of-concept works.)

So for those reading along, I used this:

static void vload(const char* filename, const uint8_t bank, const uint16_t address)
{
    cbm_k_setnam(filename);
    cbm_k_setlfs(0,8,0);
    cbm_k_load(bank+2,address); // bank+2 is a special functionality of X16 LOAD
}

Now my program doesn't have the garbage across the bottom, and it auto-loads correctly without the VLOAD bootstrapping I used in my video. Now I'm going to extract a few more songs and see how they sound. I think I'll make a video with the various songs.

Lastly, I'm cleaning up my code for public display and will post it to GitHub for the community's use.

  • Like 1
Link to comment
Share on other sites

  • 0

OMG - the demon rears its ugly head again.... Host FS vs Kernal-native routines.

It looks like the these values don't work on SD card images....

I tweaked them a little, and now the BG image loads, but the palette doesn't - how bizarre!
(I think it looks like the Kernal might be including the header bytes in its load - I'll try messing around a little more but it's bed time)

closest approximation using SD card:

setlfs (2,8,0)

load(bank+3,address)

Link to comment
Share on other sites

  • 0
1 hour ago, ZeroByte said:

OMG - the demon rears its ugly head again.... Host FS vs Kernal-native routines.

It looks like the these values don't work on SD card images....

I tweaked them a little, and now the BG image loads, but the palette doesn't - how bizarre!
(I think it looks like the Kernal might be including the header bytes in its load - I'll try messing around a little more but it's bed time)

closest approximation using SD card:

setlfs (2,8,0)

load(bank+3,address)

Are you on R38 or the newest github version of the kernal?  There's a bug in R38 with SD cards where it always uses the header of the file for the address.  It should be fixed in the current github version though.

2 hours ago, ZeroByte said:

The thing that was broken about my previous code was my values for SETLFS, which I had previously used 2,1,0 - not sure where the heck I came up with those numbers.

The device used to be 1 on older versions, but it's 8 now.  As for the first argument, I'm not sure that really matters? I haven't dug into it too much, but I couldn't find it being used anywhere in LOAD.  The third argument is what lets it know to use the passed-in address vs. the header.

Edited by Ender
Link to comment
Share on other sites

  • 0
7 hours ago, Ender said:

Are you on R38 or the newest github version of the kernal? 

:forehead smack:

Yeah I’m still using R38. But I was thinking in my head ‘they’ve fixed stuff’ - gotta actually INSTALL the fixes lol.

I think I’m going to be patient and wait for the R39 release because back in the R31 R32 days, I got some serious headaches having to keep not only my ‘master branch’ emu but cc65 and my own code in sync with each other. Things aren’t changing quite as fast nowadays so I might give the bleeding edge a whack anyway.

Can you tell these LOAD behaviors have caused me hours of debugging only to discover it wasn’t my fault? 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use