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

« back to all changes in this revision

Viewing changes to mess/src/mame/video/pastelg.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
 
    Video Hardware for Nichibutsu Mahjong series.
4
 
 
5
 
    Driver by Takahiro Nogi 2000/06/07 -
6
 
 
7
 
******************************************************************************/
8
 
 
9
 
#include "emu.h"
10
 
#include "includes/nb1413m3.h"
11
 
#include "includes/pastelg.h"
12
 
 
13
 
 
14
 
static void pastelg_vramflip(running_machine &machine);
15
 
static void pastelg_gfxdraw(running_machine &machine);
16
 
 
17
 
 
18
 
/******************************************************************************
19
 
 
20
 
 
21
 
******************************************************************************/
22
 
PALETTE_INIT( pastelg )
23
 
{
24
 
        int i;
25
 
        int bit0, bit1, bit2, bit3, r, g, b;
26
 
 
27
 
        for (i = 0; i < machine.total_colors(); i++)
28
 
        {
29
 
                bit0 = (color_prom[0] >> 0) & 0x01;
30
 
                bit1 = (color_prom[0] >> 1) & 0x01;
31
 
                bit2 = (color_prom[0] >> 2) & 0x01;
32
 
                bit3 = (color_prom[0] >> 3) & 0x01;
33
 
                r = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
34
 
                bit0 = (color_prom[0] >> 4) & 0x01;
35
 
                bit1 = (color_prom[0] >> 5) & 0x01;
36
 
                bit2 = (color_prom[0] >> 6) & 0x01;
37
 
                bit3 = (color_prom[0] >> 7) & 0x01;
38
 
                g = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
39
 
                bit0 = (color_prom[machine.total_colors()] >> 0) & 0x01;
40
 
                bit1 = (color_prom[machine.total_colors()] >> 1) & 0x01;
41
 
                bit2 = (color_prom[machine.total_colors()] >> 2) & 0x01;
42
 
                bit3 = (color_prom[machine.total_colors()] >> 3) & 0x01;
43
 
                b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
44
 
 
45
 
                palette_set_color(machine,i,MAKE_RGB(r,g,b));
46
 
                color_prom++;
47
 
        }
48
 
}
49
 
 
50
 
WRITE8_HANDLER( pastelg_clut_w )
51
 
{
52
 
        pastelg_state *state = space->machine().driver_data<pastelg_state>();
53
 
        state->m_clut[offset] = data;
54
 
}
55
 
 
56
 
/******************************************************************************
57
 
 
58
 
 
59
 
******************************************************************************/
60
 
int pastelg_blitter_src_addr_r(address_space *space)
61
 
{
62
 
        pastelg_state *state = space->machine().driver_data<pastelg_state>();
63
 
        return state->m_blitter_src_addr;
64
 
}
65
 
 
66
 
WRITE8_HANDLER( pastelg_blitter_w )
67
 
{
68
 
        pastelg_state *state = space->machine().driver_data<pastelg_state>();
69
 
        switch (offset)
70
 
        {
71
 
                case 0: state->m_blitter_src_addr = (state->m_blitter_src_addr & 0xff00) | data; break;
72
 
                case 1: state->m_blitter_src_addr = (state->m_blitter_src_addr & 0x00ff) | (data << 8); break;
73
 
                case 2: state->m_blitter_destx = data; break;
74
 
                case 3: state->m_blitter_desty = data; break;
75
 
                case 4: state->m_blitter_sizex = data; break;
76
 
                case 5: state->m_blitter_sizey = data;
77
 
                                /* writing here also starts the blit */
78
 
                                pastelg_gfxdraw(space->machine());
79
 
                                break;
80
 
                case 6: state->m_blitter_direction_x = (data & 0x01) ? 1 : 0;
81
 
                                state->m_blitter_direction_y = (data & 0x02) ? 1 : 0;
82
 
                                state->m_flipscreen = (data & 0x04) ? 0 : 1;
83
 
                                state->m_dispflag = (data & 0x08) ? 0 : 1;
84
 
                                pastelg_vramflip(space->machine());
85
 
                                break;
86
 
        }
87
 
}
88
 
 
89
 
 
90
 
WRITE8_HANDLER( threeds_romsel_w )
91
 
{
92
 
        pastelg_state *state = space->machine().driver_data<pastelg_state>();
93
 
        if (data&0xfc) printf("%02x\n",data);
94
 
        state->m_gfxrom = (data & 0x3);
95
 
}
96
 
 
97
 
