summaryrefslogtreecommitdiff
path: root/stm32
diff options
context:
space:
mode:
authorLeo C2014-06-26 16:14:25 +0200
committerLeo C2014-06-26 16:14:25 +0200
commitd9c2b1b6505e365d55703b051596c90558fd1169 (patch)
tree41c9dc97bcaeec8cbbb73511efc8cd23bada372f /stm32
parenta16ba2b0d47ac18eebbc1f9074a8b668fc312de2 (diff)
downloadz180-stamp-d9c2b1b6505e365d55703b051596c90558fd1169.zip
Table for Z180 messages
Diffstat (limited to 'stm32')
-rw-r--r--stm32/z180-stamp-stm32.c147
1 files changed, 89 insertions, 58 deletions
diff --git a/stm32/z180-stamp-stm32.c b/stm32/z180-stamp-stm32.c
index f55e076..1d5df34 100644
--- a/stm32/z180-stamp-stm32.c
+++ b/stm32/z180-stamp-stm32.c
@@ -18,7 +18,7 @@
#include "debug.h"
#include "serial.h"
#include "z80-if.h"
-#include "hdrom.h"
+#include "../Z180/hdrom.h"
#define ESCCHAR ('^'-0x40)
@@ -503,79 +503,110 @@ static void do_10ms(void)
}
}
-static
-void do_msg_init(int len, uint8_t* msg)
+struct msg_item {
+ uint8_t fct;
+ uint8_t sub_min, sub_max;
+ void (*func)(uint8_t, int, uint8_t *);
+};
+
+uint32_t msg_to_addr(uint8_t *msg)
{
- uint8_t sub_fct;
-
- if (len > 0) {
- len--;
- switch (sub_fct = *msg++) {
- case 0:
- case 1:
- case 2:
- if (len == 3) {
- uint32_t fifoadr = 0;
- while (len--)
- fifoadr = (fifoadr << 8) + msg[len];
- if (sub_fct == 0)
- z80_init_msg_fifo(fifoadr);
- else
- z80_memfifo_init(sub_fct - 1, fifoadr);
- } else {
- /* garbage from z180 */
- }
- break;
- default:
- /* garbage from z180 */
- break;
- }
- }
+ uint32_t addr = msg[0] + (msg[1] << 8) + (msg[2] << 16);
+
+ return addr;
+
}
-static
-void do_msg_char(int len, uint8_t* msg)
+void do_msg_ini_msgfifo(uint8_t subf, int len, uint8_t * msg)
{
- uint8_t sub_fct;
-
- if (len > 0) {
- len--;
- switch (sub_fct = *msg++) {
- case 1: /* console output */
- while (len--)
- putchar(*msg++);
- break;
- }
- }
+ (void)subf; (void)len;
+
+ z80_init_msg_fifo(msg_to_addr(msg));
+}
+
+
+void do_msg_ini_memfifo(uint8_t subf, int len, uint8_t * msg)
+{
+ (void)len;
+
+ z80_memfifo_init(subf - 1, msg_to_addr(msg));
}
-static
+
+void do_msg_char_out(uint8_t subf, int len, uint8_t * msg)
+{
+ (void)subf;
+
+ while (len--)
+ putchar(*msg++);
+}
+
+
+const struct msg_item z80_messages[] =
+{
+ { 0,
+ 0, 0,
+ &do_msg_ini_msgfifo},
+ { 0,
+ 1, 2,
+ &do_msg_ini_memfifo},
+ { 1,
+ 1, 1,
+ &do_msg_char_out},
+ { 0xff, /* end mark */
+ 0, 0,
+ 0},
+
+};
+
+
+
+
void do_message(int len, uint8_t *msg)
{
- uint8_t sub_fct;
+ uint8_t fct, sub_fct;
+ int i = 0;
- if (len > 0) {
- len--;
- switch (*msg++) {
- case 0: /* init functions */
- do_msg_init(len, msg);
- break;
- case 1: /* character i/o functions */
- do_msg_char(len, msg);
- break;
- default:
- /* no more functions definded yet*/
- break;
+ if (len >= 2) {
+ fct = *msg++;
+ sub_fct = *msg++;
+ len -= 2;
+
+ while (fct != z80_messages[i].fct)
+ ++i;
+
+ if (z80_messages[i].fct == 0xff) {
+ DBG_P(1, "do_message: Unknown function: %i, %i\n",
+ fct, sub_fct);
+ return; /* TODO: unknown message # */
+ }
+
+ while (fct == z80_messages[i].fct) {
+ if (sub_fct >= z80_messages[i].sub_min && sub_fct <= z80_messages[i].sub_max )
+ break;
+ ++i;
}
+
+ if (z80_messages[i].fct != fct) {
+ DBG_P(1, "do_message: Unknown sub function: %i, %i\n",
+ fct, sub_fct);
+ return; /* TODO: unknown message sub# */
+ }
+
+ (z80_messages[i].func)(sub_fct, len, msg);
+
+
} else {
- /* shoudn't happen */
+ /* TODO: error */
+ DBG_P(1, "do_message: to few arguments (%i); this shouldn't happen!\n", len);
}
}
-#define CTRBUF_LEN 20
-static void check_msg_fifo(void)
+#define CTRBUF_LEN 256
+
+void check_msg_fifo(void)
{
int ch;
static int state;