Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: FPC4NDS (Problems when I make the programs to run on NDS)

  1. #1

    FPC4NDS (Problems when I make the programs to run on NDS)

    I can make programs who uses input and video options with arm9, and run this programs at nds and at emulators
    but when I use touch with arm7 the program only works at emulators...

    I tryied to use differents programs form arm7 and arm9, but it doesn't worked:
    TouchARM9.pas
    TouchARM7.pas

    In toucharm7 the program has 2functions:
    TouchX():Integer //take the X position of touch
    and TouchY():Integer //take Y position of touch

    And in toucharm9 I tryied to use the functions of the touch7 and print in the screen where was touched

    In .bat file I used
    ppcarmnds -g --gc-sections -Tnds toucharm7.pas
    ppcarmnds -g --gc-sections -Tnds toucharm9.pas
    ndstool -c TouchTest.nds -9 toucharm9.arm9.bin -7 toucharm7.arm7.bin
    dsbuild TouchTest.nds -o TouchTest.nds.gba
    pause

    The compiler showed these Errors on toucharm9
    The function touchX doesn't exists
    The function touchY doesn't exists

    I tryied to declare toucharm7 on the uses and the compiler showed these errors on Jtypes.inc
    Can't find INTERFACE
    Can't find IMPLEMENTATION


    How can I make homebrews for NDS using the FPC4NDS?
    I have the R4DS

    Sry for my bad english

  2. #2

    FPC4NDS (Problems when I make the programs to run on NDS)

    You can't access arm7 functions from arm9 directly. In order to get the touch screen coordinates from arm9 you will need to access the IPC register via touchReadXY() function. The right way to do that is:

    1. In arm7 code, make a function to pass the touch screen values to the IPC register in arm7, then pass this function to an IRQ activated via IRQ_VCOUNT
    [pascal]
    // arm7
    var
    tempPos: touchPosition;
    procedure CatchTheTouch();
    begin
    tempPos := touchReadXY();
    ...
    IPC^.touchX := tempPos.x;
    IPC^.touchY := tempPos.y;
    ...
    end;

    begin
    // Reset the clock if needed
    rtcReset();
    irqInit();
    irqSet(IRQ_VCOUNT, @CatchTheTouch);
    irqEnable(IRQ_VCOUNT);

    while true do
    swiWaitForVBlank();
    end.

    [/pascal]

    2. In arm9 code, read the IPC values using the function touchReadXY();
    [pascal]
    //arm9
    var
    touchXY: touchPosition;

    begin
    ...

    while true do
    begin
    touchXY := touchReadXY();
    ....
    end;
    end.
    [/pascal]


    I haven't touched (:lol fpc4nds for a while, so I really don't know if something is changed in the last libnds vesion. I need to update my pascal binding, I know :roll:
    Get your fpc4gba copy now!
    Get your fpc4nds copy now!

  3. #3

    FPC4NDS (Problems when I make the programs to run on NDS)

    didn't work
    but I think the error is on arm 9 code:
    [pascal]
    //arm9
    var
    touchXY: touchPosition;

    begin
    ...

    while true do
    begin
    touchXY := touchReadXY();
    ....
    end;
    end. [/pascal]
    I will test this code:
    [pascal]
    //arm9
    var
    X:integer;
    Y:Integer;

    begin
    ...

    while true do
    begin
    X:=IPC^.touchX;
    Y:=IPC^.touchY;
    ....
    end;
    end. [/pascal]
    (I saw this code on C^^') When my brother come back with the NDS I will test
    thanks

  4. #4

    FPC4NDS (Problems when I make the programs to run on NDS)

    touchReadXY is defined both in arm7 and arm9. Maybe you missed some steps in the head part of your code:

    [pascal]
    program main9;
    {$apptype arm9}
    {$define ARM9}

    {$mode objfpc}

    uses
    ctypes;

    {$include nds.inc}

    begin
    // Your code for ARM9 here
    end.
    [/pascal]


    [pascal]
    program main7;
    {$apptype arm7}
    {$define ARM7}

    {$mode objfpc}

    uses
    ctypes;

    {$include nds.inc}

    begin
    // Your code for ARM7 here
    end.
    [/pascal]

    Without these defines, the compiler can't compile your code correctly, nor libnds will be linked in the right way.
    Get your fpc4gba copy now!
    Get your fpc4nds copy now!

  5. #5

    FPC4NDS (Problems when I make the programs to run on NDS)

    Arm7:
    [pascal]
    program toucharm7;

    {$apptype arm7} //...or arm7
    {$define ARM7} //...or arm7, according to apptype

    {$mode objfpc} // required for some libc funcs implementation

    uses
    ctypes; // required by nds headers!

    {$include nds.inc} // headers!

    var
    tempPos: touchPosition;
    procedure CatchTheTouch();
    begin
    tempPos := touchReadXY();

    IPC^.touchX := tempPos.x;
    IPC^.touchY := tempPos.y;

    end;

    begin
    // Reset the clock if needed
    rtcReset();
    irqInit();
    irqSet(IRQ_VCOUNT, @CatchTheTouch);
    irqEnable(IRQ_VCOUNT);

    while true do
    swiWaitForVBlank();
    end.
    [/pascal]

    Arm9:
    [pascal]
    program toucharm9;

    {$apptype arm9} //...or arm7
    {$define ARM9} //...or arm7, according to apptype

    {$mode objfpc} // required for some libc funcs implementation

    uses
    ctypes; // required by nds headers!

    {$include nds.inc} // headers!
    {$include dswifi9.inc} // headers!

    var
    i: integer;
    touchXY: touchPosition;
    X,Y:integer;
    begin

    consoleDemoInit();
    videoSetMode(MODE_FB0);
    vramSetBankA(VRAM_A_LCD);
    irqInit();
    irqEnable(IRQ_VBLANK);
    printf('Teste de Teclas'+#10);

    for i := 0 to (256 * 192) - 1 do
    VRAM_A[i] := RGB15(15,25,1);

    lcdSwap();

    while true do
    begin
    touchXY:= touchReadXY();
    if touchXY.x<>0 then
    begin
    X:=touchXY.x div 16;
    Y:=touchXY.y div 16;
    printf('%i / %i'+#10,[X,Y]);
    VRAM_A[(Y*256)+X-1] := RGB15(25,0,0);
    end;
    end;

    end.
    [/pascal]

    .bat code:
    Code:
    ppcarmnds -g --gc-sections -Tnds toucharm9.pas
    ppcarmnds -g --gc-sections -Tnds toucharm7.pas
    pause
    ndstool -c toucharm9.nds -9 toucharm9.arm9.bin -7 toucharm7.arm7.bin
    dsbuild toucharm9.nds -o toucharm9.nds.gba 
    del *.bin
    del *.o
    del *.elf
    pause
    This code didn't work on nds[/code]

  6. #6

    FPC4NDS (Problems when I make the programs to run on NDS)

    Works fine here, both on emulator and a real nds (phat). The only difference between emu and real hardware I have noticed is that on real hw the red line is shifted a bunch of pixels below the stylus position :think:

    I have the last libndsfpc, the last libnds and fpc4nds 2.1.4 installed.

    Edit: I have tested the executable on a slot1 (DS-X) and on a slot2 device (M3 SD Perfect).
    Get your fpc4gba copy now!
    Get your fpc4nds copy now!

  7. #7

    FPC4NDS (Problems when I make the programs to run on NDS)

    Have the r4 ds some incompatibility?
    Can I apply DIDL ?

  8. #8

    FPC4NDS (Problems when I make the programs to run on NDS)

    I ran it unpatched, because your code does not have a file system access. AFAIK r4 should work fine too, so the problem is somewhere else...
    A thing I have noticed is that in your batch file you're patching the nds rom with dsbuild. You need to use the nds file for your card, because nds.gba are only used on some slot2 devices to run nds roms in gba mode.
    In fact, trying to run the nds.gba rom, the touch screen does not work at all and the nds freezes. Try to use the .nds file and let me know if it works or not.
    Get your fpc4gba copy now!
    Get your fpc4nds copy now!

  9. #9

    FPC4NDS (Problems when I make the programs to run on NDS)

    Im using .nds file^^'

    I tested this arm9 code and worked :
    [pascal]
    program toucharm9;

    {$apptype arm9} //...or arm7
    {$define ARM9} //...or arm7, according to apptype

    {$mode objfpc} // required for some libc funcs implementation

    uses
    ctypes; // required by nds headers!

    {$include nds.inc} // headers!
    {$include dswifi9.inc} // headers!

    var
    i: integer;
    X,Y:integer;
    begin

    consoleDemoInit();

    videoSetMode(MODE_FB0);
    vramSetBankA(VRAM_A_BG);
    irqInit();
    irqEnable(IRQ_VBLANK);
    //printf('Teste de Teclas'+#10);

    for i := 0 to (256 * 192) - 1 do
    VRAM_A[i] := RGB15(15,25,1);

    lcdSwap();
    while true do
    begin
    if IPC^.touchX<>0 then
    begin
    printf('PX=%i / PY=%i'+#10,[IPC^.touchXpx,IPC^.touchYpx]);
    VRAM_A[(IPC^.touchYpx*256)+IPC^.touchXpx-1] := RGB15(25,0,0);
    end;
    end;

    end.
    [/pascal]
    now I'm trying to use the graphics of the touch screen same as the normal screen (VRAM_A)

  10. #10

    FPC4NDS (Problems when I make the programs to run on NDS)

    Uhm... that's strange... :think: If you want, send me your code that does not work, with .nds and .elf files too. I'm not sure what's happening here, so I'd love to investigate a bit further
    Get your fpc4gba copy now!
    Get your fpc4nds copy now!

Page 1 of 2 12 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
  •