typedef unsigned char byte;

#pragma interface
class IOBox {
public:
	IOBox();
	byte getSwitch0() const;
	byte getSwitch1() const;
	byte getSwitch2() const;
	byte getSwitch3() const;
	byte getSwitch4() const;
	byte getSwitch5() const;
	byte getSwitch6() const;
	byte getSwitch7() const;
	byte getAllSwitches() const;
	void setLed0(byte b);
	void setLed1(byte b);
	void setLed2(byte b);
	void setLed3(byte b);
	void setLed4(byte b);
	void setLed5(byte b);
	void setLed6(byte b);
	void setLed7(byte b);
	void setAllLeds(byte b);
private:
	struct ports {
		byte c;
		byte b;
	} __attribute__ ((packed));
	volatile ports* port;
};

inline IOBox::IOBox(): port(reinterpret_cast<volatile ports*>(0x1003)) { }
inline byte IOBox::getSwitch0() const { return port->c&0x01; }
inline byte IOBox::getSwitch1() const { return port->c&0x02; }
inline byte IOBox::getSwitch2() const { return port->c&0x04; }
inline byte IOBox::getSwitch3() const { return port->c&0x08; }
inline byte IOBox::getSwitch4() const { return port->c&0x10; }
inline byte IOBox::getSwitch5() const { return port->c&0x20; }
inline byte IOBox::getSwitch6() const { return port->c&0x40; }
inline byte IOBox::getSwitch7() const { return port->c&0x80; }
inline byte IOBox::getAllSwitches() const { return port->c; }
inline void IOBox::setLed0(byte b) { if (b) port->b|=0x01; else port->b&=~0x01; }
inline void IOBox::setLed1(byte b) { if (b) port->b|=0x02; else port->b&=~0x02; }
inline void IOBox::setLed2(byte b) { if (b) port->b|=0x04; else port->b&=~0x04; }
inline void IOBox::setLed3(byte b) { if (b) port->b|=0x08; else port->b&=~0x08; }
inline void IOBox::setLed4(byte b) { if (b) port->b|=0x10; else port->b&=~0x10; }
inline void IOBox::setLed5(byte b) { if (b) port->b|=0x20; else port->b&=~0x20; }
inline void IOBox::setLed6(byte b) { if (b) port->b|=0x40; else port->b&=~0x40; }
inline void IOBox::setLed7(byte b) { if (b) port->b|=0x80; else port->b&=~0x80; }
inline void IOBox::setAllLeds(byte b) { port->b=b; }
