trunk/src/mame/drivers/cobra.c
r17571 | r17572 | |
322 | 322 | #include "machine/jvsdev.h" |
323 | 323 | #include "video/konicdev.h" |
324 | 324 | #include "video/polynew.h" |
| 325 | #include "video/rgbgen.h" |
325 | 326 | #include "sound/rf5c400.h" |
326 | 327 | |
327 | 328 | #define GFXFIFO_IN_VERBOSE 0 |
r17571 | r17572 | |
334 | 335 | #define LOG_GFX_RAM_WRITES 0 |
335 | 336 | #define LOG_DRAW_COMMANDS 0 |
336 | 337 | |
| 338 | #define ENABLE_BILINEAR 1 |
337 | 339 | |
| 340 | |
338 | 341 | /* Cobra Renderer class */ |
339 | 342 | |
340 | 343 | struct cobra_polydata |
r17571 | r17572 | |
756 | 759 | } |
757 | 760 | } |
758 | 761 | |
| 762 | INLINE 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 | |
759 | 797 | void cobra_renderer::render_texture_scan(INT32 scanline, const extent_t &extent, const cobra_polydata &extradata, int threadid) |
760 | 798 | { |
761 | 799 | float u = extent.param[POLY_U].start; |
r17571 | r17572 | |
792 | 830 | for (int x = extent.startx; x < extent.stopx; x++) |
793 | 831 | { |
794 | 832 | int iu, iv; |
795 | | UINT32 texel; |
796 | 833 | |
797 | 834 | if (z <= zb[x] || zmode == 7) |
798 | 835 | { |
r17571 | r17572 | |
803 | 840 | else |
804 | 841 | oow = 1.0f / w; |
805 | 842 | |
| 843 | #if !ENABLE_BILINEAR |
| 844 | |
806 | 845 | iu = (int)((u * oow) * texture_width) & 0x7ff; |
807 | 846 | iv = (int)((v * oow) * texture_height) & 0x7ff; |
808 | 847 | |
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); |
810 | 849 | |
811 | | if (iu & 1) |
812 | | { |
813 | | texel &= 0xffff; |
814 | | } |
815 | | else |
816 | | { |
817 | | texel >>= 16; |
818 | | } |
| 850 | #else |
819 | 851 | |
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; |
821 | 856 | |
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); |
836 | 859 | |
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); |
838 | 864 | |
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)); |
840 | 866 | |
| 867 | #endif |
| 868 | |
| 869 | int a = RGB_ALPHA(texel); |
| 870 | |
841 | 871 | if (a != 0 || !alpha_test) |
842 | 872 | { |
843 | 873 | UINT32 gour = (int)(gr); |
844 | 874 | UINT32 goug = (int)(gg); |
845 | 875 | UINT32 goub = (int)(gb); |
846 | 876 | |
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; |
850 | 880 | |
| 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 | |
851 | 892 | if (r > 255) r = 255; |
852 | 893 | if (g > 255) g = 255; |
853 | 894 | if (b > 255) b = 255; |
r17571 | r17572 | |
3118 | 3159 | |
3119 | 3160 | static INTERRUPT_GEN( cobra_vblank ) |
3120 | 3161 | { |
3121 | | /* |
3122 | 3162 | cobra_state *cobra = device->machine().driver_data<cobra_state>(); |
3123 | 3163 | |
3124 | 3164 | if (cobra->m_vblank_enable & 0x80) |
r17571 | r17572 | |
3126 | 3166 | cputag_set_input_line(device->machine(), "maincpu", INPUT_LINE_IRQ0, ASSERT_LINE); |
3127 | 3167 | cobra->m_gfx_unk_flag = 0x80; |
3128 | 3168 | } |
3129 | | */ |
3130 | 3169 | } |
3131 | 3170 | |
3132 | | |
3133 | 3171 | static MACHINE_RESET( cobra ) |
3134 | 3172 | { |
3135 | 3173 | cobra_state *cobra = machine.driver_data<cobra_state>(); |
r17571 | r17572 | |
3304 | 3342 | rom[0x06] = 0x00; |
3305 | 3343 | rom[0x07] = 0x00; |
3306 | 3344 | |
| 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 | |
3307 | 3352 | // calculate checksum |
3308 | 3353 | UINT16 sum = 0; |
3309 | 3354 | for (int i=0; i < 14; i+=2) |
r17571 | r17572 | |
3320 | 3365 | // (gfx) |
3321 | 3366 | // 0x18932c = 0x38600000 skips check_one_scene() |
3322 | 3367 | |
| 3368 | // (sub) |
| 3369 | // 0x2d3568 = 0x60000000 [0x4082001c] skip IRQ fail |
| 3370 | |
3323 | 3371 | // (main) |
3324 | 3372 | // 0x5025ac = 0x60000000 [0x4082055c] skip IRQ fail... |
3325 | 3373 | // 0x503ec4 = 0x60000000 [0x4186fff8] |
| 3374 | // 0x503f00 = 0x60000000 [0x4186fff8] |
3326 | 3375 | |
3327 | 3376 | m_has_psac = false; |
3328 | 3377 | } |