Why(technically) don't some menus load commercial ROMs

Discussion in 'NDS - Emulation and Homebrew' started by ethanpet113, Oct 9, 2012.

  1. ethanpet113
    OP

    Newcomer ethanpet113 Member

    Joined:
    Sep 13, 2009
    Messages:
    12
    Country:
    Canada
    I know why legally you wouldn't want to load a commercial NDS ROM in your loader, but is there a reason you would as a developper be technically unable to load the commercial rom? I have some issues(mainly cosmetic, some functional) with my R4 clone, I have a real R4 that works reasonably well, but is of course limited to 2GB. So I was thining I could slap together a quick menu using libnds, but then I don't know if I have to decrypt something, or patch something to bypass copy protection and what to jump to.

    If I had to guess I would say


    Code:
    #include 
    #include 
    #include 
    
    //do fat access to get fd
    //seek to arm9 rom offset put to romAddr
    void* romAddr;
    memcpy(romAddr, arm9Destination, arm9BinarySize);
    
    arm9executeAddress();
    But that feels to simple, any thoughts or example code from programmers. Disclaimer: I am trying to provide a loader for both hombrew and my backups for cartridges I actually purchased, I am in no way endorsing piracy.
     
  2. Rydian

    Member Rydian Resident Furvertâ„¢

    Joined:
    Feb 4, 2010
    Messages:
    27,883
    Location:
    Cave Entrance, Watching Cyan Write Letters
    Country:
    United States
    Games have anti-piracy, so if you make a menu that loads commercial ROMs (such as the main menu of most flash carts), it'd be expected that you update constantly to load new games. New games with new types of AP come out, and it can be a hassle to have to dissect each new game with AP, find out what's tripping up the detection, and fake/patch that.

    EDIT: Misread, obviously.
     
  3. Ron

    Member Ron somehow a weeb now.

    Joined:
    Dec 10, 2009
    Messages:
    2,837
    Location:
    here
    Country:
    Canada
    What about games that don't have AP, for example, Electroplankton?
     
  4. Foxi4

    Reporter Foxi4 On the hunt...

    pip
    Joined:
    Sep 13, 2009
    Messages:
    22,736
    Location:
    Gaming Grotto
    Country:
    Poland
    That does indeed feel "simple". There's a bit more to launching a binary on a DS than that, I'm afraid.

    http://devkitpro.git.sourceforge.net/git/gitweb.cgi?p=devkitpro/hbmenu;a=tree;f=source;h=b5fbb9eed7b6d6636f38ff5e129440be5d60e3a5;hb=HEAD

    Here's the source code for Homebrew Loader - devkitPro's loader of choice. Now, it doesn't load commercial ROM's, but it does show the basic principles of how loading works.
     
  5. qaz00

    Newcomer qaz00 ORG 0x0

    Joined:
    Dec 31, 2010
    Messages:
    40
    Country:
    United Kingdom
    As far as I know, most DS homebrew is loaded fully into RAM in a similar way to your example, and then it can load any additional data via FS access/DLDI; However a real DS game cannot be DLDI patched, as it is not designed to be played from a device with a filesystem - so the game has to be patched to send the correct commands to read from the SD card instead of the usual commands to read from a retail cartridge OR the flashcart has to set itself up on load in such a way that the normal commands are translated inside the flashcart to SD card reads.

    Then you have to think about savegames - some (early) flashcarts had the same EEPROM/Flash chip as a real cartridge, and it was copied to the SD on next boot. More modern ones translate the EEPROM command into the appropriate SD command internally.

    Now obviously any loader that is not patching the rom (using the 2nd method) needs to be able to set the flashcart hardware up correctly - so the code will be different for each type of flashcart.
     
  6. Dirbaio

    Member Dirbaio GBAtemp Regular

    Joined:
    Sep 26, 2010
    Messages:
    158
    Location:
    Spain
    Country:
    Spain
    Coding a loader is verry tricky. I had some very bad experiences some time ago when I wanted to hack NSMB to be able to "launch" a homebrew.
    The reason why a code like yours wouldn't work is that the loaded ROM's ARM9 binary would go into the same place that the loader code is. So you have to put the loader's code somewhere else. Some loaders put the code in the high part of RAM, some others load the code in VRAM (I didn't even know this was possible, lol). For example Wood loads a tiny loader at the high part of RAM (0x023xxxxx up), and that tiny loader loads the ROM. It's all very tricky.

    And also you gotta load the ARM7 binary too. Commercial games have ARM7 loaded into VRAM but homebrew games load their ARM7 binary directly to the ARM7 WRAM, which is only accessible from ARM7. So the ARM7 binary has to be loaded from ARM7. And ARM7 has no access to FAT. So this becomes a mess really fast, with complex IPC shit and all. It becomes very very difficult to debug too. It's a headache.

    About your initial question: No, there's no technical reasons a loader can't load commercial ROMs. Well, there's one. Homebrew, as long as it has DLDI, it works on any card. But commercial ROMs use another method to read the game data from the card. Flashcards need to be configured to map these ROM reads into the SD. And the method is different for different cards and all. And there's also configuring the save. And there's very little info on it on the net :P

    So unless you're 100% sure you want to make a loader, I'd say don't even try, because it's going to be a headache until you get even homebrew ROMs booting.
     

Share This Page