Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve rom info #146

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from

Conversation

networkfusion
Copy link
Collaborator

@networkfusion networkfusion commented Oct 14, 2024

Description

In this PR I have changed the ROM file that provides the "override" settings to be a more generic file that is able to handle more situations related to the ROM information.

The file can now contain the ROM description, and also contains whether the ROM enables GS and patch support (for future use).

To use it, a "group name" needs adding to the ROM specific ini:

[metadata]
desscription=This is the description of the ROM I wish to load.

which if availiable, is added to the ROM load screen.

Old ROM ini files will probably be broken as the override parameters have also been added to a "group name" [custom_boot], so you would either need to manually adjust the file or re 'set' the overridden parameters in the menu.

Motivation and Context

Works towards a "descriptive" ROM load system.

How Has This Been Tested?

Screenshots

Types of changes

  • Improvement (non-breaking change that adds a new feature)
  • Bug fix (fixes an issue)
  • Breaking change (breaking change)
  • Documentation Improvement
  • Config and build (change in the configuration and build system, has no impact on code or features)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Signed-off-by: GITHUB_USER <GITHUB_USER_EMAIL>

Summary by CodeRabbit

  • New Features

    • Enhanced ROM information handling with new metadata fields including description, cheats enabled, and patches enabled.
    • Improved display of ROM metadata in the user interface, showing dynamic descriptions and the status of cheats and patches.
  • Bug Fixes

    • Resolved issues with displaying static ROM descriptions by implementing dynamic formatting.
  • Documentation

    • Updated comments and structure definitions to clarify the purpose of new fields and functions.

@networkfusion networkfusion changed the base branch from main to develop October 14, 2024 20:54
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Inline review comments failed to post

Actionable comments posted: 20

🧹 Outside diff range and nitpick comments (45)
src/menu/actions.h (1)

14-14: LGTM! Consider adding documentation for the new function.

The addition of actions_init is a good improvement, likely for initializing the actions module. Its declaration follows proper C conventions and is consistently placed within the file.

To enhance code maintainability, consider adding a brief documentation comment for this new function, similar to how the file itself is documented. For example:

/**
 * @brief Initialize the actions module
 */
void actions_init(void);
src/menu/sound.h (3)

15-21: LGTM: Well-structured sound effect enum

The sound_effect_t enum is a good addition, providing a clear and structured way to represent different sound effects. The naming is consistent and descriptive, covering common UI interactions.

Consider adding a brief comment above the enum to describe its purpose and usage. For example:

/**
 * @brief Enumeration of available sound effects for menu interactions.
 */
typedef enum {
    // ... (existing enum members)
} sound_effect_t;

26-27: LGTM: New sound effect initialization and control functions

The addition of sound_init_sfx() and sound_use_sfx(bool) functions is consistent with the existing sound initialization functions and provides necessary control over sound effects.

Consider adding brief documentation for these new functions to improve clarity. For example:

/**
 * @brief Initialize sound effects system.
 */
void sound_init_sfx(void);

/**
 * @brief Enable or disable sound effects.
 * @param enable True to enable sound effects, false to disable.
 */
void sound_use_sfx(bool enable);

28-28: LGTM: New function to play sound effects

The addition of sound_play_effect(sound_effect_t sfx) provides a clear way to play specific sound effects using the sound_effect_t enum.

Consider adding brief documentation for this new function to improve clarity. For example:

/**
 * @brief Play a specified sound effect.
 * @param sfx The sound effect to play, as defined in sound_effect_t.
 */
void sound_play_effect(sound_effect_t sfx);
.devcontainer/Dockerfile (1)

Line range hint 1-17: Consider pinning the MIPS64 GCC toolchain version.

While updating the SC64 deployer version is good for keeping the project up-to-date, it's worth noting that the MIPS64 GCC toolchain version is not specified. For better reproducibility and to avoid potential issues with future toolchain updates, consider pinning this version as well.

You could modify the relevant line to include a specific version, like this:

-    wget https://github.com/DragonMinded/libdragon/releases/download/toolchain-continuous-prerelease/gcc-toolchain-mips64-x86_64.deb && \
+    wget https://github.com/DragonMinded/libdragon/releases/download/toolchain-9.1.0/gcc-toolchain-mips64-x86_64.deb && \

Replace 9.1.0 with the desired version. Make sure to check the libdragon releases page for the latest stable version.

src/menu/views/flashcart_info.c (3)

8-8: Approved: Enhanced user feedback with sound effect

The addition of sound_play_effect(SFX_EXIT) when the back action is invoked improves user interaction by providing audio feedback. This is a good enhancement to the user experience.

Consider defining a constant for the sound effect (e.g., SOUND_EFFECT_BACK) to improve code readability and maintainability.


22-24: Approved: Improved user communication

The addition of the message "This feature is not yet supported." provides clear information to the user about the current state of the flashcart information feature. This improves user communication and aligns with the PR objectives.

Consider using a constant for the message text to facilitate easier updates and potential localization in the future. For example:

#define FLASHCART_INFO_NOT_SUPPORTED_MSG "This feature is not yet supported."

// In the draw function
component_main_text_draw(
    ALIGN_CENTER, VALIGN_TOP,
    "FLASHCART INFORMATION\n\n\n"
    FLASHCART_INFO_NOT_SUPPORTED_MSG "\n\n"
);

27-31: Consider using a task tracking system for future enhancements

The added comments provide valuable information about planned improvements to the flashcart information display. However, it's generally better to use a task tracking system (like GitHub Issues) for managing future enhancements rather than inline comments in the code.

Would you like me to create GitHub issues for these planned enhancements? This would help in tracking the progress of these features and keep the codebase clean.

If you prefer to keep these as comments, consider using a standardized format like:

// TODO: Display cart type, firmware version, and supported features (flashcart_features_t)
src/menu/views/error.c (2)

8-8: LGTM: Sound effect for back action.

The addition of sound_play_effect(SFX_EXIT); provides appropriate auditory feedback when the user navigates back from the error screen.

Consider moving the sound effect call before setting menu->next_mode for consistency with other similar patterns in the codebase:

 if (menu->actions.back) {
+    sound_play_effect(SFX_EXIT);
     menu->next_mode = MENU_MODE_BROWSER;
-    sound_play_effect(SFX_EXIT);
 }

53-55: LGTM: Sound effect for error display.

The addition of sound_play_effect(SFX_ERROR); provides appropriate auditory feedback when an error message is displayed.

Consider adding error handling for the sound_play_effect call to ensure robustness:

+    if (sound_play_effect(SFX_ERROR) != SOUND_OK) {
+        debugf("Failed to play error sound effect\n");
+    }
     menu->next_mode = MENU_MODE_ERROR;
     menu->error_message = error_message;

This change assumes the existence of a SOUND_OK status and a debugf function for logging. Adjust as necessary based on your project's conventions.

src/menu/views/rtc.c (2)

22-22: LGTM: Sound effect addition enhances user feedback

The addition of the sound_play_effect(SFX_EXIT) call provides auditory feedback when the user exits the menu, which is a good UX improvement.

Consider defining an enum or constants for the different sound effects (if not already done) to improve code readability and maintainability. For example:

typedef enum {
    SFX_EXIT,
    SFX_ENTER,
    // ... other sound effects
} SoundEffect;

This would make it clearer what sound effects are available throughout the application.


39-39: LGTM: Updated user instructions provide more options

The modification to include information about setting the date and time via a game is a good addition, providing users with more options.

Consider clarifying the phrase "a game that uses it" to be more specific. For example:

-        "application and set via USB or a game that uses it.\n\n"
+        "application and set via USB or a compatible N64 game with RTC support.\n\n"

This change would make it clearer to users what kind of games can be used for this purpose.

src/menu/views/credits.c (1)

16-16: LGTM: Added sound effect for menu navigation.

The addition of sound_play_effect(SFX_EXIT); enhances user experience by providing audio feedback when exiting the credits view. This is a good improvement to the menu navigation.

Consider adding error handling for the sound_play_effect call, in case the sound system fails to initialize or the effect doesn't exist:

if (sound_play_effect(SFX_EXIT) != SOUND_OK) {
    // Log error or handle gracefully
}

This assumes that sound_play_effect returns a status code. If it doesn't, you can disregard this suggestion.

src/menu/views/system_info.c (2)

31-33: LGTM: Sound effect for menu exit

The addition of sound_play_effect(SFX_EXIT); when exiting the system info view is a good improvement for user experience. It provides auditory feedback to the user's action.

For improved clarity, consider adding a brief comment explaining the purpose of this sound effect:

 if (menu->actions.back) {
     menu->next_mode = MENU_MODE_BROWSER;
+    // Play exit sound effect when leaving the system info view
     sound_play_effect(SFX_EXIT);
 }

Line range hint 1-91: Consider adding sound effects for consistency

The addition of a sound effect for exiting the system info view enhances user feedback. For consistency, consider adding appropriate sound effects to other user interactions within this view, if applicable. This could include sounds for navigation or selection of options, providing a more cohesive auditory experience throughout the menu system.

Would you like assistance in identifying potential places to add sound effects for other user interactions?

src/menu/settings.c (2)

42-42: LGTM: Consistent loading of sound_enabled setting

The change to load sound_enabled from the "menu" section is consistent with its new status as a regular setting rather than a beta feature. This aligns well with the initialization in the init structure.

For consistency with other settings, consider adding a TODO comment similar to the one for pal60_enabled:

-    settings->sound_enabled = mini_get_bool(ini, "menu", "sound_enabled", init.sound_enabled);
+    settings->sound_enabled = mini_get_bool(ini, "menu", "sound_enabled", init.sound_enabled); // TODO: consider changing file setting name

This maintains consistency in code style and reminds developers to review the setting name in the future if needed.


58-58: LGTM: Consistent saving of sound_enabled setting

The change to save sound_enabled to the "menu" section is consistent with the loading function and the overall structure of the settings. This ensures that the setting is properly persisted and retrieved.

For consistency with other settings, consider grouping similar settings together:

 mini_set_bool(ini, "menu", "pal60", settings->pal60_enabled);
 mini_set_bool(ini, "menu", "show_protected_entries", settings->show_protected_entries);
+mini_set_bool(ini, "menu", "sound_enabled", settings->sound_enabled);
 mini_set_string(ini, "menu", "default_directory", settings->default_directory);
 mini_set_bool(ini, "menu", "use_saves_folder", settings->use_saves_folder);
-mini_set_bool(ini, "menu", "sound_enabled", settings->sound_enabled);

This groups all boolean settings together, improving readability and maintainability.

docs/99_developer_guide.md (1)

Line range hint 67-77: Great addition! Consider clarifying the purpose.

The new instructions for testing generated documentation in the dev-container are a valuable addition. They provide clear steps for setting up the environment and serving the documentation locally, which is crucial for ensuring the quality of documentation changes.

Consider adding a brief explanation of why testing the generated docs locally is important. For example:

 ### Test generated docs in the dev-container
+Testing the documentation locally allows you to preview changes and ensure everything renders correctly before submitting your changes.
+
 Install Prerequisites:
 ```bash
 apt-get install ruby-full build-essential zlib1g-dev
 gem install jekyll bundler

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 Markdownlint</summary><blockquote>

9-9: Punctuation: ':'
Trailing punctuation in heading

(MD026, no-trailing-punctuation)

</blockquote></details>

</details>

</blockquote></details>
<details>
<summary>docs/00_getting_started_sd.md (1)</summary><blockquote>

`3-16`: **Excellent additions for flashcart-specific instructions!**

The new sections for SC64 and other supported flashcarts provide clear and specific instructions, which aligns well with the PR objective of enhancing ROM file versatility. This improvement will help users set up their SD cards correctly based on their flashcart type.



Consider adjusting the heading levels for consistency:

```diff
-#### SC64
+### SC64

-#### Other supported flashcarts
+### Other supported flashcarts

This change will maintain a consistent heading hierarchy throughout the document.

🧰 Tools
🪛 Markdownlint

4-4: Expected: h3; Actual: h4
Heading levels should only increment by one level at a time

(MD001, heading-increment)

src/menu/views/image_viewer.c (3)

2-2: LGTM! Consider grouping related headers.

The inclusion of "../sound.h" is appropriate for adding sound functionality to the image viewer.

Consider grouping related headers together. You might want to move this include statement next to other menu-related headers for better organization.


44-44: LGTM! Sound effects enhance user experience.

The addition of sound effects for navigation actions is a good improvement to the user interface. The placement and choice of sounds (SFX_EXIT for back action, SFX_ENTER for enter action) are appropriate and consistent with user expectations.

For consistency, consider adding a sound effect for the case when show_message becomes false without changing the mode (line 46). This would provide audio feedback for all user interactions.

Also applies to: 53-53


Sound Effects Implementation Issues Identified

The verification process revealed the following issues with the sound effects implementation:

  • Missing Sound File: exit.wav is not present in the assets directory. This will prevent the SFX_EXIT sound effect from playing.
  • Improper Linking: The sfx_exit and sfx_enter sound effects are not properly initialized in sound.c, resulting in sound effects not being loaded correctly.

Recommended Actions:

  1. Add exit.wav to Assets:

    • Ensure that the exit.wav file is added to the assets directory.
    • Verify the file's integrity and compatibility with the application.
  2. Initialize Sound Effects in sound.c:

    • Update sound.c to load sfx_exit and sfx_enter correctly. For example:
      void sound_init_mp3_playback(void) {
          sfx_exit = wav64_load("assets/exit.wav");
          sfx_enter = wav64_load("assets/enter.wav");
          // ... other initialization code
      }
    • Confirm that the initialization function is called appropriately during the application's startup.
  3. Test Sound Playback:

    • After adding the sound file and updating the code, perform tests to ensure that both SFX_EXIT and SFX_ENTER play as expected during user interactions.
    • Adjust volume levels if necessary to maintain consistency with other UI sounds.
🔗 Analysis chain

Line range hint 1-138: Overall, good improvements to user feedback.

The changes in this file successfully implement sound effects for user actions in the image viewer, enhancing the user experience. The modifications are minimal, well-placed, and align with the PR objectives.

To ensure the sound effects are working as intended, please verify:

  1. The correct sound files are available and properly linked.
  2. The sound effects play correctly during navigation in the image viewer.
  3. The volume levels are appropriate and consistent with other UI sounds in the application.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify sound-related files and usage
