void task_b_main(LAYER *layer_bg) { FIFO fifo; TIMER *timer_display; int i, fifobuf[128], count = 0; char strings[20]; init_fifo(&fifo, 128, fifobuf); timer_display = timer_alloc(); timer_init(timer_display, &fifo, 1); timer_set(timer_display, 1); for(;;) { count++; io_cli(); if(0 == fifo_status(&fifo)) { io_sti(); } else { i = fifo_get(&fifo); io_sti(); if(1 == i) { sprintf(strings, "%11d", count); displayStrings_atLayer(layer_bg, 0, 144, COL8_FFFFFF, COL8_008484, strings); timer_set(timer_display, 1); } } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; char s[40], mcursor[256], keybuf[32]; int mx, my, i; init_gdtidt(); init_pic(); io_sti(); fifo8_init(&keyfifo, 32, keybuf); io_out8(PIC0_IMR, 0xf9); io_out8(PIC1_IMR, 0xef); init_palette(); init_screen8(binfo->vram, binfo->scrnx, binfo->scrny); 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); putfonts8_asc(binfo->vram, binfo->scrnx, 0, 0, COL8_FFFFFF, s); for (;;) { io_cli(); if (fifo8_status(&keyfifo) == 0) { io_stihlt(); } else { i = fifo8_get(&keyfifo); io_sti(); boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 0, 16, 15, 31); putfonts8_asc(binfo->vram, binfo->scrnx, 0, 16, COL8_FFFFFF, s); } } }
void task_b_main(void) { struct FIFO32 fifo; struct TIMER *timer_ts; int i, fifobuf[128]; fifo32_init(&fifo, 128, fifobuf); timer_ts = timer_alloc(); timer_init(timer_ts, &fifo, 1); timer_settime(timer_ts, 2); for (;;) { io_cli(); if (fifo32_status(&fifo) == 0) { io_sti(); io_hlt(); } else { i = fifo32_get(&fifo); io_sti(); if (i == 1) { /* タスクスイッチ */ farjmp(0, 3 * 8); timer_settime(timer_ts, 2); } } } }
static void task_b_main(layer_t* win_layer_b) { fifo32_t fifo; timer_t* timer_1s; int data, count = 0, count1 = 0; int fifobuf[128]; char buf[32]; fifo_init(&fifo, fifobuf, 128, 0); timer_1s = timer_alloc(); timer_init(timer_1s, &fifo, 100); timer_settimer(timer_1s, 100); for ( ; ; ) { ++count; io_cli(); if (0 == fifo_size(&fifo)) io_sti(); else { data = fifo_get(&fifo); io_sti(); if (100 == data) { sprintf(buf, "%011d", count - count1); drawstring_and_refresh(win_layer_b, 24, 28, COLOR8_000000, COLOR8_C6C6C6, buf, 11); count1 = count; timer_settimer(timer_1s, 100); } } } }
void task_b_main(struct SHEET *sht_win_b) { struct FIFO32 fifo; struct TIMER *timer_1s; int i, fifobuf[128], count = 0, count0 = 0; char s[12]; fifo32_init(&fifo, 128, fifobuf,0); timer_1s = timer_alloc(); timer_init(timer_1s, &fifo, 100); timer_settime(timer_1s, 100); for (;;) { count++; io_cli(); if (fifo32_status(&fifo) == 0) { io_sti(); } else { i = fifo32_get(&fifo); io_sti(); if (i == 100) { sprintf(s, "%11d", count - count0); putfonts8_asc_sht(sht_win_b, 24, 28, COL8_000000, COL8_C6C6C6, s, 11); count0 = count; timer_settime(timer_1s, 100); } } } }
void task_b_main(void) { struct FIFO32 fifo; struct TIMER *timer; int i, fifobuf[128]; fifo32_init(&fifo, 128, fifobuf); timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settime(timer, 500); for (;;) { io_cli(); if (fifo32_status(&fifo) == 0) { io_sti(); io_hlt(); } else { i = fifo32_get(&fifo); io_sti(); if (i == 1) { taskswitch3(); } } } }
void task_b_main(LAYER *layer) { FIFO fifo; TIMER *timer_1s; int i, fifobuf[128], count = 0, count0 = 0; char s[12]; init_fifo(&fifo, 128, fifobuf, 0); timer_1s = timer_alloc(); timer_init(timer_1s, &fifo, 100); timer_set(timer_1s, 100); for (;;) { count++; io_cli(); if (fifo_status(&fifo) == 0) { io_sti(); } else { i = fifo_get(&fifo); io_sti(); if (i == 100) { sprintf(s, "%11d", count - count0); displayStrings_atLayer(layer, 24, 28, COL8_000000, COL8_C6C6C6, s); count0 = count; timer_set(timer_1s, 100); } } } }
void console_task(struct SHEET *sheet) { struct TIMER *timer; struct TASK *task = task_now(); int i, fifobuf[128], cursor_x = 16, cursor_c = COL8_000000; char s[2]; fifo32_init(&task->fifo, 128, fifobuf, task); timer = timer_alloc(); timer_init(timer, &task->fifo, 1); timer_settime(timer, 50); /* 显示提示符 */ putfonts8_asc_sht(sheet, 8, 28, COL8_FFFFFF, COL8_000000, ">", 1); for (;;) { io_cli(); if (fifo32_status(&task->fifo) == 0) { task_sleep(task); io_sti(); } else { i = fifo32_get(&task->fifo); io_sti(); if (i <= 1) { /* 光标用定时器 */ if (i != 0) { timer_init(timer, &task->fifo, 0); /* 下次置0 */ cursor_c = COL8_FFFFFF; } else { timer_init(timer, &task->fifo, 1); /* 下次置1 */ cursor_c = COL8_000000; } timer_settime(timer, 50); } if (256 <= i && i <= 511) { /* 键盘数据(通过任务A) */ if (i == 8 + 256) { /* 退格键 */ if (cursor_x > 16) { /* 用空白擦除光标后将光标前移一位 */ putfonts8_asc_sht(sheet, cursor_x, 28, COL8_FFFFFF, COL8_000000, " ", 1); cursor_x -= 8; } } else { /* 一般字符 */ if (cursor_x < 240) { /* 显示一个字符之后将光标后移一位 */ s[0] = i - 256; s[1] = 0; putfonts8_asc_sht(sheet, cursor_x, 28, COL8_FFFFFF, COL8_000000, s, 1); cursor_x += 8; } } } /* 重新显示光标 */ boxfill8(sheet->buf, sheet->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sheet, cursor_x, 28, cursor_x + 8, 44); } } }
void HariMain(void) { boot_info_t* binfo = (boot_info_t*)ADR_BOOTINFO; char debug_info[64], mouse_cursor[256], keybuf[32]; int mouse_x, mouse_y; init_gdt_idt(); init_pic(); io_sti(); fifo_init(&g_keybuf, keybuf, 32); io_out8(PIC0_IMR, 0xf9); io_out8(PIC1_IMR, 0xef); init_keyboard(); /* initialize keyboard */ init_palette(); init_screen(binfo->vram, binfo->screen_x, binfo->screen_y); mouse_x = (binfo->screen_x - 16) / 2; mouse_y = (binfo->screen_y - 28 - 16) / 2; init_mouse_cursor8(mouse_cursor, COLOR8_848484); draw_block8_8(binfo->vram, binfo->screen_x, 16, 16, mouse_x, mouse_y, mouse_cursor, 16); draw_font8_asc(binfo->vram, binfo->screen_x, 8, 8, COLOR8_FFFFFF, "HELLO BOYS:"); draw_font8_asc(binfo->vram, binfo->screen_x, 9, 9, COLOR8_000000, "HELLO BOYS:"); draw_font8_asc(binfo->vram, binfo->screen_x, 31, 31, COLOR8_000000, "WELCOME TO THE LOVELY TOY-OS."); draw_font8_asc(binfo->vram, binfo->screen_x, 30, 30, COLOR8_FFFFFF, "WELCOME TO THE LOVELY TOY-OS."); sprintf(debug_info, "screen=>{%d, %d}", binfo->screen_x, binfo->screen_y); draw_font8_asc(binfo->vram, binfo->screen_x, 16, 64, COLOR8_FF0000, debug_info); enable_mouse(); /* enabled mouse */ for ( ; ; ) { int data; io_cli(); if (0 == fifo_size(&g_keybuf)) io_stihlt(); else { data = fifo_get(&g_keybuf); io_sti(); sprintf(debug_info, "%02X", data); fill_box8(binfo->vram, binfo->screen_x, COLOR8_008484, 0, 16, 15, 31); draw_font8_asc(binfo->vram, binfo->screen_x, 0, 16, COLOR8_FFFFFF, debug_info); } } }
void console_task(struct SHEET *sheet) { struct TIMER *timer; struct TASK *task = task_now(); int i, fifobuf[128], cursor_x = 16, cursor_c = COL8_000000; char s[2]; fifo32_init(&task->fifo, 128, fifobuf, task); timer = timer_alloc(); timer_init(timer, &task->fifo, 1); timer_settime(timer, 50); /* プロンプト表示 */ putfonts8_asc_sht(sheet, 8, 28, COL8_FFFFFF, COL8_000000, ">", 1); for (;;) { io_cli(); if (fifo32_status(&task->fifo) == 0) { task_sleep(task); io_sti(); } else { i = fifo32_get(&task->fifo); io_sti(); if (i <= 1) { /* カーソル用タイマ */ if (i != 0) { timer_init(timer, &task->fifo, 0); /* 次は0を */ cursor_c = COL8_FFFFFF; } else { timer_init(timer, &task->fifo, 1); /* 次は1を */ cursor_c = COL8_000000; } timer_settime(timer, 50); } if (256 <= i && i <= 511) { /* キーボードデータ(タスクA経由) */ if (i == 8 + 256) { /* バックスペース */ if (cursor_x > 16) { /* カーソルをスペースで消してから、カーソルを1つ戻す */ putfonts8_asc_sht(sheet, cursor_x, 28, COL8_FFFFFF, COL8_000000, " ", 1); cursor_x -= 8; } } else { /* 一般文字 */ if (cursor_x < 240) { /* 一文字表示してから、カーソルを1つ進める */ s[0] = i - 256; s[1] = 0; putfonts8_asc_sht(sheet, cursor_x, 28, COL8_FFFFFF, COL8_000000, s, 1); cursor_x += 8; } } } /* カーソル再表示 */ boxfill8(sheet->buf, sheet->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sheet, cursor_x, 28, cursor_x + 8, 44); } } }
void HariMain(void) { boot_info_t* binfo = (boot_info_t*)ADR_BOOTINFO; char debug_info[64], mouse_cursor[256]; int mouse_x, mouse_y; init_gdt_idt(); init_pic(); io_sti(); io_out8(PIC0_IMR, 0xf9); io_out8(PIC1_IMR, 0xef); init_palette(); init_screen(binfo->vram, binfo->screen_x, binfo->screen_y); mouse_x = (binfo->screen_x - 16) / 2; mouse_y = (binfo->screen_y - 28 - 16) / 2; init_mouse_cursor8(mouse_cursor, COLOR8_848484); draw_block8_8(binfo->vram, binfo->screen_x, 16, 16, mouse_x, mouse_y, mouse_cursor, 16); draw_font8_asc(binfo->vram, binfo->screen_x, 8, 8, COLOR8_FFFFFF, "HELLO BOYS:"); draw_font8_asc(binfo->vram, binfo->screen_x, 9, 9, COLOR8_000000, "HELLO BOYS:"); draw_font8_asc(binfo->vram, binfo->screen_x, 31, 31, COLOR8_000000, "WELCOME TO THE LOVELY TOY-OS."); draw_font8_asc(binfo->vram, binfo->screen_x, 30, 30, COLOR8_FFFFFF, "WELCOME TO THE LOVELY TOY-OS."); sprintf(debug_info, "screen=>{%d, %d}", binfo->screen_x, binfo->screen_y); draw_font8_asc(binfo->vram, binfo->screen_x, 16, 64, COLOR8_FF0000, debug_info); for ( ; ; ) { int data, i; io_cli(); if (0 == g_keybuf.next) io_stihlt(); else { data = g_keybuf.data[0]; --g_keybuf.next; for (i = 0; i < g_keybuf.next; ++i) g_keybuf.data[i] = g_keybuf.data[i + 1]; io_sti(); sprintf(debug_info, "%02X", data); fill_box8(binfo->vram, binfo->screen_x, COLOR8_008484, 0, 16, 15, 31); draw_font8_asc(binfo->vram, binfo->screen_x, 0, 16, COLOR8_FFFFFF, debug_info); } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; 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; 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); enable_mouse(); for (;;) { io_cli(); if (fifo8_status(&keyfifo) + fifo8_status(&mousefifo) == 0) { /* J char ss[10]; sprintf(ss, "%c", "J"); putfonts8_asc(binfo->vram, binfo->scrnx, 100, 100, COL8_FFFFFF, ss); */ 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); } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; /* s是输出缓冲区 mcursor存放鼠标图形 */ char s[40], mcursor[256]; int mx, my; init_gdtidt(); /* 初始化GDT, IDT */ init_pic(); /* 初始化PIC */ io_sti(); /* 打开所有可屏蔽中断 */ init_palette(); /* 初始化调色板 */ init_screen8(binfo->vram, binfo->scrnx, binfo->scrny); /* 绘制"桌面" */ 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); /* PIC0(11111001) (打开IRQ1键盘中断和连接从PIC的IRQ2)*/ io_out8(PIC1_IMR, 0xef); /* PIC1(11101111) (打开PS2鼠标中断 即IRQ12)*/ for (;;) { io_hlt(); } }
void task_b_main (struct SHEET *sht_back) { struct FIFO32 fifo; struct TIMER *timer_ts, *timer_put; int i, fifobuf[128], count = 0; fifo32_init(&fifo, 128, fifobuf); timer_ts = timer_alloc(); timer_init(timer_ts, &fifo, 2); timer_settime(timer_ts, 2); timer_put = timer_alloc(); timer_init(timer_put, &fifo, 1); timer_settime(timer_put, 1); for (;;) { count++; io_cli(); if (fifo32_status(&fifo) == 0) { io_stihlt(); } else { i = fifo32_get(&fifo); io_sti(); if (i == 1) { char s[11]; sprintf (s, "%d", count); putfonts8_asc_sht (sht_back, 0, 144, COL8_FFFFFF, COL8_008484, s, 11); timer_settime (timer_put, 1); } else if (i == 2) { // timeout 5 sec farjmp(0, 3 * 8); timer_settime(timer_ts, 2); } } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; char s[40],mcursor[256]; int mx, my; init_gdtidt(); init_pic(); io_sti(); init_palette(); init_screen8(binfo->vram, binfo->scrnx, binfo->scrny); 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); io_out8(PIC1_IMR, 0xef); for (;;) { io_hlt(); } }
void inthandler20(int *esp) { int flag_switch = 0; struct CLOCK *clock; io_cli(); io_out8(PIC0_OCW2, 0x60); clock_ctl->count++; if (clock_ctl->next > clock_ctl->count) { return; } clock = clock_ctl->c0; for (;;) { if (clock->time_out > clock_ctl->count) { break; } if(clock != task_clock){ fifo32_put(clock->fifo, clock->data); }else{ flag_switch = 1; } clock->flag_usage = CLOCK_FLAGS_ALLOC; clock = clock->next; } clock_ctl->c0 = clock; clock_ctl->next = clock->time_out; io_sti(); if(flag_switch == 1){ task_switch(); } return; }
void HariMain(void) { int i; struct BOOTINFO *binfo = (struct BOOTINFO *)0x0ff0; int xsize = (*binfo).scrnx; int ysize = (*binfo).scrny; char *vram = (*binfo).vram; char msg[40], mcursor[256]; const int mx = xsize/2; const int my = ysize/2; init_gdtidt (); init_pic (); io_sti (); init_pallete(); init_screen (vram, xsize, ysize); putfonts8_asc (binfo->vram, binfo->scrnx, 8, 8, COL8_FFFFFF, "ABC 123"); putfonts8_asc (binfo->vram, binfo->scrnx, 31, 31, COL8_000000, "Haribote OS."); putfonts8_asc (binfo->vram, binfo->scrnx, 30, 30, COL8_FFFFFF, "Haribote OS."); sprintf(msg, "scrnx = %d", binfo->scrnx); putfonts8_asc (binfo->vram, binfo->scrnx, 30, 48, COL8_FFFFFF, msg); init_mouse_cursor8 (mcursor, COL8_008484); putblock8_8 (binfo->vram, binfo->scrnx, 16, 16, mx,my, mcursor, 16); io_out8(PIC0_IMR, 0xf9); /* PIC1とキーボードを許可(11111001) */ io_out8(PIC1_IMR, 0xef); /* マウスを許可(11101111) */ for (;;) { io_cli(); if (keybuf.flag == 0) { io_stihlt(); } else { i = keybuf.data; keybuf.flag = 0; io_sti(); unsigned char s[4]; sprintf (s, "%x", i); boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 0, 48, 15, 31+48); putfonts8_asc(binfo->vram, binfo->scrnx, 0, 48, COL8_FFFFFF, s); } } }
static void task_b_main(layer_t* back_layer) { fifo32_t fifo; timer_t* timer_put; timer_t* timer_1s; int data, count = 0, count1 = 0; int fifobuf[128]; char buf[32]; fifo_init(&fifo, fifobuf, 128); timer_put = timer_alloc(); timer_init(timer_put, &fifo, 1); timer_settimer(timer_put, 1); timer_1s = timer_alloc(); timer_init(timer_1s, &fifo, 100); timer_settimer(timer_1s, 100); for ( ; ; ) { ++count; io_cli(); if (0 == fifo_size(&fifo)) io_sti(); else { data = fifo_get(&fifo); io_sti(); if (1 == data) { sprintf(buf, "%011d", count); drawstring_and_refresh(back_layer, 0, 144, COLOR8_FFFFFF, COLOR8_848484, buf, 11); timer_settimer(timer_put, 1); } else if (100 == data) { sprintf(buf, "%011d", count - count1); drawstring_and_refresh(back_layer, 0, 128, COLOR8_FFFFFF, COLOR8_848484, buf, 11); count1 = count; timer_settimer(timer_1s, 100); } } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) 0x0ff0; char s[40], mcursor[256]; int mx, my, i; init_gdtidt(); init_pic(); // Set IF (interrupt flag to 1) io_sti(); init_palette(); init_screen8(binfo->vram, binfo->scrnx, binfo->scrny); 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); /* (11111001) Open IRQ 1 (keyboard) and IRQ 2 (connect to PIC 1) */ io_out8(PIC1_IMR, 0xef); /* (11101111) Open IRQ 12 */ //--keyboard char keybuf[32]; fifo8_init(&keyfifo,32, keybuf); init_keyboard(); for (;;) { io_cli(); if (fifo8_status(&keyfifo) == 0) { io_stihlt(); } else { 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); } } }
static void console_task(layer_t* layer) { fifo32_t fifo; timer_t* timer; task_t* task = task_now(); int data, fifobuf[128], cursor_x = 8, cursor_c = COLOR8_000000; fifo_init(&fifo, fifobuf, 128, task); timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settimer(timer, 50); for ( ; ; ) { io_cli(); if (0 == fifo_size(&fifo)) { task_sleep(task); io_sti(); } else { data = fifo_get(&fifo); io_sti(); if (data <= 1) { /* timer for cursor */ if (0 != data) { timer_init(timer, &fifo, 0); cursor_c = COLOR8_FFFFFF; } else { timer_init(timer, &fifo, 1); cursor_c = COLOR8_000000; } timer_settimer(timer, 50); fill_box8(layer->buf, layer->w_size, cursor_c, cursor_x, 28, cursor_x + 7, 43); layers_refresh(layer, cursor_x, 28, cursor_x + 8, 44); } } } }
void task2(void) { int i = 0; io_sti(); for (i = 0; i < 100000; i++) { printf(TEXT_MODE_SCREEN_LEFT, "task2: %d", i); } while(true){ io_hlt(); } }
int put_fifo32(Fifo32* fi,i32 dat) { if((fi->rpos-fi->wpos+fi->len)%fi->len==1) return -1; io_cli(); fi->buf[fi->wpos]=dat; ++(fi->wpos); if(fi->wpos>=fi->len) fi->wpos=0; io_sti(); return 0; }
void kernel_start() { init_pic(); init_gdt(); init_idt(); init_graphic(); io_sti(); while(1); // halt(); }
void task1(void) { int i = 0; io_sti(); /* printf(TEXT_MODE_SCREEN_RIGHT, "0x%x", io_load_eflags()); */ for (i = 0; i < 100000; i++) { printf(TEXT_MODE_SCREEN_LEFT, "task1: %d", i); } while(true){ io_hlt(); } }
i32 get_fifo32(Fifo32* fi) { i32 out; if(fi->rpos==fi->wpos) return -1; io_cli(); out=fi->buf[fi->rpos]; ++(fi->rpos); if(fi->rpos>=fi->len) fi->rpos=0; io_sti(); return out; }
void Timer_set_frequency(uint32_t frequency) { io_cli(); // Intel 8253/8254 PIT芯片 I/O端口地址范围是40h~43h // 输入频率为 1193180 (12MHz),frequency 即每秒中断次数 uint32_t divisor = 1193180 / frequency; timer_frequency = frequency; // 分别写入低字节和高字节 io_out8(0x40, (uint8_t)(divisor & 0xFF)); io_out8(0x40, (uint8_t)((divisor >> 8) & 0xFF)); io_sti(); }
void task_b_main(struct SHEET *sht_back) { struct FIFO32 fifo; struct TIMER *timer_put, *timer_1s; int i, fifobuf[128], count = 0, count0 = 0; char s[128]; fifo32_init(&fifo, 128, fifobuf); timer_put = timer_alloc(); timer_init(timer_put, &fifo, 1); timer_settime(timer_put, 1); timer_1s = timer_alloc(); timer_init(timer_1s, &fifo, 100); timer_settime(timer_1s, 100); for (;;) { count++; io_cli(); if (fifo32_status(&fifo) == 0) { io_sti(); } else { i = fifo32_get(&fifo); io_sti(); if (i == 1) { sprintf(s, "+%11d, times=%d", count, task_switch_times); putfonts8_asc_sht(sht_back, 0, 144, COL8_FFFFFF, COL8_008484, s, 31); timer_settime(timer_put, 1); } else if (i == 100) { sprintf(s, "-%11d", count - count0); putfonts8_asc_sht(sht_back, 0, 128, COL8_FFFFFF, COL8_008484, s, 31); count0 = count; timer_settime(timer_1s, 100); } } } }
void keyboard_read(u32* key) { u8 scan_code; u32 col; BOOL b_shift; if (!is_queue_empty(&kb_queue)) { io_cli(); de_queue(&kb_queue, &scan_code); io_sti(); /* 首先处理E0 开头的情况,将b_leading_e0置位,然后直接返回 */ if (scan_code == 0xe0) { b_leading_e0 = TRUE; return; } /* 是键被抬起,暂时将键值设为0 */ if (scan_code & 0x80) { if (*key == K_SHIFT_L) b_shift_l = 0; if (*key == K_SHIFT_R) b_shift_r = 0; *key = 0; return; } b_shift = b_shift_l || b_shift_r; col = b_shift ? 1 : 0; if (b_leading_e0) { col = 2; b_leading_e0 = FALSE; } *key = keymap[scan_code & 0x7f][col]; if (*key == K_SHIFT_L) b_shift_l = 1; if (*key == K_SHIFT_R) b_shift_r = 1; b_shift = b_shift_l || b_shift_r; } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; char s[40], mcursor[256]; int mx, my, i; init_gdtidt(); init_pic(); io_sti(); /* IDT/PICの初期化が終わったのでCPUの割り込み禁止を解除 */ io_out8(PIC0_IMR, 0xf9); /* PIC1とキーボードを許可(11111001) */ io_out8(PIC1_IMR, 0xef); /* マウスを許可(11101111) */ init_palette(); init_screen8(binfo->vram, binfo->scrnx, binfo->scrny); 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); for (;;) { io_cli(); if (keybuf.flag == 0) { io_stihlt(); } else { i = keybuf.data; keybuf.flag = 0; 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); } } }
void console_task(struct SHEET *sheet) { struct FIFO32 fifo; struct TIMER *timer; struct TASK *task = task_now(); int i, fifobuf[128], cursor_x = 8, cursor_c = COL8_000000; fifo32_init(&fifo, 128, fifobuf, task); timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settime(timer, 50); for (;;) { io_cli(); if (fifo32_status(&fifo) == 0) { task_sleep(task); io_sti(); } else { i = fifo32_get(&fifo); io_sti(); if (i <= 1) { /* カーソル用タイマ */ if (i != 0) { timer_init(timer, &fifo, 0); /* 次は0を */ cursor_c = COL8_FFFFFF; } else { timer_init(timer, &fifo, 1); /* 次は1を */ cursor_c = COL8_000000; } timer_settime(timer, 50); boxfill8(sheet->buf, sheet->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sheet, cursor_x, 28, cursor_x + 8, 44); } } } }