Jump to content

Photo

Racing the Atari bus with a STM32F4 microcontroller

stm32f4 cartridge

132 replies to this topic

#1 electrotrains ONLINE  

electrotrains

    Moonsweeper

  • 300 posts
  • Location:Scotland

Posted Tue Sep 27, 2016 6:12 AM

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.

 

stm32f4disco cart2.jpg stm32f4disco cart.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

 



#2 Rybags OFFLINE  

Rybags

    Gridrunner

  • 15,997 posts
  • Location:Australia

Posted Tue Sep 27, 2016 6:47 AM

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.



#3 Irgendwer OFFLINE  

Irgendwer

    Stargunner

  • 1,443 posts
  • Location:Germany

Posted Tue Sep 27, 2016 12:41 PM

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, Tue Sep 27, 2016 12:59 PM.


#4 Irgendwer OFFLINE  

Irgendwer

    Stargunner

  • 1,443 posts
  • Location:Germany

Posted Tue Sep 27, 2016 12:55 PM

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.blo...ware-cored.html


Edited by Irgendwer, Tue Sep 27, 2016 1:00 PM.


#5 sanny OFFLINE  

sanny

    Moonsweeper

  • 358 posts
  • Location:Bavaria

Posted Tue Sep 27, 2016 6:18 PM

Cool



#6 popmilo OFFLINE  

popmilo

    Stargunner

  • 1,570 posts
  • Location:Senta, Srbija

Posted Wed Sep 28, 2016 3:07 PM

Looks like a good thing!

Please share any new info and technical details... Would love to see timing diagrams for that main loop and signals on Atari port...



#7 electrotrains ONLINE  

electrotrains

    Moonsweeper

  • Topic Starter
  • 300 posts
  • Location:Scotland

Posted Fri Sep 30, 2016 7:35 AM

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-disco...32f4xx-devices/

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


Edited by electrotrains, Fri Sep 30, 2016 7:38 AM.


#8 Larry OFFLINE  

Larry

    River Patroller

  • 4,083 posts
  • Location:U.S. -- Midwest

Posted Fri Sep 30, 2016 8:54 AM

All of you hardware guys are amazing!

-Larry



#9 Van OFFLINE  

Van

    Moonsweeper

  • 285 posts
  • Location:Maryland

Posted Fri Sep 30, 2016 11:20 AM

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, Fri Sep 30, 2016 11:20 AM.


#10 popmilo OFFLINE  

popmilo

    Stargunner

  • 1,570 posts
  • Location:Senta, Srbija

Posted Fri Sep 30, 2016 1:40 PM

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.



#11 lemiel OFFLINE  

lemiel

    Moonsweeper

  • 279 posts
  • Location:Tychy, Poland

Posted Sat Oct 1, 2016 12:39 AM

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

#12 Van OFFLINE  

Van

    Moonsweeper

  • 285 posts
  • Location:Maryland

Posted Sat Oct 1, 2016 8:24 AM

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

Well this midi sampler synth might be of interest

http://midibox.org/f...-player/?page=4

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

http://www.midibox.o...d_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



#13 Van OFFLINE  

Van

    Moonsweeper

  • 285 posts
  • Location:Maryland

Posted Sat Oct 1, 2016 9:24 AM

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



#14 electrotrains ONLINE  

electrotrains

    Moonsweeper

  • Topic Starter
  • 300 posts
  • Location:Scotland

Posted Sat Nov 26, 2016 5:36 AM

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.

 

P1150180.jpg P1150189.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

 



#15 DjayBee ONLINE  

DjayBee

    Moonsweeper

  • 341 posts
  • Location:Stuttgart, Germany

Posted Sat Nov 26, 2016 5:41 AM

I'm in for a cased one



#16 rdea6 OFFLINE  

rdea6

    River Patroller

  • 2,782 posts
  • Location:Arizona USA

Posted Sat Nov 26, 2016 5:44 AM

Yes I am interested in one Cart with shell.



#17 electrotrains ONLINE  

electrotrains

    Moonsweeper

  • Topic Starter
  • 300 posts
  • Location:Scotland

Posted Sat Nov 26, 2016 5:46 AM

Some further pictures:

 

P1150191.jpg P1150190.jpg



#18 Brentarian ONLINE  

Brentarian

    Moonsweeper

  • 456 posts
  • Location:Columbus, Georgia USA

Posted Sat Nov 26, 2016 8:37 AM

I am also interested in a cased one.

#19 popmilo OFFLINE  

popmilo

    Stargunner

  • 1,570 posts
  • Location:Senta, Srbija

Posted Sun Nov 27, 2016 5:05 AM

Looks great !

Any chance of sharing schematics for this ?



#20 Wrathchild OFFLINE  

Wrathchild

    River Patroller

  • 2,135 posts
  • Location:Reading, UK.

Posted Sun Nov 27, 2016 5:21 AM

Does flash enabled cart support also provide flash write?
Are the XEGS modes with cart-disable also supported?

A great project you have there!

#21 electrotrains ONLINE  

electrotrains

    Moonsweeper

  • Topic Starter
  • 300 posts
  • Location:Scotland

Posted Sun Nov 27, 2016 5:31 AM

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



#22 electrotrains ONLINE  

electrotrains

    Moonsweeper

  • Topic Starter
  • 300 posts
  • Location:Scotland

Posted Sun Nov 27, 2016 5:34 AM

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



#23 popmilo OFFLINE  

popmilo

    Stargunner

  • 1,570 posts
  • Location:Senta, Srbija

Posted Sun Nov 27, 2016 5:34 AM

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.



#24 electrotrains ONLINE  

electrotrains

    Moonsweeper

  • Topic Starter
  • 300 posts
  • Location:Scotland

Posted Sun Nov 27, 2016 5:39 AM

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, Sun Nov 27, 2016 5:43 AM.


#25 electrotrains ONLINE  

electrotrains

    Moonsweeper

  • Topic Starter
  • 300 posts
  • Location:Scotland

Posted Sun Nov 27, 2016 5:53 AM

One further thought - Its perfectly possible to write to the on-chip flash from software, so even without an SD card, a cartridge game could save state back to the cartridge.







Also tagged with one or more of these keywords: stm32f4, cartridge

0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users