-
Notifications
You must be signed in to change notification settings - Fork 0
/
shuffle.h
50 lines (40 loc) · 1.11 KB
/
shuffle.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include <wchar.h>
#include <locale.h>
#include <errno.h>
#include <signal.h>
#define HELP 1
#define NO_HELP 0
#define VERSION "1.2.1"
// Nanoseconds multiplied with speed
#define NSECONDS 10000
// The last bit as flag
#define IS_END_FLAG 0x01
// Dimension of the ASCII picture
extern int width, height;
// Structure for 'nanosleep' function
extern struct timespec req;
// Allocated memory for the ASCII picture
extern wchar_t *ascii_pic;
void shuffle(int *array, int n);
int load_ascii(const char *filename);
// 'p_effect' is a pointer to a function for the effect.
int show_shuffled(void(*p_effect)(int *, int), wchar_t *ansi_pic, int speed, char *rgb, int is_help);
// Swap a and b very fast (inline Assembly test: not necessary, C is really fast enough)
static inline void swap(int *a, int *b)
{
__asm__(
"movl (%0), %%eax;\n"
"movl (%1), %%ebx;\n"
"movl %%ebx, (%0);\n"
"movl %%eax, (%1);"
:
: "r"(a), "r"(b)
: "%eax", "%ebx");
}