Previous 15994 Revisions Next

r15897 Tuesday 14th August, 2012 at 16:08:32 UTC by Angelo Salese
State-ized various functions, and removed some supposedly left-over that was still used. Fixes N-88 Basic Nihongo cursor placement in 24 KHz mode
[src/mess/drivers]pc8801.c

src/mess/drivers/pc8801.c
r15896r15897
9494   - Explosion (fails to load ADPCM data?)
9595   - F-15 Strike Eagle
9696   - F2 Grand Prix ("Boot dekimasen")
97   (Fancy Promenade)
9798
98
9999    - Harakiri
100100    - Kaseijin (app) (code snippet is empty at some point)
101101    - MakaiMura (attempts to r/w the sio ports, but it's clearly crashed)
r15896r15897
256256   UINT8 inverse;
257257} crtc_t;
258258
259typedef struct
260{
261   UINT8 phase;
262   UINT8 x,y;
263   attotime time;
264} mouse_t;
265
259266class pc8801_state : public driver_device
260267{
261268public:
r15896r15897
315322   UINT8 m_has_cdrom;
316323   UINT8 m_cdrom_reg[0x10];
317324   crtc_t m_crtc;
325   mouse_t m_mouse;
318326   struct { UINT8 r, g, b; } m_palram[8];
319327   UINT8 m_dmac_ff;
320328   UINT32 m_knj_addr[2];
321   struct{
322      UINT8 phase;
323      UINT8 x,y;
324      attotime time;
325   }m_mouse;
329
326330   DECLARE_READ8_MEMBER(pc8801_alu_r);
327331   DECLARE_WRITE8_MEMBER(pc8801_alu_w);
328332   DECLARE_READ8_MEMBER(pc8801_wram_r);
r15896r15897
401405   DECLARE_WRITE8_MEMBER(pc8801_opna_w);
402406
403407   UINT8 pc8801_pixel_clock(void);
404};
408   void pc8801_dynamic_res_change(void);
409   void draw_bitmap_3bpp(bitmap_ind16 &bitmap,const rectangle &cliprect);
410   void draw_bitmap_1bpp(bitmap_ind16 &bitmap,const rectangle &cliprect);
411   UINT8 calc_cursor_pos(int x,int y,int yi);
412   UINT8 extract_text_attribute(UINT32 address,int x, UINT8 width, UINT8 &non_special);
413   void pc8801_draw_char(bitmap_ind16 &bitmap,int x,int y,int pal,UINT8 gfx_mode,UINT8 reverse,UINT8 secret,
414                          UINT8 blink,UINT8 upper,UINT8 lower,int y_size,int width, UINT8 non_special);
415   void draw_text(bitmap_ind16 &bitmap,int y_size, UINT8 width);
405416
417   UINT32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
406418
407static void pc8801_dynamic_res_change(running_machine &machine);
419protected:
408420
421   virtual void video_start();
422};
423
424
409425/*
410426CRTC command params:
4114270. CRTC reset
r15896r15897
430446[4] ---x xxxx attribute size (+1)
431447*/
432448
433#define screen_width ((state->m_crtc.param[0][0] & 0x7f) + 2) * 8
449#define screen_width ((m_crtc.param[0][0] & 0x7f) + 2) * 8
434450
435#define blink_speed ((((state->m_crtc.param[0][1] & 0xc0) >> 6) + 1) << 3)
436#define screen_height ((state->m_crtc.param[0][1] & 0x3f) + 1)
451#define blink_speed ((((m_crtc.param[0][1] & 0xc0) >> 6) + 1) << 3)
452#define screen_height ((m_crtc.param[0][1] & 0x3f) + 1)
437453
438#define lines_per_char ((state->m_crtc.param[0][2] & 0x1f) + 1)
454#define lines_per_char ((m_crtc.param[0][2] & 0x1f) + 1)
439455
440#define vretrace (((state->m_crtc.param[0][3] & 0xe0) >> 5) + 1)
441#define hretrace ((state->m_crtc.param[0][3] & 0x1f) + 2) * 8
456#define vretrace (((m_crtc.param[0][3] & 0xe0) >> 5) + 1)
457#define hretrace ((m_crtc.param[0][3] & 0x1f) + 2) * 8
442458
443#define text_color_flag ((state->m_crtc.param[0][4] & 0xe0) == 0x40)
444#define monitor_24KHz ((state->m_gfx_ctrl & 0x19) == 0x08) /* TODO: this is most likely to be WRONG */
459#define text_color_flag ((m_crtc.param[0][4] & 0xe0) == 0x40)
460//#define monitor_24KHz ((m_gfx_ctrl & 0x19) == 0x08) /* TODO: this is most likely to be WRONG */
445461
446static VIDEO_START( pc8801 )
462void pc8801_state::video_start()
447463{
448464
449465}
450466
451static void draw_bitmap_3bpp(running_machine &machine, bitmap_ind16 &bitmap,const rectangle &cliprect)
467void pc8801_state::draw_bitmap_3bpp(bitmap_ind16 &bitmap,const rectangle &cliprect)
452468{
453   pc8801_state *state = machine.driver_data<pc8801_state>();
454469   int x,y,xi;
455470   UINT32 count;
456   UINT8 *gvram = machine.root_device().memregion("gvram")->base();
471   UINT8 *gvram = machine().root_device().memregion("gvram")->base();
457472   UINT16 y_size;
458473   UINT16 y_double;
459474
460475   count = 0;
461476
462   y_double = (state->pc8801_pixel_clock());
477   y_double = (pc8801_pixel_clock());
463478   y_size = (y_double+1) * 200;
464479
465480   for(y=0;y<y_size;y+=(y_double+1))
r15896r15897
480495            if(y_double)
481496            {
482497               if(cliprect.contains(x+xi, y+0))
483                  bitmap.pix16(y+0, x+xi) = machine.pens[pen & 7];
498                  bitmap.pix16(y+0, x+xi) = machine().pens[pen & 7];
484499
485500               if(cliprect.contains(x+xi, y+1))
486                  bitmap.pix16(y+1, x+xi) = machine.pens[pen & 7];
501                  bitmap.pix16(y+1, x+xi) = machine().pens[pen & 7];
487502            }
488503            else
489504            {
490505               if(cliprect.contains(x+xi, y+0))
491                  bitmap.pix16(y, x+xi) = machine.pens[pen & 7];
506                  bitmap.pix16(y, x+xi) = machine().pens[pen & 7];
492507            }
493508         }
494509
r15896r15897
497512   }
498513}
499514
500static void draw_bitmap_1bpp(running_machine &machine, bitmap_ind16 &bitmap,const rectangle &cliprect)
515void pc8801_state::draw_bitmap_1bpp(bitmap_ind16 &bitmap,const rectangle &cliprect)
501516{
502   pc8801_state *state = machine.driver_data<pc8801_state>();
503517   int x,y,xi;
504518   UINT32 count;
505   UINT8 *gvram = state->memregion("gvram")->base();
519   UINT8 *gvram = machine().root_device().memregion("gvram")->base();
506520   UINT8 color;
507521
508522   count = 0;
509   color = (state->m_gfx_ctrl & 1) ? 7 & ((state->m_layer_mask ^ 0xe) >> 1) : 7;
523   color = (m_gfx_ctrl & 1) ? 7 & ((m_layer_mask ^ 0xe) >> 1) : 7;
510524
511525   for(y=0;y<200;y++)
512526   {
r15896r15897
518532
519533            pen = ((gvram[count+0x0000] >> (7-xi)) & 1) << 0;
520534
521            if((state->m_gfx_ctrl & 1))
535            if((m_gfx_ctrl & 1))
522536            {
523537               if(cliprect.contains(x+xi, y*2+0))
524                  bitmap.pix16(y*2+0, x+xi) = machine.pens[pen ? color : 0];
538                  bitmap.pix16(y*2+0, x+xi) = machine().pens[pen ? color : 0];
525539
526540               if(cliprect.contains(x+xi, y*2+1))
527                  bitmap.pix16(y*2+1, x+xi) = machine.pens[pen ? color : 0];
541                  bitmap.pix16(y*2+1, x+xi) = machine().pens[pen ? color : 0];
528542            }
529543            else
530544            {
531545               if(cliprect.contains(x+xi, y))
532                  bitmap.pix16(y, x+xi) = machine.pens[pen ? color : 0];
546                  bitmap.pix16(y, x+xi) = machine().pens[pen ? color : 0];
533547            }
534548         }
535549
r15896r15897
537551      }
538552   }
539553
540   if(!(state->m_gfx_ctrl & 1)) // 400 lines
554   if(!(m_gfx_ctrl & 1)) // 400 lines
541555   {
542556      count = 0;
543557
r15896r15897
552566               pen = ((gvram[count+0x4000] >> (7-xi)) & 1) << 0;
553567
554568               if(cliprect.contains(x+xi, y))
555                  bitmap.pix16(y, x+xi) = machine.pens[pen ? 7 : 0];
569                  bitmap.pix16(y, x+xi) = machine().pens[pen ? 7 : 0];
556570            }
557571
558572            count++;
r15896r15897
561575   }
562576}
563577
564static UINT8 calc_cursor_pos(running_machine &machine,int x,int y,int yi)
578UINT8 pc8801_state::calc_cursor_pos(int x,int y,int yi)
565579{
566   pc8801_state *state = machine.driver_data<pc8801_state>();
567
568   if(!(state->m_crtc.cursor_on)) // don't bother if cursor is off
580   if(!(m_crtc.cursor_on)) // don't bother if cursor is off
569581      return 0;
570582
571   if(x == state->m_crtc.param[4][0] && y == state->m_crtc.param[4][1]) /* check if position matches */
583   if(x == m_crtc.param[4][0] && y == m_crtc.param[4][1]) /* check if position matches */
572584   {
573585      /* don't pass through if we are using underscore */
574      if((!(state->m_crtc.param[0][2] & 0x40)) && yi != 7)
586      if((!(m_crtc.param[0][2] & 0x40)) && yi != 7)
575587         return 0;
576588
577589      /* finally check if blinking is currently active high */
578      if(!(state->m_crtc.param[0][2] & 0x20))
590      if(!(m_crtc.param[0][2] & 0x20))
579591         return 1;
580592
581      if(((machine.primary_screen->frame_number() / blink_speed) & 1) == 0)
593      if(((machine().primary_screen->frame_number() / blink_speed) & 1) == 0)
582594         return 1;
583595
584596      return 0;
r15896r15897
589601
590602
591603
592static UINT8 extract_text_attribute(running_machine &machine,UINT32 address,int x, UINT8 width, UINT8 &non_special)
604UINT8 pc8801_state::extract_text_attribute(UINT32 address,int x, UINT8 width, UINT8 &non_special)
593605{
594   pc8801_state *state = machine.driver_data<pc8801_state>();
595   UINT8 *vram = state->memregion("wram")->base();
606   UINT8 *vram = machine().root_device().memregion("wram")->base();
596607   int i;
597608   int fifo_size;
598609   int offset;
599610
600611   non_special = 0;
601   if(state->m_crtc.param[0][4] & 0x80)
612   if(m_crtc.param[0][4] & 0x80)
602613   {
603614      popmessage("Using non-separate mode for text tilemap, contact MESSdev");
604615      return 0;
605616   }
606617
607   fifo_size = (state->m_crtc.param[0][4] & 0x20) ? 0 : ((state->m_crtc.param[0][4] & 0x1f) + 1);
618   fifo_size = (m_crtc.param[0][4] & 0x20) ? 0 : ((m_crtc.param[0][4] & 0x1f) + 1);
608619
609620   if(fifo_size == 0)
610621   {
r15896r15897
628639   return vram[address-3+offset];
629640}
630641
631static void pc8801_draw_char(running_machine &machine,bitmap_ind16 &bitmap,int x,int y,int pal,UINT8 gfx_mode,UINT8 reverse,UINT8 secret,UINT8 blink,UINT8 upper,UINT8 lower,int y_size,int height,int width, UINT8 non_special)
642void pc8801_state::pc8801_draw_char(bitmap_ind16 &bitmap,int x,int y,int pal,UINT8 gfx_mode,UINT8 reverse,UINT8 secret,UINT8 blink,UINT8 upper,UINT8 lower,int y_size,int width, UINT8 non_special)
632643{
633   pc8801_state *state = machine.driver_data<pc8801_state>();
634644   int xi,yi;
635   UINT8 *vram = state->memregion("wram")->base();
636   UINT8 *gfx_rom = machine.root_device().memregion("gfx1")->base();
645   UINT8 *vram = machine().root_device().memregion("wram")->base();
646   UINT8 *gfx_rom = machine().root_device().memregion("gfx1")->base();
637647   UINT8 is_cursor;
638648   UINT8 y_height, y_double;
639649   UINT8 y_step;
640650
641651   y_height = lines_per_char;
642   y_double = (state->pc8801_pixel_clock());
652   y_double = (pc8801_pixel_clock());
643653   y_step = (non_special) ? 80 : 120; // trusted by Elthlead
644654
645655   for(yi=0;yi<y_height;yi++)
646656   {
647      is_cursor = calc_cursor_pos(machine,x,y,yi);
657      is_cursor = calc_cursor_pos(x,y,yi);
648658
649659      for(xi=0;xi<8;xi++)
650660      {
r15896r15897
653663         int color;
654664
655665         {
656            tile = vram[x+(y*y_step)+state->m_dma_address[2]];
666            tile = vram[x+(y*y_step)+m_dma_address[2]];
657667
658668            res_x = x*8+xi*(width+1);
659            res_y = y*y_height*(height+1)+yi*(height+1);
669            res_y = y*y_height+yi;
660670
661            if(!machine.primary_screen->visible_area().contains(res_x, res_y))
671            if(!machine().primary_screen->visible_area().contains(res_x, res_y))
662672               continue;
663673
664674            if(gfx_mode)
r15896r15897
675685               UINT8 blink_mask;
676686
677687               blink_mask = 0;
678               if(blink && ((machine.primary_screen->frame_number() / blink_speed) & 3) == 1)
688               if(blink && ((machine().primary_screen->frame_number() / blink_speed) & 3) == 1)
679689                  blink_mask = 1;
680690
681691               if(yi >= (1 << (y_double+3)) || secret || blink_mask)
r15896r15897
699709            }
700710
701711            if(color != -1)
702               bitmap.pix16(res_y, res_x) = machine.pens[color];
703
704            if(width)
705712            {
706               if(!machine.primary_screen->visible_area().contains(res_x+1, res_y))
707                  continue;
713               bitmap.pix16(res_y, res_x) = machine().pens[color];
714               if(width)
715               {
716                  if(!machine().primary_screen->visible_area().contains(res_x+1, res_y))
717                     continue;
708718
709               if(color != -1)
710                  bitmap.pix16(res_y, res_x+1) = machine.pens[color];
719                  bitmap.pix16(res_y, res_x+1) = machine().pens[color];
720               }
711721            }
712            if(height)
713            {
714               if(!machine.primary_screen->visible_area().contains(res_x, res_y+1))
715                  continue;
716
717               if(color != -1)
718                  bitmap.pix16(res_y+1, res_x) = machine.pens[color];
719
720               if(!machine.primary_screen->visible_area().contains(res_x+1, res_y+1))
721                  continue;
722
723               if(color != -1)
724                  bitmap.pix16(res_y+1, res_x+1) = machine.pens[color];
725            }
726722         }
727723      }
728724   }
729725}
730726
731static void draw_text(running_machine &machine, bitmap_ind16 &bitmap,int y_size, UINT8 width)
727void pc8801_state::draw_text(bitmap_ind16 &bitmap,int y_size, UINT8 width)
732728{
733   pc8801_state *state = machine.driver_data<pc8801_state>();
734729   int x,y;
735730   UINT8 attr;
736731   UINT8 reverse;
r15896r15897
749744         if(x & 1 && !width)
750745            continue;
751746
752         attr = extract_text_attribute(machine,(((y*120)+80+state->m_dma_address[2]) & 0xffff),(x),width,non_special);
747         attr = extract_text_attribute((((y*120)+80+m_dma_address[2]) & 0xffff),(x),width,non_special);
753748
754749         if(text_color_flag && (attr & 8)) // color mode
755750         {
r15896r15897
772767            lower = (attr & 0x20) >> 5;
773768            blink = (attr & 2) >> 1;
774769            pal|=8; //text pal bank
775            reverse ^= state->m_crtc.inverse;
770            reverse ^= m_crtc.inverse;
776771
777772            if(attr & 0x80)
778773               popmessage("Warning: mono gfx mode enabled, contact MESSdev");
779774
780775         }
781776
782         pc8801_draw_char(machine,bitmap,x,y,pal,gfx_mode,reverse,secret,blink,upper,lower,y_size,monitor_24KHz,!width,non_special);
777         pc8801_draw_char(bitmap,x,y,pal,gfx_mode,reverse,secret,blink,upper,lower,y_size,!width,non_special);
783778      }
784779   }
785780}
786781
787static SCREEN_UPDATE_IND16( pc8801 )
782UINT32 pc8801_state::screen_update( screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect )
788783{
789   pc8801_state *state = screen.machine().driver_data<pc8801_state>();
790784   bitmap.fill(screen.machine().pens[0], cliprect);
791785
792//   popmessage("%04x %04x %02x",state->m_dma_address[2],state->m_dma_counter[2],state->m_dmac_mode);
786//   popmessage("%04x %04x %02x",m_dma_address[2],m_dma_counter[2],m_dmac_mode);
793787
794   if(state->m_gfx_ctrl & 8)
788   if(m_gfx_ctrl & 8)
795789   {
796      if(state->m_gfx_ctrl & 0x10)
797         draw_bitmap_3bpp(screen.machine(),bitmap,cliprect);
790      if(m_gfx_ctrl & 0x10)
791         draw_bitmap_3bpp(bitmap,cliprect);
798792      else
799         draw_bitmap_1bpp(screen.machine(),bitmap,cliprect);
793         draw_bitmap_1bpp(bitmap,cliprect);
800794   }
801795
802796   //popmessage("%02x %02x %02x %02x %02x",state->m_layer_mask,state->m_dmac_mode,state->m_crtc.status,state->m_crtc.irq_mask,state->m_gfx_ctrl);
803797
804   if(!(state->m_layer_mask & 1) && state->m_dmac_mode & 4 && state->m_crtc.status & 0x10 && state->m_crtc.irq_mask == 3)
798   if(!(m_layer_mask & 1) && m_dmac_mode & 4 && m_crtc.status & 0x10 && m_crtc.irq_mask == 3)
805799   {
806      //popmessage("%02x %02x",state->m_crtc.param[0][0],state->m_crtc.param[0][4]);
800      //popmessage("%02x %02x",m_crtc.param[0][0],m_crtc.param[0][4]);
807801
808      draw_text(screen.machine(),bitmap,screen_height,state->m_txt_width);
802      draw_text(bitmap,screen_height,m_txt_width);
809803   }
810804
811805   return 0;
r15896r15897
11881182   return (ysize >= 400);
11891183}
11901184
1191static void pc8801_dynamic_res_change(running_machine &machine)
1185void pc8801_state::pc8801_dynamic_res_change(void)
11921186{
1193   pc8801_state *state = machine.driver_data<pc8801_state>();
11941187   rectangle visarea;
11951188   int xsize,ysize,xvis,yvis;
11961189   attoseconds_t refresh;;
11971190
11981191   /* bail out if screen params aren't valid */
1199   if(!state->m_crtc.param[0][0] || !state->m_crtc.param[0][1] || !state->m_crtc.param[0][2] || !state->m_crtc.param[0][3])
1192   if(!m_crtc.param[0][0] || !m_crtc.param[0][1] || !m_crtc.param[0][2] || !m_crtc.param[0][3])
12001193      return;
12011194
12021195   xvis = screen_width;
r15896r15897
12071200//   popmessage("H %d V %d (%d x %d) HR %d VR %d (%d %d)\n",xvis,yvis,screen_height,lines_per_char,hretrace,vretrace, xsize,ysize);
12081201
12091202   visarea.set(0, xvis - 1, 0, yvis - 1);
1210   if(state->pc8801_pixel_clock())
1203   if(pc8801_pixel_clock())
12111204      refresh = HZ_TO_ATTOSECONDS(PIXEL_CLOCK_24KHz) * (xsize) * ysize;
12121205   else
12131206      refresh = HZ_TO_ATTOSECONDS(PIXEL_CLOCK_15KHz) * (xsize) * ysize;
12141207
1215   machine.primary_screen->configure(xsize, ysize, visarea, refresh);
1208   machine().primary_screen->configure(xsize, ysize, visarea, refresh);
12161209}
12171210
12181211WRITE8_MEMBER(pc8801_state::pc8801_gfx_ctrl_w)
r15896r15897
12281221
12291222   m_gfx_ctrl = data;
12301223
1231   pc8801_dynamic_res_change(machine());
1224   pc8801_dynamic_res_change();
12321225}
12331226
12341227READ8_MEMBER(pc8801_state::pc8801_vram_select_r)
r15896r15897
13961389   {
13971390      m_crtc.param[m_crtc.cmd][m_crtc.param_count] = data;
13981391      if(m_crtc.cmd == 0)
1399         pc8801_dynamic_res_change(machine());
1392         pc8801_dynamic_res_change();
14001393
14011394      m_crtc.param_count++;
14021395   }
r15896r15897
18421835
18431836static TIMER_CALLBACK( pc8801fd_upd765_tc_to_zero )
18441837{
1845//  pc88va_state *state = machine.driver_data<pc88va_state>();
1838//  pc8801_state *state = machine.driver_data<pc8801_state>();
18461839
18471840   //printf("0\n");
18481841   upd765_tc_w(machine.device("upd765"), 0);
r15896r15897
26602653   /* video hardware */
26612654   MCFG_SCREEN_ADD("screen", RASTER)
26622655   MCFG_SCREEN_RAW_PARAMS(PIXEL_CLOCK_24KHz,848,0,640,448,0,400)
2663   MCFG_SCREEN_UPDATE_STATIC(pc8801)
2656   MCFG_SCREEN_UPDATE_DRIVER(pc8801_state, screen_update)
26642657
26652658   MCFG_GFXDECODE( pc8801 )
26662659   MCFG_PALETTE_LENGTH(0x10)
26672660   MCFG_PALETTE_INIT( pc8801 )
26682661
2669   MCFG_VIDEO_START(pc8801)
2662//   MCFG_VIDEO_START(pc8801)
26702663
26712664   /* sound hardware */
26722665   MCFG_SPEAKER_STANDARD_MONO("mono")

Previous 15994 Revisions Next


© 1998-2018 The MESS Team