view draw_inputs.pde @ 225:1c9deae71fb1

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 05 Sep 2018 20:28:23 +0300
parents 6d866e284dd2
children
line wrap: on
line source

// Collect all that "reads" the virtual image in some way or other
// plus other passive manipulations

int odd(int v)
{
    return (v & 1);
}


int even(int v)
{
    return 1 - (v & 1);
}


float getangel(float xx, float yy)
{
    float ang = degrees(atan2(xx, -yy));
    return (ang < 0) ? 360 + ang : ang;
}


int zxcolor(int col)
{
    //something that allows different zx brightness colors treated logically as the same
    //i.e. bright red and dark red the same. handy for brush transparency
    if (g_britemode == 0)
        return col;
    else
        return (col > 7) ? col - 8 : col;
}


//the "slow" call to mark "dirty block"
void updatepoint(int xx, int yy)
{
    if (yy < 0 || xx < 0 || xx >= X || yy >= Y)
        return;

    int ad = int(xx / 8) + int(yy / 8) * MX;
    g_redo[ad] = byte(0); //block update
    g_remdo[ad] = byte(1); //block update
}


int getmultibrush(int xc, int yc)
{
    //returns the multicolor color on point xc,yc at brush
    int ad, looks, mmc;
    if (g_multic == 2) return g_brush[1024 + xc + yc * X];

    ad = 1024 + xc + yc * X;
    looks = 65536 + int(xc / 8) + int(yc / 8) * MX;
    mmc = g_brush[ad] + g_brush[ad + 1] * 2;
    switch (mmc)
    {
        case 0:
            return g_map[1];
        case 1:
            return g_brush[looks];
        case 2:
            return g_brush[looks + 1000];
        case 3:
            if (g_machine == PLUS4M) return int(g_map[2]);
            return g_brush[looks + 2000];
    }
    return g_brush[ad] + g_brush[ad + 1] * 2;
}


int getmultic(int xc, int yc, int mode) //mode 0=screen 1=brush
{
    //returns the multicolor color on point xc,yc
    int ad = 1024 + xc + yc * X;

    if (g_multic == 2)
    {
        if (mode == 0) return g_map[ad];
        if (mode == 1) return g_brush[ad];
    }

    int source1 = 0,
        source2 = 0,
        looks = 65536 + int(chop2(xc) / 8) + int(yc / 8) * MX;

    if (mode == 0)
    {
        source1 = g_map[ad];
        source2 = g_map[ad + 1];
    }
    else
    if (mode == 1)
    {
        source1 = g_brush[ad];
        source2 = g_brush[ad + 1];
    }

    int mmc = source1 + source2 * 2;

    //source1=0
    //source2=+1
    //00=zeroc =0
    //01=color1=2
    //10=color2=1
    //11=color3=3

    if (mode == 0)
    {
        switch (mmc)
        {
            case 0:
                return g_map[1];
            case 1:
                return g_map[looks];
            case 2:
                return g_map[looks + 1000];
            case 3:
                if (g_machine == PLUS4M) return int(g_map[2]);
                return g_map[looks + 2000];
        }
    }
    else
    if (mode == 1)
    {
        switch (mmc)
        {
            case 0:
                return g_map[1];
            case 1:
                return g_brush[looks];
            case 2:
                return g_brush[looks + 1000];
            case 3:
                if (g_machine == PLUS4M) return int(g_map[2]);
                return g_brush[looks + 2000];
        }
    }

    return source1 + source2;
}


int getattra(int xx, int yy, int mode) //mode foreground backround
{
    //returns the internal foreground / background color on point xx,yy
    if (g_multic == 2)
    {
        return (mode == 0) ? getmultic(xx, yy, 0) : g_backg;
    }
    else
    if (g_multic == 1)
    {
        return (mode == 0) ? getmultic(xx, yy, 0) : g_map[1]; // was 0?
    }

    // XXX ! is this correct? yv is not used
    int val,
        xv = int(xx / 8),
        yv = int(yy / 8);

    int ad = 65536 + xv + yy * MX;
    if (mode == 0)
        val = g_map[ad];
    else
        val = g_map[ad + (MX * MY) * 8];

    return (g_britemode == 1 && val == 8) ? 0 : val;
}


int getabsa(int xx, int yy, int mode) //mode 0=screen 1=brush
{
    // returns the visible colour on point xx,yy
    int ssap, val = 0,
        sad = 1024 + xx + yy * X,
        ad = 65536 + int(xx / 8) + yy * MX;

    int chek = int(g_map[sad]);
    if (chek == 100 || chek == 200)
        return chek;

    if (mode == 0)
        ssap = int(g_map[sad]);
    else
        ssap = int(g_brush[sad]);

    if (ssap == 1)
    {
        if (mode == 0)
        {
            val = g_map[ad];
        }
        else
        {
            val = g_brush[ad];
        }
        if (g_britemode == 1 && val == 8) return 0;
        return val;
    }
    else
    if (ssap == 0)
    {
        if (mode == 0)
        {
            val = g_map[ad + (MX * MY) * 8];
        }
        else
        {
            val = g_brush[ad + (MX * MY) * 8];
        }
        if (g_britemode == 1 && val == 8) return 0;
        return val;
    }
    else
        return g_map[sad];
}


//the most accessible way to get a color index from a point
int easygetcolor(int xx, int yy)
{
    if (yy < 0 || xx < 0 || xx >= X || yy >= Y)
        return 0;
    else
    if (g_multic > 0)
        return getmultic(xx, yy, 0);
    else
        return getabsa(xx, yy, 0);
}


void infersize()
{
    int xx, yy, cp, okay;
    int bx, by;
    storeparameters();
    xx = 0;
    okay = 0;
    cp = easygetcolor(0, 0);
    for (xx = 0; xx < X; xx = xx + g_pixelw)
    {
        if (easygetcolor(xx, 0) == cp && okay == 0)
        {
            g_animx = xx;
        }
        else
        {
            okay = 1;
        }
    }
    okay = 0;
    for (yy = 0; yy < Y; yy++)
    {
        if (easygetcolor(0, yy) == cp && okay == 0)
        {
            g_animy = yy;
        }
        else
        {
            okay = 1;
        }
    }

    g_animx = g_animx + g_pixelw;
    g_animy = g_animy + 1;
    if (g_animx > 63 || g_animy > 63 || g_animx <= 2 || g_animy <= 2)
    {
        message("BAD SIZE|See manual");
        restoreparameters();
        g_data[int('n')] = 0;
        return;
    }
    int boldsourcex = g_bsourcex;
    int boldsourcey = g_bsourcey;
    int boldsourcex2 = g_bsourcex2;
    int boldsourcey2 = g_bsourcey2;

    g_bsourcex = g_animx;
    g_bsourcey = 0;
    g_bsourcex2 = g_animx + g_animx - g_pixelw;
    g_bsourcey2 = g_animy - 1;
    g_animframes = 0;
    g_animno = 1;
    int raamit = -1;
    for (yy = 0; yy <= Y; yy = yy + g_animy)
    {
        for (xx = 0; xx <= X; xx = xx + g_animx)
        {
            okay = 1;
            for (bx = 0; bx < g_animx; bx = bx + g_pixelw)
            {
                for (by = 0; by < g_animy; by++)
                {
                    if (easygetcolor(xx + bx, yy + by) != cp) okay = 0;
                }
            }
            if (okay == 1 && g_animframes <= 1) g_animframes = raamit;
            if (xx + g_animx < X || xx + g_animx == X) raamit++;
        }
    }
    if (g_animframes <= 0)
    {
        message("BAD BOOKEND|See manual");
        restoreparameters();
        g_data[int('n')] = 0;
        g_bsourcex = boldsourcex;
        g_bsourcey = boldsourcey;
        g_bsourcex2 = boldsourcex2;
        g_bsourcey2 = boldsourcey2;
        return;
    }
    message("Play Brush|" + g_animx + " x " + g_animy + "|" + g_animframes + " frames");
}


void animbrush_do()
{
    int bx, by;
    int horisize;
    horisize = int(X / g_animx);
    g_animno = g_animno + 1;
    if (g_animno > g_animframes) g_animno = 1;
    by = int(g_animno / horisize);
    bx = g_animno - (by * horisize);
    g_bsourcex = bx * g_animx;
    g_bsourcey = by * g_animy;
    g_bsourcex2 = g_bsourcex + g_animx - g_pixelw;
    g_bsourcey2 = g_bsourcey + g_animy - 1;
}

void set_fixed_raster(int set)
{
    for (int i = 0; i < 64; i++)
    {
        g_fixedraster[i] = g_rasterpatterns[set * 64 + i];
    }
}

int get_raster(int xx, int yy)
{
    xx = xx + g_raster_offset_x * g_pixelw;
    yy = yy + g_raster_offset_y;
    if (g_pixelw == 2)
    {
        xx = int(xx / 2);
    }
    int mx = chop8(xx);
    int my = chop8(yy);
    xx = xx - mx;
    yy = yy - my;
    return g_fixedraster[xx + yy * 8];
}

void refreshpalette()
{
    //relevant for alterable palettes, such as amiga or cpc
    if (g_palsteps == 0) return;
    for (int i = 0; i < g_maxcolors; i++)
    {
        makecolor(i, int(g_map[256 + i * 3]), int(g_map[256 + i * 3 + 1]), int(g_map[256 + i * 3 + 2]));
    }
}