From 5da602b1626ddd0c97fc2720ffc4627086a3b0c8 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 6 Oct 2003 22:00:00 -0400 Subject: [PATCH] Import backup from 2003-10-06 --- kernel.c | 4 ++-- mouse.c | 51 ++++++++++++++++++++++++++++++++++++++++++++------- mouse.h | 9 ++++++++- video.c | 4 ---- video.h | 7 +++++++ 5 files changed, 61 insertions(+), 14 deletions(-) diff --git a/kernel.c b/kernel.c index f14d7ed..cb80b2d 100644 --- a/kernel.c +++ b/kernel.c @@ -68,7 +68,7 @@ void k_init() } mm_init(); - mouse_enableData(); + mouse_init(); enable_ints(); printf("Memory available to OS: %d MB (Bytes: %d)\n", mm_totalmem/0x100000, mm_totalmem); pic1_mask(0); //unmask IRQ's 0-7 @@ -94,7 +94,7 @@ void isr(dword num) 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)); + isr_mouse(); eoi2(); break; default: diff --git a/mouse.c b/mouse.c index c5c3549..159554e 100644 --- a/mouse.c +++ b/mouse.c @@ -3,17 +3,54 @@ // Author: Josh Holtrop - -void mouse_enableData() +void mouse_init() { - outportb(0x64, 0x60); - outportb(0x60, 0x03); + outportb(0x64, 0x20); //tell keyboard controller we are going to read keyboard controller command byte + byte temp = inportb(0x60); //read keyboard controller command byte + outportb(0x64, 0x60); //tell keyboard controller we are going to write keyboard controller command byte + outportb(0x60, 0x03 | (temp&0x40)); //write keyboard controller command byte: enable mouse/keyboard ints, include original XLATE bit from temp (bit6) 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 + + //outportb(0x64, 0xD4); + //outportb(0x60, 0xE7); //scaling 2:1 } + + + +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; + mouse_bytesRead++; + if (mouse_bytesRead == 3) //complete packet received + { + mouse_bytesRead = 0; + int adjx = (char) mouse_inbuffer[1]; + int adjy = (char) mouse_inbuffer[2]; + mouse_x += adjx; + mouse_y -= adjy; //-= because screen y coordinates are opposite mouse y coordinates + if (mouse_inbuffer[0] & 0x01) //left button + { + video_pset(VXR/2+mouse_x, VYR/2+mouse_y, 0x00FFFFFF); + printf("X: %d, Y: %d\n", mouse_x, mouse_y); + } + else + { + video_pset(VXR/2+mouse_x, VYR/2+mouse_y, 0x00000000); + printf("X: %d, Y: %d\n", mouse_x, mouse_y); + } + } +} + + + + + diff --git a/mouse.h b/mouse.h index 9025f25..e610d57 100644 --- a/mouse.h +++ b/mouse.h @@ -3,7 +3,14 @@ // Author: Josh Holtrop -void mouse_enableData(); +int mouse_x = 0; +int mouse_y = 0; +int mouse_bytesRead = 0; +byte mouse_inbuffer[16]; + +void mouse_init(); +void isr_mouse(); + diff --git a/video.c b/video.c index 4fa1a30..6566d02 100644 --- a/video.c +++ b/video.c @@ -1,10 +1,6 @@ //video.c // 08/13/03 Josh Holtrop -ModeInfoBlock video_mode; -byte *vid_ptr24; -word *vid_ptr16; -dword *vid_ptr32; void video_init(ModeInfoBlock *mib) { diff --git a/video.h b/video.h index 46e4f64..527694d 100644 --- a/video.h +++ b/video.h @@ -1,6 +1,7 @@ //video.h // 08/18/03 Josh Holtrop + 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); @@ -52,6 +53,12 @@ typedef struct{ byte Reserved[206]; } ModeInfoBlock; +ModeInfoBlock video_mode; +byte *vid_ptr24; +word *vid_ptr16; +dword *vid_ptr32; + +