#ifndef _VEND_H_
#define _VEND_H_
-/* FIXME: are these typedefs right for m68hc11-gcc? */
-typedef unsigned char u8;
-typedef signed char s8;
-typedef unsigned short u16;
-typedef signed short s16;
-typedef unsigned long u32;
-typedef signed long s32;
-typedef u8 bool;
-typedef u16 addr_t;
+#include "ports.h"
+#include "types.h"
+#include "asm.h"
-/******* from display.c *******/
+/* addresses of these set at link time
+ * to add more addresses, define them here with buffered_addr_h, in helpers.c
+ * with buffered_addr, and also in LDFLAGS in the Makefile
+ */
+#define buffered_addr(a) \
+ extern volatile u8 _##a; \
+ volatile u8 a; \
+ extern inline void set_##a(u8 b) { a = b; _##a = b; } \
+ extern inline void bset_##a(const u8 m) { bset((void*)&a, m); _##a = a; } \
+ extern inline void bclr_##a(const u8 m) { bclr((void*)&a, m); _##a = a; }
-/* scrolling modes */
-#define WRAP_SCROLL_L 1 /* scroll to the left */
-#define WRAP_SCROLL_R 1 /* scroll to the right */
-#define WRAP_ALTERNATE 2 /* alternate between text */
+buffered_addr(changer_output);
+buffered_addr(misc_output);
-extern char current_message[1024];
+extern volatile u8 _switch_input;
+#define switch_input _switch_input
+extern volatile u8 _misc_input;
+#define misc_input _misc_input
+extern volatile u8 _home_sensors;
+#define home_sensors _home_sensors
-void set_msg(char* newmsg);
-void set_wrap_mode(u8 new_wrap_mode);
-void display_refresh();
+extern u16 _stack;
/******* from helpers.c *******/
-#define buffered_port_h(p) \
- void outb_##p(u8 b); \
- void bset_##p(u8 mask); \
- void bclr_##p(u8 mask);
+void delay(u16 ms);
+void my_strncpy(char* dst, char* src, u8 max_size); /* for null-term strings */
+void my_memcpy(char* dst, char* src, u8 size);
-void outb(u16 port, u8 byte);
-void bset(u16 addr, u8 mask);
-void bclr(u16 addr, u8 mask);
+/******** Some meaningful bits ******/
+#define PORTA_CHIME 0x10 /* chime is on when set */
+#define PORTA_MOTOR_CLOCK 0x20
+#define PORTA_MOTOR_COL_DISABLE 0x40
+#define PORTA_DISP_RESET 0x80 /* active low */
-buffered_port_h(3800);
+#define PORTD_KEYPAD_ROW 0x20 /* clear for row 0, set for row 1 */
-void delay(u16 ms);
+#define PORTE_MOTOR_OVERCURRENT 0x01
+#define PORTE_MOTOR_OVERVOLTAGE 0x02
-/******** Some IO Ports ******/
-#define PORTA 0x1000
-#define PORTA_DISP_RESET 0x80 /* active low */
+/* Address 1800 bits */
+#define A1800_DOOR_OPEN 0x20
-#define SPCR 0x1028 /* Serial Peripheral Control Register */
-#define SPCR_SPE 0x40 /* Serial Peripheral System Enable */
+/* Address 3000 bits */
+#define A3000_MOTOR_ROW_DISABLE 0x80
/* Address 3800 bits */
-#define A3800_DISPLAY_WRITE 0x04
+#define A3800_KEYPAD_STROBE 0x04
+#define A3800_DISPLAY_WRITE 0x08
+#define A3800_MOTOR_DATA 0x10
+#define A3800_MOTOR_COL8_ENABLE 0x20
+#define A3800_MOTOR_COL9_ENABLE 0x40
+
+/******* from main.c *******/
+int __attribute__((noreturn)) main (void);
+void __attribute__((interrupt)) rti (void);
+void __attribute__((interrupt)) sci_interrupt (void);
+void __attribute__((interrupt)) uart_interrupt (void);
+
+/* other one liners */
+extern inline bool door_open() { return switch_input & A1800_DOOR_OPEN; }
+extern inline void spi_enable() { bset((void*)&_io_ports[M6811_SPCR], M6811_SPE); }
+extern inline void spi_disable() { bclr((void*)&_io_ports[M6811_SPCR], M6811_SPE); }
#endif /* _VEND_H_ */