Skip to content

Conversation

@wheremyfoodat
Copy link
Contributor

Continuing from #55

As the title says, this PR lets the user supply their own DSP memory if needed, for purposes such as implementing fastmem, using host shared memory for exposing DSP RAM to other processing, applying memory protections to DSP memory, and so on.

This is done via a UserConfig object via which the user passes to Teakra. This config object will also be needed when it's time to merge the Teak JIT from https://github.com/raphaelthegreat/teakra/ (for enabling/disabling the JIT), which is probably not going to be any time soon as it needs a hefty rewrite.

One minor caveat is that this UserConfig struct hasn't been ported to the C interface yet, and they behave the same as they did before this PR (ie always owning DSP memory). The reason for this is that I'm unsure how to port the struct in the longterm without duplicating a lot of code (by eg making a C version of the struct, and having the interface's cpp file copy each field to the C++ version). Regardless, this isn't a huge problem since the C interface isn't as widely used, and users likely don't care much about this in the first place. It will be more important to implement C interface configs when the JIT is ready.

Tested locally by integrating the changes to Panda3DS, running the test verifier, and by testing the Rust bindings to see that the C interface still works fine.

@wheremyfoodat
Copy link
Contributor Author

Err, I should probably make CI run tests on pull request

struct SharedMemory {
std::array<u8, 0x80000> raw{};
u8* raw;
bool own_dsp_mem;
Copy link
Owner

@wwylele wwylele Aug 21, 2025

Choose a reason for hiding this comment

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

I think a better way in modern C++ to do this is something like

std::option<std::unique_ptr<std::array<u8, 0x80000>>> raw;
u8* raw_ptr; // points to either raw or user-supplied memory

so when Teakra manages the memory, it doesn't need to manually do new/delete, and it reduce the chance we mishandle and leak it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be fixed. Skipped the optional since by default unique_ptr is initialized to null and doesn't own any memory.

Copy link
Owner

Choose a reason for hiding this comment

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

You can tell my C++ skills are too rust-y by not thinking about null values 😂

@wwylele wwylele merged commit dda8ec0 into wwylele:master Aug 21, 2025
3 checks passed
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.

2 participants