WRITE8_HANDLER( threeds_output_w )
98
 
{
99
 
        pastelg_state *state = space->machine().driver_data<pastelg_state>();
100
 
        state->m_palbank = ((data & 0x10) >> 4);
101
 
 
102
 
}
103
 
 
104
 
READ8_HANDLER( threeds_rom_readback_r )
105
 
{
106
 
        pastelg_state *state = space->machine().driver_data<pastelg_state>();
107
 
        UINT8 *GFX = space->machine().region("gfx1")->base();
108
 
 
109
 
        return GFX[(state->m_blitter_src_addr | (state->m_gfxrom << 16)) & 0x3ffff];
110
 
}
111
 
 
112
 
 
113
 
WRITE8_HANDLER( pastelg_romsel_w )
114
 
{
115
 
        pastelg_state *state = space->machine().driver_data<pastelg_state>();
116
 
        int gfxlen = space->machine().region("gfx1")->bytes();
117
 
        state->m_gfxrom = ((data & 0xc0) >> 6);
118
 
        state->m_palbank = ((data & 0x10) >> 4);
119
 
        nb1413m3_sndrombank1_w(space, 0, data);
120
 
 
121
 
        if ((state->m_gfxrom << 16) > (gfxlen - 1))
122
 
        {
123
 
#ifdef MAME_DEBUG
124
 
                popmessage("GFXROM BANK OVER!!");
125
 
#endif
126
 
                state->m_gfxrom &= (gfxlen / 0x20000 - 1);
127
 
        }
128
 
}
129
 
 
130
 
/******************************************************************************
131
 
 
132
 
 
133
 
******************************************************************************/
134
 
static void pastelg_vramflip(running_machine &machine)
135
 
{
136
 
        pastelg_state *state = machine.driver_data<pastelg_state>();
137
 
        int x, y;
138
 
        UINT8 color1, color2;
139
 
        int width = machine.primary_screen->width();
140
 
        int height = machine.primary_screen->height();
141
 
 
142
 
        if (state->m_flipscreen == state->m_flipscreen_old) return;
143
 
 
144
 
        for (y = 0; y < height; y++)
145
 
        {
146
 
                for (x = 0; x < width; x++)
147
 
                {
148
 
                        color1 = state->m_videoram[(y * width) + x];
149
 
                        color2 = state->m_videoram[((y ^ 0xff) * width) + (x ^ 0xff)];
150
 
                        state->m_videoram[(y * width) + x] = color2;
151
 
                        state->m_videoram[((y ^ 0xff) * width) + (x ^ 0xff)] = color1;
152
 
                }
153
 
        }
154
 
 
155
 
        state->m_flipscreen_old = state->m_flipscreen;
156
 
}
157
 
 
158
 
static TIMER_CALLBACK( blitter_timer_callback )
159
 
{
160
 
        nb1413m3_busyflag = 1;
161
 
}
162
 
 
163
 
static void pastelg_gfxdraw(running_machine &machine)
164
 
