OSDN Git Service

first commit
[winexe-harib/winexe-harib.git] / haribote / timer.cpp
1 /* \83^\83C\83}\8aÖ\8cW */
2
3 #include "bootpack.h"
4 #include "timer.h"
5 #include "naskfunc.h"
6 #include "pic.h"
7 #include "screen.h"
8 #include "ThreadMan.h"
9 #define PIT_CTRL        0x0043
10 #define PIT_CNT0        0x0040
11
12 TIMERCTL timerctl;
13
14 void init_pit(void)
15 {
16         io_out8(PIT_CTRL, 0x34);
17
18         //0x04A9\82Å\96ñ1ms\82É\88ê\89ñint0x20\82ª\94­\8ds\82³\82ê\82é
19         //\82ªqemu\82Å\82Í10ms\88È\89º\82Ì\8eü\8aú\82É\90Ý\92è\82Å\82«\82È\82¢\82ç\82µ\82¢
20         io_out8(PIT_CNT0, 0xA9);
21         io_out8(PIT_CNT0, 0x04);
22         //io_out8(PIT_CNT0, 0x0);
23         //io_out8(PIT_CNT0, 0x0);
24         timerctl.count = 0;
25         timerctl.subcount = 0;
26         return;
27 }
28
29 extern "C" void inthandler20(int *esp)
30 {
31         io_out8(PIC0_OCW2, 0x60);       /* IRQ-00\8eó\95t\8a®\97¹\82ðPIC\82É\92Ê\92m */
32         timerctl.subcount++;
33         if(timerctl.subcount >= 55){
34                 timerctl.subcount = 0;
35                 timerctl.count++;
36                 //Screen::Inst().printf("t, %d\n", timerctl.count);
37         
38         if(timerctl.count == 50){
39                 WORD tr = 2;
40                 asm("str [eax]": :"a"(&tr));
41                 Screen::Inst().printf("test, %d\n", tr);
42                 ThreadMan::Inst().SwitchThread();
43         }
44         }
45         return;
46 }
47
48 unsigned long long timer_getbiostimer(){
49         return timerctl.count;//\96ñ55sm\82²\82Æ\82É\91\9d\82â\82¹\82Î\82æ\82¢
50 }