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

« back to all changes in this revision

Viewing changes to mess/src/mess/video/kc.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
 
  kc.c
4
 
 
5
 
  Functions to emulate the video hardware of the kc85/4,kc85/3
6
 
 
7
 
***************************************************************************/
8
 
 
9
 
#include "emu.h"
10
 
#include "includes/kc.h"
11
 
#include "machine/ram.h"
12
 
 
13
 
/* KC85/4 and KC85/3 common graphics hardware */
14
 
 
15
 
static const unsigned short kc85_colour_table[KC85_PALETTE_SIZE] =
16
 
{
17
 
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
18
 
        16, 17, 18, 19, 20, 21, 22, 23
19
 
};
20
 
 
21
 
/*
22
 
    foreground:
23
 
 
24
 
        "full" of each component
25
 
 
26
 
        black,
27
 
        blue,
28
 
        red,
29
 
        magenta,
30
 
        green,
31
 
        cyan
32
 
        yellow
33
 
        white
34
 
 
35
 
        "full of each component + half of another component"
36
 
        black
37
 
        violet
38
 
        red/purple
39
 
        pastel green
40
 
        sky blue
41
 
        yellow/green
42
 
        white
43
 
 
44
 
    background:
45
 
        "half" of each component
46
 
        black
47
 
        dark blue
48
 
        dark red
49
 
        dark magenta
50
 
        dark green
51
 
        dark cyan
52
 
        dark yellow
53
 
        dark white (grey)
54
 
 
55
 
 */
56
 
 
57
 
 
58
 
static const unsigned char kc85_palette[KC85_PALETTE_SIZE * 3] =
59
 
{
60
 
                /* 3 bit colour value. bit 2->green, bit 1->red, bit 0->blue */
61
 
 
62
 
                /* foreground colours */
63
 
                0x00, 0x00, 0x00,
64
 
                0x00, 0x00, 0xd0,
65
 
                0xd0, 0x00, 0x00,
66
 
                0xd0, 0x00, 0xd0,
67
 
                0x00, 0xd0, 0x00,
68
 
                0x00, 0xd0, 0xd0,
69
 
                0xd0, 0xd0, 0x00,
70
 
                0xd0, 0xd0, 0xd0,
71
 
 
72
 
                0x00, 0x00, 0x00,
73
 
                0x60, 0x00, 0xa0,
74
 
                0xa0, 0x60, 0x00,
75
 
                0xa0, 0x00, 0x60,
76
 
                0x00, 0xa0, 0x60,
77
 
                0x00, 0x60, 0xa0,
78
 
                0xa0, 0xa0, 0x60,
79
 
                0xd0, 0xd0, 0xd0,
80
 
 
81
 
                /* background colours are slightly darker than foreground colours */
82
 
                0x00, 0x00, 0x00,
83
 
                0x00, 0x00, 0xa0,
84
 
                0xa0, 0x00, 0x00,
85
 
                0xa0, 0x00, 0xa0,
86
 
                0x00, 0xa0, 0x00,
87
 
                0x00, 0xa0, 0xa0,
88
 
                0xa0, 0xa0, 0x00,
89
 
                0xa0, 0xa0, 0xa0
90
 
 
91
 
};
92
 
 
93
 
 
94
 
/* Initialise the palette */
95
 
PALETTE_INIT( kc85 )
96
 
{
97
 
        int i;
98
 
 
99
 
        for ( i = 0; i < sizeof(kc85_palette) / 3; i++ ) {
100
 
                palette_set_color_rgb(machine, i, kc85_palette[i*3], kc85_palette[i*3+1], kc85_palette[i*3+2]);
101
 
        }
102
 
}
103
 
 
104
 
 
105
 
enum
106
 
{
107
 
        KC85_VIDEO_EVENT_SET_BLINK_STATE
108
 
};
109
 
 
110
 
/* set new blink state - record blink state in event list */
111
 
void kc85_video_set_blink_state(running_machine &machine, int data)
112
 
{
113
 
        //spectrum_EventList_AddItemOffset(machine, KC85_VIDEO_EVENT_SET_BLINK_STATE, ((data & 0x01)<<7), machine.firstcpu->attotime_to_cycles(machine.primary_screen->scan_period() * machine.primary_screen->vpos()));
114
 
}
115
 
 
116
 
 
117
 
