5
5
#include "helpers.h"
6
6
#include "ops/op.h"
7
7
#include "teletype.h"
8
+ #include "teletype_io.h"
8
9
9
10
10
11
static void op_LAST_get (const void * data , scene_state_t * ss , exec_state_t * es ,
@@ -25,6 +26,14 @@ static void op_I_get(const void *data, scene_state_t *ss, exec_state_t *es,
25
26
command_state_t * cs );
26
27
static void op_I_set (const void * data , scene_state_t * ss , exec_state_t * es ,
27
28
command_state_t * cs );
29
+ static void op_TIME_get (const void * data , scene_state_t * ss , exec_state_t * es ,
30
+ command_state_t * cs );
31
+ static void op_TIME_set (const void * data , scene_state_t * ss , exec_state_t * es ,
32
+ command_state_t * cs );
33
+ static void op_TIME_ACT_get (const void * data , scene_state_t * ss , exec_state_t * es ,
34
+ command_state_t * cs );
35
+ static void op_TIME_ACT_set (const void * data , scene_state_t * ss , exec_state_t * es ,
36
+ command_state_t * cs );
28
37
29
38
// clang-format off
30
39
const tele_op_t op_A = MAKE_SIMPLE_VARIABLE_OP (A , variables .a );
@@ -39,8 +48,8 @@ const tele_op_t op_O_MAX = MAKE_SIMPLE_VARIABLE_OP(O.MAX , variables.o_
39
48
const tele_op_t op_O_MIN = MAKE_SIMPLE_VARIABLE_OP (O .MIN , variables .o_min );
40
49
const tele_op_t op_O_WRAP = MAKE_SIMPLE_VARIABLE_OP (O .WRAP , variables .o_wrap );
41
50
const tele_op_t op_T = MAKE_SIMPLE_VARIABLE_OP (T , variables .t );
42
- const tele_op_t op_TIME = MAKE_SIMPLE_VARIABLE_OP (TIME , variables . time );
43
- const tele_op_t op_TIME_ACT = MAKE_SIMPLE_VARIABLE_OP (TIME .ACT , variables . time_act );
51
+ const tele_op_t op_TIME = MAKE_GET_SET_OP (TIME , op_TIME_get , op_TIME_set , 0 , true );
52
+ const tele_op_t op_TIME_ACT = MAKE_GET_SET_OP (TIME .ACT , op_TIME_ACT_get , op_TIME_ACT_set , 0 , true );
44
53
const tele_op_t op_LAST = MAKE_GET_OP (LAST , op_LAST_get , 1 , true);
45
54
const tele_op_t op_X = MAKE_SIMPLE_VARIABLE_OP (X , variables .x );
46
55
const tele_op_t op_Y = MAKE_SIMPLE_VARIABLE_OP (Y , variables .y );
@@ -52,6 +61,34 @@ const tele_op_t op_O = MAKE_GET_SET_OP(O , op_O_get , op_O_set , 0,
52
61
const tele_op_t op_I = MAKE_GET_SET_OP (I , op_I_get , op_I_set , 0 , true);
53
62
// clang-format on
54
63
64
+ static void op_TIME_get (const void * NOTUSED (data ), scene_state_t * ss ,
65
+ exec_state_t * NOTUSED (es ), command_state_t * cs ) {
66
+ int64_t delta = ss -> variables .time_act ?
67
+ tele_get_ticks () - ss -> variables .time : ss -> variables .time ;
68
+ cs_push (cs , delta & 0x7fff );
69
+ }
70
+
71
+ static void op_TIME_set (const void * NOTUSED (data ), scene_state_t * ss ,
72
+ exec_state_t * NOTUSED (es ), command_state_t * cs ) {
73
+ int16_t new_time = cs_pop (cs );
74
+ ss -> variables .time = ss -> variables .time_act ?
75
+ tele_get_ticks () - new_time : new_time ;
76
+ }
77
+
78
+ static void op_TIME_ACT_get (const void * NOTUSED (data ), scene_state_t * ss ,
79
+ exec_state_t * NOTUSED (es ), command_state_t * cs ) {
80
+ cs_push (cs , ss -> variables .time_act ? 1 : 0 );
81
+ }
82
+
83
+ static void op_TIME_ACT_set (const void * NOTUSED (data ), scene_state_t * ss ,
84
+ exec_state_t * NOTUSED (es ), command_state_t * cs ) {
85
+ int16_t act = cs_pop (cs );
86
+ if (act && ss -> variables .time_act ) return ;
87
+ if (!act && !ss -> variables .time_act ) return ;
88
+ ss -> variables .time_act = act ? 1 : 0 ;
89
+ ss -> variables .time = tele_get_ticks () - ss -> variables .time ;
90
+ }
91
+
55
92
static void op_LAST_get (const void * NOTUSED (data ), scene_state_t * ss ,
56
93
exec_state_t * NOTUSED (es ), command_state_t * cs ) {
57
94
int16_t script_number = cs_pop (cs ) - 1 ;
0 commit comments