Just to clarify a bit more the mappers and Z80 I'm going to explain how they work.
I'm going to summarize mappers from what I've read here :
http://cgfm2.emuviews.com/txt/smsmap.txtAll of those mappers stop at address 0xBFFF, which means that if the address of the Z80 is lower or equal to 0xBFFF you're (most likely) reading from ROM.
Some of the mappers can map an SRAM to 0x8000~0xBFFFF or even to 0xC000~0xFFFF (only SRAM). This is defined by the "config" register.
From the bigger ones, you can tell they can save 4 registers (if not 1 for the 128k ones), at 0xFFFC, 0xFFFD, 0xFFFE and 0xFFFF.
0xFFFC is like a config register. It tells the mapper if you mapped an SRAM at 0x8000 or 0xC000.
0xFFFD, 0xFFFE and 0xFFFF are used to set the value of A18~A14 (if it goes as high as A18).
The smaller ones (128k) with 1 bank only use 0xFFFF to set the value of the "higher address" lines. They don't map SRAM.
The bigger ones use all of the above. They can map ROM from 0x0400 to 0x3FFF, from 0x4000 to 0x7FFF and from 0x8000 to 0xBFFF and SRAM from 0x8000 to 0xBFFF and from 0xC000 to 0xFFFF.
I think, even though the SRAM is mapped from 0xC000 to 0xFFFF, if you write to 0xFFFC or above, you'll write in the mappers' registers.
The Z80 has 16 address lines, 8 data lines, 1 Cartridge Output Enable, 1 BusReq, 1 BusAck, 1 M1, 1 MReq, 1 RD and 1 WR. (Those are the important ones, I left a bunch of them out as they are not needed)
When reading or writing from/to memory, the Z80 will pull MReq and RD or WR low.
I can tell if it's writing those 4 registers in the mapper by checking following data:
- Is MReq and WR low ?
- Is address line > 0xFFFB ?
The Z80 reads and writes data in 3 clock cycles, but reads an opcode in 2 clock cycles. You can check if the Z80 is reading an opcode by reading M1. If you can trigger on the falling edge of M1, then you have 2 clock cycles to write data on the data lines. At the rising edge of the 3rd clock cycle it will read the data lines. MReq and RD are affected by this read operation.
@C:I think your idea may complicate the process too much (or I'm not grasping the idea).
If I can have 4 variables in a CPLD, I don't need the extra cache. Whenever the Z80 tries to read a byte from ROM, just OR one of the variables to the higher address lines and that's pretty much it.
@madshaman:I'd like to make a program for the SMS, but also play some old school games

.