loveemu log このページをアンテナに追加 RSSフィード

Recent Info

Memorandom

わぁい。

2009-10-26

[] チュンソフト製ゲームのSPCの音抜けを解消する方法

さもまとまった方法を紹介する風情でありながら、ほとんど説明になっていませんし、ある意味でやや不完全です(うまくいかない場合もある)。参考メモ程度に残しておきます。

適当にやっていたら音抜けを直せたので、某所のかまいたちの夜を直そうとしています。ただ、元のdumperの方は過去に修正方法を見つけていたようで(そうだろうなとは思ってたけど)、じつは本人の手元には完全に修正されたバージョンがあるのではないかと思っていたりします。無駄骨率高そう。

さて本題ですが、上記「かまいたちの夜」をはじめとした、チュンソフトのミュージックエンジンを用いているゲームでは、楽曲の音色がすべてそろう前に演奏を開始して、演奏しつつ残りをそろえるような仕組みになっています。曲の頭の時点でSPCをダンプすると、残りの音色がそろわない状態で保存されてしまうため、楽曲の演奏が不完全なものになってしまいます。

これを直すためのアプローチはいろいろとあるかもしれませんが、ここでは音色の欠けたSPCに追加音色を移植することにします。

誰でもできる作業だと言い切るには記事が説明不足ですが、内容自体はそう難しいものでもありません。

という内容でありましたが、あすかさんがコメントで簡単確実そうな方法を寄せてくださったので、そちらを以下に掲載しておきます。

  1. 頭から吸い出したSPCファイル(以下SPC1)
  2. 全ての情報が読み込まれたSPCファイル(出来るだけ頭に近いデータ)(以下SPC2)
  3. バイナリーエディタ(範囲選択してコピー/貼り付けができるもの)

これらを用意したのち、以下の作業をやればokです。(+100hは不要; かまいたちの夜の場合)

  1. SPC2から、0x003a0〜0x100ffの範囲をコピーし、SPC1の0x003a0〜0x100ffに貼り付ける
  2. SPC2から、0x00280〜0x0029fの範囲をコピーし、SPC1の0x00280〜0x0029fに貼り付ける
  3. 一部音が鳴らない場合は、黒猫SPCなど鍵盤が見れるソフトで再生し、音が鳴っていないトラックを調べます。
    • Trk1の場合:SPC2の0x10102〜0x10103をSPC1の0x10102〜0x10103に貼り付る
    • Trk2の場合:SPC2の0x10112〜0x10113をSPC1の0x10112〜0x10113に貼り付る
    • Trk3の場合:SPC2の0x10122〜0x10123をSPC1の0x10122〜0x10123に貼り付る
    • Trk4の場合:SPC2の0x10132〜0x10133をSPC1の0x10132〜0x10133に貼り付る
    • Trk5の場合:SPC2の0x10142〜0x10143をSPC1の0x10142〜0x10143に貼り付る
    • Trk6の場合:SPC2の0x10152〜0x10153をSPC1の0x10152〜0x10153に貼り付る
    • Trk7の場合:SPC2の0x10162〜0x10163をSPC1の0x10162〜0x10163に貼り付る
    • Trk8の場合:SPC2の0x10172〜0x10173をSPC1の0x10172〜0x10173に貼り付る

Cソースにするとこんな感じでしょうか。

// Kamaitachi no Yoru SPC fix
// Method contributed by Asuka Rangray

#include <stdio.h>
#include <stdlib.h>

void fileCopyBytes(FILE *dst, FILE *src, int start, int end)
{
	int i;
	int c;

	if (start > end)
		return;

	for (i = start; i <= end; i++) {
		fseek(src, i, SEEK_SET);
		c = fgetc(src);
		fseek(dst, i, SEEK_SET);
		fputc(c, dst);
	}
}

