PDA

View Full Version : FPC 4 GBA: Issues with the gnu linker...



WILL
03-08-2005, 07:12 AM
Well since I have put up the project page only one person has really gotten some kind of response to it. I'd hope that more would take an interest as it would really help in it's development.

I think the main issue right now lies in the usage of the gnu linker used by FPC. Namely how to get the crt0.o to link with the hello.o into a GBA rom. Then how to verify that it's a valid rom.

Legolas
05-08-2005, 02:31 PM
Okay, I went a little further from the last time. I have been able to compile a basic rtl, by making some little fixes to the linux' one. I think it could be the right way, because the gnu-arm crosscompiler, usually used for gba, works without changes from the basic linux rtl.
With this rtl the compiler works without errors. The next step will be to make a startup code (prt0.as), in order to put all things to the right place. The biggest problem in this step is to make to cohabit the fpc initialization code and the gba's one. I'm not comfortable with asm, so the work proceeds slowly. If someone is interested, i can make a little guide to show my steps until this point.

PS. I forgot often to say "sorry for my english"... well, if someone can't understand my words, we can try with french or italian :D

WILL
05-08-2005, 04:15 PM
Excellent job man! :)

Hmm... my asm skills are a bit rusty, but I might be able to haggle through it if needed. I think a little guide might be useful in keeping track of the progress up until this point.

As for the startup code or prt0.as as you mention it, i that the same as the crt0.as per chance? Or something totally seperate? And... what exactly does it need to do?


PS. I forgot often to say "sorry for my english"... well, if someone can't understand my words, we can try with french or italian :D
Damn! My french teacher was right, I might have actually needed to used it... :P

Legolas
05-08-2005, 06:18 PM
Well, I'll write this guide. Maybe you could correct my english mistakes... :D
About prt0.as: it is exactly as crt0.as, it does the same things.

WILL
07-08-2005, 07:53 PM
Hows that 'guide'thingy coming along? Doesn't have to be anything too elaborate. Just a decent enough outline to see what has been done and what needs to be done next. If you are stuck then just make it as specific as you are able then we will break it all down later.

As for the prt0.as and crt0.as is the one we are using now insufficient? I know that it's supposed to be a sort of hack, but will it not direct the linker to make a proper GBA ROM?

Legolas
08-08-2005, 11:23 AM
Oh, okay! I tried to make an exaustive guide, but it taken much more time. Hour startup code is ok, if is passed with the right options to the linker. However, after a little disassembling, I found why our executables can't run on a gba: fpc compiler adds some calls (FPC_INITIALIZEUNITS, FPC_DO_EXIT, etc.) that interfere with startup code. I tried to remove them and relinking the generated asm and - surprise! - it works! At the latest tomorrow I'll put here the step-by-step. Promised! :D

WILL
08-08-2005, 04:51 PM
That is excellent news!

Can you provide the source and indicate where it was changed? Files, etc...

Legolas
08-08-2005, 05:58 PM
Of course! I'll provide the sources of all files changed and a little text file with instructions. :wink:

WILL
08-08-2005, 11:36 PM
Awesome. When do you think you can post it here?

Also, was the rom tested? Does load in an emulator?

I'll be posting it on the FPC 4 GBA site, of course, so that others can help to start working on the basic hardware libraries... sound, video, etc...

As a great guide to these things I'd recommend going to the link with the book 'Programming The Nintendo Game Boy Advance' (http://www.jharbour.com/gameboy/) on the FPC 4 GBA page.

