--[[
 *
 *  Singe 2
 *  Copyright (C) 2006-2024 Scott Duensing <scott@kangaroopunch.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 *
 *
--]]


-- Singe 2.xx Features -------------------------------------------------------


SINGE_FRAMEWORK_VERSION = 2.10

if singeGetScriptPath ~= nil then
	DIR = singeGetScriptPath():match("(.*[/\\])") or "./"
end


function utilDeepCopy(orig)
	local orig_type = type(orig)
	local copy
	if orig_type == 'table' then
		copy = {}
		for orig_key, orig_value in next, orig, nil do
			copy[utilDeepCopy(orig_key)] = utilDeepCopy(orig_value)
		end
		setmetatable(copy, utilDeepCopy(getmetatable(orig)))
	else -- number, string, boolean, etc
		copy = orig
	end
	return copy
end


function utilDump(o)
	if type(o) == 'table' then
		local s = '{ '
		for k,v in pairs(o) do
			if type(k) ~= 'number' then
				k = '"'..k..'"'
			end
			s = s .. '['..k..'] = ' .. utilDump(v) .. ','
		end
		return s .. '} '
	else
		return tostring(o)
	end
end


function utilGetTableSize(t)
   local count = 0
   for _, __ in pairs(t) do
      count = count + 1
   end
   return count
end


function utilTrim(s)
    return (s:gsub("^%s*(.-)%s*$", "%1"))
end


SCANCODE = {
	A = { name = "A", value = 4 },
	B = { name = "B", value = 5 },
	C = { name = "C", value = 6 },
	D = { name = "D", value = 7 },
	E = { name = "E", value = 8 },
	F = { name = "F", value = 9 },
	G = { name = "G", value = 10 },
	H = { name = "H", value = 11 },
	I = { name = "I", value = 12 },
	J = { name = "J", value = 13 },
	K = { name = "K", value = 14 },
	L = { name = "L", value = 15 },
	M = { name = "M", value = 16 },
	N = { name = "N", value = 17 },
	O = { name = "O", value = 18 },
	P = { name = "P", value = 19 },
	Q = { name = "Q", value = 20 },
	R = { name = "R", value = 21 },
	S = { name = "S", value = 22 },
	T = { name = "T", value = 23 },
	U = { name = "U", value = 24 },
	V = { name = "V", value = 25 },
	W = { name = "W", value = 26 },
	X = { name = "X", value = 27 },
	Y = { name = "Y", value = 28 },
	Z = { name = "Z", value = 29 },
	MAIN_1 = { name = "MAIN_1", value = 30 },
	MAIN_2 = { name = "MAIN_2", value = 31 },
	MAIN_3 = { name = "MAIN_3", value = 32 },
	MAIN_4 = { name = "MAIN_4", value = 33 },
	MAIN_5 = { name = "MAIN_5", value = 34 },
	MAIN_6 = { name = "MAIN_6", value = 35 },
	MAIN_7 = { name = "MAIN_7", value = 36 },
	MAIN_8 = { name = "MAIN_8", value = 37 },
	MAIN_9 = { name = "MAIN_9", value = 38 },
	MAIN_0 = { name = "MAIN_0", value = 39 },
	RETURN = { name = "RETURN", value = 40 },
	ESCAPE = { name = "ESCAPE", value = 41 },
	BACKSPACE = { name = "BACKSPACE", value = 42 },
	TAB = { name = "TAB", value = 43 },
	SPACE = { name = "SPACE", value = 44 },
	MINUS = { name = "MINUS", value = 45 },
	EQUALS = { name = "EQUALS", value = 46 },
	LEFTBRACKET = { name = "LEFTBRACKET", value = 47 },
	RIGHTBRACKET = { name = "RIGHTBRACKET", value = 48 },
	BACKSLASH = { name = "BACKSLASH", value = 49 },
	NONUSHASH = { name = "NONUSHASH", value = 50 },
	SEMICOLON = { name = "SEMICOLON", value = 51 },
	APOSTROPHE = { name = "APOSTROPHE", value = 52 },
	GRAVE = { name = "GRAVE", value = 53 },
	COMMA = { name = "COMMA", value = 54 },
	PERIOD = { name = "PERIOD", value = 55 },
	SLASH = { name = "SLASH", value = 56 },
	CAPSLOCK = { name = "CAPSLOCK", value = 57 },
	F1 = { name = "F1", value = 58 },
	F2 = { name = "F2", value = 59 },
	F3 = { name = "F3", value = 60 },
	F4 = { name = "F4", value = 61 },
	F5 = { name = "F5", value = 62 },
	F6 = { name = "F6", value = 63 },
	F7 = { name = "F7", value = 64 },
	F8 = { name = "F8", value = 65 },
	F9 = { name = "F9", value = 66 },
	F10 = { name = "F10", value = 67 },
	F11 = { name = "F11", value = 68 },
	F12 = { name = "F12", value = 69 },
	PRINTSCREEN = { name = "PRINTSCREEN", value = 70 },
	SCROLLLOCK = { name = "SCROLLLOCK", value = 71 },
	PAUSE = { name = "PAUSE", value = 72 },
	INSERT = { name = "INSERT", value = 73 },
	HOME = { name = "HOME", value = 74 },
	PAGEUP = { name = "PAGEUP", value = 75 },
	DELETE = { name = "DELETE", value = 76 },
	END = { name = "END", value = 77 },
	PAGEDOWN = { name = "PAGEDOWN", value = 78 },
	RIGHT = { name = "RIGHT", value = 79 },
	LEFT = { name = "LEFT", value = 80 },
	DOWN = { name = "DOWN", value = 81 },
	UP = { name = "UP", value = 82 },
	NUMLOCKCLEAR = { name = "NUMLOCKCLEAR", value = 83 },
	KP_DIVIDE = { name = "KP_DIVIDE", value = 84 },
	KP_MULTIPLY = { name = "KP_MULTIPLY", value = 85 },
	KP_MINUS = { name = "KP_MINUS", value = 86 },
	KP_PLUS = { name = "KP_PLUS", value = 87 },
	KP_ENTER = { name = "KP_ENTER", value = 88 },
	KP_1 = { name = "KP_1", value = 89 },
	KP_2 = { name = "KP_2", value = 90 },
	KP_3 = { name = "KP_3", value = 91 },
	KP_4 = { name = "KP_4", value = 92 },
	KP_5 = { name = "KP_5", value = 93 },
	KP_6 = { name = "KP_6", value = 94 },
	KP_7 = { name = "KP_7", value = 95 },
	KP_8 = { name = "KP_8", value = 96 },
	KP_9 = { name = "KP_9", value = 97 },
	KP_0 = { name = "KP_0", value = 98 },
	KP_PERIOD = { name = "KP_PERIOD", value = 99 },
	NONUSBACKSLASH = { name = "NONUSBACKSLASH", value = 100 },
	APPLICATION = { name = "APPLICATION", value = 101 },
	POWER = { name = "POWER", value = 102 },
	KP_EQUALS = { name = "KP_EQUALS", value = 103 },
	F13 = { name = "F13", value = 104 },
	F14 = { name = "F14", value = 105 },
	F15 = { name = "F15", value = 106 },
	F16 = { name = "F16", value = 107 },
	F17 = { name = "F17", value = 108 },
	F18 = { name = "F18", value = 109 },
	F19 = { name = "F19", value = 110 },
	F20 = { name = "F20", value = 111 },
	F21 = { name = "F21", value = 112 },
	F22 = { name = "F22", value = 113 },
	F23 = { name = "F23", value = 114 },
	F24 = { name = "F24", value = 115 },
	EXECUTE = { name = "EXECUTE", value = 116 },
	HELP = { name = "HELP", value = 117 },
	MENU = { name = "MENU", value = 118 },
	SELECT = { name = "SELECT", value = 119 },
	STOP = { name = "STOP", value = 120 },
	AGAIN = { name = "AGAIN", value = 121 },
	UNDO = { name = "UNDO", value = 122 },
	CUT = { name = "CUT", value = 123 },
	COPY = { name = "COPY", value = 124 },
	PASTE = { name = "PASTE", value = 125 },
	FIND = { name = "FIND", value = 126 },
	MUTE = { name = "MUTE", value = 127 },
	VOLUMEUP = { name = "VOLUMEUP", value = 128 },
	VOLUMEDOWN = { name = "VOLUMEDOWN", value = 129 },
	KP_COMMA = { name = "KP_COMMA", value = 133 },
	KP_EQUALSAS400 = { name = "KP_EQUALSAS400", value = 134 },
	INTERNATIONAL1 = { name = "INTERNATIONAL1", value = 135 },
	INTERNATIONAL2 = { name = "INTERNATIONAL2", value = 136 },
	INTERNATIONAL3 = { name = "INTERNATIONAL3", value = 137 },
	INTERNATIONAL4 = { name = "INTERNATIONAL4", value = 138 },
	INTERNATIONAL5 = { name = "INTERNATIONAL5", value = 139 },
	INTERNATIONAL6 = { name = "INTERNATIONAL6", value = 140 },
	INTERNATIONAL7 = { name = "INTERNATIONAL7", value = 141 },
	INTERNATIONAL8 = { name = "INTERNATIONAL8", value = 142 },
	INTERNATIONAL9 = { name = "INTERNATIONAL9", value = 143 },
	LANG1 = { name = "LANG1", value = 144 },
	LANG2 = { name = "LANG2", value = 145 },
	LANG3 = { name = "LANG3", value = 146 },
	LANG4 = { name = "LANG4", value = 147 },
	LANG5 = { name = "LANG5", value = 148 },
	LANG6 = { name = "LANG6", value = 149 },
	LANG7 = { name = "LANG7", value = 150 },
	LANG8 = { name = "LANG8", value = 151 },
	LANG9 = { name = "LANG9", value = 152 },
	ALTERASE = { name = "ALTERASE", value = 153 },
	SYSREQ = { name = "SYSREQ", value = 154 },
	CANCEL = { name = "CANCEL", value = 155 },
	CLEAR = { name = "CLEAR", value = 156 },
	PRIOR = { name = "PRIOR", value = 157 },
	RETURN2 = { name = "RETURN2", value = 158 },
	SEPARATOR = { name = "SEPARATOR", value = 159 },
	OUT = { name = "OUT", value = 160 },
	OPER = { name = "OPER", value = 161 },
	CLEARAGAIN = { name = "CLEARAGAIN", value = 162 },
	CRSEL = { name = "CRSEL", value = 163 },
	EXSEL = { name = "EXSEL", value = 164 },
	KP_00 = { name = "KP_00", value = 176 },
	KP_000 = { name = "KP_000", value = 177 },
	THOUSANDSSEPARATOR = { name = "THOUSANDSSEPARATOR", value = 178 },
	DECIMALSEPARATOR = { name = "DECIMALSEPARATOR", value = 179 },
	CURRENCYUNIT = { name = "CURRENCYUNIT", value = 180 },
	CURRENCYSUBUNIT = { name = "CURRENCYSUBUNIT", value = 181 },
	KP_LEFTPAREN = { name = "KP_LEFTPAREN", value = 182 },
	KP_RIGHTPAREN = { name = "KP_RIGHTPAREN", value = 183 },
	KP_LEFTBRACE = { name = "KP_LEFTBRACE", value = 184 },
	KP_RIGHTBRACE = { name = "KP_RIGHTBRACE", value = 185 },
	KP_TAB = { name = "KP_TAB", value = 186 },
	KP_BACKSPACE = { name = "KP_BACKSPACE", value = 187 },
	KP_A = { name = "KP_A", value = 188 },
	KP_B = { name = "KP_B", value = 189 },
	KP_C = { name = "KP_C", value = 190 },
	KP_D = { name = "KP_D", value = 191 },
	KP_E = { name = "KP_E", value = 192 },
	KP_F = { name = "KP_F", value = 193 },
	KP_XOR = { name = "KP_XOR", value = 194 },
	KP_POWER = { name = "KP_POWER", value = 195 },
	KP_PERCENT = { name = "KP_PERCENT", value = 196 },
	KP_LESS = { name = "KP_LESS", value = 197 },
	KP_GREATER = { name = "KP_GREATER", value = 198 },
	KP_AMPERSAND = { name = "KP_AMPERSAND", value = 199 },
	KP_DBLAMPERSAND = { name = "KP_DBLAMPERSAND", value = 200 },
	KP_VERTICALBAR = { name = "KP_VERTICALBAR", value = 201 },
	KP_DBLVERTICALBAR = { name = "KP_DBLVERTICALBAR", value = 202 },
	KP_COLON = { name = "KP_COLON", value = 203 },
	KP_HASH = { name = "KP_HASH", value = 204 },
	KP_SPACE = { name = "KP_SPACE", value = 205 },
	KP_AT = { name = "KP_AT", value = 206 },
	KP_EXCLAM = { name = "KP_EXCLAM", value = 207 },
	KP_MEMSTORE = { name = "KP_MEMSTORE", value = 208 },
	KP_MEMRECALL = { name = "KP_MEMRECALL", value = 209 },
	KP_MEMCLEAR = { name = "KP_MEMCLEAR", value = 210 },
	KP_MEMADD = { name = "KP_MEMADD", value = 211 },
	KP_MEMSUBTRACT = { name = "KP_MEMSUBTRACT", value = 212 },
	KP_MEMMULTIPLY = { name = "KP_MEMMULTIPLY", value = 213 },
	KP_MEMDIVIDE = { name = "KP_MEMDIVIDE", value = 214 },
	KP_PLUSMINUS = { name = "KP_PLUSMINUS", value = 215 },
	KP_CLEAR = { name = "KP_CLEAR", value = 216 },
	KP_CLEARENTRY = { name = "KP_CLEARENTRY", value = 217 },
	KP_BINARY = { name = "KP_BINARY", value = 218 },
	KP_OCTAL = { name = "KP_OCTAL", value = 219 },
	KP_DECIMAL = { name = "KP_DECIMAL", value = 220 },
	KP_HEXADECIMAL = { name = "KP_HEXADECIMAL", value = 221 },
	LCTRL = { name = "LCTRL", value = 224 },
	LSHIFT = { name = "LSHIFT", value = 225 },
	LALT = { name = "LALT", value = 226 },
	LGUI = { name = "LGUI", value = 227 },
	RCTRL = { name = "RCTRL", value = 228 },
	RSHIFT = { name = "RSHIFT", value = 229 },
	RALT = { name = "RALT", value = 230 },
	RGUI = { name = "RGUI", value = 231 },
	MODE = { name = "MODE", value = 257 },
	AUDIONEXT = { name = "AUDIONEXT", value = 258 },
	AUDIOPREV = { name = "AUDIOPREV", value = 259 },
	AUDIOSTOP = { name = "AUDIOSTOP", value = 260 },
	AUDIOPLAY = { name = "AUDIOPLAY", value = 261 },
	AUDIOMUTE = { name = "AUDIOMUTE", value = 262 },
	MEDIASELECT = { name = "MEDIASELECT", value = 263 },
	WWW = { name = "WWW", value = 264 },
	MAIL = { name = "MAIL", value = 265 },
	CALCULATOR = { name = "CALCULATOR", value = 266 },
	COMPUTER = { name = "COMPUTER", value = 267 },
	AC_SEARCH = { name = "AC_SEARCH", value = 268 },
	AC_HOME = { name = "AC_HOME", value = 269 },
	AC_BACK = { name = "AC_BACK", value = 270 },
	AC_FORWARD = { name = "AC_FORWARD", value = 271 },
	AC_STOP = { name = "AC_STOP", value = 272 },
	AC_REFRESH = { name = "AC_REFRESH", value = 273 },
	AC_BOOKMARKS = { name = "AC_BOOKMARKS", value = 274 },
	BRIGHTNESSDOWN = { name = "BRIGHTNESSDOWN", value = 275 },
	BRIGHTNESSUP = { name = "BRIGHTNESSUP", value = 276 },
	DISPLAYSWITCH = { name = "DISPLAYSWITCH", value = 277 },
	KBDILLUMTOGGLE = { name = "KBDILLUMTOGGLE", value = 278 },
	KBDILLUMDOWN = { name = "KBDILLUMDOWN", value = 279 },
	KBDILLUMUP = { name = "KBDILLUMUP", value = 280 },
	EJECT = { name = "EJECT", value = 281 },
	SLEEP = { name = "SLEEP", value = 282 },
	APP1 = { name = "APP1", value = 283 },
	APP2 = { name = "APP2", value = 284 },
	AUDIOREWIND = { name = "AUDIOREWIND", value = 285 },
	AUDIOFASTFORWARD = { name = "AUDIOFASTFORWARD", value = 286 }
}

