The Pedigree Project  0.1
boot/ppc/Vga.cc
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #include "Vga.h"
21 #include "ppc_font.c"
22 #include "prom.h"
23 
24 const int width = 800;
25 const int height = 600;
26 const int bytes_per_pixel = 4;
27 // extern char *ppc_font;
28 
29 extern void *prom_screen;
30 
31 #define MAKE_16(r, g, b) (((r & 0x1f) << 11) | ((g & 0x1f) << 6) | (b & 0x1f))
32 
33 void vga_putchar(
34  char c, int x, int y, unsigned short f, unsigned short b,
35  unsigned short *buf);
36 
37 void vga_init()
38 {
39  unsigned int addr;
40  prom_getprop(prom_screen, "address", (void *) &addr, 4);
41  // writeHex(addr);
42 
43  // Set device depth here!
44 
45  prom_map(addr, 0xb0000000, 0x01000000);
46  unsigned short *p = (unsigned short *) 0xb0000000;
47  for (int i = 0; i < width * height; i++)
48  {
49  p[i] = MAKE_16(0, 0, 0);
50  }
51  for (int i = 0; i < 0x7f; i++)
52  {
53  vga_putchar(
54  (char) i, (i * 8) % width, 16 * ((i * 8) / width),
55  MAKE_16(i, 0xff, 0x7f - i), MAKE_16(0x00, 0x00, 0x00), p);
56  }
57 }
58 
59 #define FONT_HEIGHT 16
60 void vga_putchar(
61  char c, int x, int y, unsigned short f, unsigned short b,
62  unsigned short *buf)
63 {
64  int idx = ((int) c) * 16;
65  for (int i = 0; i < 16; i++)
66  {
67  unsigned char row = ppc_font[idx + i];
68  for (int j = 0; j < 8; j++)
69  {
70  unsigned short col;
71  if ((row & (0x80 >> j)) != 0)
72  {
73  col = f;
74  }
75  else
76  {
77  col = b;
78  }
79  buf[y * width + i * width + x + j] = col;
80  }
81  }
82 }