Skip to content

Commit

Permalink
Add libgambatte sources to the cython extension
Browse files Browse the repository at this point in the history
  • Loading branch information
vxgmichel committed Jan 18, 2021
1 parent 4031578 commit 0a927fa
Show file tree
Hide file tree
Showing 88 changed files with 18,383 additions and 7 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,7 @@ parsec/core/gui/rc/generated_misc/
# Temporary files
*~
*#
ext/*.cpp
ext/*.cpp

# Build artefacts
*.o
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ext/input.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include "include/gambatte.h"
#include "gambatte.h"

namespace gambatte {
class GetInput : public InputGetter {
Expand Down
2 changes: 1 addition & 1 deletion ext/libgambatte.pxd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from libcpp.string cimport string

cdef extern from "include/gambatte.h" namespace "gambatte":
cdef extern from "gambatte.h" namespace "gambatte":
cdef cppclass GB:
GB() except +;
int load(string& romfile, unsigned flags);
Expand Down
25 changes: 25 additions & 0 deletions libgambatte/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--------------------------------------------------------------------------------

Copyright (C) 2007 by sinamas <sinamas at users.sourceforge.net>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License version 2 for more details.

You should have received a copy of the GNU General Public License
version 2 along with this program; if not, write to the
Free Software Foundation, Inc.,
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA

--------------------------------------------------------------------------------

The source code for the libgambatte library is directly taken from:
- [sinamas/gambatte 56e3371 ./libgambatte](https://github.com/sinamas/gambatte/tree/56e3371151b5ee86dcdcf4868324ebc6de220bc9/libgambatte)

On top of it, the following commit has been applied:
- [Fix crash for ROMs with RTC (revert logic in MemPtrs::setRambank)](https://github.com/sinamas/gambatte/pull/18/commits/cfddac6ecc28136457d44f4f80ee8fb5d0f34f5d) by [entrpntr](https://github.com/entrpntr)
53 changes: 53 additions & 0 deletions libgambatte/common/array.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/***************************************************************************
* Copyright (C) 2008 by Sindre Aamås *
* [email protected] *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License version 2 as *
* published by the Free Software Foundation. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License version 2 for more details. *
* *
* You should have received a copy of the GNU General Public License *
* version 2 along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef ARRAY_H
#define ARRAY_H

#include "defined_ptr.h"
#include "uncopyable.h"
#include <cstddef>

template<typename T>
class SimpleArray : Uncopyable {
public:
explicit SimpleArray(std::size_t size = 0) : a_(size ? new T[size] : 0) {}
~SimpleArray() { delete[] defined_ptr(a_); }
void reset(std::size_t size = 0) { delete[] defined_ptr(a_); a_ = size ? new T[size] : 0; }
T * get() const { return a_; }
operator T *() const { return a_; }

private:
T *a_;
};

template<typename T>
class Array {
public:
explicit Array(std::size_t size = 0) : a_(size), size_(size) {}
void reset(std::size_t size = 0) { a_.reset(size); size_ = size; }
std::size_t size() const { return size_; }
T * get() const { return a_; }
operator T *() const { return a_; }

private:
SimpleArray<T> a_;
std::size_t size_;
};

#endif
16 changes: 16 additions & 0 deletions libgambatte/common/defined_ptr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef DEFINED_PTR_H
#define DEFINED_PTR_H

template<class T>
inline T * defined_ptr(T *t) {
typedef char type_is_defined[sizeof *t ? 1 : -1];
(void) sizeof(type_is_defined);
return t;
}

template<class T>
inline void defined_delete(T *t) { delete defined_ptr(t); }

struct defined_deleter { template<class T> static void del(T *p) { defined_delete(p); } };

#endif
29 changes: 29 additions & 0 deletions libgambatte/common/scoped_ptr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef SCOPED_PTR_H
#define SCOPED_PTR_H

#include "transfer_ptr.h"
#include "uncopyable.h"

template<class T, class Deleter = defined_deleter>
class scoped_ptr : Uncopyable {
public:
explicit scoped_ptr(T *p = 0) : p_(p) {}
template<class U> explicit scoped_ptr(transfer_ptr<U, Deleter> p) : p_(p.release()) {}
~scoped_ptr() { Deleter::del(p_); }
T * get() const { return p_; }
void reset(T *p = 0) { Deleter::del(p_); p_ = p; }
T & operator*() const { return *p_; }
T * operator->() const { return p_; }
operator bool() const { return p_; }

template<class U>
scoped_ptr & operator=(transfer_ptr<U, Deleter> p) {
reset(p.release());
return *this;
}

private:
T *p_;
};

#endif
27 changes: 27 additions & 0 deletions libgambatte/common/transfer_ptr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef TRANSFER_PTR_H
#define TRANSFER_PTR_H

#include "defined_ptr.h"

template<class T, class Deleter = defined_deleter>
class transfer_ptr {
private:
struct released { T *p; explicit released(T *p) : p(p) {} };
public:
explicit transfer_ptr(T *p = 0) : p_(p) {}
transfer_ptr(transfer_ptr &p) : p_(p.release()) {}
transfer_ptr(released r) : p_(r.p) {}
~transfer_ptr() { Deleter::del(p_); }
T * get() const { return p_; }
T * release() { T *p = p_; p_ = 0; return p; }
operator released const () { return released(release()); }
T & operator*() const { return *p_; }
T * operator->() const { return p_; }
operator bool() const { return p_; }

private:
T *p_;
transfer_ptr & operator=(transfer_ptr const &);
};

#endif
30 changes: 30 additions & 0 deletions libgambatte/common/uncopyable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/***************************************************************************
* Copyright (C) 2009 by Sindre Aamås *
* [email protected] *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License version 2 as *
* published by the Free Software Foundation. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License version 2 for more details. *
* *
* You should have received a copy of the GNU General Public License *
* version 2 along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef UNCOPYABLE_H
#define UNCOPYABLE_H

class Uncopyable {
protected:
Uncopyable() {}
private:
Uncopyable(Uncopyable const &);
Uncopyable& operator=(Uncopyable const &);
};

#endif
Binary file removed libgambatte/libgambatte.a
Binary file not shown.
Loading

0 comments on commit 0a927fa

Please sign in to comment.