2 BootMii - a Free Software replacement for the Nintendo/BroadOn bootloader.
5 Copyright (C) 2009 bLAStY <blasty@bootmii.org>
6 Copyright (C) 2009 John Kelley <wiidev@kelley.ca>
8 # This code is licensed to you under the terms of the GNU GPL, version 2;
9 # see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
12 #include "bootmii_ppc.h"
14 #include "video_low.h"
31 #define CONSOLE_WIDTH 500
32 #define CONSOLE_LINES 10
36 #define CONSOLE_CHAR_HEIGHT 16
37 #define CONSOLE_ROW_HEIGHT (CONSOLE_CHAR_HEIGHT + 1)
39 static u32 *xfb = NULL;
48 static void memcpy32(u32 *dst, u32 *src, u32 count) {
51 sync_after_write((const void *)dst, 4);
58 static void memset32(u32 *dst, u32 setval, u32 count) {
61 sync_after_write((const void *)dst, 4);
67 u32 pal_idx(int i, u8 *pal, u8 *gfx) {
71 return (pal[pidx+0] << 16) | (pal[pidx+1] << 8) | (pal[pidx+2]);
74 int make_yuv(u8 r1, u8 g1, u8 b1, u8 r2, u8 g2, u8 b2) {
75 int y1, cb1, cr1, y2, cb2, cr2, cb, cr;
77 y1 = (299 * r1 + 587 * g1 + 114 * b1) / 1000;
78 cb1 = (-16874 * r1 - 33126 * g1 + 50000 * b1 + 12800000) / 100000;
79 cr1 = (50000 * r1 - 41869 * g1 - 8131 * b1 + 12800000) / 100000;
81 y2 = (299 * r2 + 587 * g2 + 114 * b2) / 1000;
82 cb2 = (-16874 * r2 - 33126 * g2 + 50000 * b2 + 12800000) / 100000;
83 cr2 = (50000 * r2 - 41869 * g2 - 8131 * b2 + 12800000) / 100000;
85 cb = (cb1 + cb2) >> 1;
86 cr = (cr1 + cr2) >> 1;
88 return ((y1 << 24) | (cb << 16) | (y2 << 8) | cr);
91 void fill_rect(int x, int y, int w, int h, u8 r, u8 g, u8 b) {
93 u32 col = make_yuv(r,g,b, r,g,b);
95 fb += ((y + y_add) * (640 >> 1));
98 for(y = 0; y < h; y++) {
99 memset32(fb, col, w >> 1);
104 void gfx_draw_rect(gfx_rect *n) {
111 fb += ((d_rect->y + y_add) * (640 >> 1));
112 fb += (d_rect->x >> 1);
114 for(y = 0; y < d_rect->height; y++) {
115 memcpy32(fb, d_rect->yuv_data + ((d_rect->width >> 1) * y), d_rect->width >> 1);
124 fb += ((CONSOLE_Y+y_add) * (640 >> 1));
125 fb += (CONSOLE_X >> 1);
127 fb += (CONSOLE_ROW_HEIGHT * (640 >> 1));
129 for (y = 0; y < CONSOLE_LINES*CONSOLE_ROW_HEIGHT; y++) {
130 memcpy32(fb - (CONSOLE_ROW_HEIGHT * 320), fb, CONSOLE_WIDTH >> 1);
134 fill_rect(CONSOLE_X, CONSOLE_Y+(CONSOLE_LINES-1)*CONSOLE_ROW_HEIGHT,
135 CONSOLE_WIDTH, CONSOLE_ROW_HEIGHT, 0, 0, 0);
138 void print_str_noscroll(int x, int y, char *str) {
144 for (i = 0; i < strlen(str); i++) {
146 d_char.height = CONSOLE_CHAR_HEIGHT;
149 if (str[i] == '\n') {
150 y += CONSOLE_CHAR_HEIGHT;
155 d_char.yuv_data = font_yuv[ (int)str[i] ];
156 gfx_draw_rect(&d_char);
161 void print_str(const char *str, size_t len) {
167 d_char.height = CONSOLE_CHAR_HEIGHT;
168 d_char.y = CONSOLE_Y + ((CONSOLE_LINES - 1) * CONSOLE_ROW_HEIGHT);
170 for (i = 0; i < len; i++) {
171 d_char.x = CONSOLE_X + (i * 10);
172 d_char.yuv_data = font_yuv[(int) str[i]];
173 gfx_draw_rect(&d_char);
177 int gfx_printf(const char *fmt, ...)
183 memset(buffer, 0, sizeof buffer);
185 i = vsnprintf(buffer, sizeof(buffer), fmt, args);
189 print_str(buffer, i);
190 printf("%s\n", buffer);
197 void font_to_yuv(void) {
199 u8 lr,lg,lb, rr,rg,rb;
201 for (i = 0; i < 255; i++) {
202 font_yuv[i] = (u32*)malloc(8*CONSOLE_CHAR_HEIGHT*2);
204 for (y = 0; y < CONSOLE_CHAR_HEIGHT; y++) {
205 for (x = 0; x < 8; x+=2) {
206 if (((console_font_8x16[(i*CONSOLE_CHAR_HEIGHT)+y] >> (7-x)) & 0x01) == 1) {
207 lr = 255; lg = 255; lb = 255;
209 lr = 0; lg = 0; lb = 0;
212 if (((console_font_8x16[(i*CONSOLE_CHAR_HEIGHT)+y] >> (7-(x+1))) & 0x01) == 1) {
213 rr = 255; rg = 255; rb = 255;
215 rr = 0; rg = 0; rb = 0;
218 font_yuv[i][(y<<2)+(x>>1)] = make_yuv(lr, lg, lb, rr, rg, rb);
224 void init_fb(int vmode) {
227 u32 fill_col = make_yuv(0,0,0, 0,0,0);
232 case VIDEO_640X480_NTSCi_YUV16:
233 case VIDEO_640X480_PAL60_YUV16:
234 case VIDEO_640X480_NTSCp_YUV16:
238 case VIDEO_640X480_PAL50_YUV16:
243 xfb = memalign(32, 640 * (480 + (y_add*2)) * 2);
246 for (i = 0; i < (480 + (y_add*2)) * 2 * (640 >> 1); i++) {
248 sync_after_write(fb, 4);