card/eeprom/source/main.cpp
#include <nds.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
void pause() {
iprintf("Press start...\n");
while(1) {
scanKeys();
if(keysDown() & KEY_START)
break;
swiWaitForVBlank();
}
scanKeys();
}
int main(void) {
consoleDemoInit();
iprintf("Reading cart info...\n");
static u8 header1[512];
static u8 header2[512];
sysSetBusOwners(true, true);
while(1) {
cardReadHeader(header1);
cardReadHeader(header2);
while(memcmp(header1, header2, 32) != 0) {
iprintf("Please eject & reinsert DS card.\n");
pause();
cardReadHeader(header1);
cardReadHeader(header2);
}
header1[32] = '\0';
int type = cardEepromGetType();
int size = cardEepromGetSize();
iprintf("Game ID: %s\n", header1);
iprintf("EEPROM:\n");
iprintf(" Type: %d\n", type);
iprintf(" Size: %d\n", size);
pause();
static u8 data[512];
cardReadEeprom(0, data, 512, type);
iprintf("First 160 bytes of EEPROM: \n");
for(int y=0; y<20; y++) {
for(int x=0; x<8; x++) {
iprintf("%02x ", data[y*8 + x]);
}
for(int x=0; x<8; x++) {
u8 c = data[y*8 + x];
if(isprint(c))
iprintf("%c", c);
else
iprintf(".");
}
}
iprintf("Insert a new card to read again\n");
pause();
}
return 0;
}