static int NDS_RenderClear(SDL_Renderer *renderer)
{
    NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;

	/* wait for capture unit to be ready */
	while(REG_DISPCAPCNT & DCAP_ENABLE);

	/* 3D engine can only work on one screen at a time. */
	data->is_sub = !data->is_sub;
	if (data->is_sub) {
		lcdMainOnBottom();
		vramSetBankC(VRAM_C_LCD);
		vramSetBankD(VRAM_D_SUB_SPRITE);
		REG_DISPCAPCNT = DCAP_BANK(2) | DCAP_ENABLE | DCAP_SIZE(3);
	} else {
		lcdMainOnTop();
		vramSetBankD(VRAM_D_LCD);
		vramSetBankC(VRAM_C_SUB_BG);
		REG_DISPCAPCNT = DCAP_BANK(3) | DCAP_ENABLE | DCAP_SIZE(3);
	}

	glBegin2D();

    glClearColor(renderer->r >> 3,
                 renderer->g >> 3,
                 renderer->b >> 3,
                 renderer->a >> 3);

	return 0;
}
Exemple #2
0
void initEditor(void)
{
	lcdMainOnBottom();
	videoSetMode(MODE_5_3D);
	videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE);
	
	vramSetPrimaryBanks(VRAM_A_TEXTURE,VRAM_B_TEXTURE,VRAM_C_SUB_BG,VRAM_D_TEXTURE);	
	
	glInit();
	
	glEnable(GL_TEXTURE_2D);
	// glEnable(GL_ANTIALIAS);
	glEnable(GL_BLEND);
	glEnable(GL_OUTLINE);
	
	glClearPolyID(63);
	glClearDepth(0x7FFF);
	glViewport(0,0,255,191);
	
	initVramBanks(1);
	initTextures();
	
	initRoomEdition();
	NOGBA("START mem free : %dko (%do)",getMemFree()/1024,getMemFree());

	fadeIn();
}
Exemple #3
0
void GrafikoakHasieratu()
{
	powerOn(POWER_ALL_2D);
    lcdMainOnBottom();
    hasieratuBideoa();
    //hasieratuFondoak();
	consoleDemoInit(); //Goiko pantaila testua erakusteko eta beheko irudiak erakusteko erabiliko da.
}
Exemple #4
0
int main() {
    /* Turn on the 2D graphics core. */
    powerOn(POWER_ALL_2D);

    /*
     *  Configure the VRAM and background control registers.
     *
     *  Place the main screen on the bottom physical screen. Then arrange the
     *  VRAM banks. Next, confiure the background control registers.
     */
    lcdMainOnBottom();
    initVideo();
    initBackgrounds();

    /* Set up a few sprites. */
    SpriteInfo spriteInfo[SPRITE_COUNT];
    OAMTable *oam = new OAMTable();
    initOAM(oam);
    initSprites(oam, spriteInfo);

    /* Display the backgrounds. */
    displayStarField();
    displayPlanet();
    displaySplash();

    /* Make the ship object. */
    static const int SHUTTLE_OAM_ID = 0;
    SpriteEntry * shipEntry = &oam->oamBuffer[SHUTTLE_OAM_ID];
    SpriteRotation * shipRotation = &oam->matrixBuffer[SHUTTLE_OAM_ID];
    Ship * ship = new Ship(&spriteInfo[SHUTTLE_OAM_ID]);

    /* Accelerate the ship for a little while to make it move. */
    for (int i = 0; i < 10; i++) {
        ship->accelerate();
    }

    for (;;) {
        /* Update the game state. */
        ship->moveShip();

        /* Update sprite attributes. */
        MathVector2D<float> position = ship->getPosition();
        shipEntry->x = (int)position.x;
        shipEntry->y = (int)position.y;
        rotateSprite(shipRotation, -ship->getAngleDeg());

        /*
         *  Update the OAM.
         *
         *  We have to copy our copy of OAM data into the actual OAM during
         *  VBlank (writes to it are locked during other times).
         */
        swiWaitForVBlank();
        updateOAM(oam);
    }

    return 0;
}
Exemple #5
0
void video_init()
{
    powerSET(POWER_LCD | POWER_2D_B);
    lcdMainOnBottom();
    videoSetMode(0);
    consoleDemoInit();

    iprintf("Wifi EEPROM Dumper\nMicah Dowty <*****@*****.**>\n\n");
}
Exemple #6
0
void init_displays()
{
	videoSetMode(MODE_5_2D);
	videoSetModeSub(MODE_0_2D);

	vramSetBankA(VRAM_A_MAIN_BG);
	vramSetBankB(VRAM_B_MAIN_BG);

	lcdMainOnBottom();
}
Exemple #7
0
// 2 frames delay
void setupScaledScreens2() {
    REG_DISPCNT &= ~(3<<16); // Disable main display
    REG_DISPCNT_SUB |= 1<<16; // Enable sub display
    if (consoleScreen == 0)
        lcdMainOnTop();
    else
        lcdMainOnBottom();
    powerOn(backlights[!consoleScreen]);

    refreshScaleMode();
}
Exemple #8
0
int main(void)
{
	// Video setup
	lcdMainOnBottom();
	irqEnable(IRQ_VBLANK);
	
	vramSetBankC(VRAM_C_SUB_BG);
	
    // Text console
	videoSetModeSub(MODE_5_2D);
	PrintConsole *pc = consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 4, 0, false, true);
	BG_PALETTE_SUB[255] = RGB15(31,15,0);
	bgSetPriority(pc->bgId, 0);
	
    // DSMI Logo
	int bg2 = bgInitSub(2, BgType_Bmp16, BgSize_B16_256x256, 2, 0);
	bgSetPriority(bg2, 1);
	u16 *bg2vram = bgGetGfxPtr(bg2);
	dmaCopy(dsmi_logo_dsBitmap, bg2vram, 256*192);
	
	iprintf("\x1b[12;12HPulse DS\n");
	
	// Connect
	int res = dsmi_connect();
	while(res == 0) {
		iprintf("\x1b[15;0H\x1b[KCould not connect. We apologize for the inconvecience.\n");
		while(1);
	}
	
	iprintf("\x1b[15;0H\x1b[KRunning.\n");
	
	u8 message, data1, data2;
	while(1)
	{
		// We query every 60th of a second (notice the swiWaitForVBlank).
		// For lower latency you should query more frequently.
		
		// Query and play until there are no more new messages
		while(dsmi_read(&message, &data1, &data2)) {
			printf("0x%x 0x%x 0x%x\n", message, data1, data2);
			midiToArm7(message, data1, data2);
		}
		
		swiWaitForVBlank();
	}
	
	return 0;
}
Exemple #9
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)
}
Exemple #10
0
void init_world() {
	lcdMainOnBottom();

#ifndef NATIVE
	// TODO: replace with gettimeofday() or similar
	init_genrand(genrand_int32() ^ (IPC->time.rtc.seconds +
				IPC->time.rtc.minutes*60 + IPC->time.rtc.hours*60*60 +
				IPC->time.rtc.weekday*7*24*60*60));
#else
	{
		struct timeval tv;
		gettimeofday(&tv,NULL);
		init_genrand(tv.tv_usec+tv.tv_sec*1000000);
	}
#endif

	new_game();

	torch.run(handler);
}
Exemple #11
0
void setupUnscaledScreens() {
    int screensToSet[2];

    REG_DISPCNT &= ~(3<<16);
    REG_DISPCNT |= 1<<16; // Enable main display

    if (!consoleInitialized) {
        consoleDemoInit(); // Or, consoleInit(menuConsole, ...)
        setPrintConsole(menuConsole);
        BG_PALETTE_SUB[8*16 - 1] = RGB15(17,17,17); // Grey (replaces a color established in consoleDemoInit)
        consoleInitialized = true;
    }
    if (consoleScreen == 0)
        lcdMainOnBottom();
    else
        lcdMainOnTop();

    screensToSet[!consoleScreen] = true;

    if (!(fpsOutput || timeOutput || consoleDebugOutput || isMenuOn() || isFileChooserOn())) {
        screensToSet[consoleScreen] = false;
        REG_DISPCNT_SUB &= ~(3<<16); // Disable sub display
    }
    else {
        screensToSet[consoleScreen] = true;
        REG_DISPCNT_SUB &= ~(3<<16);
        REG_DISPCNT_SUB |= 1<<16; // Enable sub display
    }

    for (int i=0; i<2; i++) {
        if (screensToSet[i]) {
            if (i == consoleScreen)
                doAtVBlank(enableConsoleBacklight);
            else
                powerOn(backlights[i]);
        }
        else
            powerOff(backlights[i]);
    }
}
Exemple #12
0
void TunnelPartInit(void)
{
	T_Mesh* mesh;
	int i;
	
	/* 
	 * Initialisation vidéo
	 */ 
	/* Modes video */
	videoSetMode(MODE_5_3D);
	videoSetModeSub(MODE_5_2D);
	lcdMainOnBottom();
	
	vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
	vramSetBankB(VRAM_B_MAIN_BG_0x06020000);
	vramSetBankC(VRAM_C_SUB_BG_0x06200000);
	vramSetBankD(VRAM_D_TEXTURE_SLOT3);
	
	videoBgEnable(DISPLAY_BG0_ACTIVE | DISPLAY_BG2_ACTIVE);
	videoBgEnableSub(DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE);
	
	/* Le BG qui servira pour le tunnel */
	TunnelBgId = bgInitSub(2, BgType_Bmp16, BgSize_B16_256x256, 0, 0);
	TunnelBgPixels = (u16*)bgGetGfxPtr(TunnelBgId);
	bgSetPriority(TunnelBgId, 2); /* Le tunnel en fond */

	/* L'avant plan de l'éléphant */	
	FrontLayerId = bgInit(2, BgType_Bmp8, BgSize_B8_256x256, 8, 0);
	FrontLayerPixels = (u8*)bgGetGfxPtr(FrontLayerId);
	bgSetPriority(FrontLayerId, 0); /* En avant plan */
	decompress(bouleBitmap, FrontLayerPixels, LZ77Vram);
	decompress(boulePal, BG_PALETTE, LZ77Vram); 
	
	bgSetPriority(0, 1); /* La 3D entre les deux */
	
	
	/* Initialisation de la 3D */
    Init3DEngine();
    
	TunnelFxInit(TunnelBgPixels);
	        
    mesh = CreateMesh();
    mesh->display_list = DiscoElephant_mesh;
    mesh->alpha = 31;
    mesh->texturing = TRUE;
    mesh->lighting = TRUE;
    DiscoElephant = CreateObj3D(mesh);
    Scene = CreateScene();
    AddObject(Scene, DiscoElephant);
    
    Scene->lights[0] = CreateLight(floattov10(0), floattov10(0), floattov10(-1), RGB15(16, 0, 01), TRUE);
    Scene->lights[1] = CreateLight(floattov10(0), floattov10(0), floattov10(-1), RGB15(0, 16, 0), TRUE);
    Scene->lights[2] = CreateLight(floattov10(0), floattov10(0), floattov10(-1), RGB15(0, 0, 16), TRUE);
    Scene->lights[3] = CreateLight(floattov10(0), floattov10(0), floattov10(-1), RGB15(16, 16, 0), TRUE);
    
    glClearColor(0, 0, 0, 0);
    
    flare_tex = CreateTextureFromMemory((u8*)flareBitmap, GL_RGBA, 0, 16, 64, TRUE, LZ77Vram);
    
    for(i=0; i<4; i++) {
    	flares[i] = malloc(sizeof(*flares[i]));
    }
    
    flares[0]->position[0] = 0;
    flares[0]->position[1] = 0;
    flares[0]->position[2] = floattof32(-1);
    flares[0]->poly_alpha = 16;
    flares[0]->color = RGB15(31, 0, 0);
    flares[0]->size = floattov16(0.15f);
    flares[0]->texture_id = flare_tex->id;
    flares[0]->poly_id = 5;
    
    flares[1]->position[0] = 0;
    flares[1]->position[1] = 0;
    flares[1]->position[2] = floattof32(-1);
    flares[1]->poly_alpha = 16;
    flares[1]->color = RGB15(0, 31, 0);
    flares[1]->size = floattov16(0.15f);
    flares[1]->texture_id = flare_tex->id;
    flares[1]->poly_id = 6;
    
    flares[2]->position[0] = 0;
    flares[2]->position[1] = 0;
    flares[2]->position[2] = floattof32(-1);
    flares[2]->poly_alpha = 16;
    flares[2]->color = RGB15(0, 0, 31);
    flares[2]->size = floattov16(0.15f);
    flares[2]->texture_id = flare_tex->id;
    flares[2]->poly_id = 6;
    
    flares[3]->position[0] = 0;
    flares[3]->position[1] = 0;
    flares[3]->position[2] = floattof32(-1);
    flares[3]->poly_alpha = 16;
    flares[3]->color = RGB15(31, 31, 0);
    flares[3]->size = floattov16(0.15f);
    flares[3]->texture_id = flare_tex->id;
    flares[3]->poly_id = 7;
    
    tex = CreateTextureFromMemory((u8*)DiscoElephantBitmap, GL_RGB, 0, 16, 64, TRUE, LZ77Vram);
    DiscoElephant->mesh->texture_id = tex->id;
    DiscoElephant->mesh->texturing = TRUE;
    
	/* Initialisation du fade in depuis le blanc */
	REG_MASTER_BRIGHT = (1<<14);
	REG_MASTER_BRIGHT_SUB = REG_MASTER_BRIGHT;
	
	StartFlash(-1000); // pour éviter un flash à la première seconde
	
	glMaterialf(GL_AMBIENT, RGB15(16,16,16));
    glMaterialf(GL_SPECULAR, BIT(15) | RGB15(31,31,31));
	glMaterialShinyness();
}
Exemple #13
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;
}
Exemple #14
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();
	}
	
}
Exemple #15
0
int main(void) {

  consoleDemoInit();

  //videoSetMode(MODE_FB0);
  videoSetMode( MODE_5_2D );
  vramSetBankA(VRAM_A_MAIN_BG);
  vramSetBankB(VRAM_B_MAIN_BG);
  // vramSetBankC(VRAM_C_MAIN_BG);
  // vramSetBankD(VRAM_D_MAIN_BG_0x06040000);
  int bg = bgInit(3, BgType_Bmp8, BgSize_B8_512x512, 0,0);  //vramSetBankA(VRAM_A_LCD);

  lcdMainOnBottom();
  // lcdMainOnTop();

  printf("Video modes configured\n");
  printf("BG ID %d\n", bg);

  if (fatInitDefault())
    printf("FAT initialized\n");
  else
    printf("FAT initialization failed\n");

  AppState state;
  uiOpenNotebook(state);

  // Keyboard *kbd =  keyboardDemoInit();

  Segment * currentSegment = NULL;


  touchPosition touch;

  while (1) {
    scanKeys();
    
    if(keysHeld() & KEY_TOUCH)
      {
	// write the touchscreen coordinates in the touch variable
	touchRead(&touch);
	
	Point screenPoint = Point(touch.px, touch.py);
	Point imagePoint = state.convertScreenToImage(screenPoint);

	if (currentSegment == NULL) {
	  state.currentPage->segments.push_back(Segment());
	  currentSegment = &(state.currentPage->segments[state.currentPage->segments.size()-1]);
	  currentSegment->points.push_back(imagePoint);
	  continue;
	}

	Point lastImagePoint = currentSegment->points[currentSegment->points.size()-1];
	currentSegment->points.push_back(imagePoint);

	Point bufferPoint = state.convertScreenToBuffer(screenPoint);
	Point lastBufferPoint = state.convertImageToBuffer(lastImagePoint);
	drawLine(lastBufferPoint.x, lastBufferPoint.y,  bufferPoint.x, bufferPoint.y, RGB15(31,0,0) | BIT(15));
      }    
    else {
      currentSegment = NULL;
    }
    if (keysDown() & KEY_X) {
      int page = state.lastPage+1;
      while (state.notebook.pages.size() < page+1) {
	state.notebook.pages.push_back(Page());
	printf("New Page created\n");
      }
      state.currentPage = &(state.notebook.pages[page]);
      currentSegment = NULL;

      printf("Display page %d\n", page);

      fillDisplay(RGB15(0,0,0) | BIT(15), page, state);
      drawPage(state.currentPage, RGB15(31,0,0) | BIT(15), state);
    }
    if (keysDown() & KEY_Y) {
      int page = 0;
      if (state.lastPage > 0) {
	page = state.lastPage-1;
      }
      state.currentPage = &(state.notebook.pages[page]);
      currentSegment = NULL;

      printf("Display page %d\n", page);

      fillDisplay(RGB15(0,0,0) | BIT(15), page, state);
      drawPage(state.currentPage, RGB15(31,0,0) | BIT(15), state);
    }
    if (keysDown() & KEY_A) {
      int page = 0;
      std::string fileName = state.notebookName + "/notes.txt";
      state.notebook = loadFile(fileName.c_str());

      state.currentPage = &(state.notebook.pages[page]);
      currentSegment = NULL;

      printf("Display page %d\n", page);

      fillDisplay(RGB15(0,0,0) | BIT(15), page, state);
      drawPage(state.currentPage, RGB15(31,0,0) | BIT(15), state);
    }
    if (keysDown() & KEY_B) {
      std::string fileName = state.notebookName + "/notes.txt";
      saveFile(fileName.c_str(), state.notebook);
    }
    if (keysDown() & KEY_LEFT) {
      state.scroll_x-=50;
      updateCenter(state);
    }
    if (keysDown() & KEY_RIGHT) {
      state.scroll_x+=50;
      updateCenter(state);
    }
    if (keysDown() & KEY_UP) {
      state.scroll_y-=50;
      updateCenter(state);
    }
    if (keysDown() & KEY_DOWN) {
      state.scroll_y+=50;
      updateCenter(state);
    }
    if (keysDown() & KEY_START) {
      uiOpenNotebook(state);
    }

    swiWaitForVBlank();
  }
}
Exemple #16
0
 void uiOpenNotebook(AppState & state) {
   lcdMainOnTop();

   DIR_ITER* dir = diropen (MAINPATH);
   if (dir == NULL) {
     printf("Marginalia data not found\n");
     return;
   }

   printf("\x1b[2J");
   printf("Select notebook to open\n(Press Select to create NEW)");

   struct stat st;
   char filename[MAXPATHLEN];
   int i=0;

   std::vector<std::string> notebooks;

   while (dirnext(dir, filename, &st) == 0) {
     // st.st_mode & S_IFDIR indicates a directory
     // if (!(st.st_mode & S_IFDIR))
     //   continue;
     // if (strcmp(filename, "..") == 0)
     //   continue;
     // if (strcmp(filename, ".") == 0)
     //   continue;
     printf ("\x1b[%d;3H%d)   %s\n", i+3, i, filename);
     notebooks.push_back(filename);
     i++;
   }
   dirclose (dir);
   int selected = 0;
   printf ("\x1b[%d;6H*", selected+3);
   
   while (1) {
    scanKeys();
    
    if(keysHeld() & KEY_TOUCH)
      {
      }    
    if (keysDown() & KEY_X) {
    }
    if (keysDown() & KEY_Y) {
    }
    if (keysDown() & KEY_SELECT) {
      printf ("\x1b[10;1H Insert new Directory Name");
      char newName[256];

      Keyboard *kbd =  keyboardDemoInit();

      scanf("%s", newName);
      printf ("\x1b[11;1H Creating directory %s", newName);

      state.notebookName = newName;
      if (mkdir(state.notebookName.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0) {
	printf ("\x1b[12;1H directory creation failed");
	continue;
      }
      
      state.lastPage = -1;
      state.scroll_x = 0;
      state.scroll_y = 0;

      state.center_x = MY_BG_W/2;
      state.center_y = MY_BG_H/2;

      fillDisplay(RGB15(0,0,0) | BIT(15), 0, state);

      std::string fileName = state.notebookName + "/notes.txt";
      state.notebook = loadFile(fileName.c_str());
      state.currentPage = &(state.notebook.pages[0]);

      drawPage(state.currentPage, RGB15(31,31,31) | BIT(15), state);
      lcdMainOnBottom();
      return;
    }
    if (keysDown() & KEY_A) {
      printf ("\x1b[20;6H opening %s\n", notebooks[selected].c_str());
      state.lastPage = -1;
      state.scroll_x = 0;
      state.scroll_y = 0;

      state.center_x = MY_BG_W/2;
      state.center_y = MY_BG_H/2;

      state.notebookName = notebooks[selected];

      fillDisplay(RGB15(0,0,0) | BIT(15), 0, state);

      std::string fileName = state.notebookName + "/notes.txt";
      state.notebook = loadFile(fileName.c_str());
      state.currentPage = &(state.notebook.pages[0]);

      drawPage(state.currentPage, RGB15(31,31,31) | BIT(15), state);
      lcdMainOnBottom();
      return;
    }
    if (keysDown() & KEY_B) {
    }
    if (keysDown() & KEY_LEFT) {
    }
    if (keysDown() & KEY_RIGHT) {
    }
    if (keysDown() & KEY_UP) {
      printf ("\x1b[%d;6H ", selected+3);
      selected -= 1;
      printf ("\x1b[%d;6H*", selected+3);
    }
    if (keysDown() & KEY_DOWN) {
      printf ("\x1b[%d;6H ", selected+3);
      selected += 1;
      printf ("\x1b[%d;6H*", selected+3);
    }

    swiWaitForVBlank();
  }
 }
Exemple #17
0
int main() {
    /* Turn on the 2D graphics core. */
    powerOn(POWER_ALL_2D);

    /*
     *  Configure the VRAM and background control registers.
     *
     *  Place the main screen on the bottom physical screen. Then arrange the
     *  VRAM banks. Next, confiure the background control registers.
     */
    lcdMainOnBottom();
    initVideo();
    initBackgrounds();

    /* Initialize maxmod using the memory based soundbank set up. */
    mmInitDefaultMem((mm_addr)soundbank_bin);

    /* Set up a few sprites. */
    SpriteInfo spriteInfo[SPRITE_COUNT];
    OAMTable *oam = new OAMTable();
    initOAM(oam);
    initSprites(oam, spriteInfo);

    /* Display the backgrounds. */
    displayStarField();
    displayPlanet();
    displaySplash();

    /*************************************************************************/

    /* Keep track of the touch screen coordinates. */
    touchPosition touch;

    /* Make the ship object. */
    static const int SHUTTLE_OAM_ID = 0;
    SpriteEntry * shipEntry = &oam->oamBuffer[SHUTTLE_OAM_ID];
    SpriteRotation * shipRotation = &oam->matrixBuffer[SHUTTLE_OAM_ID];
    Ship * ship = new Ship(&spriteInfo[SHUTTLE_OAM_ID]);

    /* Make the moon. */
    static const int MOON_OAM_ID = 1;
    SpriteEntry * moonEntry = &oam->oamBuffer[MOON_OAM_ID];
    SpriteInfo * moonInfo = &spriteInfo[MOON_OAM_ID];
    MathVector2D<int> * moonPos = new MathVector2D<int>();
    moonPos->x = moonEntry->x;
    moonPos->y = moonEntry->y;

    /* Set up sound data. */
    mmLoadEffect(SFX_THRUST);

    for (;;) {
        /* Update the game state. */
        updateInput(&touch);
        handleInput(ship, moonPos, moonInfo, &touch);
        ship->moveShip();

        /* Update ship sprite attributes. */
        MathVector2D<float> position = ship->getPosition();
        shipEntry->x = (int)position.x;
        shipEntry->y = (int)position.y;
        rotateSprite(shipRotation, -ship->getAngleDeg());
        /* Update moon sprite attributes. */
        moonEntry->x = (int)moonPos->x;
        moonEntry->y = (int)moonPos->y;

        /*
         *  Update the OAM.
         *
         *  We have to copy our copy of OAM data into the actual OAM during
         *  VBlank (writes to it are locked during other times).
         */
        swiWaitForVBlank();
        updateOAM(oam);
    }

    return 0;
}
Exemple #18
0
int main(void) 
{
	mmInitDefaultMem((mm_addr)soundbank_bin);

	//set video mode and map vram to the background
	videoSetMode(MODE_0_2D | DISPLAY_BG0_ACTIVE | 
                 DISPLAY_SPR_1D_LAYOUT | 
                 DISPLAY_SPR_ACTIVE);
    
	vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
    vramSetBankB(VRAM_B_MAIN_SPRITE);

	//set video mode and map vram to the background
	videoSetModeSub(MODE_1_2D | DISPLAY_BG1_ACTIVE | 
                 DISPLAY_SPR_1D_LAYOUT | 
                 DISPLAY_SPR_ACTIVE);

	vramSetBankD(VRAM_D_MAIN_BG_0x06000000);
    vramSetBankE(VRAM_E_MAIN_SPRITE);

    lcdMainOnBottom();

#ifdef BBDEBUG
    consoleDemoInit();
#endif

    sound s;
    s.load_bank(0);

    sprites spr;
	machine m(&s);
    machine_view mv(&spr);
#ifndef BBDEBUG
    thread_view tv;
#endif
    cursor c(&m,&spr);
    pointer p(&spr);
    iprintf("%d\n",list::unit_test());

    int frame=0;
    int x=0;
    int y=0;
    int tx=0;
    int ty=0;
    int dx=0;
    int dy=0;
    int touchedlast=0;

    int tempo=2;
    int bank=0;
    u8 flip=0;
    u8 flip_count=1;
	irqEnable( IRQ_VCOUNT );

	while(1)
	{
		// wait until line 0
		swiIntrWait( 0, IRQ_VCOUNT);

        u32 t=tempo;
        //t=t/(flip+1);
        //iprintf("%d\n",t);
        
        if (tempo==0 || frame%t==0) 
        {
            m.run();
            /*    flip_count--;
            if (flip_count==0)
            {
                flip_count=4;
                if (flip) flip=0;
                else flip=1;
                }*/
        }
		scanKeys();
        frame++;
        touchPosition touch;
        touchRead(&touch);

        if (keysDown() & KEY_UP) m.slow_down_closest(c.get_cursor_addr());
        if (keysDown() & KEY_DOWN) m.speed_up_closest(c.get_cursor_addr());
        if (tempo<0) tempo=0;

        if (keysDown() & KEY_L) sound_check(m);

        if (keysDown() & KEY_LEFT) { bank--; s.load_bank(bank); }
        if (keysDown() & KEY_RIGHT) { bank++; s.load_bank(bank); }
 
        if(keysDown() & KEY_TOUCH)
        {
            tx=touch.px;
            ty=touch.py;
            if (!c.touch(tx,ty,&p))
            {
                touchedlast=1;
            }
        }
        else if(keysHeld() & KEY_TOUCH)
		{				
            if (!c.menu_shown() &&
                !c.drag(touch.px+x,touch.py+y,(touch.px+x)/16,(touch.py+y)/16))
            {
                if (touchedlast>0) touchedlast++;
                x+=tx-touch.px;
                y+=ty-touch.py;
                tx=touch.px;
                ty=touch.py;
            }
        }

        if (keysUp() & KEY_TOUCH)
        {
            if (touchedlast>0 && touchedlast<5)
            {
                int lx=(tx+x)/16;
                int ly=(ty+y)/16;
                c.set_pos(lx,ly,lx*16,ly*16);
            }
            touchedlast=0;
        }       

        if (keysUp() & KEY_A)
        {
            for (u32 i=0; i<HEAP_SIZE; i++)
            {
                m.poke(i,rand());
            }
        }
        
        c.update(x,y);
        if (c.menu_shown()) 
        {
            dx=c.get_x()-128;
            dy=c.get_y()-82;
            if (dx!=x) x+=(dx-x)*0.1;
            if (dy!=y) y+=(dy-y)*0.1; 
        }

        p.update(x,y,&m);
        REG_BG0HOFS = x;
        REG_BG0VOFS = y;
        spr.update();
        mv.update(x,y,&m);
        s.update();
#ifndef BBDEBUG
        tv.update(&m);
#endif
        BG_PALETTE_SUB[0]=13<<10;
		swiWaitForVBlank();
        BG_PALETTE_SUB[0]=31;

	}
		
	return 0;
}
Exemple #19
0
int main() {
    /* Turn on the 2D graphics core. */
    powerOn(POWER_ALL_2D);

    /*
     *  Configure the VRAM and background control registers.
     *
     *  Place the main screen on the bottom physical screen. Then arrange the
     *  VRAM banks. Next, confiure the background control registers.
     */
    lcdMainOnBottom();
    initVideo();
    initBackgrounds();
    consoleDemoInit();
    

    /* Set up a few sprites. */
    SpriteInfo spriteInfo[SPRITE_COUNT];
    oam = new OAMTable();
    initOAM(oam);
    //initSprites(oam, spriteInfo);
    OAM_Manager oam_manager (spriteInfo,oam);
    Jogador jogador (spriteInfo, &oam_manager);
    jogador.initGfx ();

    NPC npc (spriteInfo, &oam_manager);
    npc.initGfx ();


    /*
     *  Update the OAM.
     *
     *  We have to copy our copy of OAM data into the actual OAM during VBlank
     *  (writes to it are locked during other times).
     */
    swiWaitForVBlank();
    updateOAM(oam);

    /* Loop forever so that the Nintendo DS doesn't reboot upon program
     * completion. */
    controle.reset ();
    for (;;) {
        consoleClear ();
        
        /* Update the game state. */
        updateInput();
        handleInput();

        jogador.update (&controle);
        npc.update (NULL);

       
        
        /*
         *  Update the OAM.
         *
         *  We have to copy our copy of OAM data into the actual OAM during
         *  VBlank (writes to it are locked during other times).
         */
        swiWaitForVBlank();
        updateOAM(oam);
    }

    return 0;
}
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------

	int i = 0;
	
	videoSetMode(MODE_0_2D);
	videoSetModeSub(0);   // not using subscreen

	lcdMainOnBottom();
	
	//initialize the sprite engine with 1D mapping 128 byte boundary
	//and no external palette support
	oamInit(&oamMain, SpriteMapping_1D_32, false);

	vramSetBankA(VRAM_A_MAIN_SPRITE);
	
	for (i = 0; i < 5; i++) {
		//allocate some space for the sprite graphics
		sprites[i].gfx = oamAllocateGfx(&oamMain, sprites[i].size, sprites[i].format);

		//fill each sprite with a different index (2 pixels at a time)
		dmaFillHalfWords( ((i+1)<<8)|(i+1), sprites[i].gfx, 32*32);
	}

	//set indexes to different colours
	SPRITE_PALETTE[1] = RGB15(31,0,0);
	SPRITE_PALETTE[2] = RGB15(0,31,0);
	SPRITE_PALETTE[3] = RGB15(0,0,31);
	SPRITE_PALETTE[4] = RGB15(31,0,31);
	SPRITE_PALETTE[5] = RGB15(0,31,31);

	// initialise maxmod using default settings, and enable interface for soundbank that is loaded into memory
	mmInitDefaultMem( (mm_addr)mmsolution_bin );

	// setup maxmod to use the song event handler
	mmSetEventHandler( myEventHandler );
	
	// load song
	// values for this function are in the solution header
	mmLoad( MOD_EXAMPLE2 );

	// start song playing
	mmStart( MOD_EXAMPLE2, MM_PLAY_LOOP );

	while(1) {
		for (i=0; i < 5; i++) {
			// constantly increase the sprite's y velocity
			sprites[i].dy += 1;
		
			// update the sprite's y position with its y velocity
			sprites[i].y += sprites[i].dy;
		
			// clamp the sprite's y position
			if ( sprites[i].y<72 ) sprites[i].y = 72;
			if ( sprites[i].y>96 ) sprites[i].y = 96;
		
			oamSet(	&oamMain, 					//main graphics engine context
					i,           				//oam index (0 to 127)  
					sprites[i].x,				//x and y pixel location of the sprite
					sprites[i].y, 			
					0,							//priority, lower renders last (on top)
					sprites[i].paletteAlpha,	//palette index 
					sprites[i].size,
					sprites[i].format,
					sprites[i].gfx,				//pointer to the loaded graphics
					sprites[i].rotationIndex,	//sprite rotation data  
					false,						//double the size when rotating?
					false,			//hide the sprite?
					false, false, //vflip, hflip
					false	//apply mosaic
					);              
			}

		swiWaitForVBlank();
		
		//send the updates to the hardware
		oamUpdate(&oamMain);
	}

	return 0;
}
Exemple #21
0
int main() {
	touchPosition touch;
	PrintConsole mainScreen;
	mySprite sprites[128];
	
	lcdMainOnBottom();
	initVideo();
	initBackgrounds();
	initConsole(&mainScreen);
	initSprites(sprites);
	
	//leftButtonOff
	oamSet(&oamMain, sprites[0].id, sprites[0].x, sprites[0].y, 0, 0, SpriteSize_64x64,
		SpriteColorFormat_16Color, sprites[0].gfx, -1, false, false, false, false, false);
	//rightButtonOff
	oamSet(&oamMain, sprites[2].id, sprites[2].x, sprites[2].y, 0, 0, SpriteSize_64x64,
		SpriteColorFormat_16Color, sprites[2].gfx, -1, false, false, false, false, false);
	
	int keys = keysDown();
	int currentSprite = 4;
	int moveLeft = 0;
	int moveRight = 0;
	int MOVE_SPEED = 21;
	while (true) {
		//consoleClear();
		scanKeys();
		touchRead(&touch);
		keys = keysHeld();
		
		if (keys) {
			if (keys & KEY_TOUCH) {
				touchRead(&touch);
				if (within(&touch, sprites[0])) {
					// leftButton clicked
					// leftButtonOn
					oamClearSprite(&oamMain, 0);
					oamSet(&oamMain, sprites[1].id, sprites[1].x, sprites[1].y, 0, 1, SpriteSize_64x64,
						SpriteColorFormat_16Color, sprites[1].gfx, -1, false, false, false, false, false);
					swiWaitForVBlank();
					oamUpdate(&oamMain);
					moveLeft = 1;
				}
				else if (within(&touch, sprites[2])) {
					// rightButton clicked
					// rightButtonOn
					oamClearSprite(&oamMain, 2);
					oamSet(&oamMain, sprites[3].id, sprites[3].x, sprites[3].y, 0, 1, SpriteSize_64x64,
						SpriteColorFormat_16Color, sprites[3].gfx, -1, false, false, false, false, false);
					swiWaitForVBlank();
					oamUpdate(&oamMain);
					moveRight = 1;
				}
				else if(within(&touch, sprites[currentSprite])) {
					mmEffectEx(&sprites[currentSprite].sfx);
				}
			}
		}
		else {
			//leftButtonOff
			oamClearSprite(&oamMain, 1);
			oamSet(&oamMain, sprites[0].id, sprites[0].x, sprites[0].y, 0, 0, SpriteSize_64x64,
				SpriteColorFormat_16Color, sprites[0].gfx, -1, false, false, false, false, false);
			//rightButtonOff
			oamClearSprite(&oamMain, 3);
			oamSet(&oamMain, sprites[2].id, sprites[2].x, sprites[2].y, 0, 0, SpriteSize_64x64,
				SpriteColorFormat_16Color, sprites[2].gfx, -1, false, false, false, false, false);
				
			if (moveLeft) {
				if ((currentSprite - 1) >= 4) {
					// move current sprite to the right and new one in from left
					int x1 = sprites[currentSprite].x;
					int x2 = -64;
					
					while (x1 < 280 || x2 < 96) {
						oamSet(&oamMain, sprites[currentSprite].id, x1, 
							sprites[currentSprite].y, 0, sprites[currentSprite].paletteAlpha, 
							SpriteSize_64x64, SpriteColorFormat_16Color, sprites[currentSprite].gfx, 
							-1, false, false, false, false, false);
						oamSet(&oamMain, sprites[currentSprite-1].id, x2, sprites[currentSprite-1].y,
							0, sprites[currentSprite-1].paletteAlpha, SpriteSize_64x64,
							SpriteColorFormat_16Color, sprites[currentSprite-1].gfx, -1, false, false,
							false, false, false);
						swiWaitForVBlank();
						oamUpdate(&oamMain);
						x1 += MOVE_SPEED;
						x2 += MOVE_SPEED;
					}
					currentSprite--;
				}
				moveLeft = 0;
			}
			else if (moveRight) {
				if ((currentSprite + 1) - SPRITECOUNT < 0) {
					// move current sprite to the left and new one from right
					int x1 = sprites[currentSprite].x;
					int x2 = 256;
					
					while (x1 > -80 || x2 > 96) {
						oamSet(&oamMain, sprites[currentSprite].id, x1, 
							sprites[currentSprite].y, 0, sprites[currentSprite].paletteAlpha, 
							SpriteSize_64x64, SpriteColorFormat_16Color, sprites[currentSprite].gfx, 
							-1, false, false, false, false, false);
						oamSet(&oamMain, sprites[currentSprite+1].id, x2, sprites[currentSprite+1].y,
							0, sprites[currentSprite+1].paletteAlpha, SpriteSize_64x64,
							SpriteColorFormat_16Color, sprites[currentSprite+1].gfx, -1, false, false,
							false, false, false);
						swiWaitForVBlank();
						oamUpdate(&oamMain);
						x1 -= MOVE_SPEED;
						x2 -= MOVE_SPEED;
					}
					currentSprite++;
				}
				moveRight = 0;
			}
		}
		
		//oamSet(oam, id, x, y, priority, palette_alpha, size, colorformat, gfxOffset, affineIndex,
		//sizedouble, hide, hflip, vflip, mosaic);
		//
		//gong
		consoleClear();
		printf("\x1b[3;3H%s", sprites[currentSprite].desc);
		oamSet(&oamMain, sprites[currentSprite].id, sprites[currentSprite].x, sprites[currentSprite].y, 0, sprites[currentSprite].paletteAlpha, SpriteSize_64x64, SpriteColorFormat_16Color,
			sprites[currentSprite].gfx, -1, false, false, false, false, false);
			
		swiWaitForVBlank();
		oamUpdate(&oamMain);	
	}
}
Exemple #22
0
//-------------------------------------------------------
int main() {		
//-------------------------------------------------------
 
	videoSetMode(MODE_0_3D);
	videoSetModeSub(MODE_5_2D);
 
	glInit();
 
	// sub sprites hold the bottom image when 3D directed to top
	initSubSprites();
 
	// sub background holds the top image when 3D directed to bottom
	bgInitSub(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0);
 
//-------------------------------------------------------
//	 Setup gl
//-------------------------------------------------------
	glEnable(GL_ANTIALIAS);
 
	glClearColor(0,0,0,31); 
	glClearPolyID(63);
	glClearDepth(0x7FFF);
 
	glViewport(0,0,255,191);
 
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(70, 256.0 / 192.0, 0.1, 100);
 
	glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE);
 
