<<

Technical Course Curriculum and Annotated Bibliography

CS308: Programming By James and Jarrod Parkes Abstract

At the University of Alabama in Huntsville, the Science (CS) Department is facing a decreased student interest in their CS 308 language course. As a result, this new course curriculum and annotated bibliography have been created to restore excitement into the program. Since today's students are seeking innovative applications for programming, this curriculum teaches the 6502 assembly language with a focus on the Nintendo Entertainment System (NES)--a vintage console. While linearly covering the required assembly language material, this curriculum incorporates interactive examples from classic NES titles such as Super Mario and The Legend of Zelda. With this curriculum, CS professors are also given the tools to guiding students through the development of their very own NES video games. By the end of the curriculum, professors will be fully equipped to teach the 6502 assembly language while providing students the rewarding experience of game development. Additionally, the annotated bibliography includes supplementary texts and online articles to help reinforce topics for professors and students.

Source: Google Images

ii

Table of Contents

Introduction to the Assembly Language Course...... 1! What is an Assembly Language? ...... 1! How is this Course Structured?...... 2! Chapter 1 – The Class Project...... 3! 1.1 – Requirements ...... 3! 1.2 – Deliverables ...... 4! Chapter 2 – Number Systems and Representation...... 5! 2.1 – The System...... 5! 2.2 – Data Representation ...... 5! 2.3 – Converting Data...... 6! 2.4 – Example Problems ...... 8! Chapter 3 – The 6502 Instruction Set...... 10! 3.1 – Registers and Addresses...... 10! 3.2 – Arithmetic Instructions...... 11! 3.3 – Logical Operators and Comparison Instructions...... 11! 3.4 – Jumps, Branches, and Flags...... 13! 3.5 – Shifts and Rotates ...... 14! 3.6 – 6502 Instructions Set Wallpaper ...... 15! 3.7 – Example Problems ...... 17! Chapter 4 – Assemblers and Related Tools ...... 18! 4.1 – Editor: Notepad++...... 18! 4.2 – Assembler: NES Assembler...... 18! 4.3 – Graphics Editor: Graphics Gale...... 20! 4.4 – Graphics Viewer: NES Screen Tool ...... 21! 4.5 – Example Problems ...... 22! Chapter 5 – NES Hardware ...... 23! 5.1 – NES CPU ...... 23! 5.2 – NES PPU...... 24! 5.3 – Vertical Blanking...... 24! 5.4 – Pattern Tables ...... 25! 5.5 – Attribute Tables...... 26! 5.6 – Palettes ...... 26! 5.7 – NES APU...... 26! 5.8 – Example Problems ...... 27! Chapter 6 – The Game Loop ...... 28! 6.1 – Game Loop Structure...... 28! 6.2 – Optimizations...... 29! 6.3 – Closing Remarks...... 29! 6.4 – Example Problems ...... 29! Annotated Bibliography ...... 30!

iii List of Illustrations

Introduction to the Assembly Language Course ...... 1 Figure 0.1 – Funny Computer Comic ...... 2

Chapter 1 – The Class Project ...... 3 Figure 1.1 – Battle Kid Box Art ...... 4 Figure 1.2 – Battle Kid Instruction Manual ...... 4

Figure 1.3 – Battle Kid Title Screen ...... 4 Table 1.4 – Class Project Deliverables ...... 4

Chapter 2 – Number Systems and Data Representation ...... 5 Figure 2.1 – Traffic Light Binary Numbers ...... 5 Figure 2.2 – How the NES Graphics Processor creates Color Palettes ...... 6 Figure 2.3 – Weight Notation for Base-10 ...... 7 Figure 2.4 – Weight Decimal Notation for Base-2 and Base-16 ...... 7 Table 2.5 – Binary, Decimal, and Numbers ...... 8

Chapter 3 – The 6502 Instructions Set ...... 10 Table 3.1 – Register Transfer, Load, and Store Instructions ...... 10

Figure 3.2 – The Legend of Zelda Health Paradigm ...... 12

Figure 3.3 – NES Controller with Button Layout ...... 12 Figure 3.4 – NES Rotate Instruction ...... 15 Figure 3.5 – Nintendo 6502 Assembly Instruction Set Quick Reference ...... 16

Chapter 4 – Assemblers and Related Tools ...... 18

Figure 4.1 – Batch Process (double-click file to execute) ...... 19 Figure 4.2 – Compile from Command Line ...... 20

Figure 4.3 – Character Sprite Animation ...... 21 Figure 4.4 – NES Screen Tool ...... 21

Chapter 5 – NES Hardware Basics ...... 23 Figure 5.1 – NES CPU Memory Map ...... 23

Figure 5.2 – NES PPU Memory Map ...... 24

Figure 5.3 – Dragon Warrior Pattern Table ...... 25 Figure 5.4 – NES Global Palette ...... 26

Chapter 6 – The Game Loop ...... 28

Annotated Bibliography ...... 30

iv Page%1%

Introduction to the Assembly Language Course

In the last half-century, programming experience in high-level languages—like /C++, , and Python—has eclipsed all other requirements for development jobs. Despite the growing acceptance of high-level languages, companies developing embedded applications, operating systems, and time- critical programs still need with fluency in assembly languages. More important, the assembly language concepts are the basis for understanding the internal operation of a computer system. As a result, assembly language courses remain a cornerstone for the well-rounded education of a computer scientist.

Unfortunately, students have historically struggled to learn the fundamentals of assembly languages. Due to widespread adoption of high-level languages, students often consider assembly languages useless, verbose, and outdated. Furthermore, the majority of college curriculums have not adapted for the decline of student interest in assembly languages. To counteract this problem, this new course curriculum highlights the exciting applications for assembly language in video games.

What is an Assembly Language?

At the core of every computer, there is one basic language, and it is comprised of two words—true and false. To a computer, true and false represent the voltage level of an electrical component; however, to a , true and false represent whether a condition exists or does not exist. For simplicity, the binary digit “1” denotes true, and the binary digit “0’ denotes false. Although primitive, when these digits are combined together into sequences, a programmer can form remarkably complex instructions and data sets. These computer languages, expressed in the binary number system, are known as machine languages.

Like any language, the central purpose of a machine language is to communicate ideas with symbols. As stated above, machine languages use binary symbols to communicate instructions and data from a programmer to a specific computer or (CPU). For example, the sequence “10” might represent the CPU instruction: “it is true to display the graphics, but it is false to display the graphics in color”; however, if the sequence “10” is communicated as data, then the CPU may recognize the numeric value ten. Since binary symbols can quickly grow complex and convoluted, programmers developed more comprehensive languages for expressing the same instructions and data. These languages are known as assembly languages, and they will be central focus for the (CS) 308 course.

Page%2%

How is this Course Structured?

Typically, assembly language curriculums are divided linearly into the following topics:

1) language syntax 2) basic data types 3) control structures 4) advance topics 5) applications

Although this format provides a complete overview of an assembly language, it does not challenge students to think in a creative manner. As a result, this curriculum is intentionally structured to utilize the creative concepts found in video games instead of the concepts found in a generic textbook. Noticeably, the curriculum is still split into chapters by topics, but each chapter is uniquely tailored to teach assembly language while considering its function within a video game. So, in the next six chapters, students will learn the 6502 assembly language and target the Nintendo Entertainment System (NES) as their development platform. Prepare for a uniquely educational experience!

Figure 0.1 – Funny Computer Comic Source: Google Images Page%3%

Chapter 1 - The Class Project

The time for boring students is over! To convince students this assembly language course is not a trivial study, it is time to introduce the class project. Throughout the course, students will be working together to program a video game for the NES using the 6502 assembly . The project is designed to reinforce skills learned in the classroom and to motivate your students to be creative. The final product submitted by each group will satisfy the normal project requirements for the UAH CS 308 course.

1.1 - Requirements

The final video game package must contain marketing materials and a binary of the video game. Since certain parts of the project will include tasks related to box art, story design, and advertisement, students should be encouraged to seek group participants from outside of class—the art department might be a good place to start! After students submit their project, you will take the binary and transfer them to a NES PowerPak device for hardware testing. A newly purchased NES PowerPak and NES system should be provided by the CS Department prior to the course start date. In the event of a NES hardware failure, testing may be completed using the Nestopia emulation software because of its precise hardware accuracy. On the last week of the semester, students will give a live demonstration of their video games for peer review and comments. Below, we have provided you with a minimum list of hardware and software requirements needed for the class project. % Hardware ' 1 Nintendo Entertainment System ' 2 NES Controllers ' 1 NES PowerPak Software ' Nestopia ' Notepad++ Source Code Editor ' NES Assembler ' GraphicsGale Animation Graphic Editor ' NES Screen Tool 1.50

As mentioned above, each group is responsible for delivering a marketing package. For the marketing package, groups must create an instruction manual and box art for their video game. The instruction manual should briefly describe the game’s plot and controls, and the box art should provide a minimum of two graphics intended to advertise the game. All graphics produced for the marketing package may be submitted in digital format for grading and review, and printed copies may be considered for extra credit. An example of acceptable box art is shown on the following page. % Page%4%

%

Figure 1.2 – Battle Kid Instruction Manual

Figure 1.1 – Battle Kid Box Art

Source: Sivak Games 2010 Figure 1.3 – Battle Kid Title Screen % 1.2 – Deliverables

To help with potential scheduling issues, the project has been divided into deliverable tasks corresponding to the course chapters. Assuming the curriculum is followed in order by chapter, the students should be able to complete each task in a timely manner. Listed in the table below, the class project has been chronologically outlined by each deliverable.

Table 1.4 – Class Project Deliverables

Week Chapter Deliverables

1-2 1 Team Roles, Time and Task Schedule Preliminary Data Requirements, Potential Compression 3-4 2 (optional) 5-7 3 Sample Art Assets, Basic Gameplay Summary 8 4 Title Screen, Sprite Sheet 9-11 5 Initial Memory Map, First Prototype 12-14 6 Preliminary Marketing Package, Second Prototype 15 1-6 Final Project Page%5%

Chapter 2 – Number Systems and Data Representation

To begin a discussion on number systems, it is natural to start with the concept of counting. Quite simply, a number system is a formal way of specifying how numbers are counted. At an early age, children are universally taught the process of counting using their fingers to represent the single digit values. Unbeknownst to most children, counting with their fingers is actually representative of the base-10 number system. So, why is this important to the application of assembly languages?

2.1 – The Binary Number System

Computers use the base-2 number system—more commonly referred to as binary. The digit “2” in the word “base-2” is related to the two unique digits used in the binary number system: “0” and “1”. For the digits zero and one also have the special meaning of “on” or “off”, “true” or “false”, and “high” or “low”. Each of these special meanings corresponds to whether or not a component in a computer is holding an electrical charge. To avoid confusing students, it is best to explain the binary system with visual examples similar to Figure 2.1.

Figure 2.1 – Traffic Light Binary Numbers Source: Image created by author

2.2 – Data Representation

Like the traffic lights in Figure 2.1, electrical memory components in a computer flash, or change from high to low, in the presence of binary ones and zeros. For automobile drivers, a flashing traffic light may represent whether to stop or yield at an intersection; however, in a modern computer, flashing memory components may represent numbers or processes. When automobile drivers, computers, or programmers derive meaning from symbols, they are interpreting or representing data. Below, Figure 2.2 demonstrates how the NES graphics processor interprets color information from binary numbers.

Page%6%

Figure 2.2 – How the NES Graphics Processor creates Color Palettes Source: Super Mario Bros. 1985, Image created by author

At their core, all software programs and video games are strings of a hundreds, thousands, or even millions of binary ones and zeroes. For humans it would be nearly impossible to determine the meaning of every one and zero, so assembly languages were developed as an intermediate between humans and computers. Also, computers simplify the task of interpreting binary digits, known as , into bytes. A byte is the smallest sequence of bits a computer will handle at any given moment, and it is comprised of eight bits. By using a byte, it is possible to condense binary sequences even further with the hexadecimal or “hex” (base- 16) number system. In the next section, the process of converting between binary, decimal, and hexadecimal number systems is explained, and some example practice problems are provided for review.

2.3 – Converting Data

As discussed earlier, number systems are essentially counting mechanisms, but why do so many exist? Although counting by ones, tens, and hundreds works in the base-10 number system, computers cannot count in the same manner as humans. They have no fingers! Since programmers deal with decimal numbers and computers at the same time, it is essential for them to be able to convert between the differing number systems. To accomplish this task, students will need to recall the Weighted Notational Form (WNF) for decimal numbers. Page%7%

Figure 2.3 – Weighted Decimal Notation for Base-10 Source: Image created by author

In the same way, binary numbers have a WNF using the powers of two instead of ten. For hexadecimal numbers, WNF requires the powers of 16. Below, in Figure 2.4, examples of binary and hexadecimal numbers are shown in WNF.

Figure 2.4 – Weighted Decimal Notation for Base-2 and Base-16 Source: Image created by author

