Jump to content
IGNORED

Racing the Atari bus with a STM32F4 microcontroller


electrotrains

Recommended Posts

Hi All,

 

When I came across an article about emulating gameboy cartridges with a ST32F4 microcontroller (here), I was intrigued to see if the same could be done with the Atari. The gameboy cartridge bus is about half the speed of the Atari's (1MHz rather than 2MHz) so it seemed worth trying, though I wasn't too optimistic.

 

So early this year, I bought myself a ST32F4 Discovery board (about £12 from Farnell/RS) with the aim of doing some experiments - which I finally got round to doing last weekend!

 

In short, the answer is yes - its a bit tight, but I've sucessfully got the board to emulate an 8K cartridge (Deluxe Invaders.rom - my usual first test), which happily plays on the Atari.

 

post-41252-0-53733100-1474978113_thumb.jpg post-41252-0-14944200-1474978181_thumb.jpg

 

I initially tried using interrupts like the gameboy article (triggered on the rising edge of phi2), but when viewed on the oscilloscope it was a bit hit and miss and I never got this approach to work. So I ended up with a simple polling loop:

#define PHI2_RD (GPIOC->IDR & 0x0001)
#define S5_RD (GPIOC->IDR & 0x0002)
#define ADDR_IN GPIOD->IDR
#define DATA_IN GPIOE->IDR
#define DATA_OUT GPIOE->ODR
#define SET_DATA_MODE_IN GPIOE->MODER = 0x00000000;
#define SET_DATA_MODE_OUT GPIOE->MODER = 0x55550000;

int main(void)
{
    config_gpio_data(); /* PE{8..15} */
    config_gpio_addr(); /* PD{0..15} */
    config_gpio_sig(); /* PC{0..1} */

    uint16_t addr;

    SET_DATA_MODE_IN
    while (1)
    {
        // wait for s5 low
        while (S5_RD) ;
        SET_DATA_MODE_OUT
        // while s5 low
        while (!S5_RD) {
            addr = ADDR_IN;
            DATA_OUT = ((uint16_t)cart_rom[addr])<<8;
        }
        SET_DATA_MODE_IN
    }
}

What's the point?

 

Well, the STM32F407 is cheap (less than half the price of the FPGA I used with the Ultimate Cart), the pins are (in the main) 5V tolerant so no level converting required, and it has 168k of RAM on board, as well as 1megabyte of flash. The makes it perfect for producing a wide range of Atari cartridge (or PBI?) peripherals, as long as it was fast enough to keep up with the Atari bus - which it looks like it is.

 

I might have a go a making a simple SD card multicart with this, though it would probably be limited to 128k or maybe even 64k roms or XEX files. On the plus side, it would be simple to assemble, and cheap!

 

Robin

 

  • Like 19
Link to comment
Share on other sites

What I'd like to see done in a cartridge:

 

A JIT type system that generates 6502 code on the fly for faster games.

e.g. generate softsprites quickly through sequences like:

 

LDA $4040

STA $8000

AND #$3F

ORA #$2E

STA $4040

 

Rather than looking up sprite/mask data, since the code is externally generated, just execute immediate instructions rather than slower indexed or indirect ones.

Similarly the technique could be used for chasing the beam graphics and colour effects or digital sound.

 

Though of course the consideration to be weighed up is cost competitiveness with existing CPU accelerators and the Veronika cartridge.

  • Like 3
Link to comment
Share on other sites

A JIT type system that generates 6502 code on the fly for faster games.

e.g. generate softsprites quickly through sequences like:

 

Ehm - why?

It would be much faster just to offer the graphics memory from the cart side and let the µ-controller work full speed on it without the translation step to 6502 code.

Edited by Irgendwer
  • Like 1
Link to comment
Share on other sites

