Chiming.
Beginnings of an RTI.
# muchly stolen from m68hc1x's example.tar.gz's Makefile
OBJS = \
- motors.o keypad.o display.o coinmech.o helpers.o main.o \
+ motors.o keypad.o display.o coinmech.o chime.o helpers.o main.o \
vectors.o
-INCLUDES = vend.h
-
+INCLUDES = vend.h keypad.h chime.h asm.h display.h ports.h types.h
CFLAGS = -O3 -m68hc11 -mshort -Wall -Os -g0 \
-msoft-reg-count=0 -ffixed-z
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBADD)
clean:
- rm -f $(OBJS) *.elf *.s19 *.b *.a
+ rm -f *.o *.elf *.s19 *.b *.a
#
# Some useful rules
--- /dev/null
+#include "vend.h"
+#include "chime.h"
+
+u8 chime_count;
+
+void chime() {
+ /* called from the RTI interrupt, sees if we need to turn the chime on or
+ * off (chime would be on for N RTI cycles
+ */
+ if (chime_count) {
+ bset((void*)&_io_ports[M6811_PORTA], PORTA_CHIME);
+ --chime_count;
+ } else
+ bclr((void*)&_io_ports[M6811_PORTA], PORTA_CHIME);
+}
+
--- /dev/null
+#ifndef _CHIME_H_
+#define _CHIME_H_
+
+#include "types.h"
+
+#define CHIME_TIME 10 /* number of RTI interrupts to have the chimer on */
+
+extern u8 chime_count;
+
+void chime();
+extern inline void chime_start() { chime_count = CHIME_TIME; }
+
+#endif /* _CHIME_H_ */
+#include "chime.h"
#include "vend.h"
+#include "keypad.h"
u8 last_key; /* the last key registered */
-u8 curr_key; /* the key currently being held down */
+bool new_key = 0;
/* first 8 from the first row, then 3 from the second row */
/* keys are 1-9, 0, reset */
return num;
}
-/* returns a key 0..9 or 11 for reset */
+/* returns a key 1..10 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];
+ key = keymap0[key];
}
- curr_key = keymap1[key];
-
- if (curr_key != last_key) {
- last_key = curr_key;
+ key = keymap1[key];
+
+ if (key != last_key) {
+ last_key = key;
+ if (key != 0) {
+ new_key = 1;
+ chime_start();
+ }
}
}
+
+bool keypad_pressed() {
+ if (!new_key) return 0;
+ new_key = 0;
+ return 1;
+}
#define _KEYPAD_H_
extern u8 last_key;
-extern u8 curr_key;
+
+/* returns true if a key has been pressed since the last call */
+bool keypad_pressed();
+void keypad_read();
#endif /* _KEYPAD_H_ */
#include "display.h"
+#include "keypad.h"
+#include "chime.h"
#include "vend.h"
int main() {
delay(1000);
while(1) {
+ keypad_read();
+ if (keypad_pressed()) {
+ switch (last_key) {
+
+ }
+ }
}
}
main();
}
+void rti() {
+ chime();
+}
.word def ; ffee
;; Misc
- .word def ; fff0 (RTII)
+ .word rti ; fff0 (RTII)
.word def ; fff2 (IRQ)
.word def ; fff4 (XIRQ)
.word def ; fff6 (SWI)
/******** Some meaningful bits ******/
#define PORTA_DISP_RESET 0x80 /* active low */
+#define PORTA_CHIME 0x10 /* chime is on when set */
#define PORTD_KEYPAD_ROW 0x20 /* clear for row 0, set for row 1 */
/* Address 3800 bits */
/******* from main.c *******/
int __attribute__((noreturn)) main (void);
+void __attribute__((interrupt)) rti (void);
#endif /* _VEND_H_ */