Index: mist/atari800core_mist.vhd
===================================================================
--- mist/atari800core_mist.vhd	(revision 83)
+++ mist/atari800core_mist.vhd	(revision 84)
@@ -12,6 +12,13 @@
 LIBRARY work;
 
 ENTITY atari800core_mist IS 
+	GENERIC
+	(
+		TV : integer;  -- 1 = PAL, 0=NTSC
+		VIDEO : integer; -- 1 = RGB, 2 = VGA
+		COMPOSITE_SYNC : integer; --0 = no, 1 = yes!
+		SCANDOUBLE : integer -- 1 = YES, 0=NO, (+ later scanlines etc)
+	);
 	PORT
 	(
 		CLOCK_27 :  IN  STD_LOGIC_VECTOR(1 downto 0);
@@ -133,6 +140,8 @@
   SIGNAL	KEYBOARD_SCAN :  STD_LOGIC_VECTOR(5 DOWNTO 0);
 
   SIGNAL PAL : std_logic;
+  SIGNAL COMPOSITE_ON_HSYNC : std_logic;
+  SIGNAL VGA : std_logic;
 
   signal SDRAM_REQUEST : std_logic;
   signal SDRAM_REQUEST_COMPLETE : std_logic;
@@ -189,8 +198,15 @@
 	-- ps2
 	signal SLOW_PS2_CLK : std_logic; -- around 16KHz
 
+	-- scandoubler
+	signal half_scandouble_enable_reg : std_logic;
+	signal half_scandouble_enable_next : std_logic;
+	signal VIDEO_B : std_logic_vector(7 downto 0);
+
 BEGIN 
-pal <= '1'; -- TODO, two builds, with appropriate pll settings
+pal <= '1' when tv=1 else '0';
+vga <= '1' when video=2 else '0';
+composite_on_hsync <= '1' when composite_sync=1 else '0';
 
 -- mist spi io
 mist_spi_interface : entity work.data_io 
@@ -393,7 +409,8 @@
 		cycle_length => 32,
 		internal_rom => 0,
 		internal_ram => 0,
-		video_bits => 6
+		video_bits => 8,
+		palette => 0
 	)
 	PORT MAP
 	(
@@ -402,9 +419,9 @@
 
 		VIDEO_VS => VGA_VS_RAW,
 		VIDEO_HS => VGA_HS_RAW,
-		VIDEO_B => VGA_B,
-		VIDEO_G => VGA_G,
-		VIDEO_R => VGA_R,
+		VIDEO_B => VIDEO_B,
+		VIDEO_G => open,
+		VIDEO_R => open,
 
 		AUDIO_L => AUDIO_L_PCM,
 		AUDIO_R => AUDIO_R_PCM,
@@ -496,9 +513,50 @@
 --SDRAM_CKE <= '1';		 
 LED <= '0';
 
-VGA_HS <= not(VGA_HS_RAW xor VGA_VS_RAW);
-VGA_VS <= not(VGA_VS_RAW);
+--VGA_HS <= not(VGA_HS_RAW xor VGA_VS_RAW);
+--VGA_VS <= not(VGA_VS_RAW);
 
+	process(clk,RESET_N,SDRAM_RESET_N,reset_atari)
+	begin
+		if ((RESET_N and SDRAM_RESET_N and not(reset_atari))='0') then
+			half_scandouble_enable_reg <= '0';
+		elsif (clk'event and clk='1') then
+			half_scandouble_enable_reg <= half_scandouble_enable_next;
+		end if;
+	end process;
+
+	half_scandouble_enable_next <= not(half_scandouble_enable_reg);
+
+	scandoubler1: entity work.scandoubler
+	GENERIC MAP
+	(
+		video_bits=>6
+	)
+	PORT MAP
+	( 
+		CLK => CLK,
+		RESET_N => RESET_N and SDRAM_RESET_N and not(reset_atari),
+		
+		VGA => vga,
+		COMPOSITE_ON_HSYNC => composite_on_hsync,
+
+		colour_enable => half_scandouble_enable_reg,
+		doubled_enable => '1',
+		
+		-- GTIA interface
+		colour_in => VIDEO_B,
+		vsync_in => VGA_VS_RAW,
+		hsync_in => VGA_HS_RAW,
+		
+		-- TO TV...
+		R => VGA_R,
+		G => VGA_G,
+		B => VGA_B,
+		
+		VSYNC => VGA_VS,
+		HSYNC => VGA_HS
+	);
+
 zpu: entity work.zpucore
 	GENERIC MAP
 	(
Index: mist/build.sh
===================================================================
--- mist/build.sh	(revision 83)
+++ mist/build.sh	(revision 84)
@@ -1,21 +1,105 @@
-rm -rf build
-mkdir build
-cp atari800core_mist.vhd build
-cp pll.* build
-cp atari800core.sdc build
-cp data_io.vhdl build
-cp user_io.v build
-cp mist_sector_buffer.* build
-cp zpu_rom.vhdl build
-mkdir build/common
-mkdir build/common/a8core
-mkdir build/common/components
-mkdir build/common/zpu
-cp ../common/a8core/* ./build/common/a8core
-cp ../common/components/* ./build/common/components
-cp ../common/zpu/* ./build/common/zpu
+#!/usr/bin/perl -w
+use strict;
 
-cd build
-../makeqsf ../atari800core.qsf ./common/a8core ./common/components ./common/zpu
+my $wanted_variant = shift @ARGV;
 
-quartus_sh --flow compile atari800core
+#variants...
+my $PAL = 1;
+my $NTSC = 0;
+
+my $RGB = 1; # i.e. not scandoubled
+my $VGA = 2;
+
+#Added like this to the generated qsf
+#set_parameter -name TV 1
+
+my %variants = 
+(
+	"PAL_RGB" => 
+	{
+		"TV" => $PAL,
+		"SCANDOUBLE" => 0,
+		"VIDEO" => $RGB,
+		"COMPOSITE_SYNC" => 1
+	},
+	"PAL_VGA" =>
+	{
+		"TV" => $PAL,
+		"SCANDOUBLE" => 1,
+		"VIDEO" => $VGA,
+		"COMPOSITE_SYNC" => 0
+	},
+	"PAL_VGA_CS" =>
+	{
+		"TV" => $PAL,
+		"SCANDOUBLE" => 1,
+		"VIDEO" => $VGA,
+		"COMPOSITE_SYNC" => 1
+	},
+	"NTSC_RGB" =>
+	{
+		"TV" => $NTSC,
+		"SCANDOUBLE" => 0,
+		"VIDEO" => $RGB, 
+		"COMPOSITE_SYNC" => 1
+	},
+	"NTSC_VGA" => 
+	{
+		"TV" => $NTSC,
+		"SCANDOUBLE" => 1,
+		"VIDEO" => $VGA,
+		"COMPOSITE_SYNC" => 0
+	},
+	"NTSC_VGA_CS" => 
+	{
+		"TV" => $NTSC,
+		"SCANDOUBLE" => 1,
+		"VIDEO" => $VGA,
+		"COMPOSITE_SYNC" => 1
+	}
+);
+
+if (not defined $wanted_variant or (not exists $variants{$wanted_variant} and $wanted_variant ne "ALL"))
+{
+	die "Provide variant of ALL or ".join ",",sort keys %variants;
+}
+
+foreach my $variant (sort keys %variants)
+{
+	next if ($wanted_variant ne $variant and $wanted_variant ne "ALL");
+	print "Building $variant\n";
+
+	my $dir = "build_$variant";
+	`rm -rf $dir`;
+	mkdir $dir;
+	`cp atari800core_mist.vhd $dir`;
+	`cp *pll*.* $dir`;
+	`cp *mist_sector*.* $dir`;
+	`cp *.v $dir`;
+	`cp *.vhdl $dir`;
+	`cp zpu_rom.vhdl $dir`;
+	`cp atari800core.sdc $dir`;
+	`mkdir $dir/common`;
+	`mkdir $dir/common/a8core`;
+	`mkdir $dir/common/components`;
+	`mkdir $dir/common/zpu`;
+	`cp ../common/a8core/* ./$dir/common/a8core`;
+	`cp ../common/components/* ./$dir/common/components`;
+	`cp ../common/zpu/* ./$dir/common/zpu`;
+
+	chdir $dir;
+	`../makeqsf ../atari800core.qsf ./common/a8core ./common/components ./common/zpu`;
+
+	foreach my $key (sort keys %{$variants{$variant}})
+	{
+		my $val = $variants{$variant}->{$key};
+		`echo set_parameter -name $key $val >> atari800core.qsf`;
+	}
+
+	`quartus_sh --flow compile atari800core > build.log 2> build.err`;
+
+	`quartus_cpf --convert ../output_file.cof`;
+	
+	chdir "..";
+}
+
Index: mist/makeqsf
===================================================================
--- mist/makeqsf	(revision 83)
+++ mist/makeqsf	(revision 84)
@@ -17,6 +17,7 @@
 	my @vhdl = glob ("$_/*.vhd");
 	push @vhdl, glob ("$_/*.vhdl");
 	my @verilog = glob ("$_/*.v");
+	my @qip = glob ("$_/*.qip");
 
 	foreach (@verilog)
 	{
@@ -27,6 +28,11 @@
 	{
 		print QSF_OUT "set_global_assignment -name VHDL_FILE $_\n";
 	}
+
+	foreach (@qip)
+	{
+		print QSF_OUT "set_global_assignment -name QIP_FILE $_\n";
+	}
 }
 
 close (QSF_OUT);
Index: mist/output_file.cof
===================================================================
--- mist/output_file.cof	(nonexistent)
+++ mist/output_file.cof	(revision 84)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="US-ASCII" standalone="yes"?>
+<cof>
+	<eprom_name>CFI_128Mb</eprom_name>
+	<output_filename>output_files/atari800core.rbf</output_filename>
+	<n_pages>1</n_pages>
+	<width>1</width>
+	<mode>0</mode>
+	<sof_data>
+		<user_name>Page_0</user_name>
+		<page_flags>1</page_flags>
+		<bit0>
+			<sof_filename>output_files/atari800core.sof<compress_bitstream>1</compress_bitstream></sof_filename>
+		</bit0>
+	</sof_data>
+	<version>5</version>
+	<create_cvp_file>0</create_cvp_file>
+	<options>
+	</options>
+</cof>
