commit eee4d0d

0uppy  ·  2026-07-21 21:34:21 +0000 UTC
parent a6fbee2
cotton v0.2 - added cottolette, cotton's color palette (subject to change) and the color command
3 files changed,  +60, -15
+2, -0
1@@ -8,5 +8,7 @@ void cotton_init(Cotton *c)
2     memset(c, 0, sizeof(Cotton));
3 
4     srand((unsigned int)time(NULL));
5+
6+    c->c_cottolette = COTTOLETTE[1];
7         
8 }
+16, -1
 1@@ -7,6 +7,20 @@
 2 #define VIDEO_WIDTH  250
 3 #define VIDEO_HEIGHT 200
 4 
 5+#define COTTOLETTE_SIZE 7 // would be 6 but due to high demand we invited green into the mix because green is cool <3
 6+
 7+// i might work on better names another time xP
 8+static const uint32_t COTTOLETTE[COTTOLETTE_SIZE] = 
 9+{
10+    0xFF000000, // 0 - black
11+    0xFFFFFFFF, // 1 - white
12+    0xFF28262C, // 2 - rey
13+    0xFFA9A0CF, // 3 - wist
14+    0xFFE4D8FD, // 4 - wink
15+    0xFFF9F5FF, // 5 - laven
16+    0xFFD0F0C0, // 6 - the dude nobody invited (geen)
17+};
18+
19 typedef struct
20 {
21     uint8_t  memory[MEMORY_SIZE];
22@@ -17,7 +31,8 @@ typedef struct
23     int cursor_y;
24 
25     uint32_t ticktock;
26-
27+    uint32_t c_cottolette; //id write "current_cottolete" but that would be alot to type and im lazyyyyyyy bwaaaaaa
28+    
29 } Cotton;
30 
31 void cotton_init(Cotton *c);
+42, -14
  1@@ -57,9 +57,9 @@ static char *strip_quotes(char *s)
  2 
  3 // da graphics stuff
  4 
  5-static void draw_pixel(Cotton *cotton, int x, int y, uint32_t color)
  6+static void draw_pixel(Cotton *cotton, int x, int y)
  7 {
  8-    cotton->video[y * VIDEO_WIDTH + x] = color;
  9+        cotton->video[y * VIDEO_WIDTH + x] = cotton->c_cottolette;
 10 }
 11 
 12 static void draw_char(Cotton *cotton, char c, int x, int y)
 13@@ -73,7 +73,7 @@ static void draw_char(Cotton *cotton, char c, int x, int y)
 14 
 15         if (bits & (1 << col)) 
 16         {
 17-            draw_pixel(cotton, x + col, y + row, 0xffffffff);
 18+            draw_pixel(cotton, x + col, y + row);
 19         }
 20     }
 21 
 22@@ -85,8 +85,6 @@ static void draw_char(Cotton *cotton, char c, int x, int y)
 23 
 24 static void cmd_print(Cotton *cotton, CottonWindow *cw, char *arg)
 25 {
 26-    (void)cw;
 27-
 28     if (!arg)
 29         return;
 30 
 31@@ -115,6 +113,9 @@ static void cmd_print(Cotton *cotton, CottonWindow *cw, char *arg)
 32 
 33     cotton->cursor_x = 0;
 34     cotton->cursor_y += FONT_HEIGHT + 4;
 35+
 36+    cottonwindow_update(cw, cotton->video, sizeof(cotton->video[0]) * VIDEO_WIDTH);
 37+
 38 }
 39 
 40 static void cmd_wait(Cotton *cotton, char *arg)
 41@@ -133,19 +134,46 @@ static void cmd_kill(void)
 42     exit(0);
 43 }
 44 
 45-static void cmd_clear(CottonWindow *cw)
 46+static void cmd_clear(Cotton *cotton, CottonWindow *cw)
 47 {
 48-    (void)cw;
 49+    for (int i = 0; i < VIDEO_WIDTH * VIDEO_HEIGHT; i++)
 50+    {
 51+        cotton->video[i] = 0;
 52+    }
 53+
 54+    cotton->cursor_x = 0;
 55+    cotton->cursor_y = 0;
 56 
 57-    // will work on this for v0.2
 58+    cottonwindow_update(cw, cotton->video, sizeof(cotton->video[0]) * VIDEO_WIDTH);
 59 }
 60 
 61-static void cmd_color(CottonWindow *cw, char *arg)
 62+static void cmd_color(Cotton *cotton, char *arg)
 63 {
 64-    (void)cw;
 65-    (void)arg;
 66+    if (!arg) return;
 67+
 68+    if (strcmp(arg, "black") == 0)
 69+        cotton->c_cottolette = COTTOLETTE[0];
 70+    
 71+    else if (strcmp(arg, "white") == 0)
 72+        cotton->c_cottolette = COTTOLETTE[1];
 73+    
 74+    else if (strcmp(arg, "rey") == 0)
 75+        cotton->c_cottolette = COTTOLETTE[2];
 76+
 77+    else if (strcmp(arg, "wist") == 0)
 78+        cotton->c_cottolette = COTTOLETTE[3];
 79 
 80-    // will work on this for v0.2
 81+    else if (strcmp(arg, "wink") == 0)
 82+        cotton->c_cottolette = COTTOLETTE[4];
 83+
 84+    else if (strcmp(arg, "laven") == 0)
 85+        cotton->c_cottolette = COTTOLETTE[5];
 86+
 87+    else if (strcmp(arg, "geen") == 0)
 88+        cotton->c_cottolette = COTTOLETTE[6];
 89+
 90+    else
 91+        fprintf(stderr, "cotton doesn't know the color \"%s\" sorry,, :(\n", arg);
 92 }
 93 
 94 static void cmd_input(CottonWindow *cw, char *arg)
 95@@ -203,12 +231,12 @@ void cotton_interpret(Cotton *cotton, CottonWindow *cw, FILE *file)
 96 
 97     else if (strcmp(cmd, "clear") == 0)
 98     {
 99-        cmd_clear(cw);
100+        cmd_clear(cotton, cw);
101     }
102 
103     else if (strcmp(cmd, "color") == 0)
104     {
105-        cmd_color(cw, arg);
106+        cmd_color(cotton, arg);
107     }
108 
109     else if (strcmp(cmd, "wait") == 0)