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

横スクロール - (2016/10/20 (木) 16:46:06) の編集履歴(バックアップ)


  • 裏で新しい背景を描きながら画面スクロールします。
  • SetPPUにてflag1の2bit目を1(32bitインクリメント)にして背景を縦一列に出力しています。
  • .asmを$00=Horizontal Mirrorにしておきましょう。
  • その他は縦スクロールと同じです。
#include <kihon.h>
 
//NMI割り込み
void NMIProc(void)
{
    static unsigned char bgx=0,no=2,mode=0,wno,scr=0;
    unsigned char pos[2],x;
 
    if (bgx % 8 == 3) {
        if (mode) {
            scr = 0;
        } else {
            scr = 2;
        }
        x = bgx / 8;
    }
    if (bgx % 8 == 4 && bgx < 247) {
        wno = no;
    }
    if (bgx % 8 == 5) {
        GetBackgroundAddress(scr, x, 0, pos);
        FillBackground(*(pos + 0),*(pos + 1) ,wno,10);
    }
    if (bgx % 8 == 6) {
        GetBackgroundAddress(scr, x,10, pos);
        FillBackground(*(pos + 0),*(pos + 1) ,wno,10);
    }
    if (bgx % 8 == 7) {
        GetBackgroundAddress(scr, x,20, pos);
        FillBackground(*(pos + 0),*(pos + 1) ,wno,10);
    }
 
    SetScroll(bgx,0);
    bgx++;
 
    if (bgx==247) {
        no++;
        mode^=1;
        if (mode) {
            SetPPU(0x8d,0x1e);
        } else {
            SetPPU(0x8c,0x1e);
        }
    }
    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, 0x0a, 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(0x8c,0x1e);
 
    while (1);
}