Previous 15994 Revisions Next

r8931 Saturday 28th August, 2010 at 17:14:21 UTC by Angelo Salese
[MZ-2500]: More improvements, Penguin Kun-Wars is now playable too
[src/mess/drivers]mz2500.c

src/mess/drivers/mz2500.c
r8930r8931
66
77   TODO:
88   - floppy device;
9   - graphics are really a bare minimum, this thing is very complex;
9   - graphics are really a bare minimum, this system is very complex;
1010   - keyboard inputs (needs something that actually works);
1111
1212    memory map:
r8930r8931
4141static UINT8 kanji_bank;
4242static UINT8 fdc_reverse;
4343static UINT8 key_mux;
44static UINT8 crtc_reg_index;
45static UINT8 crtc_reg[0x20];
44static UINT8 cg_reg_index;
45static UINT8 cg_reg[0x20];
4646
4747#define WRAM_RESET 0
4848#define IPL_RESET 1
r8930r8931
6868   UINT8 *vram = memory_region(machine, "maincpu");
6969   int x,y,count,xi,yi;
7070   UINT8 *gfx_data;
71   UINT8 y_step;
7172
7273   count = 0x70000;
7374
74   for (y=0;y<25;y++)
75   y_step = (text_font_reg) ? 1 : 2;
76
77   for (y=0;y<25;y+=y_step)
7578   {
7679      for (x=0;x<80;x++)
7780      {
r8930r8931
8992
9093         tile|= tile_bank << 8;
9194
92         for(yi=0;yi<8;yi++)
95         for(yi=0;yi<8*y_step;yi++)
9396         {
9497            for(xi=0;xi<8;xi++)
9598            {
r8930r8931
121124   UINT8 *vram = memory_region(machine, "maincpu");
122125   int x,y,count,xi,yi;
123126   UINT8 *gfx_data;
127   UINT8 y_step;
124128
125129   count = 0x70000;
126130
127//   if(tv_mode != 1)
128//   popmessage("%02x %02x %02x",tv_mode,text_reg[1],text_reg[2]);
131   if(tv_mode != 1)
132      popmessage("%02x %02x %02x",tv_mode,text_reg[1],text_reg[2]);
129133
130   for (y=0;y<25;y++)
134   y_step = (text_font_reg) ? 1 : 2;
135
136   for (y=0;y<25;y+=y_step)
131137   {
132138      for (x=0;x<40;x++)
133139      {
r8930r8931
145151
146152         tile|= tile_bank << 8;
147153
148         for(yi=0;yi<8;yi++)
154         for(yi=0;yi<8*y_step;yi++)
149155         {
150156            for(xi=0;xi<8;xi++)
151157            {
r8930r8931
178184   if(text_col_size)
179185      draw_80x25(machine,bitmap,cliprect);
180186   else
181   {
182      //int tv_mode = (text_reg[0] & 0x0c) >> 2;
183187      draw_40x25(machine,bitmap,cliprect,text_reg[0] >> 2);
184   }
185188
186189   #if 0
187190   if(text_font_reg)
r8930r8931
230233   #endif
231234}
232235
233static void draw_cg16_screen(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect)
236static void draw_cg16_screen(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int plane,int x_size)
234237{
235238   static UINT32 count;
236239   UINT8 *vram = memory_region(machine, "maincpu");
237240   UINT8 pen,pen_bit[4];
238   int x,y,xi;
241   int x,y,xi,pen_i;
239242
240243   count = 0x40000;
241244
242245   for(y=0;y<200;y++)
243246   {
244      for(x=0;x<320;x+=8)
247      for(x=0;x<x_size;x+=8)
245248      {
246249         for(xi=0;xi<8;xi++)
247250         {
248            pen_bit[0] = (vram[count+0x0000]>>(xi)) & 1 ? 1 : 0;
249            pen_bit[1] = (vram[count+0x4000]>>(xi)) & 1 ? 2 : 0;
250            pen_bit[2] = (vram[count+0x8000]>>(xi)) & 1 ? 4 : 0;
251            pen_bit[3] = (vram[count+0xc000]>>(xi)) & 1 ? 0 : 8; //FIXME: this should be swapped
251            pen_bit[0] = (vram[count+0x0000 + plane*0x2000]>>(xi)) & 1 ? 1 : 0; //B
252            pen_bit[1] = (vram[count+0x4000 + plane*0x2000]>>(xi)) & 1 ? 2 : 0; //R
253            pen_bit[2] = (vram[count+0x8000 + plane*0x2000]>>(xi)) & 1 ? 4 : 0; //G
254            pen_bit[3] = (vram[count+0xc000 + plane*0x2000]>>(xi)) & 1 ? 0 : 8; //I FIXME: this should be swapped
252255
253            pen = pen_bit[0]|pen_bit[1]|pen_bit[2]|pen_bit[3];
256            pen = 0;
257            for(pen_i=0;pen_i<4;pen_i++)
258               pen |= pen_bit[pen_i];
254259
255260            if(pen != 8)
256261               *BITMAP_ADDR16(bitmap, y, x+xi) = machine->pens[pen+0x200];
r8930r8931
260265   }
261266}
262267
268/* TODO: this probably allocates CLUT to somewhere ... */
263269static void draw_cg256_screen(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect)
264270{
265271   static UINT32 count;
266272   UINT8 *vram = memory_region(machine, "maincpu");
267   UINT8 pen;
268   int x,y,xi;
273   UINT8 pen,pen_bit[8];
274   int x,y,xi,pen_i;
269275
270276   count = 0x40000;
271277
r8930r8931
275281      {
276282         for(xi=0;xi<8;xi++)
277283         {
278            pen = (vram[count]>>(xi)) & 1 ? 0xff : 0x00;
284            pen_bit[0] = (vram[count + 0x2000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x10) : 0; // B1
285            pen_bit[1] = (vram[count + 0x0000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x01) : 0; // B0
286            pen_bit[2] = (vram[count + 0x6000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x20) : 0; // R1
287            pen_bit[3] = (vram[count + 0x4000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x02) : 0; // R0
288            pen_bit[4] = (vram[count + 0xa000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x40) : 0; // G1
289            pen_bit[5] = (vram[count + 0x8000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x04) : 0; // G0
290            pen_bit[6] = (vram[count + 0xe000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x80) : 0; // I1
291            pen_bit[7] = (vram[count + 0xc000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x08) : 0; // I0
279292
293            pen = 0;
294            for(pen_i=0;pen_i<8;pen_i++)
295               pen |= pen_bit[pen_i];
296
280297            if(pen)
281298               *BITMAP_ADDR16(bitmap, y, x+xi) = machine->pens[pen+0x100];
282299         }
r8930r8931
287304
288305static VIDEO_UPDATE( mz2500 )
289306{
307   bitmap_fill(bitmap, cliprect, MAKE_ARGB(0xff,0x00,0x00,0x00));
308
290309   if(pal_select)
291   {
292310      draw_tv_screen(screen->machine,bitmap,cliprect);
293      draw_cg16_screen(screen->machine,bitmap,cliprect);
294   }
295311   else //4096 mode colors
296312   {
297313      // ...
298314   }
299315
300   if(crtc_reg[0x0e] == 0x1d)
301      draw_cg256_screen(screen->machine,bitmap,cliprect);
302316
317   switch(cg_reg[0x0e])
318   {
319      case 0x03: /* CG 4 color mode */ break;
320      case 0x14:
321         draw_cg16_screen(screen->machine,bitmap,cliprect,0,320);
322         draw_cg16_screen(screen->machine,bitmap,cliprect,1,320);
323         break;
324      case 0x15:
325         draw_cg16_screen(screen->machine,bitmap,cliprect,1,320);
326         draw_cg16_screen(screen->machine,bitmap,cliprect,0,320);
327         break;
328      case 0x17:
329         draw_cg16_screen(screen->machine,bitmap,cliprect,0,640);
330         break;
331      case 0x1d:
332         draw_cg256_screen(screen->machine,bitmap,cliprect);
333         break;
334   }
335
303336    return 0;
304337}
305338
r8930r8931
674707
675708*/
676709
710static READ8_HANDLER( mz2500_rplane_latch_r )
711{
712   if(cg_reg[0x07] & 0x10)
713   {
714      static UINT8 vblank_bit;
677715
678static WRITE8_HANDLER( mz2500_crtc_addr_w )
716      // ---- ---x clear flag
717      vblank_bit = space->machine->primary_screen->vblank() ? 0 : 0x80;
718
719      return vblank_bit;
720   }
721   else
722      return 0xff;
723}
724
725static WRITE8_HANDLER( mz2500_cg_addr_w )
679726{
680   crtc_reg_index = data;
727   cg_reg_index = data;
681728}
682729
683static WRITE8_HANDLER( mz2500_crtc_data_w )
730static WRITE8_HANDLER( mz2500_cg_data_w )
684731{
685   crtc_reg[crtc_reg_index & 0x1f] = data;
732   cg_reg[cg_reg_index & 0x1f] = data;
686733
687   if((crtc_reg_index & 0x1f) == 0x08) //accessing VS LO reg clears VS HI reg
688      crtc_reg[0x09] = 0;
734   if((cg_reg_index & 0x1f) == 0x08) //accessing VS LO reg clears VS HI reg
735      cg_reg[0x09] = 0;
689736
690   if((crtc_reg_index & 0x1f) == 0x0a) //accessing VE LO reg clears VE HI reg
691      crtc_reg[0x0b] = 0;
737   if((cg_reg_index & 0x1f) == 0x0a) //accessing VE LO reg clears VE HI reg
738      cg_reg[0x0b] = 0;
692739
693   if((crtc_reg_index & 0x1f) == 0x05) //clear bitmap buffer
740   if((cg_reg_index & 0x1f) == 0x05) //clear bitmap buffer
694741   {
695742      UINT32 i;
696743      UINT8 *vram = memory_region(space->machine, "maincpu");
697744
698745      /* TODO: this isn't yet 100% accurate */
699      if(crtc_reg[0x05] & 1)
746      if(cg_reg[0x05] & 1)
700747      {
701748         for(i=0;i<0x4000;i++)
702749            vram[i+0x40000] = 0x00; //clear B
703750      }
704      if(crtc_reg[0x05] & 2)
751      if(cg_reg[0x05] & 2)
705752      {
706753         for(i=0;i<0x4000;i++)
707754            vram[i+0x44000] = 0x00; //clear R
708755      }
709      if(crtc_reg[0x05] & 4)
756      if(cg_reg[0x05] & 4)
710757      {
711758         for(i=0;i<0x4000;i++)
712759            vram[i+0x48000] = 0x00; //clear G
713760      }
714      if(crtc_reg[0x05] & 8)
761      if(cg_reg[0x05] & 8)
715762      {
716763         for(i=0;i<0x4000;i++)
717764            vram[i+0x4c000] = 0x00; //clear I
718765      }
719766   }
720767
721   if(crtc_reg_index & 0x80) //enable auto-inc
722      crtc_reg_index = (crtc_reg_index & 0xfc) | ((crtc_reg_index + 1) & 0x03);
768   if(cg_reg_index & 0x80) //enable auto-inc
769      cg_reg_index = (cg_reg_index & 0xfc) | ((cg_reg_index + 1) & 0x03);
723770
724771   {
725772      static UINT16 vs,ve,hs,he;
726773      rectangle visarea;
727      static UINT16 x_size;
728774
729      if(crtc_reg[0x0e] == 0x15)
730         x_size = 640;
731      else if(crtc_reg[0x0e] == 0x17 || crtc_reg[0x0e] == 0x1d)
732         x_size = 320;
733      else
734         x_size = 640; // TODO
735
736775      visarea.min_x = 0;
737776      visarea.min_y = 0;
738      visarea.max_x = x_size - 1;
777      visarea.max_x = 640 - 1;
739778      visarea.max_y = 200 - 1;
740779
741      vs = (crtc_reg[0x08]) | ((crtc_reg[0x09]<<8) & 1);
742      ve = (crtc_reg[0x0a]) | ((crtc_reg[0x0b]<<8) & 1);
743      hs = (crtc_reg[0x0c] & 0x7f)*8;
744      he = (crtc_reg[0x0d] & 0x7f)*8;
780      vs = (cg_reg[0x08]) | ((cg_reg[0x09]<<8) & 1);
781      ve = (cg_reg[0x0a]) | ((cg_reg[0x0b]<<8) & 1);
782      hs = (cg_reg[0x0c] & 0x7f)*8;
783      he = (cg_reg[0x0d] & 0x7f)*8;
745784
746//      popmessage("%d %d %d %d %02x",vs,ve,hs,he,crtc_reg[0x0e]);
785//      popmessage("%d %d %d %d %02x",vs,ve,hs,he,cg_reg[0x0e]);
747786
748787      space->machine->primary_screen->configure(720, 480, visarea, space->machine->primary_screen->frame_period().attoseconds); //TODO
749788   }
r8930r8931
811850   AM_RANGE(0xb4, 0xb4) AM_READWRITE(mz2500_bank_addr_r,mz2500_bank_addr_w)
812851   AM_RANGE(0xb5, 0xb5) AM_READWRITE(mz2500_bank_data_r,mz2500_bank_data_w)
813852//  AM_RANGE(0xb8, 0xb9) AM_READWRITE(kanji_r,kanji_w)
814   AM_RANGE(0xbc, 0xbc) AM_WRITE(mz2500_crtc_addr_w)
815   AM_RANGE(0xbd, 0xbd) AM_WRITE(mz2500_crtc_data_w)
853   AM_RANGE(0xbc, 0xbc) AM_WRITE(mz2500_cg_addr_w)
854   AM_RANGE(0xbd, 0xbd) AM_READ(mz2500_rplane_latch_r) AM_WRITE(mz2500_cg_data_w)
816855//   AM_RANGE(0xbc, 0xbf) AM_READ(mz2500_crtc_cg_r) //reads plane
817856   AM_RANGE(0xc6, 0xc6) AM_WRITE(mz2500_irq_sel_w)
818857   AM_RANGE(0xc7, 0xc7) AM_WRITE(mz2500_irq_data_w)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team