From: Lukas Krickl Date: Sun, 17 Nov 2024 05:45:02 +0000 (+0100) Subject: WIP: mbc1 ram access X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=cb7ccdefcb7e86fad3db0a616165ba02f2fdac66;p=gbrg%2F.git WIP: mbc1 ram access --- diff --git a/src/header.inc b/src/header.inc index 69696a4..14bb7a3 100644 --- a/src/header.inc +++ b/src/header.inc @@ -12,7 +12,11 @@ logo_end: ; cartride type ; MBC1+RAM+Battery -.db 0x02 -.fill 0, 0x14D - $ +.db 0x03 + ; rom size 32K +.db 0x00 + ; ram size 8k +.db 0x02 +.fill 0, 0x14B - $ .chksm .fill 0, 0x150 - $ diff --git a/src/hw.inc b/src/hw.inc index b44febb..9c796c5 100644 --- a/src/hw.inc +++ b/src/hw.inc @@ -88,6 +88,6 @@ ; MBC1 registers ; write 0xA here to enable sram -#define SRAM_ENABLE 0x0000 -#define ROM_BANKSEL 0x2000 -#define SRAM_BANKSEL 0x4000 +#define MBC1_SRAM_ENABLE 0x0000 +#define MBC1_ROM_BANKSEL 0x2000 +#define MBC1_SRAM_BANKSEL 0x4000 diff --git a/src/map.s b/src/map.s index db49b0a..8d25df4 100644 --- a/src/map.s +++ b/src/map.s @@ -28,9 +28,10 @@ ; maps: - ; a map is a collection of room struct pointers + ; a map is a collection of room structs ; of n*m rooms. when a player leaves a room ; they will transition to the map to the north/south/east/west + ; a map also contains a memory region for all the room's tables ; room: ; a room is a collection of tiles, falgs and actor tables diff --git a/src/mem.s b/src/mem.s index e536848..47ef253 100644 --- a/src/mem.s +++ b/src/mem.s @@ -15,6 +15,8 @@ mem_init: ld a, GM_GAME ld [game_mode], a + call mbc1_ram_enable + ret ; copies memory from one location to another @@ -64,3 +66,19 @@ shadow_oam_to_oam: jr nz, @wait REL ret shadow_oam_to_oam_end: + +; MBC1 functions + + ; ram enable mbc1 + ; TODO: it is reccomended to disable ram when not + ; using it! +mbc1_ram_enable: + ld a, 0xA + ld [MBC1_SRAM_ENABLE], a + ret + + +mbc1_ram_disable: + xor a, a + ld [MBC1_SRAM_ENABLE], a + ret diff --git a/src/wram.s b/src/wram.s index 58d47d7..aaae8e7 100644 --- a/src/wram.s +++ b/src/wram.s @@ -70,16 +70,12 @@ player: .adv player_size ; pause all other update execution until then damage_anim: .adv 1 +; map region + #define MAP_W 10 #define MAP_H 10 #define MAP_TOTAL_ROOMS MAP_W * MAP_H -; struct map -.se 0 -; list of room pointers -.de map_room_ptrs, 2 * MAP_TOTAL_ROOMS -.de map_size, 0 - ; rooms are 9x9 meta tiles #define ROOM_W 10 #define ROOM_H 8 @@ -98,6 +94,7 @@ damage_anim: .adv 1 ; current room struct ; same layout as room struct itself + ; always should point at the current map's memory region curr_room_struct: ; pointer to current room struct curr_room: .adv 2