Top
Best
New

Posted by tevlon 4 hours ago

Show HN: NES Contra (1987) port (ASM –> C and then C –> WebAssembly)(epoyraz.github.io)
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

33 points | 20 comments
raldi 2 hours ago|
But the Japanese Contra was so much better! https://www.youtube.com/shorts/CiXzONyCDW0
shinryudbz 1 hour ago||
Is the audio not supposed to work? I was hoping to hear the legendary tracks!
gwbas1c 3 hours ago||
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?

vunderba 2 hours ago||
You might like 3dSen, which came out several years ago. It does some pretty crazy stuff, converting NES games into essentially 3D voxel environments.

https://store.steampowered.com/app/1147940/3dSen_PC

tevlon 2 hours ago||
whoa, that's cool. I didn't know about this. Thanks for sharing!
BSPtree 3 hours ago|||
I would not think so, at least not in a meaningful way. That would require to edit the cartridge data thus the ROM, as all sprite data was contained within the cartridge. Sample based sound is impossible natively, as NES and older game consoles don't work with digital data but synthesizers. You could perhaps synthesize the music to WAV files and then enchance it. But then again, NES and thus its emulators have no way of playing digitized audio!
kevin_thibedeau 23 minutes ago|||
> Sample based sound is impossible natively, as NES and older game consoles don't work with digital data

The NES supports PCM audio. It was notably implemented wrong in the title screen of Double Dribble and fixed with a patch that produces clearer audio after bit reversal into the correct encoding for the hardware:

https://www.youtube.com/watch?v=Jli0RGpuZDg

cowlevel 3 hours ago||||
The NES in particular is probably not too difficult to upscale, because the graphics data is stored on its own ROM chip (sometimes RAM) in a well structured layout. SMB1 just uses a ROM chip containing many tile graphics which the CPU code addresses by tile index. It would be really easy for an emulator to use the same tile indices to address any arbitrary set of tiles loaded from a PNG. Some games use RAM, which makes it harder as you'd have to index the PNG by hash or something.
pantelisk 3 hours ago|||
Compute motion vectors, faux depth, and add DLLS5 to it maybe? Could be pretty cool, or pretty horrific. Only one way to find out :)
unleaded 3 hours ago|||
Mesen has texture packs. Don't know about sound, you'd have to reverse each game's sound driver first. https://vgmpf.com/Wiki/index.php?title=Famicom/NES_Sound_Dri...
kekebo 3 hours ago||
Idk about swapping assets but zsnes used to have a range of video filters that could improve the experience on a modern screen quite a bit.

Edit: For SNES, not NES, my bad.

egonschiele 1 hour ago||
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? :)
Dwedit 2 hours ago||
All that work and then somehow transposing the A and B keys at the very end.
pxx 56 minutes ago||
No controller support?
BSPtree 4 hours ago||
Cool, how did you build the multiplayer mode? And how much AI was used?
esikich 1 hour ago||
100% AI I'm sure. I played around with this kind of thing a month or so ago and Codex had no problems mashing games up from just the ROMs. In about 30 minutes I had the contra guys running through SMB 1 shooting enemies.
tevlon 2 hours ago||
For the Multiplayer part: It's deterministic lockstep. Both browsers run the same C core (compiled to WebAssembly), and the only thing sent over the network is each player's button bitmask per frame. Local input is delayed by 4 frames (~67 ms), which hides normal internet latency; if the other player's input for a frame hasn't arrived yet, the game waits for it. Every 2 seconds both sides compare a hash of the game RAM to catch desyncs. Transport is a WebRTC data channel via PeerJS (its free cloud server handles matchmaking with a room code), with Google's STUN server for NAT traversal and Metered's free-tier TURN relay as a fallback when a direct connection isn't possible.

For AI usage: It was all done by Claude/Codex, but it wasn't that straight forward. First: i started in April and the models weren't good enough and would make errors. You could see those immediately in glitches. 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. The rest was smooth.

gosen 1 hour ago||
thanks for bringing back my childhood memories!
einpoklum 3 hours ago|
Most of the keys aren't working for me in Firefox though :-(
tevlon 3 hours ago|
i only testing in chrome. Will look into it!