[nostalgia/core] Update for newer versions of ox

This commit is contained in:
Gary Talent 2019-06-14 07:56:53 -05:00
parent 22c9e4bdb2
commit 829357faaf
4 changed files with 37 additions and 27 deletions

View File

@ -21,13 +21,13 @@ typedef Tile CharBlock[512];
typedef Tile8 CharBlock8[256];
struct __attribute__((packed)) GbaImageDataHeader {
uint8_t bpp;
uint16_t tileCount;
uint8_t bpp = 0;
uint16_t tileCount = 0;
};
struct __attribute__((packed)) GbaImageData {
GbaImageDataHeader header;
Palette __attribute__((packed)) pal;
Palette __attribute__((packed)) pal = {};
uint8_t tiles[1];
};

View File

@ -158,7 +158,7 @@ static char charMap[128] = {
0, // ~
};
ox::Error initGfx(Context *ctx) {
ox::Error initGfx(Context*) {
/* Sprite Mode ----\ */
/* ---\| */
/* Background 0 -\|| */
@ -174,25 +174,25 @@ ox::Error initConsole(Context*) {
const auto CharsetInode = 101;
const auto PaletteStart = sizeof(GbaImageDataHeader);
ox::Error err = 0;
auto fs = (FileStore32*) loadRom();
ox::FileStore32 fs(loadRom(), 32 * 1024 * 1024);
GbaImageDataHeader imgData;
REG_BG0CNT = (28 << 8) | 1;
if (fs) {
if (fs.valid()) {
// load the header
err |= fs->read(CharsetInode, 0, sizeof(imgData), &imgData, nullptr);
err |= fs.read(CharsetInode, 0, sizeof(imgData), &imgData, nullptr);
// load palette
err |= fs->read(CharsetInode, PaletteStart,
err |= fs.read(CharsetInode, PaletteStart,
512, (uint16_t*) &MEM_PALLETE_BG[0], nullptr);
if (imgData.bpp == 4) {
err |= fs->read(CharsetInode, __builtin_offsetof(GbaImageData, tiles),
err |= fs.read(CharsetInode, __builtin_offsetof(GbaImageData, tiles),
sizeof(Tile) * imgData.tileCount, (uint16_t*) &TILE_ADDR[0][1], nullptr);
} else if (imgData.bpp == 8) {
REG_BG0CNT |= (1 << 7); // set to use 8 bits per pixel
err |= fs->read(CharsetInode, __builtin_offsetof(GbaImageData, tiles),
err |= fs.read(CharsetInode, __builtin_offsetof(GbaImageData, tiles),
sizeof(Tile8) * imgData.tileCount, (uint16_t*) &TILE8_ADDR[0][1], nullptr);
} else {
err = 1;
@ -203,27 +203,27 @@ ox::Error initConsole(Context*) {
return err;
}
ox::Error loadTileSheet(Context *ctx, InodeId_t inode) {
ox::Error loadTileSheet(Context*, InodeId_t inode) {
ox::Error err = 0;
const auto PaletteStart = sizeof(GbaImageDataHeader);
GbaImageDataHeader imgData;
auto fs = (ox::FileStore32*) ctx->rom->buff();
ox::FileStore32 fs(loadRom(), 32 * 1024 * 1024);
REG_BG0CNT = (28 << 8) | 1;
if (fs) {
if (fs.valid()) {
// load the header
err |= fs->read(inode, 0, sizeof(imgData), &imgData, nullptr);
err |= fs.read(inode, 0, sizeof(imgData), &imgData, nullptr);
// load palette
err |= fs->read(inode, PaletteStart,
err |= fs.read(inode, PaletteStart,
512, (uint16_t*) &MEM_PALLETE_BG[0], nullptr);
if (imgData.bpp == 4) {
err |= fs->read(inode, __builtin_offsetof(GbaImageData, tiles),
err |= fs.read(inode, __builtin_offsetof(GbaImageData, tiles),
sizeof(Tile) * imgData.tileCount, (uint16_t*) &TILE_ADDR[0][1], nullptr);
} else if (imgData.bpp == 8) {
REG_BG0CNT |= (1 << 7); // set to use 8 bits per pixel
err |= fs->read(inode, __builtin_offsetof(GbaImageData, tiles),
err |= fs.read(inode, __builtin_offsetof(GbaImageData, tiles),
sizeof(Tile8) * imgData.tileCount, (uint16_t*) &TILE8_ADDR[0][1], nullptr);
} else {
err = 1;
@ -241,7 +241,7 @@ void puts(Context*, int loc, const char *str) {
}
}
void setTile(Context *ctx, int layer, int column, int row, uint8_t tile) {
void setTile(Context*, int layer, int column, int row, uint8_t tile) {
if (column < GBA_TILE_COLUMNS && row < GBA_TILE_ROWS) {
MEM_BG_MAP[28 + layer][row * GBA_TILE_COLUMNS + column] = tile;
}

View File

@ -17,11 +17,11 @@ namespace nostalgia::core {
uint8_t *loadRom(const char*) {
// put the header in the wrong order to prevent mistaking this code for the
// media section
const static auto headerP2 = "_HEADER_________";
const static auto headerP1 = "NOSTALGIA_MEDIA";
const static auto headerP1Len = 15;
const static auto headerP2Len = 16;
const static auto headerLen = headerP1Len + headerP2Len + 1;
constexpr auto headerP2 = "_HEADER_________";
constexpr auto headerP1 = "NOSTALGIA_MEDIA";
constexpr auto headerP1Len = 15;
constexpr auto headerP2Len = 16;
constexpr auto headerLen = headerP1Len + headerP2Len + 1;
for (auto current = &MEM_ROM; current < ((uint8_t*) 0x0a000000); current += headerLen) {
if (ox_memcmp(current, headerP1, headerP1Len) == 0 &&

View File

@ -11,6 +11,8 @@
#include <ox/std/std.hpp>
#pragma GCC diagnostic ignored "-Wcast-align"
namespace nostalgia::core {
struct HeapSegment {
@ -26,7 +28,7 @@ struct HeapSegment {
static HeapSegment *volatile _heapIdx = nullptr;
void initHeap() {
_heapIdx = ((HeapSegment*) MEM_WRAM_END) - 1;
_heapIdx = reinterpret_cast<HeapSegment*>(MEM_WRAM_END) - 1;
// set size to half of WRAM
_heapIdx->size = (MEM_WRAM_END - MEM_WRAM_BEGIN) / 2;
_heapIdx->next = nullptr;
@ -52,7 +54,7 @@ void *malloc(std::size_t allocSize) {
panic("Heap allocation failed");
}
seg = (HeapSegment*) (((uint8_t*) seg) - allocSize);
seg = reinterpret_cast<HeapSegment*>(reinterpret_cast<uint8_t*>(seg) - allocSize);
if (prev) {
prev->next = seg;
}
@ -68,7 +70,7 @@ void *malloc(std::size_t allocSize) {
if (hs.size == 0) {
_heapIdx = hs.next;
} else {
_heapIdx = (HeapSegment*) (((uint8_t*) _heapIdx) - fullSize);
_heapIdx = reinterpret_cast<HeapSegment*>((reinterpret_cast<uint8_t*>(_heapIdx)) - fullSize);
*_heapIdx = hs;
}
@ -88,7 +90,7 @@ void free(void *ptrIn) {
// ptr was found as a valid memory allocation, deallocate it
if (current) {
// move header back to end of segment
auto newCurrent = (HeapSegment*) current->end() - sizeof(HeapSegment);
auto newCurrent = reinterpret_cast<HeapSegment*>(current->end() - sizeof(HeapSegment));
*newCurrent = *current;
current = newCurrent;
prev->next = current;
@ -132,3 +134,11 @@ void operator delete(void *ptr) {
void operator delete[](void *ptr) {
free(ptr);
}
void operator delete(void *ptr, unsigned) {
free(ptr);
}
void operator delete[](void *ptr, unsigned) {
free(ptr);
}