Skip to content

Commit

Permalink
Added VGM score format
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Zoppi <[email protected]>
  • Loading branch information
TexZK committed Mar 14, 2024
1 parent 0615802 commit 0d075ae
Show file tree
Hide file tree
Showing 12 changed files with 536 additions and 7 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.vscode/
builddir/
.vscode
builddir
_gitignore
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "contrib/TDA8425_emu"]
path = contrib/TDA8425_emu
url = https://github.com/TexZK/TDA8425_emu.git
[submodule "contrib/adplug"]
path = contrib/adplug
url = https://github.com/adplug/adplug.git
4 changes: 4 additions & 0 deletions apps/aymo_ymf262_play.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ To play via shell pipe, run:
#include "aymo_score_avd.h"
#include "aymo_score_dro.h"
#include "aymo_score_imf.h"
#include "aymo_score_raw.h"
#include "aymo_score_vgm.h"
#include "aymo_wave.h"
#include "aymo_ymf262.h"

Expand Down Expand Up @@ -97,6 +99,8 @@ static union app_scores {
struct aymo_score_avd_instance avd;
struct aymo_score_dro_instance dro;
struct aymo_score_imf_instance imf;
struct aymo_score_raw_instance raw;
struct aymo_score_vgm_instance vgm;
} score;

static struct aymo_ymf262_chip* chip;
Expand Down
1 change: 1 addition & 0 deletions contrib/adplug
Submodule adplug added at 7db72f
1 change: 1 addition & 0 deletions include/aymo_score.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ enum aymo_score_type {
aymo_score_type_dro,
aymo_score_type_imf,
aymo_score_type_raw,
aymo_score_type_vgm,
aymo_score_type_unknown
};

Expand Down
181 changes: 181 additions & 0 deletions include/aymo_score_vgm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/*
AYMO - Accelerated YaMaha Operator
Copyright (c) 2023 Andrea Zoppi.
This file is part of AYMO.
AYMO is free software: you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License as published by the Free
Software Foundation, either version 2.1 of the License, or (at your option)
any later version.
AYMO is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
more details.
You should have received a copy of the GNU Lesser General Public License
along with AYMO. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef _include_aymo_score_vgm_h
#define _include_aymo_score_vgm_h

#include "aymo_score.h"

AYMO_CXX_EXTERN_C_BEGIN


// See: https://vgmrips.net/wiki/VGM_Specification
enum aymo_score_vgm_offset {
aymo_score_vgm_offset_vgm_ident = 0x00,
aymo_score_vgm_offset_eof_offset = 0x04,
aymo_score_vgm_offset_version = 0x08,
aymo_score_vgm_offset_sn76489_clock = 0x0C,

aymo_score_vgm_offset_ym2413_clock = 0x10,
aymo_score_vgm_offset_gd3_offset = 0x14,
aymo_score_vgm_offset_total_samples = 0x18,
aymo_score_vgm_offset_loop_offset = 0x1C,

aymo_score_vgm_offset_loop_samples = 0x20,
aymo_score_vgm_offset_rate = 0x24,
aymo_score_vgm_offset_sn76489_feedback = 0x28,
aymo_score_vgm_offset_sn76489_width = 0x2A,
aymo_score_vgm_offset_sn76489_flags = 0x2B,
aymo_score_vgm_offset_ym2612_clock = 0x2C,

aymo_score_vgm_offset_ym2151_clock = 0x30,
aymo_score_vgm_offset_vgm_data_offset = 0x34,
aymo_score_vgm_offset_sega_pcm_clock = 0x38,
aymo_score_vgm_offset_spcm_interface = 0x3C,

aymo_score_vgm_offset_rf5c68_clock = 0x40,
aymo_score_vgm_offset_ym2203_clock = 0x44,
aymo_score_vgm_offset_ym2608_clock = 0x48,
aymo_score_vgm_offset_ym2610b_clock = 0x4C,

aymo_score_vgm_offset_ym3812_clock = 0x50,
aymo_score_vgm_offset_ym3526_clock = 0x54,
aymo_score_vgm_offset_y8950_clock = 0x58,
aymo_score_vgm_offset_ymf262_clock = 0x5C,

aymo_score_vgm_offset_ymf278b_clock = 0x60,
aymo_score_vgm_offset_ymf271_clock = 0x64,
aymo_score_vgm_offset_ymz280b_clock = 0x68,
aymo_score_vgm_offset_rf5c164_clock = 0x6C,

aymo_score_vgm_offset_pwm_clock = 0x70,
aymo_score_vgm_offset_ay8910_clock = 0x74,
aymo_score_vgm_offset_ay8910_chip_type = 0x78,
aymo_score_vgm_offset_ay8910_flags = 0x79,
aymo_score_vgm_offset_volume_modifier = 0x7C,
aymo_score_vgm_offset_reserved_0dh = 0x7D,
aymo_score_vgm_offset_loop_base = 0x7E,
aymo_score_vgm_offset_loop_modifier = 0x7F,

aymo_score_vgm_offset_gb_dmg_clock = 0x80,
aymo_score_vgm_offset_nes_apu_clock = 0x84,
aymo_score_vgm_offset_multipcm_clock = 0x88,
aymo_score_vgm_offset_upd7759_clock = 0x8C,

aymo_score_vgm_offset_okim6258_clock = 0x90,
aymo_score_vgm_offset_okim6258_flags = 0x94,
aymo_score_vgm_offset_k054539_flags = 0x95,
aymo_score_vgm_offset_c140_chip_type = 0x96,
aymo_score_vgm_offset_reserved_97h = 0x97,
aymo_score_vgm_offset_okim6295_clock = 0x98,
aymo_score_vgm_offset_k051649_clock = 0x9C,

aymo_score_vgm_offset_k054539_clock = 0xA0,
aymo_score_vgm_offset_huc6280_clock = 0xA4,
aymo_score_vgm_offset_c140_clock = 0xa8,
aymo_score_vgm_offset_k053260_clock = 0xAC,

aymo_score_vgm_offset_pokey_clock = 0xB0,
aymo_score_vgm_offset_qsound_clock = 0xB4,
aymo_score_vgm_offset_scsp_clock = 0xB8,
aymo_score_vgm_offset_extra_header_offset = 0xBC,

aymo_score_vgm_offset_wonderswan_clock = 0xC0,
aymo_score_vgm_offset_vsu_clock = 0xC4,
aymo_score_vgm_offset_saa1099_clock = 0xC8,
aymo_score_vgm_offset_es5503_clock = 0xCC,

aymo_score_vgm_offset_es5506_clock = 0xD0,
aymo_score_vgm_offset_es_chns = 0xD4,
aymo_score_vgm_offset_c352_clock_divider = 0xD6,
aymo_score_vgm_offset_reserved_d7h = 0xD7,
aymo_score_vgm_offset_x1_010_clock = 0xD8,
aymo_score_vgm_offset_c352_clock = 0xDC,

aymo_score_vgm_offset_ga20_clock = 0xE0,
aymo_score_vgm_offset_reserved_e4h = 0xE4,
aymo_score_vgm_offset_reserved_e8h = 0xE8,
aymo_score_vgm_offset_reserved_ech = 0xEC,

aymo_score_vgm_offset_reserved_f0h = 0xF0,
aymo_score_vgm_offset_reserved_f4h = 0xF4,
aymo_score_vgm_offset_reserved_f8h = 0xF8,
aymo_score_vgm_offset_reserved_fch = 0xFC
};

enum aymo_score_vgm_type {
aymo_score_vgm_type_opl1,
aymo_score_vgm_type_opl2,
aymo_score_vgm_type_opl3
};


struct aymo_score_vgm_instance {
const struct aymo_score_vt* vt;
struct aymo_score_status status;
const uint8_t* events;
uint32_t opl_rate;
uint32_t division;
uint32_t eof_offset;
uint32_t total_samples;
uint32_t loop_samples;
uint32_t loop_offset;
uint32_t offset;
uint32_t index;
};


AYMO_PUBLIC const struct aymo_score_vt aymo_score_vgm_vt;


AYMO_PUBLIC int aymo_score_vgm_ctor(
struct aymo_score_vgm_instance* score
);

AYMO_PUBLIC void aymo_score_vgm_dtor(
struct aymo_score_vgm_instance* score
);

AYMO_PUBLIC int aymo_score_vgm_load(
struct aymo_score_vgm_instance* score,
const void* data,
uint32_t size
);

AYMO_PUBLIC void aymo_score_vgm_unload(
struct aymo_score_vgm_instance* score
);

AYMO_PUBLIC struct aymo_score_status* aymo_score_vgm_get_status(
struct aymo_score_vgm_instance* score
);

AYMO_PUBLIC void aymo_score_vgm_restart(
struct aymo_score_vgm_instance* score
);

AYMO_PUBLIC uint32_t aymo_score_vgm_tick(
struct aymo_score_vgm_instance* score,
uint32_t count
);


AYMO_CXX_EXTERN_C_END

#endif // _include_aymo_score_vgm_h
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ sources = {
'include/aymo_score_dro.h',
'include/aymo_score_imf.h',
'include/aymo_score_raw.h',
'include/aymo_score_vgm.h',
'include/aymo_wave.h',
'include/aymo_ymf262_arm_neon.h',
'include/aymo_ymf262_none.h',
Expand All @@ -461,6 +462,7 @@ sources = {
'src/aymo_score_dro.c',
'src/aymo_score_imf.c',
'src/aymo_score_raw.c',
'src/aymo_score_vgm.c',
'src/aymo_tda8425.c',
'src/aymo_tda8425_common.c',
'src/aymo_tda8425_none.c',
Expand Down
8 changes: 8 additions & 0 deletions src/aymo_score.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ along with AYMO. If not, see <https://www.gnu.org/licenses/>.
#include "aymo_score_dro.h"
#include "aymo_score_imf.h"
#include "aymo_score_raw.h"
#include "aymo_score_vgm.h"

#include <assert.h>

Expand Down Expand Up @@ -131,6 +132,12 @@ enum aymo_score_type aymo_score_ext_to_type(
(tag[3] == '\0')) {
return aymo_score_type_raw;
}
if (((tag[0] == 'V') || (tag[0] == 'v')) &&
((tag[1] == 'G') || (tag[1] == 'g')) &&
((tag[2] == 'M') || (tag[2] == 'm')) &&
(tag[3] == '\0')) {
return aymo_score_type_vgm;
}
}
return aymo_score_type_unknown;
}
Expand All @@ -145,6 +152,7 @@ const struct aymo_score_vt* aymo_score_type_to_vt(
case aymo_score_type_dro: return &aymo_score_dro_vt;
case aymo_score_type_imf: return &aymo_score_imf_vt;
case aymo_score_type_raw: return &aymo_score_raw_vt;
case aymo_score_type_vgm: return &aymo_score_vgm_vt;
default: return NULL;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/aymo_score_dro.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,14 @@ int aymo_score_dro_load(

if ((((header->version_major == 0u) && (header->version_minor == 1u)) ||
((header->version_major == 1u) && (header->version_minor == 0u)))) {

if (size < sizeof(struct aymo_score_dro_v1_header)) {
return 1;
}
v1_header = (const struct aymo_score_dro_v1_header*)(const void*)ptr;
ptr += sizeof(struct aymo_score_dro_v1_header);
size -= sizeof(struct aymo_score_dro_v1_header);

if ((v1_header->hardware_extra[0] ||
v1_header->hardware_extra[1] ||
v1_header->hardware_extra[2])) {
Expand Down
Loading

0 comments on commit 0d075ae

Please sign in to comment.