Graphics are based on tiles that are 8x8 or 8x16 pixels in size. Unlike the CPU, the PPU used in the NES was purpose-built specifically for the NES, and runs at a different clock rate than the CPU does. The PPU, or Picture Processing Unit, with the official designation 2C02, is the component that’s responsible for rendering graphics to the screen, and oh boy, was this an experience that all NES emulator developers treasure, in a manner of speaking. The result of this can be and‘d with 0x80 to test the most-significant bit:įn sbc ( & mut self, val : u8 ) The exclusive-or bitwise operator is a neat little tool to check if the sign of two numbers is the same (whether it’s 1 or 0 is irrelevant). In binary, the sign of a number is determined by the most-significant bit a 1 signifying a negative number, and a 0 signifying a positive. If this happens, the overflow flag must be set. It’s impossible for a negative 8-bit number and a positive 8-bit number to overflow when added together, so the only cases to worry about are when adding two negative numbers together results in a positive number, or when adding two positive numbers together results in a negative number. The point of the overflow flag is to, in the world of signed 8-bit integers (with a range of -128 to 127), figure out if adding the two numbers together has overflowed or underflowed. Most of the flags are simple to determine the value of, but the overflow flag is slightly problematic. The ADC instruction adds a number to the accumulator register, and if the carry flag is currently set, an additional 1 is added.Įxecuting this instruction will update some of the CPU flags, specifically the sign flag, the zero flag, the overflow flag, and carry flag. The most interesting instructions in the 6502 are the ADC (add with carry) and SBC (subtract with carry) instructions, and the funny little relationship between them. The 6502 was a lot of fun to implement, to the point that I would recommend writing a 6502 emulator on its own as a fun project, if a full gaming emulator seemed too big of a project for the amount of time someone may have available. This isn’t anything new for anyone who has ever had to debug something in gdb, or has written any assembly for any other architecture before. It has a 16-bit address space, three registers, a stack pointer, a program counter, and a bunch of status flags. I had zero experience with the 6502 beyond reading about the early days of Apple and Steve Wozniak’s stories from the Homebrew Computer Club, but it has a fun history in retro gaming and computing, also being used in the Atari 2600, and the Commodore 64, among many other iconic systems. The NES used a MOS Technology 6502 for its CPU, with the official designation of 2A03 for the NTSC version, and emulating the CPU was where I - and most emulator developers - decided to start. It’s been a fun experience to travel back in time and appreciate the history and architecture of old systems, so I wanted to highlight some of my favorite parts of emulating the NES. One of the original reasons I wanted to write an emulator was because it was something I had been exposed to through various IRC communities that I’ve been apart of since I was a teenager in the late 90s and early 2000s, and it was also of interest to me because of my own life-long love for retro gaming dating as far back as getting the original Game Boy for Christmas (which I then complained about, because the box that it came in was smaller than the box my brother’s Christmas present came in). It was the first emulator I’ve written, and it was the first non-trivial project for which I used the Rust programming language. Very slowly over a period of around a year, I wrote a NES emulator. NES Emulation: The Good, The Bad, and The Tedious 22 November 2019
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |