/*Any fixes for this driver should be forwarded to AGEMAME HQ (http://www.mameworld.net/agemame/)*/

#include "driver.h"
#include "artwork.h"
#include "dxfmvid.h"
#include "genfmvid.h"
#include "machine/lamps.h"
#include "machine/vacfdisp.h"
#include "machine/steppers.h"
#include "font/uifnt.c"

//#define LAYOUTTEST //Enables the lamp matrix and stepper information
static gfx_element *font;	// pointer to font gfx

// video initialisation ///////////////////////////////////////////////////

VIDEO_START( deluxe_fruitmachine )
{
  font = decodegfx(fontdata,&fontlayout);

  font->colortable   = Machine->debug_remapped_colortable;
  font->total_colors = 16;

  return 0;
}

// video cleanup //////////////////////////////////////////////////////////

VIDEO_STOP( deluxe_fruitmachine )
{
  if ( font )
  {
	freegfx(font);
	font = NULL;
  }
}

// video update ///////////////////////////////////////////////////////////

VIDEO_UPDATE( deluxe_fruitmachine )
{
  int x, y,offset, nrlamps, o,p,q,r,s,t;
  char *vfd = vfd_get_string(0);
  char lampno[7];
  char reel1[5];
  char reel2[5];
  char reel3[5];
  char reel4[5];
  char reel5[5];
  char reel6[5];
  char reel1old[5];
  char reel2old[5];
  char reel3old[5];
  char reel4old[5];
  char reel5old[5];
  char reel6old[5];
       
  nrlamps = Lamps_GetNumberLamps();

  offset  = 0;

  for ( y = 0; y < 16; y++ )
  {
	for ( x = 0; x < 16; x++ )
	{
	sprintf(lampno, "LAMP%d", offset);
	#ifdef LAYOUTTEST
	plot_box(bitmap, x*8, y*8, 7, 7, Lamps_GetBrightness(offset) );
	#endif
	artwork_show(lampno, Lamps_GetBrightness(offset));
	  offset++;
	}
	if ( offset > nrlamps ) break;
  }

  y++;

  for ( x = 0; x < 16; x++ )
 {
//	drawgfx(bitmap, font, vfd[x], 7, 0, 0, x*font->width, y*font->height,
	drawgfx(bitmap, font, vfd[x], 1, 0, 0, x*font->width, y*font->height, 0, TRANSPARENCY_NONE, 0);
  }
#ifdef LAYOUTTEST
ui_popup("%3d %3d %3d %3d %3d %3d",
			  Stepper_get_position(0), Stepper_get_position(1), Stepper_get_position(2),
			  Stepper_get_position(3), Stepper_get_position(4), Stepper_get_position(5) );
#endif

for ( o = 0; o < Stepper_get_max(0); o++)
{
sprintf(reel1old, "R1%d", o);
artwork_show(reel1old, 0);
sprintf(reel1, "R1%d", Stepper_get_position(0));
artwork_show(reel1, 1);
}

for ( p = 0; p < Stepper_get_max(1); p++)
{
sprintf(reel2old, "R2%d", p);
artwork_show(reel2old, 0);
sprintf(reel2, "R2%d", Stepper_get_position(1));
artwork_show(reel2, 1);
}

for ( q = 0; q < Stepper_get_max(2); q++)
{
sprintf(reel3old, "R3%d", q);
artwork_show(reel3old, 0);
sprintf(reel3, "R3%d", Stepper_get_position(2));
artwork_show(reel3, 1);
}

for ( r = 0; r < Stepper_get_max(3); r++)
{
sprintf(reel4old, "R4%d", r);
artwork_show(reel4old, 0);
sprintf(reel4, "R4%d", Stepper_get_position(3));
artwork_show(reel4, 1);
}

for ( s = 0; s < Stepper_get_max(4); s++)
{
sprintf(reel5old, "R5%d", s);
artwork_show(reel5old, 0);
sprintf(reel5, "R5%d", Stepper_get_position(4));
artwork_show(reel5, 1);
}
for ( t = 0; t < Stepper_get_max(5); t++)
{
sprintf(reel6old, "R6%d", t);
artwork_show(reel6old, 0);
sprintf(reel6, "R6%d", Stepper_get_position(5));
artwork_show(reel6, 1);
}

#if 0 
  for ( x = 0; x < 6; x++ )
  {
	plot_box(bitmap, x*8, 240, 7, 7, steppers[x].pattern+1 );
	plot_box(bitmap, x*8, 248, 7, 7, (bfm_optic_pattern&(1<<x))?1:2   );
  }
#endif

}

// palette initialisation /////////////////////////////////////////////////

PALETTE_INIT( deluxe_fruitmachine )
{
  palette_set_color( 0,0x00,0x00,0x00);
  palette_set_color( 1,0x00,0x00,0xFF);
  palette_set_color( 2,0x00,0xFF,0x00);
  palette_set_color( 3,0x00,0xFF,0xFF);
  palette_set_color( 4,0xFF,0x00,0x00);
  palette_set_color( 5,0xFF,0x00,0xFF);
  palette_set_color( 6,0xFF,0xFF,0x00);
  palette_set_color( 7,0xFF,0xFF,0xFF);
  palette_set_color( 8,0x80,0x80,0x80);
  palette_set_color( 9,0x00,0x00,0x80);
  palette_set_color(10,0x00,0x80,0x00);
  palette_set_color(11,0x00,0x80,0x80);
  palette_set_color(12,0x80,0x00,0x00);
  palette_set_color(13,0x80,0x00,0x80);
  palette_set_color(14,0x80,0x80,0x00);
  palette_set_color(15,0x80,0x80,0x80);
}