Visually, the relationship between the binary and hexadecimal systems starts to appear in Figure 2.4. In the image, the four bits “1111” correspond to one hexadecimal digit “F”. Hexadecimal digits range from 0 through 15, and the letters “A”, “”, “C”, “”, “E”, and “F” are used for 10 through 15 instead of Arabic numbers. As long as students have completed all the necessary prerequisites for this course, they should be fully capable of converting between the binary, decimal, and hexadecimal number systems; however, if additional instruction is required, consult any of the 6502 programming books in the annotated bibliography.

Page%8%

Table 2.5 – Binary, Decimal, and Hexadecimal Numbers

Binary Decimal Hexadecimal

0000 0 0 0001 1 1 0010 2 2 0011 3 3 0100 4 4 0101 5 5 0110 6 6 0111 7 7 1000 8 8 1001 9 9 1010 10 A 1011 11 B 1100 12 C 1101 13 D 1110 14 E 1111 15 F

2.4 – Example Problems

1. In the classic NES Game, Gauntlet, your character has been reduced to 100 health points. Represent the number 100 in one byte, using the binary and hexadecimal number systems.

2. For the clock in your new NES game, you have decided to use one byte of storage. Assuming you have correctly programmed timing and your clock can never reset, what is the maximum number of seconds you can represent with one byte?

3. To present the colors light blue, dark green, and purple in your game you must use the hexadecimal numbers 21h, 0Bh, and 14h. What are the binary values for these colors?

4. John Doe needs a field for his game's map tile system. The should be one byte in length: the first four bits should represent the tile number and the last four bits should represent the tile type. Using the table below, show the binary and hexadecimal value needed to display a forest collision tile.

Page%9%

Tile Number Description Tile Type Description (4-bits) (4-bits)

0000 sand 0000 walk 0001 sea 0001 door 0010 shallow 0010 collision 0011 stone 0011 damage 0100 gravel 0100 slippery 0101 flower 0101 warp 0110 forest 0110 stair 0111 grass 0111 sink 1000 lava 1000 bounce

5. Listed below is a source code snippet from the NES game "Red Block Blue Block". Without worrying about the assembly commands, convert the highlighted numbers to their decimal equivalents.

MetaBlockCollision: .db $88,$8E,$03,$88 ; top-left corner MetaTimer: .db $CF,$00,$00,$48 ; hundreds digit

Page%10%

Chapter 3 – The 6502 Instruction Set

In the previous chapter, a link was made between data and their associated meanings through the process of data representation. Now, the same process can be used to relate 6502 assembly instructions into executable instructions for the NES. As this chapter outlines the 6502 instruction set, students should be reminded that 6502 instructions are eventually converted into an executable form for the NES processor: this is accomplished through assembling and linking. If students want to harness the full power of the NES, they will need to fully understand these processes; however, for brevity, this chapter will only include the necessary details to quickly enable students to begin their video game projects.

3.1 – Registers and Addresses

Before listing the 6502 instruction set, students should analyze the parts of the NES processor, the Ricoh A203. Like any 6502 processor, the A203 consists of three special memory locations: register-A, register-X, and register-Y. Of the three registers, register-A or “the accumulator” handles all the arithmetic functions of the processor. In contrast, registers X and Y are used primarily as counters, offsets, and temporary storage locations. The first set of load and store instructions the students will analyze involve each of these registers.

Table 3.1 – Register Transfer, Load, and Store Instructions

Instruction Description Instruction Description

TAX Transfer A to X LDX LoaD X Register TAY Transfer A to Y LDY LoaD Y Register TXA Transfer X to A STA STore Accumulator TYA Transfer Y to A STX STore X Register LDA LoaD Accumulator STY STore Y Register

Using the table above, have students focus on the mnemonics for each instruction—these are the formal names required in code for execution. Students should not be required to memorize these instructions because they may be quickly referenced online or in related texts. If finding an adequate reference becomes a problem for students, this curriculum provides a full NES- themed instruction sheet at the end of this chapter.

From this point forward, the curriculum may use the word commands instead of instructions, but the two words may be used interchangeably. Moving forward, it is important to note that nearly all commands require arguments in the form of memory addresses. While some commands use implicit addresses, like INC and DEC, the majority of instructions will require explicit 16-bit addresses. Since the 6502 processor can access memory addresses using 16 Page%11% bits, the total number of addressable memory locations is 65,536. The form in which a command addresses a memory location is known as an address mode.

In total, the 6502 can address memory in three distinct address modes: indirect, direct/absolute, and zero-paged. If an address is specified in its full 16-bit nomenclature, then the address mode being used is called absolute addressing. In the following example, this curriculum will briefly demonstrate a few of the store and load commands using explicit 16-bit addresses in the absolute . For additional examples using each address mode, consult the available resources in the annotated bibliography.

LDA #$3F ; load 3Fh into the A-register LDY #10 ; load 10d into the Y-register LDX #%00010110 ; load 00010110b into the X-register STA $0100 ; store #$3F at the hex address $0100 STY $0101 ; store #10 at the hex address $0101 STX $0102 ; store #%00010110 at the hex address ; $0102

3.2 – Arithmetic Instructions

Once data is loaded into registers, particularly the accumulator, it is time for arithmetic. By using the arithmetic instructions, programmers can perform meaningful tasks required for video game scenarios. Consider the common game mechanic for adding points to a player’s . This type of mechanic obviously requires math, and hence students should know the arithmetic instructions for their video games.

The 6502 instruction set includes the four basic arithmetic functions: addition, subtraction, multiplication, and division. For most purposes, students may assume these mathematic functions are operating only on positive integers. Unlike the section on load and store commands, this curriculum will not include a listing of each mnemonic, instruction name, and description. Instead, the curriculum will suggest the use of the NES-themed instruction sheet at the end of this chapter; however, as stated earlier, many exemplary resources exist online or in the referenced texts in the annotated bibliography. So, if students require a more traditional textbook approach to learning any set of instructions, please use the provided resources.

3.3 – Logical Operators and Comparison Instructions

Students will also need the logical operators and comparison instructions to make run-time decisions based on data. For instance, in the NES game The Legend of Zelda, programmers used comparison instructions to check when Link’s heart containers equaled zero. If Link’s heart containers equals zero, then the player loses a life! Otherwise, Link is healthy and ready to defeat the monsters of Hyrule. In the Link example, a single comparison is required, but for many applications the logical operations are also necessary to make judgments about data. The example in Figure 3.2 demonstrates arithmetic and Page%12% comparison operators being used together to determine the correct game behavior for Link.

Figure 3.2 – The Legend of Zelda Health Paradigm Source: The Legend of Zelda 1986, Image created by author

