[cc65] Disable KERNAL ROM ?

From: Oliver Schmidt <ol.sc1web.de>
Date: 2013-02-11 14:13:40
Hi,

As I'm no C64 pro I only recently realized that - leaving the BASIC
ROM out of consideration - the memory layout of the C64 and the Apple2
are in general very similiar:

A large RAM area followed by some I/O area followed by banking between
ROM and "high" RAM.

On the Apple2 I introduced quite some time ago a way to make "native"
use of high RAM for cc65 programs and so I'm wondering if a similiar
approach wouldn't be applicable - and in fact desirable - for the C64
too. Sorry, if that should have already been discussed (too) many
times...

On the Apple2 it works like this:

- After running the constructors (which tend to interact with the ROM)
the startup code banks in high RAM just before calling main().

- Before running the destructors the _exit() code banks in ROM again.

- All calls from the C library into the ROM go through little thunks
which bank in ROM, do the call and bank in high RAM again. This can be
done without changing the library code by just removing the existing
aliases between ROM routine names and actual addresses. These aliases
are replaced by the thunks exporting the same names. The thunks
themselves use the actual addresses for doing the calls.

- The builtin linker config contains a memory area and a segment for
the "high" RAM marked as optional (!).

- The builtin linker config makes sure the content of that high RAM
segment (which by default empty) is placed at the end of the generated
binary file. So after loading the binary into RAM it's located where
the BSS starts.

- The startup code copies the content of the high RAM segment (which
is by default empty) from the BSS location to it's final location just
before zero'ing the BSS. The  startup code uses for that task an
existing ROM routine that deals nicely with zero bytes to copy.

So far so good. Now that everything is in place the user just has to
compile some of his code with the option --code-name or use the
#pragma code-name to place code in high RAM. That' all :-)

Note that by this usage scenario there's no problem with code banking
out itself as the thunks are of course placed in the CODE segment.
There's no problem with data not available to the ROM as only code is
placed in high RAM. And if there's desire for a C program to call some
arbitrary ROM routine it can use the _sys() function which does the
necessary banking like the thunks.

I understand that the C64 would additionally require the setup of an
IRQ thunk handler...

Looking forward to your comments, Oliver
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Mon Feb 11 14:13:58 2013

This archive was generated by hypermail 2.1.8 : 2013-02-11 14:14:03 CET