1/* $NetBSD: x68kText.c,v 1.4 2020/11/05 16:06:08 tsutsui Exp $ */
2/*-------------------------------------------------------------------------
3 * Copyright (c) 1996 Yasushi Yamasaki
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *-----------------------------------------------------------------------*/
26
27#include "x68k.h"
28#include "mi.h"
29#include "micmap.h"
30#include "fb.h"
31
32/*-------------------------------------------------------------------------
33 * function "x68kTextOpen"                          [ X68kFBProc function ]
34 *
35 *  purpose:  call common frame buffer opening procedure
36 *            and enable TVRAM simultaneous access mode
37 *  argument: (X68kScreenRec *)pPriv : X68k private screen record
38 *  returns:  (Bool): TRUE  if succeeded
39 *                    FALSE otherwise
40 *-----------------------------------------------------------------------*/
41static uint16_t r21;
42static uint16_t tpal0;
43static uint16_t tpal15;
44
45Bool
46x68kTextOpen(X68kScreenRec *pPriv)
47{
48    if( !x68kFbCommonOpen(pPriv, "/dev/grf0") )
49        return FALSE;
50
51    /* enable TVRAM simultaneous access mode */
52    r21 = pPriv->reg->crtc.r21;
53    pPriv->reg->crtc.r21 = 0x01f0;
54
55    /* initialize scroll registers */
56    pPriv->reg->crtc.r10 = pPriv->reg->crtc.r11 = 0;
57
58    tpal0 = pPriv->reg->tpal[0];
59    tpal15 = pPriv->reg->tpal[15];
60
61    pPriv->reg->tpal[0] = 0;
62    pPriv->reg->tpal[15] = 0xFFFE;
63
64    return TRUE;
65}
66
67/*-------------------------------------------------------------------------
68 * function "x68kTextClose"                        [ X68kFBProc function ]
69 *
70 *  purpose:  close text frame buffer
71 *  argument: nothing
72 *  returns:  nothing
73 *-----------------------------------------------------------------------*/
74void
75x68kTextClose(X68kScreenRec *pPriv)
76{
77    pPriv->reg->crtc.r21 = r21;  /* recover TVRAM mode */
78    pPriv->reg->tpal[0] = tpal0;
79    pPriv->reg->tpal[15] = tpal15;
80    x68kFbCommonClose(pPriv);
81}
82
83/*-------------------------------------------------------------------------
84 * function "x68kTextInit"                     [ called by DIX AddScreen ]
85 *
86 *  purpose:  initialize text frame buffer
87 *  argument: (int)screen              : screen index
88 *            (ScreenPtr)pScreen       : DIX screen record
89 *            (int)argc, (char **)argv : standard C arguments
90 *  returns:  (Bool) TRUE  if succeeded
91 *                   FALSE otherwise
92 *-----------------------------------------------------------------------*/
93Bool
94x68kTextInit(int screen, ScreenPtr pScreen, int argc, char *argv[])
95{
96    X68kScreenRec *pPriv;
97
98    /* get private screen record set by X68KConfig */
99    pPriv = x68kGetScreenRecByType(X68K_FB_TEXT);
100
101    if ( !dixRegisterPrivateKey(&x68kScreenPrivateKeyRec, PRIVATE_SCREEN, 0) ) {
102            Error("dixRegisterPrivateKey failed");
103            return FALSE;
104    }
105    x68kSetScreenPrivate(pScreen, pPriv);
106
107    if ( !fbScreenInit(pScreen, pPriv->fb,
108                        pPriv->scr_width, pPriv->scr_height,
109                        pPriv->dpi, pPriv->dpi, pPriv->fb_width, 1) )
110        return FALSE;
111    pScreen->whitePixel = 1;
112    pScreen->blackPixel = 0;
113    if ( !miDCInitialize(pScreen, &x68kPointerScreenFuncs) )
114        return FALSE;
115    if ( !miCreateDefColormap(pScreen) )
116        return FALSE;
117    pScreen->SaveScreen = x68kSaveScreen;
118
119    return TRUE;
120}
121
122/* EOF x68kText.c */
123