MAMEWorld >> Programming
Previous thread Previous  View all threads Index   Next thread Next   Threaded Mode Threaded  

Pages: 1

drewcifer
One bad Mutha-(shut yo' mouth!)
Reged: 07/01/04
Posts: 428
Loc: Sweden
Send PM


Memory banking in Polygonet Commanders
#73875 - 05/10/06 02:22 AM


'Ello.

I'm attempting to finally remove a hack in the Polygonet Commanders driver that lets the dsp56k pass the memory tests. The first 3 memory tests are easy, but the fourth one seems to test some memory banking hardware which is a little bit confusing to me. I was wondering if anyone had any suggestions.

A description of the behavior is as follows :

There are two main sections to memtest 4. In the first section a bunch of RAM is written, in the second it's read back and checked. The reading is done exactly the same way as the writing (same bits are twiddled, etc). Since the reading expects the same bits, I'll leave that out of the description.

Each section has two loops. During each of these loops, the bits of a generic port of the dsp56k (addr ffe3) are twiddled in a manner consistent with what I believe to be memory banking. There seems to be a trick in here though.

Here's a rundown of what happens :

MEMTEST 4 (the writes to memory)
--------------------------------------------------
* First, ffe3 is set to 0020
* The first loop:


for (i = 0; i < 8; i++)
{
write test data to the range 0x8000-0xbfff
add 4 to ffe3
}


Because of the "add 4," ffe3's bits 001c are changed for each iteration of the loop. In other words (I think), 001c are the bits controlling a memory banking device, and it changes them each time around. Implementing this like a memory bank in MAME works quite well - it checks properly when verified in section 2.

The trick is in the second loop.

* First, bit 0002 of ffe3 is set (bits 001c of ffe3 are left as 111).
* The second loop :


for (i = 0; i < 2; i++)
{
for (j = 0; j < 2; j++)
{
write from 6000 to 6fff
write from 7000 to 7fff

for (k = 0; k < 2; k++)
{
write from 8000 to ffbf
flip bit 0001 of ffe3 ;
}

flip bit 0100 of ffe3 ;
}

flip bit 0080 of ffe3 ;
}


Nothing too crazy, there seem to be 3 more bits (0181) in ffe3 that control another banking device (strange that 6000-6fff and 7000-7fff aren't written when bit 0001 is twiddled, but oh well). But there's one problem : that inner loop writes at 0x8000!

0x8000 was part of the first loop's test... So either the memory from 8000 to bfff is switched based on both banking devices (a total of 6 bits of banking), or something else is going on...

I think that "something else" has to do with bits 0020 and 0002 of ffe3. Seems like 0020 is initially switched on before the first loop, then 8000-bfff change based on the first banking bits (001c). Then, before the second loop, bit 0002 is switched on and 8000-ffbf change based on the next banking bits (0181). If so, is it possible (hardware wise) that 0002 can override the banking device used in the first loop and route all memory to another physical location?

And if so, how would I best implement this in MAME? It doesn't seem particularly straightforward.

Also, I left out one other sticky point. Memory from c000 to dfff is shared between the dsp56k and the 68020. This is verified to be the case when ffe3 is 0020. Since loop 2 writes from over this region (8000-ffff), I wonder what happens to the shared memory at c000? I'm thinking if 0002 is set in ffe3, c000-dfff is not the shared memory (thus encouraging the theory that bit 0002 switches physical banks altogether), but the game doesn't get far enough to really give me any proof of this.

So yeah, thanks for reading and thanks for you comments in advance! There's a good chance I'm thinking about this all wrong too, so please don't let my description lead you too far astray .

Andrew

Edited by drewcifer (05/10/06 05:02 AM)



R. Belmont
Cuckoo for IGAvania
Reged: 09/21/03
Posts: 9716
Loc: ECV-197 The Orville
Send PM


Re: Memory banking in Polygonet Commanders new [Re: drewcifer]
#74086 - 05/11/06 09:21 PM


A few things aren't clear here.

For the first test, ffe3 is always 0x0020 | (whatever), right? And is 0x0020 set for the second test?

Also, what does the code look like that tries to verify these results? The banking in the second test definitely looks to me like double buffers for the display list (or possibly 2 lists double-buffered: one from 6000-6fff, the other from 7000-7fff given that there are 2 pairs of polygon chips on the PCB).



drewcifer
One bad Mutha-(shut yo' mouth!)
Reged: 07/01/04
Posts: 428
Loc: Sweden
Send PM


Re: Memory banking in Polygonet Commanders new [Re: R. Belmont]
#74096 - 05/11/06 10:52 PM


Thanks for the response Arbee! And thanks for reading all that junk

> A few things aren't clear here.

Understood - I can totally see where I didn't explain things well enough. I'll clarify as best I can...

> For the first test, ffe3 is always 0x0020 | (whatever), right?

Correct. Actually, ffe3 requires one more fact to explain the full story.

When the proc first fires up, ffe3 is set to 0x0020 at around, eh, the 5th instruction, and it's left on for the rest of the execution. In other words, I believe they set this bit before they even think about doing memory accesses of any sort (I'll double check to make sure they don't touch external memory before that, but I'm 99.9% positive this is the case).

When the first loop of memtest 4 starts, a "mov 0020, ffe3" is executed just to make sure ffe3 is exactly how they want it, but since it was set that way in the CPU's init routine and noone else touched it, the instruction has "no effect"...

> And is 0x0020 set for the second test?

Correct again, sorry this wasn't clear at all. Just to be complete, a full list of the ffe3 values from my error.log are as follows :


(that "mov" instruction i described above)
DSP56K WRITING (0020) TO ffe3 (PC=00000154)

(the first loop)
DSP56K WRITING (0024) TO ffe3 (PC=0000021d)
DSP56K WRITING (0028) TO ffe3 (PC=0000021d)
DSP56K WRITING (002c) TO ffe3 (PC=0000021d)
DSP56K WRITING (0030) TO ffe3 (PC=0000021d)
DSP56K WRITING (0034) TO ffe3 (PC=0000021d)
DSP56K WRITING (0038) TO ffe3 (PC=0000021d)
DSP56K WRITING (003c) TO ffe3 (PC=0000021d)


(setting bit 0002 to prepare for the second loop)
DSP56K WRITING (003e) TO ffe3 (PC=00000159)

(the second, nested, loop)
DSP56K WRITING (003f) TO ffe3 (PC=00000167)
DSP56K WRITING (013e) TO ffe3 (PC=00000169)
DSP56K WRITING (013f) TO ffe3 (PC=00000167)
DSP56K WRITING (00be) TO ffe3 (PC=0000016b)
DSP56K WRITING (00bf) TO ffe3 (PC=00000167)
DSP56K WRITING (01be) TO ffe3 (PC=00000169)
DSP56K WRITING (01bf) TO ffe3 (PC=00000167)



> Also, what does the code look like that tries to verify these results?

I'll double-check when i get home tonight, but I believe the loop which does the checking is exactly the same as the loop which does the writing. Instead of a "jump to write subroutine" call though, there's a "jump to read-and-verify subroutine."

It may be too early to really get into this though, since each segment of memory is simply loaded with values that start with fff0 and decrease as the memory addr increases. When the memory is then checked, a register simply gets loaded with fff0, memory is read, values are compared, stuff is decremented, repeat. Dumb memory check i guess - just making sure the physical device is okay (?)...

Is that what you wanted to know? I'll respond if the mem read-and-verify loop is not the same later today or tomorrow...

> The banking in the second test definitely looks to me like double buffers
> for the display list (or possibly 2 lists double-buffered: one from 6000-6fff,
> the other from 7000-7fff given that there are 2 pairs of polygon chips on the PCB).

Brilliant! Seriously, good idea - that's why it's so nice having someone else look at it - bigger picture thinking...

Andrew



drewcifer
One bad Mutha-(shut yo' mouth!)
Reged: 07/01/04
Posts: 428
Loc: Sweden
Send PM


Re: Memory banking in Polygonet Commanders new [Re: drewcifer]
#74223 - 05/13/06 08:52 PM


> In other words, I believe they set this bit [ed: ffe3 & 0x0020] before
> they even think about doing memory accesses of any sort.

Just checked. Indeed - this is set before any external memory of any sort is touched by the dsp56k.

> I'll double-check when i get home tonight, but I believe the loop which does the
> checking is exactly the same as the loop which does the writing. Instead of a "jump
> to write subroutine" call though, there's a "jump to read-and-verify subroutine."

Confirmed. The loops are perfectly symmetric - the 'checking' loops just call a different jump to do memory reading instead of writing...

I'm guessing the behavior is reasonable, it just doesn't seem like MAME is set up to handle something like this. For now, I've implemented the bits at 0x001c as banking and have left the 0x0181 stuff as a hack. Whenever we get further with the driver, we'll probably have to fix things even more. Heh there still 4 bits in that output port which haven't been touched yet .

Is this the type of thing that makes Konami such devious hardware designers?

Andrew

* Maybe one way to handle this is to have two seperate memory maps and switch between them based on bit 0002 and 0020? Gonna' look to see if that's possible...



R. Belmont
Cuckoo for IGAvania
Reged: 09/21/03
Posts: 9716
Loc: ECV-197 The Orville
Send PM


Re: Memory banking in Polygonet Commanders new [Re: drewcifer]
#74233 - 05/13/06 11:13 PM


> Is this the type of thing that makes Konami such devious hardware designers?

Generally what makes them devious is that all of their custom chips are *extremely* flexible. The K056832 has 16 physical VRAM pages logically organized in a 2D grid, and you can specify for each page of a tilemap which physical VRAM page it is - they don't have to be contigious or anything, and in some of the more creative games they aren't :-) No other hardware is that flexible, including ST-V.

> * Maybe one way to handle this is to have two seperate memory maps and switch between
> them based on bit 0002 and 0020? Gonna' look to see if that's possible...

In this case, you're best off just defining each of the ranges (6000-6fff, 7000-7fff, 8000-fbff) as a READ32_HANDLER/WRITE32_HANDLER and auto_malloc()'ing the necessary RAM space. (MESS does it in cases like the Apple Lisa where there's a custom MMU (original Apple VLSI, not the PMMU Motorola sold for the 680x0) between the 68k and the bus and so nothing has a fixed physical address, and Sega System 16/18 are also similar :-)

Edited by R. Belmont (05/13/06 11:15 PM)



drewcifer
One bad Mutha-(shut yo' mouth!)
Reged: 07/01/04
Posts: 428
Loc: Sweden
Send PM


Re: Memory banking in Polygonet Commanders new [Re: R. Belmont]
#74435 - 05/16/06 12:27 AM


> Generally what makes them devious is that all of their custom chips are *extremely*
> flexible.

I can only imagine how long you stared at those tilemaps before realizing how that chip was laid out (great work)! I have noticed that if you're expecting something really weird, you can find these things more easily though. I'd imagine you're at that point with this Konamii stuff (thus your comments when working on Lethal Enforcers). Heh, I'm really looking forward to seeing what they do with their custom 3d chips ...

> In this case, you're best off just defining each of the ranges (6000-6fff, 7000-7fff,
> 8000-fbff) as a READ32_HANDLER/WRITE32_HANDLER and auto_malloc()'ing the necessary
> RAM space.

Well shiver me' timbers - I had no idea you could just do it like that! Seriously, up until I read what you wrote, I've been severely mistaken about how you need to register memory in an ADDRESS_MAP. I've always figured the only way to write to a piece of memory in a memory handler is having a BASE for it. I've also thought the only way to bank is by using the banking functions... I dunno why, there are tons of examples right in front of me that tell me otherwise, I just haven't paid enough attention. I was *really* getting confused when trying to figure out how to make a memory handler for a piece of banked, shared memory

Anyways, thanks Arbee. Everything works in the banking without the old hacks now...

Andrew



Haze
Reged: 09/23/03
Posts: 5245
Send PM


Re: Memory banking in Polygonet Commanders new [Re: R. Belmont]
#74438 - 05/16/06 01:53 AM


> > Is this the type of thing that makes Konami such devious hardware designers?
>
> Generally what makes them devious is that all of their custom chips are *extremely*
> flexible. The K056832 has 16 physical VRAM pages logically organized in a 2D grid,
> and you can specify for each page of a tilemap which physical VRAM page it is - they
> don't have to be contigious or anything, and in some of the more creative games they
> aren't :-) No other hardware is that flexible, including ST-V.
>

the whole physical page / logical page concept is very segaish anyway, system16 does it, and IIRC the Roz layers on ST-V are pretty insane in that way.

> > * Maybe one way to handle this is to have two seperate memory maps and switch
> between
> > them based on bit 0002 and 0020? Gonna' look to see if that's possible...
>
> In this case, you're best off just defining each of the ranges (6000-6fff, 7000-7fff,
> 8000-fbff) as a READ32_HANDLER/WRITE32_HANDLER and auto_malloc()'ing the necessary
> RAM space. (MESS does it in cases like the Apple Lisa where there's a custom MMU
> (original Apple VLSI, not the PMMU Motorola sold for the 680x0) between the 68k and
> the bus and so nothing has a fixed physical address, and Sega System 16/18 are also
> similar :-)



R. Belmont
Cuckoo for IGAvania
Reged: 09/21/03
Posts: 9716
Loc: ECV-197 The Orville
Send PM


Re: Memory banking in Polygonet Commanders new [Re: drewcifer]
#74444 - 05/16/06 02:37 AM


It's possible the 3D chips aren't too bad - Ville was able to get untextured polys from their "next-gen" chipset going fairly quickly, and of course Polygonet has no textures at all :-) (I'm not even sure it has Gouraud - might be strictly flat lighting).



Anonymous
Unregistered
Send PM


Re: Memory banking in Polygonet Commanders new [Re: drewcifer]
#84847 - 08/25/06 06:21 AM


> I've also thought the
> only way to bank is by using the banking functions...

If you want to run code from the bank then you have to use the set bank code.

smf


Pages: 1

MAMEWorld >> Programming
Previous thread Previous  View all threads Index   Next thread Next   Threaded Mode Threaded  

Extra information Permissions
Moderator:  Pi 
0 registered and 102 anonymous users are browsing this forum.
You cannot start new topics
You cannot reply to topics
HTML is enabled
UBBCode is enabled
Thread views: 4368