Legolas
09-08-2005, 01:37 PM
Done! Download the package from here (http://ilcaino.free.fr/fpc4gba/fpc4gba.zip) and feel free to add/remove/change everything you want :D

{MSX}
09-08-2005, 03:24 PM
wow, looks like you guys are getting something working with this project...
I've read the txt included and it seems like you've done a lot of work and research.
I knew that Italians do it better :mrgreen:

Legolas
09-08-2005, 03:50 PM
I knew that Italians do it better :mrgreen:

:mrgreen: :mrgreen:
I must prepare a t-shirt with my face and this slogan... maybe my sexual life could be improved :pig: :pig:

WILL
09-08-2005, 10:43 PM
I knew that Italians do it better :mrgreen:

:mrgreen: :mrgreen:
I must prepare a t-shirt with my face and this slogan... maybe my sexual life could be improved :pig: :pig:
Umm... I'm not goinganywhere near this one at all.. :P


As for FPC 4 GBA though... :roll: I think we have gotten to the first milestone. The next will be to get some working libraries going... video, sound, etc... and we have more than enough materials around to be a guide. Mr. Harbour is my preferance for reading materials. Perhaps if someone were to help with the converting of the C libraries then we can come up with a set of Free Pascal based units for GBA development. Maybe even a small DelphiX-style suite for beginners too! ;)

Interested in helping MSX?

Legolas
10-08-2005, 01:39 AM
I'm overworking this night, I know, but I can't sleep for excitation :D

I've done 4 little demos that you can find here (http://ilcaino.free.fr/fpc4gba/fpc4gba_examples.zip). A couple of them are a conversion from Mr Harbour's book examples. Below some screen caps (I know, I have said 4, but one is a simple black screen :roll:)

:toocool:

http://ilcaino.free.fr/fpc4gba/Immagine1.jpg
http://ilcaino.free.fr/fpc4gba/Immagine3.jpg
http://ilcaino.free.fr/fpc4gba/Immagine2.jpg

In the zip you can find sources and roms, so you can thest the speed in an emulator. Compared to roms made with C THUMB code, these look like snails, but we are in ARM mode...
In order to make the code working... As I have said in the guide, you must strip by hand the fpc initialization code, then reassemble all. Enjoy!

WILL
10-08-2005, 01:46 AM
Very nice my friend. ;) Looks like we finally did it.

I will be posting your package on the FPC 4 GBA site sometime today. I also have been looking at the sound device of the GBA aswell. I will be working at making a directsound.pas library for it in time. :)

Once I get this working on my system I will be preparing a submission and request to have FPK and the rest of the Free Pascal team include GBA support into the compiler directly. This will include the ARM7 instructions into the GBA target. And automate the proccess of stripping the FPC initialization code.

If I could get onto IRC on freenode it would speed-up the process as FPK isn't very good at replying to emails. I imagine he gets alot...

Legolas
10-08-2005, 01:52 AM
Good! :D
Anyway I think that the problem with initialization code is in the rtl that I have recompiled... Maybe I have included some wrong things. Well, we wait for some good news from fpc team :wink:

WILL
10-08-2005, 02:28 AM
Indeed. FPK seemed rather helpful from the start of this endevour so prehaps he will be willing to go the extra mile since we have demonstrated our willingness to keep the GBA port active...

{MSX}
10-08-2005, 06:22 AM
I'm overworking this night, I know, but I can't sleep for excitation :D

I've done 4 little demos that you can find


Wow, seeing something on the screen is a real milestone!
Very well done!



Compared to roms made with C THUMB code, these look like snails, but we are in ARM mode...


Umm maybe i missed something... why are your code slow? and what's this arm mode? will we be able to do full speed?

About me helping, well i don't have a gba, and i don't know if there are emulators for linux..
I guess i could have a try anyway.
Any hint for setting up the stuff on linux, Legolas?

WILL
10-08-2005, 11:38 AM
I found some errors in your included instructions


FPCMake modification
--------------------
Copy the files you found in "FPCMake" directory of this package in the directory

%FreePascal%\source\utils\fpcm

In msys (or a dos prompt), go to %FreePascal%\source\utils\fpcm and run
"make". Go to %FreePascal%\bin\i386-win32 and copy here the new generated file
fpcmake.exe. This utility is useful when you try to build the rtl, because it
generates all makefiles starting from a smuch more simple makefile.fpc.

Running 'make' does not produce a single exe file. Instead a few directories and a bunch of files; 'fpcmade.i386-win32' and 'fpcmake.inc'.

