-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransitionHandling.s43
249 lines (196 loc) · 4.64 KB
/
transitionHandling.s43
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#include "msp430.h" ; #define controlled include file
MODULE transitionHandling
PUBLIC handleTransitionS1, handleTransitionS2, handleTransitionTick
RSEG CSTACK ; pre-declaration of segment
RSEG CODE ; place program in 'CODE' segment
; Drawing needs
EXTERN displayLog, displayRead, fullClear, displaybattery, divideR5ByR6, clearBatteryBars, ticks, beats, displayHeart, clearHeart, calculateBPM, displayBPMNumber, displayBPM, displaySave, displayOption
; Timer
EXTERN startTimerA1, stopTimer, startTimer
; Logging
EXTERN saveLog, nextLog, logCurr
EXTERN currentBpm
; Transition Function for S1 Transition place current state address in R6
;Objetivo: Maneja las trancisiones de S2 usando el estado actual
;Precondiciones: Debes incluir el address del state en R6
;Postcondiciones: Ninguna
;Autor: Kenneth J. Rosario
;Fecha: 18/abril/2021
handleTransitionS2:
push R7
mov.b 0(R6), R7
cmp.b #0, R7
jeq state0S2
cmp.b #1, R7
jeq state1S2
cmp.b #2, R7
jeq state2S2
cmp.b #12, R7
jeq state12S2ProceedToSave
cmp.b #13, R7
jeq state13S2DiscardBpm
returnHandle:
pop R7
ret
state0S2:
mov.b #1, 0(R6)
call #displayRead
jmp returnHandle
state1S2:
mov.b #2, 0(R6)
call #displayLog
jmp returnHandle
state2S2:
mov.b #1, 0(R6)
call #displayRead
jmp returnHandle
state12S2ProceedToSave:
mov.b #13, 0(R6)
call #fullClear
call #displaySave
jmp returnHandle
state13S2DiscardBpm:
mov.b #0, 0(R6)
call #fullClear
call #displayOption
jmp returnHandle
;Objetivo: Maneja las trancisiones de S1 usando el estado actual
;Precondiciones: Debes incluir el address del state en R6
;Postcondiciones: Ninguna
;Autor: Kenneth J. Rosario
;Fecha: 18/abril/2021
handleTransitionS1:
push R7
mov.b 0(R6), R7
cmp #3, R7
jeq state3S1InputBeat
cmp #1, R7
jeq state1S1ReadingState
cmp #2, R7
jeq state2S1ShowLogs
cmp #5, R7
jeq state5S1ShowLogs
cmp #6, R7
jeq state6S1ShowLogs
cmp #7, R7
jeq state7S1FinishLog
cmp #13, R7
jeq state13S1StoreBpm
returnHandleS1:
pop R7
ret
state1S1ReadingState:
call #startTimer
call #fullClear
mov #0, r12
call #displaybattery
mov.b #3, 0(R6)
jmp returnHandleS1
state2S1ShowLogs:
mov.b #5, 0(R6) ; move to state 5
call #showNextLog
jmp returnHandleS1
state5S1ShowLogs:
mov.b #6, 0(R6)
call #showNextLog
jmp returnHandleS1
state6S1ShowLogs:
mov.b #7, 0(R6)
call #showNextLog
jmp returnHandleS1
state7S1FinishLog:
mov.b #0, 0(R6)
call #fullClear
call #displayOption
jmp returnHandleS1
state3S1InputBeat:
call #displayHeart
call #startTimerA1
inc beats
jmp returnHandleS1
state13S1StoreBpm:
push r8
mov currentBpm, r8
call #saveLog
pop r8
mov.b #0, 0(R6)
call #fullClear
call #displayOption
jmp returnHandleS1
;Objetivo: Maneja las trancisiones del timer a0 usando el estado actual
;Precondiciones: Debes incluir el address del state en R6
;Postcondiciones: Ninguna
;Autor: Kenneth J. Rosario
;Fecha: 18/abril/2021
handleTransitionTick:
push r5
push r8
push r9
push r12
push r6 ; temporary store state
mov #5, r6
mov ticks, r5
call #divideR5ByR6
pop r6 ; reget state
cmp #6, r8 ; seconds
jge R8reached6
mov r8, r9
drawBatteries:
mov r9, r12
call #displaybattery
jmp returnHandleTick
R8reached6:
; check if remainder is not 0
cmp #0, r9
jnz returnHandleTick
push r6
mov r8, r5
mov #6, r6
call #divideR5ByR6
pop r6
cmp #0, r9
jeq move6ToR8
cmp #1, r9
jeq restartBattery
jmp drawBatteries
move6ToR8:
; Display calculated
push r7
push r8
push r10
; TASK: Fix battery bars at the end
mov beats, r7
mov ticks, r8
call #calculateBPM
mov r10, currentBpm
call #displayBPMNumber
call #displayBPM
pop r10
pop r8
pop r7
mov #6, r9
jmp drawBatteries
restartBattery:
call #clearBatteryBars
jmp drawBatteries
returnHandleTick:
pop r12
pop r9
pop r8
pop r5
ret
;Objetivo: Funcion que dibuja el proximo log
;Precondiciones: Ninguna
;Postcondiciones: Ninguna
;Autor: Kenneth J. Rosario
;Fecha: 18/abril/2021
showNextLog:
call #nextLog
call #fullClear
push r10
mov logCurr, r10
call #displayBPMNumber
call #displayBPM
pop r10
ret
END