logoalt Hacker News

Show HN: NES Contra (1987) port (ASM –> C and then C –> WebAssembly)

83 points • by tevlon • yesterday at 7:18 PM • 67 comments • view on HN

Based on vermiceli's annotated disassembly of Contra: https://github.com/vermiceli/nes-contra-us. Thanks for the great work.

I ported it in two steps. First to C: the game logic is translated routine by routine from the 6502 assembly, and checked frame by frame against the original in the Mesen emulator. Then the C code to WebAssembly so it runs in the browser.

The cherry on top: online multiplayer, so two players can play co-op over the internet.

Source: https://github.com/epoyraz/nes-contra-us


Comments

throwaway2037 • today at 7:32 AM

Wow, the source 6502 assembly with comments is incredible: https://github.com/vermiceli/nes-contra-us/blob/main/src/ban...

The whole thing (all banks) is more than 10,000 lines of assembly code. When I wrote assembly code for a university computer science course, it was hard to manage even 200 lines. I cannot imagine writing and managing 10,000 lines!

incr_me • today at 9:32 AM

Nice! Can you speak to your process? How much structure did you give the agent? Did you have to "discover" the right way to do the port? Perhaps you just asked Claude, and then iterated? How do you feel about the final architecture/layout of the code, and would you approach a similar project in a new way given what you've learned?

You said in another comment:

> Then, i spent some time in building a harness and collect telemetry data in Mesen. Once, i had that: i just played the game in the emulator and asked Claude Opus 5.5 to use this as verification.

Can you comment on how this verification process worked?

You'll have to forgive me for not trying to answer these questions myself by investigating the code/git history, but... I hope you understand.

Actually, I am peeking around the code a bit and it's a bit disappointing, but it's what I should have expected having tried a project like this myself with a Game Boy game. I would like to see what an AI-produced semantic (?) rewrite of a retro game would look like. That is, what a port/rewrite that wasn't so faithful/wedded to the original ROM layout or platform architecture. For example, the agent (and you, presumably) was satisfied with writing a sort of RP2C02 emulator facade instead of doing the hard work of translating the bytes into platform-agnostic graphics rendering code. So now any customization/extensions you write to the game are fundamentally constrained to the abstractions of a specific chip from the 80s.

raldi • yesterday at 9:07 PM

But the Japanese Contra was so much better! https://www.youtube.com/shorts/CiXzONyCDW0

davesque • today at 2:43 AM

Unfortunately, I'm a bit concerned that cool labor of love hacker projects like this will become much less common now that Anthropic (and possibly soon others) is moving to restrict this kind of usage. Oh well, so much for cool fun stuff.

➕ show 6 replies
shinryudbz • yesterday at 10:01 PM

Is the audio not supposed to work? I was hoping to hear the legendary tracks!

msephton • yesterday at 11:57 PM

A couple months ago I wrote about this kind of transcompilation hop-skip-jump: https://news.ycombinator.com/item?id=49643284

I used it to get games written in Lua running on SNES and in my own language/engine running on Dreamcast, Wii, Web and more.

gwbas1c • yesterday at 8:19 PM

One of the things that I'm curious about: How easy / hard is it to use the same NES game with higher resolution / color graphics, and sample-based sound?

Are there any emulators out there that let you swap in higher resolution assets so a game can be freshened without a complete port?

➕ show 5 replies
sfblah • today at 2:54 AM

No sound and the a and b buttons should be the other direction (a is to the right of b) on the keyboard.

egonschiele • yesterday at 10:20 PM

Contra is my favorite game of all time so this is a real treat, and the co-op idea is fantastic. Not to be greedy, but how hard would it be to add music? :)

BSPtree • yesterday at 7:49 PM

Cool, how did you build the multiplayer mode? And how much AI was used?

➕ show 4 replies
pmarreck • today at 1:16 AM

Where's the sound? You can likely ask AI to emulate the sound hardware with WASM!

Dwedit • yesterday at 9:50 PM

All that work and then somehow transposing the A and B keys at the very end.

erictheguy • today at 1:32 AM

Nostalgic!! Took me a few tries to beat the first level haha

pxx • yesterday at 10:59 PM

No controller support?

gosen • yesterday at 10:04 PM

thanks for bringing back my childhood memories!

einpoklum • yesterday at 8:32 PM

Most of the keys aren't working for me in Firefox though :-(

➕ show 1 reply
smjy_studio • today at 2:01 AM

[flagged]

jasonlotito • today at 12:02 AM

Whenever I see a game that uses the arrow keys and doesn't offer WASD as well, I can't help but see a game written by a non-gamer. I consider these fundamentals, and a shibboleth of whether I should care.

➕ show 2 replies