From 85733569674650b80c8af77b58e09389dfae8459 Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Tue, 9 Jun 2015 19:06:40 +0200
Subject: [PATCH] kernel/syscons: Enlarge the font to get as close as possible
 to 80x25.

---
 sys/dev/misc/syscons/sckmsrndr.c | 78 ++++++++++++++++++++++++++++++----------
 sys/dev/misc/syscons/scvidctl.c  |  6 ++++
 sys/dev/misc/syscons/syscons.c   |  6 ++++
 sys/dev/misc/syscons/syscons.h   |  1 +
 4 files changed, 72 insertions(+), 19 deletions(-)

diff --git a/sys/dev/misc/syscons/sckmsrndr.c b/sys/dev/misc/syscons/sckmsrndr.c
index 0091cef..5c691d2 100644
--- a/sys/dev/misc/syscons/sckmsrndr.c
+++ b/sys/dev/misc/syscons/sckmsrndr.c
@@ -126,8 +126,8 @@ kms_draw(scr_stat *scp, int from, int count, int flip)
 	pixel_size = 4;
 
 	draw_pos = sc->fbi->vaddr +
-	    8 * pixel_size * (from % scp->xsize) +
-	    scp->font_size * line_width * (from / scp->xsize);
+	    8 * scp->font_mag * pixel_size * (from % scp->xsize) +
+	    scp->font_mag * scp->font_size * line_width * (from / scp->xsize);
 
 	if (from + count > scp->xsize * scp->ysize)
 		count = scp->xsize * scp->ysize - from;
@@ -147,13 +147,25 @@ kms_draw(scr_stat *scp, int from, int count, int flip)
 		}
 
 		for (j = 0; j < scp->font_size; j++, char_data++) {
-			for (pos = 7; pos >= 0; pos--, p += pixel_size)
-				writel(p, *char_data & (1 << pos) ? fg : bg);
-			p += line_width - 8 * pixel_size;
+			for (pos = 7; pos >= 0; pos--, p += pixel_size * scp->font_mag) {
+				for (int xp = 0; xp < scp->font_mag; xp++) {
+					for (int yp = 0; yp < scp->font_mag; yp++) {
+						writel(p +
+						    xp * pixel_size +
+						    yp * line_width,
+						    *char_data & (1 << pos) ?
+						    fg : bg);
+					}
+				}
+			}
+
+			p += scp->font_mag * line_width -
+			    8 * scp->font_mag * pixel_size;
 		}
-		draw_pos += 8 * pixel_size;
+		draw_pos += 8 * scp->font_mag * pixel_size;
 		if ((i % scp->xsize) == scp->xsize - 1) {
-			draw_pos += (scp->font_size - 1) * line_width +
+			draw_pos +=
+			    (scp->font_size * scp->font_mag - 1) * line_width +
 			    scp->xpad * pixel_size;
 		}
 	}
@@ -173,9 +185,9 @@ draw_kmscursor(scr_stat *scp, int at, int on, int flip)
 	pixel_size = 4;
 
 	draw_pos = sc->fbi->vaddr +
-	    8 * pixel_size * (at % scp->xsize) +
-	    scp->font_size * line_width * (at / scp->xsize) +
-	    (scp->font_size - scp->cursor_base - 1) * line_width;
+	    8 * scp->font_mag * pixel_size * (at % scp->xsize) +
+	    scp->font_mag * scp->font_size * line_width * (at / scp->xsize) +
+	    (scp->font_size - scp->cursor_base - 1) * scp->font_mag * line_width;
 
 	a = sc_vtb_geta(&scp->vtb, at);
 	if (flip) {
@@ -195,9 +207,19 @@ draw_kmscursor(scr_stat *scp, int at, int on, int flip)
 	height = imin(scp->cursor_height, scp->font_size);
 
 	for (i = 0; i < height; i++, char_data--) {
-		for (pos = 7; pos >= 0; pos--, draw_pos += pixel_size)
-			writel(draw_pos, *char_data & (1 << pos) ? fg : bg);
-		draw_pos -= line_width + 8 * pixel_size;
+		for (pos = 7; pos >= 0; pos--, draw_pos += pixel_size * scp->font_mag) {
+			for (int xp = 0; xp < scp->font_mag; xp++) {
+				for (int yp = 0; yp < scp->font_mag; yp++) {
+					writel(draw_pos +
+					    xp * pixel_size +
+					    yp * line_width,
+					    *char_data & (1 << pos) ?
+					    fg : bg);
+				}
+			}
+		}
+		draw_pos -= scp->font_mag * line_width +
+		    8 * scp->font_mag * pixel_size;
 	}
 }
 
@@ -259,17 +281,35 @@ draw_kmsmouse(scr_stat *scp, int x, int y)
 	xend = imin(x + 8, 8 * (scp->xoff + scp->xsize));
 	yend = imin(y + 16, scp->font_size * (scp->yoff + scp->ysize));
 
-	draw_pos = sc->fbi->vaddr + y * line_width + x * pixel_size;
+	draw_pos = sc->fbi->vaddr + y * scp->font_mag * line_width +
+	    x * scp->font_mag * pixel_size;
 
 	for (i = 0; i < (yend - y); i++) {
 		for (j = (xend - x - 1); j >= 0; j--) {
-			if (mouse_or_mask[i] & 1 << (15 - j))
-				writel(draw_pos + pixel_size * j, colormap[15]);
-			else if (mouse_and_mask[i] & 1 << (15 - j))
-				writel(draw_pos + pixel_size * j, colormap[0]);
+			if (mouse_or_mask[i] & 1 << (15 - j)) {
+				for (int xp = 0; xp < scp->font_mag; xp++) {
+					for (int yp = 0; yp < scp->font_mag; yp++) {
+						writel(draw_pos +
+						    scp->font_mag * pixel_size * j +
+						    xp * pixel_size +
+						    yp * line_width,
+						    colormap[15]);
+					}
+				}
+			} else if (mouse_and_mask[i] & 1 << (15 - j)) {
+				for (int xp = 0; xp < scp->font_mag; xp++) {
+					for (int yp = 0; yp < scp->font_mag; yp++) {
+						writel(draw_pos +
+						    scp->font_mag * pixel_size * j +
+						    xp * pixel_size +
+						    yp * line_width,
+						    colormap[0]);
+					}
+				}
+			}
 		}
 
-		draw_pos += line_width;
+		draw_pos += scp->font_mag * line_width;
 	}
 }
 
diff --git a/sys/dev/misc/syscons/scvidctl.c b/sys/dev/misc/syscons/scvidctl.c
index 9a997bd..817c97e 100644
--- a/sys/dev/misc/syscons/scvidctl.c
+++ b/sys/dev/misc/syscons/scvidctl.c
@@ -794,11 +794,17 @@ sc_update_render(scr_stat *scp)
 		scp->status |= UNKNOWN_MODE | MOUSE_HIDDEN;
 		scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE | MOUSE_VISIBLE);
 		scp->model = V_INFO_MM_TEXT;
+		scp->font_mag = 1;
 		scp->xpixel = scp->fbi->width;
 		scp->ypixel = scp->fbi->height;
 		scp->xsize = scp->xpixel / 8;
 		scp->ysize = scp->ypixel / scp->font_size;
 		scp->xpad = scp->fbi->stride / 4 - scp->xsize * 8;
+		while (scp->xsize / (scp->font_mag + 1) >= 80 &&
+		    scp->ysize / (scp->font_mag + 1) >= 25)
+			scp->font_mag++;
+		scp->xsize /= scp->font_mag;
+		scp->ysize /= scp->font_mag;
 
 		/* allocate buffers */
 		sc_alloc_scr_buffer(scp, TRUE, TRUE);
diff --git a/sys/dev/misc/syscons/syscons.c b/sys/dev/misc/syscons/syscons.c
index 2c0d400..5898b55 100644
--- a/sys/dev/misc/syscons/syscons.c
+++ b/sys/dev/misc/syscons/syscons.c
@@ -3191,12 +3191,18 @@ init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
     }
     scp->xoff = scp->yoff = 0;
     scp->xpos = scp->ypos = 0;
+    scp->font_mag = 1;
     scp->fbi = sc->fbi;
     if (scp->fbi != NULL) {
 	scp->xpixel = scp->fbi->width;
 	scp->ypixel = scp->fbi->height;
 	scp->xsize = scp->xpixel / 8;
 	scp->ysize = scp->ypixel / scp->font_size;
+	while (scp->xsize / (scp->font_mag + 1) >= 80 &&
+	    scp->ysize / (scp->font_mag + 1) >= 25)
+		scp->font_mag++;
+	scp->xsize /= scp->font_mag;
+	scp->ysize /= scp->font_mag;
     }
     sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
     sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
diff --git a/sys/dev/misc/syscons/syscons.h b/sys/dev/misc/syscons/syscons.h
index d9bf126..dbb80dd 100644
--- a/sys/dev/misc/syscons/syscons.h
+++ b/sys/dev/misc/syscons/syscons.h
@@ -268,6 +268,7 @@ typedef struct scr_stat {
 
 	u_char		*font;			/* current font */
 	int		font_size;		/* fontsize in Y direction */
+	int		font_mag;		/* font magnification */
 
 	int		start;			/* modified area start */
 	int		end;			/* modified area end */
-- 
2.3.7

