diff --git a/src/editing_area/level.c b/src/editing_area/level.c index d7c6004..f6e44ff 100644 --- a/src/editing_area/level.c +++ b/src/editing_area/level.c @@ -11,13 +11,13 @@ static const int kble_fmt_version = 0; static int read_byte(FILE *file); static Tile read_byte_group(FILE *file, int size); -static int write_byte(FILE *file, char byte); +static int write_byte(FILE *file, unsigned char byte); static int write_byte_group(FILE *file, Tile value, int size); int level_read(struct Level *level, char *path) { FILE *file = NULL; - char byte = 0; + unsigned char byte = 0; unsigned int tile_size = 0; int level_size = 0; int i = 0; @@ -114,12 +114,11 @@ int level_write(struct Level level, char *path) for (i = 0; i < level_size; i += 1) { tile = level.data[i]; tile_size = 1; - while (tile >>= 8) { + while (tile >>= 8) tile_size += 1; - INFO_VAR("%d", tile); - } if (tile_size > max_tile_size) { max_tile_size = tile_size; + INFO_VAR("%d", max_tile_size); } } INFO("max tile size is"); @@ -162,7 +161,7 @@ static int read_byte(FILE *file) static Tile read_byte_group(FILE *file, int size) { int group = 0; - char *byte_ptr = (char *)&group; + unsigned char *byte_ptr = (unsigned char *)&group; int value = 0; int i = 0; byte_ptr += size; @@ -176,7 +175,7 @@ static Tile read_byte_group(FILE *file, int size) } /* Write a single byte safely (handle EOF). Return -1 if error. */ -static int write_byte(FILE *file, char byte) +static int write_byte(FILE *file, unsigned char byte) { const int result = fputc(byte, file); if (result == EOF) { @@ -189,7 +188,7 @@ static int write_byte(FILE *file, char byte) /* Write an integer as multiple bytes. Return -1 if error. */ static int write_byte_group(FILE *file, Tile value, int size) { - char *value_ptr = (char *)&value; + unsigned char *value_ptr = (unsigned char *)&value; value_ptr += size; int error; int i = 0;