MAMEWorld >> EmuChat
View all threads Index   Threaded Mode Threaded  

Pages: 1

GatKong
Tetris Mason
Reged: 04/20/07
Posts: 5907
Loc: Sector 9
Send PM


Random generators in PCB vs mame
#234272 - 09/22/10 05:03 PM


Recent discussion about DK barrels and different play between various versions of mame and the pcb's brings this to mind...

Depending on how the "random" is generated, I would imagine the pcb vs the emulated version could have drastic differences in "random" events, making gameplay on a competative level vastly different.

Another case in point is Hatris. Gatinha plays this alot (and is pending varification of her world record score)... she gets quite a few blue flames with the current version of mame, but has seen only one blue flame among probably fifty or more plays in the version required for score verification (which is based on mame.106). Makes a HUGE difference in game play. I have a hatris pcb... and once I get around to setting up a jamma getup, we'll be able to compare gameplay on the actual pcb as well. Maybe I could do a statistical analysis of blue flame frequency between the two versions of mame and the pcb for comparison purposes.

But getting around to the question at some point... is there any thing that could be done in emulation to approximate the original pcb's "random" frequencies... or is this just taking emulation too far given the huge variety of processors and speeds out there?







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


Re: Random generators in PCB vs mame new [Re: GatKong]
#234285 - 09/22/10 06:22 PM


> Recent discussion about DK barrels and different play between various versions of
> mame and the pcb's brings this to mind...

I'm pretty certain that the DK phenomenon reported is psychosomatic given none of the DK driver changes were anywhere near the gameplay. I've worked in the game industry for 15 years now, and one thing I know very well if that if you tell a non-technical person (producers, QA, consumers) you adjusted the gameplay in a certain way while actually doing nothing they will perceive whatever the claimed difference was and they'll tell everyone they love it. People are especially susceptible to hearing about gameplay defects they'd never imagined before in online forums and then immediately finding the game unplayable because of them.

Beyond that, most games' random-number generation is entirely internal to the game (ie, MAME cannot influence it as such), and frankly only Don Hodges knows how they operate.



Bryan Ischo
MAME Fan
Reged: 03/28/10
Posts: 358
Send PM


Re: Random generators in PCB vs mame new [Re: R. Belmont]
#234296 - 09/22/10 07:56 PM


> Beyond that, most games' random-number generation is entirely internal to the game
> (ie, MAME cannot influence it as such), and frankly only Don Hodges knows how they
> operate.

I for one find this to be a very interesting topic. I would enjoy knowing how arcade hardware generated random numbers (it would be different for every system, I imagine, but there are probably enough similarities to be able to discuss how it works in general).

So if Don Hodges wants to share any juicy tidbits on this topic I would really love to hear them!

Also - just out of curiousity - has the random number emulation of any games ever been rigorously tested? For some hardware I would imagine this would be easy - if, for example, the hardware always started every game with the same seed, or successive games with predictable seeds - and for others, much harder (if a counter that is latched when the game is started is used as the seed, for example, in which case starting a game on hardware with a known seed would be quite challenging). Comparing a game played with 'no inputs (inputs would affect the way the game played out)' on hardware versus MAME with a known random number generator seed for each would allow validation that the RNG is correctly emulated. This sounds like a royal pain in the butt so I would understand if nobody has ever done anything like it; but if anything has been done, I'd find it interesting to hear the specifics.



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


Re: Random generators in PCB vs mame new [Re: Bryan Ischo]
#234305 - 09/22/10 09:01 PM


> I for one find this to be a very interesting topic. I would enjoy knowing how arcade
> hardware generated random numbers (it would be different for every system, I imagine,
> but there are probably enough similarities to be able to discuss how it works in
> general).

To clarify: in most cases, this random number generation is internal to the *software* on a large majority of games. So the techniques used were likely similar to what was done on home computers in the early 80s.

A few later systems do have actual RNG hardware, specifically Sega System 32 and some of the later Neo Geo cartridges. The NG generator had a reversible pattern and is emulated correctly (I believe it's a LFSR, but don't hold me to that). We couldn't find the pattern for the Sega one, but nobody ever complains about those games on this topic

> So if Don Hodges wants to share any juicy tidbits on this topic I would really love
> to hear them!

Ditto.

The software-only RNGs likely are seeded by the frame count between boot and coin-up or other user inputs, so it's quite possible in that situation (especially if the RNG algorithm in the game software isn't very good) that MAME would behave differently from a cabinet that had been powered up for weeks or months at a time. This is one reason CAX is a nice sanity check on the emulation - the games are on only for the length of the show each day so they're in similar-to-MAME condition w.r.t. things like that, especially in the morning.



