From 1cc61fa8da9354b540d9ec6494ee8e7fddfb48a8 Mon Sep 17 00:00:00 2001 From: PhoenixBound Date: Sun, 7 Jul 2024 16:41:36 -0500 Subject: [PATCH] Fix edge case in transpose handling for 0xF9 Using a negative transpose can cause unsigned overflow in the addition, which will set the carry flag. ebmused was only handling that properly for large positive transpositions. Fixes an issue that Livvy and Crafty ran into but that wasn't reported or investigated until now. --- src/play.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/play.c b/src/play.c index a135a4e..c516c5e 100644 --- a/src/play.c +++ b/src/play.c @@ -216,7 +216,7 @@ static void do_command(struct song_state *st, struct channel_state *c) { break; case 0xF9: { c->cur_port_start_ctr = p[1]; - int target = p[3] + st->transpose; + int target = p[3] + (unsigned char)st->transpose; if (target >= 0x100) target -= 0xFF; target += c->transpose; make_slider(&c->note, p[2], target & 0x7F);