//-------------------------------------------------------
//	 main loop
//-------------------------------------------------------
	bool top = true;
 
	while (true) 
	{
		// wait for capture unit to be ready
		while(REG_DISPCAPCNT & DCAP_ENABLE);
 
		scanKeys();
		int keys = keysDown();
		if (keys & KEY_START) break;

		//-------------------------------------------------------
		//	 Switch render targets
		//-------------------------------------------------------
		top = !top;
 
		if(top)
		{
			lcdMainOnBottom();
			vramSetBankC(VRAM_C_LCD);
			vramSetBankD(VRAM_D_SUB_SPRITE);
			REG_DISPCAPCNT = DCAP_BANK(2) | DCAP_ENABLE | DCAP_SIZE(3);
		}
		else
		{
			lcdMainOnTop();
			vramSetBankD(VRAM_D_LCD);
			vramSetBankC(VRAM_C_SUB_BG);
			REG_DISPCAPCNT = DCAP_BANK(3) | DCAP_ENABLE | DCAP_SIZE(3);
		}
 
		//-------------------------------------------------------
		//	 Render the scene
		//-------------------------------------------------------
		glMatrixMode(GL_MODELVIEW);
 
		renderScene(top);
 
		glFlush(0);

	}
 
	return 0;
}
Exemple #23
0
static int opt_screen (const int sel)
{
    emu_screen = sel;
    (sel) ? lcdMainOnBottom() : lcdMainOnTop();
    return 1;
}
Exemple #24
0
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;
}
Exemple #25
0
int main(void)
{
    touchPosition touch;

    defaultExceptionHandler();

    lcdMainOnBottom();
    irqEnable(IRQ_VBLANK);

    videoSetMode(MODE_FB0);
    vramSetBankA(VRAM_A_LCD);

    consoleDemoInit();

    ClearScreen();

    touchPosition firstTouch = { 0, 0 };
    touchPosition lastTouch = { 0, 0 };

    int colours[3] = { 31, 31, 31 };
    int colourIndex = 0;

    printf("RGB15(%d,%d,%d)\n",colours[0],colours[1],colours[2]);

    std::stack<node*>* path = NULL;
    bool searched = false;

    node start(10,10,NULL);
    node target(244,180,NULL);

    Robot robot;
    robot.setPosition(start.x,start.y);

    int nextTouch = 0;

    //we like infinite loops in console dev!
    while(1)
    {
        swiWaitForVBlank();

        scanKeys();
        touchRead(&touch);

        int kd = keysDown();
        if (kd & KEY_A)
        {
            ClearScreen();
        }

        if (kd & KEY_UP)
        {
            ++colours[colourIndex];
            if (colours[colourIndex] > 31) colours[colourIndex] = 0;
            printf("RGB15(%d,%d,%d)\n",colours[0],colours[1],colours[2]);
        }

        if (kd & KEY_DOWN)
        {
            --colours[colourIndex];
            if (colours[colourIndex] < 0) colours[colourIndex] = 31;
            printf("RGB15(%d,%d,%d)\n",colours[0],colours[1],colours[2]);
        }

        if (kd & KEY_LEFT)
        {
            --colourIndex;
            if (colourIndex < 0) colourIndex = 2;
        }

        if (kd & KEY_RIGHT)
        {
            ++colourIndex;
            if (colourIndex > 2) colourIndex = 0;
        }

        if (kd & KEY_Y)
        {
            robot.setPosition(start.x,start.y);
            path = NULL;
            node::cleanup();
        }

        if(kd & KEY_B)
        {
            printf("Working...\n");
            searched = true;
            node current(robot.getPosition().px, robot.getPosition().py,NULL);
            path = astar::generate_path( astar::search(&current,&target) );
            printf("Path found!\n");
        }

        if (kd & KEY_R)
        {
            nextTouch = 2;
        }

        if (kd & KEY_L)
        {
            nextTouch = 1;
        }

        if(kd & KEY_TOUCH)
        {
            switch (nextTouch)
            {
            case 0:
                firstTouch = touch;
                draw::plot(touch.px,touch.py,RGB15(colours[0],colours[1],colours[2]));
                break;
            case 1: // Set start
                start.x = touch.px;
                start.y = touch.py;
                robot.setPosition(touch);
                break;
            case 2: // Set target
                target.x = touch.px;
                target.y = touch.py;
                break;
            default:
                break;
            }
        }

        if(keysHeld() & KEY_TOUCH)
        {
            if (nextTouch == 0)
            {
                lastTouch = touch;
                draw::line(firstTouch.px, firstTouch.py, lastTouch.px, lastTouch.py, RGB15(colours[0],colours[1],colours[2]));
                firstTouch = touch;
                //q.push(touch);
            }
        }

        if (keysUp() & KEY_TOUCH)
        {
            nextTouch = 0;
        }

        if (path)
        {
            if (searched && !path->empty())
            {
                assert(path != NULL);
                assert(path->top() != NULL);
                robot.move(path->top()->x, path->top()->y);

                if (robot.getPosition().px == path->top()->x && robot.getPosition().py == path->top()->y) path->pop();
            }
            else if (path->empty())
            {
                node::cleanup();
                delete path;
                path = NULL;
                searched = false;
            }
        }
        robot.draw();

        draw::plot(target.x, target.y, RGB15(31,0,0));
        draw::plot(target.x+1, target.y, RGB15(31,0,0));
        draw::plot(target.x+2, target.y, RGB15(31,0,0));
        draw::plot(target.x-1, target.y, RGB15(31,0,0));
        draw::plot(target.x-2, target.y, RGB15(31,0,0));
        draw::plot(target.x, target.y+1, RGB15(31,0,0));
        draw::plot(target.x, target.y+2, RGB15(31,0,0));
        draw::plot(target.x, target.y-1, RGB15(31,0,0));
        draw::plot(target.x, target.y-2, RGB15(31,0,0));
        draw::plot(target.x+1, target.y+1, RGB15(31,0,0));
        draw::plot(target.x+1, target.y-1, RGB15(31,0,0));
        draw::plot(target.x-1, target.y+1, RGB15(31,0,0));
        draw::plot(target.x-1, target.y-1, RGB15(31,0,0));

    }

    return 0;
}
int main()
{	

	// initialize gl
	glInit();

	u32 rotateX = 0;
	u32 rotateY = 0;

	//set mode 0, enable BG0 and set it to 3D
	videoSetMode(MODE_0_3D);
	
	// used to hold touched position
	touchPosition touchXY;
	
	lcdMainOnBottom(); // we are going to be touching the 3D display

	
	// enable edge outlining, this will be used to show which object is selected
	glEnable(GL_OUTLINE);
	
	//set the first outline color to white
	glSetOutlineColor(0,RGB15(31,31,31));
	
	int viewport[]={0,0,255,191}; // used later for gluPickMatrix()
	
	// setup the rear plane
	glClearColor(0,0,0,0); // set BG to black and clear
	glClearPolyID(0); // the BG and polygons will have the same ID unless a polygon is highlighted
	glClearDepth(0x7FFF);
	
	// setup the camera
	gluLookAt(	0.0, 0.0, 1.0,		//camera possition 
				0.0, 0.0, 0.0,		//look at
				0.0, 1.0, 0.0);		//up
	
	glLight(0, RGB15(31,31,31) , 0, floattov10(-1.0), 0); // setup the light
	
	while(1) {
		// handle key input
		scanKeys();
		u16 keys = keysHeld();
		if(!(keys & KEY_UP)) rotateX += 3;
		if(!(keys & KEY_DOWN)) rotateX -= 3;
		if(!(keys & KEY_LEFT)) rotateY += 3;
		if(!(keys & KEY_RIGHT)) rotateY -= 3;
		
		// get touchscreen position
		touchRead(&touchXY);
		
		glViewport(0,0,255,191); // set the viewport to fullscreen
		
		// setup the projection matrix for regular drawing
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective(60, 256.0 / 192.0, 0.1, 20); 
		
		glMatrixMode(GL_MODELVIEW); // use the modelview matrix while drawing
		
		glPushMatrix(); // save the state of the current matrix(the modelview matrix)
		{
			glTranslatef32(0,0,floattof32(-6));
			glRotateXi(rotateX); // add X rotation to the modelview matrix
			glRotateYi(rotateY); // add Y rotation to the modelview matrix
			
			glPushMatrix(); // save the state of the modelview matrix while making the first pass
			{ 
				// draw the scene for displaying
				
				glTranslatef32(floattof32(2.9),floattof32(0),floattof32(0)); // translate the modelview matrix to the drawing location
				if(clicked==CONE) {
					glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(1)); // set a poly ID for outlining
				} else {
					glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(0)); // set a poly ID for no outlining (same as BG)
				}
				glCallList((u32*)cone_bin); // draw a green cone from a predefined packed command list
				
				
				glTranslatef32(floattof32(-3),floattof32(1.8),floattof32(2)); // translate the modelview matrix to the drawing location
				if(clicked==CYLINDER) {
					glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(1)); // set a poly ID for outlining
				} else {
					glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(0)); // set a poly ID for no outlining (same as BG)
				}
				glCallList((u32*)cylinder_bin); // draw a blue cylinder from a predefined packed command list
				
				
				glTranslatef32(floattof32(.5),floattof32(-2.6),floattof32(-4)); // translate the modelview matrix to the drawing location
				if(clicked==SPHERE) {
					glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(1)); // set a poly ID for outlining
				} else {
					glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(0)); // set a poly ID for no outlining (same as BG)
				}
				glCallList((u32*)sphere_bin); // draw a red sphere from a predefined packed command list

			}
			glPopMatrix(1); // restores the modelview matrix to where it was just rotated
			
			// draw the scene again for picking
			{
				
				clicked = NOTHING; //reset what was clicked on
				closeW = 0x7FFFFFFF; //reset the distance
				
				//set the viewport to just off-screen, this hides all rendering that will be done during picking
				glViewport(0,192,0,192);
				
				// setup the projection matrix for picking
				glMatrixMode(GL_PROJECTION);
				glLoadIdentity();
				gluPickMatrix((touchXY.px),(191-touchXY.py),4,4,viewport); // render only what is below the cursor
				gluPerspective(60, 256.0 / 192.0, 0.1, 20); // this must be the same as the original perspective matrix
				
				glMatrixMode(GL_MODELVIEW); // switch back to modifying the modelview matrix for drawing
				
				glTranslatef32(floattof32(2.9),floattof32(0),floattof32(0)); // translate the modelview matrix to the drawing location
				startCheck();
				glCallList((u32*)cone_bin); // draw a cone from a predefined packed command list
				endCheck(CONE);
				
				glTranslatef32(floattof32(-3),floattof32(1.8),floattof32(2)); // translate the modelview matrix to the drawing location
				startCheck();
				glCallList((u32*)cylinder_bin); // draw a cylinder from a predefined packed command list
				endCheck(CYLINDER);
				
				glTranslatef32(floattof32(.5),floattof32(-2.6),floattof32(-4)); // translate the modelview matrix to the drawing location
				startCheck();
				glCallList((u32*)sphere_bin); // draw a sphere from a predefined packed command list
				endCheck(SPHERE);
			}
			
		}
		glPopMatrix(1); // restores the modelview matrix to its original state
		
		glFlush(0); // wait for everything to be drawn before starting on the next frame
	}

	return 0;
}//end main