Import backup from 2004-03-09

This commit is contained in:
Josh Holtrop 2004-03-09 22:00:00 -05:00
parent 8d0e6de040
commit 7f886e44e1
12 changed files with 211 additions and 119 deletions

View File

@ -68,4 +68,4 @@ C_Kernel:
# Clean up the source directory of any binaries #
#################################################
clean:
- rm *.o ./lst/*.lst *.bin
- rm *.o ./lst/*.lst ./lst/*.doc *.bin

View File

@ -117,7 +117,7 @@ strcpyloop:
ret
;copies memory of n bytes from src to destination
;extern void memcpy(dword dest, dword src, dword n);
;void memcpy(void *dest, void *src, dword n);
[global _memcpy]
_memcpy:
push ebp
@ -137,6 +137,101 @@ _memcpy:
pop ebp
ret
;copies memory of n dwords (n*4 bytes) from src to destination
;void memcpyd(void *dest, void *src, dword n);
[global _memcpyd]
_memcpyd:
push ebp
mov ebp, esp
push esi
push edi
push ecx
mov edi, [ebp+8]
mov esi, [ebp+12]
mov ecx, [ebp+16]
rep movsd
pop ecx
pop edi
pop esi
pop ebp
ret
;sets num bytes at buffer to the value of c
;void *memset(void *buffer, int c, int num);
[global _memset]
_memset:
push ebp
mov ebp, esp
push esi
push edi
push ecx
mov edi, [ebp+8]
push edi ;save for return address
mov eax, [ebp+12]
mov ecx, [ebp+16]
rep stosb
pop eax
pop ecx
pop edi
pop esi
pop ebp
ret
;sets num words at buffer to the value of c
;void *memsetw(void *buffer, int c, int num);
[global _memsetw]
_memsetw:
push ebp
mov ebp, esp
push esi
push edi
push ecx
mov edi, [ebp+8]
push edi ;save for return address
mov eax, [ebp+12]
mov ecx, [ebp+16]
rep stosw
pop eax
pop ecx
pop edi
pop esi
pop ebp
ret
;sets num dwords at buffer to the value of c
;void *memsetd(void *buffer, int c, int num);
[global _memsetd]
_memsetd:
push ebp
mov ebp, esp
push esi
push edi
push ecx
mov edi, [ebp+8]
push edi ;save for return address
mov eax, [ebp+12]
mov ecx, [ebp+16]
rep stosd
pop eax
pop ecx
pop edi
pop esi
pop ebp
ret
;returns the number of characters in a string
;extern dword strlen(char *str);
[global _strlen]
@ -240,57 +335,6 @@ _getCursorPosition:
ret
;
;void console_scroll()
;
[global _console_scroll]
_console_scroll:
pusha
mov esi, _console_memory+160
mov edi, _console_memory
mov ecx, 960 ;(2000-80)/2
rep movsd
mov ax, 0x0720
mov ecx, 80
rep stosw
mov esi, _console_memory
mov edi, 0xC00B8000
mov ecx, 1000
rep movsd
mov eax, [_videoMode]
cmp eax, 0
jz _console_scroll_end
call _video_drawConsole
_console_scroll_end:
popa
ret
;
;void console_cls()
;
[global _console_cls]
_console_cls:
pusha
mov edi, _console_memory
mov ax, 0x0720
mov ecx, 2000
rep stosw
push dword 0
call _writeCursorPosition
add esp, 4
mov [_cursorPosition], dword 0
mov esi, _console_memory
mov edi, 0xC00B8000
mov ecx, 1000
rep movsd
popa
ret
;
;int puts(char *str)
;

View File

@ -12,13 +12,15 @@ dword read_cr2();
dword read_cr3();
void writeCursorPosition(dword pos);
dword getCursorPosition();
void console_scroll();
void console_cls();
int puts(char *str);
int putDec(int number);
int putDecu(dword number);
void strcpy(char *dest, char *src);
void memcpy(void *dest, void *src, dword n);
void memcpyd(void *dest, void *src, dword n);
void *memset(void *buffer, int c, int num);
void *memsetw(void *buffer, int c, int num);
void *memsetd(void *buffer, int c, int num);
dword strlen(char *str);
#endif

View File

@ -25,8 +25,8 @@ void mouse_init()
outportb(0x64, 0xD4); //send command to mouse, not kbd
outportb(0x60, 0xF4); //enable data reporting
mouse_x = video_mode.XResolution >> 1;
mouse_y = video_mode.YResolution >> 1;
mouse_x = video_getWidth() >> 1;
mouse_y = video_getHeight() >> 1;
//outportb(0x64, 0xD4);
//outportb(0x60, 0xE7); //scaling 2:1
@ -50,12 +50,12 @@ void isr_mouse()
mouse_y -= adjy; //-= because screen y coordinates are opposite mouse y coordinates
if (mouse_x < 0)
mouse_x = 0;
if (mouse_x >= video_mode.XResolution)
mouse_x = video_mode.XResolution - 1;
if (mouse_x >= video_getWidth())
mouse_x = video_getWidth() - 1;
if (mouse_y < 0)
mouse_y = 0;
if (mouse_y >= video_mode.YResolution)
mouse_y = video_mode.YResolution - 1;
if (mouse_y >= video_getHeight())
mouse_y = video_getHeight() - 1;
if (mouse_inbuffer[0] & 0x01) //left button
video_pset(mouse_x, mouse_y, 0x00FF8800);
else

View File

@ -48,7 +48,7 @@ void k_init()
int p = video_getWidth()*video_getHeight()-1;
for (; p >= 0; p--)
video_psetp(p, 0x00000077);
video_drawConsole();
kio_drawConsole();
}
printf("HOS 0.13 - Kernel File Size: %u kb\tData Size: %u bytes\n", kernel_size()>>10, (dword)(&_end)-(dword)(&_code));

View File

@ -1,12 +1,13 @@
// kio.c
// Author: Josh Holtrop
// Created: 12/25/03
// Modified: 03/02/04
// Modified: 03/09/04
#include "hos_defines.h"
#include "kio.h"
dword cursorPosition = 0; //Caches the current cursor position
word console_memory[2000]; //holds a copy of the console's memory
// This is the main output routine, it uses a format string and a variable
// number of arguments to print formatted text
@ -101,10 +102,8 @@ void putc(dword chr)
}
if (cursorPosition >= 2000)
{
console_scroll();
kio_console_scroll();
cursorPosition = 2000-80;
if (video_Mode())
video_drawConsole();
}
if (!video_Mode())
writeCursorPosition(cursorPosition);
@ -112,7 +111,7 @@ void putc(dword chr)
// This function displays a number in hexadecimal
int putHex(dword number)
int putHex(dword number)
{
int hitNum = 0;
int i;
@ -132,5 +131,52 @@ int putHex(dword number)
}
void kio_console_scroll()
{
memcpyd(console_memory + 80, console_memory, 960);
memsetw(console_memory + 1920, 0x0720, 80);
if (video_Mode())
kio_drawConsole();
else
memcpyd(console_memory, 0xC00B8000, 1000);
}
void kio_console_cls()
{
memsetw(console_memory, 0x0720, 2000);
if (video_Mode())
kio_drawConsole();
else
memcpyd(console_memory, 0xC00B8000, 1000);
writeCursorPosition(0);
}
// This function draws a simple "console" window in graphical mode to display text
void kio_drawConsole()
{
video_rectf(9, 9, 490, 260, 0);
video_rect(8, 8, 491, 261, 0x00777777);
int x, y;
for (x = 0; x < 80; x++)
{
for (y = 0; y < 25; y++)
{
video_renderChar(x*6+10, y*10+10, console_memory[y*80+x], 0, 0x0000FF00);
}
}
}
// This function draws a "console" character to the graphical video screen
void kio_drawConsoleChar(dword position)
{
int x = position % 80;
int y = position / 80;
video_renderChar(x*6+10, y*10+10, console_memory[y*80+x], 0, 0x0000FF00);
}

View File

@ -1,17 +1,21 @@
//kio.h
// kio.h
// Author: Josh Holtrop
// Created: 12/25/03
// Modified: 12/25/03
#include "hos_defines.h"
// Modified: 03/09/04
#ifndef __HOS_KIO__
#define __HOS_KIO__ __HOS_KIO__
#include "hos_defines.h"
void printf(char *fmt, ...);
void putc(dword chr);
int putHex(dword number);
void kio_drawConsole();
void kio_drawConsoleChar(dword position);
void kio_console_scroll();
void kio_console_cls();
#endif

View File

@ -17,14 +17,14 @@ void vmm_init()
pageTables[0x3FF] = 0x104000|0x03; //the last page directory entry points to the page directory itself
pageTables[0] = 0;
invlpg(0);
if (videoMode) //we are in a graphical mode
if (video_Mode()) //we are in a graphical mode
{
unsigned int vidPages = video_mode.XResolution * video_mode.YResolution * (video_mode.BitsPerPixel >> 3);
unsigned int vidPages = video_getWidth() * video_getHeight() * (video_getBitsPerPixel() >> 3);
if (vidPages % 4096)
vidPages = (vidPages >> 12) + 1;
else
vidPages = (vidPages >> 12);
vmm_mapn(0xF0000000, video_mode.PhysBasePtr, vidPages);
vmm_mapn(0xF0000000, video_getPhysBasePtr(), vidPages);
}
unsigned int firstHeapEntryBlock = (unsigned int)mm_palloc();
vmm_map1((unsigned int)firstHeapEntry, firstHeapEntryBlock);
@ -62,7 +62,7 @@ void vmm_map1(unsigned int virt, unsigned int physical)
unsigned int *pageTables = (unsigned int *)0xC0104000; //this is the location of the page directory
if (!(pageTables[pde] & 0x01)) //the page directory entry does not exist, we must allocate a page for it
{
unsigned int *newpagetable = mm_palloc();
unsigned int *newpagetable = (dword *)mm_palloc();
pageTables[pde] = ((unsigned int)newpagetable) | 0x03;
invlpg(virt);
unsigned int *newpteptr = (unsigned int *)(0xFFC00000 | (pde << 12)); //points to first unsigned int of newly allocated page table

View File

@ -525,14 +525,20 @@ StdFont fonts[] = {
{stdfont10x7, 10, 7}
};
//Returns the standard font size, 0 = invalid font
// bits 0-7 = font width
// bits 8-15 = font height
unsigned int stdfont_getFontSize(unsigned int fontNumber)
//Returns the width of a given, 0 = invalid font
unsigned int stdfont_getFontWidth(unsigned int fontNumber)
{
if (fontNumber >= STDFONTS)
return 0;
return (fonts[fontNumber].charHeight << 8) | fonts[fontNumber].charWidth;
return fonts[fontNumber].charWidth;
}
//Returns the height of a given, 0 = invalid font
unsigned int stdfont_getFontHeight(unsigned int fontNumber)
{
if (fontNumber >= STDFONTS)
return 0;
return fonts[fontNumber].charHeight;
}
//Returns a pointer to the desired font's bitmap representation

View File

@ -15,9 +15,10 @@ typedef struct {
} StdFont;
//Returns the standard font size, 0 = invalid font
// bits 0-7 = font width
// bits 8-15 = font height
unsigned int stdfont_getFontSize(unsigned int fontNumber);
unsigned int stdfont_getFontWidth(unsigned int fontNumber);
//Returns the height of a given, 0 = invalid font
unsigned int stdfont_getFontHeight(unsigned int fontNumber);
//Returns a pointer to the desired font's bitmap representation
unsigned char *stdfont_getBitmap(unsigned int fontNumber);

View File

@ -10,7 +10,6 @@ dword videoMode = 0; //what video mode # we are in, 0 for console mode
word *vid_ptr16 = (word *)0xF0000000;
byte *vid_ptr24 = (byte *)0xF0000000;
dword *vid_ptr32 = (dword *)0xF0000000;
word console_memory[2000]; //holds a copy of the console's memory
void (*video_psetp)(int, dword) = video_psetpnull; //function pointer to set a pixel
//Initialized the video mode information block video_mode and allocated double-buffer memory for graphics display
@ -37,17 +36,22 @@ void video_init()
}
//Renders a character using stdfont[] as a bitmask
void video_renderChar(int x, int y, int character, dword color)
void video_renderChar(int x, int y, int character, int font, dword color)
{
int charpos = (character & 0xFF) * 8;
int charWidth = stdfont_getFontWidth(font);
if (!charWidth)
return;
int charHeight = stdfont_getFontHeight(font);
int charpos = (character & 0xFF) * charHeight;
byte *charBMP = (byte *)stdfont_getBitmap(font);
int row;
int col;
for (row = 0; row < 8; row++)
for (row = 0; row < charHeight; row++)
{
for (col = 0; col < 5; col++)
for (col = 0; col < charWidth; col++)
{
if ((stdfont[charpos+row] >> (col+3)) & 0x01)
video_pset(x+(5-col), y+row, color);
if ((charBMP[charpos + row] << col) & 0x80)
video_pset(x + col, y + row, color);
}
}
}
@ -161,31 +165,6 @@ void video_psetp32(int pixel, dword color)
void video_psetpnull(int pixel, dword color) {}
// This function draws a simple "console" window in graphical mode to display text
void video_drawConsole()
{
video_rectf(9, 9, 490, 260, 0);
video_rect(8, 8, 491, 261, 0x00777777);
int x, y;
for (x = 0; x < 80; x++)
{
for (y = 0; y < 25; y++)
{
video_renderChar(x*6+10, y*10+10, console_memory[y*80+x], 0x00FFFFFF);
}
}
}
// This function draws a "console" character to the graphical video screen
void video_drawConsoleChar(dword position)
{
int x = position % 80;
int y = position / 80;
video_renderChar(x*6+10, y*10+10, console_memory[y*80+x], 0x00FFFFFF);
}
int video_getWidth()
{
return video_mode.XResolution;
@ -196,6 +175,16 @@ int video_getHeight()
return video_mode.YResolution;
}
byte video_getBitsPerPixel()
{
return video_mode.BitsPerPixel;
}
dword video_getPhysBasePtr()
{
return video_mode.PhysBasePtr;
}
dword video_Mode()
{
return videoMode;

View File

@ -18,11 +18,11 @@ void video_psetp16(int pixel, dword color);
void video_psetp24(int pixel, dword color);
void video_psetp32(int pixel, dword color);
void video_psetpnull(int pixel, dword color);
void video_renderChar(int x, int y, int character, dword color);
void video_drawConsole();
void video_drawConsoleChar(dword position);
void video_renderChar(int x, int y, int character, int font, dword color);
int video_getWidth();
int video_getHeight();
byte video_getBitsPerPixel();
dword video_getPhysBasePtr();
dword video_Mode();