2017-06-14 03:03:29 +02:00
|
|
|
/* Copyright holders: Sarah Walker, SA1988
|
2016-08-14 22:07:17 -04:00
|
|
|
see COPYING for more details
|
|
|
|
|
*/
|
2017-05-06 17:48:33 +02:00
|
|
|
#include "dbopl.h"
|
|
|
|
|
#include "nukedopl.h"
|
2018-04-25 23:51:13 +02:00
|
|
|
#include "sound.h"
|
2017-05-06 17:48:33 +02:00
|
|
|
#include "snd_dbopl.h"
|
|
|
|
|
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2018-04-25 23:51:13 +02:00
|
|
|
int opl_type = 0;
|
2017-01-31 20:39:36 +01:00
|
|
|
|
2017-05-06 17:48:33 +02:00
|
|
|
|
2016-06-26 00:34:39 +02:00
|
|
|
static struct
|
|
|
|
|
{
|
|
|
|
|
DBOPL::Chip chip;
|
2018-04-25 23:51:13 +02:00
|
|
|
opl3_chip opl3chip;
|
2016-06-26 00:34:39 +02:00
|
|
|
int addr;
|
|
|
|
|
int timer[2];
|
|
|
|
|
uint8_t timer_ctrl;
|
|
|
|
|
uint8_t status_mask;
|
|
|
|
|
uint8_t status;
|
|
|
|
|
int is_opl3;
|
2018-04-25 23:51:13 +02:00
|
|
|
|
Added the IBM 5161 ISA expansion for PC and XT;
Cleaned up the parallel port emulation, added IRQ support, and made enabling/disabling per port;
Added the Award 430NX and the Intel Classic/PCI (Alfredo, 420TX);
Finished the 586MC1;
Added 8087 emulation;
Moved Cyrix 6x86'es to the Dev branch;
Sanitized/cleaned up memregs.c/h and intel.c/h;
Split the chipsets from machines and sanitized Port 92 emulation;
Added support for the 15bpp mode to the Compaq ATI 28800;
Moved the MR 386DX and 486 machines to the Dev branch;
Ported the new dynamic recompiler from PCem, but it remains in Dev branch until after v2.00;
Ported the new timer code from PCem;
Cleaned up the CPU table of unused stuff and better optimized its structure;
Ported the Open-XT and Open-AT from VARCem, the Open-AT is in the Dev branch;
Ported the XT MFM controller rewrite and adding of more controllers (incl. two RLL ones), from VARCem;
Added the AHA-1540A and the BusTek BT-542B;
Moved the Sumo SCSI-AT to the Dev branch;
Minor IDE, FDC, and floppy drive code clean-ups;
Made NCR 5380/53C400-based cards' BIOS address configurable;
Got rid of the legacy romset variable;
Unified (video) buffer and buffer32 into one and make the unified buffer 32-bit;
Added the Amstead PPC512 per PCem patch by John Elliott;
Switched memory mapping granularity from 16k to 4k (less than 1k not possible due to internal pages);
Rewrote the CL-GD 54xx blitter, fixes Win-OS/2 on the 54x6 among other thing;
Added the Image Manager 1024 and Professional Graphics Controller per PCem patch by John Elliott and work done on VARCem;
Added Headland HT-216, GC-205 and Video 7 VGA 1024i emulation based on PCem commit;
Implemented the fuction keys for the Toshiba T1000/T1200/T3100 enhancement;
Amstrad MegaPC does now works correctly with non-internal graphics card;
The SLiRP code no longer casts a packed struct type to a non-packed struct type;
The Xi8088 and PB410a no longer hang on 86Box when PS/2 mouse is not present;
The S3 Virge on BeOS is no longer broken (was broken by build #1591);
OS/2 2.0 build 6.167 now sees key presses again;
Xi8088 now work on CGA again;
86F images converted from either the old or new variants of the HxC MFM format now work correctly;
Hardware interrupts with a vector of 0xFF are now handled correctly;
OPTi 495SX boards no longer incorrectly have 64 MB maximum RAM when 32 MB is correct;
Fixed VNC keyboard input bugs;
Fixed AT RTC periodic interrupt - Chicago 58s / 73f / 73g / 81 MIDI play no longer hangs with the build's own VTD driver;
Fixed mouse polling with internal mice - Amstrad and Olivetti mice now work correctly;
Triones ATAPI DMA driver now correctly reads a file at the end of a CD image with a sectors number not divisible by 4;
Compaq Portable now works with all graphics cards;
Fixed various MDSI Genius bugs;
Added segment limit checks and improved page fault checks for several CPU instructions - Memphis 15xx WINSETUP and Chicago 58s WINDISK.CPL no longer issue a GPF, and some S3 drivers that used to have glitches, now work correctly;
Further improved the 808x emulation, also fixes the noticably choppy sound when using 808x CPU's, also fixes #355;
OS/2 installer no logner locks up on splash screen on PS/2 Model 70 and 80, fixes #400.
Fixed several Amstead bugs, GEM no longer crashes on the Amstrad 1640, fixes #391.
Ported John Elliott's Amstrad fixes and improvement from PCem, and fixed the default language so it's correctly Engliish, fixes #278, fixes #389.
Fixed a minor IDE timing bug, fixes #388.
Fixed Toshiba T1000 RAM issues, fixes #379.
Fixed EGA/(S)VGA overscan border handling, fixes #378;
Got rid of the now long useless IDE channel 2 auto-removal, fixes #370;
Fixed the BIOS files used by the AMSTRAD PC1512, fixes #366;
Ported the Unicode CD image file name fix from VARCem, fixes #365;
Fixed high density floppy disks on the Xi8088, fixes #359;
Fixed some bugs in the Hercules emulation, fixes #346, fixes #358;
Fixed the SCSI hard disk mode sense pages, fixes #356;
Removed the AMI Unknown 386SX because of impossibility to identify the chipset, closes #349;
Fixed bugs in the serial mouse emulation, fixes #344;
Compiled 86Box binaries now include all the required .DLL's, fixes #341;
Made some combo boxes in the Settings dialog slightly wider, fixes #276.
2019-09-20 14:02:30 +02:00
|
|
|
void (*timer_callback)(void *param, int timer, uint64_t period);
|
2016-06-26 00:34:39 +02:00
|
|
|
void *timer_param;
|
|
|
|
|
} opl[2];
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
STATUS_TIMER_1 = 0x40,
|
|
|
|
|
STATUS_TIMER_2 = 0x20,
|
|
|
|
|
STATUS_TIMER_ALL = 0x80
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
CTRL_IRQ_RESET = 0x80,
|
|
|
|
|
CTRL_TIMER1_MASK = 0x40,
|
|
|
|
|
CTRL_TIMER2_MASK = 0x20,
|
|
|
|
|
CTRL_TIMER2_CTRL = 0x02,
|
|
|
|
|
CTRL_TIMER1_CTRL = 0x01
|
|
|
|
|
};
|
|
|
|
|
|
Added the IBM 5161 ISA expansion for PC and XT;
Cleaned up the parallel port emulation, added IRQ support, and made enabling/disabling per port;
Added the Award 430NX and the Intel Classic/PCI (Alfredo, 420TX);
Finished the 586MC1;
Added 8087 emulation;
Moved Cyrix 6x86'es to the Dev branch;
Sanitized/cleaned up memregs.c/h and intel.c/h;
Split the chipsets from machines and sanitized Port 92 emulation;
Added support for the 15bpp mode to the Compaq ATI 28800;
Moved the MR 386DX and 486 machines to the Dev branch;
Ported the new dynamic recompiler from PCem, but it remains in Dev branch until after v2.00;
Ported the new timer code from PCem;
Cleaned up the CPU table of unused stuff and better optimized its structure;
Ported the Open-XT and Open-AT from VARCem, the Open-AT is in the Dev branch;
Ported the XT MFM controller rewrite and adding of more controllers (incl. two RLL ones), from VARCem;
Added the AHA-1540A and the BusTek BT-542B;
Moved the Sumo SCSI-AT to the Dev branch;
Minor IDE, FDC, and floppy drive code clean-ups;
Made NCR 5380/53C400-based cards' BIOS address configurable;
Got rid of the legacy romset variable;
Unified (video) buffer and buffer32 into one and make the unified buffer 32-bit;
Added the Amstead PPC512 per PCem patch by John Elliott;
Switched memory mapping granularity from 16k to 4k (less than 1k not possible due to internal pages);
Rewrote the CL-GD 54xx blitter, fixes Win-OS/2 on the 54x6 among other thing;
Added the Image Manager 1024 and Professional Graphics Controller per PCem patch by John Elliott and work done on VARCem;
Added Headland HT-216, GC-205 and Video 7 VGA 1024i emulation based on PCem commit;
Implemented the fuction keys for the Toshiba T1000/T1200/T3100 enhancement;
Amstrad MegaPC does now works correctly with non-internal graphics card;
The SLiRP code no longer casts a packed struct type to a non-packed struct type;
The Xi8088 and PB410a no longer hang on 86Box when PS/2 mouse is not present;
The S3 Virge on BeOS is no longer broken (was broken by build #1591);
OS/2 2.0 build 6.167 now sees key presses again;
Xi8088 now work on CGA again;
86F images converted from either the old or new variants of the HxC MFM format now work correctly;
Hardware interrupts with a vector of 0xFF are now handled correctly;
OPTi 495SX boards no longer incorrectly have 64 MB maximum RAM when 32 MB is correct;
Fixed VNC keyboard input bugs;
Fixed AT RTC periodic interrupt - Chicago 58s / 73f / 73g / 81 MIDI play no longer hangs with the build's own VTD driver;
Fixed mouse polling with internal mice - Amstrad and Olivetti mice now work correctly;
Triones ATAPI DMA driver now correctly reads a file at the end of a CD image with a sectors number not divisible by 4;
Compaq Portable now works with all graphics cards;
Fixed various MDSI Genius bugs;
Added segment limit checks and improved page fault checks for several CPU instructions - Memphis 15xx WINSETUP and Chicago 58s WINDISK.CPL no longer issue a GPF, and some S3 drivers that used to have glitches, now work correctly;
Further improved the 808x emulation, also fixes the noticably choppy sound when using 808x CPU's, also fixes #355;
OS/2 installer no logner locks up on splash screen on PS/2 Model 70 and 80, fixes #400.
Fixed several Amstead bugs, GEM no longer crashes on the Amstrad 1640, fixes #391.
Ported John Elliott's Amstrad fixes and improvement from PCem, and fixed the default language so it's correctly Engliish, fixes #278, fixes #389.
Fixed a minor IDE timing bug, fixes #388.
Fixed Toshiba T1000 RAM issues, fixes #379.
Fixed EGA/(S)VGA overscan border handling, fixes #378;
Got rid of the now long useless IDE channel 2 auto-removal, fixes #370;
Fixed the BIOS files used by the AMSTRAD PC1512, fixes #366;
Ported the Unicode CD image file name fix from VARCem, fixes #365;
Fixed high density floppy disks on the Xi8088, fixes #359;
Fixed some bugs in the Hercules emulation, fixes #346, fixes #358;
Fixed the SCSI hard disk mode sense pages, fixes #356;
Removed the AMI Unknown 386SX because of impossibility to identify the chipset, closes #349;
Fixed bugs in the serial mouse emulation, fixes #344;
Compiled 86Box binaries now include all the required .DLL's, fixes #341;
Made some combo boxes in the Settings dialog slightly wider, fixes #276.
2019-09-20 14:02:30 +02:00
|
|
|
void opl_init(void (*timer_callback)(void *param, int timer, uint64_t period), void *timer_param, int nr, int is_opl3)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2018-04-25 23:51:13 +02:00
|
|
|
opl[nr].timer_callback = timer_callback;
|
|
|
|
|
opl[nr].timer_param = timer_param;
|
|
|
|
|
opl[nr].is_opl3 = is_opl3;
|
|
|
|
|
|
|
|
|
|
if (!opl_type)
|
2016-08-08 02:52:53 +02:00
|
|
|
{
|
2018-04-25 23:51:13 +02:00
|
|
|
DBOPL::InitTables();
|
|
|
|
|
opl[nr].chip.Setup(48000, is_opl3);
|
2016-08-08 02:52:53 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-04-25 23:51:13 +02:00
|
|
|
opl[nr].opl3chip.newm = 0;
|
|
|
|
|
OPL3_Reset(&opl[nr].opl3chip, 48000);
|
2016-08-08 02:52:53 +02:00
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void opl_status_update(int nr)
|
|
|
|
|
{
|
|
|
|
|
if (opl[nr].status & (STATUS_TIMER_1 | STATUS_TIMER_2) & opl[nr].status_mask)
|
|
|
|
|
opl[nr].status |= STATUS_TIMER_ALL;
|
|
|
|
|
else
|
|
|
|
|
opl[nr].status &= ~STATUS_TIMER_ALL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void opl_timer_over(int nr, int timer)
|
|
|
|
|
{
|
|
|
|
|
if (!timer)
|
|
|
|
|
{
|
|
|
|
|
opl[nr].status |= STATUS_TIMER_1;
|
|
|
|
|
opl[nr].timer_callback(opl[nr].timer_param, 0, opl[nr].timer[0] * 4);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
opl[nr].status |= STATUS_TIMER_2;
|
|
|
|
|
opl[nr].timer_callback(opl[nr].timer_param, 1, opl[nr].timer[1] * 16);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
opl_status_update(nr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void opl_write(int nr, uint16_t addr, uint8_t val)
|
|
|
|
|
{
|
|
|
|
|
if (!(addr & 1))
|
2017-02-07 02:19:48 +01:00
|
|
|
{
|
2018-04-25 23:51:13 +02:00
|
|
|
if (!opl_type)
|
|
|
|
|
opl[nr].addr = (int)opl[nr].chip.WriteAddr(addr, val) & 0x1ff;
|
2017-02-07 02:19:48 +01:00
|
|
|
else
|
|
|
|
|
opl[nr].addr = (int)OPL3_WriteAddr(&opl[nr].opl3chip, addr, val) & 0x1ff;
|
2018-04-25 23:51:13 +02:00
|
|
|
if (!opl[nr].is_opl3)
|
|
|
|
|
opl[nr].addr &= 0xff;
|
2017-02-07 02:19:48 +01:00
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
else
|
|
|
|
|
{
|
2018-04-25 23:51:13 +02:00
|
|
|
if (!opl_type)
|
2017-02-07 02:19:48 +01:00
|
|
|
opl[nr].chip.WriteReg(opl[nr].addr, val);
|
2018-04-25 23:51:13 +02:00
|
|
|
else {
|
|
|
|
|
OPL3_WriteRegBuffered(&opl[nr].opl3chip, (uint16_t) opl[nr].addr, val);
|
|
|
|
|
if (opl[nr].addr == 0x105)
|
|
|
|
|
opl[nr].opl3chip.newm = opl[nr].addr & 0x01;
|
|
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
|
|
|
|
|
switch (opl[nr].addr)
|
|
|
|
|
{
|
|
|
|
|
case 0x02: /*Timer 1*/
|
|
|
|
|
opl[nr].timer[0] = 256 - val;
|
|
|
|
|
break;
|
|
|
|
|
case 0x03: /*Timer 2*/
|
|
|
|
|
opl[nr].timer[1] = 256 - val;
|
|
|
|
|
break;
|
|
|
|
|
case 0x04: /*Timer control*/
|
|
|
|
|
if (val & CTRL_IRQ_RESET) /*IRQ reset*/
|
|
|
|
|
{
|
|
|
|
|
opl[nr].status &= ~(STATUS_TIMER_1 | STATUS_TIMER_2);
|
|
|
|
|
opl_status_update(nr);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ((val ^ opl[nr].timer_ctrl) & CTRL_TIMER1_CTRL)
|
|
|
|
|
{
|
|
|
|
|
if (val & CTRL_TIMER1_CTRL)
|
|
|
|
|
opl[nr].timer_callback(opl[nr].timer_param, 0, opl[nr].timer[0] * 4);
|
|
|
|
|
else
|
|
|
|
|
opl[nr].timer_callback(opl[nr].timer_param, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
if ((val ^ opl[nr].timer_ctrl) & CTRL_TIMER2_CTRL)
|
|
|
|
|
{
|
|
|
|
|
if (val & CTRL_TIMER2_CTRL)
|
|
|
|
|
opl[nr].timer_callback(opl[nr].timer_param, 1, opl[nr].timer[1] * 16);
|
|
|
|
|
else
|
|
|
|
|
opl[nr].timer_callback(opl[nr].timer_param, 1, 0);
|
|
|
|
|
}
|
|
|
|
|
opl[nr].status_mask = (~val & (CTRL_TIMER1_MASK | CTRL_TIMER2_MASK)) | 0x80;
|
|
|
|
|
opl[nr].timer_ctrl = val;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t opl_read(int nr, uint16_t addr)
|
|
|
|
|
{
|
|
|
|
|
if (!(addr & 1))
|
|
|
|
|
{
|
|
|
|
|
return (opl[nr].status & opl[nr].status_mask) | (opl[nr].is_opl3 ? 0 : 0x06);
|
|
|
|
|
}
|
|
|
|
|
return opl[nr].is_opl3 ? 0 : 0xff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void opl2_update(int nr, int16_t *buffer, int samples)
|
|
|
|
|
{
|
|
|
|
|
int c;
|
2019-10-30 18:01:23 +01:00
|
|
|
Bit32s buffer_32[samples];
|
2018-04-25 23:51:13 +02:00
|
|
|
|
|
|
|
|
if (opl_type)
|
|
|
|
|
{
|
|
|
|
|
OPL3_GenerateStream(&opl[nr].opl3chip, buffer, samples);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
opl[nr].chip.GenerateBlock2(samples, buffer_32);
|
|
|
|
|
|
|
|
|
|
for (c = 0; c < samples; c++)
|
|
|
|
|
buffer[c*2] = (int16_t)buffer_32[c];
|
|
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void opl3_update(int nr, int16_t *buffer, int samples)
|
|
|
|
|
{
|
2017-01-31 20:39:36 +01:00
|
|
|
int c;
|
2019-10-30 18:01:23 +01:00
|
|
|
Bit32s buffer_32[samples*2];
|
2017-01-31 20:39:36 +01:00
|
|
|
|
2018-04-25 23:51:13 +02:00
|
|
|
if (opl_type)
|
2017-01-31 20:39:36 +01:00
|
|
|
{
|
2016-08-08 02:52:53 +02:00
|
|
|
OPL3_GenerateStream(&opl[nr].opl3chip, buffer, samples);
|
2017-01-31 20:39:36 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
opl[nr].chip.GenerateBlock3(samples, buffer_32);
|
|
|
|
|
|
|
|
|
|
for (c = 0; c < samples*2; c++)
|
|
|
|
|
buffer[c] = (int16_t)buffer_32[c];
|
|
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|