megadrive_test2

annotate 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
rev   line source
nuclear@6 1 #ifndef MEGADRIVE_IO_H_
nuclear@6 2 #define MEGADRIVE_IO_H_
nuclear@6 3
nuclear@7 4 #include <stdint.h>
nuclear@7 5
nuclear@7 6 #define IO_REG_VER *((volatile uint8_t*)0xa10001)
nuclear@7 7 #define IO_REG_DATA1 *((volatile uint8_t*)0xa10003)
nuclear@7 8 #define IO_REG_DATA2 *((volatile uint8_t*)0xa10005)
nuclear@7 9 #define IO_REG_DATA3 *((volatile uint8_t*)0xa10007)
nuclear@7 10 #define IO_REG_CTRL1 *((volatile uint8_t*)0xa10009)
nuclear@7 11 #define IO_REG_CTRL2 *((volatile uint8_t*)0xa1000b)
nuclear@7 12 #define IO_REG_CTRL3 *((volatile uint8_t*)0xa1000d)
nuclear@7 13 #define IO_REG_TXDATA1 *((volatile uint8_t*)0xa1000f)
nuclear@7 14 #define IO_REG_RXDATA1 *((volatile uint8_t*)0xa10011)
nuclear@7 15 #define IO_REG_S_CTRL1 *((volatile uint8_t*)0xa10013)
nuclear@7 16 #define IO_REG_TXDATA2 *((volatile uint8_t*)0xa10015)
nuclear@7 17 #define IO_REG_RXDATA2 *((volatile uint8_t*)0xa10017)
nuclear@7 18 #define IO_REG_S_CTRL2 *((volatile uint8_t*)0xa10013)
nuclear@7 19 #define IO_REG_TXDATA3 *((volatile uint8_t*)0xa1001b)
nuclear@7 20 #define IO_REG_RXDATA3 *((volatile uint8_t*)0xa1001d)
nuclear@7 21 #define IO_REG_S_CTRL3 *((volatile uint8_t*)0xa1001f)
nuclear@7 22 #define IO_REG_LOCK *((volatile uint8_t*)0xa14000)
nuclear@7 23 #define IO_REG_TMSS *((volatile uint8_t*)0xa14101)
nuclear@7 24
nuclear@8 25 #define IO_REG_DATA(x) *((volatile uint8_t*)0xa10003 + ((x) << 1))
nuclear@8 26 #define IO_REG_CTRL(x) *((volatile uint8_t*)0xa10009 + ((x) << 1))
nuclear@8 27
nuclear@6 28
nuclear@6 29 enum {
nuclear@6 30 IO_VER_VERSION_MASK = 0x0f,
nuclear@6 31 IO_VER_EXP = 0x20,
nuclear@6 32 IO_VER_PAL = 0x40,
nuclear@6 33 IO_VER_NONJP = 0x80
nuclear@6 34 };
nuclear@6 35
nuclear@8 36 enum {
nuclear@8 37 IO_PAD_UP = 1,
nuclear@8 38 IO_PAD_DOWN = 2,
nuclear@8 39 IO_PAD_LEFT = 4,
nuclear@8 40 IO_PAD_RIGHT = 8,
nuclear@8 41 IO_PAD_B = 16,
nuclear@8 42 IO_PAD_C = 32,
nuclear@8 43 IO_PAD_A = 64,
nuclear@8 44 IO_PAD_START = 128
nuclear@8 45 };
nuclear@8 46
nuclear@8 47 static inline void io_setdir(int port, uint8_t dir)
nuclear@8 48 {
nuclear@8 49 IO_REG_CTRL(port) = dir;
nuclear@8 50 }
nuclear@8 51
nuclear@8 52 static inline uint16_t io_readpad(int port)
nuclear@8 53 {
nuclear@8 54 uint16_t bnstate;
nuclear@8 55
nuclear@8 56 io_setdir(port, 0x40); /* pin 6 (multiplexer) output, 0-5 inputs */
nuclear@8 57 IO_REG_DATA(port) = 0x40; /* select mode 1 */
nuclear@8 58 bnstate = IO_REG_DATA(port);
nuclear@8 59 IO_REG_DATA(port) = 0; /* select mode 0 */
nuclear@8 60 bnstate |= (IO_REG_DATA(port) << 2) & (IO_PAD_A | IO_PAD_START);
nuclear@8 61 return bnstate;
nuclear@8 62 }
nuclear@8 63
nuclear@6 64 #endif /* MEGADRIVE_IO_H_ */