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

縦スクロール - (2016/10/20 (木) 16:45:27) のソース

-裏で新しい背景を描きながら画面スクロールします。
-.asmを$01=Vertical Mirrorにしておきましょう。
//(チラつき防止、&color(red){本来逆にしなければならない筈})
-NMIProc内でif (bgx % 8 == ?) {}としていくつかに分けて処理しているのは負荷分担のためです。&br()まとめて処理すると表示が追いつかずに背景がきちんと出力されません。
-初期化の処理と画面切り替えのタイミングの見直しが必要かも。
#highlight(c){{{
#include <kihon.h>

//NMI割り込み
void NMIProc(void)
{
    static unsigned char bgy=239,no=2,mode=0,wno,scr=0;
    unsigned char pos[2],y;

    if (bgy % 8 == 3) {
        if (mode) {
            scr = 0;
        } else {
            scr = 1;
        }

        y = bgy / 8;
    }
    if (bgy % 8 == 4) {
        wno = no;
    }
    if (bgy % 8 == 5) {
        GetBackgroundAddress(scr, 0, y, pos);
        FillBackground(*(pos + 0),*(pos + 1) ,wno,10);
    }
    if (bgy % 8 == 6) {
        GetBackgroundAddress(scr,10, y, pos);
        FillBackground(*(pos + 0),*(pos + 1) ,wno,10);
    }
    if (bgy % 8 == 7) {
        GetBackgroundAddress(scr,20, y, pos);
        FillBackground(*(pos + 0),*(pos + 1) ,wno,12);
    }

    if (bgy==0) {
        no++;
        mode^=1;
        if (mode) {
            SetPPU(0x8a,0x1e);
        } else {
            SetPPU(0x88,0x1e);
        }
        bgy = 239;
        SetScroll(0,bgy);
    } else {
        SetScroll(0,bgy);
        bgy--;
    }
    if (no > 9) { no=1; }
}

// メイン処理
void NesMain()
{
    unsigned char i,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);

    for (i = 0; i < 30; i++)
    {
        GetBackgroundAddress(0, 0, i, pos);
        FillBackground(*(pos + 0), *(pos + 1), 1, 32);
    }

    SetPPU(0x88,0x1e);

    VBlank();
    while (1);
}
}}}