SCANCODE_MIN = 4   -- Lowest value
SCANCODE_MAX = 286 -- Highest value, not the number of items in the table.

MODIFIER = {
	NONE   = { name = "NONE",   value = 0x0000 },
	LSHIFT = { name = "LSHIFT", value = 0x0001 },
	RSHIFT = { name = "RSHIFT", value = 0x0002 },
	LCTRL  = { name = "LCTRL",  value = 0x0040 },
	RCTRL  = { name = "RCTRL",  value = 0x0080 },
	LALT   = { name = "LALT",   value = 0x0100 },
	RALT   = { name = "RALT",   value = 0x0200 },
	LGUI   = { name = "LGUI",   value = 0x0400 },
	RGUI   = { name = "RGUI",   value = 0x0800 },
	NUM    = { name = "NUM",    value = 0x1000 },
	CAPS   = { name = "CAPS",   value = 0x2000 },
	MODE   = { name = "MODE",   value = 0x4000 },
	SCROLL = { name = "SCROLL", value = 0x8000 },

	SHIFT = { name = "SHIFT", value = 0x0001 + 0x0002 },
	CTRL  = { name = "CTRL",  value = 0x0040 + 0x0080 },
	ALT   = { name = "ALT",   value = 0x0100 + 0x0200 },
	GUI   = { name = "GUI",   value = 0x0400 + 0x0800 }
}

GAMEPAD_0 = {
	AXIS_LEFT_X = { name = "AXIS_LEFT_X", value = 500 },
	AXIS_LEFT_X_L = { name = "AXIS_LEFT_X_L", value = 501 },
	AXIS_LEFT_X_R = { name = "AXIS_LEFT_X_R", value = 502 },
	AXIS_LEFT_Y = { name = "AXIS_LEFT_Y", value = 503 },
	AXIS_LEFT_Y_U = { name = "AXIS_LEFT_Y_U", value = 504 },
	AXIS_LEFT_Y_D = { name = "AXIS_LEFT_Y_D", value = 505 },
	AXIS_RIGHT_X = { name = "AXIS_RIGHT_X", value = 506 },
	AXIS_RIGHT_X_L = { name = "AXIS_RIGHT_X_L", value = 507 },
	AXIS_RIGHT_X_R = { name = "AXIS_RIGHT_X_R", value = 508 },
	AXIS_RIGHT_Y = { name = "AXIS_RIGHT_Y", value = 509 },
	AXIS_RIGHT_Y_U = { name = "AXIS_RIGHT_Y_U", value = 510 },
	AXIS_RIGHT_Y_D = { name = "AXIS_RIGHT_Y_D", value = 511 },
	AXIS_LEFT_TRIGGER = { name = "AXIS_LEFT_TRIGGER", value = 512 },
	AXIS_LEFT_TRIGGER_N = { name = "AXIS_LEFT_TRIGGER_N", value = 513 },
	AXIS_LEFT_TRIGGER_P = { name = "AXIS_LEFT_TRIGGER_P", value = 514 },
	AXIS_RIGHT_TRIGGER = { name = "AXIS_RIGHT_TRIGGER", value = 515 },
	AXIS_RIGHT_TRIGGER_N = { name = "AXIS_RIGHT_TRIGGER_N", value = 516 },
	AXIS_RIGHT_TRIGGER_P = { name = "AXIS_RIGHT_TRIGGER_P", value = 517 },
	BUTTON_A = { name = "BUTTON_A", value = 518 },
	BUTTON_B = { name = "BUTTON_B", value = 519 },
	BUTTON_X = { name = "BUTTON_X", value = 520 },
	BUTTON_Y = { name = "BUTTON_Y", value = 521 },
	BUTTON_BACK = { name = "BUTTON_BACK", value = 522 },
	BUTTON_GUIDE = { name = "BUTTON_GUIDE", value = 523 },
	BUTTON_START = { name = "BUTTON_START", value = 524 },
	BUTTON_LEFT_STICK = { name = "BUTTON_LEFT_STICK", value = 525 },
	BUTTON_RIGHT_STICK = { name = "BUTTON_RIGHT_STICK", value = 526 },
	BUTTON_LEFT_BUMPER = { name = "BUTTON_LEFT_BUMPER", value = 527 },
	BUTTON_RIGHT_BUMPER = { name = "BUTTON_RIGHT_BUMPER", value = 528 },
	DPAD_UP = { name = "DPAD_UP", value = 529 },
	DPAD_DOWN = { name = "DPAD_DOWN", value = 530 },
	DPAD_LEFT = { name = "DPAD_LEFT", value = 531 },
	DPAD_RIGHT = { name = "DPAD_RIGHT", value = 532 }
}

GAMEPAD_0_MIN = 500 -- Lowest value
GAMEPAD_0_MAX = 532 -- Highest value, not the number of items in the table.

GAMEPAD_1 = utilDeepCopy(GAMEPAD_0)
GAMEPAD_2 = utilDeepCopy(GAMEPAD_0)
GAMEPAD_3 = utilDeepCopy(GAMEPAD_0)

for key, value in pairs(GAMEPAD_0) do
	GAMEPAD_1[key].value  = GAMEPAD_1[key].value + 100
	GAMEPAD_2[key].value  = GAMEPAD_2[key].value + 200
	GAMEPAD_3[key].value  = GAMEPAD_3[key].value + 300
end

GAMEPAD_1_MIN = GAMEPAD_0_MAX + 100
GAMEPAD_1_MAX = GAMEPAD_0_MAX + 100

GAMEPAD_2_MIN = GAMEPAD_0_MAX + 200
GAMEPAD_2_MAX = GAMEPAD_0_MAX + 200

GAMEPAD_3_MIN = GAMEPAD_0_MAX + 300
GAMEPAD_3_MAX = GAMEPAD_0_MAX + 300

GAMEPAD_AXIS_LEFT_X        = 0
GAMEPAD_AXIS_LEFT_Y        = 1
GAMEPAD_AXIS_RIGHT_X       = 2
GAMEPAD_AXIS_RIGHT_Y       = 3
GAMEPAD_AXIS_LEFT_TRIGGER  = 4
GAMEPAD_AXIS_RIGHT_TRIGGER = 5

