Index: /trunk/dports/emulators/dosbox/Portfile
===================================================================
--- /trunk/dports/emulators/dosbox/Portfile	(revision 98952)
+++ /trunk/dports/emulators/dosbox/Portfile	(revision 98953)
@@ -6,5 +6,5 @@
 name                dosbox
 version             0.74
-revision            4
+revision            5
 categories          emulators
 platforms           darwin
@@ -28,4 +28,6 @@
                     port:libsdl_sound \
                     port:libpng
+
+patchfiles          3689.diff 3694.diff 3776.diff 3777.diff
 
 # Assembly language issues
Index: /trunk/dports/emulators/dosbox/files/3689.diff
===================================================================
--- /trunk/dports/emulators/dosbox/files/3689.diff	(revision 98953)
+++ /trunk/dports/emulators/dosbox/files/3689.diff	(revision 98953)
@@ -0,0 +1,74 @@
+Index: src/gui/sdl_mapper.cpp
+===================================================================
+--- src/gui/sdl_mapper.cpp	(Revision 3688)
++++ src/gui/sdl_mapper.cpp	(Revision 3689)
+@@ -2362,17 +2362,21 @@
+ 	if (!MAPPER_LoadBinds()) CreateDefaultBinds();
+ 	if (SDL_GetModState()&KMOD_CAPS) {
+ 		for (CBindList_it bit=caps_lock_event->bindlist.begin();bit!=caps_lock_event->bindlist.end();bit++) {
+-			(*bit)->ActivateBind(32767,true,true);
+ #if SDL_VERSION_ATLEAST(1, 2, 14)
++			(*bit)->ActivateBind(32767,true,false);
+ 			(*bit)->DeActivateBind(false);
++#else
++			(*bit)->ActivateBind(32767,true,true); //Skip the action itself as bios_keyboard.cpp handles the startup state.
+ #endif
+ 		}
+ 	}
+ 	if (SDL_GetModState()&KMOD_NUM) {
+ 		for (CBindList_it bit=num_lock_event->bindlist.begin();bit!=num_lock_event->bindlist.end();bit++) {
+-			(*bit)->ActivateBind(32767,true,true);
+ #if SDL_VERSION_ATLEAST(1, 2, 14)
++			(*bit)->ActivateBind(32767,true,false);
+ 			(*bit)->DeActivateBind(false);
++#else
++			(*bit)->ActivateBind(32767,true,true);
+ #endif
+ 		}
+ 	}
+Index: src/gui/sdlmain.cpp
+===================================================================
+--- src/gui/sdlmain.cpp	(Revision 3688)
++++ src/gui/sdlmain.cpp	(Revision 3689)
+@@ -1770,6 +1770,10 @@
+ 
+ 	/* Init SDL */
+ #if SDL_VERSION_ATLEAST(1, 2, 14)
++	/* Or debian/ubuntu with older libsdl version as they have done this themselves, but then differently.
++	 * with this variable they will work correctly. I've only tested the 1.2.14 behaviour against the windows version
++	 * of libsdl
++	 */
+ 	putenv(const_cast<char*>("SDL_DISABLE_LOCK_KEYS=1"));
+ #endif
+ 	if ( SDL_Init( SDL_INIT_AUDIO|SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_CDROM
+Index: src/ints/bios_keyboard.cpp
+===================================================================
+--- src/ints/bios_keyboard.cpp	(Revision 3688)
++++ src/ints/bios_keyboard.cpp	(Revision 3689)
+@@ -33,6 +33,8 @@
+  * Define the following if this is the case */
+ #if SDL_VERSION_ATLEAST(1, 2, 14)
+ #define CAN_USE_LOCK 1
++/* For lower versions of SDL we also use a slight hack to get the startup states of numclock and capslock right.
++ * The proper way is in the mapper, but the repeating key is an unwanted side effect for lower versions of SDL */
+ #endif
+ 
+ static Bitu call_int16,call_irq1,call_irq6;
+@@ -592,9 +594,14 @@
+ 	mem_writew(BIOS_KEYBOARD_BUFFER_TAIL,0x1e);
+ 	Bit8u flag1 = 0;
+ 	Bit8u leds = 16; /* Ack recieved */
+-//MAPPER_Init takes care of this now ?
+-//	if(startup_state_capslock) { flag1|=0x40; leds|=0x04;}
+-//	if(startup_state_numlock){ flag1|=0x20; leds|=0x02;}
++
++#if SDL_VERSION_ATLEAST(1, 2, 14)
++//Nothing, mapper handles all.
++#else
++	if (startup_state_capslock) { flag1|=0x40; leds|=0x04;}
++	if (startup_state_numlock)  { flag1|=0x20; leds|=0x02;}
++#endif
++
+ 	mem_writeb(BIOS_KEYBOARD_FLAGS1,flag1);
+ 	mem_writeb(BIOS_KEYBOARD_FLAGS2,0);
+ 	mem_writeb(BIOS_KEYBOARD_FLAGS3,16); /* Enhanced keyboard installed */	
Index: /trunk/dports/emulators/dosbox/files/3694.diff
===================================================================
--- /trunk/dports/emulators/dosbox/files/3694.diff	(revision 98953)
+++ /trunk/dports/emulators/dosbox/files/3694.diff	(revision 98953)
@@ -0,0 +1,13 @@
+Index: src/cpu/callback.cpp
+===================================================================
+--- src/cpu/callback.cpp	(Revision 3693)
++++ src/cpu/callback.cpp	(Revision 3694)
+@@ -65,7 +65,7 @@
+ 	Bit16u oldcs=SegValue(cs);
+ 	Bit32u oldeip=reg_eip;
+ 	SegSet16(cs,CB_SEG);
+-	reg_eip=call_idle*CB_SIZE;
++	reg_eip=CB_SOFFSET+call_idle*CB_SIZE;
+ 	DOSBOX_RunMachine();
+ 	reg_eip=oldeip;
+ 	SegSet16(cs,oldcs);
Index: /trunk/dports/emulators/dosbox/files/3776.diff
===================================================================
--- /trunk/dports/emulators/dosbox/files/3776.diff	(revision 98953)
+++ /trunk/dports/emulators/dosbox/files/3776.diff	(revision 98953)
@@ -0,0 +1,19 @@
+Index: src/dos/dos_execute.cpp
+===================================================================
+--- src/dos/dos_execute.cpp	(Revision 3775)
++++ src/dos/dos_execute.cpp	(Revision 3776)
+@@ -93,8 +93,13 @@
+ 	DOS_MCB mcb(dos.psp()-1);
+ 	static char name[9];
+ 	mcb.GetFileName(name);
++	name[8] = 0;
+ 	if (!strlen(name)) strcpy(name,"DOSBOX");
+-	RunningProgram=name;
++	for(Bitu i = 0;i < 8;i++) { //Don't put garbage in the title bar. Mac OS X doesn't like it
++		if (name[i] == 0) break;
++		if ( !isprint(*reinterpret_cast<unsigned char*>(&name[i])) ) name[i] = '?';
++	}
++	RunningProgram = name;
+ 	GFX_SetTitle(-1,-1,false);
+ }
+ 
Index: /trunk/dports/emulators/dosbox/files/3777.diff
===================================================================
--- /trunk/dports/emulators/dosbox/files/3777.diff	(revision 98953)
+++ /trunk/dports/emulators/dosbox/files/3777.diff	(revision 98953)
@@ -0,0 +1,71 @@
+Index: src/gui/sdlmain.cpp
+===================================================================
+--- src/gui/sdlmain.cpp	(Revision 3776)
++++ src/gui/sdlmain.cpp	(Revision 3777)
+@@ -246,6 +246,12 @@
+ 	SDL_WM_SetCaption(title,VERSION);
+ }
+ 
++static void KillSwitch(bool pressed) {
++	if (!pressed)
++		return;
++	throw 1;
++}
++
+ static void PauseDOSBox(bool pressed) {
+ 	if (!pressed)
+ 		return;
+@@ -262,15 +268,22 @@
+ 		SDL_WaitEvent(&event);    // since we're not polling, cpu usage drops to 0.
+ 		switch (event.type) {
+ 
+-			case SDL_QUIT: throw(0); break;
++			case SDL_QUIT: KillSwitch(true); break;
+ 			case SDL_KEYDOWN:   // Must use Pause/Break Key to resume.
+ 			case SDL_KEYUP:
+-			if(event.key.keysym.sym==SDLK_PAUSE) {
++			if(event.key.keysym.sym == SDLK_PAUSE) {
+ 
+-				paused=false;
++				paused = false;
+ 				GFX_SetTitle(-1,-1,false);
+ 				break;
+ 			}
++#if defined (MACOSX)
++			if (event.key.keysym.sym == SDLK_q && (event.key.keysym.mod == KMOD_RMETA || event.key.keysym.mod == KMOD_LMETA) ) {
++				/* On macs, all aps exit when pressing cmd-q */
++				KillSwitch(true);
++				break;
++			} 
++#endif
+ 		}
+ 	}
+ }
+@@ -991,11 +1004,6 @@
+ 	if (sdl.desktop.fullscreen) GFX_SwitchFullScreen();
+ }
+ 
+-static void KillSwitch(bool pressed) {
+-	if (!pressed)
+-		return;
+-	throw 1;
+-}
+ 
+ static void SetPriority(PRIORITY_LEVELS level) {
+ 
+@@ -1513,6 +1521,15 @@
+ 			if (((event.key.keysym.sym==SDLK_TAB)) &&
+ 				((sdl.laltstate==SDL_KEYDOWN) || (sdl.raltstate==SDL_KEYDOWN))) break;
+ #endif
++#if defined (MACOSX)			
++		case SDL_KEYDOWN:
++		case SDL_KEYUP:
++			/* On macs CMD-Q is the default key to close an application */
++			if (event.key.keysym.sym == SDLK_q && (event.key.keysym.mod == KMOD_RMETA || event.key.keysym.mod == KMOD_LMETA) ) {
++				KillSwitch(true);
++				break;
++			} 
++#endif
+ 		default:
+ 			void MAPPER_CheckEvent(SDL_Event * event);
+ 			MAPPER_CheckEvent(&event);
