timer.cpp

来自「SimpleGraphicOperatingSystem 32位图形化操作系统 」· C++ 代码 · 共 45 行

CPP
45
字号
#include <OsDef.h>
#include <System.h>
#include <Api.h>	//Sgos api

namespace System{
    static int timerNum = 0;
    static TimerProcedure procedures[MAX_PROCEDURE];

    bool Timer::SetTimer( TimerProcedure proc, int ms )
    {
        if( timerNum==MAX_PROCEDURE )
        {
            return -1;
        }
        procedures[timerNum] = proc;
        KSetTimer( timerNum, ms );
        timerNum++;
    }

    //Del
    bool Timer::DelTimer( TimerProcedure proc )
    {
        for( int i=0; i<timerNum; i++ )
        {
            if( procedures[i] == proc )
            {
                KDelTimer( i );
                timerNum--;
                procedures[i] = procedures[timerNum];
                procedures[timerNum] = ( TimerProcedure )0;
            }
        }
    }

    //switch and run
    int Timer::Switch( int i )
    {
        if ( procedures[i] )
            procedures[i]();
        else
            DPRINT("ERROR");
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?