diff --git a/Functions.c b/Functions.c index 9c669a4..7455c40 100644 --- a/Functions.c +++ b/Functions.c @@ -37,21 +37,31 @@ void remap_pics(int pic1, int pic2) { byte a1, a2; - a1 = inportb(PIC1_DATA); - a2 = inportb(PIC2_DATA); + a1 = inportb(PIC1_DATA); //0x21 + a2 = inportb(PIC2_DATA); //0xA1 - outportb(PIC1_COMMAND, ICW1_INIT+ICW1_ICW4); - outportb(PIC2_COMMAND, ICW1_INIT+ICW1_ICW4); - outportb(PIC1_DATA, pic1); - outportb(PIC2_DATA, pic2); - outportb(PIC1_DATA, 4); - outportb(PIC2_DATA, 2); - outportb(PIC1_DATA, ICW4_8086); - outportb(PIC2_DATA, ICW4_8086); - - outportb(PIC1_DATA, a1); - outportb(PIC2_DATA, a2); -}; + outportb(PIC1_COMMAND, ICW1_INIT+ICW1_ICW4); //0x20, 0x10+0x01 00010001b + outportb(PIC2_COMMAND, ICW1_INIT+ICW1_ICW4); //0xA0, 0x10+0x01 00010001b + outportb(PIC1_DATA, pic1); //0x21, pic1 + outportb(PIC2_DATA, pic2); //0xA1, pic2 + outportb(PIC1_DATA, 4); //0x21, 0x04 00000100b + outportb(PIC2_DATA, 2); //0xA1, 0x02 00000010b + outportb(PIC1_DATA, ICW4_8086); //0x21, 0x01 00000001b + outportb(PIC2_DATA, ICW4_8086); //0xA1, 0x01 00000001b + + outportb(PIC1_DATA, a1); //0x21 + outportb(PIC2_DATA, a2); //0xA1 +} + +inline void pic1_mask(byte mask) +{ + outportb(PIC1_DATA, mask); //0x21, maskfield *OCW1* +} + +inline void pic2_mask(byte mask) +{ + outportb(PIC2_DATA, mask); //0xA1, maskfield *OCW1* +} inline void restart() { @@ -66,6 +76,16 @@ inline void eoi() outportb(0x20, 0x20); //EOI } +inline void eoi2() +{ + outportb(0xA0, 0x20); + outportb(0x20, 0x20); +} + + + + + diff --git a/functions.h b/functions.h index 7ad6b1d..22902fe 100644 --- a/functions.h +++ b/functions.h @@ -11,7 +11,10 @@ void enable_ints(); void disable_ints(); inline void restart(); void remap_pics(int pic1, int pic2); +inline void pic1_mask(byte mask); +inline void pic2_mask(byte mask); inline void eoi(); +inline void eoi2(); diff --git a/kernel.c b/kernel.c index eee0708..f14d7ed 100644 --- a/kernel.c +++ b/kernel.c @@ -14,22 +14,22 @@ #include "video.h" #include "mm.h" #include "keyboard.h" +#include "mouse.h" void isr(dword num); void k_init(); +#include "mouse.c" #include "keyboard.c" #include "mm.c" #include "functions.c" #include "video.c" dword timer = 0; -dword index = 0; -dword keepgoing = 1; -dword addresses[256]; void k_init() { + console_cls(); remap_pics(0x20, 0x28); //set timer : 2e9c = 100hz outportb(0x43, 0x34); @@ -47,11 +47,32 @@ void k_init() video_vert(10, 10, 16, 0x00ffff00); //should be yellow 'H' video_horiz(13, 10, 14, 0x00ffff00); video_vert(14, 10, 16, 0x00ffff00); + + video_horiz(10, 17, 21, 0x00ffff00); + video_vert(19, 10, 16, 0x00ffff00); + video_horiz(16, 17, 21, 0x00ffff00); + + int a, b; + for (a = 0; a < 256; a++) + { + for (b = 0; b < 256; b++) + { + video_pset(a+5, b+30, (a<<16)|(b<<8)); + video_pset(a+270, b+30, (a<<8)|(b)); + video_pset(a+535, b+30, (a<<16)|(b)); + + video_pset(a+5, b+290, (a<<16)|(b<<8)|0x000000ff); + video_pset(a+270, b+290, (a<<8)|(b)|0x00ff0000); + video_pset(a+535, b+290, (a<<16)|(b)|0x0000ff00); + } + } mm_init(); + mouse_enableData(); enable_ints(); - console_cls(); printf("Memory available to OS: %d MB (Bytes: %d)\n", mm_totalmem/0x100000, mm_totalmem); + pic1_mask(0); //unmask IRQ's 0-7 + pic2_mask(0); //unmask IRQ's 8-15 dword key = 0; for (;;) { @@ -67,37 +88,18 @@ void isr(dword num) case 0x20: // IRQ0 - timer interrupt timer++; (*(byte *)0xb8000)++; - if ((timer%25)==0) - { - if (keepgoing) - { - addresses[index] = (dword) mm_palloc(256, KERNEL_PID); - printf("Addr: 0x%x\tEntries:\t%d\n", addresses[index], mm_freeentries()); - if (addresses[index] == 0) - { - index = -1; - keepgoing = 0; - } - index++; - } - else - { - printf("Freeing %x\t", addresses[index]); - addresses[index] = mm_pfree((void *)addresses[index]); - printf("Free:\t%d\tEntries:\t%d\n", addresses[index], mm_freeentries()); - if (addresses[index] != 0) - { - index = -1; - keepgoing = 1; - } - index++; - } - } eoi(); break; case 0x21: // IRQ1 - keyboard interrupt isr_keyboard(); //isr_keybard() takes care of calling eoi() break; + case 0x2C: // IRQ12 - PS/2 mouse + printf("InB: %x, %x, %x", inportb(0x60), inportb(0x60), inportb(0x60)); + eoi2(); + break; + default: + printf("Interrupt %d (0x%x) Unhandled!!\n", num, num); + break; } } diff --git a/keyboard.c b/keyboard.c index 5170a2f..689c81f 100644 --- a/keyboard.c +++ b/keyboard.c @@ -26,6 +26,7 @@ const byte SCAN2ASCIISHIFT[128] = "\000\033!@#$%^&*()_+\010\011QWERTYUIOP{}\n\00 void isr_keyboard() { kbdScan = inportb(0x60); + //printf("\nKEYBOARD INTERRUPT: 0x%x", kbdScan); byte inState = inportb(0x61); outportb(0x61, inState|0x80); outportb(0x61, inState); diff --git a/mouse.c b/mouse.c new file mode 100644 index 0000000..c5c3549 --- /dev/null +++ b/mouse.c @@ -0,0 +1,19 @@ +// mouse.c +// 10/03/03 +// Author: Josh Holtrop + + + +void mouse_enableData() +{ + outportb(0x64, 0x60); + outportb(0x60, 0x03); + + outportb(0x64, 0xA8); //enable mouse port + + outportb(0x64, 0xD4); //send command to mouse, not kbd + outportb(0x60, 0xF4); //enable data reporting +// outportb(0x60, 0xFA); +// inportb(0x60); //get ACK off 0x60 port +// outportb(0x60, 0xFF); //mouse reset +} diff --git a/mouse.h b/mouse.h new file mode 100644 index 0000000..9025f25 --- /dev/null +++ b/mouse.h @@ -0,0 +1,10 @@ +// mouse.h +// 10/03/03 +// Author: Josh Holtrop + + +void mouse_enableData(); + + + + diff --git a/video.c b/video.c index 0a4622c..4fa1a30 100644 --- a/video.c +++ b/video.c @@ -134,7 +134,7 @@ void video_psetp(int pixel, dword color) switch(video_mode.BitsPerPixel) { case 16: - vid_ptr16[pixel] = ((color&0xFF)>>3) | ((((color>>8)&0xFF)>>2)<<6) | ((((color>>16)&0xFF)>>3)<<11); + 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)>>3)<<5) | ((((color>>16)&0xFF)>>3)<<10); break; case 24: