Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Feb 2003 22:08:46 +0700 (KRAT)
From:      Eugene Grosbein <eugen@grosbein.pp.ru>
To:        FreeBSD-gnats-submit@FreeBSD.org
Cc:        sobomax@FreeBSD.org
Subject:   ports/48426: [PATCH] digger-vgl does not support console switching
Message-ID:  <200302181508.h1IF8kK5000611@grosbein.pp.ru>

next in thread | raw e-mail | index | archive | help

>Number:         48426
>Category:       ports
>Synopsis:       [PATCH] digger-vgl does not support console switching
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Feb 18 07:30:05 PST 2003
>Closed-Date:
>Last-Modified:
>Originator:     Eugene Grosbein
>Release:        FreeBSD 4.7-STABLE i386
>Organization:
N/A
>Environment:
System: FreeBSD grosbein.pp.ru 4.7-STABLE FreeBSD 4.7-STABLE #4: Sun Feb 9 13:34:37 KRAT 2003 eu@grosbein.pp.ru:/usr/local/obj/usr/local/src/sys/DADV i386

>Description:
	It is not possible to tune sound volume while playing digger-vgl
	from console and it's not possible to switch vty's to tune it
	manually. One cannot start digger-vgl, suspend it to do some
	work and go back to the game for the same reason.	

>How-To-Repeat:
	Run digger-vgl and try to use Alt-Fn to switch vty's, you will fail.

>Fix:
	The next patch makes it possible to switch to one of ttyv0,...,ttyv9
	using Alt-F1,...,Alt-F10. Game will pause automatically.
	One can go back to the game, unpause it using Space and contunue.
	I run it over a year and it seems to be very useful.
	I put it into the 'files/' directory.

--- fbsd_kbd.c	Fri Jul  6 17:58:17 2001
+++ fbsd_kbd.c	Fri Jul  6 21:16:51 2001
@@ -1,6 +1,8 @@
 #include <sys/fbio.h>
 #include <sys/kbio.h>
 #include <sys/consio.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
 #include <vgl.h>
 
 #include "def.h"
@@ -20,6 +22,14 @@
 			 'a','s','d','f','g','h','j','k','l',';','\'','z','x',\
 			 'c','v','b','n','m',',','.','/',' '};
 
+#define	F1KEY	(59+128)
+#define	F10KEY	(68+128)
+#define	LALTKEY	(56+128)
+#define	RALTKEY	(93+128)
+#define	altpressed	(states[LALTKEY] || states[RALTKEY])
+
+extern bool started, pausef;
+
 void initkeyb(void)
 {
 	VGLKeyboardInit(VGL_CODEKEYS);
@@ -31,33 +41,80 @@
 	VGLKeyboardEnd();
 }
 
+bool UpdateStates(Sint4* result)
+{
+	Sint4 i;
+	bool isasymbol, state;
+	
+	if(*result < 128)
+		state = TRUE;
+	else {
+		state = FALSE;
+		*result -= 128;
+	}
+
+	isasymbol = FALSE;
+	for(i=0;quertycodes[i]!=0;i++)
+		if(*result == quertycodes[i]) {
+			*result = chars[i];
+			isasymbol = TRUE;
+			break;
+		}
+
+	if (isasymbol == FALSE)
+		*result+=128;
+
+	states[*result] = state;
+	return state;
+}
+
 void ProcessKbd(void)
 {
-	Sint4 result, i;
-	bool isasymbol;
+	Sint4 result;
+	static bool newconsf=FALSE;
 	bool state;
 
 	while((result = VGLKeyboardGetCh()) != 0) {
 
-		if(result < 128)
-			state = TRUE;
-		else {
-			state = FALSE;
-			result -= 128;
-		}
+		state=UpdateStates(&result);
 
-		isasymbol = FALSE;
-		for(i=0;quertycodes[i]!=0;i++)
-			if(result == quertycodes[i]) {
-				result = chars[i];
-				isasymbol = TRUE;
-				break;
+		if(newconsf==TRUE && pausef==TRUE) /* return to game ? */
+		  if(state==FALSE) 
+		    continue;
+		  else newconsf=FALSE;			/* yes */
+		
+		while(newconsf==FALSE && state==TRUE &&
+		      result>=F1KEY && result<=F10KEY && altpressed) {
+		    /* Alt-Fn pressed to switch consoles */
+		    int activecons=0;
+		    int newcons=result-F1KEY+1;
+		    ioctl(0, VT_GETACTIVE, &activecons);
+		    if(newcons==activecons) /* to another console ? */
+			break;
+		    
+		    newconsf=TRUE;
+		    /* do switch */
+		    ioctl(0,VT_ACTIVATE,(caddr_t)(long)newcons); 
+		    if(started==TRUE && pausef==FALSE) {
+			    pausef=TRUE;
+			    testpause(); /* force pause if game active */
+		    }
+		    else {
+		        VGLCheckSwitch(); /* game not active - just switch */
+		        /* now wait for another keyboard strike */
+			result=VGLKeyboardGetCh();
+			while(1) {
+			    if(result!=0) {
+				state=UpdateStates(&result);
+				    if(state==TRUE)     /* ignore releases */
+					break;	
+			        }
+		    	    usleep(500);	/* don't waste CPU when idle */
+			    result=VGLKeyboardGetCh();
 			}
-
-		if (isasymbol == FALSE)
-			result+=128;
-
-		states[result] = state;
+		    }
+		    newconsf=FALSE; /* switched back */
+		}
 
 		if(state == TRUE)
 			continue;
--- main.c	Tue Apr  4 04:42:44 2000
+++ main.c	Fri Jul  6 21:06:29 2001
@@ -561,7 +561,6 @@
 {
   int i;
   if (pausef) {
-    pausef=FALSE;
     soundpause();
     sett2val(40);
     setsoundt2();
@@ -575,6 +574,7 @@
     drawlives();
     if (!synchvid)
       curtime=gethrt();
+    pausef=FALSE;
   }
   else
     soundpauseoff();


Eugene Grosbein
>Release-Note:
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200302181508.h1IF8kK5000611>