/* draw 8 pixels */
118
 
static void kc85_draw_8_pixels(kc_state *state, bitmap_t *bitmap,int x,int y, unsigned char colour_byte, unsigned char gfx_byte)
119
 
{
120
 
        int a;
121
 
        int background_pen;
122
 
        int foreground_pen;
123
 
        int pens[2];
124
 
        int px;
125
 
 
126
 
        /* 16 foreground colours, 8 background colours */
127
 
 
128
 
        /* bit 7 = 1: flash between foreground and background colour 0: no flash */
129
 
        /* bit 6: adjusts foreground colours by adding half of another component */
130
 
        /* bit 5,4,3 = foreground colour */
131
 
                /* bit 5: background colour -> Green */
132
 
                /* bit 4: background colour -> Red */
133
 
                /* bit 3: background colour -> Blue */
134
 
        /* bit 2,1,0 = background colour */
135
 
                /* bit 2: background colour -> Green */
136
 
                /* bit 1: background colour -> Red */
137
 
                /* bit 0: background colour -> Blue */
138
 
        background_pen = (colour_byte&7) + 16;
139
 
        foreground_pen = ((colour_byte>>3) & 0x0f);
140
 
 
141
 
        if (colour_byte & state->m_kc85_blink_state)
142
 
        {
143
 
                foreground_pen = background_pen;
144
 
        }
145
 
 
146
 
        pens[0] = background_pen;
147
 
        pens[1] = foreground_pen;
148
 
 
149
 
        px = x;
150
 
 
151
 
        for (a=0; a<8; a++)
152
 
        {
153
 
                int pen;
154
 
 
155
 
                pen = pens[(gfx_byte>>7) & 0x01];
156
 
 
157
 
                if ((px >= 0) && (px < bitmap->width)
158
 
                        && (y >= 0) && (y < bitmap->height))
159
 
                {
160
 
                        *BITMAP_ADDR16(bitmap, y, px) = pen;
161
 
                }
162
 
                px++;
163
 
                gfx_byte = gfx_byte<<1;
164
 
        }
165
 
}
166
 
 
167
 
 
168
 
/* height of screen in lines */
169
 
#define KC85_SCREEN_HEIGHT 256
170
 
/* width of display in pixels */
171
 
#define KC85_SCREEN_WIDTH 320
172
 
/* height of top border in lines */
173
 
#define KC85_TOP_BORDER_SIZE 8
174
 
/* height of bottom border in lines */
175
 
#define KC85_BOTTOM_BORDER_SIZE 8
176
 
/* total number of lines in whole frame */
177
 
#define KC85_FRAME_NUM_LINES 312
178
 
/* width of whole line in pixels */
179
 
#define KC85_LINE_SIZE 512
180
 
/* width of left border in pixels */
181
 
#define KC85_LEFT_BORDER_SIZE 8
182
 
/* width of right border in pixels */
183
 
#define KC85_RIGHT_BORDER_SIZE 8
184
 
/* width of horizontal retrace in pixels */
185
 
#define KC85_RETRACE_SIZE (KC85_LINE_SIZE - KC85_LEFT_BORDER_SIZE - KC85_RIGHT_BORDER_SIZE - KC85_SCREEN_WIDTH)
186
 
/* number of lines in vertical retrace */
187
 
#define KC85_NUM_RETRACE_LINES (KC85_FRAME_NUM_LINES - KC85_TOP_BORDER_SIZE - KC85_BOTTOM_BORDER_SIZE - KC85_SCREEN_HEIGHT)
188
 
 
189
 
 
190
 
#define KC85_CYCLES_PER_FRAME 1750000.0f/50.0f
191
 
#define KC85_CYCLES_PER_LINE (KC85_CYCLES_PER_FRAME/KC85_FRAME_NUM_LINES)
192
 
#define KC85_CYCLES_PER_PIXEL (KC85_CYCLES_PER_LINE/KC85_LINE_SIZE)
193
 
 
194
 
