0.0.2d: Added BGA support, graphics!

This commit is contained in:
2026-06-05 16:14:14 -05:00
parent 5971218b56
commit f3b2f95af5
40 changed files with 1007 additions and 1197 deletions

View File

@ -33,11 +33,27 @@ static inline bool is_canonical(tty_t* tty)
return (tty->flags & TTY_CANONICAL) != 0;
}
static void raw_put(tty_t* tty, char c)
{
size_t next = (tty->raw_head + 1) % TTY_RAW_BUFFER_SIZE;
if (next != tty->raw_tail) // avoid overflow
{
tty->raw_buf[tty->raw_head] = c;
tty->raw_head = next;
}
}
tty_t* tty_get_active(void)
{
return active_tty;
}
int tty_fread(struct file* f, char* b, size_t s)
{
return (int) tty_read_active(b, s);
}
void tty_backspace(tty_t* tty)
{
if (tty->head == tty->tail)
@ -48,50 +64,88 @@ void tty_backspace(tty_t* tty)
tty->head = (tty->head + TTY_BUFFER_SIZE - 1) / TTY_BUFFER_SIZE;
}
void tty_and_flags(tty_t* tty, uint32_t flags)
{
tty->flags &= flags;
}
uint32_t tty_get_flags(tty_t* tty)
{
return tty->flags;
}
ssize_t tty_read_active(char* buf, size_t count)
{
return tty_read(active_tty, buf, count);
}
/*ssize_t tty_read(tty_t* tty, char* buf, size_t count)
/*
this is special, because when this is called the char returned by this function
is NOT added to the TTY buffer.
This can be changed however by setting flag TTY_ADDCHAR_ALWAYS.
*/
/*char tty_get_char(void)
{
size_t bytes_read = 0;
tty_t* tty = get_active_tty();
if (!tty)
{
return 0;
}
while (bytes_read < count)
while (1)
{
IRQ_DISABLE();
spin_lock(&tty->lock);
if (!tty_empty(tty))
if (tty->char_available)
{
char c = tty->input_buffer[tty->tail];
tty->tail = (tty->tail + 1) % TTY_BUFFER_SIZE;
tty->tail = next_index(tty->tail);
char c = tty->last_char;
tty->char_available = false;
spin_unlock(&tty->lock);
IRQ_ENABLE(); /* change? *//*
buf[bytes_read++] = c;
if (is_canonical(tty) && c == '\n')
{
break;
}
}
else
{
spin_unlock(&tty->lock);
IRQ_ENABLE();
}
}
return bytes_read;
return c;
}
spin_unlock(&tty->lock);
IRQ_ENABLE();
}
}*/
char tty_get_char(void)
{
tty_t* tty = get_active_tty();
if (!tty)
return 0;
while (1)
{
IRQ_DISABLE();
spin_lock(&tty->lock);
if (tty->raw_head != tty->raw_tail)
{
char c = tty->raw_buf[tty->raw_tail];
tty->raw_tail = (tty->raw_tail + 1) % TTY_RAW_BUFFER_SIZE;
spin_unlock(&tty->lock);
IRQ_ENABLE();
return c;
}
spin_unlock(&tty->lock);
IRQ_ENABLE();
}
}
ssize_t tty_read(tty_t* tty, char* buf, size_t count)
{
if (!tty || !buf)
return -1;
{
return -1;
}
size_t bytes = 0;
@ -169,6 +223,9 @@ int init_tty(void)
active_tty = t;
num_ttys = 1;
t->f_ops.read = tty_fread;
t->line_ready = false;
return 0;
}
@ -238,15 +295,18 @@ void tty_receive_char(char c, uint32_t kbd_mod)
}
}
void tty_input_char(tty_t* tty, char c)
/*void tty_input_char(tty_t* tty, char c)
{
if (!tty || c == 0)
return;
{
return;
}
IRQ_DISABLE();
spin_lock(&tty->lock);
/* backspace */
raw_put(tty, c);
if (c == '\b')
{
if (tty->head != tty->tail)
@ -255,9 +315,7 @@ void tty_input_char(tty_t* tty, char c)
if (tty->flags & TTY_ECHO)
{
putc('\b');/*
putc(' ');
putc('\b');*/
putc('\b');
}
}
@ -282,6 +340,65 @@ void tty_input_char(tty_t* tty, char c)
spin_unlock(&tty->lock);
IRQ_ENABLE();
if (tty->flags & TTY_ECHO)
{
putc(c);
}
}*/
void tty_input_char(tty_t* tty, char c)
{
if (!tty || c == 0)
{
return;
}
IRQ_DISABLE();
spin_lock(&tty->lock);
/* RAW queue always gets input */
raw_put(tty, c);
if (!(tty->flags & TTY_RAW))
{
/* canonical behavior */
if (c == '\b')
{
if (tty->head != tty->tail)
{
tty->head = (tty->head + TTY_BUFFER_SIZE - 1) % TTY_BUFFER_SIZE;
putc('\b');
putc(' ');
putc('\b');
spin_unlock(&tty->lock);
IRQ_ENABLE();
return;
}
}
else
{
size_t next = next_index(tty->head);
if (next != tty->tail)
{
tty->input_buffer[tty->head] = c;
tty->head = next;
if (c == '\n')
{
tty->line_ready = true;
}
}
}
}
spin_unlock(&tty->lock);
IRQ_ENABLE();
if (tty->flags & TTY_ECHO)
{
putc(c);