Bug 48426 - [PATCH] digger-vgl does not support console switching
Summary: [PATCH] digger-vgl does not support console switching
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-ports-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-02-18 15:30 UTC by Eugene Grosbein
Modified: 2005-02-21 11:49 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eugene Grosbein 2003-02-18 15:30:05 UTC
	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.

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.



Eugene Grosbein--bEF79ol8ZRQlozAJRIr1RVqAvJCzswRKSUemieYN3tKOcnYX
Content-Type: text/plain; name="file.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="file.diff"

--- 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();
How-To-Repeat: 	Run digger-vgl and try to use Alt-Fn to switch vty's, you will fail.
Comment 1 Tilman Keskinoz freebsd_committer freebsd_triage 2003-02-24 11:10:31 UTC
Responsible Changed
From-To: freebsd-ports-bugs->sobomax

Over to Maintainer
Comment 2 Eugene Grosbein 2003-04-07 11:57:37 UTC
Hi!

I'm just notifying about awaiting PR :-)

Eugene Grosbein
Comment 3 Mark Linimon freebsd_committer freebsd_triage 2004-04-03 01:36:32 UTC
State Changed
From-To: open->suspended

sobomax gave up maintainership of this port 8 months ago but forgot 
to reset the responsible of this PR, I am guessing. 

Mark as suspended for right now unless/until someone adopts this 
port.  (Note: this PR is quite old by now). 


Comment 4 Mark Linimon freebsd_committer freebsd_triage 2004-04-03 01:36:32 UTC
Responsible Changed
From-To: sobomax->freebsd-ports-bugs
Comment 5 Mark Linimon freebsd_committer freebsd_triage 2004-04-05 05:36:23 UTC
State Changed
From-To: suspended->open

Submitted objected to this being marked suspended, so change 
it back to open.
Comment 6 Kirill Ponomarev freebsd_committer freebsd_triage 2005-02-21 11:48:55 UTC
State Changed
From-To: open->closed

Committed, thanks!