WIP: mbc1 ram access
authorLukas Krickl <lukas@krickl.dev>
Sun, 17 Nov 2024 05:45:02 +0000 (06:45 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sun, 17 Nov 2024 05:45:02 +0000 (06:45 +0100)
src/header.inc
src/hw.inc
src/map.s
src/mem.s
src/wram.s

index 69696a4f1656c10e1199a85c1d2f46eb739cd0a2..14bb7a3e3759b49829e34b862fc4211d71e6d063 100644 (file)
@@ -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 - $
index b44febb03b6383e36acda0ff666319db9b6d8532..9c796c59c9863e9be6a0b9076552375422cc85b3 100644 (file)
@@ -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
index db49b0a0622ea908bff00d91d546a32e052af779..8d25df4ec102fcde343c30fd82df95c07ba7ba44 100644 (file)
--- a/src/map.s
+++ b/src/map.s
 
 
   ; 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
 
index e536848dc93e577460f06587513fdbe61eb45ee8..47ef2531d43e923f0e61fcefed5b52522a3b0d8b 100644 (file)
--- 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
index 58d47d704bfa3e60c5afd818d5f29bb4c0d466d9..aaae8e77fa7aec823e752973451855219833006a 100644 (file)
@@ -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