That's really great news! I apologise in advance for the long email:
Right now I'm in the process of creating the platform files
(.ucf, .xst, .ut & .batch) for a board with a single LX9 FPGA, to see
how easily the existing design fits. One potential problem is I've used
all 102 I/O pins on the FPGA (see attached entity declaration).
I will take a close look at this file later (really busy right now). But it's always a problem to fit the needed signals on the avaiable FPGA pins. :)
I am not bothering with /AS, CLK or /C_CE from the cartridge slot
because I don't think they're needed:
* I want to clock everything in the FPGA at 48MHz (i.e avoid the ugly
and actually pointless clock-doubling to 96MHz in the current design),
so I need to treat the address, data and control signals as asynchronous
inputs anyway, so there's no need to use the MD's CLK.
I am a little afraid of an asynchronous design. I am just paranoid with metastability issues. It comes from my experience with my old project based on the CPLD.
Maybe it's just a good idea to leave CLK (the 7.67 MHz one, right?) routed to the FPGA.
* The C_CE line is just for convenience and can be regenerated from the
address lines; it's asserted when the lower 4MiB is accessed (i.e the
cartridge address space).
I've attached to the e-mail some old threads(from the segaextreme forum) concerning DRAMS and the megadrive cartridge signals. Sorry if you've already seen them, or if you already know that information. But it's part of the research I did while developing my old CPLD system.
In those threads there is some speculation about using /C_CE and /OE (called in the threads /CAS_0) for a megadrive's built in refresh method. Anyway, if this information is correct, it would work only for FPM/EDO AsynchronousDRAMs. But maybe, relying on these signals is a good way to know the 'no activity window' where we can fit a refresh cycle.
As you can see, I am being paranoid. That's just because my CPLD design didn't work ;). In fact, I know that the UMDKv2 works with a CelullarRAM(PSDRAM) that incorporates a transparent self refresh mechanism. So, if you think that we are able to refresh the SDRAM with no problems, just ignore these thoughts.
* The /AS is a weird one. It toggles on most cartridge memory cycles,
but NOT during plays of sampled sounds (e.g the "Sega" ditty on Sonic
1). Since its intent can be achieved just as easily and more reliably
(i.e for ALL cycle types) with the /OE, UDSW & LDSW lines, it is not
necessary.
Yes. From what I've learned with my old project and some research, three devices accesses ROM on megadrive:
1) 680000
2) Z80 (the sound cpu or the main cpu when in 'mark III compatibility mode - sega master system mode')
3) DMA
Devices 2) and 3) won't generate /AS (address strobe comes only from 68k). So, we have to rely on /OE to get non-68k reads.
And yes, we must rely on LDSW to get 68k writes.
Indeed, it's ok to leave /AS out of the list.
I have included /DTACK because it would be good to have the freedom to
locate the FPGA's registers in address ranges where there is no
automatic DTACK generation.
Totally agreed.
I have dropped the mdBufOE_out signal from the original design because
it was just connected to ground anyway (thus enabling the three
5V<->3.3V level shifters). We can just leave the level shifters always
running, as long as they default to the MD->FPGA direction so as to
avoid bus contention on the MD side.
Totally agreed (just thought the same thing yesterday while designing the interface to my FPGA kit).
I have also removed the global reset_in signal because since the FPGA
registers start in a known state it seems a bit superfluous.
Agreed.
What do you think? Have I missed anything?
It would be good to drive 2 more cartridge signals:
1) /CART_IN - for Sega CD hardware simulation purposes. It's a low level active input to megadrive. We don't need to pass it thru a level translator: just use a open drain output on the FPGA as it's pulled up on megadrive.
2) /M3 - for Sega Master System mode purposes. It's a low level active input to megadrive. We dont' need to pass it thru a level translator: same as above.
I am finishing the schematic of the interface to my FPGA KIT (It's a Digitlent Spartan 3E Starter Kit). I will send it to you as soon as I finish it. I've placed some jumpers where it's possible to select the routing between some megadrive signals and a single port on the FPGA. It was the way I found to be able to make experiments with any megadrive signal I want, even having a few diponible ports on the FPGA.
My thinking was to proceed like this:
* Get the platform files done for the LX9 FPGA, see how the resource
utilisation looks.
* Re-write the memory controller to clock at 48MHz instead of 96MHz
(which was then divided by two again to generate the RAM clock...duh).
* Re-assess the resource-utilisation and start doing the schematic and
PCB layout.
* Order enough components for ten boards. I have a friend in Shanghai
who has agreed to accept delivery from Chinese component distributors
and then forward them to me as a gift, so we avoid the UK's extortionate
import taxes.
* Finish PCB layout and send gerbers off to the manufacturer.
* Port the memory controller to a real SDRAM (as opposed to the
psudo-SDRAM on the Nexys2). I have a working SDRAM to play with here:
http://www.makestuff.eu/wordpress/?p=2363. It should be fairly
straightforward to interleave one "DMA" memory cycle between every
MegaDrive cycle, so reads from SD-card can be done without the need for
the 68K to move data, and so the host can read and write cartridge
memory without having to halt the MD as the current design does.
* When boards and components arrive, solder one of them, spend a couple
of days testing it to make sure it works, then solder a few more boards,
test them and send them out to collaborators.
That's really great.
The next step with my FPGA kit is getting its SDRAM working. I got that (
http://opencores.org/project,sdram_controller) project as a reference design. Also, Xilinx has an IP core for that. But I don't know if it is free. (Just going to chek it later today).
Again, what do you think? Is there something in particular you'd like to
work on? You mentioned schematics, but I'd also be very grateful for
help with PCB layout and routing. There are a few layout issues,
especially given the two-layer PCB, like maintaining the signal
integrity of the high-speed (480MHz) USB signals, and making sure the
FPGA has a solid ground and enough decoupling capacitors. Luckily the
actual signal routing should be straightforward, being in general just
wide bus connections between the FPGA and adjacent components (SDRAM,
level-shifters, FX2LP, SD-card slot).
I may help with PCB layout and routing. I am used to working with Altium's Designer software (that's what I use at my job).
But to be honest, I have a little experience with PCB routing.
That would be great that if one of the sides of the board have a solid ground plane. I think that it's a robust method
to avoid bad signal integrity.
For the USB signals, we may look at some sucessful reference design. I've colaborated to a PCIe project where we were really lost in the routing of the signals from the PCIe transceivers to the board fingers. Solution: reproduce the same physical routing as the PCIe development kit we had. I know it sounds kinda funny, but it's robust :)
Despite the fact that I don't feel like an experient HDL developer, it's my main activity.
Also do you have any objection to keeping the project open-source
(GPL'd)? And do you have a development platform preference? In general I
try to make my code build on Windows, Linux and MacOSX, but I have not
yet built this particular project (i.e the GDB backend, etc) on any
platform other than i686 Linux.
That's great making this projcet open-source.
I mostly develop things under Windows. Sometimes I switch to Linux and try porting things from Windows. I have no preference but I am used to working with FPGA tools under Windows. So it's more comfortable to do everything under Windows, that way I don't have to keep switching between operational systems during the development. Anyway, I know that those FPGAs tools are released for Linux too, So I don't mind trying them.
Personally I'm concentrating on a cartridge that is as cheap as possible
but which achieves these two goals:
* When powered up standalone (i.e without a host computer attached), the
MegaDrive will run a menu program from SD-card, allowing you to choose a
game by scrolling through the list using a standard MD controller.
* When connected to a host computer (Windows, Linux or MacOSX) you can
load code over USB and connect a GDB-based debugger to do
single-stepping and breakpoints, etc.
That's pretty awesome :)
Are there any bits of functionality beyond that which you would like to
see?
You mentioned you found it difficult in your CPLD-based project to meet
the timing requirements of VDP DMA accesses. Do you know what these
timing requirements actually are, quantitatively? I guess I've been
working under the assumption that any accesses to the cartridge memory
will have similar timing requirements to those of a real 68000. So far
that assumption has served me well, but in all honesty I don't know
whether I'm one hundred metres from the cliff edge or just one metre
from it, if you know what I mean!
I can't tell you quantitatively. But let me try explaining how my old system works and then present my theory concerning the DMA.
Below there is a pseudo hardware behavior description:
There is a timer, it will set a flag every refresh period (~15us).
If (timer flag) then do a refresh cycle; else
If (mega drive access) then do a read cycle; else
If (timer flag) and (mega drive access) then do a read cycle followed by a refesh cycle (that's a special cycle supported by FPM/EDO ADRAMs).
Only clear the timer flag if the refresh cycle was performed, in order to perform a refresh cycle that was issued during a mega drive only access.
:end
So, at first sight, system behavior is good. But if you leave a game running for 4 hours, it will surelly crash. An incremental data loss happens.
I think that it happens because DMA cycles doesn't leave any space between the reads, thus my logic is not able to insert a refresh cycle during the whole DMA access.
Also, a friend of mine wrote a megadrive demo that just do not use DMA, it keeps on a loop playing music and doing some graphic effects. That demo has runned for 24 hours consecutively.
Other thoughts: my old cpld system was built around a breadboard, big wires, bad grounding - a real mess. At least it had decoupling capacitors everywhere :)
Today I have a 100 MHz digital oscilloscope, not that incredible bandwidth, but I hope I can get some quantitative results with it.
Regards,
Rafael.