Previous 15994 Revisions Next

r8929 Saturday 28th August, 2010 at 14:31:21 UTC by Angelo Salese
[MZ-2500]: Some graphics hook-up, based off Hover Attack
[src/mess/drivers]mz2500.c

src/mess/drivers/mz2500.c
r8928r8929
5757/* video stuff*/
5858static UINT8 text_reg[0x100], text_reg_index;
5959static UINT8 text_col_size, text_font_reg;
60static UINT8 pal_select;
6061
6162static VIDEO_START( mz2500 )
6263{
6364}
6465
65static VIDEO_UPDATE( mz2500 )
66static void draw_80x25(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect)
6667{
67   UINT8 *vram = memory_region(screen->machine, "maincpu");
68   UINT8 *vram = memory_region(machine, "maincpu");
6869   int x,y,count,xi,yi;
69//  gfx_element *gfx;// = screen->machine->gfx[0];
70   UINT8 *gfx_data;// = pcg_bank ? memory_region(machine, "pcg") : memory_region(machine, "cgrom");
71   int w;
70   UINT8 *gfx_data;
7271
7372   count = 0x70000;
7473
75   w = (crtc_reg[0x0e] == 0x17) ? 1 : 2; //TODO
76
77   if(text_font_reg)
74   for (y=0;y<25;y++)
7875   {
79      for (y=0;y<25;y++)
76      for (x=0;x<80;x++)
8077      {
81         for (x=0;x<40*w/*text_col_size*/;x++)
82         {
83            int tile = vram[count+0x0000] & 0xff;
84            int attr = vram[count+0x0800];
85            int tile_bank = vram[count+0x1000] & 0x3f;
86            int gfx_sel = (attr & 0x38) | (vram[count+0x1000] & 0xc0);
87            //int gfx_num;
88            int color = attr & 7;
78         int tile = vram[count+0x0000] & 0xff;
79         int attr = vram[count+0x0800];
80         int tile_bank = vram[count+0x1000] & 0x3f;
81         int gfx_sel = (attr & 0x38) | (vram[count+0x1000] & 0xc0);
82         //int gfx_num;
83         int color = attr & 7;
8984
90            if(gfx_sel == 0x80 || gfx_sel == 0xc0)
91               gfx_data = memory_region(screen->machine,"kanji"); //TODO
92            else
93               gfx_data = memory_region(screen->machine,"pcg");
85         if(gfx_sel == 0x80 || gfx_sel == 0xc0)
86            gfx_data = memory_region(machine,"kanji"); //TODO
87         else
88            gfx_data = memory_region(machine,"pcg");
9489
95            tile|= tile_bank << 8;
90         tile|= tile_bank << 8;
9691
97            for(yi=0;yi<8;yi++)
92         for(yi=0;yi<8;yi++)
93         {
94            for(xi=0;xi<8;xi++)
9895            {
99               for(xi=0;xi<8;xi++)
96               UINT8 pen_bit[3],pen;
97
98               if(gfx_sel & 0x8)
10099               {
101                  UINT8 pen_bit[3],pen;
100                  pen_bit[0] = ((gfx_data[tile*8+yi+0x1800]>>(7-xi)) & 1) ? 4 : 0; //G
101                  pen_bit[1] = ((gfx_data[tile*8+yi+0x1000]>>(7-xi)) & 1) ? 2 : 0; //R
102                  pen_bit[2] = ((gfx_data[tile*8+yi+0x0800]>>(7-xi)) & 1) ? 1 : 0; //B
102103
103                  if(gfx_sel & 0x8)
104                  {
105                     pen_bit[0] = ((gfx_data[tile*8+yi+0x1800]>>(7-xi)) & 1) ? 4 : 0; //G
106                     pen_bit[1] = ((gfx_data[tile*8+yi+0x1000]>>(7-xi)) & 1) ? 2 : 0; //R
107                     pen_bit[2] = ((gfx_data[tile*8+yi+0x0800]>>(7-xi)) & 1) ? 1 : 0; //B
104                  pen = pen_bit[0]|pen_bit[1]|pen_bit[2];
105               }
106               else
107                  pen = ((gfx_data[tile*8+yi]>>(7-xi)) & 1) ? color : 0;
108108
109                     pen = pen_bit[0]|pen_bit[1]|pen_bit[2];
110                  }
111                  else
112                     pen = ((gfx_data[tile*8+yi]>>(7-xi)) & 1) ? color : 0;
109               *BITMAP_ADDR16(bitmap, (y*8+yi), x*8+xi) = machine->pens[pen];
110            }
111         }
112            //drawgfx_opaque(bitmap,cliprect,screen->machine->gfx[gfx_num],tile,color,0,0,x*8,(y)*8);
113113
114                  *BITMAP_ADDR16(bitmap, (y*8+yi), x*8+xi) = screen->machine->pens[pen];
114         count++;
115      }
116   }
117}
118
119static void draw_40x25(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int tv_mode)
120{
121   UINT8 *vram = memory_region(machine, "maincpu");
122   int x,y,count,xi,yi;
123   UINT8 *gfx_data;
124
125   count = 0x70000;
126
127   if(tv_mode != 1)
128      popmessage("%02x",tv_mode);
129
130   for (y=0;y<25;y++)
131   {
132      for (x=0;x<40;x++)
133      {
134         int tile = vram[count+0x0000] & 0xff;
135         int attr = vram[count+0x0800];
136         int tile_bank = vram[count+0x1000] & 0x3f;
137         int gfx_sel = (attr & 0x38) | (vram[count+0x1000] & 0xc0);
138         //int gfx_num;
139         int color = attr & 7;
140
141         if(gfx_sel == 0x80 || gfx_sel == 0xc0)
142            gfx_data = memory_region(machine,"kanji"); //TODO
143         else
144            gfx_data = memory_region(machine,"pcg");
145
146         tile|= tile_bank << 8;
147
148         for(yi=0;yi<8;yi++)
149         {
150            for(xi=0;xi<8;xi++)
151            {
152               UINT8 pen_bit[3],pen;
153
154               if(gfx_sel & 0x8)
155               {
156                  pen_bit[0] = ((gfx_data[tile*8+yi+0x1800]>>(7-xi)) & 1) ? 4 : 0; //G
157                  pen_bit[1] = ((gfx_data[tile*8+yi+0x1000]>>(7-xi)) & 1) ? 2 : 0; //R
158                  pen_bit[2] = ((gfx_data[tile*8+yi+0x0800]>>(7-xi)) & 1) ? 1 : 0; //B
159
160                  pen = pen_bit[0]|pen_bit[1]|pen_bit[2];
115161               }
162               else
163                  pen = ((gfx_data[tile*8+yi]>>(7-xi)) & 1) ? color : 0;
164
165               *BITMAP_ADDR16(bitmap, (y*8+yi), x*8+xi) = machine->pens[pen];
116166            }
167         }
117168            //drawgfx_opaque(bitmap,cliprect,screen->machine->gfx[gfx_num],tile,color,0,0,x*8,(y)*8);
118169
119            count++;
120         }
170         count++;
121171      }
122172   }
173}
174
175static void draw_tv_screen(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect)
176{
177   //w = (text_col_size) ? 2 : 1; //80 : 40
178   if(text_col_size)
179      draw_80x25(machine,bitmap,cliprect);
123180   else
124181   {
182      //int tv_mode = (text_reg[0] & 0x0c) >> 2;
183      draw_40x25(machine,bitmap,cliprect,text_reg[0] >> 2);
184   }
185
186   #if 0
187   if(text_font_reg)
188   {
189
190   }
191   else
192   {
125193      for (y=0;y<25;y+=2)
126194      {
127195         for (x=0;x<40*w;x++)
128196         {
129197            int tile = vram[count+0x0000] & 0xfe;
130            int attr = vram[count+0x800];
198            int attr = vram[count+0x0800];
131199            int tile_bank = vram[count+0x1000] & 0x3f;
132200            int gfx_sel = (attr & 0x38) | (vram[count+0x1000] & 0xc0);
133201            //int gfx_num;
134202            int color = attr & 7;
135203
136204            if(gfx_sel == 0x80 || gfx_sel == 0xc0)
137               gfx_data = memory_region(screen->machine,"kanji"); //TODO
205               gfx_data = memory_region(machine,"kanji"); //TODO
138206            else
139               gfx_data = memory_region(screen->machine,"pcg");
207               gfx_data = memory_region(machine,"pcg");
140208
141209            tile|= tile_bank << 8;
142210
r8928r8929
148216
149217                  pen = ((gfx_data[tile*8+yi]>>(7-xi)) & 1) ? color : 0;
150218
151                  *BITMAP_ADDR16(bitmap, (y*8+yi), x*8+xi) = screen->machine->pens[pen];
219                  *BITMAP_ADDR16(bitmap, (y*8+yi), x*8+xi) = machine->pens[pen];
152220               }
153221            }
154222
r8928r8929
159227         }
160228      }
161229   }
230   #endif
231}
162232
233static void draw_cg256_screen(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect)
234{
235   static UINT32 count;
236   UINT8 *vram = memory_region(machine, "maincpu");
237   UINT8 pen;
238   int x,y,xi;
239
240   count = 0x40000;
241
242   for(y=0;y<200;y++)
243   {
244      for(x=0;x<320;x+=8)
245      {
246         for(xi=0;xi<8;xi++)
247         {
248            pen = (vram[count]>>(xi)) & 1 ? 0xff : 0x00;
249
250            if(pen)
251               *BITMAP_ADDR16(bitmap, y, x+xi) = machine->pens[pen+0x100];
252         }
253         count++;
254      }
255   }
256}
257
258static VIDEO_UPDATE( mz2500 )
259{
260   if(pal_select)
261      draw_tv_screen(screen->machine,bitmap,cliprect);
262   else //4096 mode colors
263   {
264      // ...
265   }
266
267   if(crtc_reg[0x0e] == 0x1d)
268      draw_cg256_screen(screen->machine,bitmap,cliprect);
269
163270    return 0;
164271}
165272
r8928r8929
304411   return vblank_bit | hblank_bit;
305412}
306413
307static WRITE8_HANDLER( mz2500_txt_crtc_w )
414/*
415[0] ---x ---- line height (0) 16 (1) 20
416[0] ---- xx-- 40 column mode (0) 64 colors (1) screen 1 (2) screen 2 (3) screen 1 + screen 2
417[1] xxxx xxxx TV map offset low address value
418[2] ---- -xxx TV map offset high address value
419
420[9] ---- xxxx vertical scrolling? (val * 2)
421*/
422
423static UINT8 pal_256_param(int index, int param)
308424{
425   UINT8 val;
426
427   switch(param & 3)
428   {
429      case 0: val = index & 0x80 ? 1 : 0; break;
430      case 1: val = index & 0x08 ? 1 : 0; break;
431      case 2: val = 1; break;
432      case 3: val = 0; break;
433   }
434
435   return val;
436}
437
438static WRITE8_HANDLER( mz2500_tv_crtc_w )
439{
309440   switch(offset)
310441   {
311442      case 0: text_reg_index = data; break;
312443      case 1:
313444         text_reg[text_reg_index] = data;
445         if(text_reg_index == 0x0a) // set 256 color palette
446         {
447            int i,r,g,b;
448            UINT8 b_param,r_param,g_param;
449
450            b_param = (data & 0x03) >> 0;
451            r_param = (data & 0x0c) >> 2;
452            g_param = (data & 0x30) >> 4;
453
454            for(i = 0;i < 0x100;i++)
455            {
456               int bit0,bit1,bit2;
457
458               bit0 = pal_256_param(i,b_param) ? 1 : 0;
459               bit1 = i & 0x01 ? 2 : 0;
460               bit2 = i & 0x10 ? 4 : 0;
461               b = bit0|bit1|bit2;
462               bit0 = pal_256_param(i,r_param) ? 1 : 0;
463               bit1 = i & 0x02 ? 2 : 0;
464               bit2 = i & 0x20 ? 4 : 0;
465               r = bit0|bit1|bit2;
466               bit0 = pal_256_param(i,g_param) ? 1 : 0;
467               bit1 = i & 0x04 ? 2 : 0;
468               bit2 = i & 0x40 ? 4 : 0;
469               g = bit0|bit1|bit2;
470
471               palette_set_color_rgb(space->machine, i+0x100,pal3bit(r),pal3bit(g),pal3bit(b));
472            }
473         }
314474         //printf("[%02x]<- %02x\n",text_reg[text_reg_index],text_reg_index);
315475         break;
316476      case 2: /* CG MASK reg */ break;
r8928r8929
492652
493653   crtc_reg[crtc_reg_index & 0x1f] = data;
494654
495   if((crtc_reg_index & 0x1f) == 0x08) //accessing vs lo reg clears vs hi reg
655   if((crtc_reg_index & 0x1f) == 0x08) //accessing VS LO reg clears VS HI reg
496656      crtc_reg[0x09] = 0;
497657
498   if((crtc_reg_index & 0x1f) == 0x0a) //accessing ve lo reg clears ve hi reg
658   if((crtc_reg_index & 0x1f) == 0x0a) //accessing VE LO reg clears VE HI reg
499659      crtc_reg[0x0b] = 0;
500660
501661   if(crtc_reg_index & 0x80) //enable auto-inc
r8928r8929
523683      hs = (crtc_reg[0x0c] & 0x7f)*8;
524684      he = (crtc_reg[0x0d] & 0x7f)*8;
525685
526      popmessage("%d %d %d %d %02x",vs,ve,hs,he,crtc_reg[0x0e]);
686//      popmessage("%d %d %d %d %02x",vs,ve,hs,he,crtc_reg[0x0e]);
527687
528688      space->machine->primary_screen->configure(720, 480, visarea, space->machine->primary_screen->frame_period().attoseconds); //TODO
529689   }
r8928r8929
538698   pit8253_gate0_w(pit8253, 0);
539699   pit8253_gate1_w(pit8253, 0);
540700   pit8253_gate0_w(pit8253, 1);
541   pit8253_gate1_w(pit8253, 1);   
701   pit8253_gate1_w(pit8253, 1);
542702}
543   
703
544704static ADDRESS_MAP_START(mz2500_io, ADDRESS_SPACE_IO, 8)
545705   ADDRESS_MAP_GLOBAL_MASK(0xff)
546706//  AM_RANGE(0x60, 0x63) AM_WRITE(w3100a_w)
r8928r8929
574734   AM_RANGE(0xea, 0xeb) AM_DEVREADWRITE("z80pio_1", z80pio_d_r, z80pio_d_w)
575735//  AM_RANGE(0xef, 0xef) AM_READWRITE(joystick_r,joystick_w)
576736    AM_RANGE(0xf0, 0xf3) AM_WRITE(timer_w)
577   AM_RANGE(0xf4, 0xf7) AM_READ(mz2500_crtc_hvblank_r) AM_WRITE(mz2500_txt_crtc_w)
737   AM_RANGE(0xf4, 0xf7) AM_READ(mz2500_crtc_hvblank_r) AM_WRITE(mz2500_tv_crtc_w)
578738//  AM_RANGE(0xf8, 0xf9) AM_READWRITE(extrom_r,extrom_w)
579739ADDRESS_MAP_END
580740
r8928r8929
9321092{
9331093   UINT8 *RAM = memory_region(machine, "maincpu");
9341094   UINT8 *IPL = memory_region(machine, "ipl");
935   int i;
1095   UINT32 i;
9361096
9371097   mz2500_reset(IPL_RESET);
9381098
9391099   //irq_vector[0] = 0xef; /* RST 28h - vblank */
9401100
941   text_col_size = 40;
1101   text_col_size = 0;
9421102   text_font_reg = 0;
9431103
9441104   /* copy IPL to its natural bank ROM/RAM position */
r8928r8929
9481108      RAM[i+0x68000] = IPL[i];
9491109   }
9501110
1111   /* clear CG RAM */
1112   for(i=0;i<0x20000;i++)
1113      RAM[i+0x40000] = 0x00;
1114
9511115   /* disable IRQ */
9521116   for(i=0;i<4;i++)
9531117      irq_mask[i] = 0;
r8928r8929
10831247static WRITE8_DEVICE_HANDLER( mz2500_pio1_porta_w )
10841248{
10851249//  printf("%02x\n",data);
1086   text_col_size = (data & 0x20) ? 80 : 40;
1250   text_col_size = (data & 0x20) ? 1 : 0;
10871251   key_mux = data & 0x1f;
10881252}
10891253
r8928r8929
11321296   ---- --x- floppy reverse bit (controls wd17xx bits in command registers)
11331297   */
11341298
1135   //printf("%02x\n",data);
1136   fdc_reverse = data & 2 ? 0x00 : 0xff;
1299//   printf("%02x\n",data);
1300   fdc_reverse = (data & 2) ? 0x00 : 0xff;
1301   pal_select = (data & 4) ? 1 : 0;
1302   if((data & 4) == 0)
1303      printf("Warning: 4096 color mode used\n");
11371304}
11381305
11391306static const ym2203_interface ym2203_interface_1 =
r8928r8929
12201387   MDRV_SOUND_ADD("ym", YM2203, 6000000/2) //unknown clock / divider
12211388   MDRV_SOUND_CONFIG(ym2203_interface_1)
12221389   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.60)
1223   
1390
12241391   MDRV_PIT8253_ADD("pit", mz2500_pit8253_intf)
12251392MACHINE_DRIVER_END
12261393

Previous 15994 Revisions Next


© 1998-2018 The MESS Team