gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Touch screen drawing demo

#108888 - outphase - Sun Nov 12, 2006 6:00 pm

I'm working on a project for school demonstrating assorted DS functions. I wanted to make a little touch screen notepad demo. Is there any way to speed this up so there is a continuous line? Thanks.

Code:
int main(void) {
//---------------------------------------------------------------------------------
   touchPosition touchXY;
   

   irqInit();
   irqSet(IRQ_VBLANK, Vblank);
   irqEnable(IRQ_VBLANK);
   videoSetMode(MODE_FB0);   //Text on main screen
   videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);   //Frame Buffer
   //vramSetBankC(VRAM_C_SUB_BG);
   
   vramSetMainBanks(   VRAM_A_LCD, VRAM_B_LCD,
                  VRAM_C_SUB_BG , VRAM_D_LCD);

   lcdSwap();
   BG0_CR = BG_MAP_BASE(31);//use bg0 for the text
   
   BG_PALETTE[255] = RGB15(31,31,31);//by default font rendered with color 255
   
   SUB_BG0_CR = BG_MAP_BASE(31);
   
   BG_PALETTE_SUB[255] = RGB15(31,31,31);   //by default font will be rendered with color 255

   
   //consoleInit() is a lot more flexible but this gets you up and running quick
   consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);
   consoleClear();

   iprintf("EE464 Project\nProof of Concept\nTouch Pad Demo\n\n");
   iprintf("Press Start to clear screen\n");
   iprintf("Press A to flood");

   for(int i = 0; i < 256*192; i++)
      VRAM_A[i] = RGB15(0,0,0);

   while(1) {
   
      
      swiWaitForVBlank();
      
      scanKeys();
      touchXY=touchReadXY();
      int held = keysHeld();
      
      if(held&KEY_TOUCH)
         VRAM_A[(touchXY.px) + (touchXY.py) * 256]=RGB15(31,31,31);
         
      if(held&KEY_START)
         for(int i = 0; i < 256*192; i++)
            VRAM_A[i] = RGB15(0,0,0);
      if(held&KEY_A)
         for(int i = 0; i < 256*192; i++)
            VRAM_A[i] = RGB15(0,0,31);
   }

   return 0;
}

#108889 - Sausage Boy - Sun Nov 12, 2006 6:18 pm

You could remember the last position touched, and draw a line between the old and the new positions (if the styles has not been lifted, of course).
_________________
"no offense, but this is the gayest game ever"

#108891 - outphase - Sun Nov 12, 2006 6:56 pm

Is there a function for that or do I need my own?

#108892 - Sausage Boy - Sun Nov 12, 2006 7:19 pm

You'll have to write this yourself, google for "line drawing algorithms".
_________________
"no offense, but this is the gayest game ever"

#108894 - outphase - Sun Nov 12, 2006 7:56 pm

i'm using the Bresenham algorithm and it looks great. Thanks.