Index: common/a8core/atari800core.vhd
===================================================================
--- common/a8core/atari800core.vhd	(revision 358)
+++ common/a8core/atari800core.vhd	(revision 359)
@@ -101,6 +101,8 @@
 		-- SIO
 		SIO_RXD : in std_logic;
 		SIO_TXD : out std_logic;
+		SIO_CLOCKIN : in std_logic :='1';
+		SIO_CLOCKOUT : out std_logic;
 		-- SIO_COMMAND_TX - see PIA PB2
 		-- TODO CLOCK IN/CLOCK OUT (unused almost everywhere...)
 
@@ -509,6 +511,7 @@
 		 SIO_IN1 => SIO_RXD,
 		 SIO_IN2 => '1',
 		 SIO_IN3 => '1',
+		 SIO_CLOCKIN => SIO_CLOCKIN,
 		 ADDR => PBI_ADDR_INT(3 DOWNTO 0),
 		 DATA_IN => WRITE_DATA(7 DOWNTO 0),
 		 keyboard_response => KEYBOARD_RESPONSE,
@@ -517,6 +520,7 @@
 		 SIO_OUT1 => SIO_TXD,
 		 SIO_OUT2 => open,
 		 SIO_OUT3 => open,
+		 SIO_CLOCKOUT => SIO_CLOCKOUT,
 		 POT_RESET => POT_RESET,
 		 CHANNEL_0_OUT => POKEY1_CHANNEL0,
 		 CHANNEL_1_OUT => POKEY1_CHANNEL1,
Index: common/a8core/pokey.vhdl
===================================================================
--- common/a8core/pokey.vhdl	(revision 358)
+++ common/a8core/pokey.vhdl	(revision 359)
@@ -47,7 +47,8 @@
 	SIO_OUT2 : OUT std_logic;
 	SIO_OUT3 : OUT std_logic;
 	
-	SIO_CLOCK : INOUT std_logic; -- TODO, should not use internally
+	SIO_CLOCKIN : IN std_logic := '1';
+	SIO_CLOCKOUT : OUT std_logic;
 	
 	POT_RESET : out std_logic
 );
@@ -1097,9 +1098,9 @@
 	end process;
 	
 	-- serial clocks
-	process(sio_clock,skctl_reg,clock_reg,clock_sync_reg,audf1_pulse,audf2_pulse,audf3_pulse)
+	process(sio_clockin,skctl_reg,clock_reg,clock_sync_reg,audf1_pulse,audf2_pulse,audf3_pulse)
 	begin
-		clock_next <= sio_clock;
+		clock_next <= sio_clockin;
 		clock_sync_next <= clock_reg;
 	
 		serout_enable <= '0';
@@ -1224,7 +1225,7 @@
 	sio_out2 <= sio_out_reg;	
 	sio_out3 <= sio_out_reg;	
 	
-	sio_clock <= audf3_pulse when clock_input='0' else 'Z';
+	sio_clockout <= audf3_pulse when clock_input='0' else 'Z';
 	
 	pot_reset <= pot_reset_reg;
 		
Index: de1/atari800core_de1.vhd
===================================================================
--- de1/atari800core_de1.vhd	(revision 358)
+++ de1/atari800core_de1.vhd	(revision 359)
@@ -172,6 +172,9 @@
 
 	SIGNAL GPIO_SIO_RXD : std_logic;
 
+	SIGNAL SIO_CLOCKOUT : std_logic;
+	SIGNAL SIO_CLOCKIN : std_logic;
+
 	-- VIDEO
 	signal VGA_VS_RAW : std_logic;
 	signal VGA_HS_RAW : std_logic;
@@ -355,10 +358,6 @@
 		 );
 
 -- PIA mapping
-CA1_IN <= '1';
-CB1_IN <= '1';
-CA2_IN <= CA2_OUT when CA2_DIR_OUT='1' else '1';
-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);
@@ -457,6 +456,11 @@
 		 SIO_IN => GPIO_SIO_RXD,
 		 SIO_OUT => SIO_TXD
 		 );
