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( add_library(
NostalgiaCommon 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 * 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/. * 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 nostalgia {
namespace core { namespace core {
ox::Error init() { ox::Error init(Context *ctx) {
auto err = initGfx(); ox::Error err = 0;
err = initGfx(ctx);
return err; return err;
} }

View File

@ -5,14 +5,17 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
#pragma once #pragma once
#include <ox/fs/filesystem.hpp>
#include "gfx.hpp" #include "gfx.hpp"
namespace nostalgia { namespace nostalgia {
namespace core { namespace core {
ox::Error init(); ox::Error init(Context *ctx);
} }
} }

View File

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

View File

@ -9,14 +9,16 @@
#include <ox/std/types.hpp> #include <ox/std/types.hpp>
#include "context.hpp"
namespace nostalgia { namespace nostalgia {
namespace core { 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
#include <ox/std/std.hpp> #include "../gfx.hpp"
namespace nostalgia { namespace nostalgia {
namespace core { namespace core {
ox::Error initGfx() { ox::Error initGfx(Context *ctx) {
return 0; 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> #include <nostalgia/core/core.hpp>
using namespace nostalgia; using namespace nostalgia::core;
int main() { int main() {
core::init(); Context ctx;
core::initConsole(); init(&ctx);
core::puts(9 * 32 + 8, "HELLO,WORLD!"); initConsole(&ctx);
core::puts(10 * 32 + 8, "01234 56789"); puts(&ctx, 9 * 32 + 8, "HELLO,WORLD!");
puts(&ctx, 10 * 32 + 8, "01234 56789");
while (1); while (1);
return 0; return 0;
} }