#pragma once

#include "xm_player/xm.h"

namespace interpreter {

constexpr int max_channels = 64;

struct channel_state {
  uint8_t instrument;
  uint8_t keyon;
  uint8_t volume;
};

struct interpreter_state {
  int interrupt_clock;
  int current_tick_rate;
  int default_tick_rate;
  int ticks_per_line;
  int tick;
  int pattern_order_table_index;
  int pattern_break;
  int pattern_index;
  int line_index;
  int next_line_index; // within the current pattern
  bool paused;
  bool reverse;
  bool repeat;

  int deferred_load_tick;
  int sample_data_ix;
  int deferred_cover_ix;

  struct xm_state xm;

  struct channel_state channel[max_channels];
};

extern struct interpreter_state state;
void interrupt();
void init(float clock_multiplier);
void pause();
void unpause();

void resume_sound();
void stop_sound();

  void deferred_load(int buf, int cover_ix);
  void deferred_load_finish();
}
