|
|||
Prex Home / Browse Source - Prex Version: 0.9.0 |
|||
root/bsp/hal/arm/gba/diag.c/* [<][>][^][v][top][bottom][index][help] */DEFINITIONSThis source file includes following definitions.
1 /*- 2 * Copyright (c) 2008, Kohsuke Ohtani 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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. 13 * 3. Neither the name of the author nor the names of any co-contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30 /* 31 * diag.c - diagnostic message support 32 */ 33 34 #include <sys/bootinfo.h> 35 #include <kernel.h> 36 #include <cpufunc.h> 37 38 #ifdef CONFIG_DIAG_SCREEN 39 40 #include "font.h" 41 42 #define VSCR_COLS 32 43 #define SCR_COLS 30 44 #define SCR_ROWS 20 45 46 /* Registers for keypad control */ 47 #define REG_DISPCNT (*(volatile u_short *)0x4000000) 48 #define REG_BG0CNT (*(volatile u_short *)0x4000008) 49 50 #define BG_PALETTE (u_short *)0x5000000 51 #define VRAM_TILE (u_short *)0x6000000 52 #define VRAM_MAP (u_short *)0x6008000 53 54 #define RGB(r, g, b) (((b) << 10) + ((g) << 5) + (r)) 55 56 static u_short *vram = VRAM_MAP; 57 static int pos_x; 58 static int pos_y; 59 60 static void 61 screen_scroll_up(void) 62 { 63 int i; 64 65 for (i = 0; i < VSCR_COLS * (SCR_ROWS - 1); i++) 66 vram[i] = vram[i + VSCR_COLS]; 67 for (i = 0; i < VSCR_COLS; i++) 68 vram[VSCR_COLS * (SCR_ROWS - 1) + i] = ' '; 69 } 70 71 static void 72 screen_newline(void) 73 { 74 75 pos_x = 0; 76 pos_y++; 77 if (pos_y >= SCR_ROWS) { 78 pos_y = SCR_ROWS - 1; 79 screen_scroll_up(); 80 } 81 } 82 83 static void 84 screen_putc(char c) 85 { 86 87 switch (c) { 88 case '\n': 89 screen_newline(); 90 return; 91 case '\r': 92 pos_x = 0; 93 return; 94 case '\b': 95 if (pos_x == 0) 96 return; 97 pos_x--; 98 return; 99 } 100 vram[pos_y * VSCR_COLS + pos_x] = c; 101 pos_x++; 102 if (pos_x >= SCR_COLS) { 103 pos_x = 0; 104 pos_y++; 105 if (pos_y >= SCR_ROWS) { 106 pos_y = SCR_ROWS - 1; 107 screen_scroll_up(); 108 } 109 } 110 } 111 112 /* 113 * Init font 114 */ 115 static void 116 screen_init_font(void) 117 { 118 int i, row, col, bit, val = 0; 119 u_short *tile = VRAM_TILE; 120 121 for (i = 0; i < 256; i++) { 122 for (row = 0; row < 8; row++) { 123 for (col = 7; col >= 0; col--) { 124 bit = (font_bitmap[i][row] & 125 (1 << col)) ? 2 : 1; 126 if (col % 2) 127 val = bit; 128 else { 129 tile[(i * 32) + 130 (row * 4) + ((7 - col) / 2)] = 131 val + (bit << 8); 132 } 133 } 134 } 135 } 136 } 137 138 /* 139 * Init screen 140 */ 141 static void 142 screen_init_screen(void) 143 { 144 u_short *pal = BG_PALETTE; 145 146 /* Initialize palette */ 147 pal[0] = 0; /* Transparent */ 148 pal[1] = RGB(0,0,0); /* Black */ 149 pal[2] = RGB(31,31,31); /* White */ 150 151 /* Setup video */ 152 REG_DISPCNT = 0x0100; /* Mode0, BG0 */ 153 REG_BG0CNT = 0x1080; /* Size0, 256color */ 154 } 155 156 void 157 diag_puts(char *buf) 158 { 159 160 while (*buf) 161 screen_putc(*buf++); 162 } 163 164 /* 165 * Init 166 */ 167 void 168 diag_init(void) 169 { 170 171 screen_init_font(); 172 screen_init_screen(); 173 } 174 175 #endif /* !CONFIG_DIAG_SCREEN */ 176 177 178 #ifdef CONFIG_DIAG_VBA 179 extern void vba_puts(char *); 180 181 void 182 diag_puts(char *str) 183 { 184 185 vba_puts(str); 186 } 187 188 /* 189 * Init 190 */ 191 void 192 diag_init(void) 193 { 194 195 } 196 #endif /* !CONFIG_DIAG_VBA */ /* [<][>][^][v][top][bottom][index][help] */ | |||
Copyright© 2005-2009 Kohsuke Ohtani |