//////////////////////////////////////////////////////////////////////
// Simple ARM9 demo (touch screen controls the colors)
// -- joat
//////////////////////////////////////////////////////////////////////
#include <NDS/NDS.h>
#include <NDS/memory.h>
#include <NDS/ARM9/rand.h>
#include <NDS/ARM9/video.h>
#include <NDS/ARM9/trig_lut.h>
//////////////////////////////////////////////////////////////////////
void pltpoint(int x, int y, int c, uint16 *vram);
void circle(int x, int y, int r, int c, uint16 *vram);
volatile unsigned int counter = 0;
void InterruptHandler(void) {
if (IF & IRQ_VBLANK) {
counter++;
IF = IRQ_VBLANK;
}
}
//////////////////////////////////////////////////////////////////////
#define KEY_TOUCH (((~IPC->buttons) << 6) & (1<<12))
int main(int argc, char ** argv) {
// Red main screen, blue sub-screen
PALETTE[0] = RGB15(0, 0, 31);
PALETTE[512] = RGB15(0, 0, 31);
// Turn on the screens and 2D cores and switch to mode 0
POWER_CR = POWER_ALL_2D;
DISPLAY_CR = MODE_FB0;
SUB_DISPLAY_CR = MODE_0_2D | DISPLAY_BG0_ACTIVE;
SUB_BG0_CR = BG_COLOR_256 | (1 << SCREEN_SHIFT);
SUB_BG1_CR = BG_COLOR_256 | (2 << SCREEN_SHIFT);
vramSetMainBanks(VRAM_A_LCD,VRAM_B_LCD,VRAM_C_SUB_BG,VRAM_D_SUB_SPRITE);
// Enable the V-blank interrupt
IME = 0;
IRQ_HANDLER = &InterruptHandler;
IE = IRQ_VBLANK;
IF = ~0;
DISP_SR = DISP_VBLANK_IRQ;
IME = 1;
int tx=64;
int ty=157;
int touched=0;
// Touchscreen calibration
int divx = 14;
int divy = 18;
int subx = 00;
int suby = 12;
uint16* vram = VRAM_A;
while (1)
{
if(counter > 0)
{
counter = 0;
if(KEY_TOUCH)
{
if(0 == 0)
{
touched = 1;
tx = IPC->touchX / divx - subx;
ty = IPC->touchY / divy - suby;
}
}
else
touched = 0;
dmaCopyWords(3, (uint32 *)VRAM_C, (uint32 *)vram, 256*192*2);
if (tx > 33 & ty > 3 & tx < 96 & ty <65 ) { circle(64,35,29, RGB15(0, 0, 31), vram); }
if (tx > 97 & ty > 3 & tx < 159 & ty < 65) { circle(126,35,29, RGB15(0, 0, 31), vram); }
if (tx > 160 & ty > 3 & tx < 222 & ty < 65) { circle(188,35,29, RGB15(0, 0, 31), vram); }
if (tx > 33 & ty > 3+62 & tx < 96 & ty <65+62 ) { circle(64,34+62,29, RGB15(0, 0, 31), vram); }
if (tx > 97 & ty > 3+62 & tx < 159 & ty < 65+62) { circle(126,34+62,29, RGB15(0, 0, 31), vram); }
if (tx > 160 & ty > 3+62 & tx < 222 & ty < 65+62) { circle(188,34+62,29, RGB15(0, 0, 31), vram); }
if (tx > 33 & ty > 3+62+62 & tx < 96 & ty <65+62+62 ) { circle(64,34+62+61,29, RGB15(0, 0, 31), vram); }
if (tx > 97 & ty > 3+62+62 & tx < 159 & ty < 65+62+62) { circle(126,34+62+61,29, RGB15(0, 0, 31), vram); }
if (tx > 160 & ty > 3+62+62 & tx < 222 & ty < 65+62+62) { circle(188,34+62+61,29, RGB15(0, 0, 31), vram); }
// geef touchscreen achtergrond een andere kleur
/*
for(int i=0; i<256*192; i++)
{
VRAM_C[i] = RGB15(15,15,15);
}*/
//---------------------------------------------------------------------
// my space
for(int n=34; n<220; n++) { vram[n+4*256] = RGB15(31,0,0); }
for(int n=34; n<220; n++) { vram[n+65*256] = RGB15(31,0,0); }
for(int n=34; n<220; n++) { vram[n+126*256] = RGB15(31,0,0); }
for(int n=34; n<220; n++) { vram[n+187*256] = RGB15(31,0,0); }
for(int n=4; n<187; n++) { vram[n*256+33] = RGB15(31,0,0); }
for(int n=4; n<187; n++) { vram[n*256+95] = RGB15(31,0,0); }
for(int n=4; n<187; n++) { vram[n*256+157] = RGB15(31,0,0); }
for(int n=4; n<187; n++) { vram[n*256+219] = RGB15(31,0,0); }
//myspace
//---------------------------------------------------------------------
}
}
return 0;
}
void circle(int x, int y, int r, int c, uint16 *vram)
{
for(int a=0; a<512; a+=4)
{
pltpoint(x+((COS[a]*r)>>12),y+((SIN[a]*r)>>12),c,vram);
}
}
inline void pltpoint(int x, int y, int c, uint16 *vram)
{
int n = y*256+x;
if(n > 256*192 || n<0)
return;
vram[y*256 + x] = c;
}
//////////////////////////////////////////////////////////////////////
|