Compare commits

...

3 Commits

Author SHA1 Message Date
Yourtion
7ac78a7688 整理FIFO缓冲区 2014-09-17 15:46:42 +08:00
Yourtion
96a714a9be 改善FIFO缓冲区 2014-09-17 15:27:24 +08:00
Yourtion
9096191855 添加FIFO缓冲中断信息 2014-09-17 15:17:16 +08:00
5 changed files with 75 additions and 14 deletions

View File

@@ -1,5 +1,5 @@
OBJS_BOOTPACK = bootpack.obj naskfunc.obj hankaku.obj graphic.obj dsctbl.obj \
int.obj
int.obj fifo.obj
TOOLPATH = ../z_tools/
INCPATH = ../z_tools/haribote/

View File

@@ -3,18 +3,19 @@
#include "bootpack.h"
#include <stdio.h>
extern struct KEYBUF keybuf;
extern struct FIFO8 keyfifo;
void HariMain(void)
{
struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO;
char s[40], mcursor[256];
char s[40], mcursor[256], keybuf[32];
int mx, my, i;
init_gdtidt();
init_pic();
io_sti(); /* IDT/PICの初期化が終わったのでCPUの割り込み禁止を解除 */
fifo8_init(&keyfifo, 32, keybuf);
io_out8(PIC0_IMR, 0xf9); /* PIC1とキーボードを許可(11111001) */
io_out8(PIC1_IMR, 0xef); /* マウスを許可(11101111) */
@@ -29,11 +30,10 @@ void HariMain(void)
for (;;) {
io_cli();
if (keybuf.flag == 0) {
if (fifo8_status(&keyfifo) == 0) {
io_stihlt();
} else {
i = keybuf.data;
keybuf.flag = 0;
i = fifo8_get(&keyfifo);
io_sti();
sprintf(s, "%02X", i);
boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 0, 16, 15, 31);

View File

@@ -22,6 +22,16 @@ void asm_inthandler21(void);
void asm_inthandler27(void);
void asm_inthandler2c(void);
/* fifo.c */
struct FIFO8 {
unsigned char *buf;
int p, q, size, free, flags;
};
void fifo8_init(struct FIFO8 *fifo, int size, unsigned char *buf);
int fifo8_put(struct FIFO8 *fifo, unsigned char data);
int fifo8_get(struct FIFO8 *fifo);
int fifo8_status(struct FIFO8 *fifo);
/* graphic.c */
void init_palette(void);
void set_palette(int start, int end, unsigned char *rgb);
@@ -74,9 +84,6 @@ void set_gatedesc(struct GATE_DESCRIPTOR *gd, int offset, int selector, int ar);
#define AR_INTGATE32 0x008e
/* int.c */
struct KEYBUF {
unsigned char data, flag;
};
void init_pic(void);
void inthandler21(int *esp);
void inthandler27(int *esp);

57
07_day/fifo.c Normal file
View File

@@ -0,0 +1,57 @@
/* FIFO */
#include "bootpack.h"
#define FLAGS_OVERRUN 0x0001
void fifo8_init(struct FIFO8 *fifo, int size, unsigned char *buf)
/* 初始化FIFO缓冲区 */
{
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)
/* 向FIFO传送数据并保存 */
{
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)
/* 从FIFO取得一个数据 */
{
int data;
if (fifo->free == fifo->size) {
/* 如果缓冲区为空则返回-1 */
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;
}

View File

@@ -26,7 +26,7 @@ void init_pic(void)
#define PORT_KEYDAT 0x0060
struct KEYBUF keybuf;
struct FIFO8 keyfifo;
void inthandler21(int *esp)
/* 来自PS/2键盘的中断 */
@@ -35,10 +35,7 @@ void inthandler21(int *esp)
unsigned char data, s[4];
io_out8(PIC0_OCW2, 0x61); /* 通知PIC IRQ-01 已经受理完毕 */
data = io_in8(PORT_KEYDAT);
if (keybuf.flag == 0) {
keybuf.data = data;
keybuf.flag = 1;
}
fifo8_put(&keyfifo, data);
return;
}