Skip to content
Permalink
Browse files

1ms TIME/LAST fixes monome#144

  • Loading branch information
scanner-darkly committed May 31, 2018
1 parent 798b52d commit c29a0466d3a602ef930dff103400b9946fab20a2
Showing with 73 additions and 16 deletions.
  1. +6 −0 module/flash.c
  2. +4 −0 module/main.c
  3. +4 −0 simulator/tt.c
  4. +3 −1 src/ops/init.c
  5. +39 −2 src/ops/variables.c
  6. +8 −6 src/state.c
  7. +3 −3 src/state.h
  8. +0 −4 src/teletype.c
  9. +3 −0 src/teletype_io.h
  10. +3 −0 tests/main.c
@@ -5,6 +5,7 @@
// asf
#include "flashc.h"
#include "print_funcs.h"
#include "init_teletype.h"

// this
#include "teletype.h"
@@ -89,6 +90,11 @@ void flash_read(uint8_t preset_no, scene_state_t *scene,
unpack_grid(scene);
memcpy(text, &f.scenes[preset_no].text,
SCENE_TEXT_LINES * SCENE_TEXT_CHARS);
// need to reset timestamps
uint32_t ticks = get_ticks();
for (size_t i = 0; i < TEMP_SCRIPT; i++)
scene->scripts[i].last_time = ticks;
scene->variables.time = 0;
}

