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