/* ----------------------------------------------- GTASC - GTA adaptation for TI Calculators ----------------------------------------------- Programmed by : Olivier SANGALA Version : 1.2 License : Free under GNU General Public License ( see "gpl.txt" ) Release Date : 05/01/2007 Platform : TI89/TI92+/V200 Website : http://olivier.sangala.free.fr Email : olivier_sangala@hotmail.com ---------- License ---------- Copyright (C) 2002-2007 Olivier SANGALA 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 2 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ //----------------------------------------------------------------------------- // From 'TICT Game Construction Kit' by Thomas Nussbaumer //-------------------------------------------------------------------------- // KBLIB FUNCTIONS //-------------------------------------------------------------------------- #include // Include All Header Files #include "kblib.h" //----------------------------------------------------------------------------- int KF_CALC_TYPE; INT_HANDLER IntHandler1_OLD; INT_HANDLER IntHandler5_OLD; short kb_state=0; short kb_state_OLD=0; short kb_state_DOWN=0; short kb_state_UP=0; //----------------------------------------------------------------------------- void WaitForAllKeysReleased(void) { while(GetKeyboardState()); } //----------------------------------------------------------------------------- void KB_Enable(void) { KF_CALC_TYPE = TI89?KF_TI89:TI92PLUS?KF_TI92PLUS:KF_V200; IntHandler1_OLD = GetIntVec(AUTO_INT_1); IntHandler5_OLD = GetIntVec(AUTO_INT_5); SetIntVec(AUTO_INT_1,DUMMY_HANDLER); SetIntVec(AUTO_INT_5,DUMMY_HANDLER/*IntHandler5*/); } //----------------------------------------------------------------------------- void KB_Disable(void) { SetIntVec (AUTO_INT_1,IntHandler1_OLD); SetIntVec (AUTO_INT_5,IntHandler5_OLD); } //----------------------------------------------------------------------------- short GetKeyboardState(void) { register unsigned char val; register short key = 0; if (KF_CALC_TYPE==KF_TI89) { val = _rowread(~(1<<0)); if (val & 0x01) key |= KEYFLAGS_UP; if (val & 0x02) key |= KEYFLAGS_LEFT; if (val & 0x04) key |= KEYFLAGS_DOWN; if (val & 0x08) key |= KEYFLAGS_RIGHT; if (val & 0x10) key |= KEYFLAGS_2ND; if (val & 0x20) key |= KEYFLAGS_SHIFT; if (val & 0x40) key |= KEYFLAGS_DIAMOND; if (val & 0x80) key |= KEYFLAGS_ALPHA; val = _rowread(~(1<<1)); if (val & 0x01) key |= KEYFLAGS_ENTER; if (val & 0x02) key |= KEYFLAGS_PLUS; if (val & 0x04) key |= KEYFLAGS_MINUS; val = _rowread(~(1<<6)); if (val & 0x01) key |= KEYFLAGS_ESC; } else if (KF_CALC_TYPE==KF_TI92PLUS || KF_CALC_TYPE==KF_V200) { // WARNING : unkwown matrix keys for V200 // supposed to be the same as TI92P // seems to work for following keys val = _rowread(~(1<<0)); if (val & 0x01) key |= KEYFLAGS_2ND; if (val & 0x02) key |= KEYFLAGS_DIAMOND; if (val & 0x04) key |= KEYFLAGS_SHIFT; if (val & 0x08) key |= KEYFLAGS_ALPHA; // = HAND (TI92PLUS) if (val & 0x10) key |= KEYFLAGS_LEFT; if (val & 0x20) key |= KEYFLAGS_UP; if (val & 0x40) key |= KEYFLAGS_RIGHT; if (val & 0x80) key |= KEYFLAGS_DOWN; val = _rowread(~(1<<6)); if (val & 0x40) key |= KEYFLAGS_ENTER; // ENTER2 val = _rowread(~(1<<8)); if (val & 0x10) key |= KEYFLAGS_PLUS; if (val & 0x40) key |= KEYFLAGS_ESC; val = _rowread(~(1<<9)); if (val & 0x01) key |= KEYFLAGS_MINUS; if (val & 0x02) key |= KEYFLAGS_ENTER; // ENTER1 } // up / down keys kb_state=key; kb_state_DOWN = ((kb_state_OLD^kb_state) & ( kb_state)); kb_state_UP = ((kb_state_OLD^kb_state) & (~kb_state)); kb_state_OLD = kb_state; return key; } //----------------------------------------------------------------------------- void WaitForKeyDOWN(short Key) { do { GetKeyboardState(); } while (!(kb_state_DOWN&Key)); } //----------------------------------------------------------------------------- void WaitForKeyUP(short Key) { do { GetKeyboardState(); } while (!(kb_state_UP&Key)); } //-----------------------------------------------------------------------------