[Mit-cadr-cvs] r327 - in trunk/emulator: chaos usim

ggilley at common-lisp.net ggilley at common-lisp.net
Mon Nov 19 06:08:11 UTC 2012


Author: ggilley
Date: Sun Nov 18 22:08:09 2012
New Revision: 327

Log:
get mac working

Modified:
   trunk/emulator/chaos/FILE.c
   trunk/emulator/chaos/chaos.h
   trunk/emulator/chaos/chaosd.c
   trunk/emulator/chaos/client.c
   trunk/emulator/chaos/log.c
   trunk/emulator/chaos/node.c
   trunk/emulator/chaos/server.c
   trunk/emulator/chaos/transport.c
   trunk/emulator/usim/Makefile
   trunk/emulator/usim/chaos.c
   trunk/emulator/usim/disk.c
   trunk/emulator/usim/ether.c
   trunk/emulator/usim/iob.c
   trunk/emulator/usim/kbd_old.c
   trunk/emulator/usim/lmfs.c
   trunk/emulator/usim/main.c
   trunk/emulator/usim/readmcr.c
   trunk/emulator/usim/ucode.c
   trunk/emulator/usim/x11.c

Modified: trunk/emulator/chaos/FILE.c
==============================================================================
--- trunk/emulator/chaos/FILE.c	Sun Nov 18 11:08:41 2012	(r326)
+++ trunk/emulator/chaos/FILE.c	Sun Nov 18 22:08:09 2012	(r327)
@@ -79,7 +79,7 @@
 /* use utimes instead of "outmoded" utime */
 #endif
 
-#ifdef __NetBSD__
+#if defined(__NetBSD__) || defined(OSX)
 #include <utime.h>
 #include <sys/statvfs.h>
 #endif
@@ -1341,7 +1341,7 @@
 		    strcmp(ofhname, ifh->f_name) == 0) {
 			errstring = "File handle already exists";
 			error(t, "", BUG);
-			return;
+			return 1;
 		}
 	/*
 	 * The output file handle name is the contact name the user end
@@ -1357,7 +1357,7 @@
 			(void)close(fd);
 		errstring = "Data connection could not be established";
 		error(t, "", NET);
-		return;
+		return 1;
 	}
 	if ((ifh = salloc(file_handle)) == FNULL ||
 	    (ofh = salloc(file_handle)) == FNULL)
@@ -1377,6 +1377,7 @@
 	ofh->f_next = file_handles;
 	file_handles = ofh;
 	respond(t, NOSTR);
+	return 0;
 }
 
 /*
@@ -2042,11 +2043,12 @@
 				afree(a);
 				t->t_args = ANULL;
 				xcommand(t);
-				return;
+				return 0;
 			}
 			xflush(x);
 		}
 	error(t, t->t_fh->f_name, errcode);
+	return 1;
 }
 
 /*
@@ -2072,7 +2074,7 @@
 	x->x_left = x->x_bptr - x->x_bbuf;
 	x->x_bptr = x->x_bbuf;
 	x->x_state = X_PROCESS;
-	return;
+	return 0;
 }
 propread(x)
 register struct xfer *x;
@@ -2133,11 +2135,12 @@
 			afree(t->t_args);
 			t->t_args = ANULL;
 			xcommand(t);
-			return;
+			return 0;
 		}
 		xflush(x);
 	}
 	error(t, t->t_fh->f_name, errcode);
+	return 1;
 }
 /*
  * Start up a directory transfer by first doing the glob and responding to the
@@ -2238,7 +2241,7 @@
 		x->x_left = x->x_bptr - x->x_bbuf;
 		x->x_bptr = x->x_bbuf;
 		x->x_state = X_PROCESS;
-		return;
+		return 0;
 	}
 derror:
 	error(t, t->t_fh->f_name, errcode);
@@ -2246,6 +2249,7 @@
 #ifndef SELECT
 	(void)write(ctlpipe[1], (char *)&ax, sizeof(x));
 #endif
+	return 1;
 }
 /*
  * Assemble a directory entry record in the buffer for this transfer.
@@ -2465,7 +2469,7 @@
 #endif 
         if (x->x_options & (O_DIRECTORY|O_PROPERTIES)) {
 		respond(t, NOSTR);
-		return;
+		return 0;
 	}
 	/*
 	 * If writing a file, rename the temp file.
@@ -2767,8 +2771,8 @@
 				(void)close(2);
 				(void)open("/dev/null", 2);
 				(void)dup(0); (void)dup(0);
-				execl("/bin/rmdir", "rmdir", real, 0);
-				execl("/usr/bin/rmdir", "rmdir", real, 0);
+				execl("/bin/rmdir", "rmdir", real, (char *)0);
+				execl("/usr/bin/rmdir", "rmdir", real, (char *)0);
 				exit(1);
 			} else if (pid == -1) {
 				errstring = "Can't fork subprocess for rmdir";
@@ -3002,7 +3006,7 @@
 
 	if ((t->t_args->a_options & ~(O_NEWOK|O_OLD|O_DELETED|O_READ|O_WRITE))) {
 		error(t, "", UUO);
-		return;
+		return 1;
 	}
 	d.dummy[sizeof(struct direct)] = '\0';
 	dfile = t->t_args->a_strings[0];
@@ -3265,6 +3269,7 @@
 	if (dreal) free(dreal);
 	if (idir) free(idir);
 	if (ddir) free(ddir);	
+	return 0;
 }
 incommon(old, new)
 register char *old, *new;
@@ -3335,8 +3340,8 @@
 				(void)close(2);
 				(void)open("/dev/null", 2);
 				(void)dup(0); (void)dup(0);
-				execl("/bin/mkdir", "mkdir", dir, 0);
-				execl("/usr/bin/mkdir", "mkdir", dir, 0);
+				execl("/bin/mkdir", "mkdir", dir, (char *)0);
+				execl("/usr/bin/mkdir", "mkdir", dir, (char *)0);
 				exit(1);
 			}
 			while ((rp = wait(&st)) >= 0)
@@ -3451,7 +3456,7 @@
 						     plp->p_value, x)) {
 							error(t,
 							      fhname, errcode);
-							return;
+							return 0;
 						} else
 							break;
 					else {
@@ -3460,7 +3465,7 @@
 						"No a changeable property: %s",
 							plp->p_name);
 						error(t, fhname, CSP);
-						return;
+						return 0;
 					}
 			if (pp->p_indicator == NOSTR) {
 				(void)sprintf(errbuf,
@@ -3468,11 +3473,12 @@
 					plp->p_name);
 				errstring = errbuf;
 				error(t, fhname, UKP);
-				return;
+				return 0;
 			}
 		}
 		respond(t, NOSTR);
 	}
+	return 0;
 }
 

 /*
@@ -3768,11 +3774,19 @@
 		return IPV;
 	}
 	if (mtime != s->st_mtime) {
+#if defined(OSX)
+		struct utimbuf timep;
+
+		timep.actime = s->st_atime;
+		timep.modtime = mtime;
+		if (utime(file, &timep) < 0) {
+#else
 		time_t timep[2];
 
 		timep[0] = s->st_atime;
 		timep[1] = mtime;
 		if (utime(file, timep) < 0) {
+#endif
 			errstring =
 				"No permission to change modification time";
 			return ATF;
@@ -3811,11 +3825,19 @@
 		return IPV;
 	}
 	if (atime != s->st_atime) {
+#if defined(OSX)
+		struct utimbuf timep;
+
+		timep.modtime = s->st_mtime;
+		timep.actime = atime;
+		if (utime(file, &timep) < 0) {
+#else
 		time_t timep[2];
 
 		timep[1] = s->st_mtime;
 		timep[0] = atime;
 		if (utime(file, timep) < 0) {
+#endif
 			errstring = "No permission to change reference date";
 			return ATF;
 		} else if (x) {
@@ -4552,39 +4574,65 @@
 /*
  * Write an eof packet on a transfer.
  */
