/* An xshmu screen for my implementation of Chifir. * * It took me 32 minutes to implement Chifir’s CPU, but I didn’t * implement a screen for it at the time, because I didn’t have a * reasonable X-Windows library. Now I do; it’s xshmu. So I * refactored chifir.c slightly and wrote this. It took me 28 more * minutes to get it to where it could run an infinite loop (requiring * fixing bugs in both the one-instruction infinite loop program and * my implementation of the Chifir virtual machine), at which point I * declared success. */ #include #include #include #include #include #include "xshmu.h" #include "chifir.h" xshmu w; void refresh_screen() { /* XXX maybe it should translate keystrokes delivered to the Chifir window instead of the window where you’re running this program */ while (xshmu_get_event(w)) ; xshmu_pic from = { .p = &m[1048576], .w = 512, .stride = 512, .h = 684 }; xshmu_copy(xshmu_framebuffer(w), from); xshmu_flush(w); } int main(int argc, char **argv) { if (argc != 2) { errno = EIO; die("usage: chifir_xshmu input_file"); } int fd = open(argv[1], O_RDONLY); if (fd < 0) die("open"); read_image(fd, m); w = xshmu_open("Chifir", 512, 684, ""); run(0); return 0; // can’t happen }