int main(int argc, char *argv[])
{
	FILE *fBase = NULL;
	FILE *fPatch = NULL;
	int result = EXIT_FAILURE;

	if (argc < 2) {
		fprintf(stderr, "Error: too few input files\n");
		fprintf(stderr, "Arguments: <base spc> <patch spc>\n");
		return EXIT_FAILURE;
	}

	// file 1:
	// spc file which starts from the beginning of a song,
	// but lacks some instruments. (Chunsoft's music engine
	// delayloads some samples just after the start of a song)
	fBase = fopen(argv[1], "r+b");
	if (fBase == NULL)
		goto onexit;

	// file 2:
	// spc file which has fully loaded necessary instruments.
	// If it's closer to the beginning of a song, it's better.
	fPatch = fopen(argv[2], "rb");
	if (fPatch == NULL)
		goto onexit;

	// step 1: copy $02a0-ffff of ARAM
	fileCopyBytes(fBase, fPatch, 0x003a0, 0x100ff);
	// step 2: copy $0180-019f of ARAM
	fileCopyBytes(fBase, fPatch, 0x00280, 0x0029f);
	// step 3: copy pitch registers if needed
	#if 0
	fileCopyBytes(fBase, fPatch, 0x10102, 0x10103); // CH#0
	fileCopyBytes(fBase, fPatch, 0x10112, 0x10113); // CH#1
	fileCopyBytes(fBase, fPatch, 0x10122, 0x10123); // CH#2
	fileCopyBytes(fBase, fPatch, 0x10132, 0x10133); // CH#3
	fileCopyBytes(fBase, fPatch, 0x10142, 0x10143); // CH#4
	fileCopyBytes(fBase, fPatch, 0x10152, 0x10153); // CH#5
	fileCopyBytes(fBase, fPatch, 0x10162, 0x10163); // CH#6
	fileCopyBytes(fBase, fPatch, 0x10172, 0x10173); // CH#7
	#endif

	result = EXIT_SUCCESS;

onexit:
	if (fPatch)
		fclose(fPatch);
	if (fBase)
		fclose(fBase);
	return result;
}

で、やっぱり修正版は手元にあるそうです。うーむ。

一応、わたしが書いた内容も以下に残しておきます。上記の方法の方がおそらく確実です

続きを読む

2009-10-04

[] Update: Nintendo DS susie plugin package

Here goes: nitroscrap-20091004.zip (source code included)

f:id:loveemu:20091003221544p:image:w640

Changes

  • axnds: added extremely simple header checking.
  • axnds: merged no file mapping code to main code.
  • ifnscr: fixed 4bpp image decoding (horizontal flipping, palette index, support 16 color image), which was too much broken.

What Susie (and its plugin) is

Susie is not very popular outside of Japanese programs (list of a couple below) but it is still a plugin format used my many more general image viewing and manipulation programs, the plugin format also has a somewhat of a history of use in rom hacking/game hacking/program hacking circles.

Programs that support SUSIE plugins (be warned there have been some issues with programs not totally supporting the format):

Note there are several more around, this is just a basic selection.

2009-10-02

[] Nintendo DS File Formats

Note: All the contents of this article are entirely copied from http://llref.emutalk.net/nds_formats.htm for archival purpose. *1

Sections
  • Generic Header Format
  • Graphic File Formats
  • Archive File Formats
  • Sound File Formats
  • Custom File Formats
  • Compression Formats

続きを読む

*1:The server was dead when I found the site... oh well

2009-03-11

[] Nintendo DS susie plugin package (beta!)

このまえnscrのプラグインつくったけど、こんどはndsのプラグインつくったよ。

ndsファイル内のファイルシステムを読むプラグインだよ。ndstoolのソースコードを書き換えたよ。

「これでファイルを展開しなくてもnscrが見えちゃう」って思ったのに、よく考えたらアーカイブの中のncgr+nclrをifnscr.spiが読めないから、結局目的は果たせなかったのです……泣いてもいいですか?