improve code quality

This commit is contained in:
spacy51 2009-08-30 20:21:34 +00:00
parent 592843e4f4
commit e512e02b3d
6 changed files with 41 additions and 36 deletions

View File

@ -2437,7 +2437,7 @@ void gbReset()
gbTimerOn = false; gbTimerOn = false;
if(gbCgbMode) { if(gbCgbMode) {
for (int i = 0; i<0x20; i++) for (i = 0; i<0x20; i++)
gbPalette[i] = 0x7fff; gbPalette[i] = 0x7fff;
// This is just to show that the starting values of the OBJ palettes are different // This is just to show that the starting values of the OBJ palettes are different
@ -2555,11 +2555,11 @@ void gbReset()
} }
} else { } else {
if(gbSgbMode) { if(gbSgbMode) {
for(int i = 0; i < 8; i++) for(i = 0; i < 8; i++)
gbPalette[i] = systemGbPalette[gbPaletteOption*8+i]; gbPalette[i] = systemGbPalette[gbPaletteOption*8+i];
} }
for(int i = 0; i < 8; i++) for(i = 0; i < 8; i++)
gbPalette[i] = systemGbPalette[gbPaletteOption*8+i]; gbPalette[i] = systemGbPalette[gbPaletteOption*8+i];
} }
@ -4079,7 +4079,9 @@ bool gbUpdateSizes()
} }
if(gbRomSize < gbRomSizes[gbRom[0x148]]) { if(gbRomSize < gbRomSizes[gbRom[0x148]]) {
gbRom = (u8 *)realloc(gbRom, gbRomSizes[gbRom[0x148]]); u8 *gbRomNew = (u8 *)realloc(gbRom, gbRomSizes[gbRom[0x148]]);
if( !gbRomNew ) { assert( false ); return false; };
gbRom = gbRomNew;
for (int i = gbRomSize; i<gbRomSizes[gbRom[0x148]]; i++) for (int i = gbRomSize; i<gbRomSizes[gbRom[0x148]]; i++)
gbRom[i] = 0x00; // Not sure if it's 0x00, 0xff or random data... gbRom[i] = 0x00; // Not sure if it's 0x00, 0xff or random data...
} }
@ -4097,7 +4099,9 @@ bool gbUpdateSizes()
} }
gbRom[0x148]++; gbRom[0x148]++;
} }
gbRom = (u8 *)realloc(gbRom, gbRomSizes[gbRom[0x148]]); u8 *gbRomNew = (u8 *)realloc(gbRom, gbRomSizes[gbRom[0x148]]);
if( !gbRomNew ) { assert( false ); return false; };
gbRom = gbRomNew;
} }
gbRomSize = gbRomSizes[gbRom[0x148]]; gbRomSize = gbRomSizes[gbRom[0x148]];
gbRomSizeMask = gbRomSizesMasks[gbRom[0x148]]; gbRomSizeMask = gbRomSizesMasks[gbRom[0x148]];
@ -4305,36 +4309,36 @@ bool gbUpdateSizes()
return true; return true;
} }
int gbGetNextEvent (int clockTicks) int gbGetNextEvent (int _clockTicks)
{ {
if (register_LCDC & 0x80) if (register_LCDC & 0x80)
{ {
if(gbLcdTicks < clockTicks) if(gbLcdTicks < _clockTicks)
clockTicks = gbLcdTicks; _clockTicks = gbLcdTicks;
if(gbLcdTicksDelayed < clockTicks) if(gbLcdTicksDelayed < _clockTicks)
clockTicks = gbLcdTicksDelayed; _clockTicks = gbLcdTicksDelayed;
if(gbLcdLYIncrementTicksDelayed < clockTicks) if(gbLcdLYIncrementTicksDelayed < _clockTicks)
clockTicks = gbLcdLYIncrementTicksDelayed; _clockTicks = gbLcdLYIncrementTicksDelayed;
} }
if(gbLcdLYIncrementTicks < clockTicks) if(gbLcdLYIncrementTicks < _clockTicks)
clockTicks = gbLcdLYIncrementTicks; _clockTicks = gbLcdLYIncrementTicks;
if(gbSerialOn && (gbSerialTicks < clockTicks)) if(gbSerialOn && (gbSerialTicks < _clockTicks))
clockTicks = gbSerialTicks; _clockTicks = gbSerialTicks;
if(gbTimerOn && (((gbInternalTimer) & gbTimerMask[gbTimerMode])+1 < clockTicks)) if(gbTimerOn && (((gbInternalTimer) & gbTimerMask[gbTimerMode])+1 < _clockTicks))
clockTicks = ((gbInternalTimer) & gbTimerMask[gbTimerMode])+1; _clockTicks = ((gbInternalTimer) & gbTimerMask[gbTimerMode])+1;
//if(soundTicks && (soundTicks < clockTicks)) //if(soundTicks && (soundTicks < _clockTicks))
// clockTicks = soundTicks; // _clockTicks = soundTicks;
if ((clockTicks<=0) || (gbInterruptWait)) if ((_clockTicks<=0) || (gbInterruptWait))
clockTicks = 1; _clockTicks = 1;
return clockTicks; return _clockTicks;
} }
void gbDrawLine() void gbDrawLine()

View File

