diff --git a/src/VirtualKeyboard.c b/src/VirtualKeyboard.c index 965b8e9..a99f625 100644 --- a/src/VirtualKeyboard.c +++ b/src/VirtualKeyboard.c @@ -32,25 +32,25 @@ #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 } + { name, sdl_code, 0 ,0, 0} #define KNL() \ - { NULL, NULL, 0, 0 ,0,0} + { NULL, 0, 0 ,0, 0} #define KEY_COLS 10 -#define KEY_ROWS 5 +#define KEY_ROWS 6 -extern struct computer ordenador; +extern struct computer ordenador; +void clean_screen(); //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), K("None",0),N("Del","BACKSPACE",8),K(",",44),K(".",46),N("Fire","LALT",308), K("UP",273),K("DOWN",274), K("LEFT",276),K("RIGHT",275)}; + K(" 1",SDLK_1),K(" 2",SDLK_2), K(" 3",SDLK_3), K(" 4",SDLK_4), K(" 5",SDLK_5), K(" 6",SDLK_6), K(" 7",SDLK_7), K(" 8",SDLK_8), K(" 9",SDLK_9), K(" 0",SDLK_0), + K(" Q",SDLK_q), K(" W",SDLK_w), K(" E",SDLK_e), K(" R",SDLK_r), K(" T",SDLK_t), K(" Y",SDLK_y), K(" U",SDLK_u), K(" I",SDLK_i), K(" O",SDLK_o), K(" P",SDLK_p), + K(" A",SDLK_a), K(" S",SDLK_s), K(" D",SDLK_d), K(" F",SDLK_f), K(" G",SDLK_g), K(" H",SDLK_h), K(" J",SDLK_j), K(" K",SDLK_k), K(" L",SDLK_l),K("Enter",SDLK_RETURN), + K("Caps",SDLK_LSHIFT),K(" Z",SDLK_z),K(" X",SDLK_x),K(" C",SDLK_c), K(" V",SDLK_v), K(" B",SDLK_b), K(" N",SDLK_n), K(" M",SDLK_m), K("Sym",SDLK_LCTRL),K("Space",SDLK_SPACE), + K("Ext",SDLK_TAB),K(" ,",SDLK_COMMA),K(" .",SDLK_PERIOD), K(" ;",SDLK_SEMICOLON), K(" \"",SDLK_QUOTEDBL),KNL(),K(" Up",SDLK_UP),K("Down",SDLK_DOWN), K("Left",SDLK_LEFT),K("Right",SDLK_RIGHT), + K("None",0),K("Done",1),K("Fire",SDLK_LALT),K("Del",SDLK_BACKSPACE),KNL(),KNL(),KNL(),KNL(),KNL(),KNL()}; void VirtualKeyboard_init(SDL_Surface *screen, TTF_Font *font) { @@ -151,7 +151,11 @@ struct virtkey *get_key_internal() else if (k & KEY_SELECT) { virtkey_t *key = &keys[ VirtualKeyboard.sel_y * KEY_COLS + VirtualKeyboard.sel_x ]; - + /* + if (key->sdl_code == 1) // "Done" + if (keys[3 * KEY_COLS + 0 ].is_done) {key->sdl_code = 304; return key; } //Caps Shit + else if (keys[3 * KEY_COLS + 8 ].is_done) {key->sdl_code = 306; return key; } //Sym Shit + */ 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) @@ -170,7 +174,7 @@ struct virtkey *get_key_internal() struct virtkey* get_key() { virtkey_t *key; - SDL_Rect rect = {32, 128, FULL_DISPLAY_X-64, FULL_DISPLAY_Y-272}; + SDL_Rect rect = {32, 120, FULL_DISPLAY_X-64, FULL_DISPLAY_Y-250}; keys[3 * KEY_COLS + 0 ].is_done = 0; //Caps Shit keys[3 * KEY_COLS + 8 ].is_done = 0; //Sym Shift @@ -178,6 +182,8 @@ struct virtkey* get_key() SDL_FillRect(VirtualKeyboard.screen, &rect, SDL_MapRGB(ordenador.screen->format, 0xff, 0xff, 0xff)); key = get_key_internal(); + + clean_screen(); return key; } diff --git a/src/VirtualKeyboard.h b/src/VirtualKeyboard.h index 4b8eb35..defde62 100644 --- a/src/VirtualKeyboard.h +++ b/src/VirtualKeyboard.h @@ -27,8 +27,7 @@ typedef struct virtkey { - const char *name; //It is not necessary in FBZX Wii - const char *ev_name; //It is not necessary in FBZX Wii + const char *name; int sdl_code; int is_done; int caps_on; diff --git a/src/computer.c b/src/computer.c index 59a2ae3..9a8b076 100644 --- a/src/computer.c +++ b/src/computer.c @@ -713,7 +713,7 @@ inline void read_keyboard () { enum joystate_y {JOY_CENTER_Y, JOY_UP, JOY_DOWN}; int joy_axis_x[2],joy_axis_y[2], joy_n, joybutton_n; static unsigned char joybutton_matrix[2][322]; - unsigned char status_hat; + unsigned char status_hat[2]; int fire_on[2]; fire_on[0]=0; fire_on[1]=0; @@ -764,11 +764,14 @@ inline void read_keyboard () { SDL_JoystickGetButton(ordenador.joystick_sdl[joy_n], joybutton_n); } //JOY HAT - status_hat = SDL_JoystickGetHat(ordenador.joystick_sdl[joy_n], 0); - joybutton_matrix[joy_n][(ordenador.joybuttonkey[joy_n][18])] = (status_hat & SDL_HAT_UP); - joybutton_matrix[joy_n][(ordenador.joybuttonkey[joy_n][19])] = (status_hat & SDL_HAT_DOWN); - joybutton_matrix[joy_n][(ordenador.joybuttonkey[joy_n][20])] = (status_hat & SDL_HAT_LEFT); - joybutton_matrix[joy_n][(ordenador.joybuttonkey[joy_n][21])] = (status_hat & SDL_HAT_RIGHT); + status_hat[joy_n] = SDL_JoystickGetHat(ordenador.joystick_sdl[joy_n], 0); + if(!ordenador.joypad_as_joystick[joy_n]) + { + joybutton_matrix[joy_n][(ordenador.joybuttonkey[joy_n][18])] = (status_hat[joy_n] & SDL_HAT_UP); + joybutton_matrix[joy_n][(ordenador.joybuttonkey[joy_n][19])] = (status_hat[joy_n] & SDL_HAT_DOWN); + joybutton_matrix[joy_n][(ordenador.joybuttonkey[joy_n][20])] = (status_hat[joy_n] & SDL_HAT_LEFT); + joybutton_matrix[joy_n][(ordenador.joybuttonkey[joy_n][21])] = (status_hat[joy_n] & SDL_HAT_RIGHT); + } } //Keyboard buffer @@ -790,7 +793,7 @@ inline void read_keyboard () { joybutton_matrix[0][(ordenador.keyboard_buffer[1][ordenador.kbd_buffer_pointer])]=1; ordenador.kbd_buffer_pointer--; - countdown=15; + countdown=8; } @@ -844,7 +847,7 @@ inline void read_keyboard () { ordenador.keyboard_buffer[0][1]= SDLK_F6; //F6 ordenador.keyboard_buffer[1][1]= 0; ordenador.kbd_buffer_pointer=6; - countdown=15; + countdown=8; break; case SDLK_F10: // Reset emulator @@ -889,7 +892,9 @@ inline void read_keyboard () { } } for(joy_n=0;joy_ndblscan,10); fprintf(fconfig,"volume=%c%c",65+(object->volume/4),10); fprintf(fconfig,"bw=%c%c",48+object->bw,10); + fprintf(fconfig,"tap_fast=%c%c",48+object->tape_fast_load,10); + fprintf(fconfig,"joypad1=%c%c",48+object->joypad_as_joystick[0],10); + fprintf(fconfig,"joypad2=%c%c",48+object->joypad_as_joystick[1],10); + fprintf(fconfig,"rumble1=%c%c",48+object->rumble[0],10); + fprintf(fconfig,"rumble2=%c%c",48+object->rumble[1],10); + + + for (joy_n=0; joy_n<2; joy_n++) + for (key=0; key<22; key++) + fprintf(fconfig,"joybutton_%c_%c=%.3d%c",joy_n+48,key+97, object->joybuttonkey[joy_n][key],10); + fclose(fconfig); + } void load_config(struct computer *object) { char config_path[1024]; char line[1024],carac,done; - int length,pos; + int length,pos, key_sdl=0;; FILE *fconfig; - unsigned char volume=255,mode128k=255,issue=255,joystick1=255,joystick2=255,ay_emul=255,mdr_active=255,dblscan=255,bw=255; + unsigned char volume=255,mode128k=255,issue=255,joystick1=255,joystick2=255,ay_emul=255,mdr_active=255, + dblscan=255,bw=255, tap_fast=0, joypad1=0, joypad2=0, rumble1=0, rumble2=0, joy_n=0, key_n=0; strcpy(config_path,getenv("HOME")); length=strlen(config_path); @@ -468,12 +482,12 @@ void load_config(struct computer *object) { issue=line[6]-'0'; continue; } - if (!strncmp(line,"joystick1=",9)) { - joystick1=line[9]-'0'; + if (!strncmp(line,"joystick1=",10)) { + joystick1=line[10]-'0'; continue; } - if (!strncmp(line,"joystick2=",9)) { - joystick2=line[9]-'0'; + if (!strncmp(line,"joystick2=",10)) { + joystick2=line[10]-'0'; continue; } if (!strncmp(line,"ay_sound=",9)) { @@ -496,6 +510,32 @@ void load_config(struct computer *object) { bw=(line[3]-'0'); continue; } + if (!strncmp(line,"tap_fast=",9)) { + tap_fast=(line[9]-'0'); + continue; + } + if (!strncmp(line,"joypad1=",8)) { + joypad1=line[8]-'0'; + continue; + } + if (!strncmp(line,"joypad2=",8)) { + joypad2=line[8]-'0'; + continue; + } + if (!strncmp(line,"rumble1=",8)) { + rumble1=line[8]-'0'; + continue; + } + if (!strncmp(line,"rumble2=",8)) { + rumble2=line[8]-'0'; + continue; + } + if (!strncmp(line,"joybutton_",10)) { + sscanf(line, "joybutton_%c_%c=%3d",&joy_n ,&key_n, &key_sdl); + if ((joy_n<50) && (joy_n>47) && (key_n<119) && (key_n>96)) + object->joybuttonkey[joy_n-48][key_n-97]=key_sdl; + continue; + } } if (mode128k<5) { @@ -526,7 +566,22 @@ void load_config(struct computer *object) { object->volume=volume; set_volume(volume); } - + if (tap_fast<2) { + object->tape_fast_load=tap_fast; + } + if (joypad1<2) { + object->joypad_as_joystick[0]=joypad1; + } + if (joypad2<2) { + object->joypad_as_joystick[1]=joypad2; + } + if (rumble1<2) { + object->rumble[0]=rumble1; + } + if (rumble2<2) { + object->rumble[1]=rumble2; + } + fclose(fconfig); } @@ -581,6 +636,10 @@ int main(int argc,char *argv[]) { printf("Computer init\n"); printf("Modo: %d\n",ordenador.mode128k); + + printf("Set volume\n"); + set_volume(70); + // load current config load_config(&ordenador); printf("Modo: %d\n",ordenador.mode128k); diff --git a/src/gui_sdl.c b/src/gui_sdl.c index 04b2ec3..d4e36bf 100644 --- a/src/gui_sdl.c +++ b/src/gui_sdl.c @@ -50,6 +50,7 @@ extern FILE *fdebug; #endif extern int countdown; +void clean_screen(); static const char *main_menu_messages[] = { @@ -98,9 +99,11 @@ static const char *input_messages[] = { /*06*/ "Bind key to Classic", /*07*/ "^|a|b|x|y|L|R|Zl|Zr|-", /*08*/ "Bind key to Pad", - /*09*/ "^|UP|DOWN|LEFT|RIGHT", - /*10*/ "Rumble", + /*09*/ "^|Up|Down|Left|Right", + /*10*/ "Use Joypad as Joystick", /*11*/ "^|On|Off", + /*12*/ "Rumble", + /*13*/ "^|On|Off", NULL, }; @@ -236,7 +239,7 @@ static void manage_tape(int which) break; case 1: //Emulate load "" ordenador.kbd_buffer_pointer=6; - countdown=15; + countdown=8; ordenador.keyboard_buffer[0][6]= SDLK_1; //Edit ordenador.keyboard_buffer[1][6]= SDLK_LSHIFT; ordenador.keyboard_buffer[0][5]= SDLK_j; //Load @@ -348,7 +351,7 @@ static void emulation_settings(void) if (submenus[0] != submenus_old[0]) ResetComputer(); else ordenador.ay_emul = !submenus[6]; - ordenador.volume = submenus[1]*8; + ordenador.volume = submenus[1]*8; //I should use set_volume() ? ordenador.tape_fast_load = !submenus[2]; ordenador.turbo = !submenus[3]; @@ -386,7 +389,7 @@ static void input_options(int joy) const unsigned int pad_to_sdl[] = {18, 19, 20, 21}; int joy_key = 1; unsigned int sdl_key; - unsigned int submenus[6]; + unsigned int submenus[7]; int opt; struct virtkey *virtualkey; @@ -394,7 +397,8 @@ static void input_options(int joy) memset(submenus, 0, sizeof(submenus)); submenus[0] = ordenador.joystick[joy]; - submenus[5] = !ordenador.rumble[joy]; + submenus[5] = !ordenador.joypad_as_joystick[joy]; + submenus[6] = !ordenador.rumble[joy]; opt = menu_select_title("Input menu", input_messages, submenus); @@ -402,9 +406,10 @@ static void input_options(int joy) return; ordenador.joystick[joy] = submenus[0]; - ordenador.rumble[joy] = !submenus[5]; + ordenador.joypad_as_joystick[joy] = !submenus[5]; + ordenador.rumble[joy] = !submenus[6]; - if (opt == 0 || opt == 10) + if (opt == 0 || opt == 10|| opt == 12) return; virtualkey = get_key(); @@ -412,6 +417,11 @@ static void input_options(int joy) return; sdl_key = virtualkey->sdl_code; + if (virtualkey->sdl_code==1) //"Done" selected + {if (virtualkey->caps_on) sdl_key = 304; //Caps Shit + else if (virtualkey->sym_on) sdl_key = 306; //Sym Shit + else return; } + switch(opt) { case 2: // wiimote @@ -744,7 +754,7 @@ void virtual_keyboard(void) if (key) {key_code = key->sdl_code;} else return; ordenador.kbd_buffer_pointer=1; - countdown=15; + countdown=8; 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; @@ -896,4 +906,6 @@ void main_menu() } } while (opt == 5 || opt == 7 || opt == 8 || opt == 12); + clean_screen(); + } diff --git a/src/menus.c b/src/menus.c index 1f0729c..b0a2d2a 100644 --- a/src/menus.c +++ b/src/menus.c @@ -1887,8 +1887,6 @@ void keyboard_menu() { wait_key(); clean_screen(); } - - void clean_screen() { diff --git a/src/sound.c b/src/sound.c index cf36e47..bc74df3 100644 --- a/src/sound.c +++ b/src/sound.c @@ -81,7 +81,6 @@ int sound_init() { ordenador.sign=0; ordenador.format=0; ordenador.channels=1; - ordenador.channels = 1; ordenador.freq=48000; ordenador.buffer_len=4800; // will wait 1/10 second return (0); @@ -183,8 +182,8 @@ int sound_init_asnd() { ASND_Init(); ASND_Pause(0); ordenador.sign=0; - ordenador.format=0; - ordenador.channels=1; + ordenador.format=0; //8 bit + ordenador.channels=1; //mono ordenador.freq=48000; ordenador.buffer_len=4096; started_sound_asnd = 0; @@ -497,7 +496,7 @@ void sound_play() { case SOUND_ASND: // ASND if (!started_sound_asnd) { ASND_SetVoice(1,VOICE_MONO_8BIT,48000,0,sound[0],ordenador.buffer_len, - ordenador.volume, ordenador.volume, callback); + MID_VOLUME, MID_VOLUME, callback); started_sound_asnd = 1; } //Double buffer diff --git a/src/spk_ay.c b/src/spk_ay.c index dbaa0bf..abee2b2 100644 --- a/src/spk_ay.c +++ b/src/spk_ay.c @@ -288,7 +288,7 @@ inline void play_sound (unsigned int tstados) { while (ordenador.tstados_counter_sound >= ordenador.tst_sample) { ordenador.tstados_counter_sound -= ordenador.tst_sample; - if (sound_type!=1) + if (sound_type!=1) //!SOUND_OSS for (bucle = 0; bucle < ordenador.increment; bucle++) { sample_v = ordenador.sample1b[bucle]; if ((ordenador.sound_bit) && (sample_v)) {