From eae470221b7b2d440dbfde1c8c6abb92953d3071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=90=D0=BB=D0=B4?= =?UTF-8?q?=D0=B0=D1=88=D0=BA=D0=B8=D0=BD?= Date: Wed, 6 Jul 2022 21:29:15 +0800 Subject: [PATCH] Optimize scrolling Move entire screen, starting from the second line, one line up --- 17-video-scroll/drivers/screen.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/17-video-scroll/drivers/screen.c b/17-video-scroll/drivers/screen.c index 02d4dd7..a31ea10 100644 --- a/17-video-scroll/drivers/screen.c +++ b/17-video-scroll/drivers/screen.c @@ -83,11 +83,9 @@ int print_char(char c, int col, int row, char attr) { /* Check if the offset is over screen size and scroll */ if (offset >= MAX_ROWS * MAX_COLS * 2) { - int i; - for (i = 1; i < MAX_ROWS; i++) - memory_copy(get_offset(0, i) + VIDEO_ADDRESS, - get_offset(0, i-1) + VIDEO_ADDRESS, - MAX_COLS * 2); + memory_copy(get_offset(0, 1) + VIDEO_ADDRESS, + get_offset(0, 0) + VIDEO_ADDRESS, + MAX_COLS * (MAX_ROWS - 1) * 2); /* Blank last line */ char *last_line = get_offset(0, MAX_ROWS-1) + VIDEO_ADDRESS;