aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2012-05-09 00:04:17 +0000
committerDimitri Sokolyuk <demon@dim13.org>2012-05-09 00:04:17 +0000
commitd94d595fd7c7817dae2887285a3c3d47fba6a765 (patch)
tree87b0255579990af689ab8199b18a528f186c8f39
parent11129399de73cd03a914ee7ddc2dd641feb83f21 (diff)
devices stub
-rw-r--r--dcpu16.h3
-rw-r--r--emu.c20
-rw-r--r--keyboard.c53
-rw-r--r--lem1802.c59
-rw-r--r--main.c3
5 files changed, 136 insertions, 2 deletions
diff --git a/dcpu16.h b/dcpu16.h
index 9a47624..0194f46 100644
--- a/dcpu16.h
+++ b/dcpu16.h
@@ -63,5 +63,8 @@ int step(struct context *);
void tuiemu(struct context *);
void guiemu(struct context *);
void dumpcode(struct context *);
+void register_lem(struct context *);
+void register_keyb(struct context *);
+void register_clk(struct context *);
#endif
diff --git a/emu.c b/emu.c
index 1f1df17..c1e29e1 100644
--- a/emu.c
+++ b/emu.c
@@ -94,20 +94,36 @@ void
hwn(struct context *c, unsigned short *a)
{
/* TODO */
+ *a = c->ndev;
cycle += 2;
}
void
hwq(struct context *c, unsigned short *a)
{
- /* TODO */
+ struct device *d = &c->dev[*a];
+
+ c->reg[A] = d->id;
+ c->reg[B] = d->id >> 16;
+ c->reg[C] = d->version;
+ c->reg[X] = d->manu;
+ c->reg[Y] = d->manu >> 16;
+
cycle += 4;
}
void
hwi(struct context *c, unsigned short *a)
{
- /* TODO */
+ struct device *d = &c->dev[*a];
+
+ if (d->cb) {
+ d->cb(c);
+ } else {
+ warnx("invalid device %d", *a);
+ errors++;
+ }
+
cycle += 4;
}
diff --git a/keyboard.c b/keyboard.c
new file mode 100644
index 0000000..cd8dde5
--- /dev/null
+++ b/keyboard.c
@@ -0,0 +1,53 @@
+/* $Id$ */
+/*
+ * Copyright (c) 2012 Dimitri Sokolyuk <demon@dim13.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, dATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdio.h>
+#include "dcpu16.h"
+
+enum { KEYB_CLEAR,
+ KEYB_STORE,
+ KEYB_PRESSED,
+ KEYB_INTR,
+};
+
+void
+keyb(struct context *c)
+{
+ switch (c->reg[A]) {
+ case KEYB_CLEAR:
+ break;
+ case KEYB_STORE:
+ break;
+ case KEYB_PRESSED:
+ break;
+ case KEYB_INTR:
+ break;
+ default:
+ break;
+ }
+}
+
+void
+register_keyb(struct context *c)
+{
+ struct device *d = &c->dev[++c->ndev];
+
+ d->id = 0x30cf7406;
+ d->version = 0x1;
+ d->manu = 0;
+ d->cb = keyb;
+}
diff --git a/lem1802.c b/lem1802.c
new file mode 100644
index 0000000..55dd492
--- /dev/null
+++ b/lem1802.c
@@ -0,0 +1,59 @@
+/* $Id$ */
+/*
+ * Copyright (c) 2012 Dimitri Sokolyuk <demon@dim13.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, dATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdio.h>
+#include "dcpu16.h"
+
+enum { MEM_MAP_SCREEN,
+ MEM_MAP_FONT,
+ MEM_MAP_PALETTE,
+ SET_BORDER_COLOR,
+ MEM_DUMP_FONT,
+ MEM_DUMP_PALETTE,
+};
+
+void
+lem(struct context *c)
+{
+ switch (c->reg[A]) {
+ case MEM_MAP_SCREEN:
+ break;
+ case MEM_MAP_FONT:
+ break;
+ case MEM_MAP_PALETTE:
+ break;
+ case SET_BORDER_COLOR:
+ break;
+ case MEM_DUMP_FONT:
+ break;
+ case MEM_DUMP_PALETTE:
+ break;
+ default:
+ break;
+ }
+}
+
+void
+register_lem(struct context *c)
+{
+ struct device *d = &c->dev[++c->ndev];
+
+ d->id = 0x7349f615;
+ d->version = 0x1802;
+ d->manu = 0x1c6c8b36;
+ d->cb = lem;
+}
diff --git a/main.c b/main.c
index af1538b..f54bf45 100644
--- a/main.c
+++ b/main.c
@@ -89,6 +89,9 @@ main(int argc, char **argv)
fclose(fd);
+ register_lem(&c);
+ register_keyb(&c);
+ register_clk(&c);
emu(&c);
return 0;