view scn2k/scn2k_grp.cc @ 74:f8751d74918b default tip

Remove “duplicate” functions as they can be remplaced by a nearly-identical existing function.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 02 Apr 2011 19:13:54 +0200
parents f9eb96a4cce0
children
line wrap: on
line source

/*
 * Copyright (c) 2004-2006  Kazunori "jagarl" Ueno
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "scn2k.h"
#include "system/file.h"
#include "system/system_config.h"
#include "font/text.h"
#include "window/render.h"

extern XKFont::HorizLayout* DefaultLayout(int text_size);

/*******************************************************************
** GrpObj(implementation)
*/

GrpObj::GrpObj(void) :
	name(""), gan_name(""), pic_parent(0), picture(0), anm(0),
	_posx(0), _posy(0), clip_area(0,0,0,0),
	alpha(255), order(0), surface_num(0), print_moji(""), print_size(0), print_r(-1),print_g(-1),print_b(-1),
	dig_number(0), dig_digit(0),
	zoomx(-1), zoomy(-1), rotate(-1), attr(GrpObj::HIDDEN) {
	int i;
	for (i=0; i<9; i++) {
		posx[i] = posy[i] = 0;
	}
}

GrpObj::~GrpObj() {
	if (picture != NULL) delete picture;
}

int GrpObj::PosX() {
	return _posx;
}

int GrpObj::PosY() {
	return _posy;
}

void GrpObj::SetUpdate(void) {
	attr = Attribute (attr | UPDATE_PICTURE);
	//Update(); //FIXME
}

void GrpObj::SetPos(int index, int x, int y) {
	if (index < 0 || index > 8) {
		fprintf(stderr,"GrpObj::SetPos: Invalid index %d <- %d,%d\n",index,x,y);
		return;
	}
	if (x == posx[index] && y == posy[index]) return;
	attr = Attribute(attr | UPDATE_POS);
	_posx += x-posx[index];
	_posy += y-posy[index];
	posx[index] = x;
	posy[index] = y;
}

void GrpObj::GetPos(int index, int& x, int& y) {
	if (index < 0 || index > 8) {
		fprintf(stderr,"GrpObj::GetPos: Invalid index %d\n",index);
		x = 0; y = 0;
		return;
	}
	x = posx[index];
	y = posy[index];
}

void GrpObj::SetAlpha(int new_alpha) {
	if (alpha == new_alpha) return;
	alpha = new_alpha;
	attr = Attribute(attr | UPDATE_ALPHA);
	return;
}

void GrpObj::SetSurfaceNum(int num) {
	if (num != -1) {
		if (surface_num == num) return;
		surface_num = num;
	}
	attr = Attribute(attr | UPDATE_SNUM);
}

void GrpObj::SetClipArea(int x, int y, int w, int h) {
	Rect new_clip(x,y,x+w,y+h);
	if (clip_area == new_clip) return;
	clip_area = new_clip;
	attr = Attribute(attr | UPDATE_CLIP);
}

PicBase* GrpObj::DeletePic(void) {
	PicBase* p = picture;
	anm = NULL;
	picture = NULL;
	src_pos.clear();
	attr = Attribute(attr & HIDDEN);
	return p;
}

void GrpObj::GetSrcGeom(int& width, int& height) {
	if (src_pos.empty()) {
		width = 0; height = 0;
		if (name.length() == 0) {
			return;
		}
		/* ボタンの位置情報を求める */
		/* g00 ファイルのヘッダ部分に位置情報は入っている */
		string path(name);
		path += ".g00";
		ARCINFO* info = FileSearcher::GetInstance()->Find(FileSearcher::PDT, path.c_str(), "g00");
		if (info == NULL) { // ファイルが見つからない
			fprintf(stderr, "GrpObj::GetSrcGeom : Cannot find file %s\n", path.c_str());
			return;
		}
		const char* data = info->Read();
		if (data != NULL && *data == 2) { // 画像ファイル内にボタン情報が存在する
			int srclen = read_little_endian_int(data+5);
			int i;
			for (i=0; i<srclen; i++) {
				int x1 = read_little_endian_int(data+9+i*24+0);
				int y1 = read_little_endian_int(data+9+i*24+4);
				int x2 = read_little_endian_int(data+9+i*24+8);
				int y2 = read_little_endian_int(data+9+i*24+12);
				src_pos.push_back(Rect(x1, y1, x2+1, y2+1));
				if (width < src_pos.back().width()) width = src_pos.back().width();
				if (height < src_pos.back().height()) height = src_pos.back().height();
			}
		} else { // 画像ファイルから大きさ取得
			width = read_little_endian_short(data+1);
			height = read_little_endian_short(data+3);
			src_pos.push_back(Rect(0,0,width,height));
		}
		delete info;
	}
	int sn = surface_num;
	if (sn < 0 || sn > src_pos.size()) sn = 0;
	width = src_pos[sn].width();
	height = src_pos[sn].height();
}

void GrpObj::Update(void) {
	if (attr & UPDATE_PICTURE) {
		UpdateSurface();
		attr = Attribute( (attr | UPDATE_ALL) & (~UPDATE_PICTURE));
	}
	if (picture == NULL) return;
	if (attr & UPDATE_POS) {
		if (zoomx != -1 || zoomy != -1) {
			int w=0, h=0;
			GetSrcGeom(w,h);
			picture->Move(_posx-w/2, _posy-h/2);
		} else {
			picture->Move(_posx, _posy);
		}
	}
	if (attr & UPDATE_ALPHA) {
		if (alpha <= 0) {
			picture->SetSurfaceAlpha(0, Rect(0,0));
			picture->hide();
		} else if (alpha >= ALPHA_MAX) {
			picture->SetSurfaceAlpha(0, Rect(0,0));
			if (attr & HIDDEN) picture->hide();
			else picture->show();
		} else {
			picture->SetSurfaceAlpha(&alpha, Rect(0,0,1,1));
			if (attr & HIDDEN) picture->hide();
			else picture->show();
		}
	}
	if ( (attr & UPDATE_SNUM) && (!src_pos.empty())) {
		if (surface_num < 0 || surface_num >= src_pos.size()) surface_num = 0;
		picture->SetSurfacePos(src_pos[surface_num].lx, src_pos[surface_num].ty);
	}
	if (attr & UPDATE_CLIP) {
		picture->SetClipArea(clip_area);
	}
	attr = Attribute(attr & (~UPDATE_ALL));
	if (attr & ANM_PLAYSTART) {
		if (anm != NULL) {
			anm->Play();
			attr = Attribute(attr | ANM_PLAYING);
		}
		attr = Attribute(attr & (~ANM_PLAYSTART));
	}
}

void GrpObj::CreateSurface(PicContainer* parent) {
	if (picture != NULL) {
		PicBase* p = DeletePic();
		delete p;
	}
	src_pos.clear();
	// picture を作成
	pic_parent = parent;
	picture = parent->create_leaf(Rect(_posx,_posy,_posx+1,_posy+1), 0);
	picture->hide();
	UpdateSurface();
}
  
void GrpObj::UpdateSurface(void) {
	if (pic_parent == NULL || picture == NULL) return;
	int width = 0, height = 0;
	if (gtype == FILE || gtype == GAN) {
		if (name.length() == 0) return;
		// ファイル名が存在する場合、ファイルを読み込み
		GetSrcGeom(width, height);
		if (width <= 0 || height <= 0) return;
		// surface の設定
		if (surface_num == 0 && ( ((zoomx > 0 && zoomx != 256) || (zoomy > 0 && zoomy != 256)) || rotate > 0)) {
			ZoomRotate();
		} else {
			// 普通に surface を設定
			string path(name);
			path += ".g00";
			picture->SetSurface(path.c_str(), 0, 0);
			picture->SetSurfaceRect(Rect(0,0,width,height));
		}
		if (attr & BLIT_ADD)
			picture->SetSurfaceAttribute(PicBase::BLIT_ADD);
	} else if (gtype == MOJI) { // テキスト描画
		if (print_moji.length() == 0) return;
		UpdateMoji();
	} else if (gtype == DIGIT) { // 数値を画像表示
		UpdateDigit();
	}
}

void GrpObj::ZoomRotate(void) {
	picture->SetSurface( (Surface*)0, 0, 0);

	// 回転、縮小拡大は座標原点が画像の中心になる
	string path(name);
	path += ".g00";
	Surface* surface_orig = pic_parent->Root().NewSurface(path.c_str());
	if (surface_orig == NULL) return;

	Surface* zoom_surface = pic_parent->Root().RotZoomSurface(surface_orig, double(zoomx)/256.0, double(zoomy)/256.0, rotate);
	Rect zoom_r (*zoom_surface);
	picture->SetSurface(zoom_surface, 0, 0);
	picture->SetSurfaceFreeFlag();
	//picture->Move(PosX() + - zoom_r.width()/2, PosY() + - zoom_r.height()/2);
// 中心座標がわからん・・・
	picture->Move(320 - zoom_r.width()/2, 240 - zoom_r.height()/2);
	picture->SetSurfaceRect(Rect(0, 0, zoom_r.width(), zoom_r.height()));

	pic_parent->Root().DeleteSurface(surface_orig);
}

void GrpObj::UpdateMoji(void) { // 文字の大きさ、色などを変更
	if (print_moji.length() == 0 || print_size <= 2) return;
	if (pic_parent == 0) return;
	/* テキストの大きさを得る */
	int r, g, b;
	if (print_r == -1 || print_g == -1 || print_b == -1) {// 色設定なし
		r = g = b = 0;  // とりあえず黒(clannad のSave/Loadメニュー用)
	} else {
		r = print_r;
		g = print_g;
		b = print_b;
	}
	TextStream ts = TextStream::ParseMoji(print_moji.c_str(), r, g, b, print_size);
	TextGlyphStream gs;
	vector<int> lh;
	// とりあえず drawable width は充分に大きく(2048)取る
	DefaultLayout(print_size-2)->Layout(ts, gs, lh, 2048); // print_size そのままだと弱干大きすぎるので -2
	int width = gs.width();
	int height = gs.height();
	Surface* surface = pic_parent->Root().NewSurface(width, height, ALPHA_MASK);
	DSurfaceFill(surface, Rect(*surface), 0, 0, 0, 0);
	DSurfaceRenderText(gs.begin(), gs.end(), Rect(0, 0, width, height), surface, Rect(0,0));
	picture->SetSurface(surface, 0, 0);
	picture->SetSurfaceRect(Rect(0,0,width,height));
	picture->SetSurfaceFreeFlag();
}

void GrpObj::UpdateDigit(void) {
	// 画像表示の数値文字列を表示する
	if (name.length() == 0) return;
	// ファイル名が存在する場合、ファイルを読み込み
	string path(name);
	path += ".g00";
	Surface* surface_orig = pic_parent->Root().NewSurface(path.c_str());
	if (surface_orig == NULL) return;

	int width, height;
	int i;
	GetSrcGeom(width, height);
	if (width <= 0 || height <= 0) return;
	if (src_pos.size() < 14) {
		// 必要な数の object がない
		// 表示できない分の空の rect を追加しておく
		for (i=src_pos.size(); i<14; i++)
			src_pos.push_back(Rect(0,0,0,0));
		pic_parent->Root().DeleteSurface(surface_orig);
		return;
	}
	// 桁数の計算
	char num_str[20];
	if (dig_number < 0) sprintf(num_str, "%d", -dig_number);
	else sprintf(num_str, "%d", dig_number);
	int sign_count = 0;
	int space_count = 0;
	int total_count;
	int dig_count = strlen(num_str);
	if (dig_number < 0 && (attr&DIG_SIGN) == 0) dig_count++;
	if (dig_count < dig_digit) space_count = dig_digit - dig_count;
	if (attr & DIG_SIGN) sign_count = 1;
	total_count = dig_count + space_count + sign_count;

	Surface* surface = pic_parent->Root().NewSurface(width*total_count, height, ALPHA_MASK);
	DSurfaceFill(surface, Rect(*surface), 0, 0, 0, 0);

	/* surface にコピーする */
	int cur_x = 0;
	if ( (attr & DIG_PACK) && !(attr & DIG_ZERO)) { // 始めに空白を挿入
		cur_x += space_count * width;
	}
	int plus = 10, minus = 11, plusminus = 12;
	if (dig_number < 0) {
		DSurfaceMove(surface, src_pos[minus], surface, Rect(cur_x,0));
		cur_x += width;
	} else if (attr & DIG_SIGN) {
		if (dig_number == 0)
			DSurfaceMove(surface, src_pos[plusminus], surface, Rect(cur_x,0));
		else
			DSurfaceMove(surface, src_pos[plus], surface, Rect(cur_x,0));
		cur_x += width;
	}
	if (attr & DIG_ZERO) { // ゼロ・パディング
		for (i=0; i<space_count; i++) {
			DSurfaceMove(surface, src_pos[0], surface, Rect(cur_x, 0));
			cur_x += width;;
		}
	} else if (!(attr & DIG_PACK)) { // PACK オプションなし
		cur_x += space_count * width;
	}
	for (i=0; num_str[i] != 0; i++) {
		DSurfaceMove(surface_orig, src_pos[num_str[i]-'0'], surface, Rect(cur_x, 0));
		cur_x += width;
	}
	
	/* picture に設定 */
	picture->SetSurface(surface, 0, 0);
	picture->SetSurfaceRect(Rect(0,0,width*total_count,height));
	picture->SetSurfaceFreeFlag();

	pic_parent->Root().DeleteSurface(surface_orig);
}

void GrpObj::CreateGan(Event::Container& event, int event_number) {
	if (picture == NULL) {
		fprintf(stderr,"GrpObj::CreateGan() is called before Create()\n");
		return;
	}
	if (anm != NULL) {
		anm->Abort();
		delete anm;
		anm = NULL;
	}
	if (gan_name.empty()) return;
	/* アニーメション情報 (.GAN ファイル)を求める */
	string path(gan_name);
	path += ".gan";
	ARCINFO* info = FileSearcher::GetInstance()->Find(FileSearcher::GAN, path.c_str(), "gan");
	if (info == NULL) {
		fprintf(stderr,"GrpObj::CreateGan: Cannot Find 'GAN' file %s\n", path.c_str());
		return;
	}
	const char* data = info->Read();
	if (read_little_endian_int(data) != 10000 || read_little_endian_int(data+4) != 10000) {
		fprintf(stderr,"GrpObj::CreateGan: Invalid'GAN' file %s\n", path.c_str());
		delete info;
		return;
	}

	attr = Attribute(attr | UPDATE_POS);

	const char* buf = data + 16;
	buf += strlen(buf) + 1; // 画像ファイル名が入っている
	buf += 4; // 定数 20000
	int pics = read_little_endian_int(buf); buf += 4; // 複数のアニメーション情報が入っている場合、情報数 
	// 以下、pics 回繰り返し
	// アニメーションを行う実体を作成
	AnmAlphaMove* wid = new AnmAlphaMove(event, picture);

	if (event_number && event_number < pics) { // 複数のアニメーション情報がある場合、先の情報を読み飛ばす */
		int i; for (i=0; i<event_number; i++) {
			buf += 4; // 定数 30000
			int ptns = read_little_endian_int(buf); buf += 4;
			buf += ptns*52;
		}
	}
	buf += 4; // 定数 30000
	int ptns = read_little_endian_int(buf); buf += 4;
	int total_time = 0;
	int i;
	for (i=0; i<ptns; i++) {
		int p = read_little_endian_int(buf+i*52+0*8+4);
		int x = read_little_endian_int(buf+i*52+1*8+4);
		int y = read_little_endian_int(buf+i*52+2*8+4);
		int t = read_little_endian_int(buf+i*52+3*8+4);
		int a = read_little_endian_int(buf+i*52+4*8+4);
		x += PosX();
		y += PosY();
		if (p == -1) { a = 0; p = 0; } // p == -1 ならなにも表示しない
		if (p >= src_pos.size()) {
			fprintf(stderr,"Reading GAN file %s (G00 %s) : not enough pictures in .G00 file\n", path.c_str(), name.c_str());
			a = 0; p = 0;
		}
		total_time += t;
		wid->ptns.push_back(AnmAlphaMove::Ptn(Rect(x,y), src_pos[p], a, total_time));
	}
	wid->SetPtn(); // パターン登録終了
	attr = Attribute(attr | ANM_PLAYSTART);
	anm = wid;
}

void GrpObj::CreateGanSpecial(Event::Container& event, int event_number, int time) {
	if (picture == NULL) {
		fprintf(stderr,"GrpObj::CreateGan() is called before Create()\n");
		return;
	}
	if (anm != NULL) {
		anm->Abort();
		delete anm;
		anm = NULL;
	}

	// アニメーションを行う実体を作成
	AnmAlphaMove* wid = new AnmAlphaMove(event, picture);

	int i;
	switch(event_number) {
		case 0: // pattern を 0 から最後まで変化させる
			for (i=0; i<src_pos.size(); i++) {
				wid->ptns.push_back(AnmAlphaMove::Ptn(Rect(PosX(), PosY()), src_pos[i], 255, time*i));
			}
			wid->SetPtn(); // パターン登録終了
			anm = wid;
			attr = Attribute(attr | ANM_PLAYSTART);
			break;
		default:
			break;
	}
}

void GrpObj::SetZoomRotate(int new_zoom_x, int new_zoom_y, int new_rotate) {
	if (zoomx == new_zoom_x && zoomy == new_zoom_y && rotate == new_rotate) return;
	if (zoomx == -1 || zoomy == -1 || new_zoom_x == -1 || new_zoom_y == -1) {
		attr = Attribute(attr | UPDATE_POS); // centering する
	}
	zoomx = new_zoom_x;
	zoomy = new_zoom_y;
	if (new_rotate != -1) rotate = new_rotate;
	if (zoomx < 0) zoomx = 256;
	if (zoomy < 0) zoomy = 256;
	if (rotate < 0) rotate = 0;
	else if (rotate > 360) rotate %= 360;

	attr = Attribute(attr | UPDATE_PICTURE);
}

