blob: 372677576357716e23cd675203788381ef848cbb [file] [log] [blame]
/*
* Copyright 2017, Adrien Destugues, pulkomandy@pulkomandy.tk
* Distributed under terms of the MIT license.
*/
#include "ctk-arch.h"
#include "libconio.h"
extern unsigned int vram[];
ctk_arch_key_t key;
/* Keyboard management */
ctk_arch_key_t
ctk_arch_getkey(void)
{
return key;
}
unsigned char kbhit(void)
{
volatile unsigned int* const UART_STATUS = 0x3D31;
volatile unsigned int* const UART_RX = 0x3D36;
unsigned int tmp;
if ((*UART_STATUS & 1) == 0)
return 0;
tmp = *UART_RX;
if ((tmp == 0x55) || (tmp == 0xA0) || (tmp == 0x90) || (tmp == 0xC0) || (tmp == 0x80))
return 0;
key = tmp;
return 1;
}
#if 0
/* Mouse management */
void ctk_mouse_init(void)
{
mx = 50;
my = 20;
}
unsigned char ctk_mouse_xtoc(unsigned short x)
{
return x;
}
unsigned char ctk_mouse_ytoc(unsigned short y)
{
return y;
}
void ctk_mouse_hide(void)
{
vram_attr[ctk_mouse_ytoc(my)][ctk_mouse_xtoc(mx)] &= ~32;
}
void ctk_mouse_show(void)
{
vram_attr[ctk_mouse_ytoc(my)][ctk_mouse_xtoc(mx)] |= 32;
}
unsigned short ctk_mouse_x(void)
{
if (mouse_x != 0)
{
ctk_mouse_hide();
mx += mouse_x; mouse_x = 0;
if (mx < 0) mx = 0;
if (mx >= LIBCONIO_SCREEN_WIDTH) mx = LIBCONIO_SCREEN_WIDTH - 1;
}
return mx;
}
unsigned short ctk_mouse_y(void)
{
if (mouse_y != 0) {
ctk_mouse_hide();
my += mouse_y; mouse_y = 0;
if (my < 0) my = 0;
if (my >= LIBCONIO_SCREEN_HEIGHT) my = LIBCONIO_SCREEN_HEIGHT - 1;
}
return my;
}
unsigned char ctk_mouse_button(void)
{
return mouse_buttons;
}
#endif
extern int vram_attr[];
#define VRAM_WIDTH 64
/* Character display */
void
ctk_arch_draw_char(char c,
unsigned char x, unsigned char y,
unsigned char reversed,
unsigned char color)
{
if (reversed)
color ^= 8;
vram[y * VRAM_WIDTH + x] = c;
if (x & 1) {
vram_attr[(y * VRAM_WIDTH + x) / 2] &= 0xff;
vram_attr[(y * VRAM_WIDTH + x) / 2] |= color << 8;
} else {
vram_attr[(y * VRAM_WIDTH + x) / 2] &= 0xff00;
vram_attr[(y * VRAM_WIDTH + x) / 2] |= color;
}
}