#41133 - rize - Mon Apr 25, 2005 8:56 pm
I was playing with the hello world demo (using dualis) and trying out a few things.
First let me ask a few basic questions. I thought I read somewhere that only the ARM7 can retrieve touch input, yet there is no ARM7 code in this demo and it is getting touch input via IPC->touchX etc. Am I misunderstanding something?
Second, the first line sets the video mode and is commented "not using the main screen". However, I thought video mode was set independantly of screen. I enabled the main screen as well without changing the video mode and there seems to be no problems.
Third, is there a trunc or round function somewhere? If not, is there a better method than what I used below (aside from putting that mess into a macro of course).
[edit: the problem below is solved... go ahead and laugh, I should have known better]
Anyway, onto the strange if behavior. I'm taking the uncalibrated touch input storing it in integers tx and ty and using the following:
... to recalibrate the touch input for dualis. It apparently works great giving me X values from 1 to 256 and Y values from 1 to 192. However the minus 14 caused the Y value to default to -14 instead of 0. So I threw an if statement in... just to make it look nice.
For some reason the branch is never taken and ty is set to 0 no matter where I touch the (emulated) screen. I even checked the hex value and tried:
That doesn't work either. However, the following three if statements work fine:
To verify that the touch input is what I think it should be, I'm printing the results out in dec and hex and also modifying the screen colors depending on the values of tx and ty. Everything works perfectly except the original two if statements. The problem occurs on dualis and ideas.
I figure its either some subtle syntax or type problem or else some kind of compiler error.
Here's the complete modified helloworld code I'm using:
Last edited by rize on Mon Apr 25, 2005 11:55 pm; edited 3 times in total
First let me ask a few basic questions. I thought I read somewhere that only the ARM7 can retrieve touch input, yet there is no ARM7 code in this demo and it is getting touch input via IPC->touchX etc. Am I misunderstanding something?
Second, the first line sets the video mode and is commented "not using the main screen". However, I thought video mode was set independantly of screen. I enabled the main screen as well without changing the video mode and there seems to be no problems.
Third, is there a trunc or round function somewhere? If not, is there a better method than what I used below (aside from putting that mess into a macro of course).
[edit: the problem below is solved... go ahead and laugh, I should have known better]
Anyway, onto the strange if behavior. I'm taking the uncalibrated touch input storing it in integers tx and ty and using the following:
Code: |
tx = tx/14;
ty = f32toint(floatof32((float)(IPC->touchY)/(float)17.508))-14; |
... to recalibrate the touch input for dualis. It apparently works great giving me X values from 1 to 256 and Y values from 1 to 192. However the minus 14 caused the Y value to default to -14 instead of 0. So I threw an if statement in... just to make it look nice.
Code: |
if (ty = -14) ty = 0; |
For some reason the branch is never taken and ty is set to 0 no matter where I touch the (emulated) screen. I even checked the hex value and tried:
Code: |
if (ty = 0xFFFFFFF2) ty = 0; |
That doesn't work either. However, the following three if statements work fine:
Code: |
if (ty != -14); else ty = 0;
if (ty > 0); else ty = 0; if (ty < 1) ty = 0; //I should have used this one to begin with |
To verify that the touch input is what I think it should be, I'm printing the results out in dec and hex and also modifying the screen colors depending on the values of tx and ty. Everything works perfectly except the original two if statements. The problem occurs on dualis and ideas.
I figure its either some subtle syntax or type problem or else some kind of compiler error.
Here's the complete modified helloworld code I'm using:
Code: |
////////////////////////////////////////////////////////////////////// // Simple consol print demo // -- dovoto (modified by rize) ////////////////////////////////////////////////////////////////////// #include <NDS/NDS.h> #include <NDS/ARM9/console.h> //basic print funcionality int main(void) { videoSetMode(0); //not using the main screen //\\rize: afiak, video mode has nothing to do with a particular screen //sub bg 0 will be used to print text videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); vramSetBankC(VRAM_C_SUB_BG); SUB_BG0_CR = BG_MAP_BASE(31); //main screen initialized as well videoSetMode(MODE_0_2D | DISPLAY_BG0_ACTIVE); vramSetBankC(VRAM_C_MAIN_BG); BG0_CR = BG_MAP_BASE(31); //set up the SUB palette just once (i0 for BG i255 for text color) BG_PALETTE_SUB[0] = RGB15(31,31,31); BG_PALETTE_SUB[255] = RGB15(0,0,0); while(1) { int tx, ty; consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16); consolePrintSet(0,0); consolePrintf("\n Hello World - Hijacked\n"); tx = IPC->touchX/14; ty = f32toint(floatof32((float)(IPC->touchY)/(float)17.508))-14; // if (ty = -14) ty = 0; // if (ty = 0xFFFFFFF2) ty = 0; // if (ty != -14); else ty = 0; // if (ty >= 1); else ty = 0; if (ty < 1) ty = 0; consolePrintSet(0,10); consolePrintf(" DEC Touch x = %d \n", tx); consolePrintf(" DEC Touch y = %d \n\n", ty); consolePrintf(" HEX Touch x = %X \n", tx); consolePrintf(" HEX Touch y = %X \n\n", ty); //BG based on touch input; text inverse of BG BG_PALETTE[0] = RGB15(tx/9, (tx+ty)/15, ty/7); BG_PALETTE[255] = ~BG_PALETTE[0] & (0xFFFF >> 1); consoleInitDefault((u16*)SCREEN_BASE_BLOCK(31), (u16*)CHAR_BASE_BLOCK(0), 16); consolePrintSet(0,22); consolePrintf(" BG COLOR = %04X\n", BG_PALETTE[0]); } return 0; } |
Last edited by rize on Mon Apr 25, 2005 11:55 pm; edited 3 times in total