|
| 1 | +#ifndef _API_H |
| 2 | +#define _API_H |
| 3 | + |
| 4 | +#ifdef __cplusplus |
| 5 | +extern "C" { |
| 6 | +#endif |
| 7 | + |
| 8 | +// Specify version compiled against. Semantic versioning enforcement takes place |
| 9 | +// in CHECK_VERSION |
| 10 | +#define MAJOR 1 |
| 11 | +#define MINOR 1 |
| 12 | +#define REVISION 0 |
| 13 | + |
| 14 | +#define byte unsigned char |
| 15 | + |
| 16 | +/* |
| 17 | + * Parameter Type Description |
| 18 | + * sprite *byte pointer to the sprite image data |
| 19 | + * x byte x coordinate |
| 20 | + * y byte y coordinate |
| 21 | + * w byte width of sprite |
| 22 | + * h byte height of sprite, must be multiple of 8 |
| 23 | + * f byte boolean that specifies whether or not to flip horizontally |
| 24 | + * m mode drawing mode, see below |
| 25 | + */ |
| 26 | +void DRAW_SPRITE(byte *sprite, byte x, byte y, byte w, byte h, byte f, byte m); |
| 27 | +/* normal, replaces everything underneath the sprite */ |
| 28 | +#define DRAW_NOP 0x0 |
| 29 | +/* logical OR, fastest mode */ |
| 30 | +#define DRAW_OR 0x1 |
| 31 | +/* logical AND */ |
| 32 | +#define DRAW_AND 0x2 |
| 33 | +/* logical XOR */ |
| 34 | +#define DRAW_XOR 0x4 |
| 35 | + |
| 36 | +/* Push video memory to the OLED (expensive) */ |
| 37 | +void DISPLAY(); |
| 38 | + |
| 39 | +/* |
| 40 | +Erases the rectangular portiion of the screen defined by the parameters. Note |
| 41 | +that background graphics will be erased as well. |
| 42 | +
|
| 43 | +Parameter Type Description |
| 44 | +x byte x coordinate |
| 45 | +y byte y coordinate |
| 46 | +w byte width |
| 47 | +h byte height, must be multiple of 8 |
| 48 | +*/ |
| 49 | +void CLEAR_SPRITE(byte x, byte y, byte w, byte h); |
| 50 | + |
| 51 | +/* |
| 52 | +Sets a pixel to a specific color |
| 53 | +Parameter Type Description |
| 54 | +x byte x coordinate |
| 55 | +y byte y coordinate |
| 56 | +c byte color, 0 for black, 1 for white |
| 57 | +*/ |
| 58 | +void SET_PIXEL(byte x, byte y, byte c); |
| 59 | + |
| 60 | +/* |
| 61 | +Bresenham line algorithm |
| 62 | +
|
| 63 | +Parameter Type Description |
| 64 | +x0 byte x coordinate of first point |
| 65 | +y0 byte y coordinate of first point |
| 66 | +x1 byte x coordinate of second point |
| 67 | +y1 byte y coordinate of second point |
| 68 | +c byte color, 0 for black, 1 for white |
| 69 | +Note: Computationally expensive, it is recommended to draw lines sparingly. |
| 70 | +*/ |
| 71 | +void DRAW_LINE(byte x0, byte y0, byte x1, byte y1, byte c); |
| 72 | + |
| 73 | +void DELAY_MS(byte delay); |
| 74 | +void LED_ON(); |
| 75 | +void LED_OFF(); |
| 76 | + |
| 77 | +/* Waits for an interrupt to fire. WAIT() should be called at the end of the |
| 78 | + * game loop in order to synchronize the frame rate to a consistent 20 FPS. */ |
| 79 | +void WAIT(); |
| 80 | + |
| 81 | +void LOAD_MUSIC(byte *music); |
| 82 | +void PLAY_EFFECT(byte *effect); |
| 83 | +void PLAY_EFFECT_ONCE(byte *effect); |
| 84 | +void SPI_ENABLE(); |
| 85 | +void SPI_DISABLE(); |
| 86 | +void SPI_WRITE(byte v); |
| 87 | + |
| 88 | +/* Clear the graphics in video memory */ |
| 89 | +void CLEAR(); |
| 90 | + |
| 91 | +/* |
| 92 | +Copying the background back and forth between video memory and a buffer is |
| 93 | +useful for games with background graphics. This technique would be used |
| 94 | +instead of calling CLEAR_SPRITE(). Typically a game should copy the |
| 95 | +background where a sprite will be drawn, draw the sprite, call DISPLAY() to |
| 96 | +show the graphics, and then erase the sprite by copying the buffer back into |
| 97 | +video memory. |
| 98 | +
|
| 99 | +The buffer needs to be a page taller than the sprite. For instance, if the |
| 100 | +sprite is 24x16 pixels (2 pages tall, 48 total bytes). The buffer needs to |
| 101 | +be 24*24 pixels (3 pages tall, 72 total bytes) |
| 102 | +
|
| 103 | +Parameter Type Description |
| 104 | +data *byte pointer to byte array |
| 105 | +x byte x coordinate |
| 106 | +y byte y coordinate |
| 107 | +w byte width |
| 108 | +h byte height |
| 109 | +dir byte direction, 0 = vmem -> buffer, 1 = buffer -> vmem |
| 110 | +*/ |
| 111 | +void COPY_BACKGROUND(byte *data, byte x, byte y, byte w, byte h, byte dir); |
| 112 | + |
| 113 | +void DRAW_STRING(const char *text); |
| 114 | +void SET_CURSOR(byte row, byte col); |
| 115 | + |
| 116 | +/* Returns a byte that is packed with the button state. For each bit that is |
| 117 | + * unset the corresponding button is pushed. |
| 118 | + * Bit Position Mask Button |
| 119 | + * 1 1 up |
| 120 | + * 2 2 down |
| 121 | + * 3 4 left |
| 122 | + * 4 8 right |
| 123 | + * 5 16 a |
| 124 | + * 6 32 b |
| 125 | + */ |
| 126 | +byte READ_BUTTONS(); |
| 127 | + |
| 128 | +void GET_PIXEL(byte x, byte y); |
| 129 | + |
| 130 | +void GET_VERSION(byte *p); |
| 131 | +void CHECK_VERSION(byte major, byte minor, byte revision); |
| 132 | + |
| 133 | +void LOAD_PERSISTENT(byte *buffer); |
| 134 | +void SAVE_PERSISTENT(byte *buffer); |
| 135 | + |
| 136 | +// This will spin forever if there is a version mismatch |
| 137 | +#define api_init() CHECK_VERSION(MAJOR, MINOR, REVISION) |
| 138 | + |
| 139 | +#ifdef __cplusplus |
| 140 | +} // extern "C" |
| 141 | +#endif |
| 142 | + |
| 143 | +#endif |
0 commit comments