megadrive_test2

diff src/io.h @ 11:302bcd73edc4

added 6button support
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 24 Jun 2017 03:47:37 +0300
parents ca7108a82867
children
line diff
     1.1 --- a/src/io.h	Sat Jun 24 02:33:52 2017 +0300
     1.2 +++ b/src/io.h	Sat Jun 24 03:47:37 2017 +0300
     1.3 @@ -34,14 +34,18 @@
     1.4  };
     1.5  
     1.6  enum {
     1.7 -	IO_PAD_UP		= 1,
     1.8 -	IO_PAD_DOWN		= 2,
     1.9 -	IO_PAD_LEFT		= 4,
    1.10 -	IO_PAD_RIGHT	= 8,
    1.11 -	IO_PAD_B		= 16,
    1.12 -	IO_PAD_C		= 32,
    1.13 -	IO_PAD_A		= 64,
    1.14 -	IO_PAD_START	= 128
    1.15 +	IO_PAD_UP		= 0x001,
    1.16 +	IO_PAD_DOWN		= 0x002,
    1.17 +	IO_PAD_LEFT		= 0x004,
    1.18 +	IO_PAD_RIGHT	= 0x008,
    1.19 +	IO_PAD_B		= 0x010,
    1.20 +	IO_PAD_C		= 0x020,
    1.21 +	IO_PAD_A		= 0x040,
    1.22 +	IO_PAD_START	= 0x080,
    1.23 +
    1.24 +	IO_PAD_Z		= 0x100,
    1.25 +	IO_PAD_Y		= 0x200,
    1.26 +	IO_PAD_X		= 0x400
    1.27  };
    1.28  #define IO_PAD_LOW_MASK		0x3f
    1.29  #define IO_PAD_HIGH_MASK	(IO_PAD_A | IO_PAD_START)
    1.30 @@ -66,6 +70,36 @@
    1.31  	return bnstate;
    1.32  }
    1.33  
    1.34 +static inline uint16_t io_readpad6(int port)
    1.35 +{
    1.36 +	uint16_t bnstate;
    1.37 +
    1.38 +	IO_REG_DATA(port) = 0x40;	/* start with mode 1 */
    1.39 +	asm volatile("nop");
    1.40 +	asm volatile("nop");
    1.41 +	bnstate = ~IO_REG_DATA(port) & IO_PAD_LOW_MASK;
    1.42 +
    1.43 +	IO_REG_DATA(port) = 0;		/* select mode 0 */
    1.44 +	asm volatile("nop");
    1.45 +	asm volatile("nop");
    1.46 +	bnstate |= ~(IO_REG_DATA(port) << 2) & IO_PAD_HIGH_MASK;
    1.47 +
    1.48 +	/* then introduce two more rising edges to trigger extended mode */
    1.49 +	IO_REG_DATA(port) = 0x40;
    1.50 +	asm volatile("nop");
    1.51 +	asm volatile("nop");
    1.52 +	IO_REG_DATA(port) = 0;
    1.53 +	asm volatile("nop");
    1.54 +	asm volatile("nop");
    1.55 +	IO_REG_DATA(port) = 0x40;
    1.56 +	asm volatile("nop");
    1.57 +	asm volatile("nop");
    1.58 +
    1.59 +	bnstate |= (uint16_t)(~IO_REG_DATA(port) & 0x7) << 8;
    1.60 +	IO_REG_DATA(port) = 0;		/* return mode to 0 */
    1.61 +	return bnstate;
    1.62 +}
    1.63 +
    1.64  void io_init(void);
    1.65  /*uint16_t io_readpad(int port);*/
    1.66