1 /* term_overlay_x11.c: X-windows overlay frame buffer code
2 
3    Copyright (c) 1997-2003, Tarik Isani (xhomer@isani.org)
4 
5    This file is part of Xhomer.
6 
7    Xhomer is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License version 2
9    as published by the Free Software Foundation.
10 
11    Xhomer is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15 
16    You should have received a copy of the GNU General Public License
17    along with Xhomer; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20 
21 
22 /* TBD:
23 */
24 
25 #ifdef PRO
26 
27 #include <stdlib.h>
28 #include <string.h>
29 #include "pro_defs.h"
30 #include "pro_font.h"
31 
32 
33 int			pro_overlay_on = 0;
34 unsigned char		*pro_overlay_data;	/* overlay frame buffer */
35 unsigned char		*pro_overlay_alpha;	/* overlay frame buffer alpha */
36 
37 LOCAL int		pro_overlay_open = 0;
38 LOCAL int		clutmode;
39 LOCAL int		pixsize;
40 LOCAL int		blackpixel;
41 LOCAL int		whitepixel;
42 LOCAL int		overlay_a;
43 LOCAL int		start_x;
44 LOCAL int		last_x;
45 LOCAL int		last_y;
46 LOCAL int		last_size;
47 
48 
49 /* Print a single character into overlay frame buffer */
50 
51 /* x = 0..79  y= 0..23 */
52 
53 /* xnor = 0 -> replace mode
54    xnor = 1 -> xnor mode */
55 
56 /* prints 12x10 characters */
57 
pro_overlay_print_char(int x,int y,int xnor,int font,char ch)58 LOCAL void pro_overlay_print_char(int x, int y, int xnor, int font, char ch)
59 {
60 int	sx, sy, sx0, sy0; /* screen coordinates */
61 int	i, pix, pnum, opix, vindex;
62 int	charint;
63 
64 
65 	charint = ((int)ch) - PRO_FONT_FIRSTCHAR;
66 	if ((charint < 0) || (charint>(PRO_FONT_NUMCHARS-1)))
67 	  charint = 32 - PRO_FONT_FIRSTCHAR;
68 
69 	sx0 = x * 12;
70 	sy0 = y * 10;
71 
72 	/* Render character */
73 
74 	for(y=0; y<10; y++)
75 	{
76 	  sy = sy0 + y;
77 
78 	  for(x=0; x<12; x++)
79 	  {
80 	    sx = sx0 + x;
81 
82 	    /* Set color */
83 
84 	    if (((pro_overlay_font[font][charint][y] >> (11-x)) & 01) == 0)
85 	      pix = blackpixel;
86 	    else
87 	      pix = whitepixel;
88 
89 	    /* Plot pixel */
90 
91 	    pnum = sy*PRO_VID_SCRWIDTH+sx;
92 
93 	    /* Perform XNOR, if required */
94 
95 	    if (xnor == 1)
96 	    {
97 	      /* Get old pixel value */
98 
99 	      opix = 0;
100 
101 	      for(i=0; i<pixsize; i++)
102 	        opix |= pro_overlay_data[pixsize*pnum+i] << (i*8);
103 
104 	      if (opix == blackpixel)
105 	      {
106 	        if (pix == blackpixel)
107 	          pix = whitepixel;
108 	        else
109 	          pix = blackpixel;
110 	      }
111 	    }
112 
113 	    /* Assign alpha based on color */
114 
115 	    if (pix == blackpixel)
116 	      pro_overlay_alpha[sy*PRO_VID_SCRWIDTH+sx] = overlay_a;
117 	    else
118 	      /* Make white pixels non-transparent */
119 
120 	      pro_overlay_alpha[sy*PRO_VID_SCRWIDTH+sx] = PRO_OVERLAY_MAXA;
121 
122 	    /* Write pixel into frame buffer */
123 
124 	    for(i=0; i<pixsize; i++)
125 	      pro_overlay_data[pixsize*pnum+i] = pix >> (i*8);
126 
127 	    /* Mark display cache entry invalid */
128 
129 	    vindex = vmem((sy<<6) | ((sx>>4)&077));
130 	    pro_vid_mvalid[cmem(vindex)] = 0;
131 	  }
132 	}
133 }
134 
135 
136 /* Print text string into overlay frame buffer */
137 
pro_overlay_print(int x,int y,int xnor,int font,char * text)138 void pro_overlay_print(int x, int y, int xnor, int font, char *text)
139 {
140 int	i, size;
141 
142 
143 	if (pro_overlay_open)
144 	{
145 	  if (x == -1)
146 	    x = start_x;
147 	  else if (x == -2)
148 	    x = last_x + last_size;
149 	  else
150 	    start_x = x;
151 
152 	  if (y == -1)
153 	    y = last_y + 1;
154 	  else if (y == -2)
155 	    y = last_y;
156 
157 	  if (y > 23)
158 	    y = 23;
159 
160 	  size = strlen(text);
161 
162 	  for(i=0; i<size; i++)
163 	    pro_overlay_print_char(x+i, y, xnor, font, text[i]);
164 
165 	  last_x = x;
166 	  last_y = y;
167 	  last_size = size;
168 	}
169 }
170 
171 
172 /* Clear the overlay frame buffer */
173 
pro_overlay_clear()174 void pro_overlay_clear ()
175 {
176 int	i, j;
177 
178 	if (pro_overlay_open)
179 	{
180 	  for(i=0; i<PRO_VID_SCRWIDTH*PRO_VID_MEMHEIGHT; i++)
181 	  {
182 	    for(j=0; j<pixsize; j++)
183 	      pro_overlay_data[pixsize*i+j] = blackpixel >> (j*8);
184 
185 	    pro_overlay_alpha[i] = 0;
186 	  }
187 	}
188 }
189 
190 
191 /* Turn on overlay */
192 
pro_overlay_enable()193 void pro_overlay_enable ()
194 {
195 	pro_overlay_clear();
196 	pro_overlay_on = 1;
197 }
198 
199 
200 /* Turn off overlay */
201 
pro_overlay_disable()202 void pro_overlay_disable ()
203 {
204 	pro_clear_mvalid();
205 	pro_overlay_on = 0;
206 }
207 
208 
209 /* Initialize the overlay frame buffer */
210 
pro_overlay_init(int psize,int cmode,int bpixel,int wpixel)211 void pro_overlay_init (int psize, int cmode, int bpixel, int wpixel)
212 {
213 	if (pro_overlay_open == 0)
214 	{
215 	  start_x = 0;
216 	  last_x = 0;
217 	  last_y = 0;
218 	  last_size = 0;
219 
220 	  clutmode = cmode;
221 	  pixsize = psize;
222 	  blackpixel = bpixel;
223 	  whitepixel = wpixel;
224 
225 	  /* No blending is done in 8-bit modes */
226 
227 	  if (cmode == 1)
228 	    overlay_a = PRO_OVERLAY_MAXA;
229 	  else
230 	    overlay_a = PRO_OVERLAY_A;
231 
232 	  pro_overlay_data = (char *)malloc(PRO_VID_SCRWIDTH*PRO_VID_MEMHEIGHT*pixsize);
233 	  pro_overlay_alpha = (char *)malloc(PRO_VID_SCRWIDTH*PRO_VID_MEMHEIGHT);
234 	  pro_overlay_on = 0;
235 	  pro_overlay_open = 1;
236 	}
237 }
238 
239 
240 /* Close the overlay frame buffer */
241 
pro_overlay_close()242 void pro_overlay_close ()
243 {
244 	if (pro_overlay_open)
245 	{
246 	  free(pro_overlay_data);
247 	  free(pro_overlay_alpha);
248 	  pro_overlay_on = 0;
249 	  pro_overlay_open = 0;
250 	}
251 }
252 #endif
253