Homebrew Selecting the screen to print text or pixels.

razieliyo

New Member
OP
Newbie
Joined
Jan 4, 2011
Messages
3
Trophies
0
XP
18
Country
Well, I'm just starting with NDS homebrew programming. I'm reading a few tutorials and I compiled a simple example I found over there:
CODE#include
#include

int main(void) {
ÂÂÂÂint i;

ÂÂÂÂconsoleDemoInit();

ÂÂÂÂvideoSetMode(MODE_FB0);

ÂÂÂÂvramSetBankA(VRAM_A_LCD);

ÂÂÂÂprintf("Hello world!\n");
ÂÂÂÂprintf("Whats up, folks?");

ÂÂÂÂfor(i = 0; i < 256 * 192; i++)
ÂÂÂÂÂÂÂÂVRAM_A = RGB15(31,0,0);

ÂÂÂÂswiWaitForVBlank();

ÂÂÂÂreturn 0;
}
Maybe you know where I took it from. This fills the up screen with red and prints hello world bla bla bla in touchscreen. My question is, how can I select where to draw and where to print text? I'm using purely libnds, not PAlib or so.

Thanks!
 

WioWao

Well-Known Member
Member
Joined
Nov 14, 2008
Messages
198
Trophies
0
XP
67
Country
VRAM_A is in a way a "table" of your screen. Thing is, its only in 1 dimension. So you can't print to a "coordinate". You can however convert a coordinate to this huge 1 dimensional table. Actually you are directly writing to the videoRAM of the DS. So from 0-255 is the top of the screen. As soon as you get over 255, to 256, you are at the row below the first.

So everytime you want to "go down"(yes the screen is "upside down", it seems strange as a beginner, but it is) on the screen, you have to increase with 256. So, y-coordinate*256 + the x-coordinate = printing at the location you want.
Code:
VRAM_A[y-coordinate*256+x-coordinate] = RGB15(31,0,0);
Ill make a picture to show you what i mean. Because i cant fit 256 sqaures with numbers in it i had to remix the DS to have 14 pixels per row xD But i hope you get the point
wink.gif

whatimean.jpg


As for printing to specific places on the screen(Note it's using iprintf not printf):
Code:
// ansi escape sequence to set print co-ordinates
// /x1b[line;columnH
iprintf("\x1b[10;10HHello World!");

Edit: Spelling mistakes.

Edit2: This guide is good for beginners: http://dev-scene.com/NDS/Tutorials
 

razieliyo

New Member
OP
Newbie
Joined
Jan 4, 2011
Messages
3
Trophies
0
XP
18
Country
I think you didn't understand me. The question was, how to select what screen to use, but I think I've found something that helps me. lcdMainOnBottom(); to select the bottom screen.
Anyway, that explanation was good for clearing concepts for me, so thanks!
grog.gif
 

WioWao

Well-Known Member
Member
Joined
Nov 14, 2008
Messages
198
Trophies
0
XP
67
Country
Oooh i only read the "where to draw" part. Hehe Np. But check out the guide i posted, though it is not done it has been the only one, i have found so far, that explains things thoughrouly
moogle.gif
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    BakerMan @ BakerMan: @salazarcosplay yeah cod's still up