~ubuntu-branches/debian/sid/mame/sid

« back to all changes in this revision

Viewing changes to src/emu/video/msm6255.c

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Emmanuel Kasper, Félix Arreola Rodríguez, Jordi Mallach
  • Date: 2011-05-11 21:06:50 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110511210650-jizvh8a6x117y9hr
Tags: 0.142-1
[ Emmanuel Kasper ]
* New upstream release
* Set NOWERROR=1 to allow compiling with gcc-4.6
* Remove fix_powerpc_build.patch, as upstream has taken it in this release
* Add gnome-video-arcade front end as a suggested package

[ Félix Arreola Rodríguez ]
* Add kfreebsd-build.patch to quilt series, to fix build on kfreebsd

[ Jordi Mallach ]
* Remove unneeded and bogus addition of --with-quilt to the dh invocation.
* Add Cesare Falco (long time Ubuntu maintainer) to Uploaders, and wrap
  them into multiple lines.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**********************************************************************
 
2
 
 
3
    OKI MSM6255 Dot Matrix LCD Controller implementation
 
4
 
 
5
    Copyright MESS Team.
 
6
    Visit http://mamedev.org for licensing and usage restrictions.
 
7
 
 
8
**********************************************************************/
 
9
 
 
10
#include "emu.h"
 
11
#include "msm6255.h"
 
12
#include "machine/devhelpr.h"
 
13
 
 
14
 
 
15
 
 
16
//**************************************************************************
 
17
//  MACROS / CONSTANTS
 
18
//**************************************************************************
 
19
 
 
20
#define LOG 0
 
21
 
 
22
 
 
23
// registers
 
24
enum
 
25
{
 
26
        REGISTER_MOR = 0,
 
27
        REGISTER_PR,
 
28
        REGISTER_HNR,
 
29
        REGISTER_DVR,
 
30
        REGISTER_CPR,
 
31
        REGISTER_SLR,
 
32
        REGISTER_SUR,
 
33
        REGISTER_CLR,
 
34
        REGISTER_CUR
 
35
};
 
36
 
 
37
 
 
38
#define MOR_GRAPHICS            0x01
 
39
#define MOR_4_BIT_PARALLEL      0x02
 
40
#define MOR_2_BIT_PARALLEL      0x04
 
41
#define MOR_DISPLAY_ON          0x08
 
42
#define MOR_CURSOR_BLINK        0x10
 
43
#define MOR_CURSOR_ON           0x20
 
44
#define MOR_BLINK_TIME_16       0x40
 
45
 
 
46
 
 
47
#define PR_HP_4                         0x03
 
48
#define PR_HP_5                         0x04
 
49
#define PR_HP_6                         0x05
 
50
#define PR_HP_7                         0x06
 
51
#define PR_HP_8                         0x07
 
52
#define PR_HP_MASK                      0x07
 
53
#define PR_VP_MASK                      0xf0
 
54
 
 
55
 
 
56
#define HNR_HN_MASK                     0x7f
 
57
 
 
58
 
 
59
#define DVR_DN_MASK                     0x7f
 
60
 
 
61
 
 
62
#define CPR_CPD_MASK            0x0f
 
63
#define CPR_CPU_MASK            0xf0
 
64
 
 
65
 
 
66
 
 
67
//**************************************************************************
 
68
//  GLOBAL VARIABLES
 
69
//**************************************************************************
 
70
 
 
71
// devices
 
72
const device_type MSM6255 = msm6255_device_config::static_alloc_device_config;
 
73
 
 
74
 
 
75
 
 
76
//**************************************************************************
 
77
//  DEVICE CONFIGURATION
 
78
//**************************************************************************
 
79
 
 
80
GENERIC_DEVICE_CONFIG_SETUP(msm6255, "MSM6255")
 
81
 
 
82
 
 
83
//-------------------------------------------------
 
84
//  device_config_complete - perform any
 
85
//  operations now that the configuration is
 
86
//  complete
 
87
//-------------------------------------------------
 
88
 
 
89
void msm6255_device_config::device_config_complete()
 
90
{
 
91
        // inherit a copy of the static data
 
92
        const msm6255_interface *intf = reinterpret_cast<const msm6255_interface *>(static_config());
 
93
        if (intf != NULL)
 
94
        {
 
95
                *static_cast<msm6255_interface *>(this) = *intf;
 
96
 
 
97
                m_char_ram_r = intf->m_char_ram_r;
 
98
        }
 
99
        // or initialize to defaults if none provided
 
100
        else
 
101
        {
 
102
                fatalerror("Interface not specified!");
 
103
        }
 
104
}
 
105
 
 
106
 
 
107
 
 
108
//**************************************************************************
 
109
//  INLINE HELPERS
 
110
//**************************************************************************
 
111
 
 
112
//-------------------------------------------------
 
113
//  read_video_data - read video ROM/RAM
 
114
//-------------------------------------------------
 
115
 
 
116
inline UINT8 msm6255_device::read_video_data(UINT16 ma, UINT8 ra)
 
117
{
 
118
        return m_config.m_char_ram_r(this, ma, ra);
 
119
}
 
120
 
 
121
 
 
122
 
 
123
//**************************************************************************
 
124
//  LIVE DEVICE
 
125
//**************************************************************************
 
126
 
 
127
//-------------------------------------------------
 
128
//  msm6255_device - constructor
 
129
//-------------------------------------------------
 
130
 
 
131
msm6255_device::msm6255_device(running_machine &_machine, const msm6255_device_config &config)
 
132
    : device_t(_machine, config),
 
133
          m_cursor(0),
 
134
      m_config(config)
 
135
{
 
136
}
 
137
 
 
138
 
 
139
//-------------------------------------------------
 
140
//  device_start - device-specific startup
 
141
//-------------------------------------------------
 
142
 
 
143
void msm6255_device::device_start()
 
144
{
 
145
        // find screen
 
146
        m_screen = m_machine.device<screen_device>(m_config.m_screen_tag);
 
147
 
 
148
        // register for state saving
 
149
        save_item(NAME(m_ir));
 
150
        save_item(NAME(m_mor));
 
151
        save_item(NAME(m_pr));
 
152
        save_item(NAME(m_hnr));
 
153
        save_item(NAME(m_dvr));
 
154
        save_item(NAME(m_cpr));
 
155
        save_item(NAME(m_slr));
 
156
        save_item(NAME(m_sur));
 
157
        save_item(NAME(m_clr));
 
158
        save_item(NAME(m_cur));
 
159
        save_item(NAME(m_cursor));
 
160
        save_item(NAME(m_frame));
 
161
}
 
162
 
 
163
 
 
164
//-------------------------------------------------
 
165
//  device_reset - device-specific reset
 
166
//-------------------------------------------------
 
167
 
 
168
void msm6255_device::device_reset()
 
169
{
 
170
        m_frame = 0;
 
171
}
 
172
 
 
173
 
 
174
//-------------------------------------------------
 
175
//  read - register read
 
176
//-------------------------------------------------
 
177
 
 
178
READ8_MEMBER( msm6255_device::read )
 
179
{
 
180
        UINT8 data = 0;
 
181
 
 
182
        if (offset & 0x01)
 
183
        {
 
184
                return m_ir;
 
185
        }
 
186
        else
 
187
        {
 
188
                switch (m_ir)
 
189
                {
 
190
                case REGISTER_MOR:
 
191
                        break; // write-only
 
192
 
 
193
                case REGISTER_PR:
 
194
                        data = m_pr;
 
195
                        break;
 
196
 
 
197
                case REGISTER_HNR:
 
198
                        data = m_hnr;
 
199
                        break;
 
200
 
 
201
                case REGISTER_DVR:
 
202
                        break; // write-only
 
203
 
 
204
                case REGISTER_CPR:
 
205
                        data = m_cpr;
 
206
                        break;
 
207
 
 
208
                case REGISTER_SLR:
 
209
                        data = m_slr;
 
210
                        break;
 
211
 
 
212
                case REGISTER_SUR:
 
213
                        data = m_sur;
 
214
                        break;
 
215
 
 
216
                case REGISTER_CLR:
 
217
                        data = m_clr;
 
218
                        break;
 
219
 
 
220
                case REGISTER_CUR:
 
221
                        data = m_cur;
 
222
                        break;
 
223
                }
 
224
        }
 
225
 
 
226
        return data;
 
227
}
 