void GrpObj::Refresh(GrpObj& parent_obj) {
	//if (&parent_obj != this) printf("Toto\n"); //FIXME

	GrpObjMap::iterator it;

	for (it = children_obj.begin(); it != children_obj.end(); it++)
		it->second.Refresh(parent_obj);

	if (picture == NULL) return;
	if (alpha == 0 || (attr & GrpObj::HIDDEN) || (parent_obj.attr & GrpObj::HIDDEN)) {
		if (attr & GrpObj::ANM_PLAYING) {
			attr = GrpObj::Attribute(attr & ~(GrpObj::ANM_PLAYING));
			if (anm != NULL) anm->Abort();
		}
		picture->hide();
	} else {
		Update();
		picture->show();
	}
}

void GrpObj::_debug_Dump(int id, int indent)
{
	const char* repr;

	if (indent == 0)
		repr = "obj %04d(%p): name %10s  pos %d,%d alpha %d (%d/%d/%d)\n";
	else
		repr = "  * obj %04d(%p): name %10s  pos %d,%d alpha %d (%d/%d/%d)\n";

	if (picture != NULL) {
		if (!name.empty())
			fprintf(stderr, repr,
				id, this, name.c_str(), PosX(), PosY(), alpha, attr&GrpObj::HIDDEN ? 1 : 0, 0,
				picture->IsHidden());
		else if (!print_moji.empty())
			fprintf(stderr, repr,
				id, this, print_moji.c_str(), PosX(), PosY(), alpha, attr&GrpObj::HIDDEN ? 1 : 0,
				0, picture->IsHidden());
		else
			fprintf(stderr, repr,
				id, this, "<EMPTY>", PosX(), PosY(), alpha, attr&GrpObj::HIDDEN ? 1 : 0, 0,
				picture->IsHidden());
	}

	GrpObjMap::iterator it;
	for (it = children_obj.begin(); it != children_obj.end(); it++)
		it->second._debug_Dump(it->first, indent+1);
}

/******************************************************************
**
**	class ScnGrp*
*/
/* Princess Bride: 背景画の一部のみ移動、の実装 */

ScnGrpMove::ScnGrpMove(Event::Container& container, PicBase* _pic, PicRoot& _root, Surface* _dest, const Rect& _dest_r, Surface* _src, const Rect& _from, const Rect& _to, int total_time) :
	WidAnmTime(container, _pic, total_time),
	dest(_dest), src(_src), root(_root),dest_r(_dest_r), from(_from), to(_to) {
	int dx = to.lx - from.lx;
	int dy = to.ty - from.ty;
	if (dx < 0) dx = -dx;
	if (dy < 0) dy = -dy;
	if (dx < dy) dx = dy;
	if (dx == 0) dx = 1;
	SetAllCount(dx);
}

void ScnGrpMove::Exec(int count) {
	Rect r(0,0,dest_r.width(),dest_r.height());
	int dx = to.lx - from.lx;
	int dy = to.ty - from.ty;
	int x = dx*count/all_count + from.lx;
	int y = dy*count/all_count + from.ty;
	r.rmove(x, y);
	root.BlitSurface(src, r, dest, dest_r);
	iterator it;
	for (it=pic.begin(); it!=pic.end(); it++)
		(*it)->SetSurface(dest, 0, 0);
}

void ScnGrpAnm::CalcTotal(void) {
	/* total time を計算 */
	if (empty()) return;
	int tm = 0;
	vector<ScnGrpAnmAtom>::iterator it;
	for (it=begin(); it != end(); it++) tm += it->time;
	total_time = tm;
	SetAllCount(tm);
}

void ScnGrpAnm::Exec(int count) {
	int tm = 0; vector<ScnGrpAnmAtom>::iterator it;
	for (it=begin(); it != end(); it++) {
		tm += it->time;
		if (count < tm) break;
	}
	if (it == end()) it--;
	owner.LoadSurface(it->name.c_str(), 0);
}


/*****************************************************
*
*  Grp
*
*/

#include "music2/music.h"