/*
195
 
 
196
 
    - 1750000 cpu cycles per second
197
 
    - 35000 cpu cycles per frame
198
 
    - 35000/312 = 112.179 cycles per line
199
 
    - 112.179/(512/8) = 1.752 cycles per 8-pixels
200
 
*/
201
 
 
202
 
/* Operation:
203
 
 
204
 
    - Vertical and horizontal dimensions are split into states.
205
 
    - Horizontal states take a multiple of horizontal cycles, and vertical states take a multiple of lines.
206
 
    - The horizontal states comprise left border, main display, right border and horizontal retrace timing.
207
 
    - The vertical states comprise top border, main display, bottom border and vertical retrace timing.
208
 
 
209
 
 
210
 
    - if frame rate is 50Hz, and there are 312 lines, then the line rate is 15600Hz.
211
 
    - Each frame takes 0.02 seconds, and each line takes 0.0000064 seconds - approx 64microseconds per line
212
 
 
213
 
    - the event list is based on cpu time
214
 
 
215
 
*/
216
 
 
217
 
static const int horizontal_next_state_table[]=
218
 
{
219
 
        1,2,3,0
220
 
};
221
 
 
222
 
/* number of cycles for each state */
223
 
static const int horizontal_graphics_state_cycles[]=
224
 
{
225
 
        /* left border */
226
 
        (KC85_LEFT_BORDER_SIZE*KC85_CYCLES_PER_PIXEL),
227
 
        /* main display */
228
 
        (KC85_SCREEN_WIDTH*KC85_CYCLES_PER_PIXEL),
229
 
        /* right border */
230
 
        (KC85_RIGHT_BORDER_SIZE*KC85_CYCLES_PER_PIXEL),
231
 
        /* horizontal retrace */
232
 
        (KC85_RETRACE_SIZE*KC85_CYCLES_PER_PIXEL)
233
 
};
234
 
 
235
 
static const int vertical_next_state_table[]=
236
 
{
237
 
        1,2,3,0
238
 
};
239
 
 
240
 
/* number of lines for each state */
241
 
static const int vertical_graphics_state_lines[]=
242
 
{
243
 
        /* top border */
244
 
        KC85_TOP_BORDER_SIZE*KC85_CYCLES_PER_LINE,
245
 
        /* main display */
246
 
        KC85_SCREEN_HEIGHT*KC85_CYCLES_PER_LINE,
247
 
        /* bottom display */
248
 
        KC85_BOTTOM_BORDER_SIZE*KC85_CYCLES_PER_LINE,
249
 
        /* vertical retrace */
250
 
        KC85_NUM_RETRACE_LINES*KC85_CYCLES_PER_LINE
251
 
};
252
 
 
253
 
struct video_state
254
 
{
255
 
        /* current state */
256
 
        int state;
257
 
        /* number of cycles remaining in this state */
258
 
        int cycles_remaining_in_state;
259
 
        /* number of cycles remaining (starts at total of all states) */
260
 
        int cycles_remaining;
261
 
};
262
 
 
263
 
struct grab_info
264
 
{
265
 
        unsigned char *pixel_ram;
266
 
        unsigned char *colour_ram;
267
 
};
268
 
 
269
 
struct video_update_state
270
 
{
271
 
        /* bitmap to render to */
272
 
        bitmap_t *bitmap;
273
 
        /* grab colour and pixel information for 8-pixels referenced by x,y coordinate */
274
 
        void (*pixel_grab_callback)(struct grab_info *,int x,int y, unsigned char *colour_ptr, unsigned char *pixel_ptr);
275
 
        /* current coords */
276
 
        int x,y;
277
 
        /* render coordinates */
278
 
        int render_x,render_y;
279
 
 
280
 
        struct video_state horizontal;
281
 
        struct video_state vertical;
282
 
        struct grab_info grab_data;
283
 
};
284
 
 
285
 
 
286
 
/* process visible cycles within a line */
287
 
/* the cycles will never span over the end of a line */
288
 
static void kc85_common_process_cycles(kc_state *state, struct video_update_state *video_update, int cycles)
289
 
