Page 1 of 4 123 ... LastLast
Results 1 to 10 of 40

Thread: another day, another problem (touchpad).

  1. #1

    another day, another problem (touchpad).

    Hi ... AGAIN. :)

    I can not read the touchpad.

    It worked before. before = yesterday, before i recompiled fpc ...

    it's not the code, because it ran before and i also copied the code from
    another thread from here.

    it can't be my batch-file either (or are there any new compiler switches that
    i need for the touchpad O_O).

    here's the code anyway:

    Code:
    Program Touch;
    {$APPTYPE ARM9}
    {$DEFINE ARM9}
    {$MODE OBJFPC}
    
    uses
      cTypes;
    
    {$INCLUDE NDS.INC}
    
    var
      touchXY: touchPosition;
    
    begin
      consoleDemoInit();
      videoSetMode(MODE_FB0);
      vramSetBankA(vram_A_LCD);
    
      irqInit();
      irqEnable(IRQ_VBLANK);
    
      lcdSwap;
    
      while true do
      begin
        touchXY := touchReadXY();
        If &#40;touchXY.X <> 0&#41; then
          vram_A&#91;100 * 256 + 100&#93; &#58;= rgb15&#40;31,31,31&#41;;
      end;
    end.
    ... saved as touch.pp9

    and...

    Code:
    program Touch;
    
    &#123;$apptype arm7&#125; //...or arm7
    &#123;$define ARM7&#125;   //...or arm7, according to apptype
    
    &#123;$mode objfpc&#125;   // required for some libc funcs implementation
    
    uses
      ctypes; // required by nds headers!
    
    &#123;$include nds.inc&#125;  // headers!
    
    var
      tempPos&#58; touchPosition;
    
    procedure CatchTheTouch&#40;&#41;;
    begin
      tempPos &#58;=  touchReadXY&#40;&#41;;
    
      IPC^.touchX &#58;= tempPos.x;
      IPC^.touchY &#58;= tempPos.y;
    
    end;
    
    begin
      // Reset the clock if needed
      rtcReset&#40;&#41;;
      irqInit&#40;&#41;;
      irqSet&#40;IRQ_VCOUNT, @CatchTheTouch&#41;;
      irqEnable&#40;IRQ_VCOUNT&#41;;
    
      while true do
        swiWaitForVBlank&#40;&#41;;
    end.
    ... saved as touch.pp7

    my batch-file looks like this:

    Code:
    @cls
    ppcarmnds %1.pp9 -Sg
    ppcarmnds %1.pp7 -Sg
    ndstool -c %1.nds -9 %1.arm9.bin -7 %1.arm7.bin
    j&#58;\nds\no$gba %1
    -Sg enables Jumping
    %1 = Parameter 1 for the batch-file

    I have tried using px instead of x, which of course didn't make any difference, probably because there isn't any ipc happening at all.

    i did not look at the asm-source yet. i could, but i do not have a reference
    to compare with ... maybe if someone could compile the code and upload
    the asm-source somewhere ... it could help me find the error.

    any advise?

  2. #2

    another day, another problem (touchpad).

    so, i found something out.

    This:

    Code:
    Program Touch;
    &#123;$APPTYPE ARM9&#125;
    &#123;$DEFINE ARM9&#125;
    &#123;$MODE OBJFPC&#125;
    
    uses
      cTypes;
    
    &#123;$INCLUDE NDS.INC&#125;
    
    
    //arm9
    var
      touchXY&#58; touchPosition;
    
    begin
      consoleDemoInit&#40;&#41;;
      videoSetMode&#40;MODE_FB0&#41;;
      vramSetBankA&#40;vram_A_LCD&#41;;
    
      irqInit&#40;&#41;;
      irqEnable&#40;IRQ_VBLANK&#41;;
    
      lcdSwap;
    
    
      vram_a&#91;0&#93; &#58;= rgb15&#40;0,0,0&#41;;
    
        vram_a&#91;10&#93; &#58;= rgb15&#40;0,0,0&#41;;
          vram_a&#91;20&#93; &#58;= rgb15&#40;0,0,0&#41;;
    
      while true do
      begin
        swiWaitForVBlank;
        touchXY &#58;= touchReadXY&#40;&#41;;
        If &#40;touchxy.X <> 0&#41; then
        begin
          iprintf&#40;#27 + '&#91;7;5H' + 'Touch x = %04X, %04X' + #10, &#91;touchxy.px, touchxy.py&#93;&#41;;
          vram_A&#91;&#40;touchxy.py div 16&#41; * 256 + &#40;touchxy.px div 16&#41;&#93; &#58;= rgb15&#40;31,31,31&#41;;
        end;
        end;
    end.
    ...WORKS. It's the code for ARM9 and it works... but it's strange, because:

    1st:
    i've read that the arm9 can't communicate with the touchpad directly and has
    to do this via arm7 and ipc, BUT THERE IS NO arm7-code.

    2nd: normally i used px/py without dividing and it gave me the exact
    position of the pen, whereas NOW i have to divide px/py (like before in x/y,
    which gave me unexact results) and x is increasing continously and y just stays empty.

    what the hell is going on here??

  3. #3

    another day, another problem (touchpad).

    Old versions of libnds required to write arm7 touch screen handling code by hand. New versions include a default handler that provides touhscreen access directly from arm9, so usually you don't need to do it by hand
    Get your fpc4gba copy now!
    Get your fpc4nds copy now!

  4. #4

    another day, another problem (touchpad).

    i don't really like the idea. there's no real benefit except i don't have to write
    like what, 10 lines of code? it seems to me that the drawbacks weigh much
    heavier than the benefits.

    -> how do i write my own handler now?

    -> why is x increasing, y empty and px/py now lacking any precision, which
    they had before? (I still don't know how to calculate the correct values,
    a simple div16 doesn't really do the trick but that's not the problem here).

    -> "it's a lie". the arm9 can't communicate with the SPI, but the library
    fools you in believing it can.

    so ... how do i write my own handler, which gives me correct results,
    which i actually expect? :D i don't care about that as long i can write
    my own one (and pass stuff via IPC, which doesn't seem to work anymore,
    because i can't even pass a simple 1 via ipc^.touchx, for example.)

    i really appreciate your work and effort (i wouldn't be here without you
    and wouldn't code my nds without you :D), but this really really reminds
    me of "it's not a bug, it's a feature" ...

  5. #5

    another day, another problem (touchpad).

    Quote Originally Posted by 21o6
    i don't really like the idea. there's no real benefit except i don't have to write
    like what, 10 lines of code? it seems to me that the drawbacks weigh much
    heavier than the benefits.
    -> how do i write my own handler now?
    Sorry, but I think you are aiming your arrows to the wrong target. This change is not my choice, but Wintermute's (the guy that created libnds).

    -> why is x increasing, y empty and px/py now lacking any precision, which
    they had before? (I still don't know how to calculate the correct values,
    a simple div16 doesn't really do the trick but that's not the problem here).
    I don't know. I got similar issues with emulators, while the same code worked as expected on real hardware.
    -> "it's a lie". the arm9 can't communicate with the SPI, but the library
    fools you in believing it can.
    The way the lib works is: every VBlank, arm7 reads the input device state and stores them in the IPC struct in the shared memory. On the arm9 you can find some useful functions that read that shared memory. The arm9 can't communicate with the SPI, but can read the shared memory. The arm7 default code does the trick.
    so ... how do i write my own handler, which gives me correct results,
    which i actually expect? i don't care about that as long i can write
    my own one (and pass stuff via IPC, which doesn't seem to work anymore,
    because i can't even pass a simple 1 via ipc^.touchx, for example.)
    Let me investigate a bit about that
    i really appreciate your work and effort (i wouldn't be here without you
    and wouldn't code my nds without you ), but this really really reminds
    me of "it's not a bug, it's a feature" ...
    In fact, as you guess, it's not a bug, it's a feature
    Get your fpc4gba copy now!
    Get your fpc4nds copy now!

  6. #6

    another day, another problem (touchpad).

    i am sorry for ranting at you.

    i really thought that was your idea, sorry for that too. i am just upset that
    i always run into problems without knowing why.

    i have tried the code on my phat nds and it works as in the emulator. now
    i have to figure out how to calculate the right values (i don't know if i can
    look that up somewhere, but actually i find that one out myself. i really
    need more training to get back into coding :D).

    thank you for taking time and investigating in how i can write my own
    handler and stuff :D

    oh and... i really consider this more a bug than a feature :D

    (i will take a deep look into hardware/registers/memory layout now) ...

  7. #7

    another day, another problem (touchpad).

    No problemo
    Uhm... combining arm9 and arm7 hangs the ds here too. Maybe it's an arm7 related bug, because combining fpc made arm9 and dkp made arm7 works fine :scratch:
    Get your fpc4gba copy now!
    Get your fpc4nds copy now!

  8. #8

    another day, another problem (touchpad).

    i didn't even recognize that it hangs the DS ... i've tested on a black screen
    waiting for input from the touchpen ... lol

    that explains why ipc didn't work, too.

    ok, i go shoot myself now xD

    seriously, if i can help in any way, please tell me :D

  9. #9

    another day, another problem (touchpad).

    i have fiddled around a bit with the coordinates.

    it's not 100% exact, but it's waay better than only doing div 16 and really
    sufficient when used on hardware.

    Code:
    touchxy.px &#58;= &#40;touchxy.px div 14&#41; - 19;
    touchxy.py &#58;= &#40;touchxy.py div 19&#41; - 10;
    this gives me the best result, the X/Y-range goes from 0..251:0..191.

    Tested with no$gba and my phat NDS.
    Please note that your emulator will probably give slightly different results.

    i hope this will get obselete soon :)

    oh and... does anybody actually need this stuff? 100+ views but nobody's posting.

  10. #10

    another day, another problem (touchpad).

    I would say the touch pad is really important.

    I think you are breaking new ground here, that will expalin the lack of posts, I myself have played with the DS stuff, but I've had to put it to one side for now.

    Keep up the investigation
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

Page 1 of 4 123 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •