Add Context to core

This commit is contained in:
Gary Talent 2017-10-12 04:50:33 -05:00
parent 329e8be825
commit 507c894c15
8 changed files with 62 additions and 28 deletions

View File

@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 2.8.11)
add_library(
NostalgiaCommon

View File

@ -0,0 +1,21 @@
/*
* 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>
namespace nostalgia {
namespace core {
// User Input Output
struct Context {
ox::FileSystem32 *rom = nullptr;
};
}
}

View File

@ -5,14 +5,15 @@
* 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/std/types.hpp>
#include "gfx.hpp"
#include "core.hpp"
namespace nostalgia {
namespace core {
ox::Error init() {
auto err = initGfx();
ox::Error init(Context *ctx) {
ox::Error err = 0;
err = initGfx(ctx);
return err;
}

View File

@ -5,14 +5,17 @@
* 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/filesystem.hpp>
#include "gfx.hpp"
namespace nostalgia {
namespace core {
ox::Error init();
ox::Error init(Context *ctx);
}
}

View File

@ -116,7 +116,7 @@ static char charMap[128] = {
26, // Z
};
ox::Error initGfx() {
ox::Error initGfx(Context *ctx) {
/* Sprite Mode ----\ */
/* ---\| */
/* Background 0 -\|| */
@ -127,31 +127,37 @@ ox::Error initGfx() {
return 0;
}
void initConsole() {
auto charsetInode = 101;
ox::Error initConsole(Context *ctx) {
const auto CharsetInode = 101;
const auto PaletteStart = sizeof(GbaImageDataHeader);
ox::Error err = 0;
auto fs = (FileStore32*) findMedia();
GbaImageDataHeader imgData;
fs->read(101, 0, sizeof(imgData), &imgData, nullptr);
REG_BG0CNT = (28 << 8) | 1;
if (fs) {
err |= fs->read(CharsetInode, 0, sizeof(imgData), &imgData, nullptr);
// load palette
fs->read(charsetInode, sizeof(GbaImageDataHeader),
err |= fs->read(CharsetInode, PaletteStart,
512, (uint16_t*) &MEM_PALLETE_BG[0], nullptr);
if (imgData.bpp == 4) {
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);
} else {
} else if (imgData.bpp == 4) {
REG_BG0CNT |= (1 << 7); // set to use 8 bits per pixel
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);
}
} else {
err = 1;
}
return err;
}
void puts(int loc, const char *str) {
void puts(Context *ctx, int loc, const char *str) {
for (int i = 0; str[i]; i++) {
MEM_BG_MAP[28][loc + i] = charMap[(int) str[i]];
}

View File

@ -9,14 +9,16 @@
#include <ox/std/types.hpp>
#include "context.hpp"
namespace nostalgia {
namespace core {
ox::Error initGfx();
ox::Error initGfx(Context *ctx);
void initConsole();
ox::Error initConsole(Context *ctx);
void puts(int loc, const char *str);
void puts(Context *ctx, int loc, const char *str);
}
}

View File

@ -6,19 +6,20 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <ox/std/std.hpp>
#include "../gfx.hpp"
namespace nostalgia {
namespace core {
ox::Error initGfx() {
return 0;
ox::Error initGfx(Context *ctx) {
return 1;
}
void initConsole() {
ox::Error initConsole(Context *ctx) {
return 1;
}
void puts(int loc, const char *str) {
void puts(Context *ctx, int loc, const char *str) {
}
}

View File

@ -8,13 +8,14 @@
#include <nostalgia/core/core.hpp>
using namespace nostalgia;
using namespace nostalgia::core;
int main() {
core::init();
core::initConsole();
core::puts(9 * 32 + 8, "HELLO,WORLD!");
core::puts(10 * 32 + 8, "01234 56789");
Context ctx;
init(&ctx);
initConsole(&ctx);
puts(&ctx, 9 * 32 + 8, "HELLO,WORLD!");
puts(&ctx, 10 * 32 + 8, "01234 56789");
while (1);
return 0;
}