{
290
 
        while (cycles!=0)
291
 
        {
292
 
                int cycles_to_do;
293
 
 
294
 
                /* do as many cycles up to end of current state */
295
 
                cycles_to_do = MIN(video_update->horizontal.cycles_remaining_in_state, cycles);
296
 
 
297
 
                //logerror("process cycles: cycles_to_do %d\n",cycles_to_do);
298
 
 
299
 
                /* update screen based on current state */
300
 
                switch (video_update->horizontal.state)
301
 
                {
302
 
                        /* border */
303
 
                        case 0:
304
 
                        {
305
 
                        //  video_update->render_x+=(cycles_to_do)*8;
306
 
                        }
307
 
                        break;
308
 
 
309
 
                        /* pixels */
310
 
                        case 1:
311
 
                        {
312
 
                                int i;
313
 
 
314
 
                                for (i=0; i<cycles_to_do; i++)
315
 
                                {
316
 
                                        unsigned char colour_byte;
317
 
                                        unsigned char gfx_byte;
318
 
 
319
 
                                        /* grab colour and pixel information */
320
 
                                        video_update->pixel_grab_callback(&video_update->grab_data,video_update->x,video_update->y,&colour_byte, &gfx_byte);
321
 
                                        /* draw to screen */
322
 
                                        kc85_draw_8_pixels(state, video_update->bitmap, video_update->render_x, video_update->render_y,colour_byte, gfx_byte);
323
 
                                        /* update render coordinate */
324
 
                                        video_update->render_x+=8;
325
 
                                        video_update->x++;
326
 
 
327
 
                                        if (video_update->x>=(320/8))
328
 
                                        {
329
 
                                                video_update->x = (320/8)-1;
330
 
                                        }
331
 
 
332
 
                                        if (video_update->render_x>=320)
333
 
                                        {
334
 
                                                video_update->render_x = 319;
335
 
                                        }
336
 
 
337
 
 
338
 
                                }
339
 
                        }
340
 
                        break;
341
 
 
342
 
                        /* border */
343
 
                        case 2:
344
 
                        {
345
 
                        //  video_update->render_x+=(cycles_to_do)*8;
346
 
                        }
347
 
                        break;
348
 
 
349
 
                        /* invisible/retrace */
350
 
                        case 3:
351
 
                        {
352
 
 
353
 
 
354
 
                        }
355
 
                        break;
356
 
                }
357
 
 
358
 
                video_update->horizontal.cycles_remaining_in_state -=cycles_to_do;
359
 
 
360
 
                /* is state over? */
361
 
                if (video_update->horizontal.cycles_remaining_in_state<=0)
362
 
                {
363
 
                        /* update state */
364
 
                        video_update->horizontal.state = horizontal_next_state_table[video_update->horizontal.state];
365
 
                        video_update->horizontal.cycles_remaining_in_state+=horizontal_graphics_state_cycles[video_update->horizontal.state];
366
 
                }
367
 
 
368
 
                cycles-=cycles_to_do;
369
 
        }
370
 
}
371
 
 
372
 
/* process a whole visible line */
373
 
static int kc85_common_vh_process_line(kc_state *state, struct video_update_state *video_update, int cycles)
374
 
{
375
 
        int cycles_to_do;
376
 
 
377
 
        /* do cycles in line */
378
 
        while ((video_update->horizontal.cycles_remaining!=0) && (cycles!=0))
379
 
        {
380
 
                /* do as many cycles as will fit onto the line */
381
 
                cycles_to_do = MIN(cycles,video_update->horizontal.cycles_remaining);
382
 
 
383
 
                //logerror("process line: cycles_to_do: %d\n",cycles_to_do);
384
 
 
385
 
                /* do the cycles - draw them */
386
 
                kc85_common_process_cycles(state, video_update, cycles_to_do);
387
 
 
388
 
                video_update->horizontal.cycles_remaining -= cycles_to_do;
389
 
                cycles -=cycles_to_do;
390
 
        }
391
 
 
392
 
        /* line over */
393
 
 
394
 
        if (video_update->horizontal.cycles_remaining==0)
395
 
        {
396
 
                /* reset */
397
 
                video_update->horizontal.cycles_remaining+=KC85_CYCLES_PER_LINE;
398
 
                /* update x,y fetch pos */
399
 
                video_update->x = 0;
400
 
                video_update->y++;
401
 
 
402
 
                /* update x,y render pos */
403
 
                video_update->render_x = 0;
404
 
                video_update->render_y++;
405
 
 
406
 
                if (video_update->y>=256)
407
 
                {
408
 
                        video_update->y = 255;
409
 
                }
410
 
 
411
 
                if (video_update->render_y>=256)
412
 
                {
413
 
                        video_update->render_y = 255;
414
 
                }
415
 
 
416
 
 
417
 
        }
418
 
 
419
 
        /* cycles remaining */
420
 
        return cycles;
421
 
}
422
 
 
423
 
