Computing Pi on the NES

201,087
0
Published 2023-03-03
An NES game that computes the digits of pi.

Become a Patron - patreon.com/NesHacker
Buy my t-shirt (Amazon Affiliate Link) - amzn.to/3ksOPmR
Get the ROM - github.com/NesHacker/NesPi/raw/main/nes-pi.nes
See the Code - github.com/NesHacker/NesPi

Pi-Spigot Algorithm Paper (Rabinowitz & Wagon, 1995):
www.maa.org/sites/default/files/pdf/pubs/amm_suppl…

Music:

“Raintown (My Love For You) - Instrumental Version” by Alchemorph
“Maldito” by Family Kush
“Boiling Point - Instrumental Version” by Evgeny Bardyuzha
“Night Chase” by Raz Burg

Chapters:

0:00 Introduction
2:20 Choosing a Mapper
3:16 Math Routines
5:22 The Spigot Algorithm
7:18 Coding the Game

All Comments (21)
  • I remember when I realized that game console were just special-built computers and not just "magic game machines" - so cool
  • @nict2
    This video is going to blow up on Pi Day. 🥧
  • @vdubs4189
    I would love to learn more about NMIs and graphics programming.
  • @Josh2102
    NES translations 1:03 「あのー、フロップは何ですか?」= umm, what’s a flop? 5:00 「そうです」= that’s right
  • @JoshJones720
    Great video. The use of visuals on this channel to explain assembly and binary operations are very helpful.
  • @Mentalbox52
    It's not entirely true that the nes lacks multiplication and division, but that it's limited. There are 4 bitwise opcodes, ROL, ROR, ASL, and LSR which you can use to shift the bits left and right which can be used to multiply and divide bytes by 2.
  • @LukeAvedon
    Super cool! Loved, "do you even flop bro"
  • @BlocPanda
    I love the fact that the NES is asking "What is 'Flop'?". Just a nice touch. Also, 1:00
  • @cerulity32k
    I love how starkly different the 6502 is from modern x86_64. It really shows how far we've come, going from no hardware multiplication to something like VFNMSUB132PD (Fused Negative Multiply-Subtract of Packed Double Precision Floating-Point Values). I don't even know if that instruction has ever been used for any meaningful purposes, but it's there.
  • I'm Brazilian and I study computer engineering, your videos inspired me a lot and I'm more and more interested in programming with the 6502. I would love to learn more about NMIs and I'm already following your playlist on basic assembly!
  • @Jennn
    This video deserves 1000x the views it currently has. Thank you sir. This was Great!
  • @Zygorg
    Man, never thought ill watch a 9min vid about PI in the NES, but how you explain it and how you put it graphically makes it very engaging. Thanks for this video even though i dont have any idea of it!
  • I sold my stack of Megaman NES carts around 8 years ago... You just hit me so hard in the feels with your stack.
  • @Bofner
    I've been living in Japan and learning assembly for the past 8 months now, but I was very surprised to see your NES speak in Japanese xD
  • @v1x4z
    A complex, daunting process explained in a very understandable and concise manner. The visuals are very smooth and helpful and your speech has a nice, relaxing cadence. Exceptional video, can't wait for more.
  • @jumanji4037
    This was a really great video, very well explained. I’d love it if you could go into more depth on handling interrupts, I had no clue you could save the address of a register on an interior call. Could also do a brief tutorial on NES audio programming, it’s one of the more difficult concepts I’m trying to grasp.
  • Wow, I was once assigned to do this using the 8086 assembly and didn't even try, was too hard back then but definitely knowing that algorithm would have changed a lot
  • @TauGeneration
    ah yes , my videogame from my childhood. Pi for the NES. i especially loved it's requel/remake "Super Pi" fore SNES
  • I have a video request: a video covering the ins and outs of scrolling on the NES. From what I understand, you need to go through all sorts of hoops to be able to get scrolling in all directions. I've studied enough of the hardware to understand it can do general scrolling in one direction, but beyond that is a mystery to me. What makes bi-directional scrolling so hard, how is it accomplished, and what are the limitations to it depending on the mapper you're using? NESMaker is a good example of how this frustrated me a lot in the past. They released this tool allowing you to build your own NES games without needing programming, but anytime they were asked why can't they provide four-way scrolling, they pretty much just said it's not possible and those of us not in the know were left just wonder "But why?" I'd LOVE to see you cover this, and Vdubs also suggested teaching more about "NMIs and graphics programming." I think a video on scrolling and all the hurdles would be a great start.