Inspect, discover, enable/disable to access registers, of the OPLL sound chip.
More...
Inspect, discover, enable/disable to access registers, of the OPLL sound chip.
Example
The following code detects the MSX-MUSIC (OPLL) and plays a test tone if detected.
#include <string.h>
#define LO_BYTE(x) (uint8_t)((x) & 0xff)
#define HI_BYTE(x) (uint8_t)(((x) >> 8) & 0xff)
#define SUS_OFF (0)
#define KEY_OFF (0)
#define SUS_ON (uint16_t)(1 << 13)
#define KEY_ON (uint16_t)(1 << 12)
#define BLOCK(x) (uint16_t)((x) << 9)
#define F_NUM(x) (uint16_t)(x)
#define INST(x) (uint8_t)((x) << 4)
#define VOL(x) (uint8_t)((x) & 0x0f)
void test_OPLL(void) {
if (!opll.slot) return;
{
opll.device->write(0x10, 0);
opll.device->write(0x20, 0);
opll.device->write(0x30, (INST(3) | VOL(0)));
uint16_t x = (SUS_OFF | KEY_ON | BLOCK(4) | F_NUM(257));
opll.device->write(0x10, LO_BYTE(x));
opll.device->write(0x20, HI_BYTE(x));
__asm__("ei");
}
}
void main(void) {
for (;;) {
test_OPLL();
}
}
void sleep_millis(uint16_t ms)
MSX Wait for the specified time to elapse in milliseconds.
const struct OPLL_Device * device
Pointer to device interface.
uint8_t OPLL_find(struct OPLL *opll)
MSX Find OPLL sound chip.
void OPLL_enable(const struct OPLL *opll)
MSX Enable OPLL sound chip.
Using #include <msx.h> includes almost all C header files in libmsx, for ease to use.
Device interface for MSX-MUSIC (OPLL).
void(*const write)(uint8_t reg, uint8_t value)
MSX Function pointer to write data to a OPLL register.
◆ OPLL
Data Fields |
uint8_t |
slot |
Slot address of the OPLL. |
uint8_t |
version |
Version/Identifier of the OPLL.
1 if FMPAC,
2 or greater value if other OPLL,
- bit #7 is set if it is the internal OPLL.
|
const struct OPLL_Device * |
device |
Pointer to device interface. |
◆ OPLL_inspect()
uint8_t OPLL_inspect |
( |
uint8_t |
slot | ) |
|
MSX
Inspect whether OPLL is on the given slot.
- Parameters
-
- Returns
- Version/Identifier of the OPLL.
0
if not OPLL,
1
if FMPAC,
2
or greater value if other OPLL,
- bit #7 is set if it is the internal OPLL.
◆ OPLL_find()
uint8_t OPLL_find |
( |
struct OPLL * |
opll | ) |
|
MSX
Find OPLL sound chip.
- Parameters
-
opll | [out] pointer to a OPLL handle to be initialized. |
- Returns
- the slot address of OPLL if found,
0
otherwise.
- Postcondition
- If no OPLL found,
0
is set to opll->slot
.
-
If a OPLL found;
- the slot address of OPLL is set to
opll->slot
,
1
is set to opll->version
if FMPAC,
2
or greater value is set to opll->version
if other OPLL,
- bit #7 is set if it is the internal OPLL.
- the device interface is set to
opll->device
.
◆ OPLL_enable()
void OPLL_enable |
( |
const struct OPLL * |
opll | ) |
|
MSX
Enable OPLL sound chip.
Expose OPLL sound chip on the slot opll->slot
and enable to access registers of the sound chip.
The opll
shall point to a OPLL handle initialized by OPLL_find().
- Parameters
-
opll | pointer to the OPLL handle. |
◆ OPLL_disable()
void OPLL_disable |
( |
const struct OPLL * |
opll | ) |
|
MSX
Disable OPLL sound chip.
Unexpose OPLL sound chip on the slot opll->slot
and disable to access registers of the sound chip.
The opll
shall point to a OPLL handle initialized by OPLL_find().
- Parameters
-
opll | pointer to the OPLL handle. |