summaryrefslogtreecommitdiff
path: root/tools/lz/output.c
diff options
context:
space:
mode:
authorRangi <remy.oukaour+rangi42@gmail.com>2020-06-29 12:26:45 -0400
committerRangi <remy.oukaour+rangi42@gmail.com>2020-06-29 12:26:45 -0400
commitc8346c0bf99aaef85757bae09311661d06d801c4 (patch)
tree7c32be6879465b259cdfa92acfd5953a8f82c74c /tools/lz/output.c
parent416255bea47756eefb365f32c996100d5c88c9c3 (diff)
parent9dbe676f445210aaaa6eedcd805cbb65318ac77f (diff)
Merge branch 'master' of https://github.com/pret/pokegold
Diffstat (limited to 'tools/lz/output.c')
-rw-r--r--tools/lz/output.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/tools/lz/output.c b/tools/lz/output.c
index 43e7ba92..484a9516 100644
--- a/tools/lz/output.c
+++ b/tools/lz/output.c
@@ -28,8 +28,16 @@ void write_commands_and_padding_to_textfile (const char * file, const struct com
if (fputs("\tlzend\n", fp) < 0) error_exit(1, "could not write terminator to compressed output");
if (padding_size) {
input_stream += padding_offset;
- int rv = fprintf(fp, "\tdb $%02hhx", *(input_stream ++));
- while ((rv >= 0) && (-- padding_size)) rv = fprintf(fp, ", $%02hhx", *(input_stream ++));
+ int rv = 0;
+ unsigned pos;
+ const char * prefix = "\tdb";
+ for (pos = 0; (rv >= 0) && (pos < padding_size); pos ++) {
+ if (input_stream[pos])
+ rv = fprintf(fp, "%s $%02hhx", prefix, input_stream[pos]);
+ else
+ rv = fprintf(fp, "%s 0", prefix);
+ prefix = ",";
+ }
if (rv >= 0) rv = -(putc('\n', fp) == EOF);
if (rv < 0) error_exit(1, "could not write padding to compressed output");
}