You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
2.2 KiB

  1. #include "muse.h"
  2. enum { MUSE_OFF, MUSE_ON, MUSE_C_1_2, MUSE_C1, MUSE_C2, MUSE_C4, MUSE_C8, MUSE_C3, MUSE_C6, MUSE_B1, MUSE_B2, MUSE_B3, MUSE_B4, MUSE_B5, MUSE_B6, MUSE_B7, MUSE_B8, MUSE_B9, MUSE_B10, MUSE_B11, MUSE_B12, MUSE_B13, MUSE_B14, MUSE_B15, MUSE_B16, MUSE_B17, MUSE_B18, MUSE_B19, MUSE_B20, MUSE_B21, MUSE_B22, MUSE_B23, MUSE_B24, MUSE_B25, MUSE_B26, MUSE_B27, MUSE_B28, MUSE_B29, MUSE_B30, MUSE_B31 };
  3. bool number_of_ones_to_bool[16] = {1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1};
  4. uint8_t muse_interval[4] = {MUSE_B7, MUSE_B19, MUSE_B3, MUSE_B28};
  5. uint8_t muse_theme[4] = {MUSE_B8, MUSE_B23, MUSE_B18, MUSE_B17};
  6. bool muse_timer_1bit = 0;
  7. uint8_t muse_timer_2bit = 0;
  8. uint8_t muse_timer_2bit_counter = 0;
  9. uint8_t muse_timer_4bit = 0;
  10. uint32_t muse_timer_31bit = 0;
  11. bool bit_for_value(uint8_t value) {
  12. switch (value) {
  13. case MUSE_OFF:
  14. return 0;
  15. case MUSE_ON:
  16. return 1;
  17. case MUSE_C_1_2:
  18. return muse_timer_1bit;
  19. case MUSE_C1:
  20. return (muse_timer_4bit & 1);
  21. case MUSE_C2:
  22. return (muse_timer_4bit & 2);
  23. case MUSE_C4:
  24. return (muse_timer_4bit & 4);
  25. case MUSE_C8:
  26. return (muse_timer_4bit & 8);
  27. case MUSE_C3:
  28. return (muse_timer_2bit & 1);
  29. case MUSE_C6:
  30. return (muse_timer_2bit & 2);
  31. default:
  32. return muse_timer_31bit & (1UL << (value - MUSE_B1));
  33. }
  34. }
  35. uint8_t muse_clock_pulse(void) {
  36. bool top = number_of_ones_to_bool[bit_for_value(muse_theme[0]) + (bit_for_value(muse_theme[1]) << 1) + (bit_for_value(muse_theme[2]) << 2) + (bit_for_value(muse_theme[3]) << 3)];
  37. if (muse_timer_1bit == 0) {
  38. if (muse_timer_2bit_counter == 0) {
  39. muse_timer_2bit = (muse_timer_2bit + 1) % 4;
  40. }
  41. muse_timer_2bit_counter = (muse_timer_2bit_counter + 1) % 3;
  42. muse_timer_4bit = (muse_timer_4bit + 1) % 16;
  43. muse_timer_31bit = (muse_timer_31bit << 1) + top;
  44. }
  45. muse_timer_1bit = (muse_timer_1bit + 1) % 2;
  46. return bit_for_value(muse_interval[0]) + (bit_for_value(muse_interval[1]) << 1) + (bit_for_value(muse_interval[2]) << 2) + (bit_for_value(muse_interval[3]) << 3);
  47. }