PROGRAMMING > Console homebrew

Any DS coders here?

(1/2) > >>

relsoft:

:updance:

Kind of liking this Homebrew DS coding.  I love the framebuffer mode. It's like TPTC on the DS.

combatking0:
I'm not into DS coding, but it's something I'd like to learn about.

Where would be a good place to start?

relsoft:
I just read some docs on the net and downloaded the DevkitPro package.  The example files there are easy to follow.

I've uploaded some NDS files along with sources and screenshots....

BTW, to try this on Windows or DOS, you can DL the No\$GBA emulator for free here, then load the NDS file.

http://nocash.emubase.de/gba.htm

--- Code: ---/*
NDS Translucent Plasma
Relminator

http://rel.betterwebber.com

*/

#include <nds.h>
#include <stdio.h>
#include <math.h>

// some sine LUTs
u8 lsin1[2048];
u8 lsin2[2048];
u8 lsin3[2048];

// RGB palette
u16 pal[256];

int main(void)
{

// constant sine divisor
const u8 K1 = 32;
const u8 K2 = 12;
const u8 K3 = 28;

// maximum values our dynamic plasmas can move
u16 KSIN1 = u8(K1 *(360/57.3f));
u16 KSIN2 = u8(K2 *(360/57.3f));
u16 KSIN3 = u8(K3 *(360/57.3f));

// precalculate our luts
for (int i = 0; i< ((2048) - 1); i++)
{
lsin1[i] = sin(i/(float)K1) * 32+32;
lsin2[i] = sin(i/(float)K2) * 16+16;
lsin3[i] = sin(i/(float)K3) * 20+20;
}

// generate our 256 color palette
for (int i=0; i<256; i++)
{
u8 r = (u8)(abs(int(16 - 15 * sin(i * M_PI / 16.0f))));
u8 g = (u8)(abs(int(16 - 15 * sin(i * M_PI / 12.0f))));
u8 b = (u8)(abs(int(16 - 15 * sin(i * M_PI / 18.0f))));
pal[i] = RGB15(r,g,b);
}

irqInit();
irqEnable(IRQ_VBLANK);

//initialize the DS Dos-like functionality
consoleDemoInit();

iprintf("\x1b[1;1HTranslucent Plasma!");
iprintf("\x1b[3;1HRelsoft");
iprintf("\x1b[4;1Hhttp://rel.betterwebber.com");
iprintf("\x1b[6;1HAnya Therese B. Lope");

//set frame buffer mode 0
videoSetMode(MODE_FB0);

//enable VRAM A for writting by the cpu and use
//as a framebuffer by video hardware
vramSetBankA(VRAM_A_LCD);

u8 rot; // translucent factor
u16 counter =0; // frame counter
u16 a = 0, b = 0, ct = 0; // movement deltas
u16 c; // palette color index

while(1)
{

// dynamically move our plasmas
a= (a + 1) % (KSIN1 + 1);
b = (b + 1) % (KSIN2 + 1);
ct = (ct + 1) % (KSIN3 + 1);

// offset 2nd plasma by a factor of 64 * 2 or (-64 to 64)
rot = 64 * (((counter & 1) == 1) | 1);

// inc frame
counter++;

//write to vram directly
short unsigned int *vram_offset = VRAM_A;

for (int ya = 0; ya<SCREEN_HEIGHT; ya++)
{
for (int xa = 0; xa <SCREEN_WIDTH-1; xa++)
{
rot = -rot; // draw plasmas every other pixel
// calculate colors
c = (lsin1[xa + a + rot] + lsin2[ya + b + rot] +lsin3[1024+xa + ya - ct]);
c = (lsin1[xa + a + rot+c] + lsin2[ya + b + rot+c] +lsin3[1024+xa + ya - ct+c]);
// write to vram
*vram_offset++ = pal[c];
}
vram_offset++; // magic
}
swiWaitForVBlank();
}

return 0;
}

--- End code ---

Clyde:
Nice to see you coding btw dude :)

All the very best,
Clyde.

relsoft:

--- Quote from: Clyde on April 19, 2010 ---I'll download the emu and give these a go!
Nice to see you coding btw dude :)

All the very best,
Clyde.

--- End quote ---

Yeah, it's been a while since I last coded something worthwhile.  My daughter was actually the one who motivated me to learn DS coding as she wanted me to make a game on the DS. Nut its more likely that I'll be making a demo first. :)