[nostalgia] Update Developer Handbook
This commit is contained in:
parent
e8a046c2dc
commit
0a48692ee1
@ -1,4 +1,4 @@
|
|||||||
# Developer Handbook
|
# Nostalgia Developer Handbook
|
||||||
|
|
||||||
## About
|
## About
|
||||||
|
|
||||||
@ -88,7 +88,8 @@ uint8_t *loadRom(const char *path) {
|
|||||||
fseek(file, 0, SEEK_END);
|
fseek(file, 0, SEEK_END);
|
||||||
const auto size = ftell(file);
|
const auto size = ftell(file);
|
||||||
rewind(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];
|
auto buff = new uint8_t[size];
|
||||||
fread(buff, size, 1, file);
|
fread(buff, size, 1, file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
@ -110,7 +111,8 @@ int main() {
|
|||||||
// using malloc does not call the constructor
|
// using malloc does not call the constructor
|
||||||
std::vector<int> *list = (std::vector<int>*) malloc(sizeof(std::vector<int>));
|
std::vector<int> *list = (std::vector<int>*) malloc(sizeof(std::vector<int>));
|
||||||
doStuff(list);
|
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);
|
free(list);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -143,10 +145,10 @@ likely will change.
|
|||||||
### Error Handling
|
### Error Handling
|
||||||
|
|
||||||
Exceptions are clean and nice in userland code running in environments with
|
Exceptions are clean and nice in userland code running in environments with
|
||||||
expansive system resources, but absolutely unacceptable in code running in
|
expansive system resources, but they are a bit of a pain in small bare metal
|
||||||
restrictive bare metal environments.
|
environments.
|
||||||
The GBA build has them disabled.
|
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.
|
inflates the size of the binary.
|
||||||
The binary size bloat is often cited as one of the main reasons why many
|
The binary size bloat is often cited as one of the main reasons why many
|
||||||
embedded developers prefer C to C++.
|
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.
|
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.
|
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.
|
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
|
The model function takes an instance of the type it is modelling and a template
|
||||||
parameter type.
|
parameter type.
|
||||||
The template parameter type must implement the API used in the models, but it
|
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:
|
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
|
### Serialization
|
||||||
|
|
||||||
Using the model system, Ox provides for 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::Result<ox::Buffer> writeSpritePalette1(NostalgiaPalette *pal) noexcept {
|
||||||
ox::Buffer buffer(ox::units::MB);
|
ox::Buffer buffer(ox::units::MB);
|
||||||
oxReturnError(ox::writeMC(buffer.data(), buffer.size(), pal));
|
oxReturnError(ox::writeMC(buffer.data(), buffer.size(), pal));
|
||||||
return ox::move(buffer);
|
return std::move(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Result<ox::Buffer> writeSpritePalette2(NostalgiaPalette *pal) noexcept {
|
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::Result<ox::Buffer> writeSpritePalette1(NostalgiaPalette *pal) noexcept {
|
||||||
ox::Buffer buffer(ox::units::MB);
|
ox::Buffer buffer(ox::units::MB);
|
||||||
oxReturnError(ox::writeOC(buffer.data(), buffer.size(), pal));
|
oxReturnError(ox::writeOC(buffer.data(), buffer.size(), pal));
|
||||||
return ox::move(buffer);
|
return std::move(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Result<ox::Buffer> writeSpritePalette2(NostalgiaPalette *pal) noexcept {
|
ox::Result<ox::Buffer> writeSpritePalette2(NostalgiaPalette *pal) noexcept {
|
||||||
|
Loading…
Reference in New Issue
Block a user