void CGbaLoader::LoadBorder(void)
{
  videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);
  videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE);
  vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_MAIN_BG_0x06020000, VRAM_C_SUB_BG_0x06200000, VRAM_D_LCD);

  // for the main screen
  REG_BG3CNT = BG_BMP16_256x256 | BG_BMP_BASE(0) | BG_WRAP_OFF;
  REG_BG3PA = 1 << 8; //scale x
  REG_BG3PB = 0; //rotation x
  REG_BG3PC = 0; //rotation y
  REG_BG3PD = 1 << 8; //scale y
  REG_BG3X = 0; //translation x
  REG_BG3Y = 0; //translation y

  memset((void*)BG_BMP_RAM(0),0,0x18000);
  memset((void*)BG_BMP_RAM(8),0,0x18000);

  cBMP15 frameBMP=createBMP15FromFile(SFN_GBAFRAME);
  if(frameBMP.valid()&&frameBMP.width()==SCREEN_WIDTH&&frameBMP.height()==SCREEN_HEIGHT)
  {
    DC_FlushRange(frameBMP.buffer(),SCREEN_WIDTH*SCREEN_HEIGHT*2);
    dmaCopy(frameBMP.buffer(),(void*)BG_BMP_RAM(0),SCREEN_WIDTH*SCREEN_HEIGHT*2);
    dmaCopy(frameBMP.buffer(),(void*)BG_BMP_RAM(8),SCREEN_WIDTH*SCREEN_HEIGHT*2);
  }
}
void init_doorminigame()
{
  videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE | DISPLAY_BG2_ACTIVE);  

  vramSetMainBanks(VRAM_A_MAIN_BG_0x6000000, VRAM_B_MAIN_SPRITE, //VRAM_B_MAIN_BG_0x6020000,
                   VRAM_C_SUB_BG, VRAM_D_MAIN_BG_0x6020000);

  SUB_BG2_CR = BG_BMP8_256x256 | BG_BMP_BASE(4);
  SUB_BG3_CR = BG_BMP8_256x256;

  SUB_BG3_XDX = 1 << 8;
  SUB_BG3_XDY = 0;
  SUB_BG3_YDX = 0;
  SUB_BG3_YDY = 1 << 8;

  SUB_BG2_XDX = 1 << 8;
  SUB_BG2_XDY = 0;
  SUB_BG2_YDX = 0;
  SUB_BG2_YDY = 1 << 8;

  SUB_BG3_CX = 0;
  SUB_BG3_CY = 0; //32 << 8;

  SUB_BG2_CX = 0;//2000;
  SUB_BG2_CY = 0;//2000; //32 << 8;

  for(int i = 0; i < 256; ++i)
    BG_PALETTE_SUB[i] = ((u16*)doorbg_pal_bin)[i];

  for(int i = 0; i < 256*256/2; ++i)
    ((u16*)BG_BMP_RAM_SUB(0))[i] = ((u16*)doorbg_img_bin)[i];

  for(int i = 0; i < 256*256/2; ++i)
    ((u16*)BG_BMP_RAM_SUB(4))[i] = ((u16*)doorfg_img_bin)[i];
}
Beispiel #3
0
void gbaFrame(void)
{
  u16* frame=NULL;
  cBMP15 frameBMP=createBMP15FromFile("/GBA/gbaframe.bmp");
  if(frameBMP.valid()&&frameBMP.width()==SCREEN_WIDTH&&frameBMP.height()==SCREEN_HEIGHT)
  {
    frame=(u16*)malloc(SCREEN_WIDTH*SCREEN_HEIGHT*2);
    memcpy(frame,frameBMP.buffer(),SCREEN_WIDTH*SCREEN_HEIGHT*2); //tricky thing
  }

  videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);
  videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE);
  vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_MAIN_BG_0x06020000, VRAM_C_SUB_BG_0x06200000, VRAM_D_LCD);

  // for the main screen
  BG3_CR = BG_BMP16_256x256 | BG_BMP_BASE(0) | BG_WRAP_OFF;
  BG3_XDX = 1 << 8; //scale x
  BG3_XDY = 0; //rotation x
  BG3_YDX = 0; //rotation y
  BG3_YDY = 1 << 8; //scale y
  BG3_CX = 0; //translation x
  BG3_CY = 0; //translation y

  if(frame)
  {
    dmaCopy(frame,(void*)BG_BMP_RAM(0),SCREEN_WIDTH*SCREEN_HEIGHT*2);
    dmaCopy(frame,(void*)BG_BMP_RAM(8),SCREEN_WIDTH*SCREEN_HEIGHT*2);
    free(frame);
  }
  else
  {
    memset((void*)BG_BMP_RAM(0),0,0x18000);
    memset((void*)BG_BMP_RAM(8),0,0x18000);
  }
}
Beispiel #4
0
void glDefaultMemorySetting(void)
{
  videoSetMode(MODE_5_2D | DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_2D | DISPLAY_SPR_2D_BMP_256);
  videoSetModeSub(MODE_2_2D | DISPLAY_BG2_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_2D | DISPLAY_SPR_2D_BMP_256);
//  videoSetModeSub(MODE_2_2D | DISPLAY_BG2_ACTIVE | DISPLAY_SPR_2D | DISPLAY_SPR_2D_BMP_256);
  
  vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_MAIN_SPRITE_0x06400000, VRAM_C_MAIN_BG_0x06020000,VRAM_D_SUB_SPRITE);
  vramSetBankE(VRAM_E_LCD);
  vramSetBankF(VRAM_F_LCD);
  vramSetBankG(VRAM_G_LCD);
  vramSetBankH(VRAM_H_SUB_BG);
  vramSetBankI(VRAM_I_LCD);
}
Beispiel #5
0
void PA_Init16bitDblBuffer(u8 screen, u8 bg_priority){

	PA_Default16bitInit(screen, bg_priority);

	DMA_Copy(Blank, (0x06000000 + (0x200000 *  screen)), 256*384, DMA_16NOW);
	PA_DrawBg[screen] =  (u16*)(0x06000000 + (0x200000 *  screen) + 192 * 512);
	PA_DrawBg32[screen] = (u32*)PA_DrawBg[screen];
		
	pa16bitbuffer[screen] = 0; // First buffer...
	charsetstart[screen] = 0; // On se réserve la moitié de la mémoire...

	_REG16(REG_BGCNT(screen, 3)) = bg_priority | BG_BMP16_256x256 | BG_BMP_BASE(0);
	PA_SetDrawSize(screen, 1);
	vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000,VRAM_B_MAIN_BG_0x06020000,VRAM_C_SUB_BG,VRAM_D_SUB_SPRITE);
}
Beispiel #6
0
void ResetVideo()
{
	// turn off video
	videoSetMode(0);
	videoSetModeSub(0);
	
	// zero out video memory
	vramSetMainBanks(
		VRAM_A_LCD,
		VRAM_B_LCD,
		VRAM_C_LCD,
		VRAM_D_LCD);
	u32* ptr = (u32*)0x6800000;
	while(ptr < (u32*)0x687FFFF)
	{
		*ptr++ = 0;
	}
}
Beispiel #7
0
void gamestate::videoInit() {
    powerOn(POWER_ALL_2D); //Turn on the 2D graphics core.

    lcdMainOnBottom(); // Place the main screen on the bottom physical screen

    /* Configure the VRAM and background control registers. */
    // This stuff is copied from pataters tutorial (because it works... 0o)
    /*
     * Map VRAM to display a background on the main and sub screens.
     *
     * The vramSetMainBanks function takes four arguments, one for each of the
     * major VRAM banks. We can use it as shorthand for assigning values to
     * each of the VRAM bank's control registers.
     *
     * We map  banks A and B to main screen background memory. This gives us
     * 256KB, which is a healty amount for 16-bit graphics.
     *
     * We map bank C to sub screen background memory.
     *
     * We map bank D to LCD. This setting is generally used for when we aren't
     * using a particular bank.
     *
     * We map bank E to main screen sprite memory (aka object memory).
     */
    vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000,
                     VRAM_B_MAIN_BG_0x06020000,
                     VRAM_C_SUB_BG_0x06200000,
                     VRAM_D_LCD);

    vramSetBankE(VRAM_E_MAIN_SPRITE);

    /* Set the video mode on the main screen. */
    videoSetMode(MODE_5_2D | // Set the graphics mode to Mode 5
                 DISPLAY_BG2_ACTIVE |
                 DISPLAY_BG3_ACTIVE | // Enable BG3 for display
                 DISPLAY_SPR_ACTIVE | // Enable sprites for display
                 DISPLAY_SPR_1D );    // Enable 1D tiled sprites

    /* Set the video mode on the sub screen. */
    videoSetModeSub(MODE_5_2D | // Set the graphics mode to Mode 5
                    DISPLAY_BG3_ACTIVE); // Enable BG3 for display
    // Sets background registers
    consoleDemoInit(); // Need this for debug-output (iprintf)
}
Beispiel #8
0
void Render::InitVideo()
{
    /*
     *  Map VRAM to display a background on the main and sub screens.
     * 
     *  The vramSetMainBanks function takes four arguments, one for each of the
     *  major VRAM banks. We can use it as shorthand for assigning values to
     *  each of the VRAM bank's control registers.
     *
     *  We map banks A and B to main screen  background memory. This gives us
     *  256KB, which is a healthy amount for 16-bit graphics.
     *
     *  We map bank C to sub screen background memory.
     *
     *  We map bank D to LCD. This setting is generally used for when we aren't
     *  using a particular bank.
     *
     *  We map bank E to main screen sprite memory (aka object memory).
     */
	 
	 vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000,
                     VRAM_B_MAIN_BG_0x06020000,
                     VRAM_C_SUB_BG_0x06200000,
                     VRAM_D_SUB_SPRITE);

    vramSetBankE(VRAM_E_MAIN_SPRITE);
	vramSetBankF(VRAM_F_MAIN_SPRITE);
	vramSetBankI(VRAM_I_SUB_SPRITE);
	
	/*  Set the video mode on the main screen. */
    videoSetMode(MODE_5_2D | // Set the graphics mode to Mode 5
                 DISPLAY_BG2_ACTIVE | // Enable BG2 for display
                 DISPLAY_BG3_ACTIVE | // Enable BG3 for display
                 DISPLAY_SPR_ACTIVE | // Enable sprites for display
                 DISPLAY_SPR_1D       // Enable 1D tiled sprites
                 );

	//Set the video mode on the sub screen. 
	videoSetModeSub(MODE_5_2D | // Set the graphics mode to Mode 5
                    DISPLAY_BG3_ACTIVE |  // Enable BG3 for display
					DISPLAY_SPR_ACTIVE |  // Enable sprites for display
					DISPLAY_SPR_1D);

}
Beispiel #9
0
void PA_Init2D(void){
	// Turn on the screens and 2D cores and switch to mode 0
	powerON(POWER_ALL);
	//  POWER_CR = POWER_ALL_2D;

	REG_POWERCNT &= ~SWITCH_SCREENS; // on s'assure que l'écran est bien
/*
	VRAM_A_CR=VRAM_ENABLE|VRAM_A_MAIN_BG;
	VRAM_B_CR=VRAM_ENABLE|VRAM_B_MAIN_SPRITE;
	VRAM_C_CR=VRAM_ENABLE|VRAM_C_SUB_BG;
	VRAM_D_CR=VRAM_ENABLE|VRAM_D_SUB_SPRITE; */
    videoSetMode(  MODE_0_2D |
                   DISPLAY_SPR_ACTIVE |    //turn on sprites
                   DISPLAY_SPR_1D |        //this is used when in tile mode
				   DISPLAY_SPR_1D_SIZE_128|
                   DISPLAY_SPR_1D_BMP      //and this in bitmap mode
                    );
	videoSetModeSub(  MODE_0_2D |
                   DISPLAY_SPR_ACTIVE |    //turn on sprites
                   DISPLAY_SPR_1D |        //this is used when in tile mode
				   DISPLAY_SPR_1D_SIZE_128|
                   DISPLAY_SPR_1D_BMP      //and this in bitmap mode
                    );

//	DISPLAY_CR = MODE_0_2D | DISPLAY_SPR_1D_LAYOUT | DISPLAY_SPR_ACTIVE|DISPLAY_SPR_1D_SIZE_128|DISPLAY_SPR_1D_BMP;
//	SUB_DISPLAY_CR = MODE_0_2D | DISPLAY_SPR_1D_LAYOUT | DISPLAY_SPR_ACTIVE|DISPLAY_SPR_1D_SIZE_128|DISPLAY_SPR_1D_BMP;


	vramSetMainBanks(VRAM_A_MAIN_SPRITE,VRAM_B_MAIN_BG_0x06000000,VRAM_C_SUB_BG,VRAM_D_SUB_SPRITE);

	// Sprite inits...
	PA_ResetSpriteSys(); // Init's the sprite system
	PA_InitSpriteExtPal(); // Init's sprite extended palettes

	PA_ResetBgSys();
	PA_InitBgExtPal(); // Init's bg extended palettes


	// VBL Inits
	SpriteVBL = PA_UpdateSpriteVBL;

}
Beispiel #10
0
void hasieratuBideoa() {
    /*  Bi pantailatan irudiak erakutsi ahal izateko memoria mapeatu. */

    vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000,
                     VRAM_B_MAIN_BG_0x06020000,
                     VRAM_C_SUB_BG_0x06200000,
                     VRAM_E_LCD);

    vramSetBankE(VRAM_E_MAIN_SPRITE);
    vramSetBankD(VRAM_D_SUB_SPRITE);

    /*  Pantaila nagusirako bideo modua ezarri */
    videoSetMode(MODE_5_2D | // 5. bideo modua ezarri
                 DISPLAY_BG2_ACTIVE | // 2. fondoa aktibatu
                 DISPLAY_BG3_ACTIVE); // 3. fondoa aktibatu

    /*  2. mailako pantaila bideo modua ezarri */
    videoSetModeSub(MODE_5_2D | // 5. bideo modua ezarri
                    DISPLAY_BG3_ACTIVE); // 3. fondoa aktibatu
}
void init_dialog()
{
  videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);
  videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE);

  vramSetMainBanks(VRAM_A_MAIN_BG_0x6000000, VRAM_B_MAIN_SPRITE, //VRAM_B_MAIN_BG_0x6020000,
                   VRAM_C_SUB_BG, VRAM_D_MAIN_BG_0x6020000);

  BG3_CR = BG_BMP8_256x256;
  SUB_BG3_CR = BG_BMP8_256x256;

  BG3_XDX = 1 << 8;
  BG3_XDY = 0;
  BG3_YDX = 0;
  BG3_YDY = 1 << 8;

  BG3_CX = 0;
  BG3_CY = 0; //32 << 8;


  SUB_BG3_XDX = 1 << 8;
  SUB_BG3_XDY = 0;
  SUB_BG3_YDX = 0;
  SUB_BG3_YDY = 1 << 8;

  SUB_BG3_CX = 0;
  SUB_BG3_CY = 0; //32 << 8;


  for(int i = 0; i < 256; ++i)
    BG_PALETTE_SUB[i] = ((u16*)dialog_subscreen_pal_bin)[i];
  
  for(int i = 0; i < 256; ++i)
    BG_PALETTE[i] = ((u16*)dialog_topscreen_pal_bin)[i];

  for(int i = 0; i < 256*256/2; ++i)
    ((u16*)BG_BMP_RAM(0))[i] = ((u16*)dialog_topscreen_img_bin)[i];

  for(int i = 0; i < 256*256/2; ++i)
    ((u16*)BG_BMP_RAM_SUB(0))[i] = ((u16*)dialog_subscreen_img_bin)[i];
}
Beispiel #12
0
SDL_Surface *NDS_SetVideoMode(_THIS, SDL_Surface *current,
                              int width, int height, int bpp, Uint32 flags)
{
    Uint32 Rmask, Gmask, Bmask, Amask;

    //if (width > 1024 || height > 512 || bpp > 16)
    //      return NULL;

    if (bpp > 8) {
        bpp = 16;
        Rmask = 0x0000001F;
        Gmask = 0x000003E0;
        Bmask = 0x00007C00;
        Amask = 0x00008000;

        videoSetMode(MODE_5_2D| DISPLAY_BG2_ACTIVE);

        vramSetMainBanks(VRAM_A_MAIN_BG,VRAM_B_MAIN_BG,VRAM_C_MAIN_BG,VRAM_D_MAIN_BG);

        BG2_CR = BG_BMP16_512x512;
        BG2_XDX = ((width / 256) << 8) | (width % 256) ;
        BG2_XDY = 0;
        BG2_YDX = 0;
        BG2_YDY = ((height / 192) << 8) | ((height % 192) + (height % 192) / 3) ;
        BG2_CX = 0;
        BG2_CY = 0;
        //        for (i = 0;i<256*192;i++)
        //              frontBuffer[i] = RGB15(31,0,0)|BIT(15);
    } else if (bpp <= 8) {
        bpp = 8;
        Rmask = 0x00000000;
        Gmask = 0x00000000;
        Bmask = 0x00000000;
        BG2_CR = BG_BMP8_1024x512;
        BG2_XDX = ((width / 256) << 8) | (width % 256) ;
        BG2_XDY = 0;
        BG2_YDX = 0;
        BG2_YDY = ((height / 192) << 8) | ((height % 192) + (height % 192) / 3) ;

    } else if (bpp < 15) bpp = 15;

    if (width <= 256) width = 256;
    else if (width < 256) width = 256;

    if (height <= 192) height = 192;
    else if (height < 192) height = 192;

    if (bpp == 8) {
        if (width < 256) width = 256;
        if (height < 192) height = 192;
        this->hidden->ndsmode = 4;
    }

    if (bpp==15) {
        if (width < 256) this->hidden->ndsmode = 5;
        else this->hidden->ndsmode = 3;
    }

    this->hidden->buffer = frontBuffer;//NDS_VRAM_BASE;

    //NDS_DISPCNT = NDS_DISP_MODE(this->hidden->ndsmode) | NDS_DISP_BG2;

    //fprintf(stderr,"Setting mode %dx%d (ndsmode %d)\n", width, height,this->hidden->ndsmode);

    // FIXME: How do I tell that 15 bits mode is 555?

    SDL_memset(this->hidden->buffer, 0,
               1024 * 512 *
               (this->hidden->ndsmode == 4 || this->hidden->ndsmode == 5 ? 2 : 1) * ((bpp + 7) / 8));

    /* Allocate the new pixel format for the screen */
    if (!SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, Amask)) {
        this->hidden->buffer = NULL;
        SDL_SetError("Couldn't allocate new pixel format for requested mode");
        return NULL;
    }

    /* Set up the new mode framebuffer */
    current->flags = flags | SDL_FULLSCREEN | SDL_HWSURFACE | (this->hidden->ndsmode > 0 ? SDL_DOUBLEBUF : 0);
    this->hidden->w = current->w = width;
    this->hidden->h = current->h = height;
    current->pixels = frontBuffer;

    if (flags & SDL_DOUBLEBUF) {
        this->hidden->secondbufferallocd = 1;
        backBuffer = (u16*)SDL_malloc(1024*512*2);
        current->pixels = backBuffer;
    }

    if (bpp == 8)
        current->pitch = 1024;
    else
        current->pitch = 512*2;

    /* We're done */
    return current;
}
Beispiel #13
0
int NDS_VideoInit(_THIS, SDL_PixelFormat *vformat)
{
    //printf("WARNING: You are using the SDL NDS video driver!\n");

    /* Determine the screen depth (use default 8-bit depth) */
    /* we change this during the SDL_SetVideoMode implementation... */
    vformat->BitsPerPixel = 16;     // mode 3
    vformat->BytesPerPixel = 2;
    vformat->Rmask = 0x0000f800;
    vformat->Gmask = 0x000007e0;
    vformat->Bmask = 0x0000001f;
    powerON(POWER_ALL);
    irqInit();
    irqSet(IRQ_VBLANK, on_irq_vblank);
    irqEnable(IRQ_VBLANK);

    //set the mode for 2 text layers and two extended background layers
    //videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);
    videoSetMode(MODE_6_2D | DISPLAY_BG2_ACTIVE);

    //set the sub background up for text display (we could just print to one
    //of the main display text backgrounds just as easily
    videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); //sub bg 0 will be used to print text

    //set the first two banks as background memory and the third as sub background memory
    //D is not used..if you need a bigger background then you will need to map
    //more vram banks consecutivly (VRAM A-D are all 0x20000 bytes in size)
    //vramSetMainBanks(VRAM_A_MAIN_BG_0x6000000, VRAM_B_MAIN_BG_0x6020000,VRAM_C_SUB_BG , VRAM_D_LCD);
    vramSetMainBanks(VRAM_A_MAIN_BG,VRAM_B_MAIN_BG,VRAM_C_MAIN_BG,VRAM_D_MAIN_BG);
    //vramSetBankA(VRAM_A_MAIN_BG);
    //vramSetBankB(VRAM_B_MAIN_BG);
    //vramSetBankC(VRAM_C_MAIN_BG);
    //vramSetBankD(VRAM_D_MAIN_BG);
    //vramSetBankE(VRAM_E_MAIN_BG);
    //vramSetBankF(VRAM_F_MAIN_BG);
    //vramSetBankG(VRAM_G_MAIN_BG);
    vramSetBankH(VRAM_H_SUB_BG);
    vramSetBankI(VRAM_I_LCD);

    ////////////////set up text background for text/////////////////////
    SUB_BG0_CR = BG_MAP_BASE(8);

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

    //BG3_CR = BG_BMP16_512x512;

    //these are rotation backgrounds so you must set the rotation attributes:
    //these are fixed point numbers with the low 8 bits the fractional part
    //this basicaly gives it a 1:1 translation in x and y so you get a nice flat bitmap
    /*  BG3_XDX = 1<<8;
        BG3_XDY = 0;
        BG3_YDX = 0;
        BG3_YDY = 1<<8;
        //our bitmap looks a bit better if we center it so scroll down (256 - 192) / 2
        BG3_CX = 0;
        BG3_CY = 0;
    */
    //consoleInit() is a lot more flexible but this gets you up and running quick
    consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(8), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);


    frontBuffer =(u16*)(0x06000000);
    //backBuffer =(u16*)(0x06000000 + 1024 * 512*2);

    //lcdSwap();
    /* We're done! */
    return 0;
}
Beispiel #14
0
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
	int min_x  = 4096 , min_y  = 4096, max_x  = 0, max_y   = 0;
	int min_px = 4096 , min_py = 4096, max_px = 0 , max_py = 0;
	touchPosition touch;

	// put the main screen on the bottom lcd
	lcdMainOnBottom();

	initOAM();
    //enable vram and map it to the right places
    vramSetMainBanks(   VRAM_A_MAIN_SPRITE,        //A and B maped consecutively as sprite memory
                        VRAM_B_MAIN_SPRITE,        //this gives us 256KB which is the max
                        VRAM_C_MAIN_BG_0x06000000,  //map C to background memory
                        VRAM_D_LCD                 //not using D
                        ); 
   
   //set the video mode
    videoSetMode(  MODE_0_2D | 
                   DISPLAY_SPR_ACTIVE |		//turn on sprites
                   DISPLAY_BG0_ACTIVE |		//turn on background 0
                   DISPLAY_SPR_1D			//this is used when in tile mode
                    );

	int i;
	
	// Sprite initialisation
	for(i = 0; i < 256; i++)
		SPRITE_PALETTE[i] = ((u16*)ballpalette_bin)[i];

	for(i = 0; i< 32*16; i++)
		SPRITE_GFX[i] = ((u16*)balldata_bin)[i];

 
	consoleInit(0, 0,BgType_Text4bpp, BgSize_T_256x256, 31,0, true, true); 
 
	iprintf("\x1b[4;8HTouch Screen Test");
	iprintf("\x1b[15;4HRight Shoulder toggles");
 
	while(1) {

		swiWaitForVBlank();
		updateOAM();

		// read the button states
		scanKeys();

		// read the touchscreen coordinates
		touchRead(&touch);
		
		int pressed = keysDown();	// buttons pressed this loop
		int held = keysHeld();		// buttons currently held

		// Right Shoulder button toggles the mode
		if ( pressed & KEY_R) TouchType ^= SINGLE;

		iprintf("\x1b[14;4HTouch mode: %s",TouchType==CONTINUOUS?"CONTINUOUS ":"SINGLE SHOT");

		iprintf("\x1b[6;5HTouch x = %04X, %04X\n", touch.rawx, touch.px);
		iprintf("\x1b[7;5HTouch y = %04X, %04X\n", touch.rawy, touch.py);		

		iprintf("\x1b[0;18Hkeys: %08X\n", keysHeld());
		iprintf("\x1b[9;10HFrame %d\n", frame);

		if ( TouchType == SINGLE && !(pressed & KEY_TOUCH) ) continue;

		if ( !(held & KEY_TOUCH) || touch.rawx == 0 || touch.rawy == 0) continue;
		
		iprintf("\x1b[12;12H(%d,%d)      ",touch.px,touch.py);

		if ( touch.rawx > max_x)		max_x = touch.rawx;
		if ( touch.rawy > max_y)		max_y = touch.rawy;
		if ( touch.px > max_px)	max_px = touch.px;
		if ( touch.py > max_py)	max_py = touch.py;

		if ( touch.rawx < min_x)		min_x = touch.rawx;
		if ( touch.rawy < min_y)		min_y = touch.rawy;
		if ( touch.px < min_px)	min_px = touch.px;
		if ( touch.py < min_py)	min_py = touch.py;

		iprintf("\x1b[0;0H(%d,%d)      ",min_px,min_py);
		iprintf("\x1b[1;0H(%d,%d)      ",min_x,min_y);
		iprintf("\x1b[22;21H(%d,%d)",max_x,max_y);
		iprintf("\x1b[23;23H(%d,%d)",max_px,max_py);

		OAMCopy[0].attribute[2] = 0;
		OAMCopy[0].attribute[1] = ATTR1_SIZE_32 |((touch.px - 16) & 0x01FF);
		OAMCopy[0].attribute[0] = ATTR0_COLOR_256 | ATTR0_SQUARE | ((touch.py -16) & 0x00FF);
		
	}
	
 
	return 0;
}
Beispiel #15
0
int main(void)
{
	
	lcdMainOnBottom();

	// Set modes
	videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);
	videoSetModeSub(MODE_5_2D | DISPLAY_BG0_ACTIVE | DISPLAY_BG2_ACTIVE);
	
	// Set banks
	vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_MAIN_BG_0x06020000,
		VRAM_C_SUB_BG_0x06200000 , VRAM_D_LCD);
	
	// Gfx on main
	REG_BG3CNT = BG_BMP16_256x256 | BG_BMP_BASE(0) | BG_PRIORITY(0);
	REG_BG3PA = 1 << 8;
	REG_BG3PB = 0;
	REG_BG3PC = 0;
	REG_BG3PD = 1 << 8;
	
	// Text bg on sub
	REG_BG0CNT_SUB = BG_MAP_BASE(4) | BG_TILE_BASE(0) | BG_PRIORITY(0);
	BG_PALETTE_SUB[255] = RGB15(31,15,0);
	consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 4, 0, false, true);
	
	// Gfx on sub
	REG_BG2CNT_SUB = BG_BMP16_256x256 | BG_MAP_BASE(2) | BG_PRIORITY(1);
	REG_BG2PA_SUB = 1 << 8;
	REG_BG2PB_SUB = 0;
	REG_BG2PC_SUB = 0;
	REG_BG2PD_SUB = 1 << 8;
	
	u16 i;
	for(i=0; i<256*192; ++i)
		sub_vram[i] = dsmi_logo_ds[i];
	drawKaos();
	drawSlider1();
	drawSlider2();
	drawSlider3();
	
	iprintf("\x1b[12;12HOSC Demo\n");
	
	iprintf("\x1b[15;0H\x1b[KConnecting\n");
	int res = dsmi_connect();
	
	if(res == 1) {
		iprintf("\x1b[15;0H\x1b[KOK\n");
	} else {
		iprintf("\x1b[15;0H\x1b[KOh no, could not connect!\n");
		while(1);
	}
	
	
	while(1)
	{
		int ret, i;
		char data[32];
		size_t size = sizeof(data);
	       	char type;

		VblankHandler();
		while( dsmi_osc_read() ){
			iprintf("\x1b[17;0H\x1b[K%s\n", dsmi_osc_getaddr());
			while( ret = dsmi_osc_getnextarg( data, &size, &type)){
				if( ret == -1) break; //buffer too small error
				switch(type){
					case 'i':
					case 'f':
					  iprintf("%c : 0x%x%x%x%x\n", type, data[0], data[1], data[2], data[3]);
					  break;
					case 's':
					  iprintf("%c : %s\n", type, data);
					  break;
					default:
					  break;
				}
			}
		}
		swiWaitForVBlank();
	}
	
}
void titlescreen()
{
  videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);
  videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE);

  vramSetMainBanks(VRAM_A_MAIN_BG_0x6000000, VRAM_B_LCD,
                   VRAM_C_SUB_BG, VRAM_D_LCD); 

  BG3_CR     = BG_BMP8_256x256 | BG_WRAP_ON | BG_MOSAIC_ON;
  SUB_BG3_CR = BG_BMP8_256x256 | BG_WRAP_ON | BG_MOSAIC_ON;

  // these are rotation backgrounds so you must set the rotation attributes:
  // these are fixed point numbers with the low 8 bits the fractional part
  // this basicaly gives it a 1:1 translation in x and y so you get a nice flat bitmap
  BG3_XDX = 1 << 8;
  BG3_XDY = 0;
  BG3_YDX = 0;
  BG3_YDY = 1 << 8;

  SUB_BG3_XDX = 1 << 8;
  SUB_BG3_XDY = 0;
  SUB_BG3_YDX = 0;
  SUB_BG3_YDY = 1 << 8;

  BG3_CX = 0;
  BG3_CY = 0;

  SUB_BG3_CX = 0;
  SUB_BG3_CY = 0;

  for(int i = 0; i < 256*192; ++i)
    BG_GFX[i] = ((u16*)titlescreen_img_bin)[i];
  for(int i = 0; i < 256; ++i)
    BG_PALETTE[i] = ((u16*)titlescreen_pal_bin)[i];

  for(int i = 0; i < 256*192; ++i)
    BG_GFX_SUB[i] = ((u16*)subtitlescreen_img_bin)[i];
  for(int i = 0; i < 256; ++i)
    BG_PALETTE_SUB[i] = ((u16*)subtitlescreen_pal_bin)[i];

  print("Hello World, 'This is a\nreally hard test,\nbla bla\nblabla");
  
  int count = 0;

  int mosaic_x = 0;
  int mosaic_y = 0;
  while(1) 
    {
      swiWaitForVBlank();
      scanKeys();    

      int pressed = keysDown();
      if (pressed & KEY_TOUCH)
        {
          //touchPosition touch_down = touchReadXY();
          count += 1;

          if (count > 0)
            break;
        }

      if (pressed & KEY_DOWN)
        mosaic_y -= 1;
      if (pressed & KEY_UP)
        mosaic_y += 1;

      if (pressed & KEY_LEFT)
        mosaic_x -= 1;
      if (pressed & KEY_RIGHT)
        mosaic_x += 1;

      if (pressed & KEY_X)
        mosaic_y = mosaic_x -= 1;
      if (pressed & KEY_Y)
        mosaic_y = mosaic_x += 1;

      mosaic_x = Math::mid(0, mosaic_x, 15);
      mosaic_y = Math::mid(0, mosaic_y, 15);
 
      BG3_CX = (mosaic_x/2) << 8;
      BG3_CY = (mosaic_y/2) << 8;

      MOSAIC_CR = mosaic_x | (mosaic_y << 4);
      SUB_MOSAIC_CR = mosaic_x | (mosaic_y << 4);
    }
}
Beispiel #17
0
int main() {
 
    //enable vram and map it to the right places
    vramSetMainBanks(   VRAM_A_MAIN_SPRITE,        //A and B maped consecutivly as sprite memory
                        VRAM_B_MAIN_SPRITE,        //this gives us 256KB which is the max
                        VRAM_C_MAIN_BG_0x06000000, //map C to background memory
                        VRAM_D_LCD                 //not using D
                        ); 
   
   //set the video mode
    videoSetMode(  MODE_0_2D | 
                   DISPLAY_SPR_ACTIVE |    //turn on sprites
                   DISPLAY_BG0_ACTIVE |    //turn on background 0
                   DISPLAY_SPR_1D |        //this is used when in tile mode
                   DISPLAY_SPR_1D_BMP      //and this in bitmap mode
                    );

  	
	consoleInit(0, 0,BgType_Text4bpp, BgSize_T_256x256, 31,0, true, true);
    
    //turn off the sprites
    initSprites();

	
// direct bitmap sprite
// print at using ansi escape sequence \x1b[line;columnH 
	iprintf("\x1b[1;1HDirect Bitmap:");
    sprites[0].attribute[0] = ATTR0_BMP | ATTR0_ROTSCALE_DOUBLE | 10; 
	sprites[0].attribute[1] = ATTR1_SIZE_32 | 20;
	sprites[0].attribute[2] = ATTR2_ALPHA(1)| 0;

	// red 32*32 square for 1d bitmap mode
	for(int i=0;i<32*32;i++)
		SPRITE_GFX[i]=RGB15(31,0,0)|(1<<15); //dont forget alpha bit

// 256 color sprite
// print at using ansi escape sequence \x1b[line;columnH 
	iprintf("\x1b[9;1H256 color:");
	sprites[1].attribute[0] = ATTR0_COLOR_256 | ATTR0_ROTSCALE_DOUBLE | 75;
	sprites[1].attribute[1] = ATTR1_SIZE_32 | 20; // size 64x64, x 10
	sprites[1].attribute[2] = 64;

    // Blue for 256 color sprite
	SPRITE_PALETTE[1]=RGB15(0,0,31);

    // blue 64*64 square for 256 color mode (must write two pixles at time)
	for(int i=0;i<32*16;i++)
		SPRITE_GFX[i+64*16]=(1<<8)|1;

// 16 color sprite
// print at using ansi escape sequence \x1b[line;columnH 
   	iprintf("\x1b[16;1H16 color:");
	sprites[2].attribute[0] = ATTR0_COLOR_16 | ATTR0_ROTSCALE_DOUBLE | 135;
	sprites[2].attribute[1] = ATTR1_SIZE_32 | 20;
	sprites[2].attribute[2] = ATTR2_PALETTE(1) | 96;

    //yellow for 16 color sprite (it is using palette 1 so colors 16-31)
    SPRITE_PALETTE[17]=RGB15(31,31,0);

    // yellow 32*32 square for 16 color mode (must write 4 pixels at a time)
	for(int i=0;i<32*8;i++)
		SPRITE_GFX[i+96*16]=(1<<12)|(1<<8)|(1<<4)|1;



	int angle=0;
    
    //we tied all our sprites to the same rotation attributes (0)
	spriteRotations[0].hdx=256;
	spriteRotations[0].hdy=0;
	spriteRotations[0].vdx=0;
	spriteRotations[0].vdy=256;

	while(1)
	{
		angle+=64;
		
		spriteRotations[0].hdx = cosLerp(angle) >> 4;
		spriteRotations[0].hdy = sinLerp(angle) >> 4;
		spriteRotations[0].vdx = -spriteRotations[0].hdy;
		spriteRotations[0].vdy = spriteRotations[0].hdx;
		
		swiWaitForVBlank();
		
		u32 display_temp = 0;

		scanKeys();
		if(keysDown()&KEY_A) {
		
			screenshotbmp("shot.bmp");

			display_temp=REG_DISPCNT;
			REG_DISPCNT=MODE_FB1;

		}

		if(keysUp()&KEY_A) {
		
			videoSetMode(  MODE_0_2D | 
				DISPLAY_SPR_ACTIVE |    //turn on sprites
				DISPLAY_BG0_ACTIVE |    //turn on background 0
				DISPLAY_SPR_1D |        //this is used when in tile mode
				DISPLAY_SPR_1D_BMP |    //and this in bitmap mode
				DCAP_OFFSET(1));
		}

		
		updateOAM();
	}
}
void gamescreen()
{
  // set the mode for 2 text layers and two extended background layers
  videoSetMode(MODE_5_2D |
               //DISPLAY_BG1_ACTIVE |
               DISPLAY_BG3_ACTIVE |
               DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D_LAYOUT
               );

  // set the first bank as background memory and the third as sub background memory
  // B and D are not used (if you want a bitmap greater than 256x256 you will need more
  // memory so another vram bank must be used and mapped consecutivly
  vramSetMainBanks(VRAM_A_MAIN_BG_0x6000000, VRAM_B_MAIN_SPRITE, //VRAM_B_MAIN_BG_0x6020000,
                   VRAM_C_SUB_BG, VRAM_D_MAIN_BG_0x6020000);
  
  // set up our bitmap background
  BG3_CR     = BG_BMP8_512x256 | BG_WRAP_ON| BG_BMP_BASE(0);
  //BG2_CR     = BG_BMP8_256x256 | BG_BMP_BASE(8);
  
  BG1_CR = BG_32x32 | BG_TILE_BASE(0) | BG_MAP_BASE(8) | BG_256_COLOR;


  // these are rotation backgrounds so you must set the rotation attributes:
  // these are fixed point numbers with the low 8 bits the fractional part
  // this basicaly gives it a 1:1 translation in x and y so you get a nice flat bitmap
  BG3_XDX = 1 << 8;
  BG3_XDY = 0;
  BG3_YDX = 0;
  BG3_YDY = 1 << 8;

  BG2_XDX = 1 << 8;
  BG2_XDY = 0;
  BG2_YDX = 0;
  BG2_YDY = 1 << 8;


  //our bitmap looks a bit better if we center it so scroll down (256 - 192) / 2
  BG3_CX = 0;
  BG3_CY = 0;

  BG2_CX = 0;
  BG2_CY = 0;

  for(int i = 0; i < 512*256; i++)
    BG_GFX[i] = ((u16*)topscreen_img_bin)[i];

  for(int i = 0; i < 256; ++i)
    BG_PALETTE[i] = ((u16*)topscreen_pal_bin)[i];
  //for(int i = 0; i < 256; ++i)
  //BG_PALETTE[i] = ((u16*)numbers_pal_bin)[i];

        
  x = 0;
  y = 0;
  px = 128-32;
  py = 103;
  oldx = x;
  oldy = y;
  drag = false;
  touch_down = touchReadXY();

  initSprites();
  
  for(int i=0;i<256*256;i++)
    {
      SPRITE_GFX[i] = i % 256 | ((i % 256) << 8);
    }

  //for(int i = 0; i < 8*8*256/2; ++i)
  //    ((u16*)BG_TILE_RAM(0))[i] = ((u16*)numbers_img_bin)[i];

  //for(int i = 0; i < 32*32; ++i)
  //((u16*)BG_MAP_RAM(8))[i] = i%256;

  /*    for(int y=0;y<64; ++y)
        for(int x=0;x<32; ++x)
        {
        SPRITE_GFX[y*64+x] = ((u16*)sprite_img_bin)[y*32+x];
        }*/

  const u8* frames[16];
  frames[0]  = walk_frame00_img_bin;
  frames[1]  = walk_frame01_img_bin;
  frames[2]  = walk_frame02_img_bin;
  frames[3]  = walk_frame03_img_bin;
  frames[4]  = walk_frame04_img_bin;
  frames[5]  = walk_frame05_img_bin;
  frames[6]  = walk_frame06_img_bin;
  frames[7]  = walk_frame07_img_bin;
  frames[8]  = walk_frame08_img_bin;
  frames[9]  = walk_frame09_img_bin;
  frames[10] = walk_frame10_img_bin;
  frames[11] = walk_frame11_img_bin;
  frames[12] = walk_frame12_img_bin;
  frames[13] = walk_frame13_img_bin;
  frames[14] = walk_frame14_img_bin;
  frames[15] = walk_frame15_img_bin;

  const u8* pal_frames[16];
  pal_frames[0]  = walk_frame00_pal_bin;
  pal_frames[1]  = walk_frame01_pal_bin;
  pal_frames[2]  = walk_frame02_pal_bin;
  pal_frames[3]  = walk_frame03_pal_bin;
  pal_frames[4]  = walk_frame04_pal_bin;
  pal_frames[5]  = walk_frame05_pal_bin;
  pal_frames[6]  = walk_frame06_pal_bin;
  pal_frames[7]  = walk_frame07_pal_bin;
  pal_frames[8]  = walk_frame08_pal_bin;
  pal_frames[9]  = walk_frame09_pal_bin;
  pal_frames[10] = walk_frame10_pal_bin;
  pal_frames[11] = walk_frame11_pal_bin;
  pal_frames[12] = walk_frame12_pal_bin;
  pal_frames[13] = walk_frame13_pal_bin;
  pal_frames[14] = walk_frame14_pal_bin;
  pal_frames[15] = walk_frame15_pal_bin;

  for(int i=0;i<64*32; ++i)
    SPRITE_GFX[i] = ((u16*)sprite_img_bin)[i];

  for(int i=0;i<32*32/2; ++i)
    SPRITE_GFX[i+64*32] = ((u16*)use_icon_img_bin)[i];

  for(int i=0;i<64*32; ++i)
    SPRITE_GFX[i+ (64*32) + (32*16)] = ((u16*)smalldoor_img_bin)[i];

  for(int i=0;i<64*32; ++i)
    SPRITE_GFX[i] = ((u16*)walk_frame00_img_bin)[i];

  for(int i = 0; i < 256; ++i)
    SPRITE_PALETTE[i] = ((u16*)walk_frame00_pal_bin)[i];


  sprites[0].attribute[0] = ATTR0_SQUARE | ATTR0_TYPE_BLENDED | ATTR0_BMP | px;
  sprites[0].attribute[1] = ATTR1_SIZE_64 | py  | ATTR1_FLIP_Y;
  sprites[0].attribute[2] = ATTR2_ALPHA(3);

  sprites[1].attribute[0] = ATTR0_SQUARE | ATTR0_COLOR_256 | (192-32-8) | ATTR0_DISABLED;
  sprites[1].attribute[1] = ATTR1_SIZE_32 | (256-32-8);
  sprites[1].attribute[2] = 64*2;//64*64;//64*32;

  sprites[2].attribute[0] = ATTR0_SQUARE | ATTR0_COLOR_256 | 90-6;
  sprites[2].attribute[1] = ATTR1_SIZE_64 | 200+16+2;
  sprites[2].attribute[2] = 64*2+32;

  int frame_index = 0;
  int sx = 0;
  //int sy = 0;
  bool left = true;;

  if (subscreen_mode == PDA)
    init_pda();
  else
    init_doorminigame();

  while(1) 
    {
      swiWaitForVBlank();

      frame_index += 1;
      frame_index = frame_index % 80;

      //SPRITE_GFX[i] = ((u16*)numbers_img_bin)[i];


      // read the button states
      scanKeys();
      touch = touchReadXY();

      pressed = keysDown();	// buttons pressed this loop
      held = keysHeld();		// buttons currently held
      
      if (subscreen_mode != DIALOG)
        {
          sprites[0].attribute[0] = ATTR0_SQUARE | ATTR0_TYPE_BLENDED | ATTR0_COLOR_256 | mod(103,512);
          sprites[0].attribute[1] = ATTR1_SIZE_64 | mod(128-32,512) | (left ? 0: ATTR1_FLIP_X);
          sprites[0].attribute[2] = ATTR2_ALPHA(3);

          sprites[2].attribute[0] = ATTR0_SQUARE | ATTR0_TYPE_BLENDED | ATTR0_COLOR_256 | mod(90-6, 512);
          sprites[2].attribute[1] = ATTR1_SIZE_64 | mod((200+16+2 - px + 128-32 + door_pos/4),512);
          sprites[2].attribute[2] = ATTR2_ALPHA(1) | 64*2+32;
        }
      else
        {
          sprites[0].attribute[0] |=  ATTR0_DISABLED;
          sprites[1].attribute[0] |=  ATTR0_DISABLED;
          sprites[2].attribute[0] |=  ATTR0_DISABLED;
        }

      if ((held & KEY_L) && (held & KEY_R))
        swiSoftReset();

      if ((pressed & KEY_LEFT) || (pressed & KEY_RIGHT))
        {
          frame_index = 0;
        }

      if (held & KEY_LEFT)
        {
          left = true;
          px -= 1;
          sprites[0].attribute[1] = sprites[0].attribute[1] & ~ATTR1_FLIP_X;

          for(int i=0;i<64*32; ++i)
            SPRITE_GFX[i] = ((u16*)frames[frame_index/5])[i];
      
          for(int i = 0; i < 256; ++i)
            SPRITE_PALETTE[i] = ((u16*)pal_frames[frame_index/5])[i];
        }
      else if (held & KEY_RIGHT)
        {
          left = false;
          px += 1;
          sprites[0].attribute[1] = sprites[0].attribute[1] | ATTR1_FLIP_X;

          for(int i=0;i<64*32; ++i)
            SPRITE_GFX[i] = ((u16*)frames[frame_index/5])[i];
      
          for(int i = 0; i < 256; ++i)
            SPRITE_PALETTE[i] = ((u16*)pal_frames[frame_index/5])[i];
        }
      else
        {
          for(int i=0;i<64*32; ++i)
            SPRITE_GFX[i] = ((u16*)frames[0])[i];
      
          for(int i = 0; i < 256; ++i)
            SPRITE_PALETTE[i] = ((u16*)pal_frames[0])[i];
        }

      if (held & KEY_DOWN)
        py += 1;
      else if (held & KEY_UP)
        py -= 1;


      if ((px + 128) > 328-16 && 
          (px + 128) < (328+35+16))
        {
          sprites[1].attribute[0] &=  ~ATTR0_DISABLED;
          //if (pressed & KEY_X)
          //            {
          if (subscreen_mode == PDA)
            {
              init_doorminigame();
              subscreen_mode = DOOR_MINIGAME;
            }
          else if (subscreen_mode == DOOR_MINIGAME)
            {
              init_pda();
              subscreen_mode = PDA;
            }
          //}
        }
      else if ((px + 128) > 133-16 &&
               (px + 128) < 133-16+32)
        {
          init_dialog();
          subscreen_mode = DIALOG;
        }
      else
        {
          sprites[1].attribute[0] |= ATTR0_DISABLED;
          if (subscreen_mode == DOOR_MINIGAME)
            {
              init_pda();
              subscreen_mode = PDA;
            }
        }


      sx = px;
      //sx += 1;
      
      if ((held & KEY_TOUCH)  && drag)
        {
          x = oldx + (touch_down.px - touch.px);
          y = oldy + (touch_down.py - touch.py);
        }

      if (!(held & KEY_TOUCH))
        drag = false;
      
      if (subscreen_mode != DIALOG)
        {
          BG3_CX  = x*500 + sx<<8 ;
          BG3_CY  = y*500 + (32<<8);
        }
      //2_CX  = -x;
      //2_CY  = -y;
      
      update_subscreen();

      updateOAM();
    }
}
Beispiel #19
0
//this function initiates video ram for immediate use with sprites
//
void blu_impl::GFX_Initiate(){
videoSetMode(MODE_0_2D);
vramSetMainBanks(VRAM_A_MAIN_SPRITE,VRAM_B_LCD,VRAM_C_LCD,VRAM_D_LCD);
}
Beispiel #20
0
Datei: main.c Projekt: 0xtob/dsmi
int main(void)
{
	lcdMainOnBottom();
	
	// Register vblank IRQ
	irqEnable(IRQ_VBLANK);
	
	// Set banks
	vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_MAIN_BG_0x06020000,
	           VRAM_C_SUB_BG_0x06200000 , VRAM_D_LCD);
	
	// Set modes
	videoSetMode(MODE_5_2D);
	videoSetModeSub(MODE_5_2D);
	
	// sub display
	int sub_bg3 = bgInitSub(3, BgType_Bmp16, BgSize_B16_256x256, 2, 0);
	bgSetPriority(sub_bg3, 1);
	
#ifdef DEBUG
	// Text bg on sub
	PrintConsole *pc = consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 4, 0, false);
	bgSetPriority(pc->bgId, 0);
	BG_PALETTE_SUB[255] = RGB15(31,0,31);
#endif
	// The main display is for graphics.
	// Set up an extended rotation background for background gfx
	int main_bg2 = bgInit(2, BgType_Bmp16, BgSize_B16_256x256, 2, 0);
	bgSetPriority(main_bg2, 1);
	
	// Set up tile mode for the keyboard
	int main_bg0 = bgInit(0, BgType_Text4bpp, BgSize_T_256x256, 8, 0);
	bgSetPriority(main_bg0, 0);
	
	// Clear tile mem
	u16 *tile_ram = (u16*)bgGetGfxPtr(main_bg0);
	u32 i;
	for(i=0; i<(32*1024); ++i) {
		tile_ram[i] = 0;
	}
	
	// Copy tiles and palettes
	dmaCopy((uint16*)keyboard_Palette, (uint16*)BG_PALETTE, 32);
	dmaCopy((uint16*)keyboard_fullnotehighlight_Palette, (uint16*)BG_PALETTE+16, 32);
	dmaCopy((uint16*)keyboard_halfnotehighlight_Palette, (uint16*)BG_PALETTE+32, 32);
	dmaCopy((uint16*)keyboard_Tiles, (uint16*)CHAR_BASE_BLOCK(0), 736);
	
	// Fill screen with empty tiles
	u16 *map = (u16*)bgGetMapPtr(main_bg0);
	for(i=0;i<768;++i) {
		map[i] = 28;
	}
	
	// Draw the backgrounds
	main_vram = (u16*)bgGetGfxPtr(main_bg2);
	for(i=0; i<192*256; ++i) {
		main_vram[i] = ((uint16*)bg_main)[i];
	}
	
	u16 *sub_vram = (u16*)bgGetGfxPtr(sub_bg3);
	for(i=0; i<192*256; ++i) {
		sub_vram[i] = ((uint16*)bg_sub)[i];
	}

	
	displayChannel(channel);
	displayOctave(baseOctave);
	
	drawString("connecting ...", 89, 96);
	
	iprintf("Connecting\n");
	int res = dsmi_connect();
	if(res == 1) {
		iprintf("OK\n");
	} else {
		iprintf("Oh no! Could not connect\n");
		drawString("failed!", 180, 96);
		while(1);
	}
	
	iprintf("Ready.\n");

	// Copy the keyboard to the screen
	kb_map = (u16*)bgGetMapPtr(main_bg0);
	u8 x, y;
	for(y=0; y<5; ++y) {
		for(x=0; x<28; ++x) {
			kb_map[32*(y+keyb_ypos)+(x+keyb_xpos)] = keyboard_Map[29*y+x+1];
		}
	}

	while(1) {
		VblankHandler();
		swiWaitForVBlank();
	}

	return 0;
}