From 6fafe08b7dc884960582d272d35650d1c9dfdf87 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Thu, 11 May 2023 23:00:53 +0100 Subject: Add some randomness --- game/main.asm | 1 + game/random.asm | 24 ++++++++++++++++++++++++ game/starfield.asm | 10 ++++++++++ 3 files changed, 35 insertions(+) create mode 100644 game/random.asm diff --git a/game/main.asm b/game/main.asm index e779a95..cdf0844 100644 --- a/game/main.asm +++ b/game/main.asm @@ -52,6 +52,7 @@ fill_loop: int_handler: iret +.include "random.asm" .include "starfield.asm" .include "entities.asm" .include "player.asm" 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 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 diff --git a/game/starfield.asm b/game/starfield.asm index e8b8ed1..ac8fe32 100644 --- a/game/starfield.asm +++ b/game/starfield.asm @@ -40,6 +40,16 @@ stars_update_addr: cmp y, 0x80 bc ld b, 0xbf + + ; add some randomness + push a + push x + push b + call rnd + pop b + pop x + pop a + stars_no_wrap: dec x bnz -- cgit v1.2.3