Based on the comments in Figure 3.2, students may already be able to determine the meanings of the JMP and BNE commands, but these instructions will be covered exclusively in the next section. Before moving ahead, there is one more core topic included with logical operations—the bitmask. A bitmask is a sequence of binary digits: for each digit set to the binary one, a programmer can indicate the importance of a “state”. In video games or complex automata, states are conditions or points in execution. When combining states, logical operators, and bitmasks, programmers can easily isolate the conditions in a system. As an example, the curriculum will detect the states of a NES controller using bitmasks—this is a very common solution found in nearly all NES games.

Figure 3.3 – NES Controller with Button Layout Source: Image created by author Page%13%

UP_MASK EQU %00001000 ; up pressed DOWN_MASK EQU %00000100 ; down pressed

HandleInput: ; : handle input LDA

As seen above, a several bitmasks and the AND operator can detect when buttons are pressed on the NES controller. After a button has been detected, programmers must then decide on the correct game behavior based on the button’s type. Historically, when players have input the “START” button, programmers have implemented a pausing behavior. In the next section, the curriculum will outline how the 6502 assembly language can make decisions based on input like the “START” button. This will be accomplished through the use of jumps, branches, and flags.

3.4 – Jumps, Branches, and Flags

In any assembly language, the command “jump” is synonymous with the phrase “move to this location in memory”. Fundamentally, an assembly language jump redirects a program’s execution to a new set of instructions. To improve readability, programmers often use labels to indicate the purpose of a set of instructions—this helps to form semantically correct jump statements. For example, if the user presses “START” on the NES controller, then the program should jump to the “START handler” set of instructions. To summarize, when programmers unconditionally jump to locations in code, they should use the normal JMP instruction; however, if programmers want to check for necessary conditions before jumping, then they should instead use branching instructions.

By design, the 6502 processor only contains a small set of branching conditions: carry, equal, sign, and overflow. Each condition is provided to the programmer in the form of a flag. A flag is a programming term for an isolated bit. To clarify, a programmer checks the condition of a flag—is the flag raised or not? In order to check the conditions of flags, a programmer must first execute an instruction to actually set the status of each flag. For instance, if a game requires the overall score to eclipse one hundred points before advancing to the next level, then a programmer must first retrieve information about the current score. Once the score is loaded, the programmer may then compare the score against one hundred. Following the compare statement, the flags will be properly set to execute a branch instruction. Below, another source code snippet is given to fully demonstrate the score example.

Page%14%

HitByMonster: ; LABEL: link got hit by a monster LDA

3.5 – Shifts and Rotates

Lastly, the 6502 instruction set includes commands for shifting and rotating bits. These commands are used less frequently than others, but they still provide important functionality for specific situations. To explain shirts, the curriculum will revisit the brief example of bitmasks. In the bitmask example, comparisons were made against several masks to indicate whether a user pressed a button on the NES controller. Although the initial example is functionally correct, the example’s efficiency could be improved with the shift commands.

A shift or “bit-shift” operates as stated: “shift a each by a certain number in the direction specified, and the excess bits will be filled based on the command”. So, for the LSR (logical shift right) command, a bit is shifted to the right based on the number specified. Since the shift is logical and not arithmetic, all excess bits are filled with the binary digit zero. For arithmetic shifts, the excess bits are filled with binary value stored in the most significant bit. Also, to improve on the previous checking for NES controller states, a revised code example is given using the shift command!

HandleInput: ; LABEL: handle input LDA

The final instructions this curriculum will cover in detail are the rotate commands. Like shifts, rotate commands deal with moving bits in either the left or right direction. The only difference betweens shifts and rotates lies in the final location of trailing bits. For shifts, bits that shifted beyond the bounds of a byte were either lost of placed temporarily in the ; however, when rotating, the trailing bits are wrapped back into the original storage location. A rotate command may be visually depicted by a ring where the head of the structure is also the tail—see Figure 3.4 for this example.

Page%15%

Figure 3.4 – NES Rotate Instruction Source: Image created by author

At this point, students should have a basic understanding of the 6502 instruction set—excluding the stack commands. The stack commands are simple assembly language abstractions for the run-time stack structure. Students should have encountered stacks in their prerequisite courses, but supplementary material on stacks is provided in referenced texts. Thankfully, most simple NES games should only require the instructions in the chapter. So, without wasting anymore time, it is time to wrap up this chapter and start developing games!

3.6 – 6502 Instruction Set Wallpaper

For reference, the curriculum has included this custom designed 6502 instruction set image. The image divides the instructions into logical groupings based on their functions. Also, visual learners will be able to associate the whimsical images with instruction types. Since programmers often swap between many programming languages at one time, the visual cues can aid in quick memorization. Upon request, the CS department can provide a full resolution image for desktop backgrounds.

NES 6205 Assembly quick reference guide

R ARITHMETIC

LOAD E ADC - ADd with Carry LDA - LoaD Accumulator SBC - SuBtract with Carry G LDX - LoaD X Register PHA - PusH Accumulator on Stack CMP - CoMPare Accumulator I PHP - PusH Processor Status on Stack

LDY - LoaD Y Register S CPX - ComPare X Register STA - STore Accumulator PLA - PuLl Accumulator from Stack CPY - ComPare Y Register T STX - STore X Register PLP - PuLl Processor Status from Stack STY - STore Y Register E TSX - Transfer Stack Pointer to X JMP - JuMP

R TXS - Transfer X to Stack Pointer JSR - Jump to RTS - ReTurn from Subroutine C STORE TAX - Transfer A to X TAY - Transfer A to Y STACK JUMPS A TXA - Transfer X to A L

TYA - Transfer Y to A L LOGICAL SYSTEM S AND - Bitwise AND TRANSFER BRK - BReaK with the Accumulator RTI - ReTurn from BIT - BIT Test NOP - No OPeration EOR - Bitwise Exclusive OR ORA - Bitwise OR with Accumulator

> CLC - CLear Carry SHIFTS >>>>> > CLD - CLear Decimal ASL - Arithmetic Shift Left > CLI - CLear Interrupt

LSR - Logical Shift Right > CLV - CLear oVerflow

ROL - ROtate Left > FLAGS SEC - SEt Carry

BRANCHES ROR - ROtate Right > SED - SEt Decimal

BCC - Branch on Carry Clear > SEI - SEt Interrupt BCS - Branch on Carry Set <<<<<< BEQ - Branch on EQual - if zero flag set INC - INCrement Memory BMI - Branch on MInus - if negative flag set INX - INcrement X BNE - Branch on Not Equal - if clear ++INCREMENT INY - DEcrement Y BPL - Branch on PLus DEC - DECrement Memory BVC - Branch on oVerflow Clear DEX - DEcrement X BVS - Branch on oVerflow Set DEY - DEcrement Y DECREMENT-- Page%17%

