Slashdot Mirror


Hacking the NES With Lisp

Andy Hefner has a detailed blog post covering his quest to program an NES with the assistance of Common Lisp. He developed a new 6502 assembler, a mini-language for composing musical sequences, and a neat demo (rom image).

80 comments

  1. a strange mix of nausea and admiration by decora · · Score: 5, Funny

    on the one hand, this guy has re-implemented assembler with lisp syntax.

    on the other hand, this guy has re-implemented assembler with lisp syntax.

    1. Re:a strange mix of nausea and admiration by Dwedit · · Score: 4, Informative

      Yeah, when you're writing Assembly, it's still assembly. Using lisp to make macros doesn't change the langauge.

    2. Re:a strange mix of nausea and admiration by Hentes · · Score: 3, Interesting

      Well he wasn't the first one to do it, Common Lisp already has a disassemble command.

    3. Re:a strange mix of nausea and admiration by MightyMartian · · Score: 4, Funny

      Great. Now I can run Super Mario Bros. in Emacs!

      --
      The world's burning. Moped Jesus spotted on I50. Details at 11.
    4. Re:a strange mix of nausea and admiration by Anonymous Coward · · Score: 5, Funny

      This reminds me of the old quote "Emacs is a wonderful operating system. All it's missing is a decent text editor."

    5. Re:a strange mix of nausea and admiration by Anonymous Coward · · Score: 5, Funny

      on the one hand, this guy has re-implemented assembler with lisp syntax.

      on the other hand, this guy has re-implemented assembler with lisp syntax.

      and on the gripping hand, it's the world's first assembler that requires you to start lines with seven parentheses and rewrites itself at runtime.

    6. Re:a strange mix of nausea and admiration by drfreak · · Score: 0, Redundant

      Normally I wouldn't reply to an AC, but being a vi fan I have to give props. Although, you know, all the best operating systems aren't emacs, they are created *in* emacs.

    7. Re:a strange mix of nausea and admiration by hoggoth · · Score: 1

      Heh +1 Motie!

      --
      - For the complete works of Shakespeare: cat /dev/random (may take some time)
    8. Re:a strange mix of nausea and admiration by Anonymous Coward · · Score: 0

      6502? Just like my old Commodore VIC-20? Common Lisp (When I took Artificial Intelligence in University I pronounced it Lithp)? Lisp is an old beast of a language that kicks the stuffing out of Fortran (and is about as old), and is still a viable A.I. language (used in game logic, simulations, etc.). I'm half impressed, half nauseous.

    9. Re:a strange mix of nausea and admiration by Darinbob · · Score: 4, Informative

      The earliest lisps had assembler. It was sort of normal in a way because assembler was your language of choice for this sort of thing. C didn't exist yet, Fortran was just wrong, the other procedural languages were bulky, etc. Machines were low on memory and you often wanted to machine specific actions, you were writing your own runtime library as you went. So even as far back as Lisp 1.5 documentation discusses how to use assembler.

      The earliest lisps had compilers as well which went well with assembler written functions. Your programming environment was often a stack of cards that were loaded into a machine, or a tape that was read. So stopping to edit/compile/link/load was often impractical compared to just dumping some assembler while still in the interpreter (though of course if you crashed the machine you had to hide until pitchfork wielding mob stopped looking for you).

      The thing people remember most about Lisp other than parentheses are CAR and CDR functions. These are named for specific fields in a PDP 36-bit word which were accessible via machine instructions.

    10. Re:a strange mix of nausea and admiration by Darinbob · · Score: 1

      Have a look at the original Emacs that was a set of macros written in TECO. That's scary stuff.

    11. Re:a strange mix of nausea and admiration by ratboy666 · · Score: 5, Interesting

      Read the fine article. Using CL does substantially change the language. Specifically, note the higher order manipulation of the eventual low-level program that the author achieved using promises (delayed evaluations). Basically, "threading while assembling".

      Also, notice the ease of introducing higher-level flow control constructs (IF and UNTIL) into assembler. And the elimination of a second assembler pass by use of promises for forward references. It's kind of "magic" -- the correct data will be there when it's needed!

      In this use-case, CL is a notational system for NES programming. It probably shouldn't be called "assembler" anymore, as the power of CL can be brought to bear in the process of generating the desired machine code.

      --
      Just another "Cubible(sic) Joe" 2 17 3061
    12. Re:a strange mix of nausea and admiration by lister+king+of+smeg · · Score: 1

      No Emacs OS can emulate vi thus it does have a desent text editor

      --
      ---Saying gnome 3 is better than windows 8 not so much a compliment as it is damning with light praise.
    13. Re:a strange mix of nausea and admiration by obsess5 · · Score: 1

      Fortran is just as old as Lisp and still a viable programming language. It is widely used in scientific computing and high-performance computing. I like both languages; good on both of them. Neither language is as simple now as they were in the early days.

    14. Re:a strange mix of nausea and admiration by pz · · Score: 1

      The thing people remember most about Lisp other than parentheses are CAR and CDR functions. These are named for specific fields in a PDP 36-bit word which were accessible via machine instructions.

      Contents of Address Register
      Contents of Data Register

      --

      Put my fist through my alarm clock with its ding-dong death inside my ear. - The Blackjacks.
    15. Re:a strange mix of nausea and admiration by Darinbob · · Score: 2

      Close but not exact. I got it wrong too, it wasn't a PDP but an IBM.

      These both were fields from the same register ( bit words and the computer allowed either 15 or 16 bit word addresses). So according to Wikipedia the definitions were:
      "Contents of the Address part of Register number"
      "Contents of the Data part of Register number"
      And a couple other tiny fields that initially were in Lisp but were later dropped.

      Yea, it's kind of weird. The PDPs used at MIT later were 36 bit and also allowed sticking two word addresses into a single word (byte addresses required a full word). So it was very handy for doing CAR/CDR in a single word there.

    16. Re:a strange mix of nausea and admiration by Darinbob · · Score: 1

      Whoops messed up again. It's "Contents of Decrement part of Register number"...

    17. Re:a strange mix of nausea and admiration by Anonymous Coward · · Score: 0

      How's the spellchecker in vi?

    18. Re:a strange mix of nausea and admiration by Randle_Revar · · Score: 1

      Doesn't have one. Vim has a good one, however (Emacs can also imitate Vim)

  2. That's hot by Anonymous Coward · · Score: 3, Interesting

    I think that is the coolest thing I have seen in a while. Nothing like the king of all high level languages generating low level machine code.

    1. Re:That's hot by MightyMartian · · Score: 1

      And somehow one of them ended up on /.

      --
      The world's burning. Moped Jesus spotted on I50. Details at 11.
    2. Re:That's hot by Anonymous Coward · · Score: 0

      And made the front page as a hacking article, too!

    3. Re:That's hot by Anonymous Coward · · Score: 0

      Odd coincidence: I wrote a 6502 assembler in Haskell just before Christmas. And Haskell is the king of all high level languages.

    4. Re:That's hot by TemporalBeing · · Score: 1

      I think that is the coolest thing I have seen in a while. Nothing like the king of all high level languages generating low level machine code.

      They didn't write it in SmallTalk which would certainly be the king of all high level languages, not lisp.

      Lisps only quality is its known use of braces - which is also its greatest fault. A queen among queens.

      --
      Truth is like the sun. You can shut it out for a time, but it ain't goin' away. - Elvis Presley (source: imdb.com)
  3. Obligatory by Hsien-Ko · · Score: 1

    But can it run Crysis?

    1. Re:Obligatory by Anonymous Coward · · Score: 0

      I'm pretty sure that it could, given that it has a general-purpose processor and memory. A virtual machine could be written and it run from a simulated environment. Not sure that it would look nice, given the 16 color limit, and the framerate would suck, but it might be fun.

    2. Re:Obligatory by tepples · · Score: 1

      a general-purpose processor and memory

      All you "Turing complete" weenies seem to forget that a Turing machine has infinite memory, unlike the 4096 bytes of RAM in the NES. Sure, you can put hundreds of megabytes of RAM on a cartridge, but at that point you could put a smartphone chipset on a cartridge and have it fill a frame buffer as if it were the successor to Wide Boy/Super Game Boy.

    3. Re:Obligatory by Hsien-Ko · · Score: 1

      What about an OnLive kind of thing? As in, streaming raw data prepared for it through a cable from another machine so we can get Crysis at glorious 256x240

  4. Re:Nostalgia is a powerful force... by ObsessiveMathsFreak · · Score: 2, Insightful

    Are you kidding?! There are probably more working NES consoles out there than N64 or Nokia N-gages.

    --
    May the Maths Be with you!
  5. Re:Nostalgia is a powerful force... by Anonymous Coward · · Score: 0

    He benefited -- he had fun doing it.
    And I benefited -- had fun reading about it. (Even I have no real nostalgia for the NES -- I played some when I was a kid, but was on more powerful hardware when I started hacking.)

  6. Re:Nostalgia is a powerful force... by Anonymous Coward · · Score: 0

    So maybe the next project is recreating the hardware.

  7. Re:Nostalgia is a powerful force... by CohibaVancouver · · Score: 2

    Exactly right. I can think of 10 different closets right now that have NESes inside.

  8. Re:Nostalgia is a powerful force... by Anonymous Coward · · Score: 5, Funny

    Those NES boxes are quite comfortable with their sexuality, thank you very much, and just value their privacy. If they want to stay in the closet, who are we to disagree?

  9. This is what Slashdot needs more of by comrade+k · · Score: 5, Interesting

    Bravo, Slashdot. This is the kind of stuff that the geek crowd finds interesting. Is it useful? Nope. Is it cool and borderline bizarre? Yep!

    --
    "Every vision is a joke until the first man accomplishes it; once realized, it becomes commonplace." -Robert H. Goddard
    1. Re:This is what Slashdot needs more of by wierd_w · · Score: 3, Interesting

      What I have always wondered about, is just how far can you push one of these old systems?

      Like the snes.. it was designed to accept a 3rd party cpu inside the cartridge, in addition to the game rom.

      What would happen if you built what would essentially be rom code toolbox routines to access the snes's hardware, and then switch execution to a more powerful/more modern low energy cpu, like an arm?

      You would use the snes as an input device (they did make a snes mouse.....), and as the graphics hardware, but run all the heavy lifting on the arm instead of the 6500 series cpu. Other than the rom routines to do the interface, everything else is handled by a shared ram bank and an sdcard slot put into the cartridge.

      Why? So you can run linux on the snes. Why? Because you could.

      I bet you could do some really clever stuff by simulating a framebuffer.

    2. Re:This is what Slashdot needs more of by DigiShaman · · Score: 3, Interesting

      Some of the best Z80 ROM music I've heard has to be M.U.S.H.A (Musha Aleste) on the Sega Genesis (Mega-Drive). Herzog Zwei comes in a close 2nd place. The composers were Gods, and they got paid to do what they loved to do. You've got to admire that kind of talent.

      --
      Life is not for the lazy.
    3. Re:This is what Slashdot needs more of by Anonymous Coward · · Score: 0

      One of the better stories on slashdot in the recent days if you ask me

    4. Re:This is what Slashdot needs more of by Hidyman · · Score: 1

      Technoforce 2 had some sweet music as well.
      Those bring back fond memories.

      --
      You can't take the sky from me ...
    5. Re:This is what Slashdot needs more of by Anonymous Coward · · Score: 0

      But is adding an external CPU really pushing the old system, or is it more like creating a new system that uses old display and sound hardware? I find it more impressive if you can push the old system, CPU and all, into doing new tricks.

    6. Re:This is what Slashdot needs more of by Anonymous Coward · · Score: 0

      I believe this is exactly how the Super FX chips in Doom and StarFox for Super NES worked.

      This is 8-bit NES though.

  10. Re:Nostalgia is a powerful force... by Pseudonym+Authority · · Score: 4, Funny

    I truly extend my condolences that your pet project didn't get featured on Slashdot and that it has made you bitter and jealous of the work of others.

  11. Re:Nostalgia is a powerful force... by Osgeld · · Score: 2

    wow there killer, way to think outside of the box, you installed software on your pc and let nintendo tell you what you could do! we need more people like you and less of these retards doing interesting things with obsolete machines.

  12. HTPCs don exits by tepples · · Score: 1

    This is why I've always preferred computers to consoles because the DRMtastic nature of the consoles quickly make them worthless.

    Except most people aren't willing to buy a PC and hook it up to a TV. The cases are too big, they don't come with a recliner-friendly remote, etc. For this reason (and greed), the Wii is still a lot more likely than the PC to get games capable of using multiple controllers.

  13. Super Game Boy by tepples · · Score: 1

    What would happen if you built what would essentially be rom code toolbox routines to access the snes's hardware, and then switch execution to a more powerful/more modern low energy cpu, like an arm?

    You'll have reimplemented Super Game Boy (for Super NES) or Game Boy Player (for Nintendo GameCube).

    1. Re:Super Game Boy by wierd_w · · Score: 1

      Didn't the gb have a z80 though? That's a bit less powerful than the 6500series cpu in the snes.

      Simply because the snes databus is 16bit doesn't mean the 3rd party cpu needs to be 16bit. The snes hardware could be treated like a 16bit peripheral, as far as the embedded SoC in the cart was concerned.

      I still think something more interesting than the superGB could be made this way.

    2. Re:Super Game Boy by Anonymous Coward · · Score: 0

      What would happen if you built what would essentially be rom code toolbox routines to access the snes's hardware, and then switch execution to a more powerful/more modern low energy cpu, like an arm?

      You'll have reimplemented Super Game Boy (for Super NES) or Game Boy Player (for Nintendo GameCube).

      Or the Supercharger for the Atari 2600.

      That's right, get off my lawn.

    3. Re:Super Game Boy by tepples · · Score: 1

      Didn't the gb have a z80 though?

      It was an 8080-derivative made by Sharp with some but not all features of the Zilog Z80, nicknamed "GBZ80" by emulator authors. Some Z80 features, such as the separate bank of BCDEHL registers for interrupt handlers, were left out in favor of special fast addressing modes for $FF00-$FFFF to mimic the 6502's "direct page" at $0000-$00FF.

      That's a bit less powerful than the 6500series cpu in the snes.

      The old Commodore 64 vs. ZX Spectrum flamewars ended up with a consensus that the 6502 is roughly as fast as a Z80 clocked two to three times as fast, depending on workload. This makes the CPU of the Nintendo Entertainment System (1.8 Mhz 6502) comparable to that of the Game Boy (4.1 MHz GBZ80) or the Sega Master System and Game Gear (3.6 MHz Z80). The 65816 in the Super NES ls clocked faster (let's say 3 MHz, because it runs at 3.6 MHz but slows down to 2.7 MHz when accessing RAM or slow cartridge ROM and freezes for a few cycles every scanline to let DRAM refresh itself).

      I still think something more interesting than the superGB could be made this way.

      There's still a limit of 4 bits per pixel unless you use an 8-bit video mode, and I don't think there's enough B-Bus bandwidth to send full-screen 8-bit 60 fps across the cart edge. But smart dithering techniques might still be able to squeeze out of 4bpp, especially when combined with the ability to select one of eight 15-color palettes for each 8x8 pixel area square. But by then, the Nintendo 64 had come out, and the version of the "Wide Boy" (SGB-like device for licensed developers and the gaming press) for the GBC and GBA ran on the N64.

  14. Re:Nostalgia is a powerful force... by EETech1 · · Score: 2

    Does that C&C lathe play CNC Music Factory

    Or is it a...
    Command and conquer lathe controller?

    I'm not vicious or malicious, just lovely and delicious. OSLT.

    Cheers!

  15. What I thought reading the title... by Anonymous Coward · · Score: 0

    thith ith awethome!

  16. 6502 assembler in Logo by leighklotz · · Score: 2

    I wrote a 6502 assembler in Logo in 1981 and we shipped it with the utilities disk.

    1. Re:6502 assembler in Logo by Anonymous Coward · · Score: 0

      Nobody cares, this is way cooler.

    2. Re:6502 assembler in Logo by Anonymous Coward · · Score: 0

      That is an awesomely insane thing to do! I didn't even know such a thing was possible in Logo. The utilities disk for what, if you don't mind me asking? Is there anywhere one can see this code, it just sounds ... wow.

  17. Actually I remember one other think about lisp by NotSoHeavyD3 · · Score: 1

    That it had the key word defun. I guess I've got to complement them on their honesty that one of the goals of the creators of lisp was to remove the fun from programming.(Because it certainly did for me.)

    --
    Did you know 80 to 90% of the moderators on slashdot wouldn't recognize a troll even if one dragged them under a bridge.
    1. Re:Actually I remember one other think about lisp by rmstar · · Score: 1

      I guess I've got to complement them on their honesty that one of the goals of the creators of lisp was to remove the fun from programming.(Because it certainly did for me.)

      Why is that? Must have been a bad teacher, because Lisp is really fun to program in. You need the help of an editor for the parentheses, but other than that its very easy and very powerful.

    2. Re:Actually I remember one other think about lisp by NotSoHeavyD3 · · Score: 1

      Oh this was back in the early 90's and we were using Emacs. Never heard anyone mention some sort of add on that would have helped with the parens. (I completely hate lisp because of that course btw.)

      --
      Did you know 80 to 90% of the moderators on slashdot wouldn't recognize a troll even if one dragged them under a bridge.
    3. Re:Actually I remember one other think about lisp by Anonymous Coward · · Score: 0

      Oh this was back in the early 90's and we were using Emacs. Never heard anyone mention some sort of add on that would have helped with the parens. (I completely hate lisp because of that course btw.)

      You should sue for a refund. Early 90's EMACS had plenty of support for coding in LISP (being coded in LISP and all that). You just had to choose the major mode you wanted to use--if you named the file correctly it "just happened."

  18. A better 6502 assembler by MichaelSmith · · Score: 1

    Just what I needed 35 years ago.

  19. Paul Graham will definitely... by curious.corn · · Score: 2

    send him a crate of beer ;)

    --
    Mi domando chi à il mandante di tutte le cazzate che faccio - Altan
  20. Looks like Henry G. Baker's COMFY 6502 compiler by dwheeler · · Score: 3, Interesting

    Fun! This 6502-assembler-in-LISP looks similar to Henry G. Baker's "COMFY" 6502 compiler (described in "The COMFY 6502 compiler", SIGPLAN Notices, 1997). You can check out the COMFY-6502 implementation that uses Common Lisp (sadly this appears to be entrapped in the ACM non-commercial-use-only license, though for 6502 code that isn't very limiting). One cool thing about the approach of using LISP as an "assembler" in general is that unlike many traditional macro assemblers, this approach can easily do stuff like choose the optimal instruction set for branches because it can determine if it's in range for a short branch and use them when available. You can do it other ways, of course, but it's pretty elegant in LISP. Those interested in this sort of thing might like my page on 6502 Language Implementation Approaches or my page on making LISP-based languages more readable (especially sweet-expressions).

    --
    - David A. Wheeler (see my Secure Programming HOWTO)
  21. it could be done... by Anonymous Coward · · Score: 0

    If you`re curious about the idea of mixing new hardware with old, look into Amiga CPU boards. Folks have taken an Amiga that shipped with a 14Mhz 68020 (or in some cases even a 7MHz 68000) and added a 200+MHz PPC as basically a co-processor. Of course when you do this, the original hardware becomes a bit of a bottleneck, so next thing you know you`ve also added a separate video card, sound card, and SCSI controller.

    But I think there have been at least a few demos that used an `060 or PPC CPU to render some fancy gfx and push it out the stock graphics hardware.

  22. thats b/c "this stuff" became illegal by decora · · Score: 4, Insightful

    if you tried to do what this guy is doing for NES with a Sony Playstation or IPhone you would sued and threatened with millions in legal bills. If you don't believe me, ask George Hotz.

    slashdot didn't move away from geeky stuff... certain corporate interests decided to attack the entire principle of DIY at its core. you can't expect slashdot to be silent about that.

    1. Re:thats b/c "this stuff" became illegal by Yvan256 · · Score: 1

      There's still SparkFun.com and Adafruit.com, I guess.

  23. This is real programming by Viol8 · · Score: 1

    I hope all the HTML-5 "coders" are taking note.

    1. Re:This is real programming by Yvan256 · · Score: 1

      Coding != Programming.

      HTML5 and CSS is coding.
      PHP* and Javascript* is programming.

      I don't care if you hate those, it's still programming. Now go cry in the corner.

  24. Re:Nostalgia is a powerful force... by windcask · · Score: 3, Insightful

    Art is about creative self-expression. If someone feels that writing an assembler for a 25 year-old console and making it 'go bloop' expresses himself in ways that modern technology cannot, what's the harm in that? It's neat. He obviously isn't trying to get rich or serve any other practical purpose with this.

  25. And for a 6502 disassembler... by ockegheim · · Score: 1

    Here is a interesting article about the design of the 6502, on archeology.org of all places.

    But you already knew it was archeology.org, didn’t you?

    --
    I’m old enough to remember 16K of memory being described as “whopping”
  26. Re:Nostalgia is a powerful force... by Anonymous Coward · · Score: 0

    Somebody better call a waaahbulance for this guy

  27. Wide Boy or Super FX by tepples · · Score: 1

    streaming raw data prepared for it through a cable from another machine

    That would be Wide Boy, the pre-production version of Super Game Boy. Or it would be Super FX, a second CPU on a Super NES cartridge that renders graphics. In discussions about "super-mappers" on NESdev BBS, I've often mentioned a TV tuner for NES connected to an Xbox 360 as the hypothetical "upper limit" of what a mapper can do.

  28. Re:Nostalgia is a powerful force... by Gordonjcp · · Score: 1

    So, what you're really saying is, "I'm unhappy with my life because I've never known what creativity feels like"?

  29. Re:Nostalgia is a powerful force... by Thud457 · · Score: 1

    nintendo frankly doesn't give a flying fuck what you do with a 25+ year old NES dumbass.

    Since doing something creative, if not actually constructive, takes your time away from playing and buying the latest Nintendo games, I'm sure they're actually against such anti-consumerist ventures.

    --

    the preceding comment is my own and in no way reflects the opinion of the Joint Chiefs of Staff

  30. Hacking with lithp? by Anonymous Coward · · Score: 0

    Thounds thtoopid to me.

  31. Re:Nostalgia is a powerful force... by Anonymous Coward · · Score: 0

    The GREATEST arcade video games EVER CREATED ran on EXTREMELY limited hardware when creativity and ingenuity ruled the day.

    For example, the PAC-MAN program Toru Iwatani et. al. created in 1979 for NAMCO was only 8 kilobytes and could fit on two sheets of paper. It was copied into 100,000 game cabinents, and made well over ONE BILLION DOLLARS worldwide!

    The graphics where laughably crude compared to today's games but it was FUN TO PLAY.

    When STREET FIGHTER II came out in 1991, it heraled the end of these colorful, fun games with crude graphics and replaced it with graphics, graphics, and MORE GRAPHICS!

    Before home game consoles got powerful enough to make video arcades essentially obsolete, all you could find in an arcade were fighting games, driving games, and shooting games, along with the cheesy ticket redemption games.

    This is why old school gamers got together and created arcade game emulaters such as MAME to relive the experience of playing these earlier games. The industry response was to crack down on the ROM sites that provided the games MAME needed to run (rightfully so on copyright grounds) then create GAMETAP which is essentially MAME across the internet.

    At least the industry has thrown a bone or two to the old school gamers by re-releasing early hit games in their arcade form or making a game pack of them bundled into a dedicated controller that can be plugged into the RCA jacks of your TV set.

  32. Anybody? by Anonymous Coward · · Score: 0

    Did anybody else read the headline and automatically think "N. E. Eth.?" Or was it just me?