Grp::Grp(Event::Container& _event, PicContainer& _parent, const Flags& f, set<int>& _cgm_data):
	event(_event),
	flags(f), 
	parent(_parent),
	status(NORMAL),
	skip_mode(SKIP_NO),
	cgm_data(_cgm_data)
{
	int i;
	for (i=0; i<MAXPDT; i++) {
		ssurface[i] = 0;
		dsurface[i] = 0;
	}

	music = MuSys::GetInstance();
	config = AyuSysConfig::GetInstance();

	screen = parent.create_leaf(Rect(0, 0, parent.Width(), parent.Height()), 0);
	screen_front = parent.create_leaf(Rect(0, 0, parent.Width(), parent.Height()), 0);
	surface = parent.Root().NewSurface(parent.Width(), parent.Height(), NO_MASK);
	surface_update = parent.Root().NewSurface(parent.Width(), parent.Height(), NO_MASK);
	DSurfaceFill(surface, Rect(*surface), 0, 0, 0);
	DSurfaceFill(surface_update, Rect(*surface), 0, 0, 0);
	screen->SetSurface(surface, 0, 0);
	screen->show();
	screen_front->hide();
	screen_front->ZMove(screen);

	LoadCgm();

	// Jumps
	RegisterCommand(0, 1, 0, "goto", NULL);
	RegisterCommand(0, 1, 1, "goto_if", NULL);
	RegisterCommand(0, 1, 2, "goto_unless", NULL);
	RegisterCommand(0, 1, 3, "goto_on", NULL);
	RegisterCommand(0, 1, 4, "goto_case", NULL);
	RegisterCommand(0, 1, 5, "gosub", NULL);
	RegisterCommand(0, 1, 6, "gosub_if", NULL);
	RegisterCommand(0, 1, 7, "gosub_unless", NULL);
	RegisterCommand(0, 1, 8, "gosub_on", NULL);
	RegisterCommand(0, 1, 9, "gosub_case", NULL);
	RegisterCommand(0, 1, 10, "ret", NULL);
	RegisterCommand(0, 1, 11, "jump", NULL);
	RegisterCommand(0, 1, 12, "farcall", NULL);
	RegisterCommand(0, 1, 13, "rtl", NULL);
	RegisterCommand(0, 1, 16, "gosub_with", NULL);
	RegisterCommand(0, 1, 17, "ret_with", NULL);
	RegisterCommand(0, 1, 18, "farcall_with", NULL);
	RegisterCommand(0, 1, 19, "rtl_with", NULL);

	RegisterCommand(2, 1, 1, "??? (unknown)", NULL);
	RegisterCommand(2, 1, 2, "InvokeDLL", NULL);
	RegisterCommand(2, 1, 10, "LoadDLL", NULL);
	RegisterCommand(2, 1, 11, "UnloadDLL", NULL);
	RegisterCommand(2, 1, 12, "CallDLL", NULL);


	// Selections
	RegisterCommand(0, 2, 0, "select_w", NULL);
	RegisterCommand(0, 2, 1, "select", NULL);
	RegisterCommand(0, 2, 2, "select_s2", NULL);
	RegisterCommand(0, 2, 3, "select_s", NULL);

	RegisterCommand(0, 2, 10, "select_?? (10)", NULL);
	RegisterCommand(0, 2, 11, "select_?? (11)", NULL);
	RegisterCommand(0, 2, 12, "select_?? (12)", NULL);
	RegisterCommand(0, 2, 13, "select_?? (13)", NULL);


	// Messages
	RegisterCommand(0, 3, 3, "par", NULL);

	RegisterCommand(0, 3, 15, "spause3", NULL);
	RegisterCommand(0, 3, 17, "pause", NULL);

	RegisterCommand(0, 3, 100, "SetFontColour", NULL);
	RegisterCommand(0, 3, 101, "FontSize", NULL);
	RegisterCommand(0, 3, 102, "TextWindow", NULL);
	RegisterCommand(0, 3, 103, "FastText", NULL);
	RegisterCommand(0, 3, 104, "NormalText", NULL);
	RegisterCommand(0, 3, 105, "FontColour", NULL);
	RegisterCommand(0, 3, 106, "SetFontColourAll", NULL);
	RegisterCommand(0, 3, 107, "FontSizeAll", NULL);

	RegisterCommand(0, 3, 120, "__doruby", NULL);

	// Already in _text
	/* RegisterCommand(0, 3, 151, "msgHide", NULL);
	RegisterCommand(0, 3, 152, "msgClear", NULL); */
	RegisterCommand(0, 3, 161, "msgHideAll", NULL);
	RegisterCommand(0, 3, 162, "msgClearAll", NULL);
	RegisterCommand(0, 3, 170, "msgHideAllTemp", NULL);

	RegisterCommand(0, 3, 201, "br", NULL);
	RegisterCommand(0, 3, 202, "par2", NULL);
	RegisterCommand(0, 3, 205, "spause", NULL);
	RegisterCommand(0, 3, 206, "spause2", NULL);
	RegisterCommand(0, 3, 207, "pause_all", NULL);
	RegisterCommand(0, 3, 210, "page", NULL);

	RegisterCommand(0, 3, 300, "SetIndent", NULL);
	RegisterCommand(0, 3, 301, "ClearIndent", NULL);
  
	RegisterCommand(0, 3, 310, "TextPos", NULL);
	RegisterCommand(0, 3, 311, "TextPosX", NULL);
	RegisterCommand(0, 3, 312, "TextPosY", NULL);
	RegisterCommand(0, 3, 320, "TextOffset", NULL);
	RegisterCommand(0, 3, 321, "TextOffsetX", NULL);
	RegisterCommand(0, 3, 322, "TextOffsetY", NULL);
	RegisterCommand(0, 3, 330, "GetTextPos", NULL);

	RegisterCommand(0, 3, 340, "WindowLen", NULL);
	RegisterCommand(0, 3, 341, "WindowLenAll", NULL);

	RegisterCommand(0, 3, 1000, "FaceOpen", NULL);
	RegisterCommand(0, 3, 1001, "FaceClear", NULL);

	RegisterCommand(0, 3, 2000, "??? (overloads 0 and 1?)", NULL);
	RegisterCommand(0, 3, 3000, "??? (unknown)", NULL);


	// System
	RegisterCommand(0, 4, 120, "SetInterrupt", NULL);
	RegisterCommand(0, 4, 121, "ClearInterrupt", NULL);
	RegisterCommand(0, 4, 303, "yield", NULL);

	RegisterCommand(0, 4, 300, "rtlButton", NULL);
	RegisterCommand(0, 4, 301, "rtlCancel", NULL);
	RegisterCommand(0, 4, 302, "rtlSystem", NULL);

	RegisterCommand(0, 4, 1000, "ShowBackground", NULL);
	RegisterCommand(0, 4, 1100, "SetSkipMode", NULL);
	RegisterCommand(0, 4, 1101, "ClearSkipMode", NULL);
	RegisterCommand(0, 4, 1102, "SkipMode", NULL);

	RegisterCommand(0, 4, 2000, "aaa", NULL);
	RegisterCommand(0, 4, 2001, "aaa", NULL);

	RegisterCommand(0, 4, 0, "pause", NULL);
	RegisterCommand(0, 4, 1, "page", NULL);
	RegisterCommand(0, 4, 2, "bgmLoop", NULL);

	RegisterCommand(1, 4, 0, "title", NULL);

	RegisterCommand(1, 4, 100, "wait", NULL);
	RegisterCommand(1, 4, 101, "waitC", NULL);

	RegisterCommand(1, 4, 110, "ResetTimer", NULL);
	RegisterCommand(1, 4, 111, "time", NULL);
	RegisterCommand(1, 4, 112, "timeC", NULL);
	RegisterCommand(1, 4, 113, "tipeC2/Timer2", NULL);
	RegisterCommand(1, 4, 114, "Timer", NULL);
	RegisterCommand(1, 4, 115, "CmpTimer", NULL);
	RegisterCommand(1, 4, 116, "SetTimer", NULL);

	RegisterCommand(1, 4, 120, "ResetExTimer", NULL);
	RegisterCommand(1, 4, 121, "timeEx", NULL);
	RegisterCommand(1, 4, 122, "timeExC", NULL);
	RegisterCommand(1, 4, 123, "timeExC2", NULL);
	RegisterCommand(1, 4, 124, "ExTimer", NULL);
	RegisterCommand(1, 4, 125, "CmpExTimer", NULL);
	RegisterCommand(1, 4, 126, "SetExTimer", NULL);

	RegisterCommand(1, 4, 130, "FlushClick", NULL);
	RegisterCommand(1, 4, 131, "GetClick", NULL);
	RegisterCommand(1, 4, 132, "WaitClick", NULL);
	RegisterCommand(1, 4, 133, "GetCursorPos2", NULL);
	RegisterCommand(1, 4, 134, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 135, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 136, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 137, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 138, "GetCursorPos2", NULL);

	RegisterCommand(1, 4, 151, "??? (unknown)", NULL);

	RegisterCommand(1, 4, 200, "KeyMouseOn", NULL);
	RegisterCommand(1, 4, 201, "KeyMouseOff", NULL);
	RegisterCommand(1, 4, 202, "GetCursorPos2", NULL);
	RegisterCommand(1, 4, 203, "SetCursorPos", NULL);
	RegisterCommand(1, 4, 204, "ShowCursor", NULL);
	RegisterCommand(1, 4, 205, "HideCursor", NULL);
	RegisterCommand(1, 4, 206, "GetMouseCursor", NULL);
	RegisterCommand(1, 4, 207, "MouseCursor", NULL);

	RegisterCommand(1, 4, 320, "CallStackClear", NULL);
	RegisterCommand(1, 4, 321, "CallStackNop", NULL);
	RegisterCommand(1, 4, 322, "CallStackPop", NULL);
	RegisterCommand(1, 4, 323, "CallStackSize", NULL);
	RegisterCommand(1, 4, 324, "CallStackTrunc", NULL);

	RegisterCommand(1, 4, 330, "EnableSkipMode", NULL);
	RegisterCommand(1, 4, 331, "DisableSkipMode", NULL);
	RegisterCommand(1, 4, 332, "LocalSkipMode", NULL);
	RegisterCommand(1, 4, 333, "SetLocalSkipMode", NULL);
	RegisterCommand(1, 4, 334, "ClearLocalSkipMode", NULL);

	RegisterCommand(1, 4, 350, "CtrlKeySkip", NULL);
	RegisterCommand(1, 4, 351, "CtrlKeySkipOn", NULL);
	RegisterCommand(1, 4, 352, "CtrlKeySkipOff", NULL);
	RegisterCommand(1, 4, 353, "CtrlPressed", NULL);
	RegisterCommand(1, 4, 354, "ShiftPressed", NULL);

	RegisterCommand(1, 4, 364, "PauseCursor", NULL);

	RegisterCommand(1, 4, 400, "GetWindowPos", NULL);
	RegisterCommand(1, 4, 401, "SetWindowPos", NULL);
	RegisterCommand(1, 4, 402, "WindowResetPos", NULL);
	RegisterCommand(1, 4, 403, "GetDefaultWindowPos", NULL);
	RegisterCommand(1, 4, 404, "SetDefaultWindowPos", NULL);
	RegisterCommand(1, 4, 405, "DefaultWindowResetPos", NULL);

	RegisterCommand(1, 4, 410, "GetWakuAll", NULL);
	RegisterCommand(1, 4, 411, "SetWakuAll", NULL);
	RegisterCommand(1, 4, 412, "GetWaku", NULL);
	RegisterCommand(1, 4, 413, "SetWaku", NULL);
	RegisterCommand(1, 4, 414, "GetWakuMod", NULL);
	RegisterCommand(1, 4, 415, "SetWakuMod_dwm", NULL);
	RegisterCommand(1, 4, 416, "SetWakuMod_ewm", NULL);

	RegisterCommand(1, 4, 420, "GetWindowAttr2", NULL);
	RegisterCommand(1, 4, 421, "SetWindowAttr2", NULL);

	RegisterCommand(1, 4, 422, "GetWindowModAttr", NULL);
	RegisterCommand(1, 4, 423, "SetWindowModAttr", NULL);
	RegisterCommand(1, 4, 424, "GetWindowAttrMod", NULL);
	RegisterCommand(1, 4, 425, "SetWindowAttrMod_sam0", NULL);
	RegisterCommand(1, 4, 426, "SetWindowAttrMod_sam1", NULL);
	RegisterCommand(1, 4, 427, "SetWindowAttrMod_sam2", NULL);

	RegisterCommand(1, 4, 430, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 431, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 432, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 435, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 436, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 437, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 440, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 441, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 442, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 445, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 446, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 447, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 450, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 451, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 452, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 455, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 456, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 457, "??? (unknown)", NULL);
  
	RegisterCommand(1, 4, 460, "EnableWindowAnm", NULL);
	RegisterCommand(1, 4, 461, "DisableWindowAnm", NULL);
	RegisterCommand(1, 4, 462, "GetOpenAnmMod", NULL);
	RegisterCommand(1, 4, 463, "SetOpenAnmMod", NULL);
	RegisterCommand(1, 4, 464, "GetOpenAnmTime", NULL);
	RegisterCommand(1, 4, 465, "SetOpenAnmTime", NULL);
	RegisterCommand(1, 4, 466, "GetCloseAnmMod", NULL);
	RegisterCommand(1, 4, 467, "SetCloseAnmMod", NULL);
	RegisterCommand(1, 4, 468, "GetCloseAnmTime", NULL);
	RegisterCommand(1, 4, 469, "SetCloseAnmTime", NULL);

	RegisterCommand(1, 4, 500, "InitFrame", NULL);
	RegisterCommand(1, 4, 501, "InitFrameLoop", NULL);
	RegisterCommand(1, 4, 502, "InitFrameTurn", NULL);
	RegisterCommand(1, 4, 503, "InitFrameAccel", NULL);
	RegisterCommand(1, 4, 504, "InitFrameDecel", NULL);
	RegisterCommand(1, 4, 510, "ReadFrame", NULL);
	RegisterCommand(1, 4, 511, "FrameActive", NULL);
	RegisterCommand(1, 4, 512, "AnyFrameActive", NULL);
	RegisterCommand(1, 4, 513, "ClearFrame", NULL);
	RegisterCommand(1, 4, 514, "ClearAllFrames", NULL);
	RegisterCommand(1, 4, 520, "InitExFrame", NULL);
	RegisterCommand(1, 4, 521, "InitExFrameLoop", NULL);
	RegisterCommand(1, 4, 522, "InitExFrameTurn", NULL);
	RegisterCommand(1, 4, 523, "InitExFrameAccel", NULL);
	RegisterCommand(1, 4, 524, "InitExFrameDecel", NULL);
	RegisterCommand(1, 4, 530, "ReadExFrame", NULL);
	RegisterCommand(1, 4, 531, "ExFrameActive", NULL);
	RegisterCommand(1, 4, 532, "AnyExFrameActive", NULL);
	RegisterCommand(1, 4, 533, "ClearExFrame", NULL);
	RegisterCommand(1, 4, 534, "ClearAllExFrames", NULL);

	RegisterCommand(1, 4, 600, "InitFrames", NULL);
	RegisterCommand(1, 4, 601, "InitFramesLoop", NULL);
	RegisterCommand(1, 4, 602, "InitFramesTurn", NULL);
	RegisterCommand(1, 4, 603, "InitFramesAccel", NULL);
	RegisterCommand(1, 4, 604, "InitFramesDecel", NULL);
	RegisterCommand(1, 4, 610, "ReadFrames", NULL);
	RegisterCommand(1, 4, 620, "InitExFrames", NULL);
	RegisterCommand(1, 4, 621, "InitExFramesLoop", NULL);
	RegisterCommand(1, 4, 622, "InitExFramesTurn", NULL);
	RegisterCommand(1, 4, 623, "InitExFramesAccel", NULL);
	RegisterCommand(1, 4, 624, "InitExFramesDecel", NULL);
	RegisterCommand(1, 4, 630, "ReadExFrames", NULL);

	RegisterCommand(1, 4, 800, "index_series", NULL);
	RegisterCommand(1, 4, 801, "??? (unknown)", NULL);

	RegisterCommand(1, 4, 1000, "rnd", NULL);
	RegisterCommand(1, 4, 1001, "pcnt", NULL);
	RegisterCommand(1, 4, 1002, "abs", NULL);
	RegisterCommand(1, 4, 1003, "power", NULL);
	RegisterCommand(1, 4, 1004, "sin", NULL);
	RegisterCommand(1, 4, 1005, "modulus", NULL);
	RegisterCommand(1, 4, 1006, "angle", NULL);
	RegisterCommand(1, 4, 1007, "min", NULL);
	RegisterCommand(1, 4, 1008, "max", NULL);
	RegisterCommand(1, 4, 1009, "constrain", NULL);
	RegisterCommand(1, 4, 1010, "cos", NULL);
	RegisterCommand(1, 4, 1011, "sign", NULL);
	RegisterCommand(1, 4, 1012, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 1013, "??? (unknown)", NULL);

	RegisterCommand(1, 4, 1100, "GetYear", NULL);
	RegisterCommand(1, 4, 1101, "GetMonth", NULL);
	RegisterCommand(1, 4, 1102, "GetDay", NULL);
	RegisterCommand(1, 4, 1103, "GetDayOfWeek", NULL);
	RegisterCommand(1, 4, 1104, "GetHour", NULL);
	RegisterCommand(1, 4, 1105, "GetMinute", NULL);
	RegisterCommand(1, 4, 1106, "GetSecond", NULL);
	RegisterCommand(1, 4, 1107, "GetMs", NULL);
	RegisterCommand(1, 4, 1110, "GetDate", NULL);
	RegisterCommand(1, 4, 1111, "GetTime", NULL);
	RegisterCommand(1, 4, 1112, "GetDateTime", NULL);

	RegisterCommand(1, 4, 1120, "SceneNum", NULL);

	RegisterCommand(1, 4, 1130, "DefaultGrp", NULL);
	RegisterCommand(1, 4, 1131, "SetDefaultGrp", NULL);
	RegisterCommand(1, 4, 1132, "DefaultBgr", NULL);
	RegisterCommand(1, 4, 1133, "SetDefaultBgr", NULL);

	RegisterCommand(1, 4, 1200, "end", NULL);
	RegisterCommand(1, 4, 1201, "MenuReturn", NULL);
	RegisterCommand(1, 4, 1202, "MenuReturn2", NULL);
	RegisterCommand(1, 4, 1203, "ReturnMenu", NULL);
	RegisterCommand(1, 4, 1204, "ReturnPrevSelect", NULL);
	RegisterCommand(1, 4, 1205, "ReturnPrevSelect2", NULL);

	RegisterCommand(1, 4, 1210, "ContextMenu", NULL);
	RegisterCommand(1, 4, 1211, "EnableSyscom", NULL);
	RegisterCommand(1, 4, 1212, "HideSyscom", NULL);
	RegisterCommand(1, 4, 1213, "DisableSyscom", NULL);
	RegisterCommand(1, 4, 1214, "SyscomEnabled", NULL);
	RegisterCommand(1, 4, 1215, "InvokeSyscom", NULL);
	RegisterCommand(1, 4, 1216, "ReadSyscom", NULL);

	RegisterCommand(1, 4, 1220, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 1221, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 1222, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 1230, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 1231, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 1232, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 1250, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 1251, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 1252, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 1253, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 1254, "??? (unknown)", NULL);

	RegisterCommand(1, 4, 1300, "GetName", NULL);
	RegisterCommand(1, 4, 1301, "SetName", NULL);
	RegisterCommand(1, 4, 1302, "nwSingle", NULL);
	RegisterCommand(1, 4, 1303, "nwMulti", NULL);
	RegisterCommand(1, 4, 1310, "GetLocalName", NULL);
	RegisterCommand(1, 4, 1311, "SetLocalName", NULL);
	RegisterCommand(1, 4, 1312, "nwSingleLocal", NULL);
	RegisterCommand(1, 4, 1313, "nwMultiLocal", NULL);

	RegisterCommand(1, 4, 1409, "SaveExists", NULL);
	RegisterCommand(1, 4, 1410, "SaveDate", NULL);
	RegisterCommand(1, 4, 1411, "SaveTime", NULL);
	RegisterCommand(1, 4, 1412, "SaveDateTime", NULL);
	RegisterCommand(1, 4, 1413, "SaveInfo", NULL);
	RegisterCommand(1, 4, 1414, "GetSaveFlag", NULL);
	RegisterCommand(1, 4, 1421, "LatestSave", NULL);

	RegisterCommand(1, 4, 1500, "cgGetTotal", (CmdImpl) &Grp::impl_cgGet);
	RegisterCommand(1, 4, 1501, "cgGetViewed", (CmdImpl) &Grp::impl_cgGet);
	RegisterCommand(1, 4, 1502, "cgGetViewedPcnt", (CmdImpl) &Grp::impl_cgGet);
	RegisterCommand(1, 4, 1503, "cgGetFlag", (CmdImpl) &Grp::impl_cgStatus);
	RegisterCommand(1, 4, 1504, "cgStatus", (CmdImpl) &Grp::impl_cgStatus);
	RegisterCommand(1, 4, 1505, "??? (unknown)", NULL);

	// Input
	RegisterCommand(1, 4, 1700, "CreateInput", NULL);
	RegisterCommand(1, 4, 1701, "CloseInput", NULL);
	RegisterCommand(1, 4, 1702, "CloseAllInput", NULL);
	RegisterCommand(1, 4, 1703, "FocusInput", NULL);
	RegisterCommand(1, 4, 1710, "SetInput", NULL);
	RegisterCommand(1, 4, 1711, "GetInput", NULL);

	RegisterCommand(1, 4, 2050, "SetCursorMono", NULL);
	RegisterCommand(1, 4, 2000, "CursorMono", NULL);
	RegisterCommand(1, 4, 2051, "SetSkipAnimations", NULL);
	RegisterCommand(1, 4, 2001, "SkipAnimations", NULL);
	RegisterCommand(1, 4, 2052, "SetLowPriority", NULL);
	RegisterCommand(1, 4, 2002, "LowPriority", NULL);
	RegisterCommand(1, 4, 2053, "SetConfirmSaveLoad", NULL);
	RegisterCommand(1, 4, 2003, "ConfirmSaveLoad", NULL);
	RegisterCommand(1, 4, 2054, "SetReduceDistortion", NULL);
	RegisterCommand(1, 4, 2004, "ReduceDistortion", NULL);
	RegisterCommand(1, 4, 2059, "SetSoundQuality", NULL);
	RegisterCommand(1, 4, 2009, "SoundQuality", NULL);
	RegisterCommand(1, 4, 2221, "SetGeneric1", NULL);
	RegisterCommand(1, 4, 2620, "DefGeneric1", NULL);
	RegisterCommand(1, 4, 2321, "Generic1", NULL);
	RegisterCommand(1, 4, 2222, "SetGeneric2", NULL);
	RegisterCommand(1, 4, 2322, "Generic2", NULL);
	RegisterCommand(1, 4, 2621, "DefGeneric2", NULL);
	RegisterCommand(1, 4, 2223, "SetMessageSpeed", NULL);
	RegisterCommand(1, 4, 2323, "MessageSpeed", NULL);
	RegisterCommand(1, 4, 2600, "DefMessageSpeed", NULL);
	RegisterCommand(1, 4, 2224, "SetMessageNoWait", NULL);
	RegisterCommand(1, 4, 2324, "MessageNoWait", NULL);
	RegisterCommand(1, 4, 2601, "DefMessageNoWait", NULL);
	RegisterCommand(1, 4, 2225, "SetKoeMode", NULL);
	RegisterCommand(1, 4, 2325, "KoeMode", NULL);
	RegisterCommand(1, 4, 2226, "SetBgmKoeFadeVol", NULL);
	RegisterCommand(1, 4, 2326, "BgmKoeFadeVol", NULL);
	RegisterCommand(1, 4, 2602, "DefBgmKoeFadeVol", NULL);
	RegisterCommand(1, 4, 2227, "SetBgmKoeFade", NULL);
	RegisterCommand(1, 4, 2327, "BgmKoeFade", NULL);
	RegisterCommand(1, 4, 2603, "DefBgmKoeFade", NULL);

	RegisterCommand(1, 4, 2230, "SetBgmVolMod", (CmdImpl) &Grp::impl_SetVolMod);
	RegisterCommand(1, 4, 2330, "BgmVolMod", (CmdImpl) &Grp::impl_GetVolMod);
	RegisterCommand(1, 4, 2231, "SetKoeVolMod", (CmdImpl) &Grp::impl_SetVolMod);
	RegisterCommand(1, 4, 2331, "KoeVolMod", (CmdImpl) &Grp::impl_GetVolMod);
	RegisterCommand(1, 4, 2232, "SetPCMVolMod", (CmdImpl) &Grp::impl_SetVolMod);
	RegisterCommand(1, 4, 2332, "PCMVolMod", (CmdImpl) &Grp::impl_GetVolMod);
	RegisterCommand(1, 4, 2233, "SetSeVolMod", (CmdImpl) &Grp::impl_SetVolMod);
	RegisterCommand(1, 4, 2333, "SeVolMod", (CmdImpl) &Grp::impl_GetVolMod);

	RegisterCommand(1, 4, 2240, "SetBgmEnabled", NULL);
	RegisterCommand(1, 4, 2340, "BgmEnabled", NULL);
	RegisterCommand(1, 4, 2241, "SetKoeEnabled", NULL);
	RegisterCommand(1, 4, 2341, "KoeEnabled", NULL);
	RegisterCommand(1, 4, 2242, "SetPcmEnabled", NULL);
	RegisterCommand(1, 4, 2342, "PcmEnabled", NULL);
	RegisterCommand(1, 4, 2243, "SetSeEnabled", NULL);
	RegisterCommand(1, 4, 2343, "SeEnabled", NULL);
	RegisterCommand(1, 4, 2250, "SetAutoMode", NULL);
	RegisterCommand(1, 4, 2350, "AutoMode", NULL);
	RegisterCommand(1, 4, 2604, "DefAutoMode", NULL);
	RegisterCommand(1, 4, 2251, "SetAutoCharTime", NULL);
	RegisterCommand(1, 4, 2351, "AutoCharTime", NULL);
	RegisterCommand(1, 4, 2605, "DefAutoCharTime", NULL);
	RegisterCommand(1, 4, 2252, "SetAutoBaseTime", NULL);
	RegisterCommand(1, 4, 2352, "AutoBaseTime", NULL);
	RegisterCommand(1, 4, 2606, "DefAutoBaseTime", NULL);
	RegisterCommand(1, 4, 2255, "SetFontQuality", NULL);
	RegisterCommand(1, 4, 2355, "FontQuality", NULL);
	RegisterCommand(1, 4, 2256, "SetFontWeight", NULL);
	RegisterCommand(1, 4, 2356, "FontWeight", NULL);
	RegisterCommand(1, 4, 2257, "SetFontShadow", NULL);
	RegisterCommand(1, 4, 2357, "FontShadow", NULL);
	RegisterCommand(1, 4, 2260, "SetWindowAttrR", NULL);
	RegisterCommand(1, 4, 2360, "WindowAttrR", NULL);
	RegisterCommand(1, 4, 2610, "DefWindowAttrR", NULL);
	RegisterCommand(1, 4, 2261, "SetWindowAttrG", NULL);
	RegisterCommand(1, 4, 2361, "WindowAttrG", NULL);
	RegisterCommand(1, 4, 2611, "DefWindowAttrG", NULL);
	RegisterCommand(1, 4, 2262, "SetWindowAttrB", NULL);
	RegisterCommand(1, 4, 2362, "WindowAttrB", NULL);
	RegisterCommand(1, 4, 2612, "DefWindowAttrB", NULL);
	RegisterCommand(1, 4, 2263, "SetWindowAttrA", NULL);
	RegisterCommand(1, 4, 2363, "WindowAttrA", NULL);
	RegisterCommand(1, 4, 2613, "DefWindowAttrA", NULL);
	RegisterCommand(1, 4, 2264, "SetWindowAttrF", NULL);
	RegisterCommand(1, 4, 2364, "WindowAttrF", NULL);
	RegisterCommand(1, 4, 2614, "DefWindowAttrF", NULL);
	RegisterCommand(1, 4, 2265, "SetWindowAttr_swaRGB", NULL);
	RegisterCommand(1, 4, 2365, "GetWindowAttr_gwaRGB", NULL);
	RegisterCommand(1, 4, 2615, "DefWindowAttr_dwaRGB", NULL);
	RegisterCommand(1, 4, 2266, "SetWindowAttr_swaRGBA", NULL);
	RegisterCommand(1, 4, 2366, "GetWindowAttr_gwaRGBA", NULL);
	RegisterCommand(1, 4, 2616, "DefWindowAttr_dwaRGBA", NULL);
	RegisterCommand(1, 4, 2267, "SetWindowAttr", NULL);
	RegisterCommand(1, 4, 2367, "GetWindowAttr", NULL);
	RegisterCommand(1, 4, 2617, "DefWindowAttr", NULL);
	RegisterCommand(1, 4, 2270, "SetShowObject1", NULL);
	RegisterCommand(1, 4, 2370, "ShowObject1", NULL);
	RegisterCommand(1, 4, 2271, "SetShowObject2", NULL);
	RegisterCommand(1, 4, 2371, "ShowObject2", NULL);
	RegisterCommand(1, 4, 2272, "SetShowWeather", NULL);
	RegisterCommand(1, 4, 2372, "ShowWeather", NULL);
	RegisterCommand(1, 4, 2273, "SetClassifyText", NULL);
	RegisterCommand(1, 4, 2373, "ClassifyText", NULL);
	RegisterCommand(1, 4, 2274, "SetUseKoe", NULL);
	RegisterCommand(1, 4, 2374, "UseKoe", NULL);
	RegisterCommand(1, 4, 2275, "SetScreenMode", NULL);
	RegisterCommand(1, 4, 2375, "ScreenMode", NULL);
	RegisterCommand(1, 4, 2276, "??? (setsyscom12?)", NULL);
	RegisterCommand(1, 4, 2622, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 2623, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 2624, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 2625, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 2626, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 2627, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 2628, "??? (unknown)", NULL);
	RegisterCommand(1, 4, 2629, "??? (unknown)", NULL);

	RegisterCommand(1, 4, 3000, "menu_save", NULL);
	RegisterCommand(1, 4, 3001, "menu_load", NULL);
	RegisterCommand(1, 4, 3002, "savemenu", NULL);
	RegisterCommand(1, 4, 3003, "loadmenu", NULL);
	RegisterCommand(1, 4, 3006, "save2", NULL);
	RegisterCommand(1, 4, 3007, "save", NULL);
	RegisterCommand(1, 4, 3008, "load2", NULL);
	RegisterCommand(1, 4, 3009, "load", NULL);
	RegisterCommand(1, 4, 3100, "menu_save_always", NULL);
	RegisterCommand(1, 4, 3101, "menu_load_always", NULL);
	RegisterCommand(1, 4, 3106, "save_always2", NULL);
	RegisterCommand(1, 4, 3107, "save_always", NULL);
	RegisterCommand(1, 4, 3108, "load_always2", NULL);
	RegisterCommand(1, 4, 3109, "load_always", NULL);

	RegisterCommand(1, 4, 3500, "Savepoint", NULL);
	RegisterCommand(1, 4, 3501, "EnableAutoSavepoints", NULL);
	RegisterCommand(1, 4, 3502, "DisableAutoSavepoints", NULL);
	RegisterCommand(1, 4, 3503, "??? (unknown)", NULL);


	// Os
	RegisterCommand(1, 5, 0, "shell", NULL);
	RegisterCommand(1, 5, 10, "launch", NULL);

	RegisterCommand(0, 5, 1, "goto", NULL);
	RegisterCommand(0, 5, 2, "goto_unless", NULL);
	RegisterCommand(0, 5, 5, "gosub", NULL);
	RegisterCommand(0, 5, 6, "gosub_if", NULL);
	RegisterCommand(0, 5, 7, "gosub_unless", NULL);
	RegisterCommand(0, 5, 10, "ret", NULL);
	RegisterCommand(0, 5, 11, "jump", NULL);
	RegisterCommand(0, 5, 12, "farcall", NULL);
	RegisterCommand(0, 5, 13, "rtl", NULL);


	// String
	RegisterCommand(1, 10, 0, "strcpy", NULL);
	RegisterCommand(1, 10, 1, "strclear", NULL);
	RegisterCommand(1, 10, 2, "strcat", NULL);
	RegisterCommand(1, 10, 3, "strlen", NULL);
	RegisterCommand(1, 10, 4, "strcmp", NULL);
	RegisterCommand(1, 10, 5, "strsub", NULL);
	RegisterCommand(1, 10, 6, "strrsub", NULL);
	RegisterCommand(1, 10, 7, "strcharlen", NULL);
	RegisterCommand(1, 10, 8, "strtrunc", NULL);
	RegisterCommand(1, 10, 10, "hantozen", NULL);
	RegisterCommand(1, 10, 11, "zentohan", NULL);
	RegisterCommand(1, 10, 12, "Uppercase", NULL);
	RegisterCommand(1, 10, 13, "Lowercase", NULL);
	RegisterCommand(1, 10, 14, "itoa_ws", NULL);
	RegisterCommand(1, 10, 15, "itoa_s", NULL);
	RegisterCommand(1, 10, 16, "itoa_w", NULL);
	RegisterCommand(1, 10, 17, "itoa", NULL);
	RegisterCommand(1, 10, 18, "atoi", NULL);
	RegisterCommand(1, 10, 19, "digits", NULL);
	RegisterCommand(1, 10, 20, "digit", NULL);
	RegisterCommand(1, 10, 30, "strpos", NULL);
	RegisterCommand(1, 10, 31, "strlpos", NULL);
	RegisterCommand(1, 10, 100, "intout/strout", NULL);
	RegisterCommand(1, 10, 200, "strused", NULL);


	// Block manipulation functions
	RegisterCommand(1, 11, 0, "setarray", NULL);
	RegisterCommand(1, 11, 1, "setrng", NULL);
	RegisterCommand(1, 11, 2, "cpyrng", NULL);
	RegisterCommand(1, 11, 3, "setarray_stepped", NULL);
	RegisterCommand(1, 11, 4, "setrng_stepped", NULL);
	RegisterCommand(1, 11, 5, "??? (unknown)", NULL);
	RegisterCommand(1, 11, 6, "cpyvars", NULL);

	RegisterCommand(1, 11, 100, "sum", NULL);
	RegisterCommand(1, 11, 101, "sums", NULL);


	// Layered shaking functions
	RegisterCommand(1, 12, 0, "ShakeLayersStop", NULL);

	RegisterCommand(1, 12, 1100, "ShakeLayers_shlud", NULL);
	RegisterCommand(1, 12, 1101, "ShakeLayers_shlrl", NULL);
	RegisterCommand(1, 12, 1102, "ShakeLayers2D", NULL);
	RegisterCommand(1, 12, 1200, "ShakeLayers_shlup", NULL);
	RegisterCommand(1, 12, 1201, "ShakeLayers_shldn", NULL);
	RegisterCommand(1, 12, 1202, "ShakeLayers_shlle", NULL);
	RegisterCommand(1, 12, 1203, "ShakeLayers_shlri", NULL);
	RegisterCommand(1, 12, 1300, "ShakeLayersSpec", NULL);

	RegisterCommand(1, 12, 3100, "ShakeLayersEx_xshlud", NULL);
	RegisterCommand(1, 12, 3101, "ShakeLayersEx_xshlrl", NULL);
	RegisterCommand(1, 12, 3102, "ShakeLayers2DEx", NULL);
	RegisterCommand(1, 12, 3200, "ShakeLayersEx_xshlup", NULL);
	RegisterCommand(1, 12, 3201, "ShakeLayersEx_xshldn", NULL);
	RegisterCommand(1, 12, 3202, "ShakeLayersEx_xshlle", NULL);
	RegisterCommand(1, 12, 3203, "ShakeLayersEx_xshlri", NULL);
	RegisterCommand(1, 12, 3300, "ShakeLayersSpecEx", NULL);

	// Shaking
	RegisterCommand(1, 13, 0, "ShakeStop", NULL);

	RegisterCommand(1, 13, 1100, "ShakeScreen", NULL);
	RegisterCommand(1, 13, 1101, "ShakeScreen", NULL);
	RegisterCommand(1, 13, 1102, "ShakeScreen2D", NULL);
	RegisterCommand(1, 13, 1200, "ShakeScreen", NULL);
	RegisterCommand(1, 13, 1201, "ShakeScreen", NULL);
	RegisterCommand(1, 13, 1202, "ShakeScreen", NULL);
	RegisterCommand(1, 13, 1203, "ShakeScreen", NULL);
	RegisterCommand(1, 13, 1300, "ShakeSpec", NULL);
	RegisterCommand(1, 13, 1400, "ShakeScreen", NULL);

	RegisterCommand(1, 13, 3100, "ShakeScreenEx", NULL);
	RegisterCommand(1, 13, 3101, "ShakeScreenEx", NULL);
	RegisterCommand(1, 13, 3102, "ShakeScreen2DEx", NULL);
	RegisterCommand(1, 13, 3200, "ShakeScreenEx", NULL);
	RegisterCommand(1, 13, 3201, "ShakeScreenEx", NULL);
	RegisterCommand(1, 13, 3202, "ShakeScreenEx", NULL);
	RegisterCommand(1, 13, 3203, "ShakeScreenEx", NULL);
	RegisterCommand(1, 13, 3300, "ShakeSpecEx", NULL);
	RegisterCommand(1, 13, 3400, "ShakeScreenEx", NULL);

	// Music
	RegisterCommand(1, 20, 0, "bgmLoop", (CmdImpl) &Grp::impl_bgmLoop);
	RegisterCommand(1, 20, 1, "bgmPlayEx", (CmdImpl) &Grp::impl_bgmLoop); //FIXME: wait
	RegisterCommand(1, 20, 2, "bgmPlay", (CmdImpl) &Grp::impl_bgmLoop);
	RegisterCommand(1, 20, 3, "bgmWait", NULL);
	RegisterCommand(1, 20, 4, "bgmPlaying", NULL);
	RegisterCommand(1, 20, 5, "bgmStop", (CmdImpl) &Grp::impl_bgmStop);
	RegisterCommand(1, 20, 6, "bgmStop2", NULL);
	RegisterCommand(1, 20, 7, "bgmStatus", NULL);
	RegisterCommand(1, 20, 8, "bgmRewind", NULL);
	RegisterCommand(1, 20, 9, "bgmStop3", NULL);
	RegisterCommand(1, 20, 10, "bgmStop4", NULL);
	RegisterCommand(1, 20, 11, "bgmVolume", NULL);
	RegisterCommand(1, 20, 12, "bgmSetVolume", NULL);
	RegisterCommand(1, 20, 13, "bgmUnMute", NULL);
	RegisterCommand(1, 20, 14, "bgmMute", NULL);
	RegisterCommand(1, 20, 105, "bgmFadeOut", (CmdImpl) &Grp::impl_bgmStop);
	RegisterCommand(1, 20, 106, "bgmFadeOut2", NULL);
	RegisterCommand(1, 20, 107, "bgmStatus2", NULL);
	RegisterCommand(1, 20, 200, "bgmTimer", NULL);

	// Sound effects
	RegisterCommand(1, 21, 0, "wavPlay", (CmdImpl) &Grp::impl_playWav);
	RegisterCommand(1, 21, 1, "wavPlayEx", (CmdImpl) &Grp::impl_playWav);
	RegisterCommand(1, 21, 2, "wavLoop", (CmdImpl) &Grp::impl_playWav);
	RegisterCommand(1, 21, 3, "wavWait", NULL);
	RegisterCommand(1, 21, 4, "wavPlaying", NULL);
	RegisterCommand(1, 21, 5, "wavStop", (CmdImpl) &Grp::impl_stopWav);
	RegisterCommand(1, 21, 7, "wavPlaying2", NULL);
	RegisterCommand(1, 21, 8, "wavRewind", NULL);
	RegisterCommand(1, 21, 9, "wavStop3", (CmdImpl) &Grp::impl_stopWav);
	RegisterCommand(1, 21, 10, "wavStop4", (CmdImpl) &Grp::impl_stopWav);
	RegisterCommand(1, 21, 11, "wavVolume", NULL);
	RegisterCommand(1, 21, 12, "wavSetVolume", NULL);
	RegisterCommand(1, 21, 13, "wavUnMute", NULL);
	RegisterCommand(1, 21, 14, "wavMute", NULL);
	RegisterCommand(1, 21, 20, "wavStopAll", (CmdImpl) &Grp::impl_stopWav);
	RegisterCommand(1, 21, 105, "wavFadeout", (CmdImpl) &Grp::impl_stopWav);
	RegisterCommand(1, 21, 106, "wavFadeOut2", NULL);

	RegisterCommand(1, 22, 0, "sePlay", (CmdImpl) &Grp::impl_playSE);

	// Voices
	RegisterCommand(1, 23, 0, "koePlay", (CmdImpl) &Grp::impl_koePlay);
	RegisterCommand(1, 23, 1, "koePlayEx", (CmdImpl) &Grp::impl_koePlay); //FIXME
	RegisterCommand(1, 23, 3, "koeWait", NULL);
	RegisterCommand(1, 23, 4, "koePlaying", NULL);
	RegisterCommand(1, 23, 5, "koeStop", NULL);
	RegisterCommand(1, 23, 6, "koeWaitC", NULL);
	RegisterCommand(1, 23, 7, "koePlayExC", (CmdImpl) &Grp::impl_koePlay); //FIXME
	RegisterCommand(1, 23, 8, "koeDoPlay", (CmdImpl) &Grp::impl_koePlay); //FIXME
	RegisterCommand(1, 23, 9, "koeDoPlayEx", (CmdImpl) &Grp::impl_koePlay); //FIXME
	RegisterCommand(1, 23, 10, "koeDoPlayExC", (CmdImpl) &Grp::impl_koePlay); //FIXME
	RegisterCommand(1, 23, 11, "koeVolume", NULL);
	RegisterCommand(1, 23, 12, "koeSetVolume", NULL);
	RegisterCommand(1, 23, 13, "koeUnMute", NULL);
	RegisterCommand(1, 23, 14, "koeMute", NULL);

	// Videos
	RegisterCommand(1, 26, 0, "movPlay", NULL);
	RegisterCommand(1, 26, 1, "movPlayEx", (CmdImpl) &Grp::impl_movPlay);
	RegisterCommand(1, 26, 2, "movLoop", NULL);
	RegisterCommand(1, 26, 3, "movWait", NULL);
	RegisterCommand(1, 26, 4, "movPlaying", NULL);
	RegisterCommand(1, 26, 5, "movStop", NULL);
	RegisterCommand(1, 26, 20, "movPlayExC", (CmdImpl) &Grp::impl_movPlay);

	// Graphic stack
	RegisterCommand(1, 30, 0, "stackClear", (CmdImpl) &Grp::impl_stackClear);
	RegisterCommand(1, 30, 1, "stackNop", NULL);
	RegisterCommand(1, 30, 2, "stackPop", NULL);
	RegisterCommand(1, 30, 3, "stackSize", NULL);
	RegisterCommand(1, 30, 4, "stackTrunc", NULL);

	// Screen settings
	RegisterCommand(1, 30, 20, "DrawAuto", NULL);
	RegisterCommand(1, 30, 21, "DrawSemiAuto", NULL);
	RegisterCommand(1, 30, 22, "DrawManual", NULL);

	RegisterCommand(1, 30, 30, "ModeToScreenSize", NULL);
	RegisterCommand(1, 30, 31, "GetDCPixel", NULL);

	RegisterCommand(1, 30, 40, "??? (Princess Bride)", NULL);

	RegisterCommand(1, 31, 0, "refresh", (CmdImpl) &Grp::impl_refresh);

	// Graphics
	RegisterCommand(1, 33, 15, "allocDC", NULL);
	RegisterCommand(1, 33, 16, "freeDC", NULL);
	RegisterCommand(1, 33, 20, "grpLoadMask", NULL);
	RegisterCommand(1, 33, 30, "grpTextout", NULL);
	RegisterCommand(1, 33, 31, "wipe", NULL);
	RegisterCommand(1, 33, 32, "shake", (CmdImpl) &Grp::impl_shake);
	RegisterCommand(1, 33, 50, "grpLoad", NULL);
	RegisterCommand(1, 33, 51, "grpMaskLoad", NULL);
	RegisterCommand(1, 33, 70, "grpBuffer", (CmdImpl) &Grp::impl_grpBuffer);
	RegisterCommand(1, 33, 71, "grpMaskBuffer", NULL);
	RegisterCommand(1, 33, 72, "grpDisplay", NULL);
	RegisterCommand(1, 33, 73, "grpOpenBG", (CmdImpl) &Grp::impl_grpOpen);
	RegisterCommand(1, 33, 74, "grpMaskOpen", NULL);
	RegisterCommand(1, 33, 75, "grpMulti", (CmdImpl) &Grp::impl_grpMulti); //FIXME: or not...
	RegisterCommand(1, 33, 76, "grpOpen", (CmdImpl) &Grp::impl_grpOpen);
	RegisterCommand(1, 33, 77, "grpMulti", NULL);
	RegisterCommand(1, 33, 100, "grpCopy", (CmdImpl) &Grp::impl_grpCopy);
	RegisterCommand(1, 33, 101, "grpMaskCopy", NULL);
	RegisterCommand(1, 33, 102, "grpMaskBlend", NULL);
	RegisterCommand(1, 33, 120, "grpCopyWithMask", NULL);
	RegisterCommand(1, 33, 121, "grpMaskCopyWithMask", NULL);
	RegisterCommand(1, 33, 140, "grpCopyInvMask", NULL);
	RegisterCommand(1, 33, 141, "grpMaskCopyInvMask", NULL);
	RegisterCommand(1, 33, 160, "grpRotate", NULL);
	RegisterCommand(1, 33, 161, "grpMaskRotate", NULL);
	RegisterCommand(1, 33, 162, "grpRotateAdd", NULL);
	RegisterCommand(1, 33, 163, "grpMaskRotateAdd", NULL);
	RegisterCommand(1, 33, 164, "grpRotateSub", NULL);
	RegisterCommand(1, 33, 165, "grpMaskRotateSub", NULL);
	RegisterCommand(1, 33, 200, "grpOutline", NULL);
	RegisterCommand(1, 33, 201, "grpFill", NULL);
	RegisterCommand(1, 33, 300, "grpInvert", NULL);
	RegisterCommand(1, 33, 301, "grpMono", NULL);
	RegisterCommand(1, 33, 302, "grpColour", NULL);
	RegisterCommand(1, 33, 303, "grpLight", NULL);
	RegisterCommand(1, 33, 400, "grpSwap", NULL);
	RegisterCommand(1, 33, 401, "grpStretchBlt", NULL);
	RegisterCommand(1, 33, 402, "grpZoom", NULL); // (258, 208, 401, 315, 0, 0, 639, 479, 1, 0, 0, 639, 479, 1750) XXX
	RegisterCommand(1, 33, 403, "grpFade", NULL);
	RegisterCommand(1, 33, 404, "grpFlash", NULL);
	RegisterCommand(1, 33, 406, "grpPan", (CmdImpl) &Grp::impl_grpPan);
	RegisterCommand(1, 33, 407, "grpShift", NULL);
	RegisterCommand(1, 33, 408, "grpSlide", NULL);
	RegisterCommand(1, 33, 409, "grpMaskStretchBlt", NULL);
	RegisterCommand(1, 33, 410, "grpNumber", NULL);
	RegisterCommand(1, 33, 411, "grpMaskNumber", NULL);
	RegisterCommand(1, 33, 500, "grpCMaskCopy", NULL);
	RegisterCommand(1, 33, 501, "grpAnd", NULL);
	RegisterCommand(1, 33, 502, "grpOr", NULL);
	RegisterCommand(1, 33, 600, "grpAdd", NULL);
	RegisterCommand(1, 33, 601, "grpMaskAdd", NULL);
	RegisterCommand(1, 33, 620, "grpAddWithMask", NULL);
	RegisterCommand(1, 33, 621, "grpMaskAddWithMask", NULL);
	RegisterCommand(1, 33, 640, "grpAddInvMask", NULL);
	RegisterCommand(1, 33, 641, "grpMaskAddInvMask", NULL);
	RegisterCommand(1, 33, 700, "grpSub", NULL);
	RegisterCommand(1, 33, 701, "grpMaskSub", NULL);
	RegisterCommand(1, 33, 720, "grpSubWithMask", NULL);
	RegisterCommand(1, 33, 721, "grpMaskSubWithMask", NULL);
	RegisterCommand(1, 33, 740, "grpSubInvMask", NULL);
	RegisterCommand(1, 33, 741, "grpMaskSubInvMask", NULL);
	RegisterCommand(1, 33, 1050, "recLoad", NULL);
	RegisterCommand(1, 33, 1051, "recMaskLoad", NULL);
	RegisterCommand(1, 33, 1052, "recDisplay", NULL);
	RegisterCommand(1, 33, 1053, "recOpenBg", (CmdImpl) &Grp::impl_grpOpen);
	RegisterCommand(1, 33, 1054, "recMaskOpen", NULL);
	RegisterCommand(1, 33, 1056, "recOpen", NULL);
	RegisterCommand(1, 33, 1055, "recMulti", NULL);
	RegisterCommand(1, 33, 1057, "recMulti", NULL);
	RegisterCommand(1, 33, 1100, "recCopy", (CmdImpl) &Grp::impl_recCopy);
	RegisterCommand(1, 33, 1101, "recMaskCopy", (CmdImpl) &Grp::impl_recCopy); //TODO: use source's alpha
	RegisterCommand(1, 33, 1102, "recMaskBlend", NULL);
	RegisterCommand(1, 33, 1120, "recCopyWithMask", NULL);
	RegisterCommand(1, 33, 1121, "recMaskCopyWithMask", NULL);
	RegisterCommand(1, 33, 1140, "recCopyInvMask", NULL);
	RegisterCommand(1, 33, 1141, "recMaskCopyInvMask", NULL);
	RegisterCommand(1, 33, 1160, "recRotate", NULL);
	RegisterCommand(1, 33, 1161, "recMaskRotate", NULL);
	RegisterCommand(1, 33, 1162, "recRotateAdd", NULL);
	RegisterCommand(1, 33, 1163, "recMaskRotateAdd", NULL);
	RegisterCommand(1, 33, 1164, "recRotateSub", NULL);
	RegisterCommand(1, 33, 1165, "recMaskRotateSub", NULL);
	RegisterCommand(1, 33, 1200, "recOutline", NULL);
	RegisterCommand(1, 33, 1201, "recFill", (CmdImpl) &Grp::impl_recFill);
	RegisterCommand(1, 33, 1300, "recInvert", NULL);
	RegisterCommand(1, 33, 1301, "recMono", NULL);
	RegisterCommand(1, 33, 1302, "recColour", NULL);
	RegisterCommand(1, 33, 1303, "recLight", NULL);
	RegisterCommand(1, 33, 1400, "recSwap", NULL);
	RegisterCommand(1, 33, 1401, "recStretchBlt", (CmdImpl) &Grp::impl_recCopy);
	RegisterCommand(1, 33, 1402, "recZoom", NULL);
	RegisterCommand(1, 33, 1403, "recFade", NULL);
	RegisterCommand(1, 33, 1404, "recFlash", NULL);
	RegisterCommand(1, 33, 1406, "recPan", NULL);
	RegisterCommand(1, 33, 1407, "recShift", NULL);
	RegisterCommand(1, 33, 1408, "recSlide", NULL);
	RegisterCommand(1, 33, 1409, "recMaskStretchBlt", NULL);
	RegisterCommand(1, 33, 1500, "recCMaskCopy", NULL);
	RegisterCommand(1, 33, 1501, "recAnd", NULL);
	RegisterCommand(1, 33, 1502, "recOr", NULL);
	RegisterCommand(1, 33, 1600, "recAdd", (CmdImpl) &Grp::impl_recAdd);
	RegisterCommand(1, 33, 1601, "recMaskAdd", NULL);
	RegisterCommand(1, 33, 1620, "recAddWithMask", NULL);
	RegisterCommand(1, 33, 1621, "recMaskAddWithMask", NULL);
	RegisterCommand(1, 33, 1640, "recAddInvMask", NULL);
	RegisterCommand(1, 33, 1641, "recMaskAddInvMask", NULL);
	RegisterCommand(1, 33, 1700, "recSub", NULL);
	RegisterCommand(1, 33, 1701, "recMaskSub", NULL);
	RegisterCommand(1, 33, 1720, "recSubWithMask", NULL);
	RegisterCommand(1, 33, 1721, "recMaskSubWithMask", NULL);
	RegisterCommand(1, 33, 1740, "recSubInvMask", NULL);
	RegisterCommand(1, 33, 1741, "recMaskSubInvMask", NULL);

	// SerialPDT
	RegisterCommand(1, 34, 2100, "snmPlay", (CmdImpl) &Grp::impl_snmPlay);
	RegisterCommand(1, 34, 2101, "snmPlayEx", (CmdImpl) &Grp::impl_snmPlay);
	RegisterCommand(1, 34, 2102, "snmLoop", NULL);
	RegisterCommand(1, 34, 2103, "snmPlayCmp", NULL);
	RegisterCommand(1, 34, 2104, "snmPlayCmpEx", NULL);
	RegisterCommand(1, 34, 2105, "snmLoopCmp", NULL);
	RegisterCommand(1, 34, 2106, "snmPlayNc", NULL);
	RegisterCommand(1, 34, 2107, "snmPlayNcEx", NULL);
	RegisterCommand(1, 34, 2108, "snmLoopNc", NULL);
	RegisterCommand(1, 34, 2109, "??? (undocumented)", NULL);
	RegisterCommand(1, 34, 2110, "snmStretch", NULL);
	RegisterCommand(1, 34, 2111, "snmStretchEx", NULL);
	RegisterCommand(1, 34, 2112, "snmStretchLoop", NULL);
	RegisterCommand(1, 34, 2113, "snmStretchCmp", NULL);
	RegisterCommand(1, 34, 2114, "snmStretchCmpEx", NULL);
	RegisterCommand(1, 34, 2115, "snmStretchLoopCmp", NULL);
	RegisterCommand(1, 34, 2116, "snmStretchNc", NULL);
	RegisterCommand(1, 34, 2117, "snmStretchNcEx", NULL);
	RegisterCommand(1, 34, 2118, "snmStretchLoopNc", NULL);
	RegisterCommand(1, 34, 2119, "??? (undocumented)", NULL);
	RegisterCommand(1, 34, 2120, "snmScroll", NULL);
	RegisterCommand(1, 34, 2121, "snmScrollEx", NULL);
	RegisterCommand(1, 34, 2122, "snmScrollLoop", NULL);

	RegisterCommand(1, 34, 3100, "snmBgPlay", (CmdImpl) &Grp::impl_snmPlay);
	RegisterCommand(1, 34, 3101, "snmBgPlayEx", NULL);
	RegisterCommand(1, 34, 3102, "snmBgLoop", NULL);
	RegisterCommand(1, 34, 3103, "snmBgPlayCmp", NULL);
	RegisterCommand(1, 34, 3104, "snmBgPlayCmpEx", NULL);
	RegisterCommand(1, 34, 3105, "snmBgLoopCmp", NULL);
	RegisterCommand(1, 34, 3106, "snmBgPlayNc", NULL);
	RegisterCommand(1, 34, 3107, "snmBgPlayNcEx", NULL);
	RegisterCommand(1, 34, 3108, "snmBgLoopNc", NULL);
	RegisterCommand(1, 34, 3109, "??? (undocumented)", NULL);
	RegisterCommand(1, 34, 3110, "snmBgStretch", NULL);
	RegisterCommand(1, 34, 3111, "snmBgStretchEx", NULL);
	RegisterCommand(1, 34, 3112, "snmBgStretchLoop", NULL);
	RegisterCommand(1, 34, 3113, "snmBgStretchCmp", NULL);
	RegisterCommand(1, 34, 3114, "snmBgStretchCmpEx", NULL);
	RegisterCommand(1, 34, 3115, "snmBgStretchLoopCmp", NULL);
	RegisterCommand(1, 34, 3116, "snmBgStretchNc", NULL);
	RegisterCommand(1, 34, 3117, "snmBgStretchNcEx", NULL);
	RegisterCommand(1, 34, 3118, "snmBgStretchLoopNc", NULL);
	RegisterCommand(1, 34, 3119, "??? (undocumented)", NULL);
	RegisterCommand(1, 34, 3120, "snmBgScroll", (CmdImpl) &Grp::impl_snmBgScroll);
	RegisterCommand(1, 34, 3121, "snmBgScrollEx", NULL);
	RegisterCommand(1, 34, 3122, "snmBgScrollLoop", NULL);

	// Obj
	RegisterCommand(1, 60, 2, "objCopyFgToBg", NULL);

	RegisterCommand(1, 61, 2, "objCopy", NULL);
	RegisterCommand(1, 61, 3, "objCopyToBg", NULL);
	RegisterCommand(1, 61, 4, "objWipeCopyOn", NULL);
	RegisterCommand(1, 61, 5, "objWipeCopyOff", NULL);
	RegisterCommand(1, 61, 10, "objClear", (CmdImpl) &Grp::impl_objClear);
	RegisterCommand(1, 61, 11, "objDelete", (CmdImpl) &Grp::impl_objClear);
	RegisterCommand(1, 61, 14, "objSwap ??? (undocumented)", NULL);

	// ObjBg
	RegisterCommand(1, 62, 2, "objBgCopyToFg", NULL);
	RegisterCommand(1, 62, 3, "objBgCopy", NULL);
	RegisterCommand(1, 62, 4, "objBgWipeCopyOn", NULL);
	RegisterCommand(1, 62, 5, "objBgWipeCopyOff", NULL);
	RegisterCommand(1, 62, 10, "objBgClear", (CmdImpl) &Grp::impl_objClear);
	RegisterCommand(1, 62, 11, "objBgDelete", (CmdImpl) &Grp::impl_objClear);
	RegisterCommand(1, 62, 14, "objSwap ??? (undocumented)", NULL);

	// Obj
	RegisterCommand(1, 71, 1000, "objOfFile", (CmdImpl) &Grp::impl_createObj);
	RegisterCommand(1, 71, 1001, "objOfFile2", (CmdImpl) &Grp::impl_createObj);
	RegisterCommand(1, 71, 1002, "objOfFile3", (CmdImpl) &Grp::impl_createObj);
	RegisterCommand(1, 71, 1003, "objOfFileGan/Anm", (CmdImpl) &Grp::impl_createObj);
	RegisterCommand(1, 71, 1100, "objOfArea", (CmdImpl) &Grp::impl_createObj);
	RegisterCommand(1, 71, 1101, "objOfRect", NULL);
	RegisterCommand(1, 71, 1200, "objOfText", (CmdImpl) &Grp::impl_createObj);
	RegisterCommand(1, 71, 1300, "objDriftOfFile", NULL);
	RegisterCommand(1, 71, 1400, "objOfDigits", (CmdImpl) &Grp::impl_createObj);

	RegisterCommand(2, 71, 1000, "subObjOfFile", (CmdImpl) &Grp::impl_createObj);
	RegisterCommand(2, 71, 1001, "subObjOfFile2", (CmdImpl) &Grp::impl_createObj);
	RegisterCommand(2, 71, 1002, "subObjOfFile3", (CmdImpl) &Grp::impl_createObj);
	RegisterCommand(2, 71, 1003, "subObjOfGan", (CmdImpl) &Grp::impl_createObj);
	RegisterCommand(2, 71, 1100, "subObjOfArea", (CmdImpl) &Grp::impl_createObj);
	RegisterCommand(2, 71, 1101, "subObjOfRect", (CmdImpl) &Grp::impl_createObj);
	RegisterCommand(2, 71, 1200, "subObjOfText", (CmdImpl) &Grp::impl_createObj);
	RegisterCommand(2, 71, 1300, "subObjDriftOfFile", NULL);
	RegisterCommand(2, 71, 1400, "subObjOfDigits", (CmdImpl) &Grp::impl_createObj);

	// ObjBg
	//I suppose it's the same thing as createObj*, but I didn't see it in action. For now, mark it unhandled.
	RegisterCommand(1, 72, 1000, "objBgOfFile", (CmdImpl) &Grp::impl_createObj);
	RegisterCommand(1, 72, 1001, "objBgOfFile2", NULL);
	RegisterCommand(1, 72, 1002, "objBgOfFile3", NULL);
	RegisterCommand(1, 72, 1003, "objBgOfFileGan/Anm", NULL);
	RegisterCommand(1, 72, 1100, "objBgOfArea", NULL);
	RegisterCommand(1, 72, 1101, "objBgOfRect", NULL);
	RegisterCommand(1, 72, 1200, "objBgOfText", NULL);
	RegisterCommand(1, 72, 1300, "objBgDriftOfFile", NULL);
	RegisterCommand(1, 72, 1400, "objBgOfDigits", NULL);

	RegisterCommand(2, 72, 1000, "objBgOfFile", NULL);
	RegisterCommand(2, 72, 1001, "objBgOfFile2", NULL);
	RegisterCommand(2, 72, 1002, "objBgOfFile3", NULL);
	RegisterCommand(2, 72, 1003, "objBgOfFileGan/Anm", NULL);
	RegisterCommand(2, 72, 1100, "objBgOfArea", NULL);
	RegisterCommand(2, 72, 1101, "objBgOfRect", NULL);
	RegisterCommand(2, 72, 1200, "objBgOfText", NULL);
	RegisterCommand(2, 72, 1300, "objBgDriftOfFile", NULL);
	RegisterCommand(2, 72, 1400, "objBgOfDigits", NULL);

	/*RegisterCommand(1, 72, 1000, "objBgOfFile", (CmdImpl) &Grp::impl_createObj);
	RegisterCommand(1, 72, 1003, "objBgOfFileGan", (CmdImpl) &Grp::impl_createObj);
	RegisterCommand(1, 72, 1100, "objBgOfArea", (CmdImpl) &Grp::impl_createObj);
	RegisterCommand(1, 72, 1200, "objBgOfText", (CmdImpl) &Grp::impl_createObj);
	RegisterCommand(1, 72, 1300, "objBgDriftOfFile", (CmdImpl) &Grp::impl_createObj);
	RegisterCommand(1, 72, 1400, "objBgOfDigits", (CmdImpl) &Grp::impl_createObj);

	RegisterCommand(2, 72, 1000, "subObjBgOfFile", NULL);//FIXME
	RegisterCommand(2, 72, 1003, "subObjBgOfGan", NULL);//FIXME
	RegisterCommand(2, 72, 1100, "subObjBgOfArea", NULL);//FIXME
	RegisterCommand(2, 72, 1200, "subObjBgOfText", NULL);//FIXME
	RegisterCommand(2, 72, 1300, "subObjBgDriftOfFile", NULL);//FIXME
	RegisterCommand(2, 72, 1400, "subObjBgOfDigits", NULL);//FIXME;*/

	// Gan
	RegisterCommand(1, 73, 0, "ganStop?", NULL); //That's what xclannad says, but I'm not sure...
	RegisterCommand(1, 73, 1000, "objStop (gan)", (CmdImpl) &Grp::impl_gan); //That's what rldev says
	RegisterCommand(1, 73, 3, "ganIsPlaying", (CmdImpl) &Grp::impl_gan);

	RegisterCommand(1, 73, 1001, "ganLoop", (CmdImpl) &Grp::impl_gan);
	RegisterCommand(1, 73, 1002, "ganRepeat", NULL);
	RegisterCommand(1, 73, 1003, "ganPlay", (CmdImpl) &Grp::impl_gan);
	RegisterCommand(1, 73, 1004, "ganOneShotRepeat", NULL);
	RegisterCommand(1, 73, 1005, "ganPlayOnce", (CmdImpl) &Grp::impl_gan);
	RegisterCommand(1, 73, 1006, "ganPlayEx", NULL);
	RegisterCommand(1, 73, 1007, "ganPlayOnceEx", NULL);
	RegisterCommand(1, 73, 1008, "ganPlayBlink", NULL);
	RegisterCommand(1, 73, 1009, "ganPlayChew", NULL);

	RegisterCommand(1, 73, 2001, "objLoop (gan)", (CmdImpl) &Grp::impl_gan);
	RegisterCommand(1, 73, 2002, "objRepeat (gan)", NULL);
	RegisterCommand(1, 73, 2003, "objPlay (gan)", (CmdImpl) &Grp::impl_gan);
	RegisterCommand(1, 73, 2004, "objOneShotRepeat (gan)", NULL);
	RegisterCommand(1, 73, 2005, "objPlayOnce (gan)", (CmdImpl) &Grp::impl_gan);
	RegisterCommand(1, 73, 2006, "objPlayEx (gan)", NULL);
	RegisterCommand(1, 73, 2007, "objPlayOnceEx (gan)", NULL);
	RegisterCommand(1, 73, 2008, "objPlayBlink (gan)", NULL);
	RegisterCommand(1, 73, 2009, "objPlayChew (gan)", NULL);

	RegisterCommand(1, 73, 3001, "ganLoop2", (CmdImpl) &Grp::impl_gan);
	RegisterCommand(1, 73, 3002, "ganRepeat2", NULL);
	RegisterCommand(1, 73, 3003, "ganPlay2", (CmdImpl) &Grp::impl_gan);
	RegisterCommand(1, 73, 3004, "ganOneShotRepeat2", NULL);
	RegisterCommand(1, 73, 3005, "ganPlayOnce2", (CmdImpl) &Grp::impl_gan);
	RegisterCommand(1, 73, 3006, "ganPlayEx2", NULL);
	RegisterCommand(1, 73, 3007, "ganPlayOnceEx2", NULL);
	RegisterCommand(1, 73, 3008, "ganPlayBlink2", NULL);
	RegisterCommand(1, 73, 3009, "ganPlayChew2", NULL);

	// FIXME
	RegisterCommand(2, 73, 0, "ganSubStop?", NULL);
	RegisterCommand(2, 73, 1000, "ganSubStop", NULL);
	RegisterCommand(2, 73, 3, "ganSubIsPlaying", NULL);
	RegisterCommand(2, 73, 2003, "objSubPlay", NULL);
	RegisterCommand(2, 73, 1001, "ganSubLoop", NULL);
	RegisterCommand(2, 73, 1003, "ganSubPlay", NULL);
	RegisterCommand(2, 73, 1005, "ganSubPlayOnce", NULL);
	RegisterCommand(2, 73, 3001, "ganSubLoop2", (CmdImpl) &Grp::impl_gan);
	RegisterCommand(2, 73, 3003, "ganSubPlay2", NULL);
	RegisterCommand(2, 73, 3005, "ganSubPlayOnce2", NULL);

	// GanBg
	RegisterCommand(1, 74, 1000, "objBgStop (gan)", (CmdImpl) &Grp::impl_gan);

	RegisterCommand(1, 74, 1001, "ganBgLoop", (CmdImpl) &Grp::impl_gan);
	RegisterCommand(1, 74, 1003, "ganBgPlay", (CmdImpl) &Grp::impl_gan);
	RegisterCommand(1, 74, 1005, "ganBgPlayOnce", (CmdImpl) &Grp::impl_gan);
	RegisterCommand(1, 74, 1006, "ganBgPlayEx", NULL);
	RegisterCommand(1, 74, 1007, "ganBgPlayOnceEx", NULL);
	RegisterCommand(1, 74, 1008, "ganBgPlayBlink", NULL);

	RegisterCommand(1, 74, 2001, "objBgLoop (gan)", (CmdImpl) &Grp::impl_gan);
	RegisterCommand(1, 74, 2003, "objBgPlay (gan)", (CmdImpl) &Grp::impl_gan);
	RegisterCommand(1, 74, 2005, "objBgPlayOnce (gan)", (CmdImpl) &Grp::impl_gan);
	RegisterCommand(1, 74, 2006, "objBgPlayEx (gan)", NULL);
	RegisterCommand(1, 74, 2007, "objBgPlayOnceEx (gan)", NULL);
	RegisterCommand(1, 74, 2008, "objBgPlayBlink (gan)", NULL);

	RegisterCommand(1, 74, 3001, "ganBgLoop2", (CmdImpl) &Grp::impl_gan);
	RegisterCommand(1, 74, 3003, "ganBgPlay2", (CmdImpl) &Grp::impl_gan);
	RegisterCommand(1, 74, 3005, "ganBgPlayOnce2", (CmdImpl) &Grp::impl_gan);
	RegisterCommand(1, 74, 3006, "ganBgPlayEx2", NULL);
	RegisterCommand(1, 74, 3007, "ganBgPlayOnceEx2", NULL);
	RegisterCommand(1, 74, 3008, "ganBgPlayBlink2", NULL);

	// Obj
	RegisterCommand(1, 81, 1000, "objMove", (CmdImpl) &Grp::impl_objSetPos);
	RegisterCommand(1, 82, 1000, "objBgMove", (CmdImpl) &Grp::impl_objSetPos);
	RegisterCommand(1, 81, 1001, "objLeft", (CmdImpl) &Grp::impl_objSetPos);
	RegisterCommand(1, 82, 1001, "objBgLeft", (CmdImpl) &Grp::impl_objSetPos);
	RegisterCommand(1, 81, 1002, "objTop", (CmdImpl) &Grp::impl_objSetPos);
	RegisterCommand(1, 82, 1002, "objBgTop", (CmdImpl) &Grp::impl_objSetPos);
	RegisterCommand(1, 81, 1003, "objAlpha", (CmdImpl) &Grp::impl_objAlpha);
	RegisterCommand(1, 82, 1003, "objBgAlpha", (CmdImpl) &Grp::impl_objAlpha);
	RegisterCommand(1, 81, 1004, "objShow", (CmdImpl) &Grp::impl_objShow);
	RegisterCommand(1, 82, 1004, "objBgShow", (CmdImpl) &Grp::impl_objShow);
	RegisterCommand(1, 81, 1005, "objDispArea", NULL);
	RegisterCommand(1, 82, 1005, "objBgDispArea", NULL);
	RegisterCommand(1, 81, 1006, "objAdjust", (CmdImpl) &Grp::impl_objSetPos);
	RegisterCommand(1, 82, 1006, "objBgAdjust", NULL); //FIXME: (CmdImpl) &Grp::impl_objSetPos);
	RegisterCommand(1, 81, 1007, "objAdjustX", NULL);
	RegisterCommand(1, 82, 1007, "objBgAdjustX", NULL);
	RegisterCommand(1, 81, 1008, "objAdjustY", NULL);
	RegisterCommand(1, 82, 1008, "objBgAdjustY", NULL);
	RegisterCommand(1, 81, 1009, "objMono", NULL);
	RegisterCommand(1, 82, 1009, "objBgMono", NULL);
	RegisterCommand(1, 81, 1010, "objInvert", NULL);
	RegisterCommand(1, 82, 1010, "objBgInvert", NULL);
	RegisterCommand(1, 81, 1011, "objLight", NULL);
	RegisterCommand(1, 82, 1011, "objBgLight", NULL);
	RegisterCommand(1, 81, 1012, "objTint", NULL);
	RegisterCommand(1, 82, 1012, "objBgTint", NULL);
	RegisterCommand(1, 81, 1013, "objTintR", NULL);
	RegisterCommand(1, 82, 1013, "objBgTintR", NULL);
	RegisterCommand(1, 81, 1014, "objTintG", NULL);
	RegisterCommand(1, 82, 1014, "objBgTintG", NULL);
	RegisterCommand(1, 81, 1015, "objTintB", NULL);
	RegisterCommand(1, 82, 1015, "objBgTintB", NULL);
	RegisterCommand(1, 81, 1016, "objColour", NULL); //FIXME: (CmdImpl) &Grp::impl_objColour);
	RegisterCommand(1, 82, 1016, "objBgColour", NULL); //FIXME: (CmdImpl) &Grp::impl_objColour);
	RegisterCommand(1, 81, 1017, "objColR", NULL);
	RegisterCommand(1, 82, 1017, "objBgColR", NULL);
	RegisterCommand(1, 81, 1018, "objColG", NULL);
	RegisterCommand(1, 82, 1018, "objBgColG", NULL);
	RegisterCommand(1, 81, 1019, "objColB", NULL);
	RegisterCommand(1, 82, 1019, "objBgColB", NULL);
	RegisterCommand(1, 81, 1020, "objColLevel", NULL);
	RegisterCommand(1, 82, 1020, "objBgColLevel", NULL);
	RegisterCommand(1, 81, 1021, "objComposite", (CmdImpl) &Grp::impl_objComposite); //FIXME: May be broken
	RegisterCommand(1, 82, 1021, "objBgComposite", (CmdImpl) &Grp::impl_objComposite);
	RegisterCommand(1, 81, 1024, "objSetText", (CmdImpl) &Grp::impl_objSetText);
	RegisterCommand(1, 82, 1024, "objBgSetText", (CmdImpl) &Grp::impl_objSetText);
	RegisterCommand(1, 81, 1025, "objTextOpts", (CmdImpl) &Grp::impl_objTextOpts); //FIXME: Incomplete
	RegisterCommand(1, 82, 1025, "objBgTextOpts", (CmdImpl) &Grp::impl_objTextOpts);
	RegisterCommand(1, 81, 1026, "objLayer", NULL);
	RegisterCommand(1, 82, 1026, "objBgLayer", NULL);
	RegisterCommand(1, 81, 1027, "objDepth", NULL);
	RegisterCommand(1, 82, 1027, "objBgDepth", NULL);
	RegisterCommand(1, 81, 1028, "objScrollRate", NULL);
	RegisterCommand(1, 82, 1028, "objBgScrollRate", NULL);
	RegisterCommand(1, 81, 1029, "objScrollRateX", NULL);
	RegisterCommand(1, 82, 1029, "objBgScrollRateX", NULL);
	RegisterCommand(1, 81, 1030, "objScrollRateY", NULL);
	RegisterCommand(1, 82, 1030, "objBgScrollRateY", NULL);
	RegisterCommand(1, 81, 1031, "objDriftOpts", NULL); //(CmdImpl) &Grp::impl_objDriftOpts);
	RegisterCommand(1, 82, 1031, "objBgDriftOpts", NULL);
	RegisterCommand(1, 81, 1032, "objOrder", (CmdImpl) &Grp::impl_objOrder);
	RegisterCommand(1, 82, 1032, "objBgOrder", (CmdImpl) &Grp::impl_objOrder);
	RegisterCommand(1, 81, 1033, "objQuarterView", NULL);
	RegisterCommand(1, 82, 1033, "objBgQuarterView", NULL);
	RegisterCommand(1, 81, 1034, "objDispRect", (CmdImpl) &Grp::impl_objDispArea);
	RegisterCommand(1, 82, 1034, "objBgDispRect", (CmdImpl) &Grp::impl_objDispArea);
	RegisterCommand(1, 81, 1035, "objDispCorner", NULL);
	RegisterCommand(1, 82, 1035, "objBgDispCorner", NULL);
	RegisterCommand(1, 81, 1036, "objAdjustVert", NULL);
	RegisterCommand(1, 82, 1036, "objBgAdjustVert", NULL);
	RegisterCommand(1, 81, 1037, "objSetDigits", (CmdImpl) &Grp::impl_objSetDigits);
	RegisterCommand(1, 82, 1037, "objBgSetDigits", (CmdImpl) &Grp::impl_objSetDigits);
	RegisterCommand(1, 81, 1038, "objNumOpts", (CmdImpl) &Grp::impl_objNumOpts);
	RegisterCommand(1, 82, 1038, "objBgNumOpts", (CmdImpl) &Grp::impl_objNumOpts);
	RegisterCommand(1, 81, 1039, "objPattNo", (CmdImpl) &Grp::impl_objPattNo);
	RegisterCommand(1, 82, 1039, "objBgPattNo", (CmdImpl) &Grp::impl_objPattNo);
	RegisterCommand(1, 81, 1041, "objAdjustAll", NULL);
	RegisterCommand(1, 82, 1041, "objBgAdjustAll", NULL);
	RegisterCommand(1, 81, 1042, "objAdjustAllX", NULL);
	RegisterCommand(1, 82, 1042, "objBgAdjustAllX", NULL);
	RegisterCommand(1, 81, 1043, "objAdjustAllY", NULL);
	RegisterCommand(1, 82, 1043, "objBgAdjustAllY", NULL);
	RegisterCommand(1, 81, 1046, "objScale", (CmdImpl) &Grp::impl_objScale);
	RegisterCommand(1, 82, 1046, "objBgScale", (CmdImpl) &Grp::impl_objScale);
	RegisterCommand(1, 81, 1047, "objWidth", (CmdImpl) &Grp::impl_objScale);
	RegisterCommand(1, 82, 1047, "objBgWidth", (CmdImpl) &Grp::impl_objScale);
	RegisterCommand(1, 81, 1048, "objHeight", (CmdImpl) &Grp::impl_objScale);
	RegisterCommand(1, 82, 1048, "objBgHeight", (CmdImpl) &Grp::impl_objScale);
	RegisterCommand(1, 81, 1049, "objRotate", (CmdImpl) &Grp::impl_objRotate);
	RegisterCommand(1, 82, 1049, "objBgRotate", (CmdImpl) &Grp::impl_objRotate);
	RegisterCommand(1, 81, 1050, "objRepOrigin", NULL);
	RegisterCommand(1, 82, 1050, "objBgRepOrigin", NULL);
	RegisterCommand(1, 81, 1051, "objRepOriginX", NULL);
	RegisterCommand(1, 82, 1051, "objBgRepOriginX", NULL);
	RegisterCommand(1, 81, 1052, "objRepOriginY", NULL);
	RegisterCommand(1, 82, 1052, "objBgRepOriginY", NULL);
	RegisterCommand(1, 81, 1053, "objOrigin", NULL);
	RegisterCommand(1, 82, 1053, "objBgOrigin", NULL);
	RegisterCommand(1, 81, 1054, "objOriginX", NULL);
	RegisterCommand(1, 82, 1054, "objBgOriginX", NULL);
	RegisterCommand(1, 81, 1055, "objOriginY", NULL);
	RegisterCommand(1, 82, 1055, "objBgOriginY", NULL);
	RegisterCommand(1, 81, 1056, "objFadeOpts", NULL);
	RegisterCommand(1, 82, 1056, "objBgFadeOpts", NULL);
	RegisterCommand(1, 81, 2006, "objAdjust2?", NULL); //FIXME: (CmdImpl) &Grp::impl_objSetPos); I don't know if it is usefull or properly implemented
	RegisterCommand(1, 82, 2006, "objBgAdjust2?", NULL); //FIXME: (CmdImpl) &Grp::impl_objSetPos); See above

	RegisterCommand(2, 81, 1000, "childObjMove", (CmdImpl) &Grp::impl_objSetPos);
	RegisterCommand(2, 82, 1000, "childObjBgMove", (CmdImpl) &Grp::impl_objSetPos);
	RegisterCommand(2, 81, 1001, "childObjLeft", NULL);
	RegisterCommand(2, 82, 1001, "childObjBgLeft", NULL);
	RegisterCommand(2, 81, 1002, "childObjTop", NULL);
	RegisterCommand(2, 82, 1002, "childObjBgTop", NULL);
	RegisterCommand(2, 81, 1003, "childObjAlpha", (CmdImpl) &Grp::impl_objAlpha);
	RegisterCommand(2, 82, 1003, "childObjBgAlpha", (CmdImpl) &Grp::impl_objAlpha);
	RegisterCommand(2, 81, 1004, "childObjShow", (CmdImpl) &Grp::impl_objShow);
	RegisterCommand(2, 82, 1004, "childObjBgShow", (CmdImpl) &Grp::impl_objShow);
	RegisterCommand(2, 81, 1005, "childObjDispArea", NULL);
	RegisterCommand(2, 82, 1005, "childObjBgDispArea", NULL);
	RegisterCommand(2, 81, 1006, "childObjAdjust", (CmdImpl) &Grp::impl_objSetPos);
	RegisterCommand(2, 82, 1006, "childObjBgAdjust", (CmdImpl) &Grp::impl_objSetPos);
	RegisterCommand(2, 81, 1007, "childObjAdjustX", NULL);
	RegisterCommand(2, 82, 1007, "childObjBgAdjustX", NULL);
	RegisterCommand(2, 81, 1008, "childObjAdjustY", NULL);
	RegisterCommand(2, 82, 1008, "childObjBgAdjustY", NULL);
	RegisterCommand(2, 81, 2006, "childObjAdjust2?", NULL);
	RegisterCommand(2, 82, 2006, "childObjBgAdjust2?", NULL);
	RegisterCommand(2, 81, 1016, "childObjColour", NULL);
	RegisterCommand(2, 82, 1016, "childObjBgColour", NULL);
	RegisterCommand(2, 81, 1017, "childObjColR", NULL);
	RegisterCommand(2, 82, 1017, "childObjBgColR", NULL);
	RegisterCommand(2, 81, 1018, "childObjColG", NULL);
	RegisterCommand(2, 82, 1018, "childObjBgColG", NULL);
	RegisterCommand(2, 81, 1019, "childObjColB", NULL);
	RegisterCommand(2, 82, 1019, "childObjBgColB", NULL);
	RegisterCommand(2, 81, 1020, "childObjColLevel", NULL);
	RegisterCommand(2, 82, 1020, "childObjBgColLevel", NULL);
	RegisterCommand(2, 81, 1021, "childObjComposite", NULL);
	RegisterCommand(2, 82, 1021, "childObjBgComposite", NULL);
	RegisterCommand(2, 81, 1024, "childObjSetText", (CmdImpl) &Grp::impl_objSetText);
	RegisterCommand(2, 82, 1024, "childObjBgSetText", (CmdImpl) &Grp::impl_objSetText);
	RegisterCommand(2, 81, 1025, "childObjTextOpts", (CmdImpl) &Grp::impl_objTextOpts);
	RegisterCommand(2, 82, 1025, "childObjBgTextOpts", (CmdImpl) &Grp::impl_objTextOpts);
	RegisterCommand(2, 81, 1032, "childObjOrder", NULL);
	RegisterCommand(2, 82, 1032, "childObjBgOrder", NULL);
	RegisterCommand(2, 81, 1034, "childObjDispRect", NULL);
	RegisterCommand(2, 82, 1034, "childObjBgDispRect", NULL);
	RegisterCommand(2, 81, 1037, "childObjSetDigits", (CmdImpl) &Grp::impl_objSetDigits);
	RegisterCommand(2, 82, 1037, "childObjBgSetDigits", (CmdImpl) &Grp::impl_objSetDigits);
	RegisterCommand(2, 81, 1038, "childObjNumOpts", (CmdImpl) &Grp::impl_objNumOpts);
	RegisterCommand(2, 82, 1038, "childObjBgNumOpts", (CmdImpl) &Grp::impl_objNumOpts);
	RegisterCommand(2, 81, 1039, "childObjPattNo", (CmdImpl) &Grp::impl_objPattNo);
	RegisterCommand(2, 82, 1039, "childObjBgPattNo", (CmdImpl) &Grp::impl_objPattNo);
	RegisterCommand(2, 81, 1046, "childObjScale", (CmdImpl) &Grp::impl_objScale);
	RegisterCommand(2, 82, 1046, "childObjBgScale", (CmdImpl) &Grp::impl_objScale);
	RegisterCommand(2, 81, 1047, "childObjWidth", NULL);
	RegisterCommand(2, 82, 1047, "childObjBgWidth", NULL);
	RegisterCommand(2, 81, 1049, "childObjRotate", NULL);
	RegisterCommand(2, 82, 1049, "childObjBgRotate", NULL);

	// Obj
	RegisterCommand(1, 84, 1000, "objGetPos", (CmdImpl) &Grp::impl_objPosDims);
	RegisterCommand(1, 84, 1100, "objGetDims", (CmdImpl) &Grp::impl_objPosDims);

	RegisterCommand(2, 84, 1000, "childObjGetPos", (CmdImpl) &Grp::impl_objPosDims);
	RegisterCommand(2, 84, 1100, "childObjGetDims", (CmdImpl) &Grp::impl_objPosDims);

	// ObjRange
	RegisterCommand(1, 90, 1000, "objRangeMove", NULL);
	RegisterCommand(1, 91, 1000, "objBgRangeMove", NULL);
	RegisterCommand(1, 90, 1001, "objRangeLeft", NULL);
	RegisterCommand(1, 91, 1001, "objBgRangeLeft", NULL);
	RegisterCommand(1, 90, 1002, "objRangeTop", NULL);
	RegisterCommand(1, 91, 1002, "objBgRangeTop", NULL);
	RegisterCommand(1, 90, 1003, "objRangeAlpha", NULL);
	RegisterCommand(1, 91, 1003, "objBgRangeAlpha", NULL);
	RegisterCommand(1, 90, 1004, "objRangeShow", NULL);
	RegisterCommand(1, 91, 1004, "objBgRangeShow", NULL);
	RegisterCommand(1, 90, 1005, "objRangeDispArea", NULL);
	RegisterCommand(1, 91, 1005, "objBgRangeDispArea", NULL);
	RegisterCommand(1, 90, 1006, "objRangeAdjust", NULL);
	RegisterCommand(1, 91, 1006, "objBgRangeAdjust", NULL);
	RegisterCommand(1, 90, 1007, "objRangeAdjustX", NULL);
	RegisterCommand(1, 91, 1007, "objBgRangeAdjustX", NULL);
	RegisterCommand(1, 90, 1008, "objRangeAdjustY", NULL);
	RegisterCommand(1, 91, 1008, "objBgRangeAdjustY", NULL);
	RegisterCommand(1, 90, 1009, "objRangeMono", NULL);
	RegisterCommand(1, 91, 1009, "objBgRangeMono", NULL);
	RegisterCommand(1, 90, 1010, "objRangeInvert", NULL);
	RegisterCommand(1, 91, 1010, "objBgRangeInvert", NULL);
	RegisterCommand(1, 90, 1011, "objRangeLight", NULL);
	RegisterCommand(1, 91, 1011, "objBgRangeLight", NULL);
	RegisterCommand(1, 90, 1012, "objRangeTint", NULL);
	RegisterCommand(1, 91, 1012, "objBgRangeTint", NULL);
	RegisterCommand(1, 90, 1013, "objRangeTintR", NULL);
	RegisterCommand(1, 91, 1013, "objBgRangeTintR", NULL);
	RegisterCommand(1, 90, 1014, "objRangeTintG", NULL);
	RegisterCommand(1, 91, 1014, "objBgRangeTintG", NULL);
	RegisterCommand(1, 90, 1015, "objRangeTintB", NULL);
	RegisterCommand(1, 91, 1015, "objBgRangeTintB", NULL);
	RegisterCommand(1, 90, 1016, "objRangeColour", NULL);
	RegisterCommand(1, 91, 1016, "objBgRangeColour", NULL);
	RegisterCommand(1, 90, 1017, "objRangeColR", NULL);
	RegisterCommand(1, 91, 1017, "objBgRangeColR", NULL);
	RegisterCommand(1, 90, 1018, "objRangeColG", NULL);
	RegisterCommand(1, 91, 1018, "objBgRangeColG", NULL);
	RegisterCommand(1, 90, 1019, "objRangeColB", NULL);
	RegisterCommand(1, 91, 1019, "objBgRangeColB", NULL);
	RegisterCommand(1, 90, 1020, "objRangeColLevel", NULL);
	RegisterCommand(1, 91, 1020, "objBgRangeColLevel", NULL);
	RegisterCommand(1, 90, 1021, "objRangeComposite", NULL);
	RegisterCommand(1, 91, 1021, "objBgRangeComposite", NULL);
	RegisterCommand(1, 90, 1024, "objRangeSetText", NULL);
	RegisterCommand(1, 91, 1024, "objBgRangeSetText", NULL);
	RegisterCommand(1, 90, 1025, "objRangeTextOpts", NULL);
	RegisterCommand(1, 91, 1025, "objBgRangeTextOpts", NULL);
	RegisterCommand(1, 90, 1026, "objRangeLayer", NULL);
	RegisterCommand(1, 91, 1026, "objBgRangeLayer", NULL);
	RegisterCommand(1, 90, 1027, "objRangeDepth", NULL);
	RegisterCommand(1, 91, 1027, "objBgRangeDepth", NULL);
	RegisterCommand(1, 90, 1028, "objRangeScrollRate", NULL);
	RegisterCommand(1, 91, 1028, "objBgRangeScrollRate", NULL);
	RegisterCommand(1, 90, 1029, "objRangeScrollRateX", NULL);
	RegisterCommand(1, 91, 1029, "objBgRangeScrollRateX", NULL);
	RegisterCommand(1, 90, 1030, "objRangeScrollRateY", NULL);
	RegisterCommand(1, 91, 1030, "objBgRangeScrollRateY", NULL);
	RegisterCommand(1, 90, 1031, "objRangeDriftOpts", NULL);
	RegisterCommand(1, 91, 1031, "objBgRangeDriftOpts", NULL);
	RegisterCommand(1, 90, 1032, "objRangeOrder", NULL);
	RegisterCommand(1, 91, 1032, "objBgRangeOrder", NULL);
	RegisterCommand(1, 90, 1033, "objRangeQuarterView", NULL);
	RegisterCommand(1, 91, 1033, "objBgRangeQuarterView", NULL);
	RegisterCommand(1, 90, 1034, "objRangeDispRect", NULL);
	RegisterCommand(1, 91, 1034, "objBgRangeDispRect", NULL);
	RegisterCommand(1, 90, 1035, "objRangeDispCorner", NULL);
	RegisterCommand(1, 91, 1035, "objBgRangeDispCorner", NULL);
	RegisterCommand(1, 90, 1036, "objRangeAdjustVert", NULL);
	RegisterCommand(1, 91, 1036, "objBgRangeAdjustVert", NULL);
	RegisterCommand(1, 90, 1037, "objRangeSetDigits", NULL);
	RegisterCommand(1, 91, 1037, "objBgRangeSetDigits", NULL);
	RegisterCommand(1, 90, 1038, "objRangeNumOpts", NULL);
	RegisterCommand(1, 91, 1038, "objBgRangeNumOpts", NULL);
	RegisterCommand(1, 90, 1039, "objRangePattNo", NULL);
	RegisterCommand(1, 91, 1039, "objBgRangePattNo", NULL);
	RegisterCommand(1, 90, 1041, "objRangeAdjustAll", NULL);
	RegisterCommand(1, 91, 1041, "objBgRangeAdjustAll", NULL);
	RegisterCommand(1, 90, 1042, "objRangeAdjustAllX", NULL);
	RegisterCommand(1, 91, 1042, "objBgRangeAdjustAllX", NULL);
	RegisterCommand(1, 90, 1043, "objRangeAdjustAllY", NULL);
	RegisterCommand(1, 91, 1043, "objBgRangeAdjustAllY", NULL);
	RegisterCommand(1, 90, 1046, "objRangeScale", NULL);
	RegisterCommand(1, 91, 1046, "objBgRangeScale", NULL);
	RegisterCommand(1, 90, 1047, "objRangeWidth", NULL);
	RegisterCommand(1, 91, 1047, "objBgRangeWidth", NULL);
	RegisterCommand(1, 90, 1048, "objRangeHeight", NULL);
	RegisterCommand(1, 91, 1048, "objBgRangeHeight", NULL);
	RegisterCommand(1, 90, 1049, "objRangeRotate", NULL);
	RegisterCommand(1, 91, 1049, "objBgRangeRotate", NULL);
	RegisterCommand(1, 90, 1050, "objRangeRepOrigin", NULL);
	RegisterCommand(1, 91, 1050, "objBgRangeRepOrigin", NULL);
	RegisterCommand(1, 90, 1051, "objRangeRepOriginX", NULL);
	RegisterCommand(1, 91, 1051, "objBgRangeRepOriginX", NULL);
	RegisterCommand(1, 90, 1052, "objRangeRepOriginY", NULL);
	RegisterCommand(1, 91, 1052, "objBgRangeRepOriginY", NULL);
	RegisterCommand(1, 90, 1053, "objRangeOrigin", NULL);
	RegisterCommand(1, 91, 1053, "objBgRangeOrigin", NULL);
	RegisterCommand(1, 90, 1054, "objRangeOriginX", NULL);
	RegisterCommand(1, 91, 1054, "objBgRangeOriginX", NULL);
	RegisterCommand(1, 90, 1055, "objRangeOriginY", NULL);
	RegisterCommand(1, 91, 1055, "objBgRangeOriginY", NULL);
	RegisterCommand(1, 90, 1056, "objRangeFadeOpts", NULL);
	RegisterCommand(1, 91, 1056, "objBgRangeFadeOpts", NULL);

	RegisterCommand(1, 255, 50, "??? (Clannad)", NULL);
	RegisterCommand(1, 255, 101, "__SaveBufferIdx", NULL);

	anm1 = NULL;
	anm2 = NULL;
}

