CPU socket plugin tester

Mitchell Gant

Active member
vacBacker
Feedback
2 (100%)
Credits
888CR
guddler said:
Nice! Whats in your board again? You seem to be doing an awful lot in there for a pic. I always thought they were little things and yet here you are emulating CPUs, storing ROMs and now emulating mathboxes!!

I badly need to get my head back into BZ. I've got a number of them to fix and a cabaret just waiting for a board
smiley6.gif

Most people seem to think that a PIC is a small 8 bit micrcontroller, which true with the old PIC16C54 when Microchip started way back.

But they now have a very large range of micros covering 8, 16 and 32 bit cores. In my day job we use mostly two devices, the 8 bit PIC18F2585 and the 16 bit dsPIC33FJ256MC710A, mostly chosen for their CAN networking ability. http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en546066

As I already have bootloader and serial port terminal code running under FreeRTOS ( http://www.freertos.org/ ) then it was an ideal choice for me to play around with at home to see what I could make it do. For anyone else it's probably a fairly BAD choice of micro for a CPU emulator!

It's running at 40MHz internally, so I get a 25nS cycle time with most instructions executing in 1 cycle. With a bit of careful coding I've got a reasonable 6502 emulator running, written mostly in C and based on code written by Larry Bank (http://www.retrogames.com/larry_bank_interview.html ). Even so I'm banging up against the ceiling of performance, especially when it has to read or write to the game PCB memory space. Then it has to sit in a tight loop to synchronise with the game PHI2 clock signal, then so the read or write on the next cycle. So any game memory access takes TWO game cycles, usually at 1.5MHz for Atari stuff.

For Battlezone I looked at the MAME source code for the mathbox ( http://mamedev.org/source/src/mame/machine/mathbox.c.html ) and saw that most of it is fairly simple and quick register stores. The real meat of it is something like this:

mb_temp = ((INT32) -REG1) * ((INT32) REG5);
REG7 = mb_temp >> 16;
mb_q = mb_temp & 0xffff;

Now that compiles to rather a lot of instrucions in the dsPIC compiler, unlike the Intel/PC compiler it is intended for. However the dsPIC has some DSP functionality built in with a 40 bit accumulator and hardware 16x16 multiply, so that can be translated to this:

result = __builtin_mpy(-REG1, REG5, NULL, 0, 0, NULL, 0, 0);
REG7 = ACCAH;
mb_q = ACCAL;

Which produces:

213:result = __builtin_mpy(-REG1, REG5, NULL, 0, 0, NULL, 0, 0);
07FBC 804055 mov.w 0x080a,w5
07FBE 804010 mov.w 0x0802,w0
07FC0 EA0200 neg.w w0,w4
07FC2 C00113 mpy w4*w5,a
214: REG7 = ACCAH;
07FC4 800120 mov.w 0x0024,w0
07FC6 884070 mov.w w0,0x080e
215: mb_q = ACCAL;
07FC8 800110 mov.w result,w0
07FCA 9FBFF0 mov.w w0,[w15-2]

This will do a 16x16 bit signed multiply in 200nS, which I think compares pretty well with the original Atari mathbox.

It's far from perfect and needs a lot more work, but the fact I saw a tank on the screen was pretty exciting. Well it was for me, my girlfriend barely looked up from playing Assassins Creed and just shook her head in pity...
 

guddler

Busting vectors like it's 1982!
vacBacker
Feedback
10 (100%)
Credits
4,058CR
Mitchell Gant said:
It's far from perfect and needs a lot more work, but the fact I saw a tank on the screen was pretty exciting. Well it was for me, my girlfriend barely looked up from playing Assassins Creed and just shook her head in pity...

smiley36.gif
Nearly spat out my tea then!!

I need to divulge the bulk of this reply later when I can get my head round it
smiley4.gif
 

Geekfix

Newbie
Feedback
1 (100%)
Credits
25CR
Did this end up as a full blown project?

Would like to try implementing this, currently having a rare old fight with Asteroids Deluxe with phantom RAM error bepp beep beep boop, all the RAM I have fitted is fine..

Cheers!
 
Top