static void kc85_common_vh_process_lines(kc_state *state, struct video_update_state *video_update, int cycles)
424
 
{
425
 
        while (cycles!=0)
426
 
        {
427
 
                int cycles_to_do;
428
 
                int cycles_done;
429
 
 
430
 
                cycles_to_do = MIN(cycles, KC85_CYCLES_PER_LINE);
431
 
                cycles_done = cycles_to_do;
432
 
 
433
 
                //logerror("process lines: cycles_to_do: %d\n",cycles_to_do);
434
 
 
435
 
 
436
 
                switch (video_update->vertical.state)
437
 
                {
438
 
                        /* border */
439
 
                        case 0:
440
 
                        {
441
 
        //          cycles_done = cycles_to_do;
442
 
                        }
443
 
                        break;
444
 
 
445
 
                        /* graphics */
446
 
                        case 1:
447
 
                        {
448
 
                                int cycles_remaining;
449
 
 
450
 
                                /* update cycles with number of cycles not processed */
451
 
                                cycles_remaining = kc85_common_vh_process_line(state, video_update, cycles_to_do);
452
 
 
453
 
                                cycles_done = cycles_to_do - cycles_remaining;
454
 
 
455
 
                        }
456
 
                        break;
457
 
 
458
 
                        /* border */
459
 
                        case 2:
460
 
                        {
461
 
        //          cycles_done = cycles_to_do;
462
 
                        }
463
 
                        break;
464
 
 
465
 
                        /* not visible */
466
 
                        case 3:
467
 
                        {
468
 
        //          cycles_done = cycles_to_do;
469
 
                        }
470
 
                        break;
471
 
                }
472
 
 
473
 
 
474
 
                //logerror("cycles done: %d\n",cycles_done);
475
 
                video_update->vertical.cycles_remaining_in_state -=cycles_done;
476
 
 
477
 
                /* is state over? */
478
 
                if (video_update->vertical.cycles_remaining_in_state<=0)
479
 
                {
480
 
                        /* update state */
481
 
                        video_update->vertical.state = vertical_next_state_table[video_update->vertical.state];
482
 
                        video_update->vertical.cycles_remaining_in_state+=vertical_graphics_state_lines[video_update->vertical.state];
483
 
                }
484
 
                cycles-=cycles_done;
485
 
        }
486
 
}
487
 
 
488
 
 
489
 
 
490
 
/* the kc85 screen is 320 pixels wide and 256 pixels tall */
491
 
/* if we assume a 50Hz display, there are 312 lines for the complete frame, leaving 56 lines not visible */
492
 
static void kc85_common_process_frame(running_machine &machine, bitmap_t *bitmap, void (*pixel_grab_callback)(struct grab_info *,int x,int y,unsigned char *, unsigned char *),struct grab_info *grab_data)
493
 
