Index: de1/atari800core.qsf
===================================================================
--- de1/atari800core.qsf	(revision 82)
+++ de1/atari800core.qsf	(revision 83)
@@ -565,6 +565,7 @@
 
 set_instance_assignment -name PARTITION_HIERARCHY root_partition -to | -section_id Top
 
+set_global_assignment -name VHDL_FILE gpio.vhd
 set_global_assignment -name VHDL_FILE atari800core_de1.vhd
 set_global_assignment -name VHDL_FILE hexdecoder.vhd
 set_global_assignment -name VHDL_FILE i2c_loader.vhd
Index: de1/atari800core_de1.vhd
===================================================================
--- de1/atari800core_de1.vhd	(revision 82)
+++ de1/atari800core_de1.vhd	(revision 83)
@@ -118,6 +118,9 @@
 	-- CARTRIDGE ACCESS
 	SIGNAL	CART_RD4 :  STD_LOGIC;
 	SIGNAL	CART_RD5 :  STD_LOGIC;
+	SIGNAL	CART_S4_n :  STD_LOGIC;
+	SIGNAL	CART_S5_n :  STD_LOGIC;
+	SIGNAL	CART_CCTL_n :  STD_LOGIC;
 	
 	-- PBI
 	SIGNAL PBI_WRITE_DATA : std_logic_vector(31 downto 0);
@@ -161,6 +164,8 @@
 	SIGNAL SIO_COMMAND : std_logic;
 	SIGNAL SIO_TXD : std_logic;
 
+	SIGNAL GPIO_SIO_RXD : std_logic;
+
 	-- VIDEO
 	signal VGA_VS_RAW : std_logic;
 	signal VGA_HS_RAW : std_logic;
@@ -202,12 +207,19 @@
 	signal pause_atari : std_logic;
 	SIGNAL speed_6502 : std_logic_vector(5 downto 0);
 
+	-- GPIO
+	signal GPIO_0_DIR_OUT : std_logic_vector(35 downto 0);
+	signal GPIO_0_OUT : std_logic_vector(35 downto 0);
+	signal GPIO_1_DIR_OUT : std_logic_vector(35 downto 0);
+	signal GPIO_1_OUT : std_logic_vector(35 downto 0);
+	signal TRIGGERS : std_logic_vector(3 downto 0);
+
 BEGIN 
 
 -- ANYTHING NOT CONNECTED...
-GPIO_0(0) <= 'Z';
-GPIO_0(35 downto 2) <= (others=>'Z');
-GPIO_1(35 downto 0) <= (others=>'Z');
+--GPIO_0(0) <= 'Z';
+--GPIO_0(35 downto 2) <= (others=>'Z');
+--GPIO_1(35 downto 0) <= (others=>'Z');
 
 FL_OE_N <= '1';
 FL_WE_N <= '1';
@@ -292,8 +304,6 @@
 		 SDRAM_ADDR => DRAM_ADDR(11 downto 0),
 		 reset_client_n => SDRAM_RESET_N
 		 );
-		 
-SDRAM_REFRESH <= '0'; -- TODO
 
 -- PIA mapping
 CA1_IN <= '1';
@@ -302,15 +312,12 @@
 CB2_IN <= CB2_OUT when CB2_DIR_OUT='1' else '1';
 SIO_COMMAND <= CB2_OUT;
 --PORTA_IN <= ((JOY2_n(3)&JOY2_n(2)&JOY2_n(1)&JOY2_n(0)&JOY1_n(3)&JOY1_n(2)&JOY1_n(1)&JOY1_n(0)) and not (porta_dir_out)) or (porta_dir_out and porta_out);
-PORTA_IN <= (not (porta_dir_out)) or (porta_dir_out and porta_out);
+--PORTA_IN <= (not (porta_dir_out)) or (porta_dir_out and porta_out);
 PORTB_IN <= PORTB_OUT;
 
--- ANTIC lightpen
-ANTIC_LIGHTPEN <= '1'; --JOY2_n(4) and JOY1_n(4);
-
 -- GTIA triggers
 --GTIA_TRIG <= CART_RD5&"1"&JOY2_n(4)&JOY1_n(4);
-GTIA_TRIG <= CART_RD5&"111";
+GTIA_TRIG <= CART_RD5&"1"&TRIGGERS(1 downto 0);
 
 -- Cartridge not inserted
 CART_RD4 <= '0';
