/*
 * wnix, a Unix-like operating system for WebAssembly applications.
 * Copyright (C) 2025  Xavier Del Campo Romero
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#include <gfx/gfx.h>
#include <gfx/private.h>
#include <drv/ps1/gpu.h>

void gfx_swapenvs(void)
{
    static short dispenv, drawenv = 256;
    const short y = dispenv;

    dispenv = drawenv;
    drawenv = y;

    GP0->mask = (const union drv_ps1_gpu_gp0)
    {
        .draw_area_tl =
        {
            .cmd = GP0_DRAW_AREA_TOP_LEFT,
            .y = drawenv
        }
    }.mask;

    GP0->mask = (const union drv_ps1_gpu_gp0)
    {
        .draw_area_br =
        {
            .cmd = GP0_DRAW_AREA_BOTTOM_RIGHT,
            .x = SCREEN_W - 1,
            .y = drawenv + SCREEN_H - 1,
        }
    }.mask;

    GP1->mask = (const union drv_ps1_gpu_gp1)
    {
        .disparea =
        {
            .cmd = GP1_START_DISPLAY_AREA,
            .y = dispenv
        }
    }.mask;
}
