commit 3651261430c0bf2512b45438288bb72b562e52d7
parent 47fe5386204c8c3299341a5b4a813d183ad7ae96
Author: Léo Villeveygoux <leo.villeveygoux@u-bordeaux.fr>
Date: Mon, 29 Apr 2019 04:02:15 +0200
Wrap y coord in sprite display
This fixes a segfault caused by y coord overflowing.
Diffstat:
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/chip8.c b/chip8.c
@@ -253,12 +253,13 @@ void step(){
unsigned char shift = x%8;
for(int i=0;i<I_N(instr);i++){
- unsigned char *screen_tile = &SCREEN[(y+i)*8+x/8];
+ unsigned char wrapped_y = (y+i)%32;
+ unsigned char *screen_tile = &SCREEN[wrapped_y*8+x/8];
unsigned char sprite_tile = RAM[I+i]>>shift;
V[0xf] |= *screen_tile & sprite_tile ? 1:0;
*screen_tile ^= sprite_tile;
if(shift){
- screen_tile = &SCREEN[(y+i)*8+(x/8+1)%8];
+ screen_tile = &SCREEN[wrapped_y*8+(x/8+1)%8];
sprite_tile = RAM[I+i]<<(8u-shift);
V[0xf] |= *screen_tile & sprite_tile ? 1:0;
*screen_tile ^= sprite_tile;