Java Grinder is a tool that compiles Java programs to run on platforms like microcontrollers and consoles, by outputting native assembly code and using APIs to work with custom hardware like bespoke graphics and sound chips. Amongst other hardware, Java Grinder supports the Commodore 64, which uses a variant of the 6502 CPU. [Michael Kohn] realized the Atari 2600 shares this processor, and figured he’d get started on making Java Grinder work with the Atari by expanding on the C64 work done by [Joe Davisson]. Together, they brought Java to the Atari 2600 and made a game along the way.
According to [Michael], parts of the project were easy, as some Java routines compile down into as little as 1 or 2 instructions on the 6502. Other parts were harder, like dealing with the graphics subsystem, and modifying Java Grinder to output 8-bit bytecode to fit into the Atari’s tiny 4K ROM limit. Even with this tweak, they still couldn’t fit in a game and title screen. In the end they relied on bank switching to get the job done. [Joe]’s game is pretty solid fare for the Atari 2600 — blocky graphics and bleepy sounds — and they’ve uploaded it to the page so you can try it yourself in an emulator.
At the end of the day, porting Java code to a system with 128 bytes of RAM probably isn’t going to be particularly useful. However, as a coding exercise and learning experience, there’s a lot of value here in terms of building your skills as a coder. Other such experiments have shown us Java running on other unexpected devices, like the Sega Genesis or the MSP430. Video after the break.
I’m surprised this is possible with the 2600. I have never programmed one, but my understanding is that due to the severe lack of RAM, there is no framebuffer, and the game must generate each scanline, in turn, just in time to be displayed, AKA “racing the beam.” Doing so requires really tight control of cycle counts that would be difficult to manage from anything but assembly.
All the same, very cool
Same here… which makes me want to check out how they did it. Really cool hack!
Ah, it has been answered — asssembly is required. At the time I posted my comment, the linked website wasn’t responding so I couldn’t read the info there.
There are BASIC compiler for Atari. Look up batari BASIC.
But coding for 2600 is still a pain in the butt, more so with modern TV being very picky about video standard. Some modern TV can’t do 240p at all and early video games including Atari and NES were designed for 240p only (not a full 525 lines per frame). Older TV were fine with few lines variation.
On the Atari vertical timing is purely in software. That’s why PAL and NTSC versions needed different code, or else the wrong type would make the screen roll endlessly. It has to send all 525 / 625 lines, or else a TV wouldn’t accept it. It’s not 240p, it’s 480i, like standard TV used to be. Just the same set of 240 lines repeated twice. I imagine it’s the same for the NES. There’s only 240 lines you can program for, but the TV output signal is standard.
I seem to recall that there’s actually a half-pixel offset per-field on the NES, which is what causes the “moving” color fringing on NTSC TVs.
Are you sure about that interlaced timing bit? The few 2600 kernels that I’ve actually looked into use a constant integer number scanlines on every vblank.
It does use assembly for some things, like the rendering kernels. You basically create API calls for whatever assembly routines you need to run. The game logic itself uses the bytecode compiler. Java is used as the “higher-level” language, but as they say.. “some assembly required”.
Here is the main game source so people can get a better idea of how this works:
https://github.com/mikeakohn/java_grinder/blob/master/samples/atari_2600/SpaceRevenge.java
Each API method (such as “Atari2600.setPlayer0Sprite()” causes the compiler to insert a call to the appropriate machine language subroutine. Otherwise the higher-level if-statements, for-loops, and math use the bytecode compiler.
It doesn’t really run java, it statically recompiles java bytecode to run on the target.
“Java Grinder \n\n Compile Java bytecode to microcontroller assembly.”
The article does point that out, that it produces native assembly.
This confusion is caused by Sun’s ingenious idea to call the language Java, the bytecode Java, and the virtual machine Java Virtual Machine. Grinder translates / compiles the compiled Java bytecode, but doesn’t implement the virtual machine. So there’s no garbage collection, either, come to think of it. Which is fortunate cos I dunno how much RAM you’d need to manage garbage collecting 128 bytes of RAM.
The whole thing made more sense when it was still called OAK, I hear.
They probably would have had better luck with the Atari 800/XL/XE computers, the 2600 was a joke.
They got it working. And the 2600 is an extremely difficult technical challenge. The chaps back in the day must’ve dreamed in assembler.
Java is *garbage collecting* much *GC* faster tha*GC*n C/ASM. Every *GC**GC* thing should *GC**GC**GC* be written in java for *GC**GC**GC* maximum *GC* *GC* sp*GC**GC*eed.
This is pretty neat. The Atari 2600 coder in me is a bit skeptical of the huge size (the game looks like something that could fit in 2k or even 1k) but this could definitely be an option for those who want to play with an object oriented language on the platform. Much like batari BASIC, people will likely stick to the pre-made kernels. Personally I find writing new kernels and demos much more fun :)
Can we stop abusing the work BESPOKE? Its a word used to describe commissioned custom made clothing… not custom made “anything”.
Bespoke is the past tense of bespeak. Bespeak means to ask for in advance. It was commonly (but not exclusively) used for clothing. In any event languages change and evolve…we need to evolve with them or run the risk of sounding like a crotchety old man.
Yes, why not sound like a pretentious hipster instead?
This is Java running on an Atari. The only way to make it more hipster would be to port Ruby to Atari.
Is Java hipster cos it’s become retro? Surely it’s not new enough any more for the other kind of hipster appeal. More importantly, what do Apple think about it?
Incidentally it’s some time around now, that Java’s launch is closer in time to the Atari 2600, than it is to the present day. When was it, about 1994? 2600 was 1977 (a good year for many things), and now is 2017.
No! It would be more hipster to run this on an Atari emulator running on Java! :-)
http://javatari.org
Now all we are waiting for is for someone to fun Minecraft on it
Nice! Did you try it in http://javatari.org?
It would be cool to see an Atari emulator written in Java, running an Atari game that was written in Java!!! :-)