From cd1ccf8cda05042cab913a6afca08c41a466923e Mon Sep 17 00:00:00 2001 From: "fabio.olimpieri" Date: Sun, 29 Apr 2012 12:55:59 +0000 Subject: [PATCH] Added virtual Keyboard, Added joystick buttons binding --- src/VirtualKeyboard.c | 184 +++++++++++++++++++++++++ src/VirtualKeyboard.h | 56 ++++++++ src/cargador.c | 9 +- src/cargador.h | 9 +- src/characters.c | 9 +- src/characters.h | 9 +- src/computer.c | 310 +++++++++++++++++++----------------------- src/computer.h | 13 +- src/emulator.c | 10 +- src/emulator.h | 10 +- src/gui_sdl.c | 130 +++++++++++------- src/gui_sdl.h | 29 ++++ src/menu_sdl.c | 44 ++++-- src/menu_sdl.h | 32 +++-- src/menus.c | 9 +- src/menus.h | 11 +- src/microdrive.c | 9 +- src/microdrive.h | 11 +- src/sound.c | 9 +- src/sound.h | 11 +- src/spk_ay.c | 9 +- src/spk_ay.h | 9 +- src/tape.c | 9 +- src/tape.h | 9 +- 24 files changed, 631 insertions(+), 319 deletions(-) create mode 100644 src/VirtualKeyboard.c create mode 100644 src/VirtualKeyboard.h create mode 100644 src/gui_sdl.h diff --git a/src/VirtualKeyboard.c b/src/VirtualKeyboard.c new file mode 100644 index 0000000..e0eff00 --- /dev/null +++ b/src/VirtualKeyboard.c @@ -0,0 +1,184 @@ +/********************************************************************* + * Copyright (C) 2012, Fabio Olimpieri + * Copyright (C) 2009, Simon Kagstrom + * + * Filename: VirtualKeyboard.c + * + * Description: A virtual keyboard + * + * This file is part of FBZX Wii + * + * FBZX Wii is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * FBZX Wii is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + ********************************************************************/ +#include +#include + +#include "z80free/Z80free.h" +#include "computer.h" +#include "VirtualKeyboard.h" +#include "menu_sdl.h" + + +#define K(name, sdl_code) \ + { name, "SDLK_"name, sdl_code, 0 ,0,0} +#define N(name, key_name, sdl_code) \ + { name, "SDLK_"key_name, sdl_code, 0,0,0 } +#define KNL() \ + { NULL, NULL, 0, 0 ,0,0} + + +#define KEY_COLS 10 +#define KEY_ROWS 5 + +extern struct computer ordenador; + +//TO DO Key_name and name are not necessary +static virtkey_t keys[KEY_COLS * KEY_ROWS] = { + K("1",49),K("2",50), K("3",51), K("4",52), K("5",53), K("6",54), K("7",55), K("8",56), K("9",57), K("0",48), + K("Q",113), K("W",119), K("E",101), K("R",114), K("T",116), K("Y",121), K("U",117), K("I",105), K("O",111), K("P",112), + K("A",97), K("S",115), K("D",100), K("F",102), K("G",103), K("H",104), K("J",106), K("K",107), K("L",108),N("Enter","RETURN",13), + N("Caps","LSHIFT",304),K("Z",122),K("X",120),K("C",99), K("V",118), K("B",98), K("N",110), K("M",109), N("Sym","LCTRL",306),N("Space","SPACE",32), + N("Ext","TAB",9), KNL(), N("Fire","LALT",308),KNL(), K("None",0),KNL(),KNL(), KNL(),KNL(),KNL()}; + +void VirtualKeyboard_init(SDL_Surface *screen, TTF_Font *font) +{ + VirtualKeyboard.screen = screen; + VirtualKeyboard.font = font; + VirtualKeyboard.sel_x = 0; + VirtualKeyboard.sel_y = 0; + + memset(VirtualKeyboard.buf, 0, sizeof(VirtualKeyboard.buf)); +} + +void draw() +{ + int y,x; + int screen_w = VirtualKeyboard.screen->w; + int screen_h = VirtualKeyboard.screen->h; + int key_w = 54; + int key_h = 36; + int border_x = (screen_w - (key_w * KEY_COLS)) / 2; + int border_y = (screen_h - (key_h * KEY_ROWS)) / 2; + SDL_Rect bg_rect = {border_x, border_y, + key_w * KEY_COLS, key_h * KEY_ROWS}; + + SDL_FillRect(VirtualKeyboard.screen, &bg_rect, + SDL_MapRGB(ordenador.screen->format, 0xff, 0xff, 0xff)); + + for (y = 0; y < KEY_ROWS; y++ ) + { + for (x = 0; x < KEY_COLS; x++ ) + { + int which = y * KEY_COLS + x; + virtkey_t key = keys[which]; + int r = 64, g = 64, b = 64; + const char *what = key.name; + + /* Skip empty positions */ + if (key.name == NULL) + continue; + + if ( key.is_done ) + r = 255; + if ( (x == VirtualKeyboard.sel_x && y == VirtualKeyboard.sel_y)) + g = 200; + + menu_print_font(VirtualKeyboard.screen, r, g, b, + x * key_w + border_x, y * key_h + border_y, + what, 20); + } + } +} + +void select_next_kb(int dx, int dy) +{ + int next_x = (VirtualKeyboard.sel_x + dx) % KEY_COLS; + int next_y = (VirtualKeyboard.sel_y + dy) % KEY_ROWS; + virtkey_t key; + + if (next_x < 0) + next_x = KEY_COLS + next_x; + if (next_y < 0) + next_y = KEY_ROWS + next_y; + VirtualKeyboard.sel_x = next_x; + VirtualKeyboard.sel_y = next_y; + + key = keys[ next_y * KEY_COLS + next_x ]; + + /* Skip the empty spots */ + if (key.name == NULL) + { + if (dy != 0) /* Look left */ + select_next_kb(-1, 0); + else + select_next_kb(dx, dy); + } +} + +struct virtkey *get_key_internal() +{ + while(1) + { + uint32_t k; + + draw(); + SDL_Flip(VirtualKeyboard.screen); + + k = menu_wait_key_press(); + + if (k & KEY_UP) + select_next_kb(0, -1); + else if (k & KEY_DOWN) + select_next_kb(0, 1); + else if (k & KEY_LEFT) + select_next_kb(-1, 0); + else if (k & KEY_RIGHT) + select_next_kb(1, 0); + else if (k & KEY_ESCAPE) + return NULL; + else if (k & KEY_SELECT) + { + virtkey_t *key = &keys[ VirtualKeyboard.sel_y * KEY_COLS + VirtualKeyboard.sel_x ]; + + if ((key->sdl_code == 304) && !keys[3 * KEY_COLS + 8 ].is_done) + keys[3 * KEY_COLS + 0 ].is_done = !keys[3 * KEY_COLS + 0 ].is_done; //Caps Shit + else if ((key->sdl_code == 306) && !keys[3 * KEY_COLS + 0 ].is_done) + keys[3 * KEY_COLS + 8 ].is_done = !keys[3 * KEY_COLS + 8 ].is_done; //Sym Shift + else { + key->caps_on = keys[3 * KEY_COLS + 0 ].is_done; + key->sym_on = keys[3 * KEY_COLS + 8 ].is_done; + return key; + } + } + } + + return NULL; +} + +struct virtkey* get_key() +{ + virtkey_t *key; + SDL_Rect rect = {32, 32, FULL_DISPLAY_X-64, FULL_DISPLAY_Y-96}; + + keys[3 * KEY_COLS + 0 ].is_done = 0; //Caps Shit + keys[3 * KEY_COLS + 8 ].is_done = 0; //Sym Shift + + SDL_FillRect(VirtualKeyboard.screen, &rect, SDL_MapRGB(ordenador.screen->format, 0xff, 0xff, 0xff)); + + key = get_key_internal(); + + return key; +} + diff --git a/src/VirtualKeyboard.h b/src/VirtualKeyboard.h new file mode 100644 index 0000000..4b8eb35 --- /dev/null +++ b/src/VirtualKeyboard.h @@ -0,0 +1,56 @@ +/********************************************************************* + * Copyright (C) 2012, Fabio Olimpieri + * Copyright (C) 2009, Simon Kagstrom + * + * Filename: VirtualKeyboard.h + * + * Description: A virtual keyboard + * + * This file is part of FBZX Wii + * + * FBZX Wii is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * FBZX Wii is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + ********************************************************************/ +#include +#include + +typedef struct virtkey +{ + const char *name; //It is not necessary in FBZX Wii + const char *ev_name; //It is not necessary in FBZX Wii + int sdl_code; + int is_done; + int caps_on; + int sym_on; +} virtkey_t; + + +struct Virtual_Keyboard +{ + SDL_Surface *screen; + TTF_Font *font; + int sel_x; + int sel_y; + char buf[255]; + +} VirtualKeyboard; + +void VirtualKeyboard_init(SDL_Surface *screen, TTF_Font *font); +struct virtkey* get_key(); +struct virtkey* get_key_internal(); +void draw(); +void select_next_kb(int dx, int dy); +void toggle_shift(); + + diff --git a/src/cargador.c b/src/cargador.c index d09c89b..4170c4c 100644 --- a/src/cargador.c +++ b/src/cargador.c @@ -1,13 +1,14 @@ -/* +/* + * Copyright (C) 2012 Fabio Olimpieri * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) - * This file is part of FBZX + * This file is part of FBZX Wii * - * FBZX is free software; you can redistribute it and/or modify + * FBZX Wii is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * - * FBZX is distributed in the hope that it will be useful, + * FBZX Wii is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. diff --git a/src/cargador.h b/src/cargador.h index b17332b..dbaf736 100644 --- a/src/cargador.h +++ b/src/cargador.h @@ -1,13 +1,14 @@ -/* +/* + * Copyright (C) 2012 Fabio Olimpieri * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) - * This file is part of FBZX + * This file is part of FBZX Wii * - * FBZX is free software; you can redistribute it and/or modify + * FBZX Wii is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * - * FBZX is distributed in the hope that it will be useful, + * FBZX Wii is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. diff --git a/src/characters.c b/src/characters.c index 29d9e7f..80783b6 100644 --- a/src/characters.c +++ b/src/characters.c @@ -1,13 +1,14 @@ -/* +/* + * Copyright (C) 2012 Fabio Olimpieri * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) - * This file is part of FBZX + * This file is part of FBZX Wii * - * FBZX is free software; you can redistribute it and/or modify + * FBZX Wii is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * - * FBZX is distributed in the hope that it will be useful, + * FBZX Wii is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. diff --git a/src/characters.h b/src/characters.h index 6a1f7ce..136f56f 100644 --- a/src/characters.h +++ b/src/characters.h @@ -1,13 +1,14 @@ -/* +/* + * Copyright (C) 2012 Fabio Olimpieri * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) - * This file is part of FBZX + * This file is part of FBZX Wii * - * FBZX is free software; you can redistribute it and/or modify + * FBZX Wii is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * - * FBZX is distributed in the hope that it will be useful, + * FBZX Wii is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. diff --git a/src/computer.c b/src/computer.c index e707192..6434100 100644 --- a/src/computer.c +++ b/src/computer.c @@ -1,13 +1,14 @@ -/* +/* + * Copyright (C) 2012 Fabio Olimpieri * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) - * This file is part of FBZX + * This file is part of FBZX Wii * - * FBZX is free software; you can redistribute it and/or modify + * FBZX Wii is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * - * FBZX is distributed in the hope that it will be useful, + * FBZX Wii is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. @@ -30,6 +31,8 @@ #include #include "tape.h" #include "microdrive.h" +#include "Virtualkeyboard.h" +#include "gui_sdl.h" #ifdef DEBUG extern FILE *fdebug; @@ -128,6 +131,9 @@ void computer_init () { ordenador.tape_loop_counter = 0; ordenador.kbd_buffer_pointer = 0; ordenador.key = SDL_GetKeyState(NULL); + ordenador.joybuttonkey[0][0]=SDLK_LALT; //Fire button to wiimote1 button A + ordenador.joybuttonkey[1][0]=SDLK_LALT; //Fire button to wiimote1 button A + } void computer_set_palete() { @@ -701,7 +707,8 @@ inline void read_keyboard () { SDL_Event evento,*pevento; enum joystate_x {JOY_CENTER_X, JOY_LEFT, JOY_RIGHT}; enum joystate_y {JOY_CENTER_Y, JOY_UP, JOY_DOWN}; - int joy_axis_x[2],joy_axis_y[2], loop; + int joy_axis_x[2],joy_axis_y[2], joy_n, joybutton_n; + static unsigned char joybutton_matrix[2][322]; ordenador.k8 = ordenador.k9 = ordenador.k10 = ordenador.k11 = ordenador.k12 = ordenador.k13 = ordenador.k14 = @@ -716,118 +723,66 @@ inline void read_keyboard () { return; } - if (ordenador.kbd_buffer_pointer) - { - if (countdown) - countdown--; - else + + SDL_JoystickUpdate(); + for(joy_n=0;joy_n 16384) ordenador.joy_axis_x_state[joy_n] = JOY_RIGHT; + else if (joy_axis_x[joy_n] < -16384) ordenador.joy_axis_x_state[joy_n] = JOY_LEFT; + else ordenador.joy_axis_x_state[joy_n] = JOY_CENTER_X; + + if (joy_axis_y[joy_n] > 16384) ordenador.joy_axis_y_state[joy_n] = JOY_DOWN; + else if (joy_axis_y[joy_n] < -16384) ordenador.joy_axis_y_state[joy_n] = JOY_UP; + else ordenador.joy_axis_y_state[joy_n] = JOY_CENTER_Y; + + for(joybutton_n=0;joybutton_n<5;joybutton_n++) { - switch (ordenador.kbd_buffer_pointer) - { - case 6: //Edit - ordenador.k8|=1; - ordenador.k11|=1; - break; - case 5: //Load - ordenador.k14|= 8; - break; - case 4: //" - ordenador.k15|= 2; - ordenador.k13|= 1; - break; - case 3: //" - ordenador.k15|= 2; - ordenador.k13|= 1; - break; - case 2: // Return - ordenador.k14|= 1; - break; - case 1: - if ((ordenador.tape_fast_load == 0) || (ordenador.tape_file_type==TAP_TZX)) - ordenador.pause = 0; - break; - } - ordenador.kbd_buffer_pointer--; - countdown=5; + joybutton_matrix[joy_n][(ordenador.joybuttonkey[joy_n][joybutton_n])] = + SDL_JoystickGetButton(ordenador.joystick_sdl[joy_n], joybutton_n); + } + + for(joybutton_n=7;joybutton_n<18;joybutton_n++) + { + joybutton_matrix[joy_n][(ordenador.joybuttonkey[joy_n][joybutton_n])] = + SDL_JoystickGetButton(ordenador.joystick_sdl[joy_n], joybutton_n); } } - SDL_JoystickUpdate(); - for(loop=0;loop 16384) ordenador.joy_axis_x_state[loop] = JOY_RIGHT; - else if (joy_axis_x[loop] < -16384) ordenador.joy_axis_x_state[loop] = JOY_LEFT; - else ordenador.joy_axis_x_state[loop] = JOY_CENTER_X; - - if (joy_axis_y[loop] > 16384) ordenador.joy_axis_y_state[loop] = JOY_DOWN; - else if (joy_axis_y[loop] < -16384) ordenador.joy_axis_y_state[loop] = JOY_UP; - else ordenador.joy_axis_y_state[loop] = JOY_CENTER_Y; - } temporal_io = (unsigned int) pevento->key.keysym.sym; - /* - if ((pevento->type==SDL_KEYDOWN)&&(temporal_io==SDLK_TAB)) { - if (ordenador.tab_extended==0) { - ordenador.tab_extended=1; - strcpy(ordenador.osd_text,"Function Key mode on"); - ordenador.osd_time=100; - return; - } else { - ordenador.tab_extended=0; - ordenador.osd_time=0; - return; - } - } - - if ((pevento->type==SDL_KEYDOWN)&&(ordenador.tab_extended==1)) { - ordenador.tab_extended=0; - ordenador.osd_time=0; - switch(temporal_io) { - case SDLK_1: - temporal_io=SDLK_F1; - break; - case SDLK_2: - temporal_io=SDLK_F2; - break; - case SDLK_3: - temporal_io=SDLK_F3; - break; - case SDLK_4: - temporal_io=SDLK_F4; - break; - case SDLK_5: - temporal_io=SDLK_F5; - break; - case SDLK_6: - temporal_io=SDLK_F6; - break; - case SDLK_7: - temporal_io=SDLK_F7; - break; - case SDLK_8: - temporal_io=SDLK_F8; - break; - case SDLK_9: - temporal_io=SDLK_F9; - break; - case SDLK_0: - temporal_io=SDLK_F10; - break; - case SDLK_o: - temporal_io=SDLK_F11; - break; - case SDLK_p: - temporal_io=SDLK_F12; - break; - } - } - */ if (pevento->type == SDL_KEYDOWN) switch (temporal_io) { case SDLK_ESCAPE: // to exit from the emulator @@ -863,9 +818,20 @@ inline void read_keyboard () { case SDLK_F9: //Emulate load "" - + ordenador.keyboard_buffer[0][6]= SDLK_1; //Edit + ordenador.keyboard_buffer[1][6]= SDLK_LSHIFT; + ordenador.keyboard_buffer[0][5]= SDLK_j; //Load + ordenador.keyboard_buffer[1][5]= 0; + ordenador.keyboard_buffer[0][4]= SDLK_p; //" + ordenador.keyboard_buffer[1][4]= SDLK_LCTRL; + ordenador.keyboard_buffer[0][3]= SDLK_p; //" + ordenador.keyboard_buffer[1][3]= SDLK_LCTRL; + ordenador.keyboard_buffer[0][2]= SDLK_RETURN; // Return + ordenador.keyboard_buffer[1][2]= 0; + ordenador.keyboard_buffer[0][1]= SDLK_F6; //F6 + ordenador.keyboard_buffer[1][1]= 0; ordenador.kbd_buffer_pointer=6; - countdown=5; + countdown=7; break; case SDLK_F10: // Reset emulator @@ -909,93 +875,93 @@ inline void read_keyboard () { break; } } - for(loop=0;loop diff --git a/src/emulator.h b/src/emulator.h index df973f8..59afdcf 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -1,13 +1,14 @@ -/* +/* + * Copyright (C) 2012 Fabio Olimpieri * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) - * This file is part of FBZX + * This file is part of FBZX Wii * - * FBZX is free software; you can redistribute it and/or modify + * FBZX Wii is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * - * FBZX is distributed in the hope that it will be useful, + * FBZX Wii is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. @@ -40,6 +41,7 @@ extern unsigned int jump_frames,curr_frames; void SDL_Fullscreen_Switch(void); void load_rom(char); void load_main_game(char *nombre); +void save_config(struct computer *object); FILE *myfopen(char *filename,char *mode); #endif diff --git a/src/gui_sdl.c b/src/gui_sdl.c index ada454d..ed1c158 100644 --- a/src/gui_sdl.c +++ b/src/gui_sdl.c @@ -1,17 +1,39 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Interface to the Tcl/Tk GUI - * - * Copyright 1996 Bernd Schmidt - */ +/********************************************************************* + * + * Copyright (C) 2012, Fabio Olimpieri + * + * Filename: menu_sdl.c + * Author: Fabio Olimpieri + * Description: a SDL Gui + * This file is part of FBZX Wii + * + * FBZX Wii is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * FBZX Wii is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * + ********************************************************************/ #include #include +#include #include "menu_sdl.h" #include "emulator.h" -//#include "VirtualKeyboard.h" per ora +#include "VirtualKeyboard.h" +#include "tape.h" +//#include "menus.h" +#include "emulator.h" +#include "cargador.h" #define ID_BUTTON_OFFSET 0 #define ID_AXIS_OFFSET 32 @@ -71,7 +93,7 @@ static const char *input_messages[] = { /*01*/ "^|Cursor|Kempston|Sinclair1|Sinclair2", /*02*/ " ", /*03*/ "Bind key to Wiimote", - /*04*/ "^|1|2|-", + /*04*/ "^|A|B|1|2|-", /*05*/ " ", /*06*/ "Bind key to Nunchuk", /*07*/ "^|Z|C", @@ -221,7 +243,19 @@ static void manage_tape(int which) break; case 1: //Emulate load "" ordenador.kbd_buffer_pointer=6; - countdown=5; + countdown=7; + ordenador.keyboard_buffer[0][6]= SDLK_1; //Edit + ordenador.keyboard_buffer[1][6]= SDLK_LSHIFT; + ordenador.keyboard_buffer[0][5]= SDLK_j; //Load + ordenador.keyboard_buffer[1][5]= 0; + ordenador.keyboard_buffer[0][4]= SDLK_p; //" + ordenador.keyboard_buffer[1][4]= SDLK_LCTRL; + ordenador.keyboard_buffer[0][3]= SDLK_p; //" + ordenador.keyboard_buffer[1][3]= SDLK_LCTRL; + ordenador.keyboard_buffer[0][2]= SDLK_RETURN; // Return + ordenador.keyboard_buffer[1][2]= 0; + ordenador.keyboard_buffer[0][1]= SDLK_F6; //F6 + ordenador.keyboard_buffer[1][1]= 0; break; case 2: //Play if ((ordenador.tape_fast_load == 0) || (ordenador.tape_file_type==TAP_TZX)) @@ -338,29 +372,29 @@ static void emulation_settings(void) } -static void setup_joystick(int joy, const char *key, int sdl_key) +static void setup_joystick(int joy, unsigned int sdl_key, int joy_key) { - /* - if (!strcmp(key, "None")) - { - changed_prefs.joystick_settings[1][joy].eventid[ID_BUTTON_OFFSET + sdl_key][0] = 0; - } - else - insert_keyboard_map(key, "input.1.joystick.%d.button.%d", joy, sdl_key); - */ + int loop; + + //Cancel the previous assignement - it is not possible to assign a same sdl_key to 2 joybuttons + for (loop=0; loop<18; loop++) + if (ordenador.joybuttonkey[joy][loop] == sdl_key) ordenador.joybuttonkey[joy][loop] =0; + + ordenador.joybuttonkey[joy][joy_key] = sdl_key; + } static void input_options(int joy) { - const int wiimote_to_sdl[] = {2, 3, 4, 5}; - const int nunchuk_to_sdl[] = {7, 8}; - const int classic_to_sdl[] = {9, 10, 11, 12, 13, 14, 15, 16, 17, 18}; - int sdl_key = 1; - const char *key; + const unsigned int wiimote_to_sdl[] = {0, 1, 2, 3, 4}; + const unsigned int nunchuk_to_sdl[] = {7, 8}; + const unsigned int classic_to_sdl[] = {9, 10, 11, 12, 13, 14, 15, 16, 17}; + int joy_key = 1; + unsigned int sdl_key; unsigned int submenus[5]; int opt; - //struct virtkey *virtualkey; + struct virtkey *virtualkey; memset(submenus, 0, sizeof(submenus)); @@ -375,26 +409,27 @@ static void input_options(int joy) ordenador.joystick[joy] = submenus[0]; ordenador.rumble[joy] = !submenus[4]; - /* - virtualkey = virtkbd_get_key(); + if (opt == 0 || opt == 12) + return; + + virtualkey = get_key(); if (virtualkey == NULL) return; - key = virtualkey->ev_name; - */ + sdl_key = virtualkey->sdl_code; switch(opt) { case 3: // wiimote - sdl_key = wiimote_to_sdl[submenus[1]]; break; + joy_key = wiimote_to_sdl[submenus[1]]; break; case 6: // nunchuk - sdl_key = nunchuk_to_sdl[submenus[2]]; break; + joy_key = nunchuk_to_sdl[submenus[2]]; break; case 9: // classic - sdl_key = classic_to_sdl[submenus[3]]; break; + joy_key = classic_to_sdl[submenus[3]]; break; default: break; } - setup_joystick(joy, key, sdl_key); + setup_joystick(joy, sdl_key, joy_key); } @@ -531,28 +566,27 @@ static void set_Port(int which) break; } } +*/ -static void virtual_keyboard(void) +void virtual_keyboard(void) { int key_code; - virtkey_t *key =virtkbd_get_key(); + virtkey_t *key =get_key(); if (key) {key_code = key->sdl_code;} else return; - SDL_Event event_key; - - event_key.type=SDL_KEYDOWN; - event_key.key.keysym.sym=key_code; - SDL_PushEvent(&event_key); - DEBUG_LOG ("Push Event: keycode %d %s\n", key_code, "SDL_KEYDOWN"); - - event_key.type=SDL_KEYUP; - SDL_PushEvent(&event_key); - DEBUG_LOG ("Push Event: keycode %d %s\n", key_code, "SDL_KEYUP"); + ordenador.kbd_buffer_pointer=1; + countdown=7; + ordenador.keyboard_buffer[0][1]= key_code; + if (key->caps_on) ordenador.keyboard_buffer[1][1]= SDLK_LSHIFT; + else if (key->sym_on) ordenador.keyboard_buffer[1][1]= SDLK_LCTRL; + else ordenador.keyboard_buffer[1][1]= 0; + printf ("Push Event: keycode %d\n", key_code); + } -*/ + static void save_load_snapshot(int which) { @@ -583,7 +617,7 @@ static void save_load_snapshot(int which) { if (which == 0) // Load snapshot file { - retorno=load_z80(filename); + retorno=load_z80((char *)filename); switch(retorno) { case 0: // all right @@ -605,7 +639,7 @@ static void save_load_snapshot(int which) case 1: // Save snapshot file snprintf(db, 255, "%s/%s.z80", dir, fb); retorno=save_z80(db); - msgInfo("State saved",3000,NULL); + msgInfo("Snapshot saved",3000,NULL); break; default: break; diff --git a/src/gui_sdl.h b/src/gui_sdl.h new file mode 100644 index 0000000..c0b7bab --- /dev/null +++ b/src/gui_sdl.h @@ -0,0 +1,29 @@ +/********************************************************************* + * + * Copyright (C) 2012, Fabio Olimpieri + * + * Filename: menu_sdl.h + * Author: Fabio Olimpieri + * Description: a SDL Gui + * This file is part of FBZX Wii + * + * FBZX Wii is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * FBZX Wii is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * + ********************************************************************/ + +void virtual_keyboard(void); +void main_menu(); + + diff --git a/src/menu_sdl.c b/src/menu_sdl.c index 4b18f36..6f5be52 100644 --- a/src/menu_sdl.c +++ b/src/menu_sdl.c @@ -1,14 +1,28 @@ /********************************************************************* -* -* Copyright (C) 2004,2008, Simon Kagstrom -* -* Filename: menu.c -* Author: Simon Kagstrom -* Description: Code for menus (originally for Mophun) -* -* $Id$ -* -********************************************************************/ + * Copyright (C) 2012, Fabio Olimpieri + * Copyright (C) 2009, Simon Kagstrom + * + * Filename: menu_sdl.c + * + * Description: Code for menus (originally for Mophun) + * + * This file is part of FBZX Wii + * + * FBZX Wii is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * FBZX Wii is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + ********************************************************************/ + #include #include #include @@ -16,11 +30,13 @@ #include #include #include - +#include +#include +#include #include "menu_sdl.h" -#include "emulator.h" //Necessary to use ordenador.joystick_number and ordenador.joystick_sdl -//#include "VirtualKeyboard.h" +#include "emulator.h" +#include "VirtualKeyboard.h" @@ -966,7 +982,7 @@ void menu_init(SDL_Surface *screen) menu_font20 = read_font(FONT_PATH, 20); real_screen = screen; - //virtkbd_init(screen, menu_font_alt16); per ora + VirtualKeyboard_init(screen, menu_font16); //prima c'era il font 16 alt is_inited = 1; } diff --git a/src/menu_sdl.h b/src/menu_sdl.h index d455975..f289e4f 100644 --- a/src/menu_sdl.h +++ b/src/menu_sdl.h @@ -1,24 +1,33 @@ /********************************************************************* + * Copyright (C) 2012, Fabio Olimpieri + * Copyright (C) 2009, Simon Kagstrom * - * Copyright (C) 2004, 2008, Simon Kagstrom + * Filename: menu_sdl.h + * + * Description: Code for menus (originally for Mophun) * - * Filename: menu.h - * Author: Simon Kagstrom - * Description: + * This file is part of FBZX Wii * - * $Id$ + * FBZX Wii is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. * + * FBZX Wii is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * ********************************************************************/ + #ifndef __MENU_H__ #define __MENU_H__ #include #include -#include - -#if defined(__cplusplus) -extern "C" { -#endif #define KEY_UP 1 #define KEY_DOWN 2 @@ -55,8 +64,5 @@ int menu_is_inited(void); int ext_matches(const char *name, const char *ext); -#if defined(__cplusplus) -} -#endif #endif /* !__MENU_H__ */ diff --git a/src/menus.c b/src/menus.c index 225b85e..276d962 100644 --- a/src/menus.c +++ b/src/menus.c @@ -1,13 +1,14 @@ -/* +/* + * Copyright (C) 2012 Fabio Olimpieri * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) - * This file is part of FBZX + * This file is part of FBZX Wii * - * FBZX is free software; you can redistribute it and/or modify + * FBZX Wii is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * - * FBZX is distributed in the hope that it will be useful, + * FBZX Wii is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. diff --git a/src/menus.h b/src/menus.h index eefcc59..fb39403 100644 --- a/src/menus.h +++ b/src/menus.h @@ -1,13 +1,14 @@ -/* - * Copyright 2003-2011 (C) Raster Software Vigo (Sergio Costas) - * This file is part of FBZX +/* + * Copyright (C) 2012 Fabio Olimpieri + * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) + * This file is part of FBZX Wii * - * FBZX is free software; you can redistribute it and/or modify + * FBZX Wii is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * - * FBZX is distributed in the hope that it will be useful, + * FBZX Wii is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. diff --git a/src/microdrive.c b/src/microdrive.c index f999691..530dafa 100644 --- a/src/microdrive.c +++ b/src/microdrive.c @@ -1,13 +1,14 @@ -/* +/* + * Copyright (C) 2012 Fabio Olimpieri * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) - * This file is part of FBZX + * This file is part of FBZX Wii * - * FBZX is free software; you can redistribute it and/or modify + * FBZX Wii is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * - * FBZX is distributed in the hope that it will be useful, + * FBZX Wii is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. diff --git a/src/microdrive.h b/src/microdrive.h index ac7bf04..8bb0cd7 100644 --- a/src/microdrive.h +++ b/src/microdrive.h @@ -1,13 +1,14 @@ -/* +/* + * Copyright (C) 2012 Fabio Olimpieri * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) - * This file is part of FBZX + * This file is part of FBZX Wii * - * FBZX is free software; you can redistribute it and/or modify + * FBZX Wii is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * - * FBZX is distributed in the hope that it will be useful, + * FBZX Wii is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. @@ -16,7 +17,7 @@ * along with this program. If not, see . * */ - + #ifndef H_MICRODRIVE #define H_MICRODRIVE diff --git a/src/sound.c b/src/sound.c index 8049233..cf36e47 100644 --- a/src/sound.c +++ b/src/sound.c @@ -1,13 +1,14 @@ -/* +/* + * Copyright (C) 2012 Fabio Olimpieri * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) - * This file is part of FBZX + * This file is part of FBZX Wii * - * FBZX is free software; you can redistribute it and/or modify + * FBZX Wii is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * - * FBZX is distributed in the hope that it will be useful, + * FBZX Wii is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. diff --git a/src/sound.h b/src/sound.h index 7d8d96c..b582f32 100644 --- a/src/sound.h +++ b/src/sound.h @@ -1,13 +1,14 @@ -/* +/* + * Copyright (C) 2012 Fabio Olimpieri * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) - * This file is part of FBZX + * This file is part of FBZX Wii * - * FBZX is free software; you can redistribute it and/or modify + * FBZX Wii is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * - * FBZX is distributed in the hope that it will be useful, + * FBZX Wii is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. @@ -16,7 +17,7 @@ * along with this program. If not, see . * */ - + #ifndef SOUND_H #define SOUND_H diff --git a/src/spk_ay.c b/src/spk_ay.c index 5a72372..dbaa0bf 100644 --- a/src/spk_ay.c +++ b/src/spk_ay.c @@ -1,13 +1,14 @@ -/* +/* + * Copyright (C) 2012 Fabio Olimpieri * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) - * This file is part of FBZX + * This file is part of FBZX Wii * - * FBZX is free software; you can redistribute it and/or modify + * FBZX Wii is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * - * FBZX is distributed in the hope that it will be useful, + * FBZX Wii is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. diff --git a/src/spk_ay.h b/src/spk_ay.h index 6db1ac0..b2c5127 100644 --- a/src/spk_ay.h +++ b/src/spk_ay.h @@ -1,13 +1,14 @@ -/* +/* + * Copyright (C) 2012 Fabio Olimpieri * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) - * This file is part of FBZX + * This file is part of FBZX Wii * - * FBZX is free software; you can redistribute it and/or modify + * FBZX Wii is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * - * FBZX is distributed in the hope that it will be useful, + * FBZX Wii is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. diff --git a/src/tape.c b/src/tape.c index 69593cf..b3b3cfa 100644 --- a/src/tape.c +++ b/src/tape.c @@ -1,13 +1,14 @@ -/* +/* + * Copyright (C) 2012 Fabio Olimpieri * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) - * This file is part of FBZX + * This file is part of FBZX Wii * - * FBZX is free software; you can redistribute it and/or modify + * FBZX Wii is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * - * FBZX is distributed in the hope that it will be useful, + * FBZX Wii is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. diff --git a/src/tape.h b/src/tape.h index b277a08..0574b2d 100644 --- a/src/tape.h +++ b/src/tape.h @@ -1,13 +1,14 @@ -/* +/* + * Copyright (C) 2012 Fabio Olimpieri * Copyright 2003-2009 (C) Raster Software Vigo (Sergio Costas) - * This file is part of FBZX + * This file is part of FBZX Wii * - * FBZX is free software; you can redistribute it and/or modify + * FBZX Wii is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * - * FBZX is distributed in the hope that it will be useful, + * FBZX Wii is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details.