Skip to content

Commit

Permalink
Update version number and fix function names
Browse files Browse the repository at this point in the history
  • Loading branch information
savaughn committed Mar 2, 2024
1 parent 01c7c40 commit 1dc9f11
Show file tree
Hide file tree
Showing 13 changed files with 287 additions and 130 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,22 @@ jobs:
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Install Test tools
run: |
brew install cunit cppcheck
- name: Build wariosave
run: |
cd lib
mkdir -p build/release
make release
- name: Run Tests
run: |
cppcheck --std=c11 --enable=all --inconclusive --suppress=missingInclude --suppress=missingIncludeSystem --suppress=unusedFunction lib/src/ || true
cd test/
make test
- name: Publish Build Artifacts
uses: actions/upload-artifact@v2
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# lib and example build folder
build/
deps/

.DS_Store
.DS_Store

# test executable
wariosave_test
3 changes: 2 additions & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/example/include",
"${workspaceFolder}/lib/include"
"${workspaceFolder}/lib/include",
"/opt/homebrew/Cellar/cunit/2.1-3/include"
],
"defines": [],
"macFrameworkPath": [
Expand Down
4 changes: 2 additions & 2 deletions example/include/print.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <wariosave.h>

void print_player_save(PlayerSave *save);
void print_save_data(WarioSave *save);
void print_player_save(WS_PlayerSave *save);
void print_save_data(WS_WarioSave *save);

#endif // PRINT_H
16 changes: 8 additions & 8 deletions example/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
int main(int argc, char *argv[])
{
// Complete savefile buffer
WarioGameSave game_save;
WS_WarioGameSave game_save;
// Save slot buffer (3 file slots)
WarioSave save_file[FILE_COUNT];
WS_WarioSave save_file[WS_MAX_FILE_SLOT_COUNT];
// Formatted player save data (3 player saves)
PlayerSave player_save[FILE_COUNT];
WS_PlayerSave player_save[WS_MAX_FILE_SLOT_COUNT];

if (argc != 2)
{
Expand All @@ -23,17 +23,17 @@ int main(int argc, char *argv[])
}

const char *file_path = argv[1];
int error = load_save_to_buffer(&game_save, file_path);
WS_FileError error = ws_load_save_to_buffer(&game_save, file_path);
if (error != NO_ERROR)
{
return error;
}

for (int fileSlot = FILE_A; fileSlot < FILE_COUNT; fileSlot++)
for (uint8_t file_slot = FILE_A; file_slot < FILE_COUNT; file_slot++)
{
save_file[fileSlot] = game_save.save[fileSlot];
initialize_player_save(&save_file[fileSlot], &player_save[fileSlot]);
print_player_save(&player_save[fileSlot]);
save_file[file_slot] = game_save.save[file_slot];
ws_initialize_player_save(&save_file[file_slot], &player_save[file_slot]);
print_player_save(&player_save[file_slot]);
}

return 0;
Expand Down
16 changes: 8 additions & 8 deletions example/src/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@

#include "print.h"

void print_treasures_obtained(PlayerSave *player_save)
void print_treasures_obtained(WS_PlayerSave *player_save)
{
for (int i = 0; i < MAX_TREASURE_COUNT; i++)
for (int i = 0; i < WS_MAX_TREASURE_COUNT; i++)
{
printf("%c ", player_save->treasure.obtained[i] ? treasure_names[i] : '-');
if (i >= MAX_TREASURE_COUNT - 1)
printf("%c ", player_save->treasure.obtained[i] ? WS_treasure_names[i] : '-');
if (i >= WS_MAX_TREASURE_COUNT - 1)
{
printf("\n");
}
}
}

void print_player_save(PlayerSave *save) {
void print_player_save(WS_PlayerSave *save) {
printf("Total Coins: %u\n", save->total_coins);
printf("Hearts: %d\n", save->hearts);
printf("Lives: %d\n", save->lives);
printf("Game Completed: %s\n", save->game_completed ? "true" : "false");
for (int i = 0; i < LEVELS_COUNT; i++) {
printf("%s: %d%%\n", default_level_data[i].name, save->levels[i].completion_rate);
for (int i = 0; i < WS_LEVELS_COUNT; i++) {
printf("%s: %d%%\n", WS_default_level_data[i].name, save->levels[i].completion_rate);
}
printf("Treasure completion rate: %d%%\n", save->treasure.completion_rate);
print_treasures_obtained(save);
}

void print_save_data(WarioSave *save)
void print_save_data(WS_WarioSave *save)
{
printf("sLevelId: %d\n", save->sLevelId);
printf("sTotalCoins_High: %02x\n", save->sTotalCoins_High);
Expand Down
85 changes: 51 additions & 34 deletions lib/include/wariosave/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* (See accompanying file LICENSE.txt or copy at http://opensource.org/licenses/MIT)
*/

#ifndef COMMON_H
#define COMMON_H
#ifndef WS_COMMON_H
#define WS_COMMON_H

#include <stdio.h>
#include <stdlib.h>
Expand All @@ -23,29 +23,37 @@
((byte) & 0x02 ? '1' : '0'), \
((byte) & 0x01 ? '1' : '0')

#define SAVE_FILE_A_OFFSET 0x04
#define SAVE_FILE_B_OFFSET 0x44
#define SAVE_FILE_C_OFFSET 0x84
#define SAVE_FILE_OFFSET 0x40
#define SAVE_STRUCT_SIZE 0x14
#define LEVELS_COUNT 7
#define MAX_COURSE_COUNT 8
#define MAX_LVL_NAME_CHAR 14
#define MAX_COURSE_NAME_CHAR 18
#define MAX_COIN_DIGITS_STR 7
#define MAX_TREASURE_COUNT 15
#define WS_SAVE_FILE_A_OFFSET 0x04
#define WS_SAVE_FILE_B_OFFSET 0x44
#define WS_SAVE_FILE_C_OFFSET 0x84
#define WS_SAVE_FILE_OFFSET 0x40
#define WS_SAVE_STRUCT_SIZE 0x14
#define WS_LEVELS_COUNT 7
#define WS_MAX_COURSE_COUNT 8
#define WS_MAX_LVL_NAME_CHAR 14
#define WS_MAX_COURSE_NAME_CHAR 18
#define WS_MAX_COIN_DIGITS_STR 7
#define WS_MAX_TREASURE_COUNT 15
#define WS_MAX_FILE_SLOT_COUNT 3

typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;

/**
* WS_Level data structure
* name: Name of the level
* course_exit_count: Number of course exits in the level
* completion_bitmask: 8-bit bitmask of course completion
* completion_rate: Completion rate of the level in percentage
*/
typedef struct
{
/**
* Name of the level
* Max length of 14 characters
*/
char name[MAX_LVL_NAME_CHAR];
char name[WS_MAX_LVL_NAME_CHAR];
/**
* Number of course exits in the level
*/
Expand All @@ -58,14 +66,14 @@ typedef struct
* Completion rate of the level in percentage
*/
uint8_t completion_rate;
} Level;
} WS_Level;

/**
* Default level data
* name: Name of the level
* course_exit_count: Number of course exits in the level
*/
static const Level default_level_data[LEVELS_COUNT] = {
static const WS_Level WS_default_level_data[WS_LEVELS_COUNT] = {
{.name = "Rice Beach",
.course_exit_count = 7,
.completion_bitmask = 0,
Expand Down Expand Up @@ -99,15 +107,15 @@ static const Level default_level_data[LEVELS_COUNT] = {
typedef struct
{
uint8_t sLevelId;
// Values 99xxxx stored in dec format. Use get_decimal_bytes to convert to int
// Values 99xxxx stored in dec format. Use ws_get_decimal_bytes to convert to int
uint8_t sTotalCoins_High;
// Values xx99xx stored in dec format. Use get_decimal_bytes to convert to int
// Values xx99xx stored in dec format. Use ws_get_decimal_bytes to convert to int
uint8_t sTotalCoins_Mid;
// Values xxxx99 stored in dec format. Use get_decimal_bytes to convert to int
// Values xxxx99 stored in dec format. Use ws_get_decimal_bytes to convert to int
uint8_t sTotalCoins_Low;
// Value stored in memory in dec format. Use get_decimal_byte to convert to int
// Value stored in memory in dec format. Use ws_get_decimal_byte to convert to int
uint8_t sHearts;
// Value stored in memory in dec format. Use get_decimal_byte to convert to int
// Value stored in memory in dec format. Use ws_get_decimal_byte to convert to int
uint8_t sLives;
// Current powerup value
uint8_t sPlPower;
Expand Down Expand Up @@ -138,11 +146,14 @@ typedef struct
* 1-bit flag of game completion
*/
uint8_t sGameCompleted;
} WarioSave;
} WS_WarioSave;

typedef struct { WarioSave save[3]; } WarioGameSave;
/**
* All three save slots copied into one buffer
*/
typedef struct { WS_WarioSave save[WS_MAX_FILE_SLOT_COUNT]; } WS_WarioGameSave;

static const char treasure_names[MAX_TREASURE_COUNT] = {
static const char WS_treasure_names[WS_MAX_TREASURE_COUNT] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O'
};
typedef enum {
Expand All @@ -161,8 +172,14 @@ typedef enum {
TREASURE_M,
TREASURE_N,
TREASURE_O
} TreasureNames;
} WS_TreasureNames;

/**
* WS_Treasure data structure
* count: count of treasures obtained
* completion_rate: completion rate of the treasures in percentage
* obtained: array of bools representing if the treasure was obtained
*/
typedef struct {
/**
* count of treasures obtained
Expand All @@ -174,11 +191,11 @@ typedef struct {
uint8_t completion_rate;
/**
* array of bools representing if the treasure was obtained
* accessed with TreasureNames enum
* accessed with WS_TreasureNames enum
* EX: treasure.obtained[TREASURE_A]
*/
TreasureNames obtained[MAX_TREASURE_COUNT];
} Treasure;
WS_TreasureNames obtained[WS_MAX_TREASURE_COUNT];
} WS_Treasure;

// Custom save file structure for useful data
typedef struct
Expand All @@ -205,27 +222,27 @@ typedef struct
/**
* Array of level completion rates
*/
Level levels[LEVELS_COUNT];
WS_Level levels[WS_LEVELS_COUNT];
/**
* Treasure data
* WS_Treasure data
*/
Treasure treasure;
} PlayerSave;
WS_Treasure treasure;
} WS_PlayerSave;

typedef enum
{
NO_ERROR = 0,
FILE_ERROR,
MEMORY_ERROR,
READ_ERROR
} FileError;
} WS_FileError;

typedef enum
{
FILE_A = 0,
FILE_B,
FILE_C,
FILE_COUNT
} SaveSlot;
} WS_SaveSlot;

#endif
Loading

0 comments on commit 1dc9f11

Please sign in to comment.