aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2022-03-14 19:12:18 +0100
committerBad Diode <bd@badd10de.dev>2022-03-14 19:12:18 +0100
commit5813c416cff70e0b773e5151f07bf037fe692679 (patch)
treeb63de6bc2a804db500efcd1a12613ff228539166
parentd87d43ce228e9b2e795fa85c5dee3708c2812625 (diff)
downloaduxnfb-5813c416cff70e0b773e5151f07bf037fe692679.tar.gz
uxnfb-5813c416cff70e0b773e5151f07bf037fe692679.zip
Fix TTY cursor and graphics mode
-rw-r--r--Makefile2
-rw-r--r--src/main.c10
-rw-r--r--src/ppu.c54
3 files changed, 53 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index 8c56874..37b3802 100644
--- a/Makefile
+++ b/Makefile
@@ -48,8 +48,6 @@ $(UXN_ROM): $(UXN_ASM)
48 ./$(UXN_ASM) $(TAL_SRC) $(UXN_ROM) 48 ./$(UXN_ASM) $(TAL_SRC) $(UXN_ROM)
49 49
50run: $(BIN) $(UXN_ROM) 50run: $(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
55clean: 53clean:
diff --git a/src/main.c b/src/main.c
index fcd42a4..29c4d5e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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
25typedef struct timespec Time; 26typedef struct timespec Time;
26 27
28void
29halt(int stub) {
30 (void)stub;
31 set_tty(false);
32 exit(EXIT_SUCCESS);
33}
34
27Time 35Time
28time_now(){ 36time_now(){
29 struct timespec t; 37 struct timespec t;
@@ -446,6 +454,8 @@ load_rom(char *file_name) {
446 454
447void 455void
448init_uxn(Uxn *u, char *file_name) { 456init_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
diff --git a/src/ppu.c b/src/ppu.c
index ff93ec1..aa99ed8 100644
--- a/src/ppu.c
+++ b/src/ppu.c
@@ -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
93static struct termios prev_t;
94
95void
96set_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
92int 133int
93ppu_init(void) { 134ppu_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;