Previous 199869 Revisions Next

r17532 Tuesday 28th August, 2012 at 13:04:12 UTC by Ville Linde
cobra.c: Latest research (nw)
[src/mame/drivers]cobra.c

trunk/src/mame/drivers/cobra.c
r17531r17532
11/*  Konami Cobra System
22
3   Driver by Ville Linde
34
5
46    Games on this hardware
57    ----------------------
68
r17531r17532
158160
159161        0x0011c:        Same as above?
160162
163      0x00454:      (mask 0xff) 0x80000000                     Tex related
164
161165        0x00458:        Set to 0x02100000 (0xff) by texselect()
162166
163        0x02904:        -------- ------xx xx------ --------             Tex mag filter?
164                        -------- -------- --xxxx-- --------             Tex min filter?
167                  ------xx -------- -------- --------            Texture select (0-3)
168                  -------- ---x---- -------- --------            ?
165169
166        0x02908:        -------- ----xxx- -------- --------             Tex wrap S (0 = repeat, 1 = mirror, 2 = clamp)
167                        -------- -------x xx------ --------             Tex wrap T
170      0x02900:      -------- -------- -------- --------            Texture[0] ?
168171
169        0x02910:        xxxx---- -------- -------- --------             Texture width shift (size = 1 << X)
170                        ----xxxx -------- -------- --------             Texture height shift (size = 1 << X)
172        0x02904:        -------- ------xx xx------ --------             Texture[0] mag filter?
173                        -------- -------- --xxxx-- --------             Texture[0] min filter?
174
175        0x02908:        -------- ----xxx- -------- --------             Texture[0] wrap S (0 = repeat, 1 = mirror, 2 = clamp)
176                        -------- -------x xx------ --------             Texture[0] wrap T
177
178        0x02910:        xxxx---- -------- -------- --------             Texture[0] width shift (size = 1 << X)
179                        ----xxxx -------- -------- --------             Texture[0] height shift (size = 1 << X)
171180                        -------- ----x--- -------- --------             ?
172181                        -------- -------- -x------ --------             ?
173                        -------- -------- -------- xxx-----             Texture format (texel size, 2 = 4-bit, 3 = 8-bit, 4 = 16-bit)
174                        -------- -------- -------- ---xxx--             Texture format param
182                        -------- -------- -------- xxx-----             Texture[0] format (texel size, 2 = 4-bit, 3 = 8-bit, 4 = 16-bit)
183                        -------- -------- -------- ---xxx--             Texture[0] format param
175184
176        0x02914:        --xxxxxx xxxxxxxx xx------ --------             ? (texture param, set to 0x1243)
185        0x02914:        xxxxxxxx xxxxxxxx xxxx---- --------             Texture[0] address
177186
187      0x02980:      Texture[1] ?
188      0x02984:      Texture[1] min/mag filter
189      0x02988:      Texture[1] wrap
190      0x02990:      Texture[1] width/height/format
191      0x02994:      Texture[1] address
192
193      0x02a00:      Texture[2] ?
194      0x02a04:      Texture[2] min/mag filter
195      0x02a08:      Texture[2] wrap
196      0x02a10:      Texture[2] width/height/format
197      0x02a14:      Texture[2] address
198
199      0x02a80:      Texture[3] ?
200      0x02a84:      Texture[3] min/mag filter
201      0x02a88:      Texture[3] wrap
202      0x02a90:      Texture[3] width/height/format
203      0x02a94:      Texture[3] address
204
178205        0x40018:        Set to 0x0001040a (0xc0) by mode_stipple()      (bits 24..27 = stipple pattern?)
179206        0x400d0:        Set to 0x80000000 (0x80) by mode_stipple()
180        0x400f4:        Set to 0x40000000 (0x80) by texselect()
181207
208        0x400f4:        xxx----- -------- -------- --------            Texture select (0-3)
209
210                  xxx----- -------- -------- --------            ?
211
182212        0x40114:        -------- ----x--- -------- --------             Scissor enable
183213
184214        0x40138:        Set to 0x88800000 (0xe0) by mode_viewclip()
r17531r17532
198228        0x40198:        x------- -------- -------- --------             Alpha test enable?
199229                        -------- xxx----- -------- --------             Alpha test function (0 = never, 1 = less, 2 = lequal, 3 = greater,
200230                                                                                             4 = gequal, 5 = equal, 6 = notequal, 7 = always)
231                  -------- -------- xxxxxxxx xxxxxxxx            Alpha test reference value?
201232
202233        0x4019c:        x------- -------- -------- --------             Fog enable
203234                        ----x--- -------- -------- --------             0 = table fog, 1 = linear fog
204235
236      0x401a8:      (mask 0xff): 0x2CAB34FD                     ?
237      0x401ac:      (mask 0xf0): 0x48C70000                     ?
238      0x401b8:      (mask 0x20): 0x00400000                     ?
239
205240        0x401bc:                                                        Texture env mode
206241                        xxx----- -------- -------- --------             ?
207242                        ---xxx-- -------- -------- --------             ?
r17531r17532
216251                                    0xa92b0100 = (equal, 16)
217252
218253                        -------- -------- xxxxxxxx xxxx----             Stencil reference value?
254                  ----xxxx xxxxxxxx -------- --------            Stencil fill value?
219255                        xxx----- -------- -------- --------             Stencil function?
220256
221257
222258        0x80020:        -------- ----xxx- -------- --------             Depth test function (7 = always?)
223259
260      0x80040:      (mask 0x0f) 0x00002CAB (same value as 0x401a8)
261      0x80044:      (mask 0x0f) 0x000034FD (same value as 0x401a8)
262      0x80048:      (mask 0x0f) 0x000048C7 (same value as 0x401ac)
263
224264        0x80050:        (mask 0x7c) 0x04445500 = (As, 1-As)             Blend register
225265                                    0x04111100 = (1, 1)
226266                                    0x04441100 = (As, 1)
r17531r17532
284324#include "video/polynew.h"
285325#include "sound/rf5c400.h"
286326
287#define GFXFIFO_IN_VERBOSE      0
288#define GFXFIFO_OUT_VERBOSE      0
289#define M2SFIFO_VERBOSE         1
290#define S2MFIFO_VERBOSE         1
327#define GFXFIFO_IN_VERBOSE         0
328#define GFXFIFO_OUT_VERBOSE         0
329#define M2SFIFO_VERBOSE            0
330#define S2MFIFO_VERBOSE            0
291331
332#define LOG_DEBUG_STATES         0
333#define LOG_JVS                  0
334#define LOG_GFX_RAM_WRITES         0
335#define LOG_DRAW_COMMANDS         0
292336
337
293338/* Cobra Renderer class */
294339
295340struct cobra_polydata
296341{
342   UINT32 alpha_test;
343   UINT32 zmode;
344   UINT32 tex_format;
345   UINT32 tex_address;
297346};
298347
299class cobra_renderer : public poly_manager<float, cobra_polydata, 6, 10000>
348class cobra_renderer : public poly_manager<float, cobra_polydata, 8, 10000>
300349{
301350public:
302351   cobra_renderer(running_machine &machine)
303      : poly_manager<float, cobra_polydata, 6, 10000>(machine)
352      : poly_manager<float, cobra_polydata, 8, 10000>(machine)
304353   {
305354      m_texture_ram = auto_alloc_array(machine, UINT32, 0x100000);
306355
r17531r17532
338387   void gfx_fifo_exec(running_machine &machine);
339388   UINT32 gfx_read_gram(UINT32 address);
340389   void gfx_write_gram(UINT32 address, UINT32 mask, UINT32 data);
390   UINT64 gfx_read_reg(running_machine &machine);
391   void gfx_write_reg(running_machine &machine, UINT64 data);
341392
342393   void display(bitmap_rgb32 *bitmap, const rectangle &cliprect);
343394
r17531r17532
352403
353404   UINT32 *m_gfx_gram;
354405   UINT32 *m_gfx_regmask;
406   
407   UINT32 m_gfx_register_select;
408   UINT64 *m_gfx_register;
355409
410   UINT32 m_texram_ptr;
411
356412   enum
357413   {
358414      RE_STATUS_IDLE            = 0,
359415      RE_STATUS_COMMAND         = 1,
360416   };
417
418   enum
419   {
420      POLY_Z      = 0,
421      POLY_R      = 1,
422      POLY_G      = 2,
423      POLY_B      = 3,
424      POLY_A      = 4,
425      POLY_U      = 5,
426      POLY_V      = 6,
427      POLY_W      = 7,
428   };
361429};
362430
363431
r17531r17532
433501
434502bool cobra_jvs::switches(UINT8 *&buf, UINT8 count_players, UINT8 bytes_per_switch)
435503{
504#if LOG_JVS
436505   printf("jvs switch read: num players %d, bytes %d\n", count_players, bytes_per_switch);
506#endif
437507
438508   if (count_players > 2 || bytes_per_switch > 2)
439509      return false;
r17531r17532
455525
456526bool cobra_jvs::coin_counters(UINT8 *&buf, UINT8 count)
457527{
528#if LOG_JVS
458529   printf("jvs coin counter read: count %d\n", count);
530#endif
459531
460532   if (count > 2)
461533      return false;
r17531r17532
625697   int m_gfx_re_status;
626698   UINT32 m_gfx_unk_status;
627699
628   int m_gfx_register_select;
629   UINT64 *m_gfx_register;
630700   UINT64 m_gfx_fifo_mem[256];
631701   int m_gfx_fifo_cache_addr;
632702   int m_gfx_fifo_loopback;
r17531r17532
642712
643713void cobra_renderer::render_color_scan(INT32 scanline, const extent_t &extent, const cobra_polydata &extradata, int threadid)
644714{
645    UINT32 *fb = &m_framebuffer->pix32(scanline);
715    UINT32 *fb = &m_backbuffer->pix32(scanline);
716   float *zb = (float*)&m_zbuffer->pix32(scanline);
646717
647    UINT32 color = 0xff000000; // TODO
718   float z = extent.param[POLY_Z].start;
719   float dz = extent.param[POLY_Z].dpdx;
648720
721   float gr = extent.param[POLY_R].start;
722   float dgr = extent.param[POLY_R].dpdx;
723   float gg = extent.param[POLY_G].start;
724   float dgg = extent.param[POLY_G].dpdx;
725   float gb = extent.param[POLY_B].start;
726   float dgb = extent.param[POLY_B].dpdx;
727   float ga = extent.param[POLY_A].start;
728   float dga = extent.param[POLY_A].dpdx;
729
730   UINT32 zmode = extradata.zmode;
731
649732    for (int x = extent.startx; x < extent.stopx; x++)
650733    {
651        fb[x] = color;
734      if (z <= zb[x] || zmode == 7)
735      {
736         UINT32 r = (int)(gr);
737         UINT32 g = (int)(gg);
738         UINT32 b = (int)(gb);
739
740         if (r > 255) r = 255;
741         if (g > 255) g = 255;
742         if (b > 255) b = 255;
743
744         r <<= 16;
745         g <<= 8;
746
747         fb[x] = 0xff000000 | r | g | b;
748         zb[x] = z;
749      }
750
751      z += dz;
752      gr += dgr;
753      gg += dgg;
754      gb += dgb;
755      ga += dga;
652756    }
653757}
654758
655759void cobra_renderer::render_texture_scan(INT32 scanline, const extent_t &extent, const cobra_polydata &extradata, int threadid)
656760{
657   float u = extent.param[0].start;
658   float v = extent.param[1].start;
659   float du = extent.param[0].dpdx;
660   float dv = extent.param[1].dpdx;
661   UINT32 *fb = &m_framebuffer->pix32(scanline);
761   float u = extent.param[POLY_U].start;
762   float v = extent.param[POLY_V].start;
763   float du = extent.param[POLY_U].dpdx;
764   float dv = extent.param[POLY_V].dpdx;
662765
663   int texture_width = 1 << ((m_gfx_gram[0x2910/4] >> 28) & 0xf);
664   int texture_height = 1 << ((m_gfx_gram[0x2910/4] >> 24) & 0xf);
766   float w = extent.param[POLY_W].start;
767   float dw = extent.param[POLY_W].dpdx;
665768
769   float z = extent.param[POLY_Z].start;
770   float dz = extent.param[POLY_Z].dpdx;
771
772   float gr = extent.param[POLY_R].start;
773   float dgr = extent.param[POLY_R].dpdx;
774   float gg = extent.param[POLY_G].start;
775   float dgg = extent.param[POLY_G].dpdx;
776   float gb = extent.param[POLY_B].start;
777   float dgb = extent.param[POLY_B].dpdx;
778   float ga = extent.param[POLY_A].start;
779   float dga = extent.param[POLY_A].dpdx;
780
781   UINT32 *fb = &m_backbuffer->pix32(scanline);
782   float *zb = (float*)&m_zbuffer->pix32(scanline);
783
784   UINT32 texture_width  = 1 << ((extradata.tex_format >> 28) & 0xf);
785   UINT32 texture_height = 1 << ((extradata.tex_format >> 24) & 0xf);
786   UINT32 tex_address = extradata.tex_address;
787
788   UINT32 alpha_test = extradata.alpha_test;
789   UINT32 zmode = extradata.zmode;
790   UINT32 tex_format = (extradata.tex_format >> 2) & 0x7;
791
666792   for (int x = extent.startx; x < extent.stopx; x++)
667793   {
668794      int iu, iv;
669795      UINT32 texel;
670796
671      iu = (int)(u * texture_width);
672      iv = (int)(v * texture_height);
797      if (z <= zb[x] || zmode == 7)
798      {
799         float oow;
673800
674      texel = m_texture_ram[((iv * texture_width) + iu) / 2];
801         if (w == 0)
802            oow = 1.0f;
803         else
804            oow = 1.0f / w;
675805
676      if (iu & 1)
677      {
678         texel &= 0xffff;
679      }
680      else
681      {
682         texel >>= 16;
683      }
806         iu = (int)((u * oow) * texture_width) & 0x7ff;
807         iv = (int)((v * oow) * texture_height) & 0x7ff;
684808
685      UINT32 r = (texel & 0x7c00) << 9;
686      UINT32 g = (texel & 0x03e0) << 6;
687      UINT32 b = (texel & 0x001f) << 3;
809         texel = m_texture_ram[tex_address + (((iv * texture_width) + iu) / 2)];
688810
689      fb[x] = 0xff000000 | r | g | b;
811         if (iu & 1)
812         {
813            texel &= 0xffff;
814         }
815         else
816         {
817            texel >>= 16;
818         }
690819
820         UINT32 texr, texg, texb, texa;
821
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         }
836
837         UINT32 goua = (int)(ga);
838
839         int a = (texa * goua) >> 8;
840
841         if (a != 0 || !alpha_test)
842         {
843            UINT32 gour = (int)(gr);
844            UINT32 goug = (int)(gg);
845            UINT32 goub = (int)(gb);
846   
847            int r = (texr * gour) >> 8;
848            int g = (texg * goug) >> 8;
849            int b = (texb * goub) >> 8;
850
851            if (r > 255) r = 255;
852            if (g > 255) g = 255;
853            if (b > 255) b = 255;
854
855            r <<= 16;
856            g <<= 8;
857
858            fb[x] = 0xff000000 | r | g | b;
859            zb[x] = z;
860         }
861      }
862
691863      u += du;
692864      v += dv;
865      w += dw;
866      z += dz;
867
868      gr += dgr;
869      gg += dgg;
870      gb += dgb;
871      ga += dga;
693872   }
694873}
695874
r17531r17532
701880   if (x >= visarea.min_x && x <= visarea.max_x &&
702881      y >= visarea.min_y && y <= visarea.max_y)
703882   {
704      UINT32 *fb = &m_framebuffer->pix32(y);
883      UINT32 *fb = &m_backbuffer->pix32(y);
705884      fb[x] = color;
706885   }
707886}
r17531r17532
729908      {
730909         int y = y1 + (dy * (float)(x - x1) / (float)(dx));
731910
732         UINT32 *fb = &m_framebuffer->pix32(y);
911         UINT32 *fb = &m_backbuffer->pix32(y);
733912         fb[x] = color;
734913
735914         x++;
r17531r17532
742921      {
743922         int x = x1 + (dx * (float)(y - y1) / (float)(dy));
744923
745         UINT32 *fb = &m_framebuffer->pix32(y);
924         UINT32 *fb = &m_backbuffer->pix32(y);
746925         fb[x] = color;
747926
748927         y++;
r17531r17532
11721351      //
11731352      // 7 6 5 4 3 2 1 0
11741353      //----------------
1175      //             x     S2M FIFO unknown flag
1354      //             x     S2M FIFO interrupt active
11761355      //           x       Graphics board/FIFO busy flag
1177      //         x         M2S FIFO unknown flag
1356      //         x         M2S FIFO interrupt active
11781357
11791358      int value = 0x01;
11801359
r17531r17532
12991478
13001479      if ((m_m2s_int_enable & 0x80) == 0)
13011480      {
1481         m_main_int_active &= ~MAIN_INT_M2S;
1482
13021483         // clear the interrupt
13031484         cputag_set_input_line(space.machine(), "maincpu", INPUT_LINE_IRQ0, CLEAR_LINE);
13041485      }
r17531r17532
13211502
13221503   if (m_main_debug_state_wc >= 2)
13231504   {
1505#if LOG_DEBUG_STATES
13241506      if (m_main_debug_state != 0)
13251507      {
13261508         printf("MAIN: debug state %02X\n", m_main_debug_state);
13271509      }
1510#endif
13281511
13291512      m_main_debug_state = 0;
13301513      m_main_debug_state_wc = 0;
r17531r17532
15491732
15501733   if (m_sub_debug_state_wc >= 2)
15511734   {
1735#if LOG_DEBUG_STATES
15521736      if (m_sub_debug_state != 0)
15531737      {
15541738         printf("SUB: debug state %02X\n", m_sub_debug_state);
15551739      }
1740#endif
15561741
15571742      m_sub_debug_state = 0;
15581743      m_sub_debug_state_wc = 0;
r17531r17532
16891874
16901875static UINT32 sub_unknown_dma_r(device_t *device, int width)
16911876{
1692   printf("DMA read from unknown: size %d\n", width);
1877   //printf("DMA read from unknown: size %d\n", width);
16931878   return 0;
16941879}
16951880
16961881static void sub_unknown_dma_w(device_t *device, int width, UINT32 data)
16971882{
1698   printf("DMA write to unknown: size %d, data %08X\n", width, data);
1883   //printf("DMA write to unknown: size %d, data %08X\n", width, data);
16991884}
17001885
17011886static void sub_jvs_w(device_t *device, UINT8 data)
17021887{
17031888   cobra_jvs_host *jvs = downcast<cobra_jvs_host *>(device->machine().device("cobra_jvs_host"));
1889
1890#if LOG_JVS
17041891   printf("sub_jvs_w: %02X\n", data);
1892#endif
17051893
17061894   const UINT8 *rec_data;
17071895   UINT32 rec_size;
r17531r17532
17101898
17111899   if (rec_size > 0)
17121900   {
1713      /*
1901#if LOG_JVS
17141902      printf("jvs reply ");
17151903      for (int i=0; i < rec_size; i++)
17161904      {
17171905         printf("%02X ", rec_data[i]);
17181906      }
17191907      printf("\n");
1720      */
1908#endif
17211909
17221910      for (int i=0; i < rec_size; i++)
17231911      {
r17531r17532
17371925   AM_RANGE(0x78210000, 0x78217fff) AM_MIRROR(0x80000000) AM_RAM_WRITE(sub_psac_palette_w) AM_SHARE("paletteram")                  // PSAC palette RAM
17381926   AM_RANGE(0x78220000, 0x7823ffff) AM_MIRROR(0x80000000) AM_DEVREADWRITE_LEGACY("k001604", k001604_tile_r, k001604_tile_w)         // PSAC tile RAM
17391927   AM_RANGE(0x78240000, 0x7827ffff) AM_MIRROR(0x80000000) AM_DEVREADWRITE_LEGACY("k001604", k001604_char_r, k001604_char_w)         // PSAC character RAM
1928   AM_RANGE(0x78280000, 0x7828000f) AM_MIRROR(0x80000000) AM_NOP                                 // ???
17401929   AM_RANGE(0x78300000, 0x7830000f) AM_MIRROR(0x80000000) AM_READWRITE(sub_psac2_r, sub_psac2_w)         // PSAC
17411930   AM_RANGE(0x7e000000, 0x7e000003) AM_MIRROR(0x80000000) AM_READWRITE(sub_unk7e_r, sub_debug_w)
17421931   AM_RANGE(0x7e040000, 0x7e041fff) AM_MIRROR(0x80000000) AM_DEVREADWRITE8_LEGACY("m48t58", timekeeper_r, timekeeper_w, 0xffffffff)   /* M48T58Y RTC/NVRAM */
17431932   AM_RANGE(0x7e180000, 0x7e180003) AM_MIRROR(0x80000000) AM_READWRITE(sub_unk1_r, sub_unk1_w)            // TMS57002?
17441933   AM_RANGE(0x7e200000, 0x7e200003) AM_MIRROR(0x80000000) AM_READWRITE(sub_config_r, sub_config_w)
1745//  AM_RANGE(0x7e280000, 0x7e28ffff) AM_MIRROR(0x80000000) AM_RAM                                           // LANC
1746//  AM_RANGE(0x7e300000, 0x7e30ffff) AM_MIRROR(0x80000000) AM_RAM                                           // LANC
1934   AM_RANGE(0x7e280000, 0x7e28ffff) AM_MIRROR(0x80000000) AM_NOP                                           // LANC
1935   AM_RANGE(0x7e300000, 0x7e30ffff) AM_MIRROR(0x80000000) AM_NOP                                           // LANC
17471936   AM_RANGE(0x7e380000, 0x7e380003) AM_MIRROR(0x80000000) AM_READWRITE(sub_mainbd_r, sub_mainbd_w)
17481937   AM_RANGE(0x7ff80000, 0x7fffffff) AM_MIRROR(0x80000000) AM_ROM AM_REGION("user2", 0)                  /* Boot ROM */
17491938ADDRESS_MAP_END
r17531r17532
17811970
17821971void cobra_renderer::display(bitmap_rgb32 *bitmap, const rectangle &cliprect)
17831972{
1784   copybitmap_trans(*bitmap, *m_framebuffer, 0, 0, 0, 0, cliprect, 0);
1973   if (m_gfx_register[0] & 0x4)
1974   {
1975      copybitmap_trans(*bitmap, *m_framebuffer, 0, 0, 0, 0, cliprect, 0);
1976   }
1977   else
1978   {
1979      copybitmap_trans(*bitmap, *m_backbuffer, 0, 0, 0, 0, cliprect, 0);
1980   }
17851981}
17861982
17871983void cobra_renderer::gfx_init(running_machine &machine)
17881984{
1789   cobra_state *cobra = machine.driver_data<cobra_state>();
1985   const rectangle& visarea = machine.primary_screen->visible_area();
17901986
17911987   m_gfx_gram = auto_alloc_array(machine, UINT32, 0x40000);
17921988
1793   cobra->m_gfx_register = auto_alloc_array(machine, UINT64, 0x3000);
1989   m_gfx_register = auto_alloc_array(machine, UINT64, 0x3000);
1990   m_gfx_register_select = 0;
1991
1992   float zvalue = 10000000.0f;
1993   m_zbuffer->fill(*(int*)&zvalue, visarea);
17941994}
17951995
17961996void cobra_renderer::gfx_exit(running_machine &machine)
r17531r17532
18062006        fputc((UINT8)(m_texture_ram[i] >> 0), file);
18072007    }
18082008    fclose(file);
1809    */
2009   */
18102010}
18112011
18122012void cobra_renderer::gfx_reset(running_machine &machine)
r17531r17532
18592059         }
18602060         break;
18612061      }
2062
2063      case 0xc:      // 0xCxxxx
2064      {
2065         switch (address & 0xffff)
2066         {
2067            case 0x3020:
2068            case 0x0020:
2069            {
2070               m_texram_ptr = (data & mask) * 4;
2071               break;
2072            }
2073         }
2074
2075         break;
2076      }
18622077   }
18632078
18642079   if (address & 3)
r17531r17532
18712086   m_gfx_gram[address/4] |= data & mask;
18722087}
18732088
2089UINT64 cobra_renderer::gfx_read_reg(running_machine &machine)
2090{
2091   return m_gfx_register[m_gfx_register_select];
2092}
2093
2094void cobra_renderer::gfx_write_reg(running_machine &machine, UINT64 data)
2095{
2096   switch (m_gfx_register_select)
2097   {
2098      case 0x0000:
2099      {
2100         const rectangle& visarea = machine.primary_screen->visible_area();
2101
2102         copybitmap_trans(*m_framebuffer, *m_backbuffer, 0, 0, 0, 0, visarea, 0);
2103         m_backbuffer->fill(0xff000000, visarea);
2104
2105         float zvalue = 10000000.0f;
2106         m_zbuffer->fill(*(int*)&zvalue, visarea);
2107         break;
2108      }
2109   }
2110
2111   m_gfx_register[m_gfx_register_select] = data;
2112}
2113
18742114void cobra_renderer::gfx_fifo_exec(running_machine &machine)
18752115{
18762116   cobra_state *cobra = machine.driver_data<cobra_state>();
r17531r17532
18792119      return;
18802120
18812121   const rectangle& visarea = machine.primary_screen->visible_area();
1882   vertex_t vert[8];
2122   vertex_t vert[32];
18832123
18842124   cobra_fifo *fifo_in = cobra->m_gfxfifo_in;
18852125   cobra_fifo *fifo_out = cobra->m_gfxfifo_out;
r17531r17532
19412181            if (w2 == 0x10500010)
19422182            {
19432183               // GFX register select
1944               cobra->m_gfx_register_select = w[3];
2184               m_gfx_register_select = w[3];
19452185
1946               printf("GFX: register select %04X\n", cobra->m_gfx_register_select);
2186               printf("GFX: register select %08X\n", m_gfx_register_select);
19472187            }
19482188            else if (w2 == 0x10500018)
19492189            {
19502190               // register write to the register selected above?
19512191               // 64-bit registers, top 32-bits in word 2, low 32-bit in word 3
1952               printf("GFX: register write %04X: %08X %08X\n", cobra->m_gfx_register_select, w[2], w[3]);
2192               printf("GFX: register write %08X: %08X %08X\n", m_gfx_register_select, w[2], w[3]);
19532193
1954               cobra->m_gfx_register[cobra->m_gfx_register_select] = ((UINT64)(w[2]) << 32) | w[3];
2194               gfx_write_reg(machine, ((UINT64)(w[2]) << 32) | w[3]);
19552195            }
19562196            else if (w2 == 0x10521000)
19572197            {
r17531r17532
19842224               logerror("gfxfifo_exec: unknown %08X %08X\n", w1, w2);
19852225            }
19862226
1987            printf("gfxfifo_exec: unhandled %08X %08X\n", w1, w2);
2227            //printf("gfxfifo_exec: unhandled %08X %08X\n", w1, w2);
19882228
19892229            fifo_in->pop(NULL, &in3);
19902230            fifo_in->pop(NULL, &in4);
r17531r17532
20082248         case 0xf1:
20092249         case 0xf4:
20102250         {
2011            printf("gfxfifo_exec: unhandled %08X %08X\n", w1, w2);
2251            //printf("gfxfifo_exec: unhandled %08X %08X\n", w1, w2);
20122252
20132253            cobra->m_gfx_re_status = RE_STATUS_IDLE;
20142254            break;
r17531r17532
20562296            }
20572297
20582298
2299           
2300            float vp_width      = u2f(m_gfx_gram[0x00090/4]);
2301            float vp_height      = u2f(m_gfx_gram[0x000a4/4]);
2302            float vp_center_x   = u2f(m_gfx_gram[0x0009c/4]);
2303            float vp_center_y   = u2f(m_gfx_gram[0x000ac/4]);
2304
2305            if (vp_width == 0.0f)
2306            {
2307               vp_width = 256.0f;
2308               vp_center_x = 256.0f;
2309            }
2310
2311#if LOG_DRAW_COMMANDS
2312            printf("--- Draw command %08X %08X ---\n", w1, w2);
2313#endif
2314           
2315
20592316            // extract vertex data
20602317            for (int i=0; i < units; i++)
20612318            {
2062               UINT64 in;
2319               float x, y, z, w;
2320               float r, g, b, a;
2321               w = 1.0f;
2322
2323               UINT64 in[4];
20632324               if (w2 & 0x40000000)      // line flags
20642325               {
2065                  fifo_in->pop(NULL, &in);
2326                  fifo_in->pop(NULL, &in[0]);
20662327               }
20672328
20682329               if (w2 & 0x20000000)      // unknown float (0.0f ... 1.0f)
20692330               {
2070                  fifo_in->pop(NULL, &in);
2331                  fifo_in->pop(NULL, &in[1]);
20712332               }
20722333
2073               fifo_in->pop(NULL, &vert[i].x);            // X coord
2074               fifo_in->pop(NULL, &vert[i].y);            // Y coord
2075               fifo_in->pop(NULL, &in);               // coord?
2076               fifo_in->pop(NULL, &in);               // Z coord
2334               fifo_in->pop(NULL, &x);                  // X coord
2335               fifo_in->pop(NULL, &y);                  // Y coord
2336               fifo_in->pop(NULL, &in[2]);               // coord?
2337               fifo_in->pop(NULL, &z);                  // Z coord
20772338
20782339               if (w2 & 0x00200000)      // texture coords
20792340               {
2080                  fifo_in->pop(NULL, &in);            // W coord (1 / Z)
2081                  fifo_in->pop(NULL, &vert[i].p[0]);      // U coord
2082                  fifo_in->pop(NULL, &vert[i].p[1]);      // V coord
2341                  fifo_in->pop(NULL, &w);               // W coord (1 / Z)
2342                  fifo_in->pop(NULL, &vert[i].p[POLY_U]);   // U/Z coord
2343                  fifo_in->pop(NULL, &vert[i].p[POLY_V]);   // V/Z coord
20832344               }
20842345
2085               fifo_in->pop(NULL, &in);               // ? (float 0.0f ... 1.0f)
2086               fifo_in->pop(NULL, &in);               // ? (float 0.0f ... 1.0f)
2087               fifo_in->pop(NULL, &in);               // ? (float 0.0f ... 1.0f)
2088               fifo_in->pop(NULL, &in);               // ? (float 0.0f ... 1.0f)
2346               fifo_in->pop(NULL, &a);                  // Gouraud Color Alpha
2347               fifo_in->pop(NULL, &r);                  // Gouraud Color R
2348               fifo_in->pop(NULL, &g);                  // Gouraud Color G
2349               fifo_in->pop(NULL, &b);                  // Gouraud Color B
20892350
20902351               if (w2 & 0x00000001)      // unknown float (0.0f ... 1.0f)
20912352               {
2092                  fifo_in->pop(NULL, &in);
2353                  fifo_in->pop(NULL, &in[3]);
20932354               }
2355
2356               vert[i].x = ((x / z) * vp_width) + vp_center_x;
2357               vert[i].y = ((y / z) * vp_height) + vp_center_y;
2358               vert[i].p[POLY_Z] = z;
2359               vert[i].p[POLY_W] = w;
2360               vert[i].p[POLY_R] = r * 255.0f;
2361               vert[i].p[POLY_G] = g * 255.0f;
2362               vert[i].p[POLY_B] = b * 255.0f;
2363               vert[i].p[POLY_A] = a * 255.0f;
2364
2365
2366#if LOG_DRAW_COMMANDS
2367               if (w2 & 0x40000000)
2368               {
2369                  printf("    ?: %08X\n", (UINT32)in[0]);
2370               }
2371               if (w2 & 0x20000000)
2372               {
2373                  printf("    ?: %08X\n", (UINT32)in[1]);
2374               }
2375
2376               printf("    x: %f\n", x);
2377               printf("    y: %f\n", y);
2378               printf("    ?: %08X\n", (UINT32)in[2]);
2379               printf("    z: %f\n", z);
2380
2381               if (w2 & 0x00200000)
2382               {
2383                  printf("    w: %f\n", w);
2384                  printf("    u: %f\n", vert[i].p[POLY_U]);
2385                  printf("    v: %f\n", vert[i].p[POLY_V]);
2386               }
2387
2388               printf("    a: %f\n", a);
2389               printf("    r: %f\n", r);
2390               printf("    g: %f\n", g);
2391               printf("    b: %f\n", b);
2392
2393               if (w2 & 0x00000001)
2394               {
2395                  printf("    ?: %08X\n", (UINT32)in[3]);
2396               }
2397
2398               printf("\n");
2399#endif
20942400            }
20952401
20962402
2403            cobra_polydata &extra = object_data_alloc();
2404
2405            int texture = (m_gfx_gram[0x400f4/4] >> 29);
2406
2407            extra.alpha_test = m_gfx_gram[0x40198/4] & 0x80000000;
2408            extra.zmode = (m_gfx_gram[0x80020/4] >> 17) & 0x7;
2409            extra.tex_format = m_gfx_gram[(0x2910 + (texture << 7)) / 4];
2410            extra.tex_address = (m_gfx_gram[(0x2914 + (texture << 7)) / 4] >> 12) & 0xfffff;
2411
2412
20972413            // render
20982414            switch ((w1 >> 24) & 0xf)
20992415            {
r17531r17532
21042420                     render_delegate rd = render_delegate(FUNC(cobra_renderer::render_texture_scan), this);
21052421                     for (int i=2; i < units; i++)
21062422                     {
2107                        render_triangle(visarea, rd, 6, vert[i-2], vert[i-1], vert[i]);
2423                        render_triangle(visarea, rd, 8, vert[i-2], vert[i-1], vert[i]);
21082424                     }
21092425                  }
21102426                  else
r17531r17532
21122428                     render_delegate rd = render_delegate(FUNC(cobra_renderer::render_color_scan), this);
21132429                     for (int i=2; i < units; i++)
21142430                     {
2115                        render_triangle(visarea, rd, 6, vert[i-2], vert[i-1], vert[i]);
2116                        //draw_point(visarea, vert[i-2], 0xffff0000);
2117                        //draw_point(visarea, vert[i-1], 0xffff0000);
2118                        //draw_point(visarea, vert[i], 0xffff0000);
2431                        render_triangle(visarea, rd, 5, vert[i-2], vert[i-1], vert[i]);
21192432                     }
21202433                  }
21212434                  break;
r17531r17532
21762489            int x = (m_gfx_gram[0x118/4] >> 16) & 0xffff;
21772490            int y = m_gfx_gram[0x118/4] & 0xffff;
21782491
2492            x &= 0x3ff;
2493            y &= 0x3ff;
2494
21792495            for (i=0; i < num; i+=4)
21802496            {
21812497               UINT32 *buffer;
r17531r17532
23122628
23132629            gfx_write_gram(reg, mask, w2);
23142630
2631#if LOG_GFX_RAM_WRITES
23152632            if (reg != 0x118 && reg != 0x114 && reg != 0x11c)
23162633            {
23172634               printf("gfxfifo_exec: ram write %05X (mask %08X): %08X (%f)\n", reg, mask, w2, u2f(w2));
23182635            }
2636#endif
23192637
23202638            cobra->m_gfx_re_status = RE_STATUS_IDLE;
23212639            break;
r17531r17532
24122730
24132731            cobra->m_gfx_unk_status |= 0x400;
24142732
2415            if (cobra->m_gfx_re_word_count == 0)
2733            if (cobra->m_gfx_re_word_count == 0 && num_left > 0)
24162734               printf("gfxfifo_exec: tex_ints %d words left\n", num - cobra->m_gfx_re_word_count);
24172735
24182736            for (int i=0; i < num_left; i++)
r17531r17532
24212739               fifo_in->pop(NULL, &param);
24222740               cobra->m_gfx_re_word_count++;
24232741
2424               UINT32 addr = m_gfx_gram[0xc3020/4];
2425               m_texture_ram[addr] = (UINT32)(param);
2426               m_gfx_gram[0xc3020/4]++;
2742               m_texture_ram[m_texram_ptr] = (UINT32)(param);
2743               m_texram_ptr++;
24272744            }
24282745
24292746
r17531r17532
26102927
26112928      // reads back the register selected by gfx register select
26122929
2613      m_gfxfifo_out->push(&space.device(), (UINT32)((m_gfx_register[m_gfx_register_select] >> 32)));
2614      m_gfxfifo_out->push(&space.device(), (UINT32)(m_gfx_register[m_gfx_register_select]));
2930      UINT64 regdata = m_renderer->gfx_read_reg(space.machine());
2931
2932      m_gfxfifo_out->push(&space.device(), (UINT32)(regdata >> 32));
2933      m_gfxfifo_out->push(&space.device(), (UINT32)(regdata));
26152934   }
26162935   else if (data == U64(0x00a0000110520800))
26172936   {
r17531r17532
26823001
26833002   if (m_gfx_debug_state_wc >= 2)
26843003   {
3004#if LOG_DEBUG_STATES
26853005      if (m_gfx_debug_state != 0)
26863006      {
26873007         printf("GFX: debug state %02X\n", m_gfx_debug_state);
26883008      }
3009#endif
26893010
26903011      m_gfx_debug_state = 0;
26913012      m_gfx_debug_state_wc = 0;
r17531r17532
27973118
27983119static INTERRUPT_GEN( cobra_vblank )
27993120{
3121   /*
28003122   cobra_state *cobra = device->machine().driver_data<cobra_state>();
28013123
28023124   if (cobra->m_vblank_enable & 0x80)
r17531r17532
28043126      cputag_set_input_line(device->machine(), "maincpu", INPUT_LINE_IRQ0, ASSERT_LINE);
28053127      cobra->m_gfx_unk_flag = 0x80;
28063128   }
3129   */
28073130}
28083131
28093132
r17531r17532
28533176
28543177   MCFG_SCREEN_ADD("screen", RASTER)
28553178   MCFG_SCREEN_REFRESH_RATE(60)
2856   MCFG_SCREEN_SIZE(512, 384)
2857   MCFG_SCREEN_VISIBLE_AREA(0, 511, 0, 383)
3179   MCFG_SCREEN_SIZE(512, 400)
3180   MCFG_SCREEN_VISIBLE_AREA(0, 511, 0, 399)
28583181   MCFG_PALETTE_LENGTH(65536)
28593182   MCFG_SCREEN_UPDATE_STATIC(cobra)
28603183
r17531r17532
29733296   {
29743297      UINT8 *rom = (UINT8*)machine().root_device().memregion("m48t58")->base();
29753298      rom[0x00] = 0x47;      // G
3299      rom[0x01] = 0x4e;      // N      // N = 2-player, Q = 1-player?
29763300      rom[0x02] = 0x36;      // 6
29773301      rom[0x03] = 0x34;      // 4
29783302      rom[0x04] = 0x35;      // 5
r17531r17532
29933317   }
29943318
29953319   // hd patches
2996   // 0x18932c = 0x38600000            skips check_one_scene()
3320   // (gfx)
3321   // 0x18932c = 0x38600000               skips check_one_scene()
29973322
3323   // (main)
3324   // 0x5025ac = 0x60000000 [0x4082055c]      skip IRQ fail...
3325   // 0x503ec4 = 0x60000000 [0x4186fff8]
3326
29983327   m_has_psac = false;
29993328}
30003329
r17531r17532
30063335   {
30073336      UINT32 *rom = (UINT32*)machine().root_device().memregion("user2")->base();
30083337
3009      //rom[0x62094 / 4] = 0x60000000;         // skip hardcheck()...
3338      rom[0x62094 / 4] = 0x60000000;         // skip hardcheck()...
30103339      rom[0x62ddc / 4] = 0x60000000;         // skip lanc_hardcheck()
30113340
30123341
r17531r17532
30743403      rom[0x0f] = (UINT8)(sum);
30753404   }
30763405
3406   // hd patches
3407   // (gfx)
3408   // 0x144354 = 0x38600000 [0x4bfffb91]      skips check_one_scene()
3409
3410   // (sub)
3411   // 0x2a5394 = 0x4800001c [0x4182001c]      sound chip check?
3412   // 0x2a53f4 = 0x4800001c [0x4082001c]      ?
3413   // 0x2a546c = 0x60000000 [0x48001a0d]      ?
3414   // 0x2a5510 = 0x48000014 [0x419e0014]      ?
3415
3416   // (main)
3417   // 0x14aa48 = 0x60000000 [0x4182fff4]      ?
3418
30773419   m_has_psac = true;
30783420}
30793421

Previous 199869 Revisions Next


© 1997-2024 The MAME Team