libmsx
C library for MSX
Loading...
Searching...
No Matches
OPLL device interface

Inspect, discover, enable/disable to access registers, of the OPLL sound chip. More...

+ Collaboration diagram for OPLL device interface:

Data Structures

struct  OPLL_Device
 Device interface for OPLL sound chip. More...
 
struct  OPLL
 OPLL Handle. More...
 

Functions

uint8_t OPLL_inspect (uint8_t slot)
 MSX Inspect whether OPLL is on the given slot.
 
uint8_t OPLL_find (struct OPLL *opll)
 MSX Find OPLL sound chip.
 
void OPLL_enable (const struct OPLL *opll)
 MSX Enable OPLL sound chip.
 
void OPLL_disable (const struct OPLL *opll)
 MSX Disable OPLL sound chip.
 

Detailed Description

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.

// -*- coding: utf-8-unix -*-
/*
* Copyright (c) 2021-2024 Daishi Mori (mori0091)
*
* This software is released under the MIT License.\n
* See https://github.com/mori0091/libmsx/blob/main/LICENSE
*
* GitHub libmsx project\n
* https://github.com/mori0091/libmsx
*/
#include <string.h>
#include <msx.h>
#include <opll.h>
static struct OPLL opll;
#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 was not found, nothing is done.
if (!opll.slot) return;
{
// 9 channels mode
opll.device->write(0x0e, 0x00);
// ch1 : Forces to KEY-OFF before next KEY-ON.
opll.device->write(0x10, 0);
opll.device->write(0x20, 0);
// ch1 : INST=3, VOL=0
// \note
// VOL(0) means maximum volume, VOL(15) means minimum volume.
// VOL(a) means "-3a dB of the maximum volume" (i.e. Vmax * 10^(-0.3a))
opll.device->write(0x30, (INST(3) | VOL(0)));
// ch1 : O4 G
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));
// \note
// Interrupts are disabled by calling `opll.device->write()`, so interrupts
// must be enabled at the end.
__asm__("ei");
sleep_millis(2000);
}
}
void main(void) {
OPLL_find(&opll); // Find OPLL
OPLL_enable(&opll); // Enable OPLL, if found.
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.
Definition opll.h:89
uint8_t OPLL_find(struct OPLL *opll)
MSX Find OPLL sound chip.
void OPLL_enable(const struct OPLL *opll)
MSX Enable OPLL sound chip.
OPLL Handle.
Definition opll.h:74
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.
Definition opll.h:64

Data Structure Documentation

◆ OPLL

struct OPLL

OPLL Handle.

See also
OPLL_find()
OPLL_enable()
OPLL_disable()

Definition at line 74 of file opll.h.

+ Collaboration diagram for 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.

Function Documentation

◆ OPLL_inspect()

uint8_t OPLL_inspect ( uint8_t  slot)

MSX Inspect whether OPLL is on the given slot.

Parameters
slota slot address
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
opllpointer 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
opllpointer to the OPLL handle.