uint8_t flash_last_saved_scene() {
@@ -783,6 +783,10 @@ void render_init(void) {
////////////////////////////////////////////////////////////////////////////////
// teletype_io.h

uint32_t tele_get_ticks() {
return get_ticks();
}

void tele_metro_updated() {
uint32_t metro_time = scene_state.variables.m;

@@ -11,6 +11,10 @@
#include "util.h"


uint32_t tele_get_ticks() {
return 0;
}

void tele_metro_updated() {
printf("METRO UPDATED");
printf("\n");
@@ -169,6 +169,8 @@ static void op_INIT_TIME_get(const void *NOTUSED(data), scene_state_t *ss,
command_state_t *NOTUSED(cs)) {
clear_delays(ss);
ss->variables.time = 0;
for (uint8_t i = 0; i < TEMP_SCRIPT; i++) ss->scripts[i].last_time = 0;
uint32_t ticks = tele_get_ticks();
for (uint8_t i = 0; i < TEMP_SCRIPT; i++) ss->scripts[i].last_time = ticks;
ss->variables.time = 0;
ss_sync_every(ss, 0);
}
@@ -5,6 +5,7 @@
#include "helpers.h"
#include "ops/op.h"
#include "teletype.h"
#include "teletype_io.h"


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,
command_state_t *cs);
static void op_I_set(const void *data, scene_state_t *ss, exec_state_t *es,
command_state_t *cs);
static void op_TIME_get(const void *data, scene_state_t *ss, exec_state_t *es,
command_state_t *cs);
static void op_TIME_set(const void *data, scene_state_t *ss, exec_state_t *es,
command_state_t *cs);
static void op_TIME_ACT_get(const void *data, scene_state_t *ss, exec_state_t *es,
command_state_t *cs);
static void op_TIME_ACT_set(const void *data, scene_state_t *ss, exec_state_t *es,
command_state_t *cs);

// clang-format off
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_
const tele_op_t op_O_MIN = MAKE_SIMPLE_VARIABLE_OP(O.MIN , variables.o_min );
const tele_op_t op_O_WRAP = MAKE_SIMPLE_VARIABLE_OP(O.WRAP , variables.o_wrap );
const tele_op_t op_T = MAKE_SIMPLE_VARIABLE_OP(T , variables.t );
const tele_op_t op_TIME = MAKE_SIMPLE_VARIABLE_OP(TIME , variables.time );
const tele_op_t op_TIME_ACT = MAKE_SIMPLE_VARIABLE_OP(TIME.ACT , variables.time_act );
const tele_op_t op_TIME = MAKE_GET_SET_OP(TIME, op_TIME_get, op_TIME_set, 0, true);
const tele_op_t op_TIME_ACT = MAKE_GET_SET_OP(TIME.ACT, op_TIME_ACT_get, op_TIME_ACT_set, 0, true);
const tele_op_t op_LAST = MAKE_GET_OP(LAST , op_LAST_get, 1, true);
const tele_op_t op_X = MAKE_SIMPLE_VARIABLE_OP(X , variables.x );
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,
const tele_op_t op_I = MAKE_GET_SET_OP(I , op_I_get, op_I_set, 0, true);
// clang-format on

static void op_TIME_get(const void *NOTUSED(data), scene_state_t *ss,
exec_state_t *NOTUSED(es), command_state_t *cs) {
int64_t delta = ss->variables.time_act ?
tele_get_ticks() - ss->variables.time : ss->variables.time;
cs_push(cs, delta & 0x7fff);
}

static void op_TIME_set(const void *NOTUSED(data), scene_state_t *ss,
exec_state_t *NOTUSED(es), command_state_t *cs) {
int16_t new_time = cs_pop(cs);
ss->variables.time = ss->variables.time_act ?
tele_get_ticks() - new_time : new_time;
}

static void op_TIME_ACT_get(const void *NOTUSED(data), scene_state_t *ss,
exec_state_t *NOTUSED(es), command_state_t *cs) {
cs_push(cs, ss->variables.time_act ? 1 : 0);
}

static void op_TIME_ACT_set(const void *NOTUSED(data), scene_state_t *ss,
exec_state_t *NOTUSED(es), command_state_t *cs) {
int16_t act = cs_pop(cs);
if (act && ss->variables.time_act) return;
if (!act && !ss->variables.time_act) return;
ss->variables.time_act = act ? 1 : 0;
ss->variables.time = tele_get_ticks() - ss->variables.time;
}

static void op_LAST_get(const void *NOTUSED(data), scene_state_t *ss,
exec_state_t *NOTUSED(es), command_state_t *cs) {
int16_t script_number = cs_pop(cs) - 1;
@@ -17,6 +17,11 @@ void ss_init(scene_state_t *ss) {
ss->stack_op.top = 0;
memset(&ss->scripts, 0, ss_scripts_size());
turtle_init(&ss->turtle);
uint32_t ticks = tele_get_ticks();
for (size_t i = 0; i < TEMP_SCRIPT; i++)
ss->scripts[i].last_time = ticks;
ss->variables.time = 0;
ss->variables.time_act = 1;
}

void ss_variables_init(scene_state_t *ss) {
@@ -331,17 +336,14 @@ size_t ss_scripts_size() {
}

int16_t ss_get_script_last(scene_state_t *ss, script_number_t idx) {
int16_t now = ss->variables.time;
if (idx < TT_SCRIPT_1) return 0;
if (idx > INIT_SCRIPT) return 0;
int16_t last = ss->scripts[idx].last_time;
if (now < last)
return (INT16_MAX - last) + (now - INT16_MIN); // I must be dense?
return now - last;
uint32_t delta = (tele_get_ticks() - ss->scripts[idx].last_time) & 0x7fff;
return delta;
}

void ss_update_script_last(scene_state_t *ss, script_number_t idx) {
ss->scripts[idx].last_time = ss->variables.time;
ss->scripts[idx].last_time = tele_get_ticks();
}

every_count_t *ss_get_every(scene_state_t *ss, script_number_t idx,
@@ -90,8 +90,8 @@ typedef struct {
int16_t r_min;
int16_t r_max;
int16_t scene;
int16_t time;
int16_t time_act;
int64_t time;
uint8_t time_act;
int16_t tr[TR_COUNT];
int16_t tr_pol[TR_COUNT];
int16_t tr_time[TR_COUNT];
@@ -129,7 +129,7 @@ typedef struct {
uint8_t l;
tele_command_t c[SCRIPT_MAX_COMMANDS];
every_count_t every[SCRIPT_MAX_COMMANDS];
int16_t last_time;
uint32_t last_time;
} scene_script_t;

typedef struct {
@@ -299,10 +299,6 @@ process_result_t process_command(scene_state_t *ss, exec_state_t *es,
// TICK /////////////////////////////////////////////////////////

void tele_tick(scene_state_t *ss, uint8_t time) {
// time is the basic resolution of all code henceforth called
// hardware 2.0: get an RTC!
if (ss->variables.time_act) ss->variables.time += time;

// could be a while() if there is reason to expect a user to cascade moves
// with SCRIPTs without the tick delay
if (ss->turtle.stepped && ss->turtle.script_number != TEMP_SCRIPT) {
@@ -7,6 +7,9 @@
// These functions are for interacting with the teletype hardware, each target
// must provide it's own implementation

// used for TIME and LAST
extern uint32_t tele_get_ticks(void);

// called when M or M.ACT are updated
extern void tele_metro_updated(void);

@@ -11,6 +11,9 @@
#include "process_tests.h"
#include "turtle_tests.h"

uint32_t tele_get_ticks() {
return 0;
}
void tele_metro_updated() {}
void tele_metro_reset() {}
void tele_tr(uint8_t i, int16_t v) {}

0 comments on commit c29a046

Please sign in to comment.