3.7 – Example Problems % 1. In the NES game Metroid, Samus must collect power-ups to enter new game areas. One power-up, the morph ball, is represented by the decimal value 43. Write a code snippet to check if the value in the accumulator matches the morph ball value. If the values matches, branch to a label called "OpenDoor". If the value does not match, jump to a label called "Blocked".

2. Assume the score in the NES game Pacman is stored in a single byte. In the current game, the user has scored 137 points. If the user adds 200 points to their score by eating an orange, then what flag is turned on (unsigned addition)?

3. John Doe has decided to use bit fields again in his adventure game. Since his hero character can equip eight weapons, John will use a byte to determine the currently equipped weapon. Given the following weapon chart, how many LSR commands are required for the hero to switch from the sword to the bow?

4. A simple Pong game uses 4 bits to store the score for each of its two players. If the byte holding both scores is in the accumulator, write a code snippet using the rotate commands to swap the scores.

5. When playing the NES game Red Block Blue Block, the score normally increases by one. In a future version, it would nice to implement a score multiplier of 2. What single 6502 instruction can multiply by 2 (not the MUL instruction)?

Page%18%

Chapter 4 – Assemblers and Related Tools

Unlike previous chapters, this part of the curriculum will move away from teaching aspects of the 6502 assembly language and focus on game applications. This should be the part of curriculum to excite and motivate students. In the following sections, the curriculum will provide recommendations and descriptions about the necessary tools to design NES programs and graphics. Unless specified, most of these tools are absolutely free to download and use, but will require online access. If online access is an issue, digital copies of the programs may be provided upon request.

4.1 – Source Code Editor: Notepad++

When editing source code, programmers often have a software preference based on the ease-of-use, cost, and language support. Since the Notepad++ software provides all of these features, this curriculum highly recommends students use it for the duration of the course; however, if students are more comfortable in other programming environments, they should be encouraged to write source code using their preferred tool. If students choose a different source code editor, they should avoid a fully featured integrated programming environment (IDE). While an IDE is great for compiling and execution on a modern platform, this course only requires assembling at the command line. Simply, the source code editor will be used to modify the source code.

Notepad++ does not ship with any default syntax highlighting for the 6502 assembly language. Since syntax highlighting is a general norm for programming environments, a custom language file has been included with the department’s copy of Notepad++. It is not a necessary requirement for students to use the custom language file, but it will greatly benefit students still becoming familiar with the 6502 assembly language. Besides basic setup, there are no additional steps for installing and running the Notepad++ software. With Notepad++ in place, students should be able to freely write 6502 assembly code, but they will need a tool for the assembly process.

4.2 – Assembler: NES Assembler

As mentioned in previous chapters, all 6502 source code must be assembled to execute on the NES. Although are not physical versions of the NES, they too require the same process. To accomplish this task, programmers must choose an assembler that specifically targets a 6502 processor. Assemblers like ASM6, , and WLA DX are used frequently for this task, but this curriculum will focus exclusively on NESASM. For the beginning NES developer, NESASM is commonly chosen because of its simple syntax and free download cost; however, after students have completed the course, their fluency with NESASM syntax should enable them to quickly convert to developing with any standard assembler.

% Page%19%

Since NESASM is a command-line tool, there is no formal installation process. In order to compile source code with NESASM, students must either (1) create a batch process or (2) compile from the command-line. Each of these procedures is demonstrated in following figures:

Figure 4.1 – Batch Process (double-click file to execute) Source: Screenshot provided by author

% Page%20%

Figure 4.2 – Compile from Command Line Source: Screenshot provided by author

By using the NESASM, this curriculum requires students to operator under a few constraints: (1) memory blocks must be organized into 8 kilobyte sections, (2) the NES header must be defined in NESASM standard, and (3) any additional directives must use the NESASM syntax. Obviously, these are constraints placed on the programmers by the assembler. So, if another assembler is chosen, then the constraints will be different. At this point, none of the example snippets have involved the constraints, and they may be freely extracted regardless of the assembler. When the curriculum begins to show examples of the game loop, code references may use the constraints, but these cases will be clearly denoted in the comment lines.

4.3 – Graphics Editor: Graphics Gale

Since the resolution of NES graphics are constricted to small 8 by 8 pixel tiles, the complex features of most graphics applications are not necessary. For example, applications such as Adobe Photoshop, Corel Graphics Suite, and GNU Image Manipulation Program (GIMP)—which often deal with high-resolution digital images—will overcomplicate simple NES graphics work. For that reason, this curriculum suggests the free graphics program Graphics Gale. Unlike the bulky graphics applications, Graphics Gale gracefully handles basic pixel images.

% Page%21%

More importantly, Graphics Gale contains an impressive frame-based editing system that will useful when creating NES game sprites. In Figure 3.3, an example sprite animation, designed in Graphics Gale, is given as a reference.

Figure 4.3 – Character Sprite Animation Source: Castlevania 3 1989, Image created by author

4.4 – Graphics Viewer: NES Screen Tool

While designing pixel art for the NES is purely a creative endeavor, optimizing pixel art for the NES is a deeply analytical task. To effectively compress the size of every graphic in a NES game, developers must organize pixel art into tile sheets and color palettes. Thankfully, the NES Screen Tool is a freely available editor that gives users a graphical representation of NES graphics data like palettes and tile sheets. In the next chapter, students will learn about the internal functions of these NES graphic entities. A sample tile sheet, loaded in the NES Screen Tool, is shown in Figure 4.4.

Figure 4.4 – NES Screen Tool Source: Screenshot provided by author

% Page%22%

4.5 – Example Problems

1. Programmers need to be comfortable with their tools. Since this curriculum uses Notepad++, define a custom color syntax for the 6502 assembly language.

2. List two differences between the ASM6 and NESASM assemblers.

3. Search and download a pixel graphic from an existing NES game. Describe the technical elements--size, shape, and color--of the downloaded pixel graphic.

4. Download a NES tool not listed in this chapter. Once downloaded, describe the use of the tool you found.

5. The NES community supports the active development of new NES tools. To join the community, register on a NES homebrew forum or question- based portal.

% Page%23%

Chapter 5 – NES Hardware Basics

By modern design standards, the grey square-shaped NES looks like a clunky console from the past. Despite its outdated appearance, the NES exterior actually hides some impressive pieces of hardware. During its prime, the NES contained three effective and affordable processors—each a separate module for handling different processing tasks. In this chapter, all three processors will be analyzed, but a major portion will be focused on the picture-processing unit (PPU).

