bool CapriceOpenDisk::HandleMessage(CMessage* pMessage)
{
	bool bHandled = false;
	if (pMessage)
	{
		switch(pMessage->MessageType())
        {
		case CMessage::CTRL_SINGLELCLICK:
		{
			if (pMessage->Destination() == this)
			{
				if (pMessage->Source() == m_pButtonCancel) {
					CloseFrame();
					CMessageServer::Instance().QueueMessage(new CMessage(CMessage::APP_EXIT, 0, this));
                    break;
                }
				if (pMessage->Source() == m_pButtonOpen) {
                    // Put selected ROM filename on button: (if there is a selection)
                    int selectedDiskIndex = m_pListBoxDisk->getFirstSelectedIndex();
                    if (selectedDiskIndex >= 0)
							{
                        DriveFile = (m_pListBoxDisk->GetItem(selectedDiskIndex)).sItemText;
                        if (selDrive) strncpy(CPC.drvB_file, DriveFile.c_str(), sizeof(CPC.drvB_file));
								else strncpy(CPC.drvA_file, DriveFile.c_str(), sizeof(CPC.drvA_file));
								std::string pchFile = DrivePath+DriveFile;
                        dsk_load(pchFile.c_str(),pDrive,'A');
								CloseFrame();
                        CMessageServer::Instance().QueueMessage(new CMessage(CMessage::APP_EXIT, 0, this));
                    }
                    break;
                }
				if (pMessage->Source() == m_pButtonClear)
				{
					if (selDrive)
					{
						strcpy(CPC.drvB_file, "");
					}
					else
					{
						strcpy(CPC.drvA_file, "");
					}
					dsk_eject(pDrive);
					CloseFrame();
					bHandled = true;
                    break;
                }
           		CMessageServer::Instance().QueueMessage(new CMessage(CMessage::APP_EXIT, 0, this));
			}
			break;
		}

		default :
			bHandled = CFrame::HandleMessage(pMessage);
			break;
		}
	}
	return bHandled;
}
bool CMessageBox::HandleMessage(CMessage* pMessage)
{
	bool bHandled = false;

	if (pMessage)
	{
    switch(pMessage->MessageType())
		{
		case CMessage::CTRL_SINGLELCLICK:
		{
			if (pMessage->Destination() == this)
			{
				for (std::map<EButton, CButton*>::iterator iter = m_ButtonMap.begin(); iter != m_ButtonMap.end(); ++iter)
				{
					if (pMessage->Source() == iter->second)
					{
						CMessageServer::Instance().QueueMessage(new CValueMessage<CMessageBox::EButton>(CMessage::CTRL_MESSAGEBOXRETURN, m_pParentWindow, nullptr, iter->first));
						CloseFrame();
            bHandled = true;
						break;
					}
				}
			}
			break;
		}
		default:
			break;
		}
		if (!bHandled)
		{
			bHandled = CFrame::HandleMessage(pMessage);
		}
	}

	return bHandled;
}
Beispiel #3
0
void Execute(void)
{
   Instruction I;
   int temp, temp1, temp2,temp3, Addr;
   char tempc;


    /* Start  here */
   I = StartInstruction;
   while (OpCodeOf(I) != HALTOP) 
   {
      if (TraceSpecified)
         TraceExecution(I);

      if (ValidOpCode(I)) 
      {
         switch (OpCodeOf(I)) 
         {
            case NOP     : break;

	    case LITOP   : PushLf(Operand1Of(I));
                           break;

	    case LLVOP   : PushLf(Lf(Operand1Of(I)));
                           break;

	    case LGVOP   : PushLf(Gf(Operand1Of(I)));
                           break;

            case SLVOP   : UpdateLf(Operand1Of(I),PopLf());
                           break;
 
            case SGVOP   : UpdateGf(Operand1Of(I),PopLf());
                           break;
 
            case LLIVOP  : PushLf(Gf(Lf(Operand1Of(I))));
                           break;
 
            case LGIVOP  : PushLf(Gf(Gf(Operand1Of(I))));
		    	   break;
 
            case SLIVOP  : UpdateGf(Lf(Operand1Of(I)),PopLf());
			   break;
 
            case SGIVOP  : UpdateGf(Gf(Operand1Of(I)),PopLf());
			   break;
 
            case LLAOP   : PushLf(LocalAddress(Operand1Of(I)));
			   break;
 
            case LGAOP   : PushLf(GlobalAddress(Operand1Of(I)));
			   break;

            case LUVOP   : Addr = LocalAddress(0);
                           for (temp = 1; temp <= Operand1Of(I); temp++) 
                           { 
                              if (Addr == 0) 
                              {
                                 fprintf(output,
                                         "TOO MANY FRAMES SPECIFIED IN LUV\n");
                                 FatalError();
	                      }
                              Addr = Gf(Addr);
                           }
                           PushLf(Gf(Addr + Operand2Of(I)));
		           break;

            case SUVOP   : Addr = LocalAddress(0);
                           for (temp = 1; temp <= Operand1Of(I); temp++) 
                           { 
                              if (Addr == 0)
                              {
                                 fprintf(output,
                                         "TOO MANY FRAMES SPECIFIED IN SUV\n");
                                 FatalError();
                              }
                              Addr = Gf(Addr);
                            }
                            UpdateGf (Addr+Operand2Of(I),PopLf());
                            break;

            case UOPOP   : temp = PopLf();
                           switch (Operand1Of(I)) 
                           {
                              case UNOT  : PushLf(1 - temp); 
                                           break;

                              case UNEG  : PushLf(- temp);
                                           break;

                              case USUCC : PushLf(temp + 1);
                                           break;

                              case UPRED : PushLf(temp - 1);
                                           break;
			    }
			    break;

	     case BOPOP   : temp2 = PopLf(); 
                            temp1 = PopLf();
                            if (ValidBinOp(I)) 
                            {
                               switch (Operand1Of(I)) 
                               {
                                  case BAND   : PushLf(temp1 * temp2);
                                                break;

                                  case BOR    : if ((temp1+temp2) > 0)
                                                   PushLf (1);
                                                else 
                                                   PushLf(0);
                                                break;

                                  case BPLUS  : PushLf(temp1 + temp2);
                                                break;

                                  case BMINUS : PushLf(temp1 - temp2);
                                                break;

                                  case BMULT  : PushLf(temp1 * temp2);
                                                break;

                                  case BDIV   : if (temp2 == 0) 
                                                {
                                                   fprintf(output,
                                                    "<<< MACHINE ERROR >>>: ");
                                                   fprintf(output,
                                                    "DIVISION BY ZERO.\n");
                                                   DumpMemory(output);
                                                   FatalError();
					        } 
                                                else 
                                                   PushLf(temp1 / temp2);
                                              
                                                break;

                                  case BEXP   : if (temp2 < 0) 
                                                {
                                                   fprintf(output,
                                                    "<<< MACHINE ERROR >>>: ");
                                                   fprintf(output,
                                                    "NEGATIVE EXPONENT. \n");
                                                   DumpMemory(output);
                                                   FatalError();
                                                } 
                                                else 
                                                {
                                                   temp = 1;
                                                   for (temp3=1; temp3<=temp2; temp3++)
                                                      temp = temp * temp1;
                                                   PushLf(temp);
					        }
					        break;

                                  case BMOD   : PushLf(temp1 % temp2);
                                                break;

                                  case BEQ    : if (temp1 ==  temp2)
                                                   PushLf(1);
                                                else
                                                   PushLf(0);
                                                break;

                                  case BNE    : if (temp1 != temp2) 
                                                   PushLf(1);
                                                else
                                                   PushLf(0);
                                                break;

                                  case BLE    : if (temp1 <= temp2)
                                                   PushLf(1);
                                                else
                                                   PushLf (0);
                                                break;

                                  case BGE    : if (temp1 >= temp2)
                                                   PushLf (1);
                                                else
                                                   PushLf (0);
                                                break;

                                  case BLT    : if (temp1 <  temp2)
                                                   PushLf(1);
                                                else
                                                   PushLf(0);
                                                break;

                                  case BGT    : if (temp1 >  temp2)
                                                   PushLf(1);
                                                else
                                                   PushLf(0);
                                                break;

			       } /* switch(Operand1Of(I)) */

			    } 
                            else 
                            {
                               fprintf(output,"<<< MACHINE ERROR >>>: ");
                               fprintf(output,"UNKNOWN OPERAND NAME: ");
    		               fprintf(TraceFile," %d ",Operand1Of(I));
                               fprintf(output,"\n");
                               DumpMemory(output);
                               FatalError();
		            }
		            break;

             case POPOP   : PopOffLf(Operand1Of(I));
                            break;
 
             case DUPOP   : PushLf(TopLf());
                            break;
 
             case SWAPOP  : temp1 = PopLf();
                            temp2 = PopLf();
                            PushLf(temp1);
                            PushLf(temp2);
		            break;

             case CALLOP  : PushReturnStack(I);
                            OpenFrame(Operand1Of(I));
                            I = PopLf() - 1;
		            break;
 
             case RTNOP   : temp = DepthLf() - Operand1Of(I);
                            if (temp > 0) 
                            {
                             for (temp1 = 0; temp1 <= (Operand1Of(I) - 1); temp1++)
                                UpdateLf(temp1, Lf(temp + temp1));

                             PopOffLf(temp);
		            }
                            I = PopReturnStack();
                            CloseFrame (Operand1Of(I));
			    break;
 
             case GOTOOP  : I = Operand1Of(I) - 1;
		  	    break;

             case CONDOP  : temp = PopLf();
                            if (temp == 0)
                               I = Operand2Of(I) - 1;
                            else
                               I = Operand1Of(I) - 1;
                            break;
 
             case CODEOP  : PushLf(Operand1Of(I));
                            break;
 
             case LIMITOP : temp2 = PopLf();  /* U */
                            temp1 = PopLf();  /* L */
                            temp  = PopLf();  /* X */
                            if ((temp >= temp1) && (temp <= temp2))
                               PushLf(temp);
                            else 
                            {
                               fprintf(output,"<<< MACHINE ERROR >>>: ");
                               fprintf(output,"VALUE OUT OF RANGE\n");
                               DumpMemory(output);
                               FatalError();
			    }
			    break;

             case SOSOP   : if (ValidOsOp(I)) 
                            {
                                switch (Operand1Of(I)) 
                                {
                                   case TRACEX  : if (TraceSpecified)
                                                     TraceSpecified = false;
                                                  else
                                                     TraceSpecified = true;
					          break;

                                   case DUMPMEM : DumpMemory(output);
                                                  break;

                                   case OSINPUT : fscanf(input," ");
					          if (feof(input)) { 
                                                     fprintf(output,
                                                      "<<< MACHINE ERROR >>>: ");
                                                     fprintf(output,
                                                      "TRIED TO READ PAST <EOF>\n");
                                                     DumpMemory(output);
                                                     FatalError();
                                                  } 
                                                  else 
                                                  {
                                                     fscanf(input,"%d",&temp);
                                                     PushLf(temp);
					          }
					          break;
 
                                  case OSINPUTC : fscanf(input," ");
					          if (feof(input)) 
                                                  {
                                                     fprintf(output,
                                                      "<<< MACHINE ERROR >>>: ");
                                                     fprintf(output,
                                                      "TRIED TO READ PAST <EOF>\n");
                                                     DumpMemory(output);
                                                     FatalError();
                                                  } 
                                                  else 
                                                  {
                                                     fscanf(input,"%c",&tempc);
                                                     PushLf(tempc);
					          }
					          break;
 
                                  case OSOUTPUT : temp = PopLf();
                                                  fprintf(output,"%d ",temp);
					          break;
 
                                  case OSOUTPUTC: tempc = PopLf();
                                                  fprintf(output,"%c",tempc);
					          break;
 
                                  case OSOUTPUTL: fprintf(output,"\n");
						  break;
 
                                  case OSEOF    : fscanf(input," ");
					          if (feof(input))
                                                     PushLf(1);
                                                  else
                                                     PushLf(0);
					          break;
                                }
			     } 
                             else 
                             {
                                fprintf(output,"%s","<<< MACHINE ERROR >>>: ");
                                fprintf(output,"%s%1d `",
                                        "UNKNOWN OPERAND NAME: ",Operand1Of(I));
    		                fprintf(TraceFile," %d ",Operand1Of(I));
                                fprintf(output, "` \n");
                                DumpMemory(output);
                                FatalError();
                             }
                             break;
	 } /* switch (OpCodeOf(I)) */
              
      } 
      else 
      {
         fprintf(output,"%s","<<< MACHINE ERROR >>>: ");
         fprintf(output,"%s","UNKNOWN OP CODE NAME: ");
    	 fprintf(output," %d ",OpCodeOf(I));
         fprintf(output,"\n");
         FatalError();
      }
 
      I++;
 
   }
}  
Beispiel #4
0
bool CapriceLoadSave::HandleMessage(CMessage* pMessage)
{
  bool bHandled = false;

  if (pMessage)
  {
    switch(pMessage->MessageType())
    {
      case CMessage::CTRL_SINGLELCLICK:
        {
          if (pMessage->Destination() == this)
          {
            if (pMessage->Source() == m_pCancelButton) {
              CloseFrame();
              bHandled = true;
              break;
            }
            if (pMessage->Source() == m_pLoadSaveButton) {
              bool actionDone = false;
              std::string filename = m_pFileNameValue->GetWindowText();
              if(!filename.empty()) {
                std::string directory = m_pDirectoryValue->GetWindowText();
                filename = directory + '/' + filename;
                switch (m_pActionValue->GetSelectedIndex()) {
                  case 0: // Load
                    {
                      DRIVE drive;
                      switch (m_pTypeValue->GetSelectedIndex()) {
                        case 0: // Drive A
                          drive = DSK_A;
                          actionDone = true;
                          CPC.current_dsk_path = directory;
                          break;
                        case 1: // Drive B
                          drive = DSK_B;
                          actionDone = true;
                          CPC.current_dsk_path = directory;
                          break;
                        case 2: // Snapshot
                          drive = OTHER;
                          actionDone = true;
                          CPC.current_snap_path = directory;
                          break;
                        case 3: // Tape
                          drive = OTHER;
                          actionDone = true;
                          CPC.current_tape_path = directory;
                          break;
                        case 4: // Cartridge
                          drive = OTHER;
                          actionDone = true;
                          CPC.current_cart_path = directory;
                          break;
                      }
                      if (actionDone) {
                        file_load(filename, drive);
                      }
                      if (m_pTypeValue->GetSelectedIndex() == 4) {
                        emulator_reset(false);
                      }
                      break;
                    }
                  case 1: // Save
                    // TODO(cpitrat): Ensure the proper extension is present in the filename, otherwise add it.
                    switch (m_pTypeValue->GetSelectedIndex()) {
                      case 0: // Drive A
                        std::cout << "Save dsk A: " << filename << std::endl;
                        dsk_save(filename, &driveA);
                        actionDone = true;
                        break;
                      case 1: // Drive B
                        std::cout << "Save dsk B: " << filename << std::endl;
                        dsk_save(filename, &driveB);
                        actionDone = true;
                        break;
                      case 2: // Snapshot
                        std::cout << "Save snapshot: " << filename << std::endl;
                        snapshot_save(filename);
                        actionDone = true;
                        break;
                      case 3: // Tape
                        {
                          std::cout << "Save tape: " << filename << std::endl;
                          // Unsupported
                          wGui::CMessageBox *pMessageBox = new wGui::CMessageBox(CRect(CPoint(m_ClientRect.Width() /2 - 125, m_ClientRect.Height() /2 - 30), 250, 60), this, nullptr, "Not implemented", "Saving tape not yet implemented", CMessageBox::BUTTON_OK);
                          pMessageBox->SetModal(true);
                          //tape_save(filename);
                          break;
                        }
                      case 4: // Cartridge
                        {
                          std::cout << "Save cartridge: " << filename << std::endl;
                          // Unsupported
                          wGui::CMessageBox *pMessageBox = new wGui::CMessageBox(CRect(CPoint(m_ClientRect.Width() /2 - 125, m_ClientRect.Height() /2 - 30), 250, 60), this, nullptr, "Not implemented", "Saving cartridge not yet implemented", CMessageBox::BUTTON_OK);
                          pMessageBox->SetModal(true);
                          //cpr_save(filename);
                          break;
                        }
                    }
                    break;
                }
              }
              if(actionDone) {
                CloseFrame();
              }
              bHandled = true;
              break;
            }
          }
        }
        break;

      case CMessage::CTRL_VALUECHANGE:
        if (pMessage->Destination() == m_pActionValue) {
          switch (m_pActionValue->GetSelectedIndex()) {
            case 0: // Load
              m_pLoadSaveButton->SetWindowText("Load");
              m_pFileNameValue->SetReadOnly(true);
              break;
            case 1: // Save
              m_pLoadSaveButton->SetWindowText("Save");
              m_pFileNameValue->SetReadOnly(false);
              break;
          }
        }
        if (pMessage->Destination() == m_pTypeValue) {
          switch (m_pTypeValue->GetSelectedIndex()) {
            case 0: // Drive A
              m_pDirectoryValue->SetWindowText(simplifyDirPath(CPC.current_dsk_path));
#ifndef WITH_IPF
              m_fileSpec = { ".dsk", ".zip" };
#else
              m_fileSpec = { ".dsk", ".ipf", ".zip" };
#endif
              UpdateFilesList();
              break;
            case 1: // Drive B
              m_pDirectoryValue->SetWindowText(simplifyDirPath(CPC.current_dsk_path));
              m_fileSpec = { ".dsk", ".zip" };
              UpdateFilesList();
              break;
            case 2: // Snapshot
              m_pDirectoryValue->SetWindowText(simplifyDirPath(CPC.current_snap_path));
              m_fileSpec = { ".sna", ".zip" };
              UpdateFilesList();
              break;
            case 3: // Tape
              m_pDirectoryValue->SetWindowText(simplifyDirPath(CPC.current_tape_path));
              m_fileSpec = { ".cdt", ".voc", ".zip" };
              UpdateFilesList();
              break;
            case 4: // Cartridge
              m_pDirectoryValue->SetWindowText(simplifyDirPath(CPC.current_cart_path));
              m_fileSpec = { ".cpr", ".zip" };
              UpdateFilesList();
              break;
          }
        }
        if (pMessage->Source() == m_pFilesList) {
          int idx = m_pFilesList->getFirstSelectedIndex();
          std::string fn;
          if (idx != -1) {
            fn = m_pFilesList->GetItem(idx).sItemText;
          }
          if(!fn.empty() && fn[fn.size()-1] == '/') {
            m_pDirectoryValue->SetWindowText(simplifyDirPath(m_pDirectoryValue->GetWindowText() + '/' + fn));
            m_pFileNameValue->SetWindowText("");
            UpdateFilesList();
          } else {
            m_pFileNameValue->SetWindowText(fn);
          }
        }
        break;

      default :
        break;
    }
  }
  if (!bHandled) {
    bHandled = CFrame::HandleMessage(pMessage);
  }
  return bHandled;
}
Beispiel #5
0
bool CapriceMemoryTool::HandleMessage(CMessage* pMessage)
{
	bool bHandled = false;

	if (pMessage)
	{
		switch(pMessage->MessageType())
		{
      case CMessage::CTRL_SINGLELCLICK:
        {
          if (pMessage->Destination() == this)
          {
            if (pMessage->Source() == m_pButtonPoke) {
              std::string adress = m_pPokeAdress->GetWindowText();
              std::string value  = m_pPokeValue->GetWindowText();
              unsigned int pokeAdress = strtol(adress.c_str(), NULL, 16);
              int pokeValue           = strtol(value.c_str(),  NULL, 16);
              if(!adress.empty() && !value.empty() && pokeAdress < 65536 && pokeValue >= -128 && pokeValue <= 255) {
                std::cout << "Poking " << pokeAdress << " with " << pokeValue << std::endl;
                pbRAM[pokeAdress] = pokeValue;
                UpdateTextMemory();
              } else {
                std::cout << "Cannot poke " << adress << "(" << pokeAdress << ") with " << value << "(" << pokeValue << ")" << std::endl;
              }
              bHandled = true;
              break;
            }
            if (pMessage->Source() == m_pButtonDisplay) {
              std::string display = m_pAdressValue->GetWindowText();
              if(display.empty()) {
                m_displayValue = -1;
              } else {
                m_displayValue = strtol(display.c_str(), NULL, 16);
              }
              m_filterValue = -1;
              std::cout << "Displaying adress " << m_displayValue << " in memory." << std::endl;
              UpdateTextMemory();
              bHandled = true;
              break;
            }
            if (pMessage->Source() == m_pButtonFilter) {
              m_displayValue = -1;
              std::string filter = m_pFilterValue->GetWindowText();
              if(filter.empty()) {
                m_filterValue = -1;
              } else {
                m_filterValue = strtol(filter.c_str(), NULL, 16);
              }
              std::cout << "Filtering value " << m_filterValue << " in memory." << std::endl;
              UpdateTextMemory();
              bHandled = true;
              break;
            }
            if (pMessage->Source() == m_pButtonCopy) {
              std::cout << m_pTextMemContent->GetWindowText() << std::endl;
            /* Requires SDL2
              if(SDL_SetClipboardText(m_pTextMemContent->GetWindowText().c_str()) < 0) {
                fprintf(stderr, "Error while copying data to clipboard: %s\n", SDL_GetError());
              }
              */
              bHandled = true;
              break;
            }
            if (pMessage->Source() == m_pButtonClose) {
              CloseFrame();
              bHandled = true;
              break;
            }
            // handle further buttons and events...
            bHandled = CFrame::HandleMessage(pMessage);
          }
        }
        break;

      case CMessage::KEYBOARD_KEYDOWN:
        if(m_bVisible)
        {
          CKeyboardMessage* pKeyboardMessage = dynamic_cast<CKeyboardMessage*>(pMessage);
          if (pKeyboardMessage && pKeyboardMessage->Key == SDLK_TAB) {
            if(CApplication::Instance()->GetKeyFocus() == m_pPokeAdress) {
              CApplication::Instance()->SetKeyFocus(m_pPokeValue);
              bHandled = true;
              break;
            }
            if(CApplication::Instance()->GetKeyFocus() == m_pPokeValue) {
              CApplication::Instance()->SetKeyFocus(m_pAdressValue);
              bHandled = true;
              break;
            }
            if(CApplication::Instance()->GetKeyFocus() == m_pAdressValue) {
              CApplication::Instance()->SetKeyFocus(m_pFilterValue);
              bHandled = true;
              break;
            }
            if(CApplication::Instance()->GetKeyFocus() == m_pFilterValue) {
              CApplication::Instance()->SetKeyFocus(m_pPokeAdress);
              bHandled = true;
              break;
            }
          }
        }
        break;

      case CMessage::CTRL_VALUECHANGE:
        if (pMessage->Destination() == m_pBytesPerLine) {
          switch (m_pBytesPerLine->GetSelectedIndex()) {
            case 0:
              m_bytesPerLine = 1;
              break;
            case 1:
              m_bytesPerLine = 4;
              break;
            case 2:
              m_bytesPerLine = 8;
              break;
            case 3:
              m_bytesPerLine = 16;
              break;
            case 4:
              m_bytesPerLine = 32;
              break;
            case 5:
              m_bytesPerLine = 64;
              break;
          }
          UpdateTextMemory();
          bHandled = CFrame::HandleMessage(pMessage);
        }
        break;

      default :
        bHandled = CFrame::HandleMessage(pMessage);
        break;
    }
  }
	return bHandled;
}