Skip to content

Commit

Permalink
pc-tty: add vt mode switching between text and graphics mode
Browse files Browse the repository at this point in the history
Graphical apps can now disable console drawing via ioctl/TTYSETMODE to
ensure uninterrupted drawing (otherwise app and console would draw
to the framebuffer in the same time, causing mess)

JIRA: RTOS-925
  • Loading branch information
adamgreloch committed Oct 1, 2024
1 parent 3d7e5f6 commit 35702e8
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 42 deletions.
86 changes: 49 additions & 37 deletions tty/pc-tty/ttypc_vga.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <sys/mman.h>
#include <sys/threads.h>

#include <tty.h>

Check failure on line 23 in tty/pc-tty/ttypc_vga.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-qemu)

tty.h: No such file or directory

Check failure on line 23 in tty/pc-tty/ttypc_vga.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-pc)

tty.h: No such file or directory

#include "ttypc.h"
#include "ttypc_fbcon.h"
#include "ttypc_vga.h"
Expand Down Expand Up @@ -82,13 +84,15 @@ ssize_t _ttypc_vga_write(ttypc_vt_t *vt, volatile uint16_t *vga, uint16_t *buff,
for (i = 0; i < n; i++) {
*(vga + i) = *(buff + i);

_ttypc_fbcon_draw_char(vt, col, row, *(buff + i));
if (col < vt->cols - 1) {
col++;
}
else {
col = 0;
row++;
if (vt->vtmode == TTY_MODE_TEXT) {
_ttypc_fbcon_draw_char(vt, col, row, *(buff + i));
if (col < vt->cols - 1) {
col++;
}
else {
col = 0;
row++;
}
}
}

Expand All @@ -108,13 +112,15 @@ volatile uint16_t *_ttypc_vga_set(ttypc_vt_t *vt, volatile uint16_t *vga, uint16
for (i = 0; i < n; i++) {
*(vga + i) = val;

_ttypc_fbcon_draw_char(vt, col, row, val);
if (col < vt->cols - 1) {
col++;
}
else {
col = 0;
row++;
if (vt->vtmode == TTY_MODE_TEXT) {
_ttypc_fbcon_draw_char(vt, col, row, val);
if (col < vt->cols - 1) {
col++;
}
else {
col = 0;
row++;
}
}
}

Expand All @@ -135,13 +141,15 @@ volatile uint16_t *_ttypc_vga_move(ttypc_vt_t *vt, volatile uint16_t *dvga, vola
for (i = 0; i < n; i++) {
dvga[i] = svga[i];

_ttypc_fbcon_draw_char(vt, col, row, svga[i]);
if (col < vt->cols - 1) {
col++;
}
else {
col = 0;
row++;
if (vt->vtmode == TTY_MODE_TEXT) {
_ttypc_fbcon_draw_char(vt, col, row, svga[i]);
if (col < vt->cols - 1) {
col++;
}
else {
col = 0;
row++;
}
}
}
}
Expand All @@ -153,15 +161,17 @@ volatile uint16_t *_ttypc_vga_move(ttypc_vt_t *vt, volatile uint16_t *dvga, vola
for (i = n; i--;) {
dvga[i] = svga[i];

_ttypc_fbcon_draw_char(vt, col, row, svga[i]);
if (col > 0) {
col--;
}
else {
if (row == 0)
break;
col = vt->cols - 1;
row--;
if (vt->vtmode == TTY_MODE_TEXT) {
_ttypc_fbcon_draw_char(vt, col, row, svga[i]);
if (col > 0) {
col--;
}
else {
if (row == 0)
break;
col = vt->cols - 1;
row--;
}
}
}
}
Expand Down Expand Up @@ -329,14 +339,16 @@ void _ttypc_vga_setcursor(ttypc_vt_t *vt)

_ttypc_vga_writereg(vt->ttypc, CRTC_CURSORH, vt->cpos);

/* Undraw current cursor */
if (curr_pos != -1) {
_ttypc_fbcon_draw_char(vt, curr_pos % vt->cols, curr_pos / vt->cols, vt->vram[curr_pos]);
}
if (vt->vtmode == TTY_MODE_TEXT) {
/* Undraw current cursor */
if (curr_pos != -1) {
_ttypc_fbcon_draw_char(vt, curr_pos % vt->cols, curr_pos / vt->cols, vt->vram[curr_pos]);
}

/* Draw a new one */
_ttypc_fbcon_draw_char(vt, vt->cpos % vt->cols, vt->cpos / vt->cols, INVERT_COLORS(vt->vram[vt->cpos]));
curr_pos = vt->cpos;
/* Draw a new one */
_ttypc_fbcon_draw_char(vt, vt->cpos % vt->cols, vt->cpos / vt->cols, INVERT_COLORS(vt->vram[vt->cpos]));
curr_pos = vt->cpos;
}
}


Expand Down
35 changes: 30 additions & 5 deletions tty/pc-tty/ttypc_vt.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <sys/mman.h>
#include <sys/threads.h>

#include <tty.h>

Check failure on line 22 in tty/pc-tty/ttypc_vt.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-qemu)

tty.h: No such file or directory

Check failure on line 22 in tty/pc-tty/ttypc_vt.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-pc)

tty.h: No such file or directory

#include "ttypc_vga.h"
#include "ttypc_fbcon.h"
#include "ttypc_vt.h"
Expand All @@ -38,10 +40,12 @@ static void _ttypc_vt_sdraw(ttypc_vt_t *vt, char c)
*(vt->vram + vt->cpos) = vt->attr | c;
vt->ss = 0;

pos = vt->cpos;
col = pos % vt->cols;
row = pos / vt->cols;
_ttypc_fbcon_draw_char(vt, col, row, vt->attr | c);
if (vt->vtmode == TTY_MODE_TEXT) {
pos = vt->cpos;
col = pos % vt->cols;
row = pos / vt->cols;
_ttypc_fbcon_draw_char(vt, col, row, vt->attr | c);
}
}


Expand Down Expand Up @@ -649,7 +653,26 @@ int ttypc_vt_pollstatus(ttypc_vt_t *vt)

int ttypc_vt_ioctl(ttypc_vt_t *vt, pid_t pid, unsigned int cmd, const void *idata, const void **odata)
{
return libtty_ioctl(&vt->tty, pid, cmd, idata, odata);
int mode;
int ret = EOK;

switch (cmd) {
case TTYSETMODE:
mode = (int)idata;
if (mode != TTY_MODE_TEXT && mode != TTY_MODE_GRAPHICS) {
ret = -EINVAL;
break;
}
vt->vtmode = mode;
break;
case TTYGETMODE:
*odata = (const void *)&vt->vtmode;
break;
default:
ret = libtty_ioctl(&vt->tty, pid, cmd, idata, odata);
break;
}
return ret;
}


Expand Down Expand Up @@ -746,5 +769,7 @@ int ttypc_vt_init(ttypc_t *ttypc, unsigned int ttybuffsz, ttypc_vt_t *vt)
/* Clear screen */
_ttypc_vga_set(vt, vt->vram, vt->attr | ' ', vt->cols * vt->rows);

vt->vtmode = TTY_MODE_TEXT;

return EOK;
}
2 changes: 2 additions & 0 deletions tty/pc-tty/ttypc_vt.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ typedef struct {
char tabs[MAXTABS]; /* Table of active tab stops */
libtty_common_t tty; /* Terminal character processing (using libtty) */

uint8_t vtmode; /* vt mode: text (0x0) or graphics (0x1) */

/* Synchronization */
handle_t lock; /* Access lock */
} ttypc_vt_t;
Expand Down

0 comments on commit 35702e8

Please sign in to comment.