@ -245,22 +245,22 @@ void gbSgbDrawBorderTile(int x, int y, int tile, int attr)
else else
xxx = 7 - xx; xxx = 7 - xx;
u16 c; u16 cc;
if (color) { if (color) {
c = gbPalette[palette + color]; cc = gbPalette[palette + color];
} else { } else {
c = gbPalette[0]; cc = gbPalette[0];
} }
switch(systemColorDepth) { switch(systemColorDepth) {
case 16: case 16:
gbSgbDraw16Bit(dest + yyy*(256+2) + xxx, c); gbSgbDraw16Bit(dest + yyy*(256+2) + xxx, cc);
break; break;
case 24: case 24:
gbSgbDraw24Bit(dest8 + (yyy*256+xxx)*3, c); gbSgbDraw24Bit(dest8 + (yyy*256+xxx)*3, cc);
break; break;
case 32: case 32:
gbSgbDraw32Bit(dest32 + yyy*(256+1)+xxx, c); gbSgbDraw32Bit(dest32 + yyy*(256+1)+xxx, cc);
break; break;
} }
} }

View File

@ -454,7 +454,7 @@ static inline void CPUWriteMemory(u32 address, u32 value)
} }
goto unwritable; goto unwritable;
case 0x0E: case 0x0E:
if(!eepromInUse | cpuSramEnabled | cpuFlashEnabled) { if((!eepromInUse) | cpuSramEnabled | cpuFlashEnabled) {
(*cpuSaveGameFunc)(address, (u8)value); (*cpuSaveGameFunc)(address, (u8)value);
break; break;
} }
@ -556,7 +556,7 @@ static inline void CPUWriteHalfWord(u32 address, u16 value)
} }
goto unwritable; goto unwritable;
case 14: case 14:
if(!eepromInUse | cpuSramEnabled | cpuFlashEnabled) { if((!eepromInUse) | cpuSramEnabled | cpuFlashEnabled) {
(*cpuSaveGameFunc)(address, (u8)value); (*cpuSaveGameFunc)(address, (u8)value);
break; break;
} }
@ -692,7 +692,7 @@ static inline void CPUWriteByte(u32 address, u8 b)
} }
goto unwritable; goto unwritable;
case 14: case 14:
if (!(saveType == 5) && (!eepromInUse | cpuSramEnabled | cpuFlashEnabled)) { if ((saveType != 5) && ((!eepromInUse) | cpuSramEnabled | cpuFlashEnabled)) {
//if(!cpuEEPROMEnabled && (cpuSramEnabled | cpuFlashEnabled)) { //if(!cpuEEPROMEnabled && (cpuSramEnabled | cpuFlashEnabled)) {

View File

@ -696,7 +696,7 @@ void BIOS_LZ77UnCompVram()
int length = (data >> 12) + 3; int length = (data >> 12) + 3;
int offset = (data & 0x0FFF); int offset = (data & 0x0FFF);
u32 windowOffset = dest + byteCount - offset - 1; u32 windowOffset = dest + byteCount - offset - 1;
for(int i = 0; i < length; i++) { for(int i2 = 0; i2 < length; i2++) {
writeValue |= (CPUReadByte(windowOffset++) << byteShift); writeValue |= (CPUReadByte(windowOffset++) << byteShift);
byteShift += 8; byteShift += 8;
byteCount++; byteCount++;
@ -781,7 +781,7 @@ void BIOS_LZ77UnCompWram()
int length = (data >> 12) + 3; int length = (data >> 12) + 3;
int offset = (data & 0x0FFF); int offset = (data & 0x0FFF);
u32 windowOffset = dest - offset - 1; u32 windowOffset = dest - offset - 1;
for(int i = 0; i < length; i++) { for(int i2 = 0; i2 < length; i2++) {
CPUWriteByte(dest++, CPUReadByte(windowOffset++)); CPUWriteByte(dest++, CPUReadByte(windowOffset++));
len--; len--;
if(len == 0) if(len == 0)

View File

@ -968,7 +968,7 @@ void systemDrawScreen()
theApp.aviRecorder = NULL; theApp.aviRecorder = NULL;
theApp.aviRecording = false; theApp.aviRecording = false;
} }
delete bmp; delete [] bmp;
} }
} }
@ -2141,7 +2141,7 @@ void VBA::updatePriority()
bool VBA::detectMMX() bool VBA::detectMMX()
{ {
bool support = false; bool support = false;
char brand[13]; char brand[12]; // not zero terminated
// check for Intel chip // check for Intel chip
__try { __try {

View File

@ -211,6 +211,7 @@ bool XAudio2_Output::init(long sampleRate)
ASSERT( hr == S_OK ); ASSERT( hr == S_OK );
float *matrix = NULL; float *matrix = NULL;
matrix = (float*)malloc( sizeof( float ) * 2 * dd.OutputFormat.Format.nChannels ); matrix = (float*)malloc( sizeof( float ) * 2 * dd.OutputFormat.Format.nChannels );
if( matrix == NULL ) return false;
bool matrixAvailable = true; bool matrixAvailable = true;
switch( dd.OutputFormat.Format.nChannels ) { switch( dd.OutputFormat.Format.nChannels ) {
case 4: // 4.0 case 4: // 4.0