2
gba_input.pas 01/09/2006 19.57.16
3
------------------------------------------------------------------------------
4
This lib is a raw porting of libgba library for gba (you can find it at
5
http://www.devkitpro.org).
7
As this is a direct port from c, I'm pretty sure that something could not work
8
as you expect. I am even more sure that this code could be written better, so
9
if you think that I have made some mistakes or you have some better
10
implemented functions, let me know [francky74 (at) gmail (dot) com]
13
Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
14
(http://www.freepascal.org)
16
Copyright (C) 2006 Francesco Lombardi
18
This library is free software; you can redistribute it and/or
19
modify it under the terms of the GNU Lesser General Public
20
License as published by the Free Software Foundation; either
21
version 2.1 of the License, or (at your option) any later version.
23
This library is distributed in the hope that it will be useful,
24
but WITHOUT ANY WARRANTY; without even the implied warranty of
25
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26
Lesser General Public License for more details.
28
You should have received a copy of the GNU Lesser General Public
29
License along with this library; if not, write to the Free Software
30
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
31
------------------------------------------------------------------------------
43
KEY_A: TKeyPadBits = (1 shl 0);
44
KEY_B: TKeyPadBits = (1 shl 1);
45
KEY_SELECT: TKeyPadBits = (1 shl 2);
46
KEY_START: TKeyPadBits = (1 shl 3);
47
KEY_RIGHT: TKeyPadBits = (1 shl 4);
48
KEY_LEFT: TKeyPadBits = (1 shl 5);
49
KEY_UP: TKeyPadBits = (1 shl 6);
50
KEY_DOWN: TKeyPadBits = (1 shl 7);
51
KEY_R: TKeyPadBits = (1 shl 8);
52
KEY_L: TKeyPadBits = (1 shl 9);
54
KEYIRQ_ENABLE: TKeyPadBits = (1 shl 14);
55
KEYIRQ_OR: TKeyPadBits = (0 shl 15);
56
KEYIRQ_AND: TKeyPadBits = (1 shl 15);
57
DPAD: TKeyPadBits = (1 shl 6) or (1 shl 7) or (1 shl 5) or (1 shl 4);
62
KeyInput = packed record
70
//---------------------------------------------------------------------------------
72
//---------------------------------------------------------------------------------
81
function KeysDown(): word;
82
function KeysDownRepeat(): word;
83
function KeysUp(): word;
84
function KeysHeld(): word;
85
procedure SetRepeat(SetDelay, SetRepeat: integer);
92
procedure SetRepeat(SetDelay, SetRepeat: integer);
98
//---------------------------------------------------------------------------------
101
pressed, released: word;
103
Keys.Last := Keys.Held;
104
Keys.Held := (REG_KEYINPUT^ and $03ff) xor $03ff; // upper 6 bits clear on hw not emulated
107
pressed := Keys.Held and ( Keys.Last xor $03ff);
109
Keys.DownRepeat := Keys.DownRepeat or pressed;
110
Keys.Down := Keys.Down or pressed;
113
released := ((Keys.Held xor $03ff) and Keys.Last);
115
Keys.Up := Keys.Up or released;
117
Keys.Down := Keys.Down and not released;
118
Keys.DownRepeat := Keys.DownRepeat and not released;
120
Keys.Up := Keys.Up and not pressed;
122
if ( Keys.Last <> Keys.Held) then
126
if ( delay <> 0) then
132
Keys.DownRepeat := Keys.DownRepeat or Keys.Held;
137
function KeysDownRepeat(): word;
141
tmp := Keys.DownRepeat;
142
Keys.DownRepeat := 0;
144
KeysDownRepeat := tmp;
147
function KeysDown(): word;
157
function KeysUp(): word;
167
function KeysHeld(): word;
169
KeysHeld := Keys.Held;