Home | History | Annotate | Line # | Download | only in dev
grf_rtreg.h revision 1.5
      1 /*	$NetBSD: grf_rtreg.h,v 1.5 1994/10/26 02:03:19 cgd Exp $	*/
      2 
      3 #ifndef _GRF_RTREG_H
      4 #define _GRF_RTREG_H
      5 
      6 /* NOTE: this driver for the MacroSystem Retina board was only possible,
      7          because MacroSystem provided information about the pecularities
      8          of the board. THANKS! Competition in Europe among gfx board
      9          manufacturers is rather tough, so Lutz Vieweg, who wrote the
     10          initial driver, has made an agreement with MS not to document
     11          the driver source (see also his Copyright disclaimer at the
     12          beginning of grf_rt.cc and ite_rt.cc).
     13          -> ALL comments and register defines after
     14 	 -> "/* -------------- START OF CODE -------------- * /"
     15 	 -> have been added by myself (mw) from studying the publically
     16 	 -> available "NCR 77C22E+" Data Manual
     17 
     18 	 Lutz' original driver source (without any of my comments) is
     19 	 available on request. */
     20 
     21 
     22 #if 0
     23 /* these are in dev/devices.h */
     24 
     25 /* definitions to find the autoconfig-board under
     26    AmigaDOS */
     27 
     28 #define RETINA_MANUFACTURER     0x4754
     29 #define RETINA_PRODUCT          6
     30 #define RETINA_SERIALNUMBER     1
     31 #endif
     32 
     33 
     34 /*
     35    For more information on the structure entries take a look at
     36    grf_rt.cc and ite_rt.cc.
     37 */
     38 
     39 struct MonDef {
     40 
     41 	/* first the general monitor characteristics */
     42 
     43 	unsigned long  FQ;
     44 	unsigned char  FLG;
     45 
     46 	unsigned short MW;  /* screen width in pixels */
     47                             /* has to be at least a multiple of 8, */
     48                             /* has to be a multiple of 64 in 256-color mode */
     49                             /* if you want to use some great tricks */
     50                             /* to speed up the vertical scrolling */
     51 	unsigned short MH;  /* screen height in pixels */
     52 
     53 	unsigned short HBS;
     54 	unsigned short HSS;
     55 	unsigned short HSE;
     56 	unsigned short HBE;
     57 	unsigned short HT;
     58 	unsigned short VBS;
     59 	unsigned short VSS;
     60 	unsigned short VSE;
     61 	unsigned short VBE;
     62 	unsigned short VT;
     63 
     64 	unsigned short DEP;  /* Color-depth, 4 for text-mode */
     65                              /* 8 enables 256-color graphics-mode, */
     66                              /* 16 and 24bit gfx not supported yet */
     67 
     68 	unsigned char * PAL; /* points to 16*3 byte RGB-palette data */
     69                              /* use LoadPalette() to set colors 0..255 */
     70                              /* in 256-color-gfx mode */
     71 
     72 	/* all following entries are font-specific in
     73 	   text mode. Make sure your monitor
     74 	   parameters are calculated for the
     75 	   appropriate font width and height!
     76 	*/
     77 
     78        unsigned short  TX;     /* Text-mode (DEP=4):          */
     79                                /* screen-width  in characters */
     80                                /* currently, TX has to be a   */
     81                                /* multiple of 16!             */
     82 
     83                                /* Gfx-mode (DEP > 4)          */
     84                                /* "logical" screen-width,     */
     85                                /* use values > MW to allow    */
     86                                /* hardware-panning            */
     87                                /* has to be a multiple of 8   */
     88 
     89        unsigned short  TY;     /* Text-mode:                  */
     90                                /* screen-height in characters */
     91 
     92                                /* Gfx-mode: "logical" screen  */
     93                                /* height for panning          */
     94 
     95        /* the following values are currently unused for gfx-mode */
     96 
     97 	unsigned short  XY;     /* TX*TY (speeds up some calcs.) */
     98 
     99 	unsigned short  FX;     /* font-width (valid values: 4,7-16) */
    100 	unsigned short  FY;     /* font-height (valid range: 1-32) */
    101 	unsigned char * FData;  /* pointer to the font-data */
    102 
    103 	/* The font data is simply an array of bytes defining
    104 	   the chars in ascending order, line by line. If your
    105 	   font is wider than 8 pixel, FData has to be an
    106 	   array of words. */
    107 
    108 	unsigned short  FLo;    /* lowest character defined */
    109 	unsigned short  FHi;    /* highest char. defined */
    110 
    111 };
    112 
    113 
    114 #if 0
    115 /* Some ready-made MonDef structures are available in grf_rt.cc */
    116 
    117 extern struct MonDef MON_640_512_60;
    118 extern struct MonDef MON_768_600_60;
    119 extern struct MonDef MON_768_600_80;
    120 
    121 /* text-screen resolutions wider than 1024 are currently damaged.
    122    The VRAM access seems to become unstable at higher resolutions.
    123    This may hopefully be subject of change.
    124 */
    125 
    126 extern struct MonDef MON_1024_768_80;
    127 extern struct MonDef MON_1024_1024_59;
    128 
    129 /* WARNING: THE FOLLOWING MONITOR MODES EXCEED THE 90-MHz LIMIT THE PROCESSOR
    130             HAS BEEN SPECIFIED FOR. USE AT YOUR OWN RISK (AND THINK ABOUT
    131             MOUNTING SOME COOLING DEVICE AT THE PROCESSOR AND RAMDAC)!     */
    132 extern struct MonDef MON_1280_1024_60;
    133 extern struct MonDef MON_1280_1024_69;
    134 
    135 /* Default monitor (change if this is too much for your monitor :-)) */
    136 #define DEFAULT_MONDEF	MON_768_600_80
    137 
    138 #else
    139 
    140 /* nothing exported for now... */
    141 
    142 #endif
    143 
    144 /* a standard 16-color palette is available in grf_rt.cc
    145    and used by the standard monitor-definitions above */
    146 extern unsigned char NCRStdPalette[];
    147 
    148 /* The prototypes for C
    149    with a little explanation
    150 
    151 	unsigned char * InitNCR(volatile void * BoardAdress, struct MonDef * md = &MON_640_512_60);
    152 
    153    This routine initialises the Retina hardware, opens a
    154    text- or gfx-mode screen, depending on the the value of MonDef.DEP,
    155    and sets the cursor to position 0.
    156    It takes as arguments a pointer to the hardware-base
    157    address as it is denoted in the DevConf structure
    158    of the AmigaDOS, and a pointer to a struct MonDef
    159    which describes the screen-mode parameters.
    160 
    161    The routine returns 0 if it was unable to open the screen,
    162    or an unsigned char * to the display/attribute memory
    163    when it succeeded. The organisation of the display memory
    164    is a little strange in text-mode (Intel-typically...) :
    165 
    166    Byte  00    01    02    03    04     05    06   etc.
    167        Char0  Attr0  --    --   Char1 Attr1   --   etc.
    168 
    169    You may set a character and its associated attribute byte
    170    with a single word-access, or you may perform to byte writes
    171    for the char and attribute. Each 2. word has no meaning,
    172    and writes to theese locations are ignored.
    173 
    174    The attribute byte for each character has the following
    175    structure:
    176 
    177    Bit  7     6     5     4     3     2     1     0
    178       BLINK BACK2 BACK1 BACK0 FORE3 FORE2 FORE1 FORE0
    179 
    180    Were FORE is the foreground-color index (0-15) and
    181    BACK is the background color index (0-7). BLINK
    182    enables blinking for the associated character.
    183    The higher 8 colors in the standard palette are
    184    lighter than the lower 8, so you may see FORE3 as
    185    an intensity bit. If FORE == 1 or FORE == 9 and
    186    BACK == 0 the character is underlined. Since I don't
    187    think this looks good, it will probably change in a
    188    future release.
    189 
    190    There's no routine "SetChar" or "SetAttr" provided,
    191    because I think it's so trivial... a function call
    192    would be pure overhead. As an example, a routine
    193    to set the char code and attribute at position x,y:
    194    (assumed the value returned by InitNCR was stored
    195     into "DispMem", the actual MonDef struct * is hold
    196     in "MDef")
    197 
    198    void SetChar(unsigned char chr, unsigned char attr,
    199                 unsigned short x, unsigned short y) {
    200 
    201       unsigned struct MonDef * md = MDef;
    202       unsigned char * c = DispMem + x*4 + y*md->TX*4;
    203 
    204       *c++ = chr;
    205       *c   = attr;
    206 
    207    }
    208 
    209    In Gfx-mode, the memory organisation is rather simple,
    210    1 byte per pixel in 256-color mode, one pixel after
    211    each other, line by line.
    212 
    213    Currently, InitNCR() disables the Retina VBLANK IRQ,
    214    but beware: When running the Retina WB-Emu under
    215    AmigaDOS, the VBLANK IRQ is ENABLED.
    216 
    217 	void SetCursorPos(unsigned short pos);
    218 
    219    This routine sets the hardware-cursor position
    220    to the screen location pos. pos can be calculated
    221    as (x + y * md->TY).
    222    Text-mode only!
    223 
    224 	void ScreenUp(void);
    225 
    226    A somewhat optimized routine that scrolls the whole
    227    screen up one row. A good idea to compile this piece
    228    of code with optimization enabled.
    229    Text-mode only!
    230 
    231 	void ScreenDown(void);
    232 
    233    A somewhat optimized routine that scrolls the whole
    234    screen down one row. A good idea to compile this piece
    235    of code with optimization enabled.
    236    Text-mode only!
    237 
    238 	unsigned char * SetSegmentPtr(unsigned long adress);
    239 
    240    Sets the beginning of the 64k-memory segment to the
    241    adress specified by the unsigned long. If adress MOD 64
    242    is != 0, the return value will point to the segments
    243    start in the Amiga adress space + (adress MOD 64).
    244    Don't use more than (65536-64) bytes in the segment
    245    you set if you aren't sure that (adress MOD 64) == 0.
    246    See retina.doc from MS for further information.
    247 
    248 	void ClearScreen(unsigned char color);
    249 
    250    Fills the whole screen with "color" - 256-color mode only!
    251 
    252 	void LoadPalette(unsigned char * pal, unsigned char firstcol,
    253 	                 unsigned char colors);
    254 
    255    Loads the palette-registers. "pal" points to an array of unsigned char
    256    triplets, for the red, green and blue component. "firstcol" determines the
    257    number of the first palette-register to load (256 available). "colors"
    258    is the number of colors you want to put in the palette registers.
    259 
    260 	void SetPalette(unsigned char colornum, unsigned char red,
    261 	                unsigned char green, unsigned char blue);
    262 
    263    Allows you to set a single color in the palette, "colornum" is the number
    264    of the palette entry (256 available), "red", "green" and "blue" are the
    265    three components.
    266 
    267 	void SetPanning(unsigned short xoff, unsigned short yoff);
    268 
    269    Moves the logical coordinate (xoff, yoff) to the upper left corner
    270    of your screen. Of course, you shouldn't specify excess values that would
    271    show garbage in the lower right area of your screen... SetPanning()
    272    does NOT check for boundaries.
    273 */
    274 
    275 /* -------------- START OF CODE -------------- */
    276 
    277 /* read VGA register */
    278 #define vgar(ba, reg) (*(((volatile unsigned char *)ba)+reg))
    279 
    280 /* write VGA register */
    281 #define vgaw(ba, reg, val) \
    282 	*(((volatile unsigned char *)ba)+reg) = val
    283 
    284 /* defines for the used register addresses (mw)
    285 
    286    NOTE: there are some registers that have different addresses when
    287          in mono or color mode. We only support color mode, and thus
    288          some addresses won't work in mono-mode! */
    289 
    290 /* General Registers: */
    291 #define GREG_STATUS0_R		0x43C2
    292 #define GREG_STATUS1_R		0x43DA
    293 #define GREG_MISC_OUTPUT_R	0x43CC
    294 #define GREG_MISC_OUTPUT_W	0x43C2
    295 #define GREG_FEATURE_CONTROL_R	0x43CA
    296 #define GREG_FEATURE_CONTROL_W	0x43DA
    297 #define GREG_POS		0x4102
    298 
    299 /* Attribute Controller: */
    300 #define ACT_ADDRESS		0x43C0
    301 #define ACT_ADDRESS_R		0x03C0
    302 #define ACT_ADDRESS_W		0x43C0
    303 #define ACT_ID_PALETTE0		0x00
    304 #define ACT_ID_PALETTE1		0x01
    305 #define ACT_ID_PALETTE2		0x02
    306 #define ACT_ID_PALETTE3		0x03
    307 #define ACT_ID_PALETTE4		0x04
    308 #define ACT_ID_PALETTE5		0x05
    309 #define ACT_ID_PALETTE6		0x06
    310 #define ACT_ID_PALETTE7		0x07
    311 #define ACT_ID_PALETTE8		0x08
    312 #define ACT_ID_PALETTE9		0x09
    313 #define ACT_ID_PALETTE10	0x0A
    314 #define ACT_ID_PALETTE11	0x0B
    315 #define ACT_ID_PALETTE12	0x0C
    316 #define ACT_ID_PALETTE13	0x0D
    317 #define ACT_ID_PALETTE14	0x0E
    318 #define ACT_ID_PALETTE15	0x0F
    319 #define ACT_ID_ATTR_MODE_CNTL	0x10
    320 #define ACT_ID_OVERSCAN_COLOR	0x11
    321 #define ACT_ID_COLOR_PLANE_ENA	0x12
    322 #define ACT_ID_HOR_PEL_PANNING	0x13
    323 #define ACT_ID_COLOR_SELECT	0x14
    324 
    325 /* Graphics Controller: */
    326 #define GCT_ADDRESS		0x43CE
    327 #define GCT_ADDRESS_R		0x03CE
    328 #define GCT_ADDRESS_W		0x03CE
    329 #define GCT_ID_SET_RESET	0x00
    330 #define GCT_ID_ENABLE_SET_RESET	0x01
    331 #define GCT_ID_COLOR_COMPARE	0x02
    332 #define GCT_ID_DATA_ROTATE	0x03
    333 #define GCT_ID_READ_MAP_SELECT	0x04
    334 #define GCT_ID_GRAPHICS_MODE	0x05
    335 #define GCT_ID_MISC		0x06
    336 #define GCT_ID_COLOR_XCARE	0x07
    337 #define GCT_ID_BITMASK		0x08
    338 
    339 /* Sequencer: */
    340 #define SEQ_ADDRESS		0x43C4
    341 #define SEQ_ADDRESS_R		0x03C4
    342 #define SEQ_ADDRESS_W		0x03C4
    343 #define SEQ_ID_RESET		0x00
    344 #define SEQ_ID_CLOCKING_MODE	0x01
    345 #define SEQ_ID_MAP_MASK		0x02
    346 #define SEQ_ID_CHAR_MAP_SELECT	0x03
    347 #define SEQ_ID_MEMORY_MODE	0x04
    348 #define SEQ_ID_EXTENDED_ENABLE	0x05	/* down from here, all seq registers are NCR extensions */
    349 #define SEQ_ID_UNKNOWN1         0x06	/* it does exist so it's probably usefull */
    350 #define SEQ_ID_UNKNOWN2         0x07	/* it does exist so it's probably usefull */
    351 #define SEQ_ID_CHIP_ID		0x08
    352 #define SEQ_ID_UNKNOWN3         0x09	/* it does exist so it's probably usefull */
    353 #define SEQ_ID_CURSOR_COLOR1	0x0A
    354 #define SEQ_ID_CURSOR_COLOR0	0x0B
    355 #define SEQ_ID_CURSOR_CONTROL	0x0C
    356 #define SEQ_ID_CURSOR_X_LOC_HI	0x0D
    357 #define SEQ_ID_CURSOR_X_LOC_LO	0x0E
    358 #define SEQ_ID_CURSOR_Y_LOC_HI	0x0F
    359 #define SEQ_ID_CURSOR_Y_LOC_LO	0x10
    360 #define SEQ_ID_CURSOR_X_INDEX	0x11
    361 #define SEQ_ID_CURSOR_Y_INDEX	0x12
    362 #define SEQ_ID_CURSOR_STORE_HI	0x13	/* printed manual is wrong about these.. */
    363 #define SEQ_ID_CURSOR_STORE_LO	0x14
    364 #define SEQ_ID_CURSOR_ST_OFF_HI	0x15
    365 #define SEQ_ID_CURSOR_ST_OFF_LO	0x16
    366 #define SEQ_ID_CURSOR_PIXELMASK	0x17
    367 #define SEQ_ID_PRIM_HOST_OFF_HI	0x18
    368 #define SEQ_ID_PRIM_HOST_OFF_LO	0x19
    369 #define SEQ_ID_DISP_OFF_HI	0x1A
    370 #define SEQ_ID_DISP_OFF_LO	0x1B
    371 #define SEQ_ID_SEC_HOST_OFF_HI	0x1C
    372 #define SEQ_ID_SEC_HOST_OFF_LO	0x1D
    373 #define SEQ_ID_EXTENDED_MEM_ENA	0x1E
    374 #define SEQ_ID_EXT_CLOCK_MODE	0x1F
    375 #define SEQ_ID_EXT_VIDEO_ADDR	0x20
    376 #define SEQ_ID_EXT_PIXEL_CNTL	0x21
    377 #define SEQ_ID_BUS_WIDTH_FEEDB	0x22
    378 #define SEQ_ID_PERF_SELECT	0x23
    379 #define SEQ_ID_COLOR_EXP_WFG	0x24
    380 #define SEQ_ID_COLOR_EXP_WBG	0x25
    381 #define SEQ_ID_EXT_RW_CONTROL	0x26
    382 #define SEQ_ID_MISC_FEATURE_SEL	0x27
    383 #define SEQ_ID_COLOR_KEY_CNTL	0x28
    384 #define SEQ_ID_COLOR_KEY_MATCH	0x29
    385 #define SEQ_ID_UNKNOWN4         0x2A
    386 #define SEQ_ID_UNKNOWN5         0x2B
    387 #define SEQ_ID_UNKNOWN6         0x2C
    388 #define SEQ_ID_CRC_CONTROL	0x2D
    389 #define SEQ_ID_CRC_DATA_LOW	0x2E
    390 #define SEQ_ID_CRC_DATA_HIGH	0x2F
    391 
    392 /* CRT Controller: */
    393 #define CRT_ADDRESS		0x43D4
    394 #define CRT_ADDRESS_R		0x03D4
    395 #define CRT_ADDRESS_W		0x03D4
    396 #define CRT_ID_HOR_TOTAL	0x00
    397 #define CRT_ID_HOR_DISP_ENA_END	0x01
    398 #define CRT_ID_START_HOR_BLANK	0x02
    399 #define CRT_ID_END_HOR_BLANK	0x03
    400 #define CRT_ID_START_HOR_RETR	0x04
    401 #define CRT_ID_END_HOR_RETR	0x05
    402 #define CRT_ID_VER_TOTAL	0x06
    403 #define CRT_ID_OVERFLOW		0x07
    404 #define CRT_ID_PRESET_ROW_SCAN	0x08
    405 #define CRT_ID_MAX_SCAN_LINE	0x09
    406 #define CRT_ID_CURSOR_START	0x0A
    407 #define CRT_ID_CURSOR_END	0x0B
    408 #define CRT_ID_START_ADDR_HIGH	0x0C
    409 #define CRT_ID_START_ADDR_LOW	0x0D
    410 #define CRT_ID_CURSOR_LOC_HIGH	0x0E
    411 #define CRT_ID_CURSOR_LOC_LOW	0x0F
    412 #define CRT_ID_START_VER_RETR	0x10
    413 #define CRT_ID_END_VER_RETR	0x11
    414 #define CRT_ID_VER_DISP_ENA_END	0x12
    415 #define CRT_ID_OFFSET		0x13
    416 #define CRT_ID_UNDERLINE_LOC	0x14
    417 #define CRT_ID_START_VER_BLANK	0x15
    418 #define CRT_ID_END_VER_BLANK	0x16
    419 #define CRT_ID_MODE_CONTROL	0x17
    420 #define CRT_ID_LINE_COMPARE	0x18
    421 #define CRT_ID_UNKNOWN1         0x19	/* are these register really void ? */
    422 #define CRT_ID_UNKNOWN2         0x1A
    423 #define CRT_ID_UNKNOWN3         0x1B
    424 #define CRT_ID_UNKNOWN4         0x1C
    425 #define CRT_ID_UNKNOWN5         0x1D
    426 #define CRT_ID_UNKNOWN6         0x1E
    427 #define CRT_ID_UNKNOWN7         0x1F
    428 #define CRT_ID_UNKNOWN8         0x20
    429 #define CRT_ID_UNKNOWN9         0x21
    430 #define CRT_ID_UNKNOWN10      	0x22
    431 #define CRT_ID_UNKNOWN11      	0x23
    432 #define CRT_ID_UNKNOWN12      	0x24
    433 #define CRT_ID_UNKNOWN13      	0x25
    434 #define CRT_ID_UNKNOWN14      	0x26
    435 #define CRT_ID_UNKNOWN15      	0x27
    436 #define CRT_ID_UNKNOWN16      	0x28
    437 #define CRT_ID_UNKNOWN17      	0x29
    438 #define CRT_ID_UNKNOWN18      	0x2A
    439 #define CRT_ID_UNKNOWN19      	0x2B
    440 #define CRT_ID_UNKNOWN20      	0x2C
    441 #define CRT_ID_UNKNOWN21      	0x2D
    442 #define CRT_ID_UNKNOWN22      	0x2E
    443 #define CRT_ID_UNKNOWN23      	0x2F
    444 #define CRT_ID_EXT_HOR_TIMING1	0x30	/* down from here, all crt registers are NCR extensions */
    445 #define CRT_ID_EXT_START_ADDR	0x31
    446 #define CRT_ID_EXT_HOR_TIMING2	0x32
    447 #define CRT_ID_EXT_VER_TIMING	0x33
    448 
    449 /* Video DAC (these are *pure* guesses from the usage of these registers,
    450    I don't have a data sheet for this chip:-/) */
    451 #define VDAC_REG_D		0x800d	/* well.. */
    452 #define VDAC_REG_SELECT		0x8001	/* perhaps.. */
    453 #define VDAC_REG_DATA		0x8003	/* dito.. */
    454 
    455 #define WGfx(ba, idx, val) \
    456 	do { vgaw(ba, GCT_ADDRESS, idx); vgaw(ba, GCT_ADDRESS_W , val); } while (0)
    457 
    458 #define WSeq(ba, idx, val) \
    459 	do { vgaw(ba, SEQ_ADDRESS, idx); vgaw(ba, SEQ_ADDRESS_W , val); } while (0)
    460 
    461 #define WCrt(ba, idx, val) \
    462 	do { vgaw(ba, CRT_ADDRESS, idx); vgaw(ba, CRT_ADDRESS_W , val); } while (0)
    463 
    464 #define WAttr(ba, idx, val) \
    465 	do { vgaw(ba, ACT_ADDRESS, idx); vgaw(ba, ACT_ADDRESS_W, val); } while (0)
    466 
    467 #define Map(m) \
    468 	do { WGfx(ba, GCT_ID_READ_MAP_SELECT, m & 3 ); WSeq(ba, SEQ_ID_MAP_MASK, (1 << (m & 3))); } while (0)
    469 
    470 static inline unsigned char RAttr(volatile void * ba, short idx) {
    471 	vgaw (ba, ACT_ADDRESS, idx);
    472 	return vgar (ba, ACT_ADDRESS_R);
    473 }
    474 
    475 static inline unsigned char RSeq(volatile void * ba, short idx) {
    476 	vgaw (ba, SEQ_ADDRESS, idx);
    477 	return vgar (ba, SEQ_ADDRESS_R);
    478 }
    479 
    480 static inline unsigned char RCrt(volatile void * ba, short idx) {
    481 	vgaw (ba, CRT_ADDRESS, idx);
    482 	return vgar (ba, CRT_ADDRESS_R);
    483 }
    484 
    485 static inline unsigned char RGfx(volatile void * ba, short idx) {
    486 	vgaw(ba, GCT_ADDRESS, idx);
    487 	return vgar (ba, GCT_ADDRESS_R);
    488 }
    489 
    490 int grfrt_cnprobe __P((void));
    491 void grfrt_iteinit __P((struct grf_softc *));
    492 #endif /* _GRF_RTREG_H */
    493