<commit_before>#include "timeline.h"

WORD frameFromStart;
WORD frameTillEnd;
WORD frameCount;
WORD lastFrameCount;
TimeSlotT *currentTimeSlot;

__regargs TimeSlotT *TimelineForward(TimeSlotT *item, WORD pos) {
  for (; item->effect; item++)
    if ((item->start <= pos) && (pos < item->end))
      break;
  return item->effect ? item : NULL;
}

__regargs void LoadEffects(TimeSlotT *item, WORD phase) {
  TimeSlotT *curr = item;

  if (phase < 0)
    phase = item->phase;

  while (curr->effect)
    curr++;

  while (--curr >= item) {
    EffectT *effect = curr->effect;

    if (phase != curr->phase)
      continue;

    EffectLoad(effect);
  }
}

__regargs void UnLoadEffects(TimeSlotT *item) {
  for (; item->effect; item++)
    EffectUnLoad(item->effect);
}

__regargs void RunEffects(TimeSlotT *item) {
  BOOL exit = FALSE;

  SetFrameCounter(item->start);

  for (; item->effect && !exit; item++) {
    EffectT *effect = item->effect;
    WORD realStart;

    if (!(ReadFrameCounter() < item->end))
      continue;

    while (ReadFrameCounter() < item->start) {
      if (LeftMouseButton()) {
        exit = TRUE;
        break;
      }
    }

    currentTimeSlot = item;

    EffectPrepare(effect);
    EffectInit(effect);

    frameFromStart = 0;
    frameTillEnd = item->end - item->start;
    realStart = ReadFrameCounter();

    lastFrameCount = ReadFrameCounter();
    while (frameCount < item->end) {
      WORD t = ReadFrameCounter();
      frameCount = t;
      frameFromStart = frameCount - realStart;
      frameTillEnd = item->end - frameCount;
      if (effect->Render)
        effect->Render();
      else
        WaitVBlank();
      lastFrameCount = t;

      if (LeftMouseButton()) {
        exit = TRUE;
        break;
      }
    }

    EffectKill(effect);
    WaitVBlank();
    EffectUnLoad(effect);

    currentTimeSlot = NULL;
  }
}

void UpdateFrameCount() {
  frameCount = ReadFrameCounter();
  frameFromStart = frameCount - currentTimeSlot->start;
  frameTillEnd = currentTimeSlot->end - frameCount;
}<commit_msg>Print received commands.<commit_after>#include "timeline.h"
#if REMOTE_CONTROL
# include "serial.h"
#endif

WORD frameFromStart;
WORD frameTillEnd;
WORD frameCount;
WORD lastFrameCount;
TimeSlotT *currentTimeSlot;

__regargs TimeSlotT *TimelineForward(TimeSlotT *item, WORD pos) {
  for (; item->effect; item++)
    if ((item->start <= pos) && (pos < item->end))
      break;
  return item->effect ? item : NULL;
}

__regargs void LoadEffects(TimeSlotT *item, WORD phase) {
  TimeSlotT *curr = item;

  if (phase < 0)
    phase = item->phase;

  while (curr->effect)
    curr++;

  while (--curr >= item) {
    EffectT *effect = curr->effect;

    if (phase != curr->phase)
      continue;

    EffectLoad(effect);
  }
}

__regargs void UnLoadEffects(TimeSlotT *item) {
  for (; item->effect; item++)
    EffectUnLoad(item->effect);
}

__regargs void RunEffects(TimeSlotT *item) {
  BOOL exit = FALSE;

#if REMOTE_CONTROL
  char cmd[16];
  WORD cmdLen = 0;
  memset(cmd, 0, sizeof(cmd));
#endif

  SetFrameCounter(item->start);

  for (; item->effect && !exit; item++) {
    EffectT *effect = item->effect;
    WORD realStart;

    if (!(ReadFrameCounter() < item->end))
      continue;

    while (ReadFrameCounter() < item->start) {
      if (LeftMouseButton()) {
        exit = TRUE;
        break;
      }
    }

    currentTimeSlot = item;

    EffectPrepare(effect);
    EffectInit(effect);

    frameFromStart = 0;
    frameTillEnd = item->end - item->start;
    realStart = ReadFrameCounter();

    lastFrameCount = ReadFrameCounter();
    while (frameCount < item->end) {
      WORD t = ReadFrameCounter();
#if REMOTE_CONTROL
      SerialPrint("F %ld\n", (LONG)t);
#endif
      frameCount = t;
      frameFromStart = frameCount - realStart;
      frameTillEnd = item->end - frameCount;
      if (effect->Render)
        effect->Render();
      else
        WaitVBlank();
      lastFrameCount = t;

      if (LeftMouseButton()) {
        exit = TRUE;
        break;
      }
#if REMOTE_CONTROL
      {
        LONG c;

        while ((c = SerialGet()) >= 0) {
          if (c == '\n') {
            Log("[Serial] Received line '%s'\n", cmd);
            memset(cmd, 0, sizeof(cmd));
            cmdLen = 0;
          } else {
            cmd[cmdLen++] = c;
          }
        }
      }
#endif
    }

    EffectKill(effect);
    WaitVBlank();
    EffectUnLoad(effect);

    currentTimeSlot = NULL;
  }
}

void UpdateFrameCount() {
  frameCount = ReadFrameCounter();
  frameFromStart = frameCount - currentTimeSlot->start;
  frameTillEnd = currentTimeSlot->end - frameCount;
}
{'fraction_non_alphanumeric': 0.13588248001728234, 'fraction_numerical': 0.0023763231799524736, 'mean_word_length': 2.698083067092652, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1026022', 'n_tokens_mistral': 1542, 'n_tokens_neox': 1478, 'n_words': 349}