{
494
 
        kc_state *state = machine.driver_data<kc_state>();
495
 
        int cycles_remaining_in_frame = KC85_CYCLES_PER_FRAME;
496
 
 
497
 
//  EVENT_LIST_ITEM *pItem;
498
 
//    int NumItems;
499
 
 
500
 
        struct video_update_state video_update;
501
 
//  int cycles_offset = 0;
502
 
 
503
 
        video_update.render_x = 0;
504
 
        video_update.render_y = 0;
505
 
        video_update.x = 0;
506
 
        video_update.y = 0;
507
 
        memcpy(&video_update.grab_data, grab_data, sizeof(struct grab_info));
508
 
        video_update.bitmap = bitmap;
509
 
        video_update.pixel_grab_callback = pixel_grab_callback;
510
 
        video_update.horizontal.state = 0;
511
 
        video_update.horizontal.cycles_remaining_in_state = horizontal_graphics_state_cycles[video_update.horizontal.state];
512
 
        video_update.horizontal.cycles_remaining = KC85_CYCLES_PER_LINE;
513
 
        video_update.vertical.state = 0;
514
 
        video_update.vertical.cycles_remaining_in_state = vertical_graphics_state_lines[video_update.vertical.state];
515
 
        video_update.vertical.cycles_remaining = KC85_CYCLES_PER_FRAME;
516
 
 
517
 
#if 0
518
 
        /* first item in list */
519
 
        pItem = spectrum_EventList_GetFirstItem(machine);
520
 
        /* number of items remaining */
521
 
        NumItems = spectrum_EventList_NumEvents(machine);
522
 
 
523
 
        while (NumItems)
524
 
        {
525
 
                int delta_cycles;
526
 
 
527
 
                /* number of cycles until event will trigger */
528
 
                delta_cycles = pItem->Event_Time - cycles_offset;
529
 
 
530
 
                //logerror("cycles between this event and next: %d\n",delta_cycles);
531
 
                kc85_common_vh_process_lines(&video_update, delta_cycles);
532
 
 
533
 
                /* update number of cycles remaining in frame */
534
 
                cycles_remaining_in_frame -= delta_cycles;
535
 
                /* set new blink state */
536
 
                state->m_kc85_blink_state = pItem->Event_Data;
537
 
 
538
 
                /* set new cycles into frame */
539
 
                cycles_offset = pItem->Event_Time;
540
 
                /* next event */
541
 
                pItem++;
542
 
                /* update number of events remaining */
543
 
                NumItems--;
544
 
        }
545
 
#endif
546
 
 
547
 
        /* process remainder */
548
 
        kc85_common_vh_process_lines(state, &video_update, cycles_remaining_in_frame);
549
 
        //spectrum_EventList_Reset(machine);
550
 
        //spectrum_EventList_SetOffsetStartTime ( machine, machine.firstcpu->attotime_to_cycles(machine.primary_screen->scan_period() * machine.primary_screen->vpos()) );
551
 
}
552
 
 
553
 
 
554
 
 
555
 
/***************************************************************************
556
 
 KC85/4 video hardware
557
 
***************************************************************************/
558
 
static void kc85_common_vh_start(running_machine &machine)
559
 
{
560
 
        kc_state *state = machine.driver_data<kc_state>();
561
 
        state->m_kc85_blink_state = 0;
562
 
        //spectrum_EventList_Initialise(machine, 30000);
563
 
}
564
 
 
565
 
 
566
 
 
567
 
VIDEO_START( kc85_4 )
568
 
{
569
 
        kc_state *state = machine.driver_data<kc_state>();
570
 
        kc85_common_vh_start(machine);
571
 
 
572
 
        state->m_kc85_4_video_ram = auto_alloc_array(machine, UINT8,
573
 
                (KC85_4_SCREEN_COLOUR_RAM_SIZE*2) +
574
 
                (KC85_4_SCREEN_PIXEL_RAM_SIZE*2));
575
 
 
576
 
        state->m_kc85_4_display_video_ram = state->m_kc85_4_video_ram;
577
 
}
578
 
 
579
 
void kc85_4_video_ram_select_bank(running_machine &machine, int bank)
580
 
{
581
 
        kc_state *state = machine.driver_data<kc_state>();
582
 
        /* calculate address of video ram to display */
583
 
        unsigned char *video_ram;
584
 
 
585
 
        video_ram = state->m_kc85_4_video_ram;
586
 
 
587
 
        if (bank!=0)
588
 
        {
589
 
                video_ram +=
590
 
                                   (KC85_4_SCREEN_PIXEL_RAM_SIZE +
591
 
                                   KC85_4_SCREEN_COLOUR_RAM_SIZE);
592
 
        }
593
 
 
594
 
        state->m_kc85_4_display_video_ram = video_ram;
595
 
}
596
 
 
597
 
unsigned char *kc85_4_get_video_ram_base(running_machine &machine, int bank, int colour)
598
 
{
599
 
        kc_state *state = machine.driver_data<kc_state>();
600
 
        /* base address: screen 0 pixel data */
601
 
        unsigned char *addr = state->m_kc85_4_video_ram;
602
 
 
603
 
        if (bank!=0)
604
 
        {
605
 
                /* access screen 1 */
606
 
                addr += KC85_4_SCREEN_PIXEL_RAM_SIZE +
607
 
                                KC85_4_SCREEN_COLOUR_RAM_SIZE;
608
 
        }
609
 
 
610
 
        if (colour!=0)
611
 
        {
612
 
                /* access colour information of selected screen */
613
 
                addr += KC85_4_SCREEN_PIXEL_RAM_SIZE;
614
 
        }
615
 
 
616
 
        return addr;
617
 
}
618
 
 
619
 
static void kc85_4_pixel_grab_callback(struct grab_info *grab_data,int x,int y, unsigned char *colour, unsigned char *gfx)
620
 
{
621
 
        int offset;
622
 
 
623
 
        offset = (y & 0xff) | ((x & 0x0ff)<<8);
624
 
 
625
 
        *colour = grab_data->colour_ram[offset];
626
 
        *gfx = grab_data->pixel_ram[offset];
627
 
 
628
 
}
629
 
 
630
 
 
631
 
/***************************************************************************
632
 
  Draw the game screen in the given bitmap_t.
633
 
  Do NOT call osd_update_display() from this function,
634
 
  it will be called by the main emulation engine.
635
 
***************************************************************************/
636
 
SCREEN_UPDATE( kc85_4 )
637
 
{
638
 
        kc_state *state = screen->machine().driver_data<kc_state>();
639
 
#if 0
640
 
        unsigned char *pixel_ram = state->m_kc85_4_display_video_ram;
641
 
        unsigned char *colour_ram = pixel_ram + 0x04000;
642
 
 
643
 
        int x,y;
644
 
 
645
 
        for (y=0; y<KC85_SCREEN_HEIGHT; y++)
646
 
        {
647
 
                for (x=0; x<(KC85_SCREEN_WIDTH>>3); x++)
648
 
                {
649
 
                        unsigned char colour_byte, gfx_byte;
650
 
                        int offset;
651
 
 
652
 
                        offset = y | (x<<8);
653
 
 
654
 
                        colour_byte = colour_ram[offset];
655
 
                        gfx_byte = pixel_ram[offset];
656
 
 
657
 
                        kc85_draw_8_pixels(state, bitmap,(x<<3),y, colour_byte, gfx_byte);
658
 
 
659
 
                }
660
 
        }
661
 
#endif
662
 
        struct grab_info grab_data;
663
 
 
664
 
        grab_data.pixel_ram = state->m_kc85_4_display_video_ram;
665
 
        grab_data.colour_ram = state->m_kc85_4_display_video_ram + 0x04000;
666
 
 
667
 
        kc85_common_process_frame(screen->machine(), bitmap, kc85_4_pixel_grab_callback,&grab_data);
668
 
 
669
 
        return 0;
670
 
}
671
 
 
672
 
/***************************************************************************
673
 
 KC85/3 video
674
 
***************************************************************************/
675
 
 
676
 
VIDEO_START( kc85_3 )
677
 
{
678
 
        kc85_common_vh_start(machine);
679
 
}
680
 
 
681
 
 
682
 
static void kc85_3_pixel_grab_callback(struct grab_info *grab_data,int x,int y, unsigned char *colour, unsigned char *gfx)
683
 