Grp::~Grp() {
	map<int,GrpObj>::iterator it;
	for (it=grpobj.begin(); it!=grpobj.end(); it++) {
		PicBase* p = it->second.DeletePic();
		delete p;
	}

	delete screen;
	delete screen_front;
	parent.Root().DeleteSurface(surface);
	parent.Root().DeleteSurface(surface_update);
	int i;
	for (i=0; i<MAXPDT; i++) {
		if (ssurface[i]) parent.Root().DeleteSurface(ssurface[i]);
		if (dsurface[i]) parent.Root().DeleteSurface(dsurface[i]);
	}
}

Surface* Grp::Dsurface(int pdt) {
	if (pdt == 0) return surface;
	if (dsurface[pdt] == 0) { // とりあえず画面の大きさということにする
		if (pdt == WORKPDT)
			dsurface[pdt] = parent.Root().NewSurface(parent.Width(), parent.Height(), ALPHA_MASK);
		else
			dsurface[pdt] = parent.Root().NewSurface(parent.Width(), parent.Height(), NO_MASK);
	}
	if (ssurface[pdt]) { // ssurface が存在すれば、dsurface にコピーして返す
		DSurfaceMove(ssurface[pdt], Rect(*ssurface[pdt]), dsurface[pdt], Rect(0,0));
		parent.Root().DeleteSurface(ssurface[pdt]);
		ssurface[pdt] = 0;
	}
	return dsurface[pdt];
}