+
+	CA1_IN <= '1';
+	CB1_IN <= '1';
+	CA2_IN <= CA2_OUT when CA2_DIR_OUT='1' else '1';
+	CB2_IN <= CB2_OUT when CB2_DIR_OUT='1' else '1';
 end generate gen_old_gpio;
 
 gen_new_gpio : if gpio=2 generate
@@ -496,12 +500,14 @@
 		 trig_in => TRIGGERS,
 		 CA2_DIR_OUT => CA2_DIR_OUT,
 		 CA2_OUT => CA2_OUT,
-		 CA2_IN => open,
+		 CA2_IN => CA2_IN,
 		 CB2_DIR_OUT => CB2_DIR_OUT,
 		 CB2_OUT => CB2_OUT,
-		 CB2_IN => open,
+		 CB2_IN => CB2_IN,
 		 SIO_IN => GPIO_SIO_RXD,
-		 SIO_OUT => SIO_TXD
+		 SIO_OUT => SIO_TXD,
+		 SIO_CLOCKIN => SIO_CLOCKIN,
+		 SIO_CLOCKOUT => SIO_CLOCKOUT
 		 );
 end generate gen_new_gpio;
 
@@ -620,7 +626,7 @@
 
 zpu_sio_command <= SIO_COMMAND;
 zpu_sio_rxd <= SIO_TXD;
-SIO_RXD <= zpu_sio_txd and UART_RXD;
+SIO_RXD <= zpu_sio_txd and UART_RXD and GPIO_SIO_RXD;
 
 -- VIDEO
 --VGA_HS <= not(VGA_HS_RAW xor VGA_VS_RAW);
@@ -691,6 +697,9 @@
 		SIO_RXD => SIO_RXD,
 		SIO_TXD => SIO_TXD,
 
+		SIO_CLOCKIN => SIO_CLOCKIN,
+		SIO_CLOCKOUT => SIO_CLOCKOUT,
+
 		CONSOL_OPTION => CONSOL_OPTION,
 		CONSOL_SELECT => CONSOL_SELECT,
 		CONSOL_START=> CONSOL_START,
Index: de1/gpiov2.vhd
===================================================================
--- de1/gpiov2.vhd	(revision 358)
+++ de1/gpiov2.vhd	(revision 359)
@@ -25,9 +25,11 @@
 	porta_in : out std_logic_vector(7 downto 0);
 	porta_out : in std_logic_vector(7 downto 0);
 	porta_output : in std_logic_vector(7 downto 0);
+	CA1_IN : OUT STD_LOGIC;
 	CA2_DIR_OUT : IN std_logic;
 	CA2_OUT : IN std_logic;
 	CA2_IN : OUT STD_LOGIC;
+	CB1_IN : OUT STD_LOGIC;
 	CB2_DIR_OUT : IN std_logic;
 	CB2_OUT : IN std_logic;
 	CB2_IN : OUT STD_LOGIC;
@@ -45,6 +47,8 @@
 	keyboard_response : out std_logic_vector(1 downto 0);
 	SIO_IN : OUT STD_LOGIC;
 	SIO_OUT : IN STD_LOGIC;
+	SIO_CLOCKIN : OUT STD_LOGIC;
+	SIO_CLOCKOUT : IN STD_LOGIC;
 	
 	-- cartridge
 	enable_179_early : in std_logic;
@@ -107,56 +111,67 @@
 begin	
 -- OUTPUTS TO GPIO
 	-- unused
-	GPIO_0_DIR_OUT(35 downto 4) <= (others=>'0');
-	GPIO_0_OUT(35 downto 4) <= (others=>'0');
+	--GPIO_0_DIR_OUT(35 downto 4) <= (others=>'0');
+	GPIO_0_OUT(35 downto 0) <= (others=>'0');
 	
 	-- sio
-	GPIO_0_DIR_OUT(0) <= CA2_dir_out;
-	GPIO_0_OUT(0) <= CA2_out;
-	GPIO_0_DIR_OUT(1) <= CB2_dir_out;
-	GPIO_0_OUT(1) <= CB2_out;
-	GPIO_0_DIR_OUT(2) <= '1';
-	GPIO_0_OUT(2) <= SIO_OUT;
-	GPIO_0_DIR_OUT(3) <= '0';
-	GPIO_0_OUT(3) <= '0';
+	--CB1=SIO_IRQ
+	--CB2=SIO_COMMAND
+	--CA1=SIO_PROCEED
+	--CA2=SIO_MOTOR_RAW
+
+	GPIO_0_DIR_OUT(0) <= '0';
+	GPIO_0_DIR_OUT(1) <= CB2_dir_out and not(CB2_OUT) and gpio_enable;
+	GPIO_0_DIR_OUT(2) <= '0';
+	GPIO_0_DIR_OUT(3) <= CA2_dir_out and not(CA2_OUT) and gpio_enable;
+	GPIO_0_DIR_OUT(4) <= not(SIO_OUT) and gpio_enable;
+	GPIO_0_DIR_OUT(5) <= '0';
+	GPIO_0_DIR_OUT(6) <= not(SIO_CLOCKOUT) and gpio_enable;
+	GPIO_0_DIR_OUT(7) <= '0';
 	
-	GPIO_0_DIR_OUT(4) <= 'Z';
-	GPIO_0_OUT(4) <= '0'; -- zpu output for logic analyzer
-	
-	CA2_in <= GPIO_0_IN(0);
+	CB1_in <= GPIO_0_IN(0);
 	CB2_in <= GPIO_0_IN(1);
-	SIO_IN <= GPIO_0_IN(3);
+	CA1_in <= GPIO_0_IN(2);
+	CA2_in <= GPIO_0_IN(3);
+	SIO_IN <= GPIO_0_IN(5);
+	SIO_CLOCKIN <= GPIO_0_IN(7);
 	
 	-- sticks
