Author Topic: simple ds two screen example  (Read 4977 times)

0 Members and 1 Guest are viewing this topic.

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
simple ds two screen example
« on: September 21, 2006 »
i thought id kick this off by bringing this nintendo ds example across from my old forum bear with me because im going to write a tut that will get anybody going with a ds.

 
Code: [Select]
//////////////////////////////////////////////////////////////////////
// two screen demo
// ninos picture viewer
//////////////////////////////////////////////////////////////////////

#include <NDS/NDS.h>

#include <NDS/ARM9/console.h>
#include "milo.h"//256x192 bmp image converted to raw bgr 5:5:5 format
#include "milo1.h"//256x192 bmp image converted to raw bgr 5:5:5 format

u16* front;//
u16* back;

void WaitForVblank();
void draw_bmp(void);
void flip();
void cls();

//THE TWO COMMANDS I MADE BELLOW HELP MENIPULATE BACKGROUNDS THEY ROTATE MOVE AND SCALE 
//AND CHOOSE ROTATOIN POINTS ON BACKGROUNDS 
//ANOTHER POINT FOR SCALEX AND SCALEY TO WORK THEY HAVE TO BE FIXED POINT FIRST SO
//(1<<8) IS YOUR NORMAL SIZE THEN TO ADJUST THE SIZE YOU DO (1<<8)+-AMOUNT
 
void rotate_and_scale_main_image(s16 scale_x,s16 scale_y,s16 x_pos,s16 Y_pos,s16 angle,s16 rot_pointx,s16 rot_pointy);
void rotate_and_scale_sub_image(s16 scale_x,s16 scale_y,s16 x_pos,s16 Y_pos,s16 angle,s16 rot_pointx,s16 rot_pointy);

s16 angle;

int main(void)
{
        powerON(POWER_ALL);
        irqInitHandler(irqDefaultHandler);
        irqSet(IRQ_VBLANK, 0);

        videoSetMode(MODE_5_2D | DISPLAY_BG2_ACTIVE);
        videoSetModeSub(MODE_5_2D | DISPLAY_BG2_ACTIVE);
       
        vramSetBankA(VRAM_A_MAIN_BG_0x6000000);
        vramSetBankB(VRAM_B_MAIN_BG_0x6020000);
        vramSetBankC(VRAM_C_SUB_BG_0x6200000);

        BG2_CR = BG_BMP16_256x256;
        SUB_BG2_CR = BG_BMP16_256x256;

        front=(u16*)(0x6000000);
        back=(u16*)(0x6020000);
       
        while(1)
        {
                  angle += 4;

                  if(IPC->touchX != 0)
                  {
                     lcdSwap();
                  }
                  draw_bmp();
                  flip();
                  cls();
                  rotate_and_scale_main_image((1<<8)-30,(1<<8)-30,128,96,angle,128,96); 
                  rotate_and_scale_sub_image((1<<8)-30,(1<<8)-30,128,96,angle,128,96);
                  WaitForVblank();
        }
        return 0;
}


void WaitForVblank()
{
        while(DISP_Y!=192);
        while(DISP_Y==192);
}

void draw_bmp(void)
{
        for(int ix = 0; ix < 256*192; ix++)
        {
                back[ix] = milo[ix] | BIT(15);
                BG_GFX_SUB[ix] = milo1[ix] | BIT(15);
        }
       
}

void flip()
{
        //flip the main screen
        u16* temp;
        temp=back;
        back=front;
        front=temp;
        BG2_CR ^= BG_BMP_BASE( 128 / 16 );
}

void cls()
{
        for(int ix = 0; ix < 246*192; ix++)
        {
                back[ix] = 0x0000 | BIT(15);
        }
}

void rotate_and_scale_main_image(s16 scale_x , s16 scale_y , s16 x_pos , s16 Y_pos , s16 angle , s16 rot_pointx , s16 rot_pointy)
{
     s16 coz=COS[angle & 0x1FF] >> 4;
     s16 zin=SIN[angle & 0x1FF] >> 4;
     BG2_XDX = ( coz * (scale_x) ) >> 8;
     BG2_XDY = (-zin * (scale_x) ) >> 8;
     BG2_YDX = ( zin * (scale_y) ) >> 8;
     BG2_YDY = ( coz * (scale_y) ) >> 8;
     BG2_CX = (x_pos<<8) - rot_pointx * (coz - zin);
     BG2_CY = (Y_pos<<8) - rot_pointy * (zin + coz);
}

void rotate_and_scale_sub_image(s16 scale_x , s16 scale_y , s16 x_pos , s16 Y_pos , s16 angle , s16 rot_pointx , s16 rot_pointy)
{
     s16 coz=COS[angle & 0x1FF] >> 4;
     s16 zin=SIN[angle & 0x1FF] >> 4;
     SUB_BG2_XDX = ( coz * (scale_x) ) >> 8;
     SUB_BG2_XDY = (-zin * (scale_x) ) >> 8;
     SUB_BG2_YDX = ( zin * (scale_y) ) >> 8;
     SUB_BG2_YDY = ( coz * (scale_y) ) >> 8;
     SUB_BG2_CX = (x_pos<<8) - rot_pointx * (coz - zin);
     SUB_BG2_CY = (Y_pos<<8) - rot_pointy * (zin + coz);
}

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17394
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: simple ds two screen example
« Reply #1 on: September 21, 2006 »
A tute would be great Nino. I don't know how many people here have tried console development, but I can think of a few for sure. It would be great to help console novices like me to learn some basics.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: simple ds two screen example
« Reply #2 on: September 22, 2006 »
no probs shockwave what i was thinking of doing was a game boy advanced one that has lots of good resources then a ds one which shows the similarites between the 2d cores and how the ds is just an extension of the gba hardware.
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17394
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: simple ds two screen example
« Reply #3 on: September 22, 2006 »
You would know best there Nino, if a Gba one would be a better introduction then that would be very cool.

When the showcase is finally finished I'm hoping to have tutorials on there too and thinking of some way of rewarding the people who write tuts.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: simple ds two screen example
« Reply #4 on: September 22, 2006 »
yeah ive already started  :D ill write the two side by side so hopefully the info doesnt conflict ;)
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17394
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: simple ds two screen example
« Reply #5 on: September 22, 2006 »
Thanks mate :)
Shockwave ^ Codigos
Challenge Trophies Won: