diff options
| author | Anghelo Carvajal <angheloalf95@gmail.com> | 2023-11-26 09:47:21 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-26 09:47:21 -0300 |
| commit | 34492a4386446fc82220fe0684ff521d760e84bd (patch) | |
| tree | 83057f1f50259946874ff3af70109395de158be1 /include | |
| parent | b25e64d1bd2ece30301f9fa5af78f963afd0cf76 (diff) | |
Move the system heap and the framebuffers to their own segments (#1488)
* make segments for the systemheap and the framebuffers
* define in the makefile
* undefined syms
* Make segments for the pre boot buffers too
* Update spec
Co-authored-by: Parker <20159000+jpburnett@users.noreply.github.com>
* review
* Update spec
Co-authored-by: Parker <20159000+jpburnett@users.noreply.github.com>
* Update Makefile
Co-authored-by: Dragorn421 <Dragorn421@users.noreply.github.com>
* comments
* comment
* move comment about the hardcoded address to buffers.h
* rewrite SYSTEM_HEAP_END_ADDR in terms of other symbols
* Use `ALIGNED` on all the buffers
* Rename SYSTEM_HEAP_END_ADDR to FRAMEBUFFERS_START_ADDR
* Put ALIGNED at the right like the rest of the codebase
* merge
* gLoBuffer
* gHiBuffer
* Add a static assert to ensure the address of gHiBuffer haven't shifted without the user noticing
* smol include cleanup
---------
Co-authored-by: Parker <20159000+jpburnett@users.noreply.github.com>
Co-authored-by: Dragorn421 <Dragorn421@users.noreply.github.com>
Diffstat (limited to 'include')
| -rw-r--r-- | include/buffers.h | 54 | ||||
| -rw-r--r-- | include/libc/assert.h | 21 | ||||
| -rw-r--r-- | include/segment_symbols.h | 4 | ||||
| -rw-r--r-- | include/variables.h | 4 |
4 files changed, 75 insertions, 8 deletions
diff --git a/include/buffers.h b/include/buffers.h index 72615a717..ed8b2152c 100644 --- a/include/buffers.h +++ b/include/buffers.h @@ -1,9 +1,24 @@ #ifndef BUFFERS_H #define BUFFERS_H -#include "z64.h" +#include "libc/assert.h" +#include "gfx.h" #include "macros.h" #include "stack.h" +#include "z64save.h" + +typedef union { + u16 framebufferHiRes[HIRES_BUFFER_HEIGHT][HIRES_BUFFER_WIDTH] ALIGNED(64); + struct { + u16 framebuffer[SCREEN_HEIGHT][SCREEN_WIDTH] ALIGNED(64); + u8 skyboxBuffer[0x5A360] ALIGNED(16); + }; +} BufferLow; + +// Equivalent to gLoBuffer.framebufferHiRes, but a different symbol is required to match +extern u16 gFramebufferHiRes1[HIRES_BUFFER_WIDTH][HIRES_BUFFER_HEIGHT]; + +extern BufferLow gLoBuffer; extern u8 gGfxSPTaskYieldBuffer[OS_YIELD_DATA_SIZE]; @@ -12,9 +27,40 @@ extern GfxPool gGfxPools[2]; extern u8 gAudioHeap[0x138000]; extern u8 gSystemHeap[]; -extern u8 gPictoPhotoI8[PICTO_PHOTO_SIZE]; -extern u8 D_80784600[0x56200]; -extern u16 gFramebuffer0[SCREEN_HEIGHT][SCREEN_WIDTH]; + +typedef union { + u16 framebufferHiRes[HIRES_BUFFER_HEIGHT][HIRES_BUFFER_WIDTH] ALIGNED(64); + struct { + u8 pictoPhotoI8[PICTO_PHOTO_SIZE] ALIGNED(64); + u8 D_80784600[0x56200] ALIGNED(64); + u16 framebuffer[SCREEN_HEIGHT][SCREEN_WIDTH] ALIGNED(64); + }; +} BufferHigh; + +// Equivalent to gHiBuffer.framebufferHiRes, but a different symbol is required to match +extern u16 gFramebufferHiRes0[HIRES_BUFFER_HEIGHT][HIRES_BUFFER_WIDTH]; + +extern BufferHigh gHiBuffer; + +#ifndef FRAMEBUFFERS_START_ADDR +/** + * The `framebuffers` segment is located at a fixed location in RAM and has a + * fixed size. + * Those framebuffers are placed at the end of the RAM space. + * This address is calculated by doing `0x80800000 - (size of framebuffers)`, + * where 0x80800000 is the end of the Expansion Pak address range. + * In the vanilla game this value expands to `0x80780000`. + * + * Since the start of the `framebuffers` segment is the end of the not-fixed + * available RAM, then the `system_heap` covers all the remaining RAM that is + * not used by the non-relocatable code/data (i.e. `boot`, `code`, and other + * buffers) up to the start of the `framebuffers` segmemt. + * @see `Main` + */ +#define FRAMEBUFFERS_START_ADDR (PHYS_TO_K0(0x800000) - sizeof(BufferHigh)) + +static_assert(FRAMEBUFFERS_START_ADDR == 0x80780000, "The expected address of gHiBuffer shifted. Please update said address in buffers.h and in the spec file."); +#endif #endif diff --git a/include/libc/assert.h b/include/libc/assert.h new file mode 100644 index 000000000..7fee0a815 --- /dev/null +++ b/include/libc/assert.h @@ -0,0 +1,21 @@ +#ifndef LIBC_ASSERT_H +#define LIBC_ASSERT_H + +// Static/compile-time assertions + +#if (__STDC_VERSION__ >= 202311L) +// static_assert is a keyword in C23, do not define it +#elif (__STDC_VERSION__ >= 201112L) +# define static_assert(cond, msg) _Static_assert(cond, msg) +#else +# ifndef GLUE +# define GLUE(a, b) a##b +# endif +# ifndef GLUE2 +# define GLUE2(a, b) GLUE(a, b) +# endif + +# define static_assert(cond, msg) typedef char GLUE2(static_assertion_failed, __LINE__)[(cond) ? 1 : -1] +#endif + +#endif diff --git a/include/segment_symbols.h b/include/segment_symbols.h index 4d5824138..c49c08026 100644 --- a/include/segment_symbols.h +++ b/include/segment_symbols.h @@ -39,6 +39,8 @@ #define ROM_FILE_UNSET \ { 0 } +DECLARE_SEGMENT(framebuffer_lo) + DECLARE_SEGMENT(boot) DECLARE_ROM_SEGMENT(boot) @@ -78,6 +80,8 @@ DECLARE_SEGMENT(code) DECLARE_ROM_SEGMENT(code) DECLARE_BSS_SEGMENT(code) +DECLARE_SEGMENT(system_heap) + DECLARE_OVERLAY_SEGMENT(kaleido_scope) DECLARE_OVERLAY_SEGMENT(player_actor) diff --git a/include/variables.h b/include/variables.h index 638a8656c..dce2df663 100644 --- a/include/variables.h +++ b/include/variables.h @@ -5,10 +5,6 @@ #include "segment_symbols.h" #include "macros.h" -// pre-boot variables -extern u16 gFramebuffer1[SCREEN_HEIGHT][SCREEN_WIDTH]; // at 0x80000500 -extern u8 D_80025D00[]; - // data extern size_t gDmaMgrDmaBuffSize; extern vs32 gIrqMgrResetStatus; |
