Previous 199869 Revisions Next

r17572 Wednesday 29th August, 2012 at 23:26:57 UTC by Ville Linde
cobra.c: Added bilinear filtering and simple alpha blending.
[src/mame/drivers]cobra.c

trunk/src/mame/drivers/cobra.c
r17571r17572
322322#include "machine/jvsdev.h"
323323#include "video/konicdev.h"
324324#include "video/polynew.h"
325#include "video/rgbgen.h"
325326#include "sound/rf5c400.h"
326327
327328#define GFXFIFO_IN_VERBOSE         0
r17571r17572
334335#define LOG_GFX_RAM_WRITES         0
335336#define LOG_DRAW_COMMANDS         0
336337
338#define ENABLE_BILINEAR            1
337339
340
338341/* Cobra Renderer class */
339342
340343struct cobra_polydata
r17571r17572
756759    }
757760}
758761
762INLINE rgb_t texture_fetch(UINT32 *texture, int u, int v, int width, int format)
763{
764   UINT32 texel = texture[((v * width) + u) / 2];
765
766   if (u & 1)
767   {
768      texel &= 0xffff;
769   }
770   else
771   {
772      texel >>= 16;
773   }
774
775   rgb_t color;
776
777   if (format == 6)
778   {
779      int r = (texel & 0xf000) >> 8;
780      int g = (texel & 0x0f00) >> 4;
781      int b = (texel & 0x00f0) >> 0;
782      int a = (texel & 0x000f) | ((texel & 0x000f) << 4);
783      color = MAKE_ARGB(a, r, g, b);
784   }
785   else
786   {
787      int r = (texel & 0xf800) >> 8;
788      int g = (texel & 0x07c0) >> 3;
789      int b = (texel & 0x003e) << 2;
790      int a = (texel & 0x0001) ? 0xff : 0;
791      color = MAKE_ARGB(a, r, g, b);
792   }
793
794   return color;
795}
796
759797void cobra_renderer::render_texture_scan(INT32 scanline, const extent_t &extent, const cobra_polydata &extradata, int threadid)
760798{
761799   float u = extent.param[POLY_U].start;
r17571r17572
792830   for (int x = extent.startx; x < extent.stopx; x++)
793831   {
794832      int iu, iv;
795      UINT32 texel;
796833
797834      if (z <= zb[x] || zmode == 7)
798835      {
r17571r17572
803840         else
804841            oow = 1.0f / w;
805842
843#if !ENABLE_BILINEAR
844
806845         iu = (int)((u * oow) * texture_width) & 0x7ff;
807846         iv = (int)((v * oow) * texture_height) & 0x7ff;
808847
809         texel = m_texture_ram[tex_address + (((iv * texture_width) + iu) / 2)];
848         rgb_t texel = texture_fetch(&m_texture_ram[tex_address], iu, iv, texture_width, tex_format);
810849
811         if (iu & 1)
812         {
813            texel &= 0xffff;
814         }
815         else
816         {
817            texel >>= 16;
818         }
850#else
819851
820         UINT32 texr, texg, texb, texa;
852         float tex_u = (u * oow) * texture_width;
853         float tex_v = (v * oow) * texture_height;
854         iu = (int)(tex_u) & 0x7ff;
855         iv = (int)(tex_v) & 0x7ff;
821856
822         if (tex_format == 6)
823         {
824            texr = (texel & 0xf000) >> 8;
825            texg = (texel & 0x0f00) >> 4;
826            texb = (texel & 0x00f0) >> 0;
827            texa = (texel & 0x000f);
828         }
829         else
830         {
831            texr = (texel & 0xf800) >> 8;
832            texg = (texel & 0x07c0) >> 3;
833            texb = (texel & 0x003e) << 2;
834            texa = (texel & 0x0001) ? 0xff : 0;
835         }
857         float lerp_u = tex_u - (float)(iu);
858         float lerp_v = tex_v - (float)(iv);
836859
837         UINT32 goua = (int)(ga);
860         rgb_t texel00 = texture_fetch(&m_texture_ram[tex_address], iu, iv, texture_width, tex_format);
861         rgb_t texel01 = texture_fetch(&m_texture_ram[tex_address], iu+1, iv, texture_width, tex_format);
862         rgb_t texel10 = texture_fetch(&m_texture_ram[tex_address], iu, iv+1, texture_width, tex_format);
863         rgb_t texel11 = texture_fetch(&m_texture_ram[tex_address], iu+1, iv+1, texture_width, tex_format);
838864
839         int a = (texa * goua) >> 8;
865         rgb_t texel = rgba_bilinear_filter(texel00, texel01, texel10, texel11, (int)(lerp_u * 255), (int)(lerp_v * 255));
840866
867#endif
868
869         int a = RGB_ALPHA(texel);
870
841871         if (a != 0 || !alpha_test)
842872         {
843873            UINT32 gour = (int)(gr);
844874            UINT32 goug = (int)(gg);
845875            UINT32 goub = (int)(gb);
846876   
847            int r = (texr * gour) >> 8;
848            int g = (texg * goug) >> 8;
849            int b = (texb * goub) >> 8;
877            int r = (RGB_RED(texel) * gour) >> 8;
878            int g = (RGB_GREEN(texel) * goug) >> 8;
879            int b = (RGB_BLUE(texel) * goub) >> 8;
850880
881            if (a != 0xff)
882            {
883               int fb_r = (fb[x] >> 16) & 0xff;
884               int fb_g = (fb[x] >> 8) & 0xff;
885               int fb_b = fb[x] & 0xff;
886
887               r = ((r * a) >> 8) + ((fb_r * (0xff-a)) >> 8);
888               g = ((g * a) >> 8) + ((fb_g * (0xff-a)) >> 8);
889               b = ((b * a) >> 8) + ((fb_b * (0xff-a)) >> 8);
890            }
891
851892            if (r > 255) r = 255;
852893            if (g > 255) g = 255;
853894            if (b > 255) b = 255;
r17571r17572
31183159
31193160static INTERRUPT_GEN( cobra_vblank )
31203161{
3121   /*
31223162   cobra_state *cobra = device->machine().driver_data<cobra_state>();
31233163
31243164   if (cobra->m_vblank_enable & 0x80)
r17571r17572
31263166      cputag_set_input_line(device->machine(), "maincpu", INPUT_LINE_IRQ0, ASSERT_LINE);
31273167      cobra->m_gfx_unk_flag = 0x80;
31283168   }
3129   */
31303169}
31313170
3132
31333171static MACHINE_RESET( cobra )
31343172{
31353173   cobra_state *cobra = machine.driver_data<cobra_state>();
r17571r17572
33043342      rom[0x06] = 0x00;
33053343      rom[0x07] = 0x00;
33063344
3345      rom[0x08] = 0x00;
3346      rom[0x09] = 0x00;
3347      rom[0x0a] = 0x4a;      // J
3348      rom[0x0b] = 0x41;      // A
3349      rom[0x0c] = 0x41;      // A
3350      rom[0x0d] = 0x00;
3351
33073352      // calculate checksum
33083353      UINT16 sum = 0;
33093354      for (int i=0; i < 14; i+=2)
r17571r17572
33203365   // (gfx)
33213366   // 0x18932c = 0x38600000               skips check_one_scene()
33223367
3368   // (sub)
3369   // 0x2d3568 = 0x60000000 [0x4082001c]      skip IRQ fail
3370
33233371   // (main)
33243372   // 0x5025ac = 0x60000000 [0x4082055c]      skip IRQ fail...
33253373   // 0x503ec4 = 0x60000000 [0x4186fff8]
3374   // 0x503f00 = 0x60000000 [0x4186fff8]
33263375
33273376   m_has_psac = false;
33283377}

Previous 199869 Revisions Next


© 1997-2024 The MAME Team