summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrédéric Mangano2013-11-01 17:41:17 +0100
committerFrédéric Mangano2013-11-01 17:41:17 +0100
commit44b013bd518ed70599dd428fb62acfde060a1286 (patch)
tree117ce7af2b763dbc6c36b68e61d6df5b9d908025
parentab53c52012a5242e2b4b7cdabeb633dbfdfebad4 (diff)
downloadlastos-44b013bd518ed70599dd428fb62acfde060a1286.tar.gz
lastos-44b013bd518ed70599dd428fb62acfde060a1286.zip
mem interface more convenient for writing
-rw-r--r--kernel.c7
-rw-r--r--shell.c22
2 files changed, 14 insertions, 15 deletions
diff --git a/kernel.c b/kernel.c
index f8ace69..f52ce83 100644
--- a/kernel.c
+++ b/kernel.c
@@ -7,7 +7,10 @@ static void echo(struct irc_message *msg, void *data)
irc_privmsg(msg->prefix->nick, msg->message.privmsg.message);
}
-static uint8_t *mem_cursor;
+static struct {
+ uint8_t *cursor;
+ int offset;
+} mem_state;
static struct irc_peer echo_bot = { IRC_BOT, "echo", "echo", "kernel", { .bot = { echo } } };
extern struct irc_peer shell_bot;
@@ -30,7 +33,7 @@ void kmain()
irc_add_peer(&serial_user);
irc_add_peer(&echo_bot);
irc_add_peer(&shell_bot);
- mem_bot.def.bot.data = &mem_cursor;
+ mem_bot.def.bot.data = &mem_state;
irc_add_peer(&mem_bot);
for (;;) {
line = sgetline();
diff --git a/shell.c b/shell.c
index d796416..560df3a 100644
--- a/shell.c
+++ b/shell.c
@@ -13,8 +13,9 @@ struct irc_peer shell_bot = { IRC_BOT, "taco", "shell", "kernel", { .bot = { she
static void mem(struct irc_message *msg, void *data)
{
- char **position = (char**) data;
- static const page = 32;
+ uint8_t **position = (uint8_t**) data;
+ int *offset = (int*) (data + sizeof(void*));
+ static const int page = 32;
char buffer[4 * page];
char *cmd = msg->message.privmsg.message;
char *dst = msg->prefix->nick;
@@ -25,19 +26,14 @@ static void mem(struct irc_message *msg, void *data)
arg = hextou32(cmd + 1);
switch (*cmd) {
case '@': /* set or display location */
- if (arg)
+ if (arg) {
*position = (uint8_t*) arg;
- else
+ *offset = 0;
+ } else {
irc_privmsg(dst, u32tohex(buffer, (uint32_t) *position));
+ }
break;
- case '*': /* move and dereference */
- if (arg)
- *position = (uint8_t*) arg;
- irc_privmsg(dst, bstohex(buffer, *position, page));
- break;
- case '+': /* move to next page or display nth page */
- if (!arg)
- *position += page;
+ case '*': /* dereference */
irc_privmsg(dst, bstohex(buffer, *position + page * arg, page));
break;
case '&': /* call with an optional parameter */
@@ -45,7 +41,7 @@ static void mem(struct irc_message *msg, void *data)
irc_privmsg(dst, u32tohex(buffer, x));
break;
default: /* write data */
- *position += hextobs(*position, cmd);
+ *offset += hextobs(*position + *offset, cmd);
}
}