-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathImprovedVBE.cs
447 lines (415 loc) · 20.1 KB
/
ImprovedVBE.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
using Cosmos.Core.IOGroup;
using Cosmos.HAL.Drivers;
using Cosmos.System;
using Cosmos.System.Graphics;
using IL2CPU.API.Attribs;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;
using Image = Cosmos.System.Graphics.Image;
namespace WaveOS
{
public class ImprovedVBE
{
[ManifestResourceStream(ResourceName = "WaveOS.Resources.WaveOS_background_768.bmp")] public static byte[] VBECanvas;
//These are black images matching the size exacly the resolution
public static Bitmap cover = new Bitmap(VBECanvas);//The base canvas
public static Bitmap data = new Bitmap(VBECanvas);//To reset the base canvas
public static int width = WaveConfigs.displayW;
public static int height = WaveConfigs.displayH;
public static void display(SVGAIICanvas c)
{
c.DrawImage(cover, 0, 0);
//clear(c, Color.Black);
//cover.RawData = data.RawData;
clear(c, Color.Black);
}
public static void clear(SVGAIICanvas c, Color col)
{
data.RawData.CopyTo(cover.RawData, 0);
}
public static void display(Canvas c)
{
c.DrawImage(cover, 0, 0);
//clear(c, Color.Black);
//cover.RawData = data.RawData;
clear(c, Color.Black);
}
public static void clear(Canvas c, Color col)
{
data.RawData.CopyTo(cover.RawData, 0);
}
public static void DrawPixelfortext2(int x, int y, int color)
{
//16777215 white
if (x >= 0 && x <= width && y >= 0 && y <= height)
{
cover.RawData[y * width + x] = color;
}
}
public static void DrawPixelfortext(int x, int y, int color)
{
//16777215 white
if (x > 0 && x < width && y > 0 && y < height)
{
cover.RawData[y * width + x] = color;
}
}
public static void DrawFilledCircle(int color, int x0, int y0, int radius)
{
int x = radius;
int y = 0;
int xChange = 1 - (radius << 1);
int yChange = 0;
int radiusError = 0;
while (x >= y)
{
for (int i = x0 - x; i <= x0 + x; i++)
{
DrawPixelfortext(i, y0 + y, color);
DrawPixelfortext(i, y0 - y, color);
}
for (int i = x0 - y; i <= x0 + y; i++)
{
DrawPixelfortext(i, y0 + x, color);
DrawPixelfortext(i, y0 - x, color);
}
y++;
radiusError += yChange;
yChange += 2;
if ((radiusError << 1) + xChange > 0)
{
x--;
radiusError += xChange;
xChange += 2;
}
}
}
public static void DrawFilledRectangle2(int color, int X, int Y, int Width, int Height)
{
if (X <= width)
{
int[] line = new int[Width];
if (X < 0)
{
line = new int[Width + X];
}
else if (X + Width > width)
{
line = new int[Width - (X + Width - width)];
}
Array.Fill(line, color);
for (int i = Y - 1; i < Y + Height - 1; i++)
{
Array.Copy(line, 0, cover.RawData, (i * width) + X, line.Length);
}
}
}
public static void DrawFilledRectangle(int color, int X, int Y, int Width, int Height)
{
if (X <= width)
{
int[] line = new int[Width];
if (X < 0)
{
line = new int[Width + X];
}
else if (X + Width > width)
{
line = new int[Width - (X + Width - width)];
}
Array.Fill(line, color);
for (int i = Y; i < Y + Height; i++)
{
Array.Copy(line, 0, cover.RawData, (i * width) + X, line.Length);
}
}
}
//Slower but can be improved with Array.Copy();
public static void DrawImage(Image image, int x, int y)
{
int counter = 0;
int prewy = y;
for (int _y = y; _y < y + image.Height; _y++)
{
for (int _x = x; _x < x + image.Width; _x++)
{
if ((_y * width) - (width - _x) < width * height)
{
if (_x > width || _x < 0)
{
//cover.RawData[((_y * width) - (width - _x))] = 0;
counter++;
}
else
{
cover.RawData[((_y * width) - (width - _x))] = image.RawData[counter];
counter++;
}
}
}
prewy++;
}
}
public static void DrawImageArray(int Width, int Height, int[] RawData, int x, int y)
{
int counter = 0;
int scan_line = 0;
for (int _y = y; _y < y + Height; _y++)
{
int[] line = new int[Width];
Array.Copy(RawData, scan_line * Width, line, 0, Width);
if (line[0] != 0 || line[^1] != 0)
{
line.CopyTo(cover.RawData, (_y - 1) * width + x);
//TODO: copy just a specific amount of length
counter += (int)Width;
}
else
{
for (int _x = x; _x < x + Width; _x++)
{
if (_y <= height - 1)
{
if (_x <= width)
{
if (RawData[counter] == 0)
{
counter++;
}
else
{
cover.RawData[((_y * width) - (width - _x))] = RawData[counter];
counter++;
}
}
else
{
counter++;
}
}
else
{
counter += (int)Width;
}
}
}
scan_line++;
}
}
//main
public static void DrawImageAlpha2(Image image, int x, int y)
{
int counter = 0;
for (int _y = y; _y < y + image.Height; _y++)
{
for (int _x = x; _x < x + image.Width; _x++)
{
if (_y <= height - 1)
{
if (_x <= width)
{
Color c = Color.FromArgb(image.RawData[counter]);
if (c.A > 0)
{
counter++;
}
else
{
cover.RawData[((_y * width) - (width - _x))] = image.RawData[counter];
counter++;
}
}
else
{
counter++;
}
}
else
{
counter += (int)image.Width;
}
}
}
}
//secondary
public static void DrawImageAlpha(Image image, int x, int y)
{
int counter = 0;
for (int _y = y; _y < y + image.Height; _y++)
{
for (int _x = x; _x < x + image.Width; _x++)
{
if (_y <= height - 1)
{
if (_x <= width)
{
Color c = Color.FromArgb(image.RawData[counter]);
if (c.A == 0)
{
counter++;
}
else
{
cover.RawData[((_y * width) - (width - _x))] = image.RawData[counter];
counter++;
}
}
else
{
counter++;
}
}
else
{
counter += (int)image.Width;
}
}
}
}
static string ASC16Base64 = "AAAAAAAAAAAAAAAAAAAAAAAAfoGlgYG9mYGBfgAAAAAAAH7/2///w+f//34AAAAAAAAAAGz+/v7+fDgQAAAAAAAAAAAQOHz+fDgQAAAAAAAAAAAYPDzn5+cYGDwAAAAAAAAAGDx+//9+GBg8AAAAAAAAAAAAABg8PBgAAAAAAAD////////nw8Pn////////AAAAAAA8ZkJCZjwAAAAAAP//////w5m9vZnD//////8AAB4OGjJ4zMzMzHgAAAAAAAA8ZmZmZjwYfhgYAAAAAAAAPzM/MDAwMHDw4AAAAAAAAH9jf2NjY2Nn5+bAAAAAAAAAGBjbPOc82xgYAAAAAACAwODw+P748ODAgAAAAAAAAgYOHj7+Ph4OBgIAAAAAAAAYPH4YGBh+PBgAAAAAAAAAZmZmZmZmZgBmZgAAAAAAAH/b29t7GxsbGxsAAAAAAHzGYDhsxsZsOAzGfAAAAAAAAAAAAAAA/v7+/gAAAAAAABg8fhgYGH48GH4AAAAAAAAYPH4YGBgYGBgYAAAAAAAAGBgYGBgYGH48GAAAAAAAAAAAABgM/gwYAAAAAAAAAAAAAAAwYP5gMAAAAAAAAAAA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Hbc2NjY3HYAAAAAAAB4zMzM2MzGxsbMAAAAAAAA/sbGwMDAwMDAwAAAAAAAAAAA/mxsbGxsbGwAAAAAAAAA/sZgMBgwYMb+AAAAAAAAAAAAftjY2NjYcAAAAAAAAAAAZmZmZmZ8YGDAAAAAAAAAAHbcGBgYGBgYAAAAAAAAAH4YPGZmZjwYfgAAAAAAAAA4bMbG/sbGbDgAAAAAAAA4bMbGxmxsbGzuAAAAAAAAHjAYDD5mZmZmPAAAAAAAAAAAAH7b29t+AAAAAAAAAAAAAwZ+29vzfmDAAAAAAAAAHDBgYHxgYGAwHAAAAAAAAAB8xsbGxsbGxsYAAAAAAAAAAP4AAP4AAP4AAAAAAAAAAAAYGH4YGAAA/wAAAAAAAAAwGAwGDBgwAH4AAAAAAAAADBgwYDAYDAB+AAAAAAAADhsbGBgYGBgYGBgYGBgYGBgYGBgYGNjY2HAAAAAAAAAAABgYAH4AGBgAAAAAAAAAAAAAdtwAdtwAAAAAAAAAOGxsOAAAAAAAAAAAAAAAAAAAAAAAABgYAAAAAAAAAAAAAAAAAAAAGAAAAAAAAAAADwwMDAwM7GxsPBwAAAAAANhsbGxsbAAAAAAAAAAAAABw2DBgyPgAAAAAAAAAAAAAAAAAfHx8fHx8fAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==";
static MemoryStream ASC16FontMS = new MemoryStream(Convert.FromBase64String(ASC16Base64));
public static void _DrawACSIIString(string s, int x, int y, int color)
{
string[] lines = s.Split('\n');
for (int l = 0; l < lines.Length; l++)
{
for (int c = 0; c < lines[l].Length; c++)
{
int offset = (Encoding.ASCII.GetBytes(lines[l][c].ToString())[0] & 0xFF) * 16;
ASC16FontMS.Seek(offset, SeekOrigin.Begin);
byte[] fontbuf = new byte[16];
ASC16FontMS.Read(fontbuf, 0, fontbuf.Length);
for (int i = 0; i < 16; i++)
{
for (int j = 0; j < 8; j++)
{
if ((fontbuf[i] & (0x80 >> j)) != 0)
{
if (x + c * 8 > width)
{
}
else
{
DrawPixelfortext((int)((x + j) + (c * 8)), (int)(y + i + (l * 16)), color);
}
}
}
}
}
}
}
public static void ScaleImage(Image image, int x, int y)
{
int counter = 0;
int counter2 = 1;
int prewy = y;
for (int _y = y; _y < y + image.Height * 3; _y++)
{
for (int _x = x; _x < x + image.Width * 3; _x++)
{
if ((_y * width) - (width - _x) < width * height)
{
if (_x > width)
{
counter++;
}
else
{
if (counter2 % 3 == 0)
{
cover.RawData[((_y * width) - (width - _x))] = image.RawData[counter];
counter++;
counter2++;
}
else
{
cover.RawData[((_y * width) - (width - _x))] = image.RawData[counter];
counter2++;
}
}
}
}
counter -= (int)image.Width;
_y += 1;
for (int _x = x; _x < x + image.Width * 3; _x++)
{
if ((_y * width) - (width - _x) < width * height)
{
if (_x > width)
{
counter++;
}
else
{
if (counter2 % 3 == 0)
{
cover.RawData[((_y * width) - (width - _x))] = image.RawData[counter];
counter++;
counter2++;
}
else
{
cover.RawData[((_y * width) - (width - _x))] = image.RawData[counter];
counter2++;
}
}
}
}
counter -= (int)image.Width;
_y += 1;
for (int _x = x; _x < x + image.Width * 3; _x++)
{
if ((_y * width) - (width - _x) < width * height)
{
if (_x > width)
{
counter++;
}
else
{
if (counter2 % 3 == 0)
{
cover.RawData[((_y * width) - (width - _x))] = image.RawData[counter];
counter++;
counter2++;
}
else
{
cover.RawData[((_y * width) - (width - _x))] = image.RawData[counter];
counter2++;
}
}
}
}
counter2 = 1;
prewy++;
}
}
public static int colourToNumber(int r, int g, int b)
{
return (r << 16) + (g << 8) + (b);
}
public static int colourToNumber(int grayNum)
{
return (grayNum << 16) + (grayNum << 8) + (grayNum);
}
public static void line(float x1, float y1, float x2, float y2, int color)
{
float dx = x2 - x1;
float dy = y2 - y1;
float length = (float)Math.Sqrt(dx * dx + dy * dy);
float angle = (float)Math.Atan2(dy, dx);
for (float i = 0; i < length; i++)
{
ImprovedVBE.DrawPixelfortext((int)(x1 + Math.Cos(angle) * i), (int)(y1 + Math.Sin(angle) * i), color);
}
}
}
}