1 /*
2  * raster-mode.c - Definition of drawing modes for the raster emulation.
3  *
4  * Written by
5  *  Ettore Perazzoli <ettore@comm2000.it>
6  *  Andreas Boose <viceteam@t-online.de>
7  *
8  * This file is part of VICE, the Versatile Commodore Emulator.
9  * See README for copyright notice.
10  *
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24  *  02111-1307  USA.
25  *
26  */
27 
28 #ifndef VICE_RASTER_MODES_H
29 #define VICE_RASTER_MODES_H
30 
31 #include "raster-cache.h"
32 
33 /* Fill the cache with the screen data and check for differences.  If nothing
34    has changed, return 0.  Otherwise, return the smallest interval that
35    contains the changed parts and return 1.  If no_check != 0, fill the cache
36    without checking for differences and return 1.  */
37 typedef int (*raster_modes_fill_cache_function_t)
38     (struct raster_cache_s *c, unsigned int *changed_start,
39     unsigned int *changed_end, int no_check);
40 
41 /* Draw part of one line to the buffer.  */
42 typedef void (*raster_modes_draw_line_cached_function_t)
43     (struct raster_cache_s *c, unsigned int start, unsigned int end);
44 
45 /* Draw the whole line to the buffer.  */
46 typedef void (*raster_modes_draw_line_function_t)
47     (void);
48 
49 /* Draw part of the background to the buffer.  */
50 typedef void (*raster_modes_draw_background_function_t)
51     (unsigned int start_pixel, unsigned int end_pixel);
52 
53 /* Draw part of the foreground to the buffer.  */
54 typedef void (*raster_modes_draw_foreground_function_t)
55     (unsigned int start_char, unsigned int end_char);
56 
57 struct raster_modes_def_s {
58     raster_modes_fill_cache_function_t fill_cache;
59     raster_modes_draw_line_cached_function_t draw_line_cached;
60     raster_modes_draw_line_function_t draw_line;
61     raster_modes_draw_background_function_t draw_background;
62     raster_modes_draw_foreground_function_t draw_foreground;
63 };
64 typedef struct raster_modes_def_s raster_modes_def_t;
65 
66 struct raster_modes_s {
67     /* Number of defined modes.  */
68     unsigned int num_modes;
69 
70     /* List of modes.  */
71     raster_modes_def_t *modes;
72 
73     /* Mode used for idle mode.  */
74     unsigned int idle_mode;
75 };
76 typedef struct raster_modes_s raster_modes_t;
77 
78 
79 extern void raster_modes_init(raster_modes_t *modes, unsigned int num_modes);
80 extern void raster_modes_shutdown(raster_modes_t *modes);
81 extern raster_modes_t *raster_modes_new(unsigned int num_modes);
82 extern void raster_modes_set(raster_modes_t *modes,
83                              unsigned int num_mode,
84                              raster_modes_fill_cache_function_t fill_cache,
85                              raster_modes_draw_line_cached_function_t draw_line_cached,
86                              raster_modes_draw_line_function_t draw_line,
87                              raster_modes_draw_background_function_t draw_background,
88                              raster_modes_draw_foreground_function_t draw_foreground);
89 extern int raster_modes_set_idle_mode(raster_modes_t *modes,
90                                       unsigned int num_mode);
91 
raster_modes_fill_cache(raster_modes_t * modes,unsigned int mode_num,struct raster_cache_s * c,unsigned int * changed_start,unsigned int * changed_end,int no_check)92 inline static int raster_modes_fill_cache(raster_modes_t *modes,
93                                           unsigned int mode_num,
94                                           struct raster_cache_s *c,
95                                           unsigned int *changed_start,
96                                           unsigned int *changed_end,
97                                           int no_check)
98 {
99     raster_modes_def_t *mode;
100 
101     mode = modes->modes + mode_num;
102 
103     return mode->fill_cache(c, changed_start, changed_end, no_check);
104 }
105 
raster_modes_draw_line_cached(raster_modes_t * modes,unsigned int mode_num,struct raster_cache_s * c,int start,int end)106 inline static void raster_modes_draw_line_cached(raster_modes_t *modes,
107                                                  unsigned int mode_num,
108                                                  struct raster_cache_s *c,
109                                                  int start,
110                                                  int end)
111 {
112     raster_modes_def_t *mode;
113 
114     mode = modes->modes + mode_num;
115 
116     mode->draw_line_cached(c, start, end);
117 }
118 
raster_modes_draw_line(raster_modes_t * modes,unsigned int mode_num)119 inline static void raster_modes_draw_line(raster_modes_t *modes,
120                                           unsigned int mode_num)
121 {
122     raster_modes_def_t *mode;
123 
124     mode = modes->modes + mode_num;
125 
126     mode->draw_line();
127 }
128 
raster_modes_draw_background(raster_modes_t * modes,unsigned int mode_num,unsigned int start_pixel,unsigned int end_pixel)129 inline static void raster_modes_draw_background(raster_modes_t *modes,
130                                                 unsigned int mode_num,
131                                                 unsigned int start_pixel,
132                                                 unsigned int end_pixel)
133 {
134     raster_modes_def_t *mode;
135 
136     mode = modes->modes + mode_num;
137 
138     mode->draw_background(start_pixel, end_pixel);
139 }
140 
raster_modes_draw_foreground(raster_modes_t * modes,unsigned int mode_num,int start_char,int end_char)141 inline static void raster_modes_draw_foreground(raster_modes_t *modes,
142                                                 unsigned int mode_num,
143                                                 int start_char,
144                                                 int end_char)
145 {
146     raster_modes_def_t *mode;
147 
148     mode = modes->modes + mode_num;
149 
150     mode->draw_foreground(start_char, end_char);
151 }
152 
153 
raster_modes_get_idle_mode(raster_modes_t * modes)154 inline static int raster_modes_get_idle_mode(raster_modes_t *modes)
155 {
156     return modes->idle_mode;
157 }
158 
159 #endif /* _RASTER_MODES_H */
160