Skip to content

Commit 53017be

Browse files
committed
Added basic file buffer editing to feed the interpreter
1 parent 648ef50 commit 53017be

File tree

7 files changed

+205
-27
lines changed

7 files changed

+205
-27
lines changed

bootloader_stage2.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
;BIOS_DATA_AREA equ 0x400
1010
KERNEL_ADDRESS equ 0x200
11-
NUM_SECTORS equ 57
11+
NUM_SECTORS equ 53
1212

1313
; GDT definitions
1414
gdt_start:

files/file1.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

files/file2.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

files/file4.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

files/testfunc.c

Lines changed: 0 additions & 3 deletions
This file was deleted.

kernel.c

Lines changed: 168 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
#define INSERT 3
1010
#define CAPSLOCK 4
1111

12+
//terminal modes:
13+
#define TERMINAL 0
14+
#define EDITOR 1
15+
#define INTERPRETER 2
16+
1217
void delay(int);
1318
void print(int, int, char *);
1419
void printChar(int, int, char, int);
@@ -26,7 +31,11 @@ void clearScreen(int);
2631
void scrollUp();
2732
void cursorBackwards();
2833
void cursorForwards();
34+
2935
void keyPressed(unsigned char);
36+
void terminal_keyPressed(unsigned char, char);
37+
void editor_keyPressed(unsigned char, char);
38+
void interpreter_keyPressed(unsigned char, char);
3039
void pitCall();
3140
void rtcCall();
3241
void printStatus(unsigned char);
@@ -47,6 +56,10 @@ int commandLength;
4756
char counter;
4857
char prevCommand[20];
4958