MOUSE_0 = {
	BUTTON_LEFT = { name = "BUTTON_LEFT", value = 1000 },
	BUTTON_RIGHT = { name = "BUTTON_RIGHT", value = 1001 },
	BUTTON_MIDDLE = { name = "BUTTON_MIDDLE", value = 1002 },
	BUTTON_X1 = { name = "BUTTON_X1", value = 1003 },
	BUTTON_X2 = { name = "BUTTON_X2", value = 1004 },
	WHEEL_UP = { name = "WHEEL_UP", value = 1005 },
	WHEEL_DOWN = { name = "WHEEL_DOWN", value = 1006 }
}

MOUSE_0_MIN = 1000
MOUSE_0_MAX = 1006

MOUSE_1 = utilDeepCopy(MOUSE_0)
MOUSE_2 = utilDeepCopy(MOUSE_0)
MOUSE_3 = utilDeepCopy(MOUSE_0)

for key, value in pairs(MOUSE_0) do
	MOUSE_1[key].value  = MOUSE_1[key].value + 100
	MOUSE_2[key].value  = MOUSE_2[key].value + 200
	MOUSE_3[key].value  = MOUSE_3[key].value + 300
end

MOUSE_1_MIN = MOUSE_0_MAX + 100
MOUSE_1_MAX = MOUSE_0_MAX + 100

