Optimize Tile At 2x2
was  Tile2x2: 64C  62A  5BE  584
now Tile2x2: 426  41C  3E4  3C4
@@ -29,6 +29,7 @@ UBYTE TileAt2x1(UINT16 tx, UINT16 ty) {
return OUT_OF_BOUNDS;
}
+ // Get y_offset with ty * width. Then add tx + collision_ptr offset
collision_ptr_tmp = ty * (UINT16)image_tile_width + tx + collision_ptr;
PUSH_BANK(collision_bank);
@@ -38,24 +39,26 @@ UBYTE TileAt2x1(UINT16 tx, UINT16 ty) {
}
UBYTE TileAt2x2(UINT16 tx, UINT16 ty) {
- UWORD y_offset, y1_offset;
+ UBYTE* collision_ptr_tmp;
UBYTE tile;
// Check tile outside of bounds
if (tx == MAX_UINT16 || tx == image_tile_width || ty == image_tile_height || ty == MAX_UINT16) {
return OUT_OF_BOUNDS;
}
- y_offset = ty * (UINT16)image_tile_width;
- y1_offset = (ty + 1U) * (UINT16)image_tile_width;
+ // Get y_offset with ty * width. Then add tx + collision_ptr offset
+ collision_ptr_tmp = ty * (UINT16)image_tile_width + tx + collision_ptr;
PUSH_BANK(collision_bank);
- tile = (UBYTE) * (collision_ptr + y_offset + tx);
+ tile = (UBYTE) * (collision_ptr_tmp);
if (!tile) {
- tile = (UBYTE) * (collision_ptr + y_offset + (tx + 1U));
+ tile = (UBYTE) * (collision_ptr_tmp + 1U);
if (!tile) {
- tile = (UBYTE) * (collision_ptr + y1_offset + (tx));
+ // add 1 more y_offset
+ collision_ptr_tmp = collision_ptr_tmp + (UINT16)image_tile_width;
+ tile = (UBYTE) * (collision_ptr_tmp);
if (!tile) {
- tile = (UBYTE) * (collision_ptr + y1_offset + (tx + 1U));
+ tile = (UBYTE) * (collision_ptr_tmp + 1U);
}
}
}
