2 * Copyright (C) 1996-1998 Szeredi Miklos
3 * Email: mszeredi@inf.bme.hu
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version. See the file COPYING.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "lib/configfile.h"
48 #include "zxbox_keyb.h"
50 int endofsingle IBSS_ATTR
;
52 int sp_nosync IBSS_ATTR
= 0;
54 int showframe IBSS_ATTR
= 1;
57 qbyte sp_int_ctr IBSS_ATTR
= 0;
58 int intkeys
[5] IBSS_ATTR
;
64 #define GLOBALCFG "zxbox.cfg"
66 /* here goes settings hadling */
68 /*static struct zxbox_settings settings;*/
69 static struct zxbox_settings old_settings
;
71 static char* noyes_options
[] = { "No", "Yes" };
72 /*static char* kempston_options[] = { "No", "Yes" };
73 static char* showfps_options[] = {"No", "Yes"};*/
75 static struct configdata config
[] =
77 {TYPE_ENUM
, 0, 2, { .int_p
= &settings
.invert_colors
}, "Invert Colors",
79 {TYPE_ENUM
, 0, 2, { .int_p
= &settings
.kempston
}, "Map keys to kempston",
81 {TYPE_ENUM
, 0, 2, { .int_p
= &settings
.showfps
}, "Show Speed",
83 {TYPE_ENUM
, 0, 2, { .int_p
= &settings
.sound
}, "Sound", noyes_options
},
84 {TYPE_INT
, 0, 9, { .int_p
= &settings
.frameskip
}, "Frameskip", NULL
},
85 {TYPE_INT
, 1, 10, { .int_p
= &settings
.volume
}, "Volume", NULL
},
86 {TYPE_STRING
, 0, 5, { .string
= (char*)&settings
.keymap
}, "Key Mapping",
89 int spcf_read_conf_file(const char *filename
)
93 settings
.keymap
[0]='2';
94 settings
.keymap
[1]='w';
95 settings
.keymap
[2]='9';
96 settings
.keymap
[3]='0';
97 settings
.keymap
[4]='z';
98 settings
.kempston
= 1 ;
99 settings
.invert_colors
=0;
101 settings
.frameskip
= 0;
104 if (configfile_load(filename
, config
,
105 sizeof(config
)/sizeof(*config
),
109 /* If the loading failed, save a new config file (as the disk is
111 configfile_save(filename
, config
,
112 sizeof(config
)/sizeof(*config
),
115 /* Keep a copy of the saved version of the settings - so we can check if
116 the settings have changed when we quit */
117 old_settings
= settings
;
118 sound_on
= settings
.sound
;
119 showframe
= settings
.frameskip
+1;
121 for ( i
=0 ; i
<5 ; i
++){
122 if (settings
.keymap
[i
] == 'E')
123 intkeys
[i
]=SK_KP_Enter
;
124 else if ( settings
.keymap
[i
] == 'S' )
125 intkeys
[i
]=SK_KP_Space
;
127 intkeys
[i
] = (unsigned) settings
.keymap
[i
];
132 /* and here it stops (settings loading ;) )*/
135 static void set_keys(void){
140 MENUITEM_STRINGLIST(menu
, "Custom keymap", NULL
,
141 "Map Up key", "Map Down key", "Map Left key",
142 "Map Right key", "Map Fire/Jump key");
144 rb
->button_clear_queue();
147 result
= rb
->do_menu(&menu
, &selected
, NULL
, false);
152 if (!zx_kbd_input((char*) &c
))
154 settings
.keymap
[0]=c
;
158 if (!zx_kbd_input((char*) &c
))
160 settings
.keymap
[1]=c
;
164 if (!zx_kbd_input((char*) &c
))
166 settings
.keymap
[2]=c
;
170 if (!zx_kbd_input((char*) &c
))
172 settings
.keymap
[3]=c
;
176 if (!zx_kbd_input((char*) &c
))
178 settings
.keymap
[4]=c
;
188 /* select predefined keymap */
189 static void select_keymap(void){
193 MENUITEM_STRINGLIST(menu
, "Predefined keymap", NULL
,
194 "2w90z", "qaopS", "7658S");
196 rb
->button_clear_queue();
199 result
= rb
->do_menu(&menu
, &selected
, NULL
, false);
204 rb
->memcpy ( (void*)&settings
.keymap
[0] , (void*)"2w90z" , 5);
208 rb
->memcpy ( (void*)&settings
.keymap
[0] , (void*)"qaopS" , 5);
212 rb
->memcpy ( (void*)&settings
.keymap
[0] , (void*)"7658S" , 5);
223 static void options_menu(void){
224 static const struct opt_items no_yes
[2] = {
232 MENUITEM_STRINGLIST(menu
, "Options", NULL
,
233 "Map Keys to kempston", "Display Speed",
234 "Invert Colors", "Frameskip", "Sound", "Volume",
235 "Predefined keymap", "Custom keymap");
237 static struct opt_items frameskip_items
[] = {
251 rb
->button_clear_queue();
254 result
= rb
->do_menu(&menu
, &selected
, NULL
, false);
259 new_setting
=settings
.kempston
;
260 rb
->set_option("Map Keys to kempston",&new_setting
,INT
,
262 if (new_setting
!= settings
.kempston
)
263 settings
.kempston
=new_setting
;
266 new_setting
= settings
.showfps
;
267 rb
->set_option("Display Speed",&new_setting
,INT
,
269 if (new_setting
!= settings
.showfps
)
270 settings
.showfps
=new_setting
;
273 new_setting
= settings
.invert_colors
;
274 rb
->set_option("Invert Colors",&new_setting
,INT
,
276 if (new_setting
!= settings
.invert_colors
)
277 settings
.invert_colors
=new_setting
;
278 rb
->splash(HZ
, "Restart to see effect");
281 new_setting
= settings
.frameskip
;
282 rb
->set_option("Frameskip",&new_setting
,INT
,
283 frameskip_items
, 10, NULL
);
284 if (new_setting
!= settings
.frameskip
)
285 settings
.frameskip
=new_setting
;
288 new_setting
= settings
.sound
;
289 rb
->set_option("Sound",&new_setting
,INT
,
291 if (new_setting
!= settings
.sound
)
292 settings
.sound
=new_setting
;
293 #if CONFIG_CODEC == SWCODEC && !defined SIMULATOR
298 new_setting
= 9 - settings
.volume
;
299 rb
->set_option("Volume",&new_setting
,INT
,
300 frameskip_items
, 10, NULL
);
301 new_setting
= 9 - new_setting
;
302 if (new_setting
!= settings
.volume
)
303 settings
.volume
=new_setting
;
319 static bool zxbox_menu(void)
321 #if CONFIG_CODEC == SWCODEC && !defined SIMULATOR
329 MENUITEM_STRINGLIST(menu
, "ZXBox Menu", NULL
,
330 "VKeyboard", "Play/Pause Tape",
331 "Save quick snapshot", "Load quick snapshot",
332 "Save Snapshot", "Toggle \"fast\" mode",
335 rb
->button_clear_queue();
338 result
= rb
->do_menu(&menu
, &selected
, NULL
, false);
343 if (!zx_kbd_input((char*) &c
))
355 save_quick_snapshot();
359 load_quick_snapshot();
366 sp_nosync
=!sp_nosync
;
382 #if defined(HAVE_ADJUSTABLE_CPU_FREQ)
387 for ( i
=0 ; i
<5 ; i
++){
388 if (settings
.keymap
[i
] == 'E')
389 intkeys
[i
]=SK_KP_Enter
;
390 else if ( settings
.keymap
[i
] == 'S' )
391 intkeys
[i
]=SK_KP_Space
;
393 intkeys
[i
] = (unsigned) settings
.keymap
[i
];
403 extern unsigned char loadim
[];
404 extern unsigned long loadim_size
;
408 static void update(void)
411 sp_border_update
>>= 1;
412 sp_imag_vert
= sp_imag_horiz
= 0;
415 static void run_singlemode(void)
418 int evenframe
, halfsec
, updateframe
;
424 while(!endofsingle
) {
432 /* Save the user settings if they have changed */
433 if (rb
->memcmp(&settings
,&old_settings
,sizeof(settings
))!=0) {
437 rb
->splash(0, "Saving settings...");
438 configfile_save(GLOBALCFG
, config
,sizeof(config
)/sizeof(*config
),SETTINGS_VERSION
);
445 start_time
= *rb
->current_tick
;
446 sound_on
= settings
.sound
;
447 showframe
= settings
.frameskip
+1;
450 halfsec
= !(sp_int_ctr
% 25);
451 evenframe
= !(sp_int_ctr
& 1);
453 if(screen_visible
) updateframe
= sp_nosync
? halfsec
:
454 !((sp_int_ctr
+SHOW_OFFS
) % showframe
);
455 else updateframe
= 0;
457 sp_flash_state
= ~sp_flash_state
;
464 spkb_process_events(evenframe
);
465 sp_updating
= updateframe
;
467 t
= sp_halfframe(t
, evenframe
? EVENHF
: ODDHF
);
468 if(SPNM(load_trapped
)) {
469 SPNM(load_trapped
) = 0;
475 if(!evenframe
) rec_tape();
477 if(!sound_avail
) spti_wait();
479 if(updateframe
) update();
480 play_sound(evenframe
);
482 else if(updateframe
) update();
488 void check_params(const void* parameter
)
490 spcf_read_conf_file(GLOBALCFG
);
491 spcf_read_command_line(parameter
);
494 static void init_load(const void *parameter
)
496 if(load_immed
) snsh_z80_load_intern(loadim
, loadim_size
);
498 check_params(parameter
);
499 if(spcf_init_snapshot
!= NULL
) {
501 rb
->splashf(HZ
, "Loading snapshot '%s'", spcf_init_snapshot
);
504 load_snapshot_file_type(spcf_init_snapshot
, spcf_init_snapshot_type
);
505 free_string(spcf_init_snapshot
);
508 if(spcf_init_tapefile
!= NULL
) {
509 /*sprintf(msgbuf, "Loading tape '%s'", spcf_init_tapefile);
511 start_play_file_type(spcf_init_tapefile
, 0, spcf_init_tapefile_type
);
512 if(!load_immed
) pause_play();
513 free_string(spcf_init_tapefile
);
517 void start_spectemu(const void *parameter
)
520 init_load(parameter
);