Phantom DJ
MAME Fan
Reged: 04/05/06
Posts: 99
Send PM


Re: Random generators in PCB vs mame new [Re: R. Belmont]
#234310 - 09/22/10 10:09 PM


Every game can generate random numbers in different ways. For example, it is well known that in Pac-Man , the random number generator is not really random, allowing patterns to be developed that can be played exactly the same each time.

In Donkey Kong, the routine to generate a random number does so by adding up the seed and 2 different timers which results in a number that is pretty damn random. These timers both run at different speeds.

Code:


Donkey Kong Z80 disassembly follows:
; this subroutine generates a random number which is saved into the seed address #6018 and returned in the A register as well.

0057 3A1860 LD A,(#6018) ; load A with seed
005A 211A60 LD HL,#601A ; load HL with timer address
005D 86 ADD A,(HL) ; add timer to seed
005E 211960 LD HL,#6019 ; load HL with another timer address
0061 86 ADD A,(HL) ; add to seed
0062 321860 LD (#6018),A ; store seed
0065 C9 RET ; return



So, as long as MAME is emulating the timing of this game correctly, I suppose that the random numbers generated here will come out the same way as an actual DK machine.

In Ms. Pac-Man, random numbers are generated simply by loading the value from the R (refresh) register, which is updated every machine cycle and will give an extremely random number whenever it is read.

Let me know if you want me to look at other game's random number generators.

Don Hodges

Edited by Phantom DJ (09/24/10 09:01 PM)



franciscohs
M.A.M.E. fan
Reged: 10/04/08
Posts: 174
Loc: Argentina
Send PM


Re: Random generators in PCB vs mame new [Re: R. Belmont]
#234312 - 09/22/10 10:22 PM


> > I for one find this to be a very interesting topic. I would enjoy knowing how
> arcade
> > hardware generated random numbers (it would be different for every system, I
> imagine,
> > but there are probably enough similarities to be able to discuss how it works in
> > general).
>
> To clarify: in most cases, this random number generation is internal to the
> *software* on a large majority of games. So the techniques used were likely similar
> to what was done on home computers in the early 80s.
>
> A few later systems do have actual RNG hardware, specifically Sega System 32 and some
> of the later Neo Geo cartridges. The NG generator had a reversible pattern and is
> emulated correctly (I believe it's a LFSR, but don't hold me to that). We couldn't
> find the pattern for the Sega one, but nobody ever complains about those games on
> this topic
>

I cannot find the story right now, but didn't that first bubble bobble decap fix something about how random numbers where generated in hardware vs the MAME simulation of it?



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


Re: Random generators in PCB vs mame new [Re: franciscohs]
#234315 - 09/22/10 11:16 PM


> I cannot find the story right now, but didn't that first bubble bobble decap fix
> something about how random numbers where generated in hardware vs the MAME simulation
> of it?

Right, Taito games with protection MCUs generally ran the software RNG on the MCU, so HLE simulation by nature wouldn't match it.



mahlemiut
MAME Fan
Reged: 06/20/07
Posts: 60
Loc: New Zealand
Send PM


Re: Random generators in PCB vs mame new [Re: franciscohs]
#234317 - 09/22/10 11:20 PM


> I cannot find the story right now, but didn't that first bubble bobble decap fix
> something about how random numbers where generated in hardware vs the MAME simulation
> of it?

I believe it fixed how the EXTEND letters appear. From memory, the letters simply rotate, but due to the timing of bubble s appearing on screen, the order will be red E, T, N, or X, green E, D. You can induce a delay by maxing out the number of bubbles (about 16) on screen at once so that no more will appear until you pop the others.

As for bonus items, they're not really random, but are determined by the contents of a multitude of counters. More details here: http://replay.marpirc.net/txt/bublbobl.txt



- Barry Rodewald
Editor at MARP - http://replay.marpirc.net



amused
MAME Fan
Reged: 04/24/08
Posts: 300
Send PM


Re: Random generators in PCB vs mame new [Re: Phantom DJ]
#234331 - 09/23/10 03:59 AM


> Let me know if you want me to look at other game's random number generators.

Please (I beg you!) look at kiwame. Maybe you can tell us the cause of bug #3566.



GatKong
Tetris Mason
Reged: 04/20/07
Posts: 5907
Loc: Sector 9
Send PM


Re: Random generators in PCB vs mame new [Re: Phantom DJ]
#234336 - 09/23/10 04:12 AM


>Let me know if you want me to look at other game's random number generators.

Yes, please look at hatris... what determines the arrival of a red or blue flame?








italieAdministrator
MAME owes italie many thank yous, hah
Reged: 09/20/03
Posts: 15246
Loc: BoomTown
Send PM


Re: Random generators in PCB vs mame new [Re: R. Belmont]
#234342 - 09/23/10 04:49 AM


> A few later systems do have actual RNG hardware, specifically Sega System 32 and some
> of the later Neo Geo cartridges. The NG generator had a reversible pattern and is
> emulated correctly (I believe it's a LFSR, but don't hold me to that). We couldn't
> find the pattern for the Sega one, but nobody ever complains about those games on
> this topic


They will now, that much is certain....



Tomu Breidah
No Problems, Only Solutions
Reged: 08/14/04
Posts: 6820
Loc: Neither here, nor there.
Send PM


Re: Random generators in PCB vs mame new [Re: GatKong]
#234356 - 09/23/10 07:30 AM


It seems like in SF2ce the majority of the time the first match (after picking Ryu) would be against E. Honda. But not ALL the time.

Maybe Jopezu can verify. I've no arcade machine to test/verify against.

The point is - if the first match is supposed to be random (ETA: yeah, I'm being presumptuous here), but a majority of the time the first match is E.Honda (when playing in MAME)... then what you've suggested could be true for any number of games.



Edited by T0M (09/23/10 07:31 AM)



LEVEL-4



etabeta
Reged: 08/25/04
Posts: 2036
Send PM


Re: Random generators in PCB vs mame new [Re: franciscohs]
#234359 - 09/23/10 08:48 AM


> I cannot find the story right now, but didn't that first bubble bobble decap fix
> something about how random numbers where generated in hardware vs the MAME simulation
> of it?

I think you refer to this

http://mamelife.blogspot.com/2006/08/completed-at-last.html



CrapBoardSoftware
My real name is banned dickhead
Reged: 01/03/06
Posts: 1250
Loc: Wisconsin
Send PM


Re: Random generators in PCB vs mame new [Re: franciscohs]
#234361 - 09/23/10 09:18 AM


It's not in the forum, but to be found at MAWS:


Quote:


- 5th August 2006: Nicola Salmoria - As you'd probably noticed, the pics in the previous post are of the Bubble Bobble custom MCU. Despite being one of the most popular games of all times, and having been in MAME for many years, the emulation of this game has never been perfect due to the lack of the original ROM for the MCU. For some time, we had been using a 68705 program found in a bootleg board, believing it had been extracted from the original. However, monster behaviour was wrong and there were other problems, like the wrong behaviour of the clock item. After some study of the program and of the game schematics, it became clear that the original MCU is not a 68705 at all (the pinout doesn't match) but looked more like a 68701. The 68705 program had been written from scratch by the bootleggers using black box reverse engineering techniques, by running the original MCU and logging all its reads and writes from memory. Indeed, the 68705 program does a lot of reads from memory without doing anything with them--simply because the original MCU would read that memory and do some unknown action with it. Eventually, the useless 68705 program was replaced by simulation code inside the emulator, which greatly improved the emulation accuracy. Monster behaviour was improved, the clock item behaviour fixed. However, there were still some unknown things, like how the randomisation of the EXTEND bubbles really worked. At last, thanks to excellent work by Trinity, the original MCU ROM has been extracted. This required removing the cover from the chip, taking photographs of it under a microscope, and manually decoding the contents of the ROM bit by bit. The photo shown in the previous post confirms that it's in the 6801 class, not a 68701 however as it was conjectured, but a 6801U4. With this ROM, we finally have the final piece of the puzzle for a 100\% guaranteed perfect emulation. Checking the original MCU program was very interesting. It was designed to provide many protection features that were eventually not used by the game, like: * Process coin inputs and update the credit counter * Handle the number of remaining lives for both players * Handle the current round number * Handle variable speed incrementing for four variables and * Return values from a 1280 bytes table of seemingly random data. The reasons why those features were not used are probably various. Some of them were probably awkward to use because they require to one one frame for the MCU to process the data, others weren't flexible enough like the coin input processing that wouldn't allow for coinage settings different from the ones hardcoded in the MCU (though versions of Bubble Bobble with different coinage settings don't seem to have been made anyway).
So, how close was the simulation to the real thing? Very close; "too good", actually. Let's see why. The clock item behaviour was spot on, but off by one frame (the simulation made the counter expire one frame too late). The EXTEND randomisation simply doesn't exist in the original MCU. While the simulation code used a RNG to provide truly random letters, the original MCU simply increases the counter every frame. This seriously affects the game, making the EXTEND letters predictable. Since a new bubble enters the screen exactly 128 frames after the previous one, and the remainder of 128 / 6 is 2, this means that if you get consecutive letters each one will be 2 places after the previous one. So if you get 3 letters you can get either E, T, N or X, E, D. After that they will repeat. There are exceptions, though: if you create a new bubble in exactly the same frame when a new bubble should enter the screen, the bubble is delayed by one frame. So by timing the fire button exactly right you can change the bubble order. In theory you could get all 6 letters in a single level--let me know if you manage to do that! Also, new bubbles will not appear if there are already 16 bubbles on the screen, so that will change the order as well. The last, and most important, thing that the MCU does is compare the player coordinates with the monsters. The results are returned as flags indicating whether each coordinate is >, =, or <, and the absolute difference. This was done correctly in the simulation code, however there appears to be a bug in the original MCU. The code there attempts to check if the player collided with a moster and set a flag and indicate which monster in that case, but it just doesn't work. It would set the flag even if the player's Y coordinate matches one monster and the X coordinate matches a different monster! This isn't much of a problem since the main program just ignores the flag--the collision detection is done correctly by the second Z80. However, the MCU also completely stops processing the monster coordinates as soon as it finds a monster whose X coordinate is within 8 pixels of the player. So e.g. if you have a monster right above you three platforms up, and that monster is the first in the list, the other monsters could stop following you. This is a very subtle effect that's completely unnoticeable from what I can tell, though in theory it exists.




Original source.

Related.



ShimaPong
MAME Fan
Reged: 03/12/05
Posts: 783
Send PM


Re: Random generators in PCB vs mame new [Re: amused]
#234386 - 09/23/10 03:50 PM


Learn 68000 assemble and try BY YOUR SELF

I have searched/created a lots of cheat code included in many Mahjong games so that in my own experience it's not hard to realize than the main routine of Mahjong.



"Any company has no power to stop people emulating"
MAME is the emulator of no giving in the pressure from any company even if they don't allow



Phantom DJ
MAME Fan
Reged: 04/05/06
Posts: 99
Send PM


Re: Random generators in PCB vs mame new [Re: GatKong]
#234699 - 09/26/10 07:13 AM


> Recent discussion about DK barrels and different play between various versions of
> mame and the pcb's brings this to mind...
>
> Depending on how the "random" is generated, I would imagine the pcb vs the emulated
> version could have drastic differences in "random" events, making gameplay on a
> competative level vastly different.
>
> Another case in point is Hatris. Gatinha plays this alot (and is pending varification
> of her world record score)... she gets quite a few blue flames with the current
> version of mame, but has seen only one blue flame among probably fifty or more plays
> in the version required for score verification (which is based on mame.106). Makes a
> HUGE difference in game play. I have a hatris pcb... and once I get around to setting
> up a jamma getup, we'll be able to compare gameplay on the actual pcb as well. Maybe
> I could do a statistical analysis of blue flame frequency between the two versions of
> mame and the pcb for comparison purposes.
>
> But getting around to the question at some point... is there any thing that could be
> done in emulation to approximate the original pcb's "random" frequencies... or is
> this just taking emulation too far given the huge variety of processors and speeds
> out there?



[Don Hodges wrote:]> > Let me know if you want me to look at other game's random number generators.
>
> Yes, please look at hatris... what determines the arrival of a red or blue flame?

From what I can tell, each hat has a chance of being a red fire. This chance depends on how many hat sets have been completed:

0-10 sets: 3/256 chance
11-15 sets: 5/256 chance
16-50 sets: 10/256 chance
over 51 sets: 15/256

If both hats are set to a fire, the game checks for this and resets one of the fires back to a hat.

The program keeps track of how many flames have appeared. After every 7th red flame, the next flame that appears will be blue.* [there is a 1/256 chance that this will not happen, and the 8th flame will stay red.]


Don Hodges
www.donhodges.com

Edited by Phantom DJ (09/26/10 07:20 AM)



GatKong
Tetris Mason
Reged: 04/20/07
Posts: 5907
Loc: Sector 9
Send PM


Re: Random generators in PCB vs mame new [Re: Phantom DJ]
#234776 - 09/27/10 04:38 AM


Thanks... that's awesome! I'll be paying attention to see how that plays out.






Pages: 1

MAMEWorld >> EmuChat
View all threads Index   Threaded Mode Threaded  

Extra information Permissions
Moderator:  Robbbert, Tafoid 
0 registered and 182 anonymous users are browsing this forum.
You cannot start new topics
You cannot reply to topics
HTML is enabled
UBBCode is enabled
Thread views: 3258