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

📄 rcos.cpp

📁 一个嵌入式系统的C代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//*************************************************************************//  MODULE : RCOS main module - control loop for the supervisor.          *//  AUTHOR : Ron Chernich                                                 *//  PURPOSE: Create, run and destroy the RCOS operating system under a    *//           host operating system.                                       *//  HISTORY:                                                              *//   04-JUN-93 Dignified with a title block from the "T8" candidate code. *//   29-OCT-93 Individual pop-ups changed to a GP Message Box function.   *//   01-FEB-94 Dependency on integer size removed by typedef'ing bit lens *//   02-FEB-94 Anti-fascist mode window re-paint added for Xlib support   *//   25-AUG-94 All animation window responsibility given to Animator.     *//   15-MAR-95 User terminals managed through a class for beter config.   *//   22-MAR-95 Configurable options added via <Preferences> object        *//*************************************************************************#include <iostream.h>#include "rcos.hpp"#include "message.hpp"#include "exec.hpp"#include "kernel.hpp"#include "app.hpp"#include "tty.hpp"#include "mmu.hpp"#include "anim.hpp"#include "timer.hpp"#include "display.h"#include "dev-disp.hpp"#include "cpmfs.hpp"#include "prefs.hpp"///////////////// Button style for pop-up message box//enum mbStyle { MB_OK, MB_OKCANCEL, MB_YESNO, MB_YESCANCEL };enum mbRetrn { ID_OK = 200, ID_CANCEL, ID_YES, ID_NO };///////////////// Globals.. the simple App instantiation makes it all start happening,//char *pszInitl =  { "RCOS - Press F1 for help" };char *pszTitle =  { "RCOS - Ron's OS Simulator Mk IIb" };App  Rcos(pszInitl);//////////////////////// this struct combines the physical attributes of an IBM 3740, 8"// single side, single density disk and a Schugart Associates 880 drive.//static DPB _IBM3740 = {        26,     // sectors (number from one)        77,     // tracks (number from zero)        1,      // sides        128,    // bytes per sector        2,      // mS per rev (~ 360 RPM)        25,     // mS track to track        10,     // mS settle        1000    // soft (recoverable) error rate};                /////////////////// This struct says how to partition a 3740 diskette into the CP/M// standard Single Side, Single Density (SSSD) - which was the only// guaranteed interchange format in the late 70's.//static DPARAM _SSSD = {        0,      // Unit number        1,      // first sec number        26,     // no of sectors        6,      // sector skew factor        1024,   // diak allocation block size (bytes)        234,    // total blocks on disk        64,     // no of directory entries        0,      // none checked (treat as fixed disk)        2       // reserved (system) tracks};       ///////////////////////////////////////////////////////////////////////// local protos in order of appearance..//static UINT16 MessageBox (char*, char**, UINT16);static void   PaintCtrls (INT16);static void   PaintFixed (void);static void   DestroyCtrls (INT16);#ifdef DOS_ENV       void   main (void);		// g++ doesn't like it#endif///////////////////////////////////////////////////////////////////////// popup a Windows-like message box with supplied heading and text,// with appropriate controls.  The size of the box depends on the// passed array of string pointers.// RETURNS: ID of button pressed to close the window//UINT16 MessageBox (char *szTitle, char **pszText, UINT16 uStyle){  UINT32 lParam;  UINT16 msg, wParam;  INT16  n, x, y, x1, y1, x2, y2;  static char *pLab[] = { "&Ok", "&Cancel", "&Yes", "&No" };  for (x = 0, y = 0; pszText[y]; y++)    x = MAX(x, (INT16)GfxTextExtent(pszText[y]));  y2 = SYS_Height + PB_HT + (GfxTextHeight() * ++y) + 16;  x2 = 16 + ((uStyle > MB_OK) ? (PB_WID << 1) + 8 : PB_WID);  x2 = MAX(x2, x+16);  y1 = (WIN_Y2 - WIN_Y1 - y2) >> 1;  x1 = (WIN_X2 - WIN_X1 - x2) >> 1;  if (uStyle == MB_OK)    Rcos.AppChildWin(RC_Modal, szTitle, x1, y1, x1+x2, y1+y2);  else    Rcos.AppChildWin(RC_Modal, szTitle, x1, y1, x1+x2, y1+y2, _Red);  Mickey.AutoPointer(x1, y1, x1+x2, y1+y2);  switch (uStyle) {    case MB_OK:      Rcos.AppCreate(RC_PushBtn, ID_OK, pLab[0],        x1 + ((x2 - PB_WID) >> 1), y1 + y2 - PB_HT - 8, PB_WID, PB_HT);      break;    case MB_OKCANCEL:      Rcos.AppCreate(RC_PushBtn, ID_CANCEL, pLab[1],        x1 + 8, y1 + y2 - PB_HT - 8, PB_WID, PB_HT);      Rcos.AppCreate(RC_PushBtn, ID_OK, pLab[0],        x1 + x2 - PB_WID - 8, y1 + y2 - PB_HT - 8, PB_WID, PB_HT);      break;    case MB_YESCANCEL:      Rcos.AppCreate(RC_PushBtn, ID_CANCEL, pLab[1],        x1 + 8, y1 + y2 - PB_HT - 8, PB_WID, PB_HT);      Rcos.AppCreate(RC_PushBtn, ID_YES, pLab[2],        x1 + x2 - PB_WID - 8, y1 + y2 - PB_HT - 8, PB_WID, PB_HT);      break;    case MB_YESNO:      Rcos.AppCreate(RC_PushBtn, ID_NO, pLab[3],        x1 + 8, y1 + y2 - PB_HT - 8, PB_WID, PB_HT);      Rcos.AppCreate(RC_PushBtn, ID_YES, pLab[2],        x1 + x2 - PB_WID - 8, y1 + y2 - PB_HT - 8, PB_WID, PB_HT);      break;  }  GfxSetClip(x1, y1, x1+x2, y1+y2);  y = y1 + SYS_Height + 8;  n = 0;  while (pszText[n]) {    x = x1 + ((x2 - GfxTextExtent(pszText[n])) >> 1);    GfxText(x, y, pszText[n], GFX_Transparent);    y += GfxTextHeight();    ++n;  }  GfxClrClip();  Mickey.ShowPointer();  while (Rcos.AppGetMsg(msg, wParam, lParam) == FALSE)    ;  Rcos.AppDestroy(RC_PushBtn, ID_OK);  Rcos.AppDestroy(RC_PushBtn, ID_CANCEL);  Rcos.AppDestroy(RC_PushBtn, ID_NO);  Rcos.AppDestroy(RC_PushBtn, ID_YES);  Rcos.AppCloseWin();  KbdIn.KeyFlush(_ALT);  KbdIn.KeyFlush(_ASC);  return wParam;}//////////////////// Paint fixed supervisor objects.//static void PaintFixed (void){  GfxRect(STRIP_X1, STRIP_Y1, STRIP_X2, STRIP_Y2, GFX_Frame, _Black);  GfxRect(STRIP_X1, STRIP_Y1+1, STRIP_X2, STRIP_Y2-1, GFX_Fill, _White);  GfxTextColorBg(_Yellow);    GfxPattern(GFX_HalfTone);  GfxRect(STRIP_X1, STRIP_Y2+1, STRIP_X2, GFX_Ymin-1, GFX_Fill, _White);  GfxPattern(GFX_Solid);  GfxRect(CON_X1-1, CON_Y1-1, CON_X2+1, CON_Y2+1, GFX_Frame, _Black);}        ////////////////////// Initialize Control panel gadgets. Ideally, these should live in a// resource segment of the EXE file as binary data which is disgarded// after use.  Oh well..//static void PaintCtrls (INT16 n){  BOOL bMx[4];   PaintFixed();  bMx[0] = bMx[1] = bMx[2] = bMx[3] = FALSE;  bMx[n] = TRUE;  Rcos.AppCreate(RC_PushBtn, PB_RUN, "&Run", PB_X1,PB_Y1,PB_WID,PB_HT);  Rcos.AppCreate(RC_PushBtn, PB_PAUSE, "&Pause", PB_X1,PB_Y1+PB_DY, PB_WID, PB_HT);  Rcos.AppCreate(RC_PushBtn, PB_STEP, "&Step",  PB_X1,PB_Y1+(2*PB_DY),PB_WID,PB_HT);  Rcos.AppCreate(RC_PushBtn, PB_ABOUT, "&About", PB_X1,PB_Y1+(3*PB_DY),PB_WID,PB_HT);  Rcos.AppCreate(RC_RadioBtn, RB_PM, "&CPU Scheduler", 20, STRIP_Y0, bMx[0]);  Rcos.AppCreate(RC_RadioBtn, RB_MM, "&Memory Manager", 150, STRIP_Y0, bMx[1]);  Rcos.AppCreate(RC_RadioBtn, RB_RM, "R&esource Manager", 300, STRIP_Y0, bMx[2]);  Rcos.AppCreate(RC_RadioBtn, RB_DM, "&Devices", 460, STRIP_Y0, bMx[3]);  Rcos.AppCreate(RC_CheckBox, CB_CONF, "Co&nfirm", 560, STRIP_Y0, TRUE);}////////////////////// Kill off all controls//static void DestroyCtrls (INT16 nWin){  if (nWin == 3) {

⌨️ 快捷键说明

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