megadrive_test2
diff src/io.h @ 8:403367d5df5a
added 8x8 font data
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 22 Jun 2017 07:44:48 +0300 |
parents | 108ecc582a11 |
children | 6ecf2f3ff05a |
line diff
1.1 --- a/src/io.h Wed Jun 21 06:49:50 2017 +0300 1.2 +++ b/src/io.h Thu Jun 22 07:44:48 2017 +0300 1.3 @@ -22,6 +22,9 @@ 1.4 #define IO_REG_LOCK *((volatile uint8_t*)0xa14000) 1.5 #define IO_REG_TMSS *((volatile uint8_t*)0xa14101) 1.6 1.7 +#define IO_REG_DATA(x) *((volatile uint8_t*)0xa10003 + ((x) << 1)) 1.8 +#define IO_REG_CTRL(x) *((volatile uint8_t*)0xa10009 + ((x) << 1)) 1.9 + 1.10 1.11 enum { 1.12 IO_VER_VERSION_MASK = 0x0f, 1.13 @@ -30,4 +33,32 @@ 1.14 IO_VER_NONJP = 0x80 1.15 }; 1.16 1.17 +enum { 1.18 + IO_PAD_UP = 1, 1.19 + IO_PAD_DOWN = 2, 1.20 + IO_PAD_LEFT = 4, 1.21 + IO_PAD_RIGHT = 8, 1.22 + IO_PAD_B = 16, 1.23 + IO_PAD_C = 32, 1.24 + IO_PAD_A = 64, 1.25 + IO_PAD_START = 128 1.26 +}; 1.27 + 1.28 +static inline void io_setdir(int port, uint8_t dir) 1.29 +{ 1.30 + IO_REG_CTRL(port) = dir; 1.31 +} 1.32 + 1.33 +static inline uint16_t io_readpad(int port) 1.34 +{ 1.35 + uint16_t bnstate; 1.36 + 1.37 + io_setdir(port, 0x40); /* pin 6 (multiplexer) output, 0-5 inputs */ 1.38 + IO_REG_DATA(port) = 0x40; /* select mode 1 */ 1.39 + bnstate = IO_REG_DATA(port); 1.40 + IO_REG_DATA(port) = 0; /* select mode 0 */ 1.41 + bnstate |= (IO_REG_DATA(port) << 2) & (IO_PAD_A | IO_PAD_START); 1.42 + return bnstate; 1.43 +} 1.44 + 1.45 #endif /* MEGADRIVE_IO_H_ */