~ubuntu-branches/ubuntu/quantal/vice/quantal

« back to all changes in this revision

Viewing changes to src/raster/raster.h

  • Committer: Bazaar Package Importer
  • Author(s): Zed Pobre
  • Date: 2005-03-27 13:06:04 UTC
  • mfrom: (4 hoary)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20050327130604-zodmv0i60dbbmcik
Tags: 1.16-3
Apply patch from Andreas Jochens <aj@andaco.de> to correct building on
AMD64 and GCC 4.x (closes: #300936)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 *
4
4
 * Written by
5
5
 *  Ettore Perazzoli <ettore@comm2000.it>
6
 
 *  Andreas Boose <boose@linux.rz.fh-hannover.de>
 
6
 *  Andreas Boose <viceteam@t-online.de>
7
7
 *
8
8
 * This file is part of VICE, the Versatile Commodore Emulator.
9
9
 * See README for copyright notice.
30
30
 
31
31
#include "vice.h"
32
32
 
33
 
#include <string.h>
34
 
 
35
33
#include "raster-changes.h"
36
34
#include "types.h"
37
 
 
38
 
struct palette_s;
 
35
#include "viewport.h"
 
36
 
 
37
 
 
38
struct canvas_refresh_s;
39
39
 
40
40
/* We assume that, if already #defined, the provided `MAX' and `MIN' actually
41
41
   work.  */
51
51
   much space anyway.  */
52
52
#define RASTER_GFX_MSK_SIZE 0x100
53
53
 
54
 
/* A simple convenience type for defining rectangular areas.  */
55
 
struct raster_rectangle_s {
56
 
    unsigned int width;
57
 
    unsigned int height;
58
 
};
59
 
typedef struct raster_rectangle_s raster_rectangle_t;
60
 
 
61
 
/* A simple convenience type for defining screen positions.  */
62
 
struct raster_position_s {
63
 
    unsigned int x;
64
 
    unsigned int y;
65
 
};
66
 
typedef struct raster_position_s raster_position_t;
67
 
 
68
 
/* A simple convenience type for defining a rectangular area on the screen.  */
69
 
struct raster_area_s {
70
 
    unsigned int xs;
71
 
    unsigned int ys;
72
 
    unsigned int xe;
73
 
    unsigned int ye;
74
 
    int is_null;
75
 
};
76
 
typedef struct raster_area_s raster_area_t;
77
 
 
78
54
struct video_canvas_s;
79
55
 
80
 
struct raster_viewport_s {
81
 
    /* Output canvas.  */
82
 
    struct video_canvas_s *canvas;
83
 
 
84
 
    /* Portion of the screen displayed on the output window window.
85
 
       FIXME: We should get this from the canvas.  */
86
 
    unsigned int width, height;
87
 
 
88
 
    /* Title for the viewport.  FIXME: Duplicated info from the canvas?  */
89
 
    char *title;
90
 
 
91
 
    /* Offset of the screen on the window.  */
92
 
    unsigned int x_offset, y_offset;
93
 
 
94
 
    /* First and last lines shown in the output window.  */
95
 
    unsigned int first_line, last_line;
96
 
 
97
 
    /* First pixel in one line of the frame buffer to be shown on the output
98
 
       window.  */
99
 
    unsigned int first_x;
100
 
 
101
 
    /* Pixel size.  */
102
 
    raster_rectangle_t pixel_size;
103
 
 
104
 
    /* Exposure handler.  */
105
 
    void *exposure_handler;
106
 
 
107
 
    /* Only display canvas if this flag is set.  */
108
 
    int update_canvas;
109
 
};
110
 
typedef struct raster_viewport_s raster_viewport_t;
111
 
 
112
 
struct raster_geometry_s {
113
 
    /* Total size of the screen, including borders and unused areas.
114
 
       (SCREEN_WIDTH, SCREEN_HEIGHT)  */
115
 
    raster_rectangle_t screen_size;
116
 
 
117
 
    /* Size of the graphics area (i.e. excluding borders and unused areas.
118
 
       (SCREEN_XPIX, SCREEN_YPIX)  */
119
 
    raster_rectangle_t gfx_size;
120
 
 
121
 
    /* Size of the text area.  (SCREEN_TEXTCOLS)  */
122
 
    raster_rectangle_t text_size;
123
 
 
124
 
    /* Position of the graphics area.  (SCREEN_BORDERWIDTH,
125
 
       SCREEN_BORDERHEIGHT) */
126
 
    raster_position_t gfx_position;
127
 
 
128
 
    /* If nonzero, `gfx_position' is expected to be moved around when poking
129
 
       to the chip registers.  */
130
 
    int gfx_area_moves;
131
 
 
132
 
    /* FIXME: Bad names.  */
133
 
    unsigned int first_displayed_line, last_displayed_line;
134
 
 
135
 
    unsigned int extra_offscreen_border;
136
 
};
137
 
typedef struct raster_geometry_s raster_geometry_t;
138
 
 
139
56
struct raster_cache_s;
 
57
struct raster_canvas_area_s;
 
58
struct raster_changes_all_s;
140
59
struct raster_modes_s;
 
60
struct raster_resource_chip_s;
141
61
struct raster_sprite_status_s;
142
62
 
143
63
struct raster_s {
144
 
    raster_viewport_t viewport;
145
 
 
146
 
    raster_geometry_t geometry;
 
64
    struct viewport_s *viewport;
 
65
    struct geometry_s *geometry;
147
66
 
148
67
    struct raster_modes_s *modes;
149
68
 
150
69
    struct raster_sprite_status_s *sprite_status;
151
70
 
152
 
    struct {
153
 
        raster_changes_t background;
154
 
        raster_changes_t foreground;
155
 
        raster_changes_t border;
156
 
        raster_changes_t next_line;
157
 
        int have_on_this_line;
158
 
    } changes;
159
 
 
160
 
    struct {
161
 
        PIXEL sing[0x100];
162
 
        PIXEL2 doub[0x100];
163
 
        PIXEL4 quad[0x100];
164
 
    } pixel_table;
165
 
 
166
 
    struct video_frame_buffer_s *frame_buffer;
167
 
    PIXEL *frame_buffer_ptr;
168
 
 
169
 
    /* This is a temporary frame buffer line used for sprite collision
 
71
    struct raster_changes_all_s *changes;
 
72
 
 
73
    /* Output canvas.  */
 
74
    struct video_canvas_s *canvas;
 
75
 
 
76
    /* Resources */
 
77
    struct raster_resource_chip_s *raster_resource_chip;
 
78
 
 
79
    /* Pointer to the draw buffer.  */
 
80
    BYTE *draw_buffer_ptr;
 
81
 
 
82
    /* This is a temporary draw buffer line used for sprite collision
170
83
       checking without drawing to the real frame buffer.  */
171
 
    PIXEL *fake_frame_buffer_line;
172
 
 
173
 
    /* Palette used for drawing.  */
174
 
    struct palette_s *palette;
175
 
 
176
 
    /* This is a bit mask representing each pixel on the screen (1 =
177
 
       foreground, 0 = background) and is used both for sprite-background
178
 
       collision checking and background sprite drawing.  When cache is
179
 
       turned on, a cached mask for each line is used instead (see
180
 
       `raster_cache_t.gfx_msk').  */
181
 
    BYTE gfx_msk[RASTER_GFX_MSK_SIZE];
182
 
 
183
 
    /* This is a temporary graphics mask used for sprite collision checking
184
 
       without drawing to the real frame buffer, and is set up to be always
185
 
       filled with zeroes.  */
186
 
    BYTE zero_gfx_msk[RASTER_GFX_MSK_SIZE];
 
84
    BYTE *fake_draw_buffer_line;
187
85
 
188
86
    /* Smooth scroll values for the graphics (not the whole screen).  */
189
87
    int xsmooth, ysmooth;
190
88
 
 
89
    /* Number of pixels at a xsmooth shift to the left.  */
 
90
    int xsmooth_shift_left;
 
91
 
 
92
    /* Number of pixels at a xsmooth shift to the right.  */
 
93
    int xsmooth_shift_right;
 
94
 
191
95
    /* If nonzero, we should skip the next frame. (used for automatic refresh
192
96
       rate setting) */
193
97
    int skip_frame;
196
100
    unsigned int current_line;
197
101
 
198
102
    /* Border and background colors.  */
199
 
    int border_color, background_color;
200
 
 
201
 
    /* Color of the overscan area.  */
202
 
    int overscan_background_color;
 
103
    unsigned int border_color;
 
104
    unsigned int background_color;
 
105
 
 
106
    /* Color of the idle background.  */
 
107
    int idle_background_color;
 
108
 
 
109
    /* Color of the xsmooth area.  */
 
110
    int xsmooth_color;
203
111
 
204
112
    /* If this is != 0, no graphics is drawn and the whole line is painted with
205
113
       border_color.  */
212
120
    /* Open border flags.  */
213
121
    int open_right_border, open_left_border;
214
122
 
 
123
    /*  Overrides the blank flag when forced DMA switches on screen and the
 
124
        store that forced DMA sets the blank flag.  The flag should be cleared
 
125
        at line zero.  */
 
126
    int blank_off;
 
127
 
215
128
    /* blank_enabled is set when line display_ystop is reached and reset when
216
129
       line display_ystart is reached and blank is 0.  */
217
130
    int blank;
224
137
    int draw_idle_state;
225
138
 
226
139
    /* Count character lines (i.e. RC on the VIC-II).  */
227
 
    int ycounter;
 
140
    unsigned int ycounter;
228
141
 
229
142
    /* Current video mode.  */
230
143
    int video_mode;
242
155
    unsigned int num_cached_lines;
243
156
 
244
157
    /* Area to update.  */
245
 
    raster_area_t update_area;
246
 
 
247
 
    unsigned int do_double_scan;
248
 
 
249
 
    /* Function to call when internal tables have to be refreshed after a
250
 
       mode change. E.g. vicii::init_drawing_tables(). NULL allowed */
251
 
    void (*refresh_tables)(void);
 
158
    struct raster_canvas_area_s *update_area;
 
159
 
 
160
    /* This is a bit mask representing each pixel on the screen (1 =
 
161
       foreground, 0 = background) and is used both for sprite-background
 
162
       collision checking and background sprite drawing.  When cache is
 
163
       turned on, a cached mask for each line is used instead (see
 
164
       `raster_cache_t.gfx_msk').  */
 
165
    BYTE gfx_msk[RASTER_GFX_MSK_SIZE];
 
166
 
 
167
    /* This is a temporary graphics mask used for sprite collision checking
 
168
       without drawing to the real frame buffer, and is set up to be always
 
169
       filled with zeroes.  */
 
170
    BYTE zero_gfx_msk[RASTER_GFX_MSK_SIZE];
 
171
 
 
172
    int (*line_changes)(struct raster_s *, unsigned int *, unsigned int *);
 
173
    void (*draw_sprites_when_cache_enabled)(struct raster_s *,
 
174
                                            struct raster_cache_s *);
 
175
    int (*fill_sprite_cache)(struct raster_s *, struct raster_cache_s *,
 
176
                             unsigned int *, unsigned int *);
 
177
 
 
178
    int intialized;
252
179
};
253
180
typedef struct raster_s raster_t;
254
181
 
255
182
struct screenshot_s;
256
183
 
257
 
#define RASTER_PIXEL(raster, c) (raster)->pixel_table.sing[(c)]
258
 
 
259
 
/* FIXME: MSDOS does not need double or quad pixel.
260
 
`ifdef' them out once all video chips actually honour this.  */
261
 
 
262
 
#define RASTER_PIXEL2(raster, c) (raster)->pixel_table.doub[(c)]
263
 
#define RASTER_PIXEL4(raster, c) (raster)->pixel_table.quad[(c)]
264
 
 
265
 
extern int raster_init(raster_t *raster, unsigned int num_modes,
266
 
                       unsigned int num_sprites);
 
184
extern int raster_init(raster_t *raster, unsigned int num_modes);
 
185
extern void raster_shutdown(raster_t *raster);
267
186
extern raster_t *raster_new(unsigned int num_modes, unsigned int num_sprites);
268
187
extern void raster_reset(raster_t *raster);
269
188
extern int raster_realize(raster_t *raster);
270
 
extern void raster_set_exposure_handler(raster_t *raster,
271
 
                                        void *exposure_handler);
272
 
extern void raster_set_table_refresh_handler(raster_t *raster,
273
 
                                             void (*handler)(void));
 
189
extern void raster_canvas_init(raster_t *raster);
274
190
extern void raster_set_geometry(raster_t *raster,
 
191
                                unsigned int canvas_width,
 
192
                                unsigned int canvas_height,
275
193
                                unsigned int screen_width,
276
194
                                unsigned int screen_height,
277
195
                                unsigned int gfx_width,
283
201
                                int gfx_area_moves,
284
202
                                unsigned int first_displayed_line,
285
203
                                unsigned int last_displayed_line,
286
 
                                unsigned int extra_offscreen_border);
287
 
extern void raster_invalidate_cache(raster_t *raster,
288
 
                                    unsigned int screen_height);
289
 
extern void raster_resize_viewport(raster_t *raster,
290
 
                                   unsigned int width, unsigned int height);
291
 
extern void raster_set_pixel_size(raster_t *raster, unsigned int width,
292
 
                                  unsigned int height, int videorendermode);
293
 
extern void raster_emulate_line(raster_t *raster);
 
204
                                unsigned int extra_offscreen_border_left,
 
205
                                unsigned int extra_offscreen_border_right);
 
206
extern void raster_new_cache(raster_t *raster, unsigned int screen_height);
 
207
extern void raster_draw_buffer_ptr_update(raster_t *raster);
294
208
extern void raster_force_repaint(raster_t *raster);
295
 
extern int raster_set_palette(raster_t *raster, struct palette_s *palette);
296
 
extern void raster_set_title(raster_t *raster, const char *title);
 
209
extern void raster_set_title(raster_t *raster, const char *name);
297
210
extern void raster_skip_frame(raster_t *raster, int skip);
298
211
extern void raster_enable_cache(raster_t *raster, int enable);
299
 
extern void raster_enable_double_scan(raster_t *raster, int enable);
300
 
extern void raster_enable_double_size(raster_t *raster, int enablex, int enabley);
301
212
extern void raster_mode_change(void);
302
 
extern void raster_rebuild_tables(raster_t *raster);
303
 
extern void raster_handle_end_of_frame(raster_t *raster);
304
213
extern void raster_set_canvas_refresh(raster_t *raster, int enable);
305
 
extern int raster_screenshot(raster_t *raster, struct screenshot_s *screenshot);
306
 
extern void raster_free(raster_t *raster);
307
 
 
 
214
extern void raster_screenshot(raster_t *raster,
 
215
                              struct screenshot_s *screenshot);
 
216
extern void raster_async_refresh(raster_t *raster,
 
217
                                 struct canvas_refresh_s *ref);
 
218
extern int raster_calc_frame_buffer_width(raster_t *raster);
 
219
extern void raster_line_changes_init(raster_t *raster);
 
220
extern void raster_line_changes_sprite_init(raster_t *raster);
308
221
 
309
222
/* Inlined functions.  These need to be *fast*.  */
310
223
 
311
 
inline static void raster_add_int_change_next_line(raster_t *raster,
312
 
                                                   int *ptr,
313
 
                                                   int new_value)
314
 
{
315
 
    if (raster->skip_frame)
316
 
        *ptr = new_value;
317
 
    else
318
 
        raster_changes_add_int(&raster->changes.next_line, 0, ptr, new_value);
319
 
}
320
 
 
321
 
inline static void raster_add_ptr_change_next_line(raster_t *raster,
322
 
                                                   void **ptr,
323
 
                                                   void *new_value)
324
 
{
325
 
    if (raster->skip_frame)
326
 
        *ptr = new_value;
327
 
    else
328
 
        raster_changes_add_ptr(&raster->changes.next_line, 0, ptr, new_value);
329
 
}
330
 
 
331
 
inline static void raster_add_int_change_foreground(raster_t *raster,
332
 
                                                    int char_x,
333
 
                                                    int *ptr,
334
 
                                                    int new_value)
