summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-11-14 13:16:01 +0100
committerAlexis211 <alexis211@gmail.com>2009-11-14 13:16:01 +0100
commit4d5c1fcf9b1616db662a5cab0cec5ac878ce5175 (patch)
tree5ae433b358f933a9cec5bc9ef3c30ba9395fe322 /Source
parent2b9e97b8635c20c5a2b87789b1014489863d1994 (diff)
downloadMelon-4d5c1fcf9b1616db662a5cab0cec5ac878ce5175.tar.gz
Melon-4d5c1fcf9b1616db662a5cab0cec5ac878ce5175.zip
Changed some things in the way init is handled.
Also : - Modified stuff in the GOL simulator - Added support for a kernel-built-in keymap
Diffstat (limited to 'Source')
-rw-r--r--Source/Applications/Demos/GOL.cpp24
-rw-r--r--Source/Kernel/Config.h8
-rw-r--r--Source/Kernel/Core/kmain.wtf.cpp93
-rw-r--r--Source/Kernel/DeviceManager/Kbd.ns.cpp79
-rw-r--r--Source/Kernel/Shell/KernelShell.class.cpp5
5 files changed, 120 insertions, 89 deletions
diff --git a/Source/Applications/Demos/GOL.cpp b/Source/Applications/Demos/GOL.cpp
index 6dd1cdf..804c9ae 100644
--- a/Source/Applications/Demos/GOL.cpp
+++ b/Source/Applications/Demos/GOL.cpp
@@ -22,20 +22,22 @@ int main(Vector<String> args) {
}
}
- while (1) {
+ char *tmp = new char[w * h + 1];
+
+ bool run = true;
+ while (run) {
//Display cells
- outvt.moveCursor(0, 0);
for (u32int y = 0; y < h; y++) {
for (u32int x = 0; x < w; x++) {
if (cells[x * h + y]) {
- outvt.setColor(0, 2);
+ tmp[y * w + x] = '#';
} else {
- outvt.setColor(7, 0);
+ tmp[y * w + x] = ' ';
}
- outvt << " ";
}
}
- outvt << "Press Ctrl+h for help";
+ outvt.moveCursor(0, 0);
+ outvt << String(tmp, w*h) << "Press Ctrl+h for help";
//Compute next generation
for (u32int y = 0; y < h; y++) {
@@ -61,9 +63,9 @@ int main(Vector<String> args) {
}
keypress_t kp = invt.getKeypress(false, false);
- if (kp.hascmd && (kp.modifiers & STATUS_CTRL)) {
+ while (kp.hascmd && (kp.modifiers & STATUS_CTRL)) {
if (kp.character == WChar("c")) {
- break;
+ run = false;
} else if (kp.character == WChar("r")) {
for (u32int i = 0; i < 20; i++) {
u64int x = Rand::rand() * w / Rand::max();
@@ -75,16 +77,18 @@ int main(Vector<String> args) {
cells[i] = true;
cells[(2 * i) % (h - i)] = true;
cells[(w * i) % (h * w - i)] = true;
+ cells[(w * i) % (h * w - i) + w] = true;
}
} else if (kp.character == WChar("h")) {
- outvt << "** Melon's demo Game Of Life Simulator help :\n";
+ outvt << "\n\n** Melon's demo Game Of Life Simulator help :\n";
outvt << " - ctrl+c : quit\n";
outvt << " - ctrl+h : show this\n";
outvt << " - ctrl+r : add some random cells\n";
- outvt << " - ctrl+R : add more cells, but not random\n";
+ outvt << " - ctrl+R : add more cells, but not random\n\n";
outvt << "Press any key to return to simultaor...";
invt.getKeypress();
}
+ kp = invt.getKeypress(false, false);
}
Thread::get().sleep(100);
diff --git a/Source/Kernel/Config.h b/Source/Kernel/Config.h
index 656089e..149f699 100644
--- a/Source/Kernel/Config.h
+++ b/Source/Kernel/Config.h
@@ -12,9 +12,9 @@
#define KVT_BLECOLOR 4 //BLE = Boot Log Entry
#define KVT_LIGHTCOLOR 8
-#define SHELL_FGCOLOR 0
-#define SHELL_BGCOLOR 7
-#define SHELL_LIGHTCOLOR 8
-#define SHELL_ENTRYCOLOR 6
+#define SHELL_FGCOLOR 7
+#define SHELL_BGCOLOR 0
+#define SHELL_LIGHTCOLOR 6
+#define SHELL_ENTRYCOLOR 15
#endif
diff --git a/Source/Kernel/Core/kmain.wtf.cpp b/Source/Kernel/Core/kmain.wtf.cpp
index e3344f1..d812c9a 100644
--- a/Source/Kernel/Core/kmain.wtf.cpp
+++ b/Source/Kernel/Core/kmain.wtf.cpp
@@ -133,6 +133,8 @@ void kmain(multiboot_info_t* mbd, u32int magic) {
Mem::placementAddress = mods[i].mod_end + 0x1000;
}
+ //************************************** BASIC KERNEL SETUP
+
//Create text output
VGATextOutput *vgaout = new VGATextOutput();
Disp::setText(vgaout);
@@ -151,58 +153,77 @@ void kmain(multiboot_info_t* mbd, u32int magic) {
PhysMem::removeTemporaryPages(); //Remove useless page mapping
Mem::createHeap(); //Create kernel heap
+ Dev::registerDevice(vgaout);
Dev::registerDevice(new Timer()); //Initialize timer
- Task::initialize(String((char*)mbd->cmdline), kvt); //Initialize multitasking
+ String kcmdline((char*)mbd->cmdline);
+ Task::initialize(kcmdline, kvt); //Initialize multitasking
- FileSystem* fs = RamFS::mount((u8int*)mods[0].mod_start, 1024 * 1024, NULL);
- DirectoryNode* cwd;
- cwd = fs->getRootNode();
- Task::currProcess()->setCwd(cwd);
- VFS::setRootNode(cwd);
+ asm volatile("sti");
- Log::init(KL_STATUS); //Setup logging
- Log::log(KL_STATUS, "kmail : Melon booting.");
+ //*************************************** PARSE COMMAND LINE
+
+ Vector<String> opts = kcmdline.split(" ");
+ String keymap = "fr", init = "/System/Applications/PaperWork.app";
+ bool enableVESA = true;
+ for (u32int i = 0; i < opts.size(); i++) {
+ Vector<String> opt = opts[i].split(":");
+ if (opt[0] == "vesa" && opt[1] != "enabled") enableVESA = false;
+ if (opt[0] == "keymap") keymap = opt[1];
+ if (opt[0] == "init") init = opt[1];
+ }
- Dev::registerDevice(vgaout);
- Log::log(KL_STATUS, "kmain : Registered textual VGA output");
- Dev::registerDevice(new VESADisplay());
- Log::log(KL_STATUS, "kmain : Created VESA display");
+ //*************************************** DEVICE SETUP
+ if (enableVESA) Dev::registerDevice(new VESADisplay());
+ FloppyController::detect();
Dev::registerDevice(new PS2Keyboard()); //Initialize keyboard driver
- if (!Kbd::loadKeymap("fr")) Log::log(KL_ERROR, "kmain : could not load french keymap.");
Kbd::setFocus(kvt); //Set focus to virtual terminal
- Log::log(KL_STATUS, "kmain : Keyboard set up");
- asm volatile("sti");
+ //*************************************** MOUNT ROOT FILESYSTEM
- selectVideoMode(*kvt); //////////////////////// SETUP VIDEO MODE
+ FileSystem* fs = RamFS::mount((u8int*)mods[0].mod_start, 1024 * 1024, NULL);
+ DirectoryNode* cwd;
+ cwd = fs->getRootNode();
+ Task::currProcess()->setCwd(cwd);
+ VFS::setRootNode(cwd);
- //Create a VT for handling the Melon bootup logo
- SimpleVT *melonLogoVT = new SimpleVT(melonLogoLines, melonLogoCols, TXTLOGO_FGCOLOR, TXTLOGO_BGCOLOR);
- melonLogoVT->map(1);
- new Thread(logoAnimation, (void*)melonLogoVT, true);
+ if (keymap != "builtin") {
+ if (!Kbd::loadKeymap(keymap)) *kvt << "\nWARNING : Could not load keymap " << keymap << ", using built-in keymap instead.";
+ }
- FloppyController::detect();
- Log::log(KL_STATUS, "kmain : Floppy drives detected");
+ Log::init(KL_STATUS); //Setup logging
+ Log::log(KL_STATUS, "kmain : Melon booting.");
- Usr::load();
+ Usr::load(); //Setup user managment
Log::log(KL_STATUS, "kmain : User list loaded");
- Process* p = Process::run("/System/Applications/PaperWork.app", 0);
- if (p == 0) {
- PANIC("Could not launch PaperWork !");
+ if (init.empty()) {
+ *kvt << "\n\n";
+ new KernelShell(cwd, kvt);
+ while (1) asm volatile("sti; hlt");
} else {
- Log::log(KL_STATUS, "kmain : Starting PaperWork (init)");
- VirtualTerminal* vt = new ScrollableVT(Disp::textRows() - 10, Disp::textCols() - 4,
- 200, SHELL_FGCOLOR, SHELL_BGCOLOR);
- Kbd::setFocus(vt);
- ((ScrollableVT*)vt)->map(9);
- p->setInVT(vt);
- p->setOutVT(vt);
- p->start();
- while (p->getState() != P_FINISHED) Task::currThread()->sleep(100);
- PANIC("PaperWork finished.");
+ selectVideoMode(*kvt);
+ //Create a VT for handling the Melon bootup logo
+ SimpleVT *melonLogoVT = new SimpleVT(melonLogoLines, melonLogoCols, TXTLOGO_FGCOLOR, TXTLOGO_BGCOLOR);
+ melonLogoVT->map(1);
+ new Thread(logoAnimation, (void*)melonLogoVT, true);
+
+ Process* p = Process::run(init, 0);
+ if (p == 0) {
+ PANIC((char*)(u8int*)ByteArray(String("Could not launch init : ") += init));
+ } else {
+ Log::log(KL_STATUS, String("kmain : Starting init : ") += init);
+ VirtualTerminal* vt = new ScrollableVT(Disp::textRows() - 10, Disp::textCols() - 4,
+ 200, SHELL_FGCOLOR, SHELL_BGCOLOR);
+ Kbd::setFocus(vt);
+ ((ScrollableVT*)vt)->map(9);
+ p->setInVT(vt);
+ p->setOutVT(vt);
+ p->start();
+ while (p->getState() != P_FINISHED) Task::currThread()->sleep(100);
+ Sys::halt();
+ }
}
PANIC("END OF KMAIN");
diff --git a/Source/Kernel/DeviceManager/Kbd.ns.cpp b/Source/Kernel/DeviceManager/Kbd.ns.cpp
index 4fbf511..58dbe6e 100644
--- a/Source/Kernel/DeviceManager/Kbd.ns.cpp
+++ b/Source/Kernel/DeviceManager/Kbd.ns.cpp
@@ -7,6 +7,11 @@
#include <VFS/File.class.h>
#include <Core/Log.ns.h>
+//Whatever built-in keymap we want to use should go here. notice without this line, melon dies.
+#include <Ressources/Keymaps/fr.cxd>
+
+#define SETKM(a, b) memcpy((u8int*)a, (u8int*)b, 128 * sizeof(WChar));;
+
namespace Kbd {
//These are arbitrarily decided codes given to each scancode
@@ -29,28 +34,10 @@ u8int ctrlkeys[] = {
/* 0xF0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
-melon_keymap_t km;
-WChar *keymapNormal = NULL, *keymapShift = NULL, *keymapCaps = NULL, *keymapAltgr = NULL, *keymapShiftAltgr = NULL;
u8int kbdstatus = 0;
VirtualTerminal *focusedVT = NULL; //This is the VT that must receive the character
void process(keypress_t kp) { //This routine sends the information of a keypress to someone
- /* String r("Key press ");
- String n = String::number(kp.pressed);
- r += n;
- r += ", hascmd=";
- n = String::number(kp.hascmd);
- r += n;
- r += ", cmd=";
- n = String::number(kp.command);
- r += n;
- r += ", haschar=";
- n = String::number(kp.haschar);
- r += n;
- r += ", char='";
- r += kp.character;
- r += "'";
- DEBUG(r); */
if (focusedVT != NULL) {
if (((kp.haschar and kp.character != 0) or (kp.hascmd and kp.command < 100)) and kp.pressed) {
focusedVT->keyPress(kp);
@@ -63,6 +50,8 @@ void setFocus(VirtualTerminal* vt) {
}
bool loadKeymap(String lang) {
+ melon_keymap_t km;
+
String file = "/System/Keymaps/";
file += lang;
file += ".mkm";
@@ -73,11 +62,27 @@ bool loadKeymap(String lang) {
Log::log(KL_WARNING, String("Kbd.ns : keymap badly loaded : ") += file);
}
- keymapNormal = km.normal;
- if (km.shift[0x10] != 0) keymapShift = km.shift; else keymapShift = keymapNormal;
- if (km.caps[0x10] != 0) keymapCaps = km.caps; else keymapShift = keymapShift;
- if (km.altgr[0x10] != 0) keymapAltgr = km.altgr; else keymapShift = keymapNormal;
- if (km.shiftaltgr[0x10] != 0) keymapShiftAltgr = km.shiftaltgr; else keymapShift = keymapAltgr;
+ SETKM(keymap_normal, km.normal);
+ if (km.shift[0x10] != 0) {
+ SETKM(keymap_shift, km.shift);
+ } else {
+ SETKM(keymap_shift, keymap_normal);
+ }
+ if (km.caps[0x10] != 0) {
+ SETKM(keymap_caps, km.caps);
+ } else {
+ SETKM(keymap_shift, keymap_shift);
+ }
+ if (km.altgr[0x10] != 0){
+ SETKM(keymap_altgr, km.altgr);
+ } else {
+ SETKM(keymap_shift, keymap_normal);
+ }
+ if (km.shiftaltgr[0x10] != 0) {
+ SETKM(keymap_shiftaltgr, km.shiftaltgr);
+ } else {
+ SETKM(keymap_shiftaltgr, keymap_altgr);
+ }
Log::log(KL_STATUS, String("Kbd.ns : loaded keymap : ") += file);
return true;
@@ -105,18 +110,18 @@ void keyPress(u8int scancode) {
}
if (((kbdstatus & STATUS_SHIFT) != 0) xor ((kbdstatus & STATUS_CAPS) != 0)) {
if (kbdstatus & STATUS_ALTGR) {
- if (keymapShiftAltgr != NULL) kp.character = keymapShiftAltgr[scancode];
+ kp.character = keymap_shiftaltgr[scancode];
} else {
- if (keymapCaps != NULL and (kbdstatus & STATUS_CAPS))
- kp.character = keymapCaps[scancode];
- else if (keymapShift != NULL)
- kp.character = keymapShift[scancode];
+ if (kbdstatus & STATUS_CAPS)
+ kp.character = keymap_caps[scancode];
+ else
+ kp.character = keymap_shift[scancode];
}
} else {
if (kbdstatus & STATUS_ALTGR) {
- if (keymapAltgr != NULL) kp.character = keymapAltgr[scancode];
+ kp.character = keymap_altgr[scancode];
} else {
- if (keymapNormal != NULL) kp.character = keymapNormal[scancode];
+ kp.character = keymap_normal[scancode];
}
}
} else if (cmd >= KBDC_KPINSERT and cmd <= KBDC_KPDEL and (kbdstatus & STATUS_NUM)) {
@@ -175,18 +180,18 @@ void keyRelease(u8int scancode) {
}
if (((kbdstatus & STATUS_SHIFT) != 0) xor ((kbdstatus & STATUS_CAPS) != 0)) {
if (kbdstatus & STATUS_ALTGR) {
- if (keymapShiftAltgr != NULL) kp.character = keymapShiftAltgr[scancode];
+ kp.character = keymap_shiftaltgr[scancode];
} else {
- if (keymapCaps != NULL and (kbdstatus & STATUS_CAPS))
- kp.character = keymapCaps[scancode];
- else if (keymapShift != NULL)
- kp.character = keymapShift[scancode];
+ if (kbdstatus & STATUS_CAPS)
+ kp.character = keymap_caps[scancode];
+ else
+ kp.character = keymap_shift[scancode];
}
} else {
if (kbdstatus & STATUS_ALTGR) {
- if (keymapAltgr != NULL) kp.character = keymapAltgr[scancode];
+ kp.character = keymap_altgr[scancode];
} else {
- if (keymapNormal != NULL) kp.character = keymapNormal[scancode];
+ kp.character = keymap_normal[scancode];
}
}
} else if (cmd >= KBDC_KPINSERT and cmd <= KBDC_KPDEL and (kbdstatus & STATUS_NUM)) {
diff --git a/Source/Kernel/Shell/KernelShell.class.cpp b/Source/Kernel/Shell/KernelShell.class.cpp
index cd897f2..b6898ba 100644
--- a/Source/Kernel/Shell/KernelShell.class.cpp
+++ b/Source/Kernel/Shell/KernelShell.class.cpp
@@ -19,7 +19,6 @@ void KernelShell::setup(DirectoryNode* cwd, VirtualTerminal *vt) {
m_vt = vt;
Task::currProcess()->setInVT(vt);
Task::currProcess()->setOutVT(vt);
- ((ScrollableVT*)m_vt)->map(9);
Kbd::setFocus(m_vt);
m_cwd = cwd;
*m_vt << "Welcome to Melon's kernel shell !\n";
@@ -32,7 +31,9 @@ KernelShell::KernelShell(DirectoryNode* cwd, VirtualTerminal* vt) {
}
KernelShell::KernelShell(DirectoryNode* cwd) {
- setup(cwd, new ScrollableVT(15, 76, 200, SHELL_FGCOLOR, SHELL_BGCOLOR));
+ ScrollableVT* vt = new ScrollableVT(15, 76, 200, SHELL_FGCOLOR, SHELL_BGCOLOR);
+ vt->map(9);
+ setup(cwd, vt);
}
KernelShell::~KernelShell() {