From 74a215746365448d0a20b26b83508af425a89b75 Mon Sep 17 00:00:00 2001 From: Maciej Gebicz Date: Thu, 10 Jul 2025 14:37:30 +0200 Subject: [PATCH 1/3] zephyrdoom: Clean up build and configuration files The commit contains the following changes: - Fix of comments structure; - Unification of whitespaces compared to other similar files in the repository; - Removal of redundant/deprecated comments; --- zephyrdoom/CMakeLists.txt | 187 +++++++++++++++++++------------------- zephyrdoom/Kconfig | 5 - 2 files changed, 93 insertions(+), 99 deletions(-) diff --git a/zephyrdoom/CMakeLists.txt b/zephyrdoom/CMakeLists.txt index d932c47..d98356f 100644 --- a/zephyrdoom/CMakeLists.txt +++ b/zephyrdoom/CMakeLists.txt @@ -6,100 +6,99 @@ target_include_directories(app PRIVATE src/) target_include_directories(app PRIVATE src/config) target_sources(app PRIVATE - src/main.c - src/n_qspi.c - src/n_fs.c - src/n_mem.c - src/n_buttons.c - src/n_display.c - src/n_rjoy.c - src/n_i2s.c - src/n_i2s_sound.c - src/deh_main.c - src/deh_str.c - src/doom/deh_misc.h - src/doom/deh_misc.c - src/d_event.c - src/d_iwad.c - src/d_mode.c - src/d_loop.c - src/i_timer.c - src/i_system.c - src/i_input.c - src/i_video.c - src/i_joystick.c - src/i_sound.c - src/m_argv.c - src/m_bbox.c - src/m_cheat.c - src/m_config.c - src/m_fixed.c - src/m_misc.c - src/m_controls.c - src/net_client.c - src/net_server.c - src/tables.c - src/v_diskicon.c - src/v_video.c - src/w_checksum.c - src/w_file.c - src/w_file_fatfs.c - src/w_main.c - src/w_wad.c - src/z_native.c - src/bluetooth_control.c - src/doom/am_map.c - src/doom/doomstat.c - src/doom/d_main.c - src/doom/d_net.c - src/doom/d_items.c - src/doom/dstrings.c - src/doom/f_wipe.c - src/doom/f_finale.c - src/doom/g_game.c - src/doom/hu_lib.c - src/doom/hu_stuff.c - src/doom/info.c - src/doom/m_menu.c - src/doom/m_random.c - src/doom/p_doors.c - src/doom/p_ceilng.c - src/doom/p_enemy.c - src/doom/p_floor.c - src/doom/p_lights.c - src/doom/p_plats.c - src/doom/p_telept.c - src/doom/p_setup.c - src/doom/p_sight.c - src/doom/p_saveg.c - src/doom/p_map.c - src/doom/p_maputl.c - src/doom/p_mobj.c - src/doom/p_inter.c - src/doom/p_tick.c - src/doom/p_spec.c - src/doom/p_switch.c - src/doom/p_pspr.c - src/doom/p_user.c - src/doom/r_bsp.c - src/doom/r_main.c - src/doom/r_data.c - src/doom/r_draw.c - src/doom/r_plane.c - src/doom/r_segs.c - src/doom/r_sky.c - src/doom/r_things.c - src/doom/s_sound.c - src/doom/st_lib.c - src/doom/st_stuff.c - src/doom/statdump.c - src/doom/sounds.c - src/doom/wi_stuff.c - ) + src/main.c + src/n_qspi.c + src/n_fs.c + src/n_mem.c + src/n_buttons.c + src/n_display.c + src/n_rjoy.c + src/n_i2s.c + src/n_i2s_sound.c + src/deh_main.c + src/deh_str.c + src/doom/deh_misc.h + src/doom/deh_misc.c + src/d_event.c + src/d_iwad.c + src/d_mode.c + src/d_loop.c + src/i_timer.c + src/i_system.c + src/i_input.c + src/i_video.c + src/i_joystick.c + src/i_sound.c + src/m_argv.c + src/m_bbox.c + src/m_cheat.c + src/m_config.c + src/m_fixed.c + src/m_misc.c + src/m_controls.c + src/net_client.c + src/net_server.c + src/tables.c + src/v_diskicon.c + src/v_video.c + src/w_checksum.c + src/w_file.c + src/w_file_fatfs.c + src/w_main.c + src/w_wad.c + src/z_native.c + src/bluetooth_control.c + src/doom/am_map.c + src/doom/doomstat.c + src/doom/d_main.c + src/doom/d_net.c + src/doom/d_items.c + src/doom/dstrings.c + src/doom/f_wipe.c + src/doom/f_finale.c + src/doom/g_game.c + src/doom/hu_lib.c + src/doom/hu_stuff.c + src/doom/info.c + src/doom/m_menu.c + src/doom/m_random.c + src/doom/p_doors.c + src/doom/p_ceilng.c + src/doom/p_enemy.c + src/doom/p_floor.c + src/doom/p_lights.c + src/doom/p_plats.c + src/doom/p_telept.c + src/doom/p_setup.c + src/doom/p_sight.c + src/doom/p_saveg.c + src/doom/p_map.c + src/doom/p_maputl.c + src/doom/p_mobj.c + src/doom/p_inter.c + src/doom/p_tick.c + src/doom/p_spec.c + src/doom/p_switch.c + src/doom/p_pspr.c + src/doom/p_user.c + src/doom/r_bsp.c + src/doom/r_main.c + src/doom/r_data.c + src/doom/r_draw.c + src/doom/r_plane.c + src/doom/r_segs.c + src/doom/r_sky.c + src/doom/r_things.c + src/doom/s_sound.c + src/doom/st_lib.c + src/doom/st_stuff.c + src/doom/statdump.c + src/doom/sounds.c + src/doom/wi_stuff.c + ) - -# set C version +# Set C version set(CMAKE_C_STANDARD 89) -# set oldest CPP version -set(CMAKE_CXX_STANDARD 98) +# Set the oldest CPP version +set(CMAKE_CXX_STANDARD 98) diff --git a/zephyrdoom/Kconfig b/zephyrdoom/Kconfig index 622300e..28b4ec1 100644 --- a/zephyrdoom/Kconfig +++ b/zephyrdoom/Kconfig @@ -1,12 +1,7 @@ mainmenu "Zephyr Kernel Configuration" -# source "${ZEPHYR_BASE}/share/sysbuild/Kconfig" source "Kconfig.zephyr" module = DOOM_MAIN module-str = doom_main source "subsys/logging/Kconfig.template.log_config" - -# Central UART seems to work even without this -# config NRF_DEFAULT_BLUETOOTH -# default y From c31c5bd4ae4b432a92c7a3a0e2d860ff2e5d857c Mon Sep 17 00:00:00 2001 From: Maciej Gebicz Date: Mon, 14 Jul 2025 12:01:42 +0200 Subject: [PATCH 2/3] zephyrdoom, config: Clean implementation sources The commit contains the following changes: - Clean up of redundant/deprecated comments; - Clean up of redundant whitespaces and new lines; - Fix of spacing within lines; - Unify C comments to C89 and C98 code structure (/**/ instead of //); - Fix too long lines; - Unify comments among files; The source code structure has been unified using default auto formatter of C code which is up to date with recent standards. In Visual Studio code if not enabled by default, the key combination is Shift + Alt + F Some exceptions have been applied for better readability due to Doxygen and ifndef/ifdef directives available in the code. --- zephyrdoom/src/config/board_config.h | 39 +++++------ zephyrdoom/src/config/config.h | 24 +++---- zephyrdoom/src/config/doom_config.h | 24 +++---- zephyrdoom/src/config/nrf_error.h | 101 ++++++++++----------------- zephyrdoom/src/config/nrfx_config.h | 99 ++++++++++++++------------ 5 files changed, 134 insertions(+), 153 deletions(-) diff --git a/zephyrdoom/src/config/board_config.h b/zephyrdoom/src/config/board_config.h index 49f6187..15d97f1 100644 --- a/zephyrdoom/src/config/board_config.h +++ b/zephyrdoom/src/config/board_config.h @@ -1,10 +1,9 @@ - #include "hal/nrf_gpio.h" -#define NRF_UARTE NRF_UARTE1_S +#define NRF_UARTE NRF_UARTE1_S -// Display -#define NRF_DISPLAY_SPIM NRF_SPIM4_S +/* Display */ +#define NRF_DISPLAY_SPIM NRF_SPIM4_S #define NRF_DISPLAY_GPIOTE NRF_GPIOTE0_S #define NRF_DOOM_TIMER NRF_TIMER0_S @@ -29,32 +28,32 @@ #define QSPI_IO2_PIN 15 #define QSPI_IO3_PIN 16 +#define SDC_SCK_PIN NRF_GPIO_PIN_MAP(1, 14) +#define SDC_MOSI_PIN NRF_GPIO_PIN_MAP(1, 13) +#define SDC_MISO_PIN NRF_GPIO_PIN_MAP(1, 15) +#define SDC_CS_PIN NRF_GPIO_PIN_MAP(1, 12) -#define SDC_SCK_PIN NRF_GPIO_PIN_MAP(1, 14) -#define SDC_MOSI_PIN NRF_GPIO_PIN_MAP(1, 13) -#define SDC_MISO_PIN NRF_GPIO_PIN_MAP(1, 15) -#define SDC_CS_PIN NRF_GPIO_PIN_MAP(1, 12) - -#define DISPLAY_PIN_SCK NRF_GPIO_PIN_MAP(0, 6) +#define DISPLAY_PIN_SCK NRF_GPIO_PIN_MAP(0, 6) #define DISPLAY_PIN_MISO NRF_GPIO_PIN_MAP(0, 5) #define DISPLAY_PIN_MOSI NRF_GPIO_PIN_MAP(0, 25) #define DISPLAY_PIN_CS_N NRF_GPIO_PIN_MAP(0, 7) #define DISPLAY_PIN_PD_N 26 -// #define MAX98357 #define PCM5102 #ifdef PCM5102 -#define I2S_PIN_SCK NRF_GPIO_PIN_MAP(1, 9) -#define I2S_PIN_BCK NRF_GPIO_PIN_MAP(1, 8) -#define I2S_PIN_DIN NRF_GPIO_PIN_MAP(1, 7) -#define I2S_PIN_LRCK NRF_GPIO_PIN_MAP(1, 6) +#define I2S_PIN_SCK NRF_GPIO_PIN_MAP(1, 9) +#define I2S_PIN_BCK NRF_GPIO_PIN_MAP(1, 8) +#define I2S_PIN_DIN NRF_GPIO_PIN_MAP(1, 7) +#define I2S_PIN_LRCK NRF_GPIO_PIN_MAP(1, 6) #endif +/* #define MAX98357 */ + #ifdef MAX98357 -#define I2S_PIN_SD NRF_GPIO_PIN_MAP(0, 10); -#define I2S_PIN_GAIN NRF_GPIO_PIN_MAP(0, 9); -#define I2S_PIN_DIN NRF_GPIO_PIN_MAP(1, 0); -#define I2S_PIN_BCK NRF_GPIO_PIN_MAP(0, 24); // BCLK -#define I2S_PIN_LRCK NRF_GPIO_PIN_MAP(0, 22); // LRC +#define I2S_PIN_SD NRF_GPIO_PIN_MAP(0, 10); +#define I2S_PIN_GAIN NRF_GPIO_PIN_MAP(0, 9); +#define I2S_PIN_DIN NRF_GPIO_PIN_MAP(1, 0); +#define I2S_PIN_BCK NRF_GPIO_PIN_MAP(0, 24); /* BCLK */ +#define I2S_PIN_LRCK NRF_GPIO_PIN_MAP(0, 22); /* LRC */ #endif diff --git a/zephyrdoom/src/config/config.h b/zephyrdoom/src/config/config.h index e643836..894347d 100644 --- a/zephyrdoom/src/config/config.h +++ b/zephyrdoom/src/config/config.h @@ -1,35 +1,35 @@ - /* Name of package */ #define PACKAGE "chocolate-doom" -/* Define to the address where bug reports for this package should be sent. */ +/* Define to the address where bug reports for this package should be sent */ #define PACKAGE_BUGREPORT "audun.wilhelmsen@nordicsemi.no" -/* Define to the full name of this package. */ +/* Define to the full name of this package */ #define PACKAGE_NAME "NRF Doom" -/* Define to the full name and version of this package. */ +/* Define to the full name and version of this package */ #define PACKAGE_STRING "NRF Doom 0.1.0" -/* Define to the one symbol short name of this package. */ +/* Define to the one symbol short name of this package */ #define PACKAGE_TARNAME "nrf-doom" -/* Define to the version of this package. */ +/* Define to the version of this package */ #define PACKAGE_VERSION "0.1.0" /* Change this when you create your awesome forked version */ #define PROGRAM_PREFIX "nrf-" -/* Define to 1 if you have the ANSI C header files. */ +/* Define to 1 if you have the ANSI C header files */ #define STDC_HEADERS 1 /* Version number of package */ #define PACKAGE_VERSION "0.1.0" -/* Define to 1 if your processor stores words with the most significant byte - first (like Motorola and SPARC, unlike Intel and VAX). */ -/* #undef WORDS_BIGENDIAN */ +/* + * Define to 1 if your processor stores words with the most significant byte + * first (like Motorola and SPARC, unlike Intel and VAX) + */ +/* #define WORDS_BIGENDIAN 1 */ -// Game-Loop debug messages +/* Game-Loop debug messages */ #define N_ldbg(...) -// #define N_ldbg printf diff --git a/zephyrdoom/src/config/doom_config.h b/zephyrdoom/src/config/doom_config.h index 9b5017f..884d79c 100644 --- a/zephyrdoom/src/config/doom_config.h +++ b/zephyrdoom/src/config/doom_config.h @@ -1,35 +1,35 @@ - /* Name of package */ #define DOOM_PACKAGE "chocolate-doom" -/* Define to the address where bug reports for this package should be sent. */ +/* Define to the address where bug reports for this package should be sent */ #define DOOM_PACKAGE_BUGREPORT "audun.wilhelmsen@nordicsemi.no" -/* Define to the full name of this package. */ +/* Define to the full name of this package */ #define DOOM_PACKAGE_NAME "NRF Doom" -/* Define to the full name and version of this package. */ +/* Define to the full name and version of this package */ #define DOOM_PACKAGE_STRING "NRF Doom 0.1.0" -/* Define to the one symbol short name of this package. */ +/* Define to the one symbol short name of this package */ #define DOOM_PACKAGE_TARNAME "nrf-doom" -/* Define to the version of this package. */ +/* Define to the version of this package */ #define DOOM_PACKAGE_VERSION "0.1.0" /* Change this when you create your awesome forked version */ #define DOOM_PROGRAM_PREFIX "nrf-" -/* Define to 1 if you have the ANSI C header files. */ +/* Define to 1 if you have the ANSI C header files */ #define DOOM_STDC_HEADERS 1 /* Version number of package */ #define DOOM_PACKAGE_VERSION "0.1.0" -/* Define to 1 if your processor stores words with the most significant byte - first (like Motorola and SPARC, unlike Intel and VAX). */ -/* #undef WORDS_BIGENDIAN */ +/* + * Define to 1 if your processor stores words with the most significant byte + * first (like Motorola and SPARC, unlike Intel and VAX) + */ +/* #define WORDS_BIGENDIAN 1 */ -// Game-Loop debug messages +/* Game-Loop debug messages */ #define N_ldbg(...) -// #define N_ldbg printf diff --git a/zephyrdoom/src/config/nrf_error.h b/zephyrdoom/src/config/nrf_error.h index 4be023e..fb20226 100644 --- a/zephyrdoom/src/config/nrf_error.h +++ b/zephyrdoom/src/config/nrf_error.h @@ -38,84 +38,53 @@ */ /** - @defgroup nrf_error SoftDevice Global Error Codes - @{ - - @brief Global Error definitions -*/ + * @defgroup nrf_error SoftDevice Global Error Codes + * @{ + * @brief Global Error definitions + */ /* Header guard */ #ifndef NRF_ERROR_H__ #define NRF_ERROR_H__ #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -/** @defgroup NRF_ERRORS_BASE Error Codes Base number definitions - * @{ */ - -// #define NRF_ERROR_BASE_NUM (0x0) ///< Global error base -#define NRF_ERROR_SDM_BASE_NUM (0x1000) ///< SDM error base -#define NRF_ERROR_SOC_BASE_NUM (0x2000) ///< SoC error base -#define NRF_ERROR_STK_BASE_NUM (0x3000) ///< STK error base +/** + * @defgroup NRF_ERRORS_BASE Error Codes Base number definitions + * @{ + */ +#define NRF_ERROR_SDM_BASE_NUM (0x1000) ///< SDM error base +#define NRF_ERROR_SOC_BASE_NUM (0x2000) ///< SoC error base +#define NRF_ERROR_STK_BASE_NUM (0x3000) ///< STK error base /** @} */ -// TODO use NRFX_* versions from C:\ncs\v2.4.0\modules\hal\nordic\nrfx\drivers\nrfx_errors.h -enum nrfx_err_t { - NRF_SUCCESS = (0x0BAD0000 + 0), - NRF_ERROR_INTERNAL = (0x0BAD0000 + 1), - NRF_ERROR_NO_MEM = (0x0BAD0000 + 2), - NRF_ERROR_NOT_SUPPORTED = (0x0BAD0000 + 3), - NRF_ERROR_INVALID_PARAM = (0x0BAD0000 + 4), - NRF_ERROR_INVALID_STATE = (0x0BAD0000 + 5), - NRF_ERROR_INVALID_LENGTH = (0x0BAD0000 + 6), - NRF_ERROR_TIMEOUT = (0x0BAD0000 + 7), - NRF_ERROR_FORBIDDEN = (0x0BAD0000 + 8), - NRF_ERROR_NULL = (0x0BAD0000 + 9), - NRF_ERROR_INVALID_ADDR = (0x0BAD0000 + 10), - NRF_ERROR_BUSY = (0x0BAD0000 + 11), - NRF_ERROR_ALREADY_INITIALIZED = (0x0BAD0000 + 12), - NRF_ERROR_DRV_TWI_ERR_OVERRUN = ((0x0BAD0000 + 0x10000) + 0), - NRF_ERROR_DRV_TWI_ERR_ANACK = ((0x0BAD0000 + 0x10000) + 1), - NRF_ERROR_DRV_TWI_ERR_DNACK = ((0x0BAD0000 + 0x10000) + 2) -}; - -// #define NRF_SUCCESS (NRF_ERROR_BASE_NUM + 0) ///< Successful command -// #define NRF_ERROR_SVC_HANDLER_MISSING \ -// (NRF_ERROR_BASE_NUM + 1) ///< SVC handler is missing -// #define NRF_ERROR_SOFTDEVICE_NOT_ENABLED \ -// (NRF_ERROR_BASE_NUM + 2) ///< SoftDevice has not been enabled -// #define NRF_ERROR_INTERNAL (NRF_ERROR_BASE_NUM + 3) ///< Internal Error -// #define NRF_ERROR_NO_MEM (NRF_ERROR_BASE_NUM + 4) ///< No Memory for -// operation #define NRF_ERROR_NOT_FOUND (NRF_ERROR_BASE_NUM + 5) ///< Not -// found #define NRF_ERROR_NOT_SUPPORTED (NRF_ERROR_BASE_NUM + 6) ///< Not -// supported #define NRF_ERROR_INVALID_PARAM (NRF_ERROR_BASE_NUM + 7) ///< -// Invalid Parameter -// #define NRF_ERROR_INVALID_STATE \ -// (NRF_ERROR_BASE_NUM + \ -// 8) ///< Invalid state, operation disallowed in this state -// #define NRF_ERROR_INVALID_LENGTH (NRF_ERROR_BASE_NUM + 9) ///< Invalid -// Length #define NRF_ERROR_INVALID_FLAGS (NRF_ERROR_BASE_NUM + 10) ///< -// Invalid Flags #define NRF_ERROR_INVALID_DATA (NRF_ERROR_BASE_NUM + 11) ///< -// Invalid Data #define NRF_ERROR_DATA_SIZE (NRF_ERROR_BASE_NUM + 12) ///< -// Invalid Data size #define NRF_ERROR_TIMEOUT (NRF_ERROR_BASE_NUM + 13) ///< -// Operation timed out #define NRF_ERROR_NULL (NRF_ERROR_BASE_NUM + 14) ///< -// Null Pointer #define NRF_ERROR_FORBIDDEN (NRF_ERROR_BASE_NUM + 15) ///< -// Forbidden Operation -// #define NRF_ERROR_INVALID_ADDR \ -// (NRF_ERROR_BASE_NUM + 16) ///< Bad Memory Address -// #define NRF_ERROR_BUSY (NRF_ERROR_BASE_NUM + 17) ///< Busy -// #define NRF_ERROR_CONN_COUNT \ -// (NRF_ERROR_BASE_NUM + 18) ///< Maximum connection count exceeded. -// #define NRF_ERROR_RESOURCES \ -// (NRF_ERROR_BASE_NUM + 19) ///< Not enough resources for operation + enum nrfx_err_t + { + NRF_SUCCESS = (0x0BAD0000 + 0), + NRF_ERROR_INTERNAL = (0x0BAD0000 + 1), + NRF_ERROR_NO_MEM = (0x0BAD0000 + 2), + NRF_ERROR_NOT_SUPPORTED = (0x0BAD0000 + 3), + NRF_ERROR_INVALID_PARAM = (0x0BAD0000 + 4), + NRF_ERROR_INVALID_STATE = (0x0BAD0000 + 5), + NRF_ERROR_INVALID_LENGTH = (0x0BAD0000 + 6), + NRF_ERROR_TIMEOUT = (0x0BAD0000 + 7), + NRF_ERROR_FORBIDDEN = (0x0BAD0000 + 8), + NRF_ERROR_NULL = (0x0BAD0000 + 9), + NRF_ERROR_INVALID_ADDR = (0x0BAD0000 + 10), + NRF_ERROR_BUSY = (0x0BAD0000 + 11), + NRF_ERROR_ALREADY_INITIALIZED = (0x0BAD0000 + 12), + NRF_ERROR_DRV_TWI_ERR_OVERRUN = ((0x0BAD0000 + 0x10000) + 0), + NRF_ERROR_DRV_TWI_ERR_ANACK = ((0x0BAD0000 + 0x10000) + 1), + NRF_ERROR_DRV_TWI_ERR_DNACK = ((0x0BAD0000 + 0x10000) + 2) + }; #ifdef __cplusplus } #endif -#endif // NRF_ERROR_H__ -/** - @} -*/ +#endif /* NRF_ERROR_H__ */ + +/** @} */ diff --git a/zephyrdoom/src/config/nrfx_config.h b/zephyrdoom/src/config/nrfx_config.h index a65409d..47f5351 100644 --- a/zephyrdoom/src/config/nrfx_config.h +++ b/zephyrdoom/src/config/nrfx_config.h @@ -1,4 +1,3 @@ - #define NRF_CLOCK NRF_CLOCK_S #define NRF_COMP NRF_COMP_S #define NRF_DCNF NRF_DCNF_S @@ -80,44 +79,41 @@ #define NRF_TAD NRF_TAD_S #define NRF_UICR NRF_UICR_S -/* Fixups for the GPIOTE driver. */ +/* Fixups for the GPIOTE driver */ #define NRF_GPIOTE NRF_GPIOTE0 #define GPIOTE_IRQHandler GPIOTE0_IRQHandler -/* Fixups for the QDEC driver. */ +/* Fixups for the QDEC driver */ #define NRF_QDEC NRF_QDEC0 #define QDEC_IRQHandler QDEC0_IRQHandler -//========================================================== - #define NRFX_POWER_ENABLED 1 #define NRFX_POWER_DEFAULT_CONFIG_IRQ_PRIORITY 3 #define NRFX_CLOCK_ENABLED 1 #define NRFX_CLOCK_DEFAULT_CONFIG_IRQ_PRIORITY 3 -// NRFX_CLOCK_CONFIG_LF_SRC - LF clock source. - -// <0=> ULP -// <1=> RC -// <2=> XTAL -// <3=> Synth - +/* + * NRFX_CLOCK_CONFIG_LF_SRC - LF clock source + * 0 - ULP + * 1 - RC + * 2 - XTAL + * 3 - Synth + */ #ifndef NRFX_CLOCK_CONFIG_LF_SRC #define NRFX_CLOCK_CONFIG_LF_SRC 2 #endif -// NRFX_CLOCK_CONFIG_HFCLK192M_SRC - HFCLK192M source. - -// <0=> HFINT -// <1=> HFXO - +/* + * NRFX_CLOCK_CONFIG_HFCLK192M_SRC - HFCLK192M source + * 0 - HFINT + * 1 - HFXO + */ #ifndef NRFX_CLOCK_CONFIG_HFCLK192M_SRC #define NRFX_CLOCK_CONFIG_HFCLK192M_SRC 1 #endif -//========================================================== -// NRFX_PRS_ENABLED - nrfx_prs - Peripheral Resource Sharing module -//========================================================== + +/* NRFX_PRS_ENABLED - nrfx_prs - Peripheral Resource Sharing module */ #define NRFX_PRS_ENABLED 0 #define NRFX_PRS_BOX_0_ENABLED 0 #define NRFX_PRS_BOX_1_ENABLED 0 @@ -125,56 +121,73 @@ #define NRFX_PRS_BOX_3_ENABLED 0 #define NRFX_PRS_BOX_4_ENABLED 1 -// NRFX_SPIM_ENABLED - nrfx_spim - SPIM peripheral driver -//========================================================== +/* NRFX_SPIM_ENABLED - nrfx_spim - SPIM peripheral driver */ #define NRFX_SPIM_ENABLED 1 #define NRFX_SPIM0_ENABLED 1 #define NRFX_SPIM1_ENABLED 0 #define NRFX_SPIM2_ENABLED 0 #define NRFX_SPIM3_ENABLED 0 -// NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY - Interrupt priority +/* NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY - Interrupt priority */ #define NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY 6 #define NRFX_SPIM_CONFIG_LOG_ENABLED 0 #define NRFX_SPIM_CONFIG_LOG_LEVEL 3 #define NRFX_SPIM_CONFIG_INFO_COLOR 0 #define NRFX_SPIM_CONFIG_DEBUG_COLOR 0 -// NRFX_SPIM_MISO_PULL_CFG - MISO pin pull configuration. -// <0=> NRF_GPIO_PIN_NOPULL -// <1=> NRF_GPIO_PIN_PULLDOWN -// <3=> NRF_GPIO_PIN_PULLUP +/* + * NRFX_SPIM_MISO_PULL_CFG - MISO pin pull configuration + * 0 - NRF_GPIO_PIN_NOPULL + * 1 - NRF_GPIO_PIN_PULLDOWN + * 3 - NRF_GPIO_PIN_PULLUP + */ #define NRFX_SPIM_MISO_PULL_CFG 1 -// NRFX_QSPI_ENABLED - nrfx_qspi - QSPI peripheral driver -//========================================================== +/* NRFX_QSPI_ENABLED - nrfx_qspi - QSPI peripheral driver */ #define NRFX_QSPI_ENABLED 1 #define NRFX_QSPI_CONFIG_SCK_DELAY 1 -// NRFX_QSPI_CONFIG_XIP_OFFSET - Address offset in the external memory for -// Execute in Place operation. +/* + * NRFX_QSPI_CONFIG_XIP_OFFSET - Address offset in the external memory for + * Execute in Place operation + */ #define NRFX_QSPI_CONFIG_XIP_OFFSET 0 -// NRFX_QSPI_CONFIG_READOC - Number of data lines and opcode used for -// reading. <0=> FastRead <1=> Read2O <2=> Read2IO <3=> Read4O <4=> Read4IO +/* + * NRFX_QSPI_CONFIG_READOC - Number of data lines and opcode used for reading + * 0 - FastRead + * 1 - Read2O + * 2 - Read2IO + * 3 - Read4O + * 4 - Read4IO + */ #define NRFX_QSPI_CONFIG_READOC 4 -// NRFX_QSPI_CONFIG_WRITEOC - Number of data lines and opcode used for -// writing. <0=> PP <1=> PP2O <2=> PP4O <3=> PP4IO +/* + * NRFX_QSPI_CONFIG_WRITEOC - Number of data lines and opcode used for writing + * 0 - PP + * 1 - PP2O + * 2 - PP4O + * 3 - PP4IO + */ #define NRFX_QSPI_CONFIG_WRITEOC 3 -// NRFX_QSPI_CONFIG_ADDRMODE - Addressing mode. -// <0=> 24bit -// <1=> 32bit +/* + * NRFX_QSPI_CONFIG_ADDRMODE - Addressing mode + * 0 - 24 bit + * 1 - 32 bit + */ #define NRFX_QSPI_CONFIG_ADDRMODE 0 -// NRFX_QSPI_CONFIG_MODE - SPI mode. -// <0=> Mode 0 -// <1=> Mode 1 +/* + * NRFX_QSPI_CONFIG_MODE - SPI mode + * 0 - Mode 0 + * 1 - Mode 1 + */ #define NRFX_QSPI_CONFIG_MODE 0 -// NRFX_QSPI_CONFIG_FREQUENCY - Frequency divider. +/* NRFX_QSPI_CONFIG_FREQUENCY - Frequency divider */ #define NRFX_QSPI_CONFIG_FREQUENCY 0 #define NRFX_QSPI_PIN_SCK NRF_QSPI_PIN_NOT_CONNECTED @@ -184,5 +197,5 @@ #define NRFX_QSPI_PIN_IO2 NRF_QSPI_PIN_NOT_CONNECTED #define NRFX_QSPI_PIN_IO3 NRF_QSPI_PIN_NOT_CONNECTED -// NRFX_QSPI_CONFIG_IRQ_PRIORITY - Interrupt priority +/* NRFX_QSPI_CONFIG_IRQ_PRIORITY - Interrupt priority */ #define NRFX_QSPI_DEFAULT_CONFIG_IRQ_PRIORITY 7 From 0cefc14783c89b7e8d427a6d51bf7c1cb0349dff Mon Sep 17 00:00:00 2001 From: Maciej Gebicz Date: Tue, 15 Jul 2025 13:04:36 +0200 Subject: [PATCH 3/3] zephyrdoom, src: Clean implementation sources IMPORTANT: The commit does not change functionality of the code! The commit contains the following changes: - Clean up of redundant/deprecated comments; - Clean up of redundant whitespaces and new lines; - Fix of spacing within lines; - Unify C comments to C89 and C98 code structure (/**/ instead of //); - Fix too long lines; - Unify comments among files; - Unify TODO sections within the code; - Remove deprecated sections of code; - Fix combining and dividing of conditions and loops; - Fix typos; - Fix various definitions of functions; Additionally, the source code structure has been unified using default auto formatter of C code which is up to date with recent standards. In Visual Studio code if not enabled by default, the key combination is Shift + Alt + F Some exceptions have been applied for better readability due to Doxygen, Chocolate Doom custom parser documentation and various directives available in the code. --- zephyrdoom/src/FT810.h | 669 ++-- zephyrdoom/src/bluetooth_control.c | 457 ++- zephyrdoom/src/bluetooth_control.h | 2 +- zephyrdoom/src/d_dedicated.c | 42 +- zephyrdoom/src/d_event.c | 55 +- zephyrdoom/src/d_event.h | 217 +- zephyrdoom/src/d_iwad.c | 383 +-- zephyrdoom/src/d_iwad.h | 44 +- zephyrdoom/src/d_loop.c | 740 ++-- zephyrdoom/src/d_loop.h | 93 +- zephyrdoom/src/d_mode.c | 210 +- zephyrdoom/src/d_mode.h | 127 +- zephyrdoom/src/d_ticcmd.h | 95 +- zephyrdoom/src/deh_defs.h | 53 +- zephyrdoom/src/deh_io.c | 131 +- zephyrdoom/src/deh_io.h | 34 +- zephyrdoom/src/deh_main.c | 252 +- zephyrdoom/src/deh_main.h | 43 +- zephyrdoom/src/deh_mapping.c | 131 +- zephyrdoom/src/deh_mapping.h | 84 +- zephyrdoom/src/deh_str.c | 217 +- zephyrdoom/src/deh_str.h | 51 +- zephyrdoom/src/deh_text.c | 87 +- zephyrdoom/src/doomkeys.h | 319 +- zephyrdoom/src/doomtype.h | 115 +- zephyrdoom/src/hardfault_handler_gcc.c | 49 +- zephyrdoom/src/i_cdmus.h | 46 +- zephyrdoom/src/i_endoom.h | 41 +- zephyrdoom/src/i_input.c | 190 +- zephyrdoom/src/i_input.h | 51 +- zephyrdoom/src/i_joystick.c | 214 +- zephyrdoom/src/i_joystick.h | 91 +- zephyrdoom/src/i_sound.c | 292 +- zephyrdoom/src/i_sound.h | 186 +- zephyrdoom/src/i_swap.h | 58 +- zephyrdoom/src/i_system.c | 560 ++- zephyrdoom/src/i_system.h | 103 +- zephyrdoom/src/i_timer.c | 79 +- zephyrdoom/src/i_timer.h | 58 +- zephyrdoom/src/i_video.c | 575 ++-- zephyrdoom/src/i_video.h | 117 +- zephyrdoom/src/m_argv.c | 402 ++- zephyrdoom/src/m_argv.h | 61 +- zephyrdoom/src/m_bbox.c | 71 +- zephyrdoom/src/m_bbox.h | 52 +- zephyrdoom/src/m_cheat.c | 87 +- zephyrdoom/src/m_cheat.h | 64 +- zephyrdoom/src/m_config.c | 3907 ++++++++++----------- zephyrdoom/src/m_config.h | 37 +- zephyrdoom/src/m_controls.c | 564 ++- zephyrdoom/src/m_controls.h | 37 +- zephyrdoom/src/m_fixed.c | 66 +- zephyrdoom/src/m_fixed.h | 54 +- zephyrdoom/src/m_misc.c | 319 +- zephyrdoom/src/m_misc.h | 37 +- zephyrdoom/src/main.c | 93 +- zephyrdoom/src/memio.c | 99 +- zephyrdoom/src/memio.h | 30 +- zephyrdoom/src/n_buttons.c | 27 +- zephyrdoom/src/n_buttons.h | 1 - zephyrdoom/src/n_display.c | 248 +- zephyrdoom/src/n_display.h | 6 +- zephyrdoom/src/n_fs.c | 109 +- zephyrdoom/src/n_fs.h | 73 +- zephyrdoom/src/n_hardfault.c | 223 +- zephyrdoom/src/n_i2s.c | 123 +- zephyrdoom/src/n_i2s.h | 1 - zephyrdoom/src/n_i2s_sound.c | 254 +- zephyrdoom/src/n_mem.c | 37 +- zephyrdoom/src/n_qspi.c | 157 +- zephyrdoom/src/n_qspi.h | 13 +- zephyrdoom/src/n_rjoy.c | 46 +- zephyrdoom/src/n_rjoy.h | 4 +- zephyrdoom/src/net_client.c | 1844 +++++----- zephyrdoom/src/net_client.h | 33 +- zephyrdoom/src/net_common.c | 274 +- zephyrdoom/src/net_common.h | 70 +- zephyrdoom/src/net_dedicated.c | 80 +- zephyrdoom/src/net_dedicated.h | 34 +- zephyrdoom/src/net_defs.h | 187 +- zephyrdoom/src/net_gui.c | 134 +- zephyrdoom/src/net_gui.h | 39 +- zephyrdoom/src/net_io.c | 50 +- zephyrdoom/src/net_io.h | 34 +- zephyrdoom/src/net_loop.c | 84 +- zephyrdoom/src/net_loop.h | 34 +- zephyrdoom/src/net_packet.c | 133 +- zephyrdoom/src/net_packet.h | 34 +- zephyrdoom/src/net_query.c | 413 +-- zephyrdoom/src/net_query.h | 34 +- zephyrdoom/src/net_server.c | 3109 ++++++++--------- zephyrdoom/src/net_server.h | 52 +- zephyrdoom/src/net_structrw.c | 205 +- zephyrdoom/src/net_structrw.h | 46 +- zephyrdoom/src/sha1.c | 334 +- zephyrdoom/src/sha1.h | 39 +- zephyrdoom/src/tables.c | 4357 ++++++++++++------------ zephyrdoom/src/tables.h | 133 +- zephyrdoom/src/v_diskicon.c | 186 +- zephyrdoom/src/v_diskicon.h | 39 +- zephyrdoom/src/v_patch.h | 83 +- zephyrdoom/src/v_video.c | 864 +++-- zephyrdoom/src/v_video.h | 106 +- zephyrdoom/src/w_checksum.c | 128 +- zephyrdoom/src/w_checksum.h | 36 +- zephyrdoom/src/w_file.c | 80 +- zephyrdoom/src/w_file.h | 102 +- zephyrdoom/src/w_file_fatfs.c | 168 +- zephyrdoom/src/w_main.c | 115 +- zephyrdoom/src/w_main.h | 34 +- zephyrdoom/src/w_merge.c | 499 ++- zephyrdoom/src/w_merge.h | 56 +- zephyrdoom/src/w_wad.c | 1138 ++++--- zephyrdoom/src/w_wad.h | 75 +- zephyrdoom/src/z_native.c | 230 +- zephyrdoom/src/z_zone.c | 443 ++- zephyrdoom/src/z_zone.h | 101 +- 117 files changed, 15046 insertions(+), 15886 deletions(-) diff --git a/zephyrdoom/src/FT810.h b/zephyrdoom/src/FT810.h index 3b00c4e..02ef994 100644 --- a/zephyrdoom/src/FT810.h +++ b/zephyrdoom/src/FT810.h @@ -8,346 +8,361 @@ #define FT810_CMD_CLKSEL 0x61 #define FT810_CMD_RST 0x68 -// #define LOW_FREQ_BOUND 58800000L//98% of 60Mhz +/* + * // #define LOW_FREQ_BOUND 58800000L // 98% of 60Mhz + * + * // #define FT81X_VERSION "1.0.4" + * + * // #define ADC_DIFFERENTIAL 1UL + * // #define ADC_SINGLE_ENDED 0UL + * // #define ADPCM_SAMPLES 2UL + * // #define ALWAYS 7UL + * // #define BARGRAPH 11UL + */ -// #define FT81X_VERSION "1.0.4" +#define BITMAPS 1UL -// #define ADC_DIFFERENTIAL 1UL -// #define ADC_SINGLE_ENDED 0UL -// #define ADPCM_SAMPLES 2UL -// #define ALWAYS 7UL -// #define BARGRAPH 11UL -#define BITMAPS 1UL +#define BORDER 0UL -#define BORDER 0UL +/* + * // #define CMDBUF_SIZE 4096UL + * // #define CMD_APPEND 4294967070UL + * // #define CMD_BGCOLOR 4294967049UL + * // #define CMD_BITMAP_TRANSFORM 4294967073UL + * // #define CMD_BUTTON 4294967053UL + * // #define CMD_CALIBRATE 4294967061UL + * // #define CMD_CLOCK 4294967060UL + * // #define CMD_COLDSTART 4294967090UL + * // #define CMD_CRC 4294967043UL + * // #define CMD_CSKETCH 4294967093UL + * // #define CMD_DIAL 4294967085UL + * // #define CMD_DLSTART 4294967040UL + * // #define CMD_EXECUTE 4294967047UL + * // #define CMD_FGCOLOR 4294967050UL + * // #define CMD_GAUGE 4294967059UL + * // #define CMD_GETMATRIX 4294967091UL + * // #define CMD_GETPOINT 4294967048UL + * // #define CMD_GETPROPS 4294967077UL + * // #define CMD_GETPTR 4294967075UL + * // #define CMD_GRADCOLOR 4294967092UL + * // #define CMD_GRADIENT 4294967051UL + * // #define CMD_HAMMERAUX 4294967044UL + * // #define CMD_IDCT_DELETED 4294967046UL + * // #define CMD_INFLATE 4294967074UL + * // #define CMD_INTERRUPT 4294967042UL + * // #define CMD_INT_RAMSHARED 4294967101UL + * // #define CMD_INT_SWLOADIMAGE 4294967102UL + * // #define CMD_KEYS 4294967054UL + * // #define CMD_LOADIDENTITY 4294967078UL + * // #define CMD_LOADIMAGE 4294967076UL + * // #define CMD_LOGO 4294967089UL + * // #define CMD_MARCH 4294967045UL + * // #define CMD_MEDIAFIFO 4294967097UL + * // #define CMD_MEMCPY 4294967069UL + * // #define CMD_MEMCRC 4294967064UL + * // #define CMD_MEMSET 4294967067UL + * // #define CMD_MEMWRITE 4294967066UL + * // #define CMD_MEMZERO 4294967068UL + * // #define CMD_NUMBER 4294967086UL + * // #define CMD_PLAYVIDEO 4294967098UL + * // #define CMD_PROGRESS 4294967055UL + * // #define CMD_REGREAD 4294967065UL + * // #define CMD_ROMFONT 4294967103UL + * // #define CMD_ROTATE 4294967081UL + * // #define CMD_SCALE 4294967080UL + * // #define CMD_SCREENSAVER 4294967087UL + * // #define CMD_SCROLLBAR 4294967057UL + * // #define CMD_SETBASE 4294967096UL + * // #define CMD_SETBITMAP 4294967107UL + * // #define CMD_SETFONT 4294967083UL + * // #define CMD_SETFONT2 4294967099UL + * // #define CMD_SETMATRIX 4294967082UL + * // #define CMD_SETROTATE 4294967094UL + * // #define CMD_SETSCRATCH 4294967100UL + * // #define CMD_SKETCH 4294967088UL + * // #define CMD_SLIDER 4294967056UL + * // #define CMD_SNAPSHOT 4294967071UL + * // #define CMD_SNAPSHOT2 4294967095UL + * // #define CMD_SPINNER 4294967062UL + * // #define CMD_STOP 4294967063UL + * // #define CMD_SWAP 4294967041UL + * // #define CMD_SYNC 4294967106UL + * // #define CMD_TEXT 4294967052UL + * // #define CMD_TOGGLE 4294967058UL + * // #define CMD_TOUCH_TRANSFORM 4294967072UL + * // #define CMD_TRACK 4294967084UL + * // #define CMD_TRANSLATE 4294967079UL + * // #define CMD_VIDEOFRAME 4294967105UL + * // #define CMD_VIDEOSTART 4294967104UL + * + * // #define DECR 4UL + */ -// #define CMDBUF_SIZE 4096UL -// #define CMD_APPEND 4294967070UL -// #define CMD_BGCOLOR 4294967049UL -// #define CMD_BITMAP_TRANSFORM 4294967073UL -// #define CMD_BUTTON 4294967053UL -// #define CMD_CALIBRATE 4294967061UL -// #define CMD_CLOCK 4294967060UL -// #define CMD_COLDSTART 4294967090UL -// #define CMD_CRC 4294967043UL -// #define CMD_CSKETCH 4294967093UL -// #define CMD_DIAL 4294967085UL -// #define CMD_DLSTART 4294967040UL -// #define CMD_EXECUTE 4294967047UL -// #define CMD_FGCOLOR 4294967050UL -// #define CMD_GAUGE 4294967059UL -// #define CMD_GETMATRIX 4294967091UL -// #define CMD_GETPOINT 4294967048UL -// #define CMD_GETPROPS 4294967077UL -// #define CMD_GETPTR 4294967075UL -// #define CMD_GRADCOLOR 4294967092UL -// #define CMD_GRADIENT 4294967051UL -// #define CMD_HAMMERAUX 4294967044UL -// #define CMD_IDCT_DELETED 4294967046UL -// #define CMD_INFLATE 4294967074UL -// #define CMD_INTERRUPT 4294967042UL -// #define CMD_INT_RAMSHARED 4294967101UL -// #define CMD_INT_SWLOADIMAGE 4294967102UL -// #define CMD_KEYS 4294967054UL -// #define CMD_LOADIDENTITY 4294967078UL -// #define CMD_LOADIMAGE 4294967076UL -// #define CMD_LOGO 4294967089UL -// #define CMD_MARCH 4294967045UL -// #define CMD_MEDIAFIFO 4294967097UL -// #define CMD_MEMCPY 4294967069UL -// #define CMD_MEMCRC 4294967064UL -// #define CMD_MEMSET 4294967067UL -// #define CMD_MEMWRITE 4294967066UL -// #define CMD_MEMZERO 4294967068UL -// #define CMD_NUMBER 4294967086UL -// #define CMD_PLAYVIDEO 4294967098UL -// #define CMD_PROGRESS 4294967055UL -// #define CMD_REGREAD 4294967065UL -// #define CMD_ROMFONT 4294967103UL -// #define CMD_ROTATE 4294967081UL -// #define CMD_SCALE 4294967080UL -// #define CMD_SCREENSAVER 4294967087UL -// #define CMD_SCROLLBAR 4294967057UL -// #define CMD_SETBASE 4294967096UL -// #define CMD_SETBITMAP 4294967107UL -// #define CMD_SETFONT 4294967083UL -// #define CMD_SETFONT2 4294967099UL -// #define CMD_SETMATRIX 4294967082UL -// #define CMD_SETROTATE 4294967094UL -// #define CMD_SETSCRATCH 4294967100UL -// #define CMD_SKETCH 4294967088UL -// #define CMD_SLIDER 4294967056UL -// #define CMD_SNAPSHOT 4294967071UL -// #define CMD_SNAPSHOT2 4294967095UL -// #define CMD_SPINNER 4294967062UL -// #define CMD_STOP 4294967063UL -// #define CMD_SWAP 4294967041UL -// #define CMD_SYNC 4294967106UL -// #define CMD_TEXT 4294967052UL -// #define CMD_TOGGLE 4294967058UL -// #define CMD_TOUCH_TRANSFORM 4294967072UL -// #define CMD_TRACK 4294967084UL -// #define CMD_TRANSLATE 4294967079UL -// #define CMD_VIDEOFRAME 4294967105UL -// #define CMD_VIDEOSTART 4294967104UL +#define FT810_DLSWAP_DONE 0UL +#define FT810_DLSWAP_FRAME 2UL +#define FT810_DLSWAP_LINE 1UL -// #define DECR 4UL -#define FT810_DLSWAP_DONE 0UL -#define FT810_DLSWAP_FRAME 2UL -#define FT810_DLSWAP_LINE 1UL +/* + * // #define EQUAL 5UL + * // #define GEQUAL 4UL + * // #define GREATER 3UL + * // #define INCR 3UL + * // #define INT_CMDEMPTY 32UL + * // #define INT_CMDFLAG 64UL + * // #define INT_CONVCOMPLETE 128UL + * // #define INT_G8 18UL + * // #define INT_L8C 12UL + * // #define INT_PLAYBACK 16UL + * // #define INT_SOUND 8UL + * // #define INT_SWAP 1UL + * // #define INT_TAG 4UL + * // #define INT_TOUCH 2UL + * // #define INT_VGA 13UL + * // #define INVERT 5UL + * // #define KEEP 1UL + * + * // #define LEQUAL 2UL + * // #define LESS 1UL + * // #define LINEAR_SAMPLES 0UL + * // #define LINE_STRIP 4UL + */ -// #define EQUAL 5UL -// #define GEQUAL 4UL -// #define GREATER 3UL -// #define INCR 3UL -// #define INT_CMDEMPTY 32UL -// #define INT_CMDFLAG 64UL -// #define INT_CONVCOMPLETE 128UL -// #define INT_G8 18UL -// #define INT_L8C 12UL -// #define INT_PLAYBACK 16UL -// #define INT_SOUND 8UL -// #define INT_SWAP 1UL -// #define INT_TAG 4UL -// #define INT_TOUCH 2UL -// #define INT_VGA 13UL -// #define INVERT 5UL -// #define KEEP 1UL +#define BILINEAR 1UL +#define NEAREST 0UL -// #define LEQUAL 2UL -// #define LESS 1UL -// #define LINEAR_SAMPLES 0UL -// #define LINE_STRIP 4UL -#define BILINEAR 1UL -#define NEAREST 0UL -// #define NEVER 0UL -// #define NOTEQUAL 6UL -#define ZERO 0UL -#define ONE 1UL -#define DST_ALPHA 3UL -#define SRC_ALPHA 2UL -#define ONE_MINUS_DST_ALPHA 5UL -#define ONE_MINUS_SRC_ALPHA 4UL -// #define OPT_CENTER 1536UL -// #define OPT_CENTERX 512UL -// #define OPT_CENTERY 1024UL -// #define OPT_FLAT 256UL -// #define OPT_FULLSCREEN 8UL -// #define OPT_MEDIAFIFO 16UL -// #define OPT_MONO 1UL -// #define OPT_NOBACK 4096UL -// #define OPT_NODL 2UL -// #define OPT_NOHANDS 49152UL -// #define OPT_NOHM 16384UL -// #define OPT_NOPOINTER 16384UL -// #define OPT_NOSECS 32768UL -// #define OPT_NOTEAR 4UL -// #define OPT_NOTICKS 8192UL -// #define OPT_RIGHTX 2048UL -// #define OPT_SIGNED 256UL -// #define OPT_SOUND 32UL +/* + * // #define NEVER 0UL + * // #define NOTEQUAL 6UL + */ -#define L1 1UL -#define L2 17UL -#define L4 2UL -#define L8 3UL -#define PALETTED 8UL -#define PALETTED4444 15UL -#define PALETTED565 14UL -#define PALETTED8 16UL -#define RGB332 4UL -#define RGB565 7UL -#define TEXT8X8 9UL -#define TEXTVGA 10UL -#define ARGB1555 0UL -#define ARGB2 5UL -#define ARGB4 6UL +#define ZERO 0UL +#define ONE 1UL +#define DST_ALPHA 3UL +#define SRC_ALPHA 2UL +#define ONE_MINUS_DST_ALPHA 5UL +#define ONE_MINUS_SRC_ALPHA 4UL -#define POINTS 2UL -#define LINES 3UL -#define RECTS 9UL -#define EDGE_STRIP_A 7UL -#define EDGE_STRIP_B 8UL -#define EDGE_STRIP_L 6UL -#define EDGE_STRIP_R 5UL +/* + * // #define OPT_CENTER 1536UL + * // #define OPT_CENTERX 512UL + * // #define OPT_CENTERY 1024UL + * // #define OPT_FLAT 256UL + * // #define OPT_FULLSCREEN 8UL + * // #define OPT_MEDIAFIFO 16UL + * // #define OPT_MONO 1UL + * // #define OPT_NOBACK 4096UL + * // #define OPT_NODL 2UL + * // #define OPT_NOHANDS 49152UL + * // #define OPT_NOHM 16384UL + * // #define OPT_NOPOINTER 16384UL + * // #define OPT_NOSECS 32768UL + * // #define OPT_NOTEAR 4UL + * // #define OPT_NOTICKS 8192UL + * // #define OPT_RIGHTX 2048UL + * // #define OPT_SIGNED 256UL + * // #define OPT_SOUND 32UL + */ -#define FT810_RAM_CMD 0x308000 -#define FT810_RAM_DL 0x300000 -#define FT810_RAM_G 0x000000 -#define FT810_RAM_G_SIZE 1024*1024L -#define FT810_RAM_REG 0x302000 -#define FT810_RAM_ROMSUB 0x30a000 +#define L1 1UL +#define L2 17UL +#define L4 2UL +#define L8 3UL +#define PALETTED 8UL +#define PALETTED4444 15UL +#define PALETTED565 14UL +#define PALETTED8 16UL +#define RGB332 4UL +#define RGB565 7UL +#define TEXT8X8 9UL +#define TEXTVGA 10UL +#define ARGB1555 0UL +#define ARGB2 5UL +#define ARGB4 6UL +#define POINTS 2UL +#define LINES 3UL +#define RECTS 9UL +#define EDGE_STRIP_A 7UL +#define EDGE_STRIP_B 8UL +#define EDGE_STRIP_L 6UL +#define EDGE_STRIP_R 5UL -// #define ROMFONT_TABLEADDRESS 3145724UL +#define FT810_RAM_CMD 0x308000 +#define FT810_RAM_DL 0x300000 +#define FT810_RAM_G 0x000000 +#define FT810_RAM_G_SIZE 1024 * 1024L +#define FT810_RAM_REG 0x302000 +#define FT810_RAM_ROMSUB 0x30a000 -#define FT810_REG_ANALOG 0x30216c -#define FT810_REG_ANA_COMP 0x302184 -#define FT810_REG_BIST_EN 0x302174 -#define FT810_REG_BUSYBITS 0x3020e8 -#define FT810_REG_CLOCK 0x302008 -#define FT810_REG_CMDB_SPACE 0x302574 -#define FT810_REG_CMDB_WRITE 0x302578 -#define FT810_REG_CMD_DL 0x302100 -#define FT810_REG_CMD_READ 0x3020f8 -#define FT810_REG_CMD_WRITE 0x3020fc -#define FT810_REG_CPURESET 0x302020 -#define FT810_REG_CRC 0x302178 -#define FT810_REG_CSPREAD 0x302068 -#define FT810_REG_CTOUCH_EXTENDED 0x302108 -#define FT810_REG_CTOUCH_TOUCH0_XY 0x302124 -#define FT810_REG_CTOUCH_TOUCH4_X 0x30216c -#define FT810_REG_CTOUCH_TOUCH4_Y 0x302120 -#define FT810_REG_CTOUCH_TOUCH1_XY 0x30211c -#define FT810_REG_CTOUCH_TOUCH2_XY 0x30218c -#define FT810_REG_CTOUCH_TOUCH3_XY 0x302190 -#define FT810_REG_CYA_TOUCH 0x302168 -#define FT810_REG_DATESTAMP 0x302564 -#define FT810_REG_DITHER 0x302060 -#define FT810_REG_DLSWAP 0x302054 -#define FT810_REG_FRAMES 0x302004 -#define FT810_REG_FREQUENCY 0x30200c -#define FT810_REG_GPIO 0x302094 -#define FT810_REG_GPIOX 0x30209c -#define FT810_REG_GPIOX_DIR 0x302098 -#define FT810_REG_GPIO_DIR 0x302090 -#define FT810_REG_HCYCLE 0x30202c -#define FT810_REG_HOFFSET 0x302030 -#define FT810_REG_HSIZE 0x302034 -#define FT810_REG_HSYNC0 0x302038 -#define FT810_REG_HSYNC1 0x30203c -#define FT810_REG_ID 0x302000 -#define FT810_REG_INT_EN 0x3020ac -#define FT810_REG_INT_FLAGS 0x3020a8 -#define FT810_REG_INT_MASK 0x3020b0 -#define FT810_REG_MACRO_0 0x3020d8 -#define FT810_REG_MACRO_1 0x3020dc -#define FT810_REG_MEDIAFIFO_READ 0x309014 -#define FT810_REG_MEDIAFIFO_WRITE 0x309018 -#define FT810_REG_OUTBITS 0x30205c -#define FT810_REG_PATCHED_ANALOG 0x302170 +/* #define ROMFONT_TABLEADDRESS 3145724UL */ + +#define FT810_REG_ANALOG 0x30216c +#define FT810_REG_ANA_COMP 0x302184 +#define FT810_REG_BIST_EN 0x302174 +#define FT810_REG_BUSYBITS 0x3020e8 +#define FT810_REG_CLOCK 0x302008 +#define FT810_REG_CMDB_SPACE 0x302574 +#define FT810_REG_CMDB_WRITE 0x302578 +#define FT810_REG_CMD_DL 0x302100 +#define FT810_REG_CMD_READ 0x3020f8 +#define FT810_REG_CMD_WRITE 0x3020fc +#define FT810_REG_CPURESET 0x302020 +#define FT810_REG_CRC 0x302178 +#define FT810_REG_CSPREAD 0x302068 +#define FT810_REG_CTOUCH_EXTENDED 0x302108 +#define FT810_REG_CTOUCH_TOUCH0_XY 0x302124 +#define FT810_REG_CTOUCH_TOUCH4_X 0x30216c +#define FT810_REG_CTOUCH_TOUCH4_Y 0x302120 +#define FT810_REG_CTOUCH_TOUCH1_XY 0x30211c +#define FT810_REG_CTOUCH_TOUCH2_XY 0x30218c +#define FT810_REG_CTOUCH_TOUCH3_XY 0x302190 +#define FT810_REG_CYA_TOUCH 0x302168 +#define FT810_REG_DATESTAMP 0x302564 +#define FT810_REG_DITHER 0x302060 +#define FT810_REG_DLSWAP 0x302054 +#define FT810_REG_FRAMES 0x302004 +#define FT810_REG_FREQUENCY 0x30200c +#define FT810_REG_GPIO 0x302094 +#define FT810_REG_GPIOX 0x30209c +#define FT810_REG_GPIOX_DIR 0x302098 +#define FT810_REG_GPIO_DIR 0x302090 +#define FT810_REG_HCYCLE 0x30202c +#define FT810_REG_HOFFSET 0x302030 +#define FT810_REG_HSIZE 0x302034 +#define FT810_REG_HSYNC0 0x302038 +#define FT810_REG_HSYNC1 0x30203c +#define FT810_REG_ID 0x302000 +#define FT810_REG_INT_EN 0x3020ac +#define FT810_REG_INT_FLAGS 0x3020a8 +#define FT810_REG_INT_MASK 0x3020b0 +#define FT810_REG_MACRO_0 0x3020d8 +#define FT810_REG_MACRO_1 0x3020dc +#define FT810_REG_MEDIAFIFO_READ 0x309014 +#define FT810_REG_MEDIAFIFO_WRITE 0x309018 +#define FT810_REG_OUTBITS 0x30205c +#define FT810_REG_PATCHED_ANALOG 0x302170 #define FT810_REG_PATCHED_TOUCH_FAULT 0x30216c -#define FT810_REG_PCLK 0x302070 -#define FT810_REG_PCLK_POL 0x30206c -#define FT810_REG_PLAY 0x30208c -#define FT810_REG_PLAYBACK_FORMAT 0x3020c4 -#define FT810_REG_PLAYBACK_FREQ 0x3020c0 -#define FT810_REG_PLAYBACK_LENGTH 0x3020b8 -#define FT810_REG_PLAYBACK_LOOP 0x3020c8 -#define FT810_REG_PLAYBACK_PLAY 0x3020cc -#define FT810_REG_PLAYBACK_READPTR 0x3020bc -#define FT810_REG_PLAYBACK_START 0x3020b4 -#define FT810_REG_PWM_DUTY 0x3020d4 -#define FT810_REG_PWM_HZ 0x3020d0 -#define FT810_REG_RENDERMODE 0x302010 -#define FT810_REG_ROMSUB_SEL 0x3020f0 -#define FT810_REG_ROTATE 0x302058 -#define FT810_REG_SNAPFORMAT 0x30201c -#define FT810_REG_SNAPSHOT 0x302018 -#define FT810_REG_SNAPY 0x302014 -#define FT810_REG_SOUND 0x302088 -#define FT810_REG_SPI_EARLY_TX 0x30217c -#define FT810_REG_SPI_WIDTH 0x302188 -#define FT810_REG_SWIZZLE 0x302064 -#define FT810_REG_TAG 0x30207c -#define FT810_REG_TAG_X 0x302074 -#define FT810_REG_TAG_Y 0x302078 -#define FT810_REG_TAP_CRC 0x302024 -#define FT810_REG_TAP_MASK 0x302028 -#define FT810_REG_TOUCH_ADC_MODE 0x302108 -#define FT810_REG_TOUCH_CHARGE 0x30210c -#define FT810_REG_TOUCH_DIRECT_XY 0x30218c -#define FT810_REG_TOUCH_DIRECT_Z1Z2 0x302190 -#define FT810_REG_TOUCH_FAULT 0x302170 -#define FT810_REG_TOUCH_MODE 0x302104 -#define FT810_REG_TOUCH_OVERSAMPLE 0x302114 -#define FT810_REG_TOUCH_RAW_XY 0x30211c -#define FT810_REG_TOUCH_RZ 0x302120 -#define FT810_REG_TOUCH_RZTHRESH 0x302118 -#define FT810_REG_TOUCH_SCREEN_XY 0x302124 -#define FT810_REG_TOUCH_SETTLE 0x302110 -#define FT810_REG_TOUCH_TAG 0x30212c -#define FT810_REG_TOUCH_TAG1 0x302134 -#define FT810_REG_TOUCH_TAG1_XY 0x302130 -#define FT810_REG_TOUCH_TAG2 0x30213c -#define FT810_REG_TOUCH_TAG2_XY 0x302138 -#define FT810_REG_TOUCH_TAG3 0x302144 -#define FT810_REG_TOUCH_TAG3_XY 0x302140 -#define FT810_REG_TOUCH_TAG4 0x30214c -#define FT810_REG_TOUCH_TAG4_XY 0x302148 -#define FT810_REG_TOUCH_TAG_XY 0x302128 -#define FT810_REG_TOUCH_TRANSFORM_A 0x302150 -#define FT810_REG_TOUCH_TRANSFORM_B 0x302154 -#define FT810_REG_TOUCH_TRANSFORM_C 0x302158 -#define FT810_REG_TOUCH_TRANSFORM_D 0x30215c -#define FT810_REG_TOUCH_TRANSFORM_E 0x302160 -#define FT810_REG_TOUCH_TRANSFORM_F 0x302164 -#define FT810_REG_TRACKER 0x309000 -#define FT810_REG_TRACKER_1 0x309004 -#define FT810_REG_TRACKER_2 0x309008 -#define FT810_REG_TRACKER_3 0x30900c -#define FT810_REG_TRACKER_4 0x309010 -#define FT810_REG_TRIM 0x302180 -#define FT810_REG_VCYCLE 0x302040 -#define FT810_REG_VOFFSET 0x302044 -#define FT810_REG_VOL_PB 0x302080 -#define FT810_REG_VOL_SOUND 0x302084 -#define FT810_REG_VSIZE 0x302048 -#define FT810_REG_VSYNC0 0x30204c -#define FT810_REG_VSYNC1 0x302050 +#define FT810_REG_PCLK 0x302070 +#define FT810_REG_PCLK_POL 0x30206c +#define FT810_REG_PLAY 0x30208c +#define FT810_REG_PLAYBACK_FORMAT 0x3020c4 +#define FT810_REG_PLAYBACK_FREQ 0x3020c0 +#define FT810_REG_PLAYBACK_LENGTH 0x3020b8 +#define FT810_REG_PLAYBACK_LOOP 0x3020c8 +#define FT810_REG_PLAYBACK_PLAY 0x3020cc +#define FT810_REG_PLAYBACK_READPTR 0x3020bc +#define FT810_REG_PLAYBACK_START 0x3020b4 +#define FT810_REG_PWM_DUTY 0x3020d4 +#define FT810_REG_PWM_HZ 0x3020d0 +#define FT810_REG_RENDERMODE 0x302010 +#define FT810_REG_ROMSUB_SEL 0x3020f0 +#define FT810_REG_ROTATE 0x302058 +#define FT810_REG_SNAPFORMAT 0x30201c +#define FT810_REG_SNAPSHOT 0x302018 +#define FT810_REG_SNAPY 0x302014 +#define FT810_REG_SOUND 0x302088 +#define FT810_REG_SPI_EARLY_TX 0x30217c +#define FT810_REG_SPI_WIDTH 0x302188 +#define FT810_REG_SWIZZLE 0x302064 +#define FT810_REG_TAG 0x30207c +#define FT810_REG_TAG_X 0x302074 +#define FT810_REG_TAG_Y 0x302078 +#define FT810_REG_TAP_CRC 0x302024 +#define FT810_REG_TAP_MASK 0x302028 +#define FT810_REG_TOUCH_ADC_MODE 0x302108 +#define FT810_REG_TOUCH_CHARGE 0x30210c +#define FT810_REG_TOUCH_DIRECT_XY 0x30218c +#define FT810_REG_TOUCH_DIRECT_Z1Z2 0x302190 +#define FT810_REG_TOUCH_FAULT 0x302170 +#define FT810_REG_TOUCH_MODE 0x302104 +#define FT810_REG_TOUCH_OVERSAMPLE 0x302114 +#define FT810_REG_TOUCH_RAW_XY 0x30211c +#define FT810_REG_TOUCH_RZ 0x302120 +#define FT810_REG_TOUCH_RZTHRESH 0x302118 +#define FT810_REG_TOUCH_SCREEN_XY 0x302124 +#define FT810_REG_TOUCH_SETTLE 0x302110 +#define FT810_REG_TOUCH_TAG 0x30212c +#define FT810_REG_TOUCH_TAG1 0x302134 +#define FT810_REG_TOUCH_TAG1_XY 0x302130 +#define FT810_REG_TOUCH_TAG2 0x30213c +#define FT810_REG_TOUCH_TAG2_XY 0x302138 +#define FT810_REG_TOUCH_TAG3 0x302144 +#define FT810_REG_TOUCH_TAG3_XY 0x302140 +#define FT810_REG_TOUCH_TAG4 0x30214c +#define FT810_REG_TOUCH_TAG4_XY 0x302148 +#define FT810_REG_TOUCH_TAG_XY 0x302128 +#define FT810_REG_TOUCH_TRANSFORM_A 0x302150 +#define FT810_REG_TOUCH_TRANSFORM_B 0x302154 +#define FT810_REG_TOUCH_TRANSFORM_C 0x302158 +#define FT810_REG_TOUCH_TRANSFORM_D 0x30215c +#define FT810_REG_TOUCH_TRANSFORM_E 0x302160 +#define FT810_REG_TOUCH_TRANSFORM_F 0x302164 +#define FT810_REG_TRACKER 0x309000 +#define FT810_REG_TRACKER_1 0x309004 +#define FT810_REG_TRACKER_2 0x309008 +#define FT810_REG_TRACKER_3 0x30900c +#define FT810_REG_TRACKER_4 0x309010 +#define FT810_REG_TRIM 0x302180 +#define FT810_REG_VCYCLE 0x302040 +#define FT810_REG_VOFFSET 0x302044 +#define FT810_REG_VOL_PB 0x302080 +#define FT810_REG_VOL_SOUND 0x302084 +#define FT810_REG_VSIZE 0x302048 +#define FT810_REG_VSYNC0 0x30204c +#define FT810_REG_VSYNC1 0x302050 -#define FT810_REPEAT 1UL -#define FT810_REPLACE 2UL +#define FT810_REPEAT 1UL +#define FT810_REPLACE 2UL #define FT810_TOUCHMODE_CONTINUOUS 3UL -#define FT810_TOUCHMODE_FRAME 2UL -#define FT810_TOUCHMODE_OFF 0UL -#define FT810_TOUCHMODE_ONESHOT 1UL -#define FT810_ULAW_SAMPLES 1UL -#define FT810_VERTEX2F(x,y) ((1UL<<30)|(((x)&32767UL)<<15)|(((y)&32767UL)<<0)) -#define FT810_VERTEX2II(x,y,handle,cell) ((2UL<<30)|(((x)&511UL)<<21)|(((y)&511UL)<<12)|(((handle)&31UL)<<7)|(((cell)&127UL)<<0)) -#define FT810_BITMAP_SOURCE(addr) ((1UL<<24)|(((addr)&4194303UL)<<0)) -#define FT810_CLEAR_COLOR_RGB(red,green,blue) ((2UL<<24)|(((red)&255UL)<<16)|(((green)&255UL)<<8)|(((blue)&255UL)<<0)) -#define FT810_TAG(s) ((3UL<<24)|(((s)&255UL)<<0)) -#define FT810_COLOR_RGB(red,green,blue) ((4UL<<24)|(((red)&255UL)<<16)|(((green)&255UL)<<8)|(((blue)&255UL)<<0)) -#define FT810_BITMAP_HANDLE(handle) ((5UL<<24)|(((handle)&31UL)<<0)) -#define FT810_CELL(cell) ((6UL<<24)|(((cell)&127UL)<<0)) -#define FT810_BITMAP_LAYOUT(format,linestride,height) ((7UL<<24)|(((format)&31UL)<<19)|(((linestride)&1023UL)<<9)|(((height)&511UL)<<0)) -#define FT810_BITMAP_SIZE(filter,wrapx,wrapy,width,height) ((8UL<<24)|(((filter)&1UL)<<20)|(((wrapx)&1UL)<<19)|(((wrapy)&1UL)<<18)|(((width)&511UL)<<9)|(((height)&511UL)<<0)) -#define FT810_ALPHA_FUNC(func,ref) ((9UL<<24)|(((func)&7UL)<<8)|(((ref)&255UL)<<0)) -#define FT810_STENCIL_FUNC(func,ref,mask) ((10UL<<24)|(((func)&7UL)<<16)|(((ref)&255UL)<<8)|(((mask)&255UL)<<0)) -#define FT810_BLEND_FUNC(src,dst) ((11UL<<24)|(((src)&7UL)<<3)|(((dst)&7UL)<<0)) -#define FT810_STENCIL_OP(sfail,spass) ((12UL<<24)|(((sfail)&7UL)<<3)|(((spass)&7UL)<<0)) -#define FT810_POINT_SIZE(size) ((13UL<<24)|(((size)&8191UL)<<0)) -#define FT810_LINE_WIDTH(width) ((14UL<<24)|(((width)&4095UL)<<0)) -#define FT810_CLEAR_COLOR_A(alpha) ((15UL<<24)|(((alpha)&255UL)<<0)) -#define FT810_COLOR_A(alpha) ((16UL<<24)|(((alpha)&255UL)<<0)) -#define FT810_CLEAR_STENCIL(s) ((17UL<<24)|(((s)&255UL)<<0)) -#define FT810_CLEAR_TAG(s) ((18UL<<24)|(((s)&255UL)<<0)) -#define FT810_STENCIL_MASK(mask) ((19UL<<24)|(((mask)&255UL)<<0)) -#define FT810_TAG_MASK(mask) ((20UL<<24)|(((mask)&1UL)<<0)) -#define FT810_BITMAP_TRANSFORM_A(a) ((21UL<<24)|(((a)&131071UL)<<0)) -#define FT810_BITMAP_TRANSFORM_B(b) ((22UL<<24)|(((b)&131071UL)<<0)) -#define FT810_BITMAP_TRANSFORM_C(c) ((23UL<<24)|(((c)&16777215UL)<<0)) -#define FT810_BITMAP_TRANSFORM_D(d) ((24UL<<24)|(((d)&131071UL)<<0)) -#define FT810_BITMAP_TRANSFORM_E(e) ((25UL<<24)|(((e)&131071UL)<<0)) -#define FT810_BITMAP_TRANSFORM_F(f) ((26UL<<24)|(((f)&16777215UL)<<0)) -#define FT810_SCISSOR_XY(x,y) ((27UL<<24)|(((x)&2047UL)<<11)|(((y)&2047UL)<<0)) -#define FT810_SCISSOR_SIZE(width,height) ((28UL<<24)|(((width)&4095UL)<<12)|(((height)&4095UL)<<0)) -#define FT810_CALL(dest) ((29UL<<24)|(((dest)&65535UL)<<0)) -#define FT810_JUMP(dest) ((30UL<<24)|(((dest)&65535UL)<<0)) -#define FT810_BEGIN(prim) ((31UL<<24)|(((prim)&15UL)<<0)) -#define FT810_COLOR_MASK(r,g,b,a) ((32UL<<24)|(((r)&1UL)<<3)|(((g)&1UL)<<2)|(((b)&1UL)<<1)|(((a)&1UL)<<0)) -#define FT810_CLEAR(c,s,t) ((38UL<<24)|(((c)&1UL)<<2)|(((s)&1UL)<<1)|(((t)&1UL)<<0)) -#define FT810_VERTEX_FORMAT(frac) ((39UL<<24)|(((frac)&7UL)<<0)) -#define FT810_BITMAP_LAYOUT_H(linestride,height) ((40UL<<24)|(((linestride)&3UL)<<2)|(((height)&3UL)<<0)) -#define FT810_BITMAP_SIZE_H(width,height) ((41UL<<24)|(((width)&3UL)<<2)|(((height)&3UL)<<0)) -#define FT810_PALETTE_SOURCE(addr) ((42UL<<24)|(((addr)&4194303UL)<<0)) -#define FT810_VERTEX_TRANSLATE_X(x) ((43UL<<24)|(((x)&131071UL)<<0)) -#define FT810_VERTEX_TRANSLATE_Y(y) ((44UL<<24)|(((y)&131071UL)<<0)) -#define FT810_NOP() ((45UL<<24)) -#define FT810_END() ((33UL<<24)) -#define FT810_SAVE_CONTEXT() ((34UL<<24)) -#define FT810_RESTORE_CONTEXT() ((35UL<<24)) -#define FT810_RETURN() ((36UL<<24)) -#define FT810_MACRO(m) ((37UL<<24)|(((m)&1UL)<<0)) -#define FT810_DISPLAY() ((0UL<<24)) +#define FT810_TOUCHMODE_FRAME 2UL +#define FT810_TOUCHMODE_OFF 0UL +#define FT810_TOUCHMODE_ONESHOT 1UL +#define FT810_ULAW_SAMPLES 1UL +#define FT810_VERTEX2F(x, y) ((1UL << 30) | (((x) & 32767UL) << 15) | (((y) & 32767UL) << 0)) +#define FT810_VERTEX2II(x, y, handle, cell) ((2UL << 30) | (((x) & 511UL) << 21) | (((y) & 511UL) << 12) | (((handle) & 31UL) << 7) | (((cell) & 127UL) << 0)) +#define FT810_BITMAP_SOURCE(addr) ((1UL << 24) | (((addr) & 4194303UL) << 0)) +#define FT810_CLEAR_COLOR_RGB(red, green, blue) ((2UL << 24) | (((red) & 255UL) << 16) | (((green) & 255UL) << 8) | (((blue) & 255UL) << 0)) +#define FT810_TAG(s) ((3UL << 24) | (((s) & 255UL) << 0)) +#define FT810_COLOR_RGB(red, green, blue) ((4UL << 24) | (((red) & 255UL) << 16) | (((green) & 255UL) << 8) | (((blue) & 255UL) << 0)) +#define FT810_BITMAP_HANDLE(handle) ((5UL << 24) | (((handle) & 31UL) << 0)) +#define FT810_CELL(cell) ((6UL << 24) | (((cell) & 127UL) << 0)) +#define FT810_BITMAP_LAYOUT(format, linestride, height) ((7UL << 24) | (((format) & 31UL) << 19) | (((linestride) & 1023UL) << 9) | (((height) & 511UL) << 0)) +#define FT810_BITMAP_SIZE(filter, wrapx, wrapy, width, height) ((8UL << 24) | (((filter) & 1UL) << 20) | (((wrapx) & 1UL) << 19) | (((wrapy) & 1UL) << 18) | (((width) & 511UL) << 9) | (((height) & 511UL) << 0)) +#define FT810_ALPHA_FUNC(func, ref) ((9UL << 24) | (((func) & 7UL) << 8) | (((ref) & 255UL) << 0)) +#define FT810_STENCIL_FUNC(func, ref, mask) ((10UL << 24) | (((func) & 7UL) << 16) | (((ref) & 255UL) << 8) | (((mask) & 255UL) << 0)) +#define FT810_BLEND_FUNC(src, dst) ((11UL << 24) | (((src) & 7UL) << 3) | (((dst) & 7UL) << 0)) +#define FT810_STENCIL_OP(sfail, spass) ((12UL << 24) | (((sfail) & 7UL) << 3) | (((spass) & 7UL) << 0)) +#define FT810_POINT_SIZE(size) ((13UL << 24) | (((size) & 8191UL) << 0)) +#define FT810_LINE_WIDTH(width) ((14UL << 24) | (((width) & 4095UL) << 0)) +#define FT810_CLEAR_COLOR_A(alpha) ((15UL << 24) | (((alpha) & 255UL) << 0)) +#define FT810_COLOR_A(alpha) ((16UL << 24) | (((alpha) & 255UL) << 0)) +#define FT810_CLEAR_STENCIL(s) ((17UL << 24) | (((s) & 255UL) << 0)) +#define FT810_CLEAR_TAG(s) ((18UL << 24) | (((s) & 255UL) << 0)) +#define FT810_STENCIL_MASK(mask) ((19UL << 24) | (((mask) & 255UL) << 0)) +#define FT810_TAG_MASK(mask) ((20UL << 24) | (((mask) & 1UL) << 0)) +#define FT810_BITMAP_TRANSFORM_A(a) ((21UL << 24) | (((a) & 131071UL) << 0)) +#define FT810_BITMAP_TRANSFORM_B(b) ((22UL << 24) | (((b) & 131071UL) << 0)) +#define FT810_BITMAP_TRANSFORM_C(c) ((23UL << 24) | (((c) & 16777215UL) << 0)) +#define FT810_BITMAP_TRANSFORM_D(d) ((24UL << 24) | (((d) & 131071UL) << 0)) +#define FT810_BITMAP_TRANSFORM_E(e) ((25UL << 24) | (((e) & 131071UL) << 0)) +#define FT810_BITMAP_TRANSFORM_F(f) ((26UL << 24) | (((f) & 16777215UL) << 0)) +#define FT810_SCISSOR_XY(x, y) ((27UL << 24) | (((x) & 2047UL) << 11) | (((y) & 2047UL) << 0)) +#define FT810_SCISSOR_SIZE(width, height) ((28UL << 24) | (((width) & 4095UL) << 12) | (((height) & 4095UL) << 0)) +#define FT810_CALL(dest) ((29UL << 24) | (((dest) & 65535UL) << 0)) +#define FT810_JUMP(dest) ((30UL << 24) | (((dest) & 65535UL) << 0)) +#define FT810_BEGIN(prim) ((31UL << 24) | (((prim) & 15UL) << 0)) +#define FT810_COLOR_MASK(r, g, b, a) ((32UL << 24) | (((r) & 1UL) << 3) | (((g) & 1UL) << 2) | (((b) & 1UL) << 1) | (((a) & 1UL) << 0)) +#define FT810_CLEAR(c, s, t) ((38UL << 24) | (((c) & 1UL) << 2) | (((s) & 1UL) << 1) | (((t) & 1UL) << 0)) +#define FT810_VERTEX_FORMAT(frac) ((39UL << 24) | (((frac) & 7UL) << 0)) +#define FT810_BITMAP_LAYOUT_H(linestride, height) ((40UL << 24) | (((linestride) & 3UL) << 2) | (((height) & 3UL) << 0)) +#define FT810_BITMAP_SIZE_H(width, height) ((41UL << 24) | (((width) & 3UL) << 2) | (((height) & 3UL) << 0)) +#define FT810_PALETTE_SOURCE(addr) ((42UL << 24) | (((addr) & 4194303UL) << 0)) +#define FT810_VERTEX_TRANSLATE_X(x) ((43UL << 24) | (((x) & 131071UL) << 0)) +#define FT810_VERTEX_TRANSLATE_Y(y) ((44UL << 24) | (((y) & 131071UL) << 0)) +#define FT810_NOP() ((45UL << 24)) +#define FT810_END() ((33UL << 24)) +#define FT810_SAVE_CONTEXT() ((34UL << 24)) +#define FT810_RESTORE_CONTEXT() ((35UL << 24)) +#define FT810_RETURN() ((36UL << 24)) +#define FT810_MACRO(m) ((37UL << 24) | (((m) & 1UL) << 0)) +#define FT810_DISPLAY() ((0UL << 24)) diff --git a/zephyrdoom/src/bluetooth_control.c b/zephyrdoom/src/bluetooth_control.c index 101b1b8..b64d15a 100644 --- a/zephyrdoom/src/bluetooth_control.c +++ b/zephyrdoom/src/bluetooth_control.c @@ -28,18 +28,23 @@ static const struct gpio_dt_spec led1 = GPIO_DT_SPEC_GET(LED1_NODE, gpios); static const struct gpio_dt_spec led2 = GPIO_DT_SPEC_GET(LED2_NODE, gpios); -static void blink_timer_handler(struct k_timer *timer_id) { - if (gpio_is_ready_dt(&led1)) { +static void blink_timer_handler(struct k_timer *timer_id) +{ + if (gpio_is_ready_dt(&led1)) + { gpio_pin_toggle_dt(&led1); } - if (gpio_is_ready_dt(&led2)) { + + if (gpio_is_ready_dt(&led2)) + { gpio_pin_toggle_dt(&led2); } } K_TIMER_DEFINE(blink_timer, blink_timer_handler, NULL); -typedef enum { +typedef enum +{ DEVICE_TYPE_NONE, DEVICE_TYPE_XBOX, DEVICE_TYPE_KEYBOARD, @@ -53,9 +58,10 @@ static connected_device_t current_device_type = DEVICE_TYPE_NONE; static void hids_on_ready(struct k_work *work); static K_WORK_DEFINE(hids_ready_work, hids_on_ready); -static void parse_xbox_report(const uint8_t *data, size_t len) { - static bool prev_dpad_up, prev_dpad_down, prev_button_back, - prev_button_start; +static void parse_xbox_report(const uint8_t *data, size_t len) +{ + static bool prev_dpad_up, prev_dpad_down, prev_button_back, prev_button_start; + static event_t prev_joystick_event; event_t joystick_event; @@ -79,10 +85,13 @@ static void parse_xbox_report(const uint8_t *data, size_t len) { leftJoyX = ((leftJoyX - 32767) / (double)32767) * 65; leftJoyY = ((leftJoyY - 32767) / (double)32767) * 65; - if (leftJoyX > -8 && leftJoyX < 8) { + if (leftJoyX > -8 && leftJoyX < 8) + { leftJoyX = 0; } - if (leftJoyY > -8 && leftJoyY < 8) { + + if (leftJoyY > -8 && leftJoyY < 8) + { leftJoyY = 0; } @@ -91,35 +100,48 @@ static void parse_xbox_report(const uint8_t *data, size_t len) { int16_t LT = data[8]; int16_t RT = data[10]; - if (LT > 5) { + if (LT > 5) + { joystick_event.data4 = -LT; - } else if (RT > 5) { + } + else if (RT > 5) + { joystick_event.data4 = RT; - } else { + } + else + { joystick_event.data4 = 0; } if (joystick_event.data1 != prev_joystick_event.data1 || joystick_event.data2 != prev_joystick_event.data2 || joystick_event.data3 != prev_joystick_event.data3 || - joystick_event.data4 != prev_joystick_event.data4) { + joystick_event.data4 != prev_joystick_event.data4) + { D_PostEvent(&joystick_event); prev_joystick_event = joystick_event; } - if (dpad_up && !prev_dpad_up) { + if (dpad_up && !prev_dpad_up) + { keyboard_event.data1 = key_up; D_PostEvent(&keyboard_event); } - if (dpad_down && !prev_dpad_down) { + + if (dpad_down && !prev_dpad_down) + { keyboard_event.data1 = key_down; D_PostEvent(&keyboard_event); } - if (button_back && !prev_button_back) { + + if (button_back && !prev_button_back) + { keyboard_event.data1 = key_map_toggle; D_PostEvent(&keyboard_event); } - if (button_start && !prev_button_start) { + + if (button_start && !prev_button_start) + { keyboard_event.data1 = key_menu_activate; D_PostEvent(&keyboard_event); } @@ -130,68 +152,112 @@ static void parse_xbox_report(const uint8_t *data, size_t len) { prev_button_start = button_start; } -static void parse_keyboard_report(const uint8_t *data, size_t len) { - typedef struct { +static void parse_keyboard_report(const uint8_t *data, size_t len) +{ + typedef struct + { uint8_t hid; int doom; int ascii; } keymap_t; + static const keymap_t key_map[] = { - {0x04, 'a', 'a'}, {0x05, 'b', 'b'}, - {0x06, 'c', 'c'}, {0x07, 'd', 'd'}, - {0x08, 'e', 'e'}, {0x09, 'f', 'f'}, - {0x0A, 'g', 'g'}, {0x0B, 'h', 'h'}, - {0x0C, 'i', 'i'}, {0x0D, 'j', 'j'}, - {0x0E, 'k', 'k'}, {0x0F, 'l', 'l'}, - {0x10, 'm', 'm'}, {0x11, 'n', 'n'}, - {0x12, 'o', 'o'}, {0x13, 'p', 'p'}, - {0x14, 'q', 'q'}, {0x15, 'r', 'r'}, - {0x16, 's', 's'}, {0x17, 't', 't'}, - {0x18, 'u', 'u'}, {0x19, 'v', 'v'}, - {0x1A, 'w', 'w'}, {0x1B, 'x', 'x'}, - {0x1C, 'y', 'y'}, {0x1D, 'z', 'z'}, - {0x1E, '1', '1'}, {0x1F, '2', '2'}, - {0x20, '3', '3'}, {0x21, '4', '4'}, - {0x22, '5', '5'}, {0x23, '6', '6'}, - {0x24, '7', '7'}, {0x25, '8', '8'}, - {0x26, '9', '9'}, {0x27, '0', '0'}, - {0x28, KEY_ENTER, 0}, {0x29, KEY_ESCAPE, 0}, - {0x2A, KEY_BACKSPACE, 0}, {0x2B, KEY_TAB, 0}, - {0x2C, ' ', ' '}, {0x36, ',', ','}, - {0x37, '.', '.'}, {0x4F, KEY_RIGHTARROW, 0}, - {0x50, KEY_LEFTARROW, 0}, {0x51, KEY_DOWNARROW, 0}, - {0x52, KEY_UPARROW, 0}, {0x3A, KEY_F1, 0}, - {0x3B, KEY_F2, 0}, {0x3C, KEY_F3, 0}, - {0x3D, KEY_F4, 0}, {0x3E, KEY_F5, 0}, - {0x3F, KEY_F6, 0}, {0x40, KEY_F7, 0}, - {0x41, KEY_F8, 0}, {0x42, KEY_F9, 0}, - {0x43, KEY_F10, 0}, {0x44, KEY_F11, 0}, + {0x04, 'a', 'a'}, + {0x05, 'b', 'b'}, + {0x06, 'c', 'c'}, + {0x07, 'd', 'd'}, + {0x08, 'e', 'e'}, + {0x09, 'f', 'f'}, + {0x0A, 'g', 'g'}, + {0x0B, 'h', 'h'}, + {0x0C, 'i', 'i'}, + {0x0D, 'j', 'j'}, + {0x0E, 'k', 'k'}, + {0x0F, 'l', 'l'}, + {0x10, 'm', 'm'}, + {0x11, 'n', 'n'}, + {0x12, 'o', 'o'}, + {0x13, 'p', 'p'}, + {0x14, 'q', 'q'}, + {0x15, 'r', 'r'}, + {0x16, 's', 's'}, + {0x17, 't', 't'}, + {0x18, 'u', 'u'}, + {0x19, 'v', 'v'}, + {0x1A, 'w', 'w'}, + {0x1B, 'x', 'x'}, + {0x1C, 'y', 'y'}, + {0x1D, 'z', 'z'}, + {0x1E, '1', '1'}, + {0x1F, '2', '2'}, + {0x20, '3', '3'}, + {0x21, '4', '4'}, + {0x22, '5', '5'}, + {0x23, '6', '6'}, + {0x24, '7', '7'}, + {0x25, '8', '8'}, + {0x26, '9', '9'}, + {0x27, '0', '0'}, + {0x28, KEY_ENTER, 0}, + {0x29, KEY_ESCAPE, 0}, + {0x2A, KEY_BACKSPACE, 0}, + {0x2B, KEY_TAB, 0}, + {0x2C, ' ', ' '}, + {0x36, ',', ','}, + {0x37, '.', '.'}, + {0x4F, KEY_RIGHTARROW, 0}, + {0x50, KEY_LEFTARROW, 0}, + {0x51, KEY_DOWNARROW, 0}, + {0x52, KEY_UPARROW, 0}, + {0x3A, KEY_F1, 0}, + {0x3B, KEY_F2, 0}, + {0x3C, KEY_F3, 0}, + {0x3D, KEY_F4, 0}, + {0x3E, KEY_F5, 0}, + {0x3F, KEY_F6, 0}, + {0x40, KEY_F7, 0}, + {0x41, KEY_F8, 0}, + {0x42, KEY_F9, 0}, + {0x43, KEY_F10, 0}, + {0x44, KEY_F11, 0}, {0x45, KEY_F12, 0}, }; - typedef struct { + + typedef struct + { uint8_t bitmask; int doom; } modmap_t; + static const modmap_t mod_map[] = { - {0x01, KEY_RCTRL}, {0x02, KEY_RSHIFT}, {0x04, KEY_RALT}, - {0x10, KEY_RCTRL}, {0x20, KEY_RSHIFT}, {0x40, KEY_RALT}, + {0x01, KEY_RCTRL}, + {0x02, KEY_RSHIFT}, + {0x04, KEY_RALT}, + {0x10, KEY_RCTRL}, + {0x20, KEY_RSHIFT}, + {0x40, KEY_RALT}, }; static uint8_t last_modifier_byte = 0; static uint8_t previously_pressed_hids[6] = {0}; - if (len < 8) return; + if (len < 8) + return; uint8_t current_modifier_byte = data[0]; int mod_map_size = sizeof(mod_map) / sizeof(mod_map[0]); - for (int i = 0; i < mod_map_size; i++) { + for (int i = 0; i < mod_map_size; i++) + { uint8_t bit = mod_map[i].bitmask; - if ((current_modifier_byte & bit) && !(last_modifier_byte & bit)) { + if ((current_modifier_byte & bit) && !(last_modifier_byte & bit)) + { event_t e = {.type = ev_keydown, .data1 = mod_map[i].doom}; D_PostEvent(&e); - } else if (!(current_modifier_byte & bit) && - (last_modifier_byte & bit)) { + } + else if (!(current_modifier_byte & bit) && + (last_modifier_byte & bit)) + { event_t e = {.type = ev_keyup, .data1 = mod_map[i].doom}; D_PostEvent(&e); } @@ -202,19 +268,28 @@ static void parse_keyboard_report(const uint8_t *data, size_t len) { memcpy(current_pressed_hids, &data[2], sizeof(current_pressed_hids)); int key_map_size = sizeof(key_map) / sizeof(key_map[0]); - for (int i = 0; i < 6; i++) { + for (int i = 0; i < 6; i++) + { uint8_t current_hid = current_pressed_hids[i]; - if (current_hid == 0x00 || current_hid == 0x01) continue; + if (current_hid == 0x00 || current_hid == 0x01) + continue; + bool was_pressed_before = false; - for (int j = 0; j < 6; j++) { - if (previously_pressed_hids[j] == current_hid) { + for (int j = 0; j < 6; j++) + { + if (previously_pressed_hids[j] == current_hid) + { was_pressed_before = true; break; } } - if (!was_pressed_before) { - for (int k = 0; k < key_map_size; k++) { - if (key_map[k].hid == current_hid) { + + if (!was_pressed_before) + { + for (int k = 0; k < key_map_size; k++) + { + if (key_map[k].hid == current_hid) + { event_t e = {.type = ev_keydown, .data1 = key_map[k].doom, .data2 = key_map[k].ascii}; @@ -224,19 +299,29 @@ static void parse_keyboard_report(const uint8_t *data, size_t len) { } } } - for (int i = 0; i < 6; i++) { + + for (int i = 0; i < 6; i++) + { uint8_t previous_hid = previously_pressed_hids[i]; - if (previous_hid == 0x00 || previous_hid == 0x01) continue; + if (previous_hid == 0x00 || previous_hid == 0x01) + continue; + bool still_pressed = false; - for (int j = 0; j < 6; j++) { - if (current_pressed_hids[j] == previous_hid) { + for (int j = 0; j < 6; j++) + { + if (current_pressed_hids[j] == previous_hid) + { still_pressed = true; break; } } - if (!still_pressed) { - for (int k = 0; k < key_map_size; k++) { - if (key_map[k].hid == previous_hid) { + + if (!still_pressed) + { + for (int k = 0; k < key_map_size; k++) + { + if (key_map[k].hid == previous_hid) + { event_t e = {.type = ev_keyup, .data1 = key_map[k].doom}; D_PostEvent(&e); break; @@ -244,35 +329,44 @@ static void parse_keyboard_report(const uint8_t *data, size_t len) { } } } + memcpy(previously_pressed_hids, current_pressed_hids, sizeof(previously_pressed_hids)); } -struct bt_gatt_dm { +struct bt_gatt_dm +{ struct bt_conn *conn; void *context; struct bt_gatt_discover_params discover_params; struct bt_gatt_dm_attr attrs[CONFIG_BT_GATT_DM_MAX_ATTRS]; size_t cur_attr_id; - union { + + union + { struct bt_uuid uuid; struct bt_uuid_16 u16; struct bt_uuid_32 u32; struct bt_uuid_128 u128; } svc_uuid; + sys_slist_t chunk_list; size_t cur_chunk_len; const struct bt_gatt_dm_cb *cb; bool search_svc_by_uuid; }; -static bool is_device_xbox(struct bt_gatt_dm *dm) { +static bool is_device_xbox(struct bt_gatt_dm *dm) +{ const struct bt_uuid *xbox_uuid = BT_UUID_DECLARE_128( BT_UUID_128_ENCODE(BT_UUID_HIDS_REPORT_VAL, 0, 0, 0, 0)); - for (int i = 0; dm->attrs[i].handle != 0; i++) { - if (dm->attrs[i].uuid->type == BT_UUID_TYPE_128) { - if (!bt_uuid_cmp(dm->attrs[i].uuid, xbox_uuid)) { + for (int i = 0; dm->attrs[i].handle != 0; i++) + { + if (dm->attrs[i].uuid->type == BT_UUID_TYPE_128) + { + if (!bt_uuid_cmp(dm->attrs[i].uuid, xbox_uuid)) + { return true; } } @@ -281,34 +375,41 @@ static bool is_device_xbox(struct bt_gatt_dm *dm) { return false; } -static void convert_xbox_uuids(struct bt_gatt_dm *dm) { - for (int i = 0; dm->attrs[i].handle != 0; i++) { - if (dm->attrs[i].uuid->type != BT_UUID_TYPE_128) { +static void convert_xbox_uuids(struct bt_gatt_dm *dm) +{ + for (int i = 0; dm->attrs[i].handle != 0; i++) + { + if (dm->attrs[i].uuid->type != BT_UUID_TYPE_128) + { continue; } if (!bt_uuid_cmp(dm->attrs[i].uuid, BT_UUID_DECLARE_128(BT_UUID_128_ENCODE( - BT_UUID_HIDS_REPORT_MAP_VAL, 0, 0, 0, 0)))) { + BT_UUID_HIDS_REPORT_MAP_VAL, 0, 0, 0, 0)))) + { dm->attrs[i].uuid->type = BT_UUID_TYPE_16; BT_UUID_16(dm->attrs[i].uuid)->val = BT_UUID_HIDS_REPORT_MAP_VAL; - - } else if (!bt_uuid_cmp( - dm->attrs[i].uuid, - BT_UUID_DECLARE_128(BT_UUID_128_ENCODE( - BT_UUID_HIDS_CTRL_POINT_VAL, 0, 0, 0, 0)))) { + } + else if (!bt_uuid_cmp( + dm->attrs[i].uuid, + BT_UUID_DECLARE_128(BT_UUID_128_ENCODE( + BT_UUID_HIDS_CTRL_POINT_VAL, 0, 0, 0, 0)))) + { dm->attrs[i].uuid->type = BT_UUID_TYPE_16; BT_UUID_16(dm->attrs[i].uuid)->val = BT_UUID_HIDS_CTRL_POINT_VAL; - - } else if (!bt_uuid_cmp(dm->attrs[i].uuid, - BT_UUID_DECLARE_128(BT_UUID_128_ENCODE( - BT_UUID_HIDS_REPORT_VAL, 0, 0, 0, 0)))) { + } + else if (!bt_uuid_cmp(dm->attrs[i].uuid, + BT_UUID_DECLARE_128(BT_UUID_128_ENCODE( + BT_UUID_HIDS_REPORT_VAL, 0, 0, 0, 0)))) + { dm->attrs[i].uuid->type = BT_UUID_TYPE_16; BT_UUID_16(dm->attrs[i].uuid)->val = BT_UUID_HIDS_REPORT_VAL; - - } else if (!bt_uuid_cmp(dm->attrs[i].uuid, - BT_UUID_DECLARE_128(BT_UUID_128_ENCODE( - BT_UUID_HIDS_INFO_VAL, 0, 0, 0, 0)))) { + } + else if (!bt_uuid_cmp(dm->attrs[i].uuid, + BT_UUID_DECLARE_128(BT_UUID_128_ENCODE( + BT_UUID_HIDS_INFO_VAL, 0, 0, 0, 0)))) + { dm->attrs[i].uuid->type = BT_UUID_TYPE_16; BT_UUID_16(dm->attrs[i].uuid)->val = BT_UUID_HIDS_INFO_VAL; } @@ -317,37 +418,44 @@ static void convert_xbox_uuids(struct bt_gatt_dm *dm) { static uint8_t hogp_notify_cb(struct bt_hogp *hogp_ctx, struct bt_hogp_rep_info *rep, uint8_t err, - const uint8_t *data) { - if (err || !data) { + const uint8_t *data) +{ + if (err || !data) + { return BT_GATT_ITER_STOP; } - switch (current_device_type) { - case DEVICE_TYPE_XBOX: - parse_xbox_report(data, bt_hogp_rep_size(rep)); - break; - case DEVICE_TYPE_KEYBOARD: - parse_keyboard_report(data, bt_hogp_rep_size(rep)); - break; - default: - break; + switch (current_device_type) + { + case DEVICE_TYPE_XBOX: + parse_xbox_report(data, bt_hogp_rep_size(rep)); + break; + case DEVICE_TYPE_KEYBOARD: + parse_keyboard_report(data, bt_hogp_rep_size(rep)); + break; + default: + break; } return BT_GATT_ITER_CONTINUE; } -static void discovery_completed_cb(struct bt_gatt_dm *dm, void *context) { +static void discovery_completed_cb(struct bt_gatt_dm *dm, void *context) +{ printk("Discovery completed.\n"); k_timer_stop(&blink_timer); - if (is_device_xbox(dm)) { + if (is_device_xbox(dm)) + { printk("Device identified as: XBOX Controller\n"); current_device_type = DEVICE_TYPE_XBOX; convert_xbox_uuids(dm); gpio_pin_set_dt(&led1, 1); gpio_pin_set_dt(&led2, 0); - } else { + } + else + { printk("Device identified as: Standard Keyboard\n"); current_device_type = DEVICE_TYPE_KEYBOARD; @@ -356,7 +464,8 @@ static void discovery_completed_cb(struct bt_gatt_dm *dm, void *context) { } int err = bt_hogp_handles_assign(dm, &hogp); - if (err) { + if (err) + { printk("Could not init HIDS client object, error: %d\n", err); } @@ -364,12 +473,14 @@ static void discovery_completed_cb(struct bt_gatt_dm *dm, void *context) { } static void discovery_service_not_found_cb(struct bt_conn *conn, - void *context) { + void *context) +{ printk("HIDS service not found.\n"); k_timer_start(&blink_timer, K_MSEC(BLINK_INTERVAL_MS), K_MSEC(BLINK_INTERVAL_MS)); } -static void discovery_error_cb(struct bt_conn *conn, int err, void *context) { +static void discovery_error_cb(struct bt_conn *conn, int err, void *context) +{ printk("Discovery failed, error: %d\n", err); k_timer_start(&blink_timer, K_MSEC(BLINK_INTERVAL_MS), K_MSEC(BLINK_INTERVAL_MS)); } @@ -380,49 +491,65 @@ static const struct bt_gatt_dm_cb discovery_callbacks = { .error_found = discovery_error_cb, }; -static void gatt_discover(struct bt_conn *conn) { +static void gatt_discover(struct bt_conn *conn) +{ int err = bt_gatt_dm_start(conn, BT_UUID_HIDS, &discovery_callbacks, NULL); - if (err) { + if (err) + { printk("Could not start discovery, error: %d\n", err); } } static void security_changed(struct bt_conn *conn, bt_security_t level, - enum bt_security_err err) { - if (err) { + enum bt_security_err err) +{ + if (err) + { printk("Security failed: level %u, err %d\n", level, err); return; } + printk("Security changed: level %u\n", level); gatt_discover(conn); } -static void connected(struct bt_conn *conn, uint8_t conn_err) { - if (conn_err) { +static void connected(struct bt_conn *conn, uint8_t conn_err) +{ + if (conn_err) + { printk("Connection failed (err %u)\n", conn_err); - if (default_conn) { + + if (default_conn) + { bt_conn_unref(default_conn); default_conn = NULL; } + bt_scan_start(BT_SCAN_TYPE_SCAN_ACTIVE); return; } + printk("Connected.\n"); default_conn = bt_conn_ref(conn); int err = bt_conn_set_security(conn, BT_SECURITY_L2); - if (err) { + if (err) + { printk("Failed to set security: %d\n", err); gatt_discover(conn); } } -static void disconnected(struct bt_conn *conn, uint8_t reason) { +static void disconnected(struct bt_conn *conn, uint8_t reason) +{ printk("Disconnected (reason 0x%02x)\n", reason); - if (bt_hogp_assign_check(&hogp)) { + if (bt_hogp_assign_check(&hogp)) + { bt_hogp_release(&hogp); } - if (default_conn == conn) { + + if (default_conn == conn) + { bt_conn_unref(default_conn); default_conn = NULL; current_device_type = DEVICE_TYPE_NONE; @@ -442,31 +569,40 @@ BT_CONN_CB_DEFINE(conn_callbacks) = { .security_changed = security_changed, }; -static void hids_on_ready(struct k_work *work) { +static void hids_on_ready(struct k_work *work) +{ printk("HIDS is ready. Subscribing to reports...\n"); struct bt_hogp_rep_info *rep = NULL; - while (NULL != (rep = bt_hogp_rep_next(&hogp, rep))) { - if (bt_hogp_rep_type(rep) == BT_HIDS_REPORT_TYPE_INPUT) { + while (NULL != (rep = bt_hogp_rep_next(&hogp, rep))) + { + if (bt_hogp_rep_type(rep) == BT_HIDS_REPORT_TYPE_INPUT) + { int err = bt_hogp_rep_subscribe(&hogp, rep, hogp_notify_cb); - if (err) { + if (err) + { printk("Subscribe error (%d) for report id %u\n", err, bt_hogp_rep_id(rep)); - } else { + } + else + { printk("Subscribed to report id %u\n", bt_hogp_rep_id(rep)); } } } } -static void hogp_ready_cb(struct bt_hogp *hogp_ctx) { +static void hogp_ready_cb(struct bt_hogp *hogp_ctx) +{ k_work_submit(&hids_ready_work); } -static void hogp_prep_fail_cb(struct bt_hogp *hogp_ctx, int err) { +static void hogp_prep_fail_cb(struct bt_hogp *hogp_ctx, int err) +{ printk("ERROR: HIDS client preparation failed (%d)!\n", err); } -static void scan_init(void) { +static void scan_init(void) +{ struct bt_scan_init_param scan_init_param = {.connect_if_match = 1}; bt_scan_init(&scan_init_param); BT_SCAN_CB_INIT(scan_callbacks, NULL, NULL, NULL, NULL); @@ -475,24 +611,35 @@ static void scan_init(void) { bt_scan_filter_enable(BT_SCAN_UUID_FILTER, false); } -static void num_comp_reply(bool accept) { - if (accept) { +static void num_comp_reply(bool accept) +{ + if (accept) + { bt_conn_auth_passkey_confirm(auth_conn); - } else { + } + else + { bt_conn_auth_cancel(auth_conn); } + bt_conn_unref(auth_conn); auth_conn = NULL; } -static void button_handler(uint32_t button_state, uint32_t has_changed) { - if (auth_conn) { - if (has_changed & button_state & DK_BTN1_MSK) num_comp_reply(true); - if (has_changed & button_state & DK_BTN2_MSK) num_comp_reply(false); +static void button_handler(uint32_t button_state, uint32_t has_changed) +{ + if (auth_conn) + { + if (has_changed & button_state & DK_BTN1_MSK) + num_comp_reply(true); + + if (has_changed & button_state & DK_BTN2_MSK) + num_comp_reply(false); } } -static void auth_passkey_confirm(struct bt_conn *conn, unsigned int passkey) { +static void auth_passkey_confirm(struct bt_conn *conn, unsigned int passkey) +{ char addr[BT_ADDR_LE_STR_LEN]; bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); printk("Passkey for %s: %06u\n", addr, passkey); @@ -500,7 +647,8 @@ static void auth_passkey_confirm(struct bt_conn *conn, unsigned int passkey) { auth_conn = bt_conn_ref(conn); } -static void auth_cancel(struct bt_conn *conn) { +static void auth_cancel(struct bt_conn *conn) +{ printk("Pairing cancelled.\n"); } @@ -509,24 +657,31 @@ static struct bt_conn_auth_cb auth_callbacks = { .cancel = auth_cancel, }; -int bluetooth_control_init(void) { +int bluetooth_control_init(void) +{ int err; printk("Initializing Unified Bluetooth Controller\n"); - if (!gpio_is_ready_dt(&led1) || !gpio_is_ready_dt(&led2)) { + if (!gpio_is_ready_dt(&led1) || !gpio_is_ready_dt(&led2)) + { printk("Error: LED device(s) are not ready\n"); return -ENODEV; } + err = gpio_pin_configure_dt(&led1, GPIO_OUTPUT_INACTIVE); - if (err) { + if (err) + { printk("Error %d: failed to configure LED1 pin\n", err); return err; } + err = gpio_pin_configure_dt(&led2, GPIO_OUTPUT_INACTIVE); - if (err) { + if (err) + { printk("Error %d: failed to configure LED2 pin\n", err); return err; } + k_timer_start(&blink_timer, K_MSEC(BLINK_INTERVAL_MS), K_MSEC(BLINK_INTERVAL_MS)); @@ -534,28 +689,34 @@ int bluetooth_control_init(void) { .ready_cb = hogp_ready_cb, .prep_error_cb = hogp_prep_fail_cb, }; + bt_hogp_init(&hogp, &hogp_init_params); err = bt_conn_auth_cb_register(&auth_callbacks); - if (err) { + if (err) + { printk("Failed to register authorization callbacks.\n"); return err; } err = dk_buttons_init(button_handler); - if (err) { + if (err) + { printk("Failed to initialize buttons (err %d)\n", err); return err; } err = bt_enable(NULL); - if (err) { + if (err) + { printk("Bluetooth init failed (err %d)\n", err); return err; } + printk("Bluetooth initialized\n"); - if (IS_ENABLED(CONFIG_SETTINGS)) { + if (IS_ENABLED(CONFIG_SETTINGS)) + { settings_load(); printk("Settings loaded.\n"); } @@ -563,10 +724,12 @@ int bluetooth_control_init(void) { scan_init(); err = bt_scan_start(BT_SCAN_TYPE_SCAN_ACTIVE); - if (err) { + if (err) + { printk("Scanning failed to start (err %d)\n", err); return err; } + printk("Scanning successfully started\n"); return 0; } diff --git a/zephyrdoom/src/bluetooth_control.h b/zephyrdoom/src/bluetooth_control.h index a5dbef4..51b78f3 100644 --- a/zephyrdoom/src/bluetooth_control.h +++ b/zephyrdoom/src/bluetooth_control.h @@ -3,4 +3,4 @@ int bluetooth_control_init(void); -#endif +#endif /* BLUETOOTH_CONTROL_H__ */ diff --git a/zephyrdoom/src/d_dedicated.c b/zephyrdoom/src/d_dedicated.c index 3919a62..d485648 100644 --- a/zephyrdoom/src/d_dedicated.c +++ b/zephyrdoom/src/d_dedicated.c @@ -1,18 +1,19 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// Code specific to the standalone dedicated server. -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Code specific to the standalone dedicated server. + */ #include #include @@ -29,11 +30,12 @@ void NET_CL_Run(void) { - // No client present :-) - // - // This is here because the server code sometimes runs this - // to let the client do some processing if it needs to. - // In a standalone dedicated server, we don't have a client. + /* + * No client present. + * This is here because the server code sometimes runs this + * to let the client do some processing if it needs to. + * In a standalone dedicated server, we don't have a client. + */ } void D_DoomMain(void) diff --git a/zephyrdoom/src/d_event.c b/zephyrdoom/src/d_event.c index 0099742..ba7268e 100644 --- a/zephyrdoom/src/d_event.c +++ b/zephyrdoom/src/d_event.c @@ -1,23 +1,22 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// -// DESCRIPTION: Event handling. -// -// Events are asynchronous inputs generally generated by the game user. -// Events can be discarded if no responder claims them -// +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Event handling. + * Events are asynchronous inputs generally generated by the game user. + * Events can be discarded if no responder claims them. + */ #include #include "d_event.h" @@ -28,24 +27,19 @@ static event_t events[MAXEVENTS]; static int eventhead; static int eventtail; -// -// D_PostEvent -// Called by the I/O functions when input is detected -// -void D_PostEvent (event_t* ev) +/* Called by the I/O functions when input is detected. */ +void D_PostEvent(event_t *ev) { events[eventhead] = *ev; eventhead = (eventhead + 1) % MAXEVENTS; } -// Read an event from the queue. - +/* Read an event from the queue. */ event_t *D_PopEvent(void) { event_t *result; - // No more events waiting. - + /* No more events waiting */ if (eventtail == eventhead) { return NULL; @@ -53,8 +47,7 @@ event_t *D_PopEvent(void) result = &events[eventtail]; - // Advance to the next event in the queue. - + /* Advance to the next event in the queue */ eventtail = (eventtail + 1) % MAXEVENTS; return result; diff --git a/zephyrdoom/src/d_event.h b/zephyrdoom/src/d_event.h index 1a68d28..882bd7b 100644 --- a/zephyrdoom/src/d_event.h +++ b/zephyrdoom/src/d_event.h @@ -1,146 +1,143 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// -// - +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Event handling. + */ #ifndef __D_EVENT__ #define __D_EVENT__ - #include "doomtype.h" - -// -// Event handling. -// - -// Input event types. +/* Input event types. */ typedef enum { - // Key press/release events. - // data1: Key code (from doomkeys.h) of the key that was - // pressed or released. This is the key as it appears - // on a US keyboard layout, and does not change with - // layout. - // For ev_keydown only: - // data2: ASCII representation of the key that was pressed that - // changes with the keyboard layout; eg. if 'Z' is - // pressed on a German keyboard, data1='y',data2='z'. - // Not affected by modifier keys. - // data3: ASCII input, fully modified according to keyboard - // layout and any modifier keys that are held down. - // Only set if I_StartTextInput() has been called. + /* + * Key press/release events: + * data1 - Key code (from doomkeys.h) of the key that was + * pressed or released. This is the key as it appears + * on a US keyboard layout, and does not change with + * layout. + * + * For ev_keydown only: + * data2 - ASCII representation of the key that was pressed that + * changes with the keyboard layout; e.g. if 'Z' is + * pressed on a German keyboard, data1='y',data2='z'. + * Not affected by modifier keys. + * data3 - ASCII input, fully modified according to keyboard + * layout and any modifier keys that are held down. + * Only set if I_StartTextInput() has been called. + */ ev_keydown, ev_keyup, - // Mouse movement event. - // data1: Bitfield of buttons currently held down. - // (bit 0 = left; bit 1 = right; bit 2 = middle). - // data2: X axis mouse movement (turn). - // data3: Y axis mouse movement (forward/backward). + /* + * Mouse movement event: + * data1 - Bitfield of buttons currently held down + * (bit 0 = left; bit 1 = right; bit 2 = middle). + * data2 - X axis mouse movement (turn). + * data3 - Y axis mouse movement (forward/backward). + */ ev_mouse, - // Joystick state. - // data1: Bitfield of buttons currently pressed. - // data2: X axis mouse movement (turn). - // data3: Y axis mouse movement (forward/backward). - // data4: Third axis mouse movement (strafe). - // data5: Fourth axis mouse movement (look) + /* + * Joystick state: + * data1 - Bitfield of buttons currently pressed. + * data2 - X axis mouse movement (turn). + * data3 - Y axis mouse movement (forward/backward). + * data4 - Third axis mouse movement (strafe). + * data5 - Fourth axis mouse movement (look) + */ ev_joystick, - // Quit event. Triggered when the user clicks the "close" button - // to terminate the application. + /* + * Quit event. Triggered when the user clicks the "close" button + * to terminate the application. + */ ev_quit } evtype_t; -// Event structure. +/* Event structure. */ typedef struct __attribute__((packed)) { evtype_t type; - // Event-specific data; see the descriptions given above. - // NRFD-NOTE: Changed from int to short + /* + * Event-specific data; see the descriptions given above. + * NRFD-NOTE: Changed from int to short. + */ short data1, data2, data3, data4, data5; } event_t; - -// -// Button/action code definitions. -// +/* Button/action code definitions. */ typedef enum { - // Press "Fire". - BT_ATTACK = 1, - // Use button, to open doors, activate switches. - BT_USE = 2, - - // Flag: game events, not really buttons. - BT_SPECIAL = 128, - BT_SPECIALMASK = 3, - - // Flag, weapon change pending. - // If true, the next 3 bits hold weapon num. - BT_CHANGE = 4, - // The 3bit weapon mask and shift, convenience. - BT_WEAPONMASK = (8+16+32), - BT_WEAPONSHIFT = 3, - - // Pause the game. - BTS_PAUSE = 1, - // Save the game at each console. - BTS_SAVEGAME = 2, - - // Savegame slot numbers - // occupy the second byte of buttons. - BTS_SAVEMASK = (4+8+16), - BTS_SAVESHIFT = 2, - + /* Press "Fire" */ + BT_ATTACK = 1, + /* Use button, to open doors, activate switches */ + BT_USE = 2, + + /* Flag game events, not really buttons */ + BT_SPECIAL = 128, + BT_SPECIALMASK = 3, + + /* + * Flag, weapon change pending. + * If true, the next 3 bits hold weapon num. + */ + BT_CHANGE = 4, + /* The 3bit weapon mask and shift, convenience */ + BT_WEAPONMASK = (8 + 16 + 32), + BT_WEAPONSHIFT = 3, + + /* Pause the game */ + BTS_PAUSE = 1, + /* Save the game at each console */ + BTS_SAVEGAME = 2, + + /* Savegame slot numbers occupy the second byte of buttons */ + BTS_SAVEMASK = (4 + 8 + 16), + BTS_SAVESHIFT = 2 } buttoncode_t; -// villsa [STRIFE] Strife specific buttons -// TODO - not finished +/* + * villsa [STRIFE] Strife specific buttons + * TODO - not finished + */ typedef enum { - // Player view look up - BT2_LOOKUP = 1, - // Player view look down - BT2_LOOKDOWN = 2, - // Center player's view - BT2_CENTERVIEW = 4, - // Use inventory item - BT2_INVUSE = 8, - // Drop inventory item - BT2_INVDROP = 16, - // Jump up and down - BT2_JUMP = 32, - // Use medkit - BT2_HEALTH = 128, - + /* Player view look up */ + BT2_LOOKUP = 1, + /* Player view look down */ + BT2_LOOKDOWN = 2, + /* Center player's view */ + BT2_CENTERVIEW = 4, + /* Use inventory item */ + BT2_INVUSE = 8, + /* Drop inventory item */ + BT2_INVDROP = 16, + /* Jump up and down */ + BT2_JUMP = 32, + /* Use medkit */ + BT2_HEALTH = 128 } buttoncode2_t; +/* Called by IO functions when input is detected. */ +void D_PostEvent(event_t *ev); - - -// Called by IO functions when input is detected. -void D_PostEvent (event_t *ev); - -// Read an event from the event queue - +/* Read an event from the event queue. */ event_t *D_PopEvent(void); - -#endif +#endif /* __D_EVENT__ */ diff --git a/zephyrdoom/src/d_iwad.c b/zephyrdoom/src/d_iwad.c index 83040da..b4a90df 100644 --- a/zephyrdoom/src/d_iwad.c +++ b/zephyrdoom/src/d_iwad.c @@ -1,20 +1,20 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Search for and locate an IWAD file, and initialize according -// to the IWAD type. -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Search for and locate an IWAD file, and initialize according + * to the IWAD type. + */ #include #include @@ -37,89 +37,91 @@ #include "n_mem.h" #include "n_fs.h" -static const iwad_t iwads[] = -{ - { "doom.wad", doom, retail, "Doom" }, - { "doom1.wad", doom, shareware, "Doom Shareware" }, - { "doom2.wad", doom2, commercial, "Doom II" }, +static const iwad_t iwads[] = { + {"doom.wad", doom, retail, "Doom"}, + {"doom1.wad", doom, shareware, "Doom Shareware"}, + {"doom2.wad", doom2, commercial, "Doom II"} + /* - { "plutonia.wad", pack_plut, commercial, "Final Doom: Plutonia Experiment" }, - { "tnt.wad", pack_tnt, commercial, "Final Doom: TNT: Evilution" }, - { "chex.wad", pack_chex, retail, "Chex Quest" }, - { "hacx.wad", pack_hacx, commercial, "Hacx" }, - { "freedm.wad", doom2, commercial, "FreeDM" }, - { "freedoom2.wad", doom2, commercial, "Freedoom: Phase 2" }, - { "freedoom1.wad", doom, retail, "Freedoom: Phase 1" }, - { "heretic.wad", heretic, retail, "Heretic" }, - { "heretic1.wad", heretic, shareware, "Heretic Shareware" }, - { "hexen.wad", hexen, commercial, "Hexen" }, - //{ "strife0.wad", strife, commercial, "Strife" }, // haleyjd: STRIFE-FIXME - { "strife1.wad", strife, commercial, "Strife" },*/ + * { "plutonia.wad", pack_plut, commercial, "Final Doom: Plutonia Experiment" } + * { "tnt.wad", pack_tnt, commercial, "Final Doom: TNT: Evilution" } + * { "chex.wad", pack_chex, retail, "Chex Quest" } + * { "hacx.wad", pack_hacx, commercial, "Hacx" } + * { "freedm.wad", doom2, commercial, "FreeDM" } + * { "freedoom2.wad", doom2, commercial, "Freedoom: Phase 2" } + * { "freedoom1.wad", doom, retail, "Freedoom: Phase 1" } + * { "heretic.wad", heretic, retail, "Heretic" } + * { "heretic1.wad", heretic, shareware, "Heretic Shareware" } + * { "hexen.wad", hexen, commercial, "Hexen" } + * { "strife1.wad", strife, commercial, "Strife" } + */ }; -// Array of locations to search for IWAD files -// -// "128 IWAD search directories should be enough for anybody". - -/* NRFD-TODO? -#define MAX_IWAD_DIRS 128 - -static boolean iwad_dirs_built = false; -static char *iwad_dirs[MAX_IWAD_DIRS]; -static int num_iwad_dirs = 0; -*/ +/* + * Array of locations to search for IWAD files. + * 128 IWAD search directories should be enough for anybody. + */ +/* + * NRFD-TODO + * #define MAX_IWAD_DIRS 128 + * + * static boolean iwad_dirs_built = false; + * static char *iwad_dirs[MAX_IWAD_DIRS]; + * static int num_iwad_dirs = 0; + */ static void AddIWADDir(char *dir) { - /* NRFD_TODO? - if (num_iwad_dirs < MAX_IWAD_DIRS) - { - iwad_dirs[num_iwad_dirs] = dir; - ++num_iwad_dirs; - } - */ + /* + * NRFD-TODO + * if (num_iwad_dirs < MAX_IWAD_DIRS) { + * iwad_dirs[num_iwad_dirs] = dir; + * ++num_iwad_dirs; + * } + */ } - -// Check if the specified directory contains the specified IWAD -// file, returning the full path to the IWAD if found, or NULL -// if not found. - +/* + * Check if the specified directory contains the specified IWAD + * file, returning the full path to the IWAD if found, or NULL + * if not found. + */ static char *CheckDirectoryHasIWAD(char *dir, char *iwadname) { char *filename; char *probe; - // As a special case, the "directory" may refer directly to an - // IWAD file if the path comes from DOOMWADDIR or DOOMWADPATH. - - // probe = M_FileCaseExists(dir); - // if (DirIsFile(dir, iwadname) && probe != NULL) - // { - // return probe; - // } - - // Construct the full path to the IWAD if it is located in - // this directory, and check if it exists. - -/* NRFD-TODO? - if (!strcmp(dir, ".")) - { - filename = M_StringDuplicate(iwadname); - } - else - { - filename = M_StringJoin(dir, DIR_SEPARATOR_S, iwadname, NULL); - } + /* + * As a special case, the "directory" may refer directly to an + * IWAD file if the path comes from DOOMWADDIR or DOOMWADPATH. + */ + /* + * probe = M_FileCaseExists(dir); + * if (DirIsFile(dir, iwadname) && probe != NULL) { + * return probe; + * } + */ - probe = M_FileCaseExists(filename); - if (probe != NULL) - { - return probe; - } + /* + * Construct the full path to the IWAD if it is located in + * this directory, and check if it exists. + */ + /* + * NRFD-TODO + * if (!strcmp(dir, ".")) { + * filename = M_StringDuplicate(iwadname); + * } else { + * filename = M_StringJoin(dir, DIR_SEPARATOR_S, iwadname, NULL); + * } + * + * probe = M_FileCaseExists(filename); + * if (probe != NULL) { + * return probe; + * } + * + * free(filename); + */ - free(filename); - */ probe = M_FileCaseExists(iwadname); if (probe != NULL) { @@ -129,15 +131,17 @@ static char *CheckDirectoryHasIWAD(char *dir, char *iwadname) return NULL; } -// Search a directory to try to find an IWAD -// Returns the location of the IWAD if found, otherwise NULL. - -static char *SearchDirectoryForIWAD(char *dir, int mask, GameMission_t *mission) +/* + * Search a directory to try to find an IWAD. + * Returns the location of the IWAD if found, otherwise NULL. + */ +static char *SearchDirectoryForIWAD(char *dir, int mask, + GameMission_t *mission) { char *filename; size_t i; - for (i=0; i // - iwadparm = M_CheckParmWithArgs("-iwad", 1); if (iwadparm) { - // Search through IWAD dirs for an IWAD with the given name. - + /* Search through IWAD dirs for an IWAD with the given name */ iwadfile = myargv[iwadparm + 1]; result = D_FindWADByName(iwadfile); @@ -338,26 +325,26 @@ char *D_FindIWAD(int mask, GameMission_t *mission) } else { - // Search through the list and look for an IWAD - + /* Search through the list and look for an IWAD */ result = NULL; - /* NRFD-TODO? - BuildIWADDirList(); + /* + * NRFD-TODO + * BuildIWADDirList(); + * + * for (i=0; result == NULL && i #include @@ -35,91 +35,88 @@ #include "net_io.h" #include "net_query.h" #include "net_server.h" -//#include "net_sdl.h" #include "net_loop.h" -// The complete set of data for a particular tic. +/* TODO - Move nonvanilla demo functions into a dedicated file */ +#include "m_misc.h" +#include "w_wad.h" -typedef struct __attribute__((packed)) +/* The complete set of data for a particular tic. */ +typedef struct __attribute__((packed)) { ticcmd_t cmds[NET_MAXPLAYERS]; boolean ingame[NET_MAXPLAYERS]; } ticcmd_set_t; -// Maximum time that we wait in TryRunTics() for netgame data to be -// received before we bail out and render a frame anyway. -// Vanilla Doom used 20 for this value, but we use a smaller value -// instead for better responsiveness of the menu when we're stuck. -#define MAX_NETGAME_STALL_TICS 5 - -// -// gametic is the tic about to (or currently being) run -// maketic is the tic that hasn't had control made for it yet -// recvtic is the latest tic received from the server. -// -// a gametic cannot be run until ticcmds are received for it -// from all players. -// +/* + * Maximum time that we wait in TryRunTics() for netgame data to be + * received before we bail out and render a frame anyway. + * Vanilla Doom used 20 for this value, but we use a smaller value + * instead for better responsiveness of the menu when we're stuck. + */ +#define MAX_NETGAME_STALL_TICS 5 +/* + * gametic is the tic about to (or currently being) run. + * maketic is the tic that hasn't had control made for it yet. + * recvtic is the latest tic received from the server. + * + * A gametic cannot be run until ticcmds are received for it + * from all players. + */ static ticcmd_set_t ticdata[BACKUPTICS]; -// The index of the next tic to be made (with a call to BuildTiccmd). - +/* The index of the next tic to be made (with a call to BuildTiccmd). */ static int maketic; -// The number of complete tics received from the server so far. - +/* The number of complete tics received from the server so far. */ static int recvtic; -// The number of tics that have been run (using RunTic) so far. - +/* The number of tics that have been run (using RunTic) so far. */ int gametic; -// When set to true, a single tic is run each time TryRunTics() is called. -// This is used for -timedemo mode. - +/* + * When set to true, a single tic is run each time TryRunTics() is called. + * This is used for -timedemo mode. + */ boolean singletics = false; -// Index of the local player. - +/* Index of the local player. */ static int localplayer; -// Used for original sync code. - -static int skiptics = 0; - -// Reduce the bandwidth needed by sampling game input less and transmitting -// less. If ticdup is 2, sample half normal, 3 = one third normal, etc. - -int ticdup; +/* Used for original sync code. */ +static int skiptics = 0; -// Amount to offset the timer for game sync. - -fixed_t offsetms; - -// Use new client syncronisation code +/* + * Reduce the bandwidth needed by sampling game input less and transmitting + * less. If ticdup is 2, sample half normal, 3 = one third normal, etc. + */ +int ticdup; -static boolean new_sync = true; +/* Amount to offset the timer for game sync. */ +fixed_t offsetms; -// Callback functions for loop code. +/* Use new client syncronisation code. */ +static boolean new_sync = true; +/* Callback functions for loop code. */ static loop_interface_t *loop_interface = NULL; -// Current players in the multiplayer game. -// This is distinct from playeringame[] used by the game code, which may -// modify playeringame[] when playing back multiplayer demos. - +/* + * Current players in the multiplayer game. + * This is distinct from playeringame[] used by the game code, which may + * modify playeringame[] when playing back multiplayer demos. + */ static boolean local_playeringame[NET_MAXPLAYERS]; -// Requested player class "sent" to the server on connect. -// If we are only doing a single player game then this needs to be remembered -// and saved in the game settings. - +/* + * Requested player class "sent" to the server on connect. + * If we are only doing a single player game then this needs to be remembered + * and saved in the game settings. + */ static int player_class; - -// 35 fps clock adjusted by offsetms milliseconds - +/* 35 fps clock adjusted by offsetms milliseconds. */ static int GetAdjustedTime(void) { int time_ms; @@ -128,9 +125,10 @@ static int GetAdjustedTime(void) if (new_sync) { - // Use the adjustments from net_client.c only if we are - // using the new sync mode. - + /* + * Use the adjustments from net_client.c only if we are + * using the new sync mode. + */ time_ms += (offsetms / FRACUNIT); } int adjusted_time = (time_ms * TICRATE) / 1000; @@ -141,42 +139,36 @@ static boolean BuildNewTic(void) { int gameticdiv; ticcmd_t cmd; - gameticdiv = gametic/ticdup; + gameticdiv = gametic / ticdup; - I_StartTic (); + I_StartTic(); loop_interface->ProcessEvents(); - // Always run the menu - + /* Always run the menu */ loop_interface->RunMenu(); if (drone) { - // In drone mode, do not generate any ticcmds. - + /* In drone mode, do not generate any ticcmds */ return false; } if (new_sync) { - // If playing single player, do not allow tics to buffer - // up very far - - if (!net_client_connected && maketic - gameticdiv > 2) - return false; + /* If playing single player, do not allow tics to buffer up very far */ + if (!net_client_connected && maketic - gameticdiv > 2) + return false; - // Never go more than ~200ms ahead - - if (maketic - gameticdiv > 8) - return false; + /* Never go more than ~200ms ahead */ + if (maketic - gameticdiv > 8) + return false; } else { - if (maketic - gameticdiv >= 5) - return false; + if (maketic - gameticdiv >= 5) + return false; } - //printf ("mk:%i ",maketic); memset(&cmd, 0, sizeof(ticcmd_t)); loop_interface->BuildTiccmd(&cmd, maketic); @@ -193,30 +185,27 @@ static boolean BuildNewTic(void) return true; } -// -// NetUpdate -// Builds ticcmds for console player, -// sends out a packet -// -int lasttime; +int lasttime; -void NetUpdate (void) +/* Builds ticcmds for console player, sends out a packet. */ +void NetUpdate(void) { int nowtime; int newtics; int i; - // If we are running with singletics (timing a demo), this - // is all done separately. - + /* + * If we are running with singletics (timing a demo), this + * is all done separately. + */ if (singletics) return; - // Run network subsystems + /* Run network subsystems */ NET_CL_Run(); NET_SV_Run(); - // check time + /* Check time */ nowtime = GetAdjustedTime() / ticdup; newtics = nowtime - lasttime; lasttime = nowtime; @@ -232,8 +221,8 @@ void NetUpdate (void) newtics = 0; } - // build new ticcmds for console player - for (i=0 ; inew_sync = 0; - // TODO: New sync code is not enabled by default because it's - // currently broken. - //if (M_CheckParm("-oldsync") > 0) - // settings->new_sync = 0; - //else - // settings->new_sync = 1; + /* + * TODO - New sync code is not enabled by default because it's + * currently broken. + * if (M_CheckParm("-oldsync") > 0) + * settings->new_sync = 0; + * else + * settings->new_sync = 1; + */ //! // @category net @@ -372,11 +355,10 @@ void D_StartNetGame(net_gamesettings_t *settings, // Send n extra tics in every packet as insurance against dropped // packets. // - i = M_CheckParmWithArgs("-extratics", 1); if (i > 0) - settings->extratics = atoi(myargv[i+1]); + settings->extratics = atoi(myargv[i + 1]); else settings->extratics = 1; @@ -387,24 +369,23 @@ void D_StartNetGame(net_gamesettings_t *settings, // Reduce the resolution of the game by a factor of n, reducing // the amount of network bandwidth needed. // - i = M_CheckParmWithArgs("-dup", 1); if (i > 0) - settings->ticdup = atoi(myargv[i+1]); + settings->ticdup = atoi(myargv[i + 1]); else settings->ticdup = 1; if (net_client_connected) { - // Send our game settings and block until game start is received - // from the server. - + /* + * Send our game settings and block until game start is received + * from the server. + */ NET_CL_StartGame(settings); BlockUntilStart(settings, callback); - // Read the game settings that were received. - + /* Read the game settings that were received */ NET_CL_GetSettings(settings); } @@ -413,8 +394,7 @@ void D_StartNetGame(net_gamesettings_t *settings, settings->consoleplayer = 0; } - // Set the local player and playeringame[] values. - + /* Set the local player and playeringame[] values */ localplayer = settings->consoleplayer; for (i = 0; i < NET_MAXPLAYERS; ++i) @@ -422,131 +402,127 @@ void D_StartNetGame(net_gamesettings_t *settings, local_playeringame[i] = i < settings->num_players; } - // Copy settings to global variables. - + /* Copy settings to global variables */ ticdup = settings->ticdup; new_sync = settings->new_sync; - // TODO: Message disabled until we fix new_sync. - //if (!new_sync) - //{ - // printf("Syncing netgames like Vanilla Doom.\n"); - //} + /* + * TODO - Message disabled until we fix new_sync. + * if (!new_sync) + * { + * printf("Syncing netgames like Vanilla Doom.\n"); + * } + */ } boolean D_InitNetGame(net_connect_data_t *connect_data) { - printf("NRFD-TODO: D_InitNetGame\n"); -/* - boolean result = false; - net_addr_t *addr = NULL; - int i; - - // Call D_QuitNetGame on exit: - - I_AtExit(D_QuitNetGame, true); - - player_class = connect_data->player_class; - - //! - // @category net - // - // Start a multiplayer server, listening for connections. - // - - if (M_CheckParm("-server") > 0 - || M_CheckParm("-privateserver") > 0) - { - NET_SV_Init(); - NET_SV_AddModule(&net_loop_server_module); - NET_SV_AddModule(&net_sdl_module); - NET_SV_RegisterWithMaster(); - - net_loop_client_module.InitClient(); - addr = net_loop_client_module.ResolveAddress(NULL); - } - else - { - //! - // @category net - // - // Automatically search the local LAN for a multiplayer - // server and join it. - // - - i = M_CheckParm("-autojoin"); - - if (i > 0) - { - addr = NET_FindLANServer(); - - if (addr == NULL) - { - I_Error("No server found on local LAN"); - } - } - - //! - // @arg
- // @category net - // - // Connect to a multiplayer server running on the given - // address. - // - - i = M_CheckParmWithArgs("-connect", 1); - - if (i > 0) - { - net_sdl_module.InitClient(); - addr = net_sdl_module.ResolveAddress(myargv[i+1]); - - if (addr == NULL) - { - I_Error("Unable to resolve '%s'\n", myargv[i+1]); - } - } - } - - if (addr != NULL) - { - if (M_CheckParm("-drone") > 0) - { - connect_data->drone = true; - } - - if (!NET_CL_Connect(addr, connect_data)) - { - I_Error("D_InitNetGame: Failed to connect to %s\n", - NET_AddrToString(addr)); - } - - printf("D_InitNetGame: Connected to %s\n", NET_AddrToString(addr)); - - // Wait for launch message received from server. - - NET_WaitForLaunch(); - - result = true; - } - - return result; - */ return false; + /* + * boolean result = false; + * net_addr_t *addr = NULL; + * int i; + * + * // Call D_QuitNetGame on exit + * I_AtExit(D_QuitNetGame, true); + * + * player_class = connect_data->player_class; + * + * //! + * // @category net + * // + * // Start a multiplayer server, listening for connections. + * // + * + * if (M_CheckParm("-server") > 0 || + * M_CheckParm("-privateserver") > 0) + * { + * NET_SV_Init(); + * NET_SV_AddModule(&net_loop_server_module); + * NET_SV_AddModule(&net_sdl_module); + * NET_SV_RegisterWithMaster(); + * + * net_loop_client_module.InitClient(); + * addr = net_loop_client_module.ResolveAddress(NULL); + * } + * else + * { + * //! + * // @category net + * // + * // Automatically search the local LAN for a multiplayer + * // server and join it. + * // + * i = M_CheckParm("-autojoin"); + * + * if (i > 0) + * { + * addr = NET_FindLANServer(); + * + * if (addr == NULL) + * { + * I_Error("No server found on local LAN"); + * } + * } + * + * //! + * // @arg
+ * // @category net + * // + * // Connect to a multiplayer server running on the given + * // address. + * // + * i = M_CheckParmWithArgs("-connect", 1); + * + * if (i > 0) + * { + * net_sdl_module.InitClient(); + * addr = net_sdl_module.ResolveAddress(myargv[i+1]); + * + * if (addr == NULL) + * { + * I_Error("Unable to resolve '%s'\n", myargv[i+1]); + * } + * } + * } + * + * if (addr != NULL) + * { + * if (M_CheckParm("-drone") > 0) + * { + * connect_data->drone = true; + * } + * + * if (!NET_CL_Connect(addr, connect_data)) + * { + * I_Error("D_InitNetGame: Failed to connect to %s\n", + * NET_AddrToString(addr)); + * } + * + * printf("D_InitNetGame: Connected to %s\n", NET_AddrToString(addr)); + * + * // Wait for launch message received from server. + * NET_WaitForLaunch(); + * + * result = true; + * } + * + * return result; + */ + + return false; } - -// -// D_QuitNetGame -// Called before quitting to leave a net game -// without hanging the other players -// -void D_QuitNetGame (void) -{ - printf("NRFD-TODO: "); /* - NET_SV_Shutdown(); - NET_CL_Disconnect(); - */ + * Called before quitting to leave a net game + * without hanging the other players. + */ +void D_QuitNetGame(void) +{ + /* + * NRFD-TODO + * NET_SV_Shutdown(); + * NET_CL_Disconnect(); + */ } static int GetLowTic(void) @@ -577,10 +553,11 @@ static void OldNetSync(void) frameon++; - // ideally maketic should be 1 - 3 tics above lowtic - // if we are consistantly slower, speed up time - - for (i=0 ; i recvtic; @@ -614,21 +589,20 @@ static void OldNetSync(void) if (frameskip[0] && frameskip[1] && frameskip[2] && frameskip[3]) { skiptics = 1; - // printf ("+"); } } } -// Returns true if there are players in the game: - +/* Returns true if there are players in the game. */ static boolean PlayersInGame(void) { boolean result = false; unsigned int i; - // If we are connected to a server, check if there are any players - // in the game. - + /* + * If we are connected to a server, check if there are any players + * in the game. + */ if (net_client_connected) { for (i = 0; i < NET_MAXPLAYERS; ++i) @@ -637,9 +611,10 @@ static boolean PlayersInGame(void) } } - // Whether single or multi-player, unless we are running as a drone, - // we are in the game. - + /* + * Whether single or multi-player, unless we are running as a drone, + * we are in the game. + */ if (!drone) { result = true; @@ -648,15 +623,16 @@ static boolean PlayersInGame(void) return result; } -// When using ticdup, certain values must be cleared out when running -// the duplicate ticcmds. - +/* + * When using ticdup, certain values must be cleared out when running + * the duplicate ticcmds. + */ static void TicdupSquash(ticcmd_set_t *set) { ticcmd_t *cmd; unsigned int i; - for (i = 0; i < NET_MAXPLAYERS ; ++i) + for (i = 0; i < NET_MAXPLAYERS; ++i) { cmd = &set->cmds[i]; cmd->chatchar = 0; @@ -665,9 +641,10 @@ static void TicdupSquash(ticcmd_set_t *set) } } -// When running in single player mode, clear all the ingame[] array -// except the local player. - +/* + * When running in single player mode, clear all the ingame[] array + * except the local player. + */ static void SinglePlayerClear(ticcmd_set_t *set) { unsigned int i; @@ -681,11 +658,7 @@ static void SinglePlayerClear(ticcmd_set_t *set) } } -// -// TryRunTics -// - -void TryRunTics (void) +void TryRunTics(void) { int i; int lowtic; @@ -695,38 +668,37 @@ void TryRunTics (void) int availabletics; int counts; - - // get real tics + /* Get real tics */ entertic = I_GetTime() / ticdup; realtics = entertic - oldentertics; oldentertics = entertic; - // in singletics mode, run a single tic every time this function - // is called. - + /* + * In singletics mode, run a single tic every time this function + * is called. + */ if (singletics) { BuildNewTic(); } else { - NetUpdate (); + NetUpdate(); } lowtic = GetLowTic(); - availabletics = lowtic - gametic/ticdup; - - // decide how many tics to run + availabletics = lowtic - gametic / ticdup; + /* Decide how many tics to run */ if (new_sync) { counts = availabletics; } else { - // decide how many tics to run - if (realtics < availabletics-1) - counts = realtics+1; + /* Decide how many tics to run */ + if (realtics < availabletics - 1) + counts = realtics + 1; else if (realtics < availabletics) counts = realtics; else @@ -744,22 +716,24 @@ void TryRunTics (void) if (counts < 1) counts = 1; - // wait for new tics if needed - while (!PlayersInGame() || lowtic < gametic/ticdup + counts) + /* Wait for new tics if needed */ + while (!PlayersInGame() || lowtic < gametic / ticdup + counts) { - NetUpdate (); + NetUpdate(); lowtic = GetLowTic(); - if (lowtic < gametic/ticdup) - I_Error ("TryRunTics: lowtic < gametic"); + if (lowtic < gametic / ticdup) + I_Error("TryRunTics: lowtic < gametic"); - // Still no tics to run? Sleep until some are available. - if (lowtic < gametic/ticdup + counts) + /* Still no tics to run? Sleep until some are available */ + if (lowtic < gametic / ticdup + counts) { - // If we're in a netgame, we might spin forever waiting for - // new network data to be received. So don't stay in here - // forever - give the menu a chance to work. + /* + * If we're in a netgame, we might spin forever waiting for + * new network data to be received. So don't stay in here + * forever - give the menu a chance to work. + */ if (I_GetTime() / ticdup - entertic >= MAX_NETGAME_STALL_TICS) { return; @@ -769,7 +743,7 @@ void TryRunTics (void) } } - // run the count * ticdup dics + /* Run the count * ticdup dics */ while (counts--) { ticcmd_set_t *set; @@ -786,23 +760,21 @@ void TryRunTics (void) SinglePlayerClear(set); } - for (i=0 ; i lowtic) - I_Error ("gametic>lowtic"); + if (gametic / ticdup > lowtic) + I_Error("gametic>lowtic"); memcpy(local_playeringame, set->ingame, sizeof(local_playeringame)); loop_interface->RunTic(set->cmds, set->ingame); gametic++; - // modify command for duplicated tics - + /* Modify command for duplicated tics */ TicdupSquash(set); } - - NetUpdate (); // check for new console commands + /* Check for new console commands */ + NetUpdate(); } } @@ -811,10 +783,6 @@ void D_RegisterLoopCallbacks(loop_interface_t *i) loop_interface = i; } -// TODO: Move nonvanilla demo functions into a dedicated file. -#include "m_misc.h" -#include "w_wad.h" - static boolean StrictDemos(void) { //! @@ -827,12 +795,14 @@ static boolean StrictDemos(void) return M_ParmExists("-strictdemos"); } -// If the provided conditional value is true, we're trying to record -// a demo file that will include a non-vanilla extension. The function -// will return true if the conditional is true and it's allowed to use -// this extension (no extensions are allowed if -strictdemos is given -// on the command line). A warning is shown on the console using the -// provided string describing the non-vanilla expansion. +/* + * If the provided conditional value is true, we're trying to record + * a demo file that will include a non-vanilla extension. The function + * will return true if the conditional is true and it's allowed to use + * this extension (no extensions are allowed if -strictdemos is given + * on the command line). A warning is shown on the console using the + * provided string describing the non-vanilla expansion. + */ boolean D_NonVanillaRecord(boolean conditional, char *feature) { if (!conditional || StrictDemos()) @@ -847,32 +817,39 @@ boolean D_NonVanillaRecord(boolean conditional, char *feature) return true; } -// Returns true if the given lump number corresponds to data from a .lmp -// file, as opposed to a WAD. +/* + * Returns true if the given lump number corresponds to data from a .lmp + * file, as opposed to a WAD. + */ static boolean IsDemoFile(int lumpnum) { - printf("NRFD-TODO: IsDemoFile\n"); return false; /* - char *lower; - boolean result; - - lower = M_StringDuplicate(lumpinfo[lumpnum]->wad_file->path); - M_ForceLowercase(lower); - result = M_StringEndsWith(lower, ".lmp"); - free(lower); - - return result; */ + /* + * NRFD-TODO + * char *lower; + * boolean result; + * + * lower = M_StringDuplicate(lumpinfo[lumpnum]->wad_file->path); + * M_ForceLowercase(lower); + * result = M_StringEndsWith(lower, ".lmp"); + * free(lower); + * + * return result; + */ + + return false; } -// If the provided conditional value is true, we're trying to play back -// a demo that includes a non-vanilla extension. We return true if the -// conditional is true and it's allowed to use this extension, checking -// that: -// - The -strictdemos command line argument is not provided. -// - The given lumpnum identifying the demo to play back identifies a -// demo that comes from a .lmp file, not a .wad file. -// - Before proceeding, a warning is shown to the user on the console. -boolean D_NonVanillaPlayback(boolean conditional, int lumpnum, - char *feature) +/* + * If the provided conditional value is true, we're trying to play back + * a demo that includes a non-vanilla extension. We return true if the + * conditional is true and it's allowed to use this extension, checking + * that: + * - The -strictdemos command line argument is not provided. + * - The given lumpnum identifying the demo to play back identifies a + * demo that comes from a .lmp file, not a .wad file. + * - Before proceeding, a warning is shown to the user on the console. + */ +boolean D_NonVanillaPlayback(boolean conditional, int lumpnum, char *feature) { if (!conditional || StrictDemos()) { @@ -882,7 +859,8 @@ boolean D_NonVanillaPlayback(boolean conditional, int lumpnum, if (!IsDemoFile(lumpnum)) { printf("Warning: WAD contains demo with a non-vanilla extension " - "(%s)\n", feature); + "(%s)\n", + feature); return false; } diff --git a/zephyrdoom/src/d_loop.h b/zephyrdoom/src/d_loop.h index 9cad6f8..cab169f 100644 --- a/zephyrdoom/src/d_loop.h +++ b/zephyrdoom/src/d_loop.h @@ -1,87 +1,84 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Main loop stuff. -// +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Main loop stuff. + */ #ifndef __D_LOOP__ #define __D_LOOP__ #include "net_defs.h" -// Callback function invoked while waiting for the netgame to start. -// The callback is invoked when new players are ready. The callback -// should return true, or return false to abort startup. - +/* + * Callback function invoked while waiting for the netgame to start. + * The callback is invoked when new players are ready. The callback + * should return true, or return false to abort startup. + */ typedef boolean (*netgame_startup_callback_t)(int ready_players, int num_players); typedef struct { - // Read events from the event queue, and process them. - + /* Read events from the event queue, and process them */ void (*ProcessEvents)(); - // Given the current input state, fill in the fields of the specified - // ticcmd_t structure with data for a new tic. - + /* + * Given the current input state, fill in the fields of the specified + * ticcmd_t structure with data for a new tic. + */ void (*BuildTiccmd)(ticcmd_t *cmd, int maketic); - // Advance the game forward one tic, using the specified player input. - + /* Advance the game forward one tic, using the specified player input */ void (*RunTic)(ticcmd_t *cmds, boolean *ingame); - // Run the menu (runs independently of the game). - + /* Run the menu (runs independently of the game) */ void (*RunMenu)(); } loop_interface_t; -// Register callback functions for the main loop code to use. +/* Register callback functions for the main loop code to use. */ void D_RegisterLoopCallbacks(loop_interface_t *i); -// Create any new ticcmds and broadcast to other players. -void NetUpdate (void); +/* Create any new ticcmds and broadcast to other players. */ +void NetUpdate(void); -// Broadcasts special packets to other players -// to notify of game exit -void D_QuitNetGame (void); +/* Broadcasts special packets to other players to notify of game exit. */ +void D_QuitNetGame(void); -//? how many ticks to run? -void TryRunTics (void); +/* How many ticks to run. */ +void TryRunTics(void); -// Called at start of game loop to initialize timers +/* Called at start of game loop to initialize timers. */ void D_StartGameLoop(void); -// Initialize networking code and connect to server. - +/* Initialize networking code and connect to server. */ boolean D_InitNetGame(net_connect_data_t *connect_data); -// Start game with specified settings. The structure will be updated -// with the actual settings for the game. - +/* + * Start game with specified settings. The structure will be updated + * with the actual settings for the game. + */ void D_StartNetGame(net_gamesettings_t *settings, netgame_startup_callback_t callback); extern boolean singletics; extern int gametic, ticdup; -// Check if it is permitted to record a demo with a non-vanilla feature. +/* Check if it is permitted to record a demo with a non-vanilla feature. */ boolean D_NonVanillaRecord(boolean conditional, char *feature); -// Check if it is permitted to play back a demo with a non-vanilla feature. -boolean D_NonVanillaPlayback(boolean conditional, int lumpnum, - char *feature); +/* Check if it is permitted to play back a demo with a non-vanilla feature. */ +boolean D_NonVanillaPlayback(boolean conditional, int lumpnum, char *feature); #endif diff --git a/zephyrdoom/src/d_mode.c b/zephyrdoom/src/d_mode.c index accb142..c6fb07b 100644 --- a/zephyrdoom/src/d_mode.c +++ b/zephyrdoom/src/d_mode.c @@ -1,28 +1,29 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// -// DESCRIPTION: -// Functions and definitions relating to the game type and operational -// mode. -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * + * DESCRIPTION: + * Functions and definitions relating to the game type and operational + * mode. + */ #include "doomtype.h" #include "d_mode.h" -// Valid game mode/mission combinations, with the number of -// episodes/maps for each. - +/* + * Valid game mode/mission combinations, with the number of + * episodes/maps for each. + */ static struct { GameMission_t mission; @@ -30,28 +31,27 @@ static struct int episode; int map; } valid_modes[] = { - { pack_chex, retail, 1, 5 }, - { doom, shareware, 1, 9 }, - { doom, registered, 3, 9 }, - { doom, retail, 4, 9 }, - { doom2, commercial, 1, 32 }, - { pack_tnt, commercial, 1, 32 }, - { pack_plut, commercial, 1, 32 }, - { pack_hacx, commercial, 1, 32 }, - { heretic, shareware, 1, 9 }, - { heretic, registered, 3, 9 }, - { heretic, retail, 5, 9 }, - { hexen, commercial, 1, 60 }, - { strife, commercial, 1, 34 }, + {pack_chex, retail, 1, 5}, + {doom, shareware, 1, 9}, + {doom, registered, 3, 9}, + {doom, retail, 4, 9}, + {doom2, commercial, 1, 32}, + {pack_tnt, commercial, 1, 32}, + {pack_plut, commercial, 1, 32}, + {pack_hacx, commercial, 1, 32}, + {heretic, shareware, 1, 9}, + {heretic, registered, 3, 9}, + {heretic, retail, 5, 9}, + {hexen, commercial, 1, 60}, + {strife, commercial, 1, 34}, }; -// Check that a gamemode+gamemission received over the network is valid. - +/* Check that a gamemode + gamemission received over the network is valid. */ boolean D_ValidGameMode(GameMission_t mission, GameMode_t mode) { int i; - for (i=0; i= 1 && episode <= valid_modes[i].episode - && map >= 1 && map <= valid_modes[i].map; + return episode >= 1 && episode <= valid_modes[i].episode && map >= 1 && map <= valid_modes[i].map; } } - // Unknown mode/mission combination - + /* Unknown mode/mission combination */ return false; } -// Get the number of valid episodes for the specified mission/mode. - +/* Get the number of valid episodes for the specified mission/mode. */ int D_GetNumEpisodes(GameMission_t mission, GameMode_t mode) { int episode; @@ -114,43 +108,40 @@ int D_GetNumEpisodes(GameMission_t mission, GameMode_t mode) return episode - 1; } -// Table of valid versions - -static struct { +/* Table of valid versions. */ +static struct +{ GameMission_t mission; GameVersion_t version; } valid_versions[] = { - { doom, exe_doom_1_666 }, - { doom, exe_doom_1_7 }, - { doom, exe_doom_1_8 }, - { doom, exe_doom_1_9 }, - { doom, exe_hacx }, - { doom, exe_ultimate }, - { doom, exe_final }, - { doom, exe_final2 }, - { doom, exe_chex }, - { heretic, exe_heretic_1_3 }, - { hexen, exe_hexen_1_1 }, - { strife, exe_strife_1_2 }, - { strife, exe_strife_1_31 }, + {doom, exe_doom_1_666}, + {doom, exe_doom_1_7}, + {doom, exe_doom_1_8}, + {doom, exe_doom_1_9}, + {doom, exe_hacx}, + {doom, exe_ultimate}, + {doom, exe_final}, + {doom, exe_final2}, + {doom, exe_chex}, + {heretic, exe_heretic_1_3}, + {hexen, exe_hexen_1_1}, + {strife, exe_strife_1_2}, + {strife, exe_strife_1_31}, }; boolean D_ValidGameVersion(GameMission_t mission, GameVersion_t version) { int i; - // All Doom variants can use the Doom versions. - - if (mission == doom2 || mission == pack_plut || mission == pack_tnt - || mission == pack_hacx || mission == pack_chex) + /* All Doom variants can use the Doom versions */ + if (mission == doom2 || mission == pack_plut || mission == pack_tnt || mission == pack_hacx || mission == pack_chex) { mission = doom; } - for (i=0; i #include @@ -39,26 +39,30 @@ struct deh_context_s deh_input_type_t type; char *filename; - // If the input comes from a memory buffer, pointer to the memory - // buffer. + /* + * If the input comes from a memory buffer, pointer to the memory + * buffer. + */ unsigned char *input_buffer; size_t input_buffer_len; unsigned int input_buffer_pos; int lumpnum; - // If the input comes from a file, the file stream for reading - // data. + /* + * If the input comes from a file, the file stream for reading + * data. + */ FILE *stream; - // Current line number that we have reached: + /* Current line number that we have reached */ int linenum; - // Used by DEH_ReadLine: + /* Used by DEH_ReadLine */ boolean last_was_newline; char *readbuffer; int readbuffer_size; - // Error handling. + /* Error handling */ boolean had_error; }; @@ -68,8 +72,7 @@ static deh_context_t *DEH_NewContext(void) context = Z_Malloc(sizeof(*context), PU_STATIC, NULL); - // Initial read buffer size of 128 bytes - + /* Initial read buffer size of 128 bytes */ context->readbuffer_size = 128; context->readbuffer = Z_Malloc(context->readbuffer_size, PU_STATIC, NULL); context->linenum = 0; @@ -80,9 +83,10 @@ static deh_context_t *DEH_NewContext(void) return context; } -// Open a dehacked file for reading -// Returns NULL if open failed - +/* + * Open a dehacked file for reading + * Returns NULL if open failed + */ deh_context_t *DEH_OpenFile(char *filename) { FILE *fstream; @@ -102,8 +106,7 @@ deh_context_t *DEH_OpenFile(char *filename) return context; } -// Open a WAD lump for reading. - +/* Open a WAD lump for reading. */ deh_context_t *DEH_OpenLump(int lumpnum) { deh_context_t *context; @@ -125,8 +128,7 @@ deh_context_t *DEH_OpenLump(int lumpnum) return context; } -// Close dehacked file - +/* Close dehacked file. */ void DEH_CloseFile(deh_context_t *context) { if (context->type == DEH_INPUT_FILE) @@ -147,8 +149,7 @@ int DEH_GetCharFile(deh_context_t *context) { if (feof(context->stream)) { - // end of file - + /* End of file */ return -1; } @@ -170,31 +171,30 @@ int DEH_GetCharLump(deh_context_t *context) return result; } -// Reads a single character from a dehacked file - +/* Reads a single character from a dehacked file. */ int DEH_GetChar(deh_context_t *context) { int result = 0; - // Read characters, but ignore carriage returns - // Essentially this is a DOS->Unix conversion - + /* + * Read characters, but ignore carriage returns. + * Essentially this is a DOS->Unix conversion. + */ do { switch (context->type) { - case DEH_INPUT_FILE: - result = DEH_GetCharFile(context); - break; + case DEH_INPUT_FILE: + result = DEH_GetCharFile(context); + break; - case DEH_INPUT_LUMP: - result = DEH_GetCharLump(context); - break; + case DEH_INPUT_LUMP: + result = DEH_GetCharLump(context); + break; } } while (result == '\r'); - // Track the current line number - + /* Track the current line number */ if (context->last_was_newline) { ++context->linenum; @@ -205,8 +205,7 @@ int DEH_GetChar(deh_context_t *context) return result; } -// Increase the read buffer size - +/* Increase the read buffer size */ static void IncreaseReadBuffer(deh_context_t *context) { char *newbuffer; @@ -223,8 +222,7 @@ static void IncreaseReadBuffer(deh_context_t *context) context->readbuffer_size = newbuffer_size; } -// Read a whole line - +/* Read a whole line. */ char *DEH_ReadLine(deh_context_t *context, boolean extended) { int c; @@ -237,24 +235,22 @@ char *DEH_ReadLine(deh_context_t *context, boolean extended) if (c < 0 && pos == 0) { - // end of file - + /* End of file */ return NULL; } - // cope with lines of any length: increase the buffer size - + /* Cope with lines of any length: increase the buffer size */ if (pos >= context->readbuffer_size) { IncreaseReadBuffer(context); } - // extended string support + /* Extended string support */ if (extended && c == '\\') { c = DEH_GetChar(context); - // "\n" in the middle of a string indicates an internal linefeed + /* "\n" in the middle of a string indicates an internal linefeed */ if (c == 'n') { context->readbuffer[pos] = '\n'; @@ -262,8 +258,10 @@ char *DEH_ReadLine(deh_context_t *context, boolean extended) continue; } - // values to be assigned may be split onto multiple lines by ending - // each line that is to be continued with a backslash + /* + * Values to be assigned may be split onto multiple lines by ending + * each line that is to be continued with a backslash. + */ if (c == '\n') { escaped = true; @@ -271,8 +269,10 @@ char *DEH_ReadLine(deh_context_t *context, boolean extended) } } - // blanks before the backslash are included in the string - // but indentation after the linefeed is not + /* + * Blanks before the backslash are included in the string + * but indentation after the linefeed is not. + */ if (escaped && c >= 0 && isspace(c) && c != '\n') { continue; @@ -284,17 +284,14 @@ char *DEH_ReadLine(deh_context_t *context, boolean extended) if (c == '\n' || c < 0) { - // end of line: a full line has been read - + /* End of line, a full line has been read */ context->readbuffer[pos] = '\0'; break; } else if (c != '\0') { - // normal character; don't allow NUL characters to be - // added. - - context->readbuffer[pos] = (char) c; + /* Normal character, don't allow NUL characters to be added */ + context->readbuffer[pos] = (char)c; ++pos; } } diff --git a/zephyrdoom/src/deh_io.h b/zephyrdoom/src/deh_io.h index bbd590f..690493e 100644 --- a/zephyrdoom/src/deh_io.h +++ b/zephyrdoom/src/deh_io.h @@ -1,19 +1,19 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// -// Dehacked I/O code (does all reads from dehacked files) -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Dehacked I/O code (does all reads from dehacked files). + */ #ifndef DEH_IO_H #define DEH_IO_H @@ -29,4 +29,4 @@ void DEH_Error(deh_context_t *context, char *msg, ...); void DEH_Warning(deh_context_t *context, char *msg, ...); boolean DEH_HadError(deh_context_t *context); -#endif /* #ifndef DEH_IO_H */ +#endif /* DEH_IO_H */ diff --git a/zephyrdoom/src/deh_main.c b/zephyrdoom/src/deh_main.c index 29d4372..79cb5d6 100644 --- a/zephyrdoom/src/deh_main.c +++ b/zephyrdoom/src/deh_main.c @@ -1,19 +1,19 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// -// Main dehacked code -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Main dehacked code. + */ #include #include @@ -37,20 +37,16 @@ extern char *deh_signatures[]; static boolean deh_initialized = false; -// If true, we can parse [STRINGS] sections in BEX format. - +/* If true, we can parse [STRINGS] sections in BEX format. */ boolean deh_allow_extended_strings = false; -// If true, we can do long string replacements. - +/* If true, we can do long string replacements. */ boolean deh_allow_long_strings = false; -// If true, we can do cheat replacements longer than the originals. - +/* If true, we can do cheat replacements longer than the originals. */ boolean deh_allow_long_cheats = false; -// If false, dehacked cheat replacements are ignored. - +/* If false, dehacked cheat replacements are ignored. */ boolean deh_apply_cheats = true; void DEH_Checksum(sha1_digest_t digest) @@ -60,7 +56,7 @@ void DEH_Checksum(sha1_digest_t digest) SHA1_Init(&sha1_context); - for (i=0; deh_section_types[i] != NULL; ++i) + for (i = 0; deh_section_types[i] != NULL; ++i) { if (deh_section_types[i]->sha1_hash != NULL) { @@ -71,13 +67,12 @@ void DEH_Checksum(sha1_digest_t digest) SHA1_Final(digest, &sha1_context); } -// Called on startup to call the Init functions - +/* Called on startup to call the Init functions. */ static void InitializeSections(void) { unsigned int i; - for (i=0; deh_section_types[i] != NULL; ++i) + for (i = 0; deh_section_types[i] != NULL; ++i) { if (deh_section_types[i]->init != NULL) { @@ -93,33 +88,32 @@ static void DEH_Init(void) // // Ignore cheats in dehacked files. // - if (M_CheckParm("-nocheats") > 0) { deh_apply_cheats = false; } - // Call init functions for all the section definitions. + /* Call init functions for all the section definitions */ InitializeSections(); deh_initialized = true; } -// Given a section name, get the section structure which corresponds - +/* Given a section name, get the section structure which corresponds. */ static deh_section_t *GetSectionByName(char *name) { unsigned int i; - // we explicitely do not recognize [STRINGS] sections at all - // if extended strings are not allowed - + /* + * We explicitely do not recognize [STRINGS] sections at all + * if extended strings are not allowed. + */ if (!deh_allow_extended_strings && !strncasecmp("[STRINGS]", name, 9)) { return NULL; } - for (i=0; deh_section_types[i] != NULL; ++i) + for (i = 0; deh_section_types[i] != NULL; ++i) { if (!strcasecmp(deh_section_types[i]->name, name)) { @@ -130,8 +124,7 @@ static deh_section_t *GetSectionByName(char *name) return NULL; } -// Is the string passed just whitespace? - +/* Is the string passed just whitespace. */ static boolean IsWhitespace(char *s) { for (; *s; ++s) @@ -143,19 +136,16 @@ static boolean IsWhitespace(char *s) return true; } -// Strip whitespace from the start and end of a string - +/* Strip whitespace from the start and end of a string. */ static char *CleanString(char *s) { char *strending; - // Leading whitespace - + /* Leading whitespace */ while (*s && isspace(*s)) ++s; - // Trailing whitespace - + /* Trailing whitespace */ strending = s + strlen(s) - 1; while (strlen(s) > 0 && isspace(*strending)) @@ -167,22 +157,22 @@ static char *CleanString(char *s) return s; } -// This pattern is used a lot of times in different sections, -// an assignment is essentially just a statement of the form: -// -// Variable Name = Value -// -// The variable name can include spaces or any other characters. -// The string is split on the '=', essentially. -// -// Returns true if read correctly - +/* + * This pattern is used a lot of times in different sections, + * an assignment is essentially just a statement of the form: + * + * Variable Name = Value + * + * The variable name can include spaces or any other characters. + * The string is split on the '=', essentially. + * + * Returns true if read correctly. + */ boolean DEH_ParseAssignment(char *line, char **variable_name, char **value) { char *p; - // find the equals - + /* Find the equals */ p = strchr(line, '='); if (p == NULL) @@ -190,15 +180,15 @@ boolean DEH_ParseAssignment(char *line, char **variable_name, char **value) return false; } - // variable name at the start - // turn the '=' into a \0 to terminate the string here - + /* + * Variable name at the start turn + * the '=' into a \0 to terminate the string here. + */ *p = '\0'; *variable_name = CleanString(line); - // value immediately follows the '=' - - *value = CleanString(p+1); + /* Value immediately follows the '=' */ + *value = CleanString(p + 1); return true; } @@ -208,8 +198,7 @@ static boolean CheckSignatures(deh_context_t *context) size_t i; char *line; - // Read the first line - + /* Read the first line */ line = DEH_ReadLine(context, false); if (line == NULL) @@ -217,9 +206,8 @@ static boolean CheckSignatures(deh_context_t *context) return false; } - // Check all signatures to see if one matches - - for (i=0; deh_signatures[i] != NULL; ++i) + /* Check all signatures to see if one matches */ + for (i = 0; deh_signatures[i] != NULL; ++i) { if (!strcmp(deh_signatures[i], line)) { @@ -230,57 +218,56 @@ static boolean CheckSignatures(deh_context_t *context) return false; } -// Parses a comment string in a dehacked file. - +/* Parses a comment string in a dehacked file. */ static void DEH_ParseComment(char *comment) { - // - // Welcome, to the super-secret Chocolate Doom-specific Dehacked - // overrides function. - // - // Putting these magic comments into your Dehacked lumps will - // allow you to go beyond the normal limits of Vanilla Dehacked. - // Because of this, these comments are deliberately undocumented, - // and if you're using them you should be aware that your mod - // is not compatible with Vanilla Doom and you're probably a - // very naughty person. - // - - // Allow comments containing this special value to allow string - // replacements longer than those permitted by DOS dehacked. - // This allows us to use a dehacked patch for doing string - // replacements for emulating Chex Quest. - // - // If you use this, your dehacked patch may not work in Vanilla - // Doom. + /* + * Welcome, to the super-secret Chocolate Doom-specific Dehacked + * overrides function. + * + * Putting these magic comments into your Dehacked lumps will + * allow you to go beyond the normal limits of Vanilla Dehacked. + * Because of this, these comments are deliberately undocumented, + * and if you're using them you should be aware that your mod + * is not compatible with Vanilla Doom and you're probably a + * very naughty person. + * + * Allow comments containing this special value to allow string + * replacements longer than those permitted by DOS dehacked. + * This allows us to use a dehacked patch for doing string + * replacements for emulating Chex Quest. + * + * If you use this, your dehacked patch may not work in Vanilla + * Doom. + */ if (strstr(comment, "*allow-long-strings*") != NULL) { deh_allow_long_strings = true; } - // Allow magic comments to allow longer cheat replacements than - // those permitted by DOS dehacked. This is also for Chex - // Quest. - + /* + * Allow magic comments to allow longer cheat replacements than + * those permitted by DOS dehacked. This is also for Chex Quest. + */ if (strstr(comment, "*allow-long-cheats*") != NULL) { deh_allow_long_cheats = true; } - // Allow magic comments to allow parsing [STRINGS] section - // that are usually only found in BEX format files. This allows - // for substitution of map and episode names when loading - // Freedoom/FreeDM IWADs. - + /* + * Allow magic comments to allow parsing [STRINGS] section + * that are usually only found in BEX format files. This allows + * for substitution of map and episode names when loading + * Freedoom/FreeDM IWADs. + */ if (strstr(comment, "*allow-extended-strings*") != NULL) { deh_allow_extended_strings = true; } } -// Parses a dehacked file by reading from the context - +/* Parses a dehacked file by reading from the context. */ static void DEH_ParseContext(deh_context_t *context) { deh_section_t *current_section = NULL; @@ -289,25 +276,23 @@ static void DEH_ParseContext(deh_context_t *context) boolean extended; char *line; - // Read the header and check it matches the signature - + /* Read the header and check it matches the signature */ if (!CheckSignatures(context)) { DEH_Error(context, "This is not a valid dehacked patch file!"); } - // Read the file - + /* Read the file */ while (!DEH_HadError(context)) { - // Read the next line. We only allow the special extended parsing - // for the BEX [STRINGS] section. - extended = current_section != NULL - && !strcasecmp(current_section->name, "[STRINGS]"); + /* + * Read the next line. We only allow the special extended parsing + * for the BEX [STRINGS] section. + */ + extended = current_section != NULL && !strcasecmp(current_section->name, "[STRINGS]"); line = DEH_ReadLine(context, extended); - // end of file? - + /* End of file */ if (line == NULL) { return; @@ -318,8 +303,7 @@ static void DEH_ParseContext(deh_context_t *context) if (line[0] == '#') { - // comment - + /* Parse comment */ DEH_ParseComment(line); continue; } @@ -328,14 +312,12 @@ static void DEH_ParseContext(deh_context_t *context) { if (current_section != NULL) { - // end of section - + /* End of section */ if (current_section->end != NULL) { current_section->end(context, tag); } - //printf("end %s tag\n", current_section->name); current_section = NULL; } } @@ -343,14 +325,12 @@ static void DEH_ParseContext(deh_context_t *context) { if (current_section != NULL) { - // parse this line - + /* Parse this line */ current_section->line_parser(context, line, tag); } else { - // possibly the start of a new section - + /* Possibly the start of a new section */ sscanf(line, "%19s", section_name); current_section = GetSectionByName(section_name); @@ -358,19 +338,13 @@ static void DEH_ParseContext(deh_context_t *context) if (current_section != NULL) { tag = current_section->start(context, line); - //printf("started %s tag\n", section_name); - } - else - { - //printf("unknown section name %s\n", section_name); } } } } } -// Parses a dehacked file - +/* Parses a dehacked file */ int DEH_LoadFile(char *filename) { deh_context_t *context; @@ -380,9 +354,11 @@ int DEH_LoadFile(char *filename) DEH_Init(); } - // Before parsing a new file, reset special override flags to false. - // Magic comments should only apply to the file in which they were - // defined, and shouldn't carry over to subsequent files as well. + /* + * Before parsing a new file, reset special override flags to false. + * Magic comments should only apply to the file in which they were + * defined, and shouldn't carry over to subsequent files as well. + */ deh_allow_long_strings = false; deh_allow_long_cheats = false; deh_allow_extended_strings = false; @@ -409,9 +385,10 @@ int DEH_LoadFile(char *filename) return 1; } -// Load dehacked file from WAD lump. -// If allow_long is set, allow long strings and cheats just for this lump. - +/* + * Load dehacked file from WAD lump. + * If allow_long is set, allow long strings and cheats just for this lump. + */ int DEH_LoadLump(int lumpnum, boolean allow_long, boolean allow_error) { deh_context_t *context; @@ -421,7 +398,7 @@ int DEH_LoadLump(int lumpnum, boolean allow_long, boolean allow_error) DEH_Init(); } - // Reset all special flags to defaults. + /* Reset all special flags to defaults */ deh_allow_long_strings = allow_long; deh_allow_long_cheats = allow_long; deh_allow_extended_strings = false; @@ -438,8 +415,10 @@ int DEH_LoadLump(int lumpnum, boolean allow_long, boolean allow_error) DEH_CloseFile(context); - // If there was an error while parsing, abort with an error, but allow - // errors to just be ignored if allow_error=true. + /* + * If there was an error while parsing, abort with an error, but allow + * errors to just be ignored if allow_error=true. + */ if (!allow_error && DEH_HadError(context)) { I_Error("Error parsing dehacked lump"); @@ -463,7 +442,7 @@ int DEH_LoadLumpByName(char *name, boolean allow_long, boolean allow_error) return DEH_LoadLump(lumpnum, allow_long, allow_error); } -// Check the command line for -deh argument, and others. +/* Check the command line for -deh argument, and others. */ void DEH_ParseCommandLine(void) { char *filename; @@ -473,9 +452,8 @@ void DEH_ParseCommandLine(void) // @arg // @category mod // - // Load the given dehacked patch(es) + // Load the given dehacked patch(es). // - p = M_CheckParm("-deh"); if (p > 0) diff --git a/zephyrdoom/src/deh_main.h b/zephyrdoom/src/deh_main.h index 33ebbde..3c8aeae 100644 --- a/zephyrdoom/src/deh_main.h +++ b/zephyrdoom/src/deh_main.h @@ -1,19 +1,19 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// -// Dehacked entrypoint and common code -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Dehacked entrypoint and common code. + */ #ifndef DEH_MAIN_H #define DEH_MAIN_H @@ -22,10 +22,11 @@ #include "deh_str.h" #include "sha1.h" -// These are the limits that dehacked uses (from dheinit.h in the dehacked -// source). If these limits are exceeded, it does not generate an error, but -// a warning is displayed. - +/* + * These are the limits that dehacked uses (from dheinit.h in the dehacked + * source). If these limits are exceeded, it does not generate an error, but + * a warning is displayed. + */ #define DEH_VANILLA_NUMSTATES 966 #define DEH_VANILLA_NUMSFX 107 @@ -43,4 +44,4 @@ extern boolean deh_allow_long_strings; extern boolean deh_allow_long_cheats; extern boolean deh_apply_cheats; -#endif /* #ifndef DEH_MAIN_H */ +#endif /* DEH_MAIN_H */ diff --git a/zephyrdoom/src/deh_mapping.c b/zephyrdoom/src/deh_mapping.c index d85767a..46f714c 100644 --- a/zephyrdoom/src/deh_mapping.c +++ b/zephyrdoom/src/deh_mapping.c @@ -1,21 +1,20 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// -// Dehacked "mapping" code -// Allows the fields in structures to be mapped out and accessed by -// name -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Dehacked "mapping" code. + * Allows the fields in structures to be mapped out and accessed by name. + */ #include #include @@ -33,7 +32,7 @@ static deh_mapping_entry_t *GetMappingEntryByName(deh_context_t *context, { int i; - for (i=0; mapping->entries[i].name != NULL; ++i) + for (i = 0; mapping->entries[i].name != NULL; ++i) { deh_mapping_entry_t *entry = &mapping->entries[i]; @@ -49,17 +48,13 @@ static deh_mapping_entry_t *GetMappingEntryByName(deh_context_t *context, } } - // Not found. - + /* Not found */ DEH_Warning(context, "Field named '%s' not found", name); return NULL; } -// -// Get the location of the specified field in the specified structure. -// - +/* Get the location of the specified field in the specified structure. */ static void *GetStructField(void *structptr, deh_mapping_t *mapping, deh_mapping_entry_t *entry) @@ -71,10 +66,7 @@ static void *GetStructField(void *structptr, return (uint8_t *)structptr + offset; } -// -// Set the value of a particular field in a structure by name -// - +/* Set the value of a particular field in a structure by name. */ boolean DEH_SetMapping(deh_context_t *context, deh_mapping_t *mapping, void *structptr, char *name, int value) { @@ -88,8 +80,7 @@ boolean DEH_SetMapping(deh_context_t *context, deh_mapping_t *mapping, return false; } - // Sanity check: - + /* Sanity check */ if (entry->is_string) { DEH_Error(context, "Tried to set '%s' as integer (BUG)", name); @@ -98,34 +89,27 @@ boolean DEH_SetMapping(deh_context_t *context, deh_mapping_t *mapping, location = GetStructField(structptr, mapping, entry); - // printf("Setting %p::%s to %i (%i bytes)\n", - // structptr, name, value, entry->size); - - // Set field content based on its type: - + /* Set field content based on its type */ switch (entry->size) { - case 1: - * ((uint8_t *) location) = value; - break; - case 2: - * ((uint16_t *) location) = value; - break; - case 4: - * ((uint32_t *) location) = value; - break; - default: - DEH_Error(context, "Unknown field type for '%s' (BUG)", name); - return false; + case 1: + *((uint8_t *)location) = value; + break; + case 2: + *((uint16_t *)location) = value; + break; + case 4: + *((uint32_t *)location) = value; + break; + default: + DEH_Error(context, "Unknown field type for '%s' (BUG)", name); + return false; } return true; } -// -// Set the value of a string field in a structure by name -// - +/* Set the value of a string field in a structure by name. */ boolean DEH_SetStringMapping(deh_context_t *context, deh_mapping_t *mapping, void *structptr, char *name, char *value) { @@ -139,8 +123,7 @@ boolean DEH_SetStringMapping(deh_context_t *context, deh_mapping_t *mapping, return false; } - // Sanity check: - + /* Sanity check */ if (!entry->is_string) { DEH_Error(context, "Tried to set '%s' as string (BUG)", name); @@ -149,8 +132,7 @@ boolean DEH_SetStringMapping(deh_context_t *context, deh_mapping_t *mapping, location = GetStructField(structptr, mapping, entry); - // Copy value into field: - + /* Copy value into field */ M_StringCopy(location, value, entry->size); return true; @@ -161,39 +143,36 @@ void DEH_StructSHA1Sum(sha1_context_t *context, deh_mapping_t *mapping, { int i; - // Go through each mapping - - for (i=0; mapping->entries[i].name != NULL; ++i) + /* Go through each mapping */ + for (i = 0; mapping->entries[i].name != NULL; ++i) { deh_mapping_entry_t *entry = &mapping->entries[i]; void *location; if (entry->location == NULL) { - // Unsupported field - + /* Unsupported field */ continue; } - // Add in data for this field - + /* Add in data for this field */ location = (uint8_t *)structptr + ((uint8_t *)entry->location - (uint8_t *)mapping->base); switch (entry->size) { - case 1: - SHA1_UpdateInt32(context, *((uint8_t *) location)); - break; - case 2: - SHA1_UpdateInt32(context, *((uint16_t *) location)); - break; - case 4: - SHA1_UpdateInt32(context, *((uint32_t *) location)); - break; - default: - I_Error("Unknown dehacked mapping field type for '%s' (BUG)", - entry->name); - break; + case 1: + SHA1_UpdateInt32(context, *((uint8_t *)location)); + break; + case 2: + SHA1_UpdateInt32(context, *((uint16_t *)location)); + break; + case 4: + SHA1_UpdateInt32(context, *((uint32_t *)location)); + break; + default: + I_Error("Unknown dehacked mapping field type for '%s' (BUG)", + entry->name); + break; } } } diff --git a/zephyrdoom/src/deh_mapping.h b/zephyrdoom/src/deh_mapping.h index 771dbdd..5dad0a0 100644 --- a/zephyrdoom/src/deh_mapping.h +++ b/zephyrdoom/src/deh_mapping.h @@ -1,21 +1,20 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// -// Dehacked "mapping" code -// Allows the fields in structures to be mapped out and accessed by -// name -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Dehacked "mapping" code. + * Allows the fields in structures to be mapped out and accessed by name. + */ #ifndef DEH_MAPPING_H #define DEH_MAPPING_H @@ -24,33 +23,32 @@ #include "deh_io.h" #include "sha1.h" -#define DEH_BEGIN_MAPPING(mapping_name, structname) \ - static structname deh_mapping_base; \ - static deh_mapping_t mapping_name = \ - { \ - &deh_mapping_base, \ +#define DEH_BEGIN_MAPPING(mapping_name, structname) \ + static structname deh_mapping_base; \ + static deh_mapping_t mapping_name = \ + { \ + &deh_mapping_base, \ { -#define DEH_MAPPING(deh_name, fieldname) \ - {deh_name, &deh_mapping_base.fieldname, \ - sizeof(deh_mapping_base.fieldname), \ +#define DEH_MAPPING(deh_name, fieldname) \ + {deh_name, &deh_mapping_base.fieldname, \ + sizeof(deh_mapping_base.fieldname), \ false}, -#define DEH_MAPPING_STRING(deh_name, fieldname) \ - {deh_name, &deh_mapping_base.fieldname, \ - sizeof(deh_mapping_base.fieldname), \ +#define DEH_MAPPING_STRING(deh_name, fieldname) \ + {deh_name, &deh_mapping_base.fieldname, \ + sizeof(deh_mapping_base.fieldname), \ true}, -#define DEH_UNSUPPORTED_MAPPING(deh_name) \ +#define DEH_UNSUPPORTED_MAPPING(deh_name) \ {deh_name, NULL, -1, false}, -#define DEH_END_MAPPING \ - {NULL, NULL, -1} \ - } \ +#define DEH_END_MAPPING \ + {NULL, NULL, -1} \ + } \ }; - #define MAX_MAPPING_ENTRIES 32 typedef struct deh_mapping_s deh_mapping_t; @@ -58,21 +56,19 @@ typedef struct deh_mapping_entry_s deh_mapping_entry_t; struct deh_mapping_entry_s { - // field name - + /* Field name */ char *name; - // location relative to the base in the deh_mapping_t struct - // If this is NULL, it is an unsupported mapping - + /* + * location relative to the base in the deh_mapping_t struct. + * If this is NULL, it is an unsupported mapping. + */ void *location; - // field size - + /* Field size */ int size; - // if true, this is a string value. - + /* If true, this is a string value */ boolean is_string; }; @@ -89,4 +85,4 @@ boolean DEH_SetStringMapping(deh_context_t *context, deh_mapping_t *mapping, void DEH_StructSHA1Sum(sha1_context_t *context, deh_mapping_t *mapping, void *structptr); -#endif /* #ifndef DEH_MAPPING_H */ +#endif /* DEH_MAPPING_H */ diff --git a/zephyrdoom/src/deh_str.c b/zephyrdoom/src/deh_str.c index b115cfe..cabaf4f 100644 --- a/zephyrdoom/src/deh_str.c +++ b/zephyrdoom/src/deh_str.c @@ -1,19 +1,19 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// -// Parses Text substitution sections in dehacked files -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Parses Text substitution sections in dehacked files. + */ #include #include @@ -36,8 +36,7 @@ static deh_substitution_t **hash_table = NULL; static int hash_table_entries; static int hash_table_length = -1; -// This is the algorithm used by glib - +/* This is the algorithm used by glib. */ static unsigned int strhash(char *s) { char *p = s; @@ -56,9 +55,9 @@ static deh_substitution_t *SubstitutionForString(char *s) { int entry; - // Fallback if we have not initialized the hash table yet + /* Fallback if we have not initialized the hash table yet */ if (hash_table_length < 0) - return NULL; + return NULL; entry = strhash(s) % hash_table_length; @@ -66,20 +65,21 @@ static deh_substitution_t *SubstitutionForString(char *s) { if (!strcmp(hash_table[entry]->from_text, s)) { - // substitution found! + /* Substitution found */ return hash_table[entry]; } entry = (entry + 1) % hash_table_length; } - // no substitution found + /* No substitution found */ return NULL; } -// Look up a string to see if it has been replaced with something else -// This will be used throughout the program to substitute text - +/* + * Look up a string to see if it has been replaced with something else. + * This will be used throughout the program to substitute text. + */ char *DEH_String(char *s) { deh_substitution_t *subst; @@ -98,8 +98,7 @@ char *DEH_String(char *s) static void InitHashTable(void) { - // init hash table - + /* Init hash table */ hash_table_entries = 0; hash_table_length = 16; hash_table = Z_Malloc(sizeof(deh_substitution_t *) * hash_table_length, @@ -115,21 +114,18 @@ static void IncreaseHashtable(void) int old_table_length; int i; - // save the old table - + /* Save the old table */ old_table = hash_table; old_table_length = hash_table_length; - // double the size - + /* Double the size */ hash_table_length *= 2; hash_table = Z_Malloc(sizeof(deh_substitution_t *) * hash_table_length, PU_STATIC, NULL); memset(hash_table, 0, sizeof(deh_substitution_t *) * hash_table_length); - // go through the old table and insert all the old entries - - for (i=0; i 6) { IncreaseHashtable(); } - // find where to insert it + /* Find where to insert it */ entry = strhash(sub->from_text) % hash_table_length; while (hash_table[entry] != NULL) @@ -170,13 +164,13 @@ void DEH_AddStringReplacement(char *from_text, char *to_text) deh_substitution_t *sub; size_t len; - // Initialize the hash table if this is the first time + /* Initialize the hash table if this is the first time */ if (hash_table_length < 0) { InitHashTable(); } - // Check to see if there is an existing substitution already in place. + /* Check to see if there is an existing substitution already in place */ sub = SubstitutionForString(from_text); if (sub != NULL) @@ -189,10 +183,10 @@ void DEH_AddStringReplacement(char *from_text, char *to_text) } else { - // We need to allocate a new substitution. + /* We need to allocate a new substitution */ sub = Z_Malloc(sizeof(*sub), PU_STATIC, 0); - // We need to create our own duplicates of the provided strings. + /* We need to create our own duplicates of the provided strings */ len = strlen(from_text) + 1; sub->from_text = Z_Malloc(len, PU_STATIC, NULL); memcpy(sub->from_text, from_text, len); @@ -216,55 +210,68 @@ typedef enum FORMAT_ARG_SAVE_POS } format_arg_t; -// Get the type of a format argument. -// We can mix-and-match different format arguments as long as they -// are for the same data type. - +/* + * Get the type of a format argument. + * We can mix-and-match different format arguments as long as they + * are for the same data type. + */ static format_arg_t FormatArgumentType(char c) { switch (c) { - case 'd': case 'i': case 'o': case 'u': case 'x': case 'X': - return FORMAT_ARG_INT; - - case 'e': case 'E': case 'f': case 'F': case 'g': case 'G': - case 'a': case 'A': - return FORMAT_ARG_FLOAT; - - case 'c': case 'C': - return FORMAT_ARG_CHAR; - - case 's': case 'S': - return FORMAT_ARG_STRING; - - case 'p': - return FORMAT_ARG_PTR; - - case 'n': - return FORMAT_ARG_SAVE_POS; - - default: - return FORMAT_ARG_INVALID; + case 'd': + case 'i': + case 'o': + case 'u': + case 'x': + case 'X': + return FORMAT_ARG_INT; + + case 'e': + case 'E': + case 'f': + case 'F': + case 'g': + case 'G': + case 'a': + case 'A': + return FORMAT_ARG_FLOAT; + + case 'c': + case 'C': + return FORMAT_ARG_CHAR; + + case 's': + case 'S': + return FORMAT_ARG_STRING; + + case 'p': + return FORMAT_ARG_PTR; + + case 'n': + return FORMAT_ARG_SAVE_POS; + + default: + return FORMAT_ARG_INVALID; } } -// Given the specified string, get the type of the first format -// string encountered. - +/* + * Given the specified string, get the type of the first format + * string encountered. + */ static format_arg_t NextFormatArgument(char **str) { format_arg_t argtype; - // Search for the '%' starting the next string. - + /* Search for the '%' starting the next string */ while (**str != '\0') { if (**str == '%') { ++*str; - // Don't stop for double-%s. - + /* Don't stop for double-%s */ if (**str != '%') { break; @@ -274,8 +281,7 @@ static format_arg_t NextFormatArgument(char **str) ++*str; } - // Find the type of the format string. - + /* Find the type of the format string */ while (**str != '\0') { argtype = FormatArgumentType(**str); @@ -290,32 +296,30 @@ static format_arg_t NextFormatArgument(char **str) ++*str; } - // Stop searching, we have reached the end. - + /* Stop searching, we have reached the end */ *str = NULL; return FORMAT_ARG_INVALID; } -// Check if the specified argument type is a valid replacement for -// the original. - +/* + * Check if the specified argument type is a valid replacement for + * the original. + * + * In general, the original and replacement types should be + * identical. However, there are some cases where the replacement + * is valid and the types don't match. + */ static boolean ValidArgumentReplacement(format_arg_t original, format_arg_t replacement) { - // In general, the original and replacement types should be - // identical. However, there are some cases where the replacement - // is valid and the types don't match. - - // Characters can be represented as ints. - + /* Characters can be represented as ints */ if (original == FORMAT_ARG_CHAR && replacement == FORMAT_ARG_INT) { return true; } - // Strings are pointers. - + /* Strings are pointers */ if (original == FORMAT_ARG_STRING && replacement == FORMAT_ARG_PTR) { return true; @@ -324,17 +328,16 @@ static boolean ValidArgumentReplacement(format_arg_t original, return original == replacement; } -// Return true if the specified string contains no format arguments. - +/* Return true if the specified string contains no format arguments. */ static boolean ValidFormatReplacement(char *original, char *replacement) { char *rover1; char *rover2; int argtype1, argtype2; - // Check each argument in turn and compare types. - - rover1 = original; rover2 = replacement; + /* Check each argument in turn and compare types */ + rover1 = original; + rover2 = replacement; for (;;) { @@ -343,20 +346,17 @@ static boolean ValidFormatReplacement(char *original, char *replacement) if (argtype2 == FORMAT_ARG_INVALID) { - // No more arguments left to read from the replacement string. - + /* No more arguments left to read from the replacement string */ break; } else if (argtype1 == FORMAT_ARG_INVALID) { - // Replacement string has more arguments than the original. - + /* Replacement string has more arguments than the original */ return false; } else if (!ValidArgumentReplacement(argtype1, argtype2)) { - // Not a valid replacement argument. - + /* Not a valid replacement argument */ return false; } } @@ -364,8 +364,7 @@ static boolean ValidFormatReplacement(char *original, char *replacement) return true; } -// Get replacement format string, checking arguments. - +/* Get replacement format string, checking arguments. */ static char *FormatStringReplacement(char *s) { char *repl; @@ -375,7 +374,8 @@ static char *FormatStringReplacement(char *s) if (!ValidFormatReplacement(s, repl)) { printf("WARNING: Unsafe dehacked replacement provided for " - "printf format string: %s\n", s); + "printf format string: %s\n", + s); return s; } @@ -383,8 +383,7 @@ static char *FormatStringReplacement(char *s) return repl; } -// printf(), performing a replacement on the format string. - +/* printf(), performing a replacement on the format string. */ void DEH_printf(char *fmt, ...) { va_list args; @@ -399,8 +398,7 @@ void DEH_printf(char *fmt, ...) va_end(args); } -// fprintf(), performing a replacement on the format string. - +/* fprintf(), performing a replacement on the format string. */ void DEH_fprintf(FILE *fstream, char *fmt, ...) { va_list args; @@ -415,8 +413,7 @@ void DEH_fprintf(FILE *fstream, char *fmt, ...) va_end(args); } -// snprintf(), performing a replacement on the format string. - +/* snprintf(), performing a replacement on the format string. */ void DEH_snprintf(char *buffer, size_t len, char *fmt, ...) { va_list args; diff --git a/zephyrdoom/src/deh_str.h b/zephyrdoom/src/deh_str.h index fa11e65..1a860c1 100644 --- a/zephyrdoom/src/deh_str.h +++ b/zephyrdoom/src/deh_str.h @@ -1,38 +1,39 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// -// Dehacked string replacements -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Dehacked string replacements. + */ #ifndef DEH_STR_H #define DEH_STR_H #include -// Used to do dehacked text substitutions throughout the program - +/* Used to do dehacked text substitutions throughout the program. */ char *DEH_String(char *s); void DEH_printf(char *fmt, ...); void DEH_fprintf(FILE *fstream, char *fmt, ...); void DEH_snprintf(char *buffer, size_t len, char *fmt, ...); void DEH_AddStringReplacement(char *from_text, char *to_text); -// Static macro versions of the functions above - -// #define DEH_String(x) (x) -// #define DEH_printf printf -// #define DEH_fprintf fprintf -// #define DEH_snprintf snprintf +/* + * Static macro versions of the functions above. + * + * #define DEH_String(x) (x) + * #define DEH_printf printf + * #define DEH_fprintf fprintf + * #define DEH_snprintf snprintf + */ -#endif /* #ifndef DEH_STR_H */ +#endif /* DEH_STR_H */ diff --git a/zephyrdoom/src/deh_text.c b/zephyrdoom/src/deh_text.c index d9b22d7..f3066bc 100644 --- a/zephyrdoom/src/deh_text.c +++ b/zephyrdoom/src/deh_text.c @@ -1,19 +1,19 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// -// Parses Text substitution sections in dehacked files -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Parses Text substitution sections in dehacked files. + */ #include #include @@ -27,23 +27,23 @@ #include "deh_io.h" #include "deh_main.h" -// Given a string length, find the maximum length of a -// string that can replace it. - +/* + * Given a string length, find the maximum length of a + * string that can replace it. + */ static int TXT_MaxStringLength(int len) { - // Enough bytes for the string and the NUL terminator - + /* Enough bytes for the string and the NUL terminator */ len += 1; - // All strings in doom.exe are on 4-byte boundaries, so we may be able - // to support a slightly longer string. - // Extend up to the next 4-byte boundary - + /* + * All strings in doom.exe are on 4-byte boundaries, so we may be able + * to support a slightly longer string. + * Extend up to the next 4-byte boundary. + */ len += (4 - (len % 4)) % 4; - // Less one for the NUL terminator. - + /* Less one for the NUL terminator */ return len - 1; } @@ -59,9 +59,10 @@ static void *DEH_TextStart(deh_context_t *context, char *line) return NULL; } - // Only allow string replacements that are possible in Vanilla Doom. - // Chocolate Doom is unforgiving! - + /* + * Only allow string replacements that are possible in Vanilla Doom. + * Chocolate Doom is unforgiving! + */ if (!deh_allow_long_strings && tolen > TXT_MaxStringLength(fromlen)) { DEH_Error(context, "Replacement string is longer than the maximum " @@ -72,17 +73,15 @@ static void *DEH_TextStart(deh_context_t *context, char *line) from_text = malloc(fromlen + 1); to_text = malloc(tolen + 1); - // read in the "from" text - - for (i=0; i -#if !HAVE_DECL_STRCASECMP -#define strcasecmp stricmp -#endif -#if !HAVE_DECL_STRNCASECMP -#define strncasecmp strnicmp -#endif - -#else - -#include - -#endif -*/ - - -// -// The packed attribute forces structures to be packed into the minimum -// space necessary. If this is not done, the compiler may align structure -// fields differently to optimize memory access, inflating the overall -// structure size. It is important to use the packed attribute on certain -// structures where alignment is important, particularly data read/written -// to disk. -// + * #define macros to provide functions missing in Windows. + * Outside Windows, we use strings.h for str[n]casecmp. + */ +/* + * #if !HAVE_DECL_STRCASECMP || !HAVE_DECL_STRNCASECMP + * + * #include + * #if !HAVE_DECL_STRCASECMP + * #define strcasecmp stricmp + * #endif + * #if !HAVE_DECL_STRNCASECMP + * #define strncasecmp strnicmp + * #endif + * + * #else + * + * #include + * + * #endif + */ +/* + * The packed attribute forces structures to be packed into the minimum + * space necessary. If this is not done, the compiler may align structure + * fields differently to optimize memory access, inflating the overall + * structure size. It is important to use the packed attribute on certain + * structures where alignment is important, particularly data read/written + * to disk. + */ #ifdef __GNUC__ #if defined(_WIN32) && !defined(__clang__) -#define PACKEDATTR __attribute__((packed,gcc_struct)) +#define PACKEDATTR __attribute__((packed, gcc_struct)) #else #define PACKEDATTR __attribute__((packed)) #endif @@ -78,20 +76,19 @@ #define PACKED_STRUCT(...) PACKEDPREFIX struct __VA_ARGS__ PACKEDATTR -// C99 integer types; with gcc we just use this. Other compilers -// should add conditional statements that define the C99 types. - -// What is really wanted here is stdint.h; however, some old versions -// of Solaris don't have stdint.h and only have inttypes.h (the -// pre-standardisation version). inttypes.h is also in the C99 -// standard and defined to include stdint.h, so include this. - +/* + * C99 integer types, with gcc we just use this. Other compilers + * should add conditional statements that define the C99 types. + * What is really wanted here is stdint.h, however, some old versions + * of Solaris don't have stdint.h and only have inttypes.h (the + * pre-standardisation version). inttypes.h is also in the C99 + * standard and defined to include stdint.h, so include this. + */ #include #if defined(__cplusplus) || defined(__bool_true_false_are_defined) -// Use builtin bool type with C++. - +/* Use builtin bool type with C++ */ typedef uint8_t boolean; #else diff --git a/zephyrdoom/src/hardfault_handler_gcc.c b/zephyrdoom/src/hardfault_handler_gcc.c index 0042211..de795a3 100644 --- a/zephyrdoom/src/hardfault_handler_gcc.c +++ b/zephyrdoom/src/hardfault_handler_gcc.c @@ -42,39 +42,38 @@ extern void HardFault_c_handler(uint32_t *); -void HardFault_Handler(void) __attribute__(( naked )); +void HardFault_Handler(void) __attribute__((naked)); void HardFault_Handler(void) { __ASM volatile( - " tst lr, #4 \n" + " tst lr, #4 \n" - /* PSP is quite simple and does not require additional handler */ - " itt ne \n" - " mrsne r0, psp \n" - /* Jump to the handler, do not store LR - returning from handler just exits exception */ - " bne HardFault_Handler_Continue \n" + /* PSP is quite simple and does not require additional handler */ + " itt ne \n" + " mrsne r0, psp \n" + /* Jump to the handler, do not store LR - returning from handler just exits exception */ + " bne HardFault_Handler_Continue \n" - /* Processing MSP requires stack checking */ - " mrs r0, msp \n" + /* Processing MSP requires stack checking */ + " mrs r0, msp \n" - " ldr r1, =__StackTop \n" - " ldr r2, =__StackLimit \n" + " ldr r1, =__StackTop \n" + " ldr r2, =__StackLimit \n" - /* MSP is in the range of the stack area */ - " cmp r0, r1 \n" - " bhi HardFault_MoveSP \n" - " cmp r0, r2 \n" - " bhi HardFault_Handler_Continue \n" + /* MSP is in the range of the stack area */ + " cmp r0, r1 \n" + " bhi HardFault_MoveSP \n" + " cmp r0, r2 \n" + " bhi HardFault_Handler_Continue \n" - "HardFault_MoveSP: \n" - " mov sp, r1 \n" - " mov r0, #0 \n" + "HardFault_MoveSP: \n" + " mov sp, r1 \n" + " mov r0, #0 \n" - "HardFault_Handler_Continue: \n" - " ldr r3, =%0 \n" - " bx r3 \n" - " .ltorg \n" - : : "X"(HardFault_c_handler) - ); + "HardFault_Handler_Continue: \n" + " ldr r3, =%0 \n" + " bx r3 \n" + " .ltorg \n" + : : "X"(HardFault_c_handler)); } diff --git a/zephyrdoom/src/i_cdmus.h b/zephyrdoom/src/i_cdmus.h index 31db2a6..a43a0b8 100644 --- a/zephyrdoom/src/i_cdmus.h +++ b/zephyrdoom/src/i_cdmus.h @@ -1,30 +1,28 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 1993-2008 Raven Software -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// - -// i_cdmus.h +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 1993-2008 Raven Software + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ #ifndef __ICDMUS__ #define __ICDMUS__ -#define CDERR_NOTINSTALLED 10 // MSCDEX not installed -#define CDERR_NOAUDIOSUPPORT 11 // CD-ROM Doesn't support audio -#define CDERR_NOAUDIOTRACKS 12 // Current CD has no audio tracks -#define CDERR_BADDRIVE 20 // Bad drive number -#define CDERR_BADTRACK 21 // Bad track number -#define CDERR_IOCTLBUFFMEM 22 // Not enough low memory for IOCTL -#define CDERR_DEVREQBASE 100 // DevReq errors +#define CDERR_NOTINSTALLED 10 /* MSCDEX not installed */ +#define CDERR_NOAUDIOSUPPORT 11 /* CD-ROM Doesn't support audio */ +#define CDERR_NOAUDIOTRACKS 12 /* Current CD has no audio tracks */ +#define CDERR_BADDRIVE 20 /* Bad drive number */ +#define CDERR_BADTRACK 21 /* Bad track number */ +#define CDERR_IOCTLBUFFMEM 22 /* Not enough low memory for IOCTL */ +#define CDERR_DEVREQBASE 100 /* DevReq errors */ extern int cd_Error; @@ -38,4 +36,4 @@ int I_CDMusFirstTrack(void); int I_CDMusLastTrack(void); int I_CDMusTrackLength(int track); -#endif +#endif /* __ICDMUS__ */ diff --git a/zephyrdoom/src/i_endoom.h b/zephyrdoom/src/i_endoom.h index d4f973b..332858c 100644 --- a/zephyrdoom/src/i_endoom.h +++ b/zephyrdoom/src/i_endoom.h @@ -1,28 +1,25 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Exit text-mode ENDOOM screen. -// - +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Exit text-mode ENDOOM screen. + */ #ifndef __I_ENDOOM__ #define __I_ENDOOM__ -// Display the Endoom screen on shutdown. Pass a pointer to the -// ENDOOM lump. - +/* Display the Endoom screen on shutdown. Pass a pointer to the ENDOOM lump. */ void I_Endoom(byte *data); -#endif +#endif /* __I_ENDOOM__ */ diff --git a/zephyrdoom/src/i_input.c b/zephyrdoom/src/i_input.c index 0de1cbd..524639a 100644 --- a/zephyrdoom/src/i_input.c +++ b/zephyrdoom/src/i_input.c @@ -1,20 +1,20 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// NRF implementation of system-specific input interface. -// +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * NRF implementation of system-specific input interface. + */ #include @@ -27,105 +27,113 @@ static const int scancode_translate_table[] = SCANCODE_TO_KEYS_ARRAY; -// Lookup table for mapping ASCII characters to their equivalent when -// shift is pressed on a US layout keyboard. This is the original table -// as found in the Doom sources, comments and all. +/* + * Lookup table for mapping ASCII characters to their equivalent when + * shift is pressed on a US layout keyboard. This is the original table + * as found in the Doom sources, comments and all. + */ static const char shiftxform[] = -{ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, - 31, ' ', '!', '"', '#', '$', '%', '&', - '"', // shift-' - '(', ')', '*', '+', - '<', // shift-, - '_', // shift-- - '>', // shift-. - '?', // shift-/ - ')', // shift-0 - '!', // shift-1 - '@', // shift-2 - '#', // shift-3 - '$', // shift-4 - '%', // shift-5 - '^', // shift-6 - '&', // shift-7 - '*', // shift-8 - '(', // shift-9 - ':', - ':', // shift-; - '<', - '+', // shift-= - '>', '?', '@', - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', - 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - '[', // shift-[ - '!', // shift-backslash - OH MY GOD DOES WATCOM SUCK - ']', // shift-] - '"', '_', - '\'', // shift-` - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', - 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - '{', '|', '}', '~', 127 -}; + { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 31, ' ', '!', '"', '#', '$', '%', '&', + '"', /* shift-' */ + '(', ')', '*', '+', + '<', /* shift-, */ + '_', /* shift-- */ + '>', /* shift-. */ + '?', /* shift-/ */ + ')', /* shift-0 */ + '!', /* shift-1 */ + '@', /* shift-2 */ + '#', /* shift-3 */ + '$', /* shift-4 */ + '%', /* shift-5 */ + '^', /* shift-6 */ + '&', /* shift-7 */ + '*', /* shift-8 */ + '(', /* shift-9 */ + ':', + ':', /* shift-; */ + '<', + '+', /* shift-= */ + '>', '?', '@', + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', + 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + '[', /* shift-[ */ + '!', /* shift-backslash */ + ']', /* shift-] */ + '"', '_', + '\'', /* shift-` */ + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', + 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + '{', '|', '}', '~', 127}; -// If true, I_StartTextInput() has been called, and we are populating -// the data3 field of ev_keydown events. +/* + * If true, I_StartTextInput() has been called, and we are populating + * the data3 field of ev_keydown events. + */ static boolean text_input_enabled = true; -// Bit mask of mouse button state. +/* Bit mask of mouse button state. */ static unsigned int mouse_button_state = 0; -// Disallow mouse and joystick movement to cause forward/backward -// motion. Specified with the '-novert' command line parameter. -// This is an int to allow saving to config file +/* + * Disallow mouse and joystick movement to cause forward/backward + * motion. Specified with the '-novert' command line parameter. + * This is an int to allow saving to config file + */ int novert = 0; -// If true, keyboard mapping is ignored, like in Vanilla Doom. -// The sensible thing to do is to disable this if you have a non-US -// keyboard. - +/* + * If true, keyboard mapping is ignored, like in Vanilla Doom. + * The sensible thing to do is to disable this if you have a non-US + * keyboard. + */ const boolean vanilla_keyboard_mapping = true; -// Mouse acceleration -// -// This emulates some of the behavior of DOS mouse drivers by increasing -// the speed when the mouse is moved fast. -// -// The mouse input values are input directly to the game, but when -// the values exceed the value of mouse_threshold, they are multiplied -// by mouse_acceleration to increase the speed. +/* + * Mouse acceleration. + * + * This emulates some of the behavior of DOS mouse drivers by increasing + * the speed when the mouse is moved fast. + * + * The mouse input values are input directly to the game, but when + * the values exceed the value of mouse_threshold, they are multiplied + * by mouse_acceleration to increase the speed. + */ float mouse_acceleration = 2.0; int mouse_threshold = 10; - void I_StartTextInput(int x1, int y1, int x2, int y2) { - // NRFD-TODO? + /* NRFD-TODO */ } void I_StopTextInput(void) { - // NRFD-TODO? + /* NRFD-TODO */ } -// -// Read the change in mouse state to generate mouse motion events -// -// This is to combine all mouse movement for a tic into one mouse -// motion event. +/* + * Read the change in mouse state to generate mouse motion events. + * This is to combine all mouse movement for a tic into one mouse + * motion event. + */ void I_ReadMouse(void) { - // NRFD-TODO? + /* NRFD-TODO */ } -// Bind all variables controlling input options. +/* Bind all variables controlling input options. */ void I_BindInputVariables(void) { - printf("NRFD-TODO: I_BindInputVariables\n"); /* - M_BindFloatVariable("mouse_acceleration", &mouse_acceleration); - M_BindIntVariable("mouse_threshold", &mouse_threshold); - M_BindIntVariable("vanilla_keyboard_mapping", &vanilla_keyboard_mapping); - M_BindIntVariable("novert", &novert); - */ + /* + * NRFD-TODO + * M_BindFloatVariable("mouse_acceleration", &mouse_acceleration); + * M_BindIntVariable("mouse_threshold", &mouse_threshold); + * M_BindIntVariable("vanilla_keyboard_mapping", &vanilla_keyboard_mapping); + * M_BindIntVariable("novert", &novert); + */ } diff --git a/zephyrdoom/src/i_input.h b/zephyrdoom/src/i_input.h index 8e3b2f1..7200283 100644 --- a/zephyrdoom/src/i_input.h +++ b/zephyrdoom/src/i_input.h @@ -1,21 +1,20 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// System-specific keyboard/mouse input. -// - +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * System-specific keyboard/mouse input. + */ #ifndef __I_INPUT__ #define __I_INPUT__ @@ -30,13 +29,17 @@ extern int mouse_threshold; void I_BindInputVariables(void); void I_ReadMouse(void); -// I_StartTextInput begins text input, activating the on-screen keyboard -// (if one is used). The caller indicates that any entered text will be -// displayed in the rectangle given by the provided set of coordinates. +/* + * I_StartTextInput begins text input, activating the on-screen keyboard + * (if one is used). The caller indicates that any entered text will be + * displayed in the rectangle given by the provided set of coordinates. + */ void I_StartTextInput(int x1, int y1, int x2, int y2); -// I_StopTextInput finishes text input, deactivating the on-screen keyboard -// (if one is used). +/* + * I_StopTextInput finishes text input, deactivating the on-screen keyboard + * (if one is used). + */ void I_StopTextInput(void); -#endif +#endif /* __I_INPUT__ */ diff --git a/zephyrdoom/src/i_joystick.c b/zephyrdoom/src/i_joystick.c index 45aa3bc..a9a9eac 100644 --- a/zephyrdoom/src/i_joystick.c +++ b/zephyrdoom/src/i_joystick.c @@ -1,19 +1,19 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Joystick code. -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Joystick code. + */ #include #include @@ -27,110 +27,106 @@ #include "m_config.h" #include "m_misc.h" -// When an axis is within the dead zone, it is set to zero. -// This is 5% of the full range: - +/* + * When an axis is within the dead zone, it is set to zero. + * This is 5% of the full range. + */ #define DEAD_ZONE (32768 / 3) -/* NRFD-TODO - -static void *joystick = NULL; - -// Configuration variables: - -// Standard default.cfg Joystick enable/disable - -static int usejoystick = 0; - -// SDL GUID and index of the joystick to use. -static char *joystick_guid = ""; -static int joystick_index = -1; - -// Which joystick axis to use for horizontal movement, and whether to -// invert the direction: - -static int joystick_x_axis = 0; -static int joystick_x_invert = 0; - -// Which joystick axis to use for vertical movement, and whether to -// invert the direction: - -static int joystick_y_axis = 1; -static int joystick_y_invert = 0; - -// Which joystick axis to use for strafing? - -static int joystick_strafe_axis = -1; -static int joystick_strafe_invert = 0; - -// Which joystick axis to use for looking? - -static int joystick_look_axis = -1; -static int joystick_look_invert = 0; - -// Virtual to physical button joystick button mapping. By default this -// is a straight mapping. -static int joystick_physical_buttons[NUM_VIRTUAL_BUTTONS] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 -}; -void I_ShutdownJoystick(void) -{ - if (joystick != NULL) - { - joystick = NULL; - } -} -*/ +/* + * // NRFD-TODO + * + * static void *joystick = NULL; + * + * // Configuration variables + * // Standard default.cfg Joystick enable/disable + * static int usejoystick = 0; + * + * // SDL GUID and index of the joystick to use. + * static char *joystick_guid = ""; + * static int joystick_index = -1; + * + * // Which joystick axis to use for horizontal movement, and whether to + * // invert the direction. + * static int joystick_x_axis = 0; + * static int joystick_x_invert = 0; + * + * // Which joystick axis to use for vertical movement, and whether to + * // invert the direction. + * static int joystick_y_axis = 1; + * static int joystick_y_invert = 0; + * + * // Which joystick axis to use for strafing. + * static int joystick_strafe_axis = -1; + * static int joystick_strafe_invert = 0; + * + * // Which joystick axis to use for looking. + * static int joystick_look_axis = -1; + * static int joystick_look_invert = 0; + * + * // Virtual to physical button joystick button mapping. By default this + * // is a straight mapping. + * static int joystick_physical_buttons[NUM_VIRTUAL_BUTTONS] = { + * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * void I_ShutdownJoystick(void) + * { + * if (joystick != NULL) + * { + * joystick = NULL; + * } + * } + */ void I_InitJoystick(void) { - printf("NRFD_TODO: I_InitJoystick\n"); - - // I_AtExit(I_ShutdownJoystick, true); + /* + * NRFD-TODO + * I_AtExit(I_ShutdownJoystick, true); + */ } void I_UpdateJoystick(void) { - printf("NRFD_TODO: I_UpdateJoystick\n"); - /* - - if (joystick != NULL) - { - event_t ev; - - ev.type = ev_joystick; - ev.data1 = GetButtonsState(); - ev.data2 = GetAxisState(joystick_x_axis, joystick_x_invert); - ev.data3 = GetAxisState(joystick_y_axis, joystick_y_invert); - ev.data4 = GetAxisState(joystick_strafe_axis, joystick_strafe_invert); - ev.data5 = GetAxisState(joystick_look_axis, joystick_look_invert); - - D_PostEvent(&ev); - } - */ + /* + * NRFD-TODO + * if (joystick != NULL) + * { + * event_t ev; + * + * ev.type = ev_joystick; + * ev.data1 = GetButtonsState(); + * ev.data2 = GetAxisState(joystick_x_axis, joystick_x_invert); + * ev.data3 = GetAxisState(joystick_y_axis, joystick_y_invert); + * ev.data4 = GetAxisState(joystick_strafe_axis, joystick_strafe_invert); + * ev.data5 = GetAxisState(joystick_look_axis, joystick_look_invert); + * + * D_PostEvent(&ev); + * } + */ } void I_BindJoystickVariables(void) { - int i; - printf("NRFD-TODO: I_BindJoystickVariables\n");/* - M_BindIntVariable("use_joystick", &usejoystick); - M_BindStringVariable("joystick_guid", &joystick_guid); - M_BindIntVariable("joystick_index", &joystick_index); - M_BindIntVariable("joystick_x_axis", &joystick_x_axis); - M_BindIntVariable("joystick_y_axis", &joystick_y_axis); - M_BindIntVariable("joystick_strafe_axis", &joystick_strafe_axis); - M_BindIntVariable("joystick_x_invert", &joystick_x_invert); - M_BindIntVariable("joystick_y_invert", &joystick_y_invert); - M_BindIntVariable("joystick_strafe_invert",&joystick_strafe_invert); - M_BindIntVariable("joystick_look_axis", &joystick_look_axis); - M_BindIntVariable("joystick_look_invert", &joystick_look_invert); - - for (i = 0; i < NUM_VIRTUAL_BUTTONS; ++i) - { - char name[32]; - M_snprintf(name, sizeof(name), "joystick_physical_button%i", i); - M_BindIntVariable(name, &joystick_physical_buttons[i]); - } - */ + /* + * NRFD-TODO + * int i; + * M_BindIntVariable("use_joystick", &usejoystick); + * M_BindStringVariable("joystick_guid", &joystick_guid); + * M_BindIntVariable("joystick_index", &joystick_index); + * M_BindIntVariable("joystick_x_axis", &joystick_x_axis); + * M_BindIntVariable("joystick_y_axis", &joystick_y_axis); + * M_BindIntVariable("joystick_strafe_axis", &joystick_strafe_axis); + * M_BindIntVariable("joystick_x_invert", &joystick_x_invert); + * M_BindIntVariable("joystick_y_invert", &joystick_y_invert); + * M_BindIntVariable("joystick_strafe_invert", &joystick_strafe_invert); + * M_BindIntVariable("joystick_look_axis", &joystick_look_axis); + * M_BindIntVariable("joystick_look_invert", &joystick_look_invert); + * + * for (i = 0; i < NUM_VIRTUAL_BUTTONS; ++i) + * { + * char name[32]; + * M_snprintf(name, sizeof(name), "joystick_physical_button%i", i); + * M_BindIntVariable(name, &joystick_physical_buttons[i]); + * } + */ } diff --git a/zephyrdoom/src/i_joystick.h b/zephyrdoom/src/i_joystick.h index b693ab1..16b4ab2 100644 --- a/zephyrdoom/src/i_joystick.h +++ b/zephyrdoom/src/i_joystick.h @@ -1,64 +1,69 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// System-specific joystick interface. -// - +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * System-specific joystick interface. + */ #ifndef __I_JOYSTICK__ #define __I_JOYSTICK__ -// Number of "virtual" joystick buttons defined in configuration files. -// This needs to be at least as large as the number of different key -// bindings supported by the higher-level game code (joyb* variables). +/* + * Number of "virtual" joystick buttons defined in configuration files. + * This needs to be at least as large as the number of different key + * bindings supported by the higher-level game code (joyb* variables). + */ #define NUM_VIRTUAL_BUTTONS 11 -// If this bit is set in a configuration file axis value, the axis is -// not actually a joystick axis, but instead is a "button axis". This -// means that instead of reading an SDL joystick axis, we read the -// state of two buttons to get the axis value. This is needed for eg. -// the PS3 SIXAXIS controller, where the D-pad buttons register as -// buttons, not as two axes. +/* + * If this bit is set in a configuration file axis value, the axis is + * not actually a joystick axis, but instead is a "button axis". This + * means that instead of reading an SDL joystick axis, we read the + * state of two buttons to get the axis value. This is needed for e.g. + * the PS3 SIXAXIS controller, where the D-pad buttons register as + * buttons, not as two axes. + */ #define BUTTON_AXIS 0x10000 -// Query whether a given axis value describes a button axis. +/* Query whether a given axis value describes a button axis. */ #define IS_BUTTON_AXIS(axis) ((axis) >= 0 && ((axis) & BUTTON_AXIS) != 0) -// Get the individual buttons from a button axis value. -#define BUTTON_AXIS_NEG(axis) ((axis) & 0xff) -#define BUTTON_AXIS_POS(axis) (((axis) >> 8) & 0xff) +/* Get the individual buttons from a button axis value. */ +#define BUTTON_AXIS_NEG(axis) ((axis) & 0xff) +#define BUTTON_AXIS_POS(axis) (((axis) >> 8) & 0xff) -// Create a button axis value from two button values. +/* Create a button axis value from two button values. */ #define CREATE_BUTTON_AXIS(neg, pos) (BUTTON_AXIS | (neg) | ((pos) << 8)) -// If this bit is set in an axis value, the axis is not actually a -// joystick axis, but is a "hat" axis. This means that we read (one of) -// the hats on the joystick. -#define HAT_AXIS 0x20000 +/* + * If this bit is set in an axis value, the axis is not actually a + * joystick axis, but is a "hat" axis. This means that we read (one of) + * the hats on the joystick. + */ +#define HAT_AXIS 0x20000 #define IS_HAT_AXIS(axis) ((axis) >= 0 && ((axis) & HAT_AXIS) != 0) -// Get the hat number from a hat axis value. -#define HAT_AXIS_HAT(axis) ((axis) & 0xff) -// Which axis of the hat? (horizonal or vertical) -#define HAT_AXIS_DIRECTION(axis) (((axis) >> 8) & 0xff) +/* Get the hat number from a hat axis value. */ +#define HAT_AXIS_HAT(axis) ((axis) & 0xff) + +/* Which axis of the hat (horizonal or vertical). */ +#define HAT_AXIS_DIRECTION(axis) (((axis) >> 8) & 0xff) -#define CREATE_HAT_AXIS(hat, direction) \ - (HAT_AXIS | (hat) | ((direction) << 8)) +#define CREATE_HAT_AXIS(hat, direction) (HAT_AXIS | (hat) | ((direction) << 8)) #define HAT_AXIS_HORIZONTAL 1 -#define HAT_AXIS_VERTICAL 2 +#define HAT_AXIS_VERTICAL 2 void I_InitJoystick(void); void I_ShutdownJoystick(void); @@ -66,4 +71,4 @@ void I_UpdateJoystick(void); void I_BindJoystickVariables(void); -#endif /* #ifndef __I_JOYSTICK__ */ +#endif /* __I_JOYSTICK__ */ diff --git a/zephyrdoom/src/i_sound.c b/zephyrdoom/src/i_sound.c index 5c12813..f216be7 100644 --- a/zephyrdoom/src/i_sound.c +++ b/zephyrdoom/src/i_sound.c @@ -1,19 +1,17 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: none -// +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ #include #include @@ -21,103 +19,102 @@ #include "doom_config.h" #include "doomtype.h" -//#include "gusconf.h" #include "i_sound.h" #include "i_video.h" #include "m_argv.h" #include "m_config.h" -// Sound sample rate to use for digital output (Hz) - +/* Sound sample rate to use for digital output (Hz). */ int snd_samplerate = 44100; -// Maximum number of bytes to dedicate to allocated sound effects. -// (Default: 64MB) - +/* + * Maximum number of bytes to dedicate to allocated sound effects. + * (Default: 64MB). + */ int snd_cachesize = 64 * 1024 * 1024; -// Config variable that controls the sound buffer size. -// We default to 28ms (1000 / 35fps = 1 buffer per tic). - +/* + * Config variable that controls the sound buffer size. + * We default to 28ms (1000 / 35fps = 1 buffer per tic). + */ int snd_maxslicetime_ms = 28; -// External command to invoke to play back music. - +/* External command to invoke to play back music. */ char *snd_musiccmd = ""; -// Whether to vary the pitch of sound effects -// Each game will set the default differently - +/* + * Whether to vary the pitch of sound effects. + * Each game will set the default differently. + */ int snd_pitchshift = -1; -// Low-level sound and music modules we are using - +/* Low-level sound and music modules we are using. */ static sound_module_t *sound_module; static music_module_t *music_module; int snd_musicdevice = SNDDEVICE_SB; int snd_sfxdevice = SNDDEVICE_SB; -// Sound modules -/* NRFD-TODO? -extern void I_InitTimidityConfig(void); -extern sound_module_t sound_sdl_module; -extern sound_module_t sound_pcsound_module; -extern music_module_t music_sdl_module; -extern music_module_t music_opl_module; - -// For OPL module: - -extern opl_driver_ver_t opl_drv_ver; -extern int opl_io_port; - -// For native music module: - -extern char *music_pack_path; -extern char *timidity_cfg_path; -*/ - +/* + * // NRFD-TODO + * // Sound modules + * extern void I_InitTimidityConfig(void); + * extern sound_module_t sound_sdl_module; + * extern sound_module_t sound_pcsound_module; + * extern music_module_t music_sdl_module; + * extern music_module_t music_opl_module; + * + * // For OPL module + * extern opl_driver_ver_t opl_drv_ver; + * extern int opl_io_port; + * + * // For native music module + * extern char *music_pack_path; + * extern char *timidity_cfg_path; + */ extern sound_module_t sound_i2s_module; -// DOS-specific options: These are unused but should be maintained -// so that the config file can be shared between chocolate -// doom and doom.exe - +/* + * DOS-specific options. These are unused but should be maintained + * so that the config file can be shared between chocolate + * doom and doom.exe + */ static int snd_sbport = 0; static int snd_sbirq = 0; static int snd_sbdma = 0; static int snd_mport = 0; -// Compiled-in sound modules: - +/* Compiled-in sound modules. */ static sound_module_t *sound_modules[] = -{ - // NRFD-TODO? - &sound_i2s_module, - // &sound_sdl_module, - //&sound_pcsound_module, - NULL, + { + &sound_i2s_module, + NULL + /* + * // NRFD-TODO + * &sound_sdl_module + * &sound_pcsound_module + */ }; -// Compiled-in music modules: - +/* Compiled-in music modules. */ static music_module_t *music_modules[] = -{ - // NRFD-TODO? - //&music_sdl_module, - //&music_opl_module, - NULL, + { + NULL + /* + * // NRFD-TODO + * &music_sdl_module + * &music_opl_module + */ }; -// Check if a sound device is in the given list of devices - +/* Check if a sound device is in the given list of devices */ static boolean SndDeviceInList(snddevice_t device, snddevice_t *list, int len) { int i; - for (i=0; isound_devices, + * sound_modules[i]->num_sound_devices)) + * { + * // Initialize the module + */ + + if (1) { - // Is the sfx device in the list of devices supported by - // this module? - - if (SndDeviceInList(snd_sfxdevice, - sound_modules[i]->sound_devices, - sound_modules[i]->num_sound_devices)) + /* + * NRFD-TODO + * Add settings. + */ + i = 0; + if (sound_modules[i]->Init(use_sfx_prefix)) { - // Initialize the module - */ - if (1) { // NRFD-TODO: Setting? - i = 0; - if (sound_modules[i]->Init(use_sfx_prefix)) - { - sound_module = sound_modules[i]; - return; - } - } - /* + sound_module = sound_modules[i]; + return; } } - */ -} -// Initialize music according to snd_musicdevice. + /* + * } + * } + */ +} +/* Initialize music according to snd_musicdevice. */ static void InitMusicModule(void) { int i; music_module = NULL; - for (i=0; music_modules[i] != NULL; ++i) + for (i = 0; music_modules[i] != NULL; ++i) { - // Is the music device in the list of devices supported - // by this module? - + /* + * Is the music device in the list of devices supported + * by this module. + */ if (SndDeviceInList(snd_musicdevice, music_modules[i]->sound_devices, music_modules[i]->num_sound_devices)) { - // Initialize the module - + /* Initialize the module */ if (music_modules[i]->Init()) { music_module = music_modules[i]; @@ -191,12 +195,11 @@ static void InitMusicModule(void) } } -// -// Initializes sound stuff, including volume -// Sets channels, SFX and music volume, -// allocates channel buffer, sets S_sfx lookup. -// - +/* + * Initializes sound stuff, including volume. + * Sets channels, SFX and music volume, + * allocates channel buffer, sets S_sfx lookup. + */ void I_InitSound(boolean use_sfx_prefix) { boolean nosound, nosfx, nomusic; @@ -206,53 +209,53 @@ void I_InitSound(boolean use_sfx_prefix) // // Disable all sound output. // - - nosound = false; //M_CheckParm("-nosound") > 0; + nosound = false; + /* M_CheckParm("-nosound") > 0; */ //! // @vanilla // // Disable sound effects. // - - nosfx = false; //M_CheckParm("-nosfx") > 0; + nosfx = false; + /* M_CheckParm("-nosfx") > 0; */ //! // @vanilla // // Disable music. // + /* + * NRFD-TODO + * Add music. + */ + nomusic = true; + /* M_CheckParm("-nomusic") > 0; */ - // NRFD-TODO: Music - nomusic = true; //M_CheckParm("-nomusic") > 0; - - // Initialize the sound and music subsystems. - - // NRD-Exclude: - // if (!nosound && !screensaver_mode) - // { - // // This is kind of a hack. If native MIDI is enabled, set up - // // the TIMIDITY_CFG environment variable here before SDL_mixer - // // is opened. - - // if (!nomusic - // && (snd_musicdevice == SNDDEVICE_GENMIDI - // || snd_musicdevice == SNDDEVICE_GUS)) - // { - // I_InitTimidityConfig(); - // } - - if (!nosfx) - { - InitSfxModule(use_sfx_prefix); - } - - if (!nomusic) - { - InitMusicModule(); - } - // } + /* + * // Initialize the sound and music subsystems. + * // NRD-Exclude: + * // if (!nosound && !screensaver_mode) + * // { + * // // This is kind of a hack. If native MIDI is enabled, set up + * // // the TIMIDITY_CFG environment variable here before SDL_mixer + * // // is opened. + * // if (!nomusic && (snd_musicdevice == SNDDEVICE_GENMIDI || snd_musicdevice == SNDDEVICE_GUS)) + * // { + * // I_InitTimidityConfig(); + * // } + */ + + if (!nosfx) + { + InitSfxModule(use_sfx_prefix); + } + if (!nomusic) + { + InitMusicModule(); + } + /* } */ } void I_ShutdownSound(void) @@ -370,7 +373,6 @@ void I_InitMusic(void) void I_ShutdownMusic(void) { - } void I_SetMusicVolume(int volume) @@ -447,5 +449,5 @@ boolean I_MusicIsPlaying(void) void I_BindSoundVariables(void) { - // NRFD-Exclude + /* NRFD-EXCLUDE */ } diff --git a/zephyrdoom/src/i_sound.h b/zephyrdoom/src/i_sound.h index c71bca2..93bb0fb 100644 --- a/zephyrdoom/src/i_sound.h +++ b/zephyrdoom/src/i_sound.h @@ -1,90 +1,86 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// The not so system specific sound interface. -// - +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * The not so system specific sound interface. + */ #ifndef __I_SOUND__ #define __I_SOUND__ #include "doomtype.h" -// so that the individual game logic and sound driver code agree +/* So that the individual game logic and sound driver code agree */ #define NORM_PITCH 127 -// -// SoundFX struct. -// -typedef struct sfxinfo_struct sfxinfo_t; +/* SoundFX struct. */ +typedef struct sfxinfo_struct sfxinfo_t; struct sfxinfo_struct { - // tag name, used for hexen. + /* Tag name, used for Hexen */ char *tagname; - // lump name. If we are running with use_sfx_prefix=true, a - // 'DS' (or 'DP' for PC speaker sounds) is prepended to this. - + /* + * lump name. If we are running with use_sfx_prefix=true, a + * 'DS' (or 'DP' for PC speaker sounds) is prepended to this. + */ char name[9]; - // Sfx priority + /* Sfx priority */ int priority; - // referenced sound if a link + /* Referenced sound if a link */ sfxinfo_t *link; - // pitch if a link (Doom), whether to pitch-shift (Hexen) + /* Pitch if a link (Doom), whether to pitch-shift (Hexen) */ int pitch; - // volume if a link + /* Volume if a link */ int volume; - // this is checked every second to see if sound - // can be thrown out (if 0, then decrement, if -1, - // then throw out, if > 0, then it is in use) + /* + * This is checked every second to see if sound + * can be thrown out (if 0, then decrement, if -1, + * then throw out, if > 0, then it is in use). + */ int usefulness; - // lump number of sfx + /* lump number of sfx */ int lumpnum; - // Maximum number of channels that the sound can be played on - // (Heretic) + /* Maximum number of channels that the sound can be played on (Heretic) */ int numchannels; - // data used by the low level code + /* Data used by the low level code */ void *driver_data; }; -// -// MusicInfo struct. -// +/* MusicInfo struct. */ typedef struct { - // up to 6-character name + /* Up to 6-character name */ char *name; - // lump number of music + /* lump number of music */ int lumpnum; - // music data + /* Music data */ void *data; - // music handle once registered + /* Music handle once registered */ void *handle; - } musicinfo_t; typedef enum @@ -102,53 +98,45 @@ typedef enum SNDDEVICE_CD = 10, } snddevice_t; -// Interface for sound modules - +/* Interface for sound modules. */ typedef struct { - // List of sound devices that this sound module is used for. - + /* List of sound devices that this sound module is used for */ snddevice_t *sound_devices; int num_sound_devices; - // Initialise sound module - // Returns true if successfully initialised - + /* + * Initialise sound module. + * Returns true if successfully initialised. + */ boolean (*Init)(boolean use_sfx_prefix); - // Shutdown sound module - + /* Shutdown sound module */ void (*Shutdown)(void); - // Returns the lump index of the given sound. - + /* Returns the lump index of the given sound */ int (*GetSfxLumpNum)(sfxinfo_t *sfxinfo); - // Called periodically to update the subsystem. - + /* Called periodically to update the subsystem */ void (*Update)(void); - // Update the sound settings on the given channel. - + /* Update the sound settings on the given channel */ void (*UpdateSoundParams)(int channel, int vol, int sep); - // Start a sound on a given channel. Returns the channel id - // or -1 on failure. - + /* + * Start a sound on a given channel. Returns the channel id + * or -1 on failure. + */ int (*StartSound)(sfxinfo_t *sfxinfo, int channel, int vol, int sep, int pitch); - // Stop the sound playing on the given channel. - + /* Stop the sound playing on the given channel */ void (*StopSound)(int channel); - // Query if a sound is playing on the given channel - + /* Query if a sound is playing on the given channel */ boolean (*SoundIsPlaying)(int channel); - // Called on startup to precache sound effects (if necessary) - + /* Called on startup to precache sound effects (if necessary) */ void (*CacheSounds)(sfxinfo_t *sounds, int num_sounds); - } sound_module_t; void I_InitSound(boolean use_sfx_prefix); @@ -161,58 +149,47 @@ void I_StopSound(int channel); boolean I_SoundIsPlaying(int channel); void I_PrecacheSounds(sfxinfo_t *sounds, int num_sounds); -// Interface for music modules - +/* Interface for music modules. */ typedef struct { - // List of sound devices that this music module is used for. - + /* List of sound devices that this music module is used for */ snddevice_t *sound_devices; int num_sound_devices; - // Initialise the music subsystem - + /* Initialise the music subsystem */ boolean (*Init)(void); - // Shutdown the music subsystem - + /* Shutdown the music subsystem */ void (*Shutdown)(void); - // Set music volume - range 0-127 - + /* Set music volume - range 0-127 */ void (*SetMusicVolume)(int volume); - // Pause music - + /* Pause music */ void (*PauseMusic)(void); - // Un-pause music - + /* Un-pause music */ void (*ResumeMusic)(void); - // Register a song handle from data - // Returns a handle that can be used to play the song - + /* + * Register a song handle from data. + * Returns a handle that can be used to play the song. + */ void *(*RegisterSong)(void *data, int len); - // Un-register (free) song data - + /* Un-register (free) song data */ void (*UnRegisterSong)(void *handle); - // Play the song - + /* Play the song */ void (*PlaySong)(void *handle, boolean looping); - // Stop playing the current song. - + /* Stop playing the current song */ void (*StopSong)(void); - // Query if music is playing. - + /* Query if music is playing */ boolean (*MusicIsPlaying)(void); - // Invoked periodically to poll. - + /* Invoked periodically to poll */ void (*Poll)(void); } music_module_t; @@ -237,13 +214,14 @@ extern int snd_pitchshift; void I_BindSoundVariables(void); -// DMX version to emulate for OPL emulation: -typedef enum { - opl_doom1_1_666, // Doom 1 v1.666 - opl_doom2_1_666, // Doom 2 v1.666, Hexen, Heretic - opl_doom_1_9 // Doom v1.9, Strife +/* DMX version to emulate for OPL emulation. */ +typedef enum +{ + opl_doom1_1_666, /* Doom 1 v1.666 */ + opl_doom2_1_666, /* Doom 2 v1.666, Hexen, Heretic */ + opl_doom_1_9 /* Doom v1.9, Strife */ } opl_driver_ver_t; void I_SetOPLDriverVer(opl_driver_ver_t ver); -#endif +#endif /* __I_SOUND__ */ diff --git a/zephyrdoom/src/i_swap.h b/zephyrdoom/src/i_swap.h index bd74810..36c3581 100644 --- a/zephyrdoom/src/i_swap.h +++ b/zephyrdoom/src/i_swap.h @@ -1,37 +1,33 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Endianess handling, swapping 16bit and 32bit. -// - +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Endianess handling, swapping 16 bit and 32 bit. + * WAD files are stored little endian. + */ #ifndef __I_SWAP__ #define __I_SWAP__ +/* + * These are deliberately cast to signed values, this is the behaviour + * of the macros in the original source and some code relies on it. + */ +#define SHORT(x) ((signed short)(x)) +#define LONG(x) ((signed int)(x)) -// Endianess handling. -// WAD files are stored little endian. - -// These are deliberately cast to signed values; this is the behaviour -// of the macros in the original source and some code relies on it. - -#define SHORT(x) ((signed short) (x)) -#define LONG(x) ((signed int) (x)) - -// Defines for checking the endianness of the system. - -//#define SYS_BIG_ENDIAN +/* Defines for checking the endianness of the system. */ +/* #define SYS_BIG_ENDIAN */ -#endif +#endif /* __I_SWAP__ */ diff --git a/zephyrdoom/src/i_system.c b/zephyrdoom/src/i_system.c index 50425f6..e05a633 100644 --- a/zephyrdoom/src/i_system.c +++ b/zephyrdoom/src/i_system.c @@ -1,21 +1,17 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// - - +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ #include #include @@ -25,7 +21,11 @@ #include "doom_config.h" -//NRFD-TODO: #include "deh_str.h" +/* + * NRFD-TODO + * #include "deh_str.h" + */ + #include "doomtype.h" #include "m_argv.h" @@ -42,120 +42,121 @@ #include "z_zone.h" #define DEFAULT_RAM 16 /* MiB */ -#define MIN_RAM 4 /* MiB */ +#define MIN_RAM 4 /* MiB */ -/* NRFD-EXCLUDE: -typedef struct atexit_listentry_s atexit_listentry_t; - -struct atexit_listentry_s -{ - atexit_func_t func; - boolean run_on_error; - atexit_listentry_t *next; -}; - -static atexit_listentry_t *exit_funcs = NULL; -*/ +/* + * // NRFD-EXCLUDE + * typedef struct atexit_listentry_s atexit_listentry_t; + * + * struct atexit_listentry_s + * { + * atexit_func_t func; + * boolean run_on_error; + * atexit_listentry_t *next; + * }; + * + * static atexit_listentry_t *exit_funcs = NULL; + */ void I_AtExit(atexit_func_t func, boolean run_on_error) { - /*NRFD-EXCLUDE - atexit_listentry_t *entry; - - entry = malloc(sizeof(*entry)); - - entry->func = func; - entry->run_on_error = run_on_error; - entry->next = exit_funcs; - exit_funcs = entry; - */ + /* + * // NRFD-EXCLUDE + * atexit_listentry_t *entry; + * + * entry = malloc(sizeof(*entry)); + * + * entry->func = func; + * entry->run_on_error = run_on_error; + * entry->next = exit_funcs; + * exit_funcs = entry; + */ } -// Tactile feedback function, probably used for the Logitech Cyberman - +/* Tactile feedback function, probably used for the Logitech Cyberman. */ void I_Tactile(int on, int off, int total) { } -// Zone memory auto-allocation function that allocates the zone size -// by trying progressively smaller zone sizes until one is found that -// works. - +/* + * Zone memory auto-allocation function that allocates the zone size + * by trying progressively smaller zone sizes until one is found that + * works. + */ static byte *AutoAllocMemory(int *size, int default_ram, int min_ram) { - printf("TODO AutoAllocMemory\n"); return NULL; - /* NRFD-TODO: - byte *zonemem; - - // Allocate the zone memory. This loop tries progressively smaller - // zone sizes until a size is found that can be allocated. - // If we used the -mb command line parameter, only the parameter - // provided is accepted. - - zonemem = NULL; - - while (zonemem == NULL) - { - // We need a reasonable minimum amount of RAM to start. - - if (default_ram < min_ram) - { - I_Error("Unable to allocate %i MiB of RAM for zone", default_ram); - } - - // Try to allocate the zone memory. - - *size = default_ram * 1024 * 1024; - - zonemem = malloc(*size); - - // Failed to allocate? Reduce zone size until we reach a size - // that is acceptable. - - if (zonemem == NULL) - { - default_ram -= 1; - } - } - - return zonemem; - */ + return NULL; + + /* + * // NRFD-TODO + * byte *zonemem; + * + * // Allocate the zone memory. This loop tries progressively smaller + * // zone sizes until a size is found that can be allocated. + * // If we used the -mb command line parameter, only the parameter + * // provided is accepted. + * zonemem = NULL; + * + * while (zonemem == NULL) + * { + * // We need a reasonable minimum amount of RAM to start. + * if (default_ram < min_ram) + * { + * I_Error("Unable to allocate %i MiB of RAM for zone", default_ram); + * } + * + * // Try to allocate the zone memory. + * *size = default_ram * 1024 * 1024; + * + * zonemem = malloc(*size); + * + * // Failed to allocate. Reduce zone size until we reach a size + * // that is acceptable. + * if (zonemem == NULL) + * { + * default_ram -= 1; + * } + * } + * + * return zonemem; + */ } -byte *I_ZoneBase (int *size) +byte *I_ZoneBase(int *size) { - printf("TODO I_ZoneBase\n"); return NULL; - /* NRFD-TODO: - byte *zonemem; - int min_ram, default_ram; - int p; - - //! - // @arg - // - // Specify the heap size, in MiB (default 16). - // - - p = M_CheckParmWithArgs("-mb", 1); - - if (p > 0) - { - default_ram = atoi(myargv[p+1]); - min_ram = default_ram; - } - else - { - default_ram = DEFAULT_RAM; - min_ram = MIN_RAM; - } - - zonemem = AutoAllocMemory(size, default_ram, min_ram); - - printf("zone memory: %p, %x allocated for zone\n", - zonemem, *size); - - return zonemem; - */ + return NULL; + + /* + * // NRFD-TODO + * byte *zonemem; + * int min_ram, default_ram; + * int p; + * + * //! + * // @arg + * // + * // Specify the heap size, in MiB (default 16). + * // + * p = M_CheckParmWithArgs("-mb", 1); + * + * if (p > 0) + * { + * default_ram = atoi(myargv[p + 1]); + * min_ram = default_ram; + * } + * else + * { + * default_ram = DEFAULT_RAM; + * min_ram = MIN_RAM; + * } + * + * zonemem = AutoAllocMemory(size, default_ram, min_ram); + * + * printf("zone memory: %p, %x allocated for zone\n", + * zonemem, *size); + * + * return zonemem; + */ } void I_PrintBanner(char *msg) @@ -163,7 +164,7 @@ void I_PrintBanner(char *msg) int i; int spaces = 35 - (strlen(msg) / 2); - for (i=0; i + * // + * // Specify DOS version to emulate for NULL pointer dereference + * // emulation. Supported versions are: dos622, dos71, dosbox. + * // The default is to emulate DOS 7.1 (Windows 98). + * // + * p = M_CheckParmWithArgs("-setmem", 1); + * + * if (p > 0) + * { + * if (!strcasecmp(myargv[p + 1], "dos622")) + * { + * dos_mem_dump = mem_dump_dos622; + * } + * if (!strcasecmp(myargv[p + 1], "dos71")) + * { + * dos_mem_dump = mem_dump_win98; + * } + * else if (!strcasecmp(myargv[p + 1], "dosbox")) + * { + * dos_mem_dump = mem_dump_dosbox; + * } + * else + * { + * for (i = 0; i < DOS_MEM_DUMP_SIZE; ++i) + * { + * ++p; + * + * if (p >= myargc || myargv[p][0] == '-') + * { + * break; + * } + * + * M_StrToInt(myargv[p], &val); + * mem_dump_custom[i++] = (unsigned char) val; + * } + * + * dos_mem_dump = mem_dump_custom; + * } + * } + * } + * + * switch (size) + * { + * case 1: + * *((unsigned char *) value) = dos_mem_dump[offset]; + * return true; + * case 2: + * *((unsigned short *) value) = dos_mem_dump[offset] + * | (dos_mem_dump[offset + 1] << 8); + * return true; + * case 4: + * *((unsigned int *) value) = dos_mem_dump[offset] + * | (dos_mem_dump[offset + 1] << 8) + * | (dos_mem_dump[offset + 2] << 16) + * | (dos_mem_dump[offset + 3] << 24); + * return true; + * } + */ return false; } diff --git a/zephyrdoom/src/i_system.h b/zephyrdoom/src/i_system.h index 6b7876c..732429a 100644 --- a/zephyrdoom/src/i_system.h +++ b/zephyrdoom/src/i_system.h @@ -1,21 +1,20 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// System specific interface stuff. -// - +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * System specific interface stuff. + */ #ifndef __I_SYSTEM__ #define __I_SYSTEM__ @@ -24,63 +23,59 @@ #include "d_ticcmd.h" #include "d_event.h" - typedef void (*atexit_func_t)(void); -// Called by DoomMain. -void I_Init (void); +/* Called by DoomMain. */ +void I_Init(void); -// Called by startup code -// to get the ammount of memory to malloc -// for the zone management. -byte* I_ZoneBase (int *size); +/* + * Called by startup code to get the ammount of memory to malloc + * for the zone management. + */ +byte *I_ZoneBase(int *size); boolean I_ConsoleStdout(void); +/* + * Asynchronous interrupt functions should maintain private queues + * that are read by the synchronous functions to be converted into events. + * + * Either returns a null ticcmd, or calls a loadable driver to build it. + * This ticcmd will then be modified by the gameloop for normal input. + */ +ticcmd_t *I_BaseTiccmd(void); -// Asynchronous interrupt functions should maintain private queues -// that are read by the synchronous functions -// to be converted into events. - -// Either returns a null ticcmd, -// or calls a loadable driver to build it. -// This ticcmd will then be modified by the gameloop -// for normal input. -ticcmd_t* I_BaseTiccmd (void); - - -// Called by M_Responder when quit is selected. -// Clean exit, displays sell blurb. -void I_Quit (void); +/* + * Called by M_Responder when quit is selected. + * Clean exit, displays sell blurb. + */ +void I_Quit(void); -void I_Error (char *error, ...); +void I_Error(char *error, ...); -void I_Tactile (int on, int off, int total); +void I_Tactile(int on, int off, int total); void *I_Realloc(void *ptr, size_t size); boolean I_GetMemoryValue(unsigned int offset, void *value, int size); -// Schedule a function to be called when the program exits. -// If run_if_error is true, the function is called if the exit -// is due to an error (I_Error) - +/* + * Schedule a function to be called when the program exits. + * If run_if_error is true, the function is called if the exit + * is due to an error (I_Error). + */ void I_AtExit(atexit_func_t func, boolean run_if_error); -// Add all system-specific config file variable bindings. - +/* Add all system-specific config file variable bindings. */ void I_BindVariables(void); -// Print startup banner copyright message. - +/* Print startup banner copyright message. */ void I_PrintStartupBanner(char *gamedescription); -// Print a centered text banner displaying the given string. - +/* Print a centered text banner displaying the given string. */ void I_PrintBanner(char *text); -// Print a dividing line for startup banners. - +/* Print a dividing line for startup banners. */ void I_PrintDivider(void); -#endif +#endif /* __I_SYSTEM__ */ diff --git a/zephyrdoom/src/i_timer.c b/zephyrdoom/src/i_timer.c index d358b94..d659522 100644 --- a/zephyrdoom/src/i_timer.c +++ b/zephyrdoom/src/i_timer.c @@ -1,20 +1,20 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Timer functions. -// +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Timer functions. + */ #include "i_timer.h" @@ -22,38 +22,34 @@ #include #include "board_config.h" -// -// I_GetTime -// returns time in 1/35th second tics -// +/* static Uint32 basetime = 0; */ -//static Uint32 basetime = 0; +/* + * NRFD-TODO + * Handle overflow of timer. + */ -// NRFD-TODO: Handle overflow of timer - -int I_GetTime (void) +/* Returns time in 1/35th second tics */ +int I_GetTime(void) { NRF_DOOM_TIMER->TASKS_CAPTURE[0] = 1; uint64_t cc = NRF_DOOM_TIMER->CC[0]; - uint64_t tickTime = (cc * TICRATE)*10/312/1000; + uint64_t tickTime = (cc * TICRATE) * 10 / 312 / 1000; return tickTime; } -// -// Same as I_GetTime, but returns time in milliseconds -// - +/* Same as I_GetTime, but returns time in milliseconds. */ int I_GetTimeMS(void) { NRF_DOOM_TIMER->TASKS_CAPTURE[0] = 1; uint64_t cc = NRF_DOOM_TIMER->CC[0]; - cc = cc*10/312; + cc = cc * 10 / 312; return cc; } uint32_t I_RawTimeToFps(uint32_t time_delta) { - return 31200/time_delta; + return 31200 / time_delta; } uint32_t I_GetTimeRaw(void) @@ -63,14 +59,12 @@ uint32_t I_GetTimeRaw(void) return cc; } -// Sleep for a specified number of ms - +/* Sleep for a specified number of ms. */ void I_Sleep(int ms) { k_msleep(ms); } - void I_SleepUS(int us) { k_usleep(us); @@ -81,16 +75,19 @@ void I_WaitVBL(int count) I_Sleep((count * 1000) / 70); } - void I_InitTimer(void) { - // initialize timer + /* Initialize timer */ NRF_DOOM_TIMER->MODE = TIMER_MODE_MODE_Timer; NRF_DOOM_TIMER->BITMODE = TIMER_BITMODE_BITMODE_32Bit; NRF_DOOM_TIMER->PRESCALER = 9; - // fTIMER = 16 MHz / (2*PRESCALER) - // 2**9 = 512 - // fTIMER = 31.25Khz; - // NOTE: If timer is changed, update HU_Ticker (or make global variable) + + /* + * fTIMER = 16 MHz / (2*PRESCALER) + * 2**9 = 512 + * fTIMER = 31.25Khz; + */ + + /* If timer is changed, update HU_Ticker (or make global variable) */ NRF_DOOM_TIMER->TASKS_START = 1; } diff --git a/zephyrdoom/src/i_timer.h b/zephyrdoom/src/i_timer.h index f8db6ad..63e6b26 100644 --- a/zephyrdoom/src/i_timer.h +++ b/zephyrdoom/src/i_timer.h @@ -1,21 +1,20 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// System-specific timer interface -// - +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * System-specific timer interface. + */ #ifndef __I_TIMER__ #define __I_TIMER__ @@ -24,28 +23,25 @@ #include "doomtype.h" -// Called by D_DoomLoop, -// returns current time in tics. -int I_GetTime (void); +/* Called by D_DoomLoop, returns current time in tics. */ +int I_GetTime(void); -// returns current time in ms -int I_GetTimeMS (void); -uint32_t I_GetTimeRaw (void); +/* Returns current time in ms. */ +int I_GetTimeMS(void); +uint32_t I_GetTimeRaw(void); uint32_t I_RawTimeToFps(uint32_t time_delta); -// Pause for a specified number of ms +/* Pause for a specified number of ms. */ void I_Sleep(int ms); -// Pause for a specified number of us +/* Pause for a specified number of us. */ void I_SleepUS(int us); -// Initialize timer +/* Initialize timer. */ void I_InitTimer(void); -// Wait for vertical retrace or pause a bit. +/* Wait for vertical retrace or pause a bit. */ void I_WaitVBL(int count); - - -#endif +#endif /* __I_TIMER__ */ diff --git a/zephyrdoom/src/i_video.c b/zephyrdoom/src/i_video.c index 2564b54..6876303 100644 --- a/zephyrdoom/src/i_video.c +++ b/zephyrdoom/src/i_video.c @@ -1,23 +1,25 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// DOOM graphics stuff for NRF. -// - - -// NRFD-EXCLUDE: #include "icon.c" +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * DOOM graphics stuff for NRF. + */ + +/* + * NRFD-EXCLUDE + * #include "icon.c" + */ #include @@ -47,138 +49,124 @@ static uint32_t pixel_format; - -// display has been set up? - +/* Display has been set up. */ static boolean initialized = false; -// disable mouse? - +/* Disable mouse */ const boolean nomouse = true; const int usemouse = 1; -// Save screenshots in PNG format. - -// int png_screenshots = 0; - -// SDL video driver name - -// char *video_driver = ""; - -// Window position: - -// char *window_position = "center"; - -// SDL display number on which to run. - -// int video_display = 0; - -// Screen width and height, from configuration file. - -// int window_width = SCREENWIDTH * 2; -// int window_height = SCREENHEIGHT_4_3 * 2; - -// Fullscreen mode, 0x0 for SDL_WINDOW_FULLSCREEN_DESKTOP. - -// int fullscreen_width = 0, fullscreen_height = 0; - -// Maximum number of pixels to use for intermediate scale buffer. - -// static int max_scaling_buffer_pixels = 16000000; - -// Run in full screen mode? (int type for config code) - -// int fullscreen = true; - -// Aspect ratio correction mode - -// int aspect_ratio_correct = true; -// static int actualheight; - -// Force integer scales for resolution-independent rendering - -// int integer_scaling = false; - -// VGA Porch palette change emulation - -// const int vga_porch_flash = false; - -// Force software rendering, for systems which lack effective hardware -// acceleration - -// int force_software_renderer = false; - -// Time to wait for the screen to settle on startup before starting the -// game (ms) - -// const int startup_delay = 1000; - -// Grab the mouse? (int type for config code). nograbmouse_override allows -// this to be temporarily disabled via the command line. - -// const int grabmouse = true; -// const boolean nograbmouse_override = false; - -// The screen buffer; this is modified to draw things to the screen - -pixel_t *I_VideoBuffer; //[320*200]; -pixel_t *I_VideoBackBuffer; //[320*200]; -pixel_t I_VideoBuffers[2][320*200]; - -uint8_t display_pal[DISPLAY_PALETTE_SIZE]; +/* + * TODO + * // Save screenshots in PNG format. + * // int png_screenshots = 0; + * + * // SDL video driver name. + * // char *video_driver = ""; + * + * // Window position. + * // char *window_position = "center"; + * + * // SDL display number on which to run. + * // int video_display = 0; + * + * // Screen width and height, from configuration file. + * // int window_width = SCREENWIDTH * 2; + * // int window_height = SCREENHEIGHT_4_3 * 2; + * + * // Fullscreen mode, 0x0 for SDL_WINDOW_FULLSCREEN_DESKTOP. + * // int fullscreen_width = 0, fullscreen_height = 0; + * + * // Maximum number of pixels to use for intermediate scale buffer. + * // static int max_scaling_buffer_pixels = 16000000; + * + * // Run in full screen mode (int type for config code). + * // int fullscreen = true; + * + * // Aspect ratio correction mode. + * // int aspect_ratio_correct = true; + * // static int actualheight; + * + * // Force integer scales for resolution-independent rendering. + * // int integer_scaling = false; + * + * // VGA Porch palette change emulation. + * // const int vga_porch_flash = false; + * + * // Force software rendering, for systems which lack effective hardware + * // acceleration. + * // int force_software_renderer = false; + * + * // Time to wait for the screen to settle on startup before starting the + * // game (ms). + * // const int startup_delay = 1000; + * + * // Grab the mouse (int type for config code). nograbmouse_override allows + * // this to be temporarily disabled via the command line. + * // const int grabmouse = true; + * // const boolean nograbmouse_override = false; + */ + +/* The screen buffer, this is modified to draw things to the screen. */ +pixel_t *I_VideoBuffer; +pixel_t *I_VideoBackBuffer; +pixel_t I_VideoBuffers[2][320 * 200]; + +uint8_t display_pal[DISPLAY_PALETTE_SIZE]; static int current_dl; -// Memory references for display driver memory -static uint32_t display_vbuffer_locs[3]; // Frame buffer -static uint32_t display_palette_locs[3]; // Pallette - -// If true, game is running as a screensaver +/* Memory references for display driver memory. */ +static uint32_t display_vbuffer_locs[3]; /* Frame buffer */ +static uint32_t display_palette_locs[3]; /* Pallette */ +/* If true, game is running as a screensaver. */ const boolean screensaver_mode = false; -// Flag indicating whether the screen is currently visible: -// when the screen isnt visible, don't render the screen - +/* + * Flag indicating whether the screen is currently visible. + * When the screen is not visible, don't render the screen. + */ const boolean screenvisible = true; -// If true, we display dots at the bottom of the screen to -// indicate FPS. - +/* If true, we display dots at the bottom of the screen to indicate FPS. */ const boolean display_fps_dots = false; -// If this is true, the screen is rendered but not blitted to the -// video buffer. - +/* + * If this is true, the screen is rendered but not blitted to the + * video buffer. + */ const boolean noblit = false; -// Gamma correction level to use - +/* Gamma correction level to use. */ byte usegamma = 1; -// Joystick/gamepad hysteresis +/* Joystick/gamepad hysteresis. */ unsigned int joywait = 0; void PrintVBuffer(void) { - // pixel_t *vb = I_VideoBuffer; - // printf("%.2X %.2X %.2X %2X %.2X %.2X %.2X %2X\n", - // vb[0], vb[1], vb[2], vb[3], - // vb[4], vb[5], vb[6], vb[7]); - // printf("%.2X %.2X %.2X %2X %.2X %.2X %.2X %2X\n", - // vb[1*SCREENWIDTH+0], vb[1*SCREENWIDTH+1], vb[1*SCREENWIDTH+2], vb[1*SCREENWIDTH+3], - // vb[1*SCREENWIDTH+4], vb[1*SCREENWIDTH+5], vb[1*SCREENWIDTH+6], vb[1*SCREENWIDTH+7]); + /* + * TODO + * pixel_t *vb = I_VideoBuffer; + * printf("%.2X %.2X %.2X %2X %.2X %.2X %.2X %2X\n", + * vb[0], vb[1], vb[2], vb[3], + * vb[4], vb[5], vb[6], vb[7]); + * printf("%.2X %.2X %.2X %2X %.2X %.2X %.2X %2X\n", + * vb[1 * SCREENWIDTH + 0], vb[1 * SCREENWIDTH + 1], vb[1 * SCREENWIDTH + 2], vb[1 * SCREENWIDTH + 3], + * vb[1 * SCREENWIDTH + 4], vb[1 * SCREENWIDTH + 5], vb[1 * SCREENWIDTH + 6], vb[1 * SCREENWIDTH + 7]); + */ } - -// Set the variable controlling FPS dots. - +/* Set the variable controlling FPS dots. */ void I_DisplayFPSDots(boolean dots_on) { - // display_fps_dots = dots_on; + /* + * TODO + * display_fps_dots = dots_on; + */ } - void I_ShutdownGraphics(void) { if (initialized) @@ -187,44 +175,41 @@ void I_ShutdownGraphics(void) } } - - -// -// I_StartFrame -// -void I_StartFrame (void) +void I_StartFrame(void) { - // N_display_spi_transfer_finish(); + /* + * TODO + * N_display_spi_transfer_finish(); + */ } static void I_ToggleFullScreen(void) { - //NRFD-EXCLUDE + /* NRFD-EXCLUDE */ } void I_GenerateEvents(void) { N_ReadButtons(); - // printf("%d %d\n", joywait, I_GetTime()); if (joywait < I_GetTime()) { joywait = 0; N_rjoy_read(); - // I_UpdateJoystick(); + /* I_UpdateJoystick(); */ } - /* NRFD-TODO: mouse? - if (usemouse && !nomouse) - { - I_ReadMouse(); - }*/ + /* + * // NRFD-TODO + * // Configure mouse. + * if (usemouse && !nomouse) + * { + * I_ReadMouse(); + * } + */ } -// -// I_StartTic -// -void I_StartTic (void) +void I_StartTic(void) { N_ldbg("NRFD-TODO: I_StartTic\n"); if (!initialized) @@ -233,16 +218,11 @@ void I_StartTic (void) } I_GenerateEvents(); - } - -// -// I_UpdateNoBlit -// -void I_UpdateNoBlit (void) +void I_UpdateNoBlit(void) { - // what is this? + /* TODO */ } void I_WriteDisplayList(uint32_t pal_loc, uint32_t display_loc) @@ -250,44 +230,44 @@ void I_WriteDisplayList(uint32_t pal_loc, uint32_t display_loc) dl_start(); dl(FT810_CLEAR_COLOR_RGB(0x00, 0x00, 0x00)); - dl(FT810_CLEAR(1,1,1)); // Clear color, stencil, tag + dl(FT810_CLEAR(1, 1, 1)); /* Clear color, stencil, tag */ dl(FT810_CLEAR_COLOR_RGB(0x00, 0x00, 0x00)); - dl(FT810_CLEAR(1,0,0)); // Clear color + dl(FT810_CLEAR(1, 0, 0)); /* Clear color */ - dl(FT810_BITMAP_HANDLE(0)) ; - dl(FT810_BITMAP_LAYOUT(PALETTED8, SCREENWIDTH, SCREENHEIGHT)) ; - int16_t trans_a = (int16_t)(256/2.0); - int16_t trans_b = (int16_t)(256/2.4); + dl(FT810_BITMAP_HANDLE(0)); + dl(FT810_BITMAP_LAYOUT(PALETTED8, SCREENWIDTH, SCREENHEIGHT)); + int16_t trans_a = (int16_t)(256 / 2.0); + int16_t trans_b = (int16_t)(256 / 2.4); dl(FT810_BITMAP_TRANSFORM_A(trans_a)); dl(FT810_BITMAP_TRANSFORM_E(trans_b)); - dl(FT810_BITMAP_SIZE(NEAREST, BORDER, BORDER, 640&0x1FF, 480)); - dl(FT810_BITMAP_SIZE_H(640>>9, 0)); - dl(FT810_BITMAP_SOURCE(display_loc)) ; + dl(FT810_BITMAP_SIZE(NEAREST, BORDER, BORDER, 640 & 0x1FF, 480)); + dl(FT810_BITMAP_SIZE_H(640 >> 9, 0)); + dl(FT810_BITMAP_SOURCE(display_loc)); dl(FT810_COLOR_RGB(0xFF, 0xFF, 0xFF)); dl(FT810_BEGIN(BITMAPS)); { - dl(FT810_VERTEX_TRANSLATE_X(80*16)); - // dl(FT810_VERTEX_TRANSLATE_Y(0*16)); + dl(FT810_VERTEX_TRANSLATE_X(80 * 16)); + /* dl(FT810_VERTEX_TRANSLATE_Y(0*16)); */ dl(FT810_BLEND_FUNC(ONE, ZERO)); - dl(FT810_COLOR_MASK(0,0,0,1)); - dl(FT810_PALETTE_SOURCE(pal_loc+3)); + dl(FT810_COLOR_MASK(0, 0, 0, 1)); + dl(FT810_PALETTE_SOURCE(pal_loc + 3)); dl(FT810_VERTEX2II(0, 0, 0, 0)); dl(FT810_BLEND_FUNC(DST_ALPHA, ONE_MINUS_DST_ALPHA)); - dl(FT810_COLOR_MASK(1,0,0,0)); + dl(FT810_COLOR_MASK(1, 0, 0, 0)); dl(FT810_PALETTE_SOURCE(pal_loc)); dl(FT810_VERTEX2II(0, 0, 0, 0)); - dl(FT810_COLOR_MASK(0,1,0,0)); - dl(FT810_PALETTE_SOURCE(pal_loc+1)); + dl(FT810_COLOR_MASK(0, 1, 0, 0)); + dl(FT810_PALETTE_SOURCE(pal_loc + 1)); dl(FT810_VERTEX2II(0, 0, 0, 0)); - dl(FT810_COLOR_MASK(0,0,1,0)); - dl(FT810_PALETTE_SOURCE(pal_loc+2)); + dl(FT810_COLOR_MASK(0, 0, 1, 0)); + dl(FT810_PALETTE_SOURCE(pal_loc + 2)); dl(FT810_VERTEX2II(0, 0, 0, 0)); } dl(FT810_END()); @@ -297,131 +277,120 @@ void I_WriteDisplayList(uint32_t pal_loc, uint32_t display_loc) N_display_dlswap_frame(); } -// -// I_FinishUpdate -// -void I_FinishUpdate (void) +void I_FinishUpdate(void) { static int lasttic; int tics; int i; - // draws little dots on the bottom of the screen + /* Draws little dots on the bottom of the screen */ if (display_fps_dots) { i = I_GetTime(); tics = i - lasttic; lasttic = i; - if (tics > 20) tics = 20; + if (tics > 20) + tics = 20; - for (i=0 ; i 0; + /* + * NRFD-EXCLUDE + * nomouse = M_CheckParm("-nomouse") > 0; + */ } - - void I_InitGraphics(void) { printf("I_InitGraphics\n"); @@ -462,62 +431,78 @@ void I_InitGraphics(void) display_palette_locs[0] = N_display_ram_alloc(DISPLAY_PALETTE_SIZE); display_palette_locs[1] = N_display_ram_alloc(DISPLAY_PALETTE_SIZE); display_palette_locs[2] = N_display_ram_alloc(DISPLAY_PALETTE_SIZE); - display_vbuffer_locs[0] = N_display_ram_alloc(SCREENWIDTH*SCREENHEIGHT); - display_vbuffer_locs[1] = N_display_ram_alloc(SCREENWIDTH*SCREENHEIGHT); - display_vbuffer_locs[2] = N_display_ram_alloc(SCREENWIDTH*SCREENHEIGHT); + display_vbuffer_locs[0] = N_display_ram_alloc(SCREENWIDTH * SCREENHEIGHT); + display_vbuffer_locs[1] = N_display_ram_alloc(SCREENWIDTH * SCREENHEIGHT); + display_vbuffer_locs[2] = N_display_ram_alloc(SCREENWIDTH * SCREENHEIGHT); current_dl = 1; - // I_WriteDisplayList(display_palette_locs[0], display_vbuffer_locs[0]); - // I_WriteDisplayList(display_palette_locs[1], display_vbuffer_locs[1]); + /* + * I_WriteDisplayList(display_palette_locs[0], display_vbuffer_locs[0]); + * I_WriteDisplayList(display_palette_locs[1], display_vbuffer_locs[1]); + */ I_VideoBuffer = I_VideoBuffers[1]; I_VideoBackBuffer = I_VideoBuffers[0]; initialized = true; } -// Bind all variables controlling video options into the configuration -// file system. +/* + * Bind all variables controlling video options into the configuration + * file system. + */ void I_BindVideoVariables(void) { - // NRFD-TODO:? - // M_BindIntVariable("use_mouse", &usemouse); - // M_BindIntVariable("fullscreen", &fullscreen); - // M_BindIntVariable("video_display", &video_display); - // M_BindIntVariable("aspect_ratio_correct", &aspect_ratio_correct); - // M_BindIntVariable("integer_scaling", &integer_scaling); - // M_BindIntVariable("vga_porch_flash", &vga_porch_flash); - // M_BindIntVariable("startup_delay", &startup_delay); - // M_BindIntVariable("fullscreen_width", &fullscreen_width); - // M_BindIntVariable("fullscreen_height", &fullscreen_height); - // M_BindIntVariable("force_software_renderer", &force_software_renderer); - // M_BindIntVariable("max_scaling_buffer_pixels", &max_scaling_buffer_pixels); - // M_BindIntVariable("window_width", &window_width); - // M_BindIntVariable("window_height", &window_height); - // M_BindIntVariable("grabmouse", &grabmouse); - // M_BindStringVariable("video_driver", &video_driver); - // M_BindStringVariable("window_position", &window_position); - // M_BindIntVariable("usegamma", &usegamma); - // M_BindIntVariable("png_screenshots", &png_screenshots); + /* + * // NRFD-TODO + * M_BindIntVariable("use_mouse", &usemouse); + * M_BindIntVariable("fullscreen", &fullscreen); + * M_BindIntVariable("video_display", &video_display); + * M_BindIntVariable("aspect_ratio_correct", &aspect_ratio_correct); + * M_BindIntVariable("integer_scaling", &integer_scaling); + * M_BindIntVariable("vga_porch_flash", &vga_porch_flash); + * M_BindIntVariable("startup_delay", &startup_delay); + * M_BindIntVariable("fullscreen_width", &fullscreen_width); + * M_BindIntVariable("fullscreen_height", &fullscreen_height); + * M_BindIntVariable("force_software_renderer", &force_software_renderer); + * M_BindIntVariable("max_scaling_buffer_pixels", &max_scaling_buffer_pixels); + * M_BindIntVariable("window_width", &window_width); + * M_BindIntVariable("window_height", &window_height); + * M_BindIntVariable("grabmouse", &grabmouse); + * M_BindStringVariable("video_driver", &video_driver); + * M_BindStringVariable("window_position", &window_position); + * M_BindIntVariable("usegamma", &usegamma); + * M_BindIntVariable("png_screenshots", &png_screenshots); + */ } -// Rename to StartUpdate? +/* + * TODO + * Rename to StartUpdate + */ void I_ClearVideoBuffer(void) { - // N_display_spi_transfer_finish(); + /* N_display_spi_transfer_finish(); */ - // Swap buffers - if (I_VideoBuffer == I_VideoBuffers[0]) { + /* Swap buffers */ + if (I_VideoBuffer == I_VideoBuffers[0]) + { I_VideoBuffer = I_VideoBuffers[1]; I_VideoBackBuffer = I_VideoBuffers[0]; } - else { + else + { I_VideoBuffer = I_VideoBuffers[0]; I_VideoBackBuffer = I_VideoBuffers[1]; } V_RestoreBuffer(); - // for (int i=0; i #include @@ -24,41 +21,35 @@ #include "doomtype.h" #include "i_system.h" #include "m_misc.h" -#include "m_argv.h" // haleyjd 20110212: warning fix - -int myargc; -char** myargv; +#include "m_argv.h" /* haleyjd 20110212: Warning fix */ -// -// M_CheckParm -// Checks for the given parameter -// in the program's command line arguments. -// Returns the argument number (1 to argc-1) -// or 0 if not present -// +int myargc; +char **myargv; +/* + * Checks for the given parameter in the program's command line arguments. + * Returns the argument number (1 to argc-1) or 0 if not present. + */ int M_CheckParmWithArgs(char *check, int num_args) { - // NRFD-EXCLUDE /* - int i; + * // NRFD-EXCLUDE + * int i; + * + * for (i = 1; i < myargc - num_args; i++) + * { + * if (!strcasecmp(check, myargv[i])) + * return i; + * } + */ - for (i = 1; i < myargc - num_args; i++) - { - if (!strcasecmp(check, myargv[i])) - return i; - } -*/ return 0; } -// -// M_ParmExists -// -// Returns true if the given parameter exists in the program's command -// line arguments, false if not. -// - +/* + * Returns true if the given parameter exists in the program's command + * line arguments, false if not. + */ boolean M_ParmExists(char *check) { return M_CheckParm(check) != 0; @@ -69,188 +60,175 @@ int M_CheckParm(char *check) return M_CheckParmWithArgs(check, 0); } -#define MAXARGVS 100 +#define MAXARGVS 100 static void LoadResponseFile(int argv_index) { - // NRFD-EXCLUDE /* - FILE *handle; - int size; - char *infile; - char *file; - char *response_filename; - char **newargv; - int newargc; - int i, k; - - response_filename = myargv[argv_index] + 1; - - // Read the response file into memory - handle = fopen(response_filename, "rb"); - - if (handle == NULL) - { - printf ("\nNo such response file!"); - exit(1); - } - - printf("Found response file %s!\n", response_filename); - - size = M_FileLength(handle); - - // Read in the entire file - // Allocate one byte extra - this is in case there is an argument - // at the end of the response file, in which case a '\0' will be - // needed. - - file = malloc(size + 1); - - i = 0; - - while (i < size) - { - k = fread(file + i, 1, size - i, handle); - - if (k < 0) - { - I_Error("Failed to read full contents of '%s'", response_filename); - } - - i += k; - } - - fclose(handle); - - // Create new arguments list array - - newargv = malloc(sizeof(char *) * MAXARGVS); - newargc = 0; - memset(newargv, 0, sizeof(char *) * MAXARGVS); - - // Copy all the arguments in the list up to the response file - - for (i=0; i= size) - { - break; - } - - // If the next argument is enclosed in quote marks, treat - // the contents as a single argument. This allows long filenames - // to be specified. - - if (infile[k] == '\"') - { - // Skip the first character(") - ++k; - - newargv[newargc++] = &infile[k]; - - // Read all characters between quotes - - while (k < size && infile[k] != '\"' && infile[k] != '\n') - { - ++k; - } - - if (k >= size || infile[k] == '\n') - { - I_Error("Quotes unclosed in response file '%s'", - response_filename); - } - - // Cut off the string at the closing quote - - infile[k] = '\0'; - ++k; - } - else - { - // Read in the next argument until a space is reached - - newargv[newargc++] = &infile[k]; - - while(k < size && !isspace(infile[k])) - { - ++k; - } - - // Cut off the end of the argument at the first space - - infile[k] = '\0'; - - ++k; - } - } - - // Add arguments following the response file argument - - for (i=argv_index + 1; i= size) + * { + * break; + * } + * + * // If the next argument is enclosed in quote marks, treat + * // the contents as a single argument. This allows long filenames + * // to be specified. + * if (infile[k] == '\"') + * { + * // Skip the first character(") + * ++k; + * + * newargv[newargc++] = &infile[k]; + * + * // Read all characters between quotes + * while (k < size && infile[k] != '\"' && infile[k] != '\n') + * { + * ++k; + * } + * + * if (k >= size || infile[k] == '\n') + * { + * I_Error("Quotes unclosed in response file '%s'", + * response_filename); + * } + * + * // Cut off the string at the closing quote + * infile[k] = '\0'; + * ++k; + * } + * else + * { + * // Read in the next argument until a space is reached + * newargv[newargc++] = &infile[k]; + * + * while (k < size && !isspace(infile[k])) + * { + * ++k; + * } + * + * // Cut off the end of the argument at the first space + * infile[k] = '\0'; + * + * ++k; + * } + * } + * + * // Add arguments following the response file argument + * for (i = argv_index + 1; i < myargc; ++i) + * { + * newargv[newargc] = myargv[i]; + * ++newargc; + * } + * + * myargv = newargv; + * myargc = newargc; + * + * #if 0 + * // Disabled - Vanilla Doom does not do this. + * + * // Display arguments + * printf("%d command-line args:\n", myargc); + * + * for (k=1; kbox[BOXRIGHT]) - box[BOXRIGHT] = x; - if (ybox[BOXTOP]) - box[BOXTOP] = y; + if (x < box[BOXLEFT]) + box[BOXLEFT] = x; + else if (x > box[BOXRIGHT]) + box[BOXRIGHT] = x; + if (y < box[BOXBOTTOM]) + box[BOXBOTTOM] = y; + else if (y > box[BOXTOP]) + box[BOXTOP] = y; } diff --git a/zephyrdoom/src/m_bbox.h b/zephyrdoom/src/m_bbox.h index 4eabc0f..7fa3a74 100644 --- a/zephyrdoom/src/m_bbox.h +++ b/zephyrdoom/src/m_bbox.h @@ -1,21 +1,17 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Nil. -// - +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ #ifndef __M_BBOX__ #define __M_BBOX__ @@ -24,24 +20,20 @@ #include "m_fixed.h" - -// Bounding box coordinate storage. +/* Bounding box coordinate storage. */ enum { BOXTOP, BOXBOTTOM, BOXLEFT, BOXRIGHT -}; // bbox coordinates - -// Bounding box functions. -void M_ClearBox (fixed_t* box); +}; -void -M_AddToBox -( fixed_t* box, - fixed_t x, - fixed_t y ); +/* Bounding box functions. */ +void M_ClearBox(fixed_t *box); +void M_AddToBox(fixed_t *box, + fixed_t x, + fixed_t y); -#endif +#endif /* __M_BBOX__ */ diff --git a/zephyrdoom/src/m_cheat.c b/zephyrdoom/src/m_cheat.c index 928aea0..7832b39 100644 --- a/zephyrdoom/src/m_cheat.c +++ b/zephyrdoom/src/m_cheat.c @@ -1,53 +1,45 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Cheat sequence checking. -// - - +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Cheat sequence checking/package. + */ #include #include "doomtype.h" #include "m_cheat.h" -// -// CHEAT SEQUENCE PACKAGE -// - -// -// Called in st_stuff module, which handles the input. -// Returns a 1 if the cheat was successful, 0 if failed. -// -int -cht_CheckCheat -( cheatseq_t* cht, - char key ) +/* + * Called in st_stuff module, which handles the input. + * Returns a 1 if the cheat was successful, 0 if failed. + */ +int cht_CheckCheat(cheatseq_t *cht, char key) { - // if we make a short sequence on a cheat with parameters, this - // will not work in vanilla doom. behave the same. - + /* + * Uf we make a short sequence on a cheat with parameters, this + * will not work in Vanilla Doom. + */ if (cht->parameter_chars > 0 && strlen(cht->sequence) < cht->sequence_len) return false; if (cht->chars_read < strlen(cht->sequence)) { - // still reading characters from the cheat code - // and verifying. reset back to the beginning - // if a key is wrong - + /* + * Still reading characters from the cheat code and verifying. + * Reset back to the beginning if a key is wrong. + */ if (key == cht->sequence[cht->chars_read]) ++cht->chars_read; else @@ -57,31 +49,28 @@ cht_CheckCheat } else if (cht->param_chars_read < cht->parameter_chars) { - // we have passed the end of the cheat sequence and are - // entering parameters now - + /* + * We have passed the end of the cheat sequence and are + * entering parameters now. + */ cht->parameter_buf[cht->param_chars_read] = key; ++cht->param_chars_read; } - if (cht->chars_read >= strlen(cht->sequence) - && cht->param_chars_read >= cht->parameter_chars) + if (cht->chars_read >= strlen(cht->sequence) && cht->param_chars_read >= cht->parameter_chars) { cht->chars_read = cht->param_chars_read = 0; return true; } - // cheat not matched yet - + /* Cheat not matched yet */ return false; } -void -cht_GetParam -( cheatseq_t* cht, - char* buffer ) +void cht_GetParam(cheatseq_t *cht, + char *buffer) { memcpy(buffer, cht->parameter_buf, cht->parameter_chars); } diff --git a/zephyrdoom/src/m_cheat.h b/zephyrdoom/src/m_cheat.h index cccabb8..4602ece 100644 --- a/zephyrdoom/src/m_cheat.h +++ b/zephyrdoom/src/m_cheat.h @@ -1,62 +1,46 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Cheat code checking. -// - +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Cheat code checking/package. + */ #ifndef __M_CHEAT__ #define __M_CHEAT__ -// -// CHEAT SEQUENCE PACKAGE -// - -// declaring a cheat - +/* Declaring a cheat. */ #define CHEAT(value, parameters) \ - { value, sizeof(value) - 1, parameters, 0, 0, "" } + {value, sizeof(value) - 1, parameters, 0, 0, ""} #define MAX_CHEAT_LEN 25 #define MAX_CHEAT_PARAMS 5 typedef struct __attribute__((packed)) { - // settings for this cheat - + /* Settings for this cheat */ char sequence[MAX_CHEAT_LEN]; uint8_t sequence_len; uint8_t parameter_chars; - // state used during the game - + /* State used during the game */ uint8_t chars_read; uint8_t param_chars_read; char parameter_buf[MAX_CHEAT_PARAMS]; } cheatseq_t; -int -cht_CheckCheat -( cheatseq_t* cht, - char key ); - - -void -cht_GetParam -( cheatseq_t* cht, - char* buffer ); +int cht_CheckCheat(cheatseq_t *cht, char key); +void cht_GetParam(cheatseq_t *cht, char *buffer); -#endif +#endif /* __M_CHEAT__ */ diff --git a/zephyrdoom/src/m_config.c b/zephyrdoom/src/m_config.c index cb9897e..cd66b1f 100644 --- a/zephyrdoom/src/m_config.c +++ b/zephyrdoom/src/m_config.c @@ -1,1688 +1,1493 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 1993-2008 Raven Software -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Configuration file interface. -// +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 1993-2008 Raven Software + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Configuration file interface. + */ +#include +#include +#include +#include +#include +#include -#include -#include -#include -#include -#include -#include - -#include "doom_config.h" - -#include "doomtype.h" -#include "doomkeys.h" -#include "i_system.h" -#include "m_argv.h" -#include "m_misc.h" - -#include "z_zone.h" - -// -// DEFAULTS -// - -// Location where all configuration data is stored - -// default.cfg, savegames, etc. - -const char *configdir = ""; - -// Default filenames for configuration files. - -const char *default_main_config = "default.cfg"; -const char *default_extra_config = "nrf-doom.cfg"; - -typedef enum -{ - DEFAULT_INT, - DEFAULT_INT_HEX, - DEFAULT_STRING, - DEFAULT_FLOAT, - DEFAULT_KEY, -} default_type_t; - -typedef struct -{ - // Name of the variable - char *name; - - // Pointer to the location in memory of the variable - union { - int *i; - char **s; - float *f; - } location; - - // Type of the variable - default_type_t type; - - // If this is a key value, the original integer scancode we read from - // the config file before translating it to the internal key value. - // If zero, we didn't read this value from a config file. - // int untranslated; - - // The value we translated the scancode into when we read the - // config file on startup. If the variable value is different from - // this, it has been changed and needs to be converted; otherwise, - // use the 'untranslated' value. - // int original_translated; - - // If true, this config variable has been bound to a variable - // and is being used. - boolean bound; -} default_t; - -typedef struct -{ - default_t *defaults; - int numdefaults; - char *filename; -} default_collection_t; - - - -#define CONFIG_VARIABLE_GENERIC(name, type) \ - { #name, {NULL}, type, false } -// NRFD-TODO? key translate -// { #name, {NULL}, type, 0, 0, false } - -#define CONFIG_VARIABLE_KEY(name) \ - CONFIG_VARIABLE_GENERIC(name, DEFAULT_KEY) -#define CONFIG_VARIABLE_INT(name) \ - CONFIG_VARIABLE_GENERIC(name, DEFAULT_INT) -#define CONFIG_VARIABLE_INT_HEX(name) \ - CONFIG_VARIABLE_GENERIC(name, DEFAULT_INT_HEX) -#define CONFIG_VARIABLE_FLOAT(name) \ - CONFIG_VARIABLE_GENERIC(name, DEFAULT_FLOAT) -#define CONFIG_VARIABLE_STRING(name) \ - CONFIG_VARIABLE_GENERIC(name, DEFAULT_STRING) - -//! @begin_config_file default - -// NRFD-TODO: Add back some configs? -static default_t doom_defaults_list[] = -{ - //! - // Mouse sensitivity. This value is used to multiply input mouse - // movement to control the effect of moving the mouse. - // - // The "normal" maximum value available for this through the - // in-game options menu is 9. A value of 31 or greater will cause - // the game to crash when entering the options menu. - // - - CONFIG_VARIABLE_INT(mouse_sensitivity), - - //! - // Volume of sound effects, range 0-15. - // - - CONFIG_VARIABLE_INT(sfx_volume), - - //! - // Volume of in-game music, range 0-15. - // - - CONFIG_VARIABLE_INT(music_volume), - - //! - // @game strife - // - // If non-zero, dialogue text is displayed over characters' pictures - // when engaging actors who have voices. - // - - // CONFIG_VARIABLE_INT(show_talk), - - //! - // @game strife - // - // Volume of voice sound effects, range 0-15. - // - - CONFIG_VARIABLE_INT(voice_volume), - - //! - // @game doom - // - // If non-zero, messages are displayed on the heads-up display - // in the game ("picked up a clip", etc). If zero, these messages - // are not displayed. - // - - CONFIG_VARIABLE_INT(show_messages), - - /* NRFD-TODO: Configurable controls - - //! - // Keyboard key to turn right. - // - - CONFIG_VARIABLE_KEY(key_right), - - //! - // Keyboard key to turn left. - // - - CONFIG_VARIABLE_KEY(key_left), - - //! - // Keyboard key to move forward. - // - - CONFIG_VARIABLE_KEY(key_up), - - //! - // Keyboard key to move backward. - // - - CONFIG_VARIABLE_KEY(key_down), - - //! - // Keyboard key to strafe left. - // - - CONFIG_VARIABLE_KEY(key_strafeleft), - - //! - // Keyboard key to strafe right. - // - - CONFIG_VARIABLE_KEY(key_straferight), - - //! - // @game strife - // - // Keyboard key to use health. - // - - CONFIG_VARIABLE_KEY(key_useHealth), - - //! - // @game hexen - // - // Keyboard key to jump. - // - - CONFIG_VARIABLE_KEY(key_jump), - - //! - // @game heretic hexen - // - // Keyboard key to fly upward. - // - - CONFIG_VARIABLE_KEY(key_flyup), - - //! - // @game heretic hexen - // - // Keyboard key to fly downwards. - // - - CONFIG_VARIABLE_KEY(key_flydown), - - //! - // @game heretic hexen - // - // Keyboard key to center flying. - // - - CONFIG_VARIABLE_KEY(key_flycenter), - - //! - // @game heretic hexen - // - // Keyboard key to look up. - // - - CONFIG_VARIABLE_KEY(key_lookup), - - //! - // @game heretic hexen - // - // Keyboard key to look down. - // - - CONFIG_VARIABLE_KEY(key_lookdown), - - //! - // @game heretic hexen - // - // Keyboard key to center the view. - // - - CONFIG_VARIABLE_KEY(key_lookcenter), - - //! - // @game strife - // - // Keyboard key to query inventory. - // - - CONFIG_VARIABLE_KEY(key_invquery), - - //! - // @game strife - // - // Keyboard key to display mission objective. - // - - CONFIG_VARIABLE_KEY(key_mission), - - //! - // @game strife - // - // Keyboard key to display inventory popup. - // - - CONFIG_VARIABLE_KEY(key_invPop), - - //! - // @game strife - // - // Keyboard key to display keys popup. - // - - CONFIG_VARIABLE_KEY(key_invKey), - - //! - // @game strife - // - // Keyboard key to jump to start of inventory. - // - - CONFIG_VARIABLE_KEY(key_invHome), - - //! - // @game strife - // - // Keyboard key to jump to end of inventory. - // - - CONFIG_VARIABLE_KEY(key_invEnd), - - //! - // @game heretic hexen - // - // Keyboard key to scroll left in the inventory. - // - - CONFIG_VARIABLE_KEY(key_invleft), - - //! - // @game heretic hexen - // - // Keyboard key to scroll right in the inventory. - // - - CONFIG_VARIABLE_KEY(key_invright), - - //! - // @game strife - // - // Keyboard key to scroll left in the inventory. - // - - CONFIG_VARIABLE_KEY(key_invLeft), - - //! - // @game strife - // - // Keyboard key to scroll right in the inventory. - // - - CONFIG_VARIABLE_KEY(key_invRight), - - //! - // @game heretic hexen - // - // Keyboard key to use the current item in the inventory. - // - - CONFIG_VARIABLE_KEY(key_useartifact), - - //! - // @game strife - // - // Keyboard key to use inventory item. - // - - CONFIG_VARIABLE_KEY(key_invUse), - - //! - // @game strife - // - // Keyboard key to drop an inventory item. - // - - CONFIG_VARIABLE_KEY(key_invDrop), - - //! - // @game strife - // - // Keyboard key to look up. - // - - CONFIG_VARIABLE_KEY(key_lookUp), - - //! - // @game strife - // - // Keyboard key to look down. - // - - CONFIG_VARIABLE_KEY(key_lookDown), - - //! - // Keyboard key to fire the currently selected weapon. - // - - CONFIG_VARIABLE_KEY(key_fire), - - //! - // Keyboard key to "use" an object, eg. a door or switch. - // - - CONFIG_VARIABLE_KEY(key_use), - - //! - // Keyboard key to turn on strafing. When held down, pressing the - // key to turn left or right causes the player to strafe left or - // right instead. - // - - CONFIG_VARIABLE_KEY(key_strafe), - - //! - // Keyboard key to make the player run. - // - - CONFIG_VARIABLE_KEY(key_speed), - - //! - // If non-zero, mouse input is enabled. If zero, mouse input is - // disabled. - // - - CONFIG_VARIABLE_INT(use_mouse), - - //! - // Mouse button to fire the currently selected weapon. - // - - CONFIG_VARIABLE_INT(mouseb_fire), - - //! - // Mouse button to turn on strafing. When held down, the player - // will strafe left and right instead of turning left and right. - // - - CONFIG_VARIABLE_INT(mouseb_strafe), - - //! - // Mouse button to move forward. - // - - CONFIG_VARIABLE_INT(mouseb_forward), - - //! - // @game hexen strife - // - // Mouse button to jump. - // - - CONFIG_VARIABLE_INT(mouseb_jump), - - //! - // If non-zero, joystick input is enabled. - // - - CONFIG_VARIABLE_INT(use_joystick), - - - // //! - // // Joystick virtual button that fires the current weapon. - // // - - // CONFIG_VARIABLE_INT(joyb_fire), - - // //! - // // Joystick virtual button that makes the player strafe while - // // held down. - // // - - // CONFIG_VARIABLE_INT(joyb_strafe), - - // //! - // // Joystick virtual button to "use" an object, eg. a door or switch. - // // - - // CONFIG_VARIABLE_INT(joyb_use), - - // //! - // // Joystick virtual button that makes the player run while held - // // down. - // // - // // If this has a value of 20 or greater, the player will always run, - // // even if use_joystick is 0. - // // - - // CONFIG_VARIABLE_INT(joyb_speed), - - // //! - // // @game hexen strife - // // - // // Joystick virtual button that makes the player jump. - // // - - // CONFIG_VARIABLE_INT(joyb_jump), - */ - //! - // @game doom heretic hexen - // - // Screen size, range 3-11. - // - // A value of 11 gives a full-screen view with the status bar not - // displayed. A value of 10 gives a full-screen view with the - // status bar displayed. - // - - CONFIG_VARIABLE_INT(screenblocks), - - //! - // @game strife - // - // Screen size, range 3-11. - // - // A value of 11 gives a full-screen view with the status bar not - // displayed. A value of 10 gives a full-screen view with the - // status bar displayed. - // - - CONFIG_VARIABLE_INT(screensize), - - //! - // @game doom - // - // Screen detail. Zero gives normal "high detail" mode, while - // a non-zero value gives "low detail" mode. - // - - CONFIG_VARIABLE_INT(detaillevel), - - //! - // Number of sounds that will be played simultaneously. - // - - // CONFIG_VARIABLE_INT(snd_channels), - - //! - // Music output device. A non-zero value gives MIDI sound output, - // while a value of zero disables music. - // - - // CONFIG_VARIABLE_INT(snd_musicdevice), - - //! - // Sound effects device. A value of zero disables in-game sound - // effects, a value of 1 enables PC speaker sound effects, while - // a value in the range 2-9 enables the "normal" digital sound - // effects. - // - - // CONFIG_VARIABLE_INT(snd_sfxdevice), - - // //! - // // SoundBlaster I/O port. Unused. - // // - - // CONFIG_VARIABLE_INT(snd_sbport), - - // //! - // // SoundBlaster IRQ. Unused. - // // - - // CONFIG_VARIABLE_INT(snd_sbirq), - - // //! - // // SoundBlaster DMA channel. Unused. - // // - - // CONFIG_VARIABLE_INT(snd_sbdma), - - // //! - // // Output port to use for OPL MIDI playback. Unused. - // // - - // CONFIG_VARIABLE_INT(snd_mport), - - //! - // Gamma correction level. A value of zero disables gamma - // correction, while a value in the range 1-4 gives increasing - // levels of gamma correction. - // - - CONFIG_VARIABLE_INT(usegamma), - - //! - // @game hexen - // - // Directory in which to store savegames. - // - - // CONFIG_VARIABLE_STRING(savedir), - - //! - // @game hexen - // - // Controls whether messages are displayed in the heads-up display. - // If this has a non-zero value, messages are displayed. - // - - CONFIG_VARIABLE_INT(messageson), - - //! - // @game strife - // - // Name of background flat used by view border. - // - - // CONFIG_VARIABLE_STRING(back_flat), - - //! - // @game strife - // - // Multiplayer nickname (?). - // - - // CONFIG_VARIABLE_STRING(nickname), - - // //! - // // Multiplayer chat macro: message to send when alt+0 is pressed. - // // - - // CONFIG_VARIABLE_STRING(chatmacro0), - - // //! - // // Multiplayer chat macro: message to send when alt+1 is pressed. - // // - - // CONFIG_VARIABLE_STRING(chatmacro1), - - // //! - // // Multiplayer chat macro: message to send when alt+2 is pressed. - // // - - // CONFIG_VARIABLE_STRING(chatmacro2), - - // //! - // // Multiplayer chat macro: message to send when alt+3 is pressed. - // // - - // CONFIG_VARIABLE_STRING(chatmacro3), - - // //! - // // Multiplayer chat macro: message to send when alt+4 is pressed. - // // - - // CONFIG_VARIABLE_STRING(chatmacro4), - - // //! - // // Multiplayer chat macro: message to send when alt+5 is pressed. - // // - - // CONFIG_VARIABLE_STRING(chatmacro5), - - // //! - // // Multiplayer chat macro: message to send when alt+6 is pressed. - // // - - // CONFIG_VARIABLE_STRING(chatmacro6), - - // //! - // // Multiplayer chat macro: message to send when alt+7 is pressed. - // // - - // CONFIG_VARIABLE_STRING(chatmacro7), - - // //! - // // Multiplayer chat macro: message to send when alt+8 is pressed. - // // - - // CONFIG_VARIABLE_STRING(chatmacro8), - - // //! - // // Multiplayer chat macro: message to send when alt+9 is pressed. - // // - - // CONFIG_VARIABLE_STRING(chatmacro9), - - // //! - // // @game strife - // // - // // Serial port number to use for SERSETUP.EXE (unused). - // // - - // CONFIG_VARIABLE_INT(comport), -}; - -static default_collection_t doom_defaults = -{ - doom_defaults_list, - arrlen(doom_defaults_list), - NULL, -}; - -//! @begin_config_file extended - -static default_t extra_defaults_list[] = -{ - //! - // Name of the SDL video driver to use. If this is an empty string, - // the default video driver is used. - // - - // CONFIG_VARIABLE_STRING(video_driver), - - //! - // Position of the window on the screen when running in windowed - // mode. Accepted values are: "" (empty string) - don't care, - // "center" - place window at center of screen, "x,y" - place - // window at the specified coordinates. - // - - // CONFIG_VARIABLE_STRING(window_position), - - //! - // If non-zero, the game will run in full screen mode. If zero, - // the game will run in a window. - // - - // CONFIG_VARIABLE_INT(fullscreen), - - //! - // Index of the display on which the game should run. This has no - // effect if running in windowed mode (fullscreen=0) and - // window_position is not set to "center". - // - - // CONFIG_VARIABLE_INT(video_display), - - //! - // If non-zero, the screen will be stretched vertically to display - // correctly on a square pixel video mode. - // - - // CONFIG_VARIABLE_INT(aspect_ratio_correct), - - //! - // If non-zero, forces integer scales for resolution-independent rendering. - // - - // CONFIG_VARIABLE_INT(integer_scaling), - - // If non-zero, any pillar/letter boxes drawn around the game area - // will "flash" when the game palette changes, simulating the VGA - // "porch" - - // CONFIG_VARIABLE_INT(vga_porch_flash), - - //! - // Window width when running in windowed mode. - // - - // CONFIG_VARIABLE_INT(window_width), - - //! - // Window height when running in windowed mode. - // - - // CONFIG_VARIABLE_INT(window_height), - - //! - // Width for screen mode when running fullscreen. - // If this and fullscreen_height are both set to zero, we run - // fullscreen as a desktop window that covers the entire screen, - // rather than ever switching screen modes. It should usually - // be unnecessary to set this value. - // - - // CONFIG_VARIABLE_INT(fullscreen_width), - - //! - // Height for screen mode when running fullscreen. - // See documentation for fullscreen_width. - // - - // CONFIG_VARIABLE_INT(fullscreen_height), - - //! - // If non-zero, force the use of a software renderer. For use on - // systems lacking hardware acceleration. - // - - // CONFIG_VARIABLE_INT(force_software_renderer), - - //! - // Maximum number of pixels to use for intermediate scaling buffer. - // More pixels mean that the screen can be rendered more precisely, - // but there are diminishing returns on quality. The default limits to - // 16,000,000 pixels, which is enough to cover 4K monitor standards. - - // CONFIG_VARIABLE_INT(max_scaling_buffer_pixels), - - //! - // Number of milliseconds to wait on startup after the video mode - // has been set, before the game will start. This allows the - // screen to settle on some monitors that do not display an image - // for a brief interval after changing video modes. - // - - // CONFIG_VARIABLE_INT(startup_delay), - - //! - // @game heretic hexen strife - // - // If non-zero, display the graphical startup screen. - // - - // CONFIG_VARIABLE_INT(graphical_startup), - - //! - // @game doom heretic strife - // - // If non-zero, the ENDOOM text screen is displayed when exiting the - // game. If zero, the ENDOOM screen is not displayed. - // - - CONFIG_VARIABLE_INT(show_endoom), - - //! - // @game doom strife - // - // If non-zero, a disk activity indicator is displayed when data is read - // from disk. If zero, the disk activity indicator is not displayed. - // - - CONFIG_VARIABLE_INT(show_diskicon), - - //! - // If non-zero, save screenshots in PNG format. If zero, screenshots are - // saved in PCX format, as Vanilla Doom does. - // - - // CONFIG_VARIABLE_INT(png_screenshots), - - //! - // Sound output sample rate, in Hz. Typical values to use are - // 11025, 22050, 44100 and 48000. - // - - // CONFIG_VARIABLE_INT(snd_samplerate), - - //! - // Maximum number of bytes to allocate for caching converted sound - // effects in memory. If set to zero, there is no limit applied. - // - - // CONFIG_VARIABLE_INT(snd_cachesize), - - //! - // Maximum size of the output sound buffer size in milliseconds. - // Sound output is generated periodically in slices. Higher values - // might be more efficient but will introduce latency to the - // sound output. The default is 28ms (one slice per tic with the - // 35fps timer). - // - - // CONFIG_VARIABLE_INT(snd_maxslicetime_ms), - - //! - // If non-zero, sound effects will have their pitch varied up or - // down by a random amount during play. If zero, sound effects - // play back at their default pitch. - // - - // CONFIG_VARIABLE_INT(snd_pitchshift), - - //! - // External command to invoke to perform MIDI playback. If set to - // the empty string, SDL_mixer's internal MIDI playback is used. - // This only has any effect when snd_musicdevice is set to General - // MIDI output. - // - - // CONFIG_VARIABLE_STRING(snd_musiccmd), - - //! - // Value to set for the DMXOPTION environment variable. If this contains - // "-opl3", output for an OPL3 chip is generated when in OPL MIDI - // playback mode. - // - - // CONFIG_VARIABLE_STRING(snd_dmxoption), - - //! - // The I/O port to use to access the OPL chip. Only relevant when - // using native OPL music playback. - // - - // CONFIG_VARIABLE_INT_HEX(opl_io_port), - - //! - // Controls whether libsamplerate support is used for performing - // sample rate conversions of sound effects. Support for this - // must be compiled into the program. - // - // If zero, libsamplerate support is disabled. If non-zero, - // libsamplerate is enabled. Increasing values roughly correspond - // to higher quality conversion; the higher the quality, the - // slower the conversion process. Linear conversion = 1; - // Zero order hold = 2; Fast Sinc filter = 3; Medium quality - // Sinc filter = 4; High quality Sinc filter = 5. - // - - // CONFIG_VARIABLE_INT(use_libsamplerate), - - //! - // Scaling factor used by libsamplerate. This is used when converting - // sounds internally back into integer form; normally it should not - // be necessary to change it from the default value. The only time - // it might be needed is if a PWAD file is loaded that contains very - // loud sounds, in which case the conversion may cause sound clipping - // and the scale factor should be reduced. The lower the value, the - // quieter the sound effects become, so it should be set as high as is - // possible without clipping occurring. - - // CONFIG_VARIABLE_FLOAT(libsamplerate_scale), - - //! - // Full path to a directory containing configuration files for - // substitute music packs. These packs contain high quality renderings - // of game music to be played instead of using the system's built-in - // MIDI playback. - // - - // CONFIG_VARIABLE_STRING(music_pack_path), - - //! - // Full path to a Timidity configuration file to use for MIDI - // playback. The file will be evaluated from the directory where - // it is evaluated, so there is no need to add "dir" commands - // into it. - // - - // CONFIG_VARIABLE_STRING(timidity_cfg_path), - - //! - // Path to GUS patch files to use when operating in GUS emulation - // mode. - // - - // CONFIG_VARIABLE_STRING(gus_patch_path), - - //! - // Number of kilobytes of RAM to use in GUS emulation mode. Valid - // values are 256, 512, 768 or 1024. - // - - // CONFIG_VARIABLE_INT(gus_ram_kb), - - //! - // @game doom strife - // - // If non-zero, the Vanilla savegame limit is enforced; if the - // savegame exceeds 180224 bytes in size, the game will exit with - // an error. If this has a value of zero, there is no limit to - // the size of savegames. - // - - // CONFIG_VARIABLE_INT(vanilla_savegame_limit), - - //! - // @game doom strife - // - // If non-zero, the Vanilla demo size limit is enforced; the game - // exits with an error when a demo exceeds the demo size limit - // (128KiB by default). If this has a value of zero, there is no - // limit to the size of demos. - // - - // CONFIG_VARIABLE_INT(vanilla_demo_limit), - - //! - // If non-zero, the game behaves like Vanilla Doom, always assuming - // an American keyboard mapping. If this has a value of zero, the - // native keyboard mapping of the keyboard is used. - // - - CONFIG_VARIABLE_INT(vanilla_keyboard_mapping), - - //! - // Name to use in network games for identification. This is only - // used on the "waiting" screen while waiting for the game to start. - // - - // CONFIG_VARIABLE_STRING(player_name), - - //! - // If this is non-zero, the mouse will be "grabbed" when running - // in windowed mode so that it can be used as an input device. - // When running full screen, this has no effect. - // - - // CONFIG_VARIABLE_INT(grabmouse), - - /* NRFD-TODO: mouse - //! - // If non-zero, all vertical mouse movement is ignored. This - // emulates the behavior of the "novert" tool available under DOS - // that performs the same function. - // - - CONFIG_VARIABLE_INT(novert), - - //! - // Mouse acceleration factor. When the speed of mouse movement - // exceeds the threshold value (mouse_threshold), the speed is - // multiplied by this value. - // - - CONFIG_VARIABLE_FLOAT(mouse_acceleration), - - //! - // Mouse acceleration threshold. When the speed of mouse movement - // exceeds this threshold value, the speed is multiplied by an - // acceleration factor (mouse_acceleration). - // - - CONFIG_VARIABLE_INT(mouse_threshold), - - //! - // Mouse button to strafe left. - // - - CONFIG_VARIABLE_INT(mouseb_strafeleft), - - //! - // Mouse button to strafe right. - // - - CONFIG_VARIABLE_INT(mouseb_straferight), - - //! - // Mouse button to "use" an object, eg. a door or switch. - // - - CONFIG_VARIABLE_INT(mouseb_use), - - //! - // Mouse button to move backwards. - // - - CONFIG_VARIABLE_INT(mouseb_backward), - - //! - // Mouse button to cycle to the previous weapon. - // - - CONFIG_VARIABLE_INT(mouseb_prevweapon), - - //! - // Mouse button to cycle to the next weapon. - // - - CONFIG_VARIABLE_INT(mouseb_nextweapon), - - //! - // If non-zero, double-clicking a mouse button acts like pressing - // the "use" key to use an object in-game, eg. a door or switch. - // - - CONFIG_VARIABLE_INT(dclick_use), - */ - - //! - // SDL GUID string indicating the joystick to use. An empty string - // indicates that no joystick is configured. - // - - // CONFIG_VARIABLE_STRING(joystick_guid), - - //! - // Index of SDL joystick to use; this is only used in the case where - // multiple identical joystick devices are connected which have the - // same GUID, to distinguish between devices. - // - - // CONFIG_VARIABLE_INT(joystick_index), - - /* NRFD-TODO: joystick - //! - // Joystick axis to use to for horizontal (X) movement. - // - - CONFIG_VARIABLE_INT(joystick_x_axis), - - //! - // If non-zero, movement on the horizontal joystick axis is inverted. - // - - CONFIG_VARIABLE_INT(joystick_x_invert), - - //! - // Joystick axis to use to for vertical (Y) movement. - // - - CONFIG_VARIABLE_INT(joystick_y_axis), - - //! - // If non-zero, movement on the vertical joystick axis is inverted. - // - - CONFIG_VARIABLE_INT(joystick_y_invert), - - //! - // Joystick axis to use to for strafing movement. - // - - CONFIG_VARIABLE_INT(joystick_strafe_axis), - - //! - // If non-zero, movement on the joystick axis used for strafing - // is inverted. - // - - CONFIG_VARIABLE_INT(joystick_strafe_invert), - - //! - // Joystick axis to use to for looking up and down. - // - - CONFIG_VARIABLE_INT(joystick_look_axis), - - //! - // If non-zero, movement on the joystick axis used for looking - // is inverted. - // - - CONFIG_VARIABLE_INT(joystick_look_invert), - - //! - // The physical joystick button that corresponds to joystick - // virtual button #0. - // - - CONFIG_VARIABLE_INT(joystick_physical_button0), - - //! - // The physical joystick button that corresponds to joystick - // virtual button #1. - // - - CONFIG_VARIABLE_INT(joystick_physical_button1), - - //! - // The physical joystick button that corresponds to joystick - // virtual button #2. - // - - CONFIG_VARIABLE_INT(joystick_physical_button2), - - //! - // The physical joystick button that corresponds to joystick - // virtual button #3. - // - - CONFIG_VARIABLE_INT(joystick_physical_button3), - - //! - // The physical joystick button that corresponds to joystick - // virtual button #4. - // - - CONFIG_VARIABLE_INT(joystick_physical_button4), - - //! - // The physical joystick button that corresponds to joystick - // virtual button #5. - // - - CONFIG_VARIABLE_INT(joystick_physical_button5), - - //! - // The physical joystick button that corresponds to joystick - // virtual button #6. - // - - CONFIG_VARIABLE_INT(joystick_physical_button6), - - //! - // The physical joystick button that corresponds to joystick - // virtual button #7. - // - - CONFIG_VARIABLE_INT(joystick_physical_button7), - - //! - // The physical joystick button that corresponds to joystick - // virtual button #8. - // - - CONFIG_VARIABLE_INT(joystick_physical_button8), - - //! - // The physical joystick button that corresponds to joystick - // virtual button #9. - // - - CONFIG_VARIABLE_INT(joystick_physical_button9), - - //! - // The physical joystick button that corresponds to joystick - // virtual button #10. - // - - CONFIG_VARIABLE_INT(joystick_physical_button10), - - //! - // Joystick virtual button to make the player strafe left. - // - - CONFIG_VARIABLE_INT(joyb_strafeleft), - - //! - // Joystick virtual button to make the player strafe right. - // - - CONFIG_VARIABLE_INT(joyb_straferight), - - //! - // Joystick virtual button to activate the menu. - // - - CONFIG_VARIABLE_INT(joyb_menu_activate), - - //! - // Joystick virtual button to toggle the automap. - // - - CONFIG_VARIABLE_INT(joyb_toggle_automap), - - //! - // Joystick virtual button that cycles to the previous weapon. - // - - CONFIG_VARIABLE_INT(joyb_prevweapon), - - //! - // Joystick virtual button that cycles to the next weapon. - // - - CONFIG_VARIABLE_INT(joyb_nextweapon), - - */ - - /* NRFD-TODO: configurable controls - - //! - // Key to pause or unpause the game. - // - - CONFIG_VARIABLE_KEY(key_pause), - - //! - // Key that activates the menu when pressed. - // - - CONFIG_VARIABLE_KEY(key_menu_activate), - - //! - // Key that moves the cursor up on the menu. - // - - CONFIG_VARIABLE_KEY(key_menu_up), - - //! - // Key that moves the cursor down on the menu. - // - - CONFIG_VARIABLE_KEY(key_menu_down), - - //! - // Key that moves the currently selected slider on the menu left. - // - - CONFIG_VARIABLE_KEY(key_menu_left), - - //! - // Key that moves the currently selected slider on the menu right. - // - - CONFIG_VARIABLE_KEY(key_menu_right), - - //! - // Key to go back to the previous menu. - // - - CONFIG_VARIABLE_KEY(key_menu_back), - - //! - // Key to activate the currently selected menu item. - // - - CONFIG_VARIABLE_KEY(key_menu_forward), - - //! - // Key to answer 'yes' to a question in the menu. - // - - CONFIG_VARIABLE_KEY(key_menu_confirm), - - //! - // Key to answer 'no' to a question in the menu. - // - - CONFIG_VARIABLE_KEY(key_menu_abort), - - //! - // Keyboard shortcut to bring up the help screen. - // - - CONFIG_VARIABLE_KEY(key_menu_help), - - //! - // Keyboard shortcut to bring up the save game menu. - // - - CONFIG_VARIABLE_KEY(key_menu_save), - - //! - // Keyboard shortcut to bring up the load game menu. - // - - CONFIG_VARIABLE_KEY(key_menu_load), - - //! - // Keyboard shortcut to bring up the sound volume menu. - // - - CONFIG_VARIABLE_KEY(key_menu_volume), - - //! - // Keyboard shortcut to toggle the detail level. - // - - CONFIG_VARIABLE_KEY(key_menu_detail), - - //! - // Keyboard shortcut to quicksave the current game. - // - - CONFIG_VARIABLE_KEY(key_menu_qsave), - - //! - // Keyboard shortcut to end the game. - // - - CONFIG_VARIABLE_KEY(key_menu_endgame), - - //! - // Keyboard shortcut to toggle heads-up messages. - // - - CONFIG_VARIABLE_KEY(key_menu_messages), - - //! - // Keyboard shortcut to load the last quicksave. - // - - CONFIG_VARIABLE_KEY(key_menu_qload), - - //! - // Keyboard shortcut to quit the game. - // - - CONFIG_VARIABLE_KEY(key_menu_quit), - - //! - // Keyboard shortcut to toggle the gamma correction level. - // - - CONFIG_VARIABLE_KEY(key_menu_gamma), - - //! - // Keyboard shortcut to switch view in multiplayer. - // - - CONFIG_VARIABLE_KEY(key_spy), - - //! - // Keyboard shortcut to increase the screen size. - // - - CONFIG_VARIABLE_KEY(key_menu_incscreen), - - //! - // Keyboard shortcut to decrease the screen size. - // - - CONFIG_VARIABLE_KEY(key_menu_decscreen), - - //! - // Keyboard shortcut to save a screenshot. - // - - CONFIG_VARIABLE_KEY(key_menu_screenshot), - - //! - // Key to toggle the map view. - // - - CONFIG_VARIABLE_KEY(key_map_toggle), - - //! - // Key to pan north when in the map view. - // - - CONFIG_VARIABLE_KEY(key_map_north), - - //! - // Key to pan south when in the map view. - // - - CONFIG_VARIABLE_KEY(key_map_south), - - //! - // Key to pan east when in the map view. - // - - CONFIG_VARIABLE_KEY(key_map_east), - - //! - // Key to pan west when in the map view. - // - - CONFIG_VARIABLE_KEY(key_map_west), - - //! - // Key to zoom in when in the map view. - // - - CONFIG_VARIABLE_KEY(key_map_zoomin), - - //! - // Key to zoom out when in the map view. - // - - CONFIG_VARIABLE_KEY(key_map_zoomout), - - //! - // Key to zoom out the maximum amount when in the map view. - // - - CONFIG_VARIABLE_KEY(key_map_maxzoom), - - //! - // Key to toggle follow mode when in the map view. - // - - CONFIG_VARIABLE_KEY(key_map_follow), - - //! - // Key to toggle the grid display when in the map view. - // - - CONFIG_VARIABLE_KEY(key_map_grid), - - //! - // Key to set a mark when in the map view. - // - - CONFIG_VARIABLE_KEY(key_map_mark), - - //! - // Key to clear all marks when in the map view. - // - - CONFIG_VARIABLE_KEY(key_map_clearmark), - - //! - // Key to select weapon 1. - // - - CONFIG_VARIABLE_KEY(key_weapon1), - - //! - // Key to select weapon 2. - // - - CONFIG_VARIABLE_KEY(key_weapon2), - - //! - // Key to select weapon 3. - // - - CONFIG_VARIABLE_KEY(key_weapon3), - - //! - // Key to select weapon 4. - // - - CONFIG_VARIABLE_KEY(key_weapon4), - - //! - // Key to select weapon 5. - // - - CONFIG_VARIABLE_KEY(key_weapon5), - - //! - // Key to select weapon 6. - // - - CONFIG_VARIABLE_KEY(key_weapon6), - - //! - // Key to select weapon 7. - // - - CONFIG_VARIABLE_KEY(key_weapon7), - - //! - // Key to select weapon 8. - // - - CONFIG_VARIABLE_KEY(key_weapon8), - - //! - // Key to cycle to the previous weapon. - // - - CONFIG_VARIABLE_KEY(key_prevweapon), - - //! - // Key to cycle to the next weapon. - // - - CONFIG_VARIABLE_KEY(key_nextweapon), - */ - - /*NRFD-EXCLUDE: Hexen - //! - // @game hexen - // - // Key to use one of each artifact. - // - - CONFIG_VARIABLE_KEY(key_arti_all), - - //! - // @game hexen - // - // Key to use "quartz flask" artifact. - // - - CONFIG_VARIABLE_KEY(key_arti_health), - - //! - // @game hexen - // - // Key to use "flechette" artifact. - // - - CONFIG_VARIABLE_KEY(key_arti_poisonbag), - - //! - // @game hexen - // - // Key to use "disc of repulsion" artifact. - // - - CONFIG_VARIABLE_KEY(key_arti_blastradius), - - //! - // @game hexen - // - // Key to use "chaos device" artifact. - // - - CONFIG_VARIABLE_KEY(key_arti_teleport), - - //! - // @game hexen - // - // Key to use "banishment device" artifact. - // - - CONFIG_VARIABLE_KEY(key_arti_teleportother), - - //! - // @game hexen - // - // Key to use "porkalator" artifact. - // - - CONFIG_VARIABLE_KEY(key_arti_egg), - - //! - // @game hexen - // - // Key to use "icon of the defender" artifact. - // - - CONFIG_VARIABLE_KEY(key_arti_invulnerability), - */ - - /* NRFD-TODO: Configurable controls - //! - // Key to re-display last message. - // - - CONFIG_VARIABLE_KEY(key_message_refresh), - - //! - // Key to quit the game when recording a demo. - // +#include "doom_config.h" - CONFIG_VARIABLE_KEY(key_demo_quit), +#include "doomtype.h" +#include "doomkeys.h" +#include "i_system.h" +#include "m_argv.h" +#include "m_misc.h" - //! - // Key to send a message during multiplayer games. - // +#include "z_zone.h" - CONFIG_VARIABLE_KEY(key_multi_msg), +/* + * Location where all configuration data is stored - + * default.cfg, savegames, etc. + */ +const char *configdir = ""; - //! - // Key to send a message to player 1 during multiplayer games. - // +/* Default filenames for configuration files. */ +const char *default_main_config = "default.cfg"; +const char *default_extra_config = "nrf-doom.cfg"; - CONFIG_VARIABLE_KEY(key_multi_msgplayer1), +typedef enum +{ + DEFAULT_INT, + DEFAULT_INT_HEX, + DEFAULT_STRING, + DEFAULT_FLOAT, + DEFAULT_KEY, +} default_type_t; - //! - // Key to send a message to player 2 during multiplayer games. - // +typedef struct +{ + /* Name of the variable */ + char *name; - CONFIG_VARIABLE_KEY(key_multi_msgplayer2), + /* Pointer to the location in memory of the variable */ + union + { + int *i; + char **s; + float *f; + } location; - //! - // Key to send a message to player 3 during multiplayer games. - // + /* Type of the variable */ + default_type_t type; - CONFIG_VARIABLE_KEY(key_multi_msgplayer3), + /* + * If this is a key value, the original integer scancode we read from + * the config file before translating it to the internal key value. + * If zero, we didn't read this value from a config file. + * int untranslated; + */ - //! - // Key to send a message to player 4 during multiplayer games. - // + /* + * The value we translated the scancode into when we read the + * config file on startup. If the variable value is different from + * this, it has been changed and needs to be converted; otherwise, + * use the 'untranslated' value. + * int original_translated; + */ - CONFIG_VARIABLE_KEY(key_multi_msgplayer4), + /* + * If true, this config variable has been bound to a variable + * and is being used. + */ + boolean bound; +} default_t; - //! - // @game hexen strife - // - // Key to send a message to player 5 during multiplayer games. - // +typedef struct +{ + default_t *defaults; + int numdefaults; + char *filename; +} default_collection_t; - CONFIG_VARIABLE_KEY(key_multi_msgplayer5), +#define CONFIG_VARIABLE_GENERIC(name, type) {#name, {NULL}, type, false} +/* + * NRFD-TODO + * Translate key. + * { #name, {NULL}, type, 0, 0, false } + */ - //! - // @game hexen strife - // - // Key to send a message to player 6 during multiplayer games. - // +#define CONFIG_VARIABLE_KEY(name) \ + CONFIG_VARIABLE_GENERIC(name, DEFAULT_KEY) +#define CONFIG_VARIABLE_INT(name) \ + CONFIG_VARIABLE_GENERIC(name, DEFAULT_INT) +#define CONFIG_VARIABLE_INT_HEX(name) \ + CONFIG_VARIABLE_GENERIC(name, DEFAULT_INT_HEX) +#define CONFIG_VARIABLE_FLOAT(name) \ + CONFIG_VARIABLE_GENERIC(name, DEFAULT_FLOAT) +#define CONFIG_VARIABLE_STRING(name) \ + CONFIG_VARIABLE_GENERIC(name, DEFAULT_STRING) - CONFIG_VARIABLE_KEY(key_multi_msgplayer6), +//! @begin_config_file default - //! - // @game hexen strife - // - // Key to send a message to player 7 during multiplayer games. - // +/* + * NRFD-TODO + * Add back some configs + */ +static default_t doom_defaults_list[] = + { + //! + // Mouse sensitivity. This value is used to multiply input mouse + // movement to control the effect of moving the mouse. + // + // The "normal" maximum value available for this through the + // in-game options menu is 9. A value of 31 or greater will cause + // the game to crash when entering the options menu. + // + CONFIG_VARIABLE_INT(mouse_sensitivity), + + //! + // Volume of sound effects, range 0-15. + // + CONFIG_VARIABLE_INT(sfx_volume), + + //! + // Volume of in-game music, range 0-15. + // + CONFIG_VARIABLE_INT(music_volume), + + //! + // @game strife + // + // If non-zero, dialogue text is displayed over characters' pictures + // when engaging actors who have voices. + // + /* CONFIG_VARIABLE_INT(show_talk), */ + + //! + // @game strife + // + // Volume of voice sound effects, range 0-15. + // + CONFIG_VARIABLE_INT(voice_volume), + + //! + // @game doom + // + // If non-zero, messages are displayed on the heads-up display + // in the game ("picked up a clip", etc). If zero, these messages + // are not displayed. + // + CONFIG_VARIABLE_INT(show_messages), + + /* + * NRFD-TODO + * Configurable controls. + * + * //! + * // Keyboard key to turn right. + * // + * CONFIG_VARIABLE_KEY(key_right), + * + * //! + * // Keyboard key to turn left. + * // + * CONFIG_VARIABLE_KEY(key_left), + * + * //! + * // Keyboard key to move forward. + * // + * CONFIG_VARIABLE_KEY(key_up), + * + * //! + * // Keyboard key to move backward. + * // + * CONFIG_VARIABLE_KEY(key_down), + * + * //! + * // Keyboard key to strafe left. + * // + * CONFIG_VARIABLE_KEY(key_strafeleft), + * + * //! + * // Keyboard key to strafe right. + * // + * CONFIG_VARIABLE_KEY(key_straferight), + * + * //! + * // @game strife + * // + * // Keyboard key to use health. + * // + * CONFIG_VARIABLE_KEY(key_useHealth), + * + * //! + * // @game hexen + * // + * // Keyboard key to jump. + * // + * CONFIG_VARIABLE_KEY(key_jump), + * + * //! + * // @game heretic hexen + * // + * // Keyboard key to fly upward. + * // + * CONFIG_VARIABLE_KEY(key_flyup), + * + * //! + * // @game heretic hexen + * // + * // Keyboard key to fly downwards. + * // + * CONFIG_VARIABLE_KEY(key_flydown), + * + * //! + * // @game heretic hexen + * // + * // Keyboard key to center flying. + * // + * CONFIG_VARIABLE_KEY(key_flycenter), + * + * //! + * // @game heretic hexen + * // + * // Keyboard key to look up. + * // + * CONFIG_VARIABLE_KEY(key_lookup), + * + * //! + * // @game heretic hexen + * // + * // Keyboard key to look down. + * // + * CONFIG_VARIABLE_KEY(key_lookdown), + * + * //! + * // @game heretic hexen + * // + * // Keyboard key to center the view. + * // + * CONFIG_VARIABLE_KEY(key_lookcenter), + * + * //! + * // @game strife + * // + * // Keyboard key to query inventory. + * // + * CONFIG_VARIABLE_KEY(key_invquery), + * + * //! + * // @game strife + * // + * // Keyboard key to display mission objective. + * // + * CONFIG_VARIABLE_KEY(key_mission), + * + * //! + * // @game strife + * // + * // Keyboard key to display inventory popup. + * // + * CONFIG_VARIABLE_KEY(key_invPop), + * + * //! + * // @game strife + * // + * // Keyboard key to display keys popup. + * // + * CONFIG_VARIABLE_KEY(key_invKey), + * + * //! + * // @game strife + * // + * // Keyboard key to jump to start of inventory. + * // + * CONFIG_VARIABLE_KEY(key_invHome), + * + * //! + * // @game strife + * // + * // Keyboard key to jump to end of inventory. + * // + * CONFIG_VARIABLE_KEY(key_invEnd), + * + * //! + * // @game heretic hexen + * // + * // Keyboard key to scroll left in the inventory. + * // + * CONFIG_VARIABLE_KEY(key_invleft), + * + * //! + * // @game heretic hexen + * // + * // Keyboard key to scroll right in the inventory. + * // + * CONFIG_VARIABLE_KEY(key_invright), + * + * //! + * // @game strife + * // + * // Keyboard key to scroll left in the inventory. + * // + * CONFIG_VARIABLE_KEY(key_invLeft), + * + * //! + * // @game strife + * // + * // Keyboard key to scroll right in the inventory. + * // + * CONFIG_VARIABLE_KEY(key_invRight), + * + * //! + * // @game heretic hexen + * // + * // Keyboard key to use the current item in the inventory. + * // + * CONFIG_VARIABLE_KEY(key_useartifact), + * + * //! + * // @game strife + * // + * // Keyboard key to use inventory item. + * // + * CONFIG_VARIABLE_KEY(key_invUse), + * + * //! + * // @game strife + * // + * // Keyboard key to drop an inventory item. + * // + * CONFIG_VARIABLE_KEY(key_invDrop), + * + * //! + * // @game strife + * // + * // Keyboard key to look up. + * // + * CONFIG_VARIABLE_KEY(key_lookUp), + * + * //! + * // @game strife + * // + * // Keyboard key to look down. + * // + * CONFIG_VARIABLE_KEY(key_lookDown), + * + * //! + * // Keyboard key to fire the currently selected weapon. + * // + * CONFIG_VARIABLE_KEY(key_fire), + * + * //! + * // Keyboard key to "use" an object, e.g. a door or switch. + * // + * CONFIG_VARIABLE_KEY(key_use), + * + * //! + * // Keyboard key to turn on strafing. When held down, pressing the + * // key to turn left or right causes the player to strafe left or + * // right instead. + * // + * CONFIG_VARIABLE_KEY(key_strafe), + * + * //! + * // Keyboard key to make the player run. + * // + * CONFIG_VARIABLE_KEY(key_speed), + * + * //! + * // If non-zero, mouse input is enabled. If zero, mouse input is + * // disabled. + * // + * CONFIG_VARIABLE_INT(use_mouse), + * + * //! + * // Mouse button to fire the currently selected weapon. + * // + * CONFIG_VARIABLE_INT(mouseb_fire), + * + * //! + * // Mouse button to turn on strafing. When held down, the player + * // will strafe left and right instead of turning left and right. + * // + * CONFIG_VARIABLE_INT(mouseb_strafe), + * + * //! + * // Mouse button to move forward. + * // + * CONFIG_VARIABLE_INT(mouseb_forward), + * + * //! + * // @game hexen strife + * // + * // Mouse button to jump. + * // + * CONFIG_VARIABLE_INT(mouseb_jump), + * + * //! + * // If non-zero, joystick input is enabled. + * // + * CONFIG_VARIABLE_INT(use_joystick), + * + * + * //! + * // Joystick virtual button that fires the current weapon. + * // + * // CONFIG_VARIABLE_INT(joyb_fire), + * + * //! + * // Joystick virtual button that makes the player strafe while + * // held down. + * // + * CONFIG_VARIABLE_INT(joyb_strafe), + * + * //! + * // Joystick virtual button to "use" an object, e.g. a door or switch. + * // + * // CONFIG_VARIABLE_INT(joyb_use), + * + * //! + * // Joystick virtual button that makes the player run while held + * // down. + * // + * // If this has a value of 20 or greater, the player will always run, + * // even if use_joystick is 0. + * // + * // CONFIG_VARIABLE_INT(joyb_speed), + * + * //! + * // @game hexen strife + * // + * // Joystick virtual button that makes the player jump. + * // + * // CONFIG_VARIABLE_INT(joyb_jump), + */ + + //! + // @game doom heretic hexen + // + // Screen size, range 3-11. + // + // A value of 11 gives a full-screen view with the status bar not + // displayed. A value of 10 gives a full-screen view with the + // status bar displayed. + // + CONFIG_VARIABLE_INT(screenblocks), + + //! + // @game strife + // + // Screen size, range 3-11. + // + // A value of 11 gives a full-screen view with the status bar not + // displayed. A value of 10 gives a full-screen view with the + // status bar displayed. + // + CONFIG_VARIABLE_INT(screensize), + + //! + // @game doom + // + // Screen detail. Zero gives normal "high detail" mode, while + // a non-zero value gives "low detail" mode. + // + CONFIG_VARIABLE_INT(detaillevel), + + //! + // Number of sounds that will be played simultaneously. + // + /* CONFIG_VARIABLE_INT(snd_channels), */ + + //! + // Music output device. A non-zero value gives MIDI sound output, + // while a value of zero disables music. + // + /* CONFIG_VARIABLE_INT(snd_musicdevice), */ + + //! + // Sound effects device. A value of zero disables in-game sound + // effects, a value of 1 enables PC speaker sound effects, while + // a value in the range 2-9 enables the "normal" digital sound + // effects. + // + /* CONFIG_VARIABLE_INT(snd_sfxdevice), */ + + //! + // SoundBlaster I/O port. Unused. + // + /* CONFIG_VARIABLE_INT(snd_sbport), */ + + //! + // SoundBlaster IRQ. Unused. + // + /* CONFIG_VARIABLE_INT(snd_sbirq), */ + + //! + // SoundBlaster DMA channel. Unused. + // + /* CONFIG_VARIABLE_INT(snd_sbdma), */ + + //! + // Output port to use for OPL MIDI playback. Unused. + // + /* CONFIG_VARIABLE_INT(snd_mport), */ + + //! + // Gamma correction level. A value of zero disables gamma + // correction, while a value in the range 1-4 gives increasing + // levels of gamma correction. + // + CONFIG_VARIABLE_INT(usegamma), + + //! + // @game hexen + // + // Directory in which to store savegames. + // + /* CONFIG_VARIABLE_STRING(savedir), */ + + //! + // @game hexen + // + // Controls whether messages are displayed in the heads-up display. + // If this has a non-zero value, messages are displayed. + // + CONFIG_VARIABLE_INT(messageson), + + //! + // @game strife + // + // Name of background flat used by view border. + // + /* CONFIG_VARIABLE_STRING(back_flat), */ + + //! + // @game strife + // + // Multiplayer nickname (?). + // + /* CONFIG_VARIABLE_STRING(nickname), */ + + //! + // Multiplayer chat macro - message to send when alt+0 is pressed. + // + /* CONFIG_VARIABLE_STRING(chatmacro0), */ + + //! + // Multiplayer chat macro - message to send when alt+1 is pressed. + // + /* CONFIG_VARIABLE_STRING(chatmacro1), */ + + //! + // Multiplayer chat macro - message to send when alt+2 is pressed. + // + /* CONFIG_VARIABLE_STRING(chatmacro2), */ + + //! + // Multiplayer chat macro - message to send when alt+3 is pressed. + // + /* CONFIG_VARIABLE_STRING(chatmacro3), */ + + //! + // Multiplayer chat macro - message to send when alt+4 is pressed. + // + /* CONFIG_VARIABLE_STRING(chatmacro4), */ + + //! + // Multiplayer chat macro - message to send when alt+5 is pressed. + // + /* CONFIG_VARIABLE_STRING(chatmacro5), */ + + //! + // Multiplayer chat macro - message to send when alt+6 is pressed. + // + /* CONFIG_VARIABLE_STRING(chatmacro6), */ + + //! + // Multiplayer chat macro - message to send when alt+7 is pressed. + // + /* CONFIG_VARIABLE_STRING(chatmacro7), */ + + //! + // Multiplayer chat macro - message to send when alt+8 is pressed. + // + /* CONFIG_VARIABLE_STRING(chatmacro8), */ + + //! + // Multiplayer chat macro - message to send when alt+9 is pressed. + // + /* CONFIG_VARIABLE_STRING(chatmacro9), */ + + //! + // @game strife + // + // Serial port number to use for SERSETUP.EXE (unused). + // + /* CONFIG_VARIABLE_INT(comport), */ +}; - CONFIG_VARIABLE_KEY(key_multi_msgplayer7), +static default_collection_t doom_defaults = + { + doom_defaults_list, + arrlen(doom_defaults_list), + NULL, +}; - //! - // @game hexen strife - // - // Key to send a message to player 8 during multiplayer games. - // +//! @begin_config_file extended - CONFIG_VARIABLE_KEY(key_multi_msgplayer8), - */ +static default_t extra_defaults_list[] = + { + //! + // Name of the SDL video driver to use. If this is an empty string, + // the default video driver is used. + // + /* CONFIG_VARIABLE_STRING(video_driver), */ + + //! + // Position of the window on the screen when running in windowed + // mode. Accepted values are: "" (empty string) - don't care, + // "center" - place window at center of screen, "x,y" - place + // window at the specified coordinates. + // + /* CONFIG_VARIABLE_STRING(window_position), */ + + //! + // If non-zero, the game will run in full screen mode. If zero, + // the game will run in a window. + // + /* CONFIG_VARIABLE_INT(fullscreen), */ + + //! + // Index of the display on which the game should run. This has no + // effect if running in windowed mode (fullscreen=0) and + // window_position is not set to "center". + // + /* CONFIG_VARIABLE_INT(video_display), */ + + //! + // If non-zero, the screen will be stretched vertically to display + // correctly on a square pixel video mode. + // + /* CONFIG_VARIABLE_INT(aspect_ratio_correct), */ + + //! + // If non-zero, forces integer scales for resolution-independent rendering. + // + /* CONFIG_VARIABLE_INT(integer_scaling), */ + + // ! + // If non-zero, any pillar/letter boxes drawn around the game area + // will "flash" when the game palette changes, simulating the VGA + // "porch" + // + /* CONFIG_VARIABLE_INT(vga_porch_flash), */ + + //! + // Window width when running in windowed mode. + // + /* CONFIG_VARIABLE_INT(window_width), */ + + //! + // Window height when running in windowed mode. + // + /* CONFIG_VARIABLE_INT(window_height), */ + + //! + // Width for screen mode when running fullscreen. + // If this and fullscreen_height are both set to zero, we run + // fullscreen as a desktop window that covers the entire screen, + // rather than ever switching screen modes. It should usually + // be unnecessary to set this value. + // + /* CONFIG_VARIABLE_INT(fullscreen_width), */ + + //! + // Height for screen mode when running fullscreen. + // See documentation for fullscreen_width. + // + /* CONFIG_VARIABLE_INT(fullscreen_height), */ + + //! + // If non-zero, force the use of a software renderer. For use on + // systems lacking hardware acceleration. + // + /* CONFIG_VARIABLE_INT(force_software_renderer), */ + + //! + // Maximum number of pixels to use for intermediate scaling buffer. + // More pixels mean that the screen can be rendered more precisely, + // but there are diminishing returns on quality. The default limits to + // 16,000,000 pixels, which is enough to cover 4K monitor standards. + // + /* CONFIG_VARIABLE_INT(max_scaling_buffer_pixels), */ + + //! + // Number of milliseconds to wait on startup after the video mode + // has been set, before the game will start. This allows the + // screen to settle on some monitors that do not display an image + // for a brief interval after changing video modes. + // + /* CONFIG_VARIABLE_INT(startup_delay), */ + + //! + // @game heretic hexen strife + // + // If non-zero, display the graphical startup screen. + // + /* CONFIG_VARIABLE_INT(graphical_startup), */ + + //! + // @game doom heretic strife + // + // If non-zero, the ENDOOM text screen is displayed when exiting the + // game. If zero, the ENDOOM screen is not displayed. + // + CONFIG_VARIABLE_INT(show_endoom), + + //! + // @game doom strife + // + // If non-zero, a disk activity indicator is displayed when data is read + // from disk. If zero, the disk activity indicator is not displayed. + // + CONFIG_VARIABLE_INT(show_diskicon), + + //! + // If non-zero, save screenshots in PNG format. If zero, screenshots are + // saved in PCX format, as Vanilla Doom does. + // + /* CONFIG_VARIABLE_INT(png_screenshots), */ + + //! + // Sound output sample rate, in Hz. Typical values to use are + // 11025, 22050, 44100 and 48000. + // + /* CONFIG_VARIABLE_INT(snd_samplerate), */ + + //! + // Maximum number of bytes to allocate for caching converted sound + // effects in memory. If set to zero, there is no limit applied. + // + /* CONFIG_VARIABLE_INT(snd_cachesize), */ + + //! + // Maximum size of the output sound buffer size in milliseconds. + // Sound output is generated periodically in slices. Higher values + // might be more efficient but will introduce latency to the + // sound output. The default is 28ms (one slice per tic with the + // 35fps timer). + // + /* CONFIG_VARIABLE_INT(snd_maxslicetime_ms), */ + + //! + // If non-zero, sound effects will have their pitch varied up or + // down by a random amount during play. If zero, sound effects + // play back at their default pitch. + // + /* CONFIG_VARIABLE_INT(snd_pitchshift), */ + + //! + // External command to invoke to perform MIDI playback. If set to + // the empty string, SDL_mixer's internal MIDI playback is used. + // This only has any effect when snd_musicdevice is set to General + // MIDI output. + // + /* CONFIG_VARIABLE_STRING(snd_musiccmd), */ + + //! + // Value to set for the DMXOPTION environment variable. If this contains + // "-opl3", output for an OPL3 chip is generated when in OPL MIDI + // playback mode. + // + /* CONFIG_VARIABLE_STRING(snd_dmxoption), */ + + //! + // The I/O port to use to access the OPL chip. Only relevant when + // using native OPL music playback. + // + /* CONFIG_VARIABLE_INT_HEX(opl_io_port), */ + + //! + // Controls whether libsamplerate support is used for performing + // sample rate conversions of sound effects. Support for this + // must be compiled into the program. + // + // If zero, libsamplerate support is disabled. If non-zero, + // libsamplerate is enabled. Increasing values roughly correspond + // to higher quality conversion; the higher the quality, the + // slower the conversion process. Linear conversion = 1; + // Zero order hold = 2; Fast Sinc filter = 3; Medium quality + // Sinc filter = 4; High quality Sinc filter = 5. + // + /* CONFIG_VARIABLE_INT(use_libsamplerate), */ + + //! + // Scaling factor used by libsamplerate. This is used when converting + // sounds internally back into integer form; normally it should not + // be necessary to change it from the default value. The only time + // it might be needed is if a PWAD file is loaded that contains very + // loud sounds, in which case the conversion may cause sound clipping + // and the scale factor should be reduced. The lower the value, the + // quieter the sound effects become, so it should be set as high as is + // possible without clipping occurring. + // + /* CONFIG_VARIABLE_FLOAT(libsamplerate_scale), */ + + //! + // Full path to a directory containing configuration files for + // substitute music packs. These packs contain high quality renderings + // of game music to be played instead of using the system's built-in + // MIDI playback. + // + /* CONFIG_VARIABLE_STRING(music_pack_path), */ + + //! + // Full path to a Timidity configuration file to use for MIDI + // playback. The file will be evaluated from the directory where + // it is evaluated, so there is no need to add "dir" commands + // into it. + // + /* CONFIG_VARIABLE_STRING(timidity_cfg_path), */ + + //! + // Path to GUS patch files to use when operating in GUS emulation + // mode. + // + /* CONFIG_VARIABLE_STRING(gus_patch_path), */ + + //! + // Number of kilobytes of RAM to use in GUS emulation mode. Valid + // values are 256, 512, 768 or 1024. + // + /* CONFIG_VARIABLE_INT(gus_ram_kb), */ + + //! + // @game doom strife + // + // If non-zero, the Vanilla savegame limit is enforced; if the + // savegame exceeds 180224 bytes in size, the game will exit with + // an error. If this has a value of zero, there is no limit to + // the size of savegames. + // + /* CONFIG_VARIABLE_INT(vanilla_savegame_limit), */ + + //! + // @game doom strife + // + // If non-zero, the Vanilla demo size limit is enforced; the game + // exits with an error when a demo exceeds the demo size limit + // (128KiB by default). If this has a value of zero, there is no + // limit to the size of demos. + // + /* CONFIG_VARIABLE_INT(vanilla_demo_limit), */ + + //! + // If non-zero, the game behaves like Vanilla Doom, always assuming + // an American keyboard mapping. If this has a value of zero, the + // native keyboard mapping of the keyboard is used. + // + CONFIG_VARIABLE_INT(vanilla_keyboard_mapping), + + //! + // Name to use in network games for identification. This is only + // used on the "waiting" screen while waiting for the game to start. + // + /* CONFIG_VARIABLE_STRING(player_name), */ + + //! + // If this is non-zero, the mouse will be "grabbed" when running + // in windowed mode so that it can be used as an input device. + // When running full screen, this has no effect. + // + /* CONFIG_VARIABLE_INT(grabmouse), */ + + /* + * NRFD-TODO + * Add mouse confiugration. + * + * //! + * // If non-zero, all vertical mouse movement is ignored. This + * // emulates the behavior of the "novert" tool available under DOS + * // that performs the same function. + * // + * CONFIG_VARIABLE_INT(novert), + * + * //! + * // Mouse acceleration factor. When the speed of mouse movement + * // exceeds the threshold value (mouse_threshold), the speed is + * // multiplied by this value. + * // + * CONFIG_VARIABLE_FLOAT(mouse_acceleration), + * + * //! + * // Mouse acceleration threshold. When the speed of mouse movement + * // exceeds this threshold value, the speed is multiplied by an + * // acceleration factor (mouse_acceleration). + * // + * CONFIG_VARIABLE_INT(mouse_threshold), + * + * //! + * // Mouse button to strafe left. + * // + * CONFIG_VARIABLE_INT(mouseb_strafeleft), + * + * //! + * // Mouse button to strafe right. + * // + * CONFIG_VARIABLE_INT(mouseb_straferight), + * + * //! + * // Mouse button to "use" an object, e.g. a door or switch. + * // + * CONFIG_VARIABLE_INT(mouseb_use), + * + * //! + * // Mouse button to move backwards. + * // + * CONFIG_VARIABLE_INT(mouseb_backward), + * + * //! + * // Mouse button to cycle to the previous weapon. + * // + * CONFIG_VARIABLE_INT(mouseb_prevweapon), + * + * //! + * // Mouse button to cycle to the next weapon. + * // + * CONFIG_VARIABLE_INT(mouseb_nextweapon), + * + * //! + * // If non-zero, double-clicking a mouse button acts like pressing + * // the "use" key to use an object in-game, e.g. a door or switch. + * // + * CONFIG_VARIABLE_INT(dclick_use), + */ + + //! + // SDL GUID string indicating the joystick to use. An empty string + // indicates that no joystick is configured. + // + /* CONFIG_VARIABLE_STRING(joystick_guid), */ + + //! + // Index of SDL joystick to use; this is only used in the case where + // multiple identical joystick devices are connected which have the + // same GUID, to distinguish between devices. + // + /* CONFIG_VARIABLE_INT(joystick_index), */ + + /* + * NRFD-TODO + * Add joystick configuration. + * //! + * // Joystick axis to use to for horizontal (X) movement. + * // + * CONFIG_VARIABLE_INT(joystick_x_axis), + * + * //! + * // If non-zero, movement on the horizontal joystick axis is inverted. + * // + * CONFIG_VARIABLE_INT(joystick_x_invert), + * + * //! + * // Joystick axis to use to for vertical (Y) movement. + * // + * CONFIG_VARIABLE_INT(joystick_y_axis), + * + * //! + * // If non-zero, movement on the vertical joystick axis is inverted. + * // + * CONFIG_VARIABLE_INT(joystick_y_invert), + * + * //! + * // Joystick axis to use to for strafing movement. + * // + * CONFIG_VARIABLE_INT(joystick_strafe_axis), + * + * //! + * // If non-zero, movement on the joystick axis used for strafing + * // is inverted. + * // + * CONFIG_VARIABLE_INT(joystick_strafe_invert), + * + * //! + * // Joystick axis to use to for looking up and down. + * // + * CONFIG_VARIABLE_INT(joystick_look_axis), + * + * //! + * // If non-zero, movement on the joystick axis used for looking + * // is inverted. + * // + * CONFIG_VARIABLE_INT(joystick_look_invert), + * + * //! + * // The physical joystick button that corresponds to joystick + * // virtual button #0. + * // + * CONFIG_VARIABLE_INT(joystick_physical_button0), + * + * //! + * // The physical joystick button that corresponds to joystick + * // virtual button #1. + * // + * CONFIG_VARIABLE_INT(joystick_physical_button1), + * + * //! + * // The physical joystick button that corresponds to joystick + * // virtual button #2. + * // + * CONFIG_VARIABLE_INT(joystick_physical_button2), + * + * //! + * // The physical joystick button that corresponds to joystick + * // virtual button #3. + * // + * CONFIG_VARIABLE_INT(joystick_physical_button3), + * + * //! + * // The physical joystick button that corresponds to joystick + * // virtual button #4. + * // + * CONFIG_VARIABLE_INT(joystick_physical_button4), + * + * //! + * // The physical joystick button that corresponds to joystick + * // virtual button #5. + * // + * CONFIG_VARIABLE_INT(joystick_physical_button5), + * + * //! + * // The physical joystick button that corresponds to joystick + * // virtual button #6. + * // + * CONFIG_VARIABLE_INT(joystick_physical_button6), + * + * //! + * // The physical joystick button that corresponds to joystick + * // virtual button #7. + * // + * CONFIG_VARIABLE_INT(joystick_physical_button7), + * + * //! + * // The physical joystick button that corresponds to joystick + * // virtual button #8. + * // + * CONFIG_VARIABLE_INT(joystick_physical_button8), + * + * //! + * // The physical joystick button that corresponds to joystick + * // virtual button #9. + * // + * CONFIG_VARIABLE_INT(joystick_physical_button9), + * + * //! + * // The physical joystick button that corresponds to joystick + * // virtual button #10. + * // + * CONFIG_VARIABLE_INT(joystick_physical_button10), + * + * //! + * // Joystick virtual button to make the player strafe left. + * // + * CONFIG_VARIABLE_INT(joyb_strafeleft), + * + * //! + * // Joystick virtual button to make the player strafe right. + * // + * CONFIG_VARIABLE_INT(joyb_straferight), + * + * //! + * // Joystick virtual button to activate the menu. + * // + * CONFIG_VARIABLE_INT(joyb_menu_activate), + * + * //! + * // Joystick virtual button to toggle the automap. + * // + * CONFIG_VARIABLE_INT(joyb_toggle_automap), + * + * //! + * // Joystick virtual button that cycles to the previous weapon. + * // + * CONFIG_VARIABLE_INT(joyb_prevweapon), + * + * //! + * // Joystick virtual button that cycles to the next weapon. + * // + * CONFIG_VARIABLE_INT(joyb_nextweapon), + */ + + /* + * NRFD-TODO + * Configurable controls. + * //! + * // Key to pause or unpause the game. + * // + * CONFIG_VARIABLE_KEY(key_pause), + * + * //! + * // Key that activates the menu when pressed. + * // + * CONFIG_VARIABLE_KEY(key_menu_activate), + * + * //! + * // Key that moves the cursor up on the menu. + * // + * CONFIG_VARIABLE_KEY(key_menu_up), + * + * //! + * // Key that moves the cursor down on the menu. + * // + * CONFIG_VARIABLE_KEY(key_menu_down), + * + * //! + * // Key that moves the currently selected slider on the menu left. + * // + * CONFIG_VARIABLE_KEY(key_menu_left), + * + * //! + * // Key that moves the currently selected slider on the menu right. + * // + * CONFIG_VARIABLE_KEY(key_menu_right), + * + * //! + * // Key to go back to the previous menu. + * // + * CONFIG_VARIABLE_KEY(key_menu_back), + * + * //! + * // Key to activate the currently selected menu item. + * // + * CONFIG_VARIABLE_KEY(key_menu_forward), + * + * //! + * // Key to answer 'yes' to a question in the menu. + * // + * CONFIG_VARIABLE_KEY(key_menu_confirm), + * + * //! + * // Key to answer 'no' to a question in the menu. + * // + * CONFIG_VARIABLE_KEY(key_menu_abort), + * + * //! + * // Keyboard shortcut to bring up the help screen. + * // + * CONFIG_VARIABLE_KEY(key_menu_help), + * + * //! + * // Keyboard shortcut to bring up the save game menu. + * // + * CONFIG_VARIABLE_KEY(key_menu_save), + * + * //! + * // Keyboard shortcut to bring up the load game menu. + * // + * CONFIG_VARIABLE_KEY(key_menu_load), + * + * //! + * // Keyboard shortcut to bring up the sound volume menu. + * // + * CONFIG_VARIABLE_KEY(key_menu_volume), + * + * //! + * // Keyboard shortcut to toggle the detail level. + * // + * CONFIG_VARIABLE_KEY(key_menu_detail), + * + * //! + * // Keyboard shortcut to quicksave the current game. + * // + * CONFIG_VARIABLE_KEY(key_menu_qsave), + * + * //! + * // Keyboard shortcut to end the game. + * // + * CONFIG_VARIABLE_KEY(key_menu_endgame), + * + * //! + * // Keyboard shortcut to toggle heads-up messages. + * // + * CONFIG_VARIABLE_KEY(key_menu_messages), + * + * //! + * // Keyboard shortcut to load the last quicksave. + * // + * CONFIG_VARIABLE_KEY(key_menu_qload), + * + * //! + * // Keyboard shortcut to quit the game. + * // + * CONFIG_VARIABLE_KEY(key_menu_quit), + * + * //! + * // Keyboard shortcut to toggle the gamma correction level. + * // + * CONFIG_VARIABLE_KEY(key_menu_gamma), + * + * //! + * // Keyboard shortcut to switch view in multiplayer. + * // + * CONFIG_VARIABLE_KEY(key_spy), + * + * //! + * // Keyboard shortcut to increase the screen size. + * // + * CONFIG_VARIABLE_KEY(key_menu_incscreen), + * + * //! + * // Keyboard shortcut to decrease the screen size. + * // + * CONFIG_VARIABLE_KEY(key_menu_decscreen), + * + * //! + * // Keyboard shortcut to save a screenshot. + * // + * CONFIG_VARIABLE_KEY(key_menu_screenshot), + * + * //! + * // Key to toggle the map view. + * // + * CONFIG_VARIABLE_KEY(key_map_toggle), + * + * //! + * // Key to pan north when in the map view. + * // + * CONFIG_VARIABLE_KEY(key_map_north), + * + * //! + * // Key to pan south when in the map view. + * // + * CONFIG_VARIABLE_KEY(key_map_south), + * + * //! + * // Key to pan east when in the map view. + * // + * CONFIG_VARIABLE_KEY(key_map_east), + * + * //! + * // Key to pan west when in the map view. + * // + * CONFIG_VARIABLE_KEY(key_map_west), + * + * //! + * // Key to zoom in when in the map view. + * // + * CONFIG_VARIABLE_KEY(key_map_zoomin), + * + * //! + * // Key to zoom out when in the map view. + * // + * CONFIG_VARIABLE_KEY(key_map_zoomout), + * + * //! + * // Key to zoom out the maximum amount when in the map view. + * // + * CONFIG_VARIABLE_KEY(key_map_maxzoom), + * + * //! + * // Key to toggle follow mode when in the map view. + * // + * CONFIG_VARIABLE_KEY(key_map_follow), + * + * //! + * // Key to toggle the grid display when in the map view. + * // + * CONFIG_VARIABLE_KEY(key_map_grid), + * + * //! + * // Key to set a mark when in the map view. + * // + * CONFIG_VARIABLE_KEY(key_map_mark), + * + * //! + * // Key to clear all marks when in the map view. + * // + * CONFIG_VARIABLE_KEY(key_map_clearmark), + * + * //! + * // Key to select weapon 1. + * // + * CONFIG_VARIABLE_KEY(key_weapon1), + * + * //! + * // Key to select weapon 2. + * // + * CONFIG_VARIABLE_KEY(key_weapon2), + * + * //! + * // Key to select weapon 3. + * // + * CONFIG_VARIABLE_KEY(key_weapon3), + * + * //! + * // Key to select weapon 4. + * // + * CONFIG_VARIABLE_KEY(key_weapon4), + * + * //! + * // Key to select weapon 5. + * // + * CONFIG_VARIABLE_KEY(key_weapon5), + * + * //! + * // Key to select weapon 6. + * // + * CONFIG_VARIABLE_KEY(key_weapon6), + * + * //! + * // Key to select weapon 7. + * // + * CONFIG_VARIABLE_KEY(key_weapon7), + * + * //! + * // Key to select weapon 8. + * // + * CONFIG_VARIABLE_KEY(key_weapon8), + * + * //! + * // Key to cycle to the previous weapon. + * // + * CONFIG_VARIABLE_KEY(key_prevweapon), + * + * //! + * // Key to cycle to the next weapon. + * // + * CONFIG_VARIABLE_KEY(key_nextweapon), + */ + + /* + * NRFD-EXCLUDE + * Hexen configuration. + * //! + * // @game hexen + * // + * // Key to use one of each artifact. + * // + * CONFIG_VARIABLE_KEY(key_arti_all), + * + * //! + * // @game hexen + * // + * // Key to use "quartz flask" artifact. + * // + * CONFIG_VARIABLE_KEY(key_arti_health), + * + * //! + * // @game hexen + * // + * // Key to use "flechette" artifact. + * // + * CONFIG_VARIABLE_KEY(key_arti_poisonbag), + * + * //! + * // @game hexen + * // + * // Key to use "disc of repulsion" artifact. + * // + * CONFIG_VARIABLE_KEY(key_arti_blastradius), + * + * //! + * // @game hexen + * // + * // Key to use "chaos device" artifact. + * // + * CONFIG_VARIABLE_KEY(key_arti_teleport), + * + * //! + * // @game hexen + * // + * // Key to use "banishment device" artifact. + * // + * CONFIG_VARIABLE_KEY(key_arti_teleportother), + * + * //! + * // @game hexen + * // + * // Key to use "porkalator" artifact. + * // + * CONFIG_VARIABLE_KEY(key_arti_egg), + * + * //! + * // @game hexen + * // + * // Key to use "icon of the defender" artifact. + * // + * CONFIG_VARIABLE_KEY(key_arti_invulnerability), + */ + + /* + * NRFD-TODO + * Configurable controls. + * //! + * // Key to re-display last message. + * // + * CONFIG_VARIABLE_KEY(key_message_refresh), + * + * //! + * // Key to quit the game when recording a demo. + * // + * CONFIG_VARIABLE_KEY(key_demo_quit), + * + * //! + * // Key to send a message during multiplayer games. + * // + * CONFIG_VARIABLE_KEY(key_multi_msg), + * + * //! + * // Key to send a message to player 1 during multiplayer games. + * // + * CONFIG_VARIABLE_KEY(key_multi_msgplayer1), + * + * //! + * // Key to send a message to player 2 during multiplayer games. + * // + * CONFIG_VARIABLE_KEY(key_multi_msgplayer2), + * + * //! + * // Key to send a message to player 3 during multiplayer games. + * // + * CONFIG_VARIABLE_KEY(key_multi_msgplayer3), + * + * //! + * // Key to send a message to player 4 during multiplayer games. + * // + * CONFIG_VARIABLE_KEY(key_multi_msgplayer4), + * + * //! + * // @game hexen strife + * // + * // Key to send a message to player 5 during multiplayer games. + * // + * CONFIG_VARIABLE_KEY(key_multi_msgplayer5), + * + * //! + * // @game hexen strife + * // + * // Key to send a message to player 6 during multiplayer games. + * // + * CONFIG_VARIABLE_KEY(key_multi_msgplayer6), + * + * //! + * // @game hexen strife + * // + * // Key to send a message to player 7 during multiplayer games. + * // + * CONFIG_VARIABLE_KEY(key_multi_msgplayer7), + * + * //! + * // @game hexen strife + * // + * // Key to send a message to player 8 during multiplayer games. + * // + * CONFIG_VARIABLE_KEY(key_multi_msgplayer8), + */ }; static default_collection_t extra_defaults = -{ - extra_defaults_list, - arrlen(extra_defaults_list), - NULL, + { + extra_defaults_list, + arrlen(extra_defaults_list), + NULL, }; -// Search a collection for a variable - +/* Search a collection for a variable */ static default_t *SearchCollection(default_collection_t *collection, char *name) { int i; - for (i=0; inumdefaults; ++i) + for (i = 0; i < collection->numdefaults; ++i) { if (!strcmp(name, collection->defaults[i].name)) { @@ -1693,151 +1498,144 @@ static default_t *SearchCollection(default_collection_t *collection, char *name) return NULL; } -// Mapping from DOS keyboard scan code to internal key code (as defined -// in doomkey.h). I think I (fraggle) reused this from somewhere else -// but I can't find where. Anyway, notes: -// * KEY_PAUSE is wrong - it's in the KEY_NUMLOCK spot. This shouldn't -// matter in terms of Vanilla compatibility because neither of -// those were valid for key bindings. -// * There is no proper scan code for PrintScreen (on DOS machines it -// sends an interrupt). So I added a fake scan code of 126 for it. -// The presence of this is important so we can bind PrintScreen as -// a screenshot key. +/* + * Mapping from DOS keyboard scan code to internal key code (as defined + * in doomkey.h). I think I (fraggle) reused this from somewhere else + * but I can't find where. Anyway, notes: + * 1. KEY_PAUSE is wrong - it's in the KEY_NUMLOCK spot. This shouldn't + * matter in terms of Vanilla compatibility because neither of + * those were valid for key bindings. + * 2. There is no proper scan code for PrintScreen (on DOS machines it + * sends an interrupt). So I added a fake scan code of 126 for it. + * The presence of this is important so we can bind PrintScreen as + * a screenshot key. + */ static const int scantokey[128] = -{ - 0 , 27, '1', '2', '3', '4', '5', '6', - '7', '8', '9', '0', '-', '=', KEY_BACKSPACE, 9, - 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', - 'o', 'p', '[', ']', 13, KEY_RCTRL, 'a', 's', - 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', - '\'', '`', KEY_RSHIFT,'\\', 'z', 'x', 'c', 'v', - 'b', 'n', 'm', ',', '.', '/', KEY_RSHIFT,KEYP_MULTIPLY, - KEY_RALT, ' ', KEY_CAPSLOCK,KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, - KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, /*KEY_NUMLOCK?*/KEY_PAUSE,KEY_SCRLCK,KEY_HOME, - KEY_UPARROW,KEY_PGUP,KEY_MINUS,KEY_LEFTARROW,KEYP_5,KEY_RIGHTARROW,KEYP_PLUS,KEY_END, - KEY_DOWNARROW,KEY_PGDN,KEY_INS,KEY_DEL,0, 0, 0, KEY_F11, - KEY_F12, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, KEY_PRTSCR, 0 -}; - + { + 0, 27, '1', '2', '3', '4', '5', '6', + '7', '8', '9', '0', '-', '=', KEY_BACKSPACE, 9, + 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', + 'o', 'p', '[', ']', 13, KEY_RCTRL, 'a', 's', + 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', + '\'', '`', KEY_RSHIFT, '\\', 'z', 'x', 'c', 'v', + 'b', 'n', 'm', ',', '.', '/', KEY_RSHIFT, KEYP_MULTIPLY, + KEY_RALT, ' ', KEY_CAPSLOCK, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, + KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, /* KEY_NUMLOCK */ KEY_PAUSE, KEY_SCRLCK, KEY_HOME, + KEY_UPARROW, KEY_PGUP, KEY_MINUS, KEY_LEFTARROW, KEYP_5, KEY_RIGHTARROW, KEYP_PLUS, KEY_END, + KEY_DOWNARROW, KEY_PGDN, KEY_INS, KEY_DEL, 0, 0, 0, KEY_F11, + KEY_F12, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, KEY_PRTSCR, 0}; static void SaveDefaultCollection(default_collection_t *collection, const char *filename) { - printf("NRFD-TODO: SaveDefaultCollection\n"); /* - default_t *defaults; - int i, v; - FILE *f; - - f = fopen (filename, "w"); - if (!f) - return; // can't write the file, but don't complain - - defaults = collection->defaults; - - for (i=0 ; inumdefaults ; i++) - { - int chars_written; - - // Ignore unbound variables - - if (!defaults[i].bound) - { - continue; - } - - // Print the name and line up all values at 30 characters - - chars_written = fprintf(f, "%s ", defaults[i].name); - - for (; chars_written < 30; ++chars_written) - fprintf(f, " "); - - // Print the value - - switch (defaults[i].type) - { - case DEFAULT_KEY: - - // use the untranslated version if we can, to reduce - // the possibility of screwing up the user's config - // file - - v = *defaults[i].location.i; - - if (v == KEY_RSHIFT) - { - // Special case: for shift, force scan code for - // right shift, as this is what Vanilla uses. - // This overrides the change check below, to fix - // configuration files made by old versions that - // mistakenly used the scan code for left shift. - - v = 54; - } - else if (defaults[i].untranslated - && v == defaults[i].original_translated) - { - // Has not been changed since the last time we - // read the config file. - - v = defaults[i].untranslated; - } - else - { - // search for a reverse mapping back to a scancode - // in the scantokey table - - int s; - - for (s=0; s<128; ++s) - { - if (scantokey[s] == v) - { - v = s; - break; - } - } - } - - fprintf(f, "%i", v); - break; - - case DEFAULT_INT: - fprintf(f, "%i", *defaults[i].location.i); - break; - - case DEFAULT_INT_HEX: - fprintf(f, "0x%x", *defaults[i].location.i); - break; - - case DEFAULT_FLOAT: - fprintf(f, "%f", *defaults[i].location.f); - break; - - case DEFAULT_STRING: - fprintf(f,"\"%s\"", *defaults[i].location.s); - break; - } - - fprintf(f, "\n"); - } - - fclose (f); - */ + * // NRFD-TODO + * default_t *defaults; + * int i, v; + * FILE *f; + * + * f = fopen(filename, "w"); + * if (!f) + * // Can't write the file, but don't complain + * return; + * + * defaults = collection->defaults; + * + * for (i = 0; i < collection->numdefaults; i++) + * { + * int chars_written; + * + * // Ignore unbound variables + * if (!defaults[i].bound) + * { + * continue; + * } + * + * // Print the name and line up all values at 30 characters + * chars_written = fprintf(f, "%s ", defaults[i].name); + * + * for (; chars_written < 30; ++chars_written) + * fprintf(f, " "); + * + * // Print the value + * switch (defaults[i].type) + * { + * case DEFAULT_KEY: + * + * // Use the untranslated version if we can, to reduce + * // the possibility of screwing up the user's configuration + * // file. + * v = *defaults[i].location.i; + * + * if (v == KEY_RSHIFT) + * { + * // Special case. For shift, force scan code for + * // right shift, as this is what Vanilla uses. + * // This overrides the change check below, to fix + * // configuration files made by old versions that + * // mistakenly used the scan code for left shift. + * v = 54; + * } + * else if (defaults[i].untranslated && v == defaults[i].original_translated) + * { + * // Has not been changed since the last time we + * // read the config file. + * + * v = defaults[i].untranslated; + * } + * else + * { + * // Search for a reverse mapping back to a scancode + * // in the scantokey table. + * int s; + * + * for (s = 0; s < 128; ++s) + * { + * if (scantokey[s] == v) + * { + * v = s; + * break; + * } + * } + * } + * + * fprintf(f, "%i", v); + * break; + * + * case DEFAULT_INT: + * fprintf(f, "%i", *defaults[i].location.i); + * break; + * + * case DEFAULT_INT_HEX: + * fprintf(f, "0x%x", *defaults[i].location.i); + * break; + * + * case DEFAULT_FLOAT: + * fprintf(f, "%f", *defaults[i].location.f); + * break; + * + * case DEFAULT_STRING: + * fprintf(f, "\"%s\"", *defaults[i].location.s); + * break; + * } + * + * fprintf(f, "\n"); + * } + * + * fclose(f); + */ } -// Parses integer values in the configuration file - +/* Parses integer values in the configuration file */ static int ParseIntParameter(char *strparm) { int parm; if (strparm[0] == '0' && strparm[1] == 'x') - sscanf(strparm+2, "%x", &parm); + sscanf(strparm + 2, "%x", &parm); else sscanf(strparm, "%i", &parm); @@ -1848,168 +1646,152 @@ static void SetVariable(default_t *def, char *value) { int intparm; - // parameter found - + /* Parameter found */ switch (def->type) { - case DEFAULT_STRING: - *def->location.s = M_StringDuplicate(value); - break; - - case DEFAULT_INT: - case DEFAULT_INT_HEX: - *def->location.i = ParseIntParameter(value); - break; - - case DEFAULT_KEY: - - // translate scancodes read from config - // file (save the old value in untranslated) - - intparm = ParseIntParameter(value); - /* NRFD-TODO: translate? - def->untranslated = intparm; - if (intparm >= 0 && intparm < 128) - { - intparm = scantokey[intparm]; - } - else - { - intparm = 0; - } - - def->original_translated = intparm; - */ - *def->location.i = intparm; - break; - - case DEFAULT_FLOAT: - *def->location.f = (float) atof(value); - break; + case DEFAULT_STRING: + *def->location.s = M_StringDuplicate(value); + break; + + case DEFAULT_INT: + case DEFAULT_INT_HEX: + *def->location.i = ParseIntParameter(value); + break; + + case DEFAULT_KEY: + + /* + * Translate scancodes read from configuration + * file (save the old value in untranslated). + */ + intparm = ParseIntParameter(value); + + /* + * // NRFD-TODO + * // Translate + * def->untranslated = intparm; + * if (intparm >= 0 && intparm < 128) + * { + * intparm = scantokey[intparm]; + * } + * else + * { + * intparm = 0; + * } + * + * def->original_translated = intparm; + */ + + *def->location.i = intparm; + break; + + case DEFAULT_FLOAT: + *def->location.f = (float)atof(value); + break; } } static void LoadDefaultCollection(default_collection_t *collection, const char *filename) { - printf("NRFD-TODO: LoadDefaultCollection\n"); - // TODO: Use FatFS /* - FILE *f; - default_t *def; - char defname[80]; - char strparm[100]; - - // read the file in, overriding any set defaults - f = fopen(collection->filename, "r"); - - if (f == NULL) - { - // File not opened, but don't complain. - // It's probably just the first time they ran the game. - - return; - } - - while (!feof(f)) - { - if (fscanf(f, "%79s %99[^\n]\n", defname, strparm) != 2) - { - // This line doesn't match - - continue; - } - - // Find the setting in the list - - def = SearchCollection(collection, defname); - - if (def == NULL || !def->bound) - { - // Unknown variable? Unbound variables are also treated - // as unknown. - - continue; - } - - // Strip off trailing non-printable characters (\r characters - // from DOS text files) - - while (strlen(strparm) > 0 && !isprint(strparm[strlen(strparm)-1])) - { - strparm[strlen(strparm)-1] = '\0'; - } - - // Surrounded by quotes? If so, remove them. - if (strlen(strparm) >= 2 - && strparm[0] == '"' && strparm[strlen(strparm) - 1] == '"') - { - strparm[strlen(strparm) - 1] = '\0'; - memmove(strparm, strparm + 1, sizeof(strparm) - 1); - } - - SetVariable(def, strparm); - } - - fclose (f); - */ + * // TODO + * // Use FatFS. + * FILE *f; + * default_t *def; + * char defname[80]; + * char strparm[100]; + * + * // Read the file in, overriding any set defaults + * f = fopen(collection->filename, "r"); + * + * if (f == NULL) + * { + * // File not opened, but don't complain. + * // It's probably just the first time they ran the game. + * return; + * } + * + * while (!feof(f)) + * { + * if (fscanf(f, "%79s %99[^\n]\n", defname, strparm) != 2) + * { + * // This line doesn't match + * continue; + * } + * + * // Find the setting in the list + * def = SearchCollection(collection, defname); + * + * if (def == NULL || !def->bound) + * { + * // Unknown variable. Unbound variables are also treated + * // as unknown. + * continue; + * } + * + * // Strip off trailing non-printable characters (\r characters + * // from DOS text files). + * while (strlen(strparm) > 0 && !isprint(strparm[strlen(strparm) - 1])) + * { + * strparm[strlen(strparm) - 1] = '\0'; + * } + * + * // Surrounded by quotes. If so, remove them. + * if (strlen(strparm) >= 2 && strparm[0] == '"' && strparm[strlen(strparm) - 1] == '"') + * { + * strparm[strlen(strparm) - 1] = '\0'; + * memmove(strparm, strparm + 1, sizeof(strparm) - 1); + * } + * + * SetVariable(def, strparm); + * } + * + * fclose(f); + */ } -// Set the default filenames to use for configuration files. - +/* Set the default filenames to use for configuration files. */ void M_SetConfigFilenames(char *main_config, char *extra_config) { - /* NRFD-EXCLUDE - default_main_config = main_config; - default_extra_config = extra_config; - */ + /* + * // NRFD-EXCLUDE + * default_main_config = main_config; + * default_extra_config = extra_config; + */ } -// -// M_SaveDefaults -// - -void M_SaveDefaults (void) +void M_SaveDefaults(void) { SaveDefaultCollection(&doom_defaults, default_main_config); SaveDefaultCollection(&extra_defaults, default_extra_config); } -// -// Save defaults to alternate filenames -// - +/* Save defaults to alternate filenames. */ void M_SaveDefaultsAlternate(char *main, char *extra) { - /* NRFD-EXCLUDE - char *orig_main; - char *orig_extra; - - // Temporarily change the filenames - - orig_main = doom_defaults.filename; - orig_extra = extra_defaults.filename; - - doom_defaults.filename = main; - extra_defaults.filename = extra; - - M_SaveDefaults(); - - // Restore normal filenames - - doom_defaults.filename = orig_main; - extra_defaults.filename = orig_extra; - */ + /* + * // NRFD-EXCLUDE + * char *orig_main; + * char *orig_extra; + * + * // Temporarily change the filenames + * orig_main = doom_defaults.filename; + * orig_extra = extra_defaults.filename; + * + * doom_defaults.filename = main; + * extra_defaults.filename = extra; + * + * M_SaveDefaults(); + * + * // Restore normal filenames + * doom_defaults.filename = orig_main; + * extra_defaults.filename = orig_extra; + */ } -// -// M_LoadDefaults -// - -void M_LoadDefaults (void) +void M_LoadDefaults(void) { - int i; - - // check for a custom default file + /* Check for a custom default file */ //! // @arg @@ -2018,53 +1800,54 @@ void M_LoadDefaults (void) // Load main configuration from the specified file, instead of the // default. // -/* NRFD_EXCLUDE - i = M_CheckParmWithArgs("-config", 1); - - if (i) - { - doom_defaults.filename = myargv[i+1]; - printf (" default file: %s\n",doom_defaults.filename); - } - else - { - doom_defaults.filename = M_StringJoin(configdir, default_main_config, NULL); - } - - printf("saving config in %s\n", doom_defaults.filename); - - //! - // @arg - // - // Load additional configuration from the specified file, instead of - // the default. - // - i = M_CheckParmWithArgs("-extraconfig", 1); + /* + * // NRFD-EXCLUDE + * int i; + * i = M_CheckParmWithArgs("-config", 1); + * + * if (i) + * { + * doom_defaults.filename = myargv[i + 1]; + * printf(" default file: %s\n", doom_defaults.filename); + * } + * else + * { + * doom_defaults.filename = M_StringJoin(configdir, default_main_config, NULL); + * } + * + * printf("saving config in %s\n", doom_defaults.filename); + * + * //! + * // @arg + * // + * // Load additional configuration from the specified file, instead of + * // the default. + * // + * i = M_CheckParmWithArgs("-extraconfig", 1); + * + * if (i) + * { + * extra_defaults.filename = myargv[i + 1]; + * printf(" extra configuration file: %s\n", + * extra_defaults.filename); + * } + * else + * { + * extra_defaults.filename = M_StringJoin(configdir, default_extra_config, NULL); + * } + */ - if (i) - { - extra_defaults.filename = myargv[i+1]; - printf(" extra configuration file: %s\n", - extra_defaults.filename); - } - else - { - extra_defaults.filename = M_StringJoin(configdir, default_extra_config, NULL); - } -*/ LoadDefaultCollection(&doom_defaults, default_main_config); LoadDefaultCollection(&extra_defaults, default_extra_config); } -// Get a configuration file variable by its name - +/* Get a configuration file variable by its name. */ static default_t *GetDefaultForName(char *name) { default_t *result; - // Try the main list and the extras - + /* Try the main list and the extras */ result = SearchCollection(&doom_defaults, name); if (result == NULL) @@ -2072,8 +1855,7 @@ static default_t *GetDefaultForName(char *name) result = SearchCollection(&extra_defaults, name); } - // Not found? Internal error. - + /* Not found. Internal error. */ if (result == NULL) { I_Error("Unknown configuration variable: '%s'", name); @@ -2082,18 +1864,13 @@ static default_t *GetDefaultForName(char *name) return result; } -// -// Bind a variable to a given configuration file variable, by name. -// - +/* Bind a variable to a given configuration file variable, by name. */ void M_BindIntVariable(char *name, int *location) { default_t *variable; variable = GetDefaultForName(name); - assert(variable->type == DEFAULT_INT - || variable->type == DEFAULT_INT_HEX - || variable->type == DEFAULT_KEY); + assert(variable->type == DEFAULT_INT || variable->type == DEFAULT_INT_HEX || variable->type == DEFAULT_KEY); variable->location.i = location; variable->bound = true; @@ -2121,9 +1898,10 @@ void M_BindStringVariable(char *name, char **location) variable->bound = true; } -// Set the value of a particular variable; an API function for other -// parts of the program to assign values to config variables by name. - +/* + * Set the value of a particular variable. An API function for other + * parts of the program to assign values to config variables by name. + */ boolean M_SetVariable(char *name, char *value) { default_t *variable; @@ -2140,16 +1918,14 @@ boolean M_SetVariable(char *name, char *value) return true; } -// Get the value of a variable. - +/* Get the value of a variable. */ int M_GetIntVariable(char *name) { default_t *variable; variable = GetDefaultForName(name); - if (variable == NULL || !variable->bound - || (variable->type != DEFAULT_INT && variable->type != DEFAULT_INT_HEX)) + if (variable == NULL || !variable->bound || (variable->type != DEFAULT_INT && variable->type != DEFAULT_INT_HEX)) { return 0; } @@ -2163,8 +1939,7 @@ const char *M_GetStringVariable(char *name) variable = GetDefaultForName(name); - if (variable == NULL || !variable->bound - || variable->type != DEFAULT_STRING) + if (variable == NULL || !variable->bound || variable->type != DEFAULT_STRING) { return NULL; } @@ -2178,8 +1953,7 @@ float M_GetFloatVariable(char *name) variable = GetDefaultForName(name); - if (variable == NULL || !variable->bound - || variable->type != DEFAULT_FLOAT) + if (variable == NULL || !variable->bound || variable->type != DEFAULT_FLOAT) { return 0; } @@ -2187,103 +1961,98 @@ float M_GetFloatVariable(char *name) return *variable->location.f; } -// Get the path to the default configuration dir to use, if NULL -// is passed to M_SetConfigDir. - +/* + * Get the path to the default configuration dir to use, if NULL + * is passed to M_SetConfigDir. + */ static char *GetDefaultConfigDir(void) { return M_StringDuplicate(""); } -// -// SetConfigDir: -// -// Sets the location of the configuration directory, where configuration -// files are stored - default.cfg, chocolate-doom.cfg, savegames, etc. -// - +/* + * Sets the location of the configuration directory, where configuration + * files are stored - default.cfg, chocolate-doom.cfg, savegames, etc. + */ void M_SetConfigDir(char *dir) { - // Use the directory that was passed, or find the default. - /* NRFD-EXCLUDE - - if (dir != NULL) - { - configdir = dir; - } - else - { - configdir = GetDefaultConfigDir(); - } - - if (strcmp(configdir, "") != 0) - { - printf("Using %s for configuration and saves\n", configdir); - } - - // Make the directory if it doesn't already exist: - M_MakeDirectory(configdir); - */ + /* Use the directory that was passed, or find the default. */ + /* + * // NRFD-EXCLUDE + * + * if (dir != NULL) + * { + * configdir = dir; + * } + * else + * { + * configdir = GetDefaultConfigDir(); + * } + * + * if (strcmp(configdir, "") != 0) + * { + * printf("Using %s for configuration and saves\n", configdir); + * } + * + * // Make the directory if it doesn't already exist + * M_MakeDirectory(configdir); + */ } -// -// Calculate the path to the directory to use to store save games. -// Creates the directory as necessary. -// - +/* + * Calculate the path to the directory to use to store save games. + * Creates the directory as necessary. + */ char *M_GetSaveGameDir(char *iwadname) { - printf("NRFD-TODO: M_GetSaveGameDir\n"); return "/savegames"; - /* - char *savegamedir; - char *topdir; - int p; - - //! - // @arg - // - // Specify a path from which to load and save games. If the directory - // does not exist then it will automatically be created. - // - - p = M_CheckParmWithArgs("-savedir", 1); - if (p) - { - savegamedir = myargv[p + 1]; - if (!M_FileExists(savegamedir)) - { - M_MakeDirectory(savegamedir); - } - - // add separator at end just in case - savegamedir = M_StringJoin(savegamedir, DIR_SEPARATOR_S, NULL); - - printf("Save directory changed to %s.\n", savegamedir); - } - // If not "doing" a configuration directory (Windows), don't "do" - // a savegame directory, either. - else if (!strcmp(configdir, "")) - { - savegamedir = M_StringDuplicate(""); - } - else - { - // ~/.local/share/chocolate-doom/savegames - - topdir = M_StringJoin(configdir, "savegames", NULL); - M_MakeDirectory(topdir); - - // eg. ~/.local/share/chocolate-doom/savegames/doom2.wad/ - - savegamedir = M_StringJoin(topdir, DIR_SEPARATOR_S, iwadname, - DIR_SEPARATOR_S, NULL); - M_MakeDirectory(savegamedir); - - free(topdir); - } - - return savegamedir; - */ + /* + * // NRFD-TODO + * char *savegamedir; + * char *topdir; + * int p; + * + * //! + * // @arg + * // + * // Specify a path from which to load and save games. If the directory + * // does not exist then it will automatically be created. + * // + * p = M_CheckParmWithArgs("-savedir", 1); + * if (p) + * { + * savegamedir = myargv[p + 1]; + * if (!M_FileExists(savegamedir)) + * { + * M_MakeDirectory(savegamedir); + * } + * + * // Add separator at end just in case + * savegamedir = M_StringJoin(savegamedir, DIR_SEPARATOR_S, NULL); + * + * printf("Save directory changed to %s.\n", savegamedir); + * } + * + * // If not "doing" a configuration directory (Windows), don't "do" + * // a savegame directory, either. + * else if (!strcmp(configdir, "")) + * { + * savegamedir = M_StringDuplicate(""); + * } + * else + * { + * topdir = M_StringJoin(configdir, "savegames", NULL); + * M_MakeDirectory(topdir); + * + * savegamedir = M_StringJoin(topdir, DIR_SEPARATOR_S, iwadname, + * DIR_SEPARATOR_S, NULL); + * + * M_MakeDirectory(savegamedir); + * + * free(topdir); + * } + * + * return savegamedir; + */ } diff --git a/zephyrdoom/src/m_config.h b/zephyrdoom/src/m_config.h index 12d403d..2640780 100644 --- a/zephyrdoom/src/m_config.h +++ b/zephyrdoom/src/m_config.h @@ -1,21 +1,20 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Configuration file interface. -// - +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Configuration file interface. + */ #ifndef __M_CONFIG__ #define __M_CONFIG__ @@ -38,4 +37,4 @@ char *M_GetSaveGameDir(char *iwadname); extern char *configdir; -#endif +#endif /* __M_CONFIG__ */ diff --git a/zephyrdoom/src/m_controls.c b/zephyrdoom/src/m_controls.c index 3689965..b3cf34d 100644 --- a/zephyrdoom/src/m_controls.c +++ b/zephyrdoom/src/m_controls.c @@ -1,18 +1,18 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 1993-2008 Raven Software -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 1993-2008 Raven Software + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ #include @@ -22,12 +22,12 @@ #include "m_config.h" #include "m_misc.h" -// -// Keyboard controls -// - -// NRFD-TODO: Configurable controls +/* + * NRFD-TODO + * Configurable controls. + */ +/* Keyboard controls. */ const int key_right = KEY_RIGHTARROW; const int key_left = KEY_LEFTARROW; @@ -40,10 +40,7 @@ const int key_use = 'j'; const int key_strafe = KEY_RALT; const int key_speed = 'k'; -// -// Heretic keyboard controls -// - +/* Heretic keyboard controls. */ const int key_flyup = KEY_PGUP; const int key_flydown = KEY_INS; const int key_flycenter = KEY_HOME; @@ -56,45 +53,37 @@ const int key_invleft = '['; const int key_invright = ']'; const int key_useartifact = KEY_ENTER; -// -// Hexen key controls -// - +/* Hexen key controls. */ const int key_jump = '/'; -const int key_arti_all = KEY_BACKSPACE; -const int key_arti_health = '\\'; -const int key_arti_poisonbag = '0'; -const int key_arti_blastradius = '9'; -const int key_arti_teleport = '8'; -const int key_arti_teleportother = '7'; -const int key_arti_egg = '6'; +const int key_arti_all = KEY_BACKSPACE; +const int key_arti_health = '\\'; +const int key_arti_poisonbag = '0'; +const int key_arti_blastradius = '9'; +const int key_arti_teleport = '8'; +const int key_arti_teleportother = '7'; +const int key_arti_egg = '6'; const int key_arti_invulnerability = '5'; -// -// Strife key controls -// -// haleyjd 09/01/10 -// - -// Note: Strife also uses key_invleft, key_invright, key_jump, key_lookup, and -// key_lookdown, but with different default values. - +/* + * Strife key controls. + * + * haleyjd 09/01/10 + * + * Strife also uses key_invleft, key_invright, key_jump, key_lookup, and + * key_lookdown, but with different default values. + */ const int key_usehealth = 'h'; -const int key_invquery = 'q'; -const int key_mission = 'w'; -const int key_invpop = 'z'; -const int key_invkey = 'k'; -const int key_invhome = KEY_HOME; -const int key_invend = KEY_END; -const int key_invuse = KEY_ENTER; -const int key_invdrop = KEY_BACKSPACE; - - -// -// Mouse controls -// - +const int key_invquery = 'q'; +const int key_mission = 'w'; +const int key_invpop = 'z'; +const int key_invkey = 'k'; +const int key_invhome = KEY_HOME; +const int key_invend = KEY_END; +const int key_invuse = KEY_ENTER; +const int key_invdrop = KEY_BACKSPACE; + +/* Mouse controls. */ const int mousebfire = 0; const int mousebstrafe = 1; const int mousebforward = 2; @@ -109,24 +98,20 @@ const int mousebuse = -1; const int mousebprevweapon = -1; const int mousebnextweapon = -1; - const int key_message_refresh = KEY_ENTER; const int key_pause = KEY_PAUSE; const int key_demo_quit = 'q'; const int key_spy = KEY_F12; -// Multiplayer chat keys: - +/* Multiplayer chat keys. */ const int key_multi_msg = 't'; const int key_multi_msgplayer[4] = { - 'g', - 'i', - 'b', - 'r' - }; - -// Weapon selection keys: + 'g', + 'i', + 'b', + 'r'}; +/* Weapon selection keys. */ const int key_weapon1 = '1'; const int key_weapon2 = '2'; const int key_weapon3 = '3'; @@ -138,53 +123,48 @@ const int key_weapon8 = '8'; const int key_prevweapon = 0; const int key_nextweapon = 0; -// Map control keys: - -const int key_map_north = KEY_UPARROW; -const int key_map_south = KEY_DOWNARROW; -const int key_map_east = KEY_RIGHTARROW; -const int key_map_west = KEY_LEFTARROW; -const int key_map_zoomin = '='; -const int key_map_zoomout = '-'; -const int key_map_toggle = 'm'; -const int key_map_maxzoom = '0'; -const int key_map_follow = 'f'; -const int key_map_grid = 'g'; -const int key_map_mark = 'm'; +/* Map control keys. */ +const int key_map_north = KEY_UPARROW; +const int key_map_south = KEY_DOWNARROW; +const int key_map_east = KEY_RIGHTARROW; +const int key_map_west = KEY_LEFTARROW; +const int key_map_zoomin = '='; +const int key_map_zoomout = '-'; +const int key_map_toggle = 'm'; +const int key_map_maxzoom = '0'; +const int key_map_follow = 'f'; +const int key_map_grid = 'g'; +const int key_map_mark = 'm'; const int key_map_clearmark = 'c'; -// menu keys: - -const int key_menu_activate = KEY_ESCAPE; -const int key_menu_up = KEY_UPARROW; -const int key_menu_down = KEY_DOWNARROW; -const int key_menu_left = KEY_LEFTARROW; -const int key_menu_right = KEY_RIGHTARROW; -const int key_menu_back = KEY_BACKSPACE; -const int key_menu_forward = KEY_ENTER; -const int key_menu_confirm = 'y'; -const int key_menu_abort = 'n'; - -const int key_menu_help = KEY_F1; -const int key_menu_save = KEY_F2; -const int key_menu_load = KEY_F3; -const int key_menu_volume = KEY_F4; -const int key_menu_detail = KEY_F5; -const int key_menu_qsave = KEY_F6; -const int key_menu_endgame = KEY_F7; -const int key_menu_messages = KEY_F8; -const int key_menu_qload = KEY_F9; -const int key_menu_quit = KEY_F10; -const int key_menu_gamma = 'g';//KEY_F11; +/* Menu keys. */ +const int key_menu_activate = KEY_ESCAPE; +const int key_menu_up = KEY_UPARROW; +const int key_menu_down = KEY_DOWNARROW; +const int key_menu_left = KEY_LEFTARROW; +const int key_menu_right = KEY_RIGHTARROW; +const int key_menu_back = KEY_BACKSPACE; +const int key_menu_forward = KEY_ENTER; +const int key_menu_confirm = 'y'; +const int key_menu_abort = 'n'; + +const int key_menu_help = KEY_F1; +const int key_menu_save = KEY_F2; +const int key_menu_load = KEY_F3; +const int key_menu_volume = KEY_F4; +const int key_menu_detail = KEY_F5; +const int key_menu_qsave = KEY_F6; +const int key_menu_endgame = KEY_F7; +const int key_menu_messages = KEY_F8; +const int key_menu_qload = KEY_F9; +const int key_menu_quit = KEY_F10; +const int key_menu_gamma = 'g'; /* KEY_F11; */ const int key_menu_incscreen = KEY_EQUALS; const int key_menu_decscreen = KEY_MINUS; const int key_menu_screenshot = 0; -// -// Joystick controls -// - +/* Joystick controls. */ const int joybfire = 5; const int joybstrafe = -1; const int joybuse = 3; @@ -201,233 +181,231 @@ const int joybnextweapon = 4; const int joybmenu = -1; const int joybautomap = 6; -// Control whether if a mouse button is double clicked, it acts like -// "use" has been pressed - +/* + * Control whether if a mouse button is double clicked, it acts like + * "use" has been pressed. + */ const int dclick_use = 1; -// -// Bind all of the common controls used by Doom and all other games. -// - +/* Bind all of the common controls used by Doom and all other games. */ void M_BindBaseControls(void) { - printf("NRFD-TODO: M_BindStrifeControls\n"); /* - M_BindIntVariable("key_right", &key_right); - M_BindIntVariable("key_left", &key_left); - M_BindIntVariable("key_up", &key_up); - M_BindIntVariable("key_down", &key_down); - M_BindIntVariable("key_strafeleft", &key_strafeleft); - M_BindIntVariable("key_straferight", &key_straferight); - M_BindIntVariable("key_fire", &key_fire); - M_BindIntVariable("key_use", &key_use); - M_BindIntVariable("key_strafe", &key_strafe); - M_BindIntVariable("key_speed", &key_speed); - - M_BindIntVariable("mouseb_fire", &mousebfire); - M_BindIntVariable("mouseb_strafe", &mousebstrafe); - M_BindIntVariable("mouseb_forward", &mousebforward); - - M_BindIntVariable("joyb_fire", &joybfire); - M_BindIntVariable("joyb_strafe", &joybstrafe); - M_BindIntVariable("joyb_use", &joybuse); - M_BindIntVariable("joyb_speed", &joybspeed); - - M_BindIntVariable("joyb_menu_activate", &joybmenu); - M_BindIntVariable("joyb_toggle_automap", &joybautomap); - - // Extra controls that are not in the Vanilla versions: - - M_BindIntVariable("joyb_strafeleft", &joybstrafeleft); - M_BindIntVariable("joyb_straferight", &joybstraferight); - - M_BindIntVariable("mouseb_strafeleft", &mousebstrafeleft); - M_BindIntVariable("mouseb_straferight", &mousebstraferight); - M_BindIntVariable("mouseb_use", &mousebuse); - M_BindIntVariable("mouseb_backward", &mousebbackward); - M_BindIntVariable("dclick_use", &dclick_use); - M_BindIntVariable("key_pause", &key_pause); - M_BindIntVariable("key_message_refresh", &key_message_refresh); - */ + * // NRFD-TODO + * M_BindIntVariable("key_right", &key_right); + * M_BindIntVariable("key_left", &key_left); + * M_BindIntVariable("key_up", &key_up); + * M_BindIntVariable("key_down", &key_down); + * M_BindIntVariable("key_strafeleft", &key_strafeleft); + * M_BindIntVariable("key_straferight", &key_straferight); + * M_BindIntVariable("key_fire", &key_fire); + * M_BindIntVariable("key_use", &key_use); + * M_BindIntVariable("key_strafe", &key_strafe); + * M_BindIntVariable("key_speed", &key_speed); + * + * M_BindIntVariable("mouseb_fire", &mousebfire); + * M_BindIntVariable("mouseb_strafe", &mousebstrafe); + * M_BindIntVariable("mouseb_forward", &mousebforward); + * + * M_BindIntVariable("joyb_fire", &joybfire); + * M_BindIntVariable("joyb_strafe", &joybstrafe); + * M_BindIntVariable("joyb_use", &joybuse); + * M_BindIntVariable("joyb_speed", &joybspeed); + * + * M_BindIntVariable("joyb_menu_activate", &joybmenu); + * M_BindIntVariable("joyb_toggle_automap", &joybautomap); + * + * // Extra controls that are not in the Vanilla versions + * M_BindIntVariable("joyb_strafeleft", &joybstrafeleft); + * M_BindIntVariable("joyb_straferight", &joybstraferight); + * + * M_BindIntVariable("mouseb_strafeleft", &mousebstrafeleft); + * M_BindIntVariable("mouseb_straferight", &mousebstraferight); + * M_BindIntVariable("mouseb_use", &mousebuse); + * M_BindIntVariable("mouseb_backward", &mousebbackward); + * M_BindIntVariable("dclick_use", &dclick_use); + * M_BindIntVariable("key_pause", &key_pause); + * M_BindIntVariable("key_message_refresh", &key_message_refresh); + */ } void M_BindHereticControls(void) { - printf("NRFD-TODO: M_BindStrifeControls\n"); /* - M_BindIntVariable("key_flyup", &key_flyup); - M_BindIntVariable("key_flydown", &key_flydown); - M_BindIntVariable("key_flycenter", &key_flycenter); - - M_BindIntVariable("key_lookup", &key_lookup); - M_BindIntVariable("key_lookdown", &key_lookdown); - M_BindIntVariable("key_lookcenter", &key_lookcenter); - - M_BindIntVariable("key_invleft", &key_invleft); - M_BindIntVariable("key_invright", &key_invright); - M_BindIntVariable("key_useartifact", &key_useartifact); - */ + * // NRFD-TODO + * M_BindIntVariable("key_flyup", &key_flyup); + * M_BindIntVariable("key_flydown", &key_flydown); + * M_BindIntVariable("key_flycenter", &key_flycenter); + * + * M_BindIntVariable("key_lookup", &key_lookup); + * M_BindIntVariable("key_lookdown", &key_lookdown); + * M_BindIntVariable("key_lookcenter", &key_lookcenter); + * + * M_BindIntVariable("key_invleft", &key_invleft); + * M_BindIntVariable("key_invright", &key_invright); + * M_BindIntVariable("key_useartifact", &key_useartifact); + */ } void M_BindHexenControls(void) { - printf("NRFD-TODO: M_BindStrifeControls\n"); /* - - M_BindIntVariable("key_jump", &key_jump); - M_BindIntVariable("mouseb_jump", &mousebjump); - M_BindIntVariable("joyb_jump", &joybjump); - - M_BindIntVariable("key_arti_all", &key_arti_all); - M_BindIntVariable("key_arti_health", &key_arti_health); - M_BindIntVariable("key_arti_poisonbag", &key_arti_poisonbag); - M_BindIntVariable("key_arti_blastradius", &key_arti_blastradius); - M_BindIntVariable("key_arti_teleport", &key_arti_teleport); - M_BindIntVariable("key_arti_teleportother", &key_arti_teleportother); - M_BindIntVariable("key_arti_egg", &key_arti_egg); - M_BindIntVariable("key_arti_invulnerability", &key_arti_invulnerability); - */ + * // NRFD-TODO + * M_BindIntVariable("key_jump", &key_jump); + * M_BindIntVariable("mouseb_jump", &mousebjump); + * M_BindIntVariable("joyb_jump", &joybjump); + * + * M_BindIntVariable("key_arti_all", &key_arti_all); + * M_BindIntVariable("key_arti_health", &key_arti_health); + * M_BindIntVariable("key_arti_poisonbag", &key_arti_poisonbag); + * M_BindIntVariable("key_arti_blastradius", &key_arti_blastradius); + * M_BindIntVariable("key_arti_teleport", &key_arti_teleport); + * M_BindIntVariable("key_arti_teleportother", &key_arti_teleportother); + * M_BindIntVariable("key_arti_egg", &key_arti_egg); + * M_BindIntVariable("key_arti_invulnerability", &key_arti_invulnerability); + */ } void M_BindStrifeControls(void) { - printf("NRFD-TODO: M_BindStrifeControls\n"); /* - // These are shared with all games, but have different defaults: - key_message_refresh = '/'; - - // These keys are shared with Heretic/Hexen but have different defaults: - key_jump = 'a'; - key_lookup = KEY_PGUP; - key_lookdown = KEY_PGDN; - key_invleft = KEY_INS; - key_invright = KEY_DEL; - - M_BindIntVariable("key_jump", &key_jump); - M_BindIntVariable("key_lookUp", &key_lookup); - M_BindIntVariable("key_lookDown", &key_lookdown); - M_BindIntVariable("key_invLeft", &key_invleft); - M_BindIntVariable("key_invRight", &key_invright); - - // Custom Strife-only Keys: - M_BindIntVariable("key_useHealth", &key_usehealth); - M_BindIntVariable("key_invquery", &key_invquery); - M_BindIntVariable("key_mission", &key_mission); - M_BindIntVariable("key_invPop", &key_invpop); - M_BindIntVariable("key_invKey", &key_invkey); - M_BindIntVariable("key_invHome", &key_invhome); - M_BindIntVariable("key_invEnd", &key_invend); - M_BindIntVariable("key_invUse", &key_invuse); - M_BindIntVariable("key_invDrop", &key_invdrop); - - // Strife also supports jump on mouse and joystick, and in the exact same - // manner as Hexen! - M_BindIntVariable("mouseb_jump", &mousebjump); - M_BindIntVariable("joyb_jump", &joybjump); - */ + * // NRFD-TODO + * // These are shared with all games, but have different defaults + * key_message_refresh = '/'; + * + * // These keys are shared with Heretic/Hexen but have different defaults + * key_jump = 'a'; + * key_lookup = KEY_PGUP; + * key_lookdown = KEY_PGDN; + * key_invleft = KEY_INS; + * key_invright = KEY_DEL; + * + * M_BindIntVariable("key_jump", &key_jump); + * M_BindIntVariable("key_lookUp", &key_lookup); + * M_BindIntVariable("key_lookDown", &key_lookdown); + * M_BindIntVariable("key_invLeft", &key_invleft); + * M_BindIntVariable("key_invRight", &key_invright); + * + * // Custom Strife-only Keys: + * M_BindIntVariable("key_useHealth", &key_usehealth); + * M_BindIntVariable("key_invquery", &key_invquery); + * M_BindIntVariable("key_mission", &key_mission); + * M_BindIntVariable("key_invPop", &key_invpop); + * M_BindIntVariable("key_invKey", &key_invkey); + * M_BindIntVariable("key_invHome", &key_invhome); + * M_BindIntVariable("key_invEnd", &key_invend); + * M_BindIntVariable("key_invUse", &key_invuse); + * M_BindIntVariable("key_invDrop", &key_invdrop); + * + * // Strife also supports jump on mouse and joystick, and in the exact same + * // manner as Hexen! + * M_BindIntVariable("mouseb_jump", &mousebjump); + * M_BindIntVariable("joyb_jump", &joybjump); + */ } void M_BindWeaponControls(void) { - printf("NRFD-TODO: M_BindWeaponControls\n"); /* - M_BindIntVariable("key_weapon1", &key_weapon1); - M_BindIntVariable("key_weapon2", &key_weapon2); - M_BindIntVariable("key_weapon3", &key_weapon3); - M_BindIntVariable("key_weapon4", &key_weapon4); - M_BindIntVariable("key_weapon5", &key_weapon5); - M_BindIntVariable("key_weapon6", &key_weapon6); - M_BindIntVariable("key_weapon7", &key_weapon7); - M_BindIntVariable("key_weapon8", &key_weapon8); - - M_BindIntVariable("key_prevweapon", &key_prevweapon); - M_BindIntVariable("key_nextweapon", &key_nextweapon); - - M_BindIntVariable("joyb_prevweapon", &joybprevweapon); - M_BindIntVariable("joyb_nextweapon", &joybnextweapon); - - M_BindIntVariable("mouseb_prevweapon", &mousebprevweapon); - M_BindIntVariable("mouseb_nextweapon", &mousebnextweapon); - */ + * // NRFD-TODO + * M_BindIntVariable("key_weapon1", &key_weapon1); + * M_BindIntVariable("key_weapon2", &key_weapon2); + * M_BindIntVariable("key_weapon3", &key_weapon3); + * M_BindIntVariable("key_weapon4", &key_weapon4); + * M_BindIntVariable("key_weapon5", &key_weapon5); + * M_BindIntVariable("key_weapon6", &key_weapon6); + * M_BindIntVariable("key_weapon7", &key_weapon7); + * M_BindIntVariable("key_weapon8", &key_weapon8); + * + * M_BindIntVariable("key_prevweapon", &key_prevweapon); + * M_BindIntVariable("key_nextweapon", &key_nextweapon); + * + * M_BindIntVariable("joyb_prevweapon", &joybprevweapon); + * M_BindIntVariable("joyb_nextweapon", &joybnextweapon); + * + * M_BindIntVariable("mouseb_prevweapon", &mousebprevweapon); + * M_BindIntVariable("mouseb_nextweapon", &mousebnextweapon); + */ } void M_BindMapControls(void) { - printf("NRFD-TODO: M_BindMapControls\n"); /* - M_BindIntVariable("key_map_north", &key_map_north); - M_BindIntVariable("key_map_south", &key_map_south); - M_BindIntVariable("key_map_east", &key_map_east); - M_BindIntVariable("key_map_west", &key_map_west); - M_BindIntVariable("key_map_zoomin", &key_map_zoomin); - M_BindIntVariable("key_map_zoomout", &key_map_zoomout); - M_BindIntVariable("key_map_toggle", &key_map_toggle); - M_BindIntVariable("key_map_maxzoom", &key_map_maxzoom); - M_BindIntVariable("key_map_follow", &key_map_follow); - M_BindIntVariable("key_map_grid", &key_map_grid); - M_BindIntVariable("key_map_mark", &key_map_mark); - M_BindIntVariable("key_map_clearmark", &key_map_clearmark); - */ + * // NRFD-TODO + * M_BindIntVariable("key_map_north", &key_map_north); + * M_BindIntVariable("key_map_south", &key_map_south); + * M_BindIntVariable("key_map_east", &key_map_east); + * M_BindIntVariable("key_map_west", &key_map_west); + * M_BindIntVariable("key_map_zoomin", &key_map_zoomin); + * M_BindIntVariable("key_map_zoomout", &key_map_zoomout); + * M_BindIntVariable("key_map_toggle", &key_map_toggle); + * M_BindIntVariable("key_map_maxzoom", &key_map_maxzoom); + * M_BindIntVariable("key_map_follow", &key_map_follow); + * M_BindIntVariable("key_map_grid", &key_map_grid); + * M_BindIntVariable("key_map_mark", &key_map_mark); + * M_BindIntVariable("key_map_clearmark", &key_map_clearmark); + */ } void M_BindMenuControls(void) { - printf("NRFD-TODO: M_BindMenuControls\n"); /* - M_BindIntVariable("key_menu_activate", &key_menu_activate); - M_BindIntVariable("key_menu_up", &key_menu_up); - M_BindIntVariable("key_menu_down", &key_menu_down); - M_BindIntVariable("key_menu_left", &key_menu_left); - M_BindIntVariable("key_menu_right", &key_menu_right); - M_BindIntVariable("key_menu_back", &key_menu_back); - M_BindIntVariable("key_menu_forward", &key_menu_forward); - M_BindIntVariable("key_menu_confirm", &key_menu_confirm); - M_BindIntVariable("key_menu_abort", &key_menu_abort); - - M_BindIntVariable("key_menu_help", &key_menu_help); - M_BindIntVariable("key_menu_save", &key_menu_save); - M_BindIntVariable("key_menu_load", &key_menu_load); - M_BindIntVariable("key_menu_volume", &key_menu_volume); - M_BindIntVariable("key_menu_detail", &key_menu_detail); - M_BindIntVariable("key_menu_qsave", &key_menu_qsave); - M_BindIntVariable("key_menu_endgame", &key_menu_endgame); - M_BindIntVariable("key_menu_messages", &key_menu_messages); - M_BindIntVariable("key_menu_qload", &key_menu_qload); - M_BindIntVariable("key_menu_quit", &key_menu_quit); - M_BindIntVariable("key_menu_gamma", &key_menu_gamma); - - M_BindIntVariable("key_menu_incscreen", &key_menu_incscreen); - M_BindIntVariable("key_menu_decscreen", &key_menu_decscreen); - M_BindIntVariable("key_menu_screenshot",&key_menu_screenshot); - M_BindIntVariable("key_demo_quit", &key_demo_quit); - M_BindIntVariable("key_spy", &key_spy); - */ + * // NRFD-TODO + * M_BindIntVariable("key_menu_activate", &key_menu_activate); + * M_BindIntVariable("key_menu_up", &key_menu_up); + * M_BindIntVariable("key_menu_down", &key_menu_down); + * M_BindIntVariable("key_menu_left", &key_menu_left); + * M_BindIntVariable("key_menu_right", &key_menu_right); + * M_BindIntVariable("key_menu_back", &key_menu_back); + * M_BindIntVariable("key_menu_forward", &key_menu_forward); + * M_BindIntVariable("key_menu_confirm", &key_menu_confirm); + * M_BindIntVariable("key_menu_abort", &key_menu_abort); + * + * M_BindIntVariable("key_menu_help", &key_menu_help); + * M_BindIntVariable("key_menu_save", &key_menu_save); + * M_BindIntVariable("key_menu_load", &key_menu_load); + * M_BindIntVariable("key_menu_volume", &key_menu_volume); + * M_BindIntVariable("key_menu_detail", &key_menu_detail); + * M_BindIntVariable("key_menu_qsave", &key_menu_qsave); + * M_BindIntVariable("key_menu_endgame", &key_menu_endgame); + * M_BindIntVariable("key_menu_messages", &key_menu_messages); + * M_BindIntVariable("key_menu_qload", &key_menu_qload); + * M_BindIntVariable("key_menu_quit", &key_menu_quit); + * M_BindIntVariable("key_menu_gamma", &key_menu_gamma); + * + * M_BindIntVariable("key_menu_incscreen", &key_menu_incscreen); + * M_BindIntVariable("key_menu_decscreen", &key_menu_decscreen); + * M_BindIntVariable("key_menu_screenshot", &key_menu_screenshot); + * M_BindIntVariable("key_demo_quit", &key_demo_quit); + * M_BindIntVariable("key_spy", &key_spy); + */ } void M_BindChatControls(unsigned int num_players) { - printf("NRFD-TODO: M_BindChatControls\n"); /* - char name[32]; // haleyjd: 20 not large enough - Thank you, come again! - unsigned int i; // haleyjd: signedness conflict - - M_BindIntVariable("key_multi_msg", &key_multi_msg); - - for (i=0; i> FRACBITS; + return ((int64_t)a * (int64_t)b) >> FRACBITS; } - - -// -// FixedDiv, C version. -// - +/* FixedDiv, C version. */ fixed_t FixedDiv(fixed_t a, fixed_t b) { if ((abs(a) >> 14) >= abs(b)) { - return (a^b) < 0 ? INT_MIN : INT_MAX; + return (a ^ b) < 0 ? INT_MIN : INT_MAX; } else { - int64_t result; + int64_t result; - result = ((int64_t) a << FRACBITS) / b; + result = ((int64_t)a << FRACBITS) / b; - return (fixed_t) result; + return (fixed_t)result; } } diff --git a/zephyrdoom/src/m_fixed.h b/zephyrdoom/src/m_fixed.h index 7fcf89f..f74d5da 100644 --- a/zephyrdoom/src/m_fixed.h +++ b/zephyrdoom/src/m_fixed.h @@ -1,39 +1,31 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Fixed point arithemtics, implementation. -// - +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Fixed point arithemtics, implementation. + */ #ifndef __M_FIXED__ #define __M_FIXED__ - - - -// -// Fixed point, 32bit as 16.16. -// -#define FRACBITS 16 -#define FRACUNIT (1< #include @@ -42,113 +41,110 @@ #include "n_mem.h" #include "n_fs.h" -// -// Create a directory -// - +/* Create a directory. */ void M_MakeDirectory(char *path) { - printf("NRFD-TODO M_MakeDirectory\n"); + /* NRFD-TODO */ } -// Check if a file exists - +/* Check if a file exists */ boolean M_FileExists(char *filename) { - // if (N_fs_file_exists(filename)) { - // return true; - // } else { - // return false; - // } -} + /* + * // TODO + * if (N_fs_file_exists(filename)) + * { + * return true; + * } + * else + * { + * return false; + * } + */ -// Check if a file exists by probing for common case variation of its filename. -// Returns a newly allocated string that the caller is responsible for freeing. + return false; +} +/* + * Check if a file exists by probing for common case variation of its filename. + * Returns a newly allocated string that the caller is responsible for freeing. + */ char *M_FileCaseExists(char *path) { - // FatFs is case insensitive, so irrelevant for NRF-Doom - if (!M_FileExists(path)) { + /* FatFs is case insensitive, so irrelevant for NRF-Doom */ + if (!M_FileExists(path)) + { return NULL; } return path; } -// -// Determine the length of an open file. -// - +/* Determine the length of an open file. */ long M_FileLength(FILE *handle) { - // return 0; } -// -// M_WriteFile -// - boolean M_WriteFile(char *name, void *source, int length) { - printf("NRFD-TODO M_WriteFile\n"); return false; -/* - FILE *handle; - int count; - - handle = fopen(name, "wb"); - - if (handle == NULL) return false; - count = fwrite(source, 1, length, handle); - fclose(handle); - - if (count < length) - return false; - - return true; - */ + /* + * // NRFD-TODO + * FILE *handle; + * int count; + * + * handle = fopen(name, "wb"); + * + * if (handle == NULL) + * return false; + * + * count = fwrite(source, 1, length, handle); + * fclose(handle); + * + * if (count < length) + * return false; + * + * return true; + */ } - -// -// M_ReadFile -// - int M_ReadFile(char *name, byte **buffer) { - printf("NRFD-TODO M_ReadFile\n"); return 0; - /* - FILE *handle; - int count, length; - byte *buf; - - handle = fopen(name, "rb"); - if (handle == NULL) - I_Error ("Couldn't read file %s", name); - - // find the size of the file by seeking to the end and - // reading the current position - - length = M_FileLength(handle); - - buf = Z_Malloc (length, PU_STATIC, NULL); - count = fread(buf, 1, length, handle); - fclose (handle); - - if (count < length) - I_Error ("Couldn't read file %s", name); + return 0; - *buffer = buf; - return length; - */ + /* + * // NRFD-TODO + * FILE *handle; + * int count, length; + * byte *buf; + * + * handle = fopen(name, "rb"); + * if (handle == NULL) + * I_Error("Couldn't read file %s", name); + * + * // Find the size of the file by seeking to the end an + * // reading the current position. + * length = M_FileLength(handle); + * + * buf = Z_Malloc(length, PU_STATIC, NULL); + * count = fread(buf, 1, length, handle); + * fclose(handle); + * + * if (count < length) + * I_Error("Couldn't read file %s", name); + * + * *buffer = buf; + * return length; + */ } -// Returns the path to a temporary file of the given name, stored -// inside the system temporary directory. -// -// The returned value must be freed with Z_Free after use. - +/* + * Returns the path to a temporary file of the given name, stored + * inside the system temporary directory. + * + * The returned value must be freed with Z_Free after use. + */ char *M_TempFile(char *s) { char *tempdir; @@ -161,10 +157,7 @@ char *M_TempFile(char *s) boolean M_StrToInt(const char *str, int *result) { - return sscanf(str, " 0x%x", result) == 1 - || sscanf(str, " 0X%x", result) == 1 - || sscanf(str, " 0%o", result) == 1 - || sscanf(str, " %d", result) == 1; + return sscanf(str, " 0x%x", result) == 1 || sscanf(str, " 0X%x", result) == 1 || sscanf(str, " 0%o", result) == 1 || sscanf(str, " %d", result) == 1; } void M_ExtractFileBase(char *path, char *dest) @@ -175,19 +168,20 @@ void M_ExtractFileBase(char *path, char *dest) src = path + strlen(path) - 1; - // back up until a \ or the start + /* Back up until a \ or the start. */ while (src != path && *(src - 1) != DIR_SEPARATOR) { - src--; + src--; } filename = src; - // Copy up to eight characters - // Note: Vanilla Doom exits with an error if a filename is specified - // with a base of more than eight characters. To remove the 8.3 - // filename limit, instead we simply truncate the name. - + /* + * Copy up to eight characters. + * Vanilla Doom exits with an error if a filename is specified + * with a base of more than eight characters. To remove the 8.3 + * filename limit, instead we simply truncate the name. + */ length = 0; memset(dest, 0, 8); @@ -200,18 +194,11 @@ void M_ExtractFileBase(char *path, char *dest) break; } - dest[length++] = toupper((int)*src++); + dest[length++] = toupper((int)*src++); } } -//--------------------------------------------------------------------------- -// -// PROC M_ForceUppercase -// -// Change string to uppercase. -// -//--------------------------------------------------------------------------- - +/* Change string to uppercase. */ void M_ForceUppercase(char *text) { char *p; @@ -222,14 +209,7 @@ void M_ForceUppercase(char *text) } } -//--------------------------------------------------------------------------- -// -// PROC M_ForceLowercase -// -// Change string to lowercase. -// -//--------------------------------------------------------------------------- - +/* Change string to lowercase. */ void M_ForceLowercase(char *text) { char *p; @@ -240,12 +220,7 @@ void M_ForceLowercase(char *text) } } -// -// M_StrCaseStr -// -// Case-insensitive version of strstr() -// - +/* Case-insensitive version of strstr(). */ char *M_StrCaseStr(char *haystack, char *needle) { unsigned int haystack_len; @@ -274,18 +249,17 @@ char *M_StrCaseStr(char *haystack, char *needle) return NULL; } -// -// Safe version of strdup() that checks the string was successfully -// allocated. -// - +/* + * Safe version of strdup() that checks the string was successfully + * allocated. + */ char *M_StringDuplicate(const char *orig) { char *result; - //result = strdup(orig); - result = N_malloc(strlen(orig)+1); - if (result) strcpy(result, orig); + result = N_malloc(strlen(orig) + 1); + if (result) + strcpy(result, orig); if (result == NULL) { @@ -296,10 +270,7 @@ char *M_StringDuplicate(const char *orig) return result; } -// -// String replace function. -// - +/* String replace function. */ char *M_StringReplace(const char *haystack, const char *needle, const char *replacement) { @@ -308,8 +279,10 @@ char *M_StringReplace(const char *haystack, const char *needle, size_t needle_len = strlen(needle); size_t result_len, dst_len; - // Iterate through occurrences of 'needle' and calculate the size of - // the new string. + /* + * Iterate through occurrences of 'needle' and calculate the size of + * the new string. + */ result_len = strlen(haystack) + 1; p = haystack; @@ -325,8 +298,7 @@ char *M_StringReplace(const char *haystack, const char *needle, result_len += strlen(replacement) - needle_len; } - // Construct new string. - + /* Construct new string */ result = N_malloc(result_len); if (result == NULL) { @@ -334,7 +306,8 @@ char *M_StringReplace(const char *haystack, const char *needle, return NULL; } - dst = result; dst_len = result_len; + dst = result; + dst_len = result_len; p = haystack; while (*p != '\0') @@ -349,7 +322,8 @@ char *M_StringReplace(const char *haystack, const char *needle, else { *dst = *p; - ++dst; --dst_len; + ++dst; + --dst_len; ++p; } } @@ -359,9 +333,10 @@ char *M_StringReplace(const char *haystack, const char *needle, return result; } -// Safe string copy function that works like OpenBSD's strlcpy(). -// Returns true if the string was not truncated. - +/* + * Safe string copy function that works like OpenBSD's strlcpy(). + * Returns true if the string was not truncated. + */ boolean M_StringCopy(char *dest, const char *src, size_t dest_size) { size_t len; @@ -380,9 +355,10 @@ boolean M_StringCopy(char *dest, const char *src, size_t dest_size) return src[len] == '\0'; } -// Safe string concat function that works like OpenBSD's strlcat(). -// Returns true if string not truncated. - +/* + * Safe string concat function that works like OpenBSD's strlcat(). + * Returns true if string not truncated. + */ boolean M_StringConcat(char *dest, const char *src, size_t dest_size) { size_t offset; @@ -396,25 +372,22 @@ boolean M_StringConcat(char *dest, const char *src, size_t dest_size) return M_StringCopy(dest + offset, src, dest_size - offset); } -// Returns true if 's' begins with the specified prefix. - +/* Returns true if 's' begins with the specified prefix. */ boolean M_StringStartsWith(const char *s, const char *prefix) { - return strlen(s) > strlen(prefix) - && strncmp(s, prefix, strlen(prefix)) == 0; + return strlen(s) > strlen(prefix) && strncmp(s, prefix, strlen(prefix)) == 0; } -// Returns true if 's' ends with the specified suffix. - +/* Returns true if 's' ends with the specified suffix. */ boolean M_StringEndsWith(const char *s, const char *suffix) { - return strlen(s) >= strlen(suffix) - && strcmp(s + strlen(s) - strlen(suffix), suffix) == 0; + return strlen(s) >= strlen(suffix) && strcmp(s + strlen(s) - strlen(suffix), suffix) == 0; } -// Return a newly-malloced string with all the strings given as arguments -// concatenated together. - +/* + * Return a newly-malloced string with all the strings given as arguments + * concatenated together. + */ char *M_StringJoin(const char *s, ...) { char *result; @@ -463,7 +436,7 @@ char *M_StringJoin(const char *s, ...) return result; } -// Safe, portable vsnprintf(). +/* Safe, portable vsnprintf(). */ int M_vsnprintf(char *buf, size_t buf_len, const char *s, va_list args) { int result; @@ -473,13 +446,17 @@ int M_vsnprintf(char *buf, size_t buf_len, const char *s, va_list args) return 0; } - // Windows (and other OSes?) has a vsnprintf() that doesn't always - // append a trailing \0. So we must do it, and write into a buffer - // that is one byte shorter; otherwise this function is unsafe. + /* + * Windows (and other OSes) has a vsnprintf() that doesn't always + * append a trailing \0. So we must do it, and write into a buffer + * that is one byte shorter; otherwise this function is unsafe. + */ result = vsnprintf(buf, buf_len, s, args); - // If truncated, change the final char in the buffer to a \0. - // A negative result indicates a truncated buffer on Windows. + /* + * If truncated, change the final char in the buffer to a \0. + * A negative result indicates a truncated buffer on Windows. + */ if (result < 0 || result >= buf_len) { buf[buf_len - 1] = '\0'; @@ -489,7 +466,7 @@ int M_vsnprintf(char *buf, size_t buf_len, const char *s, va_list args) return result; } -// Safe, portable snprintf(). +/* Safe, portable snprintf(). */ int M_snprintf(char *buf, size_t buf_len, const char *s, ...) { va_list args; diff --git a/zephyrdoom/src/m_misc.h b/zephyrdoom/src/m_misc.h index 92f38a0..3be2f0d 100644 --- a/zephyrdoom/src/m_misc.h +++ b/zephyrdoom/src/m_misc.h @@ -1,21 +1,20 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Miscellaneous. -// - +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Miscellaneous. + */ #ifndef __M_MISC__ #define __M_MISC__ @@ -49,4 +48,4 @@ int M_vsnprintf(char *buf, size_t buf_len, const char *s, va_list args); int M_snprintf(char *buf, size_t buf_len, const char *s, ...); char *M_OEMToUTF8(const char *ansi); -#endif +#endif /* __M_MISC__ */ diff --git a/zephyrdoom/src/main.c b/zephyrdoom/src/main.c index d53e6f3..09a6018 100644 --- a/zephyrdoom/src/main.c +++ b/zephyrdoom/src/main.c @@ -32,22 +32,24 @@ LOG_MODULE_REGISTER(doom_main, CONFIG_DOOM_MAIN_LOG_LEVEL); * See the sample documentation for information on how to fix this. */ static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios); -#define GPIO0 ((NRF_GPIO_Type*)0x50842500UL) -#define GPIO1 ((NRF_GPIO_Type*)0x50842800UL) +#define GPIO0 ((NRF_GPIO_Type *)0x50842500UL) +#define GPIO1 ((NRF_GPIO_Type *)0x50842800UL) #define SD_ROOT_PATH "/SD:/" -/* Maximum length for path support by Windows file system */ + +/* Maximum length for path support by Windows file system. */ #define PATH_MAX_LEN 260 #define K_SEM_OPER_TIMEOUT_MS 500 K_SEM_DEFINE(m_sem_sd_oper_ongoing, 1, 1); -void clock_initialization() { +void clock_initialization() +{ nrfx_clock_hfclk_start(); nrf_clock_hfclk_div_set(NRF_CLOCK_S, NRF_CLOCK_HFCLK_DIV_1); nrfx_clock_divider_set(NRF_CLOCK_DOMAIN_HFCLK192M, NRF_CLOCK_HFCLK_DIV_1); } -static const char* sd_root_path = "/SD:"; +static const char *sd_root_path = "/SD:"; static bool sd_init_success; static FATFS fat_fs; @@ -57,21 +59,24 @@ static struct fs_mount_t mnt_pt = { .fs_data = &fat_fs, }; -int sd_card_init(void) { +int sd_card_init(void) +{ int ret; - static const char* sd_dev = "SD"; + static const char *sd_dev = "SD"; uint64_t sd_card_size_bytes; uint32_t sector_count; size_t sector_size; ret = disk_access_init(sd_dev); - if (ret) { + if (ret) + { LOG_DBG("SD card init failed, please check if SD card inserted"); return -ENODEV; } ret = disk_access_ioctl(sd_dev, DISK_IOCTL_GET_SECTOR_COUNT, §or_count); - if (ret) { + if (ret) + { LOG_ERR("Unable to get sector count"); return ret; } @@ -79,7 +84,8 @@ int sd_card_init(void) { LOG_DBG("Sector count: %d", sector_count); ret = disk_access_ioctl(sd_dev, DISK_IOCTL_GET_SECTOR_SIZE, §or_size); - if (ret) { + if (ret) + { LOG_ERR("Unable to get sector size"); return ret; } @@ -93,7 +99,8 @@ int sd_card_init(void) { mnt_pt.mnt_point = sd_root_path; ret = fs_mount(&mnt_pt); - if (ret) { + if (ret) + { LOG_ERR("Mnt. disk failed, could be format issue. should be FAT/exFAT"); return ret; } @@ -103,36 +110,44 @@ int sd_card_init(void) { return 0; } -int sd_card_list_files(char const* const path, char* buf, size_t* buf_size) { +int sd_card_list_files(char const *const path, char *buf, size_t *buf_size) +{ int ret; struct fs_dir_t dirp; static struct fs_dirent entry; char abs_path_name[PATH_MAX_LEN + 1] = SD_ROOT_PATH; size_t used_buf_size = 0; - if (k_sem_count_get(&m_sem_sd_oper_ongoing) <= 0) { + if (k_sem_count_get(&m_sem_sd_oper_ongoing) <= 0) + { LOG_ERR("SD operation ongoing"); return -EPERM; } k_sem_take(&m_sem_sd_oper_ongoing, K_MSEC(K_SEM_OPER_TIMEOUT_MS)); - if (!sd_init_success) { + if (!sd_init_success) + { k_sem_give(&m_sem_sd_oper_ongoing); return -ENODEV; } fs_dir_t_init(&dirp); - if (path == NULL) { + if (path == NULL) + { ret = fs_opendir(&dirp, sd_root_path); - if (ret) { + if (ret) + { LOG_ERR("Open SD card root dir failed"); k_sem_give(&m_sem_sd_oper_ongoing); return ret; } - } else { - if (strlen(path) > CONFIG_FS_FATFS_MAX_LFN) { + } + else + { + if (strlen(path) > CONFIG_FS_FATFS_MAX_LFN) + { LOG_ERR("Path is too long"); k_sem_give(&m_sem_sd_oper_ongoing); return -1; @@ -141,31 +156,37 @@ int sd_card_list_files(char const* const path, char* buf, size_t* buf_size) { strcat(abs_path_name, path); ret = fs_opendir(&dirp, abs_path_name); - if (ret) { + if (ret) + { LOG_ERR("Open assigned path failed"); k_sem_give(&m_sem_sd_oper_ongoing); return ret; } } - while (1) { + while (1) + { ret = fs_readdir(&dirp, &entry); - if (ret) { + if (ret) + { k_sem_give(&m_sem_sd_oper_ongoing); return ret; } - if (entry.name[0] == 0) { + if (entry.name[0] == 0) + { break; } - if (buf != NULL) { + if (buf != NULL) + { size_t remaining_buf_size = *buf_size - used_buf_size; ssize_t len = snprintk( &buf[used_buf_size], remaining_buf_size, "[%s]\t%s\n", entry.type == FS_DIR_ENTRY_DIR ? "DIR " : "FILE", entry.name); - if (len >= remaining_buf_size) { + if (len >= remaining_buf_size) + { LOG_ERR("Failed to append to buffer, error: %d", len); k_sem_give(&m_sem_sd_oper_ongoing); return -EINVAL; @@ -179,7 +200,8 @@ int sd_card_list_files(char const* const path, char* buf, size_t* buf_size) { } ret = fs_closedir(&dirp); - if (ret) { + if (ret) + { LOG_ERR("Close SD card root dir failed"); k_sem_give(&m_sem_sd_oper_ongoing); return ret; @@ -190,7 +212,8 @@ int sd_card_list_files(char const* const path, char* buf, size_t* buf_size) { return 0; } -int main(void) { +int main(void) +{ LOG_INF("BOARD STARTING %s", CONFIG_BOARD); cpu_load_init(); @@ -207,32 +230,38 @@ int main(void) { M_ArgvInit(); int err = bluetooth_control_init(); - if (err) { + if (err) + { LOG_ERR("Bluetooth control initialization failed."); return 0; } D_DoomMain(); - while (true) { + while (true) + { __WFE(); } int ret; - if (!gpio_is_ready_dt(&led)) { + if (!gpio_is_ready_dt(&led)) + { return 0; } ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE); - if (ret < 0) { + if (ret < 0) + { return 0; } - while (1) { + while (1) + { sd_card_list_files(NULL, NULL, NULL); ret = gpio_pin_toggle_dt(&led); - if (ret < 0) { + if (ret < 0) + { return 0; } k_msleep(SLEEP_TIME_MS); diff --git a/zephyrdoom/src/memio.c b/zephyrdoom/src/memio.c index 586c1b5..53aa05f 100644 --- a/zephyrdoom/src/memio.c +++ b/zephyrdoom/src/memio.c @@ -1,20 +1,20 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// Emulates the IO functions in C stdio.h reading and writing to -// memory. -// +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Emulates the IO functions in C stdio.h reading and writing to + * memory. + */ #include #include @@ -24,12 +24,14 @@ #include "z_zone.h" -typedef enum { +typedef enum +{ MODE_READ, MODE_WRITE, } memfile_mode_t; -struct _MEMFILE { +struct _MEMFILE +{ unsigned char *buf; size_t buflen; size_t alloced; @@ -37,15 +39,14 @@ struct _MEMFILE { memfile_mode_t mode; }; -// Open a memory area for reading - +/* Open a memory area for reading. */ MEMFILE *mem_fopen_read(void *buf, size_t buflen) { MEMFILE *file; file = Z_Malloc(sizeof(MEMFILE), PU_STATIC, 0); - file->buf = (unsigned char *) buf; + file->buf = (unsigned char *)buf; file->buflen = buflen; file->position = 0; file->mode = MODE_READ; @@ -53,8 +54,7 @@ MEMFILE *mem_fopen_read(void *buf, size_t buflen) return file; } -// Read bytes - +/* Read bytes. */ size_t mem_fread(void *buf, size_t size, size_t nmemb, MEMFILE *stream) { size_t items; @@ -65,8 +65,7 @@ size_t mem_fread(void *buf, size_t size, size_t nmemb, MEMFILE *stream) return -1; } - // Trying to read more bytes than we have left? - + /* Trying to read more bytes than we have left */ items = nmemb; if (items * size > stream->buflen - stream->position) @@ -74,19 +73,16 @@ size_t mem_fread(void *buf, size_t size, size_t nmemb, MEMFILE *stream) items = (stream->buflen - stream->position) / size; } - // Copy bytes to buffer - + /* Copy bytes to buffer */ memcpy(buf, stream->buf + stream->position, items * size); - // Update position - + /* Update position */ stream->position += items * size; return items; } -// Open a memory area for writing - +/* Open a memory area for writing. */ MEMFILE *mem_fopen_write(void) { MEMFILE *file; @@ -102,8 +98,7 @@ MEMFILE *mem_fopen_write(void) return file; } -// Write bytes to stream - +/* Write bytes to stream. */ size_t mem_fwrite(const void *ptr, size_t size, size_t nmemb, MEMFILE *stream) { size_t bytes; @@ -113,9 +108,10 @@ size_t mem_fwrite(const void *ptr, size_t size, size_t nmemb, MEMFILE *stream) return -1; } - // More bytes than can fit in the buffer? - // If so, reallocate bigger. - + /* + * More bytes than can fit in the buffer. + * If so, reallocate bigger. + */ bytes = size * nmemb; while (bytes > stream->alloced - stream->position) @@ -129,8 +125,7 @@ size_t mem_fwrite(const void *ptr, size_t size, size_t nmemb, MEMFILE *stream) stream->alloced *= 2; } - // Copy into buffer - + /* Copy into buffer */ memcpy(stream->buf + stream->position, ptr, bytes); stream->position += bytes; @@ -167,19 +162,19 @@ int mem_fseek(MEMFILE *stream, signed long position, mem_rel_t whence) switch (whence) { - case MEM_SEEK_SET: - newpos = (int) position; - break; - - case MEM_SEEK_CUR: - newpos = (int) (stream->position + position); - break; - - case MEM_SEEK_END: - newpos = (int) (stream->buflen + position); - break; - default: - return -1; + case MEM_SEEK_SET: + newpos = (int)position; + break; + + case MEM_SEEK_CUR: + newpos = (int)(stream->position + position); + break; + + case MEM_SEEK_END: + newpos = (int)(stream->buflen + position); + break; + default: + return -1; } if (newpos < stream->buflen) diff --git a/zephyrdoom/src/memio.h b/zephyrdoom/src/memio.h index 00fd159..ec53f5b 100644 --- a/zephyrdoom/src/memio.h +++ b/zephyrdoom/src/memio.h @@ -1,17 +1,17 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ #ifndef MEMIO_H #define MEMIO_H @@ -34,4 +34,4 @@ void mem_fclose(MEMFILE *stream); long mem_ftell(MEMFILE *stream); int mem_fseek(MEMFILE *stream, signed long offset, mem_rel_t whence); -#endif /* #ifndef MEMIO_H */ +#endif /* MEMIO_H */ diff --git a/zephyrdoom/src/n_buttons.c b/zephyrdoom/src/n_buttons.c index 3914fe4..60f4b0f 100644 --- a/zephyrdoom/src/n_buttons.c +++ b/zephyrdoom/src/n_buttons.c @@ -29,7 +29,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ - #include #include "nrf.h" @@ -60,14 +59,15 @@ void N_ButtonsInit() int N_ButtonStateRaw(int id) { - switch(id) { - case 0: + switch (id) + { + case 0: return !nrf_gpio_pin_read(BUTTON_PIN_1); - case 1: + case 1: return !nrf_gpio_pin_read(BUTTON_PIN_2); - case 2: + case 2: return !nrf_gpio_pin_read(BUTTON_PIN_3); - case 3: + case 3: return !nrf_gpio_pin_read(BUTTON_PIN_4); } I_Error("N_ButtonStateRaw: Invalid button\n"); @@ -81,21 +81,25 @@ void N_ReadButtons() boolean button_state[4]; boolean button_posedge[4]; boolean button_negedge[4]; - for (int i=0; i<4; i++) { + for (int i = 0; i < 4; i++) + { button_state[i] = N_ButtonStateRaw(i); button_posedge[i] = button_state[i] && !button_prev_state[i]; button_negedge[i] = !button_state[i] && button_prev_state[i]; } - for (int i=0; i<4; i++) { - if (button_posedge[i]) { + for (int i = 0; i < 4; i++) + { + if (button_posedge[i]) + { event.type = ev_keydown; event.data1 = button_map[i]; event.data2 = 0; event.data3 = 0; D_PostEvent(&event); } - else if (button_negedge[i]) { + else if (button_negedge[i]) + { event.type = ev_keyup; event.data1 = button_map[i]; event.data2 = 0; @@ -104,7 +108,8 @@ void N_ReadButtons() } } - for (int i=0; i<4; i++) { + for (int i = 0; i < 4; i++) + { button_prev_state[i] = button_state[i]; } } diff --git a/zephyrdoom/src/n_buttons.h b/zephyrdoom/src/n_buttons.h index 068a29c..eaac3d5 100644 --- a/zephyrdoom/src/n_buttons.h +++ b/zephyrdoom/src/n_buttons.h @@ -29,7 +29,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ - void N_ButtonsInit(); void N_ReadButtons(); int N_ButtonState(int num); diff --git a/zephyrdoom/src/n_display.c b/zephyrdoom/src/n_display.c index a979a3f..596e240 100644 --- a/zephyrdoom/src/n_display.c +++ b/zephyrdoom/src/n_display.c @@ -41,74 +41,88 @@ #define BUF_MAXCNT 8 -volatile int display_spi_tip; // transfer-in-progress +/* Transfer in progress. */ +volatile int display_spi_tip; volatile uint8_t display_spi_txd_buf[BUF_MAXCNT]; volatile uint8_t display_spi_rxd_buf[BUF_MAXCNT]; -void N_display_gpiote_end_to_cs() { +void N_display_gpiote_end_to_cs() +{ const int TASK_MODE = 3; const int LO_TO_HI = 1; const int OUT_INIT_LOW = 0; - // TODO: Confgigurable GPIOTE/DPPI channel + /* + * TODO + * Configurable GPIOTE/DPPI channel. + */ NRF_DISPLAY_GPIOTE->CONFIG[0] = (TASK_MODE << 0) | (DISPLAY_PIN_CS_N << 8) | (LO_TO_HI << 16) | (OUT_INIT_LOW << 20); NRF_DISPLAY_GPIOTE->SUBSCRIBE_OUT[0] = 0 | GPIOTE_SUBSCRIBE_OUT_EN_Msk; NRF_DISPLAY_SPIM->PUBLISH_END = 0 | SPIM_PUBLISH_END_EN_Msk; NRF_DPPIC_S->CHENSET = 1; } -void N_display_gpiote_clear() { +void N_display_gpiote_clear() +{ NRF_DISPLAY_GPIOTE->CONFIG[0] = 0; } -void N_display_spi_init() { - - // Set up GPIO pins +void N_display_spi_init() +{ + /* Set up GPIO pins */ nrf_gpio_cfg(DISPLAY_PIN_SCK, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE); - nrf_gpio_cfg(DISPLAY_PIN_MOSI,NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE); - nrf_gpio_cfg(DISPLAY_PIN_MISO,NRF_GPIO_PIN_DIR_INPUT , NRF_GPIO_PIN_INPUT_CONNECT , NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_S0S1, NRF_GPIO_PIN_NOSENSE); - nrf_gpio_cfg(DISPLAY_PIN_CS_N,NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE); - nrf_gpio_cfg(DISPLAY_PIN_PD_N,NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_S0S1, NRF_GPIO_PIN_NOSENSE); + nrf_gpio_cfg(DISPLAY_PIN_MOSI, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE); + nrf_gpio_cfg(DISPLAY_PIN_MISO, NRF_GPIO_PIN_DIR_INPUT, NRF_GPIO_PIN_INPUT_CONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_S0S1, NRF_GPIO_PIN_NOSENSE); + nrf_gpio_cfg(DISPLAY_PIN_CS_N, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE); + nrf_gpio_cfg(DISPLAY_PIN_PD_N, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_S0S1, NRF_GPIO_PIN_NOSENSE); nrf_gpio_pin_set(DISPLAY_PIN_CS_N); nrf_gpio_pin_set(DISPLAY_PIN_PD_N); - // Configure SPI Master - NRF_DISPLAY_SPIM->PSEL.SCK = DISPLAY_PIN_SCK; + /* Configure SPI Master */ + NRF_DISPLAY_SPIM->PSEL.SCK = DISPLAY_PIN_SCK; NRF_DISPLAY_SPIM->PSEL.MOSI = DISPLAY_PIN_MOSI; NRF_DISPLAY_SPIM->PSEL.MISO = DISPLAY_PIN_MISO; - // SCK pol SCK phase Bit Order (Msb First) + + /* SCK pol | SCK phase | Bit Order (Msb First) */ NRF_DISPLAY_SPIM->CONFIG = (0 << 2) | (0 << 1) | (0 << 0); - NRF_DISPLAY_SPIM->FREQUENCY = 0x01400000; // 0x14 = 32Mbps 0x0A = 16Mbps, 0x20.. = 2mbps, 0x08.. = 500kbps - NRF_DISPLAY_SPIM->ORC = 0; // Over-Read Character + + /* 0x14 = 32Mbps, 0x0A = 16Mbps, 0x20.. = 2Mbps, 0x08.. = 500Kbps */ + NRF_DISPLAY_SPIM->FREQUENCY = 0x01400000; + + /* Over-Read Character */ + NRF_DISPLAY_SPIM->ORC = 0; NRF_DISPLAY_SPIM->ENABLE = 7; NRF_DISPLAY_SPIM->TXD.PTR = 0xFFFFFFFF; display_spi_tip = 0; - } -void N_display_power_reset() { +void N_display_power_reset() +{ nrf_gpio_pin_clear(DISPLAY_PIN_PD_N); k_msleep(50); nrf_gpio_pin_set(DISPLAY_PIN_PD_N); k_msleep(50); } -void N_display_spi_setup(int txdMaxCnt, volatile uint8_t * txdPtr, - int rxdMaxCnt, volatile uint8_t * rxdPtr) { - +void N_display_spi_setup(int txdMaxCnt, volatile uint8_t *txdPtr, + int rxdMaxCnt, volatile uint8_t *rxdPtr) +{ NRF_DISPLAY_SPIM->TXD.MAXCNT = txdMaxCnt; NRF_DISPLAY_SPIM->TXD.PTR = (uint32_t)txdPtr; NRF_DISPLAY_SPIM->RXD.MAXCNT = rxdMaxCnt; NRF_DISPLAY_SPIM->RXD.PTR = (uint32_t)rxdPtr; } -void N_display_spi_transfer_finish() { - if (display_spi_tip) { - while (NRF_DISPLAY_SPIM->EVENTS_END == 0) { +void N_display_spi_transfer_finish() +{ + if (display_spi_tip) + { + while (NRF_DISPLAY_SPIM->EVENTS_END == 0) + { } NRF_DISPLAY_SPIM->EVENTS_END = 0; display_spi_tip = 0; @@ -116,20 +130,24 @@ void N_display_spi_transfer_finish() { } } -void N_display_spi_transfer_start() { +void N_display_spi_transfer_start() +{ N_display_spi_transfer_finish(); nrf_gpio_pin_clear(DISPLAY_PIN_CS_N); } -void N_display_spi_transfer_data() { +void N_display_spi_transfer_data() +{ NRF_DISPLAY_SPIM->EVENTS_END = 0; NRF_DISPLAY_SPIM->TASKS_START = 1; - while (NRF_DISPLAY_SPIM->EVENTS_END == 0) { + while (NRF_DISPLAY_SPIM->EVENTS_END == 0) + { } NRF_DISPLAY_SPIM->EVENTS_END = 0; } -void N_display_spi_transfer_data_end() { +void N_display_spi_transfer_data_end() +{ NRF_DISPLAY_SPIM->EVENTS_END = 0; N_display_gpiote_end_to_cs(); @@ -138,17 +156,20 @@ void N_display_spi_transfer_data_end() { display_spi_tip = 1; } -void N_display_spi_transfer_end() { +void N_display_spi_transfer_end() +{ nrf_gpio_pin_set(DISPLAY_PIN_CS_N); } -void N_display_spi_transfer() { +void N_display_spi_transfer() +{ N_display_spi_transfer_start(); N_display_spi_transfer_data(); N_display_spi_transfer_end(); } -void N_display_spi_cmd(uint8_t b1, uint8_t b2) { +void N_display_spi_cmd(uint8_t b1, uint8_t b2) +{ display_spi_txd_buf[0] = b1; display_spi_txd_buf[1] = b2; display_spi_txd_buf[2] = 0x00; @@ -157,43 +178,42 @@ void N_display_spi_cmd(uint8_t b1, uint8_t b2) { N_display_spi_transfer(); } -void N_display_spi_wr8(uint32_t addr, uint8_t data) { - uint8_t *addrBytes = (uint8_t*)&addr; +void N_display_spi_wr8(uint32_t addr, uint8_t data) +{ + uint8_t *addrBytes = (uint8_t *)&addr; - // Assuming MCU is Little-Endian + /* Assuming MCU is Little-Endian */ display_spi_txd_buf[0] = addrBytes[2] | 0x80; display_spi_txd_buf[1] = addrBytes[1]; display_spi_txd_buf[2] = addrBytes[0]; display_spi_txd_buf[3] = data; - //printf("Wr8 %.2X %.2X %.2X %.2X\n", display_spi_txd_buf[0], display_spi_txd_buf[1], display_spi_txd_buf[2], display_spi_txd_buf[3]); - N_display_spi_setup(4, display_spi_txd_buf, 0, NULL); N_display_spi_transfer(); } -void N_display_spi_wr16(uint32_t addr, uint16_t data) { - uint8_t *addrBytes = (uint8_t*)&addr; - uint8_t *dataBytes = (uint8_t*)&data; +void N_display_spi_wr16(uint32_t addr, uint16_t data) +{ + uint8_t *addrBytes = (uint8_t *)&addr; + uint8_t *dataBytes = (uint8_t *)&data; - // Assuming MCU is Little-Endian + /* Assuming MCU is Little-Endian */ display_spi_txd_buf[0] = addrBytes[2] | 0x80; display_spi_txd_buf[1] = addrBytes[1]; display_spi_txd_buf[2] = addrBytes[0]; display_spi_txd_buf[3] = dataBytes[0]; display_spi_txd_buf[4] = dataBytes[1]; - //printf("Wr16 %.2X %.2X %.2X %.2X %.2X\n", display_spi_txd_buf[0], display_spi_txd_buf[1], display_spi_txd_buf[2], display_spi_txd_buf[3], display_spi_txd_buf[4]); - N_display_spi_setup(5, display_spi_txd_buf, 0, NULL); N_display_spi_transfer(); } -void N_display_spi_wr32(uint32_t addr, uint32_t data) { - uint8_t *addrBytes = (uint8_t*)&addr; - uint8_t *dataBytes = (uint8_t*)&data; +void N_display_spi_wr32(uint32_t addr, uint32_t data) +{ + uint8_t *addrBytes = (uint8_t *)&addr; + uint8_t *dataBytes = (uint8_t *)&data; - // Assuming MCU is Little-Endian + /* Assuming MCU is Little-Endian */ display_spi_txd_buf[0] = addrBytes[2] | 0x80; display_spi_txd_buf[1] = addrBytes[1]; display_spi_txd_buf[2] = addrBytes[0]; @@ -207,10 +227,11 @@ void N_display_spi_wr32(uint32_t addr, uint32_t data) { N_display_spi_transfer(); } -void N_display_spi_wr(uint32_t addr, int dataSize, uint8_t *data) { - uint8_t *addrBytes = (uint8_t*)&addr; +void N_display_spi_wr(uint32_t addr, int dataSize, uint8_t *data) +{ + uint8_t *addrBytes = (uint8_t *)&addr; - // Assuming MCU is Little-Endian + /* Assuming MCU is Little-Endian */ display_spi_txd_buf[0] = addrBytes[2] | 0x80; display_spi_txd_buf[1] = addrBytes[1]; display_spi_txd_buf[2] = addrBytes[0]; @@ -220,69 +241,71 @@ void N_display_spi_wr(uint32_t addr, int dataSize, uint8_t *data) { N_display_spi_setup(3, display_spi_txd_buf, 0, NULL); N_display_spi_transfer_data(); - volatile uint8_t *dataPtr = (volatile uint8_t*)data; + volatile uint8_t *dataPtr = (volatile uint8_t *)data; N_display_spi_setup(dataSize, dataPtr, 0, NULL); N_display_spi_transfer_data_end(); - // N_display_spi_transfer_end(); + /* N_display_spi_transfer_end(); */ } -// void N_display_spi_transfer_data_async() { -// NRF_DISPLAY_SPIM->EVENTS_END = 0; -// NRF_DISPLAY_SPIM->TASKS_START = 1; -// while (NRF_DISPLAY_SPIM->EVENTS_END == 0) { -// } -// } - -// void N_display_spi_wr_async(uint32_t addr, int dataSize, uint8_t *data) { -// uint8_t *addrBytes = (uint8_t*)&addr; - -// // Assuming MCU is Little-Endian -// display_spi_txd_buf[0] = addrBytes[2] | 0x80; -// display_spi_txd_buf[1] = addrBytes[1]; -// display_spi_txd_buf[2] = addrBytes[0]; - -// N_display_spi_transfer_start(); - -// N_display_spi_setup(3, display_spi_txd_buf, 0, NULL); -// N_display_spi_transfer_data(); - -// volatile uint8_t *dataPtr = (volatile uint8_t*)data; -// N_display_spi_setup(dataSize, dataPtr, 0, NULL); -// N_display_spi_transfer_data(); - -// N_display_spi_transfer_end(); -// } +/* + * // TODO + * void N_display_spi_transfer_data_async() + * { + * NRF_DISPLAY_SPIM->EVENTS_END = 0; + * NRF_DISPLAY_SPIM->TASKS_START = 1; + * while (NRF_DISPLAY_SPIM->EVENTS_END == 0) + * { + * } + * } + * + * void N_display_spi_wr_async(uint32_t addr, int dataSize, uint8_t *data) + * { + * uint8_t *addrBytes = (uint8_t *)&addr; + * + * // Assuming MCU is Little-Endian + * display_spi_txd_buf[0] = addrBytes[2] | 0x80; + * display_spi_txd_buf[1] = addrBytes[1]; + * display_spi_txd_buf[2] = addrBytes[0]; + * + * N_display_spi_transfer_start(); + * + * N_display_spi_setup(3, display_spi_txd_buf, 0, NULL); + * N_display_spi_transfer_data(); + * + * volatile uint8_t *dataPtr = (volatile uint8_t *)data; + * N_display_spi_setup(dataSize, dataPtr, 0, NULL); + * N_display_spi_transfer_data(); + * + * N_display_spi_transfer_end(); + * } + */ -uint8_t N_display_spi_rd8(uint32_t addr) { - uint8_t *addrBytes = (uint8_t*)&addr; +uint8_t N_display_spi_rd8(uint32_t addr) +{ + uint8_t *addrBytes = (uint8_t *)&addr; - // Assuming MCU is Little-Endian + /* Assuming MCU is Little-Endian */ display_spi_txd_buf[0] = addrBytes[2]; display_spi_txd_buf[1] = addrBytes[1]; display_spi_txd_buf[2] = addrBytes[0]; display_spi_txd_buf[3] = 0x00; - // printf("Rd %.2X %.2X %.2X %.2X\n", display_spi_txd_buf[0], display_spi_txd_buf[1], display_spi_txd_buf[2], display_spi_txd_buf[3]); - N_display_spi_setup(4, display_spi_txd_buf, 5, display_spi_rxd_buf); N_display_spi_transfer(); - return display_spi_rxd_buf[4]; } -/// -------- - uint32_t ram_free_loc = FT810_RAM_G; -void N_display_wakeup() { +void N_display_wakeup() +{ N_display_spi_cmd(0x00, 0x00); } void N_display_init() { - N_display_spi_init(); N_display_power_reset(); @@ -298,50 +321,51 @@ void N_display_init() printf("N_display_init - Display ID: %.2X\n", N_display_spi_rd8(FT810_REG_ID)); printf("N_display_init - CPU Reset: %.2X\n", N_display_spi_rd8(FT810_REG_CPURESET)); - N_display_spi_wr16(FT810_REG_HSIZE, 800 ); // Active width of LCD display - N_display_spi_wr16(FT810_REG_VSIZE, 480 ); // Active height of LCD display - N_display_spi_wr16(FT810_REG_HCYCLE, 928 ); // Total number of clocks per line - N_display_spi_wr16(FT810_REG_HOFFSET, 88 ); // Start of active line - N_display_spi_wr16(FT810_REG_HSYNC0, 0 ); // Start of horizontal sync pulse - N_display_spi_wr16(FT810_REG_HSYNC1, 48 ); // End of horizontal sync pulse - N_display_spi_wr16(FT810_REG_VCYCLE, 525 ); // Total number of lines per screen - N_display_spi_wr16(FT810_REG_VOFFSET, 32 ); // Start of active screen - N_display_spi_wr16(FT810_REG_VSYNC0, 0 ); // Start of vertical sync pulse - N_display_spi_wr16(FT810_REG_VSYNC1, 3 ); // End of vertical sync pulse - N_display_spi_wr8 (FT810_REG_SWIZZLE, 0 ); // Define RGB output pins - N_display_spi_wr8 (FT810_REG_PCLK_POL, 1 ); // Define active edge of PCLK + N_display_spi_wr16(FT810_REG_HSIZE, 800); /* Active width of LCD display */ + N_display_spi_wr16(FT810_REG_VSIZE, 480); /* Active height of LCD display */ + N_display_spi_wr16(FT810_REG_HCYCLE, 928); /* Total number of clocks per line */ + N_display_spi_wr16(FT810_REG_HOFFSET, 88); /* Start of active line */ + N_display_spi_wr16(FT810_REG_HSYNC0, 0); /* Start of horizontal sync pulse */ + N_display_spi_wr16(FT810_REG_HSYNC1, 48); /* End of horizontal sync pulse */ + N_display_spi_wr16(FT810_REG_VCYCLE, 525); /* Total number of lines per screen */ + N_display_spi_wr16(FT810_REG_VOFFSET, 32); /* Start of active screen */ + N_display_spi_wr16(FT810_REG_VSYNC0, 0); /* Start of vertical sync pulse */ + N_display_spi_wr16(FT810_REG_VSYNC1, 3); /* End of vertical sync pulse */ + N_display_spi_wr8(FT810_REG_SWIZZLE, 0); /* Define RGB output pins */ + N_display_spi_wr8(FT810_REG_PCLK_POL, 1); /* Define active edge of PCLK */ uint8_t disGpio = N_display_spi_rd8(FT810_REG_GPIO); N_display_spi_wr8(FT810_REG_GPIO, disGpio | 0x80); - N_display_spi_wr8 (FT810_REG_PWM_DUTY, 0xFF ); // Backlight PWM duty cycle - - N_display_spi_wr8 (FT810_REG_PCLK, 2 ); // Pixel Clock - - N_display_spi_wr8 (FT810_REG_ROTATE, 1 ); // inverted (up-down) - + N_display_spi_wr8(FT810_REG_PWM_DUTY, 0xFF); /* Backlight PWM duty cycle */ + N_display_spi_wr8(FT810_REG_PCLK, 2); /* Pixel Clock */ + N_display_spi_wr8(FT810_REG_ROTATE, 1); /* inverted (up-down) */ } uint32_t N_display_ram_alloc(size_t size) { - uint32_t result = ram_free_loc; - ram_free_loc += size; - return result; + uint32_t result = ram_free_loc; + ram_free_loc += size; + return result; } -void N_display_dlswap_frame() { +void N_display_dlswap_frame() +{ N_display_spi_wr32(FT810_REG_DLSWAP, FT810_DLSWAP_FRAME); } uint32_t display_dli = 0; -void dl_start() { +void dl_start() +{ display_dli = FT810_RAM_DL; } -void dl(uint32_t cmd) { +void dl(uint32_t cmd) +{ N_display_spi_wr32(display_dli, cmd); display_dli += 4; } -void dl_end() { +void dl_end() +{ N_display_spi_wr32(display_dli, FT810_DISPLAY()); } diff --git a/zephyrdoom/src/n_display.h b/zephyrdoom/src/n_display.h index 5d8f49d..3dd5de8 100644 --- a/zephyrdoom/src/n_display.h +++ b/zephyrdoom/src/n_display.h @@ -29,13 +29,11 @@ * POSSIBILITY OF SUCH DAMAGE. */ - - #include -#define DISPLAY_PALETTE_SIZE (256*4) +#define DISPLAY_PALETTE_SIZE (256 * 4) -// SPI +/* SPI */ void N_display_spi_init(); void N_display_power_reset(); void N_display_spi_transfer_finish(); diff --git a/zephyrdoom/src/n_fs.c b/zephyrdoom/src/n_fs.c index 7295c4c..b154f47 100644 --- a/zephyrdoom/src/n_fs.c +++ b/zephyrdoom/src/n_fs.c @@ -1,3 +1,4 @@ +// // TODO // // /* // // * Copyright (c) 2019 - 2020, Nordic Semiconductor ASA // // * All rights reserved. @@ -45,18 +46,17 @@ // #include "n_mem.h" -// void I_Error (char *error, ...); +// void I_Error(char *error, ...); // /** // * @brief SDC block device definition -// * */ +// */ // NRF_BLOCK_DEV_SDC_DEFINE( -// m_block_dev_sdc, -// NRF_BLOCK_DEV_SDC_CONFIG(SDC_SECTOR_SIZE, -// APP_SDCARD_CONFIG(SDC_MOSI_PIN, SDC_MISO_PIN, SDC_SCK_PIN, -// SDC_CS_PIN)), -// NFR_BLOCK_DEV_INFO_CONFIG("Nordic", "SDC", "1.00") -// ); +// m_block_dev_sdc, +// NRF_BLOCK_DEV_SDC_CONFIG(SDC_SECTOR_SIZE, +// APP_SDCARD_CONFIG(SDC_MOSI_PIN, SDC_MISO_PIN, SDC_SCK_PIN, +// SDC_CS_PIN)), +// NFR_BLOCK_DEV_INFO_CONFIG("Nordic", "SDC", "1.00")); // FATFS *fs = NULL; @@ -72,12 +72,12 @@ // FRESULT ff_result; // DSTATUS disk_state = STA_NOINIT; -// // Initialize FATFS disk I/O interface by providing the block device. +// // Initialize FATFS disk I/O interface by providing the block device // static diskio_blkdev_t drives[] = -// { +// { // DISKIO_BLOCKDEV_CONFIG(NRF_BLOCKDEV_BASE_ADDR(m_block_dev_sdc, -// block_dev), NULL) -// }; +// block_dev), +// NULL)}; // diskio_blockdev_register(drives, ARRAY_SIZE(drives)); @@ -93,10 +93,10 @@ // } // uint32_t blocks_per_mb = (1024uL * 1024uL) / -// m_block_dev_sdc.block_dev.p_ops->geometry(&m_block_dev_sdc.block_dev)->blk_size; +// m_block_dev_sdc.block_dev.p_ops->geometry(&m_block_dev_sdc.block_dev)->blk_size; // uint32_t capacity = -// m_block_dev_sdc.block_dev.p_ops->geometry(&m_block_dev_sdc.block_dev)->blk_count -// / blocks_per_mb; printf("Capacity: %ld MB\n", capacity); +// m_block_dev_sdc.block_dev.p_ops->geometry(&m_block_dev_sdc.block_dev)->blk_count / blocks_per_mb; +// printf("Capacity: %ld MB\n", capacity); // printf("Mounting volume...\n"); // ff_result = f_mount(fs, "", 1); @@ -134,8 +134,7 @@ // printf("%9lu %s\n", fno.fsize, fno.fname); // } // } -// } -// while (fno.fname[0]); +// } while (fno.fname[0]); // printf("----\n \n"); // return; // } @@ -150,7 +149,8 @@ // FIL *N_fs_open(char *path) // { -// if (!fs) I_Error("N_fs_open: fs not iniitialized\n"); +// if (!fs) +// I_Error("N_fs_open: fs not iniitialized\n"); // printf("FatFS: Opening: %s\n", path); // FIL *fstream = N_malloc(sizeof(FIL)); // FRESULT ff_result; @@ -168,38 +168,37 @@ // FSIZE_t N_fs_size(FIL *fstream) // { -// if (!fs) I_Error("N_fs_open: fs not iniitialized\n"); +// if (!fs) +// I_Error("N_fs_open: fs not iniitialized\n"); // return f_size(fstream); // } // static void N_fs_close(FIL *fstream) // { -// if (!fs) I_Error("N_fs_open: fs not iniitialized\n"); -// (void) f_close(fstream); +// if (!fs) +// I_Error("N_fs_open: fs not iniitialized\n"); +// (void)f_close(fstream); // N_free(fstream); // } // // Read data from the specified position in the file into the -// // provided buffer. Returns the number of bytes read. - -// size_t N_fs_read(FIL *fstream, unsigned int offset, void *buffer, size_t -// buffer_len) +// // provided buffer. Returns the number of bytes read. +// size_t N_fs_read(FIL *fstream, unsigned int offset, void *buffer, size_t buffer_len) // { -// if (!fs) I_Error("N_fs_open: fs not iniitialized\n"); +// if (!fs) +// I_Error("N_fs_open: fs not iniitialized\n"); // size_t result; // FRESULT ff_result; -// // Jump to the specified position in the file. - +// // Jump to the specified position in the file // ff_result = f_lseek(fstream, offset); // if (ff_result != FR_OK) // { // printf("W_FatFS_Read: seek failed\n"); // return 0; // } -// // Read into the buffer. - +// // Read into the buffer // ff_result = f_read(fstream, buffer, buffer_len, &result); // if (ff_result != FR_OK) // { @@ -210,46 +209,52 @@ // return result; // } -// int N_fs_file_exists(char *path) { -// if (!fs) I_Error("N_fs_open: fs not iniitialized\n"); +// int N_fs_file_exists(char *path) +// { +// if (!fs) +// I_Error("N_fs_open: fs not iniitialized\n"); // FRESULT fr; // FILINFO fno; // fr = f_stat(path, &fno); -// switch (fr) { -// case FR_OK: -// return 1; -// break; +// switch (fr) +// { +// case FR_OK: +// return 1; +// break; -// case FR_NO_FILE: -// return 0; -// break; +// case FR_NO_FILE: +// return 0; +// break; -// default: -// I_Error("N_fs_file_exists"); +// default: +// I_Error("N_fs_file_exists"); // } // return 0; // } -// long N_fs_file_length(char *path) { -// if (!fs) I_Error("N_fs_open: fs not iniitialized\n"); +// long N_fs_file_length(char *path) +// { +// if (!fs) +// I_Error("N_fs_open: fs not iniitialized\n"); // FRESULT fr; // FILINFO fno; // fr = f_stat(path, &fno); -// switch (fr) { -// case FR_OK: -// return fno.fsize; -// break; +// switch (fr) +// { +// case FR_OK: +// return fno.fsize; +// break; -// case FR_NO_FILE: -// return 01; -// break; +// case FR_NO_FILE: +// return 01; +// break; -// default: -// I_Error("N_fs_file_length"); +// default: +// I_Error("N_fs_file_length"); // } // return -1; // } diff --git a/zephyrdoom/src/n_fs.h b/zephyrdoom/src/n_fs.h index 71ca32e..a785361 100644 --- a/zephyrdoom/src/n_fs.h +++ b/zephyrdoom/src/n_fs.h @@ -1,41 +1,41 @@ -// /* -// * Copyright (c) 2019 - 2020, Nordic Semiconductor ASA -// * All rights reserved. -// * -// * Redistribution and use in source and binary forms, with or without -// * modification, are permitted provided that the following conditions are -// met: -// * -// * 1. Redistributions of source code must retain the above copyright notice, -// this -// * list of conditions and the following disclaimer. -// * -// * 2. Redistributions in binary form must reproduce the above copyright -// * notice, this list of conditions and the following disclaimer in the -// * documentation and/or other materials provided with the distribution. -// * -// * 3. Neither the name of the copyright holder nor the names of its -// * contributors may be used to endorse or promote products derived from -// this -// * software without specific prior written permission. -// * -// * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS -// IS" -// * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// * POSSIBILITY OF SUCH DAMAGE. -// */ +/* + * Copyright (c) 2019 - 2020, Nordic Semiconductor ASA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + met: + * + * 1. Redistributions of source code must retain the above copyright notice, + this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #include "ff.h" -typedef FIL* N_FILE; +typedef FIL *N_FILE; void N_fs_init(); void N_fs_shutdown(); @@ -43,8 +43,7 @@ void N_fs_shutdown(); FIL *N_fs_open(char *path); static void N_fs_close(FIL *fstream); FSIZE_t N_fs_size(FIL *fstream); -size_t N_fs_read(FIL *fstream, unsigned int offset, void *buffer, size_t -buffer_len); +size_t N_fs_read(FIL *fstream, unsigned int offset, void *buffer, size_t buffer_len); int N_fs_file_exists(char *path); long N_fs_file_size(char *path); diff --git a/zephyrdoom/src/n_hardfault.c b/zephyrdoom/src/n_hardfault.c index 15e25dc..30fb095 100644 --- a/zephyrdoom/src/n_hardfault.c +++ b/zephyrdoom/src/n_hardfault.c @@ -29,81 +29,85 @@ * POSSIBILITY OF SUCH DAMAGE. */ - #include #include #include "hardfault.h" -__WEAK void HardFault_process(HardFault_stack_t * p_stack) +__WEAK void HardFault_process(HardFault_stack_t *p_stack) { nrf_delay_ms(5000); - // Restart the system by default + /* Restart the system by default */ NVIC_SystemReset(); } -void HardFault_Print(const char *msg) { - for (int i=0;i<256;i++) { +void HardFault_Print(const char *msg) +{ + for (int i = 0; i < 256; i++) + { char c = msg[i]; - if (!c) return; + if (!c) + return; NRF_UART0->EVENTS_TXDRDY = 0; NRF_UART0->TXD = c; - while (!NRF_UART0->EVENTS_TXDRDY) {} + while (!NRF_UART0->EVENTS_TXDRDY) + { + } } } void intToHex(unsigned long n, char *outbuf) { - int i = 12; int j = 0; - do{ + do + { outbuf[i] = "0123456789ABCDEF"[n % 16]; i--; - n = n/16; - } while( n > 0); + n = n / 16; + } while (n > 0); - while( ++i < 13){ - outbuf[j++] = outbuf[i]; + while (++i < 13) + { + outbuf[j++] = outbuf[i]; } outbuf[j] = 0; - } -void HardFault_Print_Hex(unsigned int value) { +void HardFault_Print_Hex(unsigned int value) +{ char msg[13]; intToHex(value, msg); HardFault_Print(msg); } - -void HardFault_c_handler(uint32_t * p_stack_address) +void HardFault_c_handler(uint32_t *p_stack_address) { bsp_board_led_on(2); HardFault_Print("HardFault!!\n"); #ifndef CFSR_MMARVALID - #define CFSR_MMARVALID (1 << (0 + 7)) +#define CFSR_MMARVALID (1 << (0 + 7)) #endif #ifndef CFSR_BFARVALID - #define CFSR_BFARVALID (1 << (8 + 7)) +#define CFSR_BFARVALID (1 << (8 + 7)) #endif static const char *cfsr_msgs[] = { - [0] = "The processor has attempted to execute an undefined instruction", - [1] = "The processor attempted a load or store at a location that does not permit the operation", - [2] = NULL, - [3] = "Unstack for an exception return has caused one or more access violations", - [4] = "Stacking for an exception entry has caused one or more access violations", - [5] = "A MemManage fault occurred during floating-point lazy state preservation", - [6] = NULL, - [7] = NULL, - [8] = "Instruction bus error", - [9] = "Data bus error (PC value stacked for the exception return points to the instruction that caused the fault)", + [0] = "The processor has attempted to execute an undefined instruction", + [1] = "The processor attempted a load or store at a location that does not permit the operation", + [2] = NULL, + [3] = "Unstack for an exception return has caused one or more access violations", + [4] = "Stacking for an exception entry has caused one or more access violations", + [5] = "A MemManage fault occurred during floating-point lazy state preservation", + [6] = NULL, + [7] = NULL, + [8] = "Instruction bus error", + [9] = "Data bus error (PC value stacked for the exception return points to the instruction that caused the fault)", [10] = "Data bus error (return address in the stack frame is not related to the instruction that caused the error)", [11] = "Unstack for an exception return has caused one or more BusFaults", [12] = "Stacking for an exception entry has caused one or more BusFaults", @@ -133,7 +137,7 @@ void HardFault_c_handler(uint32_t * p_stack_address) { if (((cfsr & (1 << i)) != 0) && (cfsr_msgs[i] != NULL)) { - printf("Cause: %s.\n", (char*)cfsr_msgs[i]); + printf("Cause: %s.\n", (char *)cfsr_msgs[i]); } } @@ -148,85 +152,88 @@ void HardFault_c_handler(uint32_t * p_stack_address) HardFault_Print_Hex((unsigned int)SCB->BFAR); } -/* -#ifndef CFSR_MMARVALID - #define CFSR_MMARVALID (1 << (0 + 7)) -#endif - -#ifndef CFSR_BFARVALID - #define CFSR_BFARVALID (1 << (8 + 7)) -#endif - - HardFault_stack_t * p_stack = (HardFault_stack_t *)p_stack_address; - static const char *cfsr_msgs[] = { - [0] = "The processor has attempted to execute an undefined instruction", - [1] = "The processor attempted a load or store at a location that does not permit the operation", - [2] = NULL, - [3] = "Unstack for an exception return has caused one or more access violations", - [4] = "Stacking for an exception entry has caused one or more access violations", - [5] = "A MemManage fault occurred during floating-point lazy state preservation", - [6] = NULL, - [7] = NULL, - [8] = "Instruction bus error", - [9] = "Data bus error (PC value stacked for the exception return points to the instruction that caused the fault)", - [10] = "Data bus error (return address in the stack frame is not related to the instruction that caused the error)", - [11] = "Unstack for an exception return has caused one or more BusFaults", - [12] = "Stacking for an exception entry has caused one or more BusFaults", - [13] = "A bus fault occurred during floating-point lazy state preservation", - [14] = NULL, - [15] = NULL, - [16] = "The processor has attempted to execute an undefined instruction", - [17] = "The processor has attempted to execute an instruction that makes illegal use of the EPSR", - [18] = "The processor has attempted an illegal load of EXC_RETURN to the PC, as a result of an invalid context, or an invalid EXC_RETURN value", - [19] = "The processor has attempted to access a coprocessor", - [20] = NULL, - [21] = NULL, - [22] = NULL, - [23] = NULL, - [24] = "The processor has made an unaligned memory access", - [25] = "The processor has executed an SDIV or UDIV instruction with a divisor of 0", - }; - - uint32_t cfsr = SCB->CFSR; - - if (p_stack != NULL) - { - // Print information about error. - printf("HARD FAULT at 0x%08X\n", (unsigned int)p_stack->pc); - printf(" R0: 0x%08X R1: 0x%08X R2: 0x%08X R3: 0x%08X\n", - (unsigned int)p_stack->r0, (unsigned int)p_stack->r1, (unsigned int)p_stack->r2, (unsigned int)p_stack->r3); - printf(" R12: 0x%08X LR: 0x%08X PSR: 0x%08X\n", - (unsigned int)p_stack->r12, (unsigned int)p_stack->lr, (unsigned int)p_stack->psr); - } - else - { - printf("Stack violation: stack pointer outside stack area.\n"); - } - - if (SCB->HFSR & SCB_HFSR_VECTTBL_Msk) - { - printf("Cause: BusFault on a vector table read during exception processing.\n"); - } + /* + * // TODO + * #ifndef CFSR_MMARVALID + * #define CFSR_MMARVALID (1 << (0 + 7)) + * #endif + * + * #ifndef CFSR_BFARVALID + * #define CFSR_BFARVALID (1 << (8 + 7)) + * #endif + * + * HardFault_stack_t *p_stack = (HardFault_stack_t *)p_stack_address; + * static const char *cfsr_msgs[] = { + * [0] = "The processor has attempted to execute an undefined instruction", + * [1] = "The processor attempted a load or store at a location that does not permit the operation", + * [2] = NULL, + * [3] = "Unstack for an exception return has caused one or more access violations", + * [4] = "Stacking for an exception entry has caused one or more access violations", + * [5] = "A MemManage fault occurred during floating-point lazy state preservation", + * [6] = NULL, + * [7] = NULL, + * [8] = "Instruction bus error", + * [9] = "Data bus error (PC value stacked for the exception return points to the instruction that caused the fault)", + * [10] = "Data bus error (return address in the stack frame is not related to the instruction that caused the error)", + * [11] = "Unstack for an exception return has caused one or more BusFaults", + * [12] = "Stacking for an exception entry has caused one or more BusFaults", + * [13] = "A bus fault occurred during floating-point lazy state preservation", + * [14] = NULL, + * [15] = NULL, + * [16] = "The processor has attempted to execute an undefined instruction", + * [17] = "The processor has attempted to execute an instruction that makes illegal use of the EPSR", + * [18] = "The processor has attempted an illegal load of EXC_RETURN to the PC, as a result of an invalid context, or an invalid EXC_RETURN value", + * [19] = "The processor has attempted to access a coprocessor", + * [20] = NULL, + * [21] = NULL, + * [22] = NULL, + * [23] = NULL, + * [24] = "The processor has made an unaligned memory access", + * [25] = "The processor has executed an SDIV or UDIV instruction with a divisor of 0", + * }; + * + * uint32_t cfsr = SCB->CFSR; + * + * if (p_stack != NULL) + * { + * // Print information about error + * printf("HARD FAULT at 0x%08X\n", (unsigned int)p_stack->pc); + * printf(" R0: 0x%08X R1: 0x%08X R2: 0x%08X R3: 0x%08X\n", + * (unsigned int)p_stack->r0, (unsigned int)p_stack->r1, (unsigned int)p_stack->r2, (unsigned int)p_stack->r3); + * printf(" R12: 0x%08X LR: 0x%08X PSR: 0x%08X\n", + * (unsigned int)p_stack->r12, (unsigned int)p_stack->lr, (unsigned int)p_stack->psr); + * } + * else + * { + * printf("Stack violation: stack pointer outside stack area.\n"); + * } + * + * if (SCB->HFSR & SCB_HFSR_VECTTBL_Msk) + * { + * printf("Cause: BusFault on a vector table read during exception processing.\n"); + * } + * + * for (uint32_t i = 0; i < sizeof(cfsr_msgs) / sizeof(cfsr_msgs[0]); i++) + * { + * if (((cfsr & (1 << i)) != 0) && (cfsr_msgs[i] != NULL)) + * { + * printf("Cause: %s.\n", (char *)cfsr_msgs[i]); + * } + * } + * + * if (cfsr & CFSR_MMARVALID) + * { + * printf("MemManage Fault Address: 0x%08X\n", (unsigned int)SCB->MMFAR); + * } + * + * if (cfsr & CFSR_BFARVALID) + * { + * printf("Bus Fault Address: 0x%08X\n", (unsigned int)SCB->BFAR); + * } + */ - for (uint32_t i = 0; i < sizeof(cfsr_msgs) / sizeof(cfsr_msgs[0]); i++) - { - if (((cfsr & (1 << i)) != 0) && (cfsr_msgs[i] != NULL)) - { - printf("Cause: %s.\n", (char*)cfsr_msgs[i]); - } - } - - if (cfsr & CFSR_MMARVALID) - { - printf("MemManage Fault Address: 0x%08X\n", (unsigned int)SCB->MMFAR); - } - - if (cfsr & CFSR_BFARVALID) + HardFault_process((HardFault_stack_t *)p_stack_address); + while (1) { - printf("Bus Fault Address: 0x%08X\n", (unsigned int)SCB->BFAR); } - */ - - HardFault_process((HardFault_stack_t *)p_stack_address); - while(1) {} } diff --git a/zephyrdoom/src/n_i2s.c b/zephyrdoom/src/n_i2s.c index bf68c3d..364d5fd 100644 --- a/zephyrdoom/src/n_i2s.c +++ b/zephyrdoom/src/n_i2s.c @@ -29,8 +29,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ - - #include "n_i2s.h" #include @@ -44,33 +42,35 @@ #define SAMPLE_RATE 10870 #define ZERO_SAMPLE 0 -typedef enum { - BUF_EMPTY = 0, - BUF_FILLED = 1, - BUF_QUEUED = 2, +typedef enum +{ + BUF_EMPTY = 0, + BUF_FILLED = 1, + BUF_QUEUED = 2, BUF_PLAYING = 3 } buffer_state_t; -boolean i2s_started; +boolean i2s_started; -int16_t sampleBuffers[NUM_BUFFERS][BUFFER_SIZE]; +int16_t sampleBuffers[NUM_BUFFERS][BUFFER_SIZE]; buffer_state_t bufferStates[NUM_BUFFERS]; -int queuedBuffer; +int queuedBuffer; extern uint8_t pistol[]; extern int pistol_length; - static void zero_buffer(int bufIdx) { - for (int j=0; jPIN_CNF[I2S_PIN_SCK&0x1F] = 3; - NRF_P1_S->OUT = NRF_P1_S->OUT & ~(1<<(I2S_PIN_SCK&0x1F)); - */ + /* + * // TODO + * // Pull SCK down + * NRF_P1_S->PIN_CNF[I2S_PIN_SCK & 0x1F] = 3; + * NRF_P1_S->OUT = NRF_P1_S->OUT & ~(1 << (I2S_PIN_SCK & 0x1F)); + */ - NRF_I2S->PSEL.SCK = I2S_PIN_BCK; - NRF_I2S->PSEL.LRCK = I2S_PIN_LRCK; + NRF_I2S->PSEL.SCK = I2S_PIN_BCK; + NRF_I2S->PSEL.LRCK = I2S_PIN_LRCK; NRF_I2S->PSEL.SDOUT = I2S_PIN_DIN; - // fs = 44.1kHz - // bck = 44.1kHz*16*2 = 1.442Mhz - // bck 32x/1.442Mhz - 64/2.8224Mhz (48?) + /* + * fs = 44.1kHz + * bck = 44.1kHz * 16 * 2 = 1.442Mhz + * bck 32x/1.442Mhz - 64x/2.8224Mhz (48?) + */ - NRF_I2S->CONFIG.MODE = 0; // Master + NRF_I2S->CONFIG.MODE = 0; /* Master */ NRF_I2S->CONFIG.TXEN = 1; NRF_I2S->CONFIG.MCKEN = 1; - NRF_I2S->CONFIG.MCKFREQ = 185319424; // 1391304Hz MCK - NRF_I2S->CONFIG.RATIO = 4; // 1391304/128 = 10869.5Hz (11025kHz) - NRF_I2S->CONFIG.SWIDTH = 1; // 16-bit sample width - NRF_I2S->CONFIG.CHANNELS = 0; // Stereo (1=left only) - NRF_I2S->CONFIG.CLKCONFIG = 0; // 0=32Mhz clock, 1=AudioPLL + NRF_I2S->CONFIG.MCKFREQ = 185319424; /* 1391304Hz MCK */ + NRF_I2S->CONFIG.RATIO = 4; /* 1391304 / 128 = 10869.5Hz (11025kHz) */ + NRF_I2S->CONFIG.SWIDTH = 1; /* 16-bit sample width */ + NRF_I2S->CONFIG.CHANNELS = 0; /* Stereo (1 = left only) */ + NRF_I2S->CONFIG.CLKCONFIG = 0; /* 0 = 32Mhz clock, 1 = AudioPLL */ - - NRF_I2S->RXTXD.MAXCNT = BUFFER_SIZE/2; + NRF_I2S->RXTXD.MAXCNT = BUFFER_SIZE / 2; clear_buffers(); queuedBuffer = 0; bufferStates[queuedBuffer] = BUF_QUEUED; NRF_I2S->EVENTS_TXPTRUPD = 0; - // IRQ setup + + /* IRQ setup */ NVIC_SetPriority(I2S0_IRQn, 3); NVIC_EnableIRQ(I2S0_IRQn); NRF_I2S->INTEN = I2S_INTEN_TXPTRUPD_Msk; @@ -119,44 +122,48 @@ void N_I2S_init() NRF_I2S->ENABLE = 1; i2s_started = false; - } -boolean N_I2S_next_buffer(int *buf_size, int16_t **buffer) { +boolean N_I2S_next_buffer(int *buf_size, int16_t **buffer) +{ int bufIdx = queuedBuffer; - while (1) { - bufIdx = (bufIdx+1)%NUM_BUFFERS; - switch (bufferStates[bufIdx]) { - case BUF_EMPTY: - // printf("Empty buffer at %d\n", bufIdx); - *buf_size = BUFFER_SIZE; - *buffer = sampleBuffers[bufIdx]; - bufferStates[bufIdx] = BUF_FILLED; - return true; - case BUF_FILLED: - continue; - case BUF_QUEUED: - return false; - case BUF_PLAYING: - return false; - default: - // I_Error - break; + while (1) + { + bufIdx = (bufIdx + 1) % NUM_BUFFERS; + switch (bufferStates[bufIdx]) + { + case BUF_EMPTY: + *buf_size = BUFFER_SIZE; + *buffer = sampleBuffers[bufIdx]; + bufferStates[bufIdx] = BUF_FILLED; + return true; + case BUF_FILLED: + continue; + case BUF_QUEUED: + return false; + case BUF_PLAYING: + return false; + default: + /* I_Error */ + break; } } } static void N_I2S_queue_buffers() { - for (int i=0; iTASKS_START = 1; @@ -175,10 +183,9 @@ void N_I2S_process() } } - void I2S0_IRQHandler(void) { - if(NRF_I2S->EVENTS_TXPTRUPD != 0) + if (NRF_I2S->EVENTS_TXPTRUPD != 0) { N_I2S_queue_buffers(); } diff --git a/zephyrdoom/src/n_i2s.h b/zephyrdoom/src/n_i2s.h index a63786c..83e1b58 100644 --- a/zephyrdoom/src/n_i2s.h +++ b/zephyrdoom/src/n_i2s.h @@ -29,7 +29,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ - #include #include "doomtype.h" diff --git a/zephyrdoom/src/n_i2s_sound.c b/zephyrdoom/src/n_i2s_sound.c index 67ab3be..1b32d45 100644 --- a/zephyrdoom/src/n_i2s_sound.c +++ b/zephyrdoom/src/n_i2s_sound.c @@ -1,22 +1,22 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// Copyright(C) 2008 David Flater -// Copyright(C) 2021 Nordic Semiconductor ASA -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// System interface for sound. -// +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * Copyright(C) 2008 David Flater + * Copyright(C) 2021 Nordic Semiconductor ASA + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * System interface for sound. + */ #include "doom_config.h" @@ -46,14 +46,13 @@ static boolean sound_initialized = false; typedef struct __attribute__((packed)) mobj_s { - byte *ptr; - uint16_t pos; - uint16_t len; - uint8_t left_vol; - uint8_t right_vol; + byte *ptr; + uint16_t pos; + uint16_t len; + uint8_t left_vol; + uint8_t right_vol; } channel_data_t; - channel_data_t channels[NUM_CHANNELS]; static boolean CacheSFX(sfxinfo_t *sfxinfo, int handle) @@ -64,72 +63,66 @@ static boolean CacheSFX(sfxinfo_t *sfxinfo, int handle) unsigned int length; byte *data; - // need to load the sound - + /* Need to load the sound */ lumpnum = sfxinfo->lumpnum; data = W_CacheLumpNum(lumpnum, PU_STATIC); lumplen = W_LumpLength(lumpnum); - // Check the header, and ensure this is a valid sound - - if (lumplen < 8 - || data[0] != 0x03 || data[1] != 0x00) + /* Check the header, and ensure this is a valid sound */ + if (lumplen < 8 || data[0] != 0x03 || data[1] != 0x00) { - // Invalid sound - + /* Invalid sound */ return false; } - // 16 bit sample rate field, 32 bit length field - + /* 16 bit sample rate field, 32 bit length field */ samplerate = (data[3] << 8) | data[2]; length = (data[7] << 24) | (data[6] << 16) | (data[5] << 8) | data[4]; - // If the header specifies that the length of the sound is greater than - // the length of the lump itself, this is an invalid sound lump - - // We also discard sound lumps that are less than 49 samples long, - // as this is how DMX behaves - although the actual cut-off length - // seems to vary slightly depending on the sample rate. This needs - // further investigation to better understand the correct - // behavior. - + /* + * If the header specifies that the length of the sound is greater than + * the length of the lump itself, this is an invalid sound lump. + * + * We also discard sound lumps that are less than 49 samples long, + * as this is how DMX behaves - although the actual cut-off length + * seems to vary slightly depending on the sample rate. This needs + * further investigation to better understand the correct + * behavior. + */ if (length > lumplen - 8 || length <= 48) { return false; } - // The DMX sound library seems to skip the first 16 and last 16 - // bytes of the lump - reason unknown. - + /* + * The DMX sound library seems to skip the first 16 and last 16 + * bytes of the lump - reason unknown. + */ data += 16; length -= 32; - // Setup channel - // printf("CacheSFX: channel = %0d samplerate = %d, length = %d\n", handle, samplerate, length); - + /* Setup channel */ channels[handle].ptr = data; channels[handle].pos = 0; channels[handle].len = length; - - // W_ReleaseLumpNum(lumpnum); + /* W_ReleaseLumpNum(lumpnum); */ return true; } static void GetSfxLumpName(sfxinfo_t *sfx, char *buf, size_t buf_len) { - // Linked sfx lumps? Get the lump number for the sound linked to. - + /* Linked sfx lumps. Get the lump number for the sound linked to. */ if (sfx->link != NULL) { sfx = sfx->link; } - // Doom adds a DS* prefix to sound lumps; Heretic and Hexen don't - // do this. - + /* + * Doom adds a DS* prefix to sound lumps. Heretic and Hexen don't + * do this. + */ if (use_sfx_prefix) { M_snprintf(buf, buf_len, "ds%s", DEH_String(sfx->name)); @@ -140,18 +133,12 @@ static void GetSfxLumpName(sfxinfo_t *sfx, char *buf, size_t buf_len) } } - static void N_I2S_PrecacheSounds(sfxinfo_t *sounds, int num_sounds) { printf("NRFD-TODO: N_I2S_PrecacheSounds?\n"); } - -// -// Retrieve the raw data lump index -// for a given SFX name. -// - +/* Retrieve the raw data lump index for a given SFX name. */ static int N_I2S_GetSfxLumpNum(sfxinfo_t *sfx) { char namebuf[9]; @@ -165,30 +152,29 @@ static void N_I2S_UpdateSoundParams(int handle, int vol, int sep) { int left, right; - // printf("N_I2S_UpdateSoundParams\n"); - if (!sound_initialized || handle < 0 || handle >= NUM_CHANNELS) { return; } left = ((254 - sep) * vol) / 127; - right = ((sep) * vol) / 127; + right = ((sep)*vol) / 127; - if (left < 0) left = 0; - else if ( left > 255) left = 255; - if (right < 0) right = 0; - else if (right > 255) right = 255; + if (left < 0) + left = 0; + else if (left > 255) + left = 255; + if (right < 0) + right = 0; + else if (right > 255) + right = 255; channels[handle].left_vol = left; channels[handle].right_vol = right; - - // printf("N_I2S_UpdateSoundParams: %d %d\n", left, right); } static void ClearSoundOnChannel(int channel) { - // printf("Clear channel %0d\n", channel); channels[channel].ptr = NULL; channels[channel].len = 0; channels[channel].pos = 0; @@ -196,45 +182,38 @@ static void ClearSoundOnChannel(int channel) channels[channel].right_vol = 0; } -// -// Starting a sound means adding it -// to the current list of active sounds -// in the internal channels. -// As the SFX info struct contains -// e.g. a pointer to the raw data, -// it is ignored. -// As our sound handling does not handle -// priority, it is ignored. -// Pitching (that is, increased speed of playback) -// is set, but currently not used by mixing. -// - +/* + * Starting a sound means adding it to the current list of active sounds + * in the internal channels. + * As the SFX info struct contains e.g. a pointer to the raw data, + * it is ignored. + * As our sound handling does not handle priority, it is ignored. + * Pitching (that is, increased speed of playback) + * is set, but currently not used by mixing. + */ static int N_I2S_StartSound(sfxinfo_t *sfxinfo, int channel, int vol, int sep, int pitch) { - // allocated_sound_t *snd; - - // printf("N_I2S_StartSound %.9s %d %d %d %d\n", sfxinfo->name, channel, vol, sep, pitch); + /* allocated_sound_t *snd; */ if (!sound_initialized || channel < 0 || channel >= NUM_CHANNELS) { return -1; } - // Clear a sound effect if there is already one playing - // on this channel - + /* + * Clear a sound effect if there is already one playing + * on this channel. + */ ClearSoundOnChannel(channel); - // Get the sound data - + /* Get the sound data */ if (!CacheSFX(sfxinfo, channel)) { printf("N_I2S_StartSound: Error caching SFX\n"); return false; } - // set separation, etc. - + /* Set separation, etc. */ N_I2S_UpdateSoundParams(channel, vol, sep); return channel; @@ -247,11 +226,9 @@ static void N_I2S_StopSound(int handle) return; } - ClearSoundOnChannel(handle); } - static boolean N_I2S_SoundIsPlaying(int handle) { if (!sound_initialized || handle < 0 || handle >= NUM_CHANNELS) @@ -259,40 +236,37 @@ static boolean N_I2S_SoundIsPlaying(int handle) return false; } - // printf("N_I2S_SoundIsPlaying\n"); - return (channels[handle].ptr != NULL); } -// -// Periodically called to update the sound system -// - +/* Periodically called to update the sound system. */ static void N_I2S_UpdateSound(void) { - // printf("N_I2S_UpdateSound\n"); - int16_t *buf; - int buf_len; - while (N_I2S_next_buffer(&buf_len, &buf)) { - for (int i=0; i= ch.len) { + if (channels[j].pos >= ch.len) + { ClearSoundOnChannel(j); } - sample_l += sample*ch.left_vol; - sample_r += sample*ch.right_vol; + sample_l += sample * ch.left_vol; + sample_r += sample * ch.right_vol; } } - buf[i*2] = sample_l; - buf[i*2+1] = sample_r; + buf[i * 2] = sample_l; + buf[i * 2 + 1] = sample_r; } } @@ -301,18 +275,16 @@ static void N_I2S_UpdateSound(void) static void N_I2S_ShutdownSound(void) { - } - static boolean N_I2S_InitSound(boolean _use_sfx_prefix) { - use_sfx_prefix = _use_sfx_prefix; printf("N_I2S_InitSound\n"); - for (int i=0; i #include -// extern const uint32_t __HeapLimit; -// const uint32_t heapLimit = (uint32_t)&__HeapLimit; - -void *N_malloc(size_t size) { - // void *result; - // result = malloc(size); - // size_t end = (size_t)result + size; - - // printf("A %d at %X - %X - %lX\n", size, (size_t)result, end, heapLimit); - // if (end > heapLimit) { - // printf("Heap Overflow!!\n"); - // return NULL; - // } +/* + * extern const uint32_t __HeapLimit; + * const uint32_t heapLimit = (uint32_t)&__HeapLimit; + */ - // return result; +void *N_malloc(size_t size) +{ + /* + * // TODO + * void *result; + * result = malloc(size); + * size_t end = (size_t)result + size; + * + * if (end > heapLimit) + * { + * printf("Heap Overflow!!\n"); + * return NULL; + * } + * + * return result; + */ void *result; result = malloc(size); - if (result == NULL) { + if (result == NULL) + { printf("Heap Overflow!!\n"); return NULL; } diff --git a/zephyrdoom/src/n_qspi.c b/zephyrdoom/src/n_qspi.c index 70142f8..2d5f4c4 100644 --- a/zephyrdoom/src/n_qspi.c +++ b/zephyrdoom/src/n_qspi.c @@ -40,8 +40,6 @@ #include "config/board_config.h" #include "config/nrf_error.h" #include "config/nrfx_config.h" -// #include -// #include void I_Error(char *error, ...); @@ -61,21 +59,28 @@ size_t qspi_next_loc; #include -// TODO -void N_qspi_wait() { +void N_qspi_wait() +{ k_msleep(5); - // while (!m_finished) { - // } - // m_finished = false; + + /* + * // TODO + * while (!m_finished) + * { + * } + * m_finished = false; + */ } -static void qspi_handler(nrfx_qspi_evt_t event, void *p_context) { +static void qspi_handler(nrfx_qspi_evt_t event, void *p_context) +{ UNUSED_PARAMETER(event); UNUSED_PARAMETER(p_context); m_finished = true; } -static void configure_memory(void) { +static void configure_memory(void) +{ uint32_t err_code; uint8_t rxdata[4]; uint8_t data[4]; @@ -87,12 +92,12 @@ static void configure_memory(void) { .wipwait = true, .wren = true}; - // Send reset enable + /* Send reset enable */ printf("N_qspi: Send reset enable\n"); err_code = nrfx_qspi_cinstr_xfer(&cinstr_cfg, NULL, NULL); APP_ERROR_CHECK(err_code); - // Send reset command + /* Send reset command */ printf("N_qspi: Send reset command\n"); cinstr_cfg.opcode = QSPI_STD_CMD_RST; err_code = nrfx_qspi_cinstr_xfer(&cinstr_cfg, NULL, NULL); @@ -126,42 +131,45 @@ static void configure_memory(void) { printf("N_qspi: %x %x\n", rxdata[0], rxdata[1]); /* - // Send reset enable - err_code = nrfx_qspi_cinstr_xfer(&cinstr_cfg, NULL, NULL); - APP_ERROR_CHECK(err_code); - - // Send reset command - cinstr_cfg.opcode = QSPI_STD_CMD_RST; - err_code = nrfx_qspi_cinstr_xfer(&cinstr_cfg, NULL, NULL); - APP_ERROR_CHECK(err_code); + * // Send reset enable + * err_code = nrfx_qspi_cinstr_xfer(&cinstr_cfg, NULL, NULL); + * APP_ERROR_CHECK(err_code); + * + * // Send reset command + * cinstr_cfg.opcode = QSPI_STD_CMD_RST; + * err_code = nrfx_qspi_cinstr_xfer(&cinstr_cfg, NULL, NULL); + * APP_ERROR_CHECK(err_code); + * + * // Switch to qspi and high-performance mode + * uint8_t data[3]; + * data[0] = 0x40; // Set bit 6 for Quad mode + * data[1] = 0x00; + * data[2] = 0x02; // Set bit 2 for high-performance mode + * cinstr_cfg.opcode = QSPI_STD_CMD_WRSR; + * cinstr_cfg.length = NRF_QSPI_CINSTR_LEN_4B; + * err_code = nrfx_qspi_cinstr_xfer(&cinstr_cfg, data, NULL); + * APP_ERROR_CHECK(err_code); + */ - // Switch to qspi and high-performance mode - uint8_t data[3]; - data[0] = 0x40; // set bit 6 for Quad mode - data[1] = 0x00; - data[2] = 0x02; // set bit 2 for high-performance mode - cinstr_cfg.opcode = QSPI_STD_CMD_WRSR; - cinstr_cfg.length = NRF_QSPI_CINSTR_LEN_4B; - err_code = nrfx_qspi_cinstr_xfer(&cinstr_cfg, data, NULL); - APP_ERROR_CHECK(err_code); -*/ - // Switch to qspi mode /* - data = QSPI_SR_QUAD_ENABLE_BYTE; - cinstr_cfg.opcode = QSPI_STD_CMD_WRSR; - cinstr_cfg.length = NRF_QSPI_CINSTR_LEN_2B; - err_code = nrfx_qspi_cinstr_xfer(&cinstr_cfg, &data, NULL); - APP_ERROR_CHECK(err_code); - */ - - while (nrfx_qspi_mem_busy_check()) { + * // Switch to qspi mode + * data = QSPI_SR_QUAD_ENABLE_BYTE; + * cinstr_cfg.opcode = QSPI_STD_CMD_WRSR; + * cinstr_cfg.length = NRF_QSPI_CINSTR_LEN_2B; + * err_code = nrfx_qspi_cinstr_xfer(&cinstr_cfg, &data, NULL); + * APP_ERROR_CHECK(err_code); + */ + + while (nrfx_qspi_mem_busy_check()) + { } } -void N_qspi_init() { +void N_qspi_init() +{ uint32_t err_code = NRF_SUCCESS; - // Set high-drive for QuadSpi pins + /* Set high-drive for QuadSpi pins */ nrf_gpio_cfg(QSPI_SCK_PIN, NRF_GPIO_PIN_DIR_INPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE); @@ -181,17 +189,17 @@ void N_qspi_init() { NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE); - // Set QSPI peripheral with default configuration. + /* Set QSPI peripheral with default configuration */ nrfx_qspi_config_t config = - NRFX_QSPI_DEFAULT_CONFIG(QSPI_SCK_PIN, // _pin_sck - QSPI_CSN_PIN, // _pin_csn - QSPI_IO0_PIN, // _pin_io0 - QSPI_IO1_PIN, // _pin_io1 - QSPI_IO2_PIN, // _pin_io2 - QSPI_IO3_PIN // _pin_io3 + NRFX_QSPI_DEFAULT_CONFIG(QSPI_SCK_PIN, /* _pin_sck */ + QSPI_CSN_PIN, /* _pin_csn */ + QSPI_IO0_PIN, /* _pin_io0 */ + QSPI_IO1_PIN, /* _pin_io1 */ + QSPI_IO2_PIN, /* _pin_io2 */ + QSPI_IO3_PIN /* _pin_io3 */ ); - // Set SCK frequency to max + /* Set SCK frequency to max */ config.prot_if.readoc = (nrf_qspi_readoc_t)NRFX_QSPI_CONFIG_READOC; config.prot_if.writeoc = (nrf_qspi_writeoc_t)NRFX_QSPI_CONFIG_WRITEOC; config.prot_if.addrmode = (nrf_qspi_addrmode_t)NRFX_QSPI_CONFIG_ADDRMODE; @@ -201,28 +209,36 @@ void N_qspi_init() { config.phy_if.spi_mode = (nrf_qspi_spi_mode_t)NRFX_QSPI_CONFIG_MODE; config.phy_if.sck_freq = (nrf_qspi_frequency_t)NRFX_QSPI_CONFIG_FREQUENCY; - // Try to initialize QSPI peripheral in blocking mode. - // TODO + /* + * TODO + * Try to initialize QSPI peripheral in blocking mode. + */ err_code = nrfx_qspi_init(&config, NULL, NULL); APP_ERROR_CHECK(err_code); - // Set RXDELAY to 1 - // TODO: Use define if MDK is updated to include it + /* + * TODO + * Use define if MDK is updated to include it + * Set RXDELAY to 1 + */ NRF_QSPI_S->IFTIMING = (1 << 8); printf("QSPI initialized\n"); printf("QSPI initialized %ld %ld\n", (NRF_QSPI_S->IFTIMING >> 8), ((NRF_QSPI_S->IFCONFIG1 >> 28) & 0xF)); - // Restart and configure external memory to use quad line mode for data - // exchange. + /* + * Restart and configure external memory to use quad line mode for data + * exchange. + */ configure_memory(); printf("Memory device configured. Quad Mode activated.\n"); qspi_next_loc = 0; } -void N_qspi_erase_block(size_t loc) { +void N_qspi_erase_block(size_t loc) +{ uint32_t err_code = NRF_SUCCESS; err_code = nrfx_qspi_erase(NRF_QSPI_ERASE_LEN_64KB, loc); @@ -232,7 +248,8 @@ void N_qspi_erase_block(size_t loc) { printf("N_qspi: Erased 64KB block at %d\n", loc); } -void N_qspi_write(size_t loc, void *buffer, size_t size) { +void N_qspi_write(size_t loc, void *buffer, size_t size) +{ uint32_t err_code = NRF_SUCCESS; err_code = nrfx_qspi_write(buffer, size, loc); if (err_code != NRF_SUCCESS) @@ -241,10 +258,12 @@ void N_qspi_write(size_t loc, void *buffer, size_t size) { printf("N_qspi: Wrote %d byte chunk at %d\n", size, loc); } -void N_qspi_write_block(size_t loc, void *buffer, size_t size) { +void N_qspi_write_block(size_t loc, void *buffer, size_t size) +{ uint32_t err_code = NRF_SUCCESS; - if (size > N_QSPI_BLOCK_SIZE) { + if (size > N_QSPI_BLOCK_SIZE) + { I_Error("N_qspi_write_block: Tried to write block > 64KB\n"); } @@ -261,14 +280,18 @@ void N_qspi_write_block(size_t loc, void *buffer, size_t size) { printf("N_qspi: Wrote %d byte chunk at %d\n", size, loc); } -void N_qspi_read(size_t loc, void *buffer, size_t size) { +void N_qspi_read(size_t loc, void *buffer, size_t size) +{ uint32_t err_code = NRF_SUCCESS; err_code = nrfx_qspi_read(buffer, size, loc); - if (err_code != NRF_SUCCESS) { - if (err_code == NRFX_ERROR_BUSY) { + if (err_code != NRF_SUCCESS) + { + if (err_code == NRFX_ERROR_BUSY) + { I_Error("N_qspi_write_block: nrfx_qspi_read fail NRFX_ERROR_BUSY"); } - if (err_code == NRFX_ERROR_INVALID_ADDR) { + if (err_code == NRFX_ERROR_INVALID_ADDR) + { I_Error( "N_qspi_write_block: nrfx_qspi_read fail " "NRFX_ERROR_INVALID_ADDR %x", @@ -277,18 +300,20 @@ void N_qspi_read(size_t loc, void *buffer, size_t size) { I_Error("N_qspi_write_block: nrfx_qspi_read fail UNKNOWN"); } N_qspi_wait(); - // printf("N_qspi: Read %d at %d\n", size, loc); } -void *N_qspi_data_pointer(size_t loc) { +void *N_qspi_data_pointer(size_t loc) +{ return (void *)(N_QSPI_XIP_START_ADDR + loc); } -void N_qspi_reserve_blocks(size_t block_count) { +void N_qspi_reserve_blocks(size_t block_count) +{ qspi_next_loc += block_count * N_QSPI_BLOCK_SIZE; } -size_t N_qspi_alloc_block() { +size_t N_qspi_alloc_block() +{ size_t loc = qspi_next_loc; qspi_next_loc += N_QSPI_BLOCK_SIZE; return loc; diff --git a/zephyrdoom/src/n_qspi.h b/zephyrdoom/src/n_qspi.h index 3792d95..daba056 100644 --- a/zephyrdoom/src/n_qspi.h +++ b/zephyrdoom/src/n_qspi.h @@ -31,18 +31,17 @@ #include -#define N_QSPI_XIP_START_ADDR 0x12000000 -// #define N_QSPI_XIP_START_ADDR 0x10000000 - -#define N_QSPI_BLOCK_SIZE (64*1024) +#define N_QSPI_XIP_START_ADDR 0x12000000 +/* #define N_QSPI_XIP_START_ADDR 0x10000000 */ +#define N_QSPI_BLOCK_SIZE (64 * 1024) void *N_qspi_data_pointer(size_t loc); void N_qspi_wait(); void N_qspi_init(); -void N_qspi_erase_block(size_t loc) ; -void N_qspi_write(size_t loc, void *buffer, size_t size) ; +void N_qspi_erase_block(size_t loc); +void N_qspi_write(size_t loc, void *buffer, size_t size); void N_qspi_write_block(size_t loc, void *buffer, size_t size); -void N_qspi_read(size_t loc, void *buffer, size_t size) ; +void N_qspi_read(size_t loc, void *buffer, size_t size); void N_qspi_reserve_blocks(size_t block_count); size_t N_qspi_alloc_block(); diff --git a/zephyrdoom/src/n_rjoy.c b/zephyrdoom/src/n_rjoy.c index 17fa522..b1c8ab8 100644 --- a/zephyrdoom/src/n_rjoy.c +++ b/zephyrdoom/src/n_rjoy.c @@ -27,15 +27,15 @@ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. + * + * DESCRIPTION: + * Nordic Propriatery gamepad/joycon. */ -// Nordic Propriatery gamepad/joycon - #include #include "nrf.h" #include -// #include "nrf_delay.h" #include "board_config.h" #undef PACKED_STRUCT @@ -44,7 +44,7 @@ #include "d_event.h" #include "i_system.h" -// State. +/* State. */ #include "doom/doomstat.h" const int x_cen = 128; @@ -53,16 +53,18 @@ const int guard = 4; extern short st_faceindex; -static player_t* plyr; +static player_t *plyr; -typedef struct { +typedef struct +{ uint8_t counter; uint8_t buttons; uint8_t joyX; uint8_t joyY; } rjoy_radio_packet_t; -typedef struct { +typedef struct +{ uint8_t face; uint8_t health; uint8_t ammo; @@ -71,31 +73,31 @@ typedef struct { rjoy_radio_packet_t prev_joy_state; -int N_rjoy_init() { +int N_rjoy_init() +{ plyr = &players[consoleplayer]; return 1; } - -void N_rjoy_read() { +void N_rjoy_read() +{ volatile uint32_t *ipc_ptr = &NRF_IPC_S->GPMEM[0]; uint32_t radio_packet = *ipc_ptr; rjoy_radio_packet_t new_joy_state; - uint32_t *tmp = (uint32_t*)(&new_joy_state); + uint32_t *tmp = (uint32_t *)(&new_joy_state); *tmp = radio_packet; - //printf("%d %d %d %d %lx\n", new_joy_state.counter, new_joy_state.buttons, new_joy_state.joyX, new_joy_state.joyY, *tmp); - if (new_joy_state.counter != prev_joy_state.counter) { - // printf("N_rjoy_read: %d\n", new_joy_state.counter); + if (new_joy_state.counter != prev_joy_state.counter) + { event_t ev; - int joyX = new_joy_state.joyX-x_cen; - int joyY = new_joy_state.joyY-y_cen; - - if (-guard < joyX && joyX < guard) joyX = 0; - if (-guard < joyY && joyY < guard) joyY = 0; + int joyX = new_joy_state.joyX - x_cen; + int joyY = new_joy_state.joyY - y_cen; - // printf("N_rjoy_read: %d %d\n", joyX, joyY); + if (-guard < joyX && joyX < guard) + joyX = 0; + if (-guard < joyY && joyY < guard) + joyY = 0; ev.type = ev_joystick; ev.data1 = new_joy_state.buttons; @@ -108,7 +110,7 @@ void N_rjoy_read() { } prev_joy_state = new_joy_state; - // Provide current face to radio for transfer to gamepad + /* Provide current face to radio for transfer to gamepad */ radio_packet_out response = {0}; response.face = st_faceindex; response.health = plyr->health; @@ -116,5 +118,5 @@ void N_rjoy_read() { response.armor = plyr->armorpoints; volatile uint32_t *ipc_ptr_1 = &NRF_IPC_S->GPMEM[1]; - *ipc_ptr_1 = *(uint32_t*)&response; + *ipc_ptr_1 = *(uint32_t *)&response; } diff --git a/zephyrdoom/src/n_rjoy.h b/zephyrdoom/src/n_rjoy.h index afaedc3..14fb373 100644 --- a/zephyrdoom/src/n_rjoy.h +++ b/zephyrdoom/src/n_rjoy.h @@ -27,8 +27,10 @@ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. + * + * DESCRIPTION: + * Implement custom radio based gamepad. */ -// Implement custom radio based gamepad int N_rjoy_init(); void N_rjoy_read(); diff --git a/zephyrdoom/src/net_client.c b/zephyrdoom/src/net_client.c index ed65911..829a2d7 100644 --- a/zephyrdoom/src/net_client.c +++ b/zephyrdoom/src/net_client.c @@ -1,18 +1,19 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// Network client code -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Network client code. + */ #include #include @@ -44,56 +45,43 @@ extern void D_ReceiveTic(ticcmd_t *ticcmds, boolean *playeringame); typedef enum { - // waiting for the game to launch - + /* Waiting for the game to launch */ CLIENT_STATE_WAITING_LAUNCH, - // waiting for the game to start - + /* Waiting for the game to start */ CLIENT_STATE_WAITING_START, // in game CLIENT_STATE_IN_GAME, - } net_clientstate_t; -// Type of structure used in the receive window - +/* Type of structure used in the receive window. */ typedef struct { - // Whether this tic has been received yet - + /* Whether this tic has been received yet */ boolean active; - // Last time we sent a resend request for this tic - + /* Last time we sent a resend request for this tic */ unsigned int resend_time; - // Tic data from server - + /* Tic data from server */ net_full_ticcmd_t cmd; - } net_server_recv_t; -// Type of structure used in the send window - +/* Type of structure used in the send window. */ typedef struct { - // Whether this slot is active yet - + /* Whether this slot is active yet */ boolean active; - // The tic number - + /* The tic number */ unsigned int seq; - // Time the command was generated - + /* Time the command was generated */ unsigned int time; - // Ticcmd diff - + /* Ticcmd diff */ net_ticdiff_t cmd; } net_server_send_t; @@ -104,896 +92,820 @@ static net_clientstate_t client_state; static net_addr_t *server_addr; static net_context_t *client_context; -// game settings, as received from the server when the game started - +/* Game settings, as received from the server when the game started. */ static net_gamesettings_t settings; -// true if the client code is in use - +/* True if the client code is in use. */ boolean net_client_connected; -// true if we have received waiting data from the server, -// and the wait data that was received. - +/* + * True if we have received waiting data from the server, + * and the wait data that was received. + */ boolean net_client_received_wait_data; -// NRFD-TODO: Net -// net_waitdata_t net_client_wait_data; -// Waiting at the initial wait screen for the game to be launched? +/* + * // NRFD-TODO + * // Configure network + * net_waitdata_t net_client_wait_data; + */ +/* Waiting at the initial wait screen for the game to be launched. */ boolean net_waiting_for_launch = false; -// Name that we send to the server - +/* Name that we send to the server. */ char *net_player_name = NULL; -// Connected but not participating in the game (observer) - +/* Connected but not participating in the game (observer). */ boolean drone = false; -// The last ticcmd constructed - +/* The last ticcmd constructed. */ static ticcmd_t last_ticcmd; -// Buffer of ticcmd diffs being sent to the server - -/* NRFD-TODO: -static net_server_send_t send_queue[BACKUPTICS]; - -// Receive window - -static ticcmd_t recvwindow_cmd_base[NET_MAXPLAYERS]; -static int recvwindow_start; -static net_server_recv_t recvwindow[BACKUPTICS]; - -// Whether we need to send an acknowledgement and -// when gamedata was last received. - -static boolean need_to_acknowledge; -static unsigned int gamedata_recv_time; - -// Hash checksums of our wad directory and dehacked data. - -sha1_digest_t net_local_wad_sha1sum; -sha1_digest_t net_local_deh_sha1sum; -*/ - -// Are we playing with the freedoom IWAD? - +/* + * // NRFD-TODO + * // Buffer of ticcmd diffs being sent to the server. + * static net_server_send_t send_queue[BACKUPTICS]; + * + * // Receive window. + * static ticcmd_t recvwindow_cmd_base[NET_MAXPLAYERS]; + * static int recvwindow_start; + * static net_server_recv_t recvwindow[BACKUPTICS]; + * + * // Whether we need to send an acknowledgement and + * // when gamedata was last received. + * static boolean need_to_acknowledge; + * static unsigned int gamedata_recv_time; + * + * // Hash checksums of our wad directory and dehacked data. + * sha1_digest_t net_local_wad_sha1sum; + * sha1_digest_t net_local_deh_sha1sum; + */ + +/* Are we playing with the freedoom IWAD. */ unsigned int net_local_is_freedoom; -// Average time between sending our ticcmd and receiving from the server - +/* Average time between sending our ticcmd and receiving from the server. */ static fixed_t average_latency; #define NET_CL_ExpandTicNum(b) NET_ExpandTicNum(recvwindow_start, (b)) -// Called when we become disconnected from the server - +/* Called when we become disconnected from the server. */ static void NET_CL_Disconnected(void) { D_ReceiveTic(NULL, NULL); } -// Expand a net_full_ticcmd_t, applying the diffs in cmd->cmds as -// patches against recvwindow_cmd_base. Place the results into -// the d_net.c structures (netcmds/nettics) and save the new ticcmd -// back into recvwindow_cmd_base. - +/* + * Expand a net_full_ticcmd_t, applying the diffs in cmd->cmds as + * patches against recvwindow_cmd_base. Place the results into + * the d_net.c structures (netcmds/nettics) and save the new ticcmd + * back into recvwindow_cmd_base. + */ static void NET_CL_ExpandFullTiccmd(net_full_ticcmd_t *cmd, unsigned int seq, ticcmd_t *ticcmds) { - printf("NRFD-TODO: \n"); /* - int latency; - fixed_t adjustment; - int i; - - // Update average_latency - - if (seq == send_queue[seq % BACKUPTICS].seq) - { - latency = I_GetTimeMS() - send_queue[seq % BACKUPTICS].time; - } - else if (seq > send_queue[seq % BACKUPTICS].seq) - { - // We have received the ticcmd from the server before we have - // even sent ours - - latency = 0; - } - else - { - latency = -1; - } - - if (latency >= 0) - { - if (seq <= 20) - { - average_latency = latency * FRACUNIT; - } - else - { - // Low level filter - - average_latency = (fixed_t)((average_latency * 0.9) - + (latency * FRACUNIT * 0.1)); - } - } - - //printf("latency: %i\tremote:%i\n", average_latency / FRACUNIT, - // cmd->latency); - - // Possibly adjust offsetms in d_net.c, try to make players all have - // the same lag. Don't adjust in the first few tics of play, as - // we don't have an accurate value for average_latency yet. - - if (seq > TICRATE) - { - adjustment = (cmd->latency * FRACUNIT) - average_latency; - - // Only adjust very slightly; the cumulative effect over - // multiple tics will sort it out. - - adjustment = adjustment / 100; - - offsetms += adjustment; - } - - // Expand tic diffs for all players - - for (i=0; iplayeringame[i]) - { - net_ticdiff_t *diff; - - diff = &cmd->cmds[i]; - - // Use the ticcmd diff to patch the previous ticcmd to - // the new ticcmd - - NET_TiccmdPatch(&recvwindow_cmd_base[i], diff, &ticcmds[i]); - - // Store a copy for next time - - recvwindow_cmd_base[i] = ticcmds[i]; - } - } - */ + /* + * // NRFD-TODO + * int latency; + * fixed_t adjustment; + * int i; + * + * // Update average_latency + * if (seq == send_queue[seq % BACKUPTICS].seq) + * { + * latency = I_GetTimeMS() - send_queue[seq % BACKUPTICS].time; + * } + * else if (seq > send_queue[seq % BACKUPTICS].seq) + * { + * // We have received the ticcmd from the server before we have + * // even sent ours. + * latency = 0; + * } + * else + * { + * latency = -1; + * } + * + * if (latency >= 0) + * { + * if (seq <= 20) + * { + * average_latency = latency * FRACUNIT; + * } + * else + * { + * // Low level filter + * + * average_latency = (fixed_t)((average_latency * 0.9) + (latency * FRACUNIT * 0.1)); + * } + * } + * + * // Possibly adjust offsetms in d_net.c, try to make players all have + * // the same lag. Don't adjust in the first few tics of play, as + * // we don't have an accurate value for average_latency yet. + * if (seq > TICRATE) + * { + * adjustment = (cmd->latency * FRACUNIT) - average_latency; + * + * // Only adjust very slightly, the cumulative effect over + * // multiple tics will sort it out. + * adjustment = adjustment / 100; + * + * offsetms += adjustment; + * } + * + * // Expand tic diffs for all players + * for (i = 0; i < NET_MAXPLAYERS; ++i) + * { + * if (i == settings.consoleplayer && !drone) + * { + * continue; + * } + * + * if (cmd->playeringame[i]) + * { + * net_ticdiff_t *diff; + * + * diff = &cmd->cmds[i]; + * + * // Use the ticcmd diff to patch the previous ticcmd to + * // the new ticcmd. + * NET_TiccmdPatch(&recvwindow_cmd_base[i], diff, &ticcmds[i]); + * + * // Store a copy for next time + * recvwindow_cmd_base[i] = ticcmds[i]; + * } + * } + */ } -// Advance the receive window - +/* Advance the receive window. */ static void NET_CL_AdvanceWindow(void) { - printf("NRFD-TODO: \n"); /* - ticcmd_t ticcmds[NET_MAXPLAYERS]; - - while (recvwindow[0].active) - { - // Expand tic diff data into d_net.c structures - - NET_CL_ExpandFullTiccmd(&recvwindow[0].cmd, recvwindow_start, - ticcmds); - D_ReceiveTic(ticcmds, recvwindow[0].cmd.playeringame); - - // Advance the window - - memmove(recvwindow, recvwindow + 1, - sizeof(net_server_recv_t) * (BACKUPTICS - 1)); - memset(&recvwindow[BACKUPTICS-1], 0, sizeof(net_server_recv_t)); - - ++recvwindow_start; - - //printf("CL: advanced to %i\n", recvwindow_start); - } - */ + /* + * // NRFD-TODO + * ticcmd_t ticcmds[NET_MAXPLAYERS]; + * + * while (recvwindow[0].active) + * { + * // Expand tic diff data into d_net.c structures + * NET_CL_ExpandFullTiccmd(&recvwindow[0].cmd, recvwindow_start, + * ticcmds); + * D_ReceiveTic(ticcmds, recvwindow[0].cmd.playeringame); + * + * // Advance the window + * memmove(recvwindow, recvwindow + 1, + * sizeof(net_server_recv_t) * (BACKUPTICS - 1)); + * memset(&recvwindow[BACKUPTICS - 1], 0, sizeof(net_server_recv_t)); + * + * ++recvwindow_start; + * } + */ } -// Shut down the client code, etc. Invoked after a disconnect. - +/* Shut down the client code, etc. Invoked after a disconnect. */ static void NET_CL_Shutdown(void) { - printf("NRFD-TODO: \n"); /* - if (net_client_connected) - { - net_client_connected = false; - - NET_FreeAddress(server_addr); - - // Shut down network module, etc. To do. - } - */ + /* + * // NRFD-TODO + * if (net_client_connected) + * { + * net_client_connected = false; + * + * NET_FreeAddress(server_addr); + * + * // Shut down network module, etc. here. + * } + */ } void NET_CL_LaunchGame(void) { - printf("NRFD-TODO: \n"); /* - NET_Conn_NewReliable(&client_connection, NET_PACKET_TYPE_LAUNCH); - */ + /* + * // NRFD-TODO + * NET_Conn_NewReliable(&client_connection, NET_PACKET_TYPE_LAUNCH); + */ } void NET_CL_StartGame(net_gamesettings_t *settings) { - printf("NRFD-TODO: \n"); /* - net_packet_t *packet; - - // Start from a ticcmd of all zeros - - memset(&last_ticcmd, 0, sizeof(ticcmd_t)); - - // Send packet - - packet = NET_Conn_NewReliable(&client_connection, - NET_PACKET_TYPE_GAMESTART); - - NET_WriteSettings(packet, settings); - */ + /* + * // NRFD-TODO + * net_packet_t *packet; + * + * // Start from a ticcmd of all zeros + * memset(&last_ticcmd, 0, sizeof(ticcmd_t)); + * + * // Send packet + * packet = NET_Conn_NewReliable(&client_connection, + * NET_PACKET_TYPE_GAMESTART); + * + * NET_WriteSettings(packet, settings); + */ } static void NET_CL_SendGameDataACK(void) { - printf("NRFD-TODO: \n"); /* - net_packet_t *packet; - - packet = NET_NewPacket(10); - - NET_WriteInt16(packet, NET_PACKET_TYPE_GAMEDATA_ACK); - NET_WriteInt8(packet, recvwindow_start & 0xff); - - NET_Conn_SendPacket(&client_connection, packet); - - NET_FreePacket(packet); - - need_to_acknowledge = false; - */ + /* + * // NRFD-TODO + * net_packet_t *packet; + * + * packet = NET_NewPacket(10); + * + * NET_WriteInt16(packet, NET_PACKET_TYPE_GAMEDATA_ACK); + * NET_WriteInt8(packet, recvwindow_start & 0xff); + * + * NET_Conn_SendPacket(&client_connection, packet); + * + * NET_FreePacket(packet); + * + * need_to_acknowledge = false; + */ } static void NET_CL_SendTics(int start, int end) { - printf("NRFD-TODO: \n"); /* - net_packet_t *packet; - int i; - - if (!net_client_connected) - { - // Disconnected from server - - return; - } - - if (start < 0) - start = 0; - - // Build a new packet to send to the server - - packet = NET_NewPacket(512); - NET_WriteInt16(packet, NET_PACKET_TYPE_GAMEDATA); - - // Write the start tic and number of tics. Send only the low byte - // of start - it can be inferred by the server. - - NET_WriteInt8(packet, recvwindow_start & 0xff); - NET_WriteInt8(packet, start & 0xff); - NET_WriteInt8(packet, end - start + 1); - - // Add the tics. - - for (i=start; i<=end; ++i) - { - net_server_send_t *sendobj; - - sendobj = &send_queue[i % BACKUPTICS]; - - NET_WriteInt16(packet, average_latency / FRACUNIT); - - NET_WriteTiccmdDiff(packet, &sendobj->cmd, settings.lowres_turn); - } - - // Send the packet - - NET_Conn_SendPacket(&client_connection, packet); - - // All done! - - NET_FreePacket(packet); - - // Acknowledgement has been sent as part of the packet - - need_to_acknowledge = false; - */ + /* + * // NRFD-TODO + * net_packet_t *packet; + * int i; + * + * if (!net_client_connected) + * { + * // Disconnected from server + * return; + * } + * + * if (start < 0) + * start = 0; + * + * // Build a new packet to send to the server + * packet = NET_NewPacket(512); + * NET_WriteInt16(packet, NET_PACKET_TYPE_GAMEDATA); + * + * // Write the start tic and number of tics. Send only the low byte + * // of start - it can be inferred by the server. + * NET_WriteInt8(packet, recvwindow_start & 0xff); + * NET_WriteInt8(packet, start & 0xff); + * NET_WriteInt8(packet, end - start + 1); + * + * // Add the tics + * for (i = start; i <= end; ++i) + * { + * net_server_send_t *sendobj; + * + * sendobj = &send_queue[i % BACKUPTICS]; + * + * NET_WriteInt16(packet, average_latency / FRACUNIT); + * + * NET_WriteTiccmdDiff(packet, &sendobj->cmd, settings.lowres_turn); + * } + * + * // Send the packet + * NET_Conn_SendPacket(&client_connection, packet); + * + * // All done + * NET_FreePacket(packet); + * + * // Acknowledgement has been sent as part of the packet + * need_to_acknowledge = false; + */ } -// Add a new ticcmd to the send queue - +/* Add a new ticcmd to the send queue. */ void NET_CL_SendTiccmd(ticcmd_t *ticcmd, int maketic) { - printf("NRFD-TODO: NET_CL_SendTiccmd\n"); /* - net_ticdiff_t diff; - net_server_send_t *sendobj; - int starttic, endtic; - - // Calculate the difference to the last ticcmd - - NET_TiccmdDiff(&last_ticcmd, ticcmd, &diff); - - // Store in the send queue - - sendobj = &send_queue[maketic % BACKUPTICS]; - sendobj->active = true; - sendobj->seq = maketic; - sendobj->time = I_GetTimeMS(); - sendobj->cmd = diff; - - last_ticcmd = *ticcmd; - - // Send to server. - - starttic = maketic - settings.extratics; - endtic = maketic; - - if (starttic < 0) - starttic = 0; - - NET_CL_SendTics(starttic, endtic); - */ + /* + * // NRFD-TODO + * net_ticdiff_t diff; + * net_server_send_t *sendobj; + * int starttic, endtic; + * + * // Calculate the difference to the last ticcmd + * NET_TiccmdDiff(&last_ticcmd, ticcmd, &diff); + * + * // Store in the send queue + * sendobj = &send_queue[maketic % BACKUPTICS]; + * sendobj->active = true; + * sendobj->seq = maketic; + * sendobj->time = I_GetTimeMS(); + * sendobj->cmd = diff; + * + * last_ticcmd = *ticcmd; + * + * // Send to server + * starttic = maketic - settings.extratics; + * endtic = maketic; + * + * if (starttic < 0) + * starttic = 0; + * + * NET_CL_SendTics(starttic, endtic); + */ } -// Parse a SYN packet received back from the server indicating a successful -// connection attempt. +/* + * Parse a SYN packet received back from the server indicating a successful + * connection attempt. + */ static void NET_CL_ParseSYN(net_packet_t *packet) { - printf("NRFD-TODO: \n"); /* - net_protocol_t protocol; - char *server_version; - - server_version = NET_ReadSafeString(packet); - if (server_version == NULL) - { - return; - } - - protocol = NET_ReadProtocol(packet); - if (protocol == NET_PROTOCOL_UNKNOWN) - { - return; - } - - // We are now successfully connected. - client_connection.state = NET_CONN_STATE_CONNECTED; - client_connection.protocol = protocol; - - // Even though we have negotiated a compatible protocol, the game may still - // desync. Chocolate Doom's philosophy makes this unlikely, but if we're - // playing with a forked version, or even against a different version that - // fixes a compatibility issue, we may still have problems. - if (strcmp(server_version, PACKAGE_STRING) != 0) - { - fprintf(stderr, "NET_CL_ParseSYN: This is '%s', but the server is " - "'%s'. It is possible that this mismatch may cause the game " - "to desync.\n", PACKAGE_STRING, server_version); - } - */ + /* + * // NRFD-TODO + * net_protocol_t protocol; + * char *server_version; + * + * server_version = NET_ReadSafeString(packet); + * if (server_version == NULL) + * { + * return; + * } + * + * protocol = NET_ReadProtocol(packet); + * if (protocol == NET_PROTOCOL_UNKNOWN) + * { + * return; + * } + * + * // We are now successfully connected + * client_connection.state = NET_CONN_STATE_CONNECTED; + * client_connection.protocol = protocol; + * + * // Even though we have negotiated a compatible protocol, the game may still + * // desync. Chocolate Doom's philosophy makes this unlikely, but if we're + * // playing with a forked version, or even against a different version that + * // fixes a compatibility issue, we may still have problems. + * if (strcmp(server_version, PACKAGE_STRING) != 0) + * { + * fprintf(stderr, "NET_CL_ParseSYN: This is '%s', but the server is " + * "'%s'. It is possible that this mismatch may cause the game " + * "to desync.\n", + * PACKAGE_STRING, server_version); + * } + */ } -// data received while we are waiting for the game to start - +/* Data received while we are waiting for the game to start. */ static void NET_CL_ParseWaitingData(net_packet_t *packet) { - printf("NRFD-TODO: \n"); /* - net_waitdata_t wait_data; - - if (!NET_ReadWaitData(packet, &wait_data)) - { - // Invalid packet? - return; - } - - if (wait_data.num_players > wait_data.max_players - || wait_data.ready_players > wait_data.num_players - || wait_data.max_players > NET_MAXPLAYERS) - { - // insane data - - return; - } - - if ((wait_data.consoleplayer >= 0 && drone) - || (wait_data.consoleplayer < 0 && !drone) - || (wait_data.consoleplayer >= wait_data.num_players)) - { - // Invalid player number - - return; - } - - memcpy(&net_client_wait_data, &wait_data, sizeof(net_waitdata_t)); - net_client_received_wait_data = true; - */ + /* + * // NRFD-TODO + * net_waitdata_t wait_data; + * + * if (!NET_ReadWaitData(packet, &wait_data)) + * { + * // Invalid packet + * return; + * } + * + * if (wait_data.num_players > wait_data.max_players || wait_data.ready_players > wait_data.num_players || wait_data.max_players > NET_MAXPLAYERS) + * { + * // Insane data + * return; + * } + * + * if ((wait_data.consoleplayer >= 0 && drone) || (wait_data.consoleplayer < 0 && !drone) || (wait_data.consoleplayer >= wait_data.num_players)) + * { + * // Invalid player number + * return; + * } + * + * memcpy(&net_client_wait_data, &wait_data, sizeof(net_waitdata_t)); + * net_client_received_wait_data = true; + */ } static void NET_CL_ParseLaunch(net_packet_t *packet) { - printf("NRFD-TODO: \n"); /* - unsigned int num_players; - - if (client_state != CLIENT_STATE_WAITING_LAUNCH) - { - return; - } - - // The launch packet contains the number of players that will be - // in the game when it starts, so that we can do the startup - // progress indicator (the wait data is unreliable). - - if (!NET_ReadInt8(packet, &num_players)) - { - return; - } - - net_client_wait_data.num_players = num_players; - client_state = CLIENT_STATE_WAITING_START; - */ + /* + * // NRFD-TODO + * unsigned int num_players; + * + * if (client_state != CLIENT_STATE_WAITING_LAUNCH) + * { + * return; + * } + * + * // The launch packet contains the number of players that will be + * // in the game when it starts, so that we can do the startup + * // progress indicator (the wait data is unreliable). + * if (!NET_ReadInt8(packet, &num_players)) + * { + * return; + * } + * + * net_client_wait_data.num_players = num_players; + * client_state = CLIENT_STATE_WAITING_START; + */ } static void NET_CL_ParseGameStart(net_packet_t *packet) { - printf("NRFD-TODO: \n"); /* - if (!NET_ReadSettings(packet, &settings)) - { - return; - } - - if (client_state != CLIENT_STATE_WAITING_START) - { - return; - } - - if (settings.num_players > NET_MAXPLAYERS - || settings.consoleplayer >= (signed int) settings.num_players) - { - // insane values - return; - } - - if ((drone && settings.consoleplayer >= 0) - || (!drone && settings.consoleplayer < 0)) - { - // Invalid player number: must be positive for real players, - // negative for drones - - return; - } - - client_state = CLIENT_STATE_IN_GAME; - - // Clear the receive window - - memset(recvwindow, 0, sizeof(recvwindow)); - recvwindow_start = 0; - memset(&recvwindow_cmd_base, 0, sizeof(recvwindow_cmd_base)); - - // Clear the send queue - - memset(&send_queue, 0x00, sizeof(send_queue)); - */ + /* + * // NRFD-TODO + * if (!NET_ReadSettings(packet, &settings)) + * { + * return; + * } + * + * if (client_state != CLIENT_STATE_WAITING_START) + * { + * return; + * } + * + * if (settings.num_players > NET_MAXPLAYERS || settings.consoleplayer >= (signed int)settings.num_players) + * { + * // Insane values + * return; + * } + * + * if ((drone && settings.consoleplayer >= 0) || (!drone && settings.consoleplayer < 0)) + * { + * // Invalid player number. Must be positive for real players, + * // negative for drones. + * return; + * } + * + * client_state = CLIENT_STATE_IN_GAME; + * + * // Clear the receive window + * memset(recvwindow, 0, sizeof(recvwindow)); + * recvwindow_start = 0; + * memset(&recvwindow_cmd_base, 0, sizeof(recvwindow_cmd_base)); + * + * // Clear the send queue + * memset(&send_queue, 0x00, sizeof(send_queue)); + */ } static void NET_CL_SendResendRequest(int start, int end) { - printf("NRFD-TODO: \n"); /* - net_packet_t *packet; - unsigned int nowtime; - int i; - - //printf("CL: Send resend %i-%i\n", start, end); - - packet = NET_NewPacket(64); - NET_WriteInt16(packet, NET_PACKET_TYPE_GAMEDATA_RESEND); - NET_WriteInt32(packet, start); - NET_WriteInt8(packet, end - start + 1); - NET_Conn_SendPacket(&client_connection, packet); - NET_FreePacket(packet); - - nowtime = I_GetTimeMS(); - - // Save the time we sent the resend request - - for (i=start; i<=end; ++i) - { - int index; - - index = i - recvwindow_start; - - if (index < 0 || index >= BACKUPTICS) - continue; - - recvwindow[index].resend_time = nowtime; - } - */ + /* + * // NRFD-TODO + * net_packet_t *packet; + * unsigned int nowtime; + * int i; + * + * packet = NET_NewPacket(64); + * NET_WriteInt16(packet, NET_PACKET_TYPE_GAMEDATA_RESEND); + * NET_WriteInt32(packet, start); + * NET_WriteInt8(packet, end - start + 1); + * NET_Conn_SendPacket(&client_connection, packet); + * NET_FreePacket(packet); + * + * nowtime = I_GetTimeMS(); + * + * // Save the time we sent the resend request + * for (i = start; i <= end; ++i) + * { + * int index; + * + * index = i - recvwindow_start; + * + * if (index < 0 || index >= BACKUPTICS) + * continue; + * + * recvwindow[index].resend_time = nowtime; + * } + */ } -// Check for expired resend requests - +/* Check for expired resend requests. */ static void NET_CL_CheckResends(void) { - printf("NRFD-TODO: \n"); /* - int i; - int resend_start, resend_end; - unsigned int nowtime; - - nowtime = I_GetTimeMS(); - - resend_start = -1; - resend_end = -1; - - for (i=0; iactive - && recvobj->resend_time != 0 - && nowtime > recvobj->resend_time + 300; - - if (need_resend) - { - // Start a new run of resend tics? - - if (resend_start < 0) - { - resend_start = i; - } - - resend_end = i; - } - else - { - if (resend_start >= 0) - { - // End of a run of resend tics - - //printf("CL: resend request timed out: %i-%i\n", resend_start, resend_end); - NET_CL_SendResendRequest(recvwindow_start + resend_start, - recvwindow_start + resend_end); - - resend_start = -1; - } - } - } - - if (resend_start >= 0) - { - //printf("CL: resend request timed out: %i-%i\n", resend_start, resend_end); - NET_CL_SendResendRequest(recvwindow_start + resend_start, - recvwindow_start + resend_end); - } - - // We have received some data from the server and not acknowledged - // it yet. Normally this gets acknowledged when we send our game - // data, but if the client is a drone we need to do this. - - if (need_to_acknowledge && nowtime - gamedata_recv_time > 200) - { - NET_CL_SendGameDataACK(); - } - */ + /* + * // NRFD-TODO + * int i; + * int resend_start, resend_end; + * unsigned int nowtime; + * + * nowtime = I_GetTimeMS(); + * + * resend_start = -1; + * resend_end = -1; + * + * for (i = 0; i < BACKUPTICS; ++i) + * { + * net_server_recv_t *recvobj; + * boolean need_resend; + * + * recvobj = &recvwindow[i]; + * + * // If need_resend is true, this tic needs another retransmit + * // request (300ms timeout). + * need_resend = !recvobj->active && recvobj->resend_time != 0 && nowtime > recvobj->resend_time + 300; + * + * if (need_resend) + * { + * // Start a new run of resend tics + * if (resend_start < 0) + * { + * resend_start = i; + * } + * + * resend_end = i; + * } + * else + * { + * if (resend_start >= 0) + * { + * // End of a run of resend tics + * NET_CL_SendResendRequest(recvwindow_start + resend_start, + * recvwindow_start + resend_end); + * + * resend_start = -1; + * } + * } + * } + * + * if (resend_start >= 0) + * { + * NET_CL_SendResendRequest(recvwindow_start + resend_start, + * recvwindow_start + resend_end); + * } + * + * // We have received some data from the server and not acknowledged + * // it yet. Normally this gets acknowledged when we send our game + * // data, but if the client is a drone we need to do this. + * if (need_to_acknowledge && nowtime - gamedata_recv_time > 200) + * { + * NET_CL_SendGameDataACK(); + * } + */ } - -// Parsing of NET_PACKET_TYPE_GAMEDATA packets -// (packets containing the actual ticcmd data) - +/* + * Parsing of NET_PACKET_TYPE_GAMEDATA packets + * (packets containing the actual ticcmd data). + */ static void NET_CL_ParseGameData(net_packet_t *packet) { - printf("NRFD-TODO: \n"); /* - net_server_recv_t *recvobj; - unsigned int seq, num_tics; - unsigned int nowtime; - int resend_start, resend_end; - size_t i; - int index; - - // Read header - - if (!NET_ReadInt8(packet, &seq) - || !NET_ReadInt8(packet, &num_tics)) - { - return; - } - - nowtime = I_GetTimeMS(); - - // Whatever happens, we now need to send an acknowledgement of our - // current receive point. - - if (!need_to_acknowledge) - { - need_to_acknowledge = true; - gamedata_recv_time = nowtime; - } - - // Expand byte value into the full tic number - - seq = NET_CL_ExpandTicNum(seq); - - for (i=0; i= BACKUPTICS) - { - // Out of range of the recv window - - continue; - } - - // Store in the receive window - - recvobj = &recvwindow[index]; - - recvobj->active = true; - recvobj->cmd = cmd; - } - - // Has this been received out of sequence, ie. have we not received - // all tics before the first tic in this packet? If so, send a - // resend request. - - //printf("CL: %p: %i\n", client, seq); - - resend_end = seq - recvwindow_start; - - if (resend_end <= 0) - return; - - if (resend_end >= BACKUPTICS) - resend_end = BACKUPTICS - 1; - - index = resend_end - 1; - resend_start = resend_end; - - while (index >= 0) - { - recvobj = &recvwindow[index]; - - if (recvobj->active) - { - // ended our run of unreceived tics - - break; - } - - if (recvobj->resend_time != 0) - { - // Already sent a resend request for this tic - - break; - } - - resend_start = index; - --index; - } - - // Possibly send a resend request - - if (resend_start < resend_end) - { - NET_CL_SendResendRequest(recvwindow_start + resend_start, - recvwindow_start + resend_end - 1); - } - */ + /* + * // NRFD-TODO + * net_server_recv_t *recvobj; + * unsigned int seq, num_tics; + * unsigned int nowtime; + * int resend_start, resend_end; + * size_t i; + * int index; + * + * // Read header + * if (!NET_ReadInt8(packet, &seq) || !NET_ReadInt8(packet, &num_tics)) + * { + * return; + * } + * + * nowtime = I_GetTimeMS(); + * + * // Whatever happens, we now need to send an acknowledgement of our + * // current receive point. + * if (!need_to_acknowledge) + * { + * need_to_acknowledge = true; + * gamedata_recv_time = nowtime; + * } + * + * // Expand byte value into the full tic number + * seq = NET_CL_ExpandTicNum(seq); + * + * for (i = 0; i < num_tics; ++i) + * { + * net_full_ticcmd_t cmd; + * + * index = seq - recvwindow_start + i; + * + * if (!NET_ReadFullTiccmd(packet, &cmd, settings.lowres_turn)) + * { + * return; + * } + * + * if (index < 0 || index >= BACKUPTICS) + * { + * // Out of range of the recv window + * continue; + * } + * + * // Store in the receive window + * recvobj = &recvwindow[index]; + * + * recvobj->active = true; + * recvobj->cmd = cmd; + * } + * + * // Has this been received out of sequence, i.e. have we not received + * // all tics before the first tic in this packet. If so, send a + * // resend request. + * resend_end = seq - recvwindow_start; + * + * if (resend_end <= 0) + * return; + * + * if (resend_end >= BACKUPTICS) + * resend_end = BACKUPTICS - 1; + * + * index = resend_end - 1; + * resend_start = resend_end; + * + * while (index >= 0) + * { + * recvobj = &recvwindow[index]; + * + * if (recvobj->active) + * { + * // Ended our run of unreceived tics + * break; + * } + * + * if (recvobj->resend_time != 0) + * { + * // Already sent a resend request for this tic + * break; + * } + * + * resend_start = index; + * --index; + * } + * + * // Possibly send a resend request + * if (resend_start < resend_end) + * { + * NET_CL_SendResendRequest(recvwindow_start + resend_start, + * recvwindow_start + resend_end - 1); + * } + */ } -// Parse a resend request from the server due to a dropped packet - +/* Parse a resend request from the server due to a dropped packet. */ static void NET_CL_ParseResendRequest(net_packet_t *packet) { - printf("NRFD-TODO: \n"); /* - static unsigned int start; - static unsigned int end; - static unsigned int num_tics; - - if (drone) - { - // Drones don't send gamedata. - - return; - } - - if (!NET_ReadInt32(packet, &start) - || !NET_ReadInt8(packet, &num_tics)) - { - return; - } - - end = start + num_tics - 1; - - //printf("requested resend %i-%i .. ", start, end); - - // Check we have the tics being requested. If not, reduce the - // window of tics to only what we have. - - while (start <= end - && (!send_queue[start % BACKUPTICS].active - || send_queue[start % BACKUPTICS].seq != start)) - { - ++start; - } - - while (start <= end - && (!send_queue[end % BACKUPTICS].active - || send_queue[end % BACKUPTICS].seq != end)) - { - --end; - } - - //printf("%i-%i\n", start, end); - - // Resend those tics - - if (start <= end) - { - //printf("CL: resend %i-%i\n", start, start+num_tics-1); - - NET_CL_SendTics(start, end); - } - */ + /* + * // NRFD-TODO + * static unsigned int start; + * static unsigned int end; + * static unsigned int num_tics; + * + * if (drone) + * { + * // Drones don't send gamedata + * return; + * } + * + * if (!NET_ReadInt32(packet, &start) || !NET_ReadInt8(packet, &num_tics)) + * { + * return; + * } + * + * end = start + num_tics - 1; + * + * // Check we have the tics being requested. If not, reduce the + * // window of tics to only what we have. + * while (start <= end && (!send_queue[start % BACKUPTICS].active || send_queue[start % BACKUPTICS].seq != start)) + * { + * ++start; + * } + * + * while (start <= end && (!send_queue[end % BACKUPTICS].active || send_queue[end % BACKUPTICS].seq != end)) + * { + * --end; + * } + * + * // Resend those tics + * if (start <= end) + * { + * NET_CL_SendTics(start, end); + * } + */ } -// Console message that the server wants the client to print - +/* Console message that the server wants the client to print. */ static void NET_CL_ParseConsoleMessage(net_packet_t *packet) { - printf("NRFD-TODO: \n"); /* - char *msg; - - msg = NET_ReadSafeString(packet); - - if (msg == NULL) - { - return; - } - - printf("Message from server:\n%s\n", msg); - */ + /* + * // NRFD-TODO + * char *msg; + * + * msg = NET_ReadSafeString(packet); + * + * if (msg == NULL) + * { + * return; + * } + * + * printf("Message from server:\n%s\n", msg); + */ } -// parse a received packet - +/* Parse a received packet. */ static void NET_CL_ParsePacket(net_packet_t *packet) { - printf("NRFD-TODO: \n"); /* - unsigned int packet_type; - - if (!NET_ReadInt16(packet, &packet_type)) - { - return; - } - - if (NET_Conn_Packet(&client_connection, packet, &packet_type)) - { - // Packet eaten by the common connection code - } - else - { - switch (packet_type) - { - case NET_PACKET_TYPE_SYN: - NET_CL_ParseSYN(packet); - break; - - case NET_PACKET_TYPE_WAITING_DATA: - NET_CL_ParseWaitingData(packet); - break; - - case NET_PACKET_TYPE_LAUNCH: - NET_CL_ParseLaunch(packet); - break; - - case NET_PACKET_TYPE_GAMESTART: - NET_CL_ParseGameStart(packet); - break; - - case NET_PACKET_TYPE_GAMEDATA: - NET_CL_ParseGameData(packet); - break; - - case NET_PACKET_TYPE_GAMEDATA_RESEND: - NET_CL_ParseResendRequest(packet); - break; - - case NET_PACKET_TYPE_CONSOLE_MESSAGE: - NET_CL_ParseConsoleMessage(packet); - break; - - default: - break; - } - } - */ + /* + * // NRFD-TODO + * unsigned int packet_type; + * + * if (!NET_ReadInt16(packet, &packet_type)) + * { + * return; + * } + * + * if (NET_Conn_Packet(&client_connection, packet, &packet_type)) + * { + * // Packet eaten by the common connection code + * } + * else + * { + * switch (packet_type) + * { + * case NET_PACKET_TYPE_SYN: + * NET_CL_ParseSYN(packet); + * break; + * + * case NET_PACKET_TYPE_WAITING_DATA: + * NET_CL_ParseWaitingData(packet); + * break; + * + * case NET_PACKET_TYPE_LAUNCH: + * NET_CL_ParseLaunch(packet); + * break; + * + * case NET_PACKET_TYPE_GAMESTART: + * NET_CL_ParseGameStart(packet); + * break; + * + * case NET_PACKET_TYPE_GAMEDATA: + * NET_CL_ParseGameData(packet); + * break; + * + * case NET_PACKET_TYPE_GAMEDATA_RESEND: + * NET_CL_ParseResendRequest(packet); + * break; + * + * case NET_PACKET_TYPE_CONSOLE_MESSAGE: + * NET_CL_ParseConsoleMessage(packet); + * break; + * + * default: + * break; + * } + * } + */ } -// "Run" the client code: check for new packets, send packets as -// needed - +/* "Run" the client code, check for new packets, send packets as needed. */ void NET_CL_Run(void) { - N_ldbg("NRFD-TODO: NET_CL_Run\n"); /* - net_addr_t *addr; - net_packet_t *packet; - - if (!net_client_connected) - { - return; - } - - while (NET_RecvPacket(client_context, &addr, &packet)) - { - // only accept packets from the server - - if (addr == server_addr) - { - NET_CL_ParsePacket(packet); - } - else - { - NET_FreeAddress(addr); - } - - NET_FreePacket(packet); - } - - // Run the common connection code to send any packets as needed - - NET_Conn_Run(&client_connection); - - if (client_connection.state == NET_CONN_STATE_DISCONNECTED - || client_connection.state == NET_CONN_STATE_DISCONNECTED_SLEEP) - { - NET_CL_Disconnected(); - - NET_CL_Shutdown(); - } - - net_waiting_for_launch = - client_connection.state == NET_CONN_STATE_CONNECTED - && client_state == CLIENT_STATE_WAITING_LAUNCH; - - if (client_state == CLIENT_STATE_IN_GAME) - { - // Possibly advance the receive window - - NET_CL_AdvanceWindow(); - - // Check if our resend requests have timed out - - NET_CL_CheckResends(); - } - */ + /* + * // NRFD-TODO + * net_addr_t *addr; + * net_packet_t *packet; + * + * if (!net_client_connected) + * { + * return; + * } + * + * while (NET_RecvPacket(client_context, &addr, &packet)) + * { + * // Only accept packets from the server + * if (addr == server_addr) + * { + * NET_CL_ParsePacket(packet); + * } + * else + * { + * NET_FreeAddress(addr); + * } + * + * NET_FreePacket(packet); + * } + * + * // Run the common connection code to send any packets as needed + * NET_Conn_Run(&client_connection); + * + * if (client_connection.state == NET_CONN_STATE_DISCONNECTED || client_connection.state == NET_CONN_STATE_DISCONNECTED_SLEEP) + * { + * NET_CL_Disconnected(); + * + * NET_CL_Shutdown(); + * } + * + * net_waiting_for_launch = client_connection.state == NET_CONN_STATE_CONNECTED && client_state == CLIENT_STATE_WAITING_LAUNCH; + * + * if (client_state == CLIENT_STATE_IN_GAME) + * { + * // Possibly advance the receive window + * NET_CL_AdvanceWindow(); + * + * // Check if our resend requests have timed out + * NET_CL_CheckResends(); + * } + */ } static void NET_CL_SendSYN(net_connect_data_t *data) { - printf("NRFD-TODO: \n"); /* + /* + * // NRFD-TODO net_packet_t *packet; packet = NET_NewPacket(10); @@ -1008,100 +920,91 @@ static void NET_CL_SendSYN(net_connect_data_t *data) */ } -// Connect to a server +/* Connect to a server. */ boolean NET_CL_Connect(net_addr_t *addr, net_connect_data_t *data) { - printf("NRFD-TODO: \n"); return false; /* - int start_time; - int last_send_time; - - server_addr = addr; - - memcpy(net_local_wad_sha1sum, data->wad_sha1sum, sizeof(sha1_digest_t)); - memcpy(net_local_deh_sha1sum, data->deh_sha1sum, sizeof(sha1_digest_t)); - net_local_is_freedoom = data->is_freedoom; - - // create a new network I/O context and add just the - // necessary module - - client_context = NET_NewContext(); - - // initialize module for client mode - - if (!addr->module->InitClient()) - { - return false; - } - - NET_AddModule(client_context, addr->module); - - net_client_connected = true; - net_client_received_wait_data = false; - - // Initialize connection - - NET_Conn_InitClient(&client_connection, addr, NET_PROTOCOL_UNKNOWN); - - // try to connect - - start_time = I_GetTimeMS(); - last_send_time = -1; - - while (client_connection.state == NET_CONN_STATE_CONNECTING) - { - int nowtime = I_GetTimeMS(); - - // Send a SYN packet every second. - - if (nowtime - last_send_time > 1000 || last_send_time < 0) - { - NET_CL_SendSYN(data); - last_send_time = nowtime; - } - - // time out after 5 seconds - - if (nowtime - start_time > 5000) - { - break; - } - - // run client code - - NET_CL_Run(); - - // run the server, just incase we are doing a loopback - // connect - - NET_SV_Run(); - - // Don't hog the CPU - - I_Sleep(1); - } - - if (client_connection.state == NET_CONN_STATE_CONNECTED) - { - // connected ok! - - client_state = CLIENT_STATE_WAITING_LAUNCH; - drone = data->drone; - - return true; - } - else - { - // failed to connect - - NET_CL_Shutdown(); - - return false; - } - */ + return false; + + /* + * // NRFD-TODO + * int start_time; + * int last_send_time; + * + * server_addr = addr; + * + * memcpy(net_local_wad_sha1sum, data->wad_sha1sum, sizeof(sha1_digest_t)); + * memcpy(net_local_deh_sha1sum, data->deh_sha1sum, sizeof(sha1_digest_t)); + * net_local_is_freedoom = data->is_freedoom; + * + * // Create a new network I/O context and add just the + * // necessary module. + * client_context = NET_NewContext(); + * + * // Initialize module for client mode + * if (!addr->module->InitClient()) + * { + * return false; + * } + * + * NET_AddModule(client_context, addr->module); + * + * net_client_connected = true; + * net_client_received_wait_data = false; + * + * // Initialize connection + * + * NET_Conn_InitClient(&client_connection, addr, NET_PROTOCOL_UNKNOWN); + * + * // Try to connect + * start_time = I_GetTimeMS(); + * last_send_time = -1; + * + * while (client_connection.state == NET_CONN_STATE_CONNECTING) + * { + * int nowtime = I_GetTimeMS(); + * + * // Send a SYN packet every second + * if (nowtime - last_send_time > 1000 || last_send_time < 0) + * { + * NET_CL_SendSYN(data); + * last_send_time = nowtime; + * } + * + * // Time out after 5 seconds + * if (nowtime - start_time > 5000) + * { + * break; + * } + * + * // Run client code + * NET_CL_Run(); + * + * // Run the server, just incase we are doing a loopback connect + * NET_SV_Run(); + * + * // Don't hog the CPU + * I_Sleep(1); + * } + * + * if (client_connection.state == NET_CONN_STATE_CONNECTED) + * { + * // Connected ok + * client_state = CLIENT_STATE_WAITING_LAUNCH; + * drone = data->drone; + * + * return true; + * } + * else + * { + * // Failed to connect + * NET_CL_Shutdown(); + * + * return false; + * } + */ } -// read game settings received from server - +/* Read game settings received from server. */ boolean NET_CL_GetSettings(net_gamesettings_t *_settings) { if (client_state != CLIENT_STATE_IN_GAME) @@ -1114,67 +1017,64 @@ boolean NET_CL_GetSettings(net_gamesettings_t *_settings) return true; } -// disconnect from the server - +/* Disconnect from the server. */ void NET_CL_Disconnect(void) { - printf("NRFD-TODO: \n"); /* - int start_time; - - if (!net_client_connected) - { - return; - } - - NET_Conn_Disconnect(&client_connection); - - start_time = I_GetTimeMS(); - - while (client_connection.state != NET_CONN_STATE_DISCONNECTED - && client_connection.state != NET_CONN_STATE_DISCONNECTED_SLEEP) - { - if (I_GetTimeMS() - start_time > 5000) - { - // time out after 5 seconds - - client_state = CLIENT_STATE_WAITING_START; - - fprintf(stderr, "NET_CL_Disconnect: Timeout while disconnecting from server\n"); - break; - } - - NET_CL_Run(); - NET_SV_Run(); - - I_Sleep(1); - } - - // Finished sending disconnect packets, etc. - - NET_CL_Shutdown(); - */ + /* + * // NRFD-TODO + * int start_time; + * + * if (!net_client_connected) + * { + * return; + * } + * + * NET_Conn_Disconnect(&client_connection); + * + * start_time = I_GetTimeMS(); + * + * while (client_connection.state != NET_CONN_STATE_DISCONNECTED && client_connection.state != NET_CONN_STATE_DISCONNECTED_SLEEP) + * { + * if (I_GetTimeMS() - start_time > 5000) + * { + * // Time out after 5 seconds + * client_state = CLIENT_STATE_WAITING_START; + * + * fprintf(stderr, "NET_CL_Disconnect: Timeout while disconnecting from server\n"); + * break; + * } + * + * NET_CL_Run(); + * NET_SV_Run(); + * + * I_Sleep(1); + * } + * + * // Finished sending disconnect packets, etc. + * NET_CL_Shutdown(); + */ } void NET_CL_Init(void) { - // Try to set from the USER and USERNAME environment variables - // Otherwise, fallback to "Player" - /*NRFD-EXCLUDE: - if (net_player_name == NULL) - net_player_name = getenv("USER"); - if (net_player_name == NULL) - net_player_name = getenv("USERNAME"); - - // On Windows, environment variables are in OEM codepage - // encoding, so convert to UTF8: - -#ifdef _WIN32 - if (net_player_name != NULL) - { - net_player_name = M_OEMToUTF8(net_player_name); - } -#endif - */ + /* + * // NRFD-EXCLUDE + * // Try to set from the USER and USERNAME environment variables. + * // Otherwise, fallback to "Player". + * if (net_player_name == NULL) + * net_player_name = getenv("USER"); + * if (net_player_name == NULL) + * net_player_name = getenv("USERNAME"); + * + * // On Windows, environment variables are in OEM codepage + * // encoding, so convert to UTF8. + * #ifdef _WIN32 + * if (net_player_name != NULL) + * { + * net_player_name = M_OEMToUTF8(net_player_name); + * } + * #endif + */ if (net_player_name == NULL) net_player_name = "Player"; @@ -1187,6 +1087,8 @@ void NET_Init(void) void NET_BindVariables(void) { - printf("NRFD-TODO: NET_BindVariables\n"); - // M_BindStringVariable("player_name", &net_player_name); + /* + * // NRFD-TODO + * M_BindStringVariable("player_name", &net_player_name); + */ } diff --git a/zephyrdoom/src/net_client.h b/zephyrdoom/src/net_client.h index 31dc9e4..8e4d550 100644 --- a/zephyrdoom/src/net_client.h +++ b/zephyrdoom/src/net_client.h @@ -1,18 +1,19 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// Network client code -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Network client code + */ #ifndef NET_CLIENT_H #define NET_CLIENT_H @@ -49,4 +50,4 @@ extern unsigned int net_local_is_freedoom; extern boolean drone; -#endif /* #ifndef NET_CLIENT_H */ +#endif /* NET_CLIENT_H */ diff --git a/zephyrdoom/src/net_common.c b/zephyrdoom/src/net_common.c index 7268bc9..fe116eb 100644 --- a/zephyrdoom/src/net_common.c +++ b/zephyrdoom/src/net_common.c @@ -1,18 +1,19 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// Common code shared between the client and server -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Common code shared between the client and server + */ #include #include @@ -28,16 +29,13 @@ #include "net_packet.h" #include "net_structrw.h" -// connections time out after 30 seconds - +/* Connections time out after 30 seconds. */ #define CONNECTION_TIMEOUT_LEN 30 -// maximum time between sending packets - +/* Maximum time between sending packets. */ #define KEEPALIVE_PERIOD 1 -// reliable packet that is guaranteed to reach its destination - +/* Reliable packet that is guaranteed to reach its destination. */ struct net_reliable_packet_s { net_packet_t *packet; @@ -58,8 +56,7 @@ static void NET_Conn_Init(net_connection_t *conn, net_addr_t *addr, conn->reliable_recv_seq = 0; } -// Initialize as a client connection - +/* Initialize as a client connection. */ void NET_Conn_InitClient(net_connection_t *conn, net_addr_t *addr, net_protocol_t protocol) { @@ -67,8 +64,7 @@ void NET_Conn_InitClient(net_connection_t *conn, net_addr_t *addr, conn->state = NET_CONN_STATE_CONNECTING; } -// Initialize as a server connection - +/* Initialize as a server connection. */ void NET_Conn_InitServer(net_connection_t *conn, net_addr_t *addr, net_protocol_t protocol) { @@ -76,10 +72,11 @@ void NET_Conn_InitServer(net_connection_t *conn, net_addr_t *addr, conn->state = NET_CONN_STATE_CONNECTED; } -// Send a packet to a connection -// All packets should be sent through this interface, as it maintains the -// keepalive_send_time counter. - +/* + * Send a packet to a connection + * All packets should be sent through this interface, as it maintains the + * keepalive_send_time counter. + */ void NET_Conn_SendPacket(net_connection_t *conn, net_packet_t *packet) { conn->keepalive_send_time = I_GetTimeMS(); @@ -90,9 +87,7 @@ static void NET_Conn_ParseDisconnect(net_connection_t *conn, net_packet_t *packe { net_packet_t *reply; - // Other end wants to disconnect - // Send a DISCONNECT_ACK reply. - + /* Other end wants to disconnect. Send a DISCONNECT_ACK reply. */ reply = NET_NewPacket(10); NET_WriteInt16(reply, NET_PACKET_TYPE_DISCONNECT_ACK); NET_Conn_SendPacket(conn, reply); @@ -104,17 +99,16 @@ static void NET_Conn_ParseDisconnect(net_connection_t *conn, net_packet_t *packe conn->disconnect_reason = NET_DISCONNECT_REMOTE; } -// Parse a DISCONNECT_ACK packet - +/* Parse a DISCONNECT_ACK packet. */ static void NET_Conn_ParseDisconnectACK(net_connection_t *conn, net_packet_t *packet) { - if (conn->state == NET_CONN_STATE_DISCONNECTING) { - // We have received an acknowledgement to our disconnect - // request. We have been disconnected successfully. - + /* + * We have received an acknowledgement to our disconnect + * request. We have been disconnected successfully. + */ conn->state = NET_CONN_STATE_DISCONNECTED; conn->disconnect_reason = NET_DISCONNECT_LOCAL; conn->last_send_time = -1; @@ -134,8 +128,7 @@ static void NET_Conn_ParseReject(net_connection_t *conn, net_packet_t *packet) if (conn->state == NET_CONN_STATE_CONNECTING) { - // rejected by server - + /* Rejected by server */ conn->state = NET_CONN_STATE_DISCONNECTED; conn->disconnect_reason = NET_DISCONNECT_REMOTE; @@ -157,15 +150,12 @@ static void NET_Conn_ParseReliableACK(net_connection_t *conn, net_packet_t *pack return; } - // Is this an acknowledgement for the first packet in the list? - + /* Is this an acknowledgement for the first packet in the list */ if (seq == (unsigned int)((conn->reliable_packets->seq + 1) & 0xff)) { net_reliable_packet_t *rp; - // Discard it, then. - // Unlink from the list. - + /* Discard it, then. Unlink from the list. */ rp = conn->reliable_packets; conn->reliable_packets = rp->next; @@ -174,10 +164,11 @@ static void NET_Conn_ParseReliableACK(net_connection_t *conn, net_packet_t *pack } } -// Process the header of a reliable packet -// -// Returns true if the packet should be discarded (incorrect sequence) - +/* + * Process the header of a reliable packet. + * + * Returns true if the packet should be discarded (incorrect sequence). + */ static boolean NET_Conn_ReliablePacket(net_connection_t *conn, net_packet_t *packet) { @@ -185,8 +176,7 @@ static boolean NET_Conn_ReliablePacket(net_connection_t *conn, net_packet_t *reply; boolean result; - // Read the sequence number - + /* Read the sequence number */ if (!NET_ReadInt8(packet, &seq)) { return true; @@ -194,28 +184,29 @@ static boolean NET_Conn_ReliablePacket(net_connection_t *conn, if (seq != (unsigned int)(conn->reliable_recv_seq & 0xff)) { - // This is not the next expected packet in the sequence! - // - // Discard the packet. If we were smart, we would use a proper - // sliding window protocol to do this, but I'm lazy. - + /* + * This is not the next expected packet in the sequence! + * + * Discard the packet. If we were smart, we would use a proper + * sliding window protocol to do this, but I'm lazy. + */ result = true; } else { - // Now we can receive the next packet in the sequence. - + /* Now we can receive the next packet in the sequence */ conn->reliable_recv_seq = (conn->reliable_recv_seq + 1) & 0xff; result = false; } - // Send an acknowledgement - - // Note: this is braindead. It would be much more sensible to - // include this in the next packet, rather than the overhead of - // sending a complete packet just for one byte of information. - + /* + * Send an acknowledgement. + * + * This is braindead. It would be much more sensible to + * include this in the next packet, rather than the overhead of + * sending a complete packet just for one byte of information. + */ reply = NET_NewPacket(10); NET_WriteInt16(reply, NET_PACKET_TYPE_RELIABLE_ACK); @@ -228,64 +219,58 @@ static boolean NET_Conn_ReliablePacket(net_connection_t *conn, return result; } -// Process a packet received by the server -// -// Returns true if eaten by common code - +/* + * Process a packet received by the server. + * + * Returns true if eaten by common code. + */ boolean NET_Conn_Packet(net_connection_t *conn, net_packet_t *packet, unsigned int *packet_type) { conn->keepalive_recv_time = I_GetTimeMS(); - // Is this a reliable packet? - + /* Is this a reliable packet */ if (*packet_type & NET_RELIABLE_PACKET) { if (NET_Conn_ReliablePacket(conn, packet)) { - // Invalid packet: eat it. - + /* Invalid packet - eat it */ return true; } - // Remove the reliable bit - + /* Remove the reliable bit */ *packet_type &= ~NET_RELIABLE_PACKET; } switch (*packet_type) { - case NET_PACKET_TYPE_DISCONNECT: - NET_Conn_ParseDisconnect(conn, packet); - break; - case NET_PACKET_TYPE_DISCONNECT_ACK: - NET_Conn_ParseDisconnectACK(conn, packet); - break; - case NET_PACKET_TYPE_KEEPALIVE: - // No special action needed. - break; - case NET_PACKET_TYPE_REJECTED: - NET_Conn_ParseReject(conn, packet); - break; - case NET_PACKET_TYPE_RELIABLE_ACK: - NET_Conn_ParseReliableACK(conn, packet); - break; - default: - // Not a common packet - - return false; + case NET_PACKET_TYPE_DISCONNECT: + NET_Conn_ParseDisconnect(conn, packet); + break; + case NET_PACKET_TYPE_DISCONNECT_ACK: + NET_Conn_ParseDisconnectACK(conn, packet); + break; + case NET_PACKET_TYPE_KEEPALIVE: + /* No special action needed */ + break; + case NET_PACKET_TYPE_REJECTED: + NET_Conn_ParseReject(conn, packet); + break; + case NET_PACKET_TYPE_RELIABLE_ACK: + NET_Conn_ParseReliableACK(conn, packet); + break; + default: + /* Not a common packet */ + return false; } - // We found a packet that we found interesting, and ate it. - + /* We found a packet that we found interesting, and ate it */ return true; } void NET_Conn_Disconnect(net_connection_t *conn) { - if (conn->state != NET_CONN_STATE_DISCONNECTED - && conn->state != NET_CONN_STATE_DISCONNECTING - && conn->state != NET_CONN_STATE_DISCONNECTED_SLEEP) + if (conn->state != NET_CONN_STATE_DISCONNECTED && conn->state != NET_CONN_STATE_DISCONNECTING && conn->state != NET_CONN_STATE_DISCONNECTED_SLEEP) { conn->state = NET_CONN_STATE_DISCONNECTING; conn->disconnect_reason = NET_DISCONNECT_LOCAL; @@ -303,57 +288,54 @@ void NET_Conn_Run(net_connection_t *conn) if (conn->state == NET_CONN_STATE_CONNECTED) { - // Check the keepalive counters - + /* Check the keepalive counters */ if (nowtime - conn->keepalive_recv_time > CONNECTION_TIMEOUT_LEN * 1000) { - // Haven't received any packets from the other end in a long - // time. Assume disconnected. - + /* + * Haven't received any packets from the other end in a long + * time. Assume disconnected. + */ conn->state = NET_CONN_STATE_DISCONNECTED; conn->disconnect_reason = NET_DISCONNECT_TIMEOUT; } if (nowtime - conn->keepalive_send_time > KEEPALIVE_PERIOD * 1000) { - // We have not sent anything in a long time. - // Send a keepalive. - + /* + * We have not sent anything in a long time. + * Send a keepalive. + */ packet = NET_NewPacket(10); NET_WriteInt16(packet, NET_PACKET_TYPE_KEEPALIVE); NET_Conn_SendPacket(conn, packet); NET_FreePacket(packet); } - // Check the reliable packet list. Has the first packet in the - // list timed out? - // - // NB. This is braindead, we have a fixed time of one second. - - if (conn->reliable_packets != NULL - && (conn->reliable_packets->last_send_time < 0 - || nowtime - conn->reliable_packets->last_send_time > 1000)) + /* + * Check the reliable packet list. Has the first packet in the + * list timed out. + * + * This is braindead, we have a fixed time of one second. + */ + if (conn->reliable_packets != NULL && (conn->reliable_packets->last_send_time < 0 || nowtime - conn->reliable_packets->last_send_time > 1000)) { - // Packet timed out, time to resend - + /* Packet timed out, time to resend */ NET_Conn_SendPacket(conn, conn->reliable_packets->packet); conn->reliable_packets->last_send_time = nowtime; } } else if (conn->state == NET_CONN_STATE_DISCONNECTING) { - // Waiting for a reply to our DISCONNECT request. - - if (conn->last_send_time < 0 - || nowtime - conn->last_send_time > 1000) + /* Waiting for a reply to our DISCONNECT request */ + if (conn->last_send_time < 0 || nowtime - conn->last_send_time > 1000) { - // it has been a second since the last disconnect packet - // was sent, and still no reply. - + /* + * It has been a second since the last disconnect packet + * was sent, and still no reply. + */ if (conn->num_retries < MAX_RETRIES) { - // send another disconnect - + /* Send another disconnect */ packet = NET_NewPacket(10); NET_WriteInt16(packet, NET_PACKET_TYPE_DISCONNECT); NET_Conn_SendPacket(conn, packet); @@ -364,9 +346,7 @@ void NET_Conn_Run(net_connection_t *conn) } else { - // No more retries allowed. - // Force disconnect. - + /* No more retries allowed.Force disconnect. */ conn->state = NET_CONN_STATE_DISCONNECTED; conn->disconnect_reason = NET_DISCONNECT_LOCAL; } @@ -374,13 +354,13 @@ void NET_Conn_Run(net_connection_t *conn) } else if (conn->state == NET_CONN_STATE_DISCONNECTED_SLEEP) { - // We are disconnected, waiting in case we need to send - // a DISCONNECT_ACK to the server again. - + /* + * We are disconnected, waiting in case we need to send + * a DISCONNECT_ACK to the server again. + */ if (nowtime - conn->last_send_time > 5000) { - // Idle for 5 seconds, switch state - + /* Idle for 5 seconds, switch state */ conn->state = NET_CONN_STATE_DISCONNECTED; conn->disconnect_reason = NET_DISCONNECT_REMOTE; } @@ -393,18 +373,15 @@ net_packet_t *NET_Conn_NewReliable(net_connection_t *conn, int packet_type) net_reliable_packet_t *rp; net_reliable_packet_t **listend; - // Generate a packet with the right header - + /* Generate a packet with the right header */ packet = NET_NewPacket(100); NET_WriteInt16(packet, packet_type | NET_RELIABLE_PACKET); - // write the low byte of the send sequence number - + /* Write the low byte of the send sequence number */ NET_WriteInt8(packet, conn->reliable_send_seq & 0xff); - // Add to the list of reliable packets - + /* Add to the list of reliable packets */ rp = malloc(sizeof(net_reliable_packet_t)); rp->packet = packet; rp->next = NULL; @@ -413,22 +390,22 @@ net_packet_t *NET_Conn_NewReliable(net_connection_t *conn, int packet_type) for (listend = &conn->reliable_packets; *listend != NULL; - listend = &((*listend)->next)); + listend = &((*listend)->next)) + ; *listend = rp; - // Count along the sequence - + /* Count along the sequence */ conn->reliable_send_seq = (conn->reliable_send_seq + 1) & 0xff; - // Finished - + /* Finished */ return packet; } -// Used to expand the least significant byte of a tic number into -// the full tic number, from the current tic number - +/* + * Used to expand the least significant byte of a tic number into + * the full tic number, from the current tic number. + */ unsigned int NET_ExpandTicNum(unsigned int relative, unsigned int b) { unsigned int l, h; @@ -447,8 +424,7 @@ unsigned int NET_ExpandTicNum(unsigned int relative, unsigned int b) return result; } -// Check that game settings are valid - +/* Check that game settings are valid. */ boolean NET_ValidGameSettings(GameMode_t mode, GameMission_t mission, net_gamesettings_t *settings) { diff --git a/zephyrdoom/src/net_common.h b/zephyrdoom/src/net_common.h index c155b97..6e0d686 100644 --- a/zephyrdoom/src/net_common.h +++ b/zephyrdoom/src/net_common.h @@ -1,18 +1,19 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// Common code shared between the client and server -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Common code shared between the client and server + */ #ifndef NET_COMMON_H #define NET_COMMON_H @@ -23,43 +24,39 @@ typedef enum { - // Client has sent a SYN, is waiting for a SYN in response. + /* Client has sent a SYN, is waiting for a SYN in response */ NET_CONN_STATE_CONNECTING, - // Successfully connected. + /* Successfully connected */ NET_CONN_STATE_CONNECTED, - // Sent a DISCONNECT packet, waiting for a DISCONNECT_ACK reply + /* Sent a DISCONNECT packet, waiting for a DISCONNECT_ACK reply */ NET_CONN_STATE_DISCONNECTING, - // Client successfully disconnected + /* Client successfully disconnected */ NET_CONN_STATE_DISCONNECTED, - // We are disconnected, but in a sleep state, waiting for several - // seconds. This is in case the DISCONNECT_ACK we sent failed - // to arrive, and we need to send another one. We keep this as - // a valid connection for a few seconds until we are sure that - // the other end has successfully disconnected as well. + /* + * We are disconnected, but in a sleep state, waiting for several + * seconds. This is in case the DISCONNECT_ACK we sent failed + * to arrive, and we need to send another one. We keep this as + * a valid connection for a few seconds until we are sure that + * the other end has successfully disconnected as well. + */ NET_CONN_STATE_DISCONNECTED_SLEEP, - } net_connstate_t; -// Reason a connection was terminated - +/* Reason a connection was terminated. */ typedef enum { - // As the result of a local disconnect request - + /* As the result of a local disconnect request */ NET_DISCONNECT_LOCAL, - // As the result of a remote disconnect request - + /* As the result of a remote disconnect request */ NET_DISCONNECT_REMOTE, - // Timeout (no data received in a long time) - + /* Timeout (no data received in a long time) */ NET_DISCONNECT_TIMEOUT, - } net_disconnect_reason_t; #define MAX_RETRIES 5 @@ -81,7 +78,6 @@ typedef struct int reliable_recv_seq; } net_connection_t; - void NET_Conn_SendPacket(net_connection_t *conn, net_packet_t *packet); void NET_Conn_InitClient(net_connection_t *conn, net_addr_t *addr, net_protocol_t protocol); @@ -93,9 +89,9 @@ void NET_Conn_Disconnect(net_connection_t *conn); void NET_Conn_Run(net_connection_t *conn); net_packet_t *NET_Conn_NewReliable(net_connection_t *conn, int packet_type); -// Other miscellaneous common functions +/* Other miscellaneous common functions. */ unsigned int NET_ExpandTicNum(unsigned int relative, unsigned int b); boolean NET_ValidGameSettings(GameMode_t mode, GameMission_t mission, net_gamesettings_t *settings); -#endif /* #ifndef NET_COMMON_H */ +#endif /* NET_COMMON_H */ diff --git a/zephyrdoom/src/net_dedicated.c b/zephyrdoom/src/net_dedicated.c index 3280913..b7f1d59 100644 --- a/zephyrdoom/src/net_dedicated.c +++ b/zephyrdoom/src/net_dedicated.c @@ -1,19 +1,19 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// -// Dedicated server code. -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Dedicated server code. + */ #include #include @@ -29,26 +29,48 @@ #include "net_sdl.h" #include "net_server.h" -// -// People can become confused about how dedicated servers work. Game -// options are specified to the controlling player who is the first to -// join a game. Bomb out with an error message if game options are -// specified to a dedicated server. -// - +/* + * People can become confused about how dedicated servers work. Game + * options are specified to the controlling player who is the first to + * join a game. Bomb out with an error message if game options are + * specified to a dedicated server. + */ static char *not_dedicated_options[] = -{ - "-deh", "-iwad", "-cdrom", "-gameversion", "-nomonsters", "-respawn", - "-fast", "-altdeath", "-deathmatch", "-turbo", "-merge", "-af", "-as", - "-aa", "-file", "-wart", "-skill", "-episode", "-timer", "-avg", "-warp", - "-loadgame", "-longtics", "-extratics", "-dup", "-shorttics", NULL, + { + "-deh", + "-iwad", + "-cdrom", + "-gameversion", + "-nomonsters", + "-respawn", + "-fast", + "-altdeath", + "-deathmatch", + "-turbo", + "-merge", + "-af", + "-as", + "-aa", + "-file", + "-wart", + "-skill", + "-episode", + "-timer", + "-avg", + "-warp", + "-loadgame", + "-longtics", + "-extratics", + "-dup", + "-shorttics", + NULL, }; static void CheckForClientOptions(void) { int i; - for (i=0; not_dedicated_options[i] != NULL; ++i) + for (i = 0; not_dedicated_options[i] != NULL; ++i) { if (M_CheckParm(not_dedicated_options[i]) > 0) { diff --git a/zephyrdoom/src/net_dedicated.h b/zephyrdoom/src/net_dedicated.h index ee5ed1d..ebf2fda 100644 --- a/zephyrdoom/src/net_dedicated.h +++ b/zephyrdoom/src/net_dedicated.h @@ -1,23 +1,23 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// -// Dedicated server code. -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Dedicated server code. + */ #ifndef NET_DEDICATED_H #define NET_DEDICATED_H void NET_DedicatedServer(void); -#endif /* #ifndef NET_DEDICATED_H */ +#endif /* NET_DEDICATED_H */ diff --git a/zephyrdoom/src/net_defs.h b/zephyrdoom/src/net_defs.h index 1ef9c93..8671949 100644 --- a/zephyrdoom/src/net_defs.h +++ b/zephyrdoom/src/net_defs.h @@ -1,19 +1,19 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Definitions for use in networking code. -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Definitions for use in networking code. + */ #ifndef NET_DEFS_H #define NET_DEFS_H @@ -24,27 +24,31 @@ #include "d_ticcmd.h" #include "sha1.h" -// Absolute maximum number of "nodes" in the game. This is different to -// NET_MAXPLAYERS, as there may be observers that are not participating -// (eg. left/right monitors) - +/* + * Absolute maximum number of "nodes" in the game. This is different to + * NET_MAXPLAYERS, as there may be observers that are not participating + * (e.g. left/right monitors) + */ #define MAXNETNODES 16 -// The maximum number of players, multiplayer/networking. -// This is the maximum supported by the networking code; individual games -// have their own values for MAXPLAYERS that can be smaller. - +/* + * The maximum number of players, multiplayer/networking. + * This is the maximum supported by the networking code; individual games + * have their own values for MAXPLAYERS that can be smaller. + */ #define NET_MAXPLAYERS 8 -// Maximum length of a player's name. - +/* Maximum length of a player's name. */ #define MAXPLAYERNAME 30 -// Networking and tick handling related. - -/* NRFD-TODO !! BACKUPTICS 128 */ +/* Networking and tick handling related. */ #define BACKUPTICS 4 +/* + * // NRFD-TODO + * # #define BACKUPTICS 128 + */ + typedef struct _net_module_s net_module_t; typedef struct _net_packet_s net_packet_t; typedef struct _net_addr_s net_addr_t; @@ -60,82 +64,79 @@ struct _net_packet_s struct _net_module_s { - // Initialize this module for use as a client - + /* Initialize this module for use as a client */ boolean (*InitClient)(void); - // Initialize this module for use as a server - + /* Initialize this module for use as a server */ boolean (*InitServer)(void); - // Send a packet - + /* Send a packet */ void (*SendPacket)(net_addr_t *addr, net_packet_t *packet); - // Check for new packets to receive - // - // Returns true if packet received - + /* + * Check for new packets to receive. + * + * Returns true if packet received. + */ boolean (*RecvPacket)(net_addr_t **addr, net_packet_t **packet); - // Converts an address to a string - + /* Converts an address to a string */ void (*AddrToString)(net_addr_t *addr, char *buffer, int buffer_len); - // Free back an address when no longer in use - + /* Free back an address when no longer in use */ void (*FreeAddress)(net_addr_t *addr); - // Try to resolve a name to an address - + /* Try to resolve a name to an address */ net_addr_t *(*ResolveAddress)(char *addr); }; -// net_addr_t - struct _net_addr_s { net_module_t *module; void *handle; }; -// Magic number sent when connecting to check this is a valid client -#define NET_MAGIC_NUMBER 1454104972U +/* Magic number sent when connecting to check this is a valid client. */ +#define NET_MAGIC_NUMBER 1454104972U -// Old magic number used by Chocolate Doom versions before v3.0: +/* Old magic number used by Chocolate Doom versions before v3.0 */ #define NET_OLD_MAGIC_NUMBER 3436803284U -// header field value indicating that the packet is a reliable packet - +/* Header field value indicating that the packet is a reliable packet. */ #define NET_RELIABLE_PACKET (1 << 15) -// Supported protocols. If you're developing a fork of Chocolate -// Doom, you can add your own entry to this list while maintaining -// compatibility with Chocolate Doom servers. Higher-numbered enum values -// will be preferred when negotiating a protocol for the client and server -// to use, so the order matters. -// NOTE: The values in this enum do not have any special value outside of -// the program they're compiled in. What matters is the string representation. +/* + * Supported protocols. If you're developing a fork of Chocolate + * Doom, you can add your own entry to this list while maintaining + * compatibility with Chocolate Doom servers. Higher-numbered enum values + * will be preferred when negotiating a protocol for the client and server + * to use, so the order matters. + * + * The values in this enum do not have any special value outside of + * the program they're compiled in. What matters is the string representation. + */ typedef enum { - // Protocol introduced with Chocolate Doom v3.0. Each compatibility- - // breaking change to the network protocol will produce a new protocol - // number in this enum. + /* + * Protocol introduced with Chocolate Doom v3.0. Each compatibility + * breaking change to the network protocol will produce a new protocol + * number in this enum. + */ NET_PROTOCOL_CHOCOLATE_DOOM_0, - // Add your own protocol here; be sure to add a name for it to the list - // in net_common.c too. - + /* + * Add your own protocol here. Be sure to add a name for it to the list + * in net_common.c too. + */ NET_NUM_PROTOCOLS, NET_PROTOCOL_UNKNOWN, } net_protocol_t; -// packet types - +/* Packet types. */ typedef enum { NET_PACKET_TYPE_SYN, - NET_PACKET_TYPE_ACK, // deprecated + NET_PACKET_TYPE_ACK, /* Deprecated */ NET_PACKET_TYPE_REJECTED, NET_PACKET_TYPE_KEEPALIVE, NET_PACKET_TYPE_WAITING_DATA, @@ -166,8 +167,7 @@ typedef enum NET_MASTER_PACKET_TYPE_SIGN_END_RESPONSE, } net_master_packet_type_t; -// Settings specified when the client connects to the server. - +/* Settings specified when the client connects to the server. */ typedef struct { int gamemode; @@ -181,9 +181,10 @@ typedef struct int player_class; } net_connect_data_t; -// Game settings sent by client to server when initiating game start, -// and received from the server by clients when the game starts. - +/* + * Game settings sent by client to server when initiating game start, + * and received from the server by clients when the game starts. + */ typedef struct { int ticdup; @@ -200,28 +201,27 @@ typedef struct int new_sync; int timelimit; int loadgame; - int random; // [Strife only] - - // These fields are only used by the server when sending a game - // start message: + int random; /* [Strife only] */ + /* + * These fields are only used by the server when sending a game + * start message. + */ int num_players; int consoleplayer; - // Hexen player classes: - + /* Hexen player classes */ int player_classes[NET_MAXPLAYERS]; - } net_gamesettings_t; -#define NET_TICDIFF_FORWARD (1 << 0) -#define NET_TICDIFF_SIDE (1 << 1) -#define NET_TICDIFF_TURN (1 << 2) -#define NET_TICDIFF_BUTTONS (1 << 3) -#define NET_TICDIFF_CONSISTANCY (1 << 4) -#define NET_TICDIFF_CHATCHAR (1 << 5) -#define NET_TICDIFF_RAVEN (1 << 6) -#define NET_TICDIFF_STRIFE (1 << 7) +#define NET_TICDIFF_FORWARD (1 << 0) +#define NET_TICDIFF_SIDE (1 << 1) +#define NET_TICDIFF_TURN (1 << 2) +#define NET_TICDIFF_BUTTONS (1 << 3) +#define NET_TICDIFF_CONSISTANCY (1 << 4) +#define NET_TICDIFF_CHATCHAR (1 << 5) +#define NET_TICDIFF_RAVEN (1 << 6) +#define NET_TICDIFF_STRIFE (1 << 7) typedef struct { @@ -229,8 +229,7 @@ typedef struct ticcmd_t cmd; } net_ticdiff_t; -// Complete set of ticcmds from all players - +/* Complete set of ticcmds from all players. */ typedef struct { signed int latency; @@ -239,8 +238,7 @@ typedef struct net_ticdiff_t cmds[NET_MAXPLAYERS]; } net_full_ticcmd_t; -// Data sent in response to server queries - +/* Data sent in response to server queries. */ typedef struct { char *version; @@ -253,8 +251,7 @@ typedef struct net_protocol_t protocol; } net_querydata_t; -// Data sent by the server while waiting for the game to start. - +/* Data sent by the server while waiting for the game to start. */ typedef struct { int num_players; @@ -270,4 +267,4 @@ typedef struct int is_freedoom; } net_waitdata_t; -#endif /* #ifndef NET_DEFS_H */ +#endif /* NET_DEFS_H */ diff --git a/zephyrdoom/src/net_gui.c b/zephyrdoom/src/net_gui.c index cc69722..0ff736f 100644 --- a/zephyrdoom/src/net_gui.c +++ b/zephyrdoom/src/net_gui.c @@ -1,21 +1,21 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// Graphical stuff related to the networking code: -// -// * The client waiting screen when we are waiting for the server to -// start the game. -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Graphical stuff related to the networking code. + * The client waiting screen when we are waiting for the server to + * start the game. + */ #include #include @@ -45,9 +45,11 @@ static txt_label_t *drone_label; static txt_label_t *master_msg_label; static boolean had_warning; -// Number of players we expect to be in the game. When the number is -// reached, we auto-start the game (if we're the controller). If -// zero, do not autostart. +/* + * Number of players we expect to be in the game. When the number is + * reached, we auto-start the game (if we're the controller). If + * zero, do not autostart. + */ static int expected_nodes; static void EscapePressed(TXT_UNCAST_ARG(widget), void *unused) @@ -76,7 +78,7 @@ static void OpenWaitDialog(void) TXT_SetWindowAction(window, TXT_HORIZ_LEFT, cancel); TXT_SetWindowPosition(window, TXT_HORIZ_CENTER, TXT_VERT_BOTTOM, - TXT_SCREEN_W / 2, TXT_SCREEN_H - 9); + TXT_SCREEN_W / 2, TXT_SCREEN_H - 9); old_max_players = 0; } @@ -91,14 +93,12 @@ static void BuildWindow(void) table = TXT_NewTable(3); TXT_AddWidget(window, table); - // Add spacers - + /* Add spacers */ TXT_AddWidget(table, NULL); TXT_AddWidget(table, TXT_NewStrut(25, 1)); TXT_AddWidget(table, TXT_NewStrut(17, 1)); - // Player labels - + /* Player labels */ for (i = 0; i < net_client_wait_data.max_players; ++i) { M_snprintf(buf, sizeof(buf), " %i. ", i + 1); @@ -120,10 +120,11 @@ static void UpdateGUI(void) char buf[50]; unsigned int i; - // If the value of max_players changes, we must rebuild the - // contents of the window. This includes when the first - // waiting data packet is received. - + /* + * If the value of max_players changes, we must rebuild the + * contents of the window. This includes when the first + * waiting data packet is received. + */ if (net_client_received_wait_data) { if (net_client_wait_data.max_players != old_max_players) @@ -140,7 +141,7 @@ static void UpdateGUI(void) { txt_color_t color = TXT_COLOR_BRIGHT_WHITE; - if ((signed) i == net_client_wait_data.consoleplayer) + if ((signed)i == net_client_wait_data.consoleplayer) { color = TXT_COLOR_YELLOW; } @@ -194,12 +195,13 @@ static void BuildMasterStatusWindow(void) master_msg_label = TXT_NewLabel(""); TXT_AddWidget(master_window, master_msg_label); - // This window is here purely for information, so it should be - // in the background. - + /* + * This window is here purely for information, so it should be + * in the background. + */ TXT_LowerWindow(master_window); TXT_SetWindowPosition(master_window, TXT_HORIZ_CENTER, TXT_VERT_CENTER, - TXT_SCREEN_W / 2, TXT_SCREEN_H - 4); + TXT_SCREEN_W / 2, TXT_SCREEN_H - 4); TXT_SetWindowAction(master_window, TXT_HORIZ_LEFT, NULL); TXT_SetWindowAction(master_window, TXT_HORIZ_CENTER, NULL); TXT_SetWindowAction(master_window, TXT_HORIZ_RIGHT, NULL); @@ -222,16 +224,16 @@ static void CheckMasterStatus(void) if (added) { TXT_SetLabel(master_msg_label, - "Your server is now registered with the global master server.\n" - "Other players can find your server online."); + "Your server is now registered with the global master server.\n" + "Other players can find your server online."); } else { TXT_SetLabel(master_msg_label, - "Failed to register with the master server. Your server is not\n" - "publicly accessible. You may need to reconfigure your Internet\n" - "router to add a port forward for UDP port 2342. Look up\n" - "information on port forwarding online."); + "Failed to register with the master server. Your server is not\n" + "publicly accessible. You may need to reconfigure your Internet\n" + "router to add a port forward for UDP port 2342. Look up\n" + "information on port forwarding online."); } } @@ -241,7 +243,7 @@ static void PrintSHA1Digest(char *s, byte *digest) printf("%s: ", s); - for (i=0; i 0) { @@ -377,12 +374,9 @@ static void CheckAutoLaunch(void) { int nodes; - if (net_client_received_wait_data - && net_client_wait_data.is_controller - && expected_nodes > 0) + if (net_client_received_wait_data && net_client_wait_data.is_controller && expected_nodes > 0) { - nodes = net_client_wait_data.num_players - + net_client_wait_data.num_drones; + nodes = net_client_wait_data.num_players + net_client_wait_data.num_drones; if (nodes >= expected_nodes) { diff --git a/zephyrdoom/src/net_gui.h b/zephyrdoom/src/net_gui.h index 7572fcd..5dd18ce 100644 --- a/zephyrdoom/src/net_gui.h +++ b/zephyrdoom/src/net_gui.h @@ -1,22 +1,21 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// Graphical stuff related to the networking code: -// -// * The client waiting screen when we are waiting for the server to -// start the game. -// - +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Graphical stuff related to the networking code. + * The client waiting screen when we are waiting for the server to + * start the game. + */ #ifndef NET_GUI_H #define NET_GUI_H @@ -25,4 +24,4 @@ extern void NET_WaitForLaunch(void); -#endif /* #ifndef NET_GUI_H */ +#endif /* NET_GUI_H */ diff --git a/zephyrdoom/src/net_io.c b/zephyrdoom/src/net_io.c index b3cfd35..ebc3602 100644 --- a/zephyrdoom/src/net_io.c +++ b/zephyrdoom/src/net_io.c @@ -1,20 +1,20 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Network packet I/O. Base layer for sending/receiving packets, -// through the network module system -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Network packet I/O. Base layer for sending/receiving packets, + * through the network module system + */ #include @@ -61,7 +61,7 @@ net_addr_t *NET_ResolveAddress(net_context_t *context, char *addr) result = NULL; - for (i=0; inum_modules; ++i) + for (i = 0; i < context->num_modules; ++i) { result = context->modules[i]->ResolveAddress(addr); @@ -83,7 +83,7 @@ void NET_SendBroadcast(net_context_t *context, net_packet_t *packet) { int i; - for (i=0; inum_modules; ++i) + for (i = 0; i < context->num_modules; ++i) { context->modules[i]->SendPacket(&net_broadcast_addr, packet); } @@ -95,9 +95,8 @@ boolean NET_RecvPacket(net_context_t *context, { int i; - // check all modules for new packets - - for (i=0; inum_modules; ++i) + /* Check all modules for new packets */ + for (i = 0; i < context->num_modules; ++i) { if (context->modules[i]->RecvPacket(addr, packet)) { @@ -108,9 +107,10 @@ boolean NET_RecvPacket(net_context_t *context, return false; } -// Note: this prints into a static buffer, calling again overwrites -// the first result - +/* + * This prints into a static buffer, calling again overwrites + * the first result. + */ char *NET_AddrToString(net_addr_t *addr) { static char buf[128]; diff --git a/zephyrdoom/src/net_io.h b/zephyrdoom/src/net_io.h index 91e5b2d..d35ab04 100644 --- a/zephyrdoom/src/net_io.h +++ b/zephyrdoom/src/net_io.h @@ -1,19 +1,19 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Network packet manipulation (net_packet_t) -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Network packet manipulation (net_packet_t). + */ #ifndef NET_IO_H #define NET_IO_H @@ -32,4 +32,4 @@ char *NET_AddrToString(net_addr_t *addr); void NET_FreeAddress(net_addr_t *addr); net_addr_t *NET_ResolveAddress(net_context_t *context, char *address); -#endif /* #ifndef NET_IO_H */ +#endif /* NET_IO_H */ diff --git a/zephyrdoom/src/net_loop.c b/zephyrdoom/src/net_loop.c index 2ed4d56..176fbe4 100644 --- a/zephyrdoom/src/net_loop.c +++ b/zephyrdoom/src/net_loop.c @@ -1,19 +1,19 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Loopback network module for server compiled into the client -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Loopback network module for server compiled into the client. + */ #include #include @@ -51,8 +51,7 @@ static void QueuePush(packet_queue_t *queue, net_packet_t *packet) if (new_tail == queue->head) { - // queue is full - + /* Queue is full */ return; } @@ -66,8 +65,7 @@ static net_packet_t *QueuePop(packet_queue_t *queue) if (queue->tail == queue->head) { - // queue empty - + /* Queue empty */ return NULL; } @@ -77,12 +75,7 @@ static net_packet_t *QueuePop(packet_queue_t *queue) return packet; } -//----------------------------------------------------------------------------- -// -// Client end code -// -//----------------------------------------------------------------------------- - +/* Client end code. */ static boolean NET_CL_InitClient(void) { QueueInit(&client_queue); @@ -143,22 +136,17 @@ static net_addr_t *NET_CL_ResolveAddress(char *address) } net_module_t net_loop_client_module = -{ - NET_CL_InitClient, - NET_CL_InitServer, - NET_CL_SendPacket, - NET_CL_RecvPacket, - NET_CL_AddrToString, - NET_CL_FreeAddress, - NET_CL_ResolveAddress, + { + NET_CL_InitClient, + NET_CL_InitServer, + NET_CL_SendPacket, + NET_CL_RecvPacket, + NET_CL_AddrToString, + NET_CL_FreeAddress, + NET_CL_ResolveAddress, }; -//----------------------------------------------------------------------------- -// -// Server end code -// -//----------------------------------------------------------------------------- - +/* Server end code. */ static boolean NET_SV_InitClient(void) { I_Error("NET_SV_InitClient: attempted to initialize server pipe end as a client!"); @@ -218,12 +206,12 @@ static net_addr_t *NET_SV_ResolveAddress(char *address) } net_module_t net_loop_server_module = -{ - NET_SV_InitClient, - NET_SV_InitServer, - NET_SV_SendPacket, - NET_SV_RecvPacket, - NET_SV_AddrToString, - NET_SV_FreeAddress, - NET_SV_ResolveAddress, + { + NET_SV_InitClient, + NET_SV_InitServer, + NET_SV_SendPacket, + NET_SV_RecvPacket, + NET_SV_AddrToString, + NET_SV_FreeAddress, + NET_SV_ResolveAddress, }; diff --git a/zephyrdoom/src/net_loop.h b/zephyrdoom/src/net_loop.h index d2f409d..12bbb0c 100644 --- a/zephyrdoom/src/net_loop.h +++ b/zephyrdoom/src/net_loop.h @@ -1,19 +1,19 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Loopback network module for server compiled into the client -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Loopback network module for server compiled into the client. + */ #ifndef NET_LOOP_H #define NET_LOOP_H @@ -23,4 +23,4 @@ extern net_module_t net_loop_client_module; extern net_module_t net_loop_server_module; -#endif /* #ifndef NET_LOOP_H */ +#endif /* NET_LOOP_H */ diff --git a/zephyrdoom/src/net_packet.c b/zephyrdoom/src/net_packet.c index fd0be6b..3885fdf 100644 --- a/zephyrdoom/src/net_packet.c +++ b/zephyrdoom/src/net_packet.c @@ -1,19 +1,19 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Network packet manipulation (net_packet_t) -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Network packet manipulation (net_packet_t). + */ #include #include @@ -27,7 +27,7 @@ net_packet_t *NET_NewPacket(int initial_size) { net_packet_t *packet; - packet = (net_packet_t *) Z_Malloc(sizeof(net_packet_t), PU_STATIC, 0); + packet = (net_packet_t *)Z_Malloc(sizeof(net_packet_t), PU_STATIC, 0); if (initial_size == 0) initial_size = 256; @@ -39,14 +39,10 @@ net_packet_t *NET_NewPacket(int initial_size) total_packet_memory += sizeof(net_packet_t) + initial_size; - //printf("total packet memory: %i bytes\n", total_packet_memory); - //printf("%p: allocated\n", packet); - return packet; } -// duplicates an existing packet - +/* Duplicates an existing packet. */ net_packet_t *NET_PacketDup(net_packet_t *packet) { net_packet_t *newpacket; @@ -60,16 +56,12 @@ net_packet_t *NET_PacketDup(net_packet_t *packet) void NET_FreePacket(net_packet_t *packet) { - //printf("%p: destroyed\n", packet); - total_packet_memory -= sizeof(net_packet_t) + packet->alloced; Z_Free(packet->data); Z_Free(packet); } -// Read a byte from the packet, returning true if read -// successfully - +/* Read a byte from the packet, returning true if read successfully. */ boolean NET_ReadInt8(net_packet_t *packet, unsigned int *data) { if (packet->pos + 1 > packet->len) @@ -82,9 +74,10 @@ boolean NET_ReadInt8(net_packet_t *packet, unsigned int *data) return true; } -// Read a 16-bit integer from the packet, returning true if read -// successfully - +/* + * Read a 16-bit integer from the packet, returning true if read + * successfully. + */ boolean NET_ReadInt16(net_packet_t *packet, unsigned int *data) { byte *p; @@ -100,9 +93,10 @@ boolean NET_ReadInt16(net_packet_t *packet, unsigned int *data) return true; } -// Read a 32-bit integer from the packet, returning true if read -// successfully - +/* + * Read a 32-bit integer from the packet, returning true if read + * successfully. + */ boolean NET_ReadInt32(net_packet_t *packet, unsigned int *data) { byte *p; @@ -118,11 +112,10 @@ boolean NET_ReadInt32(net_packet_t *packet, unsigned int *data) return true; } -// Signed read functions - +/* Signed read functions. */ boolean NET_ReadSInt8(net_packet_t *packet, signed int *data) { - if (NET_ReadInt8(packet,(unsigned int *) data)) + if (NET_ReadInt8(packet, (unsigned int *)data)) { if (*data & (1 << 7)) { @@ -139,7 +132,7 @@ boolean NET_ReadSInt8(net_packet_t *packet, signed int *data) boolean NET_ReadSInt16(net_packet_t *packet, signed int *data) { - if (NET_ReadInt16(packet, (unsigned int *) data)) + if (NET_ReadInt16(packet, (unsigned int *)data)) { if (*data & (1 << 15)) { @@ -156,7 +149,7 @@ boolean NET_ReadSInt16(net_packet_t *packet, signed int *data) boolean NET_ReadSInt32(net_packet_t *packet, signed int *data) { - if (NET_ReadInt32(packet, (unsigned int *) data)) + if (NET_ReadInt32(packet, (unsigned int *)data)) { if (*data & (1 << 31)) { @@ -171,17 +164,17 @@ boolean NET_ReadSInt32(net_packet_t *packet, signed int *data) } } -// Read a string from the packet. Returns NULL if a terminating -// NUL character was not found before the end of the packet. - +/* + * Read a string from the packet. Returns NULL if a terminating + * NUL character was not found before the end of the packet. + */ char *NET_ReadString(net_packet_t *packet) { char *start; - start = (char *) packet->data + packet->pos; - - // Search forward for a NUL character + start = (char *)packet->data + packet->pos; + /* Search forward for a NUL character */ while (packet->pos < packet->len && packet->data[packet->pos] != '\0') { ++packet->pos; @@ -189,23 +182,25 @@ char *NET_ReadString(net_packet_t *packet) if (packet->pos >= packet->len) { - // Reached the end of the packet - + /* Reached the end of the packet */ return NULL; } - // packet->data[packet->pos] == '\0': We have reached a terminating - // NULL. Skip past this NULL and continue reading immediately - // after it. - + /* + * packet->data[packet->pos] == '\0' + * We have reached a terminating NULL. + * Skip past this NULL and continue reading immediately after it. + */ ++packet->pos; return start; } -// Read a string from the packet, but (potentially) modify it to strip -// out any unprintable characters which could be malicious control codes. -// Note that this may modify the original packet contents. +/* + * Read a string from the packet, but (potentially) modify it to strip + * out any unprintable characters which could be malicious control codes. + * Note that this may modify the original packet contents. + */ char *NET_ReadSafeString(net_packet_t *packet) { char *r, *w, *result; @@ -216,13 +211,19 @@ char *NET_ReadSafeString(net_packet_t *packet) return NULL; } - // w is always <= r, so we never produce a longer string than the original. + /* + * w is always <= r + * We never produce a longer string than the original. + */ w = result; for (r = result; *r != '\0'; ++r) { - // TODO: This is a very naive way of producing a safe string; only - // ASCII characters are allowed. Probably this should really support - // UTF-8 characters as well. + /* + * TODO + * This is a very naive way of producing a safe string. + * Only ASCII characters are allowed. + * Probably this should really support UTF-8 characters as well. + */ if (isprint(*r) || *r == '\n') { *w = *r; @@ -234,8 +235,7 @@ char *NET_ReadSafeString(net_packet_t *packet) return result; } -// Dynamically increases the size of a packet - +/* Dynamically increases the size of a packet. */ static void NET_IncreasePacket(net_packet_t *packet) { byte *newdata; @@ -254,8 +254,7 @@ static void NET_IncreasePacket(net_packet_t *packet) total_packet_memory += packet->alloced; } -// Write a single byte to the packet - +/* Write a single byte to the packet. */ void NET_WriteInt8(net_packet_t *packet, unsigned int i) { if (packet->len + 1 > packet->alloced) @@ -265,8 +264,7 @@ void NET_WriteInt8(net_packet_t *packet, unsigned int i) packet->len += 1; } -// Write a 16-bit integer to the packet - +/* Write a 16 bit integer to the packet. */ void NET_WriteInt16(net_packet_t *packet, unsigned int i) { byte *p; @@ -282,9 +280,7 @@ void NET_WriteInt16(net_packet_t *packet, unsigned int i) packet->len += 2; } - -// Write a single byte to the packet - +/* Write a single byte to the packet. */ void NET_WriteInt32(net_packet_t *packet, unsigned int i) { byte *p; @@ -309,8 +305,7 @@ void NET_WriteString(net_packet_t *packet, const char *string) string_size = strlen(string) + 1; - // Increase the packet size until large enough to hold the string - + /* Increase the packet size until large enough to hold the string */ while (packet->len + string_size > packet->alloced) { NET_IncreasePacket(packet); @@ -318,7 +313,7 @@ void NET_WriteString(net_packet_t *packet, const char *string) p = packet->data + packet->len; - M_StringCopy((char *) p, string, string_size); + M_StringCopy((char *)p, string, string_size); packet->len += string_size; } diff --git a/zephyrdoom/src/net_packet.h b/zephyrdoom/src/net_packet.h index 65ed27b..ba4a6c8 100644 --- a/zephyrdoom/src/net_packet.h +++ b/zephyrdoom/src/net_packet.h @@ -1,19 +1,19 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Definitions for use in networking code. -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Definitions for use in networking code. + */ #ifndef NET_PACKET_H #define NET_PACKET_H @@ -41,4 +41,4 @@ void NET_WriteInt32(net_packet_t *packet, unsigned int i); void NET_WriteString(net_packet_t *packet, const char *string); -#endif /* #ifndef NET_PACKET_H */ +#endif /* NET_PACKET_H */ diff --git a/zephyrdoom/src/net_query.c b/zephyrdoom/src/net_query.c index db115a1..0be0e2a 100644 --- a/zephyrdoom/src/net_query.c +++ b/zephyrdoom/src/net_query.c @@ -1,19 +1,19 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Querying servers to find their current status. -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Querying servers to find their current status. + */ #include #include @@ -32,34 +32,30 @@ #include "net_structrw.h" #include "net_sdl.h" -// DNS address of the Internet master server. - +/* DNS address of the Internet master server. */ #define MASTER_SERVER_ADDRESS "master.chocolate-doom.org:2342" -// Time to wait for a response before declaring a timeout. - +/* Time to wait for a response before declaring a timeout. */ #define QUERY_TIMEOUT_SECS 2 -// Time to wait for secure demo signatures before declaring a timeout. - +/* Time to wait for secure demo signatures before declaring a timeout. */ #define SIGNATURE_TIMEOUT_SECS 5 -// Number of query attempts to make before giving up on a server. - +/* Number of query attempts to make before giving up on a server. */ #define QUERY_MAX_ATTEMPTS 3 typedef enum { - QUERY_TARGET_SERVER, // Normal server target. - QUERY_TARGET_MASTER, // The master server. - QUERY_TARGET_BROADCAST // Send a broadcast query + QUERY_TARGET_SERVER, /* Normal server target. */ + QUERY_TARGET_MASTER, /* The master server. */ + QUERY_TARGET_BROADCAST /* Send a broadcast query */ } query_target_type_t; typedef enum { - QUERY_TARGET_QUEUED, // Query not yet sent - QUERY_TARGET_QUERIED, // Query sent, waiting response - QUERY_TARGET_RESPONDED, // Response received + QUERY_TARGET_QUEUED, /* Query not yet sent. */ + QUERY_TARGET_QUERIED, /* Query sent, waiting response. */ + QUERY_TARGET_RESPONDED, /* Response received. */ QUERY_TARGET_NO_RESPONSE } query_target_state_t; @@ -88,8 +84,7 @@ static int last_query_time = 0; static char *securedemo_start_message = NULL; -// Resolve the master server address. - +/* Resolve the master server address. */ net_addr_t *NET_Query_ResolveMaster(net_context_t *context) { net_addr_t *addr; @@ -99,15 +94,17 @@ net_addr_t *NET_Query_ResolveMaster(net_context_t *context) if (addr == NULL) { fprintf(stderr, "Warning: Failed to resolve address " - "for master server: %s\n", MASTER_SERVER_ADDRESS); + "for master server: %s\n", + MASTER_SERVER_ADDRESS); } return addr; } -// Send a registration packet to the master server to register -// ourselves with the global list. - +/* + * Send a registration packet to the master server to register + * ourselves with the global list. + */ void NET_Query_AddToMaster(net_addr_t *master_addr) { net_packet_t *packet; @@ -118,15 +115,13 @@ void NET_Query_AddToMaster(net_addr_t *master_addr) NET_FreePacket(packet); } -// Process a packet received from the master server. - +/* Process a packet received from the master server. */ void NET_Query_MasterResponse(net_packet_t *packet) { unsigned int packet_type; unsigned int result; - if (!NET_ReadInt16(packet, &packet_type) - || !NET_ReadInt16(packet, &result)) + if (!NET_ReadInt16(packet, &packet_type) || !NET_ReadInt16(packet, &result)) { return; } @@ -135,8 +130,7 @@ void NET_Query_MasterResponse(net_packet_t *packet) { if (result != 0) { - // Only show the message once. - + /* Only show the message once */ if (!registered_with_master) { printf("Registered with master server at %s\n", @@ -146,8 +140,7 @@ void NET_Query_MasterResponse(net_packet_t *packet) } else { - // Always show rejections. - + /* Always show rejections */ printf("Failed to register with master server at %s\n", MASTER_SERVER_ADDRESS); } @@ -158,8 +151,7 @@ void NET_Query_MasterResponse(net_packet_t *packet) boolean NET_Query_CheckAddedToMaster(boolean *result) { - // Got response from master yet? - + /* Got response from master yet */ if (!got_master_response) { return false; @@ -169,8 +161,7 @@ boolean NET_Query_CheckAddedToMaster(boolean *result) return true; } -// Send a query to the master server. - +/* Send a query to the master server. */ static void NET_Query_SendMasterQuery(net_addr_t *addr) { net_packet_t *packet; @@ -181,15 +172,16 @@ static void NET_Query_SendMasterQuery(net_addr_t *addr) NET_FreePacket(packet); } -// Given the specified address, find the target associated. If no -// target is found, and 'create' is true, a new target is created. - +/* + * Given the specified address, find the target associated. If no + * target is found, and 'create' is true, a new target is created. + */ static query_target_t *GetTargetForAddr(net_addr_t *addr, boolean create) { query_target_t *target; int i; - for (i=0; istate != QUERY_TARGET_QUERIED) + /* + * Not in broadcast mode, unexpected response that came out + * of nowhere. Ignore. + */ + if (broadcast_target == NULL || broadcast_target->state != QUERY_TARGET_QUERIED) { return; } - // Create new target. - + /* Create new target */ target = GetTargetForAddr(addr, true); target->state = QUERY_TARGET_QUERIED; target->query_time = broadcast_target->query_time; @@ -294,18 +281,15 @@ static void NET_Query_ParseResponse(net_addr_t *addr, net_packet_t *packet, target->state = QUERY_TARGET_RESPONDED; memcpy(&target->data, &querydata, sizeof(net_querydata_t)); - // Calculate RTT. - + /* Calculate RTT target->ping_time = I_GetTimeMS() - target->query_time; - // Invoke callback to signal that we have a new address. - + /* Invoke callback to signal that we have a new address */ callback(addr, &target->data, target->ping_time, user_data); } } -// Parse a response packet from the master server. - +/* Parse a response packet from the master server. */ static void NET_Query_ParseMasterResponse(net_addr_t *master_addr, net_packet_t *packet) { @@ -314,17 +298,16 @@ static void NET_Query_ParseMasterResponse(net_addr_t *master_addr, char *addr_str; net_addr_t *addr; - // Read the header. We are only interested in query responses. - - if (!NET_ReadInt16(packet, &packet_type) - || packet_type != NET_MASTER_PACKET_TYPE_QUERY_RESPONSE) + /* Read the header. We are only interested in query responses. */ + if (!NET_ReadInt16(packet, &packet_type) || packet_type != NET_MASTER_PACKET_TYPE_QUERY_RESPONSE) { return; } - // Read a list of strings containing the addresses of servers - // that the master knows about. - + /* + * Read a list of strings containing the addresses of servers + * that the master knows about. + */ for (;;) { addr_str = NET_ReadString(packet); @@ -334,9 +317,10 @@ static void NET_Query_ParseMasterResponse(net_addr_t *master_addr, break; } - // Resolve address and add to targets list if it is not already - // there. - + /* + * Resolve address and add to targets list if it is not already + * there. + */ addr = NET_ResolveAddress(query_context, addr_str); if (addr != NULL) @@ -345,8 +329,7 @@ static void NET_Query_ParseMasterResponse(net_addr_t *master_addr, } } - // Mark the master as having responded. - + /* Mark the master as having responded */ target = GetTargetForAddr(master_addr, true); target->state = QUERY_TARGET_RESPONDED; } @@ -357,8 +340,7 @@ static void NET_Query_ParsePacket(net_addr_t *addr, net_packet_t *packet, { query_target_t *target; - // This might be the master server responding. - + /* This might be the master server responding */ target = GetTargetForAddr(addr, false); if (target != NULL && target->type == QUERY_TARGET_MASTER) @@ -384,8 +366,7 @@ static void NET_Query_GetResponse(net_query_callback_t callback, } } -// Find a target we have not yet queried and send a query. - +/* Find a target we have not yet queried and send a query. */ static void SendOneQuery(void) { unsigned int now; @@ -393,8 +374,7 @@ static void SendOneQuery(void) now = I_GetTimeMS(); - // Rate limit - only send one query every 50ms. - + /* Rate limit - only send one query every 50ms */ if (now - last_query_time < 50) { return; @@ -402,12 +382,11 @@ static void SendOneQuery(void) for (i = 0; i < num_targets; ++i) { - // Not queried yet? - // Or last query timed out without a response? - - if (targets[i].state == QUERY_TARGET_QUEUED - || (targets[i].state == QUERY_TARGET_QUERIED - && now - targets[i].query_time > QUERY_TIMEOUT_SECS * 1000)) + /* + * Not queried yet. + * Or last query timed out without a response?. + */ + if (targets[i].state == QUERY_TARGET_QUEUED || (targets[i].state == QUERY_TARGET_QUERIED && now - targets[i].query_time > QUERY_TIMEOUT_SECS * 1000)) { break; } @@ -418,25 +397,25 @@ static void SendOneQuery(void) return; } - // Found a target to query. Send a query; how to do this depends on - // the target type. - + /* + * Found a target to query. Send a query. How to do this depends on + * the target type. + */ switch (targets[i].type) { - case QUERY_TARGET_SERVER: - NET_Query_SendQuery(targets[i].addr); - break; + case QUERY_TARGET_SERVER: + NET_Query_SendQuery(targets[i].addr); + break; - case QUERY_TARGET_BROADCAST: - NET_Query_SendQuery(NULL); - break; + case QUERY_TARGET_BROADCAST: + NET_Query_SendQuery(NULL); + break; - case QUERY_TARGET_MASTER: - NET_Query_SendMasterQuery(targets[i].addr); - break; + case QUERY_TARGET_MASTER: + NET_Query_SendMasterQuery(targets[i].addr); + break; } - //printf("Queried %s\n", NET_AddrToString(targets[i].addr)); targets[i].state = QUERY_TARGET_QUERIED; targets[i].query_time = now; ++targets[i].query_attempts; @@ -444,8 +423,7 @@ static void SendOneQuery(void) last_query_time = now; } -// Time out servers that have been queried and not responded. - +/* Time out servers that have been queried and not responded. */ static void CheckTargetTimeouts(void) { unsigned int i; @@ -456,18 +434,11 @@ static void CheckTargetTimeouts(void) for (i = 0; i < num_targets; ++i) { /* - printf("target %i: state %i, queries %i, query time %i\n", - i, targets[i].state, targets[i].query_attempts, - now - targets[i].query_time); - */ - - // We declare a target to be "no response" when we've sent - // multiple query packets to it (QUERY_MAX_ATTEMPTS) and - // received no response to any of them. - - if (targets[i].state == QUERY_TARGET_QUERIED - && targets[i].query_attempts >= QUERY_MAX_ATTEMPTS - && now - targets[i].query_time > QUERY_TIMEOUT_SECS * 1000) + * We declare a target to be "no response" when we've sent + * multiple query packets to it (QUERY_MAX_ATTEMPTS) and + * received no response to any of them. + */ + if (targets[i].state == QUERY_TARGET_QUERIED && targets[i].query_attempts >= QUERY_MAX_ATTEMPTS && now - targets[i].query_time > QUERY_TIMEOUT_SECS * 1000) { targets[i].state = QUERY_TARGET_NO_RESPONSE; @@ -480,16 +451,14 @@ static void CheckTargetTimeouts(void) } } -// If all targets have responded or timed out, returns true. - +/* If all targets have responded or timed out, returns true. */ static boolean AllTargetsDone(void) { unsigned int i; for (i = 0; i < num_targets; ++i) { - if (targets[i].state != QUERY_TARGET_RESPONDED - && targets[i].state != QUERY_TARGET_NO_RESPONSE) + if (targets[i].state != QUERY_TARGET_RESPONDED && targets[i].state != QUERY_TARGET_NO_RESPONSE) { return false; } @@ -498,44 +467,42 @@ static boolean AllTargetsDone(void) return true; } -// Polling function, invoked periodically to send queries and -// interpret new responses received from remote servers. -// Returns zero when the query sequence has completed and all targets -// have returned responses or timed out. - +/* + * Polling function, invoked periodically to send queries and + * interpret new responses received from remote servers. + * Returns zero when the query sequence has completed and all targets + * have returned responses or timed out. + */ int NET_Query_Poll(net_query_callback_t callback, void *user_data) { CheckTargetTimeouts(); - // Send a query. This will only send a single query at once. - + /* Send a query. This will only send a single query at once. */ SendOneQuery(); - // Check for a response - + /* Check for a response */ NET_Query_GetResponse(callback, user_data); return !AllTargetsDone(); } -// Stop the query loop - +/* Stop the query loop. */ static void NET_Query_ExitLoop(void) { query_loop_running = false; } -// Loop waiting for responses. -// The specified callback is invoked when a new server responds. - +/* + * Loop waiting for responses. + * The specified callback is invoked when a new server responds. + */ static void NET_Query_QueryLoop(net_query_callback_t callback, void *user_data) { query_loop_running = true; while (query_loop_running && NET_Query_Poll(callback, user_data)) { - // Don't thrash the CPU - + /* Don't thrash the CPU */ I_Sleep(1); } } @@ -556,25 +523,24 @@ void NET_Query_Init(void) printed_header = false; } -// Callback that exits the query loop when the first server is found. - +/* Callback that exits the query loop when the first server is found. */ static void NET_Query_ExitCallback(net_addr_t *addr, net_querydata_t *data, unsigned int ping_time, void *user_data) { NET_Query_ExitLoop(); } -// Search the targets list and find a target that has responded. -// If none have responded, returns NULL. - +/* + * Search the targets list and find a target that has responded. + * If none have responded, returns NULL. + */ static query_target_t *FindFirstResponder(void) { unsigned int i; for (i = 0; i < num_targets; ++i) { - if (targets[i].type == QUERY_TARGET_SERVER - && targets[i].state == QUERY_TARGET_RESPONDED) + if (targets[i].type == QUERY_TARGET_SERVER && targets[i].state == QUERY_TARGET_RESPONDED) { return &targets[i]; } @@ -583,8 +549,7 @@ static query_target_t *FindFirstResponder(void) return NULL; } -// Return a count of the number of responses. - +/* Return a count of the number of responses. */ static int GetNumResponses(void) { unsigned int i; @@ -594,8 +559,7 @@ static int GetNumResponses(void) for (i = 0; i < num_targets; ++i) { - if (targets[i].type == QUERY_TARGET_SERVER - && targets[i].state == QUERY_TARGET_RESPONDED) + if (targets[i].type == QUERY_TARGET_SERVER && targets[i].state == QUERY_TARGET_RESPONDED) { ++result; } @@ -610,8 +574,7 @@ int NET_StartLANQuery(void) NET_Query_Init(); - // Add a broadcast target to the list. - + /* Add a broadcast target to the list */ target = GetTargetForAddr(NULL, true); target->type = QUERY_TARGET_BROADCAST; @@ -625,8 +588,7 @@ int NET_StartMasterQuery(void) NET_Query_Init(); - // Resolve master address and add to targets list. - + /* Resolve master address and add to targets list */ master = NET_Query_ResolveMaster(query_context); if (master == NULL) @@ -640,8 +602,6 @@ int NET_StartMasterQuery(void) return 1; } -// ----------------------------------------------------------------------- - static void formatted_printf(int wide, char *s, ...) { va_list args; @@ -662,33 +622,33 @@ static char *GameDescription(GameMode_t mode, GameMission_t mission) { switch (mission) { - case doom: - if (mode == shareware) - return "swdoom"; - else if (mode == registered) - return "regdoom"; - else if (mode == retail) - return "ultdoom"; - else - return "doom"; - case doom2: - return "doom2"; - case pack_tnt: - return "tnt"; - case pack_plut: - return "plutonia"; - case pack_chex: - return "chex"; - case pack_hacx: - return "hacx"; - case heretic: - return "heretic"; - case hexen: - return "hexen"; - case strife: - return "strife"; - default: - return "?"; + case doom: + if (mode == shareware) + return "swdoom"; + else if (mode == registered) + return "regdoom"; + else if (mode == retail) + return "ultdoom"; + else + return "doom"; + case doom2: + return "doom2"; + case pack_tnt: + return "tnt"; + case pack_plut: + return "plutonia"; + case pack_chex: + return "chex"; + case pack_hacx: + return "hacx"; + case heretic: + return "heretic"; + case hexen: + return "hexen"; + case strife: + return "strife"; + default: + return "?"; } } @@ -702,20 +662,18 @@ static void PrintHeader(void) formatted_printf(8, "Players"); puts("Description"); - for (i=0; i<70; ++i) + for (i = 0; i < 70; ++i) putchar('='); putchar('\n'); } -// Callback function that just prints information in a table. - +/* Callback function that just prints information in a table. */ static void NET_QueryPrintCallback(net_addr_t *addr, net_querydata_t *data, unsigned int ping_time, void *user_data) { - // If this is the first server, print the header. - + /* If this is the first server, print the header */ if (!printed_header) { PrintHeader(); @@ -725,7 +683,7 @@ static void NET_QueryPrintCallback(net_addr_t *addr, formatted_printf(5, "%4i", ping_time); formatted_printf(22, "%s", NET_AddrToString(addr)); formatted_printf(4, "%i/%i ", data->num_players, - data->max_players); + data->max_players); if (data->gamemode != indetermined) { @@ -779,18 +737,15 @@ void NET_QueryAddress(char *addr_str) I_Error("NET_QueryAddress: Host '%s' not found!", addr_str); } - // Add the address to the list of targets. - + /* Add the address to the list of targets */ target = GetTargetForAddr(addr, true); printf("\nQuerying '%s'...\n", addr_str); - // Run query loop. - + /* Run query loop */ NET_Query_QueryLoop(NET_Query_ExitCallback, NULL); - // Check if the target responded. - + /* Check if the target responded */ if (target->state == QUERY_TARGET_RESPONDED) { NET_QueryPrintCallback(addr, &target->data, target->ping_time, NULL); @@ -808,13 +763,11 @@ net_addr_t *NET_FindLANServer(void) NET_Query_Init(); - // Add a broadcast target to the list. - + /* Add a broadcast target to the list */ target = GetTargetForAddr(NULL, true); target->type = QUERY_TARGET_BROADCAST; - // Run the query loop, and stop at the first target found. - + /* Run the query loop, and stop at the first target found */ NET_Query_QueryLoop(NET_Query_ExitCallback, NULL); responder = FindFirstResponder(); @@ -829,9 +782,10 @@ net_addr_t *NET_FindLANServer(void) } } -// Block until a packet of the given type is received from the given -// address. - +/* + * Block until a packet of the given type is received from the given + * address. + */ static net_packet_t *BlockForPacket(net_addr_t *addr, unsigned int packet_type, unsigned int timeout_ms) { @@ -850,9 +804,7 @@ static net_packet_t *BlockForPacket(net_addr_t *addr, unsigned int packet_type, continue; } - if (packet_src == addr - && NET_ReadInt16(packet, &read_packet_type) - && packet_type == read_packet_type) + if (packet_src == addr && NET_ReadInt16(packet, &read_packet_type) && packet_type == read_packet_type) { return packet; } @@ -860,13 +812,11 @@ static net_packet_t *BlockForPacket(net_addr_t *addr, unsigned int packet_type, NET_FreePacket(packet); } - // Timeout - no response. - + /* Timeout - no response */ return NULL; } -// Query master server for secure demo start seed value. - +/* Query master server for secure demo start seed value. */ boolean NET_StartSecureDemo(prng_seed_t seed) { net_packet_t *request, *response; @@ -877,16 +827,16 @@ boolean NET_StartSecureDemo(prng_seed_t seed) NET_Query_Init(); master_addr = NET_Query_ResolveMaster(query_context); - // Send request packet to master server. - + /* Send request packet to master server */ request = NET_NewPacket(10); NET_WriteInt16(request, NET_MASTER_PACKET_TYPE_SIGN_START); NET_SendPacket(master_addr, request); NET_FreePacket(request); - // Block for response and read contents. - // The signed start message will be saved for later. - + /* + * Block for response and read contents. + * The signed start message will be saved for later. + */ response = BlockForPacket(master_addr, NET_MASTER_PACKET_TYPE_SIGN_START_RESPONSE, SIGNATURE_TIMEOUT_SECS * 1000); @@ -912,8 +862,7 @@ boolean NET_StartSecureDemo(prng_seed_t seed) return result; } -// Query master server for secure demo end signature. - +/* Query master server for secure demo end signature. */ char *NET_EndSecureDemo(sha1_digest_t demo_hash) { net_packet_t *request, *response; @@ -922,8 +871,7 @@ char *NET_EndSecureDemo(sha1_digest_t demo_hash) master_addr = NET_Query_ResolveMaster(query_context); - // Construct end request and send to master server. - + /* Construct end request and send to master server. */ request = NET_NewPacket(10); NET_WriteInt16(request, NET_MASTER_PACKET_TYPE_SIGN_END); NET_WriteSHA1Sum(request, demo_hash); @@ -931,9 +879,10 @@ char *NET_EndSecureDemo(sha1_digest_t demo_hash) NET_SendPacket(master_addr, request); NET_FreePacket(request); - // Block for response. The response packet simply contains a string - // with the ASCII signature. - + /* + * Block for response. The response packet simply contains a string + * with the ASCII signature. + */ response = BlockForPacket(master_addr, NET_MASTER_PACKET_TYPE_SIGN_END_RESPONSE, SIGNATURE_TIMEOUT_SECS * 1000); diff --git a/zephyrdoom/src/net_query.h b/zephyrdoom/src/net_query.h index faf6217..459d8d5 100644 --- a/zephyrdoom/src/net_query.h +++ b/zephyrdoom/src/net_query.h @@ -1,19 +1,19 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Querying servers to find their current status. -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Querying servers to find their current status. + */ #ifndef NET_QUERY_H #define NET_QUERY_H @@ -40,4 +40,4 @@ extern void NET_Query_AddToMaster(net_addr_t *master_addr); extern boolean NET_Query_CheckAddedToMaster(boolean *result); extern void NET_Query_MasterResponse(net_packet_t *packet); -#endif /* #ifndef NET_QUERY_H */ +#endif /* NET_QUERY_H */ diff --git a/zephyrdoom/src/net_server.c b/zephyrdoom/src/net_server.c index 4b0e2c5..cbb35cd 100644 --- a/zephyrdoom/src/net_server.c +++ b/zephyrdoom/src/net_server.c @@ -1,18 +1,19 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// Network server code -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Network server code. + */ #include #include @@ -36,31 +37,29 @@ #include "net_packet.h" #include "net_query.h" #include "net_server.h" -// #include "net_sdl.h" #include "net_structrw.h" -// How often to refresh our registration with the master server. - +/* How often to refresh our registration with the master server. */ #define MASTER_REFRESH_PERIOD 20 * 60 /* 20 minutes */ -// How often to re-resolve the address of the master server? - +/* How often to re-resolve the address of the master server. */ #define MASTER_RESOLVE_PERIOD 8 * 60 * 60 /* 8 hours */ typedef enum { - // waiting for the game to be "launched" (key player to press the start - // button) - + /* + * Waiting for the game to be "launched" (key player to press the start + * button). + */ SERVER_WAITING_LAUNCH, - // game has been launched, we are waiting for all players to be ready - // so the game can start. - + /* + * Game has been launched, we are waiting for all players to be ready + * so the game can start. + */ SERVER_WAITING_START, - // in a game - + /* In a game */ SERVER_IN_GAME, } net_server_state_t; @@ -73,75 +72,64 @@ typedef struct int last_send_time; char *name; - // If true, the client has sent the NET_PACKET_TYPE_GAMESTART - // message indicating that it is ready for the game to start. - + /* + * If true, the client has sent the NET_PACKET_TYPE_GAMESTART + * message indicating that it is ready for the game to start. + */ boolean ready; - // Time that this client connected to the server. - // This is used to determine the controller (oldest client). - + /* + * Time that this client connected to the server. + * This is used to determine the controller (the oldest client). + */ unsigned int connect_time; - // Last time new gamedata was received from this client - + /* Last time new gamedata was received from this client */ int last_gamedata_time; - // recording a demo without -longtics - + /* Recording a demo without -longtics */ boolean recording_lowres; - // send queue: items to send to the client - // this is a circular buffer - + /* + * Send queue - items to send to the client + * this is a circular buffer. + */ int sendseq; net_full_ticcmd_t sendqueue[BACKUPTICS]; - // Latest acknowledged by the client - + /* Latest acknowledged by the client */ unsigned int acknowledged; - // Value of max_players specified by the client on connect. - + /* Value of max_players specified by the client on connect */ int max_players; - // Observer: receives data but does not participate in the game. - + /* Observer - receives data but does not participate in the game */ boolean drone; - // SHA1 hash sums of the client's WAD directory and dehacked data - + /* SHA1 hash sums of the client's WAD directory and dehacked data */ sha1_digest_t wad_sha1sum; sha1_digest_t deh_sha1sum; - // Is this client is playing with the Freedoom IWAD? - + /* Is this client is playing with the Freedoom IWAD */ unsigned int is_freedoom; - // Player class (for Hexen) - + /* Player class (for Hexen) */ int player_class; - } net_client_t; -// structure used for the recv window - +/* Structure used for the recv window. */ typedef struct { - // Whether this tic has been received yet - + /* Whether this tic has been received yet */ boolean active; - // Latency value received from the client - + /* Latency value received from the client */ signed int latency; - // Last time we sent a resend request for this tic - + /* Last time we sent a resend request for this tic */ unsigned int resend_time; - // Tic data itself - + /* Tic data itself */ net_ticdiff_t diff; } net_client_recv_t; @@ -154,14 +142,12 @@ static unsigned int sv_gamemode; static unsigned int sv_gamemission; static net_gamesettings_t sv_settings; -// For registration with master server: - +/* For registration with master server. */ static net_addr_t *master_server = NULL; static unsigned int master_refresh_time; static unsigned int master_resolve_time; -// receive window - +/* Receive window. */ static unsigned int recvwindow_start; static net_client_recv_t recvwindow[BACKUPTICS][NET_MAXPLAYERS]; @@ -169,105 +155,104 @@ static net_client_recv_t recvwindow[BACKUPTICS][NET_MAXPLAYERS]; static void NET_SV_DisconnectClient(net_client_t *client) { - printf("NRFD-TODO: NET_SV_DisconnectClient \n"); /* - if (client->active) - { - NET_Conn_Disconnect(&client->connection); - } - */ + /* + * // NRFD-TODO + * if (client->active) + * { + * NET_Conn_Disconnect(&client->connection); + * } + */ } static boolean ClientConnected(net_client_t *client) { - // Check that the client is properly connected: ie. not in the - // process of connecting or disconnecting - - return client->active - && client->connection.state == NET_CONN_STATE_CONNECTED; + /* + * Check that the client is properly connected, i.e. not in the + * process of connecting or disconnecting. + */ + return client->active && client->connection.state == NET_CONN_STATE_CONNECTED; } -// Send a message to be displayed on a client's console - +/* Send a message to be displayed on a client's console. */ static void NET_SV_SendConsoleMessage(net_client_t *client, char *s, ...) { - printf("NRFD-TODO: NET_SV_SendConsoleMessage \n"); /* - char buf[1024]; - va_list args; - net_packet_t *packet; - - va_start(args, s); - M_vsnprintf(buf, sizeof(buf), s, args); - va_end(args); - - packet = NET_Conn_NewReliable(&client->connection, - NET_PACKET_TYPE_CONSOLE_MESSAGE); - - NET_WriteString(packet, buf); - */ + /* + * // NRFD-TODO + * char buf[1024]; + * va_list args; + * net_packet_t *packet; + * + * va_start(args, s); + * M_vsnprintf(buf, sizeof(buf), s, args); + * va_end(args); + * + * packet = NET_Conn_NewReliable(&client->connection, + * NET_PACKET_TYPE_CONSOLE_MESSAGE); + * + * NET_WriteString(packet, buf); + */ } -// Send a message to all clients - +/* Send a message to all clients. */ static void NET_SV_BroadcastMessage(char *s, ...) { - printf("NRFD-TODO: NET_SV_BroadcastMessage \n"); /* - char buf[1024]; - va_list args; - int i; - - va_start(args, s); - M_vsnprintf(buf, sizeof(buf), s, args); - va_end(args); - - for (i=0; iplayer_number = pl; - ++pl; - } - else - { - clients[i].player_number = -1; - } - } - } - - for (; plplayer_number = pl; + * ++pl; + * } + * else + * { + * clients[i].player_number = -1; + * } + * } + * } + * + * for (; pl < NET_MAXPLAYERS; ++pl) + * { + * sv_players[pl] = NULL; + * } + */ } -// Returns the number of players currently connected. - +/* Returns the number of players currently connected. */ static int NET_SV_NumPlayers(void) { int i; @@ -275,7 +260,7 @@ static int NET_SV_NumPlayers(void) result = 0; - for (i=0; iplayer_number; - - // Send the WAD and dehacked checksums of the controlling client. - // If no controller found (?), send the details that the client - // is expecting anyway. - - if (controller == NULL) - { - controller = client; - } - - memcpy(&wait_data.wad_sha1sum, &controller->wad_sha1sum, - sizeof(sha1_digest_t)); - memcpy(&wait_data.deh_sha1sum, &controller->deh_sha1sum, - sizeof(sha1_digest_t)); - wait_data.is_freedoom = controller->is_freedoom; - - // set name and address of each player: - - for (i = 0; i < wait_data.num_players; ++i) - { - M_StringCopy(wait_data.player_names[i], - sv_players[i]->name, - MAXPLAYERNAME); - M_StringCopy(wait_data.player_addrs[i], - NET_AddrToString(sv_players[i]->addr), - MAXPLAYERNAME); - } - - // Construct packet: - - packet = NET_NewPacket(10); - NET_WriteInt16(packet, NET_PACKET_TYPE_WAITING_DATA); - NET_WriteWaitData(packet, &wait_data); - - // Send packet to client and free - - NET_Conn_SendPacket(&client->connection, packet); - NET_FreePacket(packet); - */ + /* + * // NRFD-TODO + * net_waitdata_t wait_data; + * net_packet_t *packet; + * net_client_t *controller; + * int i; + * + * NET_SV_AssignPlayers(); + * + * controller = NET_SV_Controller(); + * + * wait_data.num_players = NET_SV_NumPlayers(); + * wait_data.num_drones = NET_SV_NumDrones(); + * wait_data.ready_players = NET_SV_NumReadyPlayers(); + * wait_data.max_players = NET_SV_MaxPlayers(); + * wait_data.is_controller = (client == controller); + * wait_data.consoleplayer = client->player_number; + * + * // Send the WAD and dehacked checksums of the controlling client. + * // If no controller found, send the details that the client + * // is expecting anyway. + * if (controller == NULL) + * { + * controller = client; + * } + * + * memcpy(&wait_data.wad_sha1sum, &controller->wad_sha1sum, + * sizeof(sha1_digest_t)); + * memcpy(&wait_data.deh_sha1sum, &controller->deh_sha1sum, + * sizeof(sha1_digest_t)); + * wait_data.is_freedoom = controller->is_freedoom; + * + * // Set name and address of each player + * for (i = 0; i < wait_data.num_players; ++i) + * { + * M_StringCopy(wait_data.player_names[i], + * sv_players[i]->name, + * MAXPLAYERNAME); + * M_StringCopy(wait_data.player_addrs[i], + * NET_AddrToString(sv_players[i]->addr), + * MAXPLAYERNAME); + * } + * + * // Construct packet + * packet = NET_NewPacket(10); + * NET_WriteInt16(packet, NET_PACKET_TYPE_WAITING_DATA); + * NET_WriteWaitData(packet, &wait_data); + * + * // Send packet to client and free + * NET_Conn_SendPacket(&client->connection, packet); + * NET_FreePacket(packet); + */ } -// Find the latest tic which has been acknowledged as received by -// all clients. - +/* + * Find the latest tic which has been acknowledged as received by + * all clients. + */ static unsigned int NET_SV_LatestAcknowledged(void) { unsigned int lowtic = UINT_MAX; int i; - for (i=0; iactive = true; - client->connect_time = I_GetTimeMS(); - NET_Conn_InitServer(&client->connection, addr, protocol); - client->addr = addr; - client->last_send_time = -1; - - // init the ticcmd send queue - - client->sendseq = 0; - client->acknowledged = 0; - client->drone = false; - client->ready = false; - - client->last_gamedata_time = 0; - - memset(client->sendqueue, 0xff, sizeof(client->sendqueue)); - */ + /* + * // NRFD-TODO + * client->active = true; + * client->connect_time = I_GetTimeMS(); + * NET_Conn_InitServer(&client->connection, addr, protocol); + * client->addr = addr; + * client->last_send_time = -1; + * + * // Init the ticcmd send queue + * client->sendseq = 0; + * client->acknowledged = 0; + * client->drone = false; + * client->ready = false; + * + * client->last_gamedata_time = 0; + * + * memset(client->sendqueue, 0xff, sizeof(client->sendqueue)); + */ } -// parse a SYN from a client(initiating a connection) - +/* Parse a SYN from a client(initiating a connection). */ static void NET_SV_ParseSYN(net_packet_t *packet, net_client_t *client, net_addr_t *addr) { + /* + * // NRFD-TODO + * unsigned int magic; + * net_connect_data_t data; + * net_packet_t *reply; + * net_protocol_t protocol; + * char *player_name; + * char *client_version; + * int num_players; + * int i; + * + * // Read the magic number and check it is the expected one + * if (!NET_ReadInt32(packet, &magic)) + * { + * return; + * } + * + * switch (magic) + * { + * case NET_MAGIC_NUMBER: + * break; + * + * case NET_OLD_MAGIC_NUMBER: + * NET_SV_SendReject(addr, + * "You are using an old client version that is not supported by " + * "this server. This server is running " PACKAGE_STRING "."); + * return; + * + * default: + * return; + * } + * + * // Read the client version string. We actually now only use this when + * // sending a reject message, as we only reject if we can't negotiate a + * // common protocol (below). + * client_version = NET_ReadString(packet); + * if (client_version == NULL) + * { + * return; + * } + * + * // Read the client's list of accepted protocols. Net play between forks + * // of Chocolate Doom is accepted provided that they can negotiate a + * // common accepted protocol. + * protocol = NET_ReadProtocolList(packet); + * if (protocol == NET_PROTOCOL_UNKNOWN) + * { + * char reject_msg[256]; + * + * M_snprintf(reject_msg, sizeof(reject_msg), + * "Version mismatch: server version is: " PACKAGE_STRING "; " + * "client is: %s. No common compatible protocol could be " + * "negotiated.", + * client_version); + * NET_SV_SendReject(addr, reject_msg); + * return; + * } + * + * // Read connect data, and check that the game mode/mission are valid + * // and the max_players value is in a sensible range. + * if (!NET_ReadConnectData(packet, &data) || !D_ValidGameMode(data.gamemission, data.gamemode) || data.max_players > NET_MAXPLAYERS) + * { + * return; + * } + * + * // Read the player's name + * player_name = NET_ReadString(packet); + * if (player_name == NULL) + * { + * return; + * } + * + * // At this point we have received a valid SYN. + * // Not accepting new connections. + * if (server_state != SERVER_WAITING_LAUNCH) + * { + * NET_SV_SendReject(addr, + * "Server is not currently accepting connections"); + * return; + * } + * + * // Before accepting a new client, check that there is a slot free + * NET_SV_AssignPlayers(); + * num_players = NET_SV_NumPlayers(); + * + * if ((!data.drone && num_players >= NET_SV_MaxPlayers()) || NET_SV_NumClients() >= MAXNETNODES) + * { + * NET_SV_SendReject(addr, "Server is full!"); + * return; + * } + * + * // TODO + * // Add server option to allow rejecting clients which set + * // lowres_turn. This is potentially desirable as the presence of such + * // clients affects turning resolution. + * + * // Adopt the game mode and mission of the first connecting client + * if (num_players == 0 && !data.drone) + * { + * sv_gamemode = data.gamemode; + * sv_gamemission = data.gamemission; + * } + * + * // Check the connecting client is playing the same game as all + * // the other clients. + * if (data.gamemode != sv_gamemode || data.gamemission != sv_gamemission) + * { + * NET_SV_SendReject(addr, "You are playing the wrong game!"); + * return; + * } + * + * // Allocate a client slot if there isn't one already + * if (client == NULL) + * { + * // Find a slot, or return if none found + * for (i = 0; i < MAXNETNODES; ++i) + * { + * if (!clients[i].active) + * { + * client = &clients[i]; + * break; + * } + * } + * + * if (client == NULL) + * { + * return; + * } + * } + * else + * { + * // If this is a recently disconnected client, deactivate + * // to allow immediate reconnection. + * if (client->connection.state == NET_CONN_STATE_DISCONNECTED) + * { + * client->active = false; + * } + * } + * + * // Client already connected + * if (client->active) + * { + * return; + * } + * + * // Activate, initialize connection + * NET_SV_InitNewClient(client, addr, protocol); + * + * // Save the SHA1 checksums and other details + * memcpy(client->wad_sha1sum, data.wad_sha1sum, sizeof(sha1_digest_t)); + * memcpy(client->deh_sha1sum, data.deh_sha1sum, sizeof(sha1_digest_t)); + * client->is_freedoom = data.is_freedoom; + * client->max_players = data.max_players; + * client->name = M_StringDuplicate(player_name); + * client->recording_lowres = data.lowres_turn; + * client->drone = data.drone; + * client->player_class = data.player_class; + * + * // Send a reply back to the client, indicating a successful connection + * // and specifying the protocol that will be used for communications. + * reply = NET_Conn_NewReliable(&client->connection, NET_PACKET_TYPE_SYN); + * NET_WriteString(reply, PACKAGE_STRING); + * NET_WriteProtocol(reply, protocol); + */ +} - printf("NRFD-TODO: NET_SV_ParseSYN \n"); /* - unsigned int magic; - net_connect_data_t data; - net_packet_t *reply; - net_protocol_t protocol; - char *player_name; - char *client_version; - int num_players; - int i; - - // Read the magic number and check it is the expected one. - if (!NET_ReadInt32(packet, &magic)) - { - return; - } - - switch (magic) - { - case NET_MAGIC_NUMBER: - break; - - case NET_OLD_MAGIC_NUMBER: - NET_SV_SendReject(addr, - "You are using an old client version that is not supported by " - "this server. This server is running " PACKAGE_STRING "."); - return; - - default: - return; - } - - // Read the client version string. We actually now only use this when - // sending a reject message, as we only reject if we can't negotiate a - // common protocol (below). - client_version = NET_ReadString(packet); - if (client_version == NULL) - { - return; - } - - // Read the client's list of accepted protocols. Net play between forks - // of Chocolate Doom is accepted provided that they can negotiate a - // common accepted protocol. - protocol = NET_ReadProtocolList(packet); - if (protocol == NET_PROTOCOL_UNKNOWN) - { - char reject_msg[256]; - - M_snprintf(reject_msg, sizeof(reject_msg), - "Version mismatch: server version is: " PACKAGE_STRING "; " - "client is: %s. No common compatible protocol could be " - "negotiated.", client_version); - NET_SV_SendReject(addr, reject_msg); - return; - } - - // Read connect data, and check that the game mode/mission are valid - // and the max_players value is in a sensible range. - if (!NET_ReadConnectData(packet, &data) - || !D_ValidGameMode(data.gamemission, data.gamemode) - || data.max_players > NET_MAXPLAYERS) - { - return; - } +/* + * Parse a launch packet. This is sent by the key player when the "start" + * button is pressed, and causes the startup process to continue. + */ +static void NET_SV_ParseLaunch(net_packet_t *packet, net_client_t *client) +{ + /* + * // NRFD-TODO + * net_packet_t *launchpacket; + * int num_players; + * unsigned int i; + * + * // Only the controller can launch the game + * if (client != NET_SV_Controller()) + * { + * return; + * } + * + * // Can only launch when we are in the waiting state + * if (server_state != SERVER_WAITING_LAUNCH) + * { + * return; + * } + * + * // Forward launch on to all clients + * NET_SV_AssignPlayers(); + * num_players = NET_SV_NumPlayers(); + * + * for (i = 0; i < MAXNETNODES; ++i) + * { + * if (!ClientConnected(&clients[i])) + * continue; + * + * launchpacket = NET_Conn_NewReliable(&clients[i].connection, + * NET_PACKET_TYPE_LAUNCH); + * NET_WriteInt8(launchpacket, num_players); + * } + * + * // Now in launch state + * server_state = SERVER_WAITING_START; + */ +} - // Read the player's name - player_name = NET_ReadString(packet); - if (player_name == NULL) - { - return; - } +/* + * Transition to the in game state and send all players the start game + * message. Invoked once all players have indicated they are ready to + * start the game. + */ +static void StartGame(void) +{ + /* + * // NRFD-TODO + * net_packet_t *startpacket; + * unsigned int i; + * int nowtime; + * + * // Assign player numbers + * NET_SV_AssignPlayers(); + * + * // Check if anyone is recording a demo and set lowres_turn if so + * sv_settings.lowres_turn = false; + * + * for (i = 0; i < NET_MAXPLAYERS; ++i) + * { + * if (sv_players[i] != NULL && sv_players[i]->recording_lowres) + * { + * sv_settings.lowres_turn = true; + * } + * } + * + * sv_settings.num_players = NET_SV_NumPlayers(); + * + * // Copy player classes + * for (i = 0; i < NET_MAXPLAYERS; ++i) + * { + * if (sv_players[i] != NULL) + * { + * sv_settings.player_classes[i] = sv_players[i]->player_class; + * } + * else + * { + * sv_settings.player_classes[i] = 0; + * } + * } + * + * nowtime = I_GetTimeMS(); + * + * // Send start packets to each connected node + * for (i = 0; i < MAXNETNODES; ++i) + * { + * if (!ClientConnected(&clients[i])) + * continue; + * + * clients[i].last_gamedata_time = nowtime; + * + * startpacket = NET_Conn_NewReliable(&clients[i].connection, + * NET_PACKET_TYPE_GAMESTART); + * + * sv_settings.consoleplayer = clients[i].player_number; + * + * NET_WriteSettings(startpacket, &sv_settings); + * } + * + * // Change server state + * server_state = SERVER_IN_GAME; + * + * memset(recvwindow, 0, sizeof(recvwindow)); + * recvwindow_start = 0; + */ +} - // At this point we have received a valid SYN. +/* Returns true when all nodes have indicated readiness to start the game. */ +static boolean AllNodesReady(void) +{ + unsigned int i; - // Not accepting new connections? - if (server_state != SERVER_WAITING_LAUNCH) + for (i = 0; i < MAXNETNODES; ++i) { - NET_SV_SendReject(addr, - "Server is not currently accepting connections"); - return; + if (ClientConnected(&clients[i]) && !clients[i].ready) + { + return false; + } } - // Before accepting a new client, check that there is a slot free. - NET_SV_AssignPlayers(); - num_players = NET_SV_NumPlayers(); + return true; +} - if ((!data.drone && num_players >= NET_SV_MaxPlayers()) - || NET_SV_NumClients() >= MAXNETNODES) - { - NET_SV_SendReject(addr, "Server is full!"); - return; - } +/* Check if the game should start, and if so, start it. */ +static void CheckStartGame(void) +{ + /* + * // NRFD-TODO + * if (AllNodesReady()) + * { + * StartGame(); + * } + */ +} - // TODO: Add server option to allow rejecting clients which set - // lowres_turn. This is potentially desirable as the presence of such - // clients affects turning resolution. +/* + * Send waiting data with current status to all nodes that are ready to + * start the game. + */ +static void SendAllWaitingData(void) +{ + /* + * // NRFD-TODO + * unsigned int i; + * + * for (i = 0; i < MAXNETNODES; ++i) + * { + * if (ClientConnected(&clients[i]) && clients[i].ready) + * { + * NET_SV_SendWaitingData(&clients[i]); + * } + * } + */ +} - // Adopt the game mode and mission of the first connecting client: - if (num_players == 0 && !data.drone) - { - sv_gamemode = data.gamemode; - sv_gamemission = data.gamemission; - } +/* Parse a game start packet. */ +static void NET_SV_ParseGameStart(net_packet_t *packet, net_client_t *client) +{ + /* + * // NRFD-TODO + net_gamesettings_t settings; - // Check the connecting client is playing the same game as all - // the other clients - if (data.gamemode != sv_gamemode || data.gamemission != sv_gamemission) + // Can only start a game if we are in the waiting start state + if (server_state != SERVER_WAITING_START) { - NET_SV_SendReject(addr, "You are playing the wrong game!"); return; } - // Allocate a client slot if there isn't one already - if (client == NULL) + if (client == NET_SV_Controller()) { - // find a slot, or return if none found - - for (i=0; iconnection.state == NET_CONN_STATE_DISCONNECTED) - { - client->active = false; - } + sv_settings = settings; } - // Client already connected? - if (client->active) - { - return; - } + client->ready = true; + + CheckStartGame(); - // Activate, initialize connection - NET_SV_InitNewClient(client, addr, protocol); - - // Save the SHA1 checksums and other details. - memcpy(client->wad_sha1sum, data.wad_sha1sum, sizeof(sha1_digest_t)); - memcpy(client->deh_sha1sum, data.deh_sha1sum, sizeof(sha1_digest_t)); - client->is_freedoom = data.is_freedoom; - client->max_players = data.max_players; - client->name = M_StringDuplicate(player_name); - client->recording_lowres = data.lowres_turn; - client->drone = data.drone; - client->player_class = data.player_class; - - // Send a reply back to the client, indicating a successful connection - // and specifying the protocol that will be used for communications. - reply = NET_Conn_NewReliable(&client->connection, NET_PACKET_TYPE_SYN); - NET_WriteString(reply, PACKAGE_STRING); - NET_WriteProtocol(reply, protocol); + // Update all ready clients with the current state (number of players + // ready, etc.). This is used by games that show startup progress + // (e.g. Hexen's spinal loading) + SendAllWaitingData(); */ } -// Parse a launch packet. This is sent by the key player when the "start" -// button is pressed, and causes the startup process to continue. +/* Send a resend request to a client. */ +static void NET_SV_SendResendRequest(net_client_t *client, int start, int end) +{ + /* + * // NRFD-TODO + * net_packet_t *packet; + * net_client_recv_t *recvobj; + * int i; + * unsigned int nowtime; + * int index; + * + * packet = NET_NewPacket(20); + * + * NET_WriteInt16(packet, NET_PACKET_TYPE_GAMEDATA_RESEND); + * NET_WriteInt32(packet, start); + * NET_WriteInt8(packet, end - start + 1); + * + * NET_Conn_SendPacket(&client->connection, packet); + * NET_FreePacket(packet); + * + * // Store the time we send the resend request + * nowtime = I_GetTimeMS(); + * + * for (i = start; i <= end; ++i) + * { + * index = i - recvwindow_start; + * + * if (index >= BACKUPTICS) + * { + * // Outside the range + * continue; + * } + * + * recvobj = &recvwindow[index][client->player_number]; + * + * recvobj->resend_time = nowtime; + * } + */ +} -static void NET_SV_ParseLaunch(net_packet_t *packet, net_client_t *client) +/* Check for expired resend requests. */ +static void NET_SV_CheckResends(net_client_t *client) { - printf("NRFD-TODO: NET_SV_ParseLaunch \n"); /* - net_packet_t *launchpacket; - int num_players; - unsigned int i; + /* + * // NRFD-TODO + * int i; + * int player; + * int resend_start, resend_end; + * unsigned int nowtime; + * + * nowtime = I_GetTimeMS(); + * + * player = client->player_number; + * resend_start = -1; + * resend_end = -1; + * + * for (i = 0; i < BACKUPTICS; ++i) + * { + * net_client_recv_t *recvobj; + * boolean need_resend; + * + * recvobj = &recvwindow[i][player]; + * + * // If need_resend is true, this tic needs another retransmit + * // request (300ms timeout). + * need_resend = !recvobj->active && recvobj->resend_time != 0 && nowtime > recvobj->resend_time + 300; + * + * if (need_resend) + * { + * // Start a new run of resend tics + * if (resend_start < 0) + * { + * resend_start = i; + * } + * + * resend_end = i; + * } + * else + * { + * if (resend_start >= 0) + * { + * // End of a run of resend tics + * NET_SV_SendResendRequest(client, + * recvwindow_start + resend_start, + * recvwindow_start + resend_end); + * + * resend_start = -1; + * } + * } + * } + * + * if (resend_start >= 0) + * { + * NET_SV_SendResendRequest(client, + * recvwindow_start + resend_start, + * recvwindow_start + resend_end); + * } + */ +} - // Only the controller can launch the game. +/* Process game data from a client. */ +static void NET_SV_ParseGameData(net_packet_t *packet, net_client_t *client) +{ + /* + * // NRFD-TODO + * net_client_recv_t *recvobj; + * unsigned int seq; + * unsigned int ackseq; + * unsigned int num_tics; + * unsigned int nowtime; + * size_t i; + * int player; + * int resend_start, resend_end; + * int index; + * + * if (server_state != SERVER_IN_GAME) + * { + * return; + * } + * + * if (client->drone) + * { + * // Drones do not contribute any game data + * return; + * } + * + * player = client->player_number; + * + * // Read header + * if (!NET_ReadInt8(packet, &ackseq) || !NET_ReadInt8(packet, &seq) || !NET_ReadInt8(packet, &num_tics)) + * { + * return; + * } + * + * // Get the current time + * nowtime = I_GetTimeMS(); + * + * // Expand 8 bit values to the full sequence number + * ackseq = NET_SV_ExpandTicNum(ackseq); + * seq = NET_SV_ExpandTicNum(seq); + * + * // Sanity checks + * for (i = 0; i < num_tics; ++i) + * { + * net_ticdiff_t diff; + * signed int latency; + * + * if (!NET_ReadSInt16(packet, &latency) || !NET_ReadTiccmdDiff(packet, &diff, sv_settings.lowres_turn)) + * { + * return; + * } + * + * index = seq + i - recvwindow_start; + * + * if (index < 0 || index >= BACKUPTICS) + * { + * // Not in range of the recv window + * continue; + * } + * + * recvobj = &recvwindow[index][player]; + * recvobj->active = true; + * recvobj->diff = diff; + * recvobj->latency = latency; + * + * client->last_gamedata_time = nowtime; + * } + * + * // Higher acknowledgement point + * if (ackseq > client->acknowledged) + * { + * client->acknowledged = ackseq; + * } + * + * // Has this been received out of sequence, i.e. have we not received + * // all tics before the first tic in this packet? If so, send a + * // resend request. + * resend_end = seq - recvwindow_start; + * + * if (resend_end <= 0) + * return; + * + * if (resend_end >= BACKUPTICS) + * resend_end = BACKUPTICS - 1; + * + * index = resend_end - 1; + * resend_start = resend_end; + * + * while (index >= 0) + * { + * recvobj = &recvwindow[index][player]; + * + * if (recvobj->active) + * { + * // Ended our run of unreceived tics + * break; + * } + * + * if (recvobj->resend_time != 0) + * { + * // Already sent a resend request for this tic + * break; + * } + * + * resend_start = index; + * --index; + * } + * + * // Possibly send a resend request + * if (resend_start < resend_end) + * { + * NET_SV_SendResendRequest(client, + * recvwindow_start + resend_start, + * recvwindow_start + resend_end - 1); + * } + */ +} - if (client != NET_SV_Controller()) - { - return; - } +static void NET_SV_ParseGameDataACK(net_packet_t *packet, net_client_t *client) +{ + /* + * // NRFD-TODO + * unsigned int ackseq; + * + * if (server_state != SERVER_IN_GAME) + * { + * return; + * } + * + * // Read header + * if (!NET_ReadInt8(packet, &ackseq)) + * { + * return; + * } + * + * // Expand 8 bit values to the full sequence number + * ackseq = NET_SV_ExpandTicNum(ackseq); + * + * // Higher acknowledgement point than we already have + * if (ackseq > client->acknowledged) + * { + * client->acknowledged = ackseq; + * } + */ +} - // Can only launch when we are in the waiting state. +static void NET_SV_SendTics(net_client_t *client, + unsigned int start, unsigned int end) +{ + /* + * // NRFD-TODO + * net_packet_t *packet; + * unsigned int i; + * + * packet = NET_NewPacket(500); + * + * NET_WriteInt16(packet, NET_PACKET_TYPE_GAMEDATA); + * + * // Send the start tic and number of tics + * NET_WriteInt8(packet, start & 0xff); + * NET_WriteInt8(packet, end - start + 1); + * + * // Write the tics + * for (i = start; i <= end; ++i) + * { + * net_full_ticcmd_t *cmd; + * + * cmd = &client->sendqueue[i % BACKUPTICS]; + * + * if (i != cmd->seq) + * { + * I_Error("Wanted to send %i, but %i is in its place", i, cmd->seq); + * } + * + * // Add command + * NET_WriteFullTiccmd(packet, cmd, sv_settings.lowres_turn); + * } + * + * // Send packet + * NET_Conn_SendPacket(&client->connection, packet); + * + * NET_FreePacket(packet); + */ +} - if (server_state != SERVER_WAITING_LAUNCH) - { - return; - } +/* Parse a retransmission request from a client. */ +static void NET_SV_ParseResendRequest(net_packet_t *packet, net_client_t *client) +{ + /* + * NRFD-TODO + * unsigned int start, last; + * unsigned int num_tics; + * unsigned int i; + * + * // Read the starting tic and number of tics + * if (!NET_ReadInt32(packet, &start) || !NET_ReadInt8(packet, &num_tics)) + * { + * return; + * } + * + * // Check we have all the requested tics + * last = start + num_tics - 1; + * + * for (i = start; i <= last; ++i) + * { + * net_full_ticcmd_t *cmd; + * + * cmd = &client->sendqueue[i % BACKUPTICS]; + * + * if (i != cmd->seq) + * { + * // We do not have the requested tic (any more). + * // This is pretty fatal. We could disconnect the client, + * // but then again this could be a spoofed packet. + * // Just ignore it. + * return; + * } + * } + * + * // Resend those tics + * NET_SV_SendTics(client, start, last); + */ +} - // Forward launch on to all clients. +/* Send a response back to the client. */ +void NET_SV_SendQueryResponse(net_addr_t *addr) +{ + /* + * // NRFD-TODO + * net_packet_t *reply; + * net_querydata_t querydata; + * int p; + * + * // Version + * querydata.version = PACKAGE_STRING; + * + * // Server state + * querydata.server_state = server_state; + * + * // Number of players/maximum players + * querydata.num_players = NET_SV_NumPlayers(); + * querydata.max_players = NET_SV_MaxPlayers(); + * + * // Game mode/mission + * querydata.gamemode = sv_gamemode; + * querydata.gamemission = sv_gamemission; + * + * //! + * // @category net + * // @arg + * // + * // When starting a network server, specify a name for the server. + * // + * p = M_CheckParmWithArgs("-servername", 1); + * + * if (p > 0) + * { + * querydata.description = myargv[p + 1]; + * } + * else + * { + * querydata.description = "Unnamed server"; + * } + * + * // Send it and we're done + * reply = NET_NewPacket(64); + * NET_WriteInt16(reply, NET_PACKET_TYPE_QUERY_RESPONSE); + * NET_WriteQueryData(reply, &querydata); + * NET_SendPacket(addr, reply); + * NET_FreePacket(reply); + */ +} - NET_SV_AssignPlayers(); - num_players = NET_SV_NumPlayers(); +/* Process a packet received by the server. */ +static void NET_SV_Packet(net_packet_t *packet, net_addr_t *addr) +{ + /* + * // NRFD-TODO + * net_client_t *client; + * unsigned int packet_type; + * + * // Response from master server + * if (addr != NULL && addr == master_server) + * { + * NET_Query_MasterResponse(packet); + * return; + * } + * + * // Find which client this packet came from + * client = NET_SV_FindClient(addr); + * + * // Read the packet type + * if (!NET_ReadInt16(packet, &packet_type)) + * { + * // No packet type + * return; + * } + * + * if (packet_type == NET_PACKET_TYPE_SYN) + * { + * NET_SV_ParseSYN(packet, client, addr); + * } + * else if (packet_type == NET_PACKET_TYPE_QUERY) + * { + * NET_SV_SendQueryResponse(addr); + * } + * else if (client == NULL) + * { + * // Must come from a valid client, ignore otherwise + * } + * else if (NET_Conn_Packet(&client->connection, packet, &packet_type)) + * { + * // Packet was eaten by the common connection code + * } + * else + * { + * switch (packet_type) + * { + * case NET_PACKET_TYPE_GAMESTART: + * NET_SV_ParseGameStart(packet, client); + * break; + * case NET_PACKET_TYPE_LAUNCH: + * NET_SV_ParseLaunch(packet, client); + * break; + * case NET_PACKET_TYPE_GAMEDATA: + * NET_SV_ParseGameData(packet, client); + * break; + * case NET_PACKET_TYPE_GAMEDATA_ACK: + * NET_SV_ParseGameDataACK(packet, client); + * break; + * case NET_PACKET_TYPE_GAMEDATA_RESEND: + * NET_SV_ParseResendRequest(packet, client); + * break; + * default: + * // Unknown packet type + * break; + * } + * } + * + * // If this address is not in the list of clients, be sure to + * // free it back. + * if (NET_SV_FindClient(addr) == NULL) + * { + * NET_FreeAddress(addr); + * } + */ +} - for (i=0; irecording_lowres) - { - sv_settings.lowres_turn = true; - } - } - - sv_settings.num_players = NET_SV_NumPlayers(); - - // Copy player classes: - - for (i = 0; i < NET_MAXPLAYERS; ++i) - { - if (sv_players[i] != NULL) - { - sv_settings.player_classes[i] = sv_players[i]->player_class; - } - else - { - sv_settings.player_classes[i] = 0; - } - } - - nowtime = I_GetTimeMS(); - - // Send start packets to each connected node - - for (i = 0; i < MAXNETNODES; ++i) - { - if (!ClientConnected(&clients[i])) - continue; - - clients[i].last_gamedata_time = nowtime; - - startpacket = NET_Conn_NewReliable(&clients[i].connection, - NET_PACKET_TYPE_GAMESTART); - - sv_settings.consoleplayer = clients[i].player_number; - - NET_WriteSettings(startpacket, &sv_settings); - } - - // Change server state - - server_state = SERVER_IN_GAME; - - memset(recvwindow, 0, sizeof(recvwindow)); - recvwindow_start = 0; - */ -} - -// Returns true when all nodes have indicated readiness to start the game. - -static boolean AllNodesReady(void) -{ - unsigned int i; - - for (i = 0; i < MAXNETNODES; ++i) - { - if (ClientConnected(&clients[i]) && !clients[i].ready) - { - return false; - } - } - - return true; -} - -// Check if the game should start, and if so, start it. - -static void CheckStartGame(void) -{ - printf("NRFD-TODO: CheckStartGame \n"); /* - if (AllNodesReady()) - { - StartGame(); - } - */ -} - -// Send waiting data with current status to all nodes that are ready to -// start the game. - -static void SendAllWaitingData(void) -{ - printf("NRFD-TODO: SendAllWaitingData \n"); /* - unsigned int i; - - for (i = 0; i < MAXNETNODES; ++i) - { - if (ClientConnected(&clients[i]) && clients[i].ready) - { - NET_SV_SendWaitingData(&clients[i]); - } - } - */ -} - -// Parse a game start packet - -static void NET_SV_ParseGameStart(net_packet_t *packet, net_client_t *client) -{ - printf("NRFD-TODO: NET_SV_ParseGameStart \n"); /* - net_gamesettings_t settings; - - // Can only start a game if we are in the waiting start state. - - if (server_state != SERVER_WAITING_START) - { - return; - } - - if (client == NET_SV_Controller()) - { - if (!NET_ReadSettings(packet, &settings)) - { - // Malformed packet - - return; - } - - // Check the game settings are valid - - if (!NET_ValidGameSettings(sv_gamemode, sv_gamemission, &settings)) - { - return; - } - - sv_settings = settings; - } - - client->ready = true; - - CheckStartGame(); - - // Update all ready clients with the current state (number of players - // ready, etc.). This is used by games that show startup progress - // (eg. Hexen's spinal loading) - - SendAllWaitingData(); - */ -} - -// Send a resend request to a client - -static void NET_SV_SendResendRequest(net_client_t *client, int start, int end) -{ - printf("NRFD-TODO: NET_SV_SendResendRequest \n"); /* - net_packet_t *packet; - net_client_recv_t *recvobj; - int i; - unsigned int nowtime; - int index; - - //printf("SV: send resend for %i-%i\n", start, end); - - packet = NET_NewPacket(20); - - NET_WriteInt16(packet, NET_PACKET_TYPE_GAMEDATA_RESEND); - NET_WriteInt32(packet, start); - NET_WriteInt8(packet, end - start + 1); - - NET_Conn_SendPacket(&client->connection, packet); - NET_FreePacket(packet); - - // Store the time we send the resend request - - nowtime = I_GetTimeMS(); - - for (i=start; i<=end; ++i) - { - index = i - recvwindow_start; - - if (index >= BACKUPTICS) - { - // Outside the range - - continue; - } - - recvobj = &recvwindow[index][client->player_number]; - - recvobj->resend_time = nowtime; - } -*/ -} - -// Check for expired resend requests - -static void NET_SV_CheckResends(net_client_t *client) -{ - printf("NRFD-TODO: NET_SV_CheckResends \n"); /* - int i; - int player; - int resend_start, resend_end; - unsigned int nowtime; - - nowtime = I_GetTimeMS(); - - player = client->player_number; - resend_start = -1; - resend_end = -1; - - for (i=0; iactive - && recvobj->resend_time != 0 - && nowtime > recvobj->resend_time + 300; - - if (need_resend) - { - // Start a new run of resend tics? - - if (resend_start < 0) - { - resend_start = i; - } - - resend_end = i; - } - else - { - if (resend_start >= 0) - { - // End of a run of resend tics - - //printf("SV: resend request timed out: %i-%i\n", resend_start, resend_end); - NET_SV_SendResendRequest(client, - recvwindow_start + resend_start, - recvwindow_start + resend_end); - - resend_start = -1; - } - } - } - - if (resend_start >= 0) - { - NET_SV_SendResendRequest(client, - recvwindow_start + resend_start, - recvwindow_start + resend_end); - } - */ -} - -// Process game data from a client - -static void NET_SV_ParseGameData(net_packet_t *packet, net_client_t *client) -{ - printf("NRFD-TODO: NET_SV_ParseGameData \n"); /* - net_client_recv_t *recvobj; - unsigned int seq; - unsigned int ackseq; - unsigned int num_tics; - unsigned int nowtime; - size_t i; - int player; - int resend_start, resend_end; - int index; - - if (server_state != SERVER_IN_GAME) - { - return; - } - - if (client->drone) - { - // Drones do not contribute any game data. - return; - } - - player = client->player_number; - - // Read header - - if (!NET_ReadInt8(packet, &ackseq) - || !NET_ReadInt8(packet, &seq) - || !NET_ReadInt8(packet, &num_tics)) - { - return; - } - - // Get the current time - - nowtime = I_GetTimeMS(); - - // Expand 8-bit values to the full sequence number - - ackseq = NET_SV_ExpandTicNum(ackseq); - seq = NET_SV_ExpandTicNum(seq); - - // Sanity checks - - for (i=0; i= BACKUPTICS) - { - // Not in range of the recv window - - continue; - } - - recvobj = &recvwindow[index][player]; - recvobj->active = true; - recvobj->diff = diff; - recvobj->latency = latency; - - client->last_gamedata_time = nowtime; - } - - // Higher acknowledgement point? - - if (ackseq > client->acknowledged) - { - client->acknowledged = ackseq; - } - - // Has this been received out of sequence, ie. have we not received - // all tics before the first tic in this packet? If so, send a - // resend request. - - //printf("SV: %p: %i\n", client, seq); - - resend_end = seq - recvwindow_start; - - if (resend_end <= 0) - return; - - if (resend_end >= BACKUPTICS) - resend_end = BACKUPTICS - 1; - - index = resend_end - 1; - resend_start = resend_end; - - while (index >= 0) - { - recvobj = &recvwindow[index][player]; - - if (recvobj->active) - { - // ended our run of unreceived tics - - break; - } - - if (recvobj->resend_time != 0) - { - // Already sent a resend request for this tic - - break; - } - - resend_start = index; - --index; - } - - // Possibly send a resend request - - if (resend_start < resend_end) - { - - NET_SV_SendResendRequest(client, - recvwindow_start + resend_start, - recvwindow_start + resend_end - 1); - } - - */ -} - -static void NET_SV_ParseGameDataACK(net_packet_t *packet, net_client_t *client) -{ - printf("NRFD-TODO: NET_SV_ParseGameDataACK \n"); /* - unsigned int ackseq; - - if (server_state != SERVER_IN_GAME) - { - return; - } - - // Read header - - if (!NET_ReadInt8(packet, &ackseq)) - { - return; - } - - // Expand 8-bit values to the full sequence number - - ackseq = NET_SV_ExpandTicNum(ackseq); - - // Higher acknowledgement point than we already have? - - if (ackseq > client->acknowledged) - { - client->acknowledged = ackseq; - } - */ -} - -static void NET_SV_SendTics(net_client_t *client, - unsigned int start, unsigned int end) -{ - printf("NRFD-TODO: NET_SV_SendTics \n"); /* - net_packet_t *packet; - unsigned int i; - - packet = NET_NewPacket(500); - - NET_WriteInt16(packet, NET_PACKET_TYPE_GAMEDATA); - - // Send the start tic and number of tics - - NET_WriteInt8(packet, start & 0xff); - NET_WriteInt8(packet, end-start + 1); - - // Write the tics - - for (i=start; i<=end; ++i) - { - net_full_ticcmd_t *cmd; - - cmd = &client->sendqueue[i % BACKUPTICS]; - - if (i != cmd->seq) - { - I_Error("Wanted to send %i, but %i is in its place", i, cmd->seq); - } - - // Add command - - NET_WriteFullTiccmd(packet, cmd, sv_settings.lowres_turn); - } - - // Send packet - - NET_Conn_SendPacket(&client->connection, packet); - - NET_FreePacket(packet); - */ -} - -// Parse a retransmission request from a client - -static void NET_SV_ParseResendRequest(net_packet_t *packet, net_client_t *client) -{ - printf("NRFD-TODO: NET_SV_ParseResendRequest \n"); /* - unsigned int start, last; - unsigned int num_tics; - unsigned int i; - - // Read the starting tic and number of tics - - if (!NET_ReadInt32(packet, &start) - || !NET_ReadInt8(packet, &num_tics)) - { - return; - } - - //printf("SV: %p: resend %i-%i\n", client, start, start+num_tics-1); - - // Check we have all the requested tics - - last = start + num_tics - 1; - - for (i=start; i<=last; ++i) - { - net_full_ticcmd_t *cmd; - - cmd = &client->sendqueue[i % BACKUPTICS]; - - if (i != cmd->seq) - { - // We do not have the requested tic (any more) - // This is pretty fatal. We could disconnect the client, - // but then again this could be a spoofed packet. Just - // ignore it. - - return; - } - } - - // Resend those tics - - NET_SV_SendTics(client, start, last); - */ -} - -// Send a response back to the client - -void NET_SV_SendQueryResponse(net_addr_t *addr) -{ - printf("NRFD-TODO: NET_SV_SendQueryResponse\n");/* - net_packet_t *reply; - net_querydata_t querydata; - int p; - - // Version - - querydata.version = PACKAGE_STRING; - - // Server state - - querydata.server_state = server_state; - - // Number of players/maximum players - - querydata.num_players = NET_SV_NumPlayers(); - querydata.max_players = NET_SV_MaxPlayers(); - - // Game mode/mission - - querydata.gamemode = sv_gamemode; - querydata.gamemission = sv_gamemission; - - //! - // @category net - // @arg - // - // When starting a network server, specify a name for the server. - // - - p = M_CheckParmWithArgs("-servername", 1); - - if (p > 0) - { - querydata.description = myargv[p + 1]; - } - else - { - querydata.description = "Unnamed server"; - } - - // Send it and we're done. - - reply = NET_NewPacket(64); - NET_WriteInt16(reply, NET_PACKET_TYPE_QUERY_RESPONSE); - NET_WriteQueryData(reply, &querydata); - NET_SendPacket(addr, reply); - NET_FreePacket(reply); - */ -} - -// Process a packet received by the server - -static void NET_SV_Packet(net_packet_t *packet, net_addr_t *addr) -{ - printf("NRFD-TODO: NET_SV_Packet \n"); /* - net_client_t *client; - unsigned int packet_type; - - // Response from master server? - - if (addr != NULL && addr == master_server) - { - NET_Query_MasterResponse(packet); - return; - } - - // Find which client this packet came from - - client = NET_SV_FindClient(addr); - - // Read the packet type - - if (!NET_ReadInt16(packet, &packet_type)) - { - // no packet type - - return; - } - - if (packet_type == NET_PACKET_TYPE_SYN) - { - NET_SV_ParseSYN(packet, client, addr); - } - else if (packet_type == NET_PACKET_TYPE_QUERY) - { - NET_SV_SendQueryResponse(addr); - } - else if (client == NULL) - { - // Must come from a valid client; ignore otherwise - } - else if (NET_Conn_Packet(&client->connection, packet, &packet_type)) - { - // Packet was eaten by the common connection code - } - else - { - //printf("SV: %s: %i\n", NET_AddrToString(addr), packet_type); - - switch (packet_type) - { - case NET_PACKET_TYPE_GAMESTART: - NET_SV_ParseGameStart(packet, client); - break; - case NET_PACKET_TYPE_LAUNCH: - NET_SV_ParseLaunch(packet, client); - break; - case NET_PACKET_TYPE_GAMEDATA: - NET_SV_ParseGameData(packet, client); - break; - case NET_PACKET_TYPE_GAMEDATA_ACK: - NET_SV_ParseGameDataACK(packet, client); - break; - case NET_PACKET_TYPE_GAMEDATA_RESEND: - NET_SV_ParseResendRequest(packet, client); - break; - default: - // unknown packet type - - break; - } - } - - // If this address is not in the list of clients, be sure to - // free it back. - - if (NET_SV_FindClient(addr) == NULL) - { - NET_FreeAddress(addr); - } - */ -} - - -static void NET_SV_PumpSendQueue(net_client_t *client) -{ - printf("NRFD-TODO: NET_SV_PumpSendQueue \n"); /* - net_full_ticcmd_t cmd; - int recv_index; - int num_players; - int i; - int starttic, endtic; - - // If a client has not sent any acknowledgments for a while, - // wait until they catch up. - - if (client->sendseq - NET_SV_LatestAcknowledged() > 40) - { - return; - } - - // Work out the index into the receive window - - recv_index = client->sendseq - recvwindow_start; - - if (recv_index < 0 || recv_index >= BACKUPTICS) - { - return; - } - - // Check if we can generate a new entry for the send queue - // using the data in recvwindow. - - num_players = 0; - - for (i=0; isendseq > recvwindow_start + 10) - { - return; - } - - //printf("SV: have complete ticcmd for %i\n", client->sendseq); - - // We have all data we need to generate a command for this tic. - - cmd.seq = client->sendseq; - - // Add ticcmds from all players - - cmd.latency = 0; - - for (i=0; idiff; - - if (recvobj->latency > cmd.latency) - cmd.latency = recvobj->latency; - } - - //printf("SV: %i: latency %i\n", client->player_number, cmd.latency); - - // Add into the queue - - client->sendqueue[client->sendseq % BACKUPTICS] = cmd; - - // Transmit the new tic to the client - - starttic = client->sendseq - sv_settings.extratics; - endtic = client->sendseq; - - if (starttic < 0) - starttic = 0; - - NET_SV_SendTics(client, starttic, endtic); - - ++client->sendseq; - */ -} - -// Prevent against deadlock: resend requests are usually only -// triggered if we miss a packet and receive the next one. -// If we miss a whole load of packets, we can end up in a -// deadlock situation where the client will not send any more. -// If we don't receive any game data in a while, trigger a resend -// request for the next tic we're expecting. +static void NET_SV_PumpSendQueue(net_client_t *client) +{ + /* + * // NRFD-TODO + * net_full_ticcmd_t cmd; + * int recv_index; + * int num_players; + * int i; + * int starttic, endtic; + * + * // If a client has not sent any acknowledgments for a while, + * // wait until they catch up. + * if (client->sendseq - NET_SV_LatestAcknowledged() > 40) + * { + * return; + * } + * + * // Work out the index into the receive window + * recv_index = client->sendseq - recvwindow_start; + * + * if (recv_index < 0 || recv_index >= BACKUPTICS) + * { + * return; + * } + * + * // Check if we can generate a new entry for the send queue + * // using the data in recvwindow. + * num_players = 0; + * + * for (i = 0; i < NET_MAXPLAYERS; ++i) + * { + * if (sv_players[i] == client) + * { + * // Client does not rely on itself for data + * continue; + * } + * + * if (sv_players[i] == NULL || !ClientConnected(sv_players[i])) + * { + * continue; + * } + * + * if (!recvwindow[recv_index][i].active) + * { + * // We do not have this player's ticcmd, so we cannot + * // generate a complete command yet. + * return; + * } + * + * ++num_players; + * } + * + * // If this is a game with only a single player in it, we might + * // be sending a ticcmd set containing 0 ticcmds. This is fine. + * // However, there's nothing to stop the game running on ahead + * // and never stopping. Don't let the server get too far ahead + * // of the client. + * if (num_players == 0 && client->sendseq > recvwindow_start + 10) + * { + * return; + * } + * + * // We have all data we need to generate a command for this tic + * cmd.seq = client->sendseq; + * + * // Add ticcmds from all players + * cmd.latency = 0; + * + * for (i = 0; i < NET_MAXPLAYERS; ++i) + * { + * net_client_recv_t *recvobj; + * + * if (sv_players[i] == client) + * { + * // Not the player we are sending to + * cmd.playeringame[i] = false; + * continue; + * } + * + * if (sv_players[i] == NULL || !recvwindow[recv_index][i].active) + * { + * cmd.playeringame[i] = false; + * continue; + * } + * + * cmd.playeringame[i] = true; + * + * recvobj = &recvwindow[recv_index][i]; + * + * cmd.cmds[i] = recvobj->diff; + * + * if (recvobj->latency > cmd.latency) + * cmd.latency = recvobj->latency; + * } + * + * // Add into the queue + * client->sendqueue[client->sendseq % BACKUPTICS] = cmd; + * + * // Transmit the new tic to the client + * starttic = client->sendseq - sv_settings.extratics; + * endtic = client->sendseq; + * + * if (starttic < 0) + * starttic = 0; + * + * NET_SV_SendTics(client, starttic, endtic); + * + * ++client->sendseq; + */ +} +/* + * Prevent against deadlock: resend requests are usually only + * triggered if we miss a packet and receive the next one. + * If we miss a whole load of packets, we can end up in a + * deadlock situation where the client will not send any more. + * If we don't receive any game data in a while, trigger a resend + * request for the next tic we're expecting. + */ void NET_SV_CheckDeadlock(net_client_t *client) { - printf("NRFD-TODO: NET_SV_CheckDeadlock\n");/* - int nowtime; - int i; - - // Don't expect game data from clients. - - if (client->drone) - { - return; - } - - nowtime = I_GetTimeMS(); - - // If we haven't received anything for a long time, it may be a deadlock. - - if (nowtime - client->last_gamedata_time > 1000) - { - // Search the receive window for the first tic we are expecting - // from this player. - - for (i=0; iplayer_number][i].active) - { - //printf("Possible deadlock: Sending resend request\n"); - - // Found a tic we haven't received. Send a resend request. - - NET_SV_SendResendRequest(client, - recvwindow_start + i, - recvwindow_start + i + 5); - - client->last_gamedata_time = nowtime; - break; - } - } - } - */ + /* + * // NRFD-TODO + * int nowtime; + * int i; + * + * // Don't expect game data from clients + * if (client->drone) + * { + * return; + * } + * + * nowtime = I_GetTimeMS(); + * + * // If we haven't received anything for a long time, it may be a deadlock. + * if (nowtime - client->last_gamedata_time > 1000) + * { + * // Search the receive window for the first tic we are expecting + * // from this player. + * for (i = 0; i < BACKUPTICS; ++i) + * { + * if (!recvwindow[client->player_number][i].active) + * { + * printf("Possible deadlock: Sending resend request\n"); + * + * // Found a tic we haven't received. Send a resend request. + * NET_SV_SendResendRequest(client, + * recvwindow_start + i, + * recvwindow_start + i + 5); + * + * client->last_gamedata_time = nowtime; + * break; + * } + * } + * } + */ } -// Called when all players have disconnected. Return to listening for -// players to start a new game, and disconnect any drones still connected. - +/* + * Called when all players have disconnected. Return to listening for + * players to start a new game, and disconnect any drones still connected. + */ static void NET_SV_GameEnded(void) { - printf("NRFD-TODO: NET_SV_GameEnded \n"); /* - int i; - - server_state = SERVER_WAITING_LAUNCH; - sv_gamemode = indetermined; - - for (i=0; iconnection); - - if (client->connection.state == NET_CONN_STATE_DISCONNECTED - && client->connection.disconnect_reason == NET_DISCONNECT_TIMEOUT) - { - NET_SV_BroadcastMessage("Client '%s' timed out and disconnected", - client->name); - } - - // Is this client disconnected? - - if (client->connection.state == NET_CONN_STATE_DISCONNECTED) - { - client->active = false; - - // If we were about to start a game, any player disconnecting - // should cause an abort. - - if (server_state == SERVER_WAITING_START && !client->drone) - { - NET_SV_BroadcastMessage("Game startup aborted because " - "player '%s' disconnected.", - client->name); - NET_SV_GameEnded(); - } - - free(client->name); - NET_FreeAddress(client->addr); - - // Are there any clients left connected? If not, return the - // server to the waiting-for-players state. - // - // Disconnect any drones still connected. - - if (NET_SV_NumPlayers() <= 0) - { - NET_SV_GameEnded(); - } - } - - if (!ClientConnected(client)) - { - // client has not yet finished connecting - - return; - } - - if (server_state == SERVER_WAITING_LAUNCH) - { - // Waiting for the game to start - - // Send information once every second - - if (client->last_send_time < 0 - || I_GetTimeMS() - client->last_send_time > 1000) - { - NET_SV_SendWaitingData(client); - client->last_send_time = I_GetTimeMS(); - } - } - - if (server_state == SERVER_IN_GAME) - { - NET_SV_PumpSendQueue(client); - NET_SV_CheckDeadlock(client); - } - */ + /* + * // NRFD-TODO + * // Run common code + * NET_Conn_Run(&client->connection); + * + * if (client->connection.state == NET_CONN_STATE_DISCONNECTED && client->connection.disconnect_reason == NET_DISCONNECT_TIMEOUT) + * { + * NET_SV_BroadcastMessage("Client '%s' timed out and disconnected", + * client->name); + * } + * + * // Is this client disconnected + * if (client->connection.state == NET_CONN_STATE_DISCONNECTED) + * { + * client->active = false; + * + * // If we were about to start a game, any player disconnecting + * // should cause an abort. + * if (server_state == SERVER_WAITING_START && !client->drone) + * { + * NET_SV_BroadcastMessage("Game startup aborted because " + * "player '%s' disconnected.", + * client->name); + * NET_SV_GameEnded(); + * } + * + * free(client->name); + * NET_FreeAddress(client->addr); + * + * // Are there any clients left connected? If not, return the + * // server to the waiting-for-players state. + * // Disconnect any drones still connected. + * if (NET_SV_NumPlayers() <= 0) + * { + * NET_SV_GameEnded(); + * } + * } + * + * if (!ClientConnected(client)) + * { + * // Client has not yet finished connecting + * return; + * } + * + * if (server_state == SERVER_WAITING_LAUNCH) + * { + * // Waiting for the game to start. + * // Send information once every second. + * if (client->last_send_time < 0 || I_GetTimeMS() - client->last_send_time > 1000) + * { + * NET_SV_SendWaitingData(client); + * client->last_send_time = I_GetTimeMS(); + * } + * } + * + * if (server_state == SERVER_IN_GAME) + * { + * NET_SV_PumpSendQueue(client); + * NET_SV_CheckDeadlock(client); + * } + */ } -// Add a network module to the server context - +/* Add a network module to the server context. */ void NET_SV_AddModule(net_module_t *module) { module->InitServer(); NET_AddModule(server_context, module); } -// Initialize server and wait for connections - +/* Initialize server and wait for connections. */ void NET_SV_Init(void) { - printf("NRFD-TODO: NET_SV_Init\n");/* - int i; - - // initialize send/receive context - - server_context = NET_NewContext(); - - // no clients yet - - for (i=0; i MASTER_RESOLVE_PERIOD * 1000) - { - net_addr_t *new_addr; - - new_addr = NET_Query_ResolveMaster(server_context); - - // Has the master server changed address? - - if (new_addr != NULL && new_addr != master_server) - { - NET_FreeAddress(master_server); - master_server = new_addr; - } - - master_resolve_time = now; - } - - // Possibly refresh our registration with the master server. - - if (now - master_refresh_time > MASTER_REFRESH_PERIOD * 1000) - { - NET_Query_AddToMaster(master_server); - master_refresh_time = now; - } - */ + /* + * // NRFD-TODO + * unsigned int now; + * + * now = I_GetTimeMS(); + * + * // The address of the master server can change. Periodically + * // re-resolve the master server to update. + * if (now - master_resolve_time > MASTER_RESOLVE_PERIOD * 1000) + * { + * net_addr_t *new_addr; + * + * new_addr = NET_Query_ResolveMaster(server_context); + * + * // Has the master server changed address + * if (new_addr != NULL && new_addr != master_server) + * { + * NET_FreeAddress(master_server); + * master_server = new_addr; + * } + * + * master_resolve_time = now; + * } + * + * // Possibly refresh our registration with the master server + * if (now - master_refresh_time > MASTER_REFRESH_PERIOD * 1000) + * { + * NET_Query_AddToMaster(master_server); + * master_refresh_time = now; + * } + */ } void NET_SV_RegisterWithMaster(void) { - printf("NRFD-TODO: NET_SV_RegisterWithMaster\n"); /* - //! - // @category net - // - // When running a server, don't register with the global master server. - // Implies -server. - // - - if (!M_CheckParm("-privateserver")) - { - master_server = NET_Query_ResolveMaster(server_context); - } - else - { - master_server = NULL; - } - - // Send request. - - if (master_server != NULL) - { - NET_Query_AddToMaster(master_server); - master_refresh_time = I_GetTimeMS(); - master_resolve_time = master_refresh_time; - } - */ + /* + * // NRFD-TODO + * //! + * // @category net + * // + * // When running a server, don't register with the global master server. + * // Implies -server. + * // + * if (!M_CheckParm("-privateserver")) + * { + * master_server = NET_Query_ResolveMaster(server_context); + * } + * else + * { + * master_server = NULL; + * } + * + * // Send request + * if (master_server != NULL) + * { + * NET_Query_AddToMaster(master_server); + * master_refresh_time = I_GetTimeMS(); + * master_resolve_time = master_refresh_time; + * } + */ } -// Run server code to check for new packets/send packets as the server -// requires - +/* + * Run server code to check for new packets/send packets as the server + * requires. + */ void NET_SV_Run(void) { - N_ldbg("NRFD-TODO: NET_SV_Run\n"); /* - net_addr_t *addr; - net_packet_t *packet; - int i; - - if (!server_initialized) - { - return; - } - - while (NET_RecvPacket(server_context, &addr, &packet)) - { - NET_SV_Packet(packet, addr); - NET_FreePacket(packet); - } - - if (master_server != NULL) - { - UpdateMasterServer(); - } - - // "Run" any clients that may have things to do, independent of responses - // to received packets - - for (i=0; i 5000) - { - running = false; - fprintf(stderr, "SV: Timed out waiting for clients to disconnect.\n"); - } - - // Run the client code in case this is a loopback client. - - NET_CL_Run(); - NET_SV_Run(); - - // Don't hog the CPU - - I_Sleep(1); - } - */ + /* + * // NRFD-TODO + * int i; + * boolean running; + * int start_time; + * + * if (!server_initialized) + * { + * return; + * } + * + * fprintf(stderr, "SV: Shutting down server ...\n"); + * + * // Disconnect all clients + * for (i = 0; i < MAXNETNODES; ++i) + * { + * if (clients[i].active) + * { + * NET_SV_DisconnectClient(&clients[i]); + * } + * } + * + * // Wait for all clients to finish disconnecting + * start_time = I_GetTimeMS(); + * running = true; + * + * while (running) + * { + * // Check if any clients are still not finished + * running = false; + * + * for (i = 0; i < MAXNETNODES; ++i) + * { + * if (clients[i].active) + * { + * running = true; + * } + * } + * + * // Timed out + * if (I_GetTimeMS() - start_time > 5000) + * { + * running = false; + * fprintf(stderr, "SV: Timed out waiting for clients to disconnect.\n"); + * } + * + * // Run the client code in case this is a loopback client + * NET_CL_Run(); + * NET_SV_Run(); + * + * // Don't hog the CPU + * I_Sleep(1); + * } + */ } diff --git a/zephyrdoom/src/net_server.h b/zephyrdoom/src/net_server.h index c8d5047..c9005a6 100644 --- a/zephyrdoom/src/net_server.h +++ b/zephyrdoom/src/net_server.h @@ -1,41 +1,39 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// Network server code -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Network server code. + */ #ifndef NET_SERVER_H #define NET_SERVER_H -// initialize server and wait for connections - +/* Initialize server and wait for connections. */ void NET_SV_Init(void); -// run server: check for new packets received etc. - +/* Run server. Check for new packets received etc. */ void NET_SV_Run(void); -// Shut down the server -// Blocks until all clients disconnect, or until a 5 second timeout - +/* + * Shut down the server. + * Blocks until all clients disconnect, or until a 5 second timeout. + */ void NET_SV_Shutdown(void); -// Add a network module to the context used by the server - +/* Add a network module to the context used by the server. */ void NET_SV_AddModule(net_module_t *module); -// Register server with master server. - +/* Register server with master server. */ void NET_SV_RegisterWithMaster(void); -#endif /* #ifndef NET_SERVER_H */ +#endif /* NET_SERVER_H */ diff --git a/zephyrdoom/src/net_structrw.c b/zephyrdoom/src/net_structrw.c index b613177..cc7c555 100644 --- a/zephyrdoom/src/net_structrw.c +++ b/zephyrdoom/src/net_structrw.c @@ -1,18 +1,19 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// Reading and writing various structures into packets -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Reading and writing various structures into packets. + */ #include #include @@ -24,8 +25,10 @@ #include "net_packet.h" #include "net_structrw.h" -// String names for the enum values in net_protocol_t, which are what is -// sent over the wire. Every enum value must have an entry in this list. +/* + * String names for the enum values in net_protocol_t, which are what is + * sent over the wire. Every enum value must have an entry in this list. + */ static struct { net_protocol_t protocol; @@ -49,15 +52,7 @@ void NET_WriteConnectData(net_packet_t *packet, net_connect_data_t *data) boolean NET_ReadConnectData(net_packet_t *packet, net_connect_data_t *data) { - return NET_ReadInt8(packet, (unsigned int *) &data->gamemode) - && NET_ReadInt8(packet, (unsigned int *) &data->gamemission) - && NET_ReadInt8(packet, (unsigned int *) &data->lowres_turn) - && NET_ReadInt8(packet, (unsigned int *) &data->drone) - && NET_ReadInt8(packet, (unsigned int *) &data->max_players) - && NET_ReadInt8(packet, (unsigned int *) &data->is_freedoom) - && NET_ReadSHA1Sum(packet, data->wad_sha1sum) - && NET_ReadSHA1Sum(packet, data->deh_sha1sum) - && NET_ReadInt8(packet, (unsigned int *) &data->player_class); + return NET_ReadInt8(packet, (unsigned int *)&data->gamemode) && NET_ReadInt8(packet, (unsigned int *)&data->gamemission) && NET_ReadInt8(packet, (unsigned int *)&data->lowres_turn) && NET_ReadInt8(packet, (unsigned int *)&data->drone) && NET_ReadInt8(packet, (unsigned int *)&data->max_players) && NET_ReadInt8(packet, (unsigned int *)&data->is_freedoom) && NET_ReadSHA1Sum(packet, data->wad_sha1sum) && NET_ReadSHA1Sum(packet, data->deh_sha1sum) && NET_ReadInt8(packet, (unsigned int *)&data->player_class); } void NET_WriteSettings(net_packet_t *packet, net_gamesettings_t *settings) @@ -93,23 +88,7 @@ boolean NET_ReadSettings(net_packet_t *packet, net_gamesettings_t *settings) boolean success; int i; - success = NET_ReadInt8(packet, (unsigned int *) &settings->ticdup) - && NET_ReadInt8(packet, (unsigned int *) &settings->extratics) - && NET_ReadInt8(packet, (unsigned int *) &settings->deathmatch) - && NET_ReadInt8(packet, (unsigned int *) &settings->nomonsters) - && NET_ReadInt8(packet, (unsigned int *) &settings->fast_monsters) - && NET_ReadInt8(packet, (unsigned int *) &settings->respawn_monsters) - && NET_ReadInt8(packet, (unsigned int *) &settings->episode) - && NET_ReadInt8(packet, (unsigned int *) &settings->map) - && NET_ReadSInt8(packet, &settings->skill) - && NET_ReadInt8(packet, (unsigned int *) &settings->gameversion) - && NET_ReadInt8(packet, (unsigned int *) &settings->lowres_turn) - && NET_ReadInt8(packet, (unsigned int *) &settings->new_sync) - && NET_ReadInt32(packet, (unsigned int *) &settings->timelimit) - && NET_ReadSInt8(packet, (signed int *) &settings->loadgame) - && NET_ReadInt8(packet, (unsigned int *) &settings->random) - && NET_ReadInt8(packet, (unsigned int *) &settings->num_players) - && NET_ReadSInt8(packet, (signed int *) &settings->consoleplayer); + success = NET_ReadInt8(packet, (unsigned int *)&settings->ticdup) && NET_ReadInt8(packet, (unsigned int *)&settings->extratics) && NET_ReadInt8(packet, (unsigned int *)&settings->deathmatch) && NET_ReadInt8(packet, (unsigned int *)&settings->nomonsters) && NET_ReadInt8(packet, (unsigned int *)&settings->fast_monsters) && NET_ReadInt8(packet, (unsigned int *)&settings->respawn_monsters) && NET_ReadInt8(packet, (unsigned int *)&settings->episode) && NET_ReadInt8(packet, (unsigned int *)&settings->map) && NET_ReadSInt8(packet, &settings->skill) && NET_ReadInt8(packet, (unsigned int *)&settings->gameversion) && NET_ReadInt8(packet, (unsigned int *)&settings->lowres_turn) && NET_ReadInt8(packet, (unsigned int *)&settings->new_sync) && NET_ReadInt32(packet, (unsigned int *)&settings->timelimit) && NET_ReadSInt8(packet, (signed int *)&settings->loadgame) && NET_ReadInt8(packet, (unsigned int *)&settings->random) && NET_ReadInt8(packet, (unsigned int *)&settings->num_players) && NET_ReadSInt8(packet, (signed int *)&settings->consoleplayer); if (!success) { @@ -119,7 +98,7 @@ boolean NET_ReadSettings(net_packet_t *packet, net_gamesettings_t *settings) for (i = 0; i < settings->num_players; ++i) { if (!NET_ReadInt8(packet, - (unsigned int *) &settings->player_classes[i])) + (unsigned int *)&settings->player_classes[i])) { return false; } @@ -134,12 +113,7 @@ boolean NET_ReadQueryData(net_packet_t *packet, net_querydata_t *query) query->version = NET_ReadSafeString(packet); - success = query->version != NULL - && NET_ReadInt8(packet, (unsigned int *) &query->server_state) - && NET_ReadInt8(packet, (unsigned int *) &query->num_players) - && NET_ReadInt8(packet, (unsigned int *) &query->max_players) - && NET_ReadInt8(packet, (unsigned int *) &query->gamemode) - && NET_ReadInt8(packet, (unsigned int *) &query->gamemission); + success = query->version != NULL && NET_ReadInt8(packet, (unsigned int *)&query->server_state) && NET_ReadInt8(packet, (unsigned int *)&query->num_players) && NET_ReadInt8(packet, (unsigned int *)&query->max_players) && NET_ReadInt8(packet, (unsigned int *)&query->gamemode) && NET_ReadInt8(packet, (unsigned int *)&query->gamemission); if (!success) { @@ -148,9 +122,11 @@ boolean NET_ReadQueryData(net_packet_t *packet, net_querydata_t *query) query->description = NET_ReadSafeString(packet); - // We read the list of protocols supported by the server. However, - // old versions of Chocolate Doom do not support this field; it is - // okay if it cannot be successfully read. + /* + * We read the list of protocols supported by the server. However, + * old versions of Chocolate Doom do not support this field. It is + * okay if it cannot be successfully read. + */ query->protocol = NET_ReadProtocolList(packet); return query->description != NULL; @@ -166,20 +142,20 @@ void NET_WriteQueryData(net_packet_t *packet, net_querydata_t *query) NET_WriteInt8(packet, query->gamemission); NET_WriteString(packet, query->description); - // Write a list of all supported protocols. Note that the query->protocol - // field is ignored here; it is only used when receiving. + /* + * Write a list of all supported protocols. Note that the query->protocol + * field is ignored here; it is only used when receiving. + */ NET_WriteProtocolList(packet); } void NET_WriteTiccmdDiff(net_packet_t *packet, net_ticdiff_t *diff, boolean lowres_turn) { - // Header - + /* Header */ NET_WriteInt8(packet, diff->diff); - // Write the fields which are enabled: - + /* Write the fields which are enabled */ if (diff->diff & NET_TICDIFF_FORWARD) NET_WriteInt8(packet, diff->cmd.forwardmove); if (diff->diff & NET_TICDIFF_SIDE) @@ -219,13 +195,11 @@ boolean NET_ReadTiccmdDiff(net_packet_t *packet, net_ticdiff_t *diff, unsigned int val; signed int sval; - // Read header - + /* Read header */ if (!NET_ReadInt8(packet, &diff->diff)) return false; - // Read fields - + /* Read fields */ if (diff->diff & NET_TICDIFF_FORWARD) { if (!NET_ReadSInt8(packet, &sval)) @@ -320,13 +294,11 @@ void NET_TiccmdDiff(ticcmd_t *tic1, ticcmd_t *tic2, net_ticdiff_t *diff) if (tic2->chatchar != 0) diff->diff |= NET_TICDIFF_CHATCHAR; - // Heretic/Hexen-specific - + /* Heretic/Hexen-specific */ if (tic1->lookfly != tic2->lookfly || tic2->arti != 0) diff->diff |= NET_TICDIFF_RAVEN; - // Strife-specific - + /* Strife-specific */ if (tic1->buttons2 != tic2->buttons2 || tic2->inventory != 0) diff->diff |= NET_TICDIFF_STRIFE; } @@ -335,8 +307,7 @@ void NET_TiccmdPatch(ticcmd_t *src, net_ticdiff_t *diff, ticcmd_t *dest) { memmove(dest, src, sizeof(ticcmd_t)); - // Apply the diff - + /* Apply the diff */ if (diff->diff & NET_TICDIFF_FORWARD) dest->forwardmove = diff->cmd.forwardmove; if (diff->diff & NET_TICDIFF_SIDE) @@ -353,8 +324,7 @@ void NET_TiccmdPatch(ticcmd_t *src, net_ticdiff_t *diff, ticcmd_t *dest) else dest->chatchar = 0; - // Heretic/Hexen specific: - + /* Heretic/Hexen specific */ if (diff->diff & NET_TICDIFF_RAVEN) { dest->lookfly = diff->cmd.lookfly; @@ -365,8 +335,7 @@ void NET_TiccmdPatch(ticcmd_t *src, net_ticdiff_t *diff, ticcmd_t *dest) dest->arti = 0; } - // Strife-specific: - + /* Strife-specific */ if (diff->diff & NET_TICDIFF_STRIFE) { dest->buttons2 = diff->cmd.buttons2; @@ -378,37 +347,30 @@ void NET_TiccmdPatch(ticcmd_t *src, net_ticdiff_t *diff, ticcmd_t *dest) } } -// -// net_full_ticcmd_t -// - boolean NET_ReadFullTiccmd(net_packet_t *packet, net_full_ticcmd_t *cmd, boolean lowres_turn) { unsigned int bitfield; int i; - // Latency - + /* Latency */ if (!NET_ReadSInt16(packet, &cmd->latency)) { return false; } - // Regenerate playeringame from the "header" bitfield - + /* Regenerate playeringame from the "header" bitfield */ if (!NET_ReadInt8(packet, &bitfield)) { return false; } - for (i=0; iplayeringame[i] = (bitfield & (1 << i)) != 0; } - // Read cmds - - for (i=0; iplayeringame[i]) { @@ -427,16 +389,16 @@ void NET_WriteFullTiccmd(net_packet_t *packet, net_full_ticcmd_t *cmd, boolean l unsigned int bitfield; int i; - // Write the latency - + /* Write the latency */ NET_WriteInt16(packet, cmd->latency); - // Write "header" byte indicating which players are active - // in this ticcmd - + /* + * Write "header" byte indicating which players are active + * in this ticcmd. + */ bitfield = 0; - for (i=0; iplayeringame[i]) { @@ -446,9 +408,8 @@ void NET_WriteFullTiccmd(net_packet_t *packet, net_full_ticcmd_t *cmd, boolean l NET_WriteInt8(packet, bitfield); - // Write player ticcmds - - for (i=0; iplayeringame[i]) { @@ -484,12 +445,7 @@ boolean NET_ReadWaitData(net_packet_t *packet, net_waitdata_t *data) int i; char *s; - if (!NET_ReadInt8(packet, (unsigned int *) &data->num_players) - || !NET_ReadInt8(packet, (unsigned int *) &data->num_drones) - || !NET_ReadInt8(packet, (unsigned int *) &data->ready_players) - || !NET_ReadInt8(packet, (unsigned int *) &data->max_players) - || !NET_ReadInt8(packet, (unsigned int *) &data->is_controller) - || !NET_ReadSInt8(packet, &data->consoleplayer)) + if (!NET_ReadInt8(packet, (unsigned int *)&data->num_players) || !NET_ReadInt8(packet, (unsigned int *)&data->num_drones) || !NET_ReadInt8(packet, (unsigned int *)&data->ready_players) || !NET_ReadInt8(packet, (unsigned int *)&data->max_players) || !NET_ReadInt8(packet, (unsigned int *)&data->is_controller) || !NET_ReadSInt8(packet, &data->consoleplayer)) { return false; } @@ -515,9 +471,7 @@ boolean NET_ReadWaitData(net_packet_t *packet, net_waitdata_t *data) M_StringCopy(data->player_addrs[i], s, MAXPLAYERNAME); } - return NET_ReadSHA1Sum(packet, data->wad_sha1sum) - && NET_ReadSHA1Sum(packet, data->deh_sha1sum) - && NET_ReadInt8(packet, (unsigned int *) &data->is_freedoom); + return NET_ReadSHA1Sum(packet, data->wad_sha1sum) && NET_ReadSHA1Sum(packet, data->deh_sha1sum) && NET_ReadInt8(packet, (unsigned int *)&data->is_freedoom); } static boolean NET_ReadBlob(net_packet_t *packet, uint8_t *buf, size_t len) @@ -525,7 +479,7 @@ static boolean NET_ReadBlob(net_packet_t *packet, uint8_t *buf, size_t len) unsigned int b; int i; - for (i=0; icount = 0; } - -/**************** - * Transform the message X which consists of 16 32-bit-words +/* + * Transform the message X which consists of 16 32-bit-words. */ static void Transform(sha1_context_t *hd, byte *data) { - uint32_t a,b,c,d,e,tm; + uint32_t a, b, c, d, e, tm; uint32_t x[16]; - /* get values from the chaining vars */ + /* Get values from the chaining vars */ a = hd->h0; b = hd->h1; c = hd->h2; @@ -72,7 +72,7 @@ static void Transform(sha1_context_t *hd, byte *data) { int i; byte *p2; - for(i=0, p2=(byte*)x; i < 16; i++, p2 += 4 ) + for (i = 0, p2 = (byte *)x; i < 16; i++, p2 += 4) { p2[3] = *data++; p2[2] = *data++; @@ -82,110 +82,107 @@ static void Transform(sha1_context_t *hd, byte *data) } #endif +#define K1 0x5A827999L +#define K2 0x6ED9EBA1L +#define K3 0x8F1BBCDCL +#define K4 0xCA62C1D6L +#define F1(x, y, z) (z ^ (x & (y ^ z))) +#define F2(x, y, z) (x ^ y ^ z) +#define F3(x, y, z) ((x & y) | (z & (x | y))) +#define F4(x, y, z) (x ^ y ^ z) -#define K1 0x5A827999L -#define K2 0x6ED9EBA1L -#define K3 0x8F1BBCDCL -#define K4 0xCA62C1D6L -#define F1(x,y,z) ( z ^ ( x & ( y ^ z ) ) ) -#define F2(x,y,z) ( x ^ y ^ z ) -#define F3(x,y,z) ( ( x & y ) | ( z & ( x | y ) ) ) -#define F4(x,y,z) ( x ^ y ^ z ) - -#define rol(x,n) ( ((x) << (n)) | ((x) >> (32-(n))) ) +#define rol(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) -#define M(i) ( tm = x[i&0x0f] ^ x[(i-14)&0x0f] \ - ^ x[(i-8)&0x0f] ^ x[(i-3)&0x0f] \ - , (x[i&0x0f] = rol(tm,1)) ) +#define M(i) (tm = x[i & 0x0f] ^ x[(i - 14) & 0x0f] ^ x[(i - 8) & 0x0f] ^ x[(i - 3) & 0x0f], (x[i & 0x0f] = rol(tm, 1))) -#define R(a,b,c,d,e,f,k,m) do { e += rol( a, 5 ) \ - + f( b, c, d ) \ - + k \ - + m; \ - b = rol( b, 30 ); \ - } while(0) - R( a, b, c, d, e, F1, K1, x[ 0] ); - R( e, a, b, c, d, F1, K1, x[ 1] ); - R( d, e, a, b, c, F1, K1, x[ 2] ); - R( c, d, e, a, b, F1, K1, x[ 3] ); - R( b, c, d, e, a, F1, K1, x[ 4] ); - R( a, b, c, d, e, F1, K1, x[ 5] ); - R( e, a, b, c, d, F1, K1, x[ 6] ); - R( d, e, a, b, c, F1, K1, x[ 7] ); - R( c, d, e, a, b, F1, K1, x[ 8] ); - R( b, c, d, e, a, F1, K1, x[ 9] ); - R( a, b, c, d, e, F1, K1, x[10] ); - R( e, a, b, c, d, F1, K1, x[11] ); - R( d, e, a, b, c, F1, K1, x[12] ); - R( c, d, e, a, b, F1, K1, x[13] ); - R( b, c, d, e, a, F1, K1, x[14] ); - R( a, b, c, d, e, F1, K1, x[15] ); - R( e, a, b, c, d, F1, K1, M(16) ); - R( d, e, a, b, c, F1, K1, M(17) ); - R( c, d, e, a, b, F1, K1, M(18) ); - R( b, c, d, e, a, F1, K1, M(19) ); - R( a, b, c, d, e, F2, K2, M(20) ); - R( e, a, b, c, d, F2, K2, M(21) ); - R( d, e, a, b, c, F2, K2, M(22) ); - R( c, d, e, a, b, F2, K2, M(23) ); - R( b, c, d, e, a, F2, K2, M(24) ); - R( a, b, c, d, e, F2, K2, M(25) ); - R( e, a, b, c, d, F2, K2, M(26) ); - R( d, e, a, b, c, F2, K2, M(27) ); - R( c, d, e, a, b, F2, K2, M(28) ); - R( b, c, d, e, a, F2, K2, M(29) ); - R( a, b, c, d, e, F2, K2, M(30) ); - R( e, a, b, c, d, F2, K2, M(31) ); - R( d, e, a, b, c, F2, K2, M(32) ); - R( c, d, e, a, b, F2, K2, M(33) ); - R( b, c, d, e, a, F2, K2, M(34) ); - R( a, b, c, d, e, F2, K2, M(35) ); - R( e, a, b, c, d, F2, K2, M(36) ); - R( d, e, a, b, c, F2, K2, M(37) ); - R( c, d, e, a, b, F2, K2, M(38) ); - R( b, c, d, e, a, F2, K2, M(39) ); - R( a, b, c, d, e, F3, K3, M(40) ); - R( e, a, b, c, d, F3, K3, M(41) ); - R( d, e, a, b, c, F3, K3, M(42) ); - R( c, d, e, a, b, F3, K3, M(43) ); - R( b, c, d, e, a, F3, K3, M(44) ); - R( a, b, c, d, e, F3, K3, M(45) ); - R( e, a, b, c, d, F3, K3, M(46) ); - R( d, e, a, b, c, F3, K3, M(47) ); - R( c, d, e, a, b, F3, K3, M(48) ); - R( b, c, d, e, a, F3, K3, M(49) ); - R( a, b, c, d, e, F3, K3, M(50) ); - R( e, a, b, c, d, F3, K3, M(51) ); - R( d, e, a, b, c, F3, K3, M(52) ); - R( c, d, e, a, b, F3, K3, M(53) ); - R( b, c, d, e, a, F3, K3, M(54) ); - R( a, b, c, d, e, F3, K3, M(55) ); - R( e, a, b, c, d, F3, K3, M(56) ); - R( d, e, a, b, c, F3, K3, M(57) ); - R( c, d, e, a, b, F3, K3, M(58) ); - R( b, c, d, e, a, F3, K3, M(59) ); - R( a, b, c, d, e, F4, K4, M(60) ); - R( e, a, b, c, d, F4, K4, M(61) ); - R( d, e, a, b, c, F4, K4, M(62) ); - R( c, d, e, a, b, F4, K4, M(63) ); - R( b, c, d, e, a, F4, K4, M(64) ); - R( a, b, c, d, e, F4, K4, M(65) ); - R( e, a, b, c, d, F4, K4, M(66) ); - R( d, e, a, b, c, F4, K4, M(67) ); - R( c, d, e, a, b, F4, K4, M(68) ); - R( b, c, d, e, a, F4, K4, M(69) ); - R( a, b, c, d, e, F4, K4, M(70) ); - R( e, a, b, c, d, F4, K4, M(71) ); - R( d, e, a, b, c, F4, K4, M(72) ); - R( c, d, e, a, b, F4, K4, M(73) ); - R( b, c, d, e, a, F4, K4, M(74) ); - R( a, b, c, d, e, F4, K4, M(75) ); - R( e, a, b, c, d, F4, K4, M(76) ); - R( d, e, a, b, c, F4, K4, M(77) ); - R( c, d, e, a, b, F4, K4, M(78) ); - R( b, c, d, e, a, F4, K4, M(79) ); +#define R(a, b, c, d, e, f, k, m) \ + do \ + { \ + e += rol(a, 5) + f(b, c, d) + k + m; \ + b = rol(b, 30); \ + } while (0) + R(a, b, c, d, e, F1, K1, x[0]); + R(e, a, b, c, d, F1, K1, x[1]); + R(d, e, a, b, c, F1, K1, x[2]); + R(c, d, e, a, b, F1, K1, x[3]); + R(b, c, d, e, a, F1, K1, x[4]); + R(a, b, c, d, e, F1, K1, x[5]); + R(e, a, b, c, d, F1, K1, x[6]); + R(d, e, a, b, c, F1, K1, x[7]); + R(c, d, e, a, b, F1, K1, x[8]); + R(b, c, d, e, a, F1, K1, x[9]); + R(a, b, c, d, e, F1, K1, x[10]); + R(e, a, b, c, d, F1, K1, x[11]); + R(d, e, a, b, c, F1, K1, x[12]); + R(c, d, e, a, b, F1, K1, x[13]); + R(b, c, d, e, a, F1, K1, x[14]); + R(a, b, c, d, e, F1, K1, x[15]); + R(e, a, b, c, d, F1, K1, M(16)); + R(d, e, a, b, c, F1, K1, M(17)); + R(c, d, e, a, b, F1, K1, M(18)); + R(b, c, d, e, a, F1, K1, M(19)); + R(a, b, c, d, e, F2, K2, M(20)); + R(e, a, b, c, d, F2, K2, M(21)); + R(d, e, a, b, c, F2, K2, M(22)); + R(c, d, e, a, b, F2, K2, M(23)); + R(b, c, d, e, a, F2, K2, M(24)); + R(a, b, c, d, e, F2, K2, M(25)); + R(e, a, b, c, d, F2, K2, M(26)); + R(d, e, a, b, c, F2, K2, M(27)); + R(c, d, e, a, b, F2, K2, M(28)); + R(b, c, d, e, a, F2, K2, M(29)); + R(a, b, c, d, e, F2, K2, M(30)); + R(e, a, b, c, d, F2, K2, M(31)); + R(d, e, a, b, c, F2, K2, M(32)); + R(c, d, e, a, b, F2, K2, M(33)); + R(b, c, d, e, a, F2, K2, M(34)); + R(a, b, c, d, e, F2, K2, M(35)); + R(e, a, b, c, d, F2, K2, M(36)); + R(d, e, a, b, c, F2, K2, M(37)); + R(c, d, e, a, b, F2, K2, M(38)); + R(b, c, d, e, a, F2, K2, M(39)); + R(a, b, c, d, e, F3, K3, M(40)); + R(e, a, b, c, d, F3, K3, M(41)); + R(d, e, a, b, c, F3, K3, M(42)); + R(c, d, e, a, b, F3, K3, M(43)); + R(b, c, d, e, a, F3, K3, M(44)); + R(a, b, c, d, e, F3, K3, M(45)); + R(e, a, b, c, d, F3, K3, M(46)); + R(d, e, a, b, c, F3, K3, M(47)); + R(c, d, e, a, b, F3, K3, M(48)); + R(b, c, d, e, a, F3, K3, M(49)); + R(a, b, c, d, e, F3, K3, M(50)); + R(e, a, b, c, d, F3, K3, M(51)); + R(d, e, a, b, c, F3, K3, M(52)); + R(c, d, e, a, b, F3, K3, M(53)); + R(b, c, d, e, a, F3, K3, M(54)); + R(a, b, c, d, e, F3, K3, M(55)); + R(e, a, b, c, d, F3, K3, M(56)); + R(d, e, a, b, c, F3, K3, M(57)); + R(c, d, e, a, b, F3, K3, M(58)); + R(b, c, d, e, a, F3, K3, M(59)); + R(a, b, c, d, e, F4, K4, M(60)); + R(e, a, b, c, d, F4, K4, M(61)); + R(d, e, a, b, c, F4, K4, M(62)); + R(c, d, e, a, b, F4, K4, M(63)); + R(b, c, d, e, a, F4, K4, M(64)); + R(a, b, c, d, e, F4, K4, M(65)); + R(e, a, b, c, d, F4, K4, M(66)); + R(d, e, a, b, c, F4, K4, M(67)); + R(c, d, e, a, b, F4, K4, M(68)); + R(b, c, d, e, a, F4, K4, M(69)); + R(a, b, c, d, e, F4, K4, M(70)); + R(e, a, b, c, d, F4, K4, M(71)); + R(d, e, a, b, c, F4, K4, M(72)); + R(c, d, e, a, b, F4, K4, M(73)); + R(b, c, d, e, a, F4, K4, M(74)); + R(a, b, c, d, e, F4, K4, M(75)); + R(e, a, b, c, d, F4, K4, M(76)); + R(d, e, a, b, c, F4, K4, M(77)); + R(c, d, e, a, b, F4, K4, M(78)); + R(b, c, d, e, a, F4, K4, M(79)); - /* update chainig vars */ + /* Update chainig vars */ hd->h0 += a; hd->h1 += b; hd->h2 += c; @@ -193,66 +190,65 @@ static void Transform(sha1_context_t *hd, byte *data) hd->h4 += e; } - -/* Update the message digest with the contents - * of INBUF with length INLEN. - */ +/* Update the message digest with the contents of INBUF with length INLEN. */ void SHA1_Update(sha1_context_t *hd, byte *inbuf, size_t inlen) { if (hd->count == 64) { - /* flush the buffer */ - Transform(hd, hd->buf); - hd->count = 0; - hd->nblocks++; + /* Flush the buffer */ + Transform(hd, hd->buf); + hd->count = 0; + hd->nblocks++; } if (!inbuf) - return; + return; if (hd->count) { - for (; inlen && hd->count < 64; inlen--) - hd->buf[hd->count++] = *inbuf++; - SHA1_Update(hd, NULL, 0); - if (!inlen) - return; + for (; inlen && hd->count < 64; inlen--) + hd->buf[hd->count++] = *inbuf++; + SHA1_Update(hd, NULL, 0); + if (!inlen) + return; } while (inlen >= 64) { - Transform(hd, inbuf); - hd->count = 0; - hd->nblocks++; - inlen -= 64; - inbuf += 64; + Transform(hd, inbuf); + hd->count = 0; + hd->nblocks++; + inlen -= 64; + inbuf += 64; } for (; inlen && hd->count < 64; inlen--) - hd->buf[hd->count++] = *inbuf++; + hd->buf[hd->count++] = *inbuf++; } - -/* The routine final terminates the computation and - * returns the digest. +/* + * The routine final terminates the computation and returns the digest. * The handle is prepared for a new cycle, but adding bytes to the * handle will the destroy the returned buffer. - * Returns: 20 bytes representing the digest. + * Returns 20 bytes representing the digest. */ - void SHA1_Final(sha1_digest_t digest, sha1_context_t *hd) { uint32_t t, msb, lsb; byte *p; - SHA1_Update(hd, NULL, 0); /* flush */; + /* Flush */ + SHA1_Update(hd, NULL, 0); t = hd->nblocks; - /* multiply by 64 to make a byte count */ + + /* Multiply by 64 to make a byte count */ lsb = t << 6; msb = t >> 26; - /* add the count */ + + /* Add the count */ t = lsb; if ((lsb += hd->count) < t) - msb++; - /* multiply by 8 to make a bit count */ + msb++; + + /* Multiply by 8 to make a bit count */ t = lsb; lsb <<= 3; msb <<= 3; @@ -260,37 +256,53 @@ void SHA1_Final(sha1_digest_t digest, sha1_context_t *hd) if (hd->count < 56) { - /* enough room */ - hd->buf[hd->count++] = 0x80; /* pad */ - while (hd->count < 56) - hd->buf[hd->count++] = 0; /* pad */ + /* Enough room */ + hd->buf[hd->count++] = 0x80; /* Pad */ + while (hd->count < 56) + hd->buf[hd->count++] = 0; /* Pad */ } else { - /* need one extra block */ - hd->buf[hd->count++] = 0x80; /* pad character */ - while (hd->count < 64) - hd->buf[hd->count++] = 0; - SHA1_Update(hd, NULL, 0); /* flush */; - memset(hd->buf, 0, 56 ); /* fill next block with zeroes */ + /* Need one extra block */ + hd->buf[hd->count++] = 0x80; /* Pad character */ + while (hd->count < 64) + hd->buf[hd->count++] = 0; + + /* Flush */ + SHA1_Update(hd, NULL, 0); + + /* Fill next block with zeroes */ + memset(hd->buf, 0, 56); } - /* append the 64 bit count */ + + /* Append the 64 bit count */ hd->buf[56] = msb >> 24; hd->buf[57] = msb >> 16; - hd->buf[58] = msb >> 8; - hd->buf[59] = msb ; + hd->buf[58] = msb >> 8; + hd->buf[59] = msb; hd->buf[60] = lsb >> 24; hd->buf[61] = lsb >> 16; - hd->buf[62] = lsb >> 8; - hd->buf[63] = lsb ; + hd->buf[62] = lsb >> 8; + hd->buf[63] = lsb; Transform(hd, hd->buf); p = hd->buf; #ifdef SYS_BIG_ENDIAN -#define X(a) do { *(uint32_t*)p = hd->h##a ; p += 4; } while(0) -#else /* little endian */ -#define X(a) do { *p++ = hd->h##a >> 24; *p++ = hd->h##a >> 16; \ - *p++ = hd->h##a >> 8; *p++ = hd->h##a; } while(0) +#define X(a) \ + do \ + { \ + *(uint32_t *)p = hd->h##a; \ + p += 4; \ + } while (0) +#else /*Little Endian */ +#define X(a) \ + do \ + { \ + *p++ = hd->h##a >> 24; \ + *p++ = hd->h##a >> 16; \ + *p++ = hd->h##a >> 8; \ + *p++ = hd->h##a; \ + } while (0) #endif X(0); X(1); @@ -316,5 +328,5 @@ void SHA1_UpdateInt32(sha1_context_t *context, unsigned int val) void SHA1_UpdateString(sha1_context_t *context, char *str) { - SHA1_Update(context, (byte *) str, strlen(str) + 1); + SHA1_Update(context, (byte *)str, strlen(str) + 1); } diff --git a/zephyrdoom/src/sha1.h b/zephyrdoom/src/sha1.h index efb4f38..57d9434 100644 --- a/zephyrdoom/src/sha1.h +++ b/zephyrdoom/src/sha1.h @@ -1,19 +1,19 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// SHA-1 digest. -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * SHA-1 digest. + */ #ifndef __SHA1_H__ #define __SHA1_H__ @@ -23,8 +23,9 @@ typedef struct sha1_context_s sha1_context_t; typedef byte sha1_digest_t[20]; -struct sha1_context_s { - uint32_t h0,h1,h2,h3,h4; +struct sha1_context_s +{ + uint32_t h0, h1, h2, h3, h4; uint32_t nblocks; byte buf[64]; int count; @@ -36,4 +37,4 @@ void SHA1_Final(sha1_digest_t digest, sha1_context_t *context); void SHA1_UpdateInt32(sha1_context_t *context, unsigned int val); void SHA1_UpdateString(sha1_context_t *context, char *str); -#endif /* #ifndef __SHA1_H__ */ +#endif /* __SHA1_H__ */ diff --git a/zephyrdoom/src/tables.c b/zephyrdoom/src/tables.c index 223720f..698294a 100644 --- a/zephyrdoom/src/tables.c +++ b/zephyrdoom/src/tables.c @@ -1,43 +1,42 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Lookup tables. -// Do not try to look them up :-). -// In the order of appearance: -// -// int finetangent[4096] - Tangens LUT. -// Should work with BAM fairly well (12 of 16bit, -// effectively, by shifting). -// -// int finesine[10240] - Sine lookup. -// Guess what, serves as cosine, too. -// Remarkable thing is, how to use BAMs with this? -// -// int tantoangle[2049] - ArcTan LUT, -// maps tan(angle) to angle fast. Gotta search. -// -// +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Lookup tables. + * Do not try to look them up :-). + * In the order of appearance: + * + * int finetangent[4096] - Tangens LUT. + * Should work with BAM fairly well (12 of 16bit, effectively, by shifting). + * + * int finesine[10240] Sine lookup. + * Guess what, serves as cosine, too. + * Remarkable thing is, how to use BAMs with this. + * + * int tantoangle[2049] - ArcTan LUT. + * Maps tan(angle) to angle fast. Gotta search. + */ #include "tables.h" -// to get a global angle from cartesian coordinates, the coordinates are -// flipped until they are in the first octant of the coordinate system, then -// the y (<=x) is scaled and divided by x to get a tangent (slope) value -// which is looked up in the tantoangle[] table. The +1 size is to handle -// the case when x==y without additional checking. - +/* + * To get a global angle from cartesian coordinates, the coordinates are + * flipped until they are in the first octant of the coordinate system, then + * the y (<=x) is scaled and divided by x to get a tangent (slope) value + * which is looked up in the tantoangle[] table. The +1 size is to handle + * the case when x==y without additional checking. + */ int SlopeDiv(unsigned int num, unsigned int den) { unsigned ans; @@ -62,2165 +61,2149 @@ int SlopeDiv(unsigned int num, unsigned int den) } const fixed_t finetangent[4096] = -{ - -170910304,-56965752,-34178904,-24413316,-18988036,-15535599,-13145455,-11392683, - -10052327,-8994149,-8137527,-7429880,-6835455,-6329090,-5892567,-5512368, - -5178251,-4882318,-4618375,-4381502,-4167737,-3973855,-3797206,-3635590, - -3487165,-3350381,-3223918,-3106651,-2997613,-2895966,-2800983,-2712030, - -2628549,-2550052,-2476104,-2406322,-2340362,-2277919,-2218719,-2162516, - -2109087,-2058233,-2009771,-1963536,-1919378,-1877161,-1836758,-1798063, - -1760956,-1725348,-1691149,-1658278,-1626658,-1596220,-1566898,-1538632, - -1511367,-1485049,-1459630,-1435065,-1411312,-1388330,-1366084,-1344537, - -1323658,-1303416,-1283783,-1264730,-1246234,-1228269,-1210813,-1193846, - -1177345,-1161294,-1145673,-1130465,-1115654,-1101225,-1087164,-1073455, - -1060087,-1047046,-1034322,-1021901,-1009774,-997931,-986361,-975054, - -964003,-953199,-942633,-932298,-922186,-912289,-902602,-893117, - -883829,-874730,-865817,-857081,-848520,-840127,-831898,-823827, - -815910,-808143,-800521,-793041,-785699,-778490,-771411,-764460, - -757631,-750922,-744331,-737853,-731486,-725227,-719074,-713023, - -707072,-701219,-695462,-689797,-684223,-678737,-673338,-668024, - -662792,-657640,-652568,-647572,-642651,-637803,-633028,-628323, - -623686,-619117,-614613,-610174,-605798,-601483,-597229,-593033, - -588896,-584815,-580789,-576818,-572901,-569035,-565221,-561456, - -557741,-554074,-550455,-546881,-543354,-539870,-536431,-533034, - -529680,-526366,-523094,-519861,-516667,-513512,-510394,-507313, - -504269,-501261,-498287,-495348,-492443,-489571,-486732,-483925, - -481150,-478406,-475692,-473009,-470355,-467730,-465133,-462565, - -460024,-457511,-455024,-452564,-450129,-447720,-445337,-442978, - -440643,-438332,-436045,-433781,-431540,-429321,-427125,-424951, - -422798,-420666,-418555,-416465,-414395,-412344,-410314,-408303, - -406311,-404338,-402384,-400448,-398530,-396630,-394747,-392882, - -391034,-389202,-387387,-385589,-383807,-382040,-380290,-378555, - -376835,-375130,-373440,-371765,-370105,-368459,-366826,-365208, - -363604,-362013,-360436,-358872,-357321,-355783,-354257,-352744, - -351244,-349756,-348280,-346816,-345364,-343924,-342495,-341078, - -339671,-338276,-336892,-335519,-334157,-332805,-331464,-330133, - -328812,-327502,-326201,-324910,-323629,-322358,-321097,-319844, - -318601,-317368,-316143,-314928,-313721,-312524,-311335,-310154, - -308983,-307819,-306664,-305517,-304379,-303248,-302126,-301011, - -299904,-298805,-297714,-296630,-295554,-294485,-293423,-292369, - -291322,-290282,-289249,-288223,-287204,-286192,-285186,-284188, - -283195,-282210,-281231,-280258,-279292,-278332,-277378,-276430, - -275489,-274553,-273624,-272700,-271782,-270871,-269965,-269064, - -268169,-267280,-266397,-265519,-264646,-263779,-262917,-262060, - -261209,-260363,-259522,-258686,-257855,-257029,-256208,-255392, - -254581,-253774,-252973,-252176,-251384,-250596,-249813,-249035, - -248261,-247492,-246727,-245966,-245210,-244458,-243711,-242967, - -242228,-241493,-240763,-240036,-239314,-238595,-237881,-237170, - -236463,-235761,-235062,-234367,-233676,-232988,-232304,-231624, - -230948,-230275,-229606,-228941,-228279,-227621,-226966,-226314, - -225666,-225022,-224381,-223743,-223108,-222477,-221849,-221225, - -220603,-219985,-219370,-218758,-218149,-217544,-216941,-216341, - -215745,-215151,-214561,-213973,-213389,-212807,-212228,-211652, - -211079,-210509,-209941,-209376,-208815,-208255,-207699,-207145, - -206594,-206045,-205500,-204956,-204416,-203878,-203342,-202809, - -202279,-201751,-201226,-200703,-200182,-199664,-199149,-198636, - -198125,-197616,-197110,-196606,-196105,-195606,-195109,-194614, - -194122,-193631,-193143,-192658,-192174,-191693,-191213,-190736, - -190261,-189789,-189318,-188849,-188382,-187918,-187455,-186995, - -186536,-186080,-185625,-185173,-184722,-184274,-183827,-183382, - -182939,-182498,-182059,-181622,-181186,-180753,-180321,-179891, - -179463,-179037,-178612,-178190,-177769,-177349,-176932,-176516, - -176102,-175690,-175279,-174870,-174463,-174057,-173653,-173251, - -172850,-172451,-172053,-171657,-171263,-170870,-170479,-170089, - -169701,-169315,-168930,-168546,-168164,-167784,-167405,-167027, - -166651,-166277,-165904,-165532,-165162,-164793,-164426,-164060, - -163695,-163332,-162970,-162610,-162251,-161893,-161537,-161182, - -160828,-160476,-160125,-159775,-159427,-159079,-158734,-158389, - -158046,-157704,-157363,-157024,-156686,-156349,-156013,-155678, - -155345,-155013,-154682,-154352,-154024,-153697,-153370,-153045, - -152722,-152399,-152077,-151757,-151438,-151120,-150803,-150487, - -150172,-149859,-149546,-149235,-148924,-148615,-148307,-148000, - -147693,-147388,-147084,-146782,-146480,-146179,-145879,-145580, - -145282,-144986,-144690,-144395,-144101,-143808,-143517,-143226, - -142936,-142647,-142359,-142072,-141786,-141501,-141217,-140934, - -140651,-140370,-140090,-139810,-139532,-139254,-138977,-138701, - -138426,-138152,-137879,-137607,-137335,-137065,-136795,-136526, - -136258,-135991,-135725,-135459,-135195,-134931,-134668,-134406, - -134145,-133884,-133625,-133366,-133108,-132851,-132594,-132339, - -132084,-131830,-131576,-131324,-131072,-130821,-130571,-130322, - -130073,-129825,-129578,-129332,-129086,-128841,-128597,-128353, - -128111,-127869,-127627,-127387,-127147,-126908,-126669,-126432, - -126195,-125959,-125723,-125488,-125254,-125020,-124787,-124555, - -124324,-124093,-123863,-123633,-123404,-123176,-122949,-122722, - -122496,-122270,-122045,-121821,-121597,-121374,-121152,-120930, - -120709,-120489,-120269,-120050,-119831,-119613,-119396,-119179, - -118963,-118747,-118532,-118318,-118104,-117891,-117678,-117466, - -117254,-117044,-116833,-116623,-116414,-116206,-115998,-115790, - -115583,-115377,-115171,-114966,-114761,-114557,-114354,-114151, - -113948,-113746,-113545,-113344,-113143,-112944,-112744,-112546, - -112347,-112150,-111952,-111756,-111560,-111364,-111169,-110974, - -110780,-110586,-110393,-110200,-110008,-109817,-109626,-109435, - -109245,-109055,-108866,-108677,-108489,-108301,-108114,-107927, - -107741,-107555,-107369,-107184,-107000,-106816,-106632,-106449, - -106266,-106084,-105902,-105721,-105540,-105360,-105180,-105000, - -104821,-104643,-104465,-104287,-104109,-103933,-103756,-103580, - -103404,-103229,-103054,-102880,-102706,-102533,-102360,-102187, - -102015,-101843,-101671,-101500,-101330,-101159,-100990,-100820, - -100651,-100482,-100314,-100146,-99979,-99812,-99645,-99479, - -99313,-99148,-98982,-98818,-98653,-98489,-98326,-98163, - -98000,-97837,-97675,-97513,-97352,-97191,-97030,-96870, - -96710,-96551,-96391,-96233,-96074,-95916,-95758,-95601, - -95444,-95287,-95131,-94975,-94819,-94664,-94509,-94354, - -94200,-94046,-93892,-93739,-93586,-93434,-93281,-93129, - -92978,-92826,-92675,-92525,-92375,-92225,-92075,-91926, - -91777,-91628,-91480,-91332,-91184,-91036,-90889,-90742, - -90596,-90450,-90304,-90158,-90013,-89868,-89724,-89579, - -89435,-89292,-89148,-89005,-88862,-88720,-88577,-88435, - -88294,-88152,-88011,-87871,-87730,-87590,-87450,-87310, - -87171,-87032,-86893,-86755,-86616,-86479,-86341,-86204, - -86066,-85930,-85793,-85657,-85521,-85385,-85250,-85114, - -84980,-84845,-84710,-84576,-84443,-84309,-84176,-84043, - -83910,-83777,-83645,-83513,-83381,-83250,-83118,-82987, - -82857,-82726,-82596,-82466,-82336,-82207,-82078,-81949, - -81820,-81691,-81563,-81435,-81307,-81180,-81053,-80925, - -80799,-80672,-80546,-80420,-80294,-80168,-80043,-79918, - -79793,-79668,-79544,-79420,-79296,-79172,-79048,-78925, - -78802,-78679,-78557,-78434,-78312,-78190,-78068,-77947, - -77826,-77705,-77584,-77463,-77343,-77223,-77103,-76983, - -76864,-76744,-76625,-76506,-76388,-76269,-76151,-76033, - -75915,-75797,-75680,-75563,-75446,-75329,-75213,-75096, - -74980,-74864,-74748,-74633,-74517,-74402,-74287,-74172, - -74058,-73944,-73829,-73715,-73602,-73488,-73375,-73262, - -73149,-73036,-72923,-72811,-72699,-72587,-72475,-72363, - -72252,-72140,-72029,-71918,-71808,-71697,-71587,-71477, - -71367,-71257,-71147,-71038,-70929,-70820,-70711,-70602, - -70494,-70385,-70277,-70169,-70061,-69954,-69846,-69739, - -69632,-69525,-69418,-69312,-69205,-69099,-68993,-68887, - -68781,-68676,-68570,-68465,-68360,-68255,-68151,-68046, - -67942,-67837,-67733,-67629,-67526,-67422,-67319,-67216, - -67113,-67010,-66907,-66804,-66702,-66600,-66498,-66396, - -66294,-66192,-66091,-65989,-65888,-65787,-65686,-65586, - -65485,-65385,-65285,-65185,-65085,-64985,-64885,-64786, - -64687,-64587,-64488,-64389,-64291,-64192,-64094,-63996, - -63897,-63799,-63702,-63604,-63506,-63409,-63312,-63215, - -63118,-63021,-62924,-62828,-62731,-62635,-62539,-62443, - -62347,-62251,-62156,-62060,-61965,-61870,-61775,-61680, - -61585,-61491,-61396,-61302,-61208,-61114,-61020,-60926, - -60833,-60739,-60646,-60552,-60459,-60366,-60273,-60181, - -60088,-59996,-59903,-59811,-59719,-59627,-59535,-59444, - -59352,-59261,-59169,-59078,-58987,-58896,-58805,-58715, - -58624,-58534,-58443,-58353,-58263,-58173,-58083,-57994, - -57904,-57815,-57725,-57636,-57547,-57458,-57369,-57281, - -57192,-57104,-57015,-56927,-56839,-56751,-56663,-56575, - -56487,-56400,-56312,-56225,-56138,-56051,-55964,-55877, - -55790,-55704,-55617,-55531,-55444,-55358,-55272,-55186, - -55100,-55015,-54929,-54843,-54758,-54673,-54587,-54502, - -54417,-54333,-54248,-54163,-54079,-53994,-53910,-53826, - -53741,-53657,-53574,-53490,-53406,-53322,-53239,-53156, - -53072,-52989,-52906,-52823,-52740,-52657,-52575,-52492, - -52410,-52327,-52245,-52163,-52081,-51999,-51917,-51835, - -51754,-51672,-51591,-51509,-51428,-51347,-51266,-51185, - -51104,-51023,-50942,-50862,-50781,-50701,-50621,-50540, - -50460,-50380,-50300,-50221,-50141,-50061,-49982,-49902, - -49823,-49744,-49664,-49585,-49506,-49427,-49349,-49270, - -49191,-49113,-49034,-48956,-48878,-48799,-48721,-48643, - -48565,-48488,-48410,-48332,-48255,-48177,-48100,-48022, - -47945,-47868,-47791,-47714,-47637,-47560,-47484,-47407, - -47331,-47254,-47178,-47102,-47025,-46949,-46873,-46797, - -46721,-46646,-46570,-46494,-46419,-46343,-46268,-46193, - -46118,-46042,-45967,-45892,-45818,-45743,-45668,-45593, - -45519,-45444,-45370,-45296,-45221,-45147,-45073,-44999, - -44925,-44851,-44778,-44704,-44630,-44557,-44483,-44410, - -44337,-44263,-44190,-44117,-44044,-43971,-43898,-43826, - -43753,-43680,-43608,-43535,-43463,-43390,-43318,-43246, - -43174,-43102,-43030,-42958,-42886,-42814,-42743,-42671, - -42600,-42528,-42457,-42385,-42314,-42243,-42172,-42101, - -42030,-41959,-41888,-41817,-41747,-41676,-41605,-41535, - -41465,-41394,-41324,-41254,-41184,-41113,-41043,-40973, - -40904,-40834,-40764,-40694,-40625,-40555,-40486,-40416, - -40347,-40278,-40208,-40139,-40070,-40001,-39932,-39863, - -39794,-39726,-39657,-39588,-39520,-39451,-39383,-39314, - -39246,-39178,-39110,-39042,-38973,-38905,-38837,-38770, - -38702,-38634,-38566,-38499,-38431,-38364,-38296,-38229, - -38161,-38094,-38027,-37960,-37893,-37826,-37759,-37692, - -37625,-37558,-37491,-37425,-37358,-37291,-37225,-37158, - -37092,-37026,-36959,-36893,-36827,-36761,-36695,-36629, - -36563,-36497,-36431,-36365,-36300,-36234,-36168,-36103, - -36037,-35972,-35907,-35841,-35776,-35711,-35646,-35580, - -35515,-35450,-35385,-35321,-35256,-35191,-35126,-35062, - -34997,-34932,-34868,-34803,-34739,-34675,-34610,-34546, - -34482,-34418,-34354,-34289,-34225,-34162,-34098,-34034, - -33970,-33906,-33843,-33779,-33715,-33652,-33588,-33525, - -33461,-33398,-33335,-33272,-33208,-33145,-33082,-33019, - -32956,-32893,-32830,-32767,-32705,-32642,-32579,-32516, - -32454,-32391,-32329,-32266,-32204,-32141,-32079,-32017, - -31955,-31892,-31830,-31768,-31706,-31644,-31582,-31520, - -31458,-31396,-31335,-31273,-31211,-31150,-31088,-31026, - -30965,-30904,-30842,-30781,-30719,-30658,-30597,-30536, - -30474,-30413,-30352,-30291,-30230,-30169,-30108,-30048, - -29987,-29926,-29865,-29805,-29744,-29683,-29623,-29562, - -29502,-29441,-29381,-29321,-29260,-29200,-29140,-29080, - -29020,-28959,-28899,-28839,-28779,-28719,-28660,-28600, - -28540,-28480,-28420,-28361,-28301,-28241,-28182,-28122, - -28063,-28003,-27944,-27884,-27825,-27766,-27707,-27647, - -27588,-27529,-27470,-27411,-27352,-27293,-27234,-27175, - -27116,-27057,-26998,-26940,-26881,-26822,-26763,-26705, - -26646,-26588,-26529,-26471,-26412,-26354,-26295,-26237, - -26179,-26120,-26062,-26004,-25946,-25888,-25830,-25772, - -25714,-25656,-25598,-25540,-25482,-25424,-25366,-25308, - -25251,-25193,-25135,-25078,-25020,-24962,-24905,-24847, - -24790,-24732,-24675,-24618,-24560,-24503,-24446,-24389, - -24331,-24274,-24217,-24160,-24103,-24046,-23989,-23932, - -23875,-23818,-23761,-23704,-23647,-23591,-23534,-23477, - -23420,-23364,-23307,-23250,-23194,-23137,-23081,-23024, - -22968,-22911,-22855,-22799,-22742,-22686,-22630,-22573, - -22517,-22461,-22405,-22349,-22293,-22237,-22181,-22125, - -22069,-22013,-21957,-21901,-21845,-21789,-21733,-21678, - -21622,-21566,-21510,-21455,-21399,-21343,-21288,-21232, - -21177,-21121,-21066,-21010,-20955,-20900,-20844,-20789, - -20734,-20678,-20623,-20568,-20513,-20457,-20402,-20347, - -20292,-20237,-20182,-20127,-20072,-20017,-19962,-19907, - -19852,-19797,-19742,-19688,-19633,-19578,-19523,-19469, - -19414,-19359,-19305,-19250,-19195,-19141,-19086,-19032, - -18977,-18923,-18868,-18814,-18760,-18705,-18651,-18597, - -18542,-18488,-18434,-18380,-18325,-18271,-18217,-18163, - -18109,-18055,-18001,-17946,-17892,-17838,-17784,-17731, - -17677,-17623,-17569,-17515,-17461,-17407,-17353,-17300, - -17246,-17192,-17138,-17085,-17031,-16977,-16924,-16870, - -16817,-16763,-16710,-16656,-16603,-16549,-16496,-16442, - -16389,-16335,-16282,-16229,-16175,-16122,-16069,-16015, - -15962,-15909,-15856,-15802,-15749,-15696,-15643,-15590, - -15537,-15484,-15431,-15378,-15325,-15272,-15219,-15166, - -15113,-15060,-15007,-14954,-14901,-14848,-14795,-14743, - -14690,-14637,-14584,-14531,-14479,-14426,-14373,-14321, - -14268,-14215,-14163,-14110,-14057,-14005,-13952,-13900, - -13847,-13795,-13742,-13690,-13637,-13585,-13533,-13480, - -13428,-13375,-13323,-13271,-13218,-13166,-13114,-13062, - -13009,-12957,-12905,-12853,-12800,-12748,-12696,-12644, - -12592,-12540,-12488,-12436,-12383,-12331,-12279,-12227, - -12175,-12123,-12071,-12019,-11967,-11916,-11864,-11812, - -11760,-11708,-11656,-11604,-11552,-11501,-11449,-11397, - -11345,-11293,-11242,-11190,-11138,-11086,-11035,-10983, - -10931,-10880,-10828,-10777,-10725,-10673,-10622,-10570, - -10519,-10467,-10415,-10364,-10312,-10261,-10209,-10158, - -10106,-10055,-10004,-9952,-9901,-9849,-9798,-9747, - -9695,-9644,-9592,-9541,-9490,-9438,-9387,-9336, - -9285,-9233,-9182,-9131,-9080,-9028,-8977,-8926, - -8875,-8824,-8772,-8721,-8670,-8619,-8568,-8517, - -8466,-8414,-8363,-8312,-8261,-8210,-8159,-8108, - -8057,-8006,-7955,-7904,-7853,-7802,-7751,-7700, - -7649,-7598,-7547,-7496,-7445,-7395,-7344,-7293, - -7242,-7191,-7140,-7089,-7038,-6988,-6937,-6886, - -6835,-6784,-6733,-6683,-6632,-6581,-6530,-6480, - -6429,-6378,-6327,-6277,-6226,-6175,-6124,-6074, - -6023,-5972,-5922,-5871,-5820,-5770,-5719,-5668, - -5618,-5567,-5517,-5466,-5415,-5365,-5314,-5264, - -5213,-5162,-5112,-5061,-5011,-4960,-4910,-4859, - -4808,-4758,-4707,-4657,-4606,-4556,-4505,-4455, - -4404,-4354,-4303,-4253,-4202,-4152,-4101,-4051, - -4001,-3950,-3900,-3849,-3799,-3748,-3698,-3648, - -3597,-3547,-3496,-3446,-3395,-3345,-3295,-3244, - -3194,-3144,-3093,-3043,-2992,-2942,-2892,-2841, - -2791,-2741,-2690,-2640,-2590,-2539,-2489,-2439, - -2388,-2338,-2288,-2237,-2187,-2137,-2086,-2036, - -1986,-1935,-1885,-1835,-1784,-1734,-1684,-1633, - -1583,-1533,-1483,-1432,-1382,-1332,-1281,-1231, - -1181,-1131,-1080,-1030,-980,-929,-879,-829, - -779,-728,-678,-628,-578,-527,-477,-427, - -376,-326,-276,-226,-175,-125,-75,-25, - 25,75,125,175,226,276,326,376, - 427,477,527,578,628,678,728,779, - 829,879,929,980,1030,1080,1131,1181, - 1231,1281,1332,1382,1432,1483,1533,1583, - 1633,1684,1734,1784,1835,1885,1935,1986, - 2036,2086,2137,2187,2237,2288,2338,2388, - 2439,2489,2539,2590,2640,2690,2741,2791, - 2841,2892,2942,2992,3043,3093,3144,3194, - 3244,3295,3345,3395,3446,3496,3547,3597, - 3648,3698,3748,3799,3849,3900,3950,4001, - 4051,4101,4152,4202,4253,4303,4354,4404, - 4455,4505,4556,4606,4657,4707,4758,4808, - 4859,4910,4960,5011,5061,5112,5162,5213, - 5264,5314,5365,5415,5466,5517,5567,5618, - 5668,5719,5770,5820,5871,5922,5972,6023, - 6074,6124,6175,6226,6277,6327,6378,6429, - 6480,6530,6581,6632,6683,6733,6784,6835, - 6886,6937,6988,7038,7089,7140,7191,7242, - 7293,7344,7395,7445,7496,7547,7598,7649, - 7700,7751,7802,7853,7904,7955,8006,8057, - 8108,8159,8210,8261,8312,8363,8414,8466, - 8517,8568,8619,8670,8721,8772,8824,8875, - 8926,8977,9028,9080,9131,9182,9233,9285, - 9336,9387,9438,9490,9541,9592,9644,9695, - 9747,9798,9849,9901,9952,10004,10055,10106, - 10158,10209,10261,10312,10364,10415,10467,10519, - 10570,10622,10673,10725,10777,10828,10880,10931, - 10983,11035,11086,11138,11190,11242,11293,11345, - 11397,11449,11501,11552,11604,11656,11708,11760, - 11812,11864,11916,11967,12019,12071,12123,12175, - 12227,12279,12331,12383,12436,12488,12540,12592, - 12644,12696,12748,12800,12853,12905,12957,13009, - 13062,13114,13166,13218,13271,13323,13375,13428, - 13480,13533,13585,13637,13690,13742,13795,13847, - 13900,13952,14005,14057,14110,14163,14215,14268, - 14321,14373,14426,14479,14531,14584,14637,14690, - 14743,14795,14848,14901,14954,15007,15060,15113, - 15166,15219,15272,15325,15378,15431,15484,15537, - 15590,15643,15696,15749,15802,15856,15909,15962, - 16015,16069,16122,16175,16229,16282,16335,16389, - 16442,16496,16549,16603,16656,16710,16763,16817, - 16870,16924,16977,17031,17085,17138,17192,17246, - 17300,17353,17407,17461,17515,17569,17623,17677, - 17731,17784,17838,17892,17946,18001,18055,18109, - 18163,18217,18271,18325,18380,18434,18488,18542, - 18597,18651,18705,18760,18814,18868,18923,18977, - 19032,19086,19141,19195,19250,19305,19359,19414, - 19469,19523,19578,19633,19688,19742,19797,19852, - 19907,19962,20017,20072,20127,20182,20237,20292, - 20347,20402,20457,20513,20568,20623,20678,20734, - 20789,20844,20900,20955,21010,21066,21121,21177, - 21232,21288,21343,21399,21455,21510,21566,21622, - 21678,21733,21789,21845,21901,21957,22013,22069, - 22125,22181,22237,22293,22349,22405,22461,22517, - 22573,22630,22686,22742,22799,22855,22911,22968, - 23024,23081,23137,23194,23250,23307,23364,23420, - 23477,23534,23591,23647,23704,23761,23818,23875, - 23932,23989,24046,24103,24160,24217,24274,24331, - 24389,24446,24503,24560,24618,24675,24732,24790, - 24847,24905,24962,25020,25078,25135,25193,25251, - 25308,25366,25424,25482,25540,25598,25656,25714, - 25772,25830,25888,25946,26004,26062,26120,26179, - 26237,26295,26354,26412,26471,26529,26588,26646, - 26705,26763,26822,26881,26940,26998,27057,27116, - 27175,27234,27293,27352,27411,27470,27529,27588, - 27647,27707,27766,27825,27884,27944,28003,28063, - 28122,28182,28241,28301,28361,28420,28480,28540, - 28600,28660,28719,28779,28839,28899,28959,29020, - 29080,29140,29200,29260,29321,29381,29441,29502, - 29562,29623,29683,29744,29805,29865,29926,29987, - 30048,30108,30169,30230,30291,30352,30413,30474, - 30536,30597,30658,30719,30781,30842,30904,30965, - 31026,31088,31150,31211,31273,31335,31396,31458, - 31520,31582,31644,31706,31768,31830,31892,31955, - 32017,32079,32141,32204,32266,32329,32391,32454, - 32516,32579,32642,32705,32767,32830,32893,32956, - 33019,33082,33145,33208,33272,33335,33398,33461, - 33525,33588,33652,33715,33779,33843,33906,33970, - 34034,34098,34162,34225,34289,34354,34418,34482, - 34546,34610,34675,34739,34803,34868,34932,34997, - 35062,35126,35191,35256,35321,35385,35450,35515, - 35580,35646,35711,35776,35841,35907,35972,36037, - 36103,36168,36234,36300,36365,36431,36497,36563, - 36629,36695,36761,36827,36893,36959,37026,37092, - 37158,37225,37291,37358,37425,37491,37558,37625, - 37692,37759,37826,37893,37960,38027,38094,38161, - 38229,38296,38364,38431,38499,38566,38634,38702, - 38770,38837,38905,38973,39042,39110,39178,39246, - 39314,39383,39451,39520,39588,39657,39726,39794, - 39863,39932,40001,40070,40139,40208,40278,40347, - 40416,40486,40555,40625,40694,40764,40834,40904, - 40973,41043,41113,41184,41254,41324,41394,41465, - 41535,41605,41676,41747,41817,41888,41959,42030, - 42101,42172,42243,42314,42385,42457,42528,42600, - 42671,42743,42814,42886,42958,43030,43102,43174, - 43246,43318,43390,43463,43535,43608,43680,43753, - 43826,43898,43971,44044,44117,44190,44263,44337, - 44410,44483,44557,44630,44704,44778,44851,44925, - 44999,45073,45147,45221,45296,45370,45444,45519, - 45593,45668,45743,45818,45892,45967,46042,46118, - 46193,46268,46343,46419,46494,46570,46646,46721, - 46797,46873,46949,47025,47102,47178,47254,47331, - 47407,47484,47560,47637,47714,47791,47868,47945, - 48022,48100,48177,48255,48332,48410,48488,48565, - 48643,48721,48799,48878,48956,49034,49113,49191, - 49270,49349,49427,49506,49585,49664,49744,49823, - 49902,49982,50061,50141,50221,50300,50380,50460, - 50540,50621,50701,50781,50862,50942,51023,51104, - 51185,51266,51347,51428,51509,51591,51672,51754, - 51835,51917,51999,52081,52163,52245,52327,52410, - 52492,52575,52657,52740,52823,52906,52989,53072, - 53156,53239,53322,53406,53490,53574,53657,53741, - 53826,53910,53994,54079,54163,54248,54333,54417, - 54502,54587,54673,54758,54843,54929,55015,55100, - 55186,55272,55358,55444,55531,55617,55704,55790, - 55877,55964,56051,56138,56225,56312,56400,56487, - 56575,56663,56751,56839,56927,57015,57104,57192, - 57281,57369,57458,57547,57636,57725,57815,57904, - 57994,58083,58173,58263,58353,58443,58534,58624, - 58715,58805,58896,58987,59078,59169,59261,59352, - 59444,59535,59627,59719,59811,59903,59996,60088, - 60181,60273,60366,60459,60552,60646,60739,60833, - 60926,61020,61114,61208,61302,61396,61491,61585, - 61680,61775,61870,61965,62060,62156,62251,62347, - 62443,62539,62635,62731,62828,62924,63021,63118, - 63215,63312,63409,63506,63604,63702,63799,63897, - 63996,64094,64192,64291,64389,64488,64587,64687, - 64786,64885,64985,65085,65185,65285,65385,65485, - 65586,65686,65787,65888,65989,66091,66192,66294, - 66396,66498,66600,66702,66804,66907,67010,67113, - 67216,67319,67422,67526,67629,67733,67837,67942, - 68046,68151,68255,68360,68465,68570,68676,68781, - 68887,68993,69099,69205,69312,69418,69525,69632, - 69739,69846,69954,70061,70169,70277,70385,70494, - 70602,70711,70820,70929,71038,71147,71257,71367, - 71477,71587,71697,71808,71918,72029,72140,72252, - 72363,72475,72587,72699,72811,72923,73036,73149, - 73262,73375,73488,73602,73715,73829,73944,74058, - 74172,74287,74402,74517,74633,74748,74864,74980, - 75096,75213,75329,75446,75563,75680,75797,75915, - 76033,76151,76269,76388,76506,76625,76744,76864, - 76983,77103,77223,77343,77463,77584,77705,77826, - 77947,78068,78190,78312,78434,78557,78679,78802, - 78925,79048,79172,79296,79420,79544,79668,79793, - 79918,80043,80168,80294,80420,80546,80672,80799, - 80925,81053,81180,81307,81435,81563,81691,81820, - 81949,82078,82207,82336,82466,82596,82726,82857, - 82987,83118,83250,83381,83513,83645,83777,83910, - 84043,84176,84309,84443,84576,84710,84845,84980, - 85114,85250,85385,85521,85657,85793,85930,86066, - 86204,86341,86479,86616,86755,86893,87032,87171, - 87310,87450,87590,87730,87871,88011,88152,88294, - 88435,88577,88720,88862,89005,89148,89292,89435, - 89579,89724,89868,90013,90158,90304,90450,90596, - 90742,90889,91036,91184,91332,91480,91628,91777, - 91926,92075,92225,92375,92525,92675,92826,92978, - 93129,93281,93434,93586,93739,93892,94046,94200, - 94354,94509,94664,94819,94975,95131,95287,95444, - 95601,95758,95916,96074,96233,96391,96551,96710, - 96870,97030,97191,97352,97513,97675,97837,98000, - 98163,98326,98489,98653,98818,98982,99148,99313, - 99479,99645,99812,99979,100146,100314,100482,100651, - 100820,100990,101159,101330,101500,101671,101843,102015, - 102187,102360,102533,102706,102880,103054,103229,103404, - 103580,103756,103933,104109,104287,104465,104643,104821, - 105000,105180,105360,105540,105721,105902,106084,106266, - 106449,106632,106816,107000,107184,107369,107555,107741, - 107927,108114,108301,108489,108677,108866,109055,109245, - 109435,109626,109817,110008,110200,110393,110586,110780, - 110974,111169,111364,111560,111756,111952,112150,112347, - 112546,112744,112944,113143,113344,113545,113746,113948, - 114151,114354,114557,114761,114966,115171,115377,115583, - 115790,115998,116206,116414,116623,116833,117044,117254, - 117466,117678,117891,118104,118318,118532,118747,118963, - 119179,119396,119613,119831,120050,120269,120489,120709, - 120930,121152,121374,121597,121821,122045,122270,122496, - 122722,122949,123176,123404,123633,123863,124093,124324, - 124555,124787,125020,125254,125488,125723,125959,126195, - 126432,126669,126908,127147,127387,127627,127869,128111, - 128353,128597,128841,129086,129332,129578,129825,130073, - 130322,130571,130821,131072,131324,131576,131830,132084, - 132339,132594,132851,133108,133366,133625,133884,134145, - 134406,134668,134931,135195,135459,135725,135991,136258, - 136526,136795,137065,137335,137607,137879,138152,138426, - 138701,138977,139254,139532,139810,140090,140370,140651, - 140934,141217,141501,141786,142072,142359,142647,142936, - 143226,143517,143808,144101,144395,144690,144986,145282, - 145580,145879,146179,146480,146782,147084,147388,147693, - 148000,148307,148615,148924,149235,149546,149859,150172, - 150487,150803,151120,151438,151757,152077,152399,152722, - 153045,153370,153697,154024,154352,154682,155013,155345, - 155678,156013,156349,156686,157024,157363,157704,158046, - 158389,158734,159079,159427,159775,160125,160476,160828, - 161182,161537,161893,162251,162610,162970,163332,163695, - 164060,164426,164793,165162,165532,165904,166277,166651, - 167027,167405,167784,168164,168546,168930,169315,169701, - 170089,170479,170870,171263,171657,172053,172451,172850, - 173251,173653,174057,174463,174870,175279,175690,176102, - 176516,176932,177349,177769,178190,178612,179037,179463, - 179891,180321,180753,181186,181622,182059,182498,182939, - 183382,183827,184274,184722,185173,185625,186080,186536, - 186995,187455,187918,188382,188849,189318,189789,190261, - 190736,191213,191693,192174,192658,193143,193631,194122, - 194614,195109,195606,196105,196606,197110,197616,198125, - 198636,199149,199664,200182,200703,201226,201751,202279, - 202809,203342,203878,204416,204956,205500,206045,206594, - 207145,207699,208255,208815,209376,209941,210509,211079, - 211652,212228,212807,213389,213973,214561,215151,215745, - 216341,216941,217544,218149,218758,219370,219985,220603, - 221225,221849,222477,223108,223743,224381,225022,225666, - 226314,226966,227621,228279,228941,229606,230275,230948, - 231624,232304,232988,233676,234367,235062,235761,236463, - 237170,237881,238595,239314,240036,240763,241493,242228, - 242967,243711,244458,245210,245966,246727,247492,248261, - 249035,249813,250596,251384,252176,252973,253774,254581, - 255392,256208,257029,257855,258686,259522,260363,261209, - 262060,262917,263779,264646,265519,266397,267280,268169, - 269064,269965,270871,271782,272700,273624,274553,275489, - 276430,277378,278332,279292,280258,281231,282210,283195, - 284188,285186,286192,287204,288223,289249,290282,291322, - 292369,293423,294485,295554,296630,297714,298805,299904, - 301011,302126,303248,304379,305517,306664,307819,308983, - 310154,311335,312524,313721,314928,316143,317368,318601, - 319844,321097,322358,323629,324910,326201,327502,328812, - 330133,331464,332805,334157,335519,336892,338276,339671, - 341078,342495,343924,345364,346816,348280,349756,351244, - 352744,354257,355783,357321,358872,360436,362013,363604, - 365208,366826,368459,370105,371765,373440,375130,376835, - 378555,380290,382040,383807,385589,387387,389202,391034, - 392882,394747,396630,398530,400448,402384,404338,406311, - 408303,410314,412344,414395,416465,418555,420666,422798, - 424951,427125,429321,431540,433781,436045,438332,440643, - 442978,445337,447720,450129,452564,455024,457511,460024, - 462565,465133,467730,470355,473009,475692,478406,481150, - 483925,486732,489571,492443,495348,498287,501261,504269, - 507313,510394,513512,516667,519861,523094,526366,529680, - 533034,536431,539870,543354,546881,550455,554074,557741, - 561456,565221,569035,572901,576818,580789,584815,588896, - 593033,597229,601483,605798,610174,614613,619117,623686, - 628323,633028,637803,642651,647572,652568,657640,662792, - 668024,673338,678737,684223,689797,695462,701219,707072, - 713023,719074,725227,731486,737853,744331,750922,757631, - 764460,771411,778490,785699,793041,800521,808143,815910, - 823827,831898,840127,848520,857081,865817,874730,883829, - 893117,902602,912289,922186,932298,942633,953199,964003, - 975054,986361,997931,1009774,1021901,1034322,1047046,1060087, - 1073455,1087164,1101225,1115654,1130465,1145673,1161294,1177345, - 1193846,1210813,1228269,1246234,1264730,1283783,1303416,1323658, - 1344537,1366084,1388330,1411312,1435065,1459630,1485049,1511367, - 1538632,1566898,1596220,1626658,1658278,1691149,1725348,1760956, - 1798063,1836758,1877161,1919378,1963536,2009771,2058233,2109087, - 2162516,2218719,2277919,2340362,2406322,2476104,2550052,2628549, - 2712030,2800983,2895966,2997613,3106651,3223918,3350381,3487165, - 3635590,3797206,3973855,4167737,4381502,4618375,4882318,5178251, - 5512368,5892567,6329090,6835455,7429880,8137527,8994149,10052327, - 11392683,13145455,15535599,18988036,24413316,34178904,56965752,170910304 -}; - + { + -170910304, -56965752, -34178904, -24413316, -18988036, -15535599, -13145455, -11392683, + -10052327, -8994149, -8137527, -7429880, -6835455, -6329090, -5892567, -5512368, + -5178251, -4882318, -4618375, -4381502, -4167737, -3973855, -3797206, -3635590, + -3487165, -3350381, -3223918, -3106651, -2997613, -2895966, -2800983, -2712030, + -2628549, -2550052, -2476104, -2406322, -2340362, -2277919, -2218719, -2162516, + -2109087, -2058233, -2009771, -1963536, -1919378, -1877161, -1836758, -1798063, + -1760956, -1725348, -1691149, -1658278, -1626658, -1596220, -1566898, -1538632, + -1511367, -1485049, -1459630, -1435065, -1411312, -1388330, -1366084, -1344537, + -1323658, -1303416, -1283783, -1264730, -1246234, -1228269, -1210813, -1193846, + -1177345, -1161294, -1145673, -1130465, -1115654, -1101225, -1087164, -1073455, + -1060087, -1047046, -1034322, -1021901, -1009774, -997931, -986361, -975054, + -964003, -953199, -942633, -932298, -922186, -912289, -902602, -893117, + -883829, -874730, -865817, -857081, -848520, -840127, -831898, -823827, + -815910, -808143, -800521, -793041, -785699, -778490, -771411, -764460, + -757631, -750922, -744331, -737853, -731486, -725227, -719074, -713023, + -707072, -701219, -695462, -689797, -684223, -678737, -673338, -668024, + -662792, -657640, -652568, -647572, -642651, -637803, -633028, -628323, + -623686, -619117, -614613, -610174, -605798, -601483, -597229, -593033, + -588896, -584815, -580789, -576818, -572901, -569035, -565221, -561456, + -557741, -554074, -550455, -546881, -543354, -539870, -536431, -533034, + -529680, -526366, -523094, -519861, -516667, -513512, -510394, -507313, + -504269, -501261, -498287, -495348, -492443, -489571, -486732, -483925, + -481150, -478406, -475692, -473009, -470355, -467730, -465133, -462565, + -460024, -457511, -455024, -452564, -450129, -447720, -445337, -442978, + -440643, -438332, -436045, -433781, -431540, -429321, -427125, -424951, + -422798, -420666, -418555, -416465, -414395, -412344, -410314, -408303, + -406311, -404338, -402384, -400448, -398530, -396630, -394747, -392882, + -391034, -389202, -387387, -385589, -383807, -382040, -380290, -378555, + -376835, -375130, -373440, -371765, -370105, -368459, -366826, -365208, + -363604, -362013, -360436, -358872, -357321, -355783, -354257, -352744, + -351244, -349756, -348280, -346816, -345364, -343924, -342495, -341078, + -339671, -338276, -336892, -335519, -334157, -332805, -331464, -330133, + -328812, -327502, -326201, -324910, -323629, -322358, -321097, -319844, + -318601, -317368, -316143, -314928, -313721, -312524, -311335, -310154, + -308983, -307819, -306664, -305517, -304379, -303248, -302126, -301011, + -299904, -298805, -297714, -296630, -295554, -294485, -293423, -292369, + -291322, -290282, -289249, -288223, -287204, -286192, -285186, -284188, + -283195, -282210, -281231, -280258, -279292, -278332, -277378, -276430, + -275489, -274553, -273624, -272700, -271782, -270871, -269965, -269064, + -268169, -267280, -266397, -265519, -264646, -263779, -262917, -262060, + -261209, -260363, -259522, -258686, -257855, -257029, -256208, -255392, + -254581, -253774, -252973, -252176, -251384, -250596, -249813, -249035, + -248261, -247492, -246727, -245966, -245210, -244458, -243711, -242967, + -242228, -241493, -240763, -240036, -239314, -238595, -237881, -237170, + -236463, -235761, -235062, -234367, -233676, -232988, -232304, -231624, + -230948, -230275, -229606, -228941, -228279, -227621, -226966, -226314, + -225666, -225022, -224381, -223743, -223108, -222477, -221849, -221225, + -220603, -219985, -219370, -218758, -218149, -217544, -216941, -216341, + -215745, -215151, -214561, -213973, -213389, -212807, -212228, -211652, + -211079, -210509, -209941, -209376, -208815, -208255, -207699, -207145, + -206594, -206045, -205500, -204956, -204416, -203878, -203342, -202809, + -202279, -201751, -201226, -200703, -200182, -199664, -199149, -198636, + -198125, -197616, -197110, -196606, -196105, -195606, -195109, -194614, + -194122, -193631, -193143, -192658, -192174, -191693, -191213, -190736, + -190261, -189789, -189318, -188849, -188382, -187918, -187455, -186995, + -186536, -186080, -185625, -185173, -184722, -184274, -183827, -183382, + -182939, -182498, -182059, -181622, -181186, -180753, -180321, -179891, + -179463, -179037, -178612, -178190, -177769, -177349, -176932, -176516, + -176102, -175690, -175279, -174870, -174463, -174057, -173653, -173251, + -172850, -172451, -172053, -171657, -171263, -170870, -170479, -170089, + -169701, -169315, -168930, -168546, -168164, -167784, -167405, -167027, + -166651, -166277, -165904, -165532, -165162, -164793, -164426, -164060, + -163695, -163332, -162970, -162610, -162251, -161893, -161537, -161182, + -160828, -160476, -160125, -159775, -159427, -159079, -158734, -158389, + -158046, -157704, -157363, -157024, -156686, -156349, -156013, -155678, + -155345, -155013, -154682, -154352, -154024, -153697, -153370, -153045, + -152722, -152399, -152077, -151757, -151438, -151120, -150803, -150487, + -150172, -149859, -149546, -149235, -148924, -148615, -148307, -148000, + -147693, -147388, -147084, -146782, -146480, -146179, -145879, -145580, + -145282, -144986, -144690, -144395, -144101, -143808, -143517, -143226, + -142936, -142647, -142359, -142072, -141786, -141501, -141217, -140934, + -140651, -140370, -140090, -139810, -139532, -139254, -138977, -138701, + -138426, -138152, -137879, -137607, -137335, -137065, -136795, -136526, + -136258, -135991, -135725, -135459, -135195, -134931, -134668, -134406, + -134145, -133884, -133625, -133366, -133108, -132851, -132594, -132339, + -132084, -131830, -131576, -131324, -131072, -130821, -130571, -130322, + -130073, -129825, -129578, -129332, -129086, -128841, -128597, -128353, + -128111, -127869, -127627, -127387, -127147, -126908, -126669, -126432, + -126195, -125959, -125723, -125488, -125254, -125020, -124787, -124555, + -124324, -124093, -123863, -123633, -123404, -123176, -122949, -122722, + -122496, -122270, -122045, -121821, -121597, -121374, -121152, -120930, + -120709, -120489, -120269, -120050, -119831, -119613, -119396, -119179, + -118963, -118747, -118532, -118318, -118104, -117891, -117678, -117466, + -117254, -117044, -116833, -116623, -116414, -116206, -115998, -115790, + -115583, -115377, -115171, -114966, -114761, -114557, -114354, -114151, + -113948, -113746, -113545, -113344, -113143, -112944, -112744, -112546, + -112347, -112150, -111952, -111756, -111560, -111364, -111169, -110974, + -110780, -110586, -110393, -110200, -110008, -109817, -109626, -109435, + -109245, -109055, -108866, -108677, -108489, -108301, -108114, -107927, + -107741, -107555, -107369, -107184, -107000, -106816, -106632, -106449, + -106266, -106084, -105902, -105721, -105540, -105360, -105180, -105000, + -104821, -104643, -104465, -104287, -104109, -103933, -103756, -103580, + -103404, -103229, -103054, -102880, -102706, -102533, -102360, -102187, + -102015, -101843, -101671, -101500, -101330, -101159, -100990, -100820, + -100651, -100482, -100314, -100146, -99979, -99812, -99645, -99479, + -99313, -99148, -98982, -98818, -98653, -98489, -98326, -98163, + -98000, -97837, -97675, -97513, -97352, -97191, -97030, -96870, + -96710, -96551, -96391, -96233, -96074, -95916, -95758, -95601, + -95444, -95287, -95131, -94975, -94819, -94664, -94509, -94354, + -94200, -94046, -93892, -93739, -93586, -93434, -93281, -93129, + -92978, -92826, -92675, -92525, -92375, -92225, -92075, -91926, + -91777, -91628, -91480, -91332, -91184, -91036, -90889, -90742, + -90596, -90450, -90304, -90158, -90013, -89868, -89724, -89579, + -89435, -89292, -89148, -89005, -88862, -88720, -88577, -88435, + -88294, -88152, -88011, -87871, -87730, -87590, -87450, -87310, + -87171, -87032, -86893, -86755, -86616, -86479, -86341, -86204, + -86066, -85930, -85793, -85657, -85521, -85385, -85250, -85114, + -84980, -84845, -84710, -84576, -84443, -84309, -84176, -84043, + -83910, -83777, -83645, -83513, -83381, -83250, -83118, -82987, + -82857, -82726, -82596, -82466, -82336, -82207, -82078, -81949, + -81820, -81691, -81563, -81435, -81307, -81180, -81053, -80925, + -80799, -80672, -80546, -80420, -80294, -80168, -80043, -79918, + -79793, -79668, -79544, -79420, -79296, -79172, -79048, -78925, + -78802, -78679, -78557, -78434, -78312, -78190, -78068, -77947, + -77826, -77705, -77584, -77463, -77343, -77223, -77103, -76983, + -76864, -76744, -76625, -76506, -76388, -76269, -76151, -76033, + -75915, -75797, -75680, -75563, -75446, -75329, -75213, -75096, + -74980, -74864, -74748, -74633, -74517, -74402, -74287, -74172, + -74058, -73944, -73829, -73715, -73602, -73488, -73375, -73262, + -73149, -73036, -72923, -72811, -72699, -72587, -72475, -72363, + -72252, -72140, -72029, -71918, -71808, -71697, -71587, -71477, + -71367, -71257, -71147, -71038, -70929, -70820, -70711, -70602, + -70494, -70385, -70277, -70169, -70061, -69954, -69846, -69739, + -69632, -69525, -69418, -69312, -69205, -69099, -68993, -68887, + -68781, -68676, -68570, -68465, -68360, -68255, -68151, -68046, + -67942, -67837, -67733, -67629, -67526, -67422, -67319, -67216, + -67113, -67010, -66907, -66804, -66702, -66600, -66498, -66396, + -66294, -66192, -66091, -65989, -65888, -65787, -65686, -65586, + -65485, -65385, -65285, -65185, -65085, -64985, -64885, -64786, + -64687, -64587, -64488, -64389, -64291, -64192, -64094, -63996, + -63897, -63799, -63702, -63604, -63506, -63409, -63312, -63215, + -63118, -63021, -62924, -62828, -62731, -62635, -62539, -62443, + -62347, -62251, -62156, -62060, -61965, -61870, -61775, -61680, + -61585, -61491, -61396, -61302, -61208, -61114, -61020, -60926, + -60833, -60739, -60646, -60552, -60459, -60366, -60273, -60181, + -60088, -59996, -59903, -59811, -59719, -59627, -59535, -59444, + -59352, -59261, -59169, -59078, -58987, -58896, -58805, -58715, + -58624, -58534, -58443, -58353, -58263, -58173, -58083, -57994, + -57904, -57815, -57725, -57636, -57547, -57458, -57369, -57281, + -57192, -57104, -57015, -56927, -56839, -56751, -56663, -56575, + -56487, -56400, -56312, -56225, -56138, -56051, -55964, -55877, + -55790, -55704, -55617, -55531, -55444, -55358, -55272, -55186, + -55100, -55015, -54929, -54843, -54758, -54673, -54587, -54502, + -54417, -54333, -54248, -54163, -54079, -53994, -53910, -53826, + -53741, -53657, -53574, -53490, -53406, -53322, -53239, -53156, + -53072, -52989, -52906, -52823, -52740, -52657, -52575, -52492, + -52410, -52327, -52245, -52163, -52081, -51999, -51917, -51835, + -51754, -51672, -51591, -51509, -51428, -51347, -51266, -51185, + -51104, -51023, -50942, -50862, -50781, -50701, -50621, -50540, + -50460, -50380, -50300, -50221, -50141, -50061, -49982, -49902, + -49823, -49744, -49664, -49585, -49506, -49427, -49349, -49270, + -49191, -49113, -49034, -48956, -48878, -48799, -48721, -48643, + -48565, -48488, -48410, -48332, -48255, -48177, -48100, -48022, + -47945, -47868, -47791, -47714, -47637, -47560, -47484, -47407, + -47331, -47254, -47178, -47102, -47025, -46949, -46873, -46797, + -46721, -46646, -46570, -46494, -46419, -46343, -46268, -46193, + -46118, -46042, -45967, -45892, -45818, -45743, -45668, -45593, + -45519, -45444, -45370, -45296, -45221, -45147, -45073, -44999, + -44925, -44851, -44778, -44704, -44630, -44557, -44483, -44410, + -44337, -44263, -44190, -44117, -44044, -43971, -43898, -43826, + -43753, -43680, -43608, -43535, -43463, -43390, -43318, -43246, + -43174, -43102, -43030, -42958, -42886, -42814, -42743, -42671, + -42600, -42528, -42457, -42385, -42314, -42243, -42172, -42101, + -42030, -41959, -41888, -41817, -41747, -41676, -41605, -41535, + -41465, -41394, -41324, -41254, -41184, -41113, -41043, -40973, + -40904, -40834, -40764, -40694, -40625, -40555, -40486, -40416, + -40347, -40278, -40208, -40139, -40070, -40001, -39932, -39863, + -39794, -39726, -39657, -39588, -39520, -39451, -39383, -39314, + -39246, -39178, -39110, -39042, -38973, -38905, -38837, -38770, + -38702, -38634, -38566, -38499, -38431, -38364, -38296, -38229, + -38161, -38094, -38027, -37960, -37893, -37826, -37759, -37692, + -37625, -37558, -37491, -37425, -37358, -37291, -37225, -37158, + -37092, -37026, -36959, -36893, -36827, -36761, -36695, -36629, + -36563, -36497, -36431, -36365, -36300, -36234, -36168, -36103, + -36037, -35972, -35907, -35841, -35776, -35711, -35646, -35580, + -35515, -35450, -35385, -35321, -35256, -35191, -35126, -35062, + -34997, -34932, -34868, -34803, -34739, -34675, -34610, -34546, + -34482, -34418, -34354, -34289, -34225, -34162, -34098, -34034, + -33970, -33906, -33843, -33779, -33715, -33652, -33588, -33525, + -33461, -33398, -33335, -33272, -33208, -33145, -33082, -33019, + -32956, -32893, -32830, -32767, -32705, -32642, -32579, -32516, + -32454, -32391, -32329, -32266, -32204, -32141, -32079, -32017, + -31955, -31892, -31830, -31768, -31706, -31644, -31582, -31520, + -31458, -31396, -31335, -31273, -31211, -31150, -31088, -31026, + -30965, -30904, -30842, -30781, -30719, -30658, -30597, -30536, + -30474, -30413, -30352, -30291, -30230, -30169, -30108, -30048, + -29987, -29926, -29865, -29805, -29744, -29683, -29623, -29562, + -29502, -29441, -29381, -29321, -29260, -29200, -29140, -29080, + -29020, -28959, -28899, -28839, -28779, -28719, -28660, -28600, + -28540, -28480, -28420, -28361, -28301, -28241, -28182, -28122, + -28063, -28003, -27944, -27884, -27825, -27766, -27707, -27647, + -27588, -27529, -27470, -27411, -27352, -27293, -27234, -27175, + -27116, -27057, -26998, -26940, -26881, -26822, -26763, -26705, + -26646, -26588, -26529, -26471, -26412, -26354, -26295, -26237, + -26179, -26120, -26062, -26004, -25946, -25888, -25830, -25772, + -25714, -25656, -25598, -25540, -25482, -25424, -25366, -25308, + -25251, -25193, -25135, -25078, -25020, -24962, -24905, -24847, + -24790, -24732, -24675, -24618, -24560, -24503, -24446, -24389, + -24331, -24274, -24217, -24160, -24103, -24046, -23989, -23932, + -23875, -23818, -23761, -23704, -23647, -23591, -23534, -23477, + -23420, -23364, -23307, -23250, -23194, -23137, -23081, -23024, + -22968, -22911, -22855, -22799, -22742, -22686, -22630, -22573, + -22517, -22461, -22405, -22349, -22293, -22237, -22181, -22125, + -22069, -22013, -21957, -21901, -21845, -21789, -21733, -21678, + -21622, -21566, -21510, -21455, -21399, -21343, -21288, -21232, + -21177, -21121, -21066, -21010, -20955, -20900, -20844, -20789, + -20734, -20678, -20623, -20568, -20513, -20457, -20402, -20347, + -20292, -20237, -20182, -20127, -20072, -20017, -19962, -19907, + -19852, -19797, -19742, -19688, -19633, -19578, -19523, -19469, + -19414, -19359, -19305, -19250, -19195, -19141, -19086, -19032, + -18977, -18923, -18868, -18814, -18760, -18705, -18651, -18597, + -18542, -18488, -18434, -18380, -18325, -18271, -18217, -18163, + -18109, -18055, -18001, -17946, -17892, -17838, -17784, -17731, + -17677, -17623, -17569, -17515, -17461, -17407, -17353, -17300, + -17246, -17192, -17138, -17085, -17031, -16977, -16924, -16870, + -16817, -16763, -16710, -16656, -16603, -16549, -16496, -16442, + -16389, -16335, -16282, -16229, -16175, -16122, -16069, -16015, + -15962, -15909, -15856, -15802, -15749, -15696, -15643, -15590, + -15537, -15484, -15431, -15378, -15325, -15272, -15219, -15166, + -15113, -15060, -15007, -14954, -14901, -14848, -14795, -14743, + -14690, -14637, -14584, -14531, -14479, -14426, -14373, -14321, + -14268, -14215, -14163, -14110, -14057, -14005, -13952, -13900, + -13847, -13795, -13742, -13690, -13637, -13585, -13533, -13480, + -13428, -13375, -13323, -13271, -13218, -13166, -13114, -13062, + -13009, -12957, -12905, -12853, -12800, -12748, -12696, -12644, + -12592, -12540, -12488, -12436, -12383, -12331, -12279, -12227, + -12175, -12123, -12071, -12019, -11967, -11916, -11864, -11812, + -11760, -11708, -11656, -11604, -11552, -11501, -11449, -11397, + -11345, -11293, -11242, -11190, -11138, -11086, -11035, -10983, + -10931, -10880, -10828, -10777, -10725, -10673, -10622, -10570, + -10519, -10467, -10415, -10364, -10312, -10261, -10209, -10158, + -10106, -10055, -10004, -9952, -9901, -9849, -9798, -9747, + -9695, -9644, -9592, -9541, -9490, -9438, -9387, -9336, + -9285, -9233, -9182, -9131, -9080, -9028, -8977, -8926, + -8875, -8824, -8772, -8721, -8670, -8619, -8568, -8517, + -8466, -8414, -8363, -8312, -8261, -8210, -8159, -8108, + -8057, -8006, -7955, -7904, -7853, -7802, -7751, -7700, + -7649, -7598, -7547, -7496, -7445, -7395, -7344, -7293, + -7242, -7191, -7140, -7089, -7038, -6988, -6937, -6886, + -6835, -6784, -6733, -6683, -6632, -6581, -6530, -6480, + -6429, -6378, -6327, -6277, -6226, -6175, -6124, -6074, + -6023, -5972, -5922, -5871, -5820, -5770, -5719, -5668, + -5618, -5567, -5517, -5466, -5415, -5365, -5314, -5264, + -5213, -5162, -5112, -5061, -5011, -4960, -4910, -4859, + -4808, -4758, -4707, -4657, -4606, -4556, -4505, -4455, + -4404, -4354, -4303, -4253, -4202, -4152, -4101, -4051, + -4001, -3950, -3900, -3849, -3799, -3748, -3698, -3648, + -3597, -3547, -3496, -3446, -3395, -3345, -3295, -3244, + -3194, -3144, -3093, -3043, -2992, -2942, -2892, -2841, + -2791, -2741, -2690, -2640, -2590, -2539, -2489, -2439, + -2388, -2338, -2288, -2237, -2187, -2137, -2086, -2036, + -1986, -1935, -1885, -1835, -1784, -1734, -1684, -1633, + -1583, -1533, -1483, -1432, -1382, -1332, -1281, -1231, + -1181, -1131, -1080, -1030, -980, -929, -879, -829, + -779, -728, -678, -628, -578, -527, -477, -427, + -376, -326, -276, -226, -175, -125, -75, -25, + 25, 75, 125, 175, 226, 276, 326, 376, + 427, 477, 527, 578, 628, 678, 728, 779, + 829, 879, 929, 980, 1030, 1080, 1131, 1181, + 1231, 1281, 1332, 1382, 1432, 1483, 1533, 1583, + 1633, 1684, 1734, 1784, 1835, 1885, 1935, 1986, + 2036, 2086, 2137, 2187, 2237, 2288, 2338, 2388, + 2439, 2489, 2539, 2590, 2640, 2690, 2741, 2791, + 2841, 2892, 2942, 2992, 3043, 3093, 3144, 3194, + 3244, 3295, 3345, 3395, 3446, 3496, 3547, 3597, + 3648, 3698, 3748, 3799, 3849, 3900, 3950, 4001, + 4051, 4101, 4152, 4202, 4253, 4303, 4354, 4404, + 4455, 4505, 4556, 4606, 4657, 4707, 4758, 4808, + 4859, 4910, 4960, 5011, 5061, 5112, 5162, 5213, + 5264, 5314, 5365, 5415, 5466, 5517, 5567, 5618, + 5668, 5719, 5770, 5820, 5871, 5922, 5972, 6023, + 6074, 6124, 6175, 6226, 6277, 6327, 6378, 6429, + 6480, 6530, 6581, 6632, 6683, 6733, 6784, 6835, + 6886, 6937, 6988, 7038, 7089, 7140, 7191, 7242, + 7293, 7344, 7395, 7445, 7496, 7547, 7598, 7649, + 7700, 7751, 7802, 7853, 7904, 7955, 8006, 8057, + 8108, 8159, 8210, 8261, 8312, 8363, 8414, 8466, + 8517, 8568, 8619, 8670, 8721, 8772, 8824, 8875, + 8926, 8977, 9028, 9080, 9131, 9182, 9233, 9285, + 9336, 9387, 9438, 9490, 9541, 9592, 9644, 9695, + 9747, 9798, 9849, 9901, 9952, 10004, 10055, 10106, + 10158, 10209, 10261, 10312, 10364, 10415, 10467, 10519, + 10570, 10622, 10673, 10725, 10777, 10828, 10880, 10931, + 10983, 11035, 11086, 11138, 11190, 11242, 11293, 11345, + 11397, 11449, 11501, 11552, 11604, 11656, 11708, 11760, + 11812, 11864, 11916, 11967, 12019, 12071, 12123, 12175, + 12227, 12279, 12331, 12383, 12436, 12488, 12540, 12592, + 12644, 12696, 12748, 12800, 12853, 12905, 12957, 13009, + 13062, 13114, 13166, 13218, 13271, 13323, 13375, 13428, + 13480, 13533, 13585, 13637, 13690, 13742, 13795, 13847, + 13900, 13952, 14005, 14057, 14110, 14163, 14215, 14268, + 14321, 14373, 14426, 14479, 14531, 14584, 14637, 14690, + 14743, 14795, 14848, 14901, 14954, 15007, 15060, 15113, + 15166, 15219, 15272, 15325, 15378, 15431, 15484, 15537, + 15590, 15643, 15696, 15749, 15802, 15856, 15909, 15962, + 16015, 16069, 16122, 16175, 16229, 16282, 16335, 16389, + 16442, 16496, 16549, 16603, 16656, 16710, 16763, 16817, + 16870, 16924, 16977, 17031, 17085, 17138, 17192, 17246, + 17300, 17353, 17407, 17461, 17515, 17569, 17623, 17677, + 17731, 17784, 17838, 17892, 17946, 18001, 18055, 18109, + 18163, 18217, 18271, 18325, 18380, 18434, 18488, 18542, + 18597, 18651, 18705, 18760, 18814, 18868, 18923, 18977, + 19032, 19086, 19141, 19195, 19250, 19305, 19359, 19414, + 19469, 19523, 19578, 19633, 19688, 19742, 19797, 19852, + 19907, 19962, 20017, 20072, 20127, 20182, 20237, 20292, + 20347, 20402, 20457, 20513, 20568, 20623, 20678, 20734, + 20789, 20844, 20900, 20955, 21010, 21066, 21121, 21177, + 21232, 21288, 21343, 21399, 21455, 21510, 21566, 21622, + 21678, 21733, 21789, 21845, 21901, 21957, 22013, 22069, + 22125, 22181, 22237, 22293, 22349, 22405, 22461, 22517, + 22573, 22630, 22686, 22742, 22799, 22855, 22911, 22968, + 23024, 23081, 23137, 23194, 23250, 23307, 23364, 23420, + 23477, 23534, 23591, 23647, 23704, 23761, 23818, 23875, + 23932, 23989, 24046, 24103, 24160, 24217, 24274, 24331, + 24389, 24446, 24503, 24560, 24618, 24675, 24732, 24790, + 24847, 24905, 24962, 25020, 25078, 25135, 25193, 25251, + 25308, 25366, 25424, 25482, 25540, 25598, 25656, 25714, + 25772, 25830, 25888, 25946, 26004, 26062, 26120, 26179, + 26237, 26295, 26354, 26412, 26471, 26529, 26588, 26646, + 26705, 26763, 26822, 26881, 26940, 26998, 27057, 27116, + 27175, 27234, 27293, 27352, 27411, 27470, 27529, 27588, + 27647, 27707, 27766, 27825, 27884, 27944, 28003, 28063, + 28122, 28182, 28241, 28301, 28361, 28420, 28480, 28540, + 28600, 28660, 28719, 28779, 28839, 28899, 28959, 29020, + 29080, 29140, 29200, 29260, 29321, 29381, 29441, 29502, + 29562, 29623, 29683, 29744, 29805, 29865, 29926, 29987, + 30048, 30108, 30169, 30230, 30291, 30352, 30413, 30474, + 30536, 30597, 30658, 30719, 30781, 30842, 30904, 30965, + 31026, 31088, 31150, 31211, 31273, 31335, 31396, 31458, + 31520, 31582, 31644, 31706, 31768, 31830, 31892, 31955, + 32017, 32079, 32141, 32204, 32266, 32329, 32391, 32454, + 32516, 32579, 32642, 32705, 32767, 32830, 32893, 32956, + 33019, 33082, 33145, 33208, 33272, 33335, 33398, 33461, + 33525, 33588, 33652, 33715, 33779, 33843, 33906, 33970, + 34034, 34098, 34162, 34225, 34289, 34354, 34418, 34482, + 34546, 34610, 34675, 34739, 34803, 34868, 34932, 34997, + 35062, 35126, 35191, 35256, 35321, 35385, 35450, 35515, + 35580, 35646, 35711, 35776, 35841, 35907, 35972, 36037, + 36103, 36168, 36234, 36300, 36365, 36431, 36497, 36563, + 36629, 36695, 36761, 36827, 36893, 36959, 37026, 37092, + 37158, 37225, 37291, 37358, 37425, 37491, 37558, 37625, + 37692, 37759, 37826, 37893, 37960, 38027, 38094, 38161, + 38229, 38296, 38364, 38431, 38499, 38566, 38634, 38702, + 38770, 38837, 38905, 38973, 39042, 39110, 39178, 39246, + 39314, 39383, 39451, 39520, 39588, 39657, 39726, 39794, + 39863, 39932, 40001, 40070, 40139, 40208, 40278, 40347, + 40416, 40486, 40555, 40625, 40694, 40764, 40834, 40904, + 40973, 41043, 41113, 41184, 41254, 41324, 41394, 41465, + 41535, 41605, 41676, 41747, 41817, 41888, 41959, 42030, + 42101, 42172, 42243, 42314, 42385, 42457, 42528, 42600, + 42671, 42743, 42814, 42886, 42958, 43030, 43102, 43174, + 43246, 43318, 43390, 43463, 43535, 43608, 43680, 43753, + 43826, 43898, 43971, 44044, 44117, 44190, 44263, 44337, + 44410, 44483, 44557, 44630, 44704, 44778, 44851, 44925, + 44999, 45073, 45147, 45221, 45296, 45370, 45444, 45519, + 45593, 45668, 45743, 45818, 45892, 45967, 46042, 46118, + 46193, 46268, 46343, 46419, 46494, 46570, 46646, 46721, + 46797, 46873, 46949, 47025, 47102, 47178, 47254, 47331, + 47407, 47484, 47560, 47637, 47714, 47791, 47868, 47945, + 48022, 48100, 48177, 48255, 48332, 48410, 48488, 48565, + 48643, 48721, 48799, 48878, 48956, 49034, 49113, 49191, + 49270, 49349, 49427, 49506, 49585, 49664, 49744, 49823, + 49902, 49982, 50061, 50141, 50221, 50300, 50380, 50460, + 50540, 50621, 50701, 50781, 50862, 50942, 51023, 51104, + 51185, 51266, 51347, 51428, 51509, 51591, 51672, 51754, + 51835, 51917, 51999, 52081, 52163, 52245, 52327, 52410, + 52492, 52575, 52657, 52740, 52823, 52906, 52989, 53072, + 53156, 53239, 53322, 53406, 53490, 53574, 53657, 53741, + 53826, 53910, 53994, 54079, 54163, 54248, 54333, 54417, + 54502, 54587, 54673, 54758, 54843, 54929, 55015, 55100, + 55186, 55272, 55358, 55444, 55531, 55617, 55704, 55790, + 55877, 55964, 56051, 56138, 56225, 56312, 56400, 56487, + 56575, 56663, 56751, 56839, 56927, 57015, 57104, 57192, + 57281, 57369, 57458, 57547, 57636, 57725, 57815, 57904, + 57994, 58083, 58173, 58263, 58353, 58443, 58534, 58624, + 58715, 58805, 58896, 58987, 59078, 59169, 59261, 59352, + 59444, 59535, 59627, 59719, 59811, 59903, 59996, 60088, + 60181, 60273, 60366, 60459, 60552, 60646, 60739, 60833, + 60926, 61020, 61114, 61208, 61302, 61396, 61491, 61585, + 61680, 61775, 61870, 61965, 62060, 62156, 62251, 62347, + 62443, 62539, 62635, 62731, 62828, 62924, 63021, 63118, + 63215, 63312, 63409, 63506, 63604, 63702, 63799, 63897, + 63996, 64094, 64192, 64291, 64389, 64488, 64587, 64687, + 64786, 64885, 64985, 65085, 65185, 65285, 65385, 65485, + 65586, 65686, 65787, 65888, 65989, 66091, 66192, 66294, + 66396, 66498, 66600, 66702, 66804, 66907, 67010, 67113, + 67216, 67319, 67422, 67526, 67629, 67733, 67837, 67942, + 68046, 68151, 68255, 68360, 68465, 68570, 68676, 68781, + 68887, 68993, 69099, 69205, 69312, 69418, 69525, 69632, + 69739, 69846, 69954, 70061, 70169, 70277, 70385, 70494, + 70602, 70711, 70820, 70929, 71038, 71147, 71257, 71367, + 71477, 71587, 71697, 71808, 71918, 72029, 72140, 72252, + 72363, 72475, 72587, 72699, 72811, 72923, 73036, 73149, + 73262, 73375, 73488, 73602, 73715, 73829, 73944, 74058, + 74172, 74287, 74402, 74517, 74633, 74748, 74864, 74980, + 75096, 75213, 75329, 75446, 75563, 75680, 75797, 75915, + 76033, 76151, 76269, 76388, 76506, 76625, 76744, 76864, + 76983, 77103, 77223, 77343, 77463, 77584, 77705, 77826, + 77947, 78068, 78190, 78312, 78434, 78557, 78679, 78802, + 78925, 79048, 79172, 79296, 79420, 79544, 79668, 79793, + 79918, 80043, 80168, 80294, 80420, 80546, 80672, 80799, + 80925, 81053, 81180, 81307, 81435, 81563, 81691, 81820, + 81949, 82078, 82207, 82336, 82466, 82596, 82726, 82857, + 82987, 83118, 83250, 83381, 83513, 83645, 83777, 83910, + 84043, 84176, 84309, 84443, 84576, 84710, 84845, 84980, + 85114, 85250, 85385, 85521, 85657, 85793, 85930, 86066, + 86204, 86341, 86479, 86616, 86755, 86893, 87032, 87171, + 87310, 87450, 87590, 87730, 87871, 88011, 88152, 88294, + 88435, 88577, 88720, 88862, 89005, 89148, 89292, 89435, + 89579, 89724, 89868, 90013, 90158, 90304, 90450, 90596, + 90742, 90889, 91036, 91184, 91332, 91480, 91628, 91777, + 91926, 92075, 92225, 92375, 92525, 92675, 92826, 92978, + 93129, 93281, 93434, 93586, 93739, 93892, 94046, 94200, + 94354, 94509, 94664, 94819, 94975, 95131, 95287, 95444, + 95601, 95758, 95916, 96074, 96233, 96391, 96551, 96710, + 96870, 97030, 97191, 97352, 97513, 97675, 97837, 98000, + 98163, 98326, 98489, 98653, 98818, 98982, 99148, 99313, + 99479, 99645, 99812, 99979, 100146, 100314, 100482, 100651, + 100820, 100990, 101159, 101330, 101500, 101671, 101843, 102015, + 102187, 102360, 102533, 102706, 102880, 103054, 103229, 103404, + 103580, 103756, 103933, 104109, 104287, 104465, 104643, 104821, + 105000, 105180, 105360, 105540, 105721, 105902, 106084, 106266, + 106449, 106632, 106816, 107000, 107184, 107369, 107555, 107741, + 107927, 108114, 108301, 108489, 108677, 108866, 109055, 109245, + 109435, 109626, 109817, 110008, 110200, 110393, 110586, 110780, + 110974, 111169, 111364, 111560, 111756, 111952, 112150, 112347, + 112546, 112744, 112944, 113143, 113344, 113545, 113746, 113948, + 114151, 114354, 114557, 114761, 114966, 115171, 115377, 115583, + 115790, 115998, 116206, 116414, 116623, 116833, 117044, 117254, + 117466, 117678, 117891, 118104, 118318, 118532, 118747, 118963, + 119179, 119396, 119613, 119831, 120050, 120269, 120489, 120709, + 120930, 121152, 121374, 121597, 121821, 122045, 122270, 122496, + 122722, 122949, 123176, 123404, 123633, 123863, 124093, 124324, + 124555, 124787, 125020, 125254, 125488, 125723, 125959, 126195, + 126432, 126669, 126908, 127147, 127387, 127627, 127869, 128111, + 128353, 128597, 128841, 129086, 129332, 129578, 129825, 130073, + 130322, 130571, 130821, 131072, 131324, 131576, 131830, 132084, + 132339, 132594, 132851, 133108, 133366, 133625, 133884, 134145, + 134406, 134668, 134931, 135195, 135459, 135725, 135991, 136258, + 136526, 136795, 137065, 137335, 137607, 137879, 138152, 138426, + 138701, 138977, 139254, 139532, 139810, 140090, 140370, 140651, + 140934, 141217, 141501, 141786, 142072, 142359, 142647, 142936, + 143226, 143517, 143808, 144101, 144395, 144690, 144986, 145282, + 145580, 145879, 146179, 146480, 146782, 147084, 147388, 147693, + 148000, 148307, 148615, 148924, 149235, 149546, 149859, 150172, + 150487, 150803, 151120, 151438, 151757, 152077, 152399, 152722, + 153045, 153370, 153697, 154024, 154352, 154682, 155013, 155345, + 155678, 156013, 156349, 156686, 157024, 157363, 157704, 158046, + 158389, 158734, 159079, 159427, 159775, 160125, 160476, 160828, + 161182, 161537, 161893, 162251, 162610, 162970, 163332, 163695, + 164060, 164426, 164793, 165162, 165532, 165904, 166277, 166651, + 167027, 167405, 167784, 168164, 168546, 168930, 169315, 169701, + 170089, 170479, 170870, 171263, 171657, 172053, 172451, 172850, + 173251, 173653, 174057, 174463, 174870, 175279, 175690, 176102, + 176516, 176932, 177349, 177769, 178190, 178612, 179037, 179463, + 179891, 180321, 180753, 181186, 181622, 182059, 182498, 182939, + 183382, 183827, 184274, 184722, 185173, 185625, 186080, 186536, + 186995, 187455, 187918, 188382, 188849, 189318, 189789, 190261, + 190736, 191213, 191693, 192174, 192658, 193143, 193631, 194122, + 194614, 195109, 195606, 196105, 196606, 197110, 197616, 198125, + 198636, 199149, 199664, 200182, 200703, 201226, 201751, 202279, + 202809, 203342, 203878, 204416, 204956, 205500, 206045, 206594, + 207145, 207699, 208255, 208815, 209376, 209941, 210509, 211079, + 211652, 212228, 212807, 213389, 213973, 214561, 215151, 215745, + 216341, 216941, 217544, 218149, 218758, 219370, 219985, 220603, + 221225, 221849, 222477, 223108, 223743, 224381, 225022, 225666, + 226314, 226966, 227621, 228279, 228941, 229606, 230275, 230948, + 231624, 232304, 232988, 233676, 234367, 235062, 235761, 236463, + 237170, 237881, 238595, 239314, 240036, 240763, 241493, 242228, + 242967, 243711, 244458, 245210, 245966, 246727, 247492, 248261, + 249035, 249813, 250596, 251384, 252176, 252973, 253774, 254581, + 255392, 256208, 257029, 257855, 258686, 259522, 260363, 261209, + 262060, 262917, 263779, 264646, 265519, 266397, 267280, 268169, + 269064, 269965, 270871, 271782, 272700, 273624, 274553, 275489, + 276430, 277378, 278332, 279292, 280258, 281231, 282210, 283195, + 284188, 285186, 286192, 287204, 288223, 289249, 290282, 291322, + 292369, 293423, 294485, 295554, 296630, 297714, 298805, 299904, + 301011, 302126, 303248, 304379, 305517, 306664, 307819, 308983, + 310154, 311335, 312524, 313721, 314928, 316143, 317368, 318601, + 319844, 321097, 322358, 323629, 324910, 326201, 327502, 328812, + 330133, 331464, 332805, 334157, 335519, 336892, 338276, 339671, + 341078, 342495, 343924, 345364, 346816, 348280, 349756, 351244, + 352744, 354257, 355783, 357321, 358872, 360436, 362013, 363604, + 365208, 366826, 368459, 370105, 371765, 373440, 375130, 376835, + 378555, 380290, 382040, 383807, 385589, 387387, 389202, 391034, + 392882, 394747, 396630, 398530, 400448, 402384, 404338, 406311, + 408303, 410314, 412344, 414395, 416465, 418555, 420666, 422798, + 424951, 427125, 429321, 431540, 433781, 436045, 438332, 440643, + 442978, 445337, 447720, 450129, 452564, 455024, 457511, 460024, + 462565, 465133, 467730, 470355, 473009, 475692, 478406, 481150, + 483925, 486732, 489571, 492443, 495348, 498287, 501261, 504269, + 507313, 510394, 513512, 516667, 519861, 523094, 526366, 529680, + 533034, 536431, 539870, 543354, 546881, 550455, 554074, 557741, + 561456, 565221, 569035, 572901, 576818, 580789, 584815, 588896, + 593033, 597229, 601483, 605798, 610174, 614613, 619117, 623686, + 628323, 633028, 637803, 642651, 647572, 652568, 657640, 662792, + 668024, 673338, 678737, 684223, 689797, 695462, 701219, 707072, + 713023, 719074, 725227, 731486, 737853, 744331, 750922, 757631, + 764460, 771411, 778490, 785699, 793041, 800521, 808143, 815910, + 823827, 831898, 840127, 848520, 857081, 865817, 874730, 883829, + 893117, 902602, 912289, 922186, 932298, 942633, 953199, 964003, + 975054, 986361, 997931, 1009774, 1021901, 1034322, 1047046, 1060087, + 1073455, 1087164, 1101225, 1115654, 1130465, 1145673, 1161294, 1177345, + 1193846, 1210813, 1228269, 1246234, 1264730, 1283783, 1303416, 1323658, + 1344537, 1366084, 1388330, 1411312, 1435065, 1459630, 1485049, 1511367, + 1538632, 1566898, 1596220, 1626658, 1658278, 1691149, 1725348, 1760956, + 1798063, 1836758, 1877161, 1919378, 1963536, 2009771, 2058233, 2109087, + 2162516, 2218719, 2277919, 2340362, 2406322, 2476104, 2550052, 2628549, + 2712030, 2800983, 2895966, 2997613, 3106651, 3223918, 3350381, 3487165, + 3635590, 3797206, 3973855, 4167737, 4381502, 4618375, 4882318, 5178251, + 5512368, 5892567, 6329090, 6835455, 7429880, 8137527, 8994149, 10052327, + 11392683, 13145455, 15535599, 18988036, 24413316, 34178904, 56965752, 170910304}; const fixed_t finesine[10240] = -{ - 25,75,125,175,226,276,326,376, - 427,477,527,578,628,678,728,779, - 829,879,929,980,1030,1080,1130,1181, - 1231,1281,1331,1382,1432,1482,1532,1583, - 1633,1683,1733,1784,1834,1884,1934,1985, - 2035,2085,2135,2186,2236,2286,2336,2387, - 2437,2487,2537,2587,2638,2688,2738,2788, - 2839,2889,2939,2989,3039,3090,3140,3190, - 3240,3291,3341,3391,3441,3491,3541,3592, - 3642,3692,3742,3792,3843,3893,3943,3993, - 4043,4093,4144,4194,4244,4294,4344,4394, - 4445,4495,4545,4595,4645,4695,4745,4796, - 4846,4896,4946,4996,5046,5096,5146,5197, - 5247,5297,5347,5397,5447,5497,5547,5597, - 5647,5697,5748,5798,5848,5898,5948,5998, - 6048,6098,6148,6198,6248,6298,6348,6398, - 6448,6498,6548,6598,6648,6698,6748,6798, - 6848,6898,6948,6998,7048,7098,7148,7198, - 7248,7298,7348,7398,7448,7498,7548,7598, - 7648,7697,7747,7797,7847,7897,7947,7997, - 8047,8097,8147,8196,8246,8296,8346,8396, - 8446,8496,8545,8595,8645,8695,8745,8794, - 8844,8894,8944,8994,9043,9093,9143,9193, - 9243,9292,9342,9392,9442,9491,9541,9591, - 9640,9690,9740,9790,9839,9889,9939,9988, - 10038,10088,10137,10187,10237,10286,10336,10386, - 10435,10485,10534,10584,10634,10683,10733,10782, - 10832,10882,10931,10981,11030,11080,11129,11179, - 11228,11278,11327,11377,11426,11476,11525,11575, - 11624,11674,11723,11773,11822,11872,11921,11970, - 12020,12069,12119,12168,12218,12267,12316,12366, - 12415,12464,12514,12563,12612,12662,12711,12760, - 12810,12859,12908,12957,13007,13056,13105,13154, - 13204,13253,13302,13351,13401,13450,13499,13548, - 13597,13647,13696,13745,13794,13843,13892,13941, - 13990,14040,14089,14138,14187,14236,14285,14334, - 14383,14432,14481,14530,14579,14628,14677,14726, - 14775,14824,14873,14922,14971,15020,15069,15118, - 15167,15215,15264,15313,15362,15411,15460,15509, - 15557,15606,15655,15704,15753,15802,15850,15899, - 15948,15997,16045,16094,16143,16191,16240,16289, - 16338,16386,16435,16484,16532,16581,16629,16678, - 16727,16775,16824,16872,16921,16970,17018,17067, - 17115,17164,17212,17261,17309,17358,17406,17455, - 17503,17551,17600,17648,17697,17745,17793,17842, - 17890,17939,17987,18035,18084,18132,18180,18228, - 18277,18325,18373,18421,18470,18518,18566,18614, - 18663,18711,18759,18807,18855,18903,18951,19000, - 19048,19096,19144,19192,19240,19288,19336,19384, - 19432,19480,19528,19576,19624,19672,19720,19768, - 19816,19864,19912,19959,20007,20055,20103,20151, - 20199,20246,20294,20342,20390,20438,20485,20533, - 20581,20629,20676,20724,20772,20819,20867,20915, - 20962,21010,21057,21105,21153,21200,21248,21295, - 21343,21390,21438,21485,21533,21580,21628,21675, - 21723,21770,21817,21865,21912,21960,22007,22054, - 22102,22149,22196,22243,22291,22338,22385,22433, - 22480,22527,22574,22621,22668,22716,22763,22810, - 22857,22904,22951,22998,23045,23092,23139,23186, - 23233,23280,23327,23374,23421,23468,23515,23562, - 23609,23656,23703,23750,23796,23843,23890,23937, - 23984,24030,24077,24124,24171,24217,24264,24311, - 24357,24404,24451,24497,24544,24591,24637,24684, - 24730,24777,24823,24870,24916,24963,25009,25056, - 25102,25149,25195,25241,25288,25334,25381,25427, - 25473,25520,25566,25612,25658,25705,25751,25797, - 25843,25889,25936,25982,26028,26074,26120,26166, - 26212,26258,26304,26350,26396,26442,26488,26534, - 26580,26626,26672,26718,26764,26810,26856,26902, - 26947,26993,27039,27085,27131,27176,27222,27268, - 27313,27359,27405,27450,27496,27542,27587,27633, - 27678,27724,27770,27815,27861,27906,27952,27997, - 28042,28088,28133,28179,28224,28269,28315,28360, - 28405,28451,28496,28541,28586,28632,28677,28722, - 28767,28812,28858,28903,28948,28993,29038,29083, - 29128,29173,29218,29263,29308,29353,29398,29443, - 29488,29533,29577,29622,29667,29712,29757,29801, - 29846,29891,29936,29980,30025,30070,30114,30159, - 30204,30248,30293,30337,30382,30426,30471,30515, - 30560,30604,30649,30693,30738,30782,30826,30871, - 30915,30959,31004,31048,31092,31136,31181,31225, - 31269,31313,31357,31402,31446,31490,31534,31578, - 31622,31666,31710,31754,31798,31842,31886,31930, - 31974,32017,32061,32105,32149,32193,32236,32280, - 32324,32368,32411,32455,32499,32542,32586,32630, - 32673,32717,32760,32804,32847,32891,32934,32978, - 33021,33065,33108,33151,33195,33238,33281,33325, - 33368,33411,33454,33498,33541,33584,33627,33670, - 33713,33756,33799,33843,33886,33929,33972,34015, - 34057,34100,34143,34186,34229,34272,34315,34358, - 34400,34443,34486,34529,34571,34614,34657,34699, - 34742,34785,34827,34870,34912,34955,34997,35040, - 35082,35125,35167,35210,35252,35294,35337,35379, - 35421,35464,35506,35548,35590,35633,35675,35717, - 35759,35801,35843,35885,35927,35969,36011,36053, - 36095,36137,36179,36221,36263,36305,36347,36388, - 36430,36472,36514,36555,36597,36639,36681,36722, - 36764,36805,36847,36889,36930,36972,37013,37055, - 37096,37137,37179,37220,37262,37303,37344,37386, - 37427,37468,37509,37551,37592,37633,37674,37715, - 37756,37797,37838,37879,37920,37961,38002,38043, - 38084,38125,38166,38207,38248,38288,38329,38370, - 38411,38451,38492,38533,38573,38614,38655,38695, - 38736,38776,38817,38857,38898,38938,38979,39019, - 39059,39100,39140,39180,39221,39261,39301,39341, - 39382,39422,39462,39502,39542,39582,39622,39662, - 39702,39742,39782,39822,39862,39902,39942,39982, - 40021,40061,40101,40141,40180,40220,40260,40300, - 40339,40379,40418,40458,40497,40537,40576,40616, - 40655,40695,40734,40773,40813,40852,40891,40931, - 40970,41009,41048,41087,41127,41166,41205,41244, - 41283,41322,41361,41400,41439,41478,41517,41556, - 41595,41633,41672,41711,41750,41788,41827,41866, - 41904,41943,41982,42020,42059,42097,42136,42174, - 42213,42251,42290,42328,42366,42405,42443,42481, - 42520,42558,42596,42634,42672,42711,42749,42787, - 42825,42863,42901,42939,42977,43015,43053,43091, - 43128,43166,43204,43242,43280,43317,43355,43393, - 43430,43468,43506,43543,43581,43618,43656,43693, - 43731,43768,43806,43843,43880,43918,43955,43992, - 44029,44067,44104,44141,44178,44215,44252,44289, - 44326,44363,44400,44437,44474,44511,44548,44585, - 44622,44659,44695,44732,44769,44806,44842,44879, - 44915,44952,44989,45025,45062,45098,45135,45171, - 45207,45244,45280,45316,45353,45389,45425,45462, - 45498,45534,45570,45606,45642,45678,45714,45750, - 45786,45822,45858,45894,45930,45966,46002,46037, - 46073,46109,46145,46180,46216,46252,46287,46323, - 46358,46394,46429,46465,46500,46536,46571,46606, - 46642,46677,46712,46747,46783,46818,46853,46888, - 46923,46958,46993,47028,47063,47098,47133,47168, - 47203,47238,47273,47308,47342,47377,47412,47446, - 47481,47516,47550,47585,47619,47654,47688,47723, - 47757,47792,47826,47860,47895,47929,47963,47998, - 48032,48066,48100,48134,48168,48202,48237,48271, - 48305,48338,48372,48406,48440,48474,48508,48542, - 48575,48609,48643,48676,48710,48744,48777,48811, - 48844,48878,48911,48945,48978,49012,49045,49078, - 49112,49145,49178,49211,49244,49278,49311,49344, - 49377,49410,49443,49476,49509,49542,49575,49608, - 49640,49673,49706,49739,49771,49804,49837,49869, - 49902,49935,49967,50000,50032,50065,50097,50129, - 50162,50194,50226,50259,50291,50323,50355,50387, - 50420,50452,50484,50516,50548,50580,50612,50644, - 50675,50707,50739,50771,50803,50834,50866,50898, - 50929,50961,50993,51024,51056,51087,51119,51150, - 51182,51213,51244,51276,51307,51338,51369,51401, - 51432,51463,51494,51525,51556,51587,51618,51649, - 51680,51711,51742,51773,51803,51834,51865,51896, - 51926,51957,51988,52018,52049,52079,52110,52140, - 52171,52201,52231,52262,52292,52322,52353,52383, - 52413,52443,52473,52503,52534,52564,52594,52624, - 52653,52683,52713,52743,52773,52803,52832,52862, - 52892,52922,52951,52981,53010,53040,53069,53099, - 53128,53158,53187,53216,53246,53275,53304,53334, - 53363,53392,53421,53450,53479,53508,53537,53566, - 53595,53624,53653,53682,53711,53739,53768,53797, - 53826,53854,53883,53911,53940,53969,53997,54026, - 54054,54082,54111,54139,54167,54196,54224,54252, - 54280,54308,54337,54365,54393,54421,54449,54477, - 54505,54533,54560,54588,54616,54644,54672,54699, - 54727,54755,54782,54810,54837,54865,54892,54920, - 54947,54974,55002,55029,55056,55084,55111,55138, - 55165,55192,55219,55246,55274,55300,55327,55354, - 55381,55408,55435,55462,55489,55515,55542,55569, - 55595,55622,55648,55675,55701,55728,55754,55781, - 55807,55833,55860,55886,55912,55938,55965,55991, - 56017,56043,56069,56095,56121,56147,56173,56199, - 56225,56250,56276,56302,56328,56353,56379,56404, - 56430,56456,56481,56507,56532,56557,56583,56608, - 56633,56659,56684,56709,56734,56760,56785,56810, - 56835,56860,56885,56910,56935,56959,56984,57009, - 57034,57059,57083,57108,57133,57157,57182,57206, - 57231,57255,57280,57304,57329,57353,57377,57402, - 57426,57450,57474,57498,57522,57546,57570,57594, - 57618,57642,57666,57690,57714,57738,57762,57785, - 57809,57833,57856,57880,57903,57927,57950,57974, - 57997,58021,58044,58067,58091,58114,58137,58160, - 58183,58207,58230,58253,58276,58299,58322,58345, - 58367,58390,58413,58436,58459,58481,58504,58527, - 58549,58572,58594,58617,58639,58662,58684,58706, - 58729,58751,58773,58795,58818,58840,58862,58884, - 58906,58928,58950,58972,58994,59016,59038,59059, - 59081,59103,59125,59146,59168,59190,59211,59233, - 59254,59276,59297,59318,59340,59361,59382,59404, - 59425,59446,59467,59488,59509,59530,59551,59572, - 59593,59614,59635,59656,59677,59697,59718,59739, - 59759,59780,59801,59821,59842,59862,59883,59903, - 59923,59944,59964,59984,60004,60025,60045,60065, - 60085,60105,60125,60145,60165,60185,60205,60225, - 60244,60264,60284,60304,60323,60343,60363,60382, - 60402,60421,60441,60460,60479,60499,60518,60537, - 60556,60576,60595,60614,60633,60652,60671,60690, - 60709,60728,60747,60766,60785,60803,60822,60841, - 60859,60878,60897,60915,60934,60952,60971,60989, - 61007,61026,61044,61062,61081,61099,61117,61135, - 61153,61171,61189,61207,61225,61243,61261,61279, - 61297,61314,61332,61350,61367,61385,61403,61420, - 61438,61455,61473,61490,61507,61525,61542,61559, - 61577,61594,61611,61628,61645,61662,61679,61696, - 61713,61730,61747,61764,61780,61797,61814,61831, - 61847,61864,61880,61897,61913,61930,61946,61963, - 61979,61995,62012,62028,62044,62060,62076,62092, - 62108,62125,62141,62156,62172,62188,62204,62220, - 62236,62251,62267,62283,62298,62314,62329,62345, - 62360,62376,62391,62407,62422,62437,62453,62468, - 62483,62498,62513,62528,62543,62558,62573,62588, - 62603,62618,62633,62648,62662,62677,62692,62706, - 62721,62735,62750,62764,62779,62793,62808,62822, - 62836,62850,62865,62879,62893,62907,62921,62935, - 62949,62963,62977,62991,63005,63019,63032,63046, - 63060,63074,63087,63101,63114,63128,63141,63155, - 63168,63182,63195,63208,63221,63235,63248,63261, - 63274,63287,63300,63313,63326,63339,63352,63365, - 63378,63390,63403,63416,63429,63441,63454,63466, - 63479,63491,63504,63516,63528,63541,63553,63565, - 63578,63590,63602,63614,63626,63638,63650,63662, - 63674,63686,63698,63709,63721,63733,63745,63756, - 63768,63779,63791,63803,63814,63825,63837,63848, - 63859,63871,63882,63893,63904,63915,63927,63938, - 63949,63960,63971,63981,63992,64003,64014,64025, - 64035,64046,64057,64067,64078,64088,64099,64109, - 64120,64130,64140,64151,64161,64171,64181,64192, - 64202,64212,64222,64232,64242,64252,64261,64271, - 64281,64291,64301,64310,64320,64330,64339,64349, - 64358,64368,64377,64387,64396,64405,64414,64424, - 64433,64442,64451,64460,64469,64478,64487,64496, - 64505,64514,64523,64532,64540,64549,64558,64566, - 64575,64584,64592,64601,64609,64617,64626,64634, - 64642,64651,64659,64667,64675,64683,64691,64699, - 64707,64715,64723,64731,64739,64747,64754,64762, - 64770,64777,64785,64793,64800,64808,64815,64822, - 64830,64837,64844,64852,64859,64866,64873,64880, - 64887,64895,64902,64908,64915,64922,64929,64936, - 64943,64949,64956,64963,64969,64976,64982,64989, - 64995,65002,65008,65015,65021,65027,65033,65040, - 65046,65052,65058,65064,65070,65076,65082,65088, - 65094,65099,65105,65111,65117,65122,65128,65133, - 65139,65144,65150,65155,65161,65166,65171,65177, - 65182,65187,65192,65197,65202,65207,65212,65217, - 65222,65227,65232,65237,65242,65246,65251,65256, - 65260,65265,65270,65274,65279,65283,65287,65292, - 65296,65300,65305,65309,65313,65317,65321,65325, - 65329,65333,65337,65341,65345,65349,65352,65356, - 65360,65363,65367,65371,65374,65378,65381,65385, - 65388,65391,65395,65398,65401,65404,65408,65411, - 65414,65417,65420,65423,65426,65429,65431,65434, - 65437,65440,65442,65445,65448,65450,65453,65455, - 65458,65460,65463,65465,65467,65470,65472,65474, - 65476,65478,65480,65482,65484,65486,65488,65490, - 65492,65494,65496,65497,65499,65501,65502,65504, - 65505,65507,65508,65510,65511,65513,65514,65515, - 65516,65518,65519,65520,65521,65522,65523,65524, - 65525,65526,65527,65527,65528,65529,65530,65530, - 65531,65531,65532,65532,65533,65533,65534,65534, - 65534,65535,65535,65535,65535,65535,65535,65535, - 65535,65535,65535,65535,65535,65535,65535,65534, - 65534,65534,65533,65533,65532,65532,65531,65531, - 65530,65530,65529,65528,65527,65527,65526,65525, - 65524,65523,65522,65521,65520,65519,65518,65516, - 65515,65514,65513,65511,65510,65508,65507,65505, - 65504,65502,65501,65499,65497,65496,65494,65492, - 65490,65488,65486,65484,65482,65480,65478,65476, - 65474,65472,65470,65467,65465,65463,65460,65458, - 65455,65453,65450,65448,65445,65442,65440,65437, - 65434,65431,65429,65426,65423,65420,65417,65414, - 65411,65408,65404,65401,65398,65395,65391,65388, - 65385,65381,65378,65374,65371,65367,65363,65360, - 65356,65352,65349,65345,65341,65337,65333,65329, - 65325,65321,65317,65313,65309,65305,65300,65296, - 65292,65287,65283,65279,65274,65270,65265,65260, - 65256,65251,65246,65242,65237,65232,65227,65222, - 65217,65212,65207,65202,65197,65192,65187,65182, - 65177,65171,65166,65161,65155,65150,65144,65139, - 65133,65128,65122,65117,65111,65105,65099,65094, - 65088,65082,65076,65070,65064,65058,65052,65046, - 65040,65033,65027,65021,65015,65008,65002,64995, - 64989,64982,64976,64969,64963,64956,64949,64943, - 64936,64929,64922,64915,64908,64902,64895,64887, - 64880,64873,64866,64859,64852,64844,64837,64830, - 64822,64815,64808,64800,64793,64785,64777,64770, - 64762,64754,64747,64739,64731,64723,64715,64707, - 64699,64691,64683,64675,64667,64659,64651,64642, - 64634,64626,64617,64609,64600,64592,64584,64575, - 64566,64558,64549,64540,64532,64523,64514,64505, - 64496,64487,64478,64469,64460,64451,64442,64433, - 64424,64414,64405,64396,64387,64377,64368,64358, - 64349,64339,64330,64320,64310,64301,64291,64281, - 64271,64261,64252,64242,64232,64222,64212,64202, - 64192,64181,64171,64161,64151,64140,64130,64120, - 64109,64099,64088,64078,64067,64057,64046,64035, - 64025,64014,64003,63992,63981,63971,63960,63949, - 63938,63927,63915,63904,63893,63882,63871,63859, - 63848,63837,63825,63814,63803,63791,63779,63768, - 63756,63745,63733,63721,63709,63698,63686,63674, - 63662,63650,63638,63626,63614,63602,63590,63578, - 63565,63553,63541,63528,63516,63504,63491,63479, - 63466,63454,63441,63429,63416,63403,63390,63378, - 63365,63352,63339,63326,63313,63300,63287,63274, - 63261,63248,63235,63221,63208,63195,63182,63168, - 63155,63141,63128,63114,63101,63087,63074,63060, - 63046,63032,63019,63005,62991,62977,62963,62949, - 62935,62921,62907,62893,62879,62865,62850,62836, - 62822,62808,62793,62779,62764,62750,62735,62721, - 62706,62692,62677,62662,62648,62633,62618,62603, - 62588,62573,62558,62543,62528,62513,62498,62483, - 62468,62453,62437,62422,62407,62391,62376,62360, - 62345,62329,62314,62298,62283,62267,62251,62236, - 62220,62204,62188,62172,62156,62141,62125,62108, - 62092,62076,62060,62044,62028,62012,61995,61979, - 61963,61946,61930,61913,61897,61880,61864,61847, - 61831,61814,61797,61780,61764,61747,61730,61713, - 61696,61679,61662,61645,61628,61611,61594,61577, - 61559,61542,61525,61507,61490,61473,61455,61438, - 61420,61403,61385,61367,61350,61332,61314,61297, - 61279,61261,61243,61225,61207,61189,61171,61153, - 61135,61117,61099,61081,61062,61044,61026,61007, - 60989,60971,60952,60934,60915,60897,60878,60859, - 60841,60822,60803,60785,60766,60747,60728,60709, - 60690,60671,60652,60633,60614,60595,60576,60556, - 60537,60518,60499,60479,60460,60441,60421,60402, - 60382,60363,60343,60323,60304,60284,60264,60244, - 60225,60205,60185,60165,60145,60125,60105,60085, - 60065,60045,60025,60004,59984,59964,59944,59923, - 59903,59883,59862,59842,59821,59801,59780,59759, - 59739,59718,59697,59677,59656,59635,59614,59593, - 59572,59551,59530,59509,59488,59467,59446,59425, - 59404,59382,59361,59340,59318,59297,59276,59254, - 59233,59211,59190,59168,59146,59125,59103,59081, - 59059,59038,59016,58994,58972,58950,58928,58906, - 58884,58862,58840,58818,58795,58773,58751,58729, - 58706,58684,58662,58639,58617,58594,58572,58549, - 58527,58504,58481,58459,58436,58413,58390,58367, - 58345,58322,58299,58276,58253,58230,58207,58183, - 58160,58137,58114,58091,58067,58044,58021,57997, - 57974,57950,57927,57903,57880,57856,57833,57809, - 57785,57762,57738,57714,57690,57666,57642,57618, - 57594,57570,57546,57522,57498,57474,57450,57426, - 57402,57377,57353,57329,57304,57280,57255,57231, - 57206,57182,57157,57133,57108,57083,57059,57034, - 57009,56984,56959,56935,56910,56885,56860,56835, - 56810,56785,56760,56734,56709,56684,56659,56633, - 56608,56583,56557,56532,56507,56481,56456,56430, - 56404,56379,56353,56328,56302,56276,56250,56225, - 56199,56173,56147,56121,56095,56069,56043,56017, - 55991,55965,55938,55912,55886,55860,55833,55807, - 55781,55754,55728,55701,55675,55648,55622,55595, - 55569,55542,55515,55489,55462,55435,55408,55381, - 55354,55327,55300,55274,55246,55219,55192,55165, - 55138,55111,55084,55056,55029,55002,54974,54947, - 54920,54892,54865,54837,54810,54782,54755,54727, - 54699,54672,54644,54616,54588,54560,54533,54505, - 54477,54449,54421,54393,54365,54337,54308,54280, - 54252,54224,54196,54167,54139,54111,54082,54054, - 54026,53997,53969,53940,53911,53883,53854,53826, - 53797,53768,53739,53711,53682,53653,53624,53595, - 53566,53537,53508,53479,53450,53421,53392,53363, - 53334,53304,53275,53246,53216,53187,53158,53128, - 53099,53069,53040,53010,52981,52951,52922,52892, - 52862,52832,52803,52773,52743,52713,52683,52653, - 52624,52594,52564,52534,52503,52473,52443,52413, - 52383,52353,52322,52292,52262,52231,52201,52171, - 52140,52110,52079,52049,52018,51988,51957,51926, - 51896,51865,51834,51803,51773,51742,51711,51680, - 51649,51618,51587,51556,51525,51494,51463,51432, - 51401,51369,51338,51307,51276,51244,51213,51182, - 51150,51119,51087,51056,51024,50993,50961,50929, - 50898,50866,50834,50803,50771,50739,50707,50675, - 50644,50612,50580,50548,50516,50484,50452,50420, - 50387,50355,50323,50291,50259,50226,50194,50162, - 50129,50097,50065,50032,50000,49967,49935,49902, - 49869,49837,49804,49771,49739,49706,49673,49640, - 49608,49575,49542,49509,49476,49443,49410,49377, - 49344,49311,49278,49244,49211,49178,49145,49112, - 49078,49045,49012,48978,48945,48911,48878,48844, - 48811,48777,48744,48710,48676,48643,48609,48575, - 48542,48508,48474,48440,48406,48372,48338,48304, - 48271,48237,48202,48168,48134,48100,48066,48032, - 47998,47963,47929,47895,47860,47826,47792,47757, - 47723,47688,47654,47619,47585,47550,47516,47481, - 47446,47412,47377,47342,47308,47273,47238,47203, - 47168,47133,47098,47063,47028,46993,46958,46923, - 46888,46853,46818,46783,46747,46712,46677,46642, - 46606,46571,46536,46500,46465,46429,46394,46358, - 46323,46287,46252,46216,46180,46145,46109,46073, - 46037,46002,45966,45930,45894,45858,45822,45786, - 45750,45714,45678,45642,45606,45570,45534,45498, - 45462,45425,45389,45353,45316,45280,45244,45207, - 45171,45135,45098,45062,45025,44989,44952,44915, - 44879,44842,44806,44769,44732,44695,44659,44622, - 44585,44548,44511,44474,44437,44400,44363,44326, - 44289,44252,44215,44178,44141,44104,44067,44029, - 43992,43955,43918,43880,43843,43806,43768,43731, - 43693,43656,43618,43581,43543,43506,43468,43430, - 43393,43355,43317,43280,43242,43204,43166,43128, - 43091,43053,43015,42977,42939,42901,42863,42825, - 42787,42749,42711,42672,42634,42596,42558,42520, - 42481,42443,42405,42366,42328,42290,42251,42213, - 42174,42136,42097,42059,42020,41982,41943,41904, - 41866,41827,41788,41750,41711,41672,41633,41595, - 41556,41517,41478,41439,41400,41361,41322,41283, - 41244,41205,41166,41127,41088,41048,41009,40970, - 40931,40891,40852,40813,40773,40734,40695,40655, - 40616,40576,40537,40497,40458,40418,40379,40339, - 40300,40260,40220,40180,40141,40101,40061,40021, - 39982,39942,39902,39862,39822,39782,39742,39702, - 39662,39622,39582,39542,39502,39462,39422,39382, - 39341,39301,39261,39221,39180,39140,39100,39059, - 39019,38979,38938,38898,38857,38817,38776,38736, - 38695,38655,38614,38573,38533,38492,38451,38411, - 38370,38329,38288,38248,38207,38166,38125,38084, - 38043,38002,37961,37920,37879,37838,37797,37756, - 37715,37674,37633,37592,37551,37509,37468,37427, - 37386,37344,37303,37262,37220,37179,37137,37096, - 37055,37013,36972,36930,36889,36847,36805,36764, - 36722,36681,36639,36597,36556,36514,36472,36430, - 36388,36347,36305,36263,36221,36179,36137,36095, - 36053,36011,35969,35927,35885,35843,35801,35759, - 35717,35675,35633,35590,35548,35506,35464,35421, - 35379,35337,35294,35252,35210,35167,35125,35082, - 35040,34997,34955,34912,34870,34827,34785,34742, - 34699,34657,34614,34571,34529,34486,34443,34400, - 34358,34315,34272,34229,34186,34143,34100,34057, - 34015,33972,33929,33886,33843,33799,33756,33713, - 33670,33627,33584,33541,33498,33454,33411,33368, - 33325,33281,33238,33195,33151,33108,33065,33021, - 32978,32934,32891,32847,32804,32760,32717,32673, - 32630,32586,32542,32499,32455,32411,32368,32324, - 32280,32236,32193,32149,32105,32061,32017,31974, - 31930,31886,31842,31798,31754,31710,31666,31622, - 31578,31534,31490,31446,31402,31357,31313,31269, - 31225,31181,31136,31092,31048,31004,30959,30915, - 30871,30826,30782,30738,30693,30649,30604,30560, - 30515,30471,30426,30382,30337,30293,30248,30204, - 30159,30114,30070,30025,29980,29936,29891,29846, - 29801,29757,29712,29667,29622,29577,29533,29488, - 29443,29398,29353,29308,29263,29218,29173,29128, - 29083,29038,28993,28948,28903,28858,28812,28767, - 28722,28677,28632,28586,28541,28496,28451,28405, - 28360,28315,28269,28224,28179,28133,28088,28042, - 27997,27952,27906,27861,27815,27770,27724,27678, - 27633,27587,27542,27496,27450,27405,27359,27313, - 27268,27222,27176,27131,27085,27039,26993,26947, - 26902,26856,26810,26764,26718,26672,26626,26580, - 26534,26488,26442,26396,26350,26304,26258,26212, - 26166,26120,26074,26028,25982,25936,25889,25843, - 25797,25751,25705,25658,25612,25566,25520,25473, - 25427,25381,25334,25288,25241,25195,25149,25102, - 25056,25009,24963,24916,24870,24823,24777,24730, - 24684,24637,24591,24544,24497,24451,24404,24357, - 24311,24264,24217,24171,24124,24077,24030,23984, - 23937,23890,23843,23796,23750,23703,23656,23609, - 23562,23515,23468,23421,23374,23327,23280,23233, - 23186,23139,23092,23045,22998,22951,22904,22857, - 22810,22763,22716,22668,22621,22574,22527,22480, - 22433,22385,22338,22291,22243,22196,22149,22102, - 22054,22007,21960,21912,21865,21817,21770,21723, - 21675,21628,21580,21533,21485,21438,21390,21343, - 21295,21248,21200,21153,21105,21057,21010,20962, - 20915,20867,20819,20772,20724,20676,20629,20581, - 20533,20485,20438,20390,20342,20294,20246,20199, - 20151,20103,20055,20007,19959,19912,19864,19816, - 19768,19720,19672,19624,19576,19528,19480,19432, - 19384,19336,19288,19240,19192,19144,19096,19048, - 19000,18951,18903,18855,18807,18759,18711,18663, - 18614,18566,18518,18470,18421,18373,18325,18277, - 18228,18180,18132,18084,18035,17987,17939,17890, - 17842,17793,17745,17697,17648,17600,17551,17503, - 17455,17406,17358,17309,17261,17212,17164,17115, - 17067,17018,16970,16921,16872,16824,16775,16727, - 16678,16629,16581,16532,16484,16435,16386,16338, - 16289,16240,16191,16143,16094,16045,15997,15948, - 15899,15850,15802,15753,15704,15655,15606,15557, - 15509,15460,15411,15362,15313,15264,15215,15167, - 15118,15069,15020,14971,14922,14873,14824,14775, - 14726,14677,14628,14579,14530,14481,14432,14383, - 14334,14285,14236,14187,14138,14089,14040,13990, - 13941,13892,13843,13794,13745,13696,13646,13597, - 13548,13499,13450,13401,13351,13302,13253,13204, - 13154,13105,13056,13007,12957,12908,12859,12810, - 12760,12711,12662,12612,12563,12514,12464,12415, - 12366,12316,12267,12218,12168,12119,12069,12020, - 11970,11921,11872,11822,11773,11723,11674,11624, - 11575,11525,11476,11426,11377,11327,11278,11228, - 11179,11129,11080,11030,10981,10931,10882,10832, - 10782,10733,10683,10634,10584,10534,10485,10435, - 10386,10336,10286,10237,10187,10137,10088,10038, - 9988,9939,9889,9839,9790,9740,9690,9640, - 9591,9541,9491,9442,9392,9342,9292,9243, - 9193,9143,9093,9043,8994,8944,8894,8844, - 8794,8745,8695,8645,8595,8545,8496,8446, - 8396,8346,8296,8246,8196,8147,8097,8047, - 7997,7947,7897,7847,7797,7747,7697,7648, - 7598,7548,7498,7448,7398,7348,7298,7248, - 7198,7148,7098,7048,6998,6948,6898,6848, - 6798,6748,6698,6648,6598,6548,6498,6448, - 6398,6348,6298,6248,6198,6148,6098,6048, - 5998,5948,5898,5848,5798,5748,5697,5647, - 5597,5547,5497,5447,5397,5347,5297,5247, - 5197,5146,5096,5046,4996,4946,4896,4846, - 4796,4745,4695,4645,4595,4545,4495,4445, - 4394,4344,4294,4244,4194,4144,4093,4043, - 3993,3943,3893,3843,3792,3742,3692,3642, - 3592,3541,3491,3441,3391,3341,3291,3240, - 3190,3140,3090,3039,2989,2939,2889,2839, - 2788,2738,2688,2638,2587,2537,2487,2437, - 2387,2336,2286,2236,2186,2135,2085,2035, - 1985,1934,1884,1834,1784,1733,1683,1633, - 1583,1532,1482,1432,1382,1331,1281,1231, - 1181,1130,1080,1030,980,929,879,829, - 779,728,678,628,578,527,477,427, - 376,326,276,226,175,125,75,25, - -25,-75,-125,-175,-226,-276,-326,-376, - -427,-477,-527,-578,-628,-678,-728,-779, - -829,-879,-929,-980,-1030,-1080,-1130,-1181, - -1231,-1281,-1331,-1382,-1432,-1482,-1532,-1583, - -1633,-1683,-1733,-1784,-1834,-1884,-1934,-1985, - -2035,-2085,-2135,-2186,-2236,-2286,-2336,-2387, - -2437,-2487,-2537,-2588,-2638,-2688,-2738,-2788, - -2839,-2889,-2939,-2989,-3039,-3090,-3140,-3190, - -3240,-3291,-3341,-3391,-3441,-3491,-3541,-3592, - -3642,-3692,-3742,-3792,-3843,-3893,-3943,-3993, - -4043,-4093,-4144,-4194,-4244,-4294,-4344,-4394, - -4445,-4495,-4545,-4595,-4645,-4695,-4745,-4796, - -4846,-4896,-4946,-4996,-5046,-5096,-5146,-5197, - -5247,-5297,-5347,-5397,-5447,-5497,-5547,-5597, - -5647,-5697,-5748,-5798,-5848,-5898,-5948,-5998, - -6048,-6098,-6148,-6198,-6248,-6298,-6348,-6398, - -6448,-6498,-6548,-6598,-6648,-6698,-6748,-6798, - -6848,-6898,-6948,-6998,-7048,-7098,-7148,-7198, - -7248,-7298,-7348,-7398,-7448,-7498,-7548,-7598, - -7648,-7697,-7747,-7797,-7847,-7897,-7947,-7997, - -8047,-8097,-8147,-8196,-8246,-8296,-8346,-8396, - -8446,-8496,-8545,-8595,-8645,-8695,-8745,-8794, - -8844,-8894,-8944,-8994,-9043,-9093,-9143,-9193, - -9243,-9292,-9342,-9392,-9442,-9491,-9541,-9591, - -9640,-9690,-9740,-9790,-9839,-9889,-9939,-9988, - -10038,-10088,-10137,-10187,-10237,-10286,-10336,-10386, - -10435,-10485,-10534,-10584,-10634,-10683,-10733,-10782, - -10832,-10882,-10931,-10981,-11030,-11080,-11129,-11179, - -11228,-11278,-11327,-11377,-11426,-11476,-11525,-11575, - -11624,-11674,-11723,-11773,-11822,-11872,-11921,-11970, - -12020,-12069,-12119,-12168,-12218,-12267,-12316,-12366, - -12415,-12464,-12514,-12563,-12612,-12662,-12711,-12760, - -12810,-12859,-12908,-12957,-13007,-13056,-13105,-13154, - -13204,-13253,-13302,-13351,-13401,-13450,-13499,-13548, - -13597,-13647,-13696,-13745,-13794,-13843,-13892,-13941, - -13990,-14040,-14089,-14138,-14187,-14236,-14285,-14334, - -14383,-14432,-14481,-14530,-14579,-14628,-14677,-14726, - -14775,-14824,-14873,-14922,-14971,-15020,-15069,-15118, - -15167,-15215,-15264,-15313,-15362,-15411,-15460,-15509, - -15557,-15606,-15655,-15704,-15753,-15802,-15850,-15899, - -15948,-15997,-16045,-16094,-16143,-16191,-16240,-16289, - -16338,-16386,-16435,-16484,-16532,-16581,-16629,-16678, - -16727,-16775,-16824,-16872,-16921,-16970,-17018,-17067, - -17115,-17164,-17212,-17261,-17309,-17358,-17406,-17455, - -17503,-17551,-17600,-17648,-17697,-17745,-17793,-17842, - -17890,-17939,-17987,-18035,-18084,-18132,-18180,-18228, - -18277,-18325,-18373,-18421,-18470,-18518,-18566,-18614, - -18663,-18711,-18759,-18807,-18855,-18903,-18951,-19000, - -19048,-19096,-19144,-19192,-19240,-19288,-19336,-19384, - -19432,-19480,-19528,-19576,-19624,-19672,-19720,-19768, - -19816,-19864,-19912,-19959,-20007,-20055,-20103,-20151, - -20199,-20246,-20294,-20342,-20390,-20438,-20485,-20533, - -20581,-20629,-20676,-20724,-20772,-20819,-20867,-20915, - -20962,-21010,-21057,-21105,-21153,-21200,-21248,-21295, - -21343,-21390,-21438,-21485,-21533,-21580,-21628,-21675, - -21723,-21770,-21817,-21865,-21912,-21960,-22007,-22054, - -22102,-22149,-22196,-22243,-22291,-22338,-22385,-22433, - -22480,-22527,-22574,-22621,-22668,-22716,-22763,-22810, - -22857,-22904,-22951,-22998,-23045,-23092,-23139,-23186, - -23233,-23280,-23327,-23374,-23421,-23468,-23515,-23562, - -23609,-23656,-23703,-23750,-23796,-23843,-23890,-23937, - -23984,-24030,-24077,-24124,-24171,-24217,-24264,-24311, - -24357,-24404,-24451,-24497,-24544,-24591,-24637,-24684, - -24730,-24777,-24823,-24870,-24916,-24963,-25009,-25056, - -25102,-25149,-25195,-25241,-25288,-25334,-25381,-25427, - -25473,-25520,-25566,-25612,-25658,-25705,-25751,-25797, - -25843,-25889,-25936,-25982,-26028,-26074,-26120,-26166, - -26212,-26258,-26304,-26350,-26396,-26442,-26488,-26534, - -26580,-26626,-26672,-26718,-26764,-26810,-26856,-26902, - -26947,-26993,-27039,-27085,-27131,-27176,-27222,-27268, - -27313,-27359,-27405,-27450,-27496,-27542,-27587,-27633, - -27678,-27724,-27770,-27815,-27861,-27906,-27952,-27997, - -28042,-28088,-28133,-28179,-28224,-28269,-28315,-28360, - -28405,-28451,-28496,-28541,-28586,-28632,-28677,-28722, - -28767,-28812,-28858,-28903,-28948,-28993,-29038,-29083, - -29128,-29173,-29218,-29263,-29308,-29353,-29398,-29443, - -29488,-29533,-29577,-29622,-29667,-29712,-29757,-29801, - -29846,-29891,-29936,-29980,-30025,-30070,-30114,-30159, - -30204,-30248,-30293,-30337,-30382,-30426,-30471,-30515, - -30560,-30604,-30649,-30693,-30738,-30782,-30826,-30871, - -30915,-30959,-31004,-31048,-31092,-31136,-31181,-31225, - -31269,-31313,-31357,-31402,-31446,-31490,-31534,-31578, - -31622,-31666,-31710,-31754,-31798,-31842,-31886,-31930, - -31974,-32017,-32061,-32105,-32149,-32193,-32236,-32280, - -32324,-32368,-32411,-32455,-32499,-32542,-32586,-32630, - -32673,-32717,-32760,-32804,-32847,-32891,-32934,-32978, - -33021,-33065,-33108,-33151,-33195,-33238,-33281,-33325, - -33368,-33411,-33454,-33498,-33541,-33584,-33627,-33670, - -33713,-33756,-33799,-33843,-33886,-33929,-33972,-34015, - -34057,-34100,-34143,-34186,-34229,-34272,-34315,-34358, - -34400,-34443,-34486,-34529,-34571,-34614,-34657,-34699, - -34742,-34785,-34827,-34870,-34912,-34955,-34997,-35040, - -35082,-35125,-35167,-35210,-35252,-35294,-35337,-35379, - -35421,-35464,-35506,-35548,-35590,-35633,-35675,-35717, - -35759,-35801,-35843,-35885,-35927,-35969,-36011,-36053, - -36095,-36137,-36179,-36221,-36263,-36305,-36347,-36388, - -36430,-36472,-36514,-36555,-36597,-36639,-36681,-36722, - -36764,-36805,-36847,-36889,-36930,-36972,-37013,-37055, - -37096,-37137,-37179,-37220,-37262,-37303,-37344,-37386, - -37427,-37468,-37509,-37551,-37592,-37633,-37674,-37715, - -37756,-37797,-37838,-37879,-37920,-37961,-38002,-38043, - -38084,-38125,-38166,-38207,-38248,-38288,-38329,-38370, - -38411,-38451,-38492,-38533,-38573,-38614,-38655,-38695, - -38736,-38776,-38817,-38857,-38898,-38938,-38979,-39019, - -39059,-39100,-39140,-39180,-39221,-39261,-39301,-39341, - -39382,-39422,-39462,-39502,-39542,-39582,-39622,-39662, - -39702,-39742,-39782,-39822,-39862,-39902,-39942,-39982, - -40021,-40061,-40101,-40141,-40180,-40220,-40260,-40299, - -40339,-40379,-40418,-40458,-40497,-40537,-40576,-40616, - -40655,-40695,-40734,-40773,-40813,-40852,-40891,-40931, - -40970,-41009,-41048,-41087,-41127,-41166,-41205,-41244, - -41283,-41322,-41361,-41400,-41439,-41478,-41517,-41556, - -41595,-41633,-41672,-41711,-41750,-41788,-41827,-41866, - -41904,-41943,-41982,-42020,-42059,-42097,-42136,-42174, - -42213,-42251,-42290,-42328,-42366,-42405,-42443,-42481, - -42520,-42558,-42596,-42634,-42672,-42711,-42749,-42787, - -42825,-42863,-42901,-42939,-42977,-43015,-43053,-43091, - -43128,-43166,-43204,-43242,-43280,-43317,-43355,-43393, - -43430,-43468,-43506,-43543,-43581,-43618,-43656,-43693, - -43731,-43768,-43806,-43843,-43880,-43918,-43955,-43992, - -44029,-44067,-44104,-44141,-44178,-44215,-44252,-44289, - -44326,-44363,-44400,-44437,-44474,-44511,-44548,-44585, - -44622,-44659,-44695,-44732,-44769,-44806,-44842,-44879, - -44915,-44952,-44989,-45025,-45062,-45098,-45135,-45171, - -45207,-45244,-45280,-45316,-45353,-45389,-45425,-45462, - -45498,-45534,-45570,-45606,-45642,-45678,-45714,-45750, - -45786,-45822,-45858,-45894,-45930,-45966,-46002,-46037, - -46073,-46109,-46145,-46180,-46216,-46252,-46287,-46323, - -46358,-46394,-46429,-46465,-46500,-46536,-46571,-46606, - -46642,-46677,-46712,-46747,-46783,-46818,-46853,-46888, - -46923,-46958,-46993,-47028,-47063,-47098,-47133,-47168, - -47203,-47238,-47273,-47308,-47342,-47377,-47412,-47446, - -47481,-47516,-47550,-47585,-47619,-47654,-47688,-47723, - -47757,-47792,-47826,-47860,-47895,-47929,-47963,-47998, - -48032,-48066,-48100,-48134,-48168,-48202,-48236,-48271, - -48304,-48338,-48372,-48406,-48440,-48474,-48508,-48542, - -48575,-48609,-48643,-48676,-48710,-48744,-48777,-48811, - -48844,-48878,-48911,-48945,-48978,-49012,-49045,-49078, - -49112,-49145,-49178,-49211,-49244,-49278,-49311,-49344, - -49377,-49410,-49443,-49476,-49509,-49542,-49575,-49608, - -49640,-49673,-49706,-49739,-49771,-49804,-49837,-49869, - -49902,-49935,-49967,-50000,-50032,-50065,-50097,-50129, - -50162,-50194,-50226,-50259,-50291,-50323,-50355,-50387, - -50420,-50452,-50484,-50516,-50548,-50580,-50612,-50644, - -50675,-50707,-50739,-50771,-50803,-50834,-50866,-50898, - -50929,-50961,-50993,-51024,-51056,-51087,-51119,-51150, - -51182,-51213,-51244,-51276,-51307,-51338,-51369,-51401, - -51432,-51463,-51494,-51525,-51556,-51587,-51618,-51649, - -51680,-51711,-51742,-51773,-51803,-51834,-51865,-51896, - -51926,-51957,-51988,-52018,-52049,-52079,-52110,-52140, - -52171,-52201,-52231,-52262,-52292,-52322,-52353,-52383, - -52413,-52443,-52473,-52503,-52534,-52564,-52594,-52624, - -52653,-52683,-52713,-52743,-52773,-52803,-52832,-52862, - -52892,-52922,-52951,-52981,-53010,-53040,-53069,-53099, - -53128,-53158,-53187,-53216,-53246,-53275,-53304,-53334, - -53363,-53392,-53421,-53450,-53479,-53508,-53537,-53566, - -53595,-53624,-53653,-53682,-53711,-53739,-53768,-53797, - -53826,-53854,-53883,-53911,-53940,-53969,-53997,-54026, - -54054,-54082,-54111,-54139,-54167,-54196,-54224,-54252, - -54280,-54308,-54337,-54365,-54393,-54421,-54449,-54477, - -54505,-54533,-54560,-54588,-54616,-54644,-54672,-54699, - -54727,-54755,-54782,-54810,-54837,-54865,-54892,-54920, - -54947,-54974,-55002,-55029,-55056,-55084,-55111,-55138, - -55165,-55192,-55219,-55246,-55274,-55300,-55327,-55354, - -55381,-55408,-55435,-55462,-55489,-55515,-55542,-55569, - -55595,-55622,-55648,-55675,-55701,-55728,-55754,-55781, - -55807,-55833,-55860,-55886,-55912,-55938,-55965,-55991, - -56017,-56043,-56069,-56095,-56121,-56147,-56173,-56199, - -56225,-56250,-56276,-56302,-56328,-56353,-56379,-56404, - -56430,-56456,-56481,-56507,-56532,-56557,-56583,-56608, - -56633,-56659,-56684,-56709,-56734,-56760,-56785,-56810, - -56835,-56860,-56885,-56910,-56935,-56959,-56984,-57009, - -57034,-57059,-57083,-57108,-57133,-57157,-57182,-57206, - -57231,-57255,-57280,-57304,-57329,-57353,-57377,-57402, - -57426,-57450,-57474,-57498,-57522,-57546,-57570,-57594, - -57618,-57642,-57666,-57690,-57714,-57738,-57762,-57785, - -57809,-57833,-57856,-57880,-57903,-57927,-57950,-57974, - -57997,-58021,-58044,-58067,-58091,-58114,-58137,-58160, - -58183,-58207,-58230,-58253,-58276,-58299,-58322,-58345, - -58367,-58390,-58413,-58436,-58459,-58481,-58504,-58527, - -58549,-58572,-58594,-58617,-58639,-58662,-58684,-58706, - -58729,-58751,-58773,-58795,-58818,-58840,-58862,-58884, - -58906,-58928,-58950,-58972,-58994,-59016,-59038,-59059, - -59081,-59103,-59125,-59146,-59168,-59190,-59211,-59233, - -59254,-59276,-59297,-59318,-59340,-59361,-59382,-59404, - -59425,-59446,-59467,-59488,-59509,-59530,-59551,-59572, - -59593,-59614,-59635,-59656,-59677,-59697,-59718,-59739, - -59759,-59780,-59801,-59821,-59842,-59862,-59883,-59903, - -59923,-59944,-59964,-59984,-60004,-60025,-60045,-60065, - -60085,-60105,-60125,-60145,-60165,-60185,-60205,-60225, - -60244,-60264,-60284,-60304,-60323,-60343,-60363,-60382, - -60402,-60421,-60441,-60460,-60479,-60499,-60518,-60537, - -60556,-60576,-60595,-60614,-60633,-60652,-60671,-60690, - -60709,-60728,-60747,-60766,-60785,-60803,-60822,-60841, - -60859,-60878,-60897,-60915,-60934,-60952,-60971,-60989, - -61007,-61026,-61044,-61062,-61081,-61099,-61117,-61135, - -61153,-61171,-61189,-61207,-61225,-61243,-61261,-61279, - -61297,-61314,-61332,-61350,-61367,-61385,-61403,-61420, - -61438,-61455,-61473,-61490,-61507,-61525,-61542,-61559, - -61577,-61594,-61611,-61628,-61645,-61662,-61679,-61696, - -61713,-61730,-61747,-61764,-61780,-61797,-61814,-61831, - -61847,-61864,-61880,-61897,-61913,-61930,-61946,-61963, - -61979,-61995,-62012,-62028,-62044,-62060,-62076,-62092, - -62108,-62125,-62141,-62156,-62172,-62188,-62204,-62220, - -62236,-62251,-62267,-62283,-62298,-62314,-62329,-62345, - -62360,-62376,-62391,-62407,-62422,-62437,-62453,-62468, - -62483,-62498,-62513,-62528,-62543,-62558,-62573,-62588, - -62603,-62618,-62633,-62648,-62662,-62677,-62692,-62706, - -62721,-62735,-62750,-62764,-62779,-62793,-62808,-62822, - -62836,-62850,-62865,-62879,-62893,-62907,-62921,-62935, - -62949,-62963,-62977,-62991,-63005,-63019,-63032,-63046, - -63060,-63074,-63087,-63101,-63114,-63128,-63141,-63155, - -63168,-63182,-63195,-63208,-63221,-63235,-63248,-63261, - -63274,-63287,-63300,-63313,-63326,-63339,-63352,-63365, - -63378,-63390,-63403,-63416,-63429,-63441,-63454,-63466, - -63479,-63491,-63504,-63516,-63528,-63541,-63553,-63565, - -63578,-63590,-63602,-63614,-63626,-63638,-63650,-63662, - -63674,-63686,-63698,-63709,-63721,-63733,-63745,-63756, - -63768,-63779,-63791,-63803,-63814,-63825,-63837,-63848, - -63859,-63871,-63882,-63893,-63904,-63915,-63927,-63938, - -63949,-63960,-63971,-63981,-63992,-64003,-64014,-64025, - -64035,-64046,-64057,-64067,-64078,-64088,-64099,-64109, - -64120,-64130,-64140,-64151,-64161,-64171,-64181,-64192, - -64202,-64212,-64222,-64232,-64242,-64252,-64261,-64271, - -64281,-64291,-64301,-64310,-64320,-64330,-64339,-64349, - -64358,-64368,-64377,-64387,-64396,-64405,-64414,-64424, - -64433,-64442,-64451,-64460,-64469,-64478,-64487,-64496, - -64505,-64514,-64523,-64532,-64540,-64549,-64558,-64566, - -64575,-64584,-64592,-64601,-64609,-64617,-64626,-64634, - -64642,-64651,-64659,-64667,-64675,-64683,-64691,-64699, - -64707,-64715,-64723,-64731,-64739,-64747,-64754,-64762, - -64770,-64777,-64785,-64793,-64800,-64808,-64815,-64822, - -64830,-64837,-64844,-64852,-64859,-64866,-64873,-64880, - -64887,-64895,-64902,-64908,-64915,-64922,-64929,-64936, - -64943,-64949,-64956,-64963,-64969,-64976,-64982,-64989, - -64995,-65002,-65008,-65015,-65021,-65027,-65033,-65040, - -65046,-65052,-65058,-65064,-65070,-65076,-65082,-65088, - -65094,-65099,-65105,-65111,-65117,-65122,-65128,-65133, - -65139,-65144,-65150,-65155,-65161,-65166,-65171,-65177, - -65182,-65187,-65192,-65197,-65202,-65207,-65212,-65217, - -65222,-65227,-65232,-65237,-65242,-65246,-65251,-65256, - -65260,-65265,-65270,-65274,-65279,-65283,-65287,-65292, - -65296,-65300,-65305,-65309,-65313,-65317,-65321,-65325, - -65329,-65333,-65337,-65341,-65345,-65349,-65352,-65356, - -65360,-65363,-65367,-65371,-65374,-65378,-65381,-65385, - -65388,-65391,-65395,-65398,-65401,-65404,-65408,-65411, - -65414,-65417,-65420,-65423,-65426,-65429,-65431,-65434, - -65437,-65440,-65442,-65445,-65448,-65450,-65453,-65455, - -65458,-65460,-65463,-65465,-65467,-65470,-65472,-65474, - -65476,-65478,-65480,-65482,-65484,-65486,-65488,-65490, - -65492,-65494,-65496,-65497,-65499,-65501,-65502,-65504, - -65505,-65507,-65508,-65510,-65511,-65513,-65514,-65515, - -65516,-65518,-65519,-65520,-65521,-65522,-65523,-65524, - -65525,-65526,-65527,-65527,-65528,-65529,-65530,-65530, - -65531,-65531,-65532,-65532,-65533,-65533,-65534,-65534, - -65534,-65535,-65535,-65535,-65535,-65535,-65535,-65535, - -65535,-65535,-65535,-65535,-65535,-65535,-65535,-65534, - -65534,-65534,-65533,-65533,-65532,-65532,-65531,-65531, - -65530,-65530,-65529,-65528,-65527,-65527,-65526,-65525, - -65524,-65523,-65522,-65521,-65520,-65519,-65518,-65516, - -65515,-65514,-65513,-65511,-65510,-65508,-65507,-65505, - -65504,-65502,-65501,-65499,-65497,-65496,-65494,-65492, - -65490,-65488,-65486,-65484,-65482,-65480,-65478,-65476, - -65474,-65472,-65470,-65467,-65465,-65463,-65460,-65458, - -65455,-65453,-65450,-65448,-65445,-65442,-65440,-65437, - -65434,-65431,-65429,-65426,-65423,-65420,-65417,-65414, - -65411,-65408,-65404,-65401,-65398,-65395,-65391,-65388, - -65385,-65381,-65378,-65374,-65371,-65367,-65363,-65360, - -65356,-65352,-65349,-65345,-65341,-65337,-65333,-65329, - -65325,-65321,-65317,-65313,-65309,-65305,-65300,-65296, - -65292,-65287,-65283,-65279,-65274,-65270,-65265,-65260, - -65256,-65251,-65246,-65242,-65237,-65232,-65227,-65222, - -65217,-65212,-65207,-65202,-65197,-65192,-65187,-65182, - -65177,-65171,-65166,-65161,-65155,-65150,-65144,-65139, - -65133,-65128,-65122,-65117,-65111,-65105,-65099,-65094, - -65088,-65082,-65076,-65070,-65064,-65058,-65052,-65046, - -65040,-65033,-65027,-65021,-65015,-65008,-65002,-64995, - -64989,-64982,-64976,-64969,-64963,-64956,-64949,-64943, - -64936,-64929,-64922,-64915,-64908,-64902,-64895,-64887, - -64880,-64873,-64866,-64859,-64852,-64844,-64837,-64830, - -64822,-64815,-64808,-64800,-64793,-64785,-64777,-64770, - -64762,-64754,-64747,-64739,-64731,-64723,-64715,-64707, - -64699,-64691,-64683,-64675,-64667,-64659,-64651,-64642, - -64634,-64626,-64617,-64609,-64601,-64592,-64584,-64575, - -64566,-64558,-64549,-64540,-64532,-64523,-64514,-64505, - -64496,-64487,-64478,-64469,-64460,-64451,-64442,-64433, - -64424,-64414,-64405,-64396,-64387,-64377,-64368,-64358, - -64349,-64339,-64330,-64320,-64310,-64301,-64291,-64281, - -64271,-64261,-64252,-64242,-64232,-64222,-64212,-64202, - -64192,-64181,-64171,-64161,-64151,-64140,-64130,-64120, - -64109,-64099,-64088,-64078,-64067,-64057,-64046,-64035, - -64025,-64014,-64003,-63992,-63981,-63971,-63960,-63949, - -63938,-63927,-63915,-63904,-63893,-63882,-63871,-63859, - -63848,-63837,-63825,-63814,-63803,-63791,-63779,-63768, - -63756,-63745,-63733,-63721,-63709,-63698,-63686,-63674, - -63662,-63650,-63638,-63626,-63614,-63602,-63590,-63578, - -63565,-63553,-63541,-63528,-63516,-63504,-63491,-63479, - -63466,-63454,-63441,-63429,-63416,-63403,-63390,-63378, - -63365,-63352,-63339,-63326,-63313,-63300,-63287,-63274, - -63261,-63248,-63235,-63221,-63208,-63195,-63182,-63168, - -63155,-63141,-63128,-63114,-63101,-63087,-63074,-63060, - -63046,-63032,-63019,-63005,-62991,-62977,-62963,-62949, - -62935,-62921,-62907,-62893,-62879,-62865,-62850,-62836, - -62822,-62808,-62793,-62779,-62764,-62750,-62735,-62721, - -62706,-62692,-62677,-62662,-62648,-62633,-62618,-62603, - -62588,-62573,-62558,-62543,-62528,-62513,-62498,-62483, - -62468,-62453,-62437,-62422,-62407,-62391,-62376,-62360, - -62345,-62329,-62314,-62298,-62283,-62267,-62251,-62236, - -62220,-62204,-62188,-62172,-62156,-62141,-62125,-62108, - -62092,-62076,-62060,-62044,-62028,-62012,-61995,-61979, - -61963,-61946,-61930,-61913,-61897,-61880,-61864,-61847, - -61831,-61814,-61797,-61780,-61764,-61747,-61730,-61713, - -61696,-61679,-61662,-61645,-61628,-61611,-61594,-61577, - -61559,-61542,-61525,-61507,-61490,-61473,-61455,-61438, - -61420,-61403,-61385,-61367,-61350,-61332,-61314,-61297, - -61279,-61261,-61243,-61225,-61207,-61189,-61171,-61153, - -61135,-61117,-61099,-61081,-61062,-61044,-61026,-61007, - -60989,-60971,-60952,-60934,-60915,-60897,-60878,-60859, - -60841,-60822,-60803,-60785,-60766,-60747,-60728,-60709, - -60690,-60671,-60652,-60633,-60614,-60595,-60576,-60556, - -60537,-60518,-60499,-60479,-60460,-60441,-60421,-60402, - -60382,-60363,-60343,-60323,-60304,-60284,-60264,-60244, - -60225,-60205,-60185,-60165,-60145,-60125,-60105,-60085, - -60065,-60045,-60025,-60004,-59984,-59964,-59944,-59923, - -59903,-59883,-59862,-59842,-59821,-59801,-59780,-59759, - -59739,-59718,-59697,-59677,-59656,-59635,-59614,-59593, - -59572,-59551,-59530,-59509,-59488,-59467,-59446,-59425, - -59404,-59382,-59361,-59340,-59318,-59297,-59276,-59254, - -59233,-59211,-59189,-59168,-59146,-59125,-59103,-59081, - -59059,-59038,-59016,-58994,-58972,-58950,-58928,-58906, - -58884,-58862,-58840,-58818,-58795,-58773,-58751,-58729, - -58706,-58684,-58662,-58639,-58617,-58594,-58572,-58549, - -58527,-58504,-58481,-58459,-58436,-58413,-58390,-58367, - -58345,-58322,-58299,-58276,-58253,-58230,-58207,-58183, - -58160,-58137,-58114,-58091,-58067,-58044,-58021,-57997, - -57974,-57950,-57927,-57903,-57880,-57856,-57833,-57809, - -57785,-57762,-57738,-57714,-57690,-57666,-57642,-57618, - -57594,-57570,-57546,-57522,-57498,-57474,-57450,-57426, - -57402,-57377,-57353,-57329,-57304,-57280,-57255,-57231, - -57206,-57182,-57157,-57133,-57108,-57083,-57059,-57034, - -57009,-56984,-56959,-56935,-56910,-56885,-56860,-56835, - -56810,-56785,-56760,-56734,-56709,-56684,-56659,-56633, - -56608,-56583,-56557,-56532,-56507,-56481,-56456,-56430, - -56404,-56379,-56353,-56328,-56302,-56276,-56250,-56225, - -56199,-56173,-56147,-56121,-56095,-56069,-56043,-56017, - -55991,-55965,-55938,-55912,-55886,-55860,-55833,-55807, - -55781,-55754,-55728,-55701,-55675,-55648,-55622,-55595, - -55569,-55542,-55515,-55489,-55462,-55435,-55408,-55381, - -55354,-55327,-55300,-55274,-55246,-55219,-55192,-55165, - -55138,-55111,-55084,-55056,-55029,-55002,-54974,-54947, - -54920,-54892,-54865,-54837,-54810,-54782,-54755,-54727, - -54699,-54672,-54644,-54616,-54588,-54560,-54533,-54505, - -54477,-54449,-54421,-54393,-54365,-54337,-54308,-54280, - -54252,-54224,-54196,-54167,-54139,-54111,-54082,-54054, - -54026,-53997,-53969,-53940,-53911,-53883,-53854,-53826, - -53797,-53768,-53739,-53711,-53682,-53653,-53624,-53595, - -53566,-53537,-53508,-53479,-53450,-53421,-53392,-53363, - -53334,-53304,-53275,-53246,-53216,-53187,-53158,-53128, - -53099,-53069,-53040,-53010,-52981,-52951,-52922,-52892, - -52862,-52832,-52803,-52773,-52743,-52713,-52683,-52653, - -52624,-52594,-52564,-52534,-52503,-52473,-52443,-52413, - -52383,-52353,-52322,-52292,-52262,-52231,-52201,-52171, - -52140,-52110,-52079,-52049,-52018,-51988,-51957,-51926, - -51896,-51865,-51834,-51803,-51773,-51742,-51711,-51680, - -51649,-51618,-51587,-51556,-51525,-51494,-51463,-51432, - -51401,-51369,-51338,-51307,-51276,-51244,-51213,-51182, - -51150,-51119,-51087,-51056,-51024,-50993,-50961,-50929, - -50898,-50866,-50834,-50803,-50771,-50739,-50707,-50675, - -50644,-50612,-50580,-50548,-50516,-50484,-50452,-50420, - -50387,-50355,-50323,-50291,-50259,-50226,-50194,-50162, - -50129,-50097,-50065,-50032,-50000,-49967,-49935,-49902, - -49869,-49837,-49804,-49771,-49739,-49706,-49673,-49640, - -49608,-49575,-49542,-49509,-49476,-49443,-49410,-49377, - -49344,-49311,-49278,-49244,-49211,-49178,-49145,-49112, - -49078,-49045,-49012,-48978,-48945,-48911,-48878,-48844, - -48811,-48777,-48744,-48710,-48676,-48643,-48609,-48575, - -48542,-48508,-48474,-48440,-48406,-48372,-48338,-48305, - -48271,-48237,-48202,-48168,-48134,-48100,-48066,-48032, - -47998,-47963,-47929,-47895,-47860,-47826,-47792,-47757, - -47723,-47688,-47654,-47619,-47585,-47550,-47516,-47481, - -47446,-47412,-47377,-47342,-47307,-47273,-47238,-47203, - -47168,-47133,-47098,-47063,-47028,-46993,-46958,-46923, - -46888,-46853,-46818,-46783,-46747,-46712,-46677,-46642, - -46606,-46571,-46536,-46500,-46465,-46429,-46394,-46358, - -46323,-46287,-46251,-46216,-46180,-46145,-46109,-46073, - -46037,-46002,-45966,-45930,-45894,-45858,-45822,-45786, - -45750,-45714,-45678,-45642,-45606,-45570,-45534,-45498, - -45462,-45425,-45389,-45353,-45316,-45280,-45244,-45207, - -45171,-45135,-45098,-45062,-45025,-44989,-44952,-44915, - -44879,-44842,-44806,-44769,-44732,-44695,-44659,-44622, - -44585,-44548,-44511,-44474,-44437,-44400,-44363,-44326, - -44289,-44252,-44215,-44178,-44141,-44104,-44067,-44029, - -43992,-43955,-43918,-43880,-43843,-43806,-43768,-43731, - -43693,-43656,-43618,-43581,-43543,-43506,-43468,-43430, - -43393,-43355,-43317,-43280,-43242,-43204,-43166,-43128, - -43091,-43053,-43015,-42977,-42939,-42901,-42863,-42825, - -42787,-42749,-42711,-42672,-42634,-42596,-42558,-42520, - -42481,-42443,-42405,-42366,-42328,-42290,-42251,-42213, - -42174,-42136,-42097,-42059,-42020,-41982,-41943,-41904, - -41866,-41827,-41788,-41750,-41711,-41672,-41633,-41595, - -41556,-41517,-41478,-41439,-41400,-41361,-41322,-41283, - -41244,-41205,-41166,-41127,-41087,-41048,-41009,-40970, - -40931,-40891,-40852,-40813,-40773,-40734,-40695,-40655, - -40616,-40576,-40537,-40497,-40458,-40418,-40379,-40339, - -40299,-40260,-40220,-40180,-40141,-40101,-40061,-40021, - -39982,-39942,-39902,-39862,-39822,-39782,-39742,-39702, - -39662,-39622,-39582,-39542,-39502,-39462,-39422,-39382, - -39341,-39301,-39261,-39221,-39180,-39140,-39100,-39059, - -39019,-38979,-38938,-38898,-38857,-38817,-38776,-38736, - -38695,-38655,-38614,-38573,-38533,-38492,-38451,-38411, - -38370,-38329,-38288,-38248,-38207,-38166,-38125,-38084, - -38043,-38002,-37961,-37920,-37879,-37838,-37797,-37756, - -37715,-37674,-37633,-37592,-37550,-37509,-37468,-37427, - -37386,-37344,-37303,-37262,-37220,-37179,-37137,-37096, - -37055,-37013,-36972,-36930,-36889,-36847,-36805,-36764, - -36722,-36681,-36639,-36597,-36556,-36514,-36472,-36430, - -36388,-36347,-36305,-36263,-36221,-36179,-36137,-36095, - -36053,-36011,-35969,-35927,-35885,-35843,-35801,-35759, - -35717,-35675,-35633,-35590,-35548,-35506,-35464,-35421, - -35379,-35337,-35294,-35252,-35210,-35167,-35125,-35082, - -35040,-34997,-34955,-34912,-34870,-34827,-34785,-34742, - -34699,-34657,-34614,-34571,-34529,-34486,-34443,-34400, - -34358,-34315,-34272,-34229,-34186,-34143,-34100,-34057, - -34015,-33972,-33929,-33886,-33843,-33799,-33756,-33713, - -33670,-33627,-33584,-33541,-33498,-33454,-33411,-33368, - -33325,-33281,-33238,-33195,-33151,-33108,-33065,-33021, - -32978,-32934,-32891,-32847,-32804,-32760,-32717,-32673, - -32630,-32586,-32542,-32499,-32455,-32411,-32368,-32324, - -32280,-32236,-32193,-32149,-32105,-32061,-32017,-31974, - -31930,-31886,-31842,-31798,-31754,-31710,-31666,-31622, - -31578,-31534,-31490,-31446,-31402,-31357,-31313,-31269, - -31225,-31181,-31136,-31092,-31048,-31004,-30959,-30915, - -30871,-30826,-30782,-30738,-30693,-30649,-30604,-30560, - -30515,-30471,-30426,-30382,-30337,-30293,-30248,-30204, - -30159,-30114,-30070,-30025,-29980,-29936,-29891,-29846, - -29801,-29757,-29712,-29667,-29622,-29577,-29533,-29488, - -29443,-29398,-29353,-29308,-29263,-29218,-29173,-29128, - -29083,-29038,-28993,-28948,-28903,-28858,-28812,-28767, - -28722,-28677,-28632,-28586,-28541,-28496,-28451,-28405, - -28360,-28315,-28269,-28224,-28179,-28133,-28088,-28042, - -27997,-27952,-27906,-27861,-27815,-27770,-27724,-27678, - -27633,-27587,-27542,-27496,-27450,-27405,-27359,-27313, - -27268,-27222,-27176,-27131,-27085,-27039,-26993,-26947, - -26902,-26856,-26810,-26764,-26718,-26672,-26626,-26580, - -26534,-26488,-26442,-26396,-26350,-26304,-26258,-26212, - -26166,-26120,-26074,-26028,-25982,-25936,-25889,-25843, - -25797,-25751,-25705,-25658,-25612,-25566,-25520,-25473, - -25427,-25381,-25334,-25288,-25241,-25195,-25149,-25102, - -25056,-25009,-24963,-24916,-24870,-24823,-24777,-24730, - -24684,-24637,-24591,-24544,-24497,-24451,-24404,-24357, - -24311,-24264,-24217,-24171,-24124,-24077,-24030,-23984, - -23937,-23890,-23843,-23796,-23750,-23703,-23656,-23609, - -23562,-23515,-23468,-23421,-23374,-23327,-23280,-23233, - -23186,-23139,-23092,-23045,-22998,-22951,-22904,-22857, - -22810,-22763,-22716,-22668,-22621,-22574,-22527,-22480, - -22432,-22385,-22338,-22291,-22243,-22196,-22149,-22102, - -22054,-22007,-21960,-21912,-21865,-21817,-21770,-21723, - -21675,-21628,-21580,-21533,-21485,-21438,-21390,-21343, - -21295,-21248,-21200,-21153,-21105,-21057,-21010,-20962, - -20915,-20867,-20819,-20772,-20724,-20676,-20629,-20581, - -20533,-20485,-20438,-20390,-20342,-20294,-20246,-20199, - -20151,-20103,-20055,-20007,-19959,-19912,-19864,-19816, - -19768,-19720,-19672,-19624,-19576,-19528,-19480,-19432, - -19384,-19336,-19288,-19240,-19192,-19144,-19096,-19048, - -19000,-18951,-18903,-18855,-18807,-18759,-18711,-18663, - -18614,-18566,-18518,-18470,-18421,-18373,-18325,-18277, - -18228,-18180,-18132,-18084,-18035,-17987,-17939,-17890, - -17842,-17793,-17745,-17697,-17648,-17600,-17551,-17503, - -17455,-17406,-17358,-17309,-17261,-17212,-17164,-17115, - -17067,-17018,-16970,-16921,-16872,-16824,-16775,-16727, - -16678,-16629,-16581,-16532,-16484,-16435,-16386,-16338, - -16289,-16240,-16191,-16143,-16094,-16045,-15997,-15948, - -15899,-15850,-15802,-15753,-15704,-15655,-15606,-15557, - -15509,-15460,-15411,-15362,-15313,-15264,-15215,-15167, - -15118,-15069,-15020,-14971,-14922,-14873,-14824,-14775, - -14726,-14677,-14628,-14579,-14530,-14481,-14432,-14383, - -14334,-14285,-14236,-14187,-14138,-14089,-14040,-13990, - -13941,-13892,-13843,-13794,-13745,-13696,-13647,-13597, - -13548,-13499,-13450,-13401,-13351,-13302,-13253,-13204, - -13154,-13105,-13056,-13007,-12957,-12908,-12859,-12810, - -12760,-12711,-12662,-12612,-12563,-12514,-12464,-12415, - -12366,-12316,-12267,-12217,-12168,-12119,-12069,-12020, - -11970,-11921,-11872,-11822,-11773,-11723,-11674,-11624, - -11575,-11525,-11476,-11426,-11377,-11327,-11278,-11228, - -11179,-11129,-11080,-11030,-10981,-10931,-10882,-10832, - -10782,-10733,-10683,-10634,-10584,-10534,-10485,-10435, - -10386,-10336,-10286,-10237,-10187,-10137,-10088,-10038, - -9988,-9939,-9889,-9839,-9790,-9740,-9690,-9640, - -9591,-9541,-9491,-9442,-9392,-9342,-9292,-9243, - -9193,-9143,-9093,-9043,-8994,-8944,-8894,-8844, - -8794,-8745,-8695,-8645,-8595,-8545,-8496,-8446, - -8396,-8346,-8296,-8246,-8196,-8147,-8097,-8047, - -7997,-7947,-7897,-7847,-7797,-7747,-7697,-7648, - -7598,-7548,-7498,-7448,-7398,-7348,-7298,-7248, - -7198,-7148,-7098,-7048,-6998,-6948,-6898,-6848, - -6798,-6748,-6698,-6648,-6598,-6548,-6498,-6448, - -6398,-6348,-6298,-6248,-6198,-6148,-6098,-6048, - -5998,-5948,-5898,-5848,-5798,-5747,-5697,-5647, - -5597,-5547,-5497,-5447,-5397,-5347,-5297,-5247, - -5197,-5146,-5096,-5046,-4996,-4946,-4896,-4846, - -4796,-4745,-4695,-4645,-4595,-4545,-4495,-4445, - -4394,-4344,-4294,-4244,-4194,-4144,-4093,-4043, - -3993,-3943,-3893,-3843,-3792,-3742,-3692,-3642, - -3592,-3541,-3491,-3441,-3391,-3341,-3291,-3240, - -3190,-3140,-3090,-3039,-2989,-2939,-2889,-2839, - -2788,-2738,-2688,-2638,-2588,-2537,-2487,-2437, - -2387,-2336,-2286,-2236,-2186,-2135,-2085,-2035, - -1985,-1934,-1884,-1834,-1784,-1733,-1683,-1633, - -1583,-1532,-1482,-1432,-1382,-1331,-1281,-1231, - -1181,-1130,-1080,-1030,-980,-929,-879,-829, - -779,-728,-678,-628,-578,-527,-477,-427, - -376,-326,-276,-226,-175,-125,-75,-25, - 25,75,125,175,226,276,326,376, - 427,477,527,578,628,678,728,779, - 829,879,929,980,1030,1080,1130,1181, - 1231,1281,1331,1382,1432,1482,1532,1583, - 1633,1683,1733,1784,1834,1884,1934,1985, - 2035,2085,2135,2186,2236,2286,2336,2387, - 2437,2487,2537,2587,2638,2688,2738,2788, - 2839,2889,2939,2989,3039,3090,3140,3190, - 3240,3291,3341,3391,3441,3491,3542,3592, - 3642,3692,3742,3792,3843,3893,3943,3993, - 4043,4093,4144,4194,4244,4294,4344,4394, - 4445,4495,4545,4595,4645,4695,4745,4796, - 4846,4896,4946,4996,5046,5096,5146,5197, - 5247,5297,5347,5397,5447,5497,5547,5597, - 5647,5697,5747,5798,5848,5898,5948,5998, - 6048,6098,6148,6198,6248,6298,6348,6398, - 6448,6498,6548,6598,6648,6698,6748,6798, - 6848,6898,6948,6998,7048,7098,7148,7198, - 7248,7298,7348,7398,7448,7498,7548,7598, - 7648,7697,7747,7797,7847,7897,7947,7997, - 8047,8097,8147,8196,8246,8296,8346,8396, - 8446,8496,8545,8595,8645,8695,8745,8794, - 8844,8894,8944,8994,9043,9093,9143,9193, - 9243,9292,9342,9392,9442,9491,9541,9591, - 9640,9690,9740,9790,9839,9889,9939,9988, - 10038,10088,10137,10187,10237,10286,10336,10386, - 10435,10485,10534,10584,10634,10683,10733,10782, - 10832,10882,10931,10981,11030,11080,11129,11179, - 11228,11278,11327,11377,11426,11476,11525,11575, - 11624,11674,11723,11773,11822,11872,11921,11970, - 12020,12069,12119,12168,12218,12267,12316,12366, - 12415,12464,12514,12563,12612,12662,12711,12760, - 12810,12859,12908,12957,13007,13056,13105,13154, - 13204,13253,13302,13351,13401,13450,13499,13548, - 13597,13647,13696,13745,13794,13843,13892,13941, - 13990,14040,14089,14138,14187,14236,14285,14334, - 14383,14432,14481,14530,14579,14628,14677,14726, - 14775,14824,14873,14922,14971,15020,15069,15118, - 15167,15215,15264,15313,15362,15411,15460,15509, - 15557,15606,15655,15704,15753,15802,15850,15899, - 15948,15997,16045,16094,16143,16191,16240,16289, - 16338,16386,16435,16484,16532,16581,16629,16678, - 16727,16775,16824,16872,16921,16970,17018,17067, - 17115,17164,17212,17261,17309,17358,17406,17455, - 17503,17551,17600,17648,17697,17745,17793,17842, - 17890,17939,17987,18035,18084,18132,18180,18228, - 18277,18325,18373,18421,18470,18518,18566,18614, - 18663,18711,18759,18807,18855,18903,18951,19000, - 19048,19096,19144,19192,19240,19288,19336,19384, - 19432,19480,19528,19576,19624,19672,19720,19768, - 19816,19864,19912,19959,20007,20055,20103,20151, - 20199,20246,20294,20342,20390,20438,20485,20533, - 20581,20629,20676,20724,20772,20819,20867,20915, - 20962,21010,21057,21105,21153,21200,21248,21295, - 21343,21390,21438,21485,21533,21580,21628,21675, - 21723,21770,21817,21865,21912,21960,22007,22054, - 22102,22149,22196,22243,22291,22338,22385,22432, - 22480,22527,22574,22621,22668,22716,22763,22810, - 22857,22904,22951,22998,23045,23092,23139,23186, - 23233,23280,23327,23374,23421,23468,23515,23562, - 23609,23656,23703,23750,23796,23843,23890,23937, - 23984,24030,24077,24124,24171,24217,24264,24311, - 24357,24404,24451,24497,24544,24591,24637,24684, - 24730,24777,24823,24870,24916,24963,25009,25056, - 25102,25149,25195,25241,25288,25334,25381,25427, - 25473,25520,25566,25612,25658,25705,25751,25797, - 25843,25889,25936,25982,26028,26074,26120,26166, - 26212,26258,26304,26350,26396,26442,26488,26534, - 26580,26626,26672,26718,26764,26810,26856,26902, - 26947,26993,27039,27085,27131,27176,27222,27268, - 27313,27359,27405,27450,27496,27542,27587,27633, - 27678,27724,27770,27815,27861,27906,27952,27997, - 28042,28088,28133,28179,28224,28269,28315,28360, - 28405,28451,28496,28541,28586,28632,28677,28722, - 28767,28812,28858,28903,28948,28993,29038,29083, - 29128,29173,29218,29263,29308,29353,29398,29443, - 29488,29533,29577,29622,29667,29712,29757,29801, - 29846,29891,29936,29980,30025,30070,30114,30159, - 30204,30248,30293,30337,30382,30427,30471,30516, - 30560,30604,30649,30693,30738,30782,30826,30871, - 30915,30959,31004,31048,31092,31136,31181,31225, - 31269,31313,31357,31402,31446,31490,31534,31578, - 31622,31666,31710,31754,31798,31842,31886,31930, - 31974,32017,32061,32105,32149,32193,32236,32280, - 32324,32368,32411,32455,32499,32542,32586,32630, - 32673,32717,32760,32804,32847,32891,32934,32978, - 33021,33065,33108,33151,33195,33238,33281,33325, - 33368,33411,33454,33498,33541,33584,33627,33670, - 33713,33756,33799,33843,33886,33929,33972,34015, - 34057,34100,34143,34186,34229,34272,34315,34358, - 34400,34443,34486,34529,34571,34614,34657,34699, - 34742,34785,34827,34870,34912,34955,34997,35040, - 35082,35125,35167,35210,35252,35294,35337,35379, - 35421,35464,35506,35548,35590,35633,35675,35717, - 35759,35801,35843,35885,35927,35969,36011,36053, - 36095,36137,36179,36221,36263,36305,36347,36388, - 36430,36472,36514,36556,36597,36639,36681,36722, - 36764,36805,36847,36889,36930,36972,37013,37055, - 37096,37137,37179,37220,37262,37303,37344,37386, - 37427,37468,37509,37551,37592,37633,37674,37715, - 37756,37797,37838,37879,37920,37961,38002,38043, - 38084,38125,38166,38207,38248,38288,38329,38370, - 38411,38451,38492,38533,38573,38614,38655,38695, - 38736,38776,38817,38857,38898,38938,38979,39019, - 39059,39100,39140,39180,39221,39261,39301,39341, - 39382,39422,39462,39502,39542,39582,39622,39662, - 39702,39742,39782,39822,39862,39902,39942,39982, - 40021,40061,40101,40141,40180,40220,40260,40299, - 40339,40379,40418,40458,40497,40537,40576,40616, - 40655,40695,40734,40773,40813,40852,40891,40931, - 40970,41009,41048,41087,41127,41166,41205,41244, - 41283,41322,41361,41400,41439,41478,41517,41556, - 41595,41633,41672,41711,41750,41788,41827,41866, - 41904,41943,41982,42020,42059,42097,42136,42174, - 42213,42251,42290,42328,42366,42405,42443,42481, - 42520,42558,42596,42634,42672,42711,42749,42787, - 42825,42863,42901,42939,42977,43015,43053,43091, - 43128,43166,43204,43242,43280,43317,43355,43393, - 43430,43468,43506,43543,43581,43618,43656,43693, - 43731,43768,43806,43843,43880,43918,43955,43992, - 44029,44067,44104,44141,44178,44215,44252,44289, - 44326,44363,44400,44437,44474,44511,44548,44585, - 44622,44659,44695,44732,44769,44806,44842,44879, - 44915,44952,44989,45025,45062,45098,45135,45171, - 45207,45244,45280,45316,45353,45389,45425,45462, - 45498,45534,45570,45606,45642,45678,45714,45750, - 45786,45822,45858,45894,45930,45966,46002,46037, - 46073,46109,46145,46180,46216,46252,46287,46323, - 46358,46394,46429,46465,46500,46536,46571,46606, - 46642,46677,46712,46747,46783,46818,46853,46888, - 46923,46958,46993,47028,47063,47098,47133,47168, - 47203,47238,47273,47308,47342,47377,47412,47446, - 47481,47516,47550,47585,47619,47654,47688,47723, - 47757,47792,47826,47861,47895,47929,47963,47998, - 48032,48066,48100,48134,48168,48202,48237,48271, - 48305,48338,48372,48406,48440,48474,48508,48542, - 48575,48609,48643,48676,48710,48744,48777,48811, - 48844,48878,48911,48945,48978,49012,49045,49078, - 49112,49145,49178,49211,49244,49278,49311,49344, - 49377,49410,49443,49476,49509,49542,49575,49608, - 49640,49673,49706,49739,49771,49804,49837,49869, - 49902,49935,49967,50000,50032,50064,50097,50129, - 50162,50194,50226,50259,50291,50323,50355,50387, - 50420,50452,50484,50516,50548,50580,50612,50644, - 50675,50707,50739,50771,50803,50834,50866,50898, - 50929,50961,50993,51024,51056,51087,51119,51150, - 51182,51213,51244,51276,51307,51338,51369,51401, - 51432,51463,51494,51525,51556,51587,51618,51649, - 51680,51711,51742,51773,51803,51834,51865,51896, - 51926,51957,51988,52018,52049,52079,52110,52140, - 52171,52201,52231,52262,52292,52322,52353,52383, - 52413,52443,52473,52503,52534,52564,52594,52624, - 52653,52683,52713,52743,52773,52803,52832,52862, - 52892,52922,52951,52981,53010,53040,53069,53099, - 53128,53158,53187,53216,53246,53275,53304,53334, - 53363,53392,53421,53450,53479,53508,53537,53566, - 53595,53624,53653,53682,53711,53739,53768,53797, - 53826,53854,53883,53912,53940,53969,53997,54026, - 54054,54082,54111,54139,54167,54196,54224,54252, - 54280,54309,54337,54365,54393,54421,54449,54477, - 54505,54533,54560,54588,54616,54644,54672,54699, - 54727,54755,54782,54810,54837,54865,54892,54920, - 54947,54974,55002,55029,55056,55084,55111,55138, - 55165,55192,55219,55246,55274,55300,55327,55354, - 55381,55408,55435,55462,55489,55515,55542,55569, - 55595,55622,55648,55675,55701,55728,55754,55781, - 55807,55833,55860,55886,55912,55938,55965,55991, - 56017,56043,56069,56095,56121,56147,56173,56199, - 56225,56250,56276,56302,56328,56353,56379,56404, - 56430,56456,56481,56507,56532,56557,56583,56608, - 56633,56659,56684,56709,56734,56760,56785,56810, - 56835,56860,56885,56910,56935,56959,56984,57009, - 57034,57059,57083,57108,57133,57157,57182,57206, - 57231,57255,57280,57304,57329,57353,57377,57402, - 57426,57450,57474,57498,57522,57546,57570,57594, - 57618,57642,57666,57690,57714,57738,57762,57785, - 57809,57833,57856,57880,57903,57927,57950,57974, - 57997,58021,58044,58067,58091,58114,58137,58160, - 58183,58207,58230,58253,58276,58299,58322,58345, - 58367,58390,58413,58436,58459,58481,58504,58527, - 58549,58572,58594,58617,58639,58662,58684,58706, - 58729,58751,58773,58795,58818,58840,58862,58884, - 58906,58928,58950,58972,58994,59016,59038,59059, - 59081,59103,59125,59146,59168,59190,59211,59233, - 59254,59276,59297,59318,59340,59361,59382,59404, - 59425,59446,59467,59488,59509,59530,59551,59572, - 59593,59614,59635,59656,59677,59697,59718,59739, - 59759,59780,59801,59821,59842,59862,59883,59903, - 59923,59944,59964,59984,60004,60025,60045,60065, - 60085,60105,60125,60145,60165,60185,60205,60225, - 60244,60264,60284,60304,60323,60343,60363,60382, - 60402,60421,60441,60460,60479,60499,60518,60537, - 60556,60576,60595,60614,60633,60652,60671,60690, - 60709,60728,60747,60766,60785,60803,60822,60841, - 60859,60878,60897,60915,60934,60952,60971,60989, - 61007,61026,61044,61062,61081,61099,61117,61135, - 61153,61171,61189,61207,61225,61243,61261,61279, - 61297,61314,61332,61350,61367,61385,61403,61420, - 61438,61455,61473,61490,61507,61525,61542,61559, - 61577,61594,61611,61628,61645,61662,61679,61696, - 61713,61730,61747,61764,61780,61797,61814,61831, - 61847,61864,61880,61897,61913,61930,61946,61963, - 61979,61995,62012,62028,62044,62060,62076,62092, - 62108,62125,62141,62156,62172,62188,62204,62220, - 62236,62251,62267,62283,62298,62314,62329,62345, - 62360,62376,62391,62407,62422,62437,62453,62468, - 62483,62498,62513,62528,62543,62558,62573,62588, - 62603,62618,62633,62648,62662,62677,62692,62706, - 62721,62735,62750,62764,62779,62793,62808,62822, - 62836,62850,62865,62879,62893,62907,62921,62935, - 62949,62963,62977,62991,63005,63019,63032,63046, - 63060,63074,63087,63101,63114,63128,63141,63155, - 63168,63182,63195,63208,63221,63235,63248,63261, - 63274,63287,63300,63313,63326,63339,63352,63365, - 63378,63390,63403,63416,63429,63441,63454,63466, - 63479,63491,63504,63516,63528,63541,63553,63565, - 63578,63590,63602,63614,63626,63638,63650,63662, - 63674,63686,63698,63709,63721,63733,63745,63756, - 63768,63779,63791,63803,63814,63825,63837,63848, - 63859,63871,63882,63893,63904,63915,63927,63938, - 63949,63960,63971,63981,63992,64003,64014,64025, - 64035,64046,64057,64067,64078,64088,64099,64109, - 64120,64130,64140,64151,64161,64171,64181,64192, - 64202,64212,64222,64232,64242,64252,64261,64271, - 64281,64291,64301,64310,64320,64330,64339,64349, - 64358,64368,64377,64387,64396,64405,64414,64424, - 64433,64442,64451,64460,64469,64478,64487,64496, - 64505,64514,64523,64532,64540,64549,64558,64566, - 64575,64584,64592,64600,64609,64617,64626,64634, - 64642,64651,64659,64667,64675,64683,64691,64699, - 64707,64715,64723,64731,64739,64747,64754,64762, - 64770,64777,64785,64793,64800,64808,64815,64822, - 64830,64837,64844,64852,64859,64866,64873,64880, - 64887,64895,64902,64908,64915,64922,64929,64936, - 64943,64949,64956,64963,64969,64976,64982,64989, - 64995,65002,65008,65015,65021,65027,65033,65040, - 65046,65052,65058,65064,65070,65076,65082,65088, - 65094,65099,65105,65111,65117,65122,65128,65133, - 65139,65144,65150,65155,65161,65166,65171,65177, - 65182,65187,65192,65197,65202,65207,65212,65217, - 65222,65227,65232,65237,65242,65246,65251,65256, - 65260,65265,65270,65274,65279,65283,65287,65292, - 65296,65300,65305,65309,65313,65317,65321,65325, - 65329,65333,65337,65341,65345,65349,65352,65356, - 65360,65363,65367,65371,65374,65378,65381,65385, - 65388,65391,65395,65398,65401,65404,65408,65411, - 65414,65417,65420,65423,65426,65429,65431,65434, - 65437,65440,65442,65445,65448,65450,65453,65455, - 65458,65460,65463,65465,65467,65470,65472,65474, - 65476,65478,65480,65482,65484,65486,65488,65490, - 65492,65494,65496,65497,65499,65501,65502,65504, - 65505,65507,65508,65510,65511,65513,65514,65515, - 65516,65518,65519,65520,65521,65522,65523,65524, - 65525,65526,65527,65527,65528,65529,65530,65530, - 65531,65531,65532,65532,65533,65533,65534,65534, - 65534,65535,65535,65535,65535,65535,65535,65535 -}; + { + 25, 75, 125, 175, 226, 276, 326, 376, + 427, 477, 527, 578, 628, 678, 728, 779, + 829, 879, 929, 980, 1030, 1080, 1130, 1181, + 1231, 1281, 1331, 1382, 1432, 1482, 1532, 1583, + 1633, 1683, 1733, 1784, 1834, 1884, 1934, 1985, + 2035, 2085, 2135, 2186, 2236, 2286, 2336, 2387, + 2437, 2487, 2537, 2587, 2638, 2688, 2738, 2788, + 2839, 2889, 2939, 2989, 3039, 3090, 3140, 3190, + 3240, 3291, 3341, 3391, 3441, 3491, 3541, 3592, + 3642, 3692, 3742, 3792, 3843, 3893, 3943, 3993, + 4043, 4093, 4144, 4194, 4244, 4294, 4344, 4394, + 4445, 4495, 4545, 4595, 4645, 4695, 4745, 4796, + 4846, 4896, 4946, 4996, 5046, 5096, 5146, 5197, + 5247, 5297, 5347, 5397, 5447, 5497, 5547, 5597, + 5647, 5697, 5748, 5798, 5848, 5898, 5948, 5998, + 6048, 6098, 6148, 6198, 6248, 6298, 6348, 6398, + 6448, 6498, 6548, 6598, 6648, 6698, 6748, 6798, + 6848, 6898, 6948, 6998, 7048, 7098, 7148, 7198, + 7248, 7298, 7348, 7398, 7448, 7498, 7548, 7598, + 7648, 7697, 7747, 7797, 7847, 7897, 7947, 7997, + 8047, 8097, 8147, 8196, 8246, 8296, 8346, 8396, + 8446, 8496, 8545, 8595, 8645, 8695, 8745, 8794, + 8844, 8894, 8944, 8994, 9043, 9093, 9143, 9193, + 9243, 9292, 9342, 9392, 9442, 9491, 9541, 9591, + 9640, 9690, 9740, 9790, 9839, 9889, 9939, 9988, + 10038, 10088, 10137, 10187, 10237, 10286, 10336, 10386, + 10435, 10485, 10534, 10584, 10634, 10683, 10733, 10782, + 10832, 10882, 10931, 10981, 11030, 11080, 11129, 11179, + 11228, 11278, 11327, 11377, 11426, 11476, 11525, 11575, + 11624, 11674, 11723, 11773, 11822, 11872, 11921, 11970, + 12020, 12069, 12119, 12168, 12218, 12267, 12316, 12366, + 12415, 12464, 12514, 12563, 12612, 12662, 12711, 12760, + 12810, 12859, 12908, 12957, 13007, 13056, 13105, 13154, + 13204, 13253, 13302, 13351, 13401, 13450, 13499, 13548, + 13597, 13647, 13696, 13745, 13794, 13843, 13892, 13941, + 13990, 14040, 14089, 14138, 14187, 14236, 14285, 14334, + 14383, 14432, 14481, 14530, 14579, 14628, 14677, 14726, + 14775, 14824, 14873, 14922, 14971, 15020, 15069, 15118, + 15167, 15215, 15264, 15313, 15362, 15411, 15460, 15509, + 15557, 15606, 15655, 15704, 15753, 15802, 15850, 15899, + 15948, 15997, 16045, 16094, 16143, 16191, 16240, 16289, + 16338, 16386, 16435, 16484, 16532, 16581, 16629, 16678, + 16727, 16775, 16824, 16872, 16921, 16970, 17018, 17067, + 17115, 17164, 17212, 17261, 17309, 17358, 17406, 17455, + 17503, 17551, 17600, 17648, 17697, 17745, 17793, 17842, + 17890, 17939, 17987, 18035, 18084, 18132, 18180, 18228, + 18277, 18325, 18373, 18421, 18470, 18518, 18566, 18614, + 18663, 18711, 18759, 18807, 18855, 18903, 18951, 19000, + 19048, 19096, 19144, 19192, 19240, 19288, 19336, 19384, + 19432, 19480, 19528, 19576, 19624, 19672, 19720, 19768, + 19816, 19864, 19912, 19959, 20007, 20055, 20103, 20151, + 20199, 20246, 20294, 20342, 20390, 20438, 20485, 20533, + 20581, 20629, 20676, 20724, 20772, 20819, 20867, 20915, + 20962, 21010, 21057, 21105, 21153, 21200, 21248, 21295, + 21343, 21390, 21438, 21485, 21533, 21580, 21628, 21675, + 21723, 21770, 21817, 21865, 21912, 21960, 22007, 22054, + 22102, 22149, 22196, 22243, 22291, 22338, 22385, 22433, + 22480, 22527, 22574, 22621, 22668, 22716, 22763, 22810, + 22857, 22904, 22951, 22998, 23045, 23092, 23139, 23186, + 23233, 23280, 23327, 23374, 23421, 23468, 23515, 23562, + 23609, 23656, 23703, 23750, 23796, 23843, 23890, 23937, + 23984, 24030, 24077, 24124, 24171, 24217, 24264, 24311, + 24357, 24404, 24451, 24497, 24544, 24591, 24637, 24684, + 24730, 24777, 24823, 24870, 24916, 24963, 25009, 25056, + 25102, 25149, 25195, 25241, 25288, 25334, 25381, 25427, + 25473, 25520, 25566, 25612, 25658, 25705, 25751, 25797, + 25843, 25889, 25936, 25982, 26028, 26074, 26120, 26166, + 26212, 26258, 26304, 26350, 26396, 26442, 26488, 26534, + 26580, 26626, 26672, 26718, 26764, 26810, 26856, 26902, + 26947, 26993, 27039, 27085, 27131, 27176, 27222, 27268, + 27313, 27359, 27405, 27450, 27496, 27542, 27587, 27633, + 27678, 27724, 27770, 27815, 27861, 27906, 27952, 27997, + 28042, 28088, 28133, 28179, 28224, 28269, 28315, 28360, + 28405, 28451, 28496, 28541, 28586, 28632, 28677, 28722, + 28767, 28812, 28858, 28903, 28948, 28993, 29038, 29083, + 29128, 29173, 29218, 29263, 29308, 29353, 29398, 29443, + 29488, 29533, 29577, 29622, 29667, 29712, 29757, 29801, + 29846, 29891, 29936, 29980, 30025, 30070, 30114, 30159, + 30204, 30248, 30293, 30337, 30382, 30426, 30471, 30515, + 30560, 30604, 30649, 30693, 30738, 30782, 30826, 30871, + 30915, 30959, 31004, 31048, 31092, 31136, 31181, 31225, + 31269, 31313, 31357, 31402, 31446, 31490, 31534, 31578, + 31622, 31666, 31710, 31754, 31798, 31842, 31886, 31930, + 31974, 32017, 32061, 32105, 32149, 32193, 32236, 32280, + 32324, 32368, 32411, 32455, 32499, 32542, 32586, 32630, + 32673, 32717, 32760, 32804, 32847, 32891, 32934, 32978, + 33021, 33065, 33108, 33151, 33195, 33238, 33281, 33325, + 33368, 33411, 33454, 33498, 33541, 33584, 33627, 33670, + 33713, 33756, 33799, 33843, 33886, 33929, 33972, 34015, + 34057, 34100, 34143, 34186, 34229, 34272, 34315, 34358, + 34400, 34443, 34486, 34529, 34571, 34614, 34657, 34699, + 34742, 34785, 34827, 34870, 34912, 34955, 34997, 35040, + 35082, 35125, 35167, 35210, 35252, 35294, 35337, 35379, + 35421, 35464, 35506, 35548, 35590, 35633, 35675, 35717, + 35759, 35801, 35843, 35885, 35927, 35969, 36011, 36053, + 36095, 36137, 36179, 36221, 36263, 36305, 36347, 36388, + 36430, 36472, 36514, 36555, 36597, 36639, 36681, 36722, + 36764, 36805, 36847, 36889, 36930, 36972, 37013, 37055, + 37096, 37137, 37179, 37220, 37262, 37303, 37344, 37386, + 37427, 37468, 37509, 37551, 37592, 37633, 37674, 37715, + 37756, 37797, 37838, 37879, 37920, 37961, 38002, 38043, + 38084, 38125, 38166, 38207, 38248, 38288, 38329, 38370, + 38411, 38451, 38492, 38533, 38573, 38614, 38655, 38695, + 38736, 38776, 38817, 38857, 38898, 38938, 38979, 39019, + 39059, 39100, 39140, 39180, 39221, 39261, 39301, 39341, + 39382, 39422, 39462, 39502, 39542, 39582, 39622, 39662, + 39702, 39742, 39782, 39822, 39862, 39902, 39942, 39982, + 40021, 40061, 40101, 40141, 40180, 40220, 40260, 40300, + 40339, 40379, 40418, 40458, 40497, 40537, 40576, 40616, + 40655, 40695, 40734, 40773, 40813, 40852, 40891, 40931, + 40970, 41009, 41048, 41087, 41127, 41166, 41205, 41244, + 41283, 41322, 41361, 41400, 41439, 41478, 41517, 41556, + 41595, 41633, 41672, 41711, 41750, 41788, 41827, 41866, + 41904, 41943, 41982, 42020, 42059, 42097, 42136, 42174, + 42213, 42251, 42290, 42328, 42366, 42405, 42443, 42481, + 42520, 42558, 42596, 42634, 42672, 42711, 42749, 42787, + 42825, 42863, 42901, 42939, 42977, 43015, 43053, 43091, + 43128, 43166, 43204, 43242, 43280, 43317, 43355, 43393, + 43430, 43468, 43506, 43543, 43581, 43618, 43656, 43693, + 43731, 43768, 43806, 43843, 43880, 43918, 43955, 43992, + 44029, 44067, 44104, 44141, 44178, 44215, 44252, 44289, + 44326, 44363, 44400, 44437, 44474, 44511, 44548, 44585, + 44622, 44659, 44695, 44732, 44769, 44806, 44842, 44879, + 44915, 44952, 44989, 45025, 45062, 45098, 45135, 45171, + 45207, 45244, 45280, 45316, 45353, 45389, 45425, 45462, + 45498, 45534, 45570, 45606, 45642, 45678, 45714, 45750, + 45786, 45822, 45858, 45894, 45930, 45966, 46002, 46037, + 46073, 46109, 46145, 46180, 46216, 46252, 46287, 46323, + 46358, 46394, 46429, 46465, 46500, 46536, 46571, 46606, + 46642, 46677, 46712, 46747, 46783, 46818, 46853, 46888, + 46923, 46958, 46993, 47028, 47063, 47098, 47133, 47168, + 47203, 47238, 47273, 47308, 47342, 47377, 47412, 47446, + 47481, 47516, 47550, 47585, 47619, 47654, 47688, 47723, + 47757, 47792, 47826, 47860, 47895, 47929, 47963, 47998, + 48032, 48066, 48100, 48134, 48168, 48202, 48237, 48271, + 48305, 48338, 48372, 48406, 48440, 48474, 48508, 48542, + 48575, 48609, 48643, 48676, 48710, 48744, 48777, 48811, + 48844, 48878, 48911, 48945, 48978, 49012, 49045, 49078, + 49112, 49145, 49178, 49211, 49244, 49278, 49311, 49344, + 49377, 49410, 49443, 49476, 49509, 49542, 49575, 49608, + 49640, 49673, 49706, 49739, 49771, 49804, 49837, 49869, + 49902, 49935, 49967, 50000, 50032, 50065, 50097, 50129, + 50162, 50194, 50226, 50259, 50291, 50323, 50355, 50387, + 50420, 50452, 50484, 50516, 50548, 50580, 50612, 50644, + 50675, 50707, 50739, 50771, 50803, 50834, 50866, 50898, + 50929, 50961, 50993, 51024, 51056, 51087, 51119, 51150, + 51182, 51213, 51244, 51276, 51307, 51338, 51369, 51401, + 51432, 51463, 51494, 51525, 51556, 51587, 51618, 51649, + 51680, 51711, 51742, 51773, 51803, 51834, 51865, 51896, + 51926, 51957, 51988, 52018, 52049, 52079, 52110, 52140, + 52171, 52201, 52231, 52262, 52292, 52322, 52353, 52383, + 52413, 52443, 52473, 52503, 52534, 52564, 52594, 52624, + 52653, 52683, 52713, 52743, 52773, 52803, 52832, 52862, + 52892, 52922, 52951, 52981, 53010, 53040, 53069, 53099, + 53128, 53158, 53187, 53216, 53246, 53275, 53304, 53334, + 53363, 53392, 53421, 53450, 53479, 53508, 53537, 53566, + 53595, 53624, 53653, 53682, 53711, 53739, 53768, 53797, + 53826, 53854, 53883, 53911, 53940, 53969, 53997, 54026, + 54054, 54082, 54111, 54139, 54167, 54196, 54224, 54252, + 54280, 54308, 54337, 54365, 54393, 54421, 54449, 54477, + 54505, 54533, 54560, 54588, 54616, 54644, 54672, 54699, + 54727, 54755, 54782, 54810, 54837, 54865, 54892, 54920, + 54947, 54974, 55002, 55029, 55056, 55084, 55111, 55138, + 55165, 55192, 55219, 55246, 55274, 55300, 55327, 55354, + 55381, 55408, 55435, 55462, 55489, 55515, 55542, 55569, + 55595, 55622, 55648, 55675, 55701, 55728, 55754, 55781, + 55807, 55833, 55860, 55886, 55912, 55938, 55965, 55991, + 56017, 56043, 56069, 56095, 56121, 56147, 56173, 56199, + 56225, 56250, 56276, 56302, 56328, 56353, 56379, 56404, + 56430, 56456, 56481, 56507, 56532, 56557, 56583, 56608, + 56633, 56659, 56684, 56709, 56734, 56760, 56785, 56810, + 56835, 56860, 56885, 56910, 56935, 56959, 56984, 57009, + 57034, 57059, 57083, 57108, 57133, 57157, 57182, 57206, + 57231, 57255, 57280, 57304, 57329, 57353, 57377, 57402, + 57426, 57450, 57474, 57498, 57522, 57546, 57570, 57594, + 57618, 57642, 57666, 57690, 57714, 57738, 57762, 57785, + 57809, 57833, 57856, 57880, 57903, 57927, 57950, 57974, + 57997, 58021, 58044, 58067, 58091, 58114, 58137, 58160, + 58183, 58207, 58230, 58253, 58276, 58299, 58322, 58345, + 58367, 58390, 58413, 58436, 58459, 58481, 58504, 58527, + 58549, 58572, 58594, 58617, 58639, 58662, 58684, 58706, + 58729, 58751, 58773, 58795, 58818, 58840, 58862, 58884, + 58906, 58928, 58950, 58972, 58994, 59016, 59038, 59059, + 59081, 59103, 59125, 59146, 59168, 59190, 59211, 59233, + 59254, 59276, 59297, 59318, 59340, 59361, 59382, 59404, + 59425, 59446, 59467, 59488, 59509, 59530, 59551, 59572, + 59593, 59614, 59635, 59656, 59677, 59697, 59718, 59739, + 59759, 59780, 59801, 59821, 59842, 59862, 59883, 59903, + 59923, 59944, 59964, 59984, 60004, 60025, 60045, 60065, + 60085, 60105, 60125, 60145, 60165, 60185, 60205, 60225, + 60244, 60264, 60284, 60304, 60323, 60343, 60363, 60382, + 60402, 60421, 60441, 60460, 60479, 60499, 60518, 60537, + 60556, 60576, 60595, 60614, 60633, 60652, 60671, 60690, + 60709, 60728, 60747, 60766, 60785, 60803, 60822, 60841, + 60859, 60878, 60897, 60915, 60934, 60952, 60971, 60989, + 61007, 61026, 61044, 61062, 61081, 61099, 61117, 61135, + 61153, 61171, 61189, 61207, 61225, 61243, 61261, 61279, + 61297, 61314, 61332, 61350, 61367, 61385, 61403, 61420, + 61438, 61455, 61473, 61490, 61507, 61525, 61542, 61559, + 61577, 61594, 61611, 61628, 61645, 61662, 61679, 61696, + 61713, 61730, 61747, 61764, 61780, 61797, 61814, 61831, + 61847, 61864, 61880, 61897, 61913, 61930, 61946, 61963, + 61979, 61995, 62012, 62028, 62044, 62060, 62076, 62092, + 62108, 62125, 62141, 62156, 62172, 62188, 62204, 62220, + 62236, 62251, 62267, 62283, 62298, 62314, 62329, 62345, + 62360, 62376, 62391, 62407, 62422, 62437, 62453, 62468, + 62483, 62498, 62513, 62528, 62543, 62558, 62573, 62588, + 62603, 62618, 62633, 62648, 62662, 62677, 62692, 62706, + 62721, 62735, 62750, 62764, 62779, 62793, 62808, 62822, + 62836, 62850, 62865, 62879, 62893, 62907, 62921, 62935, + 62949, 62963, 62977, 62991, 63005, 63019, 63032, 63046, + 63060, 63074, 63087, 63101, 63114, 63128, 63141, 63155, + 63168, 63182, 63195, 63208, 63221, 63235, 63248, 63261, + 63274, 63287, 63300, 63313, 63326, 63339, 63352, 63365, + 63378, 63390, 63403, 63416, 63429, 63441, 63454, 63466, + 63479, 63491, 63504, 63516, 63528, 63541, 63553, 63565, + 63578, 63590, 63602, 63614, 63626, 63638, 63650, 63662, + 63674, 63686, 63698, 63709, 63721, 63733, 63745, 63756, + 63768, 63779, 63791, 63803, 63814, 63825, 63837, 63848, + 63859, 63871, 63882, 63893, 63904, 63915, 63927, 63938, + 63949, 63960, 63971, 63981, 63992, 64003, 64014, 64025, + 64035, 64046, 64057, 64067, 64078, 64088, 64099, 64109, + 64120, 64130, 64140, 64151, 64161, 64171, 64181, 64192, + 64202, 64212, 64222, 64232, 64242, 64252, 64261, 64271, + 64281, 64291, 64301, 64310, 64320, 64330, 64339, 64349, + 64358, 64368, 64377, 64387, 64396, 64405, 64414, 64424, + 64433, 64442, 64451, 64460, 64469, 64478, 64487, 64496, + 64505, 64514, 64523, 64532, 64540, 64549, 64558, 64566, + 64575, 64584, 64592, 64601, 64609, 64617, 64626, 64634, + 64642, 64651, 64659, 64667, 64675, 64683, 64691, 64699, + 64707, 64715, 64723, 64731, 64739, 64747, 64754, 64762, + 64770, 64777, 64785, 64793, 64800, 64808, 64815, 64822, + 64830, 64837, 64844, 64852, 64859, 64866, 64873, 64880, + 64887, 64895, 64902, 64908, 64915, 64922, 64929, 64936, + 64943, 64949, 64956, 64963, 64969, 64976, 64982, 64989, + 64995, 65002, 65008, 65015, 65021, 65027, 65033, 65040, + 65046, 65052, 65058, 65064, 65070, 65076, 65082, 65088, + 65094, 65099, 65105, 65111, 65117, 65122, 65128, 65133, + 65139, 65144, 65150, 65155, 65161, 65166, 65171, 65177, + 65182, 65187, 65192, 65197, 65202, 65207, 65212, 65217, + 65222, 65227, 65232, 65237, 65242, 65246, 65251, 65256, + 65260, 65265, 65270, 65274, 65279, 65283, 65287, 65292, + 65296, 65300, 65305, 65309, 65313, 65317, 65321, 65325, + 65329, 65333, 65337, 65341, 65345, 65349, 65352, 65356, + 65360, 65363, 65367, 65371, 65374, 65378, 65381, 65385, + 65388, 65391, 65395, 65398, 65401, 65404, 65408, 65411, + 65414, 65417, 65420, 65423, 65426, 65429, 65431, 65434, + 65437, 65440, 65442, 65445, 65448, 65450, 65453, 65455, + 65458, 65460, 65463, 65465, 65467, 65470, 65472, 65474, + 65476, 65478, 65480, 65482, 65484, 65486, 65488, 65490, + 65492, 65494, 65496, 65497, 65499, 65501, 65502, 65504, + 65505, 65507, 65508, 65510, 65511, 65513, 65514, 65515, + 65516, 65518, 65519, 65520, 65521, 65522, 65523, 65524, + 65525, 65526, 65527, 65527, 65528, 65529, 65530, 65530, + 65531, 65531, 65532, 65532, 65533, 65533, 65534, 65534, + 65534, 65535, 65535, 65535, 65535, 65535, 65535, 65535, + 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65534, + 65534, 65534, 65533, 65533, 65532, 65532, 65531, 65531, + 65530, 65530, 65529, 65528, 65527, 65527, 65526, 65525, + 65524, 65523, 65522, 65521, 65520, 65519, 65518, 65516, + 65515, 65514, 65513, 65511, 65510, 65508, 65507, 65505, + 65504, 65502, 65501, 65499, 65497, 65496, 65494, 65492, + 65490, 65488, 65486, 65484, 65482, 65480, 65478, 65476, + 65474, 65472, 65470, 65467, 65465, 65463, 65460, 65458, + 65455, 65453, 65450, 65448, 65445, 65442, 65440, 65437, + 65434, 65431, 65429, 65426, 65423, 65420, 65417, 65414, + 65411, 65408, 65404, 65401, 65398, 65395, 65391, 65388, + 65385, 65381, 65378, 65374, 65371, 65367, 65363, 65360, + 65356, 65352, 65349, 65345, 65341, 65337, 65333, 65329, + 65325, 65321, 65317, 65313, 65309, 65305, 65300, 65296, + 65292, 65287, 65283, 65279, 65274, 65270, 65265, 65260, + 65256, 65251, 65246, 65242, 65237, 65232, 65227, 65222, + 65217, 65212, 65207, 65202, 65197, 65192, 65187, 65182, + 65177, 65171, 65166, 65161, 65155, 65150, 65144, 65139, + 65133, 65128, 65122, 65117, 65111, 65105, 65099, 65094, + 65088, 65082, 65076, 65070, 65064, 65058, 65052, 65046, + 65040, 65033, 65027, 65021, 65015, 65008, 65002, 64995, + 64989, 64982, 64976, 64969, 64963, 64956, 64949, 64943, + 64936, 64929, 64922, 64915, 64908, 64902, 64895, 64887, + 64880, 64873, 64866, 64859, 64852, 64844, 64837, 64830, + 64822, 64815, 64808, 64800, 64793, 64785, 64777, 64770, + 64762, 64754, 64747, 64739, 64731, 64723, 64715, 64707, + 64699, 64691, 64683, 64675, 64667, 64659, 64651, 64642, + 64634, 64626, 64617, 64609, 64600, 64592, 64584, 64575, + 64566, 64558, 64549, 64540, 64532, 64523, 64514, 64505, + 64496, 64487, 64478, 64469, 64460, 64451, 64442, 64433, + 64424, 64414, 64405, 64396, 64387, 64377, 64368, 64358, + 64349, 64339, 64330, 64320, 64310, 64301, 64291, 64281, + 64271, 64261, 64252, 64242, 64232, 64222, 64212, 64202, + 64192, 64181, 64171, 64161, 64151, 64140, 64130, 64120, + 64109, 64099, 64088, 64078, 64067, 64057, 64046, 64035, + 64025, 64014, 64003, 63992, 63981, 63971, 63960, 63949, + 63938, 63927, 63915, 63904, 63893, 63882, 63871, 63859, + 63848, 63837, 63825, 63814, 63803, 63791, 63779, 63768, + 63756, 63745, 63733, 63721, 63709, 63698, 63686, 63674, + 63662, 63650, 63638, 63626, 63614, 63602, 63590, 63578, + 63565, 63553, 63541, 63528, 63516, 63504, 63491, 63479, + 63466, 63454, 63441, 63429, 63416, 63403, 63390, 63378, + 63365, 63352, 63339, 63326, 63313, 63300, 63287, 63274, + 63261, 63248, 63235, 63221, 63208, 63195, 63182, 63168, + 63155, 63141, 63128, 63114, 63101, 63087, 63074, 63060, + 63046, 63032, 63019, 63005, 62991, 62977, 62963, 62949, + 62935, 62921, 62907, 62893, 62879, 62865, 62850, 62836, + 62822, 62808, 62793, 62779, 62764, 62750, 62735, 62721, + 62706, 62692, 62677, 62662, 62648, 62633, 62618, 62603, + 62588, 62573, 62558, 62543, 62528, 62513, 62498, 62483, + 62468, 62453, 62437, 62422, 62407, 62391, 62376, 62360, + 62345, 62329, 62314, 62298, 62283, 62267, 62251, 62236, + 62220, 62204, 62188, 62172, 62156, 62141, 62125, 62108, + 62092, 62076, 62060, 62044, 62028, 62012, 61995, 61979, + 61963, 61946, 61930, 61913, 61897, 61880, 61864, 61847, + 61831, 61814, 61797, 61780, 61764, 61747, 61730, 61713, + 61696, 61679, 61662, 61645, 61628, 61611, 61594, 61577, + 61559, 61542, 61525, 61507, 61490, 61473, 61455, 61438, + 61420, 61403, 61385, 61367, 61350, 61332, 61314, 61297, + 61279, 61261, 61243, 61225, 61207, 61189, 61171, 61153, + 61135, 61117, 61099, 61081, 61062, 61044, 61026, 61007, + 60989, 60971, 60952, 60934, 60915, 60897, 60878, 60859, + 60841, 60822, 60803, 60785, 60766, 60747, 60728, 60709, + 60690, 60671, 60652, 60633, 60614, 60595, 60576, 60556, + 60537, 60518, 60499, 60479, 60460, 60441, 60421, 60402, + 60382, 60363, 60343, 60323, 60304, 60284, 60264, 60244, + 60225, 60205, 60185, 60165, 60145, 60125, 60105, 60085, + 60065, 60045, 60025, 60004, 59984, 59964, 59944, 59923, + 59903, 59883, 59862, 59842, 59821, 59801, 59780, 59759, + 59739, 59718, 59697, 59677, 59656, 59635, 59614, 59593, + 59572, 59551, 59530, 59509, 59488, 59467, 59446, 59425, + 59404, 59382, 59361, 59340, 59318, 59297, 59276, 59254, + 59233, 59211, 59190, 59168, 59146, 59125, 59103, 59081, + 59059, 59038, 59016, 58994, 58972, 58950, 58928, 58906, + 58884, 58862, 58840, 58818, 58795, 58773, 58751, 58729, + 58706, 58684, 58662, 58639, 58617, 58594, 58572, 58549, + 58527, 58504, 58481, 58459, 58436, 58413, 58390, 58367, + 58345, 58322, 58299, 58276, 58253, 58230, 58207, 58183, + 58160, 58137, 58114, 58091, 58067, 58044, 58021, 57997, + 57974, 57950, 57927, 57903, 57880, 57856, 57833, 57809, + 57785, 57762, 57738, 57714, 57690, 57666, 57642, 57618, + 57594, 57570, 57546, 57522, 57498, 57474, 57450, 57426, + 57402, 57377, 57353, 57329, 57304, 57280, 57255, 57231, + 57206, 57182, 57157, 57133, 57108, 57083, 57059, 57034, + 57009, 56984, 56959, 56935, 56910, 56885, 56860, 56835, + 56810, 56785, 56760, 56734, 56709, 56684, 56659, 56633, + 56608, 56583, 56557, 56532, 56507, 56481, 56456, 56430, + 56404, 56379, 56353, 56328, 56302, 56276, 56250, 56225, + 56199, 56173, 56147, 56121, 56095, 56069, 56043, 56017, + 55991, 55965, 55938, 55912, 55886, 55860, 55833, 55807, + 55781, 55754, 55728, 55701, 55675, 55648, 55622, 55595, + 55569, 55542, 55515, 55489, 55462, 55435, 55408, 55381, + 55354, 55327, 55300, 55274, 55246, 55219, 55192, 55165, + 55138, 55111, 55084, 55056, 55029, 55002, 54974, 54947, + 54920, 54892, 54865, 54837, 54810, 54782, 54755, 54727, + 54699, 54672, 54644, 54616, 54588, 54560, 54533, 54505, + 54477, 54449, 54421, 54393, 54365, 54337, 54308, 54280, + 54252, 54224, 54196, 54167, 54139, 54111, 54082, 54054, + 54026, 53997, 53969, 53940, 53911, 53883, 53854, 53826, + 53797, 53768, 53739, 53711, 53682, 53653, 53624, 53595, + 53566, 53537, 53508, 53479, 53450, 53421, 53392, 53363, + 53334, 53304, 53275, 53246, 53216, 53187, 53158, 53128, + 53099, 53069, 53040, 53010, 52981, 52951, 52922, 52892, + 52862, 52832, 52803, 52773, 52743, 52713, 52683, 52653, + 52624, 52594, 52564, 52534, 52503, 52473, 52443, 52413, + 52383, 52353, 52322, 52292, 52262, 52231, 52201, 52171, + 52140, 52110, 52079, 52049, 52018, 51988, 51957, 51926, + 51896, 51865, 51834, 51803, 51773, 51742, 51711, 51680, + 51649, 51618, 51587, 51556, 51525, 51494, 51463, 51432, + 51401, 51369, 51338, 51307, 51276, 51244, 51213, 51182, + 51150, 51119, 51087, 51056, 51024, 50993, 50961, 50929, + 50898, 50866, 50834, 50803, 50771, 50739, 50707, 50675, + 50644, 50612, 50580, 50548, 50516, 50484, 50452, 50420, + 50387, 50355, 50323, 50291, 50259, 50226, 50194, 50162, + 50129, 50097, 50065, 50032, 50000, 49967, 49935, 49902, + 49869, 49837, 49804, 49771, 49739, 49706, 49673, 49640, + 49608, 49575, 49542, 49509, 49476, 49443, 49410, 49377, + 49344, 49311, 49278, 49244, 49211, 49178, 49145, 49112, + 49078, 49045, 49012, 48978, 48945, 48911, 48878, 48844, + 48811, 48777, 48744, 48710, 48676, 48643, 48609, 48575, + 48542, 48508, 48474, 48440, 48406, 48372, 48338, 48304, + 48271, 48237, 48202, 48168, 48134, 48100, 48066, 48032, + 47998, 47963, 47929, 47895, 47860, 47826, 47792, 47757, + 47723, 47688, 47654, 47619, 47585, 47550, 47516, 47481, + 47446, 47412, 47377, 47342, 47308, 47273, 47238, 47203, + 47168, 47133, 47098, 47063, 47028, 46993, 46958, 46923, + 46888, 46853, 46818, 46783, 46747, 46712, 46677, 46642, + 46606, 46571, 46536, 46500, 46465, 46429, 46394, 46358, + 46323, 46287, 46252, 46216, 46180, 46145, 46109, 46073, + 46037, 46002, 45966, 45930, 45894, 45858, 45822, 45786, + 45750, 45714, 45678, 45642, 45606, 45570, 45534, 45498, + 45462, 45425, 45389, 45353, 45316, 45280, 45244, 45207, + 45171, 45135, 45098, 45062, 45025, 44989, 44952, 44915, + 44879, 44842, 44806, 44769, 44732, 44695, 44659, 44622, + 44585, 44548, 44511, 44474, 44437, 44400, 44363, 44326, + 44289, 44252, 44215, 44178, 44141, 44104, 44067, 44029, + 43992, 43955, 43918, 43880, 43843, 43806, 43768, 43731, + 43693, 43656, 43618, 43581, 43543, 43506, 43468, 43430, + 43393, 43355, 43317, 43280, 43242, 43204, 43166, 43128, + 43091, 43053, 43015, 42977, 42939, 42901, 42863, 42825, + 42787, 42749, 42711, 42672, 42634, 42596, 42558, 42520, + 42481, 42443, 42405, 42366, 42328, 42290, 42251, 42213, + 42174, 42136, 42097, 42059, 42020, 41982, 41943, 41904, + 41866, 41827, 41788, 41750, 41711, 41672, 41633, 41595, + 41556, 41517, 41478, 41439, 41400, 41361, 41322, 41283, + 41244, 41205, 41166, 41127, 41088, 41048, 41009, 40970, + 40931, 40891, 40852, 40813, 40773, 40734, 40695, 40655, + 40616, 40576, 40537, 40497, 40458, 40418, 40379, 40339, + 40300, 40260, 40220, 40180, 40141, 40101, 40061, 40021, + 39982, 39942, 39902, 39862, 39822, 39782, 39742, 39702, + 39662, 39622, 39582, 39542, 39502, 39462, 39422, 39382, + 39341, 39301, 39261, 39221, 39180, 39140, 39100, 39059, + 39019, 38979, 38938, 38898, 38857, 38817, 38776, 38736, + 38695, 38655, 38614, 38573, 38533, 38492, 38451, 38411, + 38370, 38329, 38288, 38248, 38207, 38166, 38125, 38084, + 38043, 38002, 37961, 37920, 37879, 37838, 37797, 37756, + 37715, 37674, 37633, 37592, 37551, 37509, 37468, 37427, + 37386, 37344, 37303, 37262, 37220, 37179, 37137, 37096, + 37055, 37013, 36972, 36930, 36889, 36847, 36805, 36764, + 36722, 36681, 36639, 36597, 36556, 36514, 36472, 36430, + 36388, 36347, 36305, 36263, 36221, 36179, 36137, 36095, + 36053, 36011, 35969, 35927, 35885, 35843, 35801, 35759, + 35717, 35675, 35633, 35590, 35548, 35506, 35464, 35421, + 35379, 35337, 35294, 35252, 35210, 35167, 35125, 35082, + 35040, 34997, 34955, 34912, 34870, 34827, 34785, 34742, + 34699, 34657, 34614, 34571, 34529, 34486, 34443, 34400, + 34358, 34315, 34272, 34229, 34186, 34143, 34100, 34057, + 34015, 33972, 33929, 33886, 33843, 33799, 33756, 33713, + 33670, 33627, 33584, 33541, 33498, 33454, 33411, 33368, + 33325, 33281, 33238, 33195, 33151, 33108, 33065, 33021, + 32978, 32934, 32891, 32847, 32804, 32760, 32717, 32673, + 32630, 32586, 32542, 32499, 32455, 32411, 32368, 32324, + 32280, 32236, 32193, 32149, 32105, 32061, 32017, 31974, + 31930, 31886, 31842, 31798, 31754, 31710, 31666, 31622, + 31578, 31534, 31490, 31446, 31402, 31357, 31313, 31269, + 31225, 31181, 31136, 31092, 31048, 31004, 30959, 30915, + 30871, 30826, 30782, 30738, 30693, 30649, 30604, 30560, + 30515, 30471, 30426, 30382, 30337, 30293, 30248, 30204, + 30159, 30114, 30070, 30025, 29980, 29936, 29891, 29846, + 29801, 29757, 29712, 29667, 29622, 29577, 29533, 29488, + 29443, 29398, 29353, 29308, 29263, 29218, 29173, 29128, + 29083, 29038, 28993, 28948, 28903, 28858, 28812, 28767, + 28722, 28677, 28632, 28586, 28541, 28496, 28451, 28405, + 28360, 28315, 28269, 28224, 28179, 28133, 28088, 28042, + 27997, 27952, 27906, 27861, 27815, 27770, 27724, 27678, + 27633, 27587, 27542, 27496, 27450, 27405, 27359, 27313, + 27268, 27222, 27176, 27131, 27085, 27039, 26993, 26947, + 26902, 26856, 26810, 26764, 26718, 26672, 26626, 26580, + 26534, 26488, 26442, 26396, 26350, 26304, 26258, 26212, + 26166, 26120, 26074, 26028, 25982, 25936, 25889, 25843, + 25797, 25751, 25705, 25658, 25612, 25566, 25520, 25473, + 25427, 25381, 25334, 25288, 25241, 25195, 25149, 25102, + 25056, 25009, 24963, 24916, 24870, 24823, 24777, 24730, + 24684, 24637, 24591, 24544, 24497, 24451, 24404, 24357, + 24311, 24264, 24217, 24171, 24124, 24077, 24030, 23984, + 23937, 23890, 23843, 23796, 23750, 23703, 23656, 23609, + 23562, 23515, 23468, 23421, 23374, 23327, 23280, 23233, + 23186, 23139, 23092, 23045, 22998, 22951, 22904, 22857, + 22810, 22763, 22716, 22668, 22621, 22574, 22527, 22480, + 22433, 22385, 22338, 22291, 22243, 22196, 22149, 22102, + 22054, 22007, 21960, 21912, 21865, 21817, 21770, 21723, + 21675, 21628, 21580, 21533, 21485, 21438, 21390, 21343, + 21295, 21248, 21200, 21153, 21105, 21057, 21010, 20962, + 20915, 20867, 20819, 20772, 20724, 20676, 20629, 20581, + 20533, 20485, 20438, 20390, 20342, 20294, 20246, 20199, + 20151, 20103, 20055, 20007, 19959, 19912, 19864, 19816, + 19768, 19720, 19672, 19624, 19576, 19528, 19480, 19432, + 19384, 19336, 19288, 19240, 19192, 19144, 19096, 19048, + 19000, 18951, 18903, 18855, 18807, 18759, 18711, 18663, + 18614, 18566, 18518, 18470, 18421, 18373, 18325, 18277, + 18228, 18180, 18132, 18084, 18035, 17987, 17939, 17890, + 17842, 17793, 17745, 17697, 17648, 17600, 17551, 17503, + 17455, 17406, 17358, 17309, 17261, 17212, 17164, 17115, + 17067, 17018, 16970, 16921, 16872, 16824, 16775, 16727, + 16678, 16629, 16581, 16532, 16484, 16435, 16386, 16338, + 16289, 16240, 16191, 16143, 16094, 16045, 15997, 15948, + 15899, 15850, 15802, 15753, 15704, 15655, 15606, 15557, + 15509, 15460, 15411, 15362, 15313, 15264, 15215, 15167, + 15118, 15069, 15020, 14971, 14922, 14873, 14824, 14775, + 14726, 14677, 14628, 14579, 14530, 14481, 14432, 14383, + 14334, 14285, 14236, 14187, 14138, 14089, 14040, 13990, + 13941, 13892, 13843, 13794, 13745, 13696, 13646, 13597, + 13548, 13499, 13450, 13401, 13351, 13302, 13253, 13204, + 13154, 13105, 13056, 13007, 12957, 12908, 12859, 12810, + 12760, 12711, 12662, 12612, 12563, 12514, 12464, 12415, + 12366, 12316, 12267, 12218, 12168, 12119, 12069, 12020, + 11970, 11921, 11872, 11822, 11773, 11723, 11674, 11624, + 11575, 11525, 11476, 11426, 11377, 11327, 11278, 11228, + 11179, 11129, 11080, 11030, 10981, 10931, 10882, 10832, + 10782, 10733, 10683, 10634, 10584, 10534, 10485, 10435, + 10386, 10336, 10286, 10237, 10187, 10137, 10088, 10038, + 9988, 9939, 9889, 9839, 9790, 9740, 9690, 9640, + 9591, 9541, 9491, 9442, 9392, 9342, 9292, 9243, + 9193, 9143, 9093, 9043, 8994, 8944, 8894, 8844, + 8794, 8745, 8695, 8645, 8595, 8545, 8496, 8446, + 8396, 8346, 8296, 8246, 8196, 8147, 8097, 8047, + 7997, 7947, 7897, 7847, 7797, 7747, 7697, 7648, + 7598, 7548, 7498, 7448, 7398, 7348, 7298, 7248, + 7198, 7148, 7098, 7048, 6998, 6948, 6898, 6848, + 6798, 6748, 6698, 6648, 6598, 6548, 6498, 6448, + 6398, 6348, 6298, 6248, 6198, 6148, 6098, 6048, + 5998, 5948, 5898, 5848, 5798, 5748, 5697, 5647, + 5597, 5547, 5497, 5447, 5397, 5347, 5297, 5247, + 5197, 5146, 5096, 5046, 4996, 4946, 4896, 4846, + 4796, 4745, 4695, 4645, 4595, 4545, 4495, 4445, + 4394, 4344, 4294, 4244, 4194, 4144, 4093, 4043, + 3993, 3943, 3893, 3843, 3792, 3742, 3692, 3642, + 3592, 3541, 3491, 3441, 3391, 3341, 3291, 3240, + 3190, 3140, 3090, 3039, 2989, 2939, 2889, 2839, + 2788, 2738, 2688, 2638, 2587, 2537, 2487, 2437, + 2387, 2336, 2286, 2236, 2186, 2135, 2085, 2035, + 1985, 1934, 1884, 1834, 1784, 1733, 1683, 1633, + 1583, 1532, 1482, 1432, 1382, 1331, 1281, 1231, + 1181, 1130, 1080, 1030, 980, 929, 879, 829, + 779, 728, 678, 628, 578, 527, 477, 427, + 376, 326, 276, 226, 175, 125, 75, 25, + -25, -75, -125, -175, -226, -276, -326, -376, + -427, -477, -527, -578, -628, -678, -728, -779, + -829, -879, -929, -980, -1030, -1080, -1130, -1181, + -1231, -1281, -1331, -1382, -1432, -1482, -1532, -1583, + -1633, -1683, -1733, -1784, -1834, -1884, -1934, -1985, + -2035, -2085, -2135, -2186, -2236, -2286, -2336, -2387, + -2437, -2487, -2537, -2588, -2638, -2688, -2738, -2788, + -2839, -2889, -2939, -2989, -3039, -3090, -3140, -3190, + -3240, -3291, -3341, -3391, -3441, -3491, -3541, -3592, + -3642, -3692, -3742, -3792, -3843, -3893, -3943, -3993, + -4043, -4093, -4144, -4194, -4244, -4294, -4344, -4394, + -4445, -4495, -4545, -4595, -4645, -4695, -4745, -4796, + -4846, -4896, -4946, -4996, -5046, -5096, -5146, -5197, + -5247, -5297, -5347, -5397, -5447, -5497, -5547, -5597, + -5647, -5697, -5748, -5798, -5848, -5898, -5948, -5998, + -6048, -6098, -6148, -6198, -6248, -6298, -6348, -6398, + -6448, -6498, -6548, -6598, -6648, -6698, -6748, -6798, + -6848, -6898, -6948, -6998, -7048, -7098, -7148, -7198, + -7248, -7298, -7348, -7398, -7448, -7498, -7548, -7598, + -7648, -7697, -7747, -7797, -7847, -7897, -7947, -7997, + -8047, -8097, -8147, -8196, -8246, -8296, -8346, -8396, + -8446, -8496, -8545, -8595, -8645, -8695, -8745, -8794, + -8844, -8894, -8944, -8994, -9043, -9093, -9143, -9193, + -9243, -9292, -9342, -9392, -9442, -9491, -9541, -9591, + -9640, -9690, -9740, -9790, -9839, -9889, -9939, -9988, + -10038, -10088, -10137, -10187, -10237, -10286, -10336, -10386, + -10435, -10485, -10534, -10584, -10634, -10683, -10733, -10782, + -10832, -10882, -10931, -10981, -11030, -11080, -11129, -11179, + -11228, -11278, -11327, -11377, -11426, -11476, -11525, -11575, + -11624, -11674, -11723, -11773, -11822, -11872, -11921, -11970, + -12020, -12069, -12119, -12168, -12218, -12267, -12316, -12366, + -12415, -12464, -12514, -12563, -12612, -12662, -12711, -12760, + -12810, -12859, -12908, -12957, -13007, -13056, -13105, -13154, + -13204, -13253, -13302, -13351, -13401, -13450, -13499, -13548, + -13597, -13647, -13696, -13745, -13794, -13843, -13892, -13941, + -13990, -14040, -14089, -14138, -14187, -14236, -14285, -14334, + -14383, -14432, -14481, -14530, -14579, -14628, -14677, -14726, + -14775, -14824, -14873, -14922, -14971, -15020, -15069, -15118, + -15167, -15215, -15264, -15313, -15362, -15411, -15460, -15509, + -15557, -15606, -15655, -15704, -15753, -15802, -15850, -15899, + -15948, -15997, -16045, -16094, -16143, -16191, -16240, -16289, + -16338, -16386, -16435, -16484, -16532, -16581, -16629, -16678, + -16727, -16775, -16824, -16872, -16921, -16970, -17018, -17067, + -17115, -17164, -17212, -17261, -17309, -17358, -17406, -17455, + -17503, -17551, -17600, -17648, -17697, -17745, -17793, -17842, + -17890, -17939, -17987, -18035, -18084, -18132, -18180, -18228, + -18277, -18325, -18373, -18421, -18470, -18518, -18566, -18614, + -18663, -18711, -18759, -18807, -18855, -18903, -18951, -19000, + -19048, -19096, -19144, -19192, -19240, -19288, -19336, -19384, + -19432, -19480, -19528, -19576, -19624, -19672, -19720, -19768, + -19816, -19864, -19912, -19959, -20007, -20055, -20103, -20151, + -20199, -20246, -20294, -20342, -20390, -20438, -20485, -20533, + -20581, -20629, -20676, -20724, -20772, -20819, -20867, -20915, + -20962, -21010, -21057, -21105, -21153, -21200, -21248, -21295, + -21343, -21390, -21438, -21485, -21533, -21580, -21628, -21675, + -21723, -21770, -21817, -21865, -21912, -21960, -22007, -22054, + -22102, -22149, -22196, -22243, -22291, -22338, -22385, -22433, + -22480, -22527, -22574, -22621, -22668, -22716, -22763, -22810, + -22857, -22904, -22951, -22998, -23045, -23092, -23139, -23186, + -23233, -23280, -23327, -23374, -23421, -23468, -23515, -23562, + -23609, -23656, -23703, -23750, -23796, -23843, -23890, -23937, + -23984, -24030, -24077, -24124, -24171, -24217, -24264, -24311, + -24357, -24404, -24451, -24497, -24544, -24591, -24637, -24684, + -24730, -24777, -24823, -24870, -24916, -24963, -25009, -25056, + -25102, -25149, -25195, -25241, -25288, -25334, -25381, -25427, + -25473, -25520, -25566, -25612, -25658, -25705, -25751, -25797, + -25843, -25889, -25936, -25982, -26028, -26074, -26120, -26166, + -26212, -26258, -26304, -26350, -26396, -26442, -26488, -26534, + -26580, -26626, -26672, -26718, -26764, -26810, -26856, -26902, + -26947, -26993, -27039, -27085, -27131, -27176, -27222, -27268, + -27313, -27359, -27405, -27450, -27496, -27542, -27587, -27633, + -27678, -27724, -27770, -27815, -27861, -27906, -27952, -27997, + -28042, -28088, -28133, -28179, -28224, -28269, -28315, -28360, + -28405, -28451, -28496, -28541, -28586, -28632, -28677, -28722, + -28767, -28812, -28858, -28903, -28948, -28993, -29038, -29083, + -29128, -29173, -29218, -29263, -29308, -29353, -29398, -29443, + -29488, -29533, -29577, -29622, -29667, -29712, -29757, -29801, + -29846, -29891, -29936, -29980, -30025, -30070, -30114, -30159, + -30204, -30248, -30293, -30337, -30382, -30426, -30471, -30515, + -30560, -30604, -30649, -30693, -30738, -30782, -30826, -30871, + -30915, -30959, -31004, -31048, -31092, -31136, -31181, -31225, + -31269, -31313, -31357, -31402, -31446, -31490, -31534, -31578, + -31622, -31666, -31710, -31754, -31798, -31842, -31886, -31930, + -31974, -32017, -32061, -32105, -32149, -32193, -32236, -32280, + -32324, -32368, -32411, -32455, -32499, -32542, -32586, -32630, + -32673, -32717, -32760, -32804, -32847, -32891, -32934, -32978, + -33021, -33065, -33108, -33151, -33195, -33238, -33281, -33325, + -33368, -33411, -33454, -33498, -33541, -33584, -33627, -33670, + -33713, -33756, -33799, -33843, -33886, -33929, -33972, -34015, + -34057, -34100, -34143, -34186, -34229, -34272, -34315, -34358, + -34400, -34443, -34486, -34529, -34571, -34614, -34657, -34699, + -34742, -34785, -34827, -34870, -34912, -34955, -34997, -35040, + -35082, -35125, -35167, -35210, -35252, -35294, -35337, -35379, + -35421, -35464, -35506, -35548, -35590, -35633, -35675, -35717, + -35759, -35801, -35843, -35885, -35927, -35969, -36011, -36053, + -36095, -36137, -36179, -36221, -36263, -36305, -36347, -36388, + -36430, -36472, -36514, -36555, -36597, -36639, -36681, -36722, + -36764, -36805, -36847, -36889, -36930, -36972, -37013, -37055, + -37096, -37137, -37179, -37220, -37262, -37303, -37344, -37386, + -37427, -37468, -37509, -37551, -37592, -37633, -37674, -37715, + -37756, -37797, -37838, -37879, -37920, -37961, -38002, -38043, + -38084, -38125, -38166, -38207, -38248, -38288, -38329, -38370, + -38411, -38451, -38492, -38533, -38573, -38614, -38655, -38695, + -38736, -38776, -38817, -38857, -38898, -38938, -38979, -39019, + -39059, -39100, -39140, -39180, -39221, -39261, -39301, -39341, + -39382, -39422, -39462, -39502, -39542, -39582, -39622, -39662, + -39702, -39742, -39782, -39822, -39862, -39902, -39942, -39982, + -40021, -40061, -40101, -40141, -40180, -40220, -40260, -40299, + -40339, -40379, -40418, -40458, -40497, -40537, -40576, -40616, + -40655, -40695, -40734, -40773, -40813, -40852, -40891, -40931, + -40970, -41009, -41048, -41087, -41127, -41166, -41205, -41244, + -41283, -41322, -41361, -41400, -41439, -41478, -41517, -41556, + -41595, -41633, -41672, -41711, -41750, -41788, -41827, -41866, + -41904, -41943, -41982, -42020, -42059, -42097, -42136, -42174, + -42213, -42251, -42290, -42328, -42366, -42405, -42443, -42481, + -42520, -42558, -42596, -42634, -42672, -42711, -42749, -42787, + -42825, -42863, -42901, -42939, -42977, -43015, -43053, -43091, + -43128, -43166, -43204, -43242, -43280, -43317, -43355, -43393, + -43430, -43468, -43506, -43543, -43581, -43618, -43656, -43693, + -43731, -43768, -43806, -43843, -43880, -43918, -43955, -43992, + -44029, -44067, -44104, -44141, -44178, -44215, -44252, -44289, + -44326, -44363, -44400, -44437, -44474, -44511, -44548, -44585, + -44622, -44659, -44695, -44732, -44769, -44806, -44842, -44879, + -44915, -44952, -44989, -45025, -45062, -45098, -45135, -45171, + -45207, -45244, -45280, -45316, -45353, -45389, -45425, -45462, + -45498, -45534, -45570, -45606, -45642, -45678, -45714, -45750, + -45786, -45822, -45858, -45894, -45930, -45966, -46002, -46037, + -46073, -46109, -46145, -46180, -46216, -46252, -46287, -46323, + -46358, -46394, -46429, -46465, -46500, -46536, -46571, -46606, + -46642, -46677, -46712, -46747, -46783, -46818, -46853, -46888, + -46923, -46958, -46993, -47028, -47063, -47098, -47133, -47168, + -47203, -47238, -47273, -47308, -47342, -47377, -47412, -47446, + -47481, -47516, -47550, -47585, -47619, -47654, -47688, -47723, + -47757, -47792, -47826, -47860, -47895, -47929, -47963, -47998, + -48032, -48066, -48100, -48134, -48168, -48202, -48236, -48271, + -48304, -48338, -48372, -48406, -48440, -48474, -48508, -48542, + -48575, -48609, -48643, -48676, -48710, -48744, -48777, -48811, + -48844, -48878, -48911, -48945, -48978, -49012, -49045, -49078, + -49112, -49145, -49178, -49211, -49244, -49278, -49311, -49344, + -49377, -49410, -49443, -49476, -49509, -49542, -49575, -49608, + -49640, -49673, -49706, -49739, -49771, -49804, -49837, -49869, + -49902, -49935, -49967, -50000, -50032, -50065, -50097, -50129, + -50162, -50194, -50226, -50259, -50291, -50323, -50355, -50387, + -50420, -50452, -50484, -50516, -50548, -50580, -50612, -50644, + -50675, -50707, -50739, -50771, -50803, -50834, -50866, -50898, + -50929, -50961, -50993, -51024, -51056, -51087, -51119, -51150, + -51182, -51213, -51244, -51276, -51307, -51338, -51369, -51401, + -51432, -51463, -51494, -51525, -51556, -51587, -51618, -51649, + -51680, -51711, -51742, -51773, -51803, -51834, -51865, -51896, + -51926, -51957, -51988, -52018, -52049, -52079, -52110, -52140, + -52171, -52201, -52231, -52262, -52292, -52322, -52353, -52383, + -52413, -52443, -52473, -52503, -52534, -52564, -52594, -52624, + -52653, -52683, -52713, -52743, -52773, -52803, -52832, -52862, + -52892, -52922, -52951, -52981, -53010, -53040, -53069, -53099, + -53128, -53158, -53187, -53216, -53246, -53275, -53304, -53334, + -53363, -53392, -53421, -53450, -53479, -53508, -53537, -53566, + -53595, -53624, -53653, -53682, -53711, -53739, -53768, -53797, + -53826, -53854, -53883, -53911, -53940, -53969, -53997, -54026, + -54054, -54082, -54111, -54139, -54167, -54196, -54224, -54252, + -54280, -54308, -54337, -54365, -54393, -54421, -54449, -54477, + -54505, -54533, -54560, -54588, -54616, -54644, -54672, -54699, + -54727, -54755, -54782, -54810, -54837, -54865, -54892, -54920, + -54947, -54974, -55002, -55029, -55056, -55084, -55111, -55138, + -55165, -55192, -55219, -55246, -55274, -55300, -55327, -55354, + -55381, -55408, -55435, -55462, -55489, -55515, -55542, -55569, + -55595, -55622, -55648, -55675, -55701, -55728, -55754, -55781, + -55807, -55833, -55860, -55886, -55912, -55938, -55965, -55991, + -56017, -56043, -56069, -56095, -56121, -56147, -56173, -56199, + -56225, -56250, -56276, -56302, -56328, -56353, -56379, -56404, + -56430, -56456, -56481, -56507, -56532, -56557, -56583, -56608, + -56633, -56659, -56684, -56709, -56734, -56760, -56785, -56810, + -56835, -56860, -56885, -56910, -56935, -56959, -56984, -57009, + -57034, -57059, -57083, -57108, -57133, -57157, -57182, -57206, + -57231, -57255, -57280, -57304, -57329, -57353, -57377, -57402, + -57426, -57450, -57474, -57498, -57522, -57546, -57570, -57594, + -57618, -57642, -57666, -57690, -57714, -57738, -57762, -57785, + -57809, -57833, -57856, -57880, -57903, -57927, -57950, -57974, + -57997, -58021, -58044, -58067, -58091, -58114, -58137, -58160, + -58183, -58207, -58230, -58253, -58276, -58299, -58322, -58345, + -58367, -58390, -58413, -58436, -58459, -58481, -58504, -58527, + -58549, -58572, -58594, -58617, -58639, -58662, -58684, -58706, + -58729, -58751, -58773, -58795, -58818, -58840, -58862, -58884, + -58906, -58928, -58950, -58972, -58994, -59016, -59038, -59059, + -59081, -59103, -59125, -59146, -59168, -59190, -59211, -59233, + -59254, -59276, -59297, -59318, -59340, -59361, -59382, -59404, + -59425, -59446, -59467, -59488, -59509, -59530, -59551, -59572, + -59593, -59614, -59635, -59656, -59677, -59697, -59718, -59739, + -59759, -59780, -59801, -59821, -59842, -59862, -59883, -59903, + -59923, -59944, -59964, -59984, -60004, -60025, -60045, -60065, + -60085, -60105, -60125, -60145, -60165, -60185, -60205, -60225, + -60244, -60264, -60284, -60304, -60323, -60343, -60363, -60382, + -60402, -60421, -60441, -60460, -60479, -60499, -60518, -60537, + -60556, -60576, -60595, -60614, -60633, -60652, -60671, -60690, + -60709, -60728, -60747, -60766, -60785, -60803, -60822, -60841, + -60859, -60878, -60897, -60915, -60934, -60952, -60971, -60989, + -61007, -61026, -61044, -61062, -61081, -61099, -61117, -61135, + -61153, -61171, -61189, -61207, -61225, -61243, -61261, -61279, + -61297, -61314, -61332, -61350, -61367, -61385, -61403, -61420, + -61438, -61455, -61473, -61490, -61507, -61525, -61542, -61559, + -61577, -61594, -61611, -61628, -61645, -61662, -61679, -61696, + -61713, -61730, -61747, -61764, -61780, -61797, -61814, -61831, + -61847, -61864, -61880, -61897, -61913, -61930, -61946, -61963, + -61979, -61995, -62012, -62028, -62044, -62060, -62076, -62092, + -62108, -62125, -62141, -62156, -62172, -62188, -62204, -62220, + -62236, -62251, -62267, -62283, -62298, -62314, -62329, -62345, + -62360, -62376, -62391, -62407, -62422, -62437, -62453, -62468, + -62483, -62498, -62513, -62528, -62543, -62558, -62573, -62588, + -62603, -62618, -62633, -62648, -62662, -62677, -62692, -62706, + -62721, -62735, -62750, -62764, -62779, -62793, -62808, -62822, + -62836, -62850, -62865, -62879, -62893, -62907, -62921, -62935, + -62949, -62963, -62977, -62991, -63005, -63019, -63032, -63046, + -63060, -63074, -63087, -63101, -63114, -63128, -63141, -63155, + -63168, -63182, -63195, -63208, -63221, -63235, -63248, -63261, + -63274, -63287, -63300, -63313, -63326, -63339, -63352, -63365, + -63378, -63390, -63403, -63416, -63429, -63441, -63454, -63466, + -63479, -63491, -63504, -63516, -63528, -63541, -63553, -63565, + -63578, -63590, -63602, -63614, -63626, -63638, -63650, -63662, + -63674, -63686, -63698, -63709, -63721, -63733, -63745, -63756, + -63768, -63779, -63791, -63803, -63814, -63825, -63837, -63848, + -63859, -63871, -63882, -63893, -63904, -63915, -63927, -63938, + -63949, -63960, -63971, -63981, -63992, -64003, -64014, -64025, + -64035, -64046, -64057, -64067, -64078, -64088, -64099, -64109, + -64120, -64130, -64140, -64151, -64161, -64171, -64181, -64192, + -64202, -64212, -64222, -64232, -64242, -64252, -64261, -64271, + -64281, -64291, -64301, -64310, -64320, -64330, -64339, -64349, + -64358, -64368, -64377, -64387, -64396, -64405, -64414, -64424, + -64433, -64442, -64451, -64460, -64469, -64478, -64487, -64496, + -64505, -64514, -64523, -64532, -64540, -64549, -64558, -64566, + -64575, -64584, -64592, -64601, -64609, -64617, -64626, -64634, + -64642, -64651, -64659, -64667, -64675, -64683, -64691, -64699, + -64707, -64715, -64723, -64731, -64739, -64747, -64754, -64762, + -64770, -64777, -64785, -64793, -64800, -64808, -64815, -64822, + -64830, -64837, -64844, -64852, -64859, -64866, -64873, -64880, + -64887, -64895, -64902, -64908, -64915, -64922, -64929, -64936, + -64943, -64949, -64956, -64963, -64969, -64976, -64982, -64989, + -64995, -65002, -65008, -65015, -65021, -65027, -65033, -65040, + -65046, -65052, -65058, -65064, -65070, -65076, -65082, -65088, + -65094, -65099, -65105, -65111, -65117, -65122, -65128, -65133, + -65139, -65144, -65150, -65155, -65161, -65166, -65171, -65177, + -65182, -65187, -65192, -65197, -65202, -65207, -65212, -65217, + -65222, -65227, -65232, -65237, -65242, -65246, -65251, -65256, + -65260, -65265, -65270, -65274, -65279, -65283, -65287, -65292, + -65296, -65300, -65305, -65309, -65313, -65317, -65321, -65325, + -65329, -65333, -65337, -65341, -65345, -65349, -65352, -65356, + -65360, -65363, -65367, -65371, -65374, -65378, -65381, -65385, + -65388, -65391, -65395, -65398, -65401, -65404, -65408, -65411, + -65414, -65417, -65420, -65423, -65426, -65429, -65431, -65434, + -65437, -65440, -65442, -65445, -65448, -65450, -65453, -65455, + -65458, -65460, -65463, -65465, -65467, -65470, -65472, -65474, + -65476, -65478, -65480, -65482, -65484, -65486, -65488, -65490, + -65492, -65494, -65496, -65497, -65499, -65501, -65502, -65504, + -65505, -65507, -65508, -65510, -65511, -65513, -65514, -65515, + -65516, -65518, -65519, -65520, -65521, -65522, -65523, -65524, + -65525, -65526, -65527, -65527, -65528, -65529, -65530, -65530, + -65531, -65531, -65532, -65532, -65533, -65533, -65534, -65534, + -65534, -65535, -65535, -65535, -65535, -65535, -65535, -65535, + -65535, -65535, -65535, -65535, -65535, -65535, -65535, -65534, + -65534, -65534, -65533, -65533, -65532, -65532, -65531, -65531, + -65530, -65530, -65529, -65528, -65527, -65527, -65526, -65525, + -65524, -65523, -65522, -65521, -65520, -65519, -65518, -65516, + -65515, -65514, -65513, -65511, -65510, -65508, -65507, -65505, + -65504, -65502, -65501, -65499, -65497, -65496, -65494, -65492, + -65490, -65488, -65486, -65484, -65482, -65480, -65478, -65476, + -65474, -65472, -65470, -65467, -65465, -65463, -65460, -65458, + -65455, -65453, -65450, -65448, -65445, -65442, -65440, -65437, + -65434, -65431, -65429, -65426, -65423, -65420, -65417, -65414, + -65411, -65408, -65404, -65401, -65398, -65395, -65391, -65388, + -65385, -65381, -65378, -65374, -65371, -65367, -65363, -65360, + -65356, -65352, -65349, -65345, -65341, -65337, -65333, -65329, + -65325, -65321, -65317, -65313, -65309, -65305, -65300, -65296, + -65292, -65287, -65283, -65279, -65274, -65270, -65265, -65260, + -65256, -65251, -65246, -65242, -65237, -65232, -65227, -65222, + -65217, -65212, -65207, -65202, -65197, -65192, -65187, -65182, + -65177, -65171, -65166, -65161, -65155, -65150, -65144, -65139, + -65133, -65128, -65122, -65117, -65111, -65105, -65099, -65094, + -65088, -65082, -65076, -65070, -65064, -65058, -65052, -65046, + -65040, -65033, -65027, -65021, -65015, -65008, -65002, -64995, + -64989, -64982, -64976, -64969, -64963, -64956, -64949, -64943, + -64936, -64929, -64922, -64915, -64908, -64902, -64895, -64887, + -64880, -64873, -64866, -64859, -64852, -64844, -64837, -64830, + -64822, -64815, -64808, -64800, -64793, -64785, -64777, -64770, + -64762, -64754, -64747, -64739, -64731, -64723, -64715, -64707, + -64699, -64691, -64683, -64675, -64667, -64659, -64651, -64642, + -64634, -64626, -64617, -64609, -64601, -64592, -64584, -64575, + -64566, -64558, -64549, -64540, -64532, -64523, -64514, -64505, + -64496, -64487, -64478, -64469, -64460, -64451, -64442, -64433, + -64424, -64414, -64405, -64396, -64387, -64377, -64368, -64358, + -64349, -64339, -64330, -64320, -64310, -64301, -64291, -64281, + -64271, -64261, -64252, -64242, -64232, -64222, -64212, -64202, + -64192, -64181, -64171, -64161, -64151, -64140, -64130, -64120, + -64109, -64099, -64088, -64078, -64067, -64057, -64046, -64035, + -64025, -64014, -64003, -63992, -63981, -63971, -63960, -63949, + -63938, -63927, -63915, -63904, -63893, -63882, -63871, -63859, + -63848, -63837, -63825, -63814, -63803, -63791, -63779, -63768, + -63756, -63745, -63733, -63721, -63709, -63698, -63686, -63674, + -63662, -63650, -63638, -63626, -63614, -63602, -63590, -63578, + -63565, -63553, -63541, -63528, -63516, -63504, -63491, -63479, + -63466, -63454, -63441, -63429, -63416, -63403, -63390, -63378, + -63365, -63352, -63339, -63326, -63313, -63300, -63287, -63274, + -63261, -63248, -63235, -63221, -63208, -63195, -63182, -63168, + -63155, -63141, -63128, -63114, -63101, -63087, -63074, -63060, + -63046, -63032, -63019, -63005, -62991, -62977, -62963, -62949, + -62935, -62921, -62907, -62893, -62879, -62865, -62850, -62836, + -62822, -62808, -62793, -62779, -62764, -62750, -62735, -62721, + -62706, -62692, -62677, -62662, -62648, -62633, -62618, -62603, + -62588, -62573, -62558, -62543, -62528, -62513, -62498, -62483, + -62468, -62453, -62437, -62422, -62407, -62391, -62376, -62360, + -62345, -62329, -62314, -62298, -62283, -62267, -62251, -62236, + -62220, -62204, -62188, -62172, -62156, -62141, -62125, -62108, + -62092, -62076, -62060, -62044, -62028, -62012, -61995, -61979, + -61963, -61946, -61930, -61913, -61897, -61880, -61864, -61847, + -61831, -61814, -61797, -61780, -61764, -61747, -61730, -61713, + -61696, -61679, -61662, -61645, -61628, -61611, -61594, -61577, + -61559, -61542, -61525, -61507, -61490, -61473, -61455, -61438, + -61420, -61403, -61385, -61367, -61350, -61332, -61314, -61297, + -61279, -61261, -61243, -61225, -61207, -61189, -61171, -61153, + -61135, -61117, -61099, -61081, -61062, -61044, -61026, -61007, + -60989, -60971, -60952, -60934, -60915, -60897, -60878, -60859, + -60841, -60822, -60803, -60785, -60766, -60747, -60728, -60709, + -60690, -60671, -60652, -60633, -60614, -60595, -60576, -60556, + -60537, -60518, -60499, -60479, -60460, -60441, -60421, -60402, + -60382, -60363, -60343, -60323, -60304, -60284, -60264, -60244, + -60225, -60205, -60185, -60165, -60145, -60125, -60105, -60085, + -60065, -60045, -60025, -60004, -59984, -59964, -59944, -59923, + -59903, -59883, -59862, -59842, -59821, -59801, -59780, -59759, + -59739, -59718, -59697, -59677, -59656, -59635, -59614, -59593, + -59572, -59551, -59530, -59509, -59488, -59467, -59446, -59425, + -59404, -59382, -59361, -59340, -59318, -59297, -59276, -59254, + -59233, -59211, -59189, -59168, -59146, -59125, -59103, -59081, + -59059, -59038, -59016, -58994, -58972, -58950, -58928, -58906, + -58884, -58862, -58840, -58818, -58795, -58773, -58751, -58729, + -58706, -58684, -58662, -58639, -58617, -58594, -58572, -58549, + -58527, -58504, -58481, -58459, -58436, -58413, -58390, -58367, + -58345, -58322, -58299, -58276, -58253, -58230, -58207, -58183, + -58160, -58137, -58114, -58091, -58067, -58044, -58021, -57997, + -57974, -57950, -57927, -57903, -57880, -57856, -57833, -57809, + -57785, -57762, -57738, -57714, -57690, -57666, -57642, -57618, + -57594, -57570, -57546, -57522, -57498, -57474, -57450, -57426, + -57402, -57377, -57353, -57329, -57304, -57280, -57255, -57231, + -57206, -57182, -57157, -57133, -57108, -57083, -57059, -57034, + -57009, -56984, -56959, -56935, -56910, -56885, -56860, -56835, + -56810, -56785, -56760, -56734, -56709, -56684, -56659, -56633, + -56608, -56583, -56557, -56532, -56507, -56481, -56456, -56430, + -56404, -56379, -56353, -56328, -56302, -56276, -56250, -56225, + -56199, -56173, -56147, -56121, -56095, -56069, -56043, -56017, + -55991, -55965, -55938, -55912, -55886, -55860, -55833, -55807, + -55781, -55754, -55728, -55701, -55675, -55648, -55622, -55595, + -55569, -55542, -55515, -55489, -55462, -55435, -55408, -55381, + -55354, -55327, -55300, -55274, -55246, -55219, -55192, -55165, + -55138, -55111, -55084, -55056, -55029, -55002, -54974, -54947, + -54920, -54892, -54865, -54837, -54810, -54782, -54755, -54727, + -54699, -54672, -54644, -54616, -54588, -54560, -54533, -54505, + -54477, -54449, -54421, -54393, -54365, -54337, -54308, -54280, + -54252, -54224, -54196, -54167, -54139, -54111, -54082, -54054, + -54026, -53997, -53969, -53940, -53911, -53883, -53854, -53826, + -53797, -53768, -53739, -53711, -53682, -53653, -53624, -53595, + -53566, -53537, -53508, -53479, -53450, -53421, -53392, -53363, + -53334, -53304, -53275, -53246, -53216, -53187, -53158, -53128, + -53099, -53069, -53040, -53010, -52981, -52951, -52922, -52892, + -52862, -52832, -52803, -52773, -52743, -52713, -52683, -52653, + -52624, -52594, -52564, -52534, -52503, -52473, -52443, -52413, + -52383, -52353, -52322, -52292, -52262, -52231, -52201, -52171, + -52140, -52110, -52079, -52049, -52018, -51988, -51957, -51926, + -51896, -51865, -51834, -51803, -51773, -51742, -51711, -51680, + -51649, -51618, -51587, -51556, -51525, -51494, -51463, -51432, + -51401, -51369, -51338, -51307, -51276, -51244, -51213, -51182, + -51150, -51119, -51087, -51056, -51024, -50993, -50961, -50929, + -50898, -50866, -50834, -50803, -50771, -50739, -50707, -50675, + -50644, -50612, -50580, -50548, -50516, -50484, -50452, -50420, + -50387, -50355, -50323, -50291, -50259, -50226, -50194, -50162, + -50129, -50097, -50065, -50032, -50000, -49967, -49935, -49902, + -49869, -49837, -49804, -49771, -49739, -49706, -49673, -49640, + -49608, -49575, -49542, -49509, -49476, -49443, -49410, -49377, + -49344, -49311, -49278, -49244, -49211, -49178, -49145, -49112, + -49078, -49045, -49012, -48978, -48945, -48911, -48878, -48844, + -48811, -48777, -48744, -48710, -48676, -48643, -48609, -48575, + -48542, -48508, -48474, -48440, -48406, -48372, -48338, -48305, + -48271, -48237, -48202, -48168, -48134, -48100, -48066, -48032, + -47998, -47963, -47929, -47895, -47860, -47826, -47792, -47757, + -47723, -47688, -47654, -47619, -47585, -47550, -47516, -47481, + -47446, -47412, -47377, -47342, -47307, -47273, -47238, -47203, + -47168, -47133, -47098, -47063, -47028, -46993, -46958, -46923, + -46888, -46853, -46818, -46783, -46747, -46712, -46677, -46642, + -46606, -46571, -46536, -46500, -46465, -46429, -46394, -46358, + -46323, -46287, -46251, -46216, -46180, -46145, -46109, -46073, + -46037, -46002, -45966, -45930, -45894, -45858, -45822, -45786, + -45750, -45714, -45678, -45642, -45606, -45570, -45534, -45498, + -45462, -45425, -45389, -45353, -45316, -45280, -45244, -45207, + -45171, -45135, -45098, -45062, -45025, -44989, -44952, -44915, + -44879, -44842, -44806, -44769, -44732, -44695, -44659, -44622, + -44585, -44548, -44511, -44474, -44437, -44400, -44363, -44326, + -44289, -44252, -44215, -44178, -44141, -44104, -44067, -44029, + -43992, -43955, -43918, -43880, -43843, -43806, -43768, -43731, + -43693, -43656, -43618, -43581, -43543, -43506, -43468, -43430, + -43393, -43355, -43317, -43280, -43242, -43204, -43166, -43128, + -43091, -43053, -43015, -42977, -42939, -42901, -42863, -42825, + -42787, -42749, -42711, -42672, -42634, -42596, -42558, -42520, + -42481, -42443, -42405, -42366, -42328, -42290, -42251, -42213, + -42174, -42136, -42097, -42059, -42020, -41982, -41943, -41904, + -41866, -41827, -41788, -41750, -41711, -41672, -41633, -41595, + -41556, -41517, -41478, -41439, -41400, -41361, -41322, -41283, + -41244, -41205, -41166, -41127, -41087, -41048, -41009, -40970, + -40931, -40891, -40852, -40813, -40773, -40734, -40695, -40655, + -40616, -40576, -40537, -40497, -40458, -40418, -40379, -40339, + -40299, -40260, -40220, -40180, -40141, -40101, -40061, -40021, + -39982, -39942, -39902, -39862, -39822, -39782, -39742, -39702, + -39662, -39622, -39582, -39542, -39502, -39462, -39422, -39382, + -39341, -39301, -39261, -39221, -39180, -39140, -39100, -39059, + -39019, -38979, -38938, -38898, -38857, -38817, -38776, -38736, + -38695, -38655, -38614, -38573, -38533, -38492, -38451, -38411, + -38370, -38329, -38288, -38248, -38207, -38166, -38125, -38084, + -38043, -38002, -37961, -37920, -37879, -37838, -37797, -37756, + -37715, -37674, -37633, -37592, -37550, -37509, -37468, -37427, + -37386, -37344, -37303, -37262, -37220, -37179, -37137, -37096, + -37055, -37013, -36972, -36930, -36889, -36847, -36805, -36764, + -36722, -36681, -36639, -36597, -36556, -36514, -36472, -36430, + -36388, -36347, -36305, -36263, -36221, -36179, -36137, -36095, + -36053, -36011, -35969, -35927, -35885, -35843, -35801, -35759, + -35717, -35675, -35633, -35590, -35548, -35506, -35464, -35421, + -35379, -35337, -35294, -35252, -35210, -35167, -35125, -35082, + -35040, -34997, -34955, -34912, -34870, -34827, -34785, -34742, + -34699, -34657, -34614, -34571, -34529, -34486, -34443, -34400, + -34358, -34315, -34272, -34229, -34186, -34143, -34100, -34057, + -34015, -33972, -33929, -33886, -33843, -33799, -33756, -33713, + -33670, -33627, -33584, -33541, -33498, -33454, -33411, -33368, + -33325, -33281, -33238, -33195, -33151, -33108, -33065, -33021, + -32978, -32934, -32891, -32847, -32804, -32760, -32717, -32673, + -32630, -32586, -32542, -32499, -32455, -32411, -32368, -32324, + -32280, -32236, -32193, -32149, -32105, -32061, -32017, -31974, + -31930, -31886, -31842, -31798, -31754, -31710, -31666, -31622, + -31578, -31534, -31490, -31446, -31402, -31357, -31313, -31269, + -31225, -31181, -31136, -31092, -31048, -31004, -30959, -30915, + -30871, -30826, -30782, -30738, -30693, -30649, -30604, -30560, + -30515, -30471, -30426, -30382, -30337, -30293, -30248, -30204, + -30159, -30114, -30070, -30025, -29980, -29936, -29891, -29846, + -29801, -29757, -29712, -29667, -29622, -29577, -29533, -29488, + -29443, -29398, -29353, -29308, -29263, -29218, -29173, -29128, + -29083, -29038, -28993, -28948, -28903, -28858, -28812, -28767, + -28722, -28677, -28632, -28586, -28541, -28496, -28451, -28405, + -28360, -28315, -28269, -28224, -28179, -28133, -28088, -28042, + -27997, -27952, -27906, -27861, -27815, -27770, -27724, -27678, + -27633, -27587, -27542, -27496, -27450, -27405, -27359, -27313, + -27268, -27222, -27176, -27131, -27085, -27039, -26993, -26947, + -26902, -26856, -26810, -26764, -26718, -26672, -26626, -26580, + -26534, -26488, -26442, -26396, -26350, -26304, -26258, -26212, + -26166, -26120, -26074, -26028, -25982, -25936, -25889, -25843, + -25797, -25751, -25705, -25658, -25612, -25566, -25520, -25473, + -25427, -25381, -25334, -25288, -25241, -25195, -25149, -25102, + -25056, -25009, -24963, -24916, -24870, -24823, -24777, -24730, + -24684, -24637, -24591, -24544, -24497, -24451, -24404, -24357, + -24311, -24264, -24217, -24171, -24124, -24077, -24030, -23984, + -23937, -23890, -23843, -23796, -23750, -23703, -23656, -23609, + -23562, -23515, -23468, -23421, -23374, -23327, -23280, -23233, + -23186, -23139, -23092, -23045, -22998, -22951, -22904, -22857, + -22810, -22763, -22716, -22668, -22621, -22574, -22527, -22480, + -22432, -22385, -22338, -22291, -22243, -22196, -22149, -22102, + -22054, -22007, -21960, -21912, -21865, -21817, -21770, -21723, + -21675, -21628, -21580, -21533, -21485, -21438, -21390, -21343, + -21295, -21248, -21200, -21153, -21105, -21057, -21010, -20962, + -20915, -20867, -20819, -20772, -20724, -20676, -20629, -20581, + -20533, -20485, -20438, -20390, -20342, -20294, -20246, -20199, + -20151, -20103, -20055, -20007, -19959, -19912, -19864, -19816, + -19768, -19720, -19672, -19624, -19576, -19528, -19480, -19432, + -19384, -19336, -19288, -19240, -19192, -19144, -19096, -19048, + -19000, -18951, -18903, -18855, -18807, -18759, -18711, -18663, + -18614, -18566, -18518, -18470, -18421, -18373, -18325, -18277, + -18228, -18180, -18132, -18084, -18035, -17987, -17939, -17890, + -17842, -17793, -17745, -17697, -17648, -17600, -17551, -17503, + -17455, -17406, -17358, -17309, -17261, -17212, -17164, -17115, + -17067, -17018, -16970, -16921, -16872, -16824, -16775, -16727, + -16678, -16629, -16581, -16532, -16484, -16435, -16386, -16338, + -16289, -16240, -16191, -16143, -16094, -16045, -15997, -15948, + -15899, -15850, -15802, -15753, -15704, -15655, -15606, -15557, + -15509, -15460, -15411, -15362, -15313, -15264, -15215, -15167, + -15118, -15069, -15020, -14971, -14922, -14873, -14824, -14775, + -14726, -14677, -14628, -14579, -14530, -14481, -14432, -14383, + -14334, -14285, -14236, -14187, -14138, -14089, -14040, -13990, + -13941, -13892, -13843, -13794, -13745, -13696, -13647, -13597, + -13548, -13499, -13450, -13401, -13351, -13302, -13253, -13204, + -13154, -13105, -13056, -13007, -12957, -12908, -12859, -12810, + -12760, -12711, -12662, -12612, -12563, -12514, -12464, -12415, + -12366, -12316, -12267, -12217, -12168, -12119, -12069, -12020, + -11970, -11921, -11872, -11822, -11773, -11723, -11674, -11624, + -11575, -11525, -11476, -11426, -11377, -11327, -11278, -11228, + -11179, -11129, -11080, -11030, -10981, -10931, -10882, -10832, + -10782, -10733, -10683, -10634, -10584, -10534, -10485, -10435, + -10386, -10336, -10286, -10237, -10187, -10137, -10088, -10038, + -9988, -9939, -9889, -9839, -9790, -9740, -9690, -9640, + -9591, -9541, -9491, -9442, -9392, -9342, -9292, -9243, + -9193, -9143, -9093, -9043, -8994, -8944, -8894, -8844, + -8794, -8745, -8695, -8645, -8595, -8545, -8496, -8446, + -8396, -8346, -8296, -8246, -8196, -8147, -8097, -8047, + -7997, -7947, -7897, -7847, -7797, -7747, -7697, -7648, + -7598, -7548, -7498, -7448, -7398, -7348, -7298, -7248, + -7198, -7148, -7098, -7048, -6998, -6948, -6898, -6848, + -6798, -6748, -6698, -6648, -6598, -6548, -6498, -6448, + -6398, -6348, -6298, -6248, -6198, -6148, -6098, -6048, + -5998, -5948, -5898, -5848, -5798, -5747, -5697, -5647, + -5597, -5547, -5497, -5447, -5397, -5347, -5297, -5247, + -5197, -5146, -5096, -5046, -4996, -4946, -4896, -4846, + -4796, -4745, -4695, -4645, -4595, -4545, -4495, -4445, + -4394, -4344, -4294, -4244, -4194, -4144, -4093, -4043, + -3993, -3943, -3893, -3843, -3792, -3742, -3692, -3642, + -3592, -3541, -3491, -3441, -3391, -3341, -3291, -3240, + -3190, -3140, -3090, -3039, -2989, -2939, -2889, -2839, + -2788, -2738, -2688, -2638, -2588, -2537, -2487, -2437, + -2387, -2336, -2286, -2236, -2186, -2135, -2085, -2035, + -1985, -1934, -1884, -1834, -1784, -1733, -1683, -1633, + -1583, -1532, -1482, -1432, -1382, -1331, -1281, -1231, + -1181, -1130, -1080, -1030, -980, -929, -879, -829, + -779, -728, -678, -628, -578, -527, -477, -427, + -376, -326, -276, -226, -175, -125, -75, -25, + 25, 75, 125, 175, 226, 276, 326, 376, + 427, 477, 527, 578, 628, 678, 728, 779, + 829, 879, 929, 980, 1030, 1080, 1130, 1181, + 1231, 1281, 1331, 1382, 1432, 1482, 1532, 1583, + 1633, 1683, 1733, 1784, 1834, 1884, 1934, 1985, + 2035, 2085, 2135, 2186, 2236, 2286, 2336, 2387, + 2437, 2487, 2537, 2587, 2638, 2688, 2738, 2788, + 2839, 2889, 2939, 2989, 3039, 3090, 3140, 3190, + 3240, 3291, 3341, 3391, 3441, 3491, 3542, 3592, + 3642, 3692, 3742, 3792, 3843, 3893, 3943, 3993, + 4043, 4093, 4144, 4194, 4244, 4294, 4344, 4394, + 4445, 4495, 4545, 4595, 4645, 4695, 4745, 4796, + 4846, 4896, 4946, 4996, 5046, 5096, 5146, 5197, + 5247, 5297, 5347, 5397, 5447, 5497, 5547, 5597, + 5647, 5697, 5747, 5798, 5848, 5898, 5948, 5998, + 6048, 6098, 6148, 6198, 6248, 6298, 6348, 6398, + 6448, 6498, 6548, 6598, 6648, 6698, 6748, 6798, + 6848, 6898, 6948, 6998, 7048, 7098, 7148, 7198, + 7248, 7298, 7348, 7398, 7448, 7498, 7548, 7598, + 7648, 7697, 7747, 7797, 7847, 7897, 7947, 7997, + 8047, 8097, 8147, 8196, 8246, 8296, 8346, 8396, + 8446, 8496, 8545, 8595, 8645, 8695, 8745, 8794, + 8844, 8894, 8944, 8994, 9043, 9093, 9143, 9193, + 9243, 9292, 9342, 9392, 9442, 9491, 9541, 9591, + 9640, 9690, 9740, 9790, 9839, 9889, 9939, 9988, + 10038, 10088, 10137, 10187, 10237, 10286, 10336, 10386, + 10435, 10485, 10534, 10584, 10634, 10683, 10733, 10782, + 10832, 10882, 10931, 10981, 11030, 11080, 11129, 11179, + 11228, 11278, 11327, 11377, 11426, 11476, 11525, 11575, + 11624, 11674, 11723, 11773, 11822, 11872, 11921, 11970, + 12020, 12069, 12119, 12168, 12218, 12267, 12316, 12366, + 12415, 12464, 12514, 12563, 12612, 12662, 12711, 12760, + 12810, 12859, 12908, 12957, 13007, 13056, 13105, 13154, + 13204, 13253, 13302, 13351, 13401, 13450, 13499, 13548, + 13597, 13647, 13696, 13745, 13794, 13843, 13892, 13941, + 13990, 14040, 14089, 14138, 14187, 14236, 14285, 14334, + 14383, 14432, 14481, 14530, 14579, 14628, 14677, 14726, + 14775, 14824, 14873, 14922, 14971, 15020, 15069, 15118, + 15167, 15215, 15264, 15313, 15362, 15411, 15460, 15509, + 15557, 15606, 15655, 15704, 15753, 15802, 15850, 15899, + 15948, 15997, 16045, 16094, 16143, 16191, 16240, 16289, + 16338, 16386, 16435, 16484, 16532, 16581, 16629, 16678, + 16727, 16775, 16824, 16872, 16921, 16970, 17018, 17067, + 17115, 17164, 17212, 17261, 17309, 17358, 17406, 17455, + 17503, 17551, 17600, 17648, 17697, 17745, 17793, 17842, + 17890, 17939, 17987, 18035, 18084, 18132, 18180, 18228, + 18277, 18325, 18373, 18421, 18470, 18518, 18566, 18614, + 18663, 18711, 18759, 18807, 18855, 18903, 18951, 19000, + 19048, 19096, 19144, 19192, 19240, 19288, 19336, 19384, + 19432, 19480, 19528, 19576, 19624, 19672, 19720, 19768, + 19816, 19864, 19912, 19959, 20007, 20055, 20103, 20151, + 20199, 20246, 20294, 20342, 20390, 20438, 20485, 20533, + 20581, 20629, 20676, 20724, 20772, 20819, 20867, 20915, + 20962, 21010, 21057, 21105, 21153, 21200, 21248, 21295, + 21343, 21390, 21438, 21485, 21533, 21580, 21628, 21675, + 21723, 21770, 21817, 21865, 21912, 21960, 22007, 22054, + 22102, 22149, 22196, 22243, 22291, 22338, 22385, 22432, + 22480, 22527, 22574, 22621, 22668, 22716, 22763, 22810, + 22857, 22904, 22951, 22998, 23045, 23092, 23139, 23186, + 23233, 23280, 23327, 23374, 23421, 23468, 23515, 23562, + 23609, 23656, 23703, 23750, 23796, 23843, 23890, 23937, + 23984, 24030, 24077, 24124, 24171, 24217, 24264, 24311, + 24357, 24404, 24451, 24497, 24544, 24591, 24637, 24684, + 24730, 24777, 24823, 24870, 24916, 24963, 25009, 25056, + 25102, 25149, 25195, 25241, 25288, 25334, 25381, 25427, + 25473, 25520, 25566, 25612, 25658, 25705, 25751, 25797, + 25843, 25889, 25936, 25982, 26028, 26074, 26120, 26166, + 26212, 26258, 26304, 26350, 26396, 26442, 26488, 26534, + 26580, 26626, 26672, 26718, 26764, 26810, 26856, 26902, + 26947, 26993, 27039, 27085, 27131, 27176, 27222, 27268, + 27313, 27359, 27405, 27450, 27496, 27542, 27587, 27633, + 27678, 27724, 27770, 27815, 27861, 27906, 27952, 27997, + 28042, 28088, 28133, 28179, 28224, 28269, 28315, 28360, + 28405, 28451, 28496, 28541, 28586, 28632, 28677, 28722, + 28767, 28812, 28858, 28903, 28948, 28993, 29038, 29083, + 29128, 29173, 29218, 29263, 29308, 29353, 29398, 29443, + 29488, 29533, 29577, 29622, 29667, 29712, 29757, 29801, + 29846, 29891, 29936, 29980, 30025, 30070, 30114, 30159, + 30204, 30248, 30293, 30337, 30382, 30427, 30471, 30516, + 30560, 30604, 30649, 30693, 30738, 30782, 30826, 30871, + 30915, 30959, 31004, 31048, 31092, 31136, 31181, 31225, + 31269, 31313, 31357, 31402, 31446, 31490, 31534, 31578, + 31622, 31666, 31710, 31754, 31798, 31842, 31886, 31930, + 31974, 32017, 32061, 32105, 32149, 32193, 32236, 32280, + 32324, 32368, 32411, 32455, 32499, 32542, 32586, 32630, + 32673, 32717, 32760, 32804, 32847, 32891, 32934, 32978, + 33021, 33065, 33108, 33151, 33195, 33238, 33281, 33325, + 33368, 33411, 33454, 33498, 33541, 33584, 33627, 33670, + 33713, 33756, 33799, 33843, 33886, 33929, 33972, 34015, + 34057, 34100, 34143, 34186, 34229, 34272, 34315, 34358, + 34400, 34443, 34486, 34529, 34571, 34614, 34657, 34699, + 34742, 34785, 34827, 34870, 34912, 34955, 34997, 35040, + 35082, 35125, 35167, 35210, 35252, 35294, 35337, 35379, + 35421, 35464, 35506, 35548, 35590, 35633, 35675, 35717, + 35759, 35801, 35843, 35885, 35927, 35969, 36011, 36053, + 36095, 36137, 36179, 36221, 36263, 36305, 36347, 36388, + 36430, 36472, 36514, 36556, 36597, 36639, 36681, 36722, + 36764, 36805, 36847, 36889, 36930, 36972, 37013, 37055, + 37096, 37137, 37179, 37220, 37262, 37303, 37344, 37386, + 37427, 37468, 37509, 37551, 37592, 37633, 37674, 37715, + 37756, 37797, 37838, 37879, 37920, 37961, 38002, 38043, + 38084, 38125, 38166, 38207, 38248, 38288, 38329, 38370, + 38411, 38451, 38492, 38533, 38573, 38614, 38655, 38695, + 38736, 38776, 38817, 38857, 38898, 38938, 38979, 39019, + 39059, 39100, 39140, 39180, 39221, 39261, 39301, 39341, + 39382, 39422, 39462, 39502, 39542, 39582, 39622, 39662, + 39702, 39742, 39782, 39822, 39862, 39902, 39942, 39982, + 40021, 40061, 40101, 40141, 40180, 40220, 40260, 40299, + 40339, 40379, 40418, 40458, 40497, 40537, 40576, 40616, + 40655, 40695, 40734, 40773, 40813, 40852, 40891, 40931, + 40970, 41009, 41048, 41087, 41127, 41166, 41205, 41244, + 41283, 41322, 41361, 41400, 41439, 41478, 41517, 41556, + 41595, 41633, 41672, 41711, 41750, 41788, 41827, 41866, + 41904, 41943, 41982, 42020, 42059, 42097, 42136, 42174, + 42213, 42251, 42290, 42328, 42366, 42405, 42443, 42481, + 42520, 42558, 42596, 42634, 42672, 42711, 42749, 42787, + 42825, 42863, 42901, 42939, 42977, 43015, 43053, 43091, + 43128, 43166, 43204, 43242, 43280, 43317, 43355, 43393, + 43430, 43468, 43506, 43543, 43581, 43618, 43656, 43693, + 43731, 43768, 43806, 43843, 43880, 43918, 43955, 43992, + 44029, 44067, 44104, 44141, 44178, 44215, 44252, 44289, + 44326, 44363, 44400, 44437, 44474, 44511, 44548, 44585, + 44622, 44659, 44695, 44732, 44769, 44806, 44842, 44879, + 44915, 44952, 44989, 45025, 45062, 45098, 45135, 45171, + 45207, 45244, 45280, 45316, 45353, 45389, 45425, 45462, + 45498, 45534, 45570, 45606, 45642, 45678, 45714, 45750, + 45786, 45822, 45858, 45894, 45930, 45966, 46002, 46037, + 46073, 46109, 46145, 46180, 46216, 46252, 46287, 46323, + 46358, 46394, 46429, 46465, 46500, 46536, 46571, 46606, + 46642, 46677, 46712, 46747, 46783, 46818, 46853, 46888, + 46923, 46958, 46993, 47028, 47063, 47098, 47133, 47168, + 47203, 47238, 47273, 47308, 47342, 47377, 47412, 47446, + 47481, 47516, 47550, 47585, 47619, 47654, 47688, 47723, + 47757, 47792, 47826, 47861, 47895, 47929, 47963, 47998, + 48032, 48066, 48100, 48134, 48168, 48202, 48237, 48271, + 48305, 48338, 48372, 48406, 48440, 48474, 48508, 48542, + 48575, 48609, 48643, 48676, 48710, 48744, 48777, 48811, + 48844, 48878, 48911, 48945, 48978, 49012, 49045, 49078, + 49112, 49145, 49178, 49211, 49244, 49278, 49311, 49344, + 49377, 49410, 49443, 49476, 49509, 49542, 49575, 49608, + 49640, 49673, 49706, 49739, 49771, 49804, 49837, 49869, + 49902, 49935, 49967, 50000, 50032, 50064, 50097, 50129, + 50162, 50194, 50226, 50259, 50291, 50323, 50355, 50387, + 50420, 50452, 50484, 50516, 50548, 50580, 50612, 50644, + 50675, 50707, 50739, 50771, 50803, 50834, 50866, 50898, + 50929, 50961, 50993, 51024, 51056, 51087, 51119, 51150, + 51182, 51213, 51244, 51276, 51307, 51338, 51369, 51401, + 51432, 51463, 51494, 51525, 51556, 51587, 51618, 51649, + 51680, 51711, 51742, 51773, 51803, 51834, 51865, 51896, + 51926, 51957, 51988, 52018, 52049, 52079, 52110, 52140, + 52171, 52201, 52231, 52262, 52292, 52322, 52353, 52383, + 52413, 52443, 52473, 52503, 52534, 52564, 52594, 52624, + 52653, 52683, 52713, 52743, 52773, 52803, 52832, 52862, + 52892, 52922, 52951, 52981, 53010, 53040, 53069, 53099, + 53128, 53158, 53187, 53216, 53246, 53275, 53304, 53334, + 53363, 53392, 53421, 53450, 53479, 53508, 53537, 53566, + 53595, 53624, 53653, 53682, 53711, 53739, 53768, 53797, + 53826, 53854, 53883, 53912, 53940, 53969, 53997, 54026, + 54054, 54082, 54111, 54139, 54167, 54196, 54224, 54252, + 54280, 54309, 54337, 54365, 54393, 54421, 54449, 54477, + 54505, 54533, 54560, 54588, 54616, 54644, 54672, 54699, + 54727, 54755, 54782, 54810, 54837, 54865, 54892, 54920, + 54947, 54974, 55002, 55029, 55056, 55084, 55111, 55138, + 55165, 55192, 55219, 55246, 55274, 55300, 55327, 55354, + 55381, 55408, 55435, 55462, 55489, 55515, 55542, 55569, + 55595, 55622, 55648, 55675, 55701, 55728, 55754, 55781, + 55807, 55833, 55860, 55886, 55912, 55938, 55965, 55991, + 56017, 56043, 56069, 56095, 56121, 56147, 56173, 56199, + 56225, 56250, 56276, 56302, 56328, 56353, 56379, 56404, + 56430, 56456, 56481, 56507, 56532, 56557, 56583, 56608, + 56633, 56659, 56684, 56709, 56734, 56760, 56785, 56810, + 56835, 56860, 56885, 56910, 56935, 56959, 56984, 57009, + 57034, 57059, 57083, 57108, 57133, 57157, 57182, 57206, + 57231, 57255, 57280, 57304, 57329, 57353, 57377, 57402, + 57426, 57450, 57474, 57498, 57522, 57546, 57570, 57594, + 57618, 57642, 57666, 57690, 57714, 57738, 57762, 57785, + 57809, 57833, 57856, 57880, 57903, 57927, 57950, 57974, + 57997, 58021, 58044, 58067, 58091, 58114, 58137, 58160, + 58183, 58207, 58230, 58253, 58276, 58299, 58322, 58345, + 58367, 58390, 58413, 58436, 58459, 58481, 58504, 58527, + 58549, 58572, 58594, 58617, 58639, 58662, 58684, 58706, + 58729, 58751, 58773, 58795, 58818, 58840, 58862, 58884, + 58906, 58928, 58950, 58972, 58994, 59016, 59038, 59059, + 59081, 59103, 59125, 59146, 59168, 59190, 59211, 59233, + 59254, 59276, 59297, 59318, 59340, 59361, 59382, 59404, + 59425, 59446, 59467, 59488, 59509, 59530, 59551, 59572, + 59593, 59614, 59635, 59656, 59677, 59697, 59718, 59739, + 59759, 59780, 59801, 59821, 59842, 59862, 59883, 59903, + 59923, 59944, 59964, 59984, 60004, 60025, 60045, 60065, + 60085, 60105, 60125, 60145, 60165, 60185, 60205, 60225, + 60244, 60264, 60284, 60304, 60323, 60343, 60363, 60382, + 60402, 60421, 60441, 60460, 60479, 60499, 60518, 60537, + 60556, 60576, 60595, 60614, 60633, 60652, 60671, 60690, + 60709, 60728, 60747, 60766, 60785, 60803, 60822, 60841, + 60859, 60878, 60897, 60915, 60934, 60952, 60971, 60989, + 61007, 61026, 61044, 61062, 61081, 61099, 61117, 61135, + 61153, 61171, 61189, 61207, 61225, 61243, 61261, 61279, + 61297, 61314, 61332, 61350, 61367, 61385, 61403, 61420, + 61438, 61455, 61473, 61490, 61507, 61525, 61542, 61559, + 61577, 61594, 61611, 61628, 61645, 61662, 61679, 61696, + 61713, 61730, 61747, 61764, 61780, 61797, 61814, 61831, + 61847, 61864, 61880, 61897, 61913, 61930, 61946, 61963, + 61979, 61995, 62012, 62028, 62044, 62060, 62076, 62092, + 62108, 62125, 62141, 62156, 62172, 62188, 62204, 62220, + 62236, 62251, 62267, 62283, 62298, 62314, 62329, 62345, + 62360, 62376, 62391, 62407, 62422, 62437, 62453, 62468, + 62483, 62498, 62513, 62528, 62543, 62558, 62573, 62588, + 62603, 62618, 62633, 62648, 62662, 62677, 62692, 62706, + 62721, 62735, 62750, 62764, 62779, 62793, 62808, 62822, + 62836, 62850, 62865, 62879, 62893, 62907, 62921, 62935, + 62949, 62963, 62977, 62991, 63005, 63019, 63032, 63046, + 63060, 63074, 63087, 63101, 63114, 63128, 63141, 63155, + 63168, 63182, 63195, 63208, 63221, 63235, 63248, 63261, + 63274, 63287, 63300, 63313, 63326, 63339, 63352, 63365, + 63378, 63390, 63403, 63416, 63429, 63441, 63454, 63466, + 63479, 63491, 63504, 63516, 63528, 63541, 63553, 63565, + 63578, 63590, 63602, 63614, 63626, 63638, 63650, 63662, + 63674, 63686, 63698, 63709, 63721, 63733, 63745, 63756, + 63768, 63779, 63791, 63803, 63814, 63825, 63837, 63848, + 63859, 63871, 63882, 63893, 63904, 63915, 63927, 63938, + 63949, 63960, 63971, 63981, 63992, 64003, 64014, 64025, + 64035, 64046, 64057, 64067, 64078, 64088, 64099, 64109, + 64120, 64130, 64140, 64151, 64161, 64171, 64181, 64192, + 64202, 64212, 64222, 64232, 64242, 64252, 64261, 64271, + 64281, 64291, 64301, 64310, 64320, 64330, 64339, 64349, + 64358, 64368, 64377, 64387, 64396, 64405, 64414, 64424, + 64433, 64442, 64451, 64460, 64469, 64478, 64487, 64496, + 64505, 64514, 64523, 64532, 64540, 64549, 64558, 64566, + 64575, 64584, 64592, 64600, 64609, 64617, 64626, 64634, + 64642, 64651, 64659, 64667, 64675, 64683, 64691, 64699, + 64707, 64715, 64723, 64731, 64739, 64747, 64754, 64762, + 64770, 64777, 64785, 64793, 64800, 64808, 64815, 64822, + 64830, 64837, 64844, 64852, 64859, 64866, 64873, 64880, + 64887, 64895, 64902, 64908, 64915, 64922, 64929, 64936, + 64943, 64949, 64956, 64963, 64969, 64976, 64982, 64989, + 64995, 65002, 65008, 65015, 65021, 65027, 65033, 65040, + 65046, 65052, 65058, 65064, 65070, 65076, 65082, 65088, + 65094, 65099, 65105, 65111, 65117, 65122, 65128, 65133, + 65139, 65144, 65150, 65155, 65161, 65166, 65171, 65177, + 65182, 65187, 65192, 65197, 65202, 65207, 65212, 65217, + 65222, 65227, 65232, 65237, 65242, 65246, 65251, 65256, + 65260, 65265, 65270, 65274, 65279, 65283, 65287, 65292, + 65296, 65300, 65305, 65309, 65313, 65317, 65321, 65325, + 65329, 65333, 65337, 65341, 65345, 65349, 65352, 65356, + 65360, 65363, 65367, 65371, 65374, 65378, 65381, 65385, + 65388, 65391, 65395, 65398, 65401, 65404, 65408, 65411, + 65414, 65417, 65420, 65423, 65426, 65429, 65431, 65434, + 65437, 65440, 65442, 65445, 65448, 65450, 65453, 65455, + 65458, 65460, 65463, 65465, 65467, 65470, 65472, 65474, + 65476, 65478, 65480, 65482, 65484, 65486, 65488, 65490, + 65492, 65494, 65496, 65497, 65499, 65501, 65502, 65504, + 65505, 65507, 65508, 65510, 65511, 65513, 65514, 65515, + 65516, 65518, 65519, 65520, 65521, 65522, 65523, 65524, + 65525, 65526, 65527, 65527, 65528, 65529, 65530, 65530, + 65531, 65531, 65532, 65532, 65533, 65533, 65534, 65534, + 65534, 65535, 65535, 65535, 65535, 65535, 65535, 65535}; -const fixed_t *finecosine = &finesine[FINEANGLES/4]; +const fixed_t *finecosine = &finesine[FINEANGLES / 4]; const angle_t tantoangle[2049] = -{ - 0,333772,667544,1001315,1335086,1668857,2002626,2336395, - 2670163,3003929,3337694,3671457,4005219,4338979,4672736,5006492, - 5340245,5673995,6007743,6341488,6675230,7008968,7342704,7676435, - 8010164,8343888,8677609,9011325,9345037,9678744,10012447,10346145, - 10679838,11013526,11347209,11680887,12014558,12348225,12681885,13015539, - 13349187,13682829,14016464,14350092,14683714,15017328,15350936,15684536, - 16018129,16351714,16685291,17018860,17352422,17685974,18019518,18353054, - 18686582,19020100,19353610,19687110,20020600,20354080,20687552,21021014, - 21354466,21687906,22021338,22354758,22688168,23021568,23354956,23688332, - 24021698,24355052,24688396,25021726,25355046,25688352,26021648,26354930, - 26688200,27021456,27354702,27687932,28021150,28354356,28687548,29020724, - 29353888,29687038,30020174,30353296,30686404,31019496,31352574,31685636, - 32018684,32351718,32684734,33017736,33350722,33683692,34016648,34349584, - 34682508,35015412,35348300,35681172,36014028,36346868,36679688,37012492, - 37345276,37678044,38010792,38343524,38676240,39008936,39341612,39674272, - 40006912,40339532,40672132,41004716,41337276,41669820,42002344,42334848, - 42667332,42999796,43332236,43664660,43997060,44329444,44661800,44994140, - 45326456,45658752,45991028,46323280,46655512,46987720,47319908,47652072, - 47984212,48316332,48648428,48980500,49312548,49644576,49976580,50308556, - 50640512,50972444,51304352,51636236,51968096,52299928,52631740,52963524, - 53295284,53627020,53958728,54290412,54622068,54953704,55285308,55616888, - 55948444,56279972,56611472,56942948,57274396,57605816,57937212,58268576, - 58599916,58931228,59262512,59593768,59924992,60256192,60587364,60918508, - 61249620,61580704,61911760,62242788,62573788,62904756,63235692,63566604, - 63897480,64228332,64559148,64889940,65220696,65551424,65882120,66212788, - 66543420,66874024,67204600,67535136,67865648,68196120,68526568,68856984, - 69187360,69517712,69848024,70178304,70508560,70838776,71168960,71499112, - 71829224,72159312,72489360,72819376,73149360,73479304,73809216,74139096, - 74468936,74798744,75128520,75458264,75787968,76117632,76447264,76776864, - 77106424,77435952,77765440,78094888,78424304,78753688,79083032,79412336, - 79741608,80070840,80400032,80729192,81058312,81387392,81716432,82045440, - 82374408,82703336,83032224,83361080,83689896,84018664,84347400,84676096, - 85004760,85333376,85661952,85990488,86318984,86647448,86975864,87304240, - 87632576,87960872,88289128,88617344,88945520,89273648,89601736,89929792, - 90257792,90585760,90913688,91241568,91569408,91897200,92224960,92552672, - 92880336,93207968,93535552,93863088,94190584,94518040,94845448,95172816, - 95500136,95827416,96154648,96481832,96808976,97136080,97463136,97790144, - 98117112,98444032,98770904,99097736,99424520,99751256,100077944,100404592, - 100731192,101057744,101384248,101710712,102037128,102363488,102689808,103016080, - 103342312,103668488,103994616,104320696,104646736,104972720,105298656,105624552, - 105950392,106276184,106601928,106927624,107253272,107578872,107904416,108229920, - 108555368,108880768,109206120,109531416,109856664,110181872,110507016,110832120, - 111157168,111482168,111807112,112132008,112456856,112781648,113106392,113431080, - 113755720,114080312,114404848,114729328,115053760,115378136,115702464,116026744, - 116350960,116675128,116999248,117323312,117647320,117971272,118295176,118619024, - 118942816,119266560,119590248,119913880,120237456,120560984,120884456,121207864, - 121531224,121854528,122177784,122500976,122824112,123147200,123470224,123793200, - 124116120,124438976,124761784,125084528,125407224,125729856,126052432,126374960, - 126697424,127019832,127342184,127664472,127986712,128308888,128631008,128953072, - 129275080,129597024,129918912,130240744,130562520,130884232,131205888,131527480, - 131849016,132170496,132491912,132813272,133134576,133455816,133776992,134098120, - 134419184,134740176,135061120,135382000,135702816,136023584,136344272,136664912, - 136985488,137306016,137626464,137946864,138267184,138587456,138907664,139227808, - 139547904,139867920,140187888,140507776,140827616,141147392,141467104,141786752, - 142106336,142425856,142745312,143064720,143384048,143703312,144022512,144341664, - 144660736,144979744,145298704,145617584,145936400,146255168,146573856,146892480, - 147211040,147529536,147847968,148166336,148484640,148802880,149121056,149439152, - 149757200,150075168,150393072,150710912,151028688,151346400,151664048,151981616, - 152299136,152616576,152933952,153251264,153568496,153885680,154202784,154519824, - 154836784,155153696,155470528,155787296,156104000,156420624,156737200,157053696, - 157370112,157686480,158002768,158318976,158635136,158951216,159267232,159583168, - 159899040,160214848,160530592,160846256,161161840,161477376,161792832,162108208, - 162423520,162738768,163053952,163369040,163684080,163999040,164313936,164628752, - 164943504,165258176,165572784,165887312,166201776,166516160,166830480,167144736, - 167458912,167773008,168087040,168400992,168714880,169028688,169342432,169656096, - 169969696,170283216,170596672,170910032,171223344,171536576,171849728,172162800, - 172475808,172788736,173101600,173414384,173727104,174039728,174352288,174664784, - 174977200,175289536,175601792,175913984,176226096,176538144,176850096,177161984, - 177473792,177785536,178097200,178408784,178720288,179031728,179343088,179654368, - 179965568,180276704,180587744,180898720,181209616,181520448,181831184,182141856, - 182452448,182762960,183073408,183383760,183694048,184004240,184314368,184624416, - 184934400,185244288,185554096,185863840,186173504,186483072,186792576,187102000, - 187411344,187720608,188029808,188338912,188647936,188956896,189265760,189574560, - 189883264,190191904,190500448,190808928,191117312,191425632,191733872,192042016, - 192350096,192658096,192966000,193273840,193581584,193889264,194196848,194504352, - 194811792,195119136,195426400,195733584,196040688,196347712,196654656,196961520, - 197268304,197574992,197881616,198188144,198494592,198800960,199107248,199413456, - 199719584,200025616,200331584,200637456,200943248,201248960,201554576,201860128, - 202165584,202470960,202776256,203081456,203386592,203691632,203996592,204301472, - 204606256,204910976,205215600,205520144,205824592,206128960,206433248,206737456, - 207041584,207345616,207649568,207953424,208257216,208560912,208864512,209168048, - 209471488,209774832,210078112,210381296,210684384,210987408,211290336,211593184, - 211895936,212198608,212501184,212803680,213106096,213408432,213710672,214012816, - 214314880,214616864,214918768,215220576,215522288,215823920,216125472,216426928, - 216728304,217029584,217330784,217631904,217932928,218233856,218534704,218835472, - 219136144,219436720,219737216,220037632,220337952,220638192,220938336,221238384, - 221538352,221838240,222138032,222437728,222737344,223036880,223336304,223635664, - 223934912,224234096,224533168,224832160,225131072,225429872,225728608,226027232, - 226325776,226624240,226922608,227220880,227519056,227817152,228115168,228413088, - 228710912,229008640,229306288,229603840,229901312,230198688,230495968,230793152, - 231090256,231387280,231684192,231981024,232277760,232574416,232870960,233167440, - 233463808,233760096,234056288,234352384,234648384,234944304,235240128,235535872, - 235831504,236127056,236422512,236717888,237013152,237308336,237603424,237898416, - 238193328,238488144,238782864,239077488,239372016,239666464,239960816,240255072, - 240549232,240843312,241137280,241431168,241724960,242018656,242312256,242605776, - 242899200,243192512,243485744,243778896,244071936,244364880,244657744,244950496, - 245243168,245535744,245828224,246120608,246412912,246705104,246997216,247289216, - 247581136,247872960,248164688,248456320,248747856,249039296,249330640,249621904, - 249913056,250204128,250495088,250785968,251076736,251367424,251658016,251948512, - 252238912,252529200,252819408,253109520,253399536,253689456,253979280,254269008, - 254558640,254848176,255137632,255426976,255716224,256005376,256294432,256583392, - 256872256,257161024,257449696,257738272,258026752,258315136,258603424,258891600, - 259179696,259467696,259755600,260043392,260331104,260618704,260906224,261193632, - 261480960,261768176,262055296,262342320,262629248,262916080,263202816,263489456, - 263776000,264062432,264348784,264635024,264921168,265207216,265493168,265779024, - 266064784,266350448,266636000,266921472,267206832,267492096,267777264,268062336, - 268347312,268632192,268916960,269201632,269486208,269770688,270055072,270339360, - 270623552,270907616,271191616,271475488,271759296,272042976,272326560,272610048, - 272893440,273176736,273459936,273743040,274026048,274308928,274591744,274874432, - 275157024,275439520,275721920,276004224,276286432,276568512,276850528,277132416, - 277414240,277695936,277977536,278259040,278540448,278821728,279102944,279384032, - 279665056,279945952,280226752,280507456,280788064,281068544,281348960,281629248, - 281909472,282189568,282469568,282749440,283029248,283308960,283588544,283868032, - 284147424,284426720,284705920,284985024,285264000,285542912,285821696,286100384, - 286378976,286657440,286935840,287214112,287492320,287770400,288048384,288326240, - 288604032,288881696,289159264,289436768,289714112,289991392,290268576,290545632, - 290822592,291099456,291376224,291652896,291929440,292205888,292482272,292758528, - 293034656,293310720,293586656,293862496,294138240,294413888,294689440,294964864, - 295240192,295515424,295790560,296065600,296340512,296615360,296890080,297164704, - 297439200,297713632,297987936,298262144,298536256,298810240,299084160,299357952, - 299631648,299905248,300178720,300452128,300725408,300998592,301271680,301544640, - 301817536,302090304,302362976,302635520,302908000,303180352,303452608,303724768, - 303996800,304268768,304540608,304812320,305083968,305355520,305626944,305898272, - 306169472,306440608,306711616,306982528,307253344,307524064,307794656,308065152, - 308335552,308605856,308876032,309146112,309416096,309685984,309955744,310225408, - 310494976,310764448,311033824,311303072,311572224,311841280,312110208,312379040, - 312647776,312916416,313184960,313453376,313721696,313989920,314258016,314526016, - 314793920,315061728,315329408,315597024,315864512,316131872,316399168,316666336, - 316933408,317200384,317467232,317733984,318000640,318267200,318533632,318799968, - 319066208,319332352,319598368,319864288,320130112,320395808,320661408,320926912, - 321192320,321457632,321722816,321987904,322252864,322517760,322782528,323047200, - 323311744,323576192,323840544,324104800,324368928,324632992,324896928,325160736, - 325424448,325688096,325951584,326215008,326478304,326741504,327004608,327267584, - 327530464,327793248,328055904,328318496,328580960,328843296,329105568,329367712, - 329629760,329891680,330153536,330415264,330676864,330938400,331199808,331461120, - 331722304,331983392,332244384,332505280,332766048,333026752,333287296,333547776, - 333808128,334068384,334328544,334588576,334848512,335108352,335368064,335627712, - 335887200,336146624,336405920,336665120,336924224,337183200,337442112,337700864, - 337959552,338218112,338476576,338734944,338993184,339251328,339509376,339767296, - 340025120,340282848,340540480,340797984,341055392,341312704,341569888,341826976, - 342083968,342340832,342597600,342854272,343110848,343367296,343623648,343879904, - 344136032,344392064,344648000,344903808,345159520,345415136,345670656,345926048, - 346181344,346436512,346691616,346946592,347201440,347456224,347710880,347965440, - 348219872,348474208,348728448,348982592,349236608,349490528,349744320,349998048, - 350251648,350505152,350758528,351011808,351264992,351518048,351771040,352023872, - 352276640,352529280,352781824,353034272,353286592,353538816,353790944,354042944, - 354294880,354546656,354798368,355049952,355301440,355552800,355804096,356055264, - 356306304,356557280,356808128,357058848,357309504,357560032,357810464,358060768, - 358311008,358561088,358811104,359060992,359310784,359560480,359810048,360059520, - 360308896,360558144,360807296,361056352,361305312,361554144,361802880,362051488, - 362300032,362548448,362796736,363044960,363293056,363541024,363788928,364036704, - 364284384,364531936,364779392,365026752,365274016,365521152,365768192,366015136, - 366261952,366508672,366755296,367001792,367248192,367494496,367740704,367986784, - 368232768,368478656,368724416,368970080,369215648,369461088,369706432,369951680, - 370196800,370441824,370686752,370931584,371176288,371420896,371665408,371909792, - 372154080,372398272,372642336,372886304,373130176,373373952,373617600,373861152, - 374104608,374347936,374591168,374834304,375077312,375320224,375563040,375805760, - 376048352,376290848,376533248,376775520,377017696,377259776,377501728,377743584, - 377985344,378227008,378468544,378709984,378951328,379192544,379433664,379674688, - 379915584,380156416,380397088,380637696,380878176,381118560,381358848,381599040, - 381839104,382079072,382318912,382558656,382798304,383037856,383277280,383516640, - 383755840,383994976,384233984,384472896,384711712,384950400,385188992,385427488, - 385665888,385904160,386142336,386380384,386618368,386856224,387093984,387331616, - 387569152,387806592,388043936,388281152,388518272,388755296,388992224,389229024, - 389465728,389702336,389938816,390175200,390411488,390647680,390883744,391119712, - 391355584,391591328,391826976,392062528,392297984,392533312,392768544,393003680, - 393238720,393473632,393708448,393943168,394177760,394412256,394646656,394880960, - 395115136,395349216,395583200,395817088,396050848,396284512,396518080,396751520, - 396984864,397218112,397451264,397684288,397917248,398150080,398382784,398615424, - 398847936,399080320,399312640,399544832,399776928,400008928,400240832,400472608, - 400704288,400935872,401167328,401398720,401629984,401861120,402092192,402323136, - 402553984,402784736,403015360,403245888,403476320,403706656,403936896,404167008, - 404397024,404626944,404856736,405086432,405316032,405545536,405774912,406004224, - 406233408,406462464,406691456,406920320,407149088,407377760,407606336,407834784, - 408063136,408291392,408519520,408747584,408975520,409203360,409431072,409658720, - 409886240,410113664,410340992,410568192,410795296,411022304,411249216,411476032, - 411702720,411929312,412155808,412382176,412608480,412834656,413060736,413286720, - 413512576,413738336,413964000,414189568,414415040,414640384,414865632,415090784, - 415315840,415540800,415765632,415990368,416215008,416439552,416663968,416888288, - 417112512,417336640,417560672,417784576,418008384,418232096,418455712,418679200, - 418902624,419125920,419349120,419572192,419795200,420018080,420240864,420463552, - 420686144,420908608,421130976,421353280,421575424,421797504,422019488,422241344, - 422463104,422684768,422906336,423127776,423349120,423570400,423791520,424012576, - 424233536,424454368,424675104,424895744,425116288,425336736,425557056,425777280, - 425997408,426217440,426437376,426657184,426876928,427096544,427316064,427535488, - 427754784,427974016,428193120,428412128,428631040,428849856,429068544,429287168, - 429505664,429724064,429942368,430160576,430378656,430596672,430814560,431032352, - 431250048,431467616,431685120,431902496,432119808,432336992,432554080,432771040, - 432987936,433204736,433421408,433637984,433854464,434070848,434287104,434503296, - 434719360,434935360,435151232,435367008,435582656,435798240,436013696,436229088, - 436444352,436659520,436874592,437089568,437304416,437519200,437733856,437948416, - 438162880,438377248,438591520,438805696,439019744,439233728,439447584,439661344, - 439875008,440088576,440302048,440515392,440728672,440941824,441154880,441367872, - 441580736,441793472,442006144,442218720,442431168,442643552,442855808,443067968, - 443280032,443492000,443703872,443915648,444127296,444338880,444550336,444761696, - 444972992,445184160,445395232,445606176,445817056,446027840,446238496,446449088, - 446659552,446869920,447080192,447290400,447500448,447710432,447920320,448130112, - 448339776,448549376,448758848,448968224,449177536,449386720,449595808,449804800, - 450013664,450222464,450431168,450639776,450848256,451056640,451264960,451473152, - 451681248,451889248,452097152,452304960,452512672,452720288,452927808,453135232, - 453342528,453549760,453756864,453963904,454170816,454377632,454584384,454791008, - 454997536,455203968,455410304,455616544,455822688,456028704,456234656,456440512, - 456646240,456851904,457057472,457262912,457468256,457673536,457878688,458083744, - 458288736,458493600,458698368,458903040,459107616,459312096,459516480,459720768, - 459924960,460129056,460333056,460536960,460740736,460944448,461148064,461351584, - 461554976,461758304,461961536,462164640,462367680,462570592,462773440,462976160, - 463178816,463381344,463583776,463786144,463988384,464190560,464392608,464594560, - 464796448,464998208,465199872,465401472,465602944,465804320,466005600,466206816, - 466407904,466608896,466809824,467010624,467211328,467411936,467612480,467812896, - 468013216,468213440,468413600,468613632,468813568,469013440,469213184,469412832, - 469612416,469811872,470011232,470210528,470409696,470608800,470807776,471006688, - 471205472,471404192,471602784,471801312,471999712,472198048,472396288,472594400, - 472792448,472990400,473188256,473385984,473583648,473781216,473978688,474176064, - 474373344,474570528,474767616,474964608,475161504,475358336,475555040,475751648, - 475948192,476144608,476340928,476537184,476733312,476929376,477125344,477321184, - 477516960,477712640,477908224,478103712,478299104,478494400,478689600,478884704, - 479079744,479274656,479469504,479664224,479858880,480053408,480247872,480442240, - 480636512,480830656,481024736,481218752,481412640,481606432,481800128,481993760, - 482187264,482380704,482574016,482767264,482960416,483153472,483346432,483539296, - 483732064,483924768,484117344,484309856,484502240,484694560,484886784,485078912, - 485270944,485462880,485654720,485846464,486038144,486229696,486421184,486612576, - 486803840,486995040,487186176,487377184,487568096,487758912,487949664,488140320, - 488330880,488521312,488711712,488901984,489092160,489282240,489472256,489662176, - 489851968,490041696,490231328,490420896,490610336,490799712,490988960,491178144, - 491367232,491556224,491745120,491933920,492122656,492311264,492499808,492688256, - 492876608,493064864,493253056,493441120,493629120,493817024,494004832,494192544, - 494380160,494567712,494755136,494942496,495129760,495316928,495504000,495691008, - 495877888,496064704,496251424,496438048,496624608,496811040,496997408,497183680, - 497369856,497555936,497741920,497927840,498113632,498299360,498484992,498670560, - 498856000,499041376,499226656,499411840,499596928,499781920,499966848,500151680, - 500336416,500521056,500705600,500890080,501074464,501258752,501442944,501627040, - 501811072,501995008,502178848,502362592,502546240,502729824,502913312,503096704, - 503280000,503463232,503646368,503829408,504012352,504195200,504377984,504560672, - 504743264,504925760,505108192,505290496,505472736,505654912,505836960,506018944, - 506200832,506382624,506564320,506745952,506927488,507108928,507290272,507471552, - 507652736,507833824,508014816,508195744,508376576,508557312,508737952,508918528, - 509099008,509279392,509459680,509639904,509820032,510000064,510180000,510359872, - 510539648,510719328,510898944,511078432,511257856,511437216,511616448,511795616, - 511974688,512153664,512332576,512511392,512690112,512868768,513047296,513225792, - 513404160,513582432,513760640,513938784,514116800,514294752,514472608,514650368, - 514828064,515005664,515183168,515360608,515537952,515715200,515892352,516069440, - 516246432,516423328,516600160,516776896,516953536,517130112,517306592,517482976, - 517659264,517835488,518011616,518187680,518363648,518539520,518715296,518891008, - 519066624,519242144,519417600,519592960,519768256,519943424,520118528,520293568, - 520468480,520643328,520818112,520992800,521167392,521341888,521516320,521690656, - 521864896,522039072,522213152,522387168,522561056,522734912,522908640,523082304, - 523255872,523429376,523602784,523776096,523949312,524122464,524295552,524468512, - 524641440,524814240,524986976,525159616,525332192,525504640,525677056,525849344, - 526021568,526193728,526365792,526537760,526709632,526881440,527053152,527224800, - 527396352,527567840,527739200,527910528,528081728,528252864,528423936,528594880, - 528765760,528936576,529107296,529277920,529448480,529618944,529789344,529959648, - 530129856,530300000,530470048,530640000,530809888,530979712,531149440,531319072, - 531488608,531658080,531827488,531996800,532166016,532335168,532504224,532673184, - 532842080,533010912,533179616,533348288,533516832,533685312,533853728,534022048, - 534190272,534358432,534526496,534694496,534862400,535030240,535197984,535365632, - 535533216,535700704,535868128,536035456,536202720,536369888,536536992,536704000, - 536870912 -}; - -// Now where did these came from? -const byte gammatable[5][256] = -{ { - 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16, - 17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32, - 33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48, - 49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64, - 65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80, - 81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96, - 97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112, - 113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128, - 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, - 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, - 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175, - 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, - 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207, - 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223, - 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239, - 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255 - }, + 0, 333772, 667544, 1001315, 1335086, 1668857, 2002626, 2336395, + 2670163, 3003929, 3337694, 3671457, 4005219, 4338979, 4672736, 5006492, + 5340245, 5673995, 6007743, 6341488, 6675230, 7008968, 7342704, 7676435, + 8010164, 8343888, 8677609, 9011325, 9345037, 9678744, 10012447, 10346145, + 10679838, 11013526, 11347209, 11680887, 12014558, 12348225, 12681885, 13015539, + 13349187, 13682829, 14016464, 14350092, 14683714, 15017328, 15350936, 15684536, + 16018129, 16351714, 16685291, 17018860, 17352422, 17685974, 18019518, 18353054, + 18686582, 19020100, 19353610, 19687110, 20020600, 20354080, 20687552, 21021014, + 21354466, 21687906, 22021338, 22354758, 22688168, 23021568, 23354956, 23688332, + 24021698, 24355052, 24688396, 25021726, 25355046, 25688352, 26021648, 26354930, + 26688200, 27021456, 27354702, 27687932, 28021150, 28354356, 28687548, 29020724, + 29353888, 29687038, 30020174, 30353296, 30686404, 31019496, 31352574, 31685636, + 32018684, 32351718, 32684734, 33017736, 33350722, 33683692, 34016648, 34349584, + 34682508, 35015412, 35348300, 35681172, 36014028, 36346868, 36679688, 37012492, + 37345276, 37678044, 38010792, 38343524, 38676240, 39008936, 39341612, 39674272, + 40006912, 40339532, 40672132, 41004716, 41337276, 41669820, 42002344, 42334848, + 42667332, 42999796, 43332236, 43664660, 43997060, 44329444, 44661800, 44994140, + 45326456, 45658752, 45991028, 46323280, 46655512, 46987720, 47319908, 47652072, + 47984212, 48316332, 48648428, 48980500, 49312548, 49644576, 49976580, 50308556, + 50640512, 50972444, 51304352, 51636236, 51968096, 52299928, 52631740, 52963524, + 53295284, 53627020, 53958728, 54290412, 54622068, 54953704, 55285308, 55616888, + 55948444, 56279972, 56611472, 56942948, 57274396, 57605816, 57937212, 58268576, + 58599916, 58931228, 59262512, 59593768, 59924992, 60256192, 60587364, 60918508, + 61249620, 61580704, 61911760, 62242788, 62573788, 62904756, 63235692, 63566604, + 63897480, 64228332, 64559148, 64889940, 65220696, 65551424, 65882120, 66212788, + 66543420, 66874024, 67204600, 67535136, 67865648, 68196120, 68526568, 68856984, + 69187360, 69517712, 69848024, 70178304, 70508560, 70838776, 71168960, 71499112, + 71829224, 72159312, 72489360, 72819376, 73149360, 73479304, 73809216, 74139096, + 74468936, 74798744, 75128520, 75458264, 75787968, 76117632, 76447264, 76776864, + 77106424, 77435952, 77765440, 78094888, 78424304, 78753688, 79083032, 79412336, + 79741608, 80070840, 80400032, 80729192, 81058312, 81387392, 81716432, 82045440, + 82374408, 82703336, 83032224, 83361080, 83689896, 84018664, 84347400, 84676096, + 85004760, 85333376, 85661952, 85990488, 86318984, 86647448, 86975864, 87304240, + 87632576, 87960872, 88289128, 88617344, 88945520, 89273648, 89601736, 89929792, + 90257792, 90585760, 90913688, 91241568, 91569408, 91897200, 92224960, 92552672, + 92880336, 93207968, 93535552, 93863088, 94190584, 94518040, 94845448, 95172816, + 95500136, 95827416, 96154648, 96481832, 96808976, 97136080, 97463136, 97790144, + 98117112, 98444032, 98770904, 99097736, 99424520, 99751256, 100077944, 100404592, + 100731192, 101057744, 101384248, 101710712, 102037128, 102363488, 102689808, 103016080, + 103342312, 103668488, 103994616, 104320696, 104646736, 104972720, 105298656, 105624552, + 105950392, 106276184, 106601928, 106927624, 107253272, 107578872, 107904416, 108229920, + 108555368, 108880768, 109206120, 109531416, 109856664, 110181872, 110507016, 110832120, + 111157168, 111482168, 111807112, 112132008, 112456856, 112781648, 113106392, 113431080, + 113755720, 114080312, 114404848, 114729328, 115053760, 115378136, 115702464, 116026744, + 116350960, 116675128, 116999248, 117323312, 117647320, 117971272, 118295176, 118619024, + 118942816, 119266560, 119590248, 119913880, 120237456, 120560984, 120884456, 121207864, + 121531224, 121854528, 122177784, 122500976, 122824112, 123147200, 123470224, 123793200, + 124116120, 124438976, 124761784, 125084528, 125407224, 125729856, 126052432, 126374960, + 126697424, 127019832, 127342184, 127664472, 127986712, 128308888, 128631008, 128953072, + 129275080, 129597024, 129918912, 130240744, 130562520, 130884232, 131205888, 131527480, + 131849016, 132170496, 132491912, 132813272, 133134576, 133455816, 133776992, 134098120, + 134419184, 134740176, 135061120, 135382000, 135702816, 136023584, 136344272, 136664912, + 136985488, 137306016, 137626464, 137946864, 138267184, 138587456, 138907664, 139227808, + 139547904, 139867920, 140187888, 140507776, 140827616, 141147392, 141467104, 141786752, + 142106336, 142425856, 142745312, 143064720, 143384048, 143703312, 144022512, 144341664, + 144660736, 144979744, 145298704, 145617584, 145936400, 146255168, 146573856, 146892480, + 147211040, 147529536, 147847968, 148166336, 148484640, 148802880, 149121056, 149439152, + 149757200, 150075168, 150393072, 150710912, 151028688, 151346400, 151664048, 151981616, + 152299136, 152616576, 152933952, 153251264, 153568496, 153885680, 154202784, 154519824, + 154836784, 155153696, 155470528, 155787296, 156104000, 156420624, 156737200, 157053696, + 157370112, 157686480, 158002768, 158318976, 158635136, 158951216, 159267232, 159583168, + 159899040, 160214848, 160530592, 160846256, 161161840, 161477376, 161792832, 162108208, + 162423520, 162738768, 163053952, 163369040, 163684080, 163999040, 164313936, 164628752, + 164943504, 165258176, 165572784, 165887312, 166201776, 166516160, 166830480, 167144736, + 167458912, 167773008, 168087040, 168400992, 168714880, 169028688, 169342432, 169656096, + 169969696, 170283216, 170596672, 170910032, 171223344, 171536576, 171849728, 172162800, + 172475808, 172788736, 173101600, 173414384, 173727104, 174039728, 174352288, 174664784, + 174977200, 175289536, 175601792, 175913984, 176226096, 176538144, 176850096, 177161984, + 177473792, 177785536, 178097200, 178408784, 178720288, 179031728, 179343088, 179654368, + 179965568, 180276704, 180587744, 180898720, 181209616, 181520448, 181831184, 182141856, + 182452448, 182762960, 183073408, 183383760, 183694048, 184004240, 184314368, 184624416, + 184934400, 185244288, 185554096, 185863840, 186173504, 186483072, 186792576, 187102000, + 187411344, 187720608, 188029808, 188338912, 188647936, 188956896, 189265760, 189574560, + 189883264, 190191904, 190500448, 190808928, 191117312, 191425632, 191733872, 192042016, + 192350096, 192658096, 192966000, 193273840, 193581584, 193889264, 194196848, 194504352, + 194811792, 195119136, 195426400, 195733584, 196040688, 196347712, 196654656, 196961520, + 197268304, 197574992, 197881616, 198188144, 198494592, 198800960, 199107248, 199413456, + 199719584, 200025616, 200331584, 200637456, 200943248, 201248960, 201554576, 201860128, + 202165584, 202470960, 202776256, 203081456, 203386592, 203691632, 203996592, 204301472, + 204606256, 204910976, 205215600, 205520144, 205824592, 206128960, 206433248, 206737456, + 207041584, 207345616, 207649568, 207953424, 208257216, 208560912, 208864512, 209168048, + 209471488, 209774832, 210078112, 210381296, 210684384, 210987408, 211290336, 211593184, + 211895936, 212198608, 212501184, 212803680, 213106096, 213408432, 213710672, 214012816, + 214314880, 214616864, 214918768, 215220576, 215522288, 215823920, 216125472, 216426928, + 216728304, 217029584, 217330784, 217631904, 217932928, 218233856, 218534704, 218835472, + 219136144, 219436720, 219737216, 220037632, 220337952, 220638192, 220938336, 221238384, + 221538352, 221838240, 222138032, 222437728, 222737344, 223036880, 223336304, 223635664, + 223934912, 224234096, 224533168, 224832160, 225131072, 225429872, 225728608, 226027232, + 226325776, 226624240, 226922608, 227220880, 227519056, 227817152, 228115168, 228413088, + 228710912, 229008640, 229306288, 229603840, 229901312, 230198688, 230495968, 230793152, + 231090256, 231387280, 231684192, 231981024, 232277760, 232574416, 232870960, 233167440, + 233463808, 233760096, 234056288, 234352384, 234648384, 234944304, 235240128, 235535872, + 235831504, 236127056, 236422512, 236717888, 237013152, 237308336, 237603424, 237898416, + 238193328, 238488144, 238782864, 239077488, 239372016, 239666464, 239960816, 240255072, + 240549232, 240843312, 241137280, 241431168, 241724960, 242018656, 242312256, 242605776, + 242899200, 243192512, 243485744, 243778896, 244071936, 244364880, 244657744, 244950496, + 245243168, 245535744, 245828224, 246120608, 246412912, 246705104, 246997216, 247289216, + 247581136, 247872960, 248164688, 248456320, 248747856, 249039296, 249330640, 249621904, + 249913056, 250204128, 250495088, 250785968, 251076736, 251367424, 251658016, 251948512, + 252238912, 252529200, 252819408, 253109520, 253399536, 253689456, 253979280, 254269008, + 254558640, 254848176, 255137632, 255426976, 255716224, 256005376, 256294432, 256583392, + 256872256, 257161024, 257449696, 257738272, 258026752, 258315136, 258603424, 258891600, + 259179696, 259467696, 259755600, 260043392, 260331104, 260618704, 260906224, 261193632, + 261480960, 261768176, 262055296, 262342320, 262629248, 262916080, 263202816, 263489456, + 263776000, 264062432, 264348784, 264635024, 264921168, 265207216, 265493168, 265779024, + 266064784, 266350448, 266636000, 266921472, 267206832, 267492096, 267777264, 268062336, + 268347312, 268632192, 268916960, 269201632, 269486208, 269770688, 270055072, 270339360, + 270623552, 270907616, 271191616, 271475488, 271759296, 272042976, 272326560, 272610048, + 272893440, 273176736, 273459936, 273743040, 274026048, 274308928, 274591744, 274874432, + 275157024, 275439520, 275721920, 276004224, 276286432, 276568512, 276850528, 277132416, + 277414240, 277695936, 277977536, 278259040, 278540448, 278821728, 279102944, 279384032, + 279665056, 279945952, 280226752, 280507456, 280788064, 281068544, 281348960, 281629248, + 281909472, 282189568, 282469568, 282749440, 283029248, 283308960, 283588544, 283868032, + 284147424, 284426720, 284705920, 284985024, 285264000, 285542912, 285821696, 286100384, + 286378976, 286657440, 286935840, 287214112, 287492320, 287770400, 288048384, 288326240, + 288604032, 288881696, 289159264, 289436768, 289714112, 289991392, 290268576, 290545632, + 290822592, 291099456, 291376224, 291652896, 291929440, 292205888, 292482272, 292758528, + 293034656, 293310720, 293586656, 293862496, 294138240, 294413888, 294689440, 294964864, + 295240192, 295515424, 295790560, 296065600, 296340512, 296615360, 296890080, 297164704, + 297439200, 297713632, 297987936, 298262144, 298536256, 298810240, 299084160, 299357952, + 299631648, 299905248, 300178720, 300452128, 300725408, 300998592, 301271680, 301544640, + 301817536, 302090304, 302362976, 302635520, 302908000, 303180352, 303452608, 303724768, + 303996800, 304268768, 304540608, 304812320, 305083968, 305355520, 305626944, 305898272, + 306169472, 306440608, 306711616, 306982528, 307253344, 307524064, 307794656, 308065152, + 308335552, 308605856, 308876032, 309146112, 309416096, 309685984, 309955744, 310225408, + 310494976, 310764448, 311033824, 311303072, 311572224, 311841280, 312110208, 312379040, + 312647776, 312916416, 313184960, 313453376, 313721696, 313989920, 314258016, 314526016, + 314793920, 315061728, 315329408, 315597024, 315864512, 316131872, 316399168, 316666336, + 316933408, 317200384, 317467232, 317733984, 318000640, 318267200, 318533632, 318799968, + 319066208, 319332352, 319598368, 319864288, 320130112, 320395808, 320661408, 320926912, + 321192320, 321457632, 321722816, 321987904, 322252864, 322517760, 322782528, 323047200, + 323311744, 323576192, 323840544, 324104800, 324368928, 324632992, 324896928, 325160736, + 325424448, 325688096, 325951584, 326215008, 326478304, 326741504, 327004608, 327267584, + 327530464, 327793248, 328055904, 328318496, 328580960, 328843296, 329105568, 329367712, + 329629760, 329891680, 330153536, 330415264, 330676864, 330938400, 331199808, 331461120, + 331722304, 331983392, 332244384, 332505280, 332766048, 333026752, 333287296, 333547776, + 333808128, 334068384, 334328544, 334588576, 334848512, 335108352, 335368064, 335627712, + 335887200, 336146624, 336405920, 336665120, 336924224, 337183200, 337442112, 337700864, + 337959552, 338218112, 338476576, 338734944, 338993184, 339251328, 339509376, 339767296, + 340025120, 340282848, 340540480, 340797984, 341055392, 341312704, 341569888, 341826976, + 342083968, 342340832, 342597600, 342854272, 343110848, 343367296, 343623648, 343879904, + 344136032, 344392064, 344648000, 344903808, 345159520, 345415136, 345670656, 345926048, + 346181344, 346436512, 346691616, 346946592, 347201440, 347456224, 347710880, 347965440, + 348219872, 348474208, 348728448, 348982592, 349236608, 349490528, 349744320, 349998048, + 350251648, 350505152, 350758528, 351011808, 351264992, 351518048, 351771040, 352023872, + 352276640, 352529280, 352781824, 353034272, 353286592, 353538816, 353790944, 354042944, + 354294880, 354546656, 354798368, 355049952, 355301440, 355552800, 355804096, 356055264, + 356306304, 356557280, 356808128, 357058848, 357309504, 357560032, 357810464, 358060768, + 358311008, 358561088, 358811104, 359060992, 359310784, 359560480, 359810048, 360059520, + 360308896, 360558144, 360807296, 361056352, 361305312, 361554144, 361802880, 362051488, + 362300032, 362548448, 362796736, 363044960, 363293056, 363541024, 363788928, 364036704, + 364284384, 364531936, 364779392, 365026752, 365274016, 365521152, 365768192, 366015136, + 366261952, 366508672, 366755296, 367001792, 367248192, 367494496, 367740704, 367986784, + 368232768, 368478656, 368724416, 368970080, 369215648, 369461088, 369706432, 369951680, + 370196800, 370441824, 370686752, 370931584, 371176288, 371420896, 371665408, 371909792, + 372154080, 372398272, 372642336, 372886304, 373130176, 373373952, 373617600, 373861152, + 374104608, 374347936, 374591168, 374834304, 375077312, 375320224, 375563040, 375805760, + 376048352, 376290848, 376533248, 376775520, 377017696, 377259776, 377501728, 377743584, + 377985344, 378227008, 378468544, 378709984, 378951328, 379192544, 379433664, 379674688, + 379915584, 380156416, 380397088, 380637696, 380878176, 381118560, 381358848, 381599040, + 381839104, 382079072, 382318912, 382558656, 382798304, 383037856, 383277280, 383516640, + 383755840, 383994976, 384233984, 384472896, 384711712, 384950400, 385188992, 385427488, + 385665888, 385904160, 386142336, 386380384, 386618368, 386856224, 387093984, 387331616, + 387569152, 387806592, 388043936, 388281152, 388518272, 388755296, 388992224, 389229024, + 389465728, 389702336, 389938816, 390175200, 390411488, 390647680, 390883744, 391119712, + 391355584, 391591328, 391826976, 392062528, 392297984, 392533312, 392768544, 393003680, + 393238720, 393473632, 393708448, 393943168, 394177760, 394412256, 394646656, 394880960, + 395115136, 395349216, 395583200, 395817088, 396050848, 396284512, 396518080, 396751520, + 396984864, 397218112, 397451264, 397684288, 397917248, 398150080, 398382784, 398615424, + 398847936, 399080320, 399312640, 399544832, 399776928, 400008928, 400240832, 400472608, + 400704288, 400935872, 401167328, 401398720, 401629984, 401861120, 402092192, 402323136, + 402553984, 402784736, 403015360, 403245888, 403476320, 403706656, 403936896, 404167008, + 404397024, 404626944, 404856736, 405086432, 405316032, 405545536, 405774912, 406004224, + 406233408, 406462464, 406691456, 406920320, 407149088, 407377760, 407606336, 407834784, + 408063136, 408291392, 408519520, 408747584, 408975520, 409203360, 409431072, 409658720, + 409886240, 410113664, 410340992, 410568192, 410795296, 411022304, 411249216, 411476032, + 411702720, 411929312, 412155808, 412382176, 412608480, 412834656, 413060736, 413286720, + 413512576, 413738336, 413964000, 414189568, 414415040, 414640384, 414865632, 415090784, + 415315840, 415540800, 415765632, 415990368, 416215008, 416439552, 416663968, 416888288, + 417112512, 417336640, 417560672, 417784576, 418008384, 418232096, 418455712, 418679200, + 418902624, 419125920, 419349120, 419572192, 419795200, 420018080, 420240864, 420463552, + 420686144, 420908608, 421130976, 421353280, 421575424, 421797504, 422019488, 422241344, + 422463104, 422684768, 422906336, 423127776, 423349120, 423570400, 423791520, 424012576, + 424233536, 424454368, 424675104, 424895744, 425116288, 425336736, 425557056, 425777280, + 425997408, 426217440, 426437376, 426657184, 426876928, 427096544, 427316064, 427535488, + 427754784, 427974016, 428193120, 428412128, 428631040, 428849856, 429068544, 429287168, + 429505664, 429724064, 429942368, 430160576, 430378656, 430596672, 430814560, 431032352, + 431250048, 431467616, 431685120, 431902496, 432119808, 432336992, 432554080, 432771040, + 432987936, 433204736, 433421408, 433637984, 433854464, 434070848, 434287104, 434503296, + 434719360, 434935360, 435151232, 435367008, 435582656, 435798240, 436013696, 436229088, + 436444352, 436659520, 436874592, 437089568, 437304416, 437519200, 437733856, 437948416, + 438162880, 438377248, 438591520, 438805696, 439019744, 439233728, 439447584, 439661344, + 439875008, 440088576, 440302048, 440515392, 440728672, 440941824, 441154880, 441367872, + 441580736, 441793472, 442006144, 442218720, 442431168, 442643552, 442855808, 443067968, + 443280032, 443492000, 443703872, 443915648, 444127296, 444338880, 444550336, 444761696, + 444972992, 445184160, 445395232, 445606176, 445817056, 446027840, 446238496, 446449088, + 446659552, 446869920, 447080192, 447290400, 447500448, 447710432, 447920320, 448130112, + 448339776, 448549376, 448758848, 448968224, 449177536, 449386720, 449595808, 449804800, + 450013664, 450222464, 450431168, 450639776, 450848256, 451056640, 451264960, 451473152, + 451681248, 451889248, 452097152, 452304960, 452512672, 452720288, 452927808, 453135232, + 453342528, 453549760, 453756864, 453963904, 454170816, 454377632, 454584384, 454791008, + 454997536, 455203968, 455410304, 455616544, 455822688, 456028704, 456234656, 456440512, + 456646240, 456851904, 457057472, 457262912, 457468256, 457673536, 457878688, 458083744, + 458288736, 458493600, 458698368, 458903040, 459107616, 459312096, 459516480, 459720768, + 459924960, 460129056, 460333056, 460536960, 460740736, 460944448, 461148064, 461351584, + 461554976, 461758304, 461961536, 462164640, 462367680, 462570592, 462773440, 462976160, + 463178816, 463381344, 463583776, 463786144, 463988384, 464190560, 464392608, 464594560, + 464796448, 464998208, 465199872, 465401472, 465602944, 465804320, 466005600, 466206816, + 466407904, 466608896, 466809824, 467010624, 467211328, 467411936, 467612480, 467812896, + 468013216, 468213440, 468413600, 468613632, 468813568, 469013440, 469213184, 469412832, + 469612416, 469811872, 470011232, 470210528, 470409696, 470608800, 470807776, 471006688, + 471205472, 471404192, 471602784, 471801312, 471999712, 472198048, 472396288, 472594400, + 472792448, 472990400, 473188256, 473385984, 473583648, 473781216, 473978688, 474176064, + 474373344, 474570528, 474767616, 474964608, 475161504, 475358336, 475555040, 475751648, + 475948192, 476144608, 476340928, 476537184, 476733312, 476929376, 477125344, 477321184, + 477516960, 477712640, 477908224, 478103712, 478299104, 478494400, 478689600, 478884704, + 479079744, 479274656, 479469504, 479664224, 479858880, 480053408, 480247872, 480442240, + 480636512, 480830656, 481024736, 481218752, 481412640, 481606432, 481800128, 481993760, + 482187264, 482380704, 482574016, 482767264, 482960416, 483153472, 483346432, 483539296, + 483732064, 483924768, 484117344, 484309856, 484502240, 484694560, 484886784, 485078912, + 485270944, 485462880, 485654720, 485846464, 486038144, 486229696, 486421184, 486612576, + 486803840, 486995040, 487186176, 487377184, 487568096, 487758912, 487949664, 488140320, + 488330880, 488521312, 488711712, 488901984, 489092160, 489282240, 489472256, 489662176, + 489851968, 490041696, 490231328, 490420896, 490610336, 490799712, 490988960, 491178144, + 491367232, 491556224, 491745120, 491933920, 492122656, 492311264, 492499808, 492688256, + 492876608, 493064864, 493253056, 493441120, 493629120, 493817024, 494004832, 494192544, + 494380160, 494567712, 494755136, 494942496, 495129760, 495316928, 495504000, 495691008, + 495877888, 496064704, 496251424, 496438048, 496624608, 496811040, 496997408, 497183680, + 497369856, 497555936, 497741920, 497927840, 498113632, 498299360, 498484992, 498670560, + 498856000, 499041376, 499226656, 499411840, 499596928, 499781920, 499966848, 500151680, + 500336416, 500521056, 500705600, 500890080, 501074464, 501258752, 501442944, 501627040, + 501811072, 501995008, 502178848, 502362592, 502546240, 502729824, 502913312, 503096704, + 503280000, 503463232, 503646368, 503829408, 504012352, 504195200, 504377984, 504560672, + 504743264, 504925760, 505108192, 505290496, 505472736, 505654912, 505836960, 506018944, + 506200832, 506382624, 506564320, 506745952, 506927488, 507108928, 507290272, 507471552, + 507652736, 507833824, 508014816, 508195744, 508376576, 508557312, 508737952, 508918528, + 509099008, 509279392, 509459680, 509639904, 509820032, 510000064, 510180000, 510359872, + 510539648, 510719328, 510898944, 511078432, 511257856, 511437216, 511616448, 511795616, + 511974688, 512153664, 512332576, 512511392, 512690112, 512868768, 513047296, 513225792, + 513404160, 513582432, 513760640, 513938784, 514116800, 514294752, 514472608, 514650368, + 514828064, 515005664, 515183168, 515360608, 515537952, 515715200, 515892352, 516069440, + 516246432, 516423328, 516600160, 516776896, 516953536, 517130112, 517306592, 517482976, + 517659264, 517835488, 518011616, 518187680, 518363648, 518539520, 518715296, 518891008, + 519066624, 519242144, 519417600, 519592960, 519768256, 519943424, 520118528, 520293568, + 520468480, 520643328, 520818112, 520992800, 521167392, 521341888, 521516320, 521690656, + 521864896, 522039072, 522213152, 522387168, 522561056, 522734912, 522908640, 523082304, + 523255872, 523429376, 523602784, 523776096, 523949312, 524122464, 524295552, 524468512, + 524641440, 524814240, 524986976, 525159616, 525332192, 525504640, 525677056, 525849344, + 526021568, 526193728, 526365792, 526537760, 526709632, 526881440, 527053152, 527224800, + 527396352, 527567840, 527739200, 527910528, 528081728, 528252864, 528423936, 528594880, + 528765760, 528936576, 529107296, 529277920, 529448480, 529618944, 529789344, 529959648, + 530129856, 530300000, 530470048, 530640000, 530809888, 530979712, 531149440, 531319072, + 531488608, 531658080, 531827488, 531996800, 532166016, 532335168, 532504224, 532673184, + 532842080, 533010912, 533179616, 533348288, 533516832, 533685312, 533853728, 534022048, + 534190272, 534358432, 534526496, 534694496, 534862400, 535030240, 535197984, 535365632, + 535533216, 535700704, 535868128, 536035456, 536202720, 536369888, 536536992, 536704000, + 536870912}; +/* Now where did these came from. */ +const byte gammatable[5][256] = { - 2,4,5,7,8,10,11,12,14,15,16,18,19,20,21,23, - 24,25,26,27,29,30,31,32,33,34,36,37,38,39,40,41, - 42,44,45,46,47,48,49,50,51,52,54,55,56,57,58,59, - 60,61,62,63,64,65,66,67,69,70,71,72,73,74,75,76, - 77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92, - 93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108, - 109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124, - 125,126,127,128,129,129,130,131,132,133,134,135,136,137,138,139, - 140,141,142,143,144,145,146,147,148,148,149,150,151,152,153,154, - 155,156,157,158,159,160,161,162,163,163,164,165,166,167,168,169, - 170,171,172,173,174,175,175,176,177,178,179,180,181,182,183,184, - 185,186,186,187,188,189,190,191,192,193,194,195,196,196,197,198, - 199,200,201,202,203,204,205,205,206,207,208,209,210,211,212,213, - 214,214,215,216,217,218,219,220,221,222,222,223,224,225,226,227, - 228,229,230,230,231,232,233,234,235,236,237,237,238,239,240,241, - 242,243,244,245,245,246,247,248,249,250,251,252,252,253,254,255 - }, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, + 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, + 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, + 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, + 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, + 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, + 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, + 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, + 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, + 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, + 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, + 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, + 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255}, - { - 4,7,9,11,13,15,17,19,21,22,24,26,27,29,30,32, - 33,35,36,38,39,40,42,43,45,46,47,48,50,51,52,54, - 55,56,57,59,60,61,62,63,65,66,67,68,69,70,72,73, - 74,75,76,77,78,79,80,82,83,84,85,86,87,88,89,90, - 91,92,93,94,95,96,97,98,100,101,102,103,104,105,106,107, - 108,109,110,111,112,113,114,114,115,116,117,118,119,120,121,122, - 123,124,125,126,127,128,129,130,131,132,133,133,134,135,136,137, - 138,139,140,141,142,143,144,144,145,146,147,148,149,150,151,152, - 153,153,154,155,156,157,158,159,160,160,161,162,163,164,165,166, - 166,167,168,169,170,171,172,172,173,174,175,176,177,178,178,179, - 180,181,182,183,183,184,185,186,187,188,188,189,190,191,192,193, - 193,194,195,196,197,197,198,199,200,201,201,202,203,204,205,206, - 206,207,208,209,210,210,211,212,213,213,214,215,216,217,217,218, - 219,220,221,221,222,223,224,224,225,226,227,228,228,229,230,231, - 231,232,233,234,235,235,236,237,238,238,239,240,241,241,242,243, - 244,244,245,246,247,247,248,249,250,251,251,252,253,254,254,255 - }, + {2, 4, 5, 7, 8, 10, 11, 12, 14, 15, 16, 18, 19, 20, 21, 23, + 24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 36, 37, 38, 39, 40, 41, + 42, 44, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 64, 65, 66, 67, 69, 70, 71, 72, 73, 74, 75, 76, + 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, + 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, + 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, + 125, 126, 127, 128, 129, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, + 140, 141, 142, 143, 144, 145, 146, 147, 148, 148, 149, 150, 151, 152, 153, 154, + 155, 156, 157, 158, 159, 160, 161, 162, 163, 163, 164, 165, 166, 167, 168, 169, + 170, 171, 172, 173, 174, 175, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, + 185, 186, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 196, 197, 198, + 199, 200, 201, 202, 203, 204, 205, 205, 206, 207, 208, 209, 210, 211, 212, 213, + 214, 214, 215, 216, 217, 218, 219, 220, 221, 222, 222, 223, 224, 225, 226, 227, + 228, 229, 230, 230, 231, 232, 233, 234, 235, 236, 237, 237, 238, 239, 240, 241, + 242, 243, 244, 245, 245, 246, 247, 248, 249, 250, 251, 252, 252, 253, 254, 255}, - { - 8,12,16,19,22,24,27,29,31,34,36,38,40,41,43,45, - 47,49,50,52,53,55,57,58,60,61,63,64,65,67,68,70, - 71,72,74,75,76,77,79,80,81,82,84,85,86,87,88,90, - 91,92,93,94,95,96,98,99,100,101,102,103,104,105,106,107, - 108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123, - 124,125,126,127,128,129,130,131,132,133,134,135,135,136,137,138, - 139,140,141,142,143,143,144,145,146,147,148,149,150,150,151,152, - 153,154,155,155,156,157,158,159,160,160,161,162,163,164,165,165, - 166,167,168,169,169,170,171,172,173,173,174,175,176,176,177,178, - 179,180,180,181,182,183,183,184,185,186,186,187,188,189,189,190, - 191,192,192,193,194,195,195,196,197,197,198,199,200,200,201,202, - 202,203,204,205,205,206,207,207,208,209,210,210,211,212,212,213, - 214,214,215,216,216,217,218,219,219,220,221,221,222,223,223,224, - 225,225,226,227,227,228,229,229,230,231,231,232,233,233,234,235, - 235,236,237,237,238,238,239,240,240,241,242,242,243,244,244,245, - 246,246,247,247,248,249,249,250,251,251,252,253,253,254,254,255 - }, + {4, 7, 9, 11, 13, 15, 17, 19, 21, 22, 24, 26, 27, 29, 30, 32, + 33, 35, 36, 38, 39, 40, 42, 43, 45, 46, 47, 48, 50, 51, 52, 54, + 55, 56, 57, 59, 60, 61, 62, 63, 65, 66, 67, 68, 69, 70, 72, 73, + 74, 75, 76, 77, 78, 79, 80, 82, 83, 84, 85, 86, 87, 88, 89, 90, + 91, 92, 93, 94, 95, 96, 97, 98, 100, 101, 102, 103, 104, 105, 106, 107, + 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, + 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, + 138, 139, 140, 141, 142, 143, 144, 144, 145, 146, 147, 148, 149, 150, 151, 152, + 153, 153, 154, 155, 156, 157, 158, 159, 160, 160, 161, 162, 163, 164, 165, 166, + 166, 167, 168, 169, 170, 171, 172, 172, 173, 174, 175, 176, 177, 178, 178, 179, + 180, 181, 182, 183, 183, 184, 185, 186, 187, 188, 188, 189, 190, 191, 192, 193, + 193, 194, 195, 196, 197, 197, 198, 199, 200, 201, 201, 202, 203, 204, 205, 206, + 206, 207, 208, 209, 210, 210, 211, 212, 213, 213, 214, 215, 216, 217, 217, 218, + 219, 220, 221, 221, 222, 223, 224, 224, 225, 226, 227, 228, 228, 229, 230, 231, + 231, 232, 233, 234, 235, 235, 236, 237, 238, 238, 239, 240, 241, 241, 242, 243, + 244, 244, 245, 246, 247, 247, 248, 249, 250, 251, 251, 252, 253, 254, 254, 255}, + {8, 12, 16, 19, 22, 24, 27, 29, 31, 34, 36, 38, 40, 41, 43, 45, + 47, 49, 50, 52, 53, 55, 57, 58, 60, 61, 63, 64, 65, 67, 68, 70, + 71, 72, 74, 75, 76, 77, 79, 80, 81, 82, 84, 85, 86, 87, 88, 90, + 91, 92, 93, 94, 95, 96, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, + 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, + 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 135, 136, 137, 138, + 139, 140, 141, 142, 143, 143, 144, 145, 146, 147, 148, 149, 150, 150, 151, 152, + 153, 154, 155, 155, 156, 157, 158, 159, 160, 160, 161, 162, 163, 164, 165, 165, + 166, 167, 168, 169, 169, 170, 171, 172, 173, 173, 174, 175, 176, 176, 177, 178, + 179, 180, 180, 181, 182, 183, 183, 184, 185, 186, 186, 187, 188, 189, 189, 190, + 191, 192, 192, 193, 194, 195, 195, 196, 197, 197, 198, 199, 200, 200, 201, 202, + 202, 203, 204, 205, 205, 206, 207, 207, 208, 209, 210, 210, 211, 212, 212, 213, + 214, 214, 215, 216, 216, 217, 218, 219, 219, 220, 221, 221, 222, 223, 223, 224, + 225, 225, 226, 227, 227, 228, 229, 229, 230, 231, 231, 232, 233, 233, 234, 235, + 235, 236, 237, 237, 238, 238, 239, 240, 240, 241, 242, 242, 243, 244, 244, 245, + 246, 246, 247, 247, 248, 249, 249, 250, 251, 251, 252, 253, 253, 254, 254, 255}, - { - 16,23,28,32,36,39,42,45,48,50,53,55,57,60,62,64, - 66,68,69,71,73,75,76,78,80,81,83,84,86,87,89,90, - 92,93,94,96,97,98,100,101,102,103,105,106,107,108,109,110, - 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,128, - 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, - 143,144,145,146,147,148,149,150,150,151,152,153,154,155,155,156, - 157,158,159,159,160,161,162,163,163,164,165,166,166,167,168,169, - 169,170,171,172,172,173,174,175,175,176,177,177,178,179,180,180, - 181,182,182,183,184,184,185,186,187,187,188,189,189,190,191,191, - 192,193,193,194,195,195,196,196,197,198,198,199,200,200,201,202, - 202,203,203,204,205,205,206,207,207,208,208,209,210,210,211,211, - 212,213,213,214,214,215,216,216,217,217,218,219,219,220,220,221, - 221,222,223,223,224,224,225,225,226,227,227,228,228,229,229,230, - 230,231,232,232,233,233,234,234,235,235,236,236,237,237,238,239, - 239,240,240,241,241,242,242,243,243,244,244,245,245,246,246,247, - 247,248,248,249,249,250,250,251,251,252,252,253,254,254,255,255 - } -}; + {16, 23, 28, 32, 36, 39, 42, 45, 48, 50, 53, 55, 57, 60, 62, 64, + 66, 68, 69, 71, 73, 75, 76, 78, 80, 81, 83, 84, 86, 87, 89, 90, + 92, 93, 94, 96, 97, 98, 100, 101, 102, 103, 105, 106, 107, 108, 109, 110, + 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 128, + 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, + 143, 144, 145, 146, 147, 148, 149, 150, 150, 151, 152, 153, 154, 155, 155, 156, + 157, 158, 159, 159, 160, 161, 162, 163, 163, 164, 165, 166, 166, 167, 168, 169, + 169, 170, 171, 172, 172, 173, 174, 175, 175, 176, 177, 177, 178, 179, 180, 180, + 181, 182, 182, 183, 184, 184, 185, 186, 187, 187, 188, 189, 189, 190, 191, 191, + 192, 193, 193, 194, 195, 195, 196, 196, 197, 198, 198, 199, 200, 200, 201, 202, + 202, 203, 203, 204, 205, 205, 206, 207, 207, 208, 208, 209, 210, 210, 211, 211, + 212, 213, 213, 214, 214, 215, 216, 216, 217, 217, 218, 219, 219, 220, 220, 221, + 221, 222, 223, 223, 224, 224, 225, 225, 226, 227, 227, 228, 228, 229, 229, 230, + 230, 231, 232, 232, 233, 233, 234, 234, 235, 235, 236, 236, 237, 237, 238, 239, + 239, 240, 240, 241, 241, 242, 242, 243, 243, 244, 244, 245, 245, 246, 246, 247, + 247, 248, 248, 249, 249, 250, 250, 251, 251, 252, 252, 253, 254, 254, 255, 255}}; diff --git a/zephyrdoom/src/tables.h b/zephyrdoom/src/tables.h index 0ba896a..31b6d2f 100644 --- a/zephyrdoom/src/tables.h +++ b/zephyrdoom/src/tables.h @@ -1,35 +1,33 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 1993-2008 Raven Software -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Lookup tables. -// Do not try to look them up :-). -// In the order of appearance: -// -// int finetangent[4096] - Tangens LUT. -// Should work with BAM fairly well (12 of 16bit, -// effectively, by shifting). -// -// int finesine[10240] - Sine lookup. -// Guess what, serves as cosine, too. -// Remarkable thing is, how to use BAMs with this? -// -// int tantoangle[2049] - ArcTan LUT, -// maps tan(angle) to angle fast. Gotta search. -// - +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 1993-2008 Raven Software + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Lookup tables. + * Do not try to look them up :-). + * In the order of appearance: + * + * int finetangent[4096] - Tangens LUT. + * Should work with BAM fairly well (12 of 16bit, effectively, by shifting). + * + * int finesine[10240] - Sine lookup. + * Guess what, serves as cosine, too. + * Remarkable thing is, how to use BAMs with this. + * + * int tantoangle[2049] - ArcTan LUT. + * Maps tan(angle) to angle fast. Gotta search. + */ #ifndef __TABLES__ #define __TABLES__ @@ -38,58 +36,53 @@ #include "m_fixed.h" -#define FINEANGLES 8192 -#define FINEMASK (FINEANGLES-1) - +#define FINEANGLES 8192 +#define FINEMASK (FINEANGLES - 1) -// 0x100000000 to 0x2000 -#define ANGLETOFINESHIFT 19 +/* 0x100000000 to 0x2000 */ +#define ANGLETOFINESHIFT 19 -// Effective size is 10240. -extern const fixed_t finesine[5*FINEANGLES/4]; +/* Effective size is 10240. */ +extern const fixed_t finesine[5 * FINEANGLES / 4]; -// Re-use data, is just PI/2 pahse shift. +/* Re-use data, is just PI/2 pahse shift. */ extern const fixed_t *finecosine; +/* Effective size is 4096. */ +extern const fixed_t finetangent[FINEANGLES / 2]; -// Effective size is 4096. -extern const fixed_t finetangent[FINEANGLES/2]; - -// Gamma correction tables. +/* Gamma correction tables. */ extern const byte gammatable[5][256]; -// Binary Angle Measument, BAM. - -#define ANG45 0x20000000 -#define ANG90 0x40000000 -#define ANG180 0x80000000 -#define ANG270 0xc0000000 -#define ANG_MAX 0xffffffff +/* Binary Angle Measument, BAM. */ +#define ANG45 0x20000000 +#define ANG90 0x40000000 +#define ANG180 0x80000000 +#define ANG270 0xc0000000 +#define ANG_MAX 0xffffffff -#define ANG1 (ANG45 / 45) -#define ANG60 (ANG180 / 3) +#define ANG1 (ANG45 / 45) +#define ANG60 (ANG180 / 3) -// Heretic code uses this definition as though it represents one -// degree, but it is not! This is actually ~1.40 degrees. +/* + * Heretic code uses this definition as though it represents one + * degree, but it is not! This is actually ~1.40 degrees. + */ +#define ANG1_X 0x01000000 -#define ANG1_X 0x01000000 - -#define SLOPERANGE 2048 -#define SLOPEBITS 11 -#define DBITS (FRACBITS-SLOPEBITS) +#define SLOPERANGE 2048 +#define SLOPEBITS 11 +#define DBITS (FRACBITS - SLOPEBITS) typedef unsigned angle_t; +/* + * Effective size is 2049. + * The +1 size is to handle the case when x==y without additional checking. + */ +extern const angle_t tantoangle[SLOPERANGE + 1]; -// Effective size is 2049; -// The +1 size is to handle the case when x==y -// without additional checking. -extern const angle_t tantoangle[SLOPERANGE+1]; - - -// Utility function, -// called by R_PointToAngle. +/* Utility function, called by R_PointToAngle. */ int SlopeDiv(unsigned int num, unsigned int den); - -#endif +#endif /* __TABLES__ */ diff --git a/zephyrdoom/src/v_diskicon.c b/zephyrdoom/src/v_diskicon.c index d40f218..4833cdf 100644 --- a/zephyrdoom/src/v_diskicon.c +++ b/zephyrdoom/src/v_diskicon.c @@ -1,20 +1,21 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Disk load indicator. -// +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Disk load indicator. + */ + #include #include "doomtype.h" @@ -28,21 +29,24 @@ #include "v_diskicon.h" -// Only display the disk icon if more then this much bytes have been read -// during the previous tic. - -static const int diskicon_threshold = 20*1024; - -// Two buffers: disk_data contains the data representing the disk icon -// (raw, not a patch_t) while saved_background is an equivalently-sized -// buffer where we save the background data while the disk is on screen. +/* + * Only display the disk icon if more then this much bytes have been read + * during the previous tic. + */ +static const int diskicon_threshold = 20 * 1024; + +/* + * Two buffers - disk_data contains the data representing the disk icon + * (raw, not a patch_t) while saved_background is an equivalently sized + * buffer where we save the background data while the disk is on screen. + */ static byte *disk_data; static byte *saved_background; static int loading_disk_xoffs = 0; static int loading_disk_yoffs = 0; -// Number of bytes read since the last call to V_DrawDiskIcon(). +/* Number of bytes read since the last call to V_DrawDiskIcon(). */ static size_t recent_bytes_read = 0; static boolean disk_drawn; @@ -53,7 +57,8 @@ static void CopyRegion(byte *dest, int dest_pitch, byte *s, *d; int y; - s = src; d = dest; + s = src; + d = dest; for (y = 0; y < h; ++y) { memcpy(d, s, w * sizeof(*d)); @@ -64,46 +69,45 @@ static void CopyRegion(byte *dest, int dest_pitch, static void SaveDiskData(char *disk_lump, int xoffs, int yoffs) { - printf("NRFD-TODO: SaveDiskData\n"); /* - byte *tmpscreen; - patch_t *disk; - - // Allocate a complete temporary screen where we'll draw the patch. - tmpscreen = Z_Malloc(SCREENWIDTH * SCREENHEIGHT * sizeof(*tmpscreen), - PU_STATIC, NULL); - memset(tmpscreen, 0, SCREENWIDTH * SCREENHEIGHT * sizeof(*tmpscreen)); - V_UseBuffer(tmpscreen); - - // Buffer where we'll save the disk data. - disk_data = Z_Malloc(LOADING_DISK_W * LOADING_DISK_H * sizeof(*disk_data), - PU_STATIC, NULL); - - // Draw the patch and save the result to disk_data. - disk = W_CacheLumpName(disk_lump, PU_STATIC); - V_DrawPatch(loading_disk_xoffs, loading_disk_yoffs, disk); - CopyRegion(disk_data, LOADING_DISK_W, - tmpscreen + yoffs * SCREENWIDTH + xoffs, SCREENWIDTH, - LOADING_DISK_W, LOADING_DISK_H); - W_ReleaseLumpName(disk_lump); - - V_RestoreBuffer(); - Z_Free(tmpscreen); - */ + * // NRFD-TODO + * byte *tmpscreen; + * patch_t *disk; + * + * // Allocate a complete temporary screen where we'll draw the patch + * tmpscreen = Z_Malloc(SCREENWIDTH * SCREENHEIGHT * sizeof(*tmpscreen), + * PU_STATIC, NULL); + * memset(tmpscreen, 0, SCREENWIDTH * SCREENHEIGHT * sizeof(*tmpscreen)); + * V_UseBuffer(tmpscreen); + * + * // Buffer where we'll save the disk data + * disk_data = Z_Malloc(LOADING_DISK_W * LOADING_DISK_H * sizeof(*disk_data), + * PU_STATIC, NULL); + * + * // Draw the patch and save the result to disk_data + * disk = W_CacheLumpName(disk_lump, PU_STATIC); + * V_DrawPatch(loading_disk_xoffs, loading_disk_yoffs, disk); + * CopyRegion(disk_data, LOADING_DISK_W, + * tmpscreen + yoffs * SCREENWIDTH + xoffs, SCREENWIDTH, + * LOADING_DISK_W, LOADING_DISK_H); + * W_ReleaseLumpName(disk_lump); + * + * V_RestoreBuffer(); + * Z_Free(tmpscreen); + */ } void V_EnableLoadingDisk(char *lump_name, int xoffs, int yoffs) { - printf("NRFD-TODO: V_EnableLoadingDisk\n"); /* - loading_disk_xoffs = xoffs; - loading_disk_yoffs = yoffs; - - saved_background = Z_Malloc(LOADING_DISK_W * LOADING_DISK_H - * sizeof(*saved_background), - PU_STATIC, NULL); - SaveDiskData(lump_name, xoffs, yoffs); - */ + * // NRFD-TODO + * loading_disk_xoffs = xoffs; + * loading_disk_yoffs = yoffs; + * + * saved_background = Z_Malloc(LOADING_DISK_W * LOADING_DISK_H * sizeof(*saved_background), + * PU_STATIC, NULL); + * SaveDiskData(lump_name, xoffs, yoffs); + */ } void V_BeginRead(size_t nbytes) @@ -113,45 +117,43 @@ void V_BeginRead(size_t nbytes) static byte *DiskRegionPointer(void) { - return I_VideoBuffer - + loading_disk_yoffs * SCREENWIDTH - + loading_disk_xoffs; + return I_VideoBuffer + loading_disk_yoffs * SCREENWIDTH + loading_disk_xoffs; } void V_DrawDiskIcon(void) { - printf("NRFD-TODO: V_DrawDiskIcon\n"); /* - if (disk_data != NULL && recent_bytes_read > diskicon_threshold) - { - // Save the background behind the disk before we draw it. - CopyRegion(saved_background, LOADING_DISK_W, - DiskRegionPointer(), SCREENWIDTH, - LOADING_DISK_W, LOADING_DISK_H); - - // Write the disk to the screen buffer. - CopyRegion(DiskRegionPointer(), SCREENWIDTH, - disk_data, LOADING_DISK_W, - LOADING_DISK_W, LOADING_DISK_H); - disk_drawn = true; - } - - recent_bytes_read = 0; - */ + * // NRFD-TODO + * if (disk_data != NULL && recent_bytes_read > diskicon_threshold) + * { + * // Save the background behind the disk before we draw it + * CopyRegion(saved_background, LOADING_DISK_W, + * DiskRegionPointer(), SCREENWIDTH, + * LOADING_DISK_W, LOADING_DISK_H); + * + * // Write the disk to the screen buffer + * CopyRegion(DiskRegionPointer(), SCREENWIDTH, + * disk_data, LOADING_DISK_W, + * LOADING_DISK_W, LOADING_DISK_H); + * disk_drawn = true; + * } + * + * recent_bytes_read = 0; + */ } void V_RestoreDiskBackground(void) { - printf("NRFD-TODO: V_RestoreDiskBackground\n"); /* - if (disk_drawn) - { - // Restore the background. - CopyRegion(DiskRegionPointer(), SCREENWIDTH, - saved_background, LOADING_DISK_W, - LOADING_DISK_W, LOADING_DISK_H); - - disk_drawn = false; - } - */ + * // NRFD-TODO + * if (disk_drawn) + * { + * // Restore the background + * CopyRegion(DiskRegionPointer(), SCREENWIDTH, + * saved_background, LOADING_DISK_W, + * LOADING_DISK_W, LOADING_DISK_H); + * + * disk_drawn = false; + * } + */ } diff --git a/zephyrdoom/src/v_diskicon.h b/zephyrdoom/src/v_diskicon.h index 343d061..ef64c91 100644 --- a/zephyrdoom/src/v_diskicon.h +++ b/zephyrdoom/src/v_diskicon.h @@ -1,26 +1,25 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Disk load indicator. -// +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Disk load indicator. + */ #ifndef __V_DISKICON__ #define __V_DISKICON__ -// Dimensions of the flashing "loading" disk icon - +/* Dimensions of the flashing "loading" disk icon. */ #define LOADING_DISK_W 16 #define LOADING_DISK_H 16 @@ -29,4 +28,4 @@ extern void V_BeginRead(size_t nbytes); extern void V_DrawDiskIcon(void); extern void V_RestoreDiskBackground(void); -#endif +#endif /* __V_DISKICON__ */ diff --git a/zephyrdoom/src/v_patch.h b/zephyrdoom/src/v_patch.h index 8fb694e..d95789e 100644 --- a/zephyrdoom/src/v_patch.h +++ b/zephyrdoom/src/v_patch.h @@ -1,49 +1,48 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Refresh/rendering module, shared data struct definitions. -// - +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Refresh/rendering module, shared data struct definitions. + */ #ifndef V_PATCH_H #define V_PATCH_H -// Patches. -// A patch holds one or more columns. -// Patches are used for sprites and all masked pictures, -// and we compose textures from the TEXTURE1/2 lists -// of patches. - -typedef PACKED_STRUCT ( -{ - short width; // bounding box size - short height; - short leftoffset; // pixels to the left of origin - short topoffset; // pixels below the origin - int columnofs[8]; // only [width] used - // the [0] is &columnofs[width] -}) patch_t; +/* + * Patches. + * A patch holds one or more columns. + * Patches are used for sprites and all masked pictures, + * and we compose textures from the TEXTURE1/2 lists of patches. + */ +typedef PACKED_STRUCT( + { + short width; /* Bounding box size */ + short height; + short leftoffset; /* Pixels to the left of origin */ + short topoffset; /* Pixels below the origin */ + /* The [0] is &columnofs[width] */ + int columnofs[8]; /* Only [width] used */ + }) patch_t; -// posts are runs of non masked source pixels -typedef PACKED_STRUCT ( -{ - byte topdelta; // -1 is the last post in a column - byte length; // length data bytes follows -}) post_t; +/* Posts are runs of non masked source pixels. */ +typedef PACKED_STRUCT( + { + byte topdelta; /* -1 is the last post in a column */ + byte length; /* Length data bytes follows */ + }) post_t; -// column_t is a list of 0 or more post_t, (byte)-1 terminated -typedef post_t column_t; +/* Column_t is a list of 0 or more post_t, (byte)-1 terminated. */ +typedef post_t column_t; -#endif +#endif /* V_PATCH_H */ diff --git a/zephyrdoom/src/v_video.c b/zephyrdoom/src/v_video.c index 66258a9..3f1e38b 100644 --- a/zephyrdoom/src/v_video.c +++ b/zephyrdoom/src/v_video.c @@ -1,23 +1,23 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 1993-2008 Raven Software -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Gamma correction LUT stuff. -// Functions to draw patches (by post) directly to screen. -// Functions to blit a block to the screen. -// +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 1993-2008 Raven Software + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Gamma correction LUT stuff. + * Functions to draw patches (by post) directly to screen. + * Functions to blit a block to the screen. + */ #include #include @@ -43,48 +43,50 @@ #include #endif -// TODO: There are separate RANGECHECK defines for different games, but this -// is common code. Fix this. +/* + * TODO + * There are separate RANGECHECK defines for different games, but this + * is common code. Fix this. + */ #define RANGECHECK 1 -// Blending table used for fuzzpatch, etc. -// Only used in Heretic/Hexen - +/* + * Blending table used for fuzzpatch, etc. + * Only used in Heretic/Hexen. + */ byte *tinttable = NULL; -// villsa [STRIFE] Blending table used for Strife +/* villsa [STRIFE] Blending table used for Strife. */ byte *xlatab = NULL; -// The screen buffer that the v_video.c code draws to. - +/* The screen buffer that the v_video.c code draws to. */ static pixel_t *dest_screen = NULL; -// NRFD-EXCLUDE //int dirtybox[4]; +/* + * NRFD-EXCLUDE + * int dirtybox[4]; + */ -// haleyjd 08/28/10: clipping callback function for patches. -// This is needed for Chocolate Strife, which clips patches to the screen. +/* + * haleyjd 08/28/10 - Clipping callback function for patches. + * This is needed for Chocolate Strife, which clips patches to the screen. + */ static vpatchclipfunc_t patchclip_callback = NULL; -// -// V_MarkRect -// void V_MarkRect(int x, int y, int width, int height) { - // If we are temporarily using an alternate screen, do not - // affect the update box. - /* NRFD-EXCLUDE: - if (dest_screen == I_VideoBuffer) - { - M_AddToBox (dirtybox, x, y); - M_AddToBox (dirtybox, x + width-1, y + height-1); - } - */ + /* + * NRFD-EXLUDE + * // If we are temporarily using an alternate screen, do not + * // affect the update box. + * if (dest_screen == I_VideoBuffer) + * { + * M_AddToBox(dirtybox, x, y); + * M_AddToBox(dirtybox, x + width - 1, y + height - 1); + * } + */ } - -// -// V_CopyRect -// void V_CopyRect(int srcx, int srcy, pixel_t *source, int width, int height, int destx, int desty) @@ -93,16 +95,9 @@ void V_CopyRect(int srcx, int srcy, pixel_t *source, pixel_t *dest; #ifdef RANGECHECK - if (srcx < 0 - || srcx + width > SCREENWIDTH - || srcy < 0 - || srcy + height > SCREENHEIGHT - || destx < 0 - || destx + width > SCREENWIDTH - || desty < 0 - || desty + height > SCREENHEIGHT) + if (srcx < 0 || srcx + width > SCREENWIDTH || srcy < 0 || srcy + height > SCREENHEIGHT || destx < 0 || destx + width > SCREENWIDTH || desty < 0 || desty + height > SCREENHEIGHT) { - I_Error ("Bad V_CopyRect"); + I_Error("Bad V_CopyRect"); } #endif @@ -111,7 +106,7 @@ void V_CopyRect(int srcx, int srcy, pixel_t *source, src = source + SCREENWIDTH * srcy + srcx; dest = dest_screen + SCREENWIDTH * desty + destx; - for ( ; height>0 ; height--) + for (; height > 0; height--) { memcpy(dest, src, width * sizeof(*dest)); src += SCREENWIDTH; @@ -119,26 +114,20 @@ void V_CopyRect(int srcx, int srcy, pixel_t *source, } } -// -// V_SetPatchClipCallback -// -// haleyjd 08/28/10: Added for Strife support. -// By calling this function, you can setup runtime error checking for patch -// clipping. Strife never caused errors by drawing patches partway off-screen. -// Some versions of vanilla DOOM also behaved differently than the default -// implementation, so this could possibly be extended to those as well for -// accurate emulation. -// +/* + * haleyjd 08/28/10 - Added for Strife support. + * By calling this function, you can setup runtime error checking for patch + * clipping. Strife never caused errors by drawing patches partway off-screen. + * Some versions of vanilla DOOM also behaved differently than the default + * implementation, so this could possibly be extended to those as well for + * accurate emulation. + */ void V_SetPatchClipCallback(vpatchclipfunc_t func) { patchclip_callback = func; } -// -// V_DrawPatch -// Masks a column based masked pic to the screen. -// - +/* Masks a column based masked pic to the screen. */ void V_DrawPatch(int x, int y, patch_t *patch) { int count; @@ -152,10 +141,10 @@ void V_DrawPatch(int x, int y, patch_t *patch) y -= SHORT(patch->topoffset); x -= SHORT(patch->leftoffset); - // haleyjd 08/28/10: Strife needs silent error checking here. - if(patchclip_callback) + /* haleyjd 08/28/10 - Strife needs silent error checking here */ + if (patchclip_callback) { - if(!patchclip_callback(patch, x, y)) + if (!patchclip_callback(patch, x, y)) return; } @@ -165,10 +154,7 @@ void V_DrawPatch(int x, int y, patch_t *patch) N_ldbg("V_DrawPatch: %d x %d\n", w, h); #ifdef RANGECHECK - if (x < 0 - || x + w > SCREENWIDTH - || y < 0 - || y + h > SCREENHEIGHT) + if (x < 0 || x + w > SCREENWIDTH || y < 0 || y + h > SCREENHEIGHT) { printf("%d, %d - %d x %d", x, y, w, h); I_Error("Bad V_DrawPatch"); @@ -180,16 +166,20 @@ void V_DrawPatch(int x, int y, patch_t *patch) col = 0; desttop = dest_screen + y * SCREENWIDTH + x; - for ( ; colcolumnofs[col])); - // I_SleepUS(1); // NRFD-TODO: remove? - // step through the posts in a column + /* + * // NRFD-TODO + * I_SleepUS(1); + */ + + /* Step through the posts in a column */ while (column->topdelta != 0xff) { source = (byte *)column + 3; - dest = desttop + column->topdelta*SCREENWIDTH; + dest = desttop + column->topdelta * SCREENWIDTH; count = column->length; while (count--) @@ -202,12 +192,10 @@ void V_DrawPatch(int x, int y, patch_t *patch) } } -// -// V_DrawPatchFlipped -// Masks a column based masked pic to the screen. -// Flips horizontally, e.g. to mirror face. -// - +/* + * Masks a column based masked pic to the screen. + * Flips horizontally, e.g. to mirror face. + */ void V_DrawPatchFlipped(int x, int y, patch_t *patch) { int count; @@ -221,46 +209,39 @@ void V_DrawPatchFlipped(int x, int y, patch_t *patch) y -= SHORT(patch->topoffset); x -= SHORT(patch->leftoffset); - // haleyjd 08/28/10: Strife needs silent error checking here. - if(patchclip_callback) + /* haleyjd 08/28/10 - Strife needs silent error checking here */ + if (patchclip_callback) { - if(!patchclip_callback(patch, x, y)) + if (!patchclip_callback(patch, x, y)) return; } - w = SHORT(patch->width); h = SHORT(patch->height); N_ldbg("V_DrawPatchFlipped: %d x %d\n", w, h); #ifdef RANGECHECK - if (x < 0 - || x + w > SCREENWIDTH - || y < 0 - || y + h > SCREENHEIGHT) + if (x < 0 || x + w > SCREENWIDTH || y < 0 || y + h > SCREENHEIGHT) { I_Error("Bad V_DrawPatchFlipped"); } #endif - - V_MarkRect (x, y, w, h); + V_MarkRect(x, y, w, h); col = 0; desttop = dest_screen + y * SCREENWIDTH + x; - for ( ; colcolumnofs[w - 1 - col])); - column = (column_t *)((byte *)patch + LONG(patch->columnofs[w-1-col])); - - // step through the posts in a column - while (column->topdelta != 0xff ) + /* Step through the posts in a column */ + while (column->topdelta != 0xff) { - source = (byte *)column + 3; - dest = desttop + column->topdelta*SCREENWIDTH; + dest = desttop + column->topdelta * SCREENWIDTH; count = column->length; while (count--) @@ -271,28 +252,16 @@ void V_DrawPatchFlipped(int x, int y, patch_t *patch) column = (column_t *)((byte *)column + column->length + 4); } } - } - - -// -// V_DrawPatchDirect -// Draws directly to the screen on the pc. -// - +/* Draws directly to the screen on the pc. */ void V_DrawPatchDirect(int x, int y, patch_t *patch) { V_DrawPatch(x, y, patch); } -// -// V_DrawTLPatch -// -// Masks a column based translucent masked pic to the screen. -// - -void V_DrawTLPatch(int x, int y, patch_t * patch) +/* Masks a column based translucent masked pic to the screen. */ +void V_DrawTLPatch(int x, int y, patch_t *patch) { int count, col; column_t *column; @@ -303,10 +272,7 @@ void V_DrawTLPatch(int x, int y, patch_t * patch) y -= SHORT(patch->topoffset); x -= SHORT(patch->leftoffset); - if (x < 0 - || x + SHORT(patch->width) > SCREENWIDTH - || y < 0 - || y + SHORT(patch->height) > SCREENHEIGHT) + if (x < 0 || x + SHORT(patch->width) > SCREENWIDTH || y < 0 || y + SHORT(patch->height) > SCREENHEIGHT) { I_Error("Bad V_DrawTLPatch"); } @@ -317,13 +283,12 @@ void V_DrawTLPatch(int x, int y, patch_t * patch) w = SHORT(patch->width); for (; col < w; x++, col++, desttop++) { - column = (column_t *) ((byte *) patch + LONG(patch->columnofs[col])); - - // step through the posts in a column + column = (column_t *)((byte *)patch + LONG(patch->columnofs[col])); + /* Step through the posts in a column */ while (column->topdelta != 0xff) { - source = (byte *) column + 3; + source = (byte *)column + 3; dest = desttop + column->topdelta * SCREENWIDTH; count = column->length; @@ -332,18 +297,13 @@ void V_DrawTLPatch(int x, int y, patch_t * patch) *dest = tinttable[((*dest) << 8) + *source++]; dest += SCREENWIDTH; } - column = (column_t *) ((byte *) column + column->length + 4); + column = (column_t *)((byte *)column + column->length + 4); } } } -// -// V_DrawXlaPatch -// -// villsa [STRIFE] Masks a column based translucent masked pic to the screen. -// - -void V_DrawXlaPatch(int x, int y, patch_t * patch) +/* villsa [STRIFE] Masks a column based translucent masked pic to the screen. */ +void V_DrawXlaPatch(int x, int y, patch_t *patch) { int count, col; column_t *column; @@ -354,9 +314,9 @@ void V_DrawXlaPatch(int x, int y, patch_t * patch) y -= SHORT(patch->topoffset); x -= SHORT(patch->leftoffset); - if(patchclip_callback) + if (patchclip_callback) { - if(!patchclip_callback(patch, x, y)) + if (!patchclip_callback(patch, x, y)) return; } @@ -364,36 +324,30 @@ void V_DrawXlaPatch(int x, int y, patch_t * patch) desttop = dest_screen + y * SCREENWIDTH + x; w = SHORT(patch->width); - for(; col < w; x++, col++, desttop++) + for (; col < w; x++, col++, desttop++) { - column = (column_t *) ((byte *) patch + LONG(patch->columnofs[col])); - - // step through the posts in a column + column = (column_t *)((byte *)patch + LONG(patch->columnofs[col])); - while(column->topdelta != 0xff) + /* Step through the posts in a column */ + while (column->topdelta != 0xff) { - source = (byte *) column + 3; + source = (byte *)column + 3; dest = desttop + column->topdelta * SCREENWIDTH; count = column->length; - while(count--) + while (count--) { *dest = xlatab[*dest + ((*source) << 8)]; source++; dest += SCREENWIDTH; } - column = (column_t *) ((byte *) column + column->length + 4); + column = (column_t *)((byte *)column + column->length + 4); } } } -// -// V_DrawAltTLPatch -// -// Masks a column based translucent masked pic to the screen. -// - -void V_DrawAltTLPatch(int x, int y, patch_t * patch) +/* Masks a column based translucent masked pic to the screen. */ +void V_DrawAltTLPatch(int x, int y, patch_t *patch) { int count, col; column_t *column; @@ -404,10 +358,7 @@ void V_DrawAltTLPatch(int x, int y, patch_t * patch) y -= SHORT(patch->topoffset); x -= SHORT(patch->leftoffset); - if (x < 0 - || x + SHORT(patch->width) > SCREENWIDTH - || y < 0 - || y + SHORT(patch->height) > SCREENHEIGHT) + if (x < 0 || x + SHORT(patch->width) > SCREENWIDTH || y < 0 || y + SHORT(patch->height) > SCREENHEIGHT) { I_Error("Bad V_DrawAltTLPatch"); } @@ -418,13 +369,12 @@ void V_DrawAltTLPatch(int x, int y, patch_t * patch) w = SHORT(patch->width); for (; col < w; x++, col++, desttop++) { - column = (column_t *) ((byte *) patch + LONG(patch->columnofs[col])); - - // step through the posts in a column + column = (column_t *)((byte *)patch + LONG(patch->columnofs[col])); + /* Step through the posts in a column */ while (column->topdelta != 0xff) { - source = (byte *) column + 3; + source = (byte *)column + 3; dest = desttop + column->topdelta * SCREENWIDTH; count = column->length; @@ -433,17 +383,12 @@ void V_DrawAltTLPatch(int x, int y, patch_t * patch) *dest = tinttable[((*dest) << 8) + *source++]; dest += SCREENWIDTH; } - column = (column_t *) ((byte *) column + column->length + 4); + column = (column_t *)((byte *)column + column->length + 4); } } } -// -// V_DrawShadowedPatch -// -// Masks a column based masked pic to the screen. -// - +/* Masks a column based masked pic to the screen. */ void V_DrawShadowedPatch(int x, int y, patch_t *patch) { int count, col; @@ -456,10 +401,7 @@ void V_DrawShadowedPatch(int x, int y, patch_t *patch) y -= SHORT(patch->topoffset); x -= SHORT(patch->leftoffset); - if (x < 0 - || x + SHORT(patch->width) > SCREENWIDTH - || y < 0 - || y + SHORT(patch->height) > SCREENHEIGHT) + if (x < 0 || x + SHORT(patch->width) > SCREENWIDTH || y < 0 || y + SHORT(patch->height) > SCREENHEIGHT) { I_Error("Bad V_DrawShadowedPatch"); } @@ -471,13 +413,12 @@ void V_DrawShadowedPatch(int x, int y, patch_t *patch) w = SHORT(patch->width); for (; col < w; x++, col++, desttop++, desttop2++) { - column = (column_t *) ((byte *) patch + LONG(patch->columnofs[col])); - - // step through the posts in a column + column = (column_t *)((byte *)patch + LONG(patch->columnofs[col])); + /* Step through the posts in a column */ while (column->topdelta != 0xff) { - source = (byte *) column + 3; + source = (byte *)column + 3; dest = desttop + column->topdelta * SCREENWIDTH; dest2 = desttop2 + column->topdelta * SCREENWIDTH; count = column->length; @@ -488,61 +429,45 @@ void V_DrawShadowedPatch(int x, int y, patch_t *patch) dest2 += SCREENWIDTH; *dest = *source++; dest += SCREENWIDTH; - } - column = (column_t *) ((byte *) column + column->length + 4); + column = (column_t *)((byte *)column + column->length + 4); } } } -// -// Load tint table from TINTTAB lump. -// - +/* Load tint table from TINTTAB lump. */ void V_LoadTintTable(void) { tinttable = W_CacheLumpName("TINTTAB", PU_STATIC); } -// -// V_LoadXlaTable -// -// villsa [STRIFE] Load xla table from XLATAB lump. -// - +/* villsa [STRIFE] Load xla table from XLATAB lump. */ void V_LoadXlaTable(void) { xlatab = W_CacheLumpName("XLATAB", PU_STATIC); } -// -// V_DrawBlock -// Draw a linear block of pixels into the view buffer. -// - +/* Draw a linear block of pixels into the view buffer. */ void V_DrawBlock(int x, int y, int width, int height, pixel_t *src) { pixel_t *dest; #ifdef RANGECHECK - if (x < 0 - || x + width >SCREENWIDTH - || y < 0 - || y + height > SCREENHEIGHT) + if (x < 0 || x + width > SCREENWIDTH || y < 0 || y + height > SCREENHEIGHT) { - I_Error ("Bad V_DrawBlock"); + I_Error("Bad V_DrawBlock"); } #endif - V_MarkRect (x, y, width, height); + V_MarkRect(x, y, width, height); dest = dest_screen + y * SCREENWIDTH + x; while (height--) { - memcpy (dest, src, width * sizeof(*dest)); - src += width; - dest += SCREENWIDTH; + memcpy(dest, src, width * sizeof(*dest)); + src += width; + dest += SCREENWIDTH; } } @@ -596,139 +521,122 @@ void V_DrawVertLine(int x, int y, int h, int c) void V_DrawBox(int x, int y, int w, int h, int c) { V_DrawHorizLine(x, y, w, c); - V_DrawHorizLine(x, y+h-1, w, c); + V_DrawHorizLine(x, y + h - 1, w, c); V_DrawVertLine(x, y, h, c); - V_DrawVertLine(x+w-1, y, h, c); + V_DrawVertLine(x + w - 1, y, h, c); } -// -// Draw a "raw" screen (lump containing raw data to blit directly -// to the screen) -// - +/* + * Draw a "raw" screen (lump containing raw data to blit directly + * to the screen). + */ void V_DrawRawScreen(byte *raw) { memcpy(dest_screen, raw, SCREENWIDTH * SCREENHEIGHT); } -// -// V_Init -// -void V_Init (void) +void V_Init(void) { - // no-op! - // There used to be separate screens that could be drawn to; these are - // now handled in the upper layers. + /* + * There used to be separate screens that could be drawn to, these are + * now handled in the upper layers. + */ } -// Set the buffer that the code draws to. - +/* Set the buffer that the code draws to. */ void V_UseBuffer(pixel_t *buffer) { dest_screen = buffer; } -// Restore screen buffer to the i_video screen buffer. - +/* Restore screen buffer to the i_video screen buffer. */ void V_RestoreBuffer(void) { dest_screen = I_VideoBuffer; } -// -// SCREEN SHOTS -// - -typedef PACKED_STRUCT ( -{ - char manufacturer; - char version; - char encoding; - char bits_per_pixel; - - unsigned short xmin; - unsigned short ymin; - unsigned short xmax; - unsigned short ymax; - - unsigned short hres; - unsigned short vres; +/* Screenshots. */ +typedef PACKED_STRUCT( + { + char manufacturer; + char version; + char encoding; + char bits_per_pixel; - unsigned char palette[48]; + unsigned short xmin; + unsigned short ymin; + unsigned short xmax; + unsigned short ymax; - char reserved; - char color_planes; - unsigned short bytes_per_line; - unsigned short palette_type; + unsigned short hres; + unsigned short vres; - char filler[58]; - unsigned char data; // unbounded -}) pcx_t; + unsigned char palette[48]; + char reserved; + char color_planes; + unsigned short bytes_per_line; + unsigned short palette_type; -// -// WritePCXfile -// + char filler[58]; + unsigned char data; /* Unbounded */ + }) pcx_t; void WritePCXfile(char *filename, byte *data, int width, int height, byte *palette) { - int i; - int length; - pcx_t* pcx; - byte* pack; + int i; + int length; + pcx_t *pcx; + byte *pack; - pcx = Z_Malloc (width*height*2+1000, PU_STATIC, NULL); + pcx = Z_Malloc(width * height * 2 + 1000, PU_STATIC, NULL); - pcx->manufacturer = 0x0a; // PCX id - pcx->version = 5; // 256 color - pcx->encoding = 1; // uncompressed - pcx->bits_per_pixel = 8; // 256 color + pcx->manufacturer = 0x0a; /* PCX id */ + pcx->version = 5; /* 256 color */ + pcx->encoding = 1; /* Uncompressed */ + pcx->bits_per_pixel = 8; /* 256 color */ pcx->xmin = 0; pcx->ymin = 0; - pcx->xmax = SHORT(width-1); - pcx->ymax = SHORT(height-1); + pcx->xmax = SHORT(width - 1); + pcx->ymax = SHORT(height - 1); pcx->hres = SHORT(1); pcx->vres = SHORT(1); - memset (pcx->palette,0,sizeof(pcx->palette)); - pcx->reserved = 0; // PCX spec: reserved byte must be zero - pcx->color_planes = 1; // chunky image + memset(pcx->palette, 0, sizeof(pcx->palette)); + pcx->reserved = 0; /* PCX spec - reserved byte must be zero */ + pcx->color_planes = 1; /* Chunky image */ pcx->bytes_per_line = SHORT(width); - pcx->palette_type = SHORT(2); // not a grey scale - memset (pcx->filler,0,sizeof(pcx->filler)); + pcx->palette_type = SHORT(2); /* Not a grey scale */ + memset(pcx->filler, 0, sizeof(pcx->filler)); - // pack the image + /* Pack the image */ pack = &pcx->data; - for (i=0 ; i 0 && fabs(mouse_acceleration - 1) > 0.01) - { - draw_acceleration = true; - } - - // Calculate box position - - box_x = SCREENWIDTH - MOUSE_SPEED_BOX_WIDTH - 10; - box_y = 15; - - V_DrawFilledBox(box_x, box_y, - MOUSE_SPEED_BOX_WIDTH, MOUSE_SPEED_BOX_HEIGHT, bgcolor); - V_DrawBox(box_x, box_y, - MOUSE_SPEED_BOX_WIDTH, MOUSE_SPEED_BOX_HEIGHT, bordercolor); - - // Calculate the position of the red threshold line when calibrating - // acceleration. This is 1/3 of the way along the box. - - redline_x = MOUSE_SPEED_BOX_WIDTH / 3; - - // Calculate line length - - if (draw_acceleration && speed >= mouse_threshold) - { - // Undo acceleration and get back the original mouse speed - original_speed = speed - mouse_threshold; - original_speed = (int) (original_speed / mouse_acceleration); - original_speed += mouse_threshold; - - linelen = (original_speed * redline_x) / mouse_threshold; - } - else - { - linelen = speed / linelen_multiplier; - } - - // Draw horizontal "thermometer" - - if (linelen > MOUSE_SPEED_BOX_WIDTH - 1) - { - linelen = MOUSE_SPEED_BOX_WIDTH - 1; - if (!draw_acceleration) - { - linelen_multiplier++; - } - } - - V_DrawHorizLine(box_x + 1, box_y + 4, MOUSE_SPEED_BOX_WIDTH - 2, black); - - if (!draw_acceleration || linelen < redline_x) - { - V_DrawHorizLine(box_x + 1, box_y + MOUSE_SPEED_BOX_HEIGHT / 2, - linelen, white); - } - else - { - V_DrawHorizLine(box_x + 1, box_y + MOUSE_SPEED_BOX_HEIGHT / 2, - redline_x, white); - V_DrawHorizLine(box_x + redline_x, box_y + MOUSE_SPEED_BOX_HEIGHT / 2, - linelen - redline_x, yellow); - } - - if (draw_acceleration) - { - // Draw acceleration threshold line - V_DrawVertLine(box_x + redline_x, box_y + 1, - MOUSE_SPEED_BOX_HEIGHT - 2, red); - } - else - { - // Draw multiplier lines to indicate current resolution - for (i = 1; i < linelen_multiplier; i++) - { - V_DrawVertLine( - box_x + (i * MOUSE_SPEED_BOX_WIDTH / linelen_multiplier), - box_y + 1, MOUSE_SPEED_BOX_HEIGHT - 2, yellow); - } - } + /* + * // NRFD-TODO + * int i; + * + * // haleyjd 20110213 - 12 is too small! + * char lbmname[16]; + * char *ext; + * + * // Find a file name to save it to + * #ifdef HAVE_LIBPNG + * extern int png_screenshots; + * if (png_screenshots) + * { + * ext = "png"; + * } + * else + * #endif + * { + * ext = "pcx"; + * } + * + * for (i = 0; i <= 99; i++) + * { + * M_snprintf(lbmname, sizeof(lbmname), format, i, ext); + * + * if (!M_FileExists(lbmname)) + * { + * // File doesn't exist + * break; + * } + * } + * + * if (i == 100) + * { + * #ifdef HAVE_LIBPNG + * if (png_screenshots) + * { + * I_Error("V_ScreenShot: Couldn't create a PNG"); + * } + * else + * #endif + * { + * I_Error("V_ScreenShot: Couldn't create a PCX"); + * } + * } + * #ifdef HAVE_LIBPNG + * if (png_screenshots) + * { + * WritePNGfile(lbmname, I_VideoBuffer, + * SCREENWIDTH, SCREENHEIGHT, + * W_CacheLumpName(DEH_String("PLAYPAL"), PU_CACHE)); + * } + * else + * #endif + * { + * // Save the pcx file + * WritePCXfile(lbmname, I_VideoBuffer, + * SCREENWIDTH, SCREENHEIGHT, + * W_CacheLumpName(DEH_String("PLAYPAL"), PU_CACHE)); + * } + */ } -*/ +/* + * NRFD-EXCLUDE + * + * #define MOUSE_SPEED_BOX_WIDTH 120 + * #define MOUSE_SPEED_BOX_HEIGHT 9 + * + * // If box is only to calibrate speed, testing relative speed (as a measure + * // of game pixels to movement units) is important whether physical mouse DPI + * // is high or low. Line resolution starts at 1 pixel per 1 move-unit. If + * // line maxes out, resolution becomes 1 pixel per 2 move-units, then per + * // 3 move-units, etc. + * static int linelen_multiplier = 1; + * + * void V_DrawMouseSpeedBox(int speed) + * { + * extern int usemouse; + * int bgcolor, bordercolor, red, black, white, yellow; + * int box_x, box_y; + * int original_speed; + * int redline_x; + * int linelen; + * int i; + * boolean draw_acceleration = false; + * + * // Get palette indices for colors for widget. These depend on the + * // palette of the game being played. + * bgcolor = I_GetPaletteIndex(0x77, 0x77, 0x77); + * bordercolor = I_GetPaletteIndex(0x55, 0x55, 0x55); + * red = I_GetPaletteIndex(0xff, 0x00, 0x00); + * black = I_GetPaletteIndex(0x00, 0x00, 0x00); + * yellow = I_GetPaletteIndex(0xff, 0xff, 0x00); + * white = I_GetPaletteIndex(0xff, 0xff, 0xff); + * + * // If the mouse is turned off, don't draw the box at all + * if (!usemouse) + * { + * return; + * } + * + * // If acceleration is used, draw a box that helps to calibrate the + * // threshold point. + * if (mouse_threshold > 0 && fabs(mouse_acceleration - 1) > 0.01) + * { + * draw_acceleration = true; + * } + * + * // Calculate box position + * box_x = SCREENWIDTH - MOUSE_SPEED_BOX_WIDTH - 10; + * box_y = 15; + * + * V_DrawFilledBox(box_x, box_y, + * MOUSE_SPEED_BOX_WIDTH, MOUSE_SPEED_BOX_HEIGHT, bgcolor); + * V_DrawBox(box_x, box_y, + * MOUSE_SPEED_BOX_WIDTH, MOUSE_SPEED_BOX_HEIGHT, bordercolor); + * + * // Calculate the position of the red threshold line when calibrating + * // acceleration. This is 1/3 of the way along the box. + * + * redline_x = MOUSE_SPEED_BOX_WIDTH / 3; + * + * // Calculate line length + * if (draw_acceleration && speed >= mouse_threshold) + * { + * // Undo acceleration and get back the original mouse speed + * original_speed = speed - mouse_threshold; + * original_speed = (int)(original_speed / mouse_acceleration); + * original_speed += mouse_threshold; + * + * linelen = (original_speed * redline_x) / mouse_threshold; + * } + * else + * { + * linelen = speed / linelen_multiplier; + * } + * + * // Draw horizontal "thermometer" + * if (linelen > MOUSE_SPEED_BOX_WIDTH - 1) + * { + * linelen = MOUSE_SPEED_BOX_WIDTH - 1; + * if (!draw_acceleration) + * { + * linelen_multiplier++; + * } + * } + * + * V_DrawHorizLine(box_x + 1, box_y + 4, MOUSE_SPEED_BOX_WIDTH - 2, black); + * + * if (!draw_acceleration || linelen < redline_x) + * { + * V_DrawHorizLine(box_x + 1, box_y + MOUSE_SPEED_BOX_HEIGHT / 2, + * linelen, white); + * } + * else + * { + * V_DrawHorizLine(box_x + 1, box_y + MOUSE_SPEED_BOX_HEIGHT / 2, + * redline_x, white); + * V_DrawHorizLine(box_x + redline_x, box_y + MOUSE_SPEED_BOX_HEIGHT / 2, + * linelen - redline_x, yellow); + * } + * + * if (draw_acceleration) + * { + * // Draw acceleration threshold line + * V_DrawVertLine(box_x + redline_x, box_y + 1, + * MOUSE_SPEED_BOX_HEIGHT - 2, red); + * } + * else + * { + * // Draw multiplier lines to indicate current resolution + * for (i = 1; i < linelen_multiplier; i++) + * { + * V_DrawVertLine( + * box_x + (i * MOUSE_SPEED_BOX_WIDTH / linelen_multiplier), + * box_y + 1, MOUSE_SPEED_BOX_HEIGHT - 2, yellow); + * } + * } + * } + */ diff --git a/zephyrdoom/src/v_video.h b/zephyrdoom/src/v_video.h index 7e8934d..6d3e979 100644 --- a/zephyrdoom/src/v_video.h +++ b/zephyrdoom/src/v_video.h @@ -1,55 +1,49 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Gamma correction LUT. -// Functions to draw patches (by post) directly to screen. -// Functions to blit a block to the screen. -// - +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Gamma correction LUT. + * Functions to draw patches (by post) directly to screen. + * Functions to blit a block to the screen. + */ #ifndef __V_VIDEO__ #define __V_VIDEO__ #include "doomtype.h" -// Needed because we are refering to patches. +/* Needed because we are refering to patches. */ #include "v_patch.h" -// -// VIDEO -// - -#define CENTERY (SCREENHEIGHT/2) - +/* Video */ +#define CENTERY (SCREENHEIGHT / 2) extern int dirtybox[4]; extern byte *tinttable; -// haleyjd 08/28/10: implemented for Strife support -// haleyjd 08/28/10: Patch clipping callback, implemented to support Choco -// Strife. +/* + * haleyjd 08/28/10 - Implemented for Strife support. + * Patch clipping callback, implemented to support Choco Strife. + */ typedef boolean (*vpatchclipfunc_t)(patch_t *, int, int); void V_SetPatchClipCallback(vpatchclipfunc_t func); +/* Allocates buffer screens, call before R_Init. */ +void V_Init(void); -// Allocates buffer screens, call before R_Init. -void V_Init (void); - -// Draw a block from the specified source screen to the screen. - +/* Draw a block from the specified source screen to the screen. */ void V_CopyRect(int srcx, int srcy, pixel_t *source, int width, int height, int destx, int desty); @@ -57,13 +51,12 @@ void V_CopyRect(int srcx, int srcy, pixel_t *source, void V_DrawPatch(int x, int y, patch_t *patch); void V_DrawPatchFlipped(int x, int y, patch_t *patch); void V_DrawTLPatch(int x, int y, patch_t *patch); -void V_DrawAltTLPatch(int x, int y, patch_t * patch); +void V_DrawAltTLPatch(int x, int y, patch_t *patch); void V_DrawShadowedPatch(int x, int y, patch_t *patch); -void V_DrawXlaPatch(int x, int y, patch_t * patch); // villsa [STRIFE] +void V_DrawXlaPatch(int x, int y, patch_t *patch); /* villsa [STRIFE] */ void V_DrawPatchDirect(int x, int y, patch_t *patch); -// Draw a linear block of pixels into the view buffer. - +/* Draw a linear block of pixels into the view buffer. */ void V_DrawBlock(int x, int y, int width, int height, pixel_t *src); void V_MarkRect(int x, int y, int width, int height); @@ -73,35 +66,34 @@ void V_DrawHorizLine(int x, int y, int w, int c); void V_DrawVertLine(int x, int y, int h, int c); void V_DrawBox(int x, int y, int w, int h, int c); -// Draw a raw screen lump - +/* Draw a raw screen lump. */ void V_DrawRawScreen(byte *raw); -// Temporarily switch to using a different buffer to draw graphics, etc. - +/* Temporarily switch to using a different buffer to draw graphics, etc. */ void V_UseBuffer(pixel_t *buffer); -// Return to using the normal screen buffer to draw graphics. - +/* Return to using the normal screen buffer to draw graphics. */ void V_RestoreBuffer(void); -// Save a screenshot of the current screen to a file, named in the -// format described in the string passed to the function, eg. -// "DOOM%02i.pcx" - +/* + * Save a screenshot of the current screen to a file, named in the + * format described in the string passed to the function, e.g. "DOOM%02i.pcx" + */ void V_ScreenShot(char *format); -// Load the lookup table for translucency calculations from the TINTTAB -// lump. - +/* + * Load the lookup table for translucency calculations from the TINTTAB + * lump. + */ void V_LoadTintTable(void); -// villsa [STRIFE] -// Load the lookup table for translucency calculations from the XLATAB -// lump. - +/* + * villsa [STRIFE] + * Load the lookup table for translucency calculations from the XLATAB + * lump. + */ void V_LoadXlaTable(void); void V_DrawMouseSpeedBox(int speed); -#endif +#endif /* __V_VIDEO__ */ diff --git a/zephyrdoom/src/w_checksum.c b/zephyrdoom/src/w_checksum.c index 965fce6..c6a824a 100644 --- a/zephyrdoom/src/w_checksum.c +++ b/zephyrdoom/src/w_checksum.c @@ -1,20 +1,20 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Generate a checksum of the WAD directory. -// +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Generate a checksum of the WAD directory. + */ #include #include @@ -26,48 +26,54 @@ #include "w_checksum.h" #include "w_wad.h" -// static wad_file_t **open_wadfiles = NULL; -// static int num_open_wadfiles = 0; +/* + * // TODO + * static wad_file_t **open_wadfiles = NULL; + * static int num_open_wadfiles = 0; + */ static int GetFileNumber(wad_file_t *handle) { - printf("NRF-TODO: GetFileNumber\n"); return 0; /* - int i; - int result; + return 0; - for (i = 0; i < num_open_wadfiles; ++i) - { - if (open_wadfiles[i] == handle) - { - return i; - } - } - - // Not found in list. This is a new file we haven't seen yet. - // Allocate another slot for this file. - - open_wadfiles = I_Realloc(open_wadfiles, - sizeof(wad_file_t *) * (num_open_wadfiles + 1)); - open_wadfiles[num_open_wadfiles] = handle; - - result = num_open_wadfiles; - ++num_open_wadfiles; - - return result; - */ + /* + * // NRFD-TODO + * int i; + * int result; + * + * for (i = 0; i < num_open_wadfiles; ++i) + * { + * if (open_wadfiles[i] == handle) + * { + * return i; + * } + * } + * + * // Not found in list. This is a new file we haven't seen yet. + * // Allocate another slot for this file. + * open_wadfiles = I_Realloc(open_wadfiles, + * sizeof(wad_file_t *) * (num_open_wadfiles + 1)); + * open_wadfiles[num_open_wadfiles] = handle; + * + * result = num_open_wadfiles; + * ++num_open_wadfiles; + * + * return result; + */ } static void ChecksumAddLump(sha1_context_t *sha1_context, lumpinfo_t *lump) { - printf("NRF-TODO: ChecksumAddLump\n"); /* - char buf[9]; - - M_StringCopy(buf, lump->name, sizeof(buf)); - SHA1_UpdateString(sha1_context, buf); - SHA1_UpdateInt32(sha1_context, GetFileNumber(lump->wad_file)); - SHA1_UpdateInt32(sha1_context, lump->position); - SHA1_UpdateInt32(sha1_context, lump->size); - */ + /* + * // NRFD-TODO + * char buf[9]; + * + * M_StringCopy(buf, lump->name, sizeof(buf)); + * SHA1_UpdateString(sha1_context, buf); + * SHA1_UpdateInt32(sha1_context, GetFileNumber(lump->wad_file)); + * SHA1_UpdateInt32(sha1_context, lump->position); + * SHA1_UpdateInt32(sha1_context, lump->size); + */ } void W_Checksum(sha1_digest_t digest) @@ -77,17 +83,17 @@ void W_Checksum(sha1_digest_t digest) SHA1_Init(&sha1_context); - // NRFD-TODO - // num_open_wadfiles = 0; - - // Go through each entry in the WAD directory, adding information - // about each entry to the SHA1 hash. /* - for (i = 0; i < numlumps; ++i) - { - ChecksumAddLump(&sha1_context, &lumpinfo[i]); - } - */ + * // NRFD-TODO + * num_open_wadfiles = 0; + * + * // Go through each entry in the WAD directory, adding information + * // about each entry to the SHA1 hash. + * for (i = 0; i < numlumps; ++i) + * { + * ChecksumAddLump(&sha1_context, &lumpinfo[i]); + * } + */ SHA1_Final(digest, &sha1_context); } diff --git a/zephyrdoom/src/w_checksum.h b/zephyrdoom/src/w_checksum.h index fe9bf82..756a860 100644 --- a/zephyrdoom/src/w_checksum.h +++ b/zephyrdoom/src/w_checksum.h @@ -1,20 +1,20 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Generate a checksum of the WAD directory. -// +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Generate a checksum of the WAD directory. + */ #ifndef W_CHECKSUM_H #define W_CHECKSUM_H @@ -23,4 +23,4 @@ extern void W_Checksum(sha1_digest_t digest); -#endif /* #ifndef W_CHECKSUM_H */ +#endif /* W_CHECKSUM_H */ diff --git a/zephyrdoom/src/w_file.c b/zephyrdoom/src/w_file.c index e3e10d7..f6871db 100644 --- a/zephyrdoom/src/w_file.c +++ b/zephyrdoom/src/w_file.c @@ -1,20 +1,20 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// WAD I/O functions. -// +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * WAD I/O functions. + */ #include @@ -27,7 +27,6 @@ extern wad_file_class_t fatfs_wad_file; - wad_file_t *W_OpenFile(char *path) { wad_file_t *result; @@ -35,33 +34,40 @@ wad_file_t *W_OpenFile(char *path) return fatfs_wad_file.OpenFile(path); - // Try all classes in order until we find one that works - - /* NRFD-TODO? - result = NULL; - - for (i=0; iOpenFile(path); - - if (result != NULL) - { - break; - } - } - - return result; - */ + /* + * // NRFD-TODO + * // Try all classes in order until we find one that works + * result = NULL; + * + * for (i = 0; i < arrlen(wad_file_classes); ++i) + * { + * result = wad_file_classes[i]->OpenFile(path); + * + * if (result != NULL) + * { + * break; + * } + * } + * + * return result; + */ } void W_CloseFile(wad_file_t *wad) { - // wad->file_class->CloseFile(wad); + /* + * // TODO + * wad->file_class->CloseFile(wad); + */ } size_t W_Read(wad_file_t *wad, unsigned int offset, void *buffer, size_t buffer_len) { return 0; - // return wad->file_class->Read(wad, offset, buffer, buffer_len); + + /* + * //TODO + * return wad->file_class->Read(wad, offset, buffer, buffer_len); + */ } diff --git a/zephyrdoom/src/w_file.h b/zephyrdoom/src/w_file.h index 0c4e6e0..83c18f3 100644 --- a/zephyrdoom/src/w_file.h +++ b/zephyrdoom/src/w_file.h @@ -1,21 +1,20 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// WAD I/O functions. -// - +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * WAD I/O functions. + */ #ifndef __W_FILE__ #define __W_FILE__ @@ -27,14 +26,16 @@ typedef struct _wad_file_s wad_file_t; typedef struct { - // Open a file for reading. + /* Open a file for reading */ wad_file_t *(*OpenFile)(char *path); - // Close the specified file. + /* Close the specified file */ void (*CloseFile)(wad_file_t *file); - // Read data from the specified position in the file into the - // provided buffer. Returns the number of bytes read. + /* + * Read data from the specified position in the file into the + * provided buffer. Returns the number of bytes read. + */ size_t (*Read)(wad_file_t *file, unsigned int offset, void *buffer, size_t buffer_len); } wad_file_class_t; @@ -42,37 +43,38 @@ typedef struct struct _wad_file_s { /* - // Class of this file. - wad_file_class_t *file_class; - - // If this is NULL, the file cannot be mapped into memory. If this - // is non-NULL, it is a pointer to the mapped file. - byte *mapped; - */ - // Length of the file, in bytes. + * // TODO + * // Class of this file + * wad_file_class_t *file_class; + * + * // If this is NULL, the file cannot be mapped into memory. + * // If this is non-NULL, it is a pointer to the mapped file. + * byte *mapped; + */ + + /* Length of the file, in bytes */ unsigned int length; - // File's location on disk. + /* File's location on disk */ const char *path; }; /* -// Open the specified file. Returns a pointer to a new wad_file_t -// handle for the WAD file, or NULL if it could not be opened. - -wad_file_t *W_OpenFile(char *path); - -// Close the specified WAD file. - -void W_CloseFile(wad_file_t *wad); - -// Read data from the specified file into the provided buffer. The -// data is read from the specified offset from the start of the file. -// Returns the number of bytes read. - -size_t W_Read(wad_file_t *wad, unsigned int offset, - void *buffer, size_t buffer_len); - -*/ - -#endif /* #ifndef __W_FILE__ */ + * // TODO + * // Open the specified file. Returns a pointer to a new wad_file_t + * // handle for the WAD file, or NULL if it could not be opened. + * + * wad_file_t *W_OpenFile(char *path); + * + * // Close the specified WAD file. + * void W_CloseFile(wad_file_t *wad); + * + * // Read data from the specified file into the provided buffer. The + * // data is read from the specified offset from the start of the file. + * // Returns the number of bytes read. + * size_t W_Read(wad_file_t *wad, unsigned int offset, + * void *buffer, size_t buffer_len); + * + */ + +#endif /* __W_FILE__ */ diff --git a/zephyrdoom/src/w_file_fatfs.c b/zephyrdoom/src/w_file_fatfs.c index 5da0b36..483b204 100644 --- a/zephyrdoom/src/w_file_fatfs.c +++ b/zephyrdoom/src/w_file_fatfs.c @@ -1,20 +1,20 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// WAD I/O functions. -// +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * WAD I/O functions. + */ #include @@ -34,84 +34,88 @@ extern wad_file_class_t fatfs_wad_file; static wad_file_t *W_FatFS_OpenFile(char *path) { - return NULL; /* - printf("FatFS: Opening: %s\n", path); - fatfs_wad_file_t *result; - FIL fstream; - FRESULT ff_result; - - ff_result = f_open(&fstream, path, FA_READ); - if (ff_result != FR_OK) - { - return NULL; - } + return NULL; - // Create a new fatfs_wad_file_t to hold the file handle. - - result = Z_Malloc(sizeof(fatfs_wad_file_t), PU_STATIC, 0); - result->wad.file_class = &fatfs_wad_file; - result->wad.mapped = NULL; - result->wad.length = f_size(&fstream); - result->wad.path = M_StringDuplicate(path); - result->fstream = fstream; - - printf("FatFS: Open OK\n"); - return &result->wad; - */ + /* + * // TODO + * printf("FatFS: Opening: %s\n", path); + * fatfs_wad_file_t *result; + * FIL fstream; + * FRESULT ff_result; + * + * ff_result = f_open(&fstream, path, FA_READ); + * if (ff_result != FR_OK) + * { + * return NULL; + * } + * + * // Create a new fatfs_wad_file_t to hold the file handle + * result = Z_Malloc(sizeof(fatfs_wad_file_t), PU_STATIC, 0); + * result->wad.file_class = &fatfs_wad_file; + * result->wad.mapped = NULL; + * result->wad.length = f_size(&fstream); + * result->wad.path = M_StringDuplicate(path); + * result->fstream = fstream; + * + * printf("FatFS: Open OK\n"); + * return &result->wad; + */ } static void W_FatFS_CloseFile(wad_file_t *wad) { /* - fatfs_wad_file_t *fatfs_wad; - - fatfs_wad = (fatfs_wad_file_t *) wad; - - (void) f_close(&fatfs_wad->fstream); - - Z_Free(fatfs_wad); - */ + * // TODO + * fatfs_wad_file_t *fatfs_wad; + * + * fatfs_wad = (fatfs_wad_file_t *)wad; + * + * (void)f_close(&fatfs_wad->fstream); + * + * Z_Free(fatfs_wad); + */ } -// Read data from the specified position in the file into the -// provided buffer. Returns the number of bytes read. - +/* + * Read data from the specified position in the file into the + * provided buffer. Returns the number of bytes read. + */ size_t W_FatFS_Read(wad_file_t *wad, unsigned int offset, - void *buffer, size_t buffer_len) + void *buffer, size_t buffer_len) { return 0; - /* - fatfs_wad_file_t *fatfs_wad; - size_t result; - FRESULT ff_result; - fatfs_wad = (fatfs_wad_file_t *) wad; - - // Jump to the specified position in the file. - - ff_result = f_lseek(&fatfs_wad->fstream, offset); - if (ff_result != FR_OK) - { - printf("W_FatFS_Read: seek failed\n"); - return 0; - } - // Read into the buffer. - - ff_result = f_read(&fatfs_wad->fstream, buffer, buffer_len, &result); - if (ff_result != FR_OK) - { - printf("W_FatFS_Read: seek failed\n"); - return 0; - } - - return result; - */ + /* + * // TODO + * fatfs_wad_file_t *fatfs_wad; + * size_t result; + * FRESULT ff_result; + * + * fatfs_wad = (fatfs_wad_file_t *)wad; + * + * // Jump to the specified position in the file + * ff_result = f_lseek(&fatfs_wad->fstream, offset); + * if (ff_result != FR_OK) + * { + * printf("W_FatFS_Read: seek failed\n"); + * return 0; + * } + * + * // Read into the buffer + * ff_result = f_read(&fatfs_wad->fstream, buffer, buffer_len, &result); + * if (ff_result != FR_OK) + * { + * printf("W_FatFS_Read: seek failed\n"); + * return 0; + * } + * + * return result; + */ } - wad_file_class_t fatfs_wad_file = -{ - W_FatFS_OpenFile, - W_FatFS_CloseFile, - W_FatFS_Read, + { + W_FatFS_OpenFile, + W_FatFS_CloseFile, + W_FatFS_Read, }; diff --git a/zephyrdoom/src/w_main.c b/zephyrdoom/src/w_main.c index 51dbdbc..2234591 100644 --- a/zephyrdoom/src/w_main.c +++ b/zephyrdoom/src/w_main.c @@ -1,20 +1,20 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Common code to parse command line, identifying WAD files to load. -// +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Common code to parse command line, identifying WAD files to load. + */ #include "doom_config.h" #include "d_iwad.h" @@ -25,16 +25,19 @@ #include "w_wad.h" #include "z_zone.h" -// Parse the command line, merging WAD files that are sppecified. -// Returns true if at least one file was added. +/* + * Parse the command line, merging WAD files that are sppecified. + * Returns true if at least one file was added. + */ boolean W_ParseCommandLine(void) { boolean modifiedgame = false; int p; - // Merged PWADs are loaded first, because they are supposed to be - // modified IWADs. - + /* + * Merged PWADs are loaded first, because they are supposed to be + * modified IWADs. + */ //! // @arg // @category mod @@ -42,12 +45,11 @@ boolean W_ParseCommandLine(void) // Simulates the behavior of deutex's -merge option, merging a PWAD // into the main IWAD. Multiple files may be specified. // - p = M_CheckParmWithArgs("-merge", 1); if (p > 0) { - for (p = p + 1; p // @category mod // - // Simulates the behavior of NWT's -merge option. Multiple files + // Simulates the behavior of NWT's -merge option. Multiple files // may be specified. - p = M_CheckParmWithArgs("-nwtmerge", 1); if (p > 0) { - for (p = p + 1; p // @category mod // // Simulates the behavior of NWT's -af option, merging flats into - // the main IWAD directory. Multiple files may be specified. + // the main IWAD directory. Multiple files may be specified. // - p = M_CheckParmWithArgs("-af", 1); if (p > 0) { - for (p = p + 1; p 0) { - for (p = p + 1; p -as ". // - p = M_CheckParmWithArgs("-aa", 1); if (p > 0) { - for (p = p + 1; p #include @@ -58,21 +58,21 @@ static searchlist_t iwad_flats; static searchlist_t pwad_sprites; static searchlist_t pwad_flats; -// lumps with these sprites must be replaced in the IWAD +/* Lumps with these sprites must be replaced in the IWAD. */ static sprite_frame_t *sprite_frames; static int num_sprite_frames; static int sprite_frames_alloced; -// Search in a list to find a lump with a particular name -// Linear search (slow!) -// -// Returns -1 if not found - +/* + * Search in a list to find a lump with a particular name. + * Linear search (slow!). + * Returns -1 if not found. + */ static int FindInList(searchlist_t *list, char *name) { int i; - for (i=0; inumlumps; ++i) + for (i = 0; i < list->numlumps; ++i) { if (!strncasecmp(list->lumps[i]->name, name, 8)) return i; @@ -115,12 +115,10 @@ static boolean SetupList(searchlist_t *list, searchlist_t *src_list, return false; } -// Sets up the sprite/flat search lists - +/* Sets up the sprite/flat search lists. */ static void SetupLists(void) { - // IWAD - + /* IWAD */ if (!SetupList(&iwad_flats, &iwad, "F_START", "F_END", NULL, NULL)) { I_Error("Flats section not found in IWAD"); @@ -132,14 +130,12 @@ static void SetupLists(void) I_Error("Sprites section not found in IWAD"); } - // PWAD - + /* PWAD */ SetupList(&pwad_flats, &pwad, "F_START", "F_END", "FF_START", "FF_END"); SetupList(&pwad_sprites, &pwad, "S_START", "S_END", "SS_START", "SS_END"); } -// Initialize the replace list - +/* Initialize the replace list. */ static void InitSpriteList(void) { if (sprite_frames == NULL) @@ -154,21 +150,18 @@ static void InitSpriteList(void) static boolean ValidSpriteLumpName(char *name) { - if (name[0] == '\0' || name[1] == '\0' - || name[2] == '\0' || name[3] == '\0') + if (name[0] == '\0' || name[1] == '\0' || name[2] == '\0' || name[3] == '\0') { return false; } - // First frame: - + /* First frame */ if (name[4] == '\0' || !isdigit(name[5])) { return false; } - // Second frame (optional): - + /* Second frame (optional) */ if (name[6] != '\0' && !isdigit(name[7])) { return false; @@ -177,16 +170,14 @@ static boolean ValidSpriteLumpName(char *name) return true; } -// Find a sprite frame - +/* Find a sprite frame. */ static sprite_frame_t *FindSpriteFrame(char *name, int frame) { sprite_frame_t *result; int i; - // Search the list and try to find the frame - - for (i=0; i= sprite_frames_alloced) { sprite_frame_t *newframes; @@ -213,13 +201,12 @@ static sprite_frame_t *FindSpriteFrame(char *name, int frame) sprite_frames = newframes; } - // Add to end of list - + /* Add to end of list */ result = &sprite_frames[num_sprite_frames]; strncpy(result->sprname, name, 4); result->frame = frame; - for (i=0; i<8; ++i) + for (i = 0; i < 8; ++i) result->angle_lumps[i] = NULL; ++num_sprite_frames; @@ -227,8 +214,7 @@ static sprite_frame_t *FindSpriteFrame(char *name, int frame) return result; } -// Check if sprite lump is needed in the new wad - +/* Check if sprite lump is needed in the new wad. */ static boolean SpriteLumpNeeded(lumpinfo_t *lump) { sprite_frame_t *sprite; @@ -240,16 +226,14 @@ static boolean SpriteLumpNeeded(lumpinfo_t *lump) return true; } - // check the first frame - + /* Check the first frame */ sprite = FindSpriteFrame(lump->name, lump->name[4]); angle_num = lump->name[5] - '0'; if (angle_num == 0) { - // must check all frames - - for (i=0; i<8; ++i) + /* Must check all frames */ + for (i = 0; i < 8; ++i) { if (sprite->angle_lumps[i] == lump) return true; @@ -257,15 +241,12 @@ static boolean SpriteLumpNeeded(lumpinfo_t *lump) } else { - // check if this lump is being used for this frame - + /* Check if this lump is being used for this frame */ if (sprite->angle_lumps[angle_num - 1] == lump) return true; } - // second frame if any - - // no second frame? + /* Second frame if any. No second frame. */ if (lump->name[6] == '\0') return false; @@ -274,9 +255,8 @@ static boolean SpriteLumpNeeded(lumpinfo_t *lump) if (angle_num == 0) { - // must check all frames - - for (i=0; i<8; ++i) + /* Must check all frames */ + for (i = 0; i < 8; ++i) { if (sprite->angle_lumps[i] == lump) return true; @@ -284,8 +264,7 @@ static boolean SpriteLumpNeeded(lumpinfo_t *lump) } else { - // check if this lump is being used for this frame - + /* Check if this lump is being used for this frame */ if (sprite->angle_lumps[angle_num - 1] == lump) return true; } @@ -304,14 +283,13 @@ static void AddSpriteLump(lumpinfo_t *lump) return; } - // first angle - + /* First angle */ sprite = FindSpriteFrame(lump->name, lump->name[4]); angle_num = lump->name[5] - '0'; if (angle_num == 0) { - for (i=0; i<8; ++i) + for (i = 0; i < 8; ++i) sprite->angle_lumps[i] = lump; } else @@ -319,10 +297,7 @@ static void AddSpriteLump(lumpinfo_t *lump) sprite->angle_lumps[angle_num - 1] = lump; } - // second angle - - // no second angle? - + /* Second angle. No second angle.*/ if (lump->name[6] == '\0') return; @@ -331,7 +306,7 @@ static void AddSpriteLump(lumpinfo_t *lump) if (angle_num == 0) { - for (i=0; i<8; ++i) + for (i = 0; i < 8; ++i) sprite->angle_lumps[i] = lump; } else @@ -340,49 +315,46 @@ static void AddSpriteLump(lumpinfo_t *lump) } } -// Generate the list. Run at the start, before merging - +/* Generate the list. Run at the start, before merging. */ static void GenerateSpriteList(void) { int i; InitSpriteList(); - // Add all sprites from the IWAD - - for (i=0; iname, "F_START", 8)) - { - current_section = SECTION_FLATS; - } - else if (!strncasecmp(lump->name, "S_START", 8)) + case SECTION_NORMAL: + if (!strncasecmp(lump->name, "F_START", 8)) + { + current_section = SECTION_FLATS; + } + else if (!strncasecmp(lump->name, "S_START", 8)) + { + current_section = SECTION_SPRITES; + } + + newlumps[num_newlumps++] = lump; + + break; + + case SECTION_FLATS: + + /* Have we reached the end of the section */ + if (!strncasecmp(lump->name, "F_END", 8)) + { + /* + * Add all new flats from the PWAD to the end + * of the section. + */ + for (n = 0; n < pwad_flats.numlumps; ++n) { - current_section = SECTION_SPRITES; + newlumps[num_newlumps++] = pwad_flats.lumps[n]; } newlumps[num_newlumps++] = lump; - break; - - case SECTION_FLATS: - - // Have we reached the end of the section? - - if (!strncasecmp(lump->name, "F_END", 8)) + /* Back to normal reading */ + current_section = SECTION_NORMAL; + } + else + { + /* + * If there is a flat in the PWAD with the same name, + * do not add it now. All PWAD flats are added to the + * end of the section. Otherwise, if it is only in the + * IWAD, add it now + */ + lumpindex = FindInList(&pwad_flats, lump->name); + + if (lumpindex < 0) { - // Add all new flats from the PWAD to the end - // of the section - - for (n=0; nname); - - if (lumpindex < 0) - { - newlumps[num_newlumps++] = lump; - } } + } - break; + break; - case SECTION_SPRITES: + case SECTION_SPRITES: - // Have we reached the end of the section? - - if (!strncasecmp(lump->name, "S_END", 8)) + /* Have we reached the end of the section */ + if (!strncasecmp(lump->name, "S_END", 8)) + { + /* Add all the PWAD sprites */ + for (n = 0; n < pwad_sprites.numlumps; ++n) { - // add all the PWAD sprites - - for (n=0; nname, "F_START", 8) - || !strncasecmp(lump->name, "FF_START", 8)) - { - current_section = SECTION_FLATS; - } - else if (!strncasecmp(lump->name, "S_START", 8) - || !strncasecmp(lump->name, "SS_START", 8)) - { - current_section = SECTION_SPRITES; - } - else - { - // Don't include the headers of sections - - newlumps[num_newlumps++] = lump; - } - break; - - case SECTION_FLATS: - - // PWAD flats are ignored (already merged) - - if (!strncasecmp(lump->name, "FF_END", 8) - || !strncasecmp(lump->name, "F_END", 8)) - { - // end of section - current_section = SECTION_NORMAL; - } - break; - - case SECTION_SPRITES: - - // PWAD sprites are ignored (already merged) - - if (!strncasecmp(lump->name, "SS_END", 8) - || !strncasecmp(lump->name, "S_END", 8)) - { - // end of section - current_section = SECTION_NORMAL; - } - break; + case SECTION_NORMAL: + if (!strncasecmp(lump->name, "F_START", 8) || !strncasecmp(lump->name, "FF_START", 8)) + { + current_section = SECTION_FLATS; + } + else if (!strncasecmp(lump->name, "S_START", 8) || !strncasecmp(lump->name, "SS_START", 8)) + { + current_section = SECTION_SPRITES; + } + else + { + /* Don't include the headers of sections */ + newlumps[num_newlumps++] = lump; + } + break; + + case SECTION_FLATS: + + /* PWAD flats are ignored (already merged) */ + if (!strncasecmp(lump->name, "FF_END", 8) || !strncasecmp(lump->name, "F_END", 8)) + { + // end of section + current_section = SECTION_NORMAL; + } + break; + + case SECTION_SPRITES: + + /* PWAD sprites are ignored (already merged) */ + if (!strncasecmp(lump->name, "SS_END", 8) || !strncasecmp(lump->name, "S_END", 8)) + { + /* End of section */ + current_section = SECTION_NORMAL; + } + break; } } - // Switch to the new lumpinfo, and free the old one - + /* Switch to the new lumpinfo, and free the old one */ free(lumpinfo); lumpinfo = newlumps; numlumps = num_newlumps; @@ -556,58 +520,53 @@ void W_PrintDirectory(void) { unsigned int i, n; - // debug - for (i=0; iname[n] != '\0'; ++n) + for (n = 0; n < 8 && lumpinfo[i]->name[n] != '\0'; ++n) putchar(lumpinfo[i]->name[n]); putchar('\n'); } } -// Merge in a file by name - +/* Merge in a file by name. */ void W_MergeFile(char *filename) { int old_numlumps; old_numlumps = numlumps; - // Load PWAD - + /* Load PWAD */ if (W_AddFile(filename) == NULL) return; - // IWAD is at the start, PWAD was appended to the end - + /* IWAD is at the start, PWAD was appended to the end */ iwad.lumps = lumpinfo; iwad.numlumps = old_numlumps; pwad.lumps = lumpinfo + old_numlumps; pwad.numlumps = numlumps - old_numlumps; - // Setup sprite/flat lists - + /* Setup sprite/flat lists */ SetupLists(); - // Generate list of sprites to be replaced by the PWAD - + /* Generate list of sprites to be replaced by the PWAD */ GenerateSpriteList(); - // Perform the merge - + /* Perform the merge */ DoMerge(); } -// Replace lumps in the given list with lumps from the PWAD - +/* Replace lumps in the given list with lumps from the PWAD. */ static void W_NWTAddLumps(searchlist_t *list) { int i; - // Go through the IWAD list given, replacing lumps with lumps of - // the same name from the PWAD - for (i=0; inumlumps; ++i) + /* + * Go through the IWAD list given, replacing lumps with lumps of + * the same name from the PWAD. + */ + for (i = 0; i < list->numlumps; ++i) { int index; @@ -621,55 +580,51 @@ static void W_NWTAddLumps(searchlist_t *list) } } -// Merge sprites and flats in the way NWT does with its -af and -as -// command-line options. - +/* + * Merge sprites and flats in the way NWT does with its -af and -as + * command-line options. + */ void W_NWTMergeFile(char *filename, int flags) { int old_numlumps; old_numlumps = numlumps; - // Load PWAD - + /* Load PWAD */ if (W_AddFile(filename) == NULL) return; - // IWAD is at the start, PWAD was appended to the end - + /* IWAD is at the start, PWAD was appended to the end */ iwad.lumps = lumpinfo; iwad.numlumps = old_numlumps; pwad.lumps = lumpinfo + old_numlumps; pwad.numlumps = numlumps - old_numlumps; - // Setup sprite/flat lists - + /* Setup sprite/flat lists */ SetupLists(); - // Merge in flats? - + /* Merge in flats */ if (flags & W_NWT_MERGE_FLATS) { W_NWTAddLumps(&iwad_flats); } - // Sprites? - + /* Sprites */ if (flags & W_NWT_MERGE_SPRITES) { W_NWTAddLumps(&iwad_sprites); } - // Discard the PWAD - + /* Discard the PWAD */ numlumps = old_numlumps; } -// Simulates the NWT -merge command line parameter. What this does is load -// a PWAD, then search the IWAD sprites, removing any sprite lumps that also -// exist in the PWAD. - +/* + * Simulates the NWT -merge command line parameter. What this does is load + * a PWAD, then search the IWAD sprites, removing any sprite lumps that also + * exist in the PWAD. + */ void W_NWTDashMerge(char *filename) { wad_file_t *wad_file; @@ -678,8 +633,7 @@ void W_NWTDashMerge(char *filename) old_numlumps = numlumps; - // Load PWAD - + /* Load PWAD */ wad_file = W_AddFile(filename); if (wad_file == NULL) @@ -687,34 +641,33 @@ void W_NWTDashMerge(char *filename) return; } - // IWAD is at the start, PWAD was appended to the end - + /* IWAD is at the start, PWAD was appended to the end */ iwad.lumps = lumpinfo; iwad.numlumps = old_numlumps; pwad.lumps = lumpinfo + old_numlumps; pwad.numlumps = numlumps - old_numlumps; - // Setup sprite/flat lists - + /* Setup sprite/flat lists */ SetupLists(); - // Search through the IWAD sprites list. - - for (i=0; iname) >= 0) { - // Replace this entry with an empty string. This is what - // nwt -merge does. - + /* + * Replace this entry with an empty string. This is what + * nwt -merge does. + */ M_StringCopy(iwad_sprites.lumps[i]->name, "", 8); } } - // Discard PWAD - // The PWAD must now be added in again with -file. - + /* + * Discard PWAD. + * The PWAD must now be added in again with -file. + */ numlumps = old_numlumps; W_CloseFile(wad_file); diff --git a/zephyrdoom/src/w_merge.h b/zephyrdoom/src/w_merge.h index a52adba..e5456f2 100644 --- a/zephyrdoom/src/w_merge.h +++ b/zephyrdoom/src/w_merge.h @@ -1,43 +1,39 @@ -// -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Handles merging of PWADs, similar to deutex's -merge option -// -// Ideally this should work exactly the same as in deutex, but trying to -// read the deutex source code made my brain hurt. -// +/* + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Handles merging of PWADs, similar to deutex's -merge option + * + * Ideally this should work exactly the same as in deutex, but trying to + * read the deutex source code made my brain hurt. + */ #ifndef W_MERGE_H #define W_MERGE_H -#define W_NWT_MERGE_SPRITES 0x1 -#define W_NWT_MERGE_FLATS 0x2 - -// Add a new WAD and merge it into the main directory +#define W_NWT_MERGE_SPRITES 0x1 +#define W_NWT_MERGE_FLATS 0x2 +/* Add a new WAD and merge it into the main directory. */ void W_MergeFile(char *filename); -// NWT-style merging - +/* NWT-style merging. */ void W_NWTMergeFile(char *filename, int flags); -// Acts the same as NWT's "-merge" option. - +/* Acts the same as NWT's "-merge" option. */ void W_NWTDashMerge(char *filename); -// Debug function that prints the WAD directory. - +/* Debug function that prints the WAD directory. */ void W_PrintDirectory(void); -#endif /* #ifndef W_MERGE_H */ +#endif /* W_MERGE_H */ diff --git a/zephyrdoom/src/w_wad.c b/zephyrdoom/src/w_wad.c index 324601e..af4f79d 100644 --- a/zephyrdoom/src/w_wad.c +++ b/zephyrdoom/src/w_wad.c @@ -1,23 +1,20 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Handles WAD file header, directory, lump I/O. -// - - - +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Handles WAD file header, directory, lump I/O. + */ #include #include @@ -41,105 +38,108 @@ #include "n_buttons.h" -typedef PACKED_STRUCT ( -{ - // Should be "IWAD" or "PWAD". - char identification[4]; - int numlumps; - int infotableofs; -}) wadinfo_t; - - -typedef PACKED_STRUCT ( -{ - int filepos; - int size; - char name[8]; -}) filelump_t; +typedef PACKED_STRUCT( + { + /* Should be "IWAD" or "PWAD" */ + char identification[4]; + int numlumps; + int infotableofs; + }) wadinfo_t; +typedef PACKED_STRUCT( + { + int filepos; + int size; + char name[8]; + }) filelump_t; #include "n_fs.h" #include "n_qspi.h" #include "n_mem.h" +/* From main.c */ +extern int no_sdcard; -extern int no_sdcard; //NRFD-NOTE: from main.c -// -// GLOBALS -// +/* Globals. */ -// wad_file_t *wad_file = NULL; // NRFD +/* + * // NRFD-TODO + * wad_file_t *wad_file = NULL; + */ -// Location of each lump on disk. +/* Location of each lump on disk. */ #define MAX_NUMLUMPS 1300 -// lumpinfo_t lumpinfo[MAX_NUMLUMPS]; + +/* + * // TODO + * lumpinfo_t lumpinfo[MAX_NUMLUMPS]; + */ + unsigned short numlumps = 0; filelump_t *filelumps; -// Hash table for fast lookups +/* Hash table for fast lookups. */ static lumpindex_t *lumphash = NULL; N_FILE wad_file; int first_lump_pos; /* -int debugLumpCount = 0; -int debugLumpNums[12]; -void *debugLumpCache[12]; -*/ - -// Variables for the reload hack: filename of the PWAD to reload, and the -// lumps from WADs before the reload file, so we can resent numlumps and -// load the file again. -/* NRFD-EXCLUDE -static wad_file_t *reloadhandle = NULL; -static lumpinfo_t *reloadlumps = NULL; -static char *reloadname = NULL; -static int reloadlump = -1; -*/ - -// Hash function used for lump names. + * // TODO + * int debugLumpCount = 0; + * int debugLumpNums[12]; + * void *debugLumpCache[12]; + */ + +/* + * // NRFD-EXCLUDE + * // Variables for the reload hack: filename of the PWAD to reload, and the + * // lumps from WADs before the reload file, so we can resent numlumps and + * // load the file again. + * static wad_file_t *reloadhandle = NULL; + * static lumpinfo_t *reloadlumps = NULL; + * static char *reloadname = NULL; + * static int reloadlump = -1; + */ + +/* Hash function used for lump names. */ unsigned int W_LumpNameHash(const char *s) { - // This is the djb2 string hash function, modded to work on strings - // that have a maximum length of 8. - + /* + * This is the djb2 string hash function, modded to work on strings + * that have a maximum length of 8. + */ unsigned int result = 5381; unsigned int i; - for (i=0; i < 8 && s[i] != '\0'; ++i) + for (i = 0; i < 8 && s[i] != '\0'; ++i) { - result = ((result << 5) ^ result ) ^ toupper(s[i]); + result = ((result << 5) ^ result) ^ toupper(s[i]); } return result; } -// -// LUMP BASED ROUTINES. -// +/* Lump based routines. */ -// -// W_AddFile -// All files are optional, but at least one file must be -// found (PWAD, if all required lumps are present). -// Files with a .wad extension are wadlink files -// with multiple lumps. -// Other files are single lumps with the base filename -// for the lump name. - -wad_file_t *W_AddFile (char *filename) +/* + * All files are optional, but at least one file must be + * found (PWAD, if all required lumps are present). + * Files with a .wad extension are wadlink files with multiple lumps. + * Other files are single lumps with the base filename for the lump name. + */ +wad_file_t *W_AddFile(char *filename) { wadinfo_t header; lumpindex_t i; - // wad_file_t *wad_file; + /* wad_file_t *wad_file; */ wad_file_t *wad_file_data; int length; int startlump; filelump_t *fileinfo; filelump_t *filerover; - // lumpinfo_t *filelumps; + /* lumpinfo_t *filelumps; */ boolean do_wad_transfer = false; @@ -147,132 +147,160 @@ wad_file_t *W_AddFile (char *filename) I_Sleep(1); N_ReadButtons(); - if (N_ButtonState(0)) { + if (N_ButtonState(0)) + { do_wad_transfer = true; } - /* NRFD-EXCLUDE: - // If the filename begins with a ~, it indicates that we should use the - // reload hack. - if (filename[0] == '~') + /* + * // NRFD-EXCLUDE + * // If the filename begins with a ~, it indicates that we should use the + * // reload hack. + * if (filename[0] == '~') + * { + * if (reloadname != NULL) + * { + * I_Error("Prefixing a WAD filename with '~' indicates that the " + * "WAD should be reloaded\n" + * "on each level restart, for use by level authors for " + * "rapid development. You\n" + * "can only reload one WAD file, and it must be the last " + * "file in the -file list."); + * } + * + * reloadname = strdup(filename); + * reloadlump = numlumps; + * ++filename; + * } + */ + + if (numlumps != 0) { - if (reloadname != NULL) - { - I_Error("Prefixing a WAD filename with '~' indicates that the " - "WAD should be reloaded\n" - "on each level restart, for use by level authors for " - "rapid development. You\n" - "can only reload one WAD file, and it must be the last " - "file in the -file list."); - } - - reloadname = strdup(filename); - reloadlump = numlumps; - ++filename; - } - */ - - if (numlumps != 0) { I_Error("Only one wad file supported\n"); } printf("W_AddFile: Reading %s\n", filename); - // Open the file and add to directory - // wad_file = W_OpenFile(filename); - if (!no_sdcard) { - // wad_file = N_fs_open(filename); - // if (wad_file == NULL) - // { - // printf (" couldn't open %s\n", filename); - // return NULL; - // } - } else { + + /* + * // TODO + * // Open the file and add to directory + * wad_file = W_OpenFile(filename); + */ + + if (!no_sdcard) + { + /* + * // TODO + * wad_file = N_fs_open(filename); + * if (wad_file == NULL) + * { + * printf(" couldn't open %s\n", filename); + * return NULL; + * } + */ + } + else + { printf("no_sdcard = 1 - skipping file open\n"); } wad_file_data = Z_Malloc(sizeof(wad_file_t), PU_STATIC, 0); - if (strcasecmp(filename+strlen(filename)-3 , "wad" ) ) + if (strcasecmp(filename + strlen(filename) - 3, "wad")) { - I_Error("NRFD-TODO: W_AddFile\n"); /* - // single lump file - - // fraggle: Swap the filepos and size here. The WAD directory - // parsing code expects a little-endian directory, so will swap - // them back. Effectively we're constructing a "fake WAD directory" - // here, as it would appear on disk. - - fileinfo = Z_N_Malloc(sizeof(filelump_t), PU_STATIC, 0); - fileinfo->filepos = LONG(0); - fileinfo->size = LONG(wad_file->length); - - // Name the lump after the base of the filename (without the - // extension). - - M_ExtractFileBase (filename, fileinfo->name); - numfilelumps = 1; - */ + * // NRFD-TODO + * // Single lump file. + * // fraggle - Swap the filepos and size here. The WAD directory + * // parsing code expects a little-endian directory, so will swap + * // them back. Effectively we're constructing a "fake WAD directory" + * // here, as it would appear on disk. + * fileinfo = Z_N_Malloc(sizeof(filelump_t), PU_STATIC, 0); + * fileinfo->filepos = LONG(0); + * fileinfo->size = LONG(wad_file->length); + * + * // Name the lump after the base of the filename (without the + * // extension). + * M_ExtractFileBase(filename, fileinfo->name); + * numfilelumps = 1; + */ } else { - // Copy entire WAD file to Flash memory - + /* Copy entire WAD file to Flash memory */ long file_size = 4196366; - if (!no_sdcard) { - // file_size = N_fs_size(wad_file); + if (!no_sdcard) + { + /* + * // TODO + * file_size = N_fs_size(wad_file); + */ } printf("File size: %ld\n", file_size); int num_blocks = (file_size + N_QSPI_BLOCK_SIZE - 1) / N_QSPI_BLOCK_SIZE; N_qspi_reserve_blocks(num_blocks); - if (!no_sdcard) { + if (!no_sdcard) + { uint8_t *block_data = N_malloc(N_QSPI_BLOCK_SIZE); int block_loc = 0; uint8_t *qspi_data = N_qspi_data_pointer(0); boolean data_mismatch = do_wad_transfer; /* - for (i = 0; i file_size ? (file_size%N_QSPI_BLOCK_SIZE) : N_QSPI_BLOCK_SIZE; - printf("N_fs_read\n"); - N_fs_read(wad_file, block_loc, block_data, block_size); - printf("Comparing...\n"); - for (int j = 0; j file_size ? (file_size % N_QSPI_BLOCK_SIZE) : N_QSPI_BLOCK_SIZE; + * printf("N_fs_read\n"); + * N_fs_read(wad_file, block_loc, block_data, block_size); + * printf("Comparing...\n"); + * for (int j = 0; j < block_size; j++) + * { + * if (block_data[j] != qspi_data[block_loc + j]) + * { + * data_mismatch = true; + * printf("Found mismatch in byte %d\n", block_loc + j); + * break; + * } + * } + * if (data_mismatch) + * break; + * block_loc = block_next; + * } + */ + + if (data_mismatch) + { printf("Uploading WAD data to QSPI flash memory.."); block_loc = 0; - for (i = 0; i file_size ? (file_size%N_QSPI_BLOCK_SIZE) : N_QSPI_BLOCK_SIZE; + int block_size = block_next > file_size ? (file_size % N_QSPI_BLOCK_SIZE) : N_QSPI_BLOCK_SIZE; printf("N_fs_read\n"); - // N_fs_read(wad_file, block_loc, block_data, block_size); + /* N_fs_read(wad_file, block_loc, block_data, block_size); */ printf("First 40b of block: \n"); int pt = 0; int tmp = 0; - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 10; j++) { + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 10; j++) + { printf("%x ", block_data[pt]); pt++; } printf("| "); - for (int j = 0; j < 10; j++) { - if (block_data[tmp] >= 33 && block_data[tmp] <= 126) { + for (int j = 0; j < 10; j++) + { + if (block_data[tmp] >= 33 && block_data[tmp] <= 126) + { printf("%c ", block_data[tmp]); - } else { + } + else + { printf(". "); } tmp++; @@ -282,20 +310,26 @@ wad_file_t *W_AddFile (char *filename) printf("\n"); printf("N_qspi_write_block\n"); N_qspi_write_block(block_loc, block_data, block_size); - N_qspi_read(block_loc,block_data,block_size); + N_qspi_read(block_loc, block_data, block_size); printf("First 40b of block in flash: \n"); pt = 0; tmp = 0; - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 10; j++) { + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 10; j++) + { printf("%x ", block_data[pt]); pt++; } printf("| "); - for (int j = 0; j < 10; j++) { - if (block_data[tmp] >= 33 && block_data[tmp] <= 126) { + for (int j = 0; j < 10; j++) + { + if (block_data[tmp] >= 33 && block_data[tmp] <= 126) + { printf("%c ", block_data[tmp]); - } else { + } + else + { printf(". "); } tmp++; @@ -308,23 +342,28 @@ wad_file_t *W_AddFile (char *filename) N_free(block_data); } - wadinfo_t *header_ptr = N_qspi_data_pointer(0); char *dat_ptr = N_qspi_data_pointer(0); printf("Dumping flash data: \n"); int pt = 0; int tmp = 0; - for (int i = 0; i < 30; i++) { - for (int j = 0; j < 10; j++) { + for (int i = 0; i < 30; i++) + { + for (int j = 0; j < 10; j++) + { printf("%x ", dat_ptr[pt]); pt++; } printf("| "); - for (int j = 0; j < 10; j++) { - if (dat_ptr[tmp] >= 33 && dat_ptr[tmp] <= 126) { + for (int j = 0; j < 10; j++) + { + if (dat_ptr[tmp] >= 33 && dat_ptr[tmp] <= 126) + { printf("%c ", dat_ptr[tmp]); - } else { + } + else + { printf(". "); } tmp++; @@ -332,96 +371,123 @@ wad_file_t *W_AddFile (char *filename) printf("\n"); } - // WAD file - // W_Read(wad_file, 0, &header, sizeof(header)); + /* + * // TODO + * // WAD file + * W_Read(wad_file, 0, &header, sizeof(header)); + */ + printf("Header: %x %x %x %x\n", header_ptr->identification[0], - header_ptr->identification[1], - header_ptr->identification[2], - header_ptr->identification[3]); - if (strncmp(header_ptr->identification,"IWAD",4)) + header_ptr->identification[1], + header_ptr->identification[2], + header_ptr->identification[3]); + if (strncmp(header_ptr->identification, "IWAD", 4)) { - // Homebrew levels? - if (strncmp(header_ptr->identification,"PWAD",4)) + /* Homebrew levels */ + if (strncmp(header_ptr->identification, "PWAD", 4)) { - // W_CloseFile(wad_file); - I_Error ("Wad file %s doesn't have IWAD " - "or PWAD id\n", filename); + /* + * // TODO + * W_CloseFile(wad_file); + */ + + I_Error("Wad file %s doesn't have IWAD " + "or PWAD id\n", + filename); } - // ???modifiedgame = true; + /* + * // TOOD + * modifiedgame = true; + */ } header_ptr->numlumps = LONG(header_ptr->numlumps); - // Vanilla Doom doesn't like WADs with more than 4046 lumps - // https://www.doomworld.com/vb/post/1010985 - if (!strncmp(header_ptr->identification,"PWAD",4) && header_ptr->numlumps > 4046) - { - // W_CloseFile(wad_file); - I_Error ("Error: Vanilla limit for lumps in a WAD is 4046, " - "PWAD %s has %d", filename, header_ptr->numlumps); - } + /* + * Vanilla Doom doesn't like WADs with more than 4046 lumps. + * https://www.doomworld.com/vb/post/1010985 + */ + if (!strncmp(header_ptr->identification, "PWAD", 4) && header_ptr->numlumps > 4046) + { + /* + * // TODO + * W_CloseFile(wad_file); + */ + + I_Error("Error: Vanilla limit for lumps in a WAD is 4046, " + "PWAD %s has %d", + filename, header_ptr->numlumps); + } header_ptr->infotableofs = LONG(header_ptr->infotableofs); - // length = header_ptr->numlumps*sizeof(filelump_t); - // fileinfo = Z_Malloc(length, PU_STATIC, 0); + + /* + * TODO + * length = header_ptr->numlumps * sizeof(filelump_t); + * fileinfo = Z_Malloc(length, PU_STATIC, 0); + */ printf("WAD header_ptr\n"); printf("ID: %.4s\n", header_ptr->identification); printf("Num lumps: %d\n", header_ptr->numlumps); printf("Info table: %d\n", header_ptr->infotableofs); - - if (numlumps != 0) { + if (numlumps != 0) + { I_Error("NRFD-TODO: Multiple WADs not supported yet\n"); } - if ((numlumps+header_ptr->numlumps) > MAX_NUMLUMPS) { + if ((numlumps + header_ptr->numlumps) > MAX_NUMLUMPS) + { I_Error("W_AddFile: MAX_NUMLUMPS reached\n"); } first_lump_pos = header_ptr->infotableofs; - filelumps = (filelump_t*)N_qspi_data_pointer(first_lump_pos); - numlumps += header_ptr->numlumps; - /* - for (i = 0; i < header_ptr->numlumps; i++) - { - filelump_t filelump; - int lump_pos = header_ptr->infotableofs+sizeof(filelump_t)*i; - // W_Read(wad_file, lump_pos, &filelump, sizeof(filelump_t)); - filelump = *((filelump_t*)(N_qspi_data_pointer(lump_pos))); - lumpinfo_t *lump_p = &lumpinfo[numlumps]; - // lump_p->wad_file = wad_file; // NRFD-TODO: Support multiple files - // lump_p->position = LONG(filelump.filepos); - unsigned int lump_filepos = LONG(filelump.filepos); - lump_p->size = LONG(filelump.size); - // lump_p->cache = NULL; - lump_p->cache = N_qspi_data_pointer(lump_filepos); - strncpy(lump_p->name, filelump.name, 8); - - // printf("Lump %.8s: num: %d size: %d location: %X\n", lump_p->name, numlumps, lump_p->size, (unsigned int)lump_p->cache); - - if (0) //!strncasecmp(filelump.name, "ENDOOM", 8)) - { - printf("Found ENDOOM at %X\n", lump_filepos); - char *endoom = lump_p->cache; - printf("%X\n", (unsigned int)(endoom)); - for (int i=0; i<80*4; i++) { - char c = endoom[i]; - if (i%2==1) continue; - if ((i/2)%80==0) - printf("\n"); - if (c < 32 || c > 127) - printf("X"); - else - printf("%c", c); - } - printf("\n"); - } + filelumps = (filelump_t *)N_qspi_data_pointer(first_lump_pos); + numlumps += header_ptr->numlumps; - numlumps += 1; - } - */ + /* + * // NRFD-TODO / TODO + * for (i = 0; i < header_ptr->numlumps; i++) + * { + * filelump_t filelump; + * int lump_pos = header_ptr->infotableofs + sizeof(filelump_t) * i; + * // W_Read(wad_file, lump_pos, &filelump, sizeof(filelump_t)); + * filelump = *((filelump_t *)(N_qspi_data_pointer(lump_pos))); + * lumpinfo_t *lump_p = &lumpinfo[numlumps]; + * // Support multiple files + * // lump_p->wad_file = wad_file; + * // lump_p->position = LONG(filelump.filepos); + * unsigned int lump_filepos = LONG(filelump.filepos); + * lump_p->size = LONG(filelump.size); + * // lump_p->cache = NULL; + * lump_p->cache = N_qspi_data_pointer(lump_filepos); + * strncpy(lump_p->name, filelump.name, 8); + * + * if (0) //! strncasecmp(filelump.name, "ENDOOM", 8)) + * { + * printf("Found ENDOOM at %X\n", lump_filepos); + * char *endoom = lump_p->cache; + * printf("%X\n", (unsigned int)(endoom)); + * for (int i = 0; i < 80 * 4; i++) + * { + * char c = endoom[i]; + * if (i % 2 == 1) + * continue; + * if ((i / 2) % 80 == 0) + * printf("\n"); + * if (c < 32 || c > 127) + * printf("X"); + * else + * printf("%c", c); + * } + * printf("\n"); + * } + * + * numlumps += 1; + * } + */ wad_file_data->path = filename; wad_file_data->length = file_size; @@ -433,96 +499,85 @@ wad_file_t *W_AddFile (char *filename) lumphash = NULL; } - /* NRFD-EXCLUDE - // If this is the reload file, we need to save some details about the - // file so that we can close it later on when we do a reload. - if (reloadname) - { - reloadhandle = wad_file; - reloadlumps = filelumps; - } - */ + /* + * NRFD-EXCLUDE + * // If this is the reload file, we need to save some details about the + * // file so that we can close it later on when we do a reload. + * if (reloadname) + * { + * reloadhandle = wad_file; + * reloadlumps = filelumps; + * } + */ return wad_file_data; } - void *W_LumpDataPointer(lumpindex_t lump) { return N_qspi_data_pointer(LONG(filelumps[lump].filepos)); } -// -// W_NumLumps -// -int W_NumLumps (void) +int W_NumLumps(void) { return numlumps; } -// -// W_CheckNumForName -// Returns -1 if name not found. -// - -lumpindex_t W_CheckNumForName(const char* name) +/* Returns -1 if name not found. */ +lumpindex_t W_CheckNumForName(const char *name) { lumpindex_t i; - // Do we have a hash table yet? - - /* NRFD-TODO: lump hash table */ /* - if (lumphash != NULL) + * NRFD-TODO + * // Lump hash table. + * // Do we have a hash table yet. + * if (lumphash != NULL) + * { + * int hash; + * + * // We do! Excellent. + * hash = W_LumpNameHash(name) % numlumps; + * + * for (i = lumphash[hash]; i != -1; i = lumpinfo[i]->next) + * { + * if (!strncasecmp(lumpinfo[i]->name, name, 8)) + * { + * return i; + * } + * } + * } + * else + */ { - int hash; - - // We do! Excellent. - - hash = W_LumpNameHash(name) % numlumps; - - for (i = lumphash[hash]; i != -1; i = lumpinfo[i]->next) - { - if (!strncasecmp(lumpinfo[i]->name, name, 8)) - { - return i; - } - } - } - else*/ - { - // We don't have a hash table generate yet. Linear search :-( - // - // scan backwards so patch lump files take precedence - + /* + * We don't have a hash table generate yet. Linear search :-( + * Scan backwards so patch lump files take precedence. + */ for (i = numlumps - 1; i >= 0; --i) { if (!strncasecmp(filelumps[i].name, name, 8)) - // if (!strncasecmp(lumpinfo[i].name, name, 8)) + /* if (!strncasecmp(lumpinfo[i].name, name, 8)) */ { return i; } } } - // TFB. Not found. - + /* TFB. Not found. */ return -1; } -// -// W_GetNumForName -// Calls W_CheckNumForName, but bombs out if not found. -// -lumpindex_t W_GetNumForName(const char* name) +/* Calls W_CheckNumForName, but bombs out if not found. */ +lumpindex_t W_GetNumForName(const char *name) { lumpindex_t i; - i = W_CheckNumForName (name); + i = W_CheckNumForName(name); if (i < 0) { - I_Error ("W_GetNumForName: %s not found!", name); + I_Error("W_GetNumForName: %s not found!", name); } return i; @@ -533,178 +588,168 @@ char *W_LumpName(lumpindex_t lump) return filelumps[lump].name; } -// -// W_LumpLength -// Returns the buffer size needed to load the given lump. -// +/* Returns the buffer size needed to load the given lump. */ int W_LumpLength(lumpindex_t lump) { if (lump >= numlumps) { - I_Error ("W_LumpLength: %i >= numlumps", lump); + I_Error("W_LumpLength: %i >= numlumps", lump); } - // return lumpinfo[lump].size; + /* return lumpinfo[lump].size; */ return LONG(filelumps[lump].size); } - - -// -// W_ReadLump -// Loads the lump into the given buffer, -// which must be >= W_LumpLength(). -// +/* Loads the lump into the given buffer, which must be >= W_LumpLength(). */ void W_ReadLump(lumpindex_t lump, void *dest) { if (lump >= numlumps) { - I_Error ("W_ReadLump: %i >= numlumps", lump); + I_Error("W_ReadLump: %i >= numlumps", lump); } - // lumpinfo_t *l; - // l = &lumpinfo[lump]; - // printf("W_ReadLump(dummy): %.8s\n", l->name); + /* + * // TODO + * lumpinfo_t *l; + * l = &lumpinfo[lump]; + * printf("W_ReadLump(dummy): %.8s\n", l->name); + * + * V_BeginRead(l->size); + */ - // V_BeginRead(l->size); filelump_t *filelump = &filelumps[lump]; void *ptr = N_qspi_data_pointer(LONG(filelump->filepos)); memcpy(dest, ptr, LONG(filelump->size)); - // memcpy(dest, l->cache, l->size); - - /* NRFD-EXCLUDE - - // int c; - // printf("Read lump at %d with size %d to %X\n", l->position, l->size, (unsigned int)(dest)); - // c = W_Read(l->wad_file, l->position, dest, l->size); - // c = W_Read(wad_file, l->position, dest, l->size); + /* memcpy(dest, l->cache, l->size); */ - if (c < l->size) - { - I_Error("W_ReadLump: only read %i of %i on lump %i", - c, l->size, lump); - }*/ + /* + * // NRFD-EXCLUDE + * int c; + * printf("Read lump at %d with size %d to %X\n", l->position, l->size, (unsigned int)(dest)); + * c = W_Read(l->wad_file, l->position, dest, l->size); + * c = W_Read(wad_file, l->position, dest, l->size); + * + * if (c < l->size) + * { + * I_Error("W_ReadLump: only read %i of %i on lump %i", + * c, l->size, lump); + * } + */ } - - - -// -// W_CacheLumpNum -// -// Load a lump into memory and return a pointer to a buffer containing -// the lump data. -// -// 'tag' is the type of zone memory buffer to allocate for the lump -// (usually PU_STATIC or PU_CACHE). If the lump is loaded as -// PU_STATIC, it should be released back using W_ReleaseLumpNum -// when no longer needed (do not use Z_ChangeTag). -// - +/* + * Load a lump into memory and return a pointer to a buffer containing + * the lump data. + * + * 'tag' is the type of zone memory buffer to allocate for the lump + * (usually PU_STATIC or PU_CACHE). If the lump is loaded as + * PU_STATIC, it should be released back using W_ReleaseLumpNum + * when no longer needed (do not use Z_ChangeTag). + */ void *W_CacheLumpNum(lumpindex_t lumpnum, int tag) { byte *result; - // lumpinfo_t *lump; + + /* lumpinfo_t *lump; */ if ((unsigned)lumpnum >= numlumps) { - I_Error ("W_CacheLumpNum: %i >= numlumps", lumpnum); + I_Error("W_CacheLumpNum: %i >= numlumps", lumpnum); } - // lump = &lumpinfo[lumpnum]; - - // Get the pointer to return. If the lump is in a Memory-mapped - // file, we can just return a pointer to within the memory-mapped - // region. If the lump is in an ordinary file, we may already - // have it cached; otherwise, load it into memory. - - // result = lump->cache; /* - for (int i=0;icache; + * + * for (int i = 0; i < debugLumpCount; i++) + * { + * if (debugLumpNums[i] == lumpnum) + * { + * byte *cache = debugLumpCache[i]; + * byte *qspi_data = W_LumpDataPointer(lumpnum); + * for (int j = 0; j < filelumps[lumpnum].size; j++) + * { + * if (cache[j] != qspi_data[j]) + * { + * printf("X"); + * } + * } + * return cache; + * } + * } + */ + result = W_LumpDataPointer(lumpnum); - // N_ldbg("W_CacheLumpNum: %.8s\n", lump->name); - /* NRFD-EXCLUDE: - if (lump->wad_file->mapped != NULL) - { - // Memory mapped file, return from the mmapped region. + /* N_ldbg("W_CacheLumpNum: %.8s\n", lump->name); */ - result = lump->wad_file->mapped + lump->position; - } - else if (lump->cache != NULL) - { - // Already cached, so just switch the zone tag. - - result = lump->cache; - Z_ChangeTag(lump->cache, tag); - } - else - { - // Not yet loaded, so load it now - lump->cache = Z_Malloc(W_LumpLength(lumpnum), tag, &lump->cache); - W_ReadLump (lumpnum, lump->cache); - result = lump->cache; - } - */ + /* + * // NRFD-EXCLUDE + * if (lump->wad_file->mapped != NULL) + * { + * // Memory mapped file, return from the mmapped region + * result = lump->wad_file->mapped + lump->position; + * } + * else if (lump->cache != NULL) + * { + * // Already cached, so just switch the zone tag + * result = lump->cache; + * Z_ChangeTag(lump->cache, tag); + * } + * else + * { + * // Not yet loaded, so load it now + * lump->cache = Z_Malloc(W_LumpLength(lumpnum), tag, &lump->cache); + * W_ReadLump(lumpnum, lump->cache); + * result = lump->cache; + * } + */ return result; } - - -// -// W_CacheLumpName -// void *W_CacheLumpName(char *name, int tag) { return W_CacheLumpNum(W_GetNumForName(name), tag); } -// -// Release a lump back to the cache, so that it can be reused later -// without having to read from disk again, or alternatively, discarded -// if we run out of memory. -// -// Back in Vanilla Doom, this was just done using Z_ChangeTag -// directly, but now that we have WAD mmap, things are a bit more -// complicated ... -// - +/* + * Release a lump back to the cache, so that it can be reused later + * without having to read from disk again, or alternatively, discarded + * if we run out of memory. + * + * Back in Vanilla Doom, this was just done using Z_ChangeTag + * directly, but now that we have WAD mmap, things are a bit more + * complicated. + */ void W_ReleaseLumpNum(lumpindex_t lumpnum) { - if ((unsigned)lumpnum >= numlumps) { - I_Error ("W_ReleaseLumpNum: %i >= numlumps", lumpnum); + I_Error("W_ReleaseLumpNum: %i >= numlumps", lumpnum); } - /* NRFD-EXCLUDE - - lumpinfo_t *lump; - lump = &lumpinfo[lumpnum]; - - if (lump->wad_file->mapped != NULL) - { - // Memory-mapped file, so nothing needs to be done here. - } - else - { - Z_ChangeTag(lump->cache, PU_CACHE); - } - */ + /* + * // NRFD-EXCLUDE + * lumpinfo_t *lump; + * lump = &lumpinfo[lumpnum]; + * + * if (lump->wad_file->mapped != NULL) + * { + * // Memory-mapped file, so nothing needs to be done here + * } + * else + * { + * Z_ChangeTag(lump->cache, PU_CACHE); + * } + */ } void W_ReleaseLumpName(char *name) @@ -712,26 +757,22 @@ void W_ReleaseLumpName(char *name) W_ReleaseLumpNum(W_GetNumForName(name)); } +/* TODO */ #if 0 +int info[2500][10]; +int profilecount; -// -// W_Profile -// -int info[2500][10]; -int profilecount; - -void W_Profile (void) +void W_Profile(void) { - int i; - memblock_t* block; - void* ptr; - char ch; - FILE* f; - int j; - char name[9]; - - - for (i=0 ; itag < PU_PURGELEVEL) ch = 'S'; else @@ -751,141 +792,142 @@ void W_Profile (void) } profilecount++; - f = fopen ("waddump.txt","w"); + f = fopen("waddump.txt", "w"); name[8] = 0; - for (i=0 ; i 0) - { - lumphash = Z_Malloc(sizeof(lumpindex_t) * numlumps, PU_STATIC, NULL); - - for (i = 0; i < numlumps; ++i) - { - lumphash[i] = -1; - } - - for (i = 0; i < numlumps; ++i) - { - unsigned int hash; - - hash = W_LumpNameHash(lumpinfo[i]->name) % numlumps; - - // Hook into the hash table - - lumpinfo[i]->next = lumphash[hash]; - lumphash[hash] = i; - } - } - */ - - // All done! + * // NRFD-TODO + * lumpindex_t i; + * + * // Free the old hash table, if there is one + * if (lumphash != NULL) + * { + * Z_Free(lumphash); + * } + * + * // Generate hash table + * if (numlumps > 0) + * { + * lumphash = Z_Malloc(sizeof(lumpindex_t) * numlumps, PU_STATIC, NULL); + * + * for (i = 0; i < numlumps; ++i) + * { + * lumphash[i] = -1; + * } + * + * for (i = 0; i < numlumps; ++i) + * { + * unsigned int hash; + * + * hash = W_LumpNameHash(lumpinfo[i]->name) % numlumps; + * + * // Hook into the hash table + * lumpinfo[i]->next = lumphash[hash]; + * lumphash[hash] = i; + * } + * } + */ } -// The Doom reload hack. The idea here is that if you give a WAD file to -file -// prefixed with the ~ hack, that WAD file will be reloaded each time a new -// level is loaded. This lets you use a level editor in parallel and make -// incremental changes to the level you're working on without having to restart -// the game after every change. -// But: the reload feature is a fragile hack... +/* + * The Doom reload hack. The idea here is that if you give a WAD file to -file + * prefixed with the ~ hack, that WAD file will be reloaded each time a new + * level is loaded. This lets you use a level editor in parallel and make + * incremental changes to the level you're working on without having to restart + * the game after every change. + * + * But the reload feature is a fragile hack... + */ void W_Reload(void) { - /* NRFD-EXCLUDE - char *filename; - lumpindex_t i; - - if (reloadname == NULL) - { - return; - } - - // We must free any lumps being cached from the PWAD we're about to reload: - for (i = reloadlump; i < numlumps; ++i) - { - if (lumpinfo[i]->cache != NULL) - { - Z_Free(lumpinfo[i]->cache); - } - } - - // Reset numlumps to remove the reload WAD file: - numlumps = reloadlump; - - // Now reload the WAD file. - filename = reloadname; - - W_CloseFile(reloadhandle); - free(reloadlumps); - - reloadname = NULL; - reloadlump = -1; - reloadhandle = NULL; - W_AddFile(filename); - free(filename); - - // The WAD directory has changed, so we have to regenerate the - // fast lookup hashtable: - W_GenerateHashTable(); - */ + /* + * // NRFD-EXCLUDE + * char *filename; + * lumpindex_t i; + * + * if (reloadname == NULL) + * { + * return; + * } + * + * // We must free any lumps being cached from the PWAD we're about to reload + * for (i = reloadlump; i < numlumps; ++i) + * { + * if (lumpinfo[i]->cache != NULL) + * { + * Z_Free(lumpinfo[i]->cache); + * } + * } + * + * // Reset numlumps to remove the reload WAD file + * numlumps = reloadlump; + * + * // Now reload the WAD file + * filename = reloadname; + * + * W_CloseFile(reloadhandle); + * free(reloadlumps); + * + * reloadname = NULL; + * reloadlump = -1; + * reloadhandle = NULL; + * W_AddFile(filename); + * free(filename); + * + * // The WAD directory has changed, so we have to regenerate the + * // fast lookup hashtable: + * W_GenerateHashTable(); + */ } /* -void W_DebugLump(int lump) -{ - return; - if (lump != 561) return; - - filelump_t *filelump = &filelumps[lump]; - - printf("W_DebugLump: %d size: %d\n", lump, filelump->size); - - byte *cache = N_malloc(filelump->size); - - // N_fs_read(wad_file, filelump->filepos, cache, filelump->size); - byte *qspi_data = W_LumpDataPointer(lump); - for (int i=0;isize;i++) { - cache[i] = qspi_data[i]; - } - - debugLumpNums[debugLumpCount] = lump; - debugLumpCache[debugLumpCount] = cache; - debugLumpCount++; -} -*/ + * // TODO + * void W_DebugLump(int lump) + * { + * return; + * if (lump != 561) + * return; + * + * filelump_t *filelump = &filelumps[lump]; + * + * printf("W_DebugLump: %d size: %d\n", lump, filelump->size); + * + * byte *cache = N_malloc(filelump->size); + * + * // N_fs_read(wad_file, filelump->filepos, cache, filelump->size); + * byte *qspi_data = W_LumpDataPointer(lump); + * for (int i = 0; i < filelump->size; i++) + * { + * cache[i] = qspi_data[i]; + * } + * + * debugLumpNums[debugLumpCount] = lump; + * debugLumpCache[debugLumpCount] = cache; + * debugLumpCount++; + * } + */ diff --git a/zephyrdoom/src/w_wad.h b/zephyrdoom/src/w_wad.h index ca399fb..bb7442e 100644 --- a/zephyrdoom/src/w_wad.h +++ b/zephyrdoom/src/w_wad.h @@ -1,21 +1,20 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// WAD I/O functions. -// - +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * WAD I/O functions. + */ #ifndef __W_WAD__ #define __W_WAD__ @@ -25,31 +24,33 @@ #include "doomtype.h" #include "w_file.h" - -// -// TYPES -// - -// -// WADFILE I/O related stuff. -// - +/* + * Types. + * WADFILE I/O related stuff. + */ typedef struct lumpinfo_s lumpinfo_t; typedef int lumpindex_t; struct __attribute__((packed)) lumpinfo_s { - char name[8]; - // wad_file_t *wad_file; // NRFD - // int position; - int size; - void *cache; - - // Used for hash table lookups - // lumpindex_t next; + char name[8]; + + /* + * // NRFD-TODO + * wad_file_t *wad_file; + * int position; + */ + + int size; + void *cache; + + /* + * TODO + * // Used for hash table lookups + * lumpindex_t next; + */ }; - extern lumpinfo_t lumpinfo[]; extern unsigned short numlumps; @@ -75,4 +76,4 @@ void W_ReleaseLumpName(char *name); void W_DebugLump(int num); -#endif +#endif /* __W_WAD__ */ diff --git a/zephyrdoom/src/z_native.c b/zephyrdoom/src/z_native.c index a72e186..df5e9b0 100644 --- a/zephyrdoom/src/z_native.c +++ b/zephyrdoom/src/z_native.c @@ -1,24 +1,22 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Zone Memory Allocation. Neat. -// -// This is an implementation of the zone memory API which -// uses native calls to malloc() and free(). -// - +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Zone Memory Allocation. Neat. + * This is an implementation of the zone memory API which + * uses native calls to malloc() and free(). + */ #include #include @@ -29,13 +27,13 @@ #include "n_mem.h" -#define ZONEID 0x1d4a11 +#define ZONEID 0x1d4a11 typedef struct memblock_s memblock_t; struct memblock_s { - int id; // = ZONEID + int id; /* ZONEID */ int tag; int size; void **user; @@ -43,12 +41,10 @@ struct memblock_s memblock_t *next; }; -// Linked list of allocated blocks for each tag type - +/* Linked list of allocated blocks for each tag type. */ static memblock_t *allocated_blocks[PU_NUM_TAGS]; #ifdef TESTING - static int test_malloced = 0; void *test_malloc(size_t size) @@ -73,7 +69,7 @@ void test_free(void *data) { int *i; - i = ((int *) data) - 1; + i = ((int *)data) - 1; test_malloced -= *i; @@ -82,12 +78,9 @@ void test_free(void *data) #define malloc test_malloc #define free test_free +#endif /* TESTING */ -#endif /* #ifdef TESTING */ - - -// Add a block into the linked list for its type. - +/* Add a block into the linked list for its type. */ static void Z_InsertBlock(memblock_t *block) { block->prev = NULL; @@ -100,16 +93,13 @@ static void Z_InsertBlock(memblock_t *block) } } -// Remove a block from its linked list. - +/* Remove a block from its linked list. */ static void Z_RemoveBlock(memblock_t *block) { - // Unlink from list - + /* Unlink from list */ if (block->prev == NULL) { - // Start of list - + /* Start of list */ allocated_blocks[block->tag] = block->next; } else @@ -123,50 +113,41 @@ static void Z_RemoveBlock(memblock_t *block) } } -// -// Z_Init -// -void Z_Init (void) +void Z_Init(void) { memset(allocated_blocks, 0, sizeof(allocated_blocks)); printf("zone memory: Using native C allocator.\n"); } - -// -// Z_Free -// -void Z_Free (void* ptr) +void Z_Free(void *ptr) { - // printf("Z_Free\n"); - memblock_t* block; + memblock_t *block; - block = (memblock_t *) ((byte *)ptr - sizeof(memblock_t)); + block = (memblock_t *)((byte *)ptr - sizeof(memblock_t)); if (block->id != ZONEID) { - I_Error ("Z_Free: freed a pointer without ZONEID"); + I_Error("Z_Free: freed a pointer without ZONEID"); } if (block->tag != PU_FREE && block->user != NULL) { - // clear the user's mark - + /* Clear the user's mark */ *block->user = NULL; } Z_RemoveBlock(block); - // Free back to system - + /* Free back to system */ free(block); } -// Empty data from the cache list to allocate enough data of the size -// required. -// -// Returns true if any blocks were freed. - +/* + * Empty data from the cache list to allocate enough data of the size + * required. + * + * Returns true if any blocks were freed. + */ static boolean ClearCache(int size) { memblock_t *block; @@ -179,33 +160,31 @@ static boolean ClearCache(int size) if (block == NULL) { - // Cache is already empty. - + /* Cache is already empty */ return false; } - // Search to the end of the PU_CACHE list. The blocks at the end - // of the list are the ones that have been free for longer and - // are more likely to be unneeded now. - + /* + * Search to the end of the PU_CACHE list. The blocks at the end + * of the list are the ones that have been free for longer and + * are more likely to be unneeded now. + */ while (block->next != NULL) { block = block->next; } - //printf("out of memory; cleaning out the cache: %i\n", test_malloced); - - // Search backwards through the list freeing blocks until we have - // freed the amount of memory required. - + /* + * Search backwards through the list freeing blocks until we have + * freed the amount of memory required. + */ remaining = size; while (remaining > 0) { if (block == NULL) { - // No blocks left to free; we've done our best. - + /* No blocks left to free, we've done our best */ break; } @@ -228,11 +207,7 @@ static boolean ClearCache(int size) return true; } -// -// Z_Malloc -// You can pass a NULL user if the tag is < PU_PURGELEVEL. -// - +/* You can pass a NULL user if the tag is < PU_PURGELEVEL. */ void *Z_Malloc(int size, int tag, void *user) { memblock_t *newblock; @@ -242,21 +217,21 @@ void *Z_Malloc(int size, int tag, void *user) if (tag < 0 || tag >= PU_NUM_TAGS || tag == PU_FREE) { I_Error("Z_Malloc: attempted to allocate a block with an invalid " - "tag: %i", tag); + "tag: %i", + tag); } if (user == NULL && tag >= PU_PURGELEVEL) { - I_Error ("Z_Malloc: an owner is required for purgable blocks"); + I_Error("Z_Malloc: an owner is required for purgable blocks"); } - // Malloc a block of the required size - + /* Malloc a block of the required size */ newblock = NULL; while (newblock == NULL) { - newblock = (memblock_t *) N_malloc(sizeof(memblock_t) + size); + newblock = (memblock_t *)N_malloc(sizeof(memblock_t) + size); if (newblock == NULL) { @@ -269,15 +244,14 @@ void *Z_Malloc(int size, int tag, void *user) newblock->tag = tag; - // Hook into the linked list for this tag type - + /* Hook into the linked list for this tag type */ newblock->id = ZONEID; newblock->user = user; newblock->size = size; Z_InsertBlock(newblock); - data = (unsigned char *) newblock; + data = (unsigned char *)newblock; result = data + sizeof(memblock_t); if (user != NULL) @@ -288,29 +262,21 @@ void *Z_Malloc(int size, int tag, void *user) return result; } - - -// -// Z_FreeTags -// - void Z_FreeTags(int lowtag, int hightag) { int i; - for (i=lowtag; i<= hightag; ++i) + for (i = lowtag; i <= hightag; ++i) { memblock_t *block; memblock_t *next; - // Free all in this chain - - for (block=allocated_blocks[i]; block != NULL; ) + /* Free all in this chain */ + for (block = allocated_blocks[i]; block != NULL;) { next = block->next; - // Free this block - + /* Free this block */ if (block->user != NULL) { *block->user = NULL; @@ -318,55 +284,38 @@ void Z_FreeTags(int lowtag, int hightag) free(block); - // Jump to the next in the chain - + /* Jump to the next in the chain */ block = next; } - // This chain is empty now - - allocated_blocks[i] = NULL; + /* This chain is empty now */ + allocated_blocks[i] = NULL; } } - - -// -// Z_DumpHeap -// void Z_DumpHeap(int lowtag, int hightag) { - // NRFD-EXCLUDE + /* NRFD-EXCLUDE */ } - -// -// Z_FileDumpHeap -// void Z_FileDumpHeap(FILE *f) { - // NRFD-EXCLUDE + /* NRFD-EXCLUDE */ } - - -// -// Z_CheckHeap -// -void Z_CheckHeap (void) +void Z_CheckHeap(void) { printf("Z_CheckHeap\n"); memblock_t *block; memblock_t *prev; int i; - // Check all chains - - for (i=0; inext) + for (block = allocated_blocks[i]; block != NULL; block = block->next) { if (block->id != ZONEID) { @@ -383,18 +332,11 @@ void Z_CheckHeap (void) } } - - - -// -// Z_ChangeTag -// - void Z_ChangeTag2(void *ptr, int tag, char *file, int line) { - memblock_t* block; + memblock_t *block; - block = (memblock_t *) ((byte *)ptr - sizeof(memblock_t)); + block = (memblock_t *)((byte *)ptr - sizeof(memblock_t)); if (block->id != ZONEID) I_Error("%s:%i: Z_ChangeTag: block without a ZONEID!", @@ -402,11 +344,13 @@ void Z_ChangeTag2(void *ptr, int tag, char *file, int line) if (tag >= PU_PURGELEVEL && block->user == NULL) I_Error("%s:%i: Z_ChangeTag: an owner is required " - "for purgable blocks", file, line); - - // Remove the block from its current list, and rehook it into - // its new list. + "for purgable blocks", + file, line); + /* + * Remove the block from its current list, and rehook it into + * its new list. + */ Z_RemoveBlock(block); block->tag = tag; Z_InsertBlock(block); @@ -414,9 +358,9 @@ void Z_ChangeTag2(void *ptr, int tag, char *file, int line) void Z_ChangeUser(void *ptr, void **user) { - memblock_t* block; + memblock_t *block; - block = (memblock_t *) ((byte *)ptr - sizeof(memblock_t)); + block = (memblock_t *)((byte *)ptr - sizeof(memblock_t)); if (block->id != ZONEID) { @@ -427,15 +371,9 @@ void Z_ChangeUser(void *ptr, void **user) *user = ptr; } - -// -// Z_FreeMemory -// - int Z_FreeMemory(void) { - // Limited by the system?? - + /* Limited by the system */ return -1; } diff --git a/zephyrdoom/src/z_zone.c b/zephyrdoom/src/z_zone.c index 0b8bbdf..6e17b42 100644 --- a/zephyrdoom/src/z_zone.c +++ b/zephyrdoom/src/z_zone.c @@ -1,20 +1,20 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Zone Memory Allocation. Neat. -// +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Zone Memory Allocation. Neat. + */ #include @@ -24,62 +24,50 @@ #include "z_zone.h" - -// -// ZONE MEMORY ALLOCATION -// -// There is never any space between memblocks, -// and there will never be two contiguous free memblocks. -// The rover can be left pointing at a non-empty block. -// -// It is of no value to free a cachable block, -// because it will get overwritten automatically if needed. -// - +/* + * Zone memory allocation + * + * There is never any space between memblocks, + * and there will never be two contiguous free memblocks. + * The rover can be left pointing at a non-empty block. + * + * It is of no value to free a cachable block, + * because it will get overwritten automatically if needed. + */ #define MEM_ALIGN sizeof(void *) -#define ZONEID 0x1d4a11 +#define ZONEID 0x1d4a11 typedef struct memblock_s { - int size; // including the header and possibly tiny fragments - void** user; - int tag; // PU_FREE if this is free - int id; // should be ZONEID - struct memblock_s* next; - struct memblock_s* prev; + int size; /* Including the header and possibly tiny fragments */ + void **user; + int tag; /* PU_FREE if this is free */ + int id; /* Should be ZONEID */ + struct memblock_s *next; + struct memblock_s *prev; } memblock_t; - typedef struct { - // total bytes malloced, including header - int size; - - // start / end cap for linked list - memblock_t blocklist; + /* Total bytes malloced, including header */ + int size; - memblock_t* rover; + /* Start/End cap for linked list */ + memblock_t blocklist; + memblock_t *rover; } memzone_t; - - static memzone_t *mainzone; static boolean zero_on_free; static boolean scan_on_free; - -// -// Z_ClearZone -// -void Z_ClearZone (memzone_t* zone) +void Z_ClearZone(memzone_t *zone) { - memblock_t* block; + memblock_t *block; - // set the entire zone to one free block - zone->blocklist.next = - zone->blocklist.prev = - block = (memblock_t *)( (byte *)zone + sizeof(memzone_t) ); + /* Set the entire zone to one free block */ + zone->blocklist.next = zone->blocklist.prev = block = (memblock_t *)((byte *)zone + sizeof(memzone_t)); zone->blocklist.user = (void *)zone; zone->blocklist.tag = PU_STATIC; @@ -87,29 +75,22 @@ void Z_ClearZone (memzone_t* zone) block->prev = block->next = &zone->blocklist; - // a free block. + /* A free block */ block->tag = PU_FREE; block->size = zone->size - sizeof(memzone_t); } - - -// -// Z_Init -// -void Z_Init (void) +void Z_Init(void) { - memblock_t* block; - int size; + memblock_t *block; + int size; - mainzone = (memzone_t *)I_ZoneBase (&size); + mainzone = (memzone_t *)I_ZoneBase(&size); mainzone->size = size; - // set the entire zone to one free block - mainzone->blocklist.next = - mainzone->blocklist.prev = - block = (memblock_t *)( (byte *)mainzone + sizeof(memzone_t) ); + /* Set the entire zone to one free block */ + mainzone->blocklist.next = mainzone->blocklist.prev = block = (memblock_t *)((byte *)mainzone + sizeof(memzone_t)); mainzone->blocklist.user = (void *)mainzone; mainzone->blocklist.tag = PU_STATIC; @@ -117,26 +98,30 @@ void Z_Init (void) block->prev = block->next = &mainzone->blocklist; - // free block + /* Free block */ block->tag = PU_FREE; block->size = mainzone->size - sizeof(memzone_t); - // [Deliberately undocumented] - // Zone memory debugging flag. If set, memory is zeroed after it is freed - // to deliberately break any code that attempts to use it after free. - // + /* + * [Deliberately undocumented] + * Zone memory debugging flag. If set, memory is zeroed after it is freed + * to deliberately break any code that attempts to use it after free. + */ zero_on_free = M_ParmExists("-zonezero"); - // [Deliberately undocumented] - // Zone memory debugging flag. If set, each time memory is freed, the zone - // heap is scanned to look for remaining pointers to the freed block. - // + /* + * [Deliberately undocumented] + * Zone memory debugging flag. If set, each time memory is freed, the zone + * heap is scanned to look for remaining pointers to the freed block. + */ scan_on_free = M_ParmExists("-zonescan"); } -// Scan the zone heap for pointers within the specified range, and warn about -// any remaining pointers. +/* + * Scan the zone heap for pointers within the specified range, and warn about + * any remaining pointers. + */ static void ScanForBlock(void *start, void *end) { memblock_t *block; @@ -151,9 +136,11 @@ static void ScanForBlock(void *start, void *end) if (tag == PU_STATIC || tag == PU_LEVEL || tag == PU_LEVSPEC) { - // Scan for pointers on the assumption that pointers are aligned - // on word boundaries (word size depending on pointer size): - mem = (void **) ((byte *) block + sizeof(memblock_t)); + /* + * Scan for pointers on the assumption that pointers are aligned + * on word boundaries (word size depending on pointer size). + */ + mem = (void **)((byte *)block + sizeof(memblock_t)); len = (block->size - sizeof(memblock_t)) / sizeof(void *); for (i = 0; i < len; ++i) @@ -172,47 +159,45 @@ static void ScanForBlock(void *start, void *end) } } -// -// Z_Free -// -void Z_Free (void* ptr) +void Z_Free(void *ptr) { - memblock_t* block; - memblock_t* other; + memblock_t *block; + memblock_t *other; - block = (memblock_t *) ( (byte *)ptr - sizeof(memblock_t)); + block = (memblock_t *)((byte *)ptr - sizeof(memblock_t)); if (block->id != ZONEID) - I_Error ("Z_Free: freed a pointer without ZONEID"); + I_Error("Z_Free: freed a pointer without ZONEID"); if (block->tag != PU_FREE && block->user != NULL) { - // clear the user's mark + /* Clear the user's mark */ *block->user = 0; } - // mark as free + /* Mark as free */ block->tag = PU_FREE; block->user = NULL; block->id = 0; - // If the -zonezero flag is provided, we zero out the block on free - // to break code that depends on reading freed memory. + /* + * If the -zonezero flag is provided, we zero out the block on free + * to break code that depends on reading freed memory. + */ if (zero_on_free) { memset(ptr, 0, block->size - sizeof(memblock_t)); } if (scan_on_free) { - ScanForBlock(ptr, - (byte *) ptr + block->size - sizeof(memblock_t)); + ScanForBlock(ptr, (byte *)ptr + block->size - sizeof(memblock_t)); } other = block->prev; if (other->tag == PU_FREE) { - // merge with previous free block + /* Merge with previous free block */ other->size += block->size; other->next = block->next; other->next->prev = other; @@ -226,7 +211,7 @@ void Z_Free (void* ptr) other = block->next; if (other->tag == PU_FREE) { - // merge the next free block onto the end + /* Merge the next free block onto the end */ block->size += other->size; block->next = other->next; block->next->prev = block; @@ -236,40 +221,28 @@ void Z_Free (void* ptr) } } +/* You can pass a NULL user if the tag is < PU_PURGELEVEL. */ +#define MINFRAGMENT 64 - -// -// Z_Malloc -// You can pass a NULL user if the tag is < PU_PURGELEVEL. -// -#define MINFRAGMENT 64 - - -void* -Z_Malloc -( int size, - int tag, - void* user ) +void *Z_Malloc(int size, int tag, void *user) { - int extra; - memblock_t* start; - memblock_t* rover; - memblock_t* newblock; - memblock_t* base; + int extra; + memblock_t *start; + memblock_t *rover; + memblock_t *newblock; + memblock_t *base; void *result; size = (size + MEM_ALIGN - 1) & ~(MEM_ALIGN - 1); - // scan through the block list, - // looking for the first free block - // of sufficient size, - // throwing out any purgable blocks along the way. - - // account for size of block header + /* + * Scan through the block list, looking for the first free block + * of sufficient size, throwing out any purgable blocks along the way. + * Account for size of block header. + */ size += sizeof(memblock_t); - // if there is a free block behind the rover, - // back up over them + /* If there is a free block behind the rover, back up over them. */ base = mainzone->rover; if (base->prev->tag == PU_FREE) @@ -282,25 +255,25 @@ Z_Malloc { if (rover == start) { - // scanned all the way around the list - I_Error ("Z_Malloc: failed on allocation of %i bytes", size); + /* Scanned all the way around the list */ + I_Error("Z_Malloc: failed on allocation of %i bytes", size); } if (rover->tag != PU_FREE) { if (rover->tag < PU_PURGELEVEL) { - // hit a block that can't be purged, - // so move base past it + /* Hit a block that can't be purged, so move base past it */ base = rover = rover->next; } else { - // free the rover block (adding the size to base) - - // the rover can be the base block + /* + * Free the rover block (adding the size to base). + * The rover can be the base block. + */ base = base->prev; - Z_Free ((byte *)rover+sizeof(memblock_t)); + Z_Free((byte *)rover + sizeof(memblock_t)); base = base->next; rover = base->next; } @@ -312,14 +285,13 @@ Z_Malloc } while (base->tag != PU_FREE || base->size < size); - - // found a block big enough + /* Found a block big enough */ extra = base->size - size; - if (extra > MINFRAGMENT) + if (extra > MINFRAGMENT) { - // there will be a free fragment after the allocated block - newblock = (memblock_t *) ((byte *)base + size ); + /* There will be a free fragment after the allocated block */ + newblock = (memblock_t *)((byte *)base + size); newblock->size = extra; newblock->tag = PU_FREE; @@ -333,19 +305,19 @@ Z_Malloc } if (user == NULL && tag >= PU_PURGELEVEL) - I_Error ("Z_Malloc: an owner is required for purgable blocks"); + I_Error("Z_Malloc: an owner is required for purgable blocks"); base->user = user; base->tag = tag; - result = (void *) ((byte *)base + sizeof(memblock_t)); + result = (void *)((byte *)base + sizeof(memblock_t)); if (base->user) { *base->user = result; } - // next allocation will start looking here + /* Next allocation will start looking here */ mainzone->rover = base->next; base->id = ZONEID; @@ -353,148 +325,119 @@ Z_Malloc return result; } - - -// -// Z_FreeTags -// -void -Z_FreeTags -( int lowtag, - int hightag ) +void Z_FreeTags(int lowtag, + int hightag) { - memblock_t* block; - memblock_t* next; + memblock_t *block; + memblock_t *next; - for (block = mainzone->blocklist.next ; - block != &mainzone->blocklist ; - block = next) + for (block = mainzone->blocklist.next; + block != &mainzone->blocklist; + block = next) { - // get link before freeing - next = block->next; + /* Get link before freeing */ + next = block->next; - // free block? - if (block->tag == PU_FREE) - continue; + /* Free block */ + if (block->tag == PU_FREE) + continue; - if (block->tag >= lowtag && block->tag <= hightag) - Z_Free ( (byte *)block+sizeof(memblock_t)); + if (block->tag >= lowtag && block->tag <= hightag) + Z_Free((byte *)block + sizeof(memblock_t)); } } - - -// -// Z_DumpHeap -// Note: TFileDumpHeap( stdout ) ? -// -void -Z_DumpHeap -( int lowtag, - int hightag ) +/* Note - TFileDumpHeap(stdout) */ +void Z_DumpHeap(int lowtag, + int hightag) { - memblock_t* block; + memblock_t *block; - printf ("zone size: %i location: %p\n", - mainzone->size,mainzone); + printf("zone size: %i location: %p\n", + mainzone->size, mainzone); - printf ("tag range: %i to %i\n", - lowtag, hightag); + printf("tag range: %i to %i\n", + lowtag, hightag); - for (block = mainzone->blocklist.next ; ; block = block->next) + for (block = mainzone->blocklist.next;; block = block->next) { - if (block->tag >= lowtag && block->tag <= hightag) - printf ("block:%p size:%7i user:%p tag:%3i\n", - block, block->size, block->user, block->tag); + if (block->tag >= lowtag && block->tag <= hightag) + printf("block:%p size:%7i user:%p tag:%3i\n", + block, block->size, block->user, block->tag); - if (block->next == &mainzone->blocklist) - { - // all blocks have been hit - break; - } + if (block->next == &mainzone->blocklist) + { + /* All blocks have been hit */ + break; + } - if ( (byte *)block + block->size != (byte *)block->next) - printf ("ERROR: block size does not touch the next block\n"); + if ((byte *)block + block->size != (byte *)block->next) + printf("ERROR: block size does not touch the next block\n"); - if ( block->next->prev != block) - printf ("ERROR: next block doesn't have proper back link\n"); + if (block->next->prev != block) + printf("ERROR: next block doesn't have proper back link\n"); - if (block->tag == PU_FREE && block->next->tag == PU_FREE) - printf ("ERROR: two consecutive free blocks\n"); + if (block->tag == PU_FREE && block->next->tag == PU_FREE) + printf("ERROR: two consecutive free blocks\n"); } } - -// -// Z_FileDumpHeap -// -void Z_FileDumpHeap (FILE* f) +void Z_FileDumpHeap(FILE *f) { - memblock_t* block; + memblock_t *block; - fprintf (f,"zone size: %i location: %p\n",mainzone->size,mainzone); + fprintf(f, "zone size: %i location: %p\n", mainzone->size, mainzone); - for (block = mainzone->blocklist.next ; ; block = block->next) + for (block = mainzone->blocklist.next;; block = block->next) { - fprintf (f,"block:%p size:%7i user:%p tag:%3i\n", - block, block->size, block->user, block->tag); + fprintf(f, "block:%p size:%7i user:%p tag:%3i\n", + block, block->size, block->user, block->tag); - if (block->next == &mainzone->blocklist) - { - // all blocks have been hit - break; - } + if (block->next == &mainzone->blocklist) + { + /* All blocks have been hit */ + break; + } - if ( (byte *)block + block->size != (byte *)block->next) - fprintf (f,"ERROR: block size does not touch the next block\n"); + if ((byte *)block + block->size != (byte *)block->next) + fprintf(f, "ERROR: block size does not touch the next block\n"); - if ( block->next->prev != block) - fprintf (f,"ERROR: next block doesn't have proper back link\n"); + if (block->next->prev != block) + fprintf(f, "ERROR: next block doesn't have proper back link\n"); - if (block->tag == PU_FREE && block->next->tag == PU_FREE) - fprintf (f,"ERROR: two consecutive free blocks\n"); + if (block->tag == PU_FREE && block->next->tag == PU_FREE) + fprintf(f, "ERROR: two consecutive free blocks\n"); } } - - -// -// Z_CheckHeap -// -void Z_CheckHeap (void) +void Z_CheckHeap(void) { - memblock_t* block; + memblock_t *block; - for (block = mainzone->blocklist.next ; ; block = block->next) - { - if (block->next == &mainzone->blocklist) + for (block = mainzone->blocklist.next;; block = block->next) { - // all blocks have been hit - break; - } + if (block->next == &mainzone->blocklist) + { + /* All blocks have been hit */ + break; + } - if ( (byte *)block + block->size != (byte *)block->next) - I_Error ("Z_CheckHeap: block size does not touch the next block\n"); + if ((byte *)block + block->size != (byte *)block->next) + I_Error("Z_CheckHeap: block size does not touch the next block\n"); - if ( block->next->prev != block) - I_Error ("Z_CheckHeap: next block doesn't have proper back link\n"); + if (block->next->prev != block) + I_Error("Z_CheckHeap: next block doesn't have proper back link\n"); - if (block->tag == PU_FREE && block->next->tag == PU_FREE) - I_Error ("Z_CheckHeap: two consecutive free blocks\n"); + if (block->tag == PU_FREE && block->next->tag == PU_FREE) + I_Error("Z_CheckHeap: two consecutive free blocks\n"); } } - - - -// -// Z_ChangeTag -// void Z_ChangeTag2(void *ptr, int tag, char *file, int line) { - memblock_t* block; + memblock_t *block; - block = (memblock_t *) ((byte *)ptr - sizeof(memblock_t)); + block = (memblock_t *)((byte *)ptr - sizeof(memblock_t)); if (block->id != ZONEID) I_Error("%s:%i: Z_ChangeTag: block without a ZONEID!", @@ -502,16 +445,17 @@ void Z_ChangeTag2(void *ptr, int tag, char *file, int line) if (tag >= PU_PURGELEVEL && block->user == NULL) I_Error("%s:%i: Z_ChangeTag: an owner is required " - "for purgable blocks", file, line); + "for purgable blocks", + file, line); block->tag = tag; } void Z_ChangeUser(void *ptr, void **user) { - memblock_t* block; + memblock_t *block; - block = (memblock_t *) ((byte *)ptr - sizeof(memblock_t)); + block = (memblock_t *)((byte *)ptr - sizeof(memblock_t)); if (block->id != ZONEID) { @@ -522,19 +466,14 @@ void Z_ChangeUser(void *ptr, void **user) *user = ptr; } - - -// -// Z_FreeMemory -// -int Z_FreeMemory (void) +int Z_FreeMemory(void) { - memblock_t* block; - int free; + memblock_t *block; + int free; free = 0; - for (block = mainzone->blocklist.next ; + for (block = mainzone->blocklist.next; block != &mainzone->blocklist; block = block->next) { diff --git a/zephyrdoom/src/z_zone.h b/zephyrdoom/src/z_zone.h index 8f4c3ec..da732f3 100644 --- a/zephyrdoom/src/z_zone.h +++ b/zephyrdoom/src/z_zone.h @@ -1,73 +1,66 @@ -// -// Copyright(C) 1993-1996 Id Software, Inc. -// Copyright(C) 2005-2014 Simon Howard -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// DESCRIPTION: -// Zone Memory Allocation, perhaps NeXT ObjectiveC inspired. -// Remark: this was the only stuff that, according -// to John Carmack, might have been useful for -// Quake. -// - - +/* + * Copyright(C) 1993-1996 Id Software, Inc. + * Copyright(C) 2005-2014 Simon Howard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION: + * Zone Memory Allocation, perhaps NeXT ObjectiveC inspired. + * Remark - this was the only stuff that, according + * to John Carmack, might have been useful for Quake. + */ #ifndef __Z_ZONE__ #define __Z_ZONE__ #include -// -// ZONE MEMORY -// PU - purge tags. - +/* + * Zone memory. + * PU - purge tags. + */ enum { - PU_STATIC = 1, // static entire execution time - PU_SOUND, // static while playing - PU_MUSIC, // static while playing - PU_FREE, // a free block - PU_LEVEL, // static until level exited - PU_LEVSPEC, // a special thinker in a level - - // Tags >= PU_PURGELEVEL are purgable whenever needed. + PU_STATIC = 1, /* Static entire execution time */ + PU_SOUND, /* Static while playing */ + PU_MUSIC, /* Static while playing */ + PU_FREE, /* A free block */ + PU_LEVEL, /* Static until level exited */ + PU_LEVSPEC, /* A special thinker in a level */ + /* Tags >= PU_PURGELEVEL are purgable whenever needed */ PU_PURGELEVEL, PU_CACHE, - // Total number of different tag types - + /* Total number of different tag types */ PU_NUM_TAGS }; - -void Z_Init (void); -void* Z_Malloc (int size, int tag, void *ptr); -void Z_Free (void *ptr); -void Z_FreeTags (int lowtag, int hightag); -void Z_DumpHeap (int lowtag, int hightag); -void Z_FileDumpHeap (FILE *f); -void Z_CheckHeap (void); -void Z_ChangeTag2 (void *ptr, int tag, char *file, int line); -void Z_ChangeUser(void *ptr, void **user); -int Z_FreeMemory (void); +void Z_Init(void); +void *Z_Malloc(int size, int tag, void *ptr); +void Z_Free(void *ptr); +void Z_FreeTags(int lowtag, int hightag); +void Z_DumpHeap(int lowtag, int hightag); +void Z_FileDumpHeap(FILE *f); +void Z_CheckHeap(void); +void Z_ChangeTag2(void *ptr, int tag, char *file, int line); +void Z_ChangeUser(void *ptr, void **user); +int Z_FreeMemory(void); unsigned int Z_ZoneSize(void); -// -// This is used to get the local FILE:LINE info from CPP -// prior to really call the function in question. -// -#define Z_ChangeTag(p,t) \ +/* + * This is used to get the local FILE:LINE info from CPP + * prior to really call the function in question. + */ +#define Z_ChangeTag(p, t) \ Z_ChangeTag2((p), (t), __FILE__, __LINE__) - -#endif +#endif /* __Z_ZONE__ */