-	--GPIO_0_OUT(35 downto 19) <= (others=>'0');
-	--GPIO_0_DIR_OUT(35) <= '0'; -- trig 0
-	--GPIO_0_DIR_OUT(34) <= gpio_enable and porta_output(0) and not(porta_out(0)); -- stick 0
-	--GPIO_0_DIR_OUT(33) <= '0';
-	--GPIO_0_DIR_OUT(32) <= gpio_enable and porta_output(1) and not(porta_out(1)); -- stick 0
-	--GPIO_0_DIR_OUT(31) <= '0';
-	--GPIO_0_DIR_OUT(30) <= gpio_enable and porta_output(2) and not(porta_out(2)); -- stick 0
-	--GPIO_0_DIR_OUT(29) <= gpio_enable and pot_reset;
-	--GPIO_0_DIR_OUT(28) <= gpio_enable and porta_output(3) and not(porta_out(3)); -- stick 0
-	--GPIO_0_DIR_OUT(27) <= gpio_enable and pot_reset;
-	--GPIO_0_DIR_OUT(26) <= gpio_enable and pot_reset;
-	--GPIO_0_DIR_OUT(25) <= '0'; -- trig 1
-	--GPIO_0_DIR_OUT(24) <= gpio_enable and porta_output(4) and not(porta_out(4)); -- stick 1
-	--GPIO_0_DIR_OUT(23) <= gpio_enable and porta_output(7) and not(porta_out(7)); -- stick 1
-	--GPIO_0_DIR_OUT(22) <= gpio_enable and porta_output(5) and not(porta_out(5)); -- stick 1
-	--GPIO_0_DIR_OUT(21) <= gpio_enable and pot_reset;
-	--GPIO_0_DIR_OUT(20) <= gpio_enable and porta_output(6) and not(porta_out(6)); -- stick 1
-	--GPIO_0_DIR_OUT(19 downto 8) <= (others=>'0');
+	-- PORTA7,6,5,4,TRIG1,POT3,2,1,0,PORTA3,2,1,0,TRIG0
+	GPIO_0_DIR_OUT(8) <= gpio_enable and porta_output(7) and not(porta_out(7)); -- stick
+	GPIO_0_DIR_OUT(9) <= gpio_enable and porta_output(6) and not(porta_out(6)); -- stick
+	GPIO_0_DIR_OUT(10) <= gpio_enable and porta_output(5) and not(porta_out(5)); -- stick
+	GPIO_0_DIR_OUT(11) <= gpio_enable and porta_output(4) and not(porta_out(4)); -- stick
+	GPIO_0_DIR_OUT(17) <= gpio_enable and porta_output(3) and not(porta_out(3)); -- stick
+	GPIO_0_DIR_OUT(18) <= gpio_enable and porta_output(2) and not(porta_out(2)); -- stick
+	GPIO_0_DIR_OUT(19) <= gpio_enable and porta_output(1) and not(porta_out(1)); -- stick
+	GPIO_0_DIR_OUT(20) <= gpio_enable and porta_output(0) and not(porta_out(0)); -- stick
+
+	GPIO_0_DIR_OUT(12) <= '0'; -- trig
+	GPIO_0_DIR_OUT(21) <= '0'; -- trig
+
+	GPIO_0_DIR_OUT(13) <= gpio_enable and pot_reset;
+	GPIO_0_DIR_OUT(14) <= gpio_enable and pot_reset;
+	GPIO_0_DIR_OUT(15) <= gpio_enable and pot_reset;
+	GPIO_0_DIR_OUT(16) <= gpio_enable and pot_reset;
+
+	-- ext
+	GPIO_0_DIR_OUT(22) <= '0';
+	GPIO_0_DIR_OUT(23) <= '0';
+	GPIO_0_DIR_OUT(24) <= '0';
+	GPIO_0_DIR_OUT(25) <= '0';
+	GPIO_0_DIR_OUT(26) <= '0';
+	GPIO_0_DIR_OUT(27) <= '0';
 	
 	-- keyboard
-	--GPIO_0_OUT(7 downto 0) <= (others=>'0');
-	--GPIO_0_DIR_OUT(7) <= '0'; -- keyboard response 2
-	--GPIO_0_DIR_OUT(6) <= '0'; -- keyboard response 1
-	--GPIO_0_DIR_OUT(5) <= gpio_enable and not(keyboard_scan(5)); -- keyboard scan 5
-	--GPIO_0_DIR_OUT(4) <= gpio_enable and not(keyboard_scan(4)); -- keyboard scan 4
-	--GPIO_0_DIR_OUT(3) <= gpio_enable and not(keyboard_scan(3)); -- keyboard scan 3
-	--GPIO_0_DIR_OUT(2) <= gpio_enable and not(keyboard_scan(2)); -- keyboard scan 2
-	--GPIO_0_DIR_OUT(1) <= gpio_enable and not(keyboard_scan(1)); -- keyboard scan 1
-	--GPIO_0_DIR_OUT(0) <= gpio_enable and not(keyboard_scan(0)); -- keyboard scan 0
+	GPIO_0_DIR_OUT(28) <= gpio_enable and not(keyboard_scan(2)); -- keyboard scan 2
+	GPIO_0_DIR_OUT(29) <= gpio_enable and not(keyboard_scan(1)); -- keyboard scan 1
+	GPIO_0_DIR_OUT(30) <= gpio_enable and not(keyboard_scan(0)); -- keyboard scan 0
+	GPIO_0_DIR_OUT(31) <= '0'; -- keyboard response 1
+	GPIO_0_DIR_OUT(32) <= gpio_enable and not(keyboard_scan(5)); -- keyboard scan 5
+	GPIO_0_DIR_OUT(33) <= gpio_enable and not(keyboard_scan(4)); -- keyboard scan 4
+	GPIO_0_DIR_OUT(34) <= gpio_enable and not(keyboard_scan(3)); -- keyboard scan 3
+	GPIO_0_DIR_OUT(35) <= '0'; -- keyboard response 2
 	
 	-- cart
 	GPIO_1_DIR_OUT(0) <= gpio_enable and bus_control_oe; -- cart control
