~ubuntu-branches/ubuntu/raring/vice/raring

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
 * video.m - MacVICE video interface
 *
 * Written by
 *  Christian Vogelgsang <chris@vogelgsang.org>
 *  Michael Klein <michael.klein@puffin.lb.shuttle.de>
 *
 * This file is part of VICE, the Versatile Commodore Emulator.
 * See README for copyright notice.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 *  02111-1307  USA.
 *
 */

#include "videoarch.h"
#include "palette.h"

#import "vicemachinenotifier.h"
#import "vicemachine.h"
#import "vicewindow.h"

// VICE Video Resources

int video_arch_resources_init(void)
{
    return 0;
}

void video_arch_resources_shutdown(void)
{
}

// VICE interface:

int video_init_cmdline_options(void)
{
    return 0;
}

int video_init(void)
{
   return 0;
}

void video_shutdown(void)
{
}

void video_arch_canvas_init(struct video_canvas_s *canvas)
{
    canvas->window = nil;
    canvas->video_draw_buffer_callback = NULL;
}

// ---------- VICE Canvas ----------

video_canvas_t *video_canvas_create(struct video_canvas_s *canvas,
                                    unsigned int *width,
                                    unsigned int *height,
                                    int mapped)
{
    int w = *width;
    int h = *height;
    
    // encapsulate canvas ptr
    video_canvas_t *canvasPtr = canvas;
    NSData *data = [NSData dataWithBytes:&canvasPtr length:sizeof(video_canvas_t *)];

    // call UI thread to create canvas
    [[theVICEMachine app] createCanvas:data withSize:NSMakeSize(w,h)];

    // init rendering
    video_canvas_set_palette(canvas,canvas->palette);

    // register canvas in machine controller (to allow access via id)
    canvas->canvasId = [theVICEMachine registerCanvas:canvas];

    // re-post all required notifications for new window
    [[theVICEMachine machineNotifier] notifyNewWindow];

    return canvas;
}

void video_canvas_destroy(video_canvas_t *canvas)
{
    // encapsulate canvas ptr
    video_canvas_t *canvasPtr = canvas;
    NSData *data = [NSData dataWithBytes:&canvasPtr length:sizeof(video_canvas_t *)];

    // call UI thread to destroy canvas
    [[theVICEMachine app] destroyCanvas:data];

    video_canvas_shutdown(canvas);
}

// VICE wants to change the size of the canvas -> adapt View
void video_canvas_resize(video_canvas_t * canvas,
                         unsigned int width,
                         unsigned int height)
{
    if (canvas->videoconfig->doublesizex)
        width *= 2;
    if (canvas->videoconfig->doublesizey)
        height *= 2;
    if (canvas->width == width && canvas->height == height)
        return;

    canvas->width = width;
    canvas->height = height;

    // encapsulate canvas ptr
    video_canvas_t *canvasPtr = canvas;
    NSData *data = [NSData dataWithBytes:&canvasPtr length:sizeof(video_canvas_t *)];

    // call UI thread to resize canvas
    [[theVICEMachine app] resizeCanvas:data withSize:NSMakeSize(width,height)];
}

void video_canvas_refresh(video_canvas_t *canvas,
                          unsigned int xs, unsigned int ys,
                          unsigned int xi, unsigned int yi,
                          unsigned int w, unsigned int h)
{
    if (canvas->videoconfig->doublesizex) {
        xi *= 2;
        w *= 2;
    }
    if (canvas->videoconfig->doublesizey) {
        yi *= 2;
        h *= 2;
    }
    w = MIN(w, canvas->width - xi);
    h = MIN(h, canvas->height - yi);

    // render into texture buffer
    video_canvas_render(canvas, canvas->buffer,
                        w, h, xs, ys, xi, yi, 
                        canvas->pitch, canvas->depth);

#if 1
    // call updateCanvas selector in main thread - non-blocking
    VICEWindow *window = canvas->window;
    [window performSelectorOnMainThread:@selector(updateCanvas:) 
                             withObject:nil 
                          waitUntilDone:NO];
#else
    // call updateCanvas via proxy object - blocks if main app blocks
    // encapsulate canvas ptr
    video_canvas_t *canvasPtr = canvas;    
    NSData *data = [NSData dataWithBytes:&canvasPtr length:sizeof(video_canvas_t *)];
    // call UI thread to resize canvas
    [[theVICEMachine app] updateCanvas:data];
#endif
}

// ----- Palette Stuff -----

int video_canvas_set_palette(video_canvas_t *c, palette_t *p)
{
    int i;
    int rshift = 0;
    int rbits = 0;
    int gshift = 0;
    int gbits = 0;
    int bshift = 0;
    int bbits = 0;
    DWORD rmask = 0;
    DWORD gmask = 0;
    DWORD bmask = 0;

    c->palette = p;
    for (i = 0; i < p->num_entries; i++)
    {
        DWORD col;

        switch (c->depth)
        {
            case 16:    /* RGB 5:5:5 */
                /* TODO */
                rbits = 3; rshift = 10; rmask = 0x1f;
                gbits = 3; gshift = 5; gmask = 0x1f;
                bbits = 3; bshift = 0; bmask = 0x1f;
                break;
            case 32:    /* RGB 8:8:8 */
            default:
                rbits = 0; rshift = 16; rmask = 0xff;
                gbits = 0; gshift = 8; gmask = 0xff;
                bbits = 0; bshift = 0; bmask = 0xff;
        }
        col = (p->entries[i].red   >> rbits) << rshift
            | (p->entries[i].green >> gbits) << gshift
            | (p->entries[i].blue  >> bbits) << bshift;

        video_render_setphysicalcolor(c->videoconfig, i, col, c->depth);
    }
    if (c->depth > 8)
    {
        for (i = 0; i < 256; i++)
        {
            video_render_setrawrgb(i,
                                   ((i & (rmask << rbits)) >> rbits) << rshift,
                                   ((i & (gmask << gbits)) >> gbits) << gshift,
                                   ((i & (bmask << bbits)) >> bbits) << bshift);
        }
        video_render_initraw();
    }

    return 0;
}

// ----- Color Stuff -----

int uicolor_alloc_color(unsigned int red, unsigned int green,
                        unsigned int blue, unsigned long *color_pixel,
                        BYTE *pixel_return)
{
    return 0;
}

void uicolor_convert_color_table(unsigned int colnr, BYTE *data,
                                 long color_pixel, void *c)
{
}

void uicolor_free_color(unsigned int red, unsigned int green,
                        unsigned int blue, unsigned long color_pixel)
{
}