blob: 372677576357716e23cd675203788381ef848cbb [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
PulkoMandy42349612021-09-23 22:18:46 +020010extern unsigned int vram[];
11
12ctk_arch_key_t key;
13
PulkoMandy612e2cf2021-09-20 23:00:40 +020014/* Keyboard management */
15ctk_arch_key_t
16ctk_arch_getkey(void)
17{
PulkoMandy42349612021-09-23 22:18:46 +020018 return key;
PulkoMandy612e2cf2021-09-20 23:00:40 +020019}
20
21unsigned char kbhit(void)
22{
PulkoMandy6c4cba62021-09-21 21:33:31 +020023 volatile unsigned int* const UART_STATUS = 0x3D31;
PulkoMandy42349612021-09-23 22:18:46 +020024 volatile unsigned int* const UART_RX = 0x3D36;
25 unsigned int tmp;
PulkoMandy6c4cba62021-09-21 21:33:31 +020026
PulkoMandy42349612021-09-23 22:18:46 +020027 if ((*UART_STATUS & 1) == 0)
28 return 0;
29
30 tmp = *UART_RX;
31 if ((tmp == 0x55) || (tmp == 0xA0) || (tmp == 0x90) || (tmp == 0xC0) || (tmp == 0x80))
32 return 0;
33
34 key = tmp;
35
36 return 1;
PulkoMandy612e2cf2021-09-20 23:00:40 +020037}
38
39#if 0
40/* Mouse management */
41void ctk_mouse_init(void)
42{
43 mx = 50;
44 my = 20;
45}
46
47unsigned char ctk_mouse_xtoc(unsigned short x)
48{
49 return x;
50}
51
52unsigned char ctk_mouse_ytoc(unsigned short y)
53{
54 return y;
55}
56
57void ctk_mouse_hide(void)
58{
59 vram_attr[ctk_mouse_ytoc(my)][ctk_mouse_xtoc(mx)] &= ~32;
60}
61
62void ctk_mouse_show(void)
63{
64 vram_attr[ctk_mouse_ytoc(my)][ctk_mouse_xtoc(mx)] |= 32;
65}
66
67unsigned short ctk_mouse_x(void)
68{
69 if (mouse_x != 0)
70 {
71 ctk_mouse_hide();
72 mx += mouse_x; mouse_x = 0;
73 if (mx < 0) mx = 0;
74 if (mx >= LIBCONIO_SCREEN_WIDTH) mx = LIBCONIO_SCREEN_WIDTH - 1;
75 }
76 return mx;
77}
78
79unsigned short ctk_mouse_y(void)
80{
81 if (mouse_y != 0) {
82 ctk_mouse_hide();
83 my += mouse_y; mouse_y = 0;
84 if (my < 0) my = 0;
85 if (my >= LIBCONIO_SCREEN_HEIGHT) my = LIBCONIO_SCREEN_HEIGHT - 1;
86 }
87 return my;
88}
89
90unsigned char ctk_mouse_button(void)
91{
92 return mouse_buttons;
93}
94#endif
95
PulkoMandy612e2cf2021-09-20 23:00:40 +020096extern int vram_attr[];
97#define VRAM_WIDTH 64
98
99/* Character display */
100void
101ctk_arch_draw_char(char c,
102 unsigned char x, unsigned char y,
103 unsigned char reversed,
104 unsigned char color)
105{
PulkoMandybb8de5f2021-09-21 21:27:57 +0200106 if (reversed)
107 color ^= 8;
108
PulkoMandy612e2cf2021-09-20 23:00:40 +0200109 vram[y * VRAM_WIDTH + x] = c;
110 if (x & 1) {
111 vram_attr[(y * VRAM_WIDTH + x) / 2] &= 0xff;
112 vram_attr[(y * VRAM_WIDTH + x) / 2] |= color << 8;
113 } else {
114 vram_attr[(y * VRAM_WIDTH + x) / 2] &= 0xff00;
115 vram_attr[(y * VRAM_WIDTH + x) / 2] |= color;
116 }
PulkoMandy42349612021-09-23 22:18:46 +0200117}