Sunday, September 4, 2016

NESDEV - Assembly

I originally started this post a little more than 3 months ago.  Two things have happened since...
  • Not long after starting, I realized how sick I was of coding in Assembly (a result of my Computer Engineering Technology degree).  I had abandoned this project to simply focus on games, making small projects in Unity and Unreal.
  • A few days ago, I received approval to create a fully functioning NES cartridge as my Senior Project.  Hence, I am putting Unreal and Unity back on the shelf to put more focus back onto this project.
Hopefully, the result of the above events will result in a blog post AT LEAST once a week (as I will have to attend class to work on it anyway.  The ultimate goal now is to (hopefully) design an original game, and look into the equipment required to write it onto a cartridge, and write a paper reviewing my research and methodology.

--- Original Post Below ---

This post will be based upon Week 3 of the Nerdy Nights Tutorial, as well as diving further into the 6052 processor.  As I already have some familiarity with assembly programming, I may skip over some of the basics.  If I somehow manage to get people who want to know more, I'll update.

The 6052 Processor

The memory addresses of the 6052 processor are divided up as such:
  • $0000 - $0800 = Internal RAM
  • $2000 - $2007 = PPU Access Ports
  • $4000 - $4017 = Ausio and Controller Access Ports
  • $6000 - $7FFF = Optional WRAM (read from cart)
  • $8000 - $FFFF = ROM (read from cart)
The last set of addresses ($8000-$FFFF) will store the bulk of our code.

Like other microprocessors during this time, the 6052 has 3 key 8-bit registers that will no doubt be used frequently: Accumulator (A), and Index Registers X & Y. The accumulator is typically used to store data and perform basic math operations, while the two indexes are ofthen used to keep track of loops, counting, or accessing memory.  There is also a status register that hold information about the most previous instruction the CPU performed.

Assembly Code Structure

 This part of the post may require some research before I post any notes.  It appears for the purpose of emulation, we will be using an assembler known as NESASM3.  Below will be a few new concepts  that will be required in each programfor emulation.

 I have highlighted a few topics topics so that I may come back to them and add more info.
  • iNES Header
    • iNES is a NES emulator
    • This 16-byte header provides all the necessary information to the emulator concerning the specs of the game, including mapping, graphics mirroring, and PGR/CHR sizes.
    • This is not necessary for real hardware usage.
  • Banking
    • The 6502 processor breaks the 32kB limit of code into 8kB "banks".  I will need to revisit this in the future to understand the importance of using these banks.
  •  Vectors
    • a.k.s "Interrupts" - There are 3 occurrences when the NES will interrupt your program to jump to a specific point.  Those points are assigned the following tags:
      • NMI Vector: Occurs every frame, PPU is letting the processor know that it is open for graphic updates (enterng the "V Blank"[1] state).
      • RESET Vector:  Called everytime the reset button is hit or when the NES is powered on.
      • IRQ Vector:  Typically controlled by the mapper.  Need more info on this (not being included in Nerdy Nights tutorial). 
    • Each of these interrupts must appear in the PRG code, even if it is not being used.
I am considering scanning my notebook page where I printed off the Nerdy Nights "background.asm" example code and made annotations, as I feel it would be better seeing each of the above code snippets in context.  Maybe I will just make that a separate blog post.

The next Nerdy Nights lesson goes more in-depth on the PPU.  I will save the code overview notebook post until after I share those notes.

Cheers,
-JWest

[1] The "V Blank" state is the period when the PPU refreshed the screen.  I don't recall if I had already clarified that term before this post or not.

Wednesday, May 18, 2016

NESDev - Architecture Overview

As I mentioned in my last post, the majority of this process will simply involve following the "Nerdy Nights" tutorial.  Hopefully, my blog posts won't simply just sound like I'm just repeating everything I read there, but more like I'm reading, understanding, and connecting dots, adding my own research in an attempt to learn more of what I can do with this...

Anyway -


THE NINTENDO ENTERTAINMENT SYSTEM

For the most part, the system is built just like your standard every-day computer.   It features a central processor (CPU), a graphics processor (PPU - P.icture P.rocessing U.int), an audio processor (APU), RAM and ROM.  Granted, not all of these components are actually featured inside of the NES console itself.  The console contains the CPU, PPU, and APU, while each individual game cartridge holds the ROM and RAM.  Week 2 of Nerdy Nights features a few images that illustrate this architecture well.

A bit more detail...

  • The CPU of the NES is a "custom 6052" processor.  This processor was featured in many other home entertainment units, like the Apple II, Atari, and the Commodore P.E.T..  It is an 8-bit processor featuring a 16-bit address bus.  I will go further into the features of the board when we get into the assembly programming.
  • The PPU fetches all graphical data from the game cartridge, known as CHR (character memory), primarily containing sprites.  This graphical data will come in the form of tiles, sprites, pallettes, tables, and a background.
    • Tiles are 8x8 squares of pixels.  These tiles are tied together to make the background or a Sprite.
      • Background tiles are snapped to a grid and cannot move freely, while sprites are the opposite. 
      • I recall from Rob Santos's post-mortem that getting tiles to work cohesively as a sprite was a bit of a challenge, I guess we'll see what he means when we actually get to coding!
        A single sprite from The Legend of Zelda.  Link is made up of multiple sprites.
    • The Background is 32x30 tiles in size, and has the ability to scroll.  The graphical RAM can hold up to two screens of background, one of which is updated off screen.

      -- SKETCH OF THE "2-SCREEN" CONCEPT HERE --
    • A Pattern Table is where the tile data is stored on a cartridge.  There are 2 tables, each of which can hold 256 tiles.  One holds tiles for the background, one for sprites.
    • An Attribute Table is a 64 byte array that stores color palette information for the background.  The attribute table controls this information in 2x2 tile sections.
    • The Color Palette for the NES is rather limited; only 16 colors available.  Two are stored, one for the background, and another for sprites.



  • The NES color palette.

  •  The system also features a "Lockout Chip", a 4-bit processor called the 10NES, both within the console and on the cartridge.  This chip was used to authenticate (i.e. approved by Nintendo) any game being inserted into the console.  If the console ever got stuck in a "reboot loop", these chips were the cause.  If I am to port a game onto actual hardware, i may have to find a way around this...Of course, all of these concepts will be covered in much greater detail as this learning process continues.  Next post will go over the introduction to the assembly programming language that the 6052 processor will use.
    I reserve the right to come back and edit this post in case I made mistakes.  :|
    -JWest  

Friday, May 6, 2016

It's been a year...

Hello,

I opened up my blog for the first time in God knows how long, and finally mustered up the courage to look at the date of my last post.  It's been a little more than a year - April 4th, 2015.

I think about games nearly all the time.  Video games are still a big part of my life, and they have been since I was a child.  However, making games has been a slightly different story.  The last couple of weeks I've been kicking around the idea of letting my wife pursue her career and act as the stay at home dad int the future.  Not only would it allow me to dedicate the majority of the day to our kids, but being at home without work or school to stress over would also allow me to actually build.  But these are thoughts for the future, not necessarily something to act upon quite yet.

Something else I've been reflecting on is a feeling I've been fighting with for the last few years is just the motivation to do something of my own volition.  At the end of each day, I just want to sit at my chair and play video games.  So this summer, I'm starting again.  I'm not jumping into game design, like I originally aimed.  Well, not directly, anyway.

This time I'm looking at NES development.  This will just be the study of how games were made back when the cartridge was required, and games were coded purely in (by my understanding) assembly.  Not only will this tie closely to what I've studied the last 3 years, this will also be something exciting, something that I might actually desire to sit and work on.  Now that I have my old computer set-up running again, I can keep a blog about my findings and developments a little more easily as well.

I'll be studying the tutorials found here, and I'll share any relevant information I come across with every blog post I right.  The next post will be observing the NES architecture, but I am just about to finish the semester, so it may not be written for a few days.

Here's to hoping I keep my word this time.

Cheers,
-JWest