Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* http://www.housedillon.com/?p=1272
- * Written by iskunk (Daniel Richard G.)
- * THIS FILE IS IN THE PUBLIC DOMAIN
- *
- * Program to emulate the CM-5's "random and pleasing" LED panel mode
- * (revision 3)
- */
- #include <stdio.h>
- #include <stdint.h>
- #include <string.h>
- #include <unistd.h>
- #define NUM_ROWS 32 /* unique rows */
- #define NUM_ROWS_DISPLAYED 106 /* rows in front panel display */
- static uint16_t fn(uint16_t x)
- {
- /* https://en.wikipedia.org/wiki/Linear_feedback_shift_register
- * Primitive polynomial: x^16 + x^12 + x^3 + x^1 + 1
- */
- return ((x >> 0) ^ (x >> 4) ^ (x >> 13) ^ (x >> 15)) & 1;
- }
- static void print_row(uint16_t x)
- {
- uint16_t m;
- int pos;
- char v[17];
- for (m = 1 << 15, pos = 0; m != 0; m >>= 1, pos++)
- v[pos] = (x & m) ? 'O' : '-';
- v[16] = '\0';
- puts(v);
- }
- int main(void)
- {
- uint16_t gen = 1;
- uint16_t rows[NUM_ROWS];
- int i;
- memset(rows, 0, sizeof(rows));
- for (;;)
- {
- /* ANSI sequence to clear terminal */
- fputs("\033[2J\033[1;1H", stdout);
- for (i = 0; i < NUM_ROWS; i++)
- {
- uint16_t gen_bit = fn(gen);
- uint16_t row_bit = ((gen >> 0) & (gen >> 1)) & 1;
- gen = (gen_bit << 15) | (gen >> 1);
- if (i & 4)
- rows[i] = (row_bit << 15) | (rows[i] >> 1);
- else
- rows[i] = (rows[i] << 1) | row_bit;
- }
- for (i = 0; i < NUM_ROWS_DISPLAYED; i++)
- print_row(rows[i & 31]);
- fflush(stdout);
- usleep(250000);
- }
- return 0;
- }
- /* EOF */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement