Vhex-kernel/src/kernel/devices/tty/ioctl/ioctl.c

52 lines
928 B
C
Raw Normal View History

2019-12-20 11:31:34 +01:00
#include <kernel/devices/tty.h>
#include <kernel/util/atomic.h>
2019-12-20 11:31:34 +01:00
#include <stdarg.h>
void tty_ioctl(void *inode, uint32_t cmd, ...)
2019-12-20 11:31:34 +01:00
{
struct tty_s *tty;
2019-12-20 11:31:34 +01:00
va_list ap;
// Start atomic operation
atomic_start();
tty = inode;
2019-12-20 11:31:34 +01:00
va_start(ap, cmd);
switch (cmd)
{
case TTY_IOCTL_GETDX:
{
int *dx = va_arg(ap, int*);
*dx = tty->cursor.x * (KERNEL_FONT_REAL_WIDTH + 1);
2019-12-20 11:31:34 +01:00
break;
}
case TTY_IOCTL_GETDY:
{
int *dy = va_arg(ap, int*);
int start = tty->cursor.y;
2019-12-20 11:31:34 +01:00
int saved_start;
int line = -1;
while (++line < DISPLAY_VCHAR_MAX - 1)
{
// Update check line.
saved_start = start;
start = (start - 1 < 0) ? tty->cursor.max.y : start - 1;
2019-12-20 11:31:34 +01:00
// Check if the line exist.
if (tty->buffer[start][0] == '\0')
2019-12-20 11:31:34 +01:00
{
start = saved_start;
break;
}
}
*dy = line * (KERNEL_FONT_REAL_HEIGHT + 1);
break;
}
}
va_end(ap);
// Stop atomic operation
atomic_stop();
2019-12-20 11:31:34 +01:00
}