void set_palette(int start, int end, unsigned char *rgb) { int i, eflags; eflags = _io_load_eflags(); _io_cli(); _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; } _io_store_eflags(eflags); return; }
void inthandler20(int *esp){ int i,j; struct TIMER *timer; _io_out8(PIC0_OCW2, 0x60); timerctl.count ++; if(timerctl.next_time > timerctl.count){ return; } timer = timerctl.t0; for (;;){ if (timer->timeout > timerctl.count){ /* time out all done*/ break; } timer->flags == TIMER_FLAGS_ALLOC; fifo32_put(timer->fifo, timer->data); // find last timer timer = timer->next_timer; } // next_timer setting timerctl.t0 = timer; // the lastest timer timerctl.next_time = timerctl.t0 -> timeout; return; }
void _inthandler27(int *esp) /* PIC0からの不完全割り込み対策 */ /* Athlon64X2機などではチップセットの都合によりPICの初期化時にこの割り込みが1度だけおこる */ /* この割り込み処理関数は、その割り込みに対して何もしないでやり過ごす */ /* なぜ何もしなくていいの? → この割り込みはPIC初期化時の電気的なノイズによって発生したものなので、 まじめに何か処理してやる必要がない。 */ { _io_out8(PIC0_OCW2, 0x67); /* IRQ-07受付完了をPICに通知 */ return; }
// bochs is 10x than qemu void init_pit(void){ int i; struct TIMER *t; _io_out8(PIT_CTRL, 0x36); _io_out8(PIT_CNT0, 0x9c); _io_out8(PIT_CNT0, 0x2e); timerctl.count = 0; timerctl.next_time = 0xffffffff; for (i = 0; i < MAX_TIMER; i++){ timerctl.timers0[i].flags = 0; } t = timer_alloc(); t->timeout = 0xffffffff; t->flags = TIMER_FLAGS_USING; t->next_timer = 0x00; timerctl.t0 = t; timerctl.next_time = 0xffffffff; return; }
void inthandler27(int *esp) { _io_out8(PIC0_OCW2, 0x67); return; }
void init_pic(void) { _io_out8(PIC0_IMR, 0xff ); _io_out8(PIC1_IMR, 0xff ); _io_out8(PIC0_ICW1, 0x11 ); _io_out8(PIC0_ICW2, 0x20 ); _io_out8(PIC0_ICW3, 1 << 2); _io_out8(PIC0_ICW4, 0x01 ); _io_out8(PIC1_ICW1, 0x11 ); _io_out8(PIC1_ICW2, 0x28 ); _io_out8(PIC1_ICW3, 2 ); _io_out8(PIC1_ICW4, 0x01 ); _io_out8(PIC0_IMR, 0xfb ); _io_out8(PIC1_IMR, 0xff ); return; }
void init_pic(void) /* PICの初期化 */ { _io_out8(PIC0_IMR, 0xff ); /* 全ての割り込みを受け付けない */ _io_out8(PIC1_IMR, 0xff ); /* 全ての割り込みを受け付けない */ _io_out8(PIC0_ICW1, 0x11 ); /* エッジトリガモード */ _io_out8(PIC0_ICW2, 0x20 ); /* IRQ0-7は、INT20-27で受ける */ _io_out8(PIC0_ICW3, 1 << 2); /* PIC1はIRQ2にて接続 */ _io_out8(PIC0_ICW4, 0x01 ); /* ノンバッファモード */ _io_out8(PIC1_ICW1, 0x11 ); /* エッジトリガモード */ _io_out8(PIC1_ICW2, 0x28 ); /* IRQ8-15は、INT28-2fで受ける */ _io_out8(PIC1_ICW3, 2 ); /* PIC1はIRQ2にて接続 */ _io_out8(PIC1_ICW4, 0x01 ); /* ノンバッファモード */ _io_out8(PIC0_IMR, 0xfb ); /* 11111011 PIC1以外は全て禁止 */ _io_out8(PIC1_IMR, 0xff ); /* 11111111 全ての割り込みを受け付けない */ return; }
void main(){ struct BOOTINFO *binfo; struct FIFO32 fifo; binfo = (struct BOOTINFO *) ADR_BOOTINFO; char s[MAX_LENGTH]; char mcursor[256]; // mouse and keyboard data int fifobuf[BUF_LEN]; struct TIMER *timer, *timer2, *timer3; int fifo_data; struct MOUSE_DEC mdec; int mx,my; // memory manager struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; unsigned int memtotal; // overlay control struct SHTCTL *shtctl; struct SHEET *sht_win, *sht_mouse; unsigned char *buf_back, buf_mouse[256]; unsigned char *buf_win; // gdt control init_gdtidt(); init_pic(); init_pit(); _io_sti(); // init fifo fifo32_init(&fifo, BUF_LEN, fifobuf); init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); timer = timer_alloc(); timer_init(timer, &fifo, 10); timer_settime(timer, 1000); timer2 = timer_alloc(); timer_init(timer2, &fifo, 3); timer_settime(timer2, 300); timer3 = timer_alloc(); timer_init(timer3,&fifo, 1); timer_settime(timer3, 50); // must after init pit // qemu 1000 = 10s // bochs 1000 = 1s _io_out8(PIC0_IMR,0xf8); _io_out8(PIC1_IMR,0xef); // mouse and keyboard control // memory set memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); // this is ERROR! // c400 is system memman_free(memman, 0x00400000, memtotal - 0x00400000); /************************************************** * screen * ----------------------------------------------*/ // video initialize init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); sht_back = sheet_alloc(shtctl); // background sheet sht_mouse = sheet_alloc(shtctl); // mouse sheet sht_win = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); // background buffer buf_win = (unsigned char *) memman_alloc_4k(memman,160*52); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); // bind buf sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); sheet_setbuf(sht_win, buf_win, 160, 52, -1); init_screen(buf_back, binfo->scrnx, binfo->scrny); // init color init_mouse_cursor8(buf_mouse, 99); make_window8(buf_win, 160, 52, "counter"); // init slide sheet_slide(sht_back, 0, 0); // initial mouse position mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; int cursor_x, cursor_c; make_textbox8(sht_win, 8, 28, 144, 16, COL8_FFFFFF); cursor_x = 8; cursor_c = COL8_FFFFFF; // init mouse slide // init position 0,0 sheet_slide(sht_mouse, mx, my); sheet_slide(sht_win,80,72); sheet_updown(sht_back, 0); sheet_updown(sht_win, 1); sheet_updown(sht_mouse, 2); /*------------------------------------------------- * screen * ***********************************************/ /*************** memory info *********/ /* itoa(s,memtotal / 1024 /1024,MAX_LENGTH); putfont8_asc(buf_back, binfo->scrnx, 0, 32, COL8_FFFFFF, s); itoa(s,memman_total(memman) / 1024,MAX_LENGTH); putfont8_asc(buf_back, binfo->scrnx, 0, 64, COL8_FFFFFF, s); sheet_refresh(sht_back, 0, 32, binfo->scrnx, 80); */ /*************** memory info *********/ /* * TSS */ struct TSS32 tss_a, tss_b; tss_a.ldtr = 0; tss_a.iomap = 0x40000000; tss_b.ldtr = 0; tss_b.iomap = 0x40000000; struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT; set_segmdesc(gdt+3, 103, (int) &tss_a, AR_TSS32); set_segmdesc(gdt+4, 103, (int) &tss_b, AR_TSS32); int task_b_esp; // current tr _load_tr(3 * 8); task_b_esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024; tss_b.eip = (int) &task_b_main; tss_b.eflags = 0x00000202; /* IF = 1; */ tss_b.eax = 0; tss_b.ecx = 0; tss_b.edx = 0; tss_b.ebx = 0; tss_b.esp = task_b_esp; tss_b.ebp = 0; tss_b.esi = 0; tss_b.edi = 0; tss_b.es = 2 * 8; tss_b.cs = 1 * 8; tss_b.ss = 2 * 8; tss_b.ds = 2 * 8; tss_b.fs = 2 * 8; tss_b.gs = 2 * 8; int count = 0; mt_init(); for(;;){ count ++; _io_cli(); if(0 == (fifo32_status(&fifo) )){ _io_stihlt(); //_io_sti(); // too fast } else{ fifo_data = fifo32_get(&fifo); _io_sti(); if(256 <= fifo_data && fifo_data < 512){ // keyboard data if(fifo_data < 256 + 0x54){ if(keytable[fifo_data-256] != 0){ s[0] = keytable[fifo_data-256]; s[1] = 0; putfont8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF,s, 1); cursor_x += 8; // next pos } if(fifo_data == 256 + 0x0e && cursor_x >= 8){ putfont8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF," ", 1); cursor_x -= 8; } // boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x+7, 43); // sheet_refresh(sht_win, cursor_x, 28, cursor_x+7, 43); } } else if(512 <= fifo_data && fifo_data < 768){ // mouse data // fifo_data -= 512; //have some error if (mouse_decode(&mdec,fifo_data - 512) != 0){ mx += mdec.x; my += mdec.y; if(mx < 0){ mx = 0; } if(my < 0){ my = 0; } if(mx > binfo->scrnx - 1){ mx = binfo->scrnx -1; } if(my > binfo->scrny - 1){ my = binfo->scrny -1; } sheet_slide(sht_mouse, mx, my); if( (mdec.btn & 0x01) != 0 && (mx > sht_win->vx0 && mx < (sht_win->vx0 + sht_win->bxsize)) && ( my > sht_win->vy0 - sht_win->bysize*2 && my < (sht_win->vy0 + sht_win->bysize * 2) ) ){ sheet_slide(sht_win, mx - 80, my - 8); } } } else if( fifo_data == 10){ putfont8_asc_sht(sht_back, 0, 140, COL8_FFFFFF, COL8_008484,"10[sec]", 7); itoa(s,count,MAX_LENGTH); putfont8_asc_sht(sht_back, 140, 28, COL8_000000, COL8_C6C6C6, s ,12 ); } else if( fifo_data == 3){ putfont8_asc_sht(sht_back, 100, 0, COL8_FFFFFF, COL8_008484,"3[sec]", 6); } else{ if(fifo_data != 0){ timer_init(timer3, &fifo, 0); boxfill8(buf_back, binfo->scrnx, COL8_FFFFFF, 8, 96, 15, 111); } else{ timer_init(timer3, &fifo, 1); boxfill8(buf_back, binfo->scrnx, COL8_008484, 8, 96, 15, 111); } timer_settime(timer3, 50); sheet_refresh(sht_back, 8, 96, 16, 112); } } } }