Selecting the screen to print text or pixels.

Discussion in 'NDS - Emulation and Homebrew' started by razieliyo, Jan 4, 2011.

  1. razieliyo
    OP

    Newcomer razieliyo Newbie

    Joined:
    Jan 4, 2011
    Messages:
    3
    Country:
    Spain
    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!
     
  2. WioWao

    Member WioWao GBAtemp Regular

    Joined:
    Nov 14, 2008
    Messages:
    198
    Country:
    Denmark
    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 [​IMG]
    [​IMG]

    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
     
  3. razieliyo
    OP

    Newcomer razieliyo Newbie

    Joined:
    Jan 4, 2011
    Messages:
    3
    Country:
    Spain
    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! [​IMG]
     
  4. WioWao

    Member WioWao GBAtemp Regular

    Joined:
    Nov 14, 2008
    Messages:
    198
    Country:
    Denmark
    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 [​IMG]
     
  5. razieliyo
    OP

    Newcomer razieliyo Newbie

    Joined:
    Jan 4, 2011
    Messages:
    3
    Country:
    Spain
    Maybe I didn't explain very well. Thanks for the help really! I'm studying that guide like if it were my bible.
     

Share This Page