Robots w/Lasers

August 8, 2007

Java for NDS?

I know what you’re thinking…”That’s a horrible idea and you’re a horrible person for suggesting it!”

The main problems with Java on DS:
1. Interpreted languages are slower, the overhead is bad on a slower embedded platform
2. No direct memory access. Almost all of the DS hardware is interfaced by reading and writing directly to specific memory locations
3. No primitive unsigned 8-bit types. What were they thinking?

But…I went ahead and did it anyway, just for fun. I didn’t start from scratch, I took Torlus’s KVM port to GBA and used that as a base for getting it to work on DS. Right now, when it starts, you pick a .class file, and it will run it! In addition, using KNI, I’ve written a basic wrapper around parts of libnds, enough to read input from the touchscreen/buttons, and to move sprites around.

Download here: java4nds_r2.zip — includes the compiled KVM.nds, some examples along with source code, and instructions on making your own .java files.

To use this demo, place kvm.nds, all the *.class files, and all the *.bin files on the root of your flashcart.
Run kvm.nds, then select a .class file to run. There are a few examples testing various stuff.
Don’t forget to DLDI-patch the kvm.nds

Filed under: Java,Nintendo DS,Software — davr @ 8:36 am

68 Comments »

  1. A great work! Congratulations! :-) I will test it this night at my home!! ^_^

    Comment by avelino — August 9, 2007 @ 12:24 am

  2. very very nice, will this tool get a full JAD/JAR support?

    Comment by sotex — August 9, 2007 @ 3:28 am

  3. Cool! I’m looking forward to seeing how this evolves! I’ve been writing Java apps for many years now, but I never thought I’d see my fav language (Java threading! YAY!!!) on the DS. Way to go!

    Comment by jeff — August 9, 2007 @ 5:47 am

  4. Hooray! Now my DS can crash just like a server! Tons of VB programmers who can copy/paste java code can now target the DS and tell users to ‘upgrade their machine’ and ‘add more memory!’

    Yes, you win at teh internet!

    Comment by javaRULES — August 9, 2007 @ 7:07 am

  5. [...] there’s a compression utility for the DS that carpman is developing. It seems that there are more things to add, such as .zip support, but it’s [...]

    Pingback by from the gutter » Blog Archive » cool DS apps — August 9, 2007 @ 11:20 am

  6. Could you open Source?
    ibm_chen@163.com
    Chenmin

    Comment by chenmin — August 10, 2007 @ 4:04 am

  7. Nice Application, Hope this will grow to something big!

    Comment by penpvdbs — August 10, 2007 @ 6:21 am

  8. I’d be interested to see some benchmarks between this and C++. If it works even halfway decently, some very simplistic games may take advantage of java’s simplicity.

    Comment by FireSlash — August 10, 2007 @ 7:48 am

  9. ”That’s an excellent idea and you’re an awesome person for suggesting it!”

    Comment by LiuRR90 — August 10, 2007 @ 10:45 am

  10. Can this run .jar files?

    Comment by The Great Unknown — August 10, 2007 @ 4:05 pm

  11. As it’s compiled now, it cannot run .jar files…but I think I just need to enable it. I haven’t tested. jar files aren’t anything special, it’s just a .zip with some .class inside it.

    Comment by davr — August 10, 2007 @ 4:52 pm

  12. you are a god cant wait for more

    Comment by matt — August 10, 2007 @ 8:57 pm

  13. You rock! Can be really a superb improvement on ds homebrew developing. Thnx. Hope you can make it run .jar files etc

    Comment by bigfoot — August 11, 2007 @ 9:58 am

  14. Just unzip your jar files and you can run it now. What is everyone’s fascination with jar files?

    Comment by davr — August 11, 2007 @ 10:49 am

  15. You mean, decompress? And run the .class files within it?

    Comment by The Great Unknown — August 11, 2007 @ 1:17 pm

  16. JAR files are in ZIP format as davr said above, So you can just rename to .zip and open them, i.e. unzipping.

    Comment by natrium42 — August 12, 2007 @ 10:01 pm

  17. Hi,

    I would like to congratulate davr for its exciting work! I’ve just tested it and it works really well. I’m both a NDS enthusiast and a J2ME programmer, and I was really willing to se some solution to allow running Java on NDS. I believe it opens much more possibilities for Java developers and users.
    I would like to know what are your plans, davr. Do you intend to open source it? I believe we could easily build a implementation of MIDP 1.0 over the libnds wrappers you have. If we are able to implement also MIDP lifecycle and JAR file parsing, then we have the first J2ME implementation for NDS!
    Also, I would like to discuss with you about the JAR files. Yes, we can always unzip the JAR file, but then we are going on the opposite direction from the Java universe. Packaging a Java application in a JAR file mas sense both in space saving and application distribution at a really small cost, and allow us to aim for interoperability.
    I would really like to contribute, specifically on the implementation of MIDP 1.0 over the libnds wrappers, but first I would like to know more about which direction you want to take with this project.
    Way to go, davr!

    Comment by fabinader — August 14, 2007 @ 5:05 am

  18. [...] want to develop homebrew in their favorite language, i’ve found a very, very useful thing : Java4NDS. Now, you can port your java application on your Nintendo DS. It’s very [...]

    Pingback by Nintendo DS and chinese learning program. And other stuff. — August 16, 2007 @ 11:11 am

  19. Thank you very much for this!

    But I´ve a prpblem with this..
    I compiled a *.java file and had a *.class file.
    But when i will start this file with java4nds (kvm.nds)
    there comes: “Selected: HelloWorld

    OK
    ALERT: java/lang/classFormatErro
    r: Bad version information.

    JVM Exited with 127
    Press A to load a class.”

    Can anyone help me?
    The files, which comes from you goes without a problem..

    Comment by c3pl1o — August 18, 2007 @ 4:48 am

  20. edit: It´s the same if i will comile your .java files. It doesn´t goes..
    But your .class files goes perfect.

    Comment by c3pl1o — August 18, 2007 @ 4:58 am

  21. Make sure you are compiling for an older version of java. KVM does NOT support 1.5 or 1.6 (aka 5 or 6), just compile for as old a version as you can. Check the help files on your compiler to find out how to change this setting.

    Comment by davr — August 18, 2007 @ 8:49 am

  22. Thank you very much! with v1.4 it goes very good!
    But have you any idea how to use a touchscreen keyboard in the java files?

    Comment by c3pl1o — August 18, 2007 @ 9:24 am

  23. I wish to port a Japanese vocabulary learning program I wrote for my Japanese mobile phone (that has since died). I wrote it about 2 years back in DoJa (strange J2ME profile but not too strange). My question is, what is the default font, and does it support hiragana/katakana (Japanese characters). I know that all DSs have Japanese fonts already installed (even EU and US models) as when I host a wireless game, the other players can see my Japanese name.

    If Japanese characters are supported, I will surely use this product to port my simple learning application to the DS. I am very excited by this news indeed.

    Comment by Takapa — August 25, 2007 @ 6:51 am

  24. Java4NDS can do Japanese characters, but you’d have to write the code yourself.

    The DS itself does not have any fonts that coders can use (the firmware has a font, but it’s not accessible once your own program starts)

    Comment by davr — August 26, 2007 @ 5:04 pm

  25. oh..
    I want Sound Class… :-(
    but Java4nds is very cool!!!

    Comment by rozie — August 27, 2007 @ 5:24 am

  26. Would you like to give me the source code?
    I´m from germany, so I wanted to have a german kvm.nds.

    With wich editor have you made this file?

    Comment by c3pl1o — August 30, 2007 @ 11:49 am

  27. Hey, it’s pretty cool. Just saw this:
    https://j2me-nds.dev.java.net/
    Still in planing stages though.

    Comment by d — September 7, 2007 @ 10:59 pm

  28. https://j2me-nds.dev.java.net/ ain’t been updated for 6 months, there’s nothing in svn but the web page… it’ll never leave the planning stages.

    Comment by q — September 18, 2007 @ 1:07 pm

  29. Hey,

    Good work :) I’m also a J2ME programmer, just did the likes of R-Type among other things for J2ME phones…

    I agree with the coder’s comments above, if you implement midp lifecycle, you’d get effectively the beginnings of a cool emulator type thing – heck, you’ve got the res there to run J2ME midp2 apps, with the DS on it’s side !

    Great stuff !

    Comment by John — October 11, 2007 @ 11:59 pm

  30. great work !!!
    please implement wifi support

    thanx

    Comment by toybox — October 30, 2007 @ 6:15 pm

  31. J2ME

    Comment by asdf — November 30, 2007 @ 2:16 pm

  32. Hey! This looks like it SHOULD be awesome… But mine doesn’t run right!
    I’ve even patched the nds file, but on startup, all I get is
    “JAVA CDLC for NDS
    Initial port to GBA by Torlus
    Port to NDS by davr”


    and that’s it. It doesn’t go beyond that to where I can select the *.class files…

    Any suggestions?

    THANKS!!!

    Comment by rwt — December 1, 2007 @ 5:07 pm

  33. Sorry, I’m stupid. I used the wrong DLDI patch…

    GREAT stuff!

    THANKS AGAIN!!!

    Comment by rwt — December 1, 2007 @ 6:12 pm

  34. Wow! This is insane… Makes me think forward… Eclipse for NDS… YAY! :) Someone port SWT pls :)

    Comment by ppeterka — December 3, 2007 @ 8:49 am

  35. WOWWOW! Fantastic. You Are GREAT!
    I hope I can make 3D Game with Java4NDS .
    God Bless You.

    Comment by younghwan,kim — December 12, 2007 @ 5:17 pm

  36. I’m also a j2me developer, and looking for a tool to run java apps on NDS. I would contribute if the project was opensourced. Feel you free to get in touch with me at mixaz at mail dot ru, anyone interested.

    Comment by mixa — December 14, 2007 @ 7:11 am

  37. I’ve decided to release my source, since I haven’t really made any progress on it, and don’t really have any plans for it.

    The source is here:
    j2me_cdlc_nds.rar (6.1MB)

    The build files are in the ‘j2me_cldc/kvm/VmSkel/build’ subdirectory

    No support is express or implied, you’re pretty much on your own with it. I might be able to answer a few questions, but I’m not gonna be able to walk you through any of it in detail.

    Comment by davr — December 14, 2007 @ 12:04 pm

  38. Hey…
    You rock man!

    I’m a game designer but also j2me enthusiast and programmer… and this is very good.! please improve it .. open source it or whatever… but keep in mind that you are giving us a great tool!!! Maybe you can tell sun to develop a j2me for nds. :D maybe nintendo will agree.

    Comment by maxtrix — February 27, 2008 @ 10:59 am

  39. Hi all,

    will it be possible to port this Java X86 Emulator: http://www-jpc.physics.ox.ac.uk/index.html

    Then we could have real MS-DOS on the DS. Then we might could install Windows95 like they did on the PSP:
    http://www.dotsis.com/mobile_phone/showthread.php?t=55133

    Regards,
    Dary

    Comment by Dary — March 20, 2008 @ 2:57 pm

  40. This is great. Thank a lot Darv!

    By the way, in case that I would like to have more than 1 sprite at a time, does anyone know how to set image for each sprite ?

    Thanks

    Dejavu S.

    Comment by Dejavu S. — March 23, 2008 @ 3:39 am

  41. Great work davr!
    thanks for the sources, I actually recompiled it and working on the update.
    now fixed:
    - java heap enlarged to 2MBytes (from the 65KBytes)
    - returned back the preverification – j2me classes MUST be preverified beforehand in order to work in KVM (and other mobile devices) – because some non-preverified classes failed to work and caused stack errors.
    - implemented proper timer (now System.currentTimeMillis() returns reasonable value)
    - implemented default (native) initialization of the videomode (modifying video registers from java somehow did’n work for me)
    - implemented png image read (modified sixlegs lib)
    - implemented native software blits between java images
    So far it seem quite usable so I’m heading towards the midp support.

    Comment by ole — May 22, 2008 @ 2:07 am

  42. Cool, ole. I hope you are able to make a webpage for it & release it when you make some more updates. I know a lot of people would be very happy with MIDP support.

    Comment by davr — May 22, 2008 @ 2:56 pm

  43. Will you make a tutorial for this? I have problems in some classes..

    Thanks…

    Comment by rads — May 23, 2008 @ 11:28 am

  44. Sorry, wont be writing any tutorials. At this point you need both advanced knowledge of Java and advanced knowledge of NDS internals in order to get much use out of it.

    Comment by davr — May 23, 2008 @ 12:17 pm

  45. I’ve released the r3 version that (partially) supports the MIDP api. You can grab it here: http://www.volny.cz/molej/pstrosnds/java4nds_r3.zip

    Comment by ole — May 31, 2008 @ 5:43 am

  46. Hi,

    Thanks for your release. I have a little question : Is it possible to run a Java Application with a DS emulator using your Java4nds ? Because I am working on a DS project but don’t have already a DS. And I encounter a problem with DS emulator (Dualis / Ideas) using Java4nds.

    Thanks to answer me ;) .

    Bye !

    Comment by Feleo — June 3, 2008 @ 1:30 am

  47. It is possible, actually I have done many tests just on the NDS emulator. I used Desmume ver. 0.8 emulator. Unfortunately the emulator is about 2x slower than the real machine (on my computer).

    Comment by ole — June 5, 2008 @ 5:36 am

  48. first, davr: your proyect its awesome.
    second, ole: Can u release a supercard SD version? (or if the R3 version can be patched w dldi or something).

    Comment by kai — June 19, 2008 @ 9:36 am

  49. kai: look at newer posts on my blog. he released a newer version that works with DLDI

    Comment by davr — June 19, 2008 @ 10:22 am

  50. hey :)

    first off, great work. this is definitely a step in the right deirection for DS homebrew.

    i am, though, on a mission. here in South Africa, we use a mobile application, MXit, alot. its just an instant-message service that costs next-to-nothing. it is also written in Java. now i’ll be totally honest, i know nothing of how java works. i downloaded a .jar file for a generic version of MXit. and i did wat i thought i should (which was obviously so wrong.) i took the .jar file, unzipped it, coppied all files inside to my DS root. copied a folder of all the files to the root. made the .jar file into a .class and .java file, put those on the root. and yes, didnt work.

    so my question is, can u help me get MXit to work? requires internet too. dunno if that makes such a diff. but i have managed to get it to run off my home-internet Wi-Fi signal before, so its possible.

    for more info:
    http://www.mxit.co.za

    for a generic version of the app:
    http://defza.com/mxit/mxitk.jar

    once again great work.
    peace from South Africa :)

    Comment by South African Josh — January 4, 2009 @ 1:38 pm

  51. Hello,

    I’ not a computer/NDS expert :-( , so this discussion is hard to understand. I’got a Kanji programm as a Jar file and a file for Palm OS. Is it possible to dezipp the Jar and run it on Java4nds or is it easier to emulate Palm OS-based PRC file (is there even a “Palm4nds” programm)??? I’m sorry, but I just start to leave the mainstream NDS and would like to have a “NDS for dummies”.
    Thank you very much :-)

    Comment by nekonetsuke — January 6, 2009 @ 1:58 pm

  52. That’s a horrible idea and you’re a horrible person for suggesting it!

    Comment by THE ANONYMOUS SAGE — March 5, 2009 @ 11:19 pm

  53. Is this going anywhere?

    Comment by jo — March 27, 2009 @ 2:53 pm

  54. Yeah… ole made a few updates since this initial post, including MIDP support. Check out his site for details:
    http://www.volny.cz/molej/pstrosnds/

    Comment by David R — March 27, 2009 @ 2:54 pm

  55. Thanks for the well done job on Porting Java for NDS.
    Your friend Ole made a good enhacement enabling CLDC / MIDP application with his PSTROS.

    Quick questions:
    1) Does Java for NDS able to run audio ?
    2) Does PSTROS with Java for NDS able to run audio ?
    3) Are you working in enhancements to have MIDP 2.0 on both ?

    Comment by Fernando — October 26, 2009 @ 3:27 am

  56. 4) Is it possible to use both screens, together, with your Java / KVM port to NDS ?

    Comment by Fernando — November 2, 2009 @ 7:37 am

  57. No Wi-fi support, no Opera Mini. :(

    Comment by Rafael — December 5, 2009 @ 11:51 am

  58. Are you going to inlcude WiFi support? I requested it :D

    Comment by Marti — December 13, 2009 @ 12:17 pm

  59. I’m gonna have to bump this old thread and point out…

    MINECRAFT

    Comment by John Sirbu — April 19, 2011 @ 5:52 pm

  60. hi,I should say that you guys are great!
    But…it that all?I think it still can not support the jar…though I didn’t test the jad…
    :(

    Comment by bywuu — May 17, 2011 @ 6:30 am

  61. I tested the jad,it can work but then it showed:

    ! nds/pstros/video/system.dsf

    what does that mean???

    Comment by bywuu — May 17, 2011 @ 7:07 am

  62. i was wondering since the activity on this project slowed down if i can use the source of the .nds so i can use that to auto load things. Also do you have any documentation for the libraries?

    Comment by Erik Decker — August 19, 2011 @ 6:19 am

  63. Erik Decker: Yes, I released the source. And someone else updated it to support more stuff. Try reading the links above you.

    Comment by davr — August 19, 2011 @ 10:45 am

  64. enable jar, then dumb down minecraft. no random terrain, rather pre chosen saves that are put on the r4, and also, who needs sound, if its a classic version, kinda like the mobile os version. same for terraria. remove random terrains, and dumb down some stuff, i know nozzing!!!!

    Comment by connor — December 8, 2011 @ 2:13 pm

  65. nice but is still dont now how to make something with GUI :(

    Comment by Kingperer — June 24, 2012 @ 8:42 am

  66. I get the error “ALER>T: Strange value of thisIP” for everything with this VM. At first, it seemed to be caused by the arrays I was using in my code. So I rewrote my code to use no arrays, and it still happens. No clue what’s causing it, Google doesn’t help. This VM is simply throwing an a unique error.

    Comment by khoraski — February 23, 2015 @ 7:51 pm

  67. My goodness, this thing is barely stable. I figured out the “Strange value of thisIP” comes from having too many characters stored in a string. Why’s this throw an error? Who knows. I’m know getting an “Illegal stack size” error for absolutely no reason at all. The code is completely valid. This JVM is just incredibly unstable and regular coding for it is just not good.

    Comment by khoraski — February 24, 2015 @ 9:09 pm

  68. will minecraft work?

    Comment by coinman_1 — May 9, 2015 @ 8:59 am

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress

Bad Behavior has blocked 2578 access attempts in the last 7 days.




Paid Advertisements
Renegade Motorhome - Costa Rica - Guitar Lessons - British Virgin Islands