How to Trigger a Diamond in Mr. Do!

By Don Hodges 6/29/2009

Last updated 2/19/2017

In the 1983 video game Mr. Do!, there is a special diamond that randomly appears in the game.  If the player is able to grab it, the round ends and a free game is awarded.

Through code analysis, we can discover how to trigger the diamond, in games that have their dip switch setting for "special" set to easy.


Here is how to do it:

1.  Power cycle the game.

2.  Allow the demo to run through 11 times.

3. On the 12th game demo, insert a quarter at the moment that Mr. Do! eats the center prize.

4.  Start a game.

5.  Loosen the first apple on the bottom right side.

6.  If everything is done correctly, there will be a diamond when it drops, every time.

Technical Details and Code Analysis

For those of you with inquiring minds

The following code segment from Mr. Do! is called after an apple drops during a game, and after checks to make sure someone is playing and there isn't already a diamond onscreen:

50D3: CD F4 02 call $02F4   ; randomize HL
50D6: 3A 02 A0 ld a,($A002) ; load A with easy/hard dipswitch . easy = #DF, hard =#D7
50D9: E6 08    and $08      ; is this hard setting?
50DB: 28 07    jr z,$50E4   ; yes, skip ahead

; check for diamond , easy setting

50DD: 7D       ld a,l       ; load A with random number low byte
50DE: E6 80    and $80      ; mask bits with 10000000 - turn off all but highest bit
50E0: B4       or h         ; mix bits with random number high byte. result zero?
50E1: C0       ret nz       ; no, return [overall 1/512 chance to get diamond]

50E2: 18 05    jr $50E9     ; else jump ahead to display diamond

; check for diamond, hard setting

50E4: 7D       ld a,l       ; load A with random number low byte
50E5: E6 E0    and $E0      ; mask bits with 11100000 - top 3 bits stay on 
50E7: B4       or h         ; mix bits with random number high byte. result zero?
50E8: C0       ret nz       ; no, return [overall 1/2048 chance to get diamond]

; display diamond sprite

50E9: 21 09 E3 ld hl,$E309  ; load HL with diamond sprite address
50EC: 36 80    ld (hl),$80  ; set sprite to diamond


For the easy skill, to get a diamond we need the random number low byte to be less than 128 decimal, out of a possible 256.  This has a 50% chance of happening.  We also require that the random number high byte be equal to zero.  This has a 1 in 256 chance of happening.  Both will happen, and trigger a diamond, with a 1 in 512 chance.

For the hard setting, we need the low byte to be less than 32, which has a 1/8 chance.  It also requires the high byte to be equal to zero, which has 1/256 chance.  Both will happen, and trigger a diamond, with a 1 in 2048 chance.

The reason that we are able to predict when a diamond will appear is that the random numbers in Mr. Do! are not really random.  The random number seed is planted here:

0082: 21 5B 36 ld hl,$365B   ; load HL with random number seed #365B
0085: 22 7B E0 ld ($E07B),hl ; store into random number

And let's have a look at the "random" number generator that uses this seed during play:

02F4: 2A 7B E0 ld hl,($E07B) ; load HL with current random number
02F7: 54       ld d,h        ; copy H to D
02F8: 5D       ld e,l        ; copy L to E. DE now has a copy of HL
02F9: 29       add hl,hl     ; double it
02FA: 19       add hl,de     ; triple it
02FB: 7B       ld a,e        ; load A with original low byte
02FC: 84       add a,h       ; add to high byte
02FD: 67       ld h,a        ; store into H
02FE: 22 7B E0 ld ($E07B),hl ; store result into current random number
0301: C9       ret           ; return

The above is a deterministic algorithm which will generate the same sequence of numbers every time.

For example, starting with the seed value of hexadecimal #365B, the random number sequence always goes:

365B, FE11, 0B33, 5499, 96CB, 8F61, 0F23, 5069, 5A3B, 49B1, 8E13, and on and on ....

Setting up a MAME memory watch on this location, we can watch it progress and observe that it gets a value of #0049 during the 12th demo round after a reset.  With some experimentation, we discover that inserting a credit at the appropriate time will allow this value to occur when the first apple is dropped during a game, in turn causing a diamond to appear.



In accordance with Title 17 U.S.C. Section 107, some of the material on this site is distributed without profit to those who have expressed a prior interest in receiving the included information for research and educational purposes. For more information go to: If you wish to use copyrighted material from this site for purposes of your own that go beyond 'fair use', you must obtain permission from the copyright owner.


All content Copyright 2015 Don Hodges
Various logos are trademarks of their respective companies.
Send Email to Don Hodges