Previous 15994 Revisions Next

r15432 Saturday 9th June, 2012 at 20:59:37 UTC by Sandro Ronco
kc: replaced unused eventlst code with partial updates. (nw)
[src/mess/drivers]kc.c
[src/mess/includes]kc.h
[src/mess/machine]kc.c
[src/mess/video]kc.c

src/mess/machine/kc.c
r15431r15432
350350      /* BASIC takes next priority */
351351           LOG(("BASIC rom 0x0c000\n"));
352352
353        membank("bank4")->set_base(machine().root_device().memregion("basic")->base());
353        membank("bank4")->set_base(memregion("basic")->base());
354354      space->install_read_bank(0xc000, 0xdfff, "bank4");
355355      space->unmap_write(0xc000, 0xdfff);
356356   }
r15431r15432
373373      /* enable CAOS rom in memory range 0x0e000-0x0ffff */
374374      LOG(("CAOS rom 0x0e000\n"));
375375      /* read will access the rom */
376      membank("bank5")->set_base(machine().root_device().memregion("caos")->base() + 0x2000);
376      membank("bank5")->set_base(memregion("caos")->base() + 0x2000);
377377      space->install_read_bank(0xe000, 0xffff, "bank5");
378378      space->unmap_write(0xe000, 0xffff);
379379   }
r15431r15432
397397        /* IRM enabled */
398398        LOG(("IRM enabled\n"));
399399
400      membank("bank3")->set_base(m_ram_base + 0x4000);
400      membank("bank3")->set_base(m_video_ram);
401401      space->install_readwrite_bank(0x8000, 0xbfff, "bank3");
402402    }
403403    else
r15431r15432
462462      /* CAOS rom takes priority */
463463      LOG(("CAOS rom 0x0c000\n"));
464464
465      membank("bank4")->set_base(machine().root_device().memregion("caos")->base());
465      membank("bank4")->set_base(memregion("caos")->base());
466466      space->install_read_bank(0xc000, 0xdfff, "bank4");
467467      space->unmap_write(0xc000, 0xdfff);
468468   }
r15431r15432
475475
476476         int bank = memregion("basic")->bytes() == 0x8000 ? (m_port_86_data>>5) & 0x03 : 0;
477477
478         membank("bank4")->set_base(machine().root_device().memregion("basic")->base() + (bank << 13));
478         membank("bank4")->set_base(memregion("basic")->base() + (bank << 13));
479479         space->install_read_bank(0xc000, 0xdfff, "bank4");
480480         space->unmap_write(0xc000, 0xdfff);
481481      }
r15431r15432
498498      /* IRM enabled - has priority over RAM8 enabled */
499499      LOG(("IRM enabled\n"));
500500
501      UINT8* ram_page = (UINT8*)kc85_4_get_video_ram_base(machine(), (m_port_84_data & 0x04), (m_port_84_data & 0x02));
501      UINT8* ram_page = m_video_ram + ((BIT(m_port_84_data, 2)<<15) | (BIT(m_port_84_data, 1)<<14));
502502
503503      membank("bank3")->set_base(ram_page);
504504      space->install_readwrite_bank(0x8000, 0xa7ff, "bank3");
505505
506      ram_page = (UINT8*)kc85_4_get_video_ram_base(machine(), 0, 0);
507
508      membank("bank6")->set_base(ram_page + 0x2800);
506      membank("bank6")->set_base(m_video_ram + 0x2800);
509507      space->install_readwrite_bank(0xa800, 0xbfff, "bank6");
510508   }
511509    else if (m_pio_data[1] & (1<<5))
r15431r15432
645643
646644   m_port_84_data = data;
647645
648   kc85_4_video_ram_select_bank(machine(), data & 0x01);
646   video_control_w(data);
649647
650   m_high_resolution = (data & 0x08) ? 0 : 1;
651
652648   update_0x08000();
653649}
654650
r15431r15432
724720
725721}
726722
727static TIMER_CALLBACK(kc85_15khz_timer_callback )
723TIMER_DEVICE_CALLBACK( kc_scanline )
728724{
729   kc_state *state = machine.driver_data<kc_state>();
725   kc_state *state = timer.machine().driver_data<kc_state>();
726   int scanline = (int)param;
730727
731   /* toggle state of square wave */
732   state->m_kc85_15khz_state^=1;
728   /* set clock input for channel 0 and 1 to ctc */
729   z80ctc_trg0_w(state->m_z80ctc, 1);
730   z80ctc_trg0_w(state->m_z80ctc, 0);
731   z80ctc_trg1_w(state->m_z80ctc, 1);
732   z80ctc_trg1_w(state->m_z80ctc, 0);
733733
734   /* set clock input for channel 2 and 3 to ctc */
735   z80ctc_trg0_w(state->m_z80ctc, state->m_kc85_15khz_state);
736   z80ctc_trg1_w(state->m_z80ctc, state->m_kc85_15khz_state);
737}
738
739static TIMER_CALLBACK(kc85_50hz_timer_callback)
740{
741   kc_state *state = machine.driver_data<kc_state>();
742
743   /* toggle state of square wave */
744   state->m_kc85_50hz_state^=1;
745
746   /* set clock input for channel 2 and 3 to ctc */
747   z80ctc_trg2_w(state->m_z80ctc, state->m_kc85_50hz_state);
748   z80ctc_trg3_w(state->m_z80ctc, state->m_kc85_50hz_state);
749}
750
751/* video blink */
752WRITE_LINE_MEMBER( kc_state::ctc_zc2_callback )
753{
754   /* is blink enabled? */
755   if (m_pio_data[1] & (1<<7))
734   if (scanline == 256)
756735   {
757      /* yes */
758      /* toggle state of blink to video hardware */
759      kc85_video_set_blink_state(machine(), state);
736      /* set clock input for channel 2 and 3 to ctc */
737      z80ctc_trg2_w(state->m_z80ctc, 1);
738      z80ctc_trg2_w(state->m_z80ctc, 0);
739      z80ctc_trg3_w(state->m_z80ctc, 1);
740      z80ctc_trg3_w(state->m_z80ctc, 0);
760741   }
761742}
762743
r15431r15432
781762   m_cassette_timer = machine().scheduler().timer_alloc(FUNC(kc_cassette_timer_callback));
782763   m_cassette_oneshot_timer = machine().scheduler().timer_alloc(FUNC(kc_cassette_oneshot_timer));
783764
784   // kc85 has a 50 Hz input to the ctc channel 2 and 3
785   // channel 2 this controls the video colour flash
786   // kc85 has a 15 kHz (?) input to the ctc channel 0 and 1
787   // channel 0 and channel 1 are used for cassette write
788   machine().scheduler().timer_pulse(attotime::from_hz(50), FUNC(kc85_50hz_timer_callback), 0, NULL);
789   machine().scheduler().timer_pulse(attotime::from_hz(15625), FUNC(kc85_15khz_timer_callback), 0, NULL);
790
791765   m_ram_base = m_ram->pointer();
792766
793767   m_expansions[0] = machine().device<kcexp_slot_device>("m8");
r15431r15432
806780   update_0x0c000();
807781   update_0x0e000();
808782
809   m_kc85_50hz_state = 0;
810   m_kc85_15khz_state = 0;
811
812783   // set low resolution at reset
813784   m_high_resolution = 0;
814785
src/mess/includes/kc.h
r15431r15432
122122
123123   // defined in video/kc.c
124124   virtual void video_start();
125   virtual UINT32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
126   DECLARE_WRITE_LINE_MEMBER( video_toggle_blink_state );
127   void video_draw_8_pixels(bitmap_ind16 &bitmap, int x, int y, UINT8 colour_byte, UINT8 gfx_byte);
125128
126129   // driver state
127130   UINT8 *            m_ram_base;
131   UINT8 *            m_video_ram;
128132   int             m_pio_data[2];
129133   int               m_high_resolution;
130134   UINT8            m_ardy;
131135   UINT8            m_brdy;
132   int             m_kc85_50hz_state;
133   int             m_kc85_15khz_state;
134136   int               m_kc85_blink_state;
135137   int               m_k0_line;
136138   int               m_k1_line;
r15431r15432
167169
168170   // defined in video/kc.c
169171   virtual void video_start();
172   virtual UINT32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
173   void video_control_w(int data);
170174
171175   // driver state
172176   UINT8            m_port_84_data;
173177   UINT8            m_port_86_data;
174   UINT8 *            m_video_ram;
175178   UINT8 *            m_display_video_ram;
176179};
177180
r15431r15432
180183
181184extern PALETTE_INIT( kc85 );
182185
183void kc85_video_set_blink_state(running_machine &machine, int data);
184
185SCREEN_UPDATE_IND16( kc85_3 );
186SCREEN_UPDATE_IND16( kc85_4 );
187
188/* select video ram to display */
189void kc85_4_video_ram_select_bank(running_machine &machine, int bank);
190/* select video ram which is visible in address space */
191unsigned char *kc85_4_get_video_ram_base(running_machine &machine, int bank, int colour);
192
193
194186/*----------- defined in machine/kc.c -----------*/
195187
196188QUICKLOAD_LOAD( kc );
189TIMER_DEVICE_CALLBACK( kc_scanline );
197190
198191#endif /* KC_H_ */
src/mess/video/kc.c
r15431r15432
99#include "emu.h"
1010#include "includes/kc.h"
1111
12/* KC85/4 and KC85/3 common graphics hardware */
13
14static const unsigned short kc85_colour_table[KC85_PALETTE_SIZE] =
12// 3 bit colour value. bit 2->green, bit 1->red, bit 0->blue
13static const UINT8 kc85_palette[KC85_PALETTE_SIZE * 3] =
1514{
16   0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
17   16, 17, 18, 19, 20, 21, 22, 23
18};
15   // foreground colours, "full" of each component
16   0x00, 0x00, 0x00,    // black
17   0x00, 0x00, 0xd0,    // blue
18   0xd0, 0x00, 0x00,    // red
19   0xd0, 0x00, 0xd0,    // magenta
20   0x00, 0xd0, 0x00,    // green
21   0x00, 0xd0, 0xd0,    // cyan
22   0xd0, 0xd0, 0x00,    // yellow
23   0xd0, 0xd0, 0xd0,    // white
1924
20/*
21    foreground:
25   // full of each component + half of another component
26   0x00, 0x00, 0x00,    // black
27   0x60, 0x00, 0xa0,    // violet
28   0xa0, 0x60, 0x00,    // brown
29   0xa0, 0x00, 0x60,    // red/purple
30   0x00, 0xa0, 0x60,    // pastel green
31   0x00, 0x60, 0xa0,    // sky blue
32   0xa0, 0xa0, 0x60,    // yellow/green
33   0xd0, 0xd0, 0xd0,    // white
2234
23        "full" of each component
24
25        black,
26        blue,
27        red,
28        magenta,
29        green,
30        cyan
31        yellow
32        white
33
34        "full of each component + half of another component"
35        black
36        violet
37        red/purple
38        pastel green
39        sky blue
40        yellow/green
41        white
42
43    background:
44        "half" of each component
45        black
46        dark blue
47        dark red
48        dark magenta
49        dark green
50        dark cyan
51        dark yellow
52        dark white (grey)
53
54 */
55
56
57static const unsigned char kc85_palette[KC85_PALETTE_SIZE * 3] =
58{
59      /* 3 bit colour value. bit 2->green, bit 1->red, bit 0->blue */
60
61      /* foreground colours */
62      0x00, 0x00, 0x00,
63      0x00, 0x00, 0xd0,
64      0xd0, 0x00, 0x00,
65      0xd0, 0x00, 0xd0,
66      0x00, 0xd0, 0x00,
67      0x00, 0xd0, 0xd0,
68      0xd0, 0xd0, 0x00,
69      0xd0, 0xd0, 0xd0,
70
71      0x00, 0x00, 0x00,
72      0x60, 0x00, 0xa0,
73      0xa0, 0x60, 0x00,
74      0xa0, 0x00, 0x60,
75      0x00, 0xa0, 0x60,
76      0x00, 0x60, 0xa0,
77      0xa0, 0xa0, 0x60,
78      0xd0, 0xd0, 0xd0,
79
80      /* background colours are slightly darker than foreground colours */
81      0x00, 0x00, 0x00,
82      0x00, 0x00, 0xa0,
83      0xa0, 0x00, 0x00,
84      0xa0, 0x00, 0xa0,
85      0x00, 0xa0, 0x00,
86      0x00, 0xa0, 0xa0,
87      0xa0, 0xa0, 0x00,
88      0xa0, 0xa0, 0xa0
89
35   // background colours are slightly darker than foreground colours
36   0x00, 0x00, 0x00,    // black
37   0x00, 0x00, 0xa0,    // dark blue
38   0xa0, 0x00, 0x00,    // dark red
39   0xa0, 0x00, 0xa0,    // dark magenta
40   0x00, 0xa0, 0x00,    // dark green
41   0x00, 0xa0, 0xa0,    // dark cyan
42   0xa0, 0xa0, 0x00,    // dark yellow
43   0xa0, 0xa0, 0xa0    // dark white (grey)
9044};
9145
9246
9347/* Initialise the palette */
9448PALETTE_INIT( kc85 )
9549{
96   int i;
97
98   for ( i = 0; i < sizeof(kc85_palette) / 3; i++ ) {
50   for (int i = 0; i < sizeof(kc85_palette) / 3; i++ )
9951      palette_set_color_rgb(machine, i, kc85_palette[i*3], kc85_palette[i*3+1], kc85_palette[i*3+2]);
100   }
10152}
10253
103
104enum
54/* set new blink state */
55WRITE_LINE_MEMBER( kc_state::video_toggle_blink_state )
10556{
106   KC85_VIDEO_EVENT_SET_BLINK_STATE
107};
57   if (state)
58   {
59      machine().primary_screen->update_partial(machine().primary_screen->vpos());
10860
109/* set new blink state - record blink state in event list */
110void kc85_video_set_blink_state(running_machine &machine, int data)
111{
112   //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()));
61      m_kc85_blink_state = !m_kc85_blink_state;
62   }
11363}
11464
11565
11666/* draw 8 pixels */
117static void kc85_draw_8_pixels(kc_state *state, bitmap_ind16 &bitmap,int x,int y, unsigned char colour_byte, unsigned char gfx_byte)
67void kc_state::video_draw_8_pixels(bitmap_ind16 &bitmap, int x, int y, UINT8 colour_byte, UINT8 gfx_byte)
11868{
119   int background_pen;
120   int foreground_pen;
12169   int pens[4];
12270   int px;
12371
124   if (state->m_high_resolution)
72   if (m_high_resolution)
12573   {
12674      /* High resolution: 4 colors for block */
12775
r15431r15432
162110         /* bit 1: background colour -> Red */
163111         /* bit 0: background colour -> Blue */
164112
165      background_pen = (colour_byte&7) + 16;
166      foreground_pen = ((colour_byte>>3) & 0x0f);
113      int background_pen = (colour_byte&7) + 16;
114      int foreground_pen = ((colour_byte>>3) & 0x0f);
167115
168      if (colour_byte & state->m_kc85_blink_state)
116      if ((colour_byte & 0x80) && m_kc85_blink_state && (m_pio_data[1] & 0x80))
169117      {
170118         foreground_pen = background_pen;
171119      }
r15431r15432
190138}
191139
192140
193/* height of screen in lines */
194#define KC85_SCREEN_HEIGHT 256
195/* width of display in pixels */
196#define KC85_SCREEN_WIDTH 320
197/* height of top border in lines */
198#define KC85_TOP_BORDER_SIZE 8
199/* height of bottom border in lines */
200#define KC85_BOTTOM_BORDER_SIZE 8
201/* total number of lines in whole frame */
202#define KC85_FRAME_NUM_LINES 312
203/* width of whole line in pixels */
204#define KC85_LINE_SIZE 512
205/* width of left border in pixels */
206#define KC85_LEFT_BORDER_SIZE 8
207/* width of right border in pixels */
208#define KC85_RIGHT_BORDER_SIZE 8
209/* width of horizontal retrace in pixels */
210#define KC85_RETRACE_SIZE (KC85_LINE_SIZE - KC85_LEFT_BORDER_SIZE - KC85_RIGHT_BORDER_SIZE - KC85_SCREEN_WIDTH)
211/* number of lines in vertical retrace */
212#define KC85_NUM_RETRACE_LINES (KC85_FRAME_NUM_LINES - KC85_TOP_BORDER_SIZE - KC85_BOTTOM_BORDER_SIZE - KC85_SCREEN_HEIGHT)
213
214
215#define KC85_CYCLES_PER_FRAME 1750000.0f/50.0f
216#define KC85_CYCLES_PER_LINE (KC85_CYCLES_PER_FRAME/KC85_FRAME_NUM_LINES)
217#define KC85_CYCLES_PER_PIXEL (KC85_CYCLES_PER_LINE/KC85_LINE_SIZE)
218
219/*
220
221    - 1750000 cpu cycles per second
222    - 35000 cpu cycles per frame
223    - 35000/312 = 112.179 cycles per line
224    - 112.179/(512/8) = 1.752 cycles per 8-pixels
225*/
226
227/* Operation:
228
229    - Vertical and horizontal dimensions are split into states.
230    - Horizontal states take a multiple of horizontal cycles, and vertical states take a multiple of lines.
231    - The horizontal states comprise left border, main display, right border and horizontal retrace timing.
232    - The vertical states comprise top border, main display, bottom border and vertical retrace timing.
233
234
235    - if frame rate is 50Hz, and there are 312 lines, then the line rate is 15600Hz.
236    - Each frame takes 0.02 seconds, and each line takes 0.0000064 seconds - approx 64microseconds per line
237
238    - the event list is based on cpu time
239
240*/
241
242static const int horizontal_next_state_table[]=
243{
244   1,2,3,0
245};
246
247/* number of cycles for each state */
248static const int horizontal_graphics_state_cycles[]=
249{
250   /* left border */
251   (KC85_LEFT_BORDER_SIZE*KC85_CYCLES_PER_PIXEL),
252   /* main display */
253   (KC85_SCREEN_WIDTH*KC85_CYCLES_PER_PIXEL),
254   /* right border */
255   (KC85_RIGHT_BORDER_SIZE*KC85_CYCLES_PER_PIXEL),
256   /* horizontal retrace */
257   (KC85_RETRACE_SIZE*KC85_CYCLES_PER_PIXEL)
258};
259
260static const int vertical_next_state_table[]=
261{
262   1,2,3,0
263};
264
265/* number of lines for each state */
266static const int vertical_graphics_state_lines[]=
267{
268   /* top border */
269   KC85_TOP_BORDER_SIZE*KC85_CYCLES_PER_LINE,
270   /* main display */
271   KC85_SCREEN_HEIGHT*KC85_CYCLES_PER_LINE,
272   /* bottom display */
273   KC85_BOTTOM_BORDER_SIZE*KC85_CYCLES_PER_LINE,
274   /* vertical retrace */
275   KC85_NUM_RETRACE_LINES*KC85_CYCLES_PER_LINE
276};
277
278struct video_state
279{
280   /* current state */
281   int state;
282   /* number of cycles remaining in this state */
283   int cycles_remaining_in_state;
284   /* number of cycles remaining (starts at total of all states) */
285   int cycles_remaining;
286};
287
288struct grab_info
289{
290   unsigned char *pixel_ram;
291   unsigned char *colour_ram;
292};
293
294struct video_update_state
295{
296   /* bitmap to render to */
297   bitmap_ind16 *bitmap;
298   /* grab colour and pixel information for 8-pixels referenced by x,y coordinate */
299   void (*pixel_grab_callback)(struct grab_info *,int x,int y, unsigned char *colour_ptr, unsigned char *pixel_ptr);
300   /* current coords */
301   int x,y;
302   /* render coordinates */
303   int render_x,render_y;
304
305   struct video_state horizontal;
306   struct video_state vertical;
307   struct grab_info grab_data;
308};
309
310
311/* process visible cycles within a line */
312/* the cycles will never span over the end of a line */
313static void kc85_common_process_cycles(kc_state *state, struct video_update_state *video_update, int cycles)
314{
315   while (cycles!=0)
316   {
317      int cycles_to_do;
318
319      /* do as many cycles up to end of current state */
320      cycles_to_do = MIN(video_update->horizontal.cycles_remaining_in_state, cycles);
321
322      //logerror("process cycles: cycles_to_do %d\n",cycles_to_do);
323
324      /* update screen based on current state */
325      switch (video_update->horizontal.state)
326      {
327         /* border */
328         case 0:
329         {
330         //  video_update->render_x+=(cycles_to_do)*8;
331         }
332         break;
333
334         /* pixels */
335         case 1:
336         {
337            int i;
338
339            for (i=0; i<cycles_to_do; i++)
340            {
341               unsigned char colour_byte;
342               unsigned char gfx_byte;
343
344               /* grab colour and pixel information */
345               video_update->pixel_grab_callback(&video_update->grab_data,video_update->x,video_update->y,&colour_byte, &gfx_byte);
346               /* draw to screen */
347               kc85_draw_8_pixels(state, *video_update->bitmap, video_update->render_x, video_update->render_y,colour_byte, gfx_byte);
348               /* update render coordinate */
349               video_update->render_x+=8;
350               video_update->x++;
351
352               if (video_update->x>=(320/8))
353               {
354                  video_update->x = (320/8)-1;
355               }
356
357               if (video_update->render_x>=320)
358               {
359                  video_update->render_x = 319;
360               }
361
362
363            }
364         }
365         break;
366
367         /* border */
368         case 2:
369         {
370         //  video_update->render_x+=(cycles_to_do)*8;
371         }
372         break;
373
374         /* invisible/retrace */
375         case 3:
376         {
377
378
379         }
380         break;
381      }
382
383      video_update->horizontal.cycles_remaining_in_state -=cycles_to_do;
384
385      /* is state over? */
386      if (video_update->horizontal.cycles_remaining_in_state<=0)
387      {
388         /* update state */
389         video_update->horizontal.state = horizontal_next_state_table[video_update->horizontal.state];
390         video_update->horizontal.cycles_remaining_in_state+=horizontal_graphics_state_cycles[video_update->horizontal.state];
391      }
392
393      cycles-=cycles_to_do;
394   }
395}
396
397/* process a whole visible line */
398static int kc85_common_vh_process_line(kc_state *state, struct video_update_state *video_update, int cycles)
399{
400   int cycles_to_do;
401
402   /* do cycles in line */
403   while ((video_update->horizontal.cycles_remaining!=0) && (cycles!=0))
404   {
405      /* do as many cycles as will fit onto the line */
406      cycles_to_do = MIN(cycles,video_update->horizontal.cycles_remaining);
407
408      //logerror("process line: cycles_to_do: %d\n",cycles_to_do);
409
410      /* do the cycles - draw them */
411      kc85_common_process_cycles(state, video_update, cycles_to_do);
412
413      video_update->horizontal.cycles_remaining -= cycles_to_do;
414      cycles -=cycles_to_do;
415   }
416
417   /* line over */
418
419   if (video_update->horizontal.cycles_remaining==0)
420   {
421      /* reset */
422      video_update->horizontal.cycles_remaining+=KC85_CYCLES_PER_LINE;
423      /* update x,y fetch pos */
424      video_update->x = 0;
425      video_update->y++;
426
427      /* update x,y render pos */
428      video_update->render_x = 0;
429      video_update->render_y++;
430
431      if (video_update->y>=256)
432      {
433         video_update->y = 255;
434      }
435
436      if (video_update->render_y>=256)
437      {
438         video_update->render_y = 255;
439      }
440
441
442   }
443
444   /* cycles remaining */
445   return cycles;
446}
447
448static void kc85_common_vh_process_lines(kc_state *state, struct video_update_state *video_update, int cycles)
449{
450   while (cycles!=0)
451   {
452      int cycles_to_do;
453      int cycles_done;
454
455      cycles_to_do = MIN(cycles, KC85_CYCLES_PER_LINE);
456      cycles_done = cycles_to_do;
457
458      //logerror("process lines: cycles_to_do: %d\n",cycles_to_do);
459
460
461      switch (video_update->vertical.state)
462      {
463         /* border */
464         case 0:
465         {
466   //          cycles_done = cycles_to_do;
467         }
468         break;
469
470         /* graphics */
471         case 1:
472         {
473            int cycles_remaining;
474
475            /* update cycles with number of cycles not processed */
476            cycles_remaining = kc85_common_vh_process_line(state, video_update, cycles_to_do);
477
478            cycles_done = cycles_to_do - cycles_remaining;
479
480         }
481         break;
482
483         /* border */
484         case 2:
485         {
486   //          cycles_done = cycles_to_do;
487         }
488         break;
489
490         /* not visible */
491         case 3:
492         {
493   //          cycles_done = cycles_to_do;
494         }
495         break;
496      }
497
498
499      //logerror("cycles done: %d\n",cycles_done);
500      video_update->vertical.cycles_remaining_in_state -=cycles_done;
501
502      /* is state over? */
503      if (video_update->vertical.cycles_remaining_in_state<=0)
504      {
505         /* update state */
506         video_update->vertical.state = vertical_next_state_table[video_update->vertical.state];
507         video_update->vertical.cycles_remaining_in_state+=vertical_graphics_state_lines[video_update->vertical.state];
508      }
509      cycles-=cycles_done;
510   }
511}
512
513
514
515/* the kc85 screen is 320 pixels wide and 256 pixels tall */
516/* if we assume a 50Hz display, there are 312 lines for the complete frame, leaving 56 lines not visible */
517static void kc85_common_process_frame(running_machine &machine, bitmap_ind16 &bitmap, void (*pixel_grab_callback)(struct grab_info *,int x,int y,unsigned char *, unsigned char *),struct grab_info *grab_data)
518{
519   kc_state *state = machine.driver_data<kc_state>();
520   int cycles_remaining_in_frame = KC85_CYCLES_PER_FRAME;
521
522//  EVENT_LIST_ITEM *pItem;
523//    int NumItems;
524
525   struct video_update_state video_update;
526//  int cycles_offset = 0;
527
528   video_update.render_x = 0;
529   video_update.render_y = 0;
530   video_update.x = 0;
531   video_update.y = 0;
532   memcpy(&video_update.grab_data, grab_data, sizeof(struct grab_info));
533   video_update.bitmap = &bitmap;
534   video_update.pixel_grab_callback = pixel_grab_callback;
535   video_update.horizontal.state = 0;
536   video_update.horizontal.cycles_remaining_in_state = horizontal_graphics_state_cycles[video_update.horizontal.state];
537   video_update.horizontal.cycles_remaining = KC85_CYCLES_PER_LINE;
538   video_update.vertical.state = 0;
539   video_update.vertical.cycles_remaining_in_state = vertical_graphics_state_lines[video_update.vertical.state];
540   video_update.vertical.cycles_remaining = KC85_CYCLES_PER_FRAME;
541
542#if 0
543   /* first item in list */
544   pItem = spectrum_EventList_GetFirstItem(machine);
545   /* number of items remaining */
546   NumItems = spectrum_EventList_NumEvents(machine);
547
548   while (NumItems)
549   {
550      int delta_cycles;
551
552      /* number of cycles until event will trigger */
553      delta_cycles = pItem->Event_Time - cycles_offset;
554
555      //logerror("cycles between this event and next: %d\n",delta_cycles);
556      kc85_common_vh_process_lines(&video_update, delta_cycles);
557
558      /* update number of cycles remaining in frame */
559      cycles_remaining_in_frame -= delta_cycles;
560      /* set new blink state */
561      state->m_kc85_blink_state = pItem->Event_Data;
562
563      /* set new cycles into frame */
564      cycles_offset = pItem->Event_Time;
565      /* next event */
566      pItem++;
567      /* update number of events remaining */
568      NumItems--;
569   }
570#endif
571
572   /* process remainder */
573   kc85_common_vh_process_lines(state, &video_update, cycles_remaining_in_frame);
574   //spectrum_EventList_Reset(machine);
575   //spectrum_EventList_SetOffsetStartTime ( machine, machine.firstcpu->attotime_to_cycles(machine.primary_screen->scan_period() * machine.primary_screen->vpos()) );
576}
577
578
579
580141/***************************************************************************
581142 KC85/4 video hardware
582143***************************************************************************/
583static void kc85_common_vh_start(running_machine &machine)
584{
585   kc_state *state = machine.driver_data<kc_state>();
586   state->m_kc85_blink_state = 0;
587   //spectrum_EventList_Initialise(machine, 30000);
588}
589144
590
591
592145void kc85_4_state::video_start()
593146{
594   kc85_common_vh_start(machine());
595
596   m_video_ram = auto_alloc_array(machine(), UINT8,
597      (KC85_4_SCREEN_COLOUR_RAM_SIZE*2) +
598      (KC85_4_SCREEN_PIXEL_RAM_SIZE*2));
599
147   m_video_ram = machine().memory().region_alloc("videoram", (KC85_4_SCREEN_COLOUR_RAM_SIZE*2) + (KC85_4_SCREEN_PIXEL_RAM_SIZE*2), 1, ENDIANNESS_LITTLE)->base();
600148   m_display_video_ram = m_video_ram;
149
150   m_kc85_blink_state = 0;
601151}
602152
603void kc85_4_video_ram_select_bank(running_machine &machine, int bank)
153void kc85_4_state::video_control_w(int data)
604154{
605   kc85_4_state *state = machine.driver_data<kc85_4_state>();
606155   /* calculate address of video ram to display */
607   unsigned char *video_ram;
156   if (data & 1)
157      m_display_video_ram = m_video_ram + (KC85_4_SCREEN_PIXEL_RAM_SIZE + KC85_4_SCREEN_COLOUR_RAM_SIZE);
158   else
159      m_display_video_ram = m_video_ram;
608160
609   video_ram = state->m_video_ram;
610
611   if (bank!=0)
612   {
613      video_ram +=
614               (KC85_4_SCREEN_PIXEL_RAM_SIZE +
615               KC85_4_SCREEN_COLOUR_RAM_SIZE);
616   }
617
618   state->m_display_video_ram = video_ram;
161   m_high_resolution = (data & 0x08) ? 0 : 1;
619162}
620163
621unsigned char *kc85_4_get_video_ram_base(running_machine &machine, int bank, int colour)
622{
623   kc85_4_state *state = machine.driver_data<kc85_4_state>();
624   /* base address: screen 0 pixel data */
625   unsigned char *addr = state->m_video_ram;
626164
627   if (bank!=0)
628   {
629      /* access screen 1 */
630      addr += KC85_4_SCREEN_PIXEL_RAM_SIZE +
631            KC85_4_SCREEN_COLOUR_RAM_SIZE;
632   }
633
634   if (colour!=0)
635   {
636      /* access colour information of selected screen */
637      addr += KC85_4_SCREEN_PIXEL_RAM_SIZE;
638   }
639
640   return addr;
641}
642
643static void kc85_4_pixel_grab_callback(struct grab_info *grab_data,int x,int y, unsigned char *colour, unsigned char *gfx)
165UINT32 kc85_4_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
644166{
645   int offset;
167   UINT8 *pixel_ram = m_display_video_ram;
168   UINT8 *colour_ram = pixel_ram + 0x04000;
646169
647   offset = (y & 0xff) | ((x & 0x0ff)<<8);
648
649   *colour = grab_data->colour_ram[offset];
650   *gfx = grab_data->pixel_ram[offset];
651
652}
653
654
655/***************************************************************************
656  Draw the game screen in the given bitmap_ind16.
657  Do NOT call osd_update_display() from this function,
658  it will be called by the main emulation engine.
659***************************************************************************/
660SCREEN_UPDATE_IND16( kc85_4 )
661{
662   kc85_4_state *state = screen.machine().driver_data<kc85_4_state>();
663#if 0
664   unsigned char *pixel_ram = state->m_display_video_ram;
665   unsigned char *colour_ram = pixel_ram + 0x04000;
666
667   int x,y;
668
669   for (y=0; y<KC85_SCREEN_HEIGHT; y++)
170   for (int y=cliprect.min_y; y<=cliprect.max_y; y++)
670171   {
671      for (x=0; x<(KC85_SCREEN_WIDTH>>3); x++)
172      for (int x=0; x<(KC85_SCREEN_WIDTH>>3); x++)
672173      {
673         unsigned char colour_byte, gfx_byte;
674         int offset;
174         UINT16 offset = y | (x<<8);
675175
676         offset = y | (x<<8);
176         UINT8 colour_byte = colour_ram[offset];
177         UINT8 gfx_byte = pixel_ram[offset];
677178
678         colour_byte = colour_ram[offset];
679         gfx_byte = pixel_ram[offset];
680
681         kc85_draw_8_pixels(state, bitmap,(x<<3),y, colour_byte, gfx_byte);
682
179         video_draw_8_pixels(bitmap, (x<<3), y, colour_byte, gfx_byte);
683180      }
684181   }
685#endif
686   struct grab_info grab_data;
687182
688   grab_data.pixel_ram = state->m_display_video_ram;
689   grab_data.colour_ram = state->m_display_video_ram + 0x04000;
690
691   kc85_common_process_frame(screen.machine(), bitmap, kc85_4_pixel_grab_callback,&grab_data);
692
693183   return 0;
694184}
695185
r15431r15432
699189
700190void kc_state::video_start()
701191{
702   kc85_common_vh_start(machine());
703}
192   m_video_ram = machine().memory().region_alloc("videoram", 0x4000, 1, ENDIANNESS_LITTLE)->base();
704193
705
706static void kc85_3_pixel_grab_callback(struct grab_info *grab_data,int x,int y, unsigned char *colour, unsigned char *gfx)
707{
708   int pixel_offset,colour_offset;
709
710   /* this has got to be speeded up!!! */
711   if ((x & 0x020)==0)
712   {
713      pixel_offset = (x & 0x01f) | (((y>>2) & 0x03)<<5) |
714      ((y & 0x03)<<7) | (((y>>4) & 0x0f)<<9);
715
716      colour_offset = (x & 0x01f) | (((y>>2) & 0x03f)<<5);
717   }
718   else
719   {
720      /* 1  0  1  0  0  V7 V6 V1  V0 V3 V2 V5 V4 H2 H1 H0 */
721      /* 1  0  1  1  0  0  0  V7  V6 V3 V2 V5 V4 H2 H1 H0 */
722
723      pixel_offset = 0x02000+((x & 0x07) | (((y>>4) & 0x03)<<3) |
724         (((y>>2) & 0x03)<<5) | ((y & 0x03)<<7) | ((y>>6) & 0x03)<<9);
725
726      colour_offset = 0x0800+((x & 0x07) | (((y>>4) & 0x03)<<3) |
727         (((y>>2) & 0x03)<<5) | ((y>>6) & 0x03)<<7);
728   }
729
730   *colour = grab_data->colour_ram[colour_offset];
731   *gfx = grab_data->pixel_ram[pixel_offset];
732
194   m_kc85_blink_state = 0;
733195}
734196
735/***************************************************************************
736  Draw the game screen in the given bitmap_ind16.
737  Do NOT call osd_update_display() from this function,
738  it will be called by the main emulation engine.
739***************************************************************************/
740SCREEN_UPDATE_IND16( kc85_3 )
197UINT32 kc_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
741198{
742   kc_state *state = screen.machine().driver_data<kc_state>();
743
744#if 0
745199   /* colour ram takes up 0x02800 bytes */
746      unsigned char *pixel_ram = machine.device<ram_device>(RAM_TAG)->pointer()+0x08000;
747   unsigned char *colour_ram = pixel_ram + 0x02800;
200   UINT8 *pixel_ram = m_video_ram;
201   UINT8 *colour_ram = m_video_ram + 0x02800;
748202
749   int x,y;
750
751   for (y=0; y<KC85_SCREEN_HEIGHT; y++)
203   for (int y=cliprect.min_y; y<=cliprect.max_y; y++)
752204   {
753      for (x=0; x<(KC85_SCREEN_WIDTH>>3); x++)
205      for (int x=0; x<(KC85_SCREEN_WIDTH>>3); x++)
754206      {
755         unsigned char colour_byte, gfx_byte;
756207         int pixel_offset,colour_offset;
757208
758209         if ((x & 0x020)==0)
r15431r15432
774225               (((y>>2) & 0x03)<<5) | ((y>>6) & 0x03)<<7);
775226         }
776227
777         colour_byte = colour_ram[colour_offset];
778         gfx_byte = pixel_ram[pixel_offset];
228         UINT8 colour_byte = colour_ram[colour_offset];
229         UINT8 gfx_byte = pixel_ram[pixel_offset];
779230
780         kc85_draw_8_pixels(state, bitmap,(x<<3),y, colour_byte, gfx_byte);
231         video_draw_8_pixels(bitmap,(x<<3),y, colour_byte, gfx_byte);
781232      }
782233   }
783#endif
784234
785   struct grab_info grab_data;
786
787   grab_data.pixel_ram = state->m_ram_base + 0x04000;
788   grab_data.colour_ram = state->m_ram_base + 0x04000 + 0x02800;
789
790   kc85_common_process_frame(screen.machine(), bitmap, kc85_3_pixel_grab_callback,&grab_data);
791
792235   return 0;
793236}
src/mess/drivers/kc.c
r15431r15432
109109    DEVCB_CPU_INPUT_LINE("maincpu", 0),
110110   DEVCB_DRIVER_LINE_MEMBER(kc_state, ctc_zc0_callback),
111111   DEVCB_DRIVER_LINE_MEMBER(kc_state, ctc_zc1_callback),
112   DEVCB_DRIVER_LINE_MEMBER(kc_state, ctc_zc2_callback)
112   DEVCB_DRIVER_LINE_MEMBER(kc_state, video_toggle_blink_state)
113113};
114114
115115const kc_keyb_interface kc85_keyboard_interface =
r15431r15432
139139
140140   /* video hardware */
141141   MCFG_SCREEN_ADD("screen", RASTER)
142   MCFG_SCREEN_REFRESH_RATE(50)
143   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
144   MCFG_SCREEN_SIZE(KC85_SCREEN_WIDTH, KC85_SCREEN_HEIGHT)
145   MCFG_SCREEN_VISIBLE_AREA(0, (KC85_SCREEN_WIDTH - 1), 0, (KC85_SCREEN_HEIGHT - 1))
146   MCFG_SCREEN_UPDATE_STATIC( kc85_3 )
142   MCFG_SCREEN_RAW_PARAMS(XTAL_28_37516MHz/2, 908, 0, 320, 312, 0, 256)
143   MCFG_SCREEN_UPDATE_DRIVER(kc_state, screen_update)
144   MCFG_TIMER_ADD_SCANLINE("scantimer", kc_scanline, "screen", 0, 1)
147145
148146   MCFG_PALETTE_LENGTH(KC85_PALETTE_SIZE)
149147   MCFG_PALETTE_INIT( kc85 )
r15431r15432
176174
177175   /* internal ram */
178176   MCFG_RAM_ADD(RAM_TAG)
179   MCFG_RAM_DEFAULT_SIZE("32K")
177   MCFG_RAM_DEFAULT_SIZE("16K")
180178MACHINE_CONFIG_END
181179
182180
r15431r15432
193191
194192   /* video hardware */
195193   MCFG_SCREEN_ADD("screen", RASTER)
196   MCFG_SCREEN_REFRESH_RATE(50)
197   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
198   MCFG_SCREEN_SIZE(KC85_SCREEN_WIDTH, KC85_SCREEN_HEIGHT)
199   MCFG_SCREEN_VISIBLE_AREA(0, (KC85_SCREEN_WIDTH - 1), 0, (KC85_SCREEN_HEIGHT - 1))
200   MCFG_SCREEN_UPDATE_STATIC( kc85_4 )
194   MCFG_SCREEN_RAW_PARAMS(XTAL_28_37516MHz/2, 908, 0, 320, 312, 0, 256)
195   MCFG_SCREEN_UPDATE_DRIVER(kc85_4_state, screen_update)
196   MCFG_TIMER_ADD_SCANLINE("scantimer", kc_scanline, "screen", 0, 1)
201197
202198   MCFG_PALETTE_LENGTH(KC85_PALETTE_SIZE)
203199   MCFG_PALETTE_INIT( kc85 )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team