Slightly improve code quality
This commit is contained in:
parent
28be6356f2
commit
6b116d2592
|
@ -74,9 +74,9 @@ fn init_window(event_loop: &EventLoop<()>) -> Window {
|
|||
fn draw(chip8_gfx: &[u8], frame: &mut [u8]) {
|
||||
for (i, pixel) in frame.chunks_exact_mut(4).enumerate() {
|
||||
let rgba = if chip8_gfx[i] == 1 {
|
||||
[0xFF, 0xFF, 0xFF, 0xFF]
|
||||
[0xFF; 4]
|
||||
} else {
|
||||
[0x00, 0x00, 0x00, 0xFF]
|
||||
[0x00; 4]
|
||||
};
|
||||
|
||||
pixel.copy_from_slice(&rgba);
|
||||
|
|
|
@ -17,7 +17,7 @@ impl Display {
|
|||
let mut set_vf = false;
|
||||
|
||||
// Each byte in data is a row, with the column being data.len() tall
|
||||
// This means when writing this sprite, x should not change, but y
|
||||
// This means when writing this sprite, x will change for each bit in a byte and y
|
||||
// should be incremented by 1 for every new byte we draw to the graphics buffer
|
||||
for (y_offset, byte) in data.iter().enumerate() {
|
||||
// Access every bit of the byte
|
||||
|
@ -35,14 +35,13 @@ impl Display {
|
|||
break; // Stop Drawing this spite and move on to the next
|
||||
}
|
||||
|
||||
if bit == 0x1 && self.buf[gfx_i] == 0x1 {
|
||||
if bit == 0x1 && self.buf[gfx_i] == 0x01 {
|
||||
set_vf = true;
|
||||
}
|
||||
|
||||
self.buf[gfx_i] ^= bit;
|
||||
}
|
||||
}
|
||||
|
||||
set_vf
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue