~ubuntu-branches/ubuntu/raring/mame/raring-proposed

« back to all changes in this revision

Viewing changes to mess/src/mame/video/n8080.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach, Jordi Mallach, Emmanuel Kasper
  • Date: 2011-12-19 22:56:27 UTC
  • mfrom: (0.1.2)
  • Revision ID: package-import@ubuntu.com-20111219225627-ub5oga1oys4ogqzm
Tags: 0.144-1
[ Jordi Mallach ]
* Fix syntax errors in DEP5 copyright file (lintian).
* Use a versioned copyright Format specification field.
* Update Vcs-* URLs.
* Move transitional packages to the new metapackages section, and make
  them priority extra.
* Remove references to GNU/Linux and MESS sources from copyright.
* Add build variables for s390x.
* Use .xz tarballs as it cuts 4MB for the upstream sources.
* Add nplayers.ini as a patch. Update copyright file to add CC-BY-SA-3.0.

[ Emmanuel Kasper ]
* New upstream release. Closes: #651538.
* Add Free Desktop compliant png icons of various sizes taken from
  the hydroxygen iconset
* Mess is now built from a new source package, to avoid possible source
  incompatibilities between mame and the mess overlay.
* Mame-tools are not built from the mame source package anymore, but
  from the mess source package

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 
3
 
  Nintendo 8080 video emulation
4
 
 
5
 
***************************************************************************/
6
 
 
7
 
#include "emu.h"
8
 
#include "includes/n8080.h"
9
 
 
10
 
 
11
 
WRITE8_HANDLER( n8080_video_control_w )
12
 
{
13
 
        n8080_state *state = space->machine().driver_data<n8080_state>();
14
 
 
15
 
        state->m_sheriff_color_mode = (data >> 3) & 3;
16
 
        state->m_sheriff_color_data = (data >> 0) & 7;
17
 
        flip_screen_set_no_update(space->machine(), data & 0x20);
18
 
}
19
 
 
20
 
 
21
 
PALETTE_INIT( n8080 )
22
 
{
23
 
        int i;
24
 
 
25
 
        for (i = 0; i < 8; i++)
26
 
                palette_set_color_rgb(machine, i, pal1bit(i >> 0), pal1bit(i >> 1), pal1bit(i >> 2));
27
 
}
28
 
 
29
 
 
30
 
PALETTE_INIT( helifire )
31
 
{
32
 
        int i;
33
 
 
34
 
        PALETTE_INIT_CALL(n8080);
35
 
 
36
 
        for (i = 0; i < 0x100; i++)
37
 
        {
38
 
                int level = 0xff * exp(-3 * i / 255.); /* capacitor discharge */
39
 
 
40
 
                palette_set_color(machine, 0x000 + 8 + i, MAKE_RGB(0x00, 0x00, level));   /* shades of blue */
41
 
                palette_set_color(machine, 0x100 + 8 + i, MAKE_RGB(0x00, 0xC0, level));   /* shades of blue w/ green star */
42
 
 
43
 
                palette_set_color(machine, 0x200 + 8 + i, MAKE_RGB(level, 0x00, 0x00));   /* shades of red */
44
 
                palette_set_color(machine, 0x300 + 8 + i, MAKE_RGB(level, 0xC0, 0x00));   /* shades of red w/ green star */
45
 
        }
46
 
}
47
 
 
48
 
 
49
 
void spacefev_start_red_cannon( running_machine &machine )
50
 
{
51
 
        n8080_state *state = machine.driver_data<n8080_state>();
52
 
 
53
 
        state->m_spacefev_red_cannon = 1;
54
 
        state->m_cannon_timer->adjust(attotime::from_usec(550 * 68 * 10));
55
 
}
56
 
 
57
 
 
58
 
static TIMER_CALLBACK( spacefev_stop_red_cannon )
59
 
{
60
 
        n8080_state *state = machine.driver_data<n8080_state>();
61
 
 
62
 
        state->m_spacefev_red_cannon = 0;
63
 
        state->m_cannon_timer->adjust(attotime::never);
64
 
}
65
 
 
66
 
 
67
 
static void helifire_next_line( running_machine &machine )
68
 
{
69
 
        n8080_state *state = machine.driver_data<n8080_state>();
70
 
 
71
 
        state->m_helifire_mv++;
72
 
 
73
 
        if (state->m_helifire_sc % 4 == 2)
74
 
        {
75
 
                state->m_helifire_mv %= 256;
76
 
        }
77
 
        else
78
 
        {
79
 
                if (flip_screen_get(machine))
80
 
                        state->m_helifire_mv %= 255;
81
 
                else
82
 
                        state->m_helifire_mv %= 257;
83
 
        }
84
 
 
85
 
        if (state->m_helifire_mv == 128)
86
 
        {
87
 
                state->m_helifire_sc++;
88
 
        }
89
 
}
90
 
 
91
 
 
92
 
VIDEO_START( spacefev )
93
 
{
94
 
        n8080_state *state = machine.driver_data<n8080_state>();
95
 
 
96
 
        state->m_cannon_timer = machine.scheduler().timer_alloc(FUNC(spacefev_stop_red_cannon));
97
 
 
98
 
        flip_screen_set_no_update(machine, 0);
99
 
 
100
 
        state->save_item(NAME(state->m_spacefev_red_screen));
101
 
        state->save_item(NAME(state->m_spacefev_red_cannon));
102
 
}
103
 
 
104
 
 
105
 
VIDEO_START( sheriff )
106
 
{
107
 
        n8080_state *state = machine.driver_data<n8080_state>();
108
 
 
109
 
        flip_screen_set_no_update(machine, 0);
110
 
 
111
 
        state->save_item(NAME(state->m_sheriff_color_mode));
112
 
        state->save_item(NAME(state->m_sheriff_color_data));
113
 
}
114
 
 
115
 
 
116
 
VIDEO_START( helifire )
117
 
{
118
 
        n8080_state *state = machine.driver_data<n8080_state>();
119
 
        UINT8 data = 0;
120
 
        int i;
121
 
 
122
 
        state->save_item(NAME(state->m_helifire_mv));
123
 
        state->save_item(NAME(state->m_helifire_sc));
124
 
        state->save_item(NAME(state->m_helifire_flash));
125
 
        state->save_item(NAME(state->m_helifire_LSFR));
126
 
 
127
 
        for (i = 0; i < 63; i++)
128
 
        {
129
 
                int bit =
130
 
                        (data >> 6) ^
131
 
                        (data >> 7) ^ 1;
132
 
 
133
 
                data = (data << 1) | (bit & 1);
134
 
 
135
 
                state->m_helifire_LSFR[i] = data;
136
 
        }
137
 
 
138
 
        flip_screen_set_no_update(machine, 0);
139
 
}
140
 
 
141
 
 
142
 
SCREEN_UPDATE( spacefev )
143
 
{
144
 
        n8080_state *state = screen->machine().driver_data<n8080_state>();
145
 
        UINT8 mask = flip_screen_get(screen->machine()) ? 0xff : 0x00;
146
 
 
147
 
        int x;
148
 
        int y;
149
 
 
150
 
        const UINT8* pRAM = state->m_videoram;
151
 
        const UINT8* pPROM = screen->machine().region("proms")->base();
152
 
 
153
 
        for (y = 0; y < 256; y++)
154
 
        {
155
 
                UINT16* pLine = BITMAP_ADDR16(bitmap, y ^ mask, 0);
156
 
 
157
 
                for (x = 0; x < 256; x += 8)
158
 
                {
159
 
                        int n;
160
 
 
161
 
                        UINT8 color = 0;
162
 
 
163
 
                        if (state->m_spacefev_red_screen)
164
 
                                color = 1;
165
 
                        else
166
 
                        {
167
 
                                UINT8 val = pPROM[x >> 3];
168
 
 
169
 
                                if ((x >> 3) == 0x06)
170
 
                                {
171
 
                                        color = state->m_spacefev_red_cannon ? 1 : 7;
172
 
                                }
173
 
 
174
 
                                if ((x >> 3) == 0x1b)
175
 
                                {
176
 
                                        static const UINT8 ufo_color[] =
177
 
                                        {
178
 
                                                1, /* red     */
179
 
                                                2, /* green   */
180
 
                                                7, /* white   */
181
 
                                                3, /* yellow  */
182
 
                                                5, /* magenta */
183
 
                                                6, /* cyan    */
184
 
                                        };
185
 
 
186
 
                                        int cycle = screen->frame_number() / 32;
187
 
 
188
 
                                        color = ufo_color[cycle % 6];
189
 
                                }
190
 
 
191
 
                                for (n = color + 1; n < 8; n++)
192
 
                                {
193
 
                                        if (~val & (1 << n))
194
 
                                        {
195
 
                                                color = n;
196
 
                                        }
197
 
                                }
198
 
                        }
199
 
 
200
 
                        for (n = 0; n < 8; n++)
201
 
                        {
202
 
                                pLine[(x + n) ^ mask] = (pRAM[x >> 3] & (1 << n)) ? color : 0;
203
 
                        }
204
 
                }
205
 
 
206
 
                pRAM += 32;
207
 
        }
208
 
        return 0;
209
 
}
210
 
 
211
 
 
212
 
SCREEN_UPDATE( sheriff )
213
 
{
214
 
        n8080_state *state = screen->machine().driver_data<n8080_state>();
215
 
        UINT8 mask = flip_screen_get(screen->machine()) ? 0xff : 0x00;
216
 
 
217
 
        const UINT8* pPROM = screen->machine().region("proms")->base();
218
 
 
219
 
        int x;
220
 
        int y;
221
 
 
222
 
        const UINT8* pRAM = state->m_videoram;
223
 
 
224
 
        for (y = 0; y < 256; y++)
225
 
        {
226
 
                UINT16* pLine = BITMAP_ADDR16(bitmap, y ^ mask, 0);
227
 
 
228
 
                for (x = 0; x < 256; x += 8)
229
 
                {
230
 
                        int n;
231
 
 
232
 
                        UINT8 color = pPROM[32 * (y >> 3) + (x >> 3)];
233
 
 
234
 
                        if (state->m_sheriff_color_mode == 1 && !(color & 8))
235
 
                                color = state->m_sheriff_color_data ^ 7;
236
 
 
237
 
                        if (state->m_sheriff_color_mode == 2)
238
 
                                color = state->m_sheriff_color_data ^ 7;
239
 
 
240
 
                        if (state->m_sheriff_color_mode == 3)
241
 
                                color = 7;
242
 
 
243
 
                        for (n = 0; n < 8; n++)
244
 
                        {
245
 
                                pLine[(x + n) ^ mask] = ((pRAM[x >> 3] >> n) & 1) ? (color & 7) : 0;
246
 
                        }
247
 
                }
248
 
 
249
 
                pRAM += 32;
250
 
        }
251
 
        return 0;
252
 
}
253
 
 
254
 
 
255
 
SCREEN_UPDATE( helifire )
256
 
