libmsx
C library for MSX
Loading...
Searching...
No Matches
SCC/SCC+ device interface

#include <scc.h> Inspect, discover, enable/disable to access registers, of the SCC/SCC+ sound chip. More...

+ Collaboration diagram for SCC/SCC+ device interface:

Data Structures

struct  SCC_Waveform
 The structure of the SCC/SCC+ 32-byte waveform data register. More...
 
struct  SCC_Channel
 Device interface for a sound channel of SCC/SCC+ sound chip. More...
 
struct  SCC_Device
 Device interface for SCC/SCC+ sound chip. More...
 
struct  SCC
 SCC Handle. More...
 

Functions

uint8_t SCC_inspect (uint8_t slot)
 MSX Inspect whether SCC/SCC+ is on the given slot.
 
uint8_t SCC_find (struct SCC *scc)
 MSX Find SCC/SCC+ sound chip.
 
void SCC_set_mode (struct SCC *scc, uint8_t mode)
 MSX Set the SCC handle to SCC compatible mode or SCC+ mode.
 
uint8_t SCC_get_mode (struct SCC *scc)
 MSX Check which mode the SCC handle is set to.
 
void SCC_enable (const struct SCC *scc)
 MSX Enable SCC/SCC+ sound chip.
 
void SCC_disable (const struct SCC *scc)
 MSX Disable SCC/SCC+ sound chip.
 

Detailed Description

#include <scc.h> Inspect, discover, enable/disable to access registers, of the SCC/SCC+ sound chip.

Example
The following code detects the Konami SCC/SCC+ sound chip and plays a triangular wave 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 <scc.h>
const int8_t triangle[32] = {
0, 16, 32, 48, 64, 80, 96, 112,
127, 112, 96, 80, 64, 48, 32, 16,
0, -16, -32, -48, -64, -80, -96, -112,
-128, -112, -96, -80, -64, -48, -32, -16,
};
static struct SCC scc;
void test_SCC(void) {
if (!scc.slot) return;
SCC_enable(&scc);
{
uint8_t slot_p2 = msx_get_slot((void *)0x8000);
msx_ENASLT(scc.slot, (void *)0x8000);
{
memcpy((void *)scc.device->channels[0].wo_waveform, triangle, 32);
*scc.device->rw_channel_mask = 0x01; // unmute ch1
*scc.device->channels[0].rw_volume = 15;
*scc.device->channels[0].rw_fdr = 0x11d; // O4 G
}
msx_ENASLT(slot_p2, (void *)0x8000);
__asm__("ei");
}
SCC_disable(&scc);
}
void main(void) {
if (SCC_find(&scc)) {
test_SCC();
}
for (;;) {
}
}
void msx_ENASLT(uint8_t slot, void *addr)
MSX BIOS : ENASLT (0024H / MAIN).
uint8_t msx_get_slot(void *addr)
MSX Get the current slot of a 16KiB page that including the given address.
void await_vsync(void)
MSX Waits for next VSYNC interrupt.
void SCC_enable(const struct SCC *scc)
MSX Enable SCC/SCC+ sound chip.
uint8_t SCC_find(struct SCC *scc)
MSX Find SCC/SCC+ sound chip.
void SCC_disable(const struct SCC *scc)
MSX Disable SCC/SCC+ sound chip.
SCC Handle.
Definition scc.h:106
Using #include <msx.h> includes almost all C header files in libmsx, for ease to use.
Device interface for Konami SCC/SCC+ sound cartridge.

Data Structure Documentation

◆ SCC_Waveform

struct SCC_Waveform

The structure of the SCC/SCC+ 32-byte waveform data register.

Definition at line 50 of file scc.h.

Data Fields
int8_t data[32]

◆ SCC_Channel

struct SCC_Channel

Device interface for a sound channel of SCC/SCC+ sound chip.

Definition at line 57 of file scc.h.

