Add missing nostalgia directory level in src tree

This commit is contained in:
2017-05-12 17:55:18 -05:00
parent 1b9f8f40f4
commit bfc87b50b1
43 changed files with 22 additions and 19 deletions

View File

@@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 2.8.11)
if(WOMBAT_BUILD_TYPE STREQUAL "GBA")
enable_language(C ASM)
set(
CPP
gba/gfx.cpp
gba/media.cpp
)
elseif(WOMBAT_BUILD_TYPE STREQUAL "Native")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(
CPP
qt/gfx.cpp
)
endif()
add_library(
NostalgiaCore
${CPP}
core.cpp
)
install(
FILES
core.hpp
gfx.hpp
gba/gba.hpp
DESTINATION
include/nostalgia/core
)

View File

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

View File

@@ -0,0 +1,18 @@
/*
* 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/.
*/
#pragma once
#include "gfx.hpp"
namespace nostalgia {
namespace core {
ox::Error init();
}
}

View File

@@ -0,0 +1,48 @@
/*
* 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/.
*/
#pragma once
#include <ox/std/types.hpp>
/////////////////////////////////////////////////////////////////
// I/O Registers
#define REG_DISPCNT *((volatile uint32_t*) 0x04000000)
/////////////////////////////////////////////////////////////////
// background registers
// background control registers
#define REG_BG0CNT *((volatile uint32_t*) 0x04000008)
#define REG_BG1CNT *((volatile uint32_t*) 0x0400000a)
#define REG_BG2CNT *((volatile uint32_t*) 0x0400000c)
#define REG_BG3CNT *((volatile uint32_t*) 0x0400000e)
// background horizontal scrolling registers
#define REG_BG0HOFS *((volatile uint32_t*) 0x04000010)
#define REG_BG1HOFS *((volatile uint32_t*) 0x04000014)
#define REG_BG2HOFS *((volatile uint32_t*) 0x04000018)
#define REG_BG3HOFS *((volatile uint32_t*) 0x0400001c)
// background vertical scrolling registers
#define REG_BG0VOFS *((volatile uint32_t*) 0x04000012)
#define REG_BG1VOFS *((volatile uint32_t*) 0x04000016)
#define REG_BG2VOFS *((volatile uint32_t*) 0x0400001a)
#define REG_BG3VOFS *((volatile uint32_t*) 0x0400001e)
/////////////////////////////////////////////////////////////////
// Memory Addresses
#define MEM_PALLETE_BG ((uint16_t*) 0x05000000)
#define MEM_PALLETE_SPRITE ((uint16_t*) 0x05000200)
typedef uint16_t BgMapTile[1024];
#define MEM_BG_MAP ((BgMapTile*) 0x06000000)
#define MEM_ROM *((uint8_t*) 0x08000000)

View File

@@ -0,0 +1,36 @@
/*
* 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/.
*/
#pragma once
#include <ox/std/types.hpp>
namespace nostalgia {
namespace core {
typedef struct { uint32_t data[8]; } __attribute__((aligned(4))) Tile, Tile4;
// d-tile: double-sized tile (8bpp)
typedef struct { uint32_t data[16]; } __attribute__((aligned(4))) Tile8;
// tile block: 32x16 tiles, 16x16 d-tiles
typedef uint16_t Palette[256];
typedef Tile CharBlock[512];
typedef Tile8 CharBlock8[256];
struct __attribute__((packed)) GbaImageDataHeader {
uint8_t bpp;
uint16_t tileCount;
};
struct __attribute__((packed)) GbaImageData {
GbaImageDataHeader header;
Palette __attribute__((packed)) pal;
uint8_t tiles[1];
};
}
}

View File

@@ -0,0 +1,161 @@
/*
* 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>
#include <ox/std/std.hpp>
#include "addresses.hpp"
#include "media.hpp"
#include "gba.hpp"
#include "../gfx.hpp"
namespace nostalgia {
namespace core {
using namespace ox::fs;
#define TILE_ADDR ((CharBlock*) 0x06000000)
#define TILE8_ADDR ((CharBlock8*) 0x06000000)
// 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,
38, // !
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
37, // ,
0,
0,
0,
27, // 0
28, // 1
29, // 2
30, // 3
31, // 4
32, // 5
33, // 6
34, // 7
35, // 8
36, // 9
0,
0,
0,
0,
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
};
ox::Error initGfx() {
/* Sprite Mode ----\ */
/* ---\| */
/* Background 0 -\|| */
/* Objects -----\||| */
/* |||| */
REG_DISPCNT = 0x1100;
return 0;
}
void initConsole() {
auto charsetInode = 101;
auto fs = (FileStore32*) findMedia();
GbaImageDataHeader imgData;
fs->read(101, 0, sizeof(imgData), &imgData, nullptr);
REG_BG0CNT = (28 << 8) | 1;
if (fs) {
// load palette
fs->read(charsetInode, sizeof(GbaImageDataHeader),
512, (uint16_t*) &MEM_PALLETE_BG[0], nullptr);
if (imgData.bpp == 4) {
fs->read(charsetInode, __builtin_offsetof(GbaImageData, tiles),
sizeof(Tile) * imgData.tileCount, (uint16_t*) &TILE_ADDR[0][1], nullptr);
} else {
REG_BG0CNT |= (1 << 7); // set to use 8 bits per pixel
fs->read(charsetInode, __builtin_offsetof(GbaImageData, tiles),
sizeof(Tile8) * imgData.tileCount, (uint16_t*) &TILE8_ADDR[0][1], nullptr);
}
}
}
void puts(int loc, const char *str) {
for (int i = 0; str[i]; i++) {
MEM_BG_MAP[28][loc + i] = charMap[(int) str[i]];
}
}
}
}

View File

@@ -0,0 +1,36 @@
/*
* 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>
#include <ox/std/std.hpp>
#include "addresses.hpp"
#include "media.hpp"
namespace nostalgia {
namespace core {
uint8_t *findMedia() {
// put the header in the wrong order to prevent mistaking this code for the
// media section
const static auto headerP2 = "_HEADER_________";
const static auto headerP1 = "NOSTALGIA_MEDIA";
const static auto headerP1Len = 15;
const static auto headerP2Len = 16;
const static auto headerLen = headerP1Len + headerP2Len + 1;
for (auto current = &MEM_ROM; current < ((uint8_t*) 0x0a000000); current += headerLen) {
if (ox_memcmp(current, headerP1, headerP1Len) == 0 &&
ox_memcmp(current + headerP1Len, headerP2, headerP2Len) == 0) {
return current + headerLen;
}
}
return 0;
}
}
}

View File

@@ -0,0 +1,19 @@
/*
* 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/.
*/
#pragma once
#include <ox/std/types.hpp>
namespace nostalgia {
namespace core {
uint8_t *findMedia();
}
}

View File

@@ -0,0 +1,22 @@
/*
* 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/.
*/
#pragma once
#include <ox/std/types.hpp>
namespace nostalgia {
namespace core {
ox::Error initGfx();
void initConsole();
void puts(int loc, const char *str);
}
}

View File

@@ -0,0 +1,25 @@
/*
* 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/std/std.hpp>
namespace nostalgia {
namespace core {
ox::Error initGfx() {
return 0;
}
void initConsole() {
}
void puts(int loc, const char *str) {
}
}
}