first nds demo

Nikolaus Gradwohl2008-08-11T07:13:00+00:00

I got a nintendo DS 2 weeks ago and have hacked my first demo using the arm compilers from devkitPro. To compile the code follow the drunkencoders-Tutorial.

the program initializes the lower screen in a 2d graphics mode, and draws a circle (using the bresenham-algorithm for circles) wherever the screen is touched by the stylus. if the A button is pressed the screen is cleared. No sophisticated doublebuffering, 3d or sound stuff this time - but hey! it's the first program for a nds! and it works! :-)

#include <nds.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

void setPixel( int x, int y, int color ) {
    VRAM_A[x + y * 256] = color;
}

void circle( int mx, int my, int r, int color ) {
    int x = 0;
    int y = r;
    int d = 3 - 2 * r;

    while (x <= y) {
        setPixel( mx  + x, my + y, color );
        setPixel( mx  - x, my + y, color );
        setPixel( mx  - x, my - y, color );
        setPixel( mx  + x, my - y, color );
        setPixel( mx  + y, my + x, color );
        setPixel( mx  - y, my + x, color );
        setPixel( mx  - y, my - x, color );
        setPixel( mx  + y, my - x, color );

        if (d < 0) {
            d = d + 4 * x + 6;
        } else {
            d = d + 4 * ( x - y ) + 10;
            y --;
        }
        x++;
    }
}

int main(void) {
    touchPosition touch;

    videoSetMode(MODE_FB0);
    vramSetBankA(VRAM_A_LCD);

    lcdMainOnBottom();

    while(1) {
        scanKeys();

        if(keysHeld() & KEY_TOUCH) {
            touch=touchReadXY();
            circle( touch.px, touch.py, 20, rand());
        }

        if (keysHeld() & KEY_A) {
            for ( int y = 0; y < 192; y ++ ) {
                for ( int x = 0; x < 256; x ++ ) {
                    setPixel( x, y, 0);
                }
            }
        }
    }
    return 0;
}
Tweet This! submit to reddit Digg! Tags: | no comments | no trackbacks

See also:

nds line-demo
Happy Birthday Gameboy
feeling watched in openframeworks
osc app using openframeworks
SLR controlling via computer

Trackbacks

Comments

Leave a response

Leave a comment