From 628b4d656b919b037c07eb09198ca4b021b9eddc Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 3 Nov 2019 23:20:13 -0600 Subject: [PATCH] [nostalgia/core] Move puts function out of core implementations to core --- src/nostalgia/core/CMakeLists.txt | 1 + src/nostalgia/core/gba/gfx.cpp | 148 +---------------------------- src/nostalgia/core/gfx.cpp | 150 ++++++++++++++++++++++++++++++ src/nostalgia/core/sdl/gfx.cpp | 9 +- 4 files changed, 159 insertions(+), 149 deletions(-) create mode 100644 src/nostalgia/core/gfx.cpp diff --git a/src/nostalgia/core/CMakeLists.txt b/src/nostalgia/core/CMakeLists.txt index 6e1bb47e..5c6309ba 100644 --- a/src/nostalgia/core/CMakeLists.txt +++ b/src/nostalgia/core/CMakeLists.txt @@ -1,6 +1,7 @@ add_library( NostalgiaCore core.cpp + gfx.cpp ) target_link_libraries( diff --git a/src/nostalgia/core/gba/gfx.cpp b/src/nostalgia/core/gba/gfx.cpp index 02ccab73..6e78e7f2 100644 --- a/src/nostalgia/core/gba/gfx.cpp +++ b/src/nostalgia/core/gba/gfx.cpp @@ -10,17 +10,16 @@ #include #include -#include "../media.hpp" +#include +#include #include "addresses.hpp" #include "gba.hpp" #include "panic.hpp" -#include "../gfx.hpp" - namespace nostalgia::core { -using namespace ox; +extern char charMap[128]; #define TILE_ADDR ((CharBlock*) 0x06000000) #define TILE8_ADDR ((CharBlock8*) 0x06000000) @@ -28,137 +27,6 @@ using namespace ox; constexpr auto GBA_TILE_COLUMNS = 32; constexpr auto GBA_TILE_ROWS = 32; -// map ASCII values to the nostalgia charset -static char charMap[128] = { - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, // space - 38, // ! - 0, // " - 0, // # - 0, // $ - 0, // % - 0, // & - 0, // ' - 42, // ( - 43, // ) - 0, // * - 0, // + - 37, // , - 0, // - - 39, // . - 0, // / - 27, // 0 - 28, // 1 - 29, // 2 - 30, // 3 - 31, // 4 - 32, // 5 - 33, // 6 - 34, // 7 - 35, // 8 - 36, // 9 - 40, // : - 0, // ; - 0, // < - 41, // = - 0, // > - 0, // ? - 0, // @ - 1, // A - 2, // B - 3, // C - 4, // D - 5, // E - 6, // F - 7, // G - 8, // H - 9, // I - 10, // J - 11, // K - 12, // L - 13, // M - 14, // N - 15, // O - 16, // P - 17, // Q - 18, // R - 19, // S - 20, // T - 21, // U - 22, // V - 23, // W - 24, // X - 25, // Y - 26, // Z - 44, // [ - 0, // backslash - 45, // ] - 0, // ^ - 0, // _ - 0, // ` - 1, // a - 2, // b - 3, // c - 4, // d - 5, // e - 6, // f - 7, // g - 8, // h - 9, // i - 10, // j - 11, // k - 12, // l - 13, // m - 14, // n - 15, // o - 16, // p - 17, // q - 18, // r - 19, // s - 20, // t - 21, // u - 22, // v - 23, // w - 24, // x - 25, // y - 26, // z - 46, // { - 0, // | - 48, // } - 0, // ~ -}; - struct GbaPaletteTarget { volatile uint16_t *palette = nullptr; }; @@ -277,16 +145,8 @@ ox::Error loadTileSheet(Context *ctx, } // 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++) { - MEM_BG_MAP[28][loc + i] = charMap[(int) str[i]]; - } -} - void setTile(Context*, 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; - } + MEM_BG_MAP[28 + layer][row * GBA_TILE_COLUMNS + column] = tile; } } diff --git a/src/nostalgia/core/gfx.cpp b/src/nostalgia/core/gfx.cpp new file mode 100644 index 00000000..2abffce5 --- /dev/null +++ b/src/nostalgia/core/gfx.cpp @@ -0,0 +1,150 @@ +/* + * Copyright 2016 - 2019 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 "gfx.hpp" + +namespace nostalgia::core { + +// map ASCII values to the nostalgia charset +char charMap[128] = { + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, // space + 38, // ! + 0, // " + 0, // # + 0, // $ + 0, // % + 0, // & + 0, // ' + 42, // ( + 43, // ) + 0, // * + 0, // + + 37, // , + 0, // - + 39, // . + 0, // / + 27, // 0 + 28, // 1 + 29, // 2 + 30, // 3 + 31, // 4 + 32, // 5 + 33, // 6 + 34, // 7 + 35, // 8 + 36, // 9 + 40, // : + 0, // ; + 0, // < + 41, // = + 0, // > + 0, // ? + 0, // @ + 1, // A + 2, // B + 3, // C + 4, // D + 5, // E + 6, // F + 7, // G + 8, // H + 9, // I + 10, // J + 11, // K + 12, // L + 13, // M + 14, // N + 15, // O + 16, // P + 17, // Q + 18, // R + 19, // S + 20, // T + 21, // U + 22, // V + 23, // W + 24, // X + 25, // Y + 26, // Z + 44, // [ + 0, // backslash + 45, // ] + 0, // ^ + 0, // _ + 0, // ` + 1, // a + 2, // b + 3, // c + 4, // d + 5, // e + 6, // f + 7, // g + 8, // h + 9, // i + 10, // j + 11, // k + 12, // l + 13, // m + 14, // n + 15, // o + 16, // p + 17, // q + 18, // r + 19, // s + 20, // t + 21, // u + 22, // v + 23, // w + 24, // x + 25, // y + 26, // z + 46, // { + 0, // | + 48, // } + 0, // ~ +}; + +void puts(Context *ctx, int loc, const char *str) { + for (int i = 0; str[i]; i++) { + setTile(ctx, 0, loc + i, 0, charMap[static_cast(str[i])]); + } +} + +} diff --git a/src/nostalgia/core/sdl/gfx.cpp b/src/nostalgia/core/sdl/gfx.cpp index 8d2ebc9c..b2dfcfa5 100644 --- a/src/nostalgia/core/sdl/gfx.cpp +++ b/src/nostalgia/core/sdl/gfx.cpp @@ -55,8 +55,10 @@ ox::Error shutdownGfx() { return OxError(0); } -ox::Error initConsole(Context*) { - return OxError(1); +ox::Error initConsole(Context *ctx) { + constexpr auto TilesheetAddr = "/TileSheets/Charset.ng"; + constexpr auto PaletteAddr = "/Palettes/Charset.npal"; + return loadTileSheet(ctx, TileSheetSpace::Background, 0, TilesheetAddr, PaletteAddr); } SDL_Color createSDL_Color(Color nc) { @@ -154,9 +156,6 @@ void draw() { SDL_RenderPresent(renderer); } -void puts(Context*, int, const char*) { -} - void setTile(Context*, int, int, int, uint8_t) { }