Annotation of XNU/pexpert/i386/display_putc.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      6:  * The contents of this file constitute Original Code as defined in and
                      7:  * are subject to the Apple Public Source License Version 1.1 (the
                      8:  * "License").  You may not use this file except in compliance with the
                      9:  * License.  Please obtain a copy of the License at
                     10:  * http://www.apple.com/publicsource and read it before using this file.
                     11:  * 
                     12:  * This Original Code and all software distributed under the License are
                     13:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
                     14:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
                     15:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
                     16:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
                     17:  * License for the specific language governing rights and limitations
                     18:  * under the License.
                     19:  * 
                     20:  * @APPLE_LICENSE_HEADER_END@
                     21:  */
                     22: #include "debug_font.h"
                     23: 
                     24: 
                     25: #define kNormal  0
                     26: #define kBold    1
                     27: #define kInverse 2
                     28: 
                     29: 
                     30: #define kCharHeight   12 // pixels
                     31: #define kCharWidth     6 // pixels
                     32: #define kHeaderHeight 18 // pixels
                     33: 
                     34: /* Internal routines */
                     35: void init_display_putc(unsigned char *baseaddr, int rowbytes, int height);
                     36: void display_putc(char c);
                     37: void scroll(void);
                     38: void checkXY(void);
                     39: void copyNormalChar(unsigned char *bptr, unsigned char *fptr);
                     40: void copyBoldChar(unsigned char *bptr, unsigned char *fptr);
                     41: void copyInverseChar(unsigned char *bptr, unsigned char *fptr);
                     42: 
                     43: /* globals */
                     44: static unsigned char *gBaseAddr;
                     45: static int gRowBytes, gHeight;
                     46: static int gCursorX, gCursorY;         // Where the cursor is at all times
                     47: static int gMaxX, gMaxY;               // screen limits
                     48: static int gStyle;                     // normal, bold, inverse, etc.
                     49: 
                     50: void init_display_putc(unsigned char *baseaddr, int rowbytes, int height)
                     51: {
                     52:        if (!baseaddr)
                     53:                gBaseAddr  = 0;
                     54:        else
                     55:        {
                     56:                gBaseAddr  = baseaddr;
                     57:                gRowBytes  = rowbytes;
                     58:                gHeight    = height;
                     59:                gCursorX   = 0;
                     60:                gCursorY   = 2;
                     61:                gStyle     = kNormal;
                     62:                gMaxX      = gRowBytes / kCharWidth;
                     63:                gMaxY      = gHeight / kCharHeight;
                     64:        }
                     65: }
                     66: 
                     67: void display_putc(char c)
                     68: {
                     69:        register unsigned char *bptr;
                     70:        register unsigned char *fptr;
                     71: 
                     72: 
                     73:        // handle special characters first
                     74:        switch (c)
                     75:        {
                     76:                case '\t': gCursorX += 4;                               return;
                     77:                case '\b': gCursorX -= 4;                               return;
                     78:                case '\n': gCursorX  = 0; gCursorY++;   return;
                     79:                case '\r': gCursorX  = 0; gCursorY++;   return;
                     80:                case '\300': gStyle = kNormal;                  return;
                     81:                case '\301': gStyle = kBold;                    return;
                     82:                case '\302': gStyle = kInverse;                 return;
                     83:        }
                     84: 
                     85:        // scroll if needed
                     86:        checkXY();
                     87: 
                     88:        // non-printable chars are a space
                     89:        if ((c < 0x20) || (c > 0x7e)) c = 0x20;
                     90: 
                     91:        // our font starts with a space
                     92:        c -= 0x20;
                     93: 
                     94:        bptr = gBaseAddr
                     95:                                 + (gRowBytes * kCharHeight * gCursorY)
                     96:                                 + (kCharWidth * gCursorX);
                     97:        fptr = Font[(int)c];
                     98: 
                     99:        switch (gStyle)
                    100:        {
                    101:                case kNormal:   copyNormalChar(bptr, fptr); break;
                    102:                case kBold:             copyBoldChar(bptr, fptr);       break;
                    103:                case kInverse:  copyInverseChar(bptr, fptr);break;
                    104:        }
                    105:        gCursorX++;
                    106: }
                    107: 
                    108: 
                    109: void checkXY(void)
                    110: {
                    111:        if (gCursorX >= gMaxX)
                    112:        {
                    113:                gCursorX = 0;
                    114:                gCursorY++;
                    115:        }
                    116: 
                    117:        if (gCursorY >= gMaxY)
                    118:        {
                    119:                scroll();
                    120:                gCursorY--;
                    121:        }
                    122: }
                    123: 
                    124: void scroll(void)
                    125: {
                    126:        unsigned long *src;
                    127:        unsigned long *dst;
                    128:        int xlimit  = gRowBytes / 4;
                    129:        int ylimit  = gHeight - kCharHeight - kHeaderHeight;
                    130:        int x,y;
                    131: 
                    132:        src = (unsigned long*)(gBaseAddr + (gRowBytes * (kCharHeight + kHeaderHeight)));
                    133:        dst = (unsigned long*)(gBaseAddr + (gRowBytes * kHeaderHeight));
                    134: 
                    135:        for (y = 0; y < ylimit; y++)
                    136:                for (x = 0; x < xlimit; x++)
                    137:                        *dst++ = *src++;
                    138: }
                    139: 
                    140: void copyNormalChar(register unsigned char *bptr, register unsigned char *fptr)
                    141: {
                    142:        int i;
                    143: 
                    144:        for (i = 0; i < kCharHeight; i++)
                    145:        {
                    146:                *bptr++ = *fptr++; *bptr++ = *fptr++; *bptr++ = *fptr++;
                    147:                *bptr++ = *fptr++; *bptr++ = *fptr++; *bptr++ = *fptr++;
                    148:                bptr += gRowBytes - kCharWidth;
                    149:        }
                    150: }
                    151: 
                    152: void copyBoldChar(register unsigned char *bptr, register unsigned char *fptr)
                    153: {
                    154:        int i;
                    155: 
                    156:        for (i = 0; i < kCharHeight; i++)
                    157:        {
                    158:                *bptr++ = *fptr++; if (!(*fptr)) *(bptr-1) = *fptr;
                    159:                *bptr++ = *fptr++; if (!(*fptr)) *(bptr-1) = *fptr;
                    160:                *bptr++ = *fptr++; if (!(*fptr)) *(bptr-1) = *fptr;
                    161:                *bptr++ = *fptr++; if (!(*fptr)) *(bptr-1) = *fptr;
                    162:                *bptr++ = *fptr++; if (!(*fptr)) *(bptr-1) = *fptr;
                    163:                *bptr++ = *fptr++; if (!(*fptr)) *(bptr-1) = *fptr;
                    164:                bptr += gRowBytes - kCharWidth;
                    165:        }
                    166: }
                    167: 
                    168: void copyInverseChar(register unsigned char *bptr, register unsigned char *fptr)
                    169: {
                    170:        int i;
                    171: 
                    172:        for (i = 0; i < kCharHeight; i++)
                    173:        {
                    174:                *bptr++ = ~(*fptr++);
                    175:                *bptr++ = ~(*fptr++);
                    176:                *bptr++ = ~(*fptr++);
                    177:                *bptr++ = ~(*fptr++);
                    178:                *bptr++ = ~(*fptr++);
                    179:                *bptr++ = ~(*fptr++);
                    180:                bptr += gRowBytes - kCharWidth;
                    181:        }
                    182: }
                    183: 
                    184: 
                    185: #if DEBUG
                    186: void dump_kprintf_state(void)
                    187: {
                    188:        printf("gBaseAddr=%lx\tgRowBytes=%d\tgHeight=%d\tgStyle=%d\n",
                    189:                                        (long)gBaseAddr, gRowBytes, gHeight, gStyle);
                    190: }
                    191: #endif /* DEBUG */
                    192: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.