/*
 * video.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 _VIDEO_H_
#define _VIDEO_H_

#include <common.h>
#include <pci.h>
#include <device.h>

#define TEXT_HEIGHT 25
#define TEXT_WIDTH 80
#define VGA_AC_INDEX 0x3C0
#define VGA_AC_WRITE 0x3C0
#define VGA_AC_READ 0x3C1
#define VGA_MISC_WRITE 0x3C2
#define VGA_SEQ_INDEX 0x3C4
#define VGA_SEQ_DATA 0x3C5
#define VGA_DAC_READ_INDEX 0x3C7
#define VGA_DEC_WRITE_INDEX 0x3C8
#define VGA_DAC_DATA 0x3C9
#define VGA_MISC_READ 0x3CC
#define VGA_MISC_WRITE 0x3C2
#define VGA_CRTC_INDEX 0x3D4
#define VGA_CRTC_DATA 0x3D5
#define VGA_GC_INDEX 0x3CE
#define VGA_GC_DATA 0x3CF

typedef struct video_device video_device_t;

typedef dword_t (*video_init_proc_t)(list_entry_t *video_devices);
typedef dword_t (*video_cleanup_proc_t)(void);

typedef dword_t (*video_control_proc_t)(
    video_device_t *device,
    dword_t control_code,
    const void *in_buffer,
    size_t in_length,
    void *out_buffer,
    size_t out_length
);

typedef struct
{
    video_init_proc_t init_proc;
    video_cleanup_proc_t cleanup_proc;
    video_control_proc_t control_proc;
} video_driver_t;

struct video_device
{
    device_t header;
    list_entry_t list;
    pci_device_t *pci_device;
    video_driver_t *driver;
    video_mode_t current_mode;
};

dword_t video_default_control(
    video_device_t *device,
    dword_t control_code,
    const void *in_buffer,
    size_t in_length,
    void *out_buffer,
    size_t out_length
);

dword_t register_video_driver(video_driver_t *driver);
dword_t unregister_video_driver(video_driver_t *driver);
void video_init();

#endif
