Image corruption when using drawPlusMask() in some cases [register allocation issue]

Is there a limit to the number of sprites that can be drawn on screen at once?

I started a game using static characters and recently have been adding sprites with Team A.R.G’s sprite tool.

When adding a larger character the sprite images appear jumbled and in some instances including parts of other unrelated sprites.

I removed the sprite code to a separate file to see try and track down the problem. I can show two sprites at once. If I add a third sprite, in this case a second instance of the first one, then the display becomes jumbled. I think the size of the sprite could be an issue as the large one has the problems.

Some example code…

#include <Arduboy2.h>
Arduboy2 arduboy;
Sprites sprites;

const unsigned char PROGMEM questor_plus_mask[] = {
  // width, height,
  6, 8,
  // FRAME 00
  0x10, 0x10, 0xff, 0xff, 0x7d, 0x7f, 
  0x7f, 0x7f, 0xfd, 0xff, 0x10, 0x10, 
  // FRAME 01
  0x10, 0x10, 0x7f, 0x7f, 0xfd, 0xff, 
  0x7f, 0x7f, 0xfd, 0xff, 0x10, 0x10, 
  // FRAME 02
  0x10, 0x10, 0xff, 0xff, 0x7d, 0x7f, 
  0xff, 0xff, 0x7d, 0x7f, 0x10, 0x10, 
  // FRAME 03
  0x08, 0x08, 0x7f, 0x7f, 0xfd, 0xff, 
  0xff, 0xff, 0x7d, 0x7f, 0x08, 0x08,
};
int questorX = 0;
int questorY = 50;
byte questorSpriteNumber = 0;

