From 2dbfec8e0ef9b007fc45df50b13e390d1e62adfd Mon Sep 17 00:00:00 2001 From: "fabio.olimpieri" Date: Sun, 12 Apr 2015 19:35:35 +0000 Subject: [PATCH] "-" on wiimote and canc on keyboard pause the emulation, rzx browser improvements --- src/computer.c | 72 +++++++++++++++++++++++++++++++++++++++++++++-- src/gui_sdl.c | 25 ++++++++-------- src/menu_sdl.c | 2 ++ src/rzx_lib/rzx.c | 3 +- 4 files changed, 88 insertions(+), 14 deletions(-) diff --git a/src/computer.c b/src/computer.c index 8f31f29..32ba8fe 100644 --- a/src/computer.c +++ b/src/computer.c @@ -1177,6 +1177,66 @@ inline void paint_one_pixel(unsigned char *colour,unsigned char *address ) { } #endif +inline void pause() { + unsigned int temporal_io; + SDL_Event evento,*pevento; + unsigned char minus_pressed=2; + + pevento=&evento; + printf("Pause\n"); + + while (1) + { + SDL_JoystickUpdate(); + + #ifdef HW_DOL //Gamecube button "Z" + if (!SDL_JoystickGetButton(ordenador.joystick_sdl[0], 4 ) && minus_pressed==2 ) minus_pressed = 1; //Released + if (SDL_JoystickGetButton(ordenador.joystick_sdl[0], 4 ) && minus_pressed==1) minus_pressed = 0; //Pressed + if (!SDL_JoystickGetButton(ordenador.joystick_sdl[0], 4 ) && minus_pressed==0 ) return; //Released + #else //HW_RVL - WIN // Wii button "-" + if (!SDL_JoystickGetButton(ordenador.joystick_sdl[0], 4) && + !SDL_JoystickGetButton(ordenador.joystick_sdl[0], 17) && minus_pressed==2 ) minus_pressed=1; //Released + if ((SDL_JoystickGetButton(ordenador.joystick_sdl[0], 4) || + SDL_JoystickGetButton(ordenador.joystick_sdl[0], 17)) && minus_pressed==1) minus_pressed = 0; //Pressed + if (!SDL_JoystickGetButton(ordenador.joystick_sdl[0], 4) && + !SDL_JoystickGetButton(ordenador.joystick_sdl[0], 17) && minus_pressed==0 ) return; //Released + #endif + + memset(&evento,0, sizeof(SDL_Event)); + SDL_PollEvent (&evento); + + if (pevento->type==SDL_QUIT) { + printf("SDL_QUIT event\n"); + salir = 0; + return; + } + + temporal_io = (unsigned int) pevento->key.keysym.sym; + + if (pevento->type == SDL_KEYDOWN) + switch (temporal_io) { + case SDLK_ESCAPE: // to exit from the emulator + if (ordenador.esc_again==0) { + ordenador.esc_again=1; + strcpy(ordenador.osd_text,"ESC again to exit"); + ordenador.osd_time=100; + } else + salir = 0; + return; + break; + + case SDLK_F10: // Reset emulator + ResetComputer (); + return; + break; + + case SDLK_DELETE: //unpause RZX playing + return; + break; + } + SDL_Delay(50); + } +} // Read the keyboard and stores the flags @@ -1215,10 +1275,15 @@ inline void read_keyboard () { #ifdef HW_DOL if (SDL_JoystickGetButton(ordenador.joystick_sdl[0], 7)) //Gamecube button "Start" {if (ordenador.vk_is_active) virtkey_ir_deactivate();main_menu(); } + if (SDL_JoystickGetButton(ordenador.joystick_sdl[0], 4) //Gamecube button "Z" + pause(); #else //HW_RVL - WIN if (SDL_JoystickGetButton(ordenador.joystick_sdl[0], 6) ||//Wii button "Home" SDL_JoystickGetButton(ordenador.joystick_sdl[0], 19)) {if (ordenador.vk_is_active) virtkey_ir_deactivate();main_menu(); } + if (SDL_JoystickGetButton(ordenador.joystick_sdl[0], 4) ||//Wii button "-" + SDL_JoystickGetButton(ordenador.joystick_sdl[0], 17)) + pause(); #endif #ifdef HW_DOL @@ -1244,14 +1309,14 @@ inline void read_keyboard () { else ordenador.joy_axis_y_state[joy_n] = JOY_CENTER_Y; if (!ordenador.vk_is_active) { - for(joybutton_n=0;joybutton_n<5;joybutton_n++) + for(joybutton_n=0;joybutton_n<4;joybutton_n++) { joybutton_matrix[joy_n][(ordenador.joybuttonkey[joy_n][joybutton_n])] = SDL_JoystickGetButton(ordenador.joystick_sdl[joy_n], joybutton_n); } #ifdef HW_RVL - for(joybutton_n=7;joybutton_n<18;joybutton_n++) + for(joybutton_n=7;joybutton_n<17;joybutton_n++) { joybutton_matrix[joy_n][(ordenador.joybuttonkey[joy_n][joybutton_n])] = SDL_JoystickGetButton(ordenador.joystick_sdl[joy_n], joybutton_n); @@ -1432,6 +1497,9 @@ inline void read_keyboard () { if (!ordenador.vk_auto) {if (!ordenador.vk_is_active) virtkey_ir_activate(); else virtkey_ir_deactivate();} break; + case SDLK_DELETE: // Pause emulator + pause(); + break; #ifndef GEKKO case SDLK_RALT: //Full_screen SDL_Fullscreen_Switch(); diff --git a/src/gui_sdl.c b/src/gui_sdl.c index ffb9e40..c0f5904 100644 --- a/src/gui_sdl.c +++ b/src/gui_sdl.c @@ -168,14 +168,14 @@ static const char *input_messages[] = { /*01*/ "^|Curs|Kemps|Sincl1|Sincl2|Fuller|QAOP", #ifdef HW_RVL /*02*/ "Bind key to Wiimote", - /*03*/ "^|A|B|1|2|-|+", + /*03*/ "^|A|B|1|2|+", /*04*/ "Bind key to Nunchuk", /*05*/ "^|Z|C", /*06*/ "Bind key to Classic", - /*07*/ "^|a|b|x|y|L|R|Zl|Zr|-|+", + /*07*/ "^|a|b|x|y|L|R|Zl|Zr|+", #else //HW_DOL - WIN /*02*/ "Bind key to Controller", - /*03*/ "^|A|B|X|Y|Z", + /*03*/ "^|A|B|X|Y", /*04*/ "Unused", /*05*/ "^|----", /*06*/ "Unused", @@ -883,9 +883,9 @@ static void setup_joystick(int joy, unsigned int sdl_key, int joy_key) static void input_options(int joy) { - const unsigned int wiimote_to_sdl[] = {0, 1, 2, 3, 4,5}; + const unsigned int wiimote_to_sdl[] = {0, 1, 2, 3, 5}; const unsigned int nunchuk_to_sdl[] = {7, 8}; - const unsigned int classic_to_sdl[] = {9, 10, 11, 12, 13, 14, 15, 16, 17,18}; + const unsigned int classic_to_sdl[] = {9, 10, 11, 12, 13, 14, 15, 16, 18}; const unsigned int pad_to_sdl[] = {19, 20, 21, 22}; int joy_key = 1; unsigned int sdl_key; @@ -1913,6 +1913,7 @@ static int load_rzx(int edit) if (!(ext_matches(filename, ".rzx")|ext_matches(filename, ".RZX"))) {free((void *)filename); return -1;} + printf("Loading %s\n", filename); if (edit) retorno=rzx_edit(filename); else retorno=rzx_playback(filename); @@ -1984,7 +1985,11 @@ static void rzx_browser() ordenador.frames_count_rzx=rzx_browser_list[block_n_int].frames_count; - if (ordenador.playing_rzx) rzx_set_file_position(rzx_position); + if (ordenador.playing_rzx) + { + rzx_set_file_position(rzx_position); + ordenador.maxicount = 0; //Force rzx_update and interrupt + } if (ordenador.recording_rzx) { @@ -2010,6 +2015,7 @@ static void rzx_browser() rzx_snapshot_counter = block_n_int+1; } } + ordenador.icount = 0; } static int do_rzx(int which) @@ -2065,12 +2071,9 @@ static int do_rzx(int which) retorno = -2; break; case 4: //browser - if (!ordenador.playing_rzx&&!ordenador.recording_rzx) break; - if (ordenador.recording_rzx) rzx_update(&ordenador.icount); //Discard the records - ordenador.icount = 0; - rzx_reset(); //Reset internal library variables + if (!ordenador.playing_rzx&&!ordenador.recording_rzx) break; + if (ordenador.recording_rzx) rzx_update(0); //Force rzx_close_irb rzx_browser(); - if (ordenador.playing_rzx) ordenador.maxicount = 0; //Force rzx_update and interrupt retorno = -2; break; case 5: //edit diff --git a/src/menu_sdl.c b/src/menu_sdl.c index b61f7b9..475859d 100644 --- a/src/menu_sdl.c +++ b/src/menu_sdl.c @@ -560,6 +560,8 @@ int extract_screen(char* screen_memory, const char* name) char char_id[10]; int retorno; + printf("Extracting screen of %s\n", name); + if ((ext_matches(name, ".tap")||ext_matches(name, ".TAP"))) { sprintf(filename,"%s/%s",load_path_taps, name); diff --git a/src/rzx_lib/rzx.c b/src/rzx_lib/rzx.c index 2ddc592..47f77ed 100644 --- a/src/rzx_lib/rzx.c +++ b/src/rzx_lib/rzx.c @@ -304,6 +304,7 @@ void rzx_set_file_position(unsigned int rzx_position) #endif fseek(rzxfile,rzx_position,SEEK_SET); INcount=0; + INmax=0; INold=0xFFFF; } @@ -925,7 +926,7 @@ void rzx_store_input(rzx_u8 value) int rzx_get_input(rzx_u8 *input) { - if(INcount>=INmax) {printf("Too many inputs read\n"); *input=0; return RZX_SYNCLOST;}; + if(INcount>=INmax) {printf("Too many inputs read, expected %d\n", INmax); *input=0; return RZX_SYNCLOST;}; *input = inputbuffer[INcount++]; return RZX_OK; }