From 715bb9341a4636213dfa0aa0ce4ae84565bb7625 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 28 Dec 2003 22:00:00 -0500 Subject: [PATCH] Import backup from 2003-12-28 --- Functions.c | 1 + asmfuncs.asm | 24 +++++++++++++++++++++--- bootdef.inc | 2 +- idt.inc | 2 ++ kernel.c | 48 ++++++++---------------------------------------- kio.c | 22 +++++++++++++++++++--- mm.c | 9 ++++++++- mouse.c | 8 -------- video.c | 48 +++++++++++++++++++++++++++++++++++++----------- video.h | 27 ++++++++++++++++----------- 10 files changed, 113 insertions(+), 78 deletions(-) diff --git a/Functions.c b/Functions.c index 1f6c0da..63ed44f 100644 --- a/Functions.c +++ b/Functions.c @@ -74,6 +74,7 @@ inline void pic2_mask(byte mask) //Restarts the computer inline void restart() { + enable_ints(); byte temp; do { diff --git a/asmfuncs.asm b/asmfuncs.asm index 1fd2a3f..f955994 100644 --- a/asmfuncs.asm +++ b/asmfuncs.asm @@ -4,6 +4,10 @@ ; Modified: 12/25/03 [extern _putc] +[extern _console_memory] +[extern _cursorPosition] +[extern _video_drawConsole] +[extern _videoMode] %macro jzfar 1 jnz %%skip @@ -134,13 +138,22 @@ _getCursorPosition: [global _console_scroll] _console_scroll: pusha - mov esi, 0xc00b8000+160 - mov edi, 0xc00b8000 + 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 @@ -152,13 +165,18 @@ _console_scroll: [global _console_cls] _console_cls: pusha - mov edi, 0xc00b8000 + 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 diff --git a/bootdef.inc b/bootdef.inc index 504c7f6..771a115 100644 --- a/bootdef.inc +++ b/bootdef.inc @@ -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_ROOT_SEG 0x0900 ;right after FAT diff --git a/idt.inc b/idt.inc index e12b2f6..77fe552 100644 --- a/idt.inc +++ b/idt.inc @@ -10,6 +10,7 @@ idtr: %macro isr_label 1 isr_%1: + push eax mov eax, %1 jmp isr_main %endmacro @@ -79,6 +80,7 @@ isr_main: pop es pop ds popa + pop eax iret diff --git a/kernel.c b/kernel.c index 206cb5c..91960ff 100644 --- a/kernel.c +++ b/kernel.c @@ -60,50 +60,18 @@ void k_init() pic2_mask(0); //unmask IRQ's 8-15 enable_ints(); 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) { - dword p; - for (p = 0; p < video_mode.XResolution*video_mode.YResolution; p++) - video_psetp(p, 0x00000055); + int x, y; + for (x = 0; x < video_mode.XResolution; x++) + for (y = 0; y < video_mode.YResolution; y++) + video_pset(x, y, 0x00000044); + video_drawConsole(); } - dword callnum = 0; - dword fa = 0; - dword la; - 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()); + printf("HOS 0.13 - Kernel Size: %u kb\n", kernel_size()>>10); + 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); dword key = 0; for (;;) diff --git a/kio.c b/kio.c index 6eae447..0bb3514 100644 --- a/kio.c +++ b/kio.c @@ -1,10 +1,12 @@ + //kio.c // Author: Josh Holtrop // Created: 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, ...) { 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) { char charac = (char)chr; @@ -81,18 +84,31 @@ void putc(dword chr) } 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++; } if (cursorPosition >= 2000) { console_scroll(); 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 hitNum = 0; diff --git a/mm.c b/mm.c index f5ca36c..ecdcbb8 100644 --- a/mm.c +++ b/mm.c @@ -1,5 +1,7 @@ // 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) #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) { dword a; @@ -55,6 +59,7 @@ void mm_pfreen(dword base, dword pages) } +// This function frees a single page void mm_pfree(dword base) { // 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() { dword bite; @@ -86,6 +92,7 @@ void *mm_palloc() } +// This function reports the number of bytes of free physical memory dword mm_freemem() { dword a; diff --git a/mouse.c b/mouse.c index 80ef5d3..d8542c9 100644 --- a/mouse.c +++ b/mouse.c @@ -28,8 +28,6 @@ void mouse_init() void isr_mouse() { byte inb = inportb(0x60); //read mouse byte - //printf("InB: %x\n", inb); - //return; if ((inb == 0xFA) && (mouse_bytesRead < 1)) //ACK return; mouse_inbuffer[mouse_bytesRead] = inb; @@ -50,15 +48,9 @@ void isr_mouse() if (mouse_y >= video_mode.YResolution) mouse_y = video_mode.YResolution - 1; if (mouse_inbuffer[0] & 0x01) //left button - { video_pset(mouse_x, mouse_y, 0x00FF8800); - printf("X: %d, Y: %d\n", mouse_x, mouse_y); - } else - { video_pset(mouse_x, mouse_y, 0x00FFFFFF); - printf("X: %d, Y: %d\n", mouse_x, mouse_y); - } } } diff --git a/video.c b/video.c index 4e70045..9d318d5 100644 --- a/video.c +++ b/video.c @@ -4,9 +4,9 @@ //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 { @@ -30,7 +30,7 @@ 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, dword color) { int charpos = (character & 0xFF) * 8; int row; @@ -46,7 +46,7 @@ void video_renderChar(int x, int y, int character, dword color) } //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) { @@ -70,7 +70,7 @@ void video_horiz(int y, int x1, int x2, dword color) } //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) { @@ -95,7 +95,7 @@ void video_vert(int x, int y1, int y2, dword color) } //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(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 -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) { @@ -125,13 +125,13 @@ inline void video_pset(int x, int y, dword color) } //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); } //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+1] = (color>>8) & 0xFF; @@ -139,13 +139,39 @@ void video_psetp24(int pixel, dword color) } //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; } //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); +} + diff --git a/video.h b/video.h index edaab47..03bca9c 100644 --- a/video.h +++ b/video.h @@ -1,18 +1,21 @@ //video.h // 08/18/03 Josh Holtrop -// Modified: 11/12/03 +// Modified: 12/28/03 -void video_init(); -void video_horiz(int y, int x1, int x2, 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_rectf(int x1, int y1, int x2, int y2, dword color); +void video_init(); +void video_horiz(int y, int x1, int x2, 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_rectf(int x1, int y1, int x2, int y2, dword color); inline void video_pset(int x, int y, dword color); -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_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); + typedef struct{ word ModeAttributes; @@ -53,11 +56,13 @@ typedef struct{ byte Reserved[206]; } ModeInfoBlock; + ModeInfoBlock video_mode; 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); //function pointer to set a pixel