[BACK]Return to diag.c CVS log [TXT][DIR] Up to [local] / prex / sys / arch / arm / gba

Annotation of prex/sys/arch/arm/gba/diag.c, Revision 1.1.1.1

1.1       nbrk        1: /*-
                      2:  * Copyright (c) 2005-2006, 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 - GBA screen management
                     32:  */
                     33: #include <kernel.h>
                     34:
                     35: #ifdef DEBUG
                     36:
                     37: #ifdef CONFIG_DIAG_SCREEN
                     38: #include "font.h"
                     39:
                     40: #define VSCR_COLS      32
                     41: #define SCR_COLS       30
                     42: #define SCR_ROWS       20
                     43:
                     44: /* Registers for keypad control */
                     45: #define REG_DISPCNT    (*(volatile u_short *)0x4000000)
                     46: #define REG_BG0CNT     (*(volatile u_short *)0x4000008)
                     47:
                     48: #define BG_PALETTE     (u_short *)0x5000000
                     49: #define VRAM_TILE      (u_short *)0x6000000
                     50: #define VRAM_MAP       (u_short *)0x6008000
                     51:
                     52: #define        RGB(r, g, b)    (((b) << 10) + ((g) << 5) + (r))
                     53:
                     54: static u_short *vram = VRAM_MAP;
                     55: static int pos_x;
                     56: static int pos_y;
                     57:
                     58: static void
                     59: scroll_up(void)
                     60: {
                     61:        int i;
                     62:
                     63:        for (i = 0; i < VSCR_COLS * (SCR_ROWS - 1); i++)
                     64:                vram[i] = vram[i + VSCR_COLS];
                     65:        for (i = 0; i < VSCR_COLS; i++)
                     66:                vram[VSCR_COLS * (SCR_ROWS - 1) + i] = ' ';
                     67: }
                     68:
                     69: static void
                     70: new_line(void)
                     71: {
                     72:
                     73:        pos_x = 0;
                     74:        pos_y++;
                     75:        if (pos_y >= SCR_ROWS) {
                     76:                pos_y = SCR_ROWS - 1;
                     77:                scroll_up();
                     78:        }
                     79: }
                     80:
                     81: static void
                     82: put_char(char ch)
                     83: {
                     84:
                     85:        switch (ch) {
                     86:        case '\n':
                     87:                new_line();
                     88:                return;
                     89:        case '\r':
                     90:                pos_x = 0;
                     91:                return;
                     92:        case '\b':
                     93:                if (pos_x == 0)
                     94:                        return;
                     95:                pos_x--;
                     96:                return;
                     97:        }
                     98:
                     99:        vram[pos_y * VSCR_COLS + pos_x] = ch;
                    100:        pos_x++;
                    101:        if (pos_x >= SCR_COLS) {
                    102:                pos_x = 0;
                    103:                pos_y++;
                    104:                if (pos_y >= SCR_ROWS) {
                    105:                        pos_y = SCR_ROWS - 1;
                    106:                        scroll_up();
                    107:                }
                    108:        }
                    109: }
                    110:
                    111: /*
                    112:  * Init font
                    113:  */
                    114: static void
                    115: init_font(void)
                    116: {
                    117:        int i, row, col, bit, val = 0;
                    118:        u_short *tile = VRAM_TILE;
                    119:
                    120:        for (i = 0; i < 256; i++) {
                    121:                for (row = 0; row < 8; row++) {
                    122:                        for (col = 7; col >= 0; col--) {
                    123:                                bit = (font_bitmap[i][row] & (1 << col)) ? 2 : 1;
                    124:                                if (col % 2)
                    125:                                        val = bit;
                    126:                                else
                    127:                                        tile[(i * 32) + (row * 4) + ((7 - col) / 2)] =
                    128:                                                val + (bit << 8);
                    129:                        }
                    130:                }
                    131:        }
                    132: }
                    133:
                    134: /*
                    135:  * Init screen
                    136:  */
                    137: static void
                    138: init_screen(void)
                    139: {
                    140:        u_short *pal = BG_PALETTE;
                    141:
                    142:        /* Initialize palette */
                    143:        pal[0] = 0;             /* Transparent */
                    144:        pal[1] = RGB(0,0,0);    /* Black */
                    145:        pal[2] = RGB(31,31,31); /* White */
                    146:
                    147:        /* Setup video */
                    148:        REG_DISPCNT = 0x0100;   /* Mode0, BG0 */
                    149:        REG_BG0CNT = 0x1080;    /* Size0, 256color */
                    150: }
                    151: #endif /* CONFIG_DIAG_SCREEN */
                    152:
                    153:
                    154: void
                    155: diag_print(char *buf)
                    156: {
                    157: #ifdef CONFIG_DIAG_SCREEN
                    158:        char *p = buf;
                    159:
                    160:        while (*p)
                    161:                put_char(*p++);
                    162: #endif
                    163:
                    164:        /*
                    165:         * Warning: Enabling CONFIG_DIAG_VBA will cause
                    166:         * hang on actual GBA h/w.
                    167:         */
                    168: #ifdef CONFIG_DIAG_VBA
                    169:        puts(buf);
                    170: #endif
                    171: }
                    172:
                    173: #endif /* DEBUG */
                    174:
                    175: /*
                    176:  * Init
                    177:  */
                    178: void
                    179: diag_init(void)
                    180: {
                    181:
                    182: #ifdef DEBUG
                    183: #ifdef CONFIG_DIAG_SCREEN
                    184:        init_font();
                    185:        init_screen();
                    186: #endif
                    187: #endif
                    188: }
                    189:

CVSweb