examples: Turn some bitshifts into multiplications for clarity

This commit is contained in:
Antonio Niño Díaz 2023-06-05 20:01:20 +01:00
parent 33e9ba783e
commit e3fbe8dbec
9 changed files with 21 additions and 21 deletions

View File

@ -91,7 +91,7 @@ int main(int argc, char **argv)
x[n] = x[n - 1];
y[n] = y[n - 1];
NF_Blend3dSprite(n, n + 1, 31 - (n << 2));
NF_Blend3dSprite(n, n + 1, 31 - (n * 4));
NF_Move3dSprite(n, x[n], y[n]);
}

View File

@ -34,7 +34,7 @@ void hblank_handler(void)
if ((bgx[vline] < 1) || (bgx[vline] > 63))
i[vline] *= -1;
NF_ScrollBg(0, 1, bg_x[1] + ((bgx[vline] >> 3) - 4), 0);
NF_ScrollBg(0, 1, bg_x[1] + ((bgx[vline] / 8) - 4), 0);
}
if ((vline >= 160) && (vline <= 191))
@ -45,7 +45,7 @@ void hblank_handler(void)
if ((bgx[vline] < 1) || (bgx[vline] > (vline - 156)))
i[vline] *= -1;
NF_ScrollBg(0, 0, (bg_x[0] + (((vline - 156) >> 1) - bgx[vline])), 0);
NF_ScrollBg(0, 0, bg_x[0] + (((vline - 156) / 2) - bgx[vline]), 0);
}
}
@ -104,7 +104,7 @@ int main(int argc, char **argv)
// Layer 0 calculations
if ((y >= 160) && (y <= 191))
{
bgx[y] = ((y - 156) >> 1);
bgx[y] = (y - 156) / 2;
i[y] = inc;
inc *= -1;
}

View File

@ -31,7 +31,7 @@ void hblank_handler(void)
if ((bgx[vline] < 1) || (bgx[vline] > 63))
i[vline] *= -1;
NF_ScrollBg(1, 3, ((bgx[vline] >> 3) - 4), 0);
NF_ScrollBg(1, 3, (bgx[vline] / 8) - 4, 0);
}
}

View File

@ -24,7 +24,7 @@ void hblank_handler(void)
// Calculate fade value based on the line
int fade = 0x0F - (((vline + 1) * 16) / 192);
REG_BLDY = fade >> 1; // Top screen
REG_BLDY = fade / 2; // Top screen
REG_BLDY_SUB = fade; // Bottom screen
}
}

View File

@ -39,9 +39,9 @@ void InitAnimatedBg(void)
for (int x = 0; x < MAP_X; x++)
{
// Calculate the map 4x4 region to fill
int start_x = x << 2;
int start_x = x * 4;
int end_x = start_x + 4;
int start_y = y << 2;
int start_y = y * 4;
int end_y = start_y + 4;
// Displacement
@ -58,7 +58,7 @@ void InitAnimatedBg(void)
if (frame > 10)
frame = 10;
NF_SetTileOfMap(1, 3, tile_x, tile_y, (frame << 4) + n);
NF_SetTileOfMap(1, 3, tile_x, tile_y, (frame * 16) + n);
n++;
}
}
@ -86,9 +86,9 @@ void AnimateWater(void)
for (int x = 0; x < MAP_X; x++)
{
// Calculate the map 4x4 region to fill
int start_x = x << 2;
int start_x = x * 4;
int end_x = start_x + 4;
int start_y = y << 2;
int start_y = y * 4;
int end_y = start_y + 4;
// CAlculate the frame to draw
@ -107,7 +107,7 @@ void AnimateWater(void)
{
for (int tile_x = start_x; tile_x < end_x; tile_x++)
{
NF_SetTileOfMap(1, 3, tile_x, tile_y, (WATER_FRAME[x][y] << 4) + n);
NF_SetTileOfMap(1, 3, tile_x, tile_y, (WATER_FRAME[x][y] * 16) + n);
n++;
}
}

View File

@ -123,7 +123,7 @@ int main(int argc, char **argv)
memcpy(NF_16BITS_BACKBUFFER[1] + offset,
NF_BG16B[1].buffer + offset,
(sqr_xb - sqr_xa) << 1);
(sqr_xb - sqr_xa) * 2);
}
}
}

View File

@ -60,7 +60,7 @@ int main(int argc, char **argv)
// Copy palette of the bottom screen to the palette of the backbuffer
for (int n = 0; n < 256; n++)
NF_8BITS_BACKBUFFER[1].pal[n] = *((u16*)(0x05000400 + (n << 1)));
NF_8BITS_BACKBUFFER[1].pal[n] = *((u16*)(0x05000400 + (n * 2)));
// Set last color of the palette to red to draw using read
NF_8BITS_BACKBUFFER[1].pal[255] = RGB15(31, 0, 0);

View File

@ -128,18 +128,18 @@ int main(int argc, char **argv)
// Change the tile under the pointer if the user presses a button
if (keys & KEY_B)
NF_SetTileOfMap(1, 2, x >> 3, y >> 3, 0);
NF_SetTileOfMap(1, 2, x / 8, y / 8, 0);
if (keys & KEY_A)
NF_SetTileOfMap(1, 2, x >> 3, y >> 3, 1);
NF_SetTileOfMap(1, 2, x / 8, y / 8, 1);
if (keys & KEY_Y)
NF_SetTileOfMap(1, 2, x >> 3, y >> 3, 2);
NF_SetTileOfMap(1, 2, x / 8, y / 8, 2);
if (keys & KEY_X)
NF_SetTileOfMap(1, 2, x >> 3, y >> 3, 3);
NF_SetTileOfMap(1, 2, x / 8, y / 8, 3);
NF_UpdateVramMap(1, 2);
// Print the color of the tile under the pointer
int tilenum = NF_GetTileOfMap(1, 2, x >> 3, y >> 3);
int tilenum = NF_GetTileOfMap(1, 2, x / 8, y / 8);
switch (tilenum)
{
case 0:

View File

@ -78,13 +78,13 @@ int main(int argc, char **argv)
{
mini_x = right;
mini_y = (NF_BG16B[0].height * right) / NF_BG16B[0].width;
disp_y = (192 - mini_y) >> 1;
disp_y = (192 - mini_y) / 2;
}
else
{
mini_x = (NF_BG16B[0].width * bottom) / NF_BG16B[0].height;
mini_y = bottom;
disp_x = (256 - mini_x) >> 1;
disp_x = (256 - mini_x) / 2;
}
// Generate thumbnail