--- /dev/null
+ ; inits the random seed
+rand_init:
+ xor a, a
+ ld a, [srand]
+ ld a, [srand+1]
+ ret
+
+
+#define rand_table_end (rand_table + 512)
+ ; gets a pseudo-random number
+ ; and advances to the next seed
+ ; uses:
+ ; hl, a, b
+ ; returns:
+ ; a: random value
+rand:
+ ld a, [srand+1] ; low value
+ ld l, a ; load into low
+ ld a, [srand] ; high value
+ ld h, a ; load into high
+
+ ; store back
+
+ inc hl ; srand++
+ ld a, l
+ ld [srand+1], a
+ ld a, h
+ and a, ((rand_table_end - rand_table - 1) >> 8); overflow at max size
+ ld [srand], a
+
+ ld a, [hl] ; next value
+ ret
+
+ ; table of "rng" values
+ ; currently this will literally just read the rom following this
+ ; label treating the code as pseudo random numbers
+ ; TODO: genrate better rng table
+rand_table:
+