PDA

View Full Version : FPC4NDS (Problems when I make the programs to run on NDS)



unneon
25-05-2007, 12:25 AM
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

Legolas
25-05-2007, 09:58 AM
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

// 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.



2. In arm9 code, read the IPC values using the function touchReadXY();

//arm9
var
touchXY: touchPosition;

begin
...

while true do
begin
touchXY := touchReadXY();
....
end;
end.



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:

unneon
27-05-2007, 07:10 PM
didn't work
but I think the error is on arm 9 code:

//arm9
var
touchXY: touchPosition;

begin
...

while true do
begin
touchXY := touchReadXY();
....
end;
end.
I will test this code:

//arm9
var
X:integer;
Y:Integer;

begin
...

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

Legolas
27-05-2007, 07:46 PM
touchReadXY is defined both in arm7 and arm9. Maybe you missed some steps in the head part of your code:


program main9;
{$apptype arm9}
{$define ARM9}

{$mode objfpc}

uses
ctypes;

{$include nds.inc}

begin
// Your code for ARM9 here
end.




program main7;
{$apptype arm7}
{$define ARM7}

{$mode objfpc}

uses
ctypes;

{$include nds.inc}

begin
// Your code for ARM7 here
end.


Without these defines, the compiler can't compile your code correctly, nor libnds will be linked in the right way.

unneon
27-05-2007, 08:55 PM
Arm7:

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.


Arm9:

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.


.bat 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]

Legolas
27-05-2007, 10:34 PM
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).

unneon
27-05-2007, 10:52 PM
Have the r4 ds some incompatibility?
Can I apply DIDL ?

Legolas
27-05-2007, 11:43 PM
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. :)

unneon
30-05-2007, 06:02 PM
Im using .nds file^^'

I tested this arm9 code and worked :

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.

now I'm trying to use the graphics of the touch screen same as the normal screen (VRAM_A)

Legolas
30-05-2007, 09:15 PM
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 :)

unneon
30-05-2007, 10:50 PM
here is the code:
http://rapidshare.com/files/34337474/arm-nds.rar.html

Good investigation ^^

Legolas
31-05-2007, 12:11 AM
here is the code:
http://rapidshare.com/files/34337474/arm-nds.rar.html

Good investigation ^^

It works just fine here on my phat ds, both your executable and a recompiled one :shock:

By the way, I have uploaded a new lib version on libndsfpc (http://sourceforge.net/projects/libndsfpc) SVN. At this time 3d does not work anymore (something goes wrong in glLoadIdentity and in some other funcs), but the 2d part is pretty usable. If you want give a try to this new version, remember that you will need to update your devkitpro's libnds to the latest release too :)