335
 
{
336
 
    if (raster->skip_frame || char_x <= 0)
337
 
        *ptr = new_value;
338
 
    else if (char_x < (int)raster->geometry.text_size.width) {
339
 
        raster_changes_add_int(&raster->changes.foreground,
340
 
                               char_x, ptr, new_value);
341
 
        raster->changes.have_on_this_line = 1;
342
 
    } else {
343
 
        raster_add_int_change_next_line(raster, ptr, new_value);
344
 
    }
345
 
}
346
 
 
347
 
inline static void raster_add_ptr_change_foreground(raster_t *raster,
348
 
                                                    int char_x,
349
 
                                                    void **ptr,
350
 
                                                    void *new_value)
351
 
{
352
 
    if (raster->skip_frame || char_x <= 0)
353
 
        *ptr = new_value;
354
 
    else if (char_x < (int)raster->geometry.text_size.width) {
355
 
        raster_changes_add_ptr(&raster->changes.foreground,
356
 
                               char_x, ptr, new_value);
357
 
        raster->changes.have_on_this_line = 1;
358
 
    } else {
359
 
        raster_add_ptr_change_next_line(raster, ptr, new_value);
360
 
    }
361
 
}
362
 
 
363
 
inline static void raster_add_int_change_background(raster_t *raster,
364
 
                                                    int raster_x,
365
 
                                                    int *ptr,
366
 
                                                    int new_value)
367
 
{
368
 
    if (raster->skip_frame || raster_x <= 0)
369
 
        *ptr = new_value;
370
 
    else if (raster_x < (int)raster->geometry.screen_size.width) {
371
 
        raster_changes_add_int(&raster->changes.background,
372
 
                               raster_x, ptr, new_value);
373
 
        raster->changes.have_on_this_line = 1;
374
 
    } else {
375
 
        raster_add_int_change_next_line(raster, ptr, new_value);
376
 
    }
377
 
}
378
 
 
379
 
inline static void raster_add_ptr_change_background(raster_t *raster,
380
 
                                                    int raster_x,
381
 
                                                    void **ptr,
382
 
                                                    void *new_value)
383
 
{
384
 
    if (raster->skip_frame || raster_x <= 0)
385
 
        *ptr = new_value;
386
 
    else if (raster_x < (int)raster->geometry.screen_size.width) {
387
 
        raster_changes_add_ptr(&raster->changes.background,
388
 
                               raster_x, ptr, new_value);
389
 
        raster->changes.have_on_this_line = 1;
390
 
    } else {
391
 
        raster_add_ptr_change_next_line(raster, ptr, new_value);
392
 
    }
393
 
}
394
 
 
395
 
inline static void raster_add_int_change_border(raster_t *raster,
396
 
                                                int raster_x,
397
 
                                                int *ptr,
398
 
                                                int new_value)
399
 
{
400
 
    if (raster->skip_frame || raster_x <= 0)
401
 
        *ptr = new_value;
402
 
    else if (raster_x < (int)raster->geometry.screen_size.width) {
403
 
        raster_changes_add_int(&raster->changes.border,
404
 
                               raster_x, ptr, new_value);
405
 
        raster->changes.have_on_this_line = 1;
406
 
    } else {
407
 
        raster_add_int_change_next_line(raster, ptr, new_value);
408
 
    }
409
 
}
410
 
 
411
 
inline static void vid_memcpy(PIXEL *dst, PIXEL *src, unsigned int count)
412
 
{
413
 
    memcpy(dst, src, count * sizeof(PIXEL));
414
 
}
415
 
 
416
 
#if VIDEO_DISPLAY_DEPTH > 8
417
 
 
418
 
inline static void vid_memset(PIXEL *dst, PIXEL value, unsigned int count)
419
 
{
420
 
    int i;
421
 
 
422
 
    for (i = 0; i < count; i++)
423
 
        dst[i] = value;
424
 
}
425
 
 
426
 
#else
427
 
 
428
 
inline static void vid_memset(PIXEL *dst, PIXEL value, unsigned int count)
429
 
{
430
 
    memset(dst, value, count);
 
224
inline static void raster_changes_next_line_add_int(raster_t *raster,
 
225
                                                    int *ptr,
 
226
                                                    int new_value)
 
227
{
 
228
    raster_changes_add_int(raster->changes->next_line, 0, ptr, new_value);
 
229
}
 
230
 
 
231
inline static void raster_changes_next_line_add_ptr(raster_t *raster,
 
232
                                                    void **ptr,
 
233
                                                    void *new_value)
 
234
{
 
235
    raster_changes_add_ptr(raster->changes->next_line, 0, ptr, new_value);
 
236
}
 
237
 
 
238
inline static void raster_changes_foreground_add_int(raster_t *raster,
 
239
                                                     int char_x,
 
240
                                                     int *ptr,
 
241
                                                     int new_value)
 
242
{
 
243
    if (char_x <= 0)
 
244
        *ptr = new_value;
 
245
    else if (char_x < (int)raster->geometry->text_size.width) {
 
246
        raster_changes_add_int(raster->changes->foreground,
 
247
                               char_x, ptr, new_value);
 
248
        raster->changes->have_on_this_line = 1;
 
249
    } else {
 
250
        raster_changes_next_line_add_int(raster, ptr, new_value);
 
251
    }
 
252
}
 
253
 
 
254
inline static void raster_changes_foreground_add_ptr(raster_t *raster,
 
255
                                                     int char_x,
 
256
                                                     void **ptr,
 
257
                                                     void *new_value)
 
258
{
 
259
    if (char_x <= 0)
 
260
        *ptr = new_value;
 
261
    else if (char_x < (int)raster->geometry->text_size.width) {
 
262
        raster_changes_add_ptr(raster->changes->foreground,
 
263
                               char_x, ptr, new_value);
 
264
        raster->changes->have_on_this_line = 1;
 
265
    } else {
 
266
        raster_changes_next_line_add_ptr(raster, ptr, new_value);
 
267
    }
 
268
}
 
269
 
 
270
inline static void raster_changes_background_add_int(raster_t *raster,
 
271
                                                     int raster_x,
 
272
                                                     int *ptr,
 
273
                                                     int new_value)
 
274
{
 
275
    if (raster_x <= 0)
 
276
        *ptr = new_value;
 
277
    else if (raster_x < (int)raster->geometry->screen_size.width) {
 
278
        raster_changes_add_int(raster->changes->background,
 
279
                               raster_x, ptr, new_value);
 
280
        raster->changes->have_on_this_line = 1;
 
281
    } else {
 
282
        raster_changes_next_line_add_int(raster, ptr, new_value);
 
283
    }
 
284
}
 
285
 
 
286
inline static void raster_changes_background_add_ptr(raster_t *raster,
 
287
                                                     int raster_x,
 
288
                                                     void **ptr,
 
289
                                                     void *new_value)
 
290
{
 
291
    if (raster_x <= 0)
 
292
        *ptr = new_value;
 
293
    else if (raster_x < (int)raster->geometry->screen_size.width) {
 
294
        raster_changes_add_ptr(raster->changes->background,
 
295
                               raster_x, ptr, new_value);
 
296
        raster->changes->have_on_this_line = 1;
 
297
    } else {
 
298
        raster_changes_next_line_add_ptr(raster, ptr, new_value);
 
299
    }
 
300
}
 
301
 
 
302
inline static void raster_changes_border_add_int(raster_t *raster,
 
303
                                                 int raster_x,
 
304
                                                 int *ptr,
 
305
                                                 int new_value)
 
306
{
 
307
    if (raster_x <= 0)
 
308
        *ptr = new_value;
 
309
    else if (raster_x < (int)raster->geometry->screen_size.width) {
 
310
        raster_changes_add_int(raster->changes->border,
 
311
                               raster_x, ptr, new_value);
 
312
        raster->changes->have_on_this_line = 1;
 
313
    } else {
 
314
        raster_changes_next_line_add_int(raster, ptr, new_value);
 
315
    }
 
316
}
 
317
 
 
318
inline static void raster_changes_sprites_add_int(raster_t *raster,
 
319
                                                  int raster_x,
 
320
                                                  int *ptr,
 
321
                                                  int new_value)
 
322
{
 
323
    if (raster_x < -(int)raster->geometry->extra_offscreen_border_left)
 
324
        *ptr = new_value;
 
325
    else if (raster_x < (int)(raster->geometry->screen_size.width 
 
326
                        + raster->geometry->extra_offscreen_border_right)) {
 
327
        raster_changes_add_int(raster->changes->sprites,
 
328
                               raster_x, ptr, new_value);
 
329
        raster->changes->have_on_this_line = 1;
 
330
    } else {
 
331
        raster_changes_next_line_add_int(raster, ptr, new_value);
 
332
    }
431
333
}
432
334
 
433
335
#endif
434
336
 
435
 
#endif /* _RASTER_H */
436