InverterProcess.cpp

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2004  Pentagram Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #include "pent_include.h"
00020 
00021 #include "InverterProcess.h"
00022 #include "Kernel.h"
00023 #include "GUIApp.h"
00024 
00025 #include "IDataSource.h"
00026 #include "ODataSource.h"
00027 
00028 static unsigned int states[] = { 0, 8, 63, 211, 493, 945, 1594, 2459, 3552,
00029                                                                  4870, 6406, 8139, 10042, 12078, 14207, 16384,
00030                                                                  18561, 20690, 22726, 24629, 26362, 27898,
00031                                                                  29216, 30308, 31174, 31823, 32274, 32556,
00032                                                                  32704, 32760, 32768,
00033                                                                  32775, 32831, 32979, 33261, 33713, 34362,
00034                                                                  35227, 36320, 37638, 39174, 40907, 42810,
00035                                                                  44846, 46975, 49152, 51328, 53457, 55494,
00036                                                                  57396, 59129, 60665, 61984, 63076, 63942,
00037                                                                  64591, 65042, 65324, 65472, 65528, 65536 };
00038 
00039 InverterProcess *InverterProcess::inverter = 0;
00040 
00041 // p_dynamic_class stuff 
00042 DEFINE_RUNTIME_CLASSTYPE_CODE(InverterProcess,Process)
00043 
00044 InverterProcess::InverterProcess()
00045         : Process()
00046 {
00047 
00048 }
00049 
00050 InverterProcess::InverterProcess(unsigned int target)
00051         : Process()
00052 {
00053         targetstate = target;
00054 }
00055 
00056 InverterProcess::~InverterProcess(void)
00057 {
00058         if (inverter == this)
00059                 inverter = 0;
00060 }
00061 
00062 bool InverterProcess::run(const uint32)
00063 {
00064         GUIApp* app = GUIApp::get_instance();
00065 
00066         unsigned int state = app->getInversion();
00067         if (state == targetstate) {
00068                 terminate();
00069         } else {
00070                 unsigned int i = 0;
00071                 while (states[i] <= state) i++;
00072                 app->setInversion(states[i]);
00073         }
00074 
00075         return false;
00076 }
00077 
00078 void InverterProcess::saveData(ODataSource* ods)
00079 {
00080         Process::saveData(ods);
00081         
00082         ods->write2(static_cast<uint16>(targetstate));
00083 }
00084 
00085 bool InverterProcess::loadData(IDataSource* ids, uint32 version)
00086 {
00087         if (!Process::loadData(ids, version)) return false;
00088         
00089         targetstate = ids->read2();
00090 
00091         inverter = this; //static
00092         return true;
00093 }
00094 
00095 // static
00096 ProcId InverterProcess::invertScreen()
00097 {
00098         if (inverter) {
00099                 if (inverter->targetstate == 0)
00100                         inverter->setTarget(0x8000);
00101                 else
00102                         inverter->setTarget(0);
00103                 return inverter->getPid();
00104         } else {
00105                 unsigned int target = 0x8000;
00106                 if (GUIApp::get_instance()->isInverted()) target = 0;
00107                 inverter = new InverterProcess(target);
00108                 return Kernel::get_instance()->addProcess(inverter);
00109         }
00110 }
00111 
00112 
00113 uint32 InverterProcess::I_invertScreen(const uint8* args,
00114                                                                            unsigned int /*argsize*/)
00115 {
00116         return invertScreen();
00117 }
00118 
00119 void InverterProcess::ConCmd_invertScreen(const Console::ArgvType &argv)
00120 {
00121         invertScreen();
00122 }

Generated on Fri Jul 27 22:27:20 2007 for pentagram by  doxygen 1.4.7