fix masking coords for negative values

This commit is contained in:
wgroeneveld 2018-12-06 14:54:29 +01:00
parent ac801197b4
commit ce5e25d68a
2 changed files with 18 additions and 2 deletions

View File

@ -133,13 +133,13 @@ void Sprite::buildOam(int tileIndex) {
if(!oam) {
this->oam = std::unique_ptr<OBJ_ATTR>(new OBJ_ATTR());
this->oam->attr0 = ATTR0_Y(this->y) |
this->oam->attr0 = ATTR0_Y(this->y & 0x00FF) |
ATTR0_MODE(0) |
(GFX_MODE << 10) |
(MOSAIC_MODE << 12) |
(COLOR_MODE_256 << 13) |
(this->shape_bits << 14);
this->oam->attr1 = this->x |
this->oam->attr1 = (this->x & 0x01FF) |
(AFFINE_FLAG_NONE_SET_YET << 9) |
(HORIZONTAL_FLIP_FLAG << 12) |
(VERTICAL_FLIP_FLAG << 13) |

View File

@ -182,6 +182,12 @@ public:
SpriteWithStubOam() : Sprite(nullptr, imageSize, x, y, SIZE_8_8) {
oam = std::unique_ptr<OBJ_ATTR>(new OBJ_ATTR());
}
OBJ_ATTR* buildOamForTesting() {
buildOam(0);
return oam.get();
}
};
class SpriteSuite : public ::testing::Test {
@ -234,6 +240,16 @@ TEST_F(SpriteSuite, CollidesWith_B_Half_In_A_On_X_Axis_Collides) {
ASSERT_TRUE(a->collidesWith(*b));
}
TEST_F(SpriteSuite, MovesToNegativeCoordsAreMaskedIntoOAM) {
s->moveTo(-10, -15);
auto oam = s->buildOamForTesting();
auto attr0 = std::bitset<16>(oam->attr0).to_string();
auto attr1 = std::bitset<16>(oam->attr1).to_string();
ASSERT_EQ(std::string("0000000011110001"), attr0);
ASSERT_EQ(std::string("0000000111110110"), attr1);
}
TEST_F(SpriteSuite, BuildingWithSize_SetsWidthAndHeight) {
auto s = SpriteBuilder<Sprite>().withSize(SIZE_64_32).buildPtr();
ASSERT_EQ(64, s->getWidth());