Previous 15994 Revisions Next

r6728 Thursday 24th December, 2009 at 08:53:29 UTC by Barry Rodewald
[FMTOWNS] Implemented sprite flipping.
[src/mess/video]fmtowns.c

src/mess/video/fmtowns.c
r6727r6728
612612 *       +2: Y position (10-bit)
613613 *       +4: Sprite Attribute
614614 *          bit 15: enforce offsets (regs 2-5)
615 *          bit 12,13: flip sprite
615616 *          bits 10-0: Sprite RAM offset containing sprite pattern
616617 *          TODO: other attributes (zoom?)
617618 *       +6: Sprite Colour
618619 *          bit 15: use colour data in located in sprite RAM offset in bits 11-0 (x32)
619620 */
620void render_sprite_4(bitmap_t* bitmap, UINT32 poffset, UINT32 coffset, UINT16 x, UINT16 y, const rectangle* rect)
621void render_sprite_4(bitmap_t* bitmap, UINT32 poffset, UINT32 coffset, UINT16 x, UINT16 y, UINT16 xflip, UINT16 yflip, const rectangle* rect)
621622{
622623   UINT16 xpos,ypos;
623624   UINT16 col,pixel;
624625   UINT32 voffset;
626   int xstart,xend,xdir,ystart,yend,ydir;
625627   
626   for(ypos=y;ypos<y+16;ypos++)
628   if(xflip)
627629   {
628      for(xpos=x;xpos<x+16;xpos+=2)
630      xstart = x+16;
631      xend = x;
632      xdir = -2;
633   }
634   else
635   {
636      xstart = x;
637      xend = x+16;
638      xdir = 2;
639   }
640   if(yflip)
641   {
642      ystart = y+16;
643      yend = y;
644      ydir = -1;
645   }
646   else
647   {
648      ystart = y;
649      yend = y+16;
650      ydir = 1;
651   }
652   
653   for(ypos=ystart;ypos!=yend;ypos+=ydir)
654   {
655      for(xpos=xstart;xpos!=xend;xpos+=xdir)
629656      {
630657         voffset = 0;
631         pixel = towns_sprram[poffset] & 0x0f;
658         if(xflip)
659            pixel = (towns_sprram[poffset] & 0xf0) >> 4;
660         else
661            pixel = towns_sprram[poffset] & 0x0f;
632662         col = towns_sprram[coffset+(pixel*2)] | (towns_sprram[coffset+(pixel*2)+1] << 8);
633663         voffset += (towns_crtc_reg[24] * 4) * ypos;  // scanline size in bytes * y pos
634664         voffset += (xpos & 0x1ff) * 2;
r6727r6728
639669            towns_gfxvram[voffset+1] = (col & 0xff00) >> 8;
640670            towns_gfxvram[voffset] = col & 0x00ff;
641671         }
642         voffset+=2;
643         pixel = (towns_sprram[poffset] & 0xf0) >> 4;
672         if(xflip)
673         {
674            voffset+=2;
675            pixel = (towns_sprram[poffset] & 0xf0) >> 4;
676         }
677         else
678         {
679            voffset-=2;
680            pixel = towns_sprram[poffset] & 0x0f;
681         }
644682         col = towns_sprram[coffset+(pixel*2)] | (towns_sprram[coffset+(pixel*2)+1] << 8);
645683         voffset &= 0x3ffff;
646684         voffset += (towns_sprite_reg[6] & 0x10) ? 0x60000 : 0x40000;
r6727r6728
654692   }
655693}
656694
657void render_sprite_16(bitmap_t* bitmap, UINT32 poffset, UINT16 x, UINT16 y, const rectangle* rect)
695void render_sprite_16(bitmap_t* bitmap, UINT32 poffset, UINT16 x, UINT16 y, UINT16 xflip, UINT16 yflip, const rectangle* rect)
658696{
659697   UINT16 xpos,ypos;
660   UINT16 col;//,pixel;
698   UINT16 col;
661699   UINT32 voffset;
700   int xstart,ystart,xend,yend,xdir,ydir;
662701   
663   for(ypos=y;ypos<y+16;ypos++)
702   if(xflip)
664703   {
665      for(xpos=x;xpos<x+16;xpos++)
704      xstart = x+16;
705      xend = x;
706      xdir = -1;
707   }
708   else
709   {
710      xstart = x;
711      xend = x+16;
712      xdir = 1;
713   }
714   if(yflip)
715   {
716      ystart = y+16;
717      yend = y;
718      ydir = -1;
719   }
720   else
721   {
722      ystart = y;
723      yend = y+16;
724      ydir = 1;
725   }
726   
727   for(ypos=ystart;ypos!=yend;ypos+=ydir)
728   {
729      for(xpos=xstart;xpos!=xend;xpos+=xdir)
666730      {
667731         voffset = (towns_sprite_reg[6] & 0x10) ? 0x60000 : 0x40000;
668732         col = towns_sprram[poffset] | (towns_sprram[poffset+1] << 8);
r6727r6728
717781            n,x,y,attr,colour,poffset,coffset);
718782#endif
719783         if(!(colour & 0x2000))
720            render_sprite_4(bitmap,(poffset+pshift)&0x1ffff,coffset,x,y,rect);
784            render_sprite_4(bitmap,(poffset+pshift)&0x1ffff,coffset,x,y,attr&0x2000,attr&0x1000,rect);
721785      }
722786      else
723787      {
r6727r6728
727791         printf("Sprite16 #%i, X %i Y %i Attr %04x Col %04x Poff %05x Coff %05x\n",
728792            n,x,y,attr,colour,poffset,coffset);
729793#endif
730         render_sprite_16(bitmap,(poffset+pshift)&0x1ffff,x,y,rect);
794         render_sprite_16(bitmap,(poffset+pshift)&0x1ffff,x,y,attr&0x2000,attr&0x1000,rect);
731795      }
732796   }
733797}

Previous 15994 Revisions Next


© 1998-2018 The MESS Team