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

Annotation of prex-old/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:  * Warning: Enabling CONFIG_DIAG_VBA will cause hang on actual GBA h/w.
                     38:  */
                     39: #ifdef CONFIG_DIAG_SCREEN
                     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: 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: new_line(void)
                     73: {
                     74:
                     75:        pos_x = 0;
                     76:        pos_y++;
                     77:        if (pos_y >= SCR_ROWS) {
                     78:                pos_y = SCR_ROWS - 1;
                     79:                scroll_up();
                     80:        }
                     81: }
                     82:
                     83: static void
                     84: put_char(char ch)
                     85: {
                     86:
                     87:        switch (ch) {
                     88:        case '\n':
                     89:                new_line();
                     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:
                    101:        vram[pos_y * VSCR_COLS + pos_x] = ch;
                    102:        pos_x++;
                    103:        if (pos_x >= SCR_COLS) {
                    104:                pos_x = 0;
                    105:                pos_y++;
                    106:                if (pos_y >= SCR_ROWS) {
                    107:                        pos_y = SCR_ROWS - 1;
                    108:                        scroll_up();
                    109:                }
                    110:        }
                    111: }
                    112:
                    113: /*
                    114:  * Write
                    115:  */
                    116: void
                    117: diag_print(char *buf)
                    118: {
                    119:
                    120:        while (*buf)
                    121:                put_char(*buf++);
                    122: }
                    123:
                    124: /*
                    125:  * Init font
                    126:  */
                    127: static void
                    128: init_font(void)
                    129: {
                    130:        int i, row, col, bit, val = 0;
                    131:        u_short *tile = VRAM_TILE;
                    132:
                    133:        for (i = 0; i < 256; i++) {
                    134:                for (row = 0; row < 8; row++) {
                    135:                        for (col = 7; col >= 0; col--) {
                    136:                                bit = (font_bitmap[i][row] & (1 << col)) ? 2 : 1;
                    137:                                if (col % 2)
                    138:                                        val = bit;
                    139:                                else
                    140:                                        tile[(i * 32) + (row * 4) + ((7 - col) / 2)] =
                    141:                                                val + (bit << 8);
                    142:                        }
                    143:                }
                    144:        }
                    145: }
                    146:
                    147: /*
                    148:  * Init screen
                    149:  */
                    150: static void
                    151: init_screen(void)
                    152: {
                    153:        u_short *pal = BG_PALETTE;
                    154:
                    155:        /* Initialize palette */
                    156:        pal[0] = 0;             /* Transparent */
                    157:        pal[1] = RGB(0,0,0);    /* Black */
                    158:        pal[2] = RGB(31,31,31); /* White */
                    159:
                    160:        /* Setup video */
                    161:        REG_DISPCNT = 0x0100;   /* Mode0, BG0 */
                    162:        REG_BG0CNT = 0x1080;    /* Size0, 256color */
                    163: }
                    164: #endif /* CONFIG_DIAG_SCREEN */
                    165:
                    166: #endif /* DEBUG */
                    167:
                    168: /*
                    169:  * Init
                    170:  */
                    171: void
                    172: diag_init(void)
                    173: {
                    174:
                    175: #ifdef DEBUG
                    176: #ifdef CONFIG_DIAG_SCREEN
                    177:        init_font();
                    178:        init_screen();
                    179: #endif
                    180: #endif
                    181: }
                    182:

CVSweb