2 * Copyright (c) 2015 Conrad Meyer <cse.cem@gmail.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/callout.h>
33 #include <sys/kernel.h>
35 #include <sys/systm.h>
36 #include <sys/terminal.h>
38 #include <dev/vt/vt.h>
40 extern const unsigned char vt_beastie_vga16[];
41 extern const unsigned char vt_beastie2_vga16[];
42 extern const unsigned char vt_orb_vga16[];
44 static struct callout vt_splash_cpu_callout;
46 static inline unsigned char
47 vt_vga2bsd(unsigned char vga)
49 static const unsigned char lut[8] = {
62 return (lut[vga & 0x7] | bright);
66 vt_draw_2_vga16_px(struct vt_device *vd, vt_axis_t x, vt_axis_t y,
70 vd->vd_driver->vd_setpixel(vd, x, y, vt_vga2bsd(color >> 4));
71 vd->vd_driver->vd_setpixel(vd, x + 1, y, vt_vga2bsd(color & 0xf));
75 vt_draw_1_logo(struct vt_device *vd, vt_axis_t top, vt_axis_t left)
77 const unsigned char rle_sent = 0x16, *data;
78 unsigned int xy, run, runcolor, i;
80 switch (vt_splash_cpu_style) {
81 case VT_LOGOS_DRAW_ALT_BEASTIE:
82 data = vt_beastie2_vga16;
84 case VT_LOGOS_DRAW_ORB:
87 case VT_LOGOS_DRAW_BEASTIE:
90 data = vt_beastie_vga16;
94 /* Decode basic RLE (gets us to 30-40% of uncompressed data size): */
95 for (i = 0, xy = 0; xy < vt_logo_sprite_height * vt_logo_sprite_width;) {
96 if (data[i] == rle_sent) {
97 runcolor = data[i + 1];
100 for (; run; run--, xy += 2)
101 vt_draw_2_vga16_px(vd,
102 left + (xy % vt_logo_sprite_width),
103 top + (xy / vt_logo_sprite_width),
108 vt_draw_2_vga16_px(vd, left + (xy % vt_logo_sprite_width),
109 top + (xy / vt_logo_sprite_width), data[i]);
118 vtterm_draw_cpu_logos(struct vt_device *vd)
120 unsigned int ncpu, i;
124 ncpu = vt_splash_ncpu;
131 if (vd->vd_driver->vd_drawrect)
132 vd->vd_driver->vd_drawrect(vd, 0, 0, vd->vd_width,
133 vt_logo_sprite_height, 1, TC_BLACK);
135 * Blank is okay because we only ever draw beasties on full screen
138 else if (vd->vd_driver->vd_blank)
139 vd->vd_driver->vd_blank(vd, TC_BLACK);
141 ncpu = MIN(ncpu, vd->vd_width / vt_logo_sprite_width);
142 for (i = 0, left = 0; i < ncpu; left += vt_logo_sprite_width, i++)
143 vt_draw_1_logo(vd, 0, left);
147 vt_fini_logos(void *dummy __unused)
149 struct vt_device *vd;
150 struct vt_window *vw;
157 if (!vt_draw_logo_cpus)
159 if (!vty_enabled(VTY_VT))
166 if ((vd->vd_flags & (VDF_DEAD | VDF_TEXTMODE)) != 0) {
170 vt_draw_logo_cpus = 0;
173 for (i = 0; i < VT_MAXWINDOWS; i++) {
174 vw = vd->vd_windows[i];
177 tm = vw->vw_terminal;
182 vt_termsize(vd, vf, &size);
183 vt_winsize(vd, vf, &wsz);
185 /* Resize screen buffer and terminal. */
186 terminal_mute(tm, 1);
187 vtbuf_grow(&vw->vw_buf, &size, vw->vw_buf.vb_history_size);
188 terminal_set_winsize_blank(tm, &wsz, 0, NULL);
189 terminal_set_cursor(tm, &vw->vw_buf.vb_cursor);
190 terminal_mute(tm, 0);
193 vt_compute_drawable_area(vw);
195 if (vd->vd_curwindow == vw) {
196 vd->vd_flags |= VDF_INVALID;
197 vt_resume_flush_timer(vd, 0);
204 vt_init_logos(void *dummy)
206 struct vt_device *vd;
207 struct vt_window *vw;
213 if (!vty_enabled(VTY_VT))
230 KASSERT((vd->vd_flags & VDF_INITIALIZED) != 0,
231 ("vd %p not initialized", vd));
233 if ((vd->vd_flags & (VDF_DEAD | VDF_TEXTMODE)) != 0)
235 if (vd->vd_height <= vt_logo_sprite_height)
238 vt_draw_logo_cpus = 1;
241 vt_termsize(vd, vf, &size);
242 vt_winsize(vd, vf, &wsz);
244 /* Resize screen buffer and terminal. */
245 terminal_mute(tm, 1);
246 vtbuf_grow(&vw->vw_buf, &size, vw->vw_buf.vb_history_size);
247 terminal_set_winsize_blank(tm, &wsz, 0, NULL);
248 terminal_set_cursor(tm, &vw->vw_buf.vb_cursor);
249 terminal_mute(tm, 0);
252 vt_compute_drawable_area(vw);
254 if (vd->vd_curwindow == vw) {
255 vd->vd_flags |= VDF_INVALID;
256 vt_resume_flush_timer(vd, 0);
259 callout_init(&vt_splash_cpu_callout, 1);
260 callout_reset(&vt_splash_cpu_callout, vt_splash_cpu_duration * hz,
261 vt_fini_logos, NULL);
266 SYSINIT(vt_logos, SI_SUB_CPU + 1, SI_ORDER_ANY, vt_init_logos, NULL);