{
257
 
        n8080_state *state = screen->machine().driver_data<n8080_state>();
258
 
        int SUN_BRIGHTNESS = input_port_read(screen->machine(), "POT0");
259
 
        int SEA_BRIGHTNESS = input_port_read(screen->machine(), "POT1");
260
 
 
261
 
        static const int wave[8] = { 0, 1, 2, 2, 2, 1, 0, 0 };
262
 
 
263
 
        unsigned saved_mv = state->m_helifire_mv;
264
 
        unsigned saved_sc = state->m_helifire_sc;
265
 
 
266
 
        int x;
267
 
        int y;
268
 
 
269
 
        for (y = 0; y < 256; y++)
270
 
        {
271
 
                UINT16* pLine = BITMAP_ADDR16(bitmap, y, 0);
272
 
 
273
 
                int level = 120 + wave[state->m_helifire_mv & 7];
274
 
 
275
 
                /* draw sky */
276
 
 
277
 
                for (x = level; x < 256; x++)
278
 
                {
279
 
                        pLine[x] = 0x200 + 8 + SUN_BRIGHTNESS + x - level;
280
 
                }
281
 
 
282
 
                /* draw stars */
283
 
 
284
 
                if (state->m_helifire_mv % 8 == 4) /* upper half */
285
 
                {
286
 
                        int step = (320 * (state->m_helifire_mv - 0)) % sizeof state->m_helifire_LSFR;
287
 
 
288
 
                        int data =
289
 
                                ((state->m_helifire_LSFR[step] & 1) << 6) |
290
 
                                ((state->m_helifire_LSFR[step] & 2) << 4) |
291
 
                                ((state->m_helifire_LSFR[step] & 4) << 2) |
292
 
                                ((state->m_helifire_LSFR[step] & 8) << 0);
293
 
 
294
 
                        pLine[0x80 + data] |= 0x100;
295
 
                }
296
 
 
297
 
                if (state->m_helifire_mv % 8 == 5) /* lower half */
298
 
                {
299
 
                        int step = (320 * (state->m_helifire_mv - 1)) % sizeof state->m_helifire_LSFR;
300
 
 
301
 
                        int data =
302
 
                                ((state->m_helifire_LSFR[step] & 1) << 6) |
303
 
                                ((state->m_helifire_LSFR[step] & 2) << 4) |
304
 
                                ((state->m_helifire_LSFR[step] & 4) << 2) |
305
 
                                ((state->m_helifire_LSFR[step] & 8) << 0);
306
 
 
307
 
                        pLine[0x00 + data] |= 0x100;
308
 
                }
309
 
 
310
 
                /* draw sea */
311
 
 
312
 
                for (x = 0; x < level; x++)
313
 
                {
314
 
                        pLine[x] = 8 + SEA_BRIGHTNESS + x;
315
 
                }
316
 
 
317
 
                /* draw foreground */
318
 
 
319
 
                for (x = 0; x < 256; x += 8)
320
 
                {
321
 
                        int offset = 32 * y + (x >> 3);
322
 
 
323
 
                        int n;
324
 
 
325
 
                        for (n = 0; n < 8; n++)
326
 
                        {
327
 
                                if (flip_screen_get(screen->machine()))
328
 
                                {
329
 
                                        if ((state->m_videoram[offset ^ 0x1fff] << n) & 0x80)
330
 
                                        {
331
 
                                                pLine[x + n] = state->m_colorram[offset ^ 0x1fff] & 7;
332
 
                                        }
333
 
                                }
334
 
                                else
335
 
                                {
336
 
                                        if ((state->m_videoram[offset] >> n) & 1)
337
 
                                        {
338
 
                                                pLine[x + n] = state->m_colorram[offset] & 7;
339
 
                                        }
340
 
                                }
341
 
                        }
342
 
                }
343
 
 
344
 
                /* next line */
345
 
 
346
 
                helifire_next_line(screen->machine());
347
 
        }
348
 
 
349
 
        state->m_helifire_mv = saved_mv;
350
 
        state->m_helifire_sc = saved_sc;
351
 
        return 0;
352
 
}
353
 
 
354
 
 
355
 
SCREEN_EOF( helifire )
356
 
{
357
 
        n8080_state *state = machine.driver_data<n8080_state>();
358
 
        int n = (machine.primary_screen->frame_number() >> 1) % sizeof state->m_helifire_LSFR;
359
 
 
360
 
        int i;
361
 
 
362
 
        for (i = 0; i < 8; i++)
363
 
        {
364
 
                int R = (i & 1);
365
 
                int G = (i & 2);
366
 
                int B = (i & 4);
367
 
 
368
 
                if (state->m_helifire_flash)
369
 
                {
370
 
                        if (state->m_helifire_LSFR[n] & 0x20)
371
 
                        {
372
 
                                G |= B;
373
 
                        }
374
 
 
375
 
                        if (machine.primary_screen->frame_number() & 0x04)
376
 
                        {
377
 
                                R |= G;
378
 
                        }
379
 
                }
380
 
 
381
 
                palette_set_color_rgb(machine,i,
382
 
                        R ? 255 : 0,
383
 
                        G ? 255 : 0,
384
 
                        B ? 255 : 0);
385
 
        }
386
 
 
387
 
        for (i = 0; i < 256; i++)
388
 
        {
389
 
                helifire_next_line(machine);
390
 
        }
391
 
}