bugfixes, refactoring

git-svn-id: file:///home/notaz/opt/svn/PicoDrive@394 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2008-03-25 19:23:07 +00:00
parent 1ca2ea4f60
commit bdec53c90b
13 changed files with 139 additions and 178 deletions

View file

@ -24,7 +24,7 @@ static const int *cfg_opt_counts[] = { &opt_entry_count, &opt2_entry_count, &cdo
#define NL "\n"
static void mystrip(char *str)
static char *mystrip(char *str)
{
int i, len;
@ -32,10 +32,13 @@ static void mystrip(char *str)
for (i = 0; i < len; i++)
if (str[i] != ' ') break;
if (i > 0) memmove(str, str + i, len - i + 1);
len = strlen(str);
for (i = len - 1; i >= 0; i--)
if (str[i] != ' ') break;
str[i+1] = 0;
return str;
}
@ -167,22 +170,18 @@ static void keys_write(FILE *fn, const char *bind_str, const int binds[32],
#endif
for (i = 0; i < sizeof(me_ctrl_actions) / sizeof(me_ctrl_actions[0]); i++) {
if (me_ctrl_actions[i].mask & binds[t]) {
sprintf(act, "player%i ", ((binds[t]>>16)&1)+1);
strncpy(act + 8, me_ctrl_actions[i].name, 31);
break;
strncpy(act, me_ctrl_actions[i].name, 31);
fprintf(fn, "%s %s = player%i %s" NL, bind_str, names[t],
((binds[t]>>16)&1)+1, mystrip(act));
}
}
if (act[0] == 0)
{
for (i = 0; emuctrl_actions[i].name != NULL; i++)
if (emuctrl_actions[i].mask & binds[t]) {
strncpy(act, emuctrl_actions[i].name, 31);
break;
}
}
mystrip(act);
fprintf(fn, "%s %s = %s" NL, bind_str, names[t], act);
for (i = 0; emuctrl_actions[i].name != NULL; i++) {
if (emuctrl_actions[i].mask & binds[t]) {
strncpy(act, emuctrl_actions[i].name, 31);
fprintf(fn, "%s %s = %s" NL, bind_str, names[t], mystrip(act));
}
}
}
}
@ -566,9 +565,11 @@ static int custom_read(menu_entry *me, const char *var, const char *val)
}
static unsigned int keys_encountered = 0;
static void keys_parse(const char *var, const char *val, int binds[32], const char *names[32])
{
int t, i, keys_encountered = 0;
int t, i;
unsigned int player;
for (t = 0; t < 32; t++)
@ -580,7 +581,7 @@ static void keys_parse(const char *var, const char *val, int binds[32], const ch
return;
}
if (!(keys_encountered & (1<<t))) {
if (binds == currentConfig.KeyBinds && !(keys_encountered & (1<<t))) { // hack
binds[t] = 0;
keys_encountered |= 1<<t;
}
@ -607,7 +608,6 @@ static void keys_parse(const char *var, const char *val, int binds[32], const ch
fail:
lprintf("unhandled action \"%s\"\n", val);
return;
}
@ -698,6 +698,8 @@ int config_readsect(const char *fname, const char *section)
}
}
keys_encountered = 0;
while (!feof(f))
{
tmp = fgets(line, sizeof(line), f);

View file

@ -41,6 +41,7 @@ char noticeMsg[64];
int state_slot = 0;
int config_slot = 0, config_slot_current = 0;
char lastRomFile[512];
int kb_combo_keys = 0, kb_combo_acts = 0; // keys and actions which need button combos
unsigned char *movie_data = NULL;
static int movie_size = 0;
@ -232,18 +233,20 @@ static int extract_text(char *dest, unsigned char *src, int len, int swab)
char *emu_makeRomId(void)
{
static char id_string[3+0x11+0x11+0x30+16];
int pos;
int pos, swab = 1;
if (PicoMCD & 1)
strcpy(id_string, "CD|");
if (PicoMCD & 1) {
strcpy(id_string, "CD|");
swab = 0;
}
else strcpy(id_string, "MD|");
pos = 3;
pos += extract_text(id_string + pos, id_header + 0x80, 0x0e, 1); // serial
pos += extract_text(id_string + pos, id_header + 0x80, 0x0e, swab); // serial
id_string[pos] = '|'; pos++;
pos += extract_text(id_string + pos, id_header + 0xf0, 0x03, 1); // region
pos += extract_text(id_string + pos, id_header + 0xf0, 0x03, swab); // region
id_string[pos] = '|'; pos++;
pos += extract_text(id_string + pos, id_header + 0x50, 0x30, 1); // overseas name
pos += extract_text(id_string + pos, id_header + 0x50, 0x30, swab); // overseas name
id_string[pos] = 0;
return id_string;
@ -328,6 +331,7 @@ int emu_ReloadRom(void)
cd_state = emu_cdCheck(&cd_region);
if (cd_state > 0)
{
PicoMCD |= 1;
// valid CD image, check for BIOS..
// we need to have config loaded at this point
@ -341,10 +345,10 @@ int emu_ReloadRom(void)
}
if (!emu_findBios(cd_region, &used_rom_name)) {
// bios_help() ?
PicoMCD &= ~1;
return 0;
}
PicoMCD |= 1;
get_ext(used_rom_name, ext);
}
else
@ -651,6 +655,47 @@ void emu_textOut16(int x, int y, const char *text)
}
}
void emu_findKeyBindCombos(void)
{
int act, u;
// find out which keys and actions are combos
kb_combo_keys = kb_combo_acts = 0;
for (act = 0; act < 32; act++)
{
int keyc = 0, keyc2 = 0;
if (act == 16 || act == 17) continue; // player2 flag
if (act > 17)
{
for (u = 0; u < 32; u++)
if (currentConfig.KeyBinds[u] & (1 << act)) keyc++;
}
else
{
for (u = 0; u < 32; u++)
if ((currentConfig.KeyBinds[u] & 0x30000) == 0 && // pl. 1
(currentConfig.KeyBinds[u] & (1 << act))) keyc++;
for (u = 0; u < 32; u++)
if ((currentConfig.KeyBinds[u] & 0x30000) == 1 && // pl. 2
(currentConfig.KeyBinds[u] & (1 << act))) keyc2++;
if (keyc2 > keyc) keyc = keyc2;
}
if (keyc > 1)
{
// loop again and mark those keys and actions as combo
for (u = 0; u < 32; u++)
{
if (currentConfig.KeyBinds[u] & (1 << act)) {
kb_combo_keys |= 1 << u;
kb_combo_acts |= 1 << act;
}
}
}
}
// printf("combo keys/acts: %08x %08x\n", kb_combo_keys, kb_combo_acts);
}
void emu_updateMovie(void)
{
@ -876,3 +921,4 @@ int emu_SaveLoadGame(int load, int sram)
return ret;
}
}

View file

@ -34,6 +34,7 @@ extern int state_slot;
extern int config_slot, config_slot_current;
extern unsigned char *movie_data;
extern char lastRomFile[512];
extern int kb_combo_keys, kb_combo_acts; // keys and actions which need button combos
int emu_ReloadRom(void);
@ -49,6 +50,7 @@ int emu_findBios(int region, char **bios_file);
void emu_textOut8 (int x, int y, const char *text);
void emu_textOut16(int x, int y, const char *text);
char *emu_makeRomId(void);
void emu_findKeyBindCombos(void);
extern const char *keyNames[];
void emu_prepareDefaultConfig(void);