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

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

View File

@ -3,12 +3,12 @@ FROM wombatant/devenv:latest
ENV DEVKITPRO /opt/devkitPro
ENV DEVKITARM ${DEVKITPRO}/devkitARM
RUN dnf install -y qt5-devel
RUN dnf install -y qt5-devel llvm libasan
###############################################################################
# Install Ox
RUN git clone -b release-0.1 https://github.com/wombatant/ox.git /usr/local/src/ox && \
RUN git clone -b e976fd3fe62c98be29c4389ba6700a4a1fb8e0ae https://github.com/wombatant/ox.git /usr/local/src/ox && \
cd /usr/local/src/ox && \
# setup build dirs
mkdir -p \

View File

@ -10,6 +10,9 @@ endif
make:
${ENV_RUN} make -j -C build HOST_ENV=${HOST_ENV}
build_rom:
${ENV_RUN} make -j -C build HOST_ENV=${HOST_ENV}
${ENV_RUN} ./build_rom.sh
preinstall:
${ENV_RUN} make -j -C build ARGS="preinstall" HOST_ENV=${HOST_ENV}
install:
@ -31,12 +34,13 @@ gdb: make
devenv-build:
docker build --no-cache . -t ${DEVENV_IMAGE}
devenv:
docker run -d -v $(shell pwd):/usr/src/project \
docker run -d \
-e LOCAL_USER_ID=$(shell id -u ${USER}) \
-e DISPLAY=$(DISPLAY) \
-e QT_AUTO_SCREEN_SCALE_FACTOR=1 \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v /run/dbus/:/run/dbus/ \
-v $(shell pwd):/usr/src/project \
-v /dev/shm:/dev/shm \
--restart=always \
--name ${DEVENV} \

View File

@ -2,9 +2,11 @@
set -e
padbin 32 build/gba-release/src/player/nostalgia.bin
${DEVKITARM}/bin/padbin 32 build/gba-release/src/player/nostalgia.bin
echo NOSTALGIA_MEDIA_HEADER_________ > media_header.txt
oxfs format 32 1m nostalgia_media.oxfs
./build/current/src/tools/nost-pack -fs nostalgia_media.oxfs -img charset.png -inode 1 -tiles 40 -c
cat build/gba-release/src/player/nostalgia.bin media_header.txt nostalgia_media.oxfs > nostalgia.gba
gbafix nostalgia.gba
${DEVKITARM}/bin/gbafix nostalgia.gba

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];
}
}
}