-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtsk_mm.ks
156 lines (133 loc) · 3.46 KB
/
rtsk_mm.ks
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
////////////////////////////////////////////////////////////////////////////////
// RTSK SOFTWARE MODE MANAGEMENT
////////////////////////////////////////////////////////////////////////////////
// CURRENT SOFTWARE MODE
GLOBAL MAJOR_MODE TO 0.
GLOBAL MINOR_MODE TO 0.
// PREVIOUS SOFTWARE MODE
GLOBAL PREVIOUS_MAJOR_MODE TO 0.
GLOBAL PREVIOUS_MINOR_MODE TO 0.
// LIST OF MAJOR MODES
GLOBAL MODES_TASKLIST TO LEXICON().
// LIST OF MAJOR MODE TRANSFER FUNCTIONS
GLOBAL MODES_ENTER TO LEXICON().
GLOBAL MODES_LEAVE TO LEXICON().
GLOBAL MODES_TRANSFER TO LEXICON().
GLOBAL MODES_COMMAND TO LEXICON().
// TIME SINCE MODE WAS INITIALIZED
GLOBAL MODE_TIMER_START TO TIME:SECONDS.
FUNCTION MODE_TIMER {
RETURN TIME:SECONDS - MODE_TIMER_START.
}
//
// REGISTER AN EXTRA TASK TO BE LOADED WHEN SWITCHING MAJOR MODE
//
FUNCTION MODE_TASK {
PARAMETER MAJOR, TASK.
// ADD NEW MAJOR MODE
IF NOT MODES_TASKLIST:HASKEY(MAJOR) {
MODES_TASKLIST:ADD(MAJOR, LIST()).
}
// ADD TASK TO THE TASKLIST
MODES_TASKLIST[MAJOR]:ADD(TASK).
}
//
// CALLED WHEN MAJOR MODE IS ENTERED
//
FUNCTION MODE_ENTER {
PARAMETER MAJOR, FUNC.
MODES_ENTER:ADD(MAJOR, FUNC).
}
//
// CALLED WHEN MAJOR MODE IS LEFT
//
FUNCTION MODE_LEAVE {
PARAMETER MAJOR, FUNC.
MODES_LEAVE:ADD(MAJOR, FUNC).
}
//
// CALLED WHEN MINOR MODE IS SWITCHED
//
FUNCTION MODE_TRANSFER {
PARAMETER MAJOR, FUNC.
MODES_TRANSFER:ADD(MAJOR, FUNC).
}
//
// CALLED WHEN MINOR MODE IS SWITCHED
//
FUNCTION MODE_COMMAND {
PARAMETER MAJOR, FUNC.
MODES_COMMAND:ADD(MAJOR, FUNC).
}
//
// CLEAR MODE SCREEN
//
FUNCTION RESET_DISPLAY {
CLEAR_MM().
SET UI_PREVIOUS_VALUES TO LEXICON().
}
//
// TRANSFER BETWEEN MODES
//
FUNCTION TRANSFER_MODE {
PARAMETER MAJOR, MINOR.
// REMEMBER PREVIOUS MODE
SET PREVIOUS_MAJOR_MODE TO MAJOR_MODE.
SET PREVIOUS_MINOR_MODE TO MINOR_MODE.
// CHECK IF MAJOR MODE CHANGED
IF MAJOR_MODE <> MAJOR {
// STOP ALL TASKS FROM THE OLD MODE
IF MODES_TASKLIST:HASKEY(MAJOR_MODE) {
FOR OLD_TASK IN MODES_TASKLIST[MAJOR_MODE] {
LOCAL INDEX IS 0.
UNTIL INDEX >= TASK_LIST:LENGTH {
LOCAL TASK IS TASK_LIST[INDEX].
IF TASK[3] = OLD_TASK {
TASK_LIST:REMOVE(INDEX).
TASK_LIST_LOOKUP:REMOVE(TASK[3]).
} ELSE {
SET INDEX TO INDEX + 1.
}
}
}
}
// LEAVE OLD MODE
IF MODES_LEAVE:HASKEY(MAJOR_MODE) {
MODES_LEAVE[MAJOR_MODE]:CALL().
}
// CHANGE MODE
SET MAJOR_MODE TO MAJOR.
SET MINOR_MODE TO MINOR.
// ENTER NEW MODE
IF MODES_ENTER:HASKEY(MAJOR_MODE) {
MODES_ENTER[MAJOR_MODE]:CALL().
}
// IF MINOR MODE DID NOT CHANGE AFTER "ENTER" CALL, TRANSFER NOW (OTHERWISE
// ENTER FUNCTION HAS ALREADY TRANSFERRED ITSELF)
IF MINOR_MODE = MINOR {
IF MODES_TRANSFER:HASKEY(MAJOR_MODE) {
MODES_TRANSFER[MAJOR_MODE]:CALL().
}
}
// MAJOR MODE CHANGED, REFRESH UI
RESET_DISPLAY().
// START ALL TASKS FROM THE NEW MODE
IF MODES_TASKLIST:HASKEY(MAJOR_MODE) {
FOR NEW_TASK IN MODES_TASKLIST[MAJOR_MODE] {
NEW_TASK:CALL(INIT).
}
}
} ELSE {
// TRANSFER MINOR MODE ONLY
SET MINOR_MODE TO MINOR.
IF MODES_TRANSFER:HASKEY(MAJOR_MODE) {
MODES_TRANSFER[MAJOR_MODE]:CALL().
}
}
// RESET MODE TIMER
SET MODE_TIMER_START TO TIME:SECONDS.
// SAVE MODE VALUES
SET_PVAR("MAJOR_MODE", MAJOR_MODE).
SET_PVAR("MINOR_MODE", MINOR_MODE).
DOWNLINK("OP", MAJOR_MODE*10 + MINOR_MODE).
}