-xpweof(x)
-register struct xfer *x;
+int
+xpweof(register struct xfer *x)
 {
-	char op = EOFOP;
+        char op = EOFOP;
 
-	if (write(x->x_fh->f_fd, &op, 1) != 1)
-		return -1;
-	if (log_verbose) {
-		log(LOG_INFO, "FILE: wrote EOF to net\n");
+        if (write(x->x_fh->f_fd, &op, 1) != 1)
+	{
+        	log(LOG_ERR, "FILE: xpweof write failed (errno %d)\n", errno);
+                int tries = 0;
+                do {
+                        usleep(100);
+                        if (write(x->x_fh->f_fd, &op, 1) == 1) {
+                                log(LOG_ERR, "FILE: xpweof retry succeeded\n");
+                                return 0;
+                        }
+                } while (tries++ < 200000);
+                log(LOG_ERR, "FILE: exhausted retries, xpweof (errno %d)\n", errno);
+                return -1;
 	}
-	return 0;
+        if (log_verbose) {
+                log(LOG_INFO, "FILE: wrote EOF to net\n");
+        }
+        return 0;
 }
 
 /*
  * Write a transfer's packet.
  */
-xpwrite(x)
-register struct xfer *x;
+int
+xpwrite(register struct xfer *x)
 {
-	register int len;
+        register int len;
+        int ret;
 
-	len = x->x_pptr - x->x_pbuf;
-	if (len == 0)
-		return 0;
-	x->x_op = x->x_options & O_BINARY ? DWDOP : DATOP;
-	len++;
-	if (log_verbose) {
-		log(LOG_INFO, "FILE: writing (%d) %d bytes to net\n",
-		    x->x_op & 0377, len);
-	}
-	if (write(x->x_fh->f_fd, (char *)&x->x_pkt, len) != len)
-		return -1;
-	return 0;
+        len = x->x_pptr - x->x_pbuf;
+        if (len == 0)
+                return 0;
+        x->x_op = x->x_options & O_BINARY ? DWDOP : DATOP;
+        len++;
+        if (log_verbose) {
+                log(LOG_INFO, "FILE: writing (%d) %d bytes to net\n",
+                    x->x_op & 0377, len);
+                if (1) dumpbuffer((u_char *)&x->x_pkt, len);
+        }
+        if ((ret = write(x->x_fh->f_fd, (char *)&x->x_pkt, len)) != len) {
+                log(LOG_ERR, "FILE: write error %d (errno %d) to file %d\n",
+                        ret, errno, x->x_fh->f_fd);
+                int tries = 0;
+                do {
+                        usleep(100);
+                        if ((ret = write(x->x_fh->f_fd, (char *)&x->x_pkt, len)) == len) {
+                                log(LOG_ERR, "FILE: write error retry succeeded\n");
+                                return 0;
+                        }
+                } while (tries++ < 200000);
+                log(LOG_ERR, "FILE: exhausted retries, write error %d (errno %d) to file %d\n",ret, errno);
+                return -1;
+        }
+        return 0;
 }
 
 /*
@@ -4688,7 +4736,7 @@
 		setjmp(closejmp);
 		for (;;) {
 			while ((x->x_flags & X_CLOSE) == 0) {
-				off_t nread;
+				off_t nread = 0;
 
 				(void)signal(SIGHUP, interrupt);
 				if (ioctl(x->x_pfd, FIONREAD, (char *)&nread) < 0)
@@ -4889,7 +4937,7 @@
  */
 void interrupt(int arg)
 {
-	off_t nread;
+	off_t nread = 0;
 
 #if !defined(BSD42) && !defined(linux) && !defined(OSX)
 	(void)signal(SIGHUP, interrupt);

Modified: trunk/emulator/chaos/chaos.h
==============================================================================
--- trunk/emulator/chaos/chaos.h	Sun Nov 18 11:08:41 2012	(r326)
+++ trunk/emulator/chaos/chaos.h	Sun Nov 18 22:08:09 2012	(r327)
@@ -126,10 +126,10 @@
   unsigned char msb;
 } chpklenfc;
 
-#define LENFC_LEN(lenfc) ((lenfc).lsb | (((lenfc).msb & 0x0f) << 8))
+#define LENFC_LEN(lenfc) ((lenfc).lsb | ((int)((lenfc).msb & 0x0f) << 8))
 #define LENFC_FC(lenfc) (((lenfc).msb & 0xf0) >> 4)
 #define SET_LENFC_LEN(lenfc,len) do {  (lenfc).lsb = (len) & 0xff; \
-(lenfc).msb = ((lenfc).msb & 0xf0) & (((len) & 0x0f00) >> 8); } while(0)
+(lenfc).msb = ((lenfc).msb & 0xf0) | (((len) & 0x0f00) >> 8); } while(0)
 #define SET_LENFC_FC(lenfc,fc) (lenfc).msb = (((lenfc).msb & 0x0f) | ((fc & 0xf) << 4))
 
 #define PH_LEN(ph) (LENFC_LEN(ph.ph_lenfc))

Modified: trunk/emulator/chaos/chaosd.c
==============================================================================
--- trunk/emulator/chaos/chaosd.c	Sun Nov 18 11:08:41 2012	(r326)
+++ trunk/emulator/chaos/chaosd.c	Sun Nov 18 22:08:09 2012	(r327)
@@ -284,9 +284,14 @@
     /* repoen stdin, stdout, stderr as bit buckets */
     open("/dev/null", O_RDONLY);
     open("/dev/null", O_WRONLY);
-    open("/dev/null", O_WRONLY);
+    if (flag_debug_level == 0)
+	open("/dev/null", O_WRONLY);
+    else {
+	unlink("server.log");
+	open("server.log", O_WRONLY | O_CREAT);
+    }
 
-    execl("./server", "server", 0);
+    execl("./server", "server", (char *)0);
 
     fprintf(stderr,"exec of ./server failed\n");
     

Modified: trunk/emulator/chaos/client.c
==============================================================================
--- trunk/emulator/chaos/client.c	Sun Nov 18 11:08:41 2012	(r326)
+++ trunk/emulator/chaos/client.c	Sun Nov 18 22:08:09 2012	(r327)
@@ -48,7 +48,11 @@
 
     unix_addr.sun_family = AF_UNIX;
 //    len = strlen(unix_addr.sun_path) + sizeof(unix_addr.sun_family);
+#if defined(OSX)
+    len = (int)SUN_LEN(&unix_addr);
+#else
     len = strlen(unix_addr.sun_path) + sizeof unix_addr - sizeof unix_addr.sun_path;
+#endif
 
     unlink(unix_addr.sun_path);
 
@@ -68,7 +72,11 @@
     sprintf(unix_addr.sun_path, "%s%s",
 	    UNIX_SOCKET_PATH, UNIX_SOCKET_SERVER_NAME);
     unix_addr.sun_family = AF_UNIX;
+#if defined(OSX)
+    len = (int)SUN_LEN(&unix_addr);
+#else
     len = strlen(unix_addr.sun_path) + sizeof(unix_addr.sun_family);
+#endif
 
     if (connect(fd, (struct sockaddr *)&unix_addr, len) < 0) {
       perror("connect(AF_UNIX)");

Modified: trunk/emulator/chaos/log.c
==============================================================================
--- trunk/emulator/chaos/log.c	Sun Nov 18 11:08:41 2012	(r326)
+++ trunk/emulator/chaos/log.c	Sun Nov 18 22:08:09 2012	(r327)
@@ -51,7 +51,7 @@
     va_end(ap);
 
     if (flag_daemon) {
-        syslog(level, string);
+        syslog(level, "%s", string);
     } else {
         printf("log: %s\n", string);
     }
@@ -69,7 +69,7 @@
 void
 debugf(int level, char *fmt, ...)
 {
-    char string[512], intro[64], *tail, *head;
+    char string[512], intro[64], *tail, *head = "";
     va_list ap;
     int len;
     int perror_no = 0;
@@ -111,9 +111,9 @@
     }
 
     if (!flag_daemon) {
-        printf("%s %s%s%s", intro, head, string, tail);
+        fprintf(stderr, "%s %s%s%s", intro, head, string, tail);
         if (perror_no) {
-            printf("%s errno %d: %s\n", intro, perror_no, perror);
+            fprintf(stderr, "%s errno %d: %s\n", intro, perror_no, perror);
         }
     }
 
@@ -131,7 +131,7 @@
 void
 tracef(int level, char *fmt, ...)
 {
-    char string[512], intro[64], *tail, *head;
+    char string[512], intro[64], *tail, *head = "";
     va_list ap;
     int len;
     int perror_no = 0;

Modified: trunk/emulator/chaos/node.c
==============================================================================
--- trunk/emulator/chaos/node.c	Sun Nov 18 11:08:41 2012	(r326)
+++ trunk/emulator/chaos/node.c	Sun Nov 18 22:08:09 2012	(r327)
@@ -84,6 +84,7 @@
         }
     }
 #endif
+    return 0;
 }
 
 /*
@@ -210,11 +211,13 @@
 int
 node_init(void)
 {
+    return 0;
 }
 
 int
 node_poll(void)
 {
+    return 0;
 }
 
 


Modified: trunk/emulator/chaos/server.c
==============================================================================
--- trunk/emulator/chaos/server.c	Sun Nov 18 11:08:41 2012	(r326)
+++ trunk/emulator/chaos/server.c	Sun Nov 18 22:08:09 2012	(r327)
@@ -72,7 +72,7 @@
         } else {
             if (skipping) {
                 skipping = 0;
-                printf("...\n");
+                fprintf(stderr, "...\n");
             }
         }
 
@@ -92,7 +92,7 @@
             }
             cbuf[16] = 0;
 
-            printf("%08x %s %s\n", offset, line, cbuf);
+            fprintf(stderr, "%08x %s %s\n", offset, line, cbuf);
         }
 
         buf += 16;
@@ -102,7 +102,7 @@
 
     if (skipping) {
         skipping = 0;
-        printf("%08x ...\n", offset-16);
+        fprintf(stderr, "%08x ...\n", offset-16);
     }
 }
 
@@ -378,7 +378,7 @@
 
     /* exec the application */
 //xxx - hack - arg should come from parsing packet
