External RAM should be visible to the VIC in MAX Machine emulation mode.
Versatile Commodore Emulator
Brought to you by:
blackystardust,
gpz
For reference, this was discussed here:
https://www.lemon64.com/forum/viewtopic.php?p=1103479
still need to come up with that test program :)
Sooo, first half is done :) I updated the test program that shows the memory mapping for the CPU (so not quite what the ticket wants to fix, but we really should make sure this is ok first)
Please have a look at https://sourceforge.net/p/vice-emu/code/HEAD/tree/testprogs/C64/carts/ultimax/
ultimax(bin/crt) is the test program built for plain 16k ROM in Ultimax mode
ultimax-maxbasic(bin/crt) is the test program built for Maxbasic Cartridge
(They are really the same thing right now)
So we first have to make sure the memory mapping for the CPU side is correct in all cases. I believe this is actually the case for both RAM and ROM, for both "c64" and "max" models, and for both cartridges. Questions arise about the I/O area:
(Please don't bother burning EPROMs yet. We should first make sure the emulation works like we expect the real Max Machine to work - then make the test work on that exact config - and only then confirm them on the real thing :))
I'll be referring to the linked schematic and my own experiences when talking about the 6703 PLA and Cartridge port pin assignments. The schematic was chosen because it exactly matches my MAX board revision. I understand there is a hand drawn Commodore schematic and a recreation of that by Ruud available on Zimmers also which might be related to an earlier revision of the Max boards, but I have my doubts that they relate to an actual released product.
https://www.zimmers.net/anonftp/pub/cbm/schematics/computers/c64/maxschematic.jpg
https://github.com/itsPkun/6703-Dumping
Pin 7 of the cartridge port on the MAX is the chip select for External RAM.
Pin7 of the cartridge port on a c64 is IO1.
If you were to plug a MAX cartridge that has External RAM included (MAX-BASIC, MultiMAX) into a c64 then External RAM would be accessible via IO1. This equates to 06xx in the MAX's memory map or specifically 03xx on the 2k RAM chip itself.
Do note that with MAX-BASIC, the CPU R/W on the cartridge port line isn't used. Rather a separate R/W signal is generated by the 6703 PLA and presents a qualified R/W for external RAM on cartridge pin 13. As this pin is reused for /DMA on a c64, and pulled high by default, the RAM on a MAX BASIC will be held in a constant read state.
It is therefore impossible to write to the external RAM on a MAX cartridge on a c64. A read via IO1 would return 00 00 FF FF 00 00 FF FF or some other default RAM state (Unless some cartridge out in the wild has a ROM chip hanging off the External Ram chip select (?)).
The MultiMAX may or may not use the qualified R/W signal. I don't own one, but if the schematics still exist online somewhere we can glean the answer from those.
IO2 on the c64 is the same pin as the CIA chip select on a MAX. It is part of the loopback necessary for a MAX cartridge to use its CIA. Technically, accessing IO2 on a MAX cart will pull EXROM low. As the CPU is addressing IO2 at the time EXROM is pulled low this should be invisible to the CPU. IO2 would just therefore be a floating bus.
IO mirrors on the MAX are both easy and complicated. The 6703 PLA only has A15 down to A10 to work with so each mirror can be no smaller than 4 pages.
VIC - D000 - D3FF
SID - D400 - D7FF
COLOUR - D800 - DBFF
CIA - DC00 - DFFF ~~
~~The default CIA mirroring scheme assumes the loopback between pins 10 and 9 of the cartridge port are joined together with no additional address decoding on the cartridge. This seems to be true for every MAX cartridge released so far. However, the loopback can be interrupted and additional address decoding can be done by the cartridge if the cartridge designer so desires. I imagine Commodore designed it like that so additional IO chips could be shoehorned into the memory map.
Naturally this could alter the CIA mirroring. Because the cartridge designer can intercept the loopback and do whatever they want with the CIA Chip Select line, they can map it anywhere. Map the CIA to DF80, map it to the External RAM chip select, etc... How you emulate those possibilities I don't have an answer for.
There is also the case that the 6703 PLA does not allow writing to the SID when BA is pulled low. No three cycle leeway. Do note I have only determined this for myself by reading my PLA dump. My methodology and conclusion is probably flawed.
Sooo - comitted the VICII test(s) and also the VICE fixes. Ultimax/Maxbasic/Multimax cartridges should now behave as expected, both in C64 and MAX Machine mode.
Please test :)