GrpObj* Grp::GetGraphicObj(int grp, bool fg) {
	if (fg)
		return &grpobj[grp];
	else
		return &bs_obj[grp];
}

GrpObj* Grp::GetGraphicObj(int grp, int index, bool fg) {
	GrpObj* g = GetGraphicObj(grp, fg);
	return &g->children_obj[index];
}

GrpObj* Grp::GetGraphicObjVarMode(Cmd& cmd, int &base_arg, bool fg) {
	GrpObj* g;
	if (cmd.cmd1 == 2) {
		g = GetGraphicObj(cmd.args[base_arg].value, cmd.args[base_arg+1].value, fg);
		base_arg += 1;
	}
	else
		g = GetGraphicObj(cmd.args[base_arg].value, fg);
	return g;
}

#include <SDL.h>
Surface* Grp::Ssurface(int pdt) {
	if (pdt == 0) return surface;
	if (ssurface[pdt]) {
		return ssurface[pdt];
	}
	return Dsurface(pdt);
}

void Grp::LoadSurface(const char* str, int pdt) {
	string s = str;
	if (cgm_info.find(s) != cgm_info.end()) {
		cgm_data.insert(cgm_info[s]);
	}
	Surface* bg = parent.Root().NewSurface(s.c_str());
	if (bg == NULL) {
		s += ".g00";
		bg = parent.Root().NewSurface(s.c_str());
	}
	if (bg != NULL) {
		if (ssurface[pdt]) parent.Root().DeleteSurface(ssurface[pdt]);
		ssurface[pdt] = bg;
		if (pdt == 0) {
			/* とりあえず Princess Bride のアニメーション効果専用 */
			Rect r(*ssurface[0]);
			Rect dr(*surface);
			int x = (dr.width()-r.width())/2;
			int y = (dr.height()-r.height())/2;
			DSurfaceMove(ssurface[0], r, surface, Rect(x,y));
			parent.Root().DeleteSurface(ssurface[0]);
			ssurface[0] = NULL;
			screen->SetSurface(surface, 0, 0);
		}
	} else {
		if (str[0] != 0)
			fprintf(stderr,"Cannot find surface %d <- '%s'\n",pdt,str);
	}
}

void Grp::InitSel(void) {
	int i;
	int args[16];
	char key[10];
	for (i=0; i<999; i++) {
		sprintf(key, "#SEL.%03d",i);
		if (config->GetParam(key, 15, &args[0], &args[1],
			&args[2], &args[3], &args[4], &args[5], &args[6], &args[7],
			&args[8], &args[9], &args[10], &args[11], &args[12], &args[13],
			&args[14])) {

			sprintf(key, "#SELR.%03d", i);
			if (config->GetParam(key, 16, &args[0], &args[1],
				&args[2], &args[3], &args[4], &args[5], &args[6], &args[7],
				&args[8], &args[9], &args[10], &args[11], &args[12], &args[13],
				&args[14], &args[15]))  continue;
		}
		SEL& s = anmtype[i];
		s.from = Rect(args[0], args[1], args[2]+1, args[3]+1);
		s.to = Rect(args[4], args[5]);
		s.time = args[6];
		s.sel_no = args[7];
		int j;
		for (j=0; j<8; j++) s.args[j] = args[8+j];
	}
}

void Grp::SetSkipMode(SkipMode _mode) {
	if ( (skip_mode & SKIP_IN_MENU) && (_mode & SKIP_IN_MENU) == 0) {
		RefreshObj();
	} else if ( (skip_mode & SKIP_IN_MENU) == 0 && (_mode & SKIP_IN_MENU) ) {
	}
	skip_mode = _mode;
}

