Started on common and core packages.

This commit is contained in:
2016-03-26 15:49:05 -05:00
parent 2434a43cec
commit 807d0397a1
39 changed files with 1849 additions and 0 deletions

35
src/CMakeLists.txt Normal file
View File

@ -0,0 +1,35 @@
cmake_minimum_required(VERSION 2.8.8)
#setup libraries
if(WOMBAT_BUILD_TYPE STREQUAL "Native")
find_package(SDL REQUIRED)
include_directories(${SDL_INCLUDE_DIR})
set(LIBS ${LIBS} ${SDL_LIBRARY})
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
set(LIBS ${LIBS} ${OPENGL_LIBRARY})
find_package(SDL_IMAGE REQUIRED)
include_directories(${SDL_IMAGE_INCLUDE_DIR})
set(LIBS ${LIBS} ${SDL_IMAGE_LIBRARY})
find_package(SDL_ttf REQUIRED)
include_directories(${SDL_TTF_INCLUDE_DIR})
set(LIBS ${LIBS} ${SDL_TTF_LIBRARY})
elseif(WOMBAT_BUILD_TYPE STREQUAL "GBA")
endif()
#project packages
include_directories(".")
add_subdirectory(core)
set(OBJS ${OBJS} $<TARGET_OBJECTS:NostalgiaCommon>)
add_subdirectory(common)
set(OBJS ${OBJS} $<TARGET_OBJECTS:NostalgiaCommon>)
add_subdirectory(player)

2
src/Makefile Normal file
View File

@ -0,0 +1,2 @@
make:
make -j -C ../ ${ARGS}

19
src/common/CMakeLists.txt Normal file
View File

@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 2.8.8)
add_library(
NostalgiaCommon OBJECT
bounds.cpp
memops.cpp
point.cpp
)
#install(TARGETS NostalgiaCommon DESTINATION lib)
install(
FILES
bounds.hpp
common.hpp
memops.hpp
point.hpp
DESTINATION
include/wombat/common
)

41
src/common/bounds.cpp Normal file
View File

@ -0,0 +1,41 @@
/*
* Copyright 2016 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 "bounds.hpp"
namespace wombat {
namespace common {
Bounds::Bounds() {
}
bool Bounds::intersects(Bounds o) const {
return o.x2() >= X && x2() >= o.X && o.y2() >= Y && y2() >= o.Y;
}
bool Bounds::contains(int x, int y) const {
return x >= X && y >= Y && x <= x2() && y <= y2();
}
int Bounds::x2() const {
return X + Width;
}
int Bounds::y2() const {
return Y + Height;
}
Point Bounds::pt1() {
return Point(X, Y);
}
Point Bounds::pt2() {
return Point(x2(), y2());
}
}
}

44
src/common/bounds.hpp Normal file
View File

@ -0,0 +1,44 @@
/*
* Copyright 2016 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/.
*/
#ifndef WOMBAT_COMMON_BOUNDS_HPP
#define WOMBAT_COMMON_BOUNDS_HPP
#include "point.hpp"
namespace wombat {
namespace common {
class Bounds {
public:
int X = 0;
int Y = 0;
int Width = 0;
int Height = 0;
/**
* Constructor
*/
Bounds();
bool intersects(Bounds other) const;
bool contains(int x, int y) const;
int x2() const;
int y2() const;
Point pt1();
Point pt2();
};
}
}
#endif

15
src/common/common.hpp Normal file
View File

@ -0,0 +1,15 @@
/*
* Copyright 2016 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/.
*/
#ifndef WOMBAT_COMMON_COMMON_HPP
#define WOMBAT_COMMON_COMMON_HPP
#include "bounds.hpp"
#include "flyweight.hpp"
#include "point.hpp"
#endif

29
src/common/memops.cpp Normal file
View File

@ -0,0 +1,29 @@
/*
* Copyright 2016 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 "memops.hpp"
namespace nostalgia {
namespace common {
void memcpy(void *src, void *dest, int size) {
char *srcBuf = (char*) src;
char *dstBuf = (char*) dest;
for (int i = 0; i < size; i++) {
dstBuf[i] = (char) srcBuf[i];
}
}
void memset(void *ptr, char val, int size) {
char *buf = (char*) ptr;
for (int i = 0; i < size; i++) {
buf[i] = val;
}
}
}
}

21
src/common/memops.hpp Normal file
View File

@ -0,0 +1,21 @@
/*
* Copyright 2016 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/.
*/
#ifndef MEMPHIS_MEMOPS_HPP
#define MEMPHIS_MEMOPS_HPP
namespace nostalgia {
namespace common {
void memcpy(void *src, void *dest, int size);
void memset(void *ptr, char val, int size);
}
}
#endif

125
src/common/point.cpp Normal file
View File

