Page 6 of 17

Re: UMDK manufacturing, part 2: Software

Posted: Thu Dec 03, 2015 9:23 pm
by Montserrat
ok, waiting for next step.

Re: UMDK manufacturing, part 2: Software

Posted: Fri Dec 04, 2015 4:57 am
by mikejmoffitt
I've been out of the loop, but my Firmware.bin is also 1280 bytes. I'm wondering if anyone would be willing to just upload binaries. I do not think it's necessary for us all to build the files expecting the same results, at least for the sake of verifying our hardware.

I did a visual inspection of mine and can't see anything wrong, so no solder bridge as far as I can tell. I'm still in the boat of having the MD not bring up TMSS or do anything. I'm rebuilding everything to see if it will turn out better. I am on Debian Stretch 64-bit .

EDIT: I looked over my logs, and it turns out a few steps failed in building parts of the project. I'm allowing my laptop to have a go at building it so I'll see how that goes (it is about eight years old, maybe that's the trick! :roll: )

Re: UMDK manufacturing, part 2: Software

Posted: Fri Dec 04, 2015 9:25 am
by Burbruee
mikejmoffitt wrote:my Firmware.bin is also 1280 bytes.
I'm guessing the menu program failed to build. Try building it manually and see why it fails, execute ./rel in its folder. But probably it failed because some tools for the crosscompiler didn't get built right. I had the same problem on my arch linux, but on debian jessie the build was flawless.

Re: UMDK manufacturing, part 2: Software

Posted: Fri Dec 04, 2015 5:06 pm
by Grind
Attached mine. You won't be able to use ddd without the full toolchain though. There were a few different problems I had building on different distros.

Try running these 3 commands:

Code: Select all

7za
help2man
sudo apt-get install libtool-bin
If 7za is a bad command install "p7zip-full"
If libtool-bin doesn't exist remove it in the second installer line in x64.txt or x86.txt

Re: UMDK manufacturing, part 2: Software

Posted: Fri Dec 04, 2015 8:46 pm
by Montserrat
I supose now we need to get it run standalone, also it will be very nice if the kit could run the debugger in the nomad, its a very portable solution and includes the screen.

Nomad its a genesis 2 whithout a reset button, may be this is related.

Re: UMDK manufacturing, part 2: Software

Posted: Fri Dec 04, 2015 9:48 pm
by MintyTheCat
Montserrat wrote:I supose now we need to get it run standalone, also it will be very nice if the kit could run the debugger in the nomad, its a very portable solution and includes the screen.

Nomad its a genesis 2 whithout a reset button, may be this is related.
For now, it is better to stick to standard MD hardware. All tests were done with Chris' MD2 and some of my MD1 boards such as the M5PAL-VA4.
We did find along the way that some games worked fine for me and not for him and as such Chris modified the VHDL accordingly.
I know for a fact that the MD3 has many compatibility issues and that was not released in such large numbers as the MD1 and MD2 with the NOMAD being even less commonly found - so if you do find yourself with an issue you may be alone with it, so please stick to MD1 and MD2 for now for reasons of sanity maintenance :wink:

What is needed to be hosted somewhere is a decent MD hardware database that lists all the known types and tables listing which games fail and indeed if UMDK is known to work on a given MD hardware version and if there are any issues.

Re: UMDK manufacturing, part 2: Software

Posted: Fri Dec 04, 2015 10:08 pm
by prophet36
Montserrat wrote:I supose now we need to get it run standalone
The debugger relies on the fact that the monitor program is loaded from flash during startup. If that load process is failing, then the monitor will not run correctly. Luckily, you now have all the necessary tools to check this. Try using gordon & spi-talk.xsvf to write a 512MiB file random-data file to flash again (like we did in the initial setup process), but this time rather than reading it back using gordon, write a little ROM that gets the MegaDrive to read it, and copy it to a block of SDRAM starting at 0x400000, then use sigtest.xsvf and loader to run it, then use loader to read the result out of SDRAM. The flash chip and the SD-card are both connected to the FPGA on a general-purpose SPI bus. There are two hardware registers for the SPI interface, SPICON=0xA13004 and SPIDATW=0xA13000. You can use them to read from flash with some code like this:

Code: Select all

    SPIDATW  = 0x0000 /* SPI word read/write */
    SPICON   = 0x0004 /* SPI interface control */
    bmTURBO  = (1<<0) /* 0x0001 */
    bmFLASH  = (1<<2) /* 0x0004 */

    .org     0x000000

    dc.l     0x000000  /* Initial SSP */
    dc.l     0x000008  /* Initial PC */
boot:
    move.b   0xA10001, d0
    andi.b   #0x0f, d0
    beq.s    1f
    move.l   #0x53454741, 0xA14000  /* write "SEGA" to TMSS register */
1:  lea      0xA13000, a0
    lea      0x400000, a1
    move.w   #(bmTURBO | bmFLASH), SPICON(a0)
    move.w   #0x0300, SPIDATW(a0)   /* 03 = "read flash" command; next three */
    move.w   #0x0000, SPIDATW(a0)   /* bytes set the read offset to zero. */
    move.w   #0xFFFF, SPIDATW(a0)   /* get first two bytes */

    /* Load 32 bytes from flash, copy them to SDRAM at 0x400000 */
    move.w   #15, d0
2:  move.w   SPIDATW(a0), (a1)+
    dbra     d0, 2b

    /* OK, we're finished copying, so go into an infinite loop */
3:  bra.s    3b
Note that I haven't tried that code, so you may need to debug it by following its execution in the trace. Also, this only reads 32 bytes (16 words) from the bottom of the flash. It would be good to verify reading the whole 512KiB of flash. For that you'll need to roll four loops with 65536 iterations each. Remember that the register used in the dbra instruction should be initialised to one less than the desired number of iterations, so for 65536 iterations you want to initialise it to 0xFFFF. Then you can use "loader" to read the result back out of SDRAM and compare it with the original data written to flash.

Let me know how you get on!

Re: UMDK manufacturing, part 2: Software

Posted: Fri Dec 04, 2015 10:23 pm
by Montserrat
prophet36 wrote:LAST POST
Didnt know you were able to speak intergalactic. Sorry i did not catch a single word. I'm afraid that i can be only usesful as a test dummy.

Sure im learning a lot, but i cant eat a whole mamuth in one day :D

Re: UMDK manufacturing, part 2: Software

Posted: Fri Dec 04, 2015 11:51 pm
by prophet36
Montserrat wrote:Sorry i did not catch a single word.
Does someone else with more programming experience want to give it a go? I just tried the "flash-read" code I posted and it does work (I just copy-pasted it over test.s and ran "make test.bin" to run it through the assembler).
Anne Isabella Ritchie wrote:If you give a man a fish he is hungry again in an hour; if you teach him to catch a fish you do him a good turn.
As I said before, I'd rather not continue telling people exactly what to type. I'd much prefer to see people experimenting with the tools (flcli, gordon, loader, etc) and trying to run their own simple assembly-language programs, learning to interpret the trace dumps and reading back execution results stored in SDRAM using the loader utility. Obviously I'm happy to answer specific questions like "how do I use loader's -r option?" and "why does the trace show that the word following a move #0x2700,sr instruction is read twice?", but I'm not prepared to answer more "tell me what to type now" questions. I hope you all understand.

Re: UMDK manufacturing, part 2: Software

Posted: Sat Dec 05, 2015 12:42 am
by Montserrat
That was rude. Seriously.

Re: UMDK manufacturing, part 2: Software

Posted: Sat Dec 05, 2015 12:57 am
by prophet36
Montserrat wrote:That was rude. Seriously.
I apologise. I certainly did not intend it to be rude.

Re: UMDK manufacturing, part 2: Software

Posted: Sat Dec 05, 2015 8:37 am
by MintyTheCat
prophet36 wrote:
Montserrat wrote:Sorry i did not catch a single word.
Does someone else with more programming experience want to give it a go? I just tried the "flash-read" code I posted and it does work (I just copy-pasted it over test.s and ran "make test.bin" to run it through the assembler).
Anne Isabella Ritchie wrote:If you give a man a fish he is hungry again in an hour; if you teach him to catch a fish you do him a good turn.
As I said before, I'd rather not continue telling people exactly what to type. I'd much prefer to see people experimenting with the tools (flcli, gordon, loader, etc) and trying to run their own simple assembly-language programs, learning to interpret the trace dumps and reading back execution results stored in SDRAM using the loader utility. Obviously I'm happy to answer specific questions like "how do I use loader's -r option?" and "why does the trace show that the word following a move #0x2700,sr instruction is read twice?", but I'm not prepared to answer more "tell me what to type now" questions. I hope you all understand.
I will try this out and put a Test-ROM together.
The other thing that some how I had not gotten around to was that it would be really great if UMDK's Memory-Map could be put somewhere for reference as I actually do not know the answer to things quickly so it would be a big help if we could perhaps have it added to UMDK's GitHub repro.
Montserrat wrote:That was rude. Seriously.
Ok, I can see both sides of this but essentially: Chris can coach people and provide answers to UMDK but he cannot teach people how to program the MD and the Motorola 68000 in general. I realise that this might be a little over whelming for some, and they may need to hang back a bit, get the books out and teach themselves more about the 68K as a chip, an architecture and indeed its machine language and then understand the MD better to know what is going on.

Me and Chris have been with the 68K since we were teenagers back in the late 80s to early 90s so do not worry that this stuff sounds involved for now: Assembly is very, very simple and really it is too simple that it throws people a bit but just stick at it, Montserrat and make lots of mistakes and try things out as it really is the best way to learn.

If you have specific MD or 68K questions just PM me or send me an E-Mail and I will try my best to sort you out. Chris is quite a busy chap supporting FPGA-Link (which UMDK uses), has some other projects and a day job so his time is often precious and short so just ask me or some people on the programming section of the forum :wink:

Re: UMDK manufacturing, part 2: Software

Posted: Sat Dec 05, 2015 12:07 pm
by prophet36
MintyTheCat wrote:The other thing that some how I had not gotten around to was that it would be really great if UMDK's Memory-Map could be put somewhere for reference
Good idea. Here goes:

SSF2 Banking
Each UMDK cart has 8 or 16 MiB of physical SDRAM. This is accessible contiguously by the host using the "loader" command's "-r" and "-w" options. The SDRAM can always be read and written, irrespective of whether the MD is executing or not. This 16MiB can be mapped into the MegaDrive's ("logical") address space using banking registers. The bare minimum to support SSF2 is to implement the bank-switching registers specified by SEGA, but UMDK extends those by splitting the 16MiB of physical SDRAM into 32 pages, 512KiB each, any of which can be mapped into any of the 512KiB logical ranges in the bottom 4MiB of the MegaDrive address-space (except the bottom 512KiB, which is hard-coded to SDRAM page 0), and into any of the 512KiB ranges in the 4MiB above that (except the 512KiB at 0x400000, which is hard-coded to SDRAM page 31, and is reserved for use by UMDK). The default on power-up is a 1:1 mapping of logical to physical addresses, except in the logical range 0x400000 - 0x47FFFF as I mentioned.

Rather than use new registers I have just reused the existing SSF2 registers, with bit 6 selecting whether to affect the first or the second 4MiB range. Here are some examples:

Ex 1: Map SDRAM page 31 at 0x080000 - 0x0FFFFF

Code: Select all

move.b #0x1F, 0xA130F3
Ex 2: Map SDRAM page 0 at 0x380000 - 0x3FFFFF

Code: Select all

move.b #0x00, 0xA130FF
Ex 3: Map SDRAM page 1 at 0x480000 - 0x4FFFFF

Code: Select all

move.b #0x41, 0xA130F3
Ex 4: Map SDRAM page 2 at 0x780000 - 0x7FFFFF

Code: Select all

move.b #0x42, 0xA130FF
The first two examples are specified by SEGA; the latter two are UMDK's proprietary extensions. So you can map any of the 32 SDRAM 512KiB pages into any of the the seven SEGA-specified regions, and into any of the seven additional regions defined by UMDK:

Code: Select all

SSF2 REGISTERS

   -------------------------------------------------------
  | Register  |        D6=0         |        D6=1         |
  |-----------|---------------------|---------------------|
  | 0xA130F3: | 0x080000 - 0x0FFFFF | 0x480000 - 0x4FFFFF |
  | 0xA130F5: | 0x100000 - 0x17FFFF | 0x500000 - 0x57FFFF |
  | 0xA130F7: | 0x180000 - 0x1FFFFF | 0x580000 - 0x5FFFFF |
  | 0xA130F9: | 0x200000 - 0x27FFFF | 0x600000 - 0x67FFFF |
  | 0xA130FB: | 0x280000 - 0x2FFFFF | 0x680000 - 0x6FFFFF |
  | 0xA130FD: | 0x300000 - 0x37FFFF | 0x700000 - 0x77FFFF |
  | 0xA130FF: | 0x380000 - 0x3FFFFF | 0x780000 - 0x7FFFFF |
   -------------------------------------------------------
The 0x400000-0x47FFFF logical range is analogous to the 0x000000-0x07FFFF logical range, which SEGA specifies as fixed (not bankable). The difference is, whilst the 0x000000-0x07FFFF range is fixed to SDRAM bank 0, the 0x400000-0x47FFFF range is fixed to SDRAM bank 31, which I'm claiming for use by the UMDK monitor. That gives game developers 15½ MiB to play with, which is hopefully enough!

SPI Controller
The SPI controller allows you to read and write to the flash and SD-card. There are three registers, SPIDATW=0xA13000, SPIDATB=0xA13002 and SPICON=0xA13004. The SPICON register looks like this:

Code: Select all

SPICON (0xA13004)

  +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  |15|14|13|12|11|10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0|
  +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
   \_________________________________/  |  |  |  |
                    |                   |  |  |   \ TURBO
         RESERVED (MUST BE ZERO)        |  |  |
                                        |  |   \ SUPPRESS
                                        |  |
                                        |   \ FLASHCS
                                        |
                                         \ SDCS
The TURBO bit allows you to select the SPI clock rate (1=24MHz, 0=400kHz). The SUPPRESS bit is not used, and should be set to zero. Lastly, the FLASHCS bit selects the UMDK's 512KiB boot flash, and the SDCS bit selects the SD-card.

There are two data registers, one for word-access and another for byte access. See the example code from a couple of posts back for an example of reading the flash using SPIDATW and the flash chip's 0x03 "read bytes" command (see page 25 of the M25P40 datasheet). Basically, word-writes to SPIDATW cause that word to be sent out on the SPI bus. Word-reads from SPIDATW read the last word received from the SPI bus. As a convenience, reads also trigger a clock-out of 0xFFFF, so you can read from flash in a tight loop (~3MiB/s in turbo mode). Note that there is no way to check whether the SPI hardware has finished sending/receiving a word; you have to insert NOPs if necessary to ensure you don't try to give the SPI controller more work to do whilst it's still busy. This is partly laziness, and partly for performance (i.e it allows a tight dbra-loop containing just one instruction [e.g move.w SPIDATW(a0), (a1)+] to read data from flash). The problem with the SPIDATW register is it only supports word-wide accesses. That's what SPIDATB is for - it behaves in exactly the same way, but for individual bytes.

If you're accessing the SD-card you should probably look at the low-level driver and the FAT32 implementation in the menu program, rather than implementing your own code at the hardware-register level. I'm happy to write proper docs for these APIs if someone's actually interested.

Soft Reset
There's a register at 0xA13006 which is a little tricky. It allows the MegaDrive to do a hard reset from software. It's used in the trap #0 handler of the menu program to allow the newly-loaded game to be started as if from power-on. You use it by writing the magic number 0xDEAD to 0xA13006.

Flash Boot Process
The first-stage bootloader lives in a small ROM in the FPGA. Its sole purpose is to start the second-stage bootloader by reading 256 bytes from flash address 0x060000 into WRAM at address 0xFF0000, and jumping into it.

The second-stage bootloader loads 1024 bytes of monitor code from flash starting at 0x060100 into SDRAM at 0x400000, then it loads the next 512 bytes from flash (making up the menu program's vectors and cart metadata) into SDRAM at 0x000000, then it loads next ~64KiB from flash (making up the actual code of the menu program) into SDRAM at 0x420200 and starts it running. The reason the menu program is loaded so high is because it needs to be able to load games without overwriting itself. The menu program itself uses the banked logical range 0x480000 - 0x4FFFFF to load the selected game ROM, but that range is free for use after loading is complete.

Monitor Program
The monitor program is loaded by the flash-boot sequence at logical address 0x400000. It is the thing which actually implements the gdb bridge, by intercepting the 68000's single-step and illegal-instruction vectors. It uses the range 0x400400 - 0x410447 for maintaining the communication with gdb. So technically the range 0x410448 - 0x47FFFF is free, but I'm claiming it as UMDK-reserved, so writing to it will result in undefined behaviour.

I think that's everything. Let me know if it's unclear and I'll re-work it.

Re: UMDK manufacturing, part 2: Software

Posted: Sun Dec 06, 2015 4:46 am
by Nemesis
Wow, lots of great info here! I've been waiting for the software setup part of this project. I've got a cart assembled and waiting for setup. It's in storage right now due to some moving, but as soon as I have access to it again, I'll definitely be digging it out and giving this a go. It'll be great to be easily able to capture info on bus access cycles without having to resort to a logic analyzer.

Re: UMDK manufacturing, part 2: Software

Posted: Mon Dec 07, 2015 12:07 am
by Montserrat
MintyTheCat wrote: Chris can coach people and provide answers to UMDK but he cannot teach people how to program the MD and the Motorola 68000 in general. I realise that this might be a little over whelming for some, and they may need to hang back a bit, get the books out and teach themselves more about the 68K as a chip, an architecture and indeed its machine language and then understand the MD better to know what is going on.
I did not asked for such thing.

How to run the tools <<<-------------->>> How to program 68k or MD in general.

Knowing how to code or the secrets of the MD, its not our bussiness. But making the UMDK a working tool out of the box it is.

My goal in this thread is end with a reliable kit you can order, and then, reading a PDF instruction manual (or a post in this forum), be able to setup, run and do some basic operations.

If im not mistaken, UMDK its a developer tool and the star feature is be able to peek at the source code and making changes "on the fly" on the real hardware.

Chris demostrated in his video that exactly but he asumed everyone know how to use his tools and other tools like DDD. How nice and complete would be a single example of finding an adress in the source code, and then replacing the value to see some change, like the infinte lives hack or may be something simpler like changing a pallete color.

This is important, because when we share the manufacturer to public and some people start ordering will be lots of questions from users...so better to stay simple, concise, clear. You bought a kit, you have a manual, you have an example.This will save Chris and others tons of MP, posts, emails and explanations.

I hope you get the idea.


I'm not engineer, but you can count on me, i know how the MD works internaly (more or less) i can do testing and i have tons of hardware.