5.1 – NES CPU

The NES CPU is the center of all operations during the execution of a program. In fact, the PPU and audio-processing unit (APU) can only be accessed via the CPU and memory-mapped registers. Memory-mapped registers are static memory addresses that correspond to locations on other hardware peripherals. For the NES, the connected peripherals include the PPU and APU. By using memory-mapped registers, a programmer can drive the execution of external hardware processes. Since most memory-mapped registers never change location, the memory layout for each NES game tends to be the same; however, some special memory maps have the ability to change the default memory layout. For this chapter, the curriculum will focus on the default memory map—known as NROM.

When NROM is applied, the NES CPU addresses memory locations in a flat stack model. The entire memory space can reference 65,536 unique addresses, but certain addresses serve special purposes. For instance, the address $4000 pertains to the first square sound wave on the NES APU. General-purpose memory is located at the front end of the address space, and it provides programmers with about 4 kilobytes of storage. Other sections of the address space include the PPU registers, S-RAM, and Expansion ROM. Figure 5.1 outlines the entire NES CPU memory space.

------$10000 NMI/RESET/IRQ Vectors | 6 bytes ------$FFFA Upper Bank of PGR-ROM | 16378 bytes ------$C000 Lower Bank of PRG-ROM | 16384 bytes ------$8000 S-RAM | 8192 bytes ------$6000 Expansion ROM | 8160 bytes ------$4020 APU/Controller Registers | 32 bytes ------$4000 8 Byte Mirrors | 8148 bytes ------$2008 PPU Registers | 8 bytes Page%24%

------$2000 2 Kilobyte Mirrors | 6144 bytes ------$0800 Internal RAM | 1536 bytes ------$0200 Stack Memory | 256 bytes ------$0100 Zero Page RAM (Fast Access) | 256 bytes ------$0000 Figure 5.1 – NES CPU Memory Map

5.2 – NES PPU

To make anything appear on screen, programmers must fully understand the NES PPU. Since video games intrinsically rely on graphics, this section may be considered this most important part of the book. Since the NES PPU is a fairly complex piece of hardware, the curriculum has divided the component into the following sections: vertical blanking, pattern tables, attribute tables, and palettes. Before describing each section, it is also necessary to examine the NES PPU memory map depicted in Figure 5.2. Although these memory locations cannot be directly accessed, their numeric locations will be vital when rendering graphics to the screen.

------$4000 | Empty | 224 bytes ------$3F20 | Sprite Palette | 16 bytes ------$3F10 | Background Palette | 16 bytes ------$3F00 | Empty | 3840 bytes ------$3000 | NAM/ATTR Tables #1-3 | 3072 bytes ------$2400 | Attribute Table #0 | 64 bytes ------$23C0 | Nametable #0 (32x30 tiles) | 960 bytes ------$2000 | Pattern Table #1 (16x16 tiles) | 4096 bytes ------$1000 | Pattern Table #0 (16x16 tiles) | 4096 bytes ------$0000 Figure 5.2 – NES PPU Memory Map

5.3 – Vertical Blanking

For those using modern televisions, the concept of a vertical blanking system may seem completely foreign; however, when the NES was a popular console, Page%25% vertical blanking was the common processed used by cathode televisions to refresh a video screen. To explain the topic, the curriculum will relate vertical blanking to the feeding a new page into a typewriter. Traditionally, when a typewriter reaches the end of a page, a typist must manually scroll a new sheet of paper into the machine. Like the typist, a cathode television also requires a method for providing a fresh canvas when the screen needs to be refreshed. For a cathode television, this process is handled automatically and in a timely fashion. The period of time between the end of one screen of graphics and the beginning of new screen of graphics is known as vertical blank.

In a NES video game, all the graphics must be drawn to the screen prior to the next vertical blanking period. Otherwise, graphics glitches may occur during game play. To avoid potential problems, NES applications should handle draw the next screen of graphics as soon as the current screen of graphics is rendered. This way, a programmer can ensure no graphics glitches occur, and the user can enjoy a consistent game experience.

5.4 – Pattern Tables

Pattern tables are a data abstraction for a group of tile graphics. Each tile on the NES is 8 by 8 pixels, with the exception of sprites. To the NES hardware, the tiles exist as binary data, but to the programmer they are visual images. A full pattern table contains 32 rows, and each row contains 30 tiles—resulting in a total resolution of 256 x 240 pixels. Using the default memory map, a NES can store a total of two pattern tables; however, with the aid of special mappings, the NES can store extra pattern tables in RAM/ROM with bank switching. In a typical setup, one pattern table is used for a game’s background while the other is used for sprites. Figure 5.3 shows the pattern tables from the NES adventure game Dragon Warrior.

Figure 5.3 – Dragon Warrior Pattern Table Source: Dragon Warrior 1986 Page%26%

5.5 – Attribute Tables

While pattern tables define the structure of a NES graphic, the attribute table defines the color. When combined with the palettes chosen by the programmer, the attribute table applies color to otherwise grayscale images. Without using a visual aid, attributes may seem confusing, but simple application of color is surprisingly straightforward. Each NES tile is fundamentally composed of only four different colors. As a graphic artist, the tile colors represent the final hues displayed to the screen; however, for programmers, each color corresponds to a lookup value into palettes. Semantically, the relationship can be expressed as “color one maps to the first color in the palette”. The same relationship applies to the second, third, and fourth color. For sprites, the color is always the transparency color. Refer back to Chapter 2, Figure 2.2 to see how the attribute table modifies NES tiles.

5.6 – Palettes

Palettes in the NES PPU are split into two categories: global and user-defined. The global palette specifies all the colors the NES PPU can generate with its hardware. In total, the global palette contains 64 colors, but only 56 are uniquely indentified. Across different televisions, the quality of each color may change, and programmers should avoid the shades of yellow. To use any of these colors in a NES game, the colors must be referenced using user-defined palettes.

Figure 5.4 – NES Global Palette Source: Image created by author

User-defined palettes have already been mentioned by the curriculum, but they have not been explicitly defined. In the NES PPU, a programmer can specified a color palette for backgrounds and sprites with 12 colors each. Each palette is subdivided into four sub-palettes—containing four colors—that may be utilized by the aforementioned attribute tables. As mentioned in the attribute table section, the first color is always the transparent color.

5.7 – NES APU