Well, the STM32F407 is cheap (less than half the price of the FPGA I used with the Ultimate Cart), the pins are (in the main) 5V tolerant so no level converting required, and it has 168k of RAM on board, as well as 1megabyte of flash. The makes it perfect for producing a wide range of Atari cartridge (or PBI?) peripherals, as long as it was fast enough to keep up with the Atari bus - which it looks like it is.

 

 

Nice! Some time ago I had the idea for a fully CPU replacement done with that Cortex. It could operate 100% compatible to the 6502 CPU (with undocumented instructions etc.). When applying a 'special' code sequence, a fast mode is activated:

Classic 2 cycle instructions only need one bus cycle ('clc', 'iny' etc.).

The zero page and stack lives inside the controller, boosting all operations working with this memory space.

So a 'pha', 'pla' could also be done in one cycle like a 'lda (zp),y' could as only for the instruction fetch the external bus is needed.

I think an overall performance boost >100% is possible with very high compatibility and very low costs.

Other project pointing in that direction: http://telmomoya.blogspot.de/2016/06/c64-software-cored.html

Edited by Irgendwer
  • Like 5
Link to comment
Share on other sites

Further progress! I've hooked up an SD card reader to the Discovery board.

 

Now I can put a 8k cartridge ROM file on the SD card which the Atari then boots. Interestingly, the microcontroller on the Discovery board is fast enough to read the 8k file from the SD card into its own RAM, then set RD5 high and the Atari boots straight into cart when powered up, even though the Discovery board is itself powered from the cartridge port.

 

I guess 16k carts are the next thing to try.

 

The only problem is that there are so many on-board peripherals on the Discovery that its tricky to find spare pins for my own purposes. Might make a cartridge PCB next with just the bare microcontroller and a SD card slot - would anybody be interested in one for their own development/playing?

 

Robin

 

EDIT - in the unlikely event that anybody is following along - I'm using this SD/FatFS library:

http://stm32f4-discovery.net/2014/07/library-21-read-sd-card-fatfs-stm32f4xx-devices/

Use SPI2/PinPack2 to avoid conflicts with the on-board accelerometer (at least I think that was the problem).

Edited by electrotrains
  • Like 11
Link to comment
Share on other sites

Very interesting project. I wouldn't dump the Disco board too quick, really could be interesting to use some of the on board features with the A8. I'm thinking about the audio codec, could almost have a (ARM) software Paula. Or a USB host.

Don't know if you are aware, but the F4 Disco board is at the heart of the current core for Midibox.org projects. http://ucapps.de/

Might be some libs of use.

Yogi

Edited by Van
  • Like 2
Link to comment
Share on other sites

EDIT - in the unlikely event that anybody is following along - I'm using this SD/FatFS library:

You wish ;)

We are following, but my guess is that it's just by reading this topic.

 

Is the speed of cpu on discovery board 84MHz ?

That should be around 100Mips and little over 50 instructions per Atari's cpu cycle ?

That's indeed tight for any complex address and data manipulation...

Are you familiar with Tomek's cartridge ? Think he used Microchip pic24 mcu... He also didn't do any addres decoding beside simple watching for only one address value. Works like cpu accelerator. Transmits function code and data over that one byte in sequence and returns result in the same way. Also with special display list (repeating that one address over whole screen) it can show "external" bitmap display.

  • Like 5
Link to comment
Share on other sites

Is it possible to use that board as a Covox for A8?

Well this midi sampler synth might be of interest

http://midibox.org/forums/topic/16242-sd-card-polyphonic-sample-player/?page=4

and the wiki (but out of date, as the code has been updated to the F4)

http://www.midibox.org/dokuwiki/doku.php?id=midibox_sd_card_sample_player

Now this wouldn't be impossible but the sampler project is built on the MIOS RTOS and as such would need extensions to read the A8 buss. The plus side is the A8 wouldn't have to push samples to the DAC; just send note on /note off type messages.

If a 0xD6xx address (aka Covox style) is used as a port to the Disco board, seem like it might be possible.

Yogi

Link to comment
Share on other sites

You wish ;)

