Skip to content
This repository was archived by the owner on Jan 31, 2023. It is now read-only.

Commit 539e90c

Browse files
committed
Add sprite horizontal / vertical reverse
1 parent fcad65c commit 539e90c

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

roms/nestest.nes

24 KB
Binary file not shown.

src/nes/renderer/mod.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,40 @@ pub fn render(background: &BackgroundField, sprites: &SpritesWithCtx) {
2222
fn render_background(buf: &mut Vec<u8>, background: &BackgroundField) {
2323
for (i, bg) in background.into_iter().enumerate() {
2424
let x = (i % 33) * 8;
25-
let y = (i / 33) * 8;
25+
let y = (i / 33) * 8;
2626
render_tile(buf, bg, x, y);
2727
}
2828
}
2929

3030
fn render_sprites(buf: &mut Vec<u8>, sprites: &SpritesWithCtx) {
3131
for sprite in sprites {
32-
render_sprite(buf, &sprite.sprite, &sprite.position, &sprite.palette);
32+
render_sprite(buf,
33+
&sprite.sprite,
34+
&sprite.position,
35+
&sprite.palette,
36+
sprite.attr);
3337
}
3438
}
3539

3640
fn render_sprite(data: &mut Vec<u8>,
3741
sprite: &Sprite,
3842
position: &SpritePosition,
39-
palette: &PaletteList) {
43+
palette: &PaletteList,
44+
attr: u8) {
45+
let is_vertical_reverse = (attr & 0x80) == 0x80;
46+
let is_horizontal_reverse = (attr & 0x40) == 0x40;
47+
let is_low_priority = (attr & 0x20) == 0x20;
48+
let palette_id = attr & 0x03;
4049
for i in 0..8 {
4150
for j in 0..8 {
51+
let x = position.0 as usize + if is_horizontal_reverse { 7 - j } else { j };
52+
let y = position.1 as usize + if is_vertical_reverse { 7 - i } else { i };
53+
// if is_low_priority && this.shouldPixelHide(x, y)) {
54+
// continue;
55+
// }
4256
if sprite[i][j] != 0 {
4357
let color_id = palette[sprite[i][j] as usize];
4458
let color = COLORS[color_id as usize];
45-
let x = position.0 as usize + j;
46-
let y = position.1 as usize + i;
4759
let index = (x + (y * 0x100)) * 4;
4860
data[index] = color.0;
4961
data[index + 1] = color.1;

0 commit comments

Comments
 (0)