|
|
1.1 root 1: /*
1.1.1.5 root 2: Hatari - shortcut.c
3:
1.1.1.16! root 4: This file is distributed under the GNU General Public License, version 2
! 5: or at your option any later version. Read the file gpl.txt for details.
1.1 root 6:
7: Shortcut keys
8: */
1.1.1.12 root 9: const char ShortCut_fileid[] = "Hatari shortcut.c : " __DATE__ " " __TIME__;
1.1 root 10:
1.1.1.2 root 11: #include <SDL.h>
12:
1.1 root 13: #include "main.h"
14: #include "dialog.h"
15: #include "audio.h"
1.1.1.10 root 16: #include "file.h"
17: #include "floppy.h"
1.1 root 18: #include "joy.h"
1.1.1.5 root 19: #include "m68000.h"
1.1 root 20: #include "memorySnapShot.h"
21: #include "reset.h"
22: #include "screen.h"
23: #include "screenSnapShot.h"
1.1.1.8 root 24: #include "configuration.h"
1.1 root 25: #include "shortcut.h"
1.1.1.10 root 26: #include "debugui.h"
1.1 root 27: #include "sound.h"
1.1.1.10 root 28: #include "sdlgui.h"
1.1.1.13 root 29: #include "video.h"
30: #include "avi_record.h"
1.1.1.14 root 31: #include "clocks_timings.h"
1.1.1.2 root 32:
1.1.1.8 root 33: static SHORTCUTKEYIDX ShortCutKey = SHORTCUT_NONE; /* current shortcut key */
1.1 root 34:
1.1.1.4 root 35:
1.1.1.2 root 36: /*-----------------------------------------------------------------------*/
1.1.1.9 root 37: /**
38: * Shortcut to toggle full-screen
39: */
1.1.1.5 root 40: static void ShortCut_FullScreen(void)
1.1 root 41: {
1.1.1.9 root 42: if (!bInFullScreen)
43: {
44: Screen_EnterFullScreen();
45: }
46: else
47: {
48: Screen_ReturnFromFullScreen();
49: }
1.1 root 50: }
51:
1.1.1.4 root 52:
53: /*-----------------------------------------------------------------------*/
1.1.1.9 root 54: /**
1.1.1.13 root 55: * Shortcut to toggle mouse grabbing mode
1.1.1.9 root 56: */
1.1.1.13 root 57: static void ShortCut_MouseGrab(void)
1.1 root 58: {
1.1.1.9 root 59: bGrabMouse = !bGrabMouse; /* Toggle flag */
1.1 root 60:
1.1.1.9 root 61: /* If we are in windowed mode, toggle the mouse cursor mode now: */
62: if (!bInFullScreen)
63: {
64: if (bGrabMouse)
65: {
66: SDL_WM_GrabInput(SDL_GRAB_ON);
67: }
68: else
69: {
70: SDL_WM_GrabInput(SDL_GRAB_OFF);
71: }
72: }
1.1 root 73: }
74:
1.1.1.4 root 75:
1.1.1.5 root 76: /*-----------------------------------------------------------------------*/
1.1.1.9 root 77: /**
78: * Shortcut to toggle YM/WAV sound recording
79: */
1.1.1.5 root 80: static void ShortCut_RecordSound(void)
1.1 root 81: {
1.1.1.9 root 82: /* Is working? */
83: if (bSoundWorking)
84: {
85: /* Are we currently recording? If so stop */
86: if (Sound_AreWeRecording())
87: {
88: /* Stop, and save */
89: Sound_EndRecording();
90: }
91: else
92: {
93: /* Begin recording */
94: Sound_BeginRecording(ConfigureParams.Sound.szYMCaptureFileName);
95: }
96: }
1.1 root 97: }
98:
1.1.1.5 root 99:
100: /*-----------------------------------------------------------------------*/
1.1.1.9 root 101: /**
102: * Shortcut to toggle screen animation recording
103: */
1.1.1.5 root 104: static void ShortCut_RecordAnimation(void)
1.1 root 105: {
1.1.1.9 root 106: /* Are we currently recording? If so stop */
1.1.1.13 root 107: if (Avi_AreWeRecording())
1.1.1.9 root 108: {
109: /* Stop */
1.1.1.13 root 110: Avi_StopRecording();
1.1.1.9 root 111: }
112: else
113: {
114: /* Start animation */
1.1.1.14 root 115: Avi_StartRecording ( ConfigureParams.Video.AviRecordFile , ConfigureParams.Screen.bCrop ,
116: ConfigureParams.Video.AviRecordFps == 0 ?
117: ClocksTimings_GetVBLPerSec ( ConfigureParams.System.nMachineType , nScreenRefreshRate ) :
118: (Uint32)ConfigureParams.Video.AviRecordFps << CLOCKS_TIMINGS_SHIFT_VBL ,
119: 1 << CLOCKS_TIMINGS_SHIFT_VBL ,
120: ConfigureParams.Video.AviRecordVcodec );
1.1.1.9 root 121: }
1.1 root 122: }
123:
1.1.1.4 root 124:
125: /*-----------------------------------------------------------------------*/
1.1.1.9 root 126: /**
127: * Shortcut to sound on/off
128: */
1.1.1.5 root 129: static void ShortCut_SoundOnOff(void)
1.1 root 130: {
1.1.1.9 root 131: /* Toggle sound on/off */
1.1.1.12 root 132: ConfigureParams.Sound.bEnableSound ^= true;
1.1.1.9 root 133:
134: /* And start/stop if need to */
135: if (!ConfigureParams.Sound.bEnableSound)
136: {
137: if (Sound_AreWeRecording())
138: Sound_EndRecording();
139: Audio_UnInit();
140: }
141: else
142: {
143: Audio_Init();
144: }
1.1 root 145: }
146:
1.1.1.5 root 147:
148: /*-----------------------------------------------------------------------*/
1.1.1.9 root 149: /**
1.1.1.10 root 150: * Shortcut to fast forward
1.1.1.9 root 151: */
1.1.1.10 root 152: static void ShortCut_FastForward(void)
1.1 root 153: {
1.1.1.9 root 154: /* If already on max speed, switch back to normal */
1.1.1.12 root 155: if (ConfigureParams.System.bFastForward == true)
1.1.1.9 root 156: {
157: /* Restore */
1.1.1.12 root 158: ConfigureParams.System.bFastForward = false;
1.1.1.9 root 159:
160: /* Reset the sound emulation variables: */
1.1.1.14 root 161: Sound_BufferIndexNeedReset = true;
1.1.1.9 root 162: }
163: else
164: {
165: /* Set maximum speed */
1.1.1.12 root 166: ConfigureParams.System.bFastForward = true;
1.1.1.9 root 167: }
1.1 root 168: }
169:
1.1.1.5 root 170:
171: /*-----------------------------------------------------------------------*/
1.1.1.9 root 172: /**
173: * Shortcut to 'Boss' key, ie minmize Window and switch to another application
174: */
1.1.1.5 root 175: static void ShortCut_BossKey(void)
1.1 root 176: {
1.1.1.9 root 177: /* If we are in full-screen, then return to a window */
178: Screen_ReturnFromFullScreen();
1.1.1.5 root 179:
1.1.1.9 root 180: if (bGrabMouse)
181: {
182: SDL_WM_GrabInput(SDL_GRAB_OFF);
1.1.1.12 root 183: bGrabMouse = false;
1.1.1.9 root 184: }
1.1.1.12 root 185: Main_PauseEmulation(true);
1.1.1.5 root 186:
1.1.1.9 root 187: /* Minimize Window and give up processing to next one! */
188: SDL_WM_IconifyWindow();
1.1 root 189: }
190:
1.1.1.4 root 191:
192: /*-----------------------------------------------------------------------*/
1.1.1.9 root 193: /**
1.1.1.12 root 194: * Shorcut to debug interface
1.1.1.10 root 195: */
1.1.1.12 root 196: static void ShortCut_Debug(void)
1.1.1.10 root 197: {
1.1.1.12 root 198: int running;
1.1.1.10 root 199:
1.1.1.12 root 200: /* Call the debugger */
201: running = Main_PauseEmulation(true);
1.1.1.15 root 202: DebugUI(REASON_USER);
1.1.1.12 root 203: if (running)
204: Main_UnPauseEmulation();
1.1.1.10 root 205: }
206:
207:
1.1.1.12 root 208: /*-----------------------------------------------------------------------*/
209: /**
210: * Shorcut to pausing
211: */
212: static void ShortCut_Pause(void)
213: {
214: if (!Main_UnPauseEmulation())
215: Main_PauseEmulation(true);
216: }
217:
1.1.1.10 root 218: /**
219: * Shorcut to load a disk image
220: */
221: static void ShortCut_InsertDisk(int drive)
222: {
223: char *selname, *zip_path = NULL;
224: const char *tmpname;
225:
226: if (SDLGui_SetScreen(sdlscrn))
227: return;
228:
229: if (ConfigureParams.DiskImage.szDiskFileName[drive][0])
230: tmpname = ConfigureParams.DiskImage.szDiskFileName[drive];
231: else
232: tmpname = ConfigureParams.DiskImage.szDiskImageDirectory;
233:
1.1.1.12 root 234: Main_PauseEmulation(true);
235: selname = SDLGui_FileSelect(tmpname, &zip_path, false);
1.1.1.10 root 236: if (selname)
237: {
238: if (File_Exists(selname))
1.1.1.11 root 239: Floppy_SetDiskFileName(drive, selname, zip_path);
1.1.1.10 root 240: else
241: Floppy_SetDiskFileNameNone(drive);
1.1.1.11 root 242:
243: if (zip_path)
244: free(zip_path);
1.1.1.10 root 245: free(selname);
1.1.1.11 root 246:
247: Floppy_InsertDiskIntoDrive(0);
1.1.1.10 root 248: }
249: Main_UnPauseEmulation();
250: }
251:
252:
253: /*-----------------------------------------------------------------------*/
254: /**
1.1.1.9 root 255: * Check to see if pressed any shortcut keys, and call handling function
256: */
1.1.1.8 root 257: void ShortCut_ActKey(void)
1.1.1.5 root 258: {
1.1.1.9 root 259: if (ShortCutKey == SHORTCUT_NONE)
260: return;
1.1.1.8 root 261:
1.1.1.9 root 262: switch (ShortCutKey)
263: {
264: case SHORTCUT_OPTIONS:
265: Dialog_DoProperty(); /* Show options dialog */
266: break;
267: case SHORTCUT_FULLSCREEN:
268: ShortCut_FullScreen(); /* Switch between fullscreen/windowed mode */
269: break;
1.1.1.13 root 270: case SHORTCUT_MOUSEGRAB:
271: ShortCut_MouseGrab(); /* Toggle mouse grab */
1.1.1.9 root 272: break;
273: case SHORTCUT_COLDRESET:
1.1.1.10 root 274: Main_UnPauseEmulation();
1.1.1.9 root 275: Reset_Cold(); /* Reset emulator with 'cold' (clear all) */
276: break;
277: case SHORTCUT_WARMRESET:
1.1.1.10 root 278: Main_UnPauseEmulation();
1.1.1.9 root 279: Reset_Warm(); /* Emulator 'warm' reset */
280: break;
281: case SHORTCUT_SCREENSHOT:
282: ScreenSnapShot_SaveScreen(); /* Grab screenshot */
283: break;
284: case SHORTCUT_BOSSKEY:
285: ShortCut_BossKey(); /* Boss key */
286: break;
287: case SHORTCUT_CURSOREMU: /* Toggle joystick emu on/off */
288: Joy_ToggleCursorEmulation();
289: break;
1.1.1.10 root 290: case SHORTCUT_FASTFORWARD:
291: ShortCut_FastForward(); /* Toggle Min/Max speed */
1.1.1.9 root 292: break;
293: case SHORTCUT_RECANIM:
294: ShortCut_RecordAnimation(); /* Record animation */
295: break;
296: case SHORTCUT_RECSOUND:
297: ShortCut_RecordSound(); /* Toggle sound recording */
298: break;
299: case SHORTCUT_SOUND:
300: ShortCut_SoundOnOff(); /* Enable/disable sound */
301: break;
1.1.1.12 root 302: case SHORTCUT_DEBUG:
303: ShortCut_Debug(); /* Invoke the Debug UI */
304: break;
1.1.1.10 root 305: case SHORTCUT_PAUSE:
1.1.1.12 root 306: ShortCut_Pause(); /* Invoke Pause */
1.1.1.10 root 307: break;
1.1.1.9 root 308: case SHORTCUT_QUIT:
309: Main_RequestQuit();
310: break;
311: case SHORTCUT_LOADMEM:
1.1.1.12 root 312: MemorySnapShot_Restore(ConfigureParams.Memory.szMemoryCaptureFileName, true);
1.1.1.9 root 313: break;
314: case SHORTCUT_SAVEMEM:
1.1.1.12 root 315: MemorySnapShot_Capture(ConfigureParams.Memory.szMemoryCaptureFileName, true);
1.1.1.9 root 316: break;
1.1.1.10 root 317: case SHORTCUT_INSERTDISKA:
318: ShortCut_InsertDisk(0);
319: break;
1.1.1.9 root 320: case SHORTCUT_KEYS:
321: case SHORTCUT_NONE:
322: /* ERROR: cannot happen, just make compiler happy */
323: break;
324: }
325: ShortCutKey = SHORTCUT_NONE;
326: }
327:
328:
329: /*-----------------------------------------------------------------------*/
330: /**
1.1.1.10 root 331: * Invoke shortcut identified by name. This supports only keys for
332: * functionality that cannot be invoked with command line options
1.1.1.12 root 333: * or otherwise for remote GUIs etc.
1.1.1.10 root 334: */
335: bool Shortcut_Invoke(const char *shortcut)
336: {
337: struct {
338: SHORTCUTKEYIDX id;
339: const char *name;
340: } shortcuts[] = {
1.1.1.13 root 341: { SHORTCUT_MOUSEGRAB, "mousegrab" },
1.1.1.10 root 342: { SHORTCUT_COLDRESET, "coldreset" },
343: { SHORTCUT_WARMRESET, "warmreset" },
344: { SHORTCUT_SCREENSHOT, "screenshot" },
345: { SHORTCUT_BOSSKEY, "bosskey" },
346: { SHORTCUT_RECANIM, "recanim" },
347: { SHORTCUT_RECSOUND, "recsound" },
348: { SHORTCUT_SAVEMEM, "savemem" },
349: { SHORTCUT_QUIT, "quit" },
350: { SHORTCUT_NONE, NULL }
351: };
352: int i;
353:
354: if (ShortCutKey != SHORTCUT_NONE)
355: {
356: fprintf(stderr, "Shortcut invocation failed, shortcut already active\n");
1.1.1.12 root 357: return false;
1.1.1.10 root 358: }
359: for (i = 0; shortcuts[i].name; i++)
360: {
361: if (strcmp(shortcut, shortcuts[i].name) == 0)
362: {
363: ShortCutKey = shortcuts[i].id;
364: ShortCut_ActKey();
365: ShortCutKey = SHORTCUT_NONE;
1.1.1.12 root 366: return true;
1.1.1.10 root 367: }
368: }
369: fprintf(stderr, "WARNING: unknown shortcut '%s'\n\n", shortcut);
370: fprintf(stderr, "Hatari shortcuts are:\n");
371: for (i = 0; shortcuts[i].name; i++)
372: {
373: fprintf(stderr, "- %s\n", shortcuts[i].name);
374: }
1.1.1.12 root 375: return false;
1.1.1.10 root 376: }
377:
378:
379: /*-----------------------------------------------------------------------*/
380: /**
1.1.1.9 root 381: * Check whether given key was any of the ones in given shortcut array.
382: * Return corresponding array index or SHORTCUT_NONE for no match
383: */
1.1.1.8 root 384: static SHORTCUTKEYIDX ShortCut_CheckKey(int symkey, int *keys)
385: {
1.1.1.9 root 386: SHORTCUTKEYIDX key;
1.1.1.12 root 387: for (key = SHORTCUT_OPTIONS; key < SHORTCUT_KEYS; key++)
1.1.1.9 root 388: {
389: if (symkey == keys[key])
390: return key;
391: }
392: return SHORTCUT_NONE;
1.1.1.8 root 393: }
394:
395: /*-----------------------------------------------------------------------*/
1.1.1.9 root 396: /**
397: * Check which Shortcut key is pressed/released.
398: * If press is set, store the key array index.
399: * Return zero if key didn't match to a shortcut
400: */
1.1.1.10 root 401: int ShortCut_CheckKeys(int modkey, int symkey, bool press)
1.1.1.8 root 402: {
1.1.1.9 root 403: SHORTCUTKEYIDX key;
1.1.1.8 root 404:
1.1.1.9 root 405: if (modkey & (KMOD_RALT|KMOD_LMETA|KMOD_RMETA|KMOD_MODE))
406: key = ShortCut_CheckKey(symkey, ConfigureParams.Shortcut.withModifier);
407: else
408: key = ShortCut_CheckKey(symkey, ConfigureParams.Shortcut.withoutModifier);
409:
410: if (key == SHORTCUT_NONE)
411: return 0;
412: if (press)
413: ShortCutKey = key;
414: return 1;
1.1.1.5 root 415: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.