Finally, the last hardware component to be reviewed is the sound processor called the NES APU. Of all the NES hardware, the APU is probably the most Page%27% difficult component to master. For the purposes of this class, the curriculum will only review the structure of the component, but not actual implementation. Several online sources include information on how to develop sound clips and music for the NES, but this topic is too difficult to discuss in one semester.

The NES APU consists of four sound waves: square wave 1, square wave 2, triangle wave 1, and the noise wave. The geometrical names associated with each wave describe the wave frequency of the produced sounds. For example, square sounds waves have sharp corners like a square that quickly start and end. This results in an immediate sound, unlike the triangle wave—which slowly rises and falls in pitch. In contrast, the noise wave produces an unbalanced and random sound. As a result, programmers often use the noise wave for ambient sounds and background effects.

5.8 – Example Problems

1. NROM is only one of the NES memory maps. List two other NES memory maps and explain their function.

2. Given the eight sub-palettes in the NES PPU, how many unique colors can be displayed at one time in a NES game?

3. Since each NES sprite may only reference one sub-palette, how might it be possible to create a sprite that uses more than three colors?

4. John Doe has made another design decision for his NES adventure game. He would like to display the currently equipped item in a static toolbar at the top of the screen. Would the graphic for each item be considered a background tile or a sprite tile? Page%28%

Chapter 6 – The Game Loop

Before students embark on creating their masterful NES video games, one last topic must be discussed—the game loop. At the core of all video games, old and new, is a regularly occurring game loop. By using a game loop, programmers create the illusion of time passing in a virtual environment. In modern game consoles, game logic can be timed using advanced programming interfaces, but the NES must rely on low-level hardware implementations for timing. For the basic NES game, students should be advised to use the vertical blank period as the control structure for their game loop.

6.1 – Game Loop Structure

As stated above, timing is crucial for the proper execution of any video game. To give users a fluid gaming experience, video games cannot delay or glitch—in video game terminology, this is known as lag. Generally, issues related to lag are the result of poorly designed game loops. Since the NES has limited speed and memory, game loops designed for the NES must be optimized to fit its stringent timing criteria. This curriculum will use most consistent timing criteria in the NES—the PPU vertical blank.

When the NES PPU reaches a state of vertical blank, the programmer has a limited amount of time to update the video game state. Ideally, if game updates are handled quickly, then the video game will gracefully transition to the next game state without lag. As a guideline, the average time between when vertical blank starts and ends is about 24,000 clock cycles. In simple video games, exceeding 24,000 clock cycles for game updates is unlikely; however, in the event that lag becomes an issue, programmers may count the individual clock cycles required by each assembly instruction. Below, an example game loop has been given with comments to describe the structure.

GameLoop: JSR HandleInput ; get input from controllers JSR GameLogic ; run game logic JSR UpdateSound ; do any sounds need to be played? JSR PrepareVRAMData ; prepare video data JSR frames

.1 ; loop until vblank is entered CMP frames BEG .1 JSR CopyVRAMData ; quickly update VRAM before ; vblank ends! JMP GameLoop ; GameLoop

NMI: ; vertical blank entered! INC frames ; increase frame count RTI ; return from interrupt Page%29%

6.2 – Optimizations

After students have experimented with the example game loop, they may seek ways to further optimize the process. The quickest and easiest way to improve the game loop is to limit the amount of graphic data updated per execution. For most games, backgrounds may remain static throughout game play—this provides a great opportunity to reduce graphic updates! For instance, programmers can refresh only the necessary sprite information instead of an entire screen of graphics. This method is used liberally in commercial NES games, and can make a drastic performance different in video games created for the class project!

6.3 – Closing Remarks

In six short chapters, this curriculum has finally come to a close. With the addition of the game loop section, students should now be fully equipped to finish their game projects. Although the content of this curriculum has ended, many additional learning materials exist on the Internet and in published texts. For a quick summary of approved resources, students and professors should reference the attached annotated bibliography. Since this curriculum does not require a mandatory textbook, the annotated bibliography should serve a supplementary guide for students or professors who need further instruction. Also, for any questions regarding the content in this curriculum, please contact the authors directly by email. Good luck and start gaming!

6.4 – Example Problems

1. Optimizations are commonly made to NES game loops that conserve space and time. In a similar manner, optimizations can also be made to the data required for each screen in a game. List one type of optimization that could be made to reduce the size of data needed for a screen of NES graphics.

2. Huffman coding is an advanced optimization used for text systems in some NES games. Research the Huffman coding technique, and give one example of how a Huffman tree is traversed. Page%30%

Annotated Bibliography

Anderson, Charles. The Visible Computer: 6502 User Manual. Houston: Software Masters, 1984. Print.

In this short manual, the author describes the “6502 machine [or assembly] language” using The Visible Computer (TVC)—a 6502 simulator software written for the —as the target platform. He examines the performance tradeoffs between using the robust Basic language versus the low-level, but fast, 6502 machine language. After making a strong argument for the speed of 6502, the author discusses the binary, decimal, and hexadecimal numbers systems and basic memory maps. Without becoming overly complex, the manual then provides an insightful description of each hardware component emulated on a TVC processor. Since the programming examples in this manual are demonstrated using TVC instead of modern software, novice programmers may have difficulty following the examples; however, online simulators for 6502-based processors exist for necessary circumstances. The rest of the manual outlines the 6502 instruction set, addressing modes, and control structures, and it provides useful tips for optimizing code. For the intermediate programmer, this manual reinforces the 6502 assembly language, but it is not recommended for an absolute beginner.

Dandamudi, Sivarama P. Introduction to Assembly Language Programming: For Pentium and RISC Processors. 2nd ed. New York: Springer, 2005. Print.

This dense book covers assembly language programming for CISC and RISC based processors using the NASM assembler. For universal access, the author chose the NASM assembler because it operates on all major operating systems—Windows, Mac OS X, or . As a result, this book can effectively serve as a graduate-level textbook or manual even in diverse hardware environments. Pentium and MIPS are the primary assembly languages used in examples throughout the book, but the concepts of each language will translate directly to the 6502. Topics on recursion, string processing, and techniques are included later in the book, but they will not benefit students developing for limited memory platforms like the NES. The author also includes a section on processor design principles and pipelined execution since CISC and RISC architectures involve timing constraints—similar to NES timing constraints for graphic updates. Although lengthy, this book should be highly recommended for advanced programmers with an interest in the modern applications for assembly languages.

De Jong, Marvin L. Programming & Interfacing the 6502, With Experiments. Indianapolis: H. W. Sams, 1983. Print.

In this challenging book, the author teaches the 6502 assembly language while emphasizing the importance of a “hands-on” experience. Immediately in the first chapter, the author diagrams the technical specifications of the 6502 processor using tables and charts. Then, he gives a detailed explanation about the duality of 8-bit and 16-bit address modes for instructions and data: this section is particularly useful for understanding the differences between instruction . The following chapters cover the 6502 instruction set in logical groupings, and at the end of each chapter, Page%31% experiments are listed for readers to test their knowledge. For quick referencing, the appendix includes a comprehensive chart for every 6502 instruction and address mode. This book is a valuable reference for novices or any programmer who is currently developing software on a 6502-based platform.

Fayzullin, Marat. “Nintendo Entertainment System Architecture.” Computer Emulation Resources by Marat Fayzullin. Marat Fayzullin, 2005. Web. 31 Jan. 2013. .

This online document diagrams the hardware architecture of the Nintendo Entertainment System (NES) excluding the 6502 CPU. Since the 6502 CPU has been extensively documented elsewhere on the Internet, the author decides to focus on the remaining hardware components of the NES motherboard. Before examining those components, the author gives a brief overview of the NES memory map. While stepping through the NES memory, the author describes how to manipulate the input/output ports, video controller (PPU), sound hardware, and memory switching circuits. Then, he dives into each component explaining how the memory has been mapped for joysticks, color palettes, sprites, etc. Also, the author includes a section about the Famicon Disk System (FDS), a NES extension released exclusively in Asia. However, the FDS will not be covered in the course curriculum. The document closes by explaining the .NES file format. The .NES file format is used to store images on the NES cartridges; this is important for deploying game projects to actual hardware instead of emulated environments.

Hanson, Kent. “Metriod Level Data Explained v1.01.” Metriod Database. Metriod Database, 2013. Web. 31 Jan. 2013. .

In this online document, the author reveals the intricate details of the game engine used in Metriod, a game developed by Nintendo and Intelligent Systems. Since the Metroid game engine supports complex systems for levels, collisions, and tiles, the author subdivides the document into three simple sections. The first section explains the visual process for creating level maps by combining small modular pieces into large environments. Part two covers how the individual pieces, or rooms, are designed using structure, tile, and object definitions. In the last section, the author presents a listing of the graphical components used in Metroid. This listing can serve as an extremely useful template for building your own level editor.

Iz-Tavares, Gregg, and Dan Chang. “Programming M.C. Kids.” Games.Greggman. Gregg Iz-Tavares, 2003. Web. 31 Jan. 2013. .

This online article outlines the development of M.C. Kids—an NES platform game loosely based on the McDonald’s fast-food franchise. The author begins by describing the technical differences between the vintage NES console and modern video game consoles. His opening outline summarizes the hardware capabilities of the NES while examining the vast improvements of modern gaming systems. Then, he begins to explain the working components of a platform game. After the brief introduction, the author elaborates on the storyline, design, and development of M.C. Kids. In the following portion of the article, the author includes extremely useful information on Page%32% data compression. Since the NES has so few memory resources, he provides numerous examples for reducing data consumption in M.C. Kids. The remaining article explains the complexities of M.C. Kids character animation, objects, collisions, and terrain. For an NES game developer exploring advanced design elements, this article provides invaluable insight on the creation of core game mechanics.

MacKenzie, I. Scott. The 68000 Microprocessor. Ed. Charles E. Stewart, Jr. New Jersey: Prentice Hall, 1995. Print.

For those seeking to broaden their knowledge of assembly languages, this textbook covering the 68000 microprocessor language should be highly recommended. Notably, the —and similar processors—dominated the 16-bit video game market in the era after the NES. Since the Motorola 68000 is primarily a 16-bit architecture, the author begins the textbook by explaining the differences between the 68000 and legacy architectures. Like other assembly language texts, the book then introduces the basics of data representation, memory locations, and number systems; however, the text also provides a new perspective for complex address resolution. Although the Motorola 68000 microprocessor lacks several features of modern processors, this book demonstrates how processors first began implementing modern designs like parallel processing and legacy modes. This book can effectively serve as college-level textbook, and it should be considered for future assembly courses seeking to target 16-bit video game consoles as target platforms.

Rost, Bob. Game Development for the 8-bit NES. Carnegie Mellon University, 2004. Web. 31 Jan. 2013. .

This online portal is the landing page for Bob Rost’s Game Development for the 8-bit NES. Bob Rost, a professor at Carnegie Mellon, taught this course on NES game development in the spring of 2004. On the web portal, he has provided archived to past presentations and course material used for the original class. The website also shares links to NES tools and development resources—Rost even created some of the resources especially for his course! To support the efforts of his prior students, Rost has embedded a download section listing the most successful class projects and games. Since the original course focused on a combination of assembly and high-level languages, Rost includes a link to his custom C language that may be used to develop NES games. Additionally, the site provides links to multiple NES emulators, ROMs, and code snippets. For students or teachers, this portal should be an immediate destination for supporting information on the NES, game development, and project ideas.

Watts, Lisa, and Mike Wharton. Introduction to for Beginners. London: Usborne Publishing Limited, 1983. Print.

In this short book, the topic of assembly languages is explored using quirky cartoons and full-color illustrations. For absolute beginners, this book is a necessity for quickly grasping the core concepts of assembly languages; however, for advanced programmers, this book may not provide any new, useful information. Instead of including lengthy chapters for each subject, this book provides short, insightful descriptions and focuses on the essential facts for programming. First, the book is divided into sections covering the basics of machine code, assembly commands, and Page%33% number systems. Then, the book provides colorful diagrams describing the internal structure of the 6502 and Z80 processor families. Finally, the book outlines the mnemonics for both 8-bit processors in easy-to-read tables. Again, for the novice programmer, this book can serve as a wonderful preparation for the college level assembly language course.

---. Programming the 6502. 4th ed. Berkeley: Sybex, 1983. Print.

Amongst the homebrew NES community, this book is considered the best programming reference for the 6502 assembly language. In this extensive self- contained book, the author covers the fundamentals of programming—writing, compiling, and executing—and the 6502 assembly language. Assuming no prior knowledge of programming or , this book may also serve as a textbook for any introductory programming course; however, for modern most curriculums, it is suggested to continue introducing programming concepts with languages like C or C++. More importantly, this book provides a clear explanation of memory organization in a computer. For example, where most texts avoid the technical details of hardware implementation, this book provides a robust description of the memory spaces, stacks, and addresses. Additionally, a section is included on the CPU execution cycle and binary coded decimal (BCD)—a feature not supported by the NES flavor of the 6502. For the serious programmer, this book should be used throughout the curriculum, and it should also serve as a reference for future low-level hardware courses.