8 ms·
A 6502 emulator in Common Lisp [pdf]
- rasur 13y agoThis is really quite enjoyable to read (although I've yet to finish it). Thanks for posting it.
- mark_l_watson 13y agoThat is nicely written! Even though I had the serial number 71 Apple II, and dipped into 6502 assembler way back, I am not much interested at all in the 6502 any more, but the author's literate programming/writing style is very nice - good read for those of us who still are into Common Lisp.
- swah 13y agoThis is interesting because its exactly the kind of code that I thought would be easier in C than Lisp, due to easy bit manipulation, memory access, etc.
- redline6561 13y agoMe too! Common Lisp actually was intended for system programming historically, back from when Lisp Machines had a shot at ruling the world. Consequently, there is quite nice support for low-level programming.
- pjmlp 13y agoIn the early 80's, when C was yet to become widely used, there were quite a few languages that offered support for doing systems programming. Lisp was one of them.
- e3pi 13y agoTo me, this post is in the finest spirit of HN's reason for being. It is delightful to to see the endless colliding of important primitive and historic objects written well and become accessible to many. My mind reels with all these fantastic permutations of what is possible and made accessible, and I must constantly refresh and resort the "I want to know this one too" queue.
- redline6561 13y agoI'm flattered. :)
- hsmyers 13y agoAs a long time fellow traveler in the land of Literate Programming, I must ask how you created the document---by hand or with tools and if tools, which ones?
- redline6561 13y agoThat magic actually comes courtesy of [SnabbSwitch](https://github.com/SnabbCo/snabbswitch/wiki https://github.com/SnabbCo/snabbswitch/wiki), latest project of the inimitable Luke Gorrie. Luke is also publishing SnabbSwitch semi-regularly as a [readable program](http://blog.lukego.com/blog/2012/10/24/readable-programs/ http://blog.lukego.com/blog/2012/10/24/readable-programs/). Basically, you write markdown comments in the code and there is a Makefile that uses awk and sed to grab them out, cat some things together and pass it to an awesome LaTeX stylesheet written by Pete Kazmier. See: https://github.com/redline6561/cl-6502/tree/master/src/doc https://github.com/redline6561/cl-6502/tree/master/src/doc and the Makefile in the parent directory.
- ghostDancer 13y agoThe github repo : https://github.com/redline6561/cl-6502 https://github.com/redline6561/cl-6502
- mjn 13y agoLooks like there's a work-in-progress NES emulator based on cl-6502 in there as well: https://github.com/redline6561/famiclom https://github.com/redline6561/famiclom
- redline6561 13y agoI've been stalled out on that for a month or two. The PPU has been quite tricky. I'll probably take inspiration from [nesemu1](http://bisqwit.iki.fi/jutut/kuvat/programming_examples/nesemu1/ http://bisqwit.iki.fi/jutut/kuvat/programming_examples/nesem...) for the next rewrite. Related (with screenshot!): http://blog.redlinernotes.com/posts/So-Close-and-Yet-So-Far.html http://blog.redlinernotes.com/posts/So-Close-and-Yet-So-Far.... If I can wind up with a NES emulator that is "fast enough" and 2500 lines of code instead of 75,000 (Fceux) or 150,000 (Nestopia) then I'll be happy.
- dschiptsov 13y ago"All programs have been written, and that program is Lisp. With perfection already attained, implementation is left to the ignorant who do not already know the truth of this." and, of course, "Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp". Robert Morris's addendum: "Including Common Lisp." ... except if you use a well-written Lisp interpreter library :) - Scheme
- lesslaw 13y agoYou spelled Forth wrong :>
- marcosscriven 13y agoThe is very interesting indeed. Whenever I see old ICs like the 6502 I have this fantasy of going back 30 years and making my own computer from scratch.
- pcwalton 13y agoShameless plug: My Rust 6502 emulator used macros for opcode decoding as well. CPU emulation is an ideal use case for Lispy macros: the addressing mode and opcode combinations have a lot of closely related code that's amenable to macro factoring, and having the interpreter, JIT (if present), and disassembler share code is a nice application as well.
- redline6561 13y agoHi, Patrick! Sprocketnes has been helpful reading as I've worked on my own emulator. Ian Piumarta's lib6502 uses plain C macros. It's even almost as short as cl-6502...though I don't think it's quite as readable. ;) Keep up the great work on Rust, been waiting on the gc/scheduler stuff to shake out a little bit. Looking forward to 0.8!
- jevinskie 13y agoLLVM invented the tablegen language to do this in C++.
- peterbotond 13y agoMy old vic-20 had a 6502, and c-64 had a 6510. 6510 was backwards compatible with 6502. the most obvious diffrence was the 6510 had more instructions. has any of you had a c-64 with a 6502?