-
Notifications
You must be signed in to change notification settings - Fork 9
/
Protocol.h
96 lines (83 loc) · 3.26 KB
/
Protocol.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef PROTOCOL_H
#define PROTOCOL_H
#include <stdint.h>
// RENDER
#define DRAW_WIDTH 240
#define DRAW_HEIGHT 160
#define PALETTE_COLORS 256
#define TOTAL_SCREEN_PIXELS (DRAW_WIDTH * DRAW_HEIGHT)
// TRANSFER
#define PACKET_SIZE 4
#define COLOR_SIZE 2
#define PIXEL_SIZE 1
#define AUDIO_CHUNK_SIZE 264 // (sizeof(gsm_frame) * 8)
#define AUDIO_CHUNK_PADDING 0 // (so every chunk it's exactly 66 packets)
#define AUDIO_SIZE_PACKETS 66 // -----------------------------^^
#define SPI_MODE 3
#define TRANSFER_SYNC_PERIOD 32
#define COLORS_PER_PACKET (PACKET_SIZE / COLOR_SIZE)
#define PIXELS_PER_PACKET (PACKET_SIZE / PIXEL_SIZE)
#define MAX_PIXELS_SIZE (TOTAL_SCREEN_PIXELS / PIXELS_PER_PACKET)
#define AUDIO_PADDED_SIZE (AUDIO_CHUNK_SIZE AUDIO_CHUNK_PADDING)
// DIFFS
#define TEMPORAL_DIFF_MAX_SIZE(TOTAL_PIXELS) (TOTAL_PIXELS / 8)
#define TEMPORAL_DIFF_MAX_PADDED_SIZE(TOTAL_PIXELS) \
(TEMPORAL_DIFF_MAX_SIZE(TOTAL_PIXELS) 4)
#define TEMPORAL_DIFF_MAX_PACKETS(TOTAL_PIXELS) \
(TEMPORAL_DIFF_MAX_SIZE(TOTAL_PIXELS) / PACKET_SIZE)
#define MAX_RLE 255
// FILES
#define CONFIG_FILENAME "config.cfg"
#define CONTROLS_FILENAME "controls.cfg"
#define PALETTE_CACHE_FILENAME "palette.cache"
// COMMANDS
#define CMD_RESET 0x99887000
#define CMD_RPI_OFFSET 1
#define CMD_GBA_OFFSET 2
#define CMD_FRAME_START 0x12345610
#define CMD_AUDIO 0x12345620
#define CMD_PIXELS 0x12345630
#define CMD_FRAME_END 0x12345640
#define CMD_RECOVERY 0x98765490
// RESET PACKET
#define RESET_PACKET_MASK 0b11111111111111111111000000000000
#define RENDER_MODE_BIT_MASK 0b1111
#define CONTROLS_BIT_MASK 0b1111
#define COMPRESSION_BIT_MASK 0b111
#define CPU_OVERCLOCK_BIT_MASK 0b1
#define CONTROLS_BIT_OFFSET 4
#define COMPRESSION_BIT_OFFSET 8
#define CPU_OVERCLOCK_BIT_OFFSET 11
#define IS_RESET(VALUE) (((VALUE)&RESET_PACKET_MASK) == CMD_RESET)
// METADATA PACKET
#define AUDIO_BIT_MASK 0b10000000000000000000000000000000
#define COMPR_BIT_MASK 0b01000000000000000000000000000000
#define PACKS_BIT_MASK 0b00000000000000000011111111111111
#define START_BIT_MASK 0b00000000000000001111111111111111
#define PACKS_BIT_OFFSET 16
// RENDER MODES
#define RENDER_MODES 9
#define RENDER_MODE_BENCHMARK_1 9
#define RENDER_MODE_BENCHMARK_2 10
#define RENDER_MODE_IS_BENCHMARK(MODE) \
(MODE == RENDER_MODE_BENCHMARK_1 || MODE == RENDER_MODE_BENCHMARK_2)
#define DEFAULT_RENDER_MODE 4
#define COMPRESSION_LEVELS 6
#ifdef WITH_AUDIO
#define RENDER_MODE_IS_INVALID(MODE) \
((MODE) == 1 || (MODE) == 2 || (MODE) == 3 || (MODE) == 5 || (MODE) == 6)
#endif
#ifndef WITH_AUDIO
#define RENDER_MODE_IS_INVALID(MODE) (false)
#endif
const uint32_t RENDER_MODE_WIDTH[RENDER_MODES] = {60, 60, 60, 120, 120,
120, 240, 240, 240};
const uint32_t RENDER_MODE_HEIGHT[RENDER_MODES] = {40, 80, 160, 40, 80,
160, 40, 80, 160};
const uint32_t RENDER_MODE_SCALEX[RENDER_MODES] = {4, 4, 4, 2, 2, 2, 1, 1, 1};
const uint32_t RENDER_MODE_SCALEY[RENDER_MODES] = {4, 2, 1, 4, 2, 1, 4, 2, 1};
const uint32_t RENDER_MODE_PIXELS[RENDER_MODES] = {
2400, 4800, 9600, 4800, 9600, 19200, 9600, 19200, 38400};
const uint32_t DIFF_THRESHOLDS[COMPRESSION_LEVELS] = {0, 500, 1000,
1500, 3000, 6000};
#endif // PROTOCOL_H