OpenTTD on the Sharp Zaurus ...

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
josh
Engineer
Engineer
Posts: 10
Joined: 12 Jun 2004 15:40
Location: Mainz, Germany

OpenTTD on the Sharp Zaurus ...

Post by josh »

Hi, all!

I am playing around with OpenTTD and my Zaurus SL-C760 (640x480) PDA; I have just installed an optimized SDL and kernel to squeeze out some extra fps from the Ati W100 graphics.

Cross compiling went well; startup seems o.k.

But the language string management is causing some trouble. There are strings requested via GetString() that do not exist, followed by an exit without any comment. I have to identify the calling function yet (is there a simple way in C except making all callers print out messages?). And I still have to compile it for my PC Linux to identify any differences. After all, this is just a first sign of life - not a desperate cry for help ... :wink:

Of course, if somebody would like to enlighten me about the language file and string management (the basics in two or three sentences) I would not object :P
ChrisCF
Transport Empire Developer
Transport Empire Developer
Posts: 3608
Joined: 26 Dec 2002 16:39
Location: Over there --->

Post by ChrisCF »

The string management as it is right now is awful, and I wouldn't try finding your way around it. I expect it's likely to change on account of the fact that it's worse than some of the classic UNIX string gaffes, e.g. printf("%d document%s printed", n, n=1?"":"s"). It *should* be somewhere high on the list of Sawyer's optimsations that need unoptimising :)
pasky
OpenTTD Developer
OpenTTD Developer
Posts: 90
Joined: 25 Apr 2004 15:14
Location: Czech Republic
Contact:

Re: OpenTTD on the Sharp Zaurus ...

Post by pasky »

josh wrote:I have to identify the calling function yet (is there a simple way in C except making all callers print out messages)?
If you are working on a glibc-based system:

Code: Select all

#include <execinfo.h>
...
void *stack[20];
size_t size;

size = backtrace(stack, 20);
backtrace_symbols_fd(stack, size, 2);
Or you could use your favorite debugger.
The flush toilet is the basis of Western civilization. -- Alan Coult
josh
Engineer
Engineer
Posts: 10
Joined: 12 Jun 2004 15:40
Location: Mainz, Germany

Post by josh »

ChrisCF wrote:The string management as it is right now is awful, and I wouldn't try finding your way around it. I expect it's likely to change on account of the fact that it's worse than some of the classic UNIX string gaffes, e.g. printf("%d document%s printed", n, n=1?"":"s"). It *should* be somewhere high on the list of Sawyer's optimsations that need unoptimising :)
Um, does that mean we are in fact working with the code from The Master? That might explain many interesting constructs I encountered on my quest for 'porting bugs'. I remember running TTD on a 386 with the amount of memory that today's hard disks carry as cache ...

Funny thing is, my PDA has 64 MB of RAM and most of the time does not know what to do with it :)
josh
Engineer
Engineer
Posts: 10
Joined: 12 Jun 2004 15:40
Location: Mainz, Germany

Zaurus: first run succeeded

Post by josh »

Okay, it's running on my Zaurus right now. The speed is absolutely acceptable with my optimized SDL (I'd say, 386-40 or so).

