Page 1 of 1

Why are the IO registers stored redundantly?

Posted: Mon Aug 17, 2009 4:20 pm
by spacy51

In Globals.cpp, there is "u8 *ioMem = 0;", which should contain all the IO registers, but all the IO registers are declared again seperately in the same file.

 

I can see that whenever a register has to be changed, it looks like this:

 

Code: Select all

DISPCNT = (value & 0xFFF7);
UPDATE_REG(0x00, DISPCNT);

You can replace DISPCNT by any other register. Keep in mind 0x00 is the IO register's offset from 0x04000000 (the IO registers adress in GBA's memory map).

 

 

Here's the definition for UPDATE_REG:

Code: Select all

#define UPDATE_REG(address, value)\
 {\
   WRITE16LE(((u16 *)&ioMem[address]),value);\
 }\

It writes the value to ioMem, certainly a redundancy.

 

Why is it done like that?

Couldn't we delete all the single registers and only use ioMem?

 

 

Proposal:

Code: Select all

#define DISPCNT  ioMem[0x0000]
#define DISPSTAT ioMem[0x0004]
...