MOUSE_2_MIN = MOUSE_0_MAX + 200
MOUSE_2_MAX = MOUSE_0_MAX + 200

MOUSE_3_MIN = MOUSE_0_MAX + 300
MOUSE_3_MAX = MOUSE_0_MAX + 300

SWITCH_BUTTON4    = 21
SWITCH_TILT       = 22
SWITCH_GRAB       = 23

MOUSE_SINGLE = 100
MOUSE_MANY   = 200

RENDER_SMOOTH    = 1
RENDER_PIXELATED = 0

if videoGetLanguageDescription ~= nil then
	discGetLanguageDescription = videoGetLanguageDescription
end


-- Singe 1.xx Features -------------------------------------------------------


if discSetFPS ~= nil then
	discSetFPS(MovieFPS)
	discSearch(1)
end

SWITCH_UP         =  0
SWITCH_LEFT       =  1
SWITCH_DOWN       =  2
SWITCH_RIGHT      =  3
SWITCH_START1     =  4
SWITCH_START2     =  5
SWITCH_BUTTON1    =  6
SWITCH_BUTTON2    =  7
SWITCH_BUTTON3    =  8
SWITCH_COIN1      =  9
SWITCH_COIN2      = 10
SWITCH_SKILL1     = 11
SWITCH_SKILL2     = 12
SWITCH_SKILL3     = 13
SWITCH_SERVICE    = 14
SWITCH_TEST       = 15
SWITCH_RESET      = 16
SWITCH_SCREENSHOT = 17
SWITCH_QUIT       = 18
SWITCH_PAUSE      = 19
SWITCH_CONSOLE    = 20
SWITCH_BUTTON4    = 21  -- Added in Singe 2.00
SWITCH_TILT       = 22  -- Added in Singe 2.00

FONT_QUALITY_SOLID   = 1
FONT_QUALITY_SHADED  = 2
FONT_QUALITY_BLENDED = 3

SOUND_ERROR_INVALID = -1
SOUND_REMOVE_HANDLE = -1
SOUND_ERROR_FULL    = -2

OVERLAY_NOT_UPDATED = 0
OVERLAY_UPDATED     = 1

SINGLE_MOUSE = 100
MANY_MOUSE   = 200

MODE_NORMAL = 0
MODE_FULL   = 1

-- Make old random number calls still work
random = {}
random.new = math.random

-- Map old Daphne calls to Singe calls
if singeGetHeight ~= nil then
	daphneGetHeight  = singeGetHeight
	daphneGetWidth   = singeGetWidth
	daphneScreenshot = singeScreenshot
end


-- Singe 2.10 Threaded Application Support ------------------------------------


if singeMain ~= nil then
	onOverlayUpdate = function()
		coroutine.resume(SINGE_SELF)
		return(OVERLAY_UPDATED)
	end
	singeYield = coroutine.yield
	SINGE_SELF = coroutine.create(singeMain)
end


