linux/include/sound/opl3.h

/* SPDX-License-Identifier: GPL-2.0-or-later */
#ifndef __SOUND_OPL3_H
#define __SOUND_OPL3_H

/*
 * Definitions of the OPL-3 registers.
 *
 * Copyright (c) by Jaroslav Kysela <[email protected]>,
 *                  Hannu Savolainen 1993-1996
 *
 *      The OPL-3 mode is switched on by writing 0x01, to the offset 5
 *      of the right side.
 *
 *      Another special register at the right side is at offset 4. It contains
 *      a bit mask defining which voices are used as 4 OP voices.
 *
 *      The percussive mode is implemented in the left side only.
 *
 *      With the above exceptions the both sides can be operated independently.
 *      
 *      A 4 OP voice can be created by setting the corresponding
 *      bit at offset 4 of the right side.
 *
 *      For example setting the rightmost bit (0x01) changes the
 *      first voice on the right side to the 4 OP mode. The fourth
 *      voice is made inaccessible.
 *
 *      If a voice is set to the 2 OP mode, it works like 2 OP modes
 *      of the original YM3812 (AdLib). In addition the voice can 
 *      be connected the left, right or both stereo channels. It can
 *      even be left unconnected. This works with 4 OP voices also.
 *
 *      The stereo connection bits are located in the FEEDBACK_CONNECTION
 *      register of the voice (0xC0-0xC8). In 4 OP voices these bits are
 *      in the second half of the voice.
 */

#include <sound/core.h>
#include <sound/hwdep.h>
#include <sound/timer.h>
#include <sound/seq_midi_emul.h>
#include <sound/seq_oss.h>
#include <sound/seq_oss_legacy.h>
#include <sound/seq_device.h>
#include <sound/asound_fm.h>

/*
 *    Register numbers for the global registers
 */

#define OPL3_REG_TEST
#define OPL3_ENABLE_WAVE_SELECT

#define OPL3_REG_TIMER1
#define OPL3_REG_TIMER2
#define OPL3_REG_TIMER_CONTROL
#define OPL3_IRQ_RESET
#define OPL3_TIMER1_MASK
#define OPL3_TIMER2_MASK
#define OPL3_TIMER1_START
#define OPL3_TIMER2_START

#define OPL3_REG_CONNECTION_SELECT
#define OPL3_LEFT_4OP_0
#define OPL3_LEFT_4OP_1
#define OPL3_LEFT_4OP_2
#define OPL3_RIGHT_4OP_0
#define OPL3_RIGHT_4OP_1
#define OPL3_RIGHT_4OP_2

#define OPL3_REG_MODE
#define OPL3_OPL3_ENABLE
#define OPL3_OPL4_ENABLE

#define OPL3_REG_KBD_SPLIT
#define OPL3_COMPOSITE_SINE_WAVE_MODE
#define OPL3_KEYBOARD_SPLIT

#define OPL3_REG_PERCUSSION
#define OPL3_TREMOLO_DEPTH
#define OPL3_VIBRATO_DEPTH
#define OPL3_PERCUSSION_ENABLE
#define OPL3_BASSDRUM_ON
#define OPL3_SNAREDRUM_ON
#define OPL3_TOMTOM_ON
#define OPL3_CYMBAL_ON
#define OPL3_HIHAT_ON

/*
 *    Offsets to the register banks for operators. To get the
 *      register number just add the operator offset to the bank offset
 *
 *      AM/VIB/EG/KSR/Multiple (0x20 to 0x35)
 */
#define OPL3_REG_AM_VIB
#define OPL3_TREMOLO_ON
#define OPL3_VIBRATO_ON
#define OPL3_SUSTAIN_ON
#define OPL3_KSR
#define OPL3_MULTIPLE_MASK

 /*
  *   KSL/Total level (0x40 to 0x55)
  */
#define OPL3_REG_KSL_LEVEL
#define OPL3_KSL_MASK
#define OPL3_TOTAL_LEVEL_MASK

/*
 *    Attack / Decay rate (0x60 to 0x75)
 */
#define OPL3_REG_ATTACK_DECAY
#define OPL3_ATTACK_MASK
#define OPL3_DECAY_MASK

/*
 * Sustain level / Release rate (0x80 to 0x95)
 */
#define OPL3_REG_SUSTAIN_RELEASE
#define OPL3_SUSTAIN_MASK
#define OPL3_RELEASE_MASK

/*
 * Wave select (0xE0 to 0xF5)
 */
#define OPL3_REG_WAVE_SELECT
#define OPL3_WAVE_SELECT_MASK

/*
 *    Offsets to the register banks for voices. Just add to the
 *      voice number to get the register number.
 *
 *      F-Number low bits (0xA0 to 0xA8).
 */
#define OPL3_REG_FNUM_LOW

/*
 *    F-number high bits / Key on / Block (octave) (0xB0 to 0xB8)
 */
