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 20:06:14 +00:00
|
|
|
const 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
|
|
|
|
2024-04-02 20:06:14 +00:00
|
|
|
const u8 O[4] = {
|
|
|
|
1, 1,
|
|
|
|
1, 1
|
2024-03-25 05:34:59 +00:00
|
|
|
};
|
2024-04-02 00:55:30 +00:00
|
|
|
|
2024-04-02 20:06:14 +00:00
|
|
|
const u8 T[9] = {
|
|
|
|
0, 1, 0,
|
|
|
|
1, 1, 1,
|
|
|
|
0, 0, 0
|
2024-03-25 05:34:59 +00:00
|
|
|
};
|
|
|
|
|
2024-04-02 20:06:14 +00:00
|
|
|
const u8 S[9] = {
|
|
|
|
0, 1, 1,
|
|
|
|
1, 1, 0,
|
|
|
|
0, 0, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
const u8 Z[9] = {
|
|
|
|
1, 1, 0,
|
|
|
|
0, 1, 1,
|
|
|
|
0, 0, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
const u8 J[9] = {
|
|
|
|
1, 0, 0,
|
|
|
|
1, 1, 1,
|
|
|
|
0, 0, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
const u8 L[9] = {
|
|
|
|
0, 0, 1,
|
|
|
|
1, 1, 1,
|
|
|
|
0, 0, 0
|
2024-03-25 05:34:59 +00:00
|
|
|
};
|
|
|
|
|
2024-04-02 20:06:14 +00:00
|
|
|
struct CtrlBind {
|
|
|
|
enum CtrlCode code;
|
|
|
|
u16 bind;
|
|
|
|
u8 type;
|
|
|
|
};
|
|
|
|
|
|
|
|
const size_t code_count = 12;
|
|
|
|
const struct CtrlBind ctrl_binds[12] = {
|
|
|
|
{ LEFT, 0x25, KEY },
|
|
|
|
{ RIGHT, 0x27, KEY },
|
|
|
|
{ SOFT_DROP, 0x28, KEY },
|
|
|
|
{ HARD_DROP, 0x20, KEY },
|
|
|
|
{ ROTATE_CCW, 'Z', KEY },
|
|
|
|
{ ROTATE_CW, 'X', KEY },
|
|
|
|
{ ROTATE_180, 'A', KEY },
|
|
|
|
{ SWAP, 'C', KEY },
|
|
|
|
{ ESC, 0x1B, KEY },
|
|
|
|
{ VSCROLL, 0, AXIS },
|
|
|
|
{ HSCROLL, 1, AXIS },
|
|
|
|
{ MOUSE, 0, JOYSTICK }
|
|
|
|
};
|
|
|
|
|
|
|
|
void Update(Ctrl *ctrl)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-04-02 00:55:30 +00:00
|
|
|
void Loop(Ctrl *ctrl, struct RecordBuffer *in_buf)
|
2024-03-25 05:34:59 +00:00
|
|
|
{
|
2024-04-02 20:06:14 +00:00
|
|
|
struct CharBlk4 term_blks[20 * 20];
|
|
|
|
struct TermBuf term = NewTermBuf(term_blks, 20, 20);
|
2024-03-25 05:34:59 +00:00
|
|
|
|
|
|
|
size_t out_max = TermMaxChars(&term);
|
|
|
|
char out[out_max];
|
|
|
|
|
2024-04-02 20:06:14 +00:00
|
|
|
u8 board_blks[10 * 20];
|
|
|
|
struct TetrMap board = NewTetrMap(board_blks, 10, 20);
|
2024-03-25 05:34:59 +00:00
|
|
|
|
2024-04-02 20:06:14 +00:00
|
|
|
u8 falling_blks[4 * 4];
|
|
|
|
struct TetrMap falling = NewTetrMap(falling_blks, 4, 4);
|
2024-03-25 05:34:59 +00:00
|
|
|
memcpy(falling_blks, I, falling.area);
|
|
|
|
|
|
|
|
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 20:06:14 +00:00
|
|
|
WindowsWait(1.0/30);
|
2024-03-25 05:34:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2024-04-02 20:06:14 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
if(!WindowsInit())
|
|
|
|
exit(1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct bkt code_bkts[code_count];
|
|
|
|
struct dict codes = {
|
|
|
|
.capacity = code_count,
|
|
|
|
.filled = 0,
|
|
|
|
.bkts = code_bkts
|
|
|
|
};
|
|
|
|
struct bkt bind_bkts[code_count];
|
|
|
|
struct dict binds = {
|
|
|
|
.capacity = code_count,
|
|
|
|
.filled = 0,
|
|
|
|
.bkts = bind_bkts
|
|
|
|
};
|
|
|
|
struct Axis axes[code_count];
|
|
|
|
Ctrl ctrl = NewCtrl(&codes, &binds, axes);
|
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-04-02 20:06:14 +00:00
|
|
|
const struct CtrlBind *bind = &ctrl_binds[i];
|
|
|
|
CtrlMap(&ctrl, bind->code, bind->bind, bind->type);
|
2024-03-25 05:34:59 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|