summaryrefslogtreecommitdiffstats
path: root/source/input.c
blob: c270e6b0c3a2ad5711d0078257a100f9c4419368 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* unofficial gameplaySP kai
 *
 * Copyright (C) 2006 Exophase <exophase@gmail.com>
 * Copyright (C) 2007 takka <takka@tfact.net>
 * Copyright (C) 2007 ????? <?????>
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include "common.h"

void trigger_key(uint32_t key);

void trigger_key(uint32_t key)
{
  uint32_t p1_cnt = io_registers[REG_P1CNT];

  if((p1_cnt >> 14) & 0x01)
  {
    uint32_t key_intersection = (p1_cnt & key) & 0x3FF;

    if(p1_cnt >> 15)
    {
      if(key_intersection == (p1_cnt & 0x3FF))
        raise_interrupt(IRQ_KEYPAD);
    }
    else
    {
      if(key_intersection)
        raise_interrupt(IRQ_KEYPAD);
    }
  }
}

// These are the last keys pressed, in the GBA bitfield format.
// They are stored in saved states.
uint32_t key = 0;

uint32_t rapidfire_flag = 1;
// 仿真过程输入

uint32_t update_input()
{
	enum ReGBA_Buttons new_key = ReGBA_GetPressedButtons();
	
	if (new_key & REGBA_BUTTON_MENU)
	{
		return ReGBA_Menu(REGBA_MENU_ENTRY_REASON_MENU_KEY);
	}

	bool RapidFireUsed = false;

	if (new_key & REGBA_BUTTON_RAPID_A)
	{
		if (rapidfire_flag) new_key |=  REGBA_BUTTON_A;
		else                new_key &= ~REGBA_BUTTON_A;

		RapidFireUsed = true;
	}

	if (new_key & REGBA_BUTTON_RAPID_B)
	{
		if (rapidfire_flag) new_key |=  REGBA_BUTTON_B;
		else                new_key &= ~REGBA_BUTTON_B;

		RapidFireUsed = true;
	}

	if (RapidFireUsed)
	{
		rapidfire_flag = !rapidfire_flag;
	}

	if((new_key | key) != key)
		trigger_key(new_key);

	key = new_key;
	io_registers[REG_P1] = (~key) & 0x3FF;

	return 0;
}

// type = READ / WRITE_MEM
#define input_savestate_body(type)                                            \
{                                                                             \
  FILE_##type##_VARIABLE(g_state_buffer_ptr, key);                            \
}                                                                             \

void input_read_mem_savestate()
input_savestate_body(READ_MEM)

void input_write_mem_savestate()
input_savestate_body(WRITE_MEM)