I needed this for a project, so now cc65 supports trampolines. Makes PRG banking almost nice when you can transparently call anything without manual bankswitching and/or taking care to only call to/from a common bank.

That looks nice. I think it could use a little clarification of how the function is called. What does an example "trampoline" routine look like? It says the bank parameter is in tmp4, and the address of the function is in ptr4, but that doesn't really tell the whole story.

You said in some of the github comments that your trampoline is only 10 bytes though. How did you manage that? (Are you implicitly only allowing void functions with no arguments?)

It also seems prudent to put the CRT in a fixed bank (e.g. 16/16 mapper arrangement, UNROM). I saw some comments about putting the trampoline in RAM, but I think 32k banks would be a hassle anyway. You'd have to jump through a few hoops to get the CRT linked in more than one place, probably not worth the effort.

Note the argument setup has entirely disappeared. (Doesn't seem to be a problem with __cdecl__/--standard calls, since they don't use registers.)

There is a maybe related problem with variadic functions. They require the stack size to be passed in Y and the trampoline preamble clobbers it. (Functions without a prototype will also set up Y in this way, though this is a much more obscure case.)

Your trampoline is valid, things I do in addition are checking if the bankswitch is needed at all, and jumping to callptr4, which does the same as your @call. The CRT issues would complicate 32k banks, indeed.

10 bytes was just a test trampoline that didn't switch banks, a switching one will be larger.

Thanks for testing, variadic functions will need special handling, or perhaps just disallowing them. The optimization bug needs some attention.

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum