/*
 * Author: Jake G
 * Date: 2025
 * filename: RegEdit.c
 * description: Provides a register editing interface.
 */

#include "RegEdit.h"

// For 64-Bit systems and register access.

void RegEdit_u64_SetRegister(void *reg)
{
    uint64_t *reg_ptr = (uint64_t *)reg;
    //*reg_ptr         = 0xFFFFFFFFFFFFFFFF;
    *reg_ptr = UINT64_MAX;
}

void RegEdit_u64_ClearRegister(void *reg)
{
    uint64_t *reg_ptr = (uint64_t *)reg;
    *reg_ptr          = 0;
}

void RegEdit_u64_SetBit(void *reg, uint8_t bit_num)
{
    uint64_t *reg_ptr = (uint64_t *)reg;
    *reg_ptr |= (uint64_t)(1 << bit_num);
}

void RegEdit_u64_ClearBit(void *reg, uint8_t bit_num)
{
    uint64_t *reg_ptr = (uint64_t *)reg;
    *reg_ptr &= ~(1 << bit_num);
}

bool RegEdit_u64_IsBitSet(void *reg, uint8_t bit_num)
{
    uint64_t *reg_ptr = (uint64_t *)reg;
    return *reg_ptr & (1 << bit_num);
}

void RegEdit_u64_OR_Num(void *reg, uint64_t num)
{
    uint64_t *reg_ptr = (uint64_t *)reg;
    *reg_ptr |= num;
}

void RegEdit_u64_AND_Num(void *reg, uint64_t num)
{
    uint64_t *reg_ptr = (uint64_t *)reg;
    *reg_ptr &= num;
}

void RegEdit_u64_SetNum(void *reg, uint64_t num)
{
    uint64_t *reg_ptr = (uint64_t *)reg;
    *reg_ptr          = num;
}

uint64_t RegEdit_u64_ReadReg(void *reg)
{
    uint64_t *reg_ptr = (uint64_t *)reg;
    return *reg_ptr;
}

// For 32-Bit systems and register access.

void RegEdit_u32_SetRegister(void *reg)
{
    uint32_t *reg_ptr = (uint32_t *)reg;
    *reg_ptr          = UINT32_MAX;
}

void RegEdit_u32_ClearRegister(void *reg)
{
    uint32_t *reg_ptr = (uint32_t *)reg;
    *reg_ptr          = 0;
}

void RegEdit_u32_SetBit(void *reg, uint8_t bit_num)
{
    uint32_t *reg_ptr = (uint32_t *)reg;
    *reg_ptr |= (uint32_t)(1 << bit_num);
}

void RegEdit_u32_ClearBit(void *reg, uint8_t bit_num)
{
    uint32_t *reg_ptr = (uint32_t *)reg;
    *reg_ptr &= ~(1 << bit_num);
}

bool RegEdit_u32_IsBitSet(void *reg, uint8_t bit_num)
{
    uint32_t *reg_ptr = (uint32_t *)reg;
    return *reg_ptr & (1 << bit_num);
}

void RegEdit_u32_OR_Num(void *reg, uint32_t num)
{
    uint32_t *reg_ptr = (uint32_t *)reg;
    *reg_ptr |= num;
}

void RegEdit_u32_AND_Num(void *reg, uint32_t num)
{
    uint32_t *reg_ptr = (uint32_t *)reg;
    *reg_ptr &= num;
}

void RegEdit_u32_SetNum(void *reg, uint32_t num)
{
    uint32_t *reg_ptr = (uint32_t *)reg;
    *reg_ptr          = num;
}

uint32_t RegEdit_u32_ReadReg(void *reg)
{
    uint32_t *reg_ptr = (uint32_t *)reg;
    return *reg_ptr;
}

// For 16-Bit systems and register access.

void RegEdit_u16_SetRegister(void *reg)
{
    uint16_t *reg_ptr = (uint16_t *)reg;
    *reg_ptr          = UINT16_MAX;
}

void RegEdit_u16_ClearRegister(void *reg)
{
    uint16_t *reg_ptr = (uint16_t *)reg;
    *reg_ptr          = 0;
}

void RegEdit_u16_SetBit(void *reg, uint8_t bit_num)
{
    uint16_t *reg_ptr = (uint16_t *)reg;
    *reg_ptr |= (uint16_t)(1 << bit_num);
}

void RegEdit_u16_ClearBit(void *reg, uint8_t bit_num)
{
    uint16_t *reg_ptr = (uint16_t *)reg;
    *reg_ptr &= ~(1 << bit_num);
}

bool RegEdit_u16_IsBitSet(void *reg, uint8_t bit_num)
{
    uint16_t *reg_ptr = (uint16_t *)reg;
    return *reg_ptr & (1 << bit_num);
}

void RegEdit_u16_OR_Num(void *reg, uint16_t num)
{
    uint16_t *reg_ptr = (uint16_t *)reg;
    *reg_ptr |= num;
}

void RegEdit_u16_AND_Num(void *reg, uint16_t num)
{
    uint16_t *reg_ptr = (uint16_t *)reg;
    *reg_ptr &= num;
}

void RegEdit_u16_SetNum(void *reg, uint16_t num)
{
    uint16_t *reg_ptr = (uint16_t *)reg;
    *reg_ptr          = num;
}

uint16_t RegEdit_u16_ReadReg(void *reg)
{
    uint16_t *reg_ptr = (uint16_t *)reg;
    return *reg_ptr;
}

// For 8-Bit systems and register access.

void RegEdit_u8_SetRegister(void *reg)
{
    uint8_t *reg_ptr = (uint8_t *)reg;
    *reg_ptr         = UINT8_MAX;
}

void RegEdit_u8_ClearRegister(void *reg)
{
    uint8_t *reg_ptr = (uint8_t *)reg;
    *reg_ptr         = 0;
}

void RegEdit_u8_SetBit(void *reg, uint8_t bit_num)
{
    uint8_t *reg_ptr = (uint8_t *)reg;
    *reg_ptr |= (uint8_t)(1 << bit_num);
}

void RegEdit_u8_ClearBit(void *reg, uint8_t bit_num)
{
    uint8_t *reg_ptr = (uint8_t *)reg;
    *reg_ptr &= ~(1 << bit_num);
}

bool RegEdit_u8_IsBitSet(void *reg, uint8_t bit_num)
{
    uint8_t *reg_ptr = (uint8_t *)reg;
    return *reg_ptr & (1 << bit_num);
}

void RegEdit_u8_OR_Num(void *reg, uint8_t num)
{
    uint8_t *reg_ptr = (uint8_t *)reg;
    *reg_ptr |= num;
}

void RegEdit_u8_AND_Num(void *reg, uint8_t num)
{
    uint8_t *reg_ptr = (uint8_t *)reg;
    *reg_ptr &= num;
}

void RegEdit_u8_SetNum(void *reg, uint8_t num)
{
    uint8_t *reg_ptr = (uint8_t *)reg;
    *reg_ptr         = num;
}

uint8_t RegEdit_u8_ReadReg(void *reg)
{
    uint8_t *reg_ptr = (uint8_t *)reg;
    return *reg_ptr;
}
