mirror of
https://github.com/imjasonh/nescript
synced 2026-07-09 09:18:01 +00:00
linker: test that BackgroundData::chr_bytes lands at chr_base_tile
Adds a focused unit test that constructs a `SpriteData` at tile 1 and a `BackgroundData` whose `chr_bytes` claim tiles 5-6, then verifies the linker's CHR ROM placement preserves the smiley at tile 0, the sprite at tile 1, leaves tiles 2-4 untouched, and copies the background blob at the requested base offset. Catches any future regression in the `BackgroundData::chr_base_tile` → CHR ROM splice that `assets: auto-generate CHR data from @nametable() PNG sources` introduced. https://claude.ai/code/session_01KEczoNUX3WmcFLfq6iAQxB
This commit is contained in:
parent
6501f105bd
commit
45bb84dddc
1 changed files with 50 additions and 0 deletions
|
|
@ -130,6 +130,56 @@ fn link_with_sprites_spanning_multiple_tiles() {
|
|||
assert_eq!(placed, sprite_bytes.as_slice());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn link_with_background_chr_places_blob_after_sprites() {
|
||||
// A `BackgroundData` carrying its own CHR data should drop
|
||||
// the bytes into CHR ROM at `chr_base_tile * 16`. The
|
||||
// linker must NOT touch any earlier tiles (the smiley at
|
||||
// tile 0 plus any sprites). We seed a sprite at tile 1 and
|
||||
// a background at tile 5, then verify the linker placed
|
||||
// both blobs at their expected offsets.
|
||||
let linker = Linker::new(Mirroring::Horizontal);
|
||||
let user_code = vec![Instruction::implied(NOP)];
|
||||
let sprite_bytes: Vec<u8> = vec![0xAA; 16]; // tile 1
|
||||
let bg_chr: Vec<u8> = (0..32).map(|i| i as u8).collect(); // tiles 5, 6
|
||||
let sprites = vec![SpriteData {
|
||||
name: "Player".into(),
|
||||
tile_index: 1,
|
||||
chr_bytes: sprite_bytes.clone(),
|
||||
}];
|
||||
let backgrounds = vec![crate::assets::BackgroundData {
|
||||
name: "Stage".into(),
|
||||
tiles: [5u8; 960],
|
||||
attrs: [0u8; 64],
|
||||
chr_bytes: bg_chr.clone(),
|
||||
chr_base_tile: 5,
|
||||
}];
|
||||
let rom = linker.link_banked_with_ppu(&user_code, &sprites, &[], &[], &[], &backgrounds, &[]);
|
||||
let chr_start = 16 + 16384;
|
||||
// Sprite bytes still at tile 1.
|
||||
assert_eq!(
|
||||
&rom[chr_start + 16..chr_start + 32],
|
||||
sprite_bytes.as_slice(),
|
||||
"sprite tile bytes should survive the background CHR splice"
|
||||
);
|
||||
// Background CHR at tile 5 (offset 80).
|
||||
assert_eq!(
|
||||
&rom[chr_start + 80..chr_start + 80 + 32],
|
||||
bg_chr.as_slice(),
|
||||
"background CHR bytes should land at chr_base_tile * 16"
|
||||
);
|
||||
// Tiles 2/3/4 should still be all zeros — the linker mustn't
|
||||
// shadow the gap between the sprite tile and the background.
|
||||
for tile in 2..5usize {
|
||||
let off = chr_start + tile * 16;
|
||||
assert_eq!(
|
||||
&rom[off..off + 16],
|
||||
&[0u8; 16],
|
||||
"tile {tile} should remain zero between sprite and background"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn link_splices_audio_tick_when_user_marker_present() {
|
||||
// When user code contains the `__audio_used` marker label (the
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue