1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: demo_PadButton.cpp
4
5 Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain proprietary
8 information of Nintendo and/or its licensed developers and are protected by
9 national and international copyright laws. They may not be disclosed to third
10 parties or copied or duplicated in any form, in whole or in part, without the
11 prior written consent of Nintendo.
12
13 The content herein is highly confidential and should be handled accordingly.
14
15 $Revision: $
16 *---------------------------------------------------------------------------*/
17
18 #include <nw/demo/demo_PadButton.h>
19 #include <algorithm>
20
21 namespace nw {
22 namespace demo {
23 namespace internal {
24
25 //--------------------------------------------------------------------------
PadButton()26 PadButton::PadButton()
27 {
28 Reset();
29 }
30
31 //--------------------------------------------------------------------------
32 void
Update(u32 buttonStatus)33 PadButton::Update( u32 buttonStatus )
34 {
35 if ( m_ResetFlag )
36 {
37 m_ButtonDown = m_ButtonUp = m_ButtonRepeat = m_ButtonRepeatFast = 0;
38 m_ResetFlag = false;
39 }
40 else
41 {
42 m_ButtonDown = ( m_ButtonPress ^ buttonStatus ) & buttonStatus;
43 m_ButtonUp = ( m_ButtonPress ^ buttonStatus ) & m_ButtonPress;
44 m_ButtonRepeat = m_ButtonDown;
45 m_ButtonRepeatFast = m_ButtonDown;
46 }
47 m_ButtonPress = buttonStatus;
48
49 u32 mask = 1;
50 for ( int i = 0; i < BUTTON_COUNT_MAX; ++i, mask <<= 1 )
51 {
52 if ( m_ButtonPress & mask )
53 {
54 --m_RepeatCounter[ i ];
55 --m_RepeatCounterFast[ i ];
56
57 if ( m_RepeatCounter[ i ] == 0 )
58 {
59 m_ButtonRepeat |= mask;
60 m_RepeatCounter[ i ] = REPEAT_SPAN;
61 }
62 if ( m_RepeatCounterFast[ i ] == 0 )
63 {
64 m_ButtonRepeatFast |= mask;
65 m_RepeatCounterFast[ i ] = 1;
66 }
67 }
68 else
69 {
70 m_RepeatCounter[ i ] = REPEAT_START;
71 m_RepeatCounterFast[ i ] = REPEAT_START;
72 }
73 }
74 }
75
76 //--------------------------------------------------------------------------
77 void
Reset()78 PadButton::Reset()
79 {
80 m_ResetFlag = true;
81
82 m_ButtonPress = 0;
83 m_ButtonDown = 0;
84 m_ButtonUp = 0;
85 m_ButtonRepeat = 0;
86 m_ButtonRepeatFast = 0;
87
88 std::fill_n(m_RepeatCounter, BUTTON_COUNT_MAX, static_cast<u8>(REPEAT_START));
89 std::fill_n(m_RepeatCounterFast, BUTTON_COUNT_MAX, static_cast<u8>(REPEAT_START));
90 }
91
92 //--------------------------------------------------------------------------
93 void
ClearTriggerFlag()94 PadButton::ClearTriggerFlag()
95 {
96 m_ButtonDown = 0;
97 m_ButtonUp = 0;
98 m_ButtonRepeat = 0;
99 m_ButtonRepeatFast = 0;
100 }
101
102 } // namespace nw::demo::internal
103 } // namespace nw::demo
104 } // namespace nw
105