void scroll(size_t lines) {
if(!lines) return; /* nothing to scroll */
/* copy memory from "X position = top+lines" to top */
memcpy(video_mem,
video_mem+((SCREENCOLS*lines)<<1),
((SCREENROWS-lines)*SCREENCOLS)<<1);
/* Then zero the other lines below the copied lines, which
is the same amount as the number lines that we've scrolled. */
memsetw(video_mem+(((SCREENROWS-lines)
*SCREENCOLS)<<1), /* multiply by 2 */
((k_text_color_get() & 0x70)<<8) /* fill with bgcolor */,
((SCREENCOLS*lines)) /* amount of lines to copy */);
/* If we're not yet at the top of the screen,
* move the "Y position" up by X lines. */
if(screen_ypos >= lines) screen_ypos -= lines;
}
"((k_text_color_get() & 0x70)<<8)"
well, lets split it of.
0x70 is the equivalent of 01110000b
i have no idea what value k_text_color_get() returns, but lets asume that its 0101 0101b
then
0101 0101b &
0111 0000b ==
0101 0000b
then we take 01010000b and shift it left by 8 bits which basicly just means that we'll add 8 zeroz so we get the result: 0101 0000 0000 0000b which equals 0x5000
thats binary operators for you. as for the function, i think im too drunk to fully comprihend it.
Zacariaz explained the technical working of this part of code.
As far as I can see, it takes the text attribute (fore and background color), takes out the background color and it disables / sets of (or better put: takes out) the blinking bit.
No, the routine is just calculating the background color append it to the null character and writes it to video memory.
In calculating the bg-color the following steps are performed:
- Get color/attribute (Fore and background color)
- Isolate background color (High nibble (and it with 0x70, so the intensity or blinking bit is disabled))
- Shift it one byte, so it will put up the high byte of a word...
It is used in a memset function to copy it into video memory. This means that the calculated backcolor is written to the odd bytes in video memory, so it determines the color of the written character, which, in this case, is left 0. I'd choose the space-character (0x20), but that's a whole different story.