-    r = execl(app_name, app_name, "1", 0);
+    r = execl(app_name, app_name, "1", (char *)0);
 
     if (r) {
         log(LOG_WARNING, "can't exec %s; %%m", app_name);
@@ -620,7 +620,7 @@
         break;
 
     case 3: /* setmode */
-        ret= ch_setmode(child_conn[conn_num].conn);
+        ret= ch_setmode(child_conn[conn_num].conn, mode);
 
         ctlbuf[0] = 3;
         ctlbuf[1] = ret;

Modified: trunk/emulator/chaos/transport.c
==============================================================================
--- trunk/emulator/chaos/transport.c	Sun Nov 18 11:08:41 2012	(r326)
+++ trunk/emulator/chaos/transport.c	Sun Nov 18 22:08:09 2012	(r327)
@@ -204,7 +204,7 @@
 static int
 fd_read(int index)
 {
-    int ret;
+    int ret = 0;
     
     debugf(DBG_LOW, "fd_read(index=%d)\n", index);
 

Modified: trunk/emulator/usim/Makefile
==============================================================================
--- trunk/emulator/usim/Makefile	Sun Nov 18 11:08:41 2012	(r326)
+++ trunk/emulator/usim/Makefile	Sun Nov 18 22:08:09 2012	(r327)
@@ -28,6 +28,11 @@
 #KEYBOARD = OLD
 KEYBOARD = NEW
 
+ifeq ($(OS_NAME), Darwin)
+DISPLAY = X11
+KEYBOARD = OLD
+endif
+
 #----------- code ------------
 
 USIM_SRC = main.c decode.c ucode.c disk.c iob.c chaos.c ether.c uart.c syms.c config.c
@@ -55,15 +60,15 @@
 
 # Mac OSX
 ifeq ($(OS), OSX)
-LFLAGS = -framework Cocoa
+LFLAGS = -m32 -framework Cocoa
 USIM_LIBS = -lSDLmain -lSDL -lpthread -lobjc
-CFLAGS = -O $(DEFINES)
+CFLAGS = -O -m32 -I/usr/X11/include -DDISPLAY_X11 $(DEFINES)
 # good for G5
 #CFLAGS = -fast $(DEFINES)
 endif
 
 ifeq ($(DISPLAY), X11)
-LFLAGS =
+LFLAGS = -m32
 USIM_LIBS = -L/usr/X11R6/lib -lX11
 endif
 
@@ -87,9 +92,13 @@
 # override above if 64 bit
 ifeq ($(MACH_NAME), x86_64)
 M32 = -m32
+
+ifeq ($(DISPLAY), SDL)
 USIM_LIBS = /usr/lib/libSDL-1.2.so.0.7.0 -lpthread
 endif
 
+endif
+
 #DEFINES=-DLASHUP
 DEFINES=-DCADR2
 

Modified: trunk/emulator/usim/chaos.c
==============================================================================
--- trunk/emulator/usim/chaos.c	Sun Nov 18 11:08:41 2012	(r326)
+++ trunk/emulator/usim/chaos.c	Sun Nov 18 22:08:09 2012	(r327)
@@ -551,7 +551,7 @@
 			  int i, c = 0, o = 0;
 			  unsigned char cc, cb[9];
 			  cb[8] = 0;
-			  for (i = 0; i < ret; i++) {
+			  for (i = 0; i < ret; i++, o++) {
 				  if (c == 8) { printf("%s\n", cb); c = 0; }
 				  if (c++ == 0) printf("%04d ", o);
 				  cc = ((unsigned char *)chaos_rcv_buffer)[i];

Modified: trunk/emulator/usim/disk.c
==============================================================================
--- trunk/emulator/usim/disk.c	Sun Nov 18 11:08:41 2012	(r326)
+++ trunk/emulator/usim/disk.c	Sun Nov 18 22:08:09 2012	(r327)
@@ -11,6 +11,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <string.h>
 #include <fcntl.h>
 

Modified: trunk/emulator/usim/ether.c
==============================================================================
--- trunk/emulator/usim/ether.c	Sun Nov 18 11:08:41 2012	(r326)
+++ trunk/emulator/usim/ether.c	Sun Nov 18 22:08:09 2012	(r327)
@@ -25,7 +25,13 @@
 #define uint32_t __uint32_t
 #endif
 
-#if defined(BSD)
+#if defined(OSX)
+#include <sys/socket.h>
+#include <net/if.h>
+#include <net/bpf.h>
+#endif
+
+#if defined(BSD) && !defined(OSX)
 #include <net/if.h>
 #include <net/if_dl.h>
 #include <net/if_tap.h>
@@ -118,7 +124,7 @@
 	miimoder = 0x64;
 	enabled = 0;
 
-#ifdef BSD
+#if defined(BSD) && !defined(OSX)
 	if (geteuid() != 0) {
 		printf("Not root, ethernet disabled\n");
 		return -1;
@@ -180,7 +186,7 @@
 			if (status & ETHER_DESC_TX_PAD)
 			    len = MAX(len, 60);
 
-#ifdef BSD
+#if defined(BSD) && !defined(OSX)
 			ret = write(tap_fd, packet, len);
 			if (ret != len) {
 			    perror("write"); 
@@ -202,7 +208,7 @@
 		for (i = tx_bd_num; i < 0x80; i++) {
 		    status = descs.desc_structs[i].status;
 		    if (status & ETHER_DESC_RX_EMPTY) {
-#ifdef BSD
+#if defined(BSD) && !defined(OSX)
 			len = read(tap_fd, packet, sizeof(packet));
 #else
 			len = -1;

Modified: trunk/emulator/usim/iob.c
==============================================================================
--- trunk/emulator/usim/iob.c	Sun Nov 18 11:08:41 2012	(r326)
+++ trunk/emulator/usim/iob.c	Sun Nov 18 22:08:09 2012	(r327)
@@ -11,6 +11,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <stdint.h>
 #include <signal.h>
 
 #if defined(LINUX) || defined(OSX) || defined(BSD)

Modified: trunk/emulator/usim/kbd_old.c
==============================================================================
--- trunk/emulator/usim/kbd_old.c	Sun Nov 18 11:08:41 2012	(r326)
+++ trunk/emulator/usim/kbd_old.c	Sun Nov 18 22:08:09 2012	(r327)
@@ -7,14 +7,19 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdint.h>
 
 #ifdef _WIN32
 #include "SDL/SDL.h"
 #else
+#if !defined(DISPLAY_X11)
 #include <SDL/SDL.h>
 #endif
+#endif
 
+#include "usim.h"
 #include "keyboard.h"
+#include "ucode.h"
 
 #ifdef DISPLAY_X11
 #include <X11/Xlib.h>
@@ -41,6 +46,12 @@
 #define SDLK_BACKSPACE	XK_BackSpace
 #define SDLK_BREAK	XK_Break
 #define SDLK_RETURN	XK_Return
+#define SDLK_DOWN	XK_Down
+#define SDLK_LEFT	XK_Left
+#define SDLK_RIGHT	XK_Right
+#define SDLK_UP		XK_Up
+#define SDLK_TAB	XK_Tab
+#define SDLK_ESC	XK_Escape
 #endif /* DISPLAY_X11 */
 
 extern unsigned int iob_key_scan;
@@ -134,7 +145,7 @@
 void
 iob_sdl_key_event(int code, int extra)
 {
-	int s, c;
+    int newkbd = 0; // keys found on the "new" keyboard
 
 	if (0) printf("iob_sdl_key_event(code=%x,extra=%x)\n", code, extra);
 
@@ -182,12 +193,39 @@
 		iob_key_scan = 0; /* break */
 		break;
 	case SDLK_BACKSPACE:
-		iob_key_scan = 15; /* backspace */
+		iob_key_scan = 046; /* rubout */
 		break;
 	case SDLK_RETURN:
 		iob_key_scan = 50; /* CR */
 		break;
+	case SDLK_DOWN:
+        iob_key_scan = 0176;
+        newkbd = 1;
+		break;
+	case SDLK_LEFT:
+        iob_key_scan = 0117;
+        newkbd = 1;
+		break;
+	case SDLK_RIGHT:
+        iob_key_scan = 017;
+        newkbd = 1;
+        break;
+	case SDLK_UP:
+        iob_key_scan = 0106;
+        newkbd = 1;
+        break;
+	case SDLK_TAB:
+		iob_key_scan = 18;
+		break;
+	case SDLK_ESC:
+		iob_key_scan = 1;
+		break;
 	default:
+		if (code > 255)
+		{
+			printf("unknown keycode: %d\n", code);
+			return;
+		}
 		iob_key_scan =
 			kb_sdl_to_scancode[code][(extra & (3 << 6)) ? 1 : 0];
 		break;
@@ -197,12 +235,18 @@
 	iob_key_scan |= extra & ~(3 << 6);
 	/* but if Control/Meta, add in Shift */
 	if (extra & (17 << 10))
+	{
+	  if (0) printf("extra: %x  17<<10: %x", extra, 17 << 10);
 	  iob_key_scan |= extra;
+	}
 
 	if (0) printf("code 0%o, extra 0%o, scan 0%o\n",
 		      code, extra, iob_key_scan);
 
-	iob_key_scan |= 0xffff0000;
+    if (newkbd)
+        iob_key_scan |= 1 << 16;
+    else
+        iob_key_scan |= 0xffff0000;
 
 	iob_kbd_csr |= 1 << 5;
 	assert_unibus_interrupt(0260);
@@ -251,23 +295,23 @@
 #endif /* DISPLAY_SDL */
 
 void
-iob_warm_boot_key()
+iob_warm_boot_key(void)
 {
 	iob_sdl_key_event(SDLK_RETURN, 0);
 }
 
-void
-iob_dequeue_key_event(void)
+
+void iob_dequeue_key_event(void)
 {
 }
 
-void
-sdl_queue_all_keys_up(void)
+
+void sdl_queue_all_keys_up(void)
 {
 }
 
 void
-kbd_init()
+kbd_init(void)
 {
 	int i;
 
@@ -299,15 +343,70 @@
 	kb_sdl_to_scancode['='][1] = 060 | (3<<6);   /* Sh-= = Sh-; = + */
 
 	kb_sdl_to_scancode[';'][1] = 061;	     /* Sh-; = : (unshifted) */
+	kb_sdl_to_scancode[':'][1] = 061;
+
+	kb_sdl_to_scancode['!'][1] = 2 | (3<<6);
+	kb_sdl_to_scancode['"'][1] = 3 | (3<<6);
+	kb_sdl_to_scancode['#'][1] = 4 | (3<<6);
+	kb_sdl_to_scancode['$'][1] = 5 | (3<<6);
+	kb_sdl_to_scancode['%'][1] = 6 | (3<<6);
+	kb_sdl_to_scancode['&'][1] = 7 | (3<<6);
+	kb_sdl_to_scancode['('][1] = 011 | (3<<6);
+	kb_sdl_to_scancode[')'][1] = 012 | (3<<6);
+	kb_sdl_to_scancode['_'][1] = 013 | (3<<6);
+	kb_sdl_to_scancode['~'][1] = 016 | (3<<6);
+	kb_sdl_to_scancode['@'][1] = 13;
+	kb_sdl_to_scancode['^'][1] = 14;
+
+	kb_sdl_to_scancode['Q'][1] = 20 | (3<<6);
+	kb_sdl_to_scancode['W'][1] = 21 | (3<<6);
+	kb_sdl_to_scancode['E'][1] = 22 | (3<<6);
+	kb_sdl_to_scancode['R'][1] = 23 | (3<<6);
+	kb_sdl_to_scancode['T'][1] = 24 | (3<<6);
+	kb_sdl_to_scancode['Y'][1] = 25 | (3<<6);
+	kb_sdl_to_scancode['U'][1] = 26 | (3<<6);
+	kb_sdl_to_scancode['I'][1] = 27 | (3<<6);
+	kb_sdl_to_scancode['O'][1] = 28 | (3<<6);
+	kb_sdl_to_scancode['P'][1] = 29 | (3<<6);
+	kb_sdl_to_scancode['{'][1] = 30 | (3<<6);
+	kb_sdl_to_scancode['}'][1] = 31 | (3<<6);
+	kb_sdl_to_scancode['|'][1] = 32 | (3<<6);
+
+	kb_sdl_to_scancode['A'][1] = 39 | (3<<6);
+	kb_sdl_to_scancode['S'][1] = 40 | (3<<6);
+	kb_sdl_to_scancode['D'][1] = 41 | (3<<6);
+	kb_sdl_to_scancode['F'][1] = 42 | (3<<6);
+	kb_sdl_to_scancode['G'][1] = 43 | (3<<6);
+	kb_sdl_to_scancode['H'][1] = 44 | (3<<6);
+	kb_sdl_to_scancode['J'][1] = 45 | (3<<6);
+	kb_sdl_to_scancode['K'][1] = 46 | (3<<6);
+	kb_sdl_to_scancode['L'][1] = 47 | (3<<6);
+	kb_sdl_to_scancode['+'][1] = 48 | (3<<6);
+	kb_sdl_to_scancode['*'][1] = 061 | (3<<6);
+
+	kb_sdl_to_scancode['Z'][1] = 53 | (3<<6);
+	kb_sdl_to_scancode['X'][1] = 54 | (3<<6);
+	kb_sdl_to_scancode['C'][1] = 55 | (3<<6);
+	kb_sdl_to_scancode['V'][1] = 56 | (3<<6);
+	kb_sdl_to_scancode['B'][1] = 57 | (3<<6);
+	kb_sdl_to_scancode['N'][1] = 58 | (3<<6);
+	kb_sdl_to_scancode['M'][1] = 59 | (3<<6);
+	kb_sdl_to_scancode['<'][1] = 60 | (3<<6);
+	kb_sdl_to_scancode['>'][1] = 61 | (3<<6);
+	kb_sdl_to_scancode['?'][1] = 62 | (3<<6);
 
 	/* map "Delete" to rubout */
 	kb_sdl_to_scancode[0x7f][0] = 046;	     /* Delete = Rubout */
+	kb_sdl_to_scancode[0x08][0] = 046;	     /* Delete = Rubout */
 
 	/* map tab to tab */
-	kb_sdl_to_scancode[9][0] = 022;		     /* Tab = Tab */
+	kb_sdl_to_scancode[9][0] = 0211;	     /* Tab = Tab */
 
 	/* esc = esc */
-	kb_sdl_to_scancode[0x1b][0] = 1;	     /* Esc = Esc (Terminal) */
+	kb_sdl_to_scancode[0x1b][0] = 0204;	     /* Esc = Esc (Terminal) */
+    
+    /* map arrows */
+//    kb_sdl_to_scancode[0x2b][2] = LM_K_HAND_DOWN;
 
 	/* Add shifts */
 	for (i = 0; i < 256; i++) {
@@ -316,6 +415,8 @@
 				(3 << 6);
 	}
 
+	if (0) printf("kb_sdl_to_scancode[';'][1] = %x\n", kb_sdl_to_scancode[';'][1]);
+
 #if 0   /* Don't do this */
 	/* control keys */
 	for (i = 0; i < 64; i++) {

Modified: trunk/emulator/usim/lmfs.c
==============================================================================
--- trunk/emulator/usim/lmfs.c	Sun Nov 18 11:08:41 2012	(r326)
+++ trunk/emulator/usim/lmfs.c	Sun Nov 18 22:08:09 2012	(r327)
@@ -612,7 +612,7 @@
 lmfs_open(char *img_filename, int offset)
 {
   int fd, ret;
-  u_char buffer[256*4];
+  unsigned char buffer[256*4];
   struct partition_label_s *pl;
   baccess b;
 

Modified: trunk/emulator/usim/main.c
==============================================================================
--- trunk/emulator/usim/main.c	Sun Nov 18 11:08:41 2012	(r326)
+++ trunk/emulator/usim/main.c	Sun Nov 18 22:08:09 2012	(r327)
@@ -11,6 +11,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <signal.h>
 
 #if defined(LINUX) || defined(OSX) || defined(BSD)

Modified: trunk/emulator/usim/readmcr.c
==============================================================================
--- trunk/emulator/usim/readmcr.c	Sun Nov 18 11:08:41 2012	(r326)
+++ trunk/emulator/usim/readmcr.c	Sun Nov 18 22:08:09 2012	(r327)
@@ -11,6 +11,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <fcntl.h>
 #include <unistd.h>
 

Modified: trunk/emulator/usim/ucode.c
==============================================================================
--- trunk/emulator/usim/ucode.c	Sun Nov 18 11:08:41 2012	(r326)
+++ trunk/emulator/usim/ucode.c	Sun Nov 18 22:08:09 2012	(r327)
@@ -15,6 +15,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <string.h>
 #include <ctype.h>
 #include <fcntl.h>
@@ -814,7 +815,7 @@
 	a_memory[loc] = v;
 }
 
-inline unsigned int
+unsigned int
 read_a_mem(int loc)
 {
 	return a_memory[loc];
@@ -926,7 +927,7 @@
  * advance the LC register,
  * following the rules; will read next vma if needed
  */
-inline void
+void
 advance_lc(int *ppc)
 {
 	/* lc is 26 bits */
@@ -1657,7 +1658,7 @@
 restore_state(void)
 {
 	int fd, ret, i;
-	u_char version[2];
+	unsigned char version[2];
 
 	if (restored)
 	  return 0;
@@ -1692,7 +1693,7 @@
 save_state(void)
 {
 	int fd, ret, i;
-	u_char version[2];
+	unsigned char version[2];
 
 	fd = open("usim.state", O_RDWR | O_CREAT, 0666);
 	if (fd < 0)

Modified: trunk/emulator/usim/x11.c
==============================================================================
--- trunk/emulator/usim/x11.c	Sun Nov 18 11:08:41 2012	(r326)
+++ trunk/emulator/usim/x11.c	Sun Nov 18 22:08:09 2012	(r327)
@@ -13,6 +13,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <signal.h>
 
 #include "logo.h"
@@ -86,7 +87,7 @@
 	if (updown) {
 		ret = XLookupString(&e->xkey, (char *) buffer, 5, &keysym,
 				    &status);
-#if 1
+#if 0
 		printf("keysym %d, scancode %x, sym %s, state %x\n",
 		       keysym, e->xkey.keycode, buffer, e->xkey.state);
 #endif




More information about the mit-cadr-cvs mailing list