Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

lptnote.cpp

Go to the documentation of this file.
00001 // $Id
00002 
00003 //**********************************************************************
00004 //                                                                     *
00005 //    Description:   Implementation using PC LPT port to ring a bell   *
00006 //                   for a single note.                                *
00007 //                                                                     *
00008 //    Author:        Chris White (whitecf@bcs.org.uk)                  *
00009 //                                                                     *
00010 //    Copyright (C) 2003  Monitor Computing Services Ltd.              *
00011 //                                                                     *
00012 //    This program is free software; you can redistribute it and/or    *
00013 //    modify it under the terms of the GNU General Public License      *
00014 //    as published by the Free Software Foundation; either version 2   *
00015 //    of the License, or any later version.                            *
00016 //                                                                     *
00017 //    This program is distributed in the hope that it will be useful,  *
00018 //    but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00019 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00020 //    GNU General Public License for more details.                     *
00021 //                                                                     *
00022 //    You should have received a copy of the GNU General Public        *
00023 //    License (http://www.gnu.org/copyleft/gpl.html) along with this   *
00024 //    program; if not, write to:                                       *
00025 //       The Free Software Foundation Inc.,                            *
00026 //       59 Temple Place - Suite 330,                                  *
00027 //       Boston, MA  02111-1307,                                       *
00028 //       USA.                                                          *
00029 //                                                                     *
00030 //**********************************************************************
00031 //                                                                     *
00032 //    Notes:                                                           *
00033 //                                                                     *
00034 //**********************************************************************
00035 
00036 #include <dos.h>
00037 
00038 #include <callback.h>
00039 #include <mytrace.h>
00040 #include <timeout.h>
00041 
00042 #include "lptnote.h"
00043 
00044 
00045 
00046 namespace Ut = Monitor::Utility;
00047 
00048 
00049 
00050 int    LptNote::busy = 0;
00051 
00052 
00053 LptNote::LptNote(int    newPortNumber, int    newPortBit)
00054 {
00055     _USEMYTRACE_("LptNote::LptNote(newPortNumber, newPortBit)")
00056 
00057 
00058     unsigned int    *lptPortTable((unsigned int*)0x408);
00059 
00060     lptPort = *(lptPortTable + (--newPortNumber));
00061 
00062     originalControlPort         = inportb(lptPort + 0x002);
00063     originalExtendedControlPort = inportb(lptPort + 0x402);
00064 
00065 
00066     outportb(lptPort, 0);
00067 
00068     // Ensure port is operating in SPP mode
00069     if (0x3BC != lptPort)
00070     {
00071         outportb((lptPort + 0x402), 0);
00072     }
00073     outportb((lptPort + 0x002), 0);
00074 
00075 
00076     bitOn  = 1 << newPortBit;
00077     bitOff = ~bitOn;
00078 }
00079 
00080 
00081 
00082 LptNote::~LptNote()
00083 {
00084     _USEMYTRACE_("LptNote::~LptNote()")
00085 
00086     outportb(lptPort, 0);
00087 
00088     // Restore port mode
00089     outportb((lptPort + 0x002), originalControlPort);
00090     if (0x3BC != lptPort)
00091     {
00092         outportb((lptPort + 0x402), originalExtendedControlPort);
00093     }
00094 }
00095 
00096 
00097 
00098 void
00099 LptNote::sound() const
00100 throw (Ut::Note::Busy)
00101 {
00102     _USEMYTRACE_("LptNote::sound()")
00103 
00104     if (busy)
00105     {
00106         throw Ut::Note::Busy();
00107     }
00108     else
00109     {
00110         busy = !0;
00111 
00112         // Turn on output bit
00113         outportb(lptPort, (bitOn | inportb(lptPort)));
00114 
00115         // Time length of energisation of bell
00116         new Ut::Timeout(Ut::ConstCallback< LptNote >(*this,
00117                                                      &LptNote::switchOff),
00118                         1,
00119                         "energisation time");
00120     }
00121 }
00122 
00123 
00124 
00125 void
00126 LptNote::switchOff() const
00127 {
00128     _USEMYTRACE_("LptNote::switchOff()")
00129 
00130     // Turn off output bit
00131     outportb(lptPort, (bitOff & inportb(lptPort)));
00132 
00133     busy = 0;
00134 }

Generated on Wed Oct 29 20:55:43 2003 for Bellmaster BC Turbo Vision by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002