Previous 199869 Revisions Next

r21564 Monday 4th March, 2013 at 13:07:08 UTC by David Haywood
misc refactor for future work
[src/mame/drivers]gunpey.c

trunk/src/mame/drivers/gunpey.c
r21563r21564
224224   UINT16 m_vram_bank;
225225   UINT16 m_vreg_addr;
226226
227   //UINT16 main_vram[0x800][0x800];
227   UINT8* m_blit_rom;
228   UINT8* m_vram;
229
230   // work variables for the decompression
231   int m_srcx;
232   int m_srcxbase;
233   int m_scrxcount;
234   int m_srcy;
235   int m_srcycount;
236   UINT8 m_sourcewide;
237   int m_ysize;
238   int m_xsize;
239   int m_dstx;
240   int m_dsty;
241   int m_dstxbase;
242   int m_dstxcount;
243   int m_dstycount;
244
245   int m_latched_bits_left;
246   UINT8 m_latched_byte;
247   int m_zero_bit_count;
248
249   void get_stream_next_byte(void);
250   int get_steam_bit(void);
251   UINT32 gunpey_state_get_stream_bits(int bits);
252
253   int write_dest_byte(UINT8 usedata);
254   //UINT16 main_m_vram[0x800][0x800];
228255};
229256
230257
r21563r21564
238265   int x,y;
239266   int bpp_sel;
240267   int color;
241   UINT8 *vram = memregion("vram")->base();
242268
243269   // there doesn't seem to be a specific bit to mark compressed sprites (we currently have a hack to look at the first byte of the data)
244270   // do they get decompressed at blit time instead? of are there other registers we need to look at
r21563r21564
291317   //   xsource<<=1;
292318   //   ysource <<=2;
293319
294//      UINT8 testhack = vram[((((ysource+0)&0x7ff)*0x800) + ((xsource+0)&0x7ff))];
295//      UINT8 testhack2 = vram[((((ysource+0)&0x7ff)*0x800) + ((xsource+1)&0x7ff))];
320//      UINT8 testhack = m_vram[((((ysource+0)&0x7ff)*0x800) + ((xsource+0)&0x7ff))];
321//      UINT8 testhack2 = m_vram[((((ysource+0)&0x7ff)*0x800) + ((xsource+1)&0x7ff))];
296322
297323      //if (m_wram[count+1] & 0x0010)
298324      //   color =  machine.rand()&0xf;
r21563r21564
330356         {
331357            for(int xi=0;xi<sourcewidth/2;xi++)
332358            {
333               UINT8 data = vram[((((ysource+yi)&0x7ff)*0x800) + ((xsource+xi)&0x7ff))];
359               UINT8 data = m_vram[((((ysource+yi)&0x7ff)*0x800) + ((xsource+xi)&0x7ff))];
334360               UINT8 pix;
335361               UINT32 col_offs;
336362               UINT16 color_data;
r21563r21564
338364               pix = (data & 0x0f);
339365               col_offs = ((pix + color*0x10) & 0xff) << 1;
340366               col_offs+= ((pix + color*0x10) >> 8)*0x800;
341               color_data = (vram[col_offs])|(vram[col_offs+1]<<8);
367               color_data = (m_vram[col_offs])|(m_vram[col_offs+1]<<8);
342368
343369               if(!(color_data & 0x8000))
344370               {
r21563r21564
366392               pix = (data & 0xf0)>>4;
367393               col_offs = ((pix + color*0x10) & 0xff) << 1;
368394               col_offs+= ((pix + color*0x10) >> 8)*0x800;
369               color_data = (vram[col_offs])|(vram[col_offs+1]<<8);
395               color_data = (m_vram[col_offs])|(m_vram[col_offs+1]<<8);
370396
371397               if(!(color_data & 0x8000))
372398               {
r21563r21564
401427         {
402428            for(int xi=0;xi<sourcewidth;xi++)
403429            {
404               UINT8 data = vram[((((ysource+yi)&0x7ff)*0x800) + ((xsource+xi)&0x7ff))];
430               UINT8 data = m_vram[((((ysource+yi)&0x7ff)*0x800) + ((xsource+xi)&0x7ff))];
405431               UINT8 pix;
406432               UINT32 col_offs;
407433               UINT16 color_data;
r21563r21564
419445         {
420446            for(int xi=0;xi<sourcewidth;xi++)
421447            {
422               UINT8 data = vram[((((ysource+yi)&0x7ff)*0x800) + ((xsource+xi)&0x7ff))];
448               UINT8 data = m_vram[((((ysource+yi)&0x7ff)*0x800) + ((xsource+xi)&0x7ff))];
423449               UINT8 pix;
424450               UINT32 col_offs;
425451               UINT16 color_data;
r21563r21564
427453               pix = (data & 0xff);
428454               col_offs = ((pix + color*0x100) & 0xff) << 1;
429455               col_offs+= ((pix + color*0x100) >> 8)*0x800;
430               color_data = (vram[col_offs])|(vram[col_offs+1]<<8);
456               color_data = (m_vram[col_offs])|(m_vram[col_offs+1]<<8);
431457
432458               if(!(color_data & 0x8000))
433459               {
r21563r21564
565591   gunpey_irq_check(4);
566592}
567593
594void gunpey_state::get_stream_next_byte(void)
595{
596   // check if we need to move on to the next row of the source bitmap
597   // to get the data requested
598   if (m_scrxcount==m_sourcewide)
599   {
600      m_scrxcount = 0;
601      m_srcx = m_srcxbase;
602      m_srcy++; m_srcycount++;
603   }
604
605   m_latched_byte = m_blit_rom[(((m_srcy)&0x7ff)*0x800)+((m_srcx)&0x7ff)];
606   m_latched_bits_left = 8;
607
608   // increase counters
609   m_srcx++; m_scrxcount++;
610}
611
612int gunpey_state::get_steam_bit(void)
613{
614   if (m_latched_bits_left==0)
615   {
616      get_stream_next_byte();
617   }
618
619   m_latched_bits_left--;
620
621   int bit = (m_latched_byte >> (7-m_latched_bits_left))&1;
622   
623   if (bit==0) m_zero_bit_count++;
624   else m_zero_bit_count=0;
625
626   return bit;
627}
628
629UINT32 gunpey_state::gunpey_state_get_stream_bits(int bits)
630{
631   UINT32 output = 0;
632   for (int i=0;i<bits;i++)
633   {
634      output = output<<1;
635      output |= get_steam_bit();
636   }
637
638   return output;
639}
640
641int gunpey_state::write_dest_byte(UINT8 usedata)
642{
643   // write the byte we and to destination and increase our counters
644   m_vram[(((m_dsty)&0x7ff)*0x800)+((m_dstx)&0x7ff)] = usedata;
645
646   // increase destination counter and check if we've filled our destination rectangle
647   m_dstx++; m_dstxcount++;
648   if (m_dstxcount==m_xsize)
649   {
650      m_dstxcount = 0;
651      m_dstx = m_dstxbase;
652      m_dsty++; m_dstycount++;
653      if (m_dstycount==m_ysize)
654      {
655         return -1;
656      }
657   }
658
659   return 1;
660}
661
662
568663//#define SHOW_COMPRESSED_DATA_DEBUG
569664
665
666
570667WRITE8_MEMBER(gunpey_state::gunpey_blitter_w)
571668{
572669//   UINT16 *blit_buffer = m_blit_buffer;
573670   UINT16 *blit_ram = m_blit_ram;
574   UINT8 *blit_rom = memregion("blit_data")->base();
575   UINT8 *vram = memregion("vram")->base();
576671
672
577673   //   int x,y;
578674
579675   //printf("gunpey_blitter_w offset %01x data %02x\n", offset,data);
r21563r21564
582678
583679   if(offset == 0 && data == 2) // blitter trigger, 0->1 transition
584680   {
585      int srcx = blit_ram[0x04]+(blit_ram[0x05]<<8);
586      int srcy = blit_ram[0x06]+(blit_ram[0x07]<<8);
587      int dstx = blit_ram[0x08]+(blit_ram[0x09]<<8);
588      int dsty = blit_ram[0x0a]+(blit_ram[0x0b]<<8);
589      int xsize = blit_ram[0x0c]+1;
590      int ysize = blit_ram[0x0e]+1;
681      m_srcx = blit_ram[0x04]+(blit_ram[0x05]<<8);
682      m_srcy = blit_ram[0x06]+(blit_ram[0x07]<<8);
683      m_dstx = blit_ram[0x08]+(blit_ram[0x09]<<8);
684      m_dsty = blit_ram[0x0a]+(blit_ram[0x0b]<<8);
685      m_xsize = blit_ram[0x0c]+1;
686      m_ysize = blit_ram[0x0e]+1;
591687      int rle = blit_ram[0x01];
592688//      int color,color_offs;
593689
r21563r21564
596692      ,blit_ram[0],blit_ram[1],blit_ram[2],blit_ram[3]
597693
598694
599      ,blit_ram[4],blit_ram[5], srcx
600      ,blit_ram[6],blit_ram[7], srcy
695      ,blit_ram[4],blit_ram[5], m_srcx
696      ,blit_ram[6],blit_ram[7], m_srcy
601697
602      ,blit_ram[8],blit_ram[9], dstx
603      ,blit_ram[0xa],blit_ram[0xb], dsty
698      ,blit_ram[8],blit_ram[9], m_dstx
699      ,blit_ram[0xa],blit_ram[0xb], m_dsty
604700       ,blit_ram[0xc],
605701
606702         blit_ram[0xd],blit_ram[0xe],blit_ram[0xf]);
607703*/
608      //if (srcx & 0xf800) printf("(error srcx &0xf800)");
609      //if (srcy & 0xf800) printf("(error srcy &0xf800)");
704      //if (m_srcx & 0xf800) printf("(error m_srcx &0xf800)");
705      //if (m_srcy & 0xf800) printf("(error m_srcy &0xf800)");
610706
611707      // these are definitely needed for 4bpp..
612      dstx<<=1;
613      xsize<<=1;
708      m_dstx<<=1;
709      m_xsize<<=1;
614710
615711
616712      //int color = space.machine().rand()&0x1f;
r21563r21564
652748
653749*/
654750
751
655752      if(rle)
656753      {
657754         if(rle == 8)
r21563r21564
672769            const int show_bytes = 0;
673770            int bitspacer = 0;
674771            int bitspace = 9;
772            int linespacer = 0;
675773#endif
676774
677775           
678            int dstxbase = dstx;
679            int dstwcount = 0;
680            int dstycount = 0;
681            int srcxbase = srcx;
682            int srcwcount = 0;
683            int srcycount = 0;
776            m_dstxbase = m_dstx;
777            m_dstxcount = 0;
778            m_dstycount = 0;
779            m_srcxbase = m_srcx;
780            m_scrxcount = 0;
781            m_srcycount = 0;
684782
685            UINT8 sourcewide = blit_rom[(((srcy)&0x7ff)*0x800)+((srcx)&0x7ff)];
686            srcx++;srcwcount++; // we don't want to decode the width as part of the data stream..     
687            UINT8 lastdata = 0xff; // hack so we can bail when we appear to have run out of compressed data
783            m_sourcewide = m_blit_rom[(((m_srcy)&0x7ff)*0x800)+((m_srcx)&0x7ff)]+1;
784            m_srcx++;m_scrxcount++; // we don't want to decode the width as part of the data stream..     
785            m_latched_bits_left = 0;
786            m_zero_bit_count = 0;
787
788            int lastdata = 0xff; // hack so we can bail when we appear to have run out of compressed data
688789            bool out_of_data = false;
689790
690791            for (;;)
691792            {
692               UINT8 data = blit_rom[(((srcy)&0x7ff)*0x800)+((srcx)&0x7ff)];
693793               
794               int data = gunpey_state_get_stream_bits(8);
795               
694796               // hack, really I imagine there is exactly enough compressed data to fill the dest bitmap area when decompressed, but to stop us
695797               // overrunning into reading other data we terminate on a 0000, which doesn't seem likely to be compressed data.
696798               if (data==0x00 && lastdata == 0x00)
r21563r21564
698800
699801               lastdata = data;
700802
803
804               UINT8 usedata = 0xff;
701805               if (!out_of_data)
702806               {
703807                  #ifdef SHOW_COMPRESSED_DATA_DEBUG
704                  if (count<256)
705                  {               
808                  if (count<512)
809                  {           
810                     
811
706812                     if (show_bytes)
707813                     {
708814                        printf("%02x ", data);
709815                     }
710816                     else
711817                     {
712                        //data = BITSWAP8(data,7,6,5,4,3,2,1,0);
713                        data = BITSWAP8(data,0,1,2,3,4,5,6,7);
714818                        for (int z=0;z<8;z++)
715819                        {
716820                           printf("%d", (data>>(7-z))&1);
717821                           bitspacer++;
718822                           if (bitspacer == bitspace)
719823                           {
824                              linespacer++;
825                              if ((linespacer%16) == 0) printf("\n");
826                             
720827                              printf(" ");
721828                              bitspacer = 0;
722829                           }
r21563r21564
726833                  }
727834                  #endif
728835
729                  vram[(((dsty)&0x7ff)*0x800)+((dstx)&0x7ff)] = data;
836                  usedata = data;
730837               }
731838               else
732                  vram[(((dsty)&0x7ff)*0x800)+((dstx)&0x7ff)] = 0x44;
839                  usedata = 0x44;
733840
734               // increase our source counter, taking note of the width of the compressed data in
735               // source (it differs from the destination width)
736               srcx++; srcwcount++;
737               if (srcwcount==sourcewide+1)
738               {
739                  srcwcount = 0;
740                  srcx = srcxbase;
741                  srcy++; srcycount++;
742               }
841               if ((write_dest_byte(usedata))==-1)
842                  break;
743843
744               // increase destination counter and check if we've filled our destination rectangle
745               dstx++; dstwcount++;
746               if (dstwcount==xsize)
747               {
748                  dstwcount = 0;
749                  dstx = dstxbase;
750                  dsty++; dstycount++;
751                  if (dstycount==ysize)
752                  {
753                     break;
754                  }
755               }
756844            }
757845
758846#ifdef SHOW_COMPRESSED_DATA_DEBUG
r21563r21564
765853      }
766854      else
767855      {
768         int dstxbase = dstx;
769         int dstwcount = 0;
770         int dstycount = 0;
771         int srcxbase = srcx;
772         int srcwcount = 0;
773         int srcycount = 0;
856         m_dstxbase = m_dstx;
857         m_dstxcount = 0;
858         m_dstycount = 0;
859         m_srcxbase = m_srcx;
860         m_scrxcount = 0;
861         m_srcycount = 0;
774862
775863         for (;;)
776864         {
777            UINT8 data = blit_rom[(((srcy)&0x7ff)*0x800)+((srcx)&0x7ff)];
778            vram[(((dsty)&0x7ff)*0x800)+((dstx)&0x7ff)] = data;
865            UINT8 usedata = m_blit_rom[(((m_srcy)&0x7ff)*0x800)+((m_srcx)&0x7ff)];
779866
780            srcx++; srcwcount++;
781            if (srcwcount==xsize)
867            m_srcx++; m_scrxcount++;
868            if (m_scrxcount==m_xsize)
782869            {
783               srcwcount = 0;
784               srcx = srcxbase;
785               srcy++; srcycount++;
870               m_scrxcount = 0;
871               m_srcx = m_srcxbase;
872               m_srcy++; m_srcycount++;
786873            }
787874
788            // increase destination counter and check if we've filled our destination rectangle
789            dstx++; dstwcount++;
790            if (dstwcount==xsize)
791            {
792               dstwcount = 0;
793               dstx = dstxbase;
794               dsty++; dstycount++;
795               if (dstycount==ysize)
796               {
797                  break;
798               }
799            }
875            if ((write_dest_byte(usedata))==-1)
876               break;
800877         }
801878      }
802879
803      machine().scheduler().timer_set(m_maincpu->cycles_to_attotime(xsize*ysize), timer_expired_delegate(FUNC(gunpey_state::blitter_end),this));
880      machine().scheduler().timer_set(m_maincpu->cycles_to_attotime(m_xsize*m_ysize), timer_expired_delegate(FUNC(gunpey_state::blitter_end),this));
804881
805882
806883/*
r21563r21564
10631140
10641141DRIVER_INIT_MEMBER(gunpey_state,gunpey)
10651142{
1143
1144   m_blit_rom = memregion("blit_data")->base();
1145   m_vram = memregion("vram")->base();
10661146   // ...
10671147}
10681148

Previous 199869 Revisions Next


© 1997-2024 The MAME Team