commit 9b95d77
0uppy
·
2026-07-22 23:48:50 +0000 UTC
parent ec080c8
sidequest commit to say i have reformated all of cotton to use k&4 per sewn's request kthxbye
8 files changed,
+1013,
-938
+13,
-15
1@@ -1,33 +1,31 @@
2 #include "cotton.h"
3+#include <stdio.h>
4+#include <stdlib.h>
5 #include <string.h>
6 #include <time.h>
7-#include <stdlib.h>
8-#include <stdio.h>
9
10-void cotton_init(Cotton *c)
11+void cotton_init
12+(Cotton *c)
13 {
14 memset(c, 0, sizeof(Cotton));
15
16 srand((unsigned int)time(NULL));
17
18 c->c_cottolette = COTTOLETTE[1];
19-
20 }
21
22-void cotton_store_var(Cotton *cotton, const char *name, const char *value)
23+void cotton_store_var
24+(Cotton *cotton, const char *name, const char *value)
25 {
26- for (int i = 0; i < cotton->var_count; i++)
27- {
28- if (strcmp(cotton->vars[i].name, name) == 0)
29- {
30+ for (int i = 0; i < cotton->var_count; i++) {
31+ if (strcmp(cotton->vars[i].name, name) == 0) {
32 strncpy(cotton->vars[i].value, value, VAR_VAL_LEN - 1);
33 cotton->vars[i].value[VAR_VAL_LEN - 1] = '\0';
34 return;
35 }
36 }
37
38- if (cotton->var_count < VARS)
39- {
40+ if (cotton->var_count < VARS) {
41 strncpy(cotton->vars[cotton->var_count].name, name, VAR_NAME_LEN - 1);
42 cotton->vars[cotton->var_count].name[VAR_NAME_LEN - 1] = '\0';
43
44@@ -35,9 +33,9 @@ void cotton_store_var(Cotton *cotton, const char *name, const char *value)
45 cotton->vars[cotton->var_count].value[VAR_VAL_LEN - 1] = '\0';
46
47 cotton->var_count++;
48- }
49- else
50- {
51- fprintf(stderr, "cotton ran out of variable slots :( - max ammount is %d\n", VARS);
52+ } else {
53+ fprintf(stderr,
54+ "cotton ran out of variable slots :( - max ammount is %d\n",
55+ VARS);
56 }
57 }
+22,
-14
1@@ -3,19 +3,23 @@
2
3 #include <stdint.h>
4
5-#define MEMORY_SIZE (64 * 1024)
6-#define VIDEO_WIDTH 250
7+#define MEMORY_SIZE (64 * 1024)
8+#define VIDEO_WIDTH 250
9 #define VIDEO_HEIGHT 200
10
11-#define COTTOLETTE_SIZE 7 // would be 6 but due to high demand we invited green into the mix because green is cool <3
12+#define COTTOLETTE_SIZE \
13+ 7 // would be 6 but due to high demand we invited green into the mix because
14+ // green is cool <3
15
16-#define VARS 32 // i think this is enough,, not like cot programs can be that complex rn anyway :P
17+#define VARS \
18+ 32 // i think this is enough,, not like cot programs can be that complex rn
19+ // anyway :P
20 #define VAR_NAME_LEN 16
21-#define VAR_VAL_LEN 32
22+#define VAR_VAL_LEN 32
23
24 // i might work on better names another time xP
25-static const uint32_t COTTOLETTE[COTTOLETTE_SIZE] =
26-{
27+static const uint32_t
28+COTTOLETTE[COTTOLETTE_SIZE] = {
29 0xFF000000, // 0 - black
30 0xFFFFFFFF, // 1 - white
31 0xFF28262C, // 2 - rey
32@@ -33,22 +37,26 @@ typedef struct
33
34 typedef struct
35 {
36- uint8_t memory[MEMORY_SIZE];
37+ uint8_t memory[MEMORY_SIZE];
38 uint32_t video[VIDEO_WIDTH * VIDEO_HEIGHT];
39
40- // i cant come up with a better name that gets straight to the point than "cursor" so ig it will stay this way for now,,
41+ // i cant come up with a better name that gets straight to the point than
42+ // "cursor" so ig it will stay this way for now,,
43 int cursor_x;
44 int cursor_y;
45
46 uint32_t ticktock;
47- uint32_t c_cottolette; //id write "current_cottolete" but that would be alot to type and im lazyyyyyyy bwaaaaaa
48-
49+ uint32_t c_cottolette; // id write "current_cottolete" but that would be
50+ // alot to type and im lazyyyyyyy bwaaaaaa
51+
52 CotVar vars[VARS];
53- int var_count;
54+ int var_count;
55
56 } Cotton;
57
58-void cotton_init(Cotton *c);
59-void cotton_store_var(Cotton *cotton, const char *name, const char *value);
60+void cotton_init
61+(Cotton *c);
62+void cotton_store_var
63+(Cotton *cotton, const char *name, const char *value);
64
65 #endif
+34,
-32
1@@ -1,40 +1,44 @@
2 #include "cottonwindow.h"
3 #include <stdio.h>
4
5-int cottonwindow_init(CottonWindow *cw, const char *title, int window_w, int window_h, int texture_w, int texture_h)
6+int
7+cottonwindow_init (CottonWindow *cw, const char *title, int window_w, int window_h, int texture_w, int texture_h)
8 {
9
10- if (SDL_Init(SDL_INIT_VIDEO) != 0)
11- {
12+ if (SDL_Init(SDL_INIT_VIDEO) != 0) {
13 fprintf(stderr, "cotton couldn't start SDL :( : %s\n", SDL_GetError());
14 return 0;
15 }
16
17- cw->window = SDL_CreateWindow(title, 0, 0, window_w, window_h, SDL_WINDOW_SHOWN);
18- if (!cw->window)
19- {
20- fprintf(stderr, "cotton couldn't create a window :( : %s\n", SDL_GetError());
21+ cw->window =
22+ SDL_CreateWindow(title, 0, 0, window_w, window_h, SDL_WINDOW_SHOWN);
23+ if (!cw->window) {
24+ fprintf(stderr, "cotton couldn't create a window :( : %s\n",
25+ SDL_GetError());
26 return 0;
27 }
28
29 cw->renderer = SDL_CreateRenderer(cw->window, -1, 0);
30- if (!cw->renderer)
31- {
32- fprintf(stderr, "cotton couldn't render this :( : %s\n", SDL_GetError());
33+ if (!cw->renderer) {
34+ fprintf(stderr, "cotton couldn't render this :( : %s\n",
35+ SDL_GetError());
36 return 0;
37 }
38
39- cw->texture = SDL_CreateTexture(cw->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, texture_w, texture_h);
40- if (!cw->texture)
41- {
42- fprintf(stderr, "cotton couldn't apply textures :( : %s\n", SDL_GetError());
43+ cw->texture =
44+ SDL_CreateTexture(cw->renderer, SDL_PIXELFORMAT_ARGB8888,
45+ SDL_TEXTUREACCESS_STREAMING, texture_w, texture_h);
46+ if (!cw->texture) {
47+ fprintf(stderr, "cotton couldn't apply textures :( : %s\n",
48+ SDL_GetError());
49 return 0;
50 }
51
52 return 1;
53 }
54
55-void cottonwindow_update(CottonWindow *cw, const void *buffer, int pitch)
56+void
57+cottonwindow_update(CottonWindow *cw, const void *buffer, int pitch)
58 {
59 SDL_UpdateTexture(cw->texture, NULL, buffer, pitch);
60 SDL_RenderClear(cw->renderer);
61@@ -42,36 +46,34 @@ void cottonwindow_update(CottonWindow *cw, const void *buffer, int pitch)
62 SDL_RenderPresent(cw->renderer);
63 }
64
65-int cottonwindow_process_input(CottonWindow *cw, uint8_t *keys)
66+int cottonwindow_process_input
67+(CottonWindow *cw, uint8_t *keys)
68 {
69 (void)cw;
70 (void)keys;
71 int quit = 0;
72 SDL_Event event;
73
74- while (SDL_PollEvent(&event))
75- {
76- switch (event.type)
77- {
78- case SDL_QUIT:
79- {
80- quit = 1;
81- break;
82- }
83+ while (SDL_PollEvent(&event)) {
84+ switch (event.type) {
85+ case SDL_QUIT: {
86+ quit = 1;
87+ break;
88+ }
89
90- case SDL_KEYDOWN:
91- {
92- if (event.key.keysym.sym == SDLK_ESCAPE)
93- quit = 1;
94- break;
95- }
96+ case SDL_KEYDOWN: {
97+ if (event.key.keysym.sym == SDLK_ESCAPE)
98+ quit = 1;
99+ break;
100+ }
101 }
102 }
103
104 return quit;
105 }
106
107-void cottonwindow_destroy(CottonWindow *cw)
108+void cottonwindow_destroy
109+(CottonWindow *cw)
110 {
111 SDL_DestroyTexture(cw->texture);
112 SDL_DestroyRenderer(cw->renderer);
+10,
-6
1@@ -6,15 +6,19 @@
2
3 typedef struct
4 {
5- SDL_Window *window;
6+ SDL_Window *window;
7 SDL_Renderer *renderer;
8- SDL_Texture *texture;
9+ SDL_Texture *texture;
10
11 } CottonWindow;
12
13-int cottonwindow_init(CottonWindow *cw, const char *title, int window_w, int window_h, int texture_w, int texture_h);
14-void cottonwindow_update(CottonWindow *cw, const void *buffer, int pitch);
15-int cottonwindow_process_input(CottonWindow *cw, uint8_t *keys);
16-void cottonwindow_destroy(CottonWindow *cw);
17+int cottonwindow_init
18+(CottonWindow *cw, const char *title, int window_w, int window_h, int texture_w, int texture_h);
19+void cottonwindow_update
20+(CottonWindow *cw, const void *buffer, int pitch);
21+int cottonwindow_process_input
22+(CottonWindow *cw, uint8_t *keys);
23+void cottonwindow_destroy
24+(CottonWindow *cw);
25
26 #endif
+819,
-750
1@@ -3,758 +3,827 @@
2
3 #include <stdint.h>
4
5-#define FONT_WIDTH 6
6+#define FONT_WIDTH 6
7 #define FONT_HEIGHT 8
8
9-static const uint8_t EIKI_FONT[256][FONT_HEIGHT] = {
10-
11-[' '] = {
12- 0b00000000,
13- 0b00000000,
14- 0b00000000,
15- 0b00000000,
16- 0b00000000,
17- 0b00000000,
18- 0b00000000,
19- 0b00000000,
20-},
21-
22-['A'] = {
23- 0b00000000,
24- 0b00011110,
25- 0b00100001,
26- 0b00100001,
27- 0b00111111,
28- 0b00100001,
29- 0b00110011,
30- 0b00000000,
31-},
32-
33-['B'] = {
34- 0b00000000,
35- 0b00011110,
36- 0b00100010,
37- 0b00011110,
38- 0b00100010,
39- 0b00100010,
40- 0b00011110,
41- 0b00000000,
42-},
43-
44-['C'] = {
45- 0b00000000,
46- 0b00011110,
47- 0b00100001,
48- 0b00000001,
49- 0b00000001,
50- 0b00100001,
51- 0b00011110,
52- 0b00000000,
53-},
54-
55-['D'] = {
56- 0b00000000,
57- 0b00011110,
58- 0b00100010,
59- 0b00100010,
60- 0b00100010,
61- 0b00010010,
62- 0b00001110,
63- 0b00000000,
64-},
65-
66-['E'] = {
67- 0b00000000,
68- 0b00011111,
69- 0b00000001,
70- 0b00000111,
71- 0b00000001,
72- 0b00000001,
73- 0b00011111,
74- 0b00000000,
75-},
76-
77-['F'] = {
78- 0b00000000,
79- 0b00011111,
80- 0b00000001,
81- 0b00000111,
82- 0b00000001,
83- 0b00000001,
84- 0b00000001,
85- 0b00000000,
86-},
87-
88-['G'] = {
89- 0b00000000,
90- 0b00011110,
91- 0b00010001,
92- 0b00000001,
93- 0b00011001,
94- 0b00010001,
95- 0b00001110,
96- 0b00000000,
97-},
98-
99-['H'] = {
100- 0b00000000,
101- 0b00010010,
102- 0b00010010,
103- 0b00011110,
104- 0b00010010,
105- 0b00010010,
106- 0b00010010,
107- 0b00000000,
108-},
109-
110-['I'] = {
111- 0b00000000,
112- 0b00001110,
113- 0b00000100,
114- 0b00000100,
115- 0b00000100,
116- 0b00000100,
117- 0b00001110,
118- 0b00000000,
119-},
120-
121-['J'] = {
122- 0b00000000,
123- 0b00011100,
124- 0b00001000,
125- 0b00001000,
126- 0b00001000,
127- 0b00001001,
128- 0b00000111,
129- 0b00000000,
130-},
131-
132-['K'] = {
133- 0b00000000,
134- 0b00010010,
135- 0b00010010,
136- 0b00001010,
137- 0b00000110,
138- 0b00001010,
139- 0b00010010,
140- 0b00000000,
141-},
142-
143-['L'] = {
144- 0b00000000,
145- 0b00000100,
146- 0b00000100,
147- 0b00000100,
148- 0b00000100,
149- 0b00100100,
150- 0b00111100,
151- 0b00000000,
152-},
153-
154-['M'] = {
155- 0b00000000,
156- 0b00100001,
157- 0b00110011,
158- 0b00101101,
159- 0b00100001,
160- 0b00100001,
161- 0b00100001,
162- 0b00000000,
163-},
164-
165-['N'] = {
166- 0b00000000,
167- 0b00010010,
168- 0b00010110,
169- 0b00011010,
170- 0b00010010,
171- 0b00010010,
172- 0b00010010,
173- 0b00000000,
174-},
175-
176-['O'] = {
177- 0b00000000,
178- 0b00011110,
179- 0b00100001,
180- 0b00100001,
181- 0b00100001,
182- 0b00100001,
183- 0b00011110,
184- 0b00000000,
185-},
186-
187-['P'] = {
188- 0b00000000,
189- 0b00011111,
190- 0b00100001,
191- 0b00100001,
192- 0b00011111,
193- 0b00000001,
194- 0b00000001,
195- 0b00000000,
196-},
197-
198-['Q'] = {
199- 0b00000000,
200- 0b00011110,
201- 0b00100001,
202- 0b00100001,
203- 0b00101001,
204- 0b00110001,
205- 0b00011110,
206- 0b00000000,
207-},
208-
209-['R'] = {
210- 0b00000000,
211- 0b00011110,
212- 0b00100010,
213- 0b00100010,
214- 0b00011110,
215- 0b00100010,
216- 0b00100010,
217- 0b00000000,
218-},
219-
220-['S'] = {
221- 0b00000000,
222- 0b00001110,
223- 0b00010001,
224- 0b00000110,
225- 0b00001000,
226- 0b00010001,
227- 0b00001110,
228- 0b00000000,
229-},
230-
231-['T'] = {
232- 0b00000000,
233- 0b00111111,
234- 0b00000100,
235- 0b00000100,
236- 0b00000100,
237- 0b00000100,
238- 0b00001110,
239- 0b00000000,
240-},
241-
242-['U'] = {
243- 0b00000000,
244- 0b00100001,
245- 0b00100001,
246- 0b00100001,
247- 0b00100001,
248- 0b00100001,
249- 0b00011110,
250- 0b00000000,
251-},
252-
253-['V'] = {
254- 0b00000000,
255- 0b00100001,
256- 0b00100001,
257- 0b00010010,
258- 0b00010010,
259- 0b00001100,
260- 0b00000100,
261- 0b00000000,
262-},
263-
264-['W'] = {
265- 0b00000000,
266- 0b00100001,
267- 0b00100001,
268- 0b00100001,
269- 0b00101101,
270- 0b00110011,
271- 0b00100001,
272- 0b00000000,
273-},
274-
275-['X'] = {
276- 0b00000000,
277- 0b00100001,
278- 0b00100001,
279- 0b00010010,
280- 0b00001100,
281- 0b00010010,
282- 0b00100001,
283- 0b00000000,
284-},
285-
286-['Y'] = {
287- 0b00000000,
288- 0b00100001,
289- 0b00100001,
290- 0b00010010,
291- 0b00001100,
292- 0b00001100,
293- 0b00001100,
294- 0b00000000,
295-},
296-
297-['Z'] = {
298- 0b00000000,
299- 0b00111111,
300- 0b00010000,
301- 0b00001000,
302- 0b00000100,
303- 0b00000010,
304- 0b00111111,
305- 0b00000000,
306-},
307-
308-['a'] = {
309- 0b00000000,
310- 0b00000000,
311- 0b00001110,
312- 0b00010000,
313- 0b00011110,
314- 0b00010010,
315- 0b00011110,
316- 0b00000000,
317-},
318-
319-['b'] = {
320- 0b00000000,
321- 0b00000010,
322- 0b00000010,
323- 0b00011110,
324- 0b00010010,
325- 0b00010010,
326- 0b00011110,
327- 0b00000000,
328-},
329-
330-['c'] = {
331- 0b00000000,
332- 0b00000000,
333- 0b00011110,
334- 0b00000001,
335- 0b00000001,
336- 0b00000001,
337- 0b00011110,
338- 0b00000000,
339-},
340-
341-['d'] = {
342- 0b00000000,
343- 0b00010000,
344- 0b00010000,
345- 0b00011110,
346- 0b00010010,
347- 0b00010010,
348- 0b00011110,
349- 0b00000000,
350-},
351-
352-['e'] = {
353- 0b00000000,
354- 0b00000000,
355- 0b00011110,
356- 0b00010001,
357- 0b00111111,
358- 0b00000001,
359- 0b00011110,
360- 0b00000000,
361-},
362-
363-['f'] = {
364- 0b00011000,
365- 0b00000100,
366- 0b00111110,
367- 0b00000100,
368- 0b00000100,
369- 0b00000100,
370- 0b00000100,
371- 0b00000000,
372-},
373-
374-['g'] = {
375- 0b00000000,
376- 0b00000000,
377- 0b00011110,
378- 0b00010010,
379- 0b00011110,
380- 0b00010000,
381- 0b00010000,
382- 0b00001110,
383-},
384-
385-['h'] = {
386- 0b00000000,
387- 0b00000010,
388- 0b00000010,
389- 0b00011110,
390- 0b00010010,
391- 0b00010010,
392- 0b00010010,
393- 0b00000000,
394-},
395-
396-['i'] = {
397- 0b00000000,
398- 0b00000100,
399- 0b00000000,
400- 0b00000100,
401- 0b00000100,
402- 0b00000100,
403- 0b00001100,
404- 0b00000000,
405-},
406-
407-['j'] = {
408- 0b00001000,
409- 0b00000000,
410- 0b00001000,
411- 0b00001000,
412- 0b00001000,
413- 0b00001000,
414- 0b00001000,
415- 0b00001110,
416-},
417-
418-['k'] = {
419- 0b00000001,
420- 0b00000001,
421- 0b00001001,
422- 0b00000101,
423- 0b00000011,
424- 0b00000101,
425- 0b00001001,
426- 0b00000000,
427-},
428-
429-['l'] = {
430- 0b00000000,
431- 0b00000100,
432- 0b00000100,
433- 0b00000100,
434- 0b00000100,
435- 0b00000100,
436- 0b00111100,
437- 0b00000000,
438-},
439-
440-['m'] = {
441- 0b00000000,
442- 0b00000000,
443- 0b00110110,
444- 0b00101010,
445- 0b00101010,
446- 0b00101010,
447- 0b00101010,
448- 0b00000000,
449-},
450-
451-['n'] = {
452- 0b00000000,
453- 0b00000000,
454- 0b00011100,
455- 0b00010010,
456- 0b00010010,
457- 0b00010010,
458- 0b00010010,
459- 0b00000000,
460-},
461-
462-['o'] = {
463- 0b00000000,
464- 0b00000000,
465- 0b00000000,
466- 0b00001110,
467- 0b00010001,
468- 0b00010001,
469- 0b00001110,
470- 0b00000000,
471-},
472-
473-['p'] = {
474- 0b00000000,
475- 0b00000000,
476- 0b00011110,
477- 0b00010010,
478- 0b00011110,
479- 0b00000010,
480- 0b00000010,
481- 0b00000010,
482-},
483-
484-['q'] = {
485- 0b00000000,
486- 0b00000000,
487- 0b00011110,
488- 0b00010010,
489- 0b00011110,
490- 0b00010000,
491- 0b00010000,
492- 0b00000000,
493-},
494-
495-['r'] = {
496- 0b00000000,
497- 0b00000000,
498- 0b00001110,
499- 0b00010010,
500- 0b00000010,
501- 0b00000010,
502- 0b00000010,
503- 0b00000000,
504-},
505-
506-['s'] = {
507- 0b00000000,
508- 0b00000000,
509- 0b00011110,
510- 0b00000001,
511- 0b00011110,
512- 0b00100000,
513- 0b00011110,
514- 0b00000000,
515-},
516-
517-['t'] = {
518- 0b00001000,
519- 0b00001000,
520- 0b00111110,
521- 0b00001000,
522- 0b00001000,
523- 0b00001000,
524- 0b00010000,
525- 0b00000000,
526-},
527-
528-['u'] = {
529- 0b00000000,
530- 0b00000000,
531- 0b00010001,
532- 0b00010001,
533- 0b00010001,
534- 0b00010001,
535- 0b00011110,
536- 0b00000000,
537-},
538-
539-['v'] = {
540- 0b00000000,
541- 0b00000000,
542- 0b00010001,
543- 0b00010001,
544- 0b00001010,
545- 0b00001010,
546- 0b00000100,
547- 0b00000000,
548-},
549-
550-['w'] = {
551- 0b00000000,
552- 0b00000000,
553- 0b00010001,
554- 0b00010001,
555- 0b00010101,
556- 0b00010101,
557- 0b00001010,
558- 0b00000000,
559-},
560-
561-['x'] = {
562- 0b00000000,
563- 0b00000000,
564- 0b00010001,
565- 0b00001010,
566- 0b00000100,
567- 0b00001010,
568- 0b00010001,
569- 0b00000000,
570-},
571-
572-['y'] = {
573- 0b00000000,
574- 0b00000000,
575- 0b00010001,
576- 0b00010001,
577- 0b00011110,
578- 0b00100000,
579- 0b00011110,
580- 0b00000000,
581-},
582-
583-['z'] = {
584- 0b00000000,
585- 0b00000000,
586- 0b00111111,
587- 0b00010000,
588- 0b00001000,
589- 0b00000100,
590- 0b00111111,
591- 0b00000000,
592-},
593-
594-['0'] = {
595- 0b00000000,
596- 0b00011110,
597- 0b00100001,
598- 0b00100001,
599- 0b00100001,
600- 0b00100001,
601- 0b00011110,
602- 0b00000000,
603-},
604-
605-['1'] = {
606- 0b00000000,
607- 0b00001100,
608- 0b00001000,
609- 0b00001000,
610- 0b00001000,
611- 0b00001000,
612- 0b00111110,
613- 0b00000000,
614-},
615-
616-['2'] = {
617- 0b00000000,
618- 0b00011110,
619- 0b00100000,
620- 0b00011000,
621- 0b00000100,
622- 0b00000010,
623- 0b00111110,
624- 0b00000000,
625-},
626-
627-['3'] = {
628- 0b00000000,
629- 0b00111111,
630- 0b00100000,
631- 0b00011110,
632- 0b00100000,
633- 0b00100000,
634- 0b00111111,
635- 0b00000000,
636-},
637-
638-['4'] = {
639- 0b00000000,
640- 0b00010001,
641- 0b00010001,
642- 0b00111111,
643- 0b00010000,
644- 0b00010000,
645- 0b00010000,
646- 0b00000000,
647-},
648-
649-['5'] = {
650- 0b00000000,
651- 0b00111111,
652- 0b00000001,
653- 0b00011111,
654- 0b00100000,
655- 0b00100000,
656- 0b00011111,
657- 0b00000000,
658-},
659-
660-['6'] = {
661- 0b00000000,
662- 0b00011110,
663- 0b00000001,
664- 0b00011111,
665- 0b00100001,
666- 0b00100001,
667- 0b00011110,
668- 0b00000000,
669-},
670-
671-['7'] = {
672- 0b00000000,
673- 0b00111111,
674- 0b00100000,
675- 0b00010000,
676- 0b00001000,
677- 0b00001000,
678- 0b00001000,
679- 0b00000000,
680-},
681-
682-['8'] = {
683- 0b00000000,
684- 0b00011110,
685- 0b00100001,
686- 0b00011110,
687- 0b00100001,
688- 0b00100001,
689- 0b00011110,
690- 0b00000000,
691-},
692-
693-['9'] = {
694- 0b00000000,
695- 0b00011110,
696- 0b00100001,
697- 0b00111110,
698- 0b00100000,
699- 0b00100000,
700- 0b00011110,
701- 0b00000000,
702-},
703-
704-['?'] = {
705- 0b00000000,
706- 0b00011110,
707- 0b00100001,
708- 0b00010000,
709- 0b00001000,
710- 0b00000000,
711- 0b00001000,
712- 0b00000000,
713-},
714-
715-['!'] = {
716- 0b00000000,
717- 0b00001100,
718- 0b00001100,
719- 0b00000100,
720- 0b00000100,
721- 0b00000000,
722- 0b00000100,
723- 0b00000000,
724-},
725-
726-[':'] = {
727- 0b00000000,
728- 0b00001100,
729- 0b00001100,
730- 0b00000000,
731- 0b00001100,
732- 0b00001100,
733- 0b00000000,
734- 0b00000000,
735-},
736-
737-[';'] = {
738- 0b00000000,
739- 0b00001100,
740- 0b00001100,
741- 0b00000000,
742- 0b00001100,
743- 0b00001100,
744- 0b00001000,
745- 0b00000000,
746-},
747-
748-['.'] = {
749- 0b00000000,
750- 0b00000000,
751- 0b00000000,
752- 0b00000000,
753- 0b00000000,
754- 0b00001100,
755- 0b00001100,
756- 0b00000000,
757-},
758+static const uint8_t
759+EIKI_FONT[256][FONT_HEIGHT] = {
760+
761+ [' '] =
762+ {
763+ 0b00000000,
764+ 0b00000000,
765+ 0b00000000,
766+ 0b00000000,
767+ 0b00000000,
768+ 0b00000000,
769+ 0b00000000,
770+ 0b00000000,
771+ },
772+
773+ ['A'] =
774+ {
775+ 0b00000000,
776+ 0b00011110,
777+ 0b00100001,
778+ 0b00100001,
779+ 0b00111111,
780+ 0b00100001,
781+ 0b00110011,
782+ 0b00000000,
783+ },
784+
785+ ['B'] =
786+ {
787+ 0b00000000,
788+ 0b00011110,
789+ 0b00100010,
790+ 0b00011110,
791+ 0b00100010,
792+ 0b00100010,
793+ 0b00011110,
794+ 0b00000000,
795+ },
796+
797+ ['C'] =
798+ {
799+ 0b00000000,
800+ 0b00011110,
801+ 0b00100001,
802+ 0b00000001,
803+ 0b00000001,
804+ 0b00100001,
805+ 0b00011110,
806+ 0b00000000,
807+ },
808+
809+ ['D'] =
810+ {
811+ 0b00000000,
812+ 0b00011110,
813+ 0b00100010,
814+ 0b00100010,
815+ 0b00100010,
816+ 0b00010010,
817+ 0b00001110,
818+ 0b00000000,
819+ },
820+
821+ ['E'] =
822+ {
823+ 0b00000000,
824+ 0b00011111,
825+ 0b00000001,
826+ 0b00000111,
827+ 0b00000001,
828+ 0b00000001,
829+ 0b00011111,
830+ 0b00000000,
831+ },
832+
833+ ['F'] =
834+ {
835+ 0b00000000,
836+ 0b00011111,
837+ 0b00000001,
838+ 0b00000111,
839+ 0b00000001,
840+ 0b00000001,
841+ 0b00000001,
842+ 0b00000000,
843+ },
844+
845+ ['G'] =
846+ {
847+ 0b00000000,
848+ 0b00011110,
849+ 0b00010001,
850+ 0b00000001,
851+ 0b00011001,
852+ 0b00010001,
853+ 0b00001110,
854+ 0b00000000,
855+ },
856+
857+ ['H'] =
858+ {
859+ 0b00000000,
860+ 0b00010010,
861+ 0b00010010,
862+ 0b00011110,
863+ 0b00010010,
864+ 0b00010010,
865+ 0b00010010,
866+ 0b00000000,
867+ },
868+
869+ ['I'] =
870+ {
871+ 0b00000000,
872+ 0b00001110,
873+ 0b00000100,
874+ 0b00000100,
875+ 0b00000100,
876+ 0b00000100,
877+ 0b00001110,
878+ 0b00000000,
879+ },
880+
881+ ['J'] =
882+ {
883+ 0b00000000,
884+ 0b00011100,
885+ 0b00001000,
886+ 0b00001000,
887+ 0b00001000,
888+ 0b00001001,
889+ 0b00000111,
890+ 0b00000000,
891+ },
892+
893+ ['K'] =
894+ {
895+ 0b00000000,
896+ 0b00010010,
897+ 0b00010010,
898+ 0b00001010,
899+ 0b00000110,
900+ 0b00001010,
901+ 0b00010010,
902+ 0b00000000,
903+ },
904+
905+ ['L'] =
906+ {
907+ 0b00000000,
908+ 0b00000100,
909+ 0b00000100,
910+ 0b00000100,
911+ 0b00000100,
912+ 0b00100100,
913+ 0b00111100,
914+ 0b00000000,
915+ },
916+
917+ ['M'] =
918+ {
919+ 0b00000000,
920+ 0b00100001,
921+ 0b00110011,
922+ 0b00101101,
923+ 0b00100001,
924+ 0b00100001,
925+ 0b00100001,
926+ 0b00000000,
927+ },
928+
929+ ['N'] =
930+ {
931+ 0b00000000,
932+ 0b00010010,
933+ 0b00010110,
934+ 0b00011010,
935+ 0b00010010,
936+ 0b00010010,
937+ 0b00010010,
938+ 0b00000000,
939+ },
940+
941+ ['O'] =
942+ {
943+ 0b00000000,
944+ 0b00011110,
945+ 0b00100001,
946+ 0b00100001,
947+ 0b00100001,
948+ 0b00100001,
949+ 0b00011110,
950+ 0b00000000,
951+ },
952+
953+ ['P'] =
954+ {
955+ 0b00000000,
956+ 0b00011111,
957+ 0b00100001,
958+ 0b00100001,
959+ 0b00011111,
960+ 0b00000001,
961+ 0b00000001,
962+ 0b00000000,
963+ },
964+
965+ ['Q'] =
966+ {
967+ 0b00000000,
968+ 0b00011110,
969+ 0b00100001,
970+ 0b00100001,
971+ 0b00101001,
972+ 0b00110001,
973+ 0b00011110,
974+ 0b00000000,
975+ },
976+
977+ ['R'] =
978+ {
979+ 0b00000000,
980+ 0b00011110,
981+ 0b00100010,
982+ 0b00100010,
983+ 0b00011110,
984+ 0b00100010,
985+ 0b00100010,
986+ 0b00000000,
987+ },
988+
989+ ['S'] =
990+ {
991+ 0b00000000,
992+ 0b00001110,
993+ 0b00010001,
994+ 0b00000110,
995+ 0b00001000,
996+ 0b00010001,
997+ 0b00001110,
998+ 0b00000000,
999+ },
1000+
1001+ ['T'] =
1002+ {
1003+ 0b00000000,
1004+ 0b00111111,
1005+ 0b00000100,
1006+ 0b00000100,
1007+ 0b00000100,
1008+ 0b00000100,
1009+ 0b00001110,
1010+ 0b00000000,
1011+ },
1012+
1013+ ['U'] =
1014+ {
1015+ 0b00000000,
1016+ 0b00100001,
1017+ 0b00100001,
1018+ 0b00100001,
1019+ 0b00100001,
1020+ 0b00100001,
1021+ 0b00011110,
1022+ 0b00000000,
1023+ },
1024+
1025+ ['V'] =
1026+ {
1027+ 0b00000000,
1028+ 0b00100001,
1029+ 0b00100001,
1030+ 0b00010010,
1031+ 0b00010010,
1032+ 0b00001100,
1033+ 0b00000100,
1034+ 0b00000000,
1035+ },
1036+
1037+ ['W'] =
1038+ {
1039+ 0b00000000,
1040+ 0b00100001,
1041+ 0b00100001,
1042+ 0b00100001,
1043+ 0b00101101,
1044+ 0b00110011,
1045+ 0b00100001,
1046+ 0b00000000,
1047+ },
1048+
1049+ ['X'] =
1050+ {
1051+ 0b00000000,
1052+ 0b00100001,
1053+ 0b00100001,
1054+ 0b00010010,
1055+ 0b00001100,
1056+ 0b00010010,
1057+ 0b00100001,
1058+ 0b00000000,
1059+ },
1060+
1061+ ['Y'] =
1062+ {
1063+ 0b00000000,
1064+ 0b00100001,
1065+ 0b00100001,
1066+ 0b00010010,
1067+ 0b00001100,
1068+ 0b00001100,
1069+ 0b00001100,
1070+ 0b00000000,
1071+ },
1072+
1073+ ['Z'] =
1074+ {
1075+ 0b00000000,
1076+ 0b00111111,
1077+ 0b00010000,
1078+ 0b00001000,
1079+ 0b00000100,
1080+ 0b00000010,
1081+ 0b00111111,
1082+ 0b00000000,
1083+ },
1084+
1085+ ['a'] =
1086+ {
1087+ 0b00000000,
1088+ 0b00000000,
1089+ 0b00001110,
1090+ 0b00010000,
1091+ 0b00011110,
1092+ 0b00010010,
1093+ 0b00011110,
1094+ 0b00000000,
1095+ },
1096+
1097+ ['b'] =
1098+ {
1099+ 0b00000000,
1100+ 0b00000010,
1101+ 0b00000010,
1102+ 0b00011110,
1103+ 0b00010010,
1104+ 0b00010010,
1105+ 0b00011110,
1106+ 0b00000000,
1107+ },
1108+
1109+ ['c'] =
1110+ {
1111+ 0b00000000,
1112+ 0b00000000,
1113+ 0b00011110,
1114+ 0b00000001,
1115+ 0b00000001,
1116+ 0b00000001,
1117+ 0b00011110,
1118+ 0b00000000,
1119+ },
1120+
1121+ ['d'] =
1122+ {
1123+ 0b00000000,
1124+ 0b00010000,
1125+ 0b00010000,
1126+ 0b00011110,
1127+ 0b00010010,
1128+ 0b00010010,
1129+ 0b00011110,
1130+ 0b00000000,
1131+ },
1132+
1133+ ['e'] =
1134+ {
1135+ 0b00000000,
1136+ 0b00000000,
1137+ 0b00011110,
1138+ 0b00010001,
1139+ 0b00111111,
1140+ 0b00000001,
1141+ 0b00011110,
1142+ 0b00000000,
1143+ },
1144+
1145+ ['f'] =
1146+ {
1147+ 0b00011000,
1148+ 0b00000100,
1149+ 0b00111110,
1150+ 0b00000100,
1151+ 0b00000100,
1152+ 0b00000100,
1153+ 0b00000100,
1154+ 0b00000000,
1155+ },
1156+
1157+ ['g'] =
1158+ {
1159+ 0b00000000,
1160+ 0b00000000,
1161+ 0b00011110,
1162+ 0b00010010,
1163+ 0b00011110,
1164+ 0b00010000,
1165+ 0b00010000,
1166+ 0b00001110,
1167+ },
1168+
1169+ ['h'] =
1170+ {
1171+ 0b00000000,
1172+ 0b00000010,
1173+ 0b00000010,
1174+ 0b00011110,
1175+ 0b00010010,
1176+ 0b00010010,
1177+ 0b00010010,
1178+ 0b00000000,
1179+ },
1180+
1181+ ['i'] =
1182+ {
1183+ 0b00000000,
1184+ 0b00000100,
1185+ 0b00000000,
1186+ 0b00000100,
1187+ 0b00000100,
1188+ 0b00000100,
1189+ 0b00001100,
1190+ 0b00000000,
1191+ },
1192+
1193+ ['j'] =
1194+ {
1195+ 0b00001000,
1196+ 0b00000000,
1197+ 0b00001000,
1198+ 0b00001000,
1199+ 0b00001000,
1200+ 0b00001000,
1201+ 0b00001000,
1202+ 0b00001110,
1203+ },
1204+
1205+ ['k'] =
1206+ {
1207+ 0b00000001,
1208+ 0b00000001,
1209+ 0b00001001,
1210+ 0b00000101,
1211+ 0b00000011,
1212+ 0b00000101,
1213+ 0b00001001,
1214+ 0b00000000,
1215+ },
1216+
1217+ ['l'] =
1218+ {
1219+ 0b00000000,
1220+ 0b00000100,
1221+ 0b00000100,
1222+ 0b00000100,
1223+ 0b00000100,
1224+ 0b00000100,
1225+ 0b00111100,
1226+ 0b00000000,
1227+ },
1228+
1229+ ['m'] =
1230+ {
1231+ 0b00000000,
1232+ 0b00000000,
1233+ 0b00110110,
1234+ 0b00101010,
1235+ 0b00101010,
1236+ 0b00101010,
1237+ 0b00101010,
1238+ 0b00000000,
1239+ },
1240+
1241+ ['n'] =
1242+ {
1243+ 0b00000000,
1244+ 0b00000000,
1245+ 0b00011100,
1246+ 0b00010010,
1247+ 0b00010010,
1248+ 0b00010010,
1249+ 0b00010010,
1250+ 0b00000000,
1251+ },
1252+
1253+ ['o'] =
1254+ {
1255+ 0b00000000,
1256+ 0b00000000,
1257+ 0b00000000,
1258+ 0b00001110,
1259+ 0b00010001,
1260+ 0b00010001,
1261+ 0b00001110,
1262+ 0b00000000,
1263+ },
1264+
1265+ ['p'] =
1266+ {
1267+ 0b00000000,
1268+ 0b00000000,
1269+ 0b00011110,
1270+ 0b00010010,
1271+ 0b00011110,
1272+ 0b00000010,
1273+ 0b00000010,
1274+ 0b00000010,
1275+ },
1276+
1277+ ['q'] =
1278+ {
1279+ 0b00000000,
1280+ 0b00000000,
1281+ 0b00011110,
1282+ 0b00010010,
1283+ 0b00011110,
1284+ 0b00010000,
1285+ 0b00010000,
1286+ 0b00000000,
1287+ },
1288+
1289+ ['r'] =
1290+ {
1291+ 0b00000000,
1292+ 0b00000000,
1293+ 0b00001110,
1294+ 0b00010010,
1295+ 0b00000010,
1296+ 0b00000010,
1297+ 0b00000010,
1298+ 0b00000000,
1299+ },
1300+
1301+ ['s'] =
1302+ {
1303+ 0b00000000,
1304+ 0b00000000,
1305+ 0b00011110,
1306+ 0b00000001,
1307+ 0b00011110,
1308+ 0b00100000,
1309+ 0b00011110,
1310+ 0b00000000,
1311+ },
1312+
1313+ ['t'] =
1314+ {
1315+ 0b00001000,
1316+ 0b00001000,
1317+ 0b00111110,
1318+ 0b00001000,
1319+ 0b00001000,
1320+ 0b00001000,
1321+ 0b00010000,
1322+ 0b00000000,
1323+ },
1324+
1325+ ['u'] =
1326+ {
1327+ 0b00000000,
1328+ 0b00000000,
1329+ 0b00010001,
1330+ 0b00010001,
1331+ 0b00010001,
1332+ 0b00010001,
1333+ 0b00011110,
1334+ 0b00000000,
1335+ },
1336+
1337+ ['v'] =
1338+ {
1339+ 0b00000000,
1340+ 0b00000000,
1341+ 0b00010001,
1342+ 0b00010001,
1343+ 0b00001010,
1344+ 0b00001010,
1345+ 0b00000100,
1346+ 0b00000000,
1347+ },
1348+
1349+ ['w'] =
1350+ {
1351+ 0b00000000,
1352+ 0b00000000,
1353+ 0b00010001,
1354+ 0b00010001,
1355+ 0b00010101,
1356+ 0b00010101,
1357+ 0b00001010,
1358+ 0b00000000,
1359+ },
1360+
1361+ ['x'] =
1362+ {
1363+ 0b00000000,
1364+ 0b00000000,
1365+ 0b00010001,
1366+ 0b00001010,
1367+ 0b00000100,
1368+ 0b00001010,
1369+ 0b00010001,
1370+ 0b00000000,
1371+ },
1372+
1373+ ['y'] =
1374+ {
1375+ 0b00000000,
1376+ 0b00000000,
1377+ 0b00010001,
1378+ 0b00010001,
1379+ 0b00011110,
1380+ 0b00100000,
1381+ 0b00011110,
1382+ 0b00000000,
1383+ },
1384+
1385+ ['z'] =
1386+ {
1387+ 0b00000000,
1388+ 0b00000000,
1389+ 0b00111111,
1390+ 0b00010000,
1391+ 0b00001000,
1392+ 0b00000100,
1393+ 0b00111111,
1394+ 0b00000000,
1395+ },
1396+
1397+ ['0'] =
1398+ {
1399+ 0b00000000,
1400+ 0b00011110,
1401+ 0b00100001,
1402+ 0b00100001,
1403+ 0b00100001,
1404+ 0b00100001,
1405+ 0b00011110,
1406+ 0b00000000,
1407+ },
1408+
1409+ ['1'] =
1410+ {
1411+ 0b00000000,
1412+ 0b00001100,
1413+ 0b00001000,
1414+ 0b00001000,
1415+ 0b00001000,
1416+ 0b00001000,
1417+ 0b00111110,
1418+ 0b00000000,
1419+ },
1420+
1421+ ['2'] =
1422+ {
1423+ 0b00000000,
1424+ 0b00011110,
1425+ 0b00100000,
1426+ 0b00011000,
1427+ 0b00000100,
1428+ 0b00000010,
1429+ 0b00111110,
1430+ 0b00000000,
1431+ },
1432+
1433+ ['3'] =
1434+ {
1435+ 0b00000000,
1436+ 0b00111111,
1437+ 0b00100000,
1438+ 0b00011110,
1439+ 0b00100000,
1440+ 0b00100000,
1441+ 0b00111111,
1442+ 0b00000000,
1443+ },
1444+
1445+ ['4'] =
1446+ {
1447+ 0b00000000,
1448+ 0b00010001,
1449+ 0b00010001,
1450+ 0b00111111,
1451+ 0b00010000,
1452+ 0b00010000,
1453+ 0b00010000,
1454+ 0b00000000,
1455+ },
1456+
1457+ ['5'] =
1458+ {
1459+ 0b00000000,
1460+ 0b00111111,
1461+ 0b00000001,
1462+ 0b00011111,
1463+ 0b00100000,
1464+ 0b00100000,
1465+ 0b00011111,
1466+ 0b00000000,
1467+ },
1468+
1469+ ['6'] =
1470+ {
1471+ 0b00000000,
1472+ 0b00011110,
1473+ 0b00000001,
1474+ 0b00011111,
1475+ 0b00100001,
1476+ 0b00100001,
1477+ 0b00011110,
1478+ 0b00000000,
1479+ },
1480+
1481+ ['7'] =
1482+ {
1483+ 0b00000000,
1484+ 0b00111111,
1485+ 0b00100000,
1486+ 0b00010000,
1487+ 0b00001000,
1488+ 0b00001000,
1489+ 0b00001000,
1490+ 0b00000000,
1491+ },
1492+
1493+ ['8'] =
1494+ {
1495+ 0b00000000,
1496+ 0b00011110,
1497+ 0b00100001,
1498+ 0b00011110,
1499+ 0b00100001,
1500+ 0b00100001,
1501+ 0b00011110,
1502+ 0b00000000,
1503+ },
1504+
1505+ ['9'] =
1506+ {
1507+ 0b00000000,
1508+ 0b00011110,
1509+ 0b00100001,
1510+ 0b00111110,
1511+ 0b00100000,
1512+ 0b00100000,
1513+ 0b00011110,
1514+ 0b00000000,
1515+ },
1516+
1517+ ['?'] =
1518+ {
1519+ 0b00000000,
1520+ 0b00011110,
1521+ 0b00100001,
1522+ 0b00010000,
1523+ 0b00001000,
1524+ 0b00000000,
1525+ 0b00001000,
1526+ 0b00000000,
1527+ },
1528+
1529+ ['!'] =
1530+ {
1531+ 0b00000000,
1532+ 0b00001100,
1533+ 0b00001100,
1534+ 0b00000100,
1535+ 0b00000100,
1536+ 0b00000000,
1537+ 0b00000100,
1538+ 0b00000000,
1539+ },
1540+
1541+ [':'] =
1542+ {
1543+ 0b00000000,
1544+ 0b00001100,
1545+ 0b00001100,
1546+ 0b00000000,
1547+ 0b00001100,
1548+ 0b00001100,
1549+ 0b00000000,
1550+ 0b00000000,
1551+ },
1552+
1553+ [';'] =
1554+ {
1555+ 0b00000000,
1556+ 0b00001100,
1557+ 0b00001100,
1558+ 0b00000000,
1559+ 0b00001100,
1560+ 0b00001100,
1561+ 0b00001000,
1562+ 0b00000000,
1563+ },
1564+
1565+ ['.'] =
1566+ {
1567+ 0b00000000,
1568+ 0b00000000,
1569+ 0b00000000,
1570+ 0b00000000,
1571+ 0b00000000,
1572+ 0b00001100,
1573+ 0b00001100,
1574+ 0b00000000,
1575+ },
1576
1577 };
1578
+91,
-95
1@@ -1,49 +1,49 @@
2-// i got to eventually clean up this file a bit i feel like its very janky but i suppose i can worry about that later
3+// i got to eventually clean up this file a bit i feel like its very janky but i
4+// suppose i can worry about that later
5
6-#include <stdio.h>
7-#include <string.h>
8-#include <stdlib.h>
9-#include <unistd.h>
10-#include <SDL2/SDL.h>
11 #include "interpreter.h"
12 #include "cottonwindow.h"
13 #include "eiki.h"
14+#include <SDL2/SDL.h>
15+#include <stdio.h>
16+#include <stdlib.h>
17+#include <string.h>
18+#include <unistd.h>
19
20 // maximum length of a .cot file line
21 #define MAX_LINE 256
22
23-
24 // da string AND variable stuff
25
26-static void strip_newline(char *s)
27+static void
28+strip_newline(char *s)
29 {
30- s[strcspn(s, "\r\n")] = 0;
31+ s[strcspn(s, "\r\n")] = 0;
32 }
33
34-static char *get_arg(char *line)
35+static char
36+*get_arg (char *line)
37 {
38 char *space = strchr(line, ' ');
39
40- if (space != NULL)
41- {
42+ if (space != NULL) {
43 return space + 1;
44 }
45
46- else
47- {
48+ else {
49 return NULL;
50 }
51 }
52
53-static char *strip_quotes(char *s)
54+static char
55+*strip_quotes(char *s)
56 {
57- if (s[0] == '"')
58- {
59+ if (s[0] == '"') {
60 char *end = strrchr(s, '"');
61
62- if (end == NULL)
63- {
64- fprintf(stderr, "cot syntax error : looks like you forgot a quote at the end xP\n");
65+ if (end == NULL) {
66+ fprintf(stderr, "cot syntax error : looks like you forgot a quote "
67+ "at the end xP\n");
68 return s;
69 }
70
71@@ -54,12 +54,11 @@ static char *strip_quotes(char *s)
72 return s;
73 }
74
75-static const char *get_var_value(Cotton *cotton, const char *name)
76+static const char *get_var_value
77+(Cotton *cotton, const char *name)
78 {
79- for (int i = 0; i < cotton->var_count; i++)
80- {
81- if (strcmp(cotton->vars[i].name, name) == 0)
82- {
83+ for (int i = 0; i < cotton->var_count; i++) {
84+ if (strcmp(cotton->vars[i].name, name) == 0) {
85 return cotton->vars[i].value;
86 }
87 }
88@@ -68,33 +67,31 @@ static const char *get_var_value(Cotton *cotton, const char *name)
89
90 // da graphics stuff
91
92-static void draw_pixel(Cotton *cotton, int x, int y)
93+static void draw_pixel
94+(Cotton *cotton, int x, int y)
95 {
96 cotton->video[y * VIDEO_WIDTH + x] = cotton->c_cottolette;
97 }
98
99-static void draw_char(Cotton *cotton, char c, int x, int y)
100+static void draw_char
101+(Cotton *cotton, char c, int x, int y)
102 {
103- for (int row = 0; row < FONT_HEIGHT; row++)
104- {
105+ for (int row = 0; row < FONT_HEIGHT; row++) {
106 uint8_t bits = EIKI_FONT[(uint8_t)c][row];
107
108- for (int col = 0; col < FONT_WIDTH; col++)
109- {
110+ for (int col = 0; col < FONT_WIDTH; col++) {
111
112- if (bits & (1 << col))
113- {
114- draw_pixel(cotton, x + col, y + row);
115+ if (bits & (1 << col)) {
116+ draw_pixel(cotton, x + col, y + row);
117+ }
118 }
119 }
120-
121- }
122 }
123
124-
125 // da commands
126
127-static void cmd_print(Cotton *cotton, CottonWindow *cw, char *arg)
128+static void cmd_print
129+(Cotton *cotton, CottonWindow *cw, char *arg)
130 {
131 if (!arg)
132 return;
133@@ -102,17 +99,14 @@ static void cmd_print(Cotton *cotton, CottonWindow *cw, char *arg)
134 char *text = strip_quotes(arg);
135
136 const char *value = get_var_value(cotton, text);
137- if (value != NULL)
138- {
139+ if (value != NULL) {
140 text = (char *)value;
141 }
142
143 printf("%s\n", text);
144
145- for (int i = 0; text[i] != '\0'; i++)
146- {
147- if (text[i] == '\n')
148- {
149+ for (int i = 0; text[i] != '\0'; i++) {
150+ if (text[i] == '\n') {
151 cotton->cursor_x = 0;
152 cotton->cursor_y += FONT_HEIGHT + 4;
153 continue;
154@@ -121,8 +115,7 @@ static void cmd_print(Cotton *cotton, CottonWindow *cw, char *arg)
155 draw_char(cotton, text[i], cotton->cursor_x, cotton->cursor_y);
156 cotton->cursor_x += FONT_WIDTH + 2;
157
158- if (cotton->cursor_x + FONT_WIDTH + 2 >= VIDEO_WIDTH)
159- {
160+ if (cotton->cursor_x + FONT_WIDTH + 2 >= VIDEO_WIDTH) {
161 cotton->cursor_x = 0;
162 cotton->cursor_y += FONT_HEIGHT + 4;
163 }
164@@ -131,19 +124,20 @@ static void cmd_print(Cotton *cotton, CottonWindow *cw, char *arg)
165 cotton->cursor_x = 0;
166 cotton->cursor_y += FONT_HEIGHT + 4;
167
168- cottonwindow_update(cw, cotton->video, sizeof(cotton->video[0]) * VIDEO_WIDTH);
169-
170+ cottonwindow_update(cw, cotton->video,
171+ sizeof(cotton->video[0]) * VIDEO_WIDTH);
172 }
173
174-static void cmd_var(Cotton *cotton, char *arg)
175+static void cmd_var
176+(Cotton *cotton, char *arg)
177 {
178 if (!arg)
179 return;
180
181 char *space = strchr(arg, ' ');
182- if (!space)
183- {
184- fprintf(stderr, "cot syntax error: you forgor to put a value for your variable xP\n");
185+ if (!space) {
186+ fprintf(stderr, "cot syntax error: you forgor to put a value for your "
187+ "variable xP\n");
188 return;
189 }
190
191@@ -154,7 +148,8 @@ static void cmd_var(Cotton *cotton, char *arg)
192 cotton_store_var(cotton, name, value);
193 }
194
195-static void cmd_wait(Cotton *cotton, char *arg)
196+static void
197+cmd_wait(Cotton *cotton, char *arg)
198 {
199 if (!arg)
200 return;
201@@ -164,7 +159,8 @@ static void cmd_wait(Cotton *cotton, char *arg)
202 cotton->ticktock = SDL_GetTicks() + (seconds * 1000);
203 }
204
205-static void cmd_kill(void)
206+static void
207+cmd_kill(void)
208 {
209 printf("[cotton stopped]\n");
210 exit(0);
211@@ -172,27 +168,29 @@ static void cmd_kill(void)
212
213 static void cmd_clear(Cotton *cotton, CottonWindow *cw)
214 {
215- for (int i = 0; i < VIDEO_WIDTH * VIDEO_HEIGHT; i++)
216- {
217+ for (int i = 0; i < VIDEO_WIDTH * VIDEO_HEIGHT; i++) {
218 cotton->video[i] = 0;
219 }
220
221 cotton->cursor_x = 0;
222 cotton->cursor_y = 0;
223
224- cottonwindow_update(cw, cotton->video, sizeof(cotton->video[0]) * VIDEO_WIDTH);
225+ cottonwindow_update(cw, cotton->video,
226+ sizeof(cotton->video[0]) * VIDEO_WIDTH);
227 }
228
229-static void cmd_color(Cotton *cotton, char *arg)
230+static void
231+cmd_color(Cotton *cotton, char *arg)
232 {
233- if (!arg) return;
234+ if (!arg)
235+ return;
236
237 if (strcmp(arg, "black") == 0)
238 cotton->c_cottolette = COTTOLETTE[0];
239-
240+
241 else if (strcmp(arg, "white") == 0)
242 cotton->c_cottolette = COTTOLETTE[1];
243-
244+
245 else if (strcmp(arg, "rey") == 0)
246 cotton->c_cottolette = COTTOLETTE[2];
247
248@@ -209,37 +207,46 @@ static void cmd_color(Cotton *cotton, char *arg)
249 cotton->c_cottolette = COTTOLETTE[6];
250
251 else
252- fprintf(stderr, "cot syntax error: cotton doesn't know the color \"%s\" sorry,, :(\n", arg);
253+ fprintf(stderr,
254+ "cot syntax error: cotton doesn't know the color \"%s\" "
255+ "sorry,, :(\n",
256+ arg);
257 }
258
259-static void cmd_input(Cotton *cotton, char *arg)
260+static void
261+cmd_input(Cotton *cotton, char *arg)
262 {
263- if (!arg)
264- {
265- fprintf(stderr, "cotton syntax error: input needs a variable name xP\n");
266+ if (!arg) {
267+ fprintf(stderr,
268+ "cotton syntax error: input needs a variable name xP\n");
269 return;
270 }
271
272 char buffer[VAR_VAL_LEN];
273
274- // kind of a quick and dirty way of implementing input, i know, but, i cant be arsed to get myself into a potential rabbit hole with SDL so for now i will leave this to be this way,, sorry,,
275- if (fgets(buffer, sizeof(buffer), stdin) != NULL)
276- {
277+ // kind of a quick and dirty way of implementing input, i know, but, i cant
278+ // be arsed to get myself into a potential rabbit hole with SDL so for now i
279+ // will leave this to be this way,, sorry,,
280+ if (fgets(buffer, sizeof(buffer), stdin) != NULL) {
281 buffer[strcspn(buffer, "\r\n")] = '\0';
282
283 cotton_store_var(cotton, arg, buffer);
284 }
285 }
286
287-static void cmd_unknown(const char *cmd)
288+static void
289+cmd_unknown(const char *cmd)
290 {
291- fprintf(stderr, "cot syntax error: cotton doesn't know what \"%s\" means, care to type that out again? :<\n", cmd);
292+ fprintf(stderr,
293+ "cot syntax error: cotton doesn't know what \"%s\" means, care to "
294+ "type that out again? :<\n",
295+ cmd);
296 }
297
298-
299 // da interpreter loop
300
301-void cotton_interpret(Cotton *cotton, CottonWindow *cw, FILE *file)
302+void
303+cotton_interpret(Cotton *cotton, CottonWindow *cw, FILE *file)
304 {
305 char line[MAX_LINE];
306
307@@ -253,61 +260,50 @@ void cotton_interpret(Cotton *cotton, CottonWindow *cw, FILE *file)
308 if (line[0] == '\0' || line[0] == '#')
309 return;
310
311-
312 char line_copy[MAX_LINE];
313
314 strncpy(line_copy, line, MAX_LINE - 1);
315 line_copy[MAX_LINE - 1] = '\0';
316
317-
318 char *cmd = strtok(line_copy, " ");
319
320 if (!cmd)
321 return;
322
323-
324- // RELEASE THE KRAKE- I MEAN, RELEASE THE GREAT WALL OF COMMANDS !!!
325- // could i format this better? maybe,, but but i'd say this is readable and i think readability is gud so i will keep it nice and green,,, green!! :D
326+ // RELEASE THE KRAKE- I MEAN, RELEASE THE GREAT WALL OF COMMANDS !!!
327+ // could i format this better? maybe,, but but i'd say this is readable and
328+ // i think readability is gud so i will keep it nice and green,,, green!! :D
329 char *arg = get_arg(line);
330
331-
332- if (strcmp(cmd, "print") == 0)
333- {
334+ if (strcmp(cmd, "print") == 0) {
335 cmd_print(cotton, cw, arg);
336 }
337
338- else if (strcmp(cmd, "var") == 0)
339- {
340+ else if (strcmp(cmd, "var") == 0) {
341 cmd_var(cotton, arg);
342 }
343
344- else if (strcmp(cmd, "clear") == 0)
345- {
346+ else if (strcmp(cmd, "clear") == 0) {
347 cmd_clear(cotton, cw);
348 }
349
350- else if (strcmp(cmd, "color") == 0)
351- {
352+ else if (strcmp(cmd, "color") == 0) {
353 cmd_color(cotton, arg);
354 }
355
356- else if (strcmp(cmd, "wait") == 0)
357- {
358+ else if (strcmp(cmd, "wait") == 0) {
359 cmd_wait(cotton, arg);
360 }
361
362- else if (strcmp(cmd, "input") == 0)
363- {
364+ else if (strcmp(cmd, "input") == 0) {
365 cmd_input(cotton, arg);
366 }
367
368- else if (strcmp(cmd, "kill") == 0)
369- {
370+ else if (strcmp(cmd, "kill") == 0) {
371 cmd_kill();
372 }
373
374- else
375- {
376+ else {
377 cmd_unknown(cmd);
378 }
379 }
+2,
-1
1@@ -5,6 +5,7 @@
2 #include "cottonwindow.h"
3 #include <stdio.h>
4
5-void cotton_interpret(Cotton *cotton, CottonWindow *cw, FILE *file);
6+void cotton_interpret
7+(Cotton *cotton, CottonWindow *cw, FILE *file);
8
9 #endif
+22,
-25
1@@ -1,39 +1,39 @@
2-#include <stdio.h>
3-#include <stdlib.h>
4-#include <string.h>
5 #include "cotton.h"
6 #include "cottonwindow.h"
7 #include "interpreter.h"
8+#include <stdio.h>
9+#include <stdlib.h>
10+#include <string.h>
11
12-int main(int argc, char **argv)
13+int main
14+(int argc, char **argv)
15 {
16-
17- // added this specifically with the new user input command in mind, makes it so the terminal isnt so cluttered for when there is user input needed, atleast for me :P
18- printf("\033[2J\033[H");
19
20- //thank you chld for the idea of changing the scale and having it be optional ^^
21+ // added this specifically with the new user input command in mind, makes it
22+ // so the terminal isnt so cluttered for when there is user input needed,
23+ // atleast for me :P
24+ printf("\033[2J\033[H");
25+
26+ // thank you chld for the idea of changing the scale and having it be
27+ // optional ^^
28 int scale = 4;
29 char *filename = NULL;
30
31- if (argc == 4 && strcmp(argv[1], "-s") == 0)
32- {
33+ if (argc == 4 && strcmp(argv[1], "-s") == 0) {
34 scale = atoi(argv[2]);
35 filename = argv[3];
36- }
37- else if (argc == 2)
38- {
39+ } else if (argc == 2) {
40 filename = argv[1];
41- }
42- else
43- {
44- fprintf(stderr, "usage: cotton <-s scale (scale being 2 or 4)> <file.cot>\n");
45+ } else {
46+ fprintf(stderr,
47+ "usage: cotton <-s scale (scale being 2 or 4)> <file.cot>\n");
48 return 1;
49 }
50
51 CottonWindow cw;
52
53- if (!cottonwindow_init(&cw, "cotton", VIDEO_WIDTH * scale, VIDEO_HEIGHT * scale, VIDEO_WIDTH, VIDEO_HEIGHT))
54- {
55+ if (!cottonwindow_init(&cw, "cotton", VIDEO_WIDTH * scale,
56+ VIDEO_HEIGHT * scale, VIDEO_WIDTH, VIDEO_HEIGHT)) {
57 return 1;
58 }
59
60@@ -41,8 +41,7 @@ int main(int argc, char **argv)
61 cotton_init(&cotton);
62
63 FILE *file = fopen(filename, "r");
64- if (!file)
65- {
66+ if (!file) {
67 fprintf(stderr, "cotton couldn't open \"%s\" :(\n", filename);
68 return 1;
69 }
70@@ -50,12 +49,10 @@ int main(int argc, char **argv)
71 int pitch = sizeof(cotton.video[0]) * VIDEO_WIDTH;
72 int quit = 0;
73
74- while (!quit)
75- {
76+ while (!quit) {
77 quit = cottonwindow_process_input(&cw, NULL);
78
79- if (SDL_GetTicks() >= cotton.ticktock)
80- {
81+ if (SDL_GetTicks() >= cotton.ticktock) {
82 cotton_interpret(&cotton, &cw, file);
83 }
84