Import backup from 2005-03-21
This commit is contained in:
1 parent
bb8ff09e3f
commit
14792ef954
24 files changed
+671
-197
No files matched your search
@@ -0,0 +1,126 @@
|
||||
// display.c
|
||||
// Author: Josh Holtrop
|
||||
// Date: 08/07/04
|
||||
// Modified: 03/19/05
|
||||
|
||||
#include "fs/devices.h"
|
||||
#include "char/vconsole.h"
|
||||
#include "display.h"
|
||||
#include "lang/lang.h"
|
||||
#include "kernel.h"
|
||||
#include "display/vesafb.h"
|
||||
|
||||
extern real_mode_param_t rm_params; // check if a video mode is activated
|
||||
int display_activeConsole = -1; // start with no active console
|
||||
display_t myDisplays[12]; // f1-f12 change displays
|
||||
|
||||
// initialization routine for display subsystem
|
||||
int display_init()
|
||||
{
|
||||
minor_t vc;
|
||||
int width = 80;
|
||||
int height = 25;
|
||||
int displayType = DISPLAY_CONSOLE;
|
||||
if (rm_params.vid_addr) // framebuffer mode
|
||||
{
|
||||
vesafb_init(rm_params.width, rm_params.height, rm_params.bpp);
|
||||
width = vesafb_getWidth();
|
||||
height = vesafb_getHeight();
|
||||
displayType = DISPLAY_FB;
|
||||
}
|
||||
if (( vc = vconsole_new(width, height) ))
|
||||
{
|
||||
myDisplays[11].type = displayType;
|
||||
myDisplays[11].id = vc;
|
||||
display_activeConsole = vc;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
int i;
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
if ((vc = vconsole_new(width, height)))
|
||||
{
|
||||
myDisplays[i].type = displayType;
|
||||
myDisplays[i].id = vc;
|
||||
}
|
||||
else
|
||||
return -2 - i;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// activate the given display
|
||||
int display_activate(u32_t id)
|
||||
{
|
||||
if (id > 11)
|
||||
return -1;
|
||||
switch (myDisplays[id].type)
|
||||
{
|
||||
case DISPLAY_CONSOLE:
|
||||
case DISPLAY_FB:
|
||||
display_activeConsole = myDisplays[id].id;
|
||||
return vconsole_draw(display_activeConsole);
|
||||
case DISPLAY_GRAPHICAL:
|
||||
default:
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
// routine to refresh a console window
|
||||
int display_console_draw(minor_t id, int cursorPosition, u16_t *buffer, int buff_len)
|
||||
{
|
||||
if (id == display_activeConsole)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 12; i++)
|
||||
{
|
||||
if (myDisplays[i].id == id)
|
||||
{
|
||||
if (myDisplays[i].type == DISPLAY_CONSOLE)
|
||||
{
|
||||
memcpyw((void *)CONSOLE_MEMORY, buffer, buff_len);
|
||||
writeCursorPosition(cursorPosition);
|
||||
return 0;
|
||||
}
|
||||
else if (myDisplays[i].type == DISPLAY_FB)
|
||||
return vesafb_draw(buffer, buff_len, cursorPosition);
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// write a character to the screen
|
||||
int display_console_put_char(minor_t id, u16_t c, int position)
|
||||
{
|
||||
if (id == display_activeConsole)
|
||||
{
|
||||
if (myDisplays[id].type == DISPLAY_CONSOLE)
|
||||
*(u16_t *)(CONSOLE_MEMORY + (position << 1)) = c;
|
||||
else if (myDisplays[id].type == DISPLAY_FB)
|
||||
vesafb_draw_char(position, c);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// move the cursor on the screen
|
||||
int display_console_update_cursor(minor_t id, int cursorPosition)
|
||||
{
|
||||
if (id == display_activeConsole)
|
||||
{
|
||||
if (myDisplays[id].type == DISPLAY_CONSOLE)
|
||||
writeCursorPosition(cursorPosition);
|
||||
else if (myDisplays[id].type == DISPLAY_FB)
|
||||
vesafb_update_cursor(cursorPosition);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// display.h
|
||||
// Author: Josh Holtrop
|
||||
// Date: 08/07/04
|
||||
// Modified: 03/19/05
|
||||
|
||||
#ifndef __HOS_CONSOLE__
|
||||
#define __HOS_CONSOLE__ __HOS_CONSOLE__
|
||||
|
||||
#include "hos_defines.h"
|
||||
#include "fs/devices.h"
|
||||
|
||||
#define DISPLAY_NULL 0
|
||||
#define DISPLAY_CONSOLE 1
|
||||
#define DISPLAY_FB 2
|
||||
#define DISPLAY_GRAPHICAL 3
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int type;
|
||||
minor_t id;
|
||||
} display_t;
|
||||
|
||||
int display_init();
|
||||
int display_activate(u32_t id);
|
||||
int display_console_draw(minor_t id, int cursorPosition, u16_t *buffer, int buff_len);
|
||||
int display_console_put_char(minor_t id, u16_t c, int position);
|
||||
int display_console_update_cursor(minor_t id, int cursorPosition);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
// kout.c
|
||||
// Author: Josh Holtrop
|
||||
// Date: 08/02/04
|
||||
// Modified: 03/19/05
|
||||
|
||||
#include "hos_defines.h"
|
||||
#include "kout.h"
|
||||
#include "lang/conv.h"
|
||||
#include "fs/devices.h"
|
||||
|
||||
char buffer[64]; // for hex/oct/dec/ascii conversion
|
||||
|
||||
// print a character
|
||||
void putc(int c)
|
||||
{
|
||||
#ifdef PARALLEL_DEBUG
|
||||
char_write(MAJORC_PARALLEL, 0, c);
|
||||
#endif
|
||||
char_write(MAJORC_VCONSOLE, 1, c); // write to vconsole with minor 1, first allocated
|
||||
}
|
||||
|
||||
|
||||
// print a formatted string
|
||||
void kprintf(char *fmt, ...)
|
||||
{
|
||||
u32_t *params = ((u32_t *)(&fmt)) + 1; // points to the first paramater
|
||||
int i;
|
||||
int special = 0;
|
||||
for (i = 0; ; i++)
|
||||
{
|
||||
if (special)
|
||||
{
|
||||
special = 0;
|
||||
switch (fmt[i])
|
||||
{
|
||||
case 0:
|
||||
return;
|
||||
case '%':
|
||||
putc('%');
|
||||
break;
|
||||
case 's': case 'S':
|
||||
puts((char *)*params);
|
||||
params++;
|
||||
break;
|
||||
case 'c': case 'C':
|
||||
putc(*params);
|
||||
params++;
|
||||
break;
|
||||
case 'd': case 'D': case 'i': case 'I':
|
||||
putDec(*params);
|
||||
params++;
|
||||
break;
|
||||
case 'u': case 'U':
|
||||
putDecu(*params);
|
||||
params++;
|
||||
break;
|
||||
case 'x': case 'X':
|
||||
putHex(*params);
|
||||
params++;
|
||||
break;
|
||||
case 'o': case 'O':
|
||||
putOct(*params);
|
||||
params++;
|
||||
break;
|
||||
case 'b': case 'B':
|
||||
kio_putBCD(*params);
|
||||
params++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (fmt[i])
|
||||
{
|
||||
case '%':
|
||||
special = 1;
|
||||
break;
|
||||
case 0:
|
||||
return;
|
||||
default:
|
||||
putc(fmt[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// This function prints a raw string
|
||||
void puts(char *str)
|
||||
{
|
||||
while (*str)
|
||||
{
|
||||
putc(*str++);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// This function prints a signed, decimal integer
|
||||
void putDec(int num)
|
||||
{
|
||||
itoa(num, buffer);
|
||||
puts(buffer);
|
||||
}
|
||||
|
||||
|
||||
// This function prints an unsigned, decimal integer
|
||||
void putDecu(u32_t num)
|
||||
{
|
||||
utoa(num, buffer);
|
||||
puts(buffer);
|
||||
}
|
||||
|
||||
|
||||
// This function displays a number in hexadecimal
|
||||
void putHex(u32_t num)
|
||||
{
|
||||
itox(num, buffer);
|
||||
puts(buffer);
|
||||
}
|
||||
|
||||
|
||||
// This function displays a number in octal
|
||||
void putOct(u32_t num)
|
||||
{
|
||||
itoo(num, buffer);
|
||||
puts(buffer);
|
||||
}
|
||||
|
||||
|
||||
// This function prints a two-digit binary-coded-decimal value
|
||||
void kio_putBCD(u32_t bcd)
|
||||
{
|
||||
bcdtoa(bcd, buffer);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// kout.h
|
||||
// Author: Josh Holtrop
|
||||
// Date: 08/02/04
|
||||
|
||||
#ifndef __HOS_KOUT__
|
||||
#define __HOS_KOUT__ __HOS_KOUT__
|
||||
|
||||
#include "hos_defines.h"
|
||||
|
||||
void kprintf(char *fmt, ...);
|
||||
void putHex(u32_t number);
|
||||
void kio_putBCD(u32_t bcd);
|
||||
void putc(int c);
|
||||
void puts(char *str);
|
||||
void putDec(int num);
|
||||
void putDecu(u32_t num);
|
||||
void putOct(u32_t number);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
// vesafb.c
|
||||
// Author: Josh Holtrop
|
||||
// Date: 03/19/05
|
||||
// Modified: 03/19/05
|
||||
|
||||
#include "display/display.h"
|
||||
#include "display/vesafb.h"
|
||||
#include "lang/lang.h"
|
||||
#include "hos_defines.h" // BIOS_CHAR_MAP
|
||||
|
||||
u16_t *vmem16 = (u16_t *) VESAFB_VID_ADDR;
|
||||
u32_t *vmem32 = (u32_t *) VESAFB_VID_ADDR;
|
||||
int vesafb_bpp;
|
||||
int vesafb_multiplier;
|
||||
int vesafb_width; // pixels
|
||||
int vesafb_height;
|
||||
int vesafb_xres; // characters
|
||||
int vesafb_yres;
|
||||
int vesafb_cursor; // -1 to hide, 0+ for cursor position
|
||||
|
||||
int vesafb_init(int width, int height, int bpp)
|
||||
{
|
||||
switch(vesafb_bpp = bpp)
|
||||
{
|
||||
case 15: case 16:
|
||||
vesafb_multiplier = 2;
|
||||
break;
|
||||
case 24:
|
||||
vesafb_multiplier = 3;
|
||||
break;
|
||||
case 32:
|
||||
vesafb_multiplier = 4;
|
||||
break;
|
||||
}
|
||||
vesafb_width = width;
|
||||
vesafb_height = height;
|
||||
vesafb_xres = (width >> 3) & 0xFFF8; // columns divisible by 8
|
||||
vesafb_yres = height >> 3;
|
||||
return vesafb_cursor = 0;
|
||||
}
|
||||
|
||||
void vesafb_clear()
|
||||
{
|
||||
memset(vmem32, 0, vesafb_width * vesafb_height * vesafb_multiplier);
|
||||
vesafb_update_cursor(0);
|
||||
}
|
||||
|
||||
void vesafb_update_cursor(int position)
|
||||
{
|
||||
vesafb_draw_cursor(vesafb_cursor, 0);
|
||||
vesafb_draw_cursor(vesafb_cursor = position, 1);
|
||||
}
|
||||
|
||||
void vesafb_draw_cursor(int position, int onoff)
|
||||
{
|
||||
int x = (position % vesafb_xres) << 3;
|
||||
int y = ( (position / vesafb_xres) << 3 ) + 7;
|
||||
int i;
|
||||
for (i = 0; i < 7; i++)
|
||||
vesafb_pset(x + i, y, onoff);
|
||||
}
|
||||
|
||||
void vesafb_pset(int x, int y, int onoff)
|
||||
{
|
||||
switch (vesafb_bpp)
|
||||
{
|
||||
case 15: case 16:
|
||||
*(vmem16 + vesafb_width*y + x) = (onoff ? 0xFFFF : 0);
|
||||
break;
|
||||
case 24:
|
||||
*((u32_t *)(((u32_t)vmem32) + 3*vesafb_width*y + 3*x)) = (onoff ? 0x00FFFFFF : 0);
|
||||
break;
|
||||
case 32:
|
||||
*(vmem32 + vesafb_width*y + x) = (onoff ? 0x00FFFFFF : 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int vesafb_getWidth()
|
||||
{
|
||||
return vesafb_xres;
|
||||
}
|
||||
|
||||
int vesafb_getHeight()
|
||||
{
|
||||
return vesafb_yres;
|
||||
}
|
||||
|
||||
void vesafb_draw_char(int position, u16_t chr)
|
||||
{
|
||||
int x = (position % vesafb_xres) << 3;
|
||||
int y = (position / vesafb_xres) << 3;
|
||||
int xi, yi;
|
||||
u8_t *charMap = (u8_t *) ( BIOS_CHAR_MAP + ((chr & 0xFF) << 3) );
|
||||
for (yi = 0; yi < 7; yi++)
|
||||
{
|
||||
for (xi = 0; xi < 7; xi++)
|
||||
vesafb_pset(x + xi, y + yi, (*charMap & (0x80 >> xi)));
|
||||
charMap++;
|
||||
}
|
||||
}
|
||||
|
||||
int vesafb_draw(u16_t *buffer, int buff_len, int cursor_position)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < buff_len; i++)
|
||||
vesafb_draw_char(i, *buffer++);
|
||||
vesafb_update_cursor(cursor_position);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// vesafb.h
|
||||
// Author: Josh Holtrop
|
||||
// Date: 03/19/05
|
||||
// Modified: 03/19/05
|
||||
|
||||
#ifndef __HOS_VESAFB__
|
||||
#define __HOS_VESAFB__ __HOS_VESAFB__
|
||||
|
||||
#include "hos_defines.h"
|
||||
|
||||
#define VESAFB_VID_ADDR 0xF0000000
|
||||
|
||||
int vesafb_init(int width, int height, int bpp);
|
||||
void vesafb_clear();
|
||||
void vesafb_update_cursor(int position);
|
||||
void vesafb_draw_cursor(int position, int onoff);
|
||||
void vesafb_pset(int x, int y, int onoff);
|
||||
int vesafb_getWidth();
|
||||
int vesafb_getHeight();
|
||||
void vesafb_draw_char(int position, u16_t chr);
|
||||
int vesafb_draw(u16_t *buffer, int buff_len, int cursor_position);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in new issue
Block a user