您现在的位置是:主页 > news > 网站设计建设公司/山东省住房和城乡建设厅

网站设计建设公司/山东省住房和城乡建设厅

admin2025/5/7 7:28:58news

简介网站设计建设公司,山东省住房和城乡建设厅,长沙seo优化多少钱,开发公司对物业公司的处罚通告范文一、准备工作(一)硬件设置计算机中鼠标的中断硬件组成,在前面的章节已经做了介绍:从图中可以明显看到,鼠标是接在从片的4号端口上的,而从片又是接在主片的2号端口上的,因此我们第一步就是需要打…

网站设计建设公司,山东省住房和城乡建设厅,长沙seo优化多少钱,开发公司对物业公司的处罚通告范文一、准备工作(一)硬件设置计算机中鼠标的中断硬件组成,在前面的章节已经做了介绍:从图中可以明显看到,鼠标是接在从片的4号端口上的,而从片又是接在主片的2号端口上的,因此我们第一步就是需要打…

46b43db7b038b9a5a8ce11d66b5993c6.png

一、准备工作

(一)硬件设置

计算机中鼠标的中断硬件组成,在前面的章节已经做了介绍:

903350bd6ead5c2f336d56c53eb03d07.png

从图中可以明显看到,鼠标是接在从片的4号端口上的,而从片又是接在主片的2号端口上的,因此我们第一步就是需要打开这两个端口的中断:

        io_out8(PIC0_IMR, 0xf9); /* 开启键盘和鼠标中断主芯片设置:(11111001) */io_out8(PIC1_IMR, 0xef); /* 从芯片设置:(11101111) */

之前,我们对键盘和鼠标中断号已经做了定义,分别是0X21和0X2C。那我们鼠标驱动的主要任务其实就是编写0X2C号中断的中断服务程序。另外,我们需要将中断号0X2C的中断服务程序注册到IDT表中,这个方法和键盘中断没有差异。

鼠标电路硬件上其实是从属于键盘电路的,因此我们还需要从硬件上做两个事情:

1.启用鼠标电路,程序中用init_keyboard()函数实现。

2.启动鼠标设备,程序中用 enable_mouse(&mdec)函数实现。

(二)鼠标数据接收

鼠标与CPU数据交互上和键盘不相同,因为鼠标的数据量远远大于键盘,键盘无非就是一个按键和释放,而鼠标有5种数据:点击左键、点击右键、滑动中间键、X坐标位移和Y坐标位移。所以鼠标和CPU是采用一种异步通信的方式:一次鼠标操作分3次握手完成传递,每次传递一个字节,第1个字节表示的是鼠标点击数据、第2个字节和第3个字节表示的是X坐标位移和Y坐标位移。那么第1个字节就很关键,它的定义是最低3位分别表示点击左中右键。我们需要在中断服务程序里用逻辑来区分这3个阶段,以保证能收到的数据不乱序。方法一般是:首先判断鼠标送来的数据知否在正常范围内来判断是否是第一个字节,因为超出合理范围就肯定不是第一字节。具体方法这个可以看书上的教程:

eb410982a7c0239e4b220ccaba0a6b4b.png

711896c6931019c0456575244413adfb.png

二、运行效果

fd23d5ad8b75e6dd42f2cb66f73bf696.png
桌面实时显示键盘输入和鼠标位置坐标

三、程序代码

1.Main.c

void Main(void)
{sysinit();     /*操作系统运行准备*/intservice();  /*外设中断服务准备(键盘鼠标)*/desktop();     /*桌面显示*/while(1) {;}
}

2.Desktop.c

关键点:

(1)struct BOOTINFO *binfo:这个数据结构是整个操作系统的基础信息,其作用就是从内存固定物理地址0x7000处开始读出分辨率、键盘按键状态、显卡内存地址等在前面汇编程序部分写进去的基础信息。

#define BOOTBASE                0x7000
struct BOOTINFO {char cyls, leds, vmode, reserve;short scrnx, scrny;char *vram;int  asmlen;
};

(2)extern struct FIFO8 keyfifo; extern struct FIFO8 mousefifo; keyfifo和mousefifo分别为32字节的键盘数据输入缓冲区和128字节的鼠标数据输入缓冲区。必须用关键词extern来定义变量,是因为这两个缓冲区是在Keryboard.c和Mouse.c中定义的,那么这里引用的作用显然是只管从缓冲区读出数据!FIFO8实际上只是一个缓冲区的信息描述符,它用来指向真正的数据缓冲区并做读写控制,真正的数据缓冲区是存放在char keybuf[32],mousebuf[128]这两个数组里面的。

(3)专门定义了一个数据结构struct MOUSE_DEC mdec,用来解析和存储鼠标每次送来的3个字节数据。

#include "Jiangos.h"#include <stdio.h>void desktop(void)
{struct BOOTINFO *binfo = (struct BOOTINFO *) BOOTBASE;init_palette();init_screen(binfo->vram, binfo->scrnx, binfo->scrny);static char c=7;	/*---显示字符串---*/putfont_Jiang(binfo->vram,binfo->scrnx, 10,10, COL8_FFFFFF);putfonts8_asc(binfo->vram, binfo->scrnx,10,40, COL8_FFFFFF, "Jiang OS 13572468");line(binfo->vram,binfo->scrnx,60,c); /*---显示变量---*/	char s[40];                            sprintf(s, "VRAMX=%d", binfo->scrnx);putfonts8_asc(binfo->vram, binfo->scrnx, 16, 64, COL8_FFFFFF, s);sprintf(s, "VRAMY=%d", binfo->scrny);putfonts8_asc(binfo->vram, binfo->scrnx, 100, 64, COL8_FFFFFF, s);sprintf(s, "VRAMAddr=0X %X", binfo->vram);putfonts8_asc(binfo->vram, binfo->scrnx, 184, 64, COL8_FFFFFF, s);line(binfo->vram,binfo->scrnx,84,c); /*---显示鼠标---*/char mcursor[256];int mx, my;mx = (binfo->scrnx - 16) / 2;           /*鼠标坐标位置*/my = (binfo->scrny - 28 - 16) / 2;init_mouse_cursor8(mcursor, COL8_3366CC);putblock8_8(binfo->vram, binfo->scrnx, 16, 16, mx, my, mcursor, 16);/*---键盘鼠标驱动---*/char keybuf[32],mousebuf[128];int i;extern struct FIFO8 keyfifo;extern struct FIFO8 mousefifo;fifo8_init(&keyfifo, 32, keybuf);fifo8_init(&mousefifo, 128, mousebuf);struct MOUSE_DEC mdec;init_keyboard();        /*开启鼠标电路*/enable_mouse(&mdec);    /*开启鼠标设备*/ for (;;) {io_cli();if (fifo8_status(&keyfifo) + fifo8_status(&mousefifo) == 0) {io_stihlt();} else {if (fifo8_status(&keyfifo) != 0) {i = fifo8_get(&keyfifo);io_sti();sprintf(s, "%02X---Keyborad OK!", i);boxfill8(binfo->vram, binfo->scrnx, COL8_3366CC,  0, 88, 15, 103);putfonts8_asc(binfo->vram, binfo->scrnx, 0, 88, COL8_FFFFFF, s);line(binfo->vram,binfo->scrnx,108,c);} else if (fifo8_status(&mousefifo) != 0) {i = fifo8_get(&mousefifo);io_sti();if (mouse_decode(&mdec, i) != 0) {sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y);if ((mdec.btn & 0x01) != 0) {s[1] = 'L';}if ((mdec.btn & 0x02) != 0) {s[3] = 'R';}if ((mdec.btn & 0x04) != 0) {s[2] = 'C';}boxfill8(binfo->vram, binfo->scrnx, COL8_3366CC, 0, 112, 0 + 15 * 8 - 1, 112+15);/*数据显示即将更改,把当前位置的颜色填充为背景色*/putfonts8_asc(binfo->vram, binfo->scrnx, 0, 112, COL8_FFFFFF, s);boxfill8(binfo->vram, binfo->scrnx, COL8_3366CC, mx, my, mx + 15, my + 15); /*鼠标即将挪走,把当前位置的颜色填充为背景色*/line(binfo->vram,binfo->scrnx,132,c);mx += mdec.x;my += mdec.y;if (mx < 0) {mx = 0;}if (my < 0) {my = 0;}if (mx > binfo->scrnx - 16) {mx = binfo->scrnx - 16;}if (my > binfo->scrny - 16) {my = binfo->scrny - 16;}sprintf(s, "(%3d, %3d)      ---Mouse OK", mx, my);boxfill8(binfo->vram, binfo->scrnx, COL8_3366CC, 200, 112, 200+79, 112+15); /*数据显示即将更改,把当前位置的颜色填充为背景色*/putfonts8_asc(binfo->vram, binfo->scrnx, 200, 112, COL8_FFFFFF, s); putblock8_8(binfo->vram, binfo->scrnx, 16, 16, mx, my, mcursor, 16); /*在新的位置显示出鼠标图形*/line(binfo->vram,binfo->scrnx,132,c);}}}}}void init_mouse_cursor8(char *mouse, char bc){static char cursor[16][16] = {"**************..","*OOOOOOOOOOO*...","*OOOOOOOOOO*....","*OOOOOOOOO*.....","*OOOOOOOO*......","*OOOOOOO*.......","*OOOOOOO*.......","*OOOOOOOO*......","*OOOO**OOO*.....","*OOO*..*OOO*....","*OO*....*OOO*...","*O*......*OOO*..","**........*OOO*.","*..........*OOO*","............*OO*",".............***"};int x, y;for (y = 0; y < 16; y++) {for (x = 0; x < 16; x++) {if (cursor[y][x] == '*') {mouse[y * 16 + x] = COL8_000000;}if (cursor[y][x] == 'O') {mouse[y * 16 + x] = COL8_FFFFFF;}if (cursor[y][x] == '.') {mouse[y * 16 + x] = bc;}}}return;
}void putblock8_8(char *vram, int vxsize, int pxsize,int pysize, int px0, int py0, char *buf, int bxsize)
{int x, y;for (y = 0; y < pysize; y++) {for (x = 0; x < pxsize; x++) {vram[(py0 + y) * vxsize + (px0 + x)] = buf[y * bxsize + x];}}return;
}void init_palette(void)
{static unsigned char table_rgb[18 * 3] = {0x00, 0x00, 0x00,	/*  0 */0xff, 0x00, 0x00,	/*  1 */0x00, 0xff, 0x00,	/*  2 */0xff, 0xff, 0x00,	/*  3 */0x00, 0x00, 0xff,	/*  4 */0xff, 0x00, 0xff,	/*  5 */0x00, 0xff, 0xff,	/*  6 */0xff, 0xff, 0xff,	/*  7 */0xc6, 0xc6, 0xc6,	/*  8 */0x84, 0x00, 0x00,	/*  9 */0x00, 0x84, 0x00,	/* 10 */0x84, 0x84, 0x00,	/* 11 */0x00, 0x00, 0x84,	/* 12 */0x84, 0x00, 0x84,	/* 13 */0x00, 0x84, 0x84,       /*14 */0x84, 0x84, 0x84,	/* 15 */0x33, 0x66, 0xcc,	/* 16 */0x33, 0x66, 0x99	/* 17 */};set_palette(0, 17, table_rgb);
}void set_palette(int start, int end, unsigned char *rgb)
{int i;io_out8(0x03c8, start);for (i = start; i <= end; i++) {io_out8(0x03c9, rgb[0] / 4);io_out8(0x03c9, rgb[1] / 4);io_out8(0x03c9, rgb[2] / 4);rgb += 3;}
}void putfonts8_asc(char *vram, int xsize, int x, int y, char c, unsigned char *s)
{extern char hankaku[4096];for (; *s != 0x00; s++) {putfont8(vram, xsize, x, y, c, hankaku + *s * 16);x += 8;}
}void line(char *vram,int xsize,int y,char c)
{       int i=0;for (i = 0; i <=xsize-1; i++) 
{*(vram + y*xsize + i)=c;}
}void putfont8(char *vram, int xsize, int x, int y, char c, char *font)
{int i;char *p, d /* data */;for (i = 0; i < 16; i++) {p = vram + (y + i) * xsize + x;d = font[i];if ((d & 0x80) != 0) { p[0] = c; }if ((d & 0x40) != 0) { p[1] = c; }if ((d & 0x20) != 0) { p[2] = c; }if ((d & 0x10) != 0) { p[3] = c; }if ((d & 0x08) != 0) { p[4] = c; }if ((d & 0x04) != 0) { p[5] = c; }if ((d & 0x02) != 0) { p[6] = c; }if ((d & 0x01) != 0) { p[7] = c; }}
}void boxfill8(unsigned char *vram, int xsize, unsigned char c, int x0, int y0, int x1, int y1)
{int x, y;for (y = y0; y <= y1; y++) {for (x = x0; x <= x1; x++)vram[y * xsize + x] = c;}
}void init_screen(char *vram, int x, int y)
{boxfill8(vram, x, COL8_3366CC,  0,     0,      x -  1, y - 29);boxfill8(vram, x, COL8_C6C6C6,  0,     y - 28, x -  1, y - 28);boxfill8(vram, x, COL8_FFFFFF,  0,     y - 27, x -  1, y - 27);boxfill8(vram, x, COL8_C6C6C6,  0,     y - 26, x -  1, y -  1);boxfill8(vram, x, COL8_FFFFFF,  3,     y - 24, 59,     y - 24);boxfill8(vram, x, COL8_FFFFFF,  2,     y - 24,  2,     y -  4);boxfill8(vram, x, COL8_848484,  3,     y -  4, 59,     y -  4);boxfill8(vram, x, COL8_848484, 59,     y - 23, 59,     y -  5);boxfill8(vram, x, COL8_000000,  2,     y -  3, 59,     y -  3);boxfill8(vram, x, COL8_000000, 60,     y - 24, 60,     y -  3);boxfill8(vram, x, COL8_848484, x - 47, y - 24, x -  4, y - 24);boxfill8(vram, x, COL8_848484, x - 47, y - 23, x - 47, y -  4);boxfill8(vram, x, COL8_FFFFFF, x - 47, y -  3, x -  4, y -  3);boxfill8(vram, x, COL8_FFFFFF, x -  3, y - 24, x -  3, y -  3);}void putfont_A(char *vram, int xsize, int x, int y, char c)
{char font_A[16] = {0x00, 0x18, 0x18, 0x18, 0x18, 0x24, 0x24, 0x24,0x24, 0x7e, 0x42, 0x42, 0x42, 0xe7, 0x00, 0x00};int i;char *p, d /* data */;for (i = 0; i < 16; i++) {p = vram + (y + i) * xsize + x;d = font_A[i];if ((d & 0x80) != 0) { p[0] = c; }if ((d & 0x40) != 0) { p[1] = c; }if ((d & 0x20) != 0) { p[2] = c; }if ((d & 0x10) != 0) { p[3] = c; }if ((d & 0x08) != 0) { p[4] = c; }if ((d & 0x04) != 0) { p[5] = c; }if ((d & 0x02) != 0) { p[6] = c; }if ((d & 0x01) != 0) { p[7] = c; }}}void putfont_Jiang(char *vram, int xsize, int x, int y, char color)
{char font_Jiang1[16] = {0x00, 0x10, 0x08, 0x04, 0x00, 0x20, 0x10, 0x08,0x04, 0x00, 0x00, 0x04, 0x08, 0x11, 0x20, 0x00};char font_Jiang2[16] = {0x00, 0x00, 0x00, 0x00, 0xf8, 0x20, 0x20, 0x20,0x20, 0x20, 0x20, 0x20, 0x20, 0xfc, 0x00, 0x00};int i;char *p,d1,d2; for (i = 0; i <16; i++) {p = vram  + (y + i) * xsize + x;d1 =  font_Jiang1[i];d2 =  font_Jiang2[i];if ((d1 & 0x80) != 0) { p[0] = color; }if ((d1 & 0x40) != 0) { p[1] = color; }if ((d1 & 0x20) != 0) { p[2] = color; }if ((d1 & 0x10) != 0) { p[3] = color; }if ((d1 & 0x08) != 0) { p[4] = color; }if ((d1 & 0x04) != 0) { p[5] = color; }if ((d1 & 0x02) != 0) { p[6] = color; }if ((d1 & 0x01) != 0) { p[7] = color; }if ((d2 & 0x80) != 0) { p[8] = color; }if ((d2 & 0x40) != 0) { p[9] = color; }if ((d2 & 0x20) != 0) { p[10] = color; }if ((d2 & 0x10) != 0) { p[11] = color; }if ((d2 & 0x08) != 0) { p[12] = color; }if ((d2 & 0x04) != 0) { p[13] = color; }if ((d2 & 0x02) != 0) { p[14] = color; }if ((d2 & 0x01) != 0) { p[15] = color; }}
}

3. Jiangos.h

/*--------Desktop.c----------*/#define BOOTBASE                0x7000
struct BOOTINFO {char cyls, leds, vmode, reserve;short scrnx, scrny;char *vram;int  asmlen;
};#define COL8_000000		0
#define COL8_FF0000		1
#define COL8_00FF00		2
#define COL8_FFFF00		3
#define COL8_0000FF		4
#define COL8_FF00FF		5
#define COL8_00FFFF		6
#define COL8_FFFFFF		7
#define COL8_C6C6C6		8
#define COL8_840000		9
#define COL8_008400		10
#define COL8_848400		11
#define COL8_000084		12
#define COL8_840084		13
#define COL8_008484		14
#define COL8_848484		15
#define COL8_3366CC		16
#define COL8_336699		17/*--------Sysinit.c----------*/
#define kerneladdr              0xc200        /* 内核起始物理地址,fat12格式:0x8000+0x4200*/
#define dataaddr                0x00100000    /* 定义C程序变量数据区地址 1MB处*/
#define datalenpos              0x10          /* C程序机器代码Kernelc.hrb中变量数据区长度的位置*/
#define datapospos              0x14          /* C程序机器代码Kernelc.hrb中变量数据区位置的位置*//*----------Int.c----------*/
#define idtaddr                 0x6000
#define cheaderlen              0x24              /* C程序机器代码Kernelc.hrb文件头长度*/#define IntNO_key               0x21              /*键盘中断号*/
#define IntNO_mouse             0x2c              /*鼠标中断号*//*----------Fifo.c----------*/
struct FIFO8 {unsigned char *buf;int p, q, size, free, flags;
};#define FLAGS_OVERRUN		0x0001/*----------Keyboard.c----------*/
#define PIC0_ICW1		0x0020
#define PIC0_OCW2		0x0020
#define PIC0_IMR		0x0021
#define PIC0_ICW2		0x0021
#define PIC0_ICW3		0x0021
#define PIC0_ICW4		0x0021
#define PIC1_ICW1		0x00a0
#define PIC1_OCW2		0x00a0
#define PIC1_IMR		0x00a1
#define PIC1_ICW2		0x00a1
#define PIC1_ICW3		0x00a1
#define PIC1_ICW4		0x00a1#define PORT_KEYDAT		0x0060
#define PORT_KEYCMD		0x0064#define PORT_KEYSTA		0x0064
#define KEYSTA_SEND_NOTREADY	0x02
#define KEYCMD_WRITE_MODE	0x60
#define KBC_MODE		0x47/*----------Mouse.c----------*/
#define KEYCMD_SENDTO_MOUSE		0xd4
#define MOUSECMD_ENABLE			0xf4struct MOUSE_DEC {unsigned char buf[3], phase;int x, y, btn;
};/*----------naskfunc.nas----------*/
void io_hlt(void);
void io_cli(void);
void io_sti(void);
void io_out8(int port, int data);
void mem_copy(si,di,len);   
void asm_inthandler21(void);
void asm_inthandler2c(void);

4. Keyboard.c

关键点:struct FIFO8 keyfifo。很明显,这是一个写在函数体以外的全局变量,之所以必须要定义成全局变量,是因为这个缓冲区数据需要给读取键盘数据的程序使用(Desktop.c),那么这个程序的作用是只管往缓冲区写键盘输入数据!用的函数是:fifo8_put(&keyfifo, data),一次写一个字节内容。这个变量绝对不能定义在函数体以内,不然它就变成了局部变量,前面我们讲过局部变量只在栈内简短时间生存,一旦函数执行完毕就将消失。这里定义成全局变量,编译程序就会将它写进.data段,程序链接之后就自然的写入到固定内存处(前面章节用大量篇幅讲个这个问题),而这个变量的值会一直保存到整个C程序结束运行为止。

另外,虽然用Static来定义变量也可以保证变量的值保存到整个C程序结束运行为止,但是这里也绝对不能使用Static,因为Static定义变量还有一个作用就是仅限于本源程序使用,同在一个工程里面的其它源程序不能使用(不能跨程序共享),显然这也是达不到我们的要求。

#include "Jiangos.h"struct FIFO8 keyfifo;void inthandler21(void)   /*键盘中断服务程序*/
{ /*struct BOOTINFO *binfo = (struct BOOTINFO *) BOOTBASE;*//*putfonts8_asc(binfo->vram, binfo->scrnx, 0, 0, 7, "INT 21 (IRQ-1) : PS/2 keyboard");*/unsigned char data;io_out8(PIC0_OCW2, 0x61);	 data = io_in8(PORT_KEYDAT);fifo8_put(&keyfifo, data);}void wait_KBC_sendready(void)
{for (;;) {if ((io_in8(PORT_KEYSTA) & KEYSTA_SEND_NOTREADY) == 0) {break;}}return;
}void init_keyboard(void)
{wait_KBC_sendready();io_out8(PORT_KEYCMD, KEYCMD_WRITE_MODE);wait_KBC_sendready();io_out8(PORT_KEYDAT, KBC_MODE);return;
}

5. Mouse.c

关键点:struct FIFO8 mousefifo。这也是一个写在函数体以外的全局变量,之所以必须要定义成全局变量,是因为这个缓冲区数据需要给读取鼠标输入数据的程序使用(Desktop.c),那么这个程序的作用是只管往缓冲区写鼠标输入数据!用的函数是:fifo8_put(&mousefifo, data),一次写一个字节内容。另外用函数int mouse_decode(struct MOUSE_DEC *mdec, unsigned char dat)用来控制鼠标3个字节输入数据的解析和存储。

#include "Jiangos.h"struct FIFO8 mousefifo;void inthandler2c(int *esp){unsigned char data;io_out8(PIC1_OCW2, 0x64);	/* IRQ-12PIC1 */io_out8(PIC0_OCW2, 0x62);	/* IRQ-02PIC0 */data = io_in8(PORT_KEYDAT);fifo8_put(&mousefifo, data);return;
}void enable_mouse(struct MOUSE_DEC *mdec)
{wait_KBC_sendready();io_out8(PORT_KEYCMD, KEYCMD_SENDTO_MOUSE);wait_KBC_sendready();io_out8(PORT_KEYDAT, MOUSECMD_ENABLE);mdec->phase = 0; return;
}int mouse_decode(struct MOUSE_DEC *mdec, unsigned char dat)
{if (mdec->phase == 0) {if (dat == 0xfa) {mdec->phase = 1;}return 0;}if (mdec->phase == 1) {if ((dat & 0xc8) == 0x08) {mdec->buf[0] = dat;mdec->phase = 2;}return 0;}if (mdec->phase == 2) {mdec->buf[1] = dat;mdec->phase = 3;return 0;}if (mdec->phase == 3) {mdec->buf[2] = dat;mdec->phase = 1;mdec->btn = mdec->buf[0] & 0x07;mdec->x = mdec->buf[1];mdec->y = mdec->buf[2];if ((mdec->buf[0] & 0x10) != 0) {mdec->x |= 0xffffff00;}if ((mdec->buf[0] & 0x20) != 0) {mdec->y |= 0xffffff00;}mdec->y = - mdec->y; return 1;}return -1; 
}

6. Int.c

#include "Jiangos.h"void intservice(void)
{	resetidt(IntNO_key,  (int) asm_inthandler21); /*设置键盘中断服务程序偏移*/resetidt(IntNO_mouse,(int) asm_inthandler2c); /*设置鼠标中断服务程序偏移*/io_out8(PIC0_IMR, 0xf9); /* 开启键盘和鼠标中断主芯片设置:(11111001) */io_out8(PIC1_IMR, 0xef); /* 从芯片设置:(11101111) */}void resetidt(char intNO,int intoffset) /*中断号,汇编里中断服务程序的标号偏移*/
{*(short *)(idtaddr+intNO*8)=(short) intoffset-cheaderlen;/*取低16位*/*(short *)(idtaddr+intNO*8+06)=(short) (intoffset>>16);/*取高16位*/}     

7.Fifo.c

#include "Jiangos.h"void fifo8_init(struct FIFO8 *fifo, int size, unsigned char *buf){fifo->size = size;fifo->buf = buf;fifo->free = size; fifo->flags = 0;fifo->p = 0; fifo->q = 0; return;
}int fifo8_put(struct FIFO8 *fifo, unsigned char data){if (fifo->free == 0) {fifo->flags |= FLAGS_OVERRUN;return -1;}fifo->buf[fifo->p] = data;fifo->p++;if (fifo->p == fifo->size) {fifo->p = 0;}fifo->free--;return 0;
}int fifo8_get(struct FIFO8 *fifo){int data;if (fifo->free == fifo->size) {return -1;}data = fifo->buf[fifo->q];fifo->q++;if (fifo->q == fifo->size) {fifo->q = 0;}fifo->free++;return data;
}int fifo8_status(struct FIFO8 *fifo){return fifo->size - fifo->free;
}

8.Sysinit.c

#include "Jiangos.h"void sysinit(void)  /*把C程序已初始化的变量写进内存的变量数据区*/
{struct BOOTINFO *binfo = (struct BOOTINFO *) BOOTBASE;int *dataposp=kerneladdr+(binfo->asmlen)+datapospos; /*变量区位置的位置指针*/int *datap=kerneladdr+(binfo->asmlen)+*dataposp;    /*变量区的位置指针*/ int *datalenp=kerneladdr+(binfo->asmlen)+datalenpos; /*变量区长度的位置指针*/mem_copy(datap,(int *)dataaddr,(int)((*datalenp)/4+1));/*拷贝以4个字节为单位*/
}

四、总结

我们的操作系统终于走到了Windows视窗界面,并具备了鼠标和键盘使用的能力,接下来就将大步前进了!