[nostalgia/core] Replace puts loc param with column and row params

This commit is contained in:
Gary Talent 2019-11-09 17:56:50 -06:00
parent 5dc74e6fd7
commit 71b38b243e
8 changed files with 37 additions and 30 deletions

View File

@ -9,6 +9,7 @@ add_library(
target_link_libraries(
NostalgiaCore-GBA PUBLIC
NostalgiaCore
GbaStartup
OxFS
OxStd

View File

@ -112,7 +112,11 @@ ox::Error initConsole(Context *ctx) {
constexpr auto PaletteAddr = "/Palettes/Charset.npal";
if (!ctx) {
ctx = new (ox_alloca(sizeof(Context))) Context();
ox::FileStore32 fs(loadRom(), 32 * ox::units::MB);
auto rom = loadRom();
if (!rom) {
return OxError(1);
}
ox::FileStore32 fs(rom, 32 * ox::units::MB);
ctx->rom = new (ox_alloca(sizeof(ox::FileSystem32))) ox::FileSystem32(fs);
}
return loadTileSheet(ctx, TileSheetSpace::Background, 0, TilesheetAddr, PaletteAddr);

View File

@ -13,10 +13,10 @@ namespace nostalgia::core {
void panic(const char *msg) {
oxIgnoreError(initConsole(nullptr));
puts(nullptr, 1 * 32 + 0, "SADNESS...");
puts(nullptr, 4 * 32 + 0, "UNEXPECTED STATE:");
puts(nullptr, 6 * 32 + 2, msg);
puts(nullptr, 10 * 32 + 0, "PLEASE RESTART THE SYSTEM");
puts(nullptr, 32 + 0, 1, "SADNESS...");
puts(nullptr, 32 + 0, 4, "UNEXPECTED STATE:");
puts(nullptr, 32 + 2, 6, msg);
puts(nullptr, 32 + 0, 10, "PLEASE RESTART THE SYSTEM");
// TODO: properly end program execution, this wastes power
while (1);
}

View File

@ -141,9 +141,9 @@ char charMap[128] = {
0, // ~
};
void puts(Context *ctx, int loc, const char *str) {
void puts(Context *ctx, int column, int row, const char *str) {
for (int i = 0; str[i]; i++) {
setTile(ctx, 0, loc + i, 0, charMap[static_cast<int>(str[i])]);
setTile(ctx, 0, column + i, row, charMap[static_cast<int>(str[i])]);
}
}

View File

@ -65,7 +65,7 @@ ox::Error model(T *io, NostalgiaGraphic *ng) {
ox::Error loadTileSheet(Context *ctx, ox::FileAddress file);
void puts(Context *ctx, int loc, const char *str);
void puts(Context *ctx, int column, int row, const char *str);
void setTile(Context *ctx, int layer, int column, int row, uint8_t tile);

View File

@ -21,7 +21,8 @@ static SDL_Window *window = nullptr;
static SDL_Renderer *renderer = nullptr;
static std::array<SDL_Texture*, 4> bgTextures;
static std::vector<std::vector<int>> bgTileMaps(128, std::vector<int>(128, 0));
using TileMap = std::array<std::array<int, 128>, 128>;
static std::array<TileMap, 4> bgTileMaps;
[[nodiscard]] static ox::ValErr<ox::Vector<uint8_t>> readFile(Context *ctx, const ox::FileAddress &file) {
auto [stat, err] = ctx->rom->stat(file);
@ -124,39 +125,42 @@ ox::Error loadTileSheet(Context *ctx,
return OxError(0);
}
void drawBackground(SDL_Texture *tex) {
constexpr auto DstSize = 32;
//oxTrace("nostalgia::core::drawBackground") << "Drawing background";
SDL_Rect src = {}, dst = {};
src.x = 0;
src.w = 8;
src.h = 8;
dst.x = 0;
dst.y = 0;
dst.w = DstSize;
dst.h = DstSize;
void drawBackground(const TileMap &tm, SDL_Texture *tex) {
if (tex) {
for (auto &m : bgTileMaps) {
constexpr auto DstSize = 32;
//oxTrace("nostalgia::core::drawBackground") << "Drawing background";
SDL_Rect src = {}, dst = {};
src.x = 0;
src.w = 8;
src.h = 8;
dst.x = 0;
dst.y = 0;
dst.w = DstSize;
dst.h = DstSize;
for (auto &m : tm) {
for (auto t : m) {
src.y = t * 8;
SDL_RenderCopy(renderer, tex, &src, &dst);
dst.y += DstSize;
dst.x += DstSize;
}
dst.x += DstSize;
dst.y = 0;
dst.x = 0;
dst.y += DstSize;
}
}
}
void draw() {
SDL_RenderClear(renderer);
for (auto tex : bgTextures) {
drawBackground(tex);
for (std::size_t i = 0; i < bgTileMaps.size(); i++) {
auto tex = bgTextures[i];
auto &tm = bgTileMaps[i];
drawBackground(tm, tex);
}
SDL_RenderPresent(renderer);
}
void setTile(Context*, int, int, int, uint8_t) {
void setTile(Context*, int layer, int column, int row, uint8_t tile) {
bgTileMaps[layer][row][column] = tile;
}
}

View File

@ -12,6 +12,4 @@
namespace nostalgia::core {
typedef ox::FileStore32::InodeId_t InodeId_t;
}

View File

@ -22,7 +22,7 @@ ox::Error run(ox::FileSystem *fs) {
//oxReturnError(zone.init(&ctx, Bounds{0, 0, 40, 40}, "/TileSheets/Charset.ng", "/Palettes/Charset.npal"));
//zone.draw(&ctx);
oxReturnError(initConsole(&ctx));
puts(&ctx, 9 * 32 + 10, "DOPENESS!!!");
puts(&ctx, 10, 9, "DOPENESS!!!");
oxReturnError(run());
oxReturnError(shutdownGfx());
return OxError(0);