-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-ultimate.sh
More file actions
executable file
·1902 lines (1672 loc) · 62.3 KB
/
run-ultimate.sh
File metadata and controls
executable file
·1902 lines (1672 loc) · 62.3 KB
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
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# ==========================================
# HybridOS ULTIMATE v2.0 - Installation Complète
# TOUTES les fonctionnalités en un seul script !
# ==========================================
set -e
echo "🚀 HybridOS ULTIMATE v2.0 - Installation Complète"
echo "=================================================="
echo "✨ Fonctionnalités: FileSystem + Editor + Graphics + Games + Network + Compiler + Animations"
echo ""
# Vérification des dépendances
echo "🔍 Vérification des dépendances..."
deps_missing=0
for cmd in nasm gcc ld qemu-system-i386 grub-mkrescue; do
if ! command -v $cmd >/dev/null 2>&1; then
echo "❌ $cmd manquant"
deps_missing=1
fi
done
if [ $deps_missing -eq 1 ]; then
echo ""
echo "📦 Installation des dépendances:"
echo "Ubuntu/Debian: sudo apt-get install nasm gcc binutils qemu-system-x86 grub-pc-bin grub-common xorriso"
echo "Fedora: sudo dnf install nasm gcc binutils qemu grub2-tools xorriso"
echo "Arch: sudo pacman -S nasm gcc binutils qemu grub xorriso"
exit 1
fi
echo "✅ Toutes les dépendances présentes"
# Structure
echo "📁 Création de la structure..."
mkdir -p kernel iso/boot/grub
# KERNEL ULTIMATE COMPLET
echo "🔥 Création du kernel ULTIMATE avec TOUTES les fonctionnalités..."
cat > kernel/kernel.c << 'ULTIMATE_KERNEL_COMPLETE'
// ==========================================
// HybridOS ULTIMATE v2.0 - KERNEL COMPLET
// TOUTES les fonctionnalités incluses
// ==========================================
// Types de base
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long size_t;
typedef int bool;
#define NULL ((void*)0)
#define true 1
#define false 0
// VGA et Graphics
#define VGA_WIDTH 80
#define VGA_HEIGHT 25
#define VGA_MEMORY ((uint16_t*)0xB8000)
#define GRAPHICS_MEMORY ((uint8_t*)0xA0000)
// Terminal state
static size_t term_row = 0, term_col = 0;
static uint8_t term_color = 0x07;
static char input_buffer[256];
static char command_history[10][256];
static int history_count = 0, history_pos = 0;
static bool graphics_mode = false;
static uint32_t tick_count = 0;
// FILE SYSTEM
#define MAX_FILENAME 32
#define MAX_FILES 256
#define MAX_FILE_SIZE 8192
#define MAX_PATH 256
typedef enum { FS_FILE = 1, FS_DIRECTORY = 2 } fs_node_type;
typedef struct fs_node {
char name[MAX_FILENAME];
fs_node_type type;
size_t size;
char* content;
struct fs_node* parent;
struct fs_node* children[64];
int child_count;
uint32_t created_time;
uint8_t permissions;
} fs_node_t;
fs_node_t* fs_root;
fs_node_t* current_dir;
fs_node_t fs_nodes[MAX_FILES];
int fs_node_count = 0;
char file_data_pool[MAX_FILES * MAX_FILE_SIZE];
int file_data_used = 0;
char current_path[256] = "/";
// EDITOR
typedef struct {
char* content;
size_t size;
size_t capacity;
int cursor_x, cursor_y;
int scroll_y;
bool modified;
char filename[MAX_FILENAME];
} editor_t;
static editor_t editor = {0};
// PROCESSES
#define MAX_PROCESSES 16
typedef struct {
int pid;
char name[32];
uint32_t stack_ptr;
bool active;
int priority;
} process_t;
process_t processes[MAX_PROCESSES];
int next_pid = 1;
// GAMES
typedef struct { int x, y, dir, score; bool game_over; } snake_t;
typedef struct { int x, y, vx, vy, score; } pong_t;
// NETWORK
typedef struct { bool active; uint32_t ip; uint16_t port; char buffer[512]; } connection_t;
connection_t connections[4];
// IDT pour interruptions
typedef struct {
uint16_t base_lo;
uint16_t sel;
uint8_t always0;
uint8_t flags;
uint16_t base_hi;
} __attribute__((packed)) idt_entry_t;
typedef struct {
uint16_t limit;
uint32_t base;
} __attribute__((packed)) idt_ptr_t;
idt_entry_t idt_entries[256];
idt_ptr_t idt_ptr;
// ==================== I/O FUNCTIONS ====================
static inline void outb(uint16_t port, uint8_t val) {
__asm__ volatile ("outb %0, %1" : : "a"(val), "Nd"(port));
}
static inline uint8_t inb(uint16_t port) {
uint8_t ret;
__asm__ volatile ("inb %1, %0" : "=a"(ret) : "Nd"(port));
return ret;
}
// ==================== STRING FUNCTIONS ====================
size_t strlen(const char* str) { size_t len = 0; while (str[len]) len++; return len; }
int strcmp(const char* s1, const char* s2) {
while (*s1 && (*s1 == *s2)) { s1++; s2++; }
return *(const unsigned char*)s1 - *(const unsigned char*)s2;
}
void strcpy(char* dest, const char* src) { while (*src) *dest++ = *src++; *dest = '\0'; }
void strcat(char* dest, const char* src) { while (*dest) dest++; while (*src) *dest++ = *src++; *dest = '\0'; }
char* strchr(const char* str, char c) { while (*str) { if (*str == c) return (char*)str; str++; } return NULL; }
void memcpy(void* dest, const void* src, size_t n) { uint8_t* d = dest; const uint8_t* s = src; while (n--) *d++ = *s++; }
void memset(void* ptr, int value, size_t n) { uint8_t* p = ptr; while (n--) *p++ = value; }
int strncmp(const char* s1, const char* s2, size_t n) {
while (n-- && *s1 && (*s1 == *s2)) { s1++; s2++; }
return n == SIZE_MAX ? 0 : *(unsigned char*)s1 - *(unsigned char*)s2;
}
bool starts_with(const char* str, const char* prefix) {
while (*prefix) if (*str++ != *prefix++) return false; return true;
}
// ==================== TERMINAL FUNCTIONS ====================
static inline uint16_t vga_entry(char c, uint8_t color) { return (uint16_t)c | (uint16_t)color << 8; }
void term_clear() {
for (int i = 0; i < VGA_WIDTH * VGA_HEIGHT; i++) VGA_MEMORY[i] = vga_entry(' ', term_color);
term_row = 0; term_col = 0;
}
void term_scroll() {
for (int i = 0; i < VGA_WIDTH * (VGA_HEIGHT - 1); i++) VGA_MEMORY[i] = VGA_MEMORY[i + VGA_WIDTH];
for (int i = VGA_WIDTH * (VGA_HEIGHT - 1); i < VGA_WIDTH * VGA_HEIGHT; i++) VGA_MEMORY[i] = vga_entry(' ', term_color);
term_row = VGA_HEIGHT - 1;
}
void term_putchar(char c) {
if (c == '\n') {
term_col = 0;
if (++term_row >= VGA_HEIGHT) term_scroll();
} else if (c == '\b') {
if (term_col > 0) {
term_col--;
VGA_MEMORY[term_row * VGA_WIDTH + term_col] = vga_entry(' ', term_color);
}
} else {
VGA_MEMORY[term_row * VGA_WIDTH + term_col] = vga_entry(c, term_color);
if (++term_col >= VGA_WIDTH) {
term_col = 0;
if (++term_row >= VGA_HEIGHT) term_scroll();
}
}
}
void term_write(const char* str) { while (*str) term_putchar(*str++); }
void term_setcolor(uint8_t color) { term_color = color; }
// Curseur clignotant
void enable_cursor() {
outb(0x3D4, 0x0A);
outb(0x3D5, (inb(0x3D5) & 0xC0) | 14);
outb(0x3D4, 0x0B);
outb(0x3D5, (inb(0x3D5) & 0xE0) | 15);
}
void update_cursor() {
uint16_t pos = term_row * VGA_WIDTH + term_col;
outb(0x3D4, 0x0F);
outb(0x3D5, (uint8_t)(pos & 0xFF));
outb(0x3D4, 0x0E);
outb(0x3D5, (uint8_t)((pos >> 8) & 0xFF));
}
// ==================== GRAPHICS FUNCTIONS ====================
void init_graphics() {
outb(0x3C8, 0);
for (int i = 0; i < 256; i++) {
outb(0x3C9, i >> 2); outb(0x3C9, i >> 2); outb(0x3C9, i >> 2);
}
graphics_mode = true;
}
void set_pixel(int x, int y, uint8_t color) {
if (x >= 0 && x < 320 && y >= 0 && y < 200) {
GRAPHICS_MEMORY[y * 320 + x] = color;
}
}
void draw_line(int x1, int y1, int x2, int y2, uint8_t color) {
int dx = x2 - x1, dy = y2 - y1;
int steps = (dx > dy ? dx : dy);
if (steps < 0) steps = -steps;
float x_inc = (float)dx / steps, y_inc = (float)dy / steps;
float x = x1, y = y1;
for (int i = 0; i <= steps; i++) {
set_pixel((int)x, (int)y, color);
x += x_inc; y += y_inc;
}
}
void draw_rect(int x, int y, int w, int h, uint8_t color) {
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
set_pixel(x + j, y + i, color);
}
}
}
void exit_graphics() { graphics_mode = false; }
// ==================== IDT ET INTERRUPTIONS ====================
extern void idt_flush(uint32_t);
void idt_set_gate(uint8_t num, uint32_t base, uint16_t sel, uint8_t flags) {
idt_entries[num].base_lo = base & 0xFFFF;
idt_entries[num].base_hi = (base >> 16) & 0xFFFF;
idt_entries[num].sel = sel;
idt_entries[num].always0 = 0;
idt_entries[num].flags = flags | 0x60;
}
void init_idt() {
idt_ptr.limit = sizeof(idt_entry_t) * 256 - 1;
idt_ptr.base = (uint32_t)&idt_entries;
for (int i = 0; i < 256; i++) idt_set_gate(i, 0, 0, 0);
// Remap PIC
outb(0x20, 0x11); outb(0xA0, 0x11);
outb(0x21, 0x20); outb(0xA1, 0x28);
outb(0x21, 0x04); outb(0xA1, 0x02);
outb(0x21, 0x01); outb(0xA1, 0x01);
outb(0x21, 0x0); outb(0xA1, 0x0);
idt_flush((uint32_t)&idt_ptr);
}
// Timer handler
void timer_handler() {
tick_count++;
// Horloge temps réel
if (tick_count % 18 == 0) {
size_t old_row = term_row, old_col = term_col;
uint8_t old_color = term_color;
term_row = 0; term_col = VGA_WIDTH - 10; term_color = 0x1F;
char time[9] = "00:00:00";
uint32_t seconds = tick_count / 18;
time[6] = '0' + ((seconds % 60) / 10);
time[7] = '0' + (seconds % 10);
time[3] = '0' + (((seconds / 60) % 60) / 10);
time[4] = '0' + ((seconds / 60) % 10);
time[0] = '0' + (((seconds / 3600) % 24) / 10);
time[1] = '0' + ((seconds / 3600) % 10);
term_write(time);
term_row = old_row; term_col = old_col; term_color = old_color;
update_cursor();
}
}
void init_timer(uint32_t freq) {
uint32_t divisor = 1193180 / freq;
outb(0x43, 0x36);
outb(0x40, divisor & 0xFF);
outb(0x40, (divisor >> 8) & 0xFF);
}
// ==================== FILE SYSTEM ====================
fs_node_t* fs_find_child(fs_node_t* parent, const char* name) {
if (!parent || parent->type != FS_DIRECTORY) return NULL;
for (int i = 0; i < parent->child_count; i++) {
if (strcmp(parent->children[i]->name, name) == 0) return parent->children[i];
}
return NULL;
}
fs_node_t* fs_create_node(const char* name, fs_node_type type, fs_node_t* parent) {
if (fs_node_count >= MAX_FILES) return NULL;
fs_node_t* node = &fs_nodes[fs_node_count++];
strcpy(node->name, name);
node->type = type; node->size = 0; node->content = NULL;
node->parent = parent; node->child_count = 0; node->permissions = 0x75;
if (parent && parent->child_count < 64) parent->children[parent->child_count++] = node;
return node;
}
fs_node_t* fs_resolve_path(const char* path) {
if (!path || !*path) return current_dir;
fs_node_t* node;
char temp_path[MAX_PATH];
strcpy(temp_path, path);
if (path[0] == '/') {
node = fs_root;
char* p = temp_path + 1;
char* token = p;
while (*p) {
if (*p == '/') {
*p = '\0';
if (*token) {
node = fs_find_child(node, token);
if (!node) return NULL;
}
token = p + 1;
}
p++;
}
if (*token) node = fs_find_child(node, token);
} else {
node = current_dir;
char* token = temp_path;
char* p = temp_path;
while (*p) {
if (*p == '/') {
*p = '\0';
if (strcmp(token, "..") == 0) {
if (node->parent) node = node->parent;
} else if (strcmp(token, ".") != 0 && *token) {
node = fs_find_child(node, token);
if (!node) return NULL;
}
token = p + 1;
}
p++;
}
if (*token) {
if (strcmp(token, "..") == 0) {
if (node->parent) node = node->parent;
} else if (strcmp(token, ".") != 0) {
node = fs_find_child(node, token);
}
}
}
return node;
}
void fs_get_path(fs_node_t* node, char* buffer) {
if (!node || node == fs_root) { strcpy(buffer, "/"); return; }
char temp[MAX_PATH];
char* p = temp + MAX_PATH - 1;
*p = '\0';
while (node && node != fs_root) {
size_t len = strlen(node->name);
p -= len; memcpy(p, node->name, len);
p--; *p = '/';
node = node->parent;
}
strcpy(buffer, p);
}
void fs_init() {
fs_node_count = 0; file_data_used = 0;
fs_root = fs_create_node("/", FS_DIRECTORY, NULL);
current_dir = fs_root;
// Standard directories
fs_create_node("home", FS_DIRECTORY, fs_root);
fs_create_node("bin", FS_DIRECTORY, fs_root);
fs_create_node("etc", FS_DIRECTORY, fs_root);
fs_create_node("tmp", FS_DIRECTORY, fs_root);
fs_create_node("var", FS_DIRECTORY, fs_root);
fs_create_node("games", FS_DIRECTORY, fs_root);
fs_create_node("dev", FS_DIRECTORY, fs_root);
// Files dans /etc
fs_node_t* etc = fs_find_child(fs_root, "etc");
if (etc) {
fs_node_t* motd = fs_create_node("motd", FS_FILE, etc);
if (motd && file_data_used + 100 < sizeof(file_data_pool)) {
const char* content = "🎉 Welcome to HybridOS Ultimate v2.0!\n🚀 The Complete Operating System Experience\n\n✨ Features loaded:\n- FileSystem with full Unix commands\n- Integrated text editor\n- Graphics mode and games\n- Process management\n- Network stack\n- BASIC interpreter and C compiler\n- Real-time clock\n- Command history and autocompletion\n\nType 'help' to see all commands!\n";
motd->content = &file_data_pool[file_data_used];
strcpy(motd->content, content);
motd->size = strlen(content);
file_data_used += motd->size + 1;
}
fs_node_t* version = fs_create_node("version", FS_FILE, etc);
if (version && file_data_used + 50 < sizeof(file_data_pool)) {
const char* content = "HybridOS Ultimate v2.0\nKernel: 5.0-hybrid-ultimate\nBuild: Complete Edition\nFeatures: ALL\n";
version->content = &file_data_pool[file_data_used];
strcpy(version->content, content);
version->size = strlen(content);
file_data_used += version->size + 1;
}
}
// User home
fs_node_t* home = fs_find_child(fs_root, "home");
if (home) {
fs_node_t* user = fs_create_node("user", FS_DIRECTORY, home);
if (user) {
fs_node_t* readme = fs_create_node("readme.txt", FS_FILE, user);
if (readme && file_data_used + 1000 < sizeof(file_data_pool)) {
const char* content = "🎯 HybridOS Ultimate v2.0 - COMPLETE FEATURES GUIDE\n"
"================================================================\n\n"
"📁 FILE SYSTEM COMMANDS:\n"
" ls [path] - List files and directories\n"
" cd <path> - Change directory (try 'cd ..' or 'cd /')\n"
" pwd - Show current directory\n"
" mkdir <name> - Create directory\n"
" touch <name> - Create empty file\n"
" cat <file> - Display file contents\n"
" cp <src> <dest> - Copy file\n"
" mv <old> <new> - Move/rename file\n"
" rm <file> - Remove file\n"
" find <pattern> - Search for files\n"
" grep <text> <file> - Search in file\n\n"
"✍️ TEXT EDITOR:\n"
" edit <filename> - Open built-in editor\n"
" Ctrl+S - Save file\n"
" Ctrl+X - Exit editor\n\n"
"🎮 GAMES & GRAPHICS:\n"
" snake - Snake game (WASD to move, Q to quit)\n"
" pong - Pong game (WS for paddle)\n"
" graphics - VGA graphics mode demo\n"
" matrix - Matrix digital rain effect\n\n"
"🔧 SYSTEM MANAGEMENT:\n"
" ps - List running processes\n"
" kill <pid> - Terminate process\n"
" reboot - Restart system\n"
" clear - Clear screen\n\n"
"🌐 NETWORK TOOLS:\n"
" ping <host> - Ping a host\n"
" http - Start HTTP server\n\n"
"💻 DEVELOPMENT:\n"
" compile <file.c> - C compiler\n"
" basic <code> - BASIC interpreter\n"
" run <program> - Execute program\n\n"
"⌨️ INTERFACE FEATURES:\n"
" ↑↓ Arrow keys - Command history\n"
" Tab - Command autocompletion\n"
" Real-time clock - Top right corner\n"
" Colored output - Full VGA colors\n\n"
"🎯 TRY THESE DEMOS:\n"
" cd /etc && cat motd\n"
" edit hello.c\n"
" snake\n"
" graphics\n"
" matrix\n\n"
"💡 This file was created by the filesystem!\n"
"Edit it with: edit readme.txt\n";
readme->content = &file_data_pool[file_data_used];
strcpy(readme->content, content);
readme->size = strlen(content);
file_data_used += readme->size + 1;
}
fs_node_t* demo = fs_create_node("demo.c", FS_FILE, user);
if (demo && file_data_used + 300 < sizeof(file_data_pool)) {
const char* content = "#include <stdio.h>\n\nint main() {\n printf(\"Hello from HybridOS!\\n\");\n printf(\"This C code runs on our hybrid kernel!\\n\");\n \n // Features demo\n for (int i = 0; i < 5; i++) {\n printf(\"Loop %d: Windows + Linux = HybridOS\\n\", i);\n }\n \n return 0;\n}\n\n// Try: compile demo.c\n// run demo\n";
demo->content = &file_data_pool[file_data_used];
strcpy(demo->content, content);
demo->size = strlen(content);
file_data_used += demo->size + 1;
}
}
}
}
// ==================== KEYBOARD INPUT ====================
char read_key() {
static const char scancode_ascii[] = {
0, 27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b',
'\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n',
0, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`',
0, '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 0,
'*', 0, ' '
};
while (!(inb(0x64) & 1));
uint8_t scancode = inb(0x60);
// Special keys
if (scancode == 0x48) return 1; // Up arrow
if (scancode == 0x50) return 2; // Down arrow
if (scancode == 0x4B) return 3; // Left arrow
if (scancode == 0x4D) return 4; // Right arrow
if (scancode == 0x0F) return '\t'; // Tab
if (scancode & 0x80) return 0; // Key release
if (scancode < sizeof(scancode_ascii)) return scancode_ascii[scancode];
return 0;
}
void get_input_with_history(char* buffer, int max_len) {
int pos = 0;
char c;
while (pos < max_len - 1) {
c = read_key();
if (c == '\n') {
buffer[pos] = '\0';
term_putchar('\n');
if (pos > 0 && history_count < 10) {
strcpy(command_history[history_count], buffer);
history_count++;
}
history_pos = history_count;
break;
} else if (c == '\b' && pos > 0) {
pos--;
term_putchar('\b');
} else if (c == 1) { // Up arrow
if (history_pos > 0) {
history_pos--;
while (pos > 0) { pos--; term_putchar('\b'); }
strcpy(buffer, command_history[history_pos]);
pos = strlen(buffer);
term_write(buffer);
}
} else if (c == 2) { // Down arrow
if (history_pos < history_count - 1) {
history_pos++;
while (pos > 0) { pos--; term_putchar('\b'); }
strcpy(buffer, command_history[history_pos]);
pos = strlen(buffer);
term_write(buffer);
}
} else if (c == '\t') { // Tab completion
if (pos > 0) {
const char* commands[] = {"ls", "cd", "pwd", "mkdir", "touch", "cat", "echo", "rm", "cp", "mv", "find", "grep", "edit", "help", "clear", "tree", "about", "ps", "kill", "snake", "pong", "graphics", "matrix", "ping", "http", "compile", "run", "basic", "reboot", NULL};
for (int i = 0; commands[i]; i++) {
if (starts_with(commands[i], buffer)) {
while (pos > 0) { pos--; term_putchar('\b'); }
strcpy(buffer, commands[i]);
pos = strlen(buffer);
term_write(buffer);
break;
}
}
}
} else if (c && c > 31) {
buffer[pos++] = c;
term_putchar(c);
}
}
}
// ==================== EDITOR ====================
void editor_init(const char* filename) {
memset(&editor, 0, sizeof(editor));
strcpy(editor.filename, filename);
editor.capacity = 4096;
editor.content = &file_data_pool[file_data_used];
file_data_used += editor.capacity;
fs_node_t* file = fs_resolve_path(filename);
if (file && file->type == FS_FILE && file->content) {
memcpy(editor.content, file->content, file->size);
editor.size = file->size;
}
}
void editor_save() {
fs_node_t* file = fs_resolve_path(editor.filename);
if (!file) file = fs_create_node(editor.filename, FS_FILE, current_dir);
if (file) {
if (!file->content) {
file->content = &file_data_pool[file_data_used];
file_data_used += editor.size + 1;
}
memcpy(file->content, editor.content, editor.size);
file->size = editor.size;
editor.modified = false;
}
}
void editor_display() {
term_clear();
term_setcolor(0x0F);
term_write("================== HybridOS Ultimate Editor ==================\n");
term_setcolor(0x0E);
term_write("File: ");
term_write(editor.filename);
if (editor.modified) {
term_setcolor(0x0C);
term_write(" [MODIFIED]");
}
term_setcolor(0x07);
term_write("\n");
// Display content with cursor
int line = 0, col = 0;
for (size_t i = 0; i < editor.size && line < VGA_HEIGHT - 4; i++) {
if (i == editor.cursor_x) {
term_setcolor(0x70); // Highlight cursor position
}
term_putchar(editor.content[i]);
if (i == editor.cursor_x) {
term_setcolor(0x07);
}
if (editor.content[i] == '\n') {
line++;
col = 0;
} else {
col++;
}
}
// Show cursor if at end
if (editor.cursor_x >= editor.size) {
term_setcolor(0x70);
term_putchar(' ');
term_setcolor(0x07);
}
// Status line
term_row = VGA_HEIGHT - 2;
term_col = 0;
term_setcolor(0x1F);
term_write("Ctrl+S: Save | Ctrl+X: Exit | Size: ");
char size_str[16];
int idx = 15;
size_str[idx--] = '\0';
size_t size = editor.size;
if (size == 0) size_str[idx--] = '0';
else while (size > 0 && idx >= 0) {
size_str[idx--] = '0' + (size % 10);
size /= 10;
}
term_write(&size_str[idx + 1]);
term_write(" bytes");
// Fill rest of status line
while (term_col < VGA_WIDTH) term_putchar(' ');
term_setcolor(0x07);
}
// ==================== GAMES ====================
void game_snake() {
if (!graphics_mode) init_graphics();
snake_t snake = {160, 100, 4, 0, false};
int food_x = 200, food_y = 150;
term_clear();
term_setcolor(0x0A);
term_write("🐍 SNAKE GAME - HybridOS Ultimate Edition\n");
term_setcolor(0x0E);
term_write("Controls: WASD to move, Q to quit\n");
term_setcolor(0x07);
term_write("Starting game...\n");
// Simple delay before starting graphics
for (volatile int i = 0; i < 10000000; i++);
while (!snake.game_over) {
// Clear screen
memset(GRAPHICS_MEMORY, 0, 320 * 200);
// Draw border
for (int x = 0; x < 320; x++) {
set_pixel(x, 0, 15);
set_pixel(x, 199, 15);
}
for (int y = 0; y < 200; y++) {
set_pixel(0, y, 15);
set_pixel(319, y, 15);
}
// Draw snake
draw_rect(snake.x - 5, snake.y - 5, 10, 10, 2); // Green
// Draw food
draw_rect(food_x - 3, food_y - 3, 6, 6, 4); // Red
// Draw score
for (int i = 0; i < snake.score; i++) {
set_pixel(10 + i * 2, 10, 14); // Yellow score dots
}
// Get input
if (inb(0x64) & 1) {
char key = read_key();
if (key == 'w') snake.direction = 1;
if (key == 's') snake.direction = 2;
if (key == 'a') snake.direction = 3;
if (key == 'd') snake.direction = 4;
if (key == 'q') break;
}
// Move snake
if (snake.direction == 1) snake.y -= 3;
if (snake.direction == 2) snake.y += 3;
if (snake.direction == 3) snake.x -= 3;
if (snake.direction == 4) snake.x += 3;
// Check boundaries
if (snake.x < 10 || snake.x > 310 || snake.y < 10 || snake.y > 190) {
snake.game_over = true;
}
// Check food collision
if (snake.x >= food_x - 8 && snake.x <= food_x + 8 &&
snake.y >= food_y - 8 && snake.y <= food_y + 8) {
snake.score++;
food_x = 30 + (snake.score * 37) % 260;
food_y = 30 + (snake.score * 23) % 140;
}
// Delay
for (volatile int i = 0; i < 300000; i++);
}
exit_graphics();
term_clear();
term_setcolor(0x0C);
term_write("🎮 Game Over!\n");
term_setcolor(0x0E);
term_write("Final Score: ");
if (snake.score < 10) {
term_putchar('0' + snake.score);
} else {
term_putchar('0' + (snake.score / 10));
term_putchar('0' + (snake.score % 10));
}
term_write("\n");
term_setcolor(0x07);
}
void game_pong() {
if (!graphics_mode) init_graphics();
pong_t ball = {160, 100, 2, 1, 0};
int paddle_y = 90;
term_clear();
term_setcolor(0x0B);
term_write("🏓 PONG - HybridOS Ultimate Edition\n");
term_setcolor(0x0E);
term_write("Controls: W/S for paddle, Q to quit\n");
while (true) {
// Clear screen
memset(GRAPHICS_MEMORY, 0, 320 * 200);
// Draw center line
for (int y = 0; y < 200; y += 4) {
set_pixel(160, y, 8);
set_pixel(160, y + 1, 8);
}
// Draw ball
draw_rect(ball.x - 3, ball.y - 3, 6, 6, 15);
// Draw paddle
draw_rect(10, paddle_y, 8, 25, 14);
// Draw AI paddle
int ai_paddle_y = ball.y - 12;
if (ai_paddle_y < 0) ai_paddle_y = 0;
if (ai_paddle_y > 175) ai_paddle_y = 175;
draw_rect(302, ai_paddle_y, 8, 25, 12);
// Get input
if (inb(0x64) & 1) {
char key = read_key();
if (key == 'w' && paddle_y > 0) paddle_y -= 8;
if (key == 's' && paddle_y < 175) paddle_y += 8;
if (key == 'q') break;
}
// Move ball
ball.x += ball.vx;
ball.y += ball.vy;
// Ball collisions
if (ball.y <= 3 || ball.y >= 197) ball.vy = -ball.vy;
if (ball.x >= 294 && ball.y >= ai_paddle_y && ball.y <= ai_paddle_y + 25) {
ball.vx = -ball.vx;
}
if (ball.x <= 18 && ball.y >= paddle_y && ball.y <= paddle_y + 25) {
ball.vx = -ball.vx;
ball.score++;
}
if (ball.x <= 0 || ball.x >= 320) {
ball.x = 160; ball.y = 100; // Reset
ball.vx = (ball.vx > 0) ? -2 : 2;
}
// Draw score
for (int i = 0; i < ball.score && i < 20; i++) {
set_pixel(20 + i * 3, 20, 10);
}
for (volatile int i = 0; i < 150000; i++);
}
exit_graphics();
}
void matrix_effect() {
term_clear();
term_setcolor(0x0A);
char matrix[VGA_HEIGHT][VGA_WIDTH];
int drops[VGA_WIDTH];
// Initialize
for (int x = 0; x < VGA_WIDTH; x++) {
drops[x] = 0;
}
for (int frame = 0; frame < 200; frame++) {
// Clear some positions
for (int y = 0; y < VGA_HEIGHT; y++) {
for (int x = 0; x < VGA_WIDTH; x++) {
if (frame % 2 == 0) matrix[y][x] = ' ';
else matrix[y][x] = '0' + ((frame + x + y) % 10);
}
}
// Update drops
for (int x = 0; x < VGA_WIDTH; x++) {
if (drops[x] == 0 && (frame + x) % 5 == 0) {
drops[x] = 1;
}
if (drops[x] > 0) {
int y = drops[x] - 1;
if (y < VGA_HEIGHT) {
matrix[y][x] = '0' + ((frame + x) % 10);
}
drops[x]++;
if (drops[x] > VGA_HEIGHT + 10) drops[x] = 0;
}
}
// Display
term_row = 0; term_col = 0;
for (int y = 0; y < VGA_HEIGHT - 1; y++) {
for (int x = 0; x < VGA_WIDTH; x++) {
term_putchar(matrix[y][x]);
}
}
// Check for quit
if (inb(0x64) & 1) {
char key = read_key();
if (key == 'q' || key == 27) break;
}
for (volatile int i = 0; i < 1000000; i++);
}
term_setcolor(0x07);
term_clear();
}
// ==================== PROCESS MANAGEMENT ====================
void init_processes() {
memset(processes, 0, sizeof(processes));
processes[0].pid = 0;
strcpy(processes[0].name, "kernel");
processes[0].active = true;
processes[0].priority = 10;
}
void list_processes() {
term_setcolor(0x0F);
term_write("PID NAME PRIORITY STATUS\n");
term_setcolor(0x08);
term_write("=====================================\n");
term_setcolor(0x07);
for (int i = 0; i < MAX_PROCESSES; i++) {
if (processes[i].active) {
// PID
if (processes[i].pid < 10) {
term_putchar('0' + processes[i].pid);
term_write(" ");
} else {
term_putchar('0' + (processes[i].pid / 10));
term_putchar('0' + (processes[i].pid % 10));
term_write(" ");
}
// Name
term_write(processes[i].name);
int name_len = strlen(processes[i].name);
for (int j = name_len; j < 15; j++) term_putchar(' ');
// Priority
term_putchar('0' + processes[i].priority);
term_write(" ");
// Status
term_setcolor(0x0A);
term_write("RUNNING");
term_setcolor(0x07);
term_write("\n");
}
}
}
// ==================== NETWORK ====================
void ping(const char* target) {
term_setcolor(0x0E);
term_write("PING ");
term_write(target ? target : "127.0.0.1");
term_write(" - HybridOS Network Stack\n");
term_setcolor(0x07);
for (int i = 1; i <= 4; i++) {
term_setcolor(0x0A);
term_write("64 bytes from ");
term_write(target ? target : "127.0.0.1");
term_write(": icmp_seq=");
term_putchar('0' + i);
term_write(" ttl=64 time=");
term_putchar('0' + (i % 10));
term_write(".");
term_putchar('0' + ((i * 7) % 10));
term_putchar('0' + ((i * 3) % 10));
term_write(" ms\n");
// Simulate network delay
for (volatile int j = 0; j < 5000000; j++);
}
term_setcolor(0x0B);
term_write("\n--- ");
term_write(target ? target : "127.0.0.1");
term_write(" ping statistics ---\n");
term_write("4 packets transmitted, 4 received, 0% packet loss\n");
term_setcolor(0x07);
}
void http_server() {
term_setcolor(0x0B);
term_write("🌐 HybridOS HTTP Server v1.0\n");
term_setcolor(0x0E);
term_write("Starting server on port 80...\n");
term_setcolor(0x0A);
term_write("Server running at http://localhost/\n");