Fix setting console position.

Generate a list of video modes, though there seem to be some dups and missing ones... The Nominal resolution doesn't mean it can't be better.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39135 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
François Revol 2010-10-24 22:28:13 +00:00
parent 2e74287ab2
commit b14f16077c
4 changed files with 237 additions and 45 deletions

View File

@ -23,6 +23,9 @@ class ConsoleHandle : public CharHandle {
size_t bufferSize);
virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer,
size_t bufferSize);
void MoveTo(int16 x, int16 y);
private:
static int16 fX;
static int16 fY;
@ -80,7 +83,7 @@ static const uint16 kPalette[] = {
0xfff
};
static Screen *sScreen;
struct Screen *gScreen;
static int16 sFontWidth, sFontHeight;
static int sScreenTopOffset = 16;
int16 ConsoleHandle::fX = 0;
@ -120,7 +123,7 @@ ConsoleHandle::WriteAt(void */*cookie*/, off_t /*pos*/, const void *buffer,
if (string[i] == '\0')
break;
if (string[i] == '\n') {
//Text(&sScreen->RastPort, &string[i - len], len);
//Text(&gScreen->RastPort, &string[i - len], len);
fX = 0;
fY++;
if (fY >= console_height())
@ -129,7 +132,7 @@ ConsoleHandle::WriteAt(void */*cookie*/, off_t /*pos*/, const void *buffer,
console_set_cursor(fX, fY);
continue;
}
Text(&sScreen->RastPort, &string[i], 1);
Text(&gScreen->RastPort, &string[i], 1);
}
// not exactly, but we don't care...
@ -137,6 +140,18 @@ ConsoleHandle::WriteAt(void */*cookie*/, off_t /*pos*/, const void *buffer,
}
void
ConsoleHandle::MoveTo(int16 x, int16 y)
{
fX = x;
fY = y;
Move(&gScreen->RastPort, sFontWidth * x,
sFontHeight * y + sScreenTopOffset);
// why do I have to add this to keep the title ?
}
// #pragma mark -
@ -169,8 +184,6 @@ int
ConsoleDevice::WaitForKey()
{
char ascii;
ssize_t actual;
status_t err;
if (Read(&ascii, 1) < 1) {
panic("WFK\n");
@ -347,51 +360,51 @@ console_init(void)
NULL
};
sScreen = OpenScreen(&newScreen);
if (sScreen == NULL)
gScreen = OpenScreen(&newScreen);
if (gScreen == NULL)
panic("OpenScreen()\n");
LoadRGB4(&sScreen->ViewPort, kPalette, 16);
LoadRGB4(&gScreen->ViewPort, kPalette, 16);
SetDrMd(&sScreen->RastPort, JAM2);
SetDrMd(&gScreen->RastPort, JAM2);
// 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);
TextFont *font = OpenFont(gScreen->Font);
if (font == NULL)
panic("OpenFont()\n");
sFontHeight = sScreen->Font->ta_YSize;
sFontHeight = gScreen->Font->ta_YSize;
sFontWidth = font->tf_XSize;
sScreenTopOffset = sScreen->BarHeight * 2; // ???
sScreenTopOffset = gScreen->BarHeight * 2; // ???
//ClearScreen(&sScreen->RastPort);
//ClearScreen(&gScreen->RastPort);
dbgerr = stdout = stderr = (FILE *)&sOutput;
console_set_cursor(0, 0);
/*
dprintf("LeftEdge %d\n", sScreen->LeftEdge);
dprintf("TopEdge %d\n", sScreen->TopEdge);
dprintf("Width %d\n", sScreen->Width);
dprintf("Height %d\n", sScreen->Height);
dprintf("MouseX %d\n", sScreen->MouseX);
dprintf("MouseY %d\n", sScreen->MouseY);
dprintf("Flags 0x%08x\n", sScreen->Flags);
dprintf("BarHeight %d\n", sScreen->BarHeight);
dprintf("BarVBorder %d\n", sScreen->BarVBorder);
dprintf("BarHBorder %d\n", sScreen->BarHBorder);
dprintf("MenuVBorder %d\n", sScreen->MenuVBorder);
dprintf("MenuHBorder %d\n", sScreen->MenuHBorder);
dprintf("WBorTop %d\n", sScreen->WBorTop);
dprintf("WBorLeft %d\n", sScreen->WBorLeft);
dprintf("WBorRight %d\n", sScreen->WBorRight);
dprintf("WBorBottom %d\n", sScreen->WBorBottom);
dprintf("LeftEdge %d\n", gScreen->LeftEdge);
dprintf("TopEdge %d\n", gScreen->TopEdge);
dprintf("Width %d\n", gScreen->Width);
dprintf("Height %d\n", gScreen->Height);
dprintf("MouseX %d\n", gScreen->MouseX);
dprintf("MouseY %d\n", gScreen->MouseY);
dprintf("Flags 0x%08x\n", gScreen->Flags);
dprintf("BarHeight %d\n", gScreen->BarHeight);
dprintf("BarVBorder %d\n", gScreen->BarVBorder);
dprintf("BarHBorder %d\n", gScreen->BarHBorder);
dprintf("MenuVBorder %d\n", gScreen->MenuVBorder);
dprintf("MenuHBorder %d\n", gScreen->MenuHBorder);
dprintf("WBorTop %d\n", gScreen->WBorTop);
dprintf("WBorLeft %d\n", gScreen->WBorLeft);
dprintf("WBorRight %d\n", gScreen->WBorRight);
dprintf("WBorBottom %d\n", gScreen->WBorBottom);
*/
KEYMAP_BASE_NAME = (Library *)OldOpenLibrary(KEYMAPNAME);
@ -404,8 +417,13 @@ console_init(void)
panic("sInput.Open() 0x%08lx\n", err);
stdin = (FILE *)&sInput;
dprintf("BytesPerRow %d\n", gScreen->RastPort.BitMap->BytesPerRow);
dprintf("Rows %d\n", gScreen->RastPort.BitMap->Rows);
dprintf("Flags %02x\n", gScreen->RastPort.BitMap->Flags);
dprintf("Depth %d\n", gScreen->RastPort.BitMap->Depth);
for (int i = 0; i < 8; i++)
dprintf("Planes[%d] %p\n", i, gScreen->RastPort.BitMap->Planes[i]);
return B_OK;
}
@ -416,15 +434,15 @@ console_init(void)
void
console_clear_screen(void)
{
Move(&sScreen->RastPort, 0, sScreenTopOffset);
ClearScreen(&sScreen->RastPort);
Move(&gScreen->RastPort, 0, sScreenTopOffset);
ClearScreen(&gScreen->RastPort);
}
int32
console_width(void)
{
int columnCount = sScreen->Width / sFontWidth;
int columnCount = gScreen->Width / sFontWidth;
return columnCount;
}
@ -432,7 +450,7 @@ console_width(void)
int32
console_height(void)
{
int lineCount = (sScreen->Height - sScreenTopOffset) / sFontHeight;
int lineCount = (gScreen->Height - sScreenTopOffset) / sFontHeight;
return lineCount;
}
@ -440,18 +458,15 @@ console_height(void)
void
console_set_cursor(int32 x, int32 y)
{
Move(&sScreen->RastPort, sFontWidth * x,
sFontHeight * y + sScreenTopOffset);
// why do I have to add this to keep the title ?
sOutput.MoveTo(x, y);
}
void
console_set_color(int32 foreground, int32 background)
{
SetAPen(&sScreen->RastPort, foreground);
SetBPen(&sScreen->RastPort, background);
SetAPen(&gScreen->RastPort, foreground);
SetBPen(&gScreen->RastPort, background);
}

View File

@ -15,6 +15,8 @@
extern "C" {
#endif
extern struct Screen *gScreen;
extern status_t console_init(void);
#ifdef __cplusplus

View File

@ -984,7 +984,7 @@ struct Library {
uint8 dummy1[10];
uint16 Version, Revision;
uint8 dummy2[34-24];
};
} _PACKED;
// <exec/execbase.h>
@ -995,7 +995,7 @@ struct MemHead {
uint8 dummy2[14-10];
uint16 Attribs;
uint32 First, Lower, Upper, Free;
};
} _PACKED;
struct ExecBase {
struct Library LibNode;
@ -1165,6 +1165,28 @@ extern "C" status_t exec_error(int32 err);
// #pragma mark -
// <graphics/gfx.h>
#ifndef __ASSEMBLER__
struct BitMap {
uint16 BytesPerRow;
uint16 Rows;
uint8 Flags;
uint8 Depth;
uint16 pad;
void *Planes[8];
};
struct Rectangle {
int16 MinX, MinY, MaxX, MaxY;
};
struct Point {
int16 x, y;
};
#endif /* __ASSEMBLER__ */
// <graphics/graphics.h>
@ -1196,7 +1218,7 @@ struct ViewPort {
struct CopList *SprIns;
struct CopList *ClrIns;
struct UCopList *UCopIns;
int16 DWidth, DHright;
int16 DWidth, DHeight;
int16 DxOffset, DyOffset;
uint16 Modes;
uint8 SpritePriorities;
@ -1206,6 +1228,7 @@ struct ViewPort {
struct RastPort {
struct Layer *Layer;
struct BitMap *BitMap;
//...
} _PACKED;
@ -1264,13 +1287,87 @@ extern struct GfxBase *GRAPHICS_BASE_NAME;
LP2NR(0x162, SetDrMd, struct RastPort *, par1, a1, unsigned long, last, d0, \
, GRAPHICS_BASE_NAME)
#define FindDisplayInfo(last) \
LP1(0x2d6, DisplayInfoHandle, FindDisplayInfo, unsigned long, last, d0, \
, GRAPHICS_BASE_NAME)
#endif
#define NextDisplayInfo(last) \
LP1(0x2dc, uint32, NextDisplayInfo, unsigned long, last, d0, \
, GRAPHICS_BASE_NAME)
#define GetDisplayInfoData(par1, par2, par3, par4, last) \
LP5(0x2f4, uint32, GetDisplayInfoData, DisplayInfoHandle, par1, a0, uint8 *, par2, a1, unsigned long, par3, d0, unsigned long, par4, d1, unsigned long, last, d2, \
, GRAPHICS_BASE_NAME)
#endif /* __ASSEMBLER__ */
/* drawing modes */
#define JAM1 0 // only draw foreground
#define JAM2 1 // draw both fg & bg
// <graphics/modeid.h>
#define INVALID_ID (~0)
// <graphics/displayinfo.h>
#ifndef __ASSEMBLER__
typedef void *DisplayInfoHandle;
struct QueryHeader {
uint32 StructID;
uint32 DisplayID;
uint32 SkipID;
uint32 Length;
};
struct DisplayInfo {
struct QueryHeader Header;
uint16 NotAvailable;
uint32 PropertyFlags;
struct Point Resolution;
uint16 PixelSpeed;
uint16 NumStdSprites;
uint16 PaletteRange;
struct Point SpriteResolution;
uint8 pad[4];
uint8 RedBits;
uint8 GreenBits;
uint8 BlueBits;
uint8 pad2[5];
uint32 reserved[2];
};
struct DimensionInfo {
struct QueryHeader Header;
uint16 MaxDepth;
uint16 MinRasterWidth;
uint16 MinRasterHeight;
uint16 MaxRasterWidth;
uint16 MaxRasterHeight;
struct Rectangle Nominal;
//... overscan stuff
struct Rectangle overscanStuff[4];
uint8 pad[14];
uint32 reserved[2];
};
#define DISPLAYNAMELEN 32
struct NameInfo {
struct QueryHeader Header;
uchar Name[DISPLAYNAMELEN];
uint32 reserved[2];
};
#endif /* __ASSEMBLER__ */
#define DTAG_DISP 0x80000000
#define DTAG_DIMS 0x80001000
#define DTAG_MNTR 0x80002000
#define DTAG_NAME 0x80003000
// #pragma mark -
@ -1361,6 +1458,8 @@ extern struct Library *KEYMAP_BASE_NAME;
#define LOWLEVEL_BASE_NAME LowLevelBase
#endif
#ifndef __ASSEMBLER__
#define GetKey() \
LP0(0x30, uint32, GetKey, \
, LOWLEVEL_BASE_NAME)
@ -1369,6 +1468,7 @@ extern struct Library *KEYMAP_BASE_NAME;
LP2NR(0x36, QueryKeys, struct KeyQuery *, par1, a0, unsigned long, last, d1, \
, LOWLEVEL_BASE_NAME)
#endif /* __ASSEMBLER__ */
// <devices/keyboard.h>

View File

@ -32,6 +32,8 @@
// #pragma mark -
@ -46,7 +48,80 @@ video_mode_hook(Menu *menu, MenuItem *item)
Menu *
video_mode_menu()
{
return NULL;
Menu *menu = new(nothrow) Menu(CHOICE_MENU, "Select Video Mode");
MenuItem *item;
menu->AddItem(item = new(nothrow) MenuItem("Default"));
item->SetMarked(true);
item->Select(true);
item->SetHelpText("The Default video mode is the one currently configured "
"in the system. If there is no mode configured yet, a viable mode will "
"be chosen automatically.");
/*
video_mode *mode = NULL;
while ((mode = (video_mode *)list_get_next_item(&sModeList, mode)) != NULL) {
char label[64];
sprintf(label, "%ux%u %u bit", mode->width, mode->height,
mode->bits_per_pixel);
menu->AddItem(item = new(nothrow) MenuItem(label));
item->SetData(mode);
}
*/
#if 1
uint32 modeID = INVALID_ID;
while ((modeID = NextDisplayInfo(modeID)) != INVALID_ID) {
//DisplayInfoHandle handle = FindDisplayInfo(modeID);
//if (handle == NULL)
// continue;
struct DisplayInfo info;
struct DimensionInfo dimension;
struct NameInfo name;
if (GetDisplayInfoData(NULL, (uint8 *)&info, sizeof(info),
DTAG_DISP, modeID) < 48/*sizeof(struct DisplayInfo)*/)
continue;
if (GetDisplayInfoData(NULL, (uint8 *)&dimension, sizeof(dimension),
DTAG_DIMS, modeID) < 66)
continue;
/*if (GetDisplayInfoData(NULL, (uint8 *)&name, sizeof(name),
DTAG_NAME, modeID) < sizeof(name) - 8)
continue;*/
if (info.NotAvailable)
continue;
if (dimension.MaxDepth < 4)
continue;
//dprintf("name: %s\n", name.Name);
/*
dprintf("mode 0x%08lx: %dx%d flags: 0x%08lx bpp: %d\n",
modeID, info.Resolution.x, info.Resolution.y, info.PropertyFlags,
info.RedBits + info.GreenBits + info.BlueBits);
dprintf("mode: %dx%d -> %dx%d\n",
dimension.MinRasterWidth, dimension.MinRasterHeight,
dimension.MaxRasterWidth, dimension.MaxRasterHeight);
dprintf("mode: %dx%d %dbpp flags: 0x%08lx\n",
dimension.Nominal.MaxX - dimension.Nominal.MinX + 1,
dimension.Nominal.MaxY - dimension.Nominal.MinY + 1,
dimension.MaxDepth, info.PropertyFlags);
*/
char label[64];
sprintf(label, "%ux%u %u bit",
dimension.Nominal.MaxX - dimension.Nominal.MinX + 1,
dimension.Nominal.MaxY - dimension.Nominal.MinY + 1,
dimension.MaxDepth);
menu->AddItem(item = new(nothrow) MenuItem(label));
item->SetData((void *)modeID);
}
#endif
dprintf("done\n");
menu->AddSeparatorItem();
menu->AddItem(item = new(nothrow) MenuItem("Return to main menu"));
item->SetType(MENU_ITEM_NO_CHOICE);
return menu;
}