#88739 - king501 - Wed Jun 21, 2006 2:36 pm
I'm trying to learn programming GBA. I don't understand why the first statement is using an deferencing operator while the other ones aren't using any...
Code: |
int main()
{
*(unsigned int*)0x04000000 = 0x0403;
((unsigned short*)0x06000000)[120+80*240] = 0x001F;
((unsigned short*)0x06000000)[136+80*240] = 0x03E0;
((unsigned short*)0x06000000)[120+96*240] = 0x7C00;
while(1);
return 0;
} |
Can someone explain it to me please?
Thanks!
#88740 - Mighty Max - Wed Jun 21, 2006 2:41 pm
The array access is equally to the * with the index 0. For every other value it accesses the memory at base+index*typesize
_________________
GBAMP Multiboot
#88774 - king501 - Wed Jun 21, 2006 4:12 pm
thanks, I don't quite understand yet, but I will try to make other researches...
#88782 - Mr Snowflake - Wed Jun 21, 2006 4:31 pm
When you do:
Code: |
((unsigned short*)0x06000000)[120+80*240] = 0x001F; |
You actually do:
Code: |
*(((unsigned short*)0x06000000) + (120+80*240)) = 0x001F; |
The name of a array (in this case (unsigned short*)0x06000000, from now on I'll just call it myArray) is the a pointer to the address of the first element in that array.
So these two statements give the same memory address:
==
When you do: myArray[10] you go to the 10th element in the array and thus you go sizeof( unsigned short ) * 10 further from the beginning of the array, so you go to *(myArray + 10).
I hope this is somewhat understandable for humans, as I have a hard time getting my message explained, especially in other languages (like English for me).
BTW: If you have GBA specific questions you should ask them on the gba boards.
_________________
http://www.mrsnowflake.be
#88785 - king501 - Wed Jun 21, 2006 4:57 pm
thanks a lot snowflake, yes your information was very helpful and very well explained.
BTW: there aren't any visible GBA boards.
#88787 - Cearn - Wed Jun 21, 2006 5:13 pm
All non-NDS boards are the GBA boards.
Also, uhm, you did notice that what you asked was explained later on the same page, right?
#88790 - Mr Snowflake - Wed Jun 21, 2006 5:23 pm
king501 wrote: |
thanks a lot snowflake, yes your information was very helpful and very well explained.
BTW: there aren't any visible GBA boards. |
I think you should use: http://forum.gbadev.org/index.php
_________________
http://www.mrsnowflake.be
#88951 - king501 - Thu Jun 22, 2006 12:49 pm
thanks a lot guys because your explanations truly helped me!
PS: yeah, sorry I will post in the [coding] section in the future.
#98433 - king501 - Tue Aug 15, 2006 6:12 am
Quote: |
#define REG_DISPCNT *(vu32*)(MEM_IO+0x0000) |
I just noticed it;
REG_DISPCNT isn't supposed to be 16 bit long instead of 32?
#98446 - Cearn - Tue Aug 15, 2006 9:45 am
As the third and fourth bytes of IO-mem don't do anything, it doesn't really matter so you can use interpret it both ways. At least on the GBA; the NDS REG_DISPCNT really does have 32 bits.
#98549 - king501 - Tue Aug 15, 2006 10:14 pm
On gbatek I've seen that 0x04000002 was used for Green Swap. That's why I was asking. But of course, I don't think nobody will ever use it.
#98555 - Cearn - Tue Aug 15, 2006 11:25 pm
You could still use bit 0 of 0400:0002 as a greenswap if you had a 32bit REG_DISPCNT, it'd just be 0x10000 instead of 1. What matters is which numbers make up the contents of memory, not what you use to get there. you may have noticed that some 32bit registers have been split into _L and _H variants; technically it doesn't matter which ones you use as long as the final entries are the same. The same holds for VRAM, OAM, etc.
In principle, it doesn't matter what datatypes you use when imposing the memory maps, although some types are more convenient or faster than others.