Skip to content

Commit

Permalink
I'm not sure where to start with this one... It wasn't hooked up to t…
Browse files Browse the repository at this point in the history
…he frontend at all; the C# side enum doesn't have this flag. It can already be done with a different option in the frontend ("VBA Vivid".) It was stored in savestates, despite having no effect on emulation. Even with some other hypothetical front end, it could only be set at initial load time, despite the fact that our existing palette manipulation can be edited at any time, of course...
  • Loading branch information
nattthebear committed Feb 3, 2018
1 parent 2cc0922 commit f185f71
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 29 deletions.
1 change: 0 additions & 1 deletion libgambatte/include/gambatte.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class GB {
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. */
TRUE_COLOR = 8 /**< Use GBP color conversion instead of GBC-screen approximation */
};

/** Load ROM image.
Expand Down
4 changes: 2 additions & 2 deletions libgambatte/src/gambatte.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void GB::reset(const std::uint32_t now) {

SaveState state;
p_->cpu.setStatePtrs(state);
setInitState(state, !(p_->loadflags & FORCE_DMG), p_->loadflags & GBA_CGB, p_->loadflags & TRUE_COLOR, now);
setInitState(state, !(p_->loadflags & FORCE_DMG), p_->loadflags & GBA_CGB, now);
p_->cpu.loadState(state);
if (length > 0)
{
Expand Down Expand Up @@ -150,7 +150,7 @@ int GB::load(const char *romfiledata, unsigned romfilelength, const std::uint32_
SaveState state;
p_->cpu.setStatePtrs(state);
p_->loadflags = flags;
setInitState(state, !(flags & FORCE_DMG), flags & GBA_CGB, flags & TRUE_COLOR, now);
setInitState(state, !(flags & FORCE_DMG), flags & GBA_CGB, now);
p_->cpu.loadState(state);
//p_->cpu.loadSavedata();
}
Expand Down
3 changes: 1 addition & 2 deletions libgambatte/src/initstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ static void setInitialDmgIoamhram(unsigned char *const ioamhram) {

} // anon namespace

void gambatte::setInitState(SaveState &state, const bool cgb, const bool gbaCgbMode, const bool trueColors, const std::uint32_t now) {
void gambatte::setInitState(SaveState &state, const bool cgb, const bool gbaCgbMode, const std::uint32_t now) {
static const unsigned char cgbObjpDump[0x40] = {
0x00, 0x00, 0xF2, 0xAB,
0x61, 0xC2, 0xD9, 0xBA,
Expand Down Expand Up @@ -1262,7 +1262,6 @@ void gambatte::setInitState(SaveState &state, const bool cgb, const bool gbaCgbM
state.ppu.oldWy = state.mem.ioamhram.get()[0x14A];
state.ppu.pendingLcdstatIrq = false;
state.ppu.isCgb = cgb;
state.ppu.trueColors = !trueColors;


state.spu.cycleCounter = 0; // spu.cycleCounter >> 12 & 7 represents the frame sequencer position.
Expand Down
2 changes: 1 addition & 1 deletion libgambatte/src/initstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <cstdint>

namespace gambatte {
void setInitState(struct SaveState &state, bool cgb, bool gbaCgbMode, bool trueColors, std::uint32_t now);
void setInitState(struct SaveState &state, bool cgb, bool gbaCgbMode, std::uint32_t now);
}

#endif
3 changes: 1 addition & 2 deletions libgambatte/src/savestate.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct SaveState {
void set(T *ptr, const unsigned long sz) { this->ptr = ptr; this->sz = sz; }

friend class SaverList;
friend void setInitState(SaveState &, bool, bool, bool, std::uint32_t);
friend void setInitState(SaveState &, bool, bool, std::uint32_t);
};

struct CPU {
Expand Down Expand Up @@ -118,7 +118,6 @@ struct SaveState {
bool weMaster;
bool pendingLcdstatIrq;
bool isCgb;
bool trueColors;
} ppu;

struct SPU {
Expand Down
23 changes: 10 additions & 13 deletions libgambatte/src/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,11 @@ void LCD::setCgbPalette(unsigned *lut) {
refreshPalettes();
}

unsigned long LCD::gbcToRgb32(const unsigned bgr15, bool trueColor) {
unsigned long LCD::gbcToRgb32(const unsigned bgr15) {
unsigned long const r = bgr15 & 0x1F;
unsigned long const g = bgr15 >> 5 & 0x1F;
unsigned long const b = bgr15 >> 10 & 0x1F;

if (trueColor)
return (r << 19) | (g << 11) | (b << 3);

return cgbColorsRgb32[bgr15 & 0x7FFF];
}

Expand Down Expand Up @@ -151,8 +148,8 @@ void LCD::loadState(const SaveState &state, const unsigned char *const oamram) {
void LCD::refreshPalettes() {
if (ppu.cgb()) {
for (unsigned i = 0; i < 8 * 8; i += 2) {
ppu.bgPalette()[i >> 1] = gbcToRgb32( bgpData[i] | bgpData[i + 1] << 8, isTrueColors());
ppu.spPalette()[i >> 1] = gbcToRgb32(objpData[i] | objpData[i + 1] << 8, isTrueColors());
ppu.bgPalette()[i >> 1] = gbcToRgb32( bgpData[i] | bgpData[i + 1] << 8);
ppu.spPalette()[i >> 1] = gbcToRgb32(objpData[i] | objpData[i + 1] << 8);
}
} else {
setDmgPalette(ppu.bgPalette() , dmgColorsRgb32 , bgpData[0]);
Expand All @@ -163,10 +160,10 @@ void LCD::refreshPalettes() {

void LCD::copyCgbPalettesToDmg() {
for (unsigned i = 0; i < 4; i++) {
dmgColorsRgb32[i] = gbcToRgb32(bgpData[i * 2] | bgpData[i * 2 + 1] << 8, isTrueColors());
dmgColorsRgb32[i] = gbcToRgb32(bgpData[i * 2] | bgpData[i * 2 + 1] << 8);
}
for (unsigned i = 0; i < 8; i++) {
dmgColorsRgb32[i + 4] = gbcToRgb32(objpData[i * 2] | objpData[i * 2 + 1] << 8, isTrueColors());
dmgColorsRgb32[i + 4] = gbcToRgb32(objpData[i * 2] | objpData[i * 2 + 1] << 8);
}
}

Expand Down Expand Up @@ -205,7 +202,7 @@ void LCD::updateScreen(const bool blanklcd, const unsigned long cycleCounter) {
update(cycleCounter);

if (blanklcd && ppu.frameBuf().fb()) {
const unsigned long color = ppu.cgb() ? gbcToRgb32(0xFFFF, isTrueColors()) : dmgColorsRgb32[0];
const unsigned long color = ppu.cgb() ? gbcToRgb32(0xFFFF) : dmgColorsRgb32[0];
clear(ppu.frameBuf().fb(), color, ppu.frameBuf().pitch());
}
}
Expand Down Expand Up @@ -319,23 +316,23 @@ bool LCD::cgbpAccessible(const unsigned long cycleCounter) {
}

void LCD::doCgbColorChange(unsigned char *const pdata,
unsigned long *const palette, unsigned index, const unsigned data, bool trueColor) {
unsigned long *const palette, unsigned index, const unsigned data) {
pdata[index] = data;
index >>= 1;
palette[index] = gbcToRgb32(pdata[index << 1] | pdata[(index << 1) + 1] << 8, trueColor);
palette[index] = gbcToRgb32(pdata[index << 1] | pdata[(index << 1) + 1] << 8);
}

void LCD::doCgbBgColorChange(unsigned index, const unsigned data, const unsigned long cycleCounter) {
if (cgbpAccessible(cycleCounter)) {
update(cycleCounter);
doCgbColorChange(bgpData, ppu.bgPalette(), index, data, isTrueColors());
doCgbColorChange(bgpData, ppu.bgPalette(), index, data);
}
}

void LCD::doCgbSpColorChange(unsigned index, const unsigned data, const unsigned long cycleCounter) {
if (cgbpAccessible(cycleCounter)) {
update(cycleCounter);
doCgbColorChange(objpData, ppu.spPalette(), index, data, isTrueColors());
doCgbColorChange(objpData, ppu.spPalette(), index, data);
}
}

Expand Down
5 changes: 2 additions & 3 deletions libgambatte/src/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ class LCD {
static void setDmgPalette(unsigned long *palette, const unsigned long *dmgColors, unsigned data);
void setDmgPaletteColor(unsigned index, unsigned long rgb32);

unsigned long gbcToRgb32(const unsigned bgr15, bool trueColor);
void doCgbColorChange(unsigned char *const pdata, unsigned long *const palette, unsigned index, const unsigned data, bool trueColor);
unsigned long gbcToRgb32(const unsigned bgr15);
void doCgbColorChange(unsigned char *const pdata, unsigned long *const palette, unsigned index, const unsigned data);

void refreshPalettes();
void setDBuffer();
Expand Down Expand Up @@ -270,7 +270,6 @@ class LCD {

bool isCgb() const { return ppu.cgb(); }
bool isDoubleSpeed() const { return ppu.lyCounter().isDoubleSpeed(); }
bool isTrueColors() const { return ppu.trueColors(); }

unsigned long *bgPalette() { return ppu.bgPalette(); }
unsigned long *spPalette() { return ppu.spPalette(); }
Expand Down
2 changes: 0 additions & 2 deletions libgambatte/src/video/ppu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,6 @@ void PPU::loadState(const SaveState &ss, const unsigned char *const oamram) {
p_.winDrawState = ss.ppu.winDrawState & (WIN_DRAW_START | WIN_DRAW_STARTED);
p_.lastM0Time = p_.now - ss.ppu.lastM0Time;
p_.cgb = ss.ppu.isCgb;
p_.trueColors = ss.ppu.trueColors;
loadSpriteList(p_, ss);

if (m3loopState && videoCycles < 144 * 456L && p_.xpos < 168
Expand Down Expand Up @@ -1804,7 +1803,6 @@ SYNCFUNC(PPU)
NSS(p_.endx);

NSS(p_.cgb);
NSS(p_.trueColors);
NSS(p_.weMaster);
}

Expand Down
3 changes: 0 additions & 3 deletions libgambatte/src/video/ppu.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ struct PPUPriv {
unsigned char endx;

bool cgb;
bool trueColors;
bool weMaster;

PPUPriv(NextM0Time &nextM0Time, const unsigned char *oamram, const unsigned char *vram);
Expand All @@ -108,7 +107,6 @@ class PPU {

unsigned long * bgPalette() { return p_.bgPalette; }
bool cgb() const { return p_.cgb; }
bool trueColors() const { return p_.trueColors; }
void doLyCountEvent() { p_.lyCounter.doEvent(); }
unsigned long doSpriteMapEvent(unsigned long time) { return p_.spriteMapper.doEvent(time); }
const PPUFrameBuf & frameBuf() const { return p_.framebuf; }
Expand Down Expand Up @@ -136,7 +134,6 @@ class PPU {
void update(unsigned long cc);
void setLayers(unsigned mask) { p_.layersMask = mask; }
void setCgb(bool cgb) { p_.cgb = cgb; }
void setTrueColors(bool trueColors) { p_.trueColors = trueColors; }

template<bool isReader>void SyncState(NewState *ns);
};
Expand Down
Binary file modified output/dll/libgambatte.dll
Binary file not shown.

0 comments on commit f185f71

Please sign in to comment.