/*
 * 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/>.
 */

#ifndef DRV_PS1_CD_REGS_H
#define DRV_PS1_CD_REGS_H

#include <stdint.h>

struct cd_reg_status
{
    uint8_t index :2;
    const uint8_t ADPBUSY :1, PRMEMPT :1, PRMWRDY :1, RSLRRDY :1, DRQSTS :1,
        BUSYSTS :1;
};

struct cd_reg_cmd
{
    uint8_t cmd;
};

struct cd_reg_rsp
{
    uint8_t rsp;
};

struct cd_reg_param
{
    uint8_t param;
};

union cd_reg_if
{
    const struct
    {
        uint8_t response :3, :1, cmd_start :1, :3;
    } r;

    struct
    {
        uint8_t ack: 5, :1, CLRPRM :1, :1;
    } w;
};

#define CD_REG(x) (0x1f801800 + (x))
#define CD_REG_STATUS ((volatile struct cd_reg_status *)CD_REG(0))
#define CD_REG_CMD ((volatile struct cd_reg_cmd *)CD_REG(1))
#define CD_REG_RSP ((const volatile struct cd_reg_rsp *)CD_REG(1))
#define CD_REG_PARAM ((volatile struct cd_reg_param *)CD_REG(2))
#define CD_REG_IF ((volatile union cd_reg_if *)CD_REG(3))

#endif
