blob: 0ab5a3fb423d86319db252b75870e076a0614f12 [file] [log] [blame]
PulkoMandy612e2cf2021-09-20 23:00:40 +02001/*
2 * Copyright 2017, Adrien Destugues, pulkomandy@pulkomandy.tk
3 * Distributed under terms of the MIT license.
4 */
5
6
7#include "ctk-arch.h"
8#include "libconio.h"
9
10/* Keyboard management */
11ctk_arch_key_t
12ctk_arch_getkey(void)
13{
PulkoMandy6c4cba62021-09-21 21:33:31 +020014 volatile unsigned int* const UART_RX = 0x3D36;
15 return *UART_RX;
PulkoMandy612e2cf2021-09-20 23:00:40 +020016}
17
18unsigned char kbhit(void)
19{
PulkoMandy6c4cba62021-09-21 21:33:31 +020020 volatile unsigned int* const UART_STATUS = 0x3D31;
21
22 return *UART_STATUS & 1;
PulkoMandy612e2cf2021-09-20 23:00:40 +020023}
24
25#if 0
26/* Mouse management */
27void ctk_mouse_init(void)
28{
29 mx = 50;
30 my = 20;
31}
32
33unsigned char ctk_mouse_xtoc(unsigned short x)
34{
35 return x;
36}
37
38unsigned char ctk_mouse_ytoc(unsigned short y)
39{
40 return y;
41}
42
43void ctk_mouse_hide(void)
44{
45 vram_attr[ctk_mouse_ytoc(my)][ctk_mouse_xtoc(mx)] &= ~32;
46}
47
48void ctk_mouse_show(void)
49{
50 vram_attr[ctk_mouse_ytoc(my)][ctk_mouse_xtoc(mx)] |= 32;
51}
52
53unsigned short ctk_mouse_x(void)
54{
55 if (mouse_x != 0)
56 {
57 ctk_mouse_hide();
58 mx += mouse_x; mouse_x = 0;
59 if (mx < 0) mx = 0;
60 if (mx >= LIBCONIO_SCREEN_WIDTH) mx = LIBCONIO_SCREEN_WIDTH - 1;
61 }
62 return mx;
63}
64
65unsigned short ctk_mouse_y(void)
66{
67 if (mouse_y != 0) {
68 ctk_mouse_hide();
69 my += mouse_y; mouse_y = 0;
70 if (my < 0) my = 0;
71 if (my >= LIBCONIO_SCREEN_HEIGHT) my = LIBCONIO_SCREEN_HEIGHT - 1;
72 }
73 return my;
74}
75
76unsigned char ctk_mouse_button(void)
77{
78 return mouse_buttons;
79}
80#endif
81
82extern int vram[];
83extern int vram_attr[];
84#define VRAM_WIDTH 64
85
86/* Character display */
87void
88ctk_arch_draw_char(char c,
89 unsigned char x, unsigned char y,
90 unsigned char reversed,
91 unsigned char color)
92{
PulkoMandybb8de5f2021-09-21 21:27:57 +020093 if (reversed)
94 color ^= 8;
95
PulkoMandy612e2cf2021-09-20 23:00:40 +020096 vram[y * VRAM_WIDTH + x] = c;
97 if (x & 1) {
98 vram_attr[(y * VRAM_WIDTH + x) / 2] &= 0xff;
99 vram_attr[(y * VRAM_WIDTH + x) / 2] |= color << 8;
100 } else {
101 vram_attr[(y * VRAM_WIDTH + x) / 2] &= 0xff00;
102 vram_attr[(y * VRAM_WIDTH + x) / 2] |= color;
103 }
104}