From efa831330a1f942400bd2826532e3b9292202553 Mon Sep 17 00:00:00 2001 From: "fabio.olimpieri" Date: Sat, 16 Feb 2013 12:09:54 +0000 Subject: [PATCH] Pause instant load option, improved load command, QAOP joystick, CBA ay Audio --- src/computer.c | 112 +++++++++++++++++++++++++++++++++---------------- src/computer.h | 2 + src/emulator.c | 25 +++++++---- src/gui_sdl.c | 55 +++++++++++++++--------- src/spk_ay.c | 4 ++ src/tape.c | 54 ++++++++++++++---------- 6 files changed, 166 insertions(+), 86 deletions(-) diff --git a/src/computer.c b/src/computer.c index c4a2e42..143d4a7 100644 --- a/src/computer.c +++ b/src/computer.c @@ -119,6 +119,7 @@ void computer_init () { //Called only on start-up ordenador.pause = 1; // tape stop ordenador.tape_fast_load = 1; // fast load by default ordenador.rewind_on_reset = 1; //Rewound on reset by default + ordenador.pause_instant_load = 0; ordenador.tape_current_mode = TAP_TRASH; ordenador.tap_file = NULL; @@ -561,6 +562,7 @@ inline void show_screen (int tstados) { curr_frames++; if (ordenador.tape_start_countdwn==1) ordenador.pause=0; //Autoplay if (ordenador.tape_start_countdwn>0) ordenador.tape_start_countdwn--; + if (ordenador.pause_fastload_countdwn>0) ordenador.pause_fastload_countdwn--; } return; } @@ -666,6 +668,7 @@ inline void show_screen (int tstados) { if (ordenador.tape_start_countdwn==1) ordenador.pause=0; //Autoplay if (ordenador.tape_start_countdwn>0) ordenador.tape_start_countdwn--; + if (ordenador.pause_fastload_countdwn>0) ordenador.pause_fastload_countdwn--; if (ordenador.mustlock) { SDL_UnlockSurface (ordenador.screen); @@ -708,6 +711,7 @@ inline void show_screen_precision (int tstados) { curr_frames++; if (ordenador.tape_start_countdwn==1) ordenador.pause=0; //Autoplay if (ordenador.tape_start_countdwn>0) ordenador.tape_start_countdwn--; + if (ordenador.pause_fastload_countdwn>0) ordenador.pause_fastload_countdwn--; } //if (ordenador.tstados_counter > 31) ordenador.interr = 0; return; @@ -911,6 +915,7 @@ inline void show_screen_precision (int tstados) { if (ordenador.tape_start_countdwn==1) ordenador.pause=0; //Autoplay if (ordenador.tape_start_countdwn>0) ordenador.tape_start_countdwn--; + if (ordenador.pause_fastload_countdwn>0) ordenador.pause_fastload_countdwn--; if (ordenador.mustlock) { SDL_UnlockSurface (ordenador.screen); @@ -1247,45 +1252,63 @@ inline void read_keyboard () { case SDLK_F9: //Emulate load "" - if (ordenador.mode128k==4) //Spanish 128k - { - ordenador.keyboard_buffer[0][8]= SDLK_l; - ordenador.keyboard_buffer[1][8]= 0; - ordenador.keyboard_buffer[0][7]= SDLK_o; - ordenador.keyboard_buffer[1][7]= 0; - ordenador.keyboard_buffer[0][6]= SDLK_a; - ordenador.keyboard_buffer[1][6]= 0; - ordenador.keyboard_buffer[0][5]= SDLK_d; - 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 - play - ordenador.keyboard_buffer[1][1]= 0; - ordenador.kbd_buffer_pointer=8; - } - else - { - 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=5; - } - - countdown_buffer=8; + switch (ordenador.mode128k) + { + case 4://Spanish 128k + ordenador.keyboard_buffer[0][8]= SDLK_l; + ordenador.keyboard_buffer[1][8]= 0; + ordenador.keyboard_buffer[0][7]= SDLK_o; + ordenador.keyboard_buffer[1][7]= 0; + ordenador.keyboard_buffer[0][6]= SDLK_a; + ordenador.keyboard_buffer[1][6]= 0; + ordenador.keyboard_buffer[0][5]= SDLK_d; + 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 - play + ordenador.keyboard_buffer[1][1]= 0; + ordenador.kbd_buffer_pointer=8; break; - + case 3: //+3 + case 2: //+2 + case 1: //128k + ordenador.kbd_buffer_pointer=2; + if (ordenador.mport1 & 0x10) //ROM 48k + { + 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.kbd_buffer_pointer=5; + } + ordenador.keyboard_buffer[0][2]= SDLK_RETURN; // Return + ordenador.keyboard_buffer[1][2]= 0; + ordenador.keyboard_buffer[0][1]= SDLK_F6; //F6 - play + ordenador.keyboard_buffer[1][1]= 0; + break; + case 0: //48k + default: + 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=5; + break; + } + break; case SDLK_F10: // Reset emulator ResetComputer (); break; @@ -1358,6 +1381,13 @@ inline void read_keyboard () { if ((ordenador.joy_axis_x_state[joy_n] == JOY_LEFT)||(joybutton_matrix[joy_n][SDLK_LEFT])) ordenador.k12|= 16; if (joybutton_matrix[joy_n][SDLK_LALT]) {ordenador.k12|= 1; fire_on[joy_n]=1;}//fire button break; + case 4: // QAOP + if ((ordenador.joy_axis_y_state[joy_n] == JOY_UP) ||(joybutton_matrix[joy_n][SDLK_UP]))ordenador.k10|=1; + if ((ordenador.joy_axis_y_state[joy_n] == JOY_DOWN)||(joybutton_matrix[joy_n][SDLK_DOWN])) ordenador.k9 |=1; + if ((ordenador.joy_axis_x_state[joy_n] == JOY_RIGHT)||(joybutton_matrix[joy_n][SDLK_RIGHT])) ordenador.k13|=1; + if ((ordenador.joy_axis_x_state[joy_n] == JOY_LEFT)||(joybutton_matrix[joy_n][SDLK_LEFT])) ordenador.k13|=2; + if (joybutton_matrix[joy_n][SDLK_LALT]) {ordenador.k15|=1; fire_on[joy_n]=1;}//fire button + break; } } else @@ -1394,6 +1424,13 @@ inline void read_keyboard () { if ((ordenador.joy_axis_x_state[joy_n] == JOY_LEFT)||(status_hat[joy_n] & SDL_HAT_LEFT)) ordenador.k12|= 16; if (joybutton_matrix[joy_n][SDLK_LALT]) {ordenador.k12|= 1; fire_on[joy_n]=1;}//fire button break; + case 4: // QAOP + if ((ordenador.joy_axis_y_state[joy_n] == JOY_UP)||(status_hat[joy_n] & SDL_HAT_UP)) ordenador.k10|=1; + if ((ordenador.joy_axis_y_state[joy_n] == JOY_DOWN)||(status_hat[joy_n] & SDL_HAT_DOWN)) ordenador.k9 |=1; + if ((ordenador.joy_axis_x_state[joy_n] == JOY_RIGHT)||(status_hat[joy_n] & SDL_HAT_RIGHT)) ordenador.k13|=1; + if ((ordenador.joy_axis_x_state[joy_n] == JOY_LEFT)||(status_hat[joy_n] & SDL_HAT_LEFT)) ordenador.k13|=2; + if (joybutton_matrix[joy_n][SDLK_LALT]) {ordenador.k15|=1; fire_on[joy_n]=1;}//fire button + break; } } @@ -1689,6 +1726,7 @@ void ResetComputer () { ordenador.precision=ordenador.precision_old; //in case the machine is reset during loading ordenador.tape_start_countdwn=0; + ordenador.pause_fastload_countdwn=0; curr_frames=0; ordenador.tstados_counter=0; ordenador.cicles_counter=0; diff --git a/src/computer.h b/src/computer.h index fceed70..b232e3c 100644 --- a/src/computer.h +++ b/src/computer.h @@ -176,6 +176,7 @@ struct computer { FILE *tap_file; unsigned char tape_fast_load; // 0 normal load; 1 fast load unsigned char rewind_on_reset; + unsigned char pause_instant_load; unsigned char current_tap[MAX_PATH_LENGTH]; unsigned char last_selected_file[MAX_PATH_LENGTH]; unsigned char last_selected_poke_file[MAX_PATH_LENGTH]; @@ -189,6 +190,7 @@ struct computer { unsigned char tape_bits_at_end; unsigned int tape_loop_counter; unsigned int tape_start_countdwn; + unsigned int pause_fastload_countdwn; long tape_loop_pos; unsigned char tape_write; // 0 can't write; 1 can write diff --git a/src/emulator.c b/src/emulator.c index 4cad70a..db6b57e 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -710,6 +710,7 @@ int save_config(struct computer *object, char *filename) { fprintf(fconfig,"volume=%c%c",65+(object->volume),10); fprintf(fconfig,"bw=%c%c",48+object->bw,10); fprintf(fconfig,"tap_fast=%c%c",48+object->tape_fast_load,10); + fprintf(fconfig,"pause_instant_load=%c%c",48+object->pause_instant_load,10); fprintf(fconfig,"rewind_on_reset=%c%c",48+object->rewind_on_reset,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); @@ -888,7 +889,7 @@ int load_config(struct computer *object, char *filename) { unsigned char volume=255,mode128k=255,issue=255,ntsc=255, joystick1=255,joystick2=255,ay_emul=255,mdr_active=255, dblscan=255,framerate =255, screen =255, text=255, precision=255, bw=255, tap_fast=255, audio_mode=255, joypad1=255, joypad2=255, rumble1=255, rumble2=255, joy_n=255, key_n=255, port=255, autoconf=255, turbo=225, vk_auto=255, vk_rumble=255, - rewind_on_reset=255; + rewind_on_reset=255, pause_instant_load =255; if (filename) strcpy(config_path,filename); else return -2; @@ -986,6 +987,10 @@ int load_config(struct computer *object, char *filename) { tap_fast=(line[9]-'0'); continue; } + if (!strncmp(line,"pause_instant_load=",19)) { + pause_instant_load=(line[19]-'0'); + continue; + } if (!strncmp(line,"rewind_on_reset=",16)) { rewind_on_reset=(line[16]-'0'); continue; @@ -1043,16 +1048,16 @@ int load_config(struct computer *object, char *filename) { if (ntsc<2) { object->videosystem=ntsc; } - if (joystick1<4) { + if (joystick1<5) { object->joystick[0]=joystick1; } - if (joystick2<4) { + if (joystick2<5) { object->joystick[1]=joystick2; } if (ay_emul<2) { object->ay_emul=ay_emul; } - if (audio_mode<4) { + if (audio_mode<5) { object->audio_mode=audio_mode; } if (mdr_active<2) { @@ -1084,6 +1089,9 @@ int load_config(struct computer *object, char *filename) { if (tap_fast<2) { object->tape_fast_load=tap_fast; } + if (pause_instant_load<2) { + object->pause_instant_load=pause_instant_load; + } if (rewind_on_reset<2) { object->rewind_on_reset=rewind_on_reset; } @@ -1531,10 +1539,13 @@ int main(int argc,char *argv[]) { FAST_LOAD is 1, we must load the block in memory and return */ if((!ordenador.mdr_paged)&&(PC==0x056c) && (ordenador.tape_fast_load==1)) { - if(ordenador.tap_file!=NULL) + if (ordenador.tap_file!=NULL) { - if (ordenador.tape_file_type==TAP_TAP) fastload_block_tap(ordenador.tap_file); - else fastload_block_tzx(ordenador.tap_file); + if (ordenador.pause_fastload_countdwn==0) + { + if (ordenador.tape_file_type==TAP_TAP) fastload_block_tap(ordenador.tap_file); + else fastload_block_tzx(ordenador.tap_file); + } } else { sprintf(ordenador.osd_text,"No TAP file selected"); diff --git a/src/gui_sdl.c b/src/gui_sdl.c index 061533f..7381857 100644 --- a/src/gui_sdl.c +++ b/src/gui_sdl.c @@ -82,12 +82,14 @@ static const char *emulation_messages[] = { /*03*/ "^|100%|50%|33%|25%|20%", /*04*/ "Tape instant load", /*05*/ "^|on|off", - /*06*/ "Turbo mode", - /*07*/ "^|off|auto|fast|ultrafast", - /*08*/ "Rewind tape on reset", - /*09*/ "^|on|off", - /*10*/ "Precision", + /*06*/ "Instant load pause", + /*07*/ "^|on|off", + /*08*/ "Turbo mode", + /*09*/ "^|off|auto|fast|ultrafast", + /*10*/ "Rewind tape on reset", /*11*/ "^|on|off", + /*12*/ "Precision", + /*13*/ "^|on|off", NULL }; @@ -99,7 +101,7 @@ static const char *audio_messages[] = { /*04*/ "^|on|off", /*05*/ " ", /*06*/ "Audio mode", - /*07*/ "^|mono|ABC|ACB|BAC", + /*07*/ "^|mono|ABC|ACB|BAC|CBA", /*08 " ", */ /*09 "Beeper low pass filter",*/ /*10 "^|0|1|2|3|4|5|6|7|max",*/ @@ -123,7 +125,7 @@ static const char *screen_messages[] = { static const char *input_messages[] = { /*00*/ "Joystick type", - /*01*/ "^|Cursor|Kempston|Sinclair1|Sinclair2", + /*01*/ "^|Cursor|Kempston|Sinclair1|Sinclair2|QAOP", /*02*/ "Bind key to Wiimote", /*03*/ "^|A|B|1|2|-|+", /*04*/ "Bind key to Nunchuk", @@ -393,11 +395,21 @@ static int manage_tape(int which) case 3: //+3 case 2: //+2 case 1: //128k + ordenador.kbd_buffer_pointer=2; + if (ordenador.mport1 & 0x10) //ROM 48k + { + 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.kbd_buffer_pointer=5; + } ordenador.keyboard_buffer[0][2]= SDLK_RETURN; // Return ordenador.keyboard_buffer[1][2]= 0; ordenador.keyboard_buffer[0][1]= SDLK_F6; //F6 - play ordenador.keyboard_buffer[1][1]= 0; - ordenador.kbd_buffer_pointer=2; break; case 0: //48k default: @@ -432,7 +444,9 @@ static int manage_tape(int which) ordenador.tape_current_mode=TAP_TRASH; rewind_tape(ordenador.tap_file,1); } - msgInfo("Tape rewound",3000,NULL); + //msgInfo("Tape rewound",3000,NULL); + sprintf (ordenador.osd_text, "Rewind tape"); + ordenador.osd_time = 100; retorno=-1; break; case 5: //Create @@ -507,7 +521,7 @@ static void set_machine_model(int which) static int emulation_settings(void) { - unsigned int submenus[6],submenus_old[6]; + unsigned int submenus[7],submenus_old[7]; int opt, i, retorno; unsigned char old_mode, old_videosystem; @@ -518,12 +532,13 @@ static int emulation_settings(void) submenus[0] = get_machine_model(); submenus[1] = jump_frames; submenus[2] = !ordenador.tape_fast_load; - submenus[3] = ordenador.turbo; - submenus[4] = !ordenador.rewind_on_reset; - submenus[5] = !ordenador.precision; + submenus[3] = !ordenador.pause_instant_load; + submenus[4] = ordenador.turbo; + submenus[5] = !ordenador.rewind_on_reset; + submenus[6] = !ordenador.precision; - for (i=0; i<6; i++) submenus_old[i] = submenus[i]; + for (i=0; i<7; i++) submenus_old[i] = submenus[i]; old_mode=ordenador.mode128k; old_videosystem = ordenador.videosystem; @@ -537,11 +552,13 @@ static int emulation_settings(void) jump_frames = submenus[1]; ordenador.tape_fast_load = !submenus[2]; - ordenador.turbo = submenus[3]; - ordenador.rewind_on_reset = !submenus[4]; + ordenador.pause_instant_load = !submenus[3]; + + ordenador.turbo = submenus[4]; + ordenador.rewind_on_reset = !submenus[5]; curr_frames=0; - if (submenus[3] != submenus_old[3]) + if (submenus[4] != submenus_old[4]) { switch(ordenador.turbo) { @@ -572,9 +589,9 @@ static int emulation_settings(void) } } - if (submenus[5] != submenus_old[5]) + if (submenus[6] != submenus_old[6]) { - ordenador.precision = !submenus[5]; + ordenador.precision = !submenus[6]; ordenador.precision_old=ordenador.precision; if (ordenador.turbo_state!=1) //Tape is not loading with turbo mode if (ordenador.precision) diff --git a/src/spk_ay.c b/src/spk_ay.c index 5eab8fc..0e20808 100644 --- a/src/spk_ay.c +++ b/src/spk_ay.c @@ -360,6 +360,10 @@ inline void play_sound (unsigned int tstados) { lvalue = (beeper + ordenador.vol_b*2 + ordenador.vol_a)*ordenador.volume; rvalue = (beeper + ordenador.vol_a + ordenador.vol_c*2)*ordenador.volume; break; + case 4: //CBA + lvalue = (beeper + ordenador.vol_b + ordenador.vol_c*2)*ordenador.volume; + rvalue = (beeper + ordenador.vol_a*2 + ordenador.vol_b)*ordenador.volume; + break; default: //No emulation rvalue = beeper*ordenador.volume; lvalue = beeper*ordenador.volume; diff --git a/src/tape.c b/src/tape.c index 177faa4..2f2bf8d 100644 --- a/src/tape.c +++ b/src/tape.c @@ -862,7 +862,12 @@ void fastload_block_tap (FILE * fichero) { procesador.Ra.br.F=0x45; procesador.Rm.br.F |= F_C; // Load OK - //if (longitud==6913) sleep(2); //Screen + + if (ordenador.pause_instant_load) + { + ordenador.pause_fastload_countdwn=2000/20+1; //tap pause + } + return; } @@ -950,11 +955,11 @@ void fastload_block_tzx (FILE * fichero) { longitud = ((unsigned int) value[0]) + 256 * ((unsigned int) value[1])+ 65536 * ((unsigned int) value[2]); for(bucle=0;bucle199) ordenador.osd_text[199]=0; else ordenador.osd_text[bucle]=0; - break; + break; case 0x32: // archive info retval=fread(value,1,2,fichero); // length if (retval!=2) {procesador.Rm.br.F &= (~F_C);return;} len = ((unsigned int) value[0]) + 256 * ((unsigned int) value[1]); retval=fread(value,1,len,fichero); - break; + break; case 0x33: // hardware info retval=fread(value,1,1,fichero); if (retval!=1) {procesador.Rm.br.F &= (~F_C);return;} len = (unsigned int) value[0] *3; retval=fread(value,1,len,fichero); - break; + break; case 0x34: // emulation info retval=fread(value,1,8,fichero); - break; + break; case 0x35: // custom info retval=fread(value,1,16,fichero); @@ -1059,11 +1064,11 @@ void fastload_block_tzx (FILE * fichero) { if (retval!=4) {procesador.Rm.br.F &= (~F_C);return;} len = ((unsigned int) value[0]) + 256 * ((unsigned int) value[1]) + 65536*((unsigned int) value[2]);// + 16777216*((unsigned int) value[3]); retval=fread(value,1,len,fichero); - break; + break; default: // not supported procesador.Rm.br.F &= (~F_C);return; //Tape error - break; + break; } } while ((blockid!=0x10)&&(!feof(fichero))); @@ -1151,8 +1156,6 @@ void fastload_block_tzx (FILE * fichero) { procesador.Ra.br.F=0x45; procesador.Rm.br.F |= F_C; // Load OK - //if (longitud==6913) sleep(2); //Screen - byte_position=ftell(fichero); retval=fread (&blockid, 1, 1, fichero); //Read next id block @@ -1164,9 +1167,10 @@ void fastload_block_tzx (FILE * fichero) { { retval=fread (value, 1, 5, fichero); //read till flag byte if (retval==5) - if ((value[4]!=0x0)&&(value[4]!=0xFF)) blockid=0x11; //custom data + if ((value[4]!=0x0)&&(value[4]!=0xFF)) blockid=0x1; //custom data + if ((value[4]==0x0)&&((value[2]+value[3]*256)!=0x13)) blockid=0x1; //custom data } - if ((blockid==0x11)||(blockid==0x12)||(blockid==0x13)||(blockid==0x14)||(blockid==0x21)||(blockid==0x24)) + if (blockid!=0x10) { //Anticipate auto ultra fast mode if ((ordenador.turbo_state!= 1)&&(ordenador.turbo==1)) @@ -1177,6 +1181,10 @@ void fastload_block_tzx (FILE * fichero) { } ordenador.tape_start_countdwn=((unsigned int)pause[0]+256*(unsigned int)pause[1])/30+1; //autoplay countdown } + else if (ordenador.pause_instant_load) + { + ordenador.pause_fastload_countdwn=((unsigned int)pause[0]+256*(unsigned int)pause[1])/20+1; //tzx pause + } fseek(fichero, byte_position, SEEK_SET); }