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

Memstuff #1164

Merged
merged 22 commits into from
May 1, 2022
Merged

Memstuff #1164

merged 22 commits into from
May 1, 2022

Conversation

EllipticEllipsis
Copy link
Contributor

Name all the memory/string.h functions I could find, document them as consistently as possible. OoT has multiple memsets and memcpys, some of which are rather non-conformant, so I added fairly complete docs for them. It's not clear how to name the ones in code_80069420

I did not document the libultra string.h since it will likely be reworked in a significant way in future anyway.

Also added some more sizeofs to places that were missing them. I didn't touch z_sram since the whole thing needs a rework anyway, or z_demo, because I'm not sure which thing is appropriate to take the sizeof in that function. The most significant change was in BgCobra: given that this has a texture in its struct that it has to align, it has an oversized buffer, so I added some appropriate defines to be able to do this. There is a remaining question of whether to do

Lib_MemSet(shadowTex, sizeof(this->shadowTextureBuffer) & ~0xF, 0)

or

Lib_MemSet(shadowTex, COBRA_SHADOW_TEX_SIZE, 0);

Drafting until #1162 is merged... apparently I started this a while ago and documented fmodf too.

@@ -831,7 +831,7 @@ void func_800645A0(GlobalContext* globalCtx, CutsceneContext* csCtx);
void Cutscene_HandleEntranceTriggers(GlobalContext* globalCtx);
void Cutscene_HandleConditionalTriggers(GlobalContext* globalCtx);
void Cutscene_SetSegment(GlobalContext* globalCtx, void* segment);
void* MemCopy(void* dest, void* src, s32 size);
void* MemCpy(void* dest, const void* src, s32 size);
Copy link
Collaborator

Choose a reason for hiding this comment

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

since with the capitalization it's already not memcpy, is there really a point to removing the o
This may just bring more confusion between memcpy and MemCpy, not that the o would help much but it's still something (at least both functions are conformant memcpys, but one is in code so may not be used in boot so it's not entirely irrelevant to prevent confusion)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally these get a proper prefix anyway. Unfortunately there's very little context for how they're used: it's essentially "the one used outside boot", and the MemSet in here isn't used at all. It's totally gone in MM, and its duties reassigned to bcopy or __osMemcpy, so practically the advice should just be "don't bother using this one".

@EllipticEllipsis EllipticEllipsis marked this pull request as ready for review March 1, 2022 19:36
*
* @param[in,out] dest address to start at
* @param[in] val value to write (s32, but interpreted as u8)
* @param[in] len number of bytes to write. Has to be s32: it is not possible to set more than 2 GB of RAM at once.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure the comment about 2GB of ram is relevant
Or at least it's not more relevant here than anything (a lot of things) that depend on addresses fitting in a s32

Copy link
Contributor Author

@EllipticEllipsis EllipticEllipsis Mar 2, 2022

Choose a reason for hiding this comment

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

Mm, I suppose it would probably be better to note that this cannot sensibly be a size_t (the function argument can, but the temp must be s32, and it feels disingenuous to allow the user to accidentally feed it a large integer that gets recast into a small negative one).

*
* There are two other memsets in this codebase,
* @sa Lib_MemSet(), MemSet()
* This one is used in __osMalloc, z_quake, z_view, and z_camera
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a point to listing where a function is used?
it's only a grep/ctrl+shift+f away to find that info,
and these names may also change eventually so it's going to get outdated too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is probably a habit from looking on GitHub with its useless searching. I think it's useful to explicitly note patterns of usage (it makes them easier to compare when you have them explicitly written down, for example), but I can see that people would regard this an unnecessary in "final" documentation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree with dragorn that its not worth commenting on where it gets used

temp_s2 = ALIGN16((s32)(&this->shadowTexture));
Lib_MemSet(temp_s2, 0x1000, 0);
shadowTex = COBRA_SHADOW_TEX_PTR(this);
Lib_MemSet(shadowTex, sizeof(this->shadowTextureBuffer) & ~0xF, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should indeed use COBRA_SHADOW_TEX_SIZE imo, these zeros are meant as the default color (transparent black) afaict, it wouldn't care if the buffer happened to be oversized, if that's what using sizeof here is meant for

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The point of this is to allow downsizing the buffer to the appropriate size, but it probably does make more sense to use the texture size directly. I'll change it.

Copy link
Collaborator

@Roman971 Roman971 left a comment

Choose a reason for hiding this comment

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

Sorry for the very late review on this one.
The changes look pretty good to me, and I just have some comments on the documentation style

Comment on lines 3 to 14
/**
* @brief memset: sets @p len bytes to @p val starting at address @p dest .
*
* There are two other memsets in this codebase,
* @sa Lib_MemSet(), MemSet()
*
* @param[in,out] dest address to start at
* @param[in] val value to write (s32, but interpreted as u8)
* @param[in] len number of bytes to write
*
* @return dest
*/
Copy link
Collaborator

@Roman971 Roman971 Apr 30, 2022

Choose a reason for hiding this comment

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

The documentation here looks good but I have a few comments regarding the syntax (based on our doxygen guide and what we've done so far):

  • We generally don't use @brief, and I believe the result is the same without it when it's the first line, so we can probably just omit it
  • We generally don't use [in]/[in,out] either for @param, and they don't seem very useful when combined with proper descriptions for each param, so I would avoid them to keep things simple
  • It looks like @see can be used instead of @sa and sounds much clearer imo
  • I believe backticks (``) can be used instead of @p, which might help with readability when looking directly at the comment in code

Note: My knowledge on doxgen is fairly limited so a lot of this could be wrong, but I wanted to at least bring it up since I don't think we've used or discussed any of these keywords in the past

src/code/fmodf.c Outdated Show resolved Hide resolved
@Roman971 Roman971 merged commit e84f5ab into zeldaret:master May 1, 2022
louist103 pushed a commit to louist103/oot that referenced this pull request Jan 3, 2023
* Un-fake a couple of matches in memory manip functions

* Document fmodf

* Un-fake a couple of matches in memory manip functions

* Document fmodf

* Rename functions and files

* Document memmove, memsets, memcpys

* Format

* Sort out some missing sizeofs

* Name fmodf

* Rename local variables

* size_t

* Use COBRA_SHADOW_TEX_SIZE

* Review

* Tweak the Doxyfile to remove @brief requirement

* Roman's review

* Fix a bug comment

* Change fmodf
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.

4 participants