Ejemplo n.º 1
0
/**
 * PSD画像のロード
 * @param filename ファイル名
 * @return ロードに成功したら true
 */
bool
PSD::load(ttstr filename)
{
	ttstr file = TVPGetPlacedPath(filename);
	if (!file.length()) {
		// 見つからなかったのでローカルパスとみなして読み込む
		psd::PSDFile::load(NarrowString(filename));
	} else {
#ifdef LOAD_MEMORY
		if (!wcschr(file.c_str(), '>')) {
			// ローカルファイルなので直接読み込む
			TVPGetLocalName(file);
			psd::PSDFile::load(NarrowString(file));
		} else {
			// メモリに読み込んでロード
			loadMemory(file);
		}
#else
		// ストリームとしてロード
		loadStream(file);
#endif
	}
	if (isLoaded) {
		addToStorage(filename);
	}
	return isLoaded;
}
Ejemplo n.º 2
0
/*
void resetMemory(unsigned char posNo)
{
	ee_write_value((unsigned char*)&ee_memoryPosition[posNo][0], (int16_t)ee_read_value(&flash_originalPosition[posNo][0]));
	ee_write_value((unsigned char*)&ee_memoryPosition[posNo][1], (int16_t)ee_read_value(&flash_originalPosition[posNo][1]));
	ee_write_value((unsigned char*)&ee_originalPosition[posNo][0], (int16_t)ee_read_value(&flash_originalPosition[posNo][0]));
	ee_write_value((unsigned char*)&ee_originalPosition[posNo][1], (int16_t)ee_read_value(&flash_originalPosition[posNo][1]));
#ifdef STORE_UBB
	ee_write_value(&ee_UBB[posNo], 0);
#endif
	
#ifdef STORE_MASSAGE
	ee_write_value(&ee_massage[posNo][0], 0);
	ee_write_value(&ee_massage[posNo][1], 0);
	ee_write_value(&ee_massage[posNo][2], 0);
#ifdef HAS_WAVE_BUTTON
	ee_write_value(&ee_waveStatus[posNo], 0);
#endif
#endif
}*/
void SteuerungFunkInit(void)
{
  unsigned char i;
  for(i = 0; i < 4; i++)
  {
    loadMemory(i);
#if defined STM8S003
    if(memPos[0] == 0 && memPos[1] == 0)
      restoreMemory(i);
#elif defined STM8S103
    if(memPos[0] == 0 && memPos[1] == 0)
      restoreMemory(i);
#endif
  }
  memPos[0] = MEM_OFF;
  memPos[1] = MEM_OFF;
}
Ejemplo n.º 3
0
void MainWindow::createActions()
{
    loadMemoryAction = new QAction(tr("&Load Memory from disk"),this);
    loadMemoryAction->setIcon(QIcon(":/images/loadMemory.png"));
    connect(loadMemoryAction, SIGNAL(triggered()), this, SLOT(loadMemory()));
    saveMemoryAction = new QAction(tr("&Save Memory to disk"),this);
    saveMemoryAction->setIcon(QIcon(":/images/saveMemory.png"));
    connect(saveMemoryAction, SIGNAL(triggered()), this, SLOT(saveMemory()));
    pasteCodeAction = new QAction(tr("&Paste Code"),this);
    pasteCodeAction->setIcon(QIcon(":/images/pasteCode.png"));
    connect(pasteCodeAction, SIGNAL(triggered()), this, SLOT(pasteCode()));
    quitAction = new QAction(tr("&Quit QtPom1"),this);
    quitAction->setIcon(QIcon(":/images/quit.png"));
    //quitAction->setIcon(QIcon(":/images/quit.png"));
    connect(quitAction, SIGNAL(triggered()), this, SLOT(quit()));

    resetAction = new QAction(tr("Soft &Reset"),this);
    resetAction->setIcon(QIcon(":/images/reset.png"));
    connect(resetAction, SIGNAL(triggered()), this, SLOT(reset()));
    hardResetAction = new QAction(tr("&Hard Reset"),this);
    hardResetAction->setIcon(QIcon(":/images/hardreset.png"));
    connect(hardResetAction, SIGNAL(triggered()), this, SLOT(hardReset()));
    debugCpuAction = new QAction(tr("&Debug Console"),this);
    debugCpuAction->setIcon(QIcon(":/images/debug.png"));
    connect(debugCpuAction, SIGNAL(triggered()), this, SLOT(debugCpu()));

    configScreenAction = new QAction(tr("&Screen Options"),this);
    configScreenAction->setIcon(QIcon(":/images/screen.png"));
    connect(configScreenAction, SIGNAL(triggered()), this, SLOT(configScreen()));
    configMemoryAction = new QAction(tr("&Memory Options"),this);
    configMemoryAction->setIcon(QIcon(":/images/memory.png"));
    connect(configMemoryAction, SIGNAL(triggered()), this, SLOT(configMemory()));

    aboutAction = new QAction(tr("&About QtPom1"),this);
    aboutAction->setIcon(QIcon(":/images/about.png"));
    connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
    aboutQtAction = new QAction(tr("About &Qt"),this);
    aboutQtAction->setIcon(QIcon(":/images/aboutQt.png"));
    connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
}
Ejemplo n.º 4
0
void main(int argc, char* argv[])
{
	bool singleClock = false;

	genAGCStates();
	MON::displayAGC();

	while(1)
	{
		// NOTE: assumes that the display is always pointing to the start of
		// a new line at the top of this loop!

	    // Clock the AGC, but between clocks, poll the keyboard
	    // for front-panel input by the user. This uses a Microsoft function;
    	// substitute some other non-blocking function to access the keyboard
    	// if you're porting this to a different platform.

		cout << "> "; cout.flush();  // display prompt

		while( !_kbhit() )
		{
			if(MON::FCLK || singleClock)
			{
					// This is a performance enhancement. If the AGC is running,
					// don't check the keyboard or simulator display every simulation
					// cycle, because that slows the simulator down too much.
				int genStateCntr = 100;
				do {
				    CLK::clkAGC(); 
					singleClock = false;

				    genAGCStates();
				    genStateCntr--;

						// This needs more work. It doesn't always stop at the
						// right location and sometimes stops at the instruction
						// afterwards, too.
					if(breakpointEnab && breakpoint == MBF::getEffectiveAddress())
					{
						MON::RUN = 0;
					}

						// Halt right after the instruction that changes a watched
						// memory location.
					if(watchEnab)
					{
						unsigned newWatchValue = MBF::readMemory(watchAddr);
						if(newWatchValue != oldWatchValue)
						{
							MON::RUN = 0;
						}
						oldWatchValue = newWatchValue;
					}


				} while (MON::FCLK && MON::RUN && genStateCntr > 0);

				updateAGCDisplay();

			}
			// for convenience, clear the single step switch on TP1; in the
			// hardware AGC, this happens when the switch is released
			if(MON::STEP && TPG::register_SG.read() == TP1) MON::STEP = 0;
		}
        char key = _getch();

	    // Keyboard controls for front-panel:
		switch(key)
		{
			// AGC controls
            // simulator controls

		case 'q': cout << "QUIT..." << endl; exit(0);
		case 'm': showMenu(); break;

		case 'd': 
			genAGCStates(); 
			MON::displayAGC(); 
			break; // update display

		case 'l': loadMemory(); break;
		case 'e': examineMemory(); break;

		case 'f':
			showSourceCode();
			break;

		case ']': 
			incrCntr(); 
			//genAGCStates();
			//displayAGC(EVERY_CYCLE);
			break;

		case '[': 
			decrCntr(); 
			//genAGCStates();
			//displayAGC(EVERY_CYCLE);
			break;

		case 'i': 
			interrupt(); 
			//genAGCStates();
			//displayAGC(EVERY_CYCLE);
			break;

		case 'z':
			//SCL::F17 = (SCL::F17 + 1) % 2; 
			genAGCStates();
			MON::displayAGC();
			break;

		case 'x':
			//SCL::F13 = (SCL::F13 + 1) % 2; 
			genAGCStates();
			MON::displayAGC();
			break;

		case 'r': 
			MON::RUN = (MON::RUN + 1) % 2; 
			genAGCStates();
			if(!MON::FCLK) MON::displayAGC();
			break;	

		case 's': 
			MON::STEP = (MON::STEP + 1) % 2; 
			genAGCStates();
			if(!MON::FCLK) MON::displayAGC();
			break;	

		case 'a': 
			MON::SA = (MON::SA + 1) % 2; 
			genAGCStates();
			MON::displayAGC();
			break;
			
		case 'n': 
			MON::INST = (MON::INST + 1) % 2; 
			genAGCStates();
			MON::displayAGC();
			break;	

		case 'p': 
			MON::PURST = (MON::PURST + 1) % 2;
			genAGCStates();
			MON::displayAGC();
			break;	

		case 'b':
			toggleBreakpoint();
			break;

		case 'y':
			toggleWatch();
			break;

		// DSKY:
		case '0': KBD::keypress(KEYIN_0); break;
		case '1': KBD::keypress(KEYIN_1); break;
		case '2': KBD::keypress(KEYIN_2); break;
		case '3': KBD::keypress(KEYIN_3); break;
		case '4': KBD::keypress(KEYIN_4); break;
		case '5': KBD::keypress(KEYIN_5); break;
		case '6': KBD::keypress(KEYIN_6); break;
		case '7': KBD::keypress(KEYIN_7); break;
		case '8': KBD::keypress(KEYIN_8); break;
		case '9': KBD::keypress(KEYIN_9); break;
		case '+': KBD::keypress(KEYIN_PLUS); break;
		case '-': KBD::keypress(KEYIN_MINUS); break;
		case '.': KBD::keypress(KEYIN_CLEAR); break;
		case '/': KBD::keypress(KEYIN_VERB); break;
		case '*': KBD::keypress(KEYIN_NOUN); break;
		case 'g': KBD::keypress(KEYIN_KEY_RELEASE); break;
		case 'h': KBD::keypress(KEYIN_ERROR_RESET); break;
		case 'j': KBD::keypress(KEYIN_ENTER); break;

		case '\0': // must be a function key
			key = _getch();
			switch(key)
			{
			case 0x3b: // F1: single clock pulse (when system clock off)
				singleClock = true; break;
		    case 0x3c: // F2: manual clock (FCLK=0)
				MON::FCLK = 0; genAGCStates(); MON::displayAGC(); break;
		    case 0x3e: // F4: fast clock (FCLK=1)
				MON::FCLK = 1; genAGCStates(); MON::displayAGC(); break;
			default: cout << "function key: " << key << "=" << hex << (int) key << dec << endl;
			}
			break;

		//default: cout << "??" << endl;
		default: cout << key << "=" << hex << (int) key << dec << endl;
		}
    }
}
Ejemplo n.º 5
0
void VM::runCycle ()
{
	updateOpcode ();

	switch (opcode)
	{
	case 0x01:
		transfer (A, B);
		break;
	case 0x02:
		transfer (B, A);
		break;
	case 0x03:
		transfer (A, C);
		break;
	case 0x04:
		transfer (C, A);
		break;
	case 0x05:
		transfer (B, C);
		break;
	case 0x06:
		transfer (C, B);
		break;
	case 0x07:
		A.data++;
		break;
	case 0x08:
		A.data--;
		break;
	case 0x09:
		B.data++;
		break;
	case 0x0A:
		B.data--;
		break;
	case 0x0B:
		C.data++;
		break;
	case 0x0C:
		C.data--;
		break;
	case 0x0D:
		A.data = A.data + B.data;
		break;
	case 0x0E:
		B.data = A.data + B.data;
		break;
	case 0x0F:
		A.data = A.data + C.data;
		break;
	case 0x10:
		C.data = A.data + C.data;
		break;
	case 0x11:
		B.data = B.data + B.data;
		break;
	case 0x12:
		C.data = B.data + C.data;
		break;
	case 0x13:
		A.data = A.data - B.data;
		break;
	case 0x14:
		A.data = A.data - C.data;
		break;
	case 0x15:
		B.data = B.data - A.data;
		break;
	case 0x16:
		B.data = B.data - C.data;
		break;
	case 0x17:
		C.data = C.data - A.data;
		break;
	case 0x18:
		C.data = C.data - B.data;
		break;
	case 0x19:
		A.data = A.data * B.data;
		break;
	case 0x1A:
		B.data = A.data * B.data;
		break;
	case 0x1B:
		A.data = A.data * C.data;
		break;
	case 0x1C:
		C.data = A.data * C.data;
		break;
	case 0x1D:
		B.data = B.data * C.data;
		break;
	case 0x1E:
		C.data = B.data * C.data;
		break;
	case 0x1F:
		A.data = A.data / B.data;
		break;
	case 0x20:
		A.data = A.data / C.data;
		break;
	case 0x21:
		B.data = B.data / A.data;
		break;
	case 0x22:
		B.data = B.data / C.data;
		break;
	case 0x23:
		C.data = C.data / A.data;
		break;
	case 0x24:
		C.data = C.data / B.data;
		break;
	case 0x25:
		updateOpcode ();
		A.data += opcode;
		break;
	case 0x26:
		updateOpcode ();
		A.data -= opcode;
		break;
	case 0x27:
		updateOpcode ();
		A.data *= opcode;
		break;
	case 0x28:
		updateOpcode ();
		A.data /= opcode;
		break;
	case 0x29:
		updateOpcode ();
		B.data += opcode;
		break;
	case 0x2A:
		updateOpcode ();
		B.data -= opcode;
		break;
	case 0x2B:
		updateOpcode ();
		B.data *= opcode;
		break;
	case 0x2C:
		updateOpcode ();
		B.data /= opcode;
		break;
	case 0x2D:
		updateOpcode ();
		C.data += opcode;
		break;
	case 0x2E:
		updateOpcode ();
		C.data -= opcode;
		break;
	case 0x2F:
		updateOpcode ();
		C.data *= opcode;
		break;
	case 0x30:
		updateOpcode ();
		C.data /= opcode;
		break;
	case 0x31:
		updateOpcode ();
		setMemory (opcode, A);
		break;
	case 0x32:
		updateOpcode ();
		setMemory (opcode, B);
		break;
	case 0x33:
		updateOpcode ();
		setMemory (opcode, C);
		break;
	case 0x34:
		updateOpcode ();
		loadMemory (opcode, A);
		break;
	case 0x35:
		updateOpcode ();
		loadMemory (opcode, B);
		break;
	case 0x36:
		updateOpcode ();
		loadMemory (opcode, C);
		break;
	case 0x37:
		updateOpcode ();
		proc.clearAll ();
		proc.data = A.data - opcode;
		break;
	case 0x38:
		if (proc.data == 0)
		{

		}
		break;
	default:
		break;
	}
}
Ejemplo n.º 6
0
void determineInstruction(char argument[], char instruction[]) {
    uint8_t byteInstruction;
    uint8_t byteArgument1;
    uint8_t byteArgument2 = NULL;

    int i = 0;
    char c = instruction[i];
    bool isLabel = false;

    while(c != '\0') {

        if(c == ':') {
            isLabel = true;
            instruction[i] = '\0';
            c = instruction[i];
        } else {
            c = instruction[++i];
        }

    }

    if(!isLabel) {
        int secondByteUsed = 0;
        int noArgument = 0;

        if (strlen(argument) < 1) {
            byteInstruction = getMachineCode(instruction, IMPLIED);

            noArgument = 1;
        }
            //FORMAT: LDA #$XX
        else if (argument[0] == '#') {
            char byte[3];
            char high = argument[2];
            char low = argument[3];

            byte[0] = high;
            byte[1] = low;
            byte[2] = '\0';

            byteArgument1 = stringToByte(byte);
            byteInstruction = getMachineCode(instruction, IMMEDIATE);

//        printf("Instruction used: %02x\n", byteInstruction);
//        printf("Value to load in accumulator: %02x\n\n", byteArgument1);
        }
            //FORMAT: STA $XXXX OR STA $XX
        else if (argument[0] == '$') {
            //if argument is 4 digits (0x0000)
            if(strlen(argument) > 3) {
                //need to get two memory locations here instead of just one
                char byteHigh[3];
                char byteLow[3];

                //get first part of the memory address
                char high = argument[1];
                char low = argument[2];
                byteHigh[0] = high;
                byteHigh[1] = low;

                high = argument[3];
                low = argument[4];
                byteLow[0] = high;
                byteLow[1] = low;

                byteLow[2] = '\0';
                byteHigh[2] = '\0';

                //little endian, low comes first
                byteArgument1 = stringToByte(byteLow);
                byteArgument2 = stringToByte(byteHigh);
                byteInstruction = getMachineCode(instruction, ABSOLUTE);

                secondByteUsed = 1;
            }
                //if argument is 2 digits (0x00) for zero page, etc.
            else {
                char byte[3];
                char high = argument[1];
                char low = argument[2];
                byte[0] = high;
                byte[1] = low;
                byte[2] = '\0';

                byteArgument1 = stringToByte(byte);
                byteInstruction = getMachineCode(instruction, ZEROPAGE);

                secondByteUsed = 0;
            }

        }
        else if (argument[0] == '(') {
            printf("new addressing shit pt 2\n\n");
        }
//        else if (argument[0] == 'A') {
//            printf("new addressing shit pt 3\n\n");
//        }
        else {
            //this is a label
            for(int i = 0; i < labelIterator; i++) {
                if(labels[i] == argument) {
                    uint8_t currentPC = programCounter;

                    //we have the location of where the label should start
                    //we need an offset from the next instruciton to that location
                    //so we increase programCounter by 2 (1 for this instruction, 1 for this argument)
                    //then subtract the location of the label from the program counter
                    //we now have the offset
                    //subtract offset from 256 now
                    currentPC += 2;
                    uint8_t location = labelLocations[i];
                    uint8_t offset = currentPC - location;

                    byteArgument1 = 256 - offset;
                    printf('test');
                }
            }
        }

        loadMemory(secondByteUsed, noArgument, byteInstruction, byteArgument1, byteArgument2);
    } else {
        //get the location of the next instruction to be executed
        uint8_t memoryLocation = programCounter + 1;
        labels[labelIterator] = instruction;
        labelLocations[labelIterator] = memoryLocation;
        labelIterator += 1;
    }
}
Ejemplo n.º 7
0
bool IPLFileIO::saveFile(const std::string path, IPLImage* image, int format, int flags, IPLImage* result, bool preview)
{
    int width = image->width();
    int height = image->height();

    FIBITMAP *dib = FreeImage_Allocate(width, height, 24);

    if(image->type() == IPLData::IMAGE_COLOR)
    {
        for(int y = 0; y < height; y++)
        {
            for(int x = 0; x < width; x++)
            {
                RGBQUAD rgb;
                rgb.rgbRed      = static_cast<BYTE>(image->plane(0)->p(x, y) * FACTOR_TO_UCHAR); // R
                rgb.rgbGreen    = static_cast<BYTE>(image->plane(1)->p(x, y) * FACTOR_TO_UCHAR); // G
                rgb.rgbBlue     = static_cast<BYTE>(image->plane(2)->p(x, y) * FACTOR_TO_UCHAR); // B
                FreeImage_SetPixelColor(dib, x, y, &rgb);
            }
        }
    }
    else
    {
        for(int y = 0; y < height; y++)
        {
            for(int x = 0; x < width; x++)
            {
                unsigned char value = image->plane(0)->p(x, y) * FACTOR_TO_UCHAR;
                RGBQUAD rgb;
                rgb.rgbRed      = value; // R
                rgb.rgbGreen    = value; // G
                rgb.rgbBlue     = value; // B
                FreeImage_SetPixelColor(dib, x, y, &rgb);
            }
        }
    }

    // all files need to be flipped
    FreeImage_FlipVertical(dib);

    bool success = false;

    if(preview)
    {
        // only save to memory for preview
        FIMEMORY* hmem = NULL;
        // open and allocate a memory stream
        hmem = FreeImage_OpenMemory();

        success = FreeImage_SaveToMemory((FREE_IMAGE_FORMAT)format, dib, hmem, flags) != 0;

        // write to result
        if(result)
        {
            loadMemory((void*)hmem, result);
        }

        //FreeImage_CloseMemory(hmem);

    }
    else
    {
        // actually save file
        success = FreeImage_Save((FREE_IMAGE_FORMAT)format, dib, path.c_str(), flags) != 0;

        // write to result
        if(result)
        {
            std::string information;
            loadFile(path, result, information);
        }
    }


    // free temporary memory
    FreeImage_Unload(dib);

    return success;
}
Ejemplo n.º 8
0
int RoccTest::parseOptions(int argc, char** argv) {
  opts_.argv0 = argv[0];
  int c;
  while (1) {
    static struct option long_options[] = {
      {"trace",      required_argument, 0,                'c'},
      {"debug",      no_argument,       0,                'd'},
      {"help",       no_argument,       0,                'h'},
      {"memory",     required_argument, 0,                'm'},
      {"no-fail",    no_argument,       &opts_.nofail,     1},
      {"timeout",    required_argument, 0,                't'},
      {"verbose",    no_argument,       0,                'v'},
      {0, 0, 0, 0}
    };
    int option_index = 0;
    c = getopt_long (argc, argv, "c:dhm:t:v", long_options, &option_index);
    if (c == -1)
      break;
    switch (c) {
      case 0:
        break;
      case 'c':
#if VM_TRACE
        opts_.filename_vcd = optarg;
        break;
#else
        std::cerr <<
            "[ERROR] Trace unsupported. Verilator needs the `--trace` arg to build an\n"
            "[ERROR]   executable that can emit VCD files (use `make debug`).\n";
        opts_.exit_code = -3;
        return opts_.exit_code;
#endif
      case 'd':
        verbose = true;
        break;
      case 'h':
        usage(argv[0]);
        opts_.exit_code = 0;
        return opts_.exit_code;
      case 'm':
        opts_.filename_mem = optarg;
        loadMemory(opts_.filename_mem);
        break;
      case 't':
        opts_.timeout = atoi(optarg) * 2;
        break;
      case 'v':
        opts_.verbose = true;
        break;
      default:
        printf("[ERROR] Bad command line option %d (%c)\n", c, c);
        opts_.exit_code = -2;
        return opts_.exit_code;
    }
  }

#if VM_TRACE
  Verilated::traceEverOn(true);
  VL_PRINTF("Enabling waves...\n");
  tfp_ = new VerilatedVcdC;
  t_->trace (tfp_, 99);
  if (opts_.filename_vcd) {
    tfp_->open(opts_.filename_vcd);
    if (verbose)
      std::cout << "[INFO] Writing VCD file" << opts_.filename_vcd << "\n";
  }
#endif

  return opts_.exit_code;
}
Ejemplo n.º 9
0
void doSteuerung(unsigned long* RfButtons)
{
	union Ergomation_keys_t keys;
	static union Ergomation_keys_t lastKeys;
//	static unsigned char storePosKeyCount;
//	static unsigned char storeComfortKeyCount;
	static unsigned char nasKeyCount = 0;
	static unsigned char lastNasTaster;
//	static unsigned char lastMemKey = 0;
//	static unsigned char lastComfortMemKey = 0;
//	enum KeyState_t lastState;
	union MData_t mData;
	static union MData_t mDataCurrent;
	unsigned char i;
	unsigned char drive;
	int16_t lastMemPos[NUM_MEM_DRIVES];
	//static signed char memoryStopped = 0;
	//static enum {none, memKeyPressed, memKeyStored} blinkMode;
//	static enum state_t currentState;
	
//	static enum usageMode_t oldSyncUsageMode = unknown;
	
#ifdef USE_TIMECOUNT
	unsigned int lastTimePos1;
	unsigned int lastTimePos2;
	static signed char useTimer[2];
	
#if (NUM_DRIVES != 2)
#error todo...
#endif
	
	if (((driveState[0] == moveDown) || (driveState[0] == moveUp))
	 && (inRushTimer[0] == 0))
	{
		if ((pulseTime[0] >= MIN_PULSE_TIME)	// normal ist 16 oder 17....
		 || ((syncActive != 0) && (syncPulseTime[0] >= MIN_PULSE_TIME)))
		{
			useTimer[0] = -1;
		} else
		{
			useTimer[0] = 0;
		}
	}

	if (((driveState[1] == moveDown) || (driveState[1] == moveUp))
	 && (inRushTimer[1] == 0))
	{
		if ((pulseTime[1] >= MIN_PULSE_TIME)	// normal ist 16 oder 17....
		 || ((syncActive != 0) && (syncPulseTime[1] >= MIN_PULSE_TIME)))
		{
			useTimer[1] = -1;
		} else
		{
			useTimer[1] = 0;
		}
	}
#endif


#ifdef __ICCAVR__
	TIMSK0	=	0;
#else
	//	TODO	pr黤en welche IRQs tats鋍hlich abgeschaltet werden m黶sen...
	//__disable_irq();
#endif
	
        
        if (syncActive == 0)
	{
		keys.data = *RfButtons;//getRFbuttons();
	} else
	{
		keys.data = syncKeysTransmitted;
		keys.data |= syncKeysReceived;
	};
	if (btActive != 0)
          keys.data |= syncBtKeysReceived;
	
        /////////////////////////////////// moving /////////////////////////////////////
	
#if (NUM_DRIVES < 4)
	mData.data		=	0;
#endif

	mData.m1up		=	keys.m1up;
	mData.m1down	=	keys.m1down;
	mData.m2up		=	keys.m2up;
	mData.m2down	=	keys.m2down;
	
#if (NUM_DRIVES >= 3)
	mData.m3up		=	keys.m3up;
	mData.m3down	=	keys.m3down;
#endif
#if (NUM_DRIVES >= 4)
	mData.m4up		=	keys.m4up;
	mData.m4down	=	keys.m4down;
#endif
/*	
	if (keys.resetUp != 0)
	{
		mData.m1up	=	1;
		mData.m2up	=	1;
		mData.m3up	=	1;
		mData.m4up	=	1;
	};
*/	
	if (/*(keys.resetDown != 0)
	 || */(NAS_KEY == 0)
	 || (allFlatTimer != 0))
	{
		mData.m1down	=	1;
		mData.m2down	=	1;
		mData.m3down	=	1;
		mData.m4down	=	1;
	};
	/////////////////////////////////// memory /////////////////////////////////////
	
	memcpy(lastMemPos, memPos, sizeof(lastMemPos));
#ifdef USE_TIMECOUNT
	lastTimePos1 = timePos[0];
	lastTimePos2 = timePos[1];
#endif
#ifdef REPROGRAMMABLE_MEMORY_POSITIONS

#ifdef USE_TIMECOUNT
#error USE_TIMECOUNT wird nicht unterst姒涚─t!
#endif
#ifdef ZERO_G_ONLY
#error ZERO_G_ONLY wird nicht unterst姒涚─t!
#endif
	
	
	if (lastKeys.data != keys.data)
	{
		if ((keys.data != 0)
		 && ((getMemoryActive() != 0) || (allFlatTimer != 0) || (automaticMovementIsActive != 0)))
		{
			stopMemory();
			allFlatTimer = 0;
			memset((void *)syncTimeout, 0, sizeof(syncTimeout));
			stopAll = active;
			memoryStopped = -1;
		}
		
		if ((keys.data & (KEY_MEMORY2 | KEY_MEMORY3 | KEY_MEMORY4)) != 0)
		{
			memTimer = MEM_STORE_DELAY;	//	Wartezeit f姒涳拷das Speichern setzen...
			blinkMode = none;			
		} else
		if (keys.data != 0)
		{
			memTimer = 0;

#ifndef   NEW_TIMER_LED_STATUS
			blinkMode = none;
#endif
		};
	};
 
	
	if (((keys.data & (KEY_ZERO_G | KEY_ALLFLAT)) == (KEY_ZERO_G | KEY_ALLFLAT))
	 && ((lastKeys.data & (KEY_ZERO_G | KEY_ALLFLAT)) != (KEY_ZERO_G | KEY_ALLFLAT)))
	{
		memoryStopped = -1;
		memTimer = MEM_RESTORE_DELAY;
		blinkMode = none;
	}

	if (((keys.data & (KEY_ZERO_G | KEY_ALLFLAT)) != (KEY_ZERO_G | KEY_ALLFLAT))
	 && ((lastKeys.data & (KEY_ZERO_G | KEY_ALLFLAT)) == (KEY_ZERO_G | KEY_ALLFLAT)))
	{
		memoryStopped = -1;
		memTimer = 0;
#ifndef   NEW_TIMER_LED_STATUS
			blinkMode = none;
#endif
	}
	
	if (keys.data == 0)
	{
		memTimer = 0;
#ifndef   NEW_TIMER_LED_STATUS
			blinkMode = none;
#endif
	};
	
	if (memTimer == 1)
	{
		if ((keys.data & (KEY_ZERO_G | KEY_ALLFLAT)) == (KEY_ZERO_G | KEY_ALLFLAT))
		{
			restoreMemory(1);
			restoreMemory(2);
			restoreMemory(3);
		} else
		{
/*			
			if (keys.zeroG != 0)
			{
				storeMemory(0);
			};
*/
			if (keys.memory2 != 0)
			{
				storeMemory(1);
			};
			if (keys.memory3 != 0)
			{
				storeMemory(2);
			};
			if (keys.memory4 != 0)
			{
				storeMemory(3);
			};
		};
		memTimer = 0;
		blinkMode = memKeyStored;
		blinkState = 0x2F;	//	3 mal blinken...
/*	} else
	if ((memTimer < 150)
	 && (memTimer > 1))
	{
		blinkMode = memKeyPressed;
*/	};
	
	if ((keys.data == 0)
	 && (lastKeys.data != 0))
	{
		if (memoryStopped != 0)
		{
			// nichts tun...
		} else
		if (lastKeys.zeroG != 0)
		{
			loadMemory(0);
		} else
		if (lastKeys.memory4 != 0)
		{
			loadMemory(3);
		} else
		if (lastKeys.memory3 != 0)
		{
			loadMemory(2);
		} else
		if (lastKeys.memory2 != 0)
		{
			loadMemory(1);
		} else
			if(lastKeys.angleAdjust != 0)
			{

				memPos[0] = syncBtpulseCounter[0];
				memPos[1] = syncBtpulseCounter[1];
			}else
		if (lastKeys.allFlat != 0)
		{
			allFlatTimer = 255;
			allFlatTimeoutTimer = 4000;	//	ca. 40 sekunden...
			
			//massageTimer = 0;
			//memset(massage_status, 0, sizeof(massage_status));
		} else
		if (lastKeys.data != 0)
		{
			stopMemory();
			allFlatTimer = 0;
		};
	};
	
	if (keys.data == 0)
	{		
		memoryStopped = 0;
	};
	
	
#else	//	#ifdef REPROGRAMMABLE_MEMORY_POSITIONS	
	if (lastKeys.data == 0)
	{
		if ((keys.data != 0)
		 && ((getMemoryActive() != 0) || (allFlatTimer != 0) || (automaticMovementIsActive != 0)))
		{
			stopMemory();
			allFlatTimer = 0;
			memset((void *)syncTimeout, 0, sizeof(syncTimeout));
			stopAll = active;
		} else		
		if (keys.zeroG != 0)
		{
			loadMemory(0);
#ifdef USE_TIMECOUNT
			ee2memcpy((char*) timePos, (__eeprom char*)ee_timePosition[0], sizeof(timePos));
#endif
	#ifndef ZERO_G_ONLY
		} else
		if (keys.memory4 != 0)
		{
			loadMemory(3);
#ifdef USE_TIMECOUNT
			ee2memcpy((char*) timePos, (__eeprom char*)ee_timePosition[3], sizeof(timePos));
#endif
		} else
		if (keys.memory3 != 0)
		{
			loadMemory(2);
#ifdef USE_TIMECOUNT
			ee2memcpy((char*) timePos, (__eeprom char*)ee_timePosition[2], sizeof(timePos));
#endif
		} else
		if (keys.memory2 != 0)
		{
			loadMemory(1);
#ifdef USE_TIMECOUNT
			ee2memcpy((char*) timePos, (__eeprom char*)ee_timePosition[1], sizeof(timePos));
#endif
	#endif
		} else
			if(keys.angleAdjust != 0)
			{
				memPos[0] = syncBtpulseCounter[0];
				memPos[1] =  syncBtpulseCounter[1];
			}
		else if (keys.allFlat != 0)
		{
//			if (lastKeys.data == 0)
//			{
//				if (allFlatTimer == 0)
//				{
					allFlatTimer = 255;
#ifdef USE_TIMECOUNT
					allFlatTimeoutTimer = 3000;	//	ca. 30 sekunden...
#else
					allFlatTimeoutTimer = 4000;	//	ca. 40 sekunden...
#endif
					
					//massageTimer = 0;
		//			MASSAGE_1 = 0;
		//			MASSAGE_2 = 0;
					//memset(massage_status, 0, sizeof(massage_status));
//				} else
//				{
//					allFlatTimer = 0;
//				};
//			};
		} else
		if (keys.data != 0)
		{
			stopMemory();
			allFlatTimer = 0;
		};

	};
	
#endif	//	#ifdef REPROGRAMMABLE_MEMORY_POSITIONS
	
#ifdef LP_STYLE_FUNCTIONALITY
	if (ee_read_value(&ee_usageMode) != pressAndRelease)
	{
		if (keys.data == 0)
		{
			stopMemory();
			allFlatTimer = 0;
		};
	};
#endif
	
#ifdef RAVEN
	if (ravenM3active == 0)
	{
		memPos[2] = MEM_OFF;
	}
#endif


//	if(keys.angleAdjust != 0 && keys.angleAdjust == lastKeys.angleAdjust)
//	{
	//	memPos[0] = syncBtpulseCounter[0][0];
	//	memPos[1] =  syncBtpulseCounter[1][0];
	//}

	if ((memcmp(lastMemPos, memPos, sizeof(memPos)) != 0)
#ifdef USE_TIMECOUNT
	 || (lastTimePos1 != timePos[0])
	 || (lastTimePos2 != timePos[1])
#endif
		 )
	{
		mDataCurrent.data = 0;
	};
	
	for (i = 0; i < NUM_MEM_DRIVES; i++)
	{
		if (memPos[i] == MEM_OFF)
		{
			mDataCurrent.m1 = 0;
		} else
		{
			mData.m1 = 0;

			if (mDataCurrent.m1 == 0)
			{
#ifdef USE_TIMECOUNT
				if (useTimer[i] != 0)
				{
					if (timePos[i] < timerCountGetCounter(i) - TIME_DIFF)
						mData.m1down = 1;
					if (timePos[i] > timerCountGetCounter(i) + TIME_DIFF)
						mData.m1up = 1;
				} else
				{
					if (memPos[i] < getPulseCounter(i) - POS_DIFF)
						mData.m1down = 1;
					if (memPos[i] > getPulseCounter(i) + POS_DIFF)
						mData.m1up = 1;
				}
#else
				if (memPos[i] < getPulseCounter(i) - POS_DIFF)
					mData.m1down = 1;
				if (memPos[i] > getPulseCounter(i) + POS_DIFF)
					mData.m1up = 1;
#endif

				mDataCurrent.m1 = mData.m1;
				moveToTimer[i] = 255;
			} else
			{
				mData.m1 = mDataCurrent.m1;

#ifdef USE_TIMECOUNT
				if (useTimer[i] != 0)
				{
					if (timePos[i] >= timerCountGetCounter(i))
						mData.m1down = 0;
					if (timePos[i] <= timerCountGetCounter(i))
						mData.m1up = 0;
					moveToTimer[i] = ALL_FLAT_PULSE_TIMEOUT;
				} else
				{
					if (memPos[i] >= getPulseCounter(i))
						mData.m1down = 0;
					if (memPos[i] <= getPulseCounter(i))
						mData.m1up = 0;
					if ((pulseTime[i] < PULSE_TIMEOUT)
					 || (driveState[i] == waitUp)
					 || (driveState[i] == waitDown))
						moveToTimer[i] = ALL_FLAT_PULSE_TIMEOUT;
				}
#else
				if (memPos[i] >= getPulseCounter(i))
					mData.m1down = 0;
				if (memPos[i] <= getPulseCounter(i))
					mData.m1up = 0;
				if ((pulseTime[i] < PULSETIME_MAX_VALUE)
				 || (driveState[i] == waitUp)
				 || (driveState[i] == waitDown))
					moveToTimer[i] = ALL_FLAT_PULSE_TIMEOUT;
#endif
			}
			
			if (mData.m1 == 0)
			{
				memPos[i] = MEM_OFF;
			}
		}
		
		if (moveToTimer[i] == 0)
		{
			memPos[i ] = MEM_OFF;
		};


		mData.data >>= 2;
		mDataCurrent.data >>= 2;
	}

	mData.data <<= (2 * NUM_MEM_DRIVES);
	mDataCurrent.data <<= (2 * NUM_MEM_DRIVES);
        
        
        	if ((keys.data == 0)
	 && (stopAll != inactive))
	{
		stopAll = setInactive;
	};
	
	if (stopAll != inactive)
	{
		stopMemory();
		allFlatTimer = 0;
		memset((void *)syncTimeout, 0, sizeof(syncTimeout));
		
		mData.data = 0;
		keys.data = 0;
	};
	
	if (stopAll == setInactive)
		stopAll = inactive;
	
/////////////////////////////////// massage ////////////////////////////////////
        
 /////////////////////////////////// teach-mode /////////////////////////////////
	
	if (keys.data != 0)
		nasKeyCount = 0;

	if ((NAS_KEY == 0)
	 && (lastNasTaster != 0))
	{
		strgKeyTimer = KEY_TIMEOUT;
		
		if (getTeachMode())
			clrTeachMode();
	}

	if ((NAS_KEY != 0)
	 && (lastNasTaster == 0)
	 && (strgKeyTimer != 0))
	{
		nasKeyCount++;
		strgKeyTimer = KEY_TIMEOUT;

		
		switch (nasKeyCount)
		{
		  case 2:
			setTeachMode();
			break;
/*			
		  case 3:
			clrTeachMode();
			break;
		  case 4:
			UBB = 1;
			break;
		  case 5:
			nrf_genRandomAddress();
			UBB = 0;
			nasKeyCount = 0;
			break;
*/
		};
	};
	
	lastNasTaster = NAS_KEY;
/////////////////////////////////// misc... ////////////////////////////////////

	
	
	if (allFlatTimeoutTimer == 0)
	{
		allFlatTimer = 0;
	};
	
	if ((allFlatTimer != 0)
	 && ((getPulseCounter(0) != 0)
	  || (getPulseCounter(1) != 0)
#if (NUM_DRIVES >= 3)
	  || (getPulseCounter(2) != 0)
#endif
#if (NUM_DRIVES >= 4)
	  || (getPulseCounter(3) != 0)
#endif
#ifdef USE_TIMECOUNT
	  || (timerCountGetCounter(0) != TIMERCOUNTER_RESETVALUE)
	  || (timerCountGetCounter(1) != TIMERCOUNTER_RESETVALUE)
#endif
		))
	{
		allFlatTimer = ALL_FLAT_PULSE_TIMEOUT;
	};

	if (((keys.ubb != 0) && (lastKeys.ubb == 0))
)//	 || ((keys.m1up != 0) && (keys.m1down != 0) && ((lastKeys.m1up == 0) || (lastKeys.m1down == 0))))
	{
		//UBB = ~UBB;
		UBB_toggle();
	};
	
	lastKeys.data = keys.data;

	if (strgKeyTimer == 0)
	{
//		storePosKeyCount = 0;
//		storeComfortKeyCount = 0;
//		updateLEDs(none);
		if (nasKeyCount == 4)
		{
			//UBB = 0;
			UBB_disable();
		}
		nasKeyCount = 0;
	};
	
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
        
        for (drive = 0; drive < NUM_DRIVES; drive++)
	{
		if ((mData.m1up != 0) && (mData.m1down == 0))
		{
			setPWMup(drive,255);
			syncTimeout[drive] = SYNC_TIMEOUT;
		} else
		if ((mData.m1up == 0) && (mData.m1down != 0))
		{
			setPWMdown(drive,255);
			syncTimeout[drive] = SYNC_TIMEOUT;
		} else
		{
			//setPWMdown(0,0);
#ifndef NO_SYNC
			if ((syncActive == 0)
			 || (syncTimeout[drive] == 0)                       //同步超时1.5S
                           || (pulseTime[drive] >= PULSETIME_MAX_VALUE)     //驱动器到两端,电流为0
//			 || (stopAll != inactive)
#ifdef USE_TIMECOUNT
			 || ((useTimer[drive] != 0)
			  && !((driveDirection[drive] == moving_down) && (timeCounterSync[drive] < (timerCountGetCounter(drive) - SYNC_OFFSET)))
			  && !((driveDirection[drive] == moving_up) && (timeCounterSync[drive] > (timerCountGetCounter(drive) + SYNC_OFFSET))))
			 || ((useTimer[drive] == 0)
			  && !((driveDirection[drive] == moving_down) && (pulseCounterSync[drive] < (getPulseCounter(drive) - SYNC_OFFSET)))
			  && !((driveDirection[drive] == moving_up) && (pulseCounterSync[drive] > (getPulseCounter(drive) + SYNC_OFFSET)))))
#else
			 ||	(!((driveDirection[drive] == moving_down) && (pulseCounterSync[drive] < (getPulseCounter(drive) - SYNC_OFFSET)))
			  && !((driveDirection[drive] == moving_up) && (pulseCounterSync[drive] > (getPulseCounter(drive) + SYNC_OFFSET)))))
#endif
#endif
			{
				setPWMdown(drive,0);
			}
		};
		
		mData.data >>= 2;
	}
	
	mData.data = 0;
  
}