Waze for WP7 – the journey begins

As Microsoft employee you are entitled to get Windows Phone device.

As a happy owner of iPhone I wanted to have similar experience and tools before moving to different device.

What i need before converting:

1. Hebrew support – there are all sorts of helpful utilities i can live with √

2. Hackernews app – I can (and will) write one pretty easily 

3. Calcalist technology RSS feeds – Mivzakim app covers that 

4. Waze – No current plans to provide WP7 version of that app.

OK – now i have a challenge – converting the client code (GPL) to managed code.

First Try

The naive way is take the C code and convert it line-by-line to C#.

3rd party code

Looking at the code i found out it uses several 3rd party libraries. No need to convert those as C# already has equivalents as part of the language or as a free managed library (zlib, libpng etc.).

Cool, so i took Waze code and replaced every call to 3rd party library with a call to C# exe file that does the equivalent action (need to uncompress steam? just call Uncompress.exe with input file containing the compressed data and filename for getting the uncompress payload back).

“3rd party graphics cannot work that way” you say. To mitigate that, i replaced each drawing command with code that write the shape types along with all the params to running-number file and built C# exe that monitors those files. Upon detecting new file it just parses the command and draws the required shape/text.

This helped me strip down the external code entirely while still being able to see nothing was broken.

Convert the code

I tried CppToCsharp hoping it will leave me reasonable amount of code to convert.

Well… it didn’t. While the tool did fine job at converting some of C/C++ challenging constructs (MACROs, pointers etc.) it left me with 20K errors spanning over 400 files.

Good thing is that you can evaluate the pace of conversion by number of files you convert per day. Once you finished with a file – you won’t come back editing it.

So after a week of intense evenings i got to 10% (40 out of 400 files were converted, 20K errors reduced to 18K).

This is not to say the program will even load – i just converted the commands to my best knowledge and expected long debugging sessions to see the areas i need to rewrite.

So we are talking about at least 10 weeks of conversion after which i will have specific version converted. Every fix to the original C code will have to be migrated to this version so i didn’t have high hopes Waze team will take my code and continue maintaining two different source codes.


Soon after getting to the 10% milestone, i got introduced to Waze’s CTO and discussed my plans with him.

Then he dropped the bomb: Waze’s BlackBerry version has similar issue as you can only develop in Java for this platform and guess what, they already have it running. Well, how did they do that you ask?

Cibyl is the answer. Naturally many people have though about this problem before and Simon, the creator of Cibyl, actually implemented fully working solution.

In short what Cibyl does is the following:

1. Compile your C/C++ code into MIPS ELF file.

2. Since MIPS is built on RISC architecture, it has small number of assembly commands. Each of them can be converted to JVM bytecode corresponding command(s).

3. Each system call (fputs etc…) is being replaced by a call to Java function with corresponding functionality

That’s it!

So your work is summed up to:

1. Getting your code compiled in GCC

2. Replace all system calls to NOPH_<syscall_name> in your C/C++ code.

3. Provide implementation for all NOPH_<syscall_name> in Java.

4. Run Cibyl

5. Collect all output class files to Jar and you that’s it.

This way you can keep ONE code base and keep only one dedicated sub-directory for system calls (which you probably already have if your product is cross-platform one).

More details on the next post.

About these ads
This entry was posted in Waze, WP7 and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s