Import backup from 2003-12-28
This commit is contained in:
parent
e82bf2ecdf
commit
715bb9341a
@ -74,6 +74,7 @@ inline void pic2_mask(byte mask)
|
|||||||
//Restarts the computer
|
//Restarts the computer
|
||||||
inline void restart()
|
inline void restart()
|
||||||
{
|
{
|
||||||
|
enable_ints();
|
||||||
byte temp;
|
byte temp;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
24
asmfuncs.asm
24
asmfuncs.asm
@ -4,6 +4,10 @@
|
|||||||
; Modified: 12/25/03
|
; Modified: 12/25/03
|
||||||
|
|
||||||
[extern _putc]
|
[extern _putc]
|
||||||
|
[extern _console_memory]
|
||||||
|
[extern _cursorPosition]
|
||||||
|
[extern _video_drawConsole]
|
||||||
|
[extern _videoMode]
|
||||||
|
|
||||||
%macro jzfar 1
|
%macro jzfar 1
|
||||||
jnz %%skip
|
jnz %%skip
|
||||||
@ -134,13 +138,22 @@ _getCursorPosition:
|
|||||||
[global _console_scroll]
|
[global _console_scroll]
|
||||||
_console_scroll:
|
_console_scroll:
|
||||||
pusha
|
pusha
|
||||||
mov esi, 0xc00b8000+160
|
mov esi, _console_memory+160
|
||||||
mov edi, 0xc00b8000
|
mov edi, _console_memory
|
||||||
mov ecx, 960 ;(2000-80)/2
|
mov ecx, 960 ;(2000-80)/2
|
||||||
rep movsd
|
rep movsd
|
||||||
mov ax, 0x0720
|
mov ax, 0x0720
|
||||||
mov ecx, 80
|
mov ecx, 80
|
||||||
rep stosw
|
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
|
popa
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@ -152,13 +165,18 @@ _console_scroll:
|
|||||||
[global _console_cls]
|
[global _console_cls]
|
||||||
_console_cls:
|
_console_cls:
|
||||||
pusha
|
pusha
|
||||||
mov edi, 0xc00b8000
|
mov edi, _console_memory
|
||||||
mov ax, 0x0720
|
mov ax, 0x0720
|
||||||
mov ecx, 2000
|
mov ecx, 2000
|
||||||
rep stosw
|
rep stosw
|
||||||
push dword 0
|
push dword 0
|
||||||
call _writeCursorPosition
|
call _writeCursorPosition
|
||||||
add esp, 4
|
add esp, 4
|
||||||
|
mov [_cursorPosition], dword 0
|
||||||
|
mov esi, _console_memory
|
||||||
|
mov edi, 0xC00B8000
|
||||||
|
mov ecx, 1000
|
||||||
|
rep movsd
|
||||||
popa
|
popa
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
%define VERSION "0.12" ;HOS version
|
%define VERSION "0.13" ;HOS version
|
||||||
|
|
||||||
%define BOOT_FAT_SEG 0x07E0 ;right after boot sector
|
%define BOOT_FAT_SEG 0x07E0 ;right after boot sector
|
||||||
%define BOOT_ROOT_SEG 0x0900 ;right after FAT
|
%define BOOT_ROOT_SEG 0x0900 ;right after FAT
|
||||||
|
2
idt.inc
2
idt.inc
@ -10,6 +10,7 @@ idtr:
|
|||||||
|
|
||||||
%macro isr_label 1
|
%macro isr_label 1
|
||||||
isr_%1:
|
isr_%1:
|
||||||
|
push eax
|
||||||
mov eax, %1
|
mov eax, %1
|
||||||
jmp isr_main
|
jmp isr_main
|
||||||
%endmacro
|
%endmacro
|
||||||
@ -79,6 +80,7 @@ isr_main:
|
|||||||
pop es
|
pop es
|
||||||
pop ds
|
pop ds
|
||||||
popa
|
popa
|
||||||
|
pop eax
|
||||||
|
|
||||||
iret
|
iret
|
||||||
|
|
||||||
|
48
kernel.c
48
kernel.c
@ -60,50 +60,18 @@ void k_init()
|
|||||||
pic2_mask(0); //unmask IRQ's 8-15
|
pic2_mask(0); //unmask IRQ's 8-15
|
||||||
enable_ints();
|
enable_ints();
|
||||||
kbd_resetLEDs(); //after enabling interrupts!!
|
kbd_resetLEDs(); //after enabling interrupts!!
|
||||||
|
|
||||||
printf("HOS 0.12 - Kernel Size: %u kb\n", kernel_size()/1024);
|
|
||||||
printf("Memory available to OS: %u MB (Bytes: %u)\n", mm_megabytes, mm_totalmem);
|
|
||||||
printf("Free memory: %u bytes\t %u pages\n", mm_freemem(), mm_freemem()>>12);
|
|
||||||
|
|
||||||
if (videoMode)
|
if (videoMode)
|
||||||
{
|
{
|
||||||
dword p;
|
int x, y;
|
||||||
for (p = 0; p < video_mode.XResolution*video_mode.YResolution; p++)
|
for (x = 0; x < video_mode.XResolution; x++)
|
||||||
video_psetp(p, 0x00000055);
|
for (y = 0; y < video_mode.YResolution; y++)
|
||||||
|
video_pset(x, y, 0x00000044);
|
||||||
|
video_drawConsole();
|
||||||
}
|
}
|
||||||
|
|
||||||
dword callnum = 0;
|
printf("HOS 0.13 - Kernel Size: %u kb\n", kernel_size()>>10);
|
||||||
dword fa = 0;
|
printf("Memory available to OS: %u MB (Bytes: %u)\n", mm_megabytes, mm_totalmem);
|
||||||
dword la;
|
printf("Free memory: %u bytes\t %u pages\n", mm_freemem(), mm_freemem()>>12);
|
||||||
dword addr;
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
la = addr;
|
|
||||||
addr = (dword)mm_palloc();
|
|
||||||
if (fa == 0)
|
|
||||||
fa = addr;
|
|
||||||
// printf("addr = 0x%x\tcallnum = %u\tfree pages = %u\n", addr, callnum, mm_freemem()>>12);
|
|
||||||
if (!addr)
|
|
||||||
break;
|
|
||||||
callnum++;
|
|
||||||
}
|
|
||||||
printf("#calls = %u\t", callnum);
|
|
||||||
printf("mm_freemem() = %d (0x%x, %x)\n", mm_freemem(), mm_freemem(), mm_freemem());
|
|
||||||
|
|
||||||
callnum = 0;
|
|
||||||
addr = fa;
|
|
||||||
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
mm_pfree(addr);
|
|
||||||
addr += 4096;
|
|
||||||
callnum++;
|
|
||||||
if (addr > la)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("#calls = %u\t", callnum);
|
|
||||||
printf("mm_freemem() = %d (0x%x, %x)\n", mm_freemem(), mm_freemem(), mm_freemem());
|
|
||||||
|
|
||||||
dword key = 0;
|
dword key = 0;
|
||||||
for (;;)
|
for (;;)
|
||||||
|
22
kio.c
22
kio.c
@ -1,10 +1,12 @@
|
|||||||
|
|
||||||
//kio.c
|
//kio.c
|
||||||
// Author: Josh Holtrop
|
// Author: Josh Holtrop
|
||||||
// Created: 12/25/03
|
// Created: 12/25/03
|
||||||
// Modified: 12/25/03
|
// Modified: 12/25/03
|
||||||
|
|
||||||
|
|
||||||
|
// This is the main output routine, it uses a format string and a variable
|
||||||
|
// number of arguments to print formatted text
|
||||||
void printf(char *fmt, ...)
|
void printf(char *fmt, ...)
|
||||||
{
|
{
|
||||||
dword *params = ((dword *)(&fmt)) + 1; //points to the first paramater
|
dword *params = ((dword *)(&fmt)) + 1; //points to the first paramater
|
||||||
@ -61,6 +63,7 @@ void printf(char *fmt, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// This function draws a single character
|
||||||
void putc(dword chr)
|
void putc(dword chr)
|
||||||
{
|
{
|
||||||
char charac = (char)chr;
|
char charac = (char)chr;
|
||||||
@ -81,18 +84,31 @@ void putc(dword chr)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
vidmem[cursorPosition] = charac | 0x0700;
|
if (videoMode)
|
||||||
|
{
|
||||||
|
console_memory[cursorPosition] = charac | 0x0700;
|
||||||
|
video_drawConsoleChar(cursorPosition);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
console_memory[cursorPosition] = charac | 0x0700;
|
||||||
|
vidmem[cursorPosition] = charac | 0x0700;
|
||||||
|
}
|
||||||
cursorPosition++;
|
cursorPosition++;
|
||||||
}
|
}
|
||||||
if (cursorPosition >= 2000)
|
if (cursorPosition >= 2000)
|
||||||
{
|
{
|
||||||
console_scroll();
|
console_scroll();
|
||||||
cursorPosition = 2000-80;
|
cursorPosition = 2000-80;
|
||||||
|
if (videoMode)
|
||||||
|
video_drawConsole();
|
||||||
}
|
}
|
||||||
writeCursorPosition(cursorPosition);
|
if (!videoMode)
|
||||||
|
writeCursorPosition(cursorPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// This function displays a number in hexadecimal
|
||||||
int putHex(dword number)
|
int putHex(dword number)
|
||||||
{
|
{
|
||||||
int hitNum = 0;
|
int hitNum = 0;
|
||||||
|
9
mm.c
9
mm.c
@ -1,5 +1,7 @@
|
|||||||
// mm.c
|
// mm.c
|
||||||
// 09/01/03 Josh Holtrop
|
// Author: Josh Holtrop
|
||||||
|
// Created: 09/01/03
|
||||||
|
// Modified: 12/28/03
|
||||||
|
|
||||||
//The total amount of physical memory available (bytes)
|
//The total amount of physical memory available (bytes)
|
||||||
#define BITMAP_SIZE 0x20000
|
#define BITMAP_SIZE 0x20000
|
||||||
@ -44,6 +46,8 @@ void mm_init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// This function frees a certain number of pages starting at the address
|
||||||
|
// specified in base for a length of pages pages
|
||||||
void mm_pfreen(dword base, dword pages)
|
void mm_pfreen(dword base, dword pages)
|
||||||
{
|
{
|
||||||
dword a;
|
dword a;
|
||||||
@ -55,6 +59,7 @@ void mm_pfreen(dword base, dword pages)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// This function frees a single page
|
||||||
void mm_pfree(dword base)
|
void mm_pfree(dword base)
|
||||||
{
|
{
|
||||||
// dword pageNumber = base >> 12; // >>12 == /4096
|
// dword pageNumber = base >> 12; // >>12 == /4096
|
||||||
@ -64,6 +69,7 @@ void mm_pfree(dword base)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// This function allocates a single page, returning its physical address
|
||||||
void *mm_palloc()
|
void *mm_palloc()
|
||||||
{
|
{
|
||||||
dword bite;
|
dword bite;
|
||||||
@ -86,6 +92,7 @@ void *mm_palloc()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// This function reports the number of bytes of free physical memory
|
||||||
dword mm_freemem()
|
dword mm_freemem()
|
||||||
{
|
{
|
||||||
dword a;
|
dword a;
|
||||||
|
8
mouse.c
8
mouse.c
@ -28,8 +28,6 @@ void mouse_init()
|
|||||||
void isr_mouse()
|
void isr_mouse()
|
||||||
{
|
{
|
||||||
byte inb = inportb(0x60); //read mouse byte
|
byte inb = inportb(0x60); //read mouse byte
|
||||||
//printf("InB: %x\n", inb);
|
|
||||||
//return;
|
|
||||||
if ((inb == 0xFA) && (mouse_bytesRead < 1)) //ACK
|
if ((inb == 0xFA) && (mouse_bytesRead < 1)) //ACK
|
||||||
return;
|
return;
|
||||||
mouse_inbuffer[mouse_bytesRead] = inb;
|
mouse_inbuffer[mouse_bytesRead] = inb;
|
||||||
@ -50,15 +48,9 @@ void isr_mouse()
|
|||||||
if (mouse_y >= video_mode.YResolution)
|
if (mouse_y >= video_mode.YResolution)
|
||||||
mouse_y = video_mode.YResolution - 1;
|
mouse_y = video_mode.YResolution - 1;
|
||||||
if (mouse_inbuffer[0] & 0x01) //left button
|
if (mouse_inbuffer[0] & 0x01) //left button
|
||||||
{
|
|
||||||
video_pset(mouse_x, mouse_y, 0x00FF8800);
|
video_pset(mouse_x, mouse_y, 0x00FF8800);
|
||||||
printf("X: %d, Y: %d\n", mouse_x, mouse_y);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
video_pset(mouse_x, mouse_y, 0x00FFFFFF);
|
video_pset(mouse_x, mouse_y, 0x00FFFFFF);
|
||||||
printf("X: %d, Y: %d\n", mouse_x, mouse_y);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
48
video.c
48
video.c
@ -4,9 +4,9 @@
|
|||||||
|
|
||||||
|
|
||||||
//Initialized the video mode information block video_mode and allocated double-buffer memory for graphics display
|
//Initialized the video mode information block video_mode and allocated double-buffer memory for graphics display
|
||||||
void video_init()
|
void video_init()
|
||||||
{
|
{
|
||||||
videoMode = *(dword *)0xC0090002;
|
videoMode = *(word *)0xC0090002;
|
||||||
|
|
||||||
if (!videoMode) //we are in console mode
|
if (!videoMode) //we are in console mode
|
||||||
{
|
{
|
||||||
@ -30,7 +30,7 @@ void video_init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Renders a character using stdfont[] as a bitmask
|
//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, dword color)
|
||||||
{
|
{
|
||||||
int charpos = (character & 0xFF) * 8;
|
int charpos = (character & 0xFF) * 8;
|
||||||
int row;
|
int row;
|
||||||
@ -46,7 +46,7 @@ void video_renderChar(int x, int y, int character, dword color)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Draws a horizontal line
|
//Draws a horizontal line
|
||||||
void video_horiz(int y, int x1, int x2, dword color)
|
void video_horiz(int y, int x1, int x2, dword color)
|
||||||
{
|
{
|
||||||
if (x1 > x2)
|
if (x1 > x2)
|
||||||
{
|
{
|
||||||
@ -70,7 +70,7 @@ void video_horiz(int y, int x1, int x2, dword color)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Draws a vertical line
|
//Draws a vertical line
|
||||||
void video_vert(int x, int y1, int y2, dword color)
|
void video_vert(int x, int y1, int y2, dword color)
|
||||||
{
|
{
|
||||||
if (y1 > y2)
|
if (y1 > y2)
|
||||||
{
|
{
|
||||||
@ -95,7 +95,7 @@ void video_vert(int x, int y1, int y2, dword color)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Draws a rectangle
|
//Draws a rectangle
|
||||||
void video_rect(int x1, int y1, int x2, int y2, dword color)
|
void video_rect(int x1, int y1, int x2, int y2, dword color)
|
||||||
{
|
{
|
||||||
video_horiz(y1, x1, x2, color);
|
video_horiz(y1, x1, x2, color);
|
||||||
video_horiz(y2, x1, x2, color);
|
video_horiz(y2, x1, x2, color);
|
||||||
@ -104,7 +104,7 @@ void video_rect(int x1, int y1, int x2, int y2, dword color)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Draws a filled rectangle
|
//Draws a filled rectangle
|
||||||
void video_rectf(int x1, int y1, int x2, int y2, dword color)
|
void video_rectf(int x1, int y1, int x2, int y2, dword color)
|
||||||
{
|
{
|
||||||
if (y2 < y1)
|
if (y2 < y1)
|
||||||
{
|
{
|
||||||
@ -125,13 +125,13 @@ inline void video_pset(int x, int y, dword color)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Draws a pixel at the specified pixel position
|
//Draws a pixel at the specified pixel position
|
||||||
void video_psetp16(int pixel, dword color)
|
void video_psetp16(int pixel, dword color)
|
||||||
{
|
{
|
||||||
vid_ptr16[pixel] = ((color&0xFF)>>3) | ((((color>>8)&0xFF)>>2)<<5) | ((((color>>16)&0xFF)>>3)<<11);
|
vid_ptr16[pixel] = ((color&0xFF)>>3) | ((((color>>8)&0xFF)>>2)<<5) | ((((color>>16)&0xFF)>>3)<<11);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Draws a pixel at the specified pixel position
|
//Draws a pixel at the specified pixel position
|
||||||
void video_psetp24(int pixel, dword color)
|
void video_psetp24(int pixel, dword color)
|
||||||
{
|
{
|
||||||
vid_ptr24[pixel*3] = color & 0xFF;
|
vid_ptr24[pixel*3] = color & 0xFF;
|
||||||
vid_ptr24[pixel*3+1] = (color>>8) & 0xFF;
|
vid_ptr24[pixel*3+1] = (color>>8) & 0xFF;
|
||||||
@ -139,13 +139,39 @@ void video_psetp24(int pixel, dword color)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Draws a pixel at the specified pixel position
|
//Draws a pixel at the specified pixel position
|
||||||
void video_psetp32(int pixel, dword color)
|
void video_psetp32(int pixel, dword color)
|
||||||
{
|
{
|
||||||
vid_ptr32[pixel] = color;
|
vid_ptr32[pixel] = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Dummy function to not draw anything if there is no graphical mode enabled
|
//Dummy function to not draw anything if there is no graphical mode enabled
|
||||||
void video_psetpnull(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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
27
video.h
27
video.h
@ -1,18 +1,21 @@
|
|||||||
//video.h
|
//video.h
|
||||||
// 08/18/03 Josh Holtrop
|
// 08/18/03 Josh Holtrop
|
||||||
// Modified: 11/12/03
|
// Modified: 12/28/03
|
||||||
|
|
||||||
void video_init();
|
void video_init();
|
||||||
void video_horiz(int y, int x1, int x2, dword color);
|
void video_horiz(int y, int x1, int x2, dword color);
|
||||||
void video_vert(int x, int y1, int y2, dword color);
|
void video_vert(int x, int y1, int y2, dword color);
|
||||||
void video_rect(int x1, int y1, int x2, int y2, dword color);
|
void video_rect(int x1, int y1, int x2, int y2, dword color);
|
||||||
void video_rectf(int x1, int y1, int x2, int y2, dword color);
|
void video_rectf(int x1, int y1, int x2, int y2, dword color);
|
||||||
inline void video_pset(int x, int y, dword color);
|
inline void video_pset(int x, int y, dword color);
|
||||||
void video_psetp16(int pixel, dword color);
|
void video_psetp16(int pixel, dword color);
|
||||||
void video_psetp24(int pixel, dword color);
|
void video_psetp24(int pixel, dword color);
|
||||||
void video_psetp32(int pixel, dword color);
|
void video_psetp32(int pixel, dword color);
|
||||||
void video_psetpnull(int pixel, dword color);
|
void video_psetpnull(int pixel, dword color);
|
||||||
void video_renderChar(int x, int y, int character, dword color);
|
void video_renderChar(int x, int y, int character, dword color);
|
||||||
|
void video_drawConsole();
|
||||||
|
void video_drawConsoleChar(dword position);
|
||||||
|
|
||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
word ModeAttributes;
|
word ModeAttributes;
|
||||||
@ -53,11 +56,13 @@ typedef struct{
|
|||||||
byte Reserved[206];
|
byte Reserved[206];
|
||||||
} ModeInfoBlock;
|
} ModeInfoBlock;
|
||||||
|
|
||||||
|
|
||||||
ModeInfoBlock video_mode;
|
ModeInfoBlock video_mode;
|
||||||
dword videoMode = 0; //what video mode # we are in, 0 for console mode
|
dword videoMode = 0; //what video mode # we are in, 0 for console mode
|
||||||
word *vid_ptr16 = (word *)0xF0000000;
|
word *vid_ptr16 = (word *)0xF0000000;
|
||||||
byte *vid_ptr24 = (byte *)0xF0000000;
|
byte *vid_ptr24 = (byte *)0xF0000000;
|
||||||
dword *vid_ptr32 = (dword *)0xF0000000;
|
dword *vid_ptr32 = (dword *)0xF0000000;
|
||||||
|
word console_memory[2000]; //holds a copy of the console's memory
|
||||||
void (*video_psetp)(int, dword); //function pointer to set a pixel
|
void (*video_psetp)(int, dword); //function pointer to set a pixel
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user