@@ -347,63 +354,55 @@
 --		 SYNC_KEYS => SYNC_KEYS,
 --		 SYNC_SWITCHES => SYNC_SWITCHES);
 
---gpio0_gen:
---   for I in 0 to 35 generate
---		gpio_0(I) <= gpio_0_out(I) when gpio_0_dir_out(I)='1' else 'Z';
---   end generate gpio0_gen;
---
---gpio1_gen:
---   for I in 0 to 35 generate
---		gpio_1(I) <= gpio_1_out(I) when gpio_1_dir_out(I)='1' else 'Z';
---   end generate gpio1_gen;
+gpio0_gen:
+   for I in 0 to 35 generate
+		gpio_0(I) <= gpio_0_out(I) when gpio_0_dir_out(I)='1' else 'Z';
+   end generate gpio0_gen;
 
---b2v_inst19 : entity work.gpio
---PORT MAP(clk => CLK,
---		 gpio_enable => GPIO_ENABLE,
---		 pot_reset => POT_RESET,
---		 virtual_keyheld => KEY_HELD,
---		 virtual_shift_pressed => SHIFT_PRESSED,
---		 virtual_control_pressed => KBCODE(7),
---		 virtual_break_pressed => BREAK_PRESSED,
---		 pbi_write_enable => PBI_WRITE_ENABLE,
---		 cart_request => CART_REQUEST,
---		 s4_n => CART_S4_n,
---		 s5_n => CART_S5_N,
---		 cctl_n => CART_CCTL_N,
---		 cart_data_write => WRITE_DATA(7 DOWNTO 0),
---		 GPIO_0_IN => GPIO_0,
---		 GPIO_0_OUT => GPIO_0_OUT,
---		 GPIO_0_DIR_OUT => GPIO_0_DIR_OUT,
---		 GPIO_1_IN => GPIO_1,
---		 GPIO_1_OUT => GPIO_1_OUT,
---		 GPIO_1_DIR_OUT => GPIO_1_DIR_OUT,		 
---		 keyboard_scan => KEYBOARD_SCAN,
---		 pbi_addr_out => PBI_ADDR,
---		 porta_out => PORTA_OUT,
---		 porta_output => PORTA_DIR_OUT,
---		 virtual_keycode => KBCODE(5 DOWNTO 0),
---		 virtual_stick_in => VIRTUAL_STICKS,
---		 virtual_trig_in => VIRTUAL_TRIGGERS,
---		 lightpen => LIGHTPEN,
---		 cart_complete => CART_REQUEST_COMPLETE,
---		 rd4 => CART_RD4,
---		 rd5 => CART_RD5,
---		 cart_data_read => CART_ROM_DO,
---		 keyboard_response => KEYBOARD_RESPONSE,
---		 porta_in => GPIO_PORTA_IN,
---		 pot_in => POT_IN,
---		 trig_in => TRIGGERS,
---		 monitor => SIO_DATA_IN, -- i.e. zpu sio out
---		 CA2_DIR_OUT => CA2_DIR_OUT,
---		 CA2_OUT => CA2_OUT,
---		 CA2_IN => GPIO_CA2_IN,
---		 CB2_DIR_OUT => CB2_DIR_OUT,
---		 CB2_OUT => CB2_OUT,
---		 CB2_IN => GPIO_CB2_IN,
---		 SIO_IN => GPIO_SIO_IN,
---		 SIO_OUT => GPIO_SIO_OUT
---		 );
+gpio1_gen:
+   for I in 0 to 35 generate
+		gpio_1(I) <= gpio_1_out(I) when gpio_1_dir_out(I)='1' else 'Z';
+   end generate gpio1_gen;
 
