1 /*
2  * video-render-crt.c - Implementation of framebuffer to physical screen copy
3  *
4  * Written by
5  *  groepaz <groepaz@gmx.net>
6  *  John Selck <graham@cruise.de>
7  *  Dag Lem <resid@nimrod.no>
8  *  Andreas Boose <viceteam@t-online.de>
9  *
10  * This file is part of VICE, the Versatile Commodore Emulator.
11  * See README for copyright notice.
12  *
13  *  This program is free software; you can redistribute it and/or modify
14  *  it under the terms of the GNU General Public License as published by
15  *  the Free Software Foundation; either version 2 of the License, or
16  *  (at your option) any later version.
17  *
18  *  This program is distributed in the hope that it will be useful,
19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  *  GNU General Public License for more details.
22  *
23  *  You should have received a copy of the GNU General Public License
24  *  along with this program; if not, write to the Free Software
25  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26  *  02111-1307  USA.
27  *
28  */
29 
30 #include "vice.h"
31 
32 #include <stdio.h>
33 
34 #include "log.h"
35 #include "machine.h"
36 #include "render1x1.h"
37 #include "render1x1crt.h"
38 #include "render1x1pal.h"
39 #include "render1x1ntsc.h"
40 #include "render1x2.h"
41 #include "render1x2crt.h"
42 #include "render2x2.h"
43 #include "render2x2crt.h"
44 #include "render2x2pal.h"
45 #include "render2x2ntsc.h"
46 #include "render2x4.h"
47 #include "render2x4crt.h"
48 #include "renderscale2x.h"
49 #include "resources.h"
50 #include "types.h"
51 #include "video-render.h"
52 #include "video.h"
53 
54 
55 static int rendermode_error = -1;
56 
video_render_crt_main(video_render_config_t * config,uint8_t * src,uint8_t * trg,int width,int height,int xs,int ys,int xt,int yt,int pitchs,int pitcht,int depth,viewport_t * viewport)57 static void video_render_crt_main(video_render_config_t *config,
58                                   uint8_t *src, uint8_t *trg,
59                                   int width, int height, int xs, int ys, int xt,
60                                   int yt, int pitchs, int pitcht, int depth,
61                                   viewport_t *viewport)
62 {
63     video_render_color_tables_t *colortab;
64     int doublescan, delayloop, rendermode, scale2x;
65 
66     rendermode = config->rendermode;
67     doublescan = config->doublescan;
68     colortab = &config->color_tables;
69     scale2x = config->scale2x;
70 
71     delayloop = (config->filter == VIDEO_FILTER_CRT);
72 
73     if ((rendermode == VIDEO_RENDER_CRT_1X1
74          || rendermode == VIDEO_RENDER_CRT_1X2
75          || rendermode == VIDEO_RENDER_CRT_2X2
76          || rendermode == VIDEO_RENDER_CRT_2X4)
77         && config->video_resources.pal_scanlineshade <= 0) {
78         doublescan = 0;
79     }
80 
81     switch (rendermode) {
82         case VIDEO_RENDER_NULL:
83             return;
84             break;
85 
86         case VIDEO_RENDER_CRT_1X1:
87             if (delayloop && depth != 8) {
88                 switch (depth) {
89                     case 16:
90                         render_16_1x1_crt(colortab, src, trg, width, height,
91                                            xs, ys, xt, yt, pitchs, pitcht);
92                         return;
93                     case 24:
94                         render_24_1x1_crt(colortab, src, trg, width, height,
95                                            xs, ys, xt, yt, pitchs, pitcht);
96                         return;
97                     case 32:
98                         render_32_1x1_crt(colortab, src, trg, width, height,
99                                            xs, ys, xt, yt, pitchs, pitcht);
100                         return;
101                 }
102             } else {
103                 switch (depth) {
104                     case 8:
105                         render_08_1x1_04(colortab, src, trg, width, height,
106                                          xs, ys, xt, yt, pitchs, pitcht);
107                         return;
108                     case 16:
109                         render_16_1x1_04(colortab, src, trg, width, height,
110                                          xs, ys, xt, yt, pitchs, pitcht);
111                         return;
112                     case 24:
113                         render_24_1x1_04(colortab, src, trg, width, height,
114                                          xs, ys, xt, yt, pitchs, pitcht);
115                         return;
116                     case 32:
117                         render_32_1x1_04(colortab, src, trg, width, height,
118                                          xs, ys, xt, yt, pitchs, pitcht);
119                         return;
120                 }
121             }
122             break;
123         case VIDEO_RENDER_CRT_1X2:
124             if (delayloop && depth != 8) {
125                 switch (depth) {
126                     case 16:
127                         render_16_1x2_crt(colortab, src, trg, width, height,
128                                           xs, ys, xt, yt, pitchs, pitcht,
129                                           viewport, config);
130                         return;
131                     case 24:
132                         render_24_1x2_crt(colortab, src, trg, width, height,
133                                           xs, ys, xt, yt, pitchs, pitcht,
134                                           viewport, config);
135                         return;
136                     case 32:
137                         render_32_1x2_crt(colortab, src, trg, width, height,
138                                           xs, ys, xt, yt, pitchs, pitcht,
139                                           viewport, config);
140                         return;
141                 }
142             } else {
143                 switch (depth) {
144                     case 8:
145                         render_08_1x2_04(colortab, src, trg, width, height,
146                                          xs, ys, xt, yt, pitchs, pitcht, doublescan, config);
147                         return;
148                     case 16:
149                         render_16_1x2_04(colortab, src, trg, width, height,
150                                          xs, ys, xt, yt, pitchs, pitcht, doublescan, config);
151                         return;
152                     case 24:
153                         render_24_1x2_04(colortab, src, trg, width, height,
154                                          xs, ys, xt, yt, pitchs, pitcht, doublescan, config);
155                         return;
156                     case 32:
157                         render_32_1x2_04(colortab, src, trg, width, height,
158                                          xs, ys, xt, yt, pitchs, pitcht, doublescan, config);
159                         return;
160                 }
161             }
162             break;
163         case VIDEO_RENDER_CRT_2X2:
164             if (scale2x) {
165                 switch (depth) {
166                     case 8:
167                         render_08_scale2x(colortab, src, trg, width, height,
168                                           xs, ys, xt, yt, pitchs, pitcht);
169                         return;
170                     case 16:
171                         render_16_scale2x(colortab, src, trg, width, height,
172                                           xs, ys, xt, yt, pitchs, pitcht);
173                         return;
174                     case 24:
175                         render_24_scale2x(colortab, src, trg, width, height,
176                                           xs, ys, xt, yt, pitchs, pitcht);
177                         return;
178                     case 32:
179                         render_32_scale2x(colortab, src, trg, width, height,
180                                           xs, ys, xt, yt, pitchs, pitcht);
181                         return;
182                 }
183             } else if (delayloop && depth != 8) {
184                 switch (depth) {
185                     case 16:
186                         render_16_2x2_crt(colortab, src, trg, width, height,
187                                           xs, ys, xt, yt, pitchs, pitcht, viewport, config);
188                         return;
189                     case 24:
190                         render_24_2x2_crt(colortab, src, trg, width, height,
191                                           xs, ys, xt, yt, pitchs, pitcht, viewport, config);
192                         return;
193                     case 32:
194                         render_32_2x2_crt(colortab, src, trg, width, height,
195                                           xs, ys, xt, yt, pitchs, pitcht, viewport, config);
196                         return;
197                 }
198             } else {
199                 switch (depth) {
200                     case 8:
201                         render_08_2x2_04(colortab, src, trg, width, height,
202                                          xs, ys, xt, yt, pitchs, pitcht, doublescan, config);
203                         return;
204                     case 16:
205                         render_16_2x2_04(colortab, src, trg, width, height,
206                                          xs, ys, xt, yt, pitchs, pitcht, doublescan, config);
207                         return;
208                     case 24:
209                         render_24_2x2_04(colortab, src, trg, width, height,
210                                          xs, ys, xt, yt, pitchs, pitcht, doublescan, config);
211                         return;
212                     case 32:
213                         render_32_2x2_04(colortab, src, trg, width, height,
214                                          xs, ys, xt, yt, pitchs, pitcht, doublescan, config);
215                         return;
216                 }
217             }
218             break;
219         case VIDEO_RENDER_CRT_2X4:
220             if (delayloop && depth != 8) {
221                 switch (depth) {
222                     case 16:
223                         render_16_2x4_crt(colortab, src, trg, width, height,
224                                           xs, ys, xt, yt, pitchs, pitcht, viewport, config);
225                         return;
226                     case 24:
227                         render_24_2x4_crt(colortab, src, trg, width, height,
228                                           xs, ys, xt, yt, pitchs, pitcht, viewport, config);
229                         return;
230                     case 32:
231                         render_32_2x4_crt(colortab, src, trg, width, height,
232                                           xs, ys, xt, yt, pitchs, pitcht, viewport, config);
233                         return;
234                 }
235             } else {
236                 switch (depth) {
237                     case 8:
238                         render_08_2x4_04(colortab, src, trg, width, height,
239                                          xs, ys, xt, yt, pitchs, pitcht, doublescan, config);
240                         return;
241                     case 16:
242                         render_16_2x4_04(colortab, src, trg, width, height,
243                                          xs, ys, xt, yt, pitchs, pitcht, doublescan, config);
244                         return;
245                     case 24:
246                         render_24_2x4_04(colortab, src, trg, width, height,
247                                          xs, ys, xt, yt, pitchs, pitcht, doublescan, config);
248                         return;
249                     case 32:
250                         render_32_2x4_04(colortab, src, trg, width, height,
251                                          xs, ys, xt, yt, pitchs, pitcht, doublescan, config);
252                         return;
253                 }
254             }
255             break;
256     }
257     if (rendermode_error != rendermode) {
258         log_error(LOG_DEFAULT, "video_render_crt_main: unsupported rendermode (%d)", rendermode);
259     }
260     rendermode_error = rendermode;
261 }
262 
video_render_crt_init(void)263 void video_render_crt_init(void)
264 {
265     video_render_crtfunc_set(video_render_crt_main);
266 }
267