mirror of
https://github.com/dborth/vbagx.git
synced 2024-11-01 00:15:10 +01:00
revert some changes
This commit is contained in:
parent
ad987a37ad
commit
923667cecc
@ -23,14 +23,14 @@ public:
|
||||
// Global configuration
|
||||
struct config_t
|
||||
{
|
||||
pan_vol_t side_chans [2]; // left and right side channel volume and pan
|
||||
bool enabled; // false = disable all effects
|
||||
|
||||
// Current sound is echoed at adjustable left/right delay,
|
||||
// with reduced treble and volume (feedback).
|
||||
float treble; // 1.0 = full treble, 0.1 = very little, 0.0 = silent
|
||||
float feedback; // 0.0 = no echo, 0.5 = each echo half previous, 1.0 = cacophony
|
||||
int delay [2]; // left, right delays (msec)
|
||||
bool enabled; // false = disable all effects
|
||||
float feedback; // 0.0 = no echo, 0.5 = each echo half previous, 1.0 = cacophony
|
||||
pan_vol_t side_chans [2]; // left and right side channel volume and pan
|
||||
};
|
||||
config_t& config() { return config_; }
|
||||
|
||||
@ -123,10 +123,10 @@ class Simple_Effects_Buffer : public Effects_Buffer {
|
||||
public:
|
||||
struct config_t
|
||||
{
|
||||
bool enabled; // false = disable all effects
|
||||
float echo; // 0.0 = none, 1.0 = lots
|
||||
float stereo; // 0.0 = channels in center, 1.0 = channels on left/right
|
||||
bool surround; // true = put some channels in back
|
||||
bool enabled; // false = disable all effects
|
||||
};
|
||||
config_t& config() { return config_; }
|
||||
|
||||
|
@ -60,7 +60,7 @@ void Gb_Apu::set_output( Blip_Buffer* center, Blip_Buffer* left, Blip_Buffer* ri
|
||||
|
||||
void Gb_Apu::synth_volume( int iv )
|
||||
{
|
||||
double v = volume_ * iv * 0.005 / osc_count;
|
||||
double v = volume_ * 0.60 / osc_count / 15 /*steps*/ / 8 /*master vol range*/ * iv;
|
||||
good_synth.volume( v );
|
||||
med_synth .volume( v );
|
||||
}
|
||||
@ -88,18 +88,8 @@ void Gb_Apu::volume( double v )
|
||||
|
||||
void Gb_Apu::reset_regs()
|
||||
{
|
||||
int i = 24; // 32 - 8
|
||||
do {
|
||||
regs [i] =
|
||||
regs [i+1] =
|
||||
regs [i+2] =
|
||||
regs [i+3] =
|
||||
regs [i+4] =
|
||||
regs [i+5] =
|
||||
regs [i+6] =
|
||||
regs [i+7] = 0;
|
||||
i-=8;
|
||||
} while(i>=0);
|
||||
for ( int i = 0; i < 0x20; i++ )
|
||||
regs [i] = 0;
|
||||
|
||||
square1.reset();
|
||||
square2.reset();
|
||||
@ -126,7 +116,7 @@ void Gb_Apu::reduce_clicks( bool reduce )
|
||||
if ( reduce && wave.mode != mode_agb ) // AGB already eliminates clicks
|
||||
dac_off_amp = -Gb_Osc::dac_bias;
|
||||
|
||||
for ( int i = 0; i < osc_count; ++i )
|
||||
for ( int i = 0; i < osc_count; i++ )
|
||||
oscs [i]->dac_off_amp = dac_off_amp;
|
||||
|
||||
// AGB always eliminates clicks on wave channel using same method
|
||||
@ -140,7 +130,7 @@ void Gb_Apu::reset( mode_t mode, bool agb_wave )
|
||||
if ( agb_wave )
|
||||
mode = mode_agb; // using AGB wave features implies AGB hardware
|
||||
wave.agb_mask = agb_wave ? 0xFF : 0;
|
||||
for ( int i = 0; i < osc_count; ++i )
|
||||
for ( int i = 0; i < osc_count; i++ )
|
||||
oscs [i]->mode = mode;
|
||||
reduce_clicks( reduce_clicks_ );
|
||||
|
||||
@ -157,17 +147,12 @@ void Gb_Apu::reset( mode_t mode, bool agb_wave )
|
||||
{0x84,0x40,0x43,0xAA,0x2D,0x78,0x92,0x3C,0x60,0x59,0x59,0xB0,0x34,0xB8,0x2E,0xDA},
|
||||
{0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF},
|
||||
};
|
||||
unsigned i = 0;
|
||||
unsigned initialSize = sizeof(initial_wave[0]);
|
||||
|
||||
for ( int b = 2; --b >= 0; )
|
||||
{
|
||||
// Init both banks (does nothing if not in AGB mode)
|
||||
// TODO: verify that this works
|
||||
write_register( 0, 0xFF1A, 0x40 );
|
||||
for (; i < initialSize; ++i ){
|
||||
write_register( 0, i + wave_ram, initial_wave [(mode != mode_dmg)] [i] );
|
||||
}
|
||||
write_register( 0, 0xFF1A, 0 );
|
||||
for ( i = 0; i < initialSize; ++i ){
|
||||
write_register( 0, 0xFF1A, b * 0x40 );
|
||||
for ( unsigned i = 0; i < sizeof initial_wave [0]; i++ )
|
||||
write_register( 0, i + wave_ram, initial_wave [(mode != mode_dmg)] [i] );
|
||||
}
|
||||
}
|
||||
@ -188,8 +173,8 @@ Gb_Apu::Gb_Apu()
|
||||
oscs [2] = &wave;
|
||||
oscs [3] = &noise;
|
||||
|
||||
int i = osc_count - 1;
|
||||
do {
|
||||
for ( int i = osc_count; --i >= 0; )
|
||||
{
|
||||
Gb_Osc& o = *oscs [i];
|
||||
o.regs = ®s [i * 5];
|
||||
o.output = 0;
|
||||
@ -199,8 +184,7 @@ Gb_Apu::Gb_Apu()
|
||||
o.outputs [3] = 0;
|
||||
o.good_synth = &good_synth;
|
||||
o.med_synth = &med_synth;
|
||||
--i;
|
||||
} while(i >= 0);
|
||||
}
|
||||
|
||||
reduce_clicks_ = false;
|
||||
set_tempo( 1.0 );
|
||||
@ -288,8 +272,8 @@ void Gb_Apu::silence_osc( Gb_Osc& o )
|
||||
|
||||
void Gb_Apu::apply_stereo()
|
||||
{
|
||||
int i = osc_count - 1;
|
||||
do {
|
||||
for ( int i = osc_count; --i >= 0; )
|
||||
{
|
||||
Gb_Osc& o = *oscs [i];
|
||||
Blip_Buffer* out = o.outputs [calc_output( i )];
|
||||
if ( o.output != out )
|
||||
@ -297,8 +281,7 @@ void Gb_Apu::apply_stereo()
|
||||
silence_osc( o );
|
||||
o.output = out;
|
||||
}
|
||||
--i;
|
||||
} while(i >=0);
|
||||
}
|
||||
}
|
||||
|
||||
void Gb_Apu::write_register( blip_time_t time, unsigned addr, int data )
|
||||
@ -343,11 +326,8 @@ void Gb_Apu::write_register( blip_time_t time, unsigned addr, int data )
|
||||
else if ( addr == vol_reg && data != old_data )
|
||||
{
|
||||
// Master volume
|
||||
int i = osc_count - 1;
|
||||
do {
|
||||
for ( int i = osc_count; --i >= 0; )
|
||||
silence_osc( *oscs [i] );
|
||||
--i;
|
||||
} while( i >=0);
|
||||
|
||||
apply_volume();
|
||||
}
|
||||
@ -360,11 +340,8 @@ void Gb_Apu::write_register( blip_time_t time, unsigned addr, int data )
|
||||
{
|
||||
// Power control
|
||||
frame_phase = 0;
|
||||
int i = osc_count - 1;
|
||||
do {
|
||||
for ( int i = osc_count; --i >= 0; )
|
||||
silence_osc( *oscs [i] );
|
||||
--i;
|
||||
} while( i >=0);
|
||||
|
||||
reset_regs();
|
||||
if ( wave.mode != mode_dmg )
|
||||
|
@ -583,8 +583,7 @@ u8 ZeroTable[256] = {
|
||||
|
||||
int inline gbGetValue(int min,int max,int v)
|
||||
{
|
||||
float o31 = float(v) / 31.0f;
|
||||
return (min +((int)((float)(max-min)* o31*(2.0f - o31))));
|
||||
return (int)(min+(float)(max-min)*(2.0*(v/31.0)-(v/31.0)*(v/31.0)));
|
||||
}
|
||||
|
||||
void gbGenFilter()
|
||||
@ -632,9 +631,9 @@ void gbCopyMemory(u16 d, u16 s, int count)
|
||||
{
|
||||
while(count) {
|
||||
gbMemoryMap[d>>12][d & 0x0fff] = gbMemoryMap[s>>12][s & 0x0fff];
|
||||
++s;
|
||||
++d;
|
||||
--count;
|
||||
s++;
|
||||
d++;
|
||||
count--;
|
||||
}
|
||||
}
|
||||
|
||||
@ -671,7 +670,7 @@ void gbDoHdma()
|
||||
gbDmaTicks = 9;
|
||||
|
||||
if (IFF & 0x80)
|
||||
++gbDmaTicks;
|
||||
gbDmaTicks++;
|
||||
|
||||
}
|
||||
|
||||
@ -889,14 +888,16 @@ void gbWriteMemory(register u16 address, register u8 value)
|
||||
{
|
||||
bool temp = false;
|
||||
|
||||
if (((gbTimerOn && !gbTimerModeChange) && (gbTimerMode & 2) &&
|
||||
if ((gbTimerOn && !gbTimerModeChange) && (gbTimerMode & 2) &&
|
||||
!(gbInternalTimer & 0x80) && (gbInternalTimer & (gbTimerClockTicks>>1)) &&
|
||||
!(gbInternalTimer & (gbTimerClockTicks>>5)))
|
||||
||
|
||||
((!gbTimerOn && !gbTimerModeChange && gbTimerOnChange ) && ((gbTimerTicks-1) < (gbTimerClockTicks>>1)))){
|
||||
temp = true;
|
||||
}else if (gbTimerOn && gbTimerModeChange && !gbTimerOnChange){
|
||||
switch(gbTimerMode & 3){
|
||||
else if ((!gbTimerOn && !gbTimerModeChange && gbTimerOnChange ) && ((gbTimerTicks-1) < (gbTimerClockTicks>>1)))
|
||||
temp = true;
|
||||
else if (gbTimerOn && gbTimerModeChange && !gbTimerOnChange)
|
||||
{
|
||||
switch(gbTimerMode & 3)
|
||||
{
|
||||
case 0x00:
|
||||
temp = false;
|
||||
break;
|
||||
@ -1015,6 +1016,8 @@ void gbWriteMemory(register u16 address, register u8 value)
|
||||
|
||||
// systemDrawScreen();
|
||||
|
||||
|
||||
|
||||
gbRegisterLYLCDCOffOn = (register_LY + 144) % 154;
|
||||
|
||||
gbLcdTicks = GBLCD_MODE_2_CLOCK_TICKS - (gbSpeed ? 2 : 1);
|
||||
@ -1119,24 +1122,13 @@ void gbWriteMemory(register u16 address, register u8 value)
|
||||
temp = ((GBLY_INCREMENT_CLOCK_TICKS-GBLCD_MODE_2_CLOCK_TICKS) -
|
||||
gbLcdLYIncrementTicks);
|
||||
|
||||
if (temp >=0){
|
||||
if (temp < 300){
|
||||
|
||||
int i = temp << (gbSpeed ? 1 : 2);
|
||||
|
||||
if((i % 2) == 0){ // Divisible by 2
|
||||
// If it is divisible by 2, it'll go much faster
|
||||
for (; i < 300; i += 2){
|
||||
gbSCYLine[i] =
|
||||
gbSCYLine[i+1] = value;
|
||||
}
|
||||
}else{ // Not divisible by 2
|
||||
for (; i < 300; ++i){
|
||||
if (temp >=0)
|
||||
{
|
||||
for (int i=temp<<(gbSpeed ? 1 : 2);i<300;i++)
|
||||
if (temp < 300)
|
||||
gbSCYLine[i] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
memset(gbSCYLine, value, sizeof(gbSCYLine));
|
||||
|
||||
@ -1154,23 +1146,10 @@ void gbWriteMemory(register u16 address, register u8 value)
|
||||
|
||||
if (temp >=0)
|
||||
{
|
||||
if (temp < 300){
|
||||
int i = temp << (gbSpeed ? 1 : 2);
|
||||
|
||||
if((i % 2) == 0){ // Divisible by 2
|
||||
// If it is divisible by 2, it'll go much faster
|
||||
for (; i < 300; i += 2){
|
||||
gbSCXLine[i] =
|
||||
gbSCXLine[i+1] = value;
|
||||
}
|
||||
}else{ // Not divisible by 2
|
||||
for (; i < 300; ++i){
|
||||
for (int i=temp<<(gbSpeed ? 1 : 2);i<300;i++)
|
||||
if (temp < 300)
|
||||
gbSCXLine[i] = value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
memset(gbSCXLine, value, sizeof(gbSCXLine));
|
||||
@ -1199,8 +1178,11 @@ void gbWriteMemory(register u16 address, register u8 value)
|
||||
|
||||
// DMA!
|
||||
case 0x46: {
|
||||
int source = value << 8;
|
||||
gbCopyMemory(0xfe00, source, 0xa0);
|
||||
int source = value * 0x0100;
|
||||
|
||||
gbCopyMemory(0xfe00,
|
||||
source,
|
||||
0xa0);
|
||||
gbMemory[0xff46] = register_DMA = value;
|
||||
return;
|
||||
}
|
||||
@ -1218,22 +1200,10 @@ void gbWriteMemory(register u16 address, register u8 value)
|
||||
|
||||
if (temp >=0)
|
||||
{
|
||||
if (temp < 300){
|
||||
int i = temp << (gbSpeed ? 1 : 2);
|
||||
|
||||
if((i % 2) == 0){ // Divisible by 2
|
||||
// If it is divisible by 2, it'll go much faster
|
||||
for (; i < 300; i += 2){
|
||||
gbBgpLine[i] =
|
||||
gbBgpLine[i+1] = value;
|
||||
}
|
||||
}else{ // Not divisible by 2
|
||||
for (; i < 300; ++i){
|
||||
for (int i=temp<<(gbSpeed ? 1 : 2);i<300;i++)
|
||||
if (temp < 300)
|
||||
gbBgpLine[i] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
memset(gbBgpLine,value,sizeof(gbBgpLine));
|
||||
|
||||
@ -1253,22 +1223,10 @@ void gbWriteMemory(register u16 address, register u8 value)
|
||||
|
||||
if (temp >=0)
|
||||
{
|
||||
if (temp < 300){
|
||||
int i = temp << (gbSpeed ? 1 : 2);
|
||||
|
||||
if((i % 2) == 0){ // Divisible by 2
|
||||
// If it is divisible by 2, it'll go much faster
|
||||
for (; i < 300; i += 2){
|
||||
gbObp0Line[i] =
|
||||
gbObp0Line[i+1] = value;
|
||||
}
|
||||
}else{ // Not divisible by 2
|
||||
for (; i < 300; ++i){
|
||||
for (int i=temp<<(gbSpeed ? 1 : 2);i<300;i++)
|
||||
if (temp < 300)
|
||||
gbObp0Line[i] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
memset(gbObp0Line,value,sizeof(gbObp0Line));
|
||||
|
||||
@ -1288,22 +1246,10 @@ void gbWriteMemory(register u16 address, register u8 value)
|
||||
|
||||
if (temp >=0)
|
||||
{
|
||||
if (temp < 300){
|
||||
int i = temp << (gbSpeed ? 1 : 2);
|
||||
|
||||
if((i % 2) == 0){ // Divisible by 2
|
||||
// If it is divisible by 2, it'll go much faster
|
||||
for (; i < 300; i += 2){
|
||||
gbObp1Line[i] =
|
||||
gbObp1Line[i+1] = value;
|
||||
}
|
||||
}else{ // Not divisible by 2
|
||||
for (; i < 300; ++i){
|
||||
for (int i=temp<<(gbSpeed ? 1 : 2);i<300;i++)
|
||||
if (temp < 300)
|
||||
gbObp1Line[i] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
memset(gbObp1Line,value,sizeof(gbObp1Line));
|
||||
|
||||
@ -1338,11 +1284,11 @@ void gbWriteMemory(register u16 address, register u8 value)
|
||||
// VBK
|
||||
case 0x4f: {
|
||||
if(gbCgbMode) {
|
||||
value &= 1;
|
||||
value = value & 1;
|
||||
if(value == gbVramBank)
|
||||
return;
|
||||
|
||||
int vramAddress = value << 13; //* 0x2000
|
||||
int vramAddress = value * 0x2000;
|
||||
gbMemoryMap[0x08] = &gbVram[vramAddress];
|
||||
gbMemoryMap[0x09] = &gbVram[vramAddress + 0x1000];
|
||||
|
||||
@ -1419,7 +1365,7 @@ void gbWriteMemory(register u16 address, register u8 value)
|
||||
case 0x55: {
|
||||
|
||||
if(gbCgbMode) {
|
||||
gbHdmaBytes = 16 + ((value & 0x7f) <<4);
|
||||
gbHdmaBytes = 16 + (value & 0x7f) * 16;
|
||||
if(gbHdmaOn) {
|
||||
if(value & 0x80) {
|
||||
gbMemory[0xff55] = register_HDMA5 = (value & 0x7f);
|
||||
@ -1439,9 +1385,9 @@ void gbWriteMemory(register u16 address, register u8 value)
|
||||
// for single and double speed, but the actual transfer takes the
|
||||
// same time
|
||||
if(gbSpeed)
|
||||
gbDmaTicks = 2 + (((value & 0x7f) + 1) << 4);
|
||||
gbDmaTicks = 2+16 * ((value & 0x7f) +1);
|
||||
else
|
||||
gbDmaTicks = 1 + (((value & 0x7f) + 1) << 3);
|
||||
gbDmaTicks = 1+8 * ((value & 0x7f)+1);
|
||||
|
||||
gbCopyMemory((gbHdmaDestination & 0x1ff0) | 0x8000,
|
||||
gbHdmaSource & 0xfff0,
|
||||
@ -1449,17 +1395,11 @@ void gbWriteMemory(register u16 address, register u8 value)
|
||||
gbHdmaDestination += gbHdmaBytes;
|
||||
gbHdmaSource += gbHdmaBytes;
|
||||
|
||||
// Spacial alignemnt
|
||||
gbMemory[0xff51] =
|
||||
gbMemory[0xff52] =
|
||||
gbMemory[0xff53] =
|
||||
gbMemory[0xff54] =
|
||||
gbMemory[0xff55] = 0xff;
|
||||
register_HDMA1 =
|
||||
register_HDMA2 =
|
||||
register_HDMA3 =
|
||||
register_HDMA4 =
|
||||
register_HDMA5 = 0xff;
|
||||
gbMemory[0xff51] = register_HDMA1 = 0xff;// = (gbHdmaSource >> 8) & 0xff;
|
||||
gbMemory[0xff52] = register_HDMA2 = 0xff;// = gbHdmaSource & 0xf0;
|
||||
gbMemory[0xff53] = register_HDMA3 = 0xff;// = ((gbHdmaDestination - 0x8000) >> 8) & 0x1f;
|
||||
gbMemory[0xff54] = register_HDMA4 = 0xff;// = gbHdmaDestination & 0xf0;
|
||||
gbMemory[0xff55] = register_HDMA5 = 0xff;
|
||||
}
|
||||
}
|
||||
return;
|
||||
@ -1592,7 +1532,7 @@ void gbWriteMemory(register u16 address, register u8 value)
|
||||
if(bank == gbWramBank)
|
||||
return;
|
||||
|
||||
int wramAddress = bank << 12; //* 0x1000
|
||||
int wramAddress = bank * 0x1000;
|
||||
gbMemoryMap[0x0d] = &gbWram[wramAddress];
|
||||
|
||||
gbWramBank = bank;
|
||||
@ -1838,7 +1778,7 @@ u8 gbReadMemory(register u16 address)
|
||||
if(gbSgbMode && gbSgbMultiplayer) {
|
||||
switch(gbSgbNextController) {
|
||||
case 0x0f:
|
||||
default:
|
||||
joy = 0;
|
||||
break;
|
||||
case 0x0e:
|
||||
joy = 1;
|
||||
@ -1849,6 +1789,8 @@ u8 gbReadMemory(register u16 address)
|
||||
case 0x0c:
|
||||
joy = 3;
|
||||
break;
|
||||
default:
|
||||
joy = 0;
|
||||
}
|
||||
}
|
||||
int joystate = gbJoymask[joy];
|
||||
@ -1869,7 +1811,7 @@ u8 gbReadMemory(register u16 address)
|
||||
if(gbSgbMode && gbSgbMultiplayer) {
|
||||
switch(gbSgbNextController) {
|
||||
case 0x0f:
|
||||
default:
|
||||
joy = 0;
|
||||
break;
|
||||
case 0x0e:
|
||||
joy = 1;
|
||||
@ -1880,6 +1822,8 @@ u8 gbReadMemory(register u16 address)
|
||||
case 0x0c:
|
||||
joy = 3;
|
||||
break;
|
||||
default:
|
||||
joy = 0;
|
||||
}
|
||||
}
|
||||
int joystate = gbJoymask[joy];
|
||||
@ -2073,24 +2017,24 @@ void gbSpeedSwitch()
|
||||
gbBlackScreen = true;
|
||||
if(gbSpeed == 0) {
|
||||
gbSpeed = 1;
|
||||
GBLCD_MODE_0_CLOCK_TICKS = 51 << 1;
|
||||
GBLCD_MODE_1_CLOCK_TICKS = 1140 << 1;
|
||||
GBLCD_MODE_2_CLOCK_TICKS = 20 << 1;
|
||||
GBLCD_MODE_3_CLOCK_TICKS = 43 << 1;
|
||||
GBLY_INCREMENT_CLOCK_TICKS = 114 << 1;
|
||||
GBLCD_MODE_0_CLOCK_TICKS = 51 * 2;
|
||||
GBLCD_MODE_1_CLOCK_TICKS = 1140 * 2;
|
||||
GBLCD_MODE_2_CLOCK_TICKS = 20 * 2;
|
||||
GBLCD_MODE_3_CLOCK_TICKS = 43 * 2;
|
||||
GBLY_INCREMENT_CLOCK_TICKS = 114 * 2;
|
||||
GBDIV_CLOCK_TICKS = 64;
|
||||
GBTIMER_MODE_0_CLOCK_TICKS = 256;
|
||||
GBTIMER_MODE_1_CLOCK_TICKS = 4;
|
||||
GBTIMER_MODE_2_CLOCK_TICKS = 16;
|
||||
GBTIMER_MODE_3_CLOCK_TICKS = 64;
|
||||
GBSERIAL_CLOCK_TICKS = 128 << 1;
|
||||
gbLcdTicks <<= 1;
|
||||
gbLcdTicksDelayed <<= 1;
|
||||
--gbLcdTicksDelayed;
|
||||
gbLcdLYIncrementTicks <<= 1;
|
||||
gbLcdLYIncrementTicksDelayed <<= 1;
|
||||
--gbLcdLYIncrementTicksDelayed;
|
||||
gbSerialTicks <<= 1;
|
||||
GBSERIAL_CLOCK_TICKS = 128 * 2;
|
||||
gbLcdTicks *= 2;
|
||||
gbLcdTicksDelayed *=2;
|
||||
gbLcdTicksDelayed--;
|
||||
gbLcdLYIncrementTicks *= 2;
|
||||
gbLcdLYIncrementTicksDelayed *= 2;
|
||||
gbLcdLYIncrementTicksDelayed--;
|
||||
gbSerialTicks *= 2;
|
||||
//SOUND_CLOCK_TICKS = soundQuality * 24 * 2;
|
||||
//soundTicks *= 2;
|
||||
gbLine99Ticks = 3;
|
||||
@ -2108,17 +2052,17 @@ void gbSpeedSwitch()
|
||||
GBTIMER_MODE_3_CLOCK_TICKS = 64;
|
||||
GBSERIAL_CLOCK_TICKS = 128;
|
||||
gbLcdTicks >>= 1;
|
||||
++gbLcdTicksDelayed;
|
||||
gbLcdTicksDelayed++;
|
||||
gbLcdTicksDelayed >>=1;
|
||||
gbLcdLYIncrementTicks >>= 1;
|
||||
++gbLcdLYIncrementTicksDelayed;
|
||||
gbLcdLYIncrementTicksDelayed++;
|
||||
gbLcdLYIncrementTicksDelayed >>= 1;
|
||||
gbSerialTicks >>= 1;
|
||||
gbSerialTicks /= 2;
|
||||
//SOUND_CLOCK_TICKS = soundQuality * 24;
|
||||
//soundTicks /= 2;
|
||||
gbLine99Ticks = 1;
|
||||
if (gbHardware & 8)
|
||||
++gbLine99Ticks;
|
||||
gbLine99Ticks++;
|
||||
}
|
||||
gbDmaTicks += (134)*GBLY_INCREMENT_CLOCK_TICKS + (37<<(gbSpeed ? 1 : 0));
|
||||
}
|
||||
@ -2166,16 +2110,19 @@ void gbGetHardwareType()
|
||||
gbCgbMode = 0;
|
||||
gbSgbMode = 0;
|
||||
if(gbRom[0x143] & 0x80) {
|
||||
if((1<<gbEmulatorType) & ((1<<0)|(1<<1)|(1<<4))){
|
||||
if((gbEmulatorType == 0) ||
|
||||
gbEmulatorType == 1 ||
|
||||
gbEmulatorType == 4) {
|
||||
gbCgbMode = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if((gbCgbMode == 0 ) && (gbRom[0x146] == 0x03)) {
|
||||
if((1<<gbEmulatorType) & ((1<<0)|(1<<2)|(1<<5))){
|
||||
if(gbEmulatorType == 0 ||
|
||||
gbEmulatorType == 2 ||
|
||||
gbEmulatorType == 5)
|
||||
gbSgbMode = 1;
|
||||
}
|
||||
}
|
||||
|
||||
gbHardware = 1; // GB
|
||||
if (((gbCgbMode == 1) && (gbEmulatorType == 0)) || (gbEmulatorType == 1))
|
||||
@ -3751,24 +3698,17 @@ static bool gbReadSaveState(gzFile gzFile)
|
||||
memset(pix, 0, 257*226*sizeof(u32));
|
||||
|
||||
if(version < GBSAVE_GAME_VERSION_6) {
|
||||
utilGzRead(gzFile, gbPalette, (sizeof(u16)<<6));
|
||||
} else{
|
||||
utilGzRead(gzFile, gbPalette, (sizeof(u16)<<7));
|
||||
}
|
||||
utilGzRead(gzFile, gbPalette, 64 * sizeof(u16));
|
||||
} else
|
||||
utilGzRead(gzFile, gbPalette, 128 * sizeof(u16));
|
||||
|
||||
if (version < 11){
|
||||
utilGzRead(gzFile, gbPalette, (sizeof(u16)<<7));
|
||||
}
|
||||
if (version < 11)
|
||||
utilGzRead(gzFile, gbPalette, 128 * sizeof(u16));
|
||||
|
||||
if(version < GBSAVE_GAME_VERSION_10) {
|
||||
if(gbCgbMode || gbSgbMode) {
|
||||
int gbp8 = gbPaletteOption << 3;
|
||||
for(int i = 0; i < 8; i+=4){
|
||||
gbPalette[i ] = systemGbPalette[gbp8+i ];
|
||||
gbPalette[i+1] = systemGbPalette[gbp8+i+1];
|
||||
gbPalette[i+2] = systemGbPalette[gbp8+i+2];
|
||||
gbPalette[i+3] = systemGbPalette[gbp8+i+3];
|
||||
}
|
||||
if(!gbCgbMode && !gbSgbMode) {
|
||||
for(int i = 0; i < 8; i++)
|
||||
gbPalette[i] = systemGbPalette[gbPaletteOption*8+i];
|
||||
}
|
||||
}
|
||||
|
||||
@ -3897,9 +3837,9 @@ static bool gbReadSaveState(gzFile gzFile)
|
||||
if(value == 0)
|
||||
value = 1;
|
||||
|
||||
gbMemoryMap[0x08] = &gbVram[register_VBK << 13];
|
||||
gbMemoryMap[0x09] = &gbVram[(register_VBK << 13) + 0x1000];
|
||||
gbMemoryMap[0x0d] = &gbWram[value << 12];
|
||||
gbMemoryMap[0x08] = &gbVram[register_VBK * 0x2000];
|
||||
gbMemoryMap[0x09] = &gbVram[register_VBK * 0x2000 + 0x1000];
|
||||
gbMemoryMap[0x0d] = &gbWram[value * 0x1000];
|
||||
}
|
||||
|
||||
gbSoundReadGame(version, gzFile);
|
||||
@ -3949,7 +3889,7 @@ static bool gbReadSaveState(gzFile gzFile)
|
||||
GBDIV_CLOCK_TICKS = 64;
|
||||
|
||||
if (gbSpeed)
|
||||
gbDivTicks >>=1;
|
||||
gbDivTicks /=2;
|
||||
|
||||
if ((gbLcdMode == 0) && (register_STAT & 8))
|
||||
gbInt48Signal |= 1;
|
||||
@ -4000,7 +3940,7 @@ static bool gbReadSaveState(gzFile gzFile)
|
||||
}
|
||||
|
||||
if (gbSpeed)
|
||||
gbLine99Ticks <<= 1;
|
||||
gbLine99Ticks *= 2;
|
||||
|
||||
systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
|
||||
|
||||
@ -4009,6 +3949,7 @@ static bool gbReadSaveState(gzFile gzFile)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool gbReadMemSaveState(char *memory, int available)
|
||||
{
|
||||
gzFile gzFile = utilMemGzOpen(memory, available, "r");
|
||||
@ -4143,12 +4084,9 @@ bool gbUpdateSizes()
|
||||
|
||||
if(gbRomSize < gbRomSizes[gbRom[0x148]]) {
|
||||
gbRom = (u8 *)realloc(gbRom, gbRomSizes[gbRom[0x148]]);
|
||||
|
||||
int gbrSize = gbRomSizes[gbRom[0x148]];
|
||||
for (int i = gbRomSize; i < gbrSize; ++i){
|
||||
for (int i = gbRomSize; i<gbRomSizes[gbRom[0x148]]; i++)
|
||||
gbRom[i] = 0x00; // Not sure if it's 0x00, 0xff or random data...
|
||||
}
|
||||
}
|
||||
// (it's in the case a cart is 'lying' on its size.
|
||||
else if ((gbRomSize>gbRomSizes[gbRom[0x148]]) && (genericflashcardEnable))
|
||||
{
|
||||
@ -4158,10 +4096,10 @@ bool gbUpdateSizes()
|
||||
{
|
||||
while (!((gbRomSize & 1) || (gbRom[0x148] == 7)))
|
||||
{
|
||||
++gbRom[0x148];
|
||||
gbRom[0x148]++;
|
||||
gbRomSize>>=1;
|
||||
}
|
||||
++gbRom[0x148];
|
||||
gbRom[0x148]++;
|
||||
}
|
||||
gbRom = (u8 *)realloc(gbRom, gbRomSizes[gbRom[0x148]]);
|
||||
}
|
||||
@ -4180,29 +4118,17 @@ bool gbUpdateSizes()
|
||||
u8 ramsize = genericflashcardEnable ? 5 : gbRom[0x149];
|
||||
gbRom[0x149] = ramsize;
|
||||
|
||||
if(((gbRom[2] - 0x6D) | (gbRom[5] - 0x47) | (gbRom[6] - 0x65) | (gbRom[7] - 0x6E) |
|
||||
(gbRom[8] - 0x69) | (gbRom[9] - 0x65) | (gbRom[0xA] - 0x28) | (gbRom[0xB] - 0x54)) == 0)
|
||||
if ((gbRom[2] == 0x6D) && (gbRom[5] == 0x47) && (gbRom[6] == 0x65) && (gbRom[7] == 0x6E) &&
|
||||
(gbRom[8] == 0x69) && (gbRom[9] == 0x65) && (gbRom[0xA] == 0x28) && (gbRom[0xB] == 0x54))
|
||||
{
|
||||
gbCheatingDevice = 1; // GameGenie
|
||||
|
||||
for (int i = 0; i < 0x20; i+=8){ // Cleans GG hardware registers
|
||||
gbRom[0x4000+i] =
|
||||
gbRom[0x4001+i] =
|
||||
gbRom[0x4002+i] =
|
||||
gbRom[0x4003+i] =
|
||||
gbRom[0x4004+i] =
|
||||
gbRom[0x4005+i] =
|
||||
gbRom[0x4006+i] =
|
||||
gbRom[0x4007+i] = 0;
|
||||
for (int i = 0; i < 0x20; i++) // Cleans GG hardware registers
|
||||
gbRom[0x4000+i] = 0;
|
||||
}
|
||||
}
|
||||
else if((((gbRom[0x104] - 0x44) | (gbRom[0x156] - 0xEA) | (gbRom[0x158] - 0x7F) |
|
||||
(gbRom[0x159] - 0xEA) | (gbRom[0x15B] - 0x7F)) == 0)
|
||||
|| (((gbRom[0x165] - 0x3E) | (gbRom[0x166] - 0xD9) | (gbRom[0x16D] - 0xE1) | (gbRom[0x16E] - 0x7F)) == 0))
|
||||
|
||||
{
|
||||
else if (((gbRom[0x104] == 0x44) && (gbRom[0x156] == 0xEA) && (gbRom[0x158] == 0x7F) &&
|
||||
(gbRom[0x159] == 0xEA) && (gbRom[0x15B] == 0x7F)) || ((gbRom[0x165] == 0x3E) &&
|
||||
(gbRom[0x166] == 0xD9) && (gbRom[0x16D] == 0xE1) && (gbRom[0x16E] == 0x7F)))
|
||||
gbCheatingDevice = 2; // GameShark
|
||||
}
|
||||
else gbCheatingDevice = 0;
|
||||
|
||||
if(ramsize > 5) {
|
||||
@ -4217,6 +4143,16 @@ bool gbUpdateSizes()
|
||||
gbRomType = gbRom[0x147];
|
||||
if (genericflashcardEnable)
|
||||
{
|
||||
/*if (gbRomType<2)
|
||||
gbRomType =3;
|
||||
else if ((gbRomType == 0xc) || (gbRomType == 0xf) || (gbRomType == 0x12) ||
|
||||
(gbRomType == 0x16) || (gbRomType == 0x1a) || (gbRomType == 0x1d))
|
||||
gbRomType++;
|
||||
else if ((gbRomType == 0xb) || (gbRomType == 0x11) || (gbRomType == 0x15) ||
|
||||
(gbRomType == 0x19) || (gbRomType == 0x1c))
|
||||
gbRomType+=2;
|
||||
else if ((gbRomType == 0x5) || (gbRomType == 0x6))
|
||||
gbRomType = 0x1a;*/
|
||||
gbRomType = 0x1b;
|
||||
}
|
||||
else if (gbCheatingDevice == 1)
|
||||
@ -4372,6 +4308,7 @@ bool gbUpdateSizes()
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int gbGetNextEvent (int clockTicks)
|
||||
{
|
||||
if (register_LCDC & 0x80)
|
||||
@ -4412,27 +4349,26 @@ void gbDrawLine()
|
||||
u16 * dest = (u16 *)pix +
|
||||
(gbBorderLineSkip+2) * (register_LY + gbBorderRowSkip+1)
|
||||
+ gbBorderColumnSkip;
|
||||
for(u32 x = 0; x < 160u; ) {
|
||||
dest[x ] = systemColorMap16[gbLineMix[x ]];
|
||||
dest[x+1] = systemColorMap16[gbLineMix[x+1]];
|
||||
dest[x+2] = systemColorMap16[gbLineMix[x+2]];
|
||||
dest[x+3] = systemColorMap16[gbLineMix[x+3]];
|
||||
for(int x = 0; x < 160; ) {
|
||||
*dest++ = systemColorMap16[gbLineMix[x++]];
|
||||
*dest++ = systemColorMap16[gbLineMix[x++]];
|
||||
*dest++ = systemColorMap16[gbLineMix[x++]];
|
||||
*dest++ = systemColorMap16[gbLineMix[x++]];
|
||||
|
||||
dest[x+4] = systemColorMap16[gbLineMix[x+4]];
|
||||
dest[x+5] = systemColorMap16[gbLineMix[x+5]];
|
||||
dest[x+6] = systemColorMap16[gbLineMix[x+6]];
|
||||
dest[x+7] = systemColorMap16[gbLineMix[x+7]];
|
||||
*dest++ = systemColorMap16[gbLineMix[x++]];
|
||||
*dest++ = systemColorMap16[gbLineMix[x++]];
|
||||
*dest++ = systemColorMap16[gbLineMix[x++]];
|
||||
*dest++ = systemColorMap16[gbLineMix[x++]];
|
||||
|
||||
dest[x+8] = systemColorMap16[gbLineMix[x+8]];
|
||||
dest[x+9] = systemColorMap16[gbLineMix[x+9]];
|
||||
dest[x+10] = systemColorMap16[gbLineMix[x+10]];
|
||||
dest[x+11] = systemColorMap16[gbLineMix[x+11]];
|
||||
*dest++ = systemColorMap16[gbLineMix[x++]];
|
||||
*dest++ = systemColorMap16[gbLineMix[x++]];
|
||||
*dest++ = systemColorMap16[gbLineMix[x++]];
|
||||
*dest++ = systemColorMap16[gbLineMix[x++]];
|
||||
|
||||
dest[x+12] = systemColorMap16[gbLineMix[x+12]];
|
||||
dest[x+13] = systemColorMap16[gbLineMix[x+13]];
|
||||
dest[x+14] = systemColorMap16[gbLineMix[x+14]];
|
||||
dest[x+15] = systemColorMap16[gbLineMix[x+15]];
|
||||
x += 16;
|
||||
*dest++ = systemColorMap16[gbLineMix[x++]];
|
||||
*dest++ = systemColorMap16[gbLineMix[x++]];
|
||||
*dest++ = systemColorMap16[gbLineMix[x++]];
|
||||
*dest++ = systemColorMap16[gbLineMix[x++]];
|
||||
}
|
||||
if(gbBorderOn)
|
||||
dest += gbBorderColumnSkip;
|
||||
@ -4445,7 +4381,7 @@ void gbDrawLine()
|
||||
u8 *dest = (u8 *)pix +
|
||||
3*(gbBorderLineSkip * (register_LY + gbBorderRowSkip) +
|
||||
gbBorderColumnSkip);
|
||||
for(u32 x = 0; x < 160;) {
|
||||
for(int x = 0; x < 160;) {
|
||||
*((u32 *)dest) = systemColorMap32[gbLineMix[x++]];
|
||||
dest+= 3;
|
||||
*((u32 *)dest) = systemColorMap32[gbLineMix[x++]];
|
||||
@ -4490,32 +4426,32 @@ void gbDrawLine()
|
||||
u32 * dest = (u32 *)pix +
|
||||
(gbBorderLineSkip+1) * (register_LY + gbBorderRowSkip+1)
|
||||
+ gbBorderColumnSkip;
|
||||
for(u32 x = 0; x < 160u; ) {
|
||||
dest[x ] = systemColorMap32[gbLineMix[x ]];
|
||||
dest[x+1] = systemColorMap32[gbLineMix[x+1]];
|
||||
dest[x+2] = systemColorMap32[gbLineMix[x+2]];
|
||||
dest[x+3] = systemColorMap32[gbLineMix[x+3]];
|
||||
for(int x = 0; x < 160;) {
|
||||
*dest++ = systemColorMap32[gbLineMix[x++]];
|
||||
*dest++ = systemColorMap32[gbLineMix[x++]];
|
||||
*dest++ = systemColorMap32[gbLineMix[x++]];
|
||||
*dest++ = systemColorMap32[gbLineMix[x++]];
|
||||
|
||||
dest[x+4] = systemColorMap32[gbLineMix[x+4]];
|
||||
dest[x+5] = systemColorMap32[gbLineMix[x+5]];
|
||||
dest[x+6] = systemColorMap32[gbLineMix[x+6]];
|
||||
dest[x+7] = systemColorMap32[gbLineMix[x+7]];
|
||||
*dest++ = systemColorMap32[gbLineMix[x++]];
|
||||
*dest++ = systemColorMap32[gbLineMix[x++]];
|
||||
*dest++ = systemColorMap32[gbLineMix[x++]];
|
||||
*dest++ = systemColorMap32[gbLineMix[x++]];
|
||||
|
||||
dest[x+8] = systemColorMap32[gbLineMix[x+8]];
|
||||
dest[x+9] = systemColorMap32[gbLineMix[x+9]];
|
||||
dest[x+10] = systemColorMap32[gbLineMix[x+10]];
|
||||
dest[x+11] = systemColorMap32[gbLineMix[x+11]];
|
||||
*dest++ = systemColorMap32[gbLineMix[x++]];
|
||||
*dest++ = systemColorMap32[gbLineMix[x++]];
|
||||
*dest++ = systemColorMap32[gbLineMix[x++]];
|
||||
*dest++ = systemColorMap32[gbLineMix[x++]];
|
||||
|
||||
dest[x+12] = systemColorMap32[gbLineMix[x+12]];
|
||||
dest[x+13] = systemColorMap32[gbLineMix[x+13]];
|
||||
dest[x+14] = systemColorMap32[gbLineMix[x+14]];
|
||||
dest[x+15] = systemColorMap32[gbLineMix[x+15]];
|
||||
x+=16;
|
||||
*dest++ = systemColorMap32[gbLineMix[x++]];
|
||||
*dest++ = systemColorMap32[gbLineMix[x++]];
|
||||
*dest++ = systemColorMap32[gbLineMix[x++]];
|
||||
*dest++ = systemColorMap32[gbLineMix[x++]];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void gbEmulate(int ticksToStop)
|
||||
{
|
||||
gbRegister tempRegister;
|
||||
@ -4590,7 +4526,7 @@ void gbEmulate(int ticksToStop)
|
||||
// PC.W is not incremented for the first byte of the next instruction.
|
||||
if (IFF & 2)
|
||||
{
|
||||
--PC.W;
|
||||
PC.W--;
|
||||
IFF &= ~2;
|
||||
}
|
||||
|
||||
@ -4855,28 +4791,12 @@ void gbEmulate(int ticksToStop)
|
||||
if (wx<0)
|
||||
wx = 0;
|
||||
|
||||
if((wx <= 159) && (tempgbWindowLine <= 143)){
|
||||
|
||||
int i = 300 - 4;
|
||||
if (gbSpeed){
|
||||
do{
|
||||
if((wx <= 159) && (tempgbWindowLine <= 143))
|
||||
for (int i = wx; i<300; i++)
|
||||
if (gbSpeed)
|
||||
gbSpritesTicks[i]+=3;
|
||||
gbSpritesTicks[i+1]+=3;
|
||||
gbSpritesTicks[i+2]+=3;
|
||||
gbSpritesTicks[i+3]+=3;
|
||||
i-=4;
|
||||
}while(i>=0);
|
||||
|
||||
}else{
|
||||
do{
|
||||
++gbSpritesTicks[i];
|
||||
++gbSpritesTicks[i+1];
|
||||
++gbSpritesTicks[i+2];
|
||||
++gbSpritesTicks[i+3];
|
||||
i-=4;
|
||||
}while(i>=0);
|
||||
}
|
||||
}
|
||||
else
|
||||
gbSpritesTicks[i]+=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4947,7 +4867,9 @@ void gbEmulate(int ticksToStop)
|
||||
// set the LY increment counter
|
||||
|
||||
if(register_LCDC & 0x80) {
|
||||
if (gbHardware & 0xa){
|
||||
if (gbHardware & 0xa)
|
||||
{
|
||||
|
||||
register_IF |= 1; // V-Blank interrupt
|
||||
gbInterruptLaunched |=1;
|
||||
}
|
||||
@ -4958,7 +4880,7 @@ void gbEmulate(int ticksToStop)
|
||||
gbLcdTicksDelayed += GBLCD_MODE_1_CLOCK_TICKS;
|
||||
gbLcdModeDelayed = 1;
|
||||
|
||||
++gbFrameCount;
|
||||
gbFrameCount++;
|
||||
systemFrame();
|
||||
|
||||
if((gbFrameCount % 10) == 0)
|
||||
@ -4977,11 +4899,14 @@ void gbEmulate(int ticksToStop)
|
||||
if(systemReadJoypads()) {
|
||||
// read joystick
|
||||
if(gbSgbMode && gbSgbMultiplayer) {
|
||||
if(gbSgbFourPlayers) {
|
||||
gbJoymask[0] = systemReadJoypad(0);
|
||||
gbJoymask[1] = systemReadJoypad(1);
|
||||
if(gbSgbFourPlayers) {
|
||||
gbJoymask[2] = systemReadJoypad(2);
|
||||
gbJoymask[3] = systemReadJoypad(3);
|
||||
} else {
|
||||
gbJoymask[0] = systemReadJoypad(0);
|
||||
gbJoymask[1] = systemReadJoypad(1);
|
||||
}
|
||||
} else {
|
||||
gbJoymask[0] = systemReadJoypad(-1);
|
||||
@ -5005,7 +4930,7 @@ void gbEmulate(int ticksToStop)
|
||||
gbCapture = (newmask & 2) ? true : false;
|
||||
|
||||
if(gbCapture && !gbCapturePrevious) {
|
||||
++gbCaptureNumber;
|
||||
gbCaptureNumber++;
|
||||
systemScreenCapture(gbCaptureNumber);
|
||||
}
|
||||
gbCapturePrevious = gbCapture;
|
||||
@ -5021,7 +4946,7 @@ void gbEmulate(int ticksToStop)
|
||||
}
|
||||
gbFrameSkipCount = 0;
|
||||
} else
|
||||
++gbFrameSkipCount;
|
||||
gbFrameSkipCount++;
|
||||
|
||||
} else {
|
||||
// go the the OAM being accessed mode
|
||||
@ -5074,19 +4999,11 @@ void gbEmulate(int ticksToStop)
|
||||
if (!gbCgbMode)
|
||||
color = gbColorOption ? gbColorFilter[gbPalette[3] & 0x7FFF] :
|
||||
gbPalette[3] & 0x7FFF;
|
||||
|
||||
int i = 160-4;
|
||||
do{
|
||||
gbLineMix[i ] =
|
||||
gbLineMix[i+1] =
|
||||
gbLineMix[i+2] =
|
||||
gbLineMix[i+3] = color;
|
||||
gbLineBuffer[i] =
|
||||
gbLineBuffer[i+1] =
|
||||
gbLineBuffer[i+2] =
|
||||
gbLineBuffer[i+3] = 0;
|
||||
i-=4;
|
||||
}while(i >= 0);
|
||||
for(int i = 0; i < 160; i++)
|
||||
{
|
||||
gbLineMix[i] = color;
|
||||
gbLineBuffer[i] = 0;
|
||||
}
|
||||
}
|
||||
gbDrawLine();
|
||||
}
|
||||
@ -5139,7 +5056,7 @@ void gbEmulate(int ticksToStop)
|
||||
{
|
||||
|
||||
// Used to update the screen with white lines when it's off.
|
||||
// (it looks strange, but it's kinda accurate)
|
||||
// (it looks strange, but it's kinda accurate :p)
|
||||
// You can try the Mario Demo Vx.x for exemple
|
||||
// (check the bottom 2 lines while moving)
|
||||
if (!gbWhiteScreen)
|
||||
@ -5155,27 +5072,18 @@ void gbEmulate(int ticksToStop)
|
||||
{
|
||||
gbWhiteScreen = 1;
|
||||
u8 register_LYLcdOff = ((register_LY+154)%154);
|
||||
for (register_LY=0;register_LY <= 0x90;++register_LY)
|
||||
for (register_LY=0;register_LY <= 0x90;register_LY++)
|
||||
{
|
||||
u16 color = gbColorOption ? gbColorFilter[0x7FFF] :
|
||||
0x7FFF;
|
||||
if (!gbCgbMode)
|
||||
color = gbColorOption ? gbColorFilter[gbPalette[0] & 0x7FFF] :
|
||||
gbPalette[0] & 0x7FFF;
|
||||
|
||||
int i = 160 - 4;
|
||||
do{
|
||||
|
||||
gbLineMix[i ] =
|
||||
gbLineMix[i+1] =
|
||||
gbLineMix[i+2] =
|
||||
gbLineMix[i+3] = color;
|
||||
gbLineBuffer[i] =
|
||||
gbLineBuffer[i+1] =
|
||||
gbLineBuffer[i+2] =
|
||||
gbLineBuffer[i+3] = 0;
|
||||
i-=4;
|
||||
}while(i >= 0);
|
||||
for(int i = 0; i < 160; i++)
|
||||
{
|
||||
gbLineMix[i] = color;
|
||||
gbLineBuffer[i] = 0;
|
||||
}
|
||||
gbDrawLine();
|
||||
}
|
||||
register_LY = register_LYLcdOff;
|
||||
@ -5198,20 +5106,11 @@ void gbEmulate(int ticksToStop)
|
||||
if (!gbCgbMode)
|
||||
color = gbColorOption ? gbColorFilter[gbPalette[0] & 0x7FFF] :
|
||||
gbPalette[0] & 0x7FFF;
|
||||
|
||||
int i = 160 - 4;
|
||||
do{
|
||||
gbLineMix[i ] =
|
||||
gbLineMix[i+1] =
|
||||
gbLineMix[i+2] =
|
||||
gbLineMix[i+3] = color;
|
||||
gbLineBuffer[i] =
|
||||
gbLineBuffer[i+1] =
|
||||
gbLineBuffer[i+2] =
|
||||
gbLineBuffer[i+3] = 0;
|
||||
i-=4;
|
||||
}while(i >= 0);
|
||||
|
||||
for(int i = 0; i < 160; i++)
|
||||
{
|
||||
gbLineMix[i] = color;
|
||||
gbLineBuffer[i] = 0;
|
||||
}
|
||||
gbDrawLine();
|
||||
}
|
||||
else if ((register_LY==144) && (!systemFrameSkip))
|
||||
@ -5233,17 +5132,20 @@ void gbEmulate(int ticksToStop)
|
||||
if(systemReadJoypads()) {
|
||||
// read joystick
|
||||
if(gbSgbMode && gbSgbMultiplayer) {
|
||||
if(gbSgbFourPlayers) {
|
||||
gbJoymask[0] = systemReadJoypad(0);
|
||||
gbJoymask[1] = systemReadJoypad(1);
|
||||
if(gbSgbFourPlayers) {
|
||||
gbJoymask[2] = systemReadJoypad(2);
|
||||
gbJoymask[3] = systemReadJoypad(3);
|
||||
} else {
|
||||
gbJoymask[0] = systemReadJoypad(0);
|
||||
gbJoymask[1] = systemReadJoypad(1);
|
||||
}
|
||||
} else {
|
||||
gbJoymask[0] = systemReadJoypad(-1);
|
||||
}
|
||||
}
|
||||
++gbFrameCount;
|
||||
gbFrameCount++;
|
||||
|
||||
systemFrame();
|
||||
|
||||
@ -5274,7 +5176,7 @@ void gbEmulate(int ticksToStop)
|
||||
|
||||
while(gbSerialTicks <= 0) {
|
||||
// increment number of shifted bits
|
||||
++gbSerialBits;
|
||||
gbSerialBits++;
|
||||
linkProc();
|
||||
if(gbSerialOn && (gbMemory[0xff02] & 1)) {
|
||||
if(gbSerialBits == 8) {
|
||||
@ -5298,7 +5200,7 @@ void gbEmulate(int ticksToStop)
|
||||
// shift serial byte to right and put a 1 bit in its place
|
||||
// gbMemory[0xff01] = 0x80 | (gbMemory[0xff01]>>1);
|
||||
// increment number of shifted bits
|
||||
++gbSerialBits;
|
||||
gbSerialBits++;
|
||||
if(gbSerialBits == 8) {
|
||||
// end of transmission
|
||||
if(gbSerialFunction) // external device
|
||||
@ -5337,7 +5239,7 @@ void gbEmulate(int ticksToStop)
|
||||
gbTimerTicks= ((gbInternalTimer) & gbTimerMask[gbTimerMode])+1-clockTicks;
|
||||
|
||||
while(gbTimerTicks <= 0) {
|
||||
++register_TIMA;
|
||||
register_TIMA++;
|
||||
// timer overflow!
|
||||
if((register_TIMA & 0xff) == 0) {
|
||||
// reload timer modulo
|
||||
@ -5432,7 +5334,7 @@ void gbEmulate(int ticksToStop)
|
||||
|
||||
if (gbIntBreak == 2)
|
||||
{
|
||||
--gbDmaTicks;
|
||||
gbDmaTicks--;
|
||||
gbIntBreak = 0;
|
||||
}
|
||||
|
||||
@ -5478,11 +5380,14 @@ void gbEmulate(int ticksToStop)
|
||||
if(systemReadJoypads()) {
|
||||
// read joystick
|
||||
if(gbSgbMode && gbSgbMultiplayer) {
|
||||
if(gbSgbFourPlayers) {
|
||||
gbJoymask[0] = systemReadJoypad(0);
|
||||
gbJoymask[1] = systemReadJoypad(1);
|
||||
if(gbSgbFourPlayers) {
|
||||
gbJoymask[2] = systemReadJoypad(2);
|
||||
gbJoymask[3] = systemReadJoypad(3);
|
||||
} else {
|
||||
gbJoymask[0] = systemReadJoypad(0);
|
||||
gbJoymask[1] = systemReadJoypad(1);
|
||||
}
|
||||
} else {
|
||||
gbJoymask[0] = systemReadJoypad(-1);
|
||||
|
@ -78,7 +78,7 @@ void gbRenderLine()
|
||||
if(y >= 144)
|
||||
return;
|
||||
|
||||
int SpritesTicks = gbSpritesTicks[x] << (gbSpeed ? 1 : 2);
|
||||
int SpritesTicks = gbSpritesTicks[x]*(gbSpeed ? 2 : 4);
|
||||
int sx = gbSCXLine[(gbSpeed ? 0 : 4)+SpritesTicks];
|
||||
int sy = gbSCYLine[(gbSpeed ? 11 : 5)+SpritesTicks];
|
||||
|
||||
@ -92,7 +92,7 @@ void gbRenderLine()
|
||||
int bx = 1 << (7 - (sx & 7));
|
||||
int by = sy & 7;
|
||||
|
||||
int tile_map_line_y = tile_map + (ty <<5);
|
||||
int tile_map_line_y = tile_map + ty * 32;
|
||||
|
||||
int tile_map_address = tile_map_line_y + tx;
|
||||
|
||||
@ -102,22 +102,24 @@ void gbRenderLine()
|
||||
|
||||
u8 tile = bank0[tile_map_address];
|
||||
|
||||
++tile_map_address;
|
||||
tile_map_address++;
|
||||
|
||||
if(!(register_LCDC & 0x10))
|
||||
tile ^= 0x80;
|
||||
|
||||
int tile_pattern_address = tile_pattern + (tile<< 4) + (by<<1);
|
||||
int tile_pattern_address = tile_pattern + tile * 16 + by*2;
|
||||
|
||||
if(register_LCDC & 0x80) {
|
||||
if((register_LCDC & 0x01 || gbCgbMode) && (layerSettings & 0x0100)) {
|
||||
while(x < 160) {
|
||||
|
||||
|
||||
|
||||
u8 tile_a = 0;
|
||||
u8 tile_b = 0;
|
||||
|
||||
if(attrs & 0x40) {
|
||||
tile_pattern_address = tile_pattern + (tile<<4) + ((7-by)<<1);
|
||||
tile_pattern_address = tile_pattern + tile * 16 + (7-by)*2;
|
||||
}
|
||||
|
||||
if(attrs & 0x08) {
|
||||
@ -143,7 +145,7 @@ void gbRenderLine()
|
||||
gbLineBuffer[x] |= 0x300;
|
||||
|
||||
if(gbCgbMode) {
|
||||
c += (attrs & 7)<<2;
|
||||
c = c + (attrs & 7)*4;
|
||||
} else {
|
||||
// Get the background palette to use (from the delayed pipeline)
|
||||
u8 BgPal = gbBgpLine[x+(gbSpeed ? 5 : 11)+SpritesTicks];
|
||||
@ -158,7 +160,7 @@ void gbRenderLine()
|
||||
if(c == 0)
|
||||
palette = 0;
|
||||
|
||||
c += palette<<2;
|
||||
c = c + 4*palette;
|
||||
// Mono Game Boy requires special palette handling
|
||||
} else {
|
||||
if (BgPal!=oldBgPal) {
|
||||
@ -166,11 +168,12 @@ void gbRenderLine()
|
||||
oldBgPal = BgPal;
|
||||
}
|
||||
if (!ColorizeGameboy) c = (BgPal>>(c<<1)) &3;
|
||||
else c += 0;
|
||||
}
|
||||
}
|
||||
gbLineMix[x] = gbColorOption ? gbColorFilter[gbPalette[c] & 0x7FFF] :
|
||||
gbPalette[c] & 0x7FFF;
|
||||
++x;
|
||||
x++;
|
||||
if(x >= 160)
|
||||
break;
|
||||
bx >>= 1;
|
||||
@ -178,7 +181,7 @@ void gbRenderLine()
|
||||
|
||||
bx = 128;
|
||||
|
||||
SpritesTicks = gbSpritesTicks[x] << (gbSpeed ? 1 : 2);
|
||||
SpritesTicks = gbSpritesTicks[x]*(gbSpeed ? 2 : 4);
|
||||
|
||||
sx = gbSCXLine[x+(gbSpeed ? 0 : 4)+SpritesTicks];
|
||||
|
||||
@ -195,9 +198,9 @@ void gbRenderLine()
|
||||
|
||||
by = sy & 7;
|
||||
|
||||
tile_pattern_address = tile_pattern + (tile<<4) + (by<<1);
|
||||
tile_pattern_address = tile_pattern + tile * 16 + by * 2;
|
||||
|
||||
tile_map_line_y = tile_map + (ty<<5);
|
||||
tile_map_line_y = tile_map + ty * 32;
|
||||
|
||||
tile_map_address = tile_map_line_y + tx;
|
||||
|
||||
@ -209,7 +212,7 @@ void gbRenderLine()
|
||||
if(!(register_LCDC & 0x10))
|
||||
tile ^= 0x80;
|
||||
|
||||
tile_pattern_address = tile_pattern + (tile<<4) + (by<<1);
|
||||
tile_pattern_address = tile_pattern + tile * 16 + by * 2;
|
||||
}
|
||||
} else {
|
||||
// Use gbBgp[0] instead of 0 (?)
|
||||
@ -217,11 +220,11 @@ void gbRenderLine()
|
||||
// Also added the gbColorOption (fixes Dracula Densetsu II color problems)
|
||||
for(int i = 0; i < 160; i++)
|
||||
{
|
||||
u16 color = gbColorOption ? gbColorFilter[0x7FFF] : 0x7FFF;
|
||||
u16 color = gbColorOption ? gbColorFilter[0x7FFF] :
|
||||
0x7FFF;
|
||||
if (!gbCgbMode) {
|
||||
// Get the background palette to use (from the delayed pipeline)
|
||||
|
||||
u8 BgPal = gbBgpLine[i+(gbSpeed ? 5 : 11)+(gbSpritesTicks[i] << (gbSpeed ? 1 : 2))];
|
||||
u8 BgPal = gbBgpLine[i+(gbSpeed ? 5 : 11)+gbSpritesTicks[i]*(gbSpeed ? 2 : 4)];
|
||||
if ((BgPal!=oldBgPal) && !gbSgbMode) {
|
||||
gbSetBGPalette(BgPal);
|
||||
oldBgPal = BgPal;
|
||||
@ -277,7 +280,7 @@ void gbRenderLine()
|
||||
by = gbWindowLine & 7;
|
||||
|
||||
// Tries to emulate the 'window scrolling bug' when wx == 0 (ie. wx-7 == -7).
|
||||
// Nothing close to perfect, but good enough for now...
|
||||
// Nothing close to perfect, but good enought for now...
|
||||
if (wx == -7)
|
||||
{
|
||||
swx = 7-((gbSCXLine[0]-1) & 7);
|
||||
@ -300,7 +303,7 @@ void gbRenderLine()
|
||||
wx = 0;
|
||||
}
|
||||
|
||||
tile_map_line_y = tile_map + (ty<<5);
|
||||
tile_map_line_y = tile_map + ty * 32;
|
||||
|
||||
tile_map_address = tile_map_line_y + tx;
|
||||
|
||||
@ -310,29 +313,25 @@ void gbRenderLine()
|
||||
u8 attrs = 0;
|
||||
if(bank1)
|
||||
attrs = bank1[tile_map_address];
|
||||
++tile_map_address;
|
||||
tile_map_address++;
|
||||
|
||||
if((register_LCDC & 16) == 0) {
|
||||
if(tile < 128) tile += 128;
|
||||
else tile -= 128;
|
||||
}
|
||||
|
||||
tile_pattern_address = tile_pattern + (tile<<4) + (by<<1);
|
||||
tile_pattern_address = tile_pattern + tile * 16 + by*2;
|
||||
|
||||
if (wx){
|
||||
i = swx - 1;
|
||||
do{
|
||||
if (wx)
|
||||
for (i = 0; i<swx; i++)
|
||||
gbLineMix[i] = gbWindowColor[i];
|
||||
--i;
|
||||
}while(i >= 0);
|
||||
}
|
||||
|
||||
while(x < 160) {
|
||||
u8 tile_a = 0;
|
||||
u8 tile_b = 0;
|
||||
|
||||
if(attrs & 0x40) {
|
||||
tile_pattern_address = tile_pattern + (tile<<4) + ((7-by)<<1);
|
||||
tile_pattern_address = tile_pattern + tile * 16 + (7-by)*2;
|
||||
}
|
||||
|
||||
if(attrs & 0x08) {
|
||||
@ -360,7 +359,7 @@ void gbRenderLine()
|
||||
gbLineBuffer[x] = 0x100 + c;
|
||||
|
||||
if(gbCgbMode) {
|
||||
c += (attrs & 7) <<2;
|
||||
c = c + (attrs & 7) * 4;
|
||||
} else {
|
||||
// Get the background palette to use (from the delayed pipeline)
|
||||
u8 BgPal = gbBgpLine[x+(gbSpeed ? 5 : 11)+gbSpritesTicks[x]*(gbSpeed ? 2 : 4)];
|
||||
@ -375,7 +374,7 @@ void gbRenderLine()
|
||||
if(c == 0)
|
||||
palette = 0;
|
||||
|
||||
c += palette<<2;
|
||||
c = c + 4*palette;
|
||||
// Mono Game Boy requires special palette handling
|
||||
} else {
|
||||
if (BgPal!=oldBgPal) {
|
||||
@ -389,12 +388,12 @@ void gbRenderLine()
|
||||
gbLineMix[x] = gbColorOption ? gbColorFilter[gbPalette[c] & 0x7FFF] :
|
||||
gbPalette[c] & 0x7FFF;
|
||||
}
|
||||
++x;
|
||||
x++;
|
||||
if(x >= 160)
|
||||
break;
|
||||
bx >>= 1;
|
||||
}
|
||||
++tx;
|
||||
tx++;
|
||||
if(tx == 32)
|
||||
tx = 0;
|
||||
bx = 128;
|
||||
@ -406,12 +405,12 @@ void gbRenderLine()
|
||||
if(tile < 128) tile += 128;
|
||||
else tile -= 128;
|
||||
}
|
||||
tile_pattern_address = tile_pattern + (tile<<4) + (by<<1);
|
||||
tile_pattern_address = tile_pattern + tile * 16 + by * 2;
|
||||
}
|
||||
|
||||
//for (i = swx; i<160; i++)
|
||||
// gbLineMix[i] = gbWindowColor[i];
|
||||
++gbWindowLine;
|
||||
gbWindowLine++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -424,25 +423,16 @@ void gbRenderLine()
|
||||
gbWindowLine = 0;
|
||||
}
|
||||
} else {
|
||||
u16 color = gbColorOption ? gbColorFilter[0x7FFF] : 0x7FFF;
|
||||
u16 color = gbColorOption ? gbColorFilter[0x7FFF] :
|
||||
0x7FFF;
|
||||
if (!gbCgbMode)
|
||||
color = gbColorOption ? gbColorFilter[gbPalette[0] & 0x7FFF] :
|
||||
gbPalette[0] & 0x7FFF;
|
||||
|
||||
int i = 160 - 4;
|
||||
do{
|
||||
|
||||
gbLineMix[i] =
|
||||
gbLineMix[i+1] =
|
||||
gbLineMix[i+2] =
|
||||
gbLineMix[i+3] = color;
|
||||
gbLineBuffer[i] =
|
||||
gbLineBuffer[i+1] =
|
||||
gbLineBuffer[i+2] =
|
||||
gbLineBuffer[i+3] = 0;
|
||||
|
||||
i-=4;
|
||||
}while(i>=0);
|
||||
for(int i = 0; i < 160; i++)
|
||||
{
|
||||
gbLineMix[i] = color;
|
||||
gbLineBuffer[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -476,7 +466,7 @@ void gbDrawSpriteTile(int tile, int x,int y,int t, int flags,
|
||||
if(!gbCgbMode) {
|
||||
if(flags & 0x10) {
|
||||
pal = gbObp1;
|
||||
ObjPal = gbObp1Line[x+11+(gbSpritesTicks[x] << (gbSpeed ? 1 : 2))];
|
||||
ObjPal = gbObp1Line[x+11+gbSpritesTicks[x]*(gbSpeed ? 2 : 4)];
|
||||
if (ObjPal!=oldObj1Pal && !gbSgbMode) {
|
||||
gbSetObj1Palette(ObjPal);
|
||||
oldObj1Pal = ObjPal;
|
||||
@ -484,7 +474,7 @@ void gbDrawSpriteTile(int tile, int x,int y,int t, int flags,
|
||||
PalOffset = 12;
|
||||
} else {
|
||||
pal = gbObp0;
|
||||
ObjPal = gbObp0Line[x+11+(gbSpritesTicks[x] << (gbSpeed ? 1 : 2))];
|
||||
ObjPal = gbObp0Line[x+11+gbSpritesTicks[x]*(gbSpeed ? 2 : 4)];
|
||||
if (ObjPal!=oldObj0Pal && !gbSgbMode) {
|
||||
gbSetObj0Palette(ObjPal);
|
||||
oldObj0Pal = ObjPal;
|
||||
@ -502,7 +492,7 @@ void gbDrawSpriteTile(int tile, int x,int y,int t, int flags,
|
||||
|
||||
int prio = flags & 0x80;
|
||||
|
||||
int address = init + (tile<<4) + (t<<1);
|
||||
int address = init + tile * 16 + 2*t;
|
||||
int a = 0;
|
||||
int b = 0;
|
||||
|
||||
@ -514,11 +504,11 @@ void gbDrawSpriteTile(int tile, int x,int y,int t, int flags,
|
||||
b = bank0[address++];
|
||||
}
|
||||
|
||||
for(int xx = 0; xx < 8; ++xx) {
|
||||
for(int xx = 0; xx < 8; xx++) {
|
||||
u8 mask = 1 << (7-xx);
|
||||
u8 c = 0;
|
||||
if( (a & mask))
|
||||
++c;
|
||||
c++;
|
||||
if( (b & mask))
|
||||
c+=2;
|
||||
|
||||
@ -529,7 +519,7 @@ void gbDrawSpriteTile(int tile, int x,int y,int t, int flags,
|
||||
if(flipx)
|
||||
xxx = (7-xx+x);
|
||||
|
||||
if(unsigned(xxx-1) >= 159)
|
||||
if(xxx < 0 || xxx > 159)
|
||||
continue;
|
||||
|
||||
u16 color = gbLineBuffer[xxx];
|
||||
@ -540,13 +530,12 @@ void gbDrawSpriteTile(int tile, int x,int y,int t, int flags,
|
||||
continue;
|
||||
}
|
||||
// Fixes OAM-BG priority for Moorhuhn 2
|
||||
if(color >= 0x300 && color != 0x300 && (register_LCDC & 1)){
|
||||
|
||||
if(color >= 0x300 && color != 0x300 && (register_LCDC & 1))
|
||||
continue;
|
||||
}else if(color >= 0x200 && color < 0x300) {
|
||||
else if(color >= 0x200 && color < 0x300) {
|
||||
int sprite = color & 0xff;
|
||||
|
||||
int spriteX = gbMemory[0xfe00 + (sprite<<2) + 1] - 8;
|
||||
int spriteX = gbMemory[0xfe00 + 4 * sprite + 1] - 8;
|
||||
|
||||
if(spriteX == x) {
|
||||
if(sprite < spriteNumber)
|
||||
@ -569,7 +558,7 @@ void gbDrawSpriteTile(int tile, int x,int y,int t, int flags,
|
||||
|
||||
// make sure that sprites will work even in CGB mode
|
||||
if(gbCgbMode) {
|
||||
c += ((flags & 0x07)<<2) + 32;
|
||||
c = c + (flags & 0x07)*4 + 32;
|
||||
} else {
|
||||
// Super Game Boy has its own special palettes
|
||||
if(gbSgbMode) {
|
||||
@ -582,7 +571,7 @@ void gbDrawSpriteTile(int tile, int x,int y,int t, int flags,
|
||||
if(c == 0)
|
||||
palette = 0;
|
||||
|
||||
c += palette<<2;
|
||||
c = c + 4*palette;
|
||||
// Monochrome Game Boy
|
||||
} else {
|
||||
if (!ColorizeGameboy) c = (ObjPal>>(c<<1)) &3;
|
||||
@ -613,7 +602,7 @@ void gbDrawSprites(bool draw)
|
||||
int yc = register_LY;
|
||||
|
||||
int address = 0xfe00;
|
||||
for(int i = 0; i < 40; ++i) {
|
||||
for(int i = 0; i < 40; i++) {
|
||||
y = gbMemory[address++];
|
||||
x = gbMemory[address++];
|
||||
int tile = gbMemory[address++];
|
||||
@ -621,74 +610,24 @@ void gbDrawSprites(bool draw)
|
||||
tile &= 254;
|
||||
int flags = gbMemory[address++];
|
||||
|
||||
// Subtract 1 because we're not checking against greater-equal 0
|
||||
if(unsigned(x-1) < 167 && unsigned(y-1) < 159) {
|
||||
if(x > 0 && y > 0 && x < 168 && y < 160) {
|
||||
// check if sprite intersects current line
|
||||
int t = yc -y + 16;
|
||||
|
||||
if((size && (unsigned(t) < 16u)) || (!size && (unsigned(t) < 8u))) {
|
||||
if((size && t >=0 && t < 16) || (!size && t >= 0 && t < 8)) {
|
||||
if (draw)
|
||||
gbDrawSpriteTile(tile,x-8,yc,t,flags,size,i);
|
||||
else
|
||||
{
|
||||
int j = x - 8;
|
||||
// Less than 0 or divisible by 4
|
||||
if(j < 0 || (j & 3) == 0){
|
||||
|
||||
// If it's less than 0, set it to 0, and then we KNOW
|
||||
// that it can be incremented by 4.
|
||||
if(j < 0) j = 0;
|
||||
// Yeah, we have to check twice. It's either that or
|
||||
// have a (rather large) duplicate if-else statement
|
||||
|
||||
if(gbSpeed){
|
||||
for (; j<300; j+=4){
|
||||
for (int j = x-8; j<300; j++)
|
||||
if (j>=0)
|
||||
{
|
||||
if (gbSpeed)
|
||||
gbSpritesTicks[j] += 5;
|
||||
gbSpritesTicks[j+1] += 5;
|
||||
gbSpritesTicks[j+2] += 5;
|
||||
gbSpritesTicks[j+3] += 5;
|
||||
}
|
||||
}else{
|
||||
int count2 = 2 + (count & 1);
|
||||
for (; j<300; j+=4){
|
||||
gbSpritesTicks[j] += count2;
|
||||
gbSpritesTicks[j+1] += count2;
|
||||
gbSpritesTicks[j+2] += count2;
|
||||
gbSpritesTicks[j+3] += count2;
|
||||
else
|
||||
gbSpritesTicks[j] += 2+(count&1);
|
||||
}
|
||||
}
|
||||
}
|
||||
//divisible by 2 at least?
|
||||
else if((j & 1) == 0){
|
||||
if(gbSpeed){
|
||||
for (; j<300; j+=2){
|
||||
gbSpritesTicks[j] += 5;
|
||||
gbSpritesTicks[j+1] += 5;
|
||||
}
|
||||
}else{
|
||||
int count2 = 2 + (count & 1);
|
||||
for (; j<300; j+=2){
|
||||
gbSpritesTicks[j] += count2;
|
||||
gbSpritesTicks[j+1] += count2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// Not divisible by 4 OR 2: use the old one
|
||||
else{
|
||||
if(gbSpeed){
|
||||
for (; j<300; ++j){
|
||||
gbSpritesTicks[j] += 5;
|
||||
}
|
||||
}else{
|
||||
int count2 = 2 + (count & 1);
|
||||
for (; j<300; ++j){
|
||||
gbSpritesTicks[j] += count2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
++count;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
// sprite limit reached!
|
||||
|
@ -334,7 +334,7 @@ void memoryUpdateMBC3Clock()
|
||||
gbDataMBC3.mapperSeconds += (int)(diff % 60);
|
||||
if(gbDataMBC3.mapperSeconds > 59) {
|
||||
gbDataMBC3.mapperSeconds -= 60;
|
||||
++gbDataMBC3.mapperMinutes;
|
||||
gbDataMBC3.mapperMinutes++;
|
||||
}
|
||||
|
||||
diff /= 60;
|
||||
@ -342,7 +342,7 @@ void memoryUpdateMBC3Clock()
|
||||
gbDataMBC3.mapperMinutes += (int)(diff % 60);
|
||||
if(gbDataMBC3.mapperMinutes > 59) {
|
||||
gbDataMBC3.mapperMinutes -= 60;
|
||||
++gbDataMBC3.mapperHours;
|
||||
gbDataMBC3.mapperHours++;
|
||||
}
|
||||
|
||||
diff /= 60;
|
||||
@ -350,7 +350,7 @@ void memoryUpdateMBC3Clock()
|
||||
gbDataMBC3.mapperHours += (int)(diff % 24);
|
||||
if(gbDataMBC3.mapperHours > 23) {
|
||||
gbDataMBC3.mapperHours -= 24;
|
||||
++gbDataMBC3.mapperDays;
|
||||
gbDataMBC3.mapperDays++;
|
||||
}
|
||||
diff /= 24;
|
||||
|
||||
@ -567,7 +567,7 @@ void mapperMBC5ROM(u16 address, u8 value)
|
||||
gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000];
|
||||
|
||||
} else {
|
||||
value &= 1;
|
||||
value = value & 1;
|
||||
if(value == gbDataMBC5.mapperROMHighAddress)
|
||||
break;
|
||||
|
||||
@ -818,7 +818,7 @@ void mapperMBC7RAM(u16 address, u8 value)
|
||||
// receiving command
|
||||
gbDataMBC7.buffer <<= 1;
|
||||
gbDataMBC7.buffer |= (value & 0x02)?1:0;
|
||||
++gbDataMBC7.count;
|
||||
gbDataMBC7.count++;
|
||||
if(gbDataMBC7.count==2) {
|
||||
// finished receiving command
|
||||
gbDataMBC7.state=2;
|
||||
@ -830,7 +830,7 @@ void mapperMBC7RAM(u16 address, u8 value)
|
||||
// receive address
|
||||
gbDataMBC7.buffer <<= 1;
|
||||
gbDataMBC7.buffer |= (value&0x02)?1:0;
|
||||
++gbDataMBC7.count;
|
||||
gbDataMBC7.count++;
|
||||
if(gbDataMBC7.count==8) {
|
||||
// finish receiving
|
||||
gbDataMBC7.state=3;
|
||||
@ -850,7 +850,7 @@ void mapperMBC7RAM(u16 address, u8 value)
|
||||
case 3:
|
||||
gbDataMBC7.buffer <<= 1;
|
||||
gbDataMBC7.buffer |= (value&0x02)?1:0;
|
||||
++gbDataMBC7.count;
|
||||
gbDataMBC7.count++;
|
||||
|
||||
switch(gbDataMBC7.code) {
|
||||
case 0:
|
||||
@ -1238,7 +1238,7 @@ void memoryUpdateTAMA5Clock()
|
||||
gbDataTAMA5.mapperSeconds += (int)(diff % 60);
|
||||
if(gbDataTAMA5.mapperSeconds > 59) {
|
||||
gbDataTAMA5.mapperSeconds -= 60;
|
||||
++gbDataTAMA5.mapperMinutes;
|
||||
gbDataTAMA5.mapperMinutes++;
|
||||
}
|
||||
|
||||
diff /= 60;
|
||||
@ -1246,7 +1246,7 @@ void memoryUpdateTAMA5Clock()
|
||||
gbDataTAMA5.mapperMinutes += (int)(diff % 60);
|
||||
if(gbDataTAMA5.mapperMinutes > 59) {
|
||||
gbDataTAMA5.mapperMinutes -= 60;
|
||||
++gbDataTAMA5.mapperHours;
|
||||
gbDataTAMA5.mapperHours++;
|
||||
}
|
||||
|
||||
diff /= 60;
|
||||
@ -1255,23 +1255,23 @@ void memoryUpdateTAMA5Clock()
|
||||
diff /= 24;
|
||||
if(gbDataTAMA5.mapperHours > 23) {
|
||||
gbDataTAMA5.mapperHours -= 24;
|
||||
++diff;
|
||||
diff++;
|
||||
|
||||
}
|
||||
|
||||
time_t days = diff;
|
||||
while (days)
|
||||
{
|
||||
++gbDataTAMA5.mapperDays;
|
||||
--days;
|
||||
gbDataTAMA5.mapperDays++;
|
||||
days--;
|
||||
if (gbDataTAMA5.mapperDays>gbDaysinMonth[gbDataTAMA5.mapperMonths-1])
|
||||
{
|
||||
gbDataTAMA5.mapperDays = 1;
|
||||
++gbDataTAMA5.mapperMonths;
|
||||
gbDataTAMA5.mapperMonths++;
|
||||
if (gbDataTAMA5.mapperMonths>12)
|
||||
{
|
||||
gbDataTAMA5.mapperMonths = 1;
|
||||
++gbDataTAMA5.mapperYears;
|
||||
gbDataTAMA5.mapperYears++;
|
||||
if ((gbDataTAMA5.mapperYears & 3) == 0)
|
||||
gbDaysinMonth[1] = 29;
|
||||
else
|
||||
@ -1376,11 +1376,11 @@ void mapperTAMA5RAM(u16 address, u8 value)
|
||||
gbDataTAMA5.mapperLYears = gbDataTAMA5.mapperYears;
|
||||
gbDataTAMA5.mapperLControl = gbDataTAMA5.mapperControl;
|
||||
|
||||
int seconds = ((gbDataTAMA5.mapperLSeconds / 10)<<4) + gbDataTAMA5.mapperLSeconds %10;
|
||||
int seconds = (gbDataTAMA5.mapperLSeconds / 10)*16 + gbDataTAMA5.mapperLSeconds %10;
|
||||
int secondsL = (gbDataTAMA5.mapperLSeconds % 10);
|
||||
int secondsH = (gbDataTAMA5.mapperLSeconds / 10);
|
||||
int minutes = ((gbDataTAMA5.mapperLMinutes / 10)<<4) + gbDataTAMA5.mapperLMinutes %10;
|
||||
int hours = ((gbDataTAMA5.mapperLHours / 10)<<4) + gbDataTAMA5.mapperLHours %10;
|
||||
int minutes = (gbDataTAMA5.mapperLMinutes / 10)*16 + gbDataTAMA5.mapperLMinutes %10;
|
||||
int hours = (gbDataTAMA5.mapperLHours / 10)*16 + gbDataTAMA5.mapperLHours %10;
|
||||
int DaysL = gbDataTAMA5.mapperLDays % 10;
|
||||
int DaysH = gbDataTAMA5.mapperLDays /10;
|
||||
int MonthsL = gbDataTAMA5.mapperLMonths % 10;
|
||||
@ -1438,11 +1438,11 @@ void mapperTAMA5RAM(u16 address, u8 value)
|
||||
}
|
||||
else if (gbDataTAMA5.mapperRamByteSelect == 0x44)
|
||||
{
|
||||
gbDataTAMA5.mapperMinutes = (data>>4)*10 + (data & 15);
|
||||
gbDataTAMA5.mapperMinutes = (data/16)*10 + data%16;
|
||||
}
|
||||
else if (gbDataTAMA5.mapperRamByteSelect == 0x54)
|
||||
{
|
||||
gbDataTAMA5.mapperHours = (data>>4)*10 + (data & 15);
|
||||
gbDataTAMA5.mapperHours = (data/16)*10 + data%16;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1462,13 +1462,14 @@ void mapperTAMA5RAM(u16 address, u8 value)
|
||||
// I put it there...
|
||||
if (value == 0x0a)
|
||||
{
|
||||
for (int i = 0; i<0x10; i++){
|
||||
int i16 = i<<4;
|
||||
for (int j = 0; j<0x10; j+=4){
|
||||
gbTAMA5ram[(i16 + j ) | 2] = gbTAMA5ram[i16 + j ];
|
||||
gbTAMA5ram[(i16 + j + 1) | 2] = gbTAMA5ram[i16 + j + 1];
|
||||
}
|
||||
}
|
||||
for (int i = 0; i<0x10; i++)
|
||||
for (int j = 0; j<0x10; j++)
|
||||
if (!(j&2))
|
||||
gbTAMA5ram[((i*0x10)+j) | 2] = gbTAMA5ram[(i*0x10)+j];
|
||||
// Enable this to see the content of the flashrom in 0xe000
|
||||
/*for (int k = 0; k<0x100; k++)
|
||||
gbMemoryMap[0xe][k] = gbTAMA5ram[k];*/
|
||||
|
||||
gbMemoryMap[0xa][0] = gbDataTAMA5.mapperRAMEnable = 1;
|
||||
}
|
||||
else
|
||||
|
@ -10,9 +10,8 @@
|
||||
#include "gbGlobals.h"
|
||||
#include "../../vbagx.h"
|
||||
#include "../../menu.h"
|
||||
#include "../../fastmath.h"
|
||||
|
||||
#define CARLLOG
|
||||
//#define CARLLOG
|
||||
|
||||
bool ColorizeGameboy = true;
|
||||
|
||||
@ -38,20 +37,18 @@ const float BL[4] = {0.1f, 0.4f, 0.7f, 1.0f};
|
||||
// factor is from 0 to 1. 0 = no extra whiteness, 1 = 100% whiteness
|
||||
u16 changeColourWhiteness(u16 rgb, float factor) {
|
||||
if (factor==0.0f) return rgb;
|
||||
int f1factor = (0x1f*factor);
|
||||
int factorm1 = 1-factor;
|
||||
int r = (rgb & 0x1f);
|
||||
r = (r * factorm1)+ f1factor;
|
||||
r = (r * (1-factor))+(0x1f*factor);
|
||||
if (r>31) {
|
||||
r=31;
|
||||
}
|
||||
int g = ((rgb >> 5) & 0x1f);
|
||||
g = (g * factorm1)+f1factor;
|
||||
g = (g * (1-factor))+(0x1f*factor);
|
||||
if (g>31) {
|
||||
g=31;
|
||||
}
|
||||
int b = ((rgb >> 10) & 0x1f);
|
||||
b = (b * factorm1)+f1factor;
|
||||
b = (b * (1-factor))+(0x1f*factor);
|
||||
if (b>31) {
|
||||
b=31;
|
||||
}
|
||||
@ -63,22 +60,23 @@ u16 changeColourWhiteness(u16 rgb, float factor) {
|
||||
u16 changeColourBrightness(u16 rgb, float factor) {
|
||||
if (factor==1.0f) return rgb;
|
||||
int bonus = 0;
|
||||
int r = int(float(rgb & 0x1f) * factor);
|
||||
int r = (rgb & 0x1f);
|
||||
r = r * factor;
|
||||
if (r>31) {
|
||||
r=31;
|
||||
bonus+= (1 >> 1);
|
||||
bonus+=(r-30)/2;
|
||||
}
|
||||
int g = int(float((rgb >> 5) & 0x1f) * factor);
|
||||
|
||||
int g = ((rgb >> 5) & 0x1f);
|
||||
g = g * factor;
|
||||
if (g>31) {
|
||||
g=31;
|
||||
bonus+=(1 >> 1);
|
||||
bonus+=(g-30)/2;
|
||||
}
|
||||
int b = int(float((rgb >> 10) & 0x1f) * factor);
|
||||
|
||||
int b = ((rgb >> 10) & 0x1f);
|
||||
b = b * factor;
|
||||
if (b>31) {
|
||||
b=31;
|
||||
bonus += (1 >> 1);
|
||||
bonus+=(b-30)/2;
|
||||
}
|
||||
r+=bonus;
|
||||
g+=bonus;
|
||||
@ -113,8 +111,8 @@ void gbSetBGPalette(u8 value, bool ColoursChanged=false) {
|
||||
log("Bg Pal: %c %c %c %c", DN[gbObp0[0]], DN[gbObp0[1]], DN[gbObp0[2]], DN[gbObp0[3]]);
|
||||
#endif
|
||||
// check for duplicates
|
||||
for (unsigned i=0; i<=2u; ++i)
|
||||
for (unsigned j=i+1; j<=3u; ++j)
|
||||
for (int i=0; i<=2; i++)
|
||||
for (int j=i+1; j<=3; j++)
|
||||
if (gbBgp[i]==gbBgp[j]) {
|
||||
dup=true;
|
||||
dupDarkness = gbBgp[i];
|
||||
@ -122,26 +120,19 @@ void gbSetBGPalette(u8 value, bool ColoursChanged=false) {
|
||||
}
|
||||
// We haven't had a full palette yet, so guess...
|
||||
if (dup && !HadBgPal) {
|
||||
int index;
|
||||
if (gbBgp[0]>gbBgp[3]) {
|
||||
DarkestToBrightestIndex[0] = 0;
|
||||
DarkestToBrightestIndex[1] = 1;
|
||||
DarkestToBrightestIndex[2] = 2;
|
||||
DarkestToBrightestIndex[3] = 3;
|
||||
|
||||
Darkness[0] = gbBgp[0];
|
||||
Darkness[1] = gbBgp[1];
|
||||
Darkness[2] = gbBgp[2];
|
||||
Darkness[3] = gbBgp[3];
|
||||
for (int Colour=0; Colour<=3; Colour++) {
|
||||
index = Colour;
|
||||
DarkestToBrightestIndex[Colour]=index;
|
||||
Darkness[Colour]=gbBgp[index];
|
||||
}
|
||||
} else {
|
||||
DarkestToBrightestIndex[0] = 3;
|
||||
DarkestToBrightestIndex[1] = 2;
|
||||
DarkestToBrightestIndex[2] = 1;
|
||||
DarkestToBrightestIndex[3] = 0;
|
||||
|
||||
Darkness[0] = gbBgp[3];
|
||||
Darkness[1] = gbBgp[2];
|
||||
Darkness[2] = gbBgp[1];
|
||||
Darkness[3] = gbBgp[0];
|
||||
for (int Colour=0; Colour<=3; Colour++) {
|
||||
index = 3-Colour;
|
||||
DarkestToBrightestIndex[Colour]=index;
|
||||
Darkness[Colour]=gbBgp[index];
|
||||
}
|
||||
}
|
||||
// brightness of brightest colour
|
||||
BrightnessForBrightest = BL[3-gbBgp[DarkestToBrightestIndex[3]]];
|
||||
@ -150,12 +141,12 @@ void gbSetBGPalette(u8 value, bool ColoursChanged=false) {
|
||||
HadBgPal = true;
|
||||
// now we need to map them from darkest to brightest
|
||||
int Colour = 0;
|
||||
for (int darkness = 3; darkness>=0; --darkness) {
|
||||
for (int index=0; index<=3; ++index) {
|
||||
for (int darkness = 3; darkness>=0; darkness--) {
|
||||
for (int index=0; index<=3; index++) {
|
||||
if (gbBgp[index]==darkness) {
|
||||
DarkestToBrightestIndex[Colour]=index;
|
||||
Darkness[Colour]=gbBgp[index];
|
||||
++Colour;
|
||||
Colour++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -175,16 +166,13 @@ void gbSetBGPalette(u8 value, bool ColoursChanged=false) {
|
||||
if (dupDarkness==0) {
|
||||
// Multiple colours set to white
|
||||
BrightnessFactor = 0;
|
||||
WhitenessFactor += BL[3-gbBgp[0]]
|
||||
+ BL[3-gbBgp[1]]
|
||||
+ BL[3-gbBgp[2]]
|
||||
+ BL[3-gbBgp[3]]
|
||||
- BL[3] - BL[2] - BL[1]- BL[0];
|
||||
|
||||
float MaxWhiteness = BL[3] + BL[3] + BL[3] + BL[3]
|
||||
-BL[3] -BL[2] -BL[1] -BL[0];
|
||||
|
||||
WhitenessFactor /= (MaxWhiteness+0.4f);
|
||||
float MaxWhiteness = 0;
|
||||
int i;
|
||||
for (i=0; i<=3; i++) {
|
||||
WhitenessFactor+=BL[3-gbBgp[i]]-BL[3-i];
|
||||
MaxWhiteness+=BL[3]-BL[3-i];
|
||||
}
|
||||
WhitenessFactor = WhitenessFactor / (MaxWhiteness+0.4f);
|
||||
// check if they are trying to make the palette brighter
|
||||
} else if (NewBrightnessForBrightest==1.0f && BrightnessForBrightest==1.0f) {
|
||||
float NewBrightnessForDarkest = BL[3-gbBgp[DarkestToBrightestIndex[0]]];
|
||||
@ -196,7 +184,7 @@ void gbSetBGPalette(u8 value, bool ColoursChanged=false) {
|
||||
}
|
||||
if (WhitenessFactor) {
|
||||
// BG colours
|
||||
for (int colour = 0; colour <= 3; ++colour) {
|
||||
for (int colour = 0; colour <= 3; colour++) {
|
||||
u16 colourRGB = systemMonoPalette[colour];
|
||||
float colourBrightness = BL[colour];
|
||||
float indexBrightness = BL[3-Darkness[colour]];
|
||||
@ -204,7 +192,7 @@ void gbSetBGPalette(u8 value, bool ColoursChanged=false) {
|
||||
gbPalette[0+DarkestToBrightestIndex[colour]] = changeColourWhiteness(colourRGB, WhitenessFactor);
|
||||
}
|
||||
// Window colours
|
||||
for (int colour = 0; colour <= 3; ++colour) {
|
||||
for (int colour = 0; colour <= 3; colour++) {
|
||||
u16 colourRGB = systemMonoPalette[4+colour];
|
||||
float colourBrightness = BL[colour];
|
||||
float indexBrightness = BL[3-Darkness[colour]];
|
||||
@ -213,14 +201,14 @@ void gbSetBGPalette(u8 value, bool ColoursChanged=false) {
|
||||
}
|
||||
} else {
|
||||
// BG colours
|
||||
for (int colour = 0; colour <= 3; ++colour) {
|
||||
for (int colour = 0; colour <= 3; colour++) {
|
||||
u16 colourRGB = systemMonoPalette[colour];
|
||||
float colourBrightness = BL[colour];
|
||||
float indexBrightness = BL[3-Darkness[colour]]*BrightnessFactor;
|
||||
gbPalette[0+DarkestToBrightestIndex[colour]] = changeColourBrightness(colourRGB, indexBrightness/colourBrightness);
|
||||
}
|
||||
// Window colours
|
||||
for (int colour = 0; colour <= 3; ++colour) {
|
||||
for (int colour = 0; colour <= 3; colour++) {
|
||||
u16 colourRGB = systemMonoPalette[4+colour];
|
||||
float colourBrightness = BL[colour];
|
||||
float indexBrightness = BL[3-Darkness[colour]]*BrightnessFactor;
|
||||
@ -262,21 +250,19 @@ void gbSetObj0Palette(u8 value, bool ColoursChanged = false) {
|
||||
}
|
||||
// We haven't had a full palette yet, so guess...
|
||||
if (dup && !HadObj1Pal) {
|
||||
int index;
|
||||
if (gbObp0[1]>gbObp0[3]) {
|
||||
DarkestToBrightestIndex[0] = 1;
|
||||
DarkestToBrightestIndex[1] = 2;
|
||||
DarkestToBrightestIndex[2] = 3;
|
||||
Darkness[0] = gbObp0[1];
|
||||
Darkness[1] = gbObp0[2];
|
||||
Darkness[2] = gbObp0[3];
|
||||
|
||||
for (int Colour=0; Colour<=2; Colour++) {
|
||||
index = Colour+1;
|
||||
DarkestToBrightestIndex[Colour]=index;
|
||||
Darkness[Colour]=gbObp0[index];
|
||||
}
|
||||
} else {
|
||||
DarkestToBrightestIndex[0] = 3;
|
||||
DarkestToBrightestIndex[1] = 2;
|
||||
DarkestToBrightestIndex[2] = 1;
|
||||
Darkness[0] = gbObp0[3];
|
||||
Darkness[1] = gbObp0[2];
|
||||
Darkness[2] = gbObp0[1];
|
||||
for (int Colour=0; Colour<=2; Colour++) {
|
||||
index = 2-Colour+1;
|
||||
DarkestToBrightestIndex[Colour]=index;
|
||||
Darkness[Colour]=gbObp0[index];
|
||||
}
|
||||
}
|
||||
// brightness of brightest colour
|
||||
BrightnessForBrightest = BL[3-gbObp0[DarkestToBrightestIndex[2]]];
|
||||
@ -285,12 +271,12 @@ void gbSetObj0Palette(u8 value, bool ColoursChanged = false) {
|
||||
HadObj0Pal = true;
|
||||
// now we need to map them from darkest to brightest
|
||||
int Colour = 0;
|
||||
for (int darkness = 3; darkness>=0; --darkness) {
|
||||
for (int darkness = 3; darkness>=0; darkness--) {
|
||||
for (int index=1; index<=3; index++) {
|
||||
if (gbObp0[index]==darkness) {
|
||||
DarkestToBrightestIndex[Colour]=index;
|
||||
Darkness[Colour]=gbObp0[index];
|
||||
++Colour;
|
||||
Colour++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -310,16 +296,13 @@ void gbSetObj0Palette(u8 value, bool ColoursChanged = false) {
|
||||
if (dupDarkness==0) {
|
||||
// Multiple colours set to white
|
||||
BrightnessFactor = 0;
|
||||
WhitenessFactor+= BL[3-gbObp0[1]]
|
||||
+ BL[3-gbObp0[2]]
|
||||
+ BL[3-gbObp0[3]]
|
||||
-BL[3] -BL[2] -BL[1];
|
||||
|
||||
float MaxWhiteness = BL[3] + BL[3] + BL[3]
|
||||
- BL[3] - BL[2] - BL[1];
|
||||
|
||||
|
||||
WhitenessFactor /= (MaxWhiteness+0.3f);
|
||||
float MaxWhiteness = 0;
|
||||
int i;
|
||||
for (i=1; i<=3; i++) {
|
||||
WhitenessFactor+=BL[3-gbObp0[i]]-BL[3-(i-1)];
|
||||
MaxWhiteness+=BL[3]-BL[3-(i-1)];
|
||||
}
|
||||
WhitenessFactor = WhitenessFactor / (MaxWhiteness+0.3f);
|
||||
// check if they are trying to make the palette brighter
|
||||
} else if (NewBrightnessForBrightest==1.0f && BrightnessForBrightest==1.0f) {
|
||||
float NewBrightnessForDarkest = BL[3-gbObp0[DarkestToBrightestIndex[0]]];
|
||||
@ -379,21 +362,19 @@ void gbSetObj1Palette(u8 value, bool ColoursChanged = false) {
|
||||
}
|
||||
// We haven't had a full palette yet, so guess...
|
||||
if (dup && !HadObj1Pal) {
|
||||
if (gbObp0[1]>gbObp0[3]) {
|
||||
DarkestToBrightestIndex[0] = 1;
|
||||
DarkestToBrightestIndex[1] = 2;
|
||||
DarkestToBrightestIndex[2] = 3;
|
||||
Darkness[0] = gbObp0[1];
|
||||
Darkness[1] = gbObp0[2];
|
||||
Darkness[2] = gbObp0[3];
|
||||
int index;
|
||||
if (gbObp1[1]>gbObp1[3]) {
|
||||
for (int Colour=0; Colour<=2; Colour++) {
|
||||
index = Colour+1;
|
||||
DarkestToBrightestIndex[Colour]=index;
|
||||
Darkness[Colour]=gbObp1[index];
|
||||
}
|
||||
} else {
|
||||
DarkestToBrightestIndex[0] = 3;
|
||||
DarkestToBrightestIndex[1] = 2;
|
||||
DarkestToBrightestIndex[2] = 1;
|
||||
Darkness[0] = gbObp0[3];
|
||||
Darkness[1] = gbObp0[2];
|
||||
Darkness[2] = gbObp0[1];
|
||||
|
||||
for (int Colour=0; Colour<=2; Colour++) {
|
||||
index = 2-Colour+1;
|
||||
DarkestToBrightestIndex[Colour]=index;
|
||||
Darkness[Colour]=gbObp1[index];
|
||||
}
|
||||
}
|
||||
// brightness of brightest colour
|
||||
BrightnessForBrightest = BL[3-gbObp1[DarkestToBrightestIndex[2]]];
|
||||
@ -427,14 +408,13 @@ void gbSetObj1Palette(u8 value, bool ColoursChanged = false) {
|
||||
if (dupDarkness==0) {
|
||||
// Multiple colours set to white
|
||||
BrightnessFactor = 0;
|
||||
WhitenessFactor+= BL[3-gbObp1[1]]
|
||||
+ BL[3-gbObp1[2]]
|
||||
+ BL[3-gbObp1[3]]
|
||||
-BL[3] -BL[2] -BL[1];
|
||||
|
||||
float MaxWhiteness = BL[3] + BL[3] + BL[3]
|
||||
- BL[3] - BL[2] - BL[1];
|
||||
WhitenessFactor /= (MaxWhiteness+0.3f);
|
||||
float MaxWhiteness = 0;
|
||||
int i;
|
||||
for (i=1; i<=3; i++) {
|
||||
WhitenessFactor+=BL[3-gbObp1[i]]-BL[3-(i-1)];
|
||||
MaxWhiteness+=BL[3]-BL[3-(i-1)];
|
||||
}
|
||||
WhitenessFactor = WhitenessFactor / (MaxWhiteness+0.3f);
|
||||
// check if they are trying to make the palette brighter
|
||||
} else if (NewBrightnessForBrightest==1.0f && BrightnessForBrightest==1.0f) {
|
||||
float NewBrightnessForDarkest = BL[3-gbObp1[DarkestToBrightestIndex[0]]];
|
||||
@ -474,14 +454,8 @@ bool StartColorizing() {
|
||||
|
||||
void StopColorizing() {
|
||||
if(!ColorizeGameboy || gbSgbMode || gbCgbMode) return;
|
||||
|
||||
int gbpo12 = gbPaletteOption*12;
|
||||
for(int i = 0; i < 12; i+=4){
|
||||
gbPalette[i] = systemGbPalette[gbpo12+i];
|
||||
gbPalette[i+1] = systemGbPalette[gbpo12+i+1];
|
||||
gbPalette[i+2] = systemGbPalette[gbpo12+i+2];
|
||||
gbPalette[i+3] = systemGbPalette[gbpo12+i+3];
|
||||
}
|
||||
for(int i = 0; i < 12; i++)
|
||||
gbPalette[i] = systemGbPalette[gbPaletteOption*12+i];
|
||||
ColorizeGameboy = false;
|
||||
}
|
||||
|
||||
@ -497,9 +471,7 @@ void gbSetSpritePal(u8 WhichPal, u32 bright, u32 medium, u32 dark) {
|
||||
// cancel if we already set to these colours
|
||||
if (WhichPal>0) {
|
||||
int p = WhichPal-1;
|
||||
if(((OldObpBright[p] - bright) | (OldObpMedium[p] - medium) | (OldObpDark[p] - dark)) == 0){
|
||||
return;
|
||||
}
|
||||
if (OldObpBright[p]==bright && OldObpMedium[p]==medium && OldObpDark[p]==dark) return;
|
||||
}
|
||||
int index = 0;
|
||||
// check if we are setting both sprite palettes at once
|
||||
@ -562,9 +534,9 @@ void gbSetBgPal(u8 WhichPal, u32 bright) {
|
||||
u8 r = (bright >> 16) & 0xFF;
|
||||
u8 g = (bright >> 8) & 0xFF;
|
||||
u8 b = (bright >> 0) & 0xFF;
|
||||
u32 medium = ((ftou((utof(r)*0.7f))) << 16) | ((ftou((utof(g)*0.7f))) << 8) | ((ftou((utof(b)*0.7f))) << 0);
|
||||
u32 dark = ((ftou((utof(r)*0.4f))) << 16) | ((ftou((utof(g)*0.4f))) << 8) | ((ftou((utof(b)*0.4f))) << 0);
|
||||
u32 black = ((ftou((utof(r)*0.1f))) << 16) | ((ftou((utof(g)*0.1f))) << 8) | ((ftou((utof(b)*0.1f))) << 0);
|
||||
u32 medium = (((u32)(r*0.7f)) << 16) | (((u32)(g*0.7f)) << 8) | (((u32)(b*0.7f)) << 0);
|
||||
u32 dark = (((u32)(r*0.4f)) << 16) | (((u32)(g*0.4f)) << 8) | (((u32)(b*0.4f)) << 0);
|
||||
u32 black = (((u32)(r*0.1f)) << 16) | (((u32)(g*0.1f)) << 8) | (((u32)(b*0.1f)) << 0);
|
||||
gbSetBgPal(WhichPal, bright, medium, dark, black);
|
||||
}
|
||||
|
||||
@ -581,7 +553,7 @@ void gbPaletteReset() {
|
||||
oldBgp = 0xFC;
|
||||
oldObp0 = oldObp1 = 0xFF;
|
||||
OldBgBright=0; OldBgMedium=0; OldBgDark=0; OldBgBlack=0;
|
||||
OldObpBright[0]= OldObpBright[1]=
|
||||
OldObpMedium[0]= OldObpMedium[1]=
|
||||
OldObpDark[0]= OldObpDark[1] =0;
|
||||
for (int i=0; i<=1; i++) {
|
||||
OldObpBright[i]=OldObpMedium[i]=OldObpDark[i]=0;
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,10 @@ bool gbSoundGetDeclicking();
|
||||
// Effects configuration
|
||||
struct gb_effects_config_t
|
||||
{
|
||||
bool enabled; // false = disable all effects
|
||||
|
||||
float echo; // 0.0 = none, 1.0 = lots
|
||||
float stereo; // 0.0 = channels in center, 1.0 = channels on left/right
|
||||
bool enabled; // false = disable all effects
|
||||
bool surround; // true = put some channels in back
|
||||
};
|
||||
|
||||
|
@ -9,11 +9,10 @@ int eepromMode = EEPROM_IDLE;
|
||||
int eepromByte = 0;
|
||||
int eepromBits = 0;
|
||||
int eepromAddress = 0;
|
||||
//--DCN (restructuring for alignment)
|
||||
int eepromSize = 512;
|
||||
u8 eepromData[0x2000];
|
||||
u8 eepromBuffer[16];
|
||||
bool eepromInUse = false;
|
||||
int eepromSize = 512;
|
||||
|
||||
variable_desc eepromSaveData[] = {
|
||||
{ &eepromMode, sizeof(int) },
|
||||
@ -79,7 +78,7 @@ int eepromRead(u32 /* address */)
|
||||
return 1;
|
||||
case EEPROM_READDATA:
|
||||
{
|
||||
++eepromBits;
|
||||
eepromBits++;
|
||||
if(eepromBits == 4) {
|
||||
eepromMode = EEPROM_READDATA2;
|
||||
eepromBits = 0;
|
||||
@ -89,14 +88,13 @@ int eepromRead(u32 /* address */)
|
||||
}
|
||||
case EEPROM_READDATA2:
|
||||
{
|
||||
//--DCN
|
||||
int data = 0;
|
||||
int address = eepromAddress << 3;
|
||||
int mask = 1 << (7 - (eepromBits & 7));
|
||||
int data = (eepromData[address+eepromByte] & mask) ? 1 : 0;
|
||||
|
||||
++eepromBits;
|
||||
data = (eepromData[address+eepromByte] & mask) ? 1 : 0;
|
||||
eepromBits++;
|
||||
if((eepromBits & 7) == 0)
|
||||
++eepromByte;
|
||||
eepromByte++;
|
||||
if(eepromBits == 0x40)
|
||||
eepromMode = EEPROM_IDLE;
|
||||
return data;
|
||||
@ -122,9 +120,9 @@ void eepromWrite(u32 /* address */, u8 value)
|
||||
case EEPROM_READADDRESS:
|
||||
eepromBuffer[eepromByte] <<= 1;
|
||||
eepromBuffer[eepromByte] |= bit;
|
||||
++eepromBits;
|
||||
eepromBits++;
|
||||
if((eepromBits & 7) == 0) {
|
||||
++eepromByte;
|
||||
eepromByte++;
|
||||
}
|
||||
if(cpuDmaCount == 0x11 || cpuDmaCount == 0x51) {
|
||||
if(eepromBits == 0x11) {
|
||||
@ -143,8 +141,8 @@ void eepromWrite(u32 /* address */, u8 value)
|
||||
eepromBits = 0;
|
||||
}
|
||||
}
|
||||
//--DCN (else, if into else if, may be an improvement; couldn't hurt)
|
||||
} else if(eepromBits == 9) {
|
||||
} else {
|
||||
if(eepromBits == 9) {
|
||||
eepromInUse = true;
|
||||
eepromAddress = (eepromBuffer[0] & 0x3F);
|
||||
if(!(eepromBuffer[0] & 0x40)) {
|
||||
@ -158,6 +156,7 @@ void eepromWrite(u32 /* address */, u8 value)
|
||||
eepromBits = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EEPROM_READDATA:
|
||||
case EEPROM_READDATA2:
|
||||
@ -167,21 +166,15 @@ void eepromWrite(u32 /* address */, u8 value)
|
||||
case EEPROM_WRITEDATA:
|
||||
eepromBuffer[eepromByte] <<= 1;
|
||||
eepromBuffer[eepromByte] |= bit;
|
||||
++eepromBits;
|
||||
eepromBits++;
|
||||
if((eepromBits & 7) == 0) {
|
||||
++eepromByte;
|
||||
eepromByte++;
|
||||
}
|
||||
if(eepromBits == 0x40) {
|
||||
eepromInUse = true;
|
||||
// write data;
|
||||
//--DCN
|
||||
int eeprom3 = eepromAddress << 3;
|
||||
for(int i = 0; i < 8; i+=4) {
|
||||
|
||||
eepromData[eeprom3 + i+1] = eepromBuffer[i+1];
|
||||
eepromData[eeprom3 + i+2] = eepromBuffer[i+2];
|
||||
eepromData[eeprom3 + i+3] = eepromBuffer[i+3];
|
||||
eepromData[eeprom3 + i+4] = eepromBuffer[i+4];
|
||||
for(int i = 0; i < 8; i++) {
|
||||
eepromData[(eepromAddress << 3) + i] = eepromBuffer[i];
|
||||
}
|
||||
systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
|
||||
} else if(eepromBits == 0x41) {
|
||||
|
@ -14,23 +14,23 @@ enum LocationType {
|
||||
|
||||
struct ELFHeader {
|
||||
u32 magic;
|
||||
u8 clazz;
|
||||
u8 data;
|
||||
u8 version;
|
||||
u8 pad[9];
|
||||
u16 e_type;
|
||||
u16 e_machine;
|
||||
u32 e_version;
|
||||
u32 e_entry;
|
||||
u32 e_phoff;
|
||||
u32 e_shoff;
|
||||
u32 e_flags;
|
||||
u16 e_type;
|
||||
u16 e_machine;
|
||||
u16 e_ehsize;
|
||||
u16 e_phentsize;
|
||||
u16 e_phnum;
|
||||
u16 e_shentsize;
|
||||
u16 e_shnum;
|
||||
u16 e_shstrndx;
|
||||
u8 clazz;
|
||||
u8 data;
|
||||
u8 version;
|
||||
u8 pad[9];
|
||||
};
|
||||
|
||||
struct ELFProgramHeader {
|
||||
@ -61,9 +61,9 @@ struct ELFSymbol {
|
||||
u32 name;
|
||||
u32 value;
|
||||
u32 size;
|
||||
u16 shndx;
|
||||
u8 info;
|
||||
u8 other;
|
||||
u16 shndx;
|
||||
};
|
||||
|
||||
struct ELFBlock {
|
||||
@ -75,21 +75,21 @@ struct ELFAttr {
|
||||
u32 name;
|
||||
u32 form;
|
||||
union {
|
||||
ELFBlock *block;
|
||||
u32 value;
|
||||
char *string;
|
||||
u8 *data;
|
||||
bool flag;
|
||||
ELFBlock *block;
|
||||
};
|
||||
};
|
||||
|
||||
struct ELFAbbrev {
|
||||
u32 number;
|
||||
u32 tag;
|
||||
bool hasChildren;
|
||||
int numAttrs;
|
||||
ELFAttr *attrs;
|
||||
ELFAbbrev *next;
|
||||
bool hasChildren;
|
||||
};
|
||||
|
||||
enum TypeEnum {
|
||||
@ -163,12 +163,12 @@ struct Object {
|
||||
char *name;
|
||||
int file;
|
||||
int line;
|
||||
bool external;
|
||||
Type *type;
|
||||
ELFBlock *location;
|
||||
u32 startScope;
|
||||
u32 endScope;
|
||||
Object *next;
|
||||
bool external;
|
||||
};
|
||||
|
||||
struct Function {
|
||||
@ -177,12 +177,12 @@ struct Function {
|
||||
u32 highPC;
|
||||
int file;
|
||||
int line;
|
||||
bool external;
|
||||
Type *returnType;
|
||||
Object *parameters;
|
||||
Object *variables;
|
||||
ELFBlock *frameBase;
|
||||
Function *next;
|
||||
bool external;
|
||||
};
|
||||
|
||||
struct LineInfoItem {
|
||||
@ -193,8 +193,8 @@ struct LineInfoItem {
|
||||
|
||||
struct LineInfo {
|
||||
int fileCount;
|
||||
int number;
|
||||
char **files;
|
||||
int number;
|
||||
LineInfoItem *lines;
|
||||
};
|
||||
|
||||
@ -219,6 +219,7 @@ struct CompileUnit {
|
||||
char *compdir;
|
||||
u32 lowPC;
|
||||
u32 highPC;
|
||||
bool hasLineInfo;
|
||||
u32 lineInfo;
|
||||
LineInfo *lineInfoTable;
|
||||
Function *functions;
|
||||
@ -226,7 +227,6 @@ struct CompileUnit {
|
||||
Object *variables;
|
||||
Type *types;
|
||||
CompileUnit *next;
|
||||
bool hasLineInfo;
|
||||
};
|
||||
|
||||
struct DebugInfo {
|
||||
|
Loading…
Reference in New Issue
Block a user