2012-09-08 19:02:33 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2007 by Sindre Aamås *
|
|
|
|
* aamas@stud.ntnu.no *
|
|
|
|
* *
|
|
|
|
* 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., *
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
***************************************************************************/
|
|
|
|
#ifndef GAMBATTE_H
|
|
|
|
#define GAMBATTE_H
|
|
|
|
|
|
|
|
#include "inputgetter.h"
|
|
|
|
#include "gbint.h"
|
|
|
|
#include <string>
|
2012-09-09 18:47:00 +00:00
|
|
|
#include <sstream>
|
2013-11-24 17:32:46 +00:00
|
|
|
#include <cstdint>
|
2014-05-10 04:22:12 +00:00
|
|
|
#include "newstate.h"
|
2012-09-08 19:02:33 +00:00
|
|
|
|
|
|
|
namespace gambatte {
|
|
|
|
enum { BG_PALETTE = 0, SP1_PALETTE = 1, SP2_PALETTE = 2 };
|
|
|
|
|
|
|
|
class GB {
|
|
|
|
public:
|
|
|
|
GB();
|
|
|
|
~GB();
|
|
|
|
|
|
|
|
enum LoadFlag {
|
|
|
|
FORCE_DMG = 1, /**< Treat the ROM as not having CGB support regardless of what its header advertises. */
|
|
|
|
GBA_CGB = 2, /**< Use GBA intial CPU register values when in CGB mode. */
|
|
|
|
MULTICART_COMPAT = 4 /**< Use heuristics to detect and support some multicart MBCs disguised as MBC1. */
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Load ROM image.
|
|
|
|
*
|
|
|
|
* @param romfile Path to rom image file. Typically a .gbc, .gb, or .zip-file (if zip-support is compiled in).
|
|
|
|
* @param flags ORed combination of LoadFlags.
|
|
|
|
* @return 0 on success, negative value on failure.
|
|
|
|
*/
|
2013-11-24 17:32:46 +00:00
|
|
|
int load(const char *romfiledata, unsigned romfilelength, std::uint32_t now, unsigned flags = 0);
|
2012-09-08 19:02:33 +00:00
|
|
|
|
|
|
|
/** Emulates until at least 'samples' stereo sound samples are produced in the supplied buffer,
|
|
|
|
* or until a video frame has been drawn.
|
|
|
|
*
|
|
|
|
* There are 35112 stereo sound samples in a video frame.
|
|
|
|
* May run for up to 2064 stereo samples too long.
|
|
|
|
* A stereo sample consists of two native endian 2s complement 16-bit PCM samples,
|
|
|
|
* with the left sample preceding the right one. Usually casting soundBuf to/from
|
|
|
|
* short* is OK and recommended. The reason for not using a short* in the interface
|
|
|
|
* is to avoid implementation-defined behaviour without compromising performance.
|
|
|
|
*
|
|
|
|
* Returns early when a new video frame has finished drawing in the video buffer,
|
|
|
|
* such that the caller may update the video output before the frame is overwritten.
|
|
|
|
* The return value indicates whether a new video frame has been drawn, and the
|
|
|
|
* exact time (in number of samples) at which it was drawn.
|
|
|
|
*
|
|
|
|
* @param soundBuf buffer with space >= samples + 2064
|
|
|
|
* @param samples in: number of stereo samples to produce, out: actual number of samples produced
|
|
|
|
* @return sample number at which the video frame was produced. -1 means no frame was produced.
|
|
|
|
*/
|
2014-05-03 03:05:34 +00:00
|
|
|
long runFor(gambatte::uint_least32_t *soundBuf, unsigned &samples);
|
|
|
|
|
|
|
|
void blitTo(gambatte::uint_least32_t *videoBuf, int pitch);
|
|
|
|
|
2012-09-08 19:02:33 +00:00
|
|
|
/** Reset to initial state.
|
|
|
|
* Equivalent to reloading a ROM image, or turning a Game Boy Color off and on again.
|
|
|
|
*/
|
2013-11-24 17:32:46 +00:00
|
|
|
void reset(std::uint32_t now);
|
2012-09-08 19:02:33 +00:00
|
|
|
|
|
|
|
/** @param palNum 0 <= palNum < 3. One of BG_PALETTE, SP1_PALETTE and SP2_PALETTE.
|
|
|
|
* @param colorNum 0 <= colorNum < 4
|
|
|
|
*/
|
|
|
|
void setDmgPaletteColor(unsigned palNum, unsigned colorNum, unsigned rgb32);
|
|
|
|
|
2012-11-18 17:02:55 +00:00
|
|
|
void setCgbPalette(unsigned *lut);
|
|
|
|
|
2012-09-08 19:02:33 +00:00
|
|
|
/** Sets the callback used for getting input state. */
|
|
|
|
void setInputGetter(InputGetter *getInput);
|
|
|
|
|
2012-10-14 15:10:33 +00:00
|
|
|
void setReadCallback(void (*callback)(unsigned));
|
|
|
|
void setWriteCallback(void (*callback)(unsigned));
|
2013-11-13 17:08:52 +00:00
|
|
|
void setExecCallback(void (*callback)(unsigned));
|
2012-11-02 19:44:31 +00:00
|
|
|
void setTraceCallback(void (*callback)(void *));
|
2012-11-05 20:15:53 +00:00
|
|
|
void setScanlineCallback(void (*callback)(), int sl);
|
2013-11-24 17:32:46 +00:00
|
|
|
void setRTCCallback(std::uint32_t (*callback)());
|
2012-10-14 15:10:33 +00:00
|
|
|
|
2012-09-08 19:02:33 +00:00
|
|
|
/** Returns true if the currently loaded ROM image is treated as having CGB support. */
|
|
|
|
bool isCgb() const;
|
|
|
|
|
|
|
|
/** Returns true if a ROM image is loaded. */
|
|
|
|
bool isLoaded() const;
|
|
|
|
|
2012-09-10 23:40:53 +00:00
|
|
|
/** Writes persistent cartridge data to disk. NOT Done implicitly on ROM close. */
|
|
|
|
void loadSavedata(const char *data);
|
|
|
|
int saveSavedataLength();
|
|
|
|
void saveSavedata(char *dest);
|
2012-09-08 19:02:33 +00:00
|
|
|
|
2012-09-11 19:05:44 +00:00
|
|
|
// 0 = vram, 1 = rom, 2 = wram, 3 = cartram, 4 = oam, 5 = hram
|
2012-09-11 15:28:38 +00:00
|
|
|
bool getMemoryArea(int which, unsigned char **data, int *length);
|
2012-09-08 19:02:33 +00:00
|
|
|
|
|
|
|
/** Saves emulator state to the file given by 'filepath'.
|
|
|
|
*
|
|
|
|
* @param videoBuf 160x144 RGB32 (native endian) video frame buffer or 0. Used for saving a thumbnail.
|
|
|
|
* @param pitch distance in number of pixels (not bytes) from the start of one line to the next in videoBuf.
|
|
|
|
* @return success
|
|
|
|
*/
|
2014-05-03 03:05:34 +00:00
|
|
|
bool saveState(std::ostream &file);
|
2012-09-08 19:02:33 +00:00
|
|
|
|
|
|
|
/** Loads emulator state from the file given by 'filepath'.
|
|
|
|
* @return success
|
|
|
|
*/
|
2012-09-09 18:47:00 +00:00
|
|
|
bool loadState(std::istream &file);
|
2012-09-08 19:02:33 +00:00
|
|
|
|
|
|
|
/** ROM header title of currently loaded ROM image. */
|
|
|
|
const std::string romTitle() const;
|
2012-09-13 21:03:34 +00:00
|
|
|
|
|
|
|
unsigned char ExternalRead(unsigned short addr);
|
|
|
|
void ExternalWrite(unsigned short addr, unsigned char val);
|
|
|
|
|
2012-12-29 01:25:06 +00:00
|
|
|
int LinkStatus(int which);
|
|
|
|
|
2013-11-11 18:05:29 +00:00
|
|
|
void GetRegs(int *dest);
|
|
|
|
|
2014-05-10 04:22:12 +00:00
|
|
|
void SaveS(NewState *ns);
|
|
|
|
void LoadS(NewState *ns);
|
|
|
|
|
2012-09-08 19:02:33 +00:00
|
|
|
private:
|
|
|
|
struct Priv;
|
|
|
|
Priv *const p_;
|
|
|
|
|
|
|
|
GB(const GB &);
|
|
|
|
GB & operator=(const GB &);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|