const unsigned char PROGMEM bones_plus_mask[] = {
// width, height,
74, 48,
// FRAME 00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x83, 0x83, 0xc2, 0xc2, 0xf7, 0xf7, 0xb7, 0xf7, 0x16, 0xf6, 0xb4, 0xf4, 0xf0, 0xf0, 0xf1, 0xf1, 0xe2, 0xe2, 0xe3, 0xe3, 0xff, 0xff, 0xfe, 0xfe, 0x34, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xe0, 0xe0, 0xc0, 0xc0, 0x70, 0x70, 0x20, 0x20, 0x60, 0x60, 0xf0, 0xf0, 0x40, 0x40, 0xc0, 0xc0, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x31, 0x31, 0x23, 0x23, 0x39, 0x39, 0x33, 0x33, 0x39, 0x39, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x1f, 0x1f, 0xbf, 0xbf, 0xff, 0xff, 0x53, 0x53, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x07, 0x07, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x82, 0x97, 0x97, 0xfe, 0xfe, 0x54, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0x40, 0x40, 0x08, 0x08, 0xc4, 0xc4, 0x18, 0x18, 0x60, 0x60, 0x08, 0x08, 0xf8, 0xf8, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x32, 0x19, 0x19, 0x3b, 0x3b, 0xd0, 0xd0, 0x80, 0x80, 0x10, 0x10, 0xd0, 0xd0, 0xf8, 0xf8, 0xf8, 0xf8, 0xfc, 0xfc, 0xf8, 0xf8, 0x70, 0x70, 0x60, 0x60, 
0x70, 0x70, 0xe0, 0xe0, 0x70, 0x70, 0x60, 0x60, 0xc0, 0xc0, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, 0xc0, 0xc0, 0x40, 0x40, 0xc0, 0xc0, 0xc0, 0xc0, 0x92, 0x92, 0xb7, 0xb7, 0x36, 0x36, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x10, 0x10, 0x38, 0x38, 0x22, 0x22, 0x00, 0x00, 0x02, 0x02, 0x04, 0x04, 0x10, 0x10, 0xe7, 0xe7, 0xef, 0xef, 0x9c, 0x9c, 0xbc, 0xbc, 0x38, 0x38, 0xb0, 0xb0, 0x80, 0x80, 0x30, 0x30, 0x60, 0x60, 0x40, 0x40, 0xc0, 0xc0, 0x80, 0x80, 0x21, 0x21, 0x6d, 0x6d, 0x69, 0x69, 0x0b, 0x0b, 0x63, 0x63, 0x00, 0x00, 0x20, 0x20, 0x11, 0x11, 0x0e, 0x0e, 
0x40, 0x40, 0x21, 0x21, 0x1e, 0x1e, 0x80, 0x80, 0x43, 0x43, 0x3c, 0x3c, 0x01, 0x01, 0x43, 0x43, 0x3d, 0x3d, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01, 0xc0, 0xc0, 0x60, 0x60, 0x70, 0x70, 0x09, 0x09, 0x01, 0x01, 0x07, 0x07, 0x04, 0x04, 0xe4, 0xe4, 0xf7, 0xf7, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0x1c, 0x1c, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x02, 0x02, 0x09, 0x09, 0x18, 0x18, 0x10, 0x10, 0x90, 0x90, 0x58, 0x58, 0x7d, 0x7d, 0x03, 0x03, 0x03, 0x03, 0x0e, 0x0e, 0x20, 0x20, 0x60, 0x60, 0x10, 0x10, 0x18, 0x18, 0x18, 0x18, 0x08, 0x08, 0x8c, 0x8c, 0xde, 0xde, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
// FRAME 01
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x83, 0x83, 0xc2, 0xc2, 0xf7, 0xf7, 0xb7, 0xf7, 0x16, 0xf6, 0xb4, 0xf4, 0xf0, 0xf0, 0xf1, 0xf1, 0xe2, 0xe2, 0xe3, 0xe3, 0xff, 0xff, 0xfe, 0xfe, 0x34, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xe0, 0xe0, 0xc0, 0xc0, 0x70, 0x70, 0x20, 0x20, 0x60, 0x60, 0xf0, 0xf0, 0x40, 0x40, 0xc0, 0xc0, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x31, 0x31, 0x23, 0x23, 0x39, 0x39, 0x33, 0x33, 0x39, 0x39, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x1f, 0x1f, 0xbf, 0xbf, 0xff, 0xff, 0x53, 0x53, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x07, 0x07, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x82, 0x97, 0x97, 0xfe, 0xfe, 0x54, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x32, 0x19, 0x19, 0x3b, 0x3b, 0xd0, 0xd0, 0x80, 0x80, 0x10, 0x10, 0xd0, 0xd0, 0xf8, 0xf8, 0xf8, 0xf8, 0xfc, 0xfc, 0xf8, 0xf8, 0x70, 0x70, 0x60, 0x60, 
0x70, 0x70, 0xe0, 0xe0, 0x70, 0x70, 0x60, 0x60, 0xc0, 0xc0, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, 0xc0, 0xc0, 0x40, 0x40, 0xc0, 0xc0, 0xc0, 0xc0, 0x92, 0x92, 0xb7, 0xb7, 0x36, 0x36, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x20, 0x20, 0xd0, 0xd0, 0x28, 0x28, 0x20, 0x20, 0x4c, 0x4c, 0xb4, 0xb4, 0xc4, 0xc4, 0xb8, 0xb8, 0x60, 0x60, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xc9, 0xc9, 0x7d, 0x7d, 0x39, 0x39, 0x0b, 0x0b, 0x63, 0x63, 0x00, 0x00, 0x20, 0x20, 0x11, 0x11, 0x0e, 0x0e, 
0x40, 0x40, 0x21, 0x21, 0x1e, 0x1e, 0x80, 0x80, 0x43, 0x43, 0x3c, 0x3c, 0x01, 0x01, 0x43, 0x43, 0x3d, 0x3d, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01, 0xc0, 0xc0, 0x60, 0x60, 0x70, 0x70, 0x09, 0x09, 0x01, 0x01, 0x07, 0x07, 0x04, 0x04, 0xe4, 0xe4, 0xf7, 0xf7, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x09, 0x09, 0x13, 0x13, 0x17, 0x17, 0x1c, 0x1c, 0x1b, 0x1b, 0x17, 0x17, 0x17, 0x17, 0x0f, 0x0f, 0x06, 0x06, 0x00, 0x00, 0x19, 0x19, 0x17, 0x17, 0x06, 0x06, 0x0e, 0x0e, 0x06, 0x06, 0x04, 0x04, 0x02, 0x02, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00, 0x03, 0x03, 0x01, 0x01, 0x80, 0x80, 0xc0, 0xc0, 0x1c, 0x1c, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x02, 0x02, 0x09, 0x09, 0x18, 0x18, 0x10, 0x10, 0x90, 0x90, 0x58, 0x58, 0x7d, 0x7d, 0x03, 0x03, 0x03, 0x03, 0x0e, 0x0e, 0x20, 0x20, 0x60, 0x60, 0x10, 0x10, 0x18, 0x18, 0x18, 0x18, 0x08, 0x08, 0x8c, 0x8c, 0xde, 0xde, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
// FRAME 02
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x83, 0x83, 0xc2, 0xc2, 0xf7, 0xf7, 0xb7, 0xf7, 0x16, 0xf6, 0xb4, 0xf4, 0xf0, 0xf0, 0xf1, 0xf1, 0xe2, 0xe2, 0xe3, 0xe3, 0xff, 0xff, 0xfe, 0xfe, 0x34, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0x40, 0x40, 0x30, 0x30, 0x60, 0x60, 0x10, 0x10, 0x18, 0x18, 0x10, 0x10, 0x30, 0x30, 0x10, 0x10, 0x10, 0x10, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x31, 0x31, 0x23, 0x23, 0x39, 0x39, 0x33, 0x33, 0x39, 0x39, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x1f, 0x1f, 0xbf, 0xbf, 0xff, 0xff, 0x53, 0x53, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0xf2, 0xf2, 0xbe, 0xbe, 0x0f, 0x0f, 0x0b, 0x0b, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0x40, 0x40, 0x08, 0x08, 0xc4, 0xc4, 0x18, 0x18, 0x60, 0x60, 0x08, 0x08, 0xf8, 0xf8, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x32, 0x19, 0x19, 0x3b, 0x3b, 0xd0, 0xd0, 0x80, 0x80, 0x10, 0x10, 0xd0, 0xd0, 0xf8, 0xf8, 0xf8, 0xf8, 0xfc, 0xfc, 0xf8, 0xf8, 0x70, 0x70, 0x60, 0x60, 
0x70, 0x70, 0xe0, 0xe0, 0x70, 0x70, 0x60, 0x60, 0xc0, 0xc0, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, 0xc0, 0xc0, 0x40, 0x40, 0xc0, 0xc0, 0xc0, 0xc0, 0x90, 0x90, 0xb5, 0xb5, 0x37, 0x37, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x10, 0x10, 0x38, 0x38, 0x22, 0x22, 0x00, 0x00, 0x02, 0x02, 0x04, 0x04, 0x10, 0x10, 0xe7, 0xe7, 0xef, 0xef, 0x9c, 0x9c, 0xbc, 0xbc, 0x38, 0x38, 0xb0, 0xb0, 0x80, 0x80, 0x30, 0x30, 0x60, 0x60, 0x40, 0x40, 0xc0, 0xc0, 0x80, 0x80, 0x21, 0x21, 0x6d, 0x6d, 0x69, 0x69, 0x0b, 0x0b, 0x63, 0x63, 0x00, 0x00, 0x20, 0x20, 0x11, 0x11, 0x0e, 0x0e, 
0x40, 0x40, 0x21, 0x21, 0x1e, 0x1e, 0x80, 0x80, 0x43, 0x43, 0x3c, 0x3c, 0x01, 0x01, 0x43, 0x43, 0x3d, 0x3d, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01, 0xc0, 0xc0, 0x60, 0x60, 0x70, 0x70, 0x09, 0x09, 0x01, 0x01, 0x07, 0x07, 0x04, 0x04, 0xe4, 0xe4, 0xf7, 0xf7, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0x1c, 0x1c, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x02, 0x02, 0x09, 0x09, 0x18, 0x18, 0x10, 0x10, 0x90, 0x90, 0x58, 0x58, 0x7d, 0x7d, 0x03, 0x03, 0x03, 0x03, 0x0e, 0x0e, 0x20, 0x20, 0x60, 0x60, 0x10, 0x10, 0x18, 0x18, 0x18, 0x18, 0x08, 0x08, 0x8c, 0x8c, 0xde, 0xde, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
int bonesX = 30;
int bonesY = 20;
byte bonesSpriteNumber = 0;


void setup() {
  arduboy.begin();
  arduboy.setFrameRate(60);
  arduboy.clear();
}


void loop() {
  
  if (!arduboy.nextFrame()) {
    return;
  }

  arduboy.clear();

  if (arduboy.everyXFrames(30)) {
    questorSpriteNumber++;
    bonesSpriteNumber++;
  }

  if (questorSpriteNumber > 3) {
    questorSpriteNumber = 0;  
  }   
  
  if (bonesSpriteNumber > 2) {
    bonesSpriteNumber = 0;  
  }

  // Sprite 1
  sprites.drawPlusMask(questorX, questorY, questor_plus_mask, questorSpriteNumber); 

  // Sprite 2
  // sprites.drawPlusMask(bonesX, bonesY, bones_plus_mask, bonesSpriteNumber);

  // Sprite 3 (2nd copy of sprite 1)
  // sprites.drawPlusMask(questorX + 8, questorY, questor_plus_mask, questorSpriteNumber); 
  
  arduboy.display();

}

This works and shows a little guy on the left of the screen.

If you uncomment the line for sprite 2…

sprites.drawPlusMask(bonesX, bonesY, bones_plus_mask, bonesSpriteNumber);

… then you get a bone monster to the right (all good so far)

Now, if you uncomment the sprite 3 line…

sprites.drawPlusMask(questorX + 8, questorY, questor_plus_mask, questorSpriteNumber); 

…it gets a bit funny! This is just adding a second copy of sprite 1.

Originally sprite 2 was going to be broken up into different parts (separate head, claw, tail, body), each as a separate sprite, which I thought would reduce the memory needed. This was again all jumbled and hard to work out what was wrong with all the components - so I put it all back together in one sprite for these examples.

I do not really know what I am doing but I wondered if it could be something to do with the following:

  • I’m not implementing sprites correctly
  • memory issues (e.g. the size of sprite 2)
  • poorly made sprites
  • wrong spacing in spritesheets
  • limit to what can be drawn on screen
  • limit to number of sprites used at once
1 Like

p.s. if you just want to skip to the jumbled appearance with all 3 sprites showing then here it is without needing to uncomment anything

#include <Arduboy2.h>
Arduboy2 arduboy;
Sprites sprites;

const unsigned char PROGMEM questor_plus_mask[] = {
  // width, height,
  6, 8,
  // FRAME 00
  0x10, 0x10, 0xff, 0xff, 0x7d, 0x7f, 
  0x7f, 0x7f, 0xfd, 0xff, 0x10, 0x10, 
  // FRAME 01
  0x10, 0x10, 0x7f, 0x7f, 0xfd, 0xff, 
  0x7f, 0x7f, 0xfd, 0xff, 0x10, 0x10, 
  // FRAME 02
  0x10, 0x10, 0xff, 0xff, 0x7d, 0x7f, 
  0xff, 0xff, 0x7d, 0x7f, 0x10, 0x10, 
  // FRAME 03
  0x08, 0x08, 0x7f, 0x7f, 0xfd, 0xff, 
  0xff, 0xff, 0x7d, 0x7f, 0x08, 0x08,
};
int questorX = 0;
int questorY = 50;
byte questorSpriteNumber = 0;

const unsigned char PROGMEM bones_plus_mask[] = {
// width, height,
74, 48,
// FRAME 00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x83, 0x83, 0xc2, 0xc2, 0xf7, 0xf7, 0xb7, 0xf7, 0x16, 0xf6, 0xb4, 0xf4, 0xf0, 0xf0, 0xf1, 0xf1, 0xe2, 0xe2, 0xe3, 0xe3, 0xff, 0xff, 0xfe, 0xfe, 0x34, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xe0, 0xe0, 0xc0, 0xc0, 0x70, 0x70, 0x20, 0x20, 0x60, 0x60, 0xf0, 0xf0, 0x40, 0x40, 0xc0, 0xc0, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x31, 0x31, 0x23, 0x23, 0x39, 0x39, 0x33, 0x33, 0x39, 0x39, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x1f, 0x1f, 0xbf, 0xbf, 0xff, 0xff, 0x53, 0x53, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x07, 0x07, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x82, 0x97, 0x97, 0xfe, 0xfe, 0x54, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0x40, 0x40, 0x08, 0x08, 0xc4, 0xc4, 0x18, 0x18, 0x60, 0x60, 0x08, 0x08, 0xf8, 0xf8, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x32, 0x19, 0x19, 0x3b, 0x3b, 0xd0, 0xd0, 0x80, 0x80, 0x10, 0x10, 0xd0, 0xd0, 0xf8, 0xf8, 0xf8, 0xf8, 0xfc, 0xfc, 0xf8, 0xf8, 0x70, 0x70, 0x60, 0x60, 
0x70, 0x70, 0xe0, 0xe0, 0x70, 0x70, 0x60, 0x60, 0xc0, 0xc0, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, 0xc0, 0xc0, 0x40, 0x40, 0xc0, 0xc0, 0xc0, 0xc0, 0x92, 0x92, 0xb7, 0xb7, 0x36, 0x36, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x10, 0x10, 0x38, 0x38, 0x22, 0x22, 0x00, 0x00, 0x02, 0x02, 0x04, 0x04, 0x10, 0x10, 0xe7, 0xe7, 0xef, 0xef, 0x9c, 0x9c, 0xbc, 0xbc, 0x38, 0x38, 0xb0, 0xb0, 0x80, 0x80, 0x30, 0x30, 0x60, 0x60, 0x40, 0x40, 0xc0, 0xc0, 0x80, 0x80, 0x21, 0x21, 0x6d, 0x6d, 0x69, 0x69, 0x0b, 0x0b, 0x63, 0x63, 0x00, 0x00, 0x20, 0x20, 0x11, 0x11, 0x0e, 0x0e, 
0x40, 0x40, 0x21, 0x21, 0x1e, 0x1e, 0x80, 0x80, 0x43, 0x43, 0x3c, 0x3c, 0x01, 0x01, 0x43, 0x43, 0x3d, 0x3d, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01, 0xc0, 0xc0, 0x60, 0x60, 0x70, 0x70, 0x09, 0x09, 0x01, 0x01, 0x07, 0x07, 0x04, 0x04, 0xe4, 0xe4, 0xf7, 0xf7, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0x1c, 0x1c, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x02, 0x02, 0x09, 0x09, 0x18, 0x18, 0x10, 0x10, 0x90, 0x90, 0x58, 0x58, 0x7d, 0x7d, 0x03, 0x03, 0x03, 0x03, 0x0e, 0x0e, 0x20, 0x20, 0x60, 0x60, 0x10, 0x10, 0x18, 0x18, 0x18, 0x18, 0x08, 0x08, 0x8c, 0x8c, 0xde, 0xde, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
// FRAME 01
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x83, 0x83, 0xc2, 0xc2, 0xf7, 0xf7, 0xb7, 0xf7, 0x16, 0xf6, 0xb4, 0xf4, 0xf0, 0xf0, 0xf1, 0xf1, 0xe2, 0xe2, 0xe3, 0xe3, 0xff, 0xff, 0xfe, 0xfe, 0x34, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xe0, 0xe0, 0xc0, 0xc0, 0x70, 0x70, 0x20, 0x20, 0x60, 0x60, 0xf0, 0xf0, 0x40, 0x40, 0xc0, 0xc0, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x31, 0x31, 0x23, 0x23, 0x39, 0x39, 0x33, 0x33, 0x39, 0x39, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x1f, 0x1f, 0xbf, 0xbf, 0xff, 0xff, 0x53, 0x53, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x07, 0x07, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x82, 0x97, 0x97, 0xfe, 0xfe, 0x54, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x32, 0x19, 0x19, 0x3b, 0x3b, 0xd0, 0xd0, 0x80, 0x80, 0x10, 0x10, 0xd0, 0xd0, 0xf8, 0xf8, 0xf8, 0xf8, 0xfc, 0xfc, 0xf8, 0xf8, 0x70, 0x70, 0x60, 0x60, 
0x70, 0x70, 0xe0, 0xe0, 0x70, 0x70, 0x60, 0x60, 0xc0, 0xc0, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, 0xc0, 0xc0, 0x40, 0x40, 0xc0, 0xc0, 0xc0, 0xc0, 0x92, 0x92, 0xb7, 0xb7, 0x36, 0x36, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x20, 0x20, 0xd0, 0xd0, 0x28, 0x28, 0x20, 0x20, 0x4c, 0x4c, 0xb4, 0xb4, 0xc4, 0xc4, 0xb8, 0xb8, 0x60, 0x60, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xc9, 0xc9, 0x7d, 0x7d, 0x39, 0x39, 0x0b, 0x0b, 0x63, 0x63, 0x00, 0x00, 0x20, 0x20, 0x11, 0x11, 0x0e, 0x0e, 
0x40, 0x40, 0x21, 0x21, 0x1e, 0x1e, 0x80, 0x80, 0x43, 0x43, 0x3c, 0x3c, 0x01, 0x01, 0x43, 0x43, 0x3d, 0x3d, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01, 0xc0, 0xc0, 0x60, 0x60, 0x70, 0x70, 0x09, 0x09, 0x01, 0x01, 0x07, 0x07, 0x04, 0x04, 0xe4, 0xe4, 0xf7, 0xf7, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x09, 0x09, 0x13, 0x13, 0x17, 0x17, 0x1c, 0x1c, 0x1b, 0x1b, 0x17, 0x17, 0x17, 0x17, 0x0f, 0x0f, 0x06, 0x06, 0x00, 0x00, 0x19, 0x19, 0x17, 0x17, 0x06, 0x06, 0x0e, 0x0e, 0x06, 0x06, 0x04, 0x04, 0x02, 0x02, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00, 0x03, 0x03, 0x01, 0x01, 0x80, 0x80, 0xc0, 0xc0, 0x1c, 0x1c, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x02, 0x02, 0x09, 0x09, 0x18, 0x18, 0x10, 0x10, 0x90, 0x90, 0x58, 0x58, 0x7d, 0x7d, 0x03, 0x03, 0x03, 0x03, 0x0e, 0x0e, 0x20, 0x20, 0x60, 0x60, 0x10, 0x10, 0x18, 0x18, 0x18, 0x18, 0x08, 0x08, 0x8c, 0x8c, 0xde, 0xde, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
// FRAME 02
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x83, 0x83, 0xc2, 0xc2, 0xf7, 0xf7, 0xb7, 0xf7, 0x16, 0xf6, 0xb4, 0xf4, 0xf0, 0xf0, 0xf1, 0xf1, 0xe2, 0xe2, 0xe3, 0xe3, 0xff, 0xff, 0xfe, 0xfe, 0x34, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0x40, 0x40, 0x30, 0x30, 0x60, 0x60, 0x10, 0x10, 0x18, 0x18, 0x10, 0x10, 0x30, 0x30, 0x10, 0x10, 0x10, 0x10, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x31, 0x31, 0x23, 0x23, 0x39, 0x39, 0x33, 0x33, 0x39, 0x39, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x1f, 0x1f, 0xbf, 0xbf, 0xff, 0xff, 0x53, 0x53, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0xf2, 0xf2, 0xbe, 0xbe, 0x0f, 0x0f, 0x0b, 0x0b, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0x40, 0x40, 0x08, 0x08, 0xc4, 0xc4, 0x18, 0x18, 0x60, 0x60, 0x08, 0x08, 0xf8, 0xf8, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x32, 0x19, 0x19, 0x3b, 0x3b, 0xd0, 0xd0, 0x80, 0x80, 0x10, 0x10, 0xd0, 0xd0, 0xf8, 0xf8, 0xf8, 0xf8, 0xfc, 0xfc, 0xf8, 0xf8, 0x70, 0x70, 0x60, 0x60, 
0x70, 0x70, 0xe0, 0xe0, 0x70, 0x70, 0x60, 0x60, 0xc0, 0xc0, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, 0xc0, 0xc0, 0x40, 0x40, 0xc0, 0xc0, 0xc0, 0xc0, 0x90, 0x90, 0xb5, 0xb5, 0x37, 0x37, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x10, 0x10, 0x38, 0x38, 0x22, 0x22, 0x00, 0x00, 0x02, 0x02, 0x04, 0x04, 0x10, 0x10, 0xe7, 0xe7, 0xef, 0xef, 0x9c, 0x9c, 0xbc, 0xbc, 0x38, 0x38, 0xb0, 0xb0, 0x80, 0x80, 0x30, 0x30, 0x60, 0x60, 0x40, 0x40, 0xc0, 0xc0, 0x80, 0x80, 0x21, 0x21, 0x6d, 0x6d, 0x69, 0x69, 0x0b, 0x0b, 0x63, 0x63, 0x00, 0x00, 0x20, 0x20, 0x11, 0x11, 0x0e, 0x0e, 
0x40, 0x40, 0x21, 0x21, 0x1e, 0x1e, 0x80, 0x80, 0x43, 0x43, 0x3c, 0x3c, 0x01, 0x01, 0x43, 0x43, 0x3d, 0x3d, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01, 0xc0, 0xc0, 0x60, 0x60, 0x70, 0x70, 0x09, 0x09, 0x01, 0x01, 0x07, 0x07, 0x04, 0x04, 0xe4, 0xe4, 0xf7, 0xf7, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0x1c, 0x1c, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x02, 0x02, 0x09, 0x09, 0x18, 0x18, 0x10, 0x10, 0x90, 0x90, 0x58, 0x58, 0x7d, 0x7d, 0x03, 0x03, 0x03, 0x03, 0x0e, 0x0e, 0x20, 0x20, 0x60, 0x60, 0x10, 0x10, 0x18, 0x18, 0x18, 0x18, 0x08, 0x08, 0x8c, 0x8c, 0xde, 0xde, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
int bonesX = 30;
int bonesY = 20;
byte bonesSpriteNumber = 0;


void setup() {
  arduboy.begin();
  arduboy.setFrameRate(60);
  arduboy.clear();
}


void loop() {
  
  if (!arduboy.nextFrame()) {
    return;
  }

  arduboy.clear();

  if (arduboy.everyXFrames(30)) {
    questorSpriteNumber++;
    bonesSpriteNumber++;
  }

  if (questorSpriteNumber > 3) {
    questorSpriteNumber = 0;  
  }   
  
  if (bonesSpriteNumber > 2) {
    bonesSpriteNumber = 0;  
  }

  // Sprite 1
  sprites.drawPlusMask(questorX, questorY, questor_plus_mask, questorSpriteNumber); 

  // Sprite 2
   sprites.drawPlusMask(bonesX, bonesY, bones_plus_mask, bonesSpriteNumber);

  // Sprite 3 (2nd copy of sprite 1)
   sprites.drawPlusMask(questorX + 8, questorY, questor_plus_mask, questorSpriteNumber); 
  
  arduboy.display();

}

I’ve seen a bug like this before (can’t remember where sadly) and I think it’s actually a bug in the compiler itself relating to compiler optimisation.

Notice that in the version with two sprites the progmem usage is higher than in the version with three sprites. I don’t know why or how, but for some reason the latter version is being optimised incorrectly and it results in the image being scrambled.

I solved this by wrapping the code drawing ‘questor’ in its own function and using that as a proxy. This prevents certain code optimisations being applied which somehow prevents the scrambling.

My edited example:

#include <Arduboy2.h>
Arduboy2 arduboy;
//Sprites sprites;

const unsigned char questor_plus_mask[] PROGMEM = {
  // width, height,
  6, 8,
  // FRAME 00
  0x10, 0x10, 0xff, 0xff, 0x7d, 0x7f, 
  0x7f, 0x7f, 0xfd, 0xff, 0x10, 0x10, 
  // FRAME 01
  0x10, 0x10, 0x7f, 0x7f, 0xfd, 0xff, 
  0x7f, 0x7f, 0xfd, 0xff, 0x10, 0x10, 
  // FRAME 02
  0x10, 0x10, 0xff, 0xff, 0x7d, 0x7f, 
  0xff, 0xff, 0x7d, 0x7f, 0x10, 0x10, 
  // FRAME 03
  0x08, 0x08, 0x7f, 0x7f, 0xfd, 0xff, 
  0xff, 0xff, 0x7d, 0x7f, 0x08, 0x08,
};
int questorX = 0;
int questorY = 50;
byte questorSpriteNumber = 0;

const unsigned char bones_plus_mask[] PROGMEM = {
// width, height,
74, 48,
// FRAME 00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x83, 0x83, 0xc2, 0xc2, 0xf7, 0xf7, 0xb7, 0xf7, 0x16, 0xf6, 0xb4, 0xf4, 0xf0, 0xf0, 0xf1, 0xf1, 0xe2, 0xe2, 0xe3, 0xe3, 0xff, 0xff, 0xfe, 0xfe, 0x34, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xe0, 0xe0, 0xc0, 0xc0, 0x70, 0x70, 0x20, 0x20, 0x60, 0x60, 0xf0, 0xf0, 0x40, 0x40, 0xc0, 0xc0, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x31, 0x31, 0x23, 0x23, 0x39, 0x39, 0x33, 0x33, 0x39, 0x39, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x1f, 0x1f, 0xbf, 0xbf, 0xff, 0xff, 0x53, 0x53, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x07, 0x07, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x82, 0x97, 0x97, 0xfe, 0xfe, 0x54, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0x40, 0x40, 0x08, 0x08, 0xc4, 0xc4, 0x18, 0x18, 0x60, 0x60, 0x08, 0x08, 0xf8, 0xf8, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x32, 0x19, 0x19, 0x3b, 0x3b, 0xd0, 0xd0, 0x80, 0x80, 0x10, 0x10, 0xd0, 0xd0, 0xf8, 0xf8, 0xf8, 0xf8, 0xfc, 0xfc, 0xf8, 0xf8, 0x70, 0x70, 0x60, 0x60, 
0x70, 0x70, 0xe0, 0xe0, 0x70, 0x70, 0x60, 0x60, 0xc0, 0xc0, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, 0xc0, 0xc0, 0x40, 0x40, 0xc0, 0xc0, 0xc0, 0xc0, 0x92, 0x92, 0xb7, 0xb7, 0x36, 0x36, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x10, 0x10, 0x38, 0x38, 0x22, 0x22, 0x00, 0x00, 0x02, 0x02, 0x04, 0x04, 0x10, 0x10, 0xe7, 0xe7, 0xef, 0xef, 0x9c, 0x9c, 0xbc, 0xbc, 0x38, 0x38, 0xb0, 0xb0, 0x80, 0x80, 0x30, 0x30, 0x60, 0x60, 0x40, 0x40, 0xc0, 0xc0, 0x80, 0x80, 0x21, 0x21, 0x6d, 0x6d, 0x69, 0x69, 0x0b, 0x0b, 0x63, 0x63, 0x00, 0x00, 0x20, 0x20, 0x11, 0x11, 0x0e, 0x0e, 
0x40, 0x40, 0x21, 0x21, 0x1e, 0x1e, 0x80, 0x80, 0x43, 0x43, 0x3c, 0x3c, 0x01, 0x01, 0x43, 0x43, 0x3d, 0x3d, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01, 0xc0, 0xc0, 0x60, 0x60, 0x70, 0x70, 0x09, 0x09, 0x01, 0x01, 0x07, 0x07, 0x04, 0x04, 0xe4, 0xe4, 0xf7, 0xf7, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0x1c, 0x1c, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x02, 0x02, 0x09, 0x09, 0x18, 0x18, 0x10, 0x10, 0x90, 0x90, 0x58, 0x58, 0x7d, 0x7d, 0x03, 0x03, 0x03, 0x03, 0x0e, 0x0e, 0x20, 0x20, 0x60, 0x60, 0x10, 0x10, 0x18, 0x18, 0x18, 0x18, 0x08, 0x08, 0x8c, 0x8c, 0xde, 0xde, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
// FRAME 01
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x83, 0x83, 0xc2, 0xc2, 0xf7, 0xf7, 0xb7, 0xf7, 0x16, 0xf6, 0xb4, 0xf4, 0xf0, 0xf0, 0xf1, 0xf1, 0xe2, 0xe2, 0xe3, 0xe3, 0xff, 0xff, 0xfe, 0xfe, 0x34, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xe0, 0xe0, 0xc0, 0xc0, 0x70, 0x70, 0x20, 0x20, 0x60, 0x60, 0xf0, 0xf0, 0x40, 0x40, 0xc0, 0xc0, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x31, 0x31, 0x23, 0x23, 0x39, 0x39, 0x33, 0x33, 0x39, 0x39, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x1f, 0x1f, 0xbf, 0xbf, 0xff, 0xff, 0x53, 0x53, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x07, 0x07, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x82, 0x97, 0x97, 0xfe, 0xfe, 0x54, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x32, 0x19, 0x19, 0x3b, 0x3b, 0xd0, 0xd0, 0x80, 0x80, 0x10, 0x10, 0xd0, 0xd0, 0xf8, 0xf8, 0xf8, 0xf8, 0xfc, 0xfc, 0xf8, 0xf8, 0x70, 0x70, 0x60, 0x60, 
0x70, 0x70, 0xe0, 0xe0, 0x70, 0x70, 0x60, 0x60, 0xc0, 0xc0, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, 0xc0, 0xc0, 0x40, 0x40, 0xc0, 0xc0, 0xc0, 0xc0, 0x92, 0x92, 0xb7, 0xb7, 0x36, 0x36, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x20, 0x20, 0xd0, 0xd0, 0x28, 0x28, 0x20, 0x20, 0x4c, 0x4c, 0xb4, 0xb4, 0xc4, 0xc4, 0xb8, 0xb8, 0x60, 0x60, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xc9, 0xc9, 0x7d, 0x7d, 0x39, 0x39, 0x0b, 0x0b, 0x63, 0x63, 0x00, 0x00, 0x20, 0x20, 0x11, 0x11, 0x0e, 0x0e, 
0x40, 0x40, 0x21, 0x21, 0x1e, 0x1e, 0x80, 0x80, 0x43, 0x43, 0x3c, 0x3c, 0x01, 0x01, 0x43, 0x43, 0x3d, 0x3d, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01, 0xc0, 0xc0, 0x60, 0x60, 0x70, 0x70, 0x09, 0x09, 0x01, 0x01, 0x07, 0x07, 0x04, 0x04, 0xe4, 0xe4, 0xf7, 0xf7, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x09, 0x09, 0x13, 0x13, 0x17, 0x17, 0x1c, 0x1c, 0x1b, 0x1b, 0x17, 0x17, 0x17, 0x17, 0x0f, 0x0f, 0x06, 0x06, 0x00, 0x00, 0x19, 0x19, 0x17, 0x17, 0x06, 0x06, 0x0e, 0x0e, 0x06, 0x06, 0x04, 0x04, 0x02, 0x02, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00, 0x03, 0x03, 0x01, 0x01, 0x80, 0x80, 0xc0, 0xc0, 0x1c, 0x1c, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x02, 0x02, 0x09, 0x09, 0x18, 0x18, 0x10, 0x10, 0x90, 0x90, 0x58, 0x58, 0x7d, 0x7d, 0x03, 0x03, 0x03, 0x03, 0x0e, 0x0e, 0x20, 0x20, 0x60, 0x60, 0x10, 0x10, 0x18, 0x18, 0x18, 0x18, 0x08, 0x08, 0x8c, 0x8c, 0xde, 0xde, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
// FRAME 02
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x83, 0x83, 0xc2, 0xc2, 0xf7, 0xf7, 0xb7, 0xf7, 0x16, 0xf6, 0xb4, 0xf4, 0xf0, 0xf0, 0xf1, 0xf1, 0xe2, 0xe2, 0xe3, 0xe3, 0xff, 0xff, 0xfe, 0xfe, 0x34, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0x40, 0x40, 0x30, 0x30, 0x60, 0x60, 0x10, 0x10, 0x18, 0x18, 0x10, 0x10, 0x30, 0x30, 0x10, 0x10, 0x10, 0x10, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x31, 0x31, 0x23, 0x23, 0x39, 0x39, 0x33, 0x33, 0x39, 0x39, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x1f, 0x1f, 0xbf, 0xbf, 0xff, 0xff, 0x53, 0x53, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0xf2, 0xf2, 0xbe, 0xbe, 0x0f, 0x0f, 0x0b, 0x0b, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0x40, 0x40, 0x08, 0x08, 0xc4, 0xc4, 0x18, 0x18, 0x60, 0x60, 0x08, 0x08, 0xf8, 0xf8, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x32, 0x19, 0x19, 0x3b, 0x3b, 0xd0, 0xd0, 0x80, 0x80, 0x10, 0x10, 0xd0, 0xd0, 0xf8, 0xf8, 0xf8, 0xf8, 0xfc, 0xfc, 0xf8, 0xf8, 0x70, 0x70, 0x60, 0x60, 
0x70, 0x70, 0xe0, 0xe0, 0x70, 0x70, 0x60, 0x60, 0xc0, 0xc0, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, 0xc0, 0xc0, 0x40, 0x40, 0xc0, 0xc0, 0xc0, 0xc0, 0x90, 0x90, 0xb5, 0xb5, 0x37, 0x37, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x10, 0x10, 0x38, 0x38, 0x22, 0x22, 0x00, 0x00, 0x02, 0x02, 0x04, 0x04, 0x10, 0x10, 0xe7, 0xe7, 0xef, 0xef, 0x9c, 0x9c, 0xbc, 0xbc, 0x38, 0x38, 0xb0, 0xb0, 0x80, 0x80, 0x30, 0x30, 0x60, 0x60, 0x40, 0x40, 0xc0, 0xc0, 0x80, 0x80, 0x21, 0x21, 0x6d, 0x6d, 0x69, 0x69, 0x0b, 0x0b, 0x63, 0x63, 0x00, 0x00, 0x20, 0x20, 0x11, 0x11, 0x0e, 0x0e, 
0x40, 0x40, 0x21, 0x21, 0x1e, 0x1e, 0x80, 0x80, 0x43, 0x43, 0x3c, 0x3c, 0x01, 0x01, 0x43, 0x43, 0x3d, 0x3d, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01, 0xc0, 0xc0, 0x60, 0x60, 0x70, 0x70, 0x09, 0x09, 0x01, 0x01, 0x07, 0x07, 0x04, 0x04, 0xe4, 0xe4, 0xf7, 0xf7, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0x1c, 0x1c, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x02, 0x02, 0x09, 0x09, 0x18, 0x18, 0x10, 0x10, 0x90, 0x90, 0x58, 0x58, 0x7d, 0x7d, 0x03, 0x03, 0x03, 0x03, 0x0e, 0x0e, 0x20, 0x20, 0x60, 0x60, 0x10, 0x10, 0x18, 0x18, 0x18, 0x18, 0x08, 0x08, 0x8c, 0x8c, 0xde, 0xde, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
int bonesX = 30;
int bonesY = 20;
byte bonesSpriteNumber = 0;


void setup() {
  arduboy.begin();
  arduboy.setFrameRate(60);
  arduboy.clear();
}


void loop() {
  
  if (!arduboy.nextFrame()) {
    return;
  }

  arduboy.clear();

  if (arduboy.everyXFrames(30)) {
    questorSpriteNumber++;
    bonesSpriteNumber++;
  }

  if (questorSpriteNumber > 3) {
    questorSpriteNumber = 0;  
  }   
  
  if (bonesSpriteNumber > 2) {
    bonesSpriteNumber = 0;  
  }

  drawQuestor(questorX, questorY); 
  drawQuestor(questorX, questorY - 8); 
  drawQuestor(questorX + 8, questorY); 
  drawQuestor(questorX + 8, questorY - 8); 

  Sprites::drawPlusMask(bonesX, bonesY, bones_plus_mask, bonesSpriteNumber);
  
  arduboy.display();

}

void drawQuestor(uint8_t x, uint8_t y)
{
  Sprites::drawPlusMask(x, y, questor_plus_mask, questorSpriteNumber); 
}

Also note that I removed the Sprites instance. Most people don’t realise, but every function inside Sprites is actually a static function that can be called without needing a Sprites object. This shouldn’t have much impact on the resulting code though, it just means the 1-byte variable sprites isn’t wasting a byte of dynamic memory.

If I remember where I’ve seen this bug before or encounter it again, I’ll let you know, but for now any variation of this temporary hack should work fine. It’s not ideal, but I’m fairly certain this is an Arduino compiler bug, so there’s not much that can be done to avoid it.

1 Like

Thank you @Pharap for your comments and suggestions.

I can see your example working with the quester and bones sprites.

The game also uses two other sprites, questorAxe and questorAxeThrown, unfortunately when I add these in I see the same issue with bones getting scrambled.

This is what I am trying now:

#include <Arduboy2.h>
Arduboy2 arduboy;
//Sprites sprites;

const unsigned char questor_plus_mask[] PROGMEM = {
  // width, height,
  6, 8,
  // FRAME 00
  0x10, 0x10, 0xff, 0xff, 0x7d, 0x7f, 
  0x7f, 0x7f, 0xfd, 0xff, 0x10, 0x10, 
  // FRAME 01
  0x10, 0x10, 0x7f, 0x7f, 0xfd, 0xff, 
  0x7f, 0x7f, 0xfd, 0xff, 0x10, 0x10, 
  // FRAME 02
  0x10, 0x10, 0xff, 0xff, 0x7d, 0x7f, 
  0xff, 0xff, 0x7d, 0x7f, 0x10, 0x10, 
  // FRAME 03
  0x08, 0x08, 0x7f, 0x7f, 0xfd, 0xff, 
  0xff, 0xff, 0x7d, 0x7f, 0x08, 0x08,
};
int questorX = 0;
int questorY = 50;
byte questorSpriteNumber = 0;

const unsigned char bones_plus_mask[] PROGMEM = {
// width, height,
74, 48,
// FRAME 00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x83, 0x83, 0xc2, 0xc2, 0xf7, 0xf7, 0xb7, 0xf7, 0x16, 0xf6, 0xb4, 0xf4, 0xf0, 0xf0, 0xf1, 0xf1, 0xe2, 0xe2, 0xe3, 0xe3, 0xff, 0xff, 0xfe, 0xfe, 0x34, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xe0, 0xe0, 0xc0, 0xc0, 0x70, 0x70, 0x20, 0x20, 0x60, 0x60, 0xf0, 0xf0, 0x40, 0x40, 0xc0, 0xc0, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x31, 0x31, 0x23, 0x23, 0x39, 0x39, 0x33, 0x33, 0x39, 0x39, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x1f, 0x1f, 0xbf, 0xbf, 0xff, 0xff, 0x53, 0x53, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x07, 0x07, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x82, 0x97, 0x97, 0xfe, 0xfe, 0x54, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0x40, 0x40, 0x08, 0x08, 0xc4, 0xc4, 0x18, 0x18, 0x60, 0x60, 0x08, 0x08, 0xf8, 0xf8, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x32, 0x19, 0x19, 0x3b, 0x3b, 0xd0, 0xd0, 0x80, 0x80, 0x10, 0x10, 0xd0, 0xd0, 0xf8, 0xf8, 0xf8, 0xf8, 0xfc, 0xfc, 0xf8, 0xf8, 0x70, 0x70, 0x60, 0x60, 
0x70, 0x70, 0xe0, 0xe0, 0x70, 0x70, 0x60, 0x60, 0xc0, 0xc0, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, 0xc0, 0xc0, 0x40, 0x40, 0xc0, 0xc0, 0xc0, 0xc0, 0x92, 0x92, 0xb7, 0xb7, 0x36, 0x36, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x10, 0x10, 0x38, 0x38, 0x22, 0x22, 0x00, 0x00, 0x02, 0x02, 0x04, 0x04, 0x10, 0x10, 0xe7, 0xe7, 0xef, 0xef, 0x9c, 0x9c, 0xbc, 0xbc, 0x38, 0x38, 0xb0, 0xb0, 0x80, 0x80, 0x30, 0x30, 0x60, 0x60, 0x40, 0x40, 0xc0, 0xc0, 0x80, 0x80, 0x21, 0x21, 0x6d, 0x6d, 0x69, 0x69, 0x0b, 0x0b, 0x63, 0x63, 0x00, 0x00, 0x20, 0x20, 0x11, 0x11, 0x0e, 0x0e, 
0x40, 0x40, 0x21, 0x21, 0x1e, 0x1e, 0x80, 0x80, 0x43, 0x43, 0x3c, 0x3c, 0x01, 0x01, 0x43, 0x43, 0x3d, 0x3d, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01, 0xc0, 0xc0, 0x60, 0x60, 0x70, 0x70, 0x09, 0x09, 0x01, 0x01, 0x07, 0x07, 0x04, 0x04, 0xe4, 0xe4, 0xf7, 0xf7, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0x1c, 0x1c, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x02, 0x02, 0x09, 0x09, 0x18, 0x18, 0x10, 0x10, 0x90, 0x90, 0x58, 0x58, 0x7d, 0x7d, 0x03, 0x03, 0x03, 0x03, 0x0e, 0x0e, 0x20, 0x20, 0x60, 0x60, 0x10, 0x10, 0x18, 0x18, 0x18, 0x18, 0x08, 0x08, 0x8c, 0x8c, 0xde, 0xde, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
// FRAME 01
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x83, 0x83, 0xc2, 0xc2, 0xf7, 0xf7, 0xb7, 0xf7, 0x16, 0xf6, 0xb4, 0xf4, 0xf0, 0xf0, 0xf1, 0xf1, 0xe2, 0xe2, 0xe3, 0xe3, 0xff, 0xff, 0xfe, 0xfe, 0x34, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xe0, 0xe0, 0xc0, 0xc0, 0x70, 0x70, 0x20, 0x20, 0x60, 0x60, 0xf0, 0xf0, 0x40, 0x40, 0xc0, 0xc0, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x31, 0x31, 0x23, 0x23, 0x39, 0x39, 0x33, 0x33, 0x39, 0x39, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x1f, 0x1f, 0xbf, 0xbf, 0xff, 0xff, 0x53, 0x53, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x07, 0x07, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x82, 0x97, 0x97, 0xfe, 0xfe, 0x54, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x32, 0x19, 0x19, 0x3b, 0x3b, 0xd0, 0xd0, 0x80, 0x80, 0x10, 0x10, 0xd0, 0xd0, 0xf8, 0xf8, 0xf8, 0xf8, 0xfc, 0xfc, 0xf8, 0xf8, 0x70, 0x70, 0x60, 0x60, 
0x70, 0x70, 0xe0, 0xe0, 0x70, 0x70, 0x60, 0x60, 0xc0, 0xc0, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, 0xc0, 0xc0, 0x40, 0x40, 0xc0, 0xc0, 0xc0, 0xc0, 0x92, 0x92, 0xb7, 0xb7, 0x36, 0x36, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x20, 0x20, 0xd0, 0xd0, 0x28, 0x28, 0x20, 0x20, 0x4c, 0x4c, 0xb4, 0xb4, 0xc4, 0xc4, 0xb8, 0xb8, 0x60, 0x60, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xc9, 0xc9, 0x7d, 0x7d, 0x39, 0x39, 0x0b, 0x0b, 0x63, 0x63, 0x00, 0x00, 0x20, 0x20, 0x11, 0x11, 0x0e, 0x0e, 
0x40, 0x40, 0x21, 0x21, 0x1e, 0x1e, 0x80, 0x80, 0x43, 0x43, 0x3c, 0x3c, 0x01, 0x01, 0x43, 0x43, 0x3d, 0x3d, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01, 0xc0, 0xc0, 0x60, 0x60, 0x70, 0x70, 0x09, 0x09, 0x01, 0x01, 0x07, 0x07, 0x04, 0x04, 0xe4, 0xe4, 0xf7, 0xf7, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x09, 0x09, 0x13, 0x13, 0x17, 0x17, 0x1c, 0x1c, 0x1b, 0x1b, 0x17, 0x17, 0x17, 0x17, 0x0f, 0x0f, 0x06, 0x06, 0x00, 0x00, 0x19, 0x19, 0x17, 0x17, 0x06, 0x06, 0x0e, 0x0e, 0x06, 0x06, 0x04, 0x04, 0x02, 0x02, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00, 0x03, 0x03, 0x01, 0x01, 0x80, 0x80, 0xc0, 0xc0, 0x1c, 0x1c, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x02, 0x02, 0x09, 0x09, 0x18, 0x18, 0x10, 0x10, 0x90, 0x90, 0x58, 0x58, 0x7d, 0x7d, 0x03, 0x03, 0x03, 0x03, 0x0e, 0x0e, 0x20, 0x20, 0x60, 0x60, 0x10, 0x10, 0x18, 0x18, 0x18, 0x18, 0x08, 0x08, 0x8c, 0x8c, 0xde, 0xde, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
// FRAME 02
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x83, 0x83, 0xc2, 0xc2, 0xf7, 0xf7, 0xb7, 0xf7, 0x16, 0xf6, 0xb4, 0xf4, 0xf0, 0xf0, 0xf1, 0xf1, 0xe2, 0xe2, 0xe3, 0xe3, 0xff, 0xff, 0xfe, 0xfe, 0x34, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0x40, 0x40, 0x30, 0x30, 0x60, 0x60, 0x10, 0x10, 0x18, 0x18, 0x10, 0x10, 0x30, 0x30, 0x10, 0x10, 0x10, 0x10, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x31, 0x31, 0x23, 0x23, 0x39, 0x39, 0x33, 0x33, 0x39, 0x39, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x1f, 0x1f, 0xbf, 0xbf, 0xff, 0xff, 0x53, 0x53, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0xf2, 0xf2, 0xbe, 0xbe, 0x0f, 0x0f, 0x0b, 0x0b, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0x40, 0x40, 0x08, 0x08, 0xc4, 0xc4, 0x18, 0x18, 0x60, 0x60, 0x08, 0x08, 0xf8, 0xf8, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x32, 0x19, 0x19, 0x3b, 0x3b, 0xd0, 0xd0, 0x80, 0x80, 0x10, 0x10, 0xd0, 0xd0, 0xf8, 0xf8, 0xf8, 0xf8, 0xfc, 0xfc, 0xf8, 0xf8, 0x70, 0x70, 0x60, 0x60, 
0x70, 0x70, 0xe0, 0xe0, 0x70, 0x70, 0x60, 0x60, 0xc0, 0xc0, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, 0xc0, 0xc0, 0x40, 0x40, 0xc0, 0xc0, 0xc0, 0xc0, 0x90, 0x90, 0xb5, 0xb5, 0x37, 0x37, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x10, 0x10, 0x38, 0x38, 0x22, 0x22, 0x00, 0x00, 0x02, 0x02, 0x04, 0x04, 0x10, 0x10, 0xe7, 0xe7, 0xef, 0xef, 0x9c, 0x9c, 0xbc, 0xbc, 0x38, 0x38, 0xb0, 0xb0, 0x80, 0x80, 0x30, 0x30, 0x60, 0x60, 0x40, 0x40, 0xc0, 0xc0, 0x80, 0x80, 0x21, 0x21, 0x6d, 0x6d, 0x69, 0x69, 0x0b, 0x0b, 0x63, 0x63, 0x00, 0x00, 0x20, 0x20, 0x11, 0x11, 0x0e, 0x0e, 
0x40, 0x40, 0x21, 0x21, 0x1e, 0x1e, 0x80, 0x80, 0x43, 0x43, 0x3c, 0x3c, 0x01, 0x01, 0x43, 0x43, 0x3d, 0x3d, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01, 0xc0, 0xc0, 0x60, 0x60, 0x70, 0x70, 0x09, 0x09, 0x01, 0x01, 0x07, 0x07, 0x04, 0x04, 0xe4, 0xe4, 0xf7, 0xf7, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0x1c, 0x1c, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x02, 0x02, 0x09, 0x09, 0x18, 0x18, 0x10, 0x10, 0x90, 0x90, 0x58, 0x58, 0x7d, 0x7d, 0x03, 0x03, 0x03, 0x03, 0x0e, 0x0e, 0x20, 0x20, 0x60, 0x60, 0x10, 0x10, 0x18, 0x18, 0x18, 0x18, 0x08, 0x08, 0x8c, 0x8c, 0xde, 0xde, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
int bonesX = 30;
int bonesY = 20;
byte bonesSpriteNumber = 0;

const unsigned char PROGMEM axe_plus_mask[] = {
  // width, height,
  5, 8,
  // FRAME 00
  0x00, 0x00, 0x3e, 0x3e, 0x06, 
  0x06, 0x00, 0x00, 0x00, 0x00,   
  // FRAME 01
  0x10, 0x10, 0x12, 0x12, 0x12, 
  0x12, 0x34, 0x34, 0x30, 0x30,
};
int axeX = 0;
int axeY = 50;
byte axeSpriteNumber = 0;

const unsigned char PROGMEM axeThrown_plus_mask[] = {
  // width, height,
  5, 8,
  // FRAME 00
  0x03, 0x03, 0x1f, 0x1f, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 
  // FRAME 01
  0x04, 0x04, 0x04, 0x04, 0x04, 
  0x04, 0x0c, 0x0c, 0x0c, 0x0c, 
  // FRAME 02
  0x00, 0x00, 0x18, 0x18, 0x1f, 
  0x1f, 0x00, 0x00, 0x00, 0x00, 
  // FRAME 03
  0x0c, 0x0c, 0x0c, 0x0c, 0x08, 
  0x08, 0x08, 0x08, 0x08, 0x08, 
  // FRAME 04
  0x00, 0x00, 0x1f, 0x1f, 0x03, 
  0x03, 0x00, 0x00, 0x00, 0x00,
};
byte axeThrownSpriteNumber = 0;
int axeThrownX = 0;
int axeThrownY = 50;

void setup() {
  arduboy.begin();
  arduboy.setFrameRate(60);
  arduboy.clear();
}


void loop() {
  
  if (!arduboy.nextFrame()) {
    return;
  }

  arduboy.clear();

  if (arduboy.everyXFrames(30)) {
    questorSpriteNumber++;
    bonesSpriteNumber++;
    axeSpriteNumber++;
    axeThrownSpriteNumber++;
  }

  if (questorSpriteNumber > 3) {
    questorSpriteNumber = 0;  
  }   
  
  if (bonesSpriteNumber > 2) {
    bonesSpriteNumber = 0;  
  }

  if (axeSpriteNumber > 1) {
    axeSpriteNumber = 0;
  }

  if (axeThrownSpriteNumber > 4) {
    axeThrownSpriteNumber = 0;
  }

  drawQuestor(questorX, questorY); 
  drawQuestor(questorX + 8, questorY); 
  drawQuestor(questorX + 16, questorY); 
  drawQuestor(questorX + 24, questorY); 

  drawBones(0,0);
  drawBones(64,0);

  drawAxe(axeX + 48, axeY);
  
  drawAxeThrown(axeThrownX + 56, axeThrownY); 
  
  arduboy.display();

}

void drawQuestor(uint8_t x, uint8_t y)
{
  Sprites::drawPlusMask(x, y, questor_plus_mask, questorSpriteNumber); 
}

void drawBones(uint8_t x, uint8_t y)
{
  Sprites::drawPlusMask(x, y, bones_plus_mask, bonesSpriteNumber); 
}

void drawAxe(uint8_t x, uint8_t y) {
  Sprites::drawPlusMask(x, y, axe_plus_mask, axeSpriteNumber);
}

void drawAxeThrown(uint8_t x, uint8_t y) {
  Sprites::drawPlusMask(x, y, axeThrown_plus_mask, axeThrownSpriteNumber);
}

I’ve attempted changing the order of the functions, including some draws in functions and some in the loop but no variation seems to resolve the issue. The 3 small sprites all animate fine, just poor bones who is muddled.

If you comment out the two new sprite functions…

  // drawAxe(axeX + 48, axeY);
  
  // drawAxeThrown(axeThrownX + 56, axeThrownY); 

…then you can see 4 questors and 2 bones all animating happily.

Tomorrow I was going to see if saving each animation frame as a separate sprite and then swapping sprites, rather than sprite frames, would make a difference. If that doesn’t work I could go back to using drawBitmap and see if that helps.

The game just needs one instance of each sprite (questor, questorAxe, questorAxeThrown and bones) drawn on screen together.

Are there any other options for animating sprites?

I did some digging.

I tried adding another call to another Sprites function (drawOverwrite) and it managed to prevent the bug, which indicates it’s a case of something being optimised in a way that’s causing side effects that it shouldn’t be.

I followed a hunch and played around with the library source code. The main functions (drawPlusMask, drawOverwrite, drawSelfMasked etc) all delegate themselves to another function called draw which in turn calls drawBitmap.

I discovered that applying __attribute__((noinline)) (a special compiler-specific command that stops the compiler from inlining the function) to the drawBitmap function prevented the bug completely.

So on line 230 of Sprites.h, changing the code to this:

__attribute__((noinline)) static void drawBitmap(int16_t x, int16_t y,
                           const uint8_t *bitmap, const uint8_t *mask,
                           uint8_t w, uint8_t h, uint8_t draw_mode);

Solved it.

That’s not an ideal solution though because it means you’re using a modified library to run your game. You’d either have to use some of the other drawing functions to force drawBitmap to be generated properly, supply a custom version of Arduboy2 (or maybe just the Sprites part) with your game, or ask the person in charge of the library if they can investigate and fix this bug.

It does mean you don’t have to go wrapping everything in individual functions though, you can go back to using drawPlusMask normally.

As far as I’m aware, there’s just the Sprites functions that support frame numbers and the regular drawing functions.


And one last thing, regarding your code, older versions of the IDE might not be able to handle where you’ve put PROGMEM. The Arduino page about progmem says:

Note that because PROGMEM is a variable modifier, there is no hard and fast rule about where it should go, so the Arduino compiler accepts all of the definitions below, which are also synonymous. However experiments have indicated that, in various versions of Arduino (having to do with GCC version), PROGMEM may work in one location and not in another. The “string table” example below has been tested to work with Arduino 13. Earlier versions of the IDE may work better if PROGMEM is included after the variable name.

const dataType variableName[] PROGMEM = {};   // use this form
const PROGMEM  dataType  variableName[] = {}; // or this form
const dataType PROGMEM variableName[] = {};   // not this one

It’s not critical, but just to let you know in case you ever run into any issues doing it that way.


P.S. Nice sprites.

1 Like

It may not be a compiler optimisation problem but instead a problem with improper assembler code.

@Dreamer3 recently rewrote parts of the Sprites drawPlusMask() function in assembler. While testing his code, I found problems where compiler errors were generated in some circumstances. @Dreamer3 fixed this by adding code with the following comment (starting at line 349 in Sprites.cpp):

        // declaring an extra high register clobber here for some reason
        // prevents a compile error for some sketches:
        // can't find a register in class 'LD_REGS' while reloading 'asm'
        : "r24"

This probably just masked the actual problem, which is now manifesting itself in a different way under different situations. It’s likely due to improper handling of the registers, just as @Pharap, you found @Dreamer3 had done with the assembler code in the Arduoby2Base class drawPixel() function:

After we solved that problem, armed with my now greater understanding of inline assembler I went back and took a look at the assembler in the Sprites class. I was kind of wary about the code, especially due to the uncertainty of “for some reason” in the comments, but the code is complicated enough that I didn’t really want to spend the time fully analysing it, since there hadn’t been any complaints.

It appears that it would now be a good idea to investigate this assembler code further for problems.

2 Likes

LOL … as you pointed out, that should have rung the alarm bells!

1 Like

Aparently that error message occurs when a block of assembly runs out of registers.

At a guess I’d say it’s possible there’s a register the asm block uses that it doesn’t list as having been clobbered or it uses a register without initialising it to an appropriate value. I suppose the function not being inlined means that certain registers are call-saved, whereas inlining removes that pre-call register saving step, which could indicate it’s one of those registers that’s causing the problem.

Interestingly, the AVR stack frame layout lists Y + 1 as pointing to the bottom of the stack frame, so it’s possible the use of Y could be causing issues, even though it’s saved at the start of the block and restored at the end.

Whatever the problem turns out to be, I think the best fix might be to do what was suggested to the OP in this SO answer and try to split the asm block up into smaller units that cooperate with variables, if at all possible.

1 Like

I remember I didn’t really like the idea of saving then directly using the Y register. I wondered if it would be better to use a constraint like “b” or “e” and let the compiler choose the actual pointer register to use. But at that point I didn’t have the desire or time to analyse and refactor the entire assember routine, so I just “let it ride”. :frowning_face:

I’m still a bit pressed for time lately, so I don’t know when I’ll be able to look into this.

For now, I would make a local copy of Sprites.h and Sprites.cpp and rename them to something like MySprites.h and MySprites.cpp. Then, rename the Sprites class to MySprites in this local copy.

You can now modify the local MySprites class to fix the problem by adding the noinline attribute, or whatever other changes work.

Once a proper fix has been released for the Arduboy2 library, it would just be a matter of changing instances of the MySprites class back to the Sprites class, then deleting MySprites.h and MySprites.cpp and any #includes to MySprites.h

2 Likes

That’s basically the long version of what I meant by

I guess if we both agree that’s a good option then that’s probably what @oldmantom should do.

Anyone else getting the same problem can be referred back here for a temporary solution until the bug is fixed.


For what it’s worth, I had a quick glance over the Sprites code.

I tried swapping Y for X, which corrupted badly, so I looked at the bottom and noticed X is actually already assigned to buffer_ofs. Then I noticed that buffer_page2_ofs was actually assiged to r, so I tried swapping it out for y. Suddenly everything seemed to work fine.

I removed the stuff that was manually saving Y on the stack and copying the contents of buffer_page2_ofs to Y on the assumption the compiler would insert that anyway and it still worked (which implies my assumption is right).

That change fixing the bug could simply be coincidence (like clobbering r24 appears to be), but it might also explain what’s been going wrong. If the compiler didn’t think Y was being clobbered, it could have been trying to use Y itself, perhaps even assigning it to one of the other inputs.

I further removed the r24 clobber and the code was still working, even when running the more advanced sketch using more sprites, and the code size indicates that the function itself is still being inlined (it’s around 10600 bytes as opposed to the 11000 odd that was the case when noinline was forced).

I’m not going to declare it ‘fixed’, but I think the compiler not seeing Y as clobbered explains the corruption and the fact another GPR was being assigned to superfluously store a value that was immediately copied into Y might explain the “oops, you’ve run out of registers” error, so I’d recommend looking into that as a first port of call. The very fact it causes the code to seemingly behave properly is argument enough to examine it further.

And to save you the trouble:

asm volatile(
        "loop_y:\n"
        "loop_x:\n"
        // load bitmap and mask data
        "lpm %A[bitmap_data], Z+\n"
        "lpm %A[mask_data], Z+\n"

        // shift mask and buffer data
        "tst %[yOffset]\n"
        "breq skip_shifting\n"
        "mul %A[bitmap_data], %[mul_amt]\n"
        "movw %[bitmap_data], r0\n"
        "mul %A[mask_data], %[mul_amt]\n"
        "movw %[mask_data], r0\n"


        // SECOND PAGE
        // if yOffset != 0 && sRow < 7
        "cpi %[sRow], 7\n"
        "brge end_second_page\n"
        // then
        "ld %[data], Y\n"
        "com %B[mask_data]\n" // invert high byte of mask
        "and %[data], %B[mask_data]\n"
        "or %[data], %B[bitmap_data]\n"
        // update buffer, increment
        "st Y+, %[data]\n"

        "end_second_page:\n"
        "skip_shifting:\n"


        // FIRST PAGE
        // if sRow >= 0
        "tst %[sRow]\n"
        "brmi skip_first_page\n"
        "ld %[data], %a[buffer_ofs]\n"
        // then
        "com %A[mask_data]\n"
        "and %[data], %A[mask_data]\n"
        "or %[data], %A[bitmap_data]\n"
        // update buffer, increment
        "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"
        "dec %[xi]\n"
        "brne loop_x\n"

        // increment y
        "next_loop_y:\n"
        "dec %[yi]\n"
        "breq finished\n"
        "mov %[xi], %[x_count]\n" // reset x counter
        // sRow++;
        "inc %[sRow]\n"
        "clr __zero_reg__\n"
        // sprite_ofs += (w - rendered_width) * 2;
        "add %A[sprite_ofs], %A[sprite_ofs_jump]\n"
        "adc %B[sprite_ofs], __zero_reg__\n"
        // buffer_ofs += WIDTH - rendered_width;
        "add %A[buffer_ofs], %A[buffer_ofs_jump]\n"
        "adc %B[buffer_ofs], __zero_reg__\n"
        // buffer_ofs_page_2 += WIDTH - rendered_width;
        "add r28, %A[buffer_ofs_jump]\n"
        "adc r29, __zero_reg__\n"

        "rjmp loop_y\n"
        "finished:\n"
        "clr __zero_reg__\n" // just in case
        : [xi] "+&r" (xi),
        [yi] "+&r" (yi),
        [sRow] "+&d" (sRow), // CPI requires an upper register
        [data] "=&r" (data),
        [mask_data] "=&r" (mask_data),
        [bitmap_data] "=&r" (bitmap_data)
        :
        [x_count] "r" (rendered_width),
        [y_count] "r" (loop_h),
        [sprite_ofs] "z" (bofs),
        [buffer_ofs] "x" (Arduboy2Base::sBuffer+ofs),
        [buffer_page2_ofs] "y" (Arduboy2Base::sBuffer+ofs+WIDTH), // Y pointer
        [buffer_ofs_jump] "r" (WIDTH-rendered_width),
        [sprite_ofs_jump] "r" ((w-rendered_width)*2),
        [yOffset] "r" (yOffset),
        [mul_amt] "r" (mul_amt)
      );

Lastly, despite the assembly being a bit messy (I still think refactoring it into blocks of mixed assembly and regular code is a good option to look into when there’s the time to do so), I have to admit that for the most part it looks like @Dreamer3 knew what he was doing and if my little experiment turns out to be a proper fix then it implies this bug was probably just a sleep-deprived oversight.

2 Likes

@Pharap, Thanks a lot for your efforts and experiments regarding this problem. :clap:
I’ll review your work in detail when I get a chance.

@oldmantom, If you follow our advice and implement your own local modified copy of the Arduboy2 Sprites class, would you mind trying @Pharap’s assembler code changes instead of noinline and see if it keeps working as you continue development? This would provide one point of data towards proving that it’s a proper fix.

2 Likes

@Pharap Thank you again, I have it working locally now with MySprites.h and MySprites.cpp

@MLXXXp Thank you too! I have tried both solutions, noinline in Sprites.h and changing the asm volatile in Sprites.cpp instead. Both appear to solve the issue in my initial tests. I’ll continue working on the game with the asm volatile change and see if it holds up.

:sparkles: :confetti_ball: :sparkles: :tada: :sparkles: :confetti_ball: :sparkles:

2 Likes

I retried the assembly I had written and it seems when testing I didn’t attempt to force noinline at the same time. My solution only works when the code is inlined, otherwise there’s a Y-register usage conflict:

I:\Documents\Arduino\libraries\Arduboy2\src\Sprites.cpp: In function 'drawBitmap':

I:\Documents\Arduino\libraries\Arduboy2\src\Sprites.cpp:343:8: error: can't find a register in class 'POINTER_Y_REGS' while reloading 'asm'

       );

        ^

I:\Documents\Arduino\libraries\Arduboy2\src\Sprites.cpp:343:8: error: 'asm' operand has impossible constraints

lto-wrapper: I:\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2/bin/avr-gcc returned 1 exit status

i:/appdata/local/arduino15/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.4-arduino2/bin/../lib/gcc/avr/4.9.2/../../../../avr/bin/ld.exe: error: lto-wrapper failed

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduboy.

Perhaps this is why that value was being loaded into a GPR and then copied into Y.

It’s unfortunate, but I guess two failed approaches probably indicates that using the Y register is probably going to be a no-go.

I’d have a go at refactoring the assembly myself, but I’ve already got a backlog of projects to be finishing.

Maybe the best approach would be to simply forget assembly for now and write a plain old code solution so a bug fix can be applied and come back to the assembly approach when a better solution is available, or at least when somebody has enough time to sit through it.

(That or use the noinline approach. It means the code isn’t portable, but most people compile with gcc anyway, and if needed there’s a VS equivalent of noinline.)

@Pharap, Can you provide sketch code that can be used to demonstrate the problem(s) and verify potential fixes?

I have established that the problem occurs when calling any of the Sprite functions more than once.

Uncommenting any of the commented-out lines should cause the compilation error:

#include <Arduboy2.h>
Arduboy2 arduboy;

const unsigned char PROGMEM image[] =
{
    8, 8,
    0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF
};


void setup()
{
	arduboy.begin();
}

void loop()
{
	if (!(arduboy.nextFrame()))
		return;
    
	arduboy.clear();
	
	Sprites::drawSelfMasked(8, 8, image, 0);
	//Sprites::drawSelfMasked(8, 24, image, 0);
	
	Sprites::drawOverwrite(24, 8, image, 0);
	//Sprites::drawOverwrite(24, 24, image, 0);
	
	Sprites::drawErase(40, 8, image, 0);
	//Sprites::drawErase(40, 24, image, 0);
	
	arduboy.display();
}
1 Like

Do not fear the assembler. It’s hand optimized for a reason - to get the speed required for this. I’ve never seen the compiler optimize memory access with ST + or LD + so that means making this much simpler (by tossing in RAW C) means making it MUCH slower.

If this is true the compiler is more open minded now. At the time it would NEVER give you Y, so the only way to get it was to do this. This (old) way actually increases register pressure by 2 since we need 2 registers for buffer_page2_ofs BEFORE it gets transferred into. If the compiler will now always give Y, then changes along the lines of what you did would definitely be an improvement - because it’s reducing the register pressure.

I’d have to see a PR or diff to bless this fully but seems like we’re headed the right direction if it works for everyone.

I guess as you found that’s not 100% true, but depends on whether the compilers wants to inline (or other things)… but effectively Y isn’t safe to use (in passed args) unless you also force some other things. So that’s why the effort to put it in a temp register then move it into Y manually.

Nothing is wrong with PUSH/POPPING and stealing Y as long as we restore it when we’re done. Likely the issue here is with the input/output operands not being specified properly. I’ll take a closer look.

This routine is impossible optimally to write with all 3 of the “16 bit” registers.

I’ll try to look at this later tonight on the actual hardware. I think the fix is something like:

--- a/src/Sprites.cpp
+++ b/src/Sprites.cpp
@@ -336,12 +336,12 @@ void Sprites::drawBitmap(int16_t x, int16_t y,
         [data] "=&r" (data),
         [mask_data] "=&r" (mask_data),
         [bitmap_data] "=&r" (bitmap_data)
+        [sprite_ofs] "+z" (bofs),
+        [buffer_ofs] "+x" (Arduboy2Base::sBuffer+ofs),
+        [buffer_page2_ofs] "+r" (Arduboy2Base::sBuffer+ofs+WIDTH), // Y pointer
         :
         [x_count] "r" (rendered_width),
         [y_count] "r" (loop_h),
-        [sprite_ofs] "z" (bofs),
-        [buffer_ofs] "x" (Arduboy2Base::sBuffer+ofs),
-        [buffer_page2_ofs] "r" (Arduboy2Base::sBuffer+ofs+WIDTH), // Y pointer
         [buffer_ofs_jump] "r" (WIDTH-rendered_width),
         [sprite_ofs_jump] "r" ((w-rendered_width)*2),
         [yOffset] "r" (yOffset),

We are clobbering X, Y [r], and Z (they are all used as increment/fetch pointers), but not telling the compiler we’re doing that. @Pharap Could you test this and see if it helps?

I tried to get it running, but it wouldn’t compile, and I see why.

To assign something as an output, it has to be an addressable unit (i.e. an ‘lvalue’), the expressions (Arduboy2Base::sBuffer+ofs) and (Arduboy2Base::sBuffer+ofs+WIDTH) do not evaluate to addressable units, (i.e. they are rvalues).


Upon realising this, I took the liberty of introducing two new variables:
uint8_t * xVar = Arduboy2Base::sBuffer + ofs; and uint8_t * yVar = xVar + WIDTH;

And then changing the outputs to:

         [data] "=&r" (data),
         [mask_data] "=&r" (mask_data),
         [bitmap_data] "=&r" (bitmap_data)
+        [sprite_ofs] "+z" (bofs),
+        [buffer_ofs] "+x" (xVar),
+        [buffer_page2_ofs] "+r" (yVar), // Y pointer
         :
         [x_count] "r" (rendered_width),
         [y_count] "r" (loop_h),
-        [sprite_ofs] "z" (bofs),
-        [buffer_ofs] "x" (Arduboy2Base::sBuffer+ofs),
-        [buffer_page2_ofs] "r" (Arduboy2Base::sBuffer+ofs+WIDTH), // Y pointer
         [buffer_ofs_jump] "r" (WIDTH-rendered_width),
         [sprite_ofs_jump] "r" ((w-rendered_width)*2),
         [yOffset] "r" (yOffset),

Sadly whilst the code that broke the ‘fix’ I posted ran (let’s call it ‘the box example’), the original code that brought up the issue (oldmantom’s ‘questor’ code) broke - the image was displaying incorrectly (in a different way to before) and stopped animating after a few seconds, at which point the device locked up and needed the reset button to flash.

I also tried removing the r24 clobber for the hell of it, same result, although interestingly the error that caused that clobber to be needed didn’t seem to crop up.

Update:
Interestingly marking r28 and r29 (the components of y) as ‘clobbered’ got ‘questor’ working, but broke ‘the box example’ (complaints of r28 and r29 not being allowed).