#include "display_basic.h"
#include "vend.h"
-#define DELAY_MAGIC 20 /* FIXME: number of loops for ~ 1 millisecond (< 256) */
void delay(u16 ms) {
- u8 i;
- for (;ms;ms--) {
- for (i=0;i<DELAY_MAGIC; i++)
- asm("nop\nnop\nnop\nnop\nnop\n");
- }
-}
-
-void print_amount(u16 amt) {
- /* take amt and show it on screen with a $ sign */
- char str[10] = {' ', '$', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '};
- u8 pos;
- for (pos = 7; amt; pos--, amt/=10) {
- str[pos] = amt%10 + '0';
- }
- set_msg(str);
+ /* delay routine written in assembly so we know what we're really getting.
+ * each inner loop should take ~1 ms to execute.
+ * 15 cycles * (1/4.9152Mhz) * 327 = 0.997 ms + a little bit on the fringes.
+ *
+ * XXX - how do we know gcc isn't optimising this? it seems to optimise after
+ * parsing C -> asm, but before asm -> machine code.
+ */
+ asm volatile ("pshx\npsha\npshb\n"); /* save registers */
+ asm volatile ("ldx %0\n" :: "m" (ms));
+ asm volatile (
+ "loop:\n"
+ " dex\n" /* 3 */
+ " beq out\n" /* 3 */
+ " ldd #327\n" /* 3 */
+ "inner_loop:\n" /* 15 cycles each */
+ " cpd #0x0000\n" /* 5 */
+ " beq inner_loop_end\n" /* 3 */
+ " subd #0x0001\n" /* 4 */
+ " bra inner_loop\n" /* 3 */
+ "inner_loop_end:\n"
+ " bra loop\n" /* 3 */
+ "out:\n"
+ " pulb\n"
+ " pula\n"
+ " pulx\n");
}
void my_strncpy(char* dst, char* src, u8 max_size) {
/******* from helpers.c *******/
void delay(u16 ms);
-void print_amount(u16 amt);
void my_strncpy(char* dst, char* src, u8 max_size); /* for null-term strings */
void my_memcpy(char* dst, char* src, u8 size);