commit aaf89d8
chld
·
2026-07-22 00:23:15 +0000 UTC
parent 7c64f22
sync
2 files changed,
+46,
-18
+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 }
+44,
-18
1@@ -4,13 +4,11 @@
2 #include <string.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5-#include <SDL2/SDL.h>
6+#include <OS.h>
7 #include "interpreter.h"
8 #include "cottonwindow.h"
9 #include "eiki.h"
10
11-#include <OS.h>
12-
13 // maximum length of a .cot file line
14 #define MAX_LINE 256
15
16@@ -59,9 +57,9 @@ static char *strip_quotes(char *s)
17
18 // da graphics stuff
19
20-static void draw_pixel(Cotton *cotton, int x, int y, uint32_t color)
21+static void draw_pixel(Cotton *cotton, int x, int y)
22 {
23- cotton->video[y * VIDEO_WIDTH + x] = color;
24+ cotton->video[y * VIDEO_WIDTH + x] = cotton->c_cottolette;
25 }
26
27 static void draw_char(Cotton *cotton, char c, int x, int y)
28@@ -75,7 +73,7 @@ static void draw_char(Cotton *cotton, char c, int x, int y)
29
30 if (bits & (1 << col))
31 {
32- draw_pixel(cotton, x + col, y + row, 0xffffffff);
33+ draw_pixel(cotton, x + col, y + row);
34 }
35 }
36
37@@ -87,8 +85,6 @@ static void draw_char(Cotton *cotton, char c, int x, int y)
38
39 static void cmd_print(Cotton *cotton, CottonWindow *cw, char *arg)
40 {
41- (void)cw;
42-
43 if (!arg)
44 return;
45
46@@ -117,6 +113,9 @@ static void cmd_print(Cotton *cotton, CottonWindow *cw, char *arg)
47
48 cotton->cursor_x = 0;
49 cotton->cursor_y += FONT_HEIGHT + 4;
50+
51+ cottonwindow_update(cw, cotton->video, sizeof(cotton->video[0]) * VIDEO_WIDTH);
52+
53 }
54
55 static void cmd_wait(Cotton *cotton, char *arg)
56@@ -126,7 +125,7 @@ static void cmd_wait(Cotton *cotton, char *arg)
57
58 int seconds = atoi(arg);
59
60- cotton->ticktock = system_time() /1000 + (seconds * 1000);
61+ cotton->ticktock = system_time() / 100 + (seconds * 1000);
62 }
63
64 static void cmd_kill(void)
65@@ -135,19 +134,46 @@ static void cmd_kill(void)
66 exit(0);
67 }
68
69-static void cmd_clear(CottonWindow *cw)
70+static void cmd_clear(Cotton *cotton, CottonWindow *cw)
71 {
72- (void)cw;
73+ for (int i = 0; i < VIDEO_WIDTH * VIDEO_HEIGHT; i++)
74+ {
75+ cotton->video[i] = 0;
76+ }
77
78- // will work on this for v0.2
79+ cotton->cursor_x = 0;
80+ cotton->cursor_y = 0;
81+
82+ cottonwindow_update(cw, cotton->video, sizeof(cotton->video[0]) * VIDEO_WIDTH);
83 }
84
85-static void cmd_color(CottonWindow *cw, char *arg)
86+static void cmd_color(Cotton *cotton, char *arg)
87 {
88- (void)cw;
89- (void)arg;
90+ if (!arg) return;
91+
92+ if (strcmp(arg, "black") == 0)
93+ cotton->c_cottolette = COTTOLETTE[0];
94+
95+ else if (strcmp(arg, "white") == 0)
96+ cotton->c_cottolette = COTTOLETTE[1];
97+
98+ else if (strcmp(arg, "rey") == 0)
99+ cotton->c_cottolette = COTTOLETTE[2];
100
101- // will work on this for v0.2
102+ else if (strcmp(arg, "wist") == 0)
103+ cotton->c_cottolette = COTTOLETTE[3];
104+
105+ else if (strcmp(arg, "wink") == 0)
106+ cotton->c_cottolette = COTTOLETTE[4];
107+
108+ else if (strcmp(arg, "laven") == 0)
109+ cotton->c_cottolette = COTTOLETTE[5];
110+
111+ else if (strcmp(arg, "geen") == 0)
112+ cotton->c_cottolette = COTTOLETTE[6];
113+
114+ else
115+ fprintf(stderr, "cotton doesn't know the color \"%s\" sorry,, :(\n", arg);
116 }
117
118 static void cmd_input(CottonWindow *cw, char *arg)
119@@ -205,12 +231,12 @@ void cotton_interpret(Cotton *cotton, CottonWindow *cw, FILE *file)
120
121 else if (strcmp(cmd, "clear") == 0)
122 {
123- cmd_clear(cw);
124+ cmd_clear(cotton, cw);
125 }
126
127 else if (strcmp(cmd, "color") == 0)
128 {
129- cmd_color(cw, arg);
130+ cmd_color(cotton, arg);
131 }
132
133 else if (strcmp(cmd, "wait") == 0)