|
11 | 11 | #include <string.h> |
12 | 12 | #include <unistd.h> |
13 | 13 |
|
14 | | -#include "uart.h" |
| 14 | +#if RV32_HAS(SDL) && RV32_HAS(SYSTEM) && !RV32_HAS(ELF_LOADER) |
| 15 | +#include <SDL.h> |
| 16 | +#include <SDL_mixer.h> |
| 17 | + |
| 18 | +#include "utils.h" |
| 19 | +#endif |
15 | 20 |
|
| 21 | +#include "uart.h" |
16 | 22 | /* Emulate 8250 (plain, without loopback mode support) */ |
17 | 23 |
|
18 | 24 | #define U8250_INTR_THRE 1 |
@@ -66,9 +72,37 @@ static uint8_t u8250_handle_in(u8250_state_t *uart) |
66 | 72 | if (value == 1) { /* start of heading (Ctrl-a) */ |
67 | 73 | if (getchar() == 120) { /* keyboard x */ |
68 | 74 | printf("\n"); /* end emulator with newline */ |
69 | | - exit(0); |
| 75 | + exit(EXIT_SUCCESS); |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | +#if RV32_HAS(SDL) && RV32_HAS(SYSTEM) && !RV32_HAS(ELF_LOADER) |
| 80 | + /* |
| 81 | + * The guestOS may repeatedly open and close the SDL window, |
| 82 | + * and the user could close the application by pressing the ctrl-c key. |
| 83 | + * Need to trap the ctrl-c key and ensure the SDL window and |
| 84 | + * SDL mixer are destroyed properly. |
| 85 | + */ |
| 86 | + SDL_VIDEO_AUDIO_DECL(); |
| 87 | + extern bool audio_init; |
| 88 | + if (value == 3 /* ctrl-c */ && window) { |
| 89 | + bool sfx_or_music_thread_init = sfx_thread_init | music_thread_init; |
| 90 | + SDL_VIDEO_AUDIO_CLEANUP(window, shutdown_audio, |
| 91 | + sfx_or_music_thread_init); |
| 92 | + |
| 93 | + /* |
| 94 | + * The sfx_or_music_init flag might not be set if a quick ctrl-c |
| 95 | + * occurs while the audio configuration is being initialized. |
| 96 | + * Therefore, need to destroy the audio settings by checking |
| 97 | + * audio_init flag. |
| 98 | + */ |
| 99 | + if (!sfx_or_music_thread_init && audio_init) { |
| 100 | + Mix_CloseAudio(); |
| 101 | + Mix_Quit(); |
| 102 | + audio_init = false; |
70 | 103 | } |
71 | 104 | } |
| 105 | +#endif |
72 | 106 |
|
73 | 107 | return value; |
74 | 108 | } |
|
0 commit comments