void Grp::SetObjChanged(int num) {
	changed_obj.insert(num);
}

void Grp::RefreshObj(void) {
	if (!deleted_pic.empty()) {
		vector<PicBase*>::iterator it;
		for (it=deleted_pic.begin(); it!=deleted_pic.end(); it++) {
			if (*it) delete *it;
		}
		deleted_pic.clear();
	}
	if (!changed_obj.empty()) {
		set<int>::iterator it;
		for (it=changed_obj.begin(); it != changed_obj.end(); it++) {
			if (grpobj.find(*it) == grpobj.end()) continue;
			GrpObj& obj = grpobj[*it];
			obj.Refresh(obj);
		}
		changed_obj.clear();
	}
	if (reserved_load_surface0.length() != 0) {
		LoadSurface(reserved_load_surface0.c_str(), 0);
		reserved_load_surface0 = "";
	}
	screen->ReBlit();
}


#include <SDL.h>
void Grp::StartAnm(int type) {
	SEL sel;

	if (anmtype.find(type) == anmtype.end()) {
		if (anmtype.find(0) == anmtype.end()) {
			sel.sel_no = 1;
			sel.from = Rect(*surface);
			sel.to = Rect(0,0);
			sel.time = 0;
		} else {
			sel = anmtype[0];
		}
	} else {
		sel = anmtype[type];
	}
	if (anm1 != NULL) {
		fprintf(stderr,"Warning: StartAnm() called before anm1 finished\n");
		anm1->Abort();
		delete anm1;
		anm1 = NULL;
	}
	map<int,GrpObj>::iterator it;
	// 現在表示中のobjectを消去
	deleted_pic.push_back(screen);
	for (it=grpobj.begin(); it!=grpobj.end(); it++) {
		if (! (it->second.attr & GrpObj::WIPEON)) { // 画像切り替え時に object 削除
			deleted_pic.push_back(it->second.DeletePic());
		} else {
			GrpObj& new_obj = bs_obj[it->first];
			if (new_obj.name.empty()) { // 新しい object が存在しなければ内容を引き継ぐ
				new_obj = it->second;
				it->second.DeletePic();
			} else {
				new_obj.attr = GrpObj::Attribute(new_obj.attr | GrpObj::WIPEON);
				deleted_pic.push_back(it->second.DeletePic());
			}
		}
	}
	grpobj.clear(); // 全オブジェクト削除

	// 全画像オブジェクトの前にscreen 移動
	// 新しい screen_front を作成しておく
	screen = screen_front;
	screen->hide();
	screen->SetSurface(surface_update, 0, 0);
	parent.Root().BlitSurface(Dsurface(1), Rect(*surface_update), surface_update, Rect(0,0));

	screen_front = parent.create_leaf(Rect(0, 0, parent.Width(), parent.Height()), 0);
	screen_front->hide();
	screen_front->ZMove(screen);
	
	// 新しい object へ更新、surface_update へ新しい object を表示
	// (object 作成時は picture は hide されている)
	for (it=bs_obj.begin(); it!=bs_obj.end(); it++) {
		grpobj[it->first] = it->second;
		it->second.DeletePic();
		CreateObj(it->first);//FIXME: Adapt to groups
		GrpObj& g = grpobj[it->first];
		if (g.picture) {
			g.Update();
			if (g.alpha == 0 || (g.attr & GrpObj::HIDDEN)) ;
			else g.picture->SimpleBlit(surface_update);
			g.picture->hide();
		}
	}
	bs_obj.clear();
	// 画像効果開始
	switch(sel.sel_no) {
		default:
		case 0: case 50: // 0 と 50 の違いが良くわからない
			if (skip_mode & SKIP_GRP_NOEFFEC)
				anm1 = new WidAnmAlpha(event, screen, ALPHA_MAX, ALPHA_MAX, 0);
			else if (skip_mode & SKIP_GRP_FAST)
				anm1 = new WidAnmAlpha(event, screen, 0, ALPHA_MAX, sel.time/4);
			else
				anm1 = new WidAnmAlpha(event, screen, 0, ALPHA_MAX, sel.time);
			break;
	}
	if (anm1) anm1->Play();
	if (skip_mode & SKIP_GRP_NOEFFEC) AbortAnm();
}