+gpio1 : entity work.gpio
+PORT MAP(clk => CLK,
+		 gpio_enable => '1',
+		 pot_reset => '0',
+		 pbi_write_enable => '0',
+		 cart_request => '0',
+		 cart_complete => open,
+		 cart_data_read => open,
+		 s4_n => cart_s4_n,
+		 s5_n => cart_s5_n,
+		 cctl_n => cart_cctl_n,
+		 cart_data_write => x"00",
+		 GPIO_0_IN => GPIO_0,
+		 GPIO_0_OUT => GPIO_0_OUT,
+		 GPIO_0_DIR_OUT => GPIO_0_DIR_OUT,
+		 GPIO_1_IN => GPIO_1,
+		 GPIO_1_OUT => GPIO_1_OUT,
+		 GPIO_1_DIR_OUT => GPIO_1_DIR_OUT,		 
+		 keyboard_scan => KEYBOARD_SCAN,
+		 pbi_addr_out => X"0000",
+		 porta_out => PORTA_OUT,
+		 porta_output => PORTA_DIR_OUT,
+		 lightpen => ANTIC_LIGHTPEN,
+		 rd4 => open,
+		 rd5 => open,
+		 keyboard_response => open,
+		 porta_in => PORTA_IN,
+		 pot_in => open,
+		 trig_in => TRIGGERS,
+		 CA2_DIR_OUT => CA2_DIR_OUT,
+		 CA2_OUT => CA2_OUT,
+		 CA2_IN => open,
+		 CB2_DIR_OUT => CB2_DIR_OUT,
+		 CB2_OUT => CB2_OUT,
+		 CB2_IN => open,
+		 SIO_IN => GPIO_SIO_RXD,
+		 SIO_OUT => SIO_TXD
+		 );
+
 --b2v_inst22 : entity work.scandoubler
 --PORT MAP(CLK => CLK,
 --		 RESET_N => RESET_N,
@@ -472,7 +471,7 @@
 -- TODO combine
 --SIO_RXD <= UART_RXD;
 UART_TXD <= SIO_TXD;
-GPIO_0(1) <= SIO_COMMAND;
+--GPIO_0(1) <= SIO_COMMAND;
 
 zpu_sio_command <= SIO_COMMAND;
 zpu_sio_rxd <= SIO_TXD;
@@ -537,9 +536,9 @@
 
 		CART_RD4 => CART_RD4,
 		CART_RD5 => CART_RD5,
-		CART_S4_n => open,
-		CART_S5_N => open,
-		CART_CCTL_N => open,
+		CART_S4_n => CART_S4_n,
+		CART_S5_N => CART_S5_n,
+		CART_CCTL_N => CART_CCTL_n,
 
 		SIO_RXD => SIO_RXD,
 		SIO_TXD => SIO_TXD,
@@ -558,7 +557,7 @@
 		SDRAM_ADDR => SDRAM_ADDR,
 		SDRAM_DO => SDRAM_DO,
 
-		ANTIC_REFRESH => open, -- TODO
+		ANTIC_REFRESH => SDRAM_REFRESH,
 
 		RAM_ADDR => RAM_ADDR,
 		RAM_DO => RAM_DO,
@@ -586,8 +585,8 @@
 		ROM_SELECT => rom_select,
 		CART_EMULATION_SELECT => "0000000",
 		CART_EMULATION_ACTIVATE => '0',
-		PAL => '1',
-		USE_SDRAM => '1',
+		PAL => SW(8),
+		USE_SDRAM => SW(9),
 		ROM_IN_RAM => '1',
 		THROTTLE_COUNT_6502 => speed_6502,
 		HALT => pause_atari
Index: de1/build.sh
===================================================================
--- de1/build.sh	(revision 82)
+++ de1/build.sh	(revision 83)
@@ -9,6 +9,7 @@
 cp sram.vhdl build
 cp sync_switches.vhd build
 cp zpu_rom.vhdl build
+cp gpio.vhd build
 
 mkdir build/common
 mkdir build/common/a8core
Index: de1/gpio.vhd
===================================================================
--- de1/gpio.vhd	(revision 82)
+++ de1/gpio.vhd	(revision 83)
@@ -18,7 +18,6 @@
 
 	-- pia
 	porta_in : out std_logic_vector(7 downto 0);
-	virtual_stick_in : in std_logic_vector(7 downto 0);
 	porta_out : in std_logic_vector(7 downto 0);
 	porta_output : in std_logic_vector(7 downto 0);
 	CA2_DIR_OUT : IN std_logic;
@@ -29,7 +28,6 @@
 	CB2_IN : OUT STD_LOGIC;
 	
 	-- gtia
-	virtual_trig_in : in std_logic_vector(3 downto 0);
 	trig_in : out std_logic_vector(3 downto 0);
 	
 	-- antic
@@ -40,11 +38,6 @@
 	pot_in : out std_logic_vector(7 downto 0);
 	keyboard_scan : in std_logic_vector(5 downto 0);
 	keyboard_response : out std_logic_vector(1 downto 0);
-	virtual_keycode : in std_logic_vector(5 downto 0);
-	virtual_keyheld : in std_logic;
-	virtual_shift_pressed : in std_logic;
-	virtual_control_pressed : in std_logic;
-	virtual_break_pressed : in std_logic;
 	SIO_IN : OUT STD_LOGIC;
 	SIO_OUT : IN STD_LOGIC;
 	
@@ -61,8 +54,6 @@
 	s5_n : in std_logic;
 	cctl_n : in std_logic;
 	
-	monitor : in std_logic;
-	
 	-- gpio connections
 	GPIO_0_IN : in std_logic_vector(35 downto 0);
 	GPIO_0_OUT : out std_logic_vector(35 downto 0);
@@ -116,8 +107,8 @@
 	GPIO_0_DIR_OUT(3) <= '0';
 	GPIO_0_OUT(3) <= '0';
 	
-	GPIO_0_DIR_OUT(4) <= '1';
-	GPIO_0_OUT(4) <= MONITOR; -- zpu output for logic analyzer
+	GPIO_0_DIR_OUT(4) <= 'Z';
+	GPIO_0_OUT(4) <= '0'; -- zpu output for logic analyzer
 	
 	CA2_in <= GPIO_0_IN(0);
 	CB2_in <= GPIO_0_IN(1);
@@ -262,11 +253,10 @@
 	porta_in7_synchronizer : synchronizer
 		port map (clk=>clk, raw=>porta_in_async(7), sync=>porta_in_gpio(7));
 		
-	porta_in(7 downto 4) <= porta_in_gpio(7 downto 4) when virtual_stick_in(7 downto 4) = "1111" else virtual_stick_in(7 downto 4);
-	porta_in(3 downto 0) <= porta_in_gpio(3 downto 0) when virtual_stick_in(3 downto 0) = "1111" else virtual_stick_in(3 downto 0);
+	porta_in(7 downto 4) <= porta_in_gpio(7 downto 4);
+	porta_in(3 downto 0) <= porta_in_gpio(3 downto 0);
 		
-	--trig_in_async <= virtual_trig_in and (not(gpio_enable&gpio_enable&gpio_enable&gpio_enable) or (rd5_async&"1"&GPIO_1_IN(25)&GPIO_1_IN(35)));	-- 28/40
-	trig_in_async <= virtual_trig_in and (not(gpio_enable&gpio_enable&"11") or (rd5_async&"1"&GPIO_1_IN(25)&GPIO_1_IN(35)));	-- 28/40
+	trig_in_async <= (not(gpio_enable&gpio_enable&"11") or (rd5_async&"1"&GPIO_1_IN(25)&GPIO_1_IN(35)));	-- 28/40
 	trig_in0_synchronizer : synchronizer
 		port map (clk=>clk, raw=>trig_in_async(0), sync=>trig_in_sync(0));							
 	trig_in1_synchronizer : synchronizer
@@ -287,30 +277,7 @@
 	keyboard_response2_synchronizer : synchronizer
 		port map (clk=>clk, raw=>keyboard_response_async(1), sync=>keyboard_response_gpio(1));			
 		
-	process(gpio_enable, keyboard_scan, keyboard_response_gpio, virtual_keycode, virtual_keyheld, virtual_shift_pressed, virtual_control_pressed, virtual_break_pressed, virtual_stick_in, virtual_trig_in)
-	begin	
-		keyboard_response <= keyboard_response_gpio;
-		
-		if (gpio_enable = '0') then
-			keyboard_response <= (others=>'1');
-		end if;
-		
-		if (virtual_keyheld='1' and virtual_keycode = not(keyboard_scan)) then
-			keyboard_response(0) <= '0';
-		end if;
-		
-		if (keyboard_scan(5 downto 4)="00" and virtual_break_pressed = '1') then
-			keyboard_response(1) <= '0';
-		end if;
-		
-		if (keyboard_scan(5 downto 4)="10" and virtual_shift_pressed = '1') then
-			keyboard_response(1) <= '0';
-		end if;
-
-		if (keyboard_scan(5 downto 4)="11" and virtual_control_pressed = '1') then
-			keyboard_response(1) <= '0';
-		end if;
-	end process;	
+	keyboard_response <= keyboard_response_gpio;
 	
 	-- cartridge
 --	 1(21). S4' Chip Select--$8000 to $9FFF  A(22). RD4 ROM present--$8000 to $9FFF
