Skip to content

Commit cbcc5b4

Browse files
committed
Initial RetroWave OPL3 board library support
1 parent c982f0a commit cbcc5b4

File tree

7 files changed

+171
-12
lines changed

7 files changed

+171
-12
lines changed

Diff for: .gitmodules

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[submodule "src/sound/RetroWave"]
2+
path = src/sound/RetroWave
3+
url = https://github.com/daemon32/RetroWave
4+
branch = 86box

Diff for: CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ cmake_dependent_option(NO_SIO "Machines without emulated Super I/O chips"
124124
cmake_dependent_option(OLIVETTI "Olivetti M290" ON "DEV_BRANCH" OFF)
125125
cmake_dependent_option(OPEN_AT "OpenAT" ON "DEV_BRANCH" OFF)
126126
cmake_dependent_option(PAS16 "Pro Audio Spectrum 16" OFF "DEV_BRANCH" OFF)
127+
cmake_dependent_option(RETROWAVE "RetroWave OPL3 support" ON "DEV_BRANCH" OFF)
127128
cmake_dependent_option(SIO_DETECT "Super I/O Detection Helper" ON "DEV_BRANCH" OFF)
128129
cmake_dependent_option(VGAWONDER "ATI VGA Wonder (ATI-18800)" ON "DEV_BRANCH" OFF)
129130
cmake_dependent_option(VNC "VNC renderer" OFF "DEV_BRANCH" OFF)

Diff for: src/include/86box/snd_opl_retrowave.h

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* 86Box A hypervisor and IBM PC system emulator that specializes in
3+
* running old operating systems and software designed for IBM
4+
* PC systems and compatibles from 1981 through fairly recent
5+
* system designs based on the PCI bus.
6+
*
7+
* This file is part of the 86Box distribution.
8+
*
9+
* Definitions for the RetroWave OPL driver.
10+
*
11+
* Version: @(#)snd_opl_retrowave.h 1.0.0 2021/12/22
12+
*
13+
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
14+
* Miran Grca, <mgrca8@gmail.com>
15+
*
16+
* Copyright 2017-2020 Fred N. van Kempen.
17+
* Copyright 2016-2019 Miran Grca.
18+
*/
19+
#ifndef SOUND_OPL_RETROWAVE_H
20+
# define SOUND_OPL_RETROWAVE_H
21+
22+
23+
extern void * retrowave_86box_module_init();
24+
extern void retrowave_close(void *);
25+
26+
extern uint16_t retrowave_write_addr(void *, uint16_t port, uint8_t val);
27+
extern void retrowave_write_reg(void *, uint16_t reg, uint8_t v);
28+
29+
extern void retrowave_generate_stream(void *, int32_t *sndptr, uint32_t num);
30+
31+
#endif /*SOUND_OPL_RETROWAVE_H*/

Diff for: src/sound/CMakeLists.txt

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# Copyright 2020,2021 David Hrdlička.
1414
#
1515

16-
add_library(snd OBJECT sound.c openal.c snd_opl.c snd_opl_nuked.c snd_resid.cc
16+
add_library(snd OBJECT sound.c openal.c snd_opl.c snd_opl_nuked.c snd_opl_retrowave.c snd_resid.cc
1717
midi.c midi_rtmidi.cpp snd_speaker.c snd_pssj.c snd_lpt_dac.c snd_ac97_codec.c snd_ac97_via.c
1818
snd_lpt_dss.c snd_adlib.c snd_adlibgold.c snd_ad1848.c snd_audiopci.c
1919
snd_azt2316a.c snd_cms.c snd_cs423x.c snd_gus.c snd_sb.c snd_sb_dsp.c
@@ -41,5 +41,10 @@ if(GUSMAX)
4141
target_compile_definitions(snd PRIVATE USE_GUSMAX)
4242
endif()
4343

44+
# Avoid building the player app, don't need it
45+
set(RETROWAVE_BUILD_PLAYER 0)
46+
4447
add_subdirectory(resid-fp)
45-
target_link_libraries(86Box resid-fp)
48+
add_subdirectory(RetroWave)
49+
target_link_libraries(86Box RetroWave)
50+
target_link_libraries(86Box resid-fp)

Diff for: src/sound/RetroWave

Submodule RetroWave added at 1c2c7a4

Diff for: src/sound/snd_opl.c

+10-10
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include <86box/io.h>
3232
#include <86box/sound.h>
3333
#include <86box/snd_opl.h>
34-
#include <86box/snd_opl_nuked.h>
34+
#include <86box/snd_opl_retrowave.h>
3535

3636

3737
enum {
@@ -155,7 +155,7 @@ static void
155155
opl_write(opl_t *dev, uint16_t port, uint8_t val)
156156
{
157157
if ((port & 0x0001) == 0x0001) {
158-
nuked_write_reg_buffered(dev->opl, dev->port, val);
158+
retrowave_write_reg(dev->opl, dev->port, val);
159159

160160
switch (dev->port) {
161161
case 0x02: /* Timer 1 */
@@ -181,7 +181,7 @@ opl_write(opl_t *dev, uint16_t port, uint8_t val)
181181
break;
182182
}
183183
} else {
184-
dev->port = nuked_write_addr(dev->opl, port, val) & 0x01ff;
184+
dev->port = retrowave_write_addr(dev->opl, port, val) & 0x01ff;
185185

186186
if (!(dev->flags & FLAG_OPL3))
187187
dev->port &= 0x00ff;
@@ -210,8 +210,8 @@ opl_init(opl_t *dev, int is_opl3)
210210
else
211211
dev->status = 0x06;
212212

213-
/* Create a NukedOPL object. */
214-
dev->opl = nuked_init(48000);
213+
/* Create a RetroWave object. */
214+
dev->opl = retrowave_86box_module_init();
215215

216216
timer_add(&dev->timers[0], timer_1, dev, 0);
217217
timer_add(&dev->timers[1], timer_2, dev, 0);
@@ -221,9 +221,9 @@ opl_init(opl_t *dev, int is_opl3)
221221
void
222222
opl_close(opl_t *dev)
223223
{
224-
/* Release the NukedOPL object. */
224+
/* Release the RetroWave object. */
225225
if (dev->opl) {
226-
nuked_close(dev->opl);
226+
retrowave_close(dev->opl);
227227
dev->opl = NULL;
228228
}
229229
}
@@ -270,7 +270,7 @@ opl2_update(opl_t *dev)
270270
return;
271271
}
272272

273-
nuked_generate_stream(dev->opl,
273+
retrowave_generate_stream(dev->opl,
274274
&dev->buffer[dev->pos * 2],
275275
sound_pos_global - dev->pos);
276276

@@ -299,7 +299,7 @@ void
299299
opl3_write(uint16_t port, uint8_t val, void *priv)
300300
{
301301
opl_t *dev = (opl_t *)priv;
302-
302+
303303
opl3_update(dev);
304304

305305
opl_write(dev, port, val);
@@ -320,7 +320,7 @@ opl3_update(opl_t *dev)
320320
if (dev->pos >= sound_pos_global)
321321
return;
322322

323-
nuked_generate_stream(dev->opl,
323+
retrowave_generate_stream(dev->opl,
324324
&dev->buffer[dev->pos * 2],
325325
sound_pos_global - dev->pos);
326326

Diff for: src/sound/snd_opl_retrowave.c

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* 86Box A hypervisor and IBM PC system emulator that specializes in
3+
* running old operating systems and software designed for IBM
4+
* PC systems and compatibles from 1981 through fairly recent
5+
* system designs based on the PCI bus.
6+
*
7+
* This file is part of the 86Box distribution.
8+
*
9+
* RetroWave OPL3 bridge.
10+
*
11+
* Version: 1.0.0
12+
*
13+
* Version: @(#)snd_opl_retrowave.c 1.0.0 2021/12/22
14+
*
15+
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
16+
* Miran Grca, <mgrca8@gmail.com>
17+
* Alexey Khokholov (Nuke.YKT)
18+
*
19+
* Copyright 2017-2020 Fred N. van Kempen.
20+
* Copyright 2016-2020 Miran Grca.
21+
* Copyright 2013-2018 Alexey Khokholov (Nuke.YKT)
22+
*/
23+
#include <stdint.h>
24+
#include <stdio.h>
25+
#include <stdlib.h>
26+
#include <string.h>
27+
#include <86box/86box.h>
28+
#include <86box/timer.h>
29+
#include <86box/sound.h>
30+
#include <86box/snd_opl_retrowave.h>
31+
#include "RetroWave/RetroWaveLib/RetroWave_86Box.h"
32+
33+
34+
#define WRBUF_SIZE 1024
35+
#define WRBUF_DELAY 1
36+
#define RSM_FRAC 10
37+
38+
39+
struct chip;
40+
41+
typedef struct chip {
42+
uint8_t opl3_port;
43+
} retrowave_t;
44+
45+
46+
uint16_t
47+
retrowave_write_addr(void *priv, uint16_t port, uint8_t val)
48+
{
49+
retrowave_t *dev = (retrowave_t *)priv;
50+
// printf("writeaddr: 0x%08x 0x%02x\n", port, val);
51+
52+
switch (port & 3) {
53+
case 0:
54+
dev->opl3_port = 0;
55+
return val;
56+
case 2:
57+
dev->opl3_port = 1;
58+
if (val == 0x05)
59+
return 0x100 | val;
60+
else
61+
return val;
62+
}
63+
}
64+
65+
66+
void
67+
retrowave_write_reg(void *priv, uint16_t reg, uint8_t val)
68+
{
69+
retrowave_t *dev = (retrowave_t *)priv;
70+
// printf("writereg: 0x%08x 0x%02x\n", reg, val);
71+
72+
uint8_t real_reg = reg & 0xff;
73+
uint8_t real_val = val;
74+
75+
if (dev->opl3_port) {
76+
retrowave_opl3_queue_port1(&retrowave_global_context, real_reg, real_val);
77+
} else {
78+
retrowave_opl3_queue_port0(&retrowave_global_context, real_reg, real_val);
79+
}
80+
}
81+
82+
83+
void *
84+
retrowave_86box_module_init()
85+
{
86+
retrowave_t *dev;
87+
uint8_t i;
88+
89+
dev = (retrowave_t *)malloc(sizeof(retrowave_t));
90+
memset(dev, 0x00, sizeof(retrowave_t));
91+
92+
dev->opl3_port = 0;
93+
94+
retrowave_init_86box("ttyOPL");
95+
retrowave_opl3_reset(&retrowave_global_context);
96+
97+
return(dev);
98+
}
99+
100+
101+
void
102+
retrowave_close(void *priv)
103+
{
104+
retrowave_t *dev = (retrowave_t *)priv;
105+
106+
free(dev);
107+
}
108+
109+
110+
void
111+
retrowave_generate_stream(void *priv, int32_t *sndptr, uint32_t num)
112+
{
113+
retrowave_t *dev = (retrowave_t *)priv;
114+
uint32_t i;
115+
116+
retrowave_flush(&retrowave_global_context);
117+
}

0 commit comments

Comments
 (0)