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

横スクロール - (2016/10/22 (土) 17:00:26) の編集履歴(バックアップ)


  • 裏で新しい背景を描きながら画面スクロールします。
  • SetPPUにてflag1の2bit目を1(32bitインクリメント)にして背景を縦一列に出力しています。
  • .asmを$01=Vertical Mirrorにしておきましょう。
  • その他は縦スクロールと同じです。
#include <kihon.h>
 
char init;
 
//NMI割り込み
void NMIProc(void)
{
	static unsigned char bgx,no,mode,wno,scr;
	unsigned char pos[2],x;
 
	if (init) {
		bgx=0;
		no=2;
		mode=1;
		scr=0;
		init=0;
	}
 
	if (bgx % 8 == 1) {
		x = bgx / 8;
		wno = no + 48;
	}
	if (bgx % 8 == 2) {
		GetBackgroundAddress(scr, x, 0, pos);
		FillBackground(*(pos + 0),*(pos + 1) ,wno,5);
	}
	if (bgx % 8 == 3) {
		GetBackgroundAddress(scr, x, 5, pos);
		FillBackground(*(pos + 0),*(pos + 1) ,wno,5);
	}
	if (bgx % 8 == 4) {
		GetBackgroundAddress(scr, x,10, pos);
		FillBackground(*(pos + 0),*(pos + 1) ,wno,5);
	}
	if (bgx % 8 == 5) {
		GetBackgroundAddress(scr, x,15, pos);
		FillBackground(*(pos + 0),*(pos + 1) ,wno,5);
	}
	if (bgx % 8 == 6) {
		GetBackgroundAddress(scr, x,20, pos);
		FillBackground(*(pos + 0),*(pos + 1) ,wno,5);
	}
	if (bgx % 8 == 7) {
		GetBackgroundAddress(scr, x,25, pos);
		FillBackground(*(pos + 0),*(pos + 1) ,wno,5);
	}
 
	if (bgx==255) {
		no++;
		mode^=1;
		if (mode) {
			scr=0;
		} else {
			scr=2;
		}
	}
 
	bgx++;
 
	if (mode) {
		SetPPU(0x8c,0x1e);
	} else {
		SetPPU(0x8d,0x1e);
	}
 
	SetScroll(bgx,0);
 
	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, 0x0a, 0x37, 0x20, 0x0f, 0x0a, 0x25, 0x20,
		0x0f, 0x0a, 0x11, 0x20, 0x0f, 0x0a, 0x2a, 0x20 };
 
	VBlank();
	InitPPU();
 
	init = 1;
 
	// パレット設定
	SetPalette((char *)bgpalette ,0);
	SetPalette((char *)sppalette, 1);
 
	for (j = 0; j < 2; j++)
	{
		for (i = 0; i < 30; i++)
		{
			GetBackgroundAddress(j * 2, 0, i, pos);
			FillBackground(*(pos + 0), *(pos + 1), 48 + j, 32);
		}
	}
 
	SetPPU(0x8d,0x1e);
 
	while (1);
}