+ Collaboration diagram for SCC_Channel:
Data Fields
volatile const struct SCC_Waveform * ro_waveform Pointer to read data from the 32-byte waveform data register.
Note
Read Only.
volatile struct SCC_Waveform * wo_waveform Pointer to write data to the 32-byte waveform data register.
Note
Write Only.
volatile uint16_t * rw_fdr Pointer to read/write data from/to the frequency division ratio register.
volatile uint8_t * rw_volume Pointer to read/write data from/to the volume register.

◆ SCC_Device

struct SCC_Device

Device interface for SCC/SCC+ sound chip.

Definition at line 81 of file scc.h.

+ Collaboration diagram for SCC_Device:
Data Fields
volatile uint8_t * rw_channel_mask Pointer to read/write a value from/to the channel mask register.
volatile uint8_t * wo_deformation Pointer to write a value to the deformation register.
Note
Write Only.
struct SCC_Channel channels[5] Device interface for each 5 channels.

◆ SCC

struct SCC

SCC Handle.

See also
SCC_find()
SCC_set_mode()
SCC_get_mode()
SCC_enable()
SCC_disable()

Definition at line 106 of file scc.h.

+ Collaboration diagram for SCC:
Data Fields
uint8_t slot Slot address of the SCC/SCC+.
uint8_t version 1 if SCC, 2 or greater value if SCC+.
uint8_t mode 1 if SCC compatible mode, 2 if SCC+ mode.
const struct SCC_Device * device Pointer to device interface.

Function Documentation

◆ SCC_inspect()

uint8_t SCC_inspect ( uint8_t  slot)

MSX Inspect whether SCC/SCC+ is on the given slot.

Parameters
slota slot address
Returns
0 if neither SCC or SCC+, 1 if SCC, 2 or greater value if SCC+.

◆ SCC_find()

uint8_t SCC_find ( struct SCC scc)

MSX Find SCC/SCC+ sound chip.

Parameters
scc[out] pointer to a SCC handle to be initialized.
Returns
the slot address of SCC/SCC+ if found, 0 otherwise.
Postcondition
If no SCC/SCC+ found, 0 is set to scc->slot.
If a SCC/SCC+ found;
  • the slot address of SCC/SCC+ is set to scc->slot,
  • 1 is set to scc->version if SCC, or
  • 2 or greater value is set to scc->version if SCC+.
  • the device interface is set to scc->device.
  • the handle is set to SCC compatible mode even if SCC+.
See also
SCC_set_mode()
SCC_get_mode()
SCC_enable()
SCC_disable()

◆ SCC_set_mode()

void SCC_set_mode ( struct SCC scc,
uint8_t  mode 
)

MSX Set the SCC handle to SCC compatible mode or SCC+ mode.

The scc shall point to a SCC handle initialized by SCC_find().

If scc->version is less than 2 (i.e., not SCC+), do nothing.

The mode set by this function shall be applied to the sound chip the next time SCC_enable() is called.

Parameters
sccpointer to the SCC handle.
mode1 for SCC mode, 2 for SCC+ mode, others are ignored.

◆ SCC_get_mode()

uint8_t SCC_get_mode ( struct SCC scc)

MSX Check which mode the SCC handle is set to.

The scc shall point to a SCC handle initialized by SCC_find().

The mode returned by this function (i.e., the mode set to the SCC handle) may not the current mode of the sound chip. The mode set to the SCC handle shall be applied to the sound chip when SCC_enable() is called.

Parameters
sccpointer to the SCC handle.
Returns
1 if SCC mode, 2 if SCC+ mode, 0 otherwise.

◆ SCC_enable()

void SCC_enable ( const struct SCC scc)

MSX Enable SCC/SCC+ sound chip.

Expose SCC/SCC+ sound chip on the slot scc->slot and enable to access registers of the sound chip by inter-slot read/write BIOS function.

The scc shall point to a SCC handle initialized by SCC_find().

Parameters
sccpointer to the SCC handle.

◆ SCC_disable()

void SCC_disable ( const struct SCC scc)

MSX Disable SCC/SCC+ sound chip.

Unexpose SCC/SCC+ sound chip on the slot scc->slot and disable to access registers of the sound chip.

The scc shall point to a SCC handle initialized by SCC_find().

Parameters
sccpointer to the SCC handle.