The string bug was really nasty (I really should learn to use a debugger, but I'm spoiled by script programming); thanks for the help!

There are (up to now) five issues when trying to crosscompile (and run)OpenTTD 0.3.2.1 for ARM architecture, some might be compiler-specific (I have trouble using compilers other than gcc-2.96 for Zaurus stuff).

I did some crude workarounds that certainly are not fit for patching the main code base. If anybody is interested, I could post a list here ...

Meanwhile, I'm hunting for more bugs. 8)
ChrisCF
Transport Empire Developer
Transport Empire Developer
Posts: 3608
Joined: 26 Dec 2002 16:39
Location: Over there --->

Post by ChrisCF »

josh wrote:Um, does that mean we are in fact working with the code from The Master?
In which case, you must be one of the naive folk that didn't know that this is a straight port of the disassembly to C. Hence the need to "unoptimise" the retarded sections. :)
josh
Engineer
Engineer
Posts: 10
Joined: 12 Jun 2004 15:40
Location: Mainz, Germany

Post by josh »

:!:
---------
Well, it's running smoothly now on my Zaurus.

There were some alignment issues that I could fix by adding GCC_PACK to all of the TileStructs. No idea how that affects performance ...

Anyone interested in hosting the binary package? I'd prepare an IPK file which is the install format for the Zaurii.
User avatar
orudge
Administrator
Administrator
Posts: 25137
Joined: 26 Jan 2001 20:18
Skype: orudge
Location: Banchory, UK
Contact:

Post by orudge »

If the file is smaller than 2MB, just attach it to a post here.
josh
Engineer
Engineer
Posts: 10
Joined: 12 Jun 2004 15:40
Location: Mainz, Germany

Post by josh »

So here it is, not even 500k of pure joy. Tested only on the C760, might run on the other models with screen resolutions of 640x480. A tycoon in the shirt pocket ... :P

I added the extension ".tar.gz" to the file because ".ipk" was rejected by the board system. Please remove it before installing!

(IPK files are basically special tgz files so you can inspect them as usual.)

Is there a possibility to add the file to the OpenTTD download page?
Attachments
openttd-c760_0.3.2.1_arm.ipk.tar.gz
Binary install file for Zaurus SL-C7x0
(467.27 KiB) Downloaded 4041 times
josh
Engineer
Engineer
Posts: 10
Joined: 12 Jun 2004 15:40
Location: Mainz, Germany

Post by josh »

:!:

Just a note to all Zaurus downloaders:

Read the docs about installing on http://www.openttd.com !!
-------------------------------------------------------------

Like with all OpenTTD distros you need to add the .grf files plus "sample.cat" from the Windows version of the original Transport Tycoon Deluxe and put them into /opt/QtPalmtop/openttd/data.

--
Last edited by josh on 21 Jun 2004 06:04, edited 1 time in total.
josh
Engineer
Engineer
Posts: 10
Joined: 12 Jun 2004 15:40
Location: Mainz, Germany

Post by josh »

Quote from forum "General OpenTTD", "topic OpenTTD gone mobile!":
blakeyez wrote: I, along with my friend, have been experimenting with getting OpenTTD running on the Sharp Zaurus SL-C750 pda. It's a japanese-only model that runs linux :)
...
The other major issue is that the sprites aren't all being loaded correctly. For example, 2 of the 4 train depot graphics are slightly messed up, and in some cases the train comes out of the side of the depot instead of the entrance :) It does crash occaisionally as well, but it all seems to trace back to incorrectly loading the sprites.
I'm a bit sorry, I did not check out all forums about OpenTTD before doing what I did. I could have joined forces with you ...

Anyway, above I have posted an IPK installer of version 0.3.2.1 for the Zaurus SL-C760 (should run on the 750 as well). So far, it seems it's running without hickups for quite a while (did'nt test run for very long).

Nearly all of the porting problems are caused by alignment issues between x86 and ARM. The code for extracting the right sprites is heavily byte/byte pointer related. Ints and Longs are often regained in the code from byte pointers by doing this:

Code: Select all

*(uint32*)some_byte_pointer
If the data you access is accidentially not aligned to 4 byte words, the ARM will return somewhat "rotated" data, thus screwing for example sprite IDs.
So if you run into problems it's a bit more secure to use

Code: Select all

(sbp[0] + (sbp[1] << 8)) + (sbp[2] << 16)) + (sbp[3] << 24))
to explicitly put together your uint32 (or uint16) from bytes (sbp = some_byte_pointer).

The other major problem is alignment related as well. The access to structs with mixed byte/int/long elements may fail because the arm compiler works with "padding", filling up bytes silently to the next word boundary because memory access is optimized to read whole words.
If you access these structs bytewise you again get in trouble with the data you get back.

