d = (void *) c->vc_origin;
s = (void *) c->vc_screenbuf;
- while (count--) {
- scr_memcpyw(d, vgacon_scrollback + soff, c->vc_size_row);
- d += c->vc_size_row;
- soff += c->vc_size_row;
-
- if (soff >= vgacon_scrollback_size)
- soff = 0;
+ if (count) {
+ int copysize;
+ count *= c->vc_size_row;
+ /* how much memory to end of buffer left? */
+ copysize = min(count, vgacon_scrollback_size - soff);
+ scr_memcpyw(d, vgacon_scrollback + soff, copysize);
+ d += copysize;
+ count -= copysize;
+
+ if (count) {
+ scr_memcpyw(d, vgacon_scrollback, count);
+ d += count;
+ }
}
if (diff == c->vc_rows) {
vgacon_cursor(c, CM_MOVE);
} else {
- while (diff--) {
- scr_memcpyw(d, s, c->vc_size_row);
- d += c->vc_size_row;
- s += c->vc_size_row;
- }
+ if (diff)
+ scr_memcpyw(d, s, diff * c->vc_size_row);
}
return 1;