INCLUDES = vend.h
-CFLAGS = -O3 -Wall -m68hc11 -mshort -Wall -Os -g0 \
+CFLAGS = -O3 -m68hc11 -mshort -Wall -Os -g0 \
-msoft-reg-count=0 -ffixed-z
LDFLAGS = -m68hc11 -mshort -Wl,-m,m68hc11elfb \
#include "types.h"
-/* these would be inline functions, but gcc won't believe that mask is a constant
- * when passed as a parameter
+/* The "g" below really should be an "i", but gcc doesn't believe that it will
+ * always be an immediate value. Using "g" makes the compiler be quiet, but
+ * the assembler will fail if the value is not an immediate.
*/
-#define bset(addr, mask) \
- asm volatile ( \
- "ldx %0\n" \
- "bset 00,x,%1" \
- : /* outputs */ \
- : "p" (addr), "i" (mask) /* inputs */ \
- : "x" /* altered registers */ \
+extern inline void bset(void* addr, u8 mask) {
+ asm volatile (
+ "ldx %0\n"
+ "bset 00,x,%1"
+ : /* outputs */
+ : "p" (addr), "g" (mask) /* inputs */
+ : "x" /* altered registers */
);
+}
-#define bclr(addr, mask) \
- asm volatile ( \
- "ldx %0\n" \
- "bclr 00,x,%1" \
- : /* outputs */ \
- : "p" (addr), "i" (mask) /* inputs */ \
- : "x" /* altered registers */ \
+extern inline void bclr(void* addr, u8 mask) {
+ asm volatile (
+ "ldx %0\n"
+ "bclr 00,x,%1"
+ : /* outputs */
+ : "p" (addr), "g" (mask) /* inputs */
+ : "x" /* altered registers */
);
+}
#endif /* _ASM_H_ */
#define DISPLAY_DELAY 100 /* ms to delay between ops - could be tweaked */
void display_reset() {
/* lower the reset line for a while */
- bclr(&_io_ports[M6811_PORTA], PORTA_DISP_RESET);
+ bclr((void*)&_io_ports[M6811_PORTA], PORTA_DISP_RESET);
delay(DISPLAY_DELAY);
- bset(&_io_ports[M6811_PORTA], PORTA_DISP_RESET);
+ bset((void*)&_io_ports[M6811_PORTA], PORTA_DISP_RESET);
spi_enable();
delay(DISPLAY_DELAY);
#include "vend.h"
+#define DELAY_MAGIC 20 /* FIXME: number of loops required for ~ 1 millisecond */
void delay(u16 ms) {
- /* FIXME fill me in */
+ int i;
+ for (;ms;ms--) {
+ for (i=0;i<DELAY_MAGIC; i++)
+ asm("nop\nnop\nnop\nnop\nnop\n");
+ }
}
#include "vend.h"
-int keypad_read_row() {
- bclr_misc_output(A3800_DISPLAY_WRITE); /* disable the display clock */
+u8 last_key; /* the last key registered */
+u8 curr_key; /* the key currently being held down */
- _io_ports[M6811_SPDR] = 0;
- while(!(_io_ports[M6811_SPDR]&M6811_SPIE)); /* wait for completion */
+/* first 8 from the first row, then 3 from the second row */
+/* keys are 1-9, 0, reset */
+const u8 keymap0[8] = {8, 7, 6, 5, 4, 3, 2, 1};
+const u8 keymap1[3] = {11, 10, 9};
- return _io_ports[M6811_SPDR];
-}
-
-/* row is 0 or 1 */
-void keypad_select_row(int row) {
+extern inline int keypad_read_row(int row) {
+ int i, num;
if (row)
_io_ports[M6811_PORTD] |= PORTD_KEYPAD_ROW;
else
_io_ports[M6811_PORTD] &= ~PORTD_KEYPAD_ROW;
+
+ bclr_misc_output(A3800_DISPLAY_WRITE); /* disable the display clock */
+
+ _io_ports[M6811_SPDR] = 0;
+ while(!(_io_ports[M6811_SPDR]&M6811_SPIE)); /* wait for completion */
+
+ for (i = _io_ports[M6811_SPDR], num = 0;
+ (i&0x1) == 0;
+ i=i>>1, num++);
+
+ return num;
}
+/* returns a key 0..9 or 11 for reset */
+void keypad_read() {
+ /* FIXME: need to do debouncing of some sort? */
+ int key;
+ key = keypad_read_row(0);
+ if (!key) {
+ key = keypad_read_row(1);
+ curr_key = keymap0[key];
+ }
+ curr_key = keymap1[key];
+
+ if (curr_key != last_key) {
+ last_key = curr_key;
+ }
+}
--- /dev/null
+#ifndef _KEYPAD_H_
+#define _KEYPAD_H_
+
+extern u8 last_key;
+extern u8 curr_key;
+
+#endif /* _KEYPAD_H_ */
#include "types.h"
#include "asm.h"
-/* addresses of these set at link time */
-/* to add more addresses, define them here with buffered_addr_h, in helpers.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; \
u8 a; \
extern inline void set_##a(u8 b) { a = *_##a = b; } \
- extern inline void bset_##a(u8 m) { a |= m; *_##a = a; } \
- extern inline void bclr_##a(u8 m) { a &= ~m ; *_##a = a; }
+ extern inline void bset_##a(const u8 m) { bset(&a, m); *_##a = a; } \
+ extern inline void bclr_##a(const u8 m) { bclr(&a, m); *_##a = a; }
buffered_addr(switch_input);
buffered_addr(misc_input);
buffered_addr(changer_output);
buffered_addr(misc_output);
-extern inline void spi_enable() { _io_ports[M6811_SPCR] |= M6811_SPE; }
-extern inline void spi_disable() { _io_ports[M6811_SPCR] &= ~M6811_SPE; }
+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); }
/******* from helpers.c *******/
-
void delay(u16 ms);
/******** Some meaningful bits ******/