A dungeon delver roguelike using Pathfinder 2nd edition rules
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Adding random number generator

+54 -1
+7
gb/src/dungeon.asm
··· 1 + SECTION "DungeonVariables", WRAM0 2 + 3 + wDungeonGrid:: ds 512 4 + wEntranceId:: db 5 + wCurrentRoom:: db 6 + wCurrentWidth:: db 7 + wCurrentHeight:: db
+12 -1
gb/src/main.asm
··· 1 1 INCLUDE "hardware.inc/hardware.inc" 2 2 rev_Check_hardware_inc 4.0 3 3 4 + SECTION "GameVariables", WRAM0 5 + 6 + randstate:: ds 4 7 + 4 8 SECTION "Header", ROM0[$100] 5 9 6 10 ; This is your ROM's entry point ··· 20 24 21 25 EntryPoint: 22 26 ; Here is where the fun begins, happy coding :) 23 - jr @ 27 + ld b, 0 28 + ld c, 10 29 + call srand 30 + call rand 31 + jp Done 32 + 33 + Done: 34 + jp Done
+35
gb/src/utils.asm
··· 1 + SECTION "Math", ROM0 2 + ;; From: https://github.com/pinobatch/libbet/blob/master/src/rand.z80#L34-L54 3 + ; Generates a pseudorandom 16-bit integer in BC 4 + ; using the LCG formula from cc65 rand(): 5 + ; x[i + 1] = x[i] * 0x01010101 + 0xB3B3B3B3 6 + ; @return A=B=state bits 31-24 (which have the best entropy), 7 + ; C=state bits 23-16, HL trashed 8 + rand:: 9 + ; Add 0xB3 then multiply by 0x01010101 10 + ld hl, randstate+0 11 + ld a, [hl] 12 + add a, $B3 13 + ld [hl+], a 14 + adc a, [hl] 15 + ld [hl+], a 16 + adc a, [hl] 17 + ld [hl+], a 18 + ld c, a 19 + adc a, [hl] 20 + ld [hl], a 21 + ld b, a 22 + ret 23 + 24 + ; Sets the random seed to BC. 25 + ; C expects startup code to behave as if srand(1) was called. 26 + ; AHL trashed 27 + srand:: 28 + ld hl,randstate+3 29 + xor a 30 + ld [hl-],a 31 + ld [hl-],a 32 + ld a,b 33 + ld [hl-],a 34 + ld [hl],c 35 + ret