@@ -236,55 +251,50 @@
 	
 -- INPUTS FROM GPIO	
 	-- sticks
---	pot_in_async <= 
---					gpio_enable&gpio_enable&gpio_enable&gpio_enable&gpio_enable&gpio_enable&gpio_enable&gpio_enable and 
---					("0000"&
---					GPIO_1_IN(27)&GPIO_1_IN(21)& -- 32/24
---					GPIO_1_IN(26)&GPIO_1_IN(29)); -- 31/34
---	pot_in0_synchronizer : synchronizer
---		port map (clk=>clk, raw=>pot_in_async(0), sync=>pot_in(0));						
---	pot_in1_synchronizer : synchronizer
---		port map (clk=>clk, raw=>pot_in_async(1), sync=>pot_in(1));						
---	pot_in2_synchronizer : synchronizer
---		port map (clk=>clk, raw=>pot_in_async(2), sync=>pot_in(2));						
---	pot_in3_synchronizer : synchronizer
---		port map (clk=>clk, raw=>pot_in_async(3), sync=>pot_in(3));							
---	pot_in4_synchronizer : synchronizer
---		port map (clk=>clk, raw=>pot_in_async(4), sync=>pot_in(4));						
---	pot_in5_synchronizer : synchronizer
---		port map (clk=>clk, raw=>pot_in_async(5), sync=>pot_in(5));						
---	pot_in6_synchronizer : synchronizer
---		port map (clk=>clk, raw=>pot_in_async(6), sync=>pot_in(6));						
---	pot_in7_synchronizer : synchronizer
---		port map (clk=>clk, raw=>pot_in_async(7), sync=>pot_in(7));								
-	pot_in(7 downto 0) <= (others=>'0');
+	pot_in_async <= 
+					gpio_enable&gpio_enable&gpio_enable&gpio_enable&gpio_enable&gpio_enable&gpio_enable&gpio_enable and 
+					("0000"&
+					GPIO_0_IN(13)&GPIO_0_IN(14)&
+					GPIO_0_IN(15)&GPIO_0_IN(16));
+	pot_in0_synchronizer : synchronizer
+		port map (clk=>clk, raw=>pot_in_async(0), sync=>pot_in(0));						
+	pot_in1_synchronizer : synchronizer
+		port map (clk=>clk, raw=>pot_in_async(1), sync=>pot_in(1));						
+	pot_in2_synchronizer : synchronizer
+		port map (clk=>clk, raw=>pot_in_async(2), sync=>pot_in(2));						
+	pot_in3_synchronizer : synchronizer
+		port map (clk=>clk, raw=>pot_in_async(3), sync=>pot_in(3));							
+	pot_in4_synchronizer : synchronizer
+		port map (clk=>clk, raw=>pot_in_async(4), sync=>pot_in(4));						
+	pot_in5_synchronizer : synchronizer
+		port map (clk=>clk, raw=>pot_in_async(5), sync=>pot_in(5));						
+	pot_in6_synchronizer : synchronizer
+		port map (clk=>clk, raw=>pot_in_async(6), sync=>pot_in(6));						
+	pot_in7_synchronizer : synchronizer
+		port map (clk=>clk, raw=>pot_in_async(7), sync=>pot_in(7));								
+	porta_in_async <= 
+					GPIO_0_IN(8)&GPIO_0_IN(9)&GPIO_0_IN(10)&GPIO_0_IN(11)& 
+					GPIO_0_IN(17)&GPIO_0_IN(18)&GPIO_0_IN(19)&GPIO_0_IN(20); 
+	porta_in0_synchronizer : synchronizer
+		port map (clk=>clk, raw=>porta_in_async(0), sync=>porta_in_gpio(0));						
+	porta_in1_synchronizer : synchronizer
+		port map (clk=>clk, raw=>porta_in_async(1), sync=>porta_in_gpio(1));						
+	porta_in2_synchronizer : synchronizer
+		port map (clk=>clk, raw=>porta_in_async(2), sync=>porta_in_gpio(2));						
+	porta_in3_synchronizer : synchronizer
+		port map (clk=>clk, raw=>porta_in_async(3), sync=>porta_in_gpio(3));						
+	porta_in4_synchronizer : synchronizer
+		port map (clk=>clk, raw=>porta_in_async(4), sync=>porta_in_gpio(4));						
+	porta_in5_synchronizer : synchronizer
+		port map (clk=>clk, raw=>porta_in_async(5), sync=>porta_in_gpio(5));						
+	porta_in6_synchronizer : synchronizer
+		port map (clk=>clk, raw=>porta_in_async(6), sync=>porta_in_gpio(6));						
+	porta_in7_synchronizer : synchronizer
+		port map (clk=>clk, raw=>porta_in_async(7), sync=>porta_in_gpio(7));
 		
