「縦スクロール」の編集履歴(バックアップ)一覧に戻る

縦スクロール - (2016/10/22 (土) 15:55:57) の編集履歴(バックアップ)


  • 裏で新しい背景を描きながら画面スクロールします。
  • .asmを$00=Horizontal Mirrorにしておきましょう。
  • NMIProc内でif (bgx % 8 == ?) {}としていくつかに分けて処理しているのは負荷分担のためです。
    まとめて処理すると表示が追いつかずに背景がきちんと出力されません。
  • 画面切り替えのタイミングの見直しが必要かも。
#include <kihon.h>
 
char init;
 
//NMI割り込み
void NMIProc(void)
{
	static unsigned char bgy,no,mode,wno,scr;
	unsigned char pos[2],y;
 
	if (init) {
		bgy=239;
		no=2;
		mode=0;
		scr=1;
		init=0;
	}
 
	if (bgy % 8 == 7) {
		y = bgy / 8;
		wno = no;
	}
	if (bgy % 8 == 6) {
		GetBackgroundAddress(scr, 0, y, pos);
		FillBackground(*(pos + 0),*(pos + 1) ,wno,5);
	}
	if (bgy % 8 == 5) {
		GetBackgroundAddress(scr, 5, y, pos);
		FillBackground(*(pos + 0),*(pos + 1) ,wno,5);
	}
	if (bgy % 8 == 4) {
		GetBackgroundAddress(scr,10, y, pos);
		FillBackground(*(pos + 0),*(pos + 1) ,wno,5);
	}
	if (bgy % 8 == 3) {
		GetBackgroundAddress(scr,15, y, pos);
		FillBackground(*(pos + 0),*(pos + 1) ,wno,5);
	}
	if (bgy % 8 == 2) {
		GetBackgroundAddress(scr,20, y, pos);
		FillBackground(*(pos + 0),*(pos + 1) ,wno,6);
	}
	if (bgy % 8 == 1) {
		GetBackgroundAddress(scr,26, y, pos);
		FillBackground(*(pos + 0),*(pos + 1) ,wno,6);
	}
 
	if (bgy==0) {
		no++;
		mode^=1;
		scr^=1;
		bgy = 239;
	} else {
		bgy--;
	}
 
	if (mode) {
		SetPPU(0x8a,0x1e);
	} else {
		SetPPU(0x88,0x1e);
	}
 
	SetScroll(0,bgy);
 
	if (no > 9) { no=1; }
}
 
// メイン処理
void NesMain()
{
	unsigned char i,j,pos[2];
	const char bgpalette[] = {
		0x0f, 0x21, 0x11, 0x20, 0x0f, 0x21, 0x11, 0x20,
		0x0f, 0x21, 0x11, 0x20, 0x0f, 0x21, 0x11, 0x20 };
	const char sppalette[] = {
		0x0f, 0x30, 0x37, 0x20, 0x0f, 0x0a, 0x25, 0x20,
		0x0f, 0x0a, 0x11, 0x20, 0x0f, 0x0a, 0x2a, 0x20 };
 
	VBlank();
	InitPPU();
 
	// パレット設定
	SetPalette((char *)bgpalette ,0);
	SetPalette((char *)sppalette, 1);
 
	init = 1;
 
	for (j = 0; j < 2; j++)
	{
		for (i = 0; i < 30; i++)
		{
			GetBackgroundAddress(1 - j, 0, i, pos);
			FillBackground(*(pos + 0), *(pos + 1), 48 + j, 32);
		}
	}
 
	SetPPU(0x88,0x1e);
	SetScroll(0,239);
 
	while (1);
}