libmsx
C library for MSX
Loading...
Searching...
No Matches
opll.h File Reference

Device interface for MSX-MUSIC (OPLL). More...

#include <stdint.h>
+ Include dependency graph for opll.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

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

Macros

#define OPLL_H_
 

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

Device interface for MSX-MUSIC (OPLL).

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

Definition in file opll.h.

Macro Definition Documentation

◆ OPLL_H_

#define OPLL_H_

Definition at line 29 of file opll.h.