aboutsummaryrefslogtreecommitdiff
path: root/game/random.asm
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-05-11 23:00:53 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-05-11 23:00:53 +0100
commit6fafe08b7dc884960582d272d35650d1c9dfdf87 (patch)
tree330b1b958428c9e01463543490d31bc6c9cb471a /game/random.asm
parent681ba9adf948ebdc909b08979c76251053af7a9e (diff)
downloadtr8vm-6fafe08b7dc884960582d272d35650d1c9dfdf87.tar.gz
tr8vm-6fafe08b7dc884960582d272d35650d1c9dfdf87.zip
Add some randomness
Diffstat (limited to 'game/random.asm')
-rw-r--r--game/random.asm24
1 files changed, 24 insertions, 0 deletions
diff --git a/game/random.asm b/game/random.asm
new file mode 100644
index 0000000..0cb74db
--- /dev/null
+++ b/game/random.asm
@@ -0,0 +1,24 @@
+;
+; Random number generator
+;
+; x[i + 1] = (5 * x[i] + 1) mod 256
+;
+; out: y random value
+rnd:
+ ld x, <seed
+ ld a, >seed
+
+ ld y, [a : x]
+ ld b, y
+
+ add y, y
+ add y, y
+ add y, b
+ add y, 7
+
+ ld [a : x], y
+
+ ret
+
+seed:
+ .db 0