Created
June 26, 2021 14:57
-
-
Save ITotalJustice/ad1f930a1e64aae90b2ce056691d9fae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void render_scanline_bg_simple(struct NES_Core* nes, uint8_t line) | |
{ | |
const uint8_t row = (line >> 3) & 31; | |
const uint8_t fine_line = line & 7; | |
const uint16_t pattern_table_addr = ppu_get_bg_pattern_table_addr(nes); | |
uint16_t nametable_addr = ppu_get_nametable_addr(nes) + (row * 32); | |
for (uint8_t col = 0; col < 32; ++col) | |
{ | |
const uint8_t tile_num = nes_ppu_read(nes, nametable_addr++); | |
const uint8_t bit_plane0 = nes->cart.chr_rom[pattern_table_addr + fine_line + (tile_num * 16) + 0]; | |
const uint8_t bit_plane1 = nes->cart.chr_rom[pattern_table_addr + fine_line + (tile_num * 16) + 8]; | |
const uint8_t full = bit_plane0 | bit_plane1; | |
for (uint8_t x = 0; x < 8; ++x) | |
{ | |
const uint8_t bit = 1 << (7 - x); | |
const uint32_t colour = (full & bit) ? 0xAAAAAAAA : 0; | |
ppu_write_pixel(nes, colour, (col * 8) + x, line); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment