Previous 15994 Revisions Next

r5530 Saturday 29th August, 2009 at 20:40:34 UTC by Angelo Salese
[X1]: Added scrolling support
[src/mess/drivers]x1.c

src/mess/drivers/x1.c
r5529r5530
1313   - clean-ups!
1414   - There are various unclear video things, these are:
1515      - how layer clearance works? Dragon Buster relies on it
16      - I bet there's a PCG reset address tied to some bit, find it;
16      - PCG reset address is tied to the screen beams in some way;
17      - Support the alternative PCG upload mode;
1718      - Add the extended gfx hookup;
1819      - (anything else?)
1920
r5529r5530
149150static UINT8 io_bank_mode;
150151static UINT8 *gfx_bitmap_ram;
151152static UINT16 pcg_index[3];
153static UINT8 pcg_reset;
154static UINT16 crtc_start_addr;
155static struct
156{
157   UINT8 gfx_bank;
158   UINT8 pcg_mode;
159}ply_reg;
152160
153
154161static VIDEO_START( x1 )
155162{
156163   colorram = auto_alloc_array(machine, UINT8, 0x1000);
157164   videoram = auto_alloc_array(machine, UINT8, 0x1000);
158   gfx_bitmap_ram = auto_alloc_array(machine, UINT8, 0xc000);
165   gfx_bitmap_ram = auto_alloc_array(machine, UINT8, 0xc000*2);
159166}
160167
161168static void draw_fgtilemap(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int w,int pri)
162169{
163170   int y,x,res_x,res_y;
171   int screen_mask;
164172
173   screen_mask = (w == 2) ? 0xfff : 0x7ff;
174
165175   for (y=0;y<25;y++)
166176   {
167177      for (x=0;x<40*w;x++)
168178      {
169         int tile = videoram[x+(y*40*w)];
170         int color = colorram[x+(y*40*w)] & 0x1f;
171         int width = (colorram[x+(y*40*w)] & 0x80)>>7;
172         int height = (colorram[x+(y*40*w)] & 0x40)>>6;
173         int pcg_bank = (colorram[x+(y*40*w)] & 0x20)>>5;
179         int tile = videoram[(x+(y*40*w)+crtc_start_addr) & screen_mask];
180         int color = colorram[(x+(y*40*w)+crtc_start_addr) & screen_mask] & 0x1f;
181         int width = (colorram[(x+(y*40*w)+crtc_start_addr) & screen_mask] & 0x80)>>7;
182         int height = (colorram[(x+(y*40*w)+crtc_start_addr) & screen_mask] & 0x40)>>6;
183         int pcg_bank = (colorram[(x+(y*40*w)+crtc_start_addr) & screen_mask] & 0x20)>>5;
174184         UINT8 *gfx_data = pcg_bank ? memory_region(machine, "pcg") : memory_region(machine, "cgrom");
175185
176186         if(((color & 0x8)>>3) != pri) continue;
r5529r5530
218228   }
219229}
220230
221static void draw_gfxbitmap(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int w)
231static void draw_gfxbitmap(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int w,int plane)
222232{
223233   int count,xi,yi,x,y;
224234   int pen_r,pen_g,pen_b,color;
225235   int yi_size;
226236
227   count = 0;
237   count = crtc_start_addr;
228238
229239   yi_size = (w == 1) ? 16 : 8;
230240
r5529r5530
236246         {
237247            for(xi=0;xi<8;xi++)
238248            {
239               pen_b = (gfx_bitmap_ram[count+0x0000]>>(7-xi)) & 1;
240               pen_r = (gfx_bitmap_ram[count+0x4000]>>(7-xi)) & 1;
241               pen_g = (gfx_bitmap_ram[count+0x8000]>>(7-xi)) & 1;
249               pen_b = (gfx_bitmap_ram[count+0x0000+plane*0xc000]>>(7-xi)) & 1;
250               pen_r = (gfx_bitmap_ram[count+0x4000+plane*0xc000]>>(7-xi)) & 1;
251               pen_g = (gfx_bitmap_ram[count+0x8000+plane*0xc000]>>(7-xi)) & 1;
242252
243253               color =  pen_g<<2 | pen_r<<1 | pen_b<<0;
244254
r5529r5530
262272         }
263273      }
264274      count+= (w == 2) ? 48 : 24;
275      count&=0x3fff;
265276   }
266277}
267278
r5529r5530
274285   bitmap_fill(bitmap, cliprect, screen->machine->pens[0x100]);
275286
276287   draw_fgtilemap(screen->machine,bitmap,cliprect,w,0);
277   draw_gfxbitmap(screen->machine,bitmap,cliprect,w);
288   draw_gfxbitmap(screen->machine,bitmap,cliprect,w,0);
289   draw_gfxbitmap(screen->machine,bitmap,cliprect,w,1);
278290   draw_fgtilemap(screen->machine,bitmap,cliprect,w,1);
279291
280292   return 0;
281293}
282294
295static VIDEO_EOF( x1 )
296{
297}
283298
284
285299static UINT8 sub_cmd,sub_val,key_flag;
286300
287301/*
r5529r5530
522536
523537   addr = (offset & 0x300) >> 8;
524538
539   if(pcg_reset)
540   {
541      pcg_index[0] = pcg_index[1] = pcg_index[2] = 0;
542      pcg_reset = 0;
543   }
544
525545   if(addr == 0)
526546   {
547      /* FIXME: this is wrong (it's for the BIOS GFX ROM, read only)  */
527548      /* maybe data actually? */
528549      pcg_index[0] = data*8;
529550      pcg_index[1] = data*8;
r5529r5530
531552   }
532553   else
533554   {
534      pcg_offset = (pcg_index[addr-1]) & 0x7ff;
535      pcg_offset+=((addr-1)*0x800);
536      PCG_RAM[pcg_offset] = data;
555//      if(!ply_reg.pcg_mode)
556//      {
557         //( ((V_CNT-CRT_YL)/FNT_YL) + TXT_YL) * TXT_XL
558//         int v_count = video_screen_get_vpos(space->machine->primary_screen);
559//
560//      }
561//      else
562      {
563         pcg_offset = (pcg_index[addr-1]) & 0x7ff;
564         pcg_offset+=((addr-1)*0x800);
565         PCG_RAM[pcg_offset] = data;
537566
538      pcg_offset &= 0x7ff;
567         pcg_offset &= 0x7ff;
539568
540       gfx_element_mark_dirty(space->machine->gfx[4], pcg_offset >> 3);
541       gfx_element_mark_dirty(space->machine->gfx[5], pcg_offset >> 3);
542       gfx_element_mark_dirty(space->machine->gfx[6], pcg_offset >> 3);
543       gfx_element_mark_dirty(space->machine->gfx[7], pcg_offset >> 3);
569          gfx_element_mark_dirty(space->machine->gfx[4], pcg_offset >> 3);
570          gfx_element_mark_dirty(space->machine->gfx[5], pcg_offset >> 3);
571          gfx_element_mark_dirty(space->machine->gfx[6], pcg_offset >> 3);
572          gfx_element_mark_dirty(space->machine->gfx[7], pcg_offset >> 3);
544573
545        pcg_index[addr-1]++;
574           pcg_index[addr-1]++;
575      }
546576   }
547577}
548578
549579static READ8_HANDLER( x1_clr_r )
550580{
551   //memset(gfx_bitmap_ram,0x00,0xc000);
552581
553582   return 0xff;
554583}
r5529r5530
557586{
558587   io_bank_mode = 0; //any read disables the extended mode.
559588
560   if(offset >= 0x0704 && offset <= 0x0707)       { return z80ctc_r(devtag_get_device(space->machine, "ctc"), offset-0x0704); }
561   else if(offset == 0x07d0)                       { return x1_clr_r(space, 0); }
589   if(offset == 0x0000)                           { return x1_clr_r(space, 0); }
590   else if(offset >= 0x0704 && offset <= 0x0707)   { return z80ctc_r(devtag_get_device(space->machine, "ctc"), offset-0x0704); }
562591   else if(offset == 0x0e03)                       { return x1_rom_r(space, 0); }
563592   else if(offset >= 0x0ff8 && offset <= 0x0fff)   { return x1_fdc_r(space, offset-0xff8); }
564593   else if(offset >= 0x1900 && offset <= 0x19ff)   { return sub_io_r(space, 0); }
r5529r5530
570599//   else if(offset >= 0x1fd0 && offset <= 0x1fdf)   { return x1_scrn_r(space,offset-0x1fd0); }
571600   else if(offset >= 0x2000 && offset <= 0x2fff)   { return colorram[offset-0x2000]; }
572601   else if(offset >= 0x3000 && offset <= 0x3fff)   { return videoram[offset-0x3000]; }
573   else if(offset >= 0x4000 && offset <= 0xffff)   { return gfx_bitmap_ram[offset-0x4000]; }
602   else if(offset >= 0x4000 && offset <= 0xffff)   { return gfx_bitmap_ram[offset-0x4000+(ply_reg.gfx_bank*0xc000)]; }
574603   else
575604   {
576605      logerror("(PC=%06x) Read i/o address %04x\n",cpu_get_pc(space->cpu),offset);
r5529r5530
584613//      fatalerror("Extended GFX RAM write %02x %04x",data,offset);
585614}
586615
616static WRITE8_HANDLER( x1_ply_w )
617{
618   ply_reg.pcg_mode = (data & 0x20)>>5;
619   ply_reg.gfx_bank = (data & 0x10)>>4;
620}
621
622static WRITE8_HANDLER( x1_6845_w )
623{
624   static int addr_latch;
625
626   if(offset == 0)
627   {
628      addr_latch = data;
629      mc6845_address_w(devtag_get_device(space->machine, "crtc"), 0,data);
630   }
631   else
632   {
633      /* FIXME: this should be inside the MC6845 core! */
634      if(addr_latch == 0x0c)
635         crtc_start_addr = ((data<<8) & 0x3f00) | (crtc_start_addr & 0xff);
636      else if(addr_latch == 0x0d)
637         crtc_start_addr = (crtc_start_addr & 0x3f00) | (data & 0xff);
638
639      mc6845_register_w(devtag_get_device(space->machine, "crtc"), 0,data);
640   }
641}
642
587643static WRITE8_HANDLER( x1_io_w )
588644{
589645   if(io_bank_mode == 1)                           { x1_ex_gfxram_w(space, offset, data); }
r5529r5530
595651   else if(offset >= 0x1000 && offset <= 0x10ff)   { x1_pal_b_w(space, 0,data); }
596652   else if(offset >= 0x1100 && offset <= 0x11ff)   { x1_pal_r_w(space, 0,data); }
597653   else if(offset >= 0x1200 && offset <= 0x12ff)   { x1_pal_g_w(space, 0,data); }
598//   else if(offset >= 0x1300 && offset <= 0x13ff)   { x1_ply_w(space->machine, 0,data; }
654   else if(offset >= 0x1300 && offset <= 0x13ff)   { x1_ply_w(space, 0,data); }
599655   else if(offset >= 0x1400 && offset <= 0x17ff)   { x1_pcg_w(space, offset-0x1400,data); }
600   else if(offset == 0x1800                    )   { mc6845_address_w(devtag_get_device(space->machine, "crtc"), 0,data); }
601   else if(offset == 0x1801                    )   { mc6845_register_w(devtag_get_device(space->machine, "crtc"), 0,data); }
656   else if(offset == 0x1800 || offset == 0x1801)   { x1_6845_w(space, offset-0x1800, data); }
602657   else if(offset >= 0x1900 && offset <= 0x19ff)   { sub_io_w(space, 0,data); }
603658   else if(offset >= 0x1a00 && offset <= 0x1aff)   { ppi8255_w(devtag_get_device(space->machine, "ppi8255_0"), (offset-0x1a00) & 3,data); }
604659   else if(offset >= 0x1b00 && offset <= 0x1bff)   { ay8910_data_w(devtag_get_device(space->machine, "ay"), 0,data); }
r5529r5530
612667//   else if(offset >= 0x1fd0 && offset <= 0x1fdf)   { x1_scrn_w(space->machine,offset-0x1fd0,data); }
613668   else if(offset >= 0x2000 && offset <= 0x2fff)   { colorram[offset-0x2000] = data; }
614669   else if(offset >= 0x3000 && offset <= 0x3fff)   { videoram[offset-0x3000] = data; }
615   else if(offset >= 0x4000 && offset <= 0xffff)   { gfx_bitmap_ram[offset-0x4000] = data; }
670   else if(offset >= 0x4000 && offset <= 0xffff)   { gfx_bitmap_ram[offset-0x4000+(ply_reg.gfx_bank*0xc000)] = data; }
616671   else
617672   {
618673      logerror("(PC=%06x) Write %02x at i/o address %04x\n",cpu_get_pc(space->cpu),data,offset);
r5529r5530
11061161
11071162   memory_set_bankptr(machine, 1, &ROM[0x00000]);
11081163
1109   memset(gfx_bitmap_ram,0x00,0xc000);
1164   memset(gfx_bitmap_ram,0x00,0xc000*2);
11101165
11111166   for(i=0;i<0x1800;i++)
11121167   {
r5529r5530
11501205   DEVCB_NULL
11511206};
11521207
1208static INTERRUPT_GEN( x1_vbl )
1209{
1210//   pcg_reset = 1;
1211}
11531212
11541213static MACHINE_DRIVER_START( x1 )
11551214   /* basic machine hardware */
11561215   MDRV_CPU_ADD("maincpu", Z80, XTAL_4MHz)
11571216   MDRV_CPU_PROGRAM_MAP(x1_mem)
11581217   MDRV_CPU_IO_MAP(x1_io)
1218   MDRV_CPU_VBLANK_INT("screen", x1_vbl)
11591219
11601220   MDRV_Z80CTC_ADD( "ctc", XTAL_4MHz , ctc_intf )
11611221
r5529r5530
11791239
11801240   MDRV_VIDEO_START(x1)
11811241   MDRV_VIDEO_UPDATE(x1)
1242   MDRV_VIDEO_EOF(x1)
11821243
11831244   MDRV_MB8877_ADD("fdc",x1_mb8877a_interface)
11841245

Previous 15994 Revisions Next


© 1998-2018 The MESS Team