#define OPL3_REG_KEYON_BLOCK
#define OPL3_KEYON_BIT
#define OPL3_BLOCKNUM_MASK
#define OPL3_FNUM_HIGH_MASK

/*
 *    Feedback / Connection (0xc0 to 0xc8)
 *
 *      These registers have two new bits when the OPL-3 mode
 *      is selected. These bits controls connecting the voice
 *      to the stereo channels. For 4 OP voices this bit is
 *      defined in the second half of the voice (add 3 to the
 *      register offset).
 *
 *      For 4 OP voices the connection bit is used in the
 *      both halves (gives 4 ways to connect the operators).
 */
#define OPL3_REG_FEEDBACK_CONNECTION
#define OPL3_FEEDBACK_MASK
#define OPL3_CONNECTION_BIT
/*
 *    In the 4 OP mode there is four possible configurations how the
 *      operators can be connected together (in 2 OP modes there is just
 *      AM or FM). The 4 OP connection mode is defined by the rightmost
 *      bit of the FEEDBACK_CONNECTION (0xC0-0xC8) on the both halves.
 *
 *      First half      Second half     Mode
 *
 *                                       +---+
 *                                       v   |
 *      0               0               >+-1-+--2--3--4-->
 *
 *
 *                                      
 *                                       +---+
 *                                       |   |
 *      0               1               >+-1-+--2-+
 *                                                |->
 *                                      >--3----4-+
 *                                      
 *                                       +---+
 *                                       |   |
 *      1               0               >+-1-+-----+
 *                                                 |->
 *                                      >--2--3--4-+
 *
 *                                       +---+
 *                                       |   |
 *      1               1               >+-1-+--+
 *                                              |
 *                                      >--2--3-+->
 *                                              |
 *                                      >--4----+
 */
#define OPL3_STEREO_BITS
#define OPL3_VOICE_TO_LEFT
#define OPL3_VOICE_TO_RIGHT

/*

 */

#define OPL3_LEFT
#define OPL3_RIGHT

#define OPL3_HW_AUTO
#define OPL3_HW_OPL2
#define OPL3_HW_OPL3
#define OPL3_HW_OPL3_SV
#define OPL3_HW_OPL3_CS
#define OPL3_HW_OPL3_FM801
#define OPL3_HW_OPL3_CS4281
#define OPL3_HW_OPL4
#define OPL3_HW_OPL4_ML
#define OPL3_HW_MASK

#define MAX_OPL2_VOICES
#define MAX_OPL3_VOICES

struct snd_opl3;

/*
 * Instrument record, aka "Patch"
 */

/* FM operator */
struct fm_operator {} __packed;

/* Instrument data */
struct fm_instrument {};

/* type */
#define FM_PATCH_OPL2
#define FM_PATCH_OPL3

/* Instrument record */
struct fm_patch {};


/*
 * A structure to keep track of each hardware voice
 */
struct snd_opl3_voice {};

struct snd_opl3 {};

/* opl3.c */
void snd_opl3_interrupt(struct snd_hwdep * hw);
int snd_opl3_new(struct snd_card *card, unsigned short hardware,
		 struct snd_opl3 **ropl3);
int snd_opl3_init(struct snd_opl3 *opl3);
int snd_opl3_create(struct snd_card *card,
		    unsigned long l_port, unsigned long r_port,
		    unsigned short hardware,
		    int integrated,
		    struct snd_opl3 ** opl3);
int snd_opl3_timer_new(struct snd_opl3 * opl3, int timer1_dev, int timer2_dev);
int snd_opl3_hwdep_new(struct snd_opl3 * opl3, int device, int seq_device,
		       struct snd_hwdep ** rhwdep);

/* opl3_synth */
int snd_opl3_open(struct snd_hwdep * hw, struct file *file);
int snd_opl3_ioctl(struct snd_hwdep * hw, struct file *file,
		   unsigned int cmd, unsigned long arg);
int snd_opl3_release(struct snd_hwdep * hw, struct file *file);

void snd_opl3_reset(struct snd_opl3 * opl3);

#if IS_ENABLED(CONFIG_SND_SEQUENCER)
long snd_opl3_write(struct snd_hwdep *hw, const char __user *buf, long count,
		    loff_t *offset);
int snd_opl3_load_patch(struct snd_opl3 *opl3,
			int prog, int bank, int type,
			const char *name,
			const unsigned char *ext,
			const unsigned char *data);
struct fm_patch *snd_opl3_find_patch(struct snd_opl3 *opl3, int prog, int bank,
				     int create_patch);
void snd_opl3_clear_patches(struct snd_opl3 *opl3);
#else
#define snd_opl3_write
static inline void snd_opl3_clear_patches(struct snd_opl3 *opl3) {}
#endif

#endif /* __SOUND_OPL3_H */