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

📄 dbgmain.c

📁 program to simulate tank levels
💻 C
📖 第 1 页 / 共 2 页
字号:

               /* Blink the button red. */
               textbackground (DBG_SCRN_BTN_BLINK_COLOR);
               gotoxy (
                  DBG_SCRN_BTN_X + iColumn * DBG_SCRN_BTN_WIDTH,
                  DBG_SCRN_BTN_Y + iRow * DBG_SCRN_BTN_HEIGHT);
               cprintf ("%s", p_chButtonText[iRow][iColumn]);
               textbackground (BLACK);

               /* Fake a button interrupt. */
               vButtonInterrupt ();
               break;

            case '-':
               /* Reduce the level in the current tank. */
               a_iTankLevels[iTankChanging] -= 80;
               if (a_iTankLevels[iTankChanging] < 0)
                  a_iTankLevels[iTankChanging] = 0;
               vUtilityDisplayFloatLevels ();
               break;

            case '+':
               /* Increase the level in the current tank. */
               a_iTankLevels[iTankChanging] += 80;
               if (a_iTankLevels[iTankChanging] > 8000)
                  a_iTankLevels[iTankChanging] = 8000;
               vUtilityDisplayFloatLevels ();
               break;

            case 'x':
            case 'X':
               /* Restore the DOS timer interrupt vector */
               setvect(0x08, OldTickISR);

               /* End the program. */
               exit(0);
               break;

            case '>':
               /* Choose a different tank to modify */
               ++iTankChanging;
               if (iTankChanging IS COUNTOF_TANKS)
                  iTankChanging = COUNTOF_TANKS - 1;
               vUtilityDisplayFloatLevels ();
               break;

            case '<':
               /* Choose a different tank to modify */
               --iTankChanging;
               if (iTankChanging < 0)
                  iTankChanging = 0;
               vUtilityDisplayFloatLevels ();
               break;
         }
      }
      OSSemPost (semDOS);
   }
}



/*****   vDebugTimerTask   **************************************

This routine makes timer interrupts happen, if the tester wants.

RETURNS: None.

*/

static void far vDebugTimerTask(

/*
INPUTS:  */
   void *p_vData)
{

/*
LOCAL VARIABLES:  */

/*-------------------------------------------------------------*/

   /* Keep the compiler happy. */
   p_vData = p_vData;

   while (TRUE) 
   {
      OSTimeDly (6);
      if (fAutoTime)
         vTimerOneThirdSecond ();
   }
}

/*****   vUtilityDrawBox   **************************************

This routine draws a box.

RETURNS: None.

*/

static void vUtilityDrawBox (

/*
INPUTS:  */
   int ixNW,      /* x-coord of northwest corner of the box. */
   int iyNW,      /* y-coord of northwest corner of the box. */
   int ixSize,    /* Inside width of the box. */
   int iySize)    /* Inside height of the box. */
{

/*
LOCAL VARIABLES:  */
   int iColumn, iRow;

/*-------------------------------------------------------------*/

   /* Draw the top of the box. */
   gotoxy (ixNW, iyNW);
   cprintf ("%c", LINE_CORNER_NW);
   for (iColumn = 0; iColumn < ixSize; ++iColumn)
      cprintf ("%c", LINE_HORIZ);
   cprintf ("%c", LINE_CORNER_NE);

   /* Draw the sides. */
   for (iRow = 1; iRow <= iySize; ++iRow)
   {
      gotoxy (ixNW, iyNW + iRow);
      cprintf ("%c", LINE_VERT);
      gotoxy (ixNW + ixSize + 1, iyNW + iRow);
      cprintf ("%c", LINE_VERT);
   }

   /* Draw the bottom. */
   gotoxy (ixNW, iyNW + iySize + 1);
   cprintf ("%c", LINE_CORNER_SW);
   for (iColumn = 0; iColumn < ixSize; ++iColumn)
      cprintf ("%c", LINE_HORIZ);
   cprintf ("%c", LINE_CORNER_SE);
   
}  


/*****   vUtilityDisplayFloatLevels   ***************************

This routine displays the debug floats.

RETURNS: None.

*/

static void vUtilityDisplayFloatLevels (

/*
INPUTS:  */
   void)
{

/*
LOCAL VARIABLES:  */
   int iTank;        /* Iterator. */

/*-------------------------------------------------------------*/

   for (iTank = 0; iTank < COUNTOF_TANKS; ++iTank)
   {
      if (iTank IS iTankChanging)
         textbackground (BLUE);
      gotoxy (iTank * 8 + 10, DBG_SCRN_FLOAT_ROW);
      cprintf (" %4d ", iTank + 1);
      gotoxy (iTank * 8 + 10, DBG_SCRN_FLOAT_ROW + 1);
      cprintf ("      ", iTank + 1);
      gotoxy (iTank * 8 + 10, DBG_SCRN_FLOAT_ROW + 2);
      cprintf (" %4d ", a_iTankLevels[iTank]);
      textbackground (BLACK);
   }

   
}  

/*****   vUtilityPrinterDisplay   *******************************

This routine displays all printer output.

RETURNS: None.

*/

static void vUtilityPrinterDisplay (

/*
INPUTS:  */
   void)
{

/*
LOCAL VARIABLES:  */
   int i, j;         /* Iterators. */

/*-------------------------------------------------------------*/

   for (i = 0; i < DBG_SCRN_PRNTR_HEIGHT; ++i)
   {
      gotoxy (DBG_SCRN_PRNTR_X + 1, DBG_SCRN_PRNTR_Y + i + 1);
      for (j = 0; j < DBG_SCRN_PRNTR_WIDTH; ++j)
         cprintf (" ");
      gotoxy (DBG_SCRN_PRNTR_X + 1, DBG_SCRN_PRNTR_Y + i + 1);
      cprintf (aa_charPrinted[i]);
   }
}  

/*****   vHardwareDisplayLine   *********************************

This routine Displays on the debug screen whatever the system 
decides should be on the Display

RETURNS: None.

*/

void vHardwareDisplayLine (

/*
INPUTS:  */
   char *a_chDisp)      /* Character string to Display */
{

/*
LOCAL VARIABLES:  */
   BYTE byErr;       /* Place for OS to return an error. */

/*-------------------------------------------------------------*/

   /* Check that the length of the string is OK */
   ASSERT (strlen (a_chDisp) <= DBG_SCRN_DISP_WIDTH);

   /* Display the string. */
   OSSemPend (semDOS, WAIT_FOREVER, &byErr);
   gotoxy (DBG_SCRN_DISP_X + 1, DBG_SCRN_DISP_Y + 1);
   cprintf ("                    ");
   gotoxy (DBG_SCRN_DISP_X + 1, DBG_SCRN_DISP_Y + 1);
   cprintf ("%s", a_chDisp);
   OSSemPost (semDOS);

}


/*****   wHardwareButtonFetch   *********************************

This routine gets the button that has been pressed.

RETURNS: None.

*/

WORD wHardwareButtonFetch (

/*
INPUTS:  */
   void)
{

/*
LOCAL VARIABLES:  */

/*-------------------------------------------------------------*/

   return (toupper (wButton));
}


/*****   vHardwareFloatSetup   **********************************

This routine gets the float hardware looking for a reading.

RETURNS: None.

*/

void vHardwareFloatSetup  (

/*
INPUTS:  */
   int iTankNumber)
{

/*
LOCAL VARIABLES:  */

/*-------------------------------------------------------------*/

   /* Check that the parameter is valid. */
   ASSERT (iTankNumber >= 0 AND iTankNumber < COUNTOF_TANKS);

   /* The floats should not be busy. */
   ASSERT (iTankToRead IS NO_TANK);

   /* Remember which tank the system asked about. */
   iTankToRead = iTankNumber;
}


/*****   iHardwareFloatGetData   ********************************

This routine returns a float reading.

RETURNS: None.

*/

int iHardwareFloatGetData   (

/*
INPUTS:  */
   void)
{

/*
LOCAL VARIABLES:  */
   int iTankTemp;       /* Temporary tank number. */

/*-------------------------------------------------------------*/

   /* We must have been asked to read something. */
   ASSERT (iTankToRead >= 0 AND iTankToRead < COUNTOF_TANKS);

   /* Remember which tank the system asked about. */
   iTankTemp = iTankToRead;

   /* We're not reading anymore. */
   iTankToRead = NO_TANK;

   /* Return the tank reading. */
   return(a_iTankLevels[iTankTemp]);
   
}

/*****   vHardwareBellOn   **************************************

This routine turns on the alarm bell.

RETURNS: None.

*/

void vHardwareBellOn  (

/*
INPUTS:  */
   void)
{

/*
LOCAL VARIABLES:  */
   BYTE byErr;       /* Place for OS to return an error. */

/*-------------------------------------------------------------*/

   OSSemPend (semDOS, WAIT_FOREVER, &byErr);

   /* Set the bell color. */
   textbackground (RED);
   textcolor (BLINK + WHITE);

   /* Draw the bell. */
   gotoxy (DBG_SCRN_BELL_X+ 1, DBG_SCRN_BELL_Y + 1);
   cprintf ("          ");
   gotoxy (DBG_SCRN_BELL_X + 1, DBG_SCRN_BELL_Y + 2);
   cprintf ("   BELL   ");
   gotoxy (DBG_SCRN_BELL_X + 1, DBG_SCRN_BELL_Y + 3);
   cprintf ("          ");

   /* Reset the text color to normal. */
   textcolor (LIGHTGRAY);
   textbackground (BLACK);

   OSSemPost (semDOS);
}

/*****   vHardwareBellOff   *************************************

This routine turns on the alarm bell.

RETURNS: None.

*/

void vHardwareBellOff  (

/*
INPUTS:  */
   void)
{

/*
LOCAL VARIABLES:  */
   BYTE byErr;       /* Place for OS to return an error. */

/*-------------------------------------------------------------*/

   OSSemPend (semDOS, WAIT_FOREVER, &byErr);
   
   /* Draw the bell in plain text. */
   gotoxy (DBG_SCRN_BELL_X + 1, DBG_SCRN_BELL_Y + 1);
   cprintf ("          ");
   gotoxy (DBG_SCRN_BELL_X + 1, DBG_SCRN_BELL_Y + 2);
   cprintf ("   BELL   ");
   gotoxy (DBG_SCRN_BELL_X + 1, DBG_SCRN_BELL_Y + 3);
   cprintf ("          ");

   OSSemPost (semDOS);
}



/*****   vHardwarePrinterOutputLine   ***************************

This routine displays on the debug screen whatever the system 
decides should be printed.

RETURNS: None.

*/

void vHardwarePrinterOutputLine (

/*
INPUTS:  */
   char *a_chPrint)     /* Character string to print */
{

/*
LOCAL VARIABLES:  */
   int i;            /* The usual. */

/*-------------------------------------------------------------*/

   /* Check that the length of the string is OK */
   ASSERT (strlen (a_chPrint) <= DBG_SCRN_PRNTR_WIDTH);

   /* Move all the old lines up. */
   for (i = 1; i < DBG_SCRN_PRNTR_HEIGHT; ++i)
      strcpy (aa_charPrinted[i - 1], aa_charPrinted[i]);

   /* Add the new line. */
   strcpy (aa_charPrinted[DBG_SCRN_PRNTR_HEIGHT - 1], a_chPrint);

   /* Note that we need to interrupt. */
   iPrinting = 4;

   /* Redraw the printer. */
   vUtilityPrinterDisplay ();
   
}  


⌨️ 快捷键说明

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