PulkoMandy | 612e2cf | 2021-09-20 23:00:40 +0200 | [diff] [blame] | 1 | /* |
| 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 */ |
| 11 | ctk_arch_key_t |
| 12 | ctk_arch_getkey(void) |
| 13 | { |
PulkoMandy | 6c4cba6 | 2021-09-21 21:33:31 +0200 | [diff] [blame^] | 14 | volatile unsigned int* const UART_RX = 0x3D36; |
| 15 | return *UART_RX; |
PulkoMandy | 612e2cf | 2021-09-20 23:00:40 +0200 | [diff] [blame] | 16 | } |
| 17 | |
| 18 | unsigned char kbhit(void) |
| 19 | { |
PulkoMandy | 6c4cba6 | 2021-09-21 21:33:31 +0200 | [diff] [blame^] | 20 | volatile unsigned int* const UART_STATUS = 0x3D31; |
| 21 | |
| 22 | return *UART_STATUS & 1; |
PulkoMandy | 612e2cf | 2021-09-20 23:00:40 +0200 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | #if 0 |
| 26 | /* Mouse management */ |
| 27 | void ctk_mouse_init(void) |
| 28 | { |
| 29 | mx = 50; |
| 30 | my = 20; |
| 31 | } |
| 32 | |
| 33 | unsigned char ctk_mouse_xtoc(unsigned short x) |
| 34 | { |
| 35 | return x; |
| 36 | } |
| 37 | |
| 38 | unsigned char ctk_mouse_ytoc(unsigned short y) |
| 39 | { |
| 40 | return y; |
| 41 | } |
| 42 | |
| 43 | void ctk_mouse_hide(void) |
| 44 | { |
| 45 | vram_attr[ctk_mouse_ytoc(my)][ctk_mouse_xtoc(mx)] &= ~32; |
| 46 | } |
| 47 | |
| 48 | void ctk_mouse_show(void) |
| 49 | { |
| 50 | vram_attr[ctk_mouse_ytoc(my)][ctk_mouse_xtoc(mx)] |= 32; |
| 51 | } |
| 52 | |
| 53 | unsigned 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 | |
| 65 | unsigned 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 | |
| 76 | unsigned char ctk_mouse_button(void) |
| 77 | { |
| 78 | return mouse_buttons; |
| 79 | } |
| 80 | #endif |
| 81 | |
| 82 | extern int vram[]; |
| 83 | extern int vram_attr[]; |
| 84 | #define VRAM_WIDTH 64 |
| 85 | |
| 86 | /* Character display */ |
| 87 | void |
| 88 | ctk_arch_draw_char(char c, |
| 89 | unsigned char x, unsigned char y, |
| 90 | unsigned char reversed, |
| 91 | unsigned char color) |
| 92 | { |
PulkoMandy | bb8de5f | 2021-09-21 21:27:57 +0200 | [diff] [blame] | 93 | if (reversed) |
| 94 | color ^= 8; |
| 95 | |
PulkoMandy | 612e2cf | 2021-09-20 23:00:40 +0200 | [diff] [blame] | 96 | 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 | } |