[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]; typedef Tile8 CharBlock8[256];
struct __attribute__((packed)) GbaImageDataHeader { struct __attribute__((packed)) GbaImageDataHeader {
uint8_t bpp; uint8_t bpp = 0;
uint16_t tileCount; uint16_t tileCount = 0;
}; };
struct __attribute__((packed)) GbaImageData { struct __attribute__((packed)) GbaImageData {
GbaImageDataHeader header; GbaImageDataHeader header;
Palette __attribute__((packed)) pal; Palette __attribute__((packed)) pal = {};
uint8_t tiles[1]; uint8_t tiles[1];
}; };

View File

@ -158,7 +158,7 @@ static char charMap[128] = {
0, // ~ 0, // ~
}; };
ox::Error initGfx(Context *ctx) { ox::Error initGfx(Context*) {
/* Sprite Mode ----\ */ /* Sprite Mode ----\ */
/* ---\| */ /* ---\| */
/* Background 0 -\|| */ /* Background 0 -\|| */
@ -174,25 +174,25 @@ ox::Error initConsole(Context*) {
const auto CharsetInode = 101; const auto CharsetInode = 101;
const auto PaletteStart = sizeof(GbaImageDataHeader); const auto PaletteStart = sizeof(GbaImageDataHeader);
ox::Error err = 0; ox::Error err = 0;
auto fs = (FileStore32*) loadRom(); ox::FileStore32 fs(loadRom(), 32 * 1024 * 1024);
GbaImageDataHeader imgData; GbaImageDataHeader imgData;
REG_BG0CNT = (28 << 8) | 1; REG_BG0CNT = (28 << 8) | 1;
if (fs) { if (fs.valid()) {
// load the header // load the header
err |= fs->read(CharsetInode, 0, sizeof(imgData), &imgData, nullptr); err |= fs.read(CharsetInode, 0, sizeof(imgData), &imgData, nullptr);
// load palette // load palette
err |= fs->read(CharsetInode, PaletteStart, err |= fs.read(CharsetInode, PaletteStart,
512, (uint16_t*) &MEM_PALLETE_BG[0], nullptr); 512, (uint16_t*) &MEM_PALLETE_BG[0], nullptr);
if (imgData.bpp == 4) { 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); sizeof(Tile) * imgData.tileCount, (uint16_t*) &TILE_ADDR[0][1], nullptr);
} else if (imgData.bpp == 8) { } else if (imgData.bpp == 8) {
REG_BG0CNT |= (1 << 7); // set to use 8 bits per pixel 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); sizeof(Tile8) * imgData.tileCount, (uint16_t*) &TILE8_ADDR[0][1], nullptr);
} else { } else {
err = 1; err = 1;
@ -203,27 +203,27 @@ ox::Error initConsole(Context*) {
return err; return err;
} }
ox::Error loadTileSheet(Context *ctx, InodeId_t inode) { ox::Error loadTileSheet(Context*, InodeId_t inode) {
ox::Error err = 0; ox::Error err = 0;
const auto PaletteStart = sizeof(GbaImageDataHeader); const auto PaletteStart = sizeof(GbaImageDataHeader);
GbaImageDataHeader imgData; GbaImageDataHeader imgData;
auto fs = (ox::FileStore32*) ctx->rom->buff(); ox::FileStore32 fs(loadRom(), 32 * 1024 * 1024);
REG_BG0CNT = (28 << 8) | 1; REG_BG0CNT = (28 << 8) | 1;
if (fs) { if (fs.valid()) {
// load the header // load the header
err |= fs->read(inode, 0, sizeof(imgData), &imgData, nullptr); err |= fs.read(inode, 0, sizeof(imgData), &imgData, nullptr);
// load palette // load palette
err |= fs->read(inode, PaletteStart, err |= fs.read(inode, PaletteStart,
512, (uint16_t*) &MEM_PALLETE_BG[0], nullptr); 512, (uint16_t*) &MEM_PALLETE_BG[0], nullptr);
if (imgData.bpp == 4) { 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); sizeof(Tile) * imgData.tileCount, (uint16_t*) &TILE_ADDR[0][1], nullptr);
} else if (imgData.bpp == 8) { } else if (imgData.bpp == 8) {
REG_BG0CNT |= (1 << 7); // set to use 8 bits per pixel 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); sizeof(Tile8) * imgData.tileCount, (uint16_t*) &TILE8_ADDR[0][1], nullptr);
} else { } else {
err = 1; 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) { if (column < GBA_TILE_COLUMNS && row < GBA_TILE_ROWS) {
MEM_BG_MAP[28 + layer][row * GBA_TILE_COLUMNS + column] = tile; 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*) { uint8_t *loadRom(const char*) {
// put the header in the wrong order to prevent mistaking this code for the // put the header in the wrong order to prevent mistaking this code for the
// media section // media section
const static auto headerP2 = "_HEADER_________"; constexpr auto headerP2 = "_HEADER_________";
const static auto headerP1 = "NOSTALGIA_MEDIA"; constexpr auto headerP1 = "NOSTALGIA_MEDIA";
const static auto headerP1Len = 15; constexpr auto headerP1Len = 15;
const static auto headerP2Len = 16; constexpr auto headerP2Len = 16;
const static auto headerLen = headerP1Len + headerP2Len + 1; constexpr auto headerLen = headerP1Len + headerP2Len + 1;
for (auto current = &MEM_ROM; current < ((uint8_t*) 0x0a000000); current += headerLen) { for (auto current = &MEM_ROM; current < ((uint8_t*) 0x0a000000); current += headerLen) {
if (ox_memcmp(current, headerP1, headerP1Len) == 0 && if (ox_memcmp(current, headerP1, headerP1Len) == 0 &&

View File

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