Table of Contents

COMPORG COURSE NOTES

Course Notes Wiki

This is a space for members of the Computer Organization class to create a source of information reflective and assisting to the course.

Aside from assignments that may have you specifically perform operations here, you should contribute when you encounter any of the following:

NES ROMs

Want to play the NES ROMs on your own system? You can download them here

For web-based play, I am using jsNES, a javascript NES emulator.

January 22, 2019

Back in the day, there used to be giant computers, and the reason these things were so huge, is because the switches that ran the logic were about the size of light switches, and you need around a million of those in a computer. Therefore, big switches equals big computer. People (from AT&T) eventually discovered a way to make these switches smaller and more reliable through the use of transistors. These didn't require the actual flipping up and down like a light switch, so they could last longer. That is how we got computers we can put on our laps!

For our project this upcoming semester, we will need to have a significant understanding on how the NES does what it does. Firstly, we'll need to understand the language “6502 assembly”, which the NES understands. For the video portion of our experiments, we'll be using 8×8 images as well as only having the selection of 3 colors. Be careful with the background of the program, it may be more difficult applying color than it is with sprites. As for sound, FamiTracker is a good recommendation for 8-bit music that will work well with our plans.

January 29th, 2019

Definitions:

cpp - c preprocessor that does general analysis of code and makes substitutions for intermediary between the coder and the computer.

mednafen:

nes:

Interrupts:

6502 Assembly Terms

There are three main registers used, one for doing basically anything, and two for temporarily storing information.

Compiling

February 7th, 2019

Pseudo-random number generation:

A technique for PRNG is to have the hardware cycle through thousands of randomly-generated numbers, where each call to the PRNG updates the number, with a seed initialized at the beginning of the game. Below is an example of such a function in 6502 assembly. The seed only needs to be set once, and it will always return an unsigned byte.

;prng.s

;Add variable and function to Zeropage
.export _Prng
.exportzp _Seed

.segment "ZEROPAGE"
_Seed: .res 2 ;Equivalent of an unsigned short

.segment "CODE"
_Prng:
  ldx #8 ;Iterate 8 times
  lda _Seed+0 ;Load first byte of seed to alter
:
  asl
  rol _Seed+1
  bcc :+
  eor #$2D ;Shift bits and XOR register value
:
  dex
  bne :--
  sta _Seed+0 ;Return first byte in seed as random number
  cmp #0
  rts ;Return

To add it to the toolchain, create a header file and include it in your program, while being sure to assemble it in your Makefile. An example header file:

//prng.h

#ifndef PRNG_H_
#define PRNG_H_

#include <stdint.h>

extern uint16_t Seed;
#pragma zpsym("Seed");

uint8_t Prng(void);

#endif

Remember to set your seed in the beginning of your program. Calls to the Prng will return a random byte, but manipulating said byte could produce a specified range of outcomes you desire.

February 13th, 2019

PPU OAM, or Object Attribute Memory is memory inside of the PPU that can store up to 64 sprites' information inside 4 bytes each. The first byte, or Byte 0, is used for referring to the positioning of the top of the referred sprite in the y axis. Byte 1 is more focused on where the sprite exists on the pattern table. The bits in Byte 2 can be used to do a variety of attribute shifting to the sprite including flipping it on the x and y axis, setting the priority of the image in comparison to the background, the palette of the sprite, and much more! Byte 3 wraps things up with the x - coordinate of the left side of the sprite. To determine whether a sprite will be on top or underneath another, look at the addresses in comparison to one another. The sprite data that occurs first in OAM will be the one that appears in the front.

February 14th, 2019

A carry is when you want to perform a mathematical operation, and the result goes above 255. The carry flag basically just says that there is an additional bit set to 1 in the stored value. This is necessary since the accumulator only holds 8-bit values. Carry flag allows you to do MOAR!!!

Game Creation Project Guidelines

Portal Kombat

Created by Stephen This will be a primitive form of Mortal Kombat… but with portals!

Boss Breaker

Progess:
Minions: Done
Bosses: Done
Players: Done
Score/Health: Done
Win/Game Over: Done
Menu: Done
Music: DONE, just add custom song

To-do:
Secrets Medals

Brain Storm

Lancer

Asteroids by Dylan & Billy

Premise

Earth is being assaulted by asteroids and, as the main character, it's your duty to protect it. With your state of the art space ship and cannons, you can blow the asteroids into small bits that can burn up in Earth's atmosphere.

Mechanical Process

Earth is seen at the bottom of the screen with your space ship positioned directly above it. Once start is pressed, the asteroids will start hurdling towards Earth from the top of the screen progressively quicker and quicker. You can use the directional keys to move around, and B to shoot at the asteroids above. The asteroids are set to a main asteroid clock that shoots the asteroids in increasingly difficult speeds. With a random number generator, an element of unpredictability is added as well. At the same time, obstacles such as satellites will be moving horizontally across the screen. These will block your fire as well as your movement. However, there will be powerups that may spawn that you'll only have to shoot to acquire!

Point System
Game Mode
power-up types
  1. Shot delay decrease
  2. screen clear
  3. ship speed increase
  4. Heals

Bug Corner

Post bugs here, either debugged bugs that you feel might pop up for others, or current bugs pending debugging.

Generic Bugs

Found a bug with hit detection.

When checking Input1 for Player1, cannot reference arithmetic regarding player2.

An example would be:

player1.x > player2.x + SPRITE_WIDTH

This will soft-lock the game upon running an if-statement containing this. However:

player1.x - SPRITE_WIDTH > player2.x

will work, and is identical in functionality. Will report back if I figure out the exact problem, and if it will work the same way with Player2's collision detection.

Game Specific Bugs

Programming Considerations

Due to the restrictive nature of the NES hardware, some “common sense” programming optimizations we would usually make are impractical here.

For example: arrays. For NES programming, especially when dealing with lots of sprites, it seems counter-intuitive, but we may want to avoid using arrays, because it actually causes a lot more work for the 6502 CPU in the NES. See this forum post for some further explanation (and some other solutions):

We have to remember: NES programming, even with the benefit of C, is NOT going to be a clean, efficient endeavor. There will be messiness. This is but one example.

Some related resources talking about programming considerations due to the hardware:

Variables

Due to the limitations of the hardware, making variables as small as possible is a common consideration. Many read/write variables, such as the X/Y coordinates of sprites, use the “uint8_t” variable type, which corresponds to an “unsigned char” under normal circumstances. Make note of the variable's maximum and minimum values, as overflows and underflows can go undetected.

Login Problems

Some people have reported problems logging into the wiki. There seems to be two sources of problems experienced:

If you are confident you are using the correct username and password, and are using a version of Internet Explorer, it is suggested that you use a different browser, such as Firefox, Safari, or Chrome.

If the “Secure Login” doesn't seem to be working for you, the behavior seems to occur when user passwords contain symbols like quote marks and asterisks. In which case, you can either:

Syntax

For those unfamiliar, here is a page on wiki editing syntax that can be used here.

DokuWiki wrap plugin

http://www.dokuwiki.org/_media/plugin:wrap_plugin_example2.png