/*
 * common.h
 *
 * Copyright (C) 2016 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
 *
 * 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 <http://www.gnu.org/licenses/>.
 */

#ifndef _COMMON_H_
#define _COMMON_H_

#include <stdlib.h>
#include <string.h>
#include <sdk/defs.h>
#include <cpu.h>

/* Monolithium-specific Helper Macros */
#define SEGMENT_RPL(x) ((x) & 0x03)
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))

#define VIDEO_MEMORY      0xF0000000
#define TEXT_VIDEO_MEMORY 0xB8000
#define TEXT_WIDTH        80
#define TEXT_HEIGHT       25

#define DOUBLE_HORIZONTAL_BAR    0xCD
#define DOUBLE_VERTICAL_BAR      0xBA
#define DOUBLE_CORNER_LEFT_MID   0xBA
#define DOUBLE_CORNER_LEFT_DOWN  0xBB
#define DOUBLE_CORNER_LEFT_UP    0xBC
#define DOUBLE_CORNER_RIGHT_UP   0xC8
#define DOUBLE_CORNER_RIGHT_DOWN 0xC9
#define DOUBLE_CORNER_RIGHT_MID  0xCC

static inline void enable_nmi()
{
    cpu_write_port_byte(0x70, cpu_read_port_byte(0x70) & 0x7F);
}

static inline void disable_nmi()
{
    cpu_write_port_byte(0x70, cpu_read_port_byte(0x70) | 0x80);
}

#endif
