PokittoCore.h
Go to the documentation of this file.
1 /**************************************************************************/
35 /**************************************************************************/
36 
37 #ifndef POKITTOCORE_H
38 #define POKITTOCORE_H
39 
40 #include <stdint.h>
41 #include <math.h>
42 #ifndef POK_SIM
43  #include "pwmout_api.h"
44  #include "HWButtons.h"
45 #else
46  #include "PokittoSimulator.h"
47 #endif
48 #if POK_USE_CONSOLE > 0
49  #include "PokittoConsole.h"
50 #endif // POK_USE_CONSOLE
51 #if POK_ENABLE_SD > 0
52  #include "PokittoDisk.h"
53 #endif
54 
55 #include "PokittoFonts.h"
56 #include "PokittoPalettes.h"
57 #include "PokittoDisplay.h"
58 #include "PokittoButtons.h"
59 #include "PokittoBattery.h"
60 #include "PokittoBacklight.h"
61 #include "PokittoSound.h"
62 #include "PokittoFakeavr.h"
63 
64 #define PALETTE_SIZE 16
65 #define PI 3.141592741f
66 
67 // For GB compatibility
68 #if PROJ_GAMEBUINO > 0
69 extern void setup();
70 extern void loop();
71 #endif // PROJ_GAMEBUINO
72 
73 extern uint32_t* ptimer; // re-directed tick counter
74 
75 namespace Pokitto {
76 
100 class Core
101 {
102 public:
105  Core();
106 
110  static Buttons buttons;
112  static Battery battery;
114  static Sound sound;
116  static Display display;
117 
118  // EXCECUTION CONTROL
119 public:
121  static void begin();
123  static void init();
125  static void init(uint8_t);
127  static bool isRunning();
129  static void quit();
130 private:
132  static bool run_state;
133 
134 public:
135  // INITIALIZATION
137  static void initDisplay();
139  static void initRandom();
141  static void initGPIO();
143  static void initLCD();
145  static void initAudio();
146 
147 
148  // DISPLAY
149 public:
151  static void initBacklight();
152 
153 private:
155  #ifndef POK_SIM
156  static pwmout_t backlightpwm;
157  #endif
158 
159  // TIMEKEEPING
160 public:
162  static void initClock();
164  static uint32_t getTime();
166  static void wait(uint16_t);
167 private:
169  static uint32_t refreshtime;
170 
171  // DIRECT TO SCREEN
172 public:
174  static void showLogo();
175  static void showWarning();
176  static void setVolLimit();
177 
178 // BUTTON INPUT HANDLING
179 private:
180  static uint8_t heldStates[];
181 public:
182  static void initButtons();
183  static void pollButtons();
184  static uint8_t leftBtn();
185  static uint8_t rightBtn();
186  static uint8_t upBtn();
187  static uint8_t downBtn();
188  static uint8_t aBtn();
189  static uint8_t bBtn();
190  static uint8_t cBtn();
191  static uint8_t leftHeld();
192  static uint8_t rightHeld();
193  static uint8_t upHeld();
194  static uint8_t downHeld();
195  static uint8_t aHeld();
196  static uint8_t bHeld();
197  static uint8_t cHeld();
198 
199  static uint8_t leftReleased();
200  static uint8_t rightReleased();
201  static uint8_t upReleased();
202  static uint8_t downReleased();
203  static uint8_t aReleased();
204  static uint8_t bReleased();
205  static uint8_t cReleased();
206 
207  // AUDIO RELATED
208  static uint8_t ampIsOn();
209  static void ampEnable(uint8_t);
210  static uint8_t soundbyte;
211 
212  // GB RELATED
213 public:
214  static void readSettings();
215  static void titleScreen(const char* name, const uint8_t *logo);
216  static void titleScreen(const char* name);
217  static void titleScreen(const uint8_t* logo);
218  static void titleScreen();
219  static bool update(bool useDirectMode=false);
220  static uint32_t frameCount;
221  static int8_t menu(const char* const* items, uint8_t length);
222  static char* filemenu(char*);
223  static char* filemenu();
224  static void keyboard(char* text, uint8_t length);
225  static void popup(const char* text, uint8_t duration);
226  static void setFrameRate(uint8_t fps);
227  static void pickRandomSeed();
228 
229  static uint8_t getCpuLoad();
230  static uint16_t getFreeRam();
231 
232  static bool collidePointRect(int16_t x1, int16_t y1 ,int16_t x2 ,int16_t y2, int16_t w, int16_t h);
233  static bool collideRectRect(int16_t x1, int16_t y1, int16_t w1, int16_t h1 ,int16_t x2 ,int16_t y2, int16_t w2, int16_t h2);
234  static bool collideBitmapBitmap(int16_t x1, int16_t y1, const uint8_t* b1, int16_t x2, int16_t y2, const uint8_t* b2);
235 
236 private:
237  static uint8_t timePerFrame;
238  static uint32_t nextFrameMillis;
239  static void updatePopup();
240  static const char* popupText;
241  static uint8_t popupTimeLeft;
242  static void displayBattery();
243  static uint16_t frameDurationMicros;
244  static uint32_t frameStartMicros, frameEndMicros;
245  static uint8_t startMenuTimer;
246  static int updateLoader(uint32_t,uint32_t);
247 public:
248  static uint8_t volbar_visible;
249  static void drawvolbar(int,int,int, bool);
250  static void askLoader();
251  static void jumpToLoader();
252 };
253 
254 // this is the instance used by the system
255 extern Core core;
256 
257 
258 }
259 
260 #endif // POKITTOCORE_H
261 
262 
Definition: PokittoButtons.h:57
Definition: PokittoBacklight.h:43
static void wait(uint16_t)
static void begin()
Definition: PokittoCore.cpp:526
static void quit()
static void initGPIO()
static Buttons buttons
Definition: PokittoCore.h:110
static void showLogo()
Definition: PokittoCore.cpp:656
static void initLCD()
static Backlight backlight
Definition: PokittoCore.h:108
Definition: PokittoDisplay.h:136
static Battery battery
Definition: PokittoCore.h:112
static Display display
Definition: PokittoCore.h:116
static uint32_t getTime()
static bool isRunning()
Definition: PokittoCore.cpp:640
Definition: PokittoBacklight.h:42
static void init()
Definition: PokittoCore.cpp:610
static Sound sound
Definition: PokittoCore.h:114
Core()
Definition: PokittoCore.cpp:163
Definition: PokittoBattery.h:49
Definition: PokittoSound.h:94
static void initBacklight()
Definition: PokittoCore.h:100
static void initRandom()
static void initClock()
static void initDisplay()
Definition: PokittoCore.cpp:647
static void initAudio()