Skip to content

Commit

Permalink
AICA MIDI out support
Browse files Browse the repository at this point in the history
  • Loading branch information
tsowell committed Jun 1, 2020
1 parent 97686ea commit d7c00cb
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
25 changes: 25 additions & 0 deletions kernel/arch/dreamcast/include/dc/sound/midi.h
@@ -0,0 +1,25 @@
/* KallistiOS ##version##
dc/sound/midi.h
Copyright (C) 2020 Thomas Sowell
*/

/** \file dc/sound/midi.h
\brief MIDI support.
\author Thomas Sowell
*/

#ifndef __DC_SOUND_MIDI_H
#define __DC_SOUND_MIDI_H

#include <sys/cdefs.h>

__BEGIN_DECLS

void snd_midi(uint8 midi);

__END_DECLS

#endif /* __DC_SOUND_MIDI_H */
2 changes: 1 addition & 1 deletion kernel/arch/dreamcast/sound/Makefile
Expand Up @@ -4,7 +4,7 @@
# (c)2001 Dan Potter
#

OBJS = snd_iface.o snd_sfxmgr.o snd_stream.o snd_stream_drv.o snd_mem.o
OBJS = snd_iface.o snd_sfxmgr.o snd_stream.o snd_stream_drv.o snd_mem.o snd_midi.o

# Only compile this if we have an ARM compiler handy
ifdef DC_ARM_CC
Expand Down
7 changes: 7 additions & 0 deletions kernel/arch/dreamcast/sound/arm/aica_cmd_iface.h
Expand Up @@ -67,11 +67,18 @@ typedef struct aica_channel {
aica_channel_t * CHANR = (aica_channel_t *)(CMDR->cmd_data);
#define AICA_CMDSTR_CHANNEL_SIZE ((sizeof(aica_cmd_t) + sizeof(aica_channel_t))/4)

#define AICA_CMDSTR_MIDI(T, CMDR, MIDIR) \
uint8 T[sizeof(aica_cmd_t) + sizeof(uint32)]; \
aica_cmd_t * CMDR = (aica_cmd_t *)T; \
uint32 * MIDIR = (uint32 *)(CMDR->cmd_data);
#define AICA_CMDSTR_MIDI_SIZE ((sizeof(aica_cmd_t) + sizeof(uint32))/4)

/* Command values (for aica_cmd_t) */
#define AICA_CMD_NONE 0x00000000 /* No command (dummy packet) */
#define AICA_CMD_PING 0x00000001 /* Check for signs of life */
#define AICA_CMD_CHAN 0x00000002 /* Perform a wavetable action */
#define AICA_CMD_SYNC_CLOCK 0x00000003 /* Reset the millisecond clock */
#define AICA_CMD_MIDI 0x00000004

/* Response values (for aica_cmd_t) */
#define AICA_RESP_NONE 0x00000000
Expand Down
4 changes: 4 additions & 0 deletions kernel/arch/dreamcast/sound/arm/main.c
Expand Up @@ -127,6 +127,10 @@ uint32 process_one(uint32 tail) {
/* Reset our timer clock to zero */
timer = 0;
break;
case AICA_CMD_MIDI:
while ((SNDREG32(0x2808) & 0x1000) == 0x1000);
SNDREG32(0x280C) = ((uint32 *)pkt->cmd_data)[0] & 0x000000FF;
break;
default:
/* error */
break;
Expand Down
14 changes: 14 additions & 0 deletions kernel/arch/dreamcast/sound/snd_midi.c
@@ -0,0 +1,14 @@
#include <dc/sound/sound.h>
#include <dc/sound/midi.h>

#include "arm/aica_cmd_iface.h"

void snd_midi(uint8 midi) {
AICA_CMDSTR_MIDI(tmp, cmd, cmdmidi);

cmd->cmd = AICA_CMD_MIDI;
cmd->timestamp = 0;
cmd->size = AICA_CMDSTR_MIDI_SIZE;
*cmdmidi = midi;
snd_sh4_to_aica(tmp, cmd->size);
}

0 comments on commit d7c00cb

Please sign in to comment.