summaryrefslogtreecommitdiff
path: root/home/random.asm
diff options
context:
space:
mode:
Diffstat (limited to 'home/random.asm')
-rw-r--r--home/random.asm63
1 files changed, 14 insertions, 49 deletions
diff --git a/home/random.asm b/home/random.asm
index ae39f439..f96718b2 100644
--- a/home/random.asm
+++ b/home/random.asm
@@ -1,84 +1,49 @@
-Random:: ; 2f8c
-; A simple hardware-based random number generator (RNG).
-
-; Two random numbers are generated by adding and subtracting
-; the divider to the respective values every time it's called.
-
-; The divider is a register that increments at a rate of 16384Hz.
-; For comparison, the Game Boy operates at a clock speed of 4.2MHz.
-
-; Additionally, an equivalent function is executed in VBlank.
-
-; This leaves a with the value in hRandomSub.
-
+Random:: ; 30a2 (0:30a2)
push bc
-
ld a, [rDIV]
ld b, a
- ld a, [hRandomAdd]
+ ld a, [hRandom]
adc b
- ld [hRandomAdd], a
-
+ ld [hRandom], a
ld a, [rDIV]
ld b, a
ld a, [hRandomSub]
sbc b
ld [hRandomSub], a
-
pop bc
ret
-; 2f9f
-
-BattleRandom:: ; 2f9f
-; _BattleRandom lives in another bank.
-
-; It handles all RNG calls in the battle engine, allowing
-; link battles to remain in sync using a shared PRNG.
+BattleRandom::
ld a, [hROMBank]
push af
- ld a, BANK(_BattleRandom)
+ ld a, BANK(BattleRandom_)
rst Bankswitch
-
- call _BattleRandom
-
- ld [PredefTemp + 1], a
+ call BattleRandom_
+ ld [wPredefHLBuffer + 1], a
pop af
rst Bankswitch
- ld a, [PredefTemp + 1]
+ ld a, [wPredefHLBuffer + 1]
ret
-; 2fb1
-
-
-RandomRange:: ; 2fb1
-; Return a random number between 0 and a (non-inclusive).
+RandomRange::
push bc
ld c, a
-
- ; b = $100 % c
xor a
sub c
-.mod
+.asm_30cb
sub c
- jr nc, .mod
+ jr nc, .asm_30cb
add c
ld b, a
-
- ; Get a random number
- ; from 0 to $ff - b.
push bc
-.loop
+.asm_30d1
call Random
- ld a, [hRandomAdd]
+ ld a, [hRandom]
ld c, a
add b
- jr c, .loop
+ jr c, .asm_30d1
ld a, c
pop bc
-
call SimpleDivide
-
pop bc
ret
-; 2fcb