Start of implementation for the console. dprintf() now uses one of the console handles for simplicity.

It crashes for now though, seems we have a stack alignment issue or maybe mangled registers. Or maybe it's due to non-static initializers not being done.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39053 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
François Revol
2010-10-22 21:09:10 +00:00
parent 2be003bc1e
commit 04fc737059
2 changed files with 138 additions and 29 deletions
+128 -3
View File
@@ -15,10 +15,77 @@
#include "console.h"
#include "keyboard.h"
class ConsoleHandle : public CharHandle {
public:
ConsoleHandle();
FILE *stdin, *stdout, *stderr;
virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer,
size_t bufferSize);
virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer,
size_t bufferSize);
private:
static int16 fX;
static int16 fY;
uint16 fPen;
};
static Screen *sScreen;
static int16 sFontWidth, sFontHeight;
int16 ConsoleHandle::fX = 0;
int16 ConsoleHandle::fY = 0;
FILE *stdin, *stdout, *stderr, *dbgerr;
// #pragma mark -
ConsoleHandle::ConsoleHandle()
: CharHandle()
{
}
ssize_t
ConsoleHandle::ReadAt(void */*cookie*/, off_t /*pos*/, void *buffer,
size_t bufferSize)
{
// don't seek in character devices
// not implemented (and not yet? needed)
return B_ERROR;
}
ssize_t
ConsoleHandle::WriteAt(void */*cookie*/, off_t /*pos*/, const void *buffer,
size_t bufferSize)
{
const char *string = (const char *)buffer;
size_t i, len;
// be nice to our audience and replace single "\n" with "\r\n"
for (i = 0, len = 0; i < bufferSize; i++, len++) {
if (string[i] == '\0')
break;
if (string[i] == '\n') {
//Text(&sScreen->RastPort, &string[i - len], len);
fY = 0;
fX++;
len = 0;
continue;
}
Text(&sScreen->RastPort, &string[i], 1);
}
// not exactly, but we don't care...
return bufferSize;
}
static ConsoleHandle sOutput;
static ConsoleHandle sErrorOutput;
static ConsoleHandle sDebugOutput;
// #pragma mark -
@@ -26,7 +93,64 @@ FILE *stdin, *stdout, *stderr;
status_t
console_init(void)
{
GRAPHICS_BASE_NAME = (GfxBase *)OldOpenLibrary(GRAPHICSNAME);
if (GRAPHICS_BASE_NAME == NULL)
panic("Cannot open %s", GRAPHICSNAME);
static NewScreen newScreen = {
0, 0,
640, -1,
2,
0, 1,
0x8000,
0x1,
NULL,
"Haiku Loader",
NULL,
NULL
};
sScreen = OpenScreen(&newScreen);
if (sScreen == NULL)
panic("OpenScreen()\n");
static const uint16 palette[] = {0xbb9, 0x0, 0xfff, 0x0f0};
LoadRGB4(&sScreen->ViewPort, palette, 4);
SetDrMd(&sScreen->RastPort, 0);
// seems not necessary, there is a default font already set.
/*
TextAttr attrs = { "Topaz", 8, 0, 0};
TextFont *font = OpenFont(&attrs);
*/
TextFont *font = OpenFont(sScreen->Font);
if (font == NULL)
panic("OpenFont()\n");
sFontHeight = sScreen->Font->ta_YSize;
sFontWidth = font->tf_XSize;
ClearScreen(&sScreen->RastPort);
//CloseScreen(sScreen);
//TODO
dbgerr = stdout = stderr = (FILE *)&sOutput;
//XXX: testing
Move(&sScreen->RastPort, 30, 30);
Text(&sScreen->RastPort, "kikou", 5);
// those crash for the moment. Stack alignment issue ?
// sOutput.WriteAt(NULL, 0LL, "abcdefgh", 10);
// dprintf("kk\nbb\n");
//XXX
while (true) {}
//panic("console_init done\n");
return B_OK;
}
@@ -38,7 +162,7 @@ console_init(void)
void
console_clear_screen(void)
{
//TODO
ClearScreen(&sScreen->RastPort);
}
@@ -61,7 +185,8 @@ console_height(void)
void
console_set_cursor(int32 x, int32 y)
{
//TODO
Move(&sScreen->RastPort, sFontWidth * x, sFontHeight * y);
}
+10 -26
View File
@@ -6,6 +6,9 @@
#include "keyboard.h"
#include "rom_calls.h"
#include "Handle.h"
#include "console.h"
#include "keyboard.h"
#include <boot/platform.h>
#include <boot/stdio.h>
@@ -14,6 +17,8 @@
#include <Errors.h>
extern FILE *dbgerr;
/*! This works only after console_init() was called.
*/
void
@@ -60,38 +65,17 @@ panic(const char *format, ...)
void
dprintf(const char *format, ...)
{
static struct AlertMessage {
uint16 column1;
uint8 line1;
char message[14];
uint8 cont;
uint16 column2;
uint8 line2;
char buffer[512];
uint8 end;
} _PACKED alert = {
10, 12,
"KERN: ",
1,
10, 22,
"",
0
};
char *buffer = alert.buffer;
char buffer[512];
va_list list;
//platform_switch_to_text_mode();
memset(buffer, 0, 512);
va_start(list, format);
vsnprintf(buffer, 512, format, list);
if (dbgerr)
vfprintf(dbgerr, format, list);
//vsnprintf(buffer, sizeof(buffer), format, list);
va_end(list);
DisplayAlert(RECOVERY_ALERT, &alert, 40);
//if (platform_boot_options() & BOOT_OPTION_DEBUG_OUTPUT)
// Bconput(DEV_CONSOLE, buffer);
}