@ -0,0 +1,125 @@
/*
* Copyright 2016 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 "point.hpp"
namespace wombat {
namespace common {
Point::Point() {
}
Point::Point(int x, int y) {
X = x;
Y = y;
}
Point Point::operator+(common::Point p) const {
p.X += X;
p.Y += Y;
return p;
}
Point Point::operator-(common::Point p) const {
auto out = *this;
out.X -= p.X;
out.Y -= p.Y;
return out;
}
Point Point::operator*(common::Point p) const {
p.X *= X;
p.Y *= Y;
return p;
}
Point Point::operator/(common::Point p) const {
auto out = *this;
out.X /= p.X;
out.Y /= p.Y;
return out;
}
Point Point::operator+=(common::Point p) {
X += p.X;
Y += p.Y;
return *this;
}
Point Point::operator-=(common::Point p) {
X -= p.X;
Y -= p.Y;
return *this;
}
Point Point::operator*=(common::Point p) {
X *= p.X;
Y *= p.Y;
return *this;
}
Point Point::operator/=(common::Point p) {
X /= p.X;
Y /= p.Y;
return *this;
}
Point Point::operator+(int i) const {
auto out = *this;
out.X += i;
out.Y += i;
return out;
}
Point Point::operator-(int i) const {
auto out = *this;
out.X -= i;
out.Y -= i;
return out;
}
Point Point::operator*(int i) const {
auto out = *this;
out.X *= i;
out.Y *= i;
return out;
}
Point Point::operator/(int i) const {
auto out = *this;
out.X /= i;
out.Y /= i;
return out;
}
Point Point::operator+=(int i) {
X += i;
Y += i;
return *this;
}
Point Point::operator-=(int i) {
X -= i;
Y -= i;
return *this;
}
Point Point::operator*=(int i) {
X *= i;
Y *= i;
return *this;
}
Point Point::operator/=(int i) {
X /= i;
Y /= i;
return *this;
}
}
}

62
src/common/point.hpp Normal file
View File

@ -0,0 +1,62 @@
/*
* Copyright 2016 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/.
*/
#ifndef WOMBAT_COMMON_POINT_HPP
#define WOMBAT_COMMON_POINT_HPP
namespace wombat {
namespace common {
class Point {
public:
int X = 0;
int Y = 0;
Point();
Point(int x, int y);
Point operator+(common::Point p) const;
Point operator-(common::Point p) const;
Point operator*(common::Point p) const;
Point operator/(common::Point p) const;
Point operator+=(common::Point p);
Point operator-=(common::Point p);
Point operator*=(common::Point p);
Point operator/=(common::Point p);
Point operator+(int i) const;
Point operator-(int i) const;
Point operator*(int i) const;
Point operator/(int i) const;
Point operator+=(int i);
Point operator-=(int i);
Point operator*=(int i);
Point operator/=(int i);
};
}
}
#endif

19
src/core/CMakeLists.txt Normal file
View File

@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 2.8.8)
if(WOMBAT_BUILD_TYPE STREQUAL "GBA")
set(
CPP
gba/core.cpp
gba/gfx.cpp
)
include_directories("gba")
elseif(WOMBAT_BUILD_TYPE STREQUAL "Native")
endif()
add_library(NostalgiaCore OBJECT ${CPP})
install(
FILES
DESTINATION
include/nostalgia/core
)

19
src/core/gba/core.cpp Normal file
View File

@ -0,0 +1,19 @@
/*
* Copyright 2016 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 "../types.hpp"
#include "registers.hpp"
namespace nostalgia {
namespace core {
int init() {
return 0;
}
}
}

8
src/core/gba/gfx.cpp Normal file
View File

@ -0,0 +1,8 @@
/*
* Copyright 2016 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 "registers.hpp"

View File

@ -0,0 +1,13 @@
/*
* Copyright 2016 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/.
*/
#ifndef NOSTALGIA_CORE_GBA_REGISTERS_HPP
#define NOSTALGIA_CORE_GBA_REGISTERS_HPP
#define REG_DISPCNT *((volatile unsigned int*) 0x04000000)
#endif

35
src/core/types.hpp Normal file
View File

@ -0,0 +1,35 @@
/*
* Copyright 2016 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/.
*/
#ifndef NOSTALGIA_CORE_TYPES_HPP
#define NOSTALGIA_CORE_TYPES_HPP
#include <cstdint>
namespace nostalgia {
namespace core {
typedef char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short uint16_t;
typedef int int32_t;
typedef unsigned int uint32_t;
typedef unsigned uint_t;
typedef long long int64_t;
typedef unsigned long long uint64_t;
#ifdef _LP64
typedef uint64_t size_t;
#elif _LP32
typedef uint32_t size_t;
#endif
}
}
#endif

19
src/player/CMakeLists.txt Normal file
View File

@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 2.8.8)
project(nostalgia)
set(WOMBAT_BUILD_TYPE "Native" CACHE STRING "The type of build to produce(Native/GBA)")
add_executable(
nostalgia
main.cpp
${OBJS}
)
#target_link_libraries(wombat ${LIBS})
set_target_properties(nostalgia
PROPERTIES
LINK_FLAGS ${LINKER_FLAGS}
COMPILER_FLAGS "-mthumb -mthumb-interwork"
)
objcopy_file(nostalgia)

11
src/player/main.cpp Normal file
View File

@ -0,0 +1,11 @@
/*
* Copyright 2016 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/.
*/
int main() {
return 0;
}