{
684
 
        int pixel_offset,colour_offset;
685
 
 
686
 
        /* this has got to be speeded up!!! */
687
 
        if ((x & 0x020)==0)
688
 
        {
689
 
                pixel_offset = (x & 0x01f) | (((y>>2) & 0x03)<<5) |
690
 
                ((y & 0x03)<<7) | (((y>>4) & 0x0f)<<9);
691
 
 
692
 
                colour_offset = (x & 0x01f) | (((y>>2) & 0x03f)<<5);
693
 
        }
694
 
        else
695
 
        {
696
 
                /* 1  0  1  0  0  V7 V6 V1  V0 V3 V2 V5 V4 H2 H1 H0 */
697
 
                /* 1  0  1  1  0  0  0  V7  V6 V3 V2 V5 V4 H2 H1 H0 */
698
 
 
699
 
                pixel_offset = 0x02000+((x & 0x07) | (((y>>4) & 0x03)<<3) |
700
 
                        (((y>>2) & 0x03)<<5) | ((y & 0x03)<<7) | ((y>>6) & 0x03)<<9);
701
 
 
702
 
                colour_offset = 0x0800+((x & 0x07) | (((y>>4) & 0x03)<<3) |
703
 
                        (((y>>2) & 0x03)<<5) | ((y>>6) & 0x03)<<7);
704
 
        }
705
 
 
706
 
        *colour = grab_data->colour_ram[colour_offset];
707
 
        *gfx = grab_data->pixel_ram[pixel_offset];
708
 
 
709
 
}
710
 
 
711
 
/***************************************************************************
712
 
  Draw the game screen in the given bitmap_t.
713
 
  Do NOT call osd_update_display() from this function,
714
 
  it will be called by the main emulation engine.
715
 
***************************************************************************/
716
 
SCREEN_UPDATE( kc85_3 )
717
 
{
718
 
#if 0
719
 
        /* colour ram takes up 0x02800 bytes */
720
 
           unsigned char *pixel_ram = ram_get_ptr(machine.device(RAM_TAG))+0x08000;
721
 
        unsigned char *colour_ram = pixel_ram + 0x02800;
722
 
 
723
 
        int x,y;
724
 
 
725
 
        for (y=0; y<KC85_SCREEN_HEIGHT; y++)
726
 
        {
727
 
                for (x=0; x<(KC85_SCREEN_WIDTH>>3); x++)
728
 
                {
729
 
                        unsigned char colour_byte, gfx_byte;
730
 
                        int pixel_offset,colour_offset;
731
 
 
732
 
                        if ((x & 0x020)==0)
733
 
                        {
734
 
                                pixel_offset = (x & 0x01f) | (((y>>2) & 0x03)<<5) |
735
 
                                ((y & 0x03)<<7) | (((y>>4) & 0x0f)<<9);
736
 
 
737
 
                                colour_offset = (x & 0x01f) | (((y>>2) & 0x03f)<<5);
738
 
                        }
739
 
                        else
740
 
                        {
741
 
                                /* 1  0  1  0  0  V7 V6 V1  V0 V3 V2 V5 V4 H2 H1 H0 */
742
 
                                /* 1  0  1  1  0  0  0  V7  V6 V3 V2 V5 V4 H2 H1 H0 */
743
 
 
744
 
                                pixel_offset = 0x02000+((x & 0x07) | (((y>>4) & 0x03)<<3) |
745
 
                                        (((y>>2) & 0x03)<<5) | ((y & 0x03)<<7) | ((y>>6) & 0x03)<<9);
746
 
 
747
 
                                colour_offset = 0x0800+((x & 0x07) | (((y>>4) & 0x03)<<3) |
748
 
                                        (((y>>2) & 0x03)<<5) | ((y>>6) & 0x03)<<7);
749
 
                        }
750
 
 
751
 
                        colour_byte = colour_ram[colour_offset];
752
 
                        gfx_byte = pixel_ram[pixel_offset];
753
 
 
754
 
                        kc85_draw_8_pixels(state, bitmap,(x<<3),y, colour_byte, gfx_byte);
755
 
                }
756
 
        }
757
 
#endif
758
 
 
759
 
        struct grab_info grab_data;
760
 
 
761
 
        grab_data.pixel_ram = ram_get_ptr(screen->machine().device(RAM_TAG))+0x08000;
762
 
        grab_data.colour_ram = ram_get_ptr(screen->machine().device(RAM_TAG))+0x08000 + 0x02800;
763
 
 
764
 
        kc85_common_process_frame(screen->machine(), bitmap, kc85_3_pixel_grab_callback,&grab_data);
765
 
 
766
 
        return 0;
767
 
}