diff options
-rw-r--r-- | definitions.gbasm | 10 | ||||
-rw-r--r-- | init.gbasm | 8 | ||||
-rw-r--r-- | main.gbasm | 8 | ||||
-rw-r--r-- | map/generation.gbasm | 168 | ||||
-rw-r--r-- | map/loading.gbasm (renamed from map.gbasm) | 41 | ||||
-rw-r--r-- | rng.gbasm | 2 | ||||
-rw-r--r-- | tiles.gbasm | 1 |
7 files changed, 188 insertions, 50 deletions
diff --git a/definitions.gbasm b/definitions.gbasm index f6b757e..2df133f 100644 --- a/definitions.gbasm +++ b/definitions.gbasm @@ -10,6 +10,9 @@ .DEFINE VRAM_start $8000 .DEFINE OAM_start $FE00 +.DEFINE dungeon_generation_step $20 +.DEFINE intial_duplication_probablity $2 + .DEFINE mem_bunny_x_px ($c000) .DEFINE mem_bunny_y_px ($c001) .DEFINE mem_button_direction ($c002) @@ -23,6 +26,13 @@ .DEFINE mem_rng_state_1 ($c00a) ; 2 bytes .DEFINE mem_rng_state_2 ($c00b) ; 2 bytes +.DEFINE mem_dungeon_generation_heads $c700 ; Takes the memory from c700 to c717 +; struct head { +; direction: u8 (really u3 but padding), +; x: u8, +; y: u8, +; } + .DEFINE mem_dungeon_map $c800 ; Takes the memory from c800 to c87f .DEFINE enum_direction_left $01 @@ -41,12 +41,12 @@ Wait_VBlank: LD $reg_lcd_controller, A Empty_VRAM: ; (Clear screen) - LD hl, $VRAM_start ; We set the HL register to the start of VRAM + LD HL, $VRAM_start ; We set the HL register to the start of VRAM Empty_VRAM.loop: XOR A - LD (HL+), a ; We set the memory pointed to by HL to 0 and increase HL - LD a, $a0 - CP h ; Until h has reached $a0 ($a0000 is the end of VRAM) + LD (HL+), A ; We set the memory pointed to by HL to 0 and increase HL + LD A, $a0 + CP H ; Until h has reached $a0 ($a0000 is the end of VRAM) JR NZ, =Empty_VRAM.loop ; BG Palette @@ -2,11 +2,11 @@ .INCLUDE "init.gbasm" Entrypoint: - CALL =Initialize_Dungeon + CALL =Initialize_RNG + CALL =Dungeon_Generation CALL =Initialize_Bunny CALL =Load_Tile CALL =Load_Map - CALL =Initialize_RNG ; LCDC LD A, $87 @@ -21,11 +21,11 @@ VBLANK_Entrypoint: CALL =Pad_Button_Check CALL =Move_Bunny CALL =Display_Bunny - CALL =RNG_Step RET .INCLUDE "tiles.gbasm" -.INCLUDE "map.gbasm" +.INCLUDE "map/loading.gbasm" +.INCLUDE "map/generation.gbasm" .INCLUDE "bunny.gbasm" .INCLUDE "buttons.gbasm" .INCLUDE "rng.gbasm" diff --git a/map/generation.gbasm b/map/generation.gbasm new file mode 100644 index 0000000..1bedffc --- /dev/null +++ b/map/generation.gbasm @@ -0,0 +1,168 @@ +Initial_dungeon: + .DB $00, $00, $00, $00, + .DB $00, $00, $00, $00, + .DB $00, $00, $00, $00, + .DB $00, $00, $00, $00, + .DB $00, $00, $00, $00, + .DB $00, $00, $00, $00, + .DB $00, $00, $00, $00, + .DB $03, $e0, $00, $00, + .DB $02, $20, $00, $00, + .DB $02, $20, $00, $00, + .DB $02, $20, $00, $00, + .DB $02, $20, $00, $00, + .DB $02, $20, $00, $00, + .DB $0e, $20, $00, $00, + .DB $3f, $20, $00, $00, + .DB $3f, $20, $00, $00, + .DB $3f, $3f, $80, $00, + .DB $3f, $00, $80, $00, + .DB $3f, $00, $80, $00, + .DB $3f, $00, $80, $00, + .DB $3f, $00, $80, $00, + .DB $3f, $00, $80, $00, + .DB $00, $01, $f8, $00, + .DB $00, $01, $f8, $00, + .DB $00, $01, $f8, $00, + .DB $00, $01, $f8, $00, + .DB $00, $01, $f8, $00, + .DB $00, $01, $ff, $80, + .DB $00, $01, $f8, $80, + .DB $00, $01, $f8, $80, + .DB $00, $00, $ff, $80, + .DB $00, $00, $00, $00, + +Initialize_Dungeon: + LD HL, $mem_dungeon_map + LD DE, =Initial_dungeon + LD BC, $0100 + JP =memcpy + +Carve_Tunnel: ; X in A, Y in B + PUSH BC + PUSH HL + LD A, C + + LD H, $00 + CP $10 + RL B + AND $0f + CP $08 + RL B + AND $07 + LD L, A + + LD C, B + LD B, $c8 + LD A, (BC) + + OR (HL) + LD (BC), A + + POP HL + POP BC + RET + +Dungeon_Generation: + ; Head initialization + LD HL, $mem_dungeon_generation_heads + CALL =RNG_Step + AND $03 + ADD $01 + LD (HL+), A + LD A, $10 + LD (HL+), A + LD (HL+), A + + LD A, $20 + PUSH AF + + Dungeon_Generation.Step: + LD HL, $mem_dungeon_generation_heads + + Dungeon_Generation.Head_loop: + LD B, (HL) + LD A, B + + CP $00 + JR Z, =Dungeon_Generation.Head_loop.end + + CALL =RNG_Step + AND $07 + JR NZ, =Dungeon_Generation.Direction_Change.end + Dungeon_Generation.Direction_Change: + DEC B + CALL =RNG_Step + AND $01 + XOR B + XOR $02 + INC A + LD B, A + LD (HL), B + Dungeon_Generation.Direction_Change.end: + + INC HL + + LD C, (HL) + LD A, B + + CP $01 + JR NZ =Dungeon_Generation.Left.end + Dungeon_Generation.Left: + DEC C + Dungeon_Generation.Left.end: + + CP $02 + JR NZ =Dungeon_Generation.Right.end + Dungeon_Generation.Right: + INC C + Dungeon_Generation.Right.end: + + AND $e0 + + JR NZ, =Dungeon_Generation.DonT_Update_X + LD (HL), C + Dungeon_Generation.DonT_Update_X: + + INC HL + + LD C, (HL) + LD A, B + + CP $03 + JR NZ =Dungeon_Generation.Up.end + Dungeon_Generation.Up: + DEC C + Dungeon_Generation.Up.end: + + CP $04 + JR NZ =Dungeon_Generation.Down.end + Dungeon_Generation.Down: + INC C + Dungeon_Generation.Down.end: + + AND $e0 + + JR NZ, =Dungeon_Generation.DonT_Update_Y + LD (HL), C + Dungeon_Generation.DonT_Update_Y: + + DEC HL + LD A, (HL+) + LD C, A + LD A, (HL+) + LD B, A + LD A, C + CALL =Carve_Tunnel + JP =Dungeon_Generation.Head_loop + + Dungeon_Generation.Head_loop.end: + + POP AF + DEC A + PUSH AF + CP $00 + JR NZ, =Dungeon_Generation.Step + + POP AF + RET diff --git a/map.gbasm b/map/loading.gbasm index d664203..8b3f414 100644 --- a/map.gbasm +++ b/map/loading.gbasm @@ -236,47 +236,6 @@ Load_Block: ; X in A, Y in B POP BC RET -Initial_dungeon: - .DB $00, $00, $00, $00, - .DB $00, $00, $00, $00, - .DB $00, $00, $00, $00, - .DB $00, $00, $00, $00, - .DB $00, $00, $00, $00, - .DB $00, $00, $00, $00, - .DB $00, $00, $00, $00, - .DB $03, $e0, $00, $00, - .DB $02, $20, $00, $00, - .DB $02, $20, $00, $00, - .DB $02, $20, $00, $00, - .DB $02, $20, $00, $00, - .DB $02, $20, $00, $00, - .DB $0e, $20, $00, $00, - .DB $3f, $20, $00, $00, - .DB $3f, $20, $00, $00, - .DB $3f, $3f, $80, $00, - .DB $3f, $00, $80, $00, - .DB $3f, $00, $80, $00, - .DB $3f, $00, $80, $00, - .DB $3f, $00, $80, $00, - .DB $3f, $00, $80, $00, - .DB $00, $01, $f8, $00, - .DB $00, $01, $f8, $00, - .DB $00, $01, $f8, $00, - .DB $00, $01, $f8, $00, - .DB $00, $01, $f8, $00, - .DB $00, $01, $ff, $80, - .DB $00, $01, $f8, $80, - .DB $00, $01, $f8, $80, - .DB $00, $00, $ff, $80, - .DB $00, $00, $00, $00, - -Initialize_Dungeon: - LD HL, $mem_dungeon_map - LD DE, =Initial_dungeon - LD BC, $0100 - JP =memcpy - - Is_Solid: ; X in A, Y in B, Result A PUSH BC @@ -9,7 +9,7 @@ Debug_RNG: Initialize_RNG: LD A, $42 LD $mem_rng_state_1, A - LD A, $69 + LD A, $15 LD $mem_rng_state_2, A RET diff --git a/tiles.gbasm b/tiles.gbasm index b66222c..faeda8d 100644 --- a/tiles.gbasm +++ b/tiles.gbasm @@ -127,3 +127,4 @@ Load_Number_Font: ; Load number font into the tilemap at tiles 0x10-0x1f INC DE DEC B JR NZ, =Load_Number_Font.loop + RET |