This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Nerdy Nights: couple of questions

Nerdy Nights: couple of questions
by on (#94257)
Well, i've been following the Nerdy Nights tutorials and i have a couple of questions that you guys might be able to help me. :)
  • Using the LSR/ROL technique for reading controllers is nice... but how do i actually get the value from each button in order to execute an action? ANDing the bits?
  • CLC clears the carry, but SEC actually does what? Set the carry to 0? Tell the assembler to expect a carry? What if i don't use it?
  • BNE and BQE confuse me. They're doing their comparison to which value? The one stored in the accumulator? Or X? Or Y?
  • The last two bits of the sprite attributes byte are the palette. But what does it mean? If i choose the number 22, that's the second color of second palette? Or second color of both palettes?
  • How does banking actually work? I see the adresses but i don't really know WHY they must be that number. Where should each bank go inside my memory and why? Inside or outside the 2KB RAM?
Re: Nerdy Nights: couple of questions
by on (#94262)
vicious wrote:
Well, i've been following the Nerdy Nights tutorials and i have a couple of questions that you guys might be able to help me. :)
  • Using the LSR/ROL technique for reading controllers is nice... but how do i actually get the value from each button in order to execute an action? ANDing the bits?


Yes, you AND the bits. Something like lda joypadstate \ AND #$01 would test the A button.
Note that this tells you what buttons are currently held down. If you want to find out which buttons have become pressed, you XOR the old buttons with new buttons, then AND with the new buttons.

Quote:
  • CLC clears the carry, but SEC actually does what? Set the carry to 0? Tell the assembler to expect a carry? What if i don't use it?


  • There are status flags. They change after executing certain instructions. Almost all instructions affect the Zero and "Negative" flags, but add, subtract, and compare instructions will also affect the Carry flag.
    SEC and CLC allow you to directly change the Carry flag.

    Quote:
  • BNE and BQE confuse me. They're doing their comparison to which value? The one stored in the accumulator? Or X? Or Y?


  • BNE and BEQ use the Zero flag to determine whether to jump or not. EQ means zero, NE means not zero.
    The zero flag gets set to zero after the result of most instructions is zero. Even loading from memory into the X or Y register changes the zero flag.
    When you do a compare instruction (CMP, CPX, CPY), it's called "EQ" or "NE" because comparing is really subtracting. When you subtract two equal values, you get zero, so the Zero flag is set appropriately.

    Quote:
  • The last two bits of the sprite attributes byte are the palette. But what does it mean? If i choose the number 22, that's the second color of second palette? Or second color of both palettes?


  • Last two bits let you select from palettes 0,1,2,3. 4 colors each, for the full 16 palette.

    Quote:
  • How does banking actually work? I see the adresses but i don't really know WHY they must be that number. Where should each bank go inside my memory and why? Inside or outside the 2KB RAM?


  • Banking works by rerouting the address lines on the cartridge and chips.
    The system sees 64KB of total memory, that's 16 address bits. Normally, 32k goes to the cartridge PRG ROM. But a memory chip may be larger than 32K, so some address bits get ignored, then the mapper fills in the rest.
    *maybe rewrite this part later

    by on (#94264)
    Couldn't be more clear. Thank you very much, Dwedit. :D

    by on (#94267)
    Whenever I'm unsure about which instructions set which flags, I look it up here:
    http://www.obelisk.demon.co.uk/6502/reference.html

    It has a full description of how every flag is set. The Z flag is pretty straightforward usually, but I often forget the details of the others.

    by on (#94281)
    Where are palettes set? I see the .db directives, but they set an entire palette, not one comprised of 4 colors.

    by on (#94307)
    Palettes are memory in the PPU that you must copy those bytes to.

    http://wiki.nesdev.com/w/index.php/PPU_palettes

    To upload data to the PPU's memory see:

    http://wiki.nesdev.com/w/index.php/PPU_registers

    Specifically $2002, $2006, and $2007.