19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL - Simple DirectMedia Layer 39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Copyright (C) 1997-2012 Sam Lantinga 49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is free software; you can redistribute it and/or 69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall modify it under the terms of the GNU Lesser General Public 79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License as published by the Free Software Foundation; either 89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall version 2.1 of the License, or (at your option) any later version. 99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is distributed in the hope that it will be useful, 119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall but WITHOUT ANY WARRANTY; without even the implied warranty of 129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Lesser General Public License for more details. 149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall You should have received a copy of the GNU Lesser General Public 169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License along with this library; if not, write to the Free Software 179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Sam Lantinga 209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall slouken@libsdl.org 219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/ 229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h" 239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Atari keyboard events manager, using hardware IKBD 269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Patrice Mandin 289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Mint includes */ 319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <mint/osbind.h> 329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../../events/SDL_sysevents.h" 349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../../events/SDL_events_c.h" 359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_atarikeys.h" 379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_atarievents_c.h" 389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_ikbdinterrupt_s.h" 399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define KEY_PRESSED 0xff 419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define KEY_UNDEFINED 0x80 429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define KEY_RELEASED 0x00 439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic Uint16 atari_prevmouseb; /* save state of mouse buttons */ 459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid AtariIkbd_InitOSKeymap(_THIS) 479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memset((void *) SDL_AtariIkbd_keyboard, KEY_UNDEFINED, sizeof(SDL_AtariIkbd_keyboard)); 499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Now install our handler */ 519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_AtariIkbd_mouseb = SDL_AtariIkbd_mousex = SDL_AtariIkbd_mousey = 0; 529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall atari_prevmouseb = 0; 539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Supexec(SDL_AtariIkbdInstall); 559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int atari_GetButton(int button) 589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall switch(button) 609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case 0: 629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return SDL_BUTTON_RIGHT; 639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case 1: 659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall default: 669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return SDL_BUTTON_LEFT; 679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid AtariIkbd_PumpEvents(_THIS) 729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int i; 749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_keysym keysym; 759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /*--- Send keyboard events ---*/ 779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for (i=0; i<ATARIBIOS_MAXKEYS; i++) { 799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Key pressed ? */ 809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (SDL_AtariIkbd_keyboard[i]==KEY_PRESSED) { 819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateKeyboard(SDL_PRESSED, 829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE)); 839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_AtariIkbd_keyboard[i]=KEY_UNDEFINED; 849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Key released ? */ 879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (SDL_AtariIkbd_keyboard[i]==KEY_RELEASED) { 889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateKeyboard(SDL_RELEASED, 899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Atari_TranslateKey(i, &keysym, SDL_FALSE)); 909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_AtariIkbd_keyboard[i]=KEY_UNDEFINED; 919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /*--- Send mouse events ---*/ 959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Mouse motion ? */ 979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (SDL_AtariIkbd_mousex || SDL_AtariIkbd_mousey) { 989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateMouseMotion(0, 1, SDL_AtariIkbd_mousex, SDL_AtariIkbd_mousey); 999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_AtariIkbd_mousex = SDL_AtariIkbd_mousey = 0; 1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Mouse button ? */ 1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (SDL_AtariIkbd_mouseb != atari_prevmouseb) { 1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for (i=0;i<2;i++) { 1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int curbutton, prevbutton; 1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall curbutton = SDL_AtariIkbd_mouseb & (1<<i); 1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall prevbutton = atari_prevmouseb & (1<<i); 1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (curbutton && !prevbutton) { 1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateMouseButton(SDL_PRESSED, atari_GetButton(i), 0, 0); 1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (!curbutton && prevbutton) { 1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateMouseButton(SDL_RELEASED, atari_GetButton(i), 0, 0); 1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall atari_prevmouseb = SDL_AtariIkbd_mouseb; 1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid AtariIkbd_ShutdownEvents(void) 1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Supexec(SDL_AtariIkbdUninstall); 1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 125