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 > help with programming, im new to c++ and ndslib

#76931 - GizmoTheGreen - Sun Mar 26, 2006 12:41 pm

hello, i am 15 years old, and new to DS programming, i know a little of visual basic and ruby.

i made a basic app called DSLasergun

Code:
#include "nds.h"
#include <nds/bios.h>
#include <nds/system.h>
#include <nds/arm9/console.h>   
#include <nds/arm9/sound.h>      
#include <stdio.h>

#include "blaster_raw.h"
#include "saberoff_raw.h"

int main(void) {

   powerON( POWER_LCD | POWER_2D_B );

   irqInit();
   irqSet(IRQ_VBLANK, NULL);
   irqEnable(IRQ_VBLANK);

   videoSetMode(0);   
   videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);   
   vramSetBankC(VRAM_C_SUB_BG);

   SUB_BG0_CR = BG_MAP_BASE(31);
   
   BG_PALETTE_SUB[255] = RGB15(0,25,0);
   
   consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);
   iprintf("\n DS Lasergun \n\n Use L & R to shoot\n depending on preference...\n\n Press Select  to swap screens\n\n\n\n Coded by GizmoTheGreen\n  ");

   setGenericSound(   11025,   
                  127,   
                  64,      
                  1 );   

   TransferSoundData blaster = {
      blaster_raw,      
      blaster_raw_size,   
      11025,            
      127,            
      64,               
      1                
   };

   while(1) {

      swiWaitForVBlank();
      scanKeys();

      //s16 userName = PersonalData[name0, name1, name2,name3,name4,name5,name6,name7,name8,name9]
      u16 keys = keysDown();
      u16 up = keysUp();

      if ( keys & KEY_R) playSound(&blaster), iprintf("\n Right handed?");
   
      if ( keys & KEY_L) playSound(&blaster), iprintf("\n Left  handed?");

      if ( keys & KEY_LID) playGenericSound(saberoff_raw, saberoff_raw_size), iprintf("\n Closed");
   
      if ( up & KEY_LID) playGenericSound(saberoff_raw, saberoff_raw_size), iprintf("\n Opened");

      if ( keys & KEY_A) iprintf("\n What? This button\n does nothin'... yet...");
   
        if ( keys & KEY_START) iprintf("\n Restarting...");

      if ( up & KEY_START) swiSoftReset();

      if ( keys & KEY_SELECT) lcdSwap();
   }
   return 0;
}


EDIT: it works in dualis and on hardware, though im borrowing friends m3, as i dont have my own, and the purpose of this app, is to pretend your DS i a gun, we love to use it on the breaks in school :)

now, can anyone help me shut of backlight while folded?
also go back to M3 menu by pressing start?

thanks in advance
_________________
Starter of the project TrueLoveDS :D
Will you find True Love?

#76999 - melw - Mon Mar 27, 2006 9:10 am

For turning off the backlight you can check for example Moonshell sources (http://mdxonline.dyndns.org/archives/nds/), seems like he has done even the DS Lite brightness settings recently. It's on the ARM7 side, using his modified IPC implementation.

What comes to going back to M3 menu, no idea if it can be done. The best solution I've succeeded doing is shutting down the program shut downs the DS...

PS. Be sure not to shoot the teacher if you want to keep your NDS intact :).

#77013 - GizmoTheGreen - Mon Mar 27, 2006 2:03 pm

Quote:
PS. Be sure not to shoot the teacher if you want to keep your NDS intact :).


:P, sure, i wont.

EDIT: when i try to compile it gives me these errors...
Code:
c:/devkitPro/examples/nds/sound/DSLasergun/source/a7sleep.cpp: In function 'u8 PM_GetRegister(int)':
c:/devkitPro/examples/nds/sound/DSLasergun/source/a7sleep.cpp:34: error: 'SerialWaitBusy' was not declared in this scope
c:/devkitPro/examples/nds/sound/DSLasergun/source/a7sleep.cpp:36: error: 'REG_SPICNT' was not declared in this scope
c:/devkitPro/examples/nds/sound/DSLasergun/source/a7sleep.cpp:36: error: 'SPI_ENABLE' was not declared in this scope
c:/devkitPro/examples/nds/sound/DSLasergun/source/a7sleep.cpp:36: error: 'SPI_DEVICE_POWER' was not declared in this scope


moved the code to new bios file(made copy of old one)
this kina fixed it except
Code:
c:/devkitPro/examples/nds/sound/DSLasergun/source/DSLasergun.c:58: undefined reference to `a7sleep'
c:/devkitPro/examples/nds/sound/DSLasergun/source/DSLasergun.c:66: undefined reference to `a7poff'


what to do?

thanks for the help, i really appreciate it, i dont have much time to study c++ as i have important school now, still i want to keep the DS programming as a hobby, so ill just continue posting here for help :)

thanks, also thanks in advance for future help
_________________
Starter of the project TrueLoveDS :D
Will you find True Love?