diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-05-11 23:00:53 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-05-11 23:00:53 +0100 |
commit | 6fafe08b7dc884960582d272d35650d1c9dfdf87 (patch) | |
tree | 330b1b958428c9e01463543490d31bc6c9cb471a /game | |
parent | 681ba9adf948ebdc909b08979c76251053af7a9e (diff) | |
download | tr8vm-6fafe08b7dc884960582d272d35650d1c9dfdf87.tar.gz tr8vm-6fafe08b7dc884960582d272d35650d1c9dfdf87.zip |
Add some randomness
Diffstat (limited to 'game')
-rw-r--r-- | game/main.asm | 1 | ||||
-rw-r--r-- | game/random.asm | 24 | ||||
-rw-r--r-- | game/starfield.asm | 10 |
3 files changed, 35 insertions, 0 deletions
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 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 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 |