The solution/workaround in this case is to add a compiler attribute to the structure to prevent this padding from happening:

Code: Select all

struct {
  uint16 element1;
  byte element2;
  uint32 element3
} __attribute__((packed)) MyStruct;
Luckily, there is already a nicer macro for this in OTTD so you just have to change the structs like this:

Code: Select all

struct {
  uint16 element1;
  byte element2;
  uint32 element3
} GCC_PACK MyStruct;
These problems obviously affect string and sprite management the same.

I've really learned a lot during this port, it seems ... :?

(If somebody is interested about my SDL setup contact me personally and I'll put up the information in one of the other forums.)
blakeyez
Engineer
Engineer
Posts: 7
Joined: 11 Jun 2004 19:15

Post by blakeyez »

Well done! Glad to see someone else was interested in working on this.

We suspected it was memory access that was the problem, but I still haven't received my Zaurus from Japan yet (should be mid-week when I get it) so I was unable to test it except with my friend's unit.

Have you got it working 100% now? Do trains come out of the sides of depots like they do on our build? :)

Dave
josh
Engineer
Engineer
Posts: 10
Joined: 12 Jun 2004 15:40
Location: Mainz, Germany

Post by josh »

blakeyez wrote:Have you got it working 100% now? Do trains come out of the sides of depots like they do on our build? :)
Oh, "100%" is a mighty big thing to claim ... :wink:

- First, I didn't get complaints anymore of access to wrong strings or sprites.

- Second, I was able to load (and play) a rather complex savegame from a Windows 'session'

- Third, there were no crashes during my last - not very extended - testing period.

But I did not replace ALL calls of the said kind - *(uint32*)byte and the like - just those which produced obvious errors. So there still may be bugs lurking somewhere ...

By the way, which compiler did you use?
blakeyez
Engineer
Engineer
Posts: 7
Joined: 11 Jun 2004 19:15

Post by blakeyez »

We were using gcc 2.95.2 I believe - it was some 'zgcc' cramfs package that Kenny found. Using this instead of 2.95 helped a lot by itself, as 2.95 caused all sorts of problems.

As soon as my Z gets here, I'd love it if you could send me a source package with your modifications (or perhaps a patch against the latest SVN codebase). Would you mind targzipping it up and e-mailing it to me: dgoodlad at gmail dot com? I'd really like to see if I could help get this really solid and find as many little issues as possible.

By the way - you mentioned that you optimized SDL (or were using an optimized package). What changes have been made? Is this psycho77_'s zports version?

Thanks!
Dave
josh
Engineer
Engineer
Posts: 10
Joined: 12 Jun 2004 15:40
Location: Mainz, Germany

Post by josh »

I think we rather move the discussion over to the "Zaurus User Group"
(I think I've seen your name around there), because it might get into off
topic regions here.

I'll start a new thread in "Everything Development"/"Linux Applications".

See you at the ZUG!
User avatar
orudge
Administrator
Administrator
Posts: 25137
Joined: 26 Jan 2001 20:18
Skype: orudge
Location: Banchory, UK
Contact:

Post by orudge »

Could someone tell us where this user group is, please? :)

EDIT: Hmm, Googled for it. http://www.zaurususergroup.com/ - seems obvious enough. :mrgreen:
tovarish
Engineer
Engineer
Posts: 1
Joined: 30 Dec 2004 16:37

Post by tovarish »

hi,

i would like to know how that alignment issue was solved.

thanks
tovarish
scream
Engineer
Engineer
Posts: 1
Joined: 03 Jan 2005 19:10
Location: Riga, Latvia

Post by scream »

Hi! I'm trying to cross-compile latest OpenTTD(not CVS) for Cacko RC8 Kathrin (X11 ROM) using their SDK. I modified Makefiles but compilation fails on a compiler error that I attached to this post. I also attached a makefile. :roll:
Attachments
bugreport.zip
Make output and Makefile
(9.18 KiB) Downloaded 528 times
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 21 guests