Splitting Assets from Code: Difference between revisions

Wrote the "Having a buffer in the codesegment" chapter
(Finished the 'Loading assets from ROM' chapter)
(Wrote the "Having a buffer in the codesegment" chapter)
Line 90:
 
== Having a buffer in the codesegment ==
The easiest method is to simply just have a global variable which will work as a "cache":
TODO
<syntaxhighlight lang="c">
u8 buffer[4096]; // The exact maximum size of a texture in TMEM (4Kilobytes).
</syntaxhighlight>
The idea is, before you start rendering the level, you load any textures you need into your global cache (which can be any size you want, not just 4096 bytes). Then, when the data isn't needed anymore, you mark that part of the buffer as "empty" and you can overwrite it with new data.
 
You're probably wondering: "hold on, this global buffer variable is part of the code... Won't it be subject to the exact same 1MB restriction we had before?". The answer is yes, however this method ensures that only the data you need is loaded at a time in the 1MB code segment (as opposed to everything being there). The alternative would be:
 
== Having a buffer somewhere in RAM ==
Line 96 ⟶ 102:
 
== Finalizing the code ==
TODO