-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathcommon.h
119 lines (94 loc) · 2.82 KB
/
common.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#pragma once
#include "MyArduboy.h"
/* Defines */
//#define DEBUG
#define FPS 60
#define APP_TITLE "QUARTO!"
#define APP_CODE "OBN-Y08"
#define APP_VERSION "0.10"
#define APP_RELEASED "OCTOBER 2019"
enum MODE_T {
MODE_LOGO = 0,
MODE_TITLE,
MODE_GAME,
};
enum GAME_MODE_T {
GAME_MODE_YOU_FIRST = 0,
GAME_MODE_CPU_FIRST,
GAME_MODE_2PLAYERS,
};
#define BOARD_SIZE 4
#define BOARD_EMPTY 0xFF
#define PIECE_ATTRS 4
#define TURN_MAX (BOARD_SIZE * BOARD_SIZE)
#define PIECE_MAX (1 << PIECE_ATTRS)
#define SETTING_BIT_2x2_RULE 0x1
#define SETTING_BIT_THINK_LED 0x2
#define SETTING_BIT_SCREEN_INV 0x4
#define SETTING_BIT_HINT 0x8
/* Typedefs */
typedef struct {
uint8_t gameMode;
uint8_t cpuLevel;
uint8_t maxLevel;
uint8_t settings;
uint32_t playFrames;
uint16_t playCount;
} RECORD_T; // sizeof(RECORD_T) must be within 26 bytes
/* Global Functions (Common) */
void readRecord(void);
void writeRecord(void);
void clearRecord(void);
void handleDPad(void);
void drawNumber(int16_t x, int16_t y, int32_t value);
void drawTime(int16_t x, int16_t y, uint32_t frames);
void invertScreen(bool isInvert);
void setSound(bool on);
void playSoundTick(void);
void playSoundClick(void);
void eepSeek(int addr);
uint8_t eepRead8(void);
uint16_t eepRead16(void);
uint32_t eepRead32(void);
void eepReadBlock(void *p, size_t n);
void eepWrite8(uint8_t val);
void eepWrite16(uint16_t val);
void eepWrite32(uint32_t val);
void eepWriteBlock(const void *p, size_t n);
/* Global Functions (Menu) */
void clearMenuItems(void);
void addMenuItem(const __FlashStringHelper *label, void (*func)(void));
int8_t getMenuItemPos(void);
int8_t getMenuItemCount(void);
void setMenuCoords(int8_t x, int8_t y, int8_t w, int8_t h, bool f, bool s);
void setMenuItemPos(int8_t pos);
void handleMenu(void);
void drawMenuItems(bool isForced);
void drawSoundEnabled(void);
/* Global Functions (Each Mode) */
void initLogo(void);
MODE_T updateLogo(void);
void drawLogo(void);
void initTitle(void);
MODE_T updateTitle(void);
void drawTitle(void);
void initGame(void);
MODE_T updateGame(void);
void drawGame(void);
void drawPiece(int16_t x, int16_t y, int16_t piece);
/* Global Variables */
extern MyArduboy arduboy;
extern RECORD_T record;
extern bool isRecordDirty;
extern int8_t padX, padY, padRepeatCount;
extern bool isInvalid;
/* For Debugging */
#ifdef DEBUG
extern bool dbgPrintEnabled;
extern char dbgRecvChar;
#define dprint(...) (!dbgPrintEnabled || Serial.print(__VA_ARGS__))
#define dprintln(...) (!dbgPrintEnabled || Serial.println(__VA_ARGS__))
#else
#define dprint(...)
#define dprintln(...)
#endif