From 699a1497a4eb432f41d643a18f2ac6ba10a66518 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Sun, 8 Nov 2009 18:21:17 +0100 Subject: Worked on graphics mode selection, in prevision for having VESA grpahics --- Source/Applications/PaperWork/main.cpp | 4 +- Source/Kernel/Core/kmain.wtf.cpp | 110 ++++++++++----------- Source/Kernel/DeviceManager/Disp.ns.cpp | 28 +++++- Source/Kernel/DeviceManager/Disp.ns.h | 13 ++- Source/Kernel/Devices/Display/Display.proto.h | 15 ++- .../Kernel/Devices/Display/VGATextOutput.class.cpp | 22 ++++- .../Kernel/Devices/Display/VGATextOutput.class.h | 3 + 7 files changed, 123 insertions(+), 72 deletions(-) diff --git a/Source/Applications/PaperWork/main.cpp b/Source/Applications/PaperWork/main.cpp index 0ec6512..1a4c1c7 100644 --- a/Source/Applications/PaperWork/main.cpp +++ b/Source/Applications/PaperWork/main.cpp @@ -28,9 +28,9 @@ int main(Vector args) { outvt << "Logging in to Melon\n"; String user, pw; while (1) { - outvt << "Username : "; + outvt << "Username: "; user = invt.readLine(); - outvt << "Password : "; + outvt << "Password: "; pw = invt.readLine(false); if (!Process::get().authenticatePW(user, pw)) { outvt << "Authentication failed.\n\n"; diff --git a/Source/Kernel/Core/kmain.wtf.cpp b/Source/Kernel/Core/kmain.wtf.cpp index afb22aa..9ecc9d7 100644 --- a/Source/Kernel/Core/kmain.wtf.cpp +++ b/Source/Kernel/Core/kmain.wtf.cpp @@ -35,11 +35,6 @@ extern u32int end; //Placement address extern "C" void kmain(multiboot_info_t* mbd, u32int magic); -#define INFO(vt) vt->setColor(KVT_FGCOLOR); *vt << " - "; vt->setColor(KVT_LIGHTCOLOR); -#define PROCESSING(vt, m) vt->setColor(KVT_BLECOLOR); *vt << " > "; vt->setColor(KVT_FGCOLOR); *vt << m; \ - vt->setCursorCol(60); vt->setColor(KVT_LIGHTCOLOR); *vt << ": "; -#define OK(vt) vt->setColor(KVT_FGCOLOR); *vt << "[ "; vt->setColor(KVT_OKCOLOR); *vt << "OK"; vt->setColor(KVT_FGCOLOR); *vt << " ]\n"; - u32int logoAnimation(void* p) { SimpleVT& vt = *((SimpleVT*)p); vt.setColor(8); @@ -84,13 +79,41 @@ u32int logoAnimation(void* p) { return 0; } +void selectVideoMode(SimpleVT& v) { + Disp::getModes(); + v << "\n\nPlease select a graphic mode in the list below:\n"; + + for (u32int i = 0; i < Disp::modes.size(); i++) { + Disp::mode_t& m = Disp::modes[i]; + v << (s32int)i << ":\t" << "Text " << m.textRows << "x" << m.textCols << "\t"; + if (m.graphWidth != 0 and m.graphHeight != 0) { + v << "Graphics " << m.graphWidth << "x" << m.graphHeight << "x" << m.graphDepth << "\t"; + } else { + v << "No graphics"; + } + v.setCursorCol(40); + v << m.device->getName() << "\n"; + } + + while (1) { + v << "\nYour selection: "; + String answer = v.readLine(); + u32int n = answer.toInt(); + if (n >= 0 and n < Disp::modes.size() and Disp::setMode(Disp::modes[n])) { + return; + } else { + v << "Error while switching video mode, please select another one.\n"; + } + } +} + void kmain(multiboot_info_t* mbd, u32int magic) { DEBUG("Entering kmain."); if (magic != MULTIBOOT_BOOTLOADER_MAGIC) { Mem::placementAddress = (u32int)&end; //Setup basic stuff so that PANIC will work VGATextOutput *vgaout = new VGATextOutput(); - Disp::setDisplay(vgaout); + Disp::setText(vgaout); PANIC("Error with multiboot header."); } @@ -107,52 +130,34 @@ void kmain(multiboot_info_t* mbd, u32int magic) { //Create text output VGATextOutput *vgaout = new VGATextOutput(); - Disp::setDisplay(vgaout); - - //Create a VT for handling the Melon bootup logo - SimpleVT *melonLogoVT = new SimpleVT(melonLogoLines, melonLogoCols, TXTLOGO_FGCOLOR, TXTLOGO_BGCOLOR); - melonLogoVT->map(1); + Disp::setText(vgaout); //Create a VT for logging what kernel does - SimpleVT *kvt = new ScrollableVT(3, 69, 10, KVT_FGCOLOR, KVT_BGCOLOR); - kvt->map(15); - - INFO(kvt); *kvt << "Lower ram : " << (s32int)mbd->mem_lower << "k, upper : " << (s32int)mbd->mem_upper << "k.\n"; - INFO(kvt); *kvt << "Placement address : " << (u32int)Mem::placementAddress << "\n"; + SimpleVT *kvt = new ScrollableVT(25, 80, 10, KVT_FGCOLOR, KVT_BGCOLOR); + kvt->map(0, 0); + *kvt << "Melon is loading..."; - PROCESSING(kvt, "Loading IDT..."); - IDT::init(); OK(kvt); + IDT::init(); //Setup interrupts - PROCESSING(kvt, "Initializing paging..."); u32int totalRam = ((mbd->mem_upper + mbd->mem_lower) * 1024); - PhysMem::initPaging(totalRam); OK(kvt); - - INFO(kvt); *kvt << "Total ram : " << (s32int)(totalRam / 1024) << "k (" << (s32int)(totalRam / (1024 * 1024)) << "M).\n"; - PROCESSING(kvt, "Initializing real GDT and cleaning page directory..."); - GDT::init(); - PhysMem::removeTemporaryPages(); OK(kvt); + PhysMem::initPaging(totalRam); //Setup paging - PROCESSING(kvt, "Creating kernel heap..."); - Mem::createHeap(); OK(kvt); - INFO(kvt); *kvt << "Free frames : " << (s32int)PhysMem::free() << "/" << (s32int)PhysMem::total() << "\n"; + GDT::init(); //Initialize real GDT, not fake one from loader.wtf.asm + PhysMem::removeTemporaryPages(); //Remove useless page mapping - PROCESSING(kvt,"Initializing PIT..."); - Dev::registerDevice(new Timer()); OK(kvt); + Mem::createHeap(); //Create kernel heap - PROCESSING(kvt, "Initializing multitasking..."); - Task::initialize(String((char*)mbd->cmdline), kvt); - new Thread(logoAnimation, (void*)melonLogoVT, true); OK(kvt); + Dev::registerDevice(new Timer()); //Initialize timer + Task::initialize(String((char*)mbd->cmdline), kvt); //Initialize multitasking - PROCESSING(kvt, "Mounting first module as ramfs on root directory..."); FileSystem* fs = RamFS::mount((u8int*)mods[0].mod_start, 1024 * 1024, NULL); DirectoryNode* cwd; cwd = fs->getRootNode(); Task::currProcess()->setCwd(cwd); - VFS::setRootNode(cwd); OK(kvt); + VFS::setRootNode(cwd); - PROCESSING(kvt, "Setting up logs..."); - Log::init(KL_STATUS); OK(kvt); - INFO(kvt); *kvt << "Logs are now going to files in /System/Logs/\n"; + Log::init(KL_STATUS); //Setup logging + Log::log(KL_STATUS, "kmail : Melon booting."); Dev::registerDevice(vgaout); Log::log(KL_STATUS, "kmain : Registered textual VGA output"); @@ -162,34 +167,29 @@ void kmain(multiboot_info_t* mbd, u32int magic) { Kbd::setFocus(kvt); //Set focus to virtual terminal Log::log(KL_STATUS, "kmain : Keyboard set up"); + asm volatile("sti"); + + selectVideoMode(*kvt); + kvt->unmap(); + + //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); + FloppyController::detect(); Log::log(KL_STATUS, "kmain : Floppy drives detected"); Usr::load(); Log::log(KL_STATUS, "kmain : User list loaded"); - asm volatile("sti"); - Log::log(KL_STATUS, "kmain : Interrupts enabled."); - - /* - new KernelShell(cwd); //No need to save that in a var, it is automatically destroyed anyways - Log::log(KL_STATUS, "kmain : Kernel shell launched"); - //kvt->unmap(); - - while (KernelShell::getInstances() > 0) { - Task::currThread()->sleep(100); - } - - Log::log(KL_STATUS, "kmain : All kernel shells finished. Halting."); - Sys::halt(); - */ - Process* p = Process::run("/System/Applications/PaperWork.app", 0); if (p == 0) { PANIC("Could not launch PaperWork !"); } else { Log::log(KL_STATUS, "kmain : Starting PaperWork (init)"); - VirtualTerminal* vt = new ScrollableVT(15, 76, 200, SHELL_FGCOLOR, SHELL_BGCOLOR); + 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); diff --git a/Source/Kernel/DeviceManager/Disp.ns.cpp b/Source/Kernel/DeviceManager/Disp.ns.cpp index 4be8d03..246e959 100644 --- a/Source/Kernel/DeviceManager/Disp.ns.cpp +++ b/Source/Kernel/DeviceManager/Disp.ns.cpp @@ -1,8 +1,10 @@ #include "Disp.ns.h" +#include namespace Disp { mode_t mode; +Vector modes; u16int textCols() { return mode.textCols; @@ -26,11 +28,27 @@ void clear() { mode.device->clear(); } -void setDisplay(Display* disp) { - mode.device = disp; - disp->clear(); - mode.textCols = disp->textCols(); - mode.textRows = disp->textRows(); +void getModes() { + modes.clear(); + Vector disps = Dev::findDevices("display"); + for (u32int i = 0; i < disps.size(); i++) { + ((Display*)(disps[i]))->getModes(modes); + } +} + +bool setMode(mode_t& newmode) { + if (newmode.device->setMode(newmode)) { + mode = newmode; + return true; + } + return false; +} + +void setText(VGATextOutput* o) { + mode.device = o; + o->clear(); + mode.textCols = 80; + mode.textRows = 25; } } diff --git a/Source/Kernel/DeviceManager/Disp.ns.h b/Source/Kernel/DeviceManager/Disp.ns.h index 0eea51d..0d56cf0 100644 --- a/Source/Kernel/DeviceManager/Disp.ns.h +++ b/Source/Kernel/DeviceManager/Disp.ns.h @@ -1,22 +1,31 @@ #ifndef DEF_DISP_NS_H #define DEF_DISP_NS_H -#include +#include #include +#include namespace Disp { struct mode_t { int textCols, textRows; + int graphWidth, graphHeight, graphDepth; + int identifier; //Used by video devices Display *device; }; + extern Vector modes; + extern mode_t mode; + u16int textCols(); u16int textRows(); void putChar(u16int line, u16int col, WChar c, u8int color); void moveCursor(u16int line, u16int col); void clear(); - void setDisplay(Display* disp); + void getModes(); + bool setMode(mode_t& mode); + + void setText(VGATextOutput* o); //To use only once : when display is initializing } #endif diff --git a/Source/Kernel/Devices/Display/Display.proto.h b/Source/Kernel/Devices/Display/Display.proto.h index 2cec616..e1775bd 100644 --- a/Source/Kernel/Devices/Display/Display.proto.h +++ b/Source/Kernel/Devices/Display/Display.proto.h @@ -5,14 +5,21 @@ #include #include +namespace Disp { struct mode_t; } + class Display : public Device { public: virtual ~Display() {} - virtual u16int textCols() = 0; - virtual u16int textRows() = 0; - virtual void putChar(u16int line, u16int col, WChar c, u8int color) = 0; //Color : - virtual void moveCursor(u16int line, u16int col) = 0; + + virtual void getModes(Vector &to) = 0; + virtual bool setMode(Disp::mode_t& mode) = 0; virtual void clear() = 0; + + //Text functions + virtual void putChar(u16int line, u16int col, WChar c, u8int color) = 0; //Color : + virtual void moveCursor(u16int line, u16int col) = 0; + + //Graphic functions }; #endif diff --git a/Source/Kernel/Devices/Display/VGATextOutput.class.cpp b/Source/Kernel/Devices/Display/VGATextOutput.class.cpp index aca5ce6..8840080 100644 --- a/Source/Kernel/Devices/Display/VGATextOutput.class.cpp +++ b/Source/Kernel/Devices/Display/VGATextOutput.class.cpp @@ -1,9 +1,11 @@ #include "VGATextOutput.class.h" +#include //Virtual address in higher half #define RAM_ADDR 0xC00B8000 using namespace Sys; //For outb +using namespace Disp; String VGATextOutput::getClass() { return "display.text"; @@ -13,12 +15,24 @@ String VGATextOutput::getName() { return "Standard mode0 VGA text display"; } -u16int VGATextOutput::textCols() { - return 80; +void VGATextOutput::getModes(Vector &to) { + mode_t m; + m.textCols = 80; + m.textRows = 25; + m.identifier = 0; + m.graphWidth = 0; + m.graphHeight = 0; + m.device = this; + to.push(m); } -u16int VGATextOutput::textRows() { - return 25; +bool VGATextOutput::setMode(mode_t& mode) { + if (mode.device == this && mode.identifier == 0) { + //TODO : switch for real to mode 0. + clear(); + return true; + } + return false; } void VGATextOutput::putChar(u16int line, u16int col, WChar c, u8int color) { diff --git a/Source/Kernel/Devices/Display/VGATextOutput.class.h b/Source/Kernel/Devices/Display/VGATextOutput.class.h index 864ae35..1ced227 100644 --- a/Source/Kernel/Devices/Display/VGATextOutput.class.h +++ b/Source/Kernel/Devices/Display/VGATextOutput.class.h @@ -8,6 +8,9 @@ class VGATextOutput : public Display { String getClass(); String getName(); + void getModes(Vector &to); + bool setMode(Disp::mode_t& mode); + u16int textCols(); u16int textRows(); void putChar(u16int line, u16int col, WChar c, u8int color); -- cgit v1.2.3