Browse Source

Refactored.
Added SDLSystem and SDLTimer mods.

woollybah 11 years ago
parent
commit
8daf4f8f74

+ 7 - 7
sdlgraphics.mod/common.bmx

@@ -62,16 +62,16 @@ Extern
 	
 	
 	' system stuff
-	Function SDL_ShowCursor(visible:Int)
+'	Function SDL_ShowCursor(visible:Int)
 	Function bmx_SDL_WarpMouseInWindow(x:Int, y:Int)
 	
-	Function bmx_SDL_GetDisplayWidth:Int(display:Int)
-	Function bmx_SDL_GetDisplayHeight:Int(display:Int)
-	Function bmx_SDL_GetDisplayDepth:Int(display:Int)
-	Function bmx_SDL_GetDisplayhertz:Int(display:Int)
+'	Function bmx_SDL_GetDisplayWidth:Int(display:Int)
+'	Function bmx_SDL_GetDisplayHeight:Int(display:Int)
+'	Function bmx_SDL_GetDisplayDepth:Int(display:Int)
+'	Function bmx_SDL_GetDisplayhertz:Int(display:Int)
 
-	Function bmx_SDL_Poll()
-	Function bmx_SDL_WaitEvent()
+'	Function bmx_SDL_Poll()
+'	Function bmx_SDL_WaitEvent()
 	
 End Extern
 

+ 0 - 314
sdlgraphics.mod/glue.c

@@ -22,12 +22,8 @@
 */
 
 #include "SDL_video.h"
-#include "SDL_events.h"
-#include "SDL_keyboard.h"
 
 #include <brl.mod/blitz.mod/blitz.h>
