#include <stdio.h>
#include <unistd.h>
#include <string.h>
+#include <strings.h>
+#include <signal.h>
#include <errno.h>
#include <assert.h>
#include <sysexits.h>
#include "dcpu16.h"
#include "common.h"
+#include "display.h"
/*
* shell-like driver for dcpu16 core
COMMAND_IMPL(run) {
- sig_t osig;
+ struct sigaction act;
(void)arg_count, (void)arg_vector;
running_ = 1;
- /* install our new interrupt signal handler */
- if ( (osig = signal(SIGINT, sigint_handler_)) == SIG_ERR ) {
- fprintf(stderr, "%s():%s\n", "signal", strerror(errno));
+ memset(&act, 0, sizeof act);
+ act.sa_handler = sigint_handler_;
+ act.sa_flags = SA_RESETHAND;
+
+ if (sigaction(SIGINT, &act, NULL)) {
+ fprintf(stderr, "%s():%s\n", "sigaction", strerror(errno));
return -1;
}
}
}
- /* restore the old interrupt signal handler */
- if (signal(SIGINT, osig) == SIG_ERR) {
- fprintf(stderr, "%s():%s\n", "signal", strerror(errno));
- return -1;
- }
-
printf("interrupted...\n");
return 0;
"May be interrupted with SIGINT.\n");
}
+COMMAND_IMPL(display) {
+ (void)arg_count, (void)arg_vector;
+
+ static DPIX *pixbuf = NULL;
+
+ if (pixbuf) {
+ printf("display already enabled..\n");
+ return 0;
+ }
+
+ pixbuf = display_init_pixbuf();
+ if (pixbuf == NULL) {
+ fprintf(stderr, "failed to initialize display buffer\n");
+ return 0;
+ }
+
+ if (dcpu16_acct_add(vm, DCPU16_ACCT_EV_WRITE, display_fn, pixbuf)) {
+ fprintf(stderr, "failed to register display update callback\n");
+ return 0;
+ }
+
+ if (dcpu16_acct_add(vm, DCPU16_ACCT_EV_RESET, display_reset_fn, pixbuf)) {
+ fprintf(stderr, "failed to register display reset callback\n");
+ return 0;
+ }
+
+ /* init display as if reset occurred */
+ display_reset_fn(vm, DCPU16_ACCT_EV_RESET, 0, pixbuf);
+
+ return 0;
+}
+COMMAND_HELP(display) {
+ fprintf(f, "\tdisplay\n");
+ if (summary) return;
+
+ fprintf(f, "Begins updating a PNM of current display contents...\n"
+ "This is not a fully-baked feature...\n");
+}
+
/* gather all these together into a searchable table */
/* help command gets some assistance in declarations */
COMMAND_ENTRY(step, 0, 1),
COMMAND_ENTRY(run, 0, 0),
COMMAND_ENTRY(reset, 0, 0),
+ COMMAND_ENTRY(display, 0, 0),
{ NULL, 0, 0, NULL, NULL }
};