Skip to content

Commit

Permalink
Minor typo/improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mateodif committed Jun 18, 2023
1 parent 1c8fe10 commit 156fb7d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/chip8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,17 @@ impl CHIP8 {
self.registers[register as usize] = byte & randint;
},
Instruction::DrawSprite { register1, register2, nibble } => {
let coord_x = (self.registers[register1 as usize] & (DISPLAY_HEIGHT - 1) as u8) as usize;
let coord_y = (self.registers[register2 as usize] & (DISPLAY_WIDTH - 1) as u8) as usize;
let coord_x = (self.registers[register1 as usize] & (DISPLAY_WIDTH - 1) as u8) as usize;
let coord_y = (self.registers[register2 as usize] & (DISPLAY_HEIGHT - 1) as u8) as usize;
self.registers[0xF as usize] = 0;

for byte in 0..(nibble as usize) {
let y = (coord_y + byte) % DISPLAY_HEIGHT;
let sprite_byte = self.memory[self.index as usize + byte];

for bit in 0..8 {
let x = (coord_x + bit) % DISPLAY_WIDTH;
let sprite_pixel = (self.memory[self.index as usize + byte] >> (7 - bit)) & 1;
let sprite_pixel = (sprite_byte >> (7 - bit)) & 1;
let display_pixel = self.display[x][y];

self.display[x][y] ^= sprite_pixel;
Expand Down
9 changes: 4 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ fn main() {
let video_subsystem = sdl_context.video().unwrap();

let window = video_subsystem.window("CHIP-8",
(chip8::DISPLAY_HEIGHT * 8) as u32,
(chip8::DISPLAY_WIDTH * 8) as u32)
(chip8::DISPLAY_HEIGHT * 10) as u32,
(chip8::DISPLAY_WIDTH * 10) as u32)
.position_centered()
.build()
.unwrap();
Expand All @@ -32,7 +32,6 @@ fn main() {
canvas.set_draw_color(Color::RGB(97, 134, 169));
canvas.clear();


let mut keydown_event = None;

for event in events.poll_iter() {
Expand All @@ -50,8 +49,8 @@ fn main() {
canvas.set_draw_color(Color::RGB(33, 41, 70));

for (x, row) in chip.get_display().iter().enumerate() {
for (y, _) in row.iter().enumerate() {
if chip.get_display()[x][y] == 1 {
for (y, &pixel) in row.iter().enumerate() {
if pixel == 1 {
canvas.draw_point((x as i32, y as i32)).unwrap();
}
}
Expand Down

0 comments on commit 156fb7d

Please sign in to comment.