6 ms·
> When I started pokegb, I spent most of the first few days implementing the CPU. Every time I hit an instruction that wasn't implemented, I'd implement it and
by andrewmcwatters 5y ago
> When I started pokegb, I spent most of the first few days implementing the CPU. Every time I hit an instruction that wasn't implemented, I'd implement it and see if it would run any further.
If you've ever written a drop-in replacement for some existing piece of software and filled the implementation with a bunch of `notimplemented()` (example)[1], you know exactly how satisfying this is. I love it.
[1]: https://github.com/Planimeter/lgf/blob/master/lua/framework/love.lua#L38 https://github.com/Planimeter/lgf/blob/master/lua/framework/...
- binji 5y agoIt really is one of the best things about emulation development. It's surprising how quickly you go from "nothing works" to "I'm playing Super Mario Bros!"
- missblit 5y agoI never did get very far with my NES emulator after getting an actual job (it was plan B for if no one liked my resume), but I do remember that being oddly satisfying [1] [1] https://github.com/missblit/nesnes/blob/master/instructions_impl.h#L4 https://github.com/missblit/nesnes/blob/master/instructions_...
- city41 5y agoIt's one of my favorite things about programming. For example I made a Neo Geo tile viewer and decoding the format and figuring out just what needs to be done to get it working then suddenly BAM! tiles tiles everywhere! It's so satisfying.
- makapuf 5y agoI made a game console on an embedded system. The magic when you actually bitbang pixels to a screen and you see that first image is breathtaking.
- tiddles 5y agoThis x1000. I started implementing a JVM for shits and giggles a while ago, and once I had laid out ~220 panics for each opcode, it was incredibly satisfying to implement them one at a time to work towards bootstrapping the standard library. Granted, most opcodes are implemented incorrectly as minor things like method and field resolution aren’t quite there yet.. as soon as I’ve implemented enough opcodes to actually run something and return/exit/throw, the correctness will be a bugger to fix :^)
- binji 5y agoJVM is a great choice! You might also want to check out WebAssembly too (full disclosure: I used to work on wasm). There aren't too many opcodes, and a lot of them are relatively simple math operations. Once you get it working, you could run things like JSLinux! https://bellard.org/jslinux/vm.html?url=win2k.cfg&mem=192&graphic=1&w=1024&h=768 https://bellard.org/jslinux/vm.html?url=win2k.cfg&mem=192&gr...
- tiddles 5y agoThat’s a great idea, I’m not that familiar with wasm and the best way to learn is of course to implement a VM :) Cheers for the link to the meeting notes in the other comment chain, sounds like a great rabbit hole
- kfrane 5y agoYou're right about wasm not being too complicated, I've learned this when watching David Beazley coding a WebAssembly interpreter in under an hour. And it doesn't require any knowledge about it beforehand. https://www.youtube.com/watch?v=r-A78RgMhZU https://www.youtube.com/watch?v=r-A78RgMhZU
- javajosh 5y agoGiven your experience at this level of abstraction, do you have any thoughts on what an ideal set of opcodes look like? E.g. something like Knuth's MMIX. Do you prefer RISC or CISC? What about RISC-V? How much do the designers of real-world micro-architectures talk to folks like you? A bit of a tangent, I know, but it feels important.
- hota_mazi 5y agoExactly this. I wrote an Apple ][ emulator, so I started by writing a 6502 emulator, and this is the only approach. Start with a giant switch, implement a few opcodes, run a program, wait until it reaches the not implemented case, implement it, repeat. It is a surprisingly satisfying activity.
- toast0 5y agoOn topic, I had tremendous fun writing the CPU emulation for my maybe 1/3rd done NES emulator (that I likely won't finish, but who knows). Off topic, I wouldn't do a 6502 as a giant switch, you'll likely miss out on a lot of the shared logic. If you decode the instructions differently, you can easily reuse logic for addressing modes and what not. I really like how the opcodes are laid out in the table on this wiki http://wiki.nesdev.com/w/index.php/CPU_unofficial_opcodes http://wiki.nesdev.com/w/index.php/CPU_unofficial_opcodes
- hota_mazi 5y agoMy giant switch leverages the bit patterns :) My emulator passes the Klaus2m functional suite and my Apple ][ emulator is able to run quite a few protected games.
- seligman99 5y agoI've done things along these lines for things like the Advent of Code "int-code" assembly language implementations. It's satisfying to go from crashing because an opcode isn't implemented to something that produces output.