Not logged in

Differences From Artifact [c17be70334348f08]:

File retro.c part of check-in [f5840434bc] - Initial checkin. Has fixed point math and RxE editor by charleschilders on 2010-05-31 21:00:50. [annotate] [view]

To Artifact [98aa4733b0a955b6]:

File retro.c part of check-in [720ed8205b] - Updated VM w/support for console dimensions backport from rx.fossil by charleschilders on 2010-08-22 16:20:47. [annotate] [view]


@@ -11,13 +11,15 @@
 #include <string.h>
 #include <netdb.h>
 #include <termios.h>
 #include <sys/socket.h>
+#include <sys/ioctl.h>
 
 /* Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
 #define IMAGE_SIZE   1000000
 #define ADDRESSES       1024
 #define STACK_DEPTH      100
+#define GLOBAL       "/usr/local/share/retro/retroImage"
 
 typedef struct {
   int sp, rsp, ip;
   int data[STACK_DEPTH], address[ADDRESSES], ports[1024];
@@ -50,8 +52,9 @@
   if (c > 0)
     putchar((char)c);
   else
     printf("\033[2J\033[1;1H");
+  /* Erase the previous character if c = backspace */
   if (c == 8) {
     putchar(32);
     putchar(8);
   }
@@ -178,8 +181,17 @@
   if ((fp = fopen(image, "rb")) != NULL) {
     x = fread(&vm->image, sizeof(int), IMAGE_SIZE, fp);
     fclose(fp);
   }
+
+  if (x == -1)
+  {
+    if ((fp = fopen(GLOBAL, "rb")) != NULL) {
+      x = fread(&vm->image, sizeof(int), IMAGE_SIZE, fp);
+      fclose(fp);
+    }
+  }
+
   return x;
 }
 
 int vm_save_image(VM *vm, char *image) {
@@ -295,8 +307,9 @@
       vm->ports[a] = 0;
 }
 
 void vm_process(VM *vm) {
+  struct winsize w;
   int a, b, opcode;
   opcode = vm->image[vm->ip];
 
   switch(opcode) {
@@ -512,11 +525,13 @@
              case -1:  vm->ports[5] = IMAGE_SIZE;
                        break;
              case -2:  vm->ports[5] = 0;
                        break;
-             case -3:  vm->ports[5] = 0;
+             case -3:  ioctl(0, TIOCGWINSZ, &w);
+                       vm->ports[5] = w.ws_col;
                        break;
-             case -4:  vm->ports[5] = 0;
+             case -4:  ioctl(0, TIOCGWINSZ, &w);
+                       vm->ports[5] = w.ws_row;
                        break;
              case -5:  vm->ports[5] = vm->sp;
                        break;
              case -6:  vm->ports[5] = vm->rsp;