From 17c4e316f89bbefff468e8bfb0c3d1d8af4628b2 Mon Sep 17 00:00:00 2001 From: Starport75 Date: Sat, 2 Sep 2023 21:27:57 -0500 Subject: [PATCH] Save data implementation --- include/save_data_manager.h | 15 +++++++++++++++ source/flash_mem.cpp | 2 +- source/main.cpp | 12 +++++++++--- source/pokedex.cpp | 5 +++-- source/save_data_manager.cpp | 31 ++++++++++++++++++++++++++++--- 5 files changed, 56 insertions(+), 9 deletions(-) diff --git a/include/save_data_manager.h b/include/save_data_manager.h index e69de29..b5d6a4a 100644 --- a/include/save_data_manager.h +++ b/include/save_data_manager.h @@ -0,0 +1,15 @@ +#ifndef SAVE_DATA_MANAGER_H +#define SAVE_DATA_MANAGER_H + +#include + +#define HALL_OF_FAME 0x01C000 +#define MYSTERY_GIFT 0x01E000 +#define HOF_SECTION 2032 + +void load_save_data(); +void write_save_data(); +bool is_caught(int dex_num); +void set_caught(int dex_num); + +#endif diff --git a/source/flash_mem.cpp b/source/flash_mem.cpp index 5bebf6a..1bf6271 100644 --- a/source/flash_mem.cpp +++ b/source/flash_mem.cpp @@ -8,7 +8,7 @@ vu32 newest_save_offset = MEM_CRAM + SAVE_A_OFFSET; vu32 memory_section_array[14] = {}; -u8 memory_buffer[0x1000]; +u8 memory_buffer[1]; char mem_name = 'A'; diff --git a/source/main.cpp b/source/main.cpp index 3ec22b3..3274ae1 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -4,7 +4,7 @@ #include #include "debug.h" -#include "flash_mem.h" +//#include "flash_mem.h" #include "gba_flash.h" #include "interrupt.h" #include "gb_link.h" @@ -26,6 +26,7 @@ #include "pokedex.h" #include "global_frame_counter.h" #include "pkmn_font.h" +#include "save_data_manager.h" /*TODO: -------- @@ -56,6 +57,11 @@ INJECTION: - Randomize base seed - Enable ribbon viewing +SAVE DATA: +- Add warning +- Add ability to erase +- Add check for Hall of Fame + TESTING: - Test all the aspects of a Pokemon (Shiny, Pokerus, etc.) - Test invalid moves @@ -106,10 +112,10 @@ int main(void) irq_enable(II_VBLANK); flash_init(FLASH_SIZE_128KB); - initalize_memory_locations(); + //initalize_memory_locations(); + load_save_data(); rand_set_seed(0x12162001); init_text_engine(); - add_script_party_var(party); // Sound bank init diff --git a/source/pokedex.cpp b/source/pokedex.cpp index bd71b86..1030938 100644 --- a/source/pokedex.cpp +++ b/source/pokedex.cpp @@ -7,6 +7,7 @@ #include "sprite_data.h" #include "pokemon_data.h" #include "global_frame_counter.h" +#include "save_data_manager.h" Dex dex_array[DEX_MAX]; int dex_shift = 0; @@ -74,9 +75,9 @@ int pokedex_loop() for (int i = 0; i < DEX_MAX; i++) { tte_set_pos(dex_x_cord + (1 * 8), (i * 8 * 3) + 16); - tte_write("^"); + tte_write(is_caught(dex_shift + i + 1) ? "^" : " "); tte_set_pos(dex_x_cord + (3 * 8), (i * 8 * 3) + 16); - tte_write(std::string(NAMES[dex_shift + i]).data()); + tte_write(is_caught(dex_shift + i + 1) ? std::string(NAMES[dex_shift + i]).data() : "----------"); tte_set_pos(dex_x_cord + (14 * 8), (i * 8 * 3) + 16); tte_write("000"); if(dex_shift + i + 1 < 10){ diff --git a/source/save_data_manager.cpp b/source/save_data_manager.cpp index 97d44ad..007a487 100644 --- a/source/save_data_manager.cpp +++ b/source/save_data_manager.cpp @@ -1,6 +1,31 @@ #include +#include "save_data_manager.h" #include "gba_flash.h" -#define HALL_OF_FAME 0x01C000 -#define MYSTERY_GIFT 0x01E000 -#define HOF_SECTION 3968 +u8 save_data_buffer[0x1000]; + + +void load_save_data(){ + flash_read(HALL_OF_FAME + 0x1000, &save_data_buffer[0], 0x1000); +} + +void write_save_data(){ + flash_write(HALL_OF_FAME + 0x1000, &save_data_buffer[0], 0x1000); +} + +bool is_caught(int dex_num){ + return (((save_data_buffer[HOF_SECTION + (dex_num / 8)]) >> dex_num % 8) & 1); +} + +void set_caught(int dex_num){ + save_data_buffer[HOF_SECTION + (dex_num / 8)] = save_data_buffer[HOF_SECTION + (dex_num / 8)] | (1 << (dex_num % 8)); +} + +/* Data map: + +Byte 0: Has made it through the tutorial +0 - 31: Caught data + + + +*/ \ No newline at end of file