Annotation of Gnu-Mach/chips/bt459.c, revision 1.1.1.1

1.1       root        1: /* 
                      2:  * Mach Operating System
                      3:  * Copyright (c) 1991,1990,1989 Carnegie Mellon University
                      4:  * All Rights Reserved.
                      5:  * 
                      6:  * Permission to use, copy, modify and distribute this software and its
                      7:  * documentation is hereby granted, provided that both the copyright
                      8:  * notice and this permission notice appear in all copies of the
                      9:  * software, derivative works or modified versions, and any portions
                     10:  * thereof, and that both notices appear in supporting documentation.
                     11:  * 
                     12:  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
                     13:  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
                     14:  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
                     15:  * 
                     16:  * Carnegie Mellon requests users of this software to return to
                     17:  * 
                     18:  *  Software Distribution Coordinator  or  [email protected]
                     19:  *  School of Computer Science
                     20:  *  Carnegie Mellon University
                     21:  *  Pittsburgh PA 15213-3890
                     22:  * 
                     23:  * any improvements or extensions that they make and grant Carnegie Mellon
                     24:  * the rights to redistribute these changes.
                     25:  */
                     26: /*
                     27:  *     File: bt459.c
                     28:  *     Author: Alessandro Forin, Carnegie Mellon University
                     29:  *     Date:   9/90
                     30:  *
                     31:  *     Routines for the bt459 RAMDAC   
                     32:  */
                     33: 
                     34: #include <platforms.h>
                     35: 
                     36: #include <chips/bt459.h>
                     37: #include <chips/screen.h>
                     38: 
                     39: #ifdef DECSTATION
                     40: 
                     41: typedef struct {
                     42:        volatile unsigned char  addr_lo;
                     43:        char                                            pad0[3];
                     44:        volatile unsigned char  addr_hi;
                     45:        char                                            pad1[3];
                     46:        volatile unsigned char  addr_reg;
                     47:        char                                            pad2[3];
                     48:        volatile unsigned char  addr_cmap;
                     49:        char                                            pad3[3];
                     50: } bt459_ds_padded_regmap_t;
                     51: #define        bt459_padded_regmap_t   bt459_ds_padded_regmap_t
                     52: 
                     53: #define        mb()    /* no write/read reordering problems */
                     54: 
                     55: #endif /* DECSTATION */
                     56: 
                     57: #ifdef FLAMINGO
                     58: 
                     59: /* Sparse space ! */
                     60: typedef struct {
                     61:        volatile unsigned int   addr_lo;
                     62:        int                                             pad0;
                     63:        volatile unsigned int   addr_hi;
                     64:        int                                             pad1;
                     65:        volatile unsigned int   addr_reg;
                     66:        int                                             pad2;
                     67:        volatile unsigned int   addr_cmap;
                     68:        int                                             pad3;
                     69: } bt459_fl_padded_regmap_t;
                     70: #define        bt459_padded_regmap_t   bt459_fl_padded_regmap_t
                     71: 
                     72: #define mb()   wbflush()
                     73: 
                     74: #endif /* FLAMINGO */
                     75: 
                     76: 
                     77: #ifndef bt459_padded_regmap_t
                     78: typedef bt459_regmap_t bt459_padded_regmap_t;
                     79: #define        wbflush()
                     80: #endif
                     81: 
                     82: /*
                     83:  * Generic register access
                     84:  */
                     85: #define bt459_select_reg_macro(r,n)            \
                     86:        (r)->addr_lo = (n); mb();               \
                     87:        (r)->addr_hi = (n) >> 8;                \
                     88:        wbflush();
                     89: 
                     90: void
                     91: bt459_select_reg(
                     92:        bt459_padded_regmap_t   *regs,
                     93:        int                     regno)
                     94: {
                     95:        bt459_select_reg_macro( regs, regno);
                     96: }
                     97: 
                     98: void 
                     99: bt459_write_reg(
                    100:        bt459_padded_regmap_t   *regs,
                    101:        int                     regno,
                    102:        unsigned char           val)
                    103: {
                    104:        bt459_select_reg_macro( regs, regno );
                    105:        regs->addr_reg = val;
                    106:        wbflush();
                    107: }
                    108: 
                    109: unsigned char
                    110: bt459_read_reg(
                    111:        bt459_padded_regmap_t   *regs,
                    112:        int                     regno)
                    113: {
                    114:        bt459_select_reg_macro( regs, regno );
                    115:        return regs->addr_reg;
                    116: }
                    117: 
                    118: 
                    119: /*
                    120:  * Color map
                    121:  */
                    122: bt459_load_colormap_entry(
                    123:        bt459_padded_regmap_t   *regs,
                    124:        int                     entry,
                    125:        color_map_t             *map)
                    126: {
                    127:        bt459_select_reg(regs, entry & 0xff);
                    128: 
                    129:        regs->addr_cmap = map->red;
                    130:        wbflush();
                    131:        regs->addr_cmap = map->green;
                    132:        wbflush();
                    133:        regs->addr_cmap = map->blue;
                    134:        wbflush();
                    135: }
                    136: 
                    137: bt459_init_colormap(
                    138:        bt459_padded_regmap_t   *regs)
                    139: {
                    140:        register int    i;
                    141: 
                    142:        bt459_select_reg(regs, 0);
                    143:        regs->addr_cmap = 0;
                    144:        wbflush();
                    145:        regs->addr_cmap = 0;
                    146:        wbflush();
                    147:        regs->addr_cmap = 0;
                    148:        wbflush();
                    149: 
                    150:        regs->addr_cmap = 0xff;
                    151:        wbflush();
                    152:        regs->addr_cmap = 0xff;
                    153:        wbflush();
                    154:        regs->addr_cmap = 0xff;
                    155:        wbflush();
                    156: 
                    157:        bt459_select_reg(regs, 255);
                    158:        regs->addr_cmap = 0xff;
                    159:        wbflush();
                    160:        regs->addr_cmap = 0xff;
                    161:        wbflush();
                    162:        regs->addr_cmap = 0xff;
                    163:        wbflush();
                    164: 
                    165: }
                    166: 
                    167: #if    1/*debug*/
                    168: bt459_print_colormap(
                    169:        bt459_padded_regmap_t   *regs)
                    170: {
                    171:        register int    i;
                    172: 
                    173:        for (i = 0; i < 256; i++) {
                    174:                register unsigned char red, green, blue;
                    175: 
                    176:                bt459_select_reg(regs, i);
                    177:                red   = regs->addr_cmap; wbflush();
                    178:                green = regs->addr_cmap; wbflush();
                    179:                blue  = regs->addr_cmap; wbflush();
                    180:                printf("%x->[x%x x%x x%x]\n", i,
                    181:                        red, green, blue);
                    182: 
                    183:        }
                    184: }
                    185: #endif
                    186: 
                    187: /*
                    188:  * Video on/off
                    189:  *
                    190:  * It is unfortunate that X11 goes backward with white@0
                    191:  * and black@1.  So we must stash away the zero-th entry
                    192:  * and fix it while screen is off.  Also must remember
                    193:  * it, sigh.
                    194:  */
                    195: struct vstate {
                    196:        bt459_padded_regmap_t   *regs;
                    197:        unsigned short  off;
                    198: };
                    199: 
                    200: bt459_video_off(
                    201:        struct vstate   *vstate,
                    202:        user_info_t     *up)
                    203: {
                    204:        register bt459_padded_regmap_t  *regs = vstate->regs;
                    205:        unsigned char           *save;
                    206: 
                    207:        if (vstate->off)
                    208:                return;
                    209: 
                    210:        /* Yes, this is awful */
                    211:        save = (unsigned char *)up->dev_dep_2.gx.colormap;
                    212: 
                    213:        bt459_select_reg(regs, 0);
                    214:        *save++ = regs->addr_cmap;
                    215:        *save++ = regs->addr_cmap;
                    216:        *save++ = regs->addr_cmap;
                    217: 
                    218:        bt459_select_reg(regs, 0);
                    219:        regs->addr_cmap = 0;
                    220:        wbflush();
                    221:        regs->addr_cmap = 0;
                    222:        wbflush();
                    223:        regs->addr_cmap = 0;
                    224:        wbflush();
                    225: 
                    226:        bt459_write_reg( regs, BT459_REG_PRM, 0);
                    227:        bt459_write_reg( regs, BT459_REG_CCR, 0);
                    228: 
                    229:        vstate->off = 1;
                    230: }
                    231: 
                    232: bt459_video_on(
                    233:        struct vstate   *vstate,
                    234:        user_info_t     *up)
                    235: {
                    236:        register bt459_padded_regmap_t  *regs = vstate->regs;
                    237:        unsigned char           *save;
                    238: 
                    239:        if (!vstate->off)
                    240:                return;
                    241: 
                    242:        /* Like I said.. */
                    243:        save = (unsigned char *)up->dev_dep_2.gx.colormap;
                    244: 
                    245:        bt459_select_reg(regs, 0);
                    246:        regs->addr_cmap = *save++;
                    247:        wbflush();
                    248:        regs->addr_cmap = *save++;
                    249:        wbflush();
                    250:        regs->addr_cmap = *save++;
                    251:        wbflush();
                    252: 
                    253:        bt459_write_reg( regs, BT459_REG_PRM, 0xff);
                    254:        bt459_write_reg( regs, BT459_REG_CCR, 0xc0);
                    255: 
                    256:        vstate->off = 0;
                    257: }
                    258: 
                    259: /*
                    260:  * Cursor
                    261:  */
                    262: bt459_pos_cursor(
                    263:        bt459_padded_regmap_t   *regs,
                    264:        register int            x,
                    265:        register int            y)
                    266: {
                    267: #define lo(v)  ((v)&0xff)
                    268: #define hi(v)  (((v)&0xf00)>>8)
                    269:        bt459_write_reg( regs, BT459_REG_CXLO, lo(x + 219));
                    270:        bt459_write_reg( regs, BT459_REG_CXHI, hi(x + 219));
                    271:        bt459_write_reg( regs, BT459_REG_CYLO, lo(y + 34));
                    272:        bt459_write_reg( regs, BT459_REG_CYHI, hi(y + 34));
                    273: }
                    274: 
                    275: 
                    276: bt459_cursor_color(
                    277:        bt459_padded_regmap_t   *regs,
                    278:        color_map_t             *color)
                    279: {
                    280:        register int    i;
                    281: 
                    282:        bt459_select_reg_macro( regs, BT459_REG_CCOLOR_2);
                    283:        for (i = 0; i < 2; i++) {
                    284:                regs->addr_reg = color->red;
                    285:                wbflush();
                    286:                regs->addr_reg = color->green;
                    287:                wbflush();
                    288:                regs->addr_reg = color->blue;
                    289:                wbflush();
                    290:                color++;
                    291:        }
                    292: }
                    293: 
                    294: bt459_cursor_sprite(
                    295:        bt459_padded_regmap_t   *regs,
                    296:        unsigned char           *cursor)
                    297: {
                    298:        register int i, j;
                    299: 
                    300:        /*
                    301:         * As per specs, must run a check to see if we
                    302:         * had contention. If so, re-write the cursor.
                    303:         */
                    304:        for (i = 0, j = 0; j < 2; j++) {
                    305:            /* loop once to write */
                    306:            for ( ; i < 1024; i++)
                    307:                bt459_write_reg( regs, BT459_REG_CRAM_BASE+i, cursor[i]);
                    308: 
                    309:            /* loop to check, if fail write again */
                    310:            for (i = 0; i < 1024; i++)
                    311:                if (bt459_read_reg( regs, BT459_REG_CRAM_BASE+i) != cursor[i])
                    312:                        break;
                    313:            if (i == 1024)
                    314:                break;/* all is well now */
                    315:        }
                    316: }
                    317: 
                    318: /*
                    319:  * Initialization
                    320:  */
                    321: bt459_init(
                    322:        bt459_padded_regmap_t   *regs,
                    323:        volatile char           *reset,
                    324:        int                     mux)
                    325: {
                    326:        if (bt459_read_reg(regs, BT459_REG_ID) != 0x4a)
                    327:                panic("bt459");
                    328: 
                    329:        if (mux == 4) {
                    330:                /* use 4:1 input mux */
                    331:                bt459_write_reg( regs, BT459_REG_CMD0, 0x40);
                    332:        } else if (mux == 5) {
                    333:                /* use 5:1 input mux */
                    334:                bt459_write_reg( regs, BT459_REG_CMD0, 0xc0);
                    335:        } /* else donno */
                    336: 
                    337:        *reset = 0;     /* force chip reset */
                    338: 
                    339:        /* no zooming, no panning */
                    340:        bt459_write_reg( regs, BT459_REG_CMD1, 0x00);
                    341: 
                    342:        /* signature test, X-windows cursor, no overlays, SYNC* PLL,
                    343:           normal RAM select, 7.5 IRE pedestal, do sync */
                    344:        bt459_write_reg( regs, BT459_REG_CMD2, 0xc2);
                    345: 
                    346:        /* get all pixel bits */        
                    347:        bt459_write_reg( regs, BT459_REG_PRM,  0xff);
                    348: 
                    349:        /* no blinking */
                    350:        bt459_write_reg( regs, BT459_REG_PBM,  0x00);
                    351: 
                    352:        /* no overlay */
                    353:        bt459_write_reg( regs, BT459_REG_ORM,  0x00);
                    354: 
                    355:        /* no overlay blink */
                    356:        bt459_write_reg( regs, BT459_REG_OBM,  0x00);
                    357: 
                    358:        /* no interleave, no underlay */
                    359:        bt459_write_reg( regs, BT459_REG_ILV,  0x00);
                    360: 
                    361:        /* normal operation, no signature analysis */
                    362:        bt459_write_reg( regs, BT459_REG_TEST, 0x00);
                    363: 
                    364:        /* no blinking, 1bit cross hair, XOR reg&crosshair,
                    365:           no crosshair on either plane 0 or 1,
                    366:           regular cursor on both planes */
                    367:        bt459_write_reg( regs, BT459_REG_CCR,  0xc0);
                    368: 
                    369:        /* home cursor */
                    370:        bt459_write_reg( regs, BT459_REG_CXLO, 0x00);
                    371:        bt459_write_reg( regs, BT459_REG_CXHI, 0x00);
                    372:        bt459_write_reg( regs, BT459_REG_CYLO, 0x00);
                    373:        bt459_write_reg( regs, BT459_REG_CYHI, 0x00);
                    374: 
                    375:        /* no crosshair window */
                    376:        bt459_write_reg( regs, BT459_REG_WXLO, 0x00);
                    377:        bt459_write_reg( regs, BT459_REG_WXHI, 0x00);
                    378:        bt459_write_reg( regs, BT459_REG_WYLO, 0x00);
                    379:        bt459_write_reg( regs, BT459_REG_WYHI, 0x00);
                    380:        bt459_write_reg( regs, BT459_REG_WWLO, 0x00);
                    381:        bt459_write_reg( regs, BT459_REG_WWHI, 0x00);
                    382:        bt459_write_reg( regs, BT459_REG_WHLO, 0x00);
                    383:        bt459_write_reg( regs, BT459_REG_WHHI, 0x00);
                    384: }

unix.superglobalmegacorp.com

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