59+
int terminalMode;
60+
61+
char fileBuffer[height*width];
62+
5063
#include "driver.c"
5164
#include "util.c"
5265
#include "IDT.c"
@@ -70,6 +83,7 @@ void main(){
7083
}
7184
modifier[INSERT] = 1;
7285
modifier[CAPSLOCK] = 0;
86+
terminalMode = TERMINAL;
7387
prompt = '$';
7488
promptColor = 0x02;
7589
clearScreen(0x0F);
@@ -98,6 +112,128 @@ void main(){
98112
//down: E0 50 E0 D0
99113
void keyPressed(unsigned char code){
100114
char c = scancodeToAscii(code, modifier[SHIFT], modifier[CTRL], modifier[CAPSLOCK]);
115+
if(terminalMode == TERMINAL){
116+
terminal_keyPressed(code, c);
117+
} else if(terminalMode == EDITOR){
118+
editor_keyPressed(code, c);
119+
} else if(terminalMode == INTERPRETER){
120+
interpreter_keyPressed(code, c);
121+
}
122+
}
123+
124+
void editor_keyPressed(unsigned char code, char c){
125+
char printable = 1;
126+
if(code == 0x0E){ // backspace
127+
if(ttx == 0 && tty == 0) return;
128+
cursorBackwards();
129+
int i = 0;
130+
while(getChar(ttx + i, tty) != 0){
131+
printChar(ttx+i,tty,getChar(ttx+i+1,tty),0x0F);
132+
i++;
133+
}
134+
printable = 0;
135+
} else if(code == 0x4B){ // left arrow
136+
ttx--;
137+
if(ttx == -1){
138+
ttx = 0;
139+
tty--;
140+
if(tty == -1) tty = 0;
141+
}
142+
setCursor(ttx, tty);
143+
printable = 0;
144+
} else if(code == 0x4D){ // right arrow
145+
ttx++;
146+
if(ttx == width){
147+
ttx = width-1;
148+
tty++;
149+
if(tty == height) tty = height-1;
150+
}
151+
setCursor(ttx, tty);
152+
printable = 0;
153+
} else if(code == 0x48){ // up arrow
154+
tty--;
155+
if(tty == -1) tty = 0;
156+
setCursor(ttx, tty);
157+
printable = 0;
158+
} else if(code == 0x50){ // down arrow
159+
tty++;
160+
if(tty == height) tty = height-1;
161+
setCursor(ttx, tty);
162+
printable = 0;
163+
} else if(code == 0xCB){ // left arrow release
164+
printable = 0;
165+
} else if(code == 0xCD){ // right arrow release
166+
printable = 0;
167+
} else if(code == 0xC8){ // up arrow release
168+
printable = 0;
169+
} else if(code == 0xCB){ // down arrow release
170+
printable = 0;
171+
} else if(code == 0x1D){ // control on
172+
modifier[CTRL] = 1;
173+
printable = 0;
174+
} else if(code == 0x9D){ //control off
175+
modifier[CTRL] = 0;
176+
printable = 0;
177+
} else if(code == 0x36 || code == 0x2A){ //shift on
178+
modifier[SHIFT] = 1;
179+
printable = 0;
180+
} else if(code == 0xB6 || code == 0xAA){ //shift off
181+
modifier[SHIFT] = 0;
182+
printable = 0;
183+
} else if(code == 0x38){ // alt on
184+
modifier[ALT] = 1;
185+
printable = 0;
186+
} else if(code == 0xB8){ // alt off
187+
modifier[ALT] = 0;
188+
printable = 0;
189+
} else if(code == 0x52){ // insert
190+
modifier[INSERT]++;
191+
modifier[INSERT] %= 2;
192+
printable = 0;
193+
} else if(code == 0x3A){ // capslock
194+
modifier[CAPSLOCK]++;
195+
modifier[CAPSLOCK] %= 2;
196+
printable = 0;
197+
}
198+
printStatus(code);
199+
200+
201+
if(modifier[CTRL] && c == 's'){
202+
int x = 0;
203+
int y = 0;
204+
for(y = 0; y < height; y++){
205+
for(x = 0; x < width; x++){
206+
fileBuffer[y*width + x] = getChar(x,y);
207+
}
208+
}
209+
printable = 0;
210+
clearScreen(0x00);
211+
terminalMode = TERMINAL;
212+
ttx = 0; tty = 0;
213+
setCursor(ttx,tty);
214+
printPrompt();
215+
printStatus(0x00);
216+
return;
217+
}
218+
219+
if(c == 0) return;
220+
if(modifier[INSERT] && printable == 1){
221+
int i = 0;
222+
while(getChar(ttx + i, tty) != 0){
223+
i++;
224+
}
225+
while(i > 0){
226+
printChar(ttx + i,tty,getChar(ttx+i-1,tty),0x0F);
227+
i--;
228+
}
229+
}
230+
ttprintChar(c);
231+
232+
233+
}
234+
void interpreter_keyPressed(unsigned char code, char c){}
235+
236+
void terminal_keyPressed(unsigned char code, char c){
101237
if(code == 0x0E){ // backspace
102238
if(getChar(ttx-1,tty) == prompt) return;
103239
cursorBackwards();
@@ -164,8 +300,10 @@ void keyPressed(unsigned char code){
164300
commandLength = strLen(command);
165301
memCopy(command,prevCommand,commandLength);
166302
sh_handler(command);
167-
ttprintChar(c);
168-
printPrompt();
303+
if(terminalMode == TERMINAL){
304+
ttprintChar(c);
305+
printPrompt();
306+
}
169307
}
170308
}
171309
void printPrompt(){
@@ -193,37 +331,55 @@ void printStatus(unsigned char code){
193331
printChar(i,absolute_height,' ',0x0F);
194332
}
195333
int statusX = 0;
196-
print(statusX, absolute_height, "KeyCode:");
197-
statusX += 8;
198334
char str[10];
335+
print(statusX, absolute_height, "Code:");
336+
statusX += 5;
199337
charToString(code,str);
200338
if(code != -1) print(statusX, absolute_height, str);
201339
statusX += 4;
202-
print(statusX, absolute_height, " Insert:");
203-
statusX += 8;
340+
341+
print(statusX, absolute_height, " Ins:");
342+
statusX += 5;
204343
printChar(statusX, absolute_height, modifier[INSERT]+'0', 0x0F);
205344
statusX += 1;
345+
206346
print(statusX, absolute_height, " Shift:");
207347
statusX += 7;
208348
printChar(statusX, absolute_height, modifier[SHIFT]+'0', 0x0F);
209349
statusX += 1;
350+
210351
print(statusX, absolute_height, " Caps:");
211352
statusX += 6;
212353
printChar(statusX, absolute_height, modifier[CAPSLOCK]+'0', 0x0F);
213354
statusX += 1;
355+
214356
print(statusX, absolute_height, " Ctrl:");
215357
statusX += 6;
216358
printChar(statusX, absolute_height, modifier[CTRL]+'0', 0x0F);
217359
statusX += 1;
360+
218361
print(statusX, absolute_height, " Alt:");
219362
statusX += 5;
220363
printChar(statusX, absolute_height, modifier[ALT]+'0', 0x0F);
221364
statusX += 1;
222-
print(statusX, absolute_height, " Last Entry:");
223-
statusX += 12;
365+
366+
print(statusX, absolute_height, " Last:");
367+
statusX += 6;
224368
intToString(commandLength,str);
225369
print(statusX, absolute_height, str);
226-
statusX += strLen(str-1);
370+
statusX += strLen(str)-1;
371+
372+
print(statusX, absolute_height, " Mode:");
373+
statusX += 6;
374+
printChar(statusX, absolute_height, terminalMode+'0', 0x0F);
375+
statusX += 1;
376+
377+
print(statusX, absolute_height, " ttx:");
378+
statusX += 5;
379+
intToString(ttx, str);
380+
print(statusX, absolute_height, str);
381+
statusX += strLen(str)-1;
382+
227383
print(statusX, absolute_height, " Time:");
228384
statusX += 6;
229385
intToString(ticks/PITfreq,str);
@@ -299,6 +455,7 @@ void cursorBackwards(){
299455
setCursor(ttx,tty);
300456
}
301457
}
458+
302459
void scrollUp(){
303460
int j;
304461
for(j = 0; j < height-1; j++){
@@ -335,6 +492,8 @@ void setCursor(int x, int y){
335492
writeByteToPort(REG_SCREEN_DATA, high);
336493
writeByteToPort(REG_SCREEN_CTRL, 15);
337494
writeByteToPort(REG_SCREEN_DATA, low);
495+
ttx = x;
496+
tty = y;
338497
}
339498
int offset(int x, int y){
340499
return 2*(y*width+x);

shell_commands.c

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
void sh_readKFS(char*);
23
void sh_glissando(char*);
34
void sh_mario(char*);
@@ -18,10 +19,11 @@ void sh_cat(char*);
1819
void sh_head(char*);
1920
void sh_ls(char*);
2021
void sh_dataTypes(char*);
22+
void sh_edit(char*);
2123

2224

23-
char *shCommandList[] = {"ls", "head","dataTypes","cat","readKFS", "glissando", "mario", "delay", "beep", "sti", "cli", "htoi", "int", "hexDump", "help","rand","charTable","colorTable", "hexTable","null"};
24-
void (*shFunctionList[])(char*) = {sh_ls, sh_head, sh_dataTypes, sh_cat,sh_readKFS, sh_glissando, sh_mario, sh_delay, sh_beep, sh_sti, sh_cli, sh_htoi, sh_int, sh_hexDump, sh_help, sh_rand, sh_charTable, sh_colorTable, sh_hexTable, sh_null};
25+
char *shCommandList[] = {"edit", "ls", "head","dataTypes","cat","readKFS", "glissando", "mario", "delay", "beep", "sti", "cli", "htoi", "int", "hexDump", "help","rand","charTable","colorTable", "hexTable","null"};
26+
void (*shFunctionList[])(char*) = {sh_edit, sh_ls, sh_head, sh_dataTypes, sh_cat,sh_readKFS, sh_glissando, sh_mario, sh_delay, sh_beep, sh_sti, sh_cli, sh_htoi, sh_int, sh_hexDump, sh_help, sh_rand, sh_charTable, sh_colorTable, sh_hexTable, sh_null};
2527

2628
void sh_handler(char* command){
2729
int i=0;
@@ -36,10 +38,25 @@ void sh_handler(char* command){
3638
while(!strEquals(shCommandList[i],program) && !strEquals(shCommandList[i],"null")) i++;
3739
if(!strEquals(shCommandList[i],"null")) (*shFunctionList[i])(params);
3840
else {
39-
ttprint("Function not found: ");
41+
ttprint("Command not found: ");
4042
ttprintln(program);
4143
}
4244
}
45+
46+
void sh_edit(char* params){
47+
terminalMode = EDITOR;
48+
clearScreen(0x0F);
49+
int x = 0;
50+
int y = 0;
51+
for(y = 0; y < height; y++){
52+
for(x = 0; x < width; x++){
53+
printChar(x,y,fileBuffer[y*width + x],0x0F);
54+
}
55+
}
56+
setCursor(0,0);
57+
58+
}
59+
4360
void sh_ls(char* params){
4461
int i;
4562
char* pointer = KFS;
@@ -84,9 +101,14 @@ void sh_cat(char* params){
84101
}
85102
int i;
86103
unsigned char** pointer;
87-
int len = getFilePointer(params,pointer);
88-
for(i = 0; i < len; i++){
89-
ttprintChar((*pointer)[i]);
104+
if(strEquals(params,"buf")){
105+
for(i = 0; i < width*height; i++)
106+
ttprintChar(fileBuffer[i]);
107+
} else {
108+
int len = getFilePointer(params,pointer);
109+
for(i = 0; i < len; i++){
110+
ttprintChar((*pointer)[i]);
111+
}
90112
}
91113
}
92114
/*
@@ -152,7 +174,8 @@ void sh_readKFS(char* params){
152174
ttprintChar(pointer[i]);
153175
}
154176
}
155-
void sh_glissando(char* params){
177+
178+
void sh_glissando(char* params){/*
156179
int i = 220;
157180
//xxxx 50
158181
char param[8];
@@ -172,9 +195,10 @@ void sh_glissando(char* params){
172195
sh_beep(param);
173196
i = i + 20;
174197
}
175-
sh_beep("0 0");
198+
sh_beep("0 0");*/
176199
}
177-
void sh_mario(char* params){
200+
201+
void sh_mario(char* params){/*
178202
sh_beep("660 100");
179203
delay(150);
180204
sh_beep("660 100");
@@ -188,7 +212,7 @@ void sh_mario(char* params){
188212
sh_beep("770 100");
189213
delay(550);
190214
sh_beep("380 100");
191-
delay(575);
215+
delay(575);*/
192216
}
193217
void sh_delay(char* params){
194218
delay(strToInt(params));
@@ -268,10 +292,11 @@ void sh_hexDump(char* params){
268292
*/
269293
}
270294
void sh_help(char* params){
295+
/*
271296
if(strLen(params) > 1){
272297
ttprintIntln(strLen(params));
273298
ttprintln("help does not accept parameters");
274-
}
299+
}*/
275300
int i = 0;
276301
ttprint("Available commands are:");
277302
while(!strEquals(shCommandList[i],"null")){

0 commit comments

Comments
 (0)