#133777 - route66 - Sun Jul 08, 2007 4:40 pm
Probably a noob thing, but if I move the printfs of the ansi_console example into the loop with swiWaitForVBlank(), then the first row doesn't get printed. What am I missing?
Also \r doesn't work. (Just kidding! hehehe)
#133830 - route66 - Mon Jul 09, 2007 2:23 am
No thoughts?
Actually, the first 6 rows dont get displayed. And this is an example that is provided with DKP!
Do I need some kind of delay between the vblank interrupt and the first printf()?
#133835 - HyperHacker - Mon Jul 09, 2007 3:16 am
The console isn't interrupt safe. Trying to print from within an interrupt can break things. Other than that, I don't know of any such limitations.
_________________
I'm a PSP hacker now, but I still <3 DS.
#133837 - route66 - Mon Jul 09, 2007 3:51 am
I am not printing from interrupt, but from the main loop, I have tried before and after swiWaitForVBlank()
#133843 - wintermute - Mon Jul 09, 2007 6:03 am
Code would help determine what the problem might be. If it's simple then post here using the bbcode code tags, if not then host the complete project somewhere we can have a look.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog
#134004 - route66 - Tue Jul 10, 2007 1:55 am
It is the ansi_console demo that comes with DKP. I commented out some of the escape code sequences, now I just have 16 printfs. The first 6 lines do not get shown.
Code: |
#include <nds.h>
#include <stdio.h>
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
int i;
// initialise the irq dispatcher
irqInit();
// a vblank interrupt is needed to use swiWaitForVBlank()
// since the dispatcher handles the flags no handler is required
irqEnable(IRQ_VBLANK);
videoSetMode(0); //not using the main screen
videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); //sub bg 0 will be used to print text
vramSetBankC(VRAM_C_SUB_BG);
SUB_BG0_CR = BG_MAP_BASE(31);
BG_PALETTE_SUB[255] = RGB15(31,31,31); //by default font will be rendered with color 255
//consoleInit() is a lot more flexible but this gets you up and running quick
consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);
// ansi escape sequence to clear screen and home cursor
// /x1b[line;columnH
iprintf("\x1b[2J");
// ansi escape sequence to set print co-ordinates
// /x1b[line;columnH
iprintf("\x1b[10;10HHello World!");
// ansi escape sequence to move cursor up
// /x1b[linesA
iprintf("\x1b[10ALine 0");
// ansi escape sequence to move cursor left
// /x1b[columnsD
iprintf("\x1b[28DColumn 0");
// ansi escape sequence to move cursor down
// /x1b[linesB
iprintf("\x1b[19BLine 19");
// ansi escape sequence to move cursor right
// /x1b[columnsC
iprintf("\x1b[5CColumn 20");
while(1) {
/*
// ansi escape sequence to clear screen and home cursor
// /x1b[line;columnH
iprintf("\x1b[2J");
// ansi escape sequence to set print co-ordinates
// /x1b[line;columnH
iprintf("\x1b[10;10HHello World!");
// ansi escape sequence to move cursor up
// /x1b[linesA
iprintf("\x1b[10ALine 0");
// ansi escape sequence to move cursor left
// /x1b[columnsD
iprintf("\x1b[28DColumn 0");
// ansi escape sequence to move cursor down
// /x1b[linesB
iprintf("\x1b[19BLine 19");
// ansi escape sequence to move cursor right
// /x1b[columnsC
iprintf("\x1b[5CColumn 20");
*/
iprintf("\x1b[2J");
for (i=0; i<15; i++)
{
printf("LINE%U\n", i);
}
swiWaitForVBlank();
}
return 0;
}
|
#134131 - wintermute - Tue Jul 10, 2007 9:41 pm
The problem here is that the current code to clear the console is rather slow. The DS has already rendered part of the screen by the time you reach the first printf and, because you run the clear code and the printing in a continuous loop, you will never see the output for the first 6 or so lines.
The console was really designed as a quick and easy way to show debug output rather than anything you should use in an application. You can certainly build simple text menu applications easily but I wouldn't really consider using it for anything that needs to have fast screen updates.
For what it's worth, you don't really need to clear the screen for every loop of that. Since it's printing the same thing each loop all you need to do is home the cursor.
Code: |
#include <nds.h>
#include <stdio.h>
int main() {
irqInit();
// a vblank interrupt is needed to use swiWaitForVBlank()
// since the dispatcher handles the flags no handler is required
irqEnable(IRQ_VBLANK);
consoleDemoInit();
int i;
iprintf("\x1b[2J");
while(1) {
swiWaitForVBlank();
iprintf("\x1b[0;0H");
for (i=0; i<15; i++) {
printf("LINE%u\n", i);
}
}
}
|
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog
#134153 - route66 - Wed Jul 11, 2007 1:56 am
Ok thanks, didn't realize clearing the screen was so slow. I was clearing the screen on every loop so I could display a lot of debug info - but I will switch to just homing the cursor.