Pages

20181030

Easy 6502

Easy 6502

  • Assembly language is the lowest level of abstraction in computers -- the point at which the code is still readable.
  • Assembly language translates directly to the bytes that are executed by your computer's processor.
  • SP is the stack pointer.
  • PC is the program counter--it's how the processor knows at what point in the program it currently is. Its like the current line number of an executing script.
  • Instructions in assembly language are like a small set of predefined functions.
  • The zero flag is set by all instructions where the result is zero.
  • In assembly language, you'll usually use labels with branch instructions. When assembled though, this label is converted to a single-byte relative offset (a number of bytes to go backwards or forwards from the next instruction) so branch instructions can only go forward and back around 256 bytes.
  • Remember that a byte is represented by two hex characters.
  • The stack in a 6502 processor is just like any other stack--values are pushed onto it and popped of it. The current depth of the stack is measured by the stack pointer, a special register.
  • JMP is an unconditional jump.
  • JSR and RTS ("jump to subroutine" and "return from subroutine") are a dynamic duo that you'll usually see used together. JSR is used to jump from the current location to another part of the code. RTS returns to the previous position. This is basically like calling a function and returning.
  • The processor knows where to return to because JSR pushes the address minus one of the next instruction onto the stack before jumping to the given location. RTS pops this location, adds one to it, and jumps to it.
  • We can define descriptive constants (or symbols) that represent numbers. The rest of the code can then simply use the constants instead of the literal number, which immediately makes it obvious what we're dealing with.
  • Nearly all games have at their heart a game loop. All game loops have the same basic form: accept user input, update the game state, and render the game state.

No comments:

Post a Comment