Previous 15994 Revisions Next

r14633 Sunday 26th February, 2012 at 07:37:12 UTC by Miodrag Milanović
Sync with MAME r15530 (no whatsnew)
[src/emu]devcb.c device.c disound.c disound.h ioport.c speaker.c speaker.h
[src/emu/cpu/powerpc]ppcdrc.c
[src/emu/machine]6532riot.c 6532riot.h
[src/emu/sound]bsmt2000.c samples.c samples.h
[src/mame/drivers]20pacgal.c konamigv.c
[src/mame/video]gticlub.c

src/mame/video/gticlub.c
r14632r14633
66#include "video/konicdev.h"
77#include "video/gticlub.h"
88
9/*
10   TODO:
11      - Fog equation and parameters are probably not accurate.
12      - Winding Heat (and maybe others) have slight Z-fighting problems.
13      - 3D isn't always turned off properly (during title screens for example).
14        Figure out what controls this. Video mixer, layer priority or some 3D register?
915
16*/
17
18#define POLY_Z      0
19#define POLY_BRI   2
20#define POLY_FOG   1
21#define POLY_U      3
22#define POLY_V      4
23#define POLY_W      5
24
25#define ZBUFFER_MAX               10000000000.0f
26
27#define LOG_POLY_FIFO            0
28
29#if LOG_POLY_FIFO
30static int count = 0;
31#endif
32
1033typedef struct _poly_extra_data poly_extra_data;
1134struct _poly_extra_data
1235{
1336   UINT32 color;
1437   int texture_x, texture_y;
38   int texture_width, texture_height;
1539   int texture_page;
1640   int texture_palette;
1741   int texture_mirror_x;
1842   int texture_mirror_y;
43   int light_r, light_g, light_b;
44   int ambient_r, ambient_g, ambient_b;
45   int fog_r, fog_g, fog_b;
46   UINT32 flags;
1947};
2048
2149static UINT8 gticlub_led_reg[2];
r14632r14633
120148         }
121149         default:
122150         {
123            mame_printf_debug("K001006_w: chip %d, device %02X, write %04X to %08X\n", chip, K001006_device_sel[chip], data & 0xffff, K001006_addr[0]++);
151            //mame_printf_debug("K001006_w: chip %d, device %02X, write %04X to %08X\n", chip, K001006_device_sel[chip], data & 0xffff, K001006_addr[0]++);
124152         }
125153      }
126154   }
r14632r14633
181209static UINT32 *K001005_3d_fifo;
182210static int K001005_3d_fifo_ptr = 0;
183211
184static int tex_mirror_table[4][128];
212static int *tex_mirror_table[2][8];
185213
186214static int K001005_bitmap_page = 0;
187215
188216static poly_manager *poly;
189217static poly_vertex prev_v[4];
190static int prev_poly_type;
191218
219static UINT32 fog_r, fog_g, fog_b;
220static UINT32 ambient_r, ambient_g, ambient_b;
221static UINT32 light_r, light_g, light_b;
222
223static UINT32 reg_far_z;
224static float far_z;
225static float fog_density = 1.5f;
226
192227static UINT8 *gfxrom;
193228
194
195229static void K001005_exit(running_machine &machine)
196230{
197231   poly_free(poly);
r14632r14633
199233
200234void K001005_init(running_machine &machine)
201235{
202   int i;
236   int i,k;
203237
204238   int width = machine.primary_screen->width();
205239   int height = machine.primary_screen->height();
r14632r14633
219253
220254   K001005_3d_fifo = auto_alloc_array(machine, UINT32, 0x10000);
221255
222   poly = poly_alloc(machine, 4000, sizeof(poly_extra_data), POLYFLAG_ALLOW_QUADS);
256   poly = poly_alloc(machine, 10000, sizeof(poly_extra_data), POLYFLAG_ALLOW_QUADS);
223257   machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(K001005_exit), &machine));
224258
225   for (i=0; i < 128; i++)
259   for (k=0; k < 8; k++)
226260   {
227      tex_mirror_table[0][i] = i & 0x3f;
228      tex_mirror_table[1][i] = i & 0x3f;
229      tex_mirror_table[2][i] = ((i & 0x3f) >= 0x20) ? (0x1f - (i & 0x1f)) : i & 0x1f;
230      tex_mirror_table[3][i] = ((i & 0x7f) >= 0x40) ? (0x3f - (i & 0x3f)) : i & 0x3f;
261      tex_mirror_table[0][k] = auto_alloc_array(machine, int, 128);
262      tex_mirror_table[1][k] = auto_alloc_array(machine, int, 128);
263
264      int size = (k+1)*8;
265
266      for (i=0; i < 128; i++)
267      {
268         tex_mirror_table[0][k][i] = i % size;
269         tex_mirror_table[1][k][i] = (i % (size*2)) >= size ? ((size - 1) - (i % size)) : i % size;
270      }
231271   }
232272
233273   K001005_status = 0;
r14632r14633
237277   K001005_3d_fifo_ptr = 0;
238278   K001005_bitmap_page = 0;
239279
240   memset(prev_v, 0, sizeof(prev_v));
241   prev_poly_type = 0;
280   memset(prev_v, 0, sizeof(poly_vertex)*4);
242281}
243282
244283// rearranges the texture data to a more practical order
r14632r14633
386425         K001005_fifo_write_ptr++;
387426         K001005_fifo_write_ptr &= 0x7ff;
388427
428         // process the current vertex data if a sync command is being sent (usually means the global registers are being changed)
429         if (data == 0x80000000)
430         {
431            render_polygons(space->machine());
432            K001005_3d_fifo_ptr = 0;
433         }
434
389435         K001005_3d_fifo[K001005_3d_fifo_ptr++] = data;
390436
437#if LOG_POLY_FIFO         
438         printf("0x%08X, ", data);
439         count++;
440         if (count >= 8)
441         {
442            count = 0;
443            printf("\n");
444         }
445#endif
446
391447         // !!! HACK to get past the FIFO B test (GTI Club & Thunder Hurricane) !!!
392448         if (cpu_get_pc(&space->device()) == 0x201ee)
393449         {
r14632r14633
404460         break;
405461      }
406462
407      case 0x100: break;
463      case 0x100:      break;
408464
409   //  case 0x10a:     poly_r = data & 0xff; break;
410   //  case 0x10b:     poly_g = data & 0xff; break;
411   //  case 0x10c:     poly_b = data & 0xff; break;
465      case 0x101:      break;      // viewport x and width?
466      case 0x102:      break;      // viewport y and height?
412467
468      case 0x104:      break;      // viewport center x? (usually 0xff)
469      case 0x105:      break;      // viewport center y? (usually 0xbf)
470
471      case 0x108:               // far Z value, 4 exponent bits?
472         {
473            // this register seems to hold the 4 missing exponent bits...
474            reg_far_z = (reg_far_z & 0x0000ffff) | ((data & 0xf) << 16);
475            UINT32 fz = reg_far_z << 11;
476            far_z = *(float*)&fz;
477            if (far_z == 0.0f)      // just in case...
478               far_z = 1.0f;
479            break;
480         }
481
482      case 0x109:               // far Z value
483         {
484            // the SHARC code throws away the bottom 11 bits of mantissa and the top 5 bits (to fit in a 16-bit register?)
485            reg_far_z = (reg_far_z & 0xffff0000) | (data & 0xffff);
486            UINT32 fz = reg_far_z << 11;
487            far_z = *(float*)&fz;
488            if (far_z == 0.0f)      // just in case...
489               far_z = 1.0f;
490            break;
491         }
492
493      case 0x10a:     light_r = data & 0xff; break;
494      case 0x10b:     light_g = data & 0xff; break;
495      case 0x10c:     light_b = data & 0xff; break;
496
497      case 0x10d:      ambient_r = data & 0xff; break;
498      case 0x10e:      ambient_g = data & 0xff; break;
499      case 0x10f:      ambient_b = data & 0xff; break;
500
501      case 0x110:      fog_r = data & 0xff; break;
502      case 0x111:      fog_g = data & 0xff; break;
503      case 0x112:      fog_b = data & 0xff; break;
504
413505      case 0x11a:
414506         K001005_status = data;
415507         K001005_fifo_write_ptr = 0;
r14632r14633
417509
418510         if (data == 2 && K001005_3d_fifo_ptr > 0)
419511         {
420            K001005_swap_buffers(space->machine());
421512            render_polygons(space->machine());
422513            poly_wait(poly, "render_polygons");
514
515#if LOG_POLY_FIFO
516            count = 0;
517            printf("\nrender %d\n", K001005_3d_fifo_ptr);
518            printf("------------------------------------\n");
519#endif
520
423521            K001005_3d_fifo_ptr = 0;
522            K001005_swap_buffers(space->machine());
424523         }
425524         break;
426525
r14632r14633
451550
452551}
453552
553static void draw_scanline_2d(void *dest, INT32 scanline, const poly_extent *extent, const void *extradata, int threadid)
554{
555   const poly_extra_data *extra = (const poly_extra_data *)extradata;
556   bitmap_rgb32 *destmap = (bitmap_rgb32 *)dest;
557   UINT32 *fb = &destmap->pix32(scanline);
558   float *zb = (float*)&K001005_zbuffer->pix32(scanline);
559   UINT32 color = extra->color;
560   int x;
561
562   for (x = extent->startx; x < extent->stopx; x++)
563   {
564      if (color & 0xff000000)
565      {
566         fb[x] = color;
567         zb[x] = 0x7fffffff;      // FIXME
568      }
569   }
570}
571
572static void draw_scanline_2d_tex(void *dest, INT32 scanline, const poly_extent *extent, const void *extradata, int threadid)
573{
574   const poly_extra_data *extra = (const poly_extra_data *)extradata;
575   bitmap_rgb32 *destmap = (bitmap_rgb32 *)dest;
576   UINT8 *texrom = gfxrom + (extra->texture_page * 0x40000);
577   int pal_chip = (extra->texture_palette & 0x8) ? 1 : 0;
578   int palette_index = (extra->texture_palette & 0x7) * 256;
579   float u = extent->param[POLY_U].start;
580   float v = extent->param[POLY_V].start;
581   float du = extent->param[POLY_U].dpdx;
582   float dv = extent->param[POLY_V].dpdx;
583   UINT32 *fb = &destmap->pix32(scanline);
584   float *zb = (float*)&K001005_zbuffer->pix32(scanline);
585   UINT32 color = extra->color;
586   int texture_mirror_x = extra->texture_mirror_x;
587   int texture_mirror_y = extra->texture_mirror_y;
588   int texture_x = extra->texture_x;
589   int texture_y = extra->texture_y;
590   int texture_width = extra->texture_width;
591   int texture_height = extra->texture_height;
592   int x;
593
594   int *x_mirror_table = tex_mirror_table[texture_mirror_x][texture_width];
595   int *y_mirror_table = tex_mirror_table[texture_mirror_y][texture_height];
596
597   for (x = extent->startx; x < extent->stopx; x++)
598   {     
599      int iu = (int)(u);
600      int iv = (int)(v);
601      int iiv, iiu, texel;
602
603      iiu = texture_x + x_mirror_table[(iu >> 4) & 0x7f];
604      iiv = texture_y + y_mirror_table[(iv >> 4) & 0x7f];
605
606      texel = texrom[((iiv & 0x1ff) * 512) + (iiu & 0x1ff)];
607      color = K001006_palette[pal_chip][palette_index + texel];
608
609      if (color & 0xff000000)
610      {
611         fb[x] = color;
612         zb[x] = 0x7fffffff;      // FIXME
613      }
614
615      u += du;
616      v += dv;
617   }
618}
619
454620static void draw_scanline(void *dest, INT32 scanline, const poly_extent *extent, const void *extradata, int threadid)
455621{
456622   const poly_extra_data *extra = (const poly_extra_data *)extradata;
457623   bitmap_rgb32 *destmap = (bitmap_rgb32 *)dest;
458   float z = extent->param[0].start;
459   float dz = extent->param[0].dpdx;
624   float z = extent->param[POLY_Z].start;
625   float dz = extent->param[POLY_Z].dpdx;
626   float bri = extent->param[POLY_BRI].start;
627   float dbri = extent->param[POLY_BRI].dpdx;
628   float fog = extent->param[POLY_FOG].start;
629   float dfog = extent->param[POLY_FOG].dpdx;
460630   UINT32 *fb = &destmap->pix32(scanline);
461   UINT32 *zb = &K001005_zbuffer->pix32(scanline);
631   float *zb = (float*)&K001005_zbuffer->pix32(scanline);
462632   UINT32 color = extra->color;
463633   int x;
464634
635   int poly_light_r = extra->light_r + extra->ambient_r;
636   int poly_light_g = extra->light_g + extra->ambient_g;
637   int poly_light_b = extra->light_b + extra->ambient_b;
638   if (poly_light_r > 255) poly_light_r = 255;
639   if (poly_light_g > 255) poly_light_g = 255;
640   if (poly_light_b > 255) poly_light_b = 255;
641   int poly_fog_r = extra->fog_r;
642   int poly_fog_g = extra->fog_g;
643   int poly_fog_b = extra->fog_b;
644
465645   for (x = extent->startx; x < extent->stopx; x++)
466646   {
467      UINT32 iz = (UINT32)z >> 16;
647      int ibri = (int)(bri);
648      int ifog = (int)(fog);
468649
469      if (iz <= zb[x])
650      if (ibri < 0) ibri = 0; if (ibri > 255) ibri = 255;
651      if (ifog < 0) ifog = 0; if (ifog > 65536) ifog = 65536;
652
653      if (z <= zb[x])
470654      {
471655         if (color & 0xff000000)
472656         {
473            fb[x] = color;
474            zb[x] = iz;
657            int r = (color >> 16) & 0xff;
658            int g = (color >> 8) & 0xff;
659            int b = color & 0xff;
660
661            r = ((((r * poly_light_r * ibri) >> 16) * ifog) + (poly_fog_r * (65536 - ifog))) >> 16;
662            g = ((((g * poly_light_g * ibri) >> 16) * ifog) + (poly_fog_g * (65536 - ifog))) >> 16;
663            b = ((((b * poly_light_b * ibri) >> 16) * ifog) + (poly_fog_b * (65536 - ifog))) >> 16;
664
665            if (r < 0) r = 0; if (r > 255) r = 255;
666            if (g < 0) g = 0; if (g > 255) g = 255;
667            if (b < 0) b = 0; if (b > 255) b = 255;
668
669            fb[x] = (color & 0xff000000) | (r << 16) | (g << 8) | b;
670            zb[x] = z;
475671         }
476672      }
477673
478674      z += dz;
675      bri += dbri;
676      fog += dfog;
479677   }
480678}
481679
r14632r14633
486684   UINT8 *texrom = gfxrom + (extra->texture_page * 0x40000);
487685   int pal_chip = (extra->texture_palette & 0x8) ? 1 : 0;
488686   int palette_index = (extra->texture_palette & 0x7) * 256;
489   float z = extent->param[0].start;
490   float u = extent->param[1].start;
491   float v = extent->param[2].start;
492   float w = extent->param[3].start;
493   float dz = extent->param[0].dpdx;
494   float du = extent->param[1].dpdx;
495   float dv = extent->param[2].dpdx;
496   float dw = extent->param[3].dpdx;
687   float z = extent->param[POLY_Z].start;
688   float u = extent->param[POLY_U].start;
689   float v = extent->param[POLY_V].start;
690   float w = extent->param[POLY_W].start;
691   float dz = extent->param[POLY_Z].dpdx;
692   float du = extent->param[POLY_U].dpdx;
693   float dv = extent->param[POLY_V].dpdx;
694   float dw = extent->param[POLY_W].dpdx;
695   float bri = extent->param[POLY_BRI].start;
696   float dbri = extent->param[POLY_BRI].dpdx;
697   float fog = extent->param[POLY_FOG].start;
698   float dfog = extent->param[POLY_FOG].dpdx;
497699   int texture_mirror_x = extra->texture_mirror_x;
498700   int texture_mirror_y = extra->texture_mirror_y;
499701   int texture_x = extra->texture_x;
500702   int texture_y = extra->texture_y;
703   int texture_width = extra->texture_width;
704   int texture_height = extra->texture_height;
501705   int x;
502706
707   int poly_light_r = extra->light_r + extra->ambient_r;
708   int poly_light_g = extra->light_g + extra->ambient_g;
709   int poly_light_b = extra->light_b + extra->ambient_b;
710   if (poly_light_r > 255) poly_light_r = 255;
711   if (poly_light_g > 255) poly_light_g = 255;
712   if (poly_light_b > 255) poly_light_b = 255;
713   int poly_fog_r = extra->fog_r;
714   int poly_fog_g = extra->fog_g;
715   int poly_fog_b = extra->fog_b;
716
503717   UINT32 *fb = &destmap->pix32(scanline);
504   UINT32 *zb = &K001005_zbuffer->pix32(scanline);
718   float *zb = (float*)&K001005_zbuffer->pix32(scanline);
719   int *x_mirror_table = tex_mirror_table[texture_mirror_x][texture_width];
720   int *y_mirror_table = tex_mirror_table[texture_mirror_y][texture_height];
505721
506722   for (x = extent->startx; x < extent->stopx; x++)
507723   {
508      UINT32 iz = (UINT32)z >> 16;
509      //int iu = u >> 16;
510      //int iv = v >> 16;
724      int ibri = (int)(bri);
725      int ifog = (int)(fog);
511726
512      if (iz < zb[x])
727      if (ibri < 0) ibri = 0; if (ibri > 255) ibri = 255;
728      if (ifog < 0) ifog = 0; if (ifog > 65536) ifog = 65536;
729
730      if (z <= zb[x])
513731      {
514732         float oow = 1.0f / w;
515733         UINT32 color;
r14632r14633
519737         iu = u * oow;
520738         iv = v * oow;
521739
522         iiu = texture_x + tex_mirror_table[texture_mirror_x][(iu >> 4) & 0x7f];
523         iiv = texture_y + tex_mirror_table[texture_mirror_y][(iv >> 4) & 0x7f];
740         iiu = texture_x + x_mirror_table[(iu >> 4) & 0x7f];
741         iiv = texture_y + y_mirror_table[(iv >> 4) & 0x7f];
742
524743         texel = texrom[((iiv & 0x1ff) * 512) + (iiu & 0x1ff)];
525744         color = K001006_palette[pal_chip][palette_index + texel];
526745
527746         if (color & 0xff000000)
528747         {
529            fb[x] = color;
530            zb[x] = iz;
748            int r = (color >> 16) & 0xff;
749            int g = (color >> 8) & 0xff;
750            int b = color & 0xff;
751
752            r = ((((r * poly_light_r * ibri) >> 16) * ifog) + (poly_fog_r * (65536 - ifog))) >> 16;
753            g = ((((g * poly_light_g * ibri) >> 16) * ifog) + (poly_fog_g * (65536 - ifog))) >> 16;
754            b = ((((b * poly_light_b * ibri) >> 16) * ifog) + (poly_fog_b * (65536 - ifog))) >> 16;
755
756            if (r < 0) r = 0; if (r > 255) r = 255;
757            if (g < 0) g = 0; if (g > 255) g = 255;
758            if (b < 0) b = 0; if (b > 255) b = 255;
759
760            fb[x] = 0xff000000 | (r << 16) | (g << 8) | b;
761            zb[x] = z;
531762         }
532763      }
533764
r14632r14633
535766      v += dv;
536767      z += dz;
537768      w += dw;
769      bri += dbri;
770      fog += dfog;
538771   }
539772}
540773
541774static void render_polygons(running_machine &machine)
542775{
543   int i, j;
544776   const rectangle visarea = machine.primary_screen->visible_area();
777   poly_vertex v[4];   
778   int poly_type;
779   int brightness;
545780
546//  mame_printf_debug("K001005_fifo_ptr = %08X\n", K001005_3d_fifo_ptr);
781   poly_vertex *vertex1;
782   poly_vertex *vertex2;
783   poly_vertex *vertex3;
784   poly_vertex *vertex4;
547785
548   for (i=0; i < K001005_3d_fifo_ptr; i++)
549   {
550      if (K001005_3d_fifo[i] == 0x80000003)
551      {
552         poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly);
553         poly_vertex v[4];
554         int r, g, b, a;
555         UINT32 color;
556         int index = i;
786   UINT32 *fifo = K001005_3d_fifo;
557787
558         ++index;
788   int index = 0;
559789
560         for (j=0; j < 4; j++)
561         {
562            int x, y;
790   do
791   {
792      UINT32 cmd = fifo[index++];
563793
564            x = ((K001005_3d_fifo[index] >>  0) & 0x3fff);
565            y = ((K001005_3d_fifo[index] >> 16) & 0x1fff);
566            x |= ((x & 0x2000) ? 0xffffc000 : 0);
567            y |= ((y & 0x1000) ? 0xffffe000 : 0);
568            ++index;
794      // Current guesswork on the command word bits:
795      // 0x01: Z-buffer disable?
796      // 0x02: Almost always set (only exception is 0x80000020 in Thunder Hurricane attract mode)
797      // 0x04:
798      // 0x08:
799      // 0x10: Texture mirror enable
800      // 0x20: Gouraud shading enable?
801      // 0x40: Unused?
802      // 0x80: Used by textured polygons.
569803
570            v[j].x = ((float)(x) / 16.0f) + 256.0f;
571            v[j].y = ((float)(-y) / 16.0f) + 192.0f;
572            v[j].p[0] = 0;   /* ??? */
573         }
574
575         ++index;
576
577         r = (K001005_3d_fifo[index] >>  0) & 0xff;
578         g = (K001005_3d_fifo[index] >>  8) & 0xff;
579         b = (K001005_3d_fifo[index] >> 16) & 0xff;
580         a = (K001005_3d_fifo[index] >> 24) & 0xff;
581         color = (a << 24) | (r << 16) | (g << 8) | (b);
582         ++index;
583
584         extra->color = color;
585         poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 1, &v[0], &v[1], &v[2]);
586         poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 1, &v[0], &v[2], &v[3]);
587//          poly_render_polygon(poly, K001005_bitmap[K001005_bitmap_page],  visarea, draw_scanline, 1, 4, v);
588
589         i = index - 1;
590      }
591      else if (K001005_3d_fifo[i] == 0x800000ae || K001005_3d_fifo[i] == 0x8000008e ||
592             K001005_3d_fifo[i] == 0x80000096 || K001005_3d_fifo[i] == 0x800000b6 ||
593             K001005_3d_fifo[i] == 0x8000002e || K001005_3d_fifo[i] == 0x8000000e ||
594             K001005_3d_fifo[i] == 0x80000016 || K001005_3d_fifo[i] == 0x80000036 ||
595             K001005_3d_fifo[i] == 0x800000aa || K001005_3d_fifo[i] == 0x800000a8 ||
596             K001005_3d_fifo[i] == 0x800000b2)
804      if (cmd == 0x800000ae || cmd == 0x8000008e || cmd == 0x80000096 || cmd == 0x800000b6 ||
805         cmd == 0x8000002e || cmd == 0x8000000e || cmd == 0x80000016 || cmd == 0x80000036 ||
806         cmd == 0x800000aa || cmd == 0x800000a8 || cmd == 0x800000b2 || cmd == 0x8000009e ||
807         cmd == 0x80000092 || cmd == 0x8000008a || cmd == 0x80000094 || cmd == 0x8000009a ||
808         cmd == 0x8000009c || cmd == 0x8000008c || cmd == 0x800000ac || cmd == 0x800000b4)
597809      {
598810         // 0x00: xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx    Command
599811         //
600812         // 0x01: xxxx---- -------- -------- --------    Texture palette
813         // 0x01: ----xx-- -------- -------- --------   Unknown flags, set by commands 0x7b...0x7e
814         // 0x01: ------xx x------- -------- --------   Texture width / 8 - 1
815         // 0x01: -------- -xxx---- -------- --------   Texture height / 8 - 1
601816         // 0x01: -------- -------x xxxx---- --------    Texture page
602817         // 0x01: -------- -------- ----x-x- x-x-x-x-    Texture X / 8
603818         // 0x01: -------- -------- -----x-x -x-x-x-x    Texture Y / 8
604819
820         // texture, Z
821
822         int tex_x, tex_y;
823         UINT32 color = 0;
605824         poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly);
606         poly_vertex v[4];
607         int tx, ty;
608         UINT32 color = 0;
609         UINT32 header;
610         UINT32 command;
611         int num_verts = 0;
612         int index = i;
613         int poly_type = 0;
614825
615         command = K001005_3d_fifo[index++];
616         header = K001005_3d_fifo[index++];
826         UINT32 header = fifo[index++];
617827
618         for (j=0; j < 4; j++)
828         int last_vertex = 0;
829         int vert_num = 0;
830         do
619831         {
620            INT16 u2, v2;
621832            int x, y, z;
622            int end = 0;
833            INT16 tu, tv;
623834
624            x = ((K001005_3d_fifo[index] >>  0) & 0x3fff);
625            y = ((K001005_3d_fifo[index] >> 16) & 0x1fff);
835            x = (fifo[index] >> 0) & 0x3fff;
836            y = (fifo[index] >> 16) & 0x1fff;
626837            x |= ((x & 0x2000) ? 0xffffc000 : 0);
627838            y |= ((y & 0x1000) ? 0xffffe000 : 0);
628839
629            poly_type = K001005_3d_fifo[index] & 0x4000;
630            end = K001005_3d_fifo[index] & 0x8000;
631            ++index;
840            poly_type = fifo[index] & 0x4000;      // 0 = triangle, 1 = quad
841            last_vertex = fifo[index] & 0x8000;
842            index++;
632843
633            z = K001005_3d_fifo[index];
634            ++index;
844            z = fifo[index] & 0xffffff00;
845            brightness = fifo[index] & 0xff;
846            index++;
635847
636            if (end)
848            if (last_vertex)
637849            {
638               color = K001005_3d_fifo[index];
639               ++index;
640
641               u2 = (K001005_3d_fifo[index] >> 16) & 0xffff;
642               v2 = (K001005_3d_fifo[index] >>  0) & 0xffff;
643               ++index;
850               color = fifo[index++];
644851            }
645            else
646            {
647               u2 = (K001005_3d_fifo[index] >> 16) & 0xffff;
648               v2 = (K001005_3d_fifo[index] >>  0) & 0xffff;
649               ++index;
650            }
651852
652            v[j].x = ((float)(x) / 16.0f) + 256.0f;
653            v[j].y = ((float)(-y) / 16.0f) + 192.0f;
654            v[j].p[0] = *(float*)(&z);
655            v[j].p[3] = 1.0f / v[j].p[0];
656            v[j].p[1] = u2 * v[j].p[3];
657            v[j].p[2] = v2 * v[j].p[3];
853            tu = (fifo[index] >> 16) & 0xffff;
854            tv = (fifo[index] & 0xffff);
855            index++;
658856
659            ++num_verts;
660
661            if (end)
662               break;
857            v[vert_num].x = ((float)(x) / 16.0f) + 256.0f;
858            v[vert_num].y = ((float)(-y) / 16.0f) + 192.0f + 8;
859            v[vert_num].p[POLY_Z] = *(float*)(&z);
860            v[vert_num].p[POLY_W] = 1.0f / v[vert_num].p[POLY_Z];
861            v[vert_num].p[POLY_U] = tu * v[vert_num].p[POLY_W];
862            v[vert_num].p[POLY_V] = tv * v[vert_num].p[POLY_W];
863            v[vert_num].p[POLY_BRI] = brightness;
864            v[vert_num].p[POLY_FOG] = (1.0f / (exp( ((v[vert_num].p[POLY_Z] * fog_density) / far_z) * ((v[vert_num].p[POLY_Z] * fog_density) / far_z) ))) * 65536.0f;
865            //v[vert_num].p[POLY_FOG] = (1.0f / (exp( ((v[vert_num].p[POLY_Z] * fog_density) / far_z) ))) * 65536.0f;
866            if (v[vert_num].p[POLY_FOG] < 0.0f) v[vert_num].p[POLY_FOG] = 0.0f;
867            if (v[vert_num].p[POLY_FOG] > 65536.0f) v[vert_num].p[POLY_FOG] = 65536.0f;
868            vert_num++;
663869         }
870         while (!last_vertex);
664871
665         ty = ((header & 0x400) >> 5) |
666             ((header & 0x100) >> 4) |
667             ((header & 0x040) >> 3) |
668             ((header & 0x010) >> 2) |
669             ((header & 0x004) >> 1) |
670             ((header & 0x001) >> 0);
872         tex_y = ((header & 0x400) >> 5) |
873               ((header & 0x100) >> 4) |
874               ((header & 0x040) >> 3) |
875               ((header & 0x010) >> 2) |
876               ((header & 0x004) >> 1) |
877               ((header & 0x001) >> 0);
671878
672         tx = ((header & 0x800) >> 6) |
673             ((header & 0x200) >> 5) |
674             ((header & 0x080) >> 4) |
675             ((header & 0x020) >> 3) |
676             ((header & 0x008) >> 2) |
677             ((header & 0x002) >> 1);
879         tex_x = ((header & 0x800) >> 6) |
880               ((header & 0x200) >> 5) |
881               ((header & 0x080) >> 4) |
882               ((header & 0x020) >> 3) |
883               ((header & 0x008) >> 2) |
884               ((header & 0x002) >> 1);
678885
679         extra->texture_x = tx * 8;
680         extra->texture_y = ty * 8;
681
886         extra->texture_x = tex_x * 8;
887         extra->texture_y = tex_y * 8;
888         extra->texture_width = (header >> 23) & 0x7;
889         extra->texture_height = (header >> 20) & 0x7;
682890         extra->texture_page = (header >> 12) & 0x1f;
683891         extra->texture_palette = (header >> 28) & 0xf;
684
685         extra->texture_mirror_x = ((command & 0x10) ? 0x2 : 0) | ((header & 0x00400000) ? 0x1 : 0);
686         extra->texture_mirror_y = ((command & 0x10) ? 0x2 : 0) | ((header & 0x00400000) ? 0x1 : 0);
687
892         extra->texture_mirror_x = ((cmd & 0x10) ? 0x1 : 0);
893         extra->texture_mirror_y = ((cmd & 0x10) ? 0x1 : 0);
688894         extra->color = color;
895         extra->light_r = light_r;      extra->light_g = light_g;      extra->light_b = light_b;
896         extra->ambient_r = ambient_r;   extra->ambient_g = ambient_g;   extra->ambient_b = ambient_b;
897         extra->fog_r = fog_r;         extra->fog_g = fog_g;         extra->fog_b = fog_b;
898         extra->flags = cmd;
689899
690         if (num_verts < 3)
900         if ((cmd & 0x20) == 0)      // possibly enable flag for gouraud shading (fixes some shading errors)
691901         {
692            poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 4, &prev_v[2], &v[0], &v[1]);
693            if (prev_poly_type)
694               poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 4, &prev_v[2], &prev_v[3], &v[0]);
695//              if (prev_poly_type)
696//                  poly_render_quad(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 4, &prev_v[2], &prev_v[3], &v[0], &v[1]);
697//              else
698//                  poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 4, &prev_v[2], &v[0], &v[1]);
902            v[0].p[POLY_BRI] = brightness;
903            v[1].p[POLY_BRI] = brightness;
904         }
699905
700            memcpy(&prev_v[0], &prev_v[2], sizeof(poly_vertex));
701            memcpy(&prev_v[1], &prev_v[3], sizeof(poly_vertex));
702            memcpy(&prev_v[2], &v[0], sizeof(poly_vertex));
703            memcpy(&prev_v[3], &v[1], sizeof(poly_vertex));
704         }
705         else
906         if (poly_type == 0)      // triangle
706907         {
707            poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 4, &v[0], &v[1], &v[2]);
708            if (num_verts > 3)
709               poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 4, &v[2], &v[3], &v[0]);
710//              poly_render_polygon(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 4, num_verts, v);
908            if (vert_num == 1)
909            {
910               vertex1 = &prev_v[2];
911               vertex2 = &prev_v[3];
912               vertex3 = &v[0];
913            }
914            else if (vert_num == 2)
915            {
916               vertex1 = &prev_v[3];
917               vertex2 = &v[0];
918               vertex3 = &v[1];
919            }
920            else
921            {
922               vertex1 = &v[0];
923               vertex2 = &v[1];
924               vertex3 = &v[2];
925            }
711926
712            memcpy(prev_v, v, sizeof(poly_vertex) * 4);
927            poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 6, vertex1, vertex2, vertex3);
928
929            memcpy(&prev_v[1], vertex1, sizeof(poly_vertex));
930            memcpy(&prev_v[2], vertex2, sizeof(poly_vertex));
931            memcpy(&prev_v[3], vertex3, sizeof(poly_vertex));
713932         }
714
715         prev_poly_type = poly_type;
716
717         while ((K001005_3d_fifo[index] & 0xffffff00) != 0x80000000 && index < K001005_3d_fifo_ptr)
933         else               // quad
718934         {
719            poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly);
720            int new_verts = 0;
721
722            if (poly_type)
935            if (vert_num == 1)
723936            {
724               memcpy(&v[0], &prev_v[2], sizeof(poly_vertex));
725               memcpy(&v[1], &prev_v[3], sizeof(poly_vertex));
937               vertex1 = &prev_v[1];
938               vertex2 = &prev_v[2];
939               vertex3 = &prev_v[3];
940               vertex4 = &v[0];
726941            }
942            else if (vert_num == 2)
943            {
944               vertex1 = &prev_v[2];
945               vertex2 = &prev_v[3];
946               vertex3 = &v[0];
947               vertex4 = &v[1];
948            }
949            else if (vert_num == 3)
950            {
951               vertex1 = &prev_v[3];
952               vertex2 = &v[0];
953               vertex3 = &v[1];
954               vertex4 = &v[2];
955            }
727956            else
728957            {
729               memcpy(&v[0], &prev_v[1], sizeof(poly_vertex));
730               memcpy(&v[1], &prev_v[2], sizeof(poly_vertex));
958               vertex1 = &v[0];
959               vertex2 = &v[1];
960               vertex3 = &v[2];
961               vertex4 = &v[3];
731962            }
732963
733            for (j=2; j < 4; j++)
734            {
735               INT16 u2, v2;
964            poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 6, vertex1, vertex2, vertex3);
965            poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 6, vertex3, vertex4, vertex1);
966
967            memcpy(&prev_v[0], vertex1, sizeof(poly_vertex));
968            memcpy(&prev_v[1], vertex2, sizeof(poly_vertex));
969            memcpy(&prev_v[2], vertex3, sizeof(poly_vertex));
970            memcpy(&prev_v[3], vertex4, sizeof(poly_vertex));
971         }
972
973         while ((fifo[index] & 0xffffff00) != 0x80000000 && index < K001005_3d_fifo_ptr)
974         {
975            poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly);
976            int new_verts = 0;
977
978            memcpy(&v[0], &prev_v[2], sizeof(poly_vertex));
979            memcpy(&v[1], &prev_v[3], sizeof(poly_vertex));
980
981            last_vertex = 0;
982            vert_num = 2;
983            do
984            {               
736985               int x, y, z;
737               int end = 0;
986               INT16 tu, tv;
738987
739988               x = ((K001005_3d_fifo[index] >>  0) & 0x3fff);
740989               y = ((K001005_3d_fifo[index] >> 16) & 0x1fff);
741990               x |= ((x & 0x2000) ? 0xffffc000 : 0);
742991               y |= ((y & 0x1000) ? 0xffffe000 : 0);
743992
744               poly_type = K001005_3d_fifo[index] & 0x4000;
745               end = K001005_3d_fifo[index] & 0x8000;
746               ++index;
993               poly_type = fifo[index] & 0x4000;
994               last_vertex = fifo[index] & 0x8000;
995               index++;
747996
748               z = K001005_3d_fifo[index];
749               ++index;
750
751               if (end)
997               z = fifo[index] & 0xffffff00;
998               brightness = fifo[index] & 0xff;
999               index++;
1000               
1001               if (last_vertex)
7521002               {
753                  color = K001005_3d_fifo[index];
754                  ++index;
755
756                  u2 = (K001005_3d_fifo[index] >> 16) & 0xffff;
757                  v2 = (K001005_3d_fifo[index] >>  0) & 0xffff;
758                  ++index;
1003                  color = fifo[index++];
7591004               }
760               else
761               {
762                  u2 = (K001005_3d_fifo[index] >> 16) & 0xffff;
763                  v2 = (K001005_3d_fifo[index] >>  0) & 0xffff;
764                  ++index;
765               }
7661005
767               v[j].x = ((float)(x) / 16.0f) + 256.0f;
768               v[j].y = ((float)(-y) / 16.0f) + 192.0f;
769               v[j].p[0] = *(float*)(&z);
770               v[j].p[3] = 1.0f / v[j].p[0];
771               v[j].p[1] = u2 * v[j].p[3];
772               v[j].p[2] = v2 * v[j].p[3];
1006               tu = (K001005_3d_fifo[index] >> 16) & 0xffff;
1007               tv = (K001005_3d_fifo[index] >>  0) & 0xffff;
1008               index++;
7731009
774               ++new_verts;
1010               v[vert_num].x = ((float)(x) / 16.0f) + 256.0f;
1011               v[vert_num].y = ((float)(-y) / 16.0f) + 192.0f + 8;
1012               v[vert_num].p[POLY_Z] = *(float*)(&z);
1013               v[vert_num].p[POLY_W] = 1.0f / v[vert_num].p[POLY_Z];
1014               v[vert_num].p[POLY_U] = tu * v[vert_num].p[POLY_W];
1015               v[vert_num].p[POLY_V] = tv * v[vert_num].p[POLY_W];
1016               v[vert_num].p[POLY_BRI] = brightness;
1017               v[vert_num].p[POLY_FOG] = (1.0f / (exp( ((v[vert_num].p[POLY_Z] * fog_density) / far_z) * ((v[vert_num].p[POLY_Z] * fog_density) / far_z) ))) * 65536.0f;
1018               //v[vert_num].p[POLY_FOG] = (1.0f / (exp( ((v[vert_num].p[POLY_Z] * fog_density) / far_z) ))) * 65536.0f;
1019               if (v[vert_num].p[POLY_FOG] < 0.0f) v[vert_num].p[POLY_FOG] = 0.0f;
1020               if (v[vert_num].p[POLY_FOG] > 65536.0f) v[vert_num].p[POLY_FOG] = 65536.0f;
7751021
776               if (end)
777                  break;
1022               vert_num++;
1023               new_verts++;
7781024            }
1025            while (!last_vertex);
7791026
780            extra->texture_x = tx * 8;
781            extra->texture_y = ty * 8;
1027            extra->texture_x = tex_x * 8;
1028            extra->texture_y = tex_y * 8;
1029            extra->texture_width = (header >> 23) & 0x7;
1030            extra->texture_height = (header >> 20) & 0x7;
7821031
7831032            extra->texture_page = (header >> 12) & 0x1f;
7841033            extra->texture_palette = (header >> 28) & 0xf;
7851034
786            extra->texture_mirror_x = ((command & 0x10) ? 0x2 : 0) | ((header & 0x00400000) ? 0x1 : 0);
787            extra->texture_mirror_y = ((command & 0x10) ? 0x2 : 0) | ((header & 0x00400000) ? 0x1 : 0);
1035            extra->texture_mirror_x = ((cmd & 0x10) ? 0x1 : 0);// & ((header & 0x00400000) ? 0x1 : 0);
1036            extra->texture_mirror_y = ((cmd & 0x10) ? 0x1 : 0);// & ((header & 0x00400000) ? 0x1 : 0);
7881037
7891038            extra->color = color;
1039            extra->light_r = light_r;      extra->light_g = light_g;      extra->light_b = light_b;
1040            extra->ambient_r = ambient_r;   extra->ambient_g = ambient_g;   extra->ambient_b = ambient_b;
1041            extra->fog_r = fog_r;         extra->fog_g = fog_g;         extra->fog_b = fog_b;
1042            extra->flags = cmd;
7901043
791            poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 4, &v[0], &v[1], &v[2]);
792            if (new_verts > 1)
793               poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 4, &v[2], &v[3], &v[0]);
794//              poly_render_polygon(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 4, new_verts + 2, v);
1044            if ((cmd & 0x20) == 0)      // possibly enable flag for gouraud shading (fixes some shading errors)
1045            {
1046               v[0].p[POLY_BRI] = brightness;
1047               v[1].p[POLY_BRI] = brightness;
1048            }
7951049
796            memcpy(prev_v, v, sizeof(poly_vertex) * 4);
1050            if (new_verts == 1)
1051            {
1052               poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 6, &v[0], &v[1], &v[2]);
1053               
1054               memcpy(&prev_v[1], &v[0], sizeof(poly_vertex));
1055               memcpy(&prev_v[2], &v[1], sizeof(poly_vertex));
1056               memcpy(&prev_v[3], &v[2], sizeof(poly_vertex));
1057            }
1058            else if (new_verts == 2)
1059            {
1060               poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 6, &v[0], &v[1], &v[2]);
1061               poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 6, &v[2], &v[3], &v[0]);
1062
1063               memcpy(&prev_v[0], &v[0], sizeof(poly_vertex));
1064               memcpy(&prev_v[1], &v[1], sizeof(poly_vertex));
1065               memcpy(&prev_v[2], &v[2], sizeof(poly_vertex));
1066               memcpy(&prev_v[3], &v[3], sizeof(poly_vertex));
1067            }
7971068         };
798
799         i = index - 1;
8001069      }
801      else if (K001005_3d_fifo[i] == 0x80000006 || K001005_3d_fifo[i] == 0x80000026 ||
802             K001005_3d_fifo[i] == 0x80000020 || K001005_3d_fifo[i] == 0x80000022)
1070      else if (cmd == 0x80000006 || cmd == 0x80000026 || cmd == 0x80000002 || cmd == 0x80000020 || cmd == 0x80000022)
8031071      {
1072         // no texture, Z
1073
8041074         poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly);
805         poly_vertex v[4];
1075         UINT32 color;
8061076         int r, g, b, a;
807         UINT32 color;
808         int num_verts = 0;
809         int index = i;
810         int poly_type = 0;
8111077
812         ++index;
813
814         for (j=0; j < 4; j++)
1078         int last_vertex = 0;
1079         int vert_num = 0;
1080         do
8151081         {
8161082            int x, y, z;
817            int end = 0;
8181083
819            x = ((K001005_3d_fifo[index] >>  0) & 0x3fff);
820            y = ((K001005_3d_fifo[index] >> 16) & 0x1fff);
1084            x = (fifo[index] >> 0) & 0x3fff;
1085            y = (fifo[index] >> 16) & 0x1fff;
8211086            x |= ((x & 0x2000) ? 0xffffc000 : 0);
8221087            y |= ((y & 0x1000) ? 0xffffe000 : 0);
8231088
824            poly_type = K001005_3d_fifo[index] & 0x4000;
825            end = K001005_3d_fifo[index] & 0x8000;
826            ++index;
1089            poly_type = fifo[index] & 0x4000;      // 0 = triangle, 1 = quad
1090            last_vertex = fifo[index] & 0x8000;
1091            index++;
8271092
828            z = K001005_3d_fifo[index];
829            ++index;
1093            z = fifo[index] & 0xffffff00;
1094            brightness = fifo[index] & 0xff;
1095            index++;
8301096
831            v[j].x = ((float)(x) / 16.0f) + 256.0f;
832            v[j].y = ((float)(-y) / 16.0f) + 192.0f;
833            v[j].p[0] = *(float*)(&z);
834
835            ++num_verts;
836
837            if (end)
838               break;
1097            v[vert_num].x = ((float)(x) / 16.0f) + 256.0f;
1098            v[vert_num].y = ((float)(-y) / 16.0f) + 192.0f + 8;
1099            v[vert_num].p[POLY_Z] = *(float*)(&z);
1100            v[vert_num].p[POLY_BRI] = brightness;
1101            v[vert_num].p[POLY_FOG] = (1.0f / (exp( ((v[vert_num].p[POLY_Z] * fog_density) / far_z) * ((v[vert_num].p[POLY_Z] * fog_density) / far_z) ))) * 65536.0f;
1102            //v[vert_num].p[POLY_FOG] = (1.0f / (exp( ((v[vert_num].p[POLY_Z] * fog_density) / far_z) ))) * 65536.0f;
1103            if (v[vert_num].p[POLY_FOG] < 0.0f) v[vert_num].p[POLY_FOG] = 0.0f;
1104            if (v[vert_num].p[POLY_FOG] > 65536.0f) v[vert_num].p[POLY_FOG] = 65536.0f;
1105            vert_num++;
8391106         }
1107         while (!last_vertex);
8401108
841         r = (K001005_3d_fifo[index] >>  0) & 0xff;
842         g = (K001005_3d_fifo[index] >>  8) & 0xff;
843         b = (K001005_3d_fifo[index] >> 16) & 0xff;
844         a = (K001005_3d_fifo[index] >> 24) & 0xff;
1109         r = (fifo[index] >>  0) & 0xff;
1110         g = (fifo[index] >>  8) & 0xff;
1111         b = (fifo[index] >> 16) & 0xff;
1112         a = (fifo[index] >> 24) & 0xff;   
8451113         color = (a << 24) | (r << 16) | (g << 8) | (b);
8461114         index++;
8471115
8481116         extra->color = color;
1117         extra->light_r = light_r;      extra->light_g = light_g;      extra->light_b = light_b;
1118         extra->ambient_r = ambient_r;   extra->ambient_g = ambient_g;   extra->ambient_b = ambient_b;
1119         extra->fog_r = fog_r;         extra->fog_g = fog_g;         extra->fog_b = fog_b;
1120         extra->flags = cmd;
8491121
850         poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 1, &v[0], &v[1], &v[2]);
851         if (num_verts > 3)
852            poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 1, &v[2], &v[3], &v[0]);
853//          poly_render_polygon(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 1, num_verts, v);
1122         if ((cmd & 0x20) == 0)      // possibly enable flag for gouraud shading (fixes some shading errors)
1123         {
1124            v[0].p[POLY_BRI] = brightness;
1125            v[1].p[POLY_BRI] = brightness;
1126         }
8541127
855         memcpy(prev_v, v, sizeof(poly_vertex) * 4);
1128         if (poly_type == 0)      // triangle
1129         {
1130            if (vert_num == 1)
1131            {
1132               vertex1 = &prev_v[2];
1133               vertex2 = &prev_v[3];
1134               vertex3 = &v[0];
1135            }
1136            else if (vert_num == 2)
1137            {
1138               vertex1 = &prev_v[3];
1139               vertex2 = &v[0];
1140               vertex3 = &v[1];
1141            }
1142            else
1143            {
1144               vertex1 = &v[0];
1145               vertex2 = &v[1];
1146               vertex3 = &v[2];
1147            }
8561148
857         while ((K001005_3d_fifo[index] & 0xffffff00) != 0x80000000 && index < K001005_3d_fifo_ptr)
1149            poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 3, vertex1, vertex2, vertex3);
1150
1151            memcpy(&prev_v[1], vertex1, sizeof(poly_vertex));
1152            memcpy(&prev_v[2], vertex2, sizeof(poly_vertex));
1153            memcpy(&prev_v[3], vertex3, sizeof(poly_vertex));
1154         }
1155         else               // quad
8581156         {
859            poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly);
860            int new_verts = 0;
861
862            if (poly_type)
1157            if (vert_num == 1)
8631158            {
864               memcpy(&v[0], &prev_v[2], sizeof(poly_vertex));
865               memcpy(&v[1], &prev_v[3], sizeof(poly_vertex));
1159               vertex1 = &prev_v[1];
1160               vertex2 = &prev_v[2];
1161               vertex3 = &prev_v[3];
1162               vertex4 = &v[0];
8661163            }
1164            else if (vert_num == 2)
1165            {
1166               vertex1 = &prev_v[2];
1167               vertex2 = &prev_v[3];
1168               vertex3 = &v[0];
1169               vertex4 = &v[1];
1170            }
1171            else if (vert_num == 3)
1172            {
1173               vertex1 = &prev_v[3];
1174               vertex2 = &v[0];
1175               vertex3 = &v[1];
1176               vertex4 = &v[2];
1177            }
8671178            else
8681179            {
869               memcpy(&v[0], &prev_v[1], sizeof(poly_vertex));
870               memcpy(&v[1], &prev_v[2], sizeof(poly_vertex));
1180               vertex1 = &v[0];
1181               vertex2 = &v[1];
1182               vertex3 = &v[2];
1183               vertex4 = &v[3];
8711184            }
8721185
873            for (j=2; j < 4; j++)
1186            poly_render_quad(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 3, vertex1, vertex2, vertex3, vertex4);           
1187
1188            memcpy(&prev_v[0], vertex1, sizeof(poly_vertex));
1189            memcpy(&prev_v[1], vertex2, sizeof(poly_vertex));
1190            memcpy(&prev_v[2], vertex3, sizeof(poly_vertex));
1191            memcpy(&prev_v[3], vertex4, sizeof(poly_vertex));
1192         }
1193
1194         while ((fifo[index] & 0xffffff00) != 0x80000000 && index < K001005_3d_fifo_ptr)
1195         {
1196            int new_verts = 0;
1197
1198            memcpy(&v[0], &prev_v[2], sizeof(poly_vertex));
1199            memcpy(&v[1], &prev_v[3], sizeof(poly_vertex));
1200
1201            last_vertex = 0;
1202            vert_num = 2;
1203            do
8741204            {
8751205               int x, y, z;
876               int end = 0;
8771206
878               x = ((K001005_3d_fifo[index] >>  0) & 0x3fff);
879               y = ((K001005_3d_fifo[index] >> 16) & 0x1fff);
1207               x = ((fifo[index] >>  0) & 0x3fff);
1208               y = ((fifo[index] >> 16) & 0x1fff);
8801209               x |= ((x & 0x2000) ? 0xffffc000 : 0);
8811210               y |= ((y & 0x1000) ? 0xffffe000 : 0);
8821211
883               poly_type = K001005_3d_fifo[index] & 0x4000;
884               end = K001005_3d_fifo[index] & 0x8000;
885               ++index;
1212               poly_type = fifo[index] & 0x4000;
1213               last_vertex = fifo[index] & 0x8000;
1214               index++;
8861215
887               z = K001005_3d_fifo[index];
888               ++index;
1216               z = fifo[index] & 0xffffff00;
1217               brightness = fifo[index] & 0xff;
1218               index++;
8891219
890               v[j].x = ((float)(x) / 16.0f) + 256.0f;
891               v[j].y = ((float)(-y) / 16.0f) + 192.0f;
892               v[j].p[0] = *(float*)(&z);
1220               v[vert_num].x = ((float)(x) / 16.0f) + 256.0f;
1221               v[vert_num].y = ((float)(-y) / 16.0f) + 192.0f + 8;
1222               v[vert_num].p[POLY_Z] = *(float*)(&z);
1223               v[vert_num].p[POLY_BRI] = brightness;
1224               v[vert_num].p[POLY_FOG] = (1.0f / (exp( ((v[vert_num].p[POLY_Z] * fog_density) / far_z) * ((v[vert_num].p[POLY_Z] * fog_density) / far_z) ))) * 65536.0f;
1225               //v[vert_num].p[POLY_FOG] = (1.0f / (exp( ((v[vert_num].p[POLY_Z] * fog_density) / far_z) ))) * 65536.0f;
1226               if (v[vert_num].p[POLY_FOG] < 0.0f) v[vert_num].p[POLY_FOG] = 0.0f;
1227               if (v[vert_num].p[POLY_FOG] > 65536.0f) v[vert_num].p[POLY_FOG] = 65536.0f;
8931228
894               ++new_verts;
895
896               if (end)
897                  break;
1229               vert_num++;
1230               new_verts++;
8981231            }
1232            while (!last_vertex);
8991233
900            r = (K001005_3d_fifo[index] >>  0) & 0xff;
901            g = (K001005_3d_fifo[index] >>  8) & 0xff;
902            b = (K001005_3d_fifo[index] >> 16) & 0xff;
903            a = (K001005_3d_fifo[index] >> 24) & 0xff;
1234            r = (fifo[index] >>  0) & 0xff;
1235            g = (fifo[index] >>  8) & 0xff;
1236            b = (fifo[index] >> 16) & 0xff;
1237            a = (fifo[index] >> 24) & 0xff;
9041238            color = (a << 24) | (r << 16) | (g << 8) | (b);
9051239            index++;
9061240
9071241            extra->color = color;
1242            extra->light_r = light_r;      extra->light_g = light_g;      extra->light_b = light_b;
1243            extra->ambient_r = ambient_r;   extra->ambient_g = ambient_g;   extra->ambient_b = ambient_b;
1244            extra->fog_r = fog_r;         extra->fog_g = fog_g;         extra->fog_b = fog_b;
1245            extra->flags = cmd;
9081246
909            poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 1, &v[0], &v[1], &v[2]);
910            if (new_verts > 1)
911               poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 1, &v[0], &v[2], &v[3]);
912//              poly_render_polygon(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 1, new_verts + 2, v);
1247            if ((cmd & 0x20) == 0)      // possibly enable flag for gouraud shading (fixes some shading errors)
1248            {
1249               v[0].p[POLY_BRI] = brightness;
1250               v[1].p[POLY_BRI] = brightness;
1251            }
9131252
914            memcpy(prev_v, v, sizeof(poly_vertex) * 4);
915         };
1253            if (new_verts == 1)
1254            {
1255               poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 3, &v[0], &v[1], &v[2]);
1256               
1257               memcpy(&prev_v[1], &v[0], sizeof(poly_vertex));
1258               memcpy(&prev_v[2], &v[1], sizeof(poly_vertex));
1259               memcpy(&prev_v[3], &v[2], sizeof(poly_vertex));
1260            }
1261            else if (new_verts == 2)
1262            {
1263               poly_render_quad(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 3, &v[0], &v[1], &v[2], &v[3]);
9161264
917         i = index - 1;
1265               memcpy(&prev_v[0], &v[0], sizeof(poly_vertex));
1266               memcpy(&prev_v[1], &v[1], sizeof(poly_vertex));
1267               memcpy(&prev_v[2], &v[2], sizeof(poly_vertex));
1268               memcpy(&prev_v[3], &v[3], sizeof(poly_vertex));
1269            }
1270         }
9181271      }
919      else if (K001005_3d_fifo[i] == 0x80000000)
1272      else if (cmd == 0x80000003 || cmd == 0x80000001)
9201273      {
1274         // no texture, no Z
9211275
1276         poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly);
1277         int r, g, b, a;
1278         UINT32 color;
1279
1280         int last_vertex = 0;
1281         int vert_num = 0;
1282         do
1283         {
1284            int x, y;
1285
1286            x = ((fifo[index] >>  0) & 0x3fff);
1287            y = ((fifo[index] >> 16) & 0x1fff);
1288            x |= ((x & 0x2000) ? 0xffffc000 : 0);
1289            y |= ((y & 0x1000) ? 0xffffe000 : 0);
1290
1291            poly_type = fifo[index] & 0x4000;
1292            last_vertex = fifo[index] & 0x8000;
1293            index++;
1294
1295            v[vert_num].x = ((float)(x) / 16.0f) + 256.0f;
1296            v[vert_num].y = ((float)(-y) / 16.0f) + 192.0f + 8;
1297            vert_num++;
1298         }
1299         while (!last_vertex);
1300
1301         // unknown word
1302         index++;
1303
1304         r = (fifo[index] >>  0) & 0xff;
1305         g = (fifo[index] >>  8) & 0xff;
1306         b = (fifo[index] >> 16) & 0xff;
1307         a = (fifo[index] >> 24) & 0xff;
1308         color = (a << 24) | (r << 16) | (g << 8) | (b);
1309         index++;
1310
1311         extra->color = color;
1312         extra->flags = cmd;
1313
1314         if (poly_type == 0)
1315         {
1316            poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_2d, 0, &v[0], &v[1], &v[2]);
1317         }
1318         else
1319         {
1320            poly_render_quad(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_2d, 0, &v[0], &v[1], &v[2], &v[3]);
1321         }
9221322      }
923      else if ((K001005_3d_fifo[i] & 0xffffff00) == 0x80000000)
1323      else if (cmd == 0x8000008b)
9241324      {
1325         // texture, no Z
1326
1327         int tex_x, tex_y;
1328         poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly);
1329         int r, g, b, a;
1330         UINT32 color = 0;
1331
1332         UINT32 header = fifo[index++];
1333
1334         int last_vertex = 0;
1335         int vert_num = 0;
1336         do
1337         {
1338            int x, y;
1339            INT16 tu, tv;
1340
1341            x = ((fifo[index] >>  0) & 0x3fff);
1342            y = ((fifo[index] >> 16) & 0x1fff);
1343            x |= ((x & 0x2000) ? 0xffffc000 : 0);
1344            y |= ((y & 0x1000) ? 0xffffe000 : 0);
1345
1346            poly_type = fifo[index] & 0x4000;
1347            last_vertex = fifo[index] & 0x8000;
1348            index++;
1349
1350            if (last_vertex)
1351            {
1352               // unknown word
1353               index++;
1354
1355               color = fifo[index++];
1356            }
1357
1358            tu = (fifo[index] >> 16) & 0xffff;
1359            tv = (fifo[index] & 0xffff);
1360            index++;
1361
1362            v[vert_num].x = ((float)(x) / 16.0f) + 256.0f;
1363            v[vert_num].y = ((float)(-y) / 16.0f) + 192.0f + 8;
1364            v[vert_num].p[POLY_U] = tu;
1365            v[vert_num].p[POLY_V] = tv;
1366            vert_num++;
1367         }
1368         while (!last_vertex);
1369
1370         r = (color >>  0) & 0xff;
1371         g = (color >>  8) & 0xff;
1372         b = (color >> 16) & 0xff;
1373         a = (color >> 24) & 0xff;
1374         extra->color = (a << 24) | (r << 16) | (g << 8) | (b);
1375         extra->flags = cmd;
1376
1377         tex_y = ((header & 0x400) >> 5) |
1378               ((header & 0x100) >> 4) |
1379               ((header & 0x040) >> 3) |
1380               ((header & 0x010) >> 2) |
1381               ((header & 0x004) >> 1) |
1382               ((header & 0x001) >> 0);
1383
1384         tex_x = ((header & 0x800) >> 6) |
1385               ((header & 0x200) >> 5) |
1386               ((header & 0x080) >> 4) |
1387               ((header & 0x020) >> 3) |
1388               ((header & 0x008) >> 2) |
1389               ((header & 0x002) >> 1);
1390
1391         extra->texture_x = tex_x * 8;
1392         extra->texture_y = tex_y * 8;
1393         extra->texture_width = (header >> 23) & 0x7;
1394         extra->texture_height = (header >> 20) & 0x7;
1395
1396         extra->texture_page = (header >> 12) & 0x1f;
1397         extra->texture_palette = (header >> 28) & 0xf;
1398
1399         extra->texture_mirror_x = ((cmd & 0x10) ? 0x1 : 0);
1400         extra->texture_mirror_y = ((cmd & 0x10) ? 0x1 : 0);
1401
1402         if (poly_type == 0)
1403         {
1404            poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_2d_tex, 5, &v[0], &v[1], &v[2]);
1405         }
1406         else
1407         {
1408            poly_render_quad(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_2d_tex, 5, &v[0], &v[1], &v[2], &v[3]);
1409         }
1410      }
1411      else if (cmd == 0x80000000)
1412      {
1413
1414      }
1415      else if (cmd == 0x80000018)
1416      {
1417
1418      }
1419      else if ((cmd & 0xffffff00) == 0x80000000)
1420      {
9251421         /*
926            mame_printf_debug("Unknown polygon type %08X:\n", K001005_3d_fifo[i]);
927            for (j=0; j < 0x20; j++)
928            {
929                mame_printf_debug("  %02X: %08X\n", j, K001005_3d_fifo[i+1+j]);
930            }
931            mame_printf_debug("\n");
932            */
1422         mame_printf_debug("Unknown polygon type %08X:\n", fifo[index-1]);
1423         for (int i=0; i < 0x20; i++)
1424         {
1425            mame_printf_debug("  %02X: %08X\n", i, fifo[index+i]);
1426         }
1427         mame_printf_debug("\n");
1428         */
1429
1430         printf("Unknown polygon type %08X:\n", fifo[index-1]);
1431         for (int i=0; i < 0x20; i++)
1432         {
1433            printf("  %02X: %08X\n", i, fifo[index+i]);
1434         }
1435         printf("\n");
9331436      }
1437      else
1438      {
1439
1440      }
9341441   }
1442   while (index < K001005_3d_fifo_ptr);
9351443}
9361444
1445
9371446void K001005_draw(bitmap_rgb32 &bitmap, const rectangle &cliprect)
9381447{
9391448   int i, j;
r14632r14633
9611470
9621471   //if (K001005_status == 2)
9631472   {
1473      float zvalue = ZBUFFER_MAX;
9641474      K001005_bitmap[K001005_bitmap_page]->fill(machine.pens[0]&0x00ffffff, K001005_cliprect);
965      K001005_zbuffer->fill(0xffffffff, K001005_cliprect);
1475      K001005_zbuffer->fill(*(int*)&zvalue, K001005_cliprect);
9661476   }
9671477}
9681478
1479/*
9691480static int tick = 0;
9701481static int debug_tex_page = 0;
9711482static int debug_tex_palette = 0;
1483*/
9721484
9731485VIDEO_START( gticlub )
9741486{
9751487   gticlub_led_reg[0] = gticlub_led_reg[1] = 0x7f;
1488   /*
9761489   tick = 0;
9771490   debug_tex_page = 0;
9781491   debug_tex_palette = 0;
1492   */
9791493
9801494   K001006_init(machine);
9811495   K001005_init(machine);
r14632r14633
9911505
9921506   k001604_draw_front_layer(k001604, bitmap, cliprect);
9931507
1508#if 0
9941509   tick++;
9951510   if( tick >= 5 ) {
9961511      tick = 0;
r14632r14633
10171532         debug_tex_palette = 0;
10181533   }
10191534
1020#if 0
10211535    if (debug_tex_page > 0)
10221536    {
10231537        char string[200];
src/mame/drivers/20pacgal.c
r14632r14633
294294INPUT_PORTS_END
295295
296296
297/* Note: 25pacman Control Panel functions the same as 20pacgal, even if Right P1/P2 start are not shown during Switch Test */
297298static INPUT_PORTS_START( 25pacman )
298299   PORT_INCLUDE(20pacgal)
299300
300   PORT_MODIFY("P2")
301   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNUSED )
302   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START1 )
303   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_START2 )
304   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
305
306301   PORT_MODIFY("SERVICE")
307   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNKNOWN )
308302   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_UNKNOWN )
309303   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNKNOWN )
310304   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNKNOWN )
311305   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_UNKNOWN )
312306   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_UNKNOWN )
313307   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_UNKNOWN )
314   PORT_SERVICE_NO_TOGGLE( 0x80, IP_ACTIVE_LOW )
315308INPUT_PORTS_END
316309
317310
318311
319
320312/*************************************
321313 *
322314 *  Machine driver
src/mame/drivers/konamigv.c
r14632r14633
765765   ROM_REGION16_BE( 0x0000080, "eeprom", 0 ) /* default eeprom */
766766   ROM_LOAD( "susume.25c",   0x000000, 0x000080, CRC(52f17df7) SHA1(b8ad7787b0692713439d7d9bebfa0c801c806006) )
767767   DISK_REGION( "cdrom" )
768   DISK_IMAGE_READONLY( "gv027j1", 0, SHA1(ad474c60ee68202324a31cc106f2054dc465f4b7) )
768   DISK_IMAGE_READONLY( "gv027j1", 0, BAD_DUMP SHA1(e7e6749ac65de7771eb8fed7d5eefaec3f902255) )
769769ROM_END
770770
771771ROM_START( hyperath )
r14632r14633
775775   ROM_LOAD( "hyperath.25c", 0x000000, 0x000080, CRC(20a8c435) SHA1(a0f203a999757fba68b391c525ac4b9684a57ba9) )
776776
777777   DISK_REGION( "cdrom" )
778   DISK_IMAGE_READONLY( "hyperath", 0, SHA1(8638dcb27d53a30ea66c09349f6ff0b78910bf79) )
778   DISK_IMAGE_READONLY( "hyperath", 0, BAD_DUMP SHA1(694ef6200c61d3052316100cd9251b495eab88a1) )
779779ROM_END
780780
781781ROM_START( pbball96 )
r14632r14633
785785   ROM_LOAD( "pbball96.25c", 0x000000, 0x000080, CRC(405a7fc9) SHA1(e2d978f49748ba3c4a425188abcd3d272ec23907) )
786786
787787   DISK_REGION( "cdrom" )
788   DISK_IMAGE_READONLY( "pbball96", 0, SHA1(6d47624e86f97c0b8ea4ebb84cc5446aa4f11fcf) )
788   DISK_IMAGE_READONLY( "pbball96", 0, BAD_DUMP SHA1(ebd0ea18ff9ce300ea1e30d66a739a96acfb0621) )
789789ROM_END
790790
791791ROM_START( weddingr )
r14632r14633
795795   ROM_LOAD( "weddingr.25c", 0x000000, 0x000080, CRC(b90509a0) SHA1(41510a0ceded81dcb26a70eba97636d38d3742c3) )
796796
797797   DISK_REGION( "cdrom" )
798   DISK_IMAGE_READONLY( "weddingr", 0, SHA1(798686b410cb43b60d6ae91507d034db2db1b185) )
798   DISK_IMAGE_READONLY( "weddingr", 0, BAD_DUMP SHA1(4e7122b191747ab7220fe4ce1b4483d62ab579af) )
799799ROM_END
800800
801801ROM_START( simpbowl )
r14632r14633
805805   ROM_LOAD( "simpbowl.25c", 0x000000, 0x000080, CRC(2c61050c) SHA1(16ae7f81cbe841c429c5c7326cf83e87db1782bf) )
806806
807807   DISK_REGION( "cdrom" )
808   DISK_IMAGE_READONLY( "simpbowl", 0, SHA1(476f100b6c420343e16a18575bbedf1f15fbd274) )
808   DISK_IMAGE_READONLY( "simpbowl", 0, BAD_DUMP SHA1(72b32a863e6891ad3bfc1fdfe9cb90a2bd334d71) )
809809ROM_END
810810
811811ROM_START( btchamp )
r14632r14633
815815   ROM_LOAD( "btchmp.25c", 0x000000, 0x000080, CRC(6d02ea54) SHA1(d3babf481fd89db3aec17f589d0d3d999a2aa6e1) )
816816
817817   DISK_REGION( "cdrom" )
818   DISK_IMAGE_READONLY( "btchamp", 0, SHA1(c9c858e9034826e1a12c3c003dd068a49a3577e1) )
818   DISK_IMAGE_READONLY( "btchamp", 0, BAD_DUMP SHA1(c9c858e9034826e1a12c3c003dd068a49a3577e1) )
819819ROM_END
820820
821821ROM_START( kdeadeye )
r14632r14633
825825   ROM_LOAD( "kdeadeye.25c", 0x000000, 0x000080, CRC(3935d2df) SHA1(cbb855c475269077803c380dbc3621e522efe51e) )
826826
827827   DISK_REGION( "cdrom" )
828   DISK_IMAGE_READONLY( "kdeadeye", 0, SHA1(55a86ad568069f3799125b47253d579793276fab) )
828   DISK_IMAGE_READONLY( "kdeadeye", 0, BAD_DUMP SHA1(3c737c51717925be724dcb93d30769649029b8ce) )
829829ROM_END
830830
831831ROM_START( nagano98 )
r14632r14633
835835   ROM_LOAD( "nagano98.25c",  0x000000, 0x000080, CRC(b64b7451) SHA1(a77a37e0cc580934d1e7e05d523bae0acd2c1480) )
836836
837837   DISK_REGION( "cdrom" )
838   DISK_IMAGE_READONLY( "nagano98", 0, SHA1(efe09a23dfbb957574b8989b5672af1ab5e27640) )
838   DISK_IMAGE_READONLY( "nagano98", 0, BAD_DUMP SHA1(1be7bd4531f249ff2233dd40a206c8d60054a8c6) )
839839ROM_END
840840
841841ROM_START( tokimosh )
r14632r14633
845845        ROM_LOAD( "tokimosh.25c", 0x000000, 0x000080, CRC(e57b833f) SHA1(f18a0974a6be69dc179706643aab837ff61c2738) )
846846
847847   DISK_REGION( "cdrom" )
848   DISK_IMAGE_READONLY( "755jaa01", 0, SHA1(f7f1545658b430f60edccf448b2832dab9984b19) )
848   DISK_IMAGE_READONLY( "755jaa01", 0, BAD_DUMP SHA1(4af080f9650e34d1ddb91bb763469d5fb3c754bd) )
849849ROM_END
850850
851851ROM_START( tokimosp )
r14632r14633
855855   ROM_LOAD( "tokimosp.25c", 0x000000, 0x000080, CRC(af4cdd87) SHA1(97041e287e4c80066043967450779b81b62b2b8e) )
856856
857857   DISK_REGION( "cdrom" )
858   DISK_IMAGE_READONLY( "756jab01", 0, SHA1(ef76fc27e43f7e4cff16bf88458e7ee327c11ca3) )
858   DISK_IMAGE_READONLY( "756jab01", 0, BAD_DUMP SHA1(7bd974d908ae5a7bfa8d30db185ab01ac38dff28) )
859859ROM_END
860860
861861/* BIOS placeholder */
src/emu/cpu/powerpc/ppcdrc.c
r14632r14633
45474547
45484548static CPU_INIT( mpc8240 )
45494549{
4550   ppcdrc_init(PPC_MODEL_MPC8240, PPCCAP_OEA | PPCCAP_VEA | PPCCAP_FPU | PPCCAP_MISALIGNED, 4/* unknown */, device, irqcallback);
4550   ppcdrc_init(PPC_MODEL_MPC8240, PPCCAP_OEA | PPCCAP_VEA | PPCCAP_FPU | PPCCAP_MISALIGNED | PPCCAP_603_MMU, 4/* unknown */, device, irqcallback);
45514551}
45524552
45534553
src/emu/devcb.c
r14632r14633
8282
8383const input_port_config *devcb_resolver::resolve_port(const char *tag, device_t &current)
8484{
85   const input_port_config *result = current.machine().port(tag);
85   astring fullname;
86   const input_port_config *result = current.machine().port(current.siblingtag(fullname, tag));
8687   if (result == NULL)
87      throw emu_fatalerror("Unable to find input port '%s' (requested by %s '%s')", tag, current.name(), current.tag());
88      throw emu_fatalerror("Unable to find input port '%s' (requested by %s '%s')", fullname.cstr(), current.name(), current.tag());
8889   return result;
8990}
9091
src/emu/sound/samples.c
r14632r14633
122122   chan.stream->update();
123123
124124   // update the parameters
125   loaded_sample &sample = m_sample[samplenum];
125   sample_t &sample = m_sample[samplenum];
126126   chan.source = sample.data;
127   chan.source_length = sample.length;
128   chan.source_num = (sample.data.count() > 0) ? samplenum : -1;
127   chan.source_length = sample.data.count();
128   chan.source_num = (chan.source_length > 0) ? samplenum : -1;
129129   chan.pos = 0;
130130   chan.frac = 0;
131131   chan.basefreq = sample.frequency;
r14632r14633
330330      channel_t &chan = m_channel[channel];
331331      if (chan.source_num >= 0 && chan.source_num < m_sample.count())
332332      {
333         loaded_sample &sample = m_sample[chan.source_num];
333         sample_t &sample = m_sample[chan.source_num];
334334         chan.source = sample.data;
335         chan.source_length = sample.length;
335         chan.source_length = sample.data.count();
336336         if (sample.data == NULL)
337337            chan.source_num = -1;
338338      }
r14632r14633
426426//  sample
427427//-------------------------------------------------
428428
429bool samples_device::read_sample(emu_file &file, loaded_sample &sample)
429bool samples_device::read_sample(emu_file &file, sample_t &sample)
430430{
431431   // read the core header and make sure it's a proper file
432432   UINT8 buf[4];
r14632r14633
453453//  read_wav_sample - read a WAV file as a sample
454454//-------------------------------------------------
455455
456bool samples_device::read_wav_sample(emu_file &file, loaded_sample &sample)
456bool samples_device::read_wav_sample(emu_file &file, sample_t &sample)
457457{
458458   // we already read the opening 'WAVE' header
459459   UINT32 offset = 4;
r14632r14633
548548   // read the data in
549549   if (bits == 8)
550550   {
551      sample.length = length;
552551      sample.data.resize(length);
553552      file.read(sample.data, length);
554553
r14632r14633
560559   else
561560   {
562561      // 16-bit data is fine as-is
563      sample.length = length / 2;
564562      sample.data.resize(length / 2);
565563      file.read(sample.data, length);
566564
567565      // swap high/low on big-endian systems
568566      if (ENDIANNESS_NATIVE != ENDIANNESS_LITTLE)
569         for (UINT32 sindex = 0; sindex < sample.length; sindex++)
567         for (UINT32 sindex = 0; sindex < length / 2; sindex++)
570568            sample.data[sindex] = LITTLE_ENDIANIZE_INT16(sample.data[sindex]);
571569   }
572570   return true;
r14632r14633
577575//  read_flac_sample - read a FLAC file as a sample
578576//-------------------------------------------------
579577
580bool samples_device::read_flac_sample(emu_file &file, loaded_sample &sample)
578bool samples_device::read_flac_sample(emu_file &file, sample_t &sample)
581579{
582580   // seek back to the start of the file
583581   file.seek(0, SEEK_SET);
584582
585583   // create the FLAC decoder and fill in the sample data
586584   flac_decoder decoder(file);
587   sample.length = decoder.total_samples();
588585   sample.frequency = decoder.sample_rate();
589586
590587   // error if more than 1 channel or not 16bpp
r14632r14633
594591      return false;
595592
596593   // resize the array and read
597   sample.data.resize(sample.length);
598   if (!decoder.decode_interleaved(sample.data, sample.length))
594   sample.data.resize(decoder.total_samples());
595   if (!decoder.decode_interleaved(sample.data, sample.data.count()))
599596      return false;
600597
601598   // finish up and clean up
src/emu/sound/samples.h
r14632r14633
105105   void set_frequency(UINT8 channel, UINT32 frequency);
106106   void set_volume(UINT8 channel, float volume);
107107
108   // helpers
109   struct sample_t
110   {
111      // shouldn't need a copy, but in case it happens, catch it here
112      sample_t &operator=(const sample_t &rhs) { assert(false); return *this; }
113
114       UINT32         frequency;      // frequency of the sample
115       dynamic_array<INT16> data;      // 16-bit signed data
116   };
117   static bool read_sample(emu_file &file, sample_t &sample);
118
108119protected:
109120   // subclasses can do it this way
110121   samples_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock);
r14632r14633
119130
120131private:
121132   // internal classes
122   struct loaded_sample
123   {
124      // shouldn't need a copy, but in case it happens, catch it here
125      loaded_sample &operator=(const loaded_sample &rhs) { assert(false); return *this; }
126
127       UINT32         length;         // length in samples
128       UINT32         frequency;      // frequency of the sample
129       dynamic_array<INT16> data;      // 16-bit signed data
130   };
131
132133   struct channel_t
133134   {
134135      sound_stream *   stream;
r14632r14633
144145   };
145146
146147   // internal helpers
147   bool read_sample(emu_file &file, loaded_sample &sample);
148   bool read_wav_sample(emu_file &file, loaded_sample &sample);
149   bool read_flac_sample(emu_file &file, loaded_sample &sample);
148   static bool read_wav_sample(emu_file &file, sample_t &sample);
149   static bool read_flac_sample(emu_file &file, sample_t &sample);
150150   void load_samples();
151151
152152   // internal state
153   dynamic_array<channel_t>      m_channel;
154   dynamic_array<loaded_sample>   m_sample;
153   dynamic_array<channel_t>   m_channel;
154   dynamic_array<sample_t>      m_sample;
155155
156156   // internal constants
157157   static const UINT8 FRAC_BITS = 24;
src/emu/sound/bsmt2000.c
r14632r14633
106106//  bsmt2000_device - constructor
107107//-------------------------------------------------
108108
109//-------------------------------------------------
110//  bsmt2000_device - constructor
111//-------------------------------------------------
112
113109bsmt2000_device::bsmt2000_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
114110   : device_t(mconfig, BSMT2000, "BSMT2000", "bsmt2000", tag, owner, clock),
115111     device_sound_interface(mconfig, *this),
src/emu/ioport.c
r14632r14633
20042004         {
20052005            *readdevicetail = init_field_device_info(field, port->owner().subtag(devicetag, field->read_device));
20062006            field->read.late_bind(*(*readdevicetail)->device);
2007            if (!field->read.has_object())
2008               fatalerror("Input port %s, unable to find valid device with tag '%s'", port->tag(), devicetag.cstr());
20072009            readdevicetail = &(*readdevicetail)->next;
20082010         }
20092011
r14632r14633
20122014         {
20132015            *writedevicetail = init_field_device_info(field, port->owner().subtag(devicetag, field->write_device));
20142016            field->write.late_bind(*(*writedevicetail)->device);
2017            if (!field->write.has_object())
2018               fatalerror("Input port %s, unable to find valid device with tag '%s'", port->tag(), devicetag.cstr());
20152019            writedevicetail = &(*writedevicetail)->next;
20162020         }
20172021
src/emu/speaker.c
r14632r14633
4545
4646
4747
48/***************************************************************************
49    DEBUGGING
50***************************************************************************/
48//**************************************************************************
49//  DEBUGGING
50//**************************************************************************
5151
5252#define VERBOSE         (0)
5353
r14632r14633
5656
5757
5858//**************************************************************************
59//  LIVE SPEAKER DEVICE
59//  GLOBAL VARIABLES
6060//**************************************************************************
6161
6262// device type definition
6363const device_type SPEAKER = &device_creator<speaker_device>;
6464
65
66
67//**************************************************************************
68//  LIVE SPEAKER DEVICE
69//**************************************************************************
70
6571//-------------------------------------------------
6672//  speaker_device - constructor
6773//-------------------------------------------------
6874
6975speaker_device::speaker_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
7076   : device_t(mconfig, SPEAKER, "Speaker", tag, owner, clock),
71     device_sound_interface(mconfig, *this),
77     device_mixer_interface(mconfig, *this),
7278     m_x(0.0),
7379     m_y(0.0),
74     m_z(0.0),
75     m_mixer_stream(NULL)
80     m_z(0.0)
7681#ifdef MAME_DEBUG
7782   ,
7883     m_max_sample(0),
r14632r14633
112117
113118
114119//-------------------------------------------------
115//  device_start - perform device-specific
116//  startup
117//-------------------------------------------------
118
119void speaker_device::device_start()
120{
121   // no inputs? that's weird
122   if (m_auto_allocated_inputs == 0)
123   {
124      logerror("Warning: speaker \"%s\" has no inputs\n", tag());
125      return;
126   }
127
128   // allocate the mixer stream
129   m_mixer_stream = machine().sound().stream_alloc(*this, m_auto_allocated_inputs, 1, machine().sample_rate());
130}
131
132
133//-------------------------------------------------
134//  device_post_load - after we load a save state
135//  be sure to update the mixer stream's output
136//  sample rate
137//-------------------------------------------------
138
139void speaker_device::device_post_load()
140{
141   m_mixer_stream->set_sample_rate(machine().sample_rate());
142}
143
144
145//-------------------------------------------------
146//  mixer_update - mix all inputs to one output
147//-------------------------------------------------
148
149void speaker_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
150{
151   VPRINTF(("Mixer_update(%d)\n", samples));
152
153   // loop over samples
154   for (int pos = 0; pos < samples; pos++)
155   {
156      // add up all the inputs
157      INT32 sample = inputs[0][pos];
158      for (int inp = 1; inp < m_auto_allocated_inputs; inp++)
159         sample += inputs[inp][pos];
160      outputs[0][pos] = sample;
161   }
162}
163
164
165//-------------------------------------------------
166120//  mix - mix in samples from the speaker's stream
167121//-------------------------------------------------
168122
r14632r14633
223177            rightmix[sample] += stream_buf[sample];
224178   }
225179}
180
181
182//-------------------------------------------------
183//  device_start - handle device startup
184//-------------------------------------------------
185
186void speaker_device::device_start()
187{
188   // dummy save to make device.c happy
189}
src/emu/speaker.h
r14632r14633
4848
4949
5050//**************************************************************************
51//  GLOBAL VARIABLES
52//**************************************************************************
53
54// device type definition
55extern const device_type SPEAKER;
56
57
58
59//**************************************************************************
5160//  DEVICE CONFIGURATION MACROS
5261//**************************************************************************
5362
r14632r14633
7281// ======================> speaker_device
7382
7483class speaker_device : public device_t,
75                  public device_sound_interface
84                  public device_mixer_interface
7685{
7786   friend resource_pool_object<speaker_device>::~resource_pool_object();
7887
r14632r14633
8998
9099protected:
91100   // device-level overrides
92   virtual void device_start();
93   virtual void device_post_load();
101   virtual void device_start() ATTR_COLD;
94102
95   // sound interface overrides
96   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
97
98103   // inline configuration state
99104   double            m_x;
100105   double            m_y;
101106   double            m_z;
102107
103108   // internal state
104   sound_stream *      m_mixer_stream;         // mixing stream
105109#ifdef MAME_DEBUG
106110   INT32            m_max_sample;         // largest sample value we've seen
107111   INT32            m_clipped_samples;      // total number of clipped samples
r14632r14633
110114};
111115
112116
113// device type definition
114extern const device_type SPEAKER;
115
116
117117// speaker device iterator
118118typedef device_type_iterator<&device_creator<speaker_device>, speaker_device> speaker_device_iterator;
119119
src/emu/disound.c
r14632r14633
7979      throw emu_fatalerror("MCFG_SOUND_ROUTE called on device '%s' with no sound interface", device.tag());
8080
8181   // append a new route to the list
82   astring devtag;
83   device.siblingtag(devtag, target);
84   sound->m_route_list.append(*global_alloc(sound_route(output, input, gain, devtag.cstr())));
82   sound->m_route_list.append(*global_alloc(sound_route(output, input, gain, target)));
8583}
8684
8785
r14632r14633
265263      for (const sound_route *route = sound->first_route(); route != NULL; route = route->next())
266264      {
267265         // see if we are the target of this route; if we are, make sure the source device is started
268         device_t *target_device = m_device.machine().device(route->m_target);
266         device_t *target_device = sound->device().siblingdevice(route->m_target);
269267         if (target_device == &m_device && !sound->device().started())
270268            throw device_missing_dependencies();
271269      }
r14632r14633
279277      for (const sound_route *route = sound->first_route(); route != NULL; route = route->next())
280278      {
281279         // see if we are the target of this route
282         device_t *target_device = m_device.machine().device(route->m_target);
280         device_t *target_device = sound->device().siblingdevice(route->m_target);
283281         if (target_device == &m_device && route->m_input == AUTO_ALLOC_INPUT)
284282         {
285283            const_cast<sound_route *>(route)->m_input = m_auto_allocated_inputs;
r14632r14633
305303      for (const sound_route *route = sound->first_route(); route != NULL; route = route->next())
306304      {
307305         // if we are the target of this route, hook it up
308         device_t *target_device = m_device.machine().device(route->m_target);
306         device_t *target_device = sound->device().siblingdevice(route->m_target);
309307         if (target_device == &m_device)
310308         {
311309            // iterate over all outputs, matching any that apply
r14632r14633
366364     m_target(target)
367365{
368366}
367
368
369
370//**************************************************************************
371//  SIMPLE DERIVED MIXER INTERFACE
372//**************************************************************************
373
374//-------------------------------------------------
375//  device_mixer_interface - constructor
376//-------------------------------------------------
377
378device_mixer_interface::device_mixer_interface(const machine_config &mconfig, device_t &device, int outputs)
379   : device_sound_interface(mconfig, device),
380     m_outputs(outputs),
381     m_mixer_stream(NULL)
382{
383}
384
385
386//-------------------------------------------------
387//  ~device_mixer_interface - destructor
388//-------------------------------------------------
389
390device_mixer_interface::~device_mixer_interface()
391{
392}
393
394
395//-------------------------------------------------
396//  interface_pre_start - perform startup prior
397//   to the device startup
398//-------------------------------------------------
399
400void device_mixer_interface::interface_pre_start()
401{
402   // call our parent
403   device_sound_interface::interface_pre_start();
404
405   // no inputs? that's weird
406   if (m_auto_allocated_inputs == 0)
407   {
408      logerror("Warning: mixer \"%s\" has no inputs\n", device().tag());
409      return;
410   }
411
412   // allocate the mixer stream
413   m_mixer_stream = stream_alloc(m_auto_allocated_inputs, m_outputs, device().machine().sample_rate());
414}
415
416
417//-------------------------------------------------
418//  interface_post_load - after we load a save
419//  state be sure to update the mixer stream's
420//  output sample rate
421//-------------------------------------------------
422
423void device_mixer_interface::interface_post_load()
424{
425   m_mixer_stream->set_sample_rate(device().machine().sample_rate());
426   
427   // call our parent
428   device_sound_interface::interface_post_load();
429}
430
431
432//-------------------------------------------------
433//  mixer_update - mix all inputs to one output
434//-------------------------------------------------
435
436void device_mixer_interface::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
437{
438   // loop over samples
439   for (int pos = 0; pos < samples; pos++)
440   {
441      // add up all the inputs
442      INT32 sample = inputs[0][pos];
443      for (int inp = 1; inp < m_auto_allocated_inputs; inp++)
444         sample += inputs[inp][pos];
445      outputs[0][pos] = sample;
446   }
447}
src/emu/disound.h
r14632r14633
152152// iterator
153153typedef device_interface_iterator<device_sound_interface> sound_interface_iterator;
154154
155
156
157// ======================> device_mixer_interface
158
159class device_mixer_interface : public device_sound_interface
160{
161public:
162   // construction/destruction
163   device_mixer_interface(const machine_config &mconfig, device_t &device, int outputs = 1);
164   virtual ~device_mixer_interface();
165
166protected:
167   // optional operation overrides
168   virtual void interface_pre_start();
169   virtual void interface_post_load();
170
171   // sound interface overrides
172   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
173
174   // internal state
175   UINT8            m_outputs;            // number of outputs
176   sound_stream *      m_mixer_stream;         // mixing stream
177};
178
179
155180#endif   /* __DISOUND_H__ */
src/emu/device.c
r14632r14633
394394   state_registrations = machine().save().registration_count() - state_registrations;
395395   device_execute_interface *exec;
396396   device_sound_interface *sound;
397   if (state_registrations == 0 && (interface(exec) || interface(sound)))
397   if (state_registrations == 0 && (interface(exec) || interface(sound)) && type() != SPEAKER)
398398   {
399399      logerror("Device '%s' did not register any state to save!\n", tag());
400400      if ((machine().system().flags & GAME_SUPPORTS_SAVE) != 0)
src/emu/machine/6532riot.c
r14632r14633
162162   via->reg_w(offset, data);
163163}
164164
165WRITE8_MEMBER( riot6532_device::write )
166{
167   reg_w(offset, data);
168}
169
165170void riot6532_device::reg_w(UINT8 offset, UINT8 data)
166171{
167172   /* if A4 == 1 and A2 == 1, we are writing to the timer */
r14632r14633
248253   return via->reg_r(offset);
249254}
250255
256READ8_MEMBER( riot6532_device::read )
257{
258   return reg_r(offset);
259}
260
251261UINT8 riot6532_device::reg_r(UINT8 offset)
252262{
253263   UINT8 val = 0;
src/emu/machine/6532riot.h
r14632r14633
5050    // construction/destruction
5151    riot6532_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
5252
53   DECLARE_READ8_MEMBER( read );
54   DECLARE_WRITE8_MEMBER( write );
55
5356    UINT8 reg_r(UINT8 offset);
5457    void reg_w(UINT8 offset, UINT8 data);
5558

Previous 15994 Revisions Next


© 1998-2018 The MESS Team