void Grp::StartShake(int total, const int* pattern) {
	if (anm2) {
		fprintf(stderr,"Warning: StartShake() called before another animation finished\n");
		anm2->Abort();
		delete anm2;
		anm2 = NULL;
	}
	if (skip_mode & SKIP_GRP_NOEFFEC) return;
	AnmAlphaMove* new_anm = new AnmAlphaMove(event, &parent); // shake screen では元画面の座標を揺らす
	int i;
	int tm = 0;
	for (i=0; i<total; i+=3) {
		int x = pattern[i];
		int y = pattern[i+1];
		new_anm->ptns.push_back(AnmAlphaMove::Ptn(Rect(x,y), Rect(0,0), 255, tm));
		tm += pattern[i+2];
	}
	new_anm->ptns.push_back(AnmAlphaMove::Ptn(Rect(0,0), Rect(0,0), 255, tm));
	new_anm->SetPtn(); // パターン登録終了
	new_anm->Play();
	anm2 = new_anm;
}

void Grp::AbortAnm(void) {
	if (anm1 == NULL) return;
	anm1->Abort();
	delete anm1;
	anm1 = NULL;
	/* 画像効果終了 */
	/* 古い画面への画像効果があれば消去 */
	if (anm2 && anm2->pic[0] != screen) {
		anm2->Abort();
		delete anm2;
		anm2 = NULL;
	}
	/* pdt1 -> pdt0 へコピー */
	DSurfaceMove(dsurface[1], Rect(*dsurface[1]), surface, Rect(0,0));
	screen->SetSurface(surface, 0, 0);
	// 画像効果開始時に存在したobjectを消去
	// 新しい object 表示
	RefreshObj();
	return;
}

void Grp::LoadSurface(const char* str) {
	if (anm1 != NULL) AbortAnm(); // 前の描画が終わってなければ強制終了
	LoadSurface(str, 1);
	bg_name = str;
}

void Grp::LoadSurface(void) {
	if (anm1 != NULL) AbortAnm(); // 前の描画が終わってなければ強制終了
	LoadSurface(bg_name.c_str(), 1);
}

void Grp::AddSurface(const char* str) {
	if (anm1 != NULL) AbortAnm(); // 前の描画が終わってなければ強制終了
	LoadSurface(bg_name.c_str());

	string s = str;
	Surface* front = parent.Root().NewSurface(s.c_str());
	if (front == NULL) {
		s += ".g00";
		front = parent.Root().NewSurface(s.c_str());
	}
	if (front != NULL) {
		parent.Root().BlitSurface(front, Rect(*front), Dsurface(1), Rect(0,0));
		parent.Root().DeleteSurface(front);
	} else {
		fprintf(stderr,"Cannot find surface %s\n",str);
	}
}

void Grp::CreateObj(int index) {
	GrpObjMap::iterator cur = grpobj.find(index);
	if (cur == grpobj.end()) return;
	GrpObj& g = grpobj[index];
	g.CreateSurface(&parent);
	g.order = index;
	if (g.picture == NULL) return; // エラー:surface が存在しない
	g.picture->hide();
	SetObjChanged(index);
	ZMoveObj(index);
}

void Grp::CreateSubObj(int grp_index, int index) {
	GrpObjMap::iterator cur = grpobj.find(grp_index);
	if (cur == grpobj.end()) return;
	GrpObj* g = &grpobj[grp_index];
	cur = g->children_obj.find(index);
	if (cur == g->children_obj.end()) return;
	g = &g->children_obj[index];
	g->CreateSurface(&parent);
	g->order = index;
	if (g->picture == NULL) return; // エラー:surface が存在しない
	g->picture->hide();
	//TODO
	SetObjChanged(grp_index);
	/*ZMoveObj(index);*/
}

void Grp::ZMoveObj(int index) {
	GrpObjMap::iterator cur = grpobj.find(index);
	if (cur == grpobj.end()) return;
	GrpObj& g = grpobj[index];
	if (g.picture == NULL) return;
	// 自分より前に object があれば、その前に表示
	// そうでなければ screen の前に表示
	GrpObjMap::iterator cur_backobj = grpobj.end();
	GrpObjMap::iterator it;
	for (it = grpobj.begin(); it != grpobj.end(); it++) {
		if (it == cur) continue;
		if (it->second.picture == NULL) continue;
		if (it->second.order < g.order) {
			if (cur_backobj == grpobj.end()) {
				cur_backobj = it;
			} else if (cur_backobj->second.order < it->second.order) {
				cur_backobj = it;
			}
		}
	}
	if (cur_backobj == grpobj.end()) {
		g.picture->ZMove(screen);
	} else {
		g.picture->ZMove(cur_backobj->second.picture);
	}
}

void Grp::SwapObj(int index1, int index2) {
	// デフォルト値から order が変更されていた場合のみ、order は保存される
	// まずは両方のobjectをswap
	if (grpobj.find(index1) == grpobj.end()) {
		if (grpobj.find(index2) == grpobj.end()) return; // どちらの object も存在しない
		grpobj[index1] = grpobj[index2];
		if (grpobj[index1].order == index2)
			grpobj[index1].order = index1;
		grpobj[index2].DeletePic();
		grpobj.erase(index2);
		ZMoveObj(index1);
		return;
	} else if (grpobj.find(index2) == grpobj.end()) { // index2 が存在しない場合
		grpobj[index2] = grpobj[index1];
		if (grpobj[index2].order == index1)
			grpobj[index2].order = index2;
		grpobj[index1].DeletePic();
		grpobj.erase(index1);
		ZMoveObj(index2);
		return;
	} else {
		GrpObj obj = grpobj[index1];
		grpobj[index1] = grpobj[index2];
		grpobj[index2].DeletePic();
		if (grpobj[index1].order == index2)
			grpobj[index1].order = index1;
		ZMoveObj(index1);
		grpobj[index2] = obj;
		if (grpobj[index2].order == index1)
			grpobj[index2].order = index2;
		ZMoveObj(index2);
		obj.DeletePic();
	}
}

bool Grp::Pressed(int x, int y, void* pointer) { // マウスクリックでキャンセル
	Grp* g = (Grp*)pointer;
	if (g->status == WAIT_MOVIE)
		g->music->StopMovie();
	if (g->status == WAIT_ANM)
		g->AbortAnm();
	if (g->status == WAIT_SHAKE && g->anm2 != NULL) {
		g->anm2->Abort();
		delete g->anm2;
		g->anm2 = NULL;
	}
	return false; // event deleted
}

/* mode.cgm の decode 用 */
static unsigned char decode_char[256] = {
	0x8b, 0xe5, 0x5d, 0xc3, 0xa1, 0xe0, 0x30, 0x44, 
	0x00, 0x85, 0xc0, 0x74, 0x09, 0x5f, 0x5e, 0x33, 
	0xc0, 0x5b, 0x8b, 0xe5, 0x5d, 0xc3, 0x8b, 0x45, 
	0x0c, 0x85, 0xc0, 0x75, 0x14, 0x8b, 0x55, 0xec, 
	0x83, 0xc2, 0x20, 0x52, 0x6a, 0x00, 0xe8, 0xf5, 
	0x28, 0x01, 0x00, 0x83, 0xc4, 0x08, 0x89, 0x45, 
	0x0c, 0x8b, 0x45, 0xe4, 0x6a, 0x00, 0x6a, 0x00, 
	0x50, 0x53, 0xff, 0x15, 0x34, 0xb1, 0x43, 0x00, 
	0x8b, 0x45, 0x10, 0x85, 0xc0, 0x74, 0x05, 0x8b, 
	0x4d, 0xec, 0x89, 0x08, 0x8a, 0x45, 0xf0, 0x84, 
	0xc0, 0x75, 0x78, 0xa1, 0xe0, 0x30, 0x44, 0x00, 
	0x8b, 0x7d, 0xe8, 0x8b, 0x75, 0x0c, 0x85, 0xc0, 
	0x75, 0x44, 0x8b, 0x1d, 0xd0, 0xb0, 0x43, 0x00, 
	0x85, 0xff, 0x76, 0x37, 0x81, 0xff, 0x00, 0x00, 
	0x04, 0x00, 0x6a, 0x00, 0x76, 0x43, 0x8b, 0x45, 
	0xf8, 0x8d, 0x55, 0xfc, 0x52, 0x68, 0x00, 0x00, 
	0x04, 0x00, 0x56, 0x50, 0xff, 0x15, 0x2c, 0xb1, 
	0x43, 0x00, 0x6a, 0x05, 0xff, 0xd3, 0xa1, 0xe0, 
	0x30, 0x44, 0x00, 0x81, 0xef, 0x00, 0x00, 0x04, 
	0x00, 0x81, 0xc6, 0x00, 0x00, 0x04, 0x00, 0x85, 
	0xc0, 0x74, 0xc5, 0x8b, 0x5d, 0xf8, 0x53, 0xe8, 
	0xf4, 0xfb, 0xff, 0xff, 0x8b, 0x45, 0x0c, 0x83, 
	0xc4, 0x04, 0x5f, 0x5e, 0x5b, 0x8b, 0xe5, 0x5d, 
	0xc3, 0x8b, 0x55, 0xf8, 0x8d, 0x4d, 0xfc, 0x51, 
	0x57, 0x56, 0x52, 0xff, 0x15, 0x2c, 0xb1, 0x43, 
	0x00, 0xeb, 0xd8, 0x8b, 0x45, 0xe8, 0x83, 0xc0, 
	0x20, 0x50, 0x6a, 0x00, 0xe8, 0x47, 0x28, 0x01, 
	0x00, 0x8b, 0x7d, 0xe8, 0x89, 0x45, 0xf4, 0x8b, 
	0xf0, 0xa1, 0xe0, 0x30, 0x44, 0x00, 0x83, 0xc4, 
	0x08, 0x85, 0xc0, 0x75, 0x56, 0x8b, 0x1d, 0xd0, 
	0xb0, 0x43, 0x00, 0x85, 0xff, 0x76, 0x49, 0x81, 
	0xff, 0x00, 0x00, 0x04, 0x00, 0x6a, 0x00, 0x76
};

void Grp::LoadCgm() {
	/* cgm ファイル読み込み */
	const char* fname = config->GetParaStr("#CGTABLE_FILE");
	if (fname == NULL) return;
	ARCINFO* info = FileSearcher::GetInstance()->Find(FileSearcher::ALL, fname, "");
	if (info == NULL) return;
	char* data = info->CopyRead();
	int sz = info->Size();
	delete info;

	
	if ( strncmp(data, "CGTABLE", 7) != 0) {
		delete[] data;
		return;
	}
	cgm_size = read_little_endian_int(data+0x10);

	int i, j;
	// xor 解除
	for (i=0; i < sz-0x20; i++) {
		data[i+0x20]^=decode_char[i&0xff];
	}
	// 展開
	int dest_size = cgm_size * 36;
	char* dest = new char[dest_size+1024];
	char* src = data + 0x28;
	char* dest_orig = dest;
	ARCINFO::Extract2k(dest,src,dest+dest_size,data+sz);
	dest = dest_orig;
	for (i=0; i<cgm_size; i++) {
		char* s = dest + i * 36;
		int n = read_little_endian_int(dest + i * 36 + 32);
		cgm_info[s] = n;
	}
	delete[] data;
	delete[] dest_orig;
}

/*****************************************************
*
*   Grp :: Save, Load : セーブファイル処理
*
*/
void Grp::Save(std::string& str) {
}

void Grp::Load(const char* str) {
	status = NORMAL;
	if (anm1 != NULL) {
		AbortAnm();
	}
	if (anm2 != NULL) {
		anm2->Abort();
		delete anm2;
		anm2 = NULL;
	}
	map<int,GrpObj>::iterator it;
	for (it=grpobj.begin(); it!=grpobj.end(); it++) {
		PicBase* p = it->second.DeletePic();
		delete p;
	}
	grpobj.clear();
	
	bg_name = "";
	music->StopCDROM(100);
}

void Grp::SaveSys(string& save) {
	char buf[1024];
	save = "\n[Graphics]\n";
	save += "CGM_CG=";

	set<int>::iterator it;
	for (it=cgm_data.begin(); it != cgm_data.end(); it++) {
		sprintf(buf,"%d,",*it);
		save += buf;
	}
	save += "\n";
}

void Grp::LoadSys(const char* save) {
	cgm_data.clear();
	save = strstr(save, "\n[Graphics]\n");

	if (save) {
		save += strlen("\n[Graphics]\n");
		do {
			if (save[0] == '[') break; // next section
			if (strncmp(save, "CGM_CG=",7) == 0) {
				save += 7;
				while(isdigit(*save)) {
					int n = atoi(save);
					cgm_data.insert(n);
					save = strchr(save, ',');
					if (save) save++;
				}
			}
			save = strchr(save, '\n');
			if (save) save++;
		} while (save);
	}
	return;
}


/*****************************************************
*
*   Grp :: Wait , Exec : コマンド実行部
*
*/
static vector<int> drawn_images;
static int draw_n = 0;
extern bool grpdump_req;
bool Grp::Wait(unsigned int current_time, Cmd& cmd) {
	if (grpdump_req) {
		grpdump_req = 0;
		GrpObjMap::iterator it;
		fprintf(stderr,"front %p(%d) / %p(%d)\n",screen,screen->IsHidden(),screen_front,screen_front->IsHidden());
		for (it=grpobj.begin(); it != grpobj.end(); it++) {
			GrpObj& obj = it->second;
			obj._debug_Dump(it->first, 0);
		}
		std::list<PicBase*>::iterator it2;
		for (it2=parent.children.begin(); it2!=parent.children.end();it2++) {
			fprintf(stderr,"%p(%d)\n",*it2,(*it2)->IsHidden());
		}
		RefreshObj();

	}
#if 0
	if (event.presscount(MOUSE_UP)) {
        	std::list<PicBase*>::iterator lit;
		draw_n++; int i=0;
		for (lit=parent.children.end(); lit!=parent.children.begin(); ) {
			lit--;
			(*lit)->hide();
			i++;
			if (i >= draw_n) break;
		}
		if (drawn_images.empty()) {
			map<int, GrpObj>::iterator it;
			for (it=grpobj.begin(); it!=grpobj.end(); it++) {
				if (it->second.picture) {
					drawn_images.push_back(it->first);
					PicBase* p = it->second.DeletePic();
					delete p;
				}
			}
		} else {
			vector<int>::iterator it;
			for (it=drawn_images.begin(); it!=drawn_images.end(); it++) {
				CreateObj(*it);
			}
			drawn_images.clear();
		}
	}
#endif
	if (status == WAIT_ANM) {
		if (anm1 != NULL) {
			if (!anm1->IsEnd()) return true;
			//FIXME: Handle animation loops
			AbortAnm();
		}
	} else if (status == WAIT_SHAKE) {
		if (anm2 != NULL) {
			if (!anm2->IsEnd()) return true;
			delete anm2;
			anm2 = NULL;
		}
		status = NORMAL;
	} else if (status == WAIT_SE) {
		if (music->IsStopSE()) status = NORMAL;
		return true;
	} else if (status == WAIT_MOVIE) {
		if (music->IsStopMovie()) {
			music->StopMovie();
			status = NORMAL;
			screen->ReBlit();
		}
		return true;
	}
	if (anm2 != NULL) {
		if (anm2->IsEnd()) {
			delete anm2;
			anm2 = NULL;
		}
	}
	return false;
}

void Grp::DeleteObjPic(int num) { // object の surface のみ削除
	if (grpobj.find(num) == grpobj.end()) return;
	deleted_pic.push_back(grpobj[num].DeletePic());
}

void Grp::DeleteSubObjPic(int num_grp, int num) {
	if (grpobj.find(num_grp) == grpobj.end()) return;
	if (grpobj[num_grp].children_obj.find(num) == grpobj[num_grp].children_obj.end()) return;
	deleted_pic.push_back(grpobj[num_grp].children_obj[num].DeletePic());
}

void Grp::DeleteObj(int num) {
	if (grpobj.find(num) == grpobj.end()) return;
	deleted_pic.push_back(grpobj[num].DeletePic());
	GrpObjMap::iterator it;
	for (it = grpobj[num].children_obj.begin(); it != grpobj[num].children_obj.end(); it++) {
		deleted_pic.push_back(it->second.DeletePic());
	}
	grpobj.erase(num);
}

void Grp::DeleteSubObj(int num_grp, int num) {
	if (grpobj.find(num_grp) == grpobj.end()) return;
	if (grpobj[num_grp].children_obj.find(num) == grpobj[num_grp].children_obj.end()) return;
	deleted_pic.push_back(grpobj[num_grp].children_obj[num].DeletePic());
	grpobj[num_grp].children_obj.erase(num);
}

void Grp::Exec(Cmd& cmd) {
	if (cmd.cmd_type == CMD_TEXTEND) {
		music->StopKoe(500); // テキスト終了で声を止める
		cmd.clear();
		return;
	}
	if (cmd.cmd_type == CMD_WAITFRAMEUPDATE) {
		// wait する場合は RefreshObj() しておく
		RefreshObj();
	}
	if (cmd.cmd_type != CMD_OTHER) return;

	CommandHandler::Exec(cmd);

	//TODO: ???
	if (cmd.cmd1 == 1 && cmd.cmd2 == 60 && cmd.cmd3 == 0) { // ??? : KANOGI : 画像オブジェクトの削除?
		DeleteObjPic(cmd.args[0].value); // 旧ファイル名のsurfaceを削除
		GrpObj& g = grpobj[cmd.args[0].value];
		g.attr = GrpObj::Attribute(g.attr | GrpObj::HIDDEN);
		cmd.clear();
	}

	// Refresh changed objects...
	//FIXME: should may be go away?
	//Seems it'll work only for objects in the foreground
	if ( (cmd.cmd1 == 1 || cmd.cmd1 == 2) && cmd.cmd2 == 81) {
		GrpObj* g;
		if (cmd.cmd1 == 2)
			g = GetGraphicObj(cmd.args[0].value, cmd.args[1].value);
		else
			g = GetGraphicObj(cmd.args[0].value);
		if (g->attr & GrpObj::UPDATE_ALL)
			SetObjChanged(cmd.args[0].value);
	}
}