Fix alignment issues with writing to VRAM, which is half-word addressable

This commit is contained in:
2017-04-18 17:49:35 -05:00
parent 661e60c24a
commit c1f9630634
7 changed files with 19 additions and 12 deletions

View File

@ -13,15 +13,15 @@
namespace nostalgia {
namespace core {
typedef struct { uint32_t data[8]; } Tile, Tile4;
typedef struct { uint32_t data[8]; } __attribute__((aligned(4))) Tile, Tile4;
// d-tile: double-sized tile (8bpp)
typedef struct { uint32_t data[16]; } Tile8;
typedef struct { uint32_t data[16]; } __attribute__((aligned(4))) Tile8;
// tile block: 32x16 tiles, 16x16 d-tiles
typedef uint16_t Pallete[256];
typedef Tile CharBlock[512];
typedef Tile8 CharBlock8[256];
struct GbaImageData {
struct __attribute__((packed)) GbaImageData {
Pallete pal;
uint16_t tileCount;
uint8_t bpp;

View File

@ -133,7 +133,7 @@ void initConsole() {
REG_BG0CNT |= (1 << 7); // set to use 8 bits per pixel
if (fs) {
FileStore32::FsSize_t readSize = 0;
fs->read(1, 516, 64 * 38, &TILE8_ADDR[0][1], nullptr);
fs->read(2, __builtin_offsetof(GbaImageData, tiles), 64 * 38, &TILE8_ADDR[0][1], nullptr);
fs->read(1, 0, 512, &MEM_PALLETE_BG[0], &readSize);
}
}

View File

@ -22,7 +22,7 @@ uint8_t *findMedia() {
const static auto headerP1Len = 15;
const static auto headerP2Len = 16;
const static auto headerLen = headerP1Len + headerP2Len + 1;
for (auto current = &MEM_ROM; current < ((uint8_t*) 0x0a000000); current += headerLen) {
if (ox_memcmp(current, headerP1, headerP1Len) == 0 &&
ox_memcmp(current + headerP1Len, headerP2, headerP2Len) == 0) {

View File

@ -73,8 +73,9 @@ int run(ClArgs args) {
}
QMap<QRgb, int> colors;
const auto imgDataBuffSize = sizeof(Pallete) + argTiles * 64;
const auto imgDataBuffSize = sizeof(GbaImageData) + 1 + argTiles * 64;
uint8_t imgDataBuff[imgDataBuffSize];
memset(&imgDataBuff, 0, imgDataBuffSize);
GbaImageData *id = (GbaImageData*) imgDataBuff;
id->bpp = 8;
id->tileCount = argTiles;
@ -90,7 +91,7 @@ int run(ClArgs args) {
colors[c] = colorId;
colorId++;
}
((uint8_t*) &id->tiles)[destI] = colors[c];
id->tiles[destI] = colors[c];
}
}
}