---	porta_in_async <= 
---					GPIO_1_IN(23)&GPIO_1_IN(20)&GPIO_1_IN(22)&GPIO_1_IN(24)& -- 27/25/23/26
---					GPIO_1_IN(28)&GPIO_1_IN(30)&GPIO_1_IN(32)&GPIO_1_IN(34); -- 39/37/35/33					
---	porta_in0_synchronizer : synchronizer
---		port map (clk=>clk, raw=>porta_in_async(0), sync=>porta_in_gpio(0));						
---	porta_in1_synchronizer : synchronizer
---		port map (clk=>clk, raw=>porta_in_async(1), sync=>porta_in_gpio(1));						
---	porta_in2_synchronizer : synchronizer
---		port map (clk=>clk, raw=>porta_in_async(2), sync=>porta_in_gpio(2));						
---	porta_in3_synchronizer : synchronizer
---		port map (clk=>clk, raw=>porta_in_async(3), sync=>porta_in_gpio(3));						
---	porta_in4_synchronizer : synchronizer
---		port map (clk=>clk, raw=>porta_in_async(4), sync=>porta_in_gpio(4));						
---	porta_in5_synchronizer : synchronizer
---		port map (clk=>clk, raw=>porta_in_async(5), sync=>porta_in_gpio(5));						
---	porta_in6_synchronizer : synchronizer
---		port map (clk=>clk, raw=>porta_in_async(6), sync=>porta_in_gpio(6));						
---	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);
---	porta_in(3 downto 0) <= porta_in_gpio(3 downto 0);
-	porta_in(7 downto 0) <= (others=>'1');
+	porta_in(7 downto 0) <= porta_in_gpio(7 downto 0);
 		
---	trig_in_async <= (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&"111"));
+	trig_in_async <= (not(gpio_enable&gpio_enable&"11") or (rd5_async&"1"&GPIO_0_IN(12)&GPIO_0_IN(21)));
 	trig_in0_synchronizer : synchronizer
 		port map (clk=>clk, raw=>trig_in_async(0), sync=>trig_in_sync(0));							
 	trig_in1_synchronizer : synchronizer
@@ -299,8 +309,7 @@
 	lightpen <= trig_in_sync(0) and trig_in_sync(1); -- either joystick button				
 	
 	-- keyboard
-	--keyboard_response_async <= not(gpio_enable&gpio_enable) or (GPIO_1_IN(7)& GPIO_1_IN(6));
-	keyboard_response_async <= "11";
+	keyboard_response_async <= not(gpio_enable&gpio_enable) or (GPIO_0_IN(35)& GPIO_0_IN(31));
 	keyboard_response1_synchronizer : synchronizer
 		port map (clk=>clk, raw=>keyboard_response_async(0), sync=>keyboard_response_gpio(0));						
 	keyboard_response2_synchronizer : synchronizer
