gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Guitar Hero DS Controller support in hombrew

#159148 - knight0fdragon - Thu Jun 26, 2008 5:06 am

Many thanks to davr for refreshing me on how SRAM works with DS


Here is the code to use the guitar hero controller for your games.

The software is provided as-is, and I can not be held responsible if anything happens to your DS

Code:
/*---------------------------------------------------------------------------------

   $Id: main.c,v 1.5 2007/10/23 00:46:29 wntrmute Exp $

   Simple console print demo
   -- dovoto

---------------------------------------------------------------------------------*/
#include <nds.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define SRAM_WAIT_18 0x03
#define GREEN   0x40
#define RED     0x20
#define YELLOW  0x10
#define BLUE    0x08

//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------

   irqInit();
   irqEnable(IRQ_VBLANK);
 
   videoSetMode(0);   //not using the main screen
   videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);   //sub bg 0 will be used to print text
   
  vramSetBankC(VRAM_C_SUB_BG);

   SUB_BG0_CR = BG_MAP_BASE(31);

   BG_PALETTE_SUB[255] = RGB15(31,31,31);   //by default font will be rendered with color 255

   //consoleInit() is a lot more flexible but this gets you up and running quick
   consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);

   iprintf("\tSwap carts if need be and press start");
  while(!(keysDown() & KEY_START))
  {
    scanKeys();
  }

//sets up ARM9 to read SLOT 2, and sets up SRAM
  sysSetBusOwners(BUS_OWNER_ARM9, BUS_OWNER_ARM9);
  REG_EXMEMCNT &= ~0x0880;

  REG_EXMEMCNT |= SRAM_WAIT_18;

  char fret[5];
  memset(fret,0,5);
//Read the buttons off the fret
 while(1)
  {
    memset(fret,' ',4);  //clears the fret buffer
    //below here we will check to see if the cart exists
    if((GBAROM[0xFFFF]) == CHECKCART)
    {
      //if it does, process the buttons
      if(((~SRAM[0x0]) & GREEN))
        fret[3] = 'G';
   
      if(((~SRAM[0x0]) & RED))
        fret[2] = 'R';
   
      if(((~SRAM[0x0]) & YELLOW))
        fret[1] = 'Y';
   
      if(((~SRAM[0x0]) & BLUE))
        fret[0] = 'B';
   
    iprintf("\x1b[6;5HFret         \n");
    iprintf("\x1b[6;5HFret %s\n",fret);
    }
    else
     //show that device is not found
      iprintf("\x1b[6;5HNOT FOUND\n",fret);
   
    iprintf("\x1b[16;5HROM(0000) %x",GBAROM[0x0]);
    iprintf("\x1b[17;5HROM(FFFF) %x",GBAROM[0xFFFF]);
  }
  return 0;
}



edit:
changed 0x600 to 0x0, as its a waste in power


not tested, but to detect if the grip exists, poll
GBAROM[0] for 0xF9FF

thanks to grizzlyadams for pointing this stuff out

to get a picture of the board used on the grip, grap it here http://i31.tinypic.com/15388jq.jpg


more edit

added check cart code, now everythign should be in order

used GBAROM[0xFFFF] and searched for the value of 0xF9FF

if you decide to use any of this code, please pass along some credit to davr Grizzleyadams and me for providing this source
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206


Last edited by knight0fdragon on Thu Jun 26, 2008 6:48 am; edited 2 times in total

#159151 - GrizzlyAdams - Thu Jun 26, 2008 6:13 am

Basically at first glance we thought the two resistors were providing power thru the buttons, but they are actually for presence detection instead.

Take care when designing for the grip, reading / writing certain addresses or values can potentially cause damage to the ds hardware (I'm not entirely sure about the gba port logic, so better safe than sorry)

Just make sure you don't read or write to GBAROM[] addresses that have bits A19-A22 set, and don't write values to SRAM[] and you should be safe.

#159156 - Dark Knight ez - Thu Jun 26, 2008 9:48 am

Nice. Seems to be really easy to get going in one's code. :)
_________________
AmplituDS website