diff -r -c -N src/core.mak srcnew/core.mak *** src/core.mak Sun Jul 30 12:32:50 2006 --- srcnew/core.mak Sun Jul 30 03:06:02 2006 *************** *** 30,35 **** --- 30,36 ---- $(OBJ)/fileio.o \ $(OBJ)/harddisk.o \ $(OBJ)/hash.o \ + $(OBJ)/hiscore.o \ $(OBJ)/info.o \ $(OBJ)/input.o \ $(OBJ)/inptport.o \ diff -r -c -N src/drawgfx.c srcnew/drawgfx.c *** src/drawgfx.c Sun Jul 30 12:32:52 2006 --- srcnew/drawgfx.c Sun Jul 30 03:03:32 2006 *************** *** 3547,3553 **** plot_pixel(bitmap,x,y,pen); } ! static int crosshair_enable=1; void drawgfx_toggle_crosshair(void) { --- 3547,3553 ---- plot_pixel(bitmap,x,y,pen); } ! static int crosshair_enable=0; void drawgfx_toggle_crosshair(void) { diff -r -c -N src/hiscore.c srcnew/hiscore.c *** src/hiscore.c Thu Jan 1 00:00:00 1970 --- srcnew/hiscore.c Thu Mar 2 00:48:32 2006 *************** *** 0 **** --- 1,377 ---- + /*************************************************************************** + + hiscore.c + + Manages the hiscore system. + + Copyright (c) 1996-2006, Nicola Salmoria and the MAME Team. + Visit http://mamedev.org for licensing and usage restrictions. + + ***************************************************************************/ + + #include "driver.h" + #include "hiscore.h" + #include "cheat.h" + + #define MAX_CONFIG_LINE_SIZE 48 + + #define VERBOSE 0 + + static mame_timer *timer; + + #if VERBOSE + #define LOG(x) logerror x + #else + #define LOG(x) + #endif + + const char *db_filename = "hiscore.dat"; /* high score definition file */ + + + struct _memory_range + { + UINT32 cpu, addr, num_bytes, start_value, end_value; + struct _memory_range *next; + }; + typedef struct _memory_range memory_range; + + + static struct + { + int hiscores_have_been_loaded; + memory_range *mem_range; + } state; + + + static int is_highscore_enabled(void) + { + /* disable high score when record/playback is on */ + if (Machine->record_file != NULL || Machine->playback_file != NULL) + return FALSE; + + /* disable high score when cheats are used */ + if (he_did_cheat != 0) + return FALSE; + + return TRUE; + } + + + + /*****************************************************************************/ + + static void copy_to_memory (int cpu, int addr, const UINT8 *source, int num_bytes) + { + int i; + for (i=0; i='0' && c<='9') + { + digit = c-'0'; + } + else if (c>='a' && c<='f') + { + digit = 10+c-'a'; + } + else if (c>='A' && c<='F') + { + digit = 10+c-'A'; + } + else + { + /* not a hexadecimal digit */ + /* safety check for premature EOL */ + if (!c) string = NULL; + break; + } + result = result*16 + digit; + } + *pString = string; + } + return result; + } + + /* given a line in the hiscore.dat file, determine if it encodes a + memory range (or a game name). + For now we assume that CPU number is always a decimal digit, and + that no game name starts with a decimal digit. + */ + static int is_mem_range (const char *pBuf) + { + char c; + for(;;) + { + c = *pBuf++; + if (c == 0) return 0; /* premature EOL */ + if (c == ':') break; + } + c = *pBuf; /* character following first ':' */ + + return (c>='0' && c<='9') || + (c>='a' && c<='f') || + (c>='A' && c<='F'); + } + + /* matching_game_name is used to skip over lines until we find : */ + static int matching_game_name (const char *pBuf, const char *name) + { + while (*name) + { + if (*name++ != *pBuf++) return 0; + } + return (*pBuf == ':'); + } + + /*****************************************************************************/ + + /* safe_to_load checks the start and end values of each memory range */ + static int safe_to_load (void) + { + memory_range *mem_range = state.mem_range; + while (mem_range) + { + if (cpunum_read_byte (mem_range->cpu, mem_range->addr) != + mem_range->start_value) + { + return 0; + } + if (cpunum_read_byte (mem_range->cpu, mem_range->addr + mem_range->num_bytes - 1) != + mem_range->end_value) + { + return 0; + } + mem_range = mem_range->next; + } + return 1; + } + + /* hiscore_free disposes of the mem_range linked list */ + static void hiscore_free (void) + { + memory_range *mem_range = state.mem_range; + while (mem_range) + { + memory_range *next = mem_range->next; + free (mem_range); + mem_range = next; + } + state.mem_range = NULL; + } + + static void hiscore_load (void) + { + if (is_highscore_enabled()) + { + mame_file *f = mame_fopen (Machine->gamedrv->name, 0, FILETYPE_HIGHSCORE, 0); + state.hiscores_have_been_loaded = 1; + LOG(("hiscore_load\n")); + if (f) + { + memory_range *mem_range = state.mem_range; + LOG(("loading...\n")); + while (mem_range) + { + UINT8 *data = malloc (mem_range->num_bytes); + if (data) + { + /* this buffer will almost certainly be small + enough to be dynamically allocated, but let's + avoid memory trashing just in case + */ + mame_fread (f, data, mem_range->num_bytes); + copy_to_memory (mem_range->cpu, mem_range->addr, data, mem_range->num_bytes); + free (data); + } + mem_range = mem_range->next; + } + mame_fclose (f); + } + } + } + + static void hiscore_save (void) + { + if (is_highscore_enabled()) + { + mame_file *f = mame_fopen (Machine->gamedrv->name, 0, FILETYPE_HIGHSCORE, 1); + LOG(("hiscore_save\n")); + if (f) + { + memory_range *mem_range = state.mem_range; + LOG(("saving...\n")); + while (mem_range) + { + UINT8 *data = malloc (mem_range->num_bytes); + if (data) + { + /* this buffer will almost certainly be small + enough to be dynamically allocated, but let's + avoid memory trashing just in case + */ + copy_from_memory (mem_range->cpu, mem_range->addr, data, mem_range->num_bytes); + mame_fwrite(f, data, mem_range->num_bytes); + free (data); + } + mem_range = mem_range->next; + } + mame_fclose(f); + } + } + } + + + /* call hiscore_update periodically (i.e. once per frame) */ + static void hiscore_periodic (int param) + { + if (state.mem_range) + { + if (!state.hiscores_have_been_loaded) + { + if (safe_to_load()) + { + hiscore_load(); + timer_enable(timer, FALSE); + } + } + } + } + + + /* call hiscore_close when done playing game */ + void hiscore_close (void) + { + if (state.hiscores_have_been_loaded) hiscore_save(); + hiscore_free(); + } + + + /*****************************************************************************/ + /* public API */ + + /* call hiscore_open once after loading a game */ + void hiscore_init (const char *name) + { + memory_range *mem_range = state.mem_range; + mame_file *f; + + state.hiscores_have_been_loaded = 0; + + while (mem_range) + { + cpunum_write_byte( + mem_range->cpu, + mem_range->addr, + ~mem_range->start_value + ); + + cpunum_write_byte( + mem_range->cpu, + mem_range->addr + mem_range->num_bytes-1, + ~mem_range->end_value + ); + mem_range = mem_range->next; + } + + state.mem_range = NULL; + + LOG(("hiscore_open: '%s'\n", name)); + + f = mame_fopen (NULL, db_filename, FILETYPE_HIGHSCORE_DB, 0); + if (f) + { + char buffer[MAX_CONFIG_LINE_SIZE]; + enum { FIND_NAME, FIND_DATA, FETCH_DATA } mode; + mode = FIND_NAME; + + while (mame_fgets (buffer, MAX_CONFIG_LINE_SIZE, f)) + { + if (mode==FIND_NAME) + { + if (matching_game_name (buffer, name)) + { + mode = FIND_DATA; + LOG(("hs config found!\n")); + } + } + else if (is_mem_range (buffer)) + { + const char *pBuf = buffer; + memory_range *mem_range = malloc(sizeof(memory_range)); + if (mem_range) + { + mem_range->cpu = hexstr2num (&pBuf); + mem_range->addr = hexstr2num (&pBuf); + mem_range->num_bytes = hexstr2num (&pBuf); + mem_range->start_value = hexstr2num (&pBuf); + mem_range->end_value = hexstr2num (&pBuf); + + mem_range->next = NULL; + { + memory_range *last = state.mem_range; + while (last && last->next) last = last->next; + if (last == NULL) + { + state.mem_range = mem_range; + } + else + { + last->next = mem_range; + } + } + + mode = FETCH_DATA; + } + else + { + hiscore_free(); + break; + } + } + else + { + /* line is a game name */ + if (mode == FETCH_DATA) break; + } + } + mame_fclose (f); + } + + timer = timer_alloc(hiscore_periodic); + timer_adjust(timer, TIME_IN_HZ(60), 0, TIME_IN_HZ(60)); + + add_exit_callback(hiscore_close); + } diff -r -c -N src/hiscore.h srcnew/hiscore.h *** src/hiscore.h Thu Jan 1 00:00:00 1970 --- srcnew/hiscore.h Tue Feb 21 22:48:44 2006 *************** *** 0 **** --- 1,19 ---- + /*************************************************************************** + + hiscore.h + + Manages the hiscore system. + + Copyright (c) 1996-2006, Nicola Salmoria and the MAME Team. + Visit http://mamedev.org for licensing and usage restrictions. + + ***************************************************************************/ + + #pragma once + + #ifndef __HISCORE_H__ + #define __HISCORE_H__ + + void hiscore_init( const char *name ); + + #endif /* __HISCORE_H__ */ diff -r -c -N src/inptport.c srcnew/inptport.c *** src/inptport.c Sun Jul 30 12:32:50 2006 --- srcnew/inptport.c Sun Jul 30 03:04:02 2006 *************** *** 876,890 **** INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_ON_SCREEN_DISPLAY,"On Screen Display", SEQ_DEF_1(KEYCODE_TILDE) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_DEBUG_BREAK, "Break in Debugger", SEQ_DEF_1(KEYCODE_TILDE) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_CONFIGURE, "Config Menu", SEQ_DEF_1(KEYCODE_TAB) ) ! INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_PAUSE, "Pause", SEQ_DEF_1(KEYCODE_P) ) ! INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_RESET_MACHINE, "Reset Game", SEQ_DEF_2(KEYCODE_F3, KEYCODE_LSHIFT) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_SOFT_RESET, "Soft Reset", SEQ_DEF_3(KEYCODE_F3, CODE_NOT, KEYCODE_LSHIFT) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_SHOW_GFX, "Show Gfx", SEQ_DEF_1(KEYCODE_F4) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_FRAMESKIP_DEC, "Frameskip Dec", SEQ_DEF_1(KEYCODE_F8) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_FRAMESKIP_INC, "Frameskip Inc", SEQ_DEF_1(KEYCODE_F9) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_THROTTLE, "Throttle", SEQ_DEF_1(KEYCODE_F10) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_SHOW_FPS, "Show FPS", SEQ_DEF_5(KEYCODE_F11, CODE_NOT, KEYCODE_LCONTROL, CODE_NOT, KEYCODE_LSHIFT) ) ! INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_SNAPSHOT, "Save Snapshot", SEQ_DEF_3(KEYCODE_F12, CODE_NOT, KEYCODE_LSHIFT) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_RECORD_MOVIE, "Record Movie", SEQ_DEF_2(KEYCODE_F12, KEYCODE_LSHIFT) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_TOGGLE_CHEAT, "Toggle Cheat", SEQ_DEF_1(KEYCODE_F6) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_UP, "UI Up", SEQ_DEF_3(KEYCODE_UP, CODE_OR, JOYCODE_1_UP) ) --- 876,890 ---- INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_ON_SCREEN_DISPLAY,"On Screen Display", SEQ_DEF_1(KEYCODE_TILDE) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_DEBUG_BREAK, "Break in Debugger", SEQ_DEF_1(KEYCODE_TILDE) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_CONFIGURE, "Config Menu", SEQ_DEF_1(KEYCODE_TAB) ) ! INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_PAUSE, "Pause", SEQ_DEF_3(KEYCODE_P, CODE_OR, KEYCODE_TAB) ) ! INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_RESET_MACHINE, "Reset Game", SEQ_DEF_1(KEYCODE_F3) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_SOFT_RESET, "Soft Reset", SEQ_DEF_3(KEYCODE_F3, CODE_NOT, KEYCODE_LSHIFT) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_SHOW_GFX, "Show Gfx", SEQ_DEF_1(KEYCODE_F4) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_FRAMESKIP_DEC, "Frameskip Dec", SEQ_DEF_1(KEYCODE_F8) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_FRAMESKIP_INC, "Frameskip Inc", SEQ_DEF_1(KEYCODE_F9) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_THROTTLE, "Throttle", SEQ_DEF_1(KEYCODE_F10) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_SHOW_FPS, "Show FPS", SEQ_DEF_5(KEYCODE_F11, CODE_NOT, KEYCODE_LCONTROL, CODE_NOT, KEYCODE_LSHIFT) ) ! INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_SNAPSHOT, "Save Snapshot", SEQ_DEF_1(KEYCODE_F12) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_RECORD_MOVIE, "Record Movie", SEQ_DEF_2(KEYCODE_F12, KEYCODE_LSHIFT) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_TOGGLE_CHEAT, "Toggle Cheat", SEQ_DEF_1(KEYCODE_F6) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_UP, "UI Up", SEQ_DEF_3(KEYCODE_UP, CODE_OR, JOYCODE_1_UP) ) *************** *** 895,901 **** INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_END, "UI End", SEQ_DEF_1(KEYCODE_END) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_PAGE_UP, "UI Page Up", SEQ_DEF_1(KEYCODE_PGUP) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_PAGE_DOWN, "UI Page Down", SEQ_DEF_1(KEYCODE_PGDN) ) ! INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_SELECT, "UI Select", SEQ_DEF_3(KEYCODE_ENTER, CODE_OR, JOYCODE_1_BUTTON1) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_CANCEL, "UI Cancel", SEQ_DEF_1(KEYCODE_ESC) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_CLEAR, "UI Clear", SEQ_DEF_1(KEYCODE_DEL) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_ZOOM_IN, "UI Zoom In", SEQ_DEF_1(KEYCODE_EQUALS) ) --- 895,901 ---- INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_END, "UI End", SEQ_DEF_1(KEYCODE_END) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_PAGE_UP, "UI Page Up", SEQ_DEF_1(KEYCODE_PGUP) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_PAGE_DOWN, "UI Page Down", SEQ_DEF_1(KEYCODE_PGDN) ) ! INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_SELECT, "UI Select", SEQ_DEF_3(KEYCODE_1, CODE_OR, JOYCODE_1_BUTTON1) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_CANCEL, "UI Cancel", SEQ_DEF_1(KEYCODE_ESC) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_CLEAR, "UI Clear", SEQ_DEF_1(KEYCODE_DEL) ) INPUT_PORT_DIGITAL_DEF( 0, IPG_UI, UI_ZOOM_IN, "UI Zoom In", SEQ_DEF_1(KEYCODE_EQUALS) ) diff -r -c -N src/mame.c srcnew/mame.c *** src/mame.c Sun Jul 30 12:32:50 2006 --- srcnew/mame.c Sun Jul 30 03:03:02 2006 *************** *** 77,82 **** --- 77,83 ---- #include "driver.h" #include "config.h" #include "cheat.h" + #include "hiscore.h" #include "debugger.h" #include "profiler.h" #include "render.h" *************** *** 297,306 **** /* load the configuration settings and NVRAM */ settingsloaded = config_load_settings(); nvram_load(); /* display the startup screens */ ! ui_display_startup_screens(!settingsloaded && !options.skip_disclaimer, !options.skip_warnings, !options.skip_gameinfo); /* ensure we don't show the opening screens on a reset */ options.skip_disclaimer = options.skip_warnings = options.skip_gameinfo = TRUE; --- 298,308 ---- /* load the configuration settings and NVRAM */ settingsloaded = config_load_settings(); + settingsloaded = 1; nvram_load(); /* display the startup screens */ ! ui_display_startup_screens(!1 && !1, !1, !1); /* ensure we don't show the opening screens on a reset */ options.skip_disclaimer = options.skip_warnings = options.skip_gameinfo = TRUE; *************** *** 955,960 **** --- 957,963 ---- fatalerror("devices_init failed"); #endif + hiscore_init(Machine->gamedrv->name); /* start the save/load system */ saveload_init(); diff -r -c -N src/profiler.c srcnew/profiler.c *** src/profiler.c Sun Jul 30 12:32:50 2006 --- srcnew/profiler.c Sun Jul 30 03:06:30 2006 *************** *** 137,142 **** --- 137,143 ---- "Sound ", "Mixer ", "Callbck", + "Hiscore", "Input ", "Movie ", "Logerr ", diff -r -c -N src/profiler.h srcnew/profiler.h *** src/profiler.h Sun Jul 30 12:32:50 2006 --- srcnew/profiler.h Sun Jul 30 03:06:58 2006 *************** *** 39,44 **** --- 39,45 ---- PROFILER_SOUND, PROFILER_MIXER, PROFILER_TIMER_CALLBACK, + PROFILER_HISCORE, PROFILER_INPUT, /* input.c and inptport.c */ PROFILER_MOVIE_REC, /* movie recording */ PROFILER_LOGERROR, /* logerror */ diff -r -c -N src/windows/config.c srcnew/windows/config.c *** src/windows/config.c Sun Jul 30 12:32:46 2006 --- srcnew/windows/config.c Sun Jul 30 03:04:54 2006 *************** *** 149,154 **** --- 149,155 ---- { "nvram_directory", "nvram", 0, "directory to save nvram contents" }, { "memcard_directory", "memcard", 0, "directory to save memory card contents" }, { "input_directory", "inp", 0, "directory to save input device logs" }, + { "hiscore_directory", "hi", 0, "directory to save hiscores" }, { "state_directory", "sta", 0, "directory to save states" }, { "artpath;artwork_directory","artwork", 0, "path to artwork files" }, { "snapshot_directory", "snap", 0, "directory to save screenshots" }, diff -r -c -N src/windows/drawd3d.c srcnew/windows/drawd3d.c *** src/windows/drawd3d.c Sun Jul 30 12:32:46 2006 --- srcnew/windows/drawd3d.c Sun Jul 30 12:19:22 2006 *************** *** 47,53 **** // CONSTANTS //============================================================ ! #define ENABLE_BORDER_PIX (0) #define VERTEX_FORMAT (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1) #define VERTEX_BUFFER_SIZE (2048*4) --- 47,53 ---- // CONSTANTS //============================================================ ! #define ENABLE_BORDER_PIX (1) #define VERTEX_FORMAT (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1) #define VERTEX_BUFFER_SIZE (2048*4) diff -r -c -N src/windows/fileio.c srcnew/windows/fileio.c *** src/windows/fileio.c Sun Jul 30 12:32:46 2006 --- srcnew/windows/fileio.c Sun Jul 30 03:05:24 2006 *************** *** 98,103 **** --- 98,104 ---- { FILETYPE_SAMPLE, "samplepath" }, { FILETYPE_ARTWORK, "artpath" }, { FILETYPE_NVRAM, "nvram_directory" }, + { FILETYPE_HIGHSCORE, "hiscore_directory" }, { FILETYPE_CONFIG, "cfg_directory" }, { FILETYPE_INPUTLOG, "input_directory" }, { FILETYPE_STATE, "state_directory" },