We are following, but my guess is that it's just by reading this topic.

 

Is the speed of cpu on discovery board 84MHz ?

...

As per STM

 

 

STM32F407/417 – 168 MHz CPU/210 DMIPS

So there is a little more head room :)

Yogi

  • Like 2
Link to comment
Share on other sites

  • 1 month later...

Hi All,

 

I've now pretty much completed this project to my satisfaction - I've got it running all ROM/CARs <=128k, and it also loads XEX files (<=128k) using the loader that flashjazzcat wrote for the Ultimate Cart. I've called it the UNO Cart, since it only has one component!

 

Essentially its a mini (and less powerful) version of the Ultimate Cart, since it can't do the bigger ROMs (its important to note there is no support for 8mbit AtariMax). It does however run 8k/16k carts, XEGS, AtariMax 1mbit, Williams, Bounty Bob, OSS and a heap more types. If it works on the Ultimate Cart and is <=128k, it should work here.

 

Anway, there's a nice menu for browsing the SD card, a full/partial filename search feature (across all sub-dirs) and the cart can be disabled for normal SIO boots to avoid removing the cartridge and so avoid wear and tear. There's also a reset button on the cartridge which returns to the menu.

 

post-41252-0-13508300-1480160064_thumb.jpg post-41252-0-88016900-1480160073_thumb.jpg

I've also designed a simple and cheap 3d printed shell (not a proper cartridge case) so the board can be easily used in XL machines without worrying about the flaps. There's a ST Link header exposed, if you wanted to experiment with programming your own firmware.

 

I've got some spare boards of the final PCB design, so I'm curious if anybody might be interested in a completed cartridge?

The price is likely to be around £30 (about $34) uncased, or £35 cased, plus £2 P&P.

 

The design has only been tested on a few Atari's, so this is a bit of a beta test really.

 

Also - I'm just gauging interest at this point, rather than taking orders. I'll order the parts to complete the spare PCBs only if a few people are interested, since I've already spent quite a lot getting the project to this stage.

 

Robin

 

  • Like 9
Link to comment
Share on other sites

Looks great !

 

Any chance of sharing schematics for this ?

 

Hi Popmilo,

 

My plan is that the UnoCart will be fully open source, like the Ultimate Cart.

 

I am also intending to write up a "build it yourself" guide with only through-hole soldering required, using a discovery board and one of my cartridge port adapters. This was going to be an article for Excel Magazine #5, but I may just do it as a post here instead, depending on Robert's plans for future issues.

 

However, I'd like to sell a few first, to recoup costs.

 

Robin

Link to comment
Share on other sites

Does flash enabled cart support also provide flash write?

Are the XEGS modes with cart-disable also supported?

 

A great project you have there!

 

Flash write - not supported. I thought about it, but I could only think of one title that makes use of this on AtariMax 1mbit carts (PacMan arcade) and it didn't seem worth the bother. I would also probably have to add another button to the PCB to initiate a save back to SD card since this can't be done in parallel with cartridge emulation.

 

XEGS with cart disable are supported, yes.

 

Robin

Link to comment
Share on other sites

Thanks Robin, your plan sounds good :)

 

I'm just interested how that one chip interfaces with cartridge port. What are the necessary signals and such.

I'm planing to do custom cartridge for my game project and this tech sounds most promising so far.

 

I'd be happy to discuss this - send me a PM?

 

This approach is probably perfect for one-off cartridge game projects and the PCB can be made even simpler (and cheaper) in this case. Plus there is a whole 1 megabyte of flash on the microcontroller (of which I'm only using a fraction for this project) - its a tiny bit too slow to be used directly by the atari bus, but could be paged in and out of the SRAM on the chip as required.

 

EDIT - for a minimal cartridge for game projects, the PCB + STM32F4 + passive components could probably be made for about £10. Which is probably not much more than a traditional EEPROM approach, but offering more capacity and flexibility with bank switching etc.

Edited by electrotrains
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...