mirror of
https://github.com/yourtion/30dayMakeOS.git
synced 2026-02-04 18:43:25 +08:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab7d0506ed | ||
|
|
ac5586eb24 | ||
|
|
7ac78a7688 | ||
|
|
96a714a9be | ||
|
|
9096191855 | ||
|
|
22bda5f82c |
@@ -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/
|
||||
|
||||
@@ -1,31 +1,99 @@
|
||||
/* bootpack */
|
||||
/* bootpackのメイン */
|
||||
|
||||
#include "bootpack.h"
|
||||
#include <stdio.h>
|
||||
|
||||
extern struct FIFO8 keyfifo, mousefifo;
|
||||
void enable_mouse(void);
|
||||
void init_keyboard(void);
|
||||
|
||||
void HariMain(void)
|
||||
{
|
||||
struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO;
|
||||
char s[40], mcursor[256];
|
||||
int mx, my;
|
||||
char s[40], mcursor[256], keybuf[32], mousebuf[128];
|
||||
int mx, my, i;
|
||||
|
||||
init_gdtidt();
|
||||
init_pic();
|
||||
io_sti(); /* IDT/PICの初期化が終わったのでCPUの割り込み禁止を解除 */
|
||||
|
||||
fifo8_init(&keyfifo, 32, keybuf);
|
||||
fifo8_init(&mousefifo, 128, mousebuf);
|
||||
io_out8(PIC0_IMR, 0xf9); /* PIC1とキーボードを許可(11111001) */
|
||||
io_out8(PIC1_IMR, 0xef); /* マウスを許可(11101111) */
|
||||
|
||||
init_keyboard();
|
||||
|
||||
init_palette();
|
||||
init_screen8(binfo->vram, binfo->scrnx, binfo->scrny);
|
||||
mx = (binfo->scrnx - 16) / 2; /* 计算画面的中心坐标*/
|
||||
mx = (binfo->scrnx - 16) / 2; /* 计算画面中心坐标 */
|
||||
my = (binfo->scrny - 28 - 16) / 2;
|
||||
init_mouse_cursor8(mcursor, COL8_008484);
|
||||
putblock8_8(binfo->vram, binfo->scrnx, 16, 16, mx, my, mcursor, 16);
|
||||
sprintf(s, "(%d, %d)", mx, my);
|
||||
putfonts8_asc(binfo->vram, binfo->scrnx, 0, 0, COL8_FFFFFF, s);
|
||||
|
||||
io_out8(PIC0_IMR, 0xf9); /* PIC1とキーボードを許可(11111001) */
|
||||
io_out8(PIC1_IMR, 0xef); /* マウスを許可(11101111) */
|
||||
enable_mouse();
|
||||
|
||||
for (;;) {
|
||||
io_hlt();
|
||||
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", i);
|
||||
boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 0, 16, 15, 31);
|
||||
putfonts8_asc(binfo->vram, binfo->scrnx, 0, 16, COL8_FFFFFF, s);
|
||||
} else if (fifo8_status(&mousefifo) != 0) {
|
||||
i = fifo8_get(&mousefifo);
|
||||
io_sti();
|
||||
sprintf(s, "%02X", i);
|
||||
boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 32, 16, 47, 31);
|
||||
putfonts8_asc(binfo->vram, binfo->scrnx, 32, 16, COL8_FFFFFF, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define PORT_KEYDAT 0x0060
|
||||
#define PORT_KEYSTA 0x0064
|
||||
#define PORT_KEYCMD 0x0064
|
||||
#define KEYSTA_SEND_NOTREADY 0x02
|
||||
#define KEYCMD_WRITE_MODE 0x60
|
||||
#define KBC_MODE 0x47
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
#define KEYCMD_SENDTO_MOUSE 0xd4
|
||||
#define MOUSECMD_ENABLE 0xf4
|
||||
|
||||
void enable_mouse(void)
|
||||
{
|
||||
/* 激活鼠标 */
|
||||
wait_KBC_sendready();
|
||||
io_out8(PORT_KEYCMD, KEYCMD_SENDTO_MOUSE);
|
||||
wait_KBC_sendready();
|
||||
io_out8(PORT_KEYDAT, MOUSECMD_ENABLE);
|
||||
return; /* 顺利的话,键盘控制器会返回ACK(0xfa) */
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
57
07_day/fifo.c
Normal file
57
07_day/fifo.c
Normal 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;
|
||||
}
|
||||
26
07_day/int.c
26
07_day/int.c
@@ -24,30 +24,32 @@ void init_pic(void)
|
||||
return;
|
||||
}
|
||||
|
||||
#define PORT_KEYDAT 0x0060
|
||||
|
||||
struct FIFO8 keyfifo;
|
||||
|
||||
void inthandler21(int *esp)
|
||||
/* 来自PS/2键盘的中断 */
|
||||
{
|
||||
struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO;
|
||||
unsigned char data, s[4];
|
||||
io_out8(PIC0_OCW2, 0x61); /* IRQ-01受付完了をPICに通知 */
|
||||
io_out8(PIC0_OCW2, 0x61); /* 通知PIC IRQ-01 已经受理完毕 */
|
||||
data = io_in8(PORT_KEYDAT);
|
||||
|
||||
sprintf(s, "%02X", data);
|
||||
boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 0, 16, 15, 31);
|
||||
putfonts8_asc(binfo->vram, binfo->scrnx, 0, 16, COL8_FFFFFF, s);
|
||||
|
||||
fifo8_put(&keyfifo, data);
|
||||
return;
|
||||
}
|
||||
|
||||
struct FIFO8 mousefifo;
|
||||
|
||||
void inthandler2c(int *esp)
|
||||
/* 来自PS/2鼠标的中断 */
|
||||
{
|
||||
struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO;
|
||||
boxfill8(binfo->vram, binfo->scrnx, COL8_000000, 0, 0, 32 * 8 - 1, 15);
|
||||
putfonts8_asc(binfo->vram, binfo->scrnx, 0, 0, COL8_FFFFFF, "INT 2C (IRQ-12) : PS/2 mouse");
|
||||
for (;;) {
|
||||
io_hlt();
|
||||
}
|
||||
unsigned char data;
|
||||
io_out8(PIC1_OCW2, 0x64); /* 通知PIC IRQ-12 已经受理完毕 */
|
||||
io_out8(PIC0_OCW2, 0x62); /* 通知PIC IRQ-02 已经受理完毕 */
|
||||
data = io_in8(PORT_KEYDAT);
|
||||
fifo8_put(&mousefifo, data);
|
||||
return;
|
||||
}
|
||||
|
||||
void inthandler27(int *esp)
|
||||
|
||||
Reference in New Issue
Block a user