Example #1
0
//===========================================================================
void ResetMachineState () {
  DiskReset();		// Set floppymotoron=0
  g_bFullSpeed = 0;	// Might've hit reset in middle of InternalCpuExecute() - so beep may get (partially) muted

  MemReset();
  DiskBoot();
  VideoResetState();
  sg_SSC.CommReset();
  PrintReset();
  JoyReset();
  MB_Reset();
  SpkrReset();
//  SoundCore_SetFade(FADE_NONE);
}
//===========================================================================
void KeybQueueKeypress (int key, BOOL bASCII)
{
        static bool bFreshReset;

	if (bASCII == ASCII)
	{       
	        if (bFreshReset && key == 0x03) {
			bFreshReset = 0;
	                return; // Swallow spurious CTRL-C caused by CTRL-BREAK
	        }
	        bFreshReset = 0;
		if (key > 0x7F)
			return;

		if (apple2e) 
		        if (capslock && (key >= 'a') && (key <='z'))
		                keycode = key - 32;
		         else
			        keycode = key;
		else
                        if (key >= '`')
			        keycode = key - 32;
			else
			        keycode = key;

		lastvirtkey = LOBYTE(VkKeyScan(key));
	}
	else
	{
		if ((key == VK_CANCEL) && (GetKeyState(VK_CONTROL) < 0))
		{
			// Ctrl+Reset
			if (apple2e)
				MemResetPaging();

			DiskReset();
			KeybReset();
			if (apple2e)
			        VideoResetState();	// Switch Alternate char set off
			MB_Reset();

#ifndef KEY_OLD
			g_nNextInIdx = g_nNextOutIdx = g_nKeyBufferCnt = 0;
#endif

			CpuReset();
			bFreshReset = 1;
			return;
		}

		if ((key == VK_INSERT) && (GetKeyState(VK_SHIFT) < 0))
		{
			// Shift+Insert
			ClipboardInitiatePaste();
			return;
		}

		if (!((key >= VK_LEFT) && (key <= VK_DELETE) && asciicode[apple2e][key - VK_LEFT]))
			return;

		keycode = asciicode[apple2e][key - VK_LEFT];		// Convert to Apple arrow keycode
		lastvirtkey = key;
	}
#ifdef KEY_OLD
	keywaiting = 1;
#else
	bool bOverflow = false;

	if(g_nKeyBufferCnt < g_nKeyBufferSize)
		g_nKeyBufferCnt++;
	else
		bOverflow = true;

	g_nKeyBuffer[g_nNextInIdx].nVirtKey = lastvirtkey;
	g_nKeyBuffer[g_nNextInIdx].nAppleKey = keycode;
	g_nNextInIdx = (g_nNextInIdx + 1) % g_nKeyBufferSize;

	if(bOverflow)
		g_nNextOutIdx = (g_nNextOutIdx + 1) % g_nKeyBufferSize;
#endif
}
void Snapshot_LoadState()
{
	char szMessage[32 + MAX_PATH];

	APPLEWIN_SNAPSHOT* pSS = (APPLEWIN_SNAPSHOT*) new char[sizeof(APPLEWIN_SNAPSHOT)];

	try
	{
		if(pSS == NULL)
			throw(0);

		memset(pSS, 0, sizeof(APPLEWIN_SNAPSHOT));

		//

		HANDLE hFile = CreateFile(	g_szSaveStateFilename,
									GENERIC_READ,
									0,
									NULL,
									OPEN_EXISTING,
									FILE_ATTRIBUTE_NORMAL,
									NULL);

		if(hFile == INVALID_HANDLE_VALUE)
		{
			strcpy(szMessage, "File not found: ");
			strcpy(szMessage + strlen(szMessage), g_szSaveStateFilename);
			throw(0);
		}

		DWORD dwBytesRead;
		BOOL bRes = ReadFile(	hFile,
								pSS,
								sizeof(APPLEWIN_SNAPSHOT),
								&dwBytesRead,
								NULL);

		CloseHandle(hFile);

		if(!bRes || (dwBytesRead != sizeof(APPLEWIN_SNAPSHOT)))
		{
			// File size wrong: probably because of version mismatch or corrupt file
			strcpy(szMessage, "File size mismatch");
			throw(0);
		}

		if(pSS->Hdr.dwTag != AW_SS_TAG)
		{
			strcpy(szMessage, "File corrupt");
			throw(0);
		}

		if(pSS->Hdr.dwVersion != MAKE_VERSION(1,0,0,1))
		{
			strcpy(szMessage, "Version mismatch");
			throw(0);
		}

		// TO DO: Verify checksum

		//
		// Reset all sub-systems
		MemReset();

		if (apple2e)
			MemResetPaging();

		DiskReset();
		KeybReset();
		VideoResetState();
		MB_Reset();

		//
		// Apple2 uint
		//

		CpuSetSnapshot(&pSS->Apple2Unit.CPU6502);
		CommSetSnapshot(&pSS->Apple2Unit.Comms);
		JoySetSnapshot(&pSS->Apple2Unit.Joystick);
		KeybSetSnapshot(&pSS->Apple2Unit.Keyboard);
		SpkrSetSnapshot(&pSS->Apple2Unit.Speaker);
		VideoSetSnapshot(&pSS->Apple2Unit.Video);
		MemSetSnapshot(&pSS->Apple2Unit.Memory);

		//

		//
		// Slot4: Mockingboard
		MB_SetSnapshot(&pSS->Mockingboard1, 4);

		//
		// Slot5: Mockingboard
		MB_SetSnapshot(&pSS->Mockingboard2, 5);

		//
		// Slot6: Disk][
		DiskSetSnapshot(&pSS->Disk2, 6);
	}
	catch(int)
	{
		MessageBox(	g_hFrameWindow,
					szMessage,
					TEXT("Load State"),
					MB_ICONEXCLAMATION | MB_SETFOREGROUND);
	}

	delete [] pSS;
}
Example #4
0
//===========================================================================
void ProcessButtonClick (int button, int mod) {
// button - number of button pressed (starting with 0, which means F1
// mod - what modifiers been set (like CTRL, ALT etc.)
	SDL_Event qe;	// for Quitting and Reset

	SoundCore_SetFade(FADE_OUT); // sound/music off?

  switch (button) {

    case BTN_HELP:	// will get some help on the screen?
	    FrameShowHelpScreen(screen->w, screen->h);

//         TCHAR filename[MAX_PATH];
//         _tcscpy(filename,g_sProgramDir);
//         _tcscat(filename,TEXT("APPLEWIN.CHM"));
//         HtmlHelp(g_hFrameWindow,filename,HH_DISPLAY_TOC,0);
//         helpquit = 1;
      break;

    case BTN_RUN:	// F2 - Run that thing! Or Shift+2 ReloadConfig and run it anyway!
	if(mod & KMOD_SHIFT) {
		  restart = 1;	// keep up flag of restarting
		  qe.type = SDL_QUIT;
		  SDL_PushEvent(&qe);// push quit event
	}
	else {
      if (g_nAppMode == MODE_LOGO)
        DiskBoot();
      else if (g_nAppMode == MODE_RUNNING)
        ResetMachineState();
      if ((g_nAppMode == MODE_DEBUG) || (g_nAppMode == MODE_STEPPING))
        DebugEnd();
      g_nAppMode = MODE_RUNNING;
      DrawStatusArea(/*(HDC)0,*/DRAW_TITLE);
      VideoRedrawScreen();
      g_bResetTiming = true;
	}
      break;

    case BTN_DRIVE1:
    case BTN_DRIVE2:
	    if (mod & KMOD_SHIFT) {
		if(mod & KMOD_ALT)
			HD_FTP_Select(button - BTN_DRIVE1);// select HDV image through FTP
		else HD_Select(button - BTN_DRIVE1);	// select HDV image from local disk
	    }
      	    else {
		if(mod & KMOD_ALT) Disk_FTP_SelectImage(button - BTN_DRIVE1);//select through FTP
		else DiskSelect(button - BTN_DRIVE1); // select image file for appropriate disk drive(#1 or #2)
	    }
/*      if (!fullscreen)
        DrawButton((HDC)0,button);*/
      break;

    case BTN_DRIVESWAP:	// F5 - swap disk drives
      DiskDriveSwap();
      break;

    case BTN_FULLSCR:	// F6 - Fullscreen on/off
      if (fullscreen) { fullscreen = 0;
        SetNormalMode(); }
      else { fullscreen = 1;
        SetFullScreenMode();}
      break;

    case BTN_DEBUG:	// F7 - debug mode - not implemented yet? Please, see README about it. --bb
/*		if (g_nAppMode == MODE_LOGO)
		{
			ResetMachineState();
		}

		if (g_nAppMode == MODE_STEPPING)
		{
			DebuggerInputConsoleChar( DEBUG_EXIT_KEY );
		}
		else
		if (g_nAppMode == MODE_DEBUG)
		{
			g_bDebugDelayBreakCheck = true;
			ProcessButtonClick(BTN_RUN);
		}
		else
		{
			DebugBegin();
		}*/
      break;

    case BTN_SETUP:	// setup is in conf file - linapple.conf.
	    		// may be it should be implemented using SDL??? 0_0 --bb
	// Now Shift-F8 save settings changed run-tme in linapple.conf
	// F8 - save current screen as a .bmp file
	    // Currently these setting are just next:
	if(mod & KMOD_SHIFT) {
		RegSaveValue(TEXT("Configuration"),TEXT("Video Emulation"),1,videotype);
		RegSaveValue(TEXT("Configuration"),TEXT("Emulation Speed"),1,g_dwSpeed);
		RegSaveValue(TEXT("Configuration"),TEXT("Fullscreen"),1,fullscreen);
	}
	else {
		FrameSaveBMP();
	}

//      {
//		  PSP_Init();
      //}
      break;


////////////////////////// my buttons handlers F9..F12 ////////////////////////////
    case BTN_CYCLE: // F9 - CYCLE through allowed video modes
//	  printf("F9 has been pressed!\n");
	  videotype++;	// Cycle through available video modes
	  if (videotype >= VT_NUM_MODES)
		  videotype = 0;
	  VideoReinitialize();
	  if ((g_nAppMode != MODE_LOGO) || ((g_nAppMode == MODE_DEBUG) && (g_bDebuggerViewingAppleOutput))) // +PATCH
	  {
		  VideoRedrawScreen();
		  g_bDebuggerViewingAppleOutput = true;  // +PATCH
	  }

  	  break;
    case BTN_QUIT:	// F10 - exit from emulator?

		qe.type = SDL_QUIT;
		SDL_PushEvent(&qe);// push quit event
		break;	//

    case BTN_SAVEST:	// Save state (F11)
	    if(mod & KMOD_ALT) { // quick save
		    Snapshot_SaveState();
	    }
	  else
	  if(PSP_SaveStateSelectImage(true))
	  {
		  Snapshot_SaveState();
	  }
  	break;
    case BTN_LOADST:	// Load state (F12) or Hot Reset (Ctrl+F12)
	    if(mod & KMOD_CTRL) {
			// Ctrl+Reset
			if (!IS_APPLE2)
				MemResetPaging();

			DiskReset();
			KeybReset();
			if (!IS_APPLE2)
				VideoResetState();	// Switch Alternate char set off
			MB_Reset();
			CpuReset();
		}
	else if(mod & KMOD_ALT)	// quick load state
	{
		Snapshot_LoadState();
	}
    	else if(PSP_SaveStateSelectImage(false))
    	  {
	   	Snapshot_LoadState();
    	  }
	  break;
}//switch (button)
//////////////////////////////////////////// end of my buttons handlers //////////////////

  if((g_nAppMode != MODE_DEBUG) && (g_nAppMode != MODE_PAUSED))
  {
	  SoundCore_SetFade(FADE_IN);
  }
}
Example #5
0
void Snapshot_LoadState()
{
  char szMessage[32 + MAX_PATH];

  APPLEWIN_SNAPSHOT* pSS = (APPLEWIN_SNAPSHOT*) new char[sizeof(APPLEWIN_SNAPSHOT)];

  try
  {
    if(pSS == NULL)
      throw(0);

    memset(pSS, 0, sizeof(APPLEWIN_SNAPSHOT));

    //

/*    HANDLE hFile = CreateFile(  g_szSaveStateFilename,
                  GENERIC_READ,
                  0,
                  NULL,
                  OPEN_EXISTING,
                  FILE_ATTRIBUTE_NORMAL,
                  NULL);*/
    HANDLE hFile = (FILE*)fopen(g_szSaveStateFilename, "rb");

    if(hFile == INVALID_HANDLE_VALUE)
    {
      strcpy(szMessage, "File not found: ");
      strcpy(szMessage + strlen(szMessage), g_szSaveStateFilename);
      throw(0);
    }

    DWORD dwBytesRead;
    BOOL bRes = ReadFile(  hFile,
                pSS,
                sizeof(APPLEWIN_SNAPSHOT),
                &dwBytesRead,
                NULL);

    CloseHandle(hFile);

    if(!bRes || (dwBytesRead != sizeof(APPLEWIN_SNAPSHOT)))
    {
      // File size wrong: probably because of version mismatch or corrupt file
      strcpy(szMessage, "File size mismatch");
      throw(0);
    }

    if(pSS->Hdr.dwTag != (DWORD) AW_SS_TAG)
    {
      strcpy(szMessage, "File corrupt");
      throw(0);
    }

/* Let it be any version, never mind it! ^_^ */
     if(pSS->Hdr.dwVersion != MAKE_VERSION(1,0,0,1))
     {
       strcpy(szMessage, "Version mismatch");
       throw(0);
     }

    // TO DO: Verify checksum

    //
    // Reset all sub-systems
    MemReset();

    if (!IS_APPLE2)
      MemResetPaging();

    DiskReset();
    KeybReset();
    VideoResetState();
    MB_Reset();

    //
    // Apple2 uint
    //

    CpuSetSnapshot(&pSS->Apple2Unit.CPU6502);
    sg_SSC.CommSetSnapshot(&pSS->Apple2Unit.Comms);
    JoySetSnapshot(&pSS->Apple2Unit.Joystick);
    KeybSetSnapshot(&pSS->Apple2Unit.Keyboard);
    SpkrSetSnapshot(&pSS->Apple2Unit.Speaker);
    VideoSetSnapshot(&pSS->Apple2Unit.Video);
    MemSetSnapshot(&pSS->Apple2Unit.Memory);

    //

    //
    // Slot4: Mockingboard
    MB_SetSnapshot(&pSS->Mockingboard1, 4);

    //
    // Slot5: Mockingboard
    MB_SetSnapshot(&pSS->Mockingboard2, 5);

    //
    // Slot6: Disk][
    DiskSetSnapshot(&pSS->Disk2, 6);

    // Hmmm. And SLOT 7 (HDD1 and HDD2)? Where are they??? -- beom beotiger ^_^
  }
  catch(int)
  {
/*    MessageBox(  g_hFrameWindow,
          szMessage,
          TEXT("Load State"),
          MB_ICONEXCLAMATION | MB_SETFOREGROUND);*/
    fprintf(stderr, "%s\n", szMessage); // instead of wndzoooe messagebox let's use powerful stderr
  }

  delete [] pSS;
}
Example #6
0
VOID main(COUNT argc, char **argv)
{
  if (argc != 2)
  {
    fprintf(stderr, "Usage: %s drive\n drive = A,B,etc.\n", pgm);
    exit(1);
  }

  drive = *argv[1] - (islower(*argv[1]) ? 'a' : 'A');
  if (drive < 0 || drive >= NDEV)
  {
    fprintf(stderr, "%s: drive out of range\n", pgm);
    exit(1);
  }

  if (!DiskReset(drive))
  {
    fprintf(stderr, "%s: cannot reset drive %c:",
            drive, 'A' + drive);
    exit(1);
  }

  get_boot(drive);

  if (!check_space(drive, oldboot))
  {
    fprintf(stderr, "%s: Not enough space to transfer system files\n", pgm);
    exit(1);
  }

#ifdef DEBUG
  if ((log = fopen("sys.log", "w")) == NULL)
  {
    printf("Can't write log file.\n");
    log = NULL;
  }
#endif

  printf("Writing boot sector...\n");
  put_boot(drive);

  printf("\nCopying KERNEL.SYS...");
  if (!copy(drive, "kernel.sys"))
  {
    fprintf(stderr, "\n%s: cannot copy \"KERNEL.SYS\"\n", pgm);
#ifdef DEBUG
    fclose(log);
#endif
    exit(1);
  }

  printf("\nCopying COMMAND.COM...");
  if (!copy(drive, "command.com"))
  {
    fprintf(stderr, "\n%s: cannot copy \"COMMAND.COM\"\n", pgm);
#ifdef DEBUG
    fclose(log);
#endif
    exit(1);
  }
  printf("\nSystem transfered.\n");
#ifdef DEBUG
  fclose(log);
#endif
  exit(0);
}
//===========================================================================
void KeybQueueKeypress (int key, BOOL bASCII)
{
	static bool bFreshReset = false;

	if (bASCII == ASCII)
	{
		if (bFreshReset && key == 0x03)
		{
			bFreshReset = false;
			return; // Swallow spurious CTRL-C caused by CTRL-BREAK
		}

		bFreshReset = false;
		if (key > 0x7F)
			return;

		if (!IS_APPLE2) 
		{
			P8Shift = false;
			if (g_bCapsLock && (key >= 'a') && (key <='z'))
			{
				P8Shift = true;
				keycode = key - 32;
			}
			else
			{
				keycode = key;
			}			

			//The latter line should be applied for Pravtes 8A/C only, but not for Pravets 82/M !!!			
			if ((g_bCapsLock == false) && (key >= 'A') && (key <='Z'))
			{
				P8Shift = true;
				if (g_Apple2Type == A2TYPE_PRAVETS8A) 
					keycode = key + 32;
			}

			//Remap some keys for Pravets82/M
			if (g_Apple2Type == A2TYPE_PRAVETS82)
			{
				if (key == 64) 
					keycode = 96;
				if (key == '^') 
					keycode = '~';

				if (g_bCapsLock == false) //cyrillic letters
				{
					if (key == '`') keycode = '^';
					if (key == 92) keycode = '@'; // \ to @	
					if (key == 124) keycode = 92;
				}
				else //(g_bCapsLock == true) //latin letters
				{
					if (key == 91) keycode = 123;
					if (key == 93) keycode = 125;
					if (key == 124) keycode = 92;
				}
			}
			if (g_Apple2Type == A2TYPE_PRAVETS8M)  //Pravets 8M charset is still uncertain
			{
				if (g_bCapsLock == false) //cyrillic letters
				{
					if (key == '[') keycode = '{';
					if (key == ']') keycode = '}';
					if (key == '`') keycode = '~'; //96= key `~
					if (key == 92) keycode = 96;
				}
				else //latin letters
				{
					if (key == '`') 
						keycode = '^'; //96= key `~
				}
			}
			//Remap some keys for Pravets8A/C, which has a different charset for Pravtes82/M, whose keys MUST NOT be remapped.
			if (g_Apple2Type == A2TYPE_PRAVETS8A) //&& (g_bCapsLock == false))
			{
				if (g_bCapsLock == false) //i.e. cyrillic letters
			    {
					if (key == '[') keycode = '{';
					if (key == ']') keycode = '}';
					if (key == '`') keycode = '~';
					if (key == 92) keycode = 96;
					if (GetCapsLockAllowed ()== true)
					{
						if ((key == 92) || (key == 124)) keycode = 96; //Ý to Þ
						//This shall be rewriten, so that enabling CAPS_LOCK (i.e. F10) will not invert these keys values)
						//The same for latin letters.
						if ((key == '{') || (key == '}') || (key == '~') || (key == 124) || (key == '^') ||  (key == 95))
							P8Shift = true;					
					}
				}
				else //i.e. latin letters
				{
					if (GetCapsLockAllowed()  == false)
					{
						if (key == '{') keycode = '[';
						if (key == '}') keycode = ']';
						if (key == 124) 
							keycode = 92;
						/*if (key == 92) 
							keycode = 124;*/
					//Characters ` and ~ cannot be generated in 7bit character mode, so they are replaced with
					}
					else
					{
						if (key == '{') keycode = 91;
						if (key == '}')	keycode = 93;
						if (key == 124)	keycode = 92;					
						if ((key == '[') || (key == ']') || (key == 92) || (key == '^') || (key == 95))
							P8Shift= true; 
						if (key == 96)	 //This line shall generate sth. else i.e. ` In fact. this character is not generateable by the pravets keyboard.
						{
							keycode = '^';
							P8Shift= true;
						}
						if (key == 126)	keycode = '^';
					}
				}
			}
		}
		else
		{
			if (g_Apple2Type == A2TYPE_PRAVETS8A)
			{
			}
			else
			{
				if (key >= '`')
					keycode = key - 32;
				else
					keycode = key;
			}
		}
		lastvirtkey = LOBYTE(VkKeyScan(key));
	} 
	else //(bASCII != ASCII)
	{
		if ((key == VK_CANCEL) && (GetKeyState(VK_CONTROL) < 0))
		{
			// Ctrl+Reset
			if (!IS_APPLE2)
				MemResetPaging();

			DiskReset();
			KeybReset();
			if (!IS_APPLE2)
				VideoResetState();	// Switch Alternate char set off
			MB_Reset();

#ifndef KEY_OLD
			g_nNextInIdx = g_nNextOutIdx = g_nKeyBufferCnt = 0;
#endif

			CpuReset();
			bFreshReset = true;
			return;
		}

		if ((key == VK_INSERT) && (GetKeyState(VK_SHIFT) < 0))
		{
			// Shift+Insert
			ClipboardInitiatePaste();
			return;
		}

		if (!((key >= VK_LEFT) && (key <= VK_DELETE) && asciicode[IS_APPLE2 ? 0 : 1][key - VK_LEFT]))
			return;

		keycode = asciicode[IS_APPLE2 ? 0 : 1][key - VK_LEFT];		// Convert to Apple arrow keycode
		lastvirtkey = key;
	}
#ifdef KEY_OLD
	keywaiting = 1;
#else
	bool bOverflow = false;

	if(g_nKeyBufferCnt < g_nKeyBufferSize)
		g_nKeyBufferCnt++;
	else
		bOverflow = true;

	g_nKeyBuffer[g_nNextInIdx].nVirtKey = lastvirtkey;
	g_nKeyBuffer[g_nNextInIdx].nAppleKey = keycode;
	g_nNextInIdx = (g_nNextInIdx + 1) % g_nKeyBufferSize;

	if(bOverflow)
		g_nNextOutIdx = (g_nNextOutIdx + 1) % g_nKeyBufferSize;
#endif
}