-#include <brl.mod/event.mod/event.h>	//event enums
-#include <brl.mod/keycodes.mod/keycodes.h>	//keycode enums
 
 enum{
 	MODE_SHARED=0,
@@ -189,313 +185,3 @@ void bbSDLExit(){
 	_currentContext=0;
 }
 
-
-
-/* System stuff */
-
-void brl_event_EmitEvent( BBObject *event );
-BBObject *brl_event_CreateEvent( int id,BBObject *source,int data,int mods,int x,int y,BBObject *extra );
-
-void bbSDLSystemEmitEvent( int id,BBObject *source,int data,int mods,int x,int y,BBObject *extra ){
-	BBObject *event=brl_event_CreateEvent( id,source,data,mods,x,y,extra );
-	brl_event_EmitEvent( event );
-}
-int mapkey(SDL_Scancode scancode);
-int mapmods(int keymods);
-
-
-int bmx_SDL_GetDisplayWidth(int display) {
-	SDL_DisplayMode mode;
-	SDL_GetCurrentDisplayMode(display, &mode);
-	return mode.w;
-}
-
-int bmx_SDL_GetDisplayHeight(int display) {
-	SDL_DisplayMode mode;
-	SDL_GetCurrentDisplayMode(display, &mode);
-	return mode.h;
-}
-
-int bmx_SDL_GetDisplayDepth(int display) {
-	SDL_DisplayMode mode;
-	SDL_GetCurrentDisplayMode(display, &mode);
-	return mode.format; // TODO - make this a proper bit depth number
-}
-
-int bmx_SDL_GetDisplayhertz(int display) {
-	SDL_DisplayMode mode;
-	SDL_GetCurrentDisplayMode(display, &mode);
-	return mode.refresh_rate;
-}
-
-void bmx_SDL_EmitSDLEvent( SDL_Event *event, BBObject *source ) {
-	int data;
-	int mods;
-	switch (event->type) {
-		case SDL_QUIT:
-			bbSDLSystemEmitEvent(BBEVENT_APPTERMINATE, source, 0, 0, 0, 0, &bbNullObject);
-			return;
-		case SDL_KEYDOWN:
-		case SDL_KEYUP:
-			data = mapkey(event->key.keysym.scancode);
-			mods = mapmods(event->key.keysym.mod);
-			if (event->key.repeat) {
-				bbSDLSystemEmitEvent( BBEVENT_KEYREPEAT,source,data,mods,0,0,&bbNullObject );
-				return;
-			}
-			bbSDLSystemEmitEvent( (event->type == SDL_KEYDOWN) ? BBEVENT_KEYDOWN : BBEVENT_KEYUP,source,data,mods,0,0,&bbNullObject );
-			return;
-			break;
-		case SDL_MOUSEMOTION:
-			bbSDLSystemEmitEvent( BBEVENT_MOUSEMOVE,source,0,0,event->motion.x,event->motion.y,&bbNullObject );
-			return;
-		case SDL_MOUSEBUTTONDOWN:
-		case SDL_MOUSEBUTTONUP:
-			bbSDLSystemEmitEvent( (event->type == SDL_MOUSEBUTTONDOWN) ? BBEVENT_MOUSEDOWN : BBEVENT_MOUSEUP,source,event->button.button,0,event->button.x,event->button.y,&bbNullObject );
-			return;
-		case SDL_MOUSEWHEEL:
-			bbSDLSystemEmitEvent( BBEVENT_MOUSEWHEEL,source,(event->wheel.y < 0) ? -1 : 1,0,0,0,&bbNullObject );
-			return;
-	}	
-	
-}
-
-void bmx_SDL_Poll() {
-	SDL_Event event;
-	while (SDL_PollEvent(&event)) {
-		bmx_SDL_EmitSDLEvent(&event, &bbNullObject);
-	}
-}
-
-void bmx_SDL_WaitEvent() {
-	SDL_Event event;
-	if (SDL_WaitEvent(&event)) {
-		bmx_SDL_EmitSDLEvent(&event, &bbNullObject);
-	}
-}
-
-
-int mapkey(SDL_Scancode scancode) {
-	switch(scancode) {
-		case SDL_SCANCODE_BACKSPACE:
-			return KEY_BACKSPACE;
-		case SDL_SCANCODE_TAB:
-			return KEY_TAB;
-		case SDL_SCANCODE_RETURN:
-			return KEY_ENTER;
-		case SDL_SCANCODE_ESCAPE:
-			return KEY_ESC;
-		case SDL_SCANCODE_SPACE:
-			return KEY_SPACE;
-		case SDL_SCANCODE_PAGEUP:
-			return KEY_PAGEUP;
-		case SDL_SCANCODE_PAGEDOWN:
-			return KEY_PAGEDOWN;
-		case SDL_SCANCODE_END:
-			return KEY_END;
-		case SDL_SCANCODE_HOME:
-			return KEY_HOME;
-		case SDL_SCANCODE_LEFT:
-			return KEY_LEFT;
-		case SDL_SCANCODE_UP:
-			return KEY_UP;
-		case SDL_SCANCODE_RIGHT:
-			return KEY_RIGHT;
-		case SDL_SCANCODE_DOWN:
-			return KEY_DOWN;
-		case SDL_SCANCODE_INSERT:
-			return KEY_INSERT;
-		case SDL_SCANCODE_DELETE:
-			return KEY_DELETE;
-		case SDL_SCANCODE_0:
-			return KEY_0;
-		case SDL_SCANCODE_1:
-			return KEY_1;
-		case SDL_SCANCODE_2:
-			return KEY_2;
-		case SDL_SCANCODE_3:
-			return KEY_3;
-		case SDL_SCANCODE_4:
-			return KEY_4;
-		case SDL_SCANCODE_5:
-			return KEY_5;
-		case SDL_SCANCODE_6:
-			return KEY_6;
-		case SDL_SCANCODE_7:
-			return KEY_7;
-		case SDL_SCANCODE_8:
-			return KEY_8;
-		case SDL_SCANCODE_9:
-			return KEY_9;
-		case SDL_SCANCODE_A:
-			return KEY_A;
-		case SDL_SCANCODE_B:
-			return KEY_B;
-		case SDL_SCANCODE_C:
-			return KEY_C;
-		case SDL_SCANCODE_D:
-			return KEY_D;
-		case SDL_SCANCODE_E:
-			return KEY_E;
-		case SDL_SCANCODE_F:
-			return KEY_F;
-		case SDL_SCANCODE_G:
-			return KEY_G;
-		case SDL_SCANCODE_H:
-			return KEY_H;
-		case SDL_SCANCODE_I:
-			return KEY_I;
-		case SDL_SCANCODE_J:
-			return KEY_J;
-		case SDL_SCANCODE_K:
-			return KEY_K;
-		case SDL_SCANCODE_L:
-			return KEY_L;
-		case SDL_SCANCODE_M:
-			return KEY_M;
-		case SDL_SCANCODE_N:
-			return KEY_N;
-		case SDL_SCANCODE_O:
-			return KEY_O;
-		case SDL_SCANCODE_P:
-			return KEY_P;
-		case SDL_SCANCODE_Q:
-			return KEY_Q;
-		case SDL_SCANCODE_R:
-			return KEY_R;
-		case SDL_SCANCODE_S:
-			return KEY_S;
-		case SDL_SCANCODE_T:
-			return KEY_T;
-		case SDL_SCANCODE_U:
-			return KEY_U;
-		case SDL_SCANCODE_V:
-			return KEY_V;
-		case SDL_SCANCODE_W:
-			return KEY_W;
-		case SDL_SCANCODE_X:
-			return KEY_X;
-		case SDL_SCANCODE_Y:
-			return KEY_Y;
-		case SDL_SCANCODE_Z:
-			return KEY_Z;
-		case SDL_SCANCODE_LGUI:
-			return KEY_LSYS;
-		case SDL_SCANCODE_RGUI:
-			return KEY_RSYS;
-		case SDL_SCANCODE_KP_0:
-			return KEY_NUM0;
-		case SDL_SCANCODE_KP_1:
-			return KEY_NUM1;
-		case SDL_SCANCODE_KP_2:
-			return KEY_NUM2;
-		case SDL_SCANCODE_KP_3:
-			return KEY_NUM3;
-		case SDL_SCANCODE_KP_4:
-			return KEY_NUM4;
-		case SDL_SCANCODE_KP_5:
-			return KEY_NUM5;
-		case SDL_SCANCODE_KP_6:
-			return KEY_NUM6;
-		case SDL_SCANCODE_KP_7:
-			return KEY_NUM7;
-		case SDL_SCANCODE_KP_8:
-			return KEY_NUM8;
-		case SDL_SCANCODE_KP_9:
-			return KEY_NUM9;
-		case SDL_SCANCODE_KP_MULTIPLY:
-			return KEY_NUMMULTIPLY;
-		case SDL_SCANCODE_KP_PLUS:
-			return KEY_NUMADD;
-		case SDL_SCANCODE_KP_EQUALS:
-			return KEY_NUMSLASH;
-		case SDL_SCANCODE_KP_MINUS:
-			return KEY_NUMSUBTRACT;
-		case SDL_SCANCODE_KP_PERIOD:
-			return KEY_NUMDECIMAL;
-		case SDL_SCANCODE_KP_DIVIDE:
-			return KEY_NUMDIVIDE;
-		case SDL_SCANCODE_F1:
-			return KEY_F1;
-		case SDL_SCANCODE_F2:
-			return KEY_F2;
-		case SDL_SCANCODE_F3:
-			return KEY_F3;
-		case SDL_SCANCODE_F4:
-			return KEY_F4;
-		case SDL_SCANCODE_F5:
-			return KEY_F5;
-		case SDL_SCANCODE_F6:
-			return KEY_F6;
-		case SDL_SCANCODE_F7:
-			return KEY_F7;
-		case SDL_SCANCODE_F8:
-			return KEY_F8;
-		case SDL_SCANCODE_F9:
-			return KEY_F9;
-		case SDL_SCANCODE_F10:
-			return KEY_F10;
-		case SDL_SCANCODE_F11:
-			return KEY_F11;
-		case SDL_SCANCODE_F12:
-			return KEY_F12;
-		case SDL_SCANCODE_LSHIFT:
-			return KEY_LSHIFT;
-		case SDL_SCANCODE_RSHIFT:
-			return KEY_RSHIFT;
-		case SDL_SCANCODE_LCTRL:
-			return KEY_LCONTROL;
-		case SDL_SCANCODE_RCTRL:
-			return KEY_RCONTROL;
-		case SDL_SCANCODE_LALT:
-			return KEY_LALT;
-		case SDL_SCANCODE_RALT:
-			return KEY_RALT;
-		case SDL_SCANCODE_GRAVE:
-			return KEY_TILDE;
-		case SDL_SCANCODE_MINUS:
-			return KEY_MINUS;
-		case SDL_SCANCODE_EQUALS:
-			return KEY_EQUALS;
-		case SDL_SCANCODE_LEFTBRACKET:
-			return KEY_OPENBRACKET;
-		case SDL_SCANCODE_RIGHTBRACKET:
-			return KEY_CLOSEBRACKET;
-		case SDL_SCANCODE_BACKSLASH:
-			return KEY_BACKSLASH;
-		case SDL_SCANCODE_SEMICOLON:
-			return KEY_SEMICOLON;
-		case SDL_SCANCODE_APOSTROPHE:
-			return KEY_QUOTES;
-		case SDL_SCANCODE_COMMA:
-			return KEY_COMMA;
-		case SDL_SCANCODE_PERIOD:
-			return KEY_PERIOD;
-		case SDL_SCANCODE_SLASH:
-			return KEY_SLASH;
-	}
-	
-	return scancode;
-}
-
-int mapmods(int keymods) {
-	int mod = 0;
-	
-	if (keymods & KMOD_SHIFT) {
-		mod |= MODIFIER_SHIFT;
-	}
-	
-	if (keymods & KMOD_CTRL) {
-		mod |= MODIFIER_CONTROL;
-	}
-	
-	if (keymods & KMOD_ALT) {
-		mod |= MODIFIER_OPTION;
-	}
-	
-	if (keymods & KMOD_GUI) {
-		mod |= MODIFIER_SYSTEM;
-	}
-
-	return mod;
-}

+ 7 - 75
sdlgraphics.mod/sdlgraphics.bmx

@@ -23,8 +23,7 @@ Strict
 
 Module SDL.SDLGraphics
 
-Import SDL.SDL
-Import BRL.System
+Import SDL.SDLSystem
 Import BRL.Graphics
 
 Import "common.bmx"
@@ -122,79 +121,12 @@ Function SDLGraphics:TGraphics( width:Int,height:Int,depth:Int=0,hertz:Int=60,fl
 	Return Graphics( width,height,depth,hertz,flags )
 End Function
 	
-SetGraphicsDriver SDLGraphicsDriver()
-
-
-
-
-
-Type TSDLSystemDriver Extends TSystemDriver
-
-	Method New()
-		SDL_Init(SDL_INIT_VIDEO)
-		OnEnd(bbSDLExit)
-	End Method
-
-	Method Poll()
-		bmx_SDL_Poll()
-	End Method
-	
-	Method Wait()
-		bmx_SDL_WaitEvent()
-	End Method
-
-	Method Emit( osevent:Byte Ptr,source:Object )
-		' TODO
-	End Method
-
-	Method SetMouseVisible( visible )
-		SDL_ShowCursor(visible)
-	End Method
+SDL_Init(SDL_INIT_VIDEO)
 
-	Method MoveMouse( x,y )
-		bmx_SDL_WarpMouseInWindow(x, y)
-	End Method
+' cleanup context on exit
+OnEnd(bbSDLExit)
+' set mouse warp function
+_sdl_WarpMouse = bmx_SDL_WarpMouseInWindow
 
-	Method Notify( text$,serious )
-		' TODO
-	End Method
-	
-	Method Confirm( text$,serious )
-		' TODO
-	End Method
-	
-	Method Proceed( text$,serious )
-		' TODO
-	End Method
-
-	Method RequestFile$( text$,exts$,save,file$ )
-		' TODO
-	End Method
-	
-	Method RequestDir$( text$,path$ )
-		' TODO
-	End Method
-
-	Method OpenURL( url$ )
-		' TODO
-	End Method
-
-	Method DesktopWidth:Int()
-		Return bmx_SDL_GetDisplayWidth(0)
-	End Method
-	
-	Method DesktopHeight:Int()
-		Return bmx_SDL_GetDisplayHeight(0)
-	End Method
-	
-	Method DesktopDepth:Int()
-		Return bmx_SDL_GetDisplayDepth(0)
-	End Method
-	
-	Method DesktopHertz:Int()
-		Return bmx_SDL_GetDisplayhertz(0)
-	End Method
-
-End Type
+SetGraphicsDriver SDLGraphicsDriver()
 
-Driver = New TSDLSystemDriver

+ 63 - 0
sdlsystem.mod/common.bmx

@@ -0,0 +1,63 @@
+' Copyright (c) 2014 Bruce A Henderson
+'
+' This software is provided 'as-is', without any express or implied
+' warranty. In no event will the authors be held liable for any damages
+' arising from the use of this software.
+'
+' Permission is granted to anyone to use this software for any purpose,
+' including commercial applications, and to alter it and redistribute it
+' freely, subject to the following restrictions:
+'
+'    1. The origin of this software must not be misrepresented; you must not
+'    claim that you wrote the original software. If you use this software
+'    in a product, an acknowledgment in the product documentation would be
+'    appreciated but is not required.
+'
+'    2. Altered source versions must be plainly marked as such, and must not be
+'    misrepresented as being the original software.
+'
+'    3. This notice may not be removed or altered from any source
+'    distribution.
+'
+SuperStrict
+
+?win32x86
+Import "../../sdl.mod/sdl.mod/include/win32x86/*.h"
+
+?win32x64
+Import "../../sdl.mod/sdl.mod/include/win32x64/*.h"
+
+?macos
+Import "../../sdl.mod/sdl.mod/include/macos/*.h"
+
+?linuxx86
+Import "../../sdl.mod/sdl.mod/include/linuxx86/*.h"
+
+?linuxx64
+Import "../../sdl.mod/sdl.mod/include/linuxx64/*.h"
+
+?linuxarm
+
+?
+
+Import "../../sdl.mod/sdl.mod/include/*.h"
+
+Import "glue.c"
+
+Extern
+
+	
+	
+	' system stuff
+	Function SDL_ShowCursor(visible:Int)
+	
+	Function bmx_SDL_GetDisplayWidth:Int(display:Int)
+	Function bmx_SDL_GetDisplayHeight:Int(display:Int)
+	Function bmx_SDL_GetDisplayDepth:Int(display:Int)
+	Function bmx_SDL_GetDisplayhertz:Int(display:Int)
+
+	Function bmx_SDL_Poll()
+	Function bmx_SDL_WaitEvent()
+	
+End Extern
+

+ 327 - 0
sdlsystem.mod/glue.c

@@ -0,0 +1,327 @@
+#include "SDL_events.h"
+#include "SDL_keyboard.h"
+
+#include <brl.mod/blitz.mod/blitz.h>
+#include <brl.mod/event.mod/event.h>	//event enums
+#include <brl.mod/keycodes.mod/keycodes.h>	//keycode enums
+
+/* System stuff */
+
+void brl_event_EmitEvent( BBObject *event );
+BBObject *brl_event_CreateEvent( int id,BBObject *source,int data,int mods,int x,int y,BBObject *extra );
+
+void bbSDLSystemEmitEvent( int id,BBObject *source,int data,int mods,int x,int y,BBObject *extra ){
+	BBObject *event=brl_event_CreateEvent( id,source,data,mods,x,y,extra );
+	brl_event_EmitEvent( event );
+}
+int mapkey(SDL_Scancode scancode);
+int mapmods(int keymods);
+
+
+
+
+int bmx_SDL_GetDisplayWidth(int display) {
+	SDL_DisplayMode mode;
+	SDL_GetCurrentDisplayMode(display, &mode);
+	return mode.w;
+}
+
+int bmx_SDL_GetDisplayHeight(int display) {
+	SDL_DisplayMode mode;
+	SDL_GetCurrentDisplayMode(display, &mode);
+	return mode.h;
+}
+
+int bmx_SDL_GetDisplayDepth(int display) {
+	SDL_DisplayMode mode;
+	SDL_GetCurrentDisplayMode(display, &mode);
+	return mode.format; // TODO - make this a proper bit depth number
+}
+
+int bmx_SDL_GetDisplayhertz(int display) {
+	SDL_DisplayMode mode;
+	SDL_GetCurrentDisplayMode(display, &mode);
+	return mode.refresh_rate;
+}
+
+void bmx_SDL_EmitSDLEvent( SDL_Event *event, BBObject *source ) {
+	int data;
+	int mods;
+	switch (event->type) {
+		case SDL_QUIT:
+			bbSDLSystemEmitEvent(BBEVENT_APPTERMINATE, source, 0, 0, 0, 0, &bbNullObject);
+			return;
+		case SDL_KEYDOWN:
+		case SDL_KEYUP:
+			data = mapkey(event->key.keysym.scancode);
+			mods = mapmods(event->key.keysym.mod);
+			if (event->key.repeat) {
+				bbSDLSystemEmitEvent( BBEVENT_KEYREPEAT,source,data,mods,0,0,&bbNullObject );
+				return;
+			}
+			bbSDLSystemEmitEvent( (event->type == SDL_KEYDOWN) ? BBEVENT_KEYDOWN : BBEVENT_KEYUP,source,data,mods,0,0,&bbNullObject );
+			return;
+			break;
+		case SDL_MOUSEMOTION:
+			bbSDLSystemEmitEvent( BBEVENT_MOUSEMOVE,source,0,0,event->motion.x,event->motion.y,&bbNullObject );
+			return;
+		case SDL_MOUSEBUTTONDOWN:
+		case SDL_MOUSEBUTTONUP:
+			bbSDLSystemEmitEvent( (event->type == SDL_MOUSEBUTTONDOWN) ? BBEVENT_MOUSEDOWN : BBEVENT_MOUSEUP,source,event->button.button,0,event->button.x,event->button.y,&bbNullObject );
+			return;
+		case SDL_MOUSEWHEEL:
+			bbSDLSystemEmitEvent( BBEVENT_MOUSEWHEEL,source,(event->wheel.y < 0) ? -1 : 1,0,0,0,&bbNullObject );
+			return;
+		case SDL_USEREVENT:
+			switch (event->user.code) {
+				case BBEVENT_TIMERTICK:
+					bbSDLSystemEmitEvent( BBEVENT_TIMERTICK,event->user.data1,(int)event->user.data2,0,0,0,&bbNullObject );
+					return;
+				case 0x802:
+					brl_event_EmitEvent( event->user.data1 );
+					return;
+			}
+	}	
+	
+}
+
+void bmx_SDL_Poll() {
+	SDL_Event event;
+	while (SDL_PollEvent(&event)) {
+		bmx_SDL_EmitSDLEvent(&event, &bbNullObject);
+	}
+}
+
+void bmx_SDL_WaitEvent() {
+	SDL_Event event;
+	if (SDL_WaitEvent(&event)) {
+		bmx_SDL_EmitSDLEvent(&event, &bbNullObject);
+	}
+}
+
+
+int mapkey(SDL_Scancode scancode) {
+	switch(scancode) {
+		case SDL_SCANCODE_BACKSPACE:
+			return KEY_BACKSPACE;
+		case SDL_SCANCODE_TAB:
+			return KEY_TAB;
+		case SDL_SCANCODE_RETURN:
+			return KEY_ENTER;
+		case SDL_SCANCODE_ESCAPE:
+			return KEY_ESC;
+		case SDL_SCANCODE_SPACE:
+			return KEY_SPACE;
+		case SDL_SCANCODE_PAGEUP:
+			return KEY_PAGEUP;
+		case SDL_SCANCODE_PAGEDOWN:
+			return KEY_PAGEDOWN;
+		case SDL_SCANCODE_END:
+			return KEY_END;
+		case SDL_SCANCODE_HOME:
+			return KEY_HOME;
+		case SDL_SCANCODE_LEFT:
+			return KEY_LEFT;
+		case SDL_SCANCODE_UP:
+			return KEY_UP;
+		case SDL_SCANCODE_RIGHT:
+			return KEY_RIGHT;
+		case SDL_SCANCODE_DOWN:
+			return KEY_DOWN;
+		case SDL_SCANCODE_INSERT:
+			return KEY_INSERT;
+		case SDL_SCANCODE_DELETE:
+			return KEY_DELETE;
+		case SDL_SCANCODE_0:
+			return KEY_0;
+		case SDL_SCANCODE_1:
+			return KEY_1;
+		case SDL_SCANCODE_2:
+			return KEY_2;
+		case SDL_SCANCODE_3:
+			return KEY_3;
+		case SDL_SCANCODE_4:
+			return KEY_4;
+		case SDL_SCANCODE_5:
+			return KEY_5;
+		case SDL_SCANCODE_6:
+			return KEY_6;
+		case SDL_SCANCODE_7:
+			return KEY_7;
+		case SDL_SCANCODE_8:
+			return KEY_8;
+		case SDL_SCANCODE_9:
+			return KEY_9;
+		case SDL_SCANCODE_A:
+			return KEY_A;
+		case SDL_SCANCODE_B:
+			return KEY_B;
+		case SDL_SCANCODE_C:
+			return KEY_C;
+		case SDL_SCANCODE_D:
+			return KEY_D;
+		case SDL_SCANCODE_E:
+			return KEY_E;
+		case SDL_SCANCODE_F:
+			return KEY_F;
+		case SDL_SCANCODE_G:
+			return KEY_G;
+		case SDL_SCANCODE_H:
+			return KEY_H;
+		case SDL_SCANCODE_I:
+			return KEY_I;
+		case SDL_SCANCODE_J:
+			return KEY_J;
+		case SDL_SCANCODE_K:
+			return KEY_K;
+		case SDL_SCANCODE_L:
+			return KEY_L;
+		case SDL_SCANCODE_M:
+			return KEY_M;
+		case SDL_SCANCODE_N:
+			return KEY_N;
+		case SDL_SCANCODE_O:
+			return KEY_O;
+		case SDL_SCANCODE_P:
+			return KEY_P;
+		case SDL_SCANCODE_Q:
+			return KEY_Q;
+		case SDL_SCANCODE_R:
+			return KEY_R;
+		case SDL_SCANCODE_S:
+			return KEY_S;
+		case SDL_SCANCODE_T:
+			return KEY_T;
+		case SDL_SCANCODE_U:
+			return KEY_U;
+		case SDL_SCANCODE_V:
+			return KEY_V;
+		case SDL_SCANCODE_W:
+			return KEY_W;
+		case SDL_SCANCODE_X:
+			return KEY_X;
+		case SDL_SCANCODE_Y:
+			return KEY_Y;
+		case SDL_SCANCODE_Z:
+			return KEY_Z;
+		case SDL_SCANCODE_LGUI:
+			return KEY_LSYS;
+		case SDL_SCANCODE_RGUI:
+			return KEY_RSYS;
+		case SDL_SCANCODE_KP_0:
+			return KEY_NUM0;
+		case SDL_SCANCODE_KP_1:
+			return KEY_NUM1;
+		case SDL_SCANCODE_KP_2:
+			return KEY_NUM2;
+		case SDL_SCANCODE_KP_3:
+			return KEY_NUM3;
+		case SDL_SCANCODE_KP_4:
+			return KEY_NUM4;
+		case SDL_SCANCODE_KP_5:
+			return KEY_NUM5;
+		case SDL_SCANCODE_KP_6:
+			return KEY_NUM6;
+		case SDL_SCANCODE_KP_7:
+			return KEY_NUM7;
+		case SDL_SCANCODE_KP_8:
+			return KEY_NUM8;
+		case SDL_SCANCODE_KP_9:
+			return KEY_NUM9;
+		case SDL_SCANCODE_KP_MULTIPLY:
+			return KEY_NUMMULTIPLY;
+		case SDL_SCANCODE_KP_PLUS:
+			return KEY_NUMADD;
+		case SDL_SCANCODE_KP_EQUALS:
+			return KEY_NUMSLASH;
+		case SDL_SCANCODE_KP_MINUS:
+			return KEY_NUMSUBTRACT;
+		case SDL_SCANCODE_KP_PERIOD:
+			return KEY_NUMDECIMAL;
+		case SDL_SCANCODE_KP_DIVIDE:
+			return KEY_NUMDIVIDE;
+		case SDL_SCANCODE_F1:
+			return KEY_F1;
+		case SDL_SCANCODE_F2:
+			return KEY_F2;
+		case SDL_SCANCODE_F3:
+			return KEY_F3;
+		case SDL_SCANCODE_F4:
+			return KEY_F4;
+		case SDL_SCANCODE_F5:
+			return KEY_F5;
+		case SDL_SCANCODE_F6:
+			return KEY_F6;
+		case SDL_SCANCODE_F7:
+			return KEY_F7;
+		case SDL_SCANCODE_F8:
+			return KEY_F8;
+		case SDL_SCANCODE_F9:
+			return KEY_F9;
+		case SDL_SCANCODE_F10:
+			return KEY_F10;
+		case SDL_SCANCODE_F11:
+			return KEY_F11;
+		case SDL_SCANCODE_F12:
+			return KEY_F12;
+		case SDL_SCANCODE_LSHIFT:
+			return KEY_LSHIFT;
+		case SDL_SCANCODE_RSHIFT:
+			return KEY_RSHIFT;
+		case SDL_SCANCODE_LCTRL:
+			return KEY_LCONTROL;
+		case SDL_SCANCODE_RCTRL:
+			return KEY_RCONTROL;
+		case SDL_SCANCODE_LALT:
+			return KEY_LALT;
+		case SDL_SCANCODE_RALT:
+			return KEY_RALT;
+		case SDL_SCANCODE_GRAVE:
+			return KEY_TILDE;
+		case SDL_SCANCODE_MINUS:
+			return KEY_MINUS;
+		case SDL_SCANCODE_EQUALS:
+			return KEY_EQUALS;
+		case SDL_SCANCODE_LEFTBRACKET:
+			return KEY_OPENBRACKET;
+		case SDL_SCANCODE_RIGHTBRACKET:
+			return KEY_CLOSEBRACKET;
+		case SDL_SCANCODE_BACKSLASH:
+			return KEY_BACKSLASH;
+		case SDL_SCANCODE_SEMICOLON:
+			return KEY_SEMICOLON;
+		case SDL_SCANCODE_APOSTROPHE:
+			return KEY_QUOTES;
+		case SDL_SCANCODE_COMMA:
+			return KEY_COMMA;
+		case SDL_SCANCODE_PERIOD:
+			return KEY_PERIOD;
+		case SDL_SCANCODE_SLASH:
+			return KEY_SLASH;
+	}
+	
+	return scancode;
+}
+
+int mapmods(int keymods) {
+	int mod = 0;
+	
+	if (keymods & KMOD_SHIFT) {
+		mod |= MODIFIER_SHIFT;
+	}
+	
+	if (keymods & KMOD_CTRL) {
+		mod |= MODIFIER_CONTROL;
+	}
+	
+	if (keymods & KMOD_ALT) {
+		mod |= MODIFIER_OPTION;
+	}
+	
+	if (keymods & KMOD_GUI) {
+		mod |= MODIFIER_SYSTEM;
+	}
+
+	return mod;
+}
+

+ 110 - 0
sdlsystem.mod/sdlsystem.bmx

@@ -0,0 +1,110 @@
+' Copyright (c) 2014 Bruce A Henderson
+'
+' This software is provided 'as-is', without any express or implied
+' warranty. In no event will the authors be held liable for any damages
+' arising from the use of this software.
+'
+' Permission is granted to anyone to use this software for any purpose,
+' including commercial applications, and to alter it and redistribute it
+' freely, subject to the following restrictions:
+'
+'    1. The origin of this software must not be misrepresented; you must not
+'    claim that you wrote the original software. If you use this software
+'    in a product, an acknowledgment in the product documentation would be
+'    appreciated but is not required.
+'
+'    2. Altered source versions must be plainly marked as such, and must not be
+'    misrepresented as being the original software.
+'
+'    3. This notice may not be removed or altered from any source
+'    distribution.
+'
+Strict
+
+Module SDL.SDLSystem
+
+
+Import SDL.SDL
+Import BRL.System
+Import brl.standardio
+
+Import "common.bmx"
+
+
+
+Global _sdl_WarpMouse(x:Int, y:Int)
+
+
+Type TSDLSystemDriver Extends TSystemDriver
+
+	Method New()
+		SDL_Init(SDL_INIT_EVENTS)
+		OnEnd(SDL_Quit)
+	End Method
+
+	Method Poll()
+		bmx_SDL_Poll()
+	End Method
+	
+	Method Wait()
+		bmx_SDL_WaitEvent()
+	End Method
+
+	Method Emit( osevent:Byte Ptr,source:Object )
+		' TODO
+	End Method
+
+	Method SetMouseVisible( visible )
+		SDL_ShowCursor(visible)
+	End Method
+
+	Method MoveMouse( x,y )
+		If _sdl_WarpMouse Then
+			_sdl_WarpMouse(x, y)
+		End If
+	End Method
+
+	Method Notify( text$,serious )
+		' TODO
+	End Method
+	
+	Method Confirm( text$,serious )
+		' TODO
+	End Method
+	
+	Method Proceed( text$,serious )
+		' TODO
+	End Method
+
+	Method RequestFile$( text$,exts$,save,file$ )
+		' TODO
+	End Method
+	
+	Method RequestDir$( text$,path$ )
+		' TODO
+	End Method
+
+	Method OpenURL( url$ )
+		' TODO
+	End Method
+
+	Method DesktopWidth:Int()
+		Return bmx_SDL_GetDisplayWidth(0)
+	End Method
+	
+	Method DesktopHeight:Int()
+		Return bmx_SDL_GetDisplayHeight(0)
+	End Method
+	
+	Method DesktopDepth:Int()
+		Return bmx_SDL_GetDisplayDepth(0)
+	End Method
+	
+	Method DesktopHertz:Int()
+		Return bmx_SDL_GetDisplayhertz(0)
+	End Method
+
+End Type
+
+Driver = New TSDLSystemDriver
+

+ 70 - 0
sdltimer.mod/glue.c

@@ -0,0 +1,70 @@
+/*
+ Copyright (c) 2014 Bruce A Henderson
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+    1. The origin of this software must not be misrepresented; you must not
+    claim that you wrote the original software. If you use this software
+    in a product, an acknowledgment in the product documentation would be
+    appreciated but is not required.
+
+    2. Altered source versions must be plainly marked as such, and must not be
+    misrepresented as being the original software.
+
+    3. This notice may not be removed or altered from any source
+    distribution.
+*/
+
+#include "SDL_events.h"
+#include "SDL_timer.h"
+#include <brl.mod/blitz.mod/blitz.h>
+
+
+void sdl_sdltimer__TimerFired( BBObject * data );
+SDL_TimerID bmx_sdl_timer_start( float hertz, BBObject * timer );
+void bmx_sdl_timer_stop( SDL_TimerID handle, BBObject * timer );
+void bmx_sdl_timer_fire( int id, BBObject * obj, int ticks);
+
+Uint32 bmx_sdl_timer_ontick(Uint32 interval, void *param) {
+	sdl_sdltimer__TimerFired((BBObject*)param);
+	return interval;
+}
+
+void bmx_sdl_timer_fire( int id, BBObject * obj, int ticks ) {
+    SDL_Event event;
+    SDL_UserEvent userevent;
+
+    userevent.type = SDL_USEREVENT;
+    userevent.code = id,
+    userevent.data1 = obj;
+	userevent.data2 = ticks;
+
+    event.type = SDL_USEREVENT;
+    event.user = userevent;
+
+    SDL_PushEvent(&event);
+}
+
+SDL_TimerID bmx_sdl_timer_start( float hertz, BBObject * timer ) {
+	SDL_TimerID t = SDL_AddTimer((int)hertz, bmx_sdl_timer_ontick, timer);
+	
+	if (!t) {
+		return 0;
+	}
+
+	BBRETAIN(timer);
+	
+	return t;
+}
+
+void bmx_sdl_timer_stop( SDL_TimerID handle, BBObject * timer ) {
+	SDL_RemoveTimer(handle);
+	BBRELEASE(timer);
+}
+

+ 163 - 0
sdltimer.mod/sdltimer.bmx

@@ -0,0 +1,163 @@
+' Copyright (c) 2014 Bruce A Henderson
+'
+' This software is provided 'as-is', without any express or implied
+' warranty. In no event will the authors be held liable for any damages
+' arising from the use of this software.
+'
+' Permission is granted to anyone to use this software for any purpose,
+' including commercial applications, and to alter it and redistribute it
+' freely, subject to the following restrictions:
+'
+'    1. The origin of this software must not be misrepresented; you must not
+'    claim that you wrote the original software. If you use this software
+'    in a product, an acknowledgment in the product documentation would be
+'    appreciated but is not required.
+'
+'    2. Altered source versions must be plainly marked as such, and must not be
+'    misrepresented as being the original software.
+'
+'    3. This notice may not be removed or altered from any source
+'    distribution.
+'
+SuperStrict
+
+Rem
+bbdoc: SDL Timer
+End Rem
+Module SDL.SDLTimer
+
+ModuleInfo "Version: 1.00"
+ModuleInfo "Author: Simon Armstrong, Mark Sibly"
+ModuleInfo "License: zlib/libpng"
+ModuleInfo "Copyright: Blitz Research Ltd"
+ModuleInfo "Modserver: BRL"
+
+ModuleInfo "History: 1.03"
+ModuleInfo "History: Update to use Byte Ptr instead of int."
+
+Import SDL.SDLSystem
+Import BRL.Event
+
+?win32x86
+Import "../../sdl.mod/sdl.mod/include/win32x86/*.h"
+
+?win32x64
+Import "../../sdl.mod/sdl.mod/include/win32x64/*.h"
+
+?macos
+Import "../../sdl.mod/sdl.mod/include/macos/*.h"
+
+?linuxx86
+Import "../../sdl.mod/sdl.mod/include/linuxx86/*.h"
+
+?linuxx64
+Import "../../sdl.mod/sdl.mod/include/linuxx64/*.h"
+
+?linuxarm
+
+?
+
+Import "../../sdl.mod/sdl.mod/include/*.h"
+
+Import "glue.c"
+
+Extern
+Function bmx_sdl_timer_start:Byte Ptr( hertz#,timer:TTimer )
+Function bmx_sdl_timer_stop( handle:Byte Ptr,timer:TTimer )
+Function bmx_sdl_timer_fire( id:Int, obj:Object, ticks:Int )
+End Extern
+
+Function _TimerFired( timer:TTimer )
+	timer.Fire
+End Function
+
+Type TTimer
+
+	Method Ticks:Int()
+		Return _ticks
+	End Method
+	
+	Method Stop()
+		If Not _handle Return
+		bmx_sdl_timer_stop _handle,Self
+		_handle=0
+		_event=Null
+	End Method
+	
+	Method Fire()
+		If Not _handle Return
+		_ticks:+1
+		If _event
+			bmx_sdl_timer_fire ($802, _event, 0)
+		Else
+			bmx_sdl_timer_fire (EVENT_TIMERTICK, Self, _ticks)
+		EndIf
+	End Method
+
+	Method Wait:Int()
+		If Not _handle Return 0
+		Local n:Int
+		Repeat
+			WaitSystem
+			n=_ticks-_wticks
+		Until n
+		_wticks:+n
+		Return n
+	End Method
+	
+	Function Create:TTimer( hertz#,event:TEvent=Null )
+		Local t:TTimer=New TTimer
+		Local handle:Byte Ptr=bmx_sdl_timer_start( hertz,t )
+		If Not handle Return Null
+		t._event=event
+		t._handle=handle
+		Return t
+	End Function
+
+	Field _ticks:Int
+	Field _wticks:Int
+	Field _event:TEvent
+	Field _handle:Byte Ptr
+
+End Type
+
+Rem
+bbdoc: Create a timer
+returns: A new timer object
+about:
+#CreateTimer creates a timer object that 'ticks' @hertz times per second.
+
+Each time the timer ticks, @event will be emitted using #EmitEvent.
+
+If @event is Null, an event with an @id equal to EVENT_TIMERTICK and 
+@source equal to the timer object will be emitted instead.
+End Rem
+Function CreateTimer:TTimer( hertz#,event:TEvent=Null )
+	Return TTimer.Create( hertz,event )
+End Function
+
+Rem
+bbdoc: Get timer tick counter
+returns: The number of times @timer has ticked over
+End Rem
+Function TimerTicks:Int( timer:TTimer )
+	Return timer.Ticks()
+End Function
+
+Rem
+bbdoc: Wait until a timer ticks
+returns: The number of ticks since the last call to #WaitTimer
+End Rem
+Function WaitTimer:Int( timer:TTimer )
+	Return timer.Wait()
+End Function
+
+Rem
+bbdoc: Stop a timer
+about:Once stopped, a timer can no longer be used.
+End Rem
+Function StopTimer( timer:TTimer )
+	timer.Stop
+End Function
+
+SDL_InitSubSystem(SDL_INIT_TIMER)