From 0a48692ee1b29af2eefcbc3b942d6d99c39b2089 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 26 Feb 2022 22:52:35 -0600 Subject: [PATCH] [nostalgia] Update Developer Handbook --- developer-handbook.md | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/developer-handbook.md b/developer-handbook.md index 332d1d35..c2c942b5 100644 --- a/developer-handbook.md +++ b/developer-handbook.md @@ -1,4 +1,4 @@ -# Developer Handbook +# Nostalgia Developer Handbook ## About @@ -88,7 +88,8 @@ uint8_t *loadRom(const char *path) { fseek(file, 0, SEEK_END); const auto size = ftell(file); rewind(file); - // new can technically throw, though this project considers out-of-memory to be unrecoverable + // new can technically throw, though this project considers out-of-memory + // to be unrecoverable auto buff = new uint8_t[size]; fread(buff, size, 1, file); fclose(file); @@ -110,7 +111,8 @@ int main() { // using malloc does not call the constructor std::vector *list = (std::vector*) malloc(sizeof(std::vector)); doStuff(list); - // free does not call the destructor, which causes memory leak for array inside list + // free does not call the destructor, which causes memory leak for array + // inside list free(list); return 0; } @@ -143,10 +145,10 @@ likely will change. ### Error Handling Exceptions are clean and nice in userland code running in environments with -expansive system resources, but absolutely unacceptable in code running in -restrictive bare metal environments. +expansive system resources, but they are a bit of a pain in small bare metal +environments. The GBA build has them disabled. -Exceptions cause the compiler to generate a great deal of extra code that +Exceptions cause also the compiler to generate a great deal of extra code that inflates the size of the binary. The binary size bloat is often cited as one of the main reasons why many embedded developers prefer C to C++. @@ -355,13 +357,12 @@ and ROM. Ox has a model system that provides a sort of manual reflection mechanism. Models require a model function for the type that you want to model. -The type must provide its number of fields in a static constexper integer named Fields. It is also good to provide a type name and type version number, though that is not required. The model function takes an instance of the type it is modelling and a template parameter type. The template parameter type must implement the API used in the models, but it -can do anything witht the data provided to it. +can do anything with the data provided to it. Here is an example from the Nostalgia/Core package: @@ -451,6 +452,19 @@ constexpr Error model(T *h, FileAddress *fa) noexcept { } ``` +There are also macros in `````` for simplifying the declaration of models: + +```cpp +oxModelBegin(NostalgiaGraphic) + oxModelField(bpp) + oxModelField(rows) + oxModelField(columns) + oxModelField(defaultPalette) + oxModelField(pal) + oxModelField(pixels) +oxModelEnd() +``` + ### Serialization Using the model system, Ox provides for serialization. @@ -510,7 +524,7 @@ ox::Result loadPalette3(const Buffer &buff) noexcept { ox::Result writeSpritePalette1(NostalgiaPalette *pal) noexcept { ox::Buffer buffer(ox::units::MB); oxReturnError(ox::writeMC(buffer.data(), buffer.size(), pal)); - return ox::move(buffer); + return std::move(buffer); } ox::Result writeSpritePalette2(NostalgiaPalette *pal) noexcept { @@ -548,7 +562,7 @@ ox::Result loadPalette3(const Buffer &buff) noexcept { ox::Result writeSpritePalette1(NostalgiaPalette *pal) noexcept { ox::Buffer buffer(ox::units::MB); oxReturnError(ox::writeOC(buffer.data(), buffer.size(), pal)); - return ox::move(buffer); + return std::move(buffer); } ox::Result writeSpritePalette2(NostalgiaPalette *pal) noexcept {