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 > Console Character Array

#174344 - JackUzi - Wed Jun 02, 2010 5:06 am

Hello again

I was just wondering if there is an array of all the characters currently on the console that my application is able to read. What I am hoping to do is detect a stylus touch, calculate which character position was pressed on the screen and then find out what character is at that position. I then need to be able to read left and right to find spaces so I can figure out the word that was selected. Is this possible?

Regards,
Stuart

#174347 - elhobbs - Wed Jun 02, 2010 8:51 am

Yes, this is possible. The console prints characters using 8x8 tiles. So it is just a matter of reading the touch coordinates and dividing by 8 to find the row and column. Then you can use that to find the offset into the the tile map which is just an array of shorts - one byte is the character the other byte I think may be the color. Here is the code libnds uses to write a char
Code:
currentConsole->fontBgMap[currentConsole->cursorX + currentConsole->windowX + (currentConsole->cursorY + currentConsole->windowY) * currentConsole->consoleWidth] = currentConsole->fontCurPal | (u16)(c + currentConsole->fontCharOffset - currentConsole->font.asciiOffset);
You would want to use your row and column values in place of cursorX and cursorY. I think you can use currentConole directly if not I think it is the value returned by the consoleInit function.

#174356 - JackUzi - Thu Jun 03, 2010 12:40 am

Thank you very much, once again. I'll start to experiment and see how it goes.

EDIT: Just gave it a go then and it works perfectly. You're a champion!

Regards,
Stuart