From 39494b5a451472db3b613446a5b1c8c2b0d92cf6 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Fri, 14 May 2010 18:42:32 +0000 Subject: Don't grab the mouse when the demo sequence advances. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1935 --- src/i_video.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/i_video.c b/src/i_video.c index 6936532d..bc3f17cf 100644 --- a/src/i_video.c +++ b/src/i_video.c @@ -85,6 +85,7 @@ static screen_mode_t *screen_modes_corrected[] = { }; extern void M_QuitDOOM(); +extern boolean advancedemo; // SDL video driver name @@ -228,7 +229,7 @@ static boolean MouseShouldBeGrabbed() // only grab mouse when playing levels (but not demos) - return (gamestate == GS_LEVEL) && !demoplayback; + return (gamestate == GS_LEVEL) && !demoplayback && !advancedemo; #endif /* #ifndef _WIN32_WCE */ } -- cgit v1.2.3 From f00575079e186bad1bbd6f4768027747db5ba748 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sun, 30 May 2010 02:56:58 +0000 Subject: Clarify/update install instructions. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1936 --- INSTALL | 159 ++++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 94 insertions(+), 65 deletions(-) diff --git a/INSTALL b/INSTALL index 80df9361..7ad85b7f 100644 --- a/INSTALL +++ b/INSTALL @@ -2,13 +2,18 @@ Chocolate Doom installation =========================== -These are instructions for how to install Chocolate Doom on Unix-like -Operating Systems. +These are instructions for how to install and set up Chocolate Doom +for play. -Dependencies ------------- +Building Chocolate Doom +----------------------- -Chocolate Doom requires the following to be installed: +Before you can play Chocolate Doom, you need to compile a binary that +you can run. If you are using Windows or Mac OS X, precompiled +binaries are available on the website for download, and you can skip +this section. + +For compilation, Chocolate Doom requires the following to be installed: * A C compiler (gcc is recommended) * make (GNU make is recommended) @@ -17,84 +22,108 @@ Chocolate Doom requires the following to be installed: * SDL_net (see http://www.libsdl.org/projects/SDL_net/) * Python (optional) -Building Chocolate Doom ------------------------ - -On a Unix system, follow the standard instructions for installing an -autotools-based package: +Follow the standard instructions for installing an autotools-based +package: 1. Run './configure' to initialize the package. 2. Run 'make' to compile the package. 3. Run 'make install' to install the package. -Advanced topics such as cross-compilation are beyond the scope of this +Advanced topics such as cross-compilation are beyond the scope of this document. Please see the GNU autoconf / automake documentation for more information. -Installing an IWAD file ------------------------ +Obtaining an IWAD file +---------------------- -To play Doom, an IWAD file is needed. This contains the Doom game data. The -file usually has one of the following filenames: +To play Doom, you need an IWAD file. This file contains the game data +that is used in gameplay (graphics, sounds, etc). The full versions of +the Doom games are proprietary and need to be bought. The IWAD file +has one of the following names: doom1.wad (Shareware Doom) doom.wad (Registered / Ultimate Doom) doom2.wad (Doom 2) tnt.wad (Final Doom: TNT: Evilution) plutonia.wad (Final Doom: Plutonia Experiment) + chex.wad (Chex Quest) -When you have this file (see the next section, "Obtaining an IWAD file", for -how to get this file), install it through one of the following methods: +If you don't have a copy of the commercial version, you can download +the shareware version (extract the file named doom1.wad): - * Put the file into the /usr/share/games/doom or - /usr/local/share/games/doom directories. - * Install it into a directory and set the environment variable DOOMWADDIR to - be the path to that directory. - * Install multiple IWADs into separate directories and set the environment - variable DOOMWADPATH to be a colon-separated list of directories to search - (similar to the Unix PATH environment variable). - * Run Chocolate Doom with the '-iwad' command line parameter to specify the - IWAD file to use, eg. + * http://www.doomworld.com/idgames/index.php?id=7053 + (idstuff/doom/win95/doom95.zip in your nearest /idgames mirror) - chocolate-doom -iwad /root/doom2.wad +If you have a commercial version, obtaining the IWAD file may slightly +complicated. The method depends on how you obtained your copy of the +game: -Obtaining an IWAD file ----------------------- + * There have been several CD-based versions of Doom. Generally, the + IWAD files can be found on the CD and copied off directly. -Obtaining the IWAD file may be a complicated process under Unix. The method -depends on how you obtained your copy of the game: + * The IWAD files might not be directly available on the CD. Look for + a program named "deice.exe". In the same directory, there should + be a single large file with a numbered extension (eg. + "resource.1"); to extract this, follow the same instructions as for + the floppy disk version (see below). - * There have been several CD-based versions of Doom. Generally, the IWAD - files can be found on the CD and copied off directly. + * If you have the floppy disk version of Doom, first copy the + contents of all the floppy disks into a directory together. You + will have several large files with numbered extensions. + Concatenate these into a single file, eg. - * The IWAD files may not be directly available on the CD. Look for a program - named "deice.exe". In the same directory, there should be a single large - file with a numbered extension (eg. "resource.1"); to extract this, follow - the same instructions as for the floppy disk version (see below). + (Unix instructions) + cat doom_se.1 doom_se.2 doom_se.3 doom_se.4 doom_se.5 > doom_se.exe - * If you have the floppy disk version of Doom, first copy the contents of all - the floppy disks into a directory together. You will have several large - files with numbered extensions. Concatenate these into a single file, eg. + (Windows/DOS instructions) + copy doom_se.1+doom_se.2+doom_se.3+doom_se.4+doom_se+5 doom_se.exe - cat doom_se.1 doom_se.2 doom_se.3 doom_se.4 doom_se.5 > doom_se.exe - - The resulting file is self-extracting LHA file. If you have a DOS emulator - (such as DOSbox), you can run it to extract the files; alternatively, you - can use the Unix LHA tool to extract the archive. + The resulting file is self-extracting LHA file. If you have a DOS + emulator (such as DOSbox), you can run it to extract the files; + alternatively, you can use the Unix LHA tool to extract the + archive. * The Doom games are also available for download on Steam - (http://www.steampowered.com/). To find the IWAD files, look in your Steam - directory, under the "steamapps/common" path. + (http://www.steampowered.com/). To find the IWAD files, look in + your Steam directory, under the "steamapps/common" path. + +Running the game +---------------- + +When you have an IWAD file, install it through one of the following +methods: + + * Under Mac OS X, you can specify the locations of the IWAD files + through the graphical launcher program. Click the "Configure..." + button, and then click "Set..." for each IWAD location to choose + its location. + + * Under Unix, put the file into the /usr/share/games/doom or + /usr/local/share/games/doom directories. + + * Place it in a directory and set the environment variable DOOMWADDIR + to be the path to that directory. + + * Install multiple IWADs into separate directories and set the + environment variable DOOMWADPATH to be a colon-separated list of + directories to search (similar to the Unix PATH environment + variable). + + * Run Chocolate Doom with the '-iwad' command line parameter to + specify the IWAD file to use, eg. + + chocolate-doom -iwad /root/doom2.wad Playing with Chex Quest ----------------------- -Chex Quest is a game based on Doom with some minor modifications that was -distributed with boxes of Chex cereal in 1997. It is possible to play -Chex Quest using Chocolate Doom. To do this, the following files are -needed: +Chex Quest is a game based on Doom with some minor modifications that +was distributed with boxes of Chex cereal in 1997. It is possible to +play Chex Quest using Chocolate Doom. To do this, the following files +are needed: * The IWAD file 'chex.wad', from the Chex Quest CD. + * The dehacked patch 'chex.deh', which can be found in the /idgames repository in utils/exe_edit/patches/chexdeh.zip. @@ -106,30 +135,30 @@ line parameter to specify the Chex Quest IWAD file: Installing upgrades ------------------- -Chocolate Doom requires a Doom 1.9 IWAD file. Generally, if you install a -recent version of Doom you should automatically have a 1.9 IWAD. However, if -you are installing from a very old CD version or from floppy disks, you might -find you have an older version. +Chocolate Doom requires a Doom 1.9 IWAD file. Generally, if you +install a recent version of Doom you should automatically have a 1.9 +IWAD. However, if you are installing from a very old CD version or +from floppy disks, you might find you have an older version. -The most obvious symptom of an out of date IWAD file is that the game will -exit at the title screen before the demo starts, with the message "Demo is -from a different game version!". If this happens, your IWAD file is out of -date and you need to upgrade. +The most obvious symptom of an out of date IWAD file is that the game +will exit at the title screen before the demo starts, with the message +"Demo is from a different game version!". If this happens, your IWAD +file is out of date and you need to upgrade. -Id Software released upgrade patches that will update your game to 1.9. The -following sites have the patches: +Id Software released upgrade patches that will update your game to +1.9. The following sites have the patches: - http://www.doomworld.com/files/patches.shtml + http://www.doomworld.com/files/patches.shtml http://www.doom2.net/doom2/utils.html ftp://ftp.idsoftware.com/idstuff/doom2 -As the patches are binary patches that run as DOS executables, you will -need a DOS emulator (such as DOSBox) to install them. +As the patches are binary patches that run as DOS executables, you +will need a DOS emulator (such as DOSBox) to install them. Music support ------------- -Support for Doom's MIDI music is available through timidity: +Support for Doom's MIDI music is available through Timidity: http://timidity.sourceforge.net/ -- cgit v1.2.3 From 373a8dd0c10c1d9f3be29cd3546819236b860ab8 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sun, 30 May 2010 03:03:44 +0000 Subject: Add INSTALL to all distribution packages, add note in README. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1937 --- README | 55 ++++++++++++++++++++++++++++++------------------------- rpm.spec.in | 5 +++-- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/README b/README index c0cf24df..0b9eaf7c 100644 --- a/README +++ b/README @@ -13,33 +13,37 @@ Chocolate Doom aims to: * As far as possible, provide all the same features that are available using the DOS version. +== Setting up gameplay == + +For instructions on how to set up Chocolate Doom for play, see the +INSTALL file. + == Configuration File == Chocolate Doom is compatible with the DOS Doom configuration file -(normally named 'default.cfg'). Existing configuration files for -DOS Doom should therefore simply work out of the box. However, -Chocolate Doom also provides some extra settings. These are stored -in a separate file named 'chocolate-doom.cfg'. +(normally named 'default.cfg'). Existing configuration files for DOS +Doom should therefore simply work out of the box. However, Chocolate +Doom also provides some extra settings. These are stored in a +separate file named 'chocolate-doom.cfg'. The configuration can be edited using the chocolate-setup tool. == Command-line options == -For a complete list of command-line options, see the CMDLINE -file. +For a complete list of command-line options, see the CMDLINE file. == Playing TCs == -With Vanilla Doom there is no way to include sprites in PWAD files. -Chocolate Doom's '-file' command line option behaves exactly the -same as Vanilla Doom, and trying to play TCs by adding the WAD files -using '-file' will not work. +With Vanilla Doom there is no way to include sprites in PWAD files. +Chocolate Doom's '-file' command line option behaves exactly the same +as Vanilla Doom, and trying to play TCs by adding the WAD files using +'-file' will not work. Many Total Conversions (TCs) are distributed as a PWAD file which must be merged into the main IWAD. Typically a copy of DEUSF.EXE is included which performs this merge. Chocolate Doom includes a new -option, '-merge', which will simulate this merge. Essentially, the -WAD directory is merged in memory, removing the need to modify the +option, '-merge', which will simulate this merge. Essentially, the +WAD directory is merged in memory, removing the need to modify the IWAD on disk. To play TCs using Chocolate Doom, run like this: @@ -53,26 +57,27 @@ Here are some examples: == Other information == - * More information, including information about how to play various classic - TCs, is available on the Chocolate Doom website: + * More information, including information about how to play various + classic TCs, is available on the Chocolate Doom website: http://www.chocolate-doom.org/ - You are encouraged to sign up and contribute any useful information you may - have regarding the port! + You are encouraged to sign up and contribute any useful information + you may have regarding the port! - * Chocolate Doom is not perfect. See the BUGS file for a list of known - issues. New bug reports can be submitted to the Chocolate Doom bug - tracker on Sourceforge. See: + * Chocolate Doom is not perfect. See the BUGS file for a list of + known issues. New bug reports can be submitted to the Chocolate + Doom bug tracker on Sourceforge. See: http://sourceforge.net/projects/chocolate-doom - * Source code patches are welcome, but please follow the style guidelines - - see the file named HACKING included with the source distribution. + * Source code patches are welcome, but please follow the style + guidelines - see the file named HACKING included with the source + distribution. - * Chocolate Doom is distributed under the GNU GPL. See the COPYING file - for more information. + * Chocolate Doom is distributed under the GNU GPL. See the COPYING + file for more information. - * Please send any feedback, questions or suggestions to fraggle@gmail.com. - Thanks! + * Please send any feedback, questions or suggestions to + fraggle@gmail.com. Thanks! diff --git a/rpm.spec.in b/rpm.spec.in index 58142c1b..b37a2876 100644 --- a/rpm.spec.in +++ b/rpm.spec.in @@ -49,10 +49,11 @@ rm -rf $RPM_BUILD_ROOT %files %doc %{_mandir}/man5/* %doc %{_mandir}/man6/* -%doc NEWS -%doc AUTHORS %doc README %doc README.OPL +%doc INSTALL +%doc NEWS +%doc AUTHORS %doc COPYING %doc CMDLINE %doc BUGS -- cgit v1.2.3 From bb3f64f28173bba0b243957c63679d2ec63dce5c Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 10 Jul 2010 15:27:52 +0000 Subject: Add key binding to change demo recording quit key. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1939 --- setup/configfile.c | 1 + setup/keyboard.c | 2 ++ setup/keyboard.h | 1 + src/g_game.c | 3 ++- src/m_config.c | 7 +++++++ 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/setup/configfile.c b/setup/configfile.c index 99ec2e03..9f0e5de5 100644 --- a/setup/configfile.c +++ b/setup/configfile.c @@ -336,6 +336,7 @@ static default_t extra_defaults_list[] = {"key_weapon7", &key_weapon7, DEFAULT_KEY, 0, 0}, {"key_weapon8", &key_weapon8, DEFAULT_KEY, 0, 0}, {"key_message_refresh", &key_message_refresh, DEFAULT_KEY, 0, 0}, + {"key_demo_quit", &key_demo_quit, DEFAULT_KEY, 0, 0}, }; static default_collection_t extra_defaults = diff --git a/setup/keyboard.c b/setup/keyboard.c index 79cb90e7..b402d10c 100644 --- a/setup/keyboard.c +++ b/setup/keyboard.c @@ -91,6 +91,7 @@ int key_weapon7 = '7'; int key_weapon8 = '8'; int key_message_refresh = KEY_ENTER; +int key_demo_quit = 'q'; int vanilla_keyboard_mapping = 1; @@ -273,6 +274,7 @@ static void OtherKeysDialog(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(unused)) AddKeyControl(table, "Decrease screen size", &key_menu_decscreen); AddKeyControl(table, "Display last message", &key_message_refresh); + AddKeyControl(table, "Finish recording demo", &key_demo_quit); TXT_AddWidgets(table, TXT_NewStrut(0, 1), TXT_NewStrut(0, 1), diff --git a/setup/keyboard.h b/setup/keyboard.h index fa3c0db3..62addc8f 100644 --- a/setup/keyboard.h +++ b/setup/keyboard.h @@ -91,6 +91,7 @@ extern int key_weapon7; extern int key_weapon8; extern int key_message_refresh; +extern int key_demo_quit; void ConfigKeyboard(void); diff --git a/src/g_game.c b/src/g_game.c index b0532f42..a9ee2641 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -184,6 +184,7 @@ int key_weapon7 = '7'; int key_weapon8 = '8'; int key_pause = KEY_PAUSE; +int key_demo_quit = 'q'; int mousebfire = 0; int mousebstrafe = 1; @@ -1846,7 +1847,7 @@ void G_WriteDemoTiccmd (ticcmd_t* cmd) { byte *demo_start; - if (gamekeydown['q']) // press q to end demo recording + if (gamekeydown[key_demo_quit]) // press q to end demo recording G_CheckDemoStatus (); demo_start = demo_p; diff --git a/src/m_config.c b/src/m_config.c index a2f3ac58..d0fe6808 100644 --- a/src/m_config.c +++ b/src/m_config.c @@ -149,6 +149,7 @@ extern int key_weapon7; extern int key_weapon8; extern int key_message_refresh; +extern int key_demo_quit; extern int mousebfire; extern int mousebstrafe; @@ -1041,6 +1042,12 @@ static default_t extra_defaults_list[] = // CONFIG_VARIABLE_KEY(key_message_refresh, key_message_refresh), + + //! + // Key to quit the game when recording a demo. + // + + CONFIG_VARIABLE_KEY(key_demo_quit, key_demo_quit), }; static default_collection_t extra_defaults = -- cgit v1.2.3 From 79300a83cb91395d97b33824dcbe39c06ff371da Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 10 Jul 2010 15:56:18 +0000 Subject: Add key bindings for multiplayer messaging. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1940 --- setup/configfile.c | 5 +++++ setup/keyboard.c | 19 ++++++++++++++++++- setup/keyboard.h | 5 +++++ src/hu_stuff.c | 22 ++++++++++++---------- src/m_config.c | 35 ++++++++++++++++++++++++++++++++++- 5 files changed, 74 insertions(+), 12 deletions(-) diff --git a/setup/configfile.c b/setup/configfile.c index 9f0e5de5..97d87aaf 100644 --- a/setup/configfile.c +++ b/setup/configfile.c @@ -337,6 +337,11 @@ static default_t extra_defaults_list[] = {"key_weapon8", &key_weapon8, DEFAULT_KEY, 0, 0}, {"key_message_refresh", &key_message_refresh, DEFAULT_KEY, 0, 0}, {"key_demo_quit", &key_demo_quit, DEFAULT_KEY, 0, 0}, + {"key_multi_msg", &key_multi_msg, DEFAULT_KEY, 0, 0}, + {"key_multi_msgplayer1", &key_multi_msgplayer[0], DEFAULT_KEY, 0, 0}, + {"key_multi_msgplayer2", &key_multi_msgplayer[1], DEFAULT_KEY, 0, 0}, + {"key_multi_msgplayer3", &key_multi_msgplayer[2], DEFAULT_KEY, 0, 0}, + {"key_multi_msgplayer4", &key_multi_msgplayer[3], DEFAULT_KEY, 0, 0}, }; static default_collection_t extra_defaults = diff --git a/setup/keyboard.c b/setup/keyboard.c index b402d10c..f16c0940 100644 --- a/setup/keyboard.c +++ b/setup/keyboard.c @@ -93,6 +93,9 @@ int key_weapon8 = '8'; int key_message_refresh = KEY_ENTER; int key_demo_quit = 'q'; +int key_multi_msg = 't'; +int key_multi_msgplayer[] = { 'g', 'i', 'b', 'r' }; + int vanilla_keyboard_mapping = 1; static int always_run = 0; @@ -116,7 +119,9 @@ static int *shortcuts[] = { &key_menu_help, &key_menu_save, &key_menu_load, &key_menu_endgame, &key_menu_messages, &key_menu_qload, &key_menu_quit, &key_menu_gamma, &key_menu_incscreen, &key_menu_decscreen, - &key_message_refresh, NULL }; + &key_message_refresh, &key_multi_msg, + &key_multi_msgplayer[0], &key_multi_msgplayer[1], + &key_multi_msgplayer[2], &key_multi_msgplayer[3] }; static int *map_keys[] = { &key_map_north, &key_map_south, &key_map_east, &key_map_west, &key_map_zoomin, &key_map_zoomout, @@ -276,6 +281,18 @@ static void OtherKeysDialog(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(unused)) AddKeyControl(table, "Display last message", &key_message_refresh); AddKeyControl(table, "Finish recording demo", &key_demo_quit); + TXT_AddWidgets(table, TXT_NewStrut(0, 1), + TXT_NewStrut(0, 1), + TXT_NewLabel(" - Multiplayer - "), + TXT_NewStrut(0, 0), + NULL); + + AddKeyControl(table, "Send message", &key_multi_msg); + AddKeyControl(table, "- to green", &key_multi_msgplayer[0]); + AddKeyControl(table, "- to indigo", &key_multi_msgplayer[1]); + AddKeyControl(table, "- to brown", &key_multi_msgplayer[2]); + AddKeyControl(table, "- to red", &key_multi_msgplayer[3]); + TXT_AddWidgets(table, TXT_NewStrut(0, 1), TXT_NewStrut(0, 1), TXT_NewLabel(" - Map - "), diff --git a/setup/keyboard.h b/setup/keyboard.h index 62addc8f..feeb9cf8 100644 --- a/setup/keyboard.h +++ b/setup/keyboard.h @@ -37,6 +37,11 @@ extern int vanilla_keyboard_mapping; extern int key_pause; +// Multiplayer messages: + +extern int key_multi_msg; +extern int key_multi_msgplayer[]; + // Menu keys: extern int key_menu_activate; diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 1381532d..afe3974c 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -88,6 +88,16 @@ char* player_names[] = HUSTR_PLRRED }; +int key_multi_msg = HU_INPUTTOGGLE; + +int key_multi_msgplayer[MAXPLAYERS] = +{ + HUSTR_KEYGREEN, + HUSTR_KEYINDIGO, + HUSTR_KEYBROWN, + HUSTR_KEYRED +}; + int key_message_refresh = KEY_ENTER; char chat_char; // remove later. @@ -572,14 +582,6 @@ boolean HU_Responder(event_t *ev) int i; int numplayers; - static char destination_keys[MAXPLAYERS] = - { - HUSTR_KEYGREEN, - HUSTR_KEYINDIGO, - HUSTR_KEYBROWN, - HUSTR_KEYRED - }; - static int num_nobrainers = 0; numplayers = 0; @@ -608,7 +610,7 @@ boolean HU_Responder(event_t *ev) message_counter = HU_MSGTIMEOUT; eatkey = true; } - else if (netgame && ev->data2 == HU_INPUTTOGGLE) + else if (netgame && ev->data2 == key_multi_msg) { eatkey = chat_on = true; HUlib_resetIText(&w_chat); @@ -618,7 +620,7 @@ boolean HU_Responder(event_t *ev) { for (i=0; idata2 == destination_keys[i]) + if (ev->data2 == key_multi_msgplayer[i]) { if (playeringame[i] && i!=consoleplayer) { diff --git a/src/m_config.c b/src/m_config.c index d0fe6808..ef9c97e8 100644 --- a/src/m_config.c +++ b/src/m_config.c @@ -150,7 +150,10 @@ extern int key_weapon8; extern int key_message_refresh; extern int key_demo_quit; - + +extern int key_multi_msg; +extern int key_multi_msgplayer[]; + extern int mousebfire; extern int mousebstrafe; extern int mousebforward; @@ -1048,6 +1051,36 @@ static default_t extra_defaults_list[] = // CONFIG_VARIABLE_KEY(key_demo_quit, key_demo_quit), + + //! + // Key to send a message during multiplayer games. + // + + CONFIG_VARIABLE_KEY(key_multi_msg, key_multi_msg), + + //! + // Key to send a message to the green player during multiplayer games. + // + + CONFIG_VARIABLE_KEY(key_multi_msgplayer1, key_multi_msgplayer[0]), + + //! + // Key to send a message to the indigo player during multiplayer games. + // + + CONFIG_VARIABLE_KEY(key_multi_msgplayer2, key_multi_msgplayer[1]), + + //! + // Key to send a message to the brown player during multiplayer games. + // + + CONFIG_VARIABLE_KEY(key_multi_msgplayer3, key_multi_msgplayer[2]), + + //! + // Key to send a message to the red player during multiplayer games. + // + + CONFIG_VARIABLE_KEY(key_multi_msgplayer4, key_multi_msgplayer[3]), }; static default_collection_t extra_defaults = -- cgit v1.2.3 From 133a09f09363605f6ecfd547d862b6dd0a479dbb Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 10 Jul 2010 16:06:15 +0000 Subject: Update NEWS and ChangeLog, bump version number. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1941 --- ChangeLog | 78 +++++++++++++++++++++++++++++++++++++++++++++++++ NEWS | 9 +++++- codeblocks/config.h | 6 ++-- codeblocks/game-res.rc | 10 +++---- codeblocks/setup-res.rc | 8 ++--- configure.in | 2 +- msvc/config.h | 6 ++-- msvc/win32.rc | 10 +++---- 8 files changed, 107 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index a5bd7228..0120d5db 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,81 @@ +2010-05-30 04:03:44 fraggle + + Add INSTALL to all distribution packages, add note in README. + +2010-05-30 03:56:58 fraggle + + Clarify/update install instructions. + +2010-05-14 19:42:32 fraggle + + Don't grab the mouse when the demo sequence advances. + +2010-05-03 17:47:25 fraggle + + Oops. + +2010-05-03 16:58:52 fraggle + + Update NEWS. + +2010-05-01 22:47:26 fraggle + + Further sanity checking on use of strcpy() with dehacked string + replacements. + +2010-05-01 22:20:30 fraggle + + Silence printf(DEH_String(...)) warnings, by providing a DEH_printf + function that checks the format string is a valid replacement. Also + add DEH_fprintf and DEH_snprintf functions to use throughout the code + to do similar checking. + +2010-05-01 20:22:52 fraggle + + Fix compiler warnings with savegame and response file code. + +2010-04-30 20:58:30 fraggle + + Merge contents of OPL-TODO into TODO file. + +2010-04-30 20:38:24 fraggle + + Add textscreen Doxyfile to dist. Add .desktop file to svn:ignore. Add + opl ctags file to localvimrc. + +2010-04-25 00:53:03 fraggle + + Add -reject_pad_with_ff parameter to allow padding value to be + specified. + +2010-04-23 21:46:29 fraggle + + Add REJECT buffer overflow emulation, based on code from PrBoom+ + (thanks entryway). Fixes YDFEAR25.LMP. + +2010-04-22 22:38:51 fraggle + + Disable OPL debugging messages. + +2010-03-08 18:52:59 fraggle + + Add OPL-TODO to dist, set svn:ignore properties. + +2010-03-08 18:50:29 fraggle + + Use native MIDI music by default. + +2010-03-08 01:14:23 fraggle + + Merge opl-branch to trunk. + + OPL support still isn't perfect, and it certainly isn't complete. + However, for now, it's good enough. + +2010-02-10 20:21:21 fraggle + + Bump version number, update ChangeLog and NEWS. + 2010-01-31 18:21:50 fraggle Change Windows resource file to use PACKAGE_COPYRIGHT and diff --git a/NEWS b/NEWS index ea6ba572..c2705062 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,4 @@ -1.4.0 (2010-??-??): +1.4.0 (2010-07-10): The biggest change in this version is the addition of OPL emulation. This emulates Vanilla Doom's MIDI playback when @@ -21,6 +21,13 @@ * Warnings are now generated for invalid dehacked replacements of printf format strings. Some potential buffer overflows are also checked. + * The installation instructions (INSTALL file) have been + clarified and made more platform-agnostic. + * The mouse is no longer warped to the center of the screen when + the demo sequence advances. + * Key bindings can now be changed for the demo recording quit key + (normally 'q') and the multiplayer messaging keys (normally + 't', 'g', 'i', 'b' and 'r'). 1.3.0 (2010-02-10): diff --git a/codeblocks/config.h b/codeblocks/config.h index 70a4a742..d092bf73 100644 --- a/codeblocks/config.h +++ b/codeblocks/config.h @@ -9,19 +9,19 @@ #define PACKAGE_NAME "Chocolate Doom" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "Chocolate Doom 1.3.0" +#define PACKAGE_STRING "Chocolate Doom 1.4.0" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "chocolate-doom" /* Define to the version of this package. */ -#define PACKAGE_VERSION "1.3.0" +#define PACKAGE_VERSION "1.4.0" /* Define to 1 if you have the ANSI C header files. */ #define STDC_HEADERS 1 /* Version number of package */ -#define VERSION "1.3.0" +#define VERSION "1.4.0" /* Define to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel and VAX). */ diff --git a/codeblocks/game-res.rc b/codeblocks/game-res.rc index 98e58491..eef24852 100644 --- a/codeblocks/game-res.rc +++ b/codeblocks/game-res.rc @@ -1,21 +1,21 @@ 1 ICON "../data/doom.ico" 1 VERSIONINFO -PRODUCTVERSION 1,3,0,0 -FILEVERSION 1,3,0,0 +PRODUCTVERSION 1,4,0,0 +FILEVERSION 1,4,0,0 FILETYPE 1 { BLOCK "StringFileInfo" { BLOCK "040904E4" { - VALUE "FileVersion", "1.3.0" - VALUE "FileDescription", "1.3.0" + VALUE "FileVersion", "1.4.0" + VALUE "FileDescription", "1.4.0" VALUE "InternalName", "Chocolate-Doom" VALUE "CompanyName", "Chocolate-Doom" VALUE "LegalCopyright", "GNU General Public License" VALUE "ProductName", "Chocolate-Doom" - VALUE "ProductVersion", "1.3.0" + VALUE "ProductVersion", "1.4.0" } } } diff --git a/codeblocks/setup-res.rc b/codeblocks/setup-res.rc index 906658f3..f1602adb 100644 --- a/codeblocks/setup-res.rc +++ b/codeblocks/setup-res.rc @@ -3,21 +3,21 @@ CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "setup-manifest.xml" 1 VERSIONINFO -PRODUCTVERSION 1,3,0,0 -FILEVERSION 1,3,0,0 +PRODUCTVERSION 1,4,0,0 +FILEVERSION 1,4,0,0 FILETYPE 1 { BLOCK "StringFileInfo" { BLOCK "040904E4" { - VALUE "FileVersion", "1.3.0" + VALUE "FileVersion", "1.4.0" VALUE "FileDescription", "Chocolate-Doom Setup" VALUE "InternalName", "chocolate-setup" VALUE "CompanyName", "fraggle@gmail.com" VALUE "LegalCopyright", "GNU General Public License" VALUE "ProductName", "Chocolate-Doom Setup" - VALUE "ProductVersion", "1.3.0" + VALUE "ProductVersion", "1.4.0" } } } diff --git a/configure.in b/configure.in index 258822ce..501064c6 100644 --- a/configure.in +++ b/configure.in @@ -1,4 +1,4 @@ -AC_INIT(Chocolate Doom, 1.3.0, fraggle@gmail.com, chocolate-doom) +AC_INIT(Chocolate Doom, 1.4.0, fraggle@gmail.com, chocolate-doom) PACKAGE_SHORTDESC="Conservative Doom source port" PACKAGE_COPYRIGHT="Copyright (C) 1993-2010" diff --git a/msvc/config.h b/msvc/config.h index 2dbf8c11..006d7c74 100644 --- a/msvc/config.h +++ b/msvc/config.h @@ -11,16 +11,16 @@ #define PACKAGE_NAME "Chocolate Doom" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "Chocolate Doom 1.3.0" +#define PACKAGE_STRING "Chocolate Doom 1.4.0" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "chocolate-doom" /* Define to the version of this package. */ -#define PACKAGE_VERSION "1.3.0" +#define PACKAGE_VERSION "1.4.0" /* Version number of package */ -#define VERSION "1.3.0" +#define VERSION "1.4.0" /* Define to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel and VAX). */ diff --git a/msvc/win32.rc b/msvc/win32.rc index 72bb7802..94a35372 100644 --- a/msvc/win32.rc +++ b/msvc/win32.rc @@ -32,21 +32,21 @@ #endif 1 VERSIONINFO -PRODUCTVERSION 1,3,0,0 -FILEVERSION 1,3,0,0 +PRODUCTVERSION 1,4,0,0 +FILEVERSION 1,4,0,0 FILETYPE 1 BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "040904E4" BEGIN - VALUE "FileVersion", "1.3.0" - VALUE "FileDescription", "Chocolate Doom 1.3.0" + VALUE "FileVersion", "1.4.0" + VALUE "FileDescription", "Chocolate Doom 1.4.0" VALUE "InternalName", "chocolate-doom" VALUE "CompanyName", "fraggle@gmail.com" VALUE "LegalCopyright", "GNU General Public License" VALUE "ProductName", "Chocolate Doom" - VALUE "ProductVersion", "1.3.0" + VALUE "ProductVersion", "1.4.0" END END END -- cgit v1.2.3 From fea1fb2a38f269fb841c4fcb0c0dea70e2bde388 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Wed, 14 Jul 2010 20:36:53 +0000 Subject: Set MACOSX_DEPLOYMENT_TARGET to target 10.4, so that the launcher will work on older versions. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1944 --- pkg/osx/GNUmakefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/osx/GNUmakefile b/pkg/osx/GNUmakefile index d119efa1..baaec048 100644 --- a/pkg/osx/GNUmakefile +++ b/pkg/osx/GNUmakefile @@ -6,6 +6,10 @@ include ../config.make +# Build so that the package will work on older versions. + +export MACOSX_DEPLOYMENT_TARGET=10.4 + STAGING_DIR=staging DMG=$(PACKAGE_TARNAME)-$(PACKAGE_VERSION).dmg -- cgit v1.2.3 From b457a1c95679a878e9508211117b11c53c9e90a4 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 17 Jul 2010 00:33:57 +0000 Subject: Check for libm, to fix Fedora compile issues. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1946 --- configure.in | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.in b/configure.in index 501064c6..4cdba724 100644 --- a/configure.in +++ b/configure.in @@ -74,6 +74,7 @@ AC_SDL_MAIN_WORKAROUND([ # Check for libsamplerate. AC_CHECK_LIB(samplerate, src_new) + AC_CHECK_LIB(m, log) AC_CHECK_HEADERS([linux/kd.h dev/isa/spkrio.h dev/speaker/speaker.h]) AC_CHECK_FUNCS(mmap sched_setaffinity ioperm) -- cgit v1.2.3 From 232fba47e0a42af8c3ec0f934eaa855163c4ee35 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Wed, 28 Jul 2010 20:39:07 +0000 Subject: Add config file parameter to set OPL I/O port. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1947 --- setup/configfile.c | 9 ++++++++- setup/sound.c | 1 + setup/sound.h | 1 + src/m_config.c | 31 +++++++++++++++++++++++++------ 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/setup/configfile.c b/setup/configfile.c index 97d87aaf..6db7f710 100644 --- a/setup/configfile.c +++ b/setup/configfile.c @@ -154,9 +154,10 @@ static int snd_sbirq = 0; static int snd_sbdma = 0; static int snd_mport = 0; -typedef enum +typedef enum { DEFAULT_INT, + DEFAULT_INT_HEX, DEFAULT_STRING, DEFAULT_FLOAT, DEFAULT_KEY, @@ -269,6 +270,7 @@ static default_t extra_defaults_list[] = {"mouse_acceleration", &mouse_acceleration, DEFAULT_FLOAT, 0, 0}, {"mouse_threshold", &mouse_threshold, DEFAULT_INT, 0, 0}, {"snd_samplerate", &snd_samplerate, DEFAULT_INT, 0, 0}, + {"opl_io_port", &opl_io_port, DEFAULT_INT_HEX, 0, 0}, {"show_endoom", &show_endoom, DEFAULT_INT, 0, 0}, {"vanilla_savegame_limit", &vanilla_savegame_limit, DEFAULT_INT, 0, 0}, {"vanilla_demo_limit", &vanilla_demo_limit, DEFAULT_INT, 0, 0}, @@ -435,6 +437,10 @@ static void SaveDefaultCollection(default_collection_t *collection) fprintf(f, "%i", v); break; + case DEFAULT_INT_HEX: + fprintf(f, "0x%x", * (int *) defaults[i].location); + break; + case DEFAULT_INT: fprintf(f, "%i", * (int *) defaults[i].location); break; @@ -528,6 +534,7 @@ static void LoadDefaultCollection(default_collection_t *collection) break; case DEFAULT_INT: + case DEFAULT_INT_HEX: * (int *) def->location = ParseIntParameter(strparm); break; diff --git a/setup/sound.c b/setup/sound.c index f7a9c6d4..59df0532 100644 --- a/setup/sound.c +++ b/setup/sound.c @@ -65,6 +65,7 @@ int snd_musicdevice = SNDDEVICE_GENMIDI; int musicVolume = 15; int snd_samplerate = 22050; +int opl_io_port = 0x388; int use_libsamplerate = 0; diff --git a/setup/sound.h b/setup/sound.h index 6c366151..eb386d6f 100644 --- a/setup/sound.h +++ b/setup/sound.h @@ -44,6 +44,7 @@ extern int snd_musicdevice; extern int musicVolume; extern int snd_samplerate; +extern int opl_io_port; extern int use_libsamplerate; diff --git a/src/m_config.c b/src/m_config.c index ef9c97e8..8744e98a 100644 --- a/src/m_config.c +++ b/src/m_config.c @@ -191,6 +191,7 @@ extern int vanilla_demo_limit; extern int snd_musicdevice; extern int snd_sfxdevice; extern int snd_samplerate; +extern int opl_io_port; // controls whether to use libsamplerate for sample rate conversions @@ -208,6 +209,7 @@ static int snd_mport = 0; typedef enum { DEFAULT_INT, + DEFAULT_INT_HEX, DEFAULT_STRING, DEFAULT_FLOAT, DEFAULT_KEY, @@ -243,14 +245,19 @@ typedef struct char *filename; } default_collection_t; +#define CONFIG_VARIABLE_GENERIC(name, variable, type) \ + { #name, &variable, type, 0, 0 } + #define CONFIG_VARIABLE_KEY(name, variable) \ - { #name, &variable, DEFAULT_KEY, 0, 0 } + CONFIG_VARIABLE_GENERIC(name, variable, DEFAULT_KEY) #define CONFIG_VARIABLE_INT(name, variable) \ - { #name, &variable, DEFAULT_INT, 0, 0 } + CONFIG_VARIABLE_GENERIC(name, variable, DEFAULT_INT) +#define CONFIG_VARIABLE_INT_HEX(name, variable) \ + CONFIG_VARIABLE_GENERIC(name, variable, DEFAULT_INT_HEX) #define CONFIG_VARIABLE_FLOAT(name, variable) \ - { #name, &variable, DEFAULT_FLOAT, 0, 0 } + CONFIG_VARIABLE_GENERIC(name, variable, DEFAULT_FLOAT) #define CONFIG_VARIABLE_STRING(name, variable) \ - { #name, &variable, DEFAULT_STRING, 0, 0 } + CONFIG_VARIABLE_GENERIC(name, variable, DEFAULT_STRING) //! @begin_config_file default.cfg @@ -625,19 +632,26 @@ static default_t extra_defaults_list[] = //! // Mouse acceleration threshold. When the speed of mouse movement - // exceeds this threshold value, the speed is multiplied by an + // exceeds this threshold value, the speed is multiplied by an // acceleration factor (mouse_acceleration). // CONFIG_VARIABLE_INT(mouse_threshold, mouse_threshold), //! - // Sound output sample rate, in Hz. Typical values to use are + // Sound output sample rate, in Hz. Typical values to use are // 11025, 22050, 44100 and 48000. // CONFIG_VARIABLE_INT(snd_samplerate, snd_samplerate), + //! + // 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, opl_io_port), + //! // If non-zero, the ENDOOM screen is displayed when exiting the // game. If zero, the ENDOOM screen is not displayed. @@ -1178,6 +1192,10 @@ static void SaveDefaultCollection(default_collection_t *collection) fprintf(f, "%i", * (int *) defaults[i].location); break; + case DEFAULT_INT_HEX: + fprintf(f, "0x%x", * (int *) defaults[i].location); + break; + case DEFAULT_FLOAT: fprintf(f, "%f", * (float *) defaults[i].location); break; @@ -1267,6 +1285,7 @@ static void LoadDefaultCollection(default_collection_t *collection) break; case DEFAULT_INT: + case DEFAULT_INT_HEX: * (int *) def->location = ParseIntParameter(strparm); break; -- cgit v1.2.3 From 4319d9cda4caab4a9c4d5f98a780ea8d9e3531f6 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 31 Jul 2010 19:25:17 +0000 Subject: Add multiplayer spy key binding. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1948 --- setup/configfile.c | 1 + setup/keyboard.c | 4 +++- setup/keyboard.h | 1 + src/g_game.c | 3 ++- src/m_config.c | 7 +++++++ 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/setup/configfile.c b/setup/configfile.c index 6db7f710..5fe1d958 100644 --- a/setup/configfile.c +++ b/setup/configfile.c @@ -314,6 +314,7 @@ static default_t extra_defaults_list[] = {"key_menu_qload", &key_menu_qload, DEFAULT_KEY, 0, 0}, {"key_menu_quit", &key_menu_quit, DEFAULT_KEY, 0, 0}, {"key_menu_gamma", &key_menu_gamma, DEFAULT_KEY, 0, 0}, + {"key_spy", &key_spy, DEFAULT_KEY, 0, 0}, {"key_menu_incscreen", &key_menu_incscreen, DEFAULT_KEY, 0, 0}, {"key_menu_decscreen", &key_menu_decscreen, DEFAULT_KEY, 0, 0}, diff --git a/setup/keyboard.c b/setup/keyboard.c index f16c0940..bcf5ec7a 100644 --- a/setup/keyboard.c +++ b/setup/keyboard.c @@ -64,6 +64,7 @@ int key_menu_messages = KEY_F8; int key_menu_qload = KEY_F9; int key_menu_quit = KEY_F10; int key_menu_gamma = KEY_F11; +int key_spy = KEY_F12; int key_menu_incscreen = KEY_EQUALS; int key_menu_decscreen = KEY_MINUS; @@ -116,7 +117,7 @@ static int *menu_nav[] = { &key_menu_activate, &key_menu_up, &key_menu_down, static int *shortcuts[] = { &key_menu_help, &key_menu_save, &key_menu_load, &key_menu_volume, &key_menu_detail, &key_menu_qsave, - &key_menu_endgame, &key_menu_messages, + &key_menu_endgame, &key_menu_messages, &key_spy, &key_menu_qload, &key_menu_quit, &key_menu_gamma, &key_menu_incscreen, &key_menu_decscreen, &key_message_refresh, &key_multi_msg, @@ -274,6 +275,7 @@ static void OtherKeysDialog(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(unused)) AddKeyControl(table, "Quick load", &key_menu_qload); AddKeyControl(table, "Quit game", &key_menu_quit); AddKeyControl(table, "Toggle gamma", &key_menu_gamma); + AddKeyControl(table, "Multiplayer spy", &key_spy); AddKeyControl(table, "Increase screen size", &key_menu_incscreen); AddKeyControl(table, "Decrease screen size", &key_menu_decscreen); diff --git a/setup/keyboard.h b/setup/keyboard.h index feeb9cf8..f934116f 100644 --- a/setup/keyboard.h +++ b/setup/keyboard.h @@ -65,6 +65,7 @@ extern int key_menu_messages; extern int key_menu_qload; extern int key_menu_quit; extern int key_menu_gamma; +extern int key_spy; extern int key_menu_incscreen; extern int key_menu_decscreen; diff --git a/src/g_game.c b/src/g_game.c index a9ee2641..701b98d5 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -185,6 +185,7 @@ int key_weapon8 = '8'; int key_pause = KEY_PAUSE; int key_demo_quit = 'q'; +int key_spy = KEY_F12; int mousebfire = 0; int mousebstrafe = 1; @@ -740,7 +741,7 @@ boolean G_Responder (event_t* ev) { // allow spy mode changes even during the demo if (gamestate == GS_LEVEL && ev->type == ev_keydown - && ev->data1 == KEY_F12 && (singledemo || !deathmatch) ) + && ev->data1 == key_spy && (singledemo || !deathmatch) ) { // spy mode do diff --git a/src/m_config.c b/src/m_config.c index 8744e98a..b2e52e7f 100644 --- a/src/m_config.c +++ b/src/m_config.c @@ -122,6 +122,7 @@ extern int key_menu_messages; extern int key_menu_qload; extern int key_menu_quit; extern int key_menu_gamma; +extern int key_spy; extern int key_menu_incscreen; extern int key_menu_decscreen; @@ -922,6 +923,12 @@ static default_t extra_defaults_list[] = CONFIG_VARIABLE_KEY(key_menu_gamma, key_menu_gamma), + //! + // Keyboard shortcut to switch view in multiplayer. + // + + CONFIG_VARIABLE_KEY(key_spy, key_spy), + //! // Keyboard shortcut to increase the screen size. // -- cgit v1.2.3 From ad8d7a1efb8c61bb39568f76ab814919895cc501 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Tue, 3 Aug 2010 20:12:36 +0000 Subject: When in windowed mode, allow the screen size to be dynamically resized by dragging the window borders. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1949 --- src/i_scale.c | 14 +++- src/i_video.c | 208 ++++++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 150 insertions(+), 72 deletions(-) diff --git a/src/i_scale.c b/src/i_scale.c index a022ab15..3f7b3a7d 100644 --- a/src/i_scale.c +++ b/src/i_scale.c @@ -53,11 +53,11 @@ static int dest_pitch; // stretch_tables[1] : 40% / 60% // All other combinations can be reached from these two tables. -static byte *stretch_tables[2]; +static byte *stretch_tables[2] = { NULL, NULL }; // 50%/50% stretch table, for 800x600 squash mode -static byte *half_stretch_table; +static byte *half_stretch_table = NULL; // Called to set the source and destination buffers before doing the // scale. @@ -364,6 +364,11 @@ static byte *GenerateStretchTable(byte *palette, int pct) static void I_InitStretchTables(byte *palette) { + if (stretch_tables[0] != NULL) + { + return; + } + // We only actually need two lookup tables: // // mix 0% = just write line 1 @@ -385,6 +390,11 @@ static void I_InitStretchTables(byte *palette) static void I_InitSquashTable(byte *palette) { + if (half_stretch_table != NULL) + { + return; + } + printf("I_InitSquashTable: Generating lookup table.."); fflush(stdout); half_stretch_table = GenerateStretchTable(palette, 50); diff --git a/src/i_video.c b/src/i_video.c index bc3f17cf..91b670b8 100644 --- a/src/i_video.c +++ b/src/i_video.c @@ -98,8 +98,6 @@ static SDL_Surface *screen; static SDL_Color palette[256]; static boolean palette_to_set; -static int windowwidth, windowheight; - // display has been set up? static boolean initialized = false; @@ -160,6 +158,12 @@ static SDL_Cursor *cursors[2]; static screen_mode_t *screen_mode; +// Window resize state. + +static boolean need_resize = false; +static unsigned int resize_w, resize_h; +static unsigned int last_resize_time; + // 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. @@ -178,6 +182,8 @@ int vanilla_keyboard_mapping = true; float mouse_acceleration = 2.0; int mouse_threshold = 10; +static void ApplyWindowResize(unsigned int w, unsigned int h); + static boolean MouseShouldBeGrabbed() { // never grab the mouse when in screensaver mode @@ -580,6 +586,13 @@ void I_GetEvent(void) palette_to_set = true; break; + case SDL_RESIZABLE: + need_resize = true; + resize_w = sdlevent.resize.w; + resize_h = sdlevent.resize.h; + last_resize_time = SDL_GetTicks(); + break; + default: break; } @@ -815,14 +828,20 @@ void I_FinishUpdate (void) static int lasttic; int tics; int i; - // UNUSED static unsigned char *bigscreen=0; if (!initialized) return; if (noblit) return; - + + if (need_resize && SDL_GetTicks() > last_resize_time + 500) + { + ApplyWindowResize(resize_w, resize_h); + need_resize = false; + palette_to_set = true; + } + UpdateGrab(); // Don't update the screen if the window isn't visible. @@ -1492,11 +1511,96 @@ static char *WindowBoxType(screen_mode_t *mode, int w, int h) } } +static void SetVideoMode(screen_mode_t *mode, int w, int h) +{ + byte *doompal; + int flags = 0; + + doompal = W_CacheLumpName(DEH_String("PLAYPAL"), PU_CACHE); + + // Generate lookup tables before setting the video mode. + + if (mode != NULL && mode->InitMode != NULL) + { + mode->InitMode(doompal); + } + + // Set the video mode. + + flags |= SDL_SWSURFACE | SDL_HWPALETTE | SDL_DOUBLEBUF; + + if (fullscreen) + { + flags |= SDL_FULLSCREEN; + } + else + { + flags |= SDL_RESIZABLE; + } + + screen = SDL_SetVideoMode(w, h, 8, flags); + + if (screen == NULL) + { + I_Error("Error setting video mode: %s\n", SDL_GetError()); + } + + // If mode was not set, it must be set now that we know the + // screen size. + + if (mode == NULL) + { + mode = I_FindScreenMode(screen->w, screen->h); + + if (mode == NULL) + { + I_Error("I_InitGraphics: Unable to find a screen mode small " + "enough for %ix%i", screen->w, screen->h); + } + + // Generate lookup tables before setting the video mode. + + if (mode->InitMode != NULL) + { + mode->InitMode(doompal); + } + } + + // Save screen mode. + + screen_mode = mode; +} + +static void ApplyWindowResize(unsigned int w, unsigned int h) +{ + screen_mode_t *mode; + + // Find the biggest screen mode that will fall within these + // dimensions, falling back to the smallest mode possible if + // none is found. + + mode = I_FindScreenMode(w, h); + + if (mode == NULL) + { + mode = I_FindScreenMode(SCREENWIDTH, SCREENHEIGHT); + } + + // Reset mode to resize window. + + printf("Resize to %ix%i\n", mode->width, mode->height); + SetVideoMode(mode, mode->width, mode->height); + + // Save settings. + + screen_width = mode->width; + screen_height = mode->height; +} + void I_InitGraphics(void) { SDL_Event dummy; byte *doompal; - int flags = 0; char *env; // Pass through the XSCREENSAVER_WINDOW environment variable to @@ -1527,70 +1631,53 @@ void I_InitGraphics(void) CheckCommandLine(); - doompal = W_CacheLumpName (DEH_String("PLAYPAL"),PU_CACHE); + // Set up title and icon. Windows cares about the ordering; this + // has to be done before the call to SDL_SetVideoMode. + + I_SetWindowCaption(); +#if !SDL_VERSION_ATLEAST(1, 3, 0) + I_SetWindowIcon(); +#endif + + // + // Enter into graphics mode. + // + // When in screensaver mode, run full screen and auto detect + // screen dimensions (don't change video mode) + // if (screensaver_mode) { - windowwidth = 0; - windowheight = 0; + SetVideoMode(NULL, 0, 0); } else { + int w, h; + if (autoadjust_video_settings) { I_AutoAdjustSettings(); } - windowwidth = screen_width; - windowheight = screen_height; + w = screen_width; + h = screen_height; - screen_mode = I_FindScreenMode(windowwidth, windowheight); + screen_mode = I_FindScreenMode(w, h); if (screen_mode == NULL) { I_Error("I_InitGraphics: Unable to find a screen mode small " - "enough for %ix%i", windowwidth, windowheight); + "enough for %ix%i", w, h); } - if (windowwidth != screen_mode->width - || windowheight != screen_mode->height) + if (w != screen_mode->width || h != screen_mode->height) { printf("I_InitGraphics: %s (%ix%i within %ix%i)\n", - WindowBoxType(screen_mode, windowwidth, windowheight), - screen_mode->width, screen_mode->height, - windowwidth, windowheight); - } - - // Generate lookup tables before setting the video mode. - - if (screen_mode->InitMode != NULL) - { - screen_mode->InitMode(doompal); + WindowBoxType(screen_mode, w, h), + screen_mode->width, screen_mode->height, w, h); } - } - - // Set up title and icon. Windows cares about the ordering; this - // has to be done before the call to SDL_SetVideoMode. - - I_SetWindowCaption(); -#if !SDL_VERSION_ATLEAST(1, 3, 0) - I_SetWindowIcon(); -#endif - - // Set the video mode. - - flags |= SDL_SWSURFACE | SDL_HWPALETTE | SDL_DOUBLEBUF; - - if (fullscreen) - { - flags |= SDL_FULLSCREEN; - } - - screen = SDL_SetVideoMode(windowwidth, windowheight, 8, flags); - if (screen == NULL) - { - I_Error("Error setting video mode: %s\n", SDL_GetError()); + SetVideoMode(screen_mode, w, h); } // Start with a clear black screen @@ -1611,6 +1698,7 @@ void I_InitGraphics(void) // Set the palette + doompal = W_CacheLumpName(DEH_String("PLAYPAL"), PU_CACHE); I_SetPalette(doompal); SDL_SetColors(screen, palette, 0, 256); @@ -1619,26 +1707,6 @@ void I_InitGraphics(void) UpdateFocus(); UpdateGrab(); - // In screensaver mode, now find a screen_mode to use. - - if (screensaver_mode) - { - screen_mode = I_FindScreenMode(screen->w, screen->h); - - if (screen_mode == NULL) - { - I_Error("I_InitGraphics: Unable to find a screen mode small " - "enough for %ix%i", screen->w, screen->h); - } - - // Generate lookup tables before setting the video mode. - - if (screen_mode->InitMode != NULL) - { - screen_mode->InitMode(doompal); - } - } - // On some systems, it takes a second or so for the screen to settle // after changing modes. We include the option to add a delay when // setting the screen mode, so that the game doesn't start immediately @@ -1654,12 +1722,12 @@ void I_InitGraphics(void) // Likewise if the screen pitch is not the same as the width // If we have to multiply, drawing is done to a separate 320x200 buf - native_surface = !SDL_MUSTLOCK(screen) + native_surface = !SDL_MUSTLOCK(screen) && screen_mode == &mode_scale_1x && screen->pitch == SCREENWIDTH && aspect_ratio_correct; - // If not, allocate a buffer and copy from that buffer to the + // If not, allocate a buffer and copy from that buffer to the // screen when we do an update if (native_surface) @@ -1670,7 +1738,7 @@ void I_InitGraphics(void) } else { - screens[0] = (unsigned char *) Z_Malloc (SCREENWIDTH * SCREENHEIGHT, + screens[0] = (unsigned char *) Z_Malloc (SCREENWIDTH * SCREENHEIGHT, PU_STATIC, NULL); } -- cgit v1.2.3 From 05cafe91729446ebd28f3fdab2302277c53530d1 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Wed, 4 Aug 2010 18:25:04 +0000 Subject: Initial code for previous/next weapon switching keys. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1950 --- src/g_game.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 115 insertions(+), 9 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 701b98d5..1e163716 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -182,6 +182,8 @@ int key_weapon5 = '5'; int key_weapon6 = '6'; int key_weapon7 = '7'; int key_weapon8 = '8'; +int key_prevweapon = 0; +int key_nextweapon = 0; int key_pause = KEY_PAUSE; int key_demo_quit = 'q'; @@ -235,6 +237,28 @@ static int *weapon_keys[] = { &key_weapon8 }; +// Set to -1 or +1 to switch to the previous or next weapon. + +static int next_weapon = 0; + +// Used for prev/next weapon keys. + +static const struct +{ + weapontype_t weapon; + weapontype_t weapon_num; +} weapon_order_table[] = { + { wp_fist, wp_fist }, + { wp_chainsaw, wp_fist }, + { wp_pistol, wp_pistol }, + { wp_shotgun, wp_shotgun }, + { wp_supershotgun, wp_shotgun }, + { wp_chaingun, wp_chaingun }, + { wp_missile, wp_missile }, + { wp_plasma, wp_plasma }, + { wp_bfg, wp_bfg } +}; + #define SLOWTURNTICS 6 #define NUMKEYS 256 @@ -396,7 +420,63 @@ int G_CmdChecksum (ticcmd_t* cmd) return sum; } - + +static boolean WeaponSelectable(weapontype_t weapon) +{ + // Can't select a weapon if we don't own it. + + if (!players[consoleplayer].weaponowned[weapon]) + { + return false; + } + + // Can't select the fist if we have the chainsaw, unless + // we also have the berserk pack. + + if (weapon == wp_fist + && players[consoleplayer].weaponowned[wp_chainsaw] + && !players[consoleplayer].powers[pw_strength]) + { + return false; + } + + return true; +} + +static int G_NextWeapon(int direction) +{ + weapontype_t weapon; + int i; + + // Find index in the table. + + if (players[consoleplayer].pendingweapon == wp_nochange) + { + weapon = players[consoleplayer].readyweapon; + } + else + { + weapon = players[consoleplayer].pendingweapon; + } + + for (i=0; ibuttons |= BT_CHANGE; + cmd->buttons |= i << BT_WEAPONSHIFT; + next_weapon = 0; + } + else { - int key = *weapon_keys[i]; + // Check weapon keys. - if (gamekeydown[key]) + for (i=0; ibuttons |= BT_CHANGE; - cmd->buttons |= i<buttons |= BT_CHANGE; + cmd->buttons |= i<data2); } + // If the next/previous weapon keys are pressed, set the next_weapon + // variable to change weapons when the next ticcmd is generated. + + if (ev->type == ev_keydown && ev->data1 == key_prevweapon) + { + next_weapon = -1; + } + else if (ev->type == ev_keydown && ev->data1 == key_nextweapon) + { + next_weapon = 1; + } + switch (ev->type) { case ev_keydown: -- cgit v1.2.3 From 5e9a9a52dbebabda79f221caf318dd8fba4b0781 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 7 Aug 2010 16:07:00 +0000 Subject: Fix sound resampling low pass filter. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1951 --- src/i_sdlsound.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/i_sdlsound.c b/src/i_sdlsound.c index d51345c7..ff191202 100644 --- a/src/i_sdlsound.c +++ b/src/i_sdlsound.c @@ -244,12 +244,15 @@ static void ExpandSoundData_SDL(byte *data, // (maximum frequency, by nyquist) dt = 1.0f / mixer_freq; - rc = 1.0f / (3.14f * samplerate); + rc = 1.0f / (2 * 3.14f * samplerate); alpha = dt / (rc + dt); - for (i=1; i @@ -41,6 +40,7 @@ #include "deh_main.h" #include "i_system.h" +#include "i_swap.h" #include "s_sound.h" #include "m_argv.h" #include "w_wad.h" @@ -49,6 +49,7 @@ #include "doomdef.h" #define LOW_PASS_FILTER +//#define DEBUG_DUMP_WAVS #define MAX_SOUND_SLICE_TIME 70 /* ms */ #define NUM_CHANNELS 16 @@ -159,12 +160,62 @@ static boolean ConvertibleRatio(int freq1, int freq2) } } +#ifdef DEBUG_DUMP_WAVS + +// Debug code to dump resampled sound effects to WAV files for analysis. + +static void WriteWAV(char *filename, byte *data, + uint32_t length, int samplerate) +{ + FILE *wav; + unsigned int i; + unsigned short s; + + wav = fopen(filename, "wb"); + + // Header + + fwrite("RIFF", 1, 4, wav); + i = LONG(36 + samplerate); + fwrite(&i, 4, 1, wav); + fwrite("WAVE", 1, 4, wav); + + // Subchunk 1 + + fwrite("fmt ", 1, 4, wav); + i = LONG(16); + fwrite(&i, 4, 1, wav); // Length + s = SHORT(1); + fwrite(&s, 2, 1, wav); // Format (PCM) + s = SHORT(2); + fwrite(&s, 2, 1, wav); // Channels (2=stereo) + i = LONG(samplerate); + fwrite(&i, 4, 1, wav); // Sample rate + i = LONG(samplerate * 2 * 2); + fwrite(&i, 4, 1, wav); // Byte rate (samplerate * stereo * 16 bit) + s = SHORT(2 * 2); + fwrite(&s, 2, 1, wav); // Block align (stereo * 16 bit) + s = SHORT(16); + fwrite(&s, 2, 1, wav); // Bits per sample (16 bit) + + // Data subchunk + + fwrite("data", 1, 4, wav); + i = LONG(length); + fwrite(&i, 4, 1, wav); // Data length + fwrite(data, 1, length, wav); // Data + + fclose(wav); +} + +#endif + // Generic sound expansion function for any sample rate. static void ExpandSoundData_SDL(byte *data, - int samplerate, - uint32_t length, - Mix_Chunk *destination) + int samplerate, + uint32_t length, + Mix_Chunk *destination) { SDL_AudioCVT convertor; uint32_t expanded_length; @@ -181,7 +232,7 @@ static void ExpandSoundData_SDL(byte *data, = Z_Malloc(expanded_length, PU_STATIC, &destination->abuf); // If we can, use the standard / optimized SDL conversion routines. - + if (samplerate <= mixer_freq && ConvertibleRatio(samplerate, mixer_freq) && SDL_BuildAudioCVT(&convertor, @@ -244,7 +295,7 @@ static void ExpandSoundData_SDL(byte *data, // (maximum frequency, by nyquist) dt = 1.0f / mixer_freq; - rc = 1.0f / (2 * 3.14f * samplerate); + rc = 1.0f / (3.14f * samplerate); alpha = dt / (rc + dt); // Both channels are processed in parallel, hence [i-2]: @@ -347,6 +398,16 @@ static boolean CacheSFX_SDL(int sound) length, &sound_chunks[sound]); +#ifdef DEBUG_DUMP_WAVS + { + char filename[16]; + + sprintf(filename, "%s.wav", DEH_String(S_sfx[sound].name)); + WriteWAV(filename, sound_chunks[sound].abuf, + sound_chunks[sound].alen, mixer_freq); + } +#endif + // don't need the original lump any more W_ReleaseLumpNum(lumpnum); -- cgit v1.2.3 From f3d3b03870a6842e104c67ce6fc7edfde89d77ec Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Mon, 9 Aug 2010 17:53:10 +0000 Subject: Add weapon cycling bindings for mouse and joystick buttons. Add weapon cycling bindings to configuration file and setup tool. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1953 --- setup/configfile.c | 6 +++++ setup/joystick.c | 4 ++++ setup/joystick.h | 2 ++ setup/keyboard.c | 7 +++++- setup/keyboard.h | 2 ++ setup/mouse.c | 6 +++++ setup/mouse.h | 2 ++ setup/txt_keyinput.c | 2 +- src/g_game.c | 65 ++++++++++++++++++++++++++++++++++++++++++++-------- src/m_config.c | 44 +++++++++++++++++++++++++++++++++++ 10 files changed, 129 insertions(+), 11 deletions(-) diff --git a/setup/configfile.c b/setup/configfile.c index 5fe1d958..2a3cb845 100644 --- a/setup/configfile.c +++ b/setup/configfile.c @@ -286,11 +286,15 @@ static default_t extra_defaults_list[] = {"joystick_y_invert", &joystick_y_invert, DEFAULT_INT, 0, 0}, {"joyb_strafeleft", &joybstrafeleft, DEFAULT_INT, 0, 0}, {"joyb_straferight", &joybstraferight, DEFAULT_INT, 0, 0}, + {"joyb_prevweapon", &joybprevweapon, DEFAULT_INT, 0, 0}, + {"joyb_nextweapon", &joybnextweapon, DEFAULT_INT, 0, 0}, {"dclick_use", &dclick_use, DEFAULT_INT, 0, 0}, {"mouseb_strafeleft", &mousebstrafeleft, DEFAULT_INT, 0, 0}, {"mouseb_straferight", &mousebstraferight, DEFAULT_INT, 0, 0}, {"mouseb_use", &mousebuse, DEFAULT_INT, 0, 0}, {"mouseb_backward", &mousebbackward, DEFAULT_INT, 0, 0}, + {"mouseb_prevweapon", &mousebprevweapon, DEFAULT_INT, 0, 0}, + {"mouseb_nextweapon", &mousebnextweapon, DEFAULT_INT, 0, 0}, {"use_libsamplerate", &use_libsamplerate, DEFAULT_INT, 0, 0}, {"key_pause", &key_pause, DEFAULT_KEY, 0, 0}, @@ -338,6 +342,8 @@ static default_t extra_defaults_list[] = {"key_weapon6", &key_weapon6, DEFAULT_KEY, 0, 0}, {"key_weapon7", &key_weapon7, DEFAULT_KEY, 0, 0}, {"key_weapon8", &key_weapon8, DEFAULT_KEY, 0, 0}, + {"key_prevweapon", &key_prevweapon, DEFAULT_KEY, 0, 0}, + {"key_nextweapon", &key_nextweapon, DEFAULT_KEY, 0, 0}, {"key_message_refresh", &key_message_refresh, DEFAULT_KEY, 0, 0}, {"key_demo_quit", &key_demo_quit, DEFAULT_KEY, 0, 0}, {"key_multi_msg", &key_multi_msg, DEFAULT_KEY, 0, 0}, diff --git a/setup/joystick.c b/setup/joystick.c index 867fa5c2..825cd8b5 100644 --- a/setup/joystick.c +++ b/setup/joystick.c @@ -50,6 +50,8 @@ int joybuse = 2; int joybspeed = 3; int joybstrafeleft = -1; int joybstraferight = -1; +int joybprevweapon = -1; +int joybnextweapon = -1; // Joystick to use, as an SDL joystick index: @@ -430,6 +432,8 @@ void ConfigJoystick(void) AddJoystickControl(button_table, "Strafe Left", &joybstrafeleft); AddJoystickControl(button_table, "Strafe Right", &joybstraferight); + AddJoystickControl(button_table, "Previous weapon", &joybprevweapon); + AddJoystickControl(button_table, "Next weapon", &joybnextweapon); TXT_SignalConnect(joystick_button, "pressed", CalibrateJoystick, NULL); TXT_SignalConnect(window, "closed", JoystickWindowClosed, NULL); diff --git a/setup/joystick.h b/setup/joystick.h index 39cf0bf4..5d3973c5 100644 --- a/setup/joystick.h +++ b/setup/joystick.h @@ -29,6 +29,8 @@ extern int joybuse; extern int joybspeed; extern int joybstrafeleft; extern int joybstraferight; +extern int joybprevweapon; +extern int joybnextweapon; extern int joystick_index; extern int joystick_x_axis; diff --git a/setup/keyboard.c b/setup/keyboard.c index bcf5ec7a..81976f85 100644 --- a/setup/keyboard.c +++ b/setup/keyboard.c @@ -90,6 +90,8 @@ int key_weapon5 = '5'; int key_weapon6 = '6'; int key_weapon7 = '7'; int key_weapon8 = '8'; +int key_prevweapon = 0; +int key_nextweapon = 0; int key_message_refresh = KEY_ENTER; int key_demo_quit = 'q'; @@ -109,7 +111,8 @@ static int *controls[] = { &key_left, &key_right, &key_up, &key_down, &key_pause, &key_weapon1, &key_weapon2, &key_weapon3, &key_weapon4, &key_weapon5, &key_weapon6, - &key_weapon7, &key_weapon8, NULL }; + &key_weapon7, &key_weapon8, + &key_prevweapon, &key_nextweapon, NULL }; static int *menu_nav[] = { &key_menu_activate, &key_menu_up, &key_menu_down, &key_menu_left, &key_menu_right, &key_menu_back, @@ -240,6 +243,8 @@ static void OtherKeysDialog(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(unused)) AddKeyControl(table, "Weapon 6", &key_weapon6); AddKeyControl(table, "Weapon 7", &key_weapon7); AddKeyControl(table, "Weapon 8", &key_weapon8); + AddKeyControl(table, "Previous weapon", &key_prevweapon); + AddKeyControl(table, "Next weapon", &key_nextweapon); TXT_AddWidgets(table, TXT_NewStrut(0, 1), TXT_NewStrut(0, 1), diff --git a/setup/keyboard.h b/setup/keyboard.h index f934116f..73510861 100644 --- a/setup/keyboard.h +++ b/setup/keyboard.h @@ -95,6 +95,8 @@ extern int key_weapon5; extern int key_weapon6; extern int key_weapon7; extern int key_weapon8; +extern int key_prevweapon; +extern int key_nextweapon; extern int key_message_refresh; extern int key_demo_quit; diff --git a/setup/mouse.c b/setup/mouse.c index 49266d48..559231b0 100644 --- a/setup/mouse.c +++ b/setup/mouse.c @@ -44,6 +44,8 @@ int mousebstrafeleft = -1; int mousebstraferight = -1; int mousebbackward = -1; int mousebuse = -1; +int mousebprevweapon = -1; +int mousebnextweapon = -1; int dclick_use = 1; @@ -55,6 +57,8 @@ static int *all_mouse_buttons[] = { &mousebstraferight, &mousebbackward, &mousebuse, + &mousebprevweapon, + &mousebnextweapon }; static void MouseSetCallback(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(variable)) @@ -104,6 +108,8 @@ static void ConfigExtraButtons(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(unused)) AddMouseControl(buttons_table, "Use", &mousebuse); AddMouseControl(buttons_table, "Strafe left", &mousebstrafeleft); AddMouseControl(buttons_table, "Strafe right", &mousebstraferight); + AddMouseControl(buttons_table, "Previous weapon", &mousebprevweapon); + AddMouseControl(buttons_table, "Next weapon", &mousebnextweapon); } void ConfigMouse(void) diff --git a/setup/mouse.h b/setup/mouse.h index f0a39ade..48270caa 100644 --- a/setup/mouse.h +++ b/setup/mouse.h @@ -37,6 +37,8 @@ extern int mousebstraferight; extern int mousebbackward; extern int mousebuse; extern int dclick_use; +extern int mousebprevweapon; +extern int mousebnextweapon; void ConfigMouse(void); diff --git a/setup/txt_keyinput.c b/setup/txt_keyinput.c index e385cc59..483c325f 100644 --- a/setup/txt_keyinput.c +++ b/setup/txt_keyinput.c @@ -111,7 +111,7 @@ static void TXT_KeyInputDrawer(TXT_UNCAST_ARG(key_input), int selected) if (*key_input->variable == 0) { - strcpy(buf, ""); + strcpy(buf, "(none)"); } else { diff --git a/src/g_game.c b/src/g_game.c index 1e163716..bf9560db 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -198,6 +198,9 @@ int mousebstraferight = -1; int mousebbackward = -1; int mousebuse = -1; +int mousebprevweapon = -1; +int mousebnextweapon = -1; + // Control whether if a mouse button is double clicked, it acts like // "use" has been pressed @@ -210,6 +213,9 @@ int joybspeed = 2; int joybstrafeleft = -1; int joybstraferight = -1; +int joybprevweapon = -1; +int joybnextweapon = -1; + // fraggle: 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 @@ -262,11 +268,13 @@ static const struct #define SLOWTURNTICS 6 #define NUMKEYS 256 +#define MAX_JOY_BUTTONS 20 +#define MAX_MOUSE_BUTTONS 3 static boolean gamekeydown[NUMKEYS]; static int turnheld; // for accelerative turning -static boolean mousearray[4]; +static boolean mousearray[MAX_MOUSE_BUTTONS + 1]; static boolean *mousebuttons = &mousearray[1]; // allow [-1] // mouse values are used once @@ -280,8 +288,6 @@ static int dclicktime2; static boolean dclickstate2; static int dclicks2; -#define MAX_JOY_BUTTONS 20 - // joystick values are repeated static int joyxmove; static int joyymove; @@ -815,7 +821,6 @@ void G_DoLoadLevel (void) players[consoleplayer].message = "Press escape to quit."; } } - static void SetJoyButtons(unsigned int buttons_mask) { @@ -823,10 +828,54 @@ static void SetJoyButtons(unsigned int buttons_mask) for (i=0; idata1 & 1; - mousebuttons[1] = ev->data1 & 2; - mousebuttons[2] = ev->data1 & 4; + SetMouseButtons(ev->data1); mousex = ev->data2*(mouseSensitivity+5)/10; mousey = ev->data3*(mouseSensitivity+5)/10; return true; // eat events diff --git a/src/m_config.c b/src/m_config.c index b2e52e7f..2065700e 100644 --- a/src/m_config.c +++ b/src/m_config.c @@ -148,6 +148,8 @@ extern int key_weapon5; extern int key_weapon6; extern int key_weapon7; extern int key_weapon8; +extern int key_prevweapon; +extern int key_nextweapon; extern int key_message_refresh; extern int key_demo_quit; @@ -164,6 +166,9 @@ extern int mousebstraferight; extern int mousebbackward; extern int mousebuse; +extern int mousebprevweapon; +extern int mousebnextweapon; + extern int dclick_use; extern int joybfire; @@ -173,6 +178,9 @@ extern int joybspeed; extern int joybstrafeleft; extern int joybstraferight; +extern int joybprevweapon; +extern int joybnextweapon; + extern int viewwidth; extern int viewheight; @@ -747,6 +755,18 @@ static default_t extra_defaults_list[] = CONFIG_VARIABLE_INT(joyb_straferight, joybstraferight), + //! + // Joystick button to cycle to the previous weapon. + // + + CONFIG_VARIABLE_INT(joyb_prevweapon, joybprevweapon), + + //! + // Joystick button to cycle to the next weapon. + // + + CONFIG_VARIABLE_INT(joyb_nextweapon, joybnextweapon), + //! // Mouse button to strafe left. // @@ -771,6 +791,18 @@ static default_t extra_defaults_list[] = CONFIG_VARIABLE_INT(mouseb_backward, mousebbackward), + //! + // Mouse button to cycle to the previous weapon. + // + + CONFIG_VARIABLE_INT(mouseb_prevweapon, mousebprevweapon), + + //! + // Mouse button to cycle to the next weapon. + // + + CONFIG_VARIABLE_INT(mouseb_nextweapon, mousebnextweapon), + //! // 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. @@ -1061,6 +1093,18 @@ static default_t extra_defaults_list[] = CONFIG_VARIABLE_KEY(key_weapon8, key_weapon8), + //! + // Key to cycle to the previous weapon. + // + + CONFIG_VARIABLE_KEY(key_prevweapon, key_prevweapon), + + //! + // Key to cycle to the next weapon. + // + + CONFIG_VARIABLE_KEY(key_nextweapon, key_nextweapon), + //! // Key to re-display last message. // -- cgit v1.2.3 From 6ebf557c44b11a16ff15e5f560a81753be33bad3 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Fri, 13 Aug 2010 18:42:52 +0000 Subject: Add C-converted version of DOSbox OPL emulator. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1955 --- opl/dbopl.c | 1603 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ opl/dbopl.h | 196 ++++++++ 2 files changed, 1799 insertions(+) create mode 100644 opl/dbopl.c create mode 100644 opl/dbopl.h diff --git a/opl/dbopl.c b/opl/dbopl.c new file mode 100644 index 00000000..556c570d --- /dev/null +++ b/opl/dbopl.c @@ -0,0 +1,1603 @@ +/* + * Copyright (C) 2002-2010 The DOSBox Team + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +// +// Chocolate Doom-related discussion: +// +// This is the DosBox OPL emulator code (src/hardware/dbopl.cpp) r3635, +// converted to C. The bulk of the work was done using the minus-minus +// script in the Chocolate Doom SVN repository, then the result tweaked +// by hand until working. +// + + +/* + DOSBox implementation of a combined Yamaha YMF262 and Yamaha YM3812 emulator. + Enabling the opl3 bit will switch the emulator to stereo opl3 output instead of regular mono opl2 + Except for the table generation it's all integer math + Can choose different types of generators, using muls and bigger tables, try different ones for slower platforms + The generation was based on the MAME implementation but tried to have it use less memory and be faster in general + MAME uses much bigger envelope tables and this will be the biggest cause of it sounding different at times + + //TODO Don't delay first operator 1 sample in opl3 mode + //TODO Maybe not use class method pointers but a regular function pointers with operator as first parameter + //TODO Fix panning for the Percussion channels, would any opl3 player use it and actually really change it though? + //TODO Check if having the same accuracy in all frequency multipliers sounds better or not + + //DUNNO Keyon in 4op, switch to 2op without keyoff. +*/ + +/* $Id: dbopl.cpp,v 1.10 2009-06-10 19:54:51 harekiet Exp $ */ + + +#include +#include +#include +//#include "dosbox.h" +#include "dbopl.h" + + +#define GCC_UNLIKELY(x) x + +#define TRUE 1 +#define FALSE 0 + +#ifndef PI +#define PI 3.14159265358979323846 +#endif + +#define OPLRATE ((double)(14318180.0 / 288.0)) +#define TREMOLO_TABLE 52 + +//Try to use most precision for frequencies +//Else try to keep different waves in synch +//#define WAVE_PRECISION 1 +#ifndef WAVE_PRECISION +//Wave bits available in the top of the 32bit range +//Original adlib uses 10.10, we use 10.22 +#define WAVE_BITS 10 +#else +//Need some extra bits at the top to have room for octaves and frequency multiplier +//We support to 8 times lower rate +//128 * 15 * 8 = 15350, 2^13.9, so need 14 bits +#define WAVE_BITS 14 +#endif +#define WAVE_SH ( 32 - WAVE_BITS ) +#define WAVE_MASK ( ( 1 << WAVE_SH ) - 1 ) + +//Use the same accuracy as the waves +#define LFO_SH ( WAVE_SH - 10 ) +//LFO is controlled by our tremolo 256 sample limit +#define LFO_MAX ( 256 << ( LFO_SH ) ) + + +//Maximum amount of attenuation bits +//Envelope goes to 511, 9 bits +#if (DBOPL_WAVE == WAVE_TABLEMUL ) +//Uses the value directly +#define ENV_BITS ( 9 ) +#else +//Add 3 bits here for more accuracy and would have to be shifted up either way +#define ENV_BITS ( 9 ) +#endif +//Limits of the envelope with those bits and when the envelope goes silent +#define ENV_MIN 0 +#define ENV_EXTRA ( ENV_BITS - 9 ) +#define ENV_MAX ( 511 << ENV_EXTRA ) +#define ENV_LIMIT ( ( 12 * 256) >> ( 3 - ENV_EXTRA ) ) +#define ENV_SILENT( _X_ ) ( (_X_) >= ENV_LIMIT ) + +//Attack/decay/release rate counter shift +#define RATE_SH 24 +#define RATE_MASK ( ( 1 << RATE_SH ) - 1 ) +//Has to fit within 16bit lookuptable +#define MUL_SH 16 + +//Check some ranges +#if ENV_EXTRA > 3 +#error Too many envelope bits +#endif + +static inline void Operator__SetState(Operator *self, Bit8u s ); +static inline Bit32u Chip__ForwardNoise(Chip *self); + +// C++'s template<> sure is useful sometimes. + +static Channel* Channel__BlockTemplate(Channel *self, Chip* chip, + Bit32u samples, Bit32s* output, + SynthMode mode ); +#define BLOCK_TEMPLATE(mode) \ + static Channel* Channel__BlockTemplate_ ## mode(Channel *self, Chip* chip, \ + Bit32u samples, Bit32s* output) \ + { \ + return Channel__BlockTemplate(self, chip, samples, output, mode); \ + } + +BLOCK_TEMPLATE(sm2AM) +BLOCK_TEMPLATE(sm2FM) +BLOCK_TEMPLATE(sm3AM) +BLOCK_TEMPLATE(sm3FM) +BLOCK_TEMPLATE(sm3FMFM) +BLOCK_TEMPLATE(sm3AMFM) +BLOCK_TEMPLATE(sm3FMAM) +BLOCK_TEMPLATE(sm3AMAM) +BLOCK_TEMPLATE(sm2Percussion) +BLOCK_TEMPLATE(sm3Percussion) + +//How much to substract from the base value for the final attenuation +static const Bit8u KslCreateTable[16] = { + //0 will always be be lower than 7 * 8 + 64, 32, 24, 19, + 16, 12, 11, 10, + 8, 6, 5, 4, + 3, 2, 1, 0, +}; + +#define M(_X_) ((Bit8u)( (_X_) * 2)) +static const Bit8u FreqCreateTable[16] = { + M(0.5), M(1 ), M(2 ), M(3 ), M(4 ), M(5 ), M(6 ), M(7 ), + M(8 ), M(9 ), M(10), M(10), M(12), M(12), M(15), M(15) +}; +#undef M + +//We're not including the highest attack rate, that gets a special value +static const Bit8u AttackSamplesTable[13] = { + 69, 55, 46, 40, + 35, 29, 23, 20, + 19, 15, 11, 10, + 9 +}; +//On a real opl these values take 8 samples to reach and are based upon larger tables +static const Bit8u EnvelopeIncreaseTable[13] = { + 4, 5, 6, 7, + 8, 10, 12, 14, + 16, 20, 24, 28, + 32, +}; + +#if ( DBOPL_WAVE == WAVE_HANDLER ) || ( DBOPL_WAVE == WAVE_TABLELOG ) +static Bit16u ExpTable[ 256 ]; +#endif + +#if ( DBOPL_WAVE == WAVE_HANDLER ) +//PI table used by WAVEHANDLER +static Bit16u SinTable[ 512 ]; +#endif + +#if ( DBOPL_WAVE > WAVE_HANDLER ) +//Layout of the waveform table in 512 entry intervals +//With overlapping waves we reduce the table to half it's size + +// | |//\\|____|WAV7|//__|/\ |____|/\/\| +// |\\//| | |WAV7| | \/| | | +// |06 |0126|17 |7 |3 |4 |4 5 |5 | + +//6 is just 0 shifted and masked + +static Bit16s WaveTable[ 8 * 512 ]; +//Distance into WaveTable the wave starts +static const Bit16u WaveBaseTable[8] = { + 0x000, 0x200, 0x200, 0x800, + 0xa00, 0xc00, 0x100, 0x400, + +}; +//Mask the counter with this +static const Bit16u WaveMaskTable[8] = { + 1023, 1023, 511, 511, + 1023, 1023, 512, 1023, +}; + +//Where to start the counter on at keyon +static const Bit16u WaveStartTable[8] = { + 512, 0, 0, 0, + 0, 512, 512, 256, +}; +#endif + +#if ( DBOPL_WAVE == WAVE_TABLEMUL ) +static Bit16u MulTable[ 384 ]; +#endif + +static Bit8u KslTable[ 8 * 16 ]; +static Bit8u TremoloTable[ TREMOLO_TABLE ]; +//Start of a channel behind the chip struct start +static Bit16u ChanOffsetTable[32]; +//Start of an operator behind the chip struct start +static Bit16u OpOffsetTable[64]; + +//The lower bits are the shift of the operator vibrato value +//The highest bit is right shifted to generate -1 or 0 for negation +//So taking the highest input value of 7 this gives 3, 7, 3, 0, -3, -7, -3, 0 +static const Bit8s VibratoTable[ 8 ] = { + 1 - 0x00, 0 - 0x00, 1 - 0x00, 30 - 0x00, + 1 - 0x80, 0 - 0x80, 1 - 0x80, 30 - 0x80 +}; + +//Shift strength for the ksl value determined by ksl strength +static const Bit8u KslShiftTable[4] = { + 31,1,2,0 +}; + +//Generate a table index and table shift value using input value from a selected rate +static void EnvelopeSelect( Bit8u val, Bit8u *index, Bit8u *shift ) { + if ( val < 13 * 4 ) { //Rate 0 - 12 + *shift = 12 - ( val >> 2 ); + *index = val & 3; + } else if ( val < 15 * 4 ) { //rate 13 - 14 + *shift = 0; + *index = val - 12 * 4; + } else { //rate 15 and up + *shift = 0; + *index = 12; + } +} + +#if ( DBOPL_WAVE == WAVE_HANDLER ) +/* + Generate the different waveforms out of the sine/exponetial table using handlers +*/ +static inline Bits MakeVolume( Bitu wave, Bitu volume ) { + Bitu total = wave + volume; + Bitu index = total & 0xff; + Bitu sig = ExpTable[ index ]; + Bitu exp = total >> 8; +#if 0 + //Check if we overflow the 31 shift limit + if ( exp >= 32 ) { + LOG_MSG( "WTF %d %d", total, exp ); + } +#endif + return (sig >> exp); +}; + +static Bits DB_FASTCALL WaveForm0( Bitu i, Bitu volume ) { + Bits neg = 0 - (( i >> 9) & 1);//Create ~0 or 0 + Bitu wave = SinTable[i & 511]; + return (MakeVolume( wave, volume ) ^ neg) - neg; +} +static Bits DB_FASTCALL WaveForm1( Bitu i, Bitu volume ) { + Bit32u wave = SinTable[i & 511]; + wave |= ( ( (i ^ 512 ) & 512) - 1) >> ( 32 - 12 ); + return MakeVolume( wave, volume ); +} +static Bits DB_FASTCALL WaveForm2( Bitu i, Bitu volume ) { + Bitu wave = SinTable[i & 511]; + return MakeVolume( wave, volume ); +} +static Bits DB_FASTCALL WaveForm3( Bitu i, Bitu volume ) { + Bitu wave = SinTable[i & 255]; + wave |= ( ( (i ^ 256 ) & 256) - 1) >> ( 32 - 12 ); + return MakeVolume( wave, volume ); +} +static Bits DB_FASTCALL WaveForm4( Bitu i, Bitu volume ) { + //Twice as fast + i <<= 1; + Bits neg = 0 - (( i >> 9) & 1);//Create ~0 or 0 + Bitu wave = SinTable[i & 511]; + wave |= ( ( (i ^ 512 ) & 512) - 1) >> ( 32 - 12 ); + return (MakeVolume( wave, volume ) ^ neg) - neg; +} +static Bits DB_FASTCALL WaveForm5( Bitu i, Bitu volume ) { + //Twice as fast + i <<= 1; + Bitu wave = SinTable[i & 511]; + wave |= ( ( (i ^ 512 ) & 512) - 1) >> ( 32 - 12 ); + return MakeVolume( wave, volume ); +} +static Bits DB_FASTCALL WaveForm6( Bitu i, Bitu volume ) { + Bits neg = 0 - (( i >> 9) & 1);//Create ~0 or 0 + return (MakeVolume( 0, volume ) ^ neg) - neg; +} +static Bits DB_FASTCALL WaveForm7( Bitu i, Bitu volume ) { + //Negative is reversed here + Bits neg = (( i >> 9) & 1) - 1; + Bitu wave = (i << 3); + //When negative the volume also runs backwards + wave = ((wave ^ neg) - neg) & 4095; + return (MakeVolume( wave, volume ) ^ neg) - neg; +} + +static const WaveHandler WaveHandlerTable[8] = { + WaveForm0, WaveForm1, WaveForm2, WaveForm3, + WaveForm4, WaveForm5, WaveForm6, WaveForm7 +}; + +#endif + +/* + Operator +*/ + +//We zero out when rate == 0 +inline void Operator__UpdateAttack(Operator *self, const Chip* chip ) { + Bit8u rate = self->reg60 >> 4; + if ( rate ) { + Bit8u val = (rate << 2) + self->ksr; + self->attackAdd = chip->attackRates[ val ]; + self->rateZero &= ~(1 << ATTACK); + } else { + self->attackAdd = 0; + self->rateZero |= (1 << ATTACK); + } +} +inline void Operator__UpdateDecay(Operator *self, const Chip* chip ) { + Bit8u rate = self->reg60 & 0xf; + if ( rate ) { + Bit8u val = (rate << 2) + self->ksr; + self->decayAdd = chip->linearRates[ val ]; + self->rateZero &= ~(1 << DECAY); + } else { + self->decayAdd = 0; + self->rateZero |= (1 << DECAY); + } +} +inline void Operator__UpdateRelease(Operator *self, const Chip* chip ) { + Bit8u rate = self->reg80 & 0xf; + if ( rate ) { + Bit8u val = (rate << 2) + self->ksr; + self->releaseAdd = chip->linearRates[ val ]; + self->rateZero &= ~(1 << RELEASE); + if ( !(self->reg20 & MASK_SUSTAIN ) ) { + self->rateZero &= ~( 1 << SUSTAIN ); + } + } else { + self->rateZero |= (1 << RELEASE); + self->releaseAdd = 0; + if ( !(self->reg20 & MASK_SUSTAIN ) ) { + self->rateZero |= ( 1 << SUSTAIN ); + } + } +} + +inline void Operator__UpdateAttenuation(Operator *self) { + Bit8u kslBase = (Bit8u)((self->chanData >> SHIFT_KSLBASE) & 0xff); + Bit32u tl = self->reg40 & 0x3f; + Bit8u kslShift = KslShiftTable[ self->reg40 >> 6 ]; + //Make sure the attenuation goes to the right bits + self->totalLevel = tl << ( ENV_BITS - 7 ); //Total level goes 2 bits below max + self->totalLevel += ( kslBase << ENV_EXTRA ) >> kslShift; +} + +void Operator__UpdateFrequency(Operator *self) { + Bit32u freq = self->chanData & (( 1 << 10 ) - 1); + Bit32u block = (self->chanData >> 10) & 0xff; +#ifdef WAVE_PRECISION + block = 7 - block; + self->waveAdd = ( freq * self->freqMul ) >> block; +#else + self->waveAdd = ( freq << block ) * self->freqMul; +#endif + if ( self->reg20 & MASK_VIBRATO ) { + self->vibStrength = (Bit8u)(freq >> 7); + +#ifdef WAVE_PRECISION + self->vibrato = ( self->vibStrength * self->freqMul ) >> block; +#else + self->vibrato = ( self->vibStrength << block ) * self->freqMul; +#endif + } else { + self->vibStrength = 0; + self->vibrato = 0; + } +} + +void Operator__UpdateRates(Operator *self, const Chip* chip ) { + //Mame seems to reverse this where enabling ksr actually lowers + //the rate, but pdf manuals says otherwise? + Bit8u newKsr = (Bit8u)((self->chanData >> SHIFT_KEYCODE) & 0xff); + if ( !( self->reg20 & MASK_KSR ) ) { + newKsr >>= 2; + } + if ( self->ksr == newKsr ) + return; + self->ksr = newKsr; + Operator__UpdateAttack( self, chip ); + Operator__UpdateDecay( self, chip ); + Operator__UpdateRelease( self, chip ); +} + +static inline Bit32s Operator__RateForward(Operator *self, Bit32u add ) { + self->rateIndex += add; + Bit32s ret = self->rateIndex >> RATE_SH; + self->rateIndex = self->rateIndex & RATE_MASK; + return ret; +} + +static Bits Operator__TemplateVolume(Operator *self, OperatorState yes) { + Bit32s vol = self->volume; + Bit32s change; + switch ( yes ) { + case OFF: + return ENV_MAX; + case ATTACK: + change = Operator__RateForward( self, self->attackAdd ); + if ( !change ) + return vol; + vol += ( (~vol) * change ) >> 3; + if ( vol < ENV_MIN ) { + self->volume = ENV_MIN; + self->rateIndex = 0; + Operator__SetState( self, DECAY ); + return ENV_MIN; + } + break; + case DECAY: + vol += Operator__RateForward( self, self->decayAdd ); + if ( GCC_UNLIKELY(vol >= self->sustainLevel) ) { + //Check if we didn't overshoot max attenuation, then just go off + if ( GCC_UNLIKELY(vol >= ENV_MAX) ) { + self->volume = ENV_MAX; + Operator__SetState( self, OFF ); + return ENV_MAX; + } + //Continue as sustain + self->rateIndex = 0; + Operator__SetState( self, SUSTAIN ); + } + break; + case SUSTAIN: + if ( self->reg20 & MASK_SUSTAIN ) { + return vol; + } + //In sustain phase, but not sustaining, do regular release + case RELEASE: + vol += Operator__RateForward( self, self->releaseAdd );; + if ( GCC_UNLIKELY(vol >= ENV_MAX) ) { + self->volume = ENV_MAX; + Operator__SetState( self, OFF ); + return ENV_MAX; + } + break; + } + self->volume = vol; + return vol; +} + +#define TEMPLATE_VOLUME(mode) \ + static Bits Operator__TemplateVolume ## mode(Operator *self) \ + { \ + return Operator__TemplateVolume(self, mode); \ + } + +TEMPLATE_VOLUME(OFF) +TEMPLATE_VOLUME(RELEASE) +TEMPLATE_VOLUME(SUSTAIN) +TEMPLATE_VOLUME(ATTACK) +TEMPLATE_VOLUME(DECAY) + +static const VolumeHandler VolumeHandlerTable[5] = { + &Operator__TemplateVolumeOFF, + &Operator__TemplateVolumeRELEASE, + &Operator__TemplateVolumeSUSTAIN, + &Operator__TemplateVolumeDECAY, + &Operator__TemplateVolumeATTACK, +}; + +static inline Bitu Operator__ForwardVolume(Operator *self) { + return self->currentLevel + (self->volHandler)(); +} + + +static inline Bitu Operator__ForwardWave(Operator *self) { + self->waveIndex += self->waveCurrent; + return self->waveIndex >> WAVE_SH; +} + +void Operator__Write20(Operator *self, const Chip* chip, Bit8u val ) { + Bit8u change = (self->reg20 ^ val ); + if ( !change ) + return; + self->reg20 = val; + //Shift the tremolo bit over the entire register, saved a branch, YES! + self->tremoloMask = (Bit8s)(val) >> 7; + self->tremoloMask &= ~(( 1 << ENV_EXTRA ) -1); + //Update specific features based on changes + if ( change & MASK_KSR ) { + Operator__UpdateRates( self, chip ); + } + //With sustain enable the volume doesn't change + if ( self->reg20 & MASK_SUSTAIN || ( !self->releaseAdd ) ) { + self->rateZero |= ( 1 << SUSTAIN ); + } else { + self->rateZero &= ~( 1 << SUSTAIN ); + } + //Frequency multiplier or vibrato changed + if ( change & (0xf | MASK_VIBRATO) ) { + self->freqMul = chip->freqMul[ val & 0xf ]; + Operator__UpdateFrequency(self); + } +} + +void Operator__Write40(Operator *self, const Chip *chip, Bit8u val ) { + if (!(self->reg40 ^ val )) + return; + self->reg40 = val; + Operator__UpdateAttenuation( self ); +} + +void Operator__Write60(Operator *self, const Chip* chip, Bit8u val ) { + Bit8u change = self->reg60 ^ val; + self->reg60 = val; + if ( change & 0x0f ) { + Operator__UpdateDecay( self, chip ); + } + if ( change & 0xf0 ) { + Operator__UpdateAttack( self, chip ); + } +} + +void Operator__Write80(Operator *self, const Chip* chip, Bit8u val ) { + Bit8u change = (self->reg80 ^ val ); + if ( !change ) + return; + self->reg80 = val; + Bit8u sustain = val >> 4; + //Turn 0xf into 0x1f + sustain |= ( sustain + 1) & 0x10; + self->sustainLevel = sustain << ( ENV_BITS - 5 ); + if ( change & 0x0f ) { + Operator__UpdateRelease( self, chip ); + } +} + +void Operator__WriteE0(Operator *self, const Chip* chip, Bit8u val ) { + if ( !(self->regE0 ^ val) ) + return; + //in opl3 mode you can always selet 7 waveforms regardless of waveformselect + Bit8u waveForm = val & ( ( 0x3 & chip->waveFormMask ) | (0x7 & chip->opl3Active ) ); + self->regE0 = val; +#if( DBOPL_WAVE == WAVE_HANDLER ) + self->waveHandler = WaveHandlerTable[ waveForm ]; +#else + self->waveBase = WaveTable + WaveBaseTable[ waveForm ]; + self->waveStart = WaveStartTable[ waveForm ] << WAVE_SH; + self->waveMask = WaveMaskTable[ waveForm ]; +#endif +} + +static inline void Operator__SetState(Operator *self, Bit8u s ) { + self->state = s; + self->volHandler = VolumeHandlerTable[ s ]; +} + +static inline int Operator__Silent(Operator *self) { + if ( !ENV_SILENT( self->totalLevel + self->volume ) ) + return FALSE; + if ( !(self->rateZero & ( 1 << self->state ) ) ) + return FALSE; + return TRUE; +} + +static inline void Operator__Prepare(Operator *self, const Chip* chip ) { + self->currentLevel = self->totalLevel + (chip->tremoloValue & self->tremoloMask); + self->waveCurrent = self->waveAdd; + if ( self->vibStrength >> chip->vibratoShift ) { + Bit32s add = self->vibrato >> chip->vibratoShift; + //Sign extend over the shift value + Bit32s neg = chip->vibratoSign; + //Negate the add with -1 or 0 + add = ( add ^ neg ) - neg; + self->waveCurrent += add; + } +} + +void Operator__KeyOn(Operator *self, Bit8u mask ) { + if ( !self->keyOn ) { + //Restart the frequency generator +#if( DBOPL_WAVE > WAVE_HANDLER ) + self->waveIndex = self->waveStart; +#else + self->waveIndex = 0; +#endif + self->rateIndex = 0; + Operator__SetState( self, ATTACK ); + } + self->keyOn |= mask; +} + +void Operator__KeyOff(Operator *self, Bit8u mask ) { + self->keyOn &= ~mask; + if ( !self->keyOn ) { + if ( self->state != OFF ) { + Operator__SetState( self, RELEASE ); + } + } +} + +static inline Bits Operator__GetWave(Operator *self, Bitu index, Bitu vol ) { +#if( DBOPL_WAVE == WAVE_HANDLER ) + return self->waveHandler( index, vol << ( 3 - ENV_EXTRA ) ); +#elif( DBOPL_WAVE == WAVE_TABLEMUL ) + return(self->waveBase[ index & self->waveMask ] * MulTable[ vol >> ENV_EXTRA ]) >> MUL_SH; +#elif( DBOPL_WAVE == WAVE_TABLELOG ) + Bit32s wave = self->waveBase[ index & self->waveMask ]; + Bit32u total = ( wave & 0x7fff ) + vol << ( 3 - ENV_EXTRA ); + Bit32s sig = ExpTable[ total & 0xff ]; + Bit32u exp = total >> 8; + Bit32s neg = wave >> 16; + return((sig ^ neg) - neg) >> exp; +#else +#error "No valid wave routine" +#endif +} + +static inline Bits Operator__GetSample(Operator *self, Bits modulation ) { + Bitu vol = Operator__ForwardVolume(self); + if ( ENV_SILENT( vol ) ) { + //Simply forward the wave + self->waveIndex += self->waveCurrent; + return 0; + } else { + Bitu index = Operator__ForwardWave(self); + index += modulation; + return Operator__GetWave( self, index, vol ); + } +} + +void Operator__Operator(Operator *self) { + self->chanData = 0; + self->freqMul = 0; + self->waveIndex = 0; + self->waveAdd = 0; + self->waveCurrent = 0; + self->keyOn = 0; + self->ksr = 0; + self->reg20 = 0; + self->reg40 = 0; + self->reg60 = 0; + self->reg80 = 0; + self->regE0 = 0; + Operator__SetState( self, OFF ); + self->rateZero = (1 << OFF); + self->sustainLevel = ENV_MAX; + self->currentLevel = ENV_MAX; + self->totalLevel = ENV_MAX; + self->volume = ENV_MAX; + self->releaseAdd = 0; +} + +/* + Channel +*/ + +void Channel__Channel(Channel *self) { + Operator__Operator(&self->op[0]); + Operator__Operator(&self->op[1]); + self->old[0] = self->old[1] = 0; + self->chanData = 0; + self->regB0 = 0; + self->regC0 = 0; + self->maskLeft = -1; + self->maskRight = -1; + self->feedback = 31; + self->fourMask = 0; + self->synthHandler = Channel__BlockTemplate_sm2FM; +}; + +static inline Operator* Channel__Op( Channel *self, Bitu index ) { + return &( ( self + (index >> 1) )->op[ index & 1 ]); +} + +void Channel__SetChanData(Channel *self, const Chip* chip, Bit32u data ) { + Bit32u change = self->chanData ^ data; + self->chanData = data; + Channel__Op( self, 0 )->chanData = data; + Channel__Op( self, 1 )->chanData = data; + //Since a frequency update triggered this, always update frequency + Operator__UpdateFrequency(Channel__Op( self, 0 )); + Operator__UpdateFrequency(Channel__Op( self, 1 )); + if ( change & ( 0xff << SHIFT_KSLBASE ) ) { + Operator__UpdateAttenuation(Channel__Op( self, 0 )); + Operator__UpdateAttenuation(Channel__Op( self, 1 )); + } + if ( change & ( 0xff << SHIFT_KEYCODE ) ) { + Operator__UpdateRates(Channel__Op( self, 0 ), chip); + Operator__UpdateRates(Channel__Op( self, 1 ), chip); + } +} + +void Channel__UpdateFrequency(Channel *self, const Chip* chip, Bit8u fourOp ) { + //Extrace the frequency bits + Bit32u data = self->chanData & 0xffff; + Bit32u kslBase = KslTable[ data >> 6 ]; + Bit32u keyCode = ( data & 0x1c00) >> 9; + if ( chip->reg08 & 0x40 ) { + keyCode |= ( data & 0x100)>>8; /* notesel == 1 */ + } else { + keyCode |= ( data & 0x200)>>9; /* notesel == 0 */ + } + //Add the keycode and ksl into the highest bits of chanData + data |= (keyCode << SHIFT_KEYCODE) | ( kslBase << SHIFT_KSLBASE ); + Channel__SetChanData( self + 0, chip, data ); + if ( fourOp & 0x3f ) { + Channel__SetChanData( self + 1, chip, data ); + } +} + +void Channel__WriteA0(Channel *self, const Chip* chip, Bit8u val ) { + Bit8u fourOp = chip->reg104 & chip->opl3Active & self->fourMask; + //Don't handle writes to silent fourop channels + if ( fourOp > 0x80 ) + return; + Bit32u change = (self->chanData ^ val ) & 0xff; + if ( change ) { + self->chanData ^= change; + Channel__UpdateFrequency( self, chip, fourOp ); + } +} + +void Channel__WriteB0(Channel *self, const Chip* chip, Bit8u val ) { + Bit8u fourOp = chip->reg104 & chip->opl3Active & self->fourMask; + //Don't handle writes to silent fourop channels + if ( fourOp > 0x80 ) + return; + Bitu change = (self->chanData ^ ( val << 8 ) ) & 0x1f00; + if ( change ) { + self->chanData ^= change; + Channel__UpdateFrequency( self, chip, fourOp ); + } + //Check for a change in the keyon/off state + if ( !(( val ^ self->regB0) & 0x20)) + return; + self->regB0 = val; + if ( val & 0x20 ) { + Operator__KeyOn( Channel__Op(self, 0), 0x1 ); + Operator__KeyOn( Channel__Op(self, 1), 0x1 ); + if ( fourOp & 0x3f ) { + Operator__KeyOn( Channel__Op(self + 1, 0), 1 ); + Operator__KeyOn( Channel__Op(self + 1, 1), 1 ); + } + } else { + Operator__KeyOff( Channel__Op(self, 0), 0x1 ); + Operator__KeyOff( Channel__Op(self, 1), 0x1 ); + if ( fourOp & 0x3f ) { + Operator__KeyOff( Channel__Op(self + 1, 0), 1 ); + Operator__KeyOff( Channel__Op(self + 1, 1), 1 ); + } + } +} + +void Channel__WriteC0(Channel *self, const Chip* chip, Bit8u val ) { + Bit8u change = val ^ self->regC0; + if ( !change ) + return; + self->regC0 = val; + self->feedback = ( val >> 1 ) & 7; + if ( self->feedback ) { + //We shift the input to the right 10 bit wave index value + self->feedback = 9 - self->feedback; + } else { + self->feedback = 31; + } + //Select the new synth mode + if ( chip->opl3Active ) { + //4-op mode enabled for this channel + if ( (chip->reg104 & self->fourMask) & 0x3f ) { + Channel* chan0, *chan1; + //Check if it's the 2nd channel in a 4-op + if ( !(self->fourMask & 0x80 ) ) { + chan0 = self; + chan1 = self + 1; + } else { + chan0 = self - 1; + chan1 = self; + } + + Bit8u synth = ( (chan0->regC0 & 1) << 0 )| (( chan1->regC0 & 1) << 1 ); + switch ( synth ) { + case 0: + chan0->synthHandler = Channel__BlockTemplate_sm3FMFM; + break; + case 1: + chan0->synthHandler = Channel__BlockTemplate_sm3AMFM; + break; + case 2: + chan0->synthHandler = Channel__BlockTemplate_sm3FMAM ; + break; + case 3: + chan0->synthHandler = Channel__BlockTemplate_sm3AMAM ; + break; + } + //Disable updating percussion channels + } else if ((self->fourMask & 0x40) && ( chip->regBD & 0x20) ) { + + //Regular dual op, am or fm + } else if ( val & 1 ) { + self->synthHandler = Channel__BlockTemplate_sm3AM; + } else { + self->synthHandler = Channel__BlockTemplate_sm3FM; + } + self->maskLeft = ( val & 0x10 ) ? -1 : 0; + self->maskRight = ( val & 0x20 ) ? -1 : 0; + //opl2 active + } else { + //Disable updating percussion channels + if ( (self->fourMask & 0x40) && ( chip->regBD & 0x20 ) ) { + + //Regular dual op, am or fm + } else if ( val & 1 ) { + self->synthHandler = Channel__BlockTemplate_sm2AM; + } else { + self->synthHandler = Channel__BlockTemplate_sm2FM; + } + } +} + +void Channel__ResetC0(Channel *self, const Chip* chip ) { + Bit8u val = self->regC0; + self->regC0 ^= 0xff; + Channel__WriteC0( self, chip, val ); +}; + +static inline void Channel__GeneratePercussion(Channel *self, Chip* chip, + Bit32s* output, int opl3Mode ) { + Channel* chan = self; + + //BassDrum + Bit32s mod = (Bit32u)((self->old[0] + self->old[1])) >> self->feedback; + self->old[0] = self->old[1]; + self->old[1] = Operator__GetSample( Channel__Op(self, 0), mod ); + + //When bassdrum is in AM mode first operator is ignoed + if ( chan->regC0 & 1 ) { + mod = 0; + } else { + mod = self->old[0]; + } + Bit32s sample = Operator__GetSample( Channel__Op(self, 1), mod ); + + //Precalculate stuff used by other outputs + Bit32u noiseBit = Chip__ForwardNoise(chip) & 0x1; + Bit32u c2 = Operator__ForwardWave(Channel__Op(self, 2)); + Bit32u c5 = Operator__ForwardWave(Channel__Op(self, 5)); + Bit32u phaseBit = (((c2 & 0x88) ^ ((c2<<5) & 0x80)) | ((c5 ^ (c5<<2)) & 0x20)) ? 0x02 : 0x00; + + //Hi-Hat + Bit32u hhVol = Operator__ForwardVolume(Channel__Op(self, 2)); + if ( !ENV_SILENT( hhVol ) ) { + Bit32u hhIndex = (phaseBit<<8) | (0x34 << ( phaseBit ^ (noiseBit << 1 ))); + sample += Operator__GetWave( Channel__Op(self, 2), hhIndex, hhVol ); + } + //Snare Drum + Bit32u sdVol = Operator__ForwardVolume( Channel__Op(self, 3) ); + if ( !ENV_SILENT( sdVol ) ) { + Bit32u sdIndex = ( 0x100 + (c2 & 0x100) ) ^ ( noiseBit << 8 ); + sample += Operator__GetWave( Channel__Op(self, 3), sdIndex, sdVol ); + } + //Tom-tom + sample += Operator__GetSample( Channel__Op(self, 4), 0 ); + + //Top-Cymbal + Bit32u tcVol = Operator__ForwardVolume(Channel__Op(self, 5)); + if ( !ENV_SILENT( tcVol ) ) { + Bit32u tcIndex = (1 + phaseBit) << 8; + sample += Operator__GetWave( Channel__Op(self, 5), tcIndex, tcVol ); + } + sample <<= 1; + if ( opl3Mode ) { + output[0] += sample; + output[1] += sample; + } else { + output[0] += sample; + } +} + +Channel* Channel__BlockTemplate(Channel *self, Chip* chip, + Bit32u samples, Bit32s* output, + SynthMode mode ) { + Bitu i; + + switch( mode ) { + case sm2AM: + case sm3AM: + if ( Operator__Silent(Channel__Op(self, 0)) + && Operator__Silent(Channel__Op(self, 1))) { + self->old[0] = self->old[1] = 0; + return(self + 1); + } + break; + case sm2FM: + case sm3FM: + if ( Operator__Silent(Channel__Op(self, 1))) { + self->old[0] = self->old[1] = 0; + return (self + 1); + } + break; + case sm3FMFM: + if ( Operator__Silent(Channel__Op(self, 3))) { + self->old[0] = self->old[1] = 0; + return (self + 2); + } + break; + case sm3AMFM: + if ( Operator__Silent( Channel__Op(self, 0) ) + && Operator__Silent( Channel__Op(self, 3) )) { + self->old[0] = self->old[1] = 0; + return (self + 2); + } + break; + case sm3FMAM: + if ( Operator__Silent( Channel__Op(self, 1)) + && Operator__Silent( Channel__Op(self, 3))) { + self->old[0] = self->old[1] = 0; + return (self + 2); + } + break; + case sm3AMAM: + if ( Operator__Silent( Channel__Op(self, 0) ) + && Operator__Silent( Channel__Op(self, 2) ) + && Operator__Silent( Channel__Op(self, 3) )) { + self->old[0] = self->old[1] = 0; + return (self + 2); + } + break; + + default: + abort(); + } + //Init the operators with the the current vibrato and tremolo values + Operator__Prepare( Channel__Op( self, 0 ), chip ); + Operator__Prepare( Channel__Op( self, 1 ), chip ); + if ( mode > sm4Start ) { + Operator__Prepare( Channel__Op( self, 2 ), chip ); + Operator__Prepare( Channel__Op( self, 3 ), chip ); + } + if ( mode > sm6Start ) { + Operator__Prepare( Channel__Op( self, 4 ), chip ); + Operator__Prepare( Channel__Op( self, 5 ), chip ); + } + for ( i = 0; i < samples; i++ ) { + //Early out for percussion handlers + if ( mode == sm2Percussion ) { + Channel__GeneratePercussion( self, chip, output + i, FALSE ); + continue; //Prevent some unitialized value bitching + } else if ( mode == sm3Percussion ) { + Channel__GeneratePercussion( self, chip, output + i * 2, TRUE ); + continue; //Prevent some unitialized value bitching + } + + //Do unsigned shift so we can shift out all bits but still stay in 10 bit range otherwise + Bit32s mod = (Bit32u)((self->old[0] + self->old[1])) >> self->feedback; + self->old[0] = self->old[1]; + self->old[1] = Operator__GetSample( Channel__Op(self, 0), mod ); + Bit32s sample; + Bit32s out0 = self->old[0]; + if ( mode == sm2AM || mode == sm3AM ) { + sample = out0 + Operator__GetSample( Channel__Op(self, 1), 0 ); + } else if ( mode == sm2FM || mode == sm3FM ) { + sample = Operator__GetSample( Channel__Op(self, 1), out0 ); + } else if ( mode == sm3FMFM ) { + Bits next = Operator__GetSample( Channel__Op(self, 1), out0 ); + next = Operator__GetSample( Channel__Op(self, 2), next ); + sample = Operator__GetSample( Channel__Op(self, 3), next ); + } else if ( mode == sm3AMFM ) { + sample = out0; + Bits next = Operator__GetSample( Channel__Op(self, 1), 0 ); + next = Operator__GetSample( Channel__Op(self, 2), next ); + sample += Operator__GetSample( Channel__Op(self, 3), next ); + } else if ( mode == sm3FMAM ) { + sample = Operator__GetSample( Channel__Op(self, 1), out0 ); + Bits next = Operator__GetSample( Channel__Op(self, 2), 0 ); + sample += Operator__GetSample( Channel__Op(self, 3), next ); + } else if ( mode == sm3AMAM ) { + sample = out0; + Bits next = Operator__GetSample( Channel__Op(self, 1), 0 ); + sample += Operator__GetSample( Channel__Op(self, 2), next ); + sample += Operator__GetSample( Channel__Op(self, 3), 0 ); + } + switch( mode ) { + case sm2AM: + case sm2FM: + output[ i ] += sample; + break; + case sm3AM: + case sm3FM: + case sm3FMFM: + case sm3AMFM: + case sm3FMAM: + case sm3AMAM: + output[ i * 2 + 0 ] += sample & self->maskLeft; + output[ i * 2 + 1 ] += sample & self->maskRight; + break; + default: + abort(); + } + } + switch( mode ) { + case sm2AM: + case sm2FM: + case sm3AM: + case sm3FM: + return ( self + 1 ); + case sm3FMFM: + case sm3AMFM: + case sm3FMAM: + case sm3AMAM: + return ( self + 2 ); + case sm2Percussion: + case sm3Percussion: + return( self + 3 ); + default: + abort(); + } + return 0; +} + +/* + Chip +*/ + +void Chip__Chip(Chip *self) { + int i; + + for (i=0; i<18; ++i) { + Channel__Channel(&self->chan[i]); + } + + self->reg08 = 0; + self->reg04 = 0; + self->regBD = 0; + self->reg104 = 0; + self->opl3Active = 0; +} + +static inline Bit32u Chip__ForwardNoise(Chip *self) { + self->noiseCounter += self->noiseAdd; + Bitu count = self->noiseCounter >> LFO_SH; + self->noiseCounter &= WAVE_MASK; + for ( ; count > 0; --count ) { + //Noise calculation from mame + self->noiseValue ^= ( 0x800302 ) & ( 0 - (self->noiseValue & 1 ) ); + self->noiseValue >>= 1; + } + return self->noiseValue; +} + +static inline Bit32u Chip__ForwardLFO(Chip *self, Bit32u samples ) { + //Current vibrato value, runs 4x slower than tremolo + self->vibratoSign = ( VibratoTable[ self->vibratoIndex >> 2] ) >> 7; + self->vibratoShift = ( VibratoTable[ self->vibratoIndex >> 2] & 7) + self->vibratoStrength; + self->tremoloValue = TremoloTable[ self->tremoloIndex ] >> self->tremoloStrength; + + //Check hom many samples there can be done before the value changes + Bit32u todo = LFO_MAX - self->lfoCounter; + Bit32u count = (todo + self->lfoAdd - 1) / self->lfoAdd; + if ( count > samples ) { + count = samples; + self->lfoCounter += count * self->lfoAdd; + } else { + self->lfoCounter += count * self->lfoAdd; + self->lfoCounter &= (LFO_MAX - 1); + //Maximum of 7 vibrato value * 4 + self->vibratoIndex = ( self->vibratoIndex + 1 ) & 31; + //Clip tremolo to the the table size + if ( self->tremoloIndex + 1 < TREMOLO_TABLE ) + ++self->tremoloIndex; + else + self->tremoloIndex = 0; + } + return count; +} + + +void Chip__WriteBD(Chip *self, Bit8u val ) { + Bit8u change = self->regBD ^ val; + if ( !change ) + return; + self->regBD = val; + //TODO could do this with shift and xor? + self->vibratoStrength = (val & 0x40) ? 0x00 : 0x01; + self->tremoloStrength = (val & 0x80) ? 0x00 : 0x02; + if ( val & 0x20 ) { + //Drum was just enabled, make sure channel 6 has the right synth + if ( change & 0x20 ) { + if ( self->opl3Active ) { + self->chan[6].synthHandler + = Channel__BlockTemplate_sm3Percussion; + } else { + self->chan[6].synthHandler + = Channel__BlockTemplate_sm2Percussion; + } + } + //Bass Drum + if ( val & 0x10 ) { + Operator__KeyOn( &self->chan[6].op[0], 0x2 ); + Operator__KeyOn( &self->chan[6].op[1], 0x2 ); + } else { + Operator__KeyOff( &self->chan[6].op[0], 0x2 ); + Operator__KeyOff( &self->chan[6].op[1], 0x2 ); + } + //Hi-Hat + if ( val & 0x1 ) { + Operator__KeyOn( &self->chan[7].op[0], 0x2 ); + } else { + Operator__KeyOff( &self->chan[7].op[0], 0x2 ); + } + //Snare + if ( val & 0x8 ) { + Operator__KeyOn( &self->chan[7].op[1], 0x2 ); + } else { + Operator__KeyOff( &self->chan[7].op[1], 0x2 ); + } + //Tom-Tom + if ( val & 0x4 ) { + Operator__KeyOn( &self->chan[8].op[0], 0x2 ); + } else { + Operator__KeyOff( &self->chan[8].op[0], 0x2 ); + } + //Top Cymbal + if ( val & 0x2 ) { + Operator__KeyOn( &self->chan[8].op[1], 0x2 ); + } else { + Operator__KeyOff( &self->chan[8].op[1], 0x2 ); + } + //Toggle keyoffs when we turn off the percussion + } else if ( change & 0x20 ) { + //Trigger a reset to setup the original synth handler + Channel__ResetC0( &self->chan[6], self ); + Operator__KeyOff( &self->chan[6].op[0], 0x2 ); + Operator__KeyOff( &self->chan[6].op[1], 0x2 ); + Operator__KeyOff( &self->chan[7].op[0], 0x2 ); + Operator__KeyOff( &self->chan[7].op[1], 0x2 ); + Operator__KeyOff( &self->chan[8].op[0], 0x2 ); + Operator__KeyOff( &self->chan[8].op[1], 0x2 ); + } +} + + +#define REGOP( _FUNC_ ) \ + index = ( ( reg >> 3) & 0x20 ) | ( reg & 0x1f ); \ + if ( OpOffsetTable[ index ] ) { \ + Operator* regOp = (Operator*)( ((char *)self ) + OpOffsetTable[ index ] ); \ + Operator__ ## _FUNC_ (regOp, self, val); \ + } + +#define REGCHAN( _FUNC_ ) \ + index = ( ( reg >> 4) & 0x10 ) | ( reg & 0xf ); \ + if ( ChanOffsetTable[ index ] ) { \ + Channel* regChan = (Channel*)( ((char *)self ) + ChanOffsetTable[ index ] ); \ + Channel__ ## _FUNC_ (regChan, self, val); \ + } + +void Chip__WriteReg(Chip *self, Bit32u reg, Bit8u val ) { + Bitu index; + switch ( (reg & 0xf0) >> 4 ) { + case 0x00 >> 4: + if ( reg == 0x01 ) { + self->waveFormMask = ( val & 0x20 ) ? 0x7 : 0x0; + } else if ( reg == 0x104 ) { + //Only detect changes in lowest 6 bits + if ( !((self->reg104 ^ val) & 0x3f) ) + return; + //Always keep the highest bit enabled, for checking > 0x80 + self->reg104 = 0x80 | ( val & 0x3f ); + } else if ( reg == 0x105 ) { + int i; + + //MAME says the real opl3 doesn't reset anything on opl3 disable/enable till the next write in another register + if ( !((self->opl3Active ^ val) & 1 ) ) + return; + self->opl3Active = ( val & 1 ) ? 0xff : 0; + //Update the 0xc0 register for all channels to signal the switch to mono/stereo handlers + for ( i = 0; i < 18;i++ ) { + Channel__ResetC0( &self->chan[i], self ); + } + } else if ( reg == 0x08 ) { + self->reg08 = val; + } + case 0x10 >> 4: + break; + case 0x20 >> 4: + case 0x30 >> 4: + REGOP( Write20 ); + break; + case 0x40 >> 4: + case 0x50 >> 4: + REGOP( Write40 ); + break; + case 0x60 >> 4: + case 0x70 >> 4: + REGOP( Write60 ); + break; + case 0x80 >> 4: + case 0x90 >> 4: + REGOP( Write80 ); + break; + case 0xa0 >> 4: + REGCHAN( WriteA0 ); + break; + case 0xb0 >> 4: + if ( reg == 0xbd ) { + Chip__WriteBD( self, val ); + } else { + REGCHAN( WriteB0 ); + } + break; + case 0xc0 >> 4: + REGCHAN( WriteC0 ); + case 0xd0 >> 4: + break; + case 0xe0 >> 4: + case 0xf0 >> 4: + REGOP( WriteE0 ); + break; + } +} + + +Bit32u Chip__WriteAddr(Chip *self, Bit32u port, Bit8u val ) { + switch ( port & 3 ) { + case 0: + return val; + case 2: + if ( self->opl3Active || (val == 0x05) ) + return 0x100 | val; + else + return val; + } + return 0; +} + +void Chip__GenerateBlock2(Chip *self, Bitu total, Bit32s* output ) { + while ( total > 0 ) { + Channel *ch; + int count; + + Bit32u samples = Chip__ForwardLFO( self, total ); + memset(output, 0, sizeof(Bit32s) * samples); + count = 0; + for ( ch = self->chan; ch < self->chan + 9; ) { + count++; + ch = (ch->synthHandler)( ch, self, samples, output ); + } + total -= samples; + output += samples; + } +} + +void Chip__GenerateBlock3(Chip *self, Bitu total, Bit32s* output ) { + while ( total > 0 ) { + int count; + Channel *ch; + + Bit32u samples = Chip__ForwardLFO( self, total ); + memset(output, 0, sizeof(Bit32s) * samples *2); + count = 0; + for ( ch = self->chan; ch < self->chan + 18; ) { + count++; + ch = (ch->synthHandler)( ch, self, samples, output ); + } + total -= samples; + output += samples * 2; + } +} + +void Chip__Setup(Chip *self, Bit32u rate ) { + double original = OPLRATE; + Bit32u i; +// double original = rate; + double scale = original / (double)rate; + + //Noise counter is run at the same precision as general waves + self->noiseAdd = (Bit32u)( 0.5 + scale * ( 1 << LFO_SH ) ); + self->noiseCounter = 0; + self->noiseValue = 1; //Make sure it triggers the noise xor the first time + //The low frequency oscillation counter + //Every time his overflows vibrato and tremoloindex are increased + self->lfoAdd = (Bit32u)( 0.5 + scale * ( 1 << LFO_SH ) ); + self->lfoCounter = 0; + self->vibratoIndex = 0; + self->tremoloIndex = 0; + + //With higher octave this gets shifted up + //-1 since the freqCreateTable = *2 +#ifdef WAVE_PRECISION + double freqScale = ( 1 << 7 ) * scale * ( 1 << ( WAVE_SH - 1 - 10)); + for ( i = 0; i < 16; i++ ) { + self->freqMul[i] = (Bit32u)( 0.5 + freqScale * FreqCreateTable[ i ] ); + } +#else + Bit32u freqScale = (Bit32u)( 0.5 + scale * ( 1 << ( WAVE_SH - 1 - 10))); + for ( i = 0; i < 16; i++ ) { + self->freqMul[i] = freqScale * FreqCreateTable[ i ]; + } +#endif + + //-3 since the real envelope takes 8 steps to reach the single value we supply + for ( i = 0; i < 76; i++ ) { + Bit8u index, shift; + EnvelopeSelect( i, &index, &shift ); + self->linearRates[i] = (Bit32u)( scale * (EnvelopeIncreaseTable[ index ] << ( RATE_SH + ENV_EXTRA - shift - 3 ))); + } + //Generate the best matching attack rate + for ( i = 0; i < 62; i++ ) { + Bit8u index, shift; + EnvelopeSelect( i, &index, &shift ); + //Original amount of samples the attack would take + Bit32s original = (Bit32u)( (AttackSamplesTable[ index ] << shift) / scale); + + Bit32s guessAdd = (Bit32u)( scale * (EnvelopeIncreaseTable[ index ] << ( RATE_SH - shift - 3 ))); + Bit32s bestAdd = guessAdd; + Bit32u bestDiff = 1 << 30; + Bit32u passes; + + for ( passes = 0; passes < 16; passes ++ ) { + Bit32s volume = ENV_MAX; + Bit32s samples = 0; + Bit32u count = 0; + while ( volume > 0 && samples < original * 2 ) { + count += guessAdd; + Bit32s change = count >> RATE_SH; + count &= RATE_MASK; + if ( GCC_UNLIKELY(change) ) { // less than 1 % + volume += ( ~volume * change ) >> 3; + } + samples++; + + } + Bit32s diff = original - samples; + Bit32u lDiff = labs( diff ); + //Init last on first pass + if ( lDiff < bestDiff ) { + bestDiff = lDiff; + bestAdd = guessAdd; + if ( !bestDiff ) + break; + } + //Below our target + if ( diff < 0 ) { + //Better than the last time + Bit32s mul = ((original - diff) << 12) / original; + guessAdd = ((guessAdd * mul) >> 12); + guessAdd++; + } else if ( diff > 0 ) { + Bit32s mul = ((original - diff) << 12) / original; + guessAdd = (guessAdd * mul) >> 12; + guessAdd--; + } + } + self->attackRates[i] = bestAdd; + } + for ( i = 62; i < 76; i++ ) { + //This should provide instant volume maximizing + self->attackRates[i] = 8 << RATE_SH; + } + //Setup the channels with the correct four op flags + //Channels are accessed through a table so they appear linear here + self->chan[ 0].fourMask = 0x00 | ( 1 << 0 ); + self->chan[ 1].fourMask = 0x80 | ( 1 << 0 ); + self->chan[ 2].fourMask = 0x00 | ( 1 << 1 ); + self->chan[ 3].fourMask = 0x80 | ( 1 << 1 ); + self->chan[ 4].fourMask = 0x00 | ( 1 << 2 ); + self->chan[ 5].fourMask = 0x80 | ( 1 << 2 ); + + self->chan[ 9].fourMask = 0x00 | ( 1 << 3 ); + self->chan[10].fourMask = 0x80 | ( 1 << 3 ); + self->chan[11].fourMask = 0x00 | ( 1 << 4 ); + self->chan[12].fourMask = 0x80 | ( 1 << 4 ); + self->chan[13].fourMask = 0x00 | ( 1 << 5 ); + self->chan[14].fourMask = 0x80 | ( 1 << 5 ); + + //mark the percussion channels + self->chan[ 6].fourMask = 0x40; + self->chan[ 7].fourMask = 0x40; + self->chan[ 8].fourMask = 0x40; + + //Clear Everything in opl3 mode + Chip__WriteReg( self, 0x105, 0x1 ); + for ( i = 0; i < 512; i++ ) { + if ( i == 0x105 ) + continue; + Chip__WriteReg( self, i, 0xff ); + Chip__WriteReg( self, i, 0x0 ); + } + Chip__WriteReg( self, 0x105, 0x0 ); + //Clear everything in opl2 mode + for ( i = 0; i < 255; i++ ) { + Chip__WriteReg( self, i, 0xff ); + Chip__WriteReg( self, i, 0x0 ); + } +} + +static int doneTables = FALSE; +void InitTables( void ) { + int i, oct; + + if ( doneTables ) + return; + doneTables = TRUE; +#if ( DBOPL_WAVE == WAVE_HANDLER ) || ( DBOPL_WAVE == WAVE_TABLELOG ) + //Exponential volume table, same as the real adlib + for ( i = 0; i < 256; i++ ) { + //Save them in reverse + ExpTable[i] = (int)( 0.5 + ( pow(2.0, ( 255 - i) * ( 1.0 /256 ) )-1) * 1024 ); + ExpTable[i] += 1024; //or remove the -1 oh well :) + //Preshift to the left once so the final volume can shift to the right + ExpTable[i] *= 2; + } +#endif +#if ( DBOPL_WAVE == WAVE_HANDLER ) + //Add 0.5 for the trunc rounding of the integer cast + //Do a PI sinetable instead of the original 0.5 PI + for ( i = 0; i < 512; i++ ) { + SinTable[i] = (Bit16s)( 0.5 - log10( sin( (i + 0.5) * (PI / 512.0) ) ) / log10(2.0)*256 ); + } +#endif +#if ( DBOPL_WAVE == WAVE_TABLEMUL ) + //Multiplication based tables + for ( i = 0; i < 384; i++ ) { + int s = i * 8; + //TODO maybe keep some of the precision errors of the original table? + double val = ( 0.5 + ( pow(2.0, -1.0 + ( 255 - s) * ( 1.0 /256 ) )) * ( 1 << MUL_SH )); + MulTable[i] = (Bit16u)(val); + } + + //Sine Wave Base + for ( i = 0; i < 512; i++ ) { + WaveTable[ 0x0200 + i ] = (Bit16s)(sin( (i + 0.5) * (PI / 512.0) ) * 4084); + WaveTable[ 0x0000 + i ] = -WaveTable[ 0x200 + i ]; + } + //Exponential wave + for ( i = 0; i < 256; i++ ) { + WaveTable[ 0x700 + i ] = (Bit16s)( 0.5 + ( pow(2.0, -1.0 + ( 255 - i * 8) * ( 1.0 /256 ) ) ) * 4085 ); + WaveTable[ 0x6ff - i ] = -WaveTable[ 0x700 + i ]; + } +#endif +#if ( DBOPL_WAVE == WAVE_TABLELOG ) + //Sine Wave Base + for ( i = 0; i < 512; i++ ) { + WaveTable[ 0x0200 + i ] = (Bit16s)( 0.5 - log10( sin( (i + 0.5) * (PI / 512.0) ) ) / log10(2.0)*256 ); + WaveTable[ 0x0000 + i ] = ((Bit16s)0x8000) | WaveTable[ 0x200 + i]; + } + //Exponential wave + for ( i = 0; i < 256; i++ ) { + WaveTable[ 0x700 + i ] = i * 8; + WaveTable[ 0x6ff - i ] = ((Bit16s)0x8000) | i * 8; + } +#endif + + // | |//\\|____|WAV7|//__|/\ |____|/\/\| + // |\\//| | |WAV7| | \/| | | + // |06 |0126|27 |7 |3 |4 |4 5 |5 | + +#if (( DBOPL_WAVE == WAVE_TABLELOG ) || ( DBOPL_WAVE == WAVE_TABLEMUL )) + for ( i = 0; i < 256; i++ ) { + //Fill silence gaps + WaveTable[ 0x400 + i ] = WaveTable[0]; + WaveTable[ 0x500 + i ] = WaveTable[0]; + WaveTable[ 0x900 + i ] = WaveTable[0]; + WaveTable[ 0xc00 + i ] = WaveTable[0]; + WaveTable[ 0xd00 + i ] = WaveTable[0]; + //Replicate sines in other pieces + WaveTable[ 0x800 + i ] = WaveTable[ 0x200 + i ]; + //double speed sines + WaveTable[ 0xa00 + i ] = WaveTable[ 0x200 + i * 2 ]; + WaveTable[ 0xb00 + i ] = WaveTable[ 0x000 + i * 2 ]; + WaveTable[ 0xe00 + i ] = WaveTable[ 0x200 + i * 2 ]; + WaveTable[ 0xf00 + i ] = WaveTable[ 0x200 + i * 2 ]; + } +#endif + + //Create the ksl table + for ( oct = 0; oct < 8; oct++ ) { + int base = oct * 8; + for ( i = 0; i < 16; i++ ) { + int val = base - KslCreateTable[i]; + if ( val < 0 ) + val = 0; + //*4 for the final range to match attenuation range + KslTable[ oct * 16 + i ] = val * 4; + } + } + //Create the Tremolo table, just increase and decrease a triangle wave + for ( i = 0; i < TREMOLO_TABLE / 2; i++ ) { + Bit8u val = i << ENV_EXTRA; + TremoloTable[i] = val; + TremoloTable[TREMOLO_TABLE - 1 - i] = val; + } + //Create a table with offsets of the channels from the start of the chip + Chip *chip = NULL; + for ( i = 0; i < 32; i++ ) { + Bitu index = i & 0xf; + if ( index >= 9 ) { + ChanOffsetTable[i] = 0; + continue; + } + //Make sure the four op channels follow eachother + if ( index < 6 ) { + index = (index % 3) * 2 + ( index / 3 ); + } + //Add back the bits for highest ones + if ( i >= 16 ) + index += 9; + Bitu blah = (Bitu) ( &(chip->chan[ index ]) ); + ChanOffsetTable[i] = blah; + } + //Same for operators + for ( i = 0; i < 64; i++ ) { + if ( i % 8 >= 6 || ( (i / 8) % 4 == 3 ) ) { + OpOffsetTable[i] = 0; + continue; + } + Bitu chNum = (i / 8) * 3 + (i % 8) % 3; + //Make sure we use 16 and up for the 2nd range to match the chanoffset gap + if ( chNum >= 12 ) + chNum += 16 - 12; + Bitu opNum = ( i % 8 ) / 3; + Channel* chan = NULL; + Bitu blah = (Bitu) ( &(chan->op[opNum]) ); + OpOffsetTable[i] = ChanOffsetTable[ chNum ] + blah; + } +#if 0 + //Stupid checks if table's are correct + for ( Bitu i = 0; i < 18; i++ ) { + Bit32u find = (Bit16u)( &(chip->chan[ i ]) ); + for ( Bitu c = 0; c < 32; c++ ) { + if ( ChanOffsetTable[c] == find ) { + find = 0; + break; + } + } + if ( find ) { + find = find; + } + } + for ( Bitu i = 0; i < 36; i++ ) { + Bit32u find = (Bit16u)( &(chip->chan[ i / 2 ].op[i % 2]) ); + for ( Bitu c = 0; c < 64; c++ ) { + if ( OpOffsetTable[c] == find ) { + find = 0; + break; + } + } + if ( find ) { + find = find; + } + } +#endif +} + +/* + +Bit32u Handler::WriteAddr( Bit32u port, Bit8u val ) { + return chip.WriteAddr( port, val ); + +} +void Handler::WriteReg( Bit32u addr, Bit8u val ) { + chip.WriteReg( addr, val ); +} + +void Handler::Generate( MixerChannel* chan, Bitu samples ) { + Bit32s buffer[ 512 * 2 ]; + if ( GCC_UNLIKELY(samples > 512) ) + samples = 512; + if ( !chip.opl3Active ) { + chip.GenerateBlock2( samples, buffer ); + chan->AddSamples_m32( samples, buffer ); + } else { + chip.GenerateBlock3( samples, buffer ); + chan->AddSamples_s32( samples, buffer ); + } +} + +void Handler::Init( Bitu rate ) { + InitTables(); + chip.Setup( rate ); +} +*/ + diff --git a/opl/dbopl.h b/opl/dbopl.h new file mode 100644 index 00000000..f7d2e416 --- /dev/null +++ b/opl/dbopl.h @@ -0,0 +1,196 @@ +/* + * Copyright (C) 2002-2010 The DOSBox Team + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include + +//Use 8 handlers based on a small logatirmic wavetabe and an exponential table for volume +#define WAVE_HANDLER 10 +//Use a logarithmic wavetable with an exponential table for volume +#define WAVE_TABLELOG 11 +//Use a linear wavetable with a multiply table for volume +#define WAVE_TABLEMUL 12 + +//Select the type of wave generator routine +#define DBOPL_WAVE WAVE_TABLEMUL + +typedef struct _Chip Chip; +typedef struct _Operator Operator; +typedef struct _Channel Channel; + +typedef uintptr_t Bitu; +typedef intptr_t Bits; +typedef uint32_t Bit32u; +typedef int32_t Bit32s; +typedef uint16_t Bit16u; +typedef int16_t Bit16s; +typedef uint8_t Bit8u; +typedef int8_t Bit8s; + +#if (DBOPL_WAVE == WAVE_HANDLER) +typedef Bits ( DB_FASTCALL *WaveHandler) ( Bitu i, Bitu volume ); +#endif + +#define DB_FASTCALL + +typedef Bits (*VolumeHandler)(); +typedef Channel* (*SynthHandler)(Channel *self, Chip* chip, Bit32u samples, Bit32s* output ); + +//Different synth modes that can generate blocks of data +typedef enum { + sm2AM, + sm2FM, + sm3AM, + sm3FM, + sm4Start, + sm3FMFM, + sm3AMFM, + sm3FMAM, + sm3AMAM, + sm6Start, + sm2Percussion, + sm3Percussion, +} SynthMode; + +//Shifts for the values contained in chandata variable +enum { + SHIFT_KSLBASE = 16, + SHIFT_KEYCODE = 24, +}; + +//Masks for operator 20 values +enum { + MASK_KSR = 0x10, + MASK_SUSTAIN = 0x20, + MASK_VIBRATO = 0x40, + MASK_TREMOLO = 0x80, +}; + +typedef enum { + OFF, + RELEASE, + SUSTAIN, + DECAY, + ATTACK, +} OperatorState; + +struct _Operator { + VolumeHandler volHandler; + +#if (DBOPL_WAVE == WAVE_HANDLER) + WaveHandler waveHandler; //Routine that generate a wave +#else + Bit16s* waveBase; + Bit32u waveMask; + Bit32u waveStart; +#endif + Bit32u waveIndex; //WAVE_BITS shifted counter of the frequency index + Bit32u waveAdd; //The base frequency without vibrato + Bit32u waveCurrent; //waveAdd + vibratao + + Bit32u chanData; //Frequency/octave and derived data coming from whatever channel controls this + Bit32u freqMul; //Scale channel frequency with this, TODO maybe remove? + Bit32u vibrato; //Scaled up vibrato strength + Bit32s sustainLevel; //When stopping at sustain level stop here + Bit32s totalLevel; //totalLevel is added to every generated volume + Bit32u currentLevel; //totalLevel + tremolo + Bit32s volume; //The currently active volume + + Bit32u attackAdd; //Timers for the different states of the envelope + Bit32u decayAdd; + Bit32u releaseAdd; + Bit32u rateIndex; //Current position of the evenlope + + Bit8u rateZero; //Bits for the different states of the envelope having no changes + Bit8u keyOn; //Bitmask of different values that can generate keyon + //Registers, also used to check for changes + Bit8u reg20, reg40, reg60, reg80, regE0; + //Active part of the envelope we're in + Bit8u state; + //0xff when tremolo is enabled + Bit8u tremoloMask; + //Strength of the vibrato + Bit8u vibStrength; + //Keep track of the calculated KSR so we can check for changes + Bit8u ksr; +}; + +struct _Channel { + Operator op[2]; + SynthHandler synthHandler; + Bit32u chanData; //Frequency/octave and derived values + Bit32s old[2]; //Old data for feedback + + Bit8u feedback; //Feedback shift + Bit8u regB0; //Register values to check for changes + Bit8u regC0; + //This should correspond with reg104, bit 6 indicates a Percussion channel, bit 7 indicates a silent channel + Bit8u fourMask; + Bit8s maskLeft; //Sign extended values for both channel's panning + Bit8s maskRight; + +}; + +struct _Chip { + //This is used as the base counter for vibrato and tremolo + Bit32u lfoCounter; + Bit32u lfoAdd; + + + Bit32u noiseCounter; + Bit32u noiseAdd; + Bit32u noiseValue; + + //Frequency scales for the different multiplications + Bit32u freqMul[16]; + //Rates for decay and release for rate of this chip + Bit32u linearRates[76]; + //Best match attack rates for the rate of this chip + Bit32u attackRates[76]; + + //18 channels with 2 operators each + Channel chan[18]; + + Bit8u reg104; + Bit8u reg08; + Bit8u reg04; + Bit8u regBD; + Bit8u vibratoIndex; + Bit8u tremoloIndex; + Bit8s vibratoSign; + Bit8u vibratoShift; + Bit8u tremoloValue; + Bit8u vibratoStrength; + Bit8u tremoloStrength; + //Mask for allowed wave forms + Bit8u waveFormMask; + //0 or -1 when enabled + Bit8s opl3Active; + +}; + +/* +struct Handler : public Adlib::Handler { + DBOPL::Chip chip; + virtual Bit32u WriteAddr( Bit32u port, Bit8u val ); + virtual void WriteReg( Bit32u addr, Bit8u val ); + virtual void Generate( MixerChannel* chan, Bitu samples ); + virtual void Init( Bitu rate ); +}; +*/ + + -- cgit v1.2.3 From 578a06c798f9b0d52f74d8bfc9258ef74a9bb6c9 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sun, 15 Aug 2010 14:57:37 +0000 Subject: Hook DBOPL into OPL library and remove FMOPL. Does not generate any sound yet. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1956 --- opl/Makefile.am | 2 +- opl/dbopl.c | 52 +-- opl/dbopl.h | 9 +- opl/fmopl.c | 1155 ------------------------------------------------------- opl/fmopl.h | 167 -------- opl/opl_sdl.c | 158 +++++--- 6 files changed, 143 insertions(+), 1400 deletions(-) delete mode 100644 opl/fmopl.c delete mode 100644 opl/fmopl.h diff --git a/opl/Makefile.am b/opl/Makefile.am index d099b875..be1619d8 100644 --- a/opl/Makefile.am +++ b/opl/Makefile.am @@ -15,5 +15,5 @@ libopl_a_SOURCES = \ opl_timer.c opl_timer.h \ opl_win32.c \ ioperm_sys.c ioperm_sys.h \ - fmopl.c fmopl.h + dbopl.c dbopl.h diff --git a/opl/dbopl.c b/opl/dbopl.c index 556c570d..a4bd6fe5 100644 --- a/opl/dbopl.c +++ b/opl/dbopl.c @@ -324,7 +324,7 @@ static const WaveHandler WaveHandlerTable[8] = { */ //We zero out when rate == 0 -inline void Operator__UpdateAttack(Operator *self, const Chip* chip ) { +static inline void Operator__UpdateAttack(Operator *self, const Chip* chip ) { Bit8u rate = self->reg60 >> 4; if ( rate ) { Bit8u val = (rate << 2) + self->ksr; @@ -335,7 +335,7 @@ inline void Operator__UpdateAttack(Operator *self, const Chip* chip ) { self->rateZero |= (1 << ATTACK); } } -inline void Operator__UpdateDecay(Operator *self, const Chip* chip ) { +static inline void Operator__UpdateDecay(Operator *self, const Chip* chip ) { Bit8u rate = self->reg60 & 0xf; if ( rate ) { Bit8u val = (rate << 2) + self->ksr; @@ -346,7 +346,7 @@ inline void Operator__UpdateDecay(Operator *self, const Chip* chip ) { self->rateZero |= (1 << DECAY); } } -inline void Operator__UpdateRelease(Operator *self, const Chip* chip ) { +static inline void Operator__UpdateRelease(Operator *self, const Chip* chip ) { Bit8u rate = self->reg80 & 0xf; if ( rate ) { Bit8u val = (rate << 2) + self->ksr; @@ -364,7 +364,7 @@ inline void Operator__UpdateRelease(Operator *self, const Chip* chip ) { } } -inline void Operator__UpdateAttenuation(Operator *self) { +static inline void Operator__UpdateAttenuation(Operator *self) { Bit8u kslBase = (Bit8u)((self->chanData >> SHIFT_KSLBASE) & 0xff); Bit32u tl = self->reg40 & 0x3f; Bit8u kslShift = KslShiftTable[ self->reg40 >> 6 ]; @@ -373,7 +373,7 @@ inline void Operator__UpdateAttenuation(Operator *self) { self->totalLevel += ( kslBase << ENV_EXTRA ) >> kslShift; } -void Operator__UpdateFrequency(Operator *self) { +static void Operator__UpdateFrequency(Operator *self) { Bit32u freq = self->chanData & (( 1 << 10 ) - 1); Bit32u block = (self->chanData >> 10) & 0xff; #ifdef WAVE_PRECISION @@ -396,7 +396,7 @@ void Operator__UpdateFrequency(Operator *self) { } } -void Operator__UpdateRates(Operator *self, const Chip* chip ) { +static void Operator__UpdateRates(Operator *self, const Chip* chip ) { //Mame seems to reverse this where enabling ksr actually lowers //the rate, but pdf manuals says otherwise? Bit8u newKsr = (Bit8u)((self->chanData >> SHIFT_KEYCODE) & 0xff); @@ -489,7 +489,7 @@ static const VolumeHandler VolumeHandlerTable[5] = { }; static inline Bitu Operator__ForwardVolume(Operator *self) { - return self->currentLevel + (self->volHandler)(); + return self->currentLevel + (self->volHandler)(self); } @@ -498,7 +498,7 @@ static inline Bitu Operator__ForwardWave(Operator *self) { return self->waveIndex >> WAVE_SH; } -void Operator__Write20(Operator *self, const Chip* chip, Bit8u val ) { +static void Operator__Write20(Operator *self, const Chip* chip, Bit8u val ) { Bit8u change = (self->reg20 ^ val ); if ( !change ) return; @@ -523,14 +523,14 @@ void Operator__Write20(Operator *self, const Chip* chip, Bit8u val ) { } } -void Operator__Write40(Operator *self, const Chip *chip, Bit8u val ) { +static void Operator__Write40(Operator *self, const Chip *chip, Bit8u val ) { if (!(self->reg40 ^ val )) return; self->reg40 = val; Operator__UpdateAttenuation( self ); } -void Operator__Write60(Operator *self, const Chip* chip, Bit8u val ) { +static void Operator__Write60(Operator *self, const Chip* chip, Bit8u val ) { Bit8u change = self->reg60 ^ val; self->reg60 = val; if ( change & 0x0f ) { @@ -541,7 +541,7 @@ void Operator__Write60(Operator *self, const Chip* chip, Bit8u val ) { } } -void Operator__Write80(Operator *self, const Chip* chip, Bit8u val ) { +static void Operator__Write80(Operator *self, const Chip* chip, Bit8u val ) { Bit8u change = (self->reg80 ^ val ); if ( !change ) return; @@ -555,7 +555,7 @@ void Operator__Write80(Operator *self, const Chip* chip, Bit8u val ) { } } -void Operator__WriteE0(Operator *self, const Chip* chip, Bit8u val ) { +static void Operator__WriteE0(Operator *self, const Chip* chip, Bit8u val ) { if ( !(self->regE0 ^ val) ) return; //in opl3 mode you can always selet 7 waveforms regardless of waveformselect @@ -596,7 +596,7 @@ static inline void Operator__Prepare(Operator *self, const Chip* chip ) { } } -void Operator__KeyOn(Operator *self, Bit8u mask ) { +static void Operator__KeyOn(Operator *self, Bit8u mask ) { if ( !self->keyOn ) { //Restart the frequency generator #if( DBOPL_WAVE > WAVE_HANDLER ) @@ -610,7 +610,7 @@ void Operator__KeyOn(Operator *self, Bit8u mask ) { self->keyOn |= mask; } -void Operator__KeyOff(Operator *self, Bit8u mask ) { +static void Operator__KeyOff(Operator *self, Bit8u mask ) { self->keyOn &= ~mask; if ( !self->keyOn ) { if ( self->state != OFF ) { @@ -649,7 +649,7 @@ static inline Bits Operator__GetSample(Operator *self, Bits modulation ) { } } -void Operator__Operator(Operator *self) { +static void Operator__Operator(Operator *self) { self->chanData = 0; self->freqMul = 0; self->waveIndex = 0; @@ -675,7 +675,7 @@ void Operator__Operator(Operator *self) { Channel */ -void Channel__Channel(Channel *self) { +static void Channel__Channel(Channel *self) { Operator__Operator(&self->op[0]); Operator__Operator(&self->op[1]); self->old[0] = self->old[1] = 0; @@ -693,7 +693,7 @@ static inline Operator* Channel__Op( Channel *self, Bitu index ) { return &( ( self + (index >> 1) )->op[ index & 1 ]); } -void Channel__SetChanData(Channel *self, const Chip* chip, Bit32u data ) { +static void Channel__SetChanData(Channel *self, const Chip* chip, Bit32u data ) { Bit32u change = self->chanData ^ data; self->chanData = data; Channel__Op( self, 0 )->chanData = data; @@ -711,7 +711,7 @@ void Channel__SetChanData(Channel *self, const Chip* chip, Bit32u data ) { } } -void Channel__UpdateFrequency(Channel *self, const Chip* chip, Bit8u fourOp ) { +static void Channel__UpdateFrequency(Channel *self, const Chip* chip, Bit8u fourOp ) { //Extrace the frequency bits Bit32u data = self->chanData & 0xffff; Bit32u kslBase = KslTable[ data >> 6 ]; @@ -729,7 +729,7 @@ void Channel__UpdateFrequency(Channel *self, const Chip* chip, Bit8u fourOp ) { } } -void Channel__WriteA0(Channel *self, const Chip* chip, Bit8u val ) { +static void Channel__WriteA0(Channel *self, const Chip* chip, Bit8u val ) { Bit8u fourOp = chip->reg104 & chip->opl3Active & self->fourMask; //Don't handle writes to silent fourop channels if ( fourOp > 0x80 ) @@ -741,7 +741,7 @@ void Channel__WriteA0(Channel *self, const Chip* chip, Bit8u val ) { } } -void Channel__WriteB0(Channel *self, const Chip* chip, Bit8u val ) { +static void Channel__WriteB0(Channel *self, const Chip* chip, Bit8u val ) { Bit8u fourOp = chip->reg104 & chip->opl3Active & self->fourMask; //Don't handle writes to silent fourop channels if ( fourOp > 0x80 ) @@ -772,7 +772,7 @@ void Channel__WriteB0(Channel *self, const Chip* chip, Bit8u val ) { } } -void Channel__WriteC0(Channel *self, const Chip* chip, Bit8u val ) { +static void Channel__WriteC0(Channel *self, const Chip* chip, Bit8u val ) { Bit8u change = val ^ self->regC0; if ( !change ) return; @@ -838,7 +838,7 @@ void Channel__WriteC0(Channel *self, const Chip* chip, Bit8u val ) { } } -void Channel__ResetC0(Channel *self, const Chip* chip ) { +static void Channel__ResetC0(Channel *self, const Chip* chip ) { Bit8u val = self->regC0; self->regC0 ^= 0xff; Channel__WriteC0( self, chip, val ); @@ -975,7 +975,7 @@ Channel* Channel__BlockTemplate(Channel *self, Chip* chip, Bit32s mod = (Bit32u)((self->old[0] + self->old[1])) >> self->feedback; self->old[0] = self->old[1]; self->old[1] = Operator__GetSample( Channel__Op(self, 0), mod ); - Bit32s sample; + Bit32s sample = 0; Bit32s out0 = self->old[0]; if ( mode == sm2AM || mode == sm3AM ) { sample = out0 + Operator__GetSample( Channel__Op(self, 1), 0 ); @@ -1095,7 +1095,7 @@ static inline Bit32u Chip__ForwardLFO(Chip *self, Bit32u samples ) { } -void Chip__WriteBD(Chip *self, Bit8u val ) { +static void Chip__WriteBD(Chip *self, Bit8u val ) { Bit8u change = self->regBD ^ val; if ( !change ) return; @@ -1240,7 +1240,7 @@ void Chip__WriteReg(Chip *self, Bit32u reg, Bit8u val ) { } -Bit32u Chip__WriteAddr(Chip *self, Bit32u port, Bit8u val ) { +static Bit32u Chip__WriteAddr(Chip *self, Bit32u port, Bit8u val ) { switch ( port & 3 ) { case 0: return val; @@ -1415,7 +1415,7 @@ void Chip__Setup(Chip *self, Bit32u rate ) { } static int doneTables = FALSE; -void InitTables( void ) { +void DBOPL_InitTables( void ) { int i, oct; if ( doneTables ) diff --git a/opl/dbopl.h b/opl/dbopl.h index f7d2e416..a5c10bfd 100644 --- a/opl/dbopl.h +++ b/opl/dbopl.h @@ -47,7 +47,7 @@ typedef Bits ( DB_FASTCALL *WaveHandler) ( Bitu i, Bitu volume ); #define DB_FASTCALL -typedef Bits (*VolumeHandler)(); +typedef Bits (*VolumeHandler)(Operator *self); typedef Channel* (*SynthHandler)(Channel *self, Chip* chip, Bit32u samples, Bit32s* output ); //Different synth modes that can generate blocks of data @@ -194,3 +194,10 @@ struct Handler : public Adlib::Handler { */ +void Chip__Setup(Chip *self, Bit32u rate ); +void DBOPL_InitTables( void ); +void Chip__Chip(Chip *self); +void Chip__WriteReg(Chip *self, Bit32u reg, Bit8u val ); +void Chip__GenerateBlock2(Chip *self, Bitu total, Bit32s* output ); + + diff --git a/opl/fmopl.c b/opl/fmopl.c deleted file mode 100644 index 1671244e..00000000 --- a/opl/fmopl.c +++ /dev/null @@ -1,1155 +0,0 @@ -/* This file is derived from fmopl.cpp from ScummVM. - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * 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. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * LGPL licensed version of MAMEs fmopl (V0.37a modified) by - * Tatsuyuki Satoh. Included from LGPL'ed AdPlug. - */ - -#include -#include -#include -#include -#include - -#include "fmopl.h" - -#define PI 3.1415926539 - -#define CLIP(value, min, max) \ - ( (value) < (min) ? (min) : \ - (value) > (max) ? (max) : (value) ) - -/* -------------------- preliminary define section --------------------- */ -/* attack/decay rate time rate */ -#define OPL_ARRATE 141280 /* RATE 4 = 2826.24ms @ 3.6MHz */ -#define OPL_DRRATE 1956000 /* RATE 4 = 39280.64ms @ 3.6MHz */ - -#define FREQ_BITS 24 /* frequency turn */ - -/* counter bits = 20 , octerve 7 */ -#define FREQ_RATE (1<<(FREQ_BITS-20)) -#define TL_BITS (FREQ_BITS+2) - -/* final output shift , limit minimum and maximum */ -#define OPL_OUTSB (TL_BITS+3-16) /* OPL output final shift 16bit */ -#define OPL_MAXOUT (0x7fff<status |= flag; - if(!(OPL->status & 0x80)) { - if(OPL->status & OPL->statusmask) { /* IRQ on */ - OPL->status |= 0x80; - /* callback user interrupt handler (IRQ is OFF to ON) */ - if(OPL->IRQHandler) - (OPL->IRQHandler)(OPL->IRQParam,1); - } - } -} - -/* status reset and IRQ handling */ -static inline void OPL_STATUS_RESET(FM_OPL *OPL, int flag) { - /* reset status flag */ - OPL->status &= ~flag; - if((OPL->status & 0x80)) { - if (!(OPL->status & OPL->statusmask)) { - OPL->status &= 0x7f; - /* callback user interrupt handler (IRQ is ON to OFF) */ - if(OPL->IRQHandler) (OPL->IRQHandler)(OPL->IRQParam,0); - } - } -} - -/* IRQ mask set */ -static inline void OPL_STATUSMASK_SET(FM_OPL *OPL, int flag) { - OPL->statusmask = flag; - /* IRQ handling check */ - OPL_STATUS_SET(OPL,0); - OPL_STATUS_RESET(OPL,0); -} - -/* ----- key on ----- */ -static inline void OPL_KEYON(OPL_SLOT *SLOT) { - /* sin wave restart */ - SLOT->Cnt = 0; - /* set attack */ - SLOT->evm = ENV_MOD_AR; - SLOT->evs = SLOT->evsa; - SLOT->evc = EG_AST; - SLOT->eve = EG_AED; -} - -/* ----- key off ----- */ -static inline void OPL_KEYOFF(OPL_SLOT *SLOT) { - if( SLOT->evm > ENV_MOD_RR) { - /* set envelope counter from envleope output */ - - // WORKAROUND: The Kyra engine does something very strange when - // starting a new song. For each channel: - // - // * The release rate is set to "fastest". - // * Any note is keyed off. - // * A very low-frequency note is keyed on. - // - // Usually, what happens next is that the real notes is keyed - // on immediately, in which case there's no problem. - // - // However, if the note is again keyed off (because the channel - // begins on a rest rather than a note), the envelope counter - // was moved from the very lowest point on the attack curve to - // the very highest point on the release curve. - // - // Again, this might not be a problem, if the release rate is - // still set to "fastest". But in many cases, it had already - // been increased. And, possibly because of inaccuracies in the - // envelope generator, that would cause the note to "fade out" - // for quite a long time. - // - // What we really need is a way to find the correct starting - // point for the envelope counter, and that may be what the - // commented-out line below is meant to do. For now, simply - // handle the pathological case. - - if (SLOT->evm == ENV_MOD_AR && SLOT->evc == EG_AST) - SLOT->evc = EG_DED; - else if( !(SLOT->evc & EG_DST) ) - //SLOT->evc = (ENV_CURVE[SLOT->evc>>ENV_BITS]<evc = EG_DST; - SLOT->eve = EG_DED; - SLOT->evs = SLOT->evsr; - SLOT->evm = ENV_MOD_RR; - } -} - -/* ---------- calcrate Envelope Generator & Phase Generator ---------- */ - -/* return : envelope output */ -static inline uint32_t OPL_CALC_SLOT(OPL_SLOT *SLOT) { - /* calcrate envelope generator */ - if((SLOT->evc += SLOT->evs) >= SLOT->eve) { - switch( SLOT->evm ) { - case ENV_MOD_AR: /* ATTACK -> DECAY1 */ - /* next DR */ - SLOT->evm = ENV_MOD_DR; - SLOT->evc = EG_DST; - SLOT->eve = SLOT->SL; - SLOT->evs = SLOT->evsd; - break; - case ENV_MOD_DR: /* DECAY -> SL or RR */ - SLOT->evc = SLOT->SL; - SLOT->eve = EG_DED; - if(SLOT->eg_typ) { - SLOT->evs = 0; - } else { - SLOT->evm = ENV_MOD_RR; - SLOT->evs = SLOT->evsr; - } - break; - case ENV_MOD_RR: /* RR -> OFF */ - SLOT->evc = EG_OFF; - SLOT->eve = EG_OFF + 1; - SLOT->evs = 0; - break; - } - } - /* calcrate envelope */ - return SLOT->TLL + ENV_CURVE[SLOT->evc>>ENV_BITS] + (SLOT->ams ? ams : 0); -} - -/* set algorythm connection */ -static void set_algorythm(OPL_CH *CH) { - int *carrier = &outd[0]; - CH->connect1 = CH->CON ? carrier : &feedback2; - CH->connect2 = carrier; -} - -/* ---------- frequency counter for operater update ---------- */ -static inline void CALC_FCSLOT(OPL_CH *CH, OPL_SLOT *SLOT) { - int ksr; - - /* frequency step counter */ - SLOT->Incr = CH->fc * SLOT->mul; - ksr = CH->kcode >> SLOT->KSR; - - if( SLOT->ksr != ksr ) { - SLOT->ksr = ksr; - /* attack , decay rate recalcration */ - SLOT->evsa = SLOT->AR[ksr]; - SLOT->evsd = SLOT->DR[ksr]; - SLOT->evsr = SLOT->RR[ksr]; - } - SLOT->TLL = SLOT->TL + (CH->ksl_base>>SLOT->ksl); -} - -/* set multi,am,vib,EG-TYP,KSR,mul */ -static inline void set_mul(FM_OPL *OPL, int slot, int v) { - OPL_CH *CH = &OPL->P_CH[slot>>1]; - OPL_SLOT *SLOT = &CH->SLOT[slot & 1]; - - SLOT->mul = MUL_TABLE[v & 0x0f]; - SLOT->KSR = (v & 0x10) ? 0 : 2; - SLOT->eg_typ = (v & 0x20) >> 5; - SLOT->vib = (v & 0x40); - SLOT->ams = (v & 0x80); - CALC_FCSLOT(CH, SLOT); -} - -/* set ksl & tl */ -static inline void set_ksl_tl(FM_OPL *OPL, int slot, int v) { - OPL_CH *CH = &OPL->P_CH[slot>>1]; - OPL_SLOT *SLOT = &CH->SLOT[slot & 1]; - int ksl = v >> 6; /* 0 / 1.5 / 3 / 6 db/OCT */ - - SLOT->ksl = ksl ? 3-ksl : 31; - SLOT->TL = (int)((v & 0x3f) * (0.75 / EG_STEP)); /* 0.75db step */ - - if(!(OPL->mode & 0x80)) { /* not CSM latch total level */ - SLOT->TLL = SLOT->TL + (CH->ksl_base >> SLOT->ksl); - } -} - -/* set attack rate & decay rate */ -static inline void set_ar_dr(FM_OPL *OPL, int slot, int v) { - OPL_CH *CH = &OPL->P_CH[slot>>1]; - OPL_SLOT *SLOT = &CH->SLOT[slot & 1]; - int ar = v >> 4; - int dr = v & 0x0f; - - SLOT->AR = ar ? &OPL->AR_TABLE[ar << 2] : RATE_0; - SLOT->evsa = SLOT->AR[SLOT->ksr]; - if(SLOT->evm == ENV_MOD_AR) - SLOT->evs = SLOT->evsa; - - SLOT->DR = dr ? &OPL->DR_TABLE[dr<<2] : RATE_0; - SLOT->evsd = SLOT->DR[SLOT->ksr]; - if(SLOT->evm == ENV_MOD_DR) - SLOT->evs = SLOT->evsd; -} - -/* set sustain level & release rate */ -static inline void set_sl_rr(FM_OPL *OPL, int slot, int v) { - OPL_CH *CH = &OPL->P_CH[slot>>1]; - OPL_SLOT *SLOT = &CH->SLOT[slot & 1]; - int sl = v >> 4; - int rr = v & 0x0f; - - SLOT->SL = SL_TABLE[sl]; - if(SLOT->evm == ENV_MOD_DR) - SLOT->eve = SLOT->SL; - SLOT->RR = &OPL->DR_TABLE[rr<<2]; - SLOT->evsr = SLOT->RR[SLOT->ksr]; - if(SLOT->evm == ENV_MOD_RR) - SLOT->evs = SLOT->evsr; -} - -/* operator output calcrator */ - -#define OP_OUT(slot,env,con) slot->wavetable[((slot->Cnt + con)>>(24-SIN_ENT_SHIFT)) & (SIN_ENT-1)][env] -/* ---------- calcrate one of channel ---------- */ -static inline void OPL_CALC_CH(OPL_CH *CH) { - uint32_t env_out; - OPL_SLOT *SLOT; - - feedback2 = 0; - /* SLOT 1 */ - SLOT = &CH->SLOT[SLOT1]; - env_out=OPL_CALC_SLOT(SLOT); - if(env_out < (uint32_t)(EG_ENT - 1)) { - /* PG */ - if(SLOT->vib) - SLOT->Cnt += (SLOT->Incr * vib) >> VIB_RATE_SHIFT; - else - SLOT->Cnt += SLOT->Incr; - /* connection */ - if(CH->FB) { - int feedback1 = (CH->op1_out[0] + CH->op1_out[1]) >> CH->FB; - CH->op1_out[1] = CH->op1_out[0]; - *CH->connect1 += CH->op1_out[0] = OP_OUT(SLOT, env_out, feedback1); - } else { - *CH->connect1 += OP_OUT(SLOT, env_out, 0); - } - } else { - CH->op1_out[1] = CH->op1_out[0]; - CH->op1_out[0] = 0; - } - /* SLOT 2 */ - SLOT = &CH->SLOT[SLOT2]; - env_out=OPL_CALC_SLOT(SLOT); - if(env_out < (uint32_t)(EG_ENT - 1)) { - /* PG */ - if(SLOT->vib) - SLOT->Cnt += (SLOT->Incr * vib) >> VIB_RATE_SHIFT; - else - SLOT->Cnt += SLOT->Incr; - /* connection */ - outd[0] += OP_OUT(SLOT, env_out, feedback2); - } -} - -/* ---------- calcrate rythm block ---------- */ -#define WHITE_NOISE_db 6.0 -static inline void OPL_CALC_RH(FM_OPL *OPL, OPL_CH *CH) { - uint32_t env_tam, env_sd, env_top, env_hh; - // This code used to do int(OPL->rnd.getRandomBit() * (WHITE_NOISE_db / EG_STEP)), - // but EG_STEP = 96.0/EG_ENT, and WHITE_NOISE_db=6.0. So, that's equivalent to - // int(OPL->rnd.getRandomBit() * EG_ENT/16). We know that EG_ENT is 4096, or 1024, - // or 128, so we can safely avoid any FP ops. - int whitenoise = (rand() & 1) * (EG_ENT>>4); - - int tone8; - - OPL_SLOT *SLOT; - int env_out; - - /* BD : same as FM serial mode and output level is large */ - feedback2 = 0; - /* SLOT 1 */ - SLOT = &CH[6].SLOT[SLOT1]; - env_out = OPL_CALC_SLOT(SLOT); - if(env_out < EG_ENT-1) { - /* PG */ - if(SLOT->vib) - SLOT->Cnt += (SLOT->Incr * vib) >> VIB_RATE_SHIFT; - else - SLOT->Cnt += SLOT->Incr; - /* connection */ - if(CH[6].FB) { - int feedback1 = (CH[6].op1_out[0] + CH[6].op1_out[1]) >> CH[6].FB; - CH[6].op1_out[1] = CH[6].op1_out[0]; - feedback2 = CH[6].op1_out[0] = OP_OUT(SLOT, env_out, feedback1); - } - else { - feedback2 = OP_OUT(SLOT, env_out, 0); - } - } else { - feedback2 = 0; - CH[6].op1_out[1] = CH[6].op1_out[0]; - CH[6].op1_out[0] = 0; - } - /* SLOT 2 */ - SLOT = &CH[6].SLOT[SLOT2]; - env_out = OPL_CALC_SLOT(SLOT); - if(env_out < EG_ENT-1) { - /* PG */ - if(SLOT->vib) - SLOT->Cnt += (SLOT->Incr * vib) >> VIB_RATE_SHIFT; - else - SLOT->Cnt += SLOT->Incr; - /* connection */ - outd[0] += OP_OUT(SLOT, env_out, feedback2) * 2; - } - - // SD (17) = mul14[fnum7] + white noise - // TAM (15) = mul15[fnum8] - // TOP (18) = fnum6(mul18[fnum8]+whitenoise) - // HH (14) = fnum7(mul18[fnum8]+whitenoise) + white noise - env_sd = OPL_CALC_SLOT(SLOT7_2) + whitenoise; - env_tam =OPL_CALC_SLOT(SLOT8_1); - env_top = OPL_CALC_SLOT(SLOT8_2); - env_hh = OPL_CALC_SLOT(SLOT7_1) + whitenoise; - - /* PG */ - if(SLOT7_1->vib) - SLOT7_1->Cnt += (SLOT7_1->Incr * vib) >> (VIB_RATE_SHIFT-1); - else - SLOT7_1->Cnt += 2 * SLOT7_1->Incr; - if(SLOT7_2->vib) - SLOT7_2->Cnt += (CH[7].fc * vib) >> (VIB_RATE_SHIFT-3); - else - SLOT7_2->Cnt += (CH[7].fc * 8); - if(SLOT8_1->vib) - SLOT8_1->Cnt += (SLOT8_1->Incr * vib) >> VIB_RATE_SHIFT; - else - SLOT8_1->Cnt += SLOT8_1->Incr; - if(SLOT8_2->vib) - SLOT8_2->Cnt += ((CH[8].fc * 3) * vib) >> (VIB_RATE_SHIFT-4); - else - SLOT8_2->Cnt += (CH[8].fc * 48); - - tone8 = OP_OUT(SLOT8_2,whitenoise,0 ); - - /* SD */ - if(env_sd < (uint32_t)(EG_ENT - 1)) - outd[0] += OP_OUT(SLOT7_1, env_sd, 0) * 8; - /* TAM */ - if(env_tam < (uint32_t)(EG_ENT - 1)) - outd[0] += OP_OUT(SLOT8_1, env_tam, 0) * 2; - /* TOP-CY */ - if(env_top < (uint32_t)(EG_ENT - 1)) - outd[0] += OP_OUT(SLOT7_2, env_top, tone8) * 2; - /* HH */ - if(env_hh < (uint32_t)(EG_ENT-1)) - outd[0] += OP_OUT(SLOT7_2, env_hh, tone8) * 2; -} - -/* ----------- initialize time tabls ----------- */ -static void init_timetables(FM_OPL *OPL, int ARRATE, int DRRATE) { - int i; - double rate; - - /* make attack rate & decay rate tables */ - for (i = 0; i < 4; i++) - OPL->AR_TABLE[i] = OPL->DR_TABLE[i] = 0; - for (i = 4; i <= 60; i++) { - rate = OPL->freqbase; /* frequency rate */ - if(i < 60) - rate *= 1.0 + (i & 3) * 0.25; /* b0-1 : x1 , x1.25 , x1.5 , x1.75 */ - rate *= 1 << ((i >> 2) - 1); /* b2-5 : shift bit */ - rate *= (double)(EG_ENT << ENV_BITS); - OPL->AR_TABLE[i] = (int)(rate / ARRATE); - OPL->DR_TABLE[i] = (int)(rate / DRRATE); - } - for (i = 60; i < 76; i++) { - OPL->AR_TABLE[i] = EG_AED-1; - OPL->DR_TABLE[i] = OPL->DR_TABLE[60]; - } -} - -/* ---------- generic table initialize ---------- */ -static int OPLOpenTable(void) { - int s,t; - double rate; - int i,j; - double pom; - - /* allocate dynamic tables */ - if((TL_TABLE = (int *)malloc(TL_MAX * 2 * sizeof(int))) == NULL) - return 0; - - if((SIN_TABLE = (int **)malloc(SIN_ENT * 4 * sizeof(int *))) == NULL) { - free(TL_TABLE); - return 0; - } - - if((AMS_TABLE = (int *)malloc(AMS_ENT * 2 * sizeof(int))) == NULL) { - free(TL_TABLE); - free(SIN_TABLE); - return 0; - } - - if((VIB_TABLE = (int *)malloc(VIB_ENT * 2 * sizeof(int))) == NULL) { - free(TL_TABLE); - free(SIN_TABLE); - free(AMS_TABLE); - return 0; - } - /* make total level table */ - for (t = 0; t < EG_ENT - 1 ; t++) { - rate = ((1 << TL_BITS) - 1) / pow(10.0, EG_STEP * t / 20); /* dB -> voltage */ - TL_TABLE[ t] = (int)rate; - TL_TABLE[TL_MAX + t] = -TL_TABLE[t]; - } - /* fill volume off area */ - for (t = EG_ENT - 1; t < TL_MAX; t++) { - TL_TABLE[t] = TL_TABLE[TL_MAX + t] = 0; - } - - /* make sinwave table (total level offet) */ - /* degree 0 = degree 180 = off */ - SIN_TABLE[0] = SIN_TABLE[SIN_ENT /2 ] = &TL_TABLE[EG_ENT - 1]; - for (s = 1;s <= SIN_ENT / 4; s++) { - pom = sin(2 * PI * s / SIN_ENT); /* sin */ - pom = 20 * log10(1 / pom); /* decibel */ - j = (int) (pom / EG_STEP); /* TL_TABLE steps */ - - /* degree 0 - 90 , degree 180 - 90 : plus section */ - SIN_TABLE[ s] = SIN_TABLE[SIN_ENT / 2 - s] = &TL_TABLE[j]; - /* degree 180 - 270 , degree 360 - 270 : minus section */ - SIN_TABLE[SIN_ENT / 2 + s] = SIN_TABLE[SIN_ENT - s] = &TL_TABLE[TL_MAX + j]; - } - for (s = 0;s < SIN_ENT; s++) { - SIN_TABLE[SIN_ENT * 1 + s] = s < (SIN_ENT / 2) ? SIN_TABLE[s] : &TL_TABLE[EG_ENT]; - SIN_TABLE[SIN_ENT * 2 + s] = SIN_TABLE[s % (SIN_ENT / 2)]; - SIN_TABLE[SIN_ENT * 3 + s] = (s / (SIN_ENT / 4)) & 1 ? &TL_TABLE[EG_ENT] : SIN_TABLE[SIN_ENT * 2 + s]; - } - - - ENV_CURVE = (int *)malloc(sizeof(int) * (2*EG_ENT+1)); - - /* envelope counter -> envelope output table */ - for (i=0; i < EG_ENT; i++) { - /* ATTACK curve */ - pom = pow(((double)(EG_ENT - 1 - i) / EG_ENT), 8) * EG_ENT; - /* if( pom >= EG_ENT ) pom = EG_ENT-1; */ - ENV_CURVE[i] = (int)pom; - /* DECAY ,RELEASE curve */ - ENV_CURVE[(EG_DST >> ENV_BITS) + i]= i; - } - /* off */ - ENV_CURVE[EG_OFF >> ENV_BITS]= EG_ENT - 1; - /* make LFO ams table */ - for (i=0; i < AMS_ENT; i++) { - pom = (1.0 + sin(2 * PI * i / AMS_ENT)) / 2; /* sin */ - AMS_TABLE[i] = (int)((1.0 / EG_STEP) * pom); /* 1dB */ - AMS_TABLE[AMS_ENT + i] = (int)((4.8 / EG_STEP) * pom); /* 4.8dB */ - } - /* make LFO vibrate table */ - for (i=0; i < VIB_ENT; i++) { - /* 100cent = 1seminote = 6% ?? */ - pom = (double)VIB_RATE * 0.06 * sin(2 * PI * i / VIB_ENT); /* +-100sect step */ - VIB_TABLE[i] = (int)(VIB_RATE + (pom * 0.07)); /* +- 7cent */ - VIB_TABLE[VIB_ENT + i] = (int)(VIB_RATE + (pom * 0.14)); /* +-14cent */ - } - return 1; -} - -static void OPLCloseTable(void) { - free(TL_TABLE); - free(SIN_TABLE); - free(AMS_TABLE); - free(VIB_TABLE); - free(ENV_CURVE); -} - -/* CSM Key Controll */ -static inline void CSMKeyControll(OPL_CH *CH) { - OPL_SLOT *slot1 = &CH->SLOT[SLOT1]; - OPL_SLOT *slot2 = &CH->SLOT[SLOT2]; - /* all key off */ - OPL_KEYOFF(slot1); - OPL_KEYOFF(slot2); - /* total level latch */ - slot1->TLL = slot1->TL + (CH->ksl_base>>slot1->ksl); - slot1->TLL = slot1->TL + (CH->ksl_base>>slot1->ksl); - /* key on */ - CH->op1_out[0] = CH->op1_out[1] = 0; - OPL_KEYON(slot1); - OPL_KEYON(slot2); -} - -/* ---------- opl initialize ---------- */ -static void OPL_initalize(FM_OPL *OPL) { - int fn; - - /* frequency base */ - OPL->freqbase = (OPL->rate) ? ((double)OPL->clock / OPL->rate) / 72 : 0; - /* Timer base time */ - OPL->TimerBase = 1.0/((double)OPL->clock / 72.0 ); - /* make time tables */ - init_timetables(OPL, OPL_ARRATE, OPL_DRRATE); - /* make fnumber -> increment counter table */ - for( fn=0; fn < 1024; fn++) { - OPL->FN_TABLE[fn] = (uint32_t)(OPL->freqbase * fn * FREQ_RATE * (1<<7) / 2); - } - /* LFO freq.table */ - OPL->amsIncr = (int)(OPL->rate ? (double)AMS_ENT * (1 << AMS_SHIFT) / OPL->rate * 3.7 * ((double)OPL->clock/3600000) : 0); - OPL->vibIncr = (int)(OPL->rate ? (double)VIB_ENT * (1 << VIB_SHIFT) / OPL->rate * 6.4 * ((double)OPL->clock/3600000) : 0); -} - -/* ---------- write a OPL registers ---------- */ -void OPLWriteReg(FM_OPL *OPL, int r, int v) { - OPL_CH *CH; - int slot; - uint32_t block_fnum; - - switch(r & 0xe0) { - case 0x00: /* 00-1f:controll */ - switch(r & 0x1f) { - case 0x01: - /* wave selector enable */ - if(OPL->type&OPL_TYPE_WAVESEL) { - OPL->wavesel = v & 0x20; - if(!OPL->wavesel) { - /* preset compatible mode */ - int c; - for(c=0; cmax_ch; c++) { - OPL->P_CH[c].SLOT[SLOT1].wavetable = &SIN_TABLE[0]; - OPL->P_CH[c].SLOT[SLOT2].wavetable = &SIN_TABLE[0]; - } - } - } - return; - case 0x02: /* Timer 1 */ - OPL->T[0] = (256-v) * 4; - break; - case 0x03: /* Timer 2 */ - OPL->T[1] = (256-v) * 16; - return; - case 0x04: /* IRQ clear / mask and Timer enable */ - if(v & 0x80) { /* IRQ flag clear */ - OPL_STATUS_RESET(OPL, 0x7f); - } else { /* set IRQ mask ,timer enable*/ - uint8_t st1 = v & 1; - uint8_t st2 = (v >> 1) & 1; - /* IRQRST,T1MSK,t2MSK,EOSMSK,BRMSK,x,ST2,ST1 */ - OPL_STATUS_RESET(OPL, v & 0x78); - OPL_STATUSMASK_SET(OPL,((~v) & 0x78) | 0x01); - /* timer 2 */ - if(OPL->st[1] != st2) { - double interval = st2 ? (double)OPL->T[1] * OPL->TimerBase : 0.0; - OPL->st[1] = st2; - if (OPL->TimerHandler) (OPL->TimerHandler)(OPL->TimerParam + 1, interval); - } - /* timer 1 */ - if(OPL->st[0] != st1) { - double interval = st1 ? (double)OPL->T[0] * OPL->TimerBase : 0.0; - OPL->st[0] = st1; - if (OPL->TimerHandler) (OPL->TimerHandler)(OPL->TimerParam + 0, interval); - } - } - return; - } - break; - case 0x20: /* am,vib,ksr,eg type,mul */ - slot = slot_array[r&0x1f]; - if(slot == -1) - return; - set_mul(OPL,slot,v); - return; - case 0x40: - slot = slot_array[r&0x1f]; - if(slot == -1) - return; - set_ksl_tl(OPL,slot,v); - return; - case 0x60: - slot = slot_array[r&0x1f]; - if(slot == -1) - return; - set_ar_dr(OPL,slot,v); - return; - case 0x80: - slot = slot_array[r&0x1f]; - if(slot == -1) - return; - set_sl_rr(OPL,slot,v); - return; - case 0xa0: - switch(r) { - case 0xbd: - /* amsep,vibdep,r,bd,sd,tom,tc,hh */ - { - uint8_t rkey = OPL->rythm ^ v; - OPL->ams_table = &AMS_TABLE[v & 0x80 ? AMS_ENT : 0]; - OPL->vib_table = &VIB_TABLE[v & 0x40 ? VIB_ENT : 0]; - OPL->rythm = v & 0x3f; - if(OPL->rythm & 0x20) { - /* BD key on/off */ - if(rkey & 0x10) { - if(v & 0x10) { - OPL->P_CH[6].op1_out[0] = OPL->P_CH[6].op1_out[1] = 0; - OPL_KEYON(&OPL->P_CH[6].SLOT[SLOT1]); - OPL_KEYON(&OPL->P_CH[6].SLOT[SLOT2]); - } else { - OPL_KEYOFF(&OPL->P_CH[6].SLOT[SLOT1]); - OPL_KEYOFF(&OPL->P_CH[6].SLOT[SLOT2]); - } - } - /* SD key on/off */ - if(rkey & 0x08) { - if(v & 0x08) - OPL_KEYON(&OPL->P_CH[7].SLOT[SLOT2]); - else - OPL_KEYOFF(&OPL->P_CH[7].SLOT[SLOT2]); - }/* TAM key on/off */ - if(rkey & 0x04) { - if(v & 0x04) - OPL_KEYON(&OPL->P_CH[8].SLOT[SLOT1]); - else - OPL_KEYOFF(&OPL->P_CH[8].SLOT[SLOT1]); - } - /* TOP-CY key on/off */ - if(rkey & 0x02) { - if(v & 0x02) - OPL_KEYON(&OPL->P_CH[8].SLOT[SLOT2]); - else - OPL_KEYOFF(&OPL->P_CH[8].SLOT[SLOT2]); - } - /* HH key on/off */ - if(rkey & 0x01) { - if(v & 0x01) - OPL_KEYON(&OPL->P_CH[7].SLOT[SLOT1]); - else - OPL_KEYOFF(&OPL->P_CH[7].SLOT[SLOT1]); - } - } - } - return; - - default: - break; - } - /* keyon,block,fnum */ - if((r & 0x0f) > 8) - return; - CH = &OPL->P_CH[r & 0x0f]; - if(!(r&0x10)) { /* a0-a8 */ - block_fnum = (CH->block_fnum & 0x1f00) | v; - } else { /* b0-b8 */ - int keyon = (v >> 5) & 1; - block_fnum = ((v & 0x1f) << 8) | (CH->block_fnum & 0xff); - if(CH->keyon != keyon) { - if((CH->keyon=keyon)) { - CH->op1_out[0] = CH->op1_out[1] = 0; - OPL_KEYON(&CH->SLOT[SLOT1]); - OPL_KEYON(&CH->SLOT[SLOT2]); - } else { - OPL_KEYOFF(&CH->SLOT[SLOT1]); - OPL_KEYOFF(&CH->SLOT[SLOT2]); - } - } - } - /* update */ - if(CH->block_fnum != block_fnum) { - int blockRv = 7 - (block_fnum >> 10); - int fnum = block_fnum & 0x3ff; - CH->block_fnum = block_fnum; - CH->ksl_base = KSL_TABLE[block_fnum >> 6]; - CH->fc = OPL->FN_TABLE[fnum] >> blockRv; - CH->kcode = CH->block_fnum >> 9; - if((OPL->mode & 0x40) && CH->block_fnum & 0x100) - CH->kcode |=1; - CALC_FCSLOT(CH,&CH->SLOT[SLOT1]); - CALC_FCSLOT(CH,&CH->SLOT[SLOT2]); - } - return; - case 0xc0: - /* FB,C */ - if((r & 0x0f) > 8) - return; - CH = &OPL->P_CH[r&0x0f]; - { - int feedback = (v >> 1) & 7; - CH->FB = feedback ? (8 + 1) - feedback : 0; - CH->CON = v & 1; - set_algorythm(CH); - } - return; - case 0xe0: /* wave type */ - slot = slot_array[r & 0x1f]; - if(slot == -1) - return; - CH = &OPL->P_CH[slot>>1]; - if(OPL->wavesel) { - CH->SLOT[slot&1].wavetable = &SIN_TABLE[(v & 0x03) * SIN_ENT]; - } - return; - } -} - -/* lock/unlock for common table */ -static int OPL_LockTable(void) { - num_lock++; - if(num_lock>1) - return 0; - /* first time */ - cur_chip = NULL; - /* allocate total level table (128kb space) */ - if(!OPLOpenTable()) { - num_lock--; - return -1; - } - return 0; -} - -static void OPL_UnLockTable(void) { - if(num_lock) - num_lock--; - if(num_lock) - return; - /* last time */ - cur_chip = NULL; - OPLCloseTable(); -} - -/*******************************************************************************/ -/* YM3812 local section */ -/*******************************************************************************/ - -/* ---------- update one of chip ----------- */ -void YM3812UpdateOne(FM_OPL *OPL, int16_t *buffer, int length, int interleave) { - int i; - int data; - int16_t *buf = buffer; - uint32_t amsCnt = OPL->amsCnt; - uint32_t vibCnt = OPL->vibCnt; - uint8_t rythm = OPL->rythm & 0x20; - OPL_CH *CH, *R_CH; - - - if((void *)OPL != cur_chip) { - cur_chip = (void *)OPL; - /* channel pointers */ - S_CH = OPL->P_CH; - E_CH = &S_CH[9]; - /* rythm slot */ - SLOT7_1 = &S_CH[7].SLOT[SLOT1]; - SLOT7_2 = &S_CH[7].SLOT[SLOT2]; - SLOT8_1 = &S_CH[8].SLOT[SLOT1]; - SLOT8_2 = &S_CH[8].SLOT[SLOT2]; - /* LFO state */ - amsIncr = OPL->amsIncr; - vibIncr = OPL->vibIncr; - ams_table = OPL->ams_table; - vib_table = OPL->vib_table; - } - R_CH = rythm ? &S_CH[6] : E_CH; - for(i = 0; i < length; i++) { - /* channel A channel B channel C */ - /* LFO */ - ams = ams_table[(amsCnt += amsIncr) >> AMS_SHIFT]; - vib = vib_table[(vibCnt += vibIncr) >> VIB_SHIFT]; - outd[0] = 0; - /* FM part */ - for(CH=S_CH; CH < R_CH; CH++) - OPL_CALC_CH(CH); - /* Rythn part */ - if(rythm) - OPL_CALC_RH(OPL, S_CH); - /* limit check */ - data = CLIP(outd[0], OPL_MINOUT, OPL_MAXOUT); - /* store to sound buffer */ - buf[i << interleave] = data >> OPL_OUTSB; - } - - OPL->amsCnt = amsCnt; - OPL->vibCnt = vibCnt; -} - -/* ---------- reset a chip ---------- */ -void OPLResetChip(FM_OPL *OPL) { - int c,s; - int i; - - /* reset chip */ - OPL->mode = 0; /* normal mode */ - OPL_STATUS_RESET(OPL, 0x7f); - /* reset with register write */ - OPLWriteReg(OPL, 0x01,0); /* wabesel disable */ - OPLWriteReg(OPL, 0x02,0); /* Timer1 */ - OPLWriteReg(OPL, 0x03,0); /* Timer2 */ - OPLWriteReg(OPL, 0x04,0); /* IRQ mask clear */ - for(i = 0xff; i >= 0x20; i--) - OPLWriteReg(OPL,i,0); - /* reset OPerator parameter */ - for(c = 0; c < OPL->max_ch ;c++ ) { - OPL_CH *CH = &OPL->P_CH[c]; - /* OPL->P_CH[c].PAN = OPN_CENTER; */ - for(s = 0; s < 2; s++ ) { - /* wave table */ - CH->SLOT[s].wavetable = &SIN_TABLE[0]; - /* CH->SLOT[s].evm = ENV_MOD_RR; */ - CH->SLOT[s].evc = EG_OFF; - CH->SLOT[s].eve = EG_OFF + 1; - CH->SLOT[s].evs = 0; - } - } -} - -/* ---------- Create a virtual YM3812 ---------- */ -/* 'rate' is sampling rate and 'bufsiz' is the size of the */ -FM_OPL *OPLCreate(int type, int clock, int rate) { - char *ptr; - FM_OPL *OPL; - int state_size; - int max_ch = 9; /* normaly 9 channels */ - - if( OPL_LockTable() == -1) - return NULL; - /* allocate OPL state space */ - state_size = sizeof(FM_OPL); - state_size += sizeof(OPL_CH) * max_ch; - - /* allocate memory block */ - ptr = (char *)calloc(state_size, 1); - if(ptr == NULL) - return NULL; - - /* clear */ - memset(ptr, 0, state_size); - OPL = (FM_OPL *)ptr; ptr += sizeof(FM_OPL); - OPL->P_CH = (OPL_CH *)ptr; ptr += sizeof(OPL_CH) * max_ch; - - /* set channel state pointer */ - OPL->type = type; - OPL->clock = clock; - OPL->rate = rate; - OPL->max_ch = max_ch; - - /* init grobal tables */ - OPL_initalize(OPL); - - /* reset chip */ - OPLResetChip(OPL); - return OPL; -} - -/* ---------- Destroy one of vietual YM3812 ---------- */ -void OPLDestroy(FM_OPL *OPL) { - OPL_UnLockTable(); - free(OPL); -} - -/* ---------- Option handlers ---------- */ -void OPLSetTimerHandler(FM_OPL *OPL, OPL_TIMERHANDLER TimerHandler,int channelOffset) { - OPL->TimerHandler = TimerHandler; - OPL->TimerParam = channelOffset; -} - -void OPLSetIRQHandler(FM_OPL *OPL, OPL_IRQHANDLER IRQHandler, int param) { - OPL->IRQHandler = IRQHandler; - OPL->IRQParam = param; -} - -void OPLSetUpdateHandler(FM_OPL *OPL, OPL_UPDATEHANDLER UpdateHandler,int param) { - OPL->UpdateHandler = UpdateHandler; - OPL->UpdateParam = param; -} - -/* ---------- YM3812 I/O interface ---------- */ -int OPLWrite(FM_OPL *OPL,int a,int v) { - if(!(a & 1)) { /* address port */ - OPL->address = v & 0xff; - } else { /* data port */ - if(OPL->UpdateHandler) - OPL->UpdateHandler(OPL->UpdateParam,0); - OPLWriteReg(OPL, OPL->address,v); - } - return OPL->status >> 7; -} - -unsigned char OPLRead(FM_OPL *OPL,int a) { - if(!(a & 1)) { /* status port */ - return OPL->status & (OPL->statusmask | 0x80); - } - - return 0; -} - -int OPLTimerOver(FM_OPL *OPL, int c) { - if(c) { /* Timer B */ - OPL_STATUS_SET(OPL, 0x20); - } else { /* Timer A */ - OPL_STATUS_SET(OPL, 0x40); - /* CSM mode key,TL controll */ - if(OPL->mode & 0x80) { /* CSM mode total level latch and auto key on */ - int ch; - if(OPL->UpdateHandler) - OPL->UpdateHandler(OPL->UpdateParam,0); - for(ch = 0; ch < 9; ch++) - CSMKeyControll(&OPL->P_CH[ch]); - } - } - /* reload timer */ - if (OPL->TimerHandler) - (OPL->TimerHandler)(OPL->TimerParam + c, (double)OPL->T[c] * OPL->TimerBase); - return OPL->status >> 7; -} - -FM_OPL *makeAdlibOPL(int rate) { - // We need to emulate one YM3812 chip - int env_bits = FMOPL_ENV_BITS_HQ; - int eg_ent = FMOPL_EG_ENT_HQ; - - OPLBuildTables(env_bits, eg_ent); - return OPLCreate(OPL_TYPE_YM3812, 3579545, rate); -} - diff --git a/opl/fmopl.h b/opl/fmopl.h deleted file mode 100644 index 2bbe8363..00000000 --- a/opl/fmopl.h +++ /dev/null @@ -1,167 +0,0 @@ -/* This file is derived from fmopl.h from ScummVM. - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * 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. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * LGPL licensed version of MAMEs fmopl (V0.37a modified) by - * Tatsuyuki Satoh. Included from LGPL'ed AdPlug. - */ - - -#ifndef OPL_FMOPL_H -#define OPL_FMOPL_H - -#include "inttypes.h" - -enum { - FMOPL_ENV_BITS_HQ = 16, - FMOPL_ENV_BITS_MQ = 8, - FMOPL_ENV_BITS_LQ = 8, - FMOPL_EG_ENT_HQ = 4096, - FMOPL_EG_ENT_MQ = 1024, - FMOPL_EG_ENT_LQ = 128 -}; - -typedef void (*OPL_TIMERHANDLER)(int channel,double interval_Sec); -typedef void (*OPL_IRQHANDLER)(int param,int irq); -typedef void (*OPL_UPDATEHANDLER)(int param,int min_interval_us); - -#define OPL_TYPE_WAVESEL 0x01 /* waveform select */ - -/* Saving is necessary for member of the 'R' mark for suspend/resume */ -/* ---------- OPL one of slot ---------- */ -typedef struct fm_opl_slot { - int TL; /* total level :TL << 8 */ - int TLL; /* adjusted now TL */ - uint8_t KSR; /* key scale rate :(shift down bit) */ - int *AR; /* attack rate :&AR_TABLE[AR<<2] */ - int *DR; /* decay rate :&DR_TABLE[DR<<2] */ - int SL; /* sustain level :SL_TABLE[SL] */ - int *RR; /* release rate :&DR_TABLE[RR<<2] */ - uint8_t ksl; /* keyscale level :(shift down bits) */ - uint8_t ksr; /* key scale rate :kcode>>KSR */ - unsigned int mul; /* multiple :ML_TABLE[ML] */ - unsigned int Cnt; /* frequency count */ - unsigned int Incr; /* frequency step */ - - /* envelope generator state */ - uint8_t eg_typ;/* envelope type flag */ - uint8_t evm; /* envelope phase */ - int evc; /* envelope counter */ - int eve; /* envelope counter end point */ - int evs; /* envelope counter step */ - int evsa; /* envelope step for AR :AR[ksr] */ - int evsd; /* envelope step for DR :DR[ksr] */ - int evsr; /* envelope step for RR :RR[ksr] */ - - /* LFO */ - uint8_t ams; /* ams flag */ - uint8_t vib; /* vibrate flag */ - /* wave selector */ - int **wavetable; -} OPL_SLOT; - -/* ---------- OPL one of channel ---------- */ -typedef struct fm_opl_channel { - OPL_SLOT SLOT[2]; - uint8_t CON; /* connection type */ - uint8_t FB; /* feed back :(shift down bit)*/ - int *connect1; /* slot1 output pointer */ - int *connect2; /* slot2 output pointer */ - int op1_out[2]; /* slot1 output for selfeedback */ - - /* phase generator state */ - unsigned int block_fnum; /* block+fnum */ - uint8_t kcode; /* key code : KeyScaleCode */ - unsigned int fc; /* Freq. Increment base */ - unsigned int ksl_base; /* KeyScaleLevel Base step */ - uint8_t keyon; /* key on/off flag */ -} OPL_CH; - -/* OPL state */ -typedef struct fm_opl_f { - uint8_t type; /* chip type */ - int clock; /* master clock (Hz) */ - int rate; /* sampling rate (Hz) */ - double freqbase; /* frequency base */ - double TimerBase; /* Timer base time (==sampling time) */ - uint8_t address; /* address register */ - uint8_t status; /* status flag */ - uint8_t statusmask; /* status mask */ - unsigned int mode; /* Reg.08 : CSM , notesel,etc. */ - - /* Timer */ - int T[2]; /* timer counter */ - uint8_t st[2]; /* timer enable */ - - /* FM channel slots */ - OPL_CH *P_CH; /* pointer of CH */ - int max_ch; /* maximum channel */ - - /* Rythm sention */ - uint8_t rythm; /* Rythm mode , key flag */ - - /* time tables */ - int AR_TABLE[76]; /* atttack rate tables */ - int DR_TABLE[76]; /* decay rate tables */ - unsigned int FN_TABLE[1024];/* fnumber -> increment counter */ - - /* LFO */ - int *ams_table; - int *vib_table; - int amsCnt; - int amsIncr; - int vibCnt; - int vibIncr; - - /* wave selector enable flag */ - uint8_t wavesel; - - /* external event callback handler */ - OPL_TIMERHANDLER TimerHandler; /* TIMER handler */ - int TimerParam; /* TIMER parameter */ - OPL_IRQHANDLER IRQHandler; /* IRQ handler */ - int IRQParam; /* IRQ parameter */ - OPL_UPDATEHANDLER UpdateHandler; /* stream update handler */ - int UpdateParam; /* stream update parameter */ -} FM_OPL; - -/* ---------- Generic interface section ---------- */ -#define OPL_TYPE_YM3526 (0) -#define OPL_TYPE_YM3812 (OPL_TYPE_WAVESEL) - -void OPLBuildTables(int ENV_BITS_PARAM, int EG_ENT_PARAM); - -FM_OPL *OPLCreate(int type, int clock, int rate); -void OPLDestroy(FM_OPL *OPL); -void OPLSetTimerHandler(FM_OPL *OPL, OPL_TIMERHANDLER TimerHandler, int channelOffset); -void OPLSetIRQHandler(FM_OPL *OPL, OPL_IRQHANDLER IRQHandler, int param); -void OPLSetUpdateHandler(FM_OPL *OPL, OPL_UPDATEHANDLER UpdateHandler, int param); - -void OPLResetChip(FM_OPL *OPL); -int OPLWrite(FM_OPL *OPL, int a, int v); -unsigned char OPLRead(FM_OPL *OPL, int a); -int OPLTimerOver(FM_OPL *OPL, int c); -void OPLWriteReg(FM_OPL *OPL, int r, int v); -void YM3812UpdateOne(FM_OPL *OPL, int16_t *buffer, int length, int interleave); - -// Factory method -FM_OPL *makeAdlibOPL(int rate); - -#endif - diff --git a/opl/opl_sdl.c b/opl/opl_sdl.c index 1963d5cd..8b7d76e5 100644 --- a/opl/opl_sdl.c +++ b/opl/opl_sdl.c @@ -33,7 +33,7 @@ #include "SDL.h" #include "SDL_mixer.h" -#include "fmopl.h" +#include "dbopl.h" #include "opl.h" #include "opl_internal.h" @@ -42,6 +42,14 @@ #define MAX_SOUND_SLICE_TIME 100 /* ms */ +typedef struct +{ + unsigned int rate; // Number of times the timer is advanced per sec. + unsigned int enabled; // Non-zero if timer is enabled. + unsigned int value; // Last value that was set. + unsigned int expire_time; // Calculated time that timer will expire. +} opl_timer_t; + // When the callback mutex is locked using OPL_Lock, callback functions // are not invoked. @@ -70,11 +78,20 @@ static unsigned int pause_offset; // OPL software emulator structure. -static FM_OPL *opl_emulator = NULL; +static Chip opl_chip; // Temporary mixing buffer used by the mixing callback. -static int16_t *mix_buffer = NULL; +static int32_t *mix_buffer = NULL; + +// Register number that was written. + +static int register_num = 0; + +// Timers; DBOPL does not do timer stuff itself. + +static opl_timer_t timer1 = { 12500, 0, 0, 0 }; +static opl_timer_t timer2 = { 3125, 0, 0, 0 }; // SDL parameters. @@ -153,14 +170,14 @@ static void FillBuffer(int16_t *buffer, unsigned int nsamples) assert(nsamples < mixing_freq); - YM3812UpdateOne(opl_emulator, mix_buffer, nsamples, 0); + Chip__GenerateBlock2(&opl_chip, nsamples, mix_buffer); // Mix into the destination buffer, doubling up into stereo. for (i=0; i timer1.expire_time) { - return OPLRead(opl_emulator, port); + result |= 0x80; // Either have expired + result |= 0x40; // Timer 1 has expired } - else + + if (timer2.enabled && current_time > timer2.expire_time) { - return 0; + result |= 0x80; // Either have expired + result |= 0x20; // Timer 2 has expired + } + + return result; +} + +static void OPLTimer_CalculateEndTime(opl_timer_t *timer) +{ + int tics; + + // If the timer is enabled, calculate the time when the timer + // will expire. + + if (timer->enabled) + { + tics = 0x100 - timer->value; + timer->expire_time = current_time + + (tics * opl_sample_rate) / timer->rate; + } +} + +static void WriteRegister(unsigned int reg_num, unsigned int value) +{ + switch (reg_num) + { + case OPL_REG_TIMER1: + timer1.value = value; + OPLTimer_CalculateEndTime(&timer1); + break; + + case OPL_REG_TIMER2: + timer2.value = value; + OPLTimer_CalculateEndTime(&timer2); + break; + + case OPL_REG_TIMER_CTRL: + if (value & 0x80) + { + timer1.enabled = 0; + timer2.enabled = 0; + } + else + { + if ((value & 0x40) == 0) + { + timer1.enabled = (value & 0x01) != 0; + OPLTimer_CalculateEndTime(&timer1); + } + + if ((value & 0x20) == 0) + { + timer1.enabled = (value & 0x02) != 0; + OPLTimer_CalculateEndTime(&timer2); + } + } + + break; + + default: + Chip__WriteReg(&opl_chip, reg_num, value); + break; } } static void OPL_SDL_PortWrite(opl_port_t port, unsigned int value) { - if (opl_emulator != NULL) + if (port == OPL_REGISTER_PORT) + { + register_num = value; + } + else if (port == OPL_DATA_PORT) { - OPLWrite(opl_emulator, port, value); + WriteRegister(register_num, value); } } -- cgit v1.2.3 From 60226b1183f5537fdde881e34e863e21c7e24d7e Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sun, 15 Aug 2010 15:23:28 +0000 Subject: Fix volume multiply; DBOPL now generating output. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1957 --- opl/opl_sdl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opl/opl_sdl.c b/opl/opl_sdl.c index 8b7d76e5..f6a3b229 100644 --- a/opl/opl_sdl.c +++ b/opl/opl_sdl.c @@ -176,8 +176,8 @@ static void FillBuffer(int16_t *buffer, unsigned int nsamples) for (i=0; ipixel static boolean native_surface; @@ -430,29 +434,58 @@ void I_StartFrame (void) } -static int MouseButtonState(void) +static void UpdateMouseButtonState(unsigned int button, boolean on) { - Uint8 state; - int result = 0; + event_t event; -#if SDL_VERSION_ATLEAST(1, 3, 0) - state = SDL_GetMouseState(0, NULL, NULL); -#else - state = SDL_GetMouseState(NULL, NULL); -#endif + if (button < SDL_BUTTON_LEFT || button > MAX_MOUSE_BUTTONS) + { + return; + } // Note: button "0" is left, button "1" is right, // button "2" is middle for Doom. This is different // to how SDL sees things. - if (state & SDL_BUTTON(1)) - result |= 1; - if (state & SDL_BUTTON(3)) - result |= 2; - if (state & SDL_BUTTON(2)) - result |= 4; + switch (button) + { + case SDL_BUTTON_LEFT: + button = 0; + break; - return result; + case SDL_BUTTON_RIGHT: + button = 1; + break; + + case SDL_BUTTON_MIDDLE: + button = 2; + break; + + default: + // SDL buttons are indexed from 1. + --button; + break; + } + + printf("button %i -> %s\n", button, on ? "on" : "off"); + + // Turn bit representing this button on or off. + + if (on) + { + mouse_button_state |= (1 << button); + } + else + { + mouse_button_state &= ~(1 << button); + } + + // Post an event with the new button state. + + event.type = ev_mouse; + event.data1 = mouse_button_state; + event.data2 = event.data3 = 0; + D_PostEvent(&event); } static int AccelerateMouse(int val) @@ -544,7 +577,7 @@ void I_GetEvent(void) /* case SDL_MOUSEMOTION: event.type = ev_mouse; - event.data1 = MouseButtonState(); + event.data1 = mouse_button_state; event.data2 = AccelerateMouse(sdlevent.motion.xrel); event.data3 = -AccelerateMouse(sdlevent.motion.yrel); D_PostEvent(&event); @@ -554,20 +587,14 @@ void I_GetEvent(void) case SDL_MOUSEBUTTONDOWN: if (usemouse && !nomouse) { - event.type = ev_mouse; - event.data1 = MouseButtonState(); - event.data2 = event.data3 = 0; - D_PostEvent(&event); + UpdateMouseButtonState(sdlevent.button.button, true); } break; case SDL_MOUSEBUTTONUP: if (usemouse && !nomouse) { - event.type = ev_mouse; - event.data1 = MouseButtonState(); - event.data2 = event.data3 = 0; - D_PostEvent(&event); + UpdateMouseButtonState(sdlevent.button.button, false); } break; @@ -637,7 +664,7 @@ static void I_ReadMouse(void) if (x != 0 || y != 0) { ev.type = ev_mouse; - ev.data1 = MouseButtonState(); + ev.data1 = mouse_button_state; ev.data2 = AccelerateMouse(x); ev.data3 = -AccelerateMouse(y); diff --git a/src/i_video.h b/src/i_video.h index bd5de24a..94ffcc29 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -28,10 +28,11 @@ #ifndef __I_VIDEO__ #define __I_VIDEO__ - #include "doomtype.h" -typedef struct +#define MAX_MOUSE_BUTTONS 8 + +typedef struct { // Screen width and height -- cgit v1.2.3 From d6a516833146d29d5e7b0d4f8ed6b80ecb193b88 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Fri, 20 Aug 2010 12:20:58 +0000 Subject: Align memory allocated by zone memory system to 8 byte boundaries on 64-bit machines. Possibly fixes problems on sparc64? Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1959 --- src/z_zone.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/z_zone.c b/src/z_zone.c index 975f41e5..2877fe6e 100644 --- a/src/z_zone.c +++ b/src/z_zone.c @@ -41,6 +41,7 @@ // because it will get overwritten automatically if needed. // +#define MEM_ALIGN sizeof(void *) #define ZONEID 0x1d4a11 typedef struct memblock_s @@ -201,7 +202,7 @@ Z_Malloc memblock_t* base; void *result; - size = (size + 3) & ~3; + size = (size + MEM_ALIGN - 1) & ~(MEM_ALIGN - 1); // scan through the block list, // looking for the first free block -- cgit v1.2.3 From 1d8283647fe152be88fad6b675c601ff8c423487 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Fri, 20 Aug 2010 13:01:29 +0000 Subject: Remove debug printf(). Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1960 --- src/i_video.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/i_video.c b/src/i_video.c index d2d0d169..ee10a12e 100644 --- a/src/i_video.c +++ b/src/i_video.c @@ -467,8 +467,6 @@ static void UpdateMouseButtonState(unsigned int button, boolean on) break; } - printf("button %i -> %s\n", button, on ? "on" : "off"); - // Turn bit representing this button on or off. if (on) -- cgit v1.2.3 From 3c1733b7b356efc7c4531242472a047fa23d1740 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 21 Aug 2010 17:47:24 +0000 Subject: "Bug fix". Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1961 --- setup/mainmenu.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/setup/mainmenu.c b/setup/mainmenu.c index 4ad1ac02..006a3547 100644 --- a/setup/mainmenu.c +++ b/setup/mainmenu.c @@ -45,6 +45,61 @@ #include "multiplayer.h" #include "sound.h" +static const int cheat_sequence[] = +{ + KEY_UPARROW, KEY_UPARROW, KEY_DOWNARROW, KEY_DOWNARROW, + KEY_LEFTARROW, KEY_RIGHTARROW, KEY_LEFTARROW, KEY_RIGHTARROW, + 'b', 'a', KEY_ENTER, 0 +}; + +static unsigned int cheat_sequence_index = 0; + +// I think these are good "sensible" defaults: + +static void SensibleDefaults(void) +{ + key_up = 'w'; + key_down = 's'; + key_strafeleft = 'a'; + key_straferight = 'd'; + mousebprevweapon = 4; + mousebnextweapon = 3; + snd_musicdevice = 3; + joybspeed = 29; + vanilla_savegame_limit = 0; + vanilla_keyboard_mapping = 0; + vanilla_demo_limit = 0; + show_endoom = 0; + dclick_use = 0; + novert = 1; +} + +static int MainMenuKeyPress(txt_window_t *window, int key, void *user_data) +{ + if (key == cheat_sequence[cheat_sequence_index]) + { + ++cheat_sequence_index; + + if (cheat_sequence[cheat_sequence_index] == 0) + { + SensibleDefaults(); + cheat_sequence_index = 0; + + window = TXT_NewWindow(NULL); + TXT_AddWidget(window, TXT_NewLabel(" \x01 ")); + TXT_SetWindowAction(window, TXT_HORIZ_RIGHT, NULL); + + return 1; + } + } + else + { + cheat_sequence_index = 0; + } + + return 0; +} + static void DoQuit(void *widget, void *dosave) { if (dosave != NULL) @@ -136,6 +191,8 @@ void MainMenu(void) quit_action = TXT_NewWindowAction(KEY_ESCAPE, "Quit"); TXT_SignalConnect(quit_action, "pressed", QuitConfirm, NULL); TXT_SetWindowAction(window, TXT_HORIZ_LEFT, quit_action); + + TXT_SetKeyListener(window, MainMenuKeyPress, NULL); } // -- cgit v1.2.3 From beaff1d633f780d2352cb68b880b96df81a1f673 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 21 Aug 2010 18:49:20 +0000 Subject: Change default mouse acceleration in setup tool to match the game's default. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1962 --- setup/mouse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/mouse.c b/setup/mouse.c index 559231b0..16984721 100644 --- a/setup/mouse.c +++ b/setup/mouse.c @@ -33,7 +33,7 @@ int usemouse = 1; int novert = 0; int mouseSensitivity = 5; -float mouse_acceleration = 1.0; +float mouse_acceleration = 2.0; int mouse_threshold = 10; int grabmouse = 1; -- cgit v1.2.3 From 14cf34bc65d7584984d26eea4154d58770125e60 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sun, 22 Aug 2010 01:21:27 +0000 Subject: Change span drawing functions to work the same as Vanilla, so that in screenshots, floors and ceilings are pixel-perfect identical to Vanilla Doom (thanks Porsche Monty). Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1963 --- src/r_draw.c | 111 ++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 61 insertions(+), 50 deletions(-) diff --git a/src/r_draw.c b/src/r_draw.c index 6813ea59..b7d847d9 100644 --- a/src/r_draw.c +++ b/src/r_draw.c @@ -594,48 +594,54 @@ int dscount; // Draws the actual span. void R_DrawSpan (void) { - fixed_t xfrac; - fixed_t yfrac; - byte* dest; - int count; - int spot; - -#ifdef RANGECHECK + unsigned int position, step; + byte *dest; + int count; + int spot; + unsigned int xtemp, ytemp; + +#ifdef RANGECHECK if (ds_x2 < ds_x1 || ds_x1<0 - || ds_x2>=SCREENWIDTH + || ds_x2>=SCREENWIDTH || (unsigned)ds_y>SCREENHEIGHT) { I_Error( "R_DrawSpan: %i to %i at %i", ds_x1,ds_x2,ds_y); } -// dscount++; -#endif +// dscount++; +#endif + + // Pack position and step variables into a single 32-bit integer, + // with x in the top 16 bits and y in the bottom 16 bits. For + // each 16-bit part, the top 6 bits are the integer part and the + // bottom 10 bits are the fractional part of the pixel position. + + position = ((ds_xfrac << 10) & 0xffff0000) + | ((ds_yfrac >> 6) & 0x0000ffff); + step = ((ds_xstep << 10) & 0xffff0000) + | ((ds_ystep >> 6) & 0x0000ffff); - - xfrac = ds_xfrac; - yfrac = ds_yfrac; - dest = ylookup[ds_y] + columnofs[ds_x1]; // We do not check for zero spans here? - count = ds_x2 - ds_x1; + count = ds_x2 - ds_x1; - do + do { - // Current texture index in u,v. - spot = ((yfrac>>(16-6))&(63*64)) + ((xfrac>>16)&63); + // Calculate current texture index in u,v. + ytemp = (position >> 4) & 0x0fc0; + xtemp = (position >> 26); + spot = xtemp | ytemp; // Lookup pixel from flat texture tile, // re-index using light/colormap. *dest++ = ds_colormap[ds_source[spot]]; - // Next step in u,v. - xfrac += ds_xstep; - yfrac += ds_ystep; - - } while (count--); -} + position += step; + + } while (count--); +} @@ -715,49 +721,54 @@ void R_DrawSpan (void) // // Again.. // -void R_DrawSpanLow (void) -{ - fixed_t xfrac; - fixed_t yfrac; - byte* dest; - int count; - int spot; - -#ifdef RANGECHECK +void R_DrawSpanLow (void) +{ + unsigned int position, step; + unsigned int xtemp, ytemp; + byte *dest; + int count; + int spot; + +#ifdef RANGECHECK if (ds_x2 < ds_x1 || ds_x1<0 - || ds_x2>=SCREENWIDTH + || ds_x2>=SCREENWIDTH || (unsigned)ds_y>SCREENHEIGHT) { I_Error( "R_DrawSpan: %i to %i at %i", ds_x1,ds_x2,ds_y); } // dscount++; -#endif - - xfrac = ds_xfrac; - yfrac = ds_yfrac; - - count = (ds_x2 - ds_x1); +#endif + + position = ((ds_xfrac << 10) & 0xffff0000) + | ((ds_yfrac >> 6) & 0x0000ffff); + step = ((ds_xstep << 10) & 0xffff0000) + | ((ds_ystep >> 6) & 0x0000ffff); + + count = (ds_x2 - ds_x1); // Blocky mode, need to multiply by 2. ds_x1 <<= 1; ds_x2 <<= 1; - + dest = ylookup[ds_y] + columnofs[ds_x1]; - - do - { - spot = ((yfrac>>(16-6))&(63*64)) + ((xfrac>>16)&63); + + do + { + // Calculate current texture index in u,v. + ytemp = (position >> 4) & 0x0fc0; + xtemp = (position >> 26); + spot = xtemp | ytemp; + // Lowres/blocky mode does it twice, // while scale is adjusted appropriately. - *dest++ = ds_colormap[ds_source[spot]]; *dest++ = ds_colormap[ds_source[spot]]; - - xfrac += ds_xstep; - yfrac += ds_ystep; + *dest++ = ds_colormap[ds_source[spot]]; - } while (count--); + position += step; + + } while (count--); } // -- cgit v1.2.3 From 966089e8bdc5d2cae9c1b9e889c9ca1405d6c29e Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sun, 22 Aug 2010 17:59:12 +0000 Subject: Shut up compiler warning. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1964 --- opl/dbopl.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/opl/dbopl.c b/opl/dbopl.c index a4bd6fe5..159cae45 100644 --- a/opl/dbopl.c +++ b/opl/dbopl.c @@ -1239,15 +1239,14 @@ void Chip__WriteReg(Chip *self, Bit32u reg, Bit8u val ) { } } - -static Bit32u Chip__WriteAddr(Chip *self, Bit32u port, Bit8u val ) { +Bit32u Chip__WriteAddr(Chip *self, Bit32u port, Bit8u val ) { switch ( port & 3 ) { case 0: return val; case 2: if ( self->opl3Active || (val == 0x05) ) return 0x100 | val; - else + else return val; } return 0; -- cgit v1.2.3 From b582e47695c2b3a19c477603a6559eb37df7ed8b Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 28 Aug 2010 18:28:05 +0000 Subject: Include INSTALL file in distribution packages. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1969 --- pkg/config.make.in | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/config.make.in b/pkg/config.make.in index d8d72c60..3fe757ff 100644 --- a/pkg/config.make.in +++ b/pkg/config.make.in @@ -21,6 +21,7 @@ PACKAGE_VERSION = @PACKAGE_VERSION@ DOC_FILES = README \ COPYING \ ChangeLog \ + INSTALL \ NEWS \ BUGS \ CMDLINE \ -- cgit v1.2.3 From 64918568eee62c73cbb87aa1bd68e191f19a4af3 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 28 Aug 2010 18:35:08 +0000 Subject: Update NEWS. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1970 --- NEWS | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/NEWS b/NEWS index c2705062..8fc37b5f 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,34 @@ +1.5.0 (2010-??-??): + + Big changes in this version: + * The DOSbox OPL emulator (DBOPL) has been imported to replace + the older FMOPL code. The quality of OPL emulation is now + therefore much better. + * When running in windowed mode, it is now possible to + dynamically resize the window by dragging the window borders. + * There are now keyboard, mouse and joystick bindings to cycle + through available weapons, making play with joypads or mobile + devices (ie. without a proper keyboard) much more practical. + * There is now a key binding to change the multiplayer spy key + (usually F12). + * There is now a configuration file parameter to set the OPL I/O + port, for cards that don't use port 0x388. + * Up to 8 mouse buttons are now supported (including the + mousewheel). + + Bugs fixed: + * It is now possible to use OPL emulation at 11025Hz sound + sampling rate (thanks to the new OPL emulator). + * The span renderer function (used for drawing floors and + ceilings) now behaves the same as Vanilla Doom, so screenshots + are pixel-perfect identical to Vanilla Doom (thanks Porsche + Monty). + * The zone memory system now aligns allocated memory to 8-byte + boundaries on 64-bit systems, which may fix crashes on systems + such as sparc64. + * The configure script now checks for libm, fixing compile + problems on Fedora Linux. + 1.4.0 (2010-07-10): The biggest change in this version is the addition of OPL -- cgit v1.2.3