Advertisement
xerpi

NDS Basic draw functions

Apr 21st, 2012
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.57 KB | None | 0 0
  1. #include <nds.h>
  2. #include <stdio.h>
  3.  
  4.  
  5. void drawHline(int y, int x0, int x1, unsigned int color);
  6. void drawVline(int x, int y0, int y1, unsigned int color);
  7. void drawPlot(int x, int y, unsigned int color);
  8. void drawRect(int x, int y, int w, int h, unsigned int color);
  9. void drawFillRect(int x, int y, int w, int h, unsigned int color);
  10.  
  11. int main(void){
  12.     int i;
  13.  
  14.     consoleDemoInit();
  15.  
  16.     videoSetMode(MODE_FB0);
  17.  
  18.     vramSetBankA(VRAM_A_LCD);
  19.  
  20.     printf("Basic draw functions by xerpi!\n");
  21.  
  22.     for(i = 0; i < 256 * 192; i++)
  23.         VRAM_A[i] = RGB15(31,0,0);
  24.        
  25.     drawRect( 10, 10, 20, 80, RGB15(0, 31, 0));
  26.     drawFillRect( 100, 100, 50, 30, RGB15(0, 0, 31));
  27.     while(1){
  28.         swiWaitForVBlank();
  29.     }
  30.  
  31.     return 0;
  32. }
  33.  
  34.  
  35. void drawPlot(int x, int y, unsigned int color){
  36.     VRAM_A[x + y*256] = color;
  37. }
  38.  
  39. void drawHline(int y, int x0, int x1, unsigned int color){
  40.     int i;
  41.     if(x0 < x1)
  42.         for(i = x0; i < x1; i++)
  43.             VRAM_A[i + y*256] = color; 
  44.     else
  45.         for(i = x1; i < x0; i++)
  46.             VRAM_A[i + y*256] = color; 
  47.  
  48. }
  49.  
  50.  
  51. void drawVline(int x, int y0, int y1, unsigned int color){
  52.     int i;
  53.     if(y0 < y1)
  54.         for(i = y0; i < y1; i++)
  55.             VRAM_A[x + i*256] = color; 
  56.     else
  57.         for(i = y1; i < y0; i++)
  58.             VRAM_A[x + i*256] = color; 
  59.  
  60. }
  61.  
  62. void drawRect(int x, int y, int w, int h, unsigned int color){
  63.     drawVline(x, y, y + h, color);
  64.     drawVline(x + w, y, y + h, color);
  65.     drawHline(y + h, x, x + w, color);
  66.     drawHline(y, x, x + w, color);
  67. }
  68.  
  69. void drawFillRect(int x, int y, int w, int h, unsigned int color){
  70.     int i;
  71.     for(i = y; i < y + h; i++)
  72.         drawHline(i, x, x + w, color);
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement