I spent my childhood `"In the year 20xx ..."` --- ## About Me (2007-2011) 15 years later, not the most disciplined young man but in need of a career. -- I got into programming because I wanted to know how computers *work*. -- I self studied SICP. I wrote a lot of lisp. I got my CS degree and a job. --
But on some level, the NES was still **magic**. --
It's only fair I warn you this is a [pet][trp] [issue][tcc] of mine. That software today is remarkably complex and powerful but we're so used to the complexity we hardly strive for understandable software anymore. -- And the low-level foundations beneath our frameworks and libraries are **fuzzy mysteries mostly forgotten**. [trp]: http://redlinernotes.com/docs/talks/trp.html [tcc]: http://blog.redlinernotes.com/posts/Towards-Comprehensible-Computing.html -- *(This probably has something to do with why I'm enamored by Smalltalk and Common Lisp. They date from a time when programming environments had different goals.)* --- ## Well... --
> You think you know when you can learn, are more sure when you can write, even more when you can teach, but certain when you can program. - Alan Perlis --
> Thus, programs must be written for people to read, and only incidentally for machines to execute. - SICP, Preface --- ## The Goal Computers can simulate anything we can describe with sufficient precision. -- Including another computer! -- To better understand how computers work, I set out to simulate a Nintendo specifically to play Mega Man 2. --
(Unstated Thesis: Clearly one of the greatest games ever made.) --
The rest of this talk will walk through the myriad difficulties encountered and lessons learned as I worked on it. I'll try not to get too lost in the weeds. **Please ask questions when you are curious or confused!** --- ## Previously ![famiclom](http://redlinernotes.com/docs/talks/trp/famiclom.png) A wonderful effort to write a [readable emulator][readable] in Common Lisp. [readable]: http://redlinernotes.com/docs/cl-6502.pdf -- Stalled out from a mixture of boredom and life changes. -- But I also made some crucial false assumptions, the death of many programs! -- > The management question, therefore, is not whether to build a pilot system and throw it away. You will do that. […] Hence plan to throw one away; you will, anyhow. - Fred Brooks, The Mythical Man Month --- ## Recently
[Nescavation][nescavation], a more widely deployed (i.e. browser-based) effort. [nescavation]: https://github.com/kingcons/nescavation -- Because life settled down, I'm still curious, and can make better assumptions! --- ## Overview To simulate the Nintendo, we have to simulate its parts. * CPU * Memory * Video Card * Sound Card * Controllers * Cartridges -- I started with the CPU since the CPU is the "brain" and seemed more straightforward than graphics or sound. (Neither of which I knew anything about.) -- Enter the [MOS 6502][mos-6502] and [cl-6502][cl-6502]. [mos-6502]: https://en.wikipedia.org/wiki/MOS_Technology_6502 [cl-6502]: https://github.com/kingcons/cl-6502 --- ## Stage 0 - The CPU in Isolation Conceptually, 8-bit CPUs are pretty straightforward.