Greetings!
I am stuck thousands of miles away from my lab, recovering from Covid. To get my brain going I've been poring over the hardware forums. I am considering putting together a new 65C02 system when I get home. So far this is a thought experiment, and I welcome any feedback.
Features* Two distinct modes of operation with distinct memory mapping logic:
USER MODE with 64K RAM and nothing else (fast) and
SYSTEM MODE with ROM and IO (slow); writes to non-IO space are directed to RAM.
* All hardware IO encapsulated in system mode with a simple user API
* Unbroken 64K user RAM space for simplicity, speed, compatibility
* Protection of sorts (similar to X86 rings, with IO accessible only to system mode)
* Simplified address decoding (none in user mode; coarse segments acceptable in system mode)
* Speed - user mode with 10ns SRAMs should reach the highest speed the CPU is capable of...
SummaryThe goal of the project is to present the user with a clean contiguous (and fast) RAM-only system and keep all housekeeping stuff in the system mode (possibly running with a stretched clock to accommodate slower ROM and peripherals). As an added benefit, the system mode acts as a HAL, encapsulating drivers and hardware complexity while the user mode is seen as a solid 64K-RAM mode. With a minimal API it is possible to construct all sorts of compatible 6502 systems with entirely different peripheral hardware.
User mode requires no address decoding at all! It's RAM all the way down.
System mode decoding is pretty minimal, as there is no RAM to deal with (hopefully... see below).
Snags: Page 0 and Page 16502 normally requires pages 0 and 1 to be in RAM in order for page 0 and the stack to function as intended. If the worst comes to worst, we can always decode Page 0/Page 1 (or n kilobytes) to RAM in system mode, making it resemble a traditional system. But I think that it is possible to avoid RAM in system mode - although it may be more of a pain in the ass than it's worth (I am curious to hear your opinions).
A ROM-only mode presents a special challenge - page 0 and page 1, which can no longer be read. Note that they can be written-through to RAM, but not read. The stack can be pushed (in RAM), but reading it in system mode will return the results from ROM.
Avoiding page 0 is doable (though annoying, and possibly not worth it!)
Avoiding using the stack is a more difficult problem - we can't return from nested ROM subroutines and interrupts. If the switch-to-RAM logic is strategically delayed by a few cycles, we effectively have a 'delay slot' so we can switch to user mode and execute an RTS or RTI (but not if it's nested!).
It is possible to store a few addresses in ROM page 1 in a way that is helpful, perhaps. We can then manipulate SP to control the return from subroutines and interrupts. This allows us to build applications with a 'message loop' - instead of system calls we jump to system APIs which reenter the main loop, for instance...
Implementation DetailsI am thinking of leaning heavily on Dr. Jefyll's contributions for:
* Clock-stretching logic to slow down when in System mode;
http://forum.6502.org/viewtopic.php?f=4&p=66907#p66907* Unimplemented opcode fast IO to switch modes;
http://forum.6502.org/viewtopic.php?f=4&t=1945There is no user mode address decoder. RAM WR qualified with Φ2. All writes (user, system, and IO) are written in RAM.
System-mode decoder can be optimized away by dedicating upper 32K to ROM and the rest to IO using A15, as an enable etc.
Is it worth it?I am still noodling it out. I like the linear 64K user mode and lack of decoding for maximum speed. I like the system mode for booting up and containing/encapsulating all hardware.
Even if low RAM needs to be decoded in system mode to support page 0/1, there is still the advantage of no decoding in user mode, clean memory map, ring separation, etc. Since we have a clean user mode, the system mode may be decoded in a coarser way as we don't need to worry about memory holes or not using the memory space efficiently.
I can also imagine more modes, or paging a 64K chunks of RAM for multitasking.
Am I missing anything?Feedback is always welcome.