⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mcoutlib.c

📁 rtCell 实时微内核-具有下列功能: 1. 完全抢占的实时微内核结构
💻 C
字号:
/*
 *******************************************************************************
 *                      The real-time kernel "rtCell"                          *
 *              Copyright 2007 taowentao, allrights reserved.                  *
 * File : mcOutLib.c                                                           *
 * By   : taowentao            2007-05-20                                      *
 *******************************************************************************
 */

#include "giCell\mcOSLib\mcOutMM.c"
#define err_bg_clr 0x04  /* error message background color */
#define err_fg_clr 0x0f  /* error message forground color  */
#define no_bg_clr  0     /* no message background color    */

void _cdecl_ GUILock(void);
void _cdecl_ GUIUnLock(void);

/*
 *******************************************************************************
 *                  The Global functions needed by microKernel                 *
 *******************************************************************************
 */

typedef struct _TCB {    /* ?? bytes, word align */
    void * pTop1;
    void * pTop2;
    void * pProc;
    void * StkBtm;
    CWORD  Size;
} TCB;                   

static void saveFPStatus(TCB *pFPO)
{
    BYTE *pBuf = pFPO->StkBtm;

    asm push es;
    asm push bx;
    asm les bx, dword ptr pBuf;
    asm fnsave es:[bx];
    asm pop bx;
    asm pop es;
}

static void restoreFPStatus(TCB *pFPO)
{
    BYTE *pBuf = pFPO->StkBtm;

    asm push es;
    asm push bx;
    asm les bx, dword ptr pBuf;
    asm frstor es:[bx];
    asm pop bx;
    asm pop es;
}

void _cdecl_ mcSwitchFPTask(void *pCurTcb, void **ppCurFPO)
{
    if ((*ppCurFPO) == NULL) {
        asm fninit;
    } else {
        if ((*ppCurFPO) != pCurTcb) {
            saveFPStatus(*ppCurFPO);
        } else {
            puts("ERR: same task NO fp switch.");
            for (;;);
        }
    }

    restoreFPStatus(pCurTcb);
    (*ppCurFPO) = pCurTcb;
}

void _cdecl_ InitFPStatus(void)
{
    asm fninit;
}

/*
 *******************************************************************************
 *                  The Global functions needed by microKernel                 *
 *******************************************************************************
 */

/* These define our textpointer, our background and foreground
 * colors (attributes), and x and y cursor coordinates */
static WORD csr_x = 0, csr_y = 0;

void _cdecl_ puttextxy(int __x, int __y, const char far *__textstring);
/* Uses the above routine to output a string... */
void _cdecl_ puts(BYTE *text)
{
    puttextxy(csr_x, csr_y, text);
    csr_y += 12;
}

#include <stdlib.h>
void _cdecl_ putf(double db)
{
    BYTE str[32];
    int dec = 10;

    GUILock();
    puttextxy(csr_x, csr_y, gcvt(db, dec, str));
    csr_y += 12;
    GUIUnLock();
}

void _cdecl_ putie(DWORD nr, DWORD base)
{
    BYTE temp[8 * sizeof(long) / 3 + 2];
    static BYTE x2c_tab[]= "0123456789abcdef";
    int i;
    BYTE *p = &temp[8 * sizeof(long) / 3 + 1];
    *p = 0;

    for (i = 0; i < (8 * sizeof(long) / 3 + 2); i ++)
        temp[i] = 0;
    do {
        -- p;
        *p = x2c_tab[(CWORD)(nr % base)];
        nr /= base;
    } while (nr > 0);

    for (i = 0; p[i] == 0 && i < (8 * sizeof(long) / 3 + 2); i ++);
    if (i < (8 * sizeof(long) / 3 + 2))
        puts(&p[i]);
}

void _cdecl_ puti(DWORD nr)
{
    putie(nr, 10);
}  

/*
 *******************************************************************************
 *                  The Global functions needed by microKernel                 *
 *******************************************************************************
 */

⌨️ 快捷键说明

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