echo "Checking for sound.h file:"
fd --type f "sound.h"

echo "\nChecking for sound effect definitions:"
rg --type c "SFX_EXIT|SFX_ENTER" -C 3

echo "\nChecking for other uses of sound_play_effect:"
rg --type c "sound_play_effect" -C 3

Length of output: 20926


Script:

#!/bin/bash
# Verify the availability of sound files associated with SFX_EXIT and SFX_ENTER

echo "Checking for sound files related to SFX_EXIT and SFX_ENTER:"

# Assuming sound files have common audio extensions
fd --type f -e wav -e mp3 -e ogg -e flac | rg -i "exit|enter"

echo "\nVerifying that sound files are properly linked in sound.c:"

# Check if sound effects are linked to specific files in sound.c
ast-grep --lang c --pattern $'
void sound_init_mp3_playback {
  $$$
  sfx_exit = wav64_load("$_");
  sfx_enter = wav64_load("$_");
  $$$
}
'

Length of output: 482


Script:

#!/bin/bash
# Check for the existence of exit.wav
echo "Checking for exit.wav in assets:"
fd --type f -e wav -e mp3 -e ogg -e flac | rg -i "exit"

echo "\nVerifying the linking of sfx_exit and sfx_enter in sound.c:"

# Use a broader pattern to find how sfx_exit and sfx_enter are loaded
ast-grep --lang c --pattern $'
void sound_init_$$$ {
  $$$
  sfx_exit = wav64_load("$_");
  sfx_enter = wav64_load("$_");
  $$$
}
'

Length of output: 396

src/menu/views/load_emulator.c (2)

39-41: LGTM: Exit sound effect added

The addition of sound_play_effect(SFX_EXIT); enhances the user experience by providing auditory feedback when exiting the emulator loading view. This is a good improvement.

For consistency, consider adding a sound effect for the enter action as well. This would provide a balanced audio experience for user interactions.


Line range hint 1-150: Overall review: Sound integration enhances user experience

The changes in this file successfully integrate sound functionality into the emulator loading process. The addition of an exit sound effect improves user feedback without disrupting the existing logic. The modifications are minimal and well-placed.

Consider the following suggestions for further improvement:

  1. Add sound effects for other user actions (e.g., when entering the emulator loading view) to provide a consistent audio experience.
  2. Ensure that the sound effects are tested across different emulator types to confirm they work as expected in all scenarios.
src/menu/views/text_viewer.c (1)

59-59: LGTM: Sound effect for exit action

The addition of sound_play_effect(SFX_EXIT); enhances user feedback when navigating back from the text viewer. This is a good improvement to the user experience.

Consider adding error handling for the sound_play_effect call if the sound module's implementation requires it. For example:

if (sound_play_effect(SFX_EXIT) != SOUND_OK) {
    // Handle error or log it
}
Makefile (2)

80-85: LGTM! Consider adding documentation for the new sound assets.

The addition of the SOUNDS variable with various .wav files is a good enhancement, aligning with the PR's objective to improve ROM capabilities.

Consider adding a comment above the SOUNDS variable to briefly explain the purpose of these sound assets and how they will be used in the project.


107-109: LGTM! Consider adding a comment explaining the audio conversion process.

The new rule for generating .wav64 files is correctly implemented and necessary for processing the newly added sound assets.

Consider adding a brief comment above this rule to explain the purpose of the .wav64 format and why this conversion is necessary for the N64 platform. This would improve the maintainability of the Makefile.

src/menu/components/background.c (1)

Line range hint 1-224: Overall assessment of changes in background.c

The changes in this file appear to be improvements in terms of code clarity and potentially efficiency. The simplification of the rectangle filling for image darkening and the relocation of image center calculations seem logical. However, it's crucial to ensure these changes don't introduce any regressions or unintended side effects.

To maintain the integrity of the codebase:

  1. Verify that the darkening process still works as expected with the simplified rectangle filling.
  2. Confirm that relocating the image center calculations doesn't affect any dependent operations.
  3. Run thorough tests on the background component to ensure all functionalities remain intact.

Consider adding unit tests for the prepare_background function if they don't already exist. This would help catch any potential issues introduced by these or future changes.

README.md (3)

52-90: Excellent addition of GamePak sprites documentation

The new "GamePak sprites" section under "Experimental features" is a comprehensive and well-structured addition to the README. It provides clear guidelines on using PNG files for N64 GamePak sprites, including supported dimensions, file naming conventions, and directory structure. The inclusion of a compatibility mode for deprecated naming conventions is thoughtful.

Suggestion for improvement:
Consider adding a brief note about the potential impact on menu performance or loading times when using GamePak sprites, especially for users with large ROM collections.


124-128: Great addition of sound attribution and licensing

The new "Sounds" subsection under "Open source software and licenses used" is a valuable addition. It properly attributes the sources of the menu sound effects and provides clear licensing information. This demonstrates good open-source practices and legal compliance.

Suggestion for improvement:
Consider adding a brief note about how users can customize or replace these sounds, if that's a possibility. This could enhance the user experience for those who might want to personalize their menu sounds.


Line range hint 1-128: Overall excellent improvements to README documentation

The changes to the README.md file significantly enhance the documentation quality and completeness. Key improvements include:

  1. Addition of menu sound effects to the feature list.
  2. Comprehensive documentation on GamePak sprites usage.
  3. Proper attribution and licensing information for sound effects.

These changes align well with the PR objectives and provide valuable information for users and contributors. The document structure remains clear and well-organized.

Suggestion for future improvement:
Consider adding a table of contents at the beginning of the README to help users navigate the growing amount of information more easily.

src/menu/components/constants.h (2)

78-80: LGTM! Consider adding a brief comment explaining 64DD.

The addition of constants for 64DD box art dimensions is a good improvement for supporting different types of box art.

Consider adding a brief comment explaining what 64DD stands for (Nintendo 64 Disk Drive) for better clarity, especially for developers who might not be familiar with the term.


91-99: LGTM! Consider minor improvements for consistency and clarity.

The addition of constants for different box art positions is a good improvement, allowing for precise layout control.

  1. Consider standardizing the abbreviation format in constant names:
    • Either use BOXART_X_JP and BOXART_X_DD, or BOXART_X_JPN and BOXART_X_64DD for consistency.
  2. In the comments, "caratules" might be a typo. Did you mean "cartridges" or is this a specific term?
  3. Consider adding a brief comment explaining the calculation for each position, which could help future maintenance.
src/menu/rom_info.h (3)

226-230: Add documentation for the new settings structure.

The addition of the settings structure with cheats_enabled and patches_enabled flags is a good improvement for fine-grained control. However, to enhance clarity and maintainability, consider adding brief documentation for these new fields.

Consider adding comments like this:

struct {
    /** @brief Flag to enable or disable cheats for this ROM. */
    bool cheats_enabled;
    /** @brief Flag to enable or disable patches for this ROM. */
    bool patches_enabled;
} settings;

232-235: Add documentation and consider null-termination for the description field.

The addition of the metadata structure with a description field is a good improvement for storing additional ROM information. However, consider the following suggestions:

  1. Add documentation for the new field to enhance clarity.
  2. Ensure null-termination for the description to prevent potential issues.

Consider updating the structure like this:

struct {
    /** @brief Additional description or notes about the ROM (null-terminated). */
    char description[256];
} metadata;

Also, ensure that any function filling this field guarantees null-termination, perhaps by using strncpy with an explicit null terminator:

strncpy(rom_info->metadata.description, source, sizeof(rom_info->metadata.description) - 1);
rom_info->metadata.description[sizeof(rom_info->metadata.description) - 1] = '\0';

238-239: Add documentation for the new function declarations.

The addition of rom_info_get_cic_seed and rom_info_load function declarations is consistent with the changes to the rom_info_t structure. However, to improve usability and maintainability, consider adding brief documentation for these functions.

Consider adding comments like this:

/**
 * @brief Retrieves the CIC seed for the given ROM information.
 * @param rom_info Pointer to the ROM information structure.
 * @param seed Pointer to store the retrieved CIC seed.
 * @return true if the CIC seed was successfully retrieved, false otherwise.
 */
bool rom_info_get_cic_seed(rom_info_t *rom_info, uint8_t *seed);

/**
 * @brief Loads ROM information from the specified path.
 * @param path Pointer to the path structure containing the ROM file location.
 * @param rom_info Pointer to the ROM information structure to be filled.
 * @return ROM_OK if successful, or an appropriate error code otherwise.
 */
rom_err_t rom_info_load(path_t *path, rom_info_t *rom_info);
src/flashcart/sc64/sc64.c (1)

257-258: LGTM! Consider updating documentation.

The addition of FLASHCART_FEATURE_AUTO_CIC and FLASHCART_FEATURE_AUTO_REGION features is a good improvement. These features can enhance compatibility and user experience.

Consider updating the relevant documentation to reflect these new features, ensuring users and developers are aware of the SC64's expanded capabilities.

src/menu/sound.c (1)

62-83: Consider logging unrecognized sound effects in sound_play_effect

In the default case of the switch statement within sound_play_effect, no action is taken if an unrecognized sfx value is passed. Adding a log message can help with debugging unexpected values.

For example:

        default:
+           // Log a warning about the unrecognized sound effect
+           debugf("Warning: Unrecognized sound effect %d\n", sfx);
            break;
src/menu/components/boxart.c (2)

87-88: Redundant if statement can be removed

The nested if (file_exists(path_get(path))) at line 88 is redundant since the same condition is already checked at line 87. This redundant check can be removed to simplify the code.

Apply this diff to simplify the code:

     if (file_exists(path_get(path))) {
-        if (file_exists(path_get(path))) {
             if (png_decoder_start(path_get(path), BOXART_WIDTH_MAX, BOXART_HEIGHT_MAX, png_decoder_callback, b) == PNG_OK) {
                 path_free(path);
                 return b;
             }
-        }
     }

133-143: Consider handling additional image dimensions

In the component_boxart_draw function, the conditions adjust box_x and box_y based on specific image dimensions. Consider handling cases where the image dimensions are outside the expected ranges to ensure proper rendering or provide fallback values.

You might want to add an else clause to handle unexpected image sizes or log a warning for easier debugging.

src/menu/menu.c (1)

30-31: Consider making INTERLACED and FPS_LIMIT user-configurable settings

Defining INTERLACED and FPS_LIMIT as constants limits flexibility. Consider making these values configurable through the settings to allow users to adjust display preferences according to their needs.

src/menu/views/settings_editor.c (1)

48-51: Implement the set_use_default_settings function to restore default settings

The function set_use_default_settings is currently commented out with a FIXME note, indicating that its implementation is pending. Implementing this function will allow users to restore the menu settings to their default values, enhancing usability.

Would you like assistance in implementing this function? I can help provide a solution or open a new GitHub issue to track this task.

src/menu/views/load_rom.c (2)

103-103: Avoid hardcoding multiple newline characters in 'format_rom_description'

Using multiple \n characters to create vertical space can lead to inconsistent layouts and is not optimal. Consider handling spacing within the layout or formatting functions to maintain consistent styling.

You might adjust the return statement as follows:

- return description[0] == '\0' ? "None.\n\n\n\n\n\n\n" : description;
+ return description[0] == '\0' ? "None." : description;

And manage the spacing in the calling function or through styling.


125-127: Consider making 'format_boolean_type' function inline

For a small utility function like format_boolean_type, making it inline can improve performance by avoiding function call overhead.

Apply this change:

-static const char *format_boolean_type (bool bool_value) {
+static inline const char *format_boolean_type (bool bool_value) {
    return bool_value ? "On" : "Off";
}
src/menu/rom_info.c (1)

921-921: Clarify the return value in rom_info_get_cic_seed

The return statement in rom_info_get_cic_seed might be confusing:

return (!rom_info->boot_override.cic);

Consider adding a comment to explain why the function returns the negation of rom_info->boot_override.cic to improve readability and maintainability.

🛑 Comments failed to post (20)
src/menu/sound.h (1)

13-13: 💡 Codebase verification

Conflict Detected: Channel number 2 is already in use

The SOUND_SFX_CHANNEL is assigned the value 2, which is already used in src/menu/mp3_player.c for .channels = 2. Please choose a different, unique channel number to avoid potential conflicts in the sound system.

  • Location of conflict: src/menu/mp3_player.c
🔗 Analysis chain

LGTM: New sound effects channel defined, but clarification needed

The addition of SOUND_SFX_CHANNEL is good for separating sound effects from MP3 playback. The use of parentheses in the macro definition is a good practice.

Could you please clarify why the specific value of 2 was chosen for this channel? It would be helpful to understand if there's a particular reason for this choice or if it's related to the underlying audio system.

To verify the uniqueness of this channel number, let's run the following script:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any other occurrences of channel number 2 in the codebase

# Test: Search for other occurrences of channel number 2
rg --type c --type cpp --type h "channel.*2" -g '!src/menu/sound.h'

Length of output: 114

src/flashcart/flashcart.h (1)

32-33: 💡 Codebase verification

Action Required: Update flashcart.c to handle new flashcart_features_t enum values.

The switch statements in flashcart.c currently do not handle FLASHCART_FEATURE_AUTO_CIC and FLASHCART_FEATURE_AUTO_REGION. To ensure consistent behavior across the codebase, please add cases for these new enum values. For example:

switch (feature) {
    case FLASHCART_FEATURE_64DD: return true;
    case FLASHCART_FEATURE_RTC: return true;
    case FLASHCART_FEATURE_USB: return true;
    case FLASHCART_FEATURE_AUTO_CIC: return true;
    case FLASHCART_FEATURE_AUTO_REGION: return true;
    default: return false;
}

This update will ensure that the new features are recognized and handled appropriately within flashcart.c.

🔗 Analysis chain

LGTM! Consider adding explanatory comments.

The addition of FLASHCART_FEATURE_AUTO_CIC and FLASHCART_FEATURE_AUTO_REGION to the flashcart_features_t enum is appropriate and aligns with the PR objectives of enhancing ROM-related capabilities. These new features will likely improve the versatility of the flashcart system.

Consider adding brief comments to explain each enum value, including the new ones. This would improve the overall documentation and make it easier for other developers to understand the purpose of each feature. For example:

typedef enum {
    FLASHCART_FEATURE_64DD,       /**< Support for 64DD functionality */
    FLASHCART_FEATURE_RTC,        /**< Real-Time Clock support */
    FLASHCART_FEATURE_USB,        /**< USB connectivity support */
    FLASHCART_FEATURE_AUTO_CIC,   /**< Automatic CIC (Copy Protection) detection */
    FLASHCART_FEATURE_AUTO_REGION /**< Automatic region detection */
} flashcart_features_t;

Let's verify the impact of these new features on the rest of the codebase:

This script will help us identify any areas of the codebase that might need to be updated to handle these new enum values.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for usage of the new enum values and potential impacts

# Search for direct usage of the new enum values
echo "Searching for direct usage of new enum values:"
rg --type c --type cpp "FLASHCART_FEATURE_AUTO_CIC|FLASHCART_FEATURE_AUTO_REGION"

# Search for switch statements or if-else chains that might need updating
echo "Searching for switch statements or if-else chains using flashcart_features_t:"
rg --type c --type cpp -A 10 "switch.*flashcart_features_t|if.*flashcart_features_t"

# Search for array initializations that might need updating
echo "Searching for array initializations using flashcart_features_t:"
rg --type c --type cpp "flashcart_features_t.*\{" -A 10

Length of output: 3704

.github/workflows/build.yml (1)

80-81: 💡 Codebase verification

Verified tag name change and identified workflow issue

  • The tag_name has been successfully updated to 'rolling_release', and no references to 'rolling-release' remain in the repository. This ensures that the tag name change should not disrupt any dependent scripts or processes.

  • The make_latest: true parameter has been correctly added, which will mark this rolling release as the latest release on GitHub, enhancing its visibility.

  • Issue Identified: The workflow includes a step for uploading a dev rolling release conditioned on the develop branch (refs/heads/develop). However, the develop branch does not exist in the repository. This means the dev release step will never execute, potentially missing out on intended pre-releases.

    • Recommendation: Create the develop branch if it's intended to be used, or update the workflow to reference the correct existing branch.
🔗 Analysis chain

Review tag name change and latest release setting

Two important changes have been made to the "Upload rolling release" step:

  1. The tag_name has been changed from rolling-release to rolling_release (underscore instead of hyphen).
  2. A new parameter make_latest: true has been added.

The tag name change is minor but could potentially break any scripts or processes that depend on the exact tag name. Ensure that all relevant documentation and dependent processes are updated accordingly.

The addition of make_latest: true is significant as it will mark this rolling release as the latest release on GitHub. This change improves visibility of the rolling release but may have implications for how users and automated tools interpret the "latest" release of your project.

To ensure these changes don't cause unintended consequences, please run the following script:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any references to the old tag name in the repository
rg "rolling-release" --type yaml --type md

# List all workflow files to verify if there are any other workflows that might be affected by this change
fd -e yml -e yaml .github/workflows

Length of output: 335


Script:

#!/bin/bash
# List all branches to verify if 'develop' branch exists
git branch -a

# Search for any references to 'rolling-release' in the entire repository
rg "rolling-release"

# Search for any references to 'rolling_release' to ensure consistency
rg "rolling_release"

# Check the status of the repository to ensure it's on the correct branch
git status

Length of output: 216


Script:

#!/bin/bash
# Display the contents of the build.yml file to verify the tag_name
cat .github/workflows/build.yml

# Search for tag_name assignments in all workflow files
rg "tag_name" .github/workflows/*.yml

Length of output: 3802

src/menu/sound.c (2)

86-86: ⚠️ Potential issue

Ensure proper cleanup of sound effect resources

The sound_deinit function currently does not close the WAV files opened in sound_init_sfx, which can lead to resource leaks.

Introduce a sound_deinit_sfx function to close all opened sound effects and call it within sound_deinit. For example:

void sound_deinit_sfx(void) {
    if (sfx_enabled) {
        wav64_close(&sfx_cursor);
        wav64_close(&sfx_exit);
        wav64_close(&sfx_setting);
        wav64_close(&sfx_enter);
        wav64_close(&sfx_error);
        sfx_enabled = false;
    }
}

void sound_deinit(void) {
    if (sound_initialized) {
        sound_deinit_sfx();
        mixer_close();
        audio_close();
        sound_initialized = false;
    }
}

43-51: ⚠️ Potential issue

Add error handling for wav64_open calls in sound_init_sfx

In the sound_init_sfx function, the wav64_open function is called for each sound effect without checking the return value. If any of these calls fail, it could lead to null pointer dereferences or crashes when attempting to play the sound effects.

Consider adding error checking for each wav64_open call and handling failures appropriately. For example:

void sound_init_sfx (void) {
    mixer_ch_set_vol(SOUND_SFX_CHANNEL, 0.5f, 0.5f);
-   wav64_open(&sfx_cursor, "rom:/cursorsound.wav64");
+   if (!wav64_open(&sfx_cursor, "rom:/cursorsound.wav64")) {
+       // Handle error, e.g., log a warning or disable this sound effect
+   }
    // Repeat for other wav64_open calls
    sfx_enabled = true;
}

Committable suggestion was skipped due to low confidence.

src/menu/actions.c (2)

93-94: ⚠️ Potential issue

Initialize pressed variable

The pressed variable is declared but not initialized. If no buttons are pressed on any joypad port, pressed may contain indeterminate values when accessed later, leading to unexpected behavior.

Apply this diff to initialize pressed:

-joypad_buttons_t pressed;
+joypad_buttons_t pressed = {0};
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    joypad_buttons_t pressed = {0};


28-29: ⚠️ Potential issue

Initialize held_dir and fast_dir variables

The variables held_dir and fast_dir are declared but not initialized. This could lead to undefined behavior if no direction input is detected on any joypad port, as their values would remain uninitialized when accessed later in the function.

Apply this diff to initialize the variables:

 joypad_8way_t held_dir;
 joypad_8way_t fast_dir;
+held_dir = JOYPAD_8WAY_NONE;
+fast_dir = JOYPAD_8WAY_NONE;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    joypad_8way_t held_dir;
    joypad_8way_t fast_dir;
    held_dir = JOYPAD_8WAY_NONE;
    fast_dir = JOYPAD_8WAY_NONE;
src/menu/components/boxart.c (3)

71-71: ⚠️ Potential issue

Potential memory leak: path not freed before reinitialization

Before reinitializing path with path_init at line 71, the existing path should be freed using path_free(path); to prevent a memory leak.

Apply this diff to fix the issue:

         // Reset the directory path used for boxart.
+        path_free(path);
         path = path_init(storage_prefix, BOXART_DIRECTORY);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

        // Reset the directory path used for boxart.
        path_free(path);
        path = path_init(storage_prefix, BOXART_DIRECTORY);

68-74: ⚠️ Potential issue

Buffer overflow due to insufficient size of file_name array

The file_name array is declared with a size of 8 bytes, but when using sprintf with format "%c%c%c%c.png", it writes 9 bytes including the null terminator. This results in a buffer overflow.

Apply this diff to fix the issue:

-        char file_name[8];
+        char file_name[9];

         // Use `snprintf` to prevent buffer overflow
-        sprintf(file_name, "%c%c%c%c.png", game_code[0], game_code[1], game_code[2], game_code[3]);
+        snprintf(file_name, sizeof(file_name), "%c%c%c%c.png", game_code[0], game_code[1], game_code[2], game_code[3]);

Repeat similar changes for the other sprintf calls:

At line 84-85:

-        sprintf(file_name, "%c%c%c.png", game_code[0], game_code[1], game_code[2]);
+        snprintf(file_name, sizeof(file_name), "%c%c%c.png", game_code[0], game_code[1], game_code[2]);

At line 98-99:

-        sprintf(file_name, "%c%c.png", game_code[1], game_code[2]);
+        snprintf(file_name, sizeof(file_name), "%c%c.png", game_code[1], game_code[2]);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

        char file_name[9];

        // reset the directory path used for boxart.
        path = path_init(storage_prefix, BOXART_DIRECTORY);

        // Use `snprintf` to prevent buffer overflow
        snprintf(file_name, sizeof(file_name), "%c%c%c%c.png", game_code[0], game_code[1], game_code[2], game_code[3]);
        path_push(path, file_name);
🧰 Tools
🪛 cppcheck

[error] 73-73: Buffer is accessed out of bounds

(bufferAccessOutOfBounds)


40-57: ⚠️ Potential issue

Missing break statements in switch case leading to unintended fall-through

The switch statement lacks break; statements after each case, causing unintended fall-through to subsequent cases. This will result in multiple path_push calls being executed, which is likely not the intended behavior.

Apply this diff to fix the issue:

         switch (current_image_view) {
             case IMAGE_GAMEPAK_FRONT:
                 path_push(path, "gamepak_front.png");
+                break;
             case IMAGE_GAMEPAK_BACK:
                 path_push(path, "gamepak_back.png");
+                break;
             case IMAGE_BOXART_BACK:
                 path_push(path, "boxart_back.png");
+                break;
             case IMAGE_BOXART_LEFT:
                 path_push(path, "boxart_left.png");
+                break;
             case IMAGE_BOXART_RIGHT:
                 path_push(path, "boxart_right.png");
+                break;
             case IMAGE_BOXART_BOTTOM:
                 path_push(path, "boxart_bottom.png");
+                break;
             case IMAGE_BOXART_TOP:
                 path_push(path, "boxart_top.png");
+                break;
             default:
                 path_push(path, "boxart_front.png");
+                break;
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

        switch (current_image_view) {
            case IMAGE_GAMEPAK_FRONT:
                path_push(path, "gamepak_front.png");
                break;
            case IMAGE_GAMEPAK_BACK:
                path_push(path, "gamepak_back.png");
                break;
            case IMAGE_BOXART_BACK:
                path_push(path, "boxart_back.png");
                break;
            case IMAGE_BOXART_LEFT:
                path_push(path, "boxart_left.png");
                break;
            case IMAGE_BOXART_RIGHT:
                path_push(path, "boxart_right.png");
                break;
            case IMAGE_BOXART_BOTTOM:
                path_push(path, "boxart_bottom.png");
                break;
            case IMAGE_BOXART_TOP:
                path_push(path, "boxart_top.png");
                break;
            default:
                path_push(path, "boxart_front.png");
                break;
        }
src/menu/views/load_disk.c (4)

10-10: 🛠️ Refactor suggestion

Consider encapsulating boxart to improve modularity

Using a static variable boxart may limit the flexibility and maintainability of the code. Encapsulating boxart within the menu_t structure or another context structure can enhance modularity and make the code more reusable, especially if multiple instances of the menu are needed in the future.


96-97: ⚠️ Potential issue

Add NULL check before drawing boxart

To prevent potential null pointer dereferences, check if boxart is not NULL before calling component_boxart_draw(boxart).

Apply this diff to add a NULL check:

if (boxart != NULL) {
    component_boxart_draw(boxart);
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

        if (boxart != NULL) {
            component_boxart_draw(boxart);
        }

154-156: ⚠️ Potential issue

Set boxart to NULL after freeing

After freeing boxart in the deinit function, set it to NULL to avoid dangling pointers and potential double-free errors in the future.

Apply this diff:

static void deinit (void) {
    component_boxart_free(boxart);
+   boxart = NULL;
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

static void deinit (void) {
    component_boxart_free(boxart);
    boxart = NULL;
}

173-173: ⚠️ Potential issue

Handle potential failure of component_boxart_init

component_boxart_init may return NULL if the initialization fails. It's important to check the return value and handle the error appropriately to prevent unexpected behavior later.

Apply this diff to add error handling:

boxart = component_boxart_init(menu->storage_prefix, menu->load.disk_info.id, IMAGE_BOXART_FRONT);
+ if (boxart == NULL) {
+     // Handle initialization failure, e.g., log an error or set a fallback image
+ }

Committable suggestion was skipped due to low confidence.

src/menu/menu.c (1)

38-39: ⚠️ Potential issue

Replace assert with proper error handling for memory allocation failure

Using assert(menu != NULL); will abort the program if memory allocation fails. In production code, it's better to handle such failures gracefully. Consider checking the result of calloc and providing an error message or entering a safe fail state.

src/menu/views/settings_editor.c (2)

14-17: ⚠️ Potential issue

Avoid casting void* directly to bool to prevent undefined behavior

Casting a void* directly to a bool can lead to unexpected results or undefined behavior because pointer values may not correctly represent boolean values when converted. Instead, cast the void* to an integer type like uintptr_t before casting to bool. This ensures the correct boolean value is obtained.

Apply the following changes to all affected functions:

-static void set_pal60_type (menu_t *menu, void *arg) {
-    menu->settings.pal60_enabled = (bool) (arg);
+static void set_pal60_type (menu_t *menu, void *arg) {
+    menu->settings.pal60_enabled = (bool)(uintptr_t)(arg);
     settings_save(&menu->settings);
 }

-static void set_protected_entries_type (menu_t *menu, void *arg) {
-    menu->settings.show_protected_entries = (bool) (arg);
+static void set_protected_entries_type (menu_t *menu, void *arg) {
+    menu->settings.show_protected_entries = (bool)(uintptr_t)(arg);
     settings_save(&menu->settings);
     menu->browser.reload = true;
 }

-static void set_use_saves_folder_type (menu_t *menu, void *arg) {
-    menu->settings.use_saves_folder = (bool) (arg);
+static void set_use_saves_folder_type (menu_t *menu, void *arg) {
+    menu->settings.use_saves_folder = (bool)(uintptr_t)(arg);
     settings_save(&menu->settings);
 }

-static void set_sound_enabled_type (menu_t *menu, void *arg) {
-    menu->settings.sound_enabled = (bool) (arg);
+static void set_sound_enabled_type (menu_t *menu, void *arg) {
+    menu->settings.sound_enabled = (bool)(uintptr_t)(arg);
     sound_use_sfx(menu->settings.sound_enabled);
     settings_save(&menu->settings);
 }

 #ifdef BETA_SETTINGS
-static void set_bgm_enabled_type (menu_t *menu, void *arg) {
-    menu->settings.bgm_enabled = (bool) (arg);
+static void set_bgm_enabled_type (menu_t *menu, void *arg) {
+    menu->settings.bgm_enabled = (bool)(uintptr_t)(arg);
     settings_save(&menu->settings);
 }

-static void set_rumble_enabled_type (menu_t *menu, void *arg) {
-    menu->settings.rumble_enabled = (bool) (arg);
+static void set_rumble_enabled_type (menu_t *menu, void *arg) {
+    menu->settings.rumble_enabled = (bool)(uintptr_t)(arg);
     settings_save(&menu->settings);
 }
 #endif

Also, update the context menu definitions to cast the boolean values to void* via uintptr_t:

 static component_context_menu_t set_pal60_type_context_menu = { .list = {
-    {.text = "On", .action = set_pal60_type, .arg = (void *) (true) },
-    {.text = "Off", .action = set_pal60_type, .arg = (void *) (false) },
+    {.text = "On", .action = set_pal60_type, .arg = (void *)(uintptr_t)(true) },
+    {.text = "Off", .action = set_pal60_type, .arg = (void *)(uintptr_t)(false) },
     COMPONENT_CONTEXT_MENU_LIST_END,
 }};

 // Repeat the above changes for all other context menus

Also applies to: 19-24, 26-29, 31-35, 38-41, 44-47


55-91: 🛠️ Refactor suggestion

Refactor to reduce code duplication in context menu and setting functions

The code for creating context menus and setting functions for each option is repetitive. Consider refactoring by creating a generic function and data structures to handle these settings dynamically. This will improve maintainability and make it easier to add or modify settings in the future.

For example, you can define a structure to represent each setting and loop through an array to create context menus and setting functions.

src/menu/views/load_rom.c (1)

215-219: 🛠️ Refactor suggestion

Simplify toggle logic for 'show_extra_info_message'

The toggle logic for show_extra_info_message can be simplified using logical negation, enhancing code readability.

Apply this diff to simplify the code:

if (menu->actions.lz_context) {
-    if (show_extra_info_message) {
-        show_extra_info_message = false;
-    } else {
-        show_extra_info_message = true;
-    }
+    show_extra_info_message = !show_extra_info_message;
    sound_play_effect(SFX_SETTING);
}

Committable suggestion was skipped due to low confidence.

src/menu/rom_info.c (2)

813-815: ⚠️ Potential issue

Prevent potential buffer overflow when copying ROM description

The use of memcpy without ensuring the source string fits within the destination buffer may lead to a buffer overflow if rom_description is longer than rom_info->metadata.description.

const char *rom_description = mini_get_string(ini, "metadata", "description", "");
memcpy(rom_info->metadata.description, rom_description, sizeof(rom_info->metadata.description));

Consider using strncpy or snprintf to safely copy the string and ensure it is null-terminated.

Apply this diff to fix the issue:

- memcpy(rom_info->metadata.description, rom_description, sizeof(rom_info->metadata.description));
+ strncpy(rom_info->metadata.description, rom_description, sizeof(rom_info->metadata.description) - 1);
+ rom_info->metadata.description[sizeof(rom_info->metadata.description) - 1] = '\0';

842-846: ⚠️ Potential issue

Free allocated memory on early return to prevent memory leaks

In the save_override function, if mini_try_load fails and returns NULL, the allocated rom_info_path is not freed before returning, leading to a memory leak.

mini_t *ini = mini_try_load(path_get(rom_info_path));

if (!ini) {
    return ROM_ERR_SAVE_IO;
}

Ensure that rom_info_path is freed before returning to prevent memory leaks.

Apply this diff to fix the memory leak:

if (!ini) {
+    path_free(rom_info_path);
    return ROM_ERR_SAVE_IO;
}

Repository owner deleted a comment from coderabbitai bot Oct 14, 2024
Improve layout handling
@networkfusion
Copy link
Collaborator Author

@coderabbitai full review

Copy link

coderabbitai bot commented Oct 23, 2024

✅ Actions performed

Full review triggered.

Copy link

coderabbitai bot commented Oct 23, 2024

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request introduces significant enhancements to the handling of ROM information within the codebase. Key updates include the restructuring of the rom_info_t data structure to incorporate new metadata and settings fields, such as description, cheats_enabled, and patches_enabled. The function responsible for loading ROM information from a file has been renamed and modified to support these new fields. Additionally, several new functions have been added to improve the display of ROM metadata and settings in the user interface.

Changes

File Change Summary
src/menu/rom_info.c - Updated rom_info_t structure to include metadata.description, settings.cheats_enabled, and settings.patches_enabled.
- Renamed load_overrides to load_rom_info_from_file.
- Adjusted logic for loading and processing INI files.
- Modified boot overrides handling to use boot_override structure.
- Updated extract_rom_info to initialize new fields.
src/menu/rom_info.h - Renamed override field to boot_override in rom_info_t.
- Added settings structure with cheats_enabled and patches_enabled fields.
- Added metadata structure with description field.
- Repositioned declarations for rom_info_get_cic_seed and rom_info_load.
src/menu/views/load_rom.c - Added format_rom_description function to return a description string.
- Added format_boolean_type inline function for boolean display.
- Updated draw function to utilize new formatting functions for metadata display.

Possibly related PRs

  • Optimize boxart image load #130: The changes in src/menu/views/load_rom.c in this PR involve modifications to the view_load_rom_init function, which may relate to the handling of ROM information and display, similar to the updates made in the main PR regarding ROM metadata and configuration management.

Suggested labels

enhancement

Poem

In the land of ROMs, where data does flow,
New fields and functions, oh how they glow!
Descriptions and settings, all neatly in place,
With cheats and patches, we quicken the pace.
A rabbit's delight, in code we rejoice,
For clarity reigns, and we all have a voice! 🐰✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (4)
src/menu/rom_info.h (2)

226-235: Consider adding validation constraints for the description field.

The new structures align well with the PR objectives. However, a few suggestions:

  1. Consider documenting the format/constraints for the description field (e.g., allowed characters, line breaks).
  2. Consider adding a constant for the description length (256) to make it configurable.
+/** @brief Maximum length for ROM description. */
+#define ROM_DESCRIPTION_MAX_LENGTH 256

 /** @brief The ROM metadata. */
 struct {
-    char description[256];
+    char description[ROM_DESCRIPTION_MAX_LENGTH];
 } metadata;

238-239: Add documentation for the new function declarations.

The functions lack documentation comments. Consider adding Doxygen-style comments to match the documentation style used throughout the file.

+/**
+ * @brief Get the CIC seed for the ROM.
+ * @param rom_info Pointer to the ROM information structure.
+ * @param seed Pointer to store the CIC seed.
+ * @return true if successful, false otherwise.
+ */
 bool rom_info_get_cic_seed (rom_info_t *rom_info, uint8_t *seed);
+
+/**
+ * @brief Load ROM information from a file.
+ * @param path Pointer to the path structure.
+ * @param rom_info Pointer to store the ROM information.
+ * @return ROM_OK on success, error code otherwise.
+ */
 rom_err_t rom_info_load (path_t *path, rom_info_t *rom_info);
src/menu/views/load_rom.c (1)

248-249: Simplify newline usage after description.

The current implementation uses multiple newlines which might cause inconsistent spacing. Consider using a single newline for better maintainability.

-            "Description:\n %s\n"
-            "\n\n\n\n\n\n\n"
+            "Description:\n %s\n"
+            "\n"
src/menu/rom_info.c (1)

832-833: Specify a section name for settings keys

In the mini_get_bool calls for cheats_enabled and patches_enabled, the section is set to NULL, which refers to the global section. For consistency with other settings read from specific sections like "metadata" and "custom_boot", consider specifying a section name such as "settings".

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 004f182 and 19faceb.

📒 Files selected for processing (3)
  • src/menu/rom_info.c (5 hunks)
  • src/menu/rom_info.h (3 hunks)
  • src/menu/views/load_rom.c (3 hunks)
🧰 Additional context used
🔇 Additional comments (5)
src/menu/rom_info.h (1)

Line range hint 202-212: Verify the breaking changes in existing ROM ini files.

The rename from override to boot_override improves clarity but introduces breaking changes. The PR objectives mention that override parameters have been moved to a new [custom_boot] section in ini files.

Let's verify the impact on existing ROM ini files:

✅ Verification successful

Let's gather more specific information about the usage of the old 'override' structure in the codebase.


Based on the results, I can now generate the final response as we have sufficient information about the breaking changes and their implementation.

Breaking changes are properly implemented with backward compatibility

The rename from override to boot_override is well-handled in the codebase:

  • All references in rom_info.c are updated to use boot_override
  • The configuration is now read from the new [custom_boot] section as intended
  • The code maintains proper initialization of override flags (all set to false by default)
  • The override functionality is properly encapsulated in getter/setter methods that handle the state consistently

The implementation ensures backward compatibility through:

  1. Default initialization of all override flags to false
  2. Using AUTOMATIC as the default value for all override types when reading from config
  3. Proper handling of the new [custom_boot] section in the configuration parser
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all ini files and check for existing 'override' usage
# to assess the impact of breaking changes

echo "Searching for ROM ini files with 'override' settings..."
rg -l '\[.*override.*\]' --type ini

echo "Checking for any hardcoded references to the old 'override' structure..."
rg -l 'override\.' --type cpp --type c

Length of output: 414


Script:

#!/bin/bash
# Check the specific usage of 'override' in rom_info.c
echo "Checking rom_info.c for 'override' references with context..."
rg 'override\.' -B 2 -A 2 src/menu/rom_info.c

# Look for any ini file patterns regardless of extension
echo -e "\nSearching for potential ROM configuration files..."
fd -e cfg -e conf -e ini -e config

# Check for any ROM configuration related code
echo -e "\nChecking for ROM configuration parsing code..."
rg -l "ini|config|cfg" src/menu/rom_info.c

Length of output: 3284

src/menu/views/load_rom.c (3)

125-127: LGTM!

The inline function is well-implemented and follows the codebase's formatting pattern.


253-254: LGTM!

The feature toggle display is well-formatted and consistently uses the boolean formatter.

Also applies to: 260-261


256-262: Verify handling of relocated override parameters.

The PR objectives mention that override parameters have been moved to a new [custom_boot] section. Ensure that the ROM info loading function properly handles both old and new parameter locations for backward compatibility.

✅ Verification successful

Based on the shell script results, I can now generate the final response as we have sufficient information about how the override parameters are handled.

Override parameters are properly handled in the new [custom_boot] section

The code shows proper implementation of the relocated override parameters:

  • All override parameters (cic_type, save_type, tv_type) are now read from the [custom_boot] section in rom_info.c
  • The code maintains proper state tracking through the boot_override struct with boolean flags for each override
  • The getter functions (e.g., rom_info_get_cic_type) correctly handle both overridden and default values
  • The override functions (e.g., rom_info_override_cic_type) properly save to the new section using save_override
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for ROM info loading and parameter handling code
rg -A 5 "custom_boot" .
rg -A 5 "override" .

Length of output: 9831

src/menu/rom_info.c (1)

796-798: Initialization of new fields is appropriate

Initializing rom_info->metadata.description, rom_info->settings.cheats_enabled, and rom_info->settings.patches_enabled to default values ensures that these fields have defined values before being used elsewhere.

Comment on lines +102 to +104
static const char *format_rom_description(char *description) {
return description[0] == '\0' ? "None." : description;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add null check and const qualifier to description parameter.

The function should handle null descriptions and mark the input parameter as const since it's not modified.

-static const char *format_rom_description(char *description) {
+static const char *format_rom_description(const char *description) {
+    if (!description) return "None.";
     return description[0] == '\0' ? "None." : description;
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
static const char *format_rom_description(char *description) {
return description[0] == '\0' ? "None." : description;
}
static const char *format_rom_description(const char *description) {
if (!description) return "None.";
return description[0] == '\0' ? "None." : description;
}


if (!ini) {
path_free(overrides_path);
path_free(rom_info_path);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Handle missing INI file by creating a new one

When mini_try_load fails to load an INI file (returns NULL), the code currently returns an error. Instead, you should initialize a new INI object using mini_new() to allow saving overrides even when the INI file does not exist.

Apply this diff to fix the issue:

 if (!ini) {
-    path_free(rom_info_path);
-    return ROM_ERR_SAVE_IO;
+    ini = mini_new();
+    if (!ini) {
+        path_free(rom_info_path);
+        return ROM_ERR_SAVE_IO;
+    }
 }

Committable suggestion was skipped due to low confidence.

Comment on lines +814 to +816
const char *rom_description = mini_get_string(ini, "metadata", "description", "");
memcpy(rom_info->metadata.description , rom_description, sizeof(rom_info->metadata.description));

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Prevent potential buffer overflow when copying the description

Using memcpy to copy rom_description into rom_info->metadata.description can lead to a buffer overflow if the source string is longer than the destination buffer. To ensure safety, consider using strncpy and explicitly null-terminating the destination buffer.

Apply this diff to fix the issue:

 const char *rom_description = mini_get_string(ini, "metadata", "description", "");
-memcpy(rom_info->metadata.description, rom_description, sizeof(rom_info->metadata.description));
+strncpy(rom_info->metadata.description, rom_description, sizeof(rom_info->metadata.description) - 1);
+rom_info->metadata.description[sizeof(rom_info->metadata.description) - 1] = '\0';
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const char *rom_description = mini_get_string(ini, "metadata", "description", "");
memcpy(rom_info->metadata.description , rom_description, sizeof(rom_info->metadata.description));
const char *rom_description = mini_get_string(ini, "metadata", "description", "");
strncpy(rom_info->metadata.description, rom_description, sizeof(rom_info->metadata.description) - 1);
rom_info->metadata.description[sizeof(rom_info->metadata.description) - 1] = '\0';

<!--- Provide a general summary of your changes in the Title above -->

## Description
<!--- Describe your changes in detail -->
Renames `components` to `ui_components`

## Motivation and Context
<!--- What does this sample do? What problem does it solve? -->
<!--- If it fixes/closes/resolves an open issue, please link to the
issue here -->
Makes the source more clear as to its functionality

## How Has This Been Tested?
<!-- (if applicable) -->
<!--- Please describe in detail how you tested your sample/changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Screenshots
<!-- (if appropriate): -->

## Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [x] Improvement (non-breaking change that adds a new feature)
- [ ] Bug fix (fixes an issue)
- [ ] Breaking change (breaking change)
- [ ] Documentation Improvement
- [ ] Config and build (change in the configuration and build system,
has no impact on code or features)

## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
- [ ] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.

<!--- It would be nice if you could sign off your contribution by
replacing the name with your GitHub user name and GitHub email contact.
-->
Signed-off-by: GITHUB_USER <GITHUB_USER_EMAIL>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant