aboutsummaryrefslogtreecommitdiff
path: root/src/fake86/sndsource.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2021-02-27 12:08:23 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2021-02-27 12:08:23 -0500
commitd49887486c772592c0e8ecc158c1cc3efb3f7709 (patch)
treeea5af335e7cee87f07de50082dd6ff66f3231353 /src/fake86/sndsource.c
downloadfake86-d49887486c772592c0e8ecc158c1cc3efb3f7709.tar.gz
Initial commit 0.13.9.16
Diffstat (limited to 'src/fake86/sndsource.c')
-rwxr-xr-xsrc/fake86/sndsource.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/fake86/sndsource.c b/src/fake86/sndsource.c
new file mode 100755
index 0000000..515d1c7
--- /dev/null
+++ b/src/fake86/sndsource.c
@@ -0,0 +1,82 @@
+/*
+ Fake86: A portable, open-source 8086 PC emulator.
+ Copyright (C)2010-2013 Mike Chambers
+
+ 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.
+*/
+
+/* ssource.c: functions to emulate the Disney Sound Source's 16-byte FIFO buffer. */
+
+#include "config.h"
+#include <stdint.h>
+
+extern void set_port_write_redirector (uint16_t startport, uint16_t endport, void *callback);
+extern void set_port_read_redirector (uint16_t startport, uint16_t endport, void *callback);
+
+extern uint8_t portram[0x10000];
+uint8_t ssourcebuf[16], ssourceptr = 0, ssourceactive = 0;
+int16_t ssourcecursample = 0;
+
+int16_t getssourcebyte() {
+ return (ssourcecursample);
+}
+
+void tickssource() {
+ uint8_t rotatefifo;
+ if ( (ssourceptr==0) || (!ssourceactive) ) {
+ ssourcecursample = 0;
+ return;
+ }
+ ssourcecursample = ssourcebuf[0];
+ for (rotatefifo=1; rotatefifo<16; rotatefifo++)
+ ssourcebuf[rotatefifo-1] = ssourcebuf[rotatefifo];
+ ssourceptr--;
+ portram[0x379] = 0;
+}
+
+void putssourcebyte (uint8_t value) {
+ if (ssourceptr==16) return;
+ ssourcebuf[ssourceptr++] = value;
+ if (ssourceptr==16) portram[0x379] = 0x40;
+}
+
+uint8_t ssourcefull() {
+ if (ssourceptr==16) return (0x40);
+ else return (0x00);
+}
+
+void outsoundsource (uint16_t portnum, uint8_t value) {
+ static uint8_t last37a = 0;
+ switch (portnum) {
+ case 0x378:
+ putssourcebyte (value);
+ break;
+ case 0x37A:
+ if ( (value & 4) && ! (last37a & 4) ) putssourcebyte (portram[0x378]);
+ last37a = value;
+ break;
+ }
+}
+
+uint8_t insoundsource (uint16_t portnum) {
+ return (ssourcefull() );
+}
+
+void initsoundsource() {
+ set_port_write_redirector (0x378, 0x378, &outsoundsource);
+ set_port_write_redirector (0x37A, 0x37A, &outsoundsource);
+ set_port_read_redirector (0x379, 0x379, &insoundsource);
+ ssourceactive = 1;
+}