···11SECTION "DungeonVariables", WRAM0
2233-wDungeonGrid:: ds 512
44-wEntranceId:: db
55-wCurrentRoom:: db
66-wCurrentWidth:: db
77-wCurrentHeight:: db33+dungeon_grid:: ds 512
44+entrance_id:: db
55+current_room:: db
66+current_width:: db
77+current_height:: db
88+generated_cells:: ds 512
99+1010+SECTION "DungeonCode", ROM0
1111+1212+; Params:
1313+; Starting Width: B
1414+; Starting Height: C
1515+InitDungeon::
1616+ ld hl, current_width
1717+ ld [hl], b
1818+ ld hl, current_height
1919+ ld [hl], c
2020+ ret
2121+2222+GenerateDungeon::
2323+ ; Dungeon Area = E
2424+ push de
2525+ push hl
2626+ push af
2727+ push bc
2828+2929+ ld hl, current_width
3030+ ld e, [hl]
3131+ ld d, 0
3232+ ld hl, current_height
3333+ ld a, [hl]
3434+ call Mul8
3535+ ld d, h
3636+ ld e, l
3737+3838+ ; Generated Cells Number = A
3939+ ld a, 0
4040+4141+ ; i = B
4242+ ld b, 0
4343+.LoopCheck:
4444+ cp a, e
4545+ jp nz, GenerateDungeon.Loop_Skip
4646+ jp nc, GenerateDungeon.Loop_Skip
4747+ jp GenerateDungeon.LoopCheck2
4848+.LoopCheck2:
4949+ push af
5050+ ld a, b
5151+ cp a, 0
5252+ pop af
5353+ jp z, GenerateDungeon.Loop_Body
5454+ push af
5555+ push bc
5656+ ld c, a
5757+ ld a, b
5858+ ld b, c
5959+ cp a, b
6060+ pop bc
6161+ pop af
6262+ jp nz, GenerateDungeon.Loop_Skip
6363+ jp nc, GenerateDungeon.Loop_Skip
6464+.Loop_Body:
6565+ push af
6666+ ld a, b
6767+ cp a, 0
6868+ pop af
6969+ jp nz, GenerateDungeon.Loop_Body2
7070+ cp a, 0
7171+ jp nz, GenerateDungeon.Loop_Body2
7272+.Loop_Body2:
7373+.Loop_Skip:
7474+ pop bc
7575+ pop af
7676+ pop hl
7777+ pop de
7878+7979+ ret
+7-2
gb/src/main.asm
···2323SECTION "Entry point", ROM0
24242525EntryPoint:
2626- ; Here is where the fun begins, happy coding :)
2626+ ; Seed random number generator
2727 ld b, 0
2828 ld c, 10
2929 call srand
3030- call rand
3030+3131+ ; Initialize Dungeon
3232+ ld b, 6
3333+ ld c, 6
3434+ call InitDungeon
3535+3136 jp Done
32373338Done:
+18
gb/src/utils.asm
···77; C=state bits 23-16, HL trashed
88rand::
99 ; Add 0xB3 then multiply by 0x01010101
1010+ push hl
1111+ push af
1012 ld hl, randstate+0
1113 ld a, [hl]
1214 add a, $B3
···1921 adc a, [hl]
2022 ld [hl], a
2123 ld b, a
2424+ pop af
2525+ pop hl
2226 ret
23272428; Sets the random seed to BC.
···3236 ld a,b
3337 ld [hl-],a
3438 ld [hl],c
3939+ ret
4040+4141+; HL = DE * A
4242+Mul8::
4343+ ld hl, 0
4444+ ld b, 8
4545+Mul8Loop:
4646+ rrca
4747+ jp nc, Mul8Skip
4848+ add hl, de
4949+Mul8Skip:
5050+ sla e
5151+ rl d
5252+ STOP
3553 ret