diff options
author | Astatin <[email protected]> | 2024-08-14 20:05:28 +0900 |
---|---|---|
committer | Astatin <astatin@redacted> | 2024-08-14 20:05:28 +0900 |
commit | f9f115384757135fa8488bd43eb3e5e91cc243d9 (patch) | |
tree | 6ab2b9bf120267f85140e1d8c9aa3a12b7e9c446 | |
parent | 59c2f3cc678df564bb9cf2b232537ce8a9d734fa (diff) |
Add RNG + do some tests with is_solid
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | bunny.gbasm | 8 | ||||
-rw-r--r-- | definitions.gbasm | 21 | ||||
-rw-r--r-- | main.gbasm | 4 | ||||
-rw-r--r-- | map.gbasm | 176 | ||||
-rw-r--r-- | rng.gbasm | 70 |
6 files changed, 243 insertions, 38 deletions
@@ -7,7 +7,7 @@ build/main.rom: main.gbasm gbasm $< $@ run: build/main.rom - gb --thread-sleep $< + gb -s 200 $< sameboy: build/main.rom sameboy build/main.rom diff --git a/bunny.gbasm b/bunny.gbasm index 01801ab..ff2aa99 100644 --- a/bunny.gbasm +++ b/bunny.gbasm @@ -148,14 +148,6 @@ Move_Bunny: RET Display_Bunny: ; X position in $81, Y position in $80 - LD A, $mem_bunny_x - LD HL, $9840 - CALL =Print_8bit - - LD A, $mem_bunny_y - LD HL, $9860 - CALL =Print_8bit - LD A, $mem_bunny_x_px LD B, A LD A, $mem_bunny_y_px diff --git a/definitions.gbasm b/definitions.gbasm index fdefee8..88c1e5c 100644 --- a/definitions.gbasm +++ b/definitions.gbasm @@ -20,9 +20,26 @@ .DEFINE mem_bunny_y ($c007) .DEFINE mem_viewport_x ($c008) .DEFINE mem_viewport_y ($c009) +.DEFINE mem_rng_state_1 ($c00a) ; 2 bytes +.DEFINE mem_rng_state_2 ($c00b) ; 2 bytes -.DEFINE mem_room_number ($c7ff) ; AND 0xf gives the size of $c800 -.DEFINE mem_room_array $c800 ; Takes the memory from c800 to c81f +.DEFINE mem_room_number ($c7ff) ; AND 0xf0 >> 8 gives the number of rooms and AND 0xf gives the number of corridors +.DEFINE mem_room_array $c800 ; Takes the memory from c800 to c840 +.DEFINE mem_corridors_array $c840 ; Takes the memory from c840 to c8a0 +; room = struct { +; x1: u8 +; x2: u8 +; y1: u8 +; y2: u8 +; } 4bytes +; corridor = struct { +; orientation: bool +; start u8 +; end u8 +; position u8 +; cut: u8 +; _padding: u24 +; } 8bytes .DEFINE enum_direction_left $01 .DEFINE enum_direction_right $02 @@ -2,9 +2,11 @@ .INCLUDE "init.gbasm" Entrypoint: + CALL =Initialize_Room CALL =Load_Tile CALL =Load_Map CALL =Initialize_Bunny + CALL =Initialize_RNG ; LCDC LD A, $87 @@ -19,6 +21,7 @@ VBLANK_Entrypoint: CALL =Pad_Button_Check CALL =Move_Bunny CALL =Display_Bunny + CALL =RNG_Step RET .INCLUDE "tiles.gbasm" @@ -26,3 +29,4 @@ VBLANK_Entrypoint: .INCLUDE "map.gbasm" .INCLUDE "bunny.gbasm" .INCLUDE "buttons.gbasm" +.INCLUDE "rng.gbasm" @@ -228,32 +228,154 @@ Load_Block: ; X in A, Y in B (X and B being AND with 0x0f) POP BC RET -Is_Solid: ; X in A, Y in B, Result A - PUSH BC - PUSH DE - - CP $15 - JR NC, =Is_Solid.Not_Empty - - CP $02 - JR C, =Is_Solid.Not_Empty - - LD A, B - - CP $05 - JR NC, =Is_Solid.Not_Empty - - CP $02 - JR C, =Is_Solid.Not_Empty - - Is_Solid.Empty: +; Is_Solid: ; X in A, Y in B, Result A +; PUSH BC +; PUSH DE +; PUSH HL +; LD C, A +; +; LD D, $00 ; Constructed room number +; LD E, $00 ; Depth +; PUSH DE +; +; Is_Solid.Corridor.loop: +; LD HL, $mem_corridors_array +; POP DE +; LD A, D +; PUSH DE +; SLA A +; SLA A +; SLA A +; OR L +; LD L, A +; +; LD A, (HL+) +; CP $00 ; 0 is horizontal +; JR Z, =Is_Solid.Corridor.horizontal +; +; Is_Solid.Corridor.vertical: +; JR =Is_Solid.Corridor.next +; +; Is_Solid.Corridor.horizontal: +; LD A, (HL+) +; LD D, A +; LD A, (HL+) +; LD E, A +; LD A, (HL+) +; CP B +; JR NZ, =Is_Solid.Corridor.room_update +; LD C, A +; CP D +; JR C, =Is_Solid.Corridor.room_update +; CP E +; JR C, =Is_Solid.NotSolid +; +; Is_Solid.Corridor.room_update: +; LD A, (HL+) +; CP C +; LD A, $00 +; ADC $00 +; POP DE +; SLA D +; OR A +; LD D, A +; PUSH DE +; +; JR =Is_Solid.Corridor.next +; +; Is_Solid.Corridor.next: +; POP DE +; INC E +; LD A, E +; PUSH DE +; CP $04 +; JR NZ =Is_Solid.Corridor.loop +; +; POP DE +; LD A, $01 +; JR =Is_Solid.End +; +; Is_Solid.NotSolid: +; POP DE +; LD A, $00 +; Is_Solid.End: +; +; POP BC +; POP DE +; POP HL +; RET + +Initialize_Room: + LD HL, $mem_room_array LD A, $00 - - JP =Is_Solid.End - Is_Solid.Not_Empty: - LD A, $01 - - Is_Solid.End: - POP DE - POP BC + LD (HL+), A + LD A, $20 + LD (HL+), A + LD A, $00 + LD (HL+), A + LD A, $20 + LD (HL+), A RET + +Is_Solid: ; X in A, Y in B, Result A +; AND $0f +; JR Z, =Is_Solid.Solid +; LD A, B +; AND $07 +; JR Z, =Is_Solid.Solid +; +; +; Is_Solid.NonSolid: +; LD A, $00 +; JR =Is_Solid.End +; +; Is_Solid.Solid: +; LD A, $01 +; +; Is_Solid.End: +; RET + PUSH BC + PUSH DE + PUSH HL + + LD C, A + LD DE, $mem_room_array + + Is_Solid.room_loop: + LD H, D + LD L, E + + LD A, (HL+) + CP C + JR NC, =Is_Solid.room_loop.next + + LD A, (HL+) + CP C + JR C, =Is_Solid.room_loop.next + + LD A, (HL+) + CP B + JR NC, =Is_Solid.room_loop.next + + LD A, (HL+) + CP B + JR NC, =Is_Solid.NonSolid + + Is_Solid.room_loop.next: + LD A, $04 + ADD E + LD E, A + CP $40 + JR NZ, =Is_Solid.room_loop + + LD A, $01 + JR =Is_Solid.End + + Is_Solid.NonSolid: + LD A, $00 + + Is_Solid.End: + POP HL + POP DE + POP BC + RET diff --git a/rng.gbasm b/rng.gbasm new file mode 100644 index 0000000..8649024 --- /dev/null +++ b/rng.gbasm @@ -0,0 +1,70 @@ +Debug_RNG: + LD A, $mem_rng_state_1 + LD HL, $9822 + CALL =Print_8bit + LD A, $mem_rng_state_2 + CALL =Print_8bit + RET + +Initialize_RNG: + LD A, $42 + LD $mem_rng_state_1, A + LD A, $69 + LD $mem_rng_state_2, A + RET + +RNG_Step: + PUSH BC + PUSH DE + + LD A, $mem_rng_state_1 + LD D, A + LD A, $mem_rng_state_2 + LD E, A + + ; state << 7 + SCF + CCF + LD A, $mem_rng_state_2 + LD B, A + LD A, $mem_rng_state_1 + LD C, A + SRA C + RR B + LD C, $00 + RR C + + ; result XOR state + LD A, D + XOR B + LD D, A + + LD A, E + XOR C + LD E, A + + ; state >> 9 + LD C, D + SRA C + + ; result XOR state + LD A, E + XOR C + LD E, A + + ; (state << 8) XOR state + LD A, D + XOR E + LD D, A + + LD A, D + LD $mem_rng_state_1, A + + LD A, E + LD $mem_rng_state_2, A + + POP DE + POP BC + RET + + |