Code: Select all
gets(unsigned char *string)
{
int strcounter = 0;
while (1)
{
scancode = inportb(0x60);
if(scancode != '\n')
{
putch(kbdus[scancode]);
string[strcounter] =scancode;
strcounter++;
}
else
return;
}
}
Code: Select all
gets(unsigned char *string)
{
int strcounter = 0;
while (1)
{
scancode = inportb(0x60);
if(scancode != '\n')
{
putch(kbdus[scancode]);
string[strcounter] =scancode;
strcounter++;
}
else
return;
}
}
Code: Select all
void putch(unsigned char c)
{
unsigned short *where;
unsigned att = attrib << 8;
/* Handle a backspace, by moving the cursor back one space */
if(c == 0x08)
{
if(csr_x != 0)
{
where = textmemptr + (csr_y * 80 + csr_x-1);
*where = 0x20 | att;
csr_x--;
}
}
/* Handles a tab by incrementing the cursor's x, but only
* to a point that will make it divisible by 8 */
else if(c == 0x09)
{
csr_x = (csr_x + 8) & ~(8 - 1);
}
/* Handles a 'Carriage Return', which simply brings the
* cursor back to the margin */
else if(c == '\r')
{
csr_x = 0;
}
/* We handle our newlines the way DOS and the BIOS do: we
* treat it as if a 'CR' was also there, so we bring the
* cursor to the margin and we increment the 'y' value */
else if(c == '\n')
{
csr_x = 0;
csr_y++;
}
/* Any character greater than and including a space, is a
* printable character. The equation for finding the index
* in a linear chunk of memory can be represented by:
* Index = [(y * width) + x] */
else if(c >= ' ')
{
where = textmemptr + (csr_y * 80 + csr_x);
*where = c | att; /* Character AND attributes: color */
csr_x++;
}
/* If the cursor has reached the edge of the screen's width, we
* insert a new line in there */
if(csr_x >= 80)
{
csr_x = 0;
csr_y++;
}
Code: Select all
gets(unsigned char *string)
{
int strcounter = 0;
while (1)
{
scancode = inportb(0x60);
if(scancode != '\n')
{
putch(kbdus[scancode]);
string[strcounter] =scancode;
strcounter++;
}
else
return;
}
}
Code: Select all
scancode = kbdus[inportb(0x60)];
Code: Select all
while (! (inportb(0x64) & 0x1) );
Code: Select all
gets(unsigned char *string)
{
int strcounter = 0;
while (1)
{
while (! (inportb(0x64) & 0x1) )
;
scancode = kbdus[inportb(0x60)];
if(scancode != '\n')
{
putch(scancode);
string[strcounter] =scancode;
strcounter++;
}
else
return;
}
}
Code: Select all
while (! (inportb(0x64) & 0x1) ) ;
Code: Select all
char *medo;
puts("type something:");
gets(medo);
puts("\n");
puts(medo);
Code: Select all
void puts(unsigned char *text)
{
int i;
for (i = 0; i < strlen(text); i++)
{
putch(text[i]);
}
}
Code: Select all
size_t strlen(const char *str)
{
size_t retval;
for(retval = 0; *str != '\0'; str++) retval++;
return retval;
}
Code: Select all
char medo[256];
puts("type something:");
gets(medo,256);
puts("\n");
puts(medo);
Code: Select all
gets(unsigned char *string)
{
int strcounter = 0;
while (1)
{
while (! (inportb(0x64) & 0x1) );
scancode = kbdus[inportb(0x60)];
if(scancode != '\n'&&)
{
putch(scancode);
*string=scancode;
*string++;
}
else
*string++;
*string = '\0';
return *string;
}
}
Code: Select all
gets( unsigned char* string )
{
while( 1 )
{
while( ! (inportb(0x64) & 0x1) );
unsigned char key = kbdus[ inportb( 0x60 ) ];
if( key != '\n' )
{
putch( key );
*string++ = key;
}
else
{
*string++ = 0; // null char at end of string
return;
}
}
}
Code: Select all
gets(unsigned char *string)
{
int strcounter = 0;
while (1)
{
while (! (inportb(0x64) & 0x1) );
scancode = kbdus[inportb(0x60)];
switch(scancode)
{
case '\n':
*string++ = 0;
return *string;
break;
default:
putch(scancode);
*string ++ = scancode;
break;
}
}
}
Code: Select all
/* bkerndev - Bran's Kernel Development Tutorial
* By: Brandon F. ([email protected])
* Desc: Keyboard driver
*
* Notes: No warranty expressed or implied. Use at own risk. */
#include <system.h>
/* KBDUS means US Keyboard Layout. This is a scancode table
* used to layout a standard US keyboard. I have left some
* comments in to give you an idea of what key is what, even
* though I set it's array index to 0. You can change that to
* whatever you want using a macro, if you wish! */
unsigned char scancode;
unsigned char kbdus[128] =
{
0, 27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */
'9', '0', '-', '=', '\b', /* Backspace */
'\t', /* Tab */
'q', 'w', 'e', 'r', /* 19 */
't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', /* Enter key */
0, /* 29 - Control */
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* 39 */
'\'', '`', 0, /* Left shift */
'\\', 'z', 'x', 'c', 'v', 'b', 'n', /* 49 */
'm', ',', '.', '/', 0, /* Right shift */
'*',
0, /* Alt */
' ', /* Space bar */
0, /* Caps lock */
0, /* 59 - F1 key ... > */
0, 0, 0, 0, 0, 0, 0, 0,
0, /* < ... F10 */
0, /* 69 - Num lock*/
0, /* Scroll Lock */
0, /* Home key */
0, /* Up Arrow */
0, /* Page Up */
'-',
0, /* Left Arrow */
0,
0, /* Right Arrow */
'+',
0, /* 79 - End key*/
0, /* Down Arrow */
0, /* Page Down */
0, /* Insert Key */
0, /* Delete Key */
0, 0, 0,
0, /* F11 Key */
0, /* F12 Key */
0, /* All other keys are undefined */
};
/* Handles the keyboard interrupt */
void keyboard_handler(struct regs *r)
{
/* Read from the keyboard's data buffer */
scancode = inportb(0x60);
/* If the top bit of the byte we read from the keyboard is
* set, that means that a key has just been released */
if (scancode & 0x80)
{
/* You can use this one to see if the user released the
* shift, alt, or control keys... */
}
else
{
/* Here, a key was just pressed. Please note that if you
* hold a key down, you will get repeated key press
* interrupts. */
/* Just to show you how this works, we simply translate
* the keyboard scancode into an ASCII value, and then
* display it to the screen. You can get creative and
* use some flags to see if a shift is pressed and use a
* different layout, or you can add another 128 entries
* to the above layout to correspond to 'shift' being
* held. If shift is held using the larger lookup table,
* you would add 128 to the scancode when you look for it */
putch(kbdus[scancode]);
}
}
/* Installs the keyboard handler into IRQ1 */
void keyboard_install()
{
irq_install_handler(1, keyboard_handler);
}
gets(unsigned char *string)
{
int strcounter = 0;
while (1)
{
while (! (inportb(0x64) & 0x1) );
scancode = kbdus[inportb(0x60)];
switch(scancode)
{
case '\n':
*string++ = 0;
return *string;
break;
default:
putch(scancode);
*string ++ = scancode;
break;
}
}
}
Code: Select all
/* bkerndev - Bran's Kernel Development Tutorial
* By: Brandon F. ([email protected])
* Desc: Keyboard driver
*
* Notes: No warranty expressed or implied. Use at own risk. */
#include <system.h>
// -1 when no keys, >= 0 when keys
volatile char keybuff = -1;
/* KBDUS means US Keyboard Layout. This is a scancode table
* used to layout a standard US keyboard. I have left some
* comments in to give you an idea of what key is what, even
* though I set it's array index to 0. You can change that to
* whatever you want using a macro, if you wish! */
unsigned char scancode;
unsigned char kbdus[128] =
{
0, 27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */
'9', '0', '-', '=', '\b', /* Backspace */
'\t', /* Tab */
'q', 'w', 'e', 'r', /* 19 */
't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', /* Enter key */
0, /* 29 - Control */
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* 39 */
'\'', '`', 0, /* Left shift */
'\\', 'z', 'x', 'c', 'v', 'b', 'n', /* 49 */
'm', ',', '.', '/', 0, /* Right shift */
'*',
0, /* Alt */
' ', /* Space bar */
0, /* Caps lock */
0, /* 59 - F1 key ... > */
0, 0, 0, 0, 0, 0, 0, 0,
0, /* < ... F10 */
0, /* 69 - Num lock*/
0, /* Scroll Lock */
0, /* Home key */
0, /* Up Arrow */
0, /* Page Up */
'-',
0, /* Left Arrow */
0,
0, /* Right Arrow */
'+',
0, /* 79 - End key*/
0, /* Down Arrow */
0, /* Page Down */
0, /* Insert Key */
0, /* Delete Key */
0, 0, 0,
0, /* F11 Key */
0, /* F12 Key */
0, /* All other keys are undefined */
};
/* Handles the keyboard interrupt */
void keyboard_handler(struct regs *r)
{
/* Read from the keyboard's data buffer */
scancode = inportb(0x60);
/* If the top bit of the byte we read from the keyboard is
* set, that means that a key has just been released */
if (scancode & 0x80)
{
/* You can use this one to see if the user released the
* shift, alt, or control keys... */
}
else
{
/* Here, a key was just pressed. Please note that if you
* hold a key down, you will get repeated key press
* interrupts. */
/* Just to show you how this works, we simply translate
* the keyboard scancode into an ASCII value, and then
* display it to the screen. You can get creative and
* use some flags to see if a shift is pressed and use a
* different layout, or you can add another 128 entries
* to the above layout to correspond to 'shift' being
* held. If shift is held using the larger lookup table,
* you would add 128 to the scancode when you look for it */
// putch(kbdus[scancode]);
keybuff = kbdus[scancode];
}
}
/* Installs the keyboard handler into IRQ1 */
void keyboard_install()
{
irq_install_handler(1, keyboard_handler);
}
int gets( unsigned char* string )
{
int n = 0;
while( 1 )
{
while( keybuff == -1 );
char tmp = keybuff; // in case another IRQ fires in the mean time
if( tmp == '\n' )
{
*string++ = 0;
return n;
}
else
{
putch( tmp );
*string++ = tmp;
n++;
}
}
return -1; // something weird happened
}