[nostalgia/core] Replace puts loc param with column and row params
This commit is contained in:
parent
5dc74e6fd7
commit
71b38b243e
@ -9,6 +9,7 @@ add_library(
|
|||||||
|
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
NostalgiaCore-GBA PUBLIC
|
NostalgiaCore-GBA PUBLIC
|
||||||
|
NostalgiaCore
|
||||||
GbaStartup
|
GbaStartup
|
||||||
OxFS
|
OxFS
|
||||||
OxStd
|
OxStd
|
||||||
|
@ -112,7 +112,11 @@ ox::Error initConsole(Context *ctx) {
|
|||||||
constexpr auto PaletteAddr = "/Palettes/Charset.npal";
|
constexpr auto PaletteAddr = "/Palettes/Charset.npal";
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
ctx = new (ox_alloca(sizeof(Context))) Context();
|
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);
|
ctx->rom = new (ox_alloca(sizeof(ox::FileSystem32))) ox::FileSystem32(fs);
|
||||||
}
|
}
|
||||||
return loadTileSheet(ctx, TileSheetSpace::Background, 0, TilesheetAddr, PaletteAddr);
|
return loadTileSheet(ctx, TileSheetSpace::Background, 0, TilesheetAddr, PaletteAddr);
|
||||||
|
@ -13,10 +13,10 @@ namespace nostalgia::core {
|
|||||||
|
|
||||||
void panic(const char *msg) {
|
void panic(const char *msg) {
|
||||||
oxIgnoreError(initConsole(nullptr));
|
oxIgnoreError(initConsole(nullptr));
|
||||||
puts(nullptr, 1 * 32 + 0, "SADNESS...");
|
puts(nullptr, 32 + 0, 1, "SADNESS...");
|
||||||
puts(nullptr, 4 * 32 + 0, "UNEXPECTED STATE:");
|
puts(nullptr, 32 + 0, 4, "UNEXPECTED STATE:");
|
||||||
puts(nullptr, 6 * 32 + 2, msg);
|
puts(nullptr, 32 + 2, 6, msg);
|
||||||
puts(nullptr, 10 * 32 + 0, "PLEASE RESTART THE SYSTEM");
|
puts(nullptr, 32 + 0, 10, "PLEASE RESTART THE SYSTEM");
|
||||||
// TODO: properly end program execution, this wastes power
|
// TODO: properly end program execution, this wastes power
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
|
@ -141,9 +141,9 @@ char charMap[128] = {
|
|||||||
0, // ~
|
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++) {
|
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])]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ ox::Error model(T *io, NostalgiaGraphic *ng) {
|
|||||||
|
|
||||||
ox::Error loadTileSheet(Context *ctx, ox::FileAddress file);
|
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);
|
void setTile(Context *ctx, int layer, int column, int row, uint8_t tile);
|
||||||
|
|
||||||
|
@ -21,7 +21,8 @@ static SDL_Window *window = nullptr;
|
|||||||
static SDL_Renderer *renderer = nullptr;
|
static SDL_Renderer *renderer = nullptr;
|
||||||
|
|
||||||
static std::array<SDL_Texture*, 4> bgTextures;
|
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) {
|
[[nodiscard]] static ox::ValErr<ox::Vector<uint8_t>> readFile(Context *ctx, const ox::FileAddress &file) {
|
||||||
auto [stat, err] = ctx->rom->stat(file);
|
auto [stat, err] = ctx->rom->stat(file);
|
||||||
@ -124,39 +125,42 @@ ox::Error loadTileSheet(Context *ctx,
|
|||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawBackground(SDL_Texture *tex) {
|
void drawBackground(const TileMap &tm, 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;
|
|
||||||
if (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) {
|
for (auto t : m) {
|
||||||
src.y = t * 8;
|
src.y = t * 8;
|
||||||
SDL_RenderCopy(renderer, tex, &src, &dst);
|
SDL_RenderCopy(renderer, tex, &src, &dst);
|
||||||
dst.y += DstSize;
|
dst.x += DstSize;
|
||||||
}
|
}
|
||||||
dst.x += DstSize;
|
dst.x = 0;
|
||||||
dst.y = 0;
|
dst.y += DstSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw() {
|
void draw() {
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
for (auto tex : bgTextures) {
|
for (std::size_t i = 0; i < bgTileMaps.size(); i++) {
|
||||||
drawBackground(tex);
|
auto tex = bgTextures[i];
|
||||||
|
auto &tm = bgTileMaps[i];
|
||||||
|
drawBackground(tm, tex);
|
||||||
}
|
}
|
||||||
SDL_RenderPresent(renderer);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,4 @@
|
|||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
typedef ox::FileStore32::InodeId_t InodeId_t;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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"));
|
//oxReturnError(zone.init(&ctx, Bounds{0, 0, 40, 40}, "/TileSheets/Charset.ng", "/Palettes/Charset.npal"));
|
||||||
//zone.draw(&ctx);
|
//zone.draw(&ctx);
|
||||||
oxReturnError(initConsole(&ctx));
|
oxReturnError(initConsole(&ctx));
|
||||||
puts(&ctx, 9 * 32 + 10, "DOPENESS!!!");
|
puts(&ctx, 10, 9, "DOPENESS!!!");
|
||||||
oxReturnError(run());
|
oxReturnError(run());
|
||||||
oxReturnError(shutdownGfx());
|
oxReturnError(shutdownGfx());
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user