228
 
 
229
 
 
230
//-------------------------------------------------
 
231
//  write - register write
 
232
//-------------------------------------------------
 
233
 
 
234
WRITE8_MEMBER( msm6255_device::write )
 
235
{
 
236
        if (offset & 0x01)
 
237
        {
 
238
                m_ir = data & 0x0f;
 
239
        }
 
240
        else
 
241
        {
 
242
                switch (m_ir)
 
243
                {
 
244
                case REGISTER_MOR:
 
245
                        m_mor = data & 0x7f;
 
246
                        break;
 
247
 
 
248
                case REGISTER_PR:
 
249
                        m_pr = data & 0xf7;
 
250
                        break;
 
251
 
 
252
                case REGISTER_HNR:
 
253
                        m_hnr = data & 0x7f;
 
254
                        break;
 
255
 
 
256
                case REGISTER_DVR:
 
257
                        m_dvr = data;
 
258
                        break;
 
259
 
 
260
                case REGISTER_CPR:
 
261
                        m_cpr = data;
 
262
                        break;
 
263
 
 
264
                case REGISTER_SLR:
 
265
                        m_slr = data;
 
266
                        break;
 
267
 
 
268
                case REGISTER_SUR:
 
269
                        m_sur = data;
 
270
                        break;
 
271
 
 
272
                case REGISTER_CLR:
 
273
                        m_clr = data;
 
274
                        break;
 
275
 
 
276
                case REGISTER_CUR:
 
277
                        m_cur = data;
 
278
                        break;
 
279
                }
 
280
        }
 
281
}
 
282
 
 
283
 
 
284
//-------------------------------------------------
 
285
//  update_cursor -
 
286
//-------------------------------------------------
 
287
 
 
288
void msm6255_device::update_cursor()
 
289
{
 
290
        if (m_mor & MOR_CURSOR_ON)
 
291
        {
 
292
                if (m_mor & MOR_CURSOR_BLINK)
 
293
                {
 
294
                        if (m_mor & MOR_BLINK_TIME_16)
 
295
                        {
 
296
                                if (m_frame == 16)
 
297
                                {
 
298
                                        m_cursor = !m_cursor;
 
299
                                        m_frame = 0;
 
300
                                }
 
301
                                else
 
302
                                {
 
303
                                        m_frame++;
 
304
                                }
 
305
                        }
 
306
                        else
 
307
                        {
 
308
                                if (m_frame == 32)
 
309
                                {
 
310
                                        m_cursor = !m_cursor;
 
311
                                        m_frame = 0;
 
312
                                }
 
313
                                else
 
314
                                {
 
315
                                        m_frame++;
 
316
                                }
 
317
                        }
 
318
                }
 
319
                else
 
320
                {
 
321
                        m_cursor = 1;
 
322
                }
 
323
        }
 
324
        else
 
325
        {
 
326
                m_cursor = 0;
 
327
        }
 
328
}
 
329
 
 
330
 
 
331
//-------------------------------------------------
 
332
//  draw_scanline -
 
333
//-------------------------------------------------
 
334
 
 
335
void msm6255_device::draw_scanline(bitmap_t *bitmap, const rectangle *cliprect, int y, UINT16 ma, UINT8 ra)
 
336
{
 
337
        UINT8 hp = (m_pr & PR_HP_MASK) + 1;
 
338
        UINT8 hn = (m_hnr & HNR_HN_MASK) + 1;
 
339
        UINT8 cpu = m_cpr & CPR_CPU_MASK;
 
340
        UINT8 cpd = m_cpr & CPR_CPD_MASK;
 
341
        UINT16 car = (m_cur << 8) | m_clr;
 
342
 
 
343
        int sx, x;
 
344
 
 
345
        for (sx = 0; sx < hn; sx++)
 
346
        {
 
347
                UINT8 data = read_video_data(ma, ra);
 
348
 
 
349
                if (m_cursor)
 
350
                {
 
351
                        if (ma == car)
 
352
                        {
 
353
                                if (ra >= cpu && ra <= cpd)
 
354
                                {
 
355
                                        data ^= 0xff;
 
356
                                }
 
357
                        }
 
358
                }
 
359
 
 
360
                for (x = 0; x < hp; x++)
 
361
                {
 
362
                        *BITMAP_ADDR16(bitmap, y, (sx * hp) + x) = BIT(data, 7);
 
363
 
 
364
                        data <<= 1;
 
365
                }
 
366
 
 
367
                ma++;
 
368
        }
 
369
}
 
370
 
 
371
 
 
372
//-------------------------------------------------
 
373
//  update_graphics -
 
374
//-------------------------------------------------
 
375
 
 
376
void msm6255_device::update_graphics(bitmap_t *bitmap, const rectangle *cliprect)
 
377
{
 
378
        UINT8 hn = (m_hnr & HNR_HN_MASK) + 1;
 
379
        UINT8 nx = (m_dvr & DVR_DN_MASK) + 1;
 
380
        UINT16 sar = (m_sur << 8) | m_slr;
 
381
 
 
382
        int y;
 
383
 
 
384
        m_cursor = 0;
 
385
        m_frame = 0;
 
386
 
 
387
        for (y = 0; y < nx; y++)
 
388
        {
 
389
                // draw upper half scanline
 
390
                UINT16 ma = sar + (y * hn);
 
391
                draw_scanline(bitmap, cliprect, y, ma, 0);
 
392
 
 
393
                // draw lower half scanline
 
394
                ma = sar + ((y + nx) * hn);
 
395
                draw_scanline(bitmap, cliprect, y + nx, ma, 0);
 
396
        }
 
397
}
 
398
 
 
399
 
 
400
//-------------------------------------------------
 
401
//  update_text -
 
402
//-------------------------------------------------
 
403
 
 
404
void msm6255_device::update_text(bitmap_t *bitmap, const rectangle *cliprect)
 
405
{
 
406
        UINT8 hn = (m_hnr & HNR_HN_MASK) + 1;
 
407
        UINT8 vp = (m_pr & PR_VP_MASK) + 1;
 
408
        UINT8 nx = (m_dvr & DVR_DN_MASK) + 1;
 
409
        UINT16 sar = (m_sur << 8) | m_slr;
 
410
 
 
411
        int sy, y;
 
412
 
 
413
        update_cursor();
 
414
 
 
415
        for (sy = 0; sy < nx; sy++)
 
416
        {
 
417
                for (y = 0; y < vp; y++)
 
418
                {
 
419
                        // draw upper half scanline
 
420
                        UINT16 ma = sar + ((sy * vp) + y) * hn;
 
421
                        draw_scanline(bitmap, cliprect, (sy * vp) + y, ma, y);
 
422
 
 
423
                        // draw lower half scanline
 
424
                        ma = sar + (((sy + nx) * vp) + y) * hn;
 
425
                        draw_scanline(bitmap, cliprect, (sy * vp) + y, ma, y);
 
426
                }
 
427
        }
 
428
}
 
429
 
 
430
 
 
431
//-------------------------------------------------
 
432
//  update_screen - update screen
 
433
//-------------------------------------------------
 
434
 
 
435
void msm6255_device::update_screen(bitmap_t *bitmap, const rectangle *cliprect)
 
436
{
 
437
        if (m_mor & MOR_DISPLAY_ON)
 
438
        {
 
439
                if (m_mor & MOR_GRAPHICS)
 
440
                {
 
441
                        update_graphics(bitmap, cliprect);
 
442
                }
 
443
                else
 
444
                {
 
445
                        update_text(bitmap, cliprect);
 
446
                }
 
447
        }
 
448
        else
 
449
        {
 
450
                bitmap_fill(bitmap, cliprect, get_black_pen(m_machine));
 
451
        }
 
452
}