2024-03-25 05:34:59 +00:00
|
|
|
#include <iso646.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "control.h"
|
|
|
|
#include "fumotris.h"
|
|
|
|
#include "term.h"
|
|
|
|
#include "tetr.h"
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include "win.h"
|
|
|
|
#endif
|
|
|
|
|
2024-04-02 00:55:30 +00:00
|
|
|
const size_t code_count = 12;
|
|
|
|
|
|
|
|
const enum CtrlCode codes[12] = {
|
2024-03-25 05:34:59 +00:00
|
|
|
LEFT,
|
|
|
|
RIGHT,
|
|
|
|
SOFT_DROP,
|
|
|
|
HARD_DROP,
|
|
|
|
ROTATE_CCW,
|
|
|
|
ROTATE_CW,
|
|
|
|
ROTATE_180,
|
|
|
|
SWAP,
|
2024-04-02 00:55:30 +00:00
|
|
|
ESC,
|
|
|
|
|
|
|
|
VSCROLL,
|
|
|
|
HSCROLL,
|
|
|
|
|
|
|
|
MOUSE
|
2024-03-25 05:34:59 +00:00
|
|
|
};
|
2024-04-02 00:55:30 +00:00
|
|
|
|
|
|
|
const u16f binds[12] = {
|
2024-03-25 05:34:59 +00:00
|
|
|
0x25,
|
|
|
|
0x27,
|
|
|
|
0x28,
|
|
|
|
0x20,
|
|
|
|
'Z',
|
|
|
|
'X',
|
|
|
|
'A',
|
|
|
|
'C',
|
2024-04-02 00:55:30 +00:00
|
|
|
0x1B,
|
2024-03-25 05:34:59 +00:00
|
|
|
|
2024-04-02 00:55:30 +00:00
|
|
|
0,
|
|
|
|
1,
|
|
|
|
|
|
|
|
0
|
2024-03-25 05:34:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
u8 I[16] = {
|
|
|
|
0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
1, 1, 1, 1,
|
|
|
|
0, 0, 0, 0
|
|
|
|
};
|
|
|
|
|
2024-04-02 00:55:30 +00:00
|
|
|
void Loop(Ctrl *ctrl, struct RecordBuffer *in_buf)
|
2024-03-25 05:34:59 +00:00
|
|
|
{
|
|
|
|
struct TermBuf term = NewTermBuf(20, 20);
|
|
|
|
struct CharBlk4 term_blks[term.area];
|
|
|
|
memset(term_blks, 0, sizeof(struct CharBlk4) * term.area);
|
|
|
|
term.blks = term_blks;
|
|
|
|
|
|
|
|
size_t out_max = TermMaxChars(&term);
|
|
|
|
char out[out_max];
|
|
|
|
memset(out, 0, out_max);
|
|
|
|
|
|
|
|
struct TetrMap board = NewTetrMap(10, 20);
|
|
|
|
u8 board_blks[board.area];
|
|
|
|
memset(board_blks, 0, board.area);
|
|
|
|
board.blks = board_blks;
|
|
|
|
|
|
|
|
struct TetrMap falling = NewTetrMap(4, 4);
|
|
|
|
u8 falling_blks[falling.area];
|
|
|
|
memcpy(falling_blks, I, falling.area);
|
|
|
|
falling.blks = falling_blks;
|
|
|
|
|
|
|
|
for (int i = 0; i < 7779997; i++) {
|
2024-04-01 22:39:21 +00:00
|
|
|
CtrlPoll(ctrl, in_buf);
|
2024-03-26 20:11:58 +00:00
|
|
|
|
2024-03-25 05:34:59 +00:00
|
|
|
TetrMapToTermBuf(&board, &term);
|
|
|
|
TetrMapToTermBuf(&falling, &term);
|
|
|
|
|
2024-04-01 22:39:21 +00:00
|
|
|
TermBufToChars(&term, out, out_max);
|
2024-04-02 00:55:30 +00:00
|
|
|
puts(out);
|
2024-03-25 05:34:59 +00:00
|
|
|
|
2024-04-02 00:55:30 +00:00
|
|
|
WindowsWait(0.5);
|
2024-03-25 05:34:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
WindowsInit();
|
|
|
|
|
2024-04-01 22:39:21 +00:00
|
|
|
Ctrl ctrl;
|
|
|
|
NEW_CTRL(ctrl, 13, 13);
|
2024-03-25 05:34:59 +00:00
|
|
|
|
2024-04-02 00:55:30 +00:00
|
|
|
for (size_t i = 0; i < code_count; i++) {
|
2024-03-25 05:34:59 +00:00
|
|
|
CtrlMap(&ctrl, key_binds[i], key_codes[i], KEY);
|
|
|
|
}
|
|
|
|
for (size_t i = 0; i < 2; i++) {
|
|
|
|
CtrlMap(&ctrl, axis_codes[i], axis_binds[i], AXIS);
|
|
|
|
}
|
|
|
|
CtrlMap(&ctrl, 0, MOUSE, JOYSTICK);
|
|
|
|
CtrlMap(&ctrl, 0, 0, WINDOW);
|
|
|
|
|
|
|
|
printf("set controls\n");
|
|
|
|
|
2024-04-02 00:55:30 +00:00
|
|
|
struct RecordBuffer in_buf = {
|
2024-04-01 22:39:21 +00:00
|
|
|
.count = 0,
|
|
|
|
.mutex = PTHREAD_MUTEX_INITIALIZER
|
|
|
|
};
|
|
|
|
|
|
|
|
StartInput(&ctrl, &in_buf);
|
|
|
|
Loop(&ctrl, &in_buf);
|
|
|
|
|
|
|
|
JoinInput(&ctrl);
|
2024-03-25 05:34:59 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|