Louis Mayencourt / Mbed OS NRFBOY
Committer:
lmayencou
Date:
Sat Jan 07 12:43:36 2017 +0000
Revision:
3:df305b314063
Parent:
1:c53e766082b4
Child:
7:fb7e549d1cf6
add frame timer - game working - bug with high scores

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lmayencou 1:c53e766082b4 1 #ifndef ABSTRACTARDUBOY_H
lmayencou 1:c53e766082b4 2 #define ABSTRACTARDUBOY_H
lmayencou 1:c53e766082b4 3
lmayencou 1:c53e766082b4 4 #include <stdint.h>
lmayencou 1:c53e766082b4 5 #include "glcdfont.h"
lmayencou 1:c53e766082b4 6
lmayencou 1:c53e766082b4 7 #define WIDTH 128
lmayencou 1:c53e766082b4 8 #define HEIGHT 64
lmayencou 1:c53e766082b4 9
lmayencou 1:c53e766082b4 10 #define WHITE 1
lmayencou 1:c53e766082b4 11 #define BLACK 0
lmayencou 1:c53e766082b4 12
lmayencou 1:c53e766082b4 13 #define COLUMN_ADDRESS_END (WIDTH - 1) & 0x7F
lmayencou 1:c53e766082b4 14 #define PAGE_ADDRESS_END ((HEIGHT/8)-1) & 0x07
lmayencou 1:c53e766082b4 15
lmayencou 3:df305b314063 16 #define _BV(b) (1UL << (b))
lmayencou 3:df305b314063 17 #define min(a,b) (((a)<(b))?(a):(b))
lmayencou 3:df305b314063 18 #define max(a,b) (((a)>(b))?(a):(b))
lmayencou 3:df305b314063 19 #define abs(a) (((a) < 0) ? -(a) : (a))
lmayencou 3:df305b314063 20 #define pgm_read_byte(a) 1
lmayencou 3:df305b314063 21
lmayencou 3:df305b314063 22 #define LEFT_BUTTON _BV(0)
lmayencou 3:df305b314063 23 #define RIGHT_BUTTON _BV(1)
lmayencou 3:df305b314063 24 #define UP_BUTTON _BV(2)
lmayencou 3:df305b314063 25 #define DOWN_BUTTON _BV(3)
lmayencou 3:df305b314063 26 #define A_BUTTON _BV(4)
lmayencou 3:df305b314063 27 #define B_BUTTON _BV(5)
lmayencou 3:df305b314063 28
lmayencou 3:df305b314063 29 typedef bool boolean;
lmayencou 3:df305b314063 30 typedef uint8_t byte;
lmayencou 3:df305b314063 31
lmayencou 1:c53e766082b4 32 class AbstractArduboy
lmayencou 1:c53e766082b4 33 {
lmayencou 1:c53e766082b4 34 public:
lmayencou 1:c53e766082b4 35 AbstractArduboy();
lmayencou 1:c53e766082b4 36
lmayencou 1:c53e766082b4 37 // pure virtual function
lmayencou 1:c53e766082b4 38 virtual void start() = 0;
lmayencou 1:c53e766082b4 39
lmayencou 1:c53e766082b4 40 virtual long getTime() = 0;
lmayencou 1:c53e766082b4 41
lmayencou 1:c53e766082b4 42 virtual void LCDDataMode() = 0;
lmayencou 1:c53e766082b4 43 virtual void LCDCommandMode() = 0;
lmayencou 1:c53e766082b4 44 virtual void drawScreen(const unsigned char *image) = 0;
lmayencou 1:c53e766082b4 45
lmayencou 1:c53e766082b4 46 virtual uint8_t getInput() = 0;
lmayencou 1:c53e766082b4 47
lmayencou 1:c53e766082b4 48 // virtual
lmayencou 1:c53e766082b4 49 virtual void idle();
lmayencou 1:c53e766082b4 50 virtual void saveMuchPower();
lmayencou 3:df305b314063 51
lmayencou 3:df305b314063 52 // init
lmayencou 3:df305b314063 53 void begin(){start();};
lmayencou 1:c53e766082b4 54
lmayencou 1:c53e766082b4 55 // frame management
lmayencou 1:c53e766082b4 56 void setFrameRate(uint8_t rate);
lmayencou 1:c53e766082b4 57 bool nextFrame();
lmayencou 1:c53e766082b4 58 bool everyXFrames(uint8_t frames);
lmayencou 1:c53e766082b4 59
lmayencou 1:c53e766082b4 60 // info
lmayencou 1:c53e766082b4 61 int cpuLoad();
lmayencou 1:c53e766082b4 62
lmayencou 1:c53e766082b4 63 // buttons
lmayencou 1:c53e766082b4 64 void poll();
lmayencou 1:c53e766082b4 65 bool pressed(uint8_t buttons);
lmayencou 1:c53e766082b4 66 bool notPressed(uint8_t buttons);
lmayencou 1:c53e766082b4 67 bool justPressed(uint8_t buttons);
lmayencou 1:c53e766082b4 68
lmayencou 1:c53e766082b4 69 // graphics
lmayencou 1:c53e766082b4 70 void blank();
lmayencou 3:df305b314063 71 void clear();
lmayencou 1:c53e766082b4 72 void clearDisplay();
lmayencou 1:c53e766082b4 73 void display();
lmayencou 1:c53e766082b4 74 void drawPixel(int x, int y, uint8_t color);
lmayencou 1:c53e766082b4 75 uint8_t getPixel(uint8_t x, uint8_t y);
lmayencou 1:c53e766082b4 76 void drawCircle(int16_t x0, int16_t y0, int16_t r, uint8_t color);
lmayencou 1:c53e766082b4 77 void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint8_t color);
lmayencou 1:c53e766082b4 78 void fillCircle(int16_t x0, int16_t y0, int16_t r, uint8_t color);
lmayencou 1:c53e766082b4 79 void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint8_t color);
lmayencou 1:c53e766082b4 80 void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint8_t color);
lmayencou 1:c53e766082b4 81 void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t color);
lmayencou 1:c53e766082b4 82 void drawFastVLine(int16_t x, int16_t y, int16_t h, uint8_t color);
lmayencou 1:c53e766082b4 83 void drawFastHLine(int16_t x, int16_t y, int16_t w, uint8_t color);
lmayencou 1:c53e766082b4 84 void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t color);
lmayencou 1:c53e766082b4 85 void fillScreen(uint8_t color);
lmayencou 1:c53e766082b4 86 void drawRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint8_t color);
lmayencou 1:c53e766082b4 87 void fillRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint8_t color);
lmayencou 1:c53e766082b4 88 void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint8_t color);
lmayencou 1:c53e766082b4 89 void drawCompressed(int16_t sx, int16_t sy, const uint8_t *bitmap, uint8_t color);
lmayencou 1:c53e766082b4 90
lmayencou 1:c53e766082b4 91 void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size);
lmayencou 1:c53e766082b4 92 uint8_t writeChar(uint8_t);
lmayencou 3:df305b314063 93 inline void setCursor(int16_t x, int16_t y) { cursor_x = x; cursor_y = y; };
lmayencou 3:df305b314063 94 void setTextSize(uint8_t s) {textsize = max(1,s); };
lmayencou 1:c53e766082b4 95
lmayencou 1:c53e766082b4 96 static inline void swap(int16_t &a, int16_t &b);
lmayencou 3:df305b314063 97
lmayencou 3:df305b314063 98 // Audio
lmayencou 3:df305b314063 99 class ArduboyAudio
lmayencou 3:df305b314063 100 {
lmayencou 3:df305b314063 101 public:
lmayencou 3:df305b314063 102 ArduboyAudio(){audio_enabled = false;};
lmayencou 3:df305b314063 103 void setup();
lmayencou 3:df305b314063 104 void on();
lmayencou 3:df305b314063 105 void off();
lmayencou 3:df305b314063 106 void saveOnOff();
lmayencou 3:df305b314063 107 bool enabled();
lmayencou 3:df305b314063 108 void tone(unsigned int frequency, unsigned long duration);
lmayencou 3:df305b314063 109
lmayencou 3:df305b314063 110 protected:
lmayencou 3:df305b314063 111 bool audio_enabled;
lmayencou 3:df305b314063 112 }audio;
lmayencou 1:c53e766082b4 113
lmayencou 1:c53e766082b4 114 protected:
lmayencou 1:c53e766082b4 115 uint8_t frameRate;
lmayencou 1:c53e766082b4 116 uint16_t frameCount;
lmayencou 1:c53e766082b4 117 uint8_t eachFrameMillis;
lmayencou 1:c53e766082b4 118 long lastFrameStart;
lmayencou 1:c53e766082b4 119 long nextFrameStart ;
lmayencou 1:c53e766082b4 120 bool post_render;
lmayencou 1:c53e766082b4 121 uint8_t lastFrameDurationMs;
lmayencou 1:c53e766082b4 122
lmayencou 1:c53e766082b4 123 uint8_t currentButtonState;
lmayencou 1:c53e766082b4 124 uint8_t previousButtonState;
lmayencou 1:c53e766082b4 125
lmayencou 1:c53e766082b4 126 uint8_t sBuffer[(HEIGHT * WIDTH) / 8];
lmayencou 1:c53e766082b4 127
lmayencou 1:c53e766082b4 128 int16_t cursor_x, cursor_y;
lmayencou 1:c53e766082b4 129 uint16_t textcolor, textbgcolor;
lmayencou 1:c53e766082b4 130 uint8_t textsize;
lmayencou 1:c53e766082b4 131 uint8_t rotation;
lmayencou 1:c53e766082b4 132 bool wrap; // If set, 'wrap' text at right edge of display
lmayencou 1:c53e766082b4 133 };
lmayencou 1:c53e766082b4 134
lmayencou 1:c53e766082b4 135 #endif // ABSTRACTARDUBOY_H