mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Removed lots of deprecated suff!
This commit is contained in:
parent
ebedeeae89
commit
c157e65352
28 changed files with 25 additions and 2000 deletions
|
@ -44,12 +44,6 @@ namespace Maxsi
|
|||
size_t WriteAt(int FileDesc, const void* Buffer, size_t BufferSize, intmax_t Position);
|
||||
}
|
||||
|
||||
// TODO: This namespace is hereby deprecated as it was stupid. Delete it soon.
|
||||
namespace StdOut
|
||||
{
|
||||
size_t Print(const char* Message);
|
||||
}
|
||||
|
||||
size_t Print(const char* msg);
|
||||
size_t PrintF(const char* format, ...);
|
||||
}
|
||||
|
|
|
@ -30,8 +30,6 @@
|
|||
|
||||
#ifdef SORTIX_KERNEL
|
||||
#include <sortix/platform.h>
|
||||
#include <sortix/globals.h> // DEBUG
|
||||
#include <sortix/iprintable.h> // DEBUG
|
||||
#include <sortix/log.h> // DEBUG
|
||||
|
||||
#include <sortix/memorymanagement.h>
|
||||
|
|
|
@ -31,7 +31,7 @@ ifdef X86FAMILY
|
|||
CPUFLAGS:=$(CPUFLAGS) -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow
|
||||
endif
|
||||
|
||||
DIRS=. x64 x86
|
||||
DIRS=. x64 x86 x86-family
|
||||
|
||||
DEFINES:=-DSORTIX_KERNEL $(CPUDEFINES)
|
||||
DEFINES:=$(DEFINES) -DPLATFORM_VIRTUAL_MEMORY
|
||||
|
@ -44,7 +44,30 @@ DEFINES:=$(DEFINES) -DINITRD
|
|||
CPPFLAGSRELEASE=-s -O3
|
||||
CPPFLAGSDEBUG=
|
||||
CPPFLAGS=-I.. -I. $(CPUDEFINES) $(CPUFLAGS) -std=gnu++0x -Wall -Wextra -nostdlib -fno-builtin -nostartfiles -nodefaultlibs -fno-exceptions -fno-rtti -fno-stack-protector $(DEFINES) $(CPPFLAGSRELEASE)
|
||||
OBJS=$(CPUOBJS) kernel.o descriptor_tables.o isr.o time.o log.o iprintable.o panic.o keyboard.o memorymanagement.o scheduler.o syscall.o application.o pong.o sound.o pci.o uart.o conway.o test.o http.o vgaterminal.o serialterminal.o descriptors.o device.o vga.o elf.o process.o initrd.o ../libmaxsi/libmaxsi-sortix.a
|
||||
OBJS=$(CPUOBJS) \
|
||||
kernel.o \
|
||||
descriptor_tables.o \
|
||||
isr.o \
|
||||
time.o \
|
||||
log.o \
|
||||
panic.o \
|
||||
keyboard.o \
|
||||
memorymanagement.o \
|
||||
scheduler.o \
|
||||
syscall.o \
|
||||
sound.o \
|
||||
pci.o \
|
||||
uart.o \
|
||||
vgaterminal.o \
|
||||
serialterminal.o \
|
||||
descriptors.o \
|
||||
device.o \
|
||||
vga.o \
|
||||
elf.o \
|
||||
process.o \
|
||||
initrd.o \
|
||||
../libmaxsi/libmaxsi-sortix.a
|
||||
|
||||
JSOBJS:=$(subst .o,-js.o,$(OBJS))
|
||||
|
||||
all: sortix.bin
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
/******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
Sortix is free software: you can redistribute it and/or modify it under the
|
||||
terms of the GNU General Public License as published by the Free Software
|
||||
Foundation, either version 3 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
application.cpp
|
||||
A test application for the scheduler and libmaxsi.
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <libmaxsi/platform.h>
|
||||
#include <libmaxsi/thread.h>
|
||||
#include <libmaxsi/io.h>
|
||||
|
||||
using namespace Maxsi;
|
||||
|
||||
void* TestThread(void* Parameter)
|
||||
{
|
||||
for ( size_t I = 0; I < 64; I++ )
|
||||
{
|
||||
StdOut::Print(".");
|
||||
Thread::USleep(20*1000); // Sleep 100 * 1000 microseconds = 100 ms.
|
||||
}
|
||||
|
||||
StdOut::Print("\n");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// The entry point in this sample program for sortix.
|
||||
void* RunApplication(void* Parameter)
|
||||
{
|
||||
StdOut::Print("Hello, says the thread!\n");
|
||||
|
||||
const char* Message = "Oooh! And message passing works!\n";
|
||||
|
||||
while ( true )
|
||||
{
|
||||
StdOut::Print("Created Thread: ");
|
||||
if ( Thread::Create(TestThread, Message) == 0 )
|
||||
{
|
||||
StdOut::Print("ERROR: Could not create child thread\n");
|
||||
}
|
||||
Thread::USleep(1300 * 1000); // Sleep 2 seconds.
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -1,143 +0,0 @@
|
|||
/******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
Sortix is free software: you can redistribute it and/or modify it under the
|
||||
terms of the GNU General Public License as published by the Free Software
|
||||
Foundation, either version 3 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
astroids.cpp
|
||||
IN SPACE, NO ONE CAN HEAR YOU find ~ | xargs shred
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "platform.h"
|
||||
#include <libmaxsi/string.h>
|
||||
#include "globals.h"
|
||||
#include "iirqhandler.h"
|
||||
#include "iprintable.h"
|
||||
#include "keyboard.h"
|
||||
#include "timer.h"
|
||||
#include "log.h"
|
||||
#include "astroids.h"
|
||||
|
||||
using namespace Maxsi;
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
DEFINE_GLOBAL_OBJECT(Astroids, Astroids);
|
||||
|
||||
const int Height = 25;
|
||||
const int Width = 80;
|
||||
|
||||
void Astroids::Init()
|
||||
{
|
||||
Time = 0;
|
||||
|
||||
Reset();
|
||||
Update();
|
||||
|
||||
GKeyboard->SetReader(this);
|
||||
GTimer->SetTimerable(this);
|
||||
}
|
||||
|
||||
void Astroids::ClearScreen()
|
||||
{
|
||||
uint16_t* Destination = (uint16_t*) 0xB8000;
|
||||
|
||||
// Copy and apply colors.
|
||||
for ( int Y = 0; Y < Height; Y++ )
|
||||
{
|
||||
uint16_t Color = COLOR8_BLACK << 8;
|
||||
|
||||
for ( int X = 0; X < Width; X++ )
|
||||
{
|
||||
Destination[X + Y*Width] = ' ' | Color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Astroids::Reset()
|
||||
{
|
||||
ClearScreen();
|
||||
PX = Width/2;
|
||||
PY = Height/2;
|
||||
PVX = 0;
|
||||
PVY = 0;
|
||||
TrailX = PX;
|
||||
TrailY = PY;
|
||||
TrailLen = 0;
|
||||
TrailMaxLen = 15;
|
||||
}
|
||||
|
||||
void Astroids::Update()
|
||||
{
|
||||
uint16_t* Destination = (uint16_t*) 0xB8000;
|
||||
|
||||
PX += PVX; PX = ((nat) PX) % ((nat) Width);
|
||||
PY += PVY; PY = ((nat) PY) % ((nat) Height);
|
||||
|
||||
uint16_t Prev = 0;
|
||||
if ( !(PVX == 0 && PVY == 0) && Destination[PX + PY*Width] > 0 ) { Reset(); }
|
||||
|
||||
if ( !(PVX == 0 && PVY == 0) )
|
||||
{
|
||||
if ( PVX < 0 ) { Prev = 0; }
|
||||
if ( PVX > 0 ) { Prev = 1; }
|
||||
if ( PVY < 0 ) { Prev = 2; }
|
||||
if ( PVY > 0 ) { Prev = 3; }
|
||||
|
||||
if ( TrailMaxLen <= TrailLen )
|
||||
{
|
||||
uint16_t AtTrail = Destination[TrailX + TrailY*Width];
|
||||
Destination[TrailX + TrailY*Width] = ' ' | (COLOR8_BLACK << 8);
|
||||
if ( (AtTrail & 0x4) == 0 ) { TrailX--; } else
|
||||
if ( (AtTrail & 0x4) == 1 ) { TrailX++; } else
|
||||
if ( (AtTrail & 0x4) == 2 ) { TrailY--; } else
|
||||
if ( (AtTrail & 0x4) == 3 ) { TrailY++; }
|
||||
}
|
||||
else { TrailLen++; }
|
||||
}
|
||||
Destination[PX + PY*Width] = (COLOR8_GREEN << 12) | Prev;
|
||||
|
||||
NextUpdate = Time + 75;
|
||||
}
|
||||
|
||||
void Astroids::OnKeystroke(uint32_t CodePoint, bool KeyUp)
|
||||
{
|
||||
const uint32_t UP = 0xFFFFFFFF - 20;
|
||||
const uint32_t LEFT = 0xFFFFFFFF - 21;
|
||||
const uint32_t RIGHT = 0xFFFFFFFF - 22;
|
||||
const uint32_t DOWN = 0xFFFFFFFF - 23;
|
||||
|
||||
if ( CodePoint == '\n' && !KeyUp )
|
||||
{
|
||||
ClearScreen();
|
||||
Reset();
|
||||
Update();
|
||||
}
|
||||
|
||||
if ( !(PVX == 0 && PVY == 1) && (CodePoint == 'w' || CodePoint == 'W') && !KeyUp ) { PVY = -1; PVX = 0; }
|
||||
if ( !(PVX == 1 && PVY == 0) && (CodePoint == 'a' || CodePoint == 'A') && !KeyUp ) { PVY = 0; PVX = -1; }
|
||||
if ( !(PVX == 0 && PVY == -1) && (CodePoint == 's' || CodePoint == 'S') && !KeyUp ) { PVY = 1; PVX = 0; }
|
||||
if ( !(PVX == -1 && PVY == 0) && (CodePoint == 'd' || CodePoint == 'D') && !KeyUp ) { PVY = 0; PVX = 1; }
|
||||
}
|
||||
|
||||
void Astroids::OnFuture(uint32_t Miliseconds)
|
||||
{
|
||||
Time += Miliseconds;
|
||||
|
||||
if ( NextUpdate <= Time ) { Update(); }
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
/******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
Sortix is free software: you can redistribute it and/or modify it under the
|
||||
terms of the GNU General Public License as published by the Free Software
|
||||
Foundation, either version 3 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
astroids.h
|
||||
IN SPACE, NO ONE CAN HEAR YOU find ~ | xargs shred
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SORTIX_ASTROIDS_H
|
||||
#define SORTIX_ASTROIDS_H
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
class Astroids : public IKeystrokable, public ITimerable
|
||||
{
|
||||
private:
|
||||
nat Time;
|
||||
nat NextUpdate;
|
||||
|
||||
private:
|
||||
int PX;
|
||||
int PY;
|
||||
int TrailX;
|
||||
int TrailY;
|
||||
int TrailLen;
|
||||
int TrailMaxLen;
|
||||
int PVX;
|
||||
int PVY;
|
||||
|
||||
public:
|
||||
void Init();
|
||||
|
||||
private:
|
||||
void ClearScreen();
|
||||
void Reset();
|
||||
void Update();
|
||||
|
||||
public:
|
||||
virtual void OnKeystroke(uint32_t CodePoint, bool KeyUp);
|
||||
virtual void OnFuture(uint32_t Miliseconds);
|
||||
|
||||
};
|
||||
|
||||
DECLARE_GLOBAL_OBJECT(Astroids, Astroids);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,194 +0,0 @@
|
|||
/******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
Sortix is free software: you can redistribute it and/or modify it under the
|
||||
terms of the GNU General Public License as published by the Free Software
|
||||
Foundation, either version 3 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
conway.cpp
|
||||
THE GAME! You lost it. OF LIFE!
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#include "globals.h"
|
||||
#include "iprintable.h"
|
||||
#include "log.h"
|
||||
#include "vga.h"
|
||||
|
||||
#ifdef PLATFORM_SERIAL
|
||||
#include "uart.h"
|
||||
#endif
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
namespace Conway
|
||||
{
|
||||
const int Height = 25;
|
||||
const int Width = 80;
|
||||
const int RowStride = Width + 2;
|
||||
const int BufferSize = (Height+2) * (Width+2);
|
||||
|
||||
#ifdef PLATFORM_SERIAL
|
||||
VGA::Frame FrameData;
|
||||
VGA::Frame* Frame = &FrameData;
|
||||
#else
|
||||
VGA::Frame* Frame = (VGA::Frame*) 0xB8000;
|
||||
#endif
|
||||
|
||||
char FrameA[BufferSize];
|
||||
char FrameB[BufferSize];
|
||||
char* CurrentFrame;
|
||||
char* LastFrame;
|
||||
bool Running;
|
||||
int PosX;
|
||||
int PosY;
|
||||
int TimeToNextFrame;
|
||||
int Time;
|
||||
|
||||
void Clear()
|
||||
{
|
||||
for ( int I = 0; I < BufferSize; I++ ) { FrameA[I] = 0; FrameB[I] = 0; }
|
||||
}
|
||||
|
||||
void Init()
|
||||
{
|
||||
CurrentFrame = FrameA;
|
||||
LastFrame = FrameB;
|
||||
|
||||
Running = false;
|
||||
|
||||
PosY = Height / 2 + 1;
|
||||
PosX = Width / 2 + 1;
|
||||
Time = 0;
|
||||
|
||||
Clear();
|
||||
}
|
||||
|
||||
void Cycle()
|
||||
{
|
||||
for ( int Y = 1; Y <= Height; Y++ )
|
||||
{
|
||||
for ( int X = 1; X <= Width; X++ )
|
||||
{
|
||||
int AliveAround = 0;
|
||||
int Current = LastFrame[Y * RowStride + X];
|
||||
|
||||
if ( LastFrame[(Y-1) * RowStride + (X-1)] > 0 ) { AliveAround++; }
|
||||
if ( LastFrame[(Y-1) * RowStride + (X-0)] > 0 ) { AliveAround++; }
|
||||
if ( LastFrame[(Y-1) * RowStride + (X+1)] > 0 ) { AliveAround++; }
|
||||
if ( LastFrame[(Y-0) * RowStride + (X-1)] > 0 ) { AliveAround++; }
|
||||
if ( LastFrame[(Y-0) * RowStride + (X+1)] > 0 ) { AliveAround++; }
|
||||
if ( LastFrame[(Y+1) * RowStride + (X-1)] > 0 ) { AliveAround++; }
|
||||
if ( LastFrame[(Y+1) * RowStride + (X-0)] > 0 ) { AliveAround++; }
|
||||
if ( LastFrame[(Y+1) * RowStride + (X+1)] > 0 ) { AliveAround++; }
|
||||
|
||||
CurrentFrame[Y * RowStride + X] = ( (Current > 0 && (AliveAround == 3 || AliveAround == 2)) || (Current == 0 && AliveAround == 3) ) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Swap buffers.
|
||||
char* TMP = LastFrame; LastFrame = CurrentFrame; CurrentFrame = TMP;
|
||||
}
|
||||
|
||||
void Render()
|
||||
{
|
||||
uint16_t* Destination = Frame->Data;
|
||||
|
||||
uint16_t Set = 'O' | (COLOR8_LIGHT_GREY << 8);
|
||||
uint16_t Unset = ' ' | (COLOR8_LIGHT_GREY << 8);
|
||||
|
||||
for ( int Y = 1; Y <= Height; Y++ )
|
||||
{
|
||||
for ( int X = 1; X <= Width; X++ )
|
||||
{
|
||||
Destination[(Y-1) * Width + (X-1)] = (LastFrame[Y * RowStride + X] > 0) ? Set : Unset;
|
||||
}
|
||||
}
|
||||
|
||||
// Render the cursor.
|
||||
if ( !Running )
|
||||
{
|
||||
Destination[(PosY-1) * Width + (PosX-1)] |= (COLOR8_RED << 12);
|
||||
}
|
||||
|
||||
#ifdef PLATFORM_SERIAL
|
||||
UART::RenderVGA(Frame);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Update(int TimePassed)
|
||||
{
|
||||
#ifdef PLATFORM_SERIAL
|
||||
while ( true )
|
||||
{
|
||||
int C = UART::TryPopChar();
|
||||
|
||||
if ( C == 'r' || C == 'R' ) { TimeToNextFrame = 0; Running = !Running; }
|
||||
|
||||
if ( !Running )
|
||||
{
|
||||
if ( C == 'w' || C == 'W' ) { if ( PosY > 1 ) { PosY--; } }
|
||||
if ( C == 's' || C == 'S' ) { if ( PosY < Height ) { PosY++; } }
|
||||
if ( C == 'a' || C == 'A' ) { if ( PosX > 1 ) { PosX--; } }
|
||||
if ( C == 'd' || C == 'D' ) { if ( PosX < Width ) { PosX++; } }
|
||||
if ( C == 'c' || C == 'C' ) { Clear(); }
|
||||
if ( C == ' ' ) { LastFrame[PosY * RowStride + PosX] = 1 - LastFrame[PosY * RowStride + PosX]; }
|
||||
}
|
||||
|
||||
if ( C == -1 ) { break; }
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( Running )
|
||||
{
|
||||
if ( TimeToNextFrame <= TimePassed )
|
||||
{
|
||||
Cycle();
|
||||
TimeToNextFrame = 50;
|
||||
}
|
||||
else
|
||||
{
|
||||
TimeToNextFrame -= TimePassed;
|
||||
}
|
||||
}
|
||||
|
||||
Render();
|
||||
}
|
||||
|
||||
void OnFuture()
|
||||
{
|
||||
const int TimePassed = 10;
|
||||
|
||||
Time += TimePassed;
|
||||
|
||||
|
||||
#ifdef PLATFORM_SERIAL
|
||||
|
||||
#ifdef JSSORIX
|
||||
const nat WaitTime = 2000;
|
||||
#else
|
||||
const nat WaitTime = 3500;
|
||||
#endif
|
||||
|
||||
// Artificially display the boot welcome screen.
|
||||
if ( Time < WaitTime ) { return; }
|
||||
#endif
|
||||
|
||||
Update(TimePassed);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
/******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
Sortix is free software: you can redistribute it and/or modify it under the
|
||||
terms of the GNU General Public License as published by the Free Software
|
||||
Foundation, either version 3 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
conway.h
|
||||
THE GAME! You lost it. OF LIFE!
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SORTIX_CONWAY_H
|
||||
#define SORTIX_CONWAY_H
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
namespace Conway
|
||||
{
|
||||
void Init();
|
||||
void Cycle();
|
||||
void Render();
|
||||
void Update(int TimePassed);
|
||||
void OnFuture();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
/******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
Sortix is free software: you can redistribute it and/or modify it under the
|
||||
terms of the GNU General Public License as published by the Free Software
|
||||
Foundation, either version 3 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
globals.h
|
||||
Macros useful to declare and define global objects in Sortix.
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SORTIX_GLOBALS_H
|
||||
#define SORTIX_GLOBALS_H
|
||||
|
||||
#define DECLARE_GLOBAL_OBJECT(Type, Name) extern Type* G##Name;
|
||||
#define DEFINE_GLOBAL_OBJECT(Type, Name) Type D##Name; Type* G##Name = &D##Name;
|
||||
|
||||
#endif
|
||||
|
183
sortix/http.cpp
183
sortix/http.cpp
|
@ -1,183 +0,0 @@
|
|||
/******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
Sortix is free software: you can redistribute it and/or modify it under the
|
||||
terms of the GNU General Public License as published by the Free Software
|
||||
Foundation, either version 3 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
http.cpp
|
||||
A very small http server running in kernel mode, heh!
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "platform.h"
|
||||
#include <libmaxsi/string.h>
|
||||
#include <libmaxsi/memory.h>
|
||||
#include "uart.h"
|
||||
|
||||
using namespace Maxsi;
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
namespace HTTP
|
||||
{
|
||||
uint32_t Left;
|
||||
|
||||
bool TryByte(char* Dest)
|
||||
{
|
||||
if ( Left == 0 )
|
||||
{
|
||||
UART::Read((uint8_t*) &Left, sizeof(Left));
|
||||
}
|
||||
|
||||
if ( Left == 0 ) { return false; }
|
||||
|
||||
UART::Read((uint8_t*) Dest, 1);
|
||||
Left--;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Close()
|
||||
{
|
||||
uint32_t ToSend = 0;
|
||||
UART::Write(&ToSend, sizeof(ToSend));
|
||||
}
|
||||
|
||||
void Send(const char* Response, uint32_t Len)
|
||||
{
|
||||
UART::Write(&Len, sizeof(Len));
|
||||
UART::Write(Response, Len);
|
||||
}
|
||||
|
||||
void Respond(const char* Body, uint32_t Len)
|
||||
{
|
||||
const char* Headers = "HTTP/1.1 200 Success\r\nConnection: close\r\nContent-Type: application/xhtml+xml\r\n\r\n";
|
||||
Send(Headers, String::Length(Headers));
|
||||
Send(Body, Len);
|
||||
Close();
|
||||
}
|
||||
|
||||
void HandleResource(const char* Operation, const char* Resource)
|
||||
{
|
||||
if ( String::Compare(Resource, "/") == 0 )
|
||||
{
|
||||
const char* Response =
|
||||
"<!DOCTYPE html>\n"
|
||||
"<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\n"
|
||||
" <head>\n"
|
||||
" <title>Hello, World!</title>\n"
|
||||
" </head>\n"
|
||||
" <body>\n"
|
||||
" <h1>\"Hello, World!\" said Sortix with a big smile!</h1>\n"
|
||||
" <p>\"Finally\", Sortix continued, \"someone completed a working HTTP server that runs under Sortix, which runs as a virtual machine, that communicates over a serial terminal driver to proxy server that communicates with the real internet!\".</p>\n"
|
||||
" <p>Sortix was happy.</p>\n"
|
||||
" <p>This website was served by a server running under my very own operating system, which is connected to the internet through a serial modem driver. Heh!</p>\n"
|
||||
" </body>\n"
|
||||
"</html>\n"
|
||||
;
|
||||
|
||||
Respond(Response, String::Length(Response)); return;
|
||||
}
|
||||
else
|
||||
{
|
||||
const char* Response = "HTTP/1.1 400 Not Found\r\nConnection: close\r\n\r\nHTTP 404 File Not Found\n";
|
||||
Send(Response, String::Length(Response)); Close(); return;
|
||||
}
|
||||
}
|
||||
|
||||
void HandleConnection()
|
||||
{
|
||||
char Buffer[1024];
|
||||
|
||||
char* Operation = NULL;
|
||||
char* Resource = NULL;
|
||||
|
||||
size_t Used = 0;
|
||||
|
||||
nat State = 0;
|
||||
|
||||
while ( true )
|
||||
{
|
||||
if ( !TryByte(Buffer + Used) ) { return; }
|
||||
Used++;
|
||||
Buffer[Used] = '\0';
|
||||
|
||||
if ( State == 0 )
|
||||
{
|
||||
if ( Used >= 4 )
|
||||
{
|
||||
if ( Buffer[0] == 'G' && Buffer[1] == 'E' && Buffer[2] == 'T' && Buffer[3] == ' ' )
|
||||
{
|
||||
State++;
|
||||
Buffer[3] = '\0';
|
||||
Operation = Buffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
const char* Response = "HTTP/1.1 501 Not Implemented\r\nConnection: close\r\n\r\nThis request is not supported by this server!\n";
|
||||
Send(Response, String::Length(Response)); Close(); return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( State == 1 )
|
||||
{
|
||||
if ( Buffer[Used-1] == ' ' )
|
||||
{
|
||||
Resource = Buffer + 4;
|
||||
Buffer[Used-1] = '\0';
|
||||
State++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( Used == 1024 )
|
||||
{
|
||||
const char* Response = "HTTP/1.1 400 Bad Request\r\n\r\n";
|
||||
Send(Response, String::Length(Response)); Close(); return;
|
||||
}
|
||||
}
|
||||
|
||||
nat LineChars = 0;
|
||||
|
||||
while ( LineChars < 4 )
|
||||
{
|
||||
char TMP;
|
||||
if ( !TryByte(&TMP) ) { return; }
|
||||
|
||||
if ( TMP == '\r' || TMP == '\n' )
|
||||
{
|
||||
LineChars++;
|
||||
}
|
||||
else
|
||||
{
|
||||
LineChars = 0;
|
||||
}
|
||||
}
|
||||
|
||||
HandleResource(Operation, Resource);
|
||||
}
|
||||
|
||||
void Init()
|
||||
{
|
||||
Left = 0;
|
||||
|
||||
while ( true )
|
||||
{
|
||||
HandleConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,257 +0,0 @@
|
|||
/******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
Sortix is free software: you can redistribute it and/or modify it under the
|
||||
terms of the GNU General Public License as published by the Free Software
|
||||
Foundation, either version 3 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
iprintable.cpp
|
||||
A common interface shared by all devices that can be printed text to.
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "platform.h"
|
||||
#include "iprintable.h"
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
int UInt8ToString(uint8_t Num, char* Dest)
|
||||
{
|
||||
uint8_t Copy = Num;
|
||||
int Result = 0;
|
||||
|
||||
while ( Copy > 9 ) { Copy /= 10; Result++; }
|
||||
|
||||
int Offset = Result;
|
||||
while ( Offset >= 0 )
|
||||
{
|
||||
Dest[Offset] = '0' + Num % 10; Num /= 10; Offset--;
|
||||
}
|
||||
|
||||
return Result + 1;
|
||||
}
|
||||
|
||||
int UInt16ToString(uint16_t Num, char* Dest)
|
||||
{
|
||||
uint16_t Copy = Num;
|
||||
int Result = 0;
|
||||
|
||||
while ( Copy > 9 ) { Copy /= 10; Result++; }
|
||||
|
||||
int Offset = Result;
|
||||
while ( Offset >= 0 )
|
||||
{
|
||||
Dest[Offset] = '0' + Num % 10; Num /= 10; Offset--;
|
||||
}
|
||||
|
||||
return Result + 1;
|
||||
}
|
||||
|
||||
int UInt32ToString(uint32_t Num, char* Dest)
|
||||
{
|
||||
uint32_t Copy = Num;
|
||||
int Result = 0;
|
||||
|
||||
while ( Copy > 9 ) { Copy /= 10; Result++; }
|
||||
|
||||
int Offset = Result;
|
||||
while ( Offset >= 0 )
|
||||
{
|
||||
Dest[Offset] = '0' + Num % 10; Num /= 10; Offset--;
|
||||
}
|
||||
|
||||
return Result + 1;
|
||||
}
|
||||
|
||||
int UInt64ToString(uint64_t Num, char* Dest)
|
||||
{
|
||||
uint64_t Copy = Num;
|
||||
int Result = 0;
|
||||
|
||||
while ( Copy > 9 ) { Copy /= 10; Result++; }
|
||||
|
||||
int Offset = Result;
|
||||
while ( Offset >= 0 )
|
||||
{
|
||||
Dest[Offset] = '0' + Num % 10; Num /= 10; Offset--;
|
||||
}
|
||||
|
||||
return Result + 1;
|
||||
}
|
||||
|
||||
// Missing functions here.
|
||||
|
||||
int UInt32ToString16(uint32_t Num, char* Dest)
|
||||
{
|
||||
uint32_t Copy = Num;
|
||||
int Result = 0;
|
||||
|
||||
while ( Copy > 15 ) { Copy /= 16; Result++; }
|
||||
|
||||
int Offset = Result;
|
||||
while ( Offset >= 0 )
|
||||
{
|
||||
if ( Num % 16 < 10 )
|
||||
{
|
||||
Dest[Offset] = '0' + Num % 16;
|
||||
}
|
||||
else
|
||||
{
|
||||
Dest[Offset] = 'A' + (Num % 16) - 10;
|
||||
}
|
||||
Num /= 16; Offset--;
|
||||
}
|
||||
|
||||
return Result + 1;
|
||||
}
|
||||
|
||||
int UInt64ToString16(uint64_t Num, char* Dest)
|
||||
{
|
||||
uint64_t Copy = Num;
|
||||
int Result = 0;
|
||||
|
||||
while ( Copy > 15 ) { Copy /= 16; Result++; }
|
||||
|
||||
int Offset = Result;
|
||||
while ( Offset >= 0 )
|
||||
{
|
||||
if ( Num % 16 < 10 )
|
||||
{
|
||||
Dest[Offset] = '0' + Num % 16;
|
||||
}
|
||||
else
|
||||
{
|
||||
Dest[Offset] = 'A' + (Num % 16) - 10;
|
||||
}
|
||||
Num /= 16; Offset--;
|
||||
}
|
||||
|
||||
return Result + 1;
|
||||
}
|
||||
|
||||
// Missing functions here.
|
||||
|
||||
#define READY_SIZE 128
|
||||
#define READY_FLUSH() Ready[AmountReady] = 0; Written += Print(Ready); AmountReady = 0;
|
||||
#define F(N) (*(Format+N))
|
||||
|
||||
#define U32 1
|
||||
#define U64 2
|
||||
#define X32 3
|
||||
#define X64 4
|
||||
#define STRING 5
|
||||
#define CHAR 6
|
||||
|
||||
|
||||
size_t IPrintable::PrintF(const char* Format, ...)
|
||||
{
|
||||
va_list list;
|
||||
va_start(list, Format);
|
||||
size_t result = PrintFV(Format, list);
|
||||
va_end(list);
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t IPrintable::PrintFV(const char* Format, va_list Parameters)
|
||||
{
|
||||
size_t Written = 0;
|
||||
char Ready[READY_SIZE + 1];
|
||||
int AmountReady = 0;
|
||||
|
||||
while ( *Format != '\0' )
|
||||
{
|
||||
if ( *Format != '%' )
|
||||
{
|
||||
Ready[AmountReady] = *Format; AmountReady++; Format++;
|
||||
}
|
||||
else
|
||||
{
|
||||
int Type = 0;
|
||||
int Len = 1;
|
||||
|
||||
if ( F(1) == 'c' ) { Type = CHAR; Len += 1; } else
|
||||
if ( F(1) == 's' ) { Type = STRING; Len += 1; } else
|
||||
if ( F(1) == 'u' ) { Type = U32; Len += 1; } else
|
||||
if ( F(1) == '3' && F(2) == '2' && F(3) == 'u' ) { Type = U32; Len += 3; } else
|
||||
if ( F(1) == '6' && F(2) == '4' && F(3) == 'u' ) { Type = U64; Len += 3; } else
|
||||
if ( F(1) == 'x' ) { Type = X32; Len += 1; } else
|
||||
if ( F(1) == '3' && F(2) == '2' && F(3) == 'x' ) { Type = X32; Len += 3; } else
|
||||
if ( F(1) == '6' && F(2) == '4' && F(3) == 'x' ) { Type = X64; Len += 3; } else
|
||||
#ifdef PLATFORM_X86
|
||||
if ( F(1) == 'z' ) { Type = U32; Len += 1; } else
|
||||
if ( F(1) == 'p' ) { Type = X32; Len += 1; } else
|
||||
#elif defined(PLATFORM_X64)
|
||||
if ( F(1) == 'z' ) { Type = U64; Len += 1; } else
|
||||
if ( F(1) == 'p' ) { Type = X64; Len += 1; } else
|
||||
#endif
|
||||
//#ifdef PLATFORM_X86_FAMILY
|
||||
if ( F(1) == 'j' && F(2) == 'u' ) { Type = U64; Len += 2; } else
|
||||
if ( F(1) == 'j' && F(2) == 'x' ) { Type = X64; Len += 2; } else { }
|
||||
//#endif
|
||||
|
||||
if ( Type == STRING )
|
||||
{
|
||||
// TODO: This isn't efficient.
|
||||
READY_FLUSH();
|
||||
const char* param = va_arg(Parameters, const char*);
|
||||
Written += Print(param);
|
||||
}
|
||||
else if ( Type == CHAR )
|
||||
{
|
||||
if ( READY_SIZE <= AmountReady ) { READY_FLUSH(); }
|
||||
uint32_t param = va_arg(Parameters, uint32_t);
|
||||
Ready[AmountReady] = param & 0xFF; AmountReady++;
|
||||
}
|
||||
else if ( Type == U32 )
|
||||
{
|
||||
if ( READY_SIZE - AmountReady < 10 ) { READY_FLUSH(); }
|
||||
uint32_t Num = va_arg(Parameters, uint32_t);
|
||||
AmountReady += UInt32ToString(Num, Ready + AmountReady);
|
||||
}
|
||||
else if ( Type == U64 )
|
||||
{
|
||||
if ( READY_SIZE - AmountReady < 20 ) { READY_FLUSH(); }
|
||||
uint64_t Num = va_arg(Parameters, uint64_t);
|
||||
AmountReady += UInt64ToString(Num, Ready + AmountReady);
|
||||
}
|
||||
else if ( Type == X32 )
|
||||
{
|
||||
if ( READY_SIZE - AmountReady < 8 ) { READY_FLUSH(); }
|
||||
uint32_t Num = va_arg(Parameters, uint32_t);
|
||||
AmountReady += UInt32ToString16(Num, Ready + AmountReady);
|
||||
}
|
||||
else if ( Type == X64 )
|
||||
{
|
||||
if ( READY_SIZE - AmountReady < 16 ) { READY_FLUSH(); }
|
||||
uint64_t Num = va_arg(Parameters, uint64_t);
|
||||
AmountReady += UInt64ToString16(Num, Ready + AmountReady);
|
||||
}
|
||||
else // Unsupported/unknown format. Just echo!
|
||||
{
|
||||
Ready[AmountReady] = *Format; AmountReady++; Written++;
|
||||
}
|
||||
|
||||
Format += Len;
|
||||
}
|
||||
|
||||
if ( READY_SIZE == AmountReady ) { READY_FLUSH(); }
|
||||
}
|
||||
|
||||
// Flush our cache.
|
||||
if ( AmountReady ) { Ready[AmountReady] = 0; Written += Print(Ready); }
|
||||
|
||||
return Written;
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
Sortix is free software: you can redistribute it and/or modify it under the
|
||||
terms of the GNU General Public License as published by the Free Software
|
||||
Foundation, either version 3 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
iprintable.h
|
||||
A common interface shared by all devices that can be printed text to.
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SORTIX_IPRINTABLE_H
|
||||
#define SORTIX_IPRINTABLE_H
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
int UInt8ToString(uint8_t Num, char* Dest);
|
||||
int UInt16ToString(uint16_t Num, char* Dest);
|
||||
int UInt32ToString(uint32_t Num, char* Dest);
|
||||
int UInt64ToString(uint64_t Num, char* Dest);
|
||||
|
||||
class IPrintable
|
||||
{
|
||||
public:
|
||||
size_t PrintFV(const char* Format, va_list Parameters);
|
||||
size_t PrintF(const char* Format, ...);
|
||||
|
||||
public:
|
||||
virtual size_t Print(const char* Message) = 0;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -5,8 +5,6 @@
|
|||
//
|
||||
|
||||
#include "platform.h"
|
||||
#include "globals.h"
|
||||
#include "iprintable.h"
|
||||
#include "iirqhandler.h"
|
||||
#include "log.h"
|
||||
#include "isr.h"
|
||||
|
|
|
@ -26,8 +26,6 @@
|
|||
#include <libmaxsi/memory.h>
|
||||
#include <libmaxsi/string.h>
|
||||
#include <libmaxsi/format.h>
|
||||
#include "globals.h"
|
||||
#include "iprintable.h"
|
||||
#include "log.h"
|
||||
#include "panic.h"
|
||||
#include "descriptor_tables.h"
|
||||
|
@ -38,8 +36,6 @@
|
|||
#include "memorymanagement.h"
|
||||
#include "scheduler.h"
|
||||
#include "syscall.h"
|
||||
#include "pong.h"
|
||||
#include "conway.h"
|
||||
#include "pci.h"
|
||||
#include "uart.h"
|
||||
#include "serialterminal.h"
|
||||
|
|
|
@ -33,8 +33,6 @@
|
|||
#include "process.h"
|
||||
#include "scheduler.h"
|
||||
|
||||
#include "pong.h"
|
||||
|
||||
using namespace Maxsi::Keyboard;
|
||||
|
||||
namespace Sortix
|
||||
|
@ -689,13 +687,6 @@ namespace Sortix
|
|||
QueueKeystroke(CodePoint);
|
||||
return;
|
||||
|
||||
#if PONG
|
||||
Pong::OnKeystroke(CodePoint, KeyUp); return;
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
return;
|
||||
#endif
|
||||
//if ( Reader != NULL ) { Reader->OnKeystroke(CodePoint, KeyUp); return; }
|
||||
|
||||
// Use this to debug the exact scancodes you receive!
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
/* Link.ld -- Linker script for the kernel - ensure everything goes in the */
|
||||
/* Correct place. */
|
||||
/* Original file taken from Bran's Kernel Development */
|
||||
/* tutorials: http://www.osdever.net/bkerndev/index.php. */
|
||||
|
||||
ENTRY(start)
|
||||
SECTIONS
|
||||
{
|
||||
|
||||
.text 0x100000 :
|
||||
{
|
||||
code = .; _code = .; __code = .;
|
||||
*(.text)
|
||||
. = ALIGN(4096);
|
||||
}
|
||||
|
||||
.data :
|
||||
{
|
||||
data = .; _data = .; __data = .;
|
||||
*(.data)
|
||||
*(.rodata)
|
||||
. = ALIGN(4096);
|
||||
}
|
||||
|
||||
.bss :
|
||||
{
|
||||
bss = .; _bss = .; __bss = .;
|
||||
*(.bss)
|
||||
. = ALIGN(4096);
|
||||
}
|
||||
|
||||
end = .; _end = .; __end = .;
|
||||
}
|
178
sortix/log.cpp
178
sortix/log.cpp
|
@ -25,188 +25,12 @@
|
|||
#include "platform.h"
|
||||
#include <libmaxsi/string.h>
|
||||
#include <libmaxsi/memory.h>
|
||||
#include "globals.h"
|
||||
#include "iprintable.h"
|
||||
#include "log.h"
|
||||
|
||||
#ifdef PLATFORM_SERIAL
|
||||
#include "uart.h"
|
||||
#endif
|
||||
|
||||
using namespace Maxsi;
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
#ifdef OLD_LOG
|
||||
DEFINE_GLOBAL_OBJECT(Log, Log);
|
||||
|
||||
void Log::Init()
|
||||
{
|
||||
#ifdef PLATFORM_SERIAL
|
||||
// Set the cursor to (0,0)
|
||||
const char InitMessage[] = { String::ASCII_ESCAPE, '[', 'H' };
|
||||
UART::Write(InitMessage, sizeof(InitMessage));
|
||||
|
||||
return;
|
||||
#endif
|
||||
|
||||
Line = 0;
|
||||
Column = 0;
|
||||
|
||||
// Empty the screen.
|
||||
size_t* Msgs = (size_t*) Messages;
|
||||
size_t Msg = ' ';
|
||||
#ifdef PLATFORM_X86
|
||||
Msg |= Msg << 8; Msg |= Msg << 16;
|
||||
#elif defined(PLATFORM_X64)
|
||||
Msg |= Msg << 8; Msg |= Msg << 16; Msg |= Msg << 32;
|
||||
#endif
|
||||
for ( nat I = 0; I < (Height*Width) / sizeof(size_t); I++ ) { Msgs[I] = Msg; }
|
||||
|
||||
// Set the color for each line.
|
||||
for ( nat Y = 0; Y < Height; Y++ ) { Colors[Y] = (COLOR8_LIGHT_GREY << 0) + (COLOR8_BLACK << 4); }
|
||||
|
||||
// Flush to our viewing device.
|
||||
UpdateScreen();
|
||||
}
|
||||
|
||||
void Log::UpdateScreen()
|
||||
{
|
||||
#ifdef PLATFORM_SERIAL
|
||||
return;
|
||||
#endif
|
||||
|
||||
uint16_t* Destination = (uint16_t*) 0xB8000;
|
||||
|
||||
// Copy and apply colors.
|
||||
for ( nat Y = 0; Y < Height; Y++ )
|
||||
{
|
||||
uint16_t Color = ((uint16_t) Colors[Y]) << 8;
|
||||
|
||||
for ( nat X = 0; X < Width; X++ )
|
||||
{
|
||||
Destination[X + Y*Width] = ( (uint16_t) Messages[X + Y*Width] ) | Color;
|
||||
}
|
||||
}
|
||||
|
||||
SetCursor(Column, Line);
|
||||
}
|
||||
|
||||
#ifndef PLATFORM_SERIAL
|
||||
size_t Log::Print(const char* Message)
|
||||
{
|
||||
size_t Written;
|
||||
while ( *Message != '\0' /*&& *Message != 0*/ )
|
||||
{
|
||||
if ( *Message == '\n' )
|
||||
{
|
||||
NewLine();
|
||||
}
|
||||
else if ( *Message == '\t' )
|
||||
{
|
||||
if ( 80 <= Column ) { NewLine(); }
|
||||
do { Messages[Column + Line * Width] = ' '; Column++; } while ( Column % 4 != 0 );
|
||||
}
|
||||
else if ( *Message == '\r' )
|
||||
{
|
||||
// No need for this driver to support line resets.
|
||||
}
|
||||
else if ( *Message == '\b' )
|
||||
{
|
||||
// No need for this driver to support backspaces.
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( 80 <= Column ) { NewLine(); }
|
||||
Messages[Column + Line * Width] = *Message; Column++;
|
||||
}
|
||||
|
||||
Message++;
|
||||
Written++;
|
||||
}
|
||||
|
||||
return Written;
|
||||
}
|
||||
#else
|
||||
size_t Log::Print(const char* Message)
|
||||
{
|
||||
size_t Written;
|
||||
while ( *Message != '\0' /*&& *Message != 0*/ )
|
||||
{
|
||||
if ( *Message == '\n' )
|
||||
{
|
||||
UART::WriteChar('\r');
|
||||
UART::WriteChar(*Message);
|
||||
}
|
||||
//else if ( *Message == '\t' )
|
||||
//{
|
||||
// if ( 80 <= Column ) { NewLine(); }
|
||||
// do { Messages[Column + Line * Width] = ' '; Column++; } while ( Column % 4 != 0 );
|
||||
//}
|
||||
else
|
||||
{
|
||||
UART::WriteChar(*Message);
|
||||
}
|
||||
|
||||
Message++;
|
||||
Written++;
|
||||
}
|
||||
|
||||
return Written;
|
||||
}
|
||||
#endif
|
||||
|
||||
void Log::NewLine()
|
||||
{
|
||||
#ifdef PLATFORM_SERIAL
|
||||
return;
|
||||
#endif
|
||||
|
||||
if ( Line < Height - 1 )
|
||||
{
|
||||
Line++;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Scroll down our buffer.
|
||||
Memory::Copy(Messages, Messages + Width, (Height-1)*Width);
|
||||
|
||||
// Scroll down our color buffer as well.
|
||||
for ( nat Y = 1; Y < Height; Y++ ) { Colors[Y-1] = Colors[Y]; }
|
||||
}
|
||||
|
||||
// Reset the new line.
|
||||
Memory::Set(Messages + Line*Width, ' ', Width);
|
||||
|
||||
// Assume the color of the new line is the same as the previous.
|
||||
Colors[Line] = Colors[Line-1];
|
||||
|
||||
Column = 0;
|
||||
|
||||
// Flush our output.
|
||||
UpdateScreen();
|
||||
}
|
||||
|
||||
void Log::SetCursor(nat X, nat Y)
|
||||
{
|
||||
#ifdef PLATFORM_SERIAL
|
||||
return;
|
||||
#endif
|
||||
|
||||
nat Value = X + Y * Width;
|
||||
|
||||
// This sends a command to indicies 14 and 15 in the
|
||||
// CRT Control Register of the VGA controller. These
|
||||
// are the high and low bytes of the index that show
|
||||
// where the hardware cursor is to be 'blinking'.
|
||||
CPU::OutPortB(0x3D4, 14);
|
||||
CPU::OutPortB(0x3D5, (Value >> 8) & 0xFF);
|
||||
CPU::OutPortB(0x3D4, 15);
|
||||
CPU::OutPortB(0x3D5, (Value >> 0) & 0xFF);
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
namespace Log
|
||||
{
|
||||
Maxsi::Format::Callback deviceCallback = NULL;
|
||||
|
@ -218,6 +42,4 @@ namespace Sortix
|
|||
devicePointer = user;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
|
30
sortix/log.h
30
sortix/log.h
|
@ -30,35 +30,6 @@
|
|||
|
||||
namespace Sortix
|
||||
{
|
||||
#ifdef OLD_LOG
|
||||
class Log : public IPrintable
|
||||
{
|
||||
protected:
|
||||
const static nat Width = 80;
|
||||
const static nat Height = 25;
|
||||
char Messages[Width * Height];
|
||||
nat Column;
|
||||
nat Line;
|
||||
uint8_t Colors[Height];
|
||||
|
||||
public:
|
||||
virtual void Init();
|
||||
|
||||
public:
|
||||
void UpdateScreen();
|
||||
|
||||
public:
|
||||
virtual size_t Print(const char* Message);
|
||||
|
||||
private:
|
||||
void NewLine();
|
||||
|
||||
public:
|
||||
void SetCursor(nat X, nat Y);
|
||||
};
|
||||
|
||||
DECLARE_GLOBAL_OBJECT(Log, Log);
|
||||
#else
|
||||
namespace Log
|
||||
{
|
||||
extern Maxsi::Format::Callback deviceCallback;
|
||||
|
@ -91,7 +62,6 @@ namespace Sortix
|
|||
return Maxsi::Format::Virtual(deviceCallback, devicePointer, format, list);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,16 +24,12 @@
|
|||
|
||||
#include "platform.h"
|
||||
#include "pci.h"
|
||||
|
||||
#include "globals.h"
|
||||
#include "iprintable.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
namespace PCI
|
||||
{
|
||||
|
||||
const uint16_t Config_Address = 0xCF8;
|
||||
const uint16_t Config_Data = 0xCFC;
|
||||
|
||||
|
|
311
sortix/pong.cpp
311
sortix/pong.cpp
|
@ -1,311 +0,0 @@
|
|||
/******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
Sortix is free software: you can redistribute it and/or modify it under the
|
||||
terms of the GNU General Public License as published by the Free Software
|
||||
Foundation, either version 3 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
|
||||
with Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
pong.cpp
|
||||
ROBOT PONG ATTACK!
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "platform.h"
|
||||
#include <libmaxsi/string.h>
|
||||
#include "globals.h"
|
||||
#include "iirqhandler.h"
|
||||
#include "iprintable.h"
|
||||
#include "keyboard.h"
|
||||
#include "time.h"
|
||||
#include "vga.h"
|
||||
#include "sound.h"
|
||||
#include "pong.h"
|
||||
|
||||
#ifdef JSSORTIX
|
||||
#include "uart.h"
|
||||
#endif
|
||||
|
||||
using namespace Maxsi;
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
namespace Pong
|
||||
{
|
||||
const int Height = 25;
|
||||
const int Width = 80;
|
||||
const int PadSize = 5;
|
||||
|
||||
nat Time;
|
||||
nat NextUpdate;
|
||||
bool InIntro;
|
||||
|
||||
int P1Y;
|
||||
int P2Y;
|
||||
bool P1VUP;
|
||||
bool P2VUP;
|
||||
bool P1VDOWN;
|
||||
bool P2VDOWN;
|
||||
nat P1Score;
|
||||
nat P2Score;
|
||||
nat HardCore;
|
||||
|
||||
int BallX;
|
||||
int BallY;
|
||||
int VelX;
|
||||
int VelY;
|
||||
int OldBallX;
|
||||
int OldBallY;
|
||||
|
||||
int SoundLeft;
|
||||
|
||||
const nat GoalFreq = 800;
|
||||
const nat CollisionFreq = 1200;
|
||||
|
||||
void Init()
|
||||
{
|
||||
ClearScreen();
|
||||
|
||||
P1Y = (Height-PadSize) / 5;
|
||||
P2Y = (Height-PadSize) / 5;
|
||||
P1VUP = false;
|
||||
P2VUP = false;
|
||||
P1VDOWN = false;
|
||||
P2VDOWN = false;
|
||||
|
||||
Time = 0;
|
||||
|
||||
SoundLeft = -1;
|
||||
|
||||
Reset();
|
||||
#ifndef JSSORTIX
|
||||
Intro();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Intro()
|
||||
{
|
||||
InIntro = true;
|
||||
|
||||
ClearScreen();
|
||||
|
||||
uint16_t* Destination = (uint16_t*) 0xB8000;
|
||||
|
||||
const char* String = "THIS IS SORTIX PONG"; size_t StringLen = String::Length(String);
|
||||
const char* Warn = "SortixV3-beta Edition"; size_t WarnLen = String::Length(Warn);
|
||||
const char* Enter = "-- press enter to continue --"; size_t EnterLen = String::Length(Enter);
|
||||
|
||||
// Copy and apply colors.
|
||||
uint16_t Color = COLOR8_GREEN << 8;
|
||||
|
||||
for ( size_t I = 0; I < StringLen; I++ ) { Destination[Width / 2 - StringLen / 2 + I + (Height/2)*Width] = (uint16_t)(String[I]) | Color; }
|
||||
for ( size_t I = 0; I < WarnLen; I++ ) { Destination[Width / 2 - WarnLen / 2 + I + (Height/2 + 1)*Width] = (uint16_t)(Warn[I]) | Color; }
|
||||
for ( size_t I = 0; I < EnterLen; I++ ) { Destination[Width / 2 - EnterLen / 2 + I + (Height/2 + 2)*Width] = (uint16_t)(Enter[I]) | Color; }
|
||||
|
||||
}
|
||||
|
||||
void ClearScreen()
|
||||
{
|
||||
uint16_t* Destination = (uint16_t*) 0xB8000;
|
||||
|
||||
// Copy and apply colors.
|
||||
for ( int Y = 0; Y < Height; Y++ )
|
||||
{
|
||||
uint16_t Color = COLOR8_BLACK << 8;
|
||||
|
||||
for ( int X = 0; X < Width; X++ )
|
||||
{
|
||||
Destination[X + Y*Width] = ' ' | Color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
P1Score = 0;
|
||||
P2Score = 0;
|
||||
InIntro = false;
|
||||
BallX = Width/2;
|
||||
BallY = Height/2;
|
||||
OldBallX = BallX;
|
||||
OldBallY = BallY;
|
||||
VelX = -1;
|
||||
VelY = -1;
|
||||
HardCore = 60;
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
void Collision()
|
||||
{
|
||||
Sound::Play(CollisionFreq);
|
||||
SoundLeft = 40;
|
||||
}
|
||||
|
||||
void Goal(nat Player)
|
||||
{
|
||||
uint16_t* Destination = (uint16_t*) 0xB8000;
|
||||
Destination[BallX + BallY*Width] = ' ' | (COLOR8_WHITE << 8);
|
||||
|
||||
BallX = Width/2;
|
||||
BallY = Height/2;
|
||||
|
||||
if ( Player == 1 )
|
||||
{
|
||||
VelX = 1;
|
||||
VelY = 1;
|
||||
P1Score++;
|
||||
}
|
||||
else if ( Player == 2 )
|
||||
{
|
||||
VelX = -1;
|
||||
VelY = -1;
|
||||
P2Score++;
|
||||
}
|
||||
|
||||
Sound::Play(GoalFreq);
|
||||
SoundLeft = 50;
|
||||
|
||||
//HardCore -= 2;
|
||||
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
void UpdateUI()
|
||||
{
|
||||
uint16_t* Destination = (uint16_t*) 0xB8000;
|
||||
|
||||
for ( int X = 0; X < Width; X++ ) { Destination[X] = ' ' | (COLOR8_LIGHT_GREY << 12) | (COLOR8_RED << 8); }
|
||||
|
||||
char Num[12];
|
||||
int Len;
|
||||
|
||||
Len = UInt32ToString(P1Score, Num);
|
||||
for ( int I = 0; I < Len; I++ ) { Destination[I] = ( Destination[I] & 0xFF00 ) | Num[I]; }
|
||||
|
||||
Len = UInt32ToString(P2Score, Num);
|
||||
for ( int I = 0; I < Len; I++ ) { Destination[Width - Len + I] = ( Destination[Width - Len + I] & 0xFF00 ) | Num[I]; }
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
#ifdef JSSORTIX
|
||||
|
||||
while ( true )
|
||||
{
|
||||
int C = UART::TryPopChar();
|
||||
|
||||
if ( C == 'w' || C == 'W' ) { P1VUP = true; P1VDOWN = false; }
|
||||
if ( C == 's' || C == 'S' ) { P1VDOWN = true; P1VUP = false; }
|
||||
if ( C == 'o' || C == 'O' ) { P2VUP = true; P1VDOWN = false; }
|
||||
if ( C == 'l' || C == 'L' ) { P2VDOWN = true; P2VUP = false; }
|
||||
|
||||
if ( C == -1 ) { break; }
|
||||
}
|
||||
#endif
|
||||
|
||||
uint16_t* Destination = (uint16_t*) 0xB8000;
|
||||
|
||||
int P1V = 0, P2V = 0;
|
||||
|
||||
if ( P1VUP && !P1VDOWN ) { P1V = -1; } else if ( !P1VUP && P1VDOWN ) { P1V = 1; }
|
||||
if ( P2VUP && !P2VDOWN ) { P2V = -1; } else if ( !P2VUP && P2VDOWN ) { P2V = 1; }
|
||||
|
||||
if ( P1V < 0 && P1Y > 1 ) { P1Y--; }
|
||||
if ( P1V > 0 && P1Y + PadSize < Height ) { P1Y++; }
|
||||
if ( P2V < 0 && P2Y > 1 ) { P2Y--; }
|
||||
if ( P2V > 0 && P2Y + PadSize < Height ) { P2Y++; }
|
||||
|
||||
for ( int Y = 1; Y < Height; Y++ )
|
||||
{
|
||||
uint16_t Color = ( Y < P1Y || Y >= P1Y + PadSize ) ? COLOR8_BLACK << 12 : COLOR8_RED << 12; Destination[Y*Width] = ' ' | Color;
|
||||
}
|
||||
|
||||
for ( int Y = 1; Y < Height; Y++ )
|
||||
{
|
||||
uint16_t Color = ( Y < P2Y || Y >= P2Y + PadSize ) ? COLOR8_BLACK << 12 : COLOR8_BLUE << 12; Destination[Width-1 + Y*Width] = ' ' | Color;
|
||||
}
|
||||
|
||||
if ( BallY + VelY <= 1 ) { VelY = 0 - VelY; Collision(); }
|
||||
if ( BallY + VelY >= Height ) { VelY = 0 - VelY; Collision(); }
|
||||
|
||||
if ( BallX + VelX < 1 ) { if ( BallY + VelY < P1Y - 1 || BallY + VelY > P1Y + PadSize + 1 ) { Goal(2); } else { VelX = 0 - VelX; Collision(); } }
|
||||
if ( BallX + VelX >= Width-1 ) { if ( BallY + VelY < P2Y - 1 || BallY + VelY > P2Y + PadSize + 1 ) { Goal(1); } else { VelX = 0 - VelX; Collision(); } }
|
||||
|
||||
Destination[OldBallX + OldBallY*Width] = ' ' | (COLOR8_WHITE << 8);
|
||||
Destination[BallX + BallY*Width] = '.' | (COLOR8_WHITE << 8);
|
||||
OldBallX = BallX; OldBallY = BallY;
|
||||
|
||||
BallX += VelX;
|
||||
BallY += VelY;
|
||||
|
||||
Destination[BallX + BallY*Width] = 'o' | (COLOR8_WHITE << 8);
|
||||
|
||||
#ifdef JSSORTIX
|
||||
UART::RenderVGA();
|
||||
|
||||
P1VUP = P1VDOWN = P2VUP = P2VDOWN = false;
|
||||
#endif
|
||||
|
||||
NextUpdate = Time + HardCore;
|
||||
}
|
||||
|
||||
void OnKeystroke(uint32_t CodePoint, bool KeyUp)
|
||||
{
|
||||
const uint32_t UP = 0xFFFFFFFF - 20;
|
||||
const uint32_t DOWN = 0xFFFFFFFF - 23;
|
||||
|
||||
if ( CodePoint == '\n' )
|
||||
{
|
||||
ClearScreen();
|
||||
Reset();
|
||||
Update();
|
||||
}
|
||||
|
||||
if ( CodePoint == 'w' || CodePoint == 'W' ) { P1VUP = !KeyUp; }
|
||||
if ( CodePoint == 's' || CodePoint == 'S' ) { P1VDOWN = !KeyUp; }
|
||||
if ( CodePoint == UP ) { P2VUP = !KeyUp; }
|
||||
if ( CodePoint == DOWN ) { P2VDOWN = !KeyUp; }
|
||||
}
|
||||
|
||||
void OnFuture()
|
||||
{
|
||||
const int TimePassed = 10;
|
||||
|
||||
Time += TimePassed;
|
||||
|
||||
#ifdef JSSORTIX
|
||||
// Artificially display the boot welcome screen.
|
||||
if ( Time < 2000 ) { return; }
|
||||
#endif
|
||||
|
||||
if ( SoundLeft > 0 )
|
||||
{
|
||||
if ( SoundLeft <= TimePassed )
|
||||
{
|
||||
Sound::Mute();
|
||||
SoundLeft = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
SoundLeft -= TimePassed;
|
||||
}
|
||||
}
|
||||
|
||||
if ( InIntro ) { return; }
|
||||
|
||||
if ( NextUpdate <= Time ) { Update(); }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
/******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
Sortix is free software: you can redistribute it and/or modify it under the
|
||||
terms of the GNU General Public License as published by the Free Software
|
||||
Foundation, either version 3 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
pong.h
|
||||
ROBOT PONG ATTACK!
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SORTIX_PONG_H
|
||||
#define SORTIX_PONG_H
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
namespace Pong
|
||||
{
|
||||
void Init();
|
||||
void Intro();
|
||||
void ClearScreen();
|
||||
void Reset();
|
||||
void Goal(nat Player);
|
||||
void Update();
|
||||
void UpdateUI();
|
||||
void OnKeystroke(uint32_t CodePoint, bool KeyUp);
|
||||
void OnFuture();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -26,12 +26,10 @@
|
|||
#include <libmaxsi/memory.h>
|
||||
#include "panic.h"
|
||||
#include "scheduler.h"
|
||||
#include "globals.h"
|
||||
#include "multiboot.h"
|
||||
#include "memorymanagement.h"
|
||||
#include "descriptor_tables.h"
|
||||
|
||||
#include "iprintable.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "sound.h" // HACK
|
||||
|
|
167
sortix/shell.cpp
167
sortix/shell.cpp
|
@ -1,167 +0,0 @@
|
|||
/******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
Sortix is free software: you can redistribute it and/or modify it under the
|
||||
terms of the GNU General Public License as published by the Free Software
|
||||
Foundation, either version 3 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
shell.cpp
|
||||
A very basic command line shell.
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "platform.h"
|
||||
#include <libmaxsi/memory.h>
|
||||
#include <libmaxsi/string.h>
|
||||
#include "globals.h"
|
||||
#include "iprintable.h"
|
||||
#include "iirqhandler.h"
|
||||
#include "log.h"
|
||||
#include "keyboard.h"
|
||||
#include "shell.h"
|
||||
|
||||
using namespace Maxsi;
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
DEFINE_GLOBAL_OBJECT(Shell, Shell);
|
||||
|
||||
const char* Prefix = "root@sortix / # ";
|
||||
|
||||
void Shell::Init()
|
||||
{
|
||||
BacklogUsed = 0;
|
||||
Column = 0;
|
||||
|
||||
// Empty the screen.
|
||||
#ifdef PLATFORM_X86
|
||||
size_t Msg = ' '; Msg |= Msg << 8; Msg |= Msg << 16;
|
||||
#elif defined(PLATFORM_X64)
|
||||
size_t Msg = ' '; Msg |= Msg << 8; Msg |= Msg << 16; Msg |= Msg << 32;
|
||||
#endif
|
||||
for ( nat I = 0; I < (BacklogHeight*Width) / sizeof(size_t); I++ ) { Backlog[I] = Msg; }
|
||||
for ( nat I = 0; I < (Height*Width) / sizeof(size_t); I++ ) { Command[I] = Msg; }
|
||||
|
||||
// Flush to our viewing device.
|
||||
UpdateScreen();
|
||||
}
|
||||
|
||||
void Shell::ClearScreen()
|
||||
{
|
||||
uint16_t* Destination = (uint16_t*) 0xB8000;
|
||||
|
||||
for ( size_t I = 0; I < (Height*Width)/sizeof(size_t); I++ ) { Destination[I] = 0; }
|
||||
}
|
||||
|
||||
void Shell::UpdateScreen()
|
||||
{
|
||||
ClearScreen();
|
||||
|
||||
uint16_t* Destination = (uint16_t*) 0xB8000;
|
||||
|
||||
uint16_t Color = ((COLOR8_LIGHT_GREY << 0) + (COLOR8_BLACK << 4)) << 8;
|
||||
|
||||
nat CommandLines = (Column + String::Length(Prefix)) / Width + 1;
|
||||
|
||||
nat BacklogLines = Height - CommandLines; if ( BacklogUsed < BacklogLines ) { BacklogLines = BacklogUsed; }
|
||||
for ( nat I = 0; I < BacklogLines; I++ )
|
||||
{
|
||||
nat Line = BacklogUsed - BacklogLines + I;
|
||||
|
||||
for ( nat X = 0; X < Width; X++ ) { Destination[X + I*Width] = ( (uint16_t) Backlog[X + Line*Width] ) | Color; }
|
||||
}
|
||||
|
||||
uint16_t* Pos = Destination + Width * BacklogLines;
|
||||
|
||||
size_t PrefixLen = String::Length(Prefix);
|
||||
for ( size_t I = 0; I < PrefixLen; I++ ) { Pos[I] = ( (uint16_t) Prefix[I] ) | Color; }
|
||||
Pos += PrefixLen;
|
||||
for ( size_t I = 0; I < Column; I++ ) { Pos[I] = ( (uint16_t) Command[I] ) | Color; }
|
||||
|
||||
SetCursor((PrefixLen + Column) % Width, BacklogLines + CommandLines - 1);
|
||||
}
|
||||
|
||||
void Shell::OnKeystroke(uint32_t CodePoint, bool KeyUp)
|
||||
{
|
||||
if ( CodePoint == '\n' )
|
||||
{
|
||||
//Execute();
|
||||
}
|
||||
else if ( CodePoint == '\t' )
|
||||
{
|
||||
// No autocompletion yet!
|
||||
}
|
||||
else if ( CodePoint == '\r' )
|
||||
{
|
||||
// No need for this driver to support line resets.
|
||||
}
|
||||
else if ( CodePoint == '\b' )
|
||||
{
|
||||
if ( 0 < Column ) { Column--; }
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( CodePoint <= 0xFF )
|
||||
{
|
||||
Command[Column] = CodePoint; Column++;
|
||||
}
|
||||
}
|
||||
|
||||
UpdateScreen();
|
||||
}
|
||||
|
||||
#if 0
|
||||
void Shell::NewLine()
|
||||
{
|
||||
if ( Line < Height - 1 )
|
||||
{
|
||||
Line++;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Scroll down our buffer.
|
||||
Memory::Copy(Messages, Messages + Width, (Height-1)*Width);
|
||||
|
||||
// Scroll down our color buffer as well.
|
||||
for ( nat Y = 1; Y < Height; Y++ ) { Colors[Y-1] = Colors[Y]; }
|
||||
}
|
||||
|
||||
// Reset the new line.
|
||||
Memory::Set(Messages + Line*Width, ' ', Width);
|
||||
|
||||
// Assume the color of the new line is the same as the previous.
|
||||
Colors[Line] = Colors[Line-1];
|
||||
|
||||
Column = 0;
|
||||
|
||||
// Flush our output.
|
||||
UpdateScreen();
|
||||
}
|
||||
#endif
|
||||
|
||||
void Shell::SetCursor(nat X, nat Y)
|
||||
{
|
||||
nat Value = X + Y * Width;
|
||||
|
||||
// This sends a command to indicies 14 and 15 in the
|
||||
// CRT Control Register of the VGA controller. These
|
||||
// are the high and low bytes of the index that show
|
||||
// where the hardware cursor is to be 'blinking'.
|
||||
X86::OutPortB(0x3D4, 14);
|
||||
X86::OutPortB(0x3D5, (Value >> 8) & 0xFF);
|
||||
X86::OutPortB(0x3D4, 15);
|
||||
X86::OutPortB(0x3D5, (Value >> 0) & 0xFF);
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
/******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
Sortix is free software: you can redistribute it and/or modify it under the
|
||||
terms of the GNU General Public License as published by the Free Software
|
||||
Foundation, either version 3 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
shell.h
|
||||
A very basic command line shell.
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SORTIX_SHELL_H
|
||||
#define SORTIX_SHELL_H
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
class Shell : public IKeystrokable
|
||||
{
|
||||
protected:
|
||||
const static nat Width = 80;
|
||||
const static nat BacklogHeight = 100;
|
||||
const static nat Height = 25;
|
||||
char Backlog[Width * BacklogHeight];
|
||||
char Command[Width * Height];
|
||||
nat BacklogUsed;
|
||||
nat Column;
|
||||
nat Scroll;
|
||||
|
||||
public:
|
||||
virtual void Init();
|
||||
|
||||
private:
|
||||
void ClearScreen();
|
||||
|
||||
public:
|
||||
void UpdateScreen();
|
||||
|
||||
public:
|
||||
virtual void OnKeystroke(uint32_t CodePoint, bool KeyUp);
|
||||
|
||||
public:
|
||||
void SetCursor(nat X, nat Y);
|
||||
};
|
||||
|
||||
DECLARE_GLOBAL_OBJECT(Shell, Shell);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -27,8 +27,6 @@
|
|||
#include "scheduler.h"
|
||||
#include "iirqhandler.h"
|
||||
#include "isr.h"
|
||||
#include "globals.h"
|
||||
#include "iprintable.h"
|
||||
#include "log.h"
|
||||
#include "panic.h"
|
||||
#include "vga.h"
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
#include "platform.h"
|
||||
#include "globals.h"
|
||||
#include "iprintable.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
void foo(int bar, unsigned int qux)
|
||||
{
|
||||
Log::PrintF("Hello, %i, and %u!", bar, qux);
|
||||
}
|
||||
}
|
|
@ -28,9 +28,6 @@
|
|||
#include "iirqhandler.h"
|
||||
#include "isr.h"
|
||||
#include "scheduler.h"
|
||||
|
||||
#include "globals.h"
|
||||
#include "iprintable.h"
|
||||
#include "log.h"
|
||||
|
||||
#if !defined(PLATFORM_X86_FAMILY)
|
||||
|
|
101
sortix/types.h
101
sortix/types.h
|
@ -1,101 +0,0 @@
|
|||
/******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
||||
|
||||
This file is part of LibMaxsi.
|
||||
|
||||
LibMaxsi is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
||||
more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
types.h
|
||||
Declares the required datatypes for the x86 architecture.
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SORTIX_TYPES_H
|
||||
#define SORTIX_TYPES_H
|
||||
|
||||
// TODO: Declare stuff from <limits.h>.
|
||||
|
||||
#undef NULL
|
||||
#if defined(__cplusplus)
|
||||
#define NULL 0
|
||||
#else
|
||||
#define NULL ((void*) 0)
|
||||
typedef int wchar_t;
|
||||
#endif
|
||||
|
||||
// Define basic signed types.
|
||||
typedef char int8_t;
|
||||
typedef short int16_t;
|
||||
typedef int int32_t;
|
||||
typedef long long int64_t;
|
||||
|
||||
// Define basic unsigned types.
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
|
||||
typedef unsigned int nat;
|
||||
|
||||
// The maximum width integers available on this platform.
|
||||
typedef int64_t intmax_t;
|
||||
typedef uint64_t uintmax_t;
|
||||
|
||||
// Define an integer able to hold the size of the largest continious memory
|
||||
// region and define pointer safe integer types.
|
||||
// TODO: 64-bit datatypes. Need to figure out which ifdef to use!
|
||||
typedef unsigned int size_t;
|
||||
typedef signed int ssize_t;
|
||||
typedef signed int intptr_t;
|
||||
typedef unsigned int uintptr_t;
|
||||
typedef signed int ptrdiff_t;
|
||||
|
||||
#define INT8_MIN (0x80)
|
||||
#define INT16_MIN (0x8000)
|
||||
#define INT32_MIN (0x80000000)
|
||||
#define INT64_MIN (0x8000000000000000ULL)
|
||||
#define INT8_MAX (0x7F)
|
||||
#define INT16_MAX (0x7FFF)
|
||||
#define INT32_MAX (0x7FFFFFFF)
|
||||
#define INT64_MAX (0x7FFFFFFFFFFFFFFFULL)
|
||||
#define UINT8_MAX (0xFF)
|
||||
#define UINT16_MAX (0xFFFF)
|
||||
#define UINT32_MAX (0xFFFFFFFF)
|
||||
#define UINT64_MAX (0xFFFFFFFFFFFFFFFFULL)
|
||||
|
||||
#define INTMAX_MIN INT64_MIN
|
||||
#define INTMAX_MAX INT64_MAX
|
||||
#define UINTMAX_MAX UINT64_MAX
|
||||
|
||||
#ifdef PLATFORM_X86
|
||||
#define SSIZE_MIN INT32_MIN
|
||||
#define SSIZE_MAX INT32_MAX
|
||||
#define SIZE_MAX UINT32_MAX
|
||||
#define INTPTR_MIN INT32_MIN
|
||||
#define INTPTR_MAX INT32_MAX
|
||||
#define UINTPTR_MAX UINT32_MAX
|
||||
#elif defined(PLATFORM_X64)
|
||||
#define SSIZE_MIN INT64_MIN
|
||||
#define SSIZE_MAX INT64_MAX
|
||||
#define SIZE_MAX UINT64_MAX
|
||||
#define INTPTR_MIN INT64_MIN
|
||||
#define INTPTR_MAX INT64_MAX
|
||||
#define UINTPTR_MAX UINT64_MAX
|
||||
#endif
|
||||
|
||||
typedef int wint_t;
|
||||
|
||||
#endif
|
||||
|
Loading…
Add table
Reference in a new issue