debug_draw.c
// XXX: temporary workaround
// static bool show_attributes = false;
temporary workaround
static bool show_attributes = false.
temporary workaround static bool show_attributes = false .
int debug_draw_nametable(ppu_t *ppu, uint32_t *lut, uint32_t *argb)
{
#if 0
    uint8_t *palette = ppu->map.palette.image;
    for (int page = 0; page < 4; ++page) {
        int py = page / 2 * 240;
        int px = (page % 2) * 256;
        for (int ty = 0; ty < 30; ++ty) {
            for (int tx = 0; tx < 32; ++tx) {
                uint16_t vram_offset =
                    ppu_fetch_nt_vram_offset(ppu, px + tx * 8, py + ty * 8);
                uint16_t tile_offset = ppu_fetch_tile_offset(ppu, vram_offset);
                uint16_t attr_base = (vram_offset & ~1023) + 0x3C0;
                uint8_t *tile = ppu->shared_mapper->on_chr_read(
                    ppu->shared_mapper, tile_offset);
                for (int y = 0; y < 8; ++y) {
                    uint8_t bits0 = tile[y];
                    uint8_t bits1 = tile[y + 8];
                    int bg_y = py + (ty * 8 + y);
                    for (int x = 7; x >= 0; --x) {
                        int bg_x = px + (tx * 8 + x);
                        int idx = (bits0 & 1) | ((bits1 & 1) << 1);
                        uint8_t ax = bg_x & 0xFF;
                        uint8_t ay = bg_y % 240;
                        uint16_t attr_offset =
                            attr_base + (ax >> 5) + ((ay >> 5) << 3);
                        uint8_t attr = ppu->map.vram[attr_offset];
                        uint8_t palette_high =
                            (attr >>
                             (((!!((ax & 0x10)) | (!!(ay & 0x10) << 1)) * 2))) &
                            0x3;
                        uint32_t color;
                        if (show_attributes) {
                            color = lut[palette[(palette_high << 2) |
                                                ((x > 3) | ((y > 3) << 1))]];
                        } else {
                            color = lut[palette[(palette_high << 2) | idx]];
                        }
                        argb[(ty * 8 + y + 240 * (page / 2)) * 512 +
                             ((page % 2) * 256) + tx * 8 + x] = color;
                        bits0 >>= 1;
                        bits1 >>= 1;
                    }
                }
            }
        }
    }
    { 
        for (int y = 0; y < 240; ++y) {
            int sx = ppu->raster_x[y];
            int sy = ppu->raster_y[y];
            argb[(sy % 480) * 512 + (sx % 512)] = 0xFF00FF00;
            argb[(sy % 480) * 512 + (sx + 256) % 512] = 0xFF00FF00;
        }
        for (int x = 0; x < 256; ++x) {
            argb[ppu->raster_y[0] * 512 + (ppu->raster_x[0] + x) % 512] =
                0xFF00FF00;
            argb[(ppu->raster_y[239] % 480) * 512 +
                 (ppu->raster_x[239] + x) % 512] = 0xFF00FF00;
        }
    }
    { 
        int sx = ppu->map.sprite_attrs[0].x;
        int sy = ppu->map.sprite_attrs[0].y;
        int h = ppu->reg.ctrl.sprite_size ? 15 : 7;
        for (int y = 0; y < h; ++y) {
            argb[((sy + y) % 480) * 512 + sx] = 0xFFFF0000;
            argb[((sy + y) % 480) * 512 + (sx + 7) % 512] = 0xFFFF0000;
        }
        for (int x = 0; x < 8; ++x) {
            argb[sy * 512 + (sx + x) % 512] = 0xFFFF0000;
            argb[((sy + h) % 480) * 512 + (sx + x) % 512] = 0xFFFF0000;
        }
    }
#endif
    return SUCCESS;
}
int debug_draw_nametable ( ppu_t * ppu , uint32_t * lut , uint32_t * argb ) { #if 0 uint8_t * palette = ppu -> map . palette . image ; for ( int page = 0 ; page < 4 ; ++ page ) { int py = page / 2 * 240 ; int px = ( page % 2 ) * 256 ; for ( int ty = 0 ; ty < 30 ; ++ ty ) { for ( int tx = 0 ; tx < 32 ; ++ tx ) { uint16_t vram_offset = ppu_fetch_nt_vram_offset ( ppu , px + tx * 8 , py + ty * 8 ) ; uint16_t tile_offset = ppu_fetch_tile_offset ( ppu , vram_offset ) ; uint16_t attr_base = ( vram_offset & ~ 1023 ) + 0x3C0 ; uint8_t * tile = ppu -> shared_mapper -> on_chr_read ( ppu -> shared_mapper , tile_offset ) ; for ( int y = 0 ; y < 8 ; ++ y ) { uint8_t bits0 = tile [ y ] ; uint8_t bits1 = tile [ y + 8 ] ; int bg_y = py + ( ty * 8 + y ) ; for ( int x = 7 ; x >= 0 ; -- x ) { int bg_x = px + ( tx * 8 + x ) ; int idx = ( bits0 & 1 ) | ( ( bits1 & 1 ) << 1 ) ; uint8_t ax = bg_x & 0xFF ; uint8_t ay = bg_y % 240 ; uint16_t attr_offset = attr_base + ( ax >> 5 ) + ( ( ay >> 5 ) << 3 ) ; uint8_t attr = ppu -> map . vram [ attr_offset ] ; uint8_t palette_high = ( attr >> ( ( ( ! ! ( ( ax & 0x10 ) ) | ( ! ! ( ay & 0x10 ) << 1 ) ) * 2 ) ) ) & 0x3 ; uint32_t color ; if ( show_attributes ) { color = lut [ palette [ ( palette_high << 2 ) | ( ( x > 3 ) | ( ( y > 3 ) << 1 ) ) ] ] ; } else { color = lut [ palette [ ( palette_high << 2 ) | idx ] ] ; } argb [ ( ty * 8 + y + 240 * ( page / 2 ) ) * 512 + ( ( page % 2 ) * 256 ) + tx * 8 + x ] = color ; bits0 >>= 1 ; bits1 >>= 1 ; } } } } } { for ( int y = 0 ; y < 240 ; ++ y ) { int sx = ppu -> raster_x [ y ] ; int sy = ppu -> raster_y [ y ] ; argb [ ( sy % 480 ) * 512 + ( sx % 512 ) ] = 0xFF00FF00 ; argb [ ( sy % 480 ) * 512 + ( sx + 256 ) % 512 ] = 0xFF00FF00 ; } for ( int x = 0 ; x < 256 ; ++ x ) { argb [ ppu -> raster_y [ 0 ] * 512 + ( ppu -> raster_x [ 0 ] + x ) % 512 ] = 0xFF00FF00 ; argb [ ( ppu -> raster_y [ 239 ] % 480 ) * 512 + ( ppu -> raster_x [ 239 ] + x ) % 512 ] = 0xFF00FF00 ; } } { int sx = ppu -> map . sprite_attrs [ 0 ] . x ; int sy = ppu -> map . sprite_attrs [ 0 ] . y ; int h = ppu -> reg . ctrl . sprite_size ? 15 : 7 ; for ( int y = 0 ; y < h ; ++ y ) { argb [ ( ( sy + y ) % 480 ) * 512 + sx ] = 0xFFFF0000 ; argb [ ( ( sy + y ) % 480 ) * 512 + ( sx + 7 ) % 512 ] = 0xFFFF0000 ; } for ( int x = 0 ; x < 8 ; ++ x ) { argb [ sy * 512 + ( sx + x ) % 512 ] = 0xFFFF0000 ; argb [ ( ( sy + h ) % 480 ) * 512 + ( sx + x ) % 512 ] = 0xFFFF0000 ; } } #endif return SUCCESS ; }
XXX: temporary workaround
static bool show_attributes = false;
XXX : temporary workaround static bool show_attributes = false ;
// uint8_t *table = &ppu->map.tables[page]; // highlight scroll window // int sx = ppu->raster_x[y]; // int sy = ppu->raster_y[y]; // highlight sprite 0