LoginSignup
1
0

More than 5 years have passed since last update.

MSX 仮想VRAM

Posted at
wall.c
/*
z88dk / WebMSX
zcc +msx -lndos -create-app wall.c
bload"cas:",r
*/

#include <msx/gfx.h>

#define BYTE unsigned char

#define WIDTH 64
#define HEIGHT 48

const int dx[] = { 0, 0, 1, 1, 1, 0, -1, -1, -1 };
const int dy[] = { 0, -1, -1, 0, 1, 1, 1, 0, -1 };

BYTE vvr[WIDTH * HEIGHT] = { 0 };

void gen_wall()
{
    int lines[][] = {
        { 0, 0, 63, 0 },
        { 0, 23, 63, 23 },
        { 0, 47, 63, 47 },
        { 0, 0, 0, 47 },
        { 31, 0, 31, 47 },
        { 47, 24, 47, 47 },
        { 63, 0, 63, 47 }
    };

    for (int i = 0; i < 7; i++) {
        int x0 = lines[i][0];
        int y0 = lines[i][1];
        int x1 = lines[i][2];
        int y1 = lines[i][3];
        int w = x1 - x0;
        int h = y1 - y0;

        if (w >= h) {
            for (int j = x0; j <= x1; j++) {
                vvr[y0 * WIDTH + j] = 1;
            }
        } else {
            for (int j = y0; j <= y1; j++) {
                vvr[j * WIDTH + x0] = 1;
            }
        }
    }
}

void write_pgt()
{
    BYTE space[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00 };
    BYTE wall[] = { 0xff, 0x81, 0xbd, 0xbd, 0xbd, 0xbd, 0x81, 0xff };

    // パターンジェネレータ・テーブル
    vwrite(space, 0, 8);
    vwrite(wall, 8, 8);
}

void main()
{
    int px = 0;
    int py = 0;

    gen_wall();
    set_mode(mode_1);
    write_pgt();

    while (! get_trigger(0)) {
        int st = get_stick(0);
        px += dx[st];
        py += dy[st];
        if (px < 0) px = 0;
        if (px > WIDTH-32) px = WIDTH-32;
        if (py < 0) py = 0;
        if (py > HEIGHT-24) py = HEIGHT-24;

        BYTE *src = vvr + (py * WIDTH + px);
        int dst = 0x1800;   // パターンネーム・テーブル
        for (int y = 0; y < 24; y++) {
            vwrite(src, dst, 32);
            src += WIDTH;
            dst += 32;
        }
    }
}

ROMカートリッジ版

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0