liveBook · Manning

Low byte

As explained in Classic Game Programming on the NES: Make your own retro video game

A low byte is the less significant eight-bit portion of a multi-byte numeric value.

A low byte is the less significant eight-bit portion of a multi-byte numeric value. In a 16-bit address, it is stored separately from the high byte; 6502 systems commonly place the low byte first. section 3.3.1 section 6.3

Use the low byte when splitting or reconstructing a 16-bit address:

  • Extract it with the assembler's < symbol, as in lda #<value. section 6.3
  • Store it at the first byte of a two-byte zero-page address, then store the high byte at the next location. section 3.3.1 section 6.3
  • Write the low byte first when setting the NES PPU address register, followed by the high byte. section 6.3

Assigning a 16-bit address

For assign_16i dest, value, lda #<value loads the low byte and stores it at dest+0. Then lda #>value loads the high byte and stores it at dest+1. Passing $2000 therefore expands into separate byte operations while keeping the call compact. section 6.3

Listing 6.6 Starting a macros file (macros.s)
.macro vram_set_address newaddress

  lda PPU_STATUS
  lda #>newaddress
  sta PPU_VRAM_ADDRESS2
  lda #<newaddress
  sta PPU_VRAM_ADDRESS2

.endmacro

Inspect the macro that extracts the low and high bytes of a supplied address before writing them to the PPU. section 6.3

How Classic Game Programming on the NES: Make your own retro video game covers it

How deep it goes
Explains byte ordering and assembler extraction, then applies them in reusable address-setting macros.
Examples
Uses $0300 pointers, $2000 PPU addressing, and assign_16i and vram_set_address macro listings.
What it assumes
Assumes basic 6502 registers and memory addressing while demonstrating zero-page pointers and 16-bit address handling.
What you can do after
Build it from scratch by splitting 16-bit addresses and storing or writing their low bytes with 6502 assembler syntax.
How it connects
Connects 16-bit addresses with high bytes, zero-page memory, assembler macros, and NES PPU addressing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Classic Game Programming on the NES: Make your own retro video game. The section links point to the parts of the book it draws on.