beautified code

git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@782 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
spacy51 2008-10-26 20:47:35 +00:00
parent 93f5527ded
commit 009c70cd7d
2 changed files with 160 additions and 158 deletions

View File

@ -2356,25 +2356,28 @@ void CPUCheckDMA(int reason, int dmamask)
void CPUUpdateRegister(u32 address, u16 value) void CPUUpdateRegister(u32 address, u16 value)
{ {
switch(address) { switch(address)
case 0x00:
{ {
if ((value & 7) >5) case 0x00:
DISPCNT = (value &7); { // we need to place the following code in { } because we declare & initialize variables in a case statement
bool change = ((DISPCNT ^ value) & 0x80) ? true : false; if((value & 7) > 5) {
bool changeBG = ((DISPCNT ^ value) & 0x0F00) ? true : false; // display modes above 0-5 are prohibited
u16 changeBGon = (((~DISPCNT) & value) & 0x0F00); DISPCNT = (value & 7);
DISPCNT = (value & 0xFFF7); }
bool change = (0 != ((DISPCNT ^ value) & 0x80));
bool changeBG = (0 != ((DISPCNT ^ value) & 0x0F00));
u16 changeBGon = ((~DISPCNT) & value) & 0x0F00; // these layers are being activated
DISPCNT = (value & 0xFFF7); // bit 3 can only be accessed by the BIOS to enable GBC mode
UPDATE_REG(0x00, DISPCNT); UPDATE_REG(0x00, DISPCNT);
if (changeBGon) if(changeBGon) {
{ layerEnableDelay = 4;
layerEnableDelay=4;
layerEnable = layerSettings & value & (~changeBGon); layerEnable = layerSettings & value & (~changeBGon);
} } else {
else
layerEnable = layerSettings & value; layerEnable = layerSettings & value;
// CPUUpdateTicks(); // CPUUpdateTicks();
}
windowOn = (layerEnable & 0x6000) ? true : false; windowOn = (layerEnable & 0x6000) ? true : false;
if(change && !((value & 0x80))) { if(change && !((value & 0x80))) {
@ -2390,10 +2393,11 @@ void CPUUpdateRegister(u32 address, u16 value)
} }
CPUUpdateRender(); CPUUpdateRender();
// we only care about changes in BG0-BG3 // we only care about changes in BG0-BG3
if(changeBG) if(changeBG) {
CPUUpdateRenderBuffers(false); CPUUpdateRenderBuffers(false);
} }
break; break;
}
case 0x04: case 0x04:
DISPSTAT = (value & 0xFF38) | (DISPSTAT & 7); DISPSTAT = (value & 0xFF38) | (DISPSTAT & 7);
UPDATE_REG(0x04, DISPSTAT); UPDATE_REG(0x04, DISPSTAT);
@ -2774,7 +2778,7 @@ void CPUUpdateRegister(u32 address, u16 value)
cpuNextEvent = cpuTotalTicks; cpuNextEvent = cpuTotalTicks;
break; break;
case 0x128: case 0x128:
#ifdef LINK_EMULATION #ifdef LINK_EMULATION
if (linkenable) if (linkenable)
{ {
StartLink(value); StartLink(value);
@ -2795,10 +2799,10 @@ void CPUUpdateRegister(u32 address, u16 value)
} }
break; break;
case 0x12a: case 0x12a:
#ifdef LINK_EMULATION #ifdef LINK_EMULATION
if(linkenable && lspeed) if(linkenable && lspeed)
LinkSSend(value); LinkSSend(value);
#endif #endif
{ {
UPDATE_REG(0x134, value); UPDATE_REG(0x134, value);
} }

View File

@ -17,8 +17,8 @@
// along with this program; if not, write to the Free Software Foundation, // along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef VBA_GBAinline_H #ifndef GBAINLINE_H
#define VBA_GBAinline_H #define GBAINLINE_H
#include "../System.h" #include "../System.h"
#include "../Port.h" #include "../Port.h"
@ -139,7 +139,7 @@ static inline u32 CPUReadMemory(u32 address)
return flashRead(address); return flashRead(address);
// default // default
default: default:
unreadable: unreadable:
#ifdef GBA_LOGGING #ifdef GBA_LOGGING
if(systemVerbose & VERBOSE_ILLEGAL_READ) { if(systemVerbose & VERBOSE_ILLEGAL_READ) {
log("Illegal word read: %08x at %08x\n", address, armMode ? log("Illegal word read: %08x at %08x\n", address, armMode ?
@ -278,7 +278,7 @@ static inline u32 CPUReadHalfWord(u32 address)
return flashRead(address); return flashRead(address);
// default // default
default: default:
unreadable: unreadable:
#ifdef GBA_LOGGING #ifdef GBA_LOGGING
if(systemVerbose & VERBOSE_ILLEGAL_READ) { if(systemVerbose & VERBOSE_ILLEGAL_READ) {
log("Illegal halfword read: %08x at %08x\n", address, armMode ? log("Illegal halfword read: %08x at %08x\n", address, armMode ?
@ -374,7 +374,7 @@ static inline u8 CPUReadByte(u32 address)
} }
// default // default
default: default:
unreadable: unreadable:
#ifdef GBA_LOGGING #ifdef GBA_LOGGING
if(systemVerbose & VERBOSE_ILLEGAL_READ) { if(systemVerbose & VERBOSE_ILLEGAL_READ) {
log("Illegal byte read: %08x at %08x\n", address, armMode ? log("Illegal byte read: %08x at %08x\n", address, armMode ?
@ -479,7 +479,7 @@ static inline void CPUWriteMemory(u32 address, u32 value)
} }
// default // default
default: default:
unwritable: unwritable:
#ifdef GBA_LOGGING #ifdef GBA_LOGGING
if(systemVerbose & VERBOSE_ILLEGAL_WRITE) { if(systemVerbose & VERBOSE_ILLEGAL_WRITE) {
log("Illegal word write: %08x to %08x from %08x\n", log("Illegal word write: %08x to %08x from %08x\n",
@ -581,7 +581,7 @@ static inline void CPUWriteHalfWord(u32 address, u16 value)
} }
goto unwritable; goto unwritable;
default: default:
unwritable: unwritable:
#ifdef GBA_LOGGING #ifdef GBA_LOGGING
if(systemVerbose & VERBOSE_ILLEGAL_WRITE) { if(systemVerbose & VERBOSE_ILLEGAL_WRITE) {
log("Illegal halfword write: %04x to %08x from %08x\n", log("Illegal halfword write: %04x to %08x from %08x\n",
@ -616,13 +616,6 @@ static inline void CPUWriteByte(u32 address, u8 b)
case 4: case 4:
if(address < 0x4000400) { if(address < 0x4000400) {
switch(address & 0x3FF) { switch(address & 0x3FF) {
case 0x301:
if(b == 0x80)
stopState = true;
holdState = 1;
holdType = -1;
cpuNextEvent = cpuTotalTicks;
break;
case 0x60: case 0x60:
case 0x61: case 0x61:
case 0x62: case 0x62:
@ -665,15 +658,20 @@ static inline void CPUWriteByte(u32 address, u8 b)
case 0x9f: case 0x9f:
soundEvent(address&0xFF, b); soundEvent(address&0xFF, b);
break; break;
default: case 0x301: // HALTCNT, undocumented
if(address & 1) if(b == 0x80)
CPUUpdateRegister(address & 0x3fe, stopState = true;
((READ16LE(((u16 *)&ioMem[address & 0x3fe]))) holdState = 1;
& 0x00FF) | holdType = -1;
b<<8); cpuNextEvent = cpuTotalTicks;
else break;
CPUUpdateRegister(address & 0x3fe, default: // every other register
((READ16LE(((u16 *)&ioMem[address & 0x3fe])) & 0xFF00) | b)); u32 lowerBits = address & 0x3fe;
if(address & 1) {
CPUUpdateRegister(lowerBits, (READ16LE(&ioMem[lowerBits]) & 0x00FF) | (b << 8));
} else {
CPUUpdateRegister(lowerBits, (READ16LE(&ioMem[lowerBits]) & 0xFF00) | b);
}
} }
break; break;
} else goto unwritable; } else goto unwritable;
@ -722,7 +720,7 @@ static inline void CPUWriteByte(u32 address, u8 b)
} }
// default // default
default: default:
unwritable: unwritable:
#ifdef GBA_LOGGING #ifdef GBA_LOGGING
if(systemVerbose & VERBOSE_ILLEGAL_WRITE) { if(systemVerbose & VERBOSE_ILLEGAL_WRITE) {
log("Illegal byte write: %02x to %08x from %08x\n", log("Illegal byte write: %02x to %08x from %08x\n",
@ -735,4 +733,4 @@ static inline void CPUWriteByte(u32 address, u8 b)
} }
} }
#endif //VBA_GBAinline_H #endif //GBAINLINE_H