[casual_games] Writing C programs for J2ME

Simon Kagstrom simon.kagstrom at bth.se
Mon Jul 31 06:25:21 EDT 2006


Hi!

While browsin the archives, I saw a thread from January 2006 where the
conversion of C-games to Java/J2ME was discussed:

Lennard Feddersen <Lennard at RustyAxe.com> wrote:
> Does anybody have any experience with automated C to J2ME style
> tools?  I'm in the early days of my next project and think it would
> fit well on cell phones but would prefer to do my PC coding in C.

(So I'm replying to a seven-month old mail :-))

Excuse me for the "marketing", but I'm working on a free-software
project called Cibyl, accessible at

http://spel.bth.se/index.php/Cibyl

Cibyl allows C programs to be recompiled into Java bytecode. It uses
a GCC MIPS cross-compiler to compile the C code and then a binary
translator to recompile the MIPS binary into Java bytecode (later
assembled by Jasmin).

Parts of the MIDP 2 API has been implemented in C (what I've needed so
far), but the process is practically completely automatic, so adding
more is easy.  A J2ME "hello world" looks like this:

   #include <cibyl.h>

   int main(int argc, char *argv[])
   {
     NOPH_GameCanvas_t canvas = NOPH_GameCanvas_get();
     NOPH_Graphics_t graphics = NOPH_GameCanvas_getGraphics(canvas);

     /* Select red pen, then draw a line */
     NOPH_Graphics_setColor(graphics, 255,0,0);
     NOPH_Graphics_drawLine(graphics, 10, 10, 50, 50);

     NOPH_GameCanvas_flushGraphics(canvas);
     return 0;
   }

The build system for applications is currently a bit rough and is
fairly dependent on a GNU system (GNU Make, binutils etc), but should
be possible to get running with Cygwin fairly easily.


Anyway, I'm only a hobby games programmer, and I'm doing this on my
spare time just for the fun of it. I would be happy if someone tried
Cibyl, though!

// Simon Kagstrom


More information about the Casual_Games mailing list