Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

made the prototype of input

  • Loading branch information...
commit fb25abc2f34dcab86348e0365a49145878a725da 1 parent cbb58ec
fleuria authored
1  .bochsrc
View
@@ -30,6 +30,7 @@ private_colormap: enabled=0
fullscreen: enabled=0
screenmode: name="sample"
keyboard_mapping: enabled=0, map=
+keyboard_type: at
debug_symbols: file=main.sym
1  Rakefile
View
@@ -104,6 +104,7 @@ cfiles = [
#
'src/chr/vga.c',
'src/chr/keybd.c',
+ 'src/chr/tty.c',
#
'src/mm/pm.c',
'src/mm/vm.c',
3  main.ld
View
@@ -1,5 +1,7 @@
ENTRY(main)
SECTIONS {
+ __bios__ = 0xa0000;
+ vgamem = 0xb8000;
.text 0x100000 : {
__kbegin__ = .;
__code__ = .;
@@ -17,6 +19,5 @@ SECTIONS {
*(.bss);
. = ALIGN(4096);
}
- vgamem = 0xb8000;
__kend__ = .;
}
4 src/blk/conf.c
View
@@ -14,3 +14,7 @@ struct bdevsw bdevsw[NBLKDEV] = {
{ &nulldev, &nulldev, &hd_request, &hdtab }
};
+struct cdevsw cdevsw[NCHRDEV] = {
+ { 0, }, /* NODEV */
+};
+
66 src/chr/keybd.c
View
@@ -14,24 +14,78 @@
*
* */
+static uint mode = 0;
+
+/* translate into flags which indicated the satus of shift, ctrl & alt. */
+char shift(char sc){
+ char ch = sc & 0x7f;
+
+ if (mode & E0ESC) {
+ switch (ch) {
+ case 0x1D: return CTRL;
+ case 0x38: return ALT;
+ }
+ }
+ else {
+ switch(ch) {
+ case 0x2A:
+ case 0x36: return SHIFT;
+ case 0x1D: return CTRL;
+ case 0x38: return ALT;
+ }
+ }
+ return 0;
+}
+
/*
* Each keyboard interrupt came along with a 8bit scan code (via inb(KB_DATA)), if bit 8 is
* set, it's releasing a key, else pressing.
* */
int do_keybd_intr(struct trap *tf){
- uchar sc, ch;
+ uchar sc, ch, m;
+ char *map = keybd_map;
// got no data
if ((inb(KB_STAT) & KB_STAT_DIB)==0){
return -1;
}
sc = inb(KB_DATA);
- // it's released
- if (sc & 0x80) {
- return 0;
+
+ // check E0ESC
+ if (sc == 0xE0)
+ mode |= E0ESC;
+
+ // check shift, ctrl and alt
+ if (m = shift(sc)) {
+ if (sc & 0x80) {
+ mode &= ~m;
+ return 0;
+ }
+ mode |= m;
+ }
+ map = (mode & SHIFT)? shift_map: keybd_map;
+ ch = map[sc & 0x7f];
+
+ if (mode & CTRL) {
+ switch(ch){
+ case 'c': ch = CINTR;
+ case 'd': ch = CEOF;
+ case 'x': ch = CKILL;
+ case 'q': ch = CSTART;
+ case 's': ch = CSTOP;
+ case 'z': ch = CSUSP;
+ case '\\': ch = CQUIT;
+ }
+ }
+
+ // on pressed
+ if ((sc & 0x80)==0) {
+ tty_input(&tty0, ch);
+ }
+ // on released
+ else {
+ mode &= ~E0ESC;
}
- ch = sc & 0x7f;
- putch(keybd_map[ch]);
}
void keybd_init(){
20 src/chr/tty.c
View
@@ -6,6 +6,10 @@
#include <tty.h>
#include <keybd.h>
+struct tty tty0;
+
+/* ---------------------------------------------- */
+
int cputc(struct clist *cp, char ch){
}
@@ -14,10 +18,22 @@ char cgetc(struct clist *cp){
/* ---------------------------------------------- */
-int ttread(struct tty *tp){
+/*
+ * Place a character on raw TTY input queue, do
+ * */
+int tty_input(struct tty *tp, char ch){
+ putch(ch);
+}
+
+int tty_canon(struct tty *tp){
}
-int ttcanon(struct tty *tp){
+int tty_output(struct tty *tp, char ch){
+}
+
+/* ---------------------------------------------- */
+
+int ttread(struct tty *tp){
}
int ttwrite(struct tty *tp){
10 src/chr/vga.c
View
@@ -16,16 +16,16 @@ struct vchar {
char vc_bgcolor:4;
};
-/* VGA is a memory mapping device, you may view it as an 80x25 array
- * whom located at 0x8b000(in main.ld).
- * */
-extern struct vchar vgamem[25][80];
-
#define VGA_WHITE 0x07
#define VGA_BLACK 0x00
#define VC_BLANK (' '|VGA_WHITE<<8)
+/* VGA is a memory mapping interface, you may view it as an 80x25 array
+ * which located at 0x8b000 (defined in main.ld).
+ * */
+extern struct vchar vgamem[25][80];
+
static int px=0, py=0;
/* adjust the position of cursor */
27 src/inc/keybd.h
View
@@ -39,5 +39,32 @@ static uchar keybd_map[256] = {
[0xD2] KEY_INS, [0xD3] KEY_DEL
};
+static uchar shift_map[256] = {
+ NUL, 033, '!', '@', '#', '$', '%', '^', // 0x00
+ '&', '*', '(', ')', '_', '+', '\b', '\t',
+ 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', // 0x10
+ 'O', 'P', '{', '}', '\n', NUL, 'A', 'S',
+ 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', // 0x20
+ '"', '~', NUL, '|', 'Z', 'X', 'C', 'V',
+ 'B', 'N', 'M', '<', '>', '?', NUL, '*', // 0x30
+ NUL, ' ', NUL, NUL, NUL, NUL, NUL, NUL,
+ NUL, NUL, NUL, NUL, NUL, NUL, NUL, '7', // 0x40
+ '8', '9', '-', '4', '5', '6', '+', '1',
+ '2', '3', '0', '.', NUL, NUL, NUL, NUL, // 0x50
+ [0x9C] '\n', // KP_Enter
+ [0xB5] '/', // KP_Div
+ [0xC8] KEY_UP, [0xD0] KEY_DN,
+ [0xC9] KEY_PGUP, [0xD1] KEY_PGDN,
+ [0xCB] KEY_LF, [0xCD] KEY_RT,
+ [0x97] KEY_HOME, [0xCF] KEY_END,
+ [0xD2] KEY_INS, [0xD3] KEY_DEL
+};
+
+/* status of shift, ctrl & alt */
+#define SHIFT 0x1
+#define CTRL 0x2
+#define ALT 0x4
+#define E0ESC 0x8
+#define CAPSLOCK 0x10
#endif
2  src/inc/param.h
View
@@ -17,6 +17,8 @@ typedef unsigned int uint;
#define NSEG 6
#define NBUF (0x200000/BSIZE) /* buffers take 2mb */
#define NBLKDEV 2
+#define NCHRDEV 2
+#define NCCS 17
#define NINODE 128
#define NFILE 128
#define NOFILE 16
26 src/inc/tty.h
View
@@ -1,17 +1,15 @@
#ifndef TTY_H
#define TTY_H
-struct cblock {
- char c_body[60];
- struct cblock *c_next;
-};
+#define NCCS 17
+#define TTY_BUFSIZ 1024
struct clist {
- uint c_num;
- struct cblock *c_first;
+ char *c_head;
+ char *c_tail;
+ char c_buf[TTY_BUFSIZ];
};
-
struct tty {
int t_flag;
int t_dev;
@@ -20,4 +18,18 @@ struct tty {
struct clist t_outq;
};
+extern struct tty tty0;
+
+/* control characters */
+#define CINTR 003 /* ctrl-C */
+#define CQUIT 034 /* ctrl-\ */
+#define CERASE 0177 /* DEL, BS */
+#define CKILL 025 /* ctrl-X */
+#define CEOF 004 /* ctrl-D */
+#define CEOL 00
+#define CSTART 021 /* ctrl-Q */
+#define CSTOP 023 /* ctrl-S */
+#define CSUSP 032 /* ctrl-Z */
+
#endif
+
Please sign in to comment.
Something went wrong with that request. Please try again.