Hacker News new | past | comments | ask | show | jobs | submit

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

https://epoyraz.github.io/nes-contra-us/
loading story #50323935
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!

Bear in mind: the dissambly was done pre-LLMs. The early commits are from 2023. Although, ChatGPT 4 existed then, it was not capable of doing these things.

Impressive work, indeed. vermiceli the GOAT.

loading story #50323940
loading story #50323579
But the Japanese Contra was so much better! https://www.youtube.com/shorts/CiXzONyCDW0
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.
loading story #50322921
loading story #50322909
loading story #50322641
loading story #50322359
loading story #50322609
Is the audio not supposed to work? I was hoping to hear the legendary tracks!
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.

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?

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

whoa, that's cool. I didn't know about this. Thanks for sharing!
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...
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!
loading story #50320012
loading story #50321278
loading story #50320067
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.

loading story #50321834
No sound and the a and b buttons should be the other direction (a is to the right of b) on the keyboard.
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? :)
Cool, how did you build the multiplayer mode? And how much AI was used?
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.
loading story #50321445
loading story #50321525
{"deleted":true,"id":50319668,"parent":50319440,"time":1793477548,"type":"comment"}
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.

Where's the sound? You can likely ask AI to emulate the sound hardware with WASM!
All that work and then somehow transposing the A and B keys at the very end.
Nostalgic!! Took me a few tries to beat the first level haha
No controller support?
thanks for bringing back my childhood memories!
Most of the keys aren't working for me in Firefox though :-(
i only testing in chrome. Will look into it!
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.
loading story #50322383
loading story #50321503