User Tools

Site Tools


notes:comporg:spring2019

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:

  • Some neat bit of information related to the class
  • Some clarification or understanding you've had with respect to concepts in the class
  • Organizational/style improvements to existing content
  • Questions you have that may deserve a more visual answer

NES ROMs

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:

  • At the moment, mednafen needs an additional command “rm -rf ~/.mednafen” before the actual call of mednafen
  • speaking of, mednafen loads up differently from nestopia as mednafen requires the nes file that is meant to be loaded in addition to the command to start mednafen
  • alt-d for the debugger in game
  • alt-shift-1 to input controller buttons for player 1 (for a second player, type a 2 instead of a 1)

nes:

  • hardware: can read 32 kB cartridge ROM at a time

Interrupts:

  • an interrupt vector is an input used to get the computer's attention ie pressing a button
  • the reset.s file that we've seen is an interrupt vector itself
6502 Assembly Terms
  • ADC - add accumulator with carry, adds two values
  • AND - logical and operator
  • ASL - Arithmetic Shift Left, shifts all bits one to the left
  • BCC - Branch if Carry Clear, If carry flag is clear branch to a new location
  • BCS - Branch if Carry Set, If carry exists, branch to a new location
  • BEQ - Branch if Equal, if Zero flag exists, branch
  • BIT - Test if pits are set in a memory location
  • BMI - Branch if Minus, If negative flag is set, branch
  • BNE - Branch if Not Equal, If zero flag is clear, branch
  • BPL - Branch if Positive, if negative flag is clear, branch
  • BRK - Break (Force Interrupt), Break flag set to 1
  • BVC - Branch if overflow clear, if overflow flag is clear, branch
  • BVS - Branch if overflow set, if overflow flag is set, branch
  • CLC - Clear Carry, sets carry flag to zero
  • CLD - Clear Decimal Mode, set decimal mode flag to 0
  • CLI - Clear interrupt disable, clears the interrupt disable flag
  • CLV - Clear Overflow Flag, V = 0
  • CMP - Compare, compares contents of accumulator to another memory value
    • Sets Carry flag if A >= M
  • Sets Zero flag if A == M
  • Sets Negative flag if bit 7 is set
  • CPX - Compare X Register, compares X register to memory value
  • CPY - Compare Y Register, compares Y register to memory value
  • DEC - Decrement Memory, Subtracts one from the value held at mem location
  • DEX - Decrement X register, Subtract one from X Register
  • DEY - Decrement Y Register, Subtract one from Y Register
  • EOR - Exclusive Or
  • INC - Increment memory, Adds one to the memory value
  • INX - Increment x Register
  • INY - Increment Y register
  • JMP - Unconditional Jump, will always happen
  • JSR - Jump to Subroutine
  • LDA - Load Accumulator, loads a value from accumulator
  • LDX - Load X Register
  • LDY - Load Y Register
  • LSR - Logical Shift Right, Bits in A and M are shifter one to the right
    • The Zero bit is set to Carry
  • NOP - No Operation, No changes
  • ORA - Logical Inclusive Or, Inclusive Or with A and M
  • PHA - Push Accumulator, Puts a copy of the accumulator onto the stack
  • PHP - Push Processor Status, Puts status flags onto the stack
  • PLA - Pull Accumulator, Pulls a value from the stack into the accumulator
  • PLP - Pull Processor Status, Sets flags from stack values
  • ROL - Rotate Left, shift everything in A or M to the left
  • Carry flag is set to bit 7
    • Bit 0 is filled with the current carry flag
  • ROR - Rotate Right, Shift everything in A or M to the right
  • Carry flag is set to old bit 0
    • bit 7 is filled with Carry flag
  • RTI - Return from interrupt, at end of interrupt processing routine
    • Sets all flags from stack
  • RTS - Return from Subroutine, at the end of a subroutine, return to call
  • STC - Subtract with Carry, subtracts the contents of a memory to accumulator
  • SEC - Set Carry Flag, Set Carry flag to one
  • SED - Set Decimal flag, Set Decimal Flag to one
  • SEI - Set Interrupt Disable, Set Interrupt Disable Flag to one
  • STA - Store Accumulator, Store accumulator contents to memory
  • STX - Store X Register, Store X register to memory
  • STY - Store Y Register, Store Y register to memory
  • TAX - Transfer Accumulator to X, Copies Acc to X register
  • TAY - Transfer Accumulator to Y, Copies Acc to Y register
  • TSX - transfer Stack pointer to X, Copies current stack contents to X
  • TSA - transfer Stack pointer to Accumulator, Copies current stack contents to Acc
  • TSX - Transfer X to Stack, copies X contents into the stack
  • TYA - Transfer Y to Accumulator, Copies Y contents into the Acc

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

Compiling

  • cc65 -Oi filename.c –add-source
  • ca65 filename.s
  • ca65 reset.s
  • ld65 -C filename.cfg -o filename.nes reset.o filename.o nes.lib

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

  • First one can be written in assembly or C
  • Can be one or Two Player
  • Nothing more complicated than simple early games like Pac-Man
  • Can be done alone or in groups
  • Our Projects
    • Rana and Mike - Brain storm, zombie tower defense
    • Jimito - Boss Breaker: Every level is a Boss fight
    • Josh - Lancer: Medieval tag with pointy sticks!
    • Stephen - Portal Kombat: Two player Mayhem!
    • a
    • a
    • a
    • a

Portal Kombat

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

  • TODO
    • New sprites x
    • Walls
    • Portals!
      • Build portals x
      • Set up teleportation logic x
    • Attack
      • Make weapons appear and move x
      • Collision detection (Yippee) x
      • Score
      • Life x
    • Title Screen
      • Choose character x
      • P1 & P2 x
    • End Game Stuff
      • Life decreasing x
      • FINISH HIM! x
    • Bonus stuff
      • Restarting x
      • Second level
      • Change the way Thing attack works (Now the Thing's weapon is twice as fast!!)x
      • Show character names when arrow is over the sprite x

Boss Breaker

  • Jimito
  • Game concept: Every level is a Boss, Bullet-hell, Shooter
  • Boss ideas
    1. SWARM: alien mass attacks, while the boss slowly grows
    2. Forger: fire scatters about the screen, while the forger makes an arsenal
    3. Factory: machines make robots to defend, while boss is built

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

  • Rana and Mike
  • concept : Plants Vs zombies style tower defense
  • player protects the brain from zombies trying to eat it
  • If zombies reach the far left of the screen the brain's health goes down every tick until it reaches zero - lose condition
  • Win if successfully defending for three waves
  • Power Ups
    • heal the brain a little (Heart)
  • Zombies
    • 2x sizes to start off, little ones and boss ones
    • maybe different colors based on difficulty
  • Brain Wave
    • Player Projectiles, maybe just little “>“s or something

Lancer

  • Joshua
  • Main concept: 2 players chasing each other around, trying to hit the sides/back of the other sprite until an arbitrary score is achieved
  • side concepts: PowerUps, multiple arenas, hazards, platformer mode (stretch goal).
  • Controls: 4 directional movement with the d-pad(diagonal presents problems with hit detection), sprint with the B button (1 ppf vs 3 ppf(pixels per frame) movement speed), A for powerups (displayed in upper left corner for player 1, upper right corner for player 2).

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
  • Destroyed asteroid: +10
  • Missed missile: -1
  • Damaged satellite: -10
  • (Co-op)Damaged opposing player: +5
Game Mode
  • 2 player allows the game to have 3 separate game modes:
  • Classic 1 player run to save the world!
  • 2 player versus: The 2nd player plays as an aggressive space invader with the quest to annihilate Earth.
  • 2 player co-op: The 2nd player assists the 1st by joining the fray to protect humanity.
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:

  • User cannot log in.
  • User cannot log in using “Secure Login”.

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:

  • Uncheck “Use Secure Login”. This sort of defeats the purpose of having security though, so it isn't outwardly recommended.
  • Change your password to something that doesn't contain quote marks or asterisks. We don't yet know exactly which characters cause this problem, but we suspect it is characters that aren't being properly escaped that could have special syntactical meaning.

Syntax

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

DokuWiki wrap plugin

notes/comporg/spring2019.txt · Last modified: 2020/01/20 11:08 by wedge