demOS

- Main Page
- Modules
- Data Structures
- Files

- File List

All Data Structures Files Modules Pages
FSM.H
Go to the documentation of this file.
1 /*------------------------------------------------------------------------------ -----------------
2 Copyright J.Hubert 2015
3
4 This file is part of demOS
5
6 demOS is free software: you can redistribute it and/or modify it under the terms of
7 the GNU Lesser General Public License as published by the Free Software Foundation,
8 either version 3 of the License, or (at your option) any later version.
9
10 demOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY ;
11 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 See the GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License along with demOS.
15 If not, see <http://www.gnu.org/licenses/>.
16 ------------------------------------------------------------------------------------------------- */
17
26 #ifndef FSM_H
27 #define FSM_H
28
29 #include "DEMOSDK\BASTYPES.H"
30
31 STRUCT(FSM)
32 {
33 struct FSMstate_* states;
34 u16 nbStates;
35 u16 activeState;
36
37 # ifdef DEMOS_DEBUG
38 char trace[40];
39 s16 traceCurrent;
40 u16 traceLastState;
41 # endif
42 };
43
44 typedef void (*FSMfunction)(FSM* _fsm);
45
46 STRUCT(FSMstate)
47 {
48 FSMfunction entryAction;
49 FSMfunction activity;
50 FSMfunction exitAction;
51 };
52
53 void FSMinit (FSM* _m, FSMstate* _states, u16 _nbStates, u16 _startState);
54 void FSMupdate (FSM* _m);
55 void FSMgoto (FSM* _m, u16 _newState);
56
57 #define FSMgotoNextState(FSM) FSMgoto((FSM),(FSM)->activeState+1)
58 #define FSMgetCurrentState(FSM) (FSM)->activeState
59 #define FSMisLastState(FSM) (((FSM)->activeState+1) == (FSM)->nbStates)
60
61 #ifdef DEMOS_DEBUG
62 u16 FSMtrace (FSM* _fsm, void* _image, u16 _pitch, u16 _planePitch, u16 _y);
63 #endif
64
65 #endif
FSM
Definition: FSM.H:31
FSMstate
Definition: FSM.H:46
BASTYPES.H
BASTYPES