diff options
author | Bad Diode <bd@badd10de.dev> | 2022-03-14 19:12:18 +0100 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2022-03-14 19:12:18 +0100 |
commit | 5813c416cff70e0b773e5151f07bf037fe692679 (patch) | |
tree | b63de6bc2a804db500efcd1a12613ff228539166 | |
parent | d87d43ce228e9b2e795fa85c5dee3708c2812625 (diff) | |
download | uxnfb-5813c416cff70e0b773e5151f07bf037fe692679.tar.gz uxnfb-5813c416cff70e0b773e5151f07bf037fe692679.zip |
Fix TTY cursor and graphics mode
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | src/main.c | 10 | ||||
-rw-r--r-- | src/ppu.c | 54 |
3 files changed, 53 insertions, 13 deletions
@@ -48,8 +48,6 @@ $(UXN_ROM): $(UXN_ASM) | |||
48 | ./$(UXN_ASM) $(TAL_SRC) $(UXN_ROM) | 48 | ./$(UXN_ASM) $(TAL_SRC) $(UXN_ROM) |
49 | 49 | ||
50 | run: $(BIN) $(UXN_ROM) | 50 | run: $(BIN) $(UXN_ROM) |
51 | # NOTE: This should probably be done on the C code. | ||
52 | # echo 0 > /sys/class/graphics/fbcon/cursor_blink | ||
53 | ./$(BIN) $(UXN_ROM) | 51 | ./$(BIN) $(UXN_ROM) |
54 | 52 | ||
55 | clean: | 53 | clean: |
@@ -1,4 +1,5 @@ | |||
1 | #include <errno.h> | 1 | #include <errno.h> |
2 | #include <signal.h> | ||
2 | #include <stdbool.h> | 3 | #include <stdbool.h> |
3 | #include <stdint.h> | 4 | #include <stdint.h> |
4 | #include <stdio.h> | 5 | #include <stdio.h> |
@@ -24,6 +25,13 @@ static Device *devmouse; | |||
24 | 25 | ||
25 | typedef struct timespec Time; | 26 | typedef struct timespec Time; |
26 | 27 | ||
28 | void | ||
29 | halt(int stub) { | ||
30 | (void)stub; | ||
31 | set_tty(false); | ||
32 | exit(EXIT_SUCCESS); | ||
33 | } | ||
34 | |||
27 | Time | 35 | Time |
28 | time_now(){ | 36 | time_now(){ |
29 | struct timespec t; | 37 | struct timespec t; |
@@ -446,6 +454,8 @@ load_rom(char *file_name) { | |||
446 | 454 | ||
447 | void | 455 | void |
448 | init_uxn(Uxn *u, char *file_name) { | 456 | init_uxn(Uxn *u, char *file_name) { |
457 | signal(SIGINT, halt); | ||
458 | |||
449 | // Setup UXN memory. | 459 | // Setup UXN memory. |
450 | uxn_boot(u, calloc(0x10000, sizeof(u8))); | 460 | uxn_boot(u, calloc(0x10000, sizeof(u8))); |
451 | 461 | ||
@@ -4,6 +4,7 @@ | |||
4 | 4 | ||
5 | #include <linux/fb.h> | 5 | #include <linux/fb.h> |
6 | #include <sys/ioctl.h> | 6 | #include <sys/ioctl.h> |
7 | #include <sys/kd.h> | ||
7 | #include <sys/mman.h> | 8 | #include <sys/mman.h> |
8 | 9 | ||
9 | #include "ppu.h" | 10 | #include "ppu.h" |
@@ -89,6 +90,46 @@ redraw_screen(void) { | |||
89 | } | 90 | } |
90 | } | 91 | } |
91 | 92 | ||
93 | static struct termios prev_t; | ||
94 | |||
95 | void | ||
96 | set_tty(bool graphics) { | ||
97 | // Disable TTY echo and set graphics mode. | ||
98 | int tty = open("/dev/tty0", O_RDWR); | ||
99 | if (!tty) { | ||
100 | fprintf(stderr,"error: couldn't open tty\n"); | ||
101 | exit(EXIT_FAILURE); | ||
102 | } | ||
103 | |||
104 | if (graphics) { | ||
105 | if (ioctl(tty, KDSETMODE, KD_GRAPHICS)) { | ||
106 | fprintf(stderr,"error: setting graphics mode failed\n"); | ||
107 | exit(EXIT_FAILURE); | ||
108 | } | ||
109 | struct termios t; | ||
110 | if (tcgetattr(STDIN_FILENO, &t)) { | ||
111 | fprintf(stderr, "error: couldn't disable terminal echo\n"); | ||
112 | exit(EXIT_FAILURE); | ||
113 | } | ||
114 | prev_t = t; | ||
115 | t.c_lflag &= ~((tcflag_t) ECHO); | ||
116 | if (tcsetattr(STDIN_FILENO, TCSANOW, &t)) { | ||
117 | fprintf(stderr, "error: couldn't disable terminal echo\n"); | ||
118 | exit(EXIT_FAILURE); | ||
119 | } | ||
120 | } else { | ||
121 | if (ioctl(tty, KDSETMODE, KD_TEXT)) { | ||
122 | fprintf(stderr,"error: setting text mode failed\n"); | ||
123 | exit(EXIT_FAILURE); | ||
124 | } | ||
125 | if (tcsetattr(STDIN_FILENO, TCSANOW, &prev_t)) { | ||
126 | fprintf(stderr, "error: couldn't restore terminal attributes\n"); | ||
127 | exit(EXIT_FAILURE); | ||
128 | } | ||
129 | } | ||
130 | close(tty); | ||
131 | } | ||
132 | |||
92 | int | 133 | int |
93 | ppu_init(void) { | 134 | ppu_init(void) { |
94 | // Open frambuffer and get the size. | 135 | // Open frambuffer and get the size. |
@@ -122,17 +163,8 @@ ppu_init(void) { | |||
122 | exit(EXIT_FAILURE); | 163 | exit(EXIT_FAILURE); |
123 | } | 164 | } |
124 | 165 | ||
125 | // Disable echo. | 166 | // Prepare TTY for graphics mode. |
126 | struct termios t; | 167 | set_tty(true); |
127 | if (tcgetattr(STDIN_FILENO, &t)) { | ||
128 | fprintf(stderr, "error: couldn't disable terminal echo\n"); | ||
129 | exit(EXIT_FAILURE); | ||
130 | } | ||
131 | t.c_lflag &= ~((tcflag_t) ECHO); | ||
132 | if (tcsetattr(STDIN_FILENO, TCSANOW, &t)) { | ||
133 | fprintf(stderr, "error: couldn't disable terminal echo\n"); | ||
134 | exit(EXIT_FAILURE); | ||
135 | } | ||
136 | 168 | ||
137 | // Initialize default palette. | 169 | // Initialize default palette. |
138 | palette[0] = 0x444444; | 170 | palette[0] = 0x444444; |