Skip to content

Commit 8ecd466

Browse files
committed
initial support for banjo SMS/GG music driver
1 parent 24dc1e1 commit 8ecd466

9 files changed

Lines changed: 4101 additions & 28 deletions

File tree

‎common/include/Music.h‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
extern void* last_music;
99
extern UINT8 stop_music_on_new_state;
10+
extern volatile UINT8 music_paused;
1011

1112
void MUSIC_isr(void) NONBANKED;
1213
void __PlayMusic(void* music, unsigned char bank, unsigned char loop);
@@ -23,22 +24,22 @@ inline void INIT_SOUND(void) {
2324
#undef MUSIC_DRIVER_GBT
2425
#endif
2526

27+
#define PauseMusic music_paused = 1, sfx_sound_cut()
28+
#define UnpauseMusic if (last_music) music_paused = 0
29+
2630
#if defined(MUSIC_DRIVER_HUGE)
2731
#include "hUGEDriver.h"
2832

29-
extern BYTE hUGE_paused;
30-
3133
#define INIT_MUSIC
3234
#define DECLARE_MUSIC(SONG) extern const void __bank_ ## SONG ## _uge; extern const hUGESong_t SONG ## _uge
3335
#define PlayMusic(SONG, LOOP) __PlayMusic(&SONG ## _uge, (uint8_t)&__bank_ ## SONG ## _uge, 0)
34-
#define StopMusic hUGE_paused = 1; sfx_sound_cut(); last_music = 0
36+
#define StopMusic PauseMusic, last_music = 0
3537

3638
#define MUTE_CHANNEL(CHANNEL) if(last_music) hUGE_mute_mask = (CHANNEL)
3739
#define UNMUTE_ALL_CHANNELS hUGE_reset_wave(),(hUGE_mute_mask = MUTE_MASK_NONE)
3840
#elif defined(MUSIC_DRIVER_GBT)
3941
#include "gbt_player.h"
4042

41-
4243
extern UINT8 mute_channels;
4344
#define INIT_MUSIC gbt_stop()
4445
#define DECLARE_MUSIC(SONG) extern const void __bank_ ## SONG ## _mod_Data; extern const unsigned char * SONG ## _mod_Data[]
@@ -47,6 +48,19 @@ inline void INIT_SOUND(void) {
4748

4849
#define MUTE_CHANNEL(CHANNEL) if (mute_channels != (CHANNEL)) (mute_channels = (CHANNEL)), gbt_enable_channels(0xF & ~(CHANNEL))
4950
#define UNMUTE_ALL_CHANNELS (mute_channels = MUTE_MASK_NONE), gbt_enable_channels(0xF)
51+
#elif defined(MUSIC_DRIVER_BANJO)
52+
#include "banjo.h"
53+
54+
extern UINT8 mute_channels;
55+
void __InitMusicDriver(void);
56+
void __StopMusic(void);
57+
#define INIT_MUSIC __InitMusicDriver()
58+
#define DECLARE_MUSIC(SONG) extern const void __bank_ ## SONG ## _fur; extern const song_data_t SONG ## _fur
59+
#define PlayMusic(SONG, LOOP) __PlayMusic(&SONG ## _fur, (uint8_t)&__bank_ ## SONG ## _fur, LOOP)
60+
#define StopMusic __StopMusic()
61+
62+
#define MUTE_CHANNEL(CHANNEL) (mute_channels = CHANNEL)
63+
#define UNMUTE_ALL_CHANNELS (mute_channels = 0)
5064
#else
5165
extern UINT8 mute_channels;
5266
#define INIT_MUSIC

‎common/include/banjo.h‎

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
2+
// banjo sound driver
3+
// Joe Kennedy 2024
4+
5+
#ifndef __BANJO_H
6+
#define __BANJO_H
7+
8+
// instructions
9+
#define NOTE_ON 0x00
10+
#define NOTE_OFF 0x01
11+
#define INSTRUMENT_CHANGE 0x02
12+
#define VOLUME_CHANGE 0x03
13+
#define FM_DRUM 0x04
14+
#define SN_NOISE_MODE 0x05
15+
#define SLIDE_UP 0x06
16+
#define SLIDE_DOWN 0x07
17+
#define SLIDE_PORTA 0x08
18+
#define SLIDE_OFF 0x09
19+
#define ARPEGGIO 0x0a
20+
#define ARPEGGIO_OFF 0x0b
21+
#define VIBRATO 0x0c
22+
#define VIBRATO_OFF 0x0d
23+
#define LEGATO_ON 0x0e
24+
#define LEGATO_OFF 0x0f
25+
#define GAME_GEAR_PAN 0x10
26+
#define END_LINE 0x80
27+
28+
#define MODE_FM 1
29+
#define MODE_SN 2
30+
#define MODE_SN_FM 3
31+
#define MODE_DUAL_SN 4
32+
#define MODE_FM_DRUMS 5
33+
#define MODE_SN_FM_DRUMS 7
34+
35+
#define CHAN_FLAG_MUTED 0x01
36+
#define CHAN_FLAG_NOTE_ON 0x02
37+
#define CHAN_FLAG_LEGATO 0x04
38+
#define CHAN_FLAG_PITCH_CHANGE 0x08
39+
#define CHAN_FLAG_VOLUME_MACRO 0x10
40+
#define CHAN_FLAG_VIBRATO 0x20
41+
#define CHAN_FLAG_ARPEGGIO 0x40
42+
#define CHAN_FLAG_SLIDE 0x80
43+
44+
// used in song/sfx table definitions
45+
#define SFX_DEF(SFX_LABEL, SFX_BANK, SFX_PRIORITY) { SFX_PRIORITY, SFX_BANK, &SFX_LABEL }
46+
#define SONG_DEF(SONG_LABEL, SONG_BANK) { 0, SONG_BANK, &SONG_LABEL }
47+
48+
typedef struct instrument_s {
49+
50+
unsigned char volume_macro_len;
51+
unsigned char volume_macro_loop;
52+
const unsigned char * volume_macro_ptr;
53+
unsigned char fm_preset;
54+
unsigned char fm_patch[8];
55+
56+
} instrument_t;
57+
58+
typedef struct song_data_s {
59+
unsigned char magic_byte;
60+
unsigned char bank;
61+
unsigned char channel_count;
62+
unsigned char loop;
63+
unsigned char sfx_channel;
64+
unsigned char has_sn;
65+
unsigned char has_fm;
66+
unsigned char has_fm_drums;
67+
unsigned char time_base;
68+
unsigned char speed_1;
69+
unsigned char speed_2;
70+
unsigned char pattern_length;
71+
unsigned char orders_length;
72+
const instrument_t * const * instrument_pointers;
73+
const unsigned char * const * const * order_pointers;
74+
unsigned char subtic;
75+
unsigned char tic;
76+
unsigned char line;
77+
unsigned char order;
78+
unsigned char process_new_line;
79+
unsigned char noise_mode;
80+
unsigned char panning;
81+
const unsigned char channel_types[32];
82+
} song_data_t;
83+
84+
typedef struct channel_s {
85+
unsigned char flags;
86+
unsigned char type;
87+
unsigned char subchannel;
88+
unsigned char port;
89+
90+
unsigned int freq;
91+
unsigned int target_freq;
92+
93+
unsigned char volume;
94+
unsigned char midi_note;
95+
unsigned char instrument_num;
96+
97+
unsigned char slide_amount;
98+
unsigned char slide_type;
99+
100+
unsigned char vibrato_current;
101+
unsigned char vibrato_target;
102+
unsigned char vibrato_counter;
103+
unsigned char vibrato_counter_add;
104+
105+
unsigned char arpeggio_pos;
106+
unsigned char arpeggio;
107+
108+
unsigned int order_table_ptr;
109+
unsigned int pattern_ptr;
110+
unsigned char line_wait;
111+
112+
unsigned char volume_macro_len;
113+
unsigned char volume_macro_pos;
114+
unsigned char volume_macro_loop;
115+
unsigned int volume_macro_ptr;
116+
117+
unsigned char fm_patch_shifted;
118+
unsigned char fm_drum_trigger;
119+
unsigned char fm_drum_volume_mask;
120+
} channel_t;
121+
122+
typedef struct song_s {
123+
124+
unsigned char priority;
125+
unsigned char bank;
126+
const song_data_t * song;
127+
128+
} song_t;
129+
130+
// stores the mode after it's set in banjo_init
131+
extern unsigned char banjo_mode;
132+
133+
// flags whether the FM unit is installed
134+
extern unsigned char banjo_fm_unit_present;
135+
136+
// flags whether we're running on a Game Gear
137+
extern unsigned char banjo_game_gear_mode;
138+
139+
// flags whether we're running on Sega System E
140+
extern unsigned char banjo_system_e;
141+
142+
extern song_data_t song_state;
143+
extern channel_t song_channels[];
144+
145+
extern song_data_t sfx_state;
146+
extern channel_t sfx_channel;
147+
148+
// sets banjo_fm_unit_present to 1 if an fm unit is installed, 0 otherwise
149+
// sets banjo_game_gear_mode to 1 if it's detected that wer're running on a game gear in game gear mode, 0 otherwise
150+
void banjo_check_hardware(void);
151+
152+
// initialise banjo for the given mode
153+
void banjo_init(unsigned char mode);
154+
155+
// Queues ON:
156+
157+
// handle song/sfx queues and update playing song/sfx
158+
// this will change the bank for slot 2 (i.e. 0x8000 to 0xbfff (writes to mapper at 0xffff))
159+
void banjo_update(void);
160+
161+
// queue song/sfx to be played back starting on next banjo_update
162+
void banjo_queue_song(unsigned char song);
163+
void banjo_queue_sfx(unsigned char sfx);
164+
165+
// set the loop mode for the song/sfx
166+
// by default songs loop, but sfx don't
167+
void banjo_queue_song_loop_mode(unsigned char loop);
168+
void banjo_queue_sfx_loop_mode(unsigned char loop);
169+
170+
// set up pointers to the song and sfx tables
171+
void banjo_set_song_table(const song_t *song_table_ptr);
172+
void banjo_set_sfx_table(const song_t *sfx_table_ptr);
173+
174+
// Queues OFF:
175+
176+
// start playing song/sfx
177+
// change to the song/sfx's bank before calling this
178+
void banjo_play_song(const song_data_t *song_ptr, unsigned char loop_mode);
179+
void banjo_play_sfx(const song_data_t *song_ptr, unsigned char loop_mode);
180+
181+
// update song/sfx if one is playing
182+
// change to the song/sfx's bank before calling this
183+
void banjo_update_song(void);
184+
void banjo_update_sfx(void);
185+
186+
// Queues both ON and OFF:
187+
188+
// stop the currently playing song/sfx
189+
void banjo_song_stop(void);
190+
void banjo_sfx_stop(void);
191+
192+
// resume playback of a stopped song
193+
void banjo_song_resume(void);
194+
195+
// mute the given song channel
196+
void banjo_mute_song_channel(unsigned char chan);
197+
198+
// unmute the given song channel
199+
// when handling your own banking and using opll fm with custom instruments
200+
// change to the song's bank before calling this to properly restore the custom instrument patch
201+
void banjo_unmute_song_channel(unsigned char chan);
202+
203+
#endif

0 commit comments

Comments
 (0)