#47591 - chishm - Mon Jul 11, 2005 5:00 am
I am working on a small assembly boot loader that should run in either DS or GBA mode. However, I am not sure on the best way to detect DS mode. How would I go about detecting if the DS is running in DS mode in the least amount of code possible, preferably using just one memory read and a compare? This will be done from the ARM7
Are there any memory addresses that contain one definite value in DS mode and another definite value in GBA mode?
Also, on a related topic, what happens if I try to use GBA IWRAM, ie memory starting at 0x0300:0000?
Thanks in advance for any replies.
EDIT: Solved, see below.
Last edited by chishm on Thu Jul 21, 2005 8:29 am; edited 1 time in total
#47593 - doublec - Mon Jul 11, 2005 5:22 am
Does this help? From http://www.bottledlight.com/ds/index.php/Main/GBAMode
Quote: |
The GBA mode BIOS is virtually identical (1 bit differs in an unused region at the end), and can be dumped in the same fashion. You *can* detect if you are running on a DS from a GBA flash cart.
Code Snippet:
uint32 getChecksum(void) {
// Figure out what we're running on
uint32 result;
asm volatile("swi 0x0D\n"
"mov r0, %0\n"
: "=r"(result) : : "r1", "r2", "r3"
);
return result;
}
...
value = getChecksum();
if (value == 0xBAAE1880)
drawString(0, 19, "Nintendo DS detected");
else if (value == 0xBAAE187F)
drawString(0, 19, "Nintendo GBA detected");
else
drawString(0, 19, "Emulator detected"); |
#47594 - Dwedit - Mon Jul 11, 2005 5:25 am
No. That detects a Nintendo DS gba, not DS mode.
The simplest way I can immediatly think of is two writes to RAM to test if they are mirrored or not, but that would take at least 6 instructions.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#47595 - tepples - Mon Jul 11, 2005 5:27 am
To distinguish a Nintendo DS in DS mode (e.g. *Me) from a GBA or a Nintendo DS in GBA mode:
#define EWRAM ((char *)0x02000000)
#define VCOUNT (*(volatile u16 *)0x04000008)
#define XKEYS (*(volatile u16 *)0x04000136)
#define ROM (*(u8 *)0x08000000)
#define ROM2 (*(u8 *)0x0A000000)
DS mode: EWRAM repeats at 4 MiB.
GBA mode: EWRAM repeats at 0.25 MiB.
DS mode: ROM2 points to Game Pak SRAM or flash.
GBA mode: ROM2 points to the same data as ROM with different wait state settings.
DS mode: If you spin on VCOUNT for 16.7 ms, it goes up to 262.
GBA mode: If you spin on VCOUNT for 16.7 ms, it goes to 227 then to 0.
DS mode: XKEYS will have at least some bits set.
GBA mode: Nope.
DS mode: Lots of other I/O registers are available. Consult the NDSTech Wiki.
GBA mode: They're hidden.
DS mode: Palette memory and OAM repeat on 2 KB intervals (1 KB for the main screen and 1 KB for the sub screen).
GBA mode: Palette memory and OAM repeat on 1 KB intervals.
Also try the SP register. Where does that point by default?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#47607 - chishm - Mon Jul 11, 2005 10:02 am
Thanks Tepples. I think that ROM2 is probably the best way to go, as the GBAMP doesn't have any game save memory. I was thinking about using XKEYS, but then realised there is the (very remote) chance that someone will push both X and Y and touch the touch screen. At least one byte in ROM2 will have a definite, differing value depending on the mode (I should hope).
Also, back to the other question, what happens to the addresses used by GBA IWRAM in DS mode? It would be nice if I could use IWRAM in both modes with accesses to the same address, but from what I have been reading it doesn't look likely. Unfortunately the DS docs that I have read (the Wiki and DSTek) don't mention this. I can't test this myself, so if someone is able to, that would be great. Thanks.
#47639 - Dwedit - Mon Jul 11, 2005 5:33 pm
Wouldn't XKEYS be zero only if X,Y,and touchscreen are pressed, AND the system is closed?
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#47658 - chishm - Tue Jul 12, 2005 12:38 am
Dwedit wrote: |
Wouldn't XKEYS be zero only if X,Y,and touchscreen are pressed, AND the system is closed? |
According to DSTek, the screen status bit is 0 when the screens are open.
Code: |
Bit Name Expl.
0 Button X 0=pressed, 1=released
1 Button Y 0=pressed, 1=released
6 Touchpad 0=pressed, 1=released
7 Screens status 0=Screens open, 1=folded |
#47659 - Dwedit - Tue Jul 12, 2005 12:52 am
Ah... backwards and unintuitive.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#48625 - chishm - Thu Jul 21, 2005 8:31 am
I have tried the XKEYS method, and so far it has worked. Although I have tried various combinations of X, Y, touch and hinge, I still can't make it fail. Keep in mind that this is done at startup, so it may not work after a certain delay.