This kind of cripples your RTL set of instructions aswell. :? You may want to correct this before I go posting it. Everything else seemed to be detailed enough to follow. Only exception is the location of a good GNU make utility to use if you choose to NOT use msys, which I opted for myself to reduce the required amount of install packages and things one has to go look for and update later on.

MSX: The reason that the current ARM code is so slow is because that the GBA's normal ARM instructions are a bit slower than the ARM7 THUMB instructions. Don't ask me why, they just are. ;)

Until FPK adds support for ARM7 the compiler will be a bit crippled in this capacity. Hopefully once we manage to establish a nice package for his team to go over and add GBA support into the current compiler, we can look forward to them adding full GBA support into the current roadmap. :)

Legolas
10-08-2005, 12:05 PM
WILL: simply ignore it. fpcmake.inc is used to build fpcmake.exe, fpcmade.i386-win32 is a flag-file indicating that fpcmake is built. The directory you say contains the object files created in building time.
Regarding MSYS, an alternative could be cygwin, but the package is much more heavy and not so simple to use. Another is to use a dos shell, but you could have some conflicts between gnu make and inprise make, if you have delphi installed.

{MSX}: GBA have 2 asm instruction set, ARM (32 bit) and THUMB (16 bit). The THUMB instructions set is more fast, but at this time fpc can handle ARM only. I don't have a GBA too, but an emulator is enough. Visual Boy Advance is open source and is compiled for several platforms, linux included (of course :)).

savage
10-08-2005, 12:14 PM
btw, it seems the home brew PSP arena is kicking off. I have seen an Elf to PBD ( Sony's PSP exe format ) tool on the internet. This may be something worth looking at at a later date. More info @ http://psp-news.dcemu.co.uk/ & http://ps2dev.org/.

{MSX}
10-08-2005, 01:18 PM
MSX: The reason that the current ARM code is so slow is because that the GBA's normal ARM instructions are a bit slower than the ARM7 THUMB instructions. Don't ask me why, they just are. ;)


Umm ok.. But i've tried with Boycott Advance, and it's *really* slow.. i can see the screen being filled with Legolas programs..
Maybe that's normal, i don't know anything of gba programming..

Btw i'll be interested in PSP too, but isn't it impossible to develop for? I've heard that the actual firmware (the OS) doesn't let people run custom code and that's almost impossible to hack.. is this all true?

savage
10-08-2005, 03:06 PM
PSP has already been hacked, follow the links I posted earlier to find out how you can run your own code on PSP. They already have lots of emulators running on it, even an MSX emulator :).

Legolas
10-08-2005, 04:11 PM
Please, I need rtl/fakertl and rtl/template directories from an old release of fpc (I think pre 1.9.8 ) in order to see how create a simple rtl. Can you search in the maze of your hard disk and send it to me? Thanks in advance! :D

WILL
13-08-2005, 06:08 PM
Here (http://www.pascalgamedevelopment.com/files/188/fpc.zip) is an old copy I found on my desktop of all places. :) I don't know what version it is, but it is not 2.0.

WILL
21-08-2005, 01:41 PM
So does that file help at all?

Legolas
21-08-2005, 09:20 PM
Not really. The present rtl is changed a lot, as far I have seen. Now I'm studying GBATek and fpc sources, in order to make the changes needed to the rtl.
I have translated also a lib for gba from c to pascal and now is pretty simple to make some demos :)
ASAP I'll send lib, demos and a tool that translates images in pascal header.

WILL
21-08-2005, 09:26 PM
Excellent. I'll try to contact the FPC team. FPK is a hard one to get a hold of sometimes.

Hopefully we can get this work intergrated into the FPC chain it's self saving users the trouble of having to 'upgrade' the compiler manually.

As for the libs, demos and other such items. Please try to seperate them according to signifigance(demos or libs being seperate, etc). For those that like to get all of it at once, we can make an 'All-In-One' package for them.