Add support world drawing

This commit is contained in:
2017-11-09 21:43:59 -06:00
parent 539aa1e7eb
commit 2edee450aa
22 changed files with 232 additions and 61 deletions

View File

@@ -16,6 +16,7 @@ elseif(NOSTALGIA_BUILD_TYPE STREQUAL "Native")
set(
CPP
qt/gfx.cpp
userland/media.cpp
userland/mem.cpp
)
endif()
@@ -34,6 +35,7 @@ install(
FILES
core.hpp
gfx.hpp
media.hpp
gba/gba.hpp
DESTINATION
include/nostalgia/core

View File

@@ -11,6 +11,8 @@
#include <ox/fs/filesystem.hpp>
#include "gfx.hpp"
#include "media.hpp"
#include "types.hpp"
namespace nostalgia {
namespace core {

View File

@@ -8,9 +8,13 @@
#include <ox/fs/filesystem.hpp>
#include <ox/std/std.hpp>
#include "../media.hpp"
#include "addresses.hpp"
#include "media.hpp"
#include "gba.hpp"
#include "panic.hpp"
#include "../gfx.hpp"
namespace nostalgia {
@@ -22,6 +26,7 @@ using namespace ox;
#define TILE8_ADDR ((CharBlock8*) 0x06000000)
const auto GBA_TILE_COLUMNS = 32;
const auto GBA_TILE_ROWS = 32;
// map ASCII values to the nostalgia charset
static char charMap[128] = {
@@ -170,7 +175,7 @@ ox::Error initConsole(Context*) {
const auto CharsetInode = 101;
const auto PaletteStart = sizeof(GbaImageDataHeader);
ox::Error err = 0;
auto fs = (FileStore32*) findMedia();
auto fs = (FileStore32*) loadRom();
GbaImageDataHeader imgData;
@@ -199,6 +204,37 @@ ox::Error initConsole(Context*) {
return err;
}
ox::Error loadTileSheet(Context *ctx, InodeId_t inode) {
ox::Error err = 0;
const auto PaletteStart = sizeof(GbaImageDataHeader);
GbaImageDataHeader imgData;
auto fs = (ox::FileStore32*) ctx->rom->buff();
REG_BG0CNT = (28 << 8) | 1;
if (fs) {
// load the header
err |= fs->read(inode, 0, sizeof(imgData), &imgData, nullptr);
// load palette
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),
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),
sizeof(Tile8) * imgData.tileCount, (uint16_t*) &TILE8_ADDR[0][1], nullptr);
} else {
err = 1;
}
} else {
err = 1;
}
return err;
}
// Do NOT use Context in the GBA version of this function.
void puts(Context*, int loc, const char *str) {
for (int i = 0; str[i]; i++) {
@@ -206,8 +242,10 @@ void puts(Context*, int loc, const char *str) {
}
}
void setTile(Context *ctx, int layer, int column, int row, uint16_t tile) {
MEM_BG_MAP[28 + layer][row * GBA_TILE_COLUMNS + column] = tile;
void setTile(Context *ctx, 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

@@ -9,12 +9,13 @@
#include <ox/fs/filesystem.hpp>
#include <ox/std/std.hpp>
#include "addresses.hpp"
#include "media.hpp"
#include "../media.hpp"
namespace nostalgia {
namespace core {
uint8_t *findMedia() {
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_________";
@@ -29,7 +30,7 @@ uint8_t *findMedia() {
return current + headerLen;
}
}
return 0;
return nullptr;
}
}

View File

@@ -5,11 +5,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <ox/std/types.hpp>
#include "context.hpp"
#include "types.hpp"
namespace nostalgia {
namespace core {
@@ -18,9 +20,11 @@ ox::Error initGfx(Context *ctx);
ox::Error initConsole(Context *ctx);
ox::Error loadTileSheet(Context *ctx, InodeId_t inode);
void puts(Context *ctx, int loc, const char *str);
void setTile(Context *ctx, int layer, int column, int row, uint16_t tile);
void setTile(Context *ctx, int layer, int column, int row, uint8_t tile);
}
}

View File

@@ -13,7 +13,7 @@
namespace nostalgia {
namespace core {
uint8_t *findMedia();
uint8_t *loadRom(const char *path = "");
}
}

View File

@@ -19,8 +19,15 @@ ox::Error initConsole(Context *ctx) {
return 1;
}
ox::Error loadTileSheet(Context *ctx, InodeId_t inode) {
return 1;
}
void puts(Context *ctx, int loc, const char *str) {
}
void setTile(Context *ctx, int layer, int column, int row, uint8_t tile) {
}
}
}

View File

@@ -0,0 +1,19 @@
/*
* Copyright 2016-2017 gtalent2@gmail.com
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <ox/fs/filestore.hpp>
namespace nostalgia {
namespace core {
typedef ox::FileStore32::InodeId_t InodeId_t;
}
}

View File

@@ -0,0 +1,22 @@
/*
* Copyright 2016-2017 gtalent2@gmail.com
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <ox/fs/filesystem.hpp>
#include <ox/std/std.hpp>
#include "../media.hpp"
namespace nostalgia {
namespace core {
uint8_t *loadRom(const char*) {
return nullptr;
}
}
}