{
165
 
        pastelg_state *state = machine.driver_data<pastelg_state>();
166
 
        UINT8 *GFX = machine.region("gfx1")->base();
167
 
        int width = machine.primary_screen->width();
168
 
 
169
 
        int x, y;
170
 
        int dx, dy;
171
 
        int startx, starty;
172
 
        int sizex, sizey;
173
 
        int incx, incy;
174
 
        int ctrx, ctry;
175
 
        int readflag;
176
 
        int gfxaddr, gfxlen;
177
 
        int count;
178
 
        UINT8 color;
179
 
 
180
 
        nb1413m3_busyctr = 0;
181
 
 
182
 
        startx = state->m_blitter_destx + state->m_blitter_sizex;
183
 
        starty = state->m_blitter_desty + state->m_blitter_sizey;
184
 
 
185
 
 
186
 
        if (state->m_blitter_direction_x)
187
 
        {
188
 
                if (state->m_blitter_sizex&0x80) sizex = 0xff-state->m_blitter_sizex;
189
 
                else sizex=state->m_blitter_sizex;
190
 
                incx = 1;
191
 
        }
192
 
        else
193
 
        {
194
 
                sizex = state->m_blitter_sizex;
195
 
                incx = -1;
196
 
        }
197
 
 
198
 
        if (state->m_blitter_direction_y)
199
 
        {
200
 
                if (state->m_blitter_sizey&0x80) sizey = 0xff-state->m_blitter_sizey;
201
 
                else sizey=state->m_blitter_sizey;
202
 
                incy = 1;
203
 
        }
204
 
        else
205
 
        {
206
 
                sizey = state->m_blitter_sizey;
207
 
                incy = -1;
208
 
        }
209
 
 
210
 
        gfxlen = machine.region("gfx1")->bytes();
211
 
        gfxaddr = (state->m_gfxrom << 16) + state->m_blitter_src_addr;
212
 
 
213
 
        readflag = 0;
214
 
 
215
 
        count = 0;
216
 
        y = starty;
217
 
 
218
 
        for (ctry = sizey; ctry >= 0; ctry--)
219
 
        {
220
 
                x = startx;
221
 
 
222
 
                for (ctrx = sizex; ctrx >= 0; ctrx--)
223
 
                {
224
 
                        gfxaddr = (state->m_gfxrom << 16) + ((state->m_blitter_src_addr + count));
225
 
 
226
 
                        if ((gfxaddr > (gfxlen - 1)))
227
 
                        {
228
 
#ifdef MAME_DEBUG
229
 
                                popmessage("GFXROM ADDRESS OVER!!");
230
 
#endif
231
 
                                gfxaddr = 0;
232
 
                        }
233
 
 
234
 
                        color = GFX[gfxaddr];
235
 
 
236
 
                        dx = x & 0xff;
237
 
                        dy = y & 0xff;
238
 
 
239
 
                        if (state->m_flipscreen)
240
 
                        {
241
 
                                dx ^= 0xff;
242
 
                                dy ^= 0xff;
243
 
                        }
244
 
 
245
 
                        if (!readflag)
246
 
                        {
247
 
                                // 1st, 3rd, 5th, ... read
248
 
                                color = (color & 0x0f);
249
 
                        }
250
 
                        else
251
 
                        {
252
 
                                // 2nd, 4th, 6th, ... read
253
 
                                color = (color & 0xf0) >> 4;
254
 
                                count++;
255
 
                        }
256
 
 
257
 
                        readflag ^= 1;
258
 
 
259
 
                        if (state->m_clut[color] & 0xf0)
260
 
                        {
261
 
                                if (color)
262
 
                                {
263
 
                                        color = ((state->m_palbank * 0x10) + color);
264
 
                                        state->m_videoram[(dy * width) + dx] = color;
265
 
                                }
266
 
                        }
267
 
                        else
268
 
                        {
269
 
                                if(state->m_clut[color] != 0)
270
 
                                {
271
 
                                        color = ((state->m_palbank * 0x10) + state->m_clut[color]);
272
 
                                        state->m_videoram[(dy * width) + dx] = color;
273
 
                                }
274
 
                        }
275
 
 
276
 
                        nb1413m3_busyctr++;
277
 
                        x += incx;
278
 
                }
279
 
 
280
 
                y += incy;
281
 
        }
282
 
 
283
 
        nb1413m3_busyflag = 0;
284
 
        machine.scheduler().timer_set(attotime::from_hz(400000) * nb1413m3_busyctr, FUNC(blitter_timer_callback));
285
 
}
286
 
 
287
 
/******************************************************************************
288
 
 
289
 
 
290
 
******************************************************************************/
291
 
VIDEO_START( pastelg )
292
 
{
293
 
        pastelg_state *state = machine.driver_data<pastelg_state>();
294
 
        int width = machine.primary_screen->width();
295
 
        int height = machine.primary_screen->height();
296
 
 
297
 
        state->m_videoram = auto_alloc_array_clear(machine, UINT8, width * height);
298
 
        state->m_clut = auto_alloc_array(machine, UINT8, 0x10);
299
 
}
300
 
 
301
 
/******************************************************************************
302
 
 
303
 
 
304
 
******************************************************************************/
305
 
SCREEN_UPDATE( pastelg )
306
 
{
307
 
        pastelg_state *state = screen->machine().driver_data<pastelg_state>();
308
 
        if (state->m_dispflag)
309
 
        {
310
 
                int x, y;
311
 
                int width = screen->width();
312
 
                int height = screen->height();
313
 
 
314
 
                for (y = 0; y < height; y++)
315
 
                        for (x = 0; x < width; x++)
316
 
                                *BITMAP_ADDR16(bitmap, y, x) = state->m_videoram[(y * width) + x];
317
 
        }
318
 
        else
319
 
                bitmap_fill(bitmap, cliprect, 0);
320
 
 
321
 
        return 0;
322
 
}