Skip to content

Commit

Permalink
Merge pull request #68 from rakslice/misaligned_rows_fix
Browse files Browse the repository at this point in the history
Misaligned rows fix
  • Loading branch information
kanjitalk755 authored Nov 18, 2020
2 parents d0b3dcd + 6b4cc38 commit d547db0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
16 changes: 11 additions & 5 deletions BasiliskII/src/SDL/video_sdl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2397,6 +2397,7 @@ static void update_display_static(driver_base *drv)
const VIDEO_MODE &mode = drv->mode;
int bytes_per_row = VIDEO_MODE_ROW_BYTES;
uint8 *p, *p2;
uint32 x2_clipped, wide_clipped;

// Check for first line from top and first line from bottom that have changed
y1 = 0;
Expand All @@ -2420,9 +2421,11 @@ static void update_display_static(driver_base *drv)
if ((int)VIDEO_MODE_DEPTH < (int)VIDEO_DEPTH_8BIT) {
const int src_bytes_per_row = bytes_per_row;
const int dst_bytes_per_row = drv->s->pitch;
const int pixels_per_byte = VIDEO_MODE_X / src_bytes_per_row;
const int pixels_per_byte = 8/mac_depth_of_video_depth(VIDEO_MODE_DEPTH);

x1 = VIDEO_MODE_X / pixels_per_byte;
const uint32 line_len = TrivialBytesPerRow(VIDEO_MODE_X, VIDEO_MODE_DEPTH);

x1 = line_len;
for (uint32 j = y1; j <= y2; j++) {
p = &the_buffer[j * bytes_per_row];
p2 = &the_buffer_copy[j * bytes_per_row];
Expand All @@ -2440,17 +2443,20 @@ static void update_display_static(driver_base *drv)
p2 = &the_buffer_copy[j * bytes_per_row];
p += bytes_per_row;
p2 += bytes_per_row;
for (uint32 i = (VIDEO_MODE_X / pixels_per_byte); i > x2; i--) {
for (uint32 i = line_len; i > x2; i--) {
p--; p2--;
if (*p != *p2) {
x2 = i;
break;
}
}
}

x1 *= pixels_per_byte;
x2 *= pixels_per_byte;
wide = (x2 - x1 + pixels_per_byte - 1) & -pixels_per_byte;
wide = x2 - x1;
x2_clipped = x2 > VIDEO_MODE_X? VIDEO_MODE_X : x2;
wide_clipped = x2_clipped - x1;

// Update copy of the_buffer
if (high && wide) {
Expand All @@ -2474,7 +2480,7 @@ static void update_display_static(driver_base *drv)
SDL_UnlockSurface(drv->s);

// Refresh display
update_sdl_video(drv->s, x1, y1, wide, high);
update_sdl_video(drv->s, x1, y1, wide_clipped, high);
}

} else {
Expand Down
8 changes: 4 additions & 4 deletions BasiliskII/src/include/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ inline video_depth DepthModeForPixelDepth(int depth)
// Returns the name of a video_depth, or an empty string if the depth is unknown
const char * NameOfDepth(video_depth depth);

// Return a bytes-per-row value (assuming no padding) for the specified depth and pixel width
// Return a bytes-per-row value (assuming enough bytes to fit the bits but no further padding) for the specified depth and pixel width
inline uint32 TrivialBytesPerRow(uint32 width, video_depth depth)
{
switch (depth) {
case VDEPTH_1BIT: return width / 8;
case VDEPTH_2BIT: return width / 4;
case VDEPTH_4BIT: return width / 2;
case VDEPTH_1BIT: return (width + 7) / 8;
case VDEPTH_2BIT: return (width + 3) / 4;
case VDEPTH_4BIT: return (width + 1) / 2;
case VDEPTH_8BIT: return width;
case VDEPTH_16BIT: return width * 2;
case VDEPTH_32BIT: return width * 4;
Expand Down
8 changes: 4 additions & 4 deletions SheepShaver/src/include/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ inline int DepthModeForPixelDepth(int depth)
}
}

// Return a bytes-per-row value (assuming no padding) for the specified depth and pixel width
// Return a bytes-per-row value (assuming enough bytes to fit the bits but no further padding) for the specified depth and pixel width
inline uint32 TrivialBytesPerRow(uint32 width, int mode)
{
switch (mode) {
case APPLE_1_BIT: return width / 8;
case APPLE_2_BIT: return width / 4;
case APPLE_4_BIT: return width / 2;
case APPLE_1_BIT: return (width + 7) / 8;
case APPLE_2_BIT: return (width + 3) / 4;
case APPLE_4_BIT: return (width + 1) / 2;
case APPLE_8_BIT: return width;
case APPLE_16_BIT: return width * 2;
case APPLE_32_BIT: return width * 4;
Expand Down

0 comments on commit d547db0

Please sign in to comment.