Fix buffer underflow in drawPlusMask

When sRow == -1 drawPlusMask can cause buffer underflow if it's
interrupted by an interrupt that changes memory that it's in the middle
of writing.  Of course it shouldn't be writing to this memory at all.

This fixes the issue.
This commit is contained in:
Josh Goebel 2017-04-21 18:46:29 -04:00 committed by Scott Allen
parent 520be03d59
commit 5d428a3a33
1 changed files with 8 additions and 4 deletions

View File

@ -285,19 +285,23 @@ void Sprites::drawBitmap(int16_t x, int16_t y,
// FIRST PAGE // FIRST PAGE
"ld %[data], %a[buffer_ofs]\n"
// if sRow >= 0 // if sRow >= 0
"tst %[sRow]\n" "tst %[sRow]\n"
"brmi end_first_page\n" "brmi skip_first_page\n"
"ld %[data], %a[buffer_ofs]\n"
// then // then
"com %A[mask_data]\n" "com %A[mask_data]\n"
"and %[data], %A[mask_data]\n" "and %[data], %A[mask_data]\n"
"or %[data], %A[bitmap_data]\n" "or %[data], %A[bitmap_data]\n"
"end_first_page:\n"
// update buffer, increment // update buffer, increment
"st %a[buffer_ofs]+, %[data]\n" "st %a[buffer_ofs]+, %[data]\n"
"jmp end_first_page\n"
"skip_first_page:\n"
// since no ST Z+ when skipped we need to do this manually
"adiw %[buffer_ofs], 1\n"
"end_first_page:\n"
// "x_loop_next:\n" // "x_loop_next:\n"
"dec %[xi]\n" "dec %[xi]\n"