[nostalgia] Update Developer Handbook

This commit is contained in:
Gary Talent 2022-02-26 22:52:35 -06:00
parent e8a046c2dc
commit 0a48692ee1

View File

@ -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<int> *list = (std::vector<int>*) malloc(sizeof(std::vector<int>));
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 ```<ox/model/def.hpp>``` 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<NostalgiaPalette> loadPalette3(const Buffer &buff) noexcept {
ox::Result<ox::Buffer> 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<ox::Buffer> writeSpritePalette2(NostalgiaPalette *pal) noexcept {
@ -548,7 +562,7 @@ ox::Result<NostalgiaPalette> loadPalette3(const Buffer &buff) noexcept {
ox::Result<ox::Buffer> 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<ox::Buffer> writeSpritePalette2(NostalgiaPalette *pal) noexcept {