Adding upstream version 4.00~pre53+dfsg.
[syslinux-debian/hramrach.git] / com32 / lib / sys / vesa / screencpy.c
blob32dce9e6dc10f3ce7414b109225a9848c283b9ff
1 /* ----------------------------------------------------------------------- *
3 * Copyright 2008 H. Peter Anvin - All Rights Reserved
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use,
9 * copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following
12 * conditions:
14 * The above copyright notice and this permission notice shall
15 * be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
26 * ----------------------------------------------------------------------- */
28 #include <inttypes.h>
29 #include <minmax.h>
30 #include <klibc/compiler.h>
31 #include <string.h>
32 #include <com32.h>
33 #include <ilog2.h>
34 #include "vesa.h"
35 #include "video.h"
37 static struct win_info {
38 char *win_base;
39 size_t win_pos;
40 size_t win_size;
41 int win_gshift;
42 int win_num;
43 } wi;
45 void __vesacon_init_copy_to_screen(void)
47 struct vesa_mode_info *const mi = &__vesa_info.mi;
48 int winn;
50 if (mi->mode_attr & 0x0080) {
51 /* Linear frame buffer */
53 wi.win_base = (char *)mi->lfb_ptr;
54 wi.win_size = 1 << 31; /* 2 GB, i.e. one huge window */
55 wi.win_pos = 0; /* Already positioned (only one position...) */
56 wi.win_num = -1; /* Not a window */
57 } else {
58 /* Paged frame buffer */
60 /* We have already tested that *one* of these is usable */
61 if ((mi->win_attr[0] & 0x05) == 0x05 && mi->win_seg[0])
62 winn = 0;
63 else
64 winn = 1;
66 wi.win_num = winn;
67 wi.win_base = (char *)(mi->win_seg[winn] << 4);
68 wi.win_size = mi->win_size << 10;
69 wi.win_gshift = ilog2(mi->win_grain) + 10;
70 wi.win_pos = -1; /* Undefined position */
74 static void set_window_pos(size_t win_pos)
76 static com32sys_t ireg;
78 wi.win_pos = win_pos;
80 if (wi.win_num < 0)
81 return; /* This should never happen... */
83 ireg.eax.w[0] = 0x4F05;
84 ireg.ebx.b[0] = wi.win_num;
85 ireg.edx.w[0] = win_pos >> wi.win_gshift;
87 __intcall(0x10, &ireg, NULL);
90 void __vesacon_copy_to_screen(size_t dst, const uint32_t * src, size_t npixels)
92 size_t win_pos, win_off;
93 size_t win_size = wi.win_size;
94 size_t omask = win_size - 1;
95 char *win_base = wi.win_base;
96 size_t l;
97 size_t bytes = npixels * __vesacon_bytes_per_pixel;
98 char rowbuf[bytes + 4] __aligned(4);
99 const char *s;
101 s = (const char *)__vesacon_format_pixels(rowbuf, src, npixels);
103 while (bytes) {
104 win_off = dst & omask;
105 win_pos = dst & ~omask;
107 if (__unlikely(win_pos != wi.win_pos))
108 set_window_pos(win_pos);
110 l = min(bytes, win_size - win_off);
111